@bolt-foundry/gambit 0.5.5 → 0.6.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 +26 -2
- package/README.md +4 -4
- package/bin/gambit.cjs +214 -0
- package/esm/mod.d.ts +22 -22
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -7
- package/esm/src/server.d.ts +1 -1
- package/esm/src/server.d.ts.map +1 -1
- package/esm/src/server.js +2 -2
- package/esm/src/trace.d.ts +1 -1
- package/esm/src/trace.d.ts.map +1 -1
- package/package.json +5 -4
- package/script/mod.d.ts +22 -22
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -14
- package/script/src/server.d.ts +1 -1
- package/script/src/server.d.ts.map +1 -1
- package/script/src/server.js +12 -12
- package/script/src/trace.d.ts +1 -1
- package/script/src/trace.d.ts.map +1 -1
- package/esm/packages/gambit-core/mod.d.ts +0 -50
- package/esm/packages/gambit-core/mod.d.ts.map +0 -1
- package/esm/packages/gambit-core/mod.js +0 -19
- package/esm/packages/gambit-core/src/definitions.d.ts +0 -11
- package/esm/packages/gambit-core/src/definitions.d.ts.map +0 -1
- package/esm/packages/gambit-core/src/definitions.js +0 -14
- package/esm/packages/gambit-core/src/openai_compat.d.ts +0 -63
- package/esm/packages/gambit-core/src/openai_compat.d.ts.map +0 -1
- package/esm/packages/gambit-core/src/openai_compat.js +0 -272
- package/esm/packages/gambit-core/src/providers/openrouter.d.ts +0 -8
- package/esm/packages/gambit-core/src/providers/openrouter.d.ts.map +0 -1
- package/esm/packages/gambit-core/src/providers/openrouter.js +0 -168
- package/esm/packages/gambit-core/src/render.d.ts +0 -51
- package/esm/packages/gambit-core/src/render.d.ts.map +0 -1
- package/esm/packages/gambit-core/src/render.js +0 -188
- package/esm/packages/gambit-core/src/schema.d.ts +0 -8
- package/esm/packages/gambit-core/src/schema.d.ts.map +0 -1
- package/esm/packages/gambit-core/src/schema.js +0 -45
- package/script/packages/gambit-core/mod.d.ts +0 -50
- package/script/packages/gambit-core/mod.d.ts.map +0 -1
- package/script/packages/gambit-core/mod.js +0 -29
- package/script/packages/gambit-core/src/definitions.d.ts +0 -11
- package/script/packages/gambit-core/src/definitions.d.ts.map +0 -1
- package/script/packages/gambit-core/src/definitions.js +0 -20
- package/script/packages/gambit-core/src/openai_compat.d.ts +0 -63
- package/script/packages/gambit-core/src/openai_compat.d.ts.map +0 -1
- package/script/packages/gambit-core/src/openai_compat.js +0 -276
- package/script/packages/gambit-core/src/providers/openrouter.d.ts +0 -8
- package/script/packages/gambit-core/src/providers/openrouter.d.ts.map +0 -1
- package/script/packages/gambit-core/src/providers/openrouter.js +0 -207
- package/script/packages/gambit-core/src/render.d.ts +0 -51
- package/script/packages/gambit-core/src/render.d.ts.map +0 -1
- package/script/packages/gambit-core/src/render.js +0 -192
- package/script/packages/gambit-core/src/schema.d.ts +0 -8
- package/script/packages/gambit-core/src/schema.d.ts.map +0 -1
- package/script/packages/gambit-core/src/schema.js +0 -51
package/script/src/server.js
CHANGED
|
@@ -36,10 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.startWebSocketSimulator = startWebSocketSimulator;
|
|
37
37
|
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
38
38
|
const path = __importStar(require("../deps/jsr.io/@std/path/1.1.4/mod.js"));
|
|
39
|
-
const
|
|
39
|
+
const gambit_core_1 = require("@bolt-foundry/gambit-core");
|
|
40
40
|
const test_bot_js_1 = require("./test_bot.js");
|
|
41
41
|
const trace_js_1 = require("./trace.js");
|
|
42
|
-
const
|
|
42
|
+
const gambit_core_2 = require("@bolt-foundry/gambit-core");
|
|
43
43
|
const durable_streams_js_1 = require("./durable_streams.js");
|
|
44
44
|
const logger = console;
|
|
45
45
|
const moduleLocation = (() => {
|
|
@@ -110,7 +110,7 @@ function resolveDefaultValue(raw) {
|
|
|
110
110
|
}
|
|
111
111
|
async function describeDeckInputSchemaFromPath(deckPath) {
|
|
112
112
|
try {
|
|
113
|
-
const deck = await (0,
|
|
113
|
+
const deck = await (0, gambit_core_2.loadDeck)(deckPath);
|
|
114
114
|
return describeZodSchema(deck.inputSchema);
|
|
115
115
|
}
|
|
116
116
|
catch (err) {
|
|
@@ -796,7 +796,7 @@ function startWebSocketSimulator(opts) {
|
|
|
796
796
|
stream: Boolean(streamOpts?.onStreamText),
|
|
797
797
|
onStreamText: streamOpts?.onStreamText,
|
|
798
798
|
});
|
|
799
|
-
if ((0,
|
|
799
|
+
if ((0, gambit_core_1.isGambitEndSignal)(result)) {
|
|
800
800
|
sessionEnded = true;
|
|
801
801
|
return "";
|
|
802
802
|
}
|
|
@@ -806,7 +806,7 @@ function startWebSocketSimulator(opts) {
|
|
|
806
806
|
const loop = async () => {
|
|
807
807
|
try {
|
|
808
808
|
if (!controller.signal.aborted) {
|
|
809
|
-
const initialResult = await (0,
|
|
809
|
+
const initialResult = await (0, gambit_core_1.runDeck)({
|
|
810
810
|
path: resolvedDeckPath,
|
|
811
811
|
input: deckInput,
|
|
812
812
|
inputProvided: hasDeckInput,
|
|
@@ -836,7 +836,7 @@ function startWebSocketSimulator(opts) {
|
|
|
836
836
|
appendFromState(enriched);
|
|
837
837
|
},
|
|
838
838
|
});
|
|
839
|
-
if ((0,
|
|
839
|
+
if ((0, gambit_core_1.isGambitEndSignal)(initialResult)) {
|
|
840
840
|
sessionEnded = true;
|
|
841
841
|
}
|
|
842
842
|
}
|
|
@@ -865,7 +865,7 @@ function startWebSocketSimulator(opts) {
|
|
|
865
865
|
});
|
|
866
866
|
if (!userMessage)
|
|
867
867
|
break;
|
|
868
|
-
const rootResult = await (0,
|
|
868
|
+
const rootResult = await (0, gambit_core_1.runDeck)({
|
|
869
869
|
path: resolvedDeckPath,
|
|
870
870
|
input: deckInput,
|
|
871
871
|
inputProvided: hasDeckInput,
|
|
@@ -903,7 +903,7 @@ function startWebSocketSimulator(opts) {
|
|
|
903
903
|
ts: Date.now(),
|
|
904
904
|
}),
|
|
905
905
|
});
|
|
906
|
-
if ((0,
|
|
906
|
+
if ((0, gambit_core_1.isGambitEndSignal)(rootResult)) {
|
|
907
907
|
sessionEnded = true;
|
|
908
908
|
break;
|
|
909
909
|
}
|
|
@@ -943,7 +943,7 @@ function startWebSocketSimulator(opts) {
|
|
|
943
943
|
broadcastTestBot({ type: "testBotStatus", run });
|
|
944
944
|
return run;
|
|
945
945
|
};
|
|
946
|
-
const deckLoadPromise = (0,
|
|
946
|
+
const deckLoadPromise = (0, gambit_core_2.loadDeck)(resolvedDeckPath)
|
|
947
947
|
.then((deck) => {
|
|
948
948
|
resolvedDeckPath = deck.path;
|
|
949
949
|
deckSlug = deckSlugFromPath(resolvedDeckPath);
|
|
@@ -1593,7 +1593,7 @@ function startWebSocketSimulator(opts) {
|
|
|
1593
1593
|
}
|
|
1594
1594
|
simulatorRunning = true;
|
|
1595
1595
|
try {
|
|
1596
|
-
const result = await (0,
|
|
1596
|
+
const result = await (0, gambit_core_1.runDeck)({
|
|
1597
1597
|
path: resolvedDeckPath,
|
|
1598
1598
|
input,
|
|
1599
1599
|
inputProvided,
|
|
@@ -2305,7 +2305,7 @@ function shouldRetryWithStringInput(error) {
|
|
|
2305
2305
|
}
|
|
2306
2306
|
async function runDeckWithFallback(args) {
|
|
2307
2307
|
try {
|
|
2308
|
-
return await (0,
|
|
2308
|
+
return await (0, gambit_core_1.runDeck)({
|
|
2309
2309
|
path: args.path,
|
|
2310
2310
|
input: args.input,
|
|
2311
2311
|
inputProvided: args.inputProvided,
|
|
@@ -2320,7 +2320,7 @@ async function runDeckWithFallback(args) {
|
|
|
2320
2320
|
}
|
|
2321
2321
|
catch (error) {
|
|
2322
2322
|
if (args.input === undefined && shouldRetryWithStringInput(error)) {
|
|
2323
|
-
return await (0,
|
|
2323
|
+
return await (0, gambit_core_1.runDeck)({
|
|
2324
2324
|
path: args.path,
|
|
2325
2325
|
input: "",
|
|
2326
2326
|
inputProvided: true,
|
package/script/src/trace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TraceEvent } from "@bolt-foundry/gambit-core
|
|
1
|
+
import type { TraceEvent } from "@bolt-foundry/gambit-core";
|
|
2
2
|
export declare function makeJsonlTracer(filePath: string): (event: TraceEvent) => void;
|
|
3
3
|
export declare function makeConsoleTracer(): (event: TraceEvent) => void;
|
|
4
4
|
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/src/trace.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/src/trace.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAI5D,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAQ7E;AAED,wBAAgB,iBAAiB,IAAI,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAmI/D"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gambit core exports for authoring and running decks/cards with runtime helpers.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
/** Define a reusable card with shared behavior, tools, or guardrails. */
|
|
7
|
-
export { defineCard } from "./src/definitions.js";
|
|
8
|
-
/** Define a deck, the primary unit of execution. */
|
|
9
|
-
export { defineDeck } from "./src/definitions.js";
|
|
10
|
-
/** Action deck definition shape. */
|
|
11
|
-
export type { ActionDeckDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
12
|
-
/** Card definition shape. */
|
|
13
|
-
export type { CardDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
14
|
-
/** Deck definition shape. */
|
|
15
|
-
export type { DeckDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
16
|
-
/** Reference to another deck. */
|
|
17
|
-
export type { DeckReferenceDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
18
|
-
/** Execution context passed to decks. */
|
|
19
|
-
export type { ExecutionContext } from "@bolt-foundry/gambit-core/internal/types";
|
|
20
|
-
/** Grader deck definition shape. */
|
|
21
|
-
export type { GraderDeckDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
22
|
-
/** Guardrails definition and hooks. */
|
|
23
|
-
export type { Guardrails } from "@bolt-foundry/gambit-core/internal/types";
|
|
24
|
-
/** JSON-serializable value type used throughout Gambit. */
|
|
25
|
-
export type { JSONValue } from "@bolt-foundry/gambit-core/internal/types";
|
|
26
|
-
/** Model provider interface for LLM backends. */
|
|
27
|
-
export type { ModelProvider } from "@bolt-foundry/gambit-core/internal/types";
|
|
28
|
-
/** Test deck definition shape. */
|
|
29
|
-
export type { TestDeckDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
30
|
-
/** Check if a value is an explicit end-of-run signal. */
|
|
31
|
-
export { isGambitEndSignal } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
32
|
-
/** Run a deck and return its execution result. */
|
|
33
|
-
export { runDeck } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
34
|
-
/** Signal for explicitly ending a Gambit run. */
|
|
35
|
-
export type { GambitEndSignal } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
36
|
-
/** OpenAI Chat Completions compatibility helper for a deck. */
|
|
37
|
-
export { chatCompletionsWithDeck } from "./src/openai_compat.js";
|
|
38
|
-
/** OpenAI-compatible request payload. */
|
|
39
|
-
export type { ChatCompletionsRequest } from "./src/openai_compat.js";
|
|
40
|
-
/** OpenAI-compatible response payload. */
|
|
41
|
-
export type { ChatCompletionsResponse } from "./src/openai_compat.js";
|
|
42
|
-
/** Render a deck to a human-readable outline or debug view. */
|
|
43
|
-
export { renderDeck } from "./src/render.js";
|
|
44
|
-
/** Options for deck rendering. */
|
|
45
|
-
export type { RenderDeckOptions } from "./src/render.js";
|
|
46
|
-
/** Result data from rendering a deck. */
|
|
47
|
-
export type { RenderDeckResult } from "./src/render.js";
|
|
48
|
-
/** Provider factory for OpenRouter-backed model calls. */
|
|
49
|
-
export { createOpenRouterProvider } from "./src/providers/openrouter.js";
|
|
50
|
-
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/packages/gambit-core/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,yEAAyE;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,oDAAoD;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,oCAAoC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,6BAA6B;AAC7B,YAAY,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/E,6BAA6B;AAC7B,YAAY,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/E,iCAAiC;AACjC,YAAY,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,yCAAyC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACjF,oCAAoC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,uCAAuC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC3E,2DAA2D;AAC3D,YAAY,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,iDAAiD;AACjD,YAAY,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAC9E,kCAAkC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AACnF,yDAAyD;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,kDAAkD;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AACrE,iDAAiD;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAClF,+DAA+D;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,yCAAyC;AACzC,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,0CAA0C;AAC1C,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,kCAAkC;AAClC,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,yCAAyC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,0DAA0D;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gambit core exports for authoring and running decks/cards with runtime helpers.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
/** Define a reusable card with shared behavior, tools, or guardrails. */
|
|
7
|
-
export { defineCard } from "./src/definitions.js";
|
|
8
|
-
/** Define a deck, the primary unit of execution. */
|
|
9
|
-
export { defineDeck } from "./src/definitions.js";
|
|
10
|
-
/** Check if a value is an explicit end-of-run signal. */
|
|
11
|
-
export { isGambitEndSignal } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
12
|
-
/** Run a deck and return its execution result. */
|
|
13
|
-
export { runDeck } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
14
|
-
/** OpenAI Chat Completions compatibility helper for a deck. */
|
|
15
|
-
export { chatCompletionsWithDeck } from "./src/openai_compat.js";
|
|
16
|
-
/** Render a deck to a human-readable outline or debug view. */
|
|
17
|
-
export { renderDeck } from "./src/render.js";
|
|
18
|
-
/** Provider factory for OpenRouter-backed model calls. */
|
|
19
|
-
export { createOpenRouterProvider } from "./src/providers/openrouter.js";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CardDefinition, DeckDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
2
|
-
import type { z } from "zod";
|
|
3
|
-
export declare function defineDeck<InputSchema extends z.ZodTypeAny, OutputSchema extends z.ZodTypeAny | undefined = undefined>(def: Omit<DeckDefinition<z.infer<InputSchema>>, "kind" | "inputSchema" | "outputSchema"> & {
|
|
4
|
-
inputSchema: InputSchema;
|
|
5
|
-
outputSchema?: OutputSchema;
|
|
6
|
-
}): DeckDefinition<z.infer<InputSchema>>;
|
|
7
|
-
export declare function defineDeck(def: Omit<DeckDefinition, "kind">): DeckDefinition;
|
|
8
|
-
export declare function defineCard(def: Omit<CardDefinition, "kind">): CardDefinition;
|
|
9
|
-
export declare function isDeckDefinition(value: unknown): value is DeckDefinition;
|
|
10
|
-
export declare function isCardDefinition(value: unknown): value is CardDefinition;
|
|
11
|
-
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../../../src/packages/gambit-core/src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/F,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,wBAAgB,UAAU,CACxB,WAAW,SAAS,CAAC,CAAC,UAAU,EAChC,YAAY,SAAS,CAAC,CAAC,UAAU,GAAG,SAAS,GAAG,SAAS,EAEzD,GAAG,EACC,IAAI,CACJ,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EACpC,MAAM,GAAG,aAAa,GAAG,cAAc,CACxC,GACC;IACA,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GACF,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AACxC,wBAAgB,UAAU,CACxB,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAChC,cAAc,CAAC;AAOlB,wBAAgB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,cAAc,CAE5E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function defineDeck(def) {
|
|
2
|
-
return { kind: "gambit.deck", ...def };
|
|
3
|
-
}
|
|
4
|
-
export function defineCard(def) {
|
|
5
|
-
return { kind: "gambit.card", ...def };
|
|
6
|
-
}
|
|
7
|
-
export function isDeckDefinition(value) {
|
|
8
|
-
return Boolean(value && typeof value === "object" &&
|
|
9
|
-
value.kind === "gambit.deck");
|
|
10
|
-
}
|
|
11
|
-
export function isCardDefinition(value) {
|
|
12
|
-
return Boolean(value && typeof value === "object" &&
|
|
13
|
-
value.kind === "gambit.card");
|
|
14
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { Guardrails, ModelMessage, ModelProvider, ToolDefinition } from "@bolt-foundry/gambit-core/internal/types";
|
|
2
|
-
export declare const logger: Console;
|
|
3
|
-
export type ChatCompletionsRequest = {
|
|
4
|
-
model: string;
|
|
5
|
-
messages: Array<{
|
|
6
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
7
|
-
content: string | null | Array<string | {
|
|
8
|
-
text?: string;
|
|
9
|
-
type?: string;
|
|
10
|
-
}>;
|
|
11
|
-
name?: string;
|
|
12
|
-
tool_call_id?: string;
|
|
13
|
-
tool_calls?: ModelMessage["tool_calls"];
|
|
14
|
-
}>;
|
|
15
|
-
tools?: Array<ToolDefinition>;
|
|
16
|
-
stream?: boolean;
|
|
17
|
-
temperature?: number;
|
|
18
|
-
top_p?: number;
|
|
19
|
-
frequency_penalty?: number;
|
|
20
|
-
presence_penalty?: number;
|
|
21
|
-
max_tokens?: number;
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
24
|
-
export type ChatCompletionsResponse = {
|
|
25
|
-
id: string;
|
|
26
|
-
object: "chat.completion";
|
|
27
|
-
created: number;
|
|
28
|
-
model: string;
|
|
29
|
-
choices: Array<{
|
|
30
|
-
index: number;
|
|
31
|
-
message: ModelMessage;
|
|
32
|
-
finish_reason: "stop" | "tool_calls" | "length";
|
|
33
|
-
logprobs: null;
|
|
34
|
-
}>;
|
|
35
|
-
usage?: {
|
|
36
|
-
prompt_tokens: number;
|
|
37
|
-
completion_tokens: number;
|
|
38
|
-
total_tokens: number;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Non-OpenAI extension field containing the full transcript and metadata.
|
|
42
|
-
* Most clients will ignore unknown fields.
|
|
43
|
-
*/
|
|
44
|
-
gambit?: {
|
|
45
|
-
deckPath: string;
|
|
46
|
-
messages: Array<ModelMessage>;
|
|
47
|
-
runId: string;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export declare function chatCompletionsWithDeck(args: {
|
|
51
|
-
deckPath: string;
|
|
52
|
-
request: ChatCompletionsRequest;
|
|
53
|
-
modelProvider: ModelProvider;
|
|
54
|
-
/**
|
|
55
|
-
* When true (default), Gambit will execute tool calls that match deck actions.
|
|
56
|
-
* Any other tool calls are returned to the caller as normal OpenAI tool calls.
|
|
57
|
-
*/
|
|
58
|
-
executeDeckTools?: boolean;
|
|
59
|
-
guardrails?: Partial<Guardrails>;
|
|
60
|
-
defaultModel?: string;
|
|
61
|
-
onStreamText?: (chunk: string) => void;
|
|
62
|
-
}): Promise<ChatCompletionsResponse>;
|
|
63
|
-
//# sourceMappingURL=openai_compat.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../../../src/packages/gambit-core/src/openai_compat.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,aAAa,EACb,cAAc,EACf,MAAM,0CAA0C,CAAC;AAElD,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;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,YAAY,CAAC;QACtB,aAAa,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC;QAChD,QAAQ,EAAE,IAAI,CAAC;KAChB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF;;;OAGG;IACH,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAC9B,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAoKF,wBAAsB,uBAAuB,CAAC,IAAI,EAAE;IAClD,QAAQ,EAAE,MAAM,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;CACxC,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAsJnC"}
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_GUARDRAILS, RESERVED_TOOL_PREFIX } from "@bolt-foundry/gambit-core/internal/constants";
|
|
2
|
-
import { loadDeck } from "@bolt-foundry/gambit-core/internal/loader";
|
|
3
|
-
import { assertZodSchema, toJsonSchema } from "./schema.js";
|
|
4
|
-
import { runDeck } from "@bolt-foundry/gambit-core/internal/runtime";
|
|
5
|
-
export const logger = console;
|
|
6
|
-
function randomId(prefix) {
|
|
7
|
-
const suffix = crypto.randomUUID().replace(/-/g, "").slice(0, 24);
|
|
8
|
-
return `${prefix}-${suffix}`;
|
|
9
|
-
}
|
|
10
|
-
function normalizeContent(content) {
|
|
11
|
-
if (content === null)
|
|
12
|
-
return null;
|
|
13
|
-
if (typeof content === "string")
|
|
14
|
-
return content;
|
|
15
|
-
if (!Array.isArray(content))
|
|
16
|
-
return String(content);
|
|
17
|
-
return content
|
|
18
|
-
.map((c) => (typeof c === "string" ? c : (c.text ?? "")))
|
|
19
|
-
.join("");
|
|
20
|
-
}
|
|
21
|
-
function normalizeMessages(input) {
|
|
22
|
-
return input.map((m) => ({
|
|
23
|
-
role: m.role,
|
|
24
|
-
content: normalizeContent(m.content),
|
|
25
|
-
name: m.name,
|
|
26
|
-
tool_call_id: m.tool_call_id,
|
|
27
|
-
tool_calls: m.tool_calls && m.tool_calls.length > 0
|
|
28
|
-
? m.tool_calls
|
|
29
|
-
: undefined,
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
function providerParamsFromRequest(req) {
|
|
33
|
-
const out = {};
|
|
34
|
-
if (req.temperature !== undefined)
|
|
35
|
-
out.temperature = req.temperature;
|
|
36
|
-
if (req.top_p !== undefined)
|
|
37
|
-
out.top_p = req.top_p;
|
|
38
|
-
if (req.frequency_penalty !== undefined) {
|
|
39
|
-
out.frequency_penalty = req.frequency_penalty;
|
|
40
|
-
}
|
|
41
|
-
if (req.presence_penalty !== undefined) {
|
|
42
|
-
out.presence_penalty = req.presence_penalty;
|
|
43
|
-
}
|
|
44
|
-
if (req.max_tokens !== undefined)
|
|
45
|
-
out.max_tokens = req.max_tokens;
|
|
46
|
-
return Object.keys(out).length ? out : undefined;
|
|
47
|
-
}
|
|
48
|
-
function mergeToolDefs(gambitTools, externalTools) {
|
|
49
|
-
if (!externalTools?.length)
|
|
50
|
-
return gambitTools;
|
|
51
|
-
return [...gambitTools, ...externalTools];
|
|
52
|
-
}
|
|
53
|
-
function toolName(tool) {
|
|
54
|
-
return tool.function?.name ?? "";
|
|
55
|
-
}
|
|
56
|
-
function assertNoToolNameCollisions(args) {
|
|
57
|
-
if (!args.externalTools?.length)
|
|
58
|
-
return;
|
|
59
|
-
const gambit = new Set(args.gambitTools.map(toolName));
|
|
60
|
-
for (const t of args.externalTools) {
|
|
61
|
-
const name = toolName(t);
|
|
62
|
-
if (!name)
|
|
63
|
-
continue;
|
|
64
|
-
if (name.startsWith(RESERVED_TOOL_PREFIX)) {
|
|
65
|
-
throw new Error(`External tool name ${name} is reserved (prefix ${RESERVED_TOOL_PREFIX})`);
|
|
66
|
-
}
|
|
67
|
-
if (gambit.has(name)) {
|
|
68
|
-
throw new Error(`Tool name collision for ${name} between Gambit deck actions and external tools`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async function buildGambitActionTools(deck) {
|
|
73
|
-
const tools = [];
|
|
74
|
-
const toolNameSet = new Set();
|
|
75
|
-
const actionPathByName = new Map();
|
|
76
|
-
for (const action of deck.actionDecks) {
|
|
77
|
-
const child = await loadDeck(action.path, deck.path);
|
|
78
|
-
if (!child.inputSchema || !child.outputSchema) {
|
|
79
|
-
throw new Error(`Deck ${child.path} must declare inputSchema and outputSchema (non-root)`);
|
|
80
|
-
}
|
|
81
|
-
assertZodSchema(child.inputSchema, "inputSchema");
|
|
82
|
-
assertZodSchema(child.outputSchema, "outputSchema");
|
|
83
|
-
const params = toJsonSchema(child.inputSchema);
|
|
84
|
-
tools.push({
|
|
85
|
-
type: "function",
|
|
86
|
-
function: {
|
|
87
|
-
name: action.name,
|
|
88
|
-
description: action.description,
|
|
89
|
-
parameters: params,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
toolNameSet.add(action.name);
|
|
93
|
-
actionPathByName.set(action.name, action.path);
|
|
94
|
-
}
|
|
95
|
-
return { tools, toolNameSet, actionPathByName };
|
|
96
|
-
}
|
|
97
|
-
function deckSystemPrompt(deck) {
|
|
98
|
-
const parts = [];
|
|
99
|
-
const prompt = deck.body ?? deck.prompt;
|
|
100
|
-
if (prompt)
|
|
101
|
-
parts.push(prompt.trim());
|
|
102
|
-
for (const card of deck.cards) {
|
|
103
|
-
if (card.body)
|
|
104
|
-
parts.push(card.body.trim());
|
|
105
|
-
}
|
|
106
|
-
return parts.join("\n\n").trim();
|
|
107
|
-
}
|
|
108
|
-
function shouldPrependDeckSystem(messages, systemPrompt) {
|
|
109
|
-
if (!systemPrompt)
|
|
110
|
-
return false;
|
|
111
|
-
if (!messages.length)
|
|
112
|
-
return true;
|
|
113
|
-
const hasExact = messages.some((m) => m.role === "system" && m.content === systemPrompt);
|
|
114
|
-
return !hasExact;
|
|
115
|
-
}
|
|
116
|
-
function warnIfSystemMismatch(args) {
|
|
117
|
-
if (!args.systemPrompt)
|
|
118
|
-
return;
|
|
119
|
-
const existing = args.provided.find((m) => m.role === "system");
|
|
120
|
-
if (!existing)
|
|
121
|
-
return;
|
|
122
|
-
if (existing.content === args.systemPrompt)
|
|
123
|
-
return;
|
|
124
|
-
logger.warn(`[gambit] chatCompletionsWithDeck: request includes a system message that does not match the deck prompt (${args.deckPath})`);
|
|
125
|
-
}
|
|
126
|
-
function toolResultContent(result) {
|
|
127
|
-
if (typeof result === "string")
|
|
128
|
-
return result;
|
|
129
|
-
try {
|
|
130
|
-
return JSON.stringify(result);
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
return String(result);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function normalizeError(err) {
|
|
137
|
-
return { message: err instanceof Error ? err.message : String(err) };
|
|
138
|
-
}
|
|
139
|
-
export async function chatCompletionsWithDeck(args) {
|
|
140
|
-
const executeDeckTools = args.executeDeckTools ?? true;
|
|
141
|
-
const guardrails = { ...DEFAULT_GUARDRAILS, ...args.guardrails };
|
|
142
|
-
const runId = randomId("run");
|
|
143
|
-
const deck = await loadDeck(args.deckPath);
|
|
144
|
-
const systemPrompt = deckSystemPrompt(deck);
|
|
145
|
-
const providedMessages = normalizeMessages(args.request.messages);
|
|
146
|
-
const messages = [];
|
|
147
|
-
warnIfSystemMismatch({
|
|
148
|
-
provided: providedMessages,
|
|
149
|
-
systemPrompt,
|
|
150
|
-
deckPath: deck.path,
|
|
151
|
-
});
|
|
152
|
-
if (shouldPrependDeckSystem(providedMessages, systemPrompt)) {
|
|
153
|
-
messages.push({ role: "system", content: systemPrompt });
|
|
154
|
-
}
|
|
155
|
-
messages.push(...providedMessages);
|
|
156
|
-
const gambit = await buildGambitActionTools(deck);
|
|
157
|
-
assertNoToolNameCollisions({
|
|
158
|
-
gambitTools: gambit.tools,
|
|
159
|
-
externalTools: args.request.tools,
|
|
160
|
-
});
|
|
161
|
-
const tools = mergeToolDefs(gambit.tools, args.request.tools);
|
|
162
|
-
const start = performance.now();
|
|
163
|
-
let passes = 0;
|
|
164
|
-
while (passes < guardrails.maxPasses) {
|
|
165
|
-
passes++;
|
|
166
|
-
if (performance.now() - start > guardrails.timeoutMs) {
|
|
167
|
-
throw new Error("Timeout exceeded");
|
|
168
|
-
}
|
|
169
|
-
const model = args.request.model ?? args.defaultModel ??
|
|
170
|
-
(() => {
|
|
171
|
-
throw new Error("No model provided");
|
|
172
|
-
})();
|
|
173
|
-
const result = await args.modelProvider.chat({
|
|
174
|
-
model,
|
|
175
|
-
messages,
|
|
176
|
-
tools: tools.length ? tools : undefined,
|
|
177
|
-
stream: Boolean(args.request.stream),
|
|
178
|
-
onStreamText: args.onStreamText,
|
|
179
|
-
params: providerParamsFromRequest(args.request),
|
|
180
|
-
});
|
|
181
|
-
messages.push(result.message);
|
|
182
|
-
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
183
|
-
const gambitCalls = result.toolCalls.filter((c) => gambit.toolNameSet.has(c.name));
|
|
184
|
-
const externalCalls = result.toolCalls.filter((c) => !gambit.toolNameSet.has(c.name));
|
|
185
|
-
if (!executeDeckTools || externalCalls.length > 0) {
|
|
186
|
-
return {
|
|
187
|
-
id: randomId("chatcmpl"),
|
|
188
|
-
object: "chat.completion",
|
|
189
|
-
created: Math.floor(Date.now() / 1000),
|
|
190
|
-
model,
|
|
191
|
-
choices: [{
|
|
192
|
-
index: 0,
|
|
193
|
-
message: result.message,
|
|
194
|
-
finish_reason: "tool_calls",
|
|
195
|
-
logprobs: null,
|
|
196
|
-
}],
|
|
197
|
-
usage: result.usage
|
|
198
|
-
? {
|
|
199
|
-
prompt_tokens: result.usage.promptTokens,
|
|
200
|
-
completion_tokens: result.usage.completionTokens,
|
|
201
|
-
total_tokens: result.usage.totalTokens,
|
|
202
|
-
}
|
|
203
|
-
: undefined,
|
|
204
|
-
gambit: { deckPath: deck.path, messages, runId },
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
// Execute only deck-defined tool calls.
|
|
208
|
-
for (const call of gambitCalls) {
|
|
209
|
-
const actionPath = gambit.actionPathByName.get(call.name);
|
|
210
|
-
if (!actionPath)
|
|
211
|
-
continue;
|
|
212
|
-
try {
|
|
213
|
-
const childResult = await runDeck({
|
|
214
|
-
path: actionPath,
|
|
215
|
-
input: call.args,
|
|
216
|
-
modelProvider: args.modelProvider,
|
|
217
|
-
isRoot: false,
|
|
218
|
-
guardrails,
|
|
219
|
-
depth: 1,
|
|
220
|
-
parentActionCallId: call.id,
|
|
221
|
-
runId,
|
|
222
|
-
defaultModel: model,
|
|
223
|
-
modelOverride: undefined,
|
|
224
|
-
trace: undefined,
|
|
225
|
-
stream: Boolean(args.request.stream),
|
|
226
|
-
onStreamText: args.onStreamText,
|
|
227
|
-
inputProvided: true,
|
|
228
|
-
});
|
|
229
|
-
messages.push({
|
|
230
|
-
role: "tool",
|
|
231
|
-
name: call.name,
|
|
232
|
-
tool_call_id: call.id,
|
|
233
|
-
content: toolResultContent(childResult),
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
catch (err) {
|
|
237
|
-
messages.push({
|
|
238
|
-
role: "tool",
|
|
239
|
-
name: call.name,
|
|
240
|
-
tool_call_id: call.id,
|
|
241
|
-
content: JSON.stringify({ error: normalizeError(err) }),
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (result.finishReason === "tool_calls") {
|
|
248
|
-
throw new Error("Model requested tool_calls but provided none");
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
id: randomId("chatcmpl"),
|
|
252
|
-
object: "chat.completion",
|
|
253
|
-
created: Math.floor(Date.now() / 1000),
|
|
254
|
-
model,
|
|
255
|
-
choices: [{
|
|
256
|
-
index: 0,
|
|
257
|
-
message: result.message,
|
|
258
|
-
finish_reason: result.finishReason,
|
|
259
|
-
logprobs: null,
|
|
260
|
-
}],
|
|
261
|
-
usage: result.usage
|
|
262
|
-
? {
|
|
263
|
-
prompt_tokens: result.usage.promptTokens,
|
|
264
|
-
completion_tokens: result.usage.completionTokens,
|
|
265
|
-
total_tokens: result.usage.totalTokens,
|
|
266
|
-
}
|
|
267
|
-
: undefined,
|
|
268
|
-
gambit: { deckPath: deck.path, messages, runId },
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
throw new Error("Max passes exceeded without completing");
|
|
272
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ModelProvider } from "@bolt-foundry/gambit-core/internal/types";
|
|
2
|
-
export declare function createOpenRouterProvider(opts: {
|
|
3
|
-
apiKey: string;
|
|
4
|
-
baseURL?: string;
|
|
5
|
-
referer?: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
}): ModelProvider;
|
|
8
|
-
//# sourceMappingURL=openrouter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../../../src/packages/gambit-core/src/providers/openrouter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,0CAA0C,CAAC;AAwBlD,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;CAChB,GAAG,aAAa,CAqLhB"}
|