@bolt-foundry/gambit 0.8.6 → 1.0.0-rc.1

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 (61) hide show
  1. package/CHANGELOG.md +25 -2
  2. package/README.md +22 -10
  3. package/esm/mod.d.ts +11 -3
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/mod.js +7 -1
  6. package/esm/src/codex_app_server_debug.d.ts +3 -2
  7. package/esm/src/codex_app_server_debug.d.ts.map +1 -1
  8. package/esm/src/codex_app_server_debug.js +5 -3
  9. package/esm/src/codex_auth.d.ts +2 -1
  10. package/esm/src/codex_auth.d.ts.map +1 -1
  11. package/esm/src/codex_auth.js +4 -2
  12. package/esm/src/default_runtime.d.ts +5 -1
  13. package/esm/src/default_runtime.d.ts.map +1 -1
  14. package/esm/src/default_runtime.js +48 -29
  15. package/esm/src/openai_compat.d.ts.map +1 -1
  16. package/esm/src/openai_compat.js +111 -11
  17. package/esm/src/providers/claude_code.d.ts.map +1 -1
  18. package/esm/src/providers/claude_code.js +3 -3
  19. package/esm/src/providers/codex.d.ts +2 -1
  20. package/esm/src/providers/codex.d.ts.map +1 -1
  21. package/esm/src/providers/codex.js +50 -22
  22. package/esm/src/providers/google.d.ts.map +1 -1
  23. package/esm/src/providers/google.js +7 -114
  24. package/esm/src/providers/manifest.d.ts +2 -2
  25. package/esm/src/providers/manifest.d.ts.map +1 -1
  26. package/esm/src/providers/manifest.js +5 -5
  27. package/esm/src/providers/ollama.d.ts.map +1 -1
  28. package/esm/src/providers/ollama.js +0 -112
  29. package/esm/src/providers/openrouter.d.ts.map +1 -1
  30. package/esm/src/providers/openrouter.js +0 -264
  31. package/esm/src/providers/requirements.js +1 -1
  32. package/package.json +1 -1
  33. package/script/mod.d.ts +11 -3
  34. package/script/mod.d.ts.map +1 -1
  35. package/script/mod.js +15 -6
  36. package/script/src/codex_app_server_debug.d.ts +3 -2
  37. package/script/src/codex_app_server_debug.d.ts.map +1 -1
  38. package/script/src/codex_app_server_debug.js +6 -3
  39. package/script/src/codex_auth.d.ts +2 -1
  40. package/script/src/codex_auth.d.ts.map +1 -1
  41. package/script/src/codex_auth.js +5 -3
  42. package/script/src/default_runtime.d.ts +5 -1
  43. package/script/src/default_runtime.d.ts.map +1 -1
  44. package/script/src/default_runtime.js +48 -28
  45. package/script/src/openai_compat.d.ts.map +1 -1
  46. package/script/src/openai_compat.js +110 -10
  47. package/script/src/providers/claude_code.d.ts.map +1 -1
  48. package/script/src/providers/claude_code.js +3 -3
  49. package/script/src/providers/codex.d.ts +2 -1
  50. package/script/src/providers/codex.d.ts.map +1 -1
  51. package/script/src/providers/codex.js +49 -21
  52. package/script/src/providers/google.d.ts.map +1 -1
  53. package/script/src/providers/google.js +7 -114
  54. package/script/src/providers/manifest.d.ts +2 -2
  55. package/script/src/providers/manifest.d.ts.map +1 -1
  56. package/script/src/providers/manifest.js +5 -5
  57. package/script/src/providers/ollama.d.ts.map +1 -1
  58. package/script/src/providers/ollama.js +0 -112
  59. package/script/src/providers/openrouter.d.ts.map +1 -1
  60. package/script/src/providers/openrouter.js +0 -264
  61. package/script/src/providers/requirements.js +1 -1
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createDefaultedRuntime = createDefaultedRuntime;
37
37
  exports.runDeck = runDeck;
38
+ exports.runDeckResponses = runDeckResponses;
38
39
  const dntShim = __importStar(require("../_dnt.shims.js"));
39
40
  const gambit_core_1 = require("@bolt-foundry/gambit-core");
40
41
  const model_matchers_js_1 = require("./model_matchers.js");
@@ -52,6 +53,12 @@ function mergeParams(aliasParams, baseParams) {
52
53
  }
