genaicode 2.1.0 → 2.4.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/CHANGELOG.md +45 -0
- package/README.md +150 -35
- package/dist/agents/cli-agent.d.ts +28 -0
- package/dist/agents/cli-agent.js +57 -0
- package/dist/agents/cli-agent.js.map +1 -0
- package/dist/agents/discovery.d.ts +10 -0
- package/dist/agents/discovery.js +31 -0
- package/dist/agents/discovery.js.map +1 -0
- package/dist/agents/drivers/claude.d.ts +25 -0
- package/dist/agents/drivers/claude.js +184 -0
- package/dist/agents/drivers/claude.js.map +1 -0
- package/dist/agents/drivers/codex-live.d.ts +17 -0
- package/dist/agents/drivers/codex-live.js +182 -0
- package/dist/agents/drivers/codex-live.js.map +1 -0
- package/dist/agents/drivers/codex.d.ts +27 -0
- package/dist/agents/drivers/codex.js +176 -0
- package/dist/agents/drivers/codex.js.map +1 -0
- package/dist/agents/drivers/copilot.d.ts +27 -0
- package/dist/agents/drivers/copilot.js +199 -0
- package/dist/agents/drivers/copilot.js.map +1 -0
- package/dist/agents/drivers/cursor.d.ts +23 -0
- package/dist/agents/drivers/cursor.js +174 -0
- package/dist/agents/drivers/cursor.js.map +1 -0
- package/dist/agents/drivers/gemini.d.ts +18 -0
- package/dist/agents/drivers/gemini.js +118 -0
- package/dist/agents/drivers/gemini.js.map +1 -0
- package/dist/agents/drivers/json.d.ts +6 -0
- package/dist/agents/drivers/json.js +20 -0
- package/dist/agents/drivers/json.js.map +1 -0
- package/dist/agents/drivers/muse-live.d.ts +17 -0
- package/dist/agents/drivers/muse-live.js +112 -0
- package/dist/agents/drivers/muse-live.js.map +1 -0
- package/dist/agents/drivers/muse.d.ts +12 -0
- package/dist/agents/drivers/muse.js +87 -0
- package/dist/agents/drivers/muse.js.map +1 -0
- package/dist/agents/drivers/opencode.d.ts +17 -0
- package/dist/agents/drivers/opencode.js +103 -0
- package/dist/agents/drivers/opencode.js.map +1 -0
- package/dist/agents/env.d.ts +16 -0
- package/dist/agents/env.js +46 -0
- package/dist/agents/env.js.map +1 -0
- package/dist/agents/event-queue.d.ts +44 -0
- package/dist/agents/event-queue.js +123 -0
- package/dist/agents/event-queue.js.map +1 -0
- package/dist/agents/hosted.d.ts +33 -0
- package/dist/agents/hosted.js +129 -0
- package/dist/agents/hosted.js.map +1 -0
- package/dist/agents/live-agent.d.ts +37 -0
- package/dist/agents/live-agent.js +142 -0
- package/dist/agents/live-agent.js.map +1 -0
- package/dist/agents/prepare.d.ts +33 -0
- package/dist/agents/prepare.js +52 -0
- package/dist/agents/prepare.js.map +1 -0
- package/dist/agents/process.d.ts +39 -0
- package/dist/agents/process.js +140 -0
- package/dist/agents/process.js.map +1 -0
- package/dist/agents/rpc.d.ts +29 -0
- package/dist/agents/rpc.js +101 -0
- package/dist/agents/rpc.js.map +1 -0
- package/dist/agents/runtime.d.ts +26 -0
- package/dist/agents/runtime.js +97 -0
- package/dist/agents/runtime.js.map +1 -0
- package/dist/agents/types.d.ts +158 -0
- package/dist/agents/types.js +2 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/agents/verify.d.ts +36 -0
- package/dist/agents/verify.js +43 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/agents.d.ts +36 -0
- package/dist/agents.js +19 -0
- package/dist/agents.js.map +1 -0
- package/dist/core/client.d.ts +7 -1
- package/dist/core/client.js +18 -3
- package/dist/core/client.js.map +1 -1
- package/dist/core/middleware.js +2 -0
- package/dist/core/middleware.js.map +1 -1
- package/dist/core/types.d.ts +51 -0
- package/dist/providers/anthropic-converter.js +32 -6
- package/dist/providers/anthropic-converter.js.map +1 -1
- package/dist/providers/anthropic.js +3 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google-converter.js +70 -3
- package/dist/providers/google-converter.js.map +1 -1
- package/dist/providers/google.d.ts +8 -0
- package/dist/providers/google.js +3 -0
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/openai-converter.d.ts +2 -0
- package/dist/providers/openai-converter.js +16 -0
- package/dist/providers/openai-converter.js.map +1 -1
- package/dist/providers/openai.js +1 -0
- package/dist/providers/openai.js.map +1 -1
- package/docs/agents.md +269 -0
- package/docs/pivot.md +8 -1
- package/docs/semver.md +6 -0
- package/package.json +7 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { liveAgent, uuidv7 } from '../live-agent.js';
|
|
2
|
+
import { RpcError } from '../rpc.js';
|
|
3
|
+
import { isObject, stringField } from './json.js';
|
|
4
|
+
const TOOL_KINDS = new Set(['commandExecution', 'toolCall', 'mcpToolCall', 'fileChange']);
|
|
5
|
+
/**
|
|
6
|
+
* Muse over its JSON-RPC server (`muse serve`). Supports `steer()`.
|
|
7
|
+
* Approval requests are reported as events and declined: the answer format is not
|
|
8
|
+
* part of this driver yet, so `capabilities.approvals` is false.
|
|
9
|
+
*/
|
|
10
|
+
export function museLive(options = {}) {
|
|
11
|
+
return liveAgent({
|
|
12
|
+
name: 'muse',
|
|
13
|
+
command: options.command ?? 'muse',
|
|
14
|
+
capabilities: { effort: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'], approvals: false },
|
|
15
|
+
args: (task) => [
|
|
16
|
+
'serve',
|
|
17
|
+
...((options.trustWorkspace ?? true) ? ['--trust-workspace'] : []),
|
|
18
|
+
...(task.extraArgs ?? []),
|
|
19
|
+
],
|
|
20
|
+
drive: (session) => driveMuse(session, options),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function driveMuse(session, options) {
|
|
24
|
+
const { task, rpc } = session;
|
|
25
|
+
const timeout = options.requestTimeoutMs ?? 60_000;
|
|
26
|
+
// Filled in as the server replies; notifications before then are not ours.
|
|
27
|
+
const ids = {};
|
|
28
|
+
let finish = () => { };
|
|
29
|
+
const finished = new Promise((resolve) => {
|
|
30
|
+
finish = resolve;
|
|
31
|
+
});
|
|
32
|
+
session.onNotification((method, params) => {
|
|
33
|
+
if (ids.session === undefined || stringField(params, 'sessionId') !== ids.session)
|
|
34
|
+
return;
|
|
35
|
+
if (method === 'turn/completed') {
|
|
36
|
+
if (ids.turn && stringField(params, 'turnId') && stringField(params, 'turnId') !== ids.turn)
|
|
37
|
+
return;
|
|
38
|
+
const terminal = stringField(params, 'terminal');
|
|
39
|
+
const error = stringField(isObject(params) ? params.error : undefined, 'message');
|
|
40
|
+
if (error)
|
|
41
|
+
session.emit({ type: 'error', message: error });
|
|
42
|
+
finish(terminal === 'completed' ? { ok: true } : { ok: false, error: error ?? `Muse turn ${terminal ?? 'ended'}.` });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const event of museNotification(method, params))
|
|
46
|
+
session.emit(event);
|
|
47
|
+
});
|
|
48
|
+
session.onRequest((method, params) => {
|
|
49
|
+
if (method === 'approval/request') {
|
|
50
|
+
session.emit({
|
|
51
|
+
type: 'approval-request',
|
|
52
|
+
request: {
|
|
53
|
+
id: stringField(params, 'id') ?? stringField(params, 'approvalId') ?? 'approval',
|
|
54
|
+
kind: 'other',
|
|
55
|
+
detail: params,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
throw new RpcError('This client cannot grant this request.', -32601);
|
|
60
|
+
});
|
|
61
|
+
await rpc.request('initialize', { clientInfo: { name: 'genaicode', version: '2' }, capabilities: { userInputDialogs: false } }, timeout);
|
|
62
|
+
rpc.notify('initialized');
|
|
63
|
+
const created = await rpc.request('session/start', {
|
|
64
|
+
commandId: uuidv7(),
|
|
65
|
+
workspaceRoot: task.cwd,
|
|
66
|
+
...(task.model ? { modelId: task.model } : {}),
|
|
67
|
+
approvalMode: 'onRequest',
|
|
68
|
+
}, timeout);
|
|
69
|
+
const sessionId = stringField(isObject(created) ? created.session : undefined, 'sessionId');
|
|
70
|
+
ids.session = sessionId;
|
|
71
|
+
if (!sessionId)
|
|
72
|
+
throw new Error('Muse did not return a session id.');
|
|
73
|
+
session.emit({ type: 'session', sessionId });
|
|
74
|
+
const input = (text) => [{ type: 'text', text }];
|
|
75
|
+
const started = await rpc.request('turn/start', {
|
|
76
|
+
sessionId,
|
|
77
|
+
input: input(task.prompt),
|
|
78
|
+
commandId: uuidv7(),
|
|
79
|
+
...(task.effort ? { reasoningEffort: task.effort } : {}),
|
|
80
|
+
}, timeout);
|
|
81
|
+
const turnId = stringField(started, 'turnId');
|
|
82
|
+
ids.turn = turnId;
|
|
83
|
+
if (!turnId)
|
|
84
|
+
throw new Error('Muse did not return a turn id.');
|
|
85
|
+
session.setSteer(async (text) => {
|
|
86
|
+
const ack = await rpc.request('turn/steer', { sessionId, expectedTurnId: turnId, input: input(text), commandId: uuidv7() }, timeout);
|
|
87
|
+
if (stringField(ack, 'turnId') !== turnId)
|
|
88
|
+
throw new Error('Muse did not confirm the input; it may not have arrived.');
|
|
89
|
+
});
|
|
90
|
+
return finished;
|
|
91
|
+
}
|
|
92
|
+
/** Map one `muse serve` notification to agent events. */
|
|
93
|
+
export function museNotification(method, params) {
|
|
94
|
+
const item = isObject(params) && isObject(params.item) ? params.item : undefined;
|
|
95
|
+
if (!item)
|
|
96
|
+
return [];
|
|
97
|
+
const kind = stringField(item, 'type') ?? stringField(item, 'kind');
|
|
98
|
+
const id = stringField(item, 'id');
|
|
99
|
+
if (method === 'item/completed' && kind === 'agentMessage') {
|
|
100
|
+
const text = stringField(item, 'text');
|
|
101
|
+
return text ? [{ type: 'message', text }] : [];
|
|
102
|
+
}
|
|
103
|
+
if (kind && TOOL_KINDS.has(kind)) {
|
|
104
|
+
const name = stringField(item, 'toolName') ?? kind;
|
|
105
|
+
if (method === 'item/started')
|
|
106
|
+
return [{ type: 'tool-start', ...(id ? { id } : {}), name }];
|
|
107
|
+
if (method === 'item/completed')
|
|
108
|
+
return [{ type: 'tool-end', ...(id ? { id } : {}), name, isError: item.status === 'failed' }];
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=muse-live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mu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IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AgentOutputParser } from '../cli-agent.js';
|
|
2
|
+
import type { AgentTask, CodingAgent } from '../types.js';
|
|
3
|
+
export interface MuseAgentOptions {
|
|
4
|
+
/** Executable name or path. Default `muse`. */
|
|
5
|
+
command?: string;
|
|
6
|
+
/** Pass `--trust-workspace` so the run does not stop to ask. Default true. */
|
|
7
|
+
trustWorkspace?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Muse in exec mode (`muse exec --json`). */
|
|
10
|
+
export declare function muse(options?: MuseAgentOptions): CodingAgent;
|
|
11
|
+
export declare function museArgs(task: AgentTask, options?: MuseAgentOptions): string[];
|
|
12
|
+
export declare function createMuseParser(): AgentOutputParser;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { cliAgent } from '../cli-agent.js';
|
|
2
|
+
import { isObject, stringField } from './json.js';
|
|
3
|
+
/** Muse in exec mode (`muse exec --json`). */
|
|
4
|
+
export function muse(options = {}) {
|
|
5
|
+
return cliAgent({
|
|
6
|
+
name: 'muse',
|
|
7
|
+
command: options.command ?? 'muse',
|
|
8
|
+
capabilities: { effort: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'], maxTurns: true },
|
|
9
|
+
args: (task) => museArgs(task, options),
|
|
10
|
+
createParser: createMuseParser,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function museArgs(task, options = {}) {
|
|
14
|
+
const args = ['exec', '--json'];
|
|
15
|
+
if (options.trustWorkspace ?? true)
|
|
16
|
+
args.push('--trust-workspace');
|
|
17
|
+
if (task.model)
|
|
18
|
+
args.push('--model', task.model);
|
|
19
|
+
if (task.effort)
|
|
20
|
+
args.push('--reasoning-effort', task.effort);
|
|
21
|
+
if (task.maxTurns !== undefined)
|
|
22
|
+
args.push('--max-model-steps', String(task.maxTurns));
|
|
23
|
+
if (task.extraArgs)
|
|
24
|
+
args.push(...task.extraArgs);
|
|
25
|
+
return [...args, task.prompt];
|
|
26
|
+
}
|
|
27
|
+
const TERMINAL = 'run.terminal.';
|
|
28
|
+
export function createMuseParser() {
|
|
29
|
+
let outcome;
|
|
30
|
+
let sessionSent = false;
|
|
31
|
+
let streamed = '';
|
|
32
|
+
return {
|
|
33
|
+
outcome: () => outcome,
|
|
34
|
+
event(value) {
|
|
35
|
+
if (!isObject(value))
|
|
36
|
+
return [];
|
|
37
|
+
const events = [];
|
|
38
|
+
const stream = isObject(value.stream) ? value.stream : undefined;
|
|
39
|
+
const sessionId = stringField(stream, 'id');
|
|
40
|
+
if (!sessionSent && stream?.kind === 'session' && sessionId) {
|
|
41
|
+
sessionSent = true;
|
|
42
|
+
events.push({ type: 'session', sessionId });
|
|
43
|
+
}
|
|
44
|
+
const type = stringField(value, 'payload_type');
|
|
45
|
+
const payload = isObject(value.payload) ? value.payload : undefined;
|
|
46
|
+
const text = stringField(payload, 'text');
|
|
47
|
+
if (!type)
|
|
48
|
+
return events;
|
|
49
|
+
if (type === 'run.output.delta' && text) {
|
|
50
|
+
streamed += text;
|
|
51
|
+
events.push({ type: 'text-delta', text });
|
|
52
|
+
}
|
|
53
|
+
else if (type === 'task.lifecycle.side_effect_intent') {
|
|
54
|
+
const operation = stringField(payload?.event, 'operation');
|
|
55
|
+
if (operation && !operation.startsWith('model.'))
|
|
56
|
+
events.push({ type: 'tool-start', name: operation });
|
|
57
|
+
}
|
|
58
|
+
else if (type === 'approval_wait.effect.started' ||
|
|
59
|
+
(type === 'runtime.session' &&
|
|
60
|
+
payload?.kind === 'approval' &&
|
|
61
|
+
stringField(payload.event, 'kind') === 'requested')) {
|
|
62
|
+
// Headless exec cannot answer; museLive() can.
|
|
63
|
+
events.push({ type: 'approval-request', request: { id: approvalId(payload), kind: 'other', detail: payload } });
|
|
64
|
+
}
|
|
65
|
+
else if (type.startsWith(TERMINAL)) {
|
|
66
|
+
const verdict = type.slice(TERMINAL.length);
|
|
67
|
+
if (verdict === 'completed') {
|
|
68
|
+
outcome = { ok: true };
|
|
69
|
+
const final = (text ?? streamed).trim();
|
|
70
|
+
if (final)
|
|
71
|
+
events.push({ type: 'message', text: final });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const reason = stringField(payload, 'reason') ?? text;
|
|
75
|
+
const message = `Muse run ${verdict}${reason ? `: ${reason}` : ''}`;
|
|
76
|
+
outcome = { ok: false, error: message };
|
|
77
|
+
events.push({ type: 'error', message });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return events;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function approvalId(payload) {
|
|
85
|
+
return stringField(payload, 'id') ?? stringField(payload, 'approvalId') ?? 'approval';
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=muse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"muse.js","sourceRoot":"","sources":["../../../src/agents/drivers/muse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6C,MAAM,iBAAiB,CAAC;AAEtF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASlD,8CAA8C;AAC9C,MAAM,UAAU,IAAI,CAAC,UAA4B,EAAE;IACjD,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;QAClC,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC9F,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QACvC,YAAY,EAAE,gBAAgB;KAC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AAO,EAAE,IAAI,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,IAAI,UAAU,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AgentOutputParser } from '../cli-agent.js';
|
|
2
|
+
import type { AgentTask, CodingAgent } from '../types.js';
|
|
3
|
+
export interface OpencodeAgentOptions {
|
|
4
|
+
/** Executable name or path. Default `opencode`. */
|
|
5
|
+
command?: string;
|
|
6
|
+
/** opencode agent to use (`--agent`). */
|
|
7
|
+
agent?: string;
|
|
8
|
+
/** Pass `--auto`: approve every permission that is not explicitly denied. Default false. */
|
|
9
|
+
autoApprove?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* opencode in run mode (`opencode run --format json`). `task.model` is `provider/model`;
|
|
13
|
+
* `task.effort` maps to `--variant`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function opencode(options?: OpencodeAgentOptions): CodingAgent;
|
|
16
|
+
export declare function opencodeArgs(task: AgentTask, options?: OpencodeAgentOptions): string[];
|
|
17
|
+
export declare function createOpencodeParser(): AgentOutputParser;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { cliAgent } from '../cli-agent.js';
|
|
2
|
+
import { isObject, numberField, stringField } from './json.js';
|
|
3
|
+
const EDIT_TOOLS = new Set(['edit', 'write', 'patch', 'multiedit']);
|
|
4
|
+
/**
|
|
5
|
+
* opencode in run mode (`opencode run --format json`). `task.model` is `provider/model`;
|
|
6
|
+
* `task.effort` maps to `--variant`.
|
|
7
|
+
*/
|
|
8
|
+
export function opencode(options = {}) {
|
|
9
|
+
return cliAgent({
|
|
10
|
+
name: 'opencode',
|
|
11
|
+
command: options.command ?? 'opencode',
|
|
12
|
+
capabilities: { effort: ['minimal', 'low', 'medium', 'high', 'max'], usage: true },
|
|
13
|
+
args: (task) => opencodeArgs(task, options),
|
|
14
|
+
createParser: createOpencodeParser,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function opencodeArgs(task, options = {}) {
|
|
18
|
+
const args = ['run', '--format', 'json'];
|
|
19
|
+
if (options.agent)
|
|
20
|
+
args.push('--agent', options.agent);
|
|
21
|
+
if (options.autoApprove)
|
|
22
|
+
args.push('--auto');
|
|
23
|
+
if (task.model)
|
|
24
|
+
args.push('--model', task.model);
|
|
25
|
+
if (task.effort)
|
|
26
|
+
args.push('--variant', task.effort);
|
|
27
|
+
if (task.extraArgs)
|
|
28
|
+
args.push(...task.extraArgs);
|
|
29
|
+
return [...args, '--', task.prompt];
|
|
30
|
+
}
|
|
31
|
+
export function createOpencodeParser() {
|
|
32
|
+
let outcome;
|
|
33
|
+
let sessionSent = false;
|
|
34
|
+
const totals = { inputTokens: 0, outputTokens: 0, cachedInputTokens: 0 };
|
|
35
|
+
let costUsd = 0;
|
|
36
|
+
let steps = 0;
|
|
37
|
+
return {
|
|
38
|
+
outcome: () => outcome ?? (steps > 0 ? { ok: true } : undefined),
|
|
39
|
+
event(value) {
|
|
40
|
+
if (!isObject(value))
|
|
41
|
+
return [];
|
|
42
|
+
const events = [];
|
|
43
|
+
const sessionId = stringField(value, 'sessionID');
|
|
44
|
+
if (sessionId && !sessionSent) {
|
|
45
|
+
sessionSent = true;
|
|
46
|
+
events.push({ type: 'session', sessionId });
|
|
47
|
+
}
|
|
48
|
+
const part = isObject(value.part) ? value.part : undefined;
|
|
49
|
+
switch (value.type) {
|
|
50
|
+
case 'text': {
|
|
51
|
+
const text = stringField(part, 'text')?.trim();
|
|
52
|
+
if (text)
|
|
53
|
+
events.push({ type: 'message', text });
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'tool_use': {
|
|
57
|
+
const name = stringField(part, 'tool') ?? 'tool';
|
|
58
|
+
const id = stringField(part, 'callID') ?? stringField(part, 'id');
|
|
59
|
+
const state = isObject(part?.state) ? part.state : undefined;
|
|
60
|
+
const failed = state?.status === 'error';
|
|
61
|
+
const output = stringField(state, 'output') ?? stringField(state, 'error');
|
|
62
|
+
events.push({
|
|
63
|
+
type: 'tool-end',
|
|
64
|
+
...(id ? { id } : {}),
|
|
65
|
+
name,
|
|
66
|
+
isError: failed,
|
|
67
|
+
...(output !== undefined ? { output } : {}),
|
|
68
|
+
});
|
|
69
|
+
const path = stringField(state?.input, 'filePath');
|
|
70
|
+
if (!failed && EDIT_TOOLS.has(name) && path)
|
|
71
|
+
events.push({ type: 'file-change', paths: [path] });
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 'step_finish': {
|
|
75
|
+
steps += 1;
|
|
76
|
+
const tokens = isObject(part?.tokens) ? part.tokens : undefined;
|
|
77
|
+
totals.inputTokens += numberField(tokens, 'input') ?? 0;
|
|
78
|
+
totals.outputTokens += numberField(tokens, 'output') ?? 0;
|
|
79
|
+
totals.cachedInputTokens += numberField(tokens?.cache, 'read') ?? 0;
|
|
80
|
+
costUsd += numberField(part, 'cost') ?? 0;
|
|
81
|
+
// Running totals across steps, so the last usage event covers the whole run.
|
|
82
|
+
if (tokens) {
|
|
83
|
+
events.push({
|
|
84
|
+
type: 'usage',
|
|
85
|
+
usage: { ...totals, totalTokens: totals.inputTokens + totals.outputTokens },
|
|
86
|
+
costUsd,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'error': {
|
|
92
|
+
const error = isObject(value.error) ? value.error : undefined;
|
|
93
|
+
const message = stringField(error?.data, 'message') ?? stringField(error, 'name') ?? 'opencode error';
|
|
94
|
+
outcome = { ok: false, error: message };
|
|
95
|
+
events.push({ type: 'error', message });
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return events;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=opencode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode.js","sourceRoot":"","sources":["../../../src/agents/drivers/opencode.ts"],"names":[],"mappings":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xC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;oBACxC,MAAM;gBACR,CAAC;YACH,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-provider credentials an agent CLI would otherwise pick up from the parent
|
|
3
|
+
* process. Remove them when the agent should use its own login and billing instead
|
|
4
|
+
* of your application's keys.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PROVIDER_CREDENTIAL_VARS: readonly string[];
|
|
7
|
+
export interface ScrubEnvOptions {
|
|
8
|
+
/** Variable names to drop: exact names or patterns. */
|
|
9
|
+
names?: readonly (string | RegExp)[];
|
|
10
|
+
/** Drop any variable whose value matches one of these (a token prefix, for example). */
|
|
11
|
+
values?: readonly RegExp[];
|
|
12
|
+
}
|
|
13
|
+
/** A copy of `env` without the matching variables. `undefined` entries are dropped too. */
|
|
14
|
+
export declare function scrubEnv(env: NodeJS.ProcessEnv, options: ScrubEnvOptions): NodeJS.ProcessEnv;
|
|
15
|
+
/** `env` without `PROVIDER_CREDENTIAL_VARS`: the agent falls back to its own login. */
|
|
16
|
+
export declare function withoutProviderCredentials(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-provider credentials an agent CLI would otherwise pick up from the parent
|
|
3
|
+
* process. Remove them when the agent should use its own login and billing instead
|
|
4
|
+
* of your application's keys.
|
|
5
|
+
*/
|
|
6
|
+
export const PROVIDER_CREDENTIAL_VARS = [
|
|
7
|
+
'ANTHROPIC_API_KEY',
|
|
8
|
+
'ANTHROPIC_AUTH_TOKEN',
|
|
9
|
+
'ANTHROPIC_BASE_URL',
|
|
10
|
+
'CLAUDE_CODE_USE_BEDROCK',
|
|
11
|
+
'CLAUDE_CODE_USE_VERTEX',
|
|
12
|
+
'OPENAI_API_KEY',
|
|
13
|
+
'OPENAI_BASE_URL',
|
|
14
|
+
'OPENAI_ORG_ID',
|
|
15
|
+
'CODEX_API_KEY',
|
|
16
|
+
'GEMINI_API_KEY',
|
|
17
|
+
'GOOGLE_API_KEY',
|
|
18
|
+
'GOOGLE_APPLICATION_CREDENTIALS',
|
|
19
|
+
'GOOGLE_GENAI_USE_VERTEXAI',
|
|
20
|
+
];
|
|
21
|
+
/** A copy of `env` without the matching variables. `undefined` entries are dropped too. */
|
|
22
|
+
export function scrubEnv(env, options) {
|
|
23
|
+
const names = options.names ?? [];
|
|
24
|
+
const values = options.values ?? [];
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const [name, value] of Object.entries(env)) {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
continue;
|
|
29
|
+
if (names.some((match) => (typeof match === 'string' ? match === name : matches(match, name))))
|
|
30
|
+
continue;
|
|
31
|
+
if (values.some((match) => matches(match, value)))
|
|
32
|
+
continue;
|
|
33
|
+
result[name] = value;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
/** `test()` from the start every time: `/g` and `/y` patterns keep `lastIndex` between calls. */
|
|
38
|
+
function matches(pattern, text) {
|
|
39
|
+
pattern.lastIndex = 0;
|
|
40
|
+
return pattern.test(text);
|
|
41
|
+
}
|
|
42
|
+
/** `env` without `PROVIDER_CREDENTIAL_VARS`: the agent falls back to its own login. */
|
|
43
|
+
export function withoutProviderCredentials(env = process.env) {
|
|
44
|
+
return scrubEnv(env, { names: PROVIDER_CREDENTIAL_VARS });
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/agents/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsB;IACzD,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;IACp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AAE,wBAAwB,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface EventQueueLimits {
|
|
2
|
+
/** Events kept for a run nobody iterates yet. The oldest are dropped past this. */
|
|
3
|
+
unreadItems: number;
|
|
4
|
+
/** Approximate bytes kept for a run nobody iterates yet. The oldest events are dropped past this. */
|
|
5
|
+
unreadBytes: number;
|
|
6
|
+
/** While iterated: above this many buffered bytes, ask the producer to pause. */
|
|
7
|
+
highWaterBytes: number;
|
|
8
|
+
/** While iterated: at or below this many buffered bytes, let a paused producer resume. */
|
|
9
|
+
lowWaterBytes: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Single-consumer queue bridging callbacks to `for await`, bounded by approximate size.
|
|
13
|
+
*
|
|
14
|
+
* Before anyone iterates, it keeps only the newest events within `unreadItems` and
|
|
15
|
+
* `unreadBytes`, since a run awaited only through `result` needs none of them. While
|
|
16
|
+
* iterated, it drops nothing: past `highWaterBytes` it calls `onPressure(true)` so the
|
|
17
|
+
* producer stops reading, and `onPressure(false)` once the consumer catches up.
|
|
18
|
+
* A consumer that stops iterating early releases the pressure and the rest is discarded.
|
|
19
|
+
*/
|
|
20
|
+
export declare class EventQueue<T> {
|
|
21
|
+
private readonly sizeOf;
|
|
22
|
+
/** Called with true when the producer should pause and false when it may resume. */
|
|
23
|
+
onPressure: ((paused: boolean) => void) | undefined;
|
|
24
|
+
private readonly items;
|
|
25
|
+
private readonly limits;
|
|
26
|
+
private bytes;
|
|
27
|
+
private closed;
|
|
28
|
+
private claimed;
|
|
29
|
+
private abandoned;
|
|
30
|
+
private pressured;
|
|
31
|
+
private wake;
|
|
32
|
+
private roomWaiters;
|
|
33
|
+
constructor(sizeOf?: (item: T) => number, limits?: Partial<EventQueueLimits>);
|
|
34
|
+
/** Approximate bytes currently buffered. */
|
|
35
|
+
get bufferedBytes(): number;
|
|
36
|
+
push(item: T): void;
|
|
37
|
+
close(): void;
|
|
38
|
+
/** Resolve once the producer may go on: the queue is below its high-water mark, or nobody reads it. */
|
|
39
|
+
room(): Promise<void>;
|
|
40
|
+
iterate(): AsyncGenerator<T>;
|
|
41
|
+
private setPressure;
|
|
42
|
+
}
|
|
43
|
+
/** A cheap size estimate for a JSON-like value: string lengths plus a few bytes per other value. */
|
|
44
|
+
export declare function approximateSize(value: unknown, depth?: number): number;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const DEFAULT_LIMITS = {
|
|
2
|
+
unreadItems: 1_000,
|
|
3
|
+
unreadBytes: 8 * 1024 * 1024,
|
|
4
|
+
highWaterBytes: 8 * 1024 * 1024,
|
|
5
|
+
lowWaterBytes: 1024 * 1024,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Single-consumer queue bridging callbacks to `for await`, bounded by approximate size.
|
|
9
|
+
*
|
|
10
|
+
* Before anyone iterates, it keeps only the newest events within `unreadItems` and
|
|
11
|
+
* `unreadBytes`, since a run awaited only through `result` needs none of them. While
|
|
12
|
+
* iterated, it drops nothing: past `highWaterBytes` it calls `onPressure(true)` so the
|
|
13
|
+
* producer stops reading, and `onPressure(false)` once the consumer catches up.
|
|
14
|
+
* A consumer that stops iterating early releases the pressure and the rest is discarded.
|
|
15
|
+
*/
|
|
16
|
+
export class EventQueue {
|
|
17
|
+
sizeOf;
|
|
18
|
+
/** Called with true when the producer should pause and false when it may resume. */
|
|
19
|
+
onPressure;
|
|
20
|
+
items = [];
|
|
21
|
+
limits;
|
|
22
|
+
bytes = 0;
|
|
23
|
+
closed = false;
|
|
24
|
+
claimed = false;
|
|
25
|
+
abandoned = false;
|
|
26
|
+
pressured = false;
|
|
27
|
+
wake;
|
|
28
|
+
roomWaiters = [];
|
|
29
|
+
constructor(sizeOf = () => 0, limits = {}) {
|
|
30
|
+
this.sizeOf = sizeOf;
|
|
31
|
+
this.limits = { ...DEFAULT_LIMITS, ...limits };
|
|
32
|
+
}
|
|
33
|
+
/** Approximate bytes currently buffered. */
|
|
34
|
+
get bufferedBytes() {
|
|
35
|
+
return this.bytes;
|
|
36
|
+
}
|
|
37
|
+
push(item) {
|
|
38
|
+
if (this.closed || this.abandoned)
|
|
39
|
+
return;
|
|
40
|
+
const size = this.sizeOf(item);
|
|
41
|
+
this.items.push({ item, size });
|
|
42
|
+
this.bytes += size;
|
|
43
|
+
if (!this.claimed) {
|
|
44
|
+
// The newest event always stays, so `done` survives however large the ones before it were.
|
|
45
|
+
while (this.items.length > 1 &&
|
|
46
|
+
(this.items.length > this.limits.unreadItems || this.bytes > this.limits.unreadBytes)) {
|
|
47
|
+
this.bytes -= this.items.shift().size;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (!this.pressured && this.bytes > this.limits.highWaterBytes) {
|
|
51
|
+
this.setPressure(true);
|
|
52
|
+
}
|
|
53
|
+
this.wake?.();
|
|
54
|
+
}
|
|
55
|
+
close() {
|
|
56
|
+
this.closed = true;
|
|
57
|
+
this.wake?.();
|
|
58
|
+
}
|
|
59
|
+
/** Resolve once the producer may go on: the queue is below its high-water mark, or nobody reads it. */
|
|
60
|
+
room() {
|
|
61
|
+
if (!this.pressured)
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
return new Promise((resolve) => this.roomWaiters.push(resolve));
|
|
64
|
+
}
|
|
65
|
+
async *iterate() {
|
|
66
|
+
if (this.claimed)
|
|
67
|
+
throw new Error('An AgentRun can be iterated only once.');
|
|
68
|
+
this.claimed = true;
|
|
69
|
+
try {
|
|
70
|
+
for (;;) {
|
|
71
|
+
const next = this.items.shift();
|
|
72
|
+
if (next !== undefined) {
|
|
73
|
+
this.bytes -= next.size;
|
|
74
|
+
if (this.pressured && this.bytes <= this.limits.lowWaterBytes)
|
|
75
|
+
this.setPressure(false);
|
|
76
|
+
yield next.item;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (this.closed)
|
|
80
|
+
return;
|
|
81
|
+
await new Promise((resolve) => {
|
|
82
|
+
this.wake = resolve;
|
|
83
|
+
});
|
|
84
|
+
this.wake = undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
// Done, or the consumer broke out early: nothing reads further events, so do not hold the producer.
|
|
89
|
+
this.abandoned = true;
|
|
90
|
+
this.items.length = 0;
|
|
91
|
+
this.bytes = 0;
|
|
92
|
+
if (this.pressured)
|
|
93
|
+
this.setPressure(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
setPressure(paused) {
|
|
97
|
+
this.pressured = paused;
|
|
98
|
+
this.onPressure?.(paused);
|
|
99
|
+
if (!paused) {
|
|
100
|
+
const waiters = this.roomWaiters;
|
|
101
|
+
this.roomWaiters = [];
|
|
102
|
+
waiters.forEach((resolve) => resolve());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** A cheap size estimate for a JSON-like value: string lengths plus a few bytes per other value. */
|
|
107
|
+
export function approximateSize(value, depth = 0) {
|
|
108
|
+
if (typeof value === 'string')
|
|
109
|
+
return value.length;
|
|
110
|
+
if (value === null || typeof value !== 'object' || depth > 8)
|
|
111
|
+
return 8;
|
|
112
|
+
let size = 8;
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
for (const item of value)
|
|
115
|
+
size += approximateSize(item, depth + 1);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
for (const [key, item] of Object.entries(value))
|
|
119
|
+
size += key.length + approximateSize(item, depth + 1);
|
|
120
|
+
}
|
|
121
|
+
return size;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=event-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue.js","sourceRoot":"","sources":["../../src/agents/event-queue.ts"],"names":[],"mappings":"AAWA,MAAM,cAAc,GAAqB;IACvC,WAAW,EAAE,KAAK;IAClB,WAAW,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IAC5B,cAAc,EAAE,CAAC,GAAG,IAAI,GA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,IAAI,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentCapabilities, AgentEvent, AgentTask, CodingAgent } from './types.js';
|
|
2
|
+
export type HostedTaskState = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
3
|
+
/** What a hosted provider receives. `cwd` is the provider's workspace reference (a repo, a branch...). */
|
|
4
|
+
export type HostedTaskRequest = Omit<AgentTask, 'env' | 'signal' | 'onApproval' | 'timeoutMs'>;
|
|
5
|
+
export interface HostedPoll {
|
|
6
|
+
state: HostedTaskState;
|
|
7
|
+
/** Events since the previous poll. */
|
|
8
|
+
events?: AgentEvent[];
|
|
9
|
+
/** Opaque position handed back on the next poll. */
|
|
10
|
+
cursor?: string;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A remote coding-agent service: tasks run on the vendor's machines and are polled.
|
|
15
|
+
* Implement this for a hosted product and pass it to `hostedAgent()`.
|
|
16
|
+
*/
|
|
17
|
+
export interface HostedAgentProvider {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly capabilities?: AgentCapabilities;
|
|
20
|
+
start(task: HostedTaskRequest, signal: AbortSignal): Promise<{
|
|
21
|
+
id: string;
|
|
22
|
+
}>;
|
|
23
|
+
poll(id: string, cursor: string | undefined, signal: AbortSignal): Promise<HostedPoll>;
|
|
24
|
+
/** Add input to a running task (backs `AgentRun.steer`). */
|
|
25
|
+
send?(id: string, text: string): Promise<void>;
|
|
26
|
+
cancel(id: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export interface HostedAgentOptions {
|
|
29
|
+
/** Delay between polls. Default 5 s. */
|
|
30
|
+
pollIntervalMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Adapt a `HostedAgentProvider` to `CodingAgent`, so hosted and local agents share one API. */
|
|
33
|
+
export declare function hostedAgent(provider: HostedAgentProvider, options?: HostedAgentOptions): CodingAgent;
|