aai-lark-bridge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -0
- package/bin/aai-lark-bridge.mjs +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +17429 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +198 -0
- package/dist/index.js +1535 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
type LocalAgentId = 'claude' | 'codex';
|
|
2
|
+
type AgentPreflightErrorCode = 'agent-binary-not-found' | 'agent-binary-not-executable' | 'agent-binary-resolve-failed' | 'agent-binary-not-readable' | 'agent-version-check-spawn-failed' | 'agent-version-check-timeout' | 'agent-version-check-signaled' | 'agent-version-check-nonzero-exit' | 'agent-version-check-empty-output';
|
|
3
|
+
interface AgentPreflightDiagnostic {
|
|
4
|
+
code: AgentPreflightErrorCode;
|
|
5
|
+
agentId: LocalAgentId;
|
|
6
|
+
agentName: string;
|
|
7
|
+
command: string;
|
|
8
|
+
binaryPath?: string;
|
|
9
|
+
realpath?: string;
|
|
10
|
+
args?: readonly string[];
|
|
11
|
+
exitCode?: number | null;
|
|
12
|
+
signal?: NodeJS.Signals | null;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
errno?: string;
|
|
15
|
+
stdoutExcerpt?: string;
|
|
16
|
+
stderrExcerpt?: string;
|
|
17
|
+
field?: string;
|
|
18
|
+
expected?: string | number;
|
|
19
|
+
actual?: string | number;
|
|
20
|
+
}
|
|
21
|
+
type AgentAvailability = {
|
|
22
|
+
ok: true;
|
|
23
|
+
version?: string;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: AgentPreflightError;
|
|
27
|
+
diagnostic: AgentPreflightDiagnostic;
|
|
28
|
+
};
|
|
29
|
+
declare class AgentPreflightError extends Error {
|
|
30
|
+
readonly diagnostic: AgentPreflightDiagnostic;
|
|
31
|
+
constructor(diagnostic: AgentPreflightDiagnostic, message?: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type CodexSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
35
|
+
type ClaudePermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
|
|
36
|
+
|
|
37
|
+
type AgentEvent = {
|
|
38
|
+
type: 'system';
|
|
39
|
+
sessionId?: string;
|
|
40
|
+
threadId?: string;
|
|
41
|
+
cwd?: string;
|
|
42
|
+
model?: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'text';
|
|
45
|
+
delta: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: 'final_text';
|
|
48
|
+
content: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'thinking';
|
|
51
|
+
delta: string;
|
|
52
|
+
} | {
|
|
53
|
+
type: 'tool_use';
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
input: unknown;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'tool_result';
|
|
59
|
+
id: string;
|
|
60
|
+
output: string;
|
|
61
|
+
isError: boolean;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'usage';
|
|
64
|
+
inputTokens?: number;
|
|
65
|
+
outputTokens?: number;
|
|
66
|
+
cachedInputTokens?: number;
|
|
67
|
+
reasoningOutputTokens?: number;
|
|
68
|
+
costUsd?: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'done';
|
|
71
|
+
sessionId?: string;
|
|
72
|
+
threadId?: string;
|
|
73
|
+
terminationReason: 'normal' | 'interrupted' | 'timeout';
|
|
74
|
+
} | {
|
|
75
|
+
type: 'error';
|
|
76
|
+
message: string;
|
|
77
|
+
terminationReason: 'failed' | 'interrupted' | 'timeout';
|
|
78
|
+
};
|
|
79
|
+
interface AgentRunOptions {
|
|
80
|
+
runId: string;
|
|
81
|
+
prompt: string;
|
|
82
|
+
cwd?: string;
|
|
83
|
+
sessionId?: string;
|
|
84
|
+
threadId?: string;
|
|
85
|
+
model?: string;
|
|
86
|
+
images?: readonly string[];
|
|
87
|
+
sandbox?: CodexSandboxMode;
|
|
88
|
+
permissionMode?: ClaudePermissionMode;
|
|
89
|
+
/**
|
|
90
|
+
* Grace period (ms) between SIGTERM and SIGKILL when stop() is called on
|
|
91
|
+
* the returned run. Lets the agent (and any subprocess it spawned, e.g.
|
|
92
|
+
* lark-cli mid-OAuth) clean up before the kernel reaps the tree.
|
|
93
|
+
* Adapters that don't kill via signals are free to ignore this. Defaults
|
|
94
|
+
* are adapter-specific.
|
|
95
|
+
*/
|
|
96
|
+
stopGraceMs?: number;
|
|
97
|
+
}
|
|
98
|
+
interface AgentRun {
|
|
99
|
+
readonly runId: string;
|
|
100
|
+
readonly events: AsyncIterable<AgentEvent>;
|
|
101
|
+
stop(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Wait up to `timeoutMs` for the agent process to exit on its own.
|
|
104
|
+
* Resolves true if it exited within the window, false if the timer
|
|
105
|
+
* fired first (caller usually wants to fall back to stop()).
|
|
106
|
+
*
|
|
107
|
+
* Use this after a terminal stream event (`done` / `error`): the
|
|
108
|
+
* stream-json `result` line arrives before claude has actually closed
|
|
109
|
+
* stdout — there's a brief telemetry/cleanup tail in between. Calling
|
|
110
|
+
* stop() in that window forces a SIGTERM and the run exits with code
|
|
111
|
+
* 143 instead of 0; waiting it out lets it exit cleanly.
|
|
112
|
+
*/
|
|
113
|
+
waitForExit(timeoutMs: number): Promise<boolean>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The bridge bot's own IM identity, resolved by the channel after the WS
|
|
117
|
+
* handshake (`/open-apis/bot/v3/info`). Injected into adapters so the agent
|
|
118
|
+
* system prompt can state "this open_id is you" with the real value.
|
|
119
|
+
*/
|
|
120
|
+
interface AgentBotIdentity {
|
|
121
|
+
openId: string;
|
|
122
|
+
name?: string;
|
|
123
|
+
}
|
|
124
|
+
interface AgentAdapter {
|
|
125
|
+
readonly id: string;
|
|
126
|
+
readonly displayName: string;
|
|
127
|
+
isAvailable(): Promise<boolean>;
|
|
128
|
+
checkAvailability?(): Promise<AgentAvailability>;
|
|
129
|
+
prepareRun?(opts: AgentRunOptions): Promise<void>;
|
|
130
|
+
run(opts: AgentRunOptions): AgentRun;
|
|
131
|
+
/**
|
|
132
|
+
* Late-bound identity injection: the adapter is constructed before the
|
|
133
|
+
* channel connects, so the channel calls this once botIdentity is known.
|
|
134
|
+
* Adapters that don't bake identity into their prompts may omit it.
|
|
135
|
+
*/
|
|
136
|
+
setBotIdentity?(identity: AgentBotIdentity): void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface LarkChannelEnvContext {
|
|
140
|
+
profile?: string;
|
|
141
|
+
rootDir?: string;
|
|
142
|
+
configPath?: string;
|
|
143
|
+
larkCliConfigDir?: string;
|
|
144
|
+
larkCliSourceConfigFile?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface ClaudeAdapterOptions {
|
|
148
|
+
binary?: string;
|
|
149
|
+
larkChannel?: LarkChannelEnvContext;
|
|
150
|
+
}
|
|
151
|
+
declare class ClaudeAdapter implements AgentAdapter {
|
|
152
|
+
readonly id = "claude";
|
|
153
|
+
readonly displayName = "Claude Code";
|
|
154
|
+
private readonly binary;
|
|
155
|
+
private readonly larkChannel;
|
|
156
|
+
private botIdentity;
|
|
157
|
+
constructor(opts?: ClaudeAdapterOptions);
|
|
158
|
+
setBotIdentity(identity: AgentBotIdentity): void;
|
|
159
|
+
isAvailable(): Promise<boolean>;
|
|
160
|
+
checkAvailability(): Promise<AgentAvailability>;
|
|
161
|
+
run(opts: AgentRunOptions): AgentRun;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type SandboxMode = CodexSandboxMode;
|
|
165
|
+
|
|
166
|
+
interface CodexAdapterOptions {
|
|
167
|
+
binary: string;
|
|
168
|
+
profileStateDir: string;
|
|
169
|
+
codexHome?: string;
|
|
170
|
+
inheritCodexHome?: boolean;
|
|
171
|
+
ignoreUserConfig?: boolean;
|
|
172
|
+
ignoreRules?: boolean;
|
|
173
|
+
sandbox?: SandboxMode;
|
|
174
|
+
stopGraceMs?: number;
|
|
175
|
+
larkChannel?: LarkChannelEnvContext;
|
|
176
|
+
}
|
|
177
|
+
declare class CodexAdapter implements AgentAdapter {
|
|
178
|
+
readonly id = "codex";
|
|
179
|
+
readonly displayName = "Codex CLI";
|
|
180
|
+
private readonly binary;
|
|
181
|
+
private readonly profileStateDir;
|
|
182
|
+
private readonly codexHome;
|
|
183
|
+
private readonly inheritCodexHome;
|
|
184
|
+
private readonly ignoreUserConfig;
|
|
185
|
+
private readonly ignoreRules;
|
|
186
|
+
private readonly sandbox;
|
|
187
|
+
private readonly defaultStopGraceMs;
|
|
188
|
+
private readonly larkChannel;
|
|
189
|
+
private botIdentity;
|
|
190
|
+
constructor(opts: CodexAdapterOptions);
|
|
191
|
+
setBotIdentity(identity: AgentBotIdentity): void;
|
|
192
|
+
isAvailable(): Promise<boolean>;
|
|
193
|
+
checkAvailability(): Promise<AgentAvailability>;
|
|
194
|
+
prepareRun(): Promise<void>;
|
|
195
|
+
run(opts: AgentRunOptions): AgentRun;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export { type AgentAdapter, type AgentEvent, type AgentRun, type AgentRunOptions, ClaudeAdapter, CodexAdapter };
|