@bolt-foundry/gambit 0.6.0 → 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.
Files changed (55) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/README.md +4 -4
  3. package/esm/mod.d.ts +22 -22
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/mod.js +7 -7
  6. package/esm/src/server.d.ts +1 -1
  7. package/esm/src/server.d.ts.map +1 -1
  8. package/esm/src/server.js +2 -2
  9. package/esm/src/trace.d.ts +1 -1
  10. package/esm/src/trace.d.ts.map +1 -1
  11. package/package.json +2 -4
  12. package/script/mod.d.ts +22 -22
  13. package/script/mod.d.ts.map +1 -1
  14. package/script/mod.js +14 -14
  15. package/script/src/server.d.ts +1 -1
  16. package/script/src/server.d.ts.map +1 -1
  17. package/script/src/server.js +12 -12
  18. package/script/src/trace.d.ts +1 -1
  19. package/script/src/trace.d.ts.map +1 -1
  20. package/esm/packages/gambit-core/mod.d.ts +0 -50
  21. package/esm/packages/gambit-core/mod.d.ts.map +0 -1
  22. package/esm/packages/gambit-core/mod.js +0 -19
  23. package/esm/packages/gambit-core/src/definitions.d.ts +0 -11
  24. package/esm/packages/gambit-core/src/definitions.d.ts.map +0 -1
  25. package/esm/packages/gambit-core/src/definitions.js +0 -14
  26. package/esm/packages/gambit-core/src/openai_compat.d.ts +0 -63
  27. package/esm/packages/gambit-core/src/openai_compat.d.ts.map +0 -1
  28. package/esm/packages/gambit-core/src/openai_compat.js +0 -272
  29. package/esm/packages/gambit-core/src/providers/openrouter.d.ts +0 -8
  30. package/esm/packages/gambit-core/src/providers/openrouter.d.ts.map +0 -1
  31. package/esm/packages/gambit-core/src/providers/openrouter.js +0 -168
  32. package/esm/packages/gambit-core/src/render.d.ts +0 -51
  33. package/esm/packages/gambit-core/src/render.d.ts.map +0 -1
  34. package/esm/packages/gambit-core/src/render.js +0 -188
  35. package/esm/packages/gambit-core/src/schema.d.ts +0 -8
  36. package/esm/packages/gambit-core/src/schema.d.ts.map +0 -1
  37. package/esm/packages/gambit-core/src/schema.js +0 -45
  38. package/script/packages/gambit-core/mod.d.ts +0 -50
  39. package/script/packages/gambit-core/mod.d.ts.map +0 -1
  40. package/script/packages/gambit-core/mod.js +0 -29
  41. package/script/packages/gambit-core/src/definitions.d.ts +0 -11
  42. package/script/packages/gambit-core/src/definitions.d.ts.map +0 -1
  43. package/script/packages/gambit-core/src/definitions.js +0 -20
  44. package/script/packages/gambit-core/src/openai_compat.d.ts +0 -63
  45. package/script/packages/gambit-core/src/openai_compat.d.ts.map +0 -1
  46. package/script/packages/gambit-core/src/openai_compat.js +0 -276
  47. package/script/packages/gambit-core/src/providers/openrouter.d.ts +0 -8
  48. package/script/packages/gambit-core/src/providers/openrouter.d.ts.map +0 -1
  49. package/script/packages/gambit-core/src/providers/openrouter.js +0 -207
  50. package/script/packages/gambit-core/src/render.d.ts +0 -51
  51. package/script/packages/gambit-core/src/render.d.ts.map +0 -1
  52. package/script/packages/gambit-core/src/render.js +0 -192
  53. package/script/packages/gambit-core/src/schema.d.ts +0 -8
  54. package/script/packages/gambit-core/src/schema.d.ts.map +0 -1
  55. package/script/packages/gambit-core/src/schema.js +0 -51
