@rivet-dev/pi 0.1.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.
- package/LICENSE +190 -0
- package/dist/actions.d.ts +188 -77
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +276 -103
- package/dist/actions.js.map +1 -1
- package/dist/actor-config.d.ts +32 -0
- package/dist/actor-config.d.ts.map +1 -0
- package/dist/actor-config.js +86 -0
- package/dist/actor-config.js.map +1 -0
- package/dist/actor-sqlite.d.ts +10 -0
- package/dist/actor-sqlite.d.ts.map +1 -0
- package/dist/actor-sqlite.js +32 -0
- package/dist/actor-sqlite.js.map +1 -0
- package/dist/actor-types.d.ts +34 -0
- package/dist/actor-types.d.ts.map +1 -0
- package/dist/actor-types.js +2 -0
- package/dist/actor-types.js.map +1 -0
- package/dist/actor.d.ts +27 -15
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +71 -78
- package/dist/actor.js.map +1 -1
- package/dist/credentials.d.ts +3 -4
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +11 -38
- package/dist/credentials.js.map +1 -1
- package/dist/drain.d.ts +12 -0
- package/dist/drain.d.ts.map +1 -0
- package/dist/drain.js +20 -0
- package/dist/drain.js.map +1 -0
- 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 +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +7 -33
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +4 -67
- package/dist/models.js.map +1 -1
- package/dist/runtime.d.ts +111 -43
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +444 -225
- package/dist/runtime.js.map +1 -1
- package/dist/storage.d.ts +27 -28
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +33 -55
- package/dist/storage.js.map +1 -1
- package/dist/tracing.d.ts +7 -4
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +11 -12
- package/dist/tracing.js.map +1 -1
- package/dist/watches.d.ts +77 -0
- package/dist/watches.d.ts.map +1 -0
- package/dist/watches.js +245 -0
- package/dist/watches.js.map +1 -0
- package/package.json +38 -15
- package/dist/sandbox.d.ts +0 -21
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/sandbox.js +0 -185
- package/dist/sandbox.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ActionContext, ActorConfigInput, ActorDefinition, Conn, ConnectContext, DestroyContext, DisconnectContext, EventSchemaConfig, QueueSchemaConfig, SleepContext, WakeContext } from "rivetkit";
|
|
2
|
+
import type { PiDatabaseProvider } from "./runtime.js";
|
|
3
|
+
/** `Omit` that keeps each member of a union, so `state` and `createState` stay alternatives. */
|
|
4
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
5
|
+
/** The app's actions as clients see them: the same arguments, without `c.pi`. */
|
|
6
|
+
type ClientActions<T, TContext> = string extends keyof T ? Record<never, never> : {
|
|
7
|
+
[K in keyof T]: T[K] extends (c: any, ...args: infer TArgs) => infer TResult ? (c: TContext, ...args: TArgs) => TResult : ClientActions<T[K], TContext>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The app's own actions, which get `c.pi` through `TAccess`. Nested objects
|
|
11
|
+
* become dotted action names.
|
|
12
|
+
*/
|
|
13
|
+
export interface UserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TAccess> {
|
|
14
|
+
[action: string]: ((c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess, ...args: any[]) => any) | UserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TAccess>;
|
|
15
|
+
}
|
|
16
|
+
/** Lifecycle hooks that get `c.pi` through `TAccess`. */
|
|
17
|
+
interface UserHooks<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TAccess> {
|
|
18
|
+
onWake?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess) => void | Promise<void>;
|
|
19
|
+
onSleep?: (c: SleepContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess) => void | Promise<void>;
|
|
20
|
+
onDestroy?: (c: DestroyContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess) => void | Promise<void>;
|
|
21
|
+
onConnect?: (c: ConnectContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues>) => void | Promise<void>;
|
|
22
|
+
onDisconnect?: (c: DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> & TAccess, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues>) => void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ordinary actor config with the app's actions and hooks typed to get `c.pi`,
|
|
26
|
+
* plus the Pi options in `TOptions`.
|
|
27
|
+
*/
|
|
28
|
+
export type UserActorConfig<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TUserActions, TOptions, TAccess> = DistributiveOmit<ActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues>, "actions" | keyof UserHooks<any, any, any, any, any, any, any, unknown>> & UserHooks<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TAccess> & TOptions & {
|
|
29
|
+
actions?: TUserActions;
|
|
30
|
+
};
|
|
31
|
+
/** The actor definition clients see: the app's actions and events plus the built-in ones. */
|
|
32
|
+
export type PiActorDefinition<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TUserActions, TBuiltInEvents extends EventSchemaConfig, TBuiltInActions> = ActorDefinition<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents & TBuiltInEvents, TQueues, ClientActions<TUserActions, ActionContext<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues>> & TBuiltInActions>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=actor-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-types.d.ts","sourceRoot":"","sources":["../src/actor-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,gGAAgG;AAChG,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,OAAO,GAChE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACV,KAAK,CAAC;AAET,iFAAiF;AACjF,KAAK,aAAa,CAAC,CAAC,EAAE,QAAQ,IAAI,MAAM,SAAS,MAAM,CAAC,GACrD,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GACpB;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAC5B,CAAC,EAAE,GAAG,EACN,GAAG,IAAI,EAAE,MAAM,KAAK,KAChB,MAAM,O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AAG,EAAE,OAAO,CAAC,CACvE,GACA,SAAS,CACR,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,CACP,GACD,QAAQ,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC;AAEvC,6FAA6F;AAC7F,MAAM,MAAM,iBAAiB,CAC5B,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,SAAS,iBAAiB,EACjC,OAAO,SAAS,iBAAiB,EACjC,YAAY,EACZ,cAAc,SAAS,iBAAiB,EACxC,eAAe,IACZ,eAAe,CAClB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,kBAAkB,EAClB,OAAO,GAAG,cAAc,EACxB,OAAO,EACP,aAAa,CACZ,YAAY,EACZ,aAAa,CACZ,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,kBAAkB,EAClB,OAAO,EACP,OAAO,CACP,CACD,GACA,eAAe,CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-types.js","sourceRoot":"","sources":["../src/actor-types.ts"],"names":[],"mappings":""}
|
package/dist/actor.d.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type
|
|
1
|
+
import type { Harness } from "@earendil-works/pi-durable";
|
|
2
|
+
import { type EventSchemaConfig, type QueueSchemaConfig, type Type } from "rivetkit";
|
|
3
3
|
import { type PiActions } from "./actions.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import type { PiActorDefinition, UserActions, UserActorConfig } from "./actor-types.js";
|
|
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`. */
|
|
6
8
|
export type PiEvents = {
|
|
7
|
-
|
|
9
|
+
"pi.events": Type<PiEventsFrame>;
|
|
10
|
+
"pi.view": Type<PiViewFrame>;
|
|
11
|
+
"pi.taskGraph": Type<PiTaskGraphFrame>;
|
|
12
|
+
"pi.doc": Type<PiDocFrame>;
|
|
8
13
|
};
|
|
9
|
-
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 Actions<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues> = Record<never, never>> = ActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, PiDatabaseProvider, TEvents, TQueues, TUserActions> & PiSessionOptions;
|
|
10
14
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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.
|
|
13
19
|
*/
|
|
14
|
-
|
|
20
|
+
export interface PiAccess {
|
|
21
|
+
readonly pi: Harness;
|
|
22
|
+
}
|
|
23
|
+
/** The app's own actions, which get `c.pi`. Nested objects become dotted action names. */
|
|
24
|
+
export type PiUserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = UserActions<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, PiAccess>;
|
|
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>;
|
|
15
27
|
/**
|
|
16
|
-
* Defines a Rivet Actor that owns one Pi
|
|
28
|
+
* Defines a Rivet Actor that owns one Pi Durable harness.
|
|
17
29
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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`.
|
|
21
34
|
*/
|
|
22
|
-
export declare function pi<TState, TConnParams, TConnState, TVars, TInput, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends
|
|
23
|
-
export {};
|
|
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>;
|
|
24
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,EAAE,
|
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,O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M,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,eAAe,CAClB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,SAAS,EACT,QAAQ,CACR,CAAC;AAoBF;;;;;;;GAOG;AACH,wBAAgB,EAAE,CACjB,MAAM,EACN,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,EACN,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,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
|
@@ -1,113 +1,106 @@
|
|
|
1
1
|
import { actor, event, } from "rivetkit";
|
|
2
2
|
import { db } from "rivetkit/db";
|
|
3
3
|
import { createPiActions } from "./actions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { assertNoReservedNames, sharedActorConfig, splitConfig, wrapActions, } from "./actor-config.js";
|
|
5
|
+
import { closeHarness, createPiRuntime, openOnWake, PI_RUNTIME, piRuntime, withPiAccess, withUnavailablePi, } from "./runtime.js";
|
|
5
6
|
import { migratePiTables } from "./storage.js";
|
|
6
|
-
|
|
7
|
-
const DEFAULT_ACTION_TIMEOUT_MS = 10 * 60_000;
|
|
7
|
+
import { unwatchConnection, } from "./watches.js";
|
|
8
8
|
const piEvents = {
|
|
9
|
-
|
|
9
|
+
"pi.events": event(),
|
|
10
|
+
"pi.view": event(),
|
|
11
|
+
"pi.taskGraph": event(),
|
|
12
|
+
"pi.doc": event(),
|
|
10
13
|
};
|
|
11
14
|
const piOptionKeys = [
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"registry",
|
|
16
|
+
"models",
|
|
17
|
+
"settings",
|
|
18
|
+
"env",
|
|
19
|
+
"conversationCreated",
|
|
20
|
+
"now",
|
|
21
|
+
"onReport",
|
|
17
22
|
"model",
|
|
18
23
|
"thinkingLevel",
|
|
19
24
|
"scopedModels",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"customTools",
|
|
24
|
-
"resourceLoader",
|
|
25
|
-
"sessionStartEvent",
|
|
26
|
-
"settings",
|
|
25
|
+
"providers",
|
|
26
|
+
"apiKeys",
|
|
27
|
+
"credentials",
|
|
27
28
|
"sandbox",
|
|
29
|
+
"documents",
|
|
28
30
|
];
|
|
29
31
|
/**
|
|
30
|
-
* Defines a Rivet Actor that owns one Pi
|
|
32
|
+
* Defines a Rivet Actor that owns one Pi Durable harness.
|
|
31
33
|
*
|
|
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,
|
|
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(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const actions = createPiActions(piOptions);
|
|
48
|
+
assertNoReservedNames("pi()", actorConfig, {
|
|
49
|
+
action: actions,
|
|
50
|
+
event: piEvents,
|
|
51
|
+
});
|
|
52
|
+
const withPi = (hook, opensHarness = true) => hook &&
|
|
53
|
+
((c, ...args) => withPiAccess(c, piOptions, () => hook(c, ...args), {
|
|
54
|
+
opensHarness,
|
|
55
|
+
}));
|
|
56
|
+
const userOnWake = actorConfig.onWake;
|
|
57
|
+
const userOnDisconnect = withPi(actorConfig.onDisconnect);
|
|
58
|
+
// The config is built from untyped parts, so `actor()` cannot check it
|
|
59
|
+
// against the generics. The declared return type is the public contract.
|
|
49
60
|
return actor({
|
|
50
|
-
...actorConfig,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
61
|
+
...sharedActorConfig("pi()", actorConfig, { slot: PI_RUNTIME, create: createPiRuntime }, (c, stop) => closeHarness(c, piOptions, stop), {
|
|
62
|
+
onSleep: withPi(actorConfig.onSleep, false),
|
|
63
|
+
onDestroy: withPi(actorConfig.onDestroy, false),
|
|
64
|
+
}),
|
|
55
65
|
db: db({ onMigrate: migratePiTables }),
|
|
56
66
|
events: { ...(actorConfig.events ?? {}), ...piEvents },
|
|
57
|
-
actions: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
? await userCreateVars(c, driverCtx)
|
|
61
|
-
: userVars === undefined
|
|
62
|
-
? undefined
|
|
63
|
-
: structuredClone(userVars);
|
|
64
|
-
return attachRuntime(vars);
|
|
67
|
+
actions: {
|
|
68
|
+
...wrapActions(actorConfig.actions ?? {}, (c, action) => withPiAccess(c, piOptions, action)),
|
|
69
|
+
...actions,
|
|
65
70
|
},
|
|
66
|
-
|
|
71
|
+
// Opening on wake resumes interrupted work, after the app's own onWake.
|
|
72
|
+
onWake: async (c) => {
|
|
73
|
+
let harness;
|
|
67
74
|
try {
|
|
68
|
-
await
|
|
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.
|
|
80
|
+
c.log.error({
|
|
81
|
+
msg: "pi durable could not open on wake; actions will retry",
|
|
82
|
+
error,
|
|
83
|
+
});
|
|
84
|
+
return withUnavailablePi(c, error, () => userOnWake?.(c));
|
|
85
|
+
}
|
|
86
|
+
Object.defineProperty(c, "pi", { value: harness, configurable: true });
|
|
87
|
+
try {
|
|
88
|
+
await userOnWake?.(c);
|
|
69
89
|
}
|
|
70
90
|
finally {
|
|
71
|
-
|
|
91
|
+
harness.resume();
|
|
72
92
|
}
|
|
73
93
|
},
|
|
74
|
-
|
|
94
|
+
onConnect: withPi(actorConfig.onConnect),
|
|
95
|
+
onDisconnect: async (c, conn) => {
|
|
75
96
|
try {
|
|
76
|
-
await
|
|
97
|
+
await userOnDisconnect?.(c, conn);
|
|
77
98
|
}
|
|
78
99
|
finally {
|
|
79
|
-
|
|
100
|
+
const runtime = piRuntime(c);
|
|
101
|
+
await unwatchConnection(runtime.actor ?? c, runtime.watches, conn.id);
|
|
80
102
|
}
|
|
81
103
|
},
|
|
82
104
|
});
|
|
83
105
|
}
|
|
84
|
-
function splitConfig(config) {
|
|
85
|
-
const actorConfig = { ...config };
|
|
86
|
-
const sessionOptions = {};
|
|
87
|
-
for (const key of piOptionKeys) {
|
|
88
|
-
if (key in actorConfig) {
|
|
89
|
-
sessionOptions[key] = actorConfig[key];
|
|
90
|
-
delete actorConfig[key];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { actorConfig, sessionOptions: sessionOptions };
|
|
94
|
-
}
|
|
95
|
-
/** Adds the Pi runtime slot to the user's vars without changing their shape. */
|
|
96
|
-
function attachRuntime(vars) {
|
|
97
|
-
const runtime = createPiRuntime();
|
|
98
|
-
if (vars === undefined) {
|
|
99
|
-
return { [PI_RUNTIME]: runtime };
|
|
100
|
-
}
|
|
101
|
-
if (typeof vars !== "object" || vars === null) {
|
|
102
|
-
throw new Error("pi() requires actor vars to be an object");
|
|
103
|
-
}
|
|
104
|
-
return Object.assign(vars, { [PI_RUNTIME]: runtime });
|
|
105
|
-
}
|
|
106
|
-
function assertNoReservedKeys(kind, custom, builtIns) {
|
|
107
|
-
for (const key of Object.keys(custom ?? {})) {
|
|
108
|
-
if (key in builtIns) {
|
|
109
|
-
throw new Error(`pi() ${kind} name is reserved: ${key}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
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":"AACA,OAAO,
|
|
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,qBAAq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AAC;gBACJ,OAAO,GAAG,MAAM,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YAC1C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,gEAAgE;gBAChE,oDAAoD;gBACpD,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;oBACX,GAAG,EAAE,uDAAuD;oBAC5D,KAAK;iBACL,CAAC,CAAC;gBACH,OAAO,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,CAAC,cAAc,CAAC,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
|
@@ -35,14 +35,13 @@ export interface PiCredentialSource {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Adapts an application's credential source to Pi's credential store. It
|
|
38
|
-
* reads only providers the source lists,
|
|
39
|
-
*
|
|
38
|
+
* reads only providers the source lists, asks the source each time Pi needs a
|
|
39
|
+
* credential, so logins and logouts apply to the next model call, and never
|
|
40
|
+
* writes.
|
|
40
41
|
*/
|
|
41
42
|
export declare class SourceCredentialStore implements PiCredentialStore {
|
|
42
43
|
#private;
|
|
43
44
|
constructor(source: PiCredentialSource);
|
|
44
|
-
/** Drops what was read so the next read sees new logins and logouts. */
|
|
45
|
-
invalidate(): void;
|
|
46
45
|
list(): Promise<PiCredentialInfo[]>;
|
|
47
46
|
read(providerId: string): Promise<PiCredential | undefined>;
|
|
48
47
|
/**
|
|
@@ -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;
|
|
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,iDAAiD;IACjD,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IACpE;;;;OAIG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;CACvE;AAKD;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;;gBAGlD,MAAM,EAAE,kBAAkB;IAItC,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI7B,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAMjE;;;OAGG;IACG,MAAM,CACX,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,CACH,OAAO,EAAE,YAAY,GAAG,SAAS,KAC7B,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,GACpC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAmB9B,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAK/C"}
|
package/dist/credentials.js
CHANGED
|
@@ -2,61 +2,34 @@
|
|
|
2
2
|
const PI_OAUTH_MIN_VALIDITY_MS = 5 * 60_000;
|
|
3
3
|
/**
|
|
4
4
|
* Adapts an application's credential source to Pi's credential store. It
|
|
5
|
-
* reads only providers the source lists,
|
|
6
|
-
*
|
|
5
|
+
* reads only providers the source lists, asks the source each time Pi needs a
|
|
6
|
+
* credential, so logins and logouts apply to the next model call, and never
|
|
7
|
+
* writes.
|
|
7
8
|
*/
|
|
8
9
|
export class SourceCredentialStore {
|
|
9
10
|
#source;
|
|
10
|
-
#listed;
|
|
11
|
-
#read = new Map();
|
|
12
11
|
constructor(source) {
|
|
13
12
|
this.#source = source;
|
|
14
13
|
}
|
|
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
14
|
list() {
|
|
21
|
-
|
|
22
|
-
this.#listed = undefined;
|
|
23
|
-
throw error;
|
|
24
|
-
});
|
|
25
|
-
return this.#listed;
|
|
15
|
+
return this.#source.list();
|
|
26
16
|
}
|
|
27
17
|
async read(providerId) {
|
|
28
18
|
if (!(await this.list()).some((entry) => entry.providerId === providerId))
|
|
29
19
|
return undefined;
|
|
30
|
-
|
|
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;
|
|
20
|
+
return toPiCredential(await this.#source.read(providerId));
|
|
42
21
|
}
|
|
43
22
|
/**
|
|
44
23
|
* Pi calls this to refresh a subscription token that expires soon. The
|
|
45
24
|
* source refreshes it, so `fn` sees a fresh credential and never writes.
|
|
46
25
|
*/
|
|
47
26
|
async modify(providerId, fn) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.#read.set(providerId, refreshed);
|
|
55
|
-
refreshed.catch(() => {
|
|
56
|
-
if (this.#read.get(providerId) === refreshed)
|
|
57
|
-
this.#read.delete(providerId);
|
|
58
|
-
});
|
|
59
|
-
const current = await refreshed;
|
|
27
|
+
const credential = await this.#source.refresh(providerId);
|
|
28
|
+
if (credential?.type === "oauth" &&
|
|
29
|
+
credential.expires - Date.now() <= PI_OAUTH_MIN_VALIDITY_MS) {
|
|
30
|
+
throw new Error(`the credential source returned a ${providerId} token that expires within five minutes`);
|
|
31
|
+
}
|
|
32
|
+
const current = toPiCredential(credential);
|
|
60
33
|
if ((await fn(current)) !== undefined) {
|
|
61
34
|
throw new Error(`pi actor cannot store credentials for ${providerId}; the credential source owns them`);
|
|
62
35
|
}
|
package/dist/credentials.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAuCA,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,CAAC,GAAG,MAAM,CAAC;AAE5C;;;;;GAKG;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,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC;YACxE,OAAO,SAAS,CAAC;QAClB,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"}
|
package/dist/drain.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fifteen minutes, so a running model call or tool call can finish before a
|
|
3
|
+
* an upgrade restarts the actor. The engine's stop threshold still bounds it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_SLEEP_GRACE_PERIOD_MS: number;
|
|
6
|
+
/**
|
|
7
|
+
* The time a drain must end by. RivetKit's grace deadline starts when the
|
|
8
|
+
* stop starts, just before `onSleep` runs, so the caller takes this before the
|
|
9
|
+
* app's own `onSleep`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function drainDeadline(gracePeriodMs: number): number;
|
|
12
|
+
//# sourceMappingURL=drain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../src/drain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAc,CAAC;AAQzD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAG3D"}
|
package/dist/drain.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fifteen minutes, so a running model call or tool call can finish before a
|
|
3
|
+
* an upgrade restarts the actor. The engine's stop threshold still bounds it.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 60_000;
|
|
6
|
+
/**
|
|
7
|
+
* Time kept back from the grace period for closing Pi and suspending the
|
|
8
|
+
* sandbox after a drain, so both finish before RivetKit's grace deadline.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_CLOSE_RESERVE_MS = 30_000;
|
|
11
|
+
/**
|
|
12
|
+
* The time a drain must end by. RivetKit's grace deadline starts when the
|
|
13
|
+
* stop starts, just before `onSleep` runs, so the caller takes this before the
|
|
14
|
+
* app's own `onSleep`.
|
|
15
|
+
*/
|
|
16
|
+
export function drainDeadline(gracePeriodMs) {
|
|
17
|
+
const closeReserve = Math.min(MAX_CLOSE_RESERVE_MS, gracePeriodMs / 4);
|
|
18
|
+
return Date.now() + gracePeriodMs - closeReserve;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=drain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.js","sourceRoot":"","sources":["../src/drain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,GAAG,MAAM,CAAC;AAEzD;;;GAGG;AACH,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,aAAqB;IAClD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,aAAa,GAAG,CAAC,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,GAAG,YAAY,CAAC;AAClD,CAAC"}
|
|
@@ -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"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error a client receives for a failed Pi Durable call. `ConversationBusy`
|
|
3
|
+
* is the one Pi error a caller is meant to handle, so it becomes a
|
|
4
|
+
* `UserError` with Pi's error name as the code. Every other error is returned
|
|
5
|
+
* as is, and RivetKit reports it to clients as an internal error.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toClientError(error: unknown): unknown;
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASrD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConversationBusy } from "@earendil-works/pi-durable";
|
|
2
|
+
import { UserError } from "rivetkit";
|
|
3
|
+
/**
|
|
4
|
+
* The error a client receives for a failed Pi Durable call. `ConversationBusy`
|
|
5
|
+
* is the one Pi error a caller is meant to handle, so it becomes a
|
|
6
|
+
* `UserError` with Pi's error name as the code. Every other error is returned
|
|
7
|
+
* as is, and RivetKit reports it to clients as an internal error.
|
|
8
|
+
*/
|
|
9
|
+
export function toClientError(error) {
|
|
10
|
+
if (error instanceof ConversationBusy) {
|
|
11
|
+
return new UserError(error.message, {
|
|
12
|
+
code: error.name,
|
|
13
|
+
metadata: { conversationId: error.conversationId },
|
|
14
|
+
cause: error,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type { PiActions,
|
|
2
|
-
export {
|
|
1
|
+
export type { PiActions, PiAgentChange, PiAgentInfo, PiCreateConversationOptions, PiPromptOptions, PiPromptResult, } from "./actions.js";
|
|
2
|
+
export { type PiAccess, type PiActorConfigInput, type PiEvents, type PiUserActions, pi, } from "./actor.js";
|
|
3
3
|
export type { PiCredentialInfo, PiCredentialSource, PiProviderCredential, } from "./credentials.js";
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
4
|
+
export type { PiModelOptions, PiProviderConfig } from "./models.js";
|
|
5
|
+
export type { PiOptions } from "./runtime.js";
|
|
6
|
+
export type { PiDocFrame, PiEventsFrame, PiTaskGraphFrame, PiViewFrame, PiWatchEvents, } from "./watches.js";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,SAAS,EACT,aAAa,EACb,WAAW,EACX,2BAA2B,EAC3B,eAAe,EACf,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,EAAE,GACF,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EACX,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,GACb,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { pi } from "./actor.js";
|
|
1
|
+
export { pi, } from "./actor.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAKN,EAAE,GACF,MAAM,YAAY,CAAC"}
|