@rivet-dev/pi 0.5.0 → 0.5.2
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/dist/actions.d.ts +188 -77
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +276 -101
- package/dist/actions.js.map +1 -1
- package/dist/actor-config.d.ts +1 -2
- package/dist/actor-config.d.ts.map +1 -1
- package/dist/actor-config.js +1 -2
- package/dist/actor-config.js.map +1 -1
- package/dist/actor-sqlite.d.ts +16 -0
- package/dist/actor-sqlite.d.ts.map +1 -0
- package/dist/actor-sqlite.js +52 -0
- package/dist/actor-sqlite.js.map +1 -0
- package/dist/actor.d.ts +21 -17
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +62 -34
- package/dist/actor.js.map +1 -1
- package/dist/credentials.d.ts +5 -5
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +12 -41
- package/dist/credentials.js.map +1 -1
- package/dist/database-env.d.ts +14 -0
- package/dist/database-env.d.ts.map +1 -0
- package/dist/database-env.js +173 -0
- package/dist/database-env.js.map +1 -0
- package/dist/drain.d.ts +1 -1
- package/dist/drain.js +1 -1
- package/dist/durable.d.ts +24 -0
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +5 -0
- package/dist/durable.js.map +1 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +4 -35
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +0 -70
- package/dist/models.js.map +1 -1
- package/dist/runtime.d.ts +84 -81
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +399 -406
- package/dist/runtime.js.map +1 -1
- package/dist/storage.d.ts +29 -45
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +52 -99
- package/dist/storage.js.map +1 -1
- package/dist/tracing.d.ts +4 -9
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +4 -40
- package/dist/tracing.js.map +1 -1
- package/dist/{durable/watches.d.ts → watches.d.ts} +5 -5
- package/dist/watches.d.ts.map +1 -0
- package/dist/{durable/watches.js → watches.js} +4 -5
- package/dist/watches.js.map +1 -0
- package/package.json +10 -18
- package/dist/durable/actions.d.ts +0 -192
- package/dist/durable/actions.d.ts.map +0 -1
- package/dist/durable/actions.js +0 -289
- package/dist/durable/actions.js.map +0 -1
- package/dist/durable/actor-sqlite.d.ts +0 -10
- package/dist/durable/actor-sqlite.d.ts.map +0 -1
- package/dist/durable/actor-sqlite.js +0 -32
- package/dist/durable/actor-sqlite.js.map +0 -1
- package/dist/durable/actor.d.ts +0 -36
- package/dist/durable/actor.d.ts.map +0 -1
- package/dist/durable/actor.js +0 -107
- package/dist/durable/actor.js.map +0 -1
- package/dist/durable/env.d.ts +0 -13
- package/dist/durable/env.d.ts.map +0 -1
- package/dist/durable/env.js +0 -178
- package/dist/durable/env.js.map +0 -1
- package/dist/durable/errors.d.ts.map +0 -1
- package/dist/durable/errors.js.map +0 -1
- package/dist/durable/index.d.ts +0 -5
- package/dist/durable/index.d.ts.map +0 -1
- package/dist/durable/index.js +0 -2
- package/dist/durable/index.js.map +0 -1
- package/dist/durable/runtime.d.ts +0 -92
- package/dist/durable/runtime.d.ts.map +0 -1
- package/dist/durable/runtime.js +0 -435
- package/dist/durable/runtime.js.map +0 -1
- package/dist/durable/storage.d.ts +0 -31
- package/dist/durable/storage.d.ts.map +0 -1
- package/dist/durable/storage.js +0 -53
- package/dist/durable/storage.js.map +0 -1
- package/dist/durable/watches.d.ts.map +0 -1
- package/dist/durable/watches.js.map +0 -1
- package/dist/sandbox.d.ts +0 -27
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/sandbox.js +0 -224
- package/dist/sandbox.js.map +0 -1
- /package/dist/{durable/errors.d.ts → errors.d.ts} +0 -0
- /package/dist/{durable/errors.js → errors.js} +0 -0
package/dist/actor.d.ts
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Harness } from "@earendil-works/pi-durable";
|
|
2
2
|
import { type EventSchemaConfig, type QueueSchemaConfig, type Type } from "rivetkit";
|
|
3
3
|
import { type PiActions } from "./actions.js";
|
|
4
4
|
import type { PiActorDefinition, UserActions, UserActorConfig } from "./actor-types.js";
|
|
5
|
-
import { type
|
|
6
|
-
|
|
5
|
+
import { type PiOptions } from "./runtime.js";
|
|
6
|
+
import { type PiDocFrame, type PiEventsFrame, type PiTaskGraphFrame, type PiViewFrame } from "./watches.js";
|
|
7
|
+
/** Watch frames, sent only to the connection that asked. See `PiWatchEvents`. */
|
|
7
8
|
export type PiEvents = {
|
|
8
|
-
|
|
9
|
+
"pi.events": Type<PiEventsFrame>;
|
|
10
|
+
"pi.view": Type<PiViewFrame>;
|
|
11
|
+
"pi.taskGraph": Type<PiTaskGraphFrame>;
|
|
12
|
+
"pi.doc": Type<PiDocFrame>;
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
|
-
* `c.pi`: the actor's Pi
|
|
12
|
-
* it throws when
|
|
13
|
-
*
|
|
14
|
-
* already open in this actor generation.
|
|
15
|
+
* `c.pi`: the actor's Pi Durable harness, in the app's own actions and hooks.
|
|
16
|
+
* Reading it throws when Pi Durable cannot open, such as after a rollback to
|
|
17
|
+
* an older schema. In `onSleep` and `onDestroy` it is set only when Pi Durable
|
|
18
|
+
* is already open in this actor generation.
|
|
15
19
|
*/
|
|
16
20
|
export interface PiAccess {
|
|
17
|
-
readonly pi:
|
|
21
|
+
readonly pi: Harness;
|
|
18
22
|
}
|
|
19
23
|
/** The app's own actions, which get `c.pi`. Nested objects become dotted action names. */
|
|
20
24
|
export type PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = UserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, PiAccess>;
|
|
21
|
-
/** Ordinary actor config plus Pi
|
|
22
|
-
export type PiActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues> = Record<never, never>> = UserActorConfig<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions,
|
|
25
|
+
/** Ordinary actor config plus the Pi Durable options. The app's actions and lifecycle hooks get `c.pi`. */
|
|
26
|
+
export type PiActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues> = Record<never, never>> = UserActorConfig<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions, PiOptions, PiAccess>;
|
|
23
27
|
/**
|
|
24
|
-
* Defines a Rivet Actor that owns one Pi
|
|
28
|
+
* Defines a Rivet Actor that owns one Pi Durable harness.
|
|
25
29
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
+
* Pi Durable stores conversations, tasks, and documents in the actor's SQLite
|
|
31
|
+
* database. Runs survive sleep, upgrades, and crashes, and resume when the
|
|
32
|
+
* actor wakes. The actions match Pi Durable's API one to one. The app's own
|
|
33
|
+
* actions and lifecycle hooks get the harness as `c.pi`.
|
|
30
34
|
*/
|
|
31
|
-
export declare function pi<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues> = PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues>>(config
|
|
35
|
+
export declare function pi<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues> = PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues>>(config: PiActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions>): PiActorDefinition<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions, PiEvents, PiActions>;
|
|
32
36
|
//# sourceMappingURL=actor.d.ts.map
|
package/dist/actor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAEN,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAO/D,OAAO,KAAK,EACX,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAMN,KAAK,SAAS,EAId,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAEhB,MAAM,cAAc,CAAC;AAEtB,iFAAiF;AACjF,MAAM,MAAM,QAAQ,GAAG;IACtB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7B,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACvC,QAAQ,EAAE,IAAI,CAAC,UA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AAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,CACP,GAAG,aAAa,CAChB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,CACP,EAED,MAAM,EAAE,kBAAkB,CACzB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,CACZ,GACC,iBAAiB,CACnB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,SAAS,CACT,CAmFA"}
|
package/dist/actor.js
CHANGED
|
@@ -2,77 +2,105 @@ import { actor, event, } from "rivetkit";
|
|
|
2
2
|
import { db } from "rivetkit/db";
|
|
3
3
|
import { createPiActions } from "./actions.js";
|
|
4
4
|
import { assertNoReservedNames, sharedActorConfig, splitConfig, wrapActions, } from "./actor-config.js";
|
|
5
|
-
import {
|
|
5
|
+
import { closeHarness, createPiRuntime, openOnWake, PI_RUNTIME, piRuntime, withPiAccess, withUnavailablePi, } from "./runtime.js";
|
|
6
6
|
import { migratePiTables } from "./storage.js";
|
|
7
|
+
import { unwatchConnection, } from "./watches.js";
|
|
7
8
|
const piEvents = {
|
|
8
|
-
|
|
9
|
+
"pi.events": event(),
|
|
10
|
+
"pi.view": event(),
|
|
11
|
+
"pi.taskGraph": event(),
|
|
12
|
+
"pi.doc": event(),
|
|
9
13
|
};
|
|
10
14
|
const piOptionKeys = [
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
15
|
+
"registry",
|
|
16
|
+
"models",
|
|
17
|
+
"settings",
|
|
18
|
+
"env",
|
|
19
|
+
"conversationCreated",
|
|
20
|
+
"now",
|
|
21
|
+
"onReport",
|
|
16
22
|
"model",
|
|
17
23
|
"thinkingLevel",
|
|
18
24
|
"scopedModels",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"customTools",
|
|
23
|
-
"resourceLoader",
|
|
24
|
-
"sessionStartEvent",
|
|
25
|
-
"settings",
|
|
25
|
+
"providers",
|
|
26
|
+
"apiKeys",
|
|
27
|
+
"credentials",
|
|
26
28
|
"sandbox",
|
|
29
|
+
"documents",
|
|
27
30
|
];
|
|
28
31
|
/**
|
|
29
|
-
* Defines a Rivet Actor that owns one Pi
|
|
32
|
+
* Defines a Rivet Actor that owns one Pi Durable harness.
|
|
30
33
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
34
|
+
* Pi Durable stores conversations, tasks, and documents in the actor's SQLite
|
|
35
|
+
* database. Runs survive sleep, upgrades, and crashes, and resume when the
|
|
36
|
+
* actor wakes. The actions match Pi Durable's API one to one. The app's own
|
|
37
|
+
* actions and lifecycle hooks get the harness as `c.pi`.
|
|
35
38
|
*/
|
|
36
|
-
export function pi(config
|
|
37
|
-
const { actorConfig, options:
|
|
39
|
+
export function pi(config) {
|
|
40
|
+
const { actorConfig, options: piOptions } = splitConfig(config, piOptionKeys);
|
|
41
|
+
if (!piOptions.registry) {
|
|
42
|
+
throw new Error("pi() needs a registry; pass createRegistry() from @earendil-works/pi-durable");
|
|
43
|
+
}
|
|
38
44
|
if (actorConfig.db !== undefined) {
|
|
39
45
|
throw new Error("pi() owns the actor database; remove the db option");
|
|
40
46
|
}
|
|
41
|
-
const actions = createPiActions(
|
|
47
|
+
const actions = createPiActions(piOptions);
|
|
42
48
|
assertNoReservedNames("pi()", actorConfig, {
|
|
43
49
|
action: actions,
|
|
44
50
|
event: piEvents,
|
|
45
51
|
});
|
|
46
|
-
const withPi = (hook,
|
|
47
|
-
((c, ...args) =>
|
|
48
|
-
|
|
52
|
+
const withPi = (hook, opensHarness = true) => hook &&
|
|
53
|
+
((c, ...args) => withPiAccess(c, piOptions, () => hook(c, ...args), {
|
|
54
|
+
opensHarness,
|
|
49
55
|
}));
|
|
50
|
-
const userOnWake =
|
|
56
|
+
const userOnWake = actorConfig.onWake;
|
|
57
|
+
const userOnDisconnect = withPi(actorConfig.onDisconnect);
|
|
51
58
|
// The config is built from untyped parts, so `actor()` cannot check it
|
|
52
59
|
// against the generics. The declared return type is the public contract.
|
|
53
60
|
return actor({
|
|
54
|
-
...sharedActorConfig("pi()", actorConfig, { slot: PI_RUNTIME, create: createPiRuntime }, (c, stop) =>
|
|
61
|
+
...sharedActorConfig("pi()", actorConfig, { slot: PI_RUNTIME, create: createPiRuntime }, (c, stop) => closeHarness(c, piOptions, stop), {
|
|
55
62
|
onSleep: withPi(actorConfig.onSleep, false),
|
|
56
63
|
onDestroy: withPi(actorConfig.onDestroy, false),
|
|
57
64
|
}),
|
|
58
65
|
db: db({ onMigrate: migratePiTables }),
|
|
59
66
|
events: { ...(actorConfig.events ?? {}), ...piEvents },
|
|
60
67
|
actions: {
|
|
61
|
-
...wrapActions(actorConfig.actions ?? {}, (c, action) =>
|
|
68
|
+
...wrapActions(actorConfig.actions ?? {}, (c, action) => withPiAccess(c, piOptions, action)),
|
|
62
69
|
...actions,
|
|
63
70
|
},
|
|
71
|
+
// Opening on wake resumes interrupted work, after the app's own onWake.
|
|
64
72
|
onWake: async (c) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
let harness;
|
|
74
|
+
try {
|
|
75
|
+
harness = await openOnWake(c, piOptions);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// The actor stays up so actions can report the cause, such as a
|
|
79
|
+
// schema newer than the code. Using c.pi throws it.
|
|
68
80
|
c.log.error({
|
|
69
|
-
msg: "pi could not
|
|
81
|
+
msg: "pi durable could not open on wake; actions will retry",
|
|
70
82
|
error,
|
|
71
83
|
});
|
|
72
|
-
|
|
84
|
+
return withUnavailablePi(c, error, () => userOnWake?.(c));
|
|
85
|
+
}
|
|
86
|
+
Object.defineProperty(c, "pi", { value: harness, configurable: true });
|
|
87
|
+
try {
|
|
88
|
+
await userOnWake?.(c);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
harness.resume();
|
|
92
|
+
}
|
|
73
93
|
},
|
|
74
94
|
onConnect: withPi(actorConfig.onConnect),
|
|
75
|
-
onDisconnect:
|
|
95
|
+
onDisconnect: async (c, conn) => {
|
|
96
|
+
try {
|
|
97
|
+
await userOnDisconnect?.(c, conn);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
const runtime = piRuntime(c);
|
|
101
|
+
await unwatchConnection(runtime.actor ?? c, runtime.watches, conn.id);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
76
104
|
});
|
|
77
105
|
}
|
|
78
106
|
//# sourceMappingURL=actor.js.map
|
package/dist/actor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actor.js","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actor.js","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,EAEL,KAAK,GAGL,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAC;AAC/D,OAAO,EACN,qBAAqB,EACrB,iBAAiB,EACjB,WAAW,EACX,WAAW,GACX,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACN,YAAY,EACZ,eAAe,EACf,UAAU,EACV,UAAU,EAGV,SAAS,EACT,YAAY,EACZ,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAKN,iBAAiB,GACjB,MAAM,cAAc,CAAC;AAUtB,MAAM,QAAQ,GAAa;IAC1B,WAAW,EAAE,KAAK,EAAiB;IACnC,SAAS,EAAE,KAAK,EAAe;IAC/B,cAAc,EAAE,KAAK,EA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,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,IAAI,CAAC;gBACJ,MAAM,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;YACvB,CAAC;oBAAS,CAAC;gBACV,OAAO,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;QACF,CAAC;QACD,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;QACxC,YAAY,EAAE,KAAK,EAAE,CAAY,EAAE,IAAoB,EAAE,EAAE;YAC1D,IAAI,CAAC;gBACJ,MAAM,gBAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;oBAAS,CAAC;gBACV,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YACvE,CAAC;QACF,CAAC;KACM,CAAC,CAAC;AACX,CAAC"}
|
package/dist/credentials.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface PiCredentialInfo {
|
|
|
24
24
|
export interface PiCredentialSource {
|
|
25
25
|
/** Providers that have a credential. */
|
|
26
26
|
list(): Promise<PiCredentialInfo[]>;
|
|
27
|
-
/** A provider's credential, possibly expired. */
|
|
27
|
+
/** A provider's credential, possibly expired, or `undefined` when it has none. */
|
|
28
28
|
read(providerId: string): Promise<PiProviderCredential | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* A provider's credential after the application refreshed it. Pi calls this
|
|
@@ -35,14 +35,14 @@ export interface PiCredentialSource {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Adapts an application's credential source to Pi's credential store. It
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* asks the source each time Pi needs a credential, so logins and logouts
|
|
39
|
+
* apply to the next model call, and never writes. Pi's `{ signal }` is not
|
|
40
|
+
* passed on, because a source is often an Actor handle, whose actions would
|
|
41
|
+
* receive the signal as an argument.
|
|
40
42
|
*/
|
|
41
43
|
export declare class SourceCredentialStore implements PiCredentialStore {
|
|
42
44
|
#private;
|
|
43
45
|
constructor(source: PiCredentialSource);
|
|
44
|
-
/** Drops what was read so the next read sees new logins and logouts. */
|
|
45
|
-
invalidate(): void;
|
|
46
46
|
list(): Promise<PiCredentialInfo[]>;
|
|
47
47
|
read(providerId: string): Promise<PiCredential | undefined>;
|
|
48
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAC7B,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,GAC1C;IACA,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEL,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,wCAAwC;IACxC,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACpC,
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAC7B,OA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 5 * 60_000;
|
|
3
3
|
/**
|
|
4
4
|
* Adapts an application's credential source to Pi's credential store. It
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* asks the source each time Pi needs a credential, so logins and logouts
|
|
6
|
+
* apply to the next model call, and never writes. Pi's `{ signal }` is not
|
|
7
|
+
* passed on, because a source is often an Actor handle, whose actions would
|
|
8
|
+
* receive the signal as an argument.
|
|
7
9
|
*/
|
|
8
10
|
export class SourceCredentialStore {
|
|
9
11
|
#source;
|
|
10
|
-
#listed;
|
|
11
|
-
#read = new Map();
|
|
12
12
|
constructor(source) {
|
|
13
13
|
this.#source = source;
|
|
14
14
|
}
|
|
15
|
-
/** Drops what was read so the next read sees new logins and logouts. */
|
|
16
|
-
invalidate() {
|
|
17
|
-
this.#listed = undefined;
|
|
18
|
-
this.#read.clear();
|
|
19
|
-
}
|
|
20
15
|
list() {
|
|
21
|
-
|
|
22
|
-
this.#listed = undefined;
|
|
23
|
-
throw error;
|
|
24
|
-
});
|
|
25
|
-
return this.#listed;
|
|
16
|
+
return this.#source.list();
|
|
26
17
|
}
|
|
27
18
|
async read(providerId) {
|
|
28
|
-
|
|
29
|
-
return undefined;
|
|
30
|
-
let read = this.#read.get(providerId);
|
|
31
|
-
if (!read) {
|
|
32
|
-
read = this.#source
|
|
33
|
-
.read(providerId)
|
|
34
|
-
.then(toPiCredential)
|
|
35
|
-
.catch((error) => {
|
|
36
|
-
this.#read.delete(providerId);
|
|
37
|
-
throw error;
|
|
38
|
-
});
|
|
39
|
-
this.#read.set(providerId, read);
|
|
40
|
-
}
|
|
41
|
-
return read;
|
|
19
|
+
return toPiCredential(await this.#source.read(providerId));
|
|
42
20
|
}
|
|
43
21
|
/**
|
|
44
22
|
* Pi calls this to refresh a subscription token that expires soon. The
|
|
45
23
|
* source refreshes it, so `fn` sees a fresh credential and never writes.
|
|
46
24
|
*/
|
|
47
25
|
async modify(providerId, fn) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
this.#read.set(providerId, refreshed);
|
|
56
|
-
refreshed.catch(() => {
|
|
57
|
-
if (this.#read.get(providerId) === refreshed)
|
|
58
|
-
this.#read.delete(providerId);
|
|
59
|
-
});
|
|
60
|
-
const current = await refreshed;
|
|
26
|
+
const credential = await this.#source.refresh(providerId);
|
|
27
|
+
if (credential?.type === "oauth" &&
|
|
28
|
+
credential.expires - Date.now() <= PI_OAUTH_MIN_VALIDITY_MS) {
|
|
29
|
+
throw new Error(`the credential source returned a ${providerId} token that expires within five minutes`);
|
|
30
|
+
}
|
|
31
|
+
const current = toPiCredential(credential);
|
|
61
32
|
if ((await fn(current)) !== undefined) {
|
|
62
33
|
throw new Error(`pi actor cannot store credentials for ${providerId}; the credential source owns them`);
|
|
63
34
|
}
|
package/dist/credentials.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAuCA,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,CAAC,GAAG,MAAM,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAuCA,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,CAAC,GAAG,MAAM,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,OAAO,qBAAqB;IACxB,OAAO,CAAqB;IAErC,YAAY,MAA0B;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAkB;QAC5B,OAAO,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CACX,UAAkB,EAClB,EAEsC;QAEtC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1D,IACC,UAAU,EAAE,IAAI,KAAK,OAAO;YAC5B,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,wBAAwB,EAC1D,CAAC;YACF,MAAM,IAAI,KAAK,CACd,oCAAoC,UAAU,yCAAyC,CACvF,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACd,yCAAyC,UAAU,mCAAmC,CACtF,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB;QAC9B,MAAM,IAAI,KAAK,CACd,0CAA0C,UAAU,mCAAmC,CACvF,CAAC;IACH,CAAC;CACD;AAED,+HAA+H;AAC/H,SAAS,cAAc,CACtB,UAA4C;IAE5C,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAClC,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IACrD,OAAO,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ExecutionEnv } from "@earendil-works/pi-durable/env";
|
|
2
|
+
import type { PiDatabase } from "./storage.js";
|
|
3
|
+
/**
|
|
4
|
+
* Pi Durable's `ExecutionEnv` over files stored in the actor's database, in
|
|
5
|
+
* the `pi_file` table, for Pi's `read`, `write`, and `edit` tools. Directories
|
|
6
|
+
* exist only as the paths of their files. There is no shell, so `exec` fails
|
|
7
|
+
* with `shell_unavailable`, and operations the tools do not use return
|
|
8
|
+
* `not_supported`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function databaseEnv(db: PiDatabase, options: {
|
|
11
|
+
id: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
}): ExecutionEnv;
|
|
14
|
+
//# sourceMappingURL=database-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-env.d.ts","sourceRoot":"","sources":["../src/database-env.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,YAAY,EASjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO/C;;;;;;GAMG;AACH,wBAAgB,WAAW,CAC1B,EAAE,EAAE,UAAU,EACd,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC,YAAY,CA8Fd"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { ExecutionError, err, FileError, LineScanner, ok, toError, } from "@earendil-works/pi-durable/env";
|
|
3
|
+
const DEFAULT_CWD = "/workspace";
|
|
4
|
+
/** Bytes per query when a scan walks a whole file. */
|
|
5
|
+
const SCAN_CHUNK_BYTES = 64 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Pi Durable's `ExecutionEnv` over files stored in the actor's database, in
|
|
8
|
+
* the `pi_file` table, for Pi's `read`, `write`, and `edit` tools. Directories
|
|
9
|
+
* exist only as the paths of their files. There is no shell, so `exec` fails
|
|
10
|
+
* with `shell_unavailable`, and operations the tools do not use return
|
|
11
|
+
* `not_supported`.
|
|
12
|
+
*/
|
|
13
|
+
export function databaseEnv(db, options) {
|
|
14
|
+
const env = {
|
|
15
|
+
id: options.id,
|
|
16
|
+
cwd: posix.resolve(DEFAULT_CWD, options.cwd ?? DEFAULT_CWD),
|
|
17
|
+
absolutePath: async (path) => ok(posix.resolve(env.cwd, path)),
|
|
18
|
+
joinPath: async (parts) => ok(posix.join(...parts)),
|
|
19
|
+
canonicalPath: async (path) => ok(posix.resolve(env.cwd, path)),
|
|
20
|
+
exists: (path, context) => attempt(path, context, async (resolved) => (await entry(db, resolved)) !== undefined),
|
|
21
|
+
fileInfo: (path, context) => attempt(path, context, async (resolved) => {
|
|
22
|
+
const info = await entry(db, resolved);
|
|
23
|
+
if (!info)
|
|
24
|
+
throw notFound(resolved);
|
|
25
|
+
return info;
|
|
26
|
+
}),
|
|
27
|
+
readTextFile: (path, context) => attempt(path, context, async (resolved) => new TextDecoder().decode(await readFile(db, resolved))),
|
|
28
|
+
readBinaryFile: (path, context) => attempt(path, context, (resolved) => readFile(db, resolved)),
|
|
29
|
+
openBinaryReader: (path, _options, context) => attempt(path, context, async (resolved) => {
|
|
30
|
+
await requireFile(db, resolved);
|
|
31
|
+
return fileReader(db, resolved);
|
|
32
|
+
}),
|
|
33
|
+
writeFile: (path, content, context) => attempt(path, context, async (resolved) => {
|
|
34
|
+
const bytes = typeof content === "string"
|
|
35
|
+
? new TextEncoder().encode(content)
|
|
36
|
+
: content;
|
|
37
|
+
await db.execute(`INSERT INTO pi_file (path, content, mtime_ms) VALUES (?, ?, ?)
|
|
38
|
+
ON CONFLICT (path) DO UPDATE SET
|
|
39
|
+
content = excluded.content,
|
|
40
|
+
mtime_ms = excluded.mtime_ms`, resolved, bytes, Date.now());
|
|
41
|
+
}),
|
|
42
|
+
exec: async () => err(new ExecutionError("shell_unavailable", "There is no shell: files are stored in the actor's database. Give pi() a sandbox to run commands.")),
|
|
43
|
+
openTextLineReader: async (path) => notSupported("openTextLineReader", path),
|
|
44
|
+
readTextLines: async (path) => notSupported("readTextLines", path),
|
|
45
|
+
appendFile: async (path) => notSupported("appendFile", path),
|
|
46
|
+
truncateFile: async (path) => notSupported("truncateFile", path),
|
|
47
|
+
flushFile: async (path) => notSupported("flushFile", path),
|
|
48
|
+
renameFile: async (path) => notSupported("renameFile", path),
|
|
49
|
+
listDir: async (path) => notSupported("listDir", path),
|
|
50
|
+
openDirReader: async (path) => notSupported("openDirReader", path),
|
|
51
|
+
watch: async () => notSupported("watch"),
|
|
52
|
+
createDir: async (path) => notSupported("createDir", path),
|
|
53
|
+
remove: async (path) => notSupported("remove", path),
|
|
54
|
+
createTempDir: async () => notSupported("createTempDir"),
|
|
55
|
+
createTempFile: async () => notSupported("createTempFile"),
|
|
56
|
+
cleanup: async () => { },
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Resolves `path`, runs `operation` unless the run is aborted, and returns a
|
|
60
|
+
* thrown error as a `FileError`.
|
|
61
|
+
*/
|
|
62
|
+
async function attempt(path, context, operation) {
|
|
63
|
+
const resolved = posix.resolve(env.cwd, path);
|
|
64
|
+
if (context.abortSignal?.aborted)
|
|
65
|
+
return err(aborted(resolved));
|
|
66
|
+
try {
|
|
67
|
+
return ok(await operation(resolved));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof FileError)
|
|
71
|
+
return err(error);
|
|
72
|
+
const cause = toError(error);
|
|
73
|
+
return err(new FileError("unknown", cause.message, resolved, cause));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return env;
|
|
77
|
+
}
|
|
78
|
+
/** The file or directory at `path`. A directory exists when a file below it does. */
|
|
79
|
+
async function entry(db, path) {
|
|
80
|
+
const [file] = await db.execute(`SELECT length(content) AS size, mtime_ms FROM pi_file WHERE path = ?`, path);
|
|
81
|
+
if (file) {
|
|
82
|
+
return {
|
|
83
|
+
name: posix.basename(path),
|
|
84
|
+
path,
|
|
85
|
+
kind: "file",
|
|
86
|
+
size: file.size,
|
|
87
|
+
mtimeMs: file.mtime_ms,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const below = path === "/" ? "/" : `${path}/`;
|
|
91
|
+
// Paths below `below` sort from it up to the same prefix ending in the next byte.
|
|
92
|
+
const [child] = await db.execute(`SELECT 1 FROM pi_file WHERE path > ? AND path < ? LIMIT 1`, below, `${below.slice(0, -1)}0`);
|
|
93
|
+
if (!child)
|
|
94
|
+
return undefined;
|
|
95
|
+
return {
|
|
96
|
+
name: posix.basename(path),
|
|
97
|
+
path,
|
|
98
|
+
kind: "directory",
|
|
99
|
+
size: 0,
|
|
100
|
+
mtimeMs: 0,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function requireFile(db, path) {
|
|
104
|
+
const info = await entry(db, path);
|
|
105
|
+
if (!info)
|
|
106
|
+
throw notFound(path);
|
|
107
|
+
if (info.kind === "directory") {
|
|
108
|
+
throw new FileError("is_directory", `${path} is a directory`, path);
|
|
109
|
+
}
|
|
110
|
+
return info;
|
|
111
|
+
}
|
|
112
|
+
async function readFile(db, path) {
|
|
113
|
+
const [row] = await db.execute(`SELECT content FROM pi_file WHERE path = ?`, path);
|
|
114
|
+
if (row)
|
|
115
|
+
return new Uint8Array(row.content);
|
|
116
|
+
await requireFile(db, path);
|
|
117
|
+
throw notFound(path);
|
|
118
|
+
}
|
|
119
|
+
/** Reads byte ranges of the stored file with SQL, so a large file is never loaded whole. */
|
|
120
|
+
function fileReader(db, path) {
|
|
121
|
+
const range = async (offset, length) => {
|
|
122
|
+
const [row] = await db.execute(`SELECT substr(content, ?, ?) AS chunk FROM pi_file WHERE path = ?`, offset + 1, length, path);
|
|
123
|
+
if (!row)
|
|
124
|
+
throw notFound(path);
|
|
125
|
+
return new Uint8Array(row.chunk ?? new Uint8Array());
|
|
126
|
+
};
|
|
127
|
+
const guarded = async (context, operation) => {
|
|
128
|
+
if (context.abortSignal?.aborted)
|
|
129
|
+
return err(aborted(path));
|
|
130
|
+
try {
|
|
131
|
+
return ok(await operation());
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error instanceof FileError)
|
|
135
|
+
return err(error);
|
|
136
|
+
const cause = toError(error);
|
|
137
|
+
return err(new FileError("unknown", cause.message, path, cause));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
info: (context) => guarded(context, () => requireFile(db, path)),
|
|
142
|
+
read: (offset, length, context) => guarded(context, () => range(offset, length)),
|
|
143
|
+
scanLines: ({ startLine, endLine }, context) => guarded(context, async () => {
|
|
144
|
+
let scanner;
|
|
145
|
+
try {
|
|
146
|
+
scanner = new LineScanner(startLine, endLine);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new FileError("invalid", "Invalid line range", path);
|
|
150
|
+
}
|
|
151
|
+
for (let offset = 0;; offset += SCAN_CHUNK_BYTES) {
|
|
152
|
+
if (context.abortSignal?.aborted)
|
|
153
|
+
throw aborted(path);
|
|
154
|
+
const chunk = await range(offset, SCAN_CHUNK_BYTES);
|
|
155
|
+
if (chunk.length > 0)
|
|
156
|
+
scanner.push(chunk);
|
|
157
|
+
if (chunk.length < SCAN_CHUNK_BYTES)
|
|
158
|
+
return scanner.finish();
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
close: async () => { },
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function aborted(path) {
|
|
165
|
+
return new FileError("aborted", "aborted", path);
|
|
166
|
+
}
|
|
167
|
+
function notFound(path) {
|
|
168
|
+
return new FileError("not_found", `${path} does not exist`, path);
|
|
169
|
+
}
|
|
170
|
+
function notSupported(operation, path) {
|
|
171
|
+
return err(new FileError("not_supported", `${operation} is not supported for files stored in the database`, path));
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=database-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-env.js","sourceRoot":"","sources":["../src/database-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAGN,cAAc,EACd,GAAG,EACH,SAAS,EAET,WAAW,EACX,EAAE,EAEF,OAAO,GACP,MAAM,gCAAgC,CAAC;AAGxC,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,sDAAsD;AACtD,MAAM,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AC;gBACR,MAAM,IAAI,SAAS,CAAC,SAAS,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC;YAC5D,CAAC;YACD,KAAK,IAAI,MAAM,GAAG,CAAC,GAAI,MAAM,IAAI,gBAAgB,EAAE,CAAC;gBACnD,IAAI,OAAO,CAAC,WAAW,EAAE,OAAO;oBAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACtD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;gBACpD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;oBAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1C,IAAI,KAAK,CAAC,MAAM,GAAG,gBAAgB;oBAAE,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;YAC9D,CAAC;QACF,CAAC,CAAC;QACH,KAAK,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;KACrB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC5B,OAAO,IAAI,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,IAAI,SAAS,CAAC,WAAW,EAAE,GAAG,IAAI,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CACpB,SAAiB,EACjB,IAAa;IAEb,OAAO,GAAG,CACT,IAAI,SAAS,CACZ,eAAe,EACf,GAAG,SAAS,oDAAoD,EAChE,IAAI,CACJ,CACD,CAAC;AACH,CAAC"}
|
package/dist/drain.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fifteen minutes, so a running model call or tool call can finish before a
|
|
3
|
-
*
|
|
3
|
+
* an upgrade restarts the actor. The engine's stop threshold still bounds it.
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_SLEEP_GRACE_PERIOD_MS: number;
|
|
6
6
|
/**
|
package/dist/drain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fifteen minutes, so a running model call or tool call can finish before a
|
|
3
|
-
*
|
|
3
|
+
* an upgrade restarts the actor. The engine's stop threshold still bounds it.
|
|
4
4
|
*/
|
|
5
5
|
export const DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 60_000;
|
|
6
6
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "rivetkit";
|
|
2
|
+
import type { PiActions, PiPromptOptions, PiPromptResult } from "./actions.js";
|
|
3
|
+
import { type PiAccess, type PiActorConfigInput, type PiEvents, type PiUserActions, pi } from "./actor.js";
|
|
4
|
+
import type { PiOptions } from "./runtime.js";
|
|
5
|
+
export * from "./index.js";
|
|
6
|
+
/** @deprecated Use `pi()` from `@rivet-dev/pi`. `piDurable()` is the same actor under its old name. */
|
|
7
|
+
export declare const piDurable: typeof pi;
|
|
8
|
+
/** @deprecated Use `PiActions` from `@rivet-dev/pi`. */
|
|
9
|
+
export type PiDurableActions = PiActions;
|
|
10
|
+
/** @deprecated Use `PiPromptOptions` from `@rivet-dev/pi`. */
|
|
11
|
+
export type PiDurablePromptOptions = PiPromptOptions;
|
|
12
|
+
/** @deprecated Use `PiPromptResult` from `@rivet-dev/pi`. */
|
|
13
|
+
export type PiDurablePromptResult = PiPromptResult;
|
|
14
|
+
/** @deprecated Use `PiAccess` from `@rivet-dev/pi`. */
|
|
15
|
+
export type PiDurableAccess = PiAccess;
|
|
16
|
+
/** @deprecated Use `PiActorConfigInput` from `@rivet-dev/pi`. */
|
|
17
|
+
export type PiDurableActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues> = Record<never, never>> = PiActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions>;
|
|
18
|
+
/** @deprecated Use `PiEvents` from `@rivet-dev/pi`. */
|
|
19
|
+
export type PiDurableEvents = PiEvents;
|
|
20
|
+
/** @deprecated Use `PiUserActions` from `@rivet-dev/pi`. */
|
|
21
|
+
export type PiDurableUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues>;
|
|
22
|
+
/** @deprecated Use `PiOptions` from `@rivet-dev/pi`. */
|
|
23
|
+
export type PiDurableOptions = PiOptions;
|
|
24
|
+
//# sourceMappingURL=durable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,EAAE,EACF,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,cAAc,YAAY,CAAC;AAE3B,uGAAuG;AACvG,eAAO,MAAM,SAAS,WAAK,CAAC;AAE5B,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACzC,8DAA8D;AAC9D,MAAM,MAAM,sBAAsB,GAAG,eAAe,CAAC;AACrD,6DAA6D;AAC7D,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC;AACnD,uDAAuD;AACvD,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;AACvC,iEAAiE;AACjE,MAAM,MAAM,yBAAyB,CACpC,MAAM,GAAG,SAAS,EAClB,WAAW,GAAG,SAAS,EACvB,UAAU,GAAG,SAAS,EACtB,KAAK,GAAG,SAAS,EACjB,MAAM,GAAG,SAAS,EAClB,OAAO,SAAS,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxD,OAAO,SAAS,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxD,YAAY,SAAS,aAAa,CACjC,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,CACP,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IACrB,kBAAkB,CACrB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,CACZ,CAAC;AACF,uDAAuD;AACvD,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;AACvC,4DAA4D;AAC5D,MAAM,MAAM,oBAAoB,CAC/B,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,SAAS,iBAAiB,EACjC,OAAO,SAAS,iBAAiB,IAC9B,aAAa,CAChB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,CACP,CAAC;AACF,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC"}
|
package/dist/durable.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":"AAEA,OAAO,EAKN,EAAE,GACF,MAAM,YAAY,CAAC;AAGpB,cAAc,YAAY,CAAC;AAE3B,uGAAuG;AACvG,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC"}
|