@bolt-foundry/gambit-core 0.6.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -0
- package/cards/context.card.md +9 -0
- package/cards/end.card.md +10 -0
- package/cards/respond.card.md +10 -0
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/constants.d.ts +1 -1
- package/esm/mod.d.ts +26 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +0 -2
- package/esm/src/builtins.d.ts +3 -0
- package/esm/src/builtins.d.ts.map +1 -0
- package/esm/src/builtins.js +26 -0
- package/esm/src/loader.d.ts.map +1 -1
- package/esm/src/loader.js +6 -3
- package/esm/src/markdown.d.ts.map +1 -1
- package/esm/src/markdown.js +25 -4
- package/esm/src/openai_compat.d.ts.map +1 -1
- package/esm/src/openai_compat.js +92 -25
- package/esm/src/openresponses.d.ts +6 -0
- package/esm/src/openresponses.d.ts.map +1 -0
- package/esm/src/openresponses.js +75 -0
- package/esm/src/runtime.d.ts.map +1 -1
- package/esm/src/runtime.js +139 -35
- package/esm/src/state.d.ts +4 -3
- package/esm/src/state.d.ts.map +1 -1
- package/esm/src/types.d.ts +306 -33
- package/esm/src/types.d.ts.map +1 -1
- package/package.json +1 -2
- package/schemas/graders/contexts/conversation.ts +17 -0
- package/schemas/graders/contexts/turn.ts +10 -0
- package/schemas/graders/respond.ts +9 -0
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/deps/jsr.io/@std/path/1.1.4/constants.d.ts +1 -1
- package/script/mod.d.ts +26 -2
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +1 -4
- package/script/src/builtins.d.ts +3 -0
- package/script/src/builtins.d.ts.map +1 -0
- package/script/src/builtins.js +63 -0
- package/script/src/loader.d.ts.map +1 -1
- package/script/src/loader.js +6 -3
- package/script/src/markdown.d.ts.map +1 -1
- package/script/src/markdown.js +25 -4
- package/script/src/openai_compat.d.ts.map +1 -1
- package/script/src/openai_compat.js +92 -25
- package/script/src/openresponses.d.ts +6 -0
- package/script/src/openresponses.d.ts.map +1 -0
- package/script/src/openresponses.js +81 -0
- package/script/src/runtime.d.ts.map +1 -1
- package/script/src/runtime.js +139 -35
- package/script/src/state.d.ts +4 -3
- package/script/src/state.d.ts.map +1 -1
- package/script/src/types.d.ts +306 -33
- package/script/src/types.d.ts.map +1 -1
- package/esm/src/providers/openrouter.d.ts +0 -8
- package/esm/src/providers/openrouter.d.ts.map +0 -1
- package/esm/src/providers/openrouter.js +0 -168
- package/script/src/providers/openrouter.d.ts +0 -8
- package/script/src/providers/openrouter.d.ts.map +0 -1
- package/script/src/providers/openrouter.js +0 -207
package/script/_dnt.polyfills.js
CHANGED
|
@@ -1,5 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.import_meta_ponyfill = exports.import_meta_ponyfill_esmodule = exports.import_meta_ponyfill_commonjs = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
6
|
+
* but instead of using npm to install additional dependencies,
|
|
7
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
8
|
+
*
|
|
9
|
+
* Note that this code might be imported multiple times
|
|
10
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
11
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
12
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
13
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
14
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
15
|
+
*/
|
|
16
|
+
//@ts-ignore
|
|
17
|
+
const node_module_1 = require("node:module");
|
|
18
|
+
//@ts-ignore
|
|
19
|
+
const node_url_1 = require("node:url");
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
const node_path_1 = require("node:path");
|
|
22
|
+
const defineGlobalPonyfill = (symbolFor, fn) => {
|
|
23
|
+
if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
|
|
24
|
+
Object.defineProperty(globalThis, Symbol.for(symbolFor), {
|
|
25
|
+
configurable: true,
|
|
26
|
+
get() {
|
|
27
|
+
return fn;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
|
|
33
|
+
(() => {
|
|
34
|
+
const moduleImportMetaWM = new WeakMap();
|
|
35
|
+
return (require, module) => {
|
|
36
|
+
let importMetaCache = moduleImportMetaWM.get(module);
|
|
37
|
+
if (importMetaCache == null) {
|
|
38
|
+
const importMeta = Object.assign(Object.create(null), {
|
|
39
|
+
url: (0, node_url_1.pathToFileURL)(module.filename).href,
|
|
40
|
+
main: require.main == module,
|
|
41
|
+
resolve: (specifier, parentURL = importMeta.url) => {
|
|
42
|
+
return (0, node_url_1.pathToFileURL)((importMeta.url === parentURL
|
|
43
|
+
? require
|
|
44
|
+
: (0, node_module_1.createRequire)(parentURL))
|
|
45
|
+
.resolve(specifier)).href;
|
|
46
|
+
},
|
|
47
|
+
filename: module.filename,
|
|
48
|
+
dirname: module.path,
|
|
49
|
+
});
|
|
50
|
+
moduleImportMetaWM.set(module, importMeta);
|
|
51
|
+
importMetaCache = importMeta;
|
|
52
|
+
}
|
|
53
|
+
return importMetaCache;
|
|
54
|
+
};
|
|
55
|
+
})());
|
|
56
|
+
defineGlobalPonyfill("import-meta-ponyfill-commonjs", exports.import_meta_ponyfill_commonjs);
|
|
57
|
+
exports.import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
|
|
58
|
+
((importMeta) => {
|
|
59
|
+
const resolveFunStr = String(importMeta.resolve);
|
|
60
|
+
const shimWs = new WeakSet();
|
|
61
|
+
//@ts-ignore
|
|
62
|
+
const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
|
|
63
|
+
.replace(/\/{3,}/, "///");
|
|
64
|
+
const commonShim = (importMeta) => {
|
|
65
|
+
if (typeof importMeta.main !== "boolean") {
|
|
66
|
+
importMeta.main = importMeta.url === mainUrl;
|
|
67
|
+
}
|
|
68
|
+
if (typeof importMeta.filename !== "string") {
|
|
69
|
+
importMeta.filename = (0, node_url_1.fileURLToPath)(importMeta.url);
|
|
70
|
+
importMeta.dirname = (0, node_path_1.dirname)(importMeta.filename);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (
|
|
74
|
+
// v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
|
|
75
|
+
resolveFunStr === "undefined" ||
|
|
76
|
+
// v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
|
|
77
|
+
resolveFunStr.startsWith("async")
|
|
78
|
+
// enable by --experimental-import-meta-resolve flag
|
|
79
|
+
) {
|
|
80
|
+
exports.import_meta_ponyfill_esmodule = (importMeta) => {
|
|
81
|
+
if (!shimWs.has(importMeta)) {
|
|
82
|
+
shimWs.add(importMeta);
|
|
83
|
+
const importMetaUrlRequire = {
|
|
84
|
+
url: importMeta.url,
|
|
85
|
+
require: (0, node_module_1.createRequire)(importMeta.url),
|
|
86
|
+
};
|
|
87
|
+
importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
|
|
88
|
+
return (0, node_url_1.pathToFileURL)((importMetaUrlRequire.url === parentURL
|
|
89
|
+
? importMetaUrlRequire.require
|
|
90
|
+
: (0, node_module_1.createRequire)(parentURL)).resolve(specifier)).href;
|
|
91
|
+
};
|
|
92
|
+
commonShim(importMeta);
|
|
93
|
+
}
|
|
94
|
+
return importMeta;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
/// native support
|
|
99
|
+
exports.import_meta_ponyfill_esmodule = (importMeta) => {
|
|
100
|
+
if (!shimWs.has(importMeta)) {
|
|
101
|
+
shimWs.add(importMeta);
|
|
102
|
+
commonShim(importMeta);
|
|
103
|
+
}
|
|
104
|
+
return importMeta;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return (0, exports.import_meta_ponyfill_esmodule)(importMeta);
|
|
108
|
+
}));
|
|
109
|
+
defineGlobalPonyfill("import-meta-ponyfill-esmodule", exports.import_meta_ponyfill_esmodule);
|
|
110
|
+
exports.import_meta_ponyfill = ((...args) => {
|
|
111
|
+
const _MODULE = (() => {
|
|
112
|
+
if (typeof require === "function" && typeof module === "object") {
|
|
113
|
+
return "commonjs";
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// eval("typeof import.meta");
|
|
117
|
+
return "esmodule";
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
if (_MODULE === "commonjs") {
|
|
121
|
+
//@ts-ignore
|
|
122
|
+
exports.import_meta_ponyfill = (r, m) => (0, exports.import_meta_ponyfill_commonjs)(r, m);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
exports.import_meta_ponyfill = (im) => (0, exports.import_meta_ponyfill_esmodule)(im);
|
|
127
|
+
}
|
|
128
|
+
//@ts-ignore
|
|
129
|
+
return (0, exports.import_meta_ponyfill)(...args);
|
|
130
|
+
});
|
|
3
131
|
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
4
132
|
if (!Object.hasOwn) {
|
|
5
133
|
Object.defineProperty(Object, "hasOwn", {
|
|
@@ -7,7 +7,7 @@ export declare const DELIMITER: ";" | ":";
|
|
|
7
7
|
* The character used to separate components of a file path.
|
|
8
8
|
* On Windows, this is `\`. On all other platforms, this is `/`.
|
|
9
9
|
*/
|
|
10
|
-
export declare const SEPARATOR: "
|
|
10
|
+
export declare const SEPARATOR: "/" | "\\";
|
|
11
11
|
/**
|
|
12
12
|
* A regular expression that matches one or more path separators.
|
|
13
13
|
*/
|
package/script/mod.d.ts
CHANGED
|
@@ -26,6 +26,32 @@ export type { Guardrails } from "./src/types.js";
|
|
|
26
26
|
export type { HandlersConfig } from "./src/types.js";
|
|
27
27
|
/** JSON-serializable value type used throughout Gambit. */
|
|
28
28
|
export type { JSONValue } from "./src/types.js";
|
|
29
|
+
/** Open Responses content part. */
|
|
30
|
+
export type { OpenResponseContentPart } from "./src/types.js";
|
|
31
|
+
/** Open Responses input (string or items). */
|
|
32
|
+
export type { OpenResponseInput } from "./src/types.js";
|
|
33
|
+
/** Open Responses item. */
|
|
34
|
+
export type { OpenResponseItem } from "./src/types.js";
|
|
35
|
+
/** Open Responses item status. */
|
|
36
|
+
export type { OpenResponseItemStatus } from "./src/types.js";
|
|
37
|
+
/** Open Responses message role. */
|
|
38
|
+
export type { OpenResponseMessageRole } from "./src/types.js";
|
|
39
|
+
/** Open Responses request type. */
|
|
40
|
+
export type { OpenResponseCreateRequest } from "./src/types.js";
|
|
41
|
+
/** Open Responses response type. */
|
|
42
|
+
export type { OpenResponseCreateResponse } from "./src/types.js";
|
|
43
|
+
/** Open Responses usage metadata. */
|
|
44
|
+
export type { OpenResponseUsage } from "./src/types.js";
|
|
45
|
+
/** Open Responses response format. */
|
|
46
|
+
export type { OpenResponseFormat } from "./src/types.js";
|
|
47
|
+
/** Open Responses tool choice. */
|
|
48
|
+
export type { OpenResponseToolChoice } from "./src/types.js";
|
|
49
|
+
/** Open Responses reasoning config. */
|
|
50
|
+
export type { OpenResponseReasoning } from "./src/types.js";
|
|
51
|
+
/** Open Responses stream options. */
|
|
52
|
+
export type { OpenResponseStreamOptions } from "./src/types.js";
|
|
53
|
+
/** Open Responses streaming event type. */
|
|
54
|
+
export type { OpenResponseEvent } from "./src/types.js";
|
|
29
55
|
/** Test deck definition shape. */
|
|
30
56
|
export type { TestDeckDefinition } from "./src/types.js";
|
|
31
57
|
/** Check if a value is an explicit end-of-run signal. */
|
|
@@ -46,8 +72,6 @@ export { renderDeck } from "./src/render.js";
|
|
|
46
72
|
export type { RenderDeckOptions } from "./src/render.js";
|
|
47
73
|
/** Result data from rendering a deck. */
|
|
48
74
|
export type { RenderDeckResult } from "./src/render.js";
|
|
49
|
-
/** Provider factory for OpenRouter-backed model calls. */
|
|
50
|
-
export { createOpenRouterProvider } from "./src/providers/openrouter.js";
|
|
51
75
|
/** Gambit CLI helpers and internal primitives. */
|
|
52
76
|
export { GAMBIT_TOOL_INIT } from "./src/constants.js";
|
|
53
77
|
/** Load a deck definition from disk. */
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,yEAAyE;AACzE,OAAO,qBAAqB,CAAC;AAE7B,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,gBAAgB,CAAC;AAC3D,6BAA6B;AAC7B,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,6BAA6B;AAC7B,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,iCAAiC;AACjC,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,yCAAyC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,oCAAoC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,uCAAuC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,8CAA8C;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,gBA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B,CAAC;AACpD,6CAA6C;AAC7C,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
package/script/mod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saveState = exports.loadState = exports.loadDeck = exports.GAMBIT_TOOL_INIT = exports.
|
|
3
|
+
exports.saveState = exports.loadState = exports.loadDeck = exports.GAMBIT_TOOL_INIT = exports.renderDeck = exports.chatCompletionsWithDeck = exports.runDeck = exports.isGambitEndSignal = exports.defineDeck = exports.defineCard = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Gambit core exports for authoring and running decks/cards with runtime helpers.
|
|
6
6
|
*
|
|
@@ -25,9 +25,6 @@ Object.defineProperty(exports, "chatCompletionsWithDeck", { enumerable: true, ge
|
|
|
25
25
|
/** Render a deck to a human-readable outline or debug view. */
|
|
26
26
|
var render_js_1 = require("./src/render.js");
|
|
27
27
|
Object.defineProperty(exports, "renderDeck", { enumerable: true, get: function () { return render_js_1.renderDeck; } });
|
|
28
|
-
/** Provider factory for OpenRouter-backed model calls. */
|
|
29
|
-
var openrouter_js_1 = require("./src/providers/openrouter.js");
|
|
30
|
-
Object.defineProperty(exports, "createOpenRouterProvider", { enumerable: true, get: function () { return openrouter_js_1.createOpenRouterProvider; } });
|
|
31
28
|
/** Gambit CLI helpers and internal primitives. */
|
|
32
29
|
var constants_js_1 = require("./src/constants.js");
|
|
33
30
|
Object.defineProperty(exports, "GAMBIT_TOOL_INIT", { enumerable: true, get: function () { return constants_js_1.GAMBIT_TOOL_INIT; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../src/src/builtins.ts"],"names":[],"mappings":"AAYA,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOzE;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO3E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveBuiltinCardPath = resolveBuiltinCardPath;
|
|
37
|
+
exports.resolveBuiltinSchemaPath = resolveBuiltinSchemaPath;
|
|
38
|
+
const path = __importStar(require("../deps/jsr.io/@std/path/1.1.4/mod.js"));
|
|
39
|
+
const CARDS_PREFIX = "gambit://cards/";
|
|
40
|
+
const SCHEMAS_PREFIX = "gambit://schemas/";
|
|
41
|
+
const CARDS_BASE_URL = new URL("../cards/", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
|
|
42
|
+
const SCHEMAS_BASE_URL = new URL("../schemas/", globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
|
|
43
|
+
function resolveFromBase(base, relative) {
|
|
44
|
+
return path.fromFileUrl(new URL(relative, base));
|
|
45
|
+
}
|
|
46
|
+
function resolveBuiltinCardPath(target) {
|
|
47
|
+
if (!target.startsWith(CARDS_PREFIX))
|
|
48
|
+
return undefined;
|
|
49
|
+
const relative = target.slice(CARDS_PREFIX.length);
|
|
50
|
+
if (!relative) {
|
|
51
|
+
throw new Error(`Invalid gambit card specifier: ${target}`);
|
|
52
|
+
}
|
|
53
|
+
return resolveFromBase(CARDS_BASE_URL, relative);
|
|
54
|
+
}
|
|
55
|
+
function resolveBuiltinSchemaPath(target) {
|
|
56
|
+
if (!target.startsWith(SCHEMAS_PREFIX))
|
|
57
|
+
return undefined;
|
|
58
|
+
const relative = target.slice(SCHEMAS_PREFIX.length);
|
|
59
|
+
if (!relative) {
|
|
60
|
+
throw new Error(`Invalid gambit schema specifier: ${target}`);
|
|
61
|
+
}
|
|
62
|
+
return resolveFromBase(SCHEMAS_BASE_URL, relative);
|
|
63
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/src/loader.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKV,UAAU,EACV,UAAU,EAEX,MAAM,YAAY,CAAC;AAsHpB,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,KAAK,CAAC,MAAM,CAAM,GACxB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CA6HrB"}
|
package/script/src/loader.js
CHANGED
|
@@ -40,6 +40,7 @@ const constants_js_1 = require("./constants.js");
|
|
|
40
40
|
const definitions_js_1 = require("./definitions.js");
|
|
41
41
|
const schema_js_1 = require("./schema.js");
|
|
42
42
|
const markdown_js_1 = require("./markdown.js");
|
|
43
|
+
const builtins_js_1 = require("./builtins.js");
|
|
43
44
|
const logger = console;
|
|
44
45
|
function toFileUrl(p) {
|
|
45
46
|
const abs = path.resolve(p);
|
|
@@ -109,10 +110,12 @@ async function loadCardInternal(cardPath, parentPath, stack = []) {
|
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
async function loadCard(cardPath, parentPath, stack = []) {
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
const builtinPath = (0, builtins_js_1.resolveBuiltinCardPath)(cardPath);
|
|
114
|
+
const normalizedPath = builtinPath ?? cardPath;
|
|
115
|
+
if ((0, markdown_js_1.isMarkdownFile)(normalizedPath)) {
|
|
116
|
+
return await (0, markdown_js_1.loadMarkdownCard)(normalizedPath, parentPath, stack);
|
|
114
117
|
}
|
|
115
|
-
return await loadCardInternal(
|
|
118
|
+
return await loadCardInternal(normalizedPath, parentPath, stack);
|
|
116
119
|
}
|
|
117
120
|
async function loadDeck(deckPath, parentPath) {
|
|
118
121
|
if ((0, markdown_js_1.isMarkdownFile)(deckPath)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/src/markdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/src/markdown.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAIV,UAAU,EACV,UAAU,EAEX,MAAM,YAAY,CAAC;AAmKpB,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,KAAK,CAAC,MAAM,CAAM,GACxB,OAAO,CAAC,UAAU,CAAC,CA8FrB;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAgLrB;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
package/script/src/markdown.js
CHANGED
|
@@ -43,10 +43,16 @@ const constants_js_1 = require("./constants.js");
|
|
|
43
43
|
const definitions_js_1 = require("./definitions.js");
|
|
44
44
|
const loader_js_1 = require("./loader.js");
|
|
45
45
|
const schema_js_1 = require("./schema.js");
|
|
46
|
+
const builtins_js_1 = require("./builtins.js");
|
|
46
47
|
const logger = console;
|
|
47
48
|
const RESPOND_MARKER = "gambit://respond";
|
|
48
49
|
const INIT_MARKER = "gambit://init";
|
|
49
50
|
const END_MARKER = "gambit://end";
|
|
51
|
+
const LEGACY_MARKER_WARNINGS = {
|
|
52
|
+
respond: false,
|
|
53
|
+
init: false,
|
|
54
|
+
end: false,
|
|
55
|
+
};
|
|
50
56
|
const INIT_TEXT = `
|
|
51
57
|
You will automatically receive a \`${constants_js_1.GAMBIT_TOOL_INIT}\` tool result at the start that provides run/context info.
|
|
52
58
|
`.trim();
|
|
@@ -56,6 +62,12 @@ When you are done, call the \`${constants_js_1.GAMBIT_TOOL_RESPOND}\` tool with
|
|
|
56
62
|
const END_TEXT = `
|
|
57
63
|
If the entire workflow is finished and no further user turns should be sent, call the \`${constants_js_1.GAMBIT_TOOL_END}\` tool with optional \`message\` and \`payload\` fields to explicitly end the session.
|
|
58
64
|
`.trim();
|
|
65
|
+
function warnLegacyMarker(marker, replacement) {
|
|
66
|
+
if (LEGACY_MARKER_WARNINGS[marker])
|
|
67
|
+
return;
|
|
68
|
+
LEGACY_MARKER_WARNINGS[marker] = true;
|
|
69
|
+
logger.warn(`[gambit] "gambit://${marker}" is deprecated; use ${replacement} instead.`);
|
|
70
|
+
}
|
|
59
71
|
function toFileUrl(p) {
|
|
60
72
|
const abs = path.resolve(p);
|
|
61
73
|
return path.toFileUrl(abs).href;
|
|
@@ -63,7 +75,9 @@ function toFileUrl(p) {
|
|
|
63
75
|
async function maybeLoadSchema(schemaPath, basePath) {
|
|
64
76
|
if (!schemaPath || typeof schemaPath !== "string")
|
|
65
77
|
return undefined;
|
|
66
|
-
const
|
|
78
|
+
const builtin = (0, builtins_js_1.resolveBuiltinSchemaPath)(schemaPath);
|
|
79
|
+
const resolved = builtin ??
|
|
80
|
+
path.resolve(path.dirname(basePath), schemaPath);
|
|
67
81
|
const mod = await Promise.resolve(`${toFileUrl(resolved)}`).then(s => __importStar(require(s)));
|
|
68
82
|
return mod.default;
|
|
69
83
|
}
|
|
@@ -125,14 +139,17 @@ async function expandEmbedsInBody(args) {
|
|
|
125
139
|
const target = match[1];
|
|
126
140
|
out += body.slice(lastIndex, matchIndex);
|
|
127
141
|
if (target === RESPOND_MARKER) {
|
|
142
|
+
warnLegacyMarker("respond", "gambit://cards/respond.card.md");
|
|
128
143
|
respond = true;
|
|
129
144
|
out += RESPOND_TEXT;
|
|
130
145
|
}
|
|
131
146
|
else if (target === INIT_MARKER) {
|
|
147
|
+
warnLegacyMarker("init", "gambit://cards/context.card.md");
|
|
132
148
|
initHint = true;
|
|
133
149
|
out += INIT_TEXT;
|
|
134
150
|
}
|
|
135
151
|
else if (target === END_MARKER) {
|
|
152
|
+
warnLegacyMarker("end", "gambit://cards/end.card.md");
|
|
136
153
|
endHint = true;
|
|
137
154
|
out += END_TEXT;
|
|
138
155
|
}
|
|
@@ -198,11 +215,13 @@ async function loadMarkdownCard(filePath, parentPath, stack = []) {
|
|
|
198
215
|
});
|
|
199
216
|
const cleanedBody = replaced.body;
|
|
200
217
|
const embeddedCards = replaced.embeds;
|
|
218
|
+
const respondFlag = Boolean(attrs.respond);
|
|
219
|
+
const allowEndFlag = Boolean(attrs.allowEnd);
|
|
201
220
|
return {
|
|
202
221
|
kind: "gambit.card",
|
|
203
222
|
path: resolved,
|
|
204
223
|
body: cleanedBody.trim(),
|
|
205
|
-
allowEnd: replaced.endHint,
|
|
224
|
+
allowEnd: allowEndFlag || replaced.endHint,
|
|
206
225
|
actionDecks,
|
|
207
226
|
actions: actionDecks,
|
|
208
227
|
testDecks: normalizeDeckRefs(attrs.testDecks, resolved),
|
|
@@ -210,7 +229,7 @@ async function loadMarkdownCard(filePath, parentPath, stack = []) {
|
|
|
210
229
|
cards: embeddedCards,
|
|
211
230
|
inputFragment,
|
|
212
231
|
outputFragment,
|
|
213
|
-
respond: replaced.respond,
|
|
232
|
+
respond: respondFlag || replaced.respond,
|
|
214
233
|
};
|
|
215
234
|
}
|
|
216
235
|
async function loadMarkdownDeck(filePath, parentPath) {
|
|
@@ -326,7 +345,9 @@ async function loadMarkdownDeck(filePath, parentPath) {
|
|
|
326
345
|
inputSchema: mergedInputSchema,
|
|
327
346
|
outputSchema: mergedOutputSchema,
|
|
328
347
|
handlers,
|
|
329
|
-
respond:
|
|
348
|
+
respond: Boolean(deckMeta.respond) ||
|
|
349
|
+
replaced.respond ||
|
|
350
|
+
allCards.some((c) => c.respond),
|
|
330
351
|
inlineEmbeds: true,
|
|
331
352
|
};
|
|
332
353
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../src/src/openai_compat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai_compat.d.ts","sourceRoot":"","sources":["../../src/src/openai_compat.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,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AChB,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;AAkPF,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,CA4JnC"}
|
|
@@ -4,6 +4,7 @@ exports.logger = void 0;
|
|
|
4
4
|
exports.chatCompletionsWithDeck = chatCompletionsWithDeck;
|
|
5
5
|
const constants_js_1 = require("./constants.js");
|
|
6
6
|
const loader_js_1 = require("./loader.js");
|
|
7
|
+
const openresponses_js_1 = require("./openresponses.js");
|
|
7
8
|
const schema_js_1 = require("./schema.js");
|
|
8
9
|
const runtime_js_1 = require("./runtime.js");
|
|
9
10
|
exports.logger = console;
|
|
@@ -33,6 +34,69 @@ function normalizeMessages(input) {
|
|
|
33
34
|
: undefined,
|
|
34
35
|
}));
|
|
35
36
|
}
|
|
37
|
+
function toChatUsage(usage) {
|
|
38
|
+
if (!usage)
|
|
39
|
+
return undefined;
|
|
40
|
+
const prompt = usage.promptTokens ?? usage.input_tokens;
|
|
41
|
+
const completion = usage.completionTokens ?? usage.output_tokens;
|
|
42
|
+
const total = usage.totalTokens ?? usage.total_tokens;
|
|
43
|
+
if (prompt === undefined && completion === undefined && total === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
prompt_tokens: prompt ?? 0,
|
|
48
|
+
completion_tokens: completion ?? 0,
|
|
49
|
+
total_tokens: total ?? 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function safeJsonArgs(str) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(str);
|
|
55
|
+
if (parsed && typeof parsed === "object") {
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// ignore bad tool args
|
|
61
|
+
}
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
function extractToolCalls(output, message) {
|
|
65
|
+
const responseCalls = output.filter((item) => item.type === "function_call");
|
|
66
|
+
if (responseCalls.length > 0) {
|
|
67
|
+
return responseCalls.map((item) => ({
|
|
68
|
+
id: item.call_id,
|
|
69
|
+
name: item.name,
|
|
70
|
+
args: safeJsonArgs(item.arguments),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
const messageCalls = message.tool_calls ?? [];
|
|
74
|
+
if (messageCalls.length === 0)
|
|
75
|
+
return undefined;
|
|
76
|
+
return messageCalls.map((call) => ({
|
|
77
|
+
id: call.id,
|
|
78
|
+
name: call.function.name,
|
|
79
|
+
args: safeJsonArgs(call.function.arguments),
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
function mergeOutputToolCalls(output, baseMessage) {
|
|
83
|
+
const responseCalls = output.filter((item) => item.type === "function_call");
|
|
84
|
+
if (responseCalls.length === 0)
|
|
85
|
+
return baseMessage;
|
|
86
|
+
return {
|
|
87
|
+
role: "assistant",
|
|
88
|
+
content: baseMessage.content ?? null,
|
|
89
|
+
name: baseMessage.name,
|
|
90
|
+
tool_calls: responseCalls.map((item) => ({
|
|
91
|
+
id: item.call_id,
|
|
92
|
+
type: "function",
|
|
93
|
+
function: {
|
|
94
|
+
name: item.name,
|
|
95
|
+
arguments: item.arguments,
|
|
96
|
+
},
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
36
100
|
function providerParamsFromRequest(req) {
|
|
37
101
|
const out = {};
|
|
38
102
|
if (req.temperature !== undefined)
|
|
@@ -174,18 +238,32 @@ async function chatCompletionsWithDeck(args) {
|
|
|
174
238
|
(() => {
|
|
175
239
|
throw new Error("No model provided");
|
|
176
240
|
})();
|
|
177
|
-
const result = await args.modelProvider.
|
|
241
|
+
const result = await args.modelProvider.responses({
|
|
178
242
|
model,
|
|
179
|
-
messages,
|
|
243
|
+
input: (0, openresponses_js_1.openResponseItemsFromMessages)(messages),
|
|
180
244
|
tools: tools.length ? tools : undefined,
|
|
181
245
|
stream: Boolean(args.request.stream),
|
|
182
|
-
|
|
246
|
+
onStreamEvent: args.onStreamText
|
|
247
|
+
? (event) => {
|
|
248
|
+
if (event.type === "response.output_text.delta") {
|
|
249
|
+
args.onStreamText?.(event.delta);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
: undefined,
|
|
183
253
|
params: providerParamsFromRequest(args.request),
|
|
184
254
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
255
|
+
const outputMessages = (0, openresponses_js_1.messagesFromOpenResponseOutput)(result.output);
|
|
256
|
+
const lastAssistantMessage = [...outputMessages].reverse().find((item) => item.role === "assistant");
|
|
257
|
+
const baseMessage = lastAssistantMessage ?? {
|
|
258
|
+
role: "assistant",
|
|
259
|
+
content: null,
|
|
260
|
+
};
|
|
261
|
+
const message = mergeOutputToolCalls(result.output, baseMessage);
|
|
262
|
+
const toolCalls = extractToolCalls(result.output, message);
|
|
263
|
+
messages.push(message);
|
|
264
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
265
|
+
const gambitCalls = toolCalls.filter((c) => gambit.toolNameSet.has(c.name));
|
|
266
|
+
const externalCalls = toolCalls.filter((c) => !gambit.toolNameSet.has(c.name));
|
|
189
267
|
if (!executeDeckTools || externalCalls.length > 0) {
|
|
190
268
|
return {
|
|
191
269
|
id: randomId("chatcmpl"),
|
|
@@ -194,17 +272,11 @@ async function chatCompletionsWithDeck(args) {
|
|
|
194
272
|
model,
|
|
195
273
|
choices: [{
|
|
196
274
|
index: 0,
|
|
197
|
-
message
|
|
275
|
+
message,
|
|
198
276
|
finish_reason: "tool_calls",
|
|
199
277
|
logprobs: null,
|
|
200
278
|
}],
|
|
201
|
-
usage: result.usage
|
|
202
|
-
? {
|
|
203
|
-
prompt_tokens: result.usage.promptTokens,
|
|
204
|
-
completion_tokens: result.usage.completionTokens,
|
|
205
|
-
total_tokens: result.usage.totalTokens,
|
|
206
|
-
}
|
|
207
|
-
: undefined,
|
|
279
|
+
usage: toChatUsage(result.usage),
|
|
208
280
|
gambit: { deckPath: deck.path, messages, runId },
|
|
209
281
|
};
|
|
210
282
|
}
|
|
@@ -248,7 +320,8 @@ async function chatCompletionsWithDeck(args) {
|
|
|
248
320
|
}
|
|
249
321
|
continue;
|
|
250
322
|
}
|
|
251
|
-
|
|
323
|
+
const finishReason = result.finishReason ?? "stop";
|
|
324
|
+
if (finishReason === "tool_calls") {
|
|
252
325
|
throw new Error("Model requested tool_calls but provided none");
|
|
253
326
|
}
|
|
254
327
|
return {
|
|
@@ -258,17 +331,11 @@ async function chatCompletionsWithDeck(args) {
|
|
|
258
331
|
model,
|
|
259
332
|
choices: [{
|
|
260
333
|
index: 0,
|
|
261
|
-
message
|
|
262
|
-
finish_reason:
|
|
334
|
+
message,
|
|
335
|
+
finish_reason: finishReason,
|
|
263
336
|
logprobs: null,
|
|
264
337
|
}],
|
|
265
|
-
usage: result.usage
|
|
266
|
-
? {
|
|
267
|
-
prompt_tokens: result.usage.promptTokens,
|
|
268
|
-
completion_tokens: result.usage.completionTokens,
|
|
269
|
-
total_tokens: result.usage.totalTokens,
|
|
270
|
-
}
|
|
271
|
-
: undefined,
|
|
338
|
+
usage: toChatUsage(result.usage),
|
|
272
339
|
gambit: { deckPath: deck.path, messages, runId },
|
|
273
340
|
};
|
|
274
341
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModelMessage, OpenResponseItem } from "./types.js";
|
|
2
|
+
export declare function openResponseItemFromMessage(message: ModelMessage): OpenResponseItem;
|
|
3
|
+
export declare function messageFromOpenResponseItem(item: OpenResponseItem): ModelMessage | null;
|
|
4
|
+
export declare function openResponseItemsFromMessages(messages: Array<ModelMessage>): Array<OpenResponseItem>;
|
|
5
|
+
export declare function messagesFromOpenResponseOutput(output: Array<OpenResponseItem>): Array<ModelMessage>;
|
|
6
|
+
//# sourceMappingURL=openresponses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openresponses.d.ts","sourceRoot":"","sources":["../../src/src/openresponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAEZ,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAmBpB,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,YAAY,GACpB,gBAAgB,CASlB;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,gBAAgB,GACrB,YAAY,GAAG,IAAI,CAwCrB;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,GAC5B,KAAK,CAAC,gBAAgB,CAAC,CAEzB;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAC9B,KAAK,CAAC,YAAY,CAAC,CAIrB"}
|