@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Context } from '@earendil-works/chord/context';
|
|
2
|
+
import type { Message } from '@earendil-works/pi-ai';
|
|
3
|
+
import { type AgentChange, Harness, type HarnessOptions, type Registry, type ToolRegistration } from '@earendil-works/pi-durable';
|
|
4
|
+
import * as restate from '@restatedev/sessions';
|
|
5
|
+
/** `withPi`'s options: pi's `Harness.open` options but the registry, which each invocation gets fresh. */
|
|
6
|
+
export type PiOptions<Tool extends ToolRegistration = ToolRegistration> = Omit<HarnessOptions<Tool>, 'registry' | 'readOnly'> & {
|
|
7
|
+
/**
|
|
8
|
+
* The invocation's tools, given its `ctx`: called once per invocation, before the closure runs, and installed in
|
|
9
|
+
* its `registry` as one extension named `withPi.tools`. The name is the same on every invocation, as pi needs for a
|
|
10
|
+
* conversation that selects extensions by name (`agent.extensions`, `settings.extensions`): a selection that does
|
|
11
|
+
* not name `withPi.tools` leaves these tools out. Tools installed in the
|
|
12
|
+
* closure are added to them; an extension of that name installed there replaces them. `Tool` is not inferred from
|
|
13
|
+
* these, so the closure's registry takes other tools too.
|
|
14
|
+
*/
|
|
15
|
+
tools?: (ctx: restate.SessionContext) => NoInfer<Tool>[];
|
|
16
|
+
/**
|
|
17
|
+
* The agent the root conversation is created with, at the first `ask` on a key. pi keeps a conversation's agent:
|
|
18
|
+
* on a key whose conversation exists this changes nothing; pi's `configure` on the root (through `harness()`)
|
|
19
|
+
* changes it.
|
|
20
|
+
*/
|
|
21
|
+
agent?: AgentChange;
|
|
22
|
+
/** The chord context of pi's calls. Default `BACKGROUND_CONTEXT`. */
|
|
23
|
+
context?: Context;
|
|
24
|
+
};
|
|
25
|
+
/** `ask`'s options. */
|
|
26
|
+
export type AskOptions = {
|
|
27
|
+
/** The submission's id, given to pi as its `requestId` as it is. Default: the invocation id (`ctx.request.id`). */
|
|
28
|
+
requestId?: string;
|
|
29
|
+
};
|
|
30
|
+
/** What an invocation's closure is handed. Everything in it is this invocation's, and ends with the closure. */
|
|
31
|
+
export type Pi<Tool extends ToolRegistration = ToolRegistration> = {
|
|
32
|
+
/**
|
|
33
|
+
* This invocation's tools, the `tools` option's already in it. Install more before the first `ask` or
|
|
34
|
+
* `harness()`: from then on pi may run again a tool call a crash cut off (once its scheduler runs, at `ask`'s
|
|
35
|
+
* submit), and a call whose tool it does not find then ends as interrupted ("may have partially run").
|
|
36
|
+
*/
|
|
37
|
+
readonly registry: Registry<Tool>;
|
|
38
|
+
/**
|
|
39
|
+
* Asks `message` in the root conversation and returns the text of the submission's answer. The message is submitted
|
|
40
|
+
* under `options.requestId`, by default the invocation id, so a retry finds its submission and waits for its run.
|
|
41
|
+
* One id is one submission: an id the conversation already holds, in this attempt or from another invocation,
|
|
42
|
+
* returns that submission's answer, without storing `message`. To ask again in one invocation, pass another
|
|
43
|
+
* `requestId`. A run that does not end `done` is a `TerminalError` whose message is `unanswered: <pi's reason>`;
|
|
44
|
+
* pi's detail (the provider's message), up to 1000 characters, is on a span `withPi.ask` of the invocation.
|
|
45
|
+
*/
|
|
46
|
+
readonly ask: (message: string, options?: AskOptions) => Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* The root conversation's messages, `[]` before its first turn. Read through a read-only Harness, which runs
|
|
49
|
+
* nothing, unless this invocation has opened pi for writing already. Opening pi's storage commits its migrations on
|
|
50
|
+
* a key never written, and the writer row (left.ts) after a closure of this attempt that opened pi for writing and
|
|
51
|
+
* wrote nothing.
|
|
52
|
+
*/
|
|
53
|
+
readonly messages: () => Promise<readonly Message[]>;
|
|
54
|
+
/**
|
|
55
|
+
* pi's Harness, opened for writing: model requests and tool calls kept alive and stopped by the stop signal, no
|
|
56
|
+
* restart limit unless `settings` give one, and a run another invocation left aborted. `ask` uses the same one.
|
|
57
|
+
*/
|
|
58
|
+
readonly harness: () => Promise<Harness>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* pi on the key's database, for each invocation's closure:
|
|
62
|
+
*
|
|
63
|
+
* const pi = withPi({ models, agent: { model }, tools: (ctx) => [transfer(ctx)] });
|
|
64
|
+
*
|
|
65
|
+
* chat: (ctx, message: string) => pi(ctx, ({ ask }) => ask(message)),
|
|
66
|
+
* history: (ctx) => pi(ctx, ({ messages }) => messages()),
|
|
67
|
+
*
|
|
68
|
+
* The closure gets a fresh `registry`, `ask`, `messages` and `harness` (see `Pi`); a tool decided per call is
|
|
69
|
+
* installed in its `registry`. Nothing is opened until one of them is used, and whatever was opened is closed when
|
|
70
|
+
* the closure ends, however it ends.
|
|
71
|
+
*/
|
|
72
|
+
export declare function withPi<Tool extends ToolRegistration = ToolRegistration>(options: PiOptions<Tool>): <T>(ctx: restate.SessionContext, work: (pi: Pi<Tool>) => T | Promise<T>) => Promise<T>;
|
|
73
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/pi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Q,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C,CAAC;AAgCF;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,IAAI,SAAS,gBAAgB,GAAG,gBAAgB,EAAE,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,IAEjF,CAAC,OAAO,OAAO,CAAC,cAAc,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC,CA4ElG"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// `withPi`: pi on a session object, configured once at module scope, and
|
|
2
|
+
// handed to each invocation's closure as a fresh registry, `ask`, `messages`
|
|
3
|
+
// and pi's own Harness. The Harness is opened on first use, with the wiring
|
|
4
|
+
// pi/index.ts describes, and closed when the closure ends.
|
|
5
|
+
import { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';
|
|
6
|
+
// pi-ai's subpath, as pi-durable imports it: its root index loads every provider.
|
|
7
|
+
import { contentText } from '@earendil-works/pi-ai/utils/text';
|
|
8
|
+
import { createRegistry, defineExtension, Harness, ROOT_CONVERSATION_ID, } from '@earendil-works/pi-durable';
|
|
9
|
+
import * as restate from '@restatedev/sessions';
|
|
10
|
+
import { keptModels } from './keepalive.js';
|
|
11
|
+
import { abortLeft } from './left.js';
|
|
12
|
+
import { openSqlKvStorage } from './storage.js';
|
|
13
|
+
import { keptTools } from './tools.js';
|
|
14
|
+
/** The name of the extension that holds the `tools` option's tools. */
|
|
15
|
+
const TOOLS = 'withPi.tools';
|
|
16
|
+
/** The longest provider's message a failed turn's span carries, in characters. */
|
|
17
|
+
const DETAIL = 1000;
|
|
18
|
+
/**
|
|
19
|
+
* The `TerminalError` of a turn that settled `unanswered`: pi's reason only. pi's detail (the provider's message,
|
|
20
|
+
* which can echo what the request carried) goes to the trace instead: a span `withPi.ask`, opened for nothing but
|
|
21
|
+
* this, ends with an error that says the reason and the detail, bounded.
|
|
22
|
+
*/
|
|
23
|
+
async function unanswered(ctx, reason, detail) {
|
|
24
|
+
const said = `unanswered: ${reason}`;
|
|
25
|
+
const text = detail === undefined ? '' : typeof detail === 'string' ? detail : JSON.stringify(detail);
|
|
26
|
+
const bounded = text.length > DETAIL ? `${text.slice(0, DETAIL)}…` : text;
|
|
27
|
+
await ctx
|
|
28
|
+
.span('withPi.ask', () => Promise.reject(new Error(bounded === '' ? said : `${said}: ${bounded}`)))
|
|
29
|
+
.catch(() => undefined);
|
|
30
|
+
return new restate.TerminalError(said);
|
|
31
|
+
}
|
|
32
|
+
/** `options` with model requests and tool calls kept alive, and no restart limit unless the author gives one. */
|
|
33
|
+
function kept(ctx, options) {
|
|
34
|
+
const { models, settings } = options;
|
|
35
|
+
// pi reads a function's models at each use: wrap each `Models` once.
|
|
36
|
+
const wrapped = new WeakMap();
|
|
37
|
+
const keep = (m) => wrapped.get(m) ?? wrapped.set(m, keptModels(ctx, m)).get(m);
|
|
38
|
+
return {
|
|
39
|
+
...options,
|
|
40
|
+
models: typeof models === 'function' ? () => keep(models()) : keep(models),
|
|
41
|
+
registry: keptTools(ctx, options.registry),
|
|
42
|
+
settings: typeof settings === 'function'
|
|
43
|
+
? () => {
|
|
44
|
+
const given = settings();
|
|
45
|
+
return { ...given, restartLimit: given?.restartLimit ?? Infinity };
|
|
46
|
+
}
|
|
47
|
+
: { ...settings, restartLimit: settings?.restartLimit ?? Infinity },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The root conversation's messages in `harness`, `[]` if it has none. */
|
|
51
|
+
async function rootMessages(harness, context) {
|
|
52
|
+
// Not `harness.root`, which would create the conversation: a read-only Harness refuses that.
|
|
53
|
+
const root = await harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
54
|
+
return root ? (await root.context(context)).messages : [];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* pi on the key's database, for each invocation's closure:
|
|
58
|
+
*
|
|
59
|
+
* const pi = withPi({ models, agent: { model }, tools: (ctx) => [transfer(ctx)] });
|
|
60
|
+
*
|
|
61
|
+
* chat: (ctx, message: string) => pi(ctx, ({ ask }) => ask(message)),
|
|
62
|
+
* history: (ctx) => pi(ctx, ({ messages }) => messages()),
|
|
63
|
+
*
|
|
64
|
+
* The closure gets a fresh `registry`, `ask`, `messages` and `harness` (see `Pi`); a tool decided per call is
|
|
65
|
+
* installed in its `registry`. Nothing is opened until one of them is used, and whatever was opened is closed when
|
|
66
|
+
* the closure ends, however it ends.
|
|
67
|
+
*/
|
|
68
|
+
export function withPi(options) {
|
|
69
|
+
const { tools, agent, context = BACKGROUND_CONTEXT, ...open } = options;
|
|
70
|
+
return async (ctx, work) => {
|
|
71
|
+
const registry = createRegistry();
|
|
72
|
+
if (tools !== undefined)
|
|
73
|
+
registry.install(defineExtension({ name: TOOLS, tools: tools(ctx) }));
|
|
74
|
+
let ended = false;
|
|
75
|
+
let writer;
|
|
76
|
+
const live = () => {
|
|
77
|
+
if (ended)
|
|
78
|
+
throw new Error('withPi: this invocation has ended; use pi inside its closure');
|
|
79
|
+
};
|
|
80
|
+
const harness = async () => {
|
|
81
|
+
live();
|
|
82
|
+
writer ??= (async () => {
|
|
83
|
+
const opened = await Harness.open(await openSqlKvStorage(ctx.db), kept(ctx, { ...open, registry }), context);
|
|
84
|
+
try {
|
|
85
|
+
await abortLeft(ctx, opened, context);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
await opened.close(context);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
return opened;
|
|
92
|
+
})();
|
|
93
|
+
return writer;
|
|
94
|
+
};
|
|
95
|
+
const pi = {
|
|
96
|
+
registry,
|
|
97
|
+
harness,
|
|
98
|
+
ask: async (message, given) => {
|
|
99
|
+
live();
|
|
100
|
+
const requestId = given?.requestId ?? ctx.request.id;
|
|
101
|
+
const root = await (await harness()).root(context, { agent });
|
|
102
|
+
const submission = await root.submit({ type: 'input', content: message, requestId }, context);
|
|
103
|
+
const settled = await submission.wait(context);
|
|
104
|
+
if (settled.type !== 'input' || settled.status !== 'done') {
|
|
105
|
+
throw await unanswered(ctx, settled.reason ?? settled.status, settled.detail);
|
|
106
|
+
}
|
|
107
|
+
// The submission's answer: the reply that settled it, read back through pi's storage.
|
|
108
|
+
const { items } = await root.entries({ minEntryId: settled.answer, maxEntryId: settled.answer }, 1, undefined, context);
|
|
109
|
+
const reply = items[0]?.model?.findLast((m) => m.role === 'assistant');
|
|
110
|
+
if (reply === undefined)
|
|
111
|
+
throw new Error(`withPi: pi stored no reply as the answer ${settled.answer}`);
|
|
112
|
+
return contentText(reply.content, '');
|
|
113
|
+
},
|
|
114
|
+
messages: async () => {
|
|
115
|
+
live();
|
|
116
|
+
if (writer !== undefined)
|
|
117
|
+
return rootMessages(await writer, context);
|
|
118
|
+
const reader = await Harness.open(await openSqlKvStorage(ctx.db), { ...open, registry, readOnly: true }, context);
|
|
119
|
+
try {
|
|
120
|
+
return await rootMessages(reader, context);
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
await reader.close(context);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
const end = async () => {
|
|
128
|
+
ended = true;
|
|
129
|
+
const opened = await writer?.catch(() => undefined);
|
|
130
|
+
await opened?.close(context);
|
|
131
|
+
};
|
|
132
|
+
let result;
|
|
133
|
+
try {
|
|
134
|
+
result = await work(pi);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// The closure's error is the invocation's: a close that fails too does not replace it.
|
|
138
|
+
await end().catch(() => undefined);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
await end();
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/pi/factory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,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uFAAuF;YACvF,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,GAAG,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/pi/index.d.ts
CHANGED
|
@@ -1,130 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { type Items } from '../conversation.ts';
|
|
7
|
-
import { type Answer } from '../output.ts';
|
|
8
|
-
import { type Definition } from '../object.ts';
|
|
9
|
-
import { type Tool as AnyTool } from '../tools.ts';
|
|
10
|
-
import type { z } from 'zod';
|
|
11
|
-
import { type Commits } from './storage.ts';
|
|
12
|
-
/** What `work` gets: `prompt(text)`, the `conversation()`, and the `harness` and chord `context` for anything else. */
|
|
13
|
-
export interface Pi {
|
|
14
|
-
harness: Harness;
|
|
15
|
-
context: Context;
|
|
16
|
-
/**
|
|
17
|
-
* Answer `text`, once, with the answer's text: a turn of the object's
|
|
18
|
-
* conversation (each prompt of an invocation has an id of its own, the
|
|
19
|
-
* same on every attempt). With `check`, a reply it returns a message for
|
|
20
|
-
* is asked again within the turn, once. With `reminder`, the model is told
|
|
21
|
-
* it after the prompt, which the conversation keeps as it was asked.
|
|
22
|
-
*/
|
|
23
|
-
prompt: (text: string, check?: Check, reminder?: string) => Promise<string>;
|
|
24
|
-
/** The object's conversation, on the model: for `reset`, `compact`, `entries` and the like. */
|
|
25
|
-
conversation: () => Promise<Conversation>;
|
|
26
|
-
}
|
|
27
|
-
/** A pi message as the conversation of turns keeps it: with the id of the pi entry it was copied from. */
|
|
28
|
-
export interface Item {
|
|
29
|
-
entry?: number;
|
|
30
|
-
message: Message;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* pi's items: pi-ai's messages. A user's message is said by the user; an
|
|
34
|
-
* assistant's (but one aborted, failed or deferred) says its text, with its
|
|
35
|
-
* tool calls; a tool's result is a result; a system message says nothing.
|
|
36
|
-
*/
|
|
37
|
-
export declare const items: Items<Item>;
|
|
38
|
-
/** An agent's options: `chat`, `prompt` and `withPi` take them. */
|
|
39
|
-
export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
|
|
40
|
-
/** The model, as `provider/model-id`: MODEL, or else openai/gpt-6-sol. */
|
|
41
|
-
model?: string;
|
|
42
|
-
/** A pi-ai model registry; by default, one of the model's provider. */
|
|
43
|
-
models?: MutableModels;
|
|
44
|
-
/** The system prompt: who the agent is, and how it answers. */
|
|
45
|
-
system?: string;
|
|
46
|
-
/** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or pi-durable's `defineTool`s. */
|
|
47
|
-
tools?: (ToolRegistration | AnyTool)[];
|
|
48
|
-
/** A directory for the coding tools, made if missing; without one, the agent has no file system. */
|
|
49
|
-
workspace?: string;
|
|
50
|
-
/** OpenAI's service tier for each request: `fast` for its fast mode (priced higher), `flex`, and so on. */
|
|
51
|
-
serviceTier?: ServiceTier;
|
|
52
|
-
/**
|
|
53
|
-
* How pi asks the model again after a request failed for a reason that
|
|
54
|
-
* passes (an overloaded or unreachable provider, a rate limit): by
|
|
55
|
-
* default without limit, 2 s after the first failure, then twice as long
|
|
56
|
-
* each time, a minute apart at most. With `maxRetries`, a failure after
|
|
57
|
-
* that many retries ends the turn. A request refused for good (a wrong API
|
|
58
|
-
* key, an unknown model) is never asked again.
|
|
59
|
-
*/
|
|
60
|
-
retry?: Partial<ConversationRetryPolicy>;
|
|
61
|
-
/**
|
|
62
|
-
* How pi's commits are written: `'each'` (the default), one write to
|
|
63
|
-
* Restate each, or `'effects'`, one for all the commits between two effects
|
|
64
|
-
* (a model call, a tool call), so that a step of a turn costs about one
|
|
65
|
-
* write, not several. With `'effects'`, what pi commits in the milliseconds
|
|
66
|
-
* between one effect's result and the next effect's start is lost in a
|
|
67
|
-
* crash, and the retry does it again from the same stored state; what
|
|
68
|
-
* others see (a publish, a call, a send, the end of the handler) is
|
|
69
|
-
* written first.
|
|
70
|
-
*/
|
|
71
|
-
commits?: Commits;
|
|
72
|
-
/**
|
|
73
|
-
* The answer as data: a zod object, whose JSON the agent replies with
|
|
74
|
-
* (checked), and `chat` and `prompt` answer with (see output.ts).
|
|
75
|
-
*/
|
|
76
|
-
output?: O;
|
|
77
|
-
}
|
|
78
|
-
export type { Commits };
|
|
79
|
-
/** OpenAI's service tiers (its Responses API's `service_tier`). */
|
|
80
|
-
export type ServiceTier = 'auto' | 'default' | 'fast' | 'flex' | 'priority';
|
|
81
|
-
/**
|
|
82
|
-
* Run `work(pi)` with a Harness over the object's database: `model` is the
|
|
83
|
-
* model to use as `provider/model-id`, and `tools` the agent's tools. `pi`
|
|
84
|
-
* has `prompt(text)`, and the `harness` and chord `context` for anything
|
|
85
|
-
* else.
|
|
86
|
-
*/
|
|
87
|
-
export declare const withPi: <T>(ctx: restate.SessionContext, { model: named, models, system, tools, workspace, serviceTier, retry, commits, }: Options, work: (pi: Pi) => Promise<T>) => Promise<T>;
|
|
88
|
-
/**
|
|
89
|
-
* Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
|
|
90
|
-
* of an invocation is a prompt of its own.
|
|
91
|
-
* With `output`, it answers with the value the agent replies with (see
|
|
92
|
-
* output.ts), not its text.
|
|
93
|
-
*/
|
|
94
|
-
export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
|
|
95
|
-
/**
|
|
96
|
-
* A chat handler: each message an invocation, the conversation in the
|
|
97
|
-
* object's database, with `options`, or the options a function of the
|
|
98
|
-
* invocation's context gives (each user's model, say). It takes the message
|
|
99
|
-
* as plain text (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
|
|
100
|
-
*/
|
|
101
|
-
export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
|
|
102
|
-
input: restate.Serde<string>;
|
|
103
|
-
accept: string;
|
|
104
|
-
explicitCancellation: boolean;
|
|
105
|
-
handler: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* A view of the conversation as clients read it: a page at a time, or what
|
|
109
|
-
* is new or changed since a cursor; `view: 'summary'` for each turn's
|
|
110
|
-
* message and answer. It answers while a message is answered.
|
|
111
|
-
*/
|
|
112
|
-
export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
113
|
-
/** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
|
|
114
|
-
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, {
|
|
115
|
-
signal: (ctx: import("../common.ts").AgentViewContext, signal: import("../companion.ts").Signal) => Promise<import("../companion.ts").Resolved>;
|
|
116
|
-
pending: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Waiting[]>;
|
|
117
|
-
status: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Status>;
|
|
118
|
-
stop: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
119
|
-
notifications: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../companion.ts").Notifications>;
|
|
120
|
-
watch: (ctx: import("../common.ts").AgentViewContext, watch: import("../companion.ts").Watch) => Promise<import("../companion.ts").Notifications>;
|
|
121
|
-
} & {
|
|
122
|
-
clear: (ctx: import("../common.ts").AgentViewContext) => Promise<import("../object.ts").Stopped>;
|
|
123
|
-
steer: (ctx: import("../common.ts").AgentViewContext, text: string) => Promise<import("../companion.ts").Steered>;
|
|
124
|
-
sync: (ctx: import("../common.ts").AgentViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
|
|
125
|
-
} & {
|
|
126
|
-
chat: (ctx: import("../common.ts").AgentContext, text: string) => Promise<Answer<O>>;
|
|
127
|
-
} & {
|
|
128
|
-
messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
|
|
129
|
-
}>;
|
|
1
|
+
export { openSqlKvStorage, SqlKvDatabase } from './storage.ts';
|
|
2
|
+
export { keptModels } from './keepalive.ts';
|
|
3
|
+
export { keptTools } from './tools.ts';
|
|
4
|
+
export { abortLeft } from './left.ts';
|
|
5
|
+
export { withPi, type AskOptions, type Pi, type PiOptions } from './factory.ts';
|
|
130
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/pi/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pi/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pi/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC"}
|