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