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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +54 -2
  2. package/README.md +165 -50
  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 +1 -1
  7. package/esm/src/codex_app_server_debug.d.ts.map +1 -1
  8. package/esm/src/codex_app_server_debug.js +1 -1
  9. package/esm/src/codex_auth.d.ts +1 -1
  10. package/esm/src/codex_auth.d.ts.map +1 -1
  11. package/esm/src/codex_auth.js +1 -1
  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 +12 -1
  20. package/esm/src/providers/codex.d.ts.map +1 -1
  21. package/esm/src/providers/codex.js +94 -30
  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 +1 -1
  37. package/script/src/codex_app_server_debug.d.ts.map +1 -1
  38. package/script/src/codex_app_server_debug.js +1 -1
  39. package/script/src/codex_auth.d.ts +1 -1
  40. package/script/src/codex_auth.d.ts.map +1 -1
  41. package/script/src/codex_auth.js +1 -1
  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 +12 -1
  50. package/script/src/providers/codex.d.ts.map +1 -1
  51. package/script/src/providers/codex.js +94 -29
  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
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GOOGLE_PREFIX = void 0;
7
7
  exports.createGoogleProvider = createGoogleProvider;
8
8
  const openai_1 = __importDefault(require("openai"));
9
+ const gambit_core_1 = require("@bolt-foundry/gambit-core");
9
10
  exports.GOOGLE_PREFIX = "google/";
10
11
  const DEFAULT_GOOGLE_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai/";
11
12
  function safeJson(input) {
@@ -24,9 +25,9 @@ function extractContent(content) {
24
25
  if (typeof content === "string")
25
26
  return content;
26
27
  if (Array.isArray(content)) {
27
- return content
28
+ return (0, gambit_core_1.joinTextParts)(content
28
29
  .map((part) => (typeof part === "string" ? part : part.text ?? ""))
29
- .join("");
30
+ .filter(Boolean));
30
31
  }
31
32
  return "";
32
33
  }
@@ -60,9 +61,7 @@ function responseItemsToChatMessages(items, instructions) {
60
61
  }
61
62
  for (const item of items) {
62
63
  if (item.type === "message") {
63
- const content = item.content
64
- .map((part) => part.text)
65
- .join("");
64
+ const content = (0, gambit_core_1.joinTextParts)(item.content.map((part) => part.text));
66
65
  messages.push({ role: item.role, content });
67
66
  continue;
68
67
  }
@@ -205,9 +204,9 @@ function createGoogleProvider(opts) {
205
204
  });
206
205
  }
