@bolt-foundry/gambit-core 0.8.1 → 0.8.3
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 +28 -32
- package/cards/context.card.md +5 -5
- package/cards/generate-test-input.card.md +12 -0
- package/esm/mod.d.ts +11 -9
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -5
- package/esm/src/constants.d.ts +4 -0
- package/esm/src/constants.d.ts.map +1 -1
- package/esm/src/constants.js +5 -0
- package/esm/src/definitions.d.ts +5 -1
- package/esm/src/definitions.d.ts.map +1 -1
- package/esm/src/loader.d.ts.map +1 -1
- package/esm/src/loader.js +61 -2
- package/esm/src/markdown.d.ts.map +1 -1
- package/esm/src/markdown.js +55 -12
- package/esm/src/render.d.ts.map +1 -1
- package/esm/src/render.js +22 -8
- package/esm/src/runtime.d.ts +1 -0
- package/esm/src/runtime.d.ts.map +1 -1
- package/esm/src/runtime.js +300 -41
- package/esm/src/state.d.ts +3 -1
- package/esm/src/state.d.ts.map +1 -1
- package/esm/src/state.js +48 -2
- package/esm/src/types.d.ts +149 -1
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/types.js +102 -1
- package/package.json +1 -2
- package/schemas/graders/grader_output.ts +7 -0
- package/script/mod.d.ts +11 -9
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -9
- package/script/src/constants.d.ts +4 -0
- package/script/src/constants.d.ts.map +1 -1
- package/script/src/constants.js +6 -1
- package/script/src/definitions.d.ts +5 -1
- package/script/src/definitions.d.ts.map +1 -1
- package/script/src/loader.d.ts.map +1 -1
- package/script/src/loader.js +61 -2
- package/script/src/markdown.d.ts.map +1 -1
- package/script/src/markdown.js +54 -11
- package/script/src/render.d.ts.map +1 -1
- package/script/src/render.js +22 -8
- package/script/src/runtime.d.ts +1 -0
- package/script/src/runtime.d.ts.map +1 -1
- package/script/src/runtime.js +299 -40
- package/script/src/state.d.ts +3 -1
- package/script/src/state.d.ts.map +1 -1
- package/script/src/state.js +48 -2
- package/script/src/types.d.ts +149 -1
- package/script/src/types.d.ts.map +1 -1
- package/script/src/types.js +103 -0
- package/esm/src/openai_compat.d.ts +0 -63
- package/esm/src/openai_compat.d.ts.map +0 -1
- package/esm/src/openai_compat.js +0 -272
- 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/openai_compat.d.ts +0 -63
- package/script/src/openai_compat.d.ts.map +0 -1
- package/script/src/openai_compat.js +0 -276
- 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/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Core runtime, definitions, and utilities for building Gambit decks outside of
|
|
4
4
|
the CLI. It includes the loader for Markdown/TypeScript decks, guardrail-aware
|
|
5
|
-
execution,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
execution, and helpers for persisting local run state. The
|
|
6
|
+
[`@bolt-foundry/gambit`](../gambit/README.md) package re-exports these APIs plus
|
|
7
|
+
the CLI, but `gambit-core` stays focused on the authoring/runtime pieces that
|
|
8
|
+
can live in any host.
|
|
9
9
|
|
|
10
10
|
> **Gambit vs. Gambit Core**
|
|
11
11
|
>
|
|
@@ -22,13 +22,13 @@ authoring/runtime pieces that can live in any host.
|
|
|
22
22
|
|
|
23
23
|
- Typed deck/card definitions with [`defineDeck`](src/definitions.ts) and
|
|
24
24
|
[`defineCard`](src/definitions.ts) that enforce Zod
|
|
25
|
-
`
|
|
25
|
+
`contextSchema`/`responseSchema`.
|
|
26
26
|
- Loader that understands Markdown decks/cards, inline embeds, and companion
|
|
27
27
|
decks (`actionDecks`, `testDecks`, `graderDecks`).
|
|
28
28
|
- Guardrail-aware runtime (`runDeck`) that can mix LLM actions and pure compute
|
|
29
29
|
decks with structured tracing and execution context helpers.
|
|
30
|
-
-
|
|
31
|
-
|
|
30
|
+
- Response-first runtime helpers that plug into any model provider implementing
|
|
31
|
+
the core `ModelProvider` interface.
|
|
32
32
|
- State utilities (`loadState`/`saveState`) used by the Gambit simulator for
|
|
33
33
|
local-first transcripts, feedback, and notes.
|
|
34
34
|
|
|
@@ -58,13 +58,13 @@ etc.).
|
|
|
58
58
|
|
|
59
59
|
## Core concepts
|
|
60
60
|
|
|
61
|
-
- **Decks**: The primary executable unit. Decks declare a label,
|
|
62
|
-
`
|
|
63
|
-
(actions/tests/graders). Decks with `modelParams` render
|
|
64
|
-
with `run`/`execute` are compute-only.
|
|
61
|
+
- **Decks**: The primary executable unit. Decks declare a label,
|
|
62
|
+
`contextSchema`, `responseSchema`, optional `body`/`prompt`, handler hooks,
|
|
63
|
+
and companion decks (actions/tests/graders). Decks with `modelParams` render
|
|
64
|
+
prompts, while decks with `run`/`execute` are compute-only.
|
|
65
65
|
- **Cards**: Reusable prompt fragments or schema fragments that can be embedded
|
|
66
66
|
within decks or other cards. Cards can contribute
|
|
67
|
-
`
|
|
67
|
+
`contextFragment`/`responseFragment` that merge into a parent deck’s schema.
|
|
68
68
|
- **Guardrails**: Limit recursion with `maxDepth`, `maxPasses`, and `timeoutMs`.
|
|
69
69
|
Decks can override guardrails per definition; `runDeck` enforces them while
|
|
70
70
|
spawning child decks.
|
|
@@ -86,8 +86,8 @@ import { z } from "zod";
|
|
|
86
86
|
|
|
87
87
|
export default defineDeck({
|
|
88
88
|
label: "Hello World",
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
contextSchema: z.object({ user: z.string() }),
|
|
90
|
+
responseSchema: z.object({ reply: z.string() }),
|
|
91
91
|
body: `
|
|
92
92
|
You are a helpful assistant that greets the user by name.
|
|
93
93
|
`,
|
|
@@ -107,7 +107,7 @@ import { z } from "zod";
|
|
|
107
107
|
|
|
108
108
|
export default defineCard({
|
|
109
109
|
label: "Shared context",
|
|
110
|
-
|
|
110
|
+
contextFragment: z.object({ customerId: z.string().uuid() }),
|
|
111
111
|
body: "Always double check the account number before responding.",
|
|
112
112
|
});
|
|
113
113
|
```
|
|
@@ -161,8 +161,8 @@ Embedded cards or system hints can be referenced with markdown image syntax.
|
|
|
161
161
|
```
|
|
162
162
|
---
|
|
163
163
|
label: Support Triage
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
contextSchema: ./schemas/triage_input.ts
|
|
165
|
+
responseSchema: ./schemas/triage_output.ts
|
|
166
166
|
actionDecks:
|
|
167
167
|
- name: escalate
|
|
168
168
|
description: Escalate to a manager
|
|
@@ -181,25 +181,22 @@ clarifying questions before choosing an action.
|
|
|
181
181
|
`loadDeck` normalizes relative paths, merges card fragments, enforces unique
|
|
182
182
|
action names, and warns about deprecated fields (`actions`,
|
|
183
183
|
`handlers.onInterval`, `intervalMs`). The Markdown loader also injects helper
|
|
184
|
-
text for built-in tools like `
|
|
185
|
-
when you add `gambit://` markers.
|
|
184
|
+
text for built-in tools like `gambit_context`, `gambit_respond`, and
|
|
185
|
+
`gambit_end` when you add `gambit://` markers.
|
|
186
186
|
|
|
187
187
|
## Compatibility and utilities
|
|
188
188
|
|
|
189
|
-
- **Chat Completions bridge**: [`chatCompletionsWithDeck`](src/openai_compat.ts)
|
|
190
|
-
lets you present a single deck as an OpenAI-compatible endpoint. It normalizes
|
|
191
|
-
tool calls, enforces deck schemas, and returns Chat Completions–shaped
|
|
192
|
-
responses with a `gambit` metadata extension.
|
|
193
189
|
- **Request rendering**: [`renderDeck`](src/render.ts) merges an existing Chat
|
|
194
190
|
Completions request with the deck’s system prompt and tool schema, so you can
|
|
195
191
|
debug what will actually reach the model or feed it into another orchestrator.
|
|
196
|
-
- **Model providers**:
|
|
197
|
-
|
|
198
|
-
|
|
192
|
+
- **Model providers**: adapters live in `@bolt-foundry/gambit` (see
|
|
193
|
+
`packages/gambit/src/providers/openrouter.ts`). Implement your own provider by
|
|
194
|
+
conforming to the `responses()` signature in `ModelProvider`.
|
|
199
195
|
- **Constants**:
|
|
200
|
-
[`
|
|
201
|
-
|
|
202
|
-
responds, and explicitly
|
|
196
|
+
[`GAMBIT_TOOL_CONTEXT`, `GAMBIT_TOOL_RESPOND`, `GAMBIT_TOOL_END`](src/constants.ts)
|
|
197
|
+
(`GAMBIT_TOOL_INIT` remains as a deprecated alias). define the reserved tool
|
|
198
|
+
names the runtime expects when the assistant starts, responds, and explicitly
|
|
199
|
+
ends runs.
|
|
203
200
|
|
|
204
201
|
## Persisted state and traces
|
|
205
202
|
|
|
@@ -223,6 +220,5 @@ deno task test # run unit tests (allowing net/fs as required)
|
|
|
223
220
|
deno task build_npm # emit the npm bundle via dnt
|
|
224
221
|
```
|
|
225
222
|
|
|
226
|
-
Tests exercise the Markdown loader, renderer,
|
|
227
|
-
|
|
228
|
-
necessary.
|
|
223
|
+
Tests exercise the Markdown loader, renderer, and runtime guardrails. Update
|
|
224
|
+
snapshots/fixtures via `deno test -- --update` when necessary.
|
package/cards/context.card.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
label = "Gambit context primer"
|
|
3
3
|
+++
|
|
4
4
|
|
|
5
|
-
You will automatically receive a `
|
|
6
|
-
run whenever the caller supplies `--context` (formerly `--init`). This
|
|
7
|
-
contains run metadata or seeded inputs. Read it before you respond,
|
|
8
|
-
trusted context, and keep it on hand throughout the workflow so
|
|
9
|
-
actions have the right data.
|
|
5
|
+
You will automatically receive a `gambit_context` tool result at the start of
|
|
6
|
+
the run whenever the caller supplies `--context` (formerly `--init`). This
|
|
7
|
+
payload contains run metadata or seeded inputs. Read it before you respond,
|
|
8
|
+
treat it as trusted context, and keep it on hand throughout the workflow so
|
|
9
|
+
downstream actions have the right data.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
+++
|
|
2
|
+
label = "Generate test input"
|
|
3
|
+
+++
|
|
4
|
+
|
|
5
|
+
When you receive a user message with:
|
|
6
|
+
|
|
7
|
+
{ "type": "gambit_test_bot_init_fill", "missing": ["path.to.field", "..."],
|
|
8
|
+
"current": { ... }, "schemaHints": [ ... ] }
|
|
9
|
+
|
|
10
|
+
Return ONLY valid JSON that supplies values for the missing fields. Do not
|
|
11
|
+
include any fields that are not listed in "missing". If the only missing path is
|
|
12
|
+
"(root)", return the full init JSON value.
|
package/esm/mod.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ 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 payload types. */
|
|
30
|
+
export type { CreateResponseRequest, CreateResponseResponse, ResponseEvent, ResponseFunctionCallItem, ResponseFunctionCallOutputItem, ResponseItem, ResponseMessageItem, ResponseTextContent, ResponseToolChoice, ResponseToolDefinition, ResponseUsage, } from "./src/types.js";
|
|
29
31
|
/** Test deck definition shape. */
|
|
30
32
|
export type { TestDeckDefinition } from "./src/types.js";
|
|
31
33
|
/** Check if a value is an explicit end-of-run signal. */
|
|
@@ -34,22 +36,20 @@ export { isGambitEndSignal } from "./src/runtime.js";
|
|
|
34
36
|
export { runDeck } from "./src/runtime.js";
|
|
35
37
|
/** Signal for explicitly ending a Gambit run. */
|
|
36
38
|
export type { GambitEndSignal } from "./src/runtime.js";
|
|
37
|
-
/**
|
|
38
|
-
export {
|
|
39
|
-
/**
|
|
40
|
-
export
|
|
41
|
-
/** OpenAI-compatible response payload. */
|
|
42
|
-
export type { ChatCompletionsResponse } from "./src/openai_compat.js";
|
|
39
|
+
/** Default guardrail settings applied to deck runs. */
|
|
40
|
+
export { DEFAULT_GUARDRAILS } from "./src/constants.js";
|
|
41
|
+
/** Reserved tool name prefix for Gambit tools. */
|
|
42
|
+
export { RESERVED_TOOL_PREFIX } from "./src/constants.js";
|
|
43
43
|
/** Render a deck to a human-readable outline or debug view. */
|
|
44
44
|
export { renderDeck } from "./src/render.js";
|
|
45
45
|
/** Options for deck rendering. */
|
|
46
46
|
export type { RenderDeckOptions } from "./src/render.js";
|
|
47
47
|
/** Result data from rendering a deck. */
|
|
48
48
|
export type { RenderDeckResult } from "./src/render.js";
|
|
49
|
-
/**
|
|
50
|
-
export {
|
|
49
|
+
/** Schema helpers for ensuring Zod input/output shapes. */
|
|
50
|
+
export { assertZodSchema, toJsonSchema } from "./src/schema.js";
|
|
51
51
|
/** Gambit CLI helpers and internal primitives. */
|
|
52
|
-
export { GAMBIT_TOOL_INIT } from "./src/constants.js";
|
|
52
|
+
export { GAMBIT_TOOL_CONTEXT, GAMBIT_TOOL_INIT } from "./src/constants.js";
|
|
53
53
|
/** Load a deck definition from disk. */
|
|
54
54
|
export { loadDeck } from "./src/loader.js";
|
|
55
55
|
/** Persisted run state stored on disk. */
|
|
@@ -64,6 +64,8 @@ export type { LoadedDeck } from "./src/types.js";
|
|
|
64
64
|
export type { ModelMessage } from "./src/types.js";
|
|
65
65
|
/** Model provider interface for LLM backends. */
|
|
66
66
|
export type { ModelProvider } from "./src/types.js";
|
|
67
|
+
/** Tool definition passed to model providers. */
|
|
68
|
+
export type { ToolDefinition } from "./src/types.js";
|
|
67
69
|
/** Trace events emitted during execution. */
|
|
68
70
|
export type { TraceEvent } from "./src/types.js";
|
|
69
71
|
//# sourceMappingURL=mod.d.ts.map
|
package/esm/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,6BAA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AAChE,kDAAkD;AAClD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,wCAAwC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,0CAA0C;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,iCAAiC;AACjC,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,4CAA4C;AAC5C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,sDAAsD;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,8CAA8C;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,iDAAiD;AACjD,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,iDAAiD;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,6CAA6C;AAC7C,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
package/esm/mod.js
CHANGED
|
@@ -12,14 +12,16 @@ export { defineDeck } from "./src/definitions.js";
|
|
|
12
12
|
export { isGambitEndSignal } from "./src/runtime.js";
|
|
13
13
|
/** Run a deck and return its execution result. */
|
|
14
14
|
export { runDeck } from "./src/runtime.js";
|
|
15
|
-
/**
|
|
16
|
-
export {
|
|
15
|
+
/** Default guardrail settings applied to deck runs. */
|
|
16
|
+
export { DEFAULT_GUARDRAILS } from "./src/constants.js";
|
|
17
|
+
/** Reserved tool name prefix for Gambit tools. */
|
|
18
|
+
export { RESERVED_TOOL_PREFIX } from "./src/constants.js";
|
|
17
19
|
/** Render a deck to a human-readable outline or debug view. */
|
|
18
20
|
export { renderDeck } from "./src/render.js";
|
|
19
|
-
/**
|
|
20
|
-
export {
|
|
21
|
+
/** Schema helpers for ensuring Zod input/output shapes. */
|
|
22
|
+
export { assertZodSchema, toJsonSchema } from "./src/schema.js";
|
|
21
23
|
/** Gambit CLI helpers and internal primitives. */
|
|
22
|
-
export { GAMBIT_TOOL_INIT } from "./src/constants.js";
|
|
24
|
+
export { GAMBIT_TOOL_CONTEXT, GAMBIT_TOOL_INIT } from "./src/constants.js";
|
|
23
25
|
/** Load a deck definition from disk. */
|
|
24
26
|
export { loadDeck } from "./src/loader.js";
|
|
25
27
|
/** Persisted run state stored on disk. */
|
package/esm/src/constants.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare const DEFAULT_GUARDRAILS: {
|
|
|
6
6
|
export declare const RESERVED_TOOL_PREFIX = "gambit_";
|
|
7
7
|
export declare const TOOL_NAME_PATTERN: RegExp;
|
|
8
8
|
export declare const MAX_TOOL_NAME_LENGTH = 64;
|
|
9
|
+
export declare const GAMBIT_TOOL_CONTEXT = "gambit_context";
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use GAMBIT_TOOL_CONTEXT instead.
|
|
12
|
+
*/
|
|
9
13
|
export declare const GAMBIT_TOOL_INIT = "gambit_init";
|
|
10
14
|
export declare const GAMBIT_TOOL_RESPOND = "gambit_respond";
|
|
11
15
|
export declare const GAMBIT_TOOL_COMPLETE = "gambit_complete";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAC;AAEX,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAC9C,eAAO,MAAM,iBAAiB,QAA6B,CAAC;AAC5D,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAC;AAEX,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAC9C,eAAO,MAAM,iBAAiB,QAA6B,CAAC;AAC5D,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD;;GAEG;AACH,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CAMpD,CAAC;AAGH,eAAO,MAAM,uBAAuB,MAAM,CAAC"}
|
package/esm/src/constants.js
CHANGED
|
@@ -6,11 +6,16 @@ export const DEFAULT_GUARDRAILS = {
|
|
|
6
6
|
export const RESERVED_TOOL_PREFIX = "gambit_";
|
|
7
7
|
export const TOOL_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
8
8
|
export const MAX_TOOL_NAME_LENGTH = 64;
|
|
9
|
+
export const GAMBIT_TOOL_CONTEXT = "gambit_context";
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use GAMBIT_TOOL_CONTEXT instead.
|
|
12
|
+
*/
|
|
9
13
|
export const GAMBIT_TOOL_INIT = "gambit_init";
|
|
10
14
|
export const GAMBIT_TOOL_RESPOND = "gambit_respond";
|
|
11
15
|
export const GAMBIT_TOOL_COMPLETE = "gambit_complete";
|
|
12
16
|
export const GAMBIT_TOOL_END = "gambit_end";
|
|
13
17
|
export const BUILTIN_TOOL_NAME_SET = new Set([
|
|
18
|
+
GAMBIT_TOOL_CONTEXT,
|
|
14
19
|
GAMBIT_TOOL_INIT,
|
|
15
20
|
GAMBIT_TOOL_RESPOND,
|
|
16
21
|
GAMBIT_TOOL_COMPLETE,
|
package/esm/src/definitions.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { CardDefinition, DeckDefinition } from "./types.js";
|
|
2
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"> & {
|
|
3
|
+
export declare function defineDeck<InputSchema extends z.ZodTypeAny, OutputSchema extends z.ZodTypeAny | undefined = undefined>(def: Omit<DeckDefinition<z.infer<InputSchema>>, "kind" | "contextSchema" | "responseSchema" | "inputSchema" | "outputSchema"> & {
|
|
4
|
+
contextSchema: InputSchema;
|
|
5
|
+
responseSchema?: OutputSchema;
|
|
6
|
+
}): DeckDefinition<z.infer<InputSchema>>;
|
|
7
|
+
export declare function defineDeck<InputSchema extends z.ZodTypeAny, OutputSchema extends z.ZodTypeAny | undefined = undefined>(def: Omit<DeckDefinition<z.infer<InputSchema>>, "kind" | "contextSchema" | "responseSchema" | "inputSchema" | "outputSchema"> & {
|
|
4
8
|
inputSchema: InputSchema;
|
|
5
9
|
outputSchema?: OutputSchema;
|
|
6
10
|
}): DeckDefinition<z.infer<InputSchema>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,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,W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AAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE"}
|
package/esm/src/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAgMpB,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,CAsIrB"}
|
package/esm/src/loader.js
CHANGED
|
@@ -5,6 +5,54 @@ import { mergeZodObjects } from "./schema.js";
|
|
|
5
5
|
import { isMarkdownFile, loadMarkdownCard, loadMarkdownDeck, } from "./markdown.js";
|
|
6
6
|
import { resolveBuiltinCardPath } from "./builtins.js";
|
|
7
7
|
const logger = console;
|
|
8
|
+
const LEGACY_SCHEMA_WARNINGS = new Set();
|
|
9
|
+
const LEGACY_FRAGMENT_WARNINGS = new Set();
|
|
10
|
+
function warnLegacySchema(resolvedPath, legacy, replacement) {
|
|
11
|
+
const key = `${resolvedPath}:${legacy}`;
|
|
12
|
+
if (LEGACY_SCHEMA_WARNINGS.has(key))
|
|
13
|
+
return;
|
|
14
|
+
LEGACY_SCHEMA_WARNINGS.add(key);
|
|
15
|
+
logger.warn(`[gambit] deck at ${resolvedPath} uses deprecated "${legacy}"; rename to "${replacement}"`);
|
|
16
|
+
}
|
|
17
|
+
function warnLegacyFragment(resolvedPath, legacy, replacement) {
|
|
18
|
+
const key = `${resolvedPath}:${legacy}`;
|
|
19
|
+
if (LEGACY_FRAGMENT_WARNINGS.has(key))
|
|
20
|
+
return;
|
|
21
|
+
LEGACY_FRAGMENT_WARNINGS.add(key);
|
|
22
|
+
logger.warn(`[gambit] card at ${resolvedPath} uses deprecated "${legacy}"; rename to "${replacement}"`);
|
|
23
|
+
}
|
|
24
|
+
function normalizeDeckSchemas(deck, resolvedPath) {
|
|
25
|
+
if (deck.inputSchema !== undefined) {
|
|
26
|
+
warnLegacySchema(resolvedPath, "inputSchema", "contextSchema");
|
|
27
|
+
}
|
|
28
|
+
if (deck.outputSchema !== undefined) {
|
|
29
|
+
warnLegacySchema(resolvedPath, "outputSchema", "responseSchema");
|
|
30
|
+
}
|
|
31
|
+
const contextSchema = deck.contextSchema ?? deck.inputSchema;
|
|
32
|
+
const responseSchema = deck.responseSchema ?? deck.outputSchema;
|
|
33
|
+
return {
|
|
34
|
+
contextSchema,
|
|
35
|
+
responseSchema,
|
|
36
|
+
inputSchema: contextSchema,
|
|
37
|
+
outputSchema: responseSchema,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function normalizeCardFragments(card, resolvedPath) {
|
|
41
|
+
if (card.inputFragment !== undefined) {
|
|
42
|
+
warnLegacyFragment(resolvedPath, "inputFragment", "contextFragment");
|
|
43
|
+
}
|
|
44
|
+
if (card.outputFragment !== undefined) {
|
|
45
|
+
warnLegacyFragment(resolvedPath, "outputFragment", "responseFragment");
|
|
46
|
+
}
|
|
47
|
+
const contextFragment = card.contextFragment ?? card.inputFragment;
|
|
48
|
+
const responseFragment = card.responseFragment ?? card.outputFragment;
|
|
49
|
+
return {
|
|
50
|
+
contextFragment,
|
|
51
|
+
responseFragment,
|
|
52
|
+
inputFragment: contextFragment,
|
|
53
|
+
outputFragment: responseFragment,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
8
56
|
function toFileUrl(p) {
|
|
9
57
|
const abs = path.resolve(p);
|
|
10
58
|
return path.toFileUrl(abs).href;
|
|
@@ -61,6 +109,7 @@ async function loadCardInternal(cardPath, parentPath, stack = []) {
|
|
|
61
109
|
const graderDecks = normalizeCompanionDecks(card.graderDecks, resolved);
|
|
62
110
|
actionDecks.forEach(checkReserved);
|
|
63
111
|
const { label: _l, ...rest } = card;
|
|
112
|
+
const fragments = normalizeCardFragments(card, resolved);
|
|
64
113
|
return {
|
|
65
114
|
...rest,
|
|
66
115
|
label: cardLabel,
|
|
@@ -70,6 +119,7 @@ async function loadCardInternal(cardPath, parentPath, stack = []) {
|
|
|
70
119
|
graderDecks,
|
|
71
120
|
path: resolved,
|
|
72
121
|
cards: [],
|
|
122
|
+
...fragments,
|
|
73
123
|
};
|
|
74
124
|
}
|
|
75
125
|
export async function loadCard(cardPath, parentPath, stack = []) {
|
|
@@ -111,12 +161,19 @@ export async function loadDeck(deckPath, parentPath) {
|
|
|
111
161
|
mergedActions[action.name] = action;
|
|
112
162
|
}
|
|
113
163
|
const actionDecks = Object.values(mergedActions);
|
|
114
|
-
|
|
115
|
-
let
|
|
164
|
+
const schemaAliases = normalizeDeckSchemas(deck, resolved);
|
|
165
|
+
let inputSchema = schemaAliases.inputSchema;
|
|
166
|
+
let outputSchema = schemaAliases.outputSchema;
|
|
167
|
+
let contextSchema = schemaAliases.contextSchema;
|
|
168
|
+
let responseSchema = schemaAliases.responseSchema;
|
|
116
169
|
for (const card of allCards) {
|
|
117
170
|
inputSchema = mergeZodObjects(inputSchema, card.inputFragment);
|
|
118
171
|
outputSchema = mergeZodObjects(outputSchema, card.outputFragment);
|
|
172
|
+
contextSchema = mergeZodObjects(contextSchema, card.contextFragment);
|
|
173
|
+
responseSchema = mergeZodObjects(responseSchema, card.responseFragment);
|
|
119
174
|
}
|
|
175
|
+
inputSchema = contextSchema;
|
|
176
|
+
outputSchema = responseSchema;
|
|
120
177
|
const executor = typeof deck.run === "function"
|
|
121
178
|
? deck.run
|
|
122
179
|
: typeof deck.execute === "function"
|
|
@@ -163,6 +220,8 @@ export async function loadDeck(deckPath, parentPath) {
|
|
|
163
220
|
actions: actionDecks,
|
|
164
221
|
testDecks: normalizeCompanionDecks(deck.testDecks, resolved),
|
|
165
222
|
graderDecks: normalizeCompanionDecks(deck.graderDecks, resolved),
|
|
223
|
+
contextSchema,
|
|
224
|
+
responseSchema,
|
|
166
225
|
inputSchema,
|
|
167
226
|
outputSchema,
|
|
168
227
|
executor,
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA+LpB,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,KAAK,CAAC,MAAM,CAAM,GACxB,OAAO,CAAC,UAAU,CAAC,CA0GrB;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAgMrB;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
package/esm/src/markdown.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
2
|
import { extract } from "../deps/jsr.io/@std/front-matter/1.0.9/any.js";
|
|
3
3
|
import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js";
|
|
4
|
-
import { BUILTIN_TOOL_NAME_SET,
|
|
4
|
+
import { BUILTIN_TOOL_NAME_SET, GAMBIT_TOOL_CONTEXT, GAMBIT_TOOL_END, GAMBIT_TOOL_RESPOND, MAX_TOOL_NAME_LENGTH, RESERVED_TOOL_PREFIX, TOOL_NAME_PATTERN, } from "./constants.js";
|
|
5
5
|
import { isCardDefinition } from "./definitions.js";
|
|
6
6
|
import { loadCard } from "./loader.js";
|
|
7
7
|
import { mergeZodObjects } from "./schema.js";
|
|
@@ -15,8 +15,10 @@ const LEGACY_MARKER_WARNINGS = {
|
|
|
15
15
|
init: false,
|
|
16
16
|
end: false,
|
|
17
17
|
};
|
|
18
|
+
const LEGACY_SCHEMA_WARNINGS = new Set();
|
|
19
|
+
const LEGACY_FRAGMENT_WARNINGS = new Set();
|
|
18
20
|
const INIT_TEXT = `
|
|
19
|
-
You will automatically receive a \`${
|
|
21
|
+
You will automatically receive a \`${GAMBIT_TOOL_CONTEXT}\` tool result at the start that provides run/context info.
|
|
20
22
|
`.trim();
|
|
21
23
|
const RESPOND_TEXT = `
|
|
22
24
|
When you are done, call the \`${GAMBIT_TOOL_RESPOND}\` tool with a JSON object that includes your \`payload\` (validated output) and optional \`status\`/ \`message\`/ \`code\`/ \`meta\`. Do not end with normal assistant text; always finish by calling \`${GAMBIT_TOOL_RESPOND}\`.
|
|
@@ -30,6 +32,20 @@ function warnLegacyMarker(marker, replacement) {
|
|
|
30
32
|
LEGACY_MARKER_WARNINGS[marker] = true;
|
|
31
33
|
logger.warn(`[gambit] "gambit://${marker}" is deprecated; use ${replacement} instead.`);
|
|
32
34
|
}
|
|
35
|
+
function warnLegacySchema(resolvedPath, legacy, replacement) {
|
|
36
|
+
const key = `${resolvedPath}:${legacy}`;
|
|
37
|
+
if (LEGACY_SCHEMA_WARNINGS.has(key))
|
|
38
|
+
return;
|
|
39
|
+
LEGACY_SCHEMA_WARNINGS.add(key);
|
|
40
|
+
logger.warn(`[gambit] deck at ${resolvedPath} uses deprecated "${legacy}"; rename to "${replacement}"`);
|
|
41
|
+
}
|
|
42
|
+
function warnLegacyFragment(resolvedPath, legacy, replacement) {
|
|
43
|
+
const key = `${resolvedPath}:${legacy}`;
|
|
44
|
+
if (LEGACY_FRAGMENT_WARNINGS.has(key))
|
|
45
|
+
return;
|
|
46
|
+
LEGACY_FRAGMENT_WARNINGS.add(key);
|
|
47
|
+
logger.warn(`[gambit] card at ${resolvedPath} uses deprecated "${legacy}"; rename to "${replacement}"`);
|
|
48
|
+
}
|
|
33
49
|
function toFileUrl(p) {
|
|
34
50
|
const abs = path.resolve(p);
|
|
35
51
|
return path.toFileUrl(abs).href;
|
|
@@ -168,8 +184,18 @@ export async function loadMarkdownCard(filePath, parentPath, stack = []) {
|
|
|
168
184
|
throw new Error(`Action name ${a.name} must match ${TOOL_NAME_PATTERN} and be <= ${MAX_TOOL_NAME_LENGTH} characters`);
|
|
169
185
|
}
|
|
170
186
|
});
|
|
171
|
-
const
|
|
172
|
-
const
|
|
187
|
+
const legacyInputSchema = attrs.inputSchema;
|
|
188
|
+
const legacyOutputSchema = attrs.outputSchema;
|
|
189
|
+
const contextFragment = await maybeLoadSchema(attrs.contextFragment ??
|
|
190
|
+
legacyInputSchema, resolved);
|
|
191
|
+
const responseFragment = await maybeLoadSchema(attrs.responseFragment ??
|
|
192
|
+
legacyOutputSchema, resolved);
|
|
193
|
+
if (legacyInputSchema !== undefined) {
|
|
194
|
+
warnLegacyFragment(resolved, "inputSchema", "contextFragment");
|
|
195
|
+
}
|
|
196
|
+
if (legacyOutputSchema !== undefined) {
|
|
197
|
+
warnLegacyFragment(resolved, "outputSchema", "responseFragment");
|
|
198
|
+
}
|
|
173
199
|
const replaced = await expandEmbedsInBody({
|
|
174
200
|
body,
|
|
175
201
|
resolvedPath: resolved,
|
|
@@ -189,8 +215,10 @@ export async function loadMarkdownCard(filePath, parentPath, stack = []) {
|
|
|
189
215
|
testDecks: normalizeDeckRefs(attrs.testDecks, resolved),
|
|
190
216
|
graderDecks: normalizeDeckRefs(attrs.graderDecks, resolved),
|
|
191
217
|
cards: embeddedCards,
|
|
192
|
-
|
|
193
|
-
|
|
218
|
+
contextFragment,
|
|
219
|
+
responseFragment,
|
|
220
|
+
inputFragment: contextFragment,
|
|
221
|
+
outputFragment: responseFragment,
|
|
194
222
|
respond: respondFlag || replaced.respond,
|
|
195
223
|
};
|
|
196
224
|
}
|
|
@@ -233,8 +261,18 @@ export async function loadMarkdownDeck(filePath, parentPath) {
|
|
|
233
261
|
stack: [resolved],
|
|
234
262
|
});
|
|
235
263
|
const cards = replaced.embeds;
|
|
236
|
-
const
|
|
237
|
-
const
|
|
264
|
+
const legacyInputSchema = deckMeta.inputSchema;
|
|
265
|
+
const legacyOutputSchema = deckMeta.outputSchema;
|
|
266
|
+
const contextSchema = await maybeLoadSchema(deckMeta.contextSchema ??
|
|
267
|
+
legacyInputSchema, resolved);
|
|
268
|
+
const responseSchema = await maybeLoadSchema(deckMeta.responseSchema ??
|
|
269
|
+
legacyOutputSchema, resolved);
|
|
270
|
+
if (legacyInputSchema !== undefined) {
|
|
271
|
+
warnLegacySchema(resolved, "inputSchema", "contextSchema");
|
|
272
|
+
}
|
|
273
|
+
if (legacyOutputSchema !== undefined) {
|
|
274
|
+
warnLegacySchema(resolved, "outputSchema", "responseSchema");
|
|
275
|
+
}
|
|
238
276
|
const allCards = flattenCards(cards);
|
|
239
277
|
const cleanedBody = replaced.body;
|
|
240
278
|
const allowEnd = Boolean(deckMeta.allowEnd) ||
|
|
@@ -249,12 +287,14 @@ export async function loadMarkdownDeck(filePath, parentPath) {
|
|
|
249
287
|
for (const action of actionDecks) {
|
|
250
288
|
mergedActions[action.name] = action;
|
|
251
289
|
}
|
|
252
|
-
let
|
|
253
|
-
let
|
|
290
|
+
let mergedContextSchema = contextSchema;
|
|
291
|
+
let mergedResponseSchema = responseSchema;
|
|
254
292
|
for (const card of allCards) {
|
|
255
|
-
|
|
256
|
-
|
|
293
|
+
mergedContextSchema = mergeZodObjects(mergedContextSchema, card.contextFragment);
|
|
294
|
+
mergedResponseSchema = mergeZodObjects(mergedResponseSchema, card.responseFragment);
|
|
257
295
|
}
|
|
296
|
+
const mergedInputSchema = mergedContextSchema;
|
|
297
|
+
const mergedOutputSchema = mergedResponseSchema;
|
|
258
298
|
const normalizeHandler = (cfg, kind) => {
|
|
259
299
|
if (!cfg)
|
|
260
300
|
return undefined;
|
|
@@ -302,8 +342,11 @@ export async function loadMarkdownDeck(filePath, parentPath) {
|
|
|
302
342
|
graderDecks: mergeDeckRefs(rootGraderDecks, embeddedGraderDecks),
|
|
303
343
|
cards: allCards,
|
|
304
344
|
label: deckMeta.label,
|
|
345
|
+
startMode: deckMeta.startMode,
|
|
305
346
|
modelParams: deckMeta.modelParams,
|
|
306
347
|
guardrails: deckMeta.guardrails,
|
|
348
|
+
contextSchema: mergedContextSchema,
|
|
349
|
+
responseSchema: mergedResponseSchema,
|
|
307
350
|
inputSchema: mergedInputSchema,
|
|
308
351
|
outputSchema: mergedOutputSchema,
|
|
309
352
|
handlers,
|
package/esm/src/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/src/render.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/src/render.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,YAAY,EAEZ,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,MAAM,SAAU,CAAC;AAE9B,MAAM,MAAM,4BAA4B,GAAG;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,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,EA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;KACxB,CAAC;IACF,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC3C,CAAC;CACH,CAAC;AA6KF,wBAAsB,UAAU,CAC9B,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,gBAAgB,CAAC,CA+E3B"}
|
package/esm/src/render.js
CHANGED
|
@@ -58,6 +58,12 @@ function warnIfSystemMismatch(args) {
|
|
|
58
58
|
function toolName(tool) {
|
|
59
59
|
return tool.function?.name ?? "";
|
|
60
60
|
}
|
|
61
|
+
function resolveContextSchema(deck) {
|
|
62
|
+
return deck.contextSchema ?? deck.inputSchema;
|
|
63
|
+
}
|
|
64
|
+
function resolveResponseSchema(deck) {
|
|
65
|
+
return deck.responseSchema ?? deck.outputSchema;
|
|
66
|
+
}
|
|
61
67
|
function assertNoToolNameCollisions(args) {
|
|
62
68
|
if (!args.externalTools?.length)
|
|
63
69
|
return;
|
|
@@ -80,12 +86,14 @@ async function buildDeckActionTools(deckPath) {
|
|
|
80
86
|
const actionPathsByName = {};
|
|
81
87
|
for (const action of deck.actionDecks) {
|
|
82
88
|
const child = await loadDeck(action.path, deck.path);
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
const contextSchema = resolveContextSchema(child);
|
|
90
|
+
const responseSchema = resolveResponseSchema(child);
|
|
91
|
+
if (!contextSchema || !responseSchema) {
|
|
92
|
+
throw new Error(`Deck ${child.path} must declare contextSchema and responseSchema (non-root)`);
|
|
85
93
|
}
|
|
86
|
-
assertZodSchema(
|
|
87
|
-
assertZodSchema(
|
|
88
|
-
const params = toJsonSchema(
|
|
94
|
+
assertZodSchema(contextSchema, "contextSchema");
|
|
95
|
+
assertZodSchema(responseSchema, "responseSchema");
|
|
96
|
+
const params = toJsonSchema(contextSchema);
|
|
89
97
|
tools.push({
|
|
90
98
|
type: "function",
|
|
91
99
|
function: {
|
|
@@ -102,8 +110,11 @@ function mergeModelParams(req, deckParams) {
|
|
|
102
110
|
const out = { ...req };
|
|
103
111
|
if (!deckParams)
|
|
104
112
|
return out;
|
|
105
|
-
if (out.model === undefined && deckParams.model)
|
|
106
|
-
out.model = deckParams.model
|
|
113
|
+
if (out.model === undefined && deckParams.model) {
|
|
114
|
+
out.model = Array.isArray(deckParams.model)
|
|
115
|
+
? deckParams.model.find((entry) => typeof entry === "string" && entry.trim().length > 0)
|
|
116
|
+
: deckParams.model;
|
|
117
|
+
}
|
|
107
118
|
if (out.temperature === undefined && deckParams.temperature !== undefined) {
|
|
108
119
|
out.temperature = deckParams.temperature;
|
|
109
120
|
}
|
|
@@ -167,7 +178,10 @@ export async function renderDeck(opts) {
|
|
|
167
178
|
}
|
|
168
179
|
tools = mergedReq.tools;
|
|
169
180
|
}
|
|
170
|
-
const
|
|
181
|
+
const resolvedModel = Array.isArray(mergedReq.model)
|
|
182
|
+
? mergedReq.model.find((entry) => typeof entry === "string" && entry.trim().length > 0)
|
|
183
|
+
: mergedReq.model;
|
|
184
|
+
const model = String(resolvedModel ?? "").trim();
|
|
171
185
|
if (!model) {
|
|
172
186
|
throw new Error(`renderDeck requires request.model (or deck.modelParams.model): ${deck.path}`);
|
|
173
187
|
}
|
package/esm/src/runtime.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ type RunOptions = {
|
|
|
29
29
|
onStateUpdate?: (state: SavedState) => void;
|
|
30
30
|
onStreamText?: (chunk: string) => void;
|
|
31
31
|
allowRootStringInput?: boolean;
|
|
32
|
+
responsesMode?: boolean;
|
|
32
33
|
};
|
|
33
34
|
export declare function runDeck(opts: RunOptions): Promise<unknown>;
|
|
34
35
|
export {};
|
package/esm/src/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/src/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot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