@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
|
@@ -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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AAC,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,SAAS,CACjB,OAAyB,EACzB,QAAgB,EAChB,OAAe;IAEf,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAyB,EACzB,QAAgB,EAChB,OAAe;IAEf,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,SAAS,CAClB,SAAS,QAAQ,IAAI,OAAO,iCAAiC,EAC7D,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAC7B,CAAC;IACH,CAAC;AACF,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { Models, ModelThinkingLevel } from "@earendil-works/pi-ai";
|
|
3
|
+
import { type ConversationDocToken, Harness, type HarnessOptions, type HarnessSettings, type ModelRef } from "@earendil-works/pi-durable";
|
|
2
4
|
import type { Sandbox, SandboxProvider } from "@rivet-dev/sandbox-adapter";
|
|
3
5
|
import { type ActorContext } from "rivetkit";
|
|
4
6
|
import type { DatabaseProvider, RawAccess } from "rivetkit/db";
|
|
5
|
-
import { SourceCredentialStore } from "./credentials.js";
|
|
6
7
|
import { type PiModelOptions } from "./models.js";
|
|
7
|
-
import { type
|
|
8
|
+
import { type ConnectionWatches } from "./watches.js";
|
|
8
9
|
export type PiDatabaseProvider = DatabaseProvider<RawAccess>;
|
|
9
10
|
/** The actor context shape every Pi helper works against. */
|
|
10
11
|
export type PiContext = ActorContext<any, any, any, any, any, PiDatabaseProvider, any, any>;
|
|
@@ -15,70 +16,102 @@ export type PiStop = {
|
|
|
15
16
|
} | {
|
|
16
17
|
reason: "destroy";
|
|
17
18
|
};
|
|
18
|
-
/**
|
|
19
|
-
export interface PiSessionOptions extends Omit<CreateAgentSessionOptions, "sessionManager" | "settingsManager" | "modelRuntime" | "model" | "scopedModels">, PiModelOptions {
|
|
20
|
-
/** Initial Pi settings for a brand-new session. Later changes persist per actor. */
|
|
21
|
-
settings?: Partial<PiSettings>;
|
|
22
|
-
/**
|
|
23
|
-
* Runs Pi's built-in file and shell tools in a sandbox. Without one, Pi has
|
|
24
|
-
* no file or shell tools and only the `customTools` passed in.
|
|
25
|
-
*/
|
|
26
|
-
sandbox?: SandboxProvider;
|
|
27
|
-
}
|
|
28
|
-
/** One open Pi session for a live actor generation. */
|
|
29
|
-
export interface PiSession {
|
|
30
|
-
session: AgentSession;
|
|
31
|
-
settingsManager: SettingsManager;
|
|
32
|
-
cwd: string;
|
|
33
|
-
sandbox: LazySandbox | undefined;
|
|
34
|
-
/** Command execution for `executeBash`. Undefined when there is no sandbox. */
|
|
35
|
-
bashOperations: BashOperations | undefined;
|
|
36
|
-
/** JSON of the settings last written to SQLite, to skip no-op writes. */
|
|
37
|
-
persistedSettings: string;
|
|
38
|
-
/** Entries (header excluded) already written to SQLite, in Pi's append order. */
|
|
39
|
-
persistedEntryCount: number;
|
|
40
|
-
/** The application's credentials, when `pi({ credentials })` is set. */
|
|
41
|
-
credentials: SourceCredentialStore | undefined;
|
|
42
|
-
}
|
|
43
|
-
/** The sandbox a session's tools run in for this actor generation. */
|
|
19
|
+
/** The sandbox Pi's tools run in for this actor generation. */
|
|
44
20
|
export interface ConnectedSandbox {
|
|
45
21
|
provider: SandboxProvider;
|
|
46
22
|
id: string;
|
|
47
23
|
sandbox: Sandbox;
|
|
48
24
|
}
|
|
49
25
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
26
|
+
* Options accepted by `pi()` on top of ordinary actor config. The Pi
|
|
27
|
+
* Durable options keep the names and types of `HarnessOptions`.
|
|
52
28
|
*/
|
|
53
|
-
interface
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
29
|
+
export interface PiOptions extends PiModelOptions {
|
|
30
|
+
/** Pi Durable's extension registry: tools, hooks, sections, tasks, and documents. */
|
|
31
|
+
registry: HarnessOptions["registry"];
|
|
32
|
+
/** pi-ai model access. Without it, the actor builds it from `model`, `providers`, `apiKeys`, and `credentials`. */
|
|
33
|
+
models?: Models;
|
|
34
|
+
settings?: HarnessSettings;
|
|
35
|
+
/**
|
|
36
|
+
* Builds a conversation's environment. Without it, the actor builds one from
|
|
37
|
+
* `sandbox`, or stores files in its own database when there is no sandbox.
|
|
38
|
+
*/
|
|
39
|
+
env?: HarnessOptions["env"];
|
|
40
|
+
conversationCreated?: HarnessOptions["conversationCreated"];
|
|
41
|
+
now?: HarnessOptions["now"];
|
|
42
|
+
onReport?: HarnessOptions["onReport"];
|
|
43
|
+
/** The starting thinking level of every new conversation. */
|
|
44
|
+
thinkingLevel?: ModelThinkingLevel;
|
|
45
|
+
/**
|
|
46
|
+
* Runs the tools of Pi's `CodingTools` extension in a sandbox. Used only
|
|
47
|
+
* when `env` is omitted. Without a sandbox, files live in the actor's
|
|
48
|
+
* database and there is no shell.
|
|
49
|
+
*/
|
|
50
|
+
sandbox?: SandboxProvider;
|
|
51
|
+
/** App documents that clients may read by `kind` with `harness.snapshot`. */
|
|
52
|
+
documents?: readonly ConversationDocToken<any>[];
|
|
53
|
+
}
|
|
54
|
+
interface OpenHarness {
|
|
55
|
+
harness: Harness;
|
|
56
|
+
stopBusyWatch: () => void;
|
|
57
|
+
isBusy: () => Promise<boolean>;
|
|
57
58
|
}
|
|
58
|
-
/** Per-actor-generation
|
|
59
|
+
/** Per-actor-generation state, stored on `c.vars` under `PI_RUNTIME`. */
|
|
59
60
|
export interface PiRuntime {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/** Set
|
|
61
|
+
/** The open harness, or the open in progress. */
|
|
62
|
+
harness?: Promise<OpenHarness>;
|
|
63
|
+
sandbox?: Promise<ConnectedSandbox>;
|
|
64
|
+
/** Set when the actor starts to sleep or is destroyed. */
|
|
64
65
|
closing: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The `onWake` context. Background work (keep-awake, scheduled wakes, the
|
|
68
|
+
* sandbox, reopening) uses it, because an action's context is cancelled
|
|
69
|
+
* with the action.
|
|
70
|
+
*/
|
|
71
|
+
actor?: PiContext;
|
|
72
|
+
/** Open Pi watches of connections, for this generation. */
|
|
73
|
+
watches: ConnectionWatches;
|
|
65
74
|
}
|
|
66
75
|
export declare const PI_RUNTIME: unique symbol;
|
|
67
76
|
export declare function createPiRuntime(): PiRuntime;
|
|
68
77
|
export declare function piRuntime(c: PiContext): PiRuntime;
|
|
69
|
-
/** Returns the actor's Pi session, opening it from SQLite on first use. */
|
|
70
|
-
export declare function ensurePiSession(c: PiContext, options: PiSessionOptions): Promise<PiSession>;
|
|
71
78
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* `c.pi` throws the open error. Shutdown hooks pass `opensSession: false`, so
|
|
76
|
-
* they use a session that is already open and never create a session or a
|
|
77
|
-
* sandbox only to close it.
|
|
79
|
+
* Opens the harness on wake without resuming interrupted work, so the app's
|
|
80
|
+
* `onWake` runs first. The caller calls `harness.resume()` after it. The wake
|
|
81
|
+
* context becomes the context of all background work.
|
|
78
82
|
*/
|
|
79
|
-
export declare function
|
|
80
|
-
|
|
83
|
+
export declare function openOnWake(c: PiContext, options: PiOptions): Promise<Harness>;
|
|
84
|
+
/**
|
|
85
|
+
* Runs an action against the harness. A failed call that left Pi Durable
|
|
86
|
+
* unusable reopens it before the error reaches the client, so the next call
|
|
87
|
+
* works. Calls use `BACKGROUND_CONTEXT`, so a wait such as `prompt` lasts
|
|
88
|
+
* until the run settles or the action times out, including while a stopping
|
|
89
|
+
* actor drains the run. RivetKit's action signal also fires when the actor
|
|
90
|
+
* starts to stop, so it cannot cancel a wait.
|
|
91
|
+
*/
|
|
92
|
+
export declare function withHarness<T>(c: PiContext, options: PiOptions, run: (harness: Harness, context: Context) => Promise<T>): Promise<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Runs one of the app's own actions or hooks with the harness on `c.pi`. A
|
|
95
|
+
* failure that left Pi Durable unusable reopens it. The error reaches the
|
|
96
|
+
* client as from a built-in action. Code that never reads `c.pi` runs even
|
|
97
|
+
* when Pi Durable is closed or cannot open; reading `c.pi` throws the cause.
|
|
98
|
+
* Shutdown hooks pass `opensHarness: false`, so they use a harness that is
|
|
99
|
+
* already open and never open and resume one only to close it.
|
|
100
|
+
*/
|
|
101
|
+
export declare function withPiAccess<T>(c: PiContext, options: PiOptions, body: () => T | Promise<T>, { opensHarness }?: {
|
|
102
|
+
opensHarness?: boolean;
|
|
81
103
|
}): Promise<T>;
|
|
104
|
+
/** App documents by `kind`, for clients that name a document. */
|
|
105
|
+
export declare function documentsByKind(options: PiOptions): ReadonlyMap<string, ConversationDocToken<any>>;
|
|
106
|
+
/** Parses `provider/modelId`. */
|
|
107
|
+
export declare function parseModelRef(name: string): ModelRef;
|
|
108
|
+
/**
|
|
109
|
+
* Closes Pi Durable for this actor generation. On sleep it drains first. On
|
|
110
|
+
* destroy it stops running work at once. Records of interrupted work stay
|
|
111
|
+
* running, and the next open resumes them. Then suspends the sandbox on
|
|
112
|
+
* sleep, or destroys it on destroy.
|
|
113
|
+
*/
|
|
114
|
+
export declare function closeHarness(c: PiContext, options: PiOptions, stop: PiStop): Promise<void>;
|
|
82
115
|
/** Runs `body` with a `c.pi` that throws `error` when read. */
|
|
83
116
|
export declare function withUnavailablePi<T>(c: PiContext, error: unknown, body: () => T | Promise<T>): T | Promise<T>;
|
|
84
117
|
/**
|
|
@@ -86,39 +119,9 @@ export declare function withUnavailablePi<T>(c: PiContext, error: unknown, body:
|
|
|
86
119
|
* provider reports the stored one no longer exists. A new sandbox id is saved
|
|
87
120
|
* as soon as `create` returns, so a failure later in the start reuses it. Any
|
|
88
121
|
* other connect failure is thrown, so a temporary outage never replaces a
|
|
89
|
-
* sandbox.
|
|
122
|
+
* sandbox.
|
|
90
123
|
*/
|
|
91
124
|
export declare function connectSandbox(c: PiContext, provider: SandboxProvider): Promise<ConnectedSandbox>;
|
|
92
|
-
/**
|
|
93
|
-
* Continues the run that was active when the actor stopped, when Pi's own
|
|
94
|
-
* `Agent.continue()` accepts the transcript: its last message is a user or a
|
|
95
|
-
* tool result message. Otherwise the chat stays as Pi left it, as after an
|
|
96
|
-
* abort. The run continues in the background and keeps the actor awake.
|
|
97
|
-
*/
|
|
98
|
-
export declare function resumeInterruptedRun(c: PiContext, options: PiSessionOptions): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Queues entries appended since the last flush and writes Pi's mutable settings
|
|
101
|
-
* when they changed. Called after every action and on shutdown.
|
|
102
|
-
*/
|
|
103
|
-
export declare function persistPiState(c: PiContext, handle: PiSession): Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Aborts the run in memory when RivetKit declares this actor generation lost.
|
|
106
|
-
* The engine may already run the next generation, which resumes the run, so
|
|
107
|
-
* the lost one must stop calling the model and running tools. A lost
|
|
108
|
-
* generation skips `onSleep`, and its storage rejects writes, so nothing is
|
|
109
|
-
* stored here. A normal stop fires the same signal and drains in `onSleep`.
|
|
110
|
-
* Takes the wake context, whose signal is the actor's, not one action's.
|
|
111
|
-
*/
|
|
112
|
-
export declare function stopRunWhenLost(c: PiContext): void;
|
|
113
|
-
/**
|
|
114
|
-
* Stops the Pi session for this actor generation. On sleep it first waits,
|
|
115
|
-
* until `drainUntil`, for a run to finish. A run still active then is not
|
|
116
|
-
* aborted: the transcript ends at the last message Pi stored, and the next
|
|
117
|
-
* wake resumes it. On destroy it aborts the run at once, since nothing would
|
|
118
|
-
* resume it. Then lets extensions shut down, flushes settings and entries,
|
|
119
|
-
* and suspends the sandbox on sleep, or destroys it on destroy.
|
|
120
|
-
*/
|
|
121
|
-
export declare function closePiSession(c: PiContext, options: PiSessionOptions, stop: PiStop): Promise<void>;
|
|
122
125
|
/**
|
|
123
126
|
* Suspends the sandbox this generation connected when the actor sleeps. On
|
|
124
127
|
* destroy it destroys the actor's sandbox, also one stored by an earlier
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAEN,KAAK,oBAAoB,EAEzB,OAAO,EAEP,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK/D,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,KAAK,iBAAiB,EAItB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAE7D,6DAA6D;AAC7D,MAAM,MAAM,SAAS,GAAG,YAAY,CACnC,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,kBAAkB,EAClB,GAAG,EACH,GAAG,CACH,CAAC;AAEF,iGAAiG;AACjG,MAAM,MAAM,MAAM,GACf;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAEzB,+DAA+D;AAC/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