@restatedev/agents 0.0.0 → 0.2.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +672 -2
  3. package/dist/calls.d.ts +29 -0
  4. package/dist/calls.d.ts.map +1 -0
  5. package/dist/calls.js +91 -0
  6. package/dist/calls.js.map +1 -0
  7. package/dist/claude/conversation.d.ts +33 -0
  8. package/dist/claude/conversation.d.ts.map +1 -0
  9. package/dist/claude/conversation.js +95 -0
  10. package/dist/claude/conversation.js.map +1 -0
  11. package/dist/claude/index.d.ts +77 -0
  12. package/dist/claude/index.d.ts.map +1 -0
  13. package/dist/claude/index.js +269 -0
  14. package/dist/claude/index.js.map +1 -0
  15. package/dist/client.d.ts +81 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +88 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/common.d.ts +261 -0
  20. package/dist/common.d.ts.map +1 -0
  21. package/dist/common.js +438 -0
  22. package/dist/common.js.map +1 -0
  23. package/dist/deepseek/index.d.ts +68 -0
  24. package/dist/deepseek/index.d.ts.map +1 -0
  25. package/dist/deepseek/index.js +363 -0
  26. package/dist/deepseek/index.js.map +1 -0
  27. package/dist/deepseek/persistence.d.ts +61 -0
  28. package/dist/deepseek/persistence.d.ts.map +1 -0
  29. package/dist/deepseek/persistence.js +224 -0
  30. package/dist/deepseek/persistence.js.map +1 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +12 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/langgraph/checkpointer.d.ts +29 -0
  36. package/dist/langgraph/checkpointer.d.ts.map +1 -0
  37. package/dist/langgraph/checkpointer.js +275 -0
  38. package/dist/langgraph/checkpointer.js.map +1 -0
  39. package/dist/langgraph/index.d.ts +66 -0
  40. package/dist/langgraph/index.d.ts.map +1 -0
  41. package/dist/langgraph/index.js +265 -0
  42. package/dist/langgraph/index.js.map +1 -0
  43. package/dist/log.d.ts +29 -0
  44. package/dist/log.d.ts.map +1 -0
  45. package/dist/log.js +145 -0
  46. package/dist/log.js.map +1 -0
  47. package/dist/object.d.ts +169 -0
  48. package/dist/object.d.ts.map +1 -0
  49. package/dist/object.js +221 -0
  50. package/dist/object.js.map +1 -0
  51. package/dist/opencode/db.d.ts +40 -0
  52. package/dist/opencode/db.d.ts.map +1 -0
  53. package/dist/opencode/db.js +161 -0
  54. package/dist/opencode/db.js.map +1 -0
  55. package/dist/opencode/index.d.ts +100 -0
  56. package/dist/opencode/index.d.ts.map +1 -0
  57. package/dist/opencode/index.js +436 -0
  58. package/dist/opencode/index.js.map +1 -0
  59. package/dist/output.d.ts +17 -0
  60. package/dist/output.d.ts.map +1 -0
  61. package/dist/output.js +81 -0
  62. package/dist/output.js.map +1 -0
  63. package/dist/pi/index.d.ts +89 -0
  64. package/dist/pi/index.d.ts.map +1 -0
  65. package/dist/pi/index.js +293 -0
  66. package/dist/pi/index.js.map +1 -0
  67. package/dist/pi/storage.d.ts +5 -0
  68. package/dist/pi/storage.d.ts.map +1 -0
  69. package/dist/pi/storage.js +41 -0
  70. package/dist/pi/storage.js.map +1 -0
  71. package/dist/signals.d.ts +154 -0
  72. package/dist/signals.d.ts.map +1 -0
  73. package/dist/signals.js +256 -0
  74. package/dist/signals.js.map +1 -0
  75. package/dist/tools.d.ts +158 -0
  76. package/dist/tools.d.ts.map +1 -0
  77. package/dist/tools.js +211 -0
  78. package/dist/tools.js.map +1 -0
  79. package/dist/webhook.d.ts +71 -0
  80. package/dist/webhook.d.ts.map +1 -0
  81. package/dist/webhook.js +102 -0
  82. package/dist/webhook.js.map +1 -0
  83. package/package.json +218 -5
  84. package/src/calls.ts +138 -0
  85. package/src/claude/README.md +84 -0
  86. package/src/claude/conversation.ts +114 -0
  87. package/src/claude/index.ts +364 -0
  88. package/src/client.ts +176 -0
  89. package/src/common.ts +550 -0
  90. package/src/deepseek/README.md +110 -0
  91. package/src/deepseek/index.ts +464 -0
  92. package/src/deepseek/persistence.ts +293 -0
  93. package/src/index.ts +24 -0
  94. package/src/langgraph/README.md +87 -0
  95. package/src/langgraph/checkpointer.ts +364 -0
  96. package/src/langgraph/index.ts +349 -0
  97. package/src/log.ts +193 -0
  98. package/src/object.ts +319 -0
  99. package/src/opencode/README.md +125 -0
  100. package/src/opencode/db.ts +223 -0
  101. package/src/opencode/index.ts +559 -0
  102. package/src/output.ts +95 -0
  103. package/src/pi/README.md +105 -0
  104. package/src/pi/index.ts +382 -0
  105. package/src/pi/storage.ts +65 -0
  106. package/src/signals.ts +386 -0
  107. package/src/tools.ts +343 -0
  108. package/src/webhook.ts +161 -0