207
206
  else if (Array.isArray(delta.content)) {
208
- const text = delta.content
207
+ const text = (0, gambit_core_1.joinTextParts)(delta.content
209
208
  .map((part) => (typeof part === "string" ? part : part.text ?? ""))
210
- .join("");
209
+ .filter(Boolean));
211
210
  if (text) {
212
211
  contentParts.push(text);
213
212
  input.onStreamEvent?.({
@@ -245,7 +244,7 @@ function createGoogleProvider(opts) {
245
244
  }));
246
245
  const message = normalizeMessage({
247
246
  role: "assistant",
248
- content: contentParts.length ? contentParts.join("") : null,
247
+ content: contentParts.length ? (0, gambit_core_1.joinTextParts)(contentParts) : null,
249
248
  tool_calls,
250
249
  });
251
250
  const toolCalls = tool_calls.length > 0
@@ -328,111 +327,5 @@ function createGoogleProvider(opts) {
328
327
  usage: mapChatUsage(response.usage),
329
328
  };
330
329
  },
331
- async chat(input) {
332
- const params = input.params ?? {};
333
- if (input.stream) {
334
- const stream = await client.chat.completions.create({
335
- model: input.model,
336
- messages: input.messages,
337
- tools: input
338
- // this predates the lint rule
339
- .tools,
340
- tool_choice: "auto",
341
- stream: true,
342
- ...params,
343
- }, input.signal ? { signal: input.signal } : undefined);
344
- let finishReason = null;
345
- const contentParts = [];
346
- const toolCallMap = new Map();
347
- for await (const chunk of stream) {
348
- const choice = chunk.choices[0];
349
- const fr = choice.finish_reason;
350
- if (fr === "stop" || fr === "tool_calls" || fr === "length" ||
351
- fr === null) {
352
- finishReason = fr ?? finishReason;
353
- }
354
- const delta = choice.delta;
355
- if (typeof delta.content === "string") {
356
- contentParts.push(delta.content);
357
- input.onStreamText?.(delta.content);
358
- }
359
- else if (Array.isArray(delta.content)) {
360
- const chunkStr = delta.content
361
- .map((c) => (typeof c === "string" ? c : c.text ?? ""))
362
- .join("");
363
- if (chunkStr) {
364
- contentParts.push(chunkStr);
365
- input.onStreamText?.(chunkStr);
366
- }
367
- }
368
- for (const tc of delta.tool_calls ?? []) {
369
- const idx = tc.index ?? 0;
370
- const existing = toolCallMap.get(idx) ??
371
- {
372
- id: tc.id,
373
- function: { name: tc.function?.name, arguments: "" },
374
- };
375
- if (tc.id)
376
- existing.id = tc.id;
377
- if (tc.function?.name)
378
- existing.function.name = tc.function.name;
379
- if (tc.function?.arguments) {
380
- existing.function.arguments += tc.function.arguments;
381
- }
382
- toolCallMap.set(idx, existing);
383
- }
384
- }
385
- const tool_calls = Array.from(toolCallMap.values()).map((tc) => ({
386
- id: tc.id ?? crypto.randomUUID().replace(/-/g, "").slice(0, 24),
387
- type: "function",
388
- function: {
389
- name: tc.function.name ?? "",
390
- arguments: tc.function.arguments,
391
- },
392
- }));
393
- const message = normalizeMessage({
394
- role: "assistant",
395
- content: contentParts.length ? contentParts.join("") : null,
396
- tool_calls,
397
- });
398
- const toolCalls = tool_calls.length > 0
399
- ? tool_calls.map((tc) => ({
400
- id: tc.id,
401
- name: tc.function.name,
402
- args: safeJson(tc.function.arguments),
403
- }))
404
- : undefined;
405
- return {
406
- message,
407
- finishReason: finishReason ?? "stop",
408
- toolCalls,
409
- };
410
- }
411
- const response = await client.chat.completions.create({
412
- model: input.model,
413
- messages: input
414
- // this predates the lint rule
415
- .messages,
416
- tools: input
417
- // this predates the lint rule
418
- .tools,
419
- tool_choice: "auto",
420
- stream: false,
421
- ...params,
422
- }, input.signal ? { signal: input.signal } : undefined);
423
- const choice = response.choices[0];
424
- const message = normalizeMessage(choice.message);
425
- const toolCalls = choice.message.tool_calls?.map((tc) => ({
426
- id: tc.id,
427
- name: tc.function.name,
428
- args: safeJson(tc.function.arguments),
429
- }));
430
- return {
431
- message,
432
- finishReason: (choice.finish_reason ?? "stop"),
433
- toolCalls,
434
- usage: mapChatUsage(response.usage),
435
- };
436
- },
437
330
  };
438
331
  }
@@ -18,8 +18,8 @@ export type ProviderRuntimeAuthStateSource = {
18
18
  kind: "json-file";
19
19
  path: string;
20
20
  };
21
- export type ProviderStorageAuthority = "bfdesktop";
22
- export type ProviderAttachmentAuthority = "bfdesktop-mitm" | "runtime-env-placeholder";
21
+ export type ProviderStorageAuthority = "workloop";
22
+ export type ProviderAttachmentAuthority = "workloop-mitm" | "runtime-env-placeholder";
23
23
  export type ProviderDestinationScope = "declared-destinations";