@@ -1,192 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
4
- exports.renderDeck = renderDeck;
5
- const constants_1 = require("@bolt-foundry/gambit-core/internal/constants");
6
- const loader_1 = require("@bolt-foundry/gambit-core/internal/loader");
7
- const schema_js_1 = require("./schema.js");
8
- exports.logger = console;
9
- function normalizeContent(content) {
10
- if (content === null)
11
- return null;
12
- if (typeof content === "string")
13
- return content;
14
- if (!Array.isArray(content))
15
- return String(content);
16
- return content
17
- .map((c) => (typeof c === "string" ? c : (c.text ?? "")))
18
- .join("");
19
- }
20
- function normalizeMessages(input) {
21
- return input.map((m) => ({
22
- role: m.role,
23
- content: normalizeContent(m.content),
24
- name: m.name,
25
- tool_call_id: m.tool_call_id,
26
- tool_calls: m.tool_calls && m.tool_calls.length > 0
27
- ? m.tool_calls
28
- : undefined,
29
- }));
30
- }
31
- function deckSystemPrompt(deck) {
32
- const parts = [];
33
- const prompt = deck.body ?? deck.prompt;
34
- if (prompt)
35
- parts.push(prompt.trim());
36
- if (!deck.inlineEmbeds) {
37
- for (const card of deck.cards) {
38
- if (card.body)
39
- parts.push(card.body.trim());
40
- }
41
- }
42
- return parts.join("\n\n").trim();
43
- }
44
- function shouldPrependDeckSystem(messages, systemPrompt) {
45
- if (!systemPrompt)
46
- return false;
47
- if (!messages.length)
48
- return true;
49
- const hasExact = messages.some((m) => m.role === "system" && m.content === systemPrompt);
50
- return !hasExact;
51
- }
52
- function warnIfSystemMismatch(args) {
53
- if (!args.systemPrompt)
54
- return;
55
- const existing = args.provided.find((m) => m.role === "system");
56
- if (!existing)
57
- return;
58
- if (existing.content === args.systemPrompt)
59
- return;
60
- exports.logger.warn(`[gambit] renderDeck: request includes a system message that does not match the deck prompt (${args.deckPath})`);
61
- }
62
- function toolName(tool) {
63
- return tool.function?.name ?? "";
64
- }
65
- function assertNoToolNameCollisions(args) {
66
- if (!args.externalTools?.length)
67
- return;
68
- const gambit = new Set(args.gambitTools.map(toolName));
69
- for (const t of args.externalTools) {
70
- const name = toolName(t);
71
- if (!name)
72
- continue;
73
- if (name.startsWith(constants_1.RESERVED_TOOL_PREFIX)) {
74
- throw new Error(`External tool name ${name} is reserved (prefix ${constants_1.RESERVED_TOOL_PREFIX})`);
75
- }
76
- if (gambit.has(name)) {
77
- throw new Error(`Tool name collision for ${name} between Gambit deck actions and external tools`);
78
- }
79
- }
80
- }
81
- async function buildDeckActionTools(deckPath) {
82
- const deck = await (0, loader_1.loadDeck)(deckPath);
83
- const tools = [];
84
- const actionPathsByName = {};
85
- for (const action of deck.actionDecks) {
86
- const child = await (0, loader_1.loadDeck)(action.path, deck.path);
87
- if (!child.inputSchema || !child.outputSchema) {
88
- throw new Error(`Deck ${child.path} must declare inputSchema and outputSchema (non-root)`);
89
- }
90
- (0, schema_js_1.assertZodSchema)(child.inputSchema, "inputSchema");
91
- (0, schema_js_1.assertZodSchema)(child.outputSchema, "outputSchema");
92
- const params = (0, schema_js_1.toJsonSchema)(child.inputSchema);
93
- tools.push({
94
- type: "function",
95
- function: {
96
- name: action.name,
97
- description: action.description,
98
- parameters: params,
99
- },
100
- });
101
- actionPathsByName[action.name] = action.path;
102
- }
103
- return { tools, actionPathsByName };
104
- }
105
- function mergeModelParams(req, deckParams) {
106
- const out = { ...req };
107
- if (!deckParams)
108
- return out;
109
- if (out.model === undefined && deckParams.model)
110
- out.model = deckParams.model;
111
- if (out.temperature === undefined && deckParams.temperature !== undefined) {
112
- out.temperature = deckParams.temperature;
113
- }
114
- if (out.top_p === undefined && deckParams.top_p !== undefined) {
115
- out.top_p = deckParams.top_p;
116
- }
117
- if (out.frequency_penalty === undefined &&
118
- deckParams.frequency_penalty !== undefined) {
119
- out.frequency_penalty = deckParams.frequency_penalty;
120
- }
121
- if (out.presence_penalty === undefined &&
122
- deckParams.presence_penalty !== undefined) {
123
- out.presence_penalty = deckParams.presence_penalty;
124
- }
125
- if (out.max_tokens === undefined && deckParams.max_tokens !== undefined) {
126
- out.max_tokens = deckParams.max_tokens;
127
- }
128
- return out;
129
- }
130
- async function renderDeck(opts) {
131
- const includeDeckSystem = opts.includeDeckSystem ?? true;
132
- const includeDeckTools = opts.includeDeckTools ?? true;
133
- const warnOnSystemMismatch = opts.warnOnSystemMismatch ?? true;
134
- const deck = await (0, loader_1.loadDeck)(opts.deckPath);
135
- const systemPrompt = deckSystemPrompt(deck);
136
- const mergedReq = mergeModelParams(opts.request, deck.modelParams);
137
- const providedMessages = normalizeMessages(mergedReq.messages);
138
- const messages = [];
139
- if (includeDeckSystem) {
140
- if (warnOnSystemMismatch) {
141
- warnIfSystemMismatch({
142
- provided: providedMessages,
143
- systemPrompt,
144
- deckPath: deck.path,
145
- });
146
- }
147
- if (shouldPrependDeckSystem(providedMessages, systemPrompt)) {
148
- messages.push({ role: "system", content: systemPrompt });
149
- }
150
- }
151
- messages.push(...providedMessages);
152
- let tools = undefined;
153
- let actionPathsByName = {};
154
- if (includeDeckTools) {
155
- const built = await buildDeckActionTools(deck.path);
156
- actionPathsByName = built.actionPathsByName;
157
- assertNoToolNameCollisions({
158
- gambitTools: built.tools,
159
- externalTools: mergedReq.tools,
160
- });
161
- tools = mergedReq.tools?.length
162
- ? [...built.tools, ...mergedReq.tools]
163
- : built.tools;
164
- }
165
- else if (mergedReq.tools?.length) {
166
- for (const t of mergedReq.tools) {
167
- const name = toolName(t);
168
- if (name.startsWith(constants_1.RESERVED_TOOL_PREFIX)) {
169
- throw new Error(`External tool name ${name} is reserved (prefix ${constants_1.RESERVED_TOOL_PREFIX})`);
170
- }
171
- }
172
- tools = mergedReq.tools;
173
- }
174
- const model = String(mergedReq.model ?? "").trim();
175
- if (!model) {
176
- throw new Error(`renderDeck requires request.model (or deck.modelParams.model): ${deck.path}`);
177
- }
178
- const { messages: _m, tools: _t, ...rest } = mergedReq;
179
- return {
180
- request: {
181
- ...rest,
182
- model,
183
- messages,
184
- tools: tools && tools.length ? tools : undefined,
185
- },
186
- gambit: {
187
- deckPath: deck.path,
188
- systemPrompt,
189
- actionPathsByName,
190
- },
191
- };
192
- }
@@ -1,8 +0,0 @@
1
- import { z } from "zod";
2
- import type { JSONValue } from "@bolt-foundry/gambit-core/internal/types";
3
- import type { ZodTypeAny } from "zod";
4
- export declare function validateWithSchema<T>(schema: z.ZodType<T>, value: unknown): T;
5
- export declare function toJsonSchema(schema: z.ZodTypeAny): Record<string, JSONValue>;
6
- export declare function assertZodSchema(value: unknown, label: string): asserts value is z.ZodTypeAny;
7
- export declare function mergeZodObjects(base: ZodTypeAny | undefined, fragment: ZodTypeAny | undefined): ZodTypeAny | undefined;
8
- //# sourceMappingURL=schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/packages/gambit-core/src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAA0B,UAAU,EAAE,MAAM,KAAK,CAAC;AAE9D,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,OAAO,GACb,CAAC,CAUH;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAO5E;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,CAQ/B;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,QAAQ,EAAE,UAAU,GAAG,SAAS,GAC/B,UAAU,GAAG,SAAS,CAOxB"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateWithSchema = validateWithSchema;
4
- exports.toJsonSchema = toJsonSchema;
5
- exports.assertZodSchema = assertZodSchema;
6
- exports.mergeZodObjects = mergeZodObjects;
7
- const zod_1 = require("zod");
8
- const zod_to_json_schema_1 = require("zod-to-json-schema");
9
- function validateWithSchema(schema, value) {
10
- const result = schema.safeParse(value);
11
- if (!result.success) {
12
- const issue = result.error.issues?.[0];
13
- const message = issue
14
- ? `${issue.path.join(".") || "(root)"}: ${issue.message}`
15
- : result.error.message;
16
- throw new Error(`Schema validation failed: ${message}`);
17
- }
18
- return result.data;
19
- }
20
- function toJsonSchema(schema) {
21
- const converted = (0, zod_to_json_schema_1.zodToJsonSchema)(schema, { $refStrategy: "none" });
22
- if (converted && typeof converted === "object") {
23
- return converted;
24
- }
25
- // Fallback to permissive object if conversion fails
26
- return { type: "object" };
27
- }
28
- function assertZodSchema(value, label) {
29
- if (!value || typeof value !== "object") {
30
- throw new Error(`${label} must be a Zod schema`);
31
- }
32
- // Duck-typing: check for safeParse
33
- if (typeof value.safeParse !== "function") {
34
- throw new Error(`${label} must be a Zod schema (missing safeParse)`);
35
- }
36
- }
37
- function mergeZodObjects(base, fragment) {
38
- if (!fragment)
39
- return base;
40
- if (!base)
41
- return fragment;
42
- const baseObj = asZodObject(base, "base schema");
43
- const fragObj = asZodObject(fragment, "fragment schema");
44
- const mergedShape = { ...fragObj.shape, ...baseObj.shape };
45
- return zod_1.z.object(mergedShape);
46
- }
47
- function asZodObject(schema, label) {
48
- if (schema instanceof zod_1.z.ZodObject)
49
- return schema;
50
- throw new Error(`${label} must be a Zod object schema to merge fragments`);
51
- }