@jini-ai/agent-runtime 0.7.3-next.2 → 0.7.4

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 (177) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +38 -0
  3. package/dist/agent-protocol/acp/models.d.ts +0 -10
  4. package/dist/agent-protocol/acp/models.js +0 -10
  5. package/dist/agent-protocol/acp/rpc.d.ts +5 -1
  6. package/dist/agent-protocol/acp/rpc.js +2 -1
  7. package/dist/agent-protocol/acp/session-permission.js +4 -3
  8. package/dist/agent-protocol/acp/session-results.d.ts +4 -4
  9. package/dist/agent-protocol/acp/session-results.js +30 -21
  10. package/dist/agent-protocol/acp/session-run.js +0 -8
  11. package/dist/agent-protocol/acp/session-types.d.ts +0 -1
  12. package/dist/agent-protocol/acp/session-usage.d.ts +12 -0
  13. package/dist/agent-protocol/acp/session-usage.js +29 -0
  14. package/dist/agent-protocol/acp/session.d.ts +1 -1
  15. package/dist/agent-protocol/acp/session.js +10 -4
  16. package/dist/agent-protocol/acp/text-suppression.js +75 -71
  17. package/dist/agent-protocol/pi-rpc/events.d.ts +21 -4
  18. package/dist/agent-protocol/pi-rpc/events.js +9 -9
  19. package/dist/agent-protocol/pi-rpc/internal.d.ts +6 -2
  20. package/dist/agent-protocol/pi-rpc/internal.js +6 -4
  21. package/dist/agent-protocol/pi-rpc/session.js +4 -3
  22. package/dist/anthropic-live-models.js +0 -0
  23. package/dist/claude-code-models.d.ts +3 -1
  24. package/dist/claude-code-models.js +4 -4
  25. package/dist/claude-stream-frames.js +1 -1
  26. package/dist/cli-probe-cache.d.ts +33 -0
  27. package/dist/cli-probe-cache.js +59 -0
  28. package/dist/custom-instructions.d.ts +107 -0
  29. package/dist/custom-instructions.js +80 -0
  30. package/dist/defs/{aider.d.ts → aider/index.d.ts} +2 -1
  31. package/dist/defs/{aider.js → aider/index.js} +6 -3
  32. package/dist/defs/amr/executable-env.d.ts +2 -0
  33. package/dist/defs/amr/executable-env.js +2 -0
  34. package/dist/defs/amr/executable-resolution.d.ts +5 -1
  35. package/dist/defs/amr/executable-resolution.js +1 -1
  36. package/dist/defs/antigravity/index.d.ts +1 -0
  37. package/dist/defs/antigravity/index.js +3 -0
  38. package/dist/defs/antigravity/permissions.d.ts +26 -0
  39. package/dist/defs/antigravity/permissions.js +66 -0
  40. package/dist/defs/{auggie.d.ts → auggie/index.d.ts} +1 -1
  41. package/dist/defs/{auggie.js → auggie/index.js} +3 -3
  42. package/dist/defs/claude/config-dir.d.ts +62 -0
  43. package/dist/defs/claude/config-dir.js +133 -0
  44. package/dist/defs/claude/filesystem.d.ts +33 -0
  45. package/dist/defs/claude/filesystem.js +30 -0
  46. package/dist/defs/{claude.d.ts → claude/index.d.ts} +1 -1
  47. package/dist/defs/{claude.js → claude/index.js} +9 -9
  48. package/dist/defs/claude/mcp-config.d.ts +22 -0
  49. package/dist/defs/claude/mcp-config.js +29 -0
  50. package/dist/defs/claude/mcp-delivery.d.ts +57 -0
  51. package/dist/defs/claude/mcp-delivery.js +75 -0
  52. package/dist/defs/claude/mcp-json.d.ts +34 -0
  53. package/dist/defs/claude/mcp-json.js +38 -0
  54. package/dist/defs/claude/subagent-start.d.ts +12 -0
  55. package/dist/defs/claude/subagent-start.js +35 -0
  56. package/dist/defs/{cline.d.ts → cline/index.d.ts} +1 -1
  57. package/dist/defs/{cline.js → cline/index.js} +3 -3
  58. package/dist/defs/codex/contracts.d.ts +47 -0
  59. package/dist/defs/codex/contracts.js +6 -0
  60. package/dist/defs/codex/event-stream.d.ts +5 -1
  61. package/dist/defs/codex/event-stream.js +29 -24
  62. package/dist/defs/codex/home-config.d.ts +55 -0
  63. package/dist/defs/codex/home-config.js +224 -0
  64. package/dist/defs/codex/home-staging.d.ts +57 -0
  65. package/dist/defs/codex/home-staging.js +184 -0
  66. package/dist/defs/{codex.d.ts → codex/index.d.ts} +2 -2
  67. package/dist/defs/{codex.js → codex/index.js} +3 -3
  68. package/dist/defs/codex/isolation.d.ts +29 -0
  69. package/dist/defs/codex/isolation.js +69 -0
  70. package/dist/defs/codex/launch.d.ts +4 -1
  71. package/dist/defs/codex/launch.js +1 -1
  72. package/dist/defs/codex/mcp-delivery.d.ts +8 -0
  73. package/dist/defs/codex/mcp-delivery.js +5 -0
  74. package/dist/defs/{crush.d.ts → crush/index.d.ts} +1 -1
  75. package/dist/defs/{crush.js → crush/index.js} +3 -3
  76. package/dist/defs/cursor-agent/event-stream.d.ts +5 -1
  77. package/dist/defs/cursor-agent/event-stream.js +14 -7
  78. package/dist/defs/{cursor-agent.d.ts → cursor-agent/index.d.ts} +1 -1
  79. package/dist/defs/{cursor-agent.js → cursor-agent/index.js} +4 -4
  80. package/dist/defs/{deepseek.d.ts → deepseek/index.d.ts} +2 -1
  81. package/dist/defs/{deepseek.js → deepseek/index.js} +6 -3
  82. package/dist/defs/{devin.d.ts → devin/index.d.ts} +1 -1
  83. package/dist/defs/{devin.js → devin/index.js} +3 -3
  84. package/dist/defs/{droid.d.ts → droid/index.d.ts} +1 -1
  85. package/dist/defs/{droid.js → droid/index.js} +3 -3
  86. package/dist/defs/gemini/event-stream.d.ts +5 -1
  87. package/dist/defs/gemini/event-stream.js +15 -12
  88. package/dist/defs/gemini/tool-calls.d.ts +7 -0
  89. package/dist/defs/gemini/tool-calls.js +9 -0
  90. package/dist/defs/{goose.d.ts → goose/index.d.ts} +1 -1
  91. package/dist/defs/{goose.js → goose/index.js} +3 -3
  92. package/dist/defs/{grok-build.d.ts → grok-build/index.d.ts} +1 -1
  93. package/dist/defs/{grok-build.js → grok-build/index.js} +3 -3
  94. package/dist/defs/index.d.ts +28 -28
  95. package/dist/defs/index.js +28 -28
  96. package/dist/defs/{kilo.d.ts → kilo/index.d.ts} +1 -1
  97. package/dist/defs/{kilo.js → kilo/index.js} +3 -3
  98. package/dist/defs/kimi/event-stream.d.ts +4 -1
  99. package/dist/defs/kimi/event-stream.js +6 -5
  100. package/dist/defs/{kimi.d.ts → kimi/index.d.ts} +1 -1
  101. package/dist/defs/{kimi.js → kimi/index.js} +3 -3
  102. package/dist/defs/{kiro.d.ts → kiro/index.d.ts} +1 -1
  103. package/dist/defs/{kiro.js → kiro/index.js} +3 -3
  104. package/dist/defs/mimo/constants.d.ts +2 -0
  105. package/dist/defs/mimo/constants.js +2 -0
  106. package/dist/defs/{mimo.d.ts → mimo/index.d.ts} +1 -1
  107. package/dist/defs/{mimo.js → mimo/index.js} +3 -3
  108. package/dist/defs/opencode/constants.d.ts +2 -0
  109. package/dist/defs/opencode/constants.js +2 -0
  110. package/dist/defs/opencode/event-stream.d.ts +5 -1
  111. package/dist/defs/opencode/event-stream.js +13 -11
  112. package/dist/defs/{opencode.d.ts → opencode/index.d.ts} +2 -2
  113. package/dist/defs/{opencode.js → opencode/index.js} +5 -5
  114. package/dist/defs/opencode/mcp-config.d.ts +108 -0
  115. package/dist/defs/opencode/mcp-config.js +119 -0
  116. package/dist/defs/opencode/model-discovery.d.ts +3 -1
  117. package/dist/defs/opencode/model-discovery.js +1 -1
  118. package/dist/defs/opencode/tool-calls.d.ts +7 -0
  119. package/dist/defs/opencode/tool-calls.js +12 -0
  120. package/dist/defs/{opencode-acp.d.ts → opencode-acp/index.d.ts} +2 -2
  121. package/dist/defs/{opencode-acp.js → opencode-acp/index.js} +4 -4
  122. package/dist/defs/{pi.d.ts → pi/index.d.ts} +1 -1
  123. package/dist/defs/{pi.js → pi/index.js} +3 -3
  124. package/dist/defs/pi/model-discovery.d.ts +4 -1
  125. package/dist/defs/pi/model-discovery.js +1 -1
  126. package/dist/defs/{qoder.d.ts → qoder/index.d.ts} +1 -1
  127. package/dist/defs/{qoder.js → qoder/index.js} +3 -3
  128. package/dist/defs/{qwen.d.ts → qwen/index.d.ts} +1 -1
  129. package/dist/defs/{qwen.js → qwen/index.js} +3 -3
  130. package/dist/defs/{reasonix.d.ts → reasonix/index.d.ts} +1 -1
  131. package/dist/defs/{reasonix.js → reasonix/index.js} +3 -3
  132. package/dist/defs/{trae-cli.d.ts → trae-cli/index.d.ts} +1 -1
  133. package/dist/defs/{trae-cli.js → trae-cli/index.js} +3 -3
  134. package/dist/defs/{vibe.d.ts → vibe/index.d.ts} +1 -1
  135. package/dist/defs/{vibe.js → vibe/index.js} +3 -3
  136. package/dist/executables.js +1 -1
  137. package/dist/inventory/index.d.ts +61 -0
  138. package/dist/inventory/index.js +45 -0
  139. package/dist/json-event-stream-shared.d.ts +10 -2
  140. package/dist/json-event-stream-shared.js +21 -13
  141. package/dist/json-event-stream.js +6 -5
  142. package/dist/launch.js +1 -1
  143. package/dist/model-catalog-live-discovery.d.ts +103 -0
  144. package/dist/model-catalog-live-discovery.js +111 -0
  145. package/dist/model-discovery-adapters.d.ts +6 -1
  146. package/dist/model-discovery-adapters.js +4 -3
  147. package/dist/model-discovery-config.js +1 -1
  148. package/dist/native-permissions.d.ts +19 -0
  149. package/dist/native-permissions.js +22 -0
  150. package/dist/providers/anthropic-messages.js +3 -2
  151. package/dist/providers/connection-guard.js +99 -84
  152. package/dist/providers/connection-test.js +0 -5
  153. package/dist/providers/google-messages.js +1 -1
  154. package/dist/providers/oauth-provider.d.ts +1 -23
  155. package/dist/providers/oauth-provider.js +1 -35
  156. package/dist/providers/openai-chat-request.js +1 -1
  157. package/dist/providers/tool-loop-verdict.d.ts +1 -0
  158. package/dist/providers/tool-loop-verdict.js +4 -1
  159. package/dist/providers/tool-turn-types.d.ts +12 -9
  160. package/dist/providers/tool-turn.d.ts +63 -1
  161. package/dist/providers/tool-turn.js +67 -1
  162. package/dist/qoder-stream.js +66 -66
  163. package/dist/role-marker-guard.js +49 -30
  164. package/dist/runtime-def-binding.js +1 -1
  165. package/dist/runtime-port-bindings.d.ts +82 -0
  166. package/dist/runtime-port-bindings.js +4 -1
  167. package/dist/runtime-strategies.d.ts +100 -0
  168. package/dist/runtime-strategies.js +129 -0
  169. package/package.json +44 -10
  170. package/dist/defs/amp.d.ts +0 -2
  171. package/dist/defs/amp.js +0 -2
  172. package/dist/defs/amr.d.ts +0 -2
  173. package/dist/defs/amr.js +0 -2
  174. package/dist/defs/codebuddy.d.ts +0 -2
  175. package/dist/defs/codebuddy.js +0 -2
  176. package/dist/defs/hermes.d.ts +0 -2
  177. package/dist/defs/hermes.js +0 -2
