@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.
- package/CHANGELOG.md +54 -2
- package/README.md +165 -50
- package/esm/mod.d.ts +11 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -1
- package/esm/src/codex_app_server_debug.d.ts +1 -1
- package/esm/src/codex_app_server_debug.d.ts.map +1 -1
- package/esm/src/codex_app_server_debug.js +1 -1
- package/esm/src/codex_auth.d.ts +1 -1
- package/esm/src/codex_auth.d.ts.map +1 -1
- package/esm/src/codex_auth.js +1 -1
- package/esm/src/default_runtime.d.ts +5 -1
- package/esm/src/default_runtime.d.ts.map +1 -1
- package/esm/src/default_runtime.js +48 -29
- package/esm/src/openai_compat.d.ts.map +1 -1
- package/esm/src/openai_compat.js +111 -11
- package/esm/src/providers/claude_code.d.ts.map +1 -1
- package/esm/src/providers/claude_code.js +3 -3
- package/esm/src/providers/codex.d.ts +12 -1
- package/esm/src/providers/codex.d.ts.map +1 -1
- package/esm/src/providers/codex.js +94 -30
- package/esm/src/providers/google.d.ts.map +1 -1
- package/esm/src/providers/google.js +7 -114
- package/esm/src/providers/manifest.d.ts +2 -2
- package/esm/src/providers/manifest.d.ts.map +1 -1
- package/esm/src/providers/manifest.js +5 -5
- package/esm/src/providers/ollama.d.ts.map +1 -1
- package/esm/src/providers/ollama.js +0 -112
- package/esm/src/providers/openrouter.d.ts.map +1 -1
- package/esm/src/providers/openrouter.js +0 -264
- package/esm/src/providers/requirements.js +1 -1
- package/package.json +1 -1
- package/script/mod.d.ts +11 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +15 -6
- package/script/src/codex_app_server_debug.d.ts +1 -1
- package/script/src/codex_app_server_debug.d.ts.map +1 -1
- package/script/src/codex_app_server_debug.js +1 -1
- package/script/src/codex_auth.d.ts +1 -1
- package/script/src/codex_auth.d.ts.map +1 -1
- package/script/src/codex_auth.js +1 -1
- package/script/src/default_runtime.d.ts +5 -1
- package/script/src/default_runtime.d.ts.map +1 -1
- package/script/src/default_runtime.js +48 -28
- package/script/src/openai_compat.d.ts.map +1 -1
- package/script/src/openai_compat.js +110 -10
- package/script/src/providers/claude_code.d.ts.map +1 -1
- package/script/src/providers/claude_code.js +3 -3
- package/script/src/providers/codex.d.ts +12 -1
- package/script/src/providers/codex.d.ts.map +1 -1
- package/script/src/providers/codex.js +94 -29
- package/script/src/providers/google.d.ts.map +1 -1
- package/script/src/providers/google.js +7 -114
- package/script/src/providers/manifest.d.ts +2 -2
- package/script/src/providers/manifest.d.ts.map +1 -1
- package/script/src/providers/manifest.js +5 -5
- package/script/src/providers/ollama.d.ts.map +1 -1
- package/script/src/providers/ollama.js +0 -112
- package/script/src/providers/openrouter.d.ts.map +1 -1
- package/script/src/providers/openrouter.js +0 -264
- package/script/src/providers/requirements.js +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
-
import { runDeck as runDeckCore } from "@bolt-foundry/gambit-core";
|
|
2
|
+
import { runDeck as runDeckCore, runDeckResponses as runDeckResponsesCore, } from "@bolt-foundry/gambit-core";
|
|
3
3
|
import { createProviderMatchers } from "./model_matchers.js";
|
|
4
4
|
import { createModelAliasResolver, loadProjectConfig, } from "./project_config.js";
|
|
5
5
|
import { CODEX_PREFIX, createCodexProvider } from "./providers/codex.js";
|
|
@@ -15,6 +15,12 @@ function mergeParams(aliasParams, baseParams) {
|
|
|
15
15
|
}
|
|
16
16
|
return baseParams ?? aliasParams;
|
|
17
17
|
}
|
|
18
|
+
const passthroughModelResolver = {
|
|
19
|
+
resolveModel: (input) => Promise.resolve({
|
|
20
|
+
model: Array.isArray(input.model) ? input.model[0] ?? "" : input.model,
|
|
21
|
+
params: input.params,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
18
24
|
function parseFallbackProviderFromConfig(fallbackProviderRaw, logger) {
|
|
19
25
|
if (typeof fallbackProviderRaw !== "string") {
|
|
20
26
|
return undefined;
|
|
@@ -53,7 +59,7 @@ function resolveSessionArtifactsConfig(opts) {
|
|
|
53
59
|
return undefined;
|
|
54
60
|
throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
|
|
55
61
|
}
|
|
56
|
-
function
|
|
62
|
+
function buildDefaultModelProviderAndResolver(opts) {
|
|
57
63
|
const openRouterApiKey = dntShim.Deno.env.get("OPENROUTER_API_KEY")?.trim();
|
|
58
64
|
const googleApiKey = (dntShim.Deno.env.get("GOOGLE_API_KEY") ??
|
|
59
65
|
dntShim.Deno.env.get("GEMINI_API_KEY"))?.trim();
|
|
@@ -277,8 +283,10 @@ function buildDefaultModelProvider(opts) {
|
|
|
277
283
|
const resolution = opts.modelAliasResolver(model);
|
|
278
284
|
return Boolean(resolution.applied || resolution.missingAlias);
|
|
279
285
|
};
|
|
280
|
-
|
|
286
|
+
const modelResolver = {
|
|
281
287
|
resolveModel: async (input) => await resolveModelSelection(input.model, input.params, input.deckPath),
|
|
288
|
+
};
|
|
289
|
+
const modelProvider = {
|
|
282
290
|
responses: async (input) => {
|
|
283
291
|
const applied = shouldResolveModel(input.request.model)
|
|
284
292
|
? await resolveModelSelection(input.request.model, input.request.params, input.deckPath)
|
|
@@ -304,25 +312,8 @@ function buildDefaultModelProvider(opts) {
|
|
|
304
312
|
},
|
|
305
313
|
});
|
|
306
314
|
},
|
|
307
|
-
chat: async (input) => {
|
|
308
|
-
const applied = shouldResolveModel(input.model)
|
|
309
|
-
? await resolveModelSelection(input.model, input.params, input.deckPath)
|
|
310
|
-
: { model: input.model, params: input.params };
|
|
311
|
-
const request = {
|
|
312
|
-
...input,
|
|
313
|
-
model: applied.model ?? input.model,
|
|
314
|
-
params: applied.params,
|
|
315
|
-
};
|
|
316
|
-
if (typeof request.model !== "string" || !request.model) {
|
|
317
|
-
throw new Error("Model is required.");
|
|
318
|
-
}
|
|
319
|
-
const selection = providerRouter.resolve({ model: request.model });
|
|
320
|
-
return await selection.provider.chat({
|
|
321
|
-
...request,
|
|
322
|
-
model: selection.model,
|
|
323
|
-
});
|
|
324
|
-
},
|
|
325
315
|
};
|
|
316
|
+
return { modelProvider, modelResolver };
|
|
326
317
|
}
|
|
327
318
|
export async function createDefaultedRuntime(opts = {}) {
|
|
328
319
|
const logger = opts.logger ?? console;
|
|
@@ -339,14 +330,16 @@ export async function createDefaultedRuntime(opts = {}) {
|
|
|
339
330
|
? "openrouter"
|
|
340
331
|
: configuredFallbackProvider;
|
|
341
332
|
const responsesMode = opts.responsesMode ?? resolveDefaultResponsesMode();
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
333
|
+
const defaults = buildDefaultModelProviderAndResolver({
|
|
334
|
+
modelAliasResolver,
|
|
335
|
+
configuredFallbackProvider,
|
|
336
|
+
effectiveFallbackProvider,
|
|
337
|
+
responsesMode,
|
|
338
|
+
logger,
|
|
339
|
+
});
|
|
340
|
+
const modelProvider = opts.modelProvider ?? defaults.modelProvider;
|
|
341
|
+
const modelResolver = opts.modelResolver ??
|
|
342
|
+
(opts.modelProvider ? passthroughModelResolver : defaults.modelResolver);
|
|
350
343
|
const defaultModel = opts.defaultModel;
|
|
351
344
|
const modelOverride = opts.modelOverride;
|
|
352
345
|
const runtimeSessionArtifacts = opts.sessionArtifacts;
|
|
@@ -355,6 +348,8 @@ export async function createDefaultedRuntime(opts = {}) {
|
|
|
355
348
|
return {
|
|
356
349
|
...coreRunOpts,
|
|
357
350
|
modelProvider: runOpts.modelProvider ?? modelProvider,
|
|
351
|
+
modelResolver: runOpts.modelResolver ??
|
|
352
|
+
(runOpts.modelProvider ? undefined : modelResolver),
|
|
358
353
|
defaultModel: runOpts.defaultModel ?? defaultModel,
|
|
359
354
|
modelOverride: runOpts.modelOverride ?? modelOverride,
|
|
360
355
|
responsesMode: runOpts.responsesMode ?? responsesMode,
|
|
@@ -366,6 +361,7 @@ export async function createDefaultedRuntime(opts = {}) {
|
|
|
366
361
|
configuredFallbackProvider,
|
|
367
362
|
effectiveFallbackProvider,
|
|
368
363
|
modelProvider,
|
|
364
|
+
modelResolver,
|
|
369
365
|
defaultModel,
|
|
370
366
|
modelOverride,
|
|
371
367
|
responsesMode,
|
|
@@ -382,6 +378,17 @@ export async function createDefaultedRuntime(opts = {}) {
|
|
|
382
378
|
}
|
|
383
379
|
throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
|
|
384
380
|
},
|
|
381
|
+
runDeckResponses: async (runOpts) => {
|
|
382
|
+
const resolved = resolveRunOptions(runOpts);
|
|
383
|
+
const effectiveSessionArtifacts = resolveSessionArtifactsConfig({
|
|
384
|
+
runtimeConfig: runtimeSessionArtifacts,
|
|
385
|
+
runConfig: runOpts.sessionArtifacts,
|
|
386
|
+
});
|
|
387
|
+
if (!effectiveSessionArtifacts) {
|
|
388
|
+
return await runDeckResponsesCore(resolved);
|
|
389
|
+
}
|
|
390
|
+
throw new Error("sessionArtifacts persistence has been removed. Use sqlite-backed workspace flows instead.");
|
|
391
|
+
},
|
|
385
392
|
};
|
|
386
393
|
}
|
|
387
394
|
export async function runDeck(opts) {
|
|
@@ -396,3 +403,15 @@ export async function runDeck(opts) {
|
|
|
396
403
|
const { runtime: _runtime, runtimeOptions: _runtimeOptions, ...runOpts } = opts;
|
|
397
404
|
return await runtime.runDeck(runOpts);
|
|
398
405
|
}
|
|
406
|
+
export async function runDeckResponses(opts) {
|
|
407
|
+
if (opts.runtime && opts.runtimeOptions) {
|
|
408
|
+
throw new Error("runDeckResponses received both runtime and runtimeOptions. Pass only one.");
|
|
409
|
+
}
|
|
410
|
+
const runtime = opts.runtime ??
|
|
411
|
+
await createDefaultedRuntime({
|
|
412
|
+
...opts.runtimeOptions,
|
|
413
|
+
configHint: opts.runtimeOptions?.configHint ?? opts.path,
|
|
414
|
+
});
|
|
415
|
+
const { runtime: _runtime, runtimeOptions: _runtimeOptions, ...runOpts } = opts;
|
|
416
|
+
return await runtime.runDeckResponses(runOpts);
|
|
417
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../src/src/openai_compat.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../src/src/openai_compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,2BAA2B,EAI5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,aAAa,EACb,0BAA0B,EAC1B,eAAe,EAEf,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,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;KACzC,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;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E,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"}
|
package/esm/src/openai_compat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
2
|
import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js";
|
|
3
|
-
import { assertZodSchema, DEFAULT_GUARDRAILS, loadDeck, RESERVED_TOOL_PREFIX, resolveEffectivePermissions,
|
|
3
|
+
import { assertZodSchema, DEFAULT_GUARDRAILS, joinTextParts, loadDeck, RESERVED_TOOL_PREFIX, resolveEffectivePermissions, runDeckResponses, stringifyResponseOutput, toJsonSchema, } from "@bolt-foundry/gambit-core";
|
|
4
4
|
export const logger = console;
|
|
5
5
|
function randomId(prefix) {
|
|
6
6
|
const suffix = crypto.randomUUID().replace(/-/g, "").slice(0, 24);
|
|
@@ -13,9 +13,9 @@ function normalizeContent(content) {
|
|
|
13
13
|
return content;
|
|
14
14
|
if (!Array.isArray(content))
|
|
15
15
|
return String(content);
|
|
16
|
-
return content
|
|
16
|
+
return joinTextParts(content
|
|
17
17
|
.map((c) => (typeof c === "string" ? c : (c.text ?? "")))
|
|
18
|
-
.
|
|
18
|
+
.filter(Boolean));
|
|
19
19
|
}
|
|
20
20
|
function normalizeMessages(input) {
|
|
21
21
|
return input.map((m) => ({
|
|
@@ -28,6 +28,88 @@ function normalizeMessages(input) {
|
|
|
28
28
|
: undefined,
|
|
29
29
|
}));
|
|
30
30
|
}
|
|
31
|
+
function responseItemsFromMessages(messages) {
|
|
32
|
+
return messages.flatMap((message) => {
|
|
33
|
+
if (message.role === "tool") {
|
|
34
|
+
return [{
|
|
35
|
+
type: "function_call_output",
|
|
36
|
+
call_id: message.tool_call_id ?? randomId("tool"),
|
|
37
|
+
output: message.content ?? "",
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
const items = [];
|
|
41
|
+
if (message.content) {
|
|
42
|
+
items.push({
|
|
43
|
+
type: "message",
|
|
44
|
+
role: message.role,
|
|
45
|
+
content: [{
|
|
46
|
+
type: message.role === "assistant" ? "output_text" : "input_text",
|
|
47
|
+
text: message.content,
|
|
48
|
+
}],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (message.role === "assistant" && message.tool_calls?.length) {
|
|
52
|
+
for (const toolCall of message.tool_calls) {
|
|
53
|
+
items.push({
|
|
54
|
+
type: "function_call",
|
|
55
|
+
call_id: toolCall.id,
|
|
56
|
+
name: toolCall.function.name,
|
|
57
|
+
arguments: toolCall.function.arguments,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (items.length)
|
|
62
|
+
return items;
|
|
63
|
+
return {
|
|
64
|
+
type: "message",
|
|
65
|
+
role: message.role,
|
|
66
|
+
content: [],
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function responseOutputToChatResult(output) {
|
|
71
|
+
const textParts = [];
|
|
72
|
+
const toolCalls = [];
|
|
73
|
+
for (const item of output) {
|
|
74
|
+
if (item.type === "message" && item.role === "assistant") {
|
|
75
|
+
for (const part of item.content) {
|
|
76
|
+
if (part.type === "output_text" || part.type === "summary_text" ||
|
|
77
|
+
part.type === "reasoning_text") {
|
|
78
|
+
textParts.push(part.text);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (item.type === "function_call") {
|
|
83
|
+
let args = {};
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(item.arguments || "{}");
|
|
86
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
87
|
+
args = parsed;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
args = {};
|
|
92
|
+
}
|
|
93
|
+
toolCalls.push({ id: item.call_id, name: item.name, args });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const message = {
|
|
97
|
+
role: "assistant",
|
|
98
|
+
content: textParts.length ? joinTextParts(textParts) : null,
|
|
99
|
+
tool_calls: toolCalls.length
|
|
100
|
+
? toolCalls.map((call) => ({
|
|
101
|
+
id: call.id,
|
|
102
|
+
type: "function",
|
|
103
|
+
function: { name: call.name, arguments: JSON.stringify(call.args) },
|
|
104
|
+
}))
|
|
105
|
+
: undefined,
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
message,
|
|
109
|
+
finishReason: toolCalls.length ? "tool_calls" : "stop",
|
|
110
|
+
toolCalls: toolCalls.length ? toolCalls : undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
31
113
|
function providerParamsFromRequest(req) {
|
|
32
114
|
const out = {};
|
|
33
115
|
if (req.temperature !== undefined)
|
|
@@ -131,6 +213,14 @@ function warnIfSystemMismatch(args) {
|
|
|
131
213
|
logger.warn(`[gambit] chatCompletionsWithDeck: request includes a system message that does not match the deck prompt (${args.deckPath})`);
|
|
132
214
|
}
|
|
133
215
|
function toolResultContent(result) {
|
|
216
|
+
if (result && typeof result === "object" &&
|
|
217
|
+
"legacyResult" in result &&
|
|
218
|
+
"output" in result) {
|
|
219
|
+
const text = stringifyResponseOutput(result.output);
|
|
220
|
+
if (text)
|
|
221
|
+
return text;
|
|
222
|
+
return toolResultContent(result.legacyResult);
|
|
223
|
+
}
|
|
134
224
|
if (typeof result === "string")
|
|
135
225
|
return result;
|
|
136
226
|
try {
|
|
@@ -203,15 +293,25 @@ export async function chatCompletionsWithDeck(args) {
|
|
|
203
293
|
(() => {
|
|
204
294
|
throw new Error("No model provided");
|
|
205
295
|
})();
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
296
|
+
const response = await args.modelProvider.responses({
|
|
297
|
+
request: {
|
|
298
|
+
model,
|
|
299
|
+
input: responseItemsFromMessages(messages),
|
|
300
|
+
tools: tools.length ? tools : undefined,
|
|
301
|
+
stream: Boolean(args.request.stream),
|
|
302
|
+
params: providerParamsFromRequest(args.request),
|
|
303
|
+
},
|
|
211
304
|
deckPath: deck.path,
|
|
212
|
-
|
|
213
|
-
|
|
305
|
+
onStreamEvent: (event) => {
|
|
306
|
+
if (event.type === "response.output_text.delta") {
|
|
307
|
+
args.onStreamText?.(event.delta);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
214
310
|
});
|
|
311
|
+
const result = {
|
|
312
|
+
...responseOutputToChatResult(response.output),
|
|
313
|
+
usage: response.usage,
|
|
314
|
+
};
|
|
215
315
|
messages.push(result.message);
|
|
216
316
|
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
217
317
|
const gambitCalls = result.toolCalls.filter((c) => gambit.toolNameSet.has(c.name));
|
|
@@ -259,7 +359,7 @@ export async function chatCompletionsWithDeck(args) {
|
|
|
259
359
|
type: "openai_compat.action.permissions",
|
|
260
360
|
permissions: actionPermissions.trace,
|
|
261
361
|
});
|
|
262
|
-
const childResult = await
|
|
362
|
+
const childResult = await runDeckResponses({
|
|
263
363
|
path: actionPath,
|
|
264
364
|
input: call.args,
|
|
265
365
|
modelProvider: args.modelProvider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude_code.d.ts","sourceRoot":"","sources":["../../../src/src/providers/claude_code.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,YAAY,EACZ,aAAa,EAKb,UAAU,EACX,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"claude_code.d.ts","sourceRoot":"","sources":["../../../src/src/providers/claude_code.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,YAAY,EACZ,aAAa,EAKb,UAAU,EACX,MAAM,2BAA2B,CAAC;AAGnC,eA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
3
4
|
export const CLAUDE_CODE_ALIAS = "claude-code-cli";
|
|
4
5
|
const CLAUDE_CODE_BIN_ENV = "GAMBIT_CLAUDE_CODE_BIN";
|
|
@@ -100,7 +101,7 @@ function extractAssistantTextFromClaudeMessage(message) {
|
|
|
100
101
|
parts.push(text);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
return parts
|
|
104
|
+
return joinTextParts(parts).trim();
|
|
104
105
|
}
|
|
105
106
|
function extractBestText(input) {
|
|
106
107
|
if (typeof input === "string" && input.trim())
|
|
@@ -428,7 +429,7 @@ function responseItemsToChatMessages(items, instructions) {
|
|
|
428
429
|
}
|
|
429
430
|
for (const item of items) {
|
|
430
431
|
if (item.type === "message") {
|
|
431
|
-
const content = item.content.map((part) => part.text)
|
|
432
|
+
const content = joinTextParts(item.content.map((part) => part.text));
|
|
432
433
|
messages.push({ role: item.role, content });
|
|
433
434
|
continue;
|
|
434
435
|
}
|
|
@@ -660,7 +661,6 @@ export function createClaudeCodeProvider(opts) {
|
|
|
660
661
|
}
|
|
661
662
|
return response;
|
|
662
663
|
},
|
|
663
|
-
chat: runChat,
|
|
664
664
|
};
|
|
665
665
|
}
|
|
666
666
|
export 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;
|
|
@@ -56,6 +57,16 @@ export declare function codexConfigArgsForTest(input: {
|
|
|
56
57
|
instructions?: string;
|
|
57
58
|
}): Array<string>;
|
|
58
59
|
export declare function safeJsonForTest(text: string): Record<string, JSONValue>;
|
|
60
|
+
export declare function appServerRequestResultForTest(input: {
|
|
61
|
+
method: string;
|
|
62
|
+
params: Record<string, unknown>;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
result?: Record<string, JSONValue>;
|
|
65
|
+
error?: {
|
|
66
|
+
code: number;
|
|
67
|
+
message: string;
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
59
70
|
export declare function sanitizeCodexSpawnArgsForTest(args: Array<string>): Array<string>;
|
|
60
71
|
export declare function extractCodexConfigValuesForTest(args: Array<string>, flag: string, prefix?: string): Array<string>;
|
|
61
72
|
export {};
|
|
@@ -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,
|
|
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,EAGZ,UAAU,EACV,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAI/D,eAAO,MAAM,YAAY,eAAe,CAAC;AA0DzC,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,KAA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