@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
|
@@ -2,7 +2,9 @@ import { runAnthropicToolTurn } from './anthropic-messages.js';
|
|
|
2
2
|
import { runAzureToolTurn } from './azure-chat.js';
|
|
3
3
|
import { runGoogleToolTurn } from './google-messages.js';
|
|
4
4
|
import { runOpenAiToolTurn } from './openai-chat.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createToolNameMap } from '@jini-ai/core';
|
|
6
|
+
import { compileOperationSchema } from './operation-schema.js';
|
|
7
|
+
export { compileOperationSchema } from './operation-schema.js';
|
|
6
8
|
export { googleParametersOf, sanitizeGoogleSchema, findNumericEnumPaths, coerceNumericEnumStringsToNumbers } from './google-schema.js';
|
|
7
9
|
/** Existing provider loops, ready for host composition; callers may replace any adapter. */
|
|
8
10
|
export const providerTurnAdapters = Object.freeze({ anthropic: runAnthropicToolTurn, openai: runOpenAiToolTurn, azure: runAzureToolTurn, google: runGoogleToolTurn });
|
|
@@ -29,13 +31,16 @@ function foldToolError(content, isError) {
|
|
|
29
31
|
return content;
|
|
30
32
|
return typeof content === "string" ? `${TOOL_ERROR_PREFIX}${content}` : [{ type: "text", text: TOOL_ERROR_PREFIX.trimEnd() }, ...content];
|
|
31
33
|
}
|
|
34
|
+
function imageUrlMimeType({ url }, _options = {}) {
|
|
35
|
+
return /^data:([^;,]+)/.exec(url)?.[1] ?? "url";
|
|
36
|
+
}
|
|
32
37
|
function imagePartMimeType(part) {
|
|
33
38
|
const source = part.source;
|
|
34
39
|
if (part.type === "image" && typeof source?.media_type === "string")
|
|
35
40
|
return source.media_type;
|
|
36
41
|
const imageUrl = part.image_url;
|
|
37
42
|
if (part.type === "image_url" && typeof imageUrl?.url === "string")
|
|
38
|
-
return
|
|
43
|
+
return imageUrlMimeType({ url: imageUrl.url });
|
|
39
44
|
const inlineData = part.inlineData;
|
|
40
45
|
if (typeof inlineData?.mimeType === "string")
|
|
41
46
|
return inlineData.mimeType;
|
|
@@ -55,25 +60,104 @@ function describeToolResultContent(content) {
|
|
|
55
60
|
})
|
|
56
61
|
.join("\n");
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
/** Invalid snapshot names fail closed before an adapter can dispatch an ambiguous operation. */
|
|
64
|
+
export class ProviderToolProjectionError extends Error {
|
|
65
|
+
code = 'invalid-wire-name';
|
|
66
|
+
constructor(_required, options = {}) {
|
|
67
|
+
super('Invalid or conflicting tool wire name', options);
|
|
68
|
+
this.name = 'ProviderToolProjectionError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function pinWireName(descriptor, names, occupied) {
|
|
72
|
+
if (descriptor.wireName === undefined)
|
|
73
|
+
return;
|
|
74
|
+
const existing = names.get(descriptor.id);
|
|
75
|
+
const owner = occupied.get(descriptor.wireName);
|
|
76
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(descriptor.wireName))
|
|
77
|
+
throw new ProviderToolProjectionError({});
|
|
78
|
+
if (existing !== undefined && existing !== descriptor.wireName)
|
|
79
|
+
throw new ProviderToolProjectionError({});
|
|
80
|
+
if (owner !== undefined && owner !== descriptor.id)
|
|
81
|
+
throw new ProviderToolProjectionError({});
|
|
82
|
+
names.set(descriptor.id, descriptor.wireName);
|
|
83
|
+
occupied.set(descriptor.wireName, descriptor.id);
|
|
84
|
+
}
|
|
85
|
+
function pinWireNames(descriptors, names) {
|
|
86
|
+
const occupied = new Map([...names].map(([id, name]) => [name, id]));
|
|
87
|
+
for (const descriptor of descriptors)
|
|
88
|
+
pinWireName(descriptor, names, occupied);
|
|
89
|
+
const pending = descriptors.filter(descriptor => !names.has(descriptor.id));
|
|
90
|
+
const mapping = createToolNameMap({ toolIds: pending.map(descriptor => descriptor.id) }, { reservedNames: [...occupied.keys()] });
|
|
91
|
+
for (const descriptor of pending)
|
|
92
|
+
names.set(descriptor.id, mapping.wireNameFor({ toolId: descriptor.id }));
|
|
93
|
+
}
|
|
94
|
+
/** Per-turn projection state only; the host registry/executor retains definition and policy ownership.
|
|
95
|
+
* Names and previously published decoders survive refresh so in-flight calls remain resolvable.
|
|
96
|
+
* Snapshot work is O(n log n + s) for n IDs and s bounded expanded schema nodes; host ports own I/O.
|
|
97
|
+
*/
|
|
98
|
+
function createToolProjection(input, _options = {}) {
|
|
99
|
+
const names = new Map();
|
|
100
|
+
const published = new Map();
|
|
101
|
+
const reported = new Set();
|
|
102
|
+
function getTools({ strict = false } = {}, { reportFallback = true } = {}) {
|
|
103
|
+
const descriptors = input.getToolSnapshot?.() ?? input.tools;
|
|
104
|
+
pinWireNames(descriptors, names);
|
|
105
|
+
return descriptors.map(descriptor => {
|
|
106
|
+
const operation = compileOperationSchema({ schema: descriptor.inputSchema, protocol: input.protocol }, { strict });
|
|
107
|
+
const name = names.get(descriptor.id);
|
|
108
|
+
published.set(name, { id: descriptor.id, operation });
|
|
109
|
+
const diagnosticKey = `${descriptor.id}:${operation.fallbackReason}`;
|
|
110
|
+
if (reportFallback && operation.fallbackReason && !reported.has(diagnosticKey)) {
|
|
111
|
+
reported.add(diagnosticKey);
|
|
112
|
+
input.onSchemaFallback?.({ toolId: descriptor.id, protocol: input.protocol, reason: operation.fallbackReason });
|
|
113
|
+
}
|
|
114
|
+
return { name, ...(descriptor.description !== undefined ? { description: descriptor.description } : {}), operation };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function decode(call) {
|
|
118
|
+
const tool = published.get(call.name);
|
|
119
|
+
return tool ? { ...call, name: tool.id, input: tool.operation.decodeInput(call.input) } : call;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
getTools,
|
|
123
|
+
/** Dispatch a published call or await host refusal wording/audit; callback errors propagate.
|
|
124
|
+
* O(1) local lookup and space; host callback/executor costs belong to those ports.
|
|
125
|
+
*/
|
|
126
|
+
async execute(call, _options = {}) {
|
|
127
|
+
if (!published.has(call.name)) {
|
|
128
|
+
// MOVE: Refusal auditing must stay separate from execution so a policy change during
|
|
129
|
+
// the callback cannot authorize a call whose name was never published this turn.
|
|
130
|
+
const refusal = await input.onUnexposedToolCall?.({ toolName: call.name, callId: call.id, input: call.input, protocol: input.protocol });
|
|
131
|
+
return { isError: true, content: refusal?.text ?? 'Tool is not exposed in this turn.' };
|
|
132
|
+
}
|
|
133
|
+
return input.executeTool(decode(call));
|
|
134
|
+
},
|
|
135
|
+
onEvent(event) {
|
|
136
|
+
input.onEvent(event.type === 'tool_use' ? { ...event, ...decode(event) } : event);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function anthropicTools(tools) {
|
|
141
|
+
return tools.map(({ name, description, operation }) => ({ name, ...(description !== undefined ? { description } : {}), input_schema: operation.schema, ...(operation.strict ? { strict: true } : {}) }));
|
|
142
|
+
}
|
|
143
|
+
function openAiTools(tools) {
|
|
144
|
+
return tools.map(({ name, description, operation }) => ({ type: 'function', function: { name, ...(description !== undefined ? { description } : {}), parameters: operation.schema, ...(operation.strict ? { strict: true } : {}) } }));
|
|
145
|
+
}
|
|
146
|
+
function googleTools(tools) {
|
|
147
|
+
return [{ functionDeclarations: tools.map(({ name, description, operation }) => ({ name, ...(description !== undefined ? { description } : {}), parameters: operation.schema })) }];
|
|
62
148
|
}
|
|
63
149
|
function normalizeTurnResult(result, capturedEndReason = null) {
|
|
64
150
|
return { stopReason: capturedEndReason ?? result.stopReason ?? result.finishReason ?? null, toolTurns: result.toolTurns };
|
|
65
151
|
}
|
|
66
152
|
async function runAnthropicTurn(input) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
input_schema: inputSchemaOf(d),
|
|
71
|
-
}));
|
|
153
|
+
const projection = createToolProjection(input);
|
|
154
|
+
const getTools = (options = {}) => anthropicTools(projection.getTools(options));
|
|
155
|
+
const tools = anthropicTools(projection.getTools({}, { reportFallback: false }));
|
|
72
156
|
const messages = input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toAnthropicToolContent([
|
|
73
157
|
{ type: 'text', text: m.content }, ...m.images.map(image => ({ type: 'image', ...image })),
|
|
74
158
|
]) : m.content }));
|
|
75
159
|
const executeTool = async (call) => {
|
|
76
|
-
const result = await
|
|
160
|
+
const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
|
|
77
161
|
return { content: toAnthropicToolContent(result.content), ...(result.isError !== undefined ? { isError: result.isError } : {}) };
|
|
78
162
|
};
|
|
79
163
|
let capturedEndReason = null;
|
|
@@ -84,6 +168,8 @@ async function runAnthropicTurn(input) {
|
|
|
84
168
|
system: input.system,
|
|
85
169
|
messages,
|
|
86
170
|
tools,
|
|
171
|
+
getTools,
|
|
172
|
+
...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
|
|
87
173
|
maxTokens: input.maxTokens ?? 8192,
|
|
88
174
|
...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
|
|
89
175
|
executeTool,
|
|
@@ -102,16 +188,15 @@ async function runAnthropicTurn(input) {
|
|
|
102
188
|
});
|
|
103
189
|
return;
|
|
104
190
|
}
|
|
105
|
-
|
|
191
|
+
projection.onEvent(event);
|
|
106
192
|
},
|
|
107
193
|
});
|
|
108
194
|
return normalizeTurnResult(result, capturedEndReason);
|
|
109
195
|
}
|
|
110
196
|
async function runOpenAiTurn(input) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}));
|
|
197
|
+
const projection = createToolProjection(input);
|
|
198
|
+
const getTools = (options = {}) => openAiTools(projection.getTools(options));
|
|
199
|
+
const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
|
|
115
200
|
const messages = [
|
|
116
201
|
{ role: "system", content: input.system },
|
|
117
202
|
...input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toOpenAiToolContent([
|
|
@@ -119,7 +204,7 @@ async function runOpenAiTurn(input) {
|
|
|
119
204
|
]) : m.content })),
|
|
120
205
|
];
|
|
121
206
|
const executeTool = async (call) => {
|
|
122
|
-
const result = await
|
|
207
|
+
const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
|
|
123
208
|
return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
|
|
124
209
|
};
|
|
125
210
|
let capturedEndReason = null;
|
|
@@ -129,6 +214,8 @@ async function runOpenAiTurn(input) {
|
|
|
129
214
|
model: input.model,
|
|
130
215
|
messages,
|
|
131
216
|
tools,
|
|
217
|
+
getTools,
|
|
218
|
+
...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
|
|
132
219
|
...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
|
|
133
220
|
...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
|
|
134
221
|
executeTool,
|
|
@@ -143,7 +230,7 @@ async function runOpenAiTurn(input) {
|
|
|
143
230
|
input.onEvent({ type: "tool_result", toolUseId: event.toolUseId, content, isError: event.isError || content.startsWith(TOOL_ERROR_PREFIX.trimEnd()) });
|
|
144
231
|
return;
|
|
145
232
|
}
|
|
146
|
-
|
|
233
|
+
projection.onEvent(event);
|
|
147
234
|
},
|
|
148
235
|
});
|
|
149
236
|
return normalizeTurnResult(result, capturedEndReason);
|
|
@@ -154,10 +241,9 @@ async function runAzureTurn(input) {
|
|
|
154
241
|
input.onEvent({ type: "end", reason: "error" });
|
|
155
242
|
return { stopReason: "error", toolTurns: 0 };
|
|
156
243
|
}
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}));
|
|
244
|
+
const projection = createToolProjection(input);
|
|
245
|
+
const getTools = (options = {}) => openAiTools(projection.getTools(options));
|
|
246
|
+
const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
|
|
161
247
|
const messages = [
|
|
162
248
|
{ role: "system", content: input.system },
|
|
163
249
|
...input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toOpenAiToolContent([
|
|
@@ -165,7 +251,7 @@ async function runAzureTurn(input) {
|
|
|
165
251
|
]) : m.content })),
|
|
166
252
|
];
|
|
167
253
|
const executeTool = async (call) => {
|
|
168
|
-
const result = await
|
|
254
|
+
const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
|
|
169
255
|
return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
|
|
170
256
|
};
|
|
171
257
|
let capturedEndReason = null;
|
|
@@ -175,6 +261,8 @@ async function runAzureTurn(input) {
|
|
|
175
261
|
model: input.model,
|
|
176
262
|
messages,
|
|
177
263
|
tools,
|
|
264
|
+
getTools,
|
|
265
|
+
...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
|
|
178
266
|
...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
|
|
179
267
|
...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
|
|
180
268
|
executeTool,
|
|
@@ -189,23 +277,21 @@ async function runAzureTurn(input) {
|
|
|
189
277
|
input.onEvent({ type: "tool_result", toolUseId: event.toolUseId, content, isError: event.isError || content.startsWith(TOOL_ERROR_PREFIX.trimEnd()) });
|
|
190
278
|
return;
|
|
191
279
|
}
|
|
192
|
-
|
|
280
|
+
projection.onEvent(event);
|
|
193
281
|
},
|
|
194
282
|
});
|
|
195
283
|
return normalizeTurnResult(result, capturedEndReason);
|
|
196
284
|
}
|
|
197
285
|
async function runGoogleTurn(input) {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const numericEnumPathsByToolName = new Map(input.tools.map((d) => [d.id, findNumericEnumPaths({ schema: inputSchemaOf(d) })]));
|
|
286
|
+
const projection = createToolProjection(input);
|
|
287
|
+
const getTools = (options = {}) => googleTools(projection.getTools(options));
|
|
288
|
+
const tools = googleTools(projection.getTools({}, { reportFallback: false }));
|
|
202
289
|
const contents = input.messages.map((m) => ({
|
|
203
290
|
role: m.role === "assistant" ? "model" : "user",
|
|
204
291
|
parts: [{ text: m.content }, ...(m.images ?? []).map(image => ({ inlineData: image }))],
|
|
205
292
|
}));
|
|
206
293
|
const executeTool = async (call) => {
|
|
207
|
-
const
|
|
208
|
-
const result = await input.executeTool({ id: call.id, name: call.name, input: coercedInput });
|
|
294
|
+
const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
|
|
209
295
|
return { content: toGoogleToolContent(result.content), ...(result.isError !== undefined ? { isError: result.isError } : {}) };
|
|
210
296
|
};
|
|
211
297
|
let capturedEndReason = null;
|
|
@@ -216,6 +302,8 @@ async function runGoogleTurn(input) {
|
|
|
216
302
|
system: input.system,
|
|
217
303
|
contents,
|
|
218
304
|
tools,
|
|
305
|
+
getTools,
|
|
306
|
+
...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
|
|
219
307
|
...(input.maxTokens !== undefined ? { maxOutputTokens: input.maxTokens } : {}),
|
|
220
308
|
...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
|
|
221
309
|
executeTool,
|
|
@@ -234,7 +322,7 @@ async function runGoogleTurn(input) {
|
|
|
234
322
|
});
|
|
235
323
|
return;
|
|
236
324
|
}
|
|
237
|
-
|
|
325
|
+
projection.onEvent(event);
|
|
238
326
|
},
|
|
239
327
|
});
|
|
240
328
|
return normalizeTurnResult(result, capturedEndReason);
|
package/dist/qoder-stream.js
CHANGED
|
@@ -25,14 +25,15 @@ function stringifyContent(value) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function textFromContentBlock(block) {
|
|
28
|
-
if (
|
|
29
|
-
return '';
|
|
30
|
-
if (block.type === 'text' && typeof block.text === 'string')
|
|
31
|
-
return block.text;
|
|
32
|
-
if (typeof block.text === 'string')
|
|
28
|
+
if (isRecord(block) && typeof block.text === 'string')
|
|
33
29
|
return block.text;
|
|
34
30
|
return '';
|
|
35
31
|
}
|
|
32
|
+
function thinkingFromContentBlock(block) {
|
|
33
|
+
if (isRecord(block) && block.type === 'thinking' && typeof block.thinking === 'string')
|
|
34
|
+
return block.thinking;
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
36
37
|
function messageFromError(error) {
|
|
37
38
|
if (isRecord(error) && typeof error.message === 'string') {
|
|
38
39
|
return error.message;
|
|
@@ -41,97 +42,109 @@ function messageFromError(error) {
|
|
|
41
42
|
return error;
|
|
42
43
|
return 'Unknown Qoder error';
|
|
43
44
|
}
|
|
45
|
+
/** First non-empty string among the candidates, or undefined. */
|
|
46
|
+
function firstNonEmpty(candidates) {
|
|
47
|
+
return candidates.find((value) => typeof value === 'string' && value.length > 0);
|
|
48
|
+
}
|
|
44
49
|
function messageFromResult(obj) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
obj.error.message.length > 0) {
|
|
50
|
-
return obj.error.message;
|
|
51
|
-
}
|
|
52
|
-
if (typeof obj.message === 'string' && obj.message.length > 0) {
|
|
53
|
-
return obj.message;
|
|
54
|
-
}
|
|
50
|
+
const errorMessage = isRecord(obj.error) ? obj.error.message : undefined;
|
|
51
|
+
const message = firstNonEmpty([obj.error, errorMessage, obj.message]);
|
|
52
|
+
if (message !== undefined)
|
|
53
|
+
return message;
|
|
55
54
|
if (typeof obj.stop_reason === 'string' && obj.stop_reason.length > 0) {
|
|
56
55
|
return `Qoder run failed: ${obj.stop_reason}`;
|
|
57
56
|
}
|
|
58
57
|
return 'Qoder run failed';
|
|
59
58
|
}
|
|
59
|
+
function optionalString(value) {
|
|
60
|
+
return typeof value === 'string' ? value : undefined;
|
|
61
|
+
}
|
|
62
|
+
function initStatusEvent(obj) {
|
|
63
|
+
return {
|
|
64
|
+
type: 'status',
|
|
65
|
+
label: 'initializing',
|
|
66
|
+
model: optionalString(obj.model),
|
|
67
|
+
sessionId: optionalString(obj.session_id),
|
|
68
|
+
qodercliVersion: optionalString(obj.qodercli_version),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function usageEvent(obj) {
|
|
72
|
+
return {
|
|
73
|
+
type: 'usage',
|
|
74
|
+
usage: obj.usage ?? null,
|
|
75
|
+
modelUsage: obj.modelUsage ?? undefined,
|
|
76
|
+
costUsd: obj.total_cost_usd ?? null,
|
|
77
|
+
durationMs: typeof obj.duration_ms === 'number' ? obj.duration_ms : null,
|
|
78
|
+
stopReason: obj.stop_reason ?? null,
|
|
79
|
+
isError: Boolean(obj.is_error),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
60
82
|
export function createQoderStreamHandler({ onEvent }) {
|
|
61
83
|
let buffer = '';
|
|
62
84
|
let emittedThinkingStart = false;
|
|
63
|
-
function
|
|
64
|
-
if (!
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
onEvent({
|
|
68
|
-
type: 'status',
|
|
69
|
-
label: 'initializing',
|
|
70
|
-
model: typeof obj.model === 'string' ? obj.model : undefined,
|
|
71
|
-
sessionId: typeof obj.session_id === 'string' ? obj.session_id : undefined,
|
|
72
|
-
qodercliVersion: typeof obj.qodercli_version === 'string'
|
|
73
|
-
? obj.qodercli_version
|
|
74
|
-
: undefined,
|
|
75
|
-
});
|
|
76
|
-
return;
|
|
85
|
+
function emitThinking(thinking) {
|
|
86
|
+
if (!emittedThinkingStart) {
|
|
87
|
+
emittedThinkingStart = true;
|
|
88
|
+
onEvent({ type: 'thinking_start' });
|
|
77
89
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
onEvent({ type: 'thinking_delta', delta: block.thinking });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (!emittedText && typeof obj.message.content === 'string') {
|
|
102
|
-
onEvent({ type: 'text_delta', delta: obj.message.content });
|
|
90
|
+
onEvent({ type: 'thinking_delta', delta: thinking });
|
|
91
|
+
}
|
|
92
|
+
/** Emit one content block's text or thinking; returns whether text was emitted. */
|
|
93
|
+
function emitContentBlock(block) {
|
|
94
|
+
const text = textFromContentBlock(block);
|
|
95
|
+
if (text.length > 0) {
|
|
96
|
+
onEvent({ type: 'text_delta', delta: text });
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const thinking = thinkingFromContentBlock(block);
|
|
100
|
+
if (thinking.length > 0)
|
|
101
|
+
emitThinking(thinking);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
function handleAssistant(obj, message, rawLine) {
|
|
105
|
+
const content = Array.isArray(message.content) ? message.content : [];
|
|
106
|
+
let emittedText = false;
|
|
107
|
+
for (const block of content) {
|
|
108
|
+
if (emitContentBlock(block))
|
|
103
109
|
emittedText = true;
|
|
104
|
-
}
|
|
105
|
-
if (obj.error && !emittedText) {
|
|
106
|
-
onEvent({
|
|
107
|
-
type: 'error',
|
|
108
|
-
message: messageFromError(obj.error),
|
|
109
|
-
raw: rawLine,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
110
|
}
|
|
114
|
-
if (
|
|
115
|
-
|
|
111
|
+
if (!emittedText && typeof message.content === 'string') {
|
|
112
|
+
onEvent({ type: 'text_delta', delta: message.content });
|
|
113
|
+
emittedText = true;
|
|
114
|
+
}
|
|
115
|
+
if (obj.error && !emittedText) {
|
|
116
|
+
onEvent({
|
|
117
|
+
type: 'error',
|
|
118
|
+
message: messageFromError(obj.error),
|
|
119
|
+
raw: rawLine,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function handleResult(obj, rawLine) {
|
|
124
|
+
onEvent(usageEvent(obj));
|
|
125
|
+
if (obj.is_error) {
|
|
116
126
|
onEvent({
|
|
117
|
-
type: '
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
costUsd: obj.total_cost_usd ?? null,
|
|
121
|
-
durationMs: typeof obj.duration_ms === 'number' ? obj.duration_ms : null,
|
|
122
|
-
stopReason: obj.stop_reason ?? null,
|
|
123
|
-
isError,
|
|
127
|
+
type: 'error',
|
|
128
|
+
message: messageFromResult(obj),
|
|
129
|
+
raw: rawLine,
|
|
124
130
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
raw: rawLine,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function handleObject(obj, rawLine) {
|
|
134
|
+
if (!isRecord(obj))
|
|
132
135
|
return;
|
|
136
|
+
if (obj.type === 'system' && obj.subtype === 'init') {
|
|
137
|
+
onEvent(initStatusEvent(obj));
|
|
138
|
+
}
|
|
139
|
+
else if (obj.type === 'assistant' && isRecord(obj.message)) {
|
|
140
|
+
handleAssistant(obj, obj.message, rawLine);
|
|
141
|
+
}
|
|
142
|
+
else if (obj.type === 'result') {
|
|
143
|
+
handleResult(obj, rawLine);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
onEvent({ type: 'raw', line: rawLine });
|
|
133
147
|
}
|
|
134
|
-
onEvent({ type: 'raw', line: rawLine });
|
|
135
148
|
}
|
|
136
149
|
function handleLine(line) {
|
|
137
150
|
try {
|
package/dist/registry.d.ts
CHANGED
|
@@ -23,4 +23,49 @@ export declare function getAgentDef({ id }: {
|
|
|
23
23
|
export declare function runtimeSupportsExternalTools({ def }: {
|
|
24
24
|
def: Pick<RuntimeAgentDef, 'externalMcpInjection'>;
|
|
25
25
|
}): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this def's CLI has a native subagent tool, per its own `supportsSubagents` declaration.
|
|
28
|
+
* The single seam a host reads before steering a run toward delegation or rendering a
|
|
29
|
+
* subagent preference toggle; never inferred from a runtime id list or model name.
|
|
30
|
+
*
|
|
31
|
+
* @complexity Time/space: O(1).
|
|
32
|
+
*/
|
|
33
|
+
export declare function runtimeSupportsSubagents({ def }: {
|
|
34
|
+
def: Pick<RuntimeAgentDef, 'supportsSubagents'>;
|
|
35
|
+
}): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* {@link runtimeSupportsSubagents} by agent id through the registry. An unknown id is unsupported.
|
|
38
|
+
* `getDef` defaults to this package's {@link getAgentDef}; a host with its own runtime registry
|
|
39
|
+
* passes its lookup so both resolve the same def.
|
|
40
|
+
*
|
|
41
|
+
* @complexity Time/space: O(n) for n registered defs (one lookup).
|
|
42
|
+
*/
|
|
43
|
+
export declare function agentSupportsSubagents({ agentId }: {
|
|
44
|
+
agentId: string;
|
|
45
|
+
}, { getDef }?: {
|
|
46
|
+
getDef?: (input: {
|
|
47
|
+
id: string;
|
|
48
|
+
}) => Pick<RuntimeAgentDef, 'supportsSubagents'> | null;
|
|
49
|
+
}): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether this def's `buildArgs` honors `RuntimeBuildOptions.chromeIntegration`, per its own
|
|
52
|
+
* `supportsChromeIntegration` declaration. Same seam shape as {@link runtimeSupportsSubagents}.
|
|
53
|
+
*
|
|
54
|
+
* @complexity Time/space: O(1).
|
|
55
|
+
*/
|
|
56
|
+
export declare function runtimeSupportsChromeIntegration({ def }: {
|
|
57
|
+
def: Pick<RuntimeAgentDef, 'supportsChromeIntegration'>;
|
|
58
|
+
}): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* {@link runtimeSupportsChromeIntegration} by agent id; same lookup contract as {@link agentSupportsSubagents}.
|
|
61
|
+
*
|
|
62
|
+
* @complexity Time/space: O(n) for n registered defs (one lookup).
|
|
63
|
+
*/
|
|
64
|
+
export declare function agentSupportsChromeIntegration({ agentId }: {
|
|
65
|
+
agentId: string;
|
|
66
|
+
}, { getDef }?: {
|
|
67
|
+
getDef?: (input: {
|
|
68
|
+
id: string;
|
|
69
|
+
}) => Pick<RuntimeAgentDef, 'supportsChromeIntegration'> | null;
|
|
70
|
+
}): boolean;
|
|
26
71
|
//# sourceMappingURL=registry.d.ts.map
|
package/dist/registry.js
CHANGED
|
@@ -80,4 +80,43 @@ export function getAgentDef({ id }) {
|
|
|
80
80
|
export function runtimeSupportsExternalTools({ def }) {
|
|
81
81
|
return def.externalMcpInjection !== undefined;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether this def's CLI has a native subagent tool, per its own `supportsSubagents` declaration.
|
|
85
|
+
* The single seam a host reads before steering a run toward delegation or rendering a
|
|
86
|
+
* subagent preference toggle; never inferred from a runtime id list or model name.
|
|
87
|
+
*
|
|
88
|
+
* @complexity Time/space: O(1).
|
|
89
|
+
*/
|
|
90
|
+
export function runtimeSupportsSubagents({ def }) {
|
|
91
|
+
return def.supportsSubagents === true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* {@link runtimeSupportsSubagents} by agent id through the registry. An unknown id is unsupported.
|
|
95
|
+
* `getDef` defaults to this package's {@link getAgentDef}; a host with its own runtime registry
|
|
96
|
+
* passes its lookup so both resolve the same def.
|
|
97
|
+
*
|
|
98
|
+
* @complexity Time/space: O(n) for n registered defs (one lookup).
|
|
99
|
+
*/
|
|
100
|
+
export function agentSupportsSubagents({ agentId }, { getDef = getAgentDef } = {}) {
|
|
101
|
+
const def = getDef({ id: agentId });
|
|
102
|
+
return def !== null && runtimeSupportsSubagents({ def });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether this def's `buildArgs` honors `RuntimeBuildOptions.chromeIntegration`, per its own
|
|
106
|
+
* `supportsChromeIntegration` declaration. Same seam shape as {@link runtimeSupportsSubagents}.
|
|
107
|
+
*
|
|
108
|
+
* @complexity Time/space: O(1).
|
|
109
|
+
*/
|
|
110
|
+
export function runtimeSupportsChromeIntegration({ def }) {
|
|
111
|
+
return def.supportsChromeIntegration === true;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* {@link runtimeSupportsChromeIntegration} by agent id; same lookup contract as {@link agentSupportsSubagents}.
|
|
115
|
+
*
|
|
116
|
+
* @complexity Time/space: O(n) for n registered defs (one lookup).
|
|
117
|
+
*/
|
|
118
|
+
export function agentSupportsChromeIntegration({ agentId }, { getDef = getAgentDef } = {}) {
|
|
119
|
+
const def = getDef({ id: agentId });
|
|
120
|
+
return def !== null && runtimeSupportsChromeIntegration({ def });
|
|
121
|
+
}
|
|
83
122
|
//# sourceMappingURL=registry.js.map
|
package/dist/runtime-state.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AcpModelProbe } from './acp-model-probe.js';
|
|
|
3
3
|
import type { RuntimeAgentDef, RuntimeCapabilityMap, RuntimeModelOption, DetectedAgent } from './types.js';
|
|
4
4
|
import type { ModelCacheEntry, ModelDiscoveryDeps } from './model-discovery-types.js';
|
|
5
5
|
export interface AgentRuntimeState {
|
|
6
|
-
/** One in-flight or settled
|
|
6
|
+
/** One in-flight or settled detection per launch scope; catalog expiry refreshes only models. */
|
|
7
7
|
readonly detections: Map<string, Promise<DetectedAgent>>;
|
|
8
8
|
readonly capabilities: Map<string, RuntimeCapabilityMap>;
|
|
9
9
|
/** One in-flight or settled `--help` probe per def id + launch path, so a run never re-spawns it. */
|
package/dist/types.d.ts
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* Ported from OD's `apps/daemon/src/runtimes/types.ts`. Product-neutral
|
|
12
12
|
* as found — see `archived provenance ledger` for the full provenance table.
|
|
13
13
|
*/
|
|
14
|
-
import type { AcpModelProbe } from './acp-model-probe.js';
|
|
15
14
|
import type { AgentModelDiscoveryPort, ModelCatalogSnapshot, DefaultModelResolution, ModelIdentityKind } from './model-discovery-types.js';
|
|
16
15
|
import type { ExecFileOptions } from 'node:child_process';
|
|
17
16
|
import type { AgentDiagnostic } from '@jini-ai/protocol';
|
|
@@ -76,6 +75,13 @@ export type RuntimeReasoningInModelId = {
|
|
|
76
75
|
levels: readonly RuntimeReasoningOption[];
|
|
77
76
|
};
|
|
78
77
|
export type RuntimeBuildOptions = {
|
|
78
|
+
/** Host-verified per-run overrides; false dimensions must be enforced or launch refused. */
|
|
79
|
+
nativeCapabilities?: Partial<import('./native-tool-policy.js').NativeCapabilities>;
|
|
80
|
+
/** Explicit host grant for shell/direct edits. false must be enforced or launch refused.
|
|
81
|
+
* Does not lift environment, MCP, path, approval or sandbox security controls. */
|
|
82
|
+
nativeToolAccess?: boolean;
|
|
83
|
+
/** Explicit trusted-host grant for hand-run CLI configuration and capabilities. */
|
|
84
|
+
cliParity?: boolean;
|
|
79
85
|
/** Explicit host/run policy; environment defaults belong to native composition. */
|
|
80
86
|
codexDisablePlugins?: boolean;
|
|
81
87
|
/** Host-scoped capability flags; absent retains the published compatibility cache. */
|
|
@@ -118,6 +124,13 @@ export type RuntimeBuildOptions = {
|
|
|
118
124
|
* still hand the run the few it wants, e.g. one PreToolUse hook. `undefined`/empty = no flag.
|
|
119
125
|
*/
|
|
120
126
|
settings?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Browser integration for this run — today `claude`'s `--chrome` (true) / `--no-chrome` (false),
|
|
129
|
+
* "Enable/Disable Claude in Chrome integration" in Claude Code 2.1.307's `-p --help`. A mechanism
|
|
130
|
+
* only: the host decides. Probe-gated like `--effort`, so a CLI without the flag gets neither.
|
|
131
|
+
* `undefined` = no flag, byte-identical to before; defs without `supportsChromeIntegration` ignore it.
|
|
132
|
+
*/
|
|
133
|
+
chromeIntegration?: boolean;
|
|
121
134
|
};
|
|
122
135
|
export type RuntimeContext = {
|
|
123
136
|
cwd?: string;
|
|
@@ -267,6 +280,16 @@ export type RuntimeLock = {
|
|
|
267
280
|
readonly acquire: (context: RuntimeLockAcquireContext) => Promise<RuntimeLockHold>;
|
|
268
281
|
};
|
|
269
282
|
export type RuntimeAgentDef = Partial<AgentModelDiscoveryPort> & {
|
|
283
|
+
/** This adapter enforces nativeToolAccess and emits normalized shell/edit tool_use events.
|
|
284
|
+
* A host requesting the policy must fail closed when this capability is absent. */
|
|
285
|
+
supportsNativeToolAccess?: boolean;
|
|
286
|
+
/** The CLI ships a native subagent tool (e.g. Claude Code's Task/Agent) a run can delegate to.
|
|
287
|
+
* Declarative only: hosts read it through `runtimeSupportsSubagents`, never by model name.
|
|
288
|
+
* Absent = no native subagents. */
|
|
289
|
+
supportsSubagents?: boolean;
|
|
290
|
+
/** `buildArgs` honors `RuntimeBuildOptions.chromeIntegration` (today Claude Code's
|
|
291
|
+
* `--chrome`/`--no-chrome`). Read through `runtimeSupportsChromeIntegration`; absent = unsupported. */
|
|
292
|
+
supportsChromeIntegration?: boolean;
|
|
270
293
|
id: string;
|
|
271
294
|
name: string;
|
|
272
295
|
bin: string;
|
|
@@ -432,4 +455,23 @@ export type RuntimeExecOptions = ExecFileOptions & {
|
|
|
432
455
|
* Node-only runtime. Re-exported here so every existing import keeps working unchanged.
|
|
433
456
|
*/
|
|
434
457
|
export type { AgentDiagnostic, AgentDiagnosticReason, AgentDiagnosticSeverity, AgentFixIntent, } from '@jini-ai/protocol';
|
|
458
|
+
export interface AcpModelProbeRequest {
|
|
459
|
+
bin: string;
|
|
460
|
+
args: string[];
|
|
461
|
+
cwd?: string;
|
|
462
|
+
env?: RuntimeEnv;
|
|
463
|
+
timeoutMs?: number;
|
|
464
|
+
signal?: AbortSignal;
|
|
465
|
+
clientName?: string;
|
|
466
|
+
clientVersion?: string;
|
|
467
|
+
defaultModelOption?: RuntimeModelOption;
|
|
468
|
+
}
|
|
469
|
+
export interface AcpModelProbe {
|
|
470
|
+
detectModels(requiredArgs: Pick<AcpModelProbeRequest, 'bin' | 'args'>, optionalArgs?: Omit<AcpModelProbeRequest, 'bin' | 'args'>): Promise<RuntimeModelOption[]>;
|
|
471
|
+
/** Optional metadata capability preserves a native current selection without guessing from order. */
|
|
472
|
+
detectMetadata?(requiredArgs: Pick<AcpModelProbeRequest, 'bin' | 'args'>, optionalArgs?: Omit<AcpModelProbeRequest, 'bin' | 'args'>): Promise<{
|
|
473
|
+
models: RuntimeModelOption[];
|
|
474
|
+
currentModelId: string | null;
|
|
475
|
+
}>;
|
|
476
|
+
}
|
|
435
477
|
//# sourceMappingURL=types.d.ts.map
|