@rivet-dev/pi 0.5.0 → 0.5.1

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 (88) hide show
  1. package/dist/actions.d.ts +188 -77
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +276 -101
  4. package/dist/actions.js.map +1 -1
  5. package/dist/actor-config.d.ts +1 -2
  6. package/dist/actor-config.d.ts.map +1 -1
  7. package/dist/actor-config.js +1 -2
  8. package/dist/actor-config.js.map +1 -1
  9. package/dist/actor-sqlite.d.ts.map +1 -0
  10. package/dist/actor-sqlite.js.map +1 -0
  11. package/dist/actor.d.ts +21 -17
  12. package/dist/actor.d.ts.map +1 -1
  13. package/dist/actor.js +62 -34
  14. package/dist/actor.js.map +1 -1
  15. package/dist/credentials.d.ts +3 -4
  16. package/dist/credentials.d.ts.map +1 -1
  17. package/dist/credentials.js +11 -39
  18. package/dist/credentials.js.map +1 -1
  19. package/dist/drain.d.ts +1 -1
  20. package/dist/drain.js +1 -1
  21. package/dist/durable.d.ts +24 -0
  22. package/dist/durable.d.ts.map +1 -0
  23. package/dist/durable.js +5 -0
  24. package/dist/durable.js.map +1 -0
  25. package/dist/errors.d.ts.map +1 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/index.d.ts +4 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/models.d.ts +4 -35
  31. package/dist/models.d.ts.map +1 -1
  32. package/dist/models.js +0 -70
  33. package/dist/models.js.map +1 -1
  34. package/dist/runtime.d.ts +84 -81
  35. package/dist/runtime.d.ts.map +1 -1
  36. package/dist/runtime.js +394 -406
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/storage.d.ts +27 -45
  39. package/dist/storage.d.ts.map +1 -1
  40. package/dist/storage.js +28 -99
  41. package/dist/storage.js.map +1 -1
  42. package/dist/tracing.d.ts +4 -9
  43. package/dist/tracing.d.ts.map +1 -1
  44. package/dist/tracing.js +4 -40
  45. package/dist/tracing.js.map +1 -1
  46. package/dist/{durable/watches.d.ts → watches.d.ts} +1 -1
  47. package/dist/watches.d.ts.map +1 -0
  48. package/dist/{durable/watches.js → watches.js} +1 -1
  49. package/dist/watches.js.map +1 -0
  50. package/package.json +10 -18
  51. package/dist/durable/actions.d.ts +0 -192
  52. package/dist/durable/actions.d.ts.map +0 -1
  53. package/dist/durable/actions.js +0 -289
  54. package/dist/durable/actions.js.map +0 -1
  55. package/dist/durable/actor-sqlite.d.ts.map +0 -1
  56. package/dist/durable/actor-sqlite.js.map +0 -1
  57. package/dist/durable/actor.d.ts +0 -36
  58. package/dist/durable/actor.d.ts.map +0 -1
  59. package/dist/durable/actor.js +0 -107
  60. package/dist/durable/actor.js.map +0 -1
  61. package/dist/durable/env.d.ts +0 -13
  62. package/dist/durable/env.d.ts.map +0 -1
  63. package/dist/durable/env.js +0 -178
  64. package/dist/durable/env.js.map +0 -1
  65. package/dist/durable/errors.d.ts.map +0 -1
  66. package/dist/durable/errors.js.map +0 -1
  67. package/dist/durable/index.d.ts +0 -5
  68. package/dist/durable/index.d.ts.map +0 -1
  69. package/dist/durable/index.js +0 -2
  70. package/dist/durable/index.js.map +0 -1
  71. package/dist/durable/runtime.d.ts +0 -92
  72. package/dist/durable/runtime.d.ts.map +0 -1
  73. package/dist/durable/runtime.js +0 -435
  74. package/dist/durable/runtime.js.map +0 -1
  75. package/dist/durable/storage.d.ts +0 -31
  76. package/dist/durable/storage.d.ts.map +0 -1
  77. package/dist/durable/storage.js +0 -53
  78. package/dist/durable/storage.js.map +0 -1
  79. package/dist/durable/watches.d.ts.map +0 -1
  80. package/dist/durable/watches.js.map +0 -1
  81. package/dist/sandbox.d.ts +0 -27
  82. package/dist/sandbox.d.ts.map +0 -1
  83. package/dist/sandbox.js +0 -224
  84. package/dist/sandbox.js.map +0 -1
  85. /package/dist/{durable/actor-sqlite.d.ts → actor-sqlite.d.ts} +0 -0
  86. /package/dist/{durable/actor-sqlite.js → actor-sqlite.js} +0 -0
  87. /package/dist/{durable/errors.d.ts → errors.d.ts} +0 -0
  88. /package/dist/{durable/errors.js → errors.js} +0 -0
