@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
@@ -1,58 +0,0 @@
1
- import type { AgentOptions as LibOptions, CompactionPolicy, Model } from '@restatedev/agentlib';
2
- import type { sdk as restate } from '@restatedev/sessions/internal';
3
- import type { AgentlibContext, Approval, Tools } from './tools.ts';
4
- /** agentlib's options that the agent sets itself, or takes under another name. */
5
- type Replaced = 'model' | 'name' | 'instructions' | 'tools' | 'onApproval' | 'onHumanApproval';
6
- /**
7
- * The options of an agentlib agent. agentlib's other options (`maxSteps`,
8
- * `compaction`, `contextWindow`, `toolResults`, `skills`, `beforeTool`,
9
- * `afterRun`...) go to its `agent()` as they are.
10
- */
11
- export interface Options<O = string> extends Omit<LibOptions<AgentlibContext, O>, Replaced> {
12
- /**
13
- * `provider/model-id` (`openai/…` or `anthropic/…`), else MODEL, else
14
- * `openai/gpt-6-sol`; or a model of agentlib (`aiModel` of
15
- * `@restatedev/agentlib/provider`, for any provider of the AI SDK).
16
- */
17
- model?: string | Model;
18
- /** The system prompt: a text, or agentlib's function of the run's context that returns one. */
19
- system?: LibOptions<AgentlibContext, O>['instructions'];
20
- /**
21
- * The tools: those of `@restatedev/agents` (`tool()`, `call`, `send`,
22
- * `workflow`, `signal`, `subagent`), and agentlib's own by the name the
23
- * model calls them, as in `[weather, { transfer: asyncTool(...) }]`.
24
- */
25
- tools?: Tools;
26
- /**
27
- * The tools of `@restatedev/agents` whose calls wait for a person's
28
- * approval before they run, by name, or a function of a call that says
29
- * whether it does. `pending` lists the wait, and `signal` approves it
30
- * (`true`, `"approved"`, `{ "approved": true }`) or denies it (anything
31
- * else). agentlib's own tools take `needsApproval` instead.
32
- */
33
- approval?: Approval;
34
- /**
35
- * How the model's conversation stays short from turn to turn. At a turn's
36
- * start, once its messages since the last summary pass `maxMessages`
37
- * (default 64) or `maxChars` (default 64 000), the earliest are summarized
38
- * by `model` (by default the agent's), and the latest `retainMessages`
39
- * (default 12) are kept. The summary is kept for the next turns. `false`
40
- * keeps the whole conversation. `messages` shows every turn either way.
41
- */
42
- history?: false | (CompactionPolicy & {
43
- model?: Model;
44
- });
45
- }
46
- /** An agent's name, and what it is beside its options. */
47
- export interface Definition<P extends string> {
48
- name: P;
49
- /** What it is: for the UI, and for the model of a parent that hands it tasks (`subagent`). */
50
- description?: string;
51
- /** It works unwatched (a sub-agent, say): its turn tells its companion at its end only. */
52
- background?: boolean;
53
- /** Options of the object, beside the ones the agent sets (its `retryPolicy`, say). */
54
- options?: restate.ObjectOptions;
55
- metadata?: Record<string, string>;
56
- }
57
- export {};
58
- //# sourceMappingURL=options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/agentlib/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,KAAK,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnE,kFAAkF;AAClF,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAE/F;;;;GAIG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,MAAM,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC;IACzF;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAEvB,+FAA+F;IAC/F,MAAM,CAAC,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAExD;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,CAAC,gBAAgB,GAAG;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;CAC1D;AAED,0DAA0D;AAC1D,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM;IAC1C,IAAI,EAAE,CAAC,CAAC;IACR,8FAA8F;IAC9F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/agentlib/options.ts"],"names":[],"mappings":""}
@@ -1,37 +0,0 @@
1
- import { sdk as restate } from '@restatedev/sessions/internal';
2
- import type { Options } from './options.ts';
3
- /**
4
- * One agentlib agent's turns. Its model, and with it agentlib's agent, load
5
- * on the first turn (a missing provider package fails that turn, not the
6
- * process); everything else is checked when the agent is defined.
7
- */
8
- export declare class Runtime<O> {
9
- private readonly name;
10
- private readonly background;
11
- private readonly libOptions;
12
- private readonly system;
13
- private readonly tools?;
14
- private readonly history;
15
- private readonly loadModel;
16
- private loading?;
17
- constructor(name: string, background: boolean, options: Options<O>);
18
- /** Answers `text` in the turn of `ctx`'s invocation. */
19
- answer(ctx: restate.ObjectContext, text: string): Promise<O | string>;
20
- /** What the companion learns as the turn starts. */
21
- private started;
22
- /** Loads the agent (once), and gives the turn what summarizes its conversation. */
23
- private prepare;
24
- /** Loads the model, and makes agentlib's agent with it. */
25
- private load;
26
- /** The options of agentlib's run of the turn. */
27
- private runOptions;
28
- /**
29
- * Records a progress event of the run. A change that clients see is
30
- * published to the companion, whose answer says which messages are steered
31
- * to the turn; the run gets them at its next event.
32
- */
33
- private onProgress;
34
- /** Ends a turn that has no answer, with `note`, at the agent and at its companion. */
35
- private end;
36
- }
37
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/agentlib/runtime.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAc5C;;;;GAIG;AACH,qBAAa,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAGzB;IACF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IACjD,OAAO,CAAC,OAAO,CAAC,CAAqB;IAErC,YAAY,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAajE;IAED,wDAAwD;IAClD,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,CA8B1E;IAED,oDAAoD;YACtC,OAAO;IASrB,mFAAmF;YACrE,OAAO;IAoBrB,2DAA2D;YAC7C,IAAI;IAiBlB,iDAAiD;IACjD,OAAO,CAAC,UAAU;IAelB;;;;OAIG;IACH,OAAO,CAAE,UAAU;IAcnB,sFAAsF;YACxE,GAAG;CAIlB"}
@@ -1,216 +0,0 @@
1
- // How an agentlib agent answers a message: a turn, from its start at the
2
- // companion, through agentlib's run (journaled), to its end.
3
- import { agent as agentlibAgent, } from '@restatedev/agentlib';
4
- import { execute, internal } from '@restatedev/restate-sdk-gen';
5
- import { sdk as restate } from '@restatedev/sessions/internal';
6
- import { approves, CANCELLED, ModelError, REFUSED, UNANSWERED } from '../common.js';
7
- import { checkHistory, modelLoader, refusing } from './model.js';
8
- import { Steering, takenIds } from './steering.js';
9
- import { companionAt, companionSendAt, read, TAKEN, waitForSignal } from './state.js';
10
- import { toolsOf } from './tools.js';
11
- import { conversationOf, Turn } from './turn.js';
12
- const { adopt } = internal;
13
- /**
14
- * One agentlib agent's turns. Its model, and with it agentlib's agent, load
15
- * on the first turn (a missing provider package fails that turn, not the
16
- * process); everything else is checked when the agent is defined.
17
- */
18
- export class Runtime {
19
- name;
20
- background;
21
- libOptions;
22
- system;
23
- tools;
24
- history;
25
- loadModel;
26
- loading;
27
- constructor(name, background, options) {
28
- const { model, system, tools, approval, history, ...libOptions } = options;
29
- this.name = name;
30
- this.background = background;
31
- this.libOptions = libOptions;
32
- this.system = system;
33
- this.history = history;
34
- this.loadModel = modelLoader(name, model);
35
- if (history)
36
- checkHistory(name, history);
37
- // Restate's tools become agentlib's here, so that a mistake fails now: two tools of one
38
- // name, or an approval of a tool the agent does not have (with no tools at all, too).
39
- const named = toolsOf(name, tools ?? [], approval);
40
- if (tools !== undefined)
41
- this.tools = named;
42
- }
43
- /** Answers `text` in the turn of `ctx`'s invocation. */
44
- async answer(ctx, text) {
45
- const steering = new Steering();
46
- steering.saw(await companionAt(ctx).start(await this.started(ctx)));
47
- const turn = await Turn.start(ctx, text);
48
- let lib;
49
- try {
50
- lib = await this.prepare(ctx, turn);
51
- }
52
- catch (error) {
53
- await this.end(ctx, turn, UNANSWERED);
54
- if (error instanceof restate.TerminalError)
55
- throw error;
56
- throw new ModelError(`${this.name}: its model: ${String(error)}`);
57
- }
58
- let result;
59
- try {
60
- result = await execute(ctx, lib.run(text, this.runOptions(ctx, turn, steering)));
61
- }
62
- catch (error) {
63
- // Only a terminal error ends the turn. Any other error fails the attempt:
64
- // Restate retries it, and replays the run from its journal.
65
- if (!(error instanceof restate.TerminalError))
66
- throw error;
67
- await this.end(ctx, turn, noteOf(error));
68
- throw error;
69
- }
70
- const answer = answerOf(result);
71
- // A cancellation that comes after the answer does not undo it: the turn still ends.
72
- await despiteCancellation(() => turn.answered(answer));
73
- await despiteCancellation(() => companionAt(ctx).close(ctx.request().id));
74
- return answer;
75
- }
76
- /** What the companion learns as the turn starts. */
77
- async started(ctx) {
78
- const since = new Date(await ctx.date.now()).toISOString();
79
- const started = { invocationId: ctx.request().id, since, steers: !this.background };
80
- // A watched turn's start is its first publish, which returns the
81
- // messages already steered to it.
82
- if (!this.background)
83
- started.publishes = true;
84
- return started;
85
- }
86
- /** Loads the agent (once), and gives the turn what summarizes its conversation. */
87
- async prepare(ctx, turn) {
88
- this.loading ??= this.load();
89
- let loaded;
90
- try {
91
- loaded = await this.loading;
92
- }
93
- catch (error) {
94
- // The next turn tries again.
95
- this.loading = undefined;
96
- throw error;
97
- }
98
- if (this.history !== false) {
99
- const policy = policyOf(this.history);
100
- turn.compactor = conversationOf(ctx, { model: loaded.summarizer, policy });
101
- }
102
- return loaded.lib;
103
- }
104
- /** Loads the model, and makes agentlib's agent with it. */
105
- async load() {
106
- const model = refusing(await this.loadModel());
107
- const options = {
108
- ...this.libOptions,
109
- name: this.name,
110
- model,
111
- onHumanApproval: askForApproval,
112
- };
113
- if (this.system !== undefined)
114
- options.instructions = this.system;
115
- if (this.tools !== undefined)
116
- options.tools = this.tools;
117
- // A summarizer of its own refuses with a 424, as the agent's model does.
118
- const custom = this.history ? this.history.model : undefined;
119
- const summarizer = custom ? refusing(custom) : model;
120
- return { lib: agentlibAgent(options), summarizer };
121
- }
122
- /** The options of agentlib's run of the turn. */
123
- runOptions(ctx, turn, steering) {
124
- const options = {
125
- name: this.name,
126
- context: { ctx },
127
- conversation: turn,
128
- onProgress: (event) => this.onProgress(ctx, turn, steering, event),
129
- };
130
- if (!this.background)
131
- options.controls = { steering: steering.source };
132
- return options;
133
- }
134
- /**
135
- * Records a progress event of the run. A change that clients see is
136
- * published to the companion, whose answer says which messages are steered
137
- * to the turn; the run gets them at its next event.
138
- */
139
- *onProgress(ctx, turn, steering, event) {
140
- yield* recordTaken(ctx, event);
141
- const changed = turn.progress(event);
142
- if (!changed || this.background)
143
- return;
144
- steering.saw(yield* adopt(companionAt(ctx).publish()));
145
- yield* steering.hand();
146
- }
147
- /** Ends a turn that has no answer, with `note`, at the agent and at its companion. */
148
- async end(ctx, turn, note) {
149
- await turn.close(note);
150
- await companionAt(ctx).close(ctx.request().id);
151
- }
152
- }
153
- /**
154
- * Waits for the signal `approval` for a tool call that needs one (agentlib's
155
- * `needsApproval`, its `humanApprovalTool`, a tool's `approve`). `pending`
156
- * lists the wait, with the tool and its input; `signal` decides it.
157
- */
158
- function* askForApproval(request, { context }) {
159
- const { call, question } = request;
160
- const input = { tool: call.name, input: call.input };
161
- if (question !== undefined)
162
- input.question = question;
163
- // A call may ask more than once: agentlib names each ask (`<agent>:approval:<call>:<n>`).
164
- const value = yield* waitForSignal(context.ctx, request.signalName, 'approval', input);
165
- return approves(value);
166
- }
167
- /**
168
- * Remembers the steered messages that the run took, so that their own
169
- * `steered` turns do nothing, and tells the companion.
170
- */
171
- function* recordTaken(ctx, event) {
172
- const ids = takenIds(event);
173
- if (ids.length === 0)
174
- return;
175
- const taken = (yield* read(ctx, TAKEN)) ?? [];
176
- ctx.set(TAKEN, [...taken, ...ids]);
177
- companionSendAt(ctx).taken(ids);
178
- }
179
- /** The bounds of the agent's `history`, without its model. */
180
- function policyOf(history) {
181
- if (!history)
182
- return {};
183
- const { maxMessages, maxChars, retainMessages } = history;
184
- return { maxMessages, maxChars, retainMessages };
185
- }
186
- /** The answer of a run: its output, or else why it stopped. */
187
- function answerOf(result) {
188
- if (result.status === 'completed')
189
- return result.output;
190
- if (result.output !== undefined)
191
- return result.output;
192
- return `Stopped: ${result.reason}`;
193
- }
194
- /** The note that says how a turn that failed for good ended. */
195
- function noteOf(error) {
196
- if (error instanceof restate.CancelledError)
197
- return CANCELLED;
198
- if (error.code === REFUSED)
199
- return UNANSWERED;
200
- return `Failed: ${error.message}`;
201
- }
202
- /**
203
- * Runs `step` of a turn that has its answer. Restate delivers a cancellation
204
- * once: if it interrupts the step, the step runs again.
205
- */
206
- async function despiteCancellation(step) {
207
- try {
208
- await step();
209
- }
210
- catch (error) {
211
- if (!(error instanceof restate.CancelledError))
212
- throw error;
213
- await step();
214
- }
215
- }
216
- //# sourceMappingURL=runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/agentlib/runtime.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6DAA6D;AAC7D,OAAO,EACL,KAAK,IAAI,aAAa,GAUvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAA2C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;AAQ3B;;;;GAIG;AACH,MAAM,OAAO,OAAO;IACD,IAAI,CAAS;IACb,UAAU,CAAU;IACpB,UAAU,CAGzB;IACe,MAAM,CAAuB;IAC7B,KAAK,C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AAC,cAAc,CAAC;YAAE,MAAM,KAAK,CAAC;QAC5D,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -1,114 +0,0 @@
1
- import { type Future, type Operation } from '@restatedev/restate-sdk-gen';
2
- import { sdk as restate } from '@restatedev/sessions/internal';
3
- type Context = restate.ObjectContext | restate.ObjectSharedContext;
4
- /** The turn being answered: its invocation, its message, and where its messages are. */
5
- export interface LiveTurn {
6
- /** The invocation id of the turn. */
7
- turn: string;
8
- /** The user's message that started it. */
9
- prompt: string;
10
- /** The id of the turn's first message. */
11
- from: number;
12
- /** How many messages the turn has so far. */
13
- n: number;
14
- }
15
- /** The bookkeeping of the messages that clients read, kept under {@link META}. */
16
- export interface Meta {
17
- /** How many messages the answered turns have: the id the next turn starts at. */
18
- chats: number;
19
- /** The cursor of the latest change. Every message written takes the next one. */
20
- cursor: number;
21
- /** The id of the first message, once the conversation was cleared. */
22
- first?: number;
23
- /** The turn being answered, if any. */
24
- live?: LiveTurn;
25
- }
26
- export declare const META = "meta";
27
- /** The ids of steered messages that a turn took, so that their own `steered` turn does nothing. */
28
- export declare const TAKEN = "taken";
29
- /** The model's conversation (agentlib's `LazyStateConversation`): chunks `t/<n>`, and `t/meta`. */
30
- export declare const CONVERSATION = "t";
31
- export declare const CONVERSATION_META = "t/meta";
32
- /** The key of the message `id`, as clients read it. */
33
- export declare const entryKey: (id: number) => string;
34
- export declare const emptyMeta: () => Meta;
35
- /** Reads state `key` inside an operation of the generator SDK. */
36
- export declare function read<T>(ctx: restate.ObjectContext, key: string): Future<T | null>;
37
- /** The agent's companion (`<agent>.prebuilt.restate`), at the agent's key. */
38
- export declare function companionAt(ctx: Context): restate.Client<{
39
- wait: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: {
40
- id: string;
41
- name: string;
42
- input?: unknown;
43
- }) => Promise<unknown>;
44
- resolve: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Signal) => Promise<{
45
- resolved: null;
46
- } | {
47
- resolved: string;
48
- }>;
49
- pending: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Waiting[]>;
50
- listen: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Waiting & {
51
- awakeable: string;
52
- }) => Promise<void>;
53
- start: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Started) => Promise<import("../companion.ts").Published | undefined>;
54
- awaitTurn: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: string) => Promise<void>;
55
- status: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../object.ts").Status>;
56
- watch: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
57
- close: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
58
- ended: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
59
- reset: (ctx: restate.ObjectContext<import("../companion.ts").State>) => Promise<void>;
60
- forget: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
61
- publish: (ctx: restate.ObjectContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Published>;
62
- steer: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Steer) => Promise<import("../companion.ts").Steered>;
63
- taken: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string[]) => Promise<void>;
64
- notifications: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Notifications>;
65
- subscribe: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: {
66
- revision: number;
67
- awakeable: string;
68
- }) => Promise<void>;
69
- unsubscribe: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
70
- }>;
71
- /** The agent's companion, for one-way sends. */
72
- export declare function companionSendAt(ctx: restate.ObjectContext): restate.SendClient<{
73
- wait: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: {
74
- id: string;
75
- name: string;
76
- input?: unknown;
77
- }) => Promise<unknown>;
78
- resolve: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Signal) => Promise<{
79
- resolved: null;
80
- } | {
81
- resolved: string;
82
- }>;
83
- pending: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Waiting[]>;
84
- listen: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Waiting & {
85
- awakeable: string;
86
- }) => Promise<void>;
87
- start: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Started) => Promise<import("../companion.ts").Published | undefined>;
88
- awaitTurn: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: string) => Promise<void>;
89
- status: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../object.ts").Status>;
90
- watch: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>, input: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
91
- close: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
92
- ended: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
93
- reset: (ctx: restate.ObjectContext<import("../companion.ts").State>) => Promise<void>;
94
- forget: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
95
- publish: (ctx: restate.ObjectContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Published>;
96
- steer: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: import("../companion.ts").Steer) => Promise<import("../companion.ts").Steered>;
97
- taken: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string[]) => Promise<void>;
98
- notifications: (ctx: restate.ObjectSharedContext<import("../companion.ts").State>) => Promise<import("../companion.ts").Notifications>;
99
- subscribe: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: {
100
- revision: number;
101
- awakeable: string;
102
- }) => Promise<void>;
103
- unsubscribe: (ctx: restate.ObjectContext<import("../companion.ts").State>, input: string) => Promise<void>;
104
- }>;
105
- /** Calls one of the agent's own handlers, at its own key, with JSON in and out. */
106
- export declare function callOwn<T>(ctx: Context, handler: string, input?: unknown): restate.InvocationPromise<T>;
107
- /**
108
- * Waits for the signal `name` and returns its value. The wait's id is
109
- * `<invocation id>:<id>`; `pending` lists it with `input`, and `signal`
110
- * resolves it.
111
- */
112
- export declare function waitForSignal(ctx: restate.ObjectContext, id: string, name: string, input?: unknown): Operation<unknown>;
113
- export {};
114
- //# sourceMappingURL=state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/agentlib/state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAK/D,KAAK,OAAO,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAEnE,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,CAAC,EAAE,MAAM,CAAC;CACX;AAED,kFAAkF;AAClF,MAAM,WAAW,IAAI;IACnB,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,eAAO,MAAM,IAAI,SAAS,CAAC;AAE3B,mGAAmG;AACnG,eAAO,MAAM,KAAK,UAAU,CAAC;AAE7B,mGAAmG;AACnG,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,iBAAiB,WAAyB,CAAC;AAExD,uDAAuD;AACvD,eAAO,MAAM,QAAQ,OAAQ,MAAM,WAAc,CAAC;AAElD,eAAO,MAAM,SAAS,QAAO,IAAiC,CAAC;AAE/D,kEAAkE;AAClE,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAIjF;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGvC;AAED,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGzD;AAED,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,gCASxE;AAED;;;;GAIG;AACH,wBAAiB,aAAa,CAC5B,GAAG,EAAE,OAAO,CAAC,aAAa,EAC1B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,OAAO,GACd,SAAS,CAAC,OAAO,CAAC,CAGpB"}
@@ -1,52 +0,0 @@
1
- // The agentlib agent's key/value state, and how its handlers reach that state,
2
- // the agent's companion, and the agent itself.
3
- import { internal } from '@restatedev/restate-sdk-gen';
4
- import { sdk as restate } from '@restatedev/sessions/internal';
5
- import { companionFor } from '../companion.js';
6
- const { adopt } = internal;
7
- export const META = 'meta';
8
- /** The ids of steered messages that a turn took, so that their own `steered` turn does nothing. */
9
- export const TAKEN = 'taken';
10
- /** The model's conversation (agentlib's `LazyStateConversation`): chunks `t/<n>`, and `t/meta`. */
11
- export const CONVERSATION = 't';
12
- export const CONVERSATION_META = `${CONVERSATION}/meta`;
13
- /** The key of the message `id`, as clients read it. */
14
- export const entryKey = (id) => `c/${id}`;
15
- export const emptyMeta = () => ({ chats: 0, cursor: 0 });
16
- /** Reads state `key` inside an operation of the generator SDK. */
17
- export function read(ctx, key) {
18
- // At runtime, `get` returns a RestatePromise, although its type says Promise.
19
- const value = ctx.get(key);
20
- return adopt(value);
21
- }
22
- /** The agent's companion (`<agent>.prebuilt.restate`), at the agent's key. */
23
- export function companionAt(ctx) {
24
- const agent = ctx.request().target.service;
25
- return ctx.objectClient(companionFor(agent), ctx.key);
26
- }
27
- /** The agent's companion, for one-way sends. */
28
- export function companionSendAt(ctx) {
29
- const agent = ctx.request().target.service;
30
- return ctx.objectSendClient(companionFor(agent), ctx.key);
31
- }
32
- /** Calls one of the agent's own handlers, at its own key, with JSON in and out. */
33
- export function callOwn(ctx, handler, input) {
34
- return ctx.genericCall({
35
- service: ctx.request().target.service,
36
- method: handler,
37
- key: ctx.key,
38
- parameter: input,
39
- inputSerde: restate.serde.json,
40
- outputSerde: restate.serde.json,
41
- });
42
- }
43
- /**
44
- * Waits for the signal `name` and returns its value. The wait's id is
45
- * `<invocation id>:<id>`; `pending` lists it with `input`, and `signal`
46
- * resolves it.
47
- */
48
- export function* waitForSignal(ctx, id, name, input) {
49
- const wait = { id: `${ctx.request().id}:${id}`, name, input };
50
- return yield* adopt(companionAt(ctx).wait(wait));
51
- }
52
- //# sourceMappingURL=state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/agentlib/state.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+CAA+C;AAC/C,OAAO,EAAE,QAAQ,EAA+B,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;AA4B3B,MAAM,C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,CAAC,WAAW,CAAa;QACjC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO;QACrC,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;QAC9B,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;KAChC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,SAAS,CAAC,CAAC,aAAa,CAC5B,GAA0B,EAC1B,EAAU,EACV,IAAY,EACZ,KAAe;IAEf,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC9D,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { ProgressEvent, SteeringUpdate } from '@restatedev/agentlib';
2
- import { type Future, type Operation } from '@restatedev/restate-sdk-gen';
3
- import type { Published } from '../companion.ts';
4
- /**
5
- * The messages steered to a turn. The turn learns of them when it publishes
6
- * a change to its companion, which answers with the messages it holds for
7
- * the turn. They go to the run, all at once, as one steering update, at the
8
- * run's next progress event after it asks for one.
9
- */
10
- export declare class Steering {
11
- private next?;
12
- private waiting;
13
- private readonly handed;
14
- /** agentlib's `controls.steering`: the next steering update, once there is one. */
15
- readonly source: () => Future<string | SteeringUpdate>;
16
- /** Notes the messages that a publish (or the turn's start) says are steered to the turn. */
17
- saw(published: Published | undefined): void;
18
- /** Hands the waiting messages to the run, if it asked for an update. */
19
- hand(): Operation<void>;
20
- }
21
- /** Returns the ids of the steered messages that a `steering` event says the run took. */
22
- export declare function takenIds(event: ProgressEvent): string[];
23
- //# sourceMappingURL=steering.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"steering.d.ts","sourceRoot":"","sources":["../../src/agentlib/steering.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAyB,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAS,MAAM,iBAAiB,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAC,CAAmC;IAChD,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C,mFAAmF;IACnF,QAAQ,CAAC,MAAM,QAAO,MAAM,CAAC,MAAM,GAAG,cAAc,CAAC,CAGnD;IAEF,4FAA4F;IAC5F,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,QAKnC;IAED,wEAAwE;IACvE,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAWvB;CACF;AAED,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAKvD"}
@@ -1,48 +0,0 @@
1
- import { channel } from '@restatedev/restate-sdk-gen';
2
- /**
3
- * The messages steered to a turn. The turn learns of them when it publishes
4
- * a change to its companion, which answers with the messages it holds for
5
- * the turn. They go to the run, all at once, as one steering update, at the
6
- * run's next progress event after it asks for one.
7
- */
8
- export class Steering {
9
- next;
10
- waiting = [];
11
- handed = new Set();
12
- /** agentlib's `controls.steering`: the next steering update, once there is one. */
13
- source = () => {
14
- this.next = channel();
15
- return this.next.receive;
16
- };
17
- /** Notes the messages that a publish (or the turn's start) says are steered to the turn. */
18
- saw(published) {
19
- for (const steer of published?.steering ?? []) {
20
- const known = this.handed.has(steer.id) || this.waiting.some((s) => s.id === steer.id);
21
- if (!known)
22
- this.waiting.push(steer);
23
- }
24
- }
25
- /** Hands the waiting messages to the run, if it asked for an update. */
26
- *hand() {
27
- const next = this.next;
28
- if (!next || this.waiting.length === 0)
29
- return;
30
- const batch = this.waiting.splice(0);
31
- for (const { id } of batch)
32
- this.handed.add(id);
33
- this.next = undefined;
34
- const message = batch.map((steer) => steer.text).join('\n\n');
35
- const ids = batch.map((steer) => steer.id);
36
- yield* next.send({ message, data: { steer: ids } });
37
- }
38
- }
39
- /** Returns the ids of the steered messages that a `steering` event says the run took. */
40
- export function takenIds(event) {
41
- if (event.type !== 'steering')
42
- return [];
43
- const ids = event.data?.steer;
44
- if (!Array.isArray(ids))
45
- return [];
46
- return ids.filter((id) => typeof id === 'string');
47
- }
48
- //# sourceMappingURL=steering.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"steering.js","sourceRoot":"","sources":["../../src/agentlib/steering.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAA6C,MAAM,6BAA6B,CAAC;AAGjG;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IACX,IAAI,CAAoC;IACxC,OAAO,GAAY,EAAE,CAAC;IACb,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAE5C,mFAAmF;IAC1E,MAAM,GAAG,GAAoC,EAAE;QACtD,IAAI,CAAC,IAAI,GAAG,OAAO,EAA2B,CAAC;QAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC,CAAC;IAEF,4FAA4F;IAC5F,GAAG,CAAC,SAAgC;QAClC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;YAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC;YACvF,IAAI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,CAAC,CAAC;AAClE,CAAC"}
@@ -1,33 +0,0 @@
1
- import { type Tool as LibTool } from '@restatedev/agentlib';
2
- import { sdk as restate } from '@restatedev/sessions/internal';
3
- import { type Approval, type Tool } from '../tools.ts';
4
- /**
5
- * The context of an agentlib agent's run (agentlib's `RunContext.context`,
6
- * and a tool's `context.context`): the invocation's context of the classic
7
- * SDK. An operation awaits its calls with `internal.adopt` of
8
- * @restatedev/restate-sdk-gen.
9
- */
10
- export interface AgentlibContext {
11
- readonly ctx: restate.ObjectContext;
12
- }
13
- /** A tool of agentlib (`tool`, `asyncTool`, `serviceTool`, `agentTool`, MCP's...). */
14
- export type AgentlibTool = LibTool<any>;
15
- /**
16
- * An agentlib agent's tools: the tools of `@restatedev/agents` (named by
17
- * their `name`), and agentlib's own (named by their key), in a list or in
18
- * one record.
19
- */
20
- export type Tools = ReadonlyArray<Tool | Record<string, AgentlibTool>> | Record<string, AgentlibTool | Tool>;
21
- export type { Approval };
22
- /**
23
- * Gives each tool its name, turning the tools of `@restatedev/agents` into
24
- * agentlib's. Those that `approval` names wait for a person's approval.
25
- */
26
- export declare function toolsOf(agent: string, tools: Tools, approval?: Approval): Record<string, AgentlibTool>;
27
- /**
28
- * Turns `tool`, one of `@restatedev/agents`, into agentlib's, named `name`.
29
- * As in every agent, arguments that do not fit its input are the model's to
30
- * fix, and a terminal error is the tool's answer, which the model sees.
31
- */
32
- export declare function fromTool(tool: Tool, name?: string, approval?: Approval): AgentlibTool;
33
- //# sourceMappingURL=tools.d.ts.map