@restatedev/agents 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +672 -2
  3. package/dist/calls.d.ts +29 -0
  4. package/dist/calls.d.ts.map +1 -0
  5. package/dist/calls.js +91 -0
  6. package/dist/calls.js.map +1 -0
  7. package/dist/claude/conversation.d.ts +33 -0
  8. package/dist/claude/conversation.d.ts.map +1 -0
  9. package/dist/claude/conversation.js +95 -0
  10. package/dist/claude/conversation.js.map +1 -0
  11. package/dist/claude/index.d.ts +77 -0
  12. package/dist/claude/index.d.ts.map +1 -0
  13. package/dist/claude/index.js +269 -0
  14. package/dist/claude/index.js.map +1 -0
  15. package/dist/client.d.ts +81 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +88 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/common.d.ts +261 -0
  20. package/dist/common.d.ts.map +1 -0
  21. package/dist/common.js +438 -0
  22. package/dist/common.js.map +1 -0
  23. package/dist/deepseek/index.d.ts +68 -0
  24. package/dist/deepseek/index.d.ts.map +1 -0
  25. package/dist/deepseek/index.js +363 -0
  26. package/dist/deepseek/index.js.map +1 -0
  27. package/dist/deepseek/persistence.d.ts +61 -0
  28. package/dist/deepseek/persistence.d.ts.map +1 -0
  29. package/dist/deepseek/persistence.js +224 -0
  30. package/dist/deepseek/persistence.js.map +1 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +12 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/langgraph/checkpointer.d.ts +29 -0
  36. package/dist/langgraph/checkpointer.d.ts.map +1 -0
  37. package/dist/langgraph/checkpointer.js +275 -0
  38. package/dist/langgraph/checkpointer.js.map +1 -0
  39. package/dist/langgraph/index.d.ts +66 -0
  40. package/dist/langgraph/index.d.ts.map +1 -0
  41. package/dist/langgraph/index.js +265 -0
  42. package/dist/langgraph/index.js.map +1 -0
  43. package/dist/log.d.ts +29 -0
  44. package/dist/log.d.ts.map +1 -0
  45. package/dist/log.js +145 -0
  46. package/dist/log.js.map +1 -0
  47. package/dist/object.d.ts +169 -0
  48. package/dist/object.d.ts.map +1 -0
  49. package/dist/object.js +221 -0
  50. package/dist/object.js.map +1 -0
  51. package/dist/opencode/db.d.ts +40 -0
  52. package/dist/opencode/db.d.ts.map +1 -0
  53. package/dist/opencode/db.js +161 -0
  54. package/dist/opencode/db.js.map +1 -0
  55. package/dist/opencode/index.d.ts +100 -0
  56. package/dist/opencode/index.d.ts.map +1 -0
  57. package/dist/opencode/index.js +436 -0
  58. package/dist/opencode/index.js.map +1 -0
  59. package/dist/output.d.ts +17 -0
  60. package/dist/output.d.ts.map +1 -0
  61. package/dist/output.js +81 -0
  62. package/dist/output.js.map +1 -0
  63. package/dist/pi/index.d.ts +89 -0
  64. package/dist/pi/index.d.ts.map +1 -0
  65. package/dist/pi/index.js +293 -0
  66. package/dist/pi/index.js.map +1 -0
  67. package/dist/pi/storage.d.ts +5 -0
  68. package/dist/pi/storage.d.ts.map +1 -0
  69. package/dist/pi/storage.js +41 -0
  70. package/dist/pi/storage.js.map +1 -0
  71. package/dist/signals.d.ts +154 -0
  72. package/dist/signals.d.ts.map +1 -0
  73. package/dist/signals.js +256 -0
  74. package/dist/signals.js.map +1 -0
  75. package/dist/tools.d.ts +158 -0
  76. package/dist/tools.d.ts.map +1 -0
  77. package/dist/tools.js +211 -0
  78. package/dist/tools.js.map +1 -0
  79. package/dist/webhook.d.ts +71 -0
  80. package/dist/webhook.d.ts.map +1 -0
  81. package/dist/webhook.js +102 -0
  82. package/dist/webhook.js.map +1 -0
  83. package/package.json +218 -5
  84. package/src/calls.ts +138 -0
  85. package/src/claude/README.md +84 -0
  86. package/src/claude/conversation.ts +114 -0
  87. package/src/claude/index.ts +364 -0
  88. package/src/client.ts +176 -0
  89. package/src/common.ts +550 -0
  90. package/src/deepseek/README.md +110 -0
  91. package/src/deepseek/index.ts +464 -0
  92. package/src/deepseek/persistence.ts +293 -0
  93. package/src/index.ts +24 -0
  94. package/src/langgraph/README.md +87 -0
  95. package/src/langgraph/checkpointer.ts +364 -0
  96. package/src/langgraph/index.ts +349 -0
  97. package/src/log.ts +193 -0
  98. package/src/object.ts +319 -0
  99. package/src/opencode/README.md +125 -0
  100. package/src/opencode/db.ts +223 -0
  101. package/src/opencode/index.ts +559 -0
  102. package/src/output.ts +95 -0
  103. package/src/pi/README.md +105 -0
  104. package/src/pi/index.ts +382 -0
  105. package/src/pi/storage.ts +65 -0
  106. package/src/signals.ts +386 -0
  107. package/src/tools.ts +343 -0
  108. package/src/webhook.ts +161 -0