24
24
  type BaseProviderAuthRequirements = {
25
25
  attachmentAuthority: ProviderAttachmentAuthority;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/src/providers/manifest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAEnD,MAAM,MAAM,2BAA2B,GACnC,gBAAgB,GAChB,yBAAyB,CAAC;AAE9B,MAAM,MAAM,wBAAwB,GAAG,uBAAuB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AAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAChC,YAAY,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;CACrD,CAAC;AAgRF,wBAAgB,oBAAoB,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAE9D;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,WAAW,GACpB,gBAAgB,GAAG,IAAI,CAEzB;AAED,wBAAgB,0BAA0B,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAEzE"}
@@ -23,8 +23,8 @@ bareAlias = "codex-cli"
23
23
 
24
24
  [auth]
25
25
  mode = "chatgpt-auth-tokens"
26
- storageAuthority = "bfdesktop"
27
- attachmentAuthority = "bfdesktop-mitm"
26
+ storageAuthority = "workloop"
27
+ attachmentAuthority = "workloop-mitm"
28
28
  destinationScope = "declared-destinations"
29
29
 
30
30
  [[destinations]]
@@ -59,7 +59,7 @@ routingPrefix = "openrouter/"
59
59
 
60
60
  [auth]
61
61
  mode = "secret"
62
- storageAuthority = "bfdesktop"
62
+ storageAuthority = "workloop"
63
63
  attachmentAuthority = "runtime-env-placeholder"
64
64
  destinationScope = "declared-destinations"
65
65
 
@@ -76,10 +76,10 @@ function isSupportedProviderKey(value) {
76
76
  value === "codex-cli" || value === "claude-code-cli";
77
77
  }
78
78
  function isSupportedStorageAuthority(value) {
79
- return value === "bfdesktop";
79
+ return value === "workloop";
80
80
  }
81
81
  function isSupportedAttachmentAuthority(value) {
82
- return value === "bfdesktop-mitm" || value === "runtime-env-placeholder";
82
+ return value === "workloop-mitm" || value === "runtime-env-placeholder";
83
83
  }
84
84
  function isSupportedDestinationScope(value) {
85
85
  return value === "declared-destinations";
@@ -1 +1 @@
1
- {"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/src/providers/ollama.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAKV,aAAa,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AAC,MAAM,CAAC,CAAC,CAgBtB;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,OAAO,CAAC,IAAI,CAAC,CA8Cf;AA+pBD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,aAAa,CAiBhB"}
@@ -111,18 +111,6 @@ async function ensureOllamaModel(model, baseURL) {
111
111
  }
112
112
  }
113
113
  }
