@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
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
|
/**
|
|
@@ -53,22 +40,9 @@ export declare function createActorModelRuntime(options: Omit<PiModelOptions, "c
|
|
|
53
40
|
/** A credential store that holds nothing and refuses writes. */
|
|
54
41
|
export declare const emptyCredentialStore: PiCredentialStore;
|
|
55
42
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* which only happens when no model is configured.
|
|
59
|
-
*/
|
|
60
|
-
export declare function openingModel(options: AllowlistOptions, runtime: ModelRuntime, saved: {
|
|
61
|
-
provider: string;
|
|
62
|
-
modelId: string;
|
|
63
|
-
} | null): PiModel | undefined;
|
|
64
|
-
/** Allowed models that have a credential, for a client's model picker. */
|
|
65
|
-
export declare function availableModels(options: AllowlistOptions, session: AgentSession): PiModelInfo[];
|
|
66
|
-
/** Throws `model_unavailable` when the session's model has no credential, for example after a logout. */
|
|
67
|
-
export declare function requireCredential(session: AgentSession): void;
|
|
68
|
-
/**
|
|
69
|
-
* Switches the session to an allowed model. The model object comes from the
|
|
70
|
-
* runtime's catalog, so a client can never choose the URL a key is sent to.
|
|
43
|
+
* Throws unless a client may switch to `provider/modelId`. With neither
|
|
44
|
+
* `model` nor `scopedModels` set, a client may not choose any model.
|
|
71
45
|
*/
|
|
72
|
-
export declare function
|
|
46
|
+
export declare function assertModelAllowed(options: AllowlistOptions, provider: string, modelId: string): void;
|
|
73
47
|
export {};
|
|
74
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
|
@@ -36,76 +36,13 @@ function allowedModels(options) {
|
|
|
36
36
|
function isAllowed(options, provider, modelId) {
|
|
37
37
|
return allowedModels(options).includes(`${provider}/${modelId}`);
|
|
38
38
|
}
|
|
39
|
-
/** Looks up a `provider/modelId` in the actor's catalog. */
|
|
40
|
-
function catalogModel(runtime, name) {
|
|
41
|
-
const slash = name.indexOf("/");
|
|
42
|
-
const model = slash > 0 ? runtime.getModel(name.slice(0, slash), name.slice(slash + 1)) : undefined;
|
|
43
|
-
if (!model) {
|
|
44
|
-
throw new Error(`pi() model ${name} is not in Pi's model catalog; add it with providers`);
|
|
45
|
-
}
|
|
46
|
-
return model;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* The model a session opens with: the model saved in the session when it is
|
|
50
|
-
* still allowed, otherwise the configured default. Undefined lets Pi choose,
|
|
51
|
-
* which only happens when no model is configured.
|
|
52
|
-
*/
|
|
53
|
-
export function openingModel(options, runtime, saved) {
|
|
54
|
-
if (saved && isAllowed(options, saved.provider, saved.modelId)) {
|
|
55
|
-
const model = runtime.getModel(saved.provider, saved.modelId);
|
|
56
|
-
if (model)
|
|
57
|
-
return model;
|
|
58
|
-
}
|
|
59
|
-
const fallback = options.model ?? allowedModels(options)[0];
|
|
60
|
-
return fallback ? catalogModel(runtime, fallback) : undefined;
|
|
61
|
-
}
|
|
62
|
-
/** Allowed models that have a credential, for a client's model picker. */
|
|
63
|
-
export function availableModels(options, session) {
|
|
64
|
-
return session.modelRuntime
|
|
65
|
-
.getAvailableSnapshot()
|
|
66
|
-
.filter((model) => isAllowed(options, model.provider, model.id))
|
|
67
|
-
.map((model) => ({
|
|
68
|
-
provider: model.provider,
|
|
69
|
-
id: model.id,
|
|
70
|
-
name: model.name,
|
|
71
|
-
reasoning: model.reasoning,
|
|
72
|
-
input: model.input,
|
|
73
|
-
contextWindow: model.contextWindow,
|
|
74
|
-
maxTokens: model.maxTokens,
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
/** Throws `model_unavailable` when the session's model has no credential, for example after a logout. */
|
|
78
|
-
export function requireCredential(session) {
|
|
79
|
-
const model = session.model;
|
|
80
|
-
if (!model)
|
|
81
|
-
return;
|
|
82
|
-
const available = session.modelRuntime
|
|
83
|
-
.getAvailableSnapshot()
|
|
84
|
-
.some((candidate) => candidate.provider === model.provider && candidate.id === model.id);
|
|
85
|
-
if (!available) {
|
|
86
|
-
throw new UserError(`No credential is configured for ${model.provider}/${model.id}.`, {
|
|
87
|
-
code: "model_unavailable",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
39
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
40
|
+
* Throws unless a client may switch to `provider/modelId`. With neither
|
|
41
|
+
* `model` nor `scopedModels` set, a client may not choose any model.
|
|
94
42
|
*/
|
|
95
|
-
export
|
|
43
|
+
export function assertModelAllowed(options, provider, modelId) {
|
|
96
44
|
if (!isAllowed(options, provider, modelId)) {
|
|
97
|
-
throw new UserError(`Model ${provider}/${modelId} is not allowed for this agent.`, {
|
|
98
|
-
code: "model_not_allowed",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
const model = session.modelRuntime
|
|
102
|
-
.getAvailableSnapshot()
|
|
103
|
-
.find((candidate) => candidate.provider === provider && candidate.id === modelId);
|
|
104
|
-
if (!model) {
|
|
105
|
-
throw new UserError(`No credential is configured for ${provider}/${modelId}.`, {
|
|
106
|
-
code: "model_unavailable",
|
|
107
|
-
});
|
|
45
|
+
throw new UserError(`Model ${provider}/${modelId} is not allowed for this agent.`, { code: "model_not_allowed" });
|
|
108
46
|
}
|
|
109
|
-
await session.setModel(model);
|
|
110
47
|
}
|
|
111
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,C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M,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,64 +1,132 @@
|
|
|
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
|
-
import type
|
|
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>;
|
|
11
|
-
/**
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
sandbox?: SandboxProvider;
|
|
20
|
-
}
|
|
21
|
-
/** One open Pi session for a live actor generation. */
|
|
22
|
-
export interface PiSession {
|
|
23
|
-
session: AgentSession;
|
|
24
|
-
settingsManager: SettingsManager;
|
|
25
|
-
cwd: string;
|
|
26
|
-
sandbox: ConnectedSandbox | undefined;
|
|
27
|
-
/** Command execution for `executeBash`. Undefined when there is no sandbox. */
|
|
28
|
-
bashOperations: BashOperations | undefined;
|
|
29
|
-
/** JSON of the settings last written to SQLite, to skip no-op writes. */
|
|
30
|
-
persistedSettings: string;
|
|
31
|
-
/** Entries (header excluded) already written to SQLite, in Pi's append order. */
|
|
32
|
-
persistedEntryCount: number;
|
|
33
|
-
/** The application's credentials, when `pi({ credentials })` is set. */
|
|
34
|
-
credentials: SourceCredentialStore | undefined;
|
|
35
|
-
}
|
|
36
|
-
/** The sandbox a session's tools run in for this actor generation. */
|
|
12
|
+
/** How an actor generation stops. A sleep drains until `drainUntil`; a destroy stops at once. */
|
|
13
|
+
export type PiStop = {
|
|
14
|
+
reason: "sleep";
|
|
15
|
+
drainUntil: number;
|
|
16
|
+
} | {
|
|
17
|
+
reason: "destroy";
|
|
18
|
+
};
|
|
19
|
+
/** The sandbox Pi's tools run in for this actor generation. */
|
|
37
20
|
export interface ConnectedSandbox {
|
|
38
21
|
provider: SandboxProvider;
|
|
39
22
|
id: string;
|
|
40
23
|
sandbox: Sandbox;
|
|
41
24
|
}
|
|
42
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Options accepted by `pi()` on top of ordinary actor config. The Pi
|
|
27
|
+
* Durable options keep the names and types of `HarnessOptions`.
|
|
28
|
+
*/
|
|
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>;
|
|
58
|
+
}
|
|
59
|
+
/** Per-actor-generation state, stored on `c.vars` under `PI_RUNTIME`. */
|
|
43
60
|
export interface PiRuntime {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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. */
|
|
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;
|
|
47
74
|
}
|
|
48
75
|
export declare const PI_RUNTIME: unique symbol;
|
|
49
76
|
export declare function createPiRuntime(): PiRuntime;
|
|
50
77
|
export declare function piRuntime(c: PiContext): PiRuntime;
|
|
51
|
-
/** Returns the actor's Pi session, opening it from SQLite on first use. */
|
|
52
|
-
export declare function ensurePiSession(c: PiContext, options: PiSessionOptions): Promise<PiSession>;
|
|
53
78
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
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.
|
|
82
|
+
*/
|
|
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;
|
|
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>;
|
|
115
|
+
/** Runs `body` with a `c.pi` that throws `error` when read. */
|
|
116
|
+
export declare function withUnavailablePi<T>(c: PiContext, error: unknown, body: () => T | Promise<T>): T | Promise<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Connects to the actor's sandbox, creating one when none is stored or the
|
|
119
|
+
* provider reports the stored one no longer exists. A new sandbox id is saved
|
|
120
|
+
* as soon as `create` returns, so a failure later in the start reuses it. Any
|
|
121
|
+
* other connect failure is thrown, so a temporary outage never replaces a
|
|
122
|
+
* sandbox.
|
|
56
123
|
*/
|
|
57
|
-
export declare function
|
|
124
|
+
export declare function connectSandbox(c: PiContext, provider: SandboxProvider): Promise<ConnectedSandbox>;
|
|
58
125
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
126
|
+
* Suspends the sandbox this generation connected when the actor sleeps. On
|
|
127
|
+
* destroy it destroys the actor's sandbox, also one stored by an earlier
|
|
128
|
+
* generation that this one never connected.
|
|
62
129
|
*/
|
|
63
|
-
export declare function
|
|
130
|
+
export declare function closeSandbox(c: PiContext, provider: SandboxProvider, connection: Promise<ConnectedSandbox> | undefined, stop: PiStop): Promise<void>;
|
|
131
|
+
export {};
|
|
64
132
|
//# sourceMappingURL=runtime.d.ts.map
|
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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