@bolt-foundry/gambit 0.6.3 → 0.6.4
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 +131 -132
- package/bin/gambit.cjs +3 -0
- package/esm/gambit/simulator-ui/dist/bundle.js +854 -889
- package/esm/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/esm/src/server.d.ts.map +1 -1
- package/esm/src/server.js +1 -0
- package/package.json +2 -2
- package/script/gambit/simulator-ui/dist/bundle.js +854 -889
- package/script/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/script/src/server.d.ts.map +1 -1
- package/script/src/server.js +1 -0
package/README.md
CHANGED
|
@@ -1,94 +1,167 @@
|
|
|
1
|
-
# Gambit
|
|
1
|
+
# Gambit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Gambit helps you build reliable LLM workflows by composing small, typed “decks”\
|
|
4
|
+
with clear inputs/outputs and guardrails. Run decks locally, stream traces, and\
|
|
5
|
+
debug with a built-in UI.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
this package, using `scripts/sync-gambit-mirror.sh` to open and auto-merge a PR
|
|
9
|
-
from the `bft-codebot` fork into gambitmono.
|
|
7
|
+
## Quickstart
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
Requirements: Deno 2.2+ and `OPENROUTER_API_KEY` (set `OPENROUTER_BASE_URL` if\
|
|
10
|
+
you proxy OpenRouter-style APIs).
|
|
11
|
+
|
|
12
|
+
Run the CLI directly from JSR (no install):
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
export OPENROUTER_API_KEY=...
|
|
16
|
+
deno run -A jsr:@bolt-foundry/gambit/cli init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Downloads example files and sets environment variables.
|
|
20
|
+
|
|
21
|
+
Run an example in the terminal (`repl`):
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
deno run -A jsr:@bolt-foundry/gambit/cli repl examples/hello.deck.md
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This example just says "hello" and repeats your message back to you.
|
|
28
|
+
|
|
29
|
+
Run an example in the browser (`serve`):
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
deno run -A jsr:@bolt-foundry/gambit/cli serve examples/hello.deck.md
|
|
33
|
+
open http://localhost:8000/debug
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
13
37
|
|
|
14
38
|
## Status quo
|
|
15
39
|
|
|
16
|
-
- Most teams wire one long prompt to several tools and hope the model routes
|
|
40
|
+
- Most teams wire one long prompt to several tools and hope the model routes\
|
|
17
41
|
correctly.
|
|
18
|
-
- Context often arrives as a single giant fetch or RAG blob, so costs climb and
|
|
42
|
+
- Context often arrives as a single giant fetch or RAG blob, so costs climb and\
|
|
19
43
|
hallucinations slip in.
|
|
20
|
-
- Input/outputs are rarely typed, which makes orchestration brittle and hard to
|
|
44
|
+
- Input/outputs are rarely typed, which makes orchestration brittle and hard to\
|
|
21
45
|
test offline.
|
|
22
|
-
- Debugging leans on provider logs instead of local traces, so reproducing
|
|
46
|
+
- Debugging leans on provider logs instead of local traces, so reproducing\
|
|
23
47
|
failures is slow.
|
|
24
48
|
|
|
25
49
|
## Our vision
|
|
26
50
|
|
|
27
|
-
- Treat each step as a small deck with explicit inputs/outputs and guardrails
|
|
51
|
+
- Treat each step as a small deck with explicit inputs/outputs and guardrails;\
|
|
28
52
|
model calls are just one kind of action.
|
|
29
|
-
- Mix LLM and compute tasks interchangeably and effortlessly inside the same
|
|
53
|
+
- Mix LLM and compute tasks interchangeably and effortlessly inside the same\
|
|
30
54
|
deck tree.
|
|
31
|
-
- Feed models only what they need per step; inject references and cards instead
|
|
55
|
+
- Feed models only what they need per step; inject references and cards instead\
|
|
32
56
|
of dumping every document.
|
|
33
|
-
- Keep orchestration logic local and testable; run decks offline with
|
|
57
|
+
- Keep orchestration logic local and testable; run decks offline with\
|
|
34
58
|
predictable traces.
|
|
35
|
-
- Ship with built-in observability (streaming, REPL, debug UI) so debugging
|
|
59
|
+
- Ship with built-in observability (streaming, REPL, debug UI) so debugging\
|
|
36
60
|
feels like regular software, not guesswork.
|
|
37
61
|
|
|
38
|
-
|
|
62
|
+
---
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
you proxy OpenRouter-style APIs).
|
|
64
|
+
## Using the CLI
|
|
42
65
|
|
|
43
|
-
|
|
66
|
+
Use the CLI to run decks locally, stream output, and capture traces/state.
|
|
44
67
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
Install the CLI:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
deno install -A -n gambit jsr:@bolt-foundry/gambit/cli
|
|
48
72
|
```
|
|
49
73
|
|
|
50
|
-
Run a
|
|
74
|
+
Run a deck once:
|
|
51
75
|
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
deno run -A jsr:@bolt-foundry/gambit/cli run --example hello_world.deck.md --init '"hi"'
|
|
76
|
+
```
|
|
77
|
+
gambit run <deck> --init <json|string> --message <json|string>
|
|
55
78
|
```
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
Drop into a REPL (streams by default):
|
|
58
81
|
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
```
|
|
83
|
+
gambit repl <deck>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Run a persona against a root deck (test bot):
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
gambit test-bot <root-deck> --test-deck <persona-deck>
|
|
62
90
|
```
|
|
63
91
|
|
|
64
|
-
|
|
92
|
+
Grade a saved session:
|
|
65
93
|
|
|
66
|
-
```
|
|
67
|
-
|
|
94
|
+
```
|
|
95
|
+
gambit grade <grader-deck> --state <file>
|
|
68
96
|
```
|
|
69
97
|
|
|
70
|
-
|
|
98
|
+
Start the Debug UI server:
|
|
71
99
|
|
|
72
|
-
```sh
|
|
73
|
-
deno run -A src/cli.ts serve src/decks/gambit-assistant.deck.md --port 8000
|
|
74
|
-
open http://localhost:8000/debug
|
|
75
100
|
```
|
|
101
|
+
gambit serve <deck> --port 8000
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Tracing and state:
|
|
105
|
+
|
|
106
|
+
`--trace <file>` for JSONL traces\
|
|
107
|
+
`--verbose` to print events\
|
|
108
|
+
`--state <file>` to persist a session.
|
|
109
|
+
|
|
110
|
+
## Using the Simulator
|
|
111
|
+
|
|
112
|
+
The simulator is the local Debug UI that streams runs and renders traces.
|
|
76
113
|
|
|
77
|
-
Install the CLI
|
|
114
|
+
Install the CLI:
|
|
78
115
|
|
|
79
|
-
```
|
|
116
|
+
```
|
|
80
117
|
deno install -A -n gambit jsr:@bolt-foundry/gambit/cli
|
|
81
|
-
gambit run path/to/root.deck.ts --init '"hi"'
|
|
82
118
|
```
|
|
83
119
|
|
|
84
|
-
|
|
85
|
-
|
|
120
|
+
Start it:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
gambit serve <deck> --port 8000
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Then open:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
http://localhost:8000/
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
It also serves:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
http://localhost:8000/test-bot
|
|
136
|
+
http://localhost:8000/calibrate
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The Debug UI shows transcript lanes plus a trace/tools feed. If the deck has an\
|
|
140
|
+
`inputSchema`, the UI renders a schema-driven form with defaults and a raw JSON\
|
|
141
|
+
tab. Local-first state is stored under `.gambit/` (sessions, traces, notes).
|
|
142
|
+
|
|
143
|
+
## Using the Library
|
|
144
|
+
|
|
145
|
+
Use the library when you want TypeScript decks/cards or custom compute steps.
|
|
146
|
+
|
|
147
|
+
Import the helpers from JSR:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
import { defineDeck, defineCard } from "jsr:@bolt-foundry/gambit";
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Define `inputSchema`/`outputSchema` with Zod to validate IO, and implement\
|
|
154
|
+
`run`/`execute` for compute decks. To call a child deck from code, use\
|
|
155
|
+
`ctx.spawnAndWait({ path, input })`. Emit structured trace events with\
|
|
156
|
+
`ctx.log(...)`.
|
|
157
|
+
|
|
158
|
+
---
|
|
86
159
|
|
|
87
160
|
## Author your first deck
|
|
88
161
|
|
|
89
|
-
Minimal Markdown deck (model-powered):
|
|
162
|
+
### Minimal Markdown deck (model-powered):
|
|
90
163
|
|
|
91
|
-
```
|
|
164
|
+
```
|
|
92
165
|
+++
|
|
93
166
|
label = "hello_world"
|
|
94
167
|
|
|
@@ -102,13 +175,13 @@ You are a concise assistant. Greet the user and echo the input.
|
|
|
102
175
|
|
|
103
176
|
Run it:
|
|
104
177
|
|
|
105
|
-
```
|
|
178
|
+
```
|
|
106
179
|
deno run -A src/cli.ts run ./hello_world.deck.md --init '"Gambit"' --stream
|
|
107
180
|
```
|
|
108
181
|
|
|
109
|
-
Compute deck in TypeScript (no model call):
|
|
182
|
+
### Compute deck in TypeScript (no model call):
|
|
110
183
|
|
|
111
|
-
```
|
|
184
|
+
```
|
|
112
185
|
// echo.deck.ts
|
|
113
186
|
import { defineDeck } from "jsr:@bolt-foundry/gambit";
|
|
114
187
|
import { z } from "zod";
|
|
@@ -125,19 +198,20 @@ export default defineDeck({
|
|
|
125
198
|
|
|
126
199
|
Run it:
|
|
127
200
|
|
|
128
|
-
```
|
|
201
|
+
```
|
|
129
202
|
deno run -A src/cli.ts run ./echo.deck.ts --init '{"text":"ping"}'
|
|
130
203
|
```
|
|
131
204
|
|
|
132
|
-
Deck with a child action (calls a TypeScript tool):
|
|
205
|
+
### Deck with a child action (calls a TypeScript tool):
|
|
133
206
|
|
|
134
|
-
```
|
|
207
|
+
```
|
|
135
208
|
+++
|
|
136
209
|
label = "agent_with_time"
|
|
137
210
|
modelParams = { model = "openai/gpt-4o-mini", temperature = 0 }
|
|
138
|
-
actionDecks
|
|
139
|
-
|
|
140
|
-
|
|
211
|
+
[[actionDecks]]
|
|
212
|
+
name = "get_time"
|
|
213
|
+
path = "./get_time.deck.ts"
|
|
214
|
+
description = "Return the current ISO timestamp."
|
|
141
215
|
+++
|
|
142
216
|
|
|
143
217
|
A tiny agent that calls get_time, then replies with the timestamp and the input.
|
|
@@ -145,7 +219,7 @@ A tiny agent that calls get_time, then replies with the timestamp and the input.
|
|
|
145
219
|
|
|
146
220
|
And the child action:
|
|
147
221
|
|
|
148
|
-
```
|
|
222
|
+
```
|
|
149
223
|
// get_time.deck.ts
|
|
150
224
|
import { defineDeck } from "jsr:@bolt-foundry/gambit";
|
|
151
225
|
import { z } from "zod";
|
|
@@ -159,78 +233,3 @@ export default defineDeck({
|
|
|
159
233
|
},
|
|
160
234
|
});
|
|
161
235
|
```
|
|
162
|
-
|
|
163
|
-
## Repo highlights
|
|
164
|
-
|
|
165
|
-
- CLI entry: `src/cli.ts`; runtime: `src/runtime.ts`; definitions: `mod.ts`.
|
|
166
|
-
- Examples: `examples/hello_world.deck.md`,
|
|
167
|
-
`examples/agent_with_multi_actions/`.
|
|
168
|
-
- Debug UI assets: `src/server.ts` (built-in UI now renders schema-driven init
|
|
169
|
-
forms beneath the user message box with a raw JSON tab, reconnect button, and
|
|
170
|
-
a trace-formatting hook).
|
|
171
|
-
- Tests/lint/format: `deno task test`, `deno task lint`, `deno task fmt`;
|
|
172
|
-
compile binary: `deno task compile`.
|
|
173
|
-
- Docs index: `docs/README.md`; authoring guide: `docs/authoring.md`; prompting
|
|
174
|
-
notes: `docs/hourglass.md`; changelog: `CHANGELOG.md`.
|
|
175
|
-
|
|
176
|
-
## Docs
|
|
177
|
-
|
|
178
|
-
- Authoring decks/cards: `docs/authoring.md`
|
|
179
|
-
- Runtime/guardrails: `docs/runtime.md`
|
|
180
|
-
- CLI, REPL, debug UI: `docs/cli.md`
|
|
181
|
-
- Examples guide: `docs/examples.md`
|
|
182
|
-
- OpenAI Chat Completions compatibility: `docs/openai-compat.md`
|
|
183
|
-
|
|
184
|
-
## OpenAI Chat Completions compatibility
|
|
185
|
-
|
|
186
|
-
If you already construct OpenAI Chat Completions-style requests, you can use
|
|
187
|
-
Gambit as a drop-in-ish wrapper that applies a deck prompt and can execute only
|
|
188
|
-
deck-defined tools (action decks).
|
|
189
|
-
|
|
190
|
-
```ts
|
|
191
|
-
import {
|
|
192
|
-
chatCompletionsWithDeck,
|
|
193
|
-
createOpenRouterProvider,
|
|
194
|
-
} from "jsr:@bolt-foundry/gambit";
|
|
195
|
-
|
|
196
|
-
const provider = createOpenRouterProvider({
|
|
197
|
-
apiKey: Deno.env.get("OPENROUTER_API_KEY")!,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const resp = await chatCompletionsWithDeck({
|
|
201
|
-
deckPath: "./path/to/root.deck.md",
|
|
202
|
-
modelProvider: provider,
|
|
203
|
-
request: {
|
|
204
|
-
model: "openai/gpt-4o-mini",
|
|
205
|
-
messages: [{ role: "user", content: "hello" }],
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
console.log(resp.choices[0].message);
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## Handlers (error/busy/idle)
|
|
213
|
-
|
|
214
|
-
- Decks may declare `handlers` with `onError`, `onBusy`, and `onIdle`.
|
|
215
|
-
`onInterval` is still accepted but deprecated (alias for `onBusy`).
|
|
216
|
-
- Busy handler input:
|
|
217
|
-
`{kind:"busy", source:{deckPath, actionName}, trigger:{reason:"timeout", elapsedMs}, childInput}`
|
|
218
|
-
plus `delayMs`/`repeatMs` knobs.
|
|
219
|
-
- Idle handler input:
|
|
220
|
-
`{kind:"idle", source:{deckPath}, trigger:{reason:"idle_timeout", elapsedMs}}`
|
|
221
|
-
with `delayMs` (and optional `repeatMs` if provided).
|
|
222
|
-
- Error handler input: `{kind:"error", source, error:{message}, childInput}` and
|
|
223
|
-
should return an envelope `{message?, code?, status?, meta?, payload?}`.
|
|
224
|
-
- Example implementations live under `examples/handlers_ts` and
|
|
225
|
-
`examples/handlers_md`.
|
|
226
|
-
- Debug UI streams handler output in a “status” lane (busy/idle) separate from
|
|
227
|
-
assistant turns.
|
|
228
|
-
|
|
229
|
-
## Next steps
|
|
230
|
-
|
|
231
|
-
- Swap `modelParams.model` or pass `--model`/`--model-force` to test other
|
|
232
|
-
providers.
|
|
233
|
-
- Add `actionDecks` to a deck and call child decks; use `spawnAndWait` inside
|
|
234
|
-
compute decks.
|
|
235
|
-
- Use `--stream` and `--verbose` while iterating; pass `--trace <file>` to
|
|
236
|
-
capture JSONL traces.
|
package/bin/gambit.cjs
CHANGED
|
@@ -161,6 +161,9 @@ const verifyChecksum = async (checksumUrl, assetName, filePath) => {
|
|
|
161
161
|
|
|
162
162
|
const main = async () => {
|
|
163
163
|
const version = getPackageVersion();
|
|
164
|
+
if (!process.env.GAMBIT_VERSION) {
|
|
165
|
+
process.env.GAMBIT_VERSION = version;
|
|
166
|
+
}
|
|
164
167
|
const assetName = process.env.GAMBIT_BINARY_NAME || getPlatformAsset();
|
|
165
168
|
if (!assetName) {
|
|
166
169
|
console.error(
|