package/dist/output.js ADDED
@@ -0,0 +1,81 @@
1
+ // An agent's answer as data, with `output` (every framework's option): a zod
2
+ // object schema. The agent's reply is its answer, as JSON: the system prompt
3
+ // asks for it, with the schema, and each prompt again, at its end; the reply
4
+ // is checked against it. The
5
+ // prompt (and so `chat`) then answers with the value, as an RPC answers.
6
+ //
7
+ // const planner = claude.agent({ name: 'planner', output: Plan }); // chat answers with a Plan
8
+ //
9
+ // The JSON may be in a code fence, or after a sentence. A reply that is not
10
+ // such JSON is answered with what is wrong with it, once, for the agent to
11
+ // answer again; then the prompt fails (a terminal error), saying how the
12
+ // reply starts. A retried attempt resumes the conversation, so it reads the
13
+ // same reply.
14
+ import * as restate from '@restatedev/sessions';
15
+ import { z } from 'zod';
16
+ /** What the system prompt asks for, with `output`: JSON of its schema, and nothing else. */
17
+ const format = (output) => 'Your final reply is your answer, as JSON only (no other text): an object of this JSON schema.\n' +
18
+ JSON.stringify(z.toJSONSchema(output));
19
+ /**
20
+ * What each prompt ends with, with `output`: the system prompt's ask, again,
21
+ * where an agent reads it last (after a long run of tool calls, it may have
22
+ * drifted from its system prompt to a summary in prose).
23
+ */
24
+ const reminder = '\n\nWhen you are done, reply with your answer as JSON only, of the schema you were given: no other text.';
25
+ /**
26
+ * The JSON `reply` holds: all of it, what a code fence (```json) holds, or
27
+ * else its object, from its first `{` to its last `}` (a model that ends a
28
+ * long run often says a sentence first: "Done. Here is the summary: {...}").
29
+ */
30
+ function jsonOf(reply) {
31
+ const fenced = /```(?:json)?\s*\n([^]*?)\n?```/.exec(reply)?.[1];
32
+ const object = reply.slice(reply.indexOf('{'), reply.lastIndexOf('}') + 1);
33
+ for (const text of [reply, fenced, object]) {
34
+ try {
35
+ if (text?.trim())
36
+ return JSON.parse(text);
37
+ }
38
+ catch {
39
+ // the next
40
+ }
41
+ }
42
+ return undefined;
43
+ }
44
+ /** The start of `reply`, for an error. */
45
+ const excerpt = (reply) => (reply.length > 300 ? `${reply.slice(0, 300)}…` : reply);
46
+ /** `reply` as a value of `output`, or what is wrong with it. */
47
+ function parsed(output, reply) {
48
+ if (!reply.trim())
49
+ return { wrong: 'it is empty' };
50
+ const json = jsonOf(reply);
51
+ if (json === undefined)
52
+ return { wrong: `it is not JSON: ${JSON.stringify(excerpt(reply))}` };
53
+ const result = output.safeParse(json);
54
+ return result.success ? { value: result.data } : { wrong: z.prettifyError(result.error) };
55
+ }
56
+ /**
57
+ * Answer `text` with a value of `output`: the agent's reply to it, parsed;
58
+ * one that is not is answered with what is wrong, once, for another reply.
59
+ */
60
+ export async function answerWith(text, output, prompt) {
61
+ let answer = parsed(output, await prompt(text));
62
+ if ('wrong' in answer) {
63
+ const again = `Your reply is not the answer asked for: ${answer.wrong}\nReply again, with the JSON only.`;
64
+ answer = parsed(output, await prompt(again));
65
+ }
66
+ if ('wrong' in answer)
67
+ throw new restate.TerminalError(`The agent's reply is not the answer asked for: ${answer.wrong}`);
68
+ return answer.value;
69
+ }
70
+ /**
71
+ * `prompt` (a framework's, of `options`), answering with a value of
72
+ * `options.output` if it has one, or else with the agent's text.
73
+ */
74
+ export const withOutput = (text, options, prompt) => {
75
+ const { output } = options;
76
+ if (!output)
77
+ return prompt(text, options);
78
+ const asked = { ...options, system: [options.system, format(output)].filter(Boolean).join('\n\n') };
79
+ return answerWith(text + reminder, output, (t) => prompt(t, asked));
80
+ };
81
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,6BAA6B;AAC7B,yEAAyE;AACzE,EAAE;AACF,mGAAmG;AACnG,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,cAAc;AACd,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,4FAA4F;AAC5F,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAE,EAAE,CACrC,iGAAiG;IACjG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAEzC;;;;GAIG;AACH,MAAM,QAAQ,GACZ,0GAA0G,CAAC;AAE7G;;;;GAIG;AACH,SAAS,MAAM,CAAC,KAAa;IAC3B,MAAM,MAAM,GAAG,gCAAgC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3E,KAAK,MAAM,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC;YACH,IAAI,IAAI,EAAE,IAAI,EAAE;gBAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,0CA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AM;QACnB,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,kDAAkD,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACpG,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAY,EACZ,OAAU,EACV,MAAqD,EACvB,EAAE;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC,IAAI,EAAE,OAAO,CAAiC,CAAC;IAC1E,MAAM,KAAK,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACpG,OAAO,UAAU,CAAC,IAAI,GAAG,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAiC,CAAC;AACtG,CAAC,CAAC"}
@@ -0,0 +1,89 @@
1
+ import * as restate from '@restatedev/sessions';
2
+ import type { Context } from '@earendil-works/chord';
3
+ import { type MutableModels } from '@earendil-works/pi-ai';
4
+ import { Harness, type Conversation, type ToolRegistration } from '@earendil-works/pi-durable';
5
+ import { type Configure } from '../common.ts';
6
+ import { type Answer } from '../output.ts';
7
+ import { type Definition } from '../object.ts';
8
+ import { type Tool as AnyTool } from '../tools.ts';
9
+ import type { z } from 'zod';
10
+ /** What `work` gets: `prompt(text)`, the `conversation()`, and the `harness` and chord `context` for anything else. */
11
+ export interface Pi {
12
+ harness: Harness;
13
+ context: Context;
14
+ /** Answer `text`, once per prompt `id`, with the answer's text. By default, each prompt of an invocation has an id of its own, the same on every attempt. */
15
+ prompt: (text: string, id?: string) => Promise<string>;
16
+ /** The object's conversation, on the model: for `reset`, `compact`, `entries` and the like. */
17
+ conversation: () => Promise<Conversation>;
18
+ }
19
+ /** An agent's options: `chat`, `prompt` and `withPi` take them. */
20
+ export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
21
+ /** The model, as `provider/model-id`: MODEL, or else openai/gpt-6-sol. */
22
+ model?: string;
23
+ /** A pi-ai model registry; by default, one of the model's provider. */
24
+ models?: MutableModels;
25
+ /** The system prompt: who the agent is, and how it answers. */
26
+ system?: string;
27
+ /** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or pi-durable's `defineTool`s. */
28
+ tools?: (ToolRegistration | AnyTool)[];
29
+ /** A directory for the coding tools, made if missing; without one, the agent has no file system. */
30
+ workspace?: string;
31
+ /** OpenAI's service tier for each request: `fast` for its fast mode (priced higher), `flex`, and so on. */
32
+ serviceTier?: ServiceTier;
33
+ /**
34
+ * The answer as data: a zod object, whose JSON the agent replies with
35
+ * (checked), and `chat` and `prompt` answer with (see output.ts).
36
+ */
37
+ output?: O;
38
+ }
39
+ /** OpenAI's service tiers (its Responses API's `service_tier`). */
40
+ export type ServiceTier = 'auto' | 'default' | 'fast' | 'flex' | 'priority';
41
+ /**
42
+ * Run `work(pi)` with a Harness over the object's database: `model` is the
43
+ * model to use as `provider/model-id`, and `tools` the agent's tools. `pi`
44
+ * has `prompt(text)`, and the `harness` and chord `context` for anything
45
+ * else.
46
+ */
47
+ export declare const withPi: <T>(ctx: restate.SessionContext, { model: named, models, system, tools, workspace, serviceTier }: Options, work: (pi: Pi) => Promise<T>) => Promise<T>;
48
+ /**
49
+ * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
50
+ * of an invocation is a prompt of its own.
51
+ * With `output`, it answers with the value the agent replies with (see
52
+ * output.ts), not its text.
53
+ */
54
+ export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
55
+ /**
56
+ * A chat handler: each message an invocation, the conversation in the
57
+ * object's database, with `options`, or the options a function of the
58
+ * invocation's context gives (each user's model, say). It takes the message
59
+ * as plain text (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
60
+ */
61
+ export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
62
+ input: restate.Serde<string>;
63
+ accept: string;
64
+ explicitCancellation: boolean;
65
+ handler: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
66
+ };
67
+ /**
68
+ * A handler of the conversation as clients read it: a page at a time, or
69
+ * what is new or changed since a cursor, from the log each change writes
70
+ * (log.ts). It answers while a message is answered.
71
+ */
72
+ export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
73
+ /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
74
+ export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
75
+ signal: (ctx: restate.ViewContext, signal: import("../signals.ts").Signal) => Promise<import("../signals.ts").Resolved>;
76
+ pending: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Waiting[]>;
77
+ status: (ctx: restate.ViewContext) => Promise<import("../object.ts").Status>;
78
+ stop: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
79
+ notifications: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Notifications>;
80
+ watch: (ctx: restate.ViewContext, watch: import("../signals.ts").Watch) => Promise<import("../signals.ts").Notifications>;
81
+ } & {
82
+ clear: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
83
+ sync: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
84
+ } & {
85
+ chat: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
86
+ } & {
87
+ messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts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293 @@
1
+ // pi agents in Restate virtual objects: a pi-durable Harness for each
2
+ // invocation, with its storage in the object's database.
3
+ //
4
+ // const assistant = pi.agent({ name: 'assistant', tools: [weather] });
5
+ // const lead = pi.agent({ name: 'lead', tools: [subagent(coder)] });
6
+ //
7
+ // or a handler of an object of your own: `handlers: { chat: pi.chat() }`,
8
+ // with options for each invocation: `pi.chat(async (ctx) => ({ model }))`
9
+ //
10
+ // or, for more than a prompt:
11
+ //
12
+ // compact: (ctx) => withPi(ctx, { tools }, async ({ conversation, context }) => ...),
13
+ //
14
+ // The model is `model`, MODEL, or else openai/gpt-6-sol, with the
15
+ // provider's API key (such as OPENAI_API_KEY).
16
+ //
17
+ // It runs `work` over `ctx.db`: pi-durable's storage is the object's
18
+ // database (storage.ts), and each pi-durable commit is an SQL transaction
19
+ // in it, stored in order with everything else the handler does. The Harness
20
+ // is opened with `tools` (made with pi-durable's `defineTool`) and closed at
21
+ // the end. A retried attempt (a crash, a lost connection) opens it again and
22
+ // carries on: a prompt is submitted once, by its id (pi-durable's requestId),
23
+ // an answered prompt returns its answer, and unfinished work resumes: a model
24
+ // call is made again, and a tool call declared `replay: 'safe'` runs again
25
+ // with the same call id, which a tool passes on to stay idempotent. A tool's
26
+ // error fails the attempt, which Restate retries (pi-durable would hand it to
27
+ // the model as the tool's result).
28
+ //
29
+ // With a `workspace` directory, the agent also gets pi-durable's coding
30
+ // tools (`read`, `write`, `edit`, `bash`) over it, on the local file system.
31
+ // The files are not in the database: they last as long as the disk does,
32
+ // and a coding tool cut off by a crash is not run again (the model is told
33
+ // it was interrupted).
34
+ import * as restate from '@restatedev/sessions';
35
+ import { awaitWithContext, BACKGROUND_CONTEXT, withCancel, withoutAbortSignal } from '@earendil-works/chord/context';
36
+ import { mkdir } from 'node:fs/promises';
37
+ import { Type } from '@earendil-works/pi-ai';
38
+ import { createModels } from '@earendil-works/pi-ai/models';
39
+ import { builtinProviders } from '@earendil-works/pi-ai/providers/all';
40
+ import { AssistantEntry, createRegistry, defineExtension, defineTool, Harness, section, } from '@earendil-works/pi-durable';
41
+ import { NodeExecutionEnv } from '@earendil-works/pi-durable/env/node';
42
+ import { CodingTools } from '@earendil-works/pi-durable/tools';
43
+ import { AttemptEnded, chatHandler, CHECK_MODEL, checkModelName, configured, messagesHandler, ModelError, modelOf, nextPromptId, providerOf, refusal, REFUSED, stopSignalOf, toolCallEnded, toolCallStarted, transcribing, Transcript, } from '../common.js';
44
+ import { withOutput } from '../output.js';
45
+ import { sessionObject } from '../object.js';
46
+ import { isTool, jsonSchemaOf } from '../tools.js';
47
+ import { openSqlKvStorage } from './storage.js';
48
+ /** The text of a message's content. */
49
+ const textOf = (content) => typeof content === 'string' ? content : content.flatMap((c) => (c.type === 'text' ? [c.text] : [])).join('');
50
+ /** A registry of `provider`'s models, such as anthropicProvider() of @earendil-works/pi-ai/providers/anthropic. */
51
+ function modelsOf(provider) {
52
+ // All of pi-ai's providers, imported as they are named: one a bundler sees.
53
+ const known = builtinProviders().find((p) => p.id === provider);
54
+ if (!known)
55
+ throw new ModelError(`pi knows no model provider "${provider}": ${CHECK_MODEL}`);
56
+ const models = createModels();
57
+ models.setProvider(known);
58
+ return models;
59
+ }
60
+ /** `t` as a pi-durable tool. */
61
+ const native = (t, ctx) => defineTool({
62
+ name: t.name,
63
+ description: t.description,
64
+ parameters: Type.Unsafe(jsonSchemaOf(t)),
65
+ replay: 'safe', // a crash runs it again, with the same call id
66
+ // Aborted (the conversation's work, on a cancellation), it waits no more.
67
+ execute: async (args, { callId }, task) => ({
68
+ output: [{ type: 'text', text: await awaitWithContext(t.run(args, { ctx, callId }), task) }],
69
+ }),
70
+ });
71
+ /**
72
+ * The tools of an agent, `system` added to its system prompt, and, with a
73
+ * `workspace`, pi's coding tools working there, with the environment they
74
+ * run in.
75
+ */
76
+ async function extensions(tools, system, workspace) {
77
+ const registry = createRegistry();
78
+ registry.install(defineExtension({ name: 'tools', tools }));
79
+ if (system)
80
+ registry.install(defineExtension({ name: 'system', sections: [section('system', () => system)] }));
81
+ if (!workspace)
82
+ return { registry, env: undefined };
83
+ await mkdir(workspace, { recursive: true });
84
+ registry.install(CodingTools);
85
+ // Tell the model where the coding tools work.
86
+ registry.install(defineExtension({ name: 'workspace', sections: [section('cwd', () => workspace)] }));
87
+ return { registry, env: () => new NodeExecutionEnv({ cwd: workspace }) };
88
+ }
89
+ /**
90
+ * The root conversation of `harness`, on `model`. It keeps the model it was
91
+ * created with: on another one now (`model` or MODEL changed), it moves to
92
+ * this one.
93
+ */
94
+ async function rootOn(harness, context, model) {
95
+ const [provider, modelId] = providerOf(model);
96
+ const root = await harness.root(context, { agent: { model: { provider, modelId } } });
97
+ const { model: current } = await root.agent(context);
98
+ if (current?.provider !== provider || current.modelId !== modelId) {
99
+ await root.configure({ model: { provider, modelId } }, context);
100
+ }
101
+ return root;
102
+ }
103
+ /**
104
+ * The error of prompt `id`, which ended unanswered for `reason` (and
105
+ * `detail`, pi-durable's): {@link REFUSED} if there is no model, or its
106
+ * provider refused it, as for the other frameworks.
107
+ */
108
+ function unanswered(id, why, detail, model) {
109
+ const reason = why ?? 'unknown';
110
+ const text = detail === undefined || detail === null ? '' : typeof detail === 'string' ? detail : JSON.stringify(detail);
111
+ const message = `prompt ${id} unanswered: ${reason}${text ? `: ${text}` : ''}`;
112
+ if (reason === 'no_model' || (reason === 'model_error' && refusal(new Error(text)))) {
113
+ return new restate.TerminalError(`${message} (the model ${model}: ${CHECK_MODEL})`, { errorCode: REFUSED });
114
+ }
115
+ return new restate.TerminalError(message);
116
+ }
117
+ /**
118
+ * Run `work(pi)` with a Harness over the object's database: `model` is the
119
+ * model to use as `provider/model-id`, and `tools` the agent's tools. `pi`
120
+ * has `prompt(text)`, and the `harness` and chord `context` for anything
121
+ * else.
122
+ */
123
+ export const withPi = async (ctx, { model: named, models, system, tools = [], workspace, serviceTier }, work) => {
124
+ const model = modelOf(named);
125
+ models ??= modelsOf(providerOf(model)[0]);
126
+ // A tool's error fails the attempt, which Restate retries (pi-durable would
127
+ // hand it to the model): the work is cancelled, so the tool call stores no
128
+ // result, and the retry runs it again with the same call id.
129
+ const { context, cancel } = withCancel(BACKGROUND_CONTEXT);
130
+ const { promise: failure, reject: failed } = Promise.withResolvers();
131
+ failure.catch(() => { });
132
+ // A cancelled invocation, whenever it comes, aborts the conversation's
133
+ // work instead (abortOn): pi-durable ends the turn, and the tool call with
134
+ // it. An attempt that ends first cancels the work, as a tool's error does:
135
+ // the next attempt goes on with it.
136
+ let cancelled;
137
+ const turn = stopSignalOf(ctx);
138
+ const onStop = () => {
139
+ const reason = turn.reason;
140
+ failed(reason);
141
+ if (reason instanceof AttemptEnded)
142
+ cancel(reason);
143
+ else
144
+ cancelled = reason;
145
+ };
146
+ turn?.addEventListener('abort', onStop, { once: true });
147
+ // The root conversation, once the Harness is open (below).
148
+ const conversation = () => rootOn(harness, context, model);
149
+ // A tool call's error: the attempt fails, and the call never returns.
150
+ const stopped = (error, task) => {
151
+ // The turn was cancelled, and the abort ended the call: pi-durable records it.
152
+ if (cancelled)
153
+ throw error;
154
+ failed(error);
155
+ if (error instanceof restate.CancelledError) {
156
+ cancelled = error;
157
+ return awaitWithContext(new Promise(() => { }), task);
158
+ }
159
+ cancel(error);
160
+ return awaitWithContext(new Promise(() => { }), context);
161
+ };
162
+ const tracked = (t) => ({
163
+ ...t,
164
+ execute: async (args, api, task) => {
165
+ try {
166
+ await toolCallStarted(ctx);
167
+ const result = await t.execute(args, api, task);
168
+ await toolCallEnded(ctx);
169
+ return result;
170
+ }
171
+ catch (error) {
172
+ return stopped(error, task);
173
+ }
174
+ },
175
+ });
176
+ const { registry, env } = await extensions(tools.map((t) => tracked(isTool(t) ? native(t, ctx) : t)), system, workspace);
177
+ const settings = {
178
+ // A task that crashes is run again however often Restate retries the attempt (its retry policy decides):
179
+ // pi-durable would park it after 5 crashes in a row, and the prompt would never be answered.
180
+ restartLimit: Infinity,
181
+ // pi-durable hands its stream settings to pi-ai's requests as they are: serviceTier is pi-ai's.
182
+ ...(serviceTier ? { stream: { serviceTier } } : {}),
183
+ };
184
+ const harness = await Harness.open(await openSqlKvStorage(ctx.db), { models, registry, env, settings }, context);
185
+ const prompt = async (text, id = nextPromptId(ctx)) => {
186
+ const root = await conversation();
187
+ const submission = await root.submit({ type: 'input', content: text, requestId: id }, context);
188
+ const settled = await submission.wait(context);
189
+ // A prompt the cancellation's abort ended fails with the cancellation.
190
+ if (settled.status !== 'done' || settled.answer === undefined)
191
+ throw cancelled ?? unanswered(id, settled.reason, settled.detail, model);
192
+ const { answer } = settled;
193
+ const entry = await root.commit((tx) => tx.entry(AssistantEntry, answer), context);
194
+ const reply = entry?.model?.at(-1);
195
+ if (!reply)
196
+ throw new restate.TerminalError(`prompt ${id}: no answer entry`);
197
+ return textOf(reply.content);
198
+ };
199
+ // `failure`, once it comes; a cancellation first aborts the conversation's work.
200
+ const abortOn = async () => {
201
+ try {
202
+ return await failure;
203
+ }
204
+ catch (error) {
205
+ if (error instanceof restate.CancelledError)
206
+ await (await conversation()).abort(context);
207
+ throw error;
208
+ }
209
+ };
210
+ try {
211
+ // The log reads the root conversation through this Harness, while it is open.
212
+ const read = async () => transcribe(ctx.db, await harness.root(context), context);
213
+ return await transcribing(ctx, read, () => Promise.race([abortOn(), work({ harness, context, conversation, prompt })]));
214
+ }
215
+ finally {
216
+ turn?.removeEventListener('abort', onStop);
217
+ await harness.close(withoutAbortSignal(context));
218
+ }
219
+ };
220
+ /** {@link prompt}, answering with the agent's text. */
221
+ const promptText = (ctx, text, options) => withPi(ctx, options, (session) => session.prompt(text));
222
+ /**
223
+ * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
224
+ * of an invocation is a prompt of its own.
225
+ * With `output`, it answers with the value the agent replies with (see
226
+ * output.ts), not its text.
227
+ */
228
+ export const prompt = (ctx, text, options = {}) => withOutput(text, options, (t, o) => promptText(ctx, t, o));
229
+ /**
230
+ * A chat handler: each message an invocation, the conversation in the
231
+ * object's database, with `options`, or the options a function of the
232
+ * invocation's context gives (each user's model, say). It takes the message
233
+ * as plain text (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
234
+ */
235
+ export const chat = (options = {}) => {
236
+ if (typeof options === 'object')
237
+ checkModelName('pi', options.model);
238
+ return chatHandler(async (ctx, message) => prompt(ctx, message, await configured(options, ctx)));
239
+ };
240
+ /**
241
+ * A handler of the conversation as clients read it: a page at a time, or
242
+ * what is new or changed since a cursor, from the log each change writes
243
+ * (log.ts). It answers while a message is answered.
244
+ */
245
+ export const messages = () => messagesHandler();
246
+ /**
247
+ * The transcript of each session's root conversation (`ctx.db`, one per
248
+ * attempt), as far as it was read, to its last entry. pi-durable's entries
249
+ * never change, and a new one takes a greater id than any before it (they
250
+ * are committed one at a time), so each read adds the entries after it.
251
+ */
252
+ const transcripts = new WeakMap();
253
+ /** The root conversation in `db`, `root` of a Harness on it, from pi-durable's entries, as `messages` gives it. */
254
+ const transcribe = async (db, root, context) => {
255
+ const read = transcripts.get(db) ?? { transcript: new Transcript() };
256
+ transcripts.set(db, read);
257
+ const { transcript } = read;
258
+ // From the last entry read (the bound is inclusive), or the first.
259
+ const query = { order: 'ascending', ...(read.last === undefined ? {} : { minEntryId: read.last }) };
260
+ for (let cursor;;) {
261
+ const page = await root.entries(query, 100, cursor, context);
262
+ for (const entry of page.items) {
263
+ if (entry.id === read.last)
264
+ continue;
265
+ read.last = entry.id;
266
+ for (const m of entry.model ?? []) {
267
+ if (m.role === 'user')
268
+ transcript.say('user', textOf(m.content));
269
+ if (m.role === 'assistant') {
270
+ transcript.say('assistant', textOf(m.content));
271
+ for (const c of m.content)
272
+ if (c.type === 'toolCall')
273
+ transcript.call(c.id, c.name, c.arguments);
274
+ }
275
+ if (m.role === 'toolResult')
276
+ transcript.result(m.toolCallId, textOf(m.content), m.isError);
277
+ }
278
+ }
279
+ cursor = page.next;
280
+ if (cursor === undefined)
281
+ return transcript;
282
+ }
283
+ };
284
+ /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
285
+ export const agent = ({ name, description, schema, background, ...options }) => sessionObject({
286
+ name,
287
+ description,
288
+ schema,
289
+ background,
290
+ handlers: { chat: chat(options) },
291
+ views: { messages: messages() },
292
+ });
293
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pi/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,yDAAyD;AACzD,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,8BAA8B;AAC9B,EAAE;AACF,wFAAwF;AACxF,EAAE;AACF,kEAAkE;AAClE,+CAA+C;AAC/C,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,8EAA8E;AAC9E,mCAAmC;AACnC,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,yEAAyE;AACzE,2EAA2E;AAC3E,uBAAuB;AACvB,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACrH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAoC,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACL,cAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EACV,OAAO,EACP,OAAO,GAKR,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO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AQ,EAAE,EAAE;CAChC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Database } from '@restatedev/sessions';
2
+ import { SqliteStorage } from '@earendil-works/pi-durable/storage/sqlite';
3
+ /** Open pi-durable storage on the session `db`. */
4
+ export declare function openSqlKvStorage(db: Database): Promise<SqliteStorage>;
5
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/pi/storage.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EACL,aAAa,EAId,MAAM,2CAA2C,CAAC;AA2CnD,mDAAmD;AACnD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAErE"}
@@ -0,0 +1,41 @@
1
+ import { SqliteStorage, } from '@earendil-works/pi-durable/storage/sqlite';
2
+ /** The prefix of pi-durable's tables and indexes. */
3
+ const PREFIX = 'restate_pi_';
4
+ /** SQL through `db`: the session, or one transaction's. */
5
+ class Executor {
6
+ db;
7
+ constructor(db) {
8
+ this.db = db;
9
+ }
10
+ async exec(sql) {
11
+ await this.db.execute(sql);
12
+ }
13
+ async run(sql, ...params) {
14
+ await this.db.execute(sql, params);
15
+ }
16
+ async get(sql, ...params) {
17
+ return this.db.get(sql, params);
18
+ }
19
+ async all(sql, ...params) {
20
+ return this.db.query(sql, params);
21
+ }
22
+ }
23
+ /** The `SqliteDatabase` facade over the session `db`. */
24
+ class SqlKvDatabase extends Executor {
25
+ #session;
26
+ constructor(db) {
27
+ super(db);
28
+ this.#session = db;
29
+ }
30
+ /** Commits when the callback resolves; rolls back, and rejects with its error, when it rejects. */
31
+ transaction(callback) {
32
+ return this.#session.transaction((tx) => callback(new Executor(tx)));
33
+ }
34
+ /** The session is the caller's to end, after the calls made before. */
35
+ async close() { }
36
+ }
37
+ /** Open pi-durable storage on the session `db`. */
38
+ export function openSqlKvStorage(db) {
39
+ return SqliteStorage.open(new SqlKvDatabase(db), { prefix: PREFIX });
40
+ }
41
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/pi/storage.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,aAAa,GAId,MAAM,2CAA2C,CAAC;AAEnD,qDAAqD;AACrD,MAAM,MAAM,GAAG,aAAa,CAAC;AAE7B,2DAA2D;AAC3D,MAAM,QAAQ;IACH,EAAE,CAAiB;IAC5B,YAAY,EAAkB;QAC5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,GAAG,MAAqB;QAC7C,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,CAAC,GAAG,CAAmB,GAAW,EAAE,GAAG,MAAqB;QAC/D,OAAO,IAAI,CAAC,EAAE,CAAC,GAAG,CAAI,GAAG,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,CAAC,GAAG,CAAmB,GAAW,EAAE,GAAG,MAAqB;QAC/D,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,CAAI,GAAG,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF;AAED,yDAAyD;AACzD,MAAM,aAAc,SAAQ,QAAQ;IACzB,QAAQ,CAAW;IAE5B,YAAY,EAAY;QACtB,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,mGAAmG;IACnG,WAAW,CAAI,QAAqD;QAClE,OAAO,IAAI,CAAC,QAAQ,CAAC,WA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