@restatedev/agents 0.11.1 → 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.
- package/README.md +189 -808
- package/dist/pi/factory.d.ts +73 -0
- package/dist/pi/factory.d.ts.map +1 -0
- package/dist/pi/factory.js +145 -0
- package/dist/pi/factory.js.map +1 -0
- package/dist/pi/index.d.ts +5 -129
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +31 -571
- package/dist/pi/index.js.map +1 -1
- package/dist/pi/keepalive.d.ts +3 -16
- package/dist/pi/keepalive.d.ts.map +1 -1
- package/dist/pi/keepalive.js +38 -41
- package/dist/pi/keepalive.js.map +1 -1
- package/dist/pi/left.d.ts +16 -0
- package/dist/pi/left.d.ts.map +1 -0
- package/dist/pi/left.js +23 -0
- package/dist/pi/left.js.map +1 -0
- package/dist/pi/storage.d.ts +19 -76
- package/dist/pi/storage.d.ts.map +1 -1
- package/dist/pi/storage.js +50 -368
- package/dist/pi/storage.js.map +1 -1
- package/dist/pi/tools.d.ts +12 -0
- package/dist/pi/tools.d.ts.map +1 -0
- package/dist/pi/tools.js +70 -0
- package/dist/pi/tools.js.map +1 -0
- package/package.json +11 -254
- package/src/pi/factory.ts +231 -0
- package/src/pi/index.ts +31 -759
- package/src/pi/keepalive.ts +46 -56
- package/src/pi/left.ts +52 -0
- package/src/pi/storage.ts +75 -409
- package/src/pi/tools.ts +78 -0
- package/dist/agentlib/agent.d.ts +0 -32
- package/dist/agentlib/agent.d.ts.map +0 -1
- package/dist/agentlib/agent.js +0 -174
- package/dist/agentlib/agent.js.map +0 -1
- package/dist/agentlib/index.d.ts +0 -5
- package/dist/agentlib/index.d.ts.map +0 -1
- package/dist/agentlib/index.js +0 -15
- package/dist/agentlib/index.js.map +0 -1
- package/dist/agentlib/messages.d.ts +0 -39
- package/dist/agentlib/messages.d.ts.map +0 -1
- package/dist/agentlib/messages.js +0 -177
- package/dist/agentlib/messages.js.map +0 -1
- package/dist/agentlib/model.d.ts +0 -31
- package/dist/agentlib/model.d.ts.map +0 -1
- package/dist/agentlib/model.js +0 -140
- package/dist/agentlib/model.js.map +0 -1
- package/dist/agentlib/options.d.ts +0 -58
- package/dist/agentlib/options.d.ts.map +0 -1
- package/dist/agentlib/options.js +0 -2
- package/dist/agentlib/options.js.map +0 -1
- package/dist/agentlib/runtime.d.ts +0 -37
- package/dist/agentlib/runtime.d.ts.map +0 -1
- package/dist/agentlib/runtime.js +0 -216
- package/dist/agentlib/runtime.js.map +0 -1
- package/dist/agentlib/state.d.ts +0 -114
- package/dist/agentlib/state.d.ts.map +0 -1
- package/dist/agentlib/state.js +0 -52
- package/dist/agentlib/state.js.map +0 -1
- package/dist/agentlib/steering.d.ts +0 -23
- package/dist/agentlib/steering.d.ts.map +0 -1
- package/dist/agentlib/steering.js +0 -48
- package/dist/agentlib/steering.js.map +0 -1
- package/dist/agentlib/tools.d.ts +0 -33
- package/dist/agentlib/tools.d.ts.map +0 -1
- package/dist/agentlib/tools.js +0 -245
- package/dist/agentlib/tools.js.map +0 -1
- package/dist/agentlib/turn.d.ts +0 -82
- package/dist/agentlib/turn.d.ts.map +0 -1
- package/dist/agentlib/turn.js +0 -253
- package/dist/agentlib/turn.js.map +0 -1
- package/dist/calls.d.ts +0 -90
- package/dist/calls.d.ts.map +0 -1
- package/dist/calls.js +0 -235
- package/dist/calls.js.map +0 -1
- package/dist/claude/index.d.ts +0 -106
- package/dist/claude/index.d.ts.map +0 -1
- package/dist/claude/index.js +0 -386
- package/dist/claude/index.js.map +0 -1
- package/dist/client.d.ts +0 -90
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -88
- package/dist/client.js.map +0 -1
- package/dist/common.d.ts +0 -410
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -563
- package/dist/common.js.map +0 -1
- package/dist/companion.d.ts +0 -286
- package/dist/companion.d.ts.map +0 -1
- package/dist/companion.js +0 -463
- package/dist/companion.js.map +0 -1
- package/dist/conversation.d.ts +0 -576
- package/dist/conversation.d.ts.map +0 -1
- package/dist/conversation.js +0 -1476
- package/dist/conversation.js.map +0 -1
- package/dist/deepseek/barriers.d.ts +0 -11
- package/dist/deepseek/barriers.d.ts.map +0 -1
- package/dist/deepseek/barriers.js +0 -36
- package/dist/deepseek/barriers.js.map +0 -1
- package/dist/deepseek/index.d.ts +0 -97
- package/dist/deepseek/index.d.ts.map +0 -1
- package/dist/deepseek/index.js +0 -603
- package/dist/deepseek/index.js.map +0 -1
- package/dist/deepseek/persistence.d.ts +0 -83
- package/dist/deepseek/persistence.d.ts.map +0 -1
- package/dist/deepseek/persistence.js +0 -262
- package/dist/deepseek/persistence.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/langgraph/checkpointer.d.ts +0 -52
- package/dist/langgraph/checkpointer.d.ts.map +0 -1
- package/dist/langgraph/checkpointer.js +0 -477
- package/dist/langgraph/checkpointer.js.map +0 -1
- package/dist/langgraph/context.d.ts +0 -10
- package/dist/langgraph/context.d.ts.map +0 -1
- package/dist/langgraph/context.js +0 -21
- package/dist/langgraph/context.js.map +0 -1
- package/dist/langgraph/errors.d.ts +0 -16
- package/dist/langgraph/errors.d.ts.map +0 -1
- package/dist/langgraph/errors.js +0 -30
- package/dist/langgraph/errors.js.map +0 -1
- package/dist/langgraph/graph.d.ts +0 -25
- package/dist/langgraph/graph.d.ts.map +0 -1
- package/dist/langgraph/graph.js +0 -378
- package/dist/langgraph/graph.js.map +0 -1
- package/dist/langgraph/index.d.ts +0 -119
- package/dist/langgraph/index.d.ts.map +0 -1
- package/dist/langgraph/index.js +0 -325
- package/dist/langgraph/index.js.map +0 -1
- package/dist/langgraph/keepalive.d.ts +0 -16
- package/dist/langgraph/keepalive.d.ts.map +0 -1
- package/dist/langgraph/keepalive.js +0 -51
- package/dist/langgraph/keepalive.js.map +0 -1
- package/dist/langgraph/nodes.d.ts +0 -71
- package/dist/langgraph/nodes.d.ts.map +0 -1
- package/dist/langgraph/nodes.js +0 -148
- package/dist/langgraph/nodes.js.map +0 -1
- package/dist/messages.d.ts +0 -18
- package/dist/messages.d.ts.map +0 -1
- package/dist/messages.js +0 -182
- package/dist/messages.js.map +0 -1
- package/dist/object.d.ts +0 -213
- package/dist/object.d.ts.map +0 -1
- package/dist/object.js +0 -309
- package/dist/object.js.map +0 -1
- package/dist/opencode/db.d.ts +0 -81
- package/dist/opencode/db.d.ts.map +0 -1
- package/dist/opencode/db.js +0 -249
- package/dist/opencode/db.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -184
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -1079
- package/dist/opencode/index.js.map +0 -1
- package/dist/output.d.ts +0 -25
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -99
- package/dist/output.js.map +0 -1
- package/dist/pi/commits.d.ts +0 -6
- package/dist/pi/commits.d.ts.map +0 -1
- package/dist/pi/commits.js +0 -3
- package/dist/pi/commits.js.map +0 -1
- package/dist/steering.d.ts +0 -32
- package/dist/steering.d.ts.map +0 -1
- package/dist/steering.js +0 -45
- package/dist/steering.js.map +0 -1
- package/dist/tools.d.ts +0 -267
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -305
- package/dist/tools.js.map +0 -1
- package/dist/webhook.d.ts +0 -71
- package/dist/webhook.d.ts.map +0 -1
- package/dist/webhook.js +0 -102
- package/dist/webhook.js.map +0 -1
- package/src/agentlib/README.md +0 -229
- package/src/agentlib/agent.ts +0 -216
- package/src/agentlib/index.ts +0 -16
- package/src/agentlib/messages.ts +0 -207
- package/src/agentlib/model.ts +0 -156
- package/src/agentlib/options.ts +0 -62
- package/src/agentlib/runtime.ts +0 -252
- package/src/agentlib/state.ts +0 -93
- package/src/agentlib/steering.ts +0 -53
- package/src/agentlib/tools.ts +0 -355
- package/src/agentlib/turn.ts +0 -302
- package/src/calls.ts +0 -330
- package/src/claude/README.md +0 -107
- package/src/claude/index.ts +0 -487
- package/src/client.ts +0 -187
- package/src/common.ts +0 -766
- package/src/companion.ts +0 -675
- package/src/conversation.ts +0 -1799
- package/src/deepseek/README.md +0 -202
- package/src/deepseek/barriers.ts +0 -63
- package/src/deepseek/index.ts +0 -740
- package/src/deepseek/persistence.ts +0 -337
- package/src/index.ts +0 -41
- package/src/langgraph/README.md +0 -199
- package/src/langgraph/checkpointer.ts +0 -614
- package/src/langgraph/context.ts +0 -27
- package/src/langgraph/errors.ts +0 -26
- package/src/langgraph/graph.ts +0 -422
- package/src/langgraph/index.ts +0 -500
- package/src/langgraph/keepalive.ts +0 -58
- package/src/langgraph/nodes.ts +0 -247
- package/src/messages.ts +0 -244
- package/src/object.ts +0 -454
- package/src/opencode/README.md +0 -249
- package/src/opencode/db.ts +0 -387
- package/src/opencode/index.ts +0 -1339
- package/src/output.ts +0 -116
- package/src/pi/README.md +0 -174
- package/src/pi/commits.ts +0 -7
- package/src/steering.ts +0 -68
- package/src/tools.ts +0 -515
- package/src/webhook.ts +0 -161
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agentlib/tools.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,IAAI,IAAI,OAAO,EAErB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EACL,KAAK,QAAQ,EAQb,KAAK,IAAI,EAEV,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,aAAa,CAAC;CACrC;AAED,sFAAsF;AAGtF,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,KAAK,GACb,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,GAClD,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC,CAAC;AAExC,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB;;;GAGG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,KAAK,EACZ,QAAQ,CAAC,EAAE,QAAQ,GAClB,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAiC9B;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,SAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CA6BxF"}
|
package/dist/agentlib/tools.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
// The tools of @restatedev/agents in an agentlib agent. Each becomes an
|
|
2
|
-
// agentlib tool whose calls are the generator SDK's, on the classic context
|
|
3
|
-
// of the agent's invocation, so Restate journals them:
|
|
4
|
-
//
|
|
5
|
-
// - `call`, `subagent` and `workflow` are calls: a crash replays their answer,
|
|
6
|
-
// and stopping the turn cancels them. No call records or idempotency keys
|
|
7
|
-
// are needed, as in a session object.
|
|
8
|
-
// - `send` is a send, made once.
|
|
9
|
-
// - `signal` waits at the agent's companion.
|
|
10
|
-
// - A `tool()` runs as a journaled step, as agentlib's `asyncTool` does. Its
|
|
11
|
-
// `ctx` has `key` and `request`, but no database or calls: a classic
|
|
12
|
-
// object has no session.
|
|
13
|
-
import { RunFailedError, tool as libTool, } from '@restatedev/agentlib';
|
|
14
|
-
import { call, run, send, serde } from '@restatedev/restate-sdk-gen';
|
|
15
|
-
import { sdk as restate } from '@restatedev/sessions/internal';
|
|
16
|
-
import { isTool, keyed, sentTo, specOf, text, } from '../tools.js';
|
|
17
|
-
import { waitForSignal } from './state.js';
|
|
18
|
-
/**
|
|
19
|
-
* Gives each tool its name, turning the tools of `@restatedev/agents` into
|
|
20
|
-
* agentlib's. Those that `approval` names wait for a person's approval.
|
|
21
|
-
*/
|
|
22
|
-
export function toolsOf(agent, tools, approval) {
|
|
23
|
-
const named = {};
|
|
24
|
-
const ours = new Set();
|
|
25
|
-
const add = (name, tool) => {
|
|
26
|
-
if (name in named)
|
|
27
|
-
throw new Error(`${agent}: two tools are named ${name}`);
|
|
28
|
-
if (isTool(tool)) {
|
|
29
|
-
named[name] = fromTool(tool, name, approval);
|
|
30
|
-
ours.add(name);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
named[name] = tool;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const addRecord = (record) => {
|
|
37
|
-
for (const [name, tool] of Object.entries(record))
|
|
38
|
-
add(name, tool);
|
|
39
|
-
};
|
|
40
|
-
if (Array.isArray(tools)) {
|
|
41
|
-
for (const tool of tools) {
|
|
42
|
-
if (isTool(tool))
|
|
43
|
-
add(tool.name, tool);
|
|
44
|
-
else
|
|
45
|
-
addRecord(tool);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
addRecord(tools);
|
|
50
|
-
}
|
|
51
|
-
for (const name of Array.isArray(approval) ? approval : []) {
|
|
52
|
-
if (ours.has(name))
|
|
53
|
-
continue;
|
|
54
|
-
throw new Error(`${agent}: approval names ${name}, which is none of its tools of @restatedev/agents ` +
|
|
55
|
-
"(agentlib's own tools take needsApproval)");
|
|
56
|
-
}
|
|
57
|
-
return named;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Turns `tool`, one of `@restatedev/agents`, into agentlib's, named `name`.
|
|
61
|
-
* As in every agent, arguments that do not fit its input are the model's to
|
|
62
|
-
* fix, and a terminal error is the tool's answer, which the model sees.
|
|
63
|
-
*/
|
|
64
|
-
export function fromTool(tool, name = tool.name, approval) {
|
|
65
|
-
const spec = specOf(tool);
|
|
66
|
-
if (!spec) {
|
|
67
|
-
throw new Error(`${tool.name} is no tool of @restatedev/agents (tool(), call, send...)`);
|
|
68
|
-
}
|
|
69
|
-
function* execute(input, { context, callId }) {
|
|
70
|
-
try {
|
|
71
|
-
return yield* perform(tool, spec, input, context.ctx, callId);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
// A tool() that reached for what an agentlib agent lacks is a programming
|
|
75
|
-
// error: it fails the turn, rather than reach the model as an answer.
|
|
76
|
-
if (error instanceof restate.TerminalError && error.message.startsWith(MISSING)) {
|
|
77
|
-
throw new RunFailedError(`the tool ${tool.name}: ${error.message}`);
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// agentlib's own tool(): it checks the input, and asks for the approval.
|
|
83
|
-
return libTool({
|
|
84
|
-
description: tool.description,
|
|
85
|
-
input: tool.input,
|
|
86
|
-
needsApproval: needsApprovalOf(name, approval),
|
|
87
|
-
execute,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/** Whether the tool `name` needs approval, as agentlib's `needsApproval` takes it. */
|
|
91
|
-
function needsApprovalOf(name, approval) {
|
|
92
|
-
if (approval === undefined)
|
|
93
|
-
return false;
|
|
94
|
-
if (typeof approval !== 'function')
|
|
95
|
-
return approval.includes(name);
|
|
96
|
-
const asks = approval;
|
|
97
|
-
// oxlint-disable-next-line require-yield -- deciding needs no wait
|
|
98
|
-
return function* (args) {
|
|
99
|
-
return asks({ name, args });
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/** Does what `tool` does, with its checked `input`, as tool call `callId`. */
|
|
103
|
-
function* perform(tool, spec, input, ctx, callId) {
|
|
104
|
-
switch (spec.kind) {
|
|
105
|
-
case 'run':
|
|
106
|
-
return yield* runTool(tool.name, spec.run, input, ctx, callId);
|
|
107
|
-
case 'call':
|
|
108
|
-
return yield* callTool(tool.name, spec, input, ctx);
|
|
109
|
-
case 'send':
|
|
110
|
-
return yield* sendTool(tool.name, spec, input, ctx);
|
|
111
|
-
case 'workflow':
|
|
112
|
-
return yield* workflowTool(tool.name, spec, input, ctx, callId);
|
|
113
|
-
case 'signal': {
|
|
114
|
-
const shown = spec.shown ? input : undefined;
|
|
115
|
-
return text(yield* waitForSignal(ctx, callId, spec.name, shown));
|
|
116
|
-
}
|
|
117
|
-
case 'subagent': {
|
|
118
|
-
const { name, task } = input;
|
|
119
|
-
return text(yield* callJson(spec.agent, spec.handler, `${ctx.key}.${name}`, task));
|
|
120
|
-
}
|
|
121
|
-
default:
|
|
122
|
-
throw new Error(`the tool ${tool.name} does what no agentlib agent knows`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* A `tool()`: its `run` as a journaled step. It has no retry limit of its
|
|
127
|
-
* own: a failure fails the attempt, which Restate retries.
|
|
128
|
-
*/
|
|
129
|
-
function* runTool(name, runOf, input, ctx, callId) {
|
|
130
|
-
const context = { ctx: sessionOf(ctx), callId, idempotencyKey: `${ctx.request().id}:${callId}` };
|
|
131
|
-
const action = runOf;
|
|
132
|
-
return yield* run(async () => text(await action(input, context)), { name, retry: {} });
|
|
133
|
-
}
|
|
134
|
-
/** A `call`: a call of the handler, or the run of a workflow, which it waits for. */
|
|
135
|
-
function* callTool(name, spec, input, ctx) {
|
|
136
|
-
const { target, handler, options } = spec;
|
|
137
|
-
const { key, parameter } = yield* split(name, target, options, input, ctx);
|
|
138
|
-
if ('workflow' in target && handler === 'run') {
|
|
139
|
-
return text(yield* runWorkflow(target.name, key, parameter));
|
|
140
|
-
}
|
|
141
|
-
return text(yield* callJson(target.name, handler, key, parameter));
|
|
142
|
-
}
|
|
143
|
-
/** A `send`: a one-way call, after the tool's `delay` if it has one. */
|
|
144
|
-
function* sendTool(name, spec, input, ctx) {
|
|
145
|
-
const { target, handler, options } = spec;
|
|
146
|
-
const { key, parameter } = yield* split(name, target, options, input, ctx);
|
|
147
|
-
const message = { service: target.name, method: handler, key, parameter, inputSerde: serde.json };
|
|
148
|
-
send(options.delay === undefined ? message : { ...message, delay: options.delay });
|
|
149
|
-
return sentTo(target.name, key, handler);
|
|
150
|
-
}
|
|
151
|
-
/** A `workflow`: a run of its own per tool call, unless the tool's `key` gives its id. */
|
|
152
|
-
function* workflowTool(name, spec, input, ctx, callId) {
|
|
153
|
-
const { target, options } = spec;
|
|
154
|
-
const key = options.key === undefined ? `${ctx.key}-${callId}` : yield* configured(name, options.key, ctx);
|
|
155
|
-
return text(yield* runWorkflow(target.name, key, options.input ? input : undefined));
|
|
156
|
-
}
|
|
157
|
-
// The calls.
|
|
158
|
-
/** Calls `method` of `service` (at `key`), with JSON in and out. */
|
|
159
|
-
function callJson(service, method, key, parameter) {
|
|
160
|
-
return call({
|
|
161
|
-
service,
|
|
162
|
-
method,
|
|
163
|
-
key,
|
|
164
|
-
parameter,
|
|
165
|
-
inputSerde: serde.json,
|
|
166
|
-
outputSerde: serde.json,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Runs workflow `service` with id `key` to its end, and returns its result.
|
|
171
|
-
* A workflow's `run` runs once per id: Restate refuses a second call of it,
|
|
172
|
-
* but that call's invocation id is the run's. So the tool calls `run`, takes
|
|
173
|
-
* the call's invocation id, and waits for that invocation; a fixed id that
|
|
174
|
-
* ran before gets its run's result. It is a call, not a send, so that
|
|
175
|
-
* stopping the turn cancels the run.
|
|
176
|
-
*/
|
|
177
|
-
function* runWorkflow(service, key, parameter) {
|
|
178
|
-
const started = call({
|
|
179
|
-
service,
|
|
180
|
-
method: 'run',
|
|
181
|
-
key,
|
|
182
|
-
parameter,
|
|
183
|
-
inputSerde: serde.json,
|
|
184
|
-
outputSerde: serde.binary,
|
|
185
|
-
});
|
|
186
|
-
const invocation = yield* started.invocation;
|
|
187
|
-
return yield* invocation.attach(serde.json);
|
|
188
|
-
}
|
|
189
|
-
/** The key, and the handler's input, of a tool call's input (as `split` in ../tools.ts). */
|
|
190
|
-
function* split(name, target, options, input, ctx) {
|
|
191
|
-
if (!keyed(target)) {
|
|
192
|
-
return { key: undefined, parameter: options.input ? input : undefined };
|
|
193
|
-
}
|
|
194
|
-
if (options.key !== undefined) {
|
|
195
|
-
const key = yield* configured(name, options.key, ctx);
|
|
196
|
-
return { key, parameter: options.input ? input : undefined };
|
|
197
|
-
}
|
|
198
|
-
// The model chose the key, as a field of the tool's input.
|
|
199
|
-
const { key, ...rest } = input;
|
|
200
|
-
return { key, parameter: options.input ? rest : undefined };
|
|
201
|
-
}
|
|
202
|
-
/** `value`, or, for a function of a session's context, what it returns, as a journaled step. */
|
|
203
|
-
function* configured(name, value, ctx) {
|
|
204
|
-
if (typeof value !== 'function')
|
|
205
|
-
return value;
|
|
206
|
-
const session = sessionOf(ctx);
|
|
207
|
-
const of = value;
|
|
208
|
-
return yield* run(async () => of(session), { name: `${name}: key` });
|
|
209
|
-
}
|
|
210
|
-
// What a tool() gets as its ctx.
|
|
211
|
-
/** How the error of a `tool()` that reached for a missing `ctx` field starts. */
|
|
212
|
-
const MISSING = 'not in an agentlib agent:';
|
|
213
|
-
const NO_DATABASE = 'an agentlib agent keeps its conversation in its state, with no SQL database';
|
|
214
|
-
const CALLS_INSTEAD = "give the agent Restate's tools (call, send, workflow, subagent) or agentlib's own";
|
|
215
|
-
/** Throws the error for a `tool()` that reached for `what`, saying what to use `instead`. */
|
|
216
|
-
function missing(what, instead) {
|
|
217
|
-
throw new restate.TerminalError(`${MISSING} ${what}: ${instead}`);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* A session object's context, as a `tool()` in an agentlib agent gets it:
|
|
221
|
-
* `key` and `request`. Its database and calls fail the turn, saying what to
|
|
222
|
-
* use instead.
|
|
223
|
-
*/
|
|
224
|
-
function sessionOf(ctx) {
|
|
225
|
-
const request = ctx.request();
|
|
226
|
-
return Object.freeze({
|
|
227
|
-
key: ctx.key,
|
|
228
|
-
request,
|
|
229
|
-
get db() {
|
|
230
|
-
return missing('ctx.db', NO_DATABASE);
|
|
231
|
-
},
|
|
232
|
-
get rpc() {
|
|
233
|
-
return missing('ctx.rpc', CALLS_INSTEAD);
|
|
234
|
-
},
|
|
235
|
-
get send() {
|
|
236
|
-
return missing('ctx.send', CALLS_INSTEAD);
|
|
237
|
-
},
|
|
238
|
-
get cancel() {
|
|
239
|
-
return missing('ctx.cancel', CALLS_INSTEAD);
|
|
240
|
-
},
|
|
241
|
-
// An agentlib agent runs on the SDK's journaled context, which has no `working`: the work just runs.
|
|
242
|
-
working: (fn) => (async () => fn())(),
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
//# sourceMappingURL=tools.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/agentlib/tools.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,4EAA4E;AAC5E,uDAAuD;AACvD,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,wCAAwC;AACxC,iCAAiC;AACjC,6CAA6C;AAC7C,6EAA6E;AAC7E,uEAAuE;AACvE,2BAA2B;AAC3B,OAAO,EACL,cAAc,EACd,IAAI,IAAI,OAAO,GAIhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAkB,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAEL,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EAGN,IAAI,GAGL,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA4B3C;;;GAGG;AACH,MAAM,UAAU,OAAO,CACrB,KAAa,EACb,KAAY,EACZ,QAAmB;IAEnB,MAAM,KAAK,GAAiC,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,IAAyB,EAAE,EAAE;QACtD,IAAI,IAAI,IAAI,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,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AI,KAAK,OAAO,EAAE,CAAC,CAAC;AACpE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,GAA0B;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,OAAO;QACP,IAAI,EAAE;YACJ,OAAO,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,GAAG;YACL,OAAO,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI,IAAI;YACN,OAAO,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,MAAM;YACR,OAAO,OAAO,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAC9C,CAAC;QACD,qGAAqG;QACrG,OAAO,EAAE,CAAI,EAAwB,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE;KAC/D,CAAC,CAAC;AACL,CAAC"}
|
package/dist/agentlib/turn.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { LazyStateConversation, type CompactionPolicy, type Conversation, type ConversationCompactionStatus, type ConversationSnapshot, type Message, type Model, type ProgressEvent } from '@restatedev/agentlib';
|
|
2
|
-
import { type Operation } from '@restatedev/restate-sdk-gen';
|
|
3
|
-
import type { sdk as restate } from '@restatedev/sessions/internal';
|
|
4
|
-
import { type LiveTurn } from './state.ts';
|
|
5
|
-
/** How the model's conversation is summarized at a turn's start (see the agent's `history`). */
|
|
6
|
-
export interface Compaction {
|
|
7
|
-
model: Model;
|
|
8
|
-
policy?: CompactionPolicy;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The model's conversation, in the state of the object of `ctx`: agentlib's
|
|
12
|
-
* `LazyStateConversation` over that state, its reads journaled. With
|
|
13
|
-
* `compaction`, it summarizes its earliest messages when they grow too many.
|
|
14
|
-
*/
|
|
15
|
-
export declare function conversationOf(ctx: restate.ObjectContext, compaction?: Compaction): LazyStateConversation;
|
|
16
|
-
/**
|
|
17
|
-
* A turn being answered. It keeps the turn's messages as clients read them
|
|
18
|
-
* (one state key each), and is the run's `Conversation`: agentlib loads the
|
|
19
|
-
* model's conversation through it, and saves the turn through it when the
|
|
20
|
-
* run ends. Its messages are then rewritten from what the run saved, under
|
|
21
|
-
* the same ids.
|
|
22
|
-
*/
|
|
23
|
-
export declare class Turn implements Conversation {
|
|
24
|
-
readonly live: LiveTurn;
|
|
25
|
-
/** Summarizes the model's conversation at the run's start, if the agent's `history` says to. */
|
|
26
|
-
compactor?: LazyStateConversation;
|
|
27
|
-
private readonly ctx;
|
|
28
|
-
private readonly meta;
|
|
29
|
-
private readonly conversation;
|
|
30
|
-
/** The turn's messages, as clients read them. Message `i` has id `live.from + i`. */
|
|
31
|
-
private entries;
|
|
32
|
-
/** The index in {@link entries} of each step's reply, by step. */
|
|
33
|
-
private readonly replies;
|
|
34
|
-
private step;
|
|
35
|
-
/** The conversation's version, once loaded or appended to. */
|
|
36
|
-
private version?;
|
|
37
|
-
/** The turn's messages of agentlib, once the run saved them. */
|
|
38
|
-
private saved;
|
|
39
|
-
private constructor();
|
|
40
|
-
/**
|
|
41
|
-
* Starts the turn that answers `prompt`. A turn before it that never ended
|
|
42
|
-
* (its invocation was killed) ends first.
|
|
43
|
-
*/
|
|
44
|
-
static start(ctx: restate.ObjectContext, prompt: string): Promise<Turn>;
|
|
45
|
-
/** Ends the turn `live`, whose invocation was killed, with the note {@link ENDED}. */
|
|
46
|
-
private static endKilled;
|
|
47
|
-
/** Records what a progress event of the run changes. Returns whether clients see a change. */
|
|
48
|
-
progress(event: ProgressEvent): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Returns the tool part of call `callId` and the index of its reply. A call
|
|
51
|
-
* that started earlier (a background call can end steps later) is found
|
|
52
|
-
* where it is; a new one is added to the current step's reply.
|
|
53
|
-
*/
|
|
54
|
-
private toolPart;
|
|
55
|
-
load(): Operation<ConversationSnapshot>;
|
|
56
|
-
compact(): Operation<ConversationCompactionStatus>;
|
|
57
|
-
/**
|
|
58
|
-
* Saves the turn's messages. Clients then read the turn as it was saved,
|
|
59
|
-
* with its replies' texts.
|
|
60
|
-
*/
|
|
61
|
-
append(messages: readonly Message[], expectedVersion: number): Operation<number>;
|
|
62
|
-
/** Ends the turn with its answer. A run that saved nothing leaves the prompt and the answer. */
|
|
63
|
-
answered(answer: unknown): Promise<void>;
|
|
64
|
-
/** Ends the turn without an answer: `note` says how (stopped, refused, failed, killed). */
|
|
65
|
-
close(note: string): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Ends a turn that the run did not save, with `text`. The model's
|
|
68
|
-
* conversation gets the prompt, the messages steered to the turn, and
|
|
69
|
-
* `text`, but not the turn's tool calls, whose results may be missing.
|
|
70
|
-
* Clients see each open tool call closed with `text`.
|
|
71
|
-
*/
|
|
72
|
-
private endUnsaved;
|
|
73
|
-
/** Appends `messages` to the model's conversation outside the run, in an operation of its own. */
|
|
74
|
-
private appendOutsideRun;
|
|
75
|
-
/** Marks the turn ended: the next turn's messages start after its own. */
|
|
76
|
-
private finish;
|
|
77
|
-
/** Stores message `i` of the turn with the next cursor, and the turn's bookkeeping. */
|
|
78
|
-
private write;
|
|
79
|
-
/** Replaces the turn's messages with `entries`, each with a new cursor, in order. */
|
|
80
|
-
private rewrite;
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=turn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"turn.d.ts","sourceRoot":"","sources":["../../src/agentlib/turn.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,4BAA4B,EACjC,KAAK,oBAAoB,EAEzB,KAAK,OAAO,EACZ,KAAK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IAED;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAoBf,IAAI,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAIvC;IAEA,OAAO,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAGlD;IAED;;;OAGG;IACF,MAAM,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAKhF;IAID,gGAAgG;IAC1F,QAAQ,CAAC,MAAM,EAAE,OAAO,iBAM7B;IAED,2FAA2F;IACrF,KAAK,CAAC,IAAI,EAAE,MAAM,iBAOvB;IAED;;;;;OAKG;YACW,UAAU;IAaxB,kGAAkG;YACpF,gBAAgB;IAU9B,0EAA0E;IAC1E,OAAO,CAAC,MAAM;IAQd,uFAAuF;IACvF,OAAO,CAAC,KAAK;IAQb,qFAAqF;IACrF,OAAO,CAAC,OAAO;CAQhB"}
|
package/dist/agentlib/turn.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
// A turn of the agentlib agent: its messages as clients read them, written as
|
|
2
|
-
// the run goes, and the model's conversation, which the run loads and saves.
|
|
3
|
-
import { LazyStateConversation, } from '@restatedev/agentlib';
|
|
4
|
-
import { execute } from '@restatedev/restate-sdk-gen';
|
|
5
|
-
import { ENDED } from '../common.js';
|
|
6
|
-
import { outputOf, render, steeringNote } from './messages.js';
|
|
7
|
-
import { CONVERSATION, CONVERSATION_META, emptyMeta, entryKey, META, read, } from './state.js';
|
|
8
|
-
/**
|
|
9
|
-
* The model's conversation, in the state of the object of `ctx`: agentlib's
|
|
10
|
-
* `LazyStateConversation` over that state, its reads journaled. With
|
|
11
|
-
* `compaction`, it summarizes its earliest messages when they grow too many.
|
|
12
|
-
*/
|
|
13
|
-
export function conversationOf(ctx, compaction) {
|
|
14
|
-
const store = {
|
|
15
|
-
*get(key) {
|
|
16
|
-
const value = yield* read(ctx, key);
|
|
17
|
-
return value ?? undefined;
|
|
18
|
-
},
|
|
19
|
-
// A state write takes effect at once (and is journaled): nothing to wait for.
|
|
20
|
-
// oxlint-disable-next-line require-yield
|
|
21
|
-
*set(key, value) {
|
|
22
|
-
ctx.set(key, value);
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
return new LazyStateConversation({
|
|
26
|
-
stateKey: CONVERSATION,
|
|
27
|
-
metaKey: CONVERSATION_META,
|
|
28
|
-
store,
|
|
29
|
-
...(compaction && { compaction }),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/** The text of a rendered message's text parts. */
|
|
33
|
-
function textOf(entry) {
|
|
34
|
-
const texts = entry.parts.map((part) => (part.type === 'text' ? part.text : ''));
|
|
35
|
-
return texts.join('');
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A turn being answered. It keeps the turn's messages as clients read them
|
|
39
|
-
* (one state key each), and is the run's `Conversation`: agentlib loads the
|
|
40
|
-
* model's conversation through it, and saves the turn through it when the
|
|
41
|
-
* run ends. Its messages are then rewritten from what the run saved, under
|
|
42
|
-
* the same ids.
|
|
43
|
-
*/
|
|
44
|
-
export class Turn {
|
|
45
|
-
live;
|
|
46
|
-
/** Summarizes the model's conversation at the run's start, if the agent's `history` says to. */
|
|
47
|
-
compactor;
|
|
48
|
-
ctx;
|
|
49
|
-
meta;
|
|
50
|
-
conversation;
|
|
51
|
-
/** The turn's messages, as clients read them. Message `i` has id `live.from + i`. */
|
|
52
|
-
entries = [];
|
|
53
|
-
/** The index in {@link entries} of each step's reply, by step. */
|
|
54
|
-
replies = new Map();
|
|
55
|
-
step = 0;
|
|
56
|
-
/** The conversation's version, once loaded or appended to. */
|
|
57
|
-
version;
|
|
58
|
-
/** The turn's messages of agentlib, once the run saved them. */
|
|
59
|
-
saved = [];
|
|
60
|
-
constructor(ctx, meta, live) {
|
|
61
|
-
this.ctx = ctx;
|
|
62
|
-
this.meta = meta;
|
|
63
|
-
this.live = live;
|
|
64
|
-
this.conversation = conversationOf(ctx);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Starts the turn that answers `prompt`. A turn before it that never ended
|
|
68
|
-
* (its invocation was killed) ends first.
|
|
69
|
-
*/
|
|
70
|
-
static async start(ctx, prompt) {
|
|
71
|
-
const meta = (await ctx.get(META)) ?? emptyMeta();
|
|
72
|
-
if (meta.live)
|
|
73
|
-
await Turn.endKilled(ctx, meta, meta.live);
|
|
74
|
-
const turn = new Turn(ctx, meta, { turn: ctx.request().id, prompt, from: meta.chats, n: 0 });
|
|
75
|
-
meta.live = turn.live;
|
|
76
|
-
turn.entries.push({ role: 'user', parts: [{ type: 'text', text: prompt }], prompt: true });
|
|
77
|
-
turn.write(0);
|
|
78
|
-
return turn;
|
|
79
|
-
}
|
|
80
|
-
/** Ends the turn `live`, whose invocation was killed, with the note {@link ENDED}. */
|
|
81
|
-
static async endKilled(ctx, meta, live) {
|
|
82
|
-
const turn = new Turn(ctx, meta, live);
|
|
83
|
-
for (let i = 0; i < live.n; i++) {
|
|
84
|
-
const entry = await ctx.get(entryKey(live.from + i));
|
|
85
|
-
if (!entry)
|
|
86
|
-
continue;
|
|
87
|
-
const rendered = { role: entry.role, parts: entry.parts };
|
|
88
|
-
if (entry.prompt)
|
|
89
|
-
rendered.prompt = true;
|
|
90
|
-
turn.entries.push(rendered);
|
|
91
|
-
}
|
|
92
|
-
await turn.close(ENDED);
|
|
93
|
-
}
|
|
94
|
-
// The run's progress, as clients see it.
|
|
95
|
-
/** Records what a progress event of the run changes. Returns whether clients see a change. */
|
|
96
|
-
progress(event) {
|
|
97
|
-
switch (event.type) {
|
|
98
|
-
case 'step':
|
|
99
|
-
this.step = event.step;
|
|
100
|
-
return false;
|
|
101
|
-
case 'tool-start':
|
|
102
|
-
this.toolPart(event.callId, event.name, event.input);
|
|
103
|
-
return true;
|
|
104
|
-
case 'tool-end': {
|
|
105
|
-
const [index, part] = this.toolPart(event.callId, event.name);
|
|
106
|
-
Object.assign(part, outputOf(event.result));
|
|
107
|
-
this.write(index);
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
case 'steering':
|
|
111
|
-
this.entries.push({ role: 'user', parts: [{ type: 'text', text: event.message }] });
|
|
112
|
-
this.write(this.entries.length - 1);
|
|
113
|
-
return true;
|
|
114
|
-
default:
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Returns the tool part of call `callId` and the index of its reply. A call
|
|
120
|
-
* that started earlier (a background call can end steps later) is found
|
|
121
|
-
* where it is; a new one is added to the current step's reply.
|
|
122
|
-
*/
|
|
123
|
-
toolPart(callId, name, input) {
|
|
124
|
-
for (const [index, entry] of this.entries.entries()) {
|
|
125
|
-
if (entry.role !== 'assistant')
|
|
126
|
-
continue;
|
|
127
|
-
const part = entry.parts.find((p) => p.type === 'tool' && p.id === callId);
|
|
128
|
-
if (part)
|
|
129
|
-
return [index, part];
|
|
130
|
-
}
|
|
131
|
-
let index = this.replies.get(this.step);
|
|
132
|
-
if (index === undefined) {
|
|
133
|
-
index = this.entries.push({ role: 'assistant', parts: [] }) - 1;
|
|
134
|
-
this.replies.set(this.step, index);
|
|
135
|
-
}
|
|
136
|
-
const part = { type: 'tool', id: callId, name, input: input ?? null };
|
|
137
|
-
this.entries[index].parts.push(part);
|
|
138
|
-
this.write(index);
|
|
139
|
-
return [index, part];
|
|
140
|
-
}
|
|
141
|
-
// agentlib's Conversation: what the run loads, compacts and saves.
|
|
142
|
-
*load() {
|
|
143
|
-
const snapshot = yield* this.conversation.load();
|
|
144
|
-
this.version = snapshot.version;
|
|
145
|
-
return snapshot;
|
|
146
|
-
}
|
|
147
|
-
*compact() {
|
|
148
|
-
if (!this.compactor)
|
|
149
|
-
return 'skipped';
|
|
150
|
-
return yield* this.compactor.compact();
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Saves the turn's messages. Clients then read the turn as it was saved,
|
|
154
|
-
* with its replies' texts.
|
|
155
|
-
*/
|
|
156
|
-
*append(messages, expectedVersion) {
|
|
157
|
-
this.version = yield* this.conversation.append(messages, expectedVersion);
|
|
158
|
-
this.saved.push(...messages);
|
|
159
|
-
this.rewrite(render(this.saved));
|
|
160
|
-
return this.version;
|
|
161
|
-
}
|
|
162
|
-
// How the turn ends.
|
|
163
|
-
/** Ends the turn with its answer. A run that saved nothing leaves the prompt and the answer. */
|
|
164
|
-
async answered(answer) {
|
|
165
|
-
if (this.saved.length === 0) {
|
|
166
|
-
const text = typeof answer === 'string' ? answer : JSON.stringify(answer);
|
|
167
|
-
await this.endUnsaved(text);
|
|
168
|
-
}
|
|
169
|
-
this.finish();
|
|
170
|
-
}
|
|
171
|
-
/** Ends the turn without an answer: `note` says how (stopped, refused, failed, killed). */
|
|
172
|
-
async close(note) {
|
|
173
|
-
if (this.saved.length === 0) {
|
|
174
|
-
await this.endUnsaved(note);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this.rewrite([...this.entries, answerEntry(note)]);
|
|
178
|
-
}
|
|
179
|
-
this.finish();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Ends a turn that the run did not save, with `text`. The model's
|
|
183
|
-
* conversation gets the prompt, the messages steered to the turn, and
|
|
184
|
-
* `text`, but not the turn's tool calls, whose results may be missing.
|
|
185
|
-
* Clients see each open tool call closed with `text`.
|
|
186
|
-
*/
|
|
187
|
-
async endUnsaved(text) {
|
|
188
|
-
const steered = this.entries.slice(1).filter((entry) => entry.role === 'user');
|
|
189
|
-
const messages = [
|
|
190
|
-
{ role: 'user', content: this.live.prompt },
|
|
191
|
-
...steered.map((entry) => ({ role: 'user', content: steeringNote(textOf(entry)) })),
|
|
192
|
-
{ role: 'assistant', content: text },
|
|
193
|
-
];
|
|
194
|
-
await this.appendOutsideRun(messages);
|
|
195
|
-
const closed = this.entries.map((entry) => closeOpenCalls(entry, text));
|
|
196
|
-
this.rewrite([...closed, answerEntry(text)]);
|
|
197
|
-
}
|
|
198
|
-
/** Appends `messages` to the model's conversation outside the run, in an operation of its own. */
|
|
199
|
-
async appendOutsideRun(messages) {
|
|
200
|
-
const conversation = this.conversation;
|
|
201
|
-
const known = this.version;
|
|
202
|
-
function* append() {
|
|
203
|
-
const version = known ?? (yield* conversation.load()).version;
|
|
204
|
-
return yield* conversation.append(messages, version);
|
|
205
|
-
}
|
|
206
|
-
this.version = await execute(this.ctx, append());
|
|
207
|
-
}
|
|
208
|
-
/** Marks the turn ended: the next turn's messages start after its own. */
|
|
209
|
-
finish() {
|
|
210
|
-
this.meta.chats = this.live.from + this.entries.length;
|
|
211
|
-
delete this.meta.live;
|
|
212
|
-
this.ctx.set(META, this.meta);
|
|
213
|
-
}
|
|
214
|
-
// Storing the turn's messages.
|
|
215
|
-
/** Stores message `i` of the turn with the next cursor, and the turn's bookkeeping. */
|
|
216
|
-
write(i) {
|
|
217
|
-
this.meta.cursor += 1;
|
|
218
|
-
const entry = { ...this.entries[i], at: this.meta.cursor };
|
|
219
|
-
this.ctx.set(entryKey(this.live.from + i), entry);
|
|
220
|
-
this.live.n = Math.max(this.live.n, this.entries.length);
|
|
221
|
-
this.ctx.set(META, this.meta);
|
|
222
|
-
}
|
|
223
|
-
/** Replaces the turn's messages with `entries`, each with a new cursor, in order. */
|
|
224
|
-
rewrite(entries) {
|
|
225
|
-
for (let i = entries.length; i < this.live.n; i++) {
|
|
226
|
-
this.ctx.clear(entryKey(this.live.from + i));
|
|
227
|
-
}
|
|
228
|
-
this.entries = entries;
|
|
229
|
-
this.live.n = entries.length;
|
|
230
|
-
for (let i = 0; i < entries.length; i++)
|
|
231
|
-
this.write(i);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/** A reply that answers a turn with `text`. */
|
|
235
|
-
function answerEntry(text) {
|
|
236
|
-
return { role: 'assistant', parts: [{ type: 'text', text }], answer: true };
|
|
237
|
-
}
|
|
238
|
-
/** Whether `part` is a tool call without an output yet. */
|
|
239
|
-
function isOpenCall(part) {
|
|
240
|
-
return part.type === 'tool' && part.output === undefined;
|
|
241
|
-
}
|
|
242
|
-
/** Gives each tool call of `entry` that has no output yet `text` as its output, as an error. */
|
|
243
|
-
function closeOpenCalls(entry, text) {
|
|
244
|
-
if (entry.role !== 'assistant' || !entry.parts.some(isOpenCall))
|
|
245
|
-
return entry;
|
|
246
|
-
const parts = entry.parts.map((part) => {
|
|
247
|
-
if (!isOpenCall(part))
|
|
248
|
-
return part;
|
|
249
|
-
return { ...part, output: text, error: true };
|
|
250
|
-
});
|
|
251
|
-
return { ...entry, parts };
|
|
252
|
-
}
|
|
253
|
-
//# sourceMappingURL=turn.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"turn.js","sourceRoot":"","sources":["../../src/agentlib/turn.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,OAAO,EACL,qBAAqB,GAStB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAkB,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,KAAK,EAAa,MAAM,cAAc,CAAC;AAChD,OAAO,EAAc,QAAQ,EAAE,MAAM,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,QAAQ,EAER,IAAI,EAEJ,IAAI,GACL,MAAM,YAAY,CAAC;AAUpB;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,GAA0B,EAC1B,UAAuB;IAEvB,MAAM,KAAK,GAAG;QACZ,CAAC,GAAG,CAAI,GAAW;YACjB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,CAAI,GAAG,EAAE,GAAG,CAAC,CAAC;YACvC,OAAO,KAAK,IAAI,SAAS,CAAC;QAC5B,CAAC;QACD,8EAA8E;QAC9E,yCAAyC;QACzC,CAAC,GAAG,CAAC,GAAW,EAAE,KAAc;YAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtB,CAAC;KACF,CAA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