53
54
  return baseParams ?? aliasParams;
54
55
  }
56
+ const passthroughModelResolver = {
57
+ resolveModel: (input) => Promise.resolve({
58
+ model: Array.isArray(input.model) ? input.model[0] ?? "" : input.model,
59
+ params: input.params,
60
+ }),
61
+ };
55
62
  function parseFallbackProviderFromConfig(fallbackProviderRaw, logger) {
56
63
  if (typeof fallbackProviderRaw !== "string") {
57
64
  return undefined;
@@ -90,7 +97,7 @@ function resolveSessionArtifactsConfig(opts) {
90
97
  return undefined;
91
98
  throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
92
99
  }
93
- function buildDefaultModelProvider(opts) {
100
+ function buildDefaultModelProviderAndResolver(opts) {
94
101
  const openRouterApiKey = dntShim.Deno.env.get("OPENROUTER_API_KEY")?.trim();
95
102
  const googleApiKey = (dntShim.Deno.env.get("GOOGLE_API_KEY") ??
96
103
  dntShim.Deno.env.get("GEMINI_API_KEY"))?.trim();
@@ -314,8 +321,10 @@ function buildDefaultModelProvider(opts) {
314
321
  const resolution = opts.modelAliasResolver(model);
315
322
  return Boolean(resolution.applied || resolution.missingAlias);
316
323
  };
317
- return {
324
+ const modelResolver = {
318
325
  resolveModel: async (input) => await resolveModelSelection(input.model, input.params, input.deckPath),
326
+ };
327
+ const modelProvider = {
319
328
  responses: async (input) => {
320
329
  const applied = shouldResolveModel(input.request.model)
321
330
  ? await resolveModelSelection(input.request.model, input.request.params, input.deckPath)
@@ -341,25 +350,8 @@ function buildDefaultModelProvider(opts) {
341
350
  },
342
351
  });
343
352
  },
344
- chat: async (input) => {
345
- const applied = shouldResolveModel(input.model)
346
- ? await resolveModelSelection(input.model, input.params, input.deckPath)
347
- : { model: input.model, params: input.params };
348
- const request = {
349
- ...input,
350
- model: applied.model ?? input.model,
351
- params: applied.params,
352
- };
353
- if (typeof request.model !== "string" || !request.model) {
354
- throw new Error("Model is required.");
355
- }
356
- const selection = providerRouter.resolve({ model: request.model });
357
- return await selection.provider.chat({
358
- ...request,
359
- model: selection.model,
360
- });
361
- },
362
353
  };
354
+ return { modelProvider, modelResolver };
363
355
  }
364
356
  async function createDefaultedRuntime(opts = {}) {
365
357
  const logger = opts.logger ?? console;
@@ -376,14 +368,16 @@ async function createDefaultedRuntime(opts = {}) {
376
368
  ? "openrouter"
377
369
  : configuredFallbackProvider;
378
370
  const responsesMode = opts.responsesMode ?? resolveDefaultResponsesMode();
379
- const modelProvider = opts.modelProvider ??
380
- buildDefaultModelProvider({
381
- modelAliasResolver,
382
- configuredFallbackProvider,
383
- effectiveFallbackProvider,
384
- responsesMode,
385
- logger,
386
- });
371
+ const defaults = buildDefaultModelProviderAndResolver({
372
+ modelAliasResolver,
373
+ configuredFallbackProvider,
374
+ effectiveFallbackProvider,
375
+ responsesMode,
376
+ logger,
377
+ });
378
+ const modelProvider = opts.modelProvider ?? defaults.modelProvider;
379
+ const modelResolver = opts.modelResolver ??
380
+ (opts.modelProvider ? passthroughModelResolver : defaults.modelResolver);
387
381
  const defaultModel = opts.defaultModel;
388
382
  const modelOverride = opts.modelOverride;
389
383
  const runtimeSessionArtifacts = opts.sessionArtifacts;
@@ -392,6 +386,8 @@ async function createDefaultedRuntime(opts = {}) {
392
386
  return {
393
387
  ...coreRunOpts,
394
388
  modelProvider: runOpts.modelProvider ?? modelProvider,
389
+ modelResolver: runOpts.modelResolver ??
390
+ (runOpts.modelProvider ? undefined : modelResolver),
395
391
  defaultModel: runOpts.defaultModel ?? defaultModel,
396
392
  modelOverride: runOpts.modelOverride ?? modelOverride,
397
393
  responsesMode: runOpts.responsesMode ?? responsesMode,
@@ -403,6 +399,7 @@ async function createDefaultedRuntime(opts = {}) {
403
399
  configuredFallbackProvider,
404
400
  effectiveFallbackProvider,
405
401
  modelProvider,
402
+ modelResolver,
406
403
  defaultModel,
407
404
  modelOverride,
408
405
  responsesMode,
@@ -419,6 +416,17 @@ async function createDefaultedRuntime(opts = {}) {
419
416
  }
420
417
  throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
421
418
  },
419
+ runDeckResponses: async (runOpts) => {
420
+ const resolved = resolveRunOptions(runOpts);
421
+ const effectiveSessionArtifacts = resolveSessionArtifactsConfig({
422
+ runtimeConfig: runtimeSessionArtifacts,
423
+ runConfig: runOpts.sessionArtifacts,
424
+ });
425
+ if (!effectiveSessionArtifacts) {
426
+ return await (0, gambit_core_1.runDeckResponses)(resolved);
427
+ }
428
+ throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
429
+ },
422
430
  };
423
431
  }
424
432
  async function runDeck(opts) {
@@ -433,3 +441,15 @@ async function runDeck(opts) {
433
441
  const { runtime: _runtime, runtimeOptions: _runtimeOptions, ...runOpts } = opts;
434
442
  return await runtime.runDeck(runOpts);
435
443
  }
444
+ async function runDeckResponses(opts) {
445
+ if (opts.runtime && opts.runtimeOptions) {
446
+ throw new Error("runDeckResponses received both runtime and runtimeOptions. Pass only one.");
447
+ }
448
+ const runtime = opts.runtime ??
449
+ await createDefaultedRuntime({
450
+ ...opts.runtimeOptions,
451
+ configHint: opts.runtimeOptions?.configHint ?? opts.path,
452
+ });
453
+ const { runtime: _runtime, runtimeOptions: _runtimeOptions, ...runOpts } = opts;
454
+ return await runtime.runDeckResponses(runOpts);
455
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../src/src/openai_compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,2BAA2B,EAG5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,aAAa,EACb,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,MAAM,SAAU,CAAC;AAO9B,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;QAC/C,OAAO,EACH,MAAM,GACN,IAAI,GACJ,KAAK,CAAC,MAAM,GAAG;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACrD,IAAI,CAAC,EAAE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,CAAC;IACjB,OAAO,EAAE,sBAAsB,CAAC;IAChC,aAAa,EAAE,aAAa,CAAC;IAC7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;IAClD,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;IAChD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,iBAAiB,CAAC,EAAE,UAAU,CAC5B,OAAO,2BAA2B,CACnC,CAAC,WAAW,CAAC,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1E,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAoNnC"}
@@ -50,9 +50,9 @@ function normalizeContent(content) {
50
50
  return content;
51
51
  if (!Array.isArray(content))
52
52
  return String(content);
53
- return content
53
+ return (0, gambit_core_1.joinTextParts)(content
54
54
  .map((c) => (typeof c === "string" ? c : (c.text ?? "")))
55
- .join("");
55
+ .filter(Boolean));
56
56
  }
57
57
  function normalizeMessages(input) {
58
58
  return input.map((m) => ({
@@ -65,6 +65,88 @@ function normalizeMessages(input) {
65
65
  : undefined,
66
66
  }));
67
67
  }
68
+ function responseItemsFromMessages(messages) {
69
+ return messages.flatMap((message) => {
70
+ if (message.role === "tool") {
71
+ return [{
72
+ type: "function_call_output",
73
+ call_id: message.tool_call_id ?? randomId("tool"),
74
+ output: message.content ?? "",
75
+ }];
76
+ }
77
+ const items = [];
78
+ if (message.content) {
79
+ items.push({
80
+ type: "message",
81
+ role: message.role,
82
+ content: [{
83
+ type: message.role === "assistant" ? "output_text" : "input_text",
84
+ text: message.content,
85
+ }],
86
+ });
87
+ }
88
+ if (message.role === "assistant" && message.tool_calls?.length) {
89
+ for (const toolCall of message.tool_calls) {
90
+ items.push({
91
+ type: "function_call",
92
+ call_id: toolCall.id,
93
+ name: toolCall.function.name,
94
+ arguments: toolCall.function.arguments,
95
+ });
96
+ }
97
+ }
98
+ if (items.length)
99
+ return items;
100
+ return {
101
+ type: "message",
102
+ role: message.role,
103
+ content: [],
104
+ };
105
+ });
106
+ }
107
+ function responseOutputToChatResult(output) {
108
+ const textParts = [];
109
+ const toolCalls = [];
110
+ for (const item of output) {
111
+ if (item.type === "message" && item.role === "assistant") {
112
+ for (const part of item.content) {
113
+ if (part.type === "output_text" || part.type === "summary_text" ||
114
+ part.type === "reasoning_text") {
115
+ textParts.push(part.text);
116
+ }
117
+ }
118
+ }
119
+ if (item.type === "function_call") {
120
+ let args = {};
121
+ try {
122
+ const parsed = JSON.parse(item.arguments || "{}");
123
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
124
+ args = parsed;
125
+ }
126
+ }
127
+ catch {
128
+ args = {};
129
+ }
130
+ toolCalls.push({ id: item.call_id, name: item.name, args });
131
+ }
132
+ }
133
+ const message = {
134
+ role: "assistant",
135
+ content: textParts.length ? (0, gambit_core_1.joinTextParts)(textParts) : null,
136
+ tool_calls: toolCalls.length
137
+ ? toolCalls.map((call) => ({
138
+ id: call.id,
139
+ type: "function",
140
+ function: { name: call.name, arguments: JSON.stringify(call.args) },
141
+ }))
142
+ : undefined,
143
+ };
144
+ return {
145
+ message,
146
+ finishReason: toolCalls.length ? "tool_calls" : "stop",
147
+ toolCalls: toolCalls.length ? toolCalls : undefined,
148
+ };
149
+ }
68
150
  function providerParamsFromRequest(req) {
69
151
  const out = {};
70
152
  if (req.temperature !== undefined)
@@ -168,6 +250,14 @@ function warnIfSystemMismatch(args) {
168
250
  exports.logger.warn(`[gambit] chatCompletionsWithDeck: request includes a system message that does not match the deck prompt (${args.deckPath})`);
169
251
  }
170
252
  function toolResultContent(result) {
253
+ if (result && typeof result === "object" &&
254
+ "legacyResult" in result &&
255
+ "output" in result) {
256
+ const text = (0, gambit_core_1.stringifyResponseOutput)(result.output);
257
+ if (text)
258
+ return text;
259
+ return toolResultContent(result.legacyResult);
260
+ }
171
261
  if (typeof result === "string")
172
262
  return result;
173
263
  try {
@@ -240,15 +330,25 @@ async function chatCompletionsWithDeck(args) {
240
330
  (() => {
241
331
  throw new Error("No model provided");
242
332
  })();
243
- const result = await args.modelProvider.chat({
244
- model,
245
- messages,
246
- tools: tools.length ? tools : undefined,
247
- stream: Boolean(args.request.stream),
333
+ const response = await args.modelProvider.responses({
334
+ request: {
335
+ model,
336
+ input: responseItemsFromMessages(messages),
337
+ tools: tools.length ? tools : undefined,
338
+ stream: Boolean(args.request.stream),
339
+ params: providerParamsFromRequest(args.request),
340
+ },
248
341
  deckPath: deck.path,
249
- onStreamText: args.onStreamText,
250
- params: providerParamsFromRequest(args.request),
342
+ onStreamEvent: (event) => {
343
+ if (event.type === "response.output_text.delta") {
344
+ args.onStreamText?.(event.delta);
345
+ }
346
+ },
251
347
  });
348
+ const result = {
349
+ ...responseOutputToChatResult(response.output),
350
+ usage: response.usage,
351
+ };
252
352
  messages.push(result.message);
253
353
  if (result.toolCalls && result.toolCalls.length > 0) {
254
354
  const gambitCalls = result.toolCalls.filter((c) => gambit.toolNameSet.has(c.name));
@@ -296,7 +396,7 @@ async function chatCompletionsWithDeck(args) {
296
396
  type: "openai_compat.action.permissions",
297
397
  permissions: actionPermissions.trace,
298
398
  });
299
- const childResult = await (0, gambit_core_1.runDeck)({
399
+ const childResult = await (0, gambit_core_1.runDeckResponses)({
300
400
  path: actionPath,
301
401
  input: call.args,
302
402
  modelProvider: args.modelProvider,
@@ -1 +1 @@
1
- {"version":3,"file":"claude_code.d.ts","sourceRoot":"","sources":["../../../src/src/providers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udeCodeProvider;
38
38
  exports.parseClaudeCodeArgsForTest = parseClaudeCodeArgsForTest;
39
39
  exports.parseClaudeCodeStdoutForTest = parseClaudeCodeStdoutForTest;
40
40
  const dntShim = __importStar(require("../../_dnt.shims.js"));
41
+ const gambit_core_1 = require("@bolt-foundry/gambit-core");
41
42
  exports.CLAUDE_CODE_PREFIX = "claude-code-cli/";
42
43
  exports.CLAUDE_CODE_ALIAS = "claude-code-cli";
43
44
  const CLAUDE_CODE_BIN_ENV = "GAMBIT_CLAUDE_CODE_BIN";
@@ -139,7 +140,7 @@ function extractAssistantTextFromClaudeMessage(message) {
139
140
  parts.push(text);
140
141
  }
141
142
  }
142
- return parts.join("").trim();
143
+ return (0, gambit_core_1.joinTextParts)(parts).trim();
143
144
  }
144
145
  function extractBestText(input) {
145
146
  if (typeof input === "string" && input.trim())
@@ -467,7 +468,7 @@ function responseItemsToChatMessages(items, instructions) {
467
468
  }
468
469
  for (const item of items) {
469
470
  if (item.type === "message") {
470
- const content = item.content.map((part) => part.text).join("");
471
+ const content = (0, gambit_core_1.joinTextParts)(item.content.map((part) => part.text));
471
472
  messages.push({ role: item.role, content });
472
473
  continue;
473
474
  }
@@ -699,7 +700,6 @@ function createClaudeCodeProvider(opts) {
699
700
  }
700
701
  return response;
701
702
  },
702
- chat: runChat,
703
703
  };
704
704
  }
705
705
  function parseClaudeCodeArgsForTest(input) {
@@ -1,4 +1,4 @@
1
- import type { JSONValue, ModelMessage, ModelProvider, ResponseItem, SavedState } from "@bolt-foundry/gambit-core";
1
+ import type { JSONValue, ModelMessage, ModelProvider, ResponseItem, SavedState, ToolDefinition } from "@bolt-foundry/gambit-core";
2
2
  import type { CodexChatgptAuthTokens } from "../codex_auth.js";
3
3
  export declare const CODEX_PREFIX = "codex-cli/";
4
4
  type CodexAssistantMessage = {
@@ -8,6 +8,7 @@ type CodexAssistantMessage = {
8
8
  type AppServerTurnRunnerInput = {
9
9
  model: string;
10
10
  messages: Array<ModelMessage>;
11
+ tools?: Array<ToolDefinition>;
11
12
  state?: SavedState;
12
13
  params?: Record<string, unknown>;
13
14
  deckPath?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../../src/src/providers/codex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,SAAS,EACT,YAAY,EACZ,aAAa,EAGb,YAAY,EAEZ,UAAU,EACX,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAI/D,eAAO,MAAM,YAAY,eAAe,CAAC;AAyDzC,KAAK,qBAAqB,GAAG;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAChD,gBAAgB,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IACvC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UNDRY_DESKTOP_CHIEF_RUNTIME_DEBUG_MCP";
68
69
  const MCP_SERVER_PATH = (() => {
69
70
  try {
70
71
  const moduleUrl = new URL(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
@@ -155,8 +156,21 @@ function shouldEnableMcpBridge() {
155
156
  return normalized === "1" || normalized === "true" || normalized === "yes";
156
157
  }
157
158
  function shouldDebugMcpBridge() {
158
- const raw = dntShim.Deno.env.get(DEBUG_MCP_ENV)?.trim().toLowerCase();
159
- return raw === "1" || raw === "true" || raw === "yes";
159
+ return [DEBUG_MCP_ENV, LEGACY_DEBUG_MCP_ENV].some((envName) => {
160
+ const raw = dntShim.Deno.env.get(envName)?.trim().toLowerCase();
161
+ return raw === "1" || raw === "true" || raw === "yes";
162
+ });
163
+ }
164
+ function isCodexNativeOrGambitBuiltinTool(name) {
165
+ return new Set([
166
+ "apply_patch",
167
+ "exec",
168
+ "gambit_consume_async_action",
169
+ "gambit_emit_output_item",
170
+ "grep_files",
171
+ "list_dir",
172
+ "read_file",
173
+ ]).has(name);
160
174
  }
161
175
  function logCodexMcpDebug(event, details) {
162
176
  if (!shouldDebugMcpBridge())
@@ -397,7 +411,15 @@ async function prepareCodexMcpRootDeck(input) {
397
411
  return {};
398
412
  }
399
413
  const deck = await (0, gambit_core_1.loadDeck)(rootDeckPath);
400
- if (deck.actionDecks.length === 0) {
414
+ const deckActionNames = new Set(deck.actionDecks.map((action) => action.name));
415
+ const deckToolNames = new Set(deck.tools.map((tool) => tool.name));
416
+ const extraExternalTools = (input.tools ?? [])
417
+ .map((tool) => tool.function)
418
+ .filter((tool) => tool &&
419
+ !isCodexNativeOrGambitBuiltinTool(tool.name) &&
420
+ !deckActionNames.has(tool.name) &&
421
+ !deckToolNames.has(tool.name));
422
+ if (deck.actionDecks.length === 0 && extraExternalTools.length === 0) {
401
423
  logCodexMcpDebug("prepareRootDeck:reuseOriginal", {
402
424
  actionCount: 0,
403
425
  deckPath: rootDeckPath,
@@ -431,15 +453,28 @@ async function prepareCodexMcpRootDeck(input) {
431
453
  }
432
454
  frontmatter.push("");
433
455
  }
456
+ for (const externalTool of extraExternalTools) {
457
+ frontmatter.push("[[tools]]");
458
+ frontmatter.push(`name = ${tomlString(externalTool.name)}`);
459
+ if (typeof externalTool.description === "string" &&
460
+ externalTool.description.trim()) {
461
+ frontmatter.push(`description = ${tomlString(externalTool.description.trim())}`);
462
+ }
463
+ frontmatter.push("");
464
+ }
434
465
  frontmatter.push("+++", "", "Codex MCP tool surface.");
435
466
  await dntShim.Deno.writeTextFile(tempDeckPath, frontmatter.join("\n"));
436
467
  logCodexMcpDebug("prepareRootDeck:synthesized", {
437
468
  actionCount: deck.actionDecks.length,
438
469
  actionNames: deck.actionDecks.map((action) => action.name),
470
+ extraToolNames: extraExternalTools.map((tool) => tool.name),
439
471
  rootDeckPath,
440
472
  synthesizedDeckPath: tempDeckPath,
441
- toolCount: deck.tools.length,
442
- toolNames: deck.tools.map((tool) => tool.name),
473
+ toolCount: deck.tools.length + extraExternalTools.length,
474
+ toolNames: [
475
+ ...deck.tools.map((tool) => tool.name),
476
+ ...extraExternalTools.map((tool) => tool.name),
477
+ ],
443
478
  });
444
479
  return {
445
480
  deckPath: tempDeckPath,
@@ -1395,7 +1430,7 @@ function extractTextParts(value) {
1395
1430
  function extractCodexItemText(record) {
1396
1431
  return typeof record.text === "string"
1397
1432
  ? record.text
1398
- : extractTextParts(record.content).join("");
1433
+ : (0, gambit_core_1.joinTextParts)(extractTextParts(record.content));
1399
1434
  }
1400
1435
  function requireCodexAssistantItemId(input) {
1401
1436
  const itemId = typeof input.record.id === "string"
@@ -1504,7 +1539,7 @@ function emitCodexReasoningEvents(input) {
1504
1539
  if (payloadType === "item.delta") {
1505
1540
  const deltaText = typeof record.text === "string"
1506
1541
  ? record.text
1507
- : extractTextParts(record.content).join("");
1542
+ : (0, gambit_core_1.joinTextParts)(extractTextParts(record.content));
1508
1543
  if (deltaText) {
1509
1544
  input.emit({
1510
1545
  type: "response.reasoning.delta",
@@ -1518,7 +1553,7 @@ function emitCodexReasoningEvents(input) {
1518
1553
  if (payloadType === "item.completed" || payloadType === "item.done") {
1519
1554
  const doneText = typeof record.text === "string"
1520
1555
  ? record.text
1521
- : extractTextParts(record.content).join("");
1556
+ : (0, gambit_core_1.joinTextParts)(extractTextParts(record.content));
1522
1557
  input.emit({
1523
1558
  type: "response.reasoning.done",
1524
1559
  output_index: outputIndex,
@@ -1612,7 +1647,7 @@ function responseItemsToChatMessages(items, instructions) {
1612
1647
  }
1613
1648
  for (const item of items) {
1614
1649
  if (item.type === "message") {
1615
- const content = item.content.map((part) => part.text).join("");
1650
+ const content = (0, gambit_core_1.joinTextParts)(item.content.map((part) => part.text));
1616
1651
  messages.push({ role: item.role, content });
1617
1652
  continue;
1618
1653
  }
@@ -1900,11 +1935,13 @@ function createCodexProvider(opts) {
1900
1935
  const cwd = codexRunCwd({ deckPath: input.deckPath });
1901
1936
  const preparedMcpRoot = await prepareCodexMcpRootDeck({
1902
1937
  deckPath: input.deckPath,
1938
+ tools: input.tools,
1903
1939
  });
1904
1940
  try {
1905
1941
  const result = await runAppServerTurn({
1906
1942
  model: input.model,
1907
1943
  messages: input.messages,
1944
+ tools: input.tools,
1908
1945
  state: input.state,
1909
1946
  params: input.params,
1910
1947
  deckPath: preparedMcpRoot.deckPath ?? input.deckPath,
@@ -1916,7 +1953,7 @@ function createCodexProvider(opts) {
1916
1953
  cwd,
1917
1954
  priorThreadId,
1918
1955
  });
1919
- const assistantText = result.assistantMessages.map((message) => message.text).join("");
1956
+ const assistantText = (0, gambit_core_1.joinTextParts)(result.assistantMessages.map((message) => message.text));
1920
1957
  if (input.stream && input.onStreamText && assistantText &&
1921
1958
  !assistantState.sawAssistantTextStream) {
1922
1959
  input.onStreamText(assistantText);
@@ -1941,15 +1978,6 @@ function createCodexProvider(opts) {
1941
1978
  await preparedMcpRoot.cleanup?.();
1942
1979
  }
1943
1980
  };
1944
- const runChat = async (input) => {
1945
- const result = await runCodexTurn(input);
1946
- return {
1947
- message: result.message,
1948
- finishReason: result.finishReason,
1949
- updatedState: result.updatedState,
1950
- usage: result.usage,
1951
- };
1952
- };
1953
1981
  return {
1954
1982
  async responses(input) {
1955
1983
  const streamHandler = input.onStreamEvent
@@ -1982,6 +2010,7 @@ function createCodexProvider(opts) {
1982
2010
  const result = await runCodexTurn({
1983
2011
  model: input.request.model,
1984
2012
  messages: responseItemsToChatMessages(input.request.input, input.request.instructions),
2013
+ tools: input.request.tools,
1985
2014
  stream: input.request.stream,
1986
2015
  params: input.request.params,
1987
2016
  state: input.state,
@@ -2097,7 +2126,6 @@ function createCodexProvider(opts) {
2097
2126
  }
2098
2127
  return response;
2099
2128
  },
2100
- chat: runChat,
2101
2129
  };
2102
2130
  }
2103
2131
  function normalizeCodexModelForTest(model) {
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,aAAa,EAId,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,aAAa,YAAY,CAAC;AAIvC,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE;QACJ,WAAW,EAAE;YACX,MAAM,EAAE,CACN,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE;gBAAE,MAAM,CAAC,EAAE,WAAW,CAAA;aAAE,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;SACvB,CAAC;KACH,CAAC;CACH,CAAC;AA8IF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,aAAa,CA6XhB"}
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,aAAa,EAId,MAAM,2BAA2B,CAAC;AAGnC,eAAO,MAAM,aAAa,YAAY,CAAC;AAIvC,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE;QACJ,WAAW,EAAE;YACX,MAAM,EAAE,CACN,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE;gBAAE,MAAM,CAAC,EAAE,WAAW,CAAA;aAAE,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;SACvB,CAAC;KACH,CAAC;CACH,CAAC;AA8IF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,aAAa,CA+OhB"}