@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.
Files changed (218) hide show
  1. package/README.md +189 -808
  2. package/dist/pi/factory.d.ts +73 -0
  3. package/dist/pi/factory.d.ts.map +1 -0
  4. package/dist/pi/factory.js +145 -0
  5. package/dist/pi/factory.js.map +1 -0
  6. package/dist/pi/index.d.ts +5 -129
  7. package/dist/pi/index.d.ts.map +1 -1
  8. package/dist/pi/index.js +31 -571
  9. package/dist/pi/index.js.map +1 -1
  10. package/dist/pi/keepalive.d.ts +3 -16
  11. package/dist/pi/keepalive.d.ts.map +1 -1
  12. package/dist/pi/keepalive.js +38 -41
  13. package/dist/pi/keepalive.js.map +1 -1
  14. package/dist/pi/left.d.ts +16 -0
  15. package/dist/pi/left.d.ts.map +1 -0
  16. package/dist/pi/left.js +23 -0
  17. package/dist/pi/left.js.map +1 -0
  18. package/dist/pi/storage.d.ts +19 -76
  19. package/dist/pi/storage.d.ts.map +1 -1
  20. package/dist/pi/storage.js +50 -368
  21. package/dist/pi/storage.js.map +1 -1
  22. package/dist/pi/tools.d.ts +12 -0
  23. package/dist/pi/tools.d.ts.map +1 -0
  24. package/dist/pi/tools.js +70 -0
  25. package/dist/pi/tools.js.map +1 -0
  26. package/package.json +11 -254
  27. package/src/pi/factory.ts +231 -0
  28. package/src/pi/index.ts +31 -759
  29. package/src/pi/keepalive.ts +46 -56
  30. package/src/pi/left.ts +52 -0
  31. package/src/pi/storage.ts +75 -409
  32. package/src/pi/tools.ts +78 -0
  33. package/dist/agentlib/agent.d.ts +0 -32
  34. package/dist/agentlib/agent.d.ts.map +0 -1
  35. package/dist/agentlib/agent.js +0 -174
  36. package/dist/agentlib/agent.js.map +0 -1
  37. package/dist/agentlib/index.d.ts +0 -5
  38. package/dist/agentlib/index.d.ts.map +0 -1
  39. package/dist/agentlib/index.js +0 -15
  40. package/dist/agentlib/index.js.map +0 -1
  41. package/dist/agentlib/messages.d.ts +0 -39
  42. package/dist/agentlib/messages.d.ts.map +0 -1
  43. package/dist/agentlib/messages.js +0 -177
  44. package/dist/agentlib/messages.js.map +0 -1
  45. package/dist/agentlib/model.d.ts +0 -31
  46. package/dist/agentlib/model.d.ts.map +0 -1
  47. package/dist/agentlib/model.js +0 -140
  48. package/dist/agentlib/model.js.map +0 -1
  49. package/dist/agentlib/options.d.ts +0 -58
  50. package/dist/agentlib/options.d.ts.map +0 -1
  51. package/dist/agentlib/options.js +0 -2
  52. package/dist/agentlib/options.js.map +0 -1
  53. package/dist/agentlib/runtime.d.ts +0 -37
  54. package/dist/agentlib/runtime.d.ts.map +0 -1
  55. package/dist/agentlib/runtime.js +0 -216
  56. package/dist/agentlib/runtime.js.map +0 -1
  57. package/dist/agentlib/state.d.ts +0 -114
  58. package/dist/agentlib/state.d.ts.map +0 -1
  59. package/dist/agentlib/state.js +0 -52
  60. package/dist/agentlib/state.js.map +0 -1
  61. package/dist/agentlib/steering.d.ts +0 -23
  62. package/dist/agentlib/steering.d.ts.map +0 -1
  63. package/dist/agentlib/steering.js +0 -48
  64. package/dist/agentlib/steering.js.map +0 -1
  65. package/dist/agentlib/tools.d.ts +0 -33
  66. package/dist/agentlib/tools.d.ts.map +0 -1
  67. package/dist/agentlib/tools.js +0 -245
  68. package/dist/agentlib/tools.js.map +0 -1
  69. package/dist/agentlib/turn.d.ts +0 -82
  70. package/dist/agentlib/turn.d.ts.map +0 -1
  71. package/dist/agentlib/turn.js +0 -253
  72. package/dist/agentlib/turn.js.map +0 -1
  73. package/dist/calls.d.ts +0 -90
  74. package/dist/calls.d.ts.map +0 -1
  75. package/dist/calls.js +0 -241
  76. package/dist/calls.js.map +0 -1
  77. package/dist/claude/index.d.ts +0 -106
  78. package/dist/claude/index.d.ts.map +0 -1
  79. package/dist/claude/index.js +0 -386
  80. package/dist/claude/index.js.map +0 -1
  81. package/dist/client.d.ts +0 -90
  82. package/dist/client.d.ts.map +0 -1
  83. package/dist/client.js +0 -88
  84. package/dist/client.js.map +0 -1
  85. package/dist/common.d.ts +0 -410
  86. package/dist/common.d.ts.map +0 -1
  87. package/dist/common.js +0 -563
  88. package/dist/common.js.map +0 -1
  89. package/dist/companion.d.ts +0 -286
  90. package/dist/companion.d.ts.map +0 -1
  91. package/dist/companion.js +0 -463
  92. package/dist/companion.js.map +0 -1
  93. package/dist/conversation.d.ts +0 -576
  94. package/dist/conversation.d.ts.map +0 -1
  95. package/dist/conversation.js +0 -1476
  96. package/dist/conversation.js.map +0 -1
  97. package/dist/deepseek/barriers.d.ts +0 -11
  98. package/dist/deepseek/barriers.d.ts.map +0 -1
  99. package/dist/deepseek/barriers.js +0 -36
  100. package/dist/deepseek/barriers.js.map +0 -1
  101. package/dist/deepseek/index.d.ts +0 -97
  102. package/dist/deepseek/index.d.ts.map +0 -1
  103. package/dist/deepseek/index.js +0 -603
  104. package/dist/deepseek/index.js.map +0 -1
  105. package/dist/deepseek/persistence.d.ts +0 -83
  106. package/dist/deepseek/persistence.d.ts.map +0 -1
  107. package/dist/deepseek/persistence.js +0 -262
  108. package/dist/deepseek/persistence.js.map +0 -1
  109. package/dist/index.d.ts +0 -14
  110. package/dist/index.d.ts.map +0 -1
  111. package/dist/index.js +0 -17
  112. package/dist/index.js.map +0 -1
  113. package/dist/langgraph/checkpointer.d.ts +0 -52
  114. package/dist/langgraph/checkpointer.d.ts.map +0 -1
  115. package/dist/langgraph/checkpointer.js +0 -477
  116. package/dist/langgraph/checkpointer.js.map +0 -1
  117. package/dist/langgraph/context.d.ts +0 -10
  118. package/dist/langgraph/context.d.ts.map +0 -1
  119. package/dist/langgraph/context.js +0 -21
  120. package/dist/langgraph/context.js.map +0 -1
  121. package/dist/langgraph/errors.d.ts +0 -16
  122. package/dist/langgraph/errors.d.ts.map +0 -1
  123. package/dist/langgraph/errors.js +0 -30
  124. package/dist/langgraph/errors.js.map +0 -1
  125. package/dist/langgraph/graph.d.ts +0 -25
  126. package/dist/langgraph/graph.d.ts.map +0 -1
  127. package/dist/langgraph/graph.js +0 -378
  128. package/dist/langgraph/graph.js.map +0 -1
  129. package/dist/langgraph/index.d.ts +0 -119
  130. package/dist/langgraph/index.d.ts.map +0 -1
  131. package/dist/langgraph/index.js +0 -325
  132. package/dist/langgraph/index.js.map +0 -1
  133. package/dist/langgraph/keepalive.d.ts +0 -16
  134. package/dist/langgraph/keepalive.d.ts.map +0 -1
  135. package/dist/langgraph/keepalive.js +0 -51
  136. package/dist/langgraph/keepalive.js.map +0 -1
  137. package/dist/langgraph/nodes.d.ts +0 -71
  138. package/dist/langgraph/nodes.d.ts.map +0 -1
  139. package/dist/langgraph/nodes.js +0 -148
  140. package/dist/langgraph/nodes.js.map +0 -1
  141. package/dist/messages.d.ts +0 -18
  142. package/dist/messages.d.ts.map +0 -1
  143. package/dist/messages.js +0 -182
  144. package/dist/messages.js.map +0 -1
  145. package/dist/object.d.ts +0 -213
  146. package/dist/object.d.ts.map +0 -1
  147. package/dist/object.js +0 -309
  148. package/dist/object.js.map +0 -1
  149. package/dist/opencode/db.d.ts +0 -81
  150. package/dist/opencode/db.d.ts.map +0 -1
  151. package/dist/opencode/db.js +0 -249
  152. package/dist/opencode/db.js.map +0 -1
  153. package/dist/opencode/index.d.ts +0 -184
  154. package/dist/opencode/index.d.ts.map +0 -1
  155. package/dist/opencode/index.js +0 -1079
  156. package/dist/opencode/index.js.map +0 -1
  157. package/dist/output.d.ts +0 -25
  158. package/dist/output.d.ts.map +0 -1
  159. package/dist/output.js +0 -99
  160. package/dist/output.js.map +0 -1
  161. package/dist/pi/commits.d.ts +0 -6
  162. package/dist/pi/commits.d.ts.map +0 -1
  163. package/dist/pi/commits.js +0 -3
  164. package/dist/pi/commits.js.map +0 -1
  165. package/dist/steering.d.ts +0 -32
  166. package/dist/steering.d.ts.map +0 -1
  167. package/dist/steering.js +0 -45
  168. package/dist/steering.js.map +0 -1
  169. package/dist/tools.d.ts +0 -267
  170. package/dist/tools.d.ts.map +0 -1
  171. package/dist/tools.js +0 -305
  172. package/dist/tools.js.map +0 -1
  173. package/dist/webhook.d.ts +0 -71
  174. package/dist/webhook.d.ts.map +0 -1
  175. package/dist/webhook.js +0 -102
  176. package/dist/webhook.js.map +0 -1
  177. package/src/agentlib/README.md +0 -229
  178. package/src/agentlib/agent.ts +0 -216
  179. package/src/agentlib/index.ts +0 -16
  180. package/src/agentlib/messages.ts +0 -207
  181. package/src/agentlib/model.ts +0 -156
  182. package/src/agentlib/options.ts +0 -62
  183. package/src/agentlib/runtime.ts +0 -252
  184. package/src/agentlib/state.ts +0 -93
  185. package/src/agentlib/steering.ts +0 -53
  186. package/src/agentlib/tools.ts +0 -355
  187. package/src/agentlib/turn.ts +0 -302
  188. package/src/calls.ts +0 -333
  189. package/src/claude/README.md +0 -107
  190. package/src/claude/index.ts +0 -487
  191. package/src/client.ts +0 -187
  192. package/src/common.ts +0 -766
  193. package/src/companion.ts +0 -675
  194. package/src/conversation.ts +0 -1799
  195. package/src/deepseek/README.md +0 -202
  196. package/src/deepseek/barriers.ts +0 -63
  197. package/src/deepseek/index.ts +0 -740
  198. package/src/deepseek/persistence.ts +0 -337
  199. package/src/index.ts +0 -41
  200. package/src/langgraph/README.md +0 -199
  201. package/src/langgraph/checkpointer.ts +0 -614
  202. package/src/langgraph/context.ts +0 -27
  203. package/src/langgraph/errors.ts +0 -26
  204. package/src/langgraph/graph.ts +0 -422
  205. package/src/langgraph/index.ts +0 -500
  206. package/src/langgraph/keepalive.ts +0 -58
  207. package/src/langgraph/nodes.ts +0 -247
  208. package/src/messages.ts +0 -244
  209. package/src/object.ts +0 -454
  210. package/src/opencode/README.md +0 -249
  211. package/src/opencode/db.ts +0 -387
  212. package/src/opencode/index.ts +0 -1339
  213. package/src/output.ts +0 -116
  214. package/src/pi/README.md +0 -174
  215. package/src/pi/commits.ts +0 -7
  216. package/src/steering.ts +0 -68
  217. package/src/tools.ts +0 -515
  218. package/src/webhook.ts +0 -161
