@jini-ai/agent-runtime 0.6.15-rc.1 → 0.6.15-rc.2

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.
@@ -80,14 +80,6 @@ function defaultPermissionDecision({ optionRecords }, { permissionMode, cliParit
80
80
  function asOptionalString(value) {
81
81
  return typeof value === 'string' ? value : null;
82
82
  }
83
- /** Fires the optional `onSessionInit` callback; kept as a one-liner so the optional-chaining call is scored against this function, not its caller. */
84
- function notifySessionInit(effects) {
85
- effects.onSessionInit?.();
86
- }
87
- /** Resolves a `session/new` response's model config id, if any. */
88
- function resolveModelConfigId(modelConfig) {
89
- return modelConfig?.configId ?? null;
90
- }
91
83
  /**
92
84
  * Handles a JSON-RPC error frame from the agent.
93
85
  *
@@ -429,9 +421,12 @@ function recordSessionIdentity({ state, result }, { resumeSessionId = null } = {
429
421
  export function handleSessionNewAck({ state, effects, result, rawLine, }) {
430
422
  recordSessionIdentity({ state, result }, { resumeSessionId: effects.resumeSessionId });
431
423
  // session/new acknowledged with a session id = handshake done.
424
+ // Invoke the optional callback here instead of relocating its complexity score to a one-line wrapper.
432
425
  if (state.sessionId)
433
- notifySessionInit(effects);
434
- state.modelConfigId = resolveModelConfigId(findModelConfigOption(result.configOptions));
426
+ effects.onSessionInit?.();
427
+ // findModelConfigOption returns null or a parsed config with a required string id.
428
+ const modelConfig = findModelConfigOption(result.configOptions);
429
+ state.modelConfigId = modelConfig ? modelConfig.configId : null;
435
430
  state.activeModel = currentModelFromSessionResult(result);
436
431
  if (state.sessionId && state.activeModel && (!effects.model || effects.model === state.activeModel)) {
437
432
  effects.send({ event: 'agent', payload: { type: 'status', label: 'model', model: state.activeModel } });
@@ -193,7 +193,8 @@ async function runAnthropicTurn(input) {
193
193
  });
194
194
  return normalizeTurnResult(result, capturedEndReason);
195
195
  }
196
- async function runOpenAiTurn(input) {
196
+ /** OpenAI and Azure share message/tool projection; the selected adapter retains its native request semantics. */
197
+ async function runOpenAiCompatibleTurn(input, _options = {}) {
197
198
  const projection = createToolProjection(input);
198
199
  const getTools = (options = {}) => openAiTools(projection.getTools(options));
199
200
  const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
@@ -208,7 +209,14 @@ async function runOpenAiTurn(input) {
208
209
  return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
209
210
  };
210
211
  let capturedEndReason = null;
211
- const result = await (({ apiKey, model, messages, onEvent, ...optionalArgs }) => input.adapters.openai({ apiKey, model, messages, onEvent }, optionalArgs))({
212
+ const result = await (({ apiKey, model, messages, onEvent, ...optionalArgs }) => {
213
+ if (input.protocol === 'azure') {
214
+ // runAzureTurn checks the required endpoint before any projection or adapter work.
215
+ const { baseUrl, ...azureOptions } = optionalArgs;
216
+ return input.adapters.azure({ apiKey, baseUrl: baseUrl, model, messages, onEvent }, azureOptions);
217
+ }
218
+ return input.adapters.openai({ apiKey, model, messages, onEvent }, optionalArgs);
219
+ })({
212
220
  apiKey: input.apiKey,
213
221
  ...(input.baseUrl ? { baseUrl: input.baseUrl } : {}),
214
222
  model: input.model,
@@ -241,46 +249,7 @@ async function runAzureTurn(input) {
241
249
  input.onEvent({ type: "end", reason: "error" });
242
250
  return { stopReason: "error", toolTurns: 0 };
243
251
  }
244
- const projection = createToolProjection(input);
245
- const getTools = (options = {}) => openAiTools(projection.getTools(options));
246
- const tools = openAiTools(projection.getTools({}, { reportFallback: false }));
247
- const messages = [
248
- { role: "system", content: input.system },
249
- ...input.messages.map((m) => ({ role: m.role, content: m.images?.length ? toOpenAiToolContent([
250
- { type: 'text', text: m.content }, ...m.images.map(image => ({ type: 'image', ...image })),
251
- ]) : m.content })),
252
- ];
253
- const executeTool = async (call) => {
254
- const result = await projection.execute({ id: call.id, name: call.name, input: call.input });
255
- return { content: foldToolError(toOpenAiToolContent(result.content), result.isError) };
256
- };
257
- let capturedEndReason = null;
258
- const result = await (({ apiKey, baseUrl, model, messages, onEvent, ...optionalArgs }) => input.adapters.azure({ apiKey, baseUrl, model, messages, onEvent }, optionalArgs))({
259
- apiKey: input.apiKey,
260
- baseUrl: input.baseUrl,
261
- model: input.model,
262
- messages,
263
- tools,
264
- getTools,
265
- ...(input.onSchemaFallback ? { onSchemaFallback: input.onSchemaFallback } : {}),
266
- ...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
267
- ...(input.maxToolTurns !== undefined ? { maxToolTurns: input.maxToolTurns } : {}),
268
- executeTool,
269
- ...(input.signal ? { signal: input.signal } : {}),
270
- onEvent: (event) => {
271
- if (event.type === "fabricated_role_marker")
272
- return;
273
- if (event.type === "end")
274
- capturedEndReason = event.reason;
275
- if (event.type === "tool_result") {
276
- const content = describeToolResultContent(event.content);
277
- input.onEvent({ type: "tool_result", toolUseId: event.toolUseId, content, isError: event.isError || content.startsWith(TOOL_ERROR_PREFIX.trimEnd()) });
278
- return;
279
- }
280
- projection.onEvent(event);
281
- },
282
- });
283
- return normalizeTurnResult(result, capturedEndReason);
252
+ return runOpenAiCompatibleTurn(input);
284
253
  }
285
254
  async function runGoogleTurn(input) {
286
255
  const projection = createToolProjection(input);
@@ -336,7 +305,7 @@ export async function runProviderToolTurn(required, optional = {}) {
336
305
  case "anthropic":
337
306
  return runAnthropicTurn(input);
338
307
  case "openai":
339
- return runOpenAiTurn(input);
308
+ return runOpenAiCompatibleTurn(input);
340
309
  case "azure":
341
310
  return runAzureTurn(input);
342
311
  case "google":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/agent-runtime",
3
- "version": "0.6.15-rc.1",
3
+ "version": "0.6.15-rc.2",
4
4
  "description": "Coding-agent runtime adapters: runtime registry, detection, launch, stream parsers, and the ACP/pi-rpc subprocess transport.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -114,18 +114,18 @@
114
114
  "devDependencies": {
115
115
  "@vitest/coverage-v8": "^2.1.9",
116
116
  "@jini-ai/core": "^0.6.13",
117
- "@jini-ai/platform": "^0.6.15-rc.1",
118
- "@jini-ai/integrations": "^0.6.15-rc.1"
117
+ "@jini-ai/integrations": "^0.6.15-rc.2",
118
+ "@jini-ai/platform": "^0.6.15-rc.2"
119
119
  },
120
120
  "dependencies": {
121
- "@jini-ai/oauth": "^0.6.15-rc.1",
122
- "@jini-ai/protocol": "^0.6.15-rc.1",
123
- "@jini-ai/core": "^0.6.15-rc.1"
121
+ "@jini-ai/core": "^0.6.15-rc.2",
122
+ "@jini-ai/protocol": "^0.6.15-rc.2",
123
+ "@jini-ai/oauth": "^0.6.15-rc.2"
124
124
  },
125
125
  "peerDependencies": {
126
- "@jini-ai/integrations": "^0.6.15-rc.1",
126
+ "@jini-ai/integrations": "^0.6.15-rc.2",
127
127
  "@github/copilot-sdk": "*",
128
- "@jini-ai/platform": "^0.6.15-rc.1"
128
+ "@jini-ai/platform": "^0.6.15-rc.2"
129
129
  },
130
130
  "peerDependenciesMeta": {
131
131
  "@jini-ai/integrations": {