@jini-ai/agent-runtime 0.4.11 → 0.6.10
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 +83 -1
- package/dist/acp-model-probe.d.ts +2 -20
- package/dist/agent-protocol/acp/json.js +46 -37
- package/dist/agent-protocol/acp/models.js +91 -73
- package/dist/agent-protocol/acp/rpc.d.ts +3 -2
- package/dist/agent-protocol/acp/rpc.js +3 -2
- package/dist/agent-protocol/acp/session-params.d.ts +1 -1
- package/dist/agent-protocol/acp/session-params.js +33 -30
- package/dist/agent-protocol/acp/session.d.ts +3 -1
- package/dist/agent-protocol/acp/session.js +62 -24
- package/dist/agent-protocol/acp/updates.js +49 -35
- package/dist/agent-protocol/pi-rpc/session.js +3 -1
- package/dist/anthropic-live-models.d.ts +12 -4
- package/dist/anthropic-live-models.js +0 -0
- package/dist/auth.js +84 -91
- package/dist/claude-code-models.d.ts +6 -5
- package/dist/claude-code-models.js +19 -12
- package/dist/claude-segment-usage.d.ts +3 -3
- package/dist/claude-segment-usage.js +63 -29
- package/dist/claude-stream.d.ts +2 -0
- package/dist/claude-stream.js +16 -5
- package/dist/copilot-stream.js +42 -50
- package/dist/defs/aider.js +3 -4
- package/dist/defs/amr.js +52 -61
- package/dist/defs/antigravity.d.ts +6 -5
- package/dist/defs/antigravity.js +48 -34
- package/dist/defs/auggie.d.ts +1 -1
- package/dist/defs/claude-compatible-args.d.ts +19 -0
- package/dist/defs/claude-compatible-args.js +42 -0
- package/dist/defs/claude.d.ts +7 -2
- package/dist/defs/claude.js +96 -85
- package/dist/defs/cline.d.ts +1 -1
- package/dist/defs/codebuddy.d.ts +1 -1
- package/dist/defs/codebuddy.js +29 -46
- package/dist/defs/codex.d.ts +15 -3
- package/dist/defs/codex.js +143 -108
- package/dist/defs/cursor-agent.d.ts +9 -7
- package/dist/defs/cursor-agent.js +53 -51
- package/dist/defs/devin.d.ts +1 -1
- package/dist/defs/goose.d.ts +1 -1
- package/dist/defs/hermes.d.ts +1 -1
- package/dist/defs/kilo.d.ts +1 -1
- package/dist/defs/kimi.d.ts +1 -1
- package/dist/defs/kiro.d.ts +1 -1
- package/dist/defs/opencode.d.ts +5 -4
- package/dist/defs/opencode.js +26 -32
- package/dist/defs/pi.d.ts +6 -5
- package/dist/defs/pi.js +24 -26
- package/dist/defs/qoder.d.ts +4 -3
- package/dist/defs/qoder.js +25 -25
- package/dist/defs/reasonix.d.ts +1 -1
- package/dist/defs/shared.d.ts +12 -3
- package/dist/defs/shared.js +19 -13
- package/dist/defs/trae-cli.d.ts +1 -1
- package/dist/defs/vibe.d.ts +1 -1
- package/dist/detection.d.ts +13 -20
- package/dist/detection.js +129 -111
- package/dist/env.js +56 -41
- package/dist/executables.js +103 -114
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-event-stream.js +611 -527
- package/dist/launch.js +44 -37
- package/dist/model-discovery-adapters.d.ts +17 -0
- package/dist/model-discovery-adapters.js +223 -164
- package/dist/model-discovery-config.js +107 -87
- package/dist/model-discovery-sdk.d.ts +16 -2
- package/dist/model-discovery-sdk.js +4 -3
- package/dist/model-discovery-shared.d.ts +14 -0
- package/dist/model-discovery-shared.js +50 -15
- package/dist/model-discovery-types.d.ts +2 -0
- package/dist/model-discovery.js +219 -117
- package/dist/models.d.ts +14 -1
- package/dist/models.js +75 -19
- package/dist/native-tool-policy.d.ts +29 -0
- package/dist/native-tool-policy.js +36 -0
- package/dist/opencode-log.js +46 -30
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +3 -3
- package/dist/providers/aihubmix.js +13 -18
- package/dist/providers/anthropic-messages.d.ts +7 -0
- package/dist/providers/anthropic-messages.js +45 -21
- package/dist/providers/azure-chat.d.ts +5 -0
- package/dist/providers/azure-chat.js +13 -5
- package/dist/providers/connection-guard.d.ts +2 -45
- package/dist/providers/connection-guard.js +11 -10
- package/dist/providers/connection-test.d.ts +4 -0
- package/dist/providers/connection-test.js +127 -110
- package/dist/providers/elevenlabs.js +4 -1
- package/dist/providers/google-messages.d.ts +4 -0
- package/dist/providers/google-messages.js +48 -23
- package/dist/providers/google-schema.js +17 -23
- package/dist/providers/model-catalog.js +160 -145
- package/dist/providers/oauth-callback-server.js +37 -34
- package/dist/providers/oauth-credentials.js +23 -23
- package/dist/providers/oauth-tokens.js +16 -24
- package/dist/providers/openai-chat.d.ts +42 -0
- package/dist/providers/openai-chat.js +80 -10
- package/dist/providers/operation-schema.d.ts +25 -0
- package/dist/providers/operation-schema.js +226 -0
- package/dist/providers/response-text.d.ts +10 -0
- package/dist/providers/response-text.js +23 -0
- package/dist/providers/tool-turn-types.d.ts +56 -9
- package/dist/providers/tool-turn.d.ts +7 -0
- package/dist/providers/tool-turn.js +120 -32
- package/dist/qoder-stream.js +93 -80
- package/dist/registry.d.ts +45 -0
- package/dist/registry.js +39 -0
- package/dist/runtime-state.d.ts +1 -1
- package/dist/types.d.ts +43 -1
- package/package.json +19 -14
|
@@ -180,7 +180,7 @@ function runInitializeProbe(bin, env) {
|
|
|
180
180
|
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
181
181
|
},
|
|
182
182
|
// A timeout or non-zero exit still hands back what was captured; the parser decides.
|
|
183
|
-
(_err, stdout) => resolve(
|
|
183
|
+
(_err, stdout) => resolve(stdout));
|
|
184
184
|
child.stdin?.on('error', () => { });
|
|
185
185
|
child.stdin?.end(CLAUDE_CODE_INITIALIZE_REQUEST);
|
|
186
186
|
}
|
|
@@ -194,11 +194,10 @@ const defaultIo = {
|
|
|
194
194
|
readConfigFile: (path) => readFile(path, 'utf8').catch(() => null),
|
|
195
195
|
};
|
|
196
196
|
let activeIo = defaultIo;
|
|
197
|
-
const cache = defaultRuntimeState.claudeModels;
|
|
198
197
|
/** Test-only: install fake I/O (or `null` to restore the real one) and clear the process cache. */
|
|
199
198
|
export function setClaudeCodeModelIoForTesting(io) {
|
|
200
199
|
activeIo = io ?? defaultIo;
|
|
201
|
-
|
|
200
|
+
defaultRuntimeState.claudeModels.clear();
|
|
202
201
|
}
|
|
203
202
|
/** One cache slot per binary + config location + auth-affecting env, fingerprinted so no secret is
|
|
204
203
|
* retained as a `Map` key. Two accounts on one host must not share a picker list. */
|
|
@@ -228,21 +227,29 @@ async function discoverClaudeCodeModels(bin, env, io) {
|
|
|
228
227
|
return null;
|
|
229
228
|
}
|
|
230
229
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
230
|
+
/** Normalizes the object and the published positional call forms to one shape. */
|
|
231
|
+
function normalizeLoadArgs(required, optional) {
|
|
232
|
+
if (typeof required === 'string')
|
|
233
|
+
return { bin: required, env: optional, options: {} };
|
|
234
|
+
return { bin: required.bin, env: required.env, options: optional };
|
|
235
|
+
}
|
|
236
|
+
/** One in-flight-or-settled discovery per cache key and TTL window; a miss starts (and caches) a new one. */
|
|
237
|
+
function cachedDiscovery(required) {
|
|
238
|
+
const { bin, env, cache, io, now } = required;
|
|
239
239
|
const key = cacheKeyFor(bin, env);
|
|
240
240
|
const cached = cache.get(key);
|
|
241
241
|
const pending = cached && cached.expiresAt > now() ? cached.value : null;
|
|
242
242
|
const value = pending ?? discoverClaudeCodeModels(bin, env, io);
|
|
243
243
|
if (!pending)
|
|
244
244
|
cache.set(key, { expiresAt: now() + CLAUDE_CODE_MODEL_CACHE_TTL_MS, value });
|
|
245
|
-
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
export async function loadClaudeCodeModels(required, optional = {}, _fallbackModels = [], clock = Date.now) {
|
|
248
|
+
const { bin, env, options } = normalizeLoadArgs(required, optional);
|
|
249
|
+
const state = options.state ?? defaultRuntimeState;
|
|
250
|
+
// The test-installed I/O only applies to the shared default state; an injected state gets real I/O.
|
|
251
|
+
const io = options.io ?? (state === defaultRuntimeState ? activeIo : defaultIo);
|
|
252
|
+
const live = await cachedDiscovery({ bin, env, cache: state.claudeModels, io, now: options.now ?? clock });
|
|
246
253
|
return live && live.length > 0 ? [...live] : null;
|
|
247
254
|
}
|
|
248
255
|
//# sourceMappingURL=claude-code-models.js.map
|
|
@@ -14,9 +14,9 @@ export declare function createClaudeSegmentUsage(_required: Record<string, never
|
|
|
14
14
|
}, _optional?: {}) => {
|
|
15
15
|
cumulativeCostUsd?: number;
|
|
16
16
|
costSessionId?: string;
|
|
17
|
-
usage:
|
|
18
|
-
costUsd:
|
|
19
|
-
durationMs:
|
|
17
|
+
usage: unknown;
|
|
18
|
+
costUsd: unknown;
|
|
19
|
+
durationMs: unknown;
|
|
20
20
|
};
|
|
21
21
|
setSession: ({ id }: {
|
|
22
22
|
id: unknown;
|
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
function isFiniteNumber(value) {
|
|
2
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
3
|
+
}
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return Boolean(value) && typeof value === 'object';
|
|
6
|
+
}
|
|
7
|
+
/** Sum each counter across every message observed in the segment. O(m·k). */
|
|
8
|
+
function sumObserved({ messages }) {
|
|
9
|
+
const observed = {};
|
|
10
|
+
for (const counters of messages.values()) {
|
|
11
|
+
for (const [key, value] of Object.entries(counters))
|
|
12
|
+
observed[key] = (observed[key] ?? 0) + value;
|
|
13
|
+
}
|
|
14
|
+
return observed;
|
|
15
|
+
}
|
|
16
|
+
/** Overlay observed totals onto the reported usage, keeping the larger finite counter. */
|
|
17
|
+
function mergeUsage({ reported, observed }) {
|
|
18
|
+
const usage = { ...(isRecord(reported) ? reported : {}) };
|
|
19
|
+
for (const [key, value] of Object.entries(observed)) {
|
|
20
|
+
const current = usage[key];
|
|
21
|
+
usage[key] = isFiniteNumber(current) ? Math.max(current, value) : value;
|
|
22
|
+
}
|
|
23
|
+
return Object.keys(usage).length ? usage : reported ?? null;
|
|
24
|
+
}
|
|
25
|
+
/** Sum the valid (finite, non-negative) per-model `costUSD` values the CLI reported. */
|
|
26
|
+
function sumModelCosts({ modelUsage }) {
|
|
27
|
+
const models = isRecord(modelUsage) ? Object.values(modelUsage) : [];
|
|
28
|
+
return models.reduce((sum, model) => {
|
|
29
|
+
const cost = isRecord(model) ? model.costUSD : undefined;
|
|
30
|
+
return sum + (isFiniteNumber(cost) && cost >= 0 ? cost : 0);
|
|
31
|
+
}, 0);
|
|
32
|
+
}
|
|
33
|
+
/** Never infer a monetary charge from token counts: only CLI-reported costs are eligible. */
|
|
34
|
+
function resolveCostUsd({ result }) {
|
|
35
|
+
const reportedModelCost = sumModelCosts({ modelUsage: result.modelUsage });
|
|
36
|
+
if (reportedModelCost <= 0)
|
|
37
|
+
return result.total_cost_usd ?? null;
|
|
38
|
+
return Math.max(typeof result.total_cost_usd === 'number' ? result.total_cost_usd : 0, reportedModelCost);
|
|
39
|
+
}
|
|
40
|
+
/** Prefer the CLI's positive duration; otherwise measure an active or interrupted segment. */
|
|
41
|
+
function resolveDurationMs({ duration, active, elapsedMs }) {
|
|
42
|
+
if (typeof duration === 'number' && duration > 0)
|
|
43
|
+
return duration;
|
|
44
|
+
return active ? Math.max(0, elapsedMs) : duration ?? null;
|
|
45
|
+
}
|
|
1
46
|
/** Token counters are per segment; Claude's dollar counter spans the session.
|
|
2
47
|
* Aborted results can zero counters already streamed. */
|
|
3
48
|
export function createClaudeSegmentUsage(_required, { nowMs = Date.now, costBasis = 'session' } = {}) {
|
|
@@ -12,50 +57,39 @@ export function createClaudeSegmentUsage(_required, { nowMs = Date.now, costBasi
|
|
|
12
57
|
/** Merge cumulative counters for one message; wrappers repeat the same streamed usage.
|
|
13
58
|
* O(k) per snapshot in k reported counters; retained state is O(m·k) for m messages in a segment. */
|
|
14
59
|
function observe({ messageId, usage }, _optional = {}) {
|
|
15
|
-
if (!usage
|
|
60
|
+
if (!isRecord(usage))
|
|
16
61
|
return;
|
|
17
62
|
const previous = messages.get(messageId) ?? {};
|
|
18
63
|
for (const [key, value] of Object.entries(usage)) {
|
|
19
|
-
if (
|
|
64
|
+
if (isFiniteNumber(value) && value >= 0)
|
|
20
65
|
previous[key] = Math.max(previous[key] ?? 0, value);
|
|
21
66
|
}
|
|
22
67
|
if (Object.keys(previous).length)
|
|
23
68
|
messages.set(messageId, previous);
|
|
24
69
|
}
|
|
70
|
+
/** Preserve the cumulative snapshot rather than calling it a per-run charge. A zeroed
|
|
71
|
+
* aborted result still uses the existing model-cost fallback for its interrupted segment. */
|
|
72
|
+
function cumulativeCostOf({ costUsd, interrupted, result }) {
|
|
73
|
+
if (costBasis !== 'session' || sessionId === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (!isFiniteNumber(costUsd) || costUsd < 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
return interrupted && result.total_cost_usd === 0 ? undefined : costUsd;
|
|
78
|
+
}
|
|
25
79
|
/** Produce one segment's totals and release its snapshots. Never infer a monetary charge
|
|
26
80
|
* from token counts: only CLI-reported costs are eligible. O(m·k), no external effects. */
|
|
27
81
|
function finish({ result, interrupted }, _optional = {}) {
|
|
28
|
-
const usage = {
|
|
29
|
-
const
|
|
30
|
-
for (const counters of messages.values()) {
|
|
31
|
-
for (const [key, value] of Object.entries(counters))
|
|
32
|
-
observed[key] = (observed[key] ?? 0) + value;
|
|
33
|
-
}
|
|
34
|
-
for (const [key, value] of Object.entries(observed)) {
|
|
35
|
-
const reported = usage[key];
|
|
36
|
-
usage[key] = typeof reported === 'number' && Number.isFinite(reported) ? Math.max(reported, value) : value;
|
|
37
|
-
}
|
|
38
|
-
const modelCosts = result.modelUsage && typeof result.modelUsage === 'object' ? Object.values(result.modelUsage) : [];
|
|
39
|
-
const reportedModelCost = modelCosts.reduce((sum, model) => {
|
|
40
|
-
const cost = model && typeof model === 'object' ? model.costUSD : undefined;
|
|
41
|
-
return sum + (typeof cost === 'number' && Number.isFinite(cost) && cost >= 0 ? cost : 0);
|
|
42
|
-
}, 0);
|
|
43
|
-
const costUsd = reportedModelCost > 0 ? Math.max(typeof result.total_cost_usd === 'number' ? result.total_cost_usd : 0, reportedModelCost) : result.total_cost_usd ?? null;
|
|
82
|
+
const usage = mergeUsage({ reported: result.usage, observed: sumObserved({ messages }) });
|
|
83
|
+
const costUsd = resolveCostUsd({ result });
|
|
44
84
|
const endedAt = nowMs();
|
|
45
|
-
const
|
|
46
|
-
const durationMs = typeof duration === 'number' && duration > 0 ? duration
|
|
47
|
-
: messages.size || interrupted ? Math.max(0, endedAt - startedAt) : duration ?? null;
|
|
85
|
+
const durationMs = resolveDurationMs({ duration: result.duration_ms, active: messages.size > 0 || interrupted, elapsedMs: endedAt - startedAt });
|
|
48
86
|
messages.clear();
|
|
49
87
|
startedAt = endedAt;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
typeof costUsd === 'number' && Number.isFinite(costUsd) && costUsd >= 0 &&
|
|
54
|
-
!(interrupted && result.total_cost_usd === 0);
|
|
55
|
-
return { usage: Object.keys(usage).length ? usage : result.usage ?? null,
|
|
56
|
-
costUsd: cumulative ? null : costUsd, durationMs,
|
|
88
|
+
const cumulativeCostUsd = cumulativeCostOf({ costUsd, interrupted, result });
|
|
89
|
+
return { usage,
|
|
90
|
+
costUsd: cumulativeCostUsd === undefined ? costUsd : null, durationMs,
|
|
57
91
|
...(costBasis === 'session' && sessionId !== undefined ? { costSessionId: sessionId } : {}),
|
|
58
|
-
...(
|
|
92
|
+
...(cumulativeCostUsd === undefined ? {} : { cumulativeCostUsd }),
|
|
59
93
|
};
|
|
60
94
|
}
|
|
61
95
|
return { observe, finish, setSession, hasObserved: () => messages.size > 0 };
|
package/dist/claude-stream.d.ts
CHANGED
package/dist/claude-stream.js
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* a larger, riskier change than this pass makes. They stay as closures,
|
|
37
37
|
* exercised only through `feed`/`flush` in the test suite.
|
|
38
38
|
*/
|
|
39
|
+
import { readDelegatedResult } from '@jini-ai/protocol';
|
|
39
40
|
import { createRoleMarkerGuard } from './role-marker-guard.js';
|
|
40
41
|
import { createClaudeSegmentUsage } from './claude-segment-usage.js';
|
|
41
42
|
function isRecord(value) {
|
|
@@ -306,10 +307,13 @@ export function handleUserMessage(obj, onEvent) {
|
|
|
306
307
|
if (!isRecord(block))
|
|
307
308
|
continue;
|
|
308
309
|
if (block.type === 'tool_result') {
|
|
310
|
+
const delegated = readDelegatedResult({ content: block.content });
|
|
309
311
|
onEvent({
|
|
310
312
|
type: 'tool_result',
|
|
311
313
|
toolUseId: block.tool_use_id,
|
|
314
|
+
// Keep original pixels until the daemon verifies the run, outcome and digest.
|
|
312
315
|
content: stringifyToolResult(block.content),
|
|
316
|
+
...(delegated ? { delegatedToolUseId: delegated.marker.toolUseId, delegatedResultContent: delegated.content } : {}),
|
|
313
317
|
isError: Boolean(block.is_error),
|
|
314
318
|
});
|
|
315
319
|
}
|
|
@@ -638,7 +642,7 @@ export function createClaudeStreamHandler({ onEvent }, options = {}) {
|
|
|
638
642
|
if (typeof message.model === 'string')
|
|
639
643
|
onEvent({ type: 'status', label: 'model', model: message.model });
|
|
640
644
|
const { textMsgId, thinkingMsgId, textAlreadyStreamed, thinkingAlreadyStreamed } = resolveAssistantMessageIds(message);
|
|
641
|
-
segmentUsage.observe({ messageId:
|
|
645
|
+
segmentUsage.observe({ messageId: usageMessageKey(), usage: message.usage });
|
|
642
646
|
// Per-turn `stop_reason` is emitted as `turn_end` AFTER the content
|
|
643
647
|
// blocks have been processed (see below). When `--include-partial-
|
|
644
648
|
// messages` is unsupported, tool_use events surface only from the
|
|
@@ -716,7 +720,7 @@ export function createClaudeStreamHandler({ onEvent }, options = {}) {
|
|
|
716
720
|
// New message boundary — see `anonymousMessageEpoch`'s declaration.
|
|
717
721
|
if (currentMessageId === null)
|
|
718
722
|
anonymousMessageEpoch += 1;
|
|
719
|
-
segmentUsage.observe({ messageId:
|
|
723
|
+
segmentUsage.observe({ messageId: usageMessageKey(), usage: isRecord(ev.message) ? ev.message.usage : undefined });
|
|
720
724
|
currentMessageStreamedText = false;
|
|
721
725
|
currentMessageStreamedThinking = false;
|
|
722
726
|
if (typeof ev.ttft_ms === 'number') {
|
|
@@ -778,6 +782,15 @@ export function createClaudeStreamHandler({ onEvent }, options = {}) {
|
|
|
778
782
|
}
|
|
779
783
|
blocks.delete(key);
|
|
780
784
|
}
|
|
785
|
+
// Usage is keyed per message; an id-less message is keyed by its epoch.
|
|
786
|
+
function usageMessageKey() {
|
|
787
|
+
return currentMessageId ?? `anon${anonymousMessageEpoch}`;
|
|
788
|
+
}
|
|
789
|
+
function handleMessageDeltaStreamEvent(ev) {
|
|
790
|
+
segmentUsage.observe({ messageId: usageMessageKey(), usage: ev.usage ?? (isRecord(ev.delta) ? ev.delta.usage : undefined) });
|
|
791
|
+
if (isRecord(ev.delta))
|
|
792
|
+
handleMessageDeltaEvent(ev.delta);
|
|
793
|
+
}
|
|
781
794
|
function handleMessageDeltaEvent(delta) {
|
|
782
795
|
const stopReason = typeof delta.stop_reason === 'string' ? delta.stop_reason : null;
|
|
783
796
|
if (stopReason)
|
|
@@ -800,9 +813,7 @@ export function createClaudeStreamHandler({ onEvent }, options = {}) {
|
|
|
800
813
|
handleContentBlockStop(ev);
|
|
801
814
|
return;
|
|
802
815
|
case 'message_delta':
|
|
803
|
-
|
|
804
|
-
if (isRecord(ev.delta))
|
|
805
|
-
handleMessageDeltaEvent(ev.delta);
|
|
816
|
+
handleMessageDeltaStreamEvent(ev);
|
|
806
817
|
return;
|
|
807
818
|
}
|
|
808
819
|
}
|
package/dist/copilot-stream.js
CHANGED
|
@@ -62,59 +62,51 @@ export function createCopilotStreamHandler({ onEvent }) {
|
|
|
62
62
|
if (!isRecord(obj) || typeof obj.type !== 'string')
|
|
63
63
|
return;
|
|
64
64
|
const data = isRecord(obj.data) ? obj.data : {};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (data.model) {
|
|
68
|
-
onEvent({ type: 'status', label: 'initializing', model: data.model });
|
|
69
|
-
}
|
|
70
|
-
return;
|
|
71
|
-
case 'assistant.turn_start':
|
|
72
|
-
onEvent({ type: 'status', label: 'streaming' });
|
|
73
|
-
return;
|
|
74
|
-
case 'assistant.reasoning_delta':
|
|
75
|
-
if (typeof data.deltaContent === 'string') {
|
|
76
|
-
onEvent({ type: 'thinking_delta', delta: data.deltaContent });
|
|
77
|
-
}
|
|
78
|
-
return;
|
|
79
|
-
case 'assistant.message_delta':
|
|
80
|
-
if (typeof data.deltaContent === 'string') {
|
|
81
|
-
onEvent({ type: 'text_delta', delta: data.deltaContent });
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
case 'tool.execution_start':
|
|
85
|
-
onEvent({
|
|
86
|
-
type: 'tool_use',
|
|
87
|
-
id: data.toolCallId ?? null,
|
|
88
|
-
name: data.toolName ?? null,
|
|
89
|
-
input: data.arguments ?? null,
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
case 'tool.execution_complete':
|
|
93
|
-
onEvent({
|
|
94
|
-
type: 'tool_result',
|
|
95
|
-
toolUseId: data.toolCallId ?? null,
|
|
96
|
-
content: stringifyResult(data.result),
|
|
97
|
-
isError: data.success === false,
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
case 'result':
|
|
101
|
-
// `result` puts usage / exitCode at the top level, not under `data`.
|
|
102
|
-
// Treat a missing exitCode as success when `success: true` is set —
|
|
103
|
-
// strict `=== 0` would otherwise mis-flag turns where Copilot emits
|
|
104
|
-
// usage without a numeric exit code as `error`.
|
|
105
|
-
onEvent({
|
|
106
|
-
type: 'usage',
|
|
107
|
-
usage: obj.usage ?? null,
|
|
108
|
-
stopReason: obj.success === true || obj.exitCode === 0 ? 'completed' : 'error',
|
|
109
|
-
durationMs: isRecord(obj.usage) ? obj.usage.sessionDurationMs ?? null : null,
|
|
110
|
-
});
|
|
111
|
-
return;
|
|
112
|
-
default:
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
65
|
+
// Event types we have no UI lane for are dropped on the floor.
|
|
66
|
+
COPILOT_EVENT_HANDLERS.get(obj.type)?.({ obj, data, onEvent });
|
|
115
67
|
}
|
|
116
68
|
return { feed, flush };
|
|
117
69
|
}
|
|
70
|
+
function emitDelta(type) {
|
|
71
|
+
return ({ data, onEvent }) => {
|
|
72
|
+
if (typeof data.deltaContent === 'string') {
|
|
73
|
+
onEvent({ type, delta: data.deltaContent });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// Map (not an object literal) so a prototype-named `type` can never resolve to a handler.
|
|
78
|
+
const COPILOT_EVENT_HANDLERS = new Map([
|
|
79
|
+
['session.tools_updated', ({ data, onEvent }) => {
|
|
80
|
+
if (data.model) {
|
|
81
|
+
onEvent({ type: 'status', label: 'initializing', model: data.model });
|
|
82
|
+
}
|
|
83
|
+
}],
|
|
84
|
+
['assistant.turn_start', ({ onEvent }) => onEvent({ type: 'status', label: 'streaming' })],
|
|
85
|
+
['assistant.reasoning_delta', emitDelta('thinking_delta')],
|
|
86
|
+
['assistant.message_delta', emitDelta('text_delta')],
|
|
87
|
+
['tool.execution_start', ({ data, onEvent }) => onEvent({
|
|
88
|
+
type: 'tool_use',
|
|
89
|
+
id: data.toolCallId ?? null,
|
|
90
|
+
name: data.toolName ?? null,
|
|
91
|
+
input: data.arguments ?? null,
|
|
92
|
+
})],
|
|
93
|
+
['tool.execution_complete', ({ data, onEvent }) => onEvent({
|
|
94
|
+
type: 'tool_result',
|
|
95
|
+
toolUseId: data.toolCallId ?? null,
|
|
96
|
+
content: stringifyResult(data.result),
|
|
97
|
+
isError: data.success === false,
|
|
98
|
+
})],
|
|
99
|
+
// `result` puts usage / exitCode at the top level, not under `data`.
|
|
100
|
+
// Treat a missing exitCode as success when `success: true` is set —
|
|
101
|
+
// strict `=== 0` would otherwise mis-flag turns where Copilot emits
|
|
102
|
+
// usage without a numeric exit code as `error`.
|
|
103
|
+
['result', ({ obj, onEvent }) => onEvent({
|
|
104
|
+
type: 'usage',
|
|
105
|
+
usage: obj.usage ?? null,
|
|
106
|
+
stopReason: obj.success === true || obj.exitCode === 0 ? 'completed' : 'error',
|
|
107
|
+
durationMs: isRecord(obj.usage) ? obj.usage.sessionDurationMs ?? null : null,
|
|
108
|
+
})],
|
|
109
|
+
]);
|
|
118
110
|
function stringifyResult(r) {
|
|
119
111
|
if (r == null)
|
|
120
112
|
return '';
|
package/dist/defs/aider.js
CHANGED
|
@@ -42,7 +42,7 @@ export const aiderAgentDef = {
|
|
|
42
42
|
// --yes-always — skip per-action confirmation
|
|
43
43
|
// --no-pretty — strip ANSI so stdout parses as plain text
|
|
44
44
|
// --no-stream — left as default (streaming on)
|
|
45
|
-
// --no-git / --no-auto-commits — the host
|
|
45
|
+
// --no-git / --no-auto-commits — outside trusted CLI parity, the host uses a
|
|
46
46
|
// managed project workspace that
|
|
47
47
|
// is not the user's git repo, so
|
|
48
48
|
// the commit machinery has
|
|
@@ -60,9 +60,8 @@ export const aiderAgentDef = {
|
|
|
60
60
|
// which is the conservative outcome restricted mode is asking for.
|
|
61
61
|
...(options.permissionMode !== 'restricted' ? ['--yes-always'] : []),
|
|
62
62
|
'--no-pretty',
|
|
63
|
-
|
|
64
|
-
'--no-auto-commits',
|
|
65
|
-
'--no-suggest-shell-commands',
|
|
63
|
+
// Managed scratch workspaces suppress git/shell; trusted parity uses Aider's own settings.
|
|
64
|
+
...(options.cliParity && options.permissionMode === 'bypass' && options.nativeToolAccess !== false ? [] : ['--no-git', '--no-auto-commits', '--no-suggest-shell-commands']),
|
|
66
65
|
'--no-show-model-warnings',
|
|
67
66
|
];
|
|
68
67
|
if (options.model && options.model !== 'default') {
|
package/dist/defs/amr.js
CHANGED
|
@@ -31,33 +31,25 @@ const PREFERRED_AMR_CHAT_MODEL_RANK = new Map(PREFERRED_AMR_CHAT_MODEL_ORDER.map
|
|
|
31
31
|
// normalizes those public ids at the spawn boundary until Vela exposes
|
|
32
32
|
// canonical ACP ids directly.
|
|
33
33
|
export function normalizeVelaModelId({ rawId }) {
|
|
34
|
-
const
|
|
35
|
-
if (!trimmed)
|
|
36
|
-
return null;
|
|
37
|
-
const withoutProvider = trimmed.startsWith('vela/')
|
|
38
|
-
? trimmed.slice('vela/'.length)
|
|
39
|
-
: trimmed;
|
|
40
|
-
const withoutPrefix = withoutProvider.startsWith('public_model_')
|
|
41
|
-
? withoutProvider.slice('public_model_'.length)
|
|
42
|
-
: withoutProvider;
|
|
34
|
+
const withoutPrefix = stripPrefix({ value: stripPrefix({ value: rawId.trim(), prefix: 'vela/' }), prefix: 'public_model_' });
|
|
43
35
|
if (!withoutPrefix)
|
|
44
36
|
return null;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
37
|
+
const alias = VELA_MODEL_ID_ALIASES.find(([pattern]) => pattern.test(withoutPrefix));
|
|
38
|
+
if (alias)
|
|
39
|
+
return alias[1];
|
|
40
|
+
return normalizeKnownVelaVersionId(withoutPrefix) ?? withoutPrefix.replace(/_/g, '-');
|
|
41
|
+
}
|
|
42
|
+
/** Compact Vela public ids whose link-facing slug is not a plain underscore-to-dash rewrite. */
|
|
43
|
+
const VELA_MODEL_ID_ALIASES = [
|
|
44
|
+
[/^deepseek_v3_2$/i, 'deepseek-v3.2'],
|
|
45
|
+
[/^deepseek-v3-2$/i, 'deepseek-v3.2'],
|
|
46
|
+
[/^kimi_k2_6$/i, 'kimi-k2.6'],
|
|
47
|
+
[/^kimi_k2_7_code$/i, 'kimi-k2.7-code'],
|
|
48
|
+
[/^glm_5_1$/i, 'glm-5.1'],
|
|
49
|
+
[/^glm_5$/i, 'glm-5'],
|
|
50
|
+
];
|
|
51
|
+
function stripPrefix({ value, prefix }) {
|
|
52
|
+
return value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
61
53
|
}
|
|
62
54
|
// Every capture group below is a mandatory (non-optional) part of its
|
|
63
55
|
// pattern — `(haiku|opus|sonnet)` is a required alternation and `(\d+)`
|
|
@@ -109,8 +101,7 @@ function isVelaChatModelId(modelId) {
|
|
|
109
101
|
return true;
|
|
110
102
|
}
|
|
111
103
|
export function parseVelaModels({ stdout }) {
|
|
112
|
-
const
|
|
113
|
-
const models = [];
|
|
104
|
+
const ids = [];
|
|
114
105
|
for (const line of String(stdout || '').split('\n')) {
|
|
115
106
|
const trimmed = line.trim();
|
|
116
107
|
if (!trimmed || trimmed.startsWith('#'))
|
|
@@ -118,21 +109,27 @@ export function parseVelaModels({ stdout }) {
|
|
|
118
109
|
// `trimmed` is already non-empty and has no leading whitespace (checked
|
|
119
110
|
// above), so its first whitespace-split token is always non-empty too.
|
|
120
111
|
const rawId = trimmed.split(/\s+/)[0];
|
|
121
|
-
|
|
122
|
-
if (!id || seen.has(id) || !isVelaChatModelId(id))
|
|
123
|
-
continue;
|
|
124
|
-
seen.add(id);
|
|
125
|
-
models.push({ id, label: id });
|
|
112
|
+
ids.push(normalizeVelaModelId({ rawId: rawId }));
|
|
126
113
|
}
|
|
127
|
-
return
|
|
114
|
+
return collectChatModels(ids);
|
|
128
115
|
}
|
|
129
116
|
export function parseVelaModelJson({ stdout, expectedSource }) {
|
|
117
|
+
const data = parseVelaModelJsonData({ stdout, expectedSource });
|
|
118
|
+
return collectChatModels(data.map((item) => {
|
|
119
|
+
const rawId = item && typeof item === 'object'
|
|
120
|
+
? item.id
|
|
121
|
+
: null;
|
|
122
|
+
return typeof rawId === 'string' ? rawId.trim() : '';
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
/** Validates the `{ source, data: [...] }` envelope and returns its `data` array. */
|
|
126
|
+
function parseVelaModelJsonData({ stdout, expectedSource }) {
|
|
130
127
|
let parsed;
|
|
131
128
|
try {
|
|
132
129
|
parsed = JSON.parse(stdout);
|
|
133
130
|
}
|
|
134
131
|
catch (error) {
|
|
135
|
-
throw new Error(`Invalid vela model JSON: ${error instanceof Error ? error.message : String(error)}
|
|
132
|
+
throw new Error(`Invalid vela model JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
136
133
|
}
|
|
137
134
|
if (!parsed || typeof parsed !== 'object') {
|
|
138
135
|
throw new Error('Invalid vela model JSON: expected object');
|
|
@@ -145,13 +142,13 @@ export function parseVelaModelJson({ stdout, expectedSource }) {
|
|
|
145
142
|
if (!Array.isArray(data)) {
|
|
146
143
|
throw new Error('Invalid vela model JSON: expected data array');
|
|
147
144
|
}
|
|
145
|
+
return data;
|
|
146
|
+
}
|
|
147
|
+
/** First occurrence of each non-empty chat model id, in preferred AMR chat order. */
|
|
148
|
+
function collectChatModels(ids) {
|
|
148
149
|
const seen = new Set();
|
|
149
150
|
const models = [];
|
|
150
|
-
for (const
|
|
151
|
-
const rawId = item && typeof item === 'object'
|
|
152
|
-
? item.id
|
|
153
|
-
: null;
|
|
154
|
-
const id = typeof rawId === 'string' ? rawId.trim() : '';
|
|
151
|
+
for (const id of ids) {
|
|
155
152
|
if (!id || seen.has(id) || !isVelaChatModelId(id))
|
|
156
153
|
continue;
|
|
157
154
|
seen.add(id);
|
|
@@ -202,34 +199,28 @@ export async function fetchVelaPresetModels({ resolvedBin, env }) {
|
|
|
202
199
|
return parseVelaModelJson({ stdout: String(stdout), expectedSource: 'preset' });
|
|
203
200
|
}
|
|
204
201
|
export async function fetchVelaRemoteModelsWithRetry({ resolvedBin, env }) {
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
// also means `attempt` is always a valid in-bounds index into
|
|
210
|
-
// `AMR_MODELS_RETRY_DELAYS_MS` whenever we reach the `sleep()` call below
|
|
211
|
-
// (the assertion just satisfies `noUncheckedIndexedAccess`).
|
|
212
|
-
//
|
|
213
|
-
// The empty loop condition and absence of break make the closing statement unreachable:
|
|
214
|
-
// success returns, and exhaustion throws after at most three attempts. Coverage instrumentation
|
|
215
|
-
// cannot prove that; document the invariant instead of forcing a test or adding v8 ignore.
|
|
216
|
-
for (let attempt = 0;; attempt += 1) {
|
|
202
|
+
// One attempt per retry delay, each followed by that delay when it fails with a retriable
|
|
203
|
+
// error; a non-retriable error (including a malformed catalog) is thrown at once. The final
|
|
204
|
+
// attempt after the last delay is not retried, so whatever it throws propagates as-is.
|
|
205
|
+
for (const delayMs of AMR_MODELS_RETRY_DELAYS_MS) {
|
|
217
206
|
try {
|
|
218
|
-
|
|
219
|
-
env,
|
|
220
|
-
timeout: AMR_MODELS_TIMEOUT_MS,
|
|
221
|
-
maxBuffer: 1024 * 1024,
|
|
222
|
-
} });
|
|
223
|
-
return parseVelaModelJson({ stdout: String(stdout), expectedSource: 'remote' });
|
|
207
|
+
return await fetchVelaRemoteModelsOnce({ resolvedBin, env });
|
|
224
208
|
}
|
|
225
209
|
catch (error) {
|
|
226
|
-
if (
|
|
227
|
-
!isRetriableVelaModelsError(error)) {
|
|
210
|
+
if (!isRetriableVelaModelsError(error))
|
|
228
211
|
throw error;
|
|
229
|
-
}
|
|
230
|
-
await sleep(AMR_MODELS_RETRY_DELAYS_MS[attempt]);
|
|
231
212
|
}
|
|
213
|
+
await sleep(delayMs);
|
|
232
214
|
}
|
|
215
|
+
return fetchVelaRemoteModelsOnce({ resolvedBin, env });
|
|
216
|
+
}
|
|
217
|
+
async function fetchVelaRemoteModelsOnce({ resolvedBin, env }) {
|
|
218
|
+
const { stdout } = await execAgentFile({ command: resolvedBin, args: ['model', 'list', '--format', 'json'] }, { options: {
|
|
219
|
+
env,
|
|
220
|
+
timeout: AMR_MODELS_TIMEOUT_MS,
|
|
221
|
+
maxBuffer: 1024 * 1024,
|
|
222
|
+
} });
|
|
223
|
+
return parseVelaModelJson({ stdout: String(stdout), expectedSource: 'remote' });
|
|
233
224
|
}
|
|
234
225
|
/**
|
|
235
226
|
* Read the signed-in account's billing summary via the vela CLI — the same
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeModelOption } from '../types.js';
|
|
1
|
+
import type { RuntimeBuildOptions, RuntimeContext, RuntimeModelOption } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Redacts any OAuth sign-in URL from agy's buffered print-mode stdout,
|
|
4
4
|
* leaving all other output byte-identical.
|
|
@@ -48,6 +48,7 @@ export declare const antigravityAgentDef: {
|
|
|
48
48
|
parse: typeof parseAgyModels;
|
|
49
49
|
timeoutMs: number;
|
|
50
50
|
};
|
|
51
|
+
fallbackModelsAssertedAt: string;
|
|
51
52
|
fallbackModels: RuntimeModelOption[];
|
|
52
53
|
supportsCustomModel: false;
|
|
53
54
|
reasoningInModelId: {
|
|
@@ -56,13 +57,13 @@ export declare const antigravityAgentDef: {
|
|
|
56
57
|
label: string;
|
|
57
58
|
}[];
|
|
58
59
|
};
|
|
59
|
-
buildArgs: ({ prompt
|
|
60
|
+
buildArgs: ({ prompt }: {
|
|
60
61
|
prompt: string;
|
|
61
62
|
imagePaths: string[];
|
|
62
|
-
}, {
|
|
63
|
+
}, { options, runtimeContext }?: {
|
|
63
64
|
extraAllowedDirs?: string[];
|
|
64
|
-
options?:
|
|
65
|
-
runtimeContext?:
|
|
65
|
+
options?: RuntimeBuildOptions;
|
|
66
|
+
runtimeContext?: RuntimeContext;
|
|
66
67
|
} | undefined) => string[];
|
|
67
68
|
maxPromptArgBytes: number;
|
|
68
69
|
streamFormat: string;
|