@restatedev/agents 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -17
- package/dist/calls.d.ts +20 -1
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +46 -7
- package/dist/calls.js.map +1 -1
- package/dist/claude/index.d.ts +11 -11
- package/dist/claude/index.d.ts.map +1 -1
- package/dist/claude/index.js +9 -6
- package/dist/claude/index.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/common.d.ts +62 -23
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +67 -38
- package/dist/common.js.map +1 -1
- package/dist/{signals.d.ts → companion.d.ts} +106 -43
- package/dist/companion.d.ts.map +1 -0
- package/dist/companion.js +463 -0
- package/dist/companion.js.map +1 -0
- package/dist/conversation.d.ts +103 -5
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +295 -75
- package/dist/conversation.js.map +1 -1
- package/dist/deepseek/index.d.ts +11 -11
- package/dist/deepseek/index.d.ts.map +1 -1
- package/dist/deepseek/index.js +23 -26
- package/dist/deepseek/index.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/langgraph/checkpointer.d.ts +2 -0
- package/dist/langgraph/checkpointer.d.ts.map +1 -1
- package/dist/langgraph/checkpointer.js +1 -1
- package/dist/langgraph/checkpointer.js.map +1 -1
- package/dist/langgraph/graph.d.ts.map +1 -1
- package/dist/langgraph/graph.js +32 -13
- package/dist/langgraph/graph.js.map +1 -1
- package/dist/langgraph/index.d.ts +11 -11
- package/dist/langgraph/index.d.ts.map +1 -1
- package/dist/langgraph/index.js +19 -13
- package/dist/langgraph/index.js.map +1 -1
- package/dist/langgraph/nodes.d.ts +2 -1
- package/dist/langgraph/nodes.d.ts.map +1 -1
- package/dist/langgraph/nodes.js +23 -20
- package/dist/langgraph/nodes.js.map +1 -1
- package/dist/object.d.ts +24 -22
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +14 -11
- package/dist/object.js.map +1 -1
- package/dist/opencode/index.d.ts +11 -11
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +25 -27
- package/dist/opencode/index.js.map +1 -1
- package/dist/pi/index.d.ts +11 -11
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +16 -17
- package/dist/pi/index.js.map +1 -1
- package/dist/steering.d.ts +2 -1
- package/dist/steering.d.ts.map +1 -1
- package/dist/steering.js +2 -2
- package/dist/steering.js.map +1 -1
- package/dist/tools.d.ts +21 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +54 -14
- package/dist/tools.js.map +1 -1
- package/dist/webhook.js +1 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +3 -3
- package/src/calls.ts +52 -11
- package/src/claude/README.md +4 -2
- package/src/claude/index.ts +9 -7
- package/src/client.ts +1 -1
- package/src/common.ts +99 -40
- package/src/companion.ts +674 -0
- package/src/conversation.ts +353 -101
- package/src/deepseek/README.md +7 -1
- package/src/deepseek/index.ts +22 -24
- package/src/index.ts +10 -4
- package/src/langgraph/README.md +8 -5
- package/src/langgraph/checkpointer.ts +1 -1
- package/src/langgraph/graph.ts +30 -16
- package/src/langgraph/index.ts +24 -17
- package/src/langgraph/nodes.ts +24 -20
- package/src/object.ts +43 -40
- package/src/opencode/README.md +5 -2
- package/src/opencode/index.ts +26 -27
- package/src/pi/README.md +6 -1
- package/src/pi/index.ts +16 -15
- package/src/steering.ts +8 -7
- package/src/tools.ts +60 -18
- package/src/webhook.ts +1 -1
- package/dist/signals.d.ts.map +0 -1
- package/dist/signals.js +0 -383
- package/dist/signals.js.map +0 -1
- package/src/signals.ts +0 -590
package/dist/object.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as restate from '@restatedev/sessions';
|
|
2
|
-
import { type Answering, type Messages, type MessagesRequest, type Summarize, type Window } from './common.ts';
|
|
2
|
+
import { type AgentContext, type AgentViewContext, type Answering, type Messages, type MessagesRequest, type Summarize, type Window } from './common.ts';
|
|
3
3
|
import { type Items } from './conversation.ts';
|
|
4
|
-
import { type Notifications, type Resolved, type Signal, type Steered, type Steering, type Waiting, type Watch } from './
|
|
4
|
+
import { type Notifications, type Resolved, type Signal, type Steered, type Steering, type Waiting, type Watch } from './companion.ts';
|
|
5
5
|
/** What an object is doing: the message it answers, if any, and what its tools wait for. */
|
|
6
6
|
export interface Status {
|
|
7
7
|
/** The message being answered (by a `chat` handler), or null. */
|
|
@@ -22,17 +22,19 @@ export interface Stopped {
|
|
|
22
22
|
* it answers, and `notifications` and `watch`, the revision of its
|
|
23
23
|
* conversation, and a wait for a newer one (an agent's
|
|
24
24
|
* has `clear` and `sync` too: {@link FOLLOWED}). Each asks the object's
|
|
25
|
-
*
|
|
26
|
-
* object's handler works.
|
|
25
|
+
* companion (its own `<name>.prebuilt.restate`, at the same key), which
|
|
26
|
+
* knows what the object does: they run while the object's handler works.
|
|
27
|
+
* They are the only way a client reaches the companion, whose handlers
|
|
28
|
+
* Restate's ingress refuses.
|
|
27
29
|
*/
|
|
28
30
|
declare const BUILT_IN: {
|
|
29
|
-
signal: (ctx:
|
|
30
|
-
pending: (ctx:
|
|
31
|
-
status: (ctx:
|
|
31
|
+
signal: (ctx: AgentViewContext, signal: Signal) => Promise<Resolved>;
|
|
32
|
+
pending: (ctx: AgentViewContext) => Promise<Waiting[]>;
|
|
33
|
+
status: (ctx: AgentViewContext) => Promise<Status>;
|
|
32
34
|
/** Cancel the invocation of the message being answered (`status`'s), as Restate's admin API cancels one. */
|
|
33
|
-
stop: (ctx:
|
|
35
|
+
stop: (ctx: AgentViewContext) => Promise<Stopped>;
|
|
34
36
|
/** The revision of the conversation: each change of what `messages` and `status` give increases it. */
|
|
35
|
-
notifications: (ctx:
|
|
37
|
+
notifications: (ctx: AgentViewContext) => Promise<Notifications>;
|
|
36
38
|
/**
|
|
37
39
|
* The revision, once there is one newer than `revision`, or at the timeout (50 s by
|
|
38
40
|
* default, at most 60 s), whichever comes first: a client then reads what
|
|
@@ -43,14 +45,14 @@ declare const BUILT_IN: {
|
|
|
43
45
|
inactivityTimeout: {
|
|
44
46
|
minutes: number;
|
|
45
47
|
};
|
|
46
|
-
handler: (ctx:
|
|
48
|
+
handler: (ctx: AgentViewContext, watch: Watch) => Promise<Notifications>;
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
/** The views of every agent: {@link followed}'s. */
|
|
50
52
|
declare const FOLLOWED: {
|
|
51
53
|
/**
|
|
52
54
|
* Forget the conversation: stop the message being answered (as `stop`),
|
|
53
|
-
* then empty the key's database, and what its
|
|
55
|
+
* then empty the key's database, and what its companion holds (waits and
|
|
54
56
|
* kept signals). The conversation's ids and cursors go on (see
|
|
55
57
|
* conversation.ts), so a follower reads on, and drops the messages before `first`.
|
|
56
58
|
* A message sent before it is answered first, then forgotten too; one sent
|
|
@@ -60,7 +62,7 @@ declare const FOLLOWED: {
|
|
|
60
62
|
inactivityTimeout: {
|
|
61
63
|
minutes: number;
|
|
62
64
|
};
|
|
63
|
-
handler: (ctx:
|
|
65
|
+
handler: (ctx: AgentViewContext) => Promise<Stopped>;
|
|
64
66
|
};
|
|
65
67
|
/**
|
|
66
68
|
* Send a message to the agent while it answers another: the turn being
|
|
@@ -75,26 +77,26 @@ declare const FOLLOWED: {
|
|
|
75
77
|
steer: {
|
|
76
78
|
input: restate.Serde<string>;
|
|
77
79
|
accept: string;
|
|
78
|
-
handler: (ctx:
|
|
80
|
+
handler: (ctx: AgentViewContext, text: string) => Promise<Steered>;
|
|
79
81
|
};
|
|
80
82
|
sync: {
|
|
81
83
|
inactivityTimeout: {
|
|
82
84
|
minutes: number;
|
|
83
85
|
};
|
|
84
|
-
handler: (ctx:
|
|
86
|
+
handler: (ctx: AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: SyncRequest) => Promise<Synced>;
|
|
85
87
|
};
|
|
86
88
|
};
|
|
87
89
|
/**
|
|
88
90
|
* The agents' handlers that only their own views call (Restate's ingress
|
|
89
91
|
* refuses them), and their types leave out: `erase`, `clear`'s work, once
|
|
90
|
-
* the handlers before it are done. It empties the key's database and its
|
|
91
|
-
*
|
|
92
|
+
* the handlers before it are done. It empties the key's database and what its
|
|
93
|
+
* companion holds, and the conversation's ids and cursors go on where they got to
|
|
92
94
|
* (conversation.ts).
|
|
93
95
|
*/
|
|
94
96
|
declare const internal: (items: Items<unknown> | undefined) => {
|
|
95
97
|
erase: {
|
|
96
98
|
ingressPrivate: boolean;
|
|
97
|
-
handler: (ctx:
|
|
99
|
+
handler: (ctx: AgentContext) => Promise<void>;
|
|
98
100
|
};
|
|
99
101
|
/**
|
|
100
102
|
* Close the latest turn, unanswered, if invocation `invocationId` ran it
|
|
@@ -105,12 +107,12 @@ declare const internal: (items: Items<unknown> | undefined) => {
|
|
|
105
107
|
*/
|
|
106
108
|
settle: {
|
|
107
109
|
ingressPrivate: boolean;
|
|
108
|
-
handler: (ctx:
|
|
110
|
+
handler: (ctx: AgentContext, invocationId: string) => Promise<boolean>;
|
|
109
111
|
};
|
|
110
112
|
/** Summarize the earliest turns, past the agent's budget. Whether it did. */
|
|
111
113
|
compact: {
|
|
112
114
|
ingressPrivate: boolean;
|
|
113
|
-
handler: (ctx:
|
|
115
|
+
handler: (ctx: AgentContext) => Promise<boolean>;
|
|
114
116
|
};
|
|
115
117
|
};
|
|
116
118
|
/**
|
|
@@ -138,8 +140,8 @@ export interface Definition<P extends string> {
|
|
|
138
140
|
description?: string;
|
|
139
141
|
schema?: readonly restate.Step[];
|
|
140
142
|
/**
|
|
141
|
-
* Whether it works unwatched, such as a subagent: its turn
|
|
142
|
-
*
|
|
143
|
+
* Whether it works unwatched, such as a subagent: its turn publishes to its
|
|
144
|
+
* companion only at its end, not at each step, so a client that follows it
|
|
143
145
|
* sees each turn once it ended. `messages` has every turn as before.
|
|
144
146
|
*/
|
|
145
147
|
background?: boolean;
|
|
@@ -201,7 +203,7 @@ type With<H, V> = Functions<typeof BUILT_IN> & (V extends {
|
|
|
201
203
|
* `options` and `metadata` add to (or replace) the ones set here, such as
|
|
202
204
|
* `options: { retryPolicy: ... }`.
|
|
203
205
|
*/
|
|
204
|
-
export declare const sessionObject: <P extends string, H extends Record<string, restate.Entry<
|
|
206
|
+
export declare const sessionObject: <P extends string, H extends Record<string, restate.Entry<AgentContext>>, V extends Record<string, restate.Entry<AgentViewContext>>>(definition: Definition<P> & {
|
|
205
207
|
handlers?: H & Reserved;
|
|
206
208
|
views?: V & Reserved;
|
|
207
209
|
metadata?: Record<string, string>;
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EACL,KAAK,SAAS,EAUd,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,KAAK,SAAS,EAEd,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAW,KAAK,KAAK,EAAmD,MAAM,mBAAmB,CAAC;AACzG,OAAO,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAUd,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,KAAK,SAAS,EAEd,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAW,KAAK,KAAK,EAAmD,MAAM,mBAAmB,CAAC;AACzG,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,MAAM,EAEX,KAAK,OAAO,EACZ,KAAK,QAAQ,EAEb,K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, chatTurn, checkWindow, isAgent, ITEMS, messageSerde, publish, refusalOf, WINDOW, } from './common.js';
|
|
5
5
|
import { compact, nextStart, restart, SCHEMA, settle, steerStored } from './conversation.js';
|
|
6
|
-
import {
|
|
6
|
+
import { companionAt, withCompanion, } from './companion.js';
|
|
7
7
|
/**
|
|
8
8
|
* The options of every object here, beside a session object's: retries for
|
|
9
9
|
* weeks, since each attempt resumes from the database: soon after a crash,
|
|
@@ -14,11 +14,12 @@ const OPTIONS = {
|
|
|
14
14
|
retryPolicy: { initialInterval: 50, exponentiationFactor: 2, maxInterval: 10_000, maxAttempts: 100_000 },
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* A call of the companion
|
|
18
|
-
* request and `step`: a restarted view joins
|
|
19
|
-
* key: asked again, it answers again, and
|
|
17
|
+
* A call of the companion of the object of `ctx` (its own, at its key); with
|
|
18
|
+
* `step`, a change, keyed by the request and `step`: a restarted view joins
|
|
19
|
+
* the same call. A read has no key: asked again, it answers again, and
|
|
20
|
+
* Restate keeps nothing of it.
|
|
20
21
|
*/
|
|
21
|
-
const companion = (ctx, step) => ctx.rpc(
|
|
22
|
+
const companion = (ctx, step) => ctx.rpc(companionAt(ctx), ctx.key, step === undefined ? {} : { idempotencyKey: `${ctx.request.id}:${step}` });
|
|
22
23
|
/**
|
|
23
24
|
* Cancel the invocation of the message being answered, if any, and say
|
|
24
25
|
* which. The companion's `status` says which, with a key of the request and
|
|
@@ -46,8 +47,10 @@ const WAITS = { inactivityTimeout: { minutes: 5 } };
|
|
|
46
47
|
* it answers, and `notifications` and `watch`, the revision of its
|
|
47
48
|
* conversation, and a wait for a newer one (an agent's
|
|
48
49
|
* has `clear` and `sync` too: {@link FOLLOWED}). Each asks the object's
|
|
49
|
-
*
|
|
50
|
-
* object's handler works.
|
|
50
|
+
* companion (its own `<name>.prebuilt.restate`, at the same key), which
|
|
51
|
+
* knows what the object does: they run while the object's handler works.
|
|
52
|
+
* They are the only way a client reaches the companion, whose handlers
|
|
53
|
+
* Restate's ingress refuses.
|
|
51
54
|
*/
|
|
52
55
|
const BUILT_IN = {
|
|
53
56
|
signal: async (ctx, signal) => companion(ctx, 'signal').resolve(signal),
|
|
@@ -82,7 +85,7 @@ const BUILT_IN = {
|
|
|
82
85
|
const followed = (steerable) => ({
|
|
83
86
|
/**
|
|
84
87
|
* Forget the conversation: stop the message being answered (as `stop`),
|
|
85
|
-
* then empty the key's database, and what its
|
|
88
|
+
* then empty the key's database, and what its companion holds (waits and
|
|
86
89
|
* kept signals). The conversation's ids and cursors go on (see
|
|
87
90
|
* conversation.ts), so a follower reads on, and drops the messages before `first`.
|
|
88
91
|
* A message sent before it is answered first, then forgotten too; one sent
|
|
@@ -151,8 +154,8 @@ const FOLLOWED = followed(false);
|
|
|
151
154
|
/**
|
|
152
155
|
* The agents' handlers that only their own views call (Restate's ingress
|
|
153
156
|
* refuses them), and their types leave out: `erase`, `clear`'s work, once
|
|
154
|
-
* the handlers before it are done. It empties the key's database and its
|
|
155
|
-
*
|
|
157
|
+
* the handlers before it are done. It empties the key's database and what its
|
|
158
|
+
* companion holds, and the conversation's ids and cursors go on where they got to
|
|
156
159
|
* (conversation.ts).
|
|
157
160
|
*/
|
|
158
161
|
const internal = (items) => ({
|
|
@@ -168,7 +171,7 @@ const internal = (items) => ({
|
|
|
168
171
|
await reset(tx);
|
|
169
172
|
await restart(tx, start);
|
|
170
173
|
});
|
|
171
|
-
await ctx.rpc(
|
|
174
|
+
await ctx.rpc(companionAt(ctx), ctx.key, { idempotencyKey: `${ctx.request.id}:reset` }).reset();
|
|
172
175
|
},
|
|
173
176
|
},
|
|
174
177
|
/**
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,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/opencode/index.d.ts
CHANGED
|
@@ -154,7 +154,7 @@ export declare const chat: <O extends z.ZodObject | undefined = undefined>(optio
|
|
|
154
154
|
input: restate.Serde<string>;
|
|
155
155
|
accept: string;
|
|
156
156
|
explicitCancellation: boolean;
|
|
157
|
-
handler: (ctx:
|
|
157
|
+
handler: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
158
158
|
};
|
|
159
159
|
/**
|
|
160
160
|
* A view of the conversation as clients read it: a page at a time, or what
|
|
@@ -165,18 +165,18 @@ export declare const chat: <O extends z.ZodObject | undefined = undefined>(optio
|
|
|
165
165
|
export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
166
166
|
/** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
|
|
167
167
|
export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, window, budget, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
|
|
168
|
-
signal: (ctx:
|
|
169
|
-
pending: (ctx:
|
|
170
|
-
status: (ctx:
|
|
171
|
-
stop: (ctx:
|
|
172
|
-
notifications: (ctx:
|
|
173
|
-
watch: (ctx:
|
|
168
|
+
signal: (ctx: import("../common.ts").AgentViewContext, signal: import("../companion.ts").Signal) => Promise<import("../companion.ts").Resolved>;
|
|
169
|
+
pending: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Waiting[]>;
|
|
170
|
+
status: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Status>;
|
|
171
|
+
stop: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
172
|
+
notifications: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Notifications>;
|
|
173
|
+
watch: (ctx: import("../common.ts").AgentViewContext, watch: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
|
|
174
174
|
} & {
|
|
175
|
-
clear: (ctx:
|
|
176
|
-
steer: (ctx:
|
|
177
|
-
sync: (ctx:
|
|
175
|
+
clear: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
176
|
+
steer: (ctx: import("../common.ts").AgentViewContext, text: string) => Promise<import("../companion.ts").Steered>;
|
|
177
|
+
sync: (ctx: import("../common.ts").AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
|
|
178
178
|
} & {
|
|
179
|
-
chat: (ctx:
|
|
179
|
+
chat: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
180
180
|
} & {
|
|
181
181
|
messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
182
182
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/opencode/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/opencode/index.ts"],"names":[],"mappings":"AA0EA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAGhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAIL,KAAK,KAAK,EAEV,KAAK,SAAS,EAWf,MAAM,cAAc,CAAC;AACtB,OAAO,EAA4B,KAAK,IAAI,EAAE,KAAK,KAAK,EAAiC,MAAM,oBAAoB,CAAC;AAGpH,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AACxD,OAAO,EAAU,KAAK,IAAI,IAAI,OAAO,EA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AO,MAAM,YAAY,GAAU,CAAC,OAC7B,OAAO,CAAC,cAAc,+EACoE,OAAO,QAChG,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,KAC9C,OAAO,CAAC,CAAC,CAgSX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,OAC7D,OAAO,CAAC,cAAc,QACrB,MAAM,YACH,OAAO,CAAC,CAAC,CAAC,KAClB,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAGK,CAAC;AAE1B;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,YAAW,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;;;;;CAGjG,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,gIAAgC,CAAC;AAEtD,6HAA6H;AAC7H,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,yEAQlF,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;EAUzB,CAAC"}
|
package/dist/opencode/index.js
CHANGED
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
// what clients read, and how turns end. What OpenCode stores of a turn (the
|
|
20
20
|
// model's replies, the tools' results) is copied into the turn after each of
|
|
21
21
|
// OpenCode's commits, in a `ctx.db` transaction of its own, idempotently (by
|
|
22
|
-
// OpenCode's message and part ids), and caught up before
|
|
23
|
-
// answer, and any close of the turn.
|
|
22
|
+
// OpenCode's message and part ids), and caught up before a tool call runs, the
|
|
23
|
+
// answer, and any close of the turn. A copy of steps (a reply with tool calls,
|
|
24
|
+
// tools' results) is published once it commits, and nothing else is: followers
|
|
25
|
+
// read the conversation then. OpenCode boots lazily, as a turn runs:
|
|
24
26
|
// an answered prompt's retry boots nothing.
|
|
25
27
|
//
|
|
26
28
|
// OpenCode records an execution claim as a turn starts, and every boot sweeps
|
|
@@ -55,8 +57,8 @@
|
|
|
55
57
|
// step, after the round's results. Once, by its steer id (`msg_steer_<id>`,
|
|
56
58
|
// which OpenCode takes once, also from a retried attempt). In such a turn,
|
|
57
59
|
// the tool's `execute.after` hook, which OpenCode awaits before it stores the
|
|
58
|
-
// result, copies the result as the tool returned it and publishes the
|
|
59
|
-
//
|
|
60
|
+
// result, copies the result as the tool returned it and publishes the copy,
|
|
61
|
+
// whose answer lists the messages, then submits them: so OpenCode places
|
|
60
62
|
// them at the step that follows, never past the turn's end. The copy stores
|
|
61
63
|
// each as a steered message of the turn, in its place, and tells the
|
|
62
64
|
// companion it is taken.
|
|
@@ -74,7 +76,7 @@ import * as restate from '@restatedev/sessions';
|
|
|
74
76
|
import { database, reset } from '@restatedev/sessions/internal';
|
|
75
77
|
import { mkdir } from 'node:fs/promises';
|
|
76
78
|
import { toSessionError } from '@opencode/core/session/to-session-error';
|
|
77
|
-
import { AttemptEnded, chatHandler, CHECK_MODEL, checkModelName, configured, fromTool, inboxOf, modelOf, providerOf, refusal, REFUSED, RETURNED_UNRECORDED, stopSignalOf,
|
|
79
|
+
import { AttemptEnded, chatHandler, CHECK_MODEL, checkModelName, configured, fromTool, inboxOf, modelOf, providerOf, refusal, REFUSED, RETURNED_UNRECORDED, stopSignalOf, toolCallStarted, } from '../common.js';
|
|
78
80
|
import { answerOnce, invocationOf, STEPS } from '../conversation.js';
|
|
79
81
|
import { conversationView } from '../messages.js';
|
|
80
82
|
import { tookSteers } from '../steering.js';
|
|
@@ -248,22 +250,21 @@ const sessionExists = (host) => host.call(host.client.session.get({ sessionID: S
|
|
|
248
250
|
* companion told it is taken in the transaction). Each once: by OpenCode's
|
|
249
251
|
* ids, a steered message by its steer id too. Not the prompt, nor what asks
|
|
250
252
|
* again (the turn has them), nor OpenCode's synthetic messages, idle markers
|
|
251
|
-
* and compactions. In a `ctx.db` transaction of its own.
|
|
252
|
-
* calls
|
|
253
|
+
* and compactions. In a `ctx.db` transaction of its own. Whether it copied a
|
|
254
|
+
* step that a follower waits for: a reply with tool calls, or a tool's result.
|
|
253
255
|
*
|
|
254
256
|
* With `own`, a call's result as its tool returned it, before OpenCode
|
|
255
257
|
* stores it: copied too (after its reply), under the id OpenCode's part has.
|
|
256
258
|
*/
|
|
257
259
|
async function copyInto(ctx, host, turn, own, steersOnly = false) {
|
|
258
260
|
if (!turn.writable)
|
|
259
|
-
return
|
|
261
|
+
return false;
|
|
260
262
|
const after = await messagesAfter(host, messageIdOf(turn.id));
|
|
261
263
|
if (!after)
|
|
262
|
-
return
|
|
264
|
+
return false;
|
|
263
265
|
const have = new Set(turn.items.flatMap((e) => (e.item.from ? [e.item.from] : [])));
|
|
264
266
|
const held = new Set(turn.steered().map((e) => e.steer));
|
|
265
267
|
const copied = [];
|
|
266
|
-
const resulted = [];
|
|
267
268
|
for (const m of after) {
|
|
268
269
|
const steer = steerOf(m);
|
|
269
270
|
if (steer !== undefined) {
|
|
@@ -319,23 +320,22 @@ async function copyInto(ctx, host, turn, own, steersOnly = false) {
|
|
|
319
320
|
...(status === 'error' ? { error: true } : {}),
|
|
320
321
|
};
|
|
321
322
|
copied.push({ item: { type: 'results', results: [result], from } });
|
|
322
|
-
resulted.push(t.id);
|
|
323
323
|
have.add(from);
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
if (own && !have.has(own.from) && have.has(own.from.split('/')[0])) {
|
|
327
327
|
copied.push({ item: { type: 'results', results: [own.result], from: own.from } });
|
|
328
|
-
resulted.push(own.result.id);
|
|
329
328
|
}
|
|
330
329
|
if (copied.length === 0)
|
|
331
|
-
return
|
|
330
|
+
return false;
|
|
332
331
|
const done = await ctx.db.transaction(async (tx) => {
|
|
333
332
|
if (!(await turn.copyIn(tx, copied)))
|
|
334
333
|
return false;
|
|
335
334
|
tookSteers(ctx, tx, copied.flatMap(({ steer }) => (steer === undefined ? [] : [steer])));
|
|
336
335
|
return true;
|
|
337
336
|
});
|
|
338
|
-
return done
|
|
337
|
+
return (done &&
|
|
338
|
+
copied.some(({ item }) => item.type === 'results' || (item.type === 'assistant' && (item.calls?.length ?? 0) > 0)));
|
|
339
339
|
}
|
|
340
340
|
/** Where prompt `messageId` is (see {@link Outcome}). */
|
|
341
341
|
async function outcome(host, messageId) {
|
|
@@ -695,21 +695,19 @@ export const withOpenCode = async (ctx, { plugins = [], model: named, system, to
|
|
|
695
695
|
let turn;
|
|
696
696
|
// Once the turn is stopped, nothing more is copied: its close says how it ended.
|
|
697
697
|
let stopping = false;
|
|
698
|
-
// The calls that returned, whose ends are published once their results are copied.
|
|
699
|
-
const returned = new Set();
|
|
700
698
|
// The copies, one after another.
|
|
701
699
|
let copying = Promise.resolve();
|
|
702
700
|
/**
|
|
703
701
|
* Copy what OpenCode has of the turn, and `own`, a call's result as its tool returned it (see {@link copyInto}):
|
|
704
|
-
* once the turn is stopped, only with `steersOnly`, its messages steered to the turn.
|
|
702
|
+
* once the turn is stopped, only with `steersOnly`, its messages steered to the turn. A copy of steps (a reply
|
|
703
|
+
* with tool calls, tools' results) is published once it is committed, for followers to read them there.
|
|
705
704
|
*/
|
|
706
705
|
const copy = (own, steersOnly = false) => {
|
|
707
706
|
const next = copying.then(async () => {
|
|
708
707
|
if (!turn || (stopping && !steersOnly) || fence.closed)
|
|
709
708
|
return undefined;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
await toolCallEnded(ctx);
|
|
709
|
+
if (await copyInto(ctx, await host(), turn, own, steersOnly))
|
|
710
|
+
await turn.stepsCommitted();
|
|
713
711
|
return undefined;
|
|
714
712
|
});
|
|
715
713
|
copying = next.catch(() => { });
|
|
@@ -751,12 +749,13 @@ export const withOpenCode = async (ctx, { plugins = [], model: named, system, to
|
|
|
751
749
|
}
|
|
752
750
|
};
|
|
753
751
|
/**
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* result is copied as the tool returns it
|
|
757
|
-
* hook, and goes on to the round's next step
|
|
758
|
-
* the
|
|
759
|
-
* submitted before OpenCode stores the
|
|
752
|
+
* Copy the reply that makes a tool call before the call runs (its copy is
|
|
753
|
+
* published), then forget the calls whose results are stored. In a turn
|
|
754
|
+
* that takes steered messages, the result is copied as the tool returns it
|
|
755
|
+
* (OpenCode stores it after this hook, and goes on to the round's next step
|
|
756
|
+
* without waiting for a copy): the copy's publish lists the messages
|
|
757
|
+
* steered to the turn, which are submitted before OpenCode stores the
|
|
758
|
+
* result ({@link steer}).
|
|
760
759
|
*/
|
|
761
760
|
const followPlugin = {
|
|
762
761
|
id: 'restate-agents.follow',
|
|
@@ -767,7 +766,6 @@ export const withOpenCode = async (ctx, { plugins = [], model: named, system, to
|
|
|
767
766
|
.catch(fail);
|
|
768
767
|
});
|
|
769
768
|
const after = await plugin.tool.hook('execute.after', async (event) => {
|
|
770
|
-
returned.add(event.id);
|
|
771
769
|
if (!inboxOf(ctx))
|
|
772
770
|
return;
|
|
773
771
|
const output = event.status === 'error'
|