@restatedev/agents 0.11.2 → 0.12.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 +189 -808
- package/dist/pi/factory.d.ts +73 -0
- package/dist/pi/factory.d.ts.map +1 -0
- package/dist/pi/factory.js +145 -0
- package/dist/pi/factory.js.map +1 -0
- package/dist/pi/index.d.ts +5 -129
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +31 -571
- package/dist/pi/index.js.map +1 -1
- package/dist/pi/keepalive.d.ts +3 -16
- package/dist/pi/keepalive.d.ts.map +1 -1
- package/dist/pi/keepalive.js +38 -41
- package/dist/pi/keepalive.js.map +1 -1
- package/dist/pi/left.d.ts +16 -0
- package/dist/pi/left.d.ts.map +1 -0
- package/dist/pi/left.js +23 -0
- package/dist/pi/left.js.map +1 -0
- package/dist/pi/storage.d.ts +19 -76
- package/dist/pi/storage.d.ts.map +1 -1
- package/dist/pi/storage.js +50 -368
- package/dist/pi/storage.js.map +1 -1
- package/dist/pi/tools.d.ts +12 -0
- package/dist/pi/tools.d.ts.map +1 -0
- package/dist/pi/tools.js +70 -0
- package/dist/pi/tools.js.map +1 -0
- package/package.json +11 -254
- package/src/pi/factory.ts +231 -0
- package/src/pi/index.ts +31 -759
- package/src/pi/keepalive.ts +46 -56
- package/src/pi/left.ts +52 -0
- package/src/pi/storage.ts +75 -409
- package/src/pi/tools.ts +78 -0
- package/dist/agentlib/agent.d.ts +0 -32
- package/dist/agentlib/agent.d.ts.map +0 -1
- package/dist/agentlib/agent.js +0 -174
- package/dist/agentlib/agent.js.map +0 -1
- package/dist/agentlib/index.d.ts +0 -5
- package/dist/agentlib/index.d.ts.map +0 -1
- package/dist/agentlib/index.js +0 -15
- package/dist/agentlib/index.js.map +0 -1
- package/dist/agentlib/messages.d.ts +0 -39
- package/dist/agentlib/messages.d.ts.map +0 -1
- package/dist/agentlib/messages.js +0 -177
- package/dist/agentlib/messages.js.map +0 -1
- package/dist/agentlib/model.d.ts +0 -31
- package/dist/agentlib/model.d.ts.map +0 -1
- package/dist/agentlib/model.js +0 -140
- package/dist/agentlib/model.js.map +0 -1
- package/dist/agentlib/options.d.ts +0 -58
- package/dist/agentlib/options.d.ts.map +0 -1
- package/dist/agentlib/options.js +0 -2
- package/dist/agentlib/options.js.map +0 -1
- package/dist/agentlib/runtime.d.ts +0 -37
- package/dist/agentlib/runtime.d.ts.map +0 -1
- package/dist/agentlib/runtime.js +0 -216
- package/dist/agentlib/runtime.js.map +0 -1
- package/dist/agentlib/state.d.ts +0 -114
- package/dist/agentlib/state.d.ts.map +0 -1
- package/dist/agentlib/state.js +0 -52
- package/dist/agentlib/state.js.map +0 -1
- package/dist/agentlib/steering.d.ts +0 -23
- package/dist/agentlib/steering.d.ts.map +0 -1
- package/dist/agentlib/steering.js +0 -48
- package/dist/agentlib/steering.js.map +0 -1
- package/dist/agentlib/tools.d.ts +0 -33
- package/dist/agentlib/tools.d.ts.map +0 -1
- package/dist/agentlib/tools.js +0 -245
- package/dist/agentlib/tools.js.map +0 -1
- package/dist/agentlib/turn.d.ts +0 -82
- package/dist/agentlib/turn.d.ts.map +0 -1
- package/dist/agentlib/turn.js +0 -253
- package/dist/agentlib/turn.js.map +0 -1
- package/dist/calls.d.ts +0 -90
- package/dist/calls.d.ts.map +0 -1
- package/dist/calls.js +0 -241
- package/dist/calls.js.map +0 -1
- package/dist/claude/index.d.ts +0 -106
- package/dist/claude/index.d.ts.map +0 -1
- package/dist/claude/index.js +0 -386
- package/dist/claude/index.js.map +0 -1
- package/dist/client.d.ts +0 -90
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -88
- package/dist/client.js.map +0 -1
- package/dist/common.d.ts +0 -410
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -563
- package/dist/common.js.map +0 -1
- package/dist/companion.d.ts +0 -286
- package/dist/companion.d.ts.map +0 -1
- package/dist/companion.js +0 -463
- package/dist/companion.js.map +0 -1
- package/dist/conversation.d.ts +0 -576
- package/dist/conversation.d.ts.map +0 -1
- package/dist/conversation.js +0 -1476
- package/dist/conversation.js.map +0 -1
- package/dist/deepseek/barriers.d.ts +0 -11
- package/dist/deepseek/barriers.d.ts.map +0 -1
- package/dist/deepseek/barriers.js +0 -36
- package/dist/deepseek/barriers.js.map +0 -1
- package/dist/deepseek/index.d.ts +0 -97
- package/dist/deepseek/index.d.ts.map +0 -1
- package/dist/deepseek/index.js +0 -603
- package/dist/deepseek/index.js.map +0 -1
- package/dist/deepseek/persistence.d.ts +0 -83
- package/dist/deepseek/persistence.d.ts.map +0 -1
- package/dist/deepseek/persistence.js +0 -262
- package/dist/deepseek/persistence.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/langgraph/checkpointer.d.ts +0 -52
- package/dist/langgraph/checkpointer.d.ts.map +0 -1
- package/dist/langgraph/checkpointer.js +0 -477
- package/dist/langgraph/checkpointer.js.map +0 -1
- package/dist/langgraph/context.d.ts +0 -10
- package/dist/langgraph/context.d.ts.map +0 -1
- package/dist/langgraph/context.js +0 -21
- package/dist/langgraph/context.js.map +0 -1
- package/dist/langgraph/errors.d.ts +0 -16
- package/dist/langgraph/errors.d.ts.map +0 -1
- package/dist/langgraph/errors.js +0 -30
- package/dist/langgraph/errors.js.map +0 -1
- package/dist/langgraph/graph.d.ts +0 -25
- package/dist/langgraph/graph.d.ts.map +0 -1
- package/dist/langgraph/graph.js +0 -378
- package/dist/langgraph/graph.js.map +0 -1
- package/dist/langgraph/index.d.ts +0 -119
- package/dist/langgraph/index.d.ts.map +0 -1
- package/dist/langgraph/index.js +0 -325
- package/dist/langgraph/index.js.map +0 -1
- package/dist/langgraph/keepalive.d.ts +0 -16
- package/dist/langgraph/keepalive.d.ts.map +0 -1
- package/dist/langgraph/keepalive.js +0 -51
- package/dist/langgraph/keepalive.js.map +0 -1
- package/dist/langgraph/nodes.d.ts +0 -71
- package/dist/langgraph/nodes.d.ts.map +0 -1
- package/dist/langgraph/nodes.js +0 -148
- package/dist/langgraph/nodes.js.map +0 -1
- package/dist/messages.d.ts +0 -18
- package/dist/messages.d.ts.map +0 -1
- package/dist/messages.js +0 -182
- package/dist/messages.js.map +0 -1
- package/dist/object.d.ts +0 -213
- package/dist/object.d.ts.map +0 -1
- package/dist/object.js +0 -309
- package/dist/object.js.map +0 -1
- package/dist/opencode/db.d.ts +0 -81
- package/dist/opencode/db.d.ts.map +0 -1
- package/dist/opencode/db.js +0 -249
- package/dist/opencode/db.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -184
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -1079
- package/dist/opencode/index.js.map +0 -1
- package/dist/output.d.ts +0 -25
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -99
- package/dist/output.js.map +0 -1
- package/dist/pi/commits.d.ts +0 -6
- package/dist/pi/commits.d.ts.map +0 -1
- package/dist/pi/commits.js +0 -3
- package/dist/pi/commits.js.map +0 -1
- package/dist/steering.d.ts +0 -32
- package/dist/steering.d.ts.map +0 -1
- package/dist/steering.js +0 -45
- package/dist/steering.js.map +0 -1
- package/dist/tools.d.ts +0 -267
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -305
- package/dist/tools.js.map +0 -1
- package/dist/webhook.d.ts +0 -71
- package/dist/webhook.d.ts.map +0 -1
- package/dist/webhook.js +0 -102
- package/dist/webhook.js.map +0 -1
- package/src/agentlib/README.md +0 -229
- package/src/agentlib/agent.ts +0 -216
- package/src/agentlib/index.ts +0 -16
- package/src/agentlib/messages.ts +0 -207
- package/src/agentlib/model.ts +0 -156
- package/src/agentlib/options.ts +0 -62
- package/src/agentlib/runtime.ts +0 -252
- package/src/agentlib/state.ts +0 -93
- package/src/agentlib/steering.ts +0 -53
- package/src/agentlib/tools.ts +0 -355
- package/src/agentlib/turn.ts +0 -302
- package/src/calls.ts +0 -333
- package/src/claude/README.md +0 -107
- package/src/claude/index.ts +0 -487
- package/src/client.ts +0 -187
- package/src/common.ts +0 -766
- package/src/companion.ts +0 -675
- package/src/conversation.ts +0 -1799
- package/src/deepseek/README.md +0 -202
- package/src/deepseek/barriers.ts +0 -63
- package/src/deepseek/index.ts +0 -740
- package/src/deepseek/persistence.ts +0 -337
- package/src/index.ts +0 -41
- package/src/langgraph/README.md +0 -199
- package/src/langgraph/checkpointer.ts +0 -614
- package/src/langgraph/context.ts +0 -27
- package/src/langgraph/errors.ts +0 -26
- package/src/langgraph/graph.ts +0 -422
- package/src/langgraph/index.ts +0 -500
- package/src/langgraph/keepalive.ts +0 -58
- package/src/langgraph/nodes.ts +0 -247
- package/src/messages.ts +0 -244
- package/src/object.ts +0 -454
- package/src/opencode/README.md +0 -249
- package/src/opencode/db.ts +0 -387
- package/src/opencode/index.ts +0 -1339
- package/src/output.ts +0 -116
- package/src/pi/README.md +0 -174
- package/src/pi/commits.ts +0 -7
- package/src/steering.ts +0 -68
- package/src/tools.ts +0 -515
- package/src/webhook.ts +0 -161
package/dist/langgraph/graph.js
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
// An agent whose `chat` runs a LangGraph graph of your own:
|
|
2
|
-
// `langgraph.agent({ name, graph })`, as the Python SDK's
|
|
3
|
-
// restate/agents/langgraph/_graph.py.
|
|
4
|
-
//
|
|
5
|
-
// The graph's state has LangGraph's `messages` (`MessagesAnnotation`), and
|
|
6
|
-
// each message to the agent is a run of the graph on the key's thread, with
|
|
7
|
-
// the message as a new `HumanMessage`:
|
|
8
|
-
//
|
|
9
|
-
// - The graph's checkpoints are in the key's database (`SqlCheckpointSaver`),
|
|
10
|
-
// stored before each step runs (`durability: 'sync'`; a step's writes
|
|
11
|
-
// with its checkpoint, see checkpointer.ts; LangGraph awaits them all
|
|
12
|
-
// before a run ends, an error or a stop included), and the prebuilt
|
|
13
|
-
// nodes (nodes.ts) and the tools of `tools()` get the handler's context
|
|
14
|
-
// there (context.ts). LangGraph's run context is the graph's own (`context`),
|
|
15
|
-
// else the handler's. A retried attempt resumes the run it cut off. A run
|
|
16
|
-
// that finishes prunes the thread to the latest checkpoint of each
|
|
17
|
-
// namespace, and what LangGraph rebuilds its delta channels from.
|
|
18
|
-
// - Any error of the run fails the attempt, and Restate retries it: none is
|
|
19
|
-
// taken for a model provider's refusal, as the built-in agent's model's
|
|
20
|
-
// can be, since a graph's models, tools and nodes are all its own. A
|
|
21
|
-
// `TerminalError` ends the turn, and so do LangGraph's own errors that a
|
|
22
|
-
// retry would meet again (errors.ts). A run that an invalid update ended
|
|
23
|
-
// leaves writes that LangGraph cannot apply: the next message starts its
|
|
24
|
-
// run from the checkpoint before them, as a new run discards them.
|
|
25
|
-
// - After each step, the AI and tool messages the step added are copied into
|
|
26
|
-
// the agent's conversation, by their ids, so that the `messages` view (and
|
|
27
|
-
// `watch`) shows the run as it goes. They are the messages after the run's
|
|
28
|
-
// prompt; if the graph trimmed the prompt away, those whose ids the
|
|
29
|
-
// conversation does not have. With `durability: 'sync'`, LangGraph streams
|
|
30
|
-
// a step's state only once its checkpoint is stored, so the conversation
|
|
31
|
-
// never gets ahead of the checkpoints; a crash between a checkpoint and its
|
|
32
|
-
// copy is made up by the next step's state, as messages are copied by id.
|
|
33
|
-
// The conversation is a log: a message the graph removes or edits later
|
|
34
|
-
// stays as it was copied.
|
|
35
|
-
// - The answer is the text of the run's last AI message. A graph that writes
|
|
36
|
-
// a `structuredResponse` in the run (LangChain's `createAgent` with a
|
|
37
|
-
// `responseFormat`) answers with it instead, as JSON, which `output`
|
|
38
|
-
// validates; one left from an earlier run is not the answer.
|
|
39
|
-
// - LangGraph's `interrupt()` waits for a signal: each pending interrupt is
|
|
40
|
-
// a wait named `interrupt`, which the agent's `pending` view lists with the
|
|
41
|
-
// interrupt's value, and which `signal` resolves (by the wait's id, or as
|
|
42
|
-
// the oldest `interrupt`). The run then resumes with `new Command({ resume
|
|
43
|
-
// })`, the signal's value as `interrupt()`'s result. The turn waits without
|
|
44
|
-
// holding a process; a retried attempt joins the same waits. Static
|
|
45
|
-
// breakpoints (`interruptBefore`, `interruptAfter`) have nothing to wait
|
|
46
|
-
// for: a compiled graph with them is refused, and a run that stops at a
|
|
47
|
-
// subgraph's fails.
|
|
48
|
-
// - A stopped run is not resumed: the next message starts a run of its own,
|
|
49
|
-
// from the state the graph had stored. What closed the stopped (or
|
|
50
|
-
// refused, or failed) run in the conversation comes first in the new run's
|
|
51
|
-
// input: the results of its cut-off tool calls, and the note that ends it,
|
|
52
|
-
// so that the graph's model knows. So does that run's message, if the graph
|
|
53
|
-
// never stored it.
|
|
54
|
-
//
|
|
55
|
-
// The graph's state is its own: its models read the state, not the
|
|
56
|
-
// conversation, so the agent's `window`, `budget` and `summarize` do not
|
|
57
|
-
// reach them. Trimming the state is the graph's job (a node that returns a
|
|
58
|
-
// `RemoveMessage` for each message to drop, say).
|
|
59
|
-
import * as restate from '@restatedev/sessions';
|
|
60
|
-
import { AIMessage, HumanMessage, ToolMessage } from '@langchain/core/messages';
|
|
61
|
-
import { mapStoredMessagesToChatMessages } from '@langchain/core/messages';
|
|
62
|
-
import { Command, InvalidUpdateError, StateGraph } from '@langchain/langgraph';
|
|
63
|
-
import { flushHeld } from '../calls.js';
|
|
64
|
-
import { fromTool, stopSignalOf } from '../common.js';
|
|
65
|
-
import { companionHere } from '../companion.js';
|
|
66
|
-
import { SqlCheckpointSaver } from './checkpointer.js';
|
|
67
|
-
import { running } from './context.js';
|
|
68
|
-
import { terminalOf } from './errors.js';
|
|
69
|
-
import { KeepModelsAlive } from './keepalive.js';
|
|
70
|
-
/** The graph's thread: there is one per key, as the key's database is its own. */
|
|
71
|
-
export const THREAD_ID = 'chat';
|
|
72
|
-
const THREAD = { configurable: { thread_id: THREAD_ID } };
|
|
73
|
-
/** Why a graph with static breakpoints is refused, and a run stopped at a subgraph's fails. */
|
|
74
|
-
export const BREAKPOINTS = 'static breakpoints (interruptBefore, interruptAfter) stop a run with nothing to wait for, and leave its tool ' +
|
|
75
|
-
'calls without results: pause the graph with interrupt() instead, which waits for a signal';
|
|
76
|
-
/**
|
|
77
|
-
* Throw a `TypeError` if `graph` has no `messages` in its state, or is
|
|
78
|
-
* compiled with static breakpoints. A subgraph's static breakpoints are found
|
|
79
|
-
* when one stops a run, which then fails: LangGraph has no public way to find
|
|
80
|
-
* every subgraph (a node may call one it makes).
|
|
81
|
-
*/
|
|
82
|
-
export function check(graph) {
|
|
83
|
-
if (!('messages' in graph.channels)) {
|
|
84
|
-
throw new TypeError("the graph's state has no messages: build it on LangGraph's MessagesAnnotation");
|
|
85
|
-
}
|
|
86
|
-
if (!(graph instanceof StateGraph) && (graph.interruptBefore?.length || graph.interruptAfter?.length)) {
|
|
87
|
-
throw new TypeError(BREAKPOINTS);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/** `graph` compiled with its checkpoints in `saver`. */
|
|
91
|
-
function compiled(graph, saver) {
|
|
92
|
-
if (graph instanceof StateGraph)
|
|
93
|
-
return graph.compile({ checkpointer: saver });
|
|
94
|
-
// A copy, as `withConfig` makes one: the graph is shared by every key's runs.
|
|
95
|
-
const Compiled = graph.constructor;
|
|
96
|
-
// oxlint-disable-next-line typescript/no-misused-spread -- the graph's fields, as its constructor takes them
|
|
97
|
-
return new Compiled({ ...graph, checkpointer: saver });
|
|
98
|
-
}
|
|
99
|
-
/** The key, in each checkpoint's metadata, of the prompt whose run made it: the run's input may be trimmed away. */
|
|
100
|
-
const PROMPT = 'restate_prompt';
|
|
101
|
-
/** The state field of a structured answer, as LangChain's `createAgent` writes it. */
|
|
102
|
-
const STRUCTURED = 'structuredResponse';
|
|
103
|
-
/** The key, in each checkpoint's metadata, of the version the structured answer's channel had as its run began. */
|
|
104
|
-
const STRUCTURED_BEFORE = 'restate_structured_version';
|
|
105
|
-
/** The prefixes of the ids of the messages that the conversation gave the graph, rather than the graph made. */
|
|
106
|
-
const CARRIED = ['prompt:', 'closed:'];
|
|
107
|
-
/** The ids of the graph's messages that the conversation has: those copied from it. */
|
|
108
|
-
const knownOf = (conversation) => new Set(conversation.entries.flatMap((e) => (e.item.id === undefined ? [] : [e.item.id])));
|
|
109
|
-
/** The version of the graph's structured answer's channel, which changes each time it is written. */
|
|
110
|
-
async function structuredVersion(app) {
|
|
111
|
-
const stored = await app.checkpointer.getTuple(THREAD);
|
|
112
|
-
return String(stored?.checkpoint.channel_versions[STRUCTURED] ?? '');
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The run's answer: the JSON of the structured answer it wrote, else its last
|
|
116
|
-
* AI message's text. A structured answer counts only if the run wrote it (its
|
|
117
|
-
* channel's version is not `before`): the state keeps an earlier run's. The
|
|
118
|
-
* text is read from the conversation, a log, as the graph may have trimmed
|
|
119
|
-
* its own history (the run's input and answer included).
|
|
120
|
-
*/
|
|
121
|
-
async function answerOf(app, turn, state, before) {
|
|
122
|
-
const structured = state[STRUCTURED];
|
|
123
|
-
if (structured !== undefined && structured !== null && (await structuredVersion(app)) !== before) {
|
|
124
|
-
return JSON.stringify(structured);
|
|
125
|
-
}
|
|
126
|
-
const replies = turn.items.flatMap((e) => (AIMessage.isInstance(e.item) && e.item.id !== undefined ? [e.item] : []));
|
|
127
|
-
return replies.at(-1)?.text ?? '';
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Copy the AI and tool messages of `messages` (the graph's state) that the
|
|
131
|
-
* conversation does not have yet: those after the run's prompt (whose id is
|
|
132
|
-
* `prompt`), as the state holds the earlier turns too; if the graph trimmed
|
|
133
|
-
* the prompt away, those whose ids are not `known`. `known` is the ids the
|
|
134
|
-
* conversation has, which this adds to; the messages the conversation gave
|
|
135
|
-
* the graph are not copied back. Tool messages that follow one another (a
|
|
136
|
-
* step's results) are copied in one write. Each write that commits is
|
|
137
|
-
* published, by the conversation (`Conversation.hold`); an AI message without
|
|
138
|
-
* tool calls is held, and is published with the next.
|
|
139
|
-
*/
|
|
140
|
-
async function copied(turn, known, messages, prompt) {
|
|
141
|
-
const at = messages.findIndex((m) => m.id === prompt);
|
|
142
|
-
const fresh = messages
|
|
143
|
-
.slice(at + 1)
|
|
144
|
-
.filter((m) => (AIMessage.isInstance(m) || ToolMessage.isInstance(m)) &&
|
|
145
|
-
m.id !== undefined &&
|
|
146
|
-
!known.has(m.id) &&
|
|
147
|
-
!CARRIED.some((prefix) => m.id.startsWith(prefix)));
|
|
148
|
-
let results = [];
|
|
149
|
-
// The results of a step in one write: one commit, however many tools ran.
|
|
150
|
-
const stored = async () => {
|
|
151
|
-
if (results.length === 0)
|
|
152
|
-
return;
|
|
153
|
-
await turn.append(...results);
|
|
154
|
-
for (const result of results)
|
|
155
|
-
known.add(result.id);
|
|
156
|
-
results = [];
|
|
157
|
-
};
|
|
158
|
-
for (const message of fresh) {
|
|
159
|
-
if (!AIMessage.isInstance(message)) {
|
|
160
|
-
results.push(message);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
await stored();
|
|
164
|
-
await turn.appendReply([message]);
|
|
165
|
-
known.add(message.id);
|
|
166
|
-
}
|
|
167
|
-
await stored();
|
|
168
|
-
}
|
|
169
|
-
/** The id of a turn's prompt, as a `HumanMessage` in the graph: the conversation's id of the turn. */
|
|
170
|
-
const promptIdOf = (turn) => `prompt:${turn.id}`;
|
|
171
|
-
/** `message` with the id `id`. */
|
|
172
|
-
const withId = (message, id) => {
|
|
173
|
-
const stored = message.toDict();
|
|
174
|
-
return mapStoredMessagesToChatMessages([{ ...stored, data: { ...stored.data, id } }])[0];
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* What the conversation has of the previous prompt's run that the graph does
|
|
178
|
-
* not: what closed the run, if it was stopped, refused or failed (the results
|
|
179
|
-
* of its cut-off tool calls and the note that ends it, which only the
|
|
180
|
-
* conversation has: copied messages have the graph's ids, these have none),
|
|
181
|
-
* and the previous prompt itself, if the graph never stored it (its run
|
|
182
|
-
* copied nothing). Each gets an id of its own, so that it is carried once.
|
|
183
|
-
*/
|
|
184
|
-
function closing(conversation, turn, messages) {
|
|
185
|
-
const turns = conversation.turns;
|
|
186
|
-
const at = turns.indexOf(turn);
|
|
187
|
-
if (at <= 0)
|
|
188
|
-
return [];
|
|
189
|
-
const previous = turns[at - 1];
|
|
190
|
-
const known = new Set(messages.map((m) => m.id));
|
|
191
|
-
const copiedAny = previous.items.some((e) => e.item.id !== undefined);
|
|
192
|
-
// Only a turn the conversation closed (stopped, refused, failed, ended) has messages the graph lacks.
|
|
193
|
-
const closed = previous.status !== undefined && previous.status !== 'answered';
|
|
194
|
-
const carried = [];
|
|
195
|
-
for (const entry of previous.entries) {
|
|
196
|
-
const item = entry.item;
|
|
197
|
-
if (entry.prompt !== undefined) {
|
|
198
|
-
if (!copiedAny && !known.has(promptIdOf(previous))) {
|
|
199
|
-
carried.push(new HumanMessage({ content: item.text, id: promptIdOf(previous) }));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
else if (closed && !HumanMessage.isInstance(item) && item.id === undefined && !known.has(`closed:${entry.n}`)) {
|
|
203
|
-
carried.push(withId(item, `closed:${entry.n}`));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return carried;
|
|
207
|
-
}
|
|
208
|
-
/** The name of the signal that answers LangGraph's `interrupt()`. */
|
|
209
|
-
export const INTERRUPT = 'interrupt';
|
|
210
|
-
/**
|
|
211
|
-
* The pending interrupts of the run, each once: LangGraph keeps each on the
|
|
212
|
-
* task whose step raised it, a subgraph's included, and each graph above that
|
|
213
|
-
* task lists it again, under the same id.
|
|
214
|
-
*/
|
|
215
|
-
function interruptsOf(snapshot) {
|
|
216
|
-
const pending = new Map();
|
|
217
|
-
for (const task of snapshot.tasks) {
|
|
218
|
-
for (const interrupted of task.interrupts ?? []) {
|
|
219
|
-
if (interrupted.id !== undefined && !pending.has(interrupted.id)) {
|
|
220
|
-
pending.set(interrupted.id, { id: interrupted.id, value: interrupted.value });
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return [...pending.values()];
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* How many resume values the thread's pending writes hold: one more each
|
|
228
|
-
* time an `interrupt()` is answered, until its step ends. LangGraph gives an
|
|
229
|
-
* interrupt the id of its task's namespace, so a node's second `interrupt()`
|
|
230
|
-
* has its first's id: the count tells them apart.
|
|
231
|
-
*/
|
|
232
|
-
async function resumesOf(ctx, saver) {
|
|
233
|
-
const rows = await ctx.db.values("SELECT type, value FROM restate_langgraph_writes WHERE thread_id = ? AND channel = '__resume__'", [THREAD_ID]);
|
|
234
|
-
let count = 0;
|
|
235
|
-
for (const [type, value] of rows) {
|
|
236
|
-
const resumes = await saver.serde.loadsTyped(String(type), value);
|
|
237
|
-
count += Array.isArray(resumes) ? resumes.length : 1;
|
|
238
|
-
}
|
|
239
|
-
return count;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Wait for a signal for each pending interrupt of `snapshot`, and return
|
|
243
|
-
* their values by interrupt id, or `undefined` if none is pending. Each
|
|
244
|
-
* wait's id is the turn's invocation id (the same in each attempt), the
|
|
245
|
-
* interrupt's id, and the count of resume values stored (see
|
|
246
|
-
* {@link resumesOf}): a retried attempt joins the same waits, and a turn that
|
|
247
|
-
* ends without them has them closed, as the companion closes the waits whose
|
|
248
|
-
* ids start with the turn's.
|
|
249
|
-
*/
|
|
250
|
-
async function resumed(ctx, saver, snapshot) {
|
|
251
|
-
const pending = interruptsOf(snapshot);
|
|
252
|
-
if (pending.length === 0)
|
|
253
|
-
return undefined;
|
|
254
|
-
// Checked before anything is stored: an object without a companion has no one to wait with.
|
|
255
|
-
const companion = companionHere(ctx, 'a wait for an interrupt');
|
|
256
|
-
// What the turn holds back is written before it waits: the waits outlive the attempt.
|
|
257
|
-
await flushHeld(ctx);
|
|
258
|
-
const resumes = await resumesOf(ctx, saver);
|
|
259
|
-
const values = await Promise.all(pending.map(({ id, value }) => {
|
|
260
|
-
const waitId = `${ctx.request.id}:interrupt:${id}:${resumes}`;
|
|
261
|
-
// As JSON, which the companion stores: the state may hold class instances.
|
|
262
|
-
const input = value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
263
|
-
return ctx
|
|
264
|
-
.rpc(companion, ctx.key, { idempotencyKey: waitId })
|
|
265
|
-
.wait({ id: waitId, name: INTERRUPT, ...(input === undefined ? {} : { input }) });
|
|
266
|
-
}));
|
|
267
|
-
return Object.fromEntries(pending.map(({ id }, i) => [id, values[i]]));
|
|
268
|
-
}
|
|
269
|
-
/** Whether a run stopped with steps to go and no interrupt: at a static breakpoint. */
|
|
270
|
-
const atBreakpoint = (paused) => paused.next.length > 0 && !paused.tasks.some((task) => (task.interrupts ?? []).length > 0);
|
|
271
|
-
/**
|
|
272
|
-
* The state of the graph's thread: where it stopped, and why (its tasks'
|
|
273
|
-
* interrupts). If the writes of the last step's tasks do not fit the state
|
|
274
|
-
* (an invalid update), it is the state of the checkpoint itself, which
|
|
275
|
-
* LangGraph shows without them: a run with new input discards them.
|
|
276
|
-
*/
|
|
277
|
-
async function storedState(app) {
|
|
278
|
-
try {
|
|
279
|
-
return await app.getState(THREAD);
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
if (!(error instanceof InvalidUpdateError))
|
|
283
|
-
throw error;
|
|
284
|
-
const latest = await app.checkpointer.getTuple(THREAD);
|
|
285
|
-
if (!latest)
|
|
286
|
-
throw error;
|
|
287
|
-
return app.getState(latest.config);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* The run of a prompt: the graph's, on the key's thread, from the prompt to
|
|
292
|
-
* its answer. `context` is the graph's run context, if not the handler's.
|
|
293
|
-
*/
|
|
294
|
-
export const graphRun = (ctx, graph, context) => (conversation) => running(ctx, () => runGraph(ctx, graph, context ?? ctx, conversation));
|
|
295
|
-
async function runGraph(ctx, graph, context, conversation) {
|
|
296
|
-
const turn = conversation.turn;
|
|
297
|
-
// The run's input: the turn's prompt, or the message that asked again within the turn, under an id of its own.
|
|
298
|
-
const step = turn.latestAsk();
|
|
299
|
-
const promptId = step === turn.prompt ? promptIdOf(turn) : `${promptIdOf(turn)}:again:${step.n}`;
|
|
300
|
-
const app = compiled(graph, new SqlCheckpointSaver(ctx.db));
|
|
301
|
-
const snapshot = await storedState(app);
|
|
302
|
-
let values = snapshot.values;
|
|
303
|
-
const messages = (values.messages ?? []);
|
|
304
|
-
const known = knownOf(conversation);
|
|
305
|
-
const metadata = (snapshot.metadata ?? {});
|
|
306
|
-
const asked = metadata[PROMPT] === promptId;
|
|
307
|
-
const stamped = metadata[STRUCTURED_BEFORE];
|
|
308
|
-
const before = asked ? (typeof stamped === 'string' ? stamped : '') : await structuredVersion(app);
|
|
309
|
-
// Each checkpoint of the run names its prompt, so that a retried attempt finds the run it cut off, and the
|
|
310
|
-
// version its structured answer had before it.
|
|
311
|
-
const saver = new SqlCheckpointSaver(ctx.db, { metadata: { [PROMPT]: promptId, [STRUCTURED_BEFORE]: before } });
|
|
312
|
-
const run = compiled(graph, saver);
|
|
313
|
-
// Each request of a model is kept alive, wherever the graph makes it (see keepalive.ts).
|
|
314
|
-
const kept = new KeepModelsAlive(ctx);
|
|
315
|
-
const options = {
|
|
316
|
-
...THREAD,
|
|
317
|
-
context,
|
|
318
|
-
durability: 'sync',
|
|
319
|
-
streamMode: 'values',
|
|
320
|
-
signal: stopSignalOf(ctx),
|
|
321
|
-
callbacks: [kept],
|
|
322
|
-
};
|
|
323
|
-
// `next` leaves out the tasks whose writes are stored, so a step whose writes were stored before its checkpoint
|
|
324
|
-
// (a crash between them) has no `next` but still has tasks: that run goes on, from those writes, without running
|
|
325
|
-
// the tasks again. A finished run has no tasks.
|
|
326
|
-
if (asked && snapshot.tasks.length === 0) {
|
|
327
|
-
// The run had finished, but its answer was not stored: that is the answer, rather than run again.
|
|
328
|
-
await copied(turn, known, messages, promptId);
|
|
329
|
-
await saver.prune([THREAD_ID]);
|
|
330
|
-
return answerOf(run, turn, values, before);
|
|
331
|
-
}
|
|
332
|
-
// A run cut off by a crash is resumed: first by the signals its pending interrupts wait for, if any. A new
|
|
333
|
-
// message (or one after a stopped run) starts a run, after what closed the previous run.
|
|
334
|
-
let start;
|
|
335
|
-
if (asked) {
|
|
336
|
-
const resumes = await resumed(ctx, saver, await storedState(run));
|
|
337
|
-
start = resumes === undefined ? null : new Command({ resume: resumes });
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
const prompt = new HumanMessage({ content: step.item.text, id: promptId });
|
|
341
|
-
const closed = step === turn.prompt ? closing(conversation, turn, messages) : [];
|
|
342
|
-
start = { messages: [...closed, prompt] };
|
|
343
|
-
}
|
|
344
|
-
for (;;) {
|
|
345
|
-
try {
|
|
346
|
-
for await (const state of await run.stream(start, options)) {
|
|
347
|
-
values = state;
|
|
348
|
-
await copied(turn, known, (state.messages ?? []), promptId);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
// LangGraph's own error, which a retry would meet again: a run past its recursion limit, say.
|
|
353
|
-
const terminal = terminalOf(error);
|
|
354
|
-
if (terminal)
|
|
355
|
-
throw terminal;
|
|
356
|
-
// No refusal, whatever its name: a graph's models, tools and nodes are all its own.
|
|
357
|
-
fromTool(ctx, error);
|
|
358
|
-
throw error;
|
|
359
|
-
}
|
|
360
|
-
finally {
|
|
361
|
-
// A request that never reported its end (a stopped run's) must not keep the attempt alive while it waits.
|
|
362
|
-
kept.releaseAll();
|
|
363
|
-
}
|
|
364
|
-
// The run stops at its interrupts: it goes on with the signals that answer them.
|
|
365
|
-
const paused = await storedState(run);
|
|
366
|
-
const resumes = await resumed(ctx, saver, paused);
|
|
367
|
-
if (resumes === undefined) {
|
|
368
|
-
// At a subgraph's static breakpoint, which check() does not look for: fail, rather than answer half done.
|
|
369
|
-
if (atBreakpoint(paused))
|
|
370
|
-
throw new restate.TerminalError(BREAKPOINTS);
|
|
371
|
-
// Only the latest checkpoint of each namespace is read again; a paused or cut-off run keeps it too.
|
|
372
|
-
await saver.prune([THREAD_ID]);
|
|
373
|
-
return answerOf(run, turn, values, before);
|
|
374
|
-
}
|
|
375
|
-
start = new Command({ resume: resumes });
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
//# sourceMappingURL=graph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/langgraph/graph.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,0DAA0D;AAC1D,sCAAsC;AACtC,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,uCAAuC;AACvC,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,0EAA0E;AAC1E,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,oEAAoE;AACpE,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AACrE,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;AACtE,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,0EAA0E;AAC1E,4BAA4B;AAC5B,6EAA6E;AAC7E,wEAAwE;AACxE,uEAAuE;AACvE,+DAA+D;AAC/D,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,2EAA2E;AAC3E,0EAA0E;AAC1E,sBAAsB;AACtB,4EAA4E;AAC5E,qEAAqE;AACrE,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,qBAAqB;AACrB,EAAE;AACF,mEAAmE;AACnE,yEAAyE;AACzE,2EAA2E;AAC3E,kDAAkD;AAClD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAoB,YAAY,EAAE,WAAW,EAAE,M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AC;YAC1B,0GAA0G;YAC1G,IAAI,YAAY,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YACvE,oGAAoG;YACpG,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/B,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK,GAAG,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type * as restate from '@restatedev/sessions';
|
|
2
|
-
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
3
|
-
import { type BaseMessage } from '@langchain/core/messages';
|
|
4
|
-
import { type StructuredToolInterface } from '@langchain/core/tools';
|
|
5
|
-
import { type Configure, type Summarize } from '../common.ts';
|
|
6
|
-
import { type Items } from '../conversation.ts';
|
|
7
|
-
import { type Answer } from '../output.ts';
|
|
8
|
-
import type { z } from 'zod';
|
|
9
|
-
import { type Definition } from '../object.ts';
|
|
10
|
-
import { type Tool as AnyTool } from '../tools.ts';
|
|
11
|
-
import { SqlCheckpointSaver } from './checkpointer.ts';
|
|
12
|
-
import { type AnyGraph } from './graph.ts';
|
|
13
|
-
export { SqlCheckpointSaver };
|
|
14
|
-
export { type AnyGraph, INTERRUPT } from './graph.ts';
|
|
15
|
-
export * as nodes from './nodes.ts';
|
|
16
|
-
/**
|
|
17
|
-
* LangGraph's items: LangChain's messages, stored as their `toDict()`. A
|
|
18
|
-
* human message is said by the user; an AI message by the assistant, with
|
|
19
|
-
* its `tool_calls` as calls; a tool message is a result (an error if its
|
|
20
|
-
* status says so).
|
|
21
|
-
*/
|
|
22
|
-
export declare const items: Items<BaseMessage>;
|
|
23
|
-
/**
|
|
24
|
-
* `given` as LangChain tools, for a graph of your own or LangChain's
|
|
25
|
-
* `createAgent`:
|
|
26
|
-
*
|
|
27
|
-
* const graph = createAgent({ model, tools: langgraph.tools([call(orders, 'status', { description: '…' })]) });
|
|
28
|
-
* const desk = langgraph.agent({ name: 'desk', graph });
|
|
29
|
-
*
|
|
30
|
-
* Restate's tools (`call`, `send`, `workflow`, `subagent`, `signal`) make
|
|
31
|
-
* their Restate calls once per tool call, even if a crash runs the tool call
|
|
32
|
-
* again: the model's reply, with the tool call's id, is checkpointed before
|
|
33
|
-
* the tools run. A `tool()` of your own runs your function, again after a
|
|
34
|
-
* crash, as do LangChain's tools, which are passed through. They take the
|
|
35
|
-
* handler's context from the graph's run (`langgraph.agent({ graph })` gives
|
|
36
|
-
* it; a handler of your own passes `context: ctx`).
|
|
37
|
-
*/
|
|
38
|
-
export declare const tools: (given: (AnyTool | StructuredToolInterface)[]) => StructuredToolInterface[];
|
|
39
|
-
/** An agent's options: `chat` and `prompt` take them. */
|
|
40
|
-
export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
|
|
41
|
-
/** The model: `openai/model-id` or `anthropic/model-id` (MODEL, or else openai/gpt-6-sol), or a chat model that calls tools. */
|
|
42
|
-
model?: string | BaseChatModel;
|
|
43
|
-
/** The system prompt: who the agent is, and how it answers. */
|
|
44
|
-
system?: string;
|
|
45
|
-
/** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or LangChain's. */
|
|
46
|
-
tools?: (AnyTool | StructuredToolInterface)[];
|
|
47
|
-
/** How many steps of the graph a turn takes at most (default 10 000): past it, the turn fails for good. */
|
|
48
|
-
recursionLimit?: number;
|
|
49
|
-
/**
|
|
50
|
-
* The answer as data: a zod object, whose JSON the agent replies with
|
|
51
|
-
* (checked), and `chat` and `prompt` answer with (see output.ts). With
|
|
52
|
-
* `graph`, the graph's own prompts must ask for it.
|
|
53
|
-
*/
|
|
54
|
-
output?: O;
|
|
55
|
-
/**
|
|
56
|
-
* A graph of your own to run, instead of the built-in tool-calling loop
|
|
57
|
-
* (graph.ts): a `StateGraph` whose state has `messages`, or a compiled one
|
|
58
|
-
* (such as LangChain's `createAgent` makes). It has its own model and
|
|
59
|
-
* tools, so it takes no `model`, `system`, `tools` or `recursionLimit`.
|
|
60
|
-
*/
|
|
61
|
-
graph?: AnyGraph;
|
|
62
|
-
/**
|
|
63
|
-
* The run context of `graph` (LangGraph's `context`), for a graph with a
|
|
64
|
-
* context schema of its own. By default the handler's context. The
|
|
65
|
-
* prebuilt `nodes` and the tools of `tools()` get the handler's context
|
|
66
|
-
* either way.
|
|
67
|
-
*/
|
|
68
|
-
context?: unknown;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
|
|
72
|
-
* of an invocation is a prompt of its own.
|
|
73
|
-
* With `output`, it answers with the value the agent replies with (see
|
|
74
|
-
* output.ts), not its text: a reply that is not one is asked again within
|
|
75
|
-
* its turn, once.
|
|
76
|
-
*/
|
|
77
|
-
export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
|
|
78
|
-
/**
|
|
79
|
-
* A chat handler: each message an invocation, the conversation in the
|
|
80
|
-
* object's database, with `options`, or the options a function of the
|
|
81
|
-
* invocation's context gives. It takes the message as plain text
|
|
82
|
-
* (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
|
|
83
|
-
*/
|
|
84
|
-
export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
|
|
85
|
-
input: restate.Serde<string>;
|
|
86
|
-
accept: string;
|
|
87
|
-
explicitCancellation: boolean;
|
|
88
|
-
handler: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* A view of the conversation as clients read it: a page at a time, or what
|
|
92
|
-
* is new or changed since a cursor; `view: 'summary'` for each turn's
|
|
93
|
-
* message and answer. It answers while a message is answered.
|
|
94
|
-
*/
|
|
95
|
-
export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
96
|
-
/**
|
|
97
|
-
* How an agent of `model` summarizes the earliest turns, past its budget:
|
|
98
|
-
* with its own model (`agent()` gives it; for an object of your own,
|
|
99
|
-
* `sessionObject`'s `summarize`).
|
|
100
|
-
*/
|
|
101
|
-
export declare const summarizer: (model?: Options['model']) => Summarize;
|
|
102
|
-
/** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
|
|
103
|
-
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, {
|
|
104
|
-
signal: (ctx: import("../common.ts").AgentViewContext, signal: import("../companion.ts").Signal) => Promise<import("../companion.ts").Resolved>;
|
|
105
|
-
pending: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Waiting[]>;
|
|
106
|
-
status: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Status>;
|
|
107
|
-
stop: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
108
|
-
notifications: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Notifications>;
|
|
109
|
-
watch: (ctx: import("../common.ts").AgentViewContext, watch: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
|
|
110
|
-
} & {
|
|
111
|
-
clear: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
112
|
-
steer: (ctx: import("../common.ts").AgentViewContext, text: string) => Promise<import("../companion.ts").Steered>;
|
|
113
|
-
sync: (ctx: import("../common.ts").AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
|
|
114
|
-
} & {
|
|
115
|
-
chat: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
116
|
-
} & {
|
|
117
|
-
messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
118
|
-
}>;
|
|
119
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/langgraph/index.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAEL,KAAK,WAAW,EAOjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,uBAAuB,EAAmC,MAAM,uBAAuB,CAAC;AAGtG,OAAO,EAEL,KAAK,SAAS,EASd,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAiC,KAAK,KAAK,EAAuB,MAAM,oBAAoB,CAAC;AAEpG,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;AAE9D,OAAO,EAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAyB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG9E,OAAO,EAAE,KAAK,QAAQ,EAAiC,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,WAAW,CA8BpC,CAAC;AAgNF;;;;;;;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