refactor: auth-cli.ts 改用 auth-rt 二进制
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7ad389adc4
commit
e18276ce07
|
|
@ -2,10 +2,10 @@
|
|||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# Prerequisite: auth-runtime must be cloned at ~/clawd/skills/auth-runtime
|
||||
if [ ! -d "$HOME/clawd/skills/auth-runtime/src" ]; then
|
||||
echo "ERROR: auth-runtime not found at ~/clawd/skills/auth-runtime"
|
||||
echo "Run: git clone http://192.168.0.108:3030/agent-skills/auth-runtime.git ~/clawd/skills/auth-runtime"
|
||||
# Prerequisite: auth-rt binary must be installed
|
||||
if ! command -v auth-rt &>/dev/null && [ ! -x "$HOME/.openclaw/bin/auth-rt" ]; then
|
||||
echo "ERROR: auth-rt not found. Install it:"
|
||||
echo " cd ~/clawd/skills/auth-runtime && ./install.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
/**
|
||||
* Thin CLI wrapper for auth-runtime.
|
||||
*
|
||||
* Copy this file into your skill's src/ directory. It spawns
|
||||
* `bun run <auth-runtime>/src/cli.ts` as a subprocess, so the
|
||||
* skill has zero npm dependency on @clawd/auth-runtime.
|
||||
* Copy this file into your skill's src/ directory. It calls the
|
||||
* `auth-rt` binary (compiled from auth-runtime), so the skill has
|
||||
* zero npm dependency on @clawd/auth-runtime.
|
||||
*
|
||||
* Prerequisites:
|
||||
* ~/.openclaw/bin/auth-rt must exist (run auth-runtime/install.sh)
|
||||
*
|
||||
* Usage:
|
||||
* import { createSkillClient } from './auth-cli.ts';
|
||||
|
|
@ -15,9 +18,8 @@ import { spawnSync } from 'child_process';
|
|||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
const AUTH_RUNTIME_DIR = process.env.AUTH_RUNTIME_DIR
|
||||
|| path.join(os.homedir(), 'clawd', 'skills', 'auth-runtime');
|
||||
const CLI_ENTRY = path.join(AUTH_RUNTIME_DIR, 'src', 'cli.ts');
|
||||
const AUTH_RT_BIN = process.env.AUTH_RT_BIN
|
||||
|| path.join(os.homedir(), '.openclaw', 'bin', 'auth-rt');
|
||||
|
||||
export interface ApiResponse {
|
||||
status: number;
|
||||
|
|
@ -38,19 +40,16 @@ export interface SkillClientOptions {
|
|||
}
|
||||
|
||||
function runCli(...args: string[]): string {
|
||||
// Use the same bun binary that's running this process
|
||||
const bun = process.execPath;
|
||||
const result = spawnSync(bun, ['run', CLI_ENTRY, ...args], {
|
||||
cwd: AUTH_RUNTIME_DIR,
|
||||
const result = spawnSync(AUTH_RT_BIN, args, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 60_000,
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
throw new Error(`auth-cli spawn failed: ${result.error.message}`);
|
||||
throw new Error(`auth-rt spawn failed: ${result.error.message}`);
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`auth-cli failed (exit ${result.status}): ${(result.stderr || '').trim()}`);
|
||||
throw new Error(`auth-rt failed (exit ${result.status}): ${(result.stderr || '').trim()}`);
|
||||
}
|
||||
return (result.stdout || '').trim();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue