@jini-ai/agent-runtime 0.4.11 → 0.4.12

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/acp-model-probe.d.ts +2 -20
  3. package/dist/agent-protocol/acp/json.js +46 -37
  4. package/dist/agent-protocol/acp/models.js +91 -73
  5. package/dist/agent-protocol/acp/rpc.d.ts +3 -2
  6. package/dist/agent-protocol/acp/rpc.js +3 -2
  7. package/dist/agent-protocol/acp/session-params.d.ts +1 -1
  8. package/dist/agent-protocol/acp/session-params.js +33 -30
  9. package/dist/agent-protocol/acp/session.d.ts +3 -1
  10. package/dist/agent-protocol/acp/session.js +62 -24
  11. package/dist/agent-protocol/acp/updates.js +49 -35
  12. package/dist/agent-protocol/pi-rpc/session.js +3 -1
  13. package/dist/anthropic-live-models.d.ts +12 -4
  14. package/dist/anthropic-live-models.js +0 -0
  15. package/dist/auth.js +84 -91
  16. package/dist/claude-code-models.d.ts +6 -5
  17. package/dist/claude-code-models.js +19 -12
  18. package/dist/claude-segment-usage.d.ts +3 -3
  19. package/dist/claude-segment-usage.js +63 -29
  20. package/dist/claude-stream.js +12 -5
  21. package/dist/copilot-stream.js +42 -50
  22. package/dist/defs/aider.js +3 -4
  23. package/dist/defs/amr.js +52 -61
  24. package/dist/defs/antigravity.d.ts +6 -5
  25. package/dist/defs/antigravity.js +48 -34
  26. package/dist/defs/auggie.d.ts +1 -1
  27. package/dist/defs/claude-compatible-args.d.ts +19 -0
  28. package/dist/defs/claude-compatible-args.js +42 -0
  29. package/dist/defs/claude.d.ts +7 -2
  30. package/dist/defs/claude.js +96 -85
  31. package/dist/defs/cline.d.ts +1 -1
  32. package/dist/defs/codebuddy.d.ts +1 -1
  33. package/dist/defs/codebuddy.js +29 -46
  34. package/dist/defs/codex.d.ts +15 -3
  35. package/dist/defs/codex.js +143 -108
  36. package/dist/defs/cursor-agent.d.ts +9 -7
  37. package/dist/defs/cursor-agent.js +53 -51
  38. package/dist/defs/devin.d.ts +1 -1
  39. package/dist/defs/goose.d.ts +1 -1
  40. package/dist/defs/hermes.d.ts +1 -1
  41. package/dist/defs/kilo.d.ts +1 -1
  42. package/dist/defs/kimi.d.ts +1 -1
  43. package/dist/defs/kiro.d.ts +1 -1
  44. package/dist/defs/opencode.d.ts +5 -4
  45. package/dist/defs/opencode.js +26 -32
  46. package/dist/defs/pi.d.ts +6 -5
  47. package/dist/defs/pi.js +24 -26
  48. package/dist/defs/qoder.d.ts +4 -3
  49. package/dist/defs/qoder.js +25 -25
  50. package/dist/defs/reasonix.d.ts +1 -1
  51. package/dist/defs/shared.d.ts +12 -3
  52. package/dist/defs/shared.js +19 -13
  53. package/dist/defs/trae-cli.d.ts +1 -1
  54. package/dist/defs/vibe.d.ts +1 -1
  55. package/dist/detection.d.ts +13 -20
  56. package/dist/detection.js +129 -111
  57. package/dist/env.js +56 -41
  58. package/dist/executables.js +103 -114
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +1 -0
  61. package/dist/json-event-stream.js +611 -527
  62. package/dist/launch.js +44 -37
  63. package/dist/model-discovery-adapters.d.ts +17 -0
  64. package/dist/model-discovery-adapters.js +223 -164
  65. package/dist/model-discovery-config.js +107 -87
  66. package/dist/model-discovery-sdk.d.ts +16 -2
  67. package/dist/model-discovery-sdk.js +4 -3
  68. package/dist/model-discovery-shared.d.ts +14 -0
  69. package/dist/model-discovery-shared.js +50 -15
  70. package/dist/model-discovery-types.d.ts +2 -0
  71. package/dist/model-discovery.js +219 -117
  72. package/dist/models.d.ts +14 -1
  73. package/dist/models.js +75 -19
  74. package/dist/native-tool-policy.d.ts +29 -0
  75. package/dist/native-tool-policy.js +36 -0
  76. package/dist/opencode-log.js +46 -30
  77. package/dist/paths.d.ts +2 -0
  78. package/dist/paths.js +3 -3
  79. package/dist/providers/aihubmix.js +13 -18
  80. package/dist/providers/anthropic-messages.d.ts +7 -0
  81. package/dist/providers/anthropic-messages.js +45 -21
  82. package/dist/providers/azure-chat.d.ts +5 -0
  83. package/dist/providers/azure-chat.js +13 -5
  84. package/dist/providers/connection-guard.d.ts +2 -45
  85. package/dist/providers/connection-guard.js +11 -10
  86. package/dist/providers/connection-test.d.ts +4 -0
  87. package/dist/providers/connection-test.js +127 -110
  88. package/dist/providers/elevenlabs.js +4 -1
  89. package/dist/providers/google-messages.d.ts +4 -0
  90. package/dist/providers/google-messages.js +48 -23
  91. package/dist/providers/google-schema.js +17 -23
  92. package/dist/providers/model-catalog.js +160 -145
  93. package/dist/providers/oauth-callback-server.js +37 -34
  94. package/dist/providers/oauth-credentials.js +23 -23
  95. package/dist/providers/oauth-tokens.js +16 -24
  96. package/dist/providers/openai-chat.d.ts +42 -0
  97. package/dist/providers/openai-chat.js +80 -10
  98. package/dist/providers/operation-schema.d.ts +25 -0
  99. package/dist/providers/operation-schema.js +226 -0
  100. package/dist/providers/response-text.d.ts +10 -0
  101. package/dist/providers/response-text.js +23 -0
  102. package/dist/providers/tool-turn-types.d.ts +35 -9
  103. package/dist/providers/tool-turn.d.ts +7 -0
  104. package/dist/providers/tool-turn.js +113 -32
  105. package/dist/qoder-stream.js +93 -80
  106. package/dist/registry.d.ts +45 -0
  107. package/dist/registry.js +39 -0
  108. package/dist/runtime-state.d.ts +1 -1
  109. package/dist/types.d.ts +43 -1
  110. package/package.json +16 -7
@@ -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 { googleParametersOf, findNumericEnumPaths, coerceNumericEnumStringsToNumbers } from './google-schema.js';
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 /^data:([^;,]+)/.exec(imageUrl.url)?.[1] ?? "url";
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,97 @@ function describeToolResultContent(content) {
55
60
  })
56
61
  .join("\n");
57
62
  }
58
- function inputSchemaOf(descriptor) {
59
- return descriptor.inputSchema && typeof descriptor.inputSchema === "object"
60
- ? descriptor.inputSchema
61
- : { type: "object", additionalProperties: false, required: [], properties: {} };
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
+ * Work is O(n log n + s) per snapshot for n IDs and s bounded expanded schema nodes; no I/O.
97
+ */
98
+ function createToolProjection(input) {
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
+ async execute(call) {
124
+ if (!published.has(call.name))
125
+ return { isError: true, content: 'Tool is not exposed in this turn.' };
126
+ return input.executeTool(decode(call));
127
+ },
128
+ onEvent(event) {
129
+ input.onEvent(event.type === 'tool_use' ? { ...event, ...decode(event) } : event);
130
+ },
131
+ };
132
+ }
133
+ function anthropicTools(tools) {
134
+ return tools.map(({ name, description, operation }) => ({ name, ...(description !== undefined ? { description } : {}), input_schema: operation.schema, ...(operation.strict ? { strict: true } : {}) }));
135
+ }
136
+ function openAiTools(tools) {
137
+ return tools.map(({ name, description, operation }) => ({ type: 'function', function: { name, ...(description !== undefined ? { description } : {}), parameters: operation.schema, ...(operation.strict ? { strict: true } : {}) } }));
138
+ }
139
+ function googleTools(tools) {
140
+ return [{ functionDeclarations: tools.map(({ name, description, operation }) => ({ name, ...(description !== undefined ? { description } : {}), parameters: operation.schema })) }];
62
141
  }
63
142
  function normalizeTurnResult(result, capturedEndReason = null) {
64
143
  return { stopReason: capturedEndReason ?? result.stopReason ?? result.finishReason ?? null, toolTurns: result.toolTurns };
65
144
  }
66
145
  async function runAnthropicTurn(input) {
67
- const tools = input.tools.map((d) => ({
68
- name: d.id,
69
- ...(d.description !== undefined ? { description: d.description } : {}),
70
- input_schema: inputSchemaOf(d),
71
- }));
146
+ const projection = createToolProjection(input);
147
+ const getTools = (options = {}) => anthropicTools(projection.getTools(options));
148
+ const tools = anthropicTools(projection.getTools({}, { reportFallback: false }));
72
149
  const messages = input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toAnthropicToolContent([
73
150
  { type: 'text', text: m.content }, ...m.images.map(image => ({ type: 'image', ...image })),
74
151
  ]) : m.content }));
75
152
  const executeTool = async (call) => {
76
- const result = await input.executeTool({ id: call.id, name: call.name, input: call.input });
153
+ const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
77
154
  return { content: toAnthropicToolContent(result.content), ...(result.isError !== undefined ? { isError: result.isError } : {}) };
78
155
  };
79
156
  let capturedEndReason = null;
@@ -84,6 +161,8 @@ async function runAnthropicTurn(input) {
84
161
  system: input.system,
85
162
  messages,
86
163
  tools,
164
+ getTools,
165
+ ...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
87
166
  maxTokens: input.maxTokens ?? 8192,
88
167
  ...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
89
168
  executeTool,
@@ -102,16 +181,15 @@ async function runAnthropicTurn(input) {
102
181
  });
103
182
  return;
104
183
  }
105
- input.onEvent(event);
184
+ projection.onEvent(event);
106
185
  },
107
186
  });
108
187
  return normalizeTurnResult(result, capturedEndReason);
109
188
  }
110
189
  async function runOpenAiTurn(input) {
111
- const tools = input.tools.map((d) => ({
112
- type: "function",
113
- function: { name: d.id, ...(d.description !== undefined ? { description: d.description } : {}), parameters: inputSchemaOf(d) },
114
- }));
190
+ const projection = createToolProjection(input);
191
+ const getTools = (options = {}) => openAiTools(projection.getTools(options));
192
+ const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
115
193
  const messages = [
116
194
  { role: "system", content: input.system },
117
195
  ...input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toOpenAiToolContent([
@@ -119,7 +197,7 @@ async function runOpenAiTurn(input) {
119
197
  ]) : m.content })),
120
198
  ];
121
199
  const executeTool = async (call) => {
122
- const result = await input.executeTool({ id: call.id, name: call.name, input: call.input });
200
+ const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
123
201
  return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
124
202
  };
125
203
  let capturedEndReason = null;
@@ -129,6 +207,8 @@ async function runOpenAiTurn(input) {
129
207
  model: input.model,
130
208
  messages,
131
209
  tools,
210
+ getTools,
211
+ ...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
132
212
  ...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
133
213
  ...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
134
214
  executeTool,
@@ -143,7 +223,7 @@ async function runOpenAiTurn(input) {
143
223
  input.onEvent({ type: "tool_result", toolUseId: event.toolUseId, content, isError: event.isError || content.startsWith(TOOL_ERROR_PREFIX.trimEnd()) });
144
224
  return;
145
225
  }
146
- input.onEvent(event);
226
+ projection.onEvent(event);
147
227
  },
148
228
  });
149
229
  return normalizeTurnResult(result, capturedEndReason);
@@ -154,10 +234,9 @@ async function runAzureTurn(input) {
154
234
  input.onEvent({ type: "end", reason: "error" });
155
235
  return { stopReason: "error", toolTurns: 0 };
156
236
  }
157
- const tools = input.tools.map((d) => ({
158
- type: "function",
159
- function: { name: d.id, ...(d.description !== undefined ? { description: d.description } : {}), parameters: inputSchemaOf(d) },
160
- }));
237
+ const projection = createToolProjection(input);
238
+ const getTools = (options = {}) => openAiTools(projection.getTools(options));
239
+ const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
161
240
  const messages = [
162
241
  { role: "system", content: input.system },
163
242
  ...input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toOpenAiToolContent([
@@ -165,7 +244,7 @@ async function runAzureTurn(input) {
165
244
  ]) : m.content })),
166
245
  ];
167
246
  const executeTool = async (call) => {
168
- const result = await input.executeTool({ id: call.id, name: call.name, input: call.input });
247
+ const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
169
248
  return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
170
249
  };
171
250
  let capturedEndReason = null;
@@ -175,6 +254,8 @@ async function runAzureTurn(input) {
175
254
  model: input.model,
176
255
  messages,
177
256
  tools,
257
+ getTools,
258
+ ...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
178
259
  ...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
179
260
  ...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
180
261
  executeTool,
@@ -189,23 +270,21 @@ async function runAzureTurn(input) {
189
270
  input.onEvent({ type: "tool_result", toolUseId: event.toolUseId, content, isError: event.isError || content.startsWith(TOOL_ERROR_PREFIX.trimEnd()) });
190
271
  return;
191
272
  }
192
- input.onEvent(event);
273
+ projection.onEvent(event);
193
274
  },
194
275
  });
195
276
  return normalizeTurnResult(result, capturedEndReason);
196
277
  }
197
278
  async function runGoogleTurn(input) {
198
- const tools = [
199
- { functionDeclarations: input.tools.map((d) => ({ name: d.id, ...(d.description !== undefined ? { description: d.description } : {}), parameters: googleParametersOf({ descriptor: d }) })) },
200
- ];
201
- const numericEnumPathsByToolName = new Map(input.tools.map((d) => [d.id, findNumericEnumPaths({ schema: inputSchemaOf(d) })]));
279
+ const projection = createToolProjection(input);
280
+ const getTools = (options = {}) => googleTools(projection.getTools(options));
281
+ const tools = googleTools(projection.getTools({}, { reportFallback: false }));
202
282
  const contents = input.messages.map((m) => ({
203
283
  role: m.role === "assistant" ? "model" : "user",
204
284
  parts: [{ text: m.content }, ...(m.images ?? []).map(image => ({ inlineData: image }))],
205
285
  }));
206
286
  const executeTool = async (call) => {
207
- const coercedInput = coerceNumericEnumStringsToNumbers({ input: call.input, paths: numericEnumPathsByToolName.get(call.name) ?? [] });
208
- const result = await input.executeTool({ id: call.id, name: call.name, input: coercedInput });
287
+ const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
209
288
  return { content: toGoogleToolContent(result.content), ...(result.isError !== undefined ? { isError: result.isError } : {}) };
210
289
  };
211
290
  let capturedEndReason = null;
@@ -216,6 +295,8 @@ async function runGoogleTurn(input) {
216
295
  system: input.system,
217
296
  contents,
218
297
  tools,
298
+ getTools,
299
+ ...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
219
300
  ...(input.maxTokens !== undefined ? { maxOutputTokens: input.maxTokens } : {}),
220
301
  ...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
221
302
  executeTool,
@@ -234,7 +315,7 @@ async function runGoogleTurn(input) {
234
315
  });
235
316
  return;
236
317
  }
237
- input.onEvent(event);
318
+ projection.onEvent(event);
238
319
  },
239
320
  });
240
321
  return normalizeTurnResult(result, capturedEndReason);
@@ -25,14 +25,15 @@ function stringifyContent(value) {
25
25
  }
26
26
  }
27
27
  function textFromContentBlock(block) {
28
- if (!isRecord(block))
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
- if (typeof obj.error === 'string' && obj.error.length > 0)
46
- return obj.error;
47
- if (isRecord(obj.error) &&
48
- typeof obj.error.message === 'string' &&
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 handleObject(obj, rawLine) {
64
- if (!isRecord(obj))
65
- return;
66
- if (obj.type === 'system' && obj.subtype === 'init') {
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
- if (obj.type === 'assistant' && isRecord(obj.message)) {
79
- const content = Array.isArray(obj.message.content)
80
- ? obj.message.content
81
- : [];
82
- let emittedText = false;
83
- for (const block of content) {
84
- const text = textFromContentBlock(block);
85
- if (text.length > 0) {
86
- emittedText = true;
87
- onEvent({ type: 'text_delta', delta: text });
88
- continue;
89
- }
90
- if (isRecord(block) &&
91
- block.type === 'thinking' &&
92
- typeof block.thinking === 'string' &&
93
- block.thinking.length > 0) {
94
- if (!emittedThinkingStart) {
95
- emittedThinkingStart = true;
96
- onEvent({ type: 'thinking_start' });
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 (obj.type === 'result') {
115
- const isError = Boolean(obj.is_error);
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: 'usage',
118
- usage: obj.usage ?? null,
119
- modelUsage: obj.modelUsage ?? undefined,
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
- if (isError) {
126
- onEvent({
127
- type: 'error',
128
- message: messageFromResult(obj),
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 {
@@ -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
@@ -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 complete detection per launch scope until explicit Rescan. */
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