@@ -15,10 +15,7 @@
15
15
  * generic-provider-material classification this task asked for — so the
16
16
  * dance is now a config-driven `beginOAuthPkce`/`completeOAuthPkce`/
17
17
  * `refreshOAuthPkceToken` triad taking an {@link OAuthPkceProviderConfig},
18
- * with `XAI_OAUTH_PROVIDER_CONFIG` kept as the one concrete preset the
19
- * origin actually shipped (same pattern this package already uses for
20
- * `RuntimeAgentDef` — a generic contract type plus concrete `defs/*`
21
- * instances).
18
+ * (the concrete xAI preset now lives in `@jini-ai/provider-plugins/xai/preset`).
22
19
  */
23
20
  import { buildAuthorizeUrl, deriveCodeChallenge, exchangeCodeForToken, generateCodeVerifier, generateState, refreshAccessToken, } from './pkce.js';
24
21
  function authServerMetadata(config) {
@@ -91,35 +88,4 @@ export async function refreshOAuthPkceToken(requiredArgs, optionalArgs = {}) {
91
88
  refreshToken: input.refreshToken,
92
89
  } }, { fetchImpl: input.fetchImpl ?? fetch });
93
90
  }
94
- // ---------------------------------------------------------------------------
95
- // Concrete preset: the one OAuth+PKCE provider the origin actually shipped.
96
- // ---------------------------------------------------------------------------
97
- /** Stable provider id used to key an xAI token in any per-provider cache. */
98
- export const XAI_OAUTH_PROVIDER_ID = 'xai';
99
- export const XAI_OAUTH_REDIRECT_HOST = '127.0.0.1';
100
- export const XAI_OAUTH_REDIRECT_PORT = 56121;
101
- export const XAI_OAUTH_REDIRECT_PATH = '/callback';
102
- /**
103
- * xAI Grok OAuth 2.0 + PKCE provider config. xAI doesn't speak MCP and
104
- * doesn't expose Dynamic Client Registration, so the issuer / endpoints /
105
- * client_id / scope are hardcoded rather than discovered — same as the
106
- * origin.
107
- *
108
- * `clientId` is a proof-of-concept id reused from NousResearch/hermes-agent
109
- * (xAI does not publish a public application-registration flow); a
110
- * consumer that provisions its own client_id with xAI should override this
111
- * field rather than edit the constant.
112
- */
113
- export const XAI_OAUTH_PROVIDER_CONFIG = {
114
- providerId: XAI_OAUTH_PROVIDER_ID,
115
- issuer: 'https://auth.x.ai',
116
- authorizationEndpoint: 'https://auth.x.ai/oauth2/authorize',
117
- tokenEndpoint: 'https://auth.x.ai/oauth2/token',
118
- clientId: 'b1a00492-073a-47ea-816f-4c329264a828',
119
- scope: 'openid profile email offline_access grok-cli:access api:access',
120
- };
121
- /** The fixed loopback redirect URI xAI's client_id is registered against. */
122
- export function xaiOAuthRedirectUri() {
123
- return `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}${XAI_OAUTH_REDIRECT_PATH}`;
124
- }
125
91
  //# sourceMappingURL=oauth-provider.js.map
@@ -1,4 +1,4 @@
1
- import { redactSecrets } from '@jini-ai/core';
1
+ import { redactSecrets } from '@jini-ai/core/redaction';
2
2
  import { createRoleMarkerGuard } from '../role-marker-guard.js';
3
3
  import { extractProviderErrorDetail } from './response-text.js';
4
4
  import { pinnedFetch } from './connection-guard.js';
@@ -13,6 +13,7 @@ export interface ToolLoopVerdict<R extends string> {
13
13
  * own exit reason stops it, and so does a missing executor: pending tool calls were already emitted
14
14
  * as `tool_use` events, so with nothing to run them the turn ends with `'stop'` rather than
15
15
  * silently retrying forever. `exitReason` is only consulted for a turn that has not ended.
16
+ * A tool-turn limit only applies when tools can actually execute; provider errors still win.
16
17
  */
17
18
  export declare function toolLoopVerdict<R extends string>({ ended, hasExecutor, exitReason }: {
18
19
  ended: boolean;
@@ -7,11 +7,14 @@
7
7
  * own exit reason stops it, and so does a missing executor: pending tool calls were already emitted
8
8
  * as `tool_use` events, so with nothing to run them the turn ends with `'stop'` rather than
9
9
  * silently retrying forever. `exitReason` is only consulted for a turn that has not ended.
10
+ * A tool-turn limit only applies when tools can actually execute; provider errors still win.
10
11
  */
11
12
  export function toolLoopVerdict({ ended, hasExecutor, exitReason }, _optional = {}) {
12
13
  if (ended)
13
14
  return { stop: true, emit: null };
14
- const emit = exitReason() || (hasExecutor ? null : 'stop');
15
+ const reason = exitReason();
16
+ // Preserve the pre-extraction missing-executor precedence without hiding Google's empty-turn errors.
17
+ const emit = !hasExecutor && (reason === null || reason === 'max_tool_turns') ? 'stop' : reason;
15
18
  return { stop: emit !== null, emit };
16
19
  }
17
20
  //# sourceMappingURL=tool-loop-verdict.js.map
@@ -1,3 +1,4 @@
1
+ import type { ToolResultContentBlock } from '@jini-ai/core/contracts/tool-result-block';
1
2
  import type { runAnthropicToolTurn, AnthropicToolDef } from './anthropic-messages.js';
2
3
  import type { runOpenAiToolTurn } from './openai-chat.js';
3
4
  import type { OpenAiFunctionToolDef } from './openai-chat-types.js';
@@ -69,18 +70,13 @@ export interface ProviderToolCall {
69
70
  readonly name: string;
70
71
  readonly input: unknown;
71
72
  }
72
- export type ProviderToolResultBlock = {
73
- readonly type: "text";
74
- readonly text: string;
75
- } | {
76
- readonly type: "image";
77
- readonly mimeType: string;
78
- readonly data: string;
79
- };
80
73
  export interface ProviderToolResult {
81
- readonly content: string | readonly ProviderToolResultBlock[];
74
+ /** A string for an ordinary result; blocks only when the result carries an image. */
75
+ readonly content: string | readonly ToolResultContentBlock[];
82
76
  readonly isError?: boolean;
83
77
  }
78
+ /** Host-owned tool execution (e.g. bridged to a daemon `ToolExecutor` over the host's own tool
79
+ * surface); always supplied, the same convention every protocol adapter uses for its executor. */
84
80
  export type ProviderToolExecutor = (call: ProviderToolCall) => Promise<ProviderToolResult>;
85
81
  /** Raw provider call metadata: an unpublished wire name has no canonical tool ID or decoder. */
86
82
  export interface ProviderUnexposedToolCall {
@@ -99,6 +95,7 @@ export interface ProviderToolTurnInput {
99
95
  readonly protocol: ProviderProtocol;
100
96
  readonly adapters: ProviderTurnAdapters;
101
97
  readonly apiKey: string;
98
+ /** `anthropic`/`openai`/`google`: a model id. `azure`: the deployment name, not a raw model id — see `AzureTurnOptions.model`'s own doc. */
102
99
  readonly model: string;
103
100
  readonly system: string;
104
101
  readonly messages: readonly ProviderChatMessage[];
@@ -124,8 +121,14 @@ export interface ProviderToolTurnOptions {
124
121
  readonly getToolSnapshot?: () => readonly ProviderToolDescriptor[];
125
122
  /** Value-free diagnostic only; execution must still validate through the host executor. */
126
123
  readonly onSchemaFallback?: (event: ProviderSchemaFallback) => void;
124
+ /** Required for `azure` (no sane global default — every Azure OpenAI resource has its own
125
+ * endpoint); optional for the other three protocols, which fall back to each adapter's own
126
+ * public default endpoint. */
127
127
  readonly baseUrl?: string;
128
128
  readonly maxTokens?: number;
129
+ /** Overrides the provider's tool-turn limit. A meta-tool surface spends several calls (e.g.
130
+ * search/describe/execute) per action, so the provider default can truncate multi-step tasks;
131
+ * the host injects its own policy value. Omit to keep the provider default. */
129
132
  readonly maxToolTurns?: number;
130
133
  readonly signal?: AbortSignal;
131
134
  }
@@ -1,10 +1,17 @@
1
- import type { ProviderTurnAdapters, ProviderToolTurnInput, ProviderToolTurnResult, ProviderToolTurnOptions } from './tool-turn-types.js';
1
+ import type { ProviderTurnAdapters, ProviderToolTurnInput, ProviderToolTurnResult, ProviderToolTurnOptions, ProviderProtocol } from './tool-turn-types.js';
2
2
  export type * from './tool-turn-types.js';
3
3
  export { compileOperationSchema } from './operation-schema.js';
4
4
  export type { CompiledOperationSchema, OperationSchemaFallbackReason } from './operation-schema.js';
5
5
  export { googleParametersOf, sanitizeGoogleSchema, findNumericEnumPaths, coerceNumericEnumStringsToNumbers } from './google-schema.js';
6
6
  /** Existing provider loops, ready for host composition; callers may replace any adapter. */
7
7
  export declare const providerTurnAdapters: ProviderTurnAdapters;
8
+ /** A stored, free-form provider string narrowed to a protocol the default adapters can dispatch, or
9
+ * null when it names something else. Case- and whitespace-insensitive because the stored column is
10
+ * free-form. The adapters themselves own the supported protocols; no second allowlist lives here.
11
+ * @complexity O(n) in provider length. */
12
+ export declare function resolveProviderProtocol({ provider }: {
13
+ provider: string;
14
+ }, _optional?: {}): ProviderProtocol | null;
8
15
  /** Invalid snapshot names fail closed before an adapter can dispatch an ambiguous operation. */
9
16
  export declare class ProviderToolProjectionError extends Error {
10
17
  readonly code = "invalid-wire-name";
@@ -12,6 +19,61 @@ export declare class ProviderToolProjectionError extends Error {
12
19
  }
13
20
  /** Runs one provider-neutral turn through the supplied adapters. The adapter end event takes precedence over a raw provider stop code.
14
21
  * Local mapping is proportional to the descriptors, expanded schemas and emitted result parts; request and loop cost belongs to the adapter ports.
22
+ *
23
+ * Provider mapping constraints (implemented here and in `google-schema.ts`):
24
+ *
25
+ * OpenAI/Azure have no host-tool-error flag on their wire. A shared fold marker carries failures
26
+ * into content and restores `isError` on outgoing events; adapter validation alone cannot detect a
27
+ * host denial in an otherwise valid string result. Azure uses the same content shape as OpenAI.
28
+ * Anthropic accepts JPEG/PNG/GIF/WebP image sources; its adapter guards unsupported media types.
29
+ * OpenAI/Azure move image parts into a follow-up user message because tool messages are text-only;
30
+ * Gemini places inline data beside function responses. Transcript events describe each image by
31
+ * MIME type instead of emitting base64 noise. Plain string results remain unchanged.
32
+ * Missing input schemas use an empty-object schema; schema dialect is a consumer concern.
33
+ *
34
+ * Gemini's restricted Schema cannot express full JSON Schema. Its supported-key allowlist follows
35
+ * the validator's Available Fields list (the Google AI Developer forum's "oneOf in response_schema"
36
+ * thread), which includes fields omitted by the prose API docs. Unsupported keys are dropped only
37
+ * from model guidance: tool handlers still validate inputs server-side. `const` becomes `enum`;
38
+ * `oneOf` becomes `anyOf`. That conversion is equivalent for disjoint tagged unions (e.g. navigation
39
+ * targets and TipTap nodes); overlapping future branches require an owner decision because the
40
+ * conversion would loosen the constraint.
41
+ *
42
+ * Local #/$defs references are resolved against the nearest enclosing, per-call definitions map,
43
+ * preventing concurrent turns from sharing definitions. Unknown references degrade to object
44
+ * guidance instead of failing an entire turn. References are inlined because Gemini has no $ref;
45
+ * ordinary object/array traversal does not consume the reference-depth budget.
46
+ * The reference cap is 4, a chosen bound rather than a product invariant: TipTap's recursive
47
+ * eight-branch block union grows combinatorially, and two reference hops represent one visible
48
+ * list/blockquote nesting level. Four hops cover two such levels while bounding request size.
49
+ * A navigation tree's separate depth limit does not determine this cap. Deeper content
50
+ * remains permissible but undescribed by a shallow type/description stub (union stubs use object);
51
+ * the stub must not recurse into properties, items or branches and recreate unbounded expansion.
52
+ *
53
+ * Gemini requires every array schema to declare items and every node to declare type unless it
54
+ * has anyOf. Unknown array items degrade to string, the narrowest valid approximation, rather than
55
+ * inviting arbitrary objects. Structural repair applies only at schema positions (properties.*, items,
56
+ * anyOf), never arbitrary default/example objects, which must not acquire invented type fields.
57
+ * Properties preserve author-chosen keys. Validation must use googleParametersOf, including shape
58
+ * repair, so it checks the actual wire schema rather than an incomplete lower-level conversion.
59
+ *
60
+ * Bare const literals infer boolean/integer/number/string; object/array const sites need an explicit
61
+ * type instead of broader inference. A type array collapses to one non-null type plus nullable;
62
+ * multiple non-null types lose precision and require an owner decision if used. Null enum members
63
+ * are removed because Gemini's enum accepts strings only and sibling nullable already conveys null.
64
+ * Numeric enums are stringified for Gemini and must be converted back at the tool-call boundary:
65
+ * a handler such as a redirect's statusCode still requires a number. Numeric paths come from the original
66
+ * unsanitized schema, once per tool, because sanitization overwrites the numeric type. The original
67
+ * type check prevents coercing numeric enum values on nonnumeric fields. Discovery traverses only
68
+ * properties, not arrays, unions or $refs; a numeric enum in those positions needs an extension.
69
+ * Coercion accepts only finite numeric-looking, nonblank strings and clones only the changed path;
70
+ * malformed paths/arguments remain untouched for the handler's validation rather than inventing data.
71
+ *
72
+ * The adapter's captured end-event reason takes precedence over the final response's raw stop code:
73
+ * a raw tool_use can mean the loop hit its cap while the model still wanted tools. Raw stop/finish
74
+ * fields are fallbacks only when no end event was observed; callers must explain the loop's actual
75
+ * stop. Anthropic alone requires a max-token default when omitted, so the shared mapping supplies it.
76
+ * Provider-internal fabricated-role-marker diagnostics are filtered because the client has no event case.
15
77
  */
16
78
  export declare function runProviderToolTurn(required: ProviderToolTurnInput, optional?: ProviderToolTurnOptions): Promise<ProviderToolTurnResult>;
17
79
  //# sourceMappingURL=tool-turn.d.ts.map
@@ -3,12 +3,20 @@ import { runAzureToolTurn } from './azure-chat.js';
3
3
  import { runGoogleToolTurn } from './google-messages.js';
4
4
  import { runOpenAiToolTurn } from './openai-chat.js';
5
5
  import {} from './openai-chat-types.js';
6
- import { createToolNameMap } from '@jini-ai/core';
6
+ import { createToolNameMap } from '@jini-ai/core/tool-exposure';
7
7
  import { compileOperationSchema } from './operation-schema.js';
8
8
  export { compileOperationSchema } from './operation-schema.js';
9
9
  export { googleParametersOf, sanitizeGoogleSchema, findNumericEnumPaths, coerceNumericEnumStringsToNumbers } from './google-schema.js';
10
10
  /** Existing provider loops, ready for host composition; callers may replace any adapter. */
11
11
  export const providerTurnAdapters = Object.freeze({ anthropic: runAnthropicToolTurn, openai: runOpenAiToolTurn, azure: runAzureToolTurn, google: runGoogleToolTurn });
12
+ /** A stored, free-form provider string narrowed to a protocol the default adapters can dispatch, or
13
+ * null when it names something else. Case- and whitespace-insensitive because the stored column is
14
+ * free-form. The adapters themselves own the supported protocols; no second allowlist lives here.
15
+ * @complexity O(n) in provider length. */
16
+ export function resolveProviderProtocol({ provider }, _optional = {}) {
17
+ const normalized = provider.trim().toLowerCase();
18
+ return Object.hasOwn(providerTurnAdapters, normalized) ? normalized : null;
19
+ }
12
20
  const TOOL_ERROR_PREFIX = "[tool error] ";
13
21
  function toAnthropicToolContent(content) {
14
22
  if (typeof content === "string")
@@ -101,6 +109,9 @@ function createToolProjection(input, _options = {}) {
101
109
  const published = new Map();
102
110
  const reported = new Set();
103
111
  function getTools({ strict = false } = {}, { reportFallback = true } = {}) {
112
+ // Descriptors only, never handlers — the same public shape `ToolRegistry.list()` returns
113
+ // (`@jini-ai/core`'s own "handlers never publicly retrievable" invariant, see that package's
114
+ // `tool-registry.ts` module doc). Mapped into each protocol's own tool-def shape below.
104
115
  const descriptors = input.getToolSnapshot?.() ?? input.tools;
105
116
  pinWireNames(descriptors, names);
106
117
  return descriptors.map(descriptor => {
@@ -278,6 +289,61 @@ async function runGoogleTurn(input) {
278
289
  }
279
290
  /** Runs one provider-neutral turn through the supplied adapters. The adapter end event takes precedence over a raw provider stop code.
280
291
  * Local mapping is proportional to the descriptors, expanded schemas and emitted result parts; request and loop cost belongs to the adapter ports.
292
+ *
293
+ * Provider mapping constraints (implemented here and in `google-schema.ts`):
294
+ *
295
+ * OpenAI/Azure have no host-tool-error flag on their wire. A shared fold marker carries failures
296
+ * into content and restores `isError` on outgoing events; adapter validation alone cannot detect a
297
+ * host denial in an otherwise valid string result. Azure uses the same content shape as OpenAI.
298
+ * Anthropic accepts JPEG/PNG/GIF/WebP image sources; its adapter guards unsupported media types.
299
+ * OpenAI/Azure move image parts into a follow-up user message because tool messages are text-only;
300
+ * Gemini places inline data beside function responses. Transcript events describe each image by
301
+ * MIME type instead of emitting base64 noise. Plain string results remain unchanged.
302
+ * Missing input schemas use an empty-object schema; schema dialect is a consumer concern.
303
+ *
304
+ * Gemini's restricted Schema cannot express full JSON Schema. Its supported-key allowlist follows
305
+ * the validator's Available Fields list (the Google AI Developer forum's "oneOf in response_schema"
306
+ * thread), which includes fields omitted by the prose API docs. Unsupported keys are dropped only
307
+ * from model guidance: tool handlers still validate inputs server-side. `const` becomes `enum`;
308
+ * `oneOf` becomes `anyOf`. That conversion is equivalent for disjoint tagged unions (e.g. navigation
309
+ * targets and TipTap nodes); overlapping future branches require an owner decision because the
310
+ * conversion would loosen the constraint.
311
+ *
312
+ * Local #/$defs references are resolved against the nearest enclosing, per-call definitions map,
313
+ * preventing concurrent turns from sharing definitions. Unknown references degrade to object
314
+ * guidance instead of failing an entire turn. References are inlined because Gemini has no $ref;
315
+ * ordinary object/array traversal does not consume the reference-depth budget.
316
+ * The reference cap is 4, a chosen bound rather than a product invariant: TipTap's recursive
317
+ * eight-branch block union grows combinatorially, and two reference hops represent one visible
318
+ * list/blockquote nesting level. Four hops cover two such levels while bounding request size.
319
+ * A navigation tree's separate depth limit does not determine this cap. Deeper content
320
+ * remains permissible but undescribed by a shallow type/description stub (union stubs use object);
321
+ * the stub must not recurse into properties, items or branches and recreate unbounded expansion.
322
+ *
323
+ * Gemini requires every array schema to declare items and every node to declare type unless it
324
+ * has anyOf. Unknown array items degrade to string, the narrowest valid approximation, rather than
325
+ * inviting arbitrary objects. Structural repair applies only at schema positions (properties.*, items,
326
+ * anyOf), never arbitrary default/example objects, which must not acquire invented type fields.
327
+ * Properties preserve author-chosen keys. Validation must use googleParametersOf, including shape
328
+ * repair, so it checks the actual wire schema rather than an incomplete lower-level conversion.
329
+ *
330
+ * Bare const literals infer boolean/integer/number/string; object/array const sites need an explicit
331
+ * type instead of broader inference. A type array collapses to one non-null type plus nullable;
332
+ * multiple non-null types lose precision and require an owner decision if used. Null enum members
333
+ * are removed because Gemini's enum accepts strings only and sibling nullable already conveys null.
334
+ * Numeric enums are stringified for Gemini and must be converted back at the tool-call boundary:
335
+ * a handler such as a redirect's statusCode still requires a number. Numeric paths come from the original
336
+ * unsanitized schema, once per tool, because sanitization overwrites the numeric type. The original
337
+ * type check prevents coercing numeric enum values on nonnumeric fields. Discovery traverses only
338
+ * properties, not arrays, unions or $refs; a numeric enum in those positions needs an extension.
339
+ * Coercion accepts only finite numeric-looking, nonblank strings and clones only the changed path;
340
+ * malformed paths/arguments remain untouched for the handler's validation rather than inventing data.
341
+ *
342
+ * The adapter's captured end-event reason takes precedence over the final response's raw stop code:
343
+ * a raw tool_use can mean the loop hit its cap while the model still wanted tools. Raw stop/finish
344
+ * fields are fallbacks only when no end event was observed; callers must explain the loop's actual
345
+ * stop. Anthropic alone requires a max-token default when omitted, so the shared mapping supplies it.
346
+ * Provider-internal fabricated-role-marker diagnostics are filtered because the client has no event case.
281
347
  */
282
348
  export async function runProviderToolTurn(required, optional = {}) {
283
349
  const input = { ...optional, ...required };
@@ -80,80 +80,80 @@ function usageEvent(obj) {
80
80
  isError: Boolean(obj.is_error),
81
81
  };
82
82
  }
83
+ function emitThinking({ thinking, state, onEvent }) {
84
+ if (!state.emittedThinkingStart) {
85
+ state.emittedThinkingStart = true;
86
+ onEvent({ type: 'thinking_start' });
87
+ }
88
+ onEvent({ type: 'thinking_delta', delta: thinking });
89
+ }
90
+ /** Emit one content block's text or thinking; returns whether text was emitted. */
91
+ function emitContentBlock({ block, state, onEvent }) {
92
+ const text = textFromContentBlock(block);
93
+ if (text.length > 0) {
94
+ onEvent({ type: 'text_delta', delta: text });
95
+ return true;
96
+ }
97
+ const thinking = thinkingFromContentBlock(block);
98
+ if (thinking.length > 0)
99
+ emitThinking({ thinking, state, onEvent });
100
+ return false;
101
+ }
102
+ function translateAssistant({ obj, message, rawLine, state, onEvent }) {
103
+ const content = Array.isArray(message.content) ? message.content : [];
104
+ let emittedText = false;
105
+ for (const block of content) {
106
+ if (emitContentBlock({ block, state, onEvent }))
107
+ emittedText = true;
108
+ }
109
+ if (!emittedText && typeof message.content === 'string') {
110
+ onEvent({ type: 'text_delta', delta: message.content });
111
+ emittedText = true;
112
+ }
113
+ if (obj.error && !emittedText) {
114
+ onEvent({
115
+ type: 'error',
116
+ message: messageFromError(obj.error),
117
+ raw: rawLine,
118
+ });
119
+ }
120
+ }
121
+ function translateResult({ obj, rawLine, onEvent }) {
122
+ onEvent(usageEvent(obj));
123
+ if (obj.is_error) {
124
+ onEvent({
125
+ type: 'error',
126
+ message: messageFromResult(obj),
127
+ raw: rawLine,
128
+ });
129
+ }
130
+ }
131
+ function translateObject({ obj, rawLine, state, onEvent }) {
132
+ if (!isRecord(obj))
133
+ return;
134
+ if (obj.type === 'system' && obj.subtype === 'init') {
135
+ onEvent(initStatusEvent(obj));
136
+ }
137
+ else if (obj.type === 'assistant' && isRecord(obj.message)) {
138
+ translateAssistant({ obj, message: obj.message, rawLine, state, onEvent });
139
+ }
140
+ else if (obj.type === 'result') {
141
+ translateResult({ obj, rawLine, onEvent });
142
+ }
143
+ else {
144
+ onEvent({ type: 'raw', line: rawLine });
145
+ }
146
+ }
83
147
  export function createQoderStreamHandler({ onEvent }, _optional = {}) {
84
148
  const lines = createBoundedLineStream({
85
149
  onLine: line => { const trimmed = line.trim(); if (trimmed)
86
150
  handleLine(trimmed); },
87
151
  onOverflow: error => onEvent({ type: 'error', message: error.message, raw: '' }),
88
152
  });
89
- let emittedThinkingStart = false;
90
- function emitThinking(thinking) {
91
- if (!emittedThinkingStart) {
92
- emittedThinkingStart = true;
93
- onEvent({ type: 'thinking_start' });
94
- }
95
- onEvent({ type: 'thinking_delta', delta: thinking });
96
- }
97
- /** Emit one content block's text or thinking; returns whether text was emitted. */
98
- function emitContentBlock(block) {
99
- const text = textFromContentBlock(block);
100
- if (text.length > 0) {
101
- onEvent({ type: 'text_delta', delta: text });
102
- return true;
103
- }
104
- const thinking = thinkingFromContentBlock(block);
105
- if (thinking.length > 0)
106
- emitThinking(thinking);
107
- return false;
108
- }
109
- function handleAssistant(obj, message, rawLine) {
110
- const content = Array.isArray(message.content) ? message.content : [];
111
- let emittedText = false;
112
- for (const block of content) {
113
- if (emitContentBlock(block))
114
- emittedText = true;
115
- }
116
- if (!emittedText && typeof message.content === 'string') {
117
- onEvent({ type: 'text_delta', delta: message.content });
118
- emittedText = true;
119
- }
120
- if (obj.error && !emittedText) {
121
- onEvent({
122
- type: 'error',
123
- message: messageFromError(obj.error),
124
- raw: rawLine,
125
- });
126
- }
127
- }
128
- function handleResult(obj, rawLine) {
129
- onEvent(usageEvent(obj));
130
- if (obj.is_error) {
131
- onEvent({
132
- type: 'error',
133
- message: messageFromResult(obj),
134
- raw: rawLine,
135
- });
136
- }
137
- }
138
- function handleObject(obj, rawLine) {
139
- if (!isRecord(obj))
140
- return;
141
- if (obj.type === 'system' && obj.subtype === 'init') {
142
- onEvent(initStatusEvent(obj));
143
- }
144
- else if (obj.type === 'assistant' && isRecord(obj.message)) {
145
- handleAssistant(obj, obj.message, rawLine);
146
- }
147
- else if (obj.type === 'result') {
148
- handleResult(obj, rawLine);
149
- }
150
- else {
151
- onEvent({ type: 'raw', line: rawLine });
152
- }
153
- }
153
+ const state = { emittedThinkingStart: false };
154
154
  function handleLine(line) {
155
155
  try {
156
- handleObject(JSON.parse(line), line);
156
+ translateObject({ obj: JSON.parse(line), rawLine: line, state, onEvent });
157
157
  }
158
158
  catch {
159
159
  onEvent({ type: 'raw', line });
@@ -126,6 +126,47 @@ const NEWLINE_ANCHORED_PENDING_MARKER_TAIL_RE = /\n[ \t]*##[ \t]+(?:user|assista
126
126
  // 1000 chunks of 50 bytes is otherwise O(n²) on string concatenation
127
127
  // alone.
128
128
  const TAIL_BUFFER_SIZE = 64;
129
+ /** Picks the confirmed-marker and pending-marker matchers for the current stream position. */
130
+ function markerRegexes({ firstChunk }) {
131
+ const matchRe = firstChunk
132
+ ? FABRICATED_ROLE_MARKER_RE
133
+ : NEWLINE_ANCHORED_ROLE_MARKER_RE;
134
+ const pendingRe = firstChunk
135
+ ? FIRST_CHUNK_PENDING_MARKER_TAIL_RE
136
+ : NEWLINE_ANCHORED_PENDING_MARKER_TAIL_RE;
137
+ return { matchRe, pendingRe };
138
+ }
139
+ /** Bytes between what was already emitted and a just-confirmed marker; `''` when the marker starts inside the emitted tail. */
140
+ function textBeforeMarker({ buffer, alreadyEmitted, markerStart }) {
141
+ if (markerStart <= alreadyEmitted)
142
+ return '';
143
+ return buffer.slice(alreadyEmitted, markerStart);
144
+ }
145
+ /** Splits the not-yet-emitted part of `buffer` into the safe prefix and a withheld complete-but-unconfirmed marker suffix. */
146
+ function withholdPendingMarker({ buffer, pendingRe, alreadyEmitted }) {
147
+ const pendingMatch = pendingRe.exec(buffer);
148
+ const pendingStart = pendingMatch
149
+ // Never withhold bytes we have already emitted in a prior
150
+ // feed — the suspicious suffix could in pathological cases
151
+ // start inside `tail` (we held back `pending` correctly on
152
+ // the prior call, but the suffix-start position is upstream
153
+ // of where we hold). Clamp to alreadyEmitted so safeToEmit
154
+ // never goes negative.
155
+ ? Math.max(pendingMatch.index, alreadyEmitted)
156
+ : buffer.length;
157
+ return { safeToEmit: buffer.slice(alreadyEmitted, pendingStart), pending: buffer.slice(pendingStart) };
158
+ }
159
+ /** Appends the newly emitted bytes to `tail`, capped at TAIL_BUFFER_SIZE; reports whether the cap sliced it. */
160
+ function rollEmittedTail({ tail, safeToEmit }) {
161
+ const fullEmitted = tail + safeToEmit;
162
+ const willSlice = fullEmitted.length > TAIL_BUFFER_SIZE;
163
+ return {
164
+ tail: willSlice
165
+ ? fullEmitted.slice(fullEmitted.length - TAIL_BUFFER_SIZE)
166
+ : fullEmitted,
167
+ willSlice,
168
+ };
169
+ }
129
170
  /**
130
171
  * Create a stateful guard that detects fabricated role markers across
131
172
  * chunk boundaries. Memory + per-call work is O(1): instead of
@@ -190,12 +231,7 @@ export function createRoleMarkerGuard({ messageId }, _optional = {}) {
190
231
  // `pending` (deferred-from-prior-call suspicious suffix), and the
191
232
  // new `text` into a single matching buffer.
192
233
  const buffer = tail + pending + text;
193
- const matchRe = firstChunk
194
- ? FABRICATED_ROLE_MARKER_RE
195
- : NEWLINE_ANCHORED_ROLE_MARKER_RE;
196
- const pendingRe = firstChunk
197
- ? FIRST_CHUNK_PENDING_MARKER_TAIL_RE
198
- : NEWLINE_ANCHORED_PENDING_MARKER_TAIL_RE;
234
+ const { matchRe, pendingRe } = markerRegexes({ firstChunk });
199
235
  // `firstChunk` transitions are tied to actual byte emission, not
200
236
  // feed count — see comment above. Transitioned at the end of
201
237
  // this function only when we emit at least one byte.
@@ -209,35 +245,18 @@ export function createRoleMarkerGuard({ messageId }, _optional = {}) {
209
245
  _contaminated = true;
210
246
  markerText = match[0].trim();
211
247
  pending = '';
212
- const alreadyEmitted = tail.length;
213
- const markerStart = match.index;
214
- if (markerStart <= alreadyEmitted)
215
- return '';
216
- return buffer.slice(alreadyEmitted, markerStart);
248
+ return textBeforeMarker({ buffer, alreadyEmitted: tail.length, markerStart: match.index });
217
249
  }
218
250
  // No confirmed marker. Check whether the buffer ends with a
219
251
  // complete-but-unconfirmed marker prefix (role keyword present,
220
252
  // lookahead char not yet arrived). If so, withhold that suffix
221
253
  // until the next feed; emit the rest.
222
- const pendingMatch = pendingRe.exec(buffer);
223
- const alreadyEmitted = tail.length;
224
- const pendingStart = pendingMatch
225
- // Never withhold bytes we have already emitted in a prior
226
- // feed — the suspicious suffix could in pathological cases
227
- // start inside `tail` (we held back `pending` correctly on
228
- // the prior call, but the suffix-start position is upstream
229
- // of where we hold). Clamp to alreadyEmitted so safeToEmit
230
- // never goes negative.
231
- ? Math.max(pendingMatch.index, alreadyEmitted)
232
- : buffer.length;
233
- const safeToEmit = buffer.slice(alreadyEmitted, pendingStart);
234
- pending = buffer.slice(pendingStart);
254
+ const held = withholdPendingMarker({ buffer, pendingRe, alreadyEmitted: tail.length });
255
+ const safeToEmit = held.safeToEmit;
256
+ pending = held.pending;
235
257
  // Roll the emitted-bytes tail forward.
236
- const fullEmitted = tail + safeToEmit;
237
- const willSlice = fullEmitted.length > TAIL_BUFFER_SIZE;
238
- tail = willSlice
239
- ? fullEmitted.slice(fullEmitted.length - TAIL_BUFFER_SIZE)
240
- : fullEmitted;
258
+ const rolled = rollEmittedTail({ tail, safeToEmit });
259
+ tail = rolled.tail;
241
260
  // `firstChunk` is true exactly while `tail` still represents the
242
261
  // entire emission so far — i.e. no slice has occurred and `^` in
243
262
  // the canonical regex genuinely anchors at byte 0 of the stream.
@@ -257,7 +276,7 @@ export function createRoleMarkerGuard({ messageId }, _optional = {}) {
257
276
  // review r3324060995.
258
277
  // Slice-based is the invariant that satisfies both: while we
259
278
  // haven't sliced, `^` is correct; once we slice, it isn't.
260
- if (willSlice)
279
+ if (rolled.willSlice)
261
280
  firstChunk = false;
262
281
  return safeToEmit;
263
282
  },
@@ -1,4 +1,4 @@
1
- import { buildCodexArgs, codexAgentDef } from './defs/codex.js';
1
+ import { buildCodexArgs, codexAgentDef } from './defs/codex/index.js';
2
2
  /** Bind model probes and the argument builder to the host transport, capability state and plugin policy.
3
3
  * The Codex config reaches only the Codex definition, through its own argument; nothing vendor-specific is
4
4
  * added to the neutral build options. Returns a definition copy without mutating the registry. @complexity O(1). */