@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.
- 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.map +1 -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 +3 -4
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +11 -39
- package/dist/credentials.js.map +1 -1
- 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 +394 -406
- package/dist/runtime.js.map +1 -1
- package/dist/storage.d.ts +27 -45
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +28 -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} +1 -1
- package/dist/watches.d.ts.map +1 -0
- package/dist/{durable/watches.js → watches.js} +1 -1
- 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.map +0 -1
- 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/actor-sqlite.d.ts → actor-sqlite.d.ts} +0 -0
- /package/dist/{durable/actor-sqlite.js → actor-sqlite.js} +0 -0
- /package/dist/{durable/errors.d.ts → errors.d.ts} +0 -0
- /package/dist/{durable/errors.js → errors.js} +0 -0
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,EAAoB;IACzC,QAAQ,EAAE,KAAK,EAAc;CAC7B,CAAC;AA+DF,MAAM,YAAY,GAAG;IACpB,UAAU;IACV,QAAQ;IACR,UAAU;IACV,KAAK;IACL,qBAAqB;IACrB,KAAK;IACL,UAAU;IACV,OAAO;IACP,eAAe;IACf,cAAc;IACd,WAAW;IACX,SAAS;IACT,aAAa;IACb,SAAS;IACT,WAAW;CACqC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,EAAE,CA0BjB,MASC;IAaD,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,WAAW,CACtD,MAAM,EACN,YAAY,CACZ,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACd,8EAA8E,CAC9E,CAAC;IACH,CAAC;IACD,IAAI,WAAW,CAAC,EA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C,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;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,CAA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AAsB,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,62 +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
|
-
});
|
|
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;
|
|
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);
|
|
61
33
|
if ((await fn(current)) !== undefined) {
|
|
62
34
|
throw new Error(`pi actor cannot store credentials for ${providerId}; the credential source owns them`);
|
|
63
35
|
}
|
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
|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B,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
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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,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"}
|
|
@@ -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"}
|
|
@@ -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,
|
|
1
|
+
export type { PiActions, PiAgentChange, PiAgentInfo, PiCreateConversationOptions, PiPromptOptions, PiPromptResult, } from "./actions.js";
|
|
2
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.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"}
|
package/dist/models.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CreateModelRuntimeOptions, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { PiCredentialSource } from "./credentials.js";
|
|
3
3
|
import type { PiContext } from "./runtime.js";
|
|
4
4
|
/** Pi's credential store interface. `read`, `list`, `modify`, and `delete`, keyed by provider id. */
|
|
@@ -7,16 +7,13 @@ export type PiCredentialStore = NonNullable<CreateModelRuntimeOptions["credentia
|
|
|
7
7
|
export type PiCredential = NonNullable<Awaited<ReturnType<PiCredentialStore["read"]>>>;
|
|
8
8
|
/** A custom provider, the same shape as one entry of Pi's `models.json` `providers`. */
|
|
9
9
|
export type PiProviderConfig = Parameters<ModelRuntime["registerProvider"]>[1];
|
|
10
|
-
/** A model from Pi's catalog. */
|
|
11
|
-
export type PiModel = NonNullable<ReturnType<ModelRuntime["getModel"]>>;
|
|
12
10
|
/** Model and credential options accepted by `pi()`. */
|
|
13
11
|
export interface PiModelOptions {
|
|
14
|
-
/** The model
|
|
12
|
+
/** The model of every new conversation, as `provider/modelId`, such as `anthropic/claude-opus-5-5`. */
|
|
15
13
|
model?: string;
|
|
16
14
|
/**
|
|
17
|
-
* Models a client may
|
|
18
|
-
* Without it, only `model`.
|
|
19
|
-
* cycling, this is a hard limit.
|
|
15
|
+
* Models a client may choose with `conversation.configure`, as `provider/modelId`.
|
|
16
|
+
* Without it, only `model`.
|
|
20
17
|
*/
|
|
21
18
|
scopedModels?: string[];
|
|
22
19
|
/** Custom providers registered on the actor's model runtime. */
|
|
@@ -32,16 +29,6 @@ export interface PiModelOptions {
|
|
|
32
29
|
*/
|
|
33
30
|
credentials?: (c: PiContext) => PiCredentialSource;
|
|
34
31
|
}
|
|
35
|
-
/** A model a client may switch to. */
|
|
36
|
-
export interface PiModelInfo {
|
|
37
|
-
provider: string;
|
|
38
|
-
id: string;
|
|
39
|
-
name: string;
|
|
40
|
-
reasoning: boolean;
|
|
41
|
-
input: PiModel["input"];
|
|
42
|
-
contextWindow: number;
|
|
43
|
-
maxTokens: number;
|
|
44
|
-
}
|
|
45
32
|
/** The model options that decide which models a client may use. */
|
|
46
33
|
type AllowlistOptions = Pick<PiModelOptions, "model" | "scopedModels">;
|
|
47
34
|
/**
|
|
@@ -57,23 +44,5 @@ export declare const emptyCredentialStore: PiCredentialStore;
|
|
|
57
44
|
* `model` nor `scopedModels` set, a client may not choose any model.
|
|
58
45
|
*/
|
|
59
46
|
export declare function assertModelAllowed(options: AllowlistOptions, provider: string, modelId: string): void;
|
|
60
|
-
/**
|
|
61
|
-
* The model a session opens with: the model saved in the session when it is
|
|
62
|
-
* still allowed, otherwise the configured default. Undefined lets Pi choose,
|
|
63
|
-
* which only happens when no model is configured.
|
|
64
|
-
*/
|
|
65
|
-
export declare function openingModel(options: AllowlistOptions, runtime: ModelRuntime, saved: {
|
|
66
|
-
provider: string;
|
|
67
|
-
modelId: string;
|
|
68
|
-
} | null): PiModel | undefined;
|
|
69
|
-
/** Allowed models that have a credential, for a client's model picker. */
|
|
70
|
-
export declare function availableModels(options: AllowlistOptions, session: AgentSession): PiModelInfo[];
|
|
71
|
-
/** Throws `model_unavailable` when the session's model has no credential, for example after a logout. */
|
|
72
|
-
export declare function requireCredential(session: AgentSession): void;
|
|
73
|
-
/**
|
|
74
|
-
* Switches the session to an allowed model. The model object comes from the
|
|
75
|
-
* runtime's catalog, so a client can never choose the URL a key is sent to.
|
|
76
|
-
*/
|
|
77
|
-
export declare function switchModel(options: AllowlistOptions, session: AgentSession, provider: string, modelId: string): Promise<void>;
|
|
78
47
|
export {};
|
|
79
48
|
//# sourceMappingURL=models.d.ts.map
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,yBAAyB,EAC9B,YAAY,EACZ,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,qGAAqG;AACrG,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAC1C,yBAAyB,CAAC,aAAa,CAAC,CACxC,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG,WAAW,CACrC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAC9C,CAAC;AAEF,wFAAwF;AACxF,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/E,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC9B,uGAAuG;IACvG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC7C;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,kBAAkB,CAAC;CACnD;AAED,mEAAmE;AACnE,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,CAAC,CAAC;AAEvE;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,EAC5C,WAAW,EAAE,iBAAiB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAUvB;AAED,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,EAAE,iBAalC,CAAC;AAeF;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACb,IAAI,CAON"}
|
package/dist/models.js
CHANGED
|
@@ -45,74 +45,4 @@ export function assertModelAllowed(options, provider, modelId) {
|
|
|
45
45
|
throw new UserError(`Model ${provider}/${modelId} is not allowed for this agent.`, { code: "model_not_allowed" });
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
/** Looks up a `provider/modelId` in the actor's catalog. */
|
|
49
|
-
function catalogModel(runtime, name) {
|
|
50
|
-
const slash = name.indexOf("/");
|
|
51
|
-
const model = slash > 0
|
|
52
|
-
? runtime.getModel(name.slice(0, slash), name.slice(slash + 1))
|
|
53
|
-
: undefined;
|
|
54
|
-
if (!model) {
|
|
55
|
-
throw new Error(`pi() model ${name} is not in Pi's model catalog; add it with providers`);
|
|
56
|
-
}
|
|
57
|
-
return model;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The model a session opens with: the model saved in the session when it is
|
|
61
|
-
* still allowed, otherwise the configured default. Undefined lets Pi choose,
|
|
62
|
-
* which only happens when no model is configured.
|
|
63
|
-
*/
|
|
64
|
-
export function openingModel(options, runtime, saved) {
|
|
65
|
-
if (saved && isAllowed(options, saved.provider, saved.modelId)) {
|
|
66
|
-
const model = runtime.getModel(saved.provider, saved.modelId);
|
|
67
|
-
if (model)
|
|
68
|
-
return model;
|
|
69
|
-
}
|
|
70
|
-
const fallback = options.model ?? allowedModels(options)[0];
|
|
71
|
-
return fallback ? catalogModel(runtime, fallback) : undefined;
|
|
72
|
-
}
|
|
73
|
-
/** Allowed models that have a credential, for a client's model picker. */
|
|
74
|
-
export function availableModels(options, session) {
|
|
75
|
-
return session.modelRuntime
|
|
76
|
-
.getAvailableSnapshot()
|
|
77
|
-
.filter((model) => isAllowed(options, model.provider, model.id))
|
|
78
|
-
.map((model) => ({
|
|
79
|
-
provider: model.provider,
|
|
80
|
-
id: model.id,
|
|
81
|
-
name: model.name,
|
|
82
|
-
reasoning: model.reasoning,
|
|
83
|
-
input: model.input,
|
|
84
|
-
contextWindow: model.contextWindow,
|
|
85
|
-
maxTokens: model.maxTokens,
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
/** Throws `model_unavailable` when the session's model has no credential, for example after a logout. */
|
|
89
|
-
export function requireCredential(session) {
|
|
90
|
-
const model = session.model;
|
|
91
|
-
if (!model)
|
|
92
|
-
return;
|
|
93
|
-
const available = session.modelRuntime
|
|
94
|
-
.getAvailableSnapshot()
|
|
95
|
-
.some((candidate) => candidate.provider === model.provider && candidate.id === model.id);
|
|
96
|
-
if (!available) {
|
|
97
|
-
throw new UserError(`No credential is configured for ${model.provider}/${model.id}.`, {
|
|
98
|
-
code: "model_unavailable",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Switches the session to an allowed model. The model object comes from the
|
|
104
|
-
* runtime's catalog, so a client can never choose the URL a key is sent to.
|
|
105
|
-
*/
|
|
106
|
-
export async function switchModel(options, session, provider, modelId) {
|
|
107
|
-
assertModelAllowed(options, provider, modelId);
|
|
108
|
-
const model = session.modelRuntime
|
|
109
|
-
.getAvailableSnapshot()
|
|
110
|
-
.find((candidate) => candidate.provider === provider && candidate.id === modelId);
|
|
111
|
-
if (!model) {
|
|
112
|
-
throw new UserError(`No credential is configured for ${provider}/${modelId}.`, {
|
|
113
|
-
code: "model_unavailable",
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
await session.setModel(model);
|
|
117
|
-
}
|
|
118
48
|
//# sourceMappingURL=models.js.map
|
package/dist/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,GACZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AA2CrC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,OAA4C,EAC5C,WAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC;QAC5E,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QAC1E,MAAM,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAsB;IACtD,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;IA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