114
- function safeJson(input) {
115
- try {
116
- const parsed = JSON.parse(input);
117
- if (parsed && typeof parsed === "object") {
118
- return parsed;
119
- }
120
- }
121
- catch {
122
- // fall through
123
- }
124
- return {};
125
- }
126
114
  function toJsonValue(value) {
127
115
  if (value === null || typeof value === "string" || typeof value === "boolean") {
128
116
  return value;
@@ -488,86 +476,6 @@ function toOpenAIInputItems(items) {
488
476
  }
489
477
  return mapped;
490
478
  }
491
- function chatMessagesToResponseItems(messages) {
492
- const items = [];
493
- for (const message of messages) {
494
- if (message.role === "tool") {
495
- if (message.tool_call_id &&
496
- typeof message.content === "string") {
497
- items.push({
498
- type: "function_call_output",
499
- call_id: message.tool_call_id,
500
- output: message.content,
501
- });
502
- }
503
- continue;
504
- }
505
- if (message.role === "system" || message.role === "user" ||
506
- message.role === "assistant") {
507
- const content = [];
508
- if (typeof message.content === "string" && message.content.length > 0) {
509
- content.push({
510
- type: message.role === "assistant" ? "output_text" : "input_text",
511
- text: message.content,
512
- });
513
- }
514
- if (content.length > 0) {
515
- items.push({
516
- type: "message",
517
- role: message.role,
518
- content,
519
- });
520
- }
521
- }
522
- if (message.role === "assistant" && message.tool_calls) {
523
- for (const call of message.tool_calls) {
524
- items.push({
525
- type: "function_call",
526
- call_id: call.id,
527
- name: call.function.name,
528
- arguments: call.function.arguments,
529
- });
530
- }
531
- }
532
- }
533
- return items;
534
- }
535
- function responseItemsToChat(items) {
536
- const textParts = [];
537
- const toolCalls = [];
538
- const messageToolCalls = [];
539
- for (const item of items) {
540
- if (item.type === "message" && item.role === "assistant") {
541
- for (const part of item.content) {
542
- if (part.type === "output_text") {
543
- textParts.push(part.text);
544
- }
545
- }
546
- }
547
- if (item.type === "function_call") {
548
- toolCalls.push({
549
- id: item.call_id,
550
- name: item.name,
551
- args: safeJson(item.arguments),
552
- });
553
- messageToolCalls.push({
554
- id: item.call_id,
555
- type: "function",
556
- function: { name: item.name, arguments: item.arguments },
557
- });
558
- }
559
- }
560
- const content = textParts.length > 0 ? textParts.join("") : null;
561
- const message = {
562
- role: "assistant",
563
- content,
564
- tool_calls: messageToolCalls.length > 0 ? messageToolCalls : undefined,
565
- };
566
- return {
567
- message,
568
- toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
569
- };
570
- }
571
479
  async function createResponse(client, request, signal, onStreamEvent) {
572
480
  const baseParams = {
573
481
  model: request.model,
@@ -811,25 +719,5 @@ function createOllamaProvider(opts) {
811
719
  async responses(input) {
812
720
  return await createResponse(client, input.request, input.signal, input.onStreamEvent);
813
721
  },
814
- async chat(input) {
815
- const response = await createResponse(client, {
816
- model: input.model,
817
- input: chatMessagesToResponseItems(input.messages),
818
- tools: input.tools,
819
- stream: input.stream,
820
- params: input.params ?? {},
821
- }, input.signal, (event) => {
822
- if (event.type === "response.output_text.delta") {
823
- input.onStreamText?.(event.delta);
824
- }
825
- });
826
- const mapped = responseItemsToChat(response.output);
827
- return {
828
- message: mapped.message,
829
- finishReason: mapped.toolCalls ? "tool_calls" : "stop",
830
- toolCalls: mapped.toolCalls,
831
- usage: response.usage,
832
- };
833
- },
834
722
  };
835
723
  }
@@ -1 +1 @@
1
- {"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openrouter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAKV,aAAa,EAOd,MAAM,2BAA2B,CAAC;AA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AC,EAAE,WAAW,CAAA;SAAE,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;KACvB,CAAC;CACH,CAAC;AA8rBF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,aAAa,CAqBhB"}
@@ -48,35 +48,6 @@ function normalizeOpenRouterModel(model) {
48
48
  ? model.slice(exports.OPENROUTER_PREFIX.length)
49
49
  : model;
50
50
  }
51
- function normalizeMessage(content) {
52
- const toolCalls = content.tool_calls ??
53
- undefined;
54
- return {
55
- role: content.role,
56
- content: typeof content.content === "string"
57
- ? content.content
58
- : Array.isArray(content.content)
59
- ? content.content
60
- .map((c) => (typeof c === "string" ? c : ""))
61
- .join("")
62
- : "",
63
- name: content.name,
64
- tool_call_id: content.tool_call_id,
65
- tool_calls: toolCalls && toolCalls.length > 0 ? toolCalls : undefined,
66
- };
67
- }
68
- function safeJson(input) {
69
- try {
70
- const parsed = JSON.parse(input);
71
- if (parsed && typeof parsed === "object") {
72
- return parsed;
73
- }
74
- }
75
- catch {
76
- // fall through
77
- }
78
- return {};
79
- }
80
51
  function toJsonValue(value) {
81
52
  if (value === null || typeof value === "string" || typeof value === "boolean") {
82
53
  return value;
@@ -464,86 +435,6 @@ function toOpenAIInputItems(items) {
464
435
  }
465
436
  return mapped;
466
437
  }
467
- function chatMessagesToResponseItems(messages) {
468
- const items = [];
469
- for (const message of messages) {
470
- if (message.role === "tool") {
471
- if (message.tool_call_id &&
472
- typeof message.content === "string") {
473
- items.push({
474
- type: "function_call_output",
475
- call_id: message.tool_call_id,
476
- output: message.content,
477
- });
478
- }
479
- continue;
480
- }
481
- if (message.role === "system" || message.role === "user" ||
482
- message.role === "assistant") {
483
- const content = [];
484
- if (typeof message.content === "string" && message.content.length > 0) {
485
- content.push({
486
- type: message.role === "assistant" ? "output_text" : "input_text",
487
- text: message.content,
488
- });
489
- }
490
- if (content.length > 0) {
491
- items.push({
492
- type: "message",
493
- role: message.role,
494
- content,
495
- });
496
- }
497
- }
498
- if (message.role === "assistant" && message.tool_calls) {
499
- for (const call of message.tool_calls) {
500
- items.push({
501
- type: "function_call",
502
- call_id: call.id,
503
- name: call.function.name,
504
- arguments: call.function.arguments,
505
- });
506
- }
507
- }
508
- }
509
- return items;
510
- }
511
- function responseItemsToChat(items) {
512
- const textParts = [];
513
- const toolCalls = [];
514
- const messageToolCalls = [];
515
- for (const item of items) {
516
- if (item.type === "message" && item.role === "assistant") {
517
- for (const part of item.content) {
518
- if (part.type === "output_text") {
519
- textParts.push(part.text);
520
- }
521
- }
522
- }
523
- if (item.type === "function_call") {
524
- toolCalls.push({
525
- id: item.call_id,
526
- name: item.name,
527
- args: safeJson(item.arguments),
528
- });
529
- messageToolCalls.push({
530
- id: item.call_id,
531
- type: "function",
532
- function: { name: item.name, arguments: item.arguments },
533
- });
534
- }
535
- }
536
- const content = textParts.length > 0 ? textParts.join("") : null;
537
- const message = {
538
- role: "assistant",
539
- content,
540
- tool_calls: messageToolCalls.length > 0 ? messageToolCalls : undefined,
541
- };
542
- return {
543
- message,
544
- toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
545
- };
546
- }
547
438
  async function createResponse(client, request, signal, onStreamEvent) {
548
439
  const baseParams = {
549
440
  model: normalizeOpenRouterModel(request.model),
@@ -778,7 +669,6 @@ async function createResponse(client, request, signal, onStreamEvent) {
778
669
  return normalizeOpenAIResponse(responseOrStream);
779
670
  }
780
671
  function createOpenRouterProvider(opts) {
781
- const debugStream = dntShim.Deno.env.get("GAMBIT_DEBUG_STREAM") === "1";
782
672
  const client = (opts.client ??
783
673
  new openai_1.default({
784
674
  apiKey: opts.apiKey,
@@ -792,159 +682,5 @@ function createOpenRouterProvider(opts) {
792
682
  async responses(input) {
793
683
  return await createResponse(client, input.request, input.signal, input.onStreamEvent);
794
684
  },
795
- async chat(input) {
796
- const params = input.params ?? {};
797
- if (opts.enableResponses) {
798
- const response = await createResponse(client, {
799
- model: normalizeOpenRouterModel(input.model),
800
- input: chatMessagesToResponseItems(input.messages),
801
- tools: input.tools,
802
- stream: input.stream,
803
- params,
804
- }, input.signal, (event) => {
805
- if (event.type === "response.output_text.delta") {
806
- input.onStreamText?.(event.delta);
807
- }
808
- });
809
- const mapped = responseItemsToChat(response.output);
810
- return {
811
- message: mapped.message,
812
- finishReason: mapped.toolCalls ? "tool_calls" : "stop",
813
- toolCalls: mapped.toolCalls,
814
- usage: response.usage,
815
- };
816
- }
817
- if (input.stream) {
818
- if (debugStream) {
819
- logger.log(`[stream-debug] requesting stream model=${input.model} messages=${input.messages.length} tools=${input.tools?.length ?? 0}`);
820
- }
821
- const stream = await client.chat.completions.create({
822
- model: normalizeOpenRouterModel(input.model),
823
- messages: input
824
- .messages,
825
- tools: input
826
- // this predates the lint rule
827
- .tools,
828
- tool_choice: "auto",
829
- stream: true,
830
- ...params,
831
- }, input.signal ? { signal: input.signal } : undefined);
832
- let finishReason = null;
833
- const contentParts = [];
834
- const toolCallMap = new Map();
835
- let chunkCount = 0;
836
- let streamedChars = 0;
837
- for await (const chunk of stream) {
838
- chunkCount++;
839
- const choice = chunk.choices[0];
840
- const fr = choice.finish_reason;
841
- if (fr === "stop" || fr === "tool_calls" || fr === "length" ||
842
- fr === null) {
843
- finishReason = fr ?? finishReason;
844
- }
845
- const delta = choice.delta;
846
- if (typeof delta.content === "string") {
847
- contentParts.push(delta.content);
848
- input.onStreamText?.(delta.content);
849
- streamedChars += delta.content.length;
850
- }
851
- else if (Array.isArray(delta.content)) {
852
- const chunkStr = delta.content
853
- .map((c) => (typeof c === "string" ? c : ""))
854
- .join("");
855
- if (chunkStr) {
856
- contentParts.push(chunkStr);
857
- input.onStreamText?.(chunkStr);
858
- streamedChars += chunkStr.length;
859
- }
860
- }
861
- for (const tc of delta.tool_calls ?? []) {
862
- const idx = tc.index ?? 0;
863
- const existing = toolCallMap.get(idx) ??
864
- {
865
- id: tc.id,
866
- function: { name: tc.function?.name, arguments: "" },
867
- };
868
- if (tc.id)
869
- existing.id = tc.id;
870
- if (tc.function?.name)
871
- existing.function.name = tc.function.name;
872
- if (tc.function?.arguments) {
873
- existing.function.arguments += tc.function.arguments;
874
- }
875
- toolCallMap.set(idx, existing);
876
- }
877
- }
878
- if (debugStream) {
879
- logger.log(`[stream-debug] completed stream chunks=${chunkCount} streamedChars=${streamedChars} finishReason=${finishReason}`);
880
- }
881
- const tool_calls = Array.from(toolCallMap.values()).map((tc) => ({
882
- id: tc.id ?? crypto.randomUUID().replace(/-/g, "").slice(0, 24),
883
- type: "function",
884
- function: {
885
- name: tc.function.name ?? "",
886
- arguments: tc.function.arguments,
887
- },
888
- }));
889
- const message = normalizeMessage({
890
- role: "assistant",
891
- content: contentParts.length ? contentParts.join("") : null,
892
- tool_calls,
893
- });
894
- const toolCalls = tool_calls.length > 0
895
- ? tool_calls.map((tc) => ({
896
- id: tc.id,
897
- name: tc.function.name,
898
- args: safeJson(tc.function.arguments),
899
- }))
900
- : undefined;
901
- return {
902
- message,
903
- finishReason: finishReason ?? "stop",
904
- toolCalls,
905
- };
906
- }
907
- const response = await client.chat.completions.create({
908
- model: normalizeOpenRouterModel(input.model),
909
- messages: input
910
- // this predates the lint rule
911
- .messages,
912
- tools: input
913
- // this predates the lint rule
914
- .tools,
915
- tool_choice: "auto",
916
- stream: false,
917
- ...params,
918
- }, input.signal ? { signal: input.signal } : undefined);
919
- const choice = response.choices[0];
920
- const message = choice.message;
921
- const normalizedMessage = normalizeMessage(message);
922
- const toolCalls = message.tool_calls?.map((tc) => ({
923
- id: tc.id,
924
- name: tc.function.name,
925
- args: safeJson(tc.function.arguments),
926
- }));
927
- return {
928
- message: normalizedMessage,
929
- finishReason: (choice.finish_reason ?? "stop"),
930
- toolCalls,
931
- usage: response.usage
932
- ? (() => {
933
- const usage = {
934
- promptTokens: response.usage.prompt_tokens ?? 0,
935
- completionTokens: response.usage.completion_tokens ?? 0,
936
- totalTokens: response.usage.total_tokens ?? 0,
937
- };
938
- const details = response.usage;
939
- const value = details.completion_tokens_details
940
- ?.reasoning_tokens ??
941
- details.output_tokens_details?.reasoning_tokens;
942
- return typeof value === "number"
943
- ? { ...usage, reasoningTokens: value }
944
- : usage;
945
- })()
946
- : undefined,
947
- };
948
- },
949
685
  };
950
686
  }
@@ -22,7 +22,7 @@ function providerAuthUsesRuntimeEnvPlaceholders(requirements) {
22
22
  requirements.auth.attachmentAuthority === "runtime-env-placeholder";
23
23
  }
24
24
  function providerAuthUsesMitmRequestTimeAttachment(requirements) {
25
- return requirements.auth.attachmentAuthority === "bfdesktop-mitm";
25
+ return requirements.auth.attachmentAuthority === "workloop-mitm";
26
26
  }
27
27
  function resolveProviderRequirements(input) {
28
28
  const identity = (0, router_js_1.resolveProviderIdentity)(input);