package/dist/calls.d.ts DELETED
@@ -1,90 +0,0 @@
1
- import type * as restate from '@restatedev/sessions';
2
- import { Schema } from '@restatedev/sessions/internal';
3
- /**
4
- * The table of the {@link Calls}: one row, of the invocation whose calls they are. `answerOnce` applies it with
5
- * the conversation's, in one commit, as a key's first turn starts.
6
- */
7
- export declare const SCHEMA: Schema;
8
- /**
9
- * Have {@link flushHeld} write, with `flush`, what a holder keeps back: by
10
- * default the rows that the conversation of the attempt's turn holds back
11
- * (`Conversation.hold`), which `answerOnce` sets. A holder of another `slot`
12
- * (pi's storage, which holds its commits until an effect starts) coexists
13
- * with it; one of the same slot replaces it, and without a `flush` the slot
14
- * is released.
15
- */
16
- export declare const holding: (ctx: restate.SessionContext, flush: (() => Promise<void>) | undefined, slot?: string) => void;
17
- /**
18
- * Write what the holders keep back, in the order they were set, one after
19
- * the other: the rows that the conversation of the attempt's turn holds back,
20
- * if any (see `Conversation.hold`), and pi's batched commits. Call it before
21
- * what another party sees, or what outlives the attempt: a publish, a
22
- * Restate call, send or wait. What is held is lost in a crash, and the
23
- * retried attempt makes it again; what was seen or called must not depend
24
- * on it.
25
- */
26
- export declare function flushHeld(ctx: restate.SessionContext): Promise<void>;
27
- /**
28
- * Run `work` (a turn's) with the calls its tools make kept as prompt
29
- * `prompt`'s: they are matched, and rejoined, within it only. An invocation
30
- * that prompts twice, its second prompt making the call its first made
31
- * (the same tool and input), would otherwise take the first's after a crash
32
- * (its record not yet forgotten), and never make its own.
33
- */
34
- export declare function forPrompt<T>(ctx: restate.SessionContext, prompt: string, work: () => Promise<T>): Promise<T>;
35
- /**
36
- * The call of tool `tool` with `input` that tool call `callId` makes: the
37
- * one it made to `tool` before (a run again), or else, if `rejoin`, the one
38
- * an earlier attempt made with the same tool and input (made again under a
39
- * new id), or else a new one, an `approval` its tool call waits for if so.
40
- * `answered()` stores that it answered.
41
- */
42
- export declare function callOf(ctx: restate.SessionContext, tool: string, input: unknown, callId: string, { rejoin, approval }?: {
43
- rejoin?: boolean;
44
- approval?: boolean;
45
- }): Promise<{
46
- id: string;
47
- /**
48
- * It answered, with `failed` if a terminal error answered it: kept until
49
- * the transcript has its result.
50
- *
51
- * It rides a commit that is under way (the one that stores the call's
52
- * result, when the framework's write has started), and is otherwise
53
- * written on its own at once ({@link ride}): a call that answered must
54
- * not stay unrecorded while something else runs (a slow tool of the same
55
- * round, a call that waits for a signal). A crash before it is written
56
- * reads the call as one that did not answer, as a crash just before a
57
- * commit of its own would have: made again under the same key, and cut off
58
- * for a stopped turn that another invocation closes ({@link outcomes} reads
59
- * the stored row; the attempt's own turn reads its state).
60
- */
61
- answered(failed?: string): Promise<void>;
62
- }>;
63
- /**
64
- * Forget the calls that answered whose result the framework stored: those
65
- * of which `stored(id, failed)` is true for the last id they were made with,
66
- * `failed` the error that answered the call, if one did. Called
67
- * after each commit of steps, and before each tool call, with the transcript as the
68
- * framework stored it: also in an attempt that made no call yet, which would
69
- * otherwise take one an earlier attempt made, and the model has the result
70
- * of.
71
- */
72
- export declare function settleCalls(ctx: restate.SessionContext, stored: (id: string, failed?: string) => boolean): Promise<void>;
73
- /**
74
- * Which of `callIds` made a Restate call that answered, in this invocation
75
- * or in `invocation`: each with the terminal error it answered with
76
- * (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
77
- * call did not answer, or that made none, is left out; so is one whose only
78
- * answered call is its approval, which it ran (or was denied) after.
79
- *
80
- * An earlier `invocation`'s calls are read only while they are still
81
- * stored, until an invocation of the key makes calls of its own; read,
82
- * never changed. With `prompt`, the calls of its turn only.
83
- */
84
- export declare function outcomes(ctx: restate.SessionContext, callIds: Iterable<string>, invocation?: string, prompt?: string): Promise<Map<string, string | undefined>>;
85
- /**
86
- * Write what rides the next commit ({@link ride}) now, if it is pending: at
87
- * the end of a turn, when no commit follows that would.
88
- */
89
- export declare const flushCalls: (ctx: restate.SessionContext) => Promise<void>;
90
- //# sourceMappingURL=calls.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[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M,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAc1C;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,OAAO,CAAC,cAAc,kBAAwB,CAAC"}
package/dist/calls.js DELETED
@@ -1,241 +0,0 @@
1
- import { flushRiders, rideCommit, Schema, ScopeKey } from '@restatedev/sessions/internal';
2
- import { randomUUID } from 'node:crypto';
3
- /**
4
- * The table of the {@link Calls}: one row, of the invocation whose calls they are. `answerOnce` applies it with
5
- * the conversation's, in one commit, as a key's first turn starts.
6
- */
7
- export const SCHEMA = new Schema('restate-agents.calls', [
8
- `CREATE TABLE restate_agent_calls (
9
- row INTEGER PRIMARY KEY CHECK (row = 0),
10
- invocation TEXT NOT NULL,
11
- calls TEXT NOT NULL
12
- )`,
13
- ]);
14
- /** What writes what is held back before anything visible, by holder: the conversation's rows, pi's batch of commits. */
15
- const HELD = new ScopeKey('what the attempt holds back');
16
- /**
17
- * Have {@link flushHeld} write, with `flush`, what a holder keeps back: by
18
- * default the rows that the conversation of the attempt's turn holds back
19
- * (`Conversation.hold`), which `answerOnce` sets. A holder of another `slot`
20
- * (pi's storage, which holds its commits until an effect starts) coexists
21
- * with it; one of the same slot replaces it, and without a `flush` the slot
22
- * is released.
23
- */
24
- export const holding = (ctx, flush, slot = 'conversation') => {
25
- const held = HELD.of(ctx, () => new Map());
26
- if (flush)
27
- held.set(slot, flush);
28
- else
29
- held.delete(slot);
30
- };
31
- /**
32
- * Write what the holders keep back, in the order they were set, one after
33
- * the other: the rows that the conversation of the attempt's turn holds back,
34
- * if any (see `Conversation.hold`), and pi's batched commits. Call it before
35
- * what another party sees, or what outlives the attempt: a publish, a
36
- * Restate call, send or wait. What is held is lost in a crash, and the
37
- * retried attempt makes it again; what was seen or called must not depend
38
- * on it.
39
- */
40
- export async function flushHeld(ctx) {
41
- for (const flush of HELD.get(ctx)?.values() ?? [])
42
- await flush();
43
- }
44
- const UPSERT = 'INSERT OR REPLACE INTO restate_agent_calls (row, invocation, calls) VALUES (0, ?, ?)';
45
- /** The slot of the calls' write that rides the next commit ({@link ride}). */
46
- const RIDER = 'restate-agents.calls';
47
- /** The write of `state`, as it is when it runs: the row, whole. */
48
- const writing = (state) => (tx) => tx.execute(UPSERT, [state.invocation, JSON.stringify(state.calls)]);
49
- /**
50
- * Store `calls`, committed before the call they record is made. The rows the
51
- * conversation holds back are written first: the call outlives the attempt,
52
- * and what led to it must too. It is the whole row, and it is written by a
53
- * commit that also carries what was pending (an answer): the state is
54
- * registered as the pending write, and flushed. A transaction under way (a
55
- * framework storing an earlier call's result) writes it as it commits, so that
56
- * the result is never committed beside an answer that is not recorded; with
57
- * none, it is a transaction of its own.
58
- */
59
- async function store(ctx, state) {
60
- await flushHeld(ctx);
61
- if (rideCommit(ctx.db, RIDER, writing(state)))
62
- await flushRiders(ctx.db);
63
- else
64
- await ctx.db.execute(UPSERT, [state.invocation, JSON.stringify(state.calls)]);
65
- }
66
- /**
67
- * Store `state` with the next commit of the database, rather than commit it
68
- * (see the top of this file), as it is then: a later change replaces it, and
69
- * the latest state is written. An `urgent` one (an answer) is written on its
70
- * own unless a commit is under way to write it; one pending that is urgent
71
- * stays so. A database that cannot ride (a view's) commits it at once.
72
- */
73
- async function ride(ctx, state, urgent = false) {
74
- const written = rideCommit(ctx.db, RIDER, writing(state), { urgent });
75
- if (!written)
76
- await store(ctx, state);
77
- }
78
- /** The calls of `invocation`, as stored: none if the row is another invocation's. */
79
- async function load(ctx, invocation) {
80
- await SCHEMA.ensure(ctx.db);
81
- const row = await ctx.db.get('SELECT invocation, calls FROM restate_agent_calls');
82
- return row?.invocation === invocation
83
- ? { invocation, calls: JSON.parse(row.calls) }
84
- : { invocation, calls: [] };
85
- }
86
- /** Each attempt's id, and its calls, by its context, once they are being read. */
87
- const ATTEMPT = new ScopeKey('the calls of an attempt');
88
- /**
89
- * The attempt of `ctx`: its id, and the calls of its invocation (loaded once,
90
- * shared by calls made at once). A load that fails (its schema's commit
91
- * cancelled, say) is not kept: the next asks again, so that a stopped turn's
92
- * close reads the calls as stored, rather than fail on the load it found.
93
- */
94
- function attemptOf(ctx) {
95
- const attempt = ATTEMPT.of(ctx, () => ({ id: randomUUID() }));
96
- if (attempt.calls === undefined) {
97
- const calls = load(ctx, ctx.request.id);
98
- attempt.calls = calls;
99
- calls.catch(() => {
100
- if (attempt.calls === calls)
101
- attempt.calls = undefined;
102
- });
103
- }
104
- return attempt;
105
- }
106
- /** `value` as JSON with its objects' keys sorted: the same input, however its keys came, is the same call. */
107
- function canonical(value) {
108
- return JSON.stringify(value, (_key, v) => v !== null && typeof v === 'object' && !Array.isArray(v)
109
- ? Object.fromEntries(Object.entries(v).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
110
- : v);
111
- }
112
- /** The prompt whose turn the tools of `ctx` run for, while `answerOnce` answers it. */
113
- const PROMPT = new ScopeKey('the prompt of the calls');
114
- /**
115
- * Run `work` (a turn's) with the calls its tools make kept as prompt
116
- * `prompt`'s: they are matched, and rejoined, within it only. An invocation
117
- * that prompts twice, its second prompt making the call its first made
118
- * (the same tool and input), would otherwise take the first's after a crash
119
- * (its record not yet forgotten), and never make its own.
120
- */
121
- export async function forPrompt(ctx, prompt, work) {
122
- const outer = PROMPT.get(ctx);
123
- PROMPT.set(ctx, prompt);
124
- try {
125
- return await work();
126
- }
127
- finally {
128
- if (outer === undefined)
129
- PROMPT.delete(ctx);
130
- else
131
- PROMPT.set(ctx, outer);
132
- }
133
- }
134
- /**
135
- * The call of tool `tool` with `input` that tool call `callId` makes: the
136
- * one it made to `tool` before (a run again), or else, if `rejoin`, the one
137
- * an earlier attempt made with the same tool and input (made again under a
138
- * new id), or else a new one, an `approval` its tool call waits for if so.
139
- * `answered()` stores that it answered.
140
- */
141
- export async function callOf(ctx, tool, input, callId, { rejoin = true, approval = false } = {}) {
142
- const attempt = attemptOf(ctx);
143
- const state = await attempt.calls;
144
- const json = canonical(input);
145
- const prompt = PROMPT.get(ctx);
146
- const ours = state.calls.filter((c) => c.prompt === prompt);
147
- // A tool call may make more than one call (an approval, then the tool's
148
- // own), each to a tool of its own.
149
- let call = ours.find((c) => c.ids.includes(callId) && c.tool === tool) ??
150
- (rejoin ? ours.find((c) => c.attempt !== attempt.id && c.tool === tool && c.input === json) : undefined);
151
- if (call) {
152
- call.attempt = attempt.id;
153
- if (!call.ids.includes(callId))
154
- call.ids.push(callId);
155
- }
156
- else {
157
- call = { tool, input: json, ids: [callId], attempt: attempt.id };
158
- if (approval)
159
- call.approval = true;
160
- if (prompt !== undefined)
161
- call.prompt = prompt;
162
- state.calls.push(call);
163
- }
164
- await store(ctx, state);
165
- const made = call;
166
- return {
167
- id: made.ids[0],
168
- /**
169
- * It answered, with `failed` if a terminal error answered it: kept until
170
- * the transcript has its result.
171
- *
172
- * It rides a commit that is under way (the one that stores the call's
173
- * result, when the framework's write has started), and is otherwise
174
- * written on its own at once ({@link ride}): a call that answered must
175
- * not stay unrecorded while something else runs (a slow tool of the same
176
- * round, a call that waits for a signal). A crash before it is written
177
- * reads the call as one that did not answer, as a crash just before a
178
- * commit of its own would have: made again under the same key, and cut off
179
- * for a stopped turn that another invocation closes ({@link outcomes} reads
180
- * the stored row; the attempt's own turn reads its state).
181
- */
182
- async answered(failed) {
183
- made.done = true;
184
- if (failed !== undefined)
185
- made.failed = failed;
186
- await ride(ctx, state, true);
187
- },
188
- };
189
- }
190
- /**
191
- * Forget the calls that answered whose result the framework stored: those
192
- * of which `stored(id, failed)` is true for the last id they were made with,
193
- * `failed` the error that answered the call, if one did. Called
194
- * after each commit of steps, and before each tool call, with the transcript as the
195
- * framework stored it: also in an attempt that made no call yet, which would
196
- * otherwise take one an earlier attempt made, and the model has the result
197
- * of.
198
- */
199
- export async function settleCalls(ctx, stored) {
200
- const state = await attemptOf(ctx).calls;
201
- const kept = state.calls.filter((c) => !c.done || !stored(c.ids.at(-1), c.failed));
202
- if (kept.length === state.calls.length)
203
- return;
204
- state.calls = kept;
205
- await ride(ctx, state);
206
- }
207
- /**
208
- * Which of `callIds` made a Restate call that answered, in this invocation
209
- * or in `invocation`: each with the terminal error it answered with
210
- * (`Error: <message>`), or `undefined` if it succeeded. A tool call whose
211
- * call did not answer, or that made none, is left out; so is one whose only
212
- * answered call is its approval, which it ran (or was denied) after.
213
- *
214
- * An earlier `invocation`'s calls are read only while they are still
215
- * stored, until an invocation of the key makes calls of its own; read,
216
- * never changed. With `prompt`, the calls of its turn only.
217
- */
218
- export async function outcomes(ctx, callIds, invocation, prompt) {
219
- const state = invocation !== undefined && invocation !== ctx.request.id
220
- ? await load(ctx, invocation)
221
- : await attemptOf(ctx).calls;
222
- const wanted = new Set(callIds);
223
- const found = new Map();
224
- for (const call of state.calls) {
225
- if (!call.done || call.approval)
226
- continue;
227
- // Another prompt's call, of the same invocation: not this turn's.
228
- if (prompt !== undefined && call.prompt !== undefined && call.prompt !== prompt)
229
- continue;
230
- for (const id of call.ids)
231
- if (wanted.has(id))
232
- found.set(id, call.failed);
233
- }
234
- return found;
235
- }
236
- /**
237
- * Write what rides the next commit ({@link ride}) now, if it is pending: at
238
- * the end of a turn, when no commit follows that would.
239
- */
240
- export const flushCalls = (ctx) => flushRiders(ctx.db);
241
- //# sourceMappingURL=calls.js.map
package/dist/calls.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA2BzC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE;IACvD;;;;IAIE;CACH,CAAC,CAAC;AAKH,wHAAwH;AACxH,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAmC,6BAA6B,CAA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GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAA2B,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC"}
@@ -1,106 +0,0 @@
1
- import * as restate from '@restatedev/sessions';
2
- import Anthropic from '@anthropic-ai/sdk';
3
- import type { BetaRunnableTool, BetaToolRunContext } from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool';
4
- import { type Configure, type Summarize } from '../common.ts';
5
- import { type Items } from '../conversation.ts';
6
- import { type Answer } from '../output.ts';
7
- import type { z } from 'zod';
8
- import { type Definition } from '../object.ts';
9
- import { type Tool as AnyTool } from '../tools.ts';
10
- type MessageParam = Anthropic.Beta.Messages.BetaMessageParam;
11
- /** The id of the tool call a tool runs for: the runner always passes it. */
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>;
21
- /** How much effort the model puts into a reply (Anthropic's `output_config.effort`). */
22
- export type Effort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
23
- /** An agent's options: `chat` and `prompt` take them. */
24
- export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
25
- /** The model, as `anthropic/model-id`: MODEL, or else anthropic/claude-sonnet-5-5. */
26
- model?: string;
27
- /** The system prompt. */
28
- system?: string;
29
- /** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or the SDK's (such as `betaZodTool`s). */
30
- tools?: (AnyTool | BetaRunnableTool)[];
31
- /** The client of the Anthropic API: by default one with ANTHROPIC_API_KEY. */
32
- client?: Anthropic;
33
- /**
34
- * The most tokens of each of the model's replies (default 16000). A reply
35
- * cut off there ends its prompt, which fails (a terminal error).
36
- */
37
- maxTokens?: number;
38
- /** How much effort the model puts into each reply: more is more thorough, and slower (default: the model's). */
39
- effort?: Effort;
40
- /**
41
- * The answer as data: a zod object, whose JSON the agent replies with
42
- * (checked), and `chat` and `prompt` answer with (see output.ts).
43
- */
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;
54
- }
55
- /**
56
- * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
57
- * of an invocation is a prompt of its own.
58
- * With `output`, it answers with the value the agent replies with (see
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.
62
- */
63
- export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
64
- /**
65
- * A chat handler: each message an invocation, the conversation in the
66
- * object's database, with `options`, or the options a function of the
67
- * invocation's context gives. It takes the message as plain text
68
- * (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
69
- */
70
- export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
71
- input: restate.Serde<string>;
72
- accept: string;
73
- explicitCancellation: boolean;
74
- handler: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
75
- };
76
- /**
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.
80
- */
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;
88
- /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
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, {
90
- signal: (ctx: import("../common.ts").AgentViewContext, signal: import("../companion.ts").Signal) => Promise<import("../companion.ts").Resolved>;
91
- pending: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Waiting[]>;
92
- status: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Status>;
93
- stop: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
94
- notifications: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Notifications>;
95
- watch: (ctx: import("../common.ts").AgentViewContext, watch: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
96
- } & {
97
- clear: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
98
- steer: (ctx: import("../common.ts").AgentViewContext, text: string) => Promise<import("../companion.ts").Steered>;
99
- sync: (ctx: import("../common.ts").AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
100
- } & {
101
- chat: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
102
- } & {
103
- messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
104
- }>;
105
- export {};
106
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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,8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