@@ -1,107 +0,0 @@
1
- import { actor, event, } from "rivetkit";
2
- import { db } from "rivetkit/db";
3
- import { assertNoReservedNames, sharedActorConfig, splitConfig, wrapActions, } from "../actor-config.js";
4
- import { withUnavailablePi } from "../runtime.js";
5
- import { createPiDurableActions } from "./actions.js";
6
- import { closeHarness, createPiDurableRuntime, openOnWake, PI_DURABLE_RUNTIME, piDurableRuntime, withPiAccess, } from "./runtime.js";
7
- import { migratePiDurableTables } from "./storage.js";
8
- import { unwatchConnection, } from "./watches.js";
9
- const piDurableEvents = {
10
- "pi.events": event(),
11
- "pi.view": event(),
12
- "pi.taskGraph": event(),
13
- "pi.doc": event(),
14
- };
15
- const piDurableOptionKeys = [
16
- "registry",
17
- "models",
18
- "settings",
19
- "env",
20
- "conversationCreated",
21
- "now",
22
- "onReport",
23
- "model",
24
- "thinkingLevel",
25
- "scopedModels",
26
- "providers",
27
- "apiKeys",
28
- "credentials",
29
- "sandbox",
30
- "documents",
31
- ];
32
- /**
33
- * Defines a Rivet Actor that owns one Pi Durable harness.
34
- *
35
- * Pi Durable stores conversations, tasks, and documents in the actor's SQLite
36
- * database. Runs survive sleep, deploys, and crashes, and resume when the
37
- * actor wakes. The actions match Pi Durable's API one to one. The app's own
38
- * actions and lifecycle hooks get the harness as `c.pi`.
39
- */
40
- export function piDurable(config) {
41
- const { actorConfig, options: durableOptions } = splitConfig(config, piDurableOptionKeys);
42
- if (!durableOptions.registry) {
43
- throw new Error("piDurable() needs a registry; pass createRegistry() from @earendil-works/pi-durable");
44
- }
45
- if (actorConfig.db !== undefined) {
46
- throw new Error("piDurable() owns the actor database; remove the db option");
47
- }
48
- const actions = createPiDurableActions(durableOptions);
49
- assertNoReservedNames("piDurable()", actorConfig, {
50
- action: actions,
51
- event: piDurableEvents,
52
- });
53
- const withPi = (hook, opensHarness = true) => hook &&
54
- ((c, ...args) => withPiAccess(c, durableOptions, () => hook(c, ...args), {
55
- opensHarness,
56
- }));
57
- const userOnWake = actorConfig.onWake;
58
- const userOnDisconnect = withPi(actorConfig.onDisconnect);
59
- // The config is built from untyped parts, so `actor()` cannot check it
60
- // against the generics. The declared return type is the public contract.
61
- return actor({
62
- ...sharedActorConfig("piDurable()", actorConfig, { slot: PI_DURABLE_RUNTIME, create: createPiDurableRuntime }, (c, stop) => closeHarness(c, durableOptions, stop), {
63
- onSleep: withPi(actorConfig.onSleep, false),
64
- onDestroy: withPi(actorConfig.onDestroy, false),
65
- }),
66
- db: db({ onMigrate: migratePiDurableTables }),
67
- events: { ...(actorConfig.events ?? {}), ...piDurableEvents },
68
- actions: {
69
- ...wrapActions(actorConfig.actions ?? {}, (c, action) => withPiAccess(c, durableOptions, action)),
70
- ...actions,
71
- },
72
- // Opening on wake resumes interrupted work, after the app's own onWake.
73
- onWake: async (c) => {
74
- let harness;
75
- try {
76
- harness = await openOnWake(c, durableOptions);
77
- }
78
- catch (error) {
79
- // The actor stays up so actions can report the cause, such as a
80
- // schema newer than the code. Using c.pi throws it.
81
- c.log.error({
82
- msg: "pi durable could not open on wake; actions will retry",
83
- error,
84
- });
85
- return withUnavailablePi(c, error, () => userOnWake?.(c));
86
- }
87
- Object.defineProperty(c, "pi", { value: harness, configurable: true });
88
- try {
89
- await userOnWake?.(c);
90
- }
91
- finally {
92
- harness.resume();
93
- }
94
- },
95
- onConnect: withPi(actorConfig.onConnect),
96
- onDisconnect: async (c, conn) => {
97
- try {
98
- await userOnDisconnect?.(c, conn);
99
- }
100
- finally {
101
- const runtime = piDurableRuntime(c);
102
- await unwatchConnection(runtime.actor ?? c, runtime.watches, conn.id);
103
- }
104
- },
105
- });
106
- }
107
- //# sourceMappingURL=actor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actor.js","sourceRoot":"","sources":["../../src/durable/actor.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,EAEL,KAAK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,CAAC,EAAE,CAAC,CAAC;YACvE,CAAC;QACF,CAAC;KACM,CAAC,CAAC;AACX,CAAC"}
@@ -1,13 +0,0 @@
1
- import { type ExecutionEnv } from "@earendil-works/pi-durable/env";
2
- import type { Sandbox } from "@rivet-dev/sandbox-adapter";
3
- /**
4
- * Pi Durable's `ExecutionEnv` inside a sandbox, for Pi's built-in tools
5
- * (`CodingTools`). Paths outside the sandbox `cwd` are rejected, and commands
6
- * never receive the actor host's environment variables.
7
- *
8
- * Only the operations Pi's tools use are supported. Every other operation
9
- * returns a `not_supported` error. Operations return failures instead of
10
- * throwing. Building the environment throws when `cwd` is outside the sandbox.
11
- */
12
- export declare function sandboxEnv(id: string, sandbox: Sandbox, cwd: string | undefined): ExecutionEnv;
13
- //# sourceMappingURL=env.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/durable/env.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,YAAY,EAWjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG1D;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACzB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,MAAM,GAAG,SAAS,GACrB,YAAY,CA8Ed"}
@@ -1,178 +0,0 @@
1
- import { posix } from "node:path";
2
- import { ExecutionError, err, FileError, ok, toError, } from "@earendil-works/pi-durable/env";
3
- import { resolveSandboxPath, shellQuote } from "../sandbox.js";
4
- /**
5
- * Pi Durable's `ExecutionEnv` inside a sandbox, for Pi's built-in tools
6
- * (`CodingTools`). Paths outside the sandbox `cwd` are rejected, and commands
7
- * never receive the actor host's environment variables.
8
- *
9
- * Only the operations Pi's tools use are supported. Every other operation
10
- * returns a `not_supported` error. Operations return failures instead of
11
- * throwing. Building the environment throws when `cwd` is outside the sandbox.
12
- */
13
- export function sandboxEnv(id, sandbox, cwd) {
14
- const root = sandbox.cwd;
15
- const inside = (path) => {
16
- try {
17
- return ok(resolveSandboxPath(root, path));
18
- }
19
- catch (error) {
20
- const cause = toError(error);
21
- return err(new FileError("permission_denied", cause.message, path, cause));
22
- }
23
- };
24
- const initialCwd = inside(cwd ?? root);
25
- if (!initialCwd.ok)
26
- throw initialCwd.error;
27
- const env = {
28
- id,
29
- cwd: initialCwd.value,
30
- absolutePath: async (path) => inside(posix.resolve(env.cwd, path)),
31
- joinPath: async (parts) => ok(posix.join(...parts)),
32
- exists: (path) => onPath(inside(path), (resolved) => sandbox.exists(resolved)),
33
- readTextFile: async (path) => {
34
- const resolved = inside(path);
35
- if (!resolved.ok)
36
- return resolved;
37
- return read(sandbox, resolved.value, async () => new TextDecoder().decode(await sandbox.readFile(resolved.value)));
38
- },
39
- readBinaryFile: async (path) => {
40
- const resolved = inside(path);
41
- if (!resolved.ok)
42
- return resolved;
43
- return read(sandbox, resolved.value, () => sandbox.readFile(resolved.value));
44
- },
45
- writeFile: async (path, content) => {
46
- if (typeof content !== "string") {
47
- return notSupported("writing binary content", path);
48
- }
49
- return onPath(inside(path), async (resolved) => {
50
- await sandbox.mkdir(posix.dirname(resolved));
51
- await sandbox.writeFile(resolved, content);
52
- });
53
- },
54
- fileInfo: async (path) => {
55
- const resolved = inside(path);
56
- return resolved.ok ? fileInfo(sandbox, resolved.value) : resolved;
57
- },
58
- // Pi's tools fall back to the absolute path when canonical paths are not supported.
59
- canonicalPath: async (path) => notSupported("canonicalPath", path),
60
- exec: async (command, options, context) => {
61
- const cwd = inside(options?.cwd ?? env.cwd);
62
- if (!cwd.ok) {
63
- return err(new ExecutionError("spawn_error", cwd.error.message, cwd.error));
64
- }
65
- return exec(sandbox, command, options, context, cwd.value);
66
- },
67
- openTextLineReader: async (path) => notSupported("openTextLineReader", path),
68
- readTextLines: async (path) => notSupported("readTextLines", path),
69
- appendFile: async (path) => notSupported("appendFile", path),
70
- truncateFile: async (path) => notSupported("truncateFile", path),
71
- flushFile: async (path) => notSupported("flushFile", path),
72
- renameFile: async (path) => notSupported("renameFile", path),
73
- listDir: async (path) => notSupported("listDir", path),
74
- createDir: async (path) => notSupported("createDir", path),
75
- remove: async (path) => notSupported("remove", path),
76
- createTempDir: async () => notSupported("createTempDir"),
77
- createTempFile: async () => notSupported("createTempFile"),
78
- cleanup: async () => { },
79
- };
80
- return env;
81
- }
82
- function notSupported(operation, path) {
83
- return err(new FileError("not_supported", `${operation} is not supported in a sandbox`, path));
84
- }
85
- /** Runs a sandbox operation on a checked path and returns its failure as a `FileError`. */
86
- async function onPath(path, operation) {
87
- if (!path.ok)
88
- return path;
89
- try {
90
- return ok(await operation(path.value));
91
- }
92
- catch (error) {
93
- const cause = toError(error);
94
- return err(new FileError("unknown", cause.message, path.value, cause));
95
- }
96
- }
97
- /** A read of a missing file reports `not_found`, which Pi's tools rely on. */
98
- async function read(sandbox, path, operation) {
99
- try {
100
- return ok(await operation());
101
- }
102
- catch (error) {
103
- const cause = toError(error);
104
- const code = (await sandbox.exists(path).catch(() => true))
105
- ? "unknown"
106
- : "not_found";
107
- return err(new FileError(code, cause.message, path, cause));
108
- }
109
- }
110
- const STAT_KINDS = {
111
- "regular file": "file",
112
- "regular empty file": "file",
113
- directory: "directory",
114
- "symbolic link": "symlink",
115
- };
116
- async function fileInfo(sandbox, path) {
117
- let result;
118
- try {
119
- result = await sandbox.exec(`stat -c '%F|%s|%Y' -- ${shellQuote(path)}`, {
120
- cwd: sandbox.cwd,
121
- });
122
- }
123
- catch (error) {
124
- const cause = toError(error);
125
- return err(new FileError("unknown", cause.message, path, cause));
126
- }
127
- if (result.exitCode !== 0) {
128
- const code = /No such file/i.test(result.stderr) ? "not_found" : "unknown";
129
- return err(new FileError(code, result.stderr.trim() || `stat exited with ${result.exitCode}`, path));
130
- }
131
- const [type = "", size = "", modified = ""] = result.stdout.trim().split("|");
132
- const kind = STAT_KINDS[type];
133
- if (!kind) {
134
- return err(new FileError("invalid", `${path} is a ${type}, not a file, directory, or symlink`, path));
135
- }
136
- return ok({
137
- name: posix.basename(path),
138
- path,
139
- kind,
140
- size: Number(size),
141
- mtimeMs: Number(modified) * 1000,
142
- });
143
- }
144
- /**
145
- * Runs a command in the sandbox. `timeout` is in seconds, as in Pi. Commands
146
- * get only the variables in `options.env`. `inheritEnv` would mean the actor
147
- * host's environment, which holds provider keys, so it is ignored.
148
- */
149
- async function exec(sandbox, command, options, context, cwd) {
150
- const decoder = new TextDecoder();
151
- const output = (text) => {
152
- if (text)
153
- options?.onOutput?.(text, context);
154
- };
155
- try {
156
- const result = await sandbox.exec(command, {
157
- cwd,
158
- env: options?.env,
159
- timeoutMs: options?.timeout === undefined ? undefined : options.timeout * 1000,
160
- signal: context.abortSignal,
161
- onData: (chunk) => output(decoder.decode(chunk, { stream: true })),
162
- });
163
- output(decoder.decode());
164
- if (result.timedOut) {
165
- return err(new ExecutionError("timeout", `Command timed out after ${options?.timeout} seconds`));
166
- }
167
- if (result.exitCode === null) {
168
- return err(new ExecutionError("unknown", "Command was killed by a signal"));
169
- }
170
- return ok({ exitCode: result.exitCode });
171
- }
172
- catch (error) {
173
- const cause = toError(error);
174
- const code = context.abortSignal?.aborted ? "aborted" : "spawn_error";
175
- return err(new ExecutionError(code, cause.message, cause));
176
- }
177
- }
178
- //# sourceMappingURL=env.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/durable/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAEN,cAAc,EACd,GAAG,EACH,SAAS,EAGT,EAAE,EAIF,OAAO,GACP,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACzB,EAAU,EACV,OAAgB,EAChB,GAAuB;IAEvB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;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,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;SAClE,CAAC,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACzB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,GAAG,CACT,IAAI,cAAc,CACjB,SAAS,EACT,2BAA2B,OAAO,EAAE,OAAO,UAAU,CACrD,CACD,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,GAAG,CACT,IAAI,cAAc,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAC/D,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;QACtE,OAAO,GAAG,CAAC,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/durable/errors.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASrD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/durable/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;QACvC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE;YACnC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE;YAClD,KAAK,EAAE,KAAK;SACZ,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -1,5 +0,0 @@
1
- export type { PiAgentChange, PiAgentInfo, PiCreateConversationOptions, PiDurableActions, PiDurablePromptOptions, PiDurablePromptResult, } from "./actions.js";
2
- export { type PiDurableAccess, type PiDurableActorConfigInput, type PiDurableEvents, type PiDurableUserActions, piDurable, } from "./actor.js";
3
- export type { PiDurableOptions } from "./runtime.js";
4
- export type { PiDocFrame, PiEventsFrame, PiTaskGraphFrame, PiViewFrame, PiWatchEvents, } from "./watches.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/durable/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,aAAa,EACb,WAAW,EACX,2BAA2B,EAC3B,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,SAAS,GACT,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EACX,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,GACb,MAAM,cAAc,CAAC"}
@@ -1,2 +0,0 @@
1
- export { piDurable, } from "./actor.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/durable/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAKN,SAAS,GACT,MAAM,YAAY,CAAC"}
@@ -1,92 +0,0 @@
1
- import type { Context } from "@earendil-works/chord";
2
- import type { Models, ModelThinkingLevel } from "@earendil-works/pi-ai";
3
- import { type ConversationDocToken, Harness, type HarnessOptions, type HarnessSettings, type ModelRef } from "@earendil-works/pi-durable";
4
- import type { SandboxProvider } from "@rivet-dev/sandbox-adapter";
5
- import { type PiModelOptions } from "../models.js";
6
- import { type ConnectedSandbox, type PiContext, type PiStop } from "../runtime.js";
7
- import { type ConnectionWatches } from "./watches.js";
8
- /**
9
- * Options accepted by `piDurable()` on top of ordinary actor config. The Pi
10
- * Durable options keep the names and types of `HarnessOptions`.
11
- */
12
- export interface PiDurableOptions extends PiModelOptions {
13
- /** Pi Durable's extension registry: tools, hooks, sections, tasks, and documents. */
14
- registry: HarnessOptions["registry"];
15
- /** pi-ai model access. Without it, the actor builds it from `model`, `providers`, `apiKeys`, and `credentials`. */
16
- models?: Models;
17
- settings?: HarnessSettings;
18
- /** Builds a conversation's environment. Without it, the actor builds one from `sandbox`. */
19
- env?: HarnessOptions["env"];
20
- conversationCreated?: HarnessOptions["conversationCreated"];
21
- now?: HarnessOptions["now"];
22
- onReport?: HarnessOptions["onReport"];
23
- /** The starting thinking level of every new conversation. */
24
- thinkingLevel?: ModelThinkingLevel;
25
- /** Runs the tools of Pi's `CodingTools` extension in a sandbox. Used only when `env` is omitted. */
26
- sandbox?: SandboxProvider;
27
- /** App documents that clients may read by `kind` with `harness.snapshot`. */
28
- documents?: readonly ConversationDocToken<any>[];
29
- }
30
- interface OpenHarness {
31
- harness: Harness;
32
- stopBusyWatch: () => void;
33
- isBusy: () => Promise<boolean>;
34
- }
35
- /** Per-actor-generation state, stored on `c.vars` under `PI_DURABLE_RUNTIME`. */
36
- export interface PiDurableRuntime {
37
- /** The open harness, or the open in progress. */
38
- harness?: Promise<OpenHarness>;
39
- sandbox?: Promise<ConnectedSandbox>;
40
- /** Set when the actor starts to sleep or is destroyed. */
41
- closing: boolean;
42
- /**
43
- * The `onWake` context. Background work (keep-awake, scheduled wakes, the
44
- * sandbox, reopening) uses it, because an action's context is cancelled
45
- * with the action.
46
- */
47
- actor?: PiContext;
48
- /** Open Pi watches of connections, for this generation. */
49
- watches: ConnectionWatches;
50
- }
51
- export declare const PI_DURABLE_RUNTIME: unique symbol;
52
- export declare function createPiDurableRuntime(): PiDurableRuntime;
53
- export declare function piDurableRuntime(c: PiContext): PiDurableRuntime;
54
- /**
55
- * Opens the harness on wake without resuming interrupted work, so the app's
56
- * `onWake` runs first. The caller calls `harness.resume()` after it. The wake
57
- * context becomes the context of all background work.
58
- */
59
- export declare function openOnWake(c: PiContext, options: PiDurableOptions): Promise<Harness>;
60
- /**
61
- * Runs an action against the harness. A failed call that left Pi Durable
62
- * unusable reopens it before the error reaches the client, so the next call
63
- * works. Calls use `BACKGROUND_CONTEXT`, so a wait such as `prompt` lasts
64
- * until the run settles or the action times out, including while a stopping
65
- * actor drains the run. RivetKit's action signal also fires when the actor
66
- * starts to stop, so it cannot cancel a wait.
67
- */
68
- export declare function withHarness<T>(c: PiContext, options: PiDurableOptions, run: (harness: Harness, context: Context) => Promise<T>): Promise<T>;
69
- /**
70
- * Runs one of the app's own actions or hooks with the harness on `c.pi`. A
71
- * failure that left Pi Durable unusable reopens it. The error reaches the
72
- * client as from a built-in action. Code that never reads `c.pi` runs even
73
- * when Pi Durable is closed or cannot open; reading `c.pi` throws the cause.
74
- * Shutdown hooks pass `opensHarness: false`, so they use a harness that is
75
- * already open and never open and resume one only to close it.
76
- */
77
- export declare function withPiAccess<T>(c: PiContext, options: PiDurableOptions, body: () => T | Promise<T>, { opensHarness }?: {
78
- opensHarness?: boolean;
79
- }): Promise<T>;
80
- /** App documents by `kind`, for clients that name a document. */
81
- export declare function documentsByKind(options: PiDurableOptions): ReadonlyMap<string, ConversationDocToken<any>>;
82
- /** Parses `provider/modelId`. */
83
- export declare function parseModelRef(name: string): ModelRef;
84
- /**
85
- * Closes Pi Durable for this actor generation. On sleep it drains first. On
86
- * destroy it stops running work at once. Records of interrupted work stay
87
- * running, and the next open resumes them. Then suspends the sandbox on
88
- * sleep, or destroys it on destroy.
89
- */
90
- export declare function closeHarness(c: PiContext, options: PiDurableOptions, stop: PiStop): Promise<void>;
91
- export {};
92
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/durable/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAEN,KAAK,oBAAoB,EAEzB,OAAO,EAEP,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,KAAK,gBAAgB,EAGrB,KAAK,SAAS,EACd,KAAK,MAAM,EAEX,MAAM,eAAe,CAAC;AAIvB,OAAO,EACN,KAAK,iBAAiB,EAItB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACvD,qFAAqF;IACrF,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACrC,mHAAmH;IACnH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,4FAA4F;IAC5F,GAAG,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5B,mBAAmB,CAAC,EAAE,cAAc,CAAC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