@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.
Files changed (136) hide show
  1. package/README.md +89 -49
  2. package/dist/calls.d.ts +29 -8
  3. package/dist/calls.d.ts.map +1 -1
  4. package/dist/calls.js +79 -18
  5. package/dist/calls.js.map +1 -1
  6. package/dist/claude/index.d.ts +36 -7
  7. package/dist/claude/index.d.ts.map +1 -1
  8. package/dist/claude/index.js +238 -156
  9. package/dist/claude/index.js.map +1 -1
  10. package/dist/client.d.ts +12 -3
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js.map +1 -1
  13. package/dist/common.d.ts +161 -71
  14. package/dist/common.d.ts.map +1 -1
  15. package/dist/common.js +277 -226
  16. package/dist/common.js.map +1 -1
  17. package/dist/conversation.d.ts +466 -0
  18. package/dist/conversation.d.ts.map +1 -0
  19. package/dist/conversation.js +1247 -0
  20. package/dist/conversation.js.map +1 -0
  21. package/dist/deepseek/index.d.ts +38 -5
  22. package/dist/deepseek/index.d.ts.map +1 -1
  23. package/dist/deepseek/index.js +323 -107
  24. package/dist/deepseek/index.js.map +1 -1
  25. package/dist/deepseek/persistence.d.ts +9 -3
  26. package/dist/deepseek/persistence.d.ts.map +1 -1
  27. package/dist/deepseek/persistence.js +12 -6
  28. package/dist/deepseek/persistence.js.map +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/langgraph/checkpointer.d.ts +16 -2
  34. package/dist/langgraph/checkpointer.d.ts.map +1 -1
  35. package/dist/langgraph/checkpointer.js +133 -26
  36. package/dist/langgraph/checkpointer.js.map +1 -1
  37. package/dist/langgraph/context.d.ts +10 -0
  38. package/dist/langgraph/context.d.ts.map +1 -0
  39. package/dist/langgraph/context.js +21 -0
  40. package/dist/langgraph/context.js.map +1 -0
  41. package/dist/langgraph/errors.d.ts +16 -0
  42. package/dist/langgraph/errors.d.ts.map +1 -0
  43. package/dist/langgraph/errors.js +30 -0
  44. package/dist/langgraph/errors.js.map +1 -0
  45. package/dist/langgraph/graph.d.ts +25 -0
  46. package/dist/langgraph/graph.d.ts.map +1 -0
  47. package/dist/langgraph/graph.js +346 -0
  48. package/dist/langgraph/graph.js.map +1 -0
  49. package/dist/langgraph/index.d.ts +65 -12
  50. package/dist/langgraph/index.d.ts.map +1 -1
  51. package/dist/langgraph/index.js +234 -180
  52. package/dist/langgraph/index.js.map +1 -1
  53. package/dist/langgraph/nodes.d.ts +70 -0
  54. package/dist/langgraph/nodes.d.ts.map +1 -0
  55. package/dist/langgraph/nodes.js +145 -0
  56. package/dist/langgraph/nodes.js.map +1 -0
  57. package/dist/messages.d.ts +18 -0
  58. package/dist/messages.d.ts.map +1 -0
  59. package/dist/messages.js +182 -0
  60. package/dist/messages.js.map +1 -0
  61. package/dist/object.d.ts +65 -23
  62. package/dist/object.d.ts.map +1 -1
  63. package/dist/object.js +123 -40
  64. package/dist/object.js.map +1 -1
  65. package/dist/output.d.ts +15 -7
  66. package/dist/output.d.ts.map +1 -1
  67. package/dist/output.js +44 -26
  68. package/dist/output.js.map +1 -1
  69. package/dist/pi/index.d.ts +39 -11
  70. package/dist/pi/index.d.ts.map +1 -1
  71. package/dist/pi/index.js +281 -77
  72. package/dist/pi/index.js.map +1 -1
  73. package/dist/pi/storage.d.ts +29 -4
  74. package/dist/pi/storage.d.ts.map +1 -1
  75. package/dist/pi/storage.js +18 -6
  76. package/dist/pi/storage.js.map +1 -1
  77. package/dist/signals.d.ts +75 -7
  78. package/dist/signals.d.ts.map +1 -1
  79. package/dist/signals.js +154 -27
  80. package/dist/signals.js.map +1 -1
  81. package/dist/steering.d.ts +31 -0
  82. package/dist/steering.d.ts.map +1 -0
  83. package/dist/steering.js +45 -0
  84. package/dist/steering.js.map +1 -0
  85. package/dist/tools.d.ts +28 -0
  86. package/dist/tools.d.ts.map +1 -1
  87. package/dist/tools.js +34 -5
  88. package/dist/tools.js.map +1 -1
  89. package/package.json +33 -37
  90. package/src/calls.ts +110 -24
  91. package/src/claude/README.md +41 -20
  92. package/src/claude/index.ts +271 -183
  93. package/src/client.ts +14 -3
  94. package/src/common.ts +354 -247
  95. package/src/conversation.ts +1527 -0
  96. package/src/deepseek/README.md +78 -11
  97. package/src/deepseek/index.ts +385 -138
  98. package/src/deepseek/persistence.ts +11 -8
  99. package/src/index.ts +13 -4
  100. package/src/langgraph/README.md +115 -25
  101. package/src/langgraph/checkpointer.ts +168 -28
  102. package/src/langgraph/context.ts +27 -0
  103. package/src/langgraph/errors.ts +26 -0
  104. package/src/langgraph/graph.ts +396 -0
  105. package/src/langgraph/index.ts +337 -193
  106. package/src/langgraph/nodes.ts +243 -0
  107. package/src/messages.ts +244 -0
  108. package/src/object.ts +178 -48
  109. package/src/output.ts +52 -31
  110. package/src/pi/README.md +18 -3
  111. package/src/pi/index.ts +346 -79
  112. package/src/pi/storage.ts +20 -7
  113. package/src/signals.ts +235 -31
  114. package/src/steering.ts +67 -0
  115. package/src/tools.ts +61 -8
  116. package/dist/claude/conversation.d.ts +0 -33
  117. package/dist/claude/conversation.d.ts.map +0 -1
  118. package/dist/claude/conversation.js +0 -95
  119. package/dist/claude/conversation.js.map +0 -1
  120. package/dist/log.d.ts +0 -29
  121. package/dist/log.d.ts.map +0 -1
  122. package/dist/log.js +0 -145
  123. package/dist/log.js.map +0 -1
  124. package/dist/opencode/db.d.ts +0 -40
  125. package/dist/opencode/db.d.ts.map +0 -1
  126. package/dist/opencode/db.js +0 -161
  127. package/dist/opencode/db.js.map +0 -1
  128. package/dist/opencode/index.d.ts +0 -100
  129. package/dist/opencode/index.d.ts.map +0 -1
  130. package/dist/opencode/index.js +0 -436
  131. package/dist/opencode/index.js.map +0 -1
  132. package/src/claude/conversation.ts +0 -114
  133. package/src/log.ts +0 -193
  134. package/src/opencode/README.md +0 -125
  135. package/src/opencode/db.ts +0 -223
  136. package/src/opencode/index.ts +0 -559
