@restatedev/agents 0.2.0 → 0.4.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 +89 -49
- package/dist/calls.d.ts +29 -8
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +79 -18
- package/dist/calls.js.map +1 -1
- package/dist/claude/index.d.ts +36 -7
- package/dist/claude/index.d.ts.map +1 -1
- package/dist/claude/index.js +238 -156
- package/dist/claude/index.js.map +1 -1
- package/dist/client.d.ts +12 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/common.d.ts +161 -71
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +277 -226
- package/dist/common.js.map +1 -1
- package/dist/conversation.d.ts +466 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +1247 -0
- package/dist/conversation.js.map +1 -0
- package/dist/deepseek/index.d.ts +38 -5
- package/dist/deepseek/index.d.ts.map +1 -1
- package/dist/deepseek/index.js +323 -107
- package/dist/deepseek/index.js.map +1 -1
- package/dist/deepseek/persistence.d.ts +9 -3
- package/dist/deepseek/persistence.d.ts.map +1 -1
- package/dist/deepseek/persistence.js +12 -6
- package/dist/deepseek/persistence.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/langgraph/checkpointer.d.ts +16 -2
- package/dist/langgraph/checkpointer.d.ts.map +1 -1
- package/dist/langgraph/checkpointer.js +133 -26
- package/dist/langgraph/checkpointer.js.map +1 -1
- package/dist/langgraph/context.d.ts +10 -0
- package/dist/langgraph/context.d.ts.map +1 -0
- package/dist/langgraph/context.js +21 -0
- package/dist/langgraph/context.js.map +1 -0
- package/dist/langgraph/errors.d.ts +16 -0
- package/dist/langgraph/errors.d.ts.map +1 -0
- package/dist/langgraph/errors.js +30 -0
- package/dist/langgraph/errors.js.map +1 -0
- package/dist/langgraph/graph.d.ts +25 -0
- package/dist/langgraph/graph.d.ts.map +1 -0
- package/dist/langgraph/graph.js +346 -0
- package/dist/langgraph/graph.js.map +1 -0
- package/dist/langgraph/index.d.ts +65 -12
- package/dist/langgraph/index.d.ts.map +1 -1
- package/dist/langgraph/index.js +234 -180
- package/dist/langgraph/index.js.map +1 -1
- package/dist/langgraph/nodes.d.ts +70 -0
- package/dist/langgraph/nodes.d.ts.map +1 -0
- package/dist/langgraph/nodes.js +145 -0
- package/dist/langgraph/nodes.js.map +1 -0
- package/dist/messages.d.ts +18 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +182 -0
- package/dist/messages.js.map +1 -0
- package/dist/object.d.ts +65 -23
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +123 -40
- package/dist/object.js.map +1 -1
- package/dist/output.d.ts +15 -7
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +44 -26
- package/dist/output.js.map +1 -1
- package/dist/pi/index.d.ts +39 -11
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +281 -77
- package/dist/pi/index.js.map +1 -1
- package/dist/pi/storage.d.ts +29 -4
- package/dist/pi/storage.d.ts.map +1 -1
- package/dist/pi/storage.js +18 -6
- package/dist/pi/storage.js.map +1 -1
- package/dist/signals.d.ts +75 -7
- package/dist/signals.d.ts.map +1 -1
- package/dist/signals.js +154 -27
- package/dist/signals.js.map +1 -1
- package/dist/steering.d.ts +31 -0
- package/dist/steering.d.ts.map +1 -0
- package/dist/steering.js +45 -0
- package/dist/steering.js.map +1 -0
- package/dist/tools.d.ts +28 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +34 -5
- package/dist/tools.js.map +1 -1
- package/package.json +33 -37
- package/src/calls.ts +110 -24
- package/src/claude/README.md +41 -20
- package/src/claude/index.ts +271 -183
- package/src/client.ts +14 -3
- package/src/common.ts +354 -247
- package/src/conversation.ts +1527 -0
- package/src/deepseek/README.md +78 -11
- package/src/deepseek/index.ts +385 -138
- package/src/deepseek/persistence.ts +11 -8
- package/src/index.ts +13 -4
- package/src/langgraph/README.md +115 -25
- package/src/langgraph/checkpointer.ts +168 -28
- package/src/langgraph/context.ts +27 -0
- package/src/langgraph/errors.ts +26 -0
- package/src/langgraph/graph.ts +396 -0
- package/src/langgraph/index.ts +337 -193
- package/src/langgraph/nodes.ts +243 -0
- package/src/messages.ts +244 -0
- package/src/object.ts +178 -48
- package/src/output.ts +52 -31
- package/src/pi/README.md +18 -3
- package/src/pi/index.ts +346 -79
- package/src/pi/storage.ts +20 -7
- package/src/signals.ts +235 -31
- package/src/steering.ts +67 -0
- package/src/tools.ts +61 -8
- package/dist/claude/conversation.d.ts +0 -33
- package/dist/claude/conversation.d.ts.map +0 -1
- package/dist/claude/conversation.js +0 -95
- package/dist/claude/conversation.js.map +0 -1
- package/dist/log.d.ts +0 -29
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -145
- package/dist/log.js.map +0 -1
- package/dist/opencode/db.d.ts +0 -40
- package/dist/opencode/db.d.ts.map +0 -1
- package/dist/opencode/db.js +0 -161
- package/dist/opencode/db.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -100
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -436
- package/dist/opencode/index.js.map +0 -1
- package/src/claude/conversation.ts +0 -114
- package/src/log.ts +0 -193
- package/src/opencode/README.md +0 -125
- package/src/opencode/db.ts +0 -223
- package/src/opencode/index.ts +0 -559
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @restatedev/agents
|
|
2
2
|
|
|
3
|
-
Durable agents on Restate: an agent of one of
|
|
3
|
+
Durable agents on Restate: an agent of one of four frameworks (pi,
|
|
4
4
|
LangGraph, Claude, the DeepSeek Harness) in a Restate virtual object, its
|
|
5
5
|
conversation in the object's own SQL database. A crash, a restart or a
|
|
6
6
|
person who takes a day to approve changes nothing: each message is answered
|
|
@@ -15,8 +15,9 @@ once, and each tool call is made once.
|
|
|
15
15
|
- [Your own session object](#your-own-session-object)
|
|
16
16
|
- [Build your own](#build-your-own)
|
|
17
17
|
- [Words](#words)
|
|
18
|
-
- [
|
|
19
|
-
stopped or killed,
|
|
18
|
+
- [The conversation of turns](docs/README.md): how a message is answered,
|
|
19
|
+
retried, stopped or killed, how the conversation is stored, what the model
|
|
20
|
+
sees, and what a client sees meanwhile
|
|
20
21
|
|
|
21
22
|
## Start here
|
|
22
23
|
|
|
@@ -68,16 +69,16 @@ Restate, wherever it is.
|
|
|
68
69
|
|
|
69
70
|
The same agent runs on each of them: `agent({ name, ...options })`, with
|
|
70
71
|
the handler `chat` (a message in, the answer out), and the views
|
|
71
|
-
`messages` (the conversation so far), `status` (what it is doing), `
|
|
72
|
-
(the message it answers), `
|
|
72
|
+
`messages` (the conversation so far), `status` (what it is doing), `steer`
|
|
73
|
+
(add to the message it answers), `stop` (the message it answers), `clear`
|
|
74
|
+
(forget it all), `sync`,
|
|
73
75
|
`notifications` and `watch` (to follow it), and `signal` and `pending`
|
|
74
76
|
([Signals](#signals)).
|
|
75
77
|
|
|
76
78
|
| Import | Framework | Choose it when |
|
|
77
79
|
| --------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
78
80
|
| [`@restatedev/agents/pi`](src/pi/README.md) | pi-durable | You want the default: any provider, coding tools on request, and its Harness (compact, reset) |
|
|
79
|
-
| [`@restatedev/agents/
|
|
80
|
-
| [`@restatedev/agents/langgraph`](src/langgraph/README.md) | LangGraph | You use LangChain: its tools, or a chat model of your own |
|
|
81
|
+
| [`@restatedev/agents/langgraph`](src/langgraph/README.md) | LangGraph | You use LangChain: its tools, a chat model of your own, or a graph of your own |
|
|
81
82
|
| [`@restatedev/agents/claude`](src/claude/README.md) | the Anthropic SDK's tool runner | You want Claude with nothing in between: the lightest, the API's own messages |
|
|
82
83
|
| [`@restatedev/agents/deepseek`](src/deepseek/README.md) | DeepSeek Harness | You want DeepSeek's harness: DeepSeek's models, or any pi-ai knows |
|
|
83
84
|
|
|
@@ -92,16 +93,18 @@ npm install @restatedev/agents @earendil-works/pi-durable @earendil-works/pi-ai
|
|
|
92
93
|
npm install @restatedev/agents @anthropic-ai/sdk # Claude
|
|
93
94
|
npm install @restatedev/agents @langchain/core @langchain/langgraph @langchain/langgraph-checkpoint \
|
|
94
95
|
@langchain/openai # LangGraph, and the provider of its models: or @langchain/anthropic
|
|
95
|
-
npm install @restatedev/agents @opencode/core@2.0.32 @opencode/plugin@2.0.32 @opencode/sdk@2.0.32 \
|
|
96
|
-
@opencode/server@2.0.32 effect@4.0.1 # OpenCode, which pins its packages, and effect
|
|
97
96
|
npm install @restatedev/agents @earendil-works/pi-ai @deepseek-ai/cordis \
|
|
98
97
|
@deepseek-ai/{dsh-agent,dsh-agent-loop,dsh-llm,dsh-llm-deepseek-api-key,dsh-llm-pi-ai,dsh-session}@0.2.1-rc.2 \
|
|
99
98
|
@deepseek-ai/{dsh-session-checkpoint-policy,dsh-session-persistence,dsh-session-projection}@0.2.1-rc.2 \
|
|
100
|
-
@deepseek-ai/{dsh-system-prompt,dsh-tools}@0.2.1-rc.2
|
|
99
|
+
@deepseek-ai/{dsh-system-prompt,dsh-tools,dsh-user-approval}@0.2.1-rc.2 \
|
|
100
|
+
@deepseek-ai/{dsh-commands,dsh-compaction,dsh-compaction-basic,dsh-compaction-tool-result-pruner,dsh-token-meter}@0.2.1-rc.2 # DeepSeek
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
OpenCode
|
|
104
|
-
|
|
103
|
+
OpenCode was a framework of this package until its agents moved onto the
|
|
104
|
+
conversation of turns: a turn whose invocation is gone (killed) must be
|
|
105
|
+
closed, never finished, and OpenCode resumes a turn it claimed whenever it
|
|
106
|
+
boots, with no public way to end it first (see
|
|
107
|
+
[docs/frameworks.md](docs/frameworks.md#opencode)). A subpath whose packages are
|
|
105
108
|
missing fails as it is imported, naming the first it lacks. The packages
|
|
106
109
|
are not published yet:
|
|
107
110
|
[`pnpm --filter e2e packaging`](../e2e/packaging.ts) installs them from
|
|
@@ -109,10 +112,10 @@ their tarballs, with pi alone. In this repository the frameworks' packages
|
|
|
109
112
|
are @restatedev/agents' development dependencies, so every example runs as it is.
|
|
110
113
|
|
|
111
114
|
Every framework takes `model`, `system`, `tools` and `output` (a
|
|
112
|
-
[structured answer](#structured-answers)); pi
|
|
113
|
-
`workspace` too, a directory for
|
|
115
|
+
[structured answer](#structured-answers)); pi takes a
|
|
116
|
+
`workspace` too, a directory for its coding tools. `system` is the whole
|
|
114
117
|
system prompt for Claude and LangGraph, and is added to the framework's own
|
|
115
|
-
(which tells the model about its tools) for pi
|
|
118
|
+
(which tells the model about its tools) for pi and DeepSeek.
|
|
116
119
|
|
|
117
120
|
Every agent takes these too, beside its framework's options:
|
|
118
121
|
|
|
@@ -121,6 +124,13 @@ Every agent takes these too, beside its framework's options:
|
|
|
121
124
|
| `description` | What it is, for the UI, and for a parent's model: `subagent(agent)` tells it |
|
|
122
125
|
| `background` | It works unwatched (a subagent, say): its turn tells its `signals` at its end only, not at each step, so a follower sees each turn once it ended |
|
|
123
126
|
| `schema` | Tables of your own in its database ([Build your own](#build-your-own)) |
|
|
127
|
+
| `window` | How many of the latest answered turns its model sees whole, with their tool calls and results (default 1), or `'all'` |
|
|
128
|
+
| `budget` | How many tokens of the turns before the window its model sees, as their messages and answers (default 32 000); `summarize` summarizes the rest |
|
|
129
|
+
|
|
130
|
+
`window` and `budget` bound what Claude's and LangGraph's model is sent
|
|
131
|
+
([what the model gets](docs/conversation.md)); pi and the DeepSeek Harness
|
|
132
|
+
keep their own history, and compact it themselves. An object holds one
|
|
133
|
+
framework's conversation: its turns are that framework's messages.
|
|
124
134
|
|
|
125
135
|
## Calling an agent
|
|
126
136
|
|
|
@@ -133,7 +143,7 @@ curl localhost:8080/assistant/alice/chat -d 'Hi, I am Alice' # "Hello Alic
|
|
|
133
143
|
```
|
|
134
144
|
|
|
135
145
|
A key answers one message at a time: a message sent while another is
|
|
136
|
-
answered waits for it ([turn semantics](
|
|
146
|
+
answered waits for it ([turn semantics](docs/turns.md) spells out how a
|
|
137
147
|
turn starts, ends, and is retried). A message that fails for good answers with an error:
|
|
138
148
|
HTTP 424 if the model's provider refused it (a missing or wrong API key, an
|
|
139
149
|
unknown model), 500 otherwise. A refused message is over: the next message
|
|
@@ -179,9 +189,30 @@ An attempt that ends before its turn does, while its process lives on
|
|
|
179
189
|
work too, a model's request included: it can store nothing more, and the
|
|
180
190
|
next attempt goes on with the turn, which is not cancelled.
|
|
181
191
|
|
|
182
|
-
**A message while it works.** A message sent while the agent
|
|
183
|
-
another waits for it: Restate answers a key's messages one at a
|
|
184
|
-
order. To
|
|
192
|
+
**A message while it works.** A message sent to `chat` while the agent
|
|
193
|
+
answers another waits for it: Restate answers a key's messages one at a
|
|
194
|
+
time, in order. To add to the message being answered ("use Celsius", "skip
|
|
195
|
+
Friday"), send it to `steer`: the turn takes it at its next step (once the
|
|
196
|
+
model's tool calls have their results, before its next request), and its
|
|
197
|
+
answer covers it. A message that comes too late for a step (the model is
|
|
198
|
+
writing its final answer, say) is answered as a turn of its own, right after
|
|
199
|
+
the turn, before the messages sent after it; so is one sent with no turn
|
|
200
|
+
being answered. Either way it is answered once: send it with an idempotency
|
|
201
|
+
key, so that a request sent again is the same message.
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
curl localhost:8080/assistant/alice/chat/send -d 'Plan my week'
|
|
205
|
+
curl localhost:8080/assistant/alice/steer -H 'idempotency-key: 7f3c…' -d 'Skip Friday' # {"id": "inv_…", "turn": "inv_1f…"}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`steer` answers the message's id and the turn that holds it for its next
|
|
209
|
+
step, or `turn: null` if it is answered as a turn of its own; `status`
|
|
210
|
+
lists the messages the turn holds and has not taken yet (`steering`). A
|
|
211
|
+
turn takes at most 16. Claude and LangGraph's built-in agent take them
|
|
212
|
+
before each model request that follows a round of tool calls; pi and
|
|
213
|
+
DeepSeek through their own inboxes; a LangGraph graph of your own, and a
|
|
214
|
+
background agent, take none ([Steering a turn](docs/turns.md#steering-a-turn)).
|
|
215
|
+
To change course outright, stop the turn (`stop`) and send the message that
|
|
185
216
|
replaces it.
|
|
186
217
|
|
|
187
218
|
**Forget a conversation.** `clear` starts a key over, such as for a UI's
|
|
@@ -235,15 +266,17 @@ curl localhost:8080/assistant/alice/messages
|
|
|
235
266
|
}
|
|
236
267
|
```
|
|
237
268
|
|
|
238
|
-
The conversation as clients read it is
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
with
|
|
245
|
-
|
|
246
|
-
|
|
269
|
+
The conversation as clients read it is the agent's conversation of turns,
|
|
270
|
+
in the object's database ([docs/conversation.md](docs/conversation.md)). A
|
|
271
|
+
message's `id` is its position, and never changes; `cursor` is where the
|
|
272
|
+
conversation is now. `limit` caps a page; `before` an id gives older
|
|
273
|
+
messages (scrolling back, while `more` says there are older ones still);
|
|
274
|
+
and `cursor` gives the messages new or changed since it, by when they
|
|
275
|
+
changed, with the next cursor: a message that grew (a tool call with its
|
|
276
|
+
output) comes again, with its `id`. `view: "summary"` gives each turn's
|
|
277
|
+
message and answer alone, under the same ids. A conversation whose earliest
|
|
278
|
+
turns are summarized, or that the framework compacted, keeps every turn as
|
|
279
|
+
it was said (only the model's context changed):
|
|
247
280
|
|
|
248
281
|
```sh
|
|
249
282
|
curl localhost:8080/assistant/alice/messages --json '{"limit": 20, "before": 40}'
|
|
@@ -382,7 +415,7 @@ and Restate retries it: the tool call runs again.
|
|
|
382
415
|
**Once.** A crash runs an unfinished tool call again with the same call id.
|
|
383
416
|
A tool that must not run twice passes its `idempotencyKey` on (made of the
|
|
384
417
|
invocation's id and the call id), as Restate's tools do with each call they
|
|
385
|
-
make: run again, it is the same call.
|
|
418
|
+
make: run again, it is the same call. The DeepSeek Harness tells
|
|
386
419
|
the model that a cut-off tool call was interrupted instead, and the model
|
|
387
420
|
makes it again as a new tool call: Restate's tools then make the same call,
|
|
388
421
|
if the input is the same (so a wait for an approval outlasts a restart), and
|
|
@@ -437,6 +470,10 @@ curl localhost:8080/support/alice/signal --json '{"id": "inv_1f…:toolu_01", "v
|
|
|
437
470
|
curl localhost:8080/support/alice/signal --json '{"name": "approval", "value": "approved", "keep": true}'
|
|
438
471
|
```
|
|
439
472
|
|
|
473
|
+
A DeepSeek agent's tool calls that need a person's approval (its `approval`
|
|
474
|
+
option) wait the same way, for the signal `approval`: see
|
|
475
|
+
[its README](src/deepseek/README.md#approvals).
|
|
476
|
+
|
|
440
477
|
A wait ends with its agent's invocation: a cancelled or killed one leaves `pending`.
|
|
441
478
|
The waits are kept by the `signals` object, keyed `<agent>:<key>`, which
|
|
442
479
|
`serve` serves beside the agents. See
|
|
@@ -445,10 +482,14 @@ The waits are kept by the `signals` object, keyed `<agent>:<key>`, which
|
|
|
445
482
|
## Structured answers
|
|
446
483
|
|
|
447
484
|
With `output`, a zod object, an agent answers with data rather than text:
|
|
448
|
-
its reply is its answer, as JSON of the schema
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
485
|
+
its reply is its answer, as JSON of the schema, and `chat` answers with the
|
|
486
|
+
value, checked against the schema: the answer is the call's return value,
|
|
487
|
+
as with any handler. Every framework takes it. Claude asks the model for it
|
|
488
|
+
natively where the model has structured outputs (the API's
|
|
489
|
+
`output_config.format`, which holds the reply to the schema), or as its
|
|
490
|
+
`nativeOutput` says; otherwise, and in the other frameworks, the system
|
|
491
|
+
prompt asks for it, with the schema, and the model is reminded of it after
|
|
492
|
+
each prompt, though `messages` shows the prompt as it was asked.
|
|
452
493
|
|
|
453
494
|
```ts
|
|
454
495
|
const Plan = z.object({ summary: z.string(), parts: z.array(z.string()) });
|
|
@@ -457,12 +498,14 @@ const planner = claude.agent({ name: 'planner', output: Plan });
|
|
|
457
498
|
const plan = await ctx.rpc(planner, 'ENG-1').chat('Plan the work on ENG-1'); // a Plan
|
|
458
499
|
```
|
|
459
500
|
|
|
460
|
-
A reply that is not such JSON (a code fence around it is fine
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
501
|
+
A reply that is not such JSON (a code fence around it is fine; asked
|
|
502
|
+
natively, the API holds it to the schema's types, not to checks such as a
|
|
503
|
+
string's `max`) is answered with what is wrong with it, once, for the model
|
|
504
|
+
to reply again; then the invocation fails, with a terminal error, and the
|
|
505
|
+
conversation shows its turn failed, with that error. A retried attempt
|
|
506
|
+
resumes the conversation, and reads the same reply. In a handler of your
|
|
507
|
+
own, `prompt(ctx, text, { output })` answers with it too. As a subagent's,
|
|
508
|
+
the parent's model gets it as JSON.
|
|
466
509
|
|
|
467
510
|
## Webhooks
|
|
468
511
|
|
|
@@ -530,7 +573,7 @@ environment variable, or else OpenAI's `openai/gpt-6-sol`, with
|
|
|
530
573
|
pi.agent({ name: 'assistant', model: 'anthropic/claude-sonnet-5-5' }); // with ANTHROPIC_API_KEY
|
|
531
574
|
```
|
|
532
575
|
|
|
533
|
-
pi
|
|
576
|
+
pi and the DeepSeek Harness take any provider they know (the
|
|
534
577
|
DeepSeek Harness, pi-ai's); LangGraph OpenAI's and Anthropic's models (and
|
|
535
578
|
any LangChain chat model, as `model`); Claude Anthropic's.
|
|
536
579
|
|
|
@@ -579,10 +622,8 @@ await serve(assistant);
|
|
|
579
622
|
```
|
|
580
623
|
|
|
581
624
|
Your tables share the database with the agent's, whose names all start with
|
|
582
|
-
`restate_` (`
|
|
583
|
-
`
|
|
584
|
-
database of their own, beside it, as OpenCode boots only on a database that
|
|
585
|
-
is empty or its own.
|
|
625
|
+
`restate_` (`restate_agent_turns`, `restate_agent_items`,
|
|
626
|
+
`restate_pi_tasks`...): any other name is yours.
|
|
586
627
|
|
|
587
628
|
**Options for each invocation.** `chat` takes options, or a function of the
|
|
588
629
|
invocation's context that gives them: each user's model and persona from
|
|
@@ -606,9 +647,8 @@ that takes its message as `chat` does (text, or a JSON string):
|
|
|
606
647
|
summarize: chatHandler(async (ctx, topic) => pi.prompt(ctx, `Summarize what we said about ${topic}`)),
|
|
607
648
|
```
|
|
608
649
|
|
|
609
|
-
pi
|
|
610
|
-
|
|
611
|
-
API, such as compacting the conversation (see their READMEs).
|
|
650
|
+
pi also has `withPi(ctx, options, work)`, for more than a prompt: the Harness's own
|
|
651
|
+
API, such as compacting the conversation (see its README).
|
|
612
652
|
|
|
613
653
|
**What `sessionObject()` sets up.** `ctx.db` in every handler; retries for weeks
|
|
614
654
|
(50 ms after a crash, then twice as long each time, up to 10 s apart), since
|
|
@@ -618,8 +658,8 @@ journal in Restate's UI. Its `options` (such as `retryPolicy`) and
|
|
|
618
658
|
[`@restatedev/sessions`](../sessions/README.md): `handlers` run one at a time per
|
|
619
659
|
key, and `views` beside them. Its own cannot be named `signal`, `pending`,
|
|
620
660
|
`status`, `stop`, `notifications` or `watch`, views every agent's
|
|
621
|
-
session object has, nor `sync`, `clear`
|
|
622
|
-
`messages` view). A view of yours reads the database too: `ctx.db` is the
|
|
661
|
+
session object has, nor `sync`, `clear`, `steer`, `erase`, `settle`, `compact`
|
|
662
|
+
or `steered`, which an agent has (one with a `messages` view). A view of yours reads the database too: `ctx.db` is the
|
|
623
663
|
database as committed, beside a message being answered.
|
|
624
664
|
|
|
625
665
|
## Build your own
|
package/dist/calls.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import type * as restate from '@restatedev/sessions';
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Run `work` (a turn's) with the calls its tools make kept as prompt
|
|
4
|
+
* `prompt`'s: they are matched, and rejoined, within it only. An invocation
|
|
5
|
+
* that prompts twice, its second prompt making the call its first made
|
|
6
|
+
* (the same tool and input), would otherwise take the first's after a crash
|
|
7
|
+
* (its record not yet forgotten), and never make its own.
|
|
8
|
+
*/
|
|
9
|
+
export declare function forPrompt<T>(ctx: restate.SessionContext, prompt: string, work: () => Promise<T>): Promise<T>;
|
|
4
10
|
/**
|
|
5
11
|
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
|
6
|
-
* one it made before (a run again), or
|
|
7
|
-
* the same tool and input (made again under a
|
|
8
|
-
*
|
|
12
|
+
* one it made to `tool` before (a run again), or else, if `rejoin`, the one
|
|
13
|
+
* an earlier attempt made with the same tool and input (made again under a
|
|
14
|
+
* new id), or else a new one, an `approval` its tool call waits for if so.
|
|
15
|
+
* `answered()` stores that it answered.
|
|
9
16
|
*/
|
|
10
|
-
export declare function callOf(ctx:
|
|
17
|
+
export declare function callOf(ctx: restate.SessionContext, tool: string, input: unknown, callId: string, { rejoin, approval }?: {
|
|
18
|
+
rejoin?: boolean;
|
|
19
|
+
approval?: boolean;
|
|
20
|
+
}): Promise<{
|
|
11
21
|
id: string;
|
|
12
22
|
/**
|
|
13
23
|
* It answered, with `failed` if a terminal error answered it: kept until
|
|
@@ -24,6 +34,17 @@ export declare function callOf(ctx: CallsContext, tool: string, input: unknown,
|
|
|
24
34
|
* otherwise take one an earlier attempt made, and the model has the result
|
|
25
35
|
* of.
|
|
26
36
|
*/
|
|
27
|
-
export declare function
|
|
28
|
-
|
|
37
|
+
export declare function settleCalls(ctx: restate.SessionContext, stored: (id: string, failed?: string) => boolean): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Which of `callIds` made a Restate call that answered, in this invocation
|
|
40
|
+
* or in `invocation`: each with the terminal error it answered with
|
|
41
|
+
* (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
|
|
42
|
+
* call did not answer, or that made none, is left out; so is one whose only
|
|
43
|
+
* answered call is its approval, which it ran (or was denied) after.
|
|
44
|
+
*
|
|
45
|
+
* An earlier `invocation`'s calls are read only while they are still
|
|
46
|
+
* stored, until an invocation of the key makes calls of its own; read,
|
|
47
|
+
* never changed. With `prompt`, the calls of its turn only.
|
|
48
|
+
*/
|
|
49
|
+
export declare function outcomes(ctx: restate.SessionContext, callIds: Iterable<string>, invocation?: string, prompt?: string): Promise<Map<string, string | undefined>>;
|
|
29
50
|
//# sourceMappingURL=calls.d.ts.map
|
package/dist/calls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAkFrD;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CASlH;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,GAAG,EAAE,OAAO,CAAC,cAAc,EAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,EAAE,MAAa,EAAE,QAAgB,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO;;IAyBhF;;;OAGG;sBACqB,MAAM;GAMjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,iBAM9G;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,OAAO,CAAC,cAAc,EAC3B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAc1C"}
|
package/dist/calls.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from '@restatedev/sessions/internal';
|
|
1
|
+
import { Schema, ScopeKey } from '@restatedev/sessions/internal';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
/** The table of the {@link Calls}: one row, of the invocation whose calls they are. */
|
|
4
4
|
const SCHEMA = new Schema('restate-agents.calls', [
|
|
@@ -24,36 +24,68 @@ async function load(ctx, invocation) {
|
|
|
24
24
|
: { invocation, calls: [] };
|
|
25
25
|
}
|
|
26
26
|
/** Each attempt's id, and its calls, by its context. */
|
|
27
|
-
const
|
|
28
|
-
/** The attempt of `ctx`: its id, and the calls of its invocation. */
|
|
27
|
+
const ATTEMPT = new ScopeKey('the calls of an attempt');
|
|
28
|
+
/** The attempt of `ctx`: its id, and the calls of its invocation (loaded once, shared by calls made at once). */
|
|
29
29
|
function attemptOf(ctx) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
return ATTEMPT.of(ctx, () => ({ id: randomUUID(), calls: load(ctx, ctx.request.id) }));
|
|
31
|
+
}
|
|
32
|
+
/** `value` as JSON with its objects' keys sorted: the same input, however its keys came, is the same call. */
|
|
33
|
+
function canonical(value) {
|
|
34
|
+
return JSON.stringify(value, (_key, v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
35
|
+
? Object.fromEntries(Object.entries(v).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
36
|
+
: v);
|
|
37
|
+
}
|
|
38
|
+
/** The prompt whose turn the tools of `ctx` run for, while `answerOnce` answers it. */
|
|
39
|
+
const PROMPT = new ScopeKey('the prompt of the calls');
|
|
40
|
+
/**
|
|
41
|
+
* Run `work` (a turn's) with the calls its tools make kept as prompt
|
|
42
|
+
* `prompt`'s: they are matched, and rejoined, within it only. An invocation
|
|
43
|
+
* that prompts twice, its second prompt making the call its first made
|
|
44
|
+
* (the same tool and input), would otherwise take the first's after a crash
|
|
45
|
+
* (its record not yet forgotten), and never make its own.
|
|
46
|
+
*/
|
|
47
|
+
export async function forPrompt(ctx, prompt, work) {
|
|
48
|
+
const outer = PROMPT.get(ctx);
|
|
49
|
+
PROMPT.set(ctx, prompt);
|
|
50
|
+
try {
|
|
51
|
+
return await work();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (outer === undefined)
|
|
55
|
+
PROMPT.delete(ctx);
|
|
56
|
+
else
|
|
57
|
+
PROMPT.set(ctx, outer);
|
|
35
58
|
}
|
|
36
|
-
return attempt;
|
|
37
59
|
}
|
|
38
60
|
/**
|
|
39
61
|
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
|
40
|
-
* one it made before (a run again), or
|
|
41
|
-
* the same tool and input (made again under a
|
|
42
|
-
*
|
|
62
|
+
* one it made to `tool` before (a run again), or else, if `rejoin`, the one
|
|
63
|
+
* an earlier attempt made with the same tool and input (made again under a
|
|
64
|
+
* new id), or else a new one, an `approval` its tool call waits for if so.
|
|
65
|
+
* `answered()` stores that it answered.
|
|
43
66
|
*/
|
|
44
|
-
export async function callOf(ctx, tool, input, callId) {
|
|
67
|
+
export async function callOf(ctx, tool, input, callId, { rejoin = true, approval = false } = {}) {
|
|
45
68
|
const attempt = attemptOf(ctx);
|
|
46
69
|
const state = await attempt.calls;
|
|
47
|
-
const json =
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
const json = canonical(input);
|
|
71
|
+
const prompt = PROMPT.get(ctx);
|
|
72
|
+
const ours = state.calls.filter((c) => c.prompt === prompt);
|
|
73
|
+
// A tool call may make more than one call (an approval, then the tool's
|
|
74
|
+
// own), each to a tool of its own.
|
|
75
|
+
let call = ours.find((c) => c.ids.includes(callId) && c.tool === tool) ??
|
|
76
|
+
(rejoin ? ours.find((c) => c.attempt !== attempt.id && c.tool === tool && c.input === json) : undefined);
|
|
50
77
|
if (call) {
|
|
51
78
|
call.attempt = attempt.id;
|
|
52
79
|
if (!call.ids.includes(callId))
|
|
53
80
|
call.ids.push(callId);
|
|
54
81
|
}
|
|
55
82
|
else {
|
|
56
|
-
|
|
83
|
+
call = { tool, input: json, ids: [callId], attempt: attempt.id };
|
|
84
|
+
if (approval)
|
|
85
|
+
call.approval = true;
|
|
86
|
+
if (prompt !== undefined)
|
|
87
|
+
call.prompt = prompt;
|
|
88
|
+
state.calls.push(call);
|
|
57
89
|
}
|
|
58
90
|
await store(ctx, state);
|
|
59
91
|
const made = call;
|
|
@@ -80,7 +112,7 @@ export async function callOf(ctx, tool, input, callId) {
|
|
|
80
112
|
* otherwise take one an earlier attempt made, and the model has the result
|
|
81
113
|
* of.
|
|
82
114
|
*/
|
|
83
|
-
export async function
|
|
115
|
+
export async function settleCalls(ctx, stored) {
|
|
84
116
|
const state = await attemptOf(ctx).calls;
|
|
85
117
|
const kept = state.calls.filter((c) => !c.done || !stored(c.ids.at(-1), c.failed));
|
|
86
118
|
if (kept.length === state.calls.length)
|
|
@@ -88,4 +120,33 @@ export async function settle(ctx, stored) {
|
|
|
88
120
|
state.calls = kept;
|
|
89
121
|
await store(ctx, state);
|
|
90
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Which of `callIds` made a Restate call that answered, in this invocation
|
|
125
|
+
* or in `invocation`: each with the terminal error it answered with
|
|
126
|
+
* (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
|
|
127
|
+
* call did not answer, or that made none, is left out; so is one whose only
|
|
128
|
+
* answered call is its approval, which it ran (or was denied) after.
|
|
129
|
+
*
|
|
130
|
+
* An earlier `invocation`'s calls are read only while they are still
|
|
131
|
+
* stored, until an invocation of the key makes calls of its own; read,
|
|
132
|
+
* never changed. With `prompt`, the calls of its turn only.
|
|
133
|
+
*/
|
|
134
|
+
export async function outcomes(ctx, callIds, invocation, prompt) {
|
|
135
|
+
const state = invocation !== undefined && invocation !== ctx.request.id
|
|
136
|
+
? await load(ctx, invocation)
|
|
137
|
+
: await attemptOf(ctx).calls;
|
|
138
|
+
const wanted = new Set(callIds);
|
|
139
|
+
const found = new Map();
|
|
140
|
+
for (const call of state.calls) {
|
|
141
|
+
if (!call.done || call.approval)
|
|
142
|
+
continue;
|
|
143
|
+
// Another prompt's call, of the same invocation: not this turn's.
|
|
144
|
+
if (prompt !== undefined && call.prompt !== undefined && call.prompt !== prompt)
|
|
145
|
+
continue;
|
|
146
|
+
for (const id of call.ids)
|
|
147
|
+
if (wanted.has(id))
|
|
148
|
+
found.set(id, call.failed);
|
|
149
|
+
}
|
|
150
|
+
return found;
|
|
151
|
+
}
|
|
91
152
|
//# sourceMappingURL=calls.js.map
|
package/dist/calls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA2BzC,uFAAuF;AACvF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE;IAChD;;;;IAIE;CACH,CAAC,CAAC;AAKH,oEAAoE;AACpE,KAAK,UAAU,KAAK,CAAC,GAAiB,EAAE,EAAE,UAAU,EAAE,KAAK,EAAS;IAClE,MAAM,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,sFAAsF,EAAE;QAC3G,UAAU;QACV,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;KACtB,CAAC,CAAC;AACL,CAAC;AAED,qFAAqF;AACrF,KAAK,UAAU,IAAI,CAAC,GAAiB,EAAE,UAAkB;IACvD,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAC1B,mDAAmD,CACpD,CAAC;IACF,OAAO,GAAG,EAAE,UAAU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,SAAS;QAC1F,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,GAAG;YAAE,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/claude/index.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import * as restate from '@restatedev/sessions';
|
|
2
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
3
3
|
import type { BetaRunnableTool, BetaToolRunContext } from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool';
|
|
4
|
-
import { type Configure } from '../common.ts';
|
|
4
|
+
import { type Configure, type Summarize } from '../common.ts';
|
|
5
|
+
import { type Items } from '../conversation.ts';
|
|
5
6
|
import { type Answer } from '../output.ts';
|
|
6
7
|
import type { z } from 'zod';
|
|
7
8
|
import { type Definition } from '../object.ts';
|
|
8
9
|
import { type Tool as AnyTool } from '../tools.ts';
|
|
10
|
+
type MessageParam = Anthropic.Beta.Messages.BetaMessageParam;
|
|
9
11
|
/** The id of the tool call a tool runs for: the runner always passes it. */
|
|
10
12
|
export declare const callId: (context?: BetaToolRunContext) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Claude's items: the SDK's messages, as JSON. A user's text is said by the
|
|
15
|
+
* user, an assistant's by the assistant, and its `tool_use` blocks are its
|
|
16
|
+
* calls; a `tool_result` is a result. A server tool's blocks (and a
|
|
17
|
+
* `system` message) say nothing: they leave no open call the API would
|
|
18
|
+
* refuse a result for.
|
|
19
|
+
*/
|
|
20
|
+
export declare const items: Items<MessageParam>;
|
|
11
21
|
/** How much effort the model puts into a reply (Anthropic's `output_config.effort`). */
|
|
12
22
|
export type Effort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
13
23
|
/** An agent's options: `chat` and `prompt` take them. */
|
|
@@ -32,12 +42,23 @@ export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undef
|
|
|
32
42
|
* (checked), and `chat` and `prompt` answer with (see output.ts).
|
|
33
43
|
*/
|
|
34
44
|
output?: O;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the model is asked for `output` natively, with the API's
|
|
47
|
+
* structured outputs (`output_config.format`: the JSON schema the API
|
|
48
|
+
* holds the final reply to), rather than in the prompt (default: if the
|
|
49
|
+
* model has them, as Claude's have since the 4.5 models). A schema the API
|
|
50
|
+
* cannot take (too complex, say) refuses the message: `false` asks in the
|
|
51
|
+
* prompt instead.
|
|
52
|
+
*/
|
|
53
|
+
nativeOutput?: boolean;
|
|
35
54
|
}
|
|
36
55
|
/**
|
|
37
56
|
* Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
|
|
38
57
|
* of an invocation is a prompt of its own.
|
|
39
58
|
* With `output`, it answers with the value the agent replies with (see
|
|
40
|
-
* output.ts), not its text
|
|
59
|
+
* output.ts), not its text: a reply that is not one is asked again within
|
|
60
|
+
* its turn, once. A model with structured outputs is asked for it natively
|
|
61
|
+
* (`nativeOutput`), else in the prompt.
|
|
41
62
|
*/
|
|
42
63
|
export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
|
|
43
64
|
/**
|
|
@@ -53,13 +74,19 @@ export declare const chat: <O extends z.ZodObject | undefined = undefined>(optio
|
|
|
53
74
|
handler: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
|
|
54
75
|
};
|
|
55
76
|
/**
|
|
56
|
-
* A
|
|
57
|
-
*
|
|
58
|
-
*
|
|
77
|
+
* A view of the conversation as clients read it: a page at a time, or what
|
|
78
|
+
* is new or changed since a cursor; `view: 'summary'` for each turn's
|
|
79
|
+
* message and answer. It answers while a message is answered.
|
|
59
80
|
*/
|
|
60
81
|
export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
82
|
+
/**
|
|
83
|
+
* How an agent of `options` summarizes the earliest turns, past its budget:
|
|
84
|
+
* with its own client and model (`agent()` gives it; for an object of your
|
|
85
|
+
* own, `sessionObject`'s `summarize`).
|
|
86
|
+
*/
|
|
87
|
+
export declare const summarizer: (options?: Options) => Summarize;
|
|
61
88
|
/** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
|
|
62
|
-
export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
|
|
89
|
+
export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, window, budget, summarize, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
|
|
63
90
|
signal: (ctx: restate.ViewContext, signal: import("../signals.ts").Signal) => Promise<import("../signals.ts").Resolved>;
|
|
64
91
|
pending: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Waiting[]>;
|
|
65
92
|
status: (ctx: restate.ViewContext) => Promise<import("../object.ts").Status>;
|
|
@@ -68,10 +95,12 @@ export declare const agent: <P extends string, O extends z.ZodObject | undefined
|
|
|
68
95
|
watch: (ctx: restate.ViewContext, watch: import("../signals.ts").Watch) => Promise<import("../signals.ts").Notifications>;
|
|
69
96
|
} & {
|
|
70
97
|
clear: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
|
|
71
|
-
|
|
98
|
+
steer: (ctx: restate.ViewContext, text: string) => Promise<import("../signals.ts").Steered>;
|
|
99
|
+
sync: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
|
|
72
100
|
} & {
|
|
73
101
|
chat: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
|
|
74
102
|
} & {
|
|
75
103
|
messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
76
104
|
}>;
|
|
105
|
+
export {};
|
|
77
106
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAEzG,OAAO,EAGL,KAAK,SAAS,EAOd,KAAK,SAAS,EAIf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,KAAK,KAAK,EAAyB,MAAM,oBAAoB,CAAC;AAGnF,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAEzE,KAAK,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;AAE7D,4EAA4E;AAC5E,eAAO,MAAM,MAAM,aAAc,kBAAkB,WAGlD,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,YAAY,CAkDrC,CAAC;AA2JF,wFAAwF;AACxF,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAEjE,yDAAyD;AACzD,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,GAAG,SAAS;IAClF,sFAAsF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