@@ -0,0 +1,169 @@
1
+ import * as restate from '@restatedev/sessions';
2
+ import { type Messages, type MessagesRequest, type Turn } from './common.ts';
3
+ import { type Notifications, type Resolved, type Signal, type Waiting, type Watch } from './signals.ts';
4
+ /** What an object is doing: the message it answers, if any, and what its tools wait for. */
5
+ export interface Status {
6
+ /** The message being answered (by a `chat` handler), or null. */
7
+ answering: Turn | null;
8
+ /** The waits of its tools, oldest first (see `pending`). */
9
+ waiting: Waiting[];
10
+ }
11
+ /** What `stop` did: the invocation of the message it stopped, or null if none was answered. */
12
+ export interface Stopped {
13
+ stopped: string | null;
14
+ }
15
+ /**
16
+ * The views every object here has, beside its own: `signal`, which resolves
17
+ * a wait of the object's tools (see `signal` in tools.ts), `pending`, the
18
+ * waits, `status`, what the object is doing, `stop`, which stops the message
19
+ * it answers, and `notifications` and `watch`, the revision of its
20
+ * conversation, and a wait for a newer one (an agent's
21
+ * has `clear` and `sync` too: {@link followed}). Each asks the object's
22
+ * `signals` companion, which knows what the object does: they run while the
23
+ * object's handler works.
24
+ */
25
+ declare const BUILT_IN: {
26
+ signal: (ctx: restate.ViewContext, signal: Signal) => Promise<Resolved>;
27
+ pending: (ctx: restate.ViewContext) => Promise<Waiting[]>;
28
+ status: (ctx: restate.ViewContext) => Promise<Status>;
29
+ /** Cancel the invocation of the message being answered (`status`'s), as Restate's admin API cancels one. */
30
+ stop: (ctx: restate.ViewContext) => Promise<Stopped>;
31
+ /** The revision of the conversation: each change of what `messages` and `status` give increases it. */
32
+ notifications: (ctx: restate.ViewContext) => Promise<Notifications>;
33
+ /**
34
+ * The revision, once there is one newer than `revision`, or at the timeout (50 s by
35
+ * default, at most 60 s), whichever comes first: a client then reads what
36
+ * changed. It waits in Restate, holding no process; a client that retries
37
+ * it with the same idempotency key joins the same wait.
38
+ */
39
+ watch: {
40
+ inactivityTimeout: {
41
+ minutes: number;
42
+ };
43
+ handler: (ctx: restate.ViewContext, watch: Watch) => Promise<Notifications>;
44
+ };
45
+ };
46
+ /**
47
+ * The views that agents (an object with a `messages` view) have beside
48
+ * those of every object: `clear`, which forgets the conversation; and
49
+ * `sync`, the conversation since `cursor` (by default, all of it), what the
50
+ * agent is doing, and the revision, in one request; with `revision`, once
51
+ * there is a newer one, or at the timeout. A client follows the
52
+ * conversation by sending each answer's `revision` and `cursor` back, at
53
+ * once while it has `more`.
54
+ */
55
+ declare const followed: (messages: (ctx: restate.ViewContext, request: MessagesRequest) => Promise<Messages>) => {
56
+ /**
57
+ * Forget the conversation: stop the message being answered (as `stop`),
58
+ * then empty the key's database, and what its `signals` hold (waits and
59
+ * kept signals). The log's ids and cursors go on (see
60
+ * log.ts), so a follower reads on, and drops the messages before `first`.
61
+ * A message sent before it is answered first, then forgotten too; one sent
62
+ * after starts anew.
63
+ */
64
+ clear: {
65
+ inactivityTimeout: {
66
+ minutes: number;
67
+ };
68
+ handler: (ctx: restate.ViewContext) => Promise<Stopped>;
69
+ };
70
+ sync: {
71
+ inactivityTimeout: {
72
+ minutes: number;
73
+ };
74
+ handler: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit }?: SyncRequest) => Promise<Synced>;
75
+ };
76
+ };
77
+ /**
78
+ * The agents' handlers that only their own views call (Restate's ingress
79
+ * refuses them), and their types leave out: `erase`, `clear`'s work, once
80
+ * the handlers before it are done. It empties the key's database and its
81
+ * signals', and the log goes on where it got to (see log.ts).
82
+ */
83
+ declare const INTERNAL: {
84
+ erase: {
85
+ ingressPrivate: boolean;
86
+ handler: (ctx: restate.SessionContext) => Promise<void>;
87
+ };
88
+ };
89
+ /**
90
+ * What `sync` reads: what is new or changed since `cursor` (default 0, all
91
+ * of it), at most `limit` messages (default 100); once the revision is past
92
+ * `revision`, if given, or at `timeoutSeconds` (default 50, at most 60).
93
+ */
94
+ export interface SyncRequest {
95
+ cursor?: number;
96
+ revision?: number;
97
+ timeoutSeconds?: number;
98
+ limit?: number;
99
+ }
100
+ /** What `sync` answers: the messages since the cursor, as `messages` gives them, the status and the revision. */
101
+ export interface Synced extends Messages {
102
+ revision: number;
103
+ status: Status;
104
+ }
105
+ /** An object's (or agent's) name, its description, and the tables of your own in its database, if any (see `sessionObject`). */
106
+ export interface Definition<P extends string> {
107
+ name: P;
108
+ /** What it is: for the UI, and for the model of a parent that hands it tasks (`subagent`). */
109
+ description?: string;
110
+ schema?: readonly restate.Step[];
111
+ /**
112
+ * Whether it works unwatched, such as a subagent: its turn calls its
113
+ * `signals` only at its end, not at each step, so a client that follows it
114
+ * sees each turn once it ended. `messages` has every turn as before.
115
+ */
116
+ background?: boolean;
117
+ }
118
+ /** Each entry's function, as clients see it; none for entries left out. */
119
+ type Functions<H> = string extends keyof H ? unknown : {
120
+ [K in keyof H]: H[K] extends {
121
+ handler: infer F;
122
+ } ? F : H[K];
123
+ };
124
+ /** The names of the handlers and views every object (or agent) has, which its own cannot take. */
125
+ type Reserved = {
126
+ [name in keyof typeof BUILT_IN | keyof ReturnType<typeof followed> | keyof typeof INTERNAL]?: 'a handler every object has: name yours otherwise';
127
+ };
128
+ /** What an object with `handlers` and `views` has: those of every object, an agent's `clear` and `sync`, and its own. */
129
+ type With<H, V> = Functions<typeof BUILT_IN> & (V extends {
130
+ messages: unknown;
131
+ } ? Functions<ReturnType<typeof followed>> : unknown) & Functions<H> & Functions<V>;
132
+ /**
133
+ * A Restate virtual object with a SQL database per key, `ctx.db`: a
134
+ * `restate.sessionObject` of @restatedev/sessions, set up for agents.
135
+ *
136
+ * const notes = sessionObject({
137
+ * name: 'notes',
138
+ * handlers: {
139
+ * add: (ctx, note: string) => ctx.db.execute('INSERT INTO notes VALUES (?)', [note]),
140
+ * },
141
+ * });
142
+ *
143
+ * Besides its own handlers and views, it has the views `status`, what it is
144
+ * doing (the message it answers, and what its tools wait for), `stop`,
145
+ * which stops that message, `pending`, the waits
146
+ * of its tools (`signal()`), `signal({ id, value })`, which resolves one,
147
+ * and `notifications` and `watch({ revision })`, to follow its
148
+ * conversation. An agent, an object with a `messages` view (such as
149
+ * `claude.messages()`), has `clear` too, which forgets its conversation
150
+ * (its database too), and `sync`, which `follow()` of @restatedev/agents/client
151
+ * reads.
152
+ *
153
+ * `schema`, optional: tables of your own, beside the agent's (which are its
154
+ * own business), made in each key's database as a session object makes
155
+ * them. Any name is yours but those starting with `restate_`, the agent's
156
+ * (`restate_pi_tasks`, `restate_claude_messages`, `restate_agent_log`...);
157
+ * OpenCode's tables are in a database of their own.
158
+ *
159
+ * `options` and `metadata` add to (or replace) the ones set here, such as
160
+ * `options: { retryPolicy: ... }`.
161
+ */
162
+ export declare const sessionObject: <P extends string, H extends Record<string, restate.Entry<restate.SessionContext>>, V extends Record<string, restate.Entry<restate.ViewContext>>>(definition: Definition<P> & {
163
+ handlers?: H & Reserved;
164
+ views?: V & Reserved;
165
+ metadata?: Record<string, string>;
166
+ options?: restate.ObjectOptions;
167
+ }) => restate.VirtualObjectDefinition<P, With<H, V>>;
168
+ export {};
169
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAkC,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAW,KAAK,IAAI,EAA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;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,GACpF,SAAS,CAAC,CAAC,CAAC,GACZ,SAAS,CAAC,CAAC,CAAC,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,aAAa,GACxB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,EAC/D,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,cAEhD,UAAU,CAAC,CAAC,CAAC,GAAG;IAC1B,QAAQ,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;IACxB,KAAK,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;CACjC,KACA,OAAO,CAAC,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAuC/C,CAAC"}
package/dist/object.js ADDED
@@ -0,0 +1,221 @@
1
+ // Virtual objects set up for SQL and agents.
2
+ import * as restate from '@restatedev/sessions';
3
+ import { reset } from '@restatedev/sessions/internal';
4
+ import { cleared, onClear, inBackground, refusal } from './common.js';
5
+ import * as log from './log.js';
6
+ import { signals, signalsOf, withCompanion, } from './signals.js';
7
+ /**
8
+ * The options of every object here, beside a session object's: retries for
9
+ * weeks, since each attempt resumes from the database: soon after a crash,
10
+ * then twice as long each time, up to 10 seconds apart (a provider's rate
11
+ * limit, say, is not asked again twice a second).
12
+ */
13
+ const OPTIONS = {
14
+ retryPolicy: { initialInterval: 50, exponentiationFactor: 2, maxInterval: 10_000, maxAttempts: 100_000 },
15
+ };
16
+ /**
17
+ * A call of the companion's of `ctx`; with `step`, a change, keyed by the
18
+ * request and `step`: a restarted view joins the same call. A read has no
19
+ * key: asked again, it answers again, and Restate keeps nothing of it.
20
+ */
21
+ const companion = (ctx, step) => ctx.rpc(signals, signalsOf(ctx), step === undefined ? {} : { idempotencyKey: `${ctx.request.id}:${step}` });
22
+ /**
23
+ * Cancel the invocation of the message being answered, if any, and say
24
+ * which. The companion's `status` says which, with a key of the request and
25
+ * `step`: a restarted view gets the same answer, and cancels the same
26
+ * invocation again (which does nothing), not the message that started once
27
+ * it was cancelled.
28
+ */
29
+ async function stopped(ctx, step) {
30
+ const turn = (await companion(ctx, step).status()).answering;
31
+ if (turn)
32
+ ctx.cancel(turn.invocationId);
33
+ return { stopped: turn?.invocationId ?? null };
34
+ }
35
+ /**
36
+ * Views that wait on the companion (`watch`, `sync`, up to a minute) or on
37
+ * the object (`clear`): Restate
38
+ * suspends one that waits past its inactivity timeout, which restarts it,
39
+ * so it is longer than the wait.
40
+ */
41
+ const WAITS = { inactivityTimeout: { minutes: 5 } };
42
+ /**
43
+ * The views every object here has, beside its own: `signal`, which resolves
44
+ * a wait of the object's tools (see `signal` in tools.ts), `pending`, the
45
+ * waits, `status`, what the object is doing, `stop`, which stops the message
46
+ * it answers, and `notifications` and `watch`, the revision of its
47
+ * conversation, and a wait for a newer one (an agent's
48
+ * has `clear` and `sync` too: {@link followed}). Each asks the object's
49
+ * `signals` companion, which knows what the object does: they run while the
50
+ * object's handler works.
51
+ */
52
+ const BUILT_IN = {
53
+ signal: async (ctx, signal) => companion(ctx, 'signal').resolve(signal),
54
+ pending: async (ctx) => companion(ctx).pending(),
55
+ status: async (ctx) => companion(ctx).status(),
56
+ /** Cancel the invocation of the message being answered (`status`'s), as Restate's admin API cancels one. */
57
+ stop: async (ctx) => stopped(ctx, 'stop'),
58
+ /** The revision of the conversation: each change of what `messages` and `status` give increases it. */
59
+ notifications: async (ctx) => companion(ctx).notifications(),
60
+ /**
61
+ * The revision, once there is one newer than `revision`, or at the timeout (50 s by
62
+ * default, at most 60 s), whichever comes first: a client then reads what
63
+ * changed. It waits in Restate, holding no process; a client that retries
64
+ * it with the same idempotency key joins the same wait.
65
+ */
66
+ watch: {
67
+ ...WAITS,
68
+ handler: async (ctx, watch) => companion(ctx, 'watch').watch(watch),
69
+ },
70
+ };
71
+ /**
72
+ * The views that agents (an object with a `messages` view) have beside
73
+ * those of every object: `clear`, which forgets the conversation; and
74
+ * `sync`, the conversation since `cursor` (by default, all of it), what the
75
+ * agent is doing, and the revision, in one request; with `revision`, once
76
+ * there is a newer one, or at the timeout. A client follows the
77
+ * conversation by sending each answer's `revision` and `cursor` back, at
78
+ * once while it has `more`.
79
+ */
80
+ const followed = (messages) => ({
81
+ /**
82
+ * Forget the conversation: stop the message being answered (as `stop`),
83
+ * then empty the key's database, and what its `signals` hold (waits and
84
+ * kept signals). The log's ids and cursors go on (see
85
+ * log.ts), so a follower reads on, and drops the messages before `first`.
86
+ * A message sent before it is answered first, then forgotten too; one sent
87
+ * after starts anew.
88
+ */
89
+ clear: {
90
+ // `erase` waits for the messages sent before it.
91
+ ...WAITS,
92
+ handler: async (ctx) => {
93
+ const stop = await stopped(ctx, 'clear');
94
+ await ctx.rpc({
95
+ service: ctx.request.target.service,
96
+ key: ctx.key,
97
+ handler: 'erase',
98
+ idempotencyKey: `${ctx.request.id}:erase`,
99
+ });
100
+ return stop;
101
+ },
102
+ },
103
+ sync: {
104
+ ...WAITS,
105
+ handler: async (ctx, { cursor = 0, revision, timeoutSeconds = 50, limit = 100 } = {}) => {
106
+ if (revision !== undefined)
107
+ await companion(ctx, 'watch').watch({ revision, timeoutSeconds });
108
+ // The revision first: a change after it shows in the next sync. Then
109
+ // what the object does, and its conversation, as they are now.
110
+ const now = await companion(ctx).notifications();
111
+ const status = await companion(ctx).status();
112
+ return { revision: now.revision, status, ...(await messages(ctx, { cursor, limit })) };
113
+ },
114
+ },
115
+ });
116
+ /**
117
+ * The agents' handlers that only their own views call (Restate's ingress
118
+ * refuses them), and their types leave out: `erase`, `clear`'s work, once
119
+ * the handlers before it are done. It empties the key's database and its
120
+ * signals', and the log goes on where it got to (see log.ts).
121
+ */
122
+ const INTERNAL = {
123
+ erase: {
124
+ ingressPrivate: true,
125
+ handler: async (ctx) => {
126
+ const start = startAfter(await log.page(ctx.db, { limit: 1 }));
127
+ await ctx.db.transaction(async (tx) => {
128
+ await reset(tx);
129
+ await log.restart(tx, start);
130
+ });
131
+ await cleared(ctx);
132
+ await ctx.rpc(signals, signalsOf(ctx), { idempotencyKey: `${ctx.request.id}:reset` }).reset();
133
+ },
134
+ },
135
+ };
136
+ /** Where the log starts after `latest`, its latest message: past its ids and cursor. */
137
+ const startAfter = ({ messages: [latest], cursor, first = 0 }) => ({
138
+ seq: cursor,
139
+ id: latest ? latest.id + 1 : first,
140
+ });
141
+ /**
142
+ * A Restate virtual object with a SQL database per key, `ctx.db`: a
143
+ * `restate.sessionObject` of @restatedev/sessions, set up for agents.
144
+ *
145
+ * const notes = sessionObject({
146
+ * name: 'notes',
147
+ * handlers: {
148
+ * add: (ctx, note: string) => ctx.db.execute('INSERT INTO notes VALUES (?)', [note]),
149
+ * },
150
+ * });
151
+ *
152
+ * Besides its own handlers and views, it has the views `status`, what it is
153
+ * doing (the message it answers, and what its tools wait for), `stop`,
154
+ * which stops that message, `pending`, the waits
155
+ * of its tools (`signal()`), `signal({ id, value })`, which resolves one,
156
+ * and `notifications` and `watch({ revision })`, to follow its
157
+ * conversation. An agent, an object with a `messages` view (such as
158
+ * `claude.messages()`), has `clear` too, which forgets its conversation
159
+ * (its database too), and `sync`, which `follow()` of @restatedev/agents/client
160
+ * reads.
161
+ *
162
+ * `schema`, optional: tables of your own, beside the agent's (which are its
163
+ * own business), made in each key's database as a session object makes
164
+ * them. Any name is yours but those starting with `restate_`, the agent's
165
+ * (`restate_pi_tasks`, `restate_claude_messages`, `restate_agent_log`...);
166
+ * OpenCode's tables are in a database of their own.
167
+ *
168
+ * `options` and `metadata` add to (or replace) the ones set here, such as
169
+ * `options: { retryPolicy: ... }`.
170
+ */
171
+ export const sessionObject = (definition) => {
172
+ const { name, description, schema, background, handlers = {}, views = {}, metadata, options } = definition;
173
+ if (background)
174
+ inBackground(name);
175
+ const own = [
176
+ ...Object.keys(BUILT_IN),
177
+ ...Object.keys(followed(async () => ({}))),
178
+ ...Object.keys(INTERNAL),
179
+ ];
180
+ if ('messages' in handlers) {
181
+ throw new Error(`${name}: \`messages\` is a view: put it in \`views\`, so that the object is an agent`);
182
+ }
183
+ for (const key of own) {
184
+ if (key in handlers || key in views)
185
+ throw new Error(`${name}: \`${key}\` is a handler of @restatedev/agents' own: name yours otherwise`);
186
+ }
187
+ // A model provider's refusal (a missing API key) ends a handler's invocation.
188
+ const yours = Object.fromEntries(Object.entries(handlers).map(([key, entry]) => [
189
+ key,
190
+ answering(entry),
191
+ ]));
192
+ const messages = views.messages;
193
+ onClear(name, messages);
194
+ const page = (typeof messages === 'function' ? messages : messages?.handler);
195
+ const agent = page === undefined ? {} : followed(page);
196
+ return withCompanion(restate.sessionObject({
197
+ name,
198
+ description,
199
+ schema,
200
+ handlers: { ...(messages === undefined ? {} : INTERNAL), ...yours },
201
+ views: { ...BUILT_IN, ...agent, ...views },
202
+ metadata,
203
+ options: { ...OPTIONS, ...options },
204
+ }));
205
+ };
206
+ /** `entry`, but a model provider's refusal it fails with ends its invocation, as `chat`'s does. */
207
+ function answering(entry) {
208
+ const { handler, ...options } = typeof entry === 'function' ? { handler: entry } : entry;
209
+ return {
210
+ ...options,
211
+ handler: async (ctx, input) => {
212
+ try {
213
+ return await handler(ctx, input);
214
+ }
215
+ catch (error) {
216
+ throw refusal(error) ?? error;
217
+ }
218
+ },
219
+ };
220
+ }
221
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC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C,CAAC;AAEF,mGAAmG;AACnG,SAAS,SAAS,CAAC,KAA4C;IAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACzF,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,KAAK,EAAE,GAA2B,EAAE,KAAc,EAAE,EAAE;YAC7D,IAAI,CAAC;gBACH,OAAO,MAAM,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;YAChC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Effect, Layer } from 'effect';
2
+ import { SqlClient } from 'effect/sql';
3
+ import { OpenCode } from '@opencode/sdk/effect';
4
+ import type { Plugin } from '@opencode/plugin';
5
+ import type { Database } from '@restatedev/sessions';
6
+ /** Closed: every later statement fails. */
7
+ export interface Fence {
8
+ closed: boolean;
9
+ }
10
+ /** An Effect SqlClient over `db`, with its statements refused once `fence` closes. */
11
+ export declare function sqlClient(db: Database, fence: Fence): Layer.Layer<SqlClient.SqlClient>;
12
+ export interface OpenOptions {
13
+ /** OpenCode plugins: models, tools, agents. */
14
+ plugins?: Plugin.Plugin[];
15
+ /** OpenCode's config (opencode.json), inline. */
16
+ config?: Record<string, unknown>;
17
+ /**
18
+ * OpenCode's own filesystem, search and shell, on the local machine, for
19
+ * its built-in tools (read, write, edit, bash, glob, grep...) in a
20
+ * session's directory. Without it, the workerd profile has none.
21
+ */
22
+ local?: boolean;
23
+ /**
24
+ * Resume the turns a previous attempt left unfinished, as OpenCode does
25
+ * when it boots (default true). A reader beside a running turn does not.
26
+ */
27
+ resume?: boolean;
28
+ }
29
+ /** A booted OpenCode: `call` runs one of `client`'s calls (which return Effects); `close` shuts it down. */
30
+ export interface Host {
31
+ client: OpenCode.Interface;
32
+ call<A, E, R>(effect: Effect.Effect<A, E, R>): Promise<A>;
33
+ close(): Promise<void>;
34
+ }
35
+ /**
36
+ * Boot OpenCode with its database in `db`. Booting resumes the turns a
37
+ * previous attempt left unfinished. Close the host when done.
38
+ */
39
+ export declare function openOpenCode(db: Database, fence: Fence, { plugins, config, local, resume }: OpenOptions): Promise<Host>;
40
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/opencode/db.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAW,MAAM,EAAQ,KAAK,EAAiB,MAAM,QAAQ,CAAC;AAErE,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAkB,QAAQ,EAAY,MAAM,sBAAsB,CAAC;AAE/E,2CAA2C;AAC3C,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC;CACjB;AA+CD,sFAAsF;AACtF,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAkEtF;AAED,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAC1B,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,4GAA4G;AAC5G,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC;IAC3B,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAYD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,QAAQ,EACZ,KAAK,EAAE,KAAK,EACZ,EAAE,OAAY,EAAE,MAAW,EAAE,KAAa,EAAE,MAAa,EAAE,EAAE,WAAW,GACvE,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
@@ -0,0 +1,161 @@
1
+ // OpenCode on the object's database: `openOpenCode(db, fence, options)` boots
2
+ // OpenCode 2.0's embedded host (@opencode/sdk) with its database in a
3
+ // SQL session, `ctx.db`.
4
+ //
5
+ // The host is OpenCode's workerd profile, the one it boots in a Cloudflare
6
+ // Durable Object: no local filesystem, shell, terminal or version control,
7
+ // config given inline, plugins given in code. Only its database differs. The
8
+ // workerd profile reads a Durable Object's SQLite, whose `exec` is
9
+ // synchronous; here OpenCode gets an Effect SqlClient instead, which is
10
+ // asynchronous, through `Database.configuredClient` (OpenCode's), the seam OpenCode keeps
11
+ // for an injected client. Each transaction is an SQL transaction, and the
12
+ // session runs statements one at a time, as OpenCode's own clients do.
13
+ //
14
+ // `fence.closed` refuses every statement from then on: an attempt that is
15
+ // giving up stores nothing more, as Restate fences an attempt that a newer
16
+ // one replaced.
17
+ import { Context, Effect, Exit, Layer, Option, Scope } from 'effect';
18
+ import { Reactivity } from 'effect/reactivity';
19
+ import { SqlClient, Statement } from 'effect/sql';
20
+ import { SqlError, UnknownError } from 'effect/sql/SqlError';
21
+ import { Database as OpenCodeDatabase } from '@opencode/core/database/database';
22
+ import { SessionRestart } from '@opencode/core/session/execution/restart';
23
+ import { ServerWorkerd } from '@opencode/server/workerd';
24
+ import { fromPromise } from '@opencode/core/plugin/promise';
25
+ import { OpenCode } from '@opencode/sdk/effect';
26
+ const error = (operation, cause) => new SqlError({
27
+ reason: new UnknownError({
28
+ cause,
29
+ message: cause instanceof Error ? cause.message : String(cause),
30
+ operation,
31
+ }),
32
+ });
33
+ /** The connection inside a transaction, for statements of that transaction. */
34
+ const InTransaction = Context.Service('@restatedev/agents/OpenCodeTransaction');
35
+ /**
36
+ * A connection whose statements go to `target`: the session, which runs one
37
+ * call at a time and holds them while a transaction runs, or that
38
+ * transaction's database. Each is refused once `fence` closes.
39
+ */
40
+ function connection(target, fence) {
41
+ // Effect binds what the compiler made of OpenCode's values: SQL values.
42
+ const exec = (read, sql, params) => Effect.tryPromise({
43
+ try: async () => {
44
+ if (fence.closed)
45
+ throw new Error('the attempt is over');
46
+ return read(sql, params);
47
+ },
48
+ catch: (cause) => error('execute', cause),
49
+ });
50
+ const run = (sql, params = []) => exec((s, p) => target.query(s, p), sql, params);
51
+ const runValues = (sql, params = []) => exec((s, p) => target.values(s, p), sql, params);
52
+ const transformed = (sql, params, transformRows) => transformRows ? Effect.map(run(sql, params), transformRows) : run(sql, params);
53
+ return {
54
+ execute: transformed,
55
+ executeRaw: (sql, params) => run(sql, params),
56
+ executeValues: (sql, params) => runValues(sql, params),
57
+ executeValuesUnprepared: (sql, params) => runValues(sql, params),
58
+ executeUnprepared: transformed,
59
+ executeStream: () => {
60
+ throw new Error('executeStream is not supported');
61
+ },
62
+ };
63
+ }
64
+ /** An Effect SqlClient over `db`, with its statements refused once `fence` closes. */
65
+ export function sqlClient(db, fence) {
66
+ // `effect` as one SQL transaction: it commits when `effect` succeeds
67
+ // and rolls back when it fails. Its statements go to the transaction's
68
+ // database.
69
+ const withTransaction = (effect) => Effect.withFiber((fiber) => {
70
+ if (Option.isSome(Context.getOption(fiber.context, InTransaction))) {
71
+ return Effect.fail(error('transaction', new Error('nested transactions are not supported')));
72
+ }
73
+ return Effect.callback((resume) => {
74
+ const rollback = new Error('rollback');
75
+ let interrupted = false;
76
+ let resumed = false;
77
+ // Settles when the transaction has committed, or rejects: with
78
+ // `rollback` once `effect` failed, or with the error of BEGIN or COMMIT.
79
+ const ended = db.transaction((tx) => new Promise((resolve, reject) => {
80
+ if (interrupted)
81
+ return reject(rollback);
82
+ const inner = Effect.provideContext(effect, Context.add(fiber.context, InTransaction, [connection(tx, fence), 0]));
83
+ resumed = true;
84
+ resume(
85
+ // A finalizer, so that the body settles however `effect`
86
+ // ends, an interruption included: otherwise the transaction
87
+ // would hold the session for good.
88
+ Effect.onExit(inner, (exit) => {
89
+ if (Exit.isSuccess(exit)) {
90
+ resolve();
91
+ return Effect.void;
92
+ }
93
+ reject(rollback);
94
+ return Effect.promise(() => settled);
95
+ }).pipe(
96
+ // The commit is part of the transaction: if it fails, so
97
+ // does the transaction.
98
+ Effect.flatMap((value) => Effect.as(Effect.tryPromise({ try: () => ended, catch: (e) => error('commit', e) }), value))));
99
+ }));
100
+ const settled = ended.catch((cause) => {
101
+ // BEGIN failed: `effect` never ran.
102
+ if (!resumed && cause !== rollback)
103
+ resume(Effect.fail(error('transaction', cause)));
104
+ });
105
+ return Effect.suspend(() => {
106
+ interrupted = true;
107
+ return Effect.promise(() => settled);
108
+ });
109
+ });
110
+ });
111
+ const make = Effect.gen(function* () {
112
+ const client = yield* SqlClient.make({
113
+ acquirer: Effect.succeed(connection(db, fence)),
114
+ compiler: Statement.makeCompilerSqlite(),
115
+ spanAttributes: [['db.system.name', 'sqlite']],
116
+ transactionService: InTransaction,
117
+ });
118
+ return Object.assign(client, { withTransaction, transactionStatements: false });
119
+ });
120
+ return Layer.effect(SqlClient.SqlClient, make).pipe(Layer.provide(Reactivity.layer));
121
+ }
122
+ /**
123
+ * How OpenCode resumes the turns a previous attempt left unfinished when it
124
+ * boots: each, however often it crashed (Restate's retry policy decides how
125
+ * often an attempt is retried), or, without `resume`, none.
126
+ */
127
+ const restarts = (resume) => resume
128
+ ? SessionRestart.layer({ maxAttempts: Infinity })
129
+ : Layer.succeed(SessionRestart.Service, { resumeSuspendedSessions: Effect.void });
130
+ /**
131
+ * Boot OpenCode with its database in `db`. Booting resumes the turns a
132
+ * previous attempt left unfinished. Close the host when done.
133
+ */
134
+ export async function openOpenCode(db, fence, { plugins = [], config = {}, local = false, resume = true }) {
135
+ // The workerd profile, but for its database, which comes first. (The
136
+ // Promise API's OpenCode.create takes no replacements; the Effect API's does.)
137
+ const profile = { storage: undefined, models: { fetch: false } };
138
+ // In 2.0.27's order: database, process spawner, snapshot, version control,
139
+ // filesystem, filesystem search, pty, plugin discovery. Local keeps the
140
+ // stubs of snapshots, the pty and plugin discovery only.
141
+ const [, spawner, snapshot, vcs, fs, search, pty, discovery] = ServerWorkerd.replacements(profile);
142
+ const rest = local ? [snapshot, pty, discovery] : [spawner, snapshot, vcs, fs, search, pty, discovery];
143
+ const scope = Scope.makeUnsafe();
144
+ const client = await Effect.runPromise(OpenCode.create({
145
+ ...ServerWorkerd.serverOptions({ ...profile, config: { content: JSON.stringify(config) } }),
146
+ plugins: plugins.map(fromPromise),
147
+ }, {
148
+ overrides: [
149
+ OpenCodeDatabase.node.replace(OpenCodeDatabase.configuredClient(sqlClient(db, fence))),
150
+ ...rest,
151
+ SessionRestart.node.replace(SessionRestart.node.mapLayer(() => restarts(resume))),
152
+ ],
153
+ }).pipe(Scope.provide(scope)));
154
+ return {
155
+ client,
156
+ // The client's calls need nothing more: OpenCode provided it all.
157
+ call: (effect) => Effect.runPromise(effect),
158
+ close: () => Effect.runPromise(Scope.close(scope, Exit.void)),
159
+ };
160
+ }
161
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/opencode/db.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,sEAAsE;AACtE,yBAAyB;AACzB,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,mEAAmE;AACnE,wEAAwE;AACxE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