package/dist/common.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as restate from '@restatedev/sessions';
2
- import type { Said } from './log.ts';
2
+ import { Link } from '@restatedev/sessions/internal';
3
+ import { type Published, type Steer } from './signals.ts';
3
4
  /**
4
5
  * A value, or a function of the invocation's context that gives it: the
5
6
  * same for every message, or each user's (from the object's database, say).
@@ -16,7 +17,7 @@ export declare const configured: <T>(value: Configure<T>, ctx: restate.SessionCo
16
17
  * order, so each gets the same id again, and its answer.
17
18
  */
18
19
  export declare const nextPromptId: (ctx: restate.SessionContext) => string;
19
- /** The default model of pi, OpenCode and LangGraph, with OPENAI_API_KEY. */
20
+ /** The default model of pi and LangGraph, with OPENAI_API_KEY. */
20
21
  export declare const DEFAULT_MODEL = "openai/gpt-6-sol";
21
22
  /** The default model of Claude agents, with ANTHROPIC_API_KEY. */
22
23
  export declare const CLAUDE_MODEL = "anthropic/claude-sonnet-5-5";
@@ -52,6 +53,11 @@ export declare const checkModelName: (framework: string, model: string | undefin
52
53
  export declare const modelIdOf: (model: string, provider: string) => string;
53
54
  /** A chat message: the request's body as text, or the string it is as JSON (`"Hi"`). */
54
55
  export declare const messageSerde: restate.Serde<string>;
56
+ /**
57
+ * What an empty answer says, as the model sees it later in the conversation:
58
+ * a provider's API may refuse an empty text (Anthropic's does).
59
+ */
60
+ export declare const NO_ANSWER = "(no answer)";
55
61
  /**
56
62
  * What a cancelled turn answers, and each tool call it cut off: the model
57
63
  * sees it in the conversation that goes on.
@@ -63,8 +69,43 @@ export declare const CANCELLED = "Cancelled: the turn was stopped before it fini
63
69
  * conversation that goes on, rather than answer it with the next message.
64
70
  */
65
71
  export declare const UNANSWERED = "Unanswered: the model's provider refused the request.";
72
+ /**
73
+ * What a turn whose invocation ended without answering it (killed, say)
74
+ * answers, and each tool call it cut off: the next message, or the companion
75
+ * once it finds the invocation gone (`settle`), closes it with this.
76
+ */
77
+ export declare const ENDED = "Ended: the turn ended before it finished, and was not answered.";
78
+ /** The result of a tool call a stopped turn cut off once its Restate call had answered: it happened. */
79
+ export declare const RETURNED_UNRECORDED = "Done, but the turn was stopped before this call's result was recorded: it did happen, so check its effect before doing it again.";
80
+ /**
81
+ * What a stopped turn records as the result of its tool call `callId`, which
82
+ * has none: `text` (cancelled, say), unless the call's Restate call answered
83
+ * (`outcomes` of calls.ts), which the model would take for undone, and do
84
+ * again: then the error it answered with, or {@link RETURNED_UNRECORDED}.
85
+ */
86
+ export declare function cutOffResult(outcomes: ReadonlyMap<string, string | undefined>, callId: string, text: string): string;
87
+ /** How many of the latest answered turns the model sees whole (with their tool calls and results), or `'all'`. */
88
+ export type Window = number | 'all';
89
+ /** The window by default: the previous turn's tool calls and results stay in view, for a follow-up. */
90
+ export declare const WINDOW: Window;
91
+ /** How many tokens of the turns before the window the model sees, by default, counted as 4 characters each. */
92
+ export declare const BUDGET = 32000;
93
+ /** How an agent summarizes earlier turns: from the request ({@link SUMMARIZE} and the turns, as text) to the summary. */
94
+ export type Summarize = (ctx: restate.SessionContext, request: string) => Promise<string>;
95
+ /** What a request to summarize earlier turns starts with, before the turns themselves. */
96
+ export declare const SUMMARIZE = "Summarize the conversation below, for the assistant who carries it on: keep the facts, names, numbers, decisions, the user's preferences, and what is still open. Answer with the summary only.\n\n";
97
+ /**
98
+ * What a turn checks its answer with: nothing if the answer is what was
99
+ * asked for, else the message that asks the model again, once, within the
100
+ * turn (`answerOnce`'s `check`). With `last`, the model was asked again
101
+ * already: a check that throws a terminal error then fails the turn, which
102
+ * is closed with it.
103
+ */
104
+ export type Check = (answer: string, last?: boolean) => string | undefined;
105
+ /** `window`, if it is one: a whole number of turns (0 or more), or `'all'`. */
106
+ export declare function checkWindow(window: Window): Window;
66
107
  /** The message a `chat` handler is answering: its invocation, and when it started. */
67
- export interface Turn {
108
+ export interface Answering {
68
109
  /** The invocation's id: `/restate/invocation/<id>/attach` waits for its answer. */
69
110
  invocationId: string;
70
111
  /** When it started, as an ISO date. */
@@ -87,19 +128,68 @@ export declare class AttemptEnded extends Error {
87
128
  * {@link AttemptEnded} once the attempt ends first (the work stops, and
88
129
  * answers nothing).
89
130
  */
90
- export declare const stopSignalOf: (ctx: object) => AbortSignal | undefined;
91
- /** Agent `name` runs in the background: see `background` in object.ts. */
92
- export declare const inBackground: (name: string) => undefined;
131
+ export declare const stopSignalOf: (ctx: restate.SessionContext) => AbortSignal | undefined;
132
+ /**
133
+ * An agent's settings: whether it runs in the background (`background:
134
+ * true`: no one follows it as it works), and, for an agent on the
135
+ * conversation of turns (conversation.ts), its framework's items, how much
136
+ * of the conversation its model sees (`window` and `budget`), and how it
137
+ * summarizes the earliest turns (`summarize`).
138
+ */
139
+ export interface Settings {
140
+ background: boolean;
141
+ /** The items of its framework, if it keeps the conversation of turns (its `messages` view is `conversationView`'s). */
142
+ items?: object;
143
+ window: Window;
144
+ budget: number;
145
+ summarize?: Summarize;
146
+ }
147
+ /** The items of a framework's `messages` view on the conversation of turns. */
148
+ export declare const ITEMS: Link<object>;
149
+ /** `definition` is an agent's, with these settings: its framework's items, if it is on the conversation of turns. */
150
+ export declare const isAgent: <D extends object>(definition: D, { background, items, window, budget, summarize, }: {
151
+ background?: boolean | undefined;
152
+ budget?: number | undefined;
153
+ items?: object | undefined;
154
+ summarize?: Summarize | undefined;
155
+ window?: Window | undefined;
156
+ }) => D;
157
+ /** The settings of the agent of `ctx`: the defaults, for an object that is no agent. */
158
+ export declare const settingsOf: (ctx: restate.SessionContext) => Settings;
159
+ /**
160
+ * The messages steered to a `chat` turn that it has not taken yet, as the
161
+ * companion last published them. The companion answers them to every
162
+ * `publish`, which a turn makes at each tool call's start and end: so the
163
+ * turn knows of them without a call of its own, and finds them at its next
164
+ * step (`takeSteers`). The newest revision wins, as tool calls that run at
165
+ * once publish at once.
166
+ */
167
+ export declare class Inbox {
168
+ #private;
169
+ revision: number;
170
+ messages: Steer[];
171
+ /** Keep what `publish` answered, if it is newer than what is kept, and tell the listeners if it lists messages. */
172
+ saw(published: Published | undefined): void;
173
+ /**
174
+ * Call `listener` after each publish that lists messages, until the
175
+ * returned function is called: for a framework that takes steered
176
+ * messages through an inbox of its own (pi's, DeepSeek's), handed to it as
177
+ * they come.
178
+ */
179
+ listen(listener: () => void): () => void;
180
+ }
181
+ /** The inbox of the `chat` turn running on `ctx`, if it takes steered messages: none outside one. */
182
+ export declare const inboxOf: (ctx: restate.SessionContext) => Inbox | undefined;
93
183
  /**
94
- * The `messages` view `view` of a framework that keeps a conversation apart
95
- * (OpenCode, in a database of its own): `clear` empties it too, as an agent
96
- * with this view is cleared.
184
+ * The conversation of `ctx` changed (see `watch` in object.ts): its revision
185
+ * increases, and the clients that follow it read it again; while a framework
186
+ * answers ({@link answering}), the calls whose results it stored are
187
+ * forgotten first. It is a call to Restate, so it also sends what the
188
+ * handler wrote before, for them to read.
97
189
  */
98
- export declare const alsoClearing: <V extends object>(view: V, clear: (ctx: restate.SessionContext) => Promise<void>) => V;
99
- /** When the agent `name`, whose `messages` view is `view`, is cleared, clear what that view keeps apart too. */
100
- export declare const onClear: (name: string, view: object | undefined) => void;
101
- /** Clear what the agent of `ctx` keeps beside its database ({@link onClear}). */
102
- export declare const cleared: (ctx: restate.SessionContext) => Promise<void | undefined>;
190
+ export declare const publish: (ctx: restate.SessionContext) => Promise<void>;
191
+ /** A step of a turn of `ctx`: {@link publish} it, unless the agent runs in the background, which publishes the turn's end only. */
192
+ export declare const stepped: (ctx: restate.SessionContext) => Promise<void>;
103
193
  /**
104
194
  * A tool call of the turn of `ctx` starts: {@link publish} it, which forgets
105
195
  * the calls whose results are stored (calls.ts) before the tool makes its
@@ -109,8 +199,30 @@ export declare const cleared: (ctx: restate.SessionContext) => Promise<void | un
109
199
  export declare function toolCallStarted(ctx: restate.SessionContext): Promise<void>;
110
200
  /** A tool call of the turn of `ctx` (a `chat` handler's) ended: {@link publish} it, unless the agent runs in the background. */
111
201
  export declare function toolCallEnded(ctx: restate.SessionContext): Promise<void>;
202
+ /** Whether a tool call's result is stored: `stored(callId, failed)`, `failed` the error the call answered with. */
203
+ export type Stored = (callId: string, failed?: string) => boolean;
204
+ /**
205
+ * Run `work`, a framework's turn on the conversation of turns, forgetting
206
+ * the calls whose results it stores as it goes: each publish while it runs
207
+ * (a tool call's start and end), and its end, forget the Restate calls of
208
+ * the tool calls whose results `stored` says are stored (calls.ts).
209
+ */
210
+ export declare function answering<T>(ctx: restate.SessionContext, stored: Stored, work: () => Promise<T>): Promise<T>;
112
211
  /** A promise that rejects with `signal`'s reason once it aborts. */
113
212
  export declare const aborted: (signal: AbortSignal) => Promise<never>;
213
+ /** A `chat` handler's answer to a message: a framework's prompt, say. */
214
+ export type Chat<A = unknown> = (ctx: restate.SessionContext, message: string) => Promise<A>;
215
+ /**
216
+ * Whether a `chat` handler's turns take steered messages: for every message,
217
+ * or for each, as the invocation's context says (a framework's options that
218
+ * a function gives, say).
219
+ */
220
+ export type Steers = boolean | ((ctx: restate.SessionContext) => boolean | Promise<boolean>);
221
+ /** The answer of `entry`, a handler that `chatHandler` made, and whether it takes steered messages. */
222
+ export declare const chatOf: (entry: object) => {
223
+ answer: Chat;
224
+ steers: Steers;
225
+ } | undefined;
114
226
  /**
115
227
  * `answer` as a chat handler, which takes its message as plain text or as a
116
228
  * JSON string, so that both of these work:
@@ -118,7 +230,7 @@ export declare const aborted: (signal: AbortSignal) => Promise<never>;
118
230
  * curl localhost:8080/assistant/alice/chat -d 'Hi'
119
231
  * curl localhost:8080/assistant/alice/chat --json '"Hi"'
120
232
  *
121
- * While it answers, the object's `status` says so (its {@link Turn}). Its
233
+ * While it answers, the object's `status` says so (its {@link Answering}). Its
122
234
  * invocation's cancellation (Restate's, explicit: `cancelled(ctx)` of
123
235
  * @restatedev/sessions/internal) aborts {@link stopSignalOf} its
124
236
  * context, whenever it comes, and cancels the calls its tools made
@@ -129,36 +241,54 @@ export declare const aborted: (signal: AbortSignal) => Promise<never>;
129
241
  *
130
242
  * It publishes when it starts and ends ({@link publish}), for the clients
131
243
  * that follow the conversation.
244
+ *
245
+ * As the `chat` handler of an agent, it also answers each message sent to
246
+ * the agent's `steer` view that no turn took, as a turn of its own (the
247
+ * private `steered` handler). With `steers` (a framework's integration says
248
+ * so), its turns take steered messages at their steps (`takeSteers`).
132
249
  */
133
- export declare const chatHandler: <A = string>(answer: (ctx: restate.SessionContext, message: string) => Promise<A>) => {
250
+ export declare const chatHandler: <A = string>(answer: Chat<A>, { steers }?: {
251
+ steers?: Steers;
252
+ }) => {
134
253
  input: restate.Serde<string>;
135
254
  accept: string;
136
255
  explicitCancellation: boolean;
137
256
  handler: (ctx: restate.SessionContext, text: string) => Promise<A>;
138
257
  };
258
+ /**
259
+ * Answer `text` as a turn of the agent of `ctx`, with `answer`: the body of a
260
+ * `chat` handler ({@link chatHandler}), and of `steered`. With `steers`, the
261
+ * turn takes the messages steered to it at its steps (unless the agent runs
262
+ * in the background).
263
+ */
264
+ export declare function chatTurn<A>(ctx: restate.SessionContext, text: string, answer: Chat<A>, steers?: Steers): Promise<A>;
139
265
  /** A tool's error, which fails the attempt (Restate retries it): the error `cause` of tool `tool`. */
140
266
  export declare class ToolError extends Error {
141
267
  readonly tool: string;
142
268
  constructor(tool: string, cause: unknown);
143
269
  }
144
270
  /**
145
- * `error` is a tool's: a framework's own tool (Claude's, LangChain's...)
146
- * that failed, whose error is never taken for the model's provider refusing
147
- * (a tool that calls a model API may fail as one does). `tool()`'s are
148
- * {@link ToolError}s.
271
+ * `error` is a tool's, in the attempt of `ctx`: a framework's own tool
272
+ * (Claude's, LangChain's...) that failed, whose error is never taken for
273
+ * the model's provider refusing (a tool that calls a model API may fail as
274
+ * one does). `tool()`'s are {@link ToolError}s.
149
275
  */
150
- export declare function fromTool(error: unknown): void;
276
+ export declare function fromTool(ctx: restate.SessionContext, error: unknown): void;
277
+ /** {@link refusal}, but not of an error a framework's tool failed with in the attempt of `ctx` ({@link fromTool}). */
278
+ export declare function refusalOf(ctx: restate.SessionContext, error: unknown): restate.TerminalError | undefined;
151
279
  /**
152
280
  * `error` as a terminal error ({@link REFUSED}), if a retry does not change
153
281
  * it: a model the agent cannot take, or its provider's refusal.
154
282
  */
155
283
  export declare function refusal(error: unknown): restate.TerminalError | undefined;
156
284
  /**
157
- * A prompt's stored answer, as the prompt returns it: {@link UNANSWERED},
158
- * stored as its provider refused it, fails as the prompt did then
159
- * ({@link REFUSED}), also in a retry after a crash right after it was stored.
285
+ * A prompt's stored answer, as the prompt returns it, by how its turn ended
286
+ * (`status`): a turn refused ({@link UNANSWERED}) fails with
287
+ * {@link REFUSED}, one failed for good with its error, one cancelled with
288
+ * the cancellation, one another invocation ended with its note; so that a
289
+ * retry after a crash right after the close fails as the prompt did.
160
290
  */
161
- export declare function storedAnswer(answer: string): string;
291
+ export declare function storedAnswer(answer: string, status?: string): string;
162
292
  /** A message of a conversation, as an agent's `messages` handler returns it. */
163
293
  export interface ChatMessage {
164
294
  /** Its id, from 0, in the order of the conversation; the same however it changes. `before` takes it. */
@@ -188,6 +318,12 @@ export type Part = {
188
318
  * follow it.
189
319
  */
190
320
  export interface MessagesRequest {
321
+ /**
322
+ * `full` (the default): every message, with its tool calls; `summary`:
323
+ * each turn's message of the user and its answer, under the ids they have
324
+ * in the full view.
325
+ */
326
+ view?: 'full' | 'summary';
191
327
  /** At most this many messages (default 50). */
192
328
  limit?: number;
193
329
  /** The messages before this one (its `id`): older ones, such as for scrolling back. */
@@ -212,50 +348,4 @@ export interface Messages {
212
348
  */
213
349
  first?: number;
214
350
  }
215
- /**
216
- * A conversation as `messages` gives it, built from a framework's transcript:
217
- * each message is started by `say`, a tool call goes to the assistant's
218
- * message, and its result to its call. Messages without parts are left out.
219
- *
220
- * A message, once given out by `messages()`, is never changed: a change
221
- * makes a new one in its place. So a framework can keep its transcript and
222
- * add to it as its conversation grows, and the log stores only the messages
223
- * that are not the ones it stored last (see log.ts).
224
- */
225
- export declare class Transcript {
226
- #private;
227
- /** A new message of `role`, with `text` if there is any. */
228
- say(role: ChatMessage['role'], text?: string): void;
229
- /** Tool call `id` of the assistant's message. */
230
- call(id: string, name: string, input: unknown): void;
231
- /** The output of tool call `id`; an error's if the framework says so, or it is a tool's `Error: <message>`. */
232
- result(id: string, output: string, error?: boolean): void;
233
- /**
234
- * Whether tool call `id` has its output: not an error's, unless it is
235
- * `failed`, the error the call answered with.
236
- */
237
- answered(id: string, failed?: string): boolean;
238
- /** Its messages, in order: those with parts. */
239
- messages(): Said[];
240
- }
241
- /**
242
- * A framework's transcript as it stands, while it answers (see
243
- * {@link transcribing}): a new one, or the one it keeps and adds to.
244
- */
245
- export type Read = () => Promise<Transcript>;
246
- /**
247
- * Run `work`, a framework's turn (or a compaction, a reset), with `read`
248
- * giving the framework's transcript as it stands, from the framework as
249
- * `work` holds it open: each publish meanwhile (a tool call's start and end)
250
- * takes it into the conversation's log, and so does `work`'s end, before the
251
- * framework closes. `messages` and `sync` read the log.
252
- */
253
- export declare function transcribing<T>(ctx: restate.SessionContext, read: Read, work: () => Promise<T>): Promise<T>;
254
- /**
255
- * The handler of an agent's conversation as clients read it, from its log:
256
- * a page of it (`{limit, before}`), or what is new or changed since a cursor
257
- * (`{cursor}`). It is a view: it answers while a message is answered, with
258
- * what was stored so far, and stores nothing.
259
- */
260
- export declare const messagesHandler: () => (ctx: restate.ViewContext, request?: MessagesRequest) => Promise<Messages>;
261
351
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAIhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjF,2CAA2C;AAC3C,eAAO,MAAM,UAAU,GAAU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