@jini-ai/agent-runtime 0.3.9 → 0.4.0

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 (200) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +34 -17
  3. package/dist/acp-model-probe.d.ts +6 -4
  4. package/dist/acp-model-probe.js +3 -3
  5. package/dist/agent-protocol/acp/account-failure.d.ts +4 -2
  6. package/dist/agent-protocol/acp/account-failure.js +1 -1
  7. package/dist/agent-protocol/acp/json.d.ts +6 -6
  8. package/dist/agent-protocol/acp/json.js +3 -3
  9. package/dist/agent-protocol/acp/models.d.ts +10 -5
  10. package/dist/agent-protocol/acp/models.js +32 -31
  11. package/dist/agent-protocol/acp/session-params.d.ts +3 -1
  12. package/dist/agent-protocol/acp/session-params.js +2 -1
  13. package/dist/agent-protocol/acp/session.d.ts +28 -22
  14. package/dist/agent-protocol/acp/session.js +181 -147
  15. package/dist/agent-protocol/acp/text-suppression.d.ts +1 -1
  16. package/dist/agent-protocol/acp/text-suppression.js +1 -1
  17. package/dist/agent-protocol/acp/types.d.ts +3 -2
  18. package/dist/agent-protocol/acp/updates.d.ts +11 -11
  19. package/dist/agent-protocol/acp/updates.js +2 -2
  20. package/dist/agent-protocol/core/json-line-stream.d.ts +24 -8
  21. package/dist/agent-protocol/core/json-line-stream.js +8 -8
  22. package/dist/agent-protocol/pi-rpc/events.d.ts +5 -1
  23. package/dist/agent-protocol/pi-rpc/events.js +36 -36
  24. package/dist/agent-protocol/pi-rpc/internal.d.ts +4 -1
  25. package/dist/agent-protocol/pi-rpc/models.d.ts +3 -1
  26. package/dist/agent-protocol/pi-rpc/models.js +1 -1
  27. package/dist/agent-protocol/pi-rpc/session.d.ts +1 -1
  28. package/dist/agent-protocol/pi-rpc/session.js +33 -32
  29. package/dist/amr-model-cache.d.ts +12 -4
  30. package/dist/amr-model-cache.js +17 -21
  31. package/dist/amr-profile-resolver.d.ts +3 -1
  32. package/dist/anthropic-live-models.js +0 -0
  33. package/dist/artifact-taxonomy.d.ts +6 -2
  34. package/dist/auth.d.ts +52 -15
  35. package/dist/auth.js +36 -36
  36. package/dist/claude-code-models.js +2 -2
  37. package/dist/claude-stream.d.ts +22 -3
  38. package/dist/claude-stream.js +24 -8
  39. package/dist/copilot-stream.d.ts +7 -3
  40. package/dist/copilot-stream.js +3 -3
  41. package/dist/defs/aider.d.ts +8 -1
  42. package/dist/defs/aider.js +2 -2
  43. package/dist/defs/amp.d.ts +8 -1
  44. package/dist/defs/amp.js +2 -2
  45. package/dist/defs/amr.d.ts +22 -6
  46. package/dist/defs/amr.js +23 -23
  47. package/dist/defs/antigravity.d.ts +15 -4
  48. package/dist/defs/antigravity.js +9 -8
  49. package/dist/defs/auggie.d.ts +4 -1
  50. package/dist/defs/auggie.js +1 -1
  51. package/dist/defs/claude.d.ts +16 -2
  52. package/dist/defs/claude.js +22 -4
  53. package/dist/defs/cline.d.ts +4 -1
  54. package/dist/defs/cline.js +1 -1
  55. package/dist/defs/codebuddy.d.ts +8 -1
  56. package/dist/defs/codebuddy.js +2 -2
  57. package/dist/defs/codex.d.ts +18 -4
  58. package/dist/defs/codex.js +7 -7
  59. package/dist/defs/copilot.d.ts +8 -1
  60. package/dist/defs/copilot.js +2 -2
  61. package/dist/defs/crush.d.ts +8 -1
  62. package/dist/defs/crush.js +1 -1
  63. package/dist/defs/cursor-agent.d.ts +14 -3
  64. package/dist/defs/cursor-agent.js +5 -5
  65. package/dist/defs/deepseek.d.ts +8 -1
  66. package/dist/defs/deepseek.js +2 -2
  67. package/dist/defs/devin.d.ts +12 -2
  68. package/dist/defs/devin.js +3 -3
  69. package/dist/defs/droid.d.ts +8 -1
  70. package/dist/defs/droid.js +1 -1
  71. package/dist/defs/gemini.d.ts +8 -1
  72. package/dist/defs/gemini.js +1 -1
  73. package/dist/defs/goose.d.ts +4 -1
  74. package/dist/defs/goose.js +1 -1
  75. package/dist/defs/grok-build.d.ts +11 -2
  76. package/dist/defs/grok-build.js +3 -3
  77. package/dist/defs/hermes.d.ts +4 -1
  78. package/dist/defs/hermes.js +2 -2
  79. package/dist/defs/kilo.d.ts +4 -1
  80. package/dist/defs/kilo.js +2 -2
  81. package/dist/defs/kimi.d.ts +4 -1
  82. package/dist/defs/kimi.js +2 -2
  83. package/dist/defs/kiro.d.ts +4 -1
  84. package/dist/defs/kiro.js +2 -2
  85. package/dist/defs/mimo.d.ts +8 -1
  86. package/dist/defs/mimo.js +2 -2
  87. package/dist/defs/opencode.d.ts +9 -2
  88. package/dist/defs/opencode.js +2 -2
  89. package/dist/defs/pi.d.ts +12 -2
  90. package/dist/defs/pi.js +9 -9
  91. package/dist/defs/qoder.d.ts +8 -1
  92. package/dist/defs/qoder.js +2 -2
  93. package/dist/defs/qwen.d.ts +8 -1
  94. package/dist/defs/qwen.js +2 -2
  95. package/dist/defs/reasonix.d.ts +4 -1
  96. package/dist/defs/reasonix.js +3 -3
  97. package/dist/defs/shared.d.ts +4 -2
  98. package/dist/defs/shared.js +2 -2
  99. package/dist/defs/trae-cli.d.ts +12 -2
  100. package/dist/defs/trae-cli.js +3 -3
  101. package/dist/defs/vibe.d.ts +4 -1
  102. package/dist/defs/vibe.js +2 -2
  103. package/dist/detection.d.ts +38 -3
  104. package/dist/detection.js +77 -37
  105. package/dist/diagnostics.d.ts +14 -3
  106. package/dist/diagnostics.js +5 -5
  107. package/dist/env.d.ts +16 -4
  108. package/dist/env.js +7 -7
  109. package/dist/executables.d.ts +24 -8
  110. package/dist/executables.js +13 -13
  111. package/dist/index.d.ts +228 -4
  112. package/dist/index.js +230 -6
  113. package/dist/invocation.d.ts +6 -1
  114. package/dist/invocation.js +2 -2
  115. package/dist/json-event-stream.d.ts +7 -2
  116. package/dist/json-event-stream.js +3 -3
  117. package/dist/launch.d.ts +12 -2
  118. package/dist/launch.js +3 -3
  119. package/dist/log-file.d.ts +4 -1
  120. package/dist/log-file.js +2 -2
  121. package/dist/mcp.d.ts +6 -3
  122. package/dist/mcp.js +1 -1
  123. package/dist/metadata.d.ts +7 -3
  124. package/dist/metadata.js +1 -1
  125. package/dist/mmd-routes.d.ts +22 -6
  126. package/dist/mmd-routes.js +14 -14
  127. package/dist/model-catalog-cache.d.ts +50 -0
  128. package/dist/model-catalog-cache.js +61 -0
  129. package/dist/model-loading-state.d.ts +10 -0
  130. package/dist/model-loading-state.js +23 -0
  131. package/dist/model-registry.d.ts +28 -7
  132. package/dist/model-registry.js +11 -8
  133. package/dist/models.d.ts +31 -6
  134. package/dist/models.js +6 -6
  135. package/dist/opencode-log.d.ts +12 -4
  136. package/dist/opencode-log.js +8 -8
  137. package/dist/paths.d.ts +6 -2
  138. package/dist/paths.js +3 -3
  139. package/dist/pi-models.d.ts +3 -1
  140. package/dist/pi-models.js +2 -2
  141. package/dist/prompt-budget.d.ts +17 -4
  142. package/dist/prompt-budget.js +3 -3
  143. package/dist/prompt-file.d.ts +5 -1
  144. package/dist/prompt-file.js +1 -1
  145. package/dist/providers/aihubmix.d.ts +34 -9
  146. package/dist/providers/aihubmix.js +26 -26
  147. package/dist/providers/anthropic-messages.d.ts +77 -20
  148. package/dist/providers/anthropic-messages.js +53 -50
  149. package/dist/providers/azure-chat.d.ts +21 -7
  150. package/dist/providers/azure-chat.js +18 -16
  151. package/dist/providers/connection-guard.d.ts +45 -31
  152. package/dist/providers/connection-guard.js +40 -143
  153. package/dist/providers/connection-test.d.ts +1 -1
  154. package/dist/providers/connection-test.js +13 -30
  155. package/dist/providers/elevenlabs.d.ts +7 -2
  156. package/dist/providers/elevenlabs.js +4 -4
  157. package/dist/providers/google-messages.d.ts +44 -10
  158. package/dist/providers/google-messages.js +36 -34
  159. package/dist/providers/google-schema.d.ts +26 -0
  160. package/dist/providers/google-schema.js +253 -0
  161. package/dist/providers/google.d.ts +21 -6
  162. package/dist/providers/google.js +10 -10
  163. package/dist/providers/index.d.ts +3 -2
  164. package/dist/providers/index.js +3 -2
  165. package/dist/providers/model-catalog.d.ts +1 -1
  166. package/dist/providers/model-catalog.js +14 -27
  167. package/dist/providers/oauth-callback-server.d.ts +1 -1
  168. package/dist/providers/oauth-callback-server.js +3 -2
  169. package/dist/providers/oauth-credentials.d.ts +7 -1
  170. package/dist/providers/oauth-credentials.js +5 -5
  171. package/dist/providers/oauth-provider.d.ts +2 -2
  172. package/dist/providers/oauth-provider.js +20 -25
  173. package/dist/providers/oauth-tokens.d.ts +26 -6
  174. package/dist/providers/oauth-tokens.js +9 -9
  175. package/dist/providers/ollama-chat.d.ts +66 -31
  176. package/dist/providers/ollama-chat.js +64 -61
  177. package/dist/providers/openai-chat.d.ts +77 -22
  178. package/dist/providers/openai-chat.js +71 -67
  179. package/dist/providers/pkce.d.ts +33 -20
  180. package/dist/providers/pkce.js +75 -146
  181. package/dist/providers/sse-decode.d.ts +3 -1
  182. package/dist/providers/sse-decode.js +1 -1
  183. package/dist/providers/token-params.d.ts +16 -5
  184. package/dist/providers/token-params.js +6 -6
  185. package/dist/providers/tool-turn-types.d.ts +89 -0
  186. package/dist/providers/tool-turn-types.js +2 -0
  187. package/dist/providers/tool-turn.d.ts +10 -0
  188. package/dist/providers/tool-turn.js +252 -0
  189. package/dist/qoder-stream.d.ts +7 -3
  190. package/dist/qoder-stream.js +3 -3
  191. package/dist/registry.d.ts +6 -2
  192. package/dist/registry.js +4 -4
  193. package/dist/resolution.d.ts +5 -1
  194. package/dist/resolution.js +3 -3
  195. package/dist/role-marker-guard.d.ts +9 -5
  196. package/dist/role-marker-guard.js +5 -5
  197. package/dist/terminal-launch.d.ts +6 -1
  198. package/dist/terminal-launch.js +2 -2
  199. package/dist/types.d.ts +37 -6
  200. package/package.json +43 -4
package/dist/models.js CHANGED
@@ -13,7 +13,7 @@ function liveModelCacheKey(agentId, scope) {
13
13
  const trimmedScope = typeof scope === 'string' ? scope.trim() : '';
14
14
  return trimmedScope ? `${agentId}\0${trimmedScope}` : agentId;
15
15
  }
16
- export function rememberLiveModels(agentId, models, scope) {
16
+ export function rememberLiveModels({ agentId, models }, { scope } = {}) {
17
17
  if (!Array.isArray(models))
18
18
  return;
19
19
  const ids = models
@@ -23,14 +23,14 @@ export function rememberLiveModels(agentId, models, scope) {
23
23
  liveModelCache.set(key, new Set(ids));
24
24
  liveModelOrder.set(key, ids);
25
25
  }
26
- export function getRememberedLiveModels(agentId, scope) {
26
+ export function getRememberedLiveModels({ agentId }, { scope } = {}) {
27
27
  const ids = liveModelOrder.get(liveModelCacheKey(agentId, scope)) ?? [];
28
28
  return ids.map((id) => ({ id, label: id }));
29
29
  }
30
- export function preferFreshLiveModels(freshModels, rememberedModels) {
30
+ export function preferFreshLiveModels({ freshModels, rememberedModels }) {
31
31
  return freshModels.length > 0 ? freshModels : rememberedModels;
32
32
  }
33
- export function isKnownModel(def, modelId, scope) {
33
+ export function isKnownModel({ def, modelId }, { scope } = {}) {
34
34
  if (!modelId)
35
35
  return false;
36
36
  const live = liveModelCache.get(liveModelCacheKey(def.id, scope));
@@ -49,7 +49,7 @@ export function isKnownModel(def, modelId, scope) {
49
49
  // surfaced to the UI, then fall back to the def's first concrete fallback
50
50
  // id so the spawn layer always has a real model to forward. Defs that DO
51
51
  // list 'default' (the common case) are left untouched.
52
- export function resolveModelForAgent(def, resolved, env = process.env, liveModelScope) {
52
+ export function resolveModelForAgent({ def, resolved }, { env = process.env, liveModelScope } = {}) {
53
53
  if (resolved && resolved !== 'default')
54
54
  return resolved;
55
55
  // Host-process env override. Lets an operator pin a different fallback
@@ -80,7 +80,7 @@ export function resolveModelForAgent(def, resolved, env = process.env, liveModel
80
80
  // as a child-process arg — not a shell string — so injection isn't a
81
81
  // concern, but we still reject anything that could be misread as a flag
82
82
  // by a downstream CLI or that contains whitespace / control chars.
83
- export function sanitizeCustomModel(id) {
83
+ export function sanitizeCustomModel({ id }) {
84
84
  if (typeof id !== 'string')
85
85
  return null;
86
86
  const trimmed = id.trim();
@@ -4,13 +4,21 @@ export interface OpenCodeServiceFailure {
4
4
  message: string;
5
5
  statusCode: number | null;
6
6
  }
7
- export declare function resolveOpenCodeLogDir(env: Record<string, string | undefined>): string | null;
8
- export declare function readLatestOpenCodeLogTail(logDir: string, options?: {
7
+ export declare function resolveOpenCodeLogDir({ env }: {
8
+ env: Record<string, string | undefined>;
9
+ }): string | null;
10
+ export declare function readLatestOpenCodeLogTail({ logDir }: {
11
+ logDir: string;
12
+ }, options?: {
9
13
  maxBytes?: number;
10
14
  since?: number;
11
15
  }): string | null;
12
- export declare function extractOpenCodeServiceFailure(logTail: string): OpenCodeServiceFailure | null;
13
- export declare function readOpenCodeServiceFailure(env: Record<string, string | undefined>, options?: {
16
+ export declare function extractOpenCodeServiceFailure({ logTail }: {
17
+ logTail: string;
18
+ }): OpenCodeServiceFailure | null;
19
+ export declare function readOpenCodeServiceFailure({ env }: {
20
+ env: Record<string, string | undefined>;
21
+ }, options?: {
14
22
  since?: number;
15
23
  }): OpenCodeServiceFailure | null;
16
24
  //# sourceMappingURL=opencode-log.d.ts.map
@@ -19,7 +19,7 @@ import { classifyAgentServiceFailure } from './auth.js';
19
19
  // `$HOME/.local/share/opencode`, with session logs under `log/`. Mirror that
20
20
  // so we read the same files the spawned CLI wrote. Null when neither var is
21
21
  // set (we have no basis to guess a path).
22
- export function resolveOpenCodeLogDir(env) {
22
+ export function resolveOpenCodeLogDir({ env }) {
23
23
  const xdg = typeof env.XDG_DATA_HOME === 'string' ? env.XDG_DATA_HOME.trim() : '';
24
24
  const home = typeof env.HOME === 'string' ? env.HOME.trim() : '';
25
25
  const base = xdg || (home ? path.join(home, '.local', 'share') : '');
@@ -38,7 +38,7 @@ export function resolveOpenCodeLogDir(env) {
38
38
  // callers are a (non-async) run-close handler and an inactivity watchdog,
39
39
  // once per failed OpenCode run. Returns null on any fs error (no dir yet,
40
40
  // perms).
41
- export function readLatestOpenCodeLogTail(logDir, options = {}) {
41
+ export function readLatestOpenCodeLogTail({ logDir }, options = {}) {
42
42
  const { maxBytes = 2_000_000, since } = options;
43
43
  let names;
44
44
  try {
@@ -124,7 +124,7 @@ function defaultMessageForCode(code) {
124
124
  // We scope to that single line so the huge request body of *other* lines
125
125
  // can't leak in, key the classification on the unambiguous HTTP `statusCode`
126
126
  // first, and fall back to keyword matching the extracted message only.
127
- export function extractOpenCodeServiceFailure(logTail) {
127
+ export function extractOpenCodeServiceFailure({ logTail }) {
128
128
  if (!logTail || !logTail.trim())
129
129
  return null;
130
130
  const lines = logTail.split(/\r?\n/);
@@ -143,7 +143,7 @@ export function extractOpenCodeServiceFailure(logTail) {
143
143
  const message = pickServiceErrorMessage(line);
144
144
  let code = statusCode != null ? codeFromStatus(statusCode) : null;
145
145
  if (!code && message)
146
- code = classifyAgentServiceFailure(message);
146
+ code = classifyAgentServiceFailure({ text: message });
147
147
  if (!code)
148
148
  return null;
149
149
  return { code, message: message || defaultMessageForCode(code), statusCode };
@@ -151,13 +151,13 @@ export function extractOpenCodeServiceFailure(logTail) {
151
151
  // Convenience for a run-close handler / inactivity watchdog: resolve the
152
152
  // log dir from the spawned agent's env, read the newest log tail (bound to
153
153
  // the current run via `since`), and classify it.
154
- export function readOpenCodeServiceFailure(env, options = {}) {
155
- const logDir = resolveOpenCodeLogDir(env);
154
+ export function readOpenCodeServiceFailure({ env }, options = {}) {
155
+ const logDir = resolveOpenCodeLogDir({ env: env });
156
156
  if (!logDir)
157
157
  return null;
158
- const tail = readLatestOpenCodeLogTail(logDir, options);
158
+ const tail = readLatestOpenCodeLogTail({ logDir: logDir }, options);
159
159
  if (!tail)
160
160
  return null;
161
- return extractOpenCodeServiceFailure(tail);
161
+ return extractOpenCodeServiceFailure({ logTail: tail });
162
162
  }
163
163
  //# sourceMappingURL=opencode-log.js.map
package/dist/paths.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- export declare function expandConfiguredEnv(configuredEnv: unknown): Record<string, string>;
2
- export declare function expandHomePath(value: string): string;
1
+ export declare function expandConfiguredEnv({ configuredEnv }: {
2
+ configuredEnv: unknown;
3
+ }): Record<string, string>;
4
+ export declare function expandHomePath({ value }: {
5
+ value: string;
6
+ }): string;
3
7
  //# sourceMappingURL=paths.d.ts.map
package/dist/paths.js CHANGED
@@ -7,18 +7,18 @@
7
7
  */
8
8
  import path from 'node:path';
9
9
  import { homedir } from 'node:os';
10
- export function expandConfiguredEnv(configuredEnv) {
10
+ export function expandConfiguredEnv({ configuredEnv }) {
11
11
  const out = {};
12
12
  if (!configuredEnv || typeof configuredEnv !== 'object')
13
13
  return out;
14
14
  for (const [key, value] of Object.entries(configuredEnv)) {
15
15
  if (typeof value !== 'string')
16
16
  continue;
17
- out[key] = expandHomePath(value);
17
+ out[key] = expandHomePath({ value: value });
18
18
  }
19
19
  return out;
20
20
  }
21
- export function expandHomePath(value) {
21
+ export function expandHomePath({ value }) {
22
22
  if (value === '~')
23
23
  return homedir();
24
24
  if (value.startsWith('~/') || value.startsWith('~\\')) {
@@ -9,5 +9,7 @@
9
9
  * dependency on it.
10
10
  */
11
11
  import type { RuntimeModelOption } from './types.js';
12
- export declare function parsePiModels(stdout: unknown): RuntimeModelOption[] | null;
12
+ export declare function parsePiModels({ stdout }: {
13
+ stdout: unknown;
14
+ }): RuntimeModelOption[] | null;
13
15
  //# sourceMappingURL=pi-models.d.ts.map
package/dist/pi-models.js CHANGED
@@ -1,4 +1,4 @@
1
- export function parsePiModels(stdout) {
1
+ export function parsePiModels({ stdout }) {
2
2
  const lines = String(stdout || '')
3
3
  .split('\n')
4
4
  .map((l) => l.trim())
@@ -14,7 +14,7 @@ export function parsePiModels(stdout) {
14
14
  // defined; the non-null assertion documents that runtime invariant
15
15
  // instead of a `noUncheckedIndexedAccess`-driven guard that could never
16
16
  // actually trigger (same treatment as this function's other port,
17
- // `agent-protocol/pi-rpc/models.ts` — see source-map.md's "Barrel
17
+ // `agent-protocol/pi-rpc/models.ts` — see archived provenance ledger's "Barrel
18
18
  // merge" section for why two copies of this function exist).
19
19
  const line = lines[i];
20
20
  const parts = line.split(/\s+/);
@@ -11,10 +11,23 @@
11
11
  * "Reduce the selected skills/design-system context…" (OD's own content
12
12
  * catalog). Replaced with the generic "selected context" phrasing so the
13
13
  * message doesn't assume a design-system-shaped host. Mechanics (byte
14
- * budgets, Windows quote-doubling math) are unchanged. See `source-map.md`.
14
+ * budgets, Windows quote-doubling math) are unchanged. See `archived provenance ledger`.
15
15
  */
16
16
  import type { RuntimeAgentDef, RuntimePromptBudgetError } from './types.js';
17
- export declare function checkPromptArgvBudget(def: RuntimeAgentDef | null | undefined, composed: unknown, platform?: NodeJS.Platform): RuntimePromptBudgetError | null;
18
- export declare function checkWindowsCmdShimCommandLineBudget(def: RuntimeAgentDef | null | undefined, resolvedBin: unknown, args: unknown): RuntimePromptBudgetError | null;
19
- export declare function checkWindowsDirectExeCommandLineBudget(def: RuntimeAgentDef | null | undefined, resolvedBin: unknown, args: unknown): RuntimePromptBudgetError | null;
17
+ export declare function checkPromptArgvBudget({ def, composed }: {
18
+ def: RuntimeAgentDef | null | undefined;
19
+ composed: unknown;
20
+ }, { platform }?: {
21
+ platform?: NodeJS.Platform;
22
+ }): RuntimePromptBudgetError | null;
23
+ export declare function checkWindowsCmdShimCommandLineBudget({ def, resolvedBin, args }: {
24
+ def: RuntimeAgentDef | null | undefined;
25
+ resolvedBin: unknown;
26
+ args: unknown;
27
+ }): RuntimePromptBudgetError | null;
28
+ export declare function checkWindowsDirectExeCommandLineBudget({ def, resolvedBin, args }: {
29
+ def: RuntimeAgentDef | null | undefined;
30
+ resolvedBin: unknown;
31
+ args: unknown;
32
+ }): RuntimePromptBudgetError | null;
20
33
  //# sourceMappingURL=prompt-budget.d.ts.map
@@ -23,7 +23,7 @@ function resolveArgvPromptBudget(maxPromptArgBytes, platform) {
23
23
  return maxPromptArgBytes;
24
24
  return Math.max(maxPromptArgBytes, POSIX_ARGV_PROMPT_BUDGET);
25
25
  }
26
- export function checkPromptArgvBudget(def, composed, platform = process.platform) {
26
+ export function checkPromptArgvBudget({ def, composed }, { platform = process.platform } = {}) {
27
27
  if (!def || typeof def.maxPromptArgBytes !== 'number')
28
28
  return null;
29
29
  const bytes = Buffer.byteLength(typeof composed === 'string' ? composed : '', 'utf8');
@@ -124,7 +124,7 @@ const WINDOWS_CREATE_PROCESS_HEADROOM = 256;
124
124
  // Pure: takes `resolvedBin` explicitly so a test on macOS can pass a fake
125
125
  // `C:\\…\\deepseek.cmd` path and exercise the same math the daemon would
126
126
  // run on Windows.
127
- export function checkWindowsCmdShimCommandLineBudget(def, resolvedBin, args) {
127
+ export function checkWindowsCmdShimCommandLineBudget({ def, resolvedBin, args }) {
128
128
  if (!def || typeof def.maxPromptArgBytes !== 'number')
129
129
  return null;
130
130
  if (typeof resolvedBin !== 'string' || !/\.(bat|cmd)$/i.test(resolvedBin))
@@ -192,7 +192,7 @@ function looksLikeWindowsPath(p) {
192
192
  // pass a fake `C:\…\deepseek.exe` and exercise the same math the daemon
193
193
  // would run on Windows. The libuv quoting math lives in
194
194
  // `quoteForWindowsDirectExe` above.
195
- export function checkWindowsDirectExeCommandLineBudget(def, resolvedBin, args) {
195
+ export function checkWindowsDirectExeCommandLineBudget({ def, resolvedBin, args }) {
196
196
  if (!def || typeof def.maxPromptArgBytes !== 'number')
197
197
  return null;
198
198
  if (typeof resolvedBin !== 'string' || resolvedBin.length === 0)
@@ -3,5 +3,9 @@ export type PreparedPromptFile = {
3
3
  path: string;
4
4
  cleanup: () => Promise<void>;
5
5
  };
6
- export declare function preparePromptFileForAgent(def: RuntimeAgentDef | null | undefined, prompt: string, label: string): Promise<PreparedPromptFile | null>;
6
+ export declare function preparePromptFileForAgent({ def, prompt, label }: {
7
+ def: RuntimeAgentDef | null | undefined;
8
+ prompt: string;
9
+ label: string;
10
+ }): Promise<PreparedPromptFile | null>;
7
11
  //# sourceMappingURL=prompt-file.d.ts.map
@@ -10,7 +10,7 @@
10
10
  import { promises as fs } from 'node:fs';
11
11
  import os from 'node:os';
12
12
  import path from 'node:path';
13
- export async function preparePromptFileForAgent(def, prompt, label) {
13
+ export async function preparePromptFileForAgent({ def, prompt, label }) {
14
14
  if (!def?.promptViaFile)
15
15
  return null;
16
16
  const safeLabel = label.replace(/[^a-zA-Z0-9_.-]/g, '-').slice(0, 80) || 'prompt';
@@ -29,7 +29,9 @@ export declare const AIHUBMIX_DEFAULT_BASE_URL = "https://aihubmix.com/v1";
29
29
  * fixed `APP-Code` attribution header. Callers spread the result into their
30
30
  * `fetch` headers and may add `content-type` etc. on top.
31
31
  */
32
- export declare function aihubmixHeaders(apiKey: string): Record<string, string>;
32
+ export declare function aihubmixHeaders({ apiKey }: {
33
+ apiKey: string;
34
+ }): Record<string, string>;
33
35
  /**
34
36
  * The APP-Code attribution header on its own (no auth). For the Anthropic /
35
37
  * Gemini routes, which carry their own auth header (`x-api-key` /
@@ -42,7 +44,9 @@ export declare function aihubmixHeaders(apiKey: string): Record<string, string>;
42
44
  */
43
45
  export declare function aihubmixAppCodeHeader(): Record<string, string>;
44
46
  export type AIHubMixProtocol = 'openai' | 'anthropic' | 'gemini';
45
- export declare function classifyAIHubMixModel(model: string): AIHubMixProtocol;
47
+ export declare function classifyAIHubMixModel({ model }: {
48
+ model: string;
49
+ }): AIHubMixProtocol;
46
50
  /**
47
51
  * Origin of the configured AIHubMix base URL — the three protocol clients all
48
52
  * derive their endpoint from it:
@@ -50,9 +54,14 @@ export declare function classifyAIHubMixModel(model: string): AIHubMixProtocol;
50
54
  * anthropic -> `${origin}` (+ /v1/messages)
51
55
  * gemini -> `${origin}/gemini` (+ /v1beta/models/{model}:...)
52
56
  */
53
- export declare function aihubmixOriginFromBase(baseUrl: string): string;
57
+ export declare function aihubmixOriginFromBase({ baseUrl }: {
58
+ baseUrl: string;
59
+ }): string;
54
60
  /** Gemini-native generateContent endpoint for an AIHubMix image model. */
55
- export declare function aihubmixGeminiImageUrl(baseUrl: string, wireModel: string): string;
61
+ export declare function aihubmixGeminiImageUrl({ baseUrl, wireModel }: {
62
+ baseUrl: string;
63
+ wireModel: string;
64
+ }): string;
56
65
  export interface AIHubMixGeminiImageRequest {
57
66
  baseUrl: string;
58
67
  apiKey: string;
@@ -73,11 +82,25 @@ export interface AIHubMixGeminiImageRequest {
73
82
  * dispatcher, abort signal, redirect policy). Throws on a non-OK status or a
74
83
  * response without inline image data.
75
84
  */
76
- export declare function aihubmixGeminiImageBytes(req: AIHubMixGeminiImageRequest, doFetch: (url: string, init: RequestInit) => Promise<Response>): Promise<Buffer>;
77
- export declare function aihubmixWireModel(catalogId: string): string;
78
- export declare function aihubmixVideoSeconds(wireModel: string, requested: number): string;
85
+ export declare function aihubmixGeminiImageBytes({ req, doFetch }: {
86
+ req: AIHubMixGeminiImageRequest;
87
+ doFetch: (requiredArgs: {
88
+ url: string;
89
+ init: RequestInit;
90
+ }) => Promise<Response>;
91
+ }): Promise<Buffer>;
92
+ export declare function aihubmixWireModel({ catalogId }: {
93
+ catalogId: string;
94
+ }): string;
95
+ export declare function aihubmixVideoSeconds({ wireModel, requested }: {
96
+ wireModel: string;
97
+ requested: number;
98
+ }): string;
79
99
  export type AIHubMixCatalogType = 'llm' | 'image_generation' | 'tts' | 'video';
80
- export declare function aihubmixCatalogUrl(baseUrl: string, type: AIHubMixCatalogType): string;
100
+ export declare function aihubmixCatalogUrl({ baseUrl, type }: {
101
+ baseUrl: string;
102
+ type: AIHubMixCatalogType;
103
+ }): string;
81
104
  export interface AIHubMixCatalogModel {
82
105
  id: string;
83
106
  label: string;
@@ -94,6 +117,8 @@ export interface ParseAIHubMixCatalogOptions {
94
117
  }
95
118
  /** Parses the AIHubMix catalogue envelope into { id, label } options. Reads
96
119
  * `model_id` (the wire name sent as `model`) and `model_name` (display). */
97
- export declare function parseAIHubMixCatalog(data: unknown, options?: ParseAIHubMixCatalogOptions): AIHubMixCatalogModel[];
120
+ export declare function parseAIHubMixCatalog({ data }: {
121
+ data: unknown;
122
+ }, options?: ParseAIHubMixCatalogOptions): AIHubMixCatalogModel[];
98
123
  export declare const AIHUBMIX_IMAGE_ASPECT_TO_SIZE: Record<string, string>;
99
124
  //# sourceMappingURL=aihubmix.d.ts.map
@@ -36,7 +36,7 @@ export const AIHUBMIX_DEFAULT_BASE_URL = 'https://aihubmix.com/v1';
36
36
  * fixed `APP-Code` attribution header. Callers spread the result into their
37
37
  * `fetch` headers and may add `content-type` etc. on top.
38
38
  */
39
- export function aihubmixHeaders(apiKey) {
39
+ export function aihubmixHeaders({ apiKey }) {
40
40
  return {
41
41
  authorization: `Bearer ${apiKey}`,
42
42
  ...aihubmixAppCodeHeader(),
@@ -55,7 +55,7 @@ export function aihubmixHeaders(apiKey) {
55
55
  export function aihubmixAppCodeHeader() {
56
56
  return { 'APP-Code': AIHUBMIX_APP_CODE };
57
57
  }
58
- export function classifyAIHubMixModel(model) {
58
+ export function classifyAIHubMixModel({ model }) {
59
59
  const m = (model || '').trim().toLowerCase();
60
60
  // Gemini: gemini*/imagen*, excluding the `-nothink`/`-search` suffixes and
61
61
  // any embedding model (those stay on the OpenAI-compatible path per §4.1).
@@ -75,7 +75,7 @@ export function classifyAIHubMixModel(model) {
75
75
  * anthropic -> `${origin}` (+ /v1/messages)
76
76
  * gemini -> `${origin}/gemini` (+ /v1beta/models/{model}:...)
77
77
  */
78
- export function aihubmixOriginFromBase(baseUrl) {
78
+ export function aihubmixOriginFromBase({ baseUrl }) {
79
79
  try {
80
80
  return new URL(baseUrl || AIHUBMIX_DEFAULT_BASE_URL).origin;
81
81
  }
@@ -84,8 +84,8 @@ export function aihubmixOriginFromBase(baseUrl) {
84
84
  }
85
85
  }
86
86
  /** Gemini-native generateContent endpoint for an AIHubMix image model. */
87
- export function aihubmixGeminiImageUrl(baseUrl, wireModel) {
88
- return (`${aihubmixOriginFromBase(baseUrl)}/gemini/v1beta/models/`
87
+ export function aihubmixGeminiImageUrl({ baseUrl, wireModel }) {
88
+ return (`${aihubmixOriginFromBase({ baseUrl: baseUrl })}/gemini/v1beta/models/`
89
89
  + `${encodeURIComponent(wireModel)}:generateContent`);
90
90
  }
91
91
  /**
@@ -100,24 +100,24 @@ export function aihubmixGeminiImageUrl(baseUrl, wireModel) {
100
100
  * dispatcher, abort signal, redirect policy). Throws on a non-OK status or a
101
101
  * response without inline image data.
102
102
  */
103
- export async function aihubmixGeminiImageBytes(req, doFetch) {
104
- const url = aihubmixGeminiImageUrl(req.baseUrl, req.wireModel);
105
- const resp = await doFetch(url, {
106
- method: 'POST',
107
- redirect: 'error',
108
- headers: {
109
- 'content-type': 'application/json',
110
- 'x-goog-api-key': req.apiKey,
111
- ...aihubmixAppCodeHeader(),
112
- },
113
- body: JSON.stringify({
114
- contents: [{ role: 'user', parts: [{ text: req.prompt }] }],
115
- generationConfig: {
116
- responseModalities: ['TEXT', 'IMAGE'],
117
- imageConfig: { aspectRatio: req.aspect },
103
+ export async function aihubmixGeminiImageBytes({ req, doFetch }) {
104
+ const url = aihubmixGeminiImageUrl({ baseUrl: req.baseUrl, wireModel: req.wireModel });
105
+ const resp = await doFetch({ url: url, init: {
106
+ method: 'POST',
107
+ redirect: 'error',
108
+ headers: {
109
+ 'content-type': 'application/json',
110
+ 'x-goog-api-key': req.apiKey,
111
+ ...aihubmixAppCodeHeader(),
118
112
  },
119
- }),
120
- });
113
+ body: JSON.stringify({
114
+ contents: [{ role: 'user', parts: [{ text: req.prompt }] }],
115
+ generationConfig: {
116
+ responseModalities: ['TEXT', 'IMAGE'],
117
+ imageConfig: { aspectRatio: req.aspect },
118
+ },
119
+ }),
120
+ } });
121
121
  if (!resp.ok) {
122
122
  const text = await resp.text().catch(() => '');
123
123
  throw new Error(`aihubmix image (gemini) ${resp.status}: ${text.slice(0, 240)}`);
@@ -143,7 +143,7 @@ const AIHUBMIX_WIRE_MODELS = {
143
143
  'aihubmix-dall-e-3': 'dall-e-3',
144
144
  'aihubmix-tts-1': 'tts-1',
145
145
  };
146
- export function aihubmixWireModel(catalogId) {
146
+ export function aihubmixWireModel({ catalogId }) {
147
147
  return AIHUBMIX_WIRE_MODELS[catalogId] ?? catalogId.replace(/^aihubmix-/, '');
148
148
  }
149
149
  // AIHubMix's unified /videos API uses a single `seconds` (string) field for
@@ -156,7 +156,7 @@ export function aihubmixWireModel(catalogId) {
156
156
  // wan: 5, 10 (default 5)
157
157
  // seedance/doubao + unknown: accepts a range — clamp to 3-12.
158
158
  // `wireModel` is the upstream name (prefix already stripped).
159
- export function aihubmixVideoSeconds(wireModel, requested) {
159
+ export function aihubmixVideoSeconds({ wireModel, requested }) {
160
160
  const m = (wireModel || '').toLowerCase();
161
161
  const req = Number.isFinite(requested) ? requested : 5;
162
162
  let allowed = null;
@@ -174,7 +174,7 @@ export function aihubmixVideoSeconds(wireModel, requested) {
174
174
  const snapped = allowed.reduce((best, v) => (Math.abs(v - req) < Math.abs(best - req) ? v : best), allowed[0]);
175
175
  return String(snapped);
176
176
  }
177
- export function aihubmixCatalogUrl(baseUrl, type) {
177
+ export function aihubmixCatalogUrl({ baseUrl, type }) {
178
178
  let origin;
179
179
  try {
180
180
  origin = new URL(baseUrl || AIHUBMIX_DEFAULT_BASE_URL).origin;
@@ -200,7 +200,7 @@ function aihubmixRowTypes(row) {
200
200
  }
201
201
  /** Parses the AIHubMix catalogue envelope into { id, label } options. Reads
202
202
  * `model_id` (the wire name sent as `model`) and `model_name` (display). */
203
- export function parseAIHubMixCatalog(data, options) {
203
+ export function parseAIHubMixCatalog({ data }, options = {}) {
204
204
  const rows = data?.data;
205
205
  if (!Array.isArray(rows))
206
206
  return [];
@@ -207,10 +207,17 @@ export interface AnthropicTurnResult {
207
207
  readonly stopReason: string | null;
208
208
  readonly toolTurns: number;
209
209
  }
210
- export declare function anthropicRequestUrl(baseUrl: string | undefined): string;
211
- export declare function anthropicHeaders(options: AnthropicTurnOptions): Record<string, string>;
212
- export declare function anthropicRequestBody(options: AnthropicTurnOptions, messages: readonly AnthropicMessageParam[]): Record<string, unknown>;
213
- export declare function extractAnthropicErrorDetail(rawText: string): string;
210
+ export declare function anthropicRequestUrl({ baseUrl }: {
211
+ baseUrl: string | undefined;
212
+ }): string;
213
+ export declare function anthropicHeaders(requiredArgs: Pick<AnthropicTurnOptions, "apiKey" | "model" | "messages" | "maxTokens" | "onEvent">, optionalArgs?: Omit<AnthropicTurnOptions, "apiKey" | "model" | "messages" | "maxTokens" | "onEvent">): Record<string, string>;
214
+ export declare function anthropicRequestBody({ options, messages }: {
215
+ options: AnthropicTurnOptions;
216
+ messages: readonly AnthropicMessageParam[];
217
+ }): Record<string, unknown>;
218
+ export declare function extractAnthropicErrorDetail({ rawText }: {
219
+ rawText: string;
220
+ }): string;
214
221
  /**
215
222
  * Validates one tool-result content block against the real API's format/size constraints.
216
223
  * Returns the violation reason, or `null` when the block is legal to send.
@@ -223,7 +230,9 @@ export declare function extractAnthropicErrorDetail(rawText: string): string;
223
230
  * @complexity O(1) — reads `data.length`, never decodes or parses the base64 payload.
224
231
  * @overallScore 100
225
232
  */
226
- export declare function invalidToolResultContentBlockReason(block: AnthropicToolResultContentBlock): string | null;
233
+ export declare function invalidToolResultContentBlockReason({ block }: {
234
+ block: AnthropicToolResultContentBlock;
235
+ }): string | null;
227
236
  /**
228
237
  * Runtime guard applied to every `AnthropicToolExecutor` result before it is wired onto the
229
238
  * outbound request or reported via `onEvent`. `AnthropicToolResult` is host-owned (see
@@ -242,7 +251,9 @@ export declare function invalidToolResultContentBlockReason(block: AnthropicTool
242
251
  * `invalidToolResultContentBlockReason`).
243
252
  * @overallScore 100
244
253
  */
245
- export declare function guardToolResult(result: AnthropicToolResult): AnthropicToolResult;
254
+ export declare function guardToolResult({ result }: {
255
+ result: AnthropicToolResult;
256
+ }): AnthropicToolResult;
246
257
  export interface AnthropicBlockState {
247
258
  readonly type: 'text' | 'tool_use' | 'other';
248
259
  text: string;
@@ -265,23 +276,58 @@ export interface AnthropicStreamState {
265
276
  usage: Record<string, unknown> | null;
266
277
  }
267
278
  /** Parses one SSE frame's data as a JSON object, or `null` for a malformed/empty keep-alive frame or a non-object payload — both are tolerated by the caller as "nothing to do this frame". */
268
- export declare function parseAnthropicSseData(raw: string): Record<string, unknown> | null;
269
- export declare function handleContentBlockStart(state: AnthropicStreamState, data: Record<string, unknown>): void;
279
+ export declare function parseAnthropicSseData({ raw }: {
280
+ raw: string;
281
+ }): Record<string, unknown> | null;
282
+ export declare function handleContentBlockStart({ state, data }: {
283
+ state: AnthropicStreamState;
284
+ data: Record<string, unknown>;
285
+ }): void;
270
286
  /**
271
287
  * Feeds one text delta through the role-marker guard and emits the safe portion. Returns
272
288
  * `'break'` once the guard flags contamination (the caller ends the turn immediately), otherwise
273
289
  * `'continue'`.
274
290
  */
275
- export declare function handleAnthropicTextDelta(state: AnthropicStreamState, index: number, text: string, onEvent: (event: AnthropicTurnEvent) => void): 'continue' | 'break';
276
- export declare function handleAnthropicInputJsonDelta(state: AnthropicStreamState, index: number, partialJson: string): void;
277
- export declare function handleContentBlockDelta(state: AnthropicStreamState, data: Record<string, unknown>, onEvent: (event: AnthropicTurnEvent) => void): 'continue' | 'break';
291
+ export declare function handleAnthropicTextDelta({ state, index, text, onEvent }: {
292
+ state: AnthropicStreamState;
293
+ index: number;
294
+ text: string;
295
+ onEvent: (event: AnthropicTurnEvent) => void;
296
+ }): 'continue' | 'break';
297
+ export declare function handleAnthropicInputJsonDelta({ state, index, partialJson }: {
298
+ state: AnthropicStreamState;
299
+ index: number;
300
+ partialJson: string;
301
+ }): void;
302
+ export declare function handleContentBlockDelta({ state, data, onEvent }: {
303
+ state: AnthropicStreamState;
304
+ data: Record<string, unknown>;
305
+ onEvent: (event: AnthropicTurnEvent) => void;
306
+ }): 'continue' | 'break';
278
307
  /** Parses one tool_use block's accumulated `input_json_delta` text, falling back to `{}` for empty or malformed JSON — mirrors OpenAI's identical fallback for `tool_calls[].function.arguments` in `openai-chat.ts`. */
279
- export declare function parseAccumulatedToolInputJson(inputJson: string): unknown;
280
- export declare function handleContentBlockStop(state: AnthropicStreamState, data: Record<string, unknown>, onEvent: (event: AnthropicTurnEvent) => void): void;
281
- export declare function handleMessageDelta(state: AnthropicStreamState, data: Record<string, unknown>, onEvent: (event: AnthropicTurnEvent) => void): void;
282
- export declare function handleAnthropicErrorFrame(data: Record<string, unknown>, onEvent: (event: AnthropicTurnEvent) => void, apiKey: string): void;
308
+ export declare function parseAccumulatedToolInputJson({ inputJson }: {
309
+ inputJson: string;
310
+ }): unknown;
311
+ export declare function handleContentBlockStop({ state, data, onEvent }: {
312
+ state: AnthropicStreamState;
313
+ data: Record<string, unknown>;
314
+ onEvent: (event: AnthropicTurnEvent) => void;
315
+ }): void;
316
+ export declare function handleMessageDelta({ state, data, onEvent }: {
317
+ state: AnthropicStreamState;
318
+ data: Record<string, unknown>;
319
+ onEvent: (event: AnthropicTurnEvent) => void;
320
+ }): void;
321
+ export declare function handleAnthropicErrorFrame({ data, onEvent, apiKey }: {
322
+ data: Record<string, unknown>;
323
+ onEvent: (event: AnthropicTurnEvent) => void;
324
+ apiKey: string;
325
+ }): void;
283
326
  /** The SSE event's dispatch key: `data.type` when present (every real Anthropic frame carries one), else the record's `event:` line, else `''` — a key that intentionally matches no entry in {@link ANTHROPIC_FRAME_HANDLERS} (`message_start`/`message_stop`/`ping`/future event types fall through as no-ops, same as before this frame was a lookup table). */
284
- export declare function anthropicFrameKind(data: Record<string, unknown>, frameEvent: string | null): string;
327
+ export declare function anthropicFrameKind({ data, frameEvent }: {
328
+ data: Record<string, unknown>;
329
+ frameEvent: string | null;
330
+ }): string;
285
331
  /**
286
332
  * Runs a full Anthropic Messages API turn, including the tool-execution
287
333
  * loop when `options.executeTool` is supplied and the model requests tool
@@ -300,9 +346,20 @@ export declare function anthropicFrameKind(data: Record<string, unknown>, frameE
300
346
  * "stop" conditions (no/empty tool_use, no executor, turn ceiling reached) are exercised as plain
301
347
  * value-in/value-out assertions rather than through the full request/event-emission machinery.
302
348
  */
303
- export declare function anthropicLoopExitReason(outcome: SingleRequestOutcome, toolTurns: number, maxToolTurns: number): AnthropicTurnEndReason | null;
304
- export declare function buildAnthropicAssistantContent(text: string, toolCalls: readonly AnthropicToolCall[]): AnthropicContentBlockParam[];
349
+ export declare function anthropicLoopExitReason({ outcome, toolTurns, maxToolTurns }: {
350
+ outcome: SingleRequestOutcome;
351
+ toolTurns: number;
352
+ maxToolTurns: number;
353
+ }): AnthropicTurnEndReason | null;
354
+ export declare function buildAnthropicAssistantContent({ text, toolCalls }: {
355
+ text: string;
356
+ toolCalls: readonly AnthropicToolCall[];
357
+ }): AnthropicContentBlockParam[];
305
358
  /** Runs every pending tool call in order and reduces the results into the `tool_result` blocks the next request's `user` message carries. Emits one `tool_result` event per call as it goes. */
306
- export declare function executeAnthropicToolCalls(executeTool: AnthropicToolExecutor, calls: readonly AnthropicToolCall[], onEvent: (event: AnthropicTurnEvent) => void): Promise<AnthropicToolResultBlockParam[]>;
307
- export declare function runAnthropicToolTurn(options: AnthropicTurnOptions): Promise<AnthropicTurnResult>;
359
+ export declare function executeAnthropicToolCalls({ executeTool, calls, onEvent }: {
360
+ executeTool: AnthropicToolExecutor;
361
+ calls: readonly AnthropicToolCall[];
362
+ onEvent: (event: AnthropicTurnEvent) => void;
363
+ }): Promise<AnthropicToolResultBlockParam[]>;
364
+ export declare function runAnthropicToolTurn(requiredArgs: Pick<AnthropicTurnOptions, "apiKey" | "model" | "messages" | "maxTokens" | "onEvent">, optionalArgs?: Omit<AnthropicTurnOptions, "apiKey" | "model" | "messages" | "maxTokens" | "onEvent">): Promise<AnthropicTurnResult>;
308
365
  //# sourceMappingURL=anthropic-messages.d.ts.map