@earendil-works/pi-durable 0.87.1 → 0.99.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/README.md +46 -4
- package/dist/documents.d.ts +66 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +98 -0
- package/dist/documents.js.map +1 -0
- package/dist/entries.d.ts +13 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/entries.js +18 -0
- package/dist/entries.js.map +1 -0
- package/dist/env/index.d.ts +131 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +45 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/node.d.ts +45 -0
- package/dist/env/node.d.ts.map +1 -0
- package/dist/env/node.js +908 -0
- package/dist/env/node.js.map +1 -0
- package/dist/env/utils/adaptive-publisher.d.ts +24 -0
- package/dist/env/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/env/utils/adaptive-publisher.js +79 -0
- package/dist/env/utils/adaptive-publisher.js.map +1 -0
- package/dist/env/utils/output-capture.d.ts +31 -0
- package/dist/env/utils/output-capture.d.ts.map +1 -0
- package/dist/env/utils/output-capture.js +238 -0
- package/dist/env/utils/output-capture.js.map +1 -0
- package/dist/env/utils/truncate.d.ts +71 -0
- package/dist/env/utils/truncate.d.ts.map +1 -0
- package/dist/env/utils/truncate.js +294 -0
- package/dist/env/utils/truncate.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/harness/config.d.ts +20 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +18 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +27 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +109 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/generation.d.ts +36 -0
- package/dist/harness/generation.d.ts.map +1 -0
- package/dist/harness/generation.js +266 -0
- package/dist/harness/generation.js.map +1 -0
- package/dist/harness/harness.d.ts +10 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +266 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/live.d.ts +40 -0
- package/dist/harness/live.d.ts.map +1 -0
- package/dist/harness/live.js +41 -0
- package/dist/harness/live.js.map +1 -0
- package/dist/harness/prompt.d.ts +24 -0
- package/dist/harness/prompt.d.ts.map +1 -0
- package/dist/harness/prompt.js +88 -0
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/registry.d.ts +7 -0
- package/dist/harness/registry.d.ts.map +1 -0
- package/dist/harness/registry.js +309 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/scheduler.d.ts +63 -0
- package/dist/harness/scheduler.d.ts.map +1 -0
- package/dist/harness/scheduler.js +605 -0
- package/dist/harness/scheduler.js.map +1 -0
- package/dist/harness/submissions.d.ts +24 -0
- package/dist/harness/submissions.d.ts.map +1 -0
- package/dist/harness/submissions.js +133 -0
- package/dist/harness/submissions.js.map +1 -0
- package/dist/harness/types.d.ts +358 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +2 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/util.d.ts +14 -0
- package/dist/harness/util.d.ts.map +1 -0
- package/dist/harness/util.js +55 -0
- package/dist/harness/util.js.map +1 -0
- package/dist/ids.d.ts +6 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +9 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/session/forks.d.ts +10 -0
- package/dist/session/forks.d.ts.map +1 -0
- package/dist/session/forks.js +42 -0
- package/dist/session/forks.js.map +1 -0
- package/dist/session/observation.d.ts +28 -0
- package/dist/session/observation.d.ts.map +1 -0
- package/dist/session/observation.js +280 -0
- package/dist/session/observation.js.map +1 -0
- package/dist/session/session.d.ts +59 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +380 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/transaction.d.ts +105 -0
- package/dist/session/transaction.d.ts.map +1 -0
- package/dist/session/transaction.js +718 -0
- package/dist/session/transaction.js.map +1 -0
- package/dist/storage/jsonl/index.d.ts +2 -0
- package/dist/storage/jsonl/index.d.ts.map +1 -0
- package/dist/storage/jsonl/index.js +2 -0
- package/dist/storage/jsonl/index.js.map +1 -0
- package/dist/storage/jsonl/node.d.ts +6 -0
- package/dist/storage/jsonl/node.d.ts.map +1 -0
- package/dist/storage/jsonl/node.js +8 -0
- package/dist/storage/jsonl/node.js.map +1 -0
- package/dist/storage/jsonl/storage.d.ts +115 -0
- package/dist/storage/jsonl/storage.d.ts.map +1 -0
- package/dist/storage/jsonl/storage.js +681 -0
- package/dist/storage/jsonl/storage.js.map +1 -0
- package/dist/storage/memory.d.ts +31 -14
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +208 -61
- package/dist/storage/memory.js.map +1 -1
- package/dist/storage/sqlite/database.d.ts +5 -1
- package/dist/storage/sqlite/database.d.ts.map +1 -1
- package/dist/storage/sqlite/database.js.map +1 -1
- package/dist/storage/sqlite/index.d.ts.map +1 -1
- package/dist/storage/sqlite/migrations.d.ts +1 -1
- package/dist/storage/sqlite/migrations.d.ts.map +1 -1
- package/dist/storage/sqlite/migrations.js +8 -1
- package/dist/storage/sqlite/migrations.js.map +1 -1
- package/dist/storage/sqlite/node.d.ts.map +1 -1
- package/dist/storage/sqlite/node.js +2 -2
- package/dist/storage/sqlite/node.js.map +1 -1
- package/dist/storage/sqlite/storage.d.ts +20 -14
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +159 -55
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/tasks.d.ts +6 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +5 -0
- package/dist/tasks.js.map +1 -0
- package/dist/testing/assertions.d.ts +5 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +25 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/runner.d.ts +10 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +14 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/storage-benchmark.d.ts +41 -0
- package/dist/testing/storage-benchmark.d.ts.map +1 -0
- package/dist/testing/storage-benchmark.js +351 -0
- package/dist/testing/storage-benchmark.js.map +1 -0
- package/dist/testing/storage-conformance.d.ts +4 -0
- package/dist/testing/storage-conformance.d.ts.map +1 -0
- package/dist/testing/storage-conformance.js +1122 -0
- package/dist/testing/storage-conformance.js.map +1 -0
- package/dist/testing/types.d.ts +19 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/types.d.ts +422 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/chord-delta-findings.md +1 -1
- package/docs/pico-v5-chord-usage.md +47 -60
- package/docs/pico-v5-handoff.md +469 -264
- package/docs/pico-v5.md +1523 -639
- package/package.json +30 -5
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import type { Context, JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { CacheRetention, Message, Models, ModelThinkingLevel, Tool, ToolResultMessage, Transport, UserMessage } from "@earendil-works/pi-ai";
|
|
3
|
+
import type { ConversationId, ConversationOwnership, ConversationRecord, Cursor, DocumentObserver, DocumentReader, EntryDraft, EntryId, EntryQuery, EntryRecord, JsonObject, Page, Session, SubmissionId, SubmissionRecord, Task, TaskId, TaskOptions, TaskRecord, TaskState, Tx } from "../types.ts";
|
|
4
|
+
/** Provider and model ID resolved through pi-ai `Models`. */
|
|
5
|
+
export type ModelRef = {
|
|
6
|
+
readonly provider: string;
|
|
7
|
+
readonly modelId: string;
|
|
8
|
+
};
|
|
9
|
+
export type UserInput = UserMessage["content"];
|
|
10
|
+
/** Host submission: user input that may start a run, or a passive entry write. */
|
|
11
|
+
export type SubmissionDraft = {
|
|
12
|
+
readonly requestId?: string;
|
|
13
|
+
} & ({
|
|
14
|
+
readonly type: "input";
|
|
15
|
+
readonly content: UserInput;
|
|
16
|
+
readonly whenBusy?: "steer" | "followUp" | "reject";
|
|
17
|
+
readonly entry?: never;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "write";
|
|
20
|
+
readonly entry: EntryDraft;
|
|
21
|
+
readonly content?: never;
|
|
22
|
+
readonly whenBusy?: never;
|
|
23
|
+
});
|
|
24
|
+
export type InputSubmissionDraft = Extract<SubmissionDraft, {
|
|
25
|
+
readonly type: "input";
|
|
26
|
+
}>;
|
|
27
|
+
export type SettledSubmissionRecord = SubmissionRecord & {
|
|
28
|
+
readonly status: "done" | "unanswered";
|
|
29
|
+
};
|
|
30
|
+
/** Awaitable host object for one durably admitted submission. */
|
|
31
|
+
export interface Submission {
|
|
32
|
+
readonly id: SubmissionId;
|
|
33
|
+
status(context: Context): Promise<SubmissionRecord>;
|
|
34
|
+
wait(context: Context): Promise<SettledSubmissionRecord>;
|
|
35
|
+
abort(context: Context): Promise<"aborted" | "already_placed" | "settled">;
|
|
36
|
+
}
|
|
37
|
+
export type SettledTask<R> = TaskRecord<JsonValue, JsonValue, R> & {
|
|
38
|
+
readonly state: Extract<TaskState<JsonValue, R>, {
|
|
39
|
+
readonly status: "terminal";
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
/** Erased executable task definition stored in the registry. */
|
|
43
|
+
export type AnyTask = {
|
|
44
|
+
readonly definition: {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly version: number;
|
|
47
|
+
readonly initial: unknown;
|
|
48
|
+
readonly phases: Readonly<Record<string, unknown>>;
|
|
49
|
+
readonly abort: unknown;
|
|
50
|
+
readonly migrate?: unknown;
|
|
51
|
+
readonly hooks?: object;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** Hook handler map declared by a task definition. */
|
|
55
|
+
export type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;
|
|
56
|
+
/** Invocation-bound conversation operations available to tools. */
|
|
57
|
+
export interface ConversationHandle {
|
|
58
|
+
readonly id: ConversationId;
|
|
59
|
+
submit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;
|
|
60
|
+
abort(context: Context): Promise<void>;
|
|
61
|
+
waitForIdle(context: Context): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/** Post-tools controls requested by a tool result. */
|
|
64
|
+
export type ToolControl = {
|
|
65
|
+
readonly addTools?: readonly string[];
|
|
66
|
+
readonly terminate?: true;
|
|
67
|
+
readonly handoff?: string;
|
|
68
|
+
};
|
|
69
|
+
export type ToolExecutionResult = {
|
|
70
|
+
readonly content?: ToolResultMessage["content"];
|
|
71
|
+
readonly isError?: boolean;
|
|
72
|
+
readonly details?: JsonValue;
|
|
73
|
+
readonly control?: ToolControl;
|
|
74
|
+
};
|
|
75
|
+
/** Operations available to one tool invocation. */
|
|
76
|
+
export interface ToolExecutionApi extends DocumentObserver, DocumentReader {
|
|
77
|
+
readonly taskId: TaskId;
|
|
78
|
+
readonly conversationId: ConversationId;
|
|
79
|
+
readonly callId: string;
|
|
80
|
+
/** Append running output; it becomes the result content when the result omits `content`. */
|
|
81
|
+
output(chunk: string | Uint8Array): void;
|
|
82
|
+
/** Replace running details; the last value becomes the result details when the result omits `details`. */
|
|
83
|
+
details(value: JsonValue, context: Context): Promise<void>;
|
|
84
|
+
commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;
|
|
85
|
+
memo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;
|
|
86
|
+
memo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;
|
|
87
|
+
createTask<I, S extends {
|
|
88
|
+
phase: string;
|
|
89
|
+
}, R, H extends object>(task: Task<I, S, R, H>, input: I, options: Omit<TaskOptions, "conversationId">, context: Context): Promise<TaskId<R>>;
|
|
90
|
+
getTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;
|
|
91
|
+
waitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;
|
|
92
|
+
conversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;
|
|
93
|
+
}
|
|
94
|
+
/** Executable tool registered in a registry. Only pi-ai `Tool` fields enter the transcript. */
|
|
95
|
+
export type ToolRegistration = Tool & {
|
|
96
|
+
/** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */
|
|
97
|
+
readonly replay?: "safe" | "unsafe";
|
|
98
|
+
readonly outputLimits?: {
|
|
99
|
+
readonly maxBytes?: number;
|
|
100
|
+
readonly maxLines?: number;
|
|
101
|
+
readonly retain?: "head" | "tail";
|
|
102
|
+
};
|
|
103
|
+
execute(args: JsonValue, api: ToolExecutionApi, context: Context): Promise<ToolExecutionResult>;
|
|
104
|
+
};
|
|
105
|
+
/** Token for removing registrations. Work already running keeps using what it started with. */
|
|
106
|
+
export interface Registration {
|
|
107
|
+
/** Idempotent; removes exactly the registrations this token covers. */
|
|
108
|
+
dispose(): void;
|
|
109
|
+
}
|
|
110
|
+
/** Pure decorator; returns a new tool with the same name and never mutates its input. */
|
|
111
|
+
export type ToolWrapper<Tool extends ToolRegistration> = (tool: Tool) => Tool;
|
|
112
|
+
/** Conversation selection for a scoped hook registration. */
|
|
113
|
+
export type HookScope = {
|
|
114
|
+
readonly conversationId: ConversationId;
|
|
115
|
+
/** Also match conversations owned, transitively, by tasks of this conversation. */
|
|
116
|
+
readonly subtree?: boolean;
|
|
117
|
+
};
|
|
118
|
+
/** Input to system prompt section rendering for one request preparation. */
|
|
119
|
+
export type PromptInput<Tool extends ToolRegistration> = {
|
|
120
|
+
readonly conversationId: ConversationId;
|
|
121
|
+
/** Active and registered tools in configured order, as offered in this request. */
|
|
122
|
+
readonly tools: readonly Tool[];
|
|
123
|
+
/** Sections already in effect after replaying the active transcript. */
|
|
124
|
+
readonly shown: Readonly<Record<string, string>>;
|
|
125
|
+
readonly model?: ModelRef;
|
|
126
|
+
readonly thinkingLevel: ModelThinkingLevel;
|
|
127
|
+
/** Committed document reads. */
|
|
128
|
+
readonly read: DocumentReader;
|
|
129
|
+
};
|
|
130
|
+
/** One registered system prompt section; sections render in registry order before each request. */
|
|
131
|
+
export type PromptSection<Tool extends ToolRegistration> = {
|
|
132
|
+
readonly key: string;
|
|
133
|
+
render(input: PromptInput<Tool>, context: Context): string | undefined | Promise<string | undefined>;
|
|
134
|
+
/** Default true: wrap the text as `<key>\n...\n</key>`. */
|
|
135
|
+
readonly tag?: boolean;
|
|
136
|
+
};
|
|
137
|
+
/** Pure decorator; returns a new section with the same key and never mutates its input. */
|
|
138
|
+
export type PromptSectionWrapper<Tool extends ToolRegistration> = (section: PromptSection<Tool>) => PromptSection<Tool>;
|
|
139
|
+
/** One registered hook handler map for task `K`. */
|
|
140
|
+
export type HookRegistration<K extends AnyTask> = {
|
|
141
|
+
readonly handlers: Partial<HooksOf<K>>;
|
|
142
|
+
readonly scope?: HookScope;
|
|
143
|
+
};
|
|
144
|
+
/** Wrapper composition failure found while building a snapshot. */
|
|
145
|
+
export type RegistryFailure = {
|
|
146
|
+
readonly kind: "tool" | "section";
|
|
147
|
+
/** Tool name or section key. */
|
|
148
|
+
readonly name: string;
|
|
149
|
+
readonly error: unknown;
|
|
150
|
+
};
|
|
151
|
+
/** Immutable view of one published registry state. */
|
|
152
|
+
export interface RegistrySnapshot<Tool extends ToolRegistration = ToolRegistration> {
|
|
153
|
+
/** Composed tools in registry order; a tool whose wrapper failed is absent. */
|
|
154
|
+
tools(): readonly Tool[];
|
|
155
|
+
tool(name: string): Tool | undefined;
|
|
156
|
+
/** Base tool names in registry order, including tools whose wrappers fail. */
|
|
157
|
+
toolNames(): readonly string[];
|
|
158
|
+
task(name: string): AnyTask | undefined;
|
|
159
|
+
/** Hooks registered for tasks with `task`'s name, in registry order. */
|
|
160
|
+
hooks<K extends AnyTask>(task: K): readonly HookRegistration<K>[];
|
|
161
|
+
/** Composed sections in registry order; a section whose wrapper failed is absent. */
|
|
162
|
+
sections(): readonly PromptSection<Tool>[];
|
|
163
|
+
/** Wrapper failures of this state. */
|
|
164
|
+
failures(): readonly RegistryFailure[];
|
|
165
|
+
/** Conversation setups in registry order, the built-in `pi` setup first. */
|
|
166
|
+
conversationSetups(): readonly {
|
|
167
|
+
readonly key: string;
|
|
168
|
+
readonly setup: ConversationSetup;
|
|
169
|
+
}[];
|
|
170
|
+
}
|
|
171
|
+
/** Read side of a registry consumed by a Harness. */
|
|
172
|
+
export interface RegistryReader<Tool extends ToolRegistration = ToolRegistration> {
|
|
173
|
+
/** Immutable view of the whole current registry. */
|
|
174
|
+
snapshot(): RegistrySnapshot<Tool>;
|
|
175
|
+
/** Called synchronously after every publication; wakes the scheduler to reconsider blocked tasks. */
|
|
176
|
+
subscribe(listener: () => void): () => void;
|
|
177
|
+
}
|
|
178
|
+
/** Application-owned registry of tools, hooks, tasks, and the system prompt. */
|
|
179
|
+
export interface Registry<Tool extends ToolRegistration = ToolRegistration> extends RegistryReader<Tool> {
|
|
180
|
+
readonly tools: {
|
|
181
|
+
add(tool: Tool): Registration;
|
|
182
|
+
/** `key` identifies the wrapper: it orders wrappers of one tool and keeps its position on re-registration. */
|
|
183
|
+
wrap(name: string, key: string, wrapper: ToolWrapper<Tool>): Registration;
|
|
184
|
+
/** Composed tools of the current state. */
|
|
185
|
+
list(): readonly Tool[];
|
|
186
|
+
};
|
|
187
|
+
readonly hooks: {
|
|
188
|
+
add<K extends AnyTask>(task: K, handlers: Partial<HooksOf<K>>, options?: {
|
|
189
|
+
readonly scope?: HookScope;
|
|
190
|
+
readonly key?: string;
|
|
191
|
+
}): Registration;
|
|
192
|
+
};
|
|
193
|
+
readonly tasks: {
|
|
194
|
+
add(task: AnyTask): Registration;
|
|
195
|
+
list(): readonly AnyTask[];
|
|
196
|
+
};
|
|
197
|
+
readonly conversations: {
|
|
198
|
+
/** `key` orders setups and keeps its position on re-registration. */
|
|
199
|
+
setup(key: string, setup: ConversationSetup): Registration;
|
|
200
|
+
};
|
|
201
|
+
readonly systemPrompt: {
|
|
202
|
+
section(key: string, render: PromptSection<Tool>["render"], options?: {
|
|
203
|
+
readonly tag?: boolean;
|
|
204
|
+
}): Registration;
|
|
205
|
+
wrap(key: string, wrapperKey: string, wrapper: PromptSectionWrapper<Tool>): Registration;
|
|
206
|
+
/** Composed sections of the current state. */
|
|
207
|
+
sections(): readonly PromptSection<Tool>[];
|
|
208
|
+
};
|
|
209
|
+
/** Stage registrations and disposals made synchronously by `register`, then publish them at once. Cannot nest. */
|
|
210
|
+
batch(register: () => void): Registration;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Stages the documents every new conversation gets. Runs inside every Harness commit that creates or forks a
|
|
214
|
+
* conversation, including raw `Tx` creation, after fork copies and before host `init`. Table reads throw, since the
|
|
215
|
+
* conversation write came first; a fork (`conversation.parent`) already holds its copied documents. A throw fails the
|
|
216
|
+
* creating commit.
|
|
217
|
+
*/
|
|
218
|
+
export type ConversationSetup = (tx: Tx, conversation: ConversationRecord, registry: RegistrySnapshot) => void | Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Runs inside the creating commit, after the conversation and its configuration exist. The conversation creation is
|
|
221
|
+
* already a table write, so table reads here throw `ReadAfterWrite`; document access remains available.
|
|
222
|
+
*/
|
|
223
|
+
export type ConversationInit = (tx: Tx, conversationId: ConversationId) => void | Promise<void>;
|
|
224
|
+
export type ConversationCreateOptions = {
|
|
225
|
+
readonly ownership: ConversationOwnership;
|
|
226
|
+
readonly init?: ConversationInit;
|
|
227
|
+
};
|
|
228
|
+
/** Curated pi-ai request options; absent fields use pi-ai defaults. */
|
|
229
|
+
export type ConversationStreamOptions = {
|
|
230
|
+
transport?: Transport;
|
|
231
|
+
timeoutMs?: number;
|
|
232
|
+
/** Provider/SDK retries inside one request attempt. */
|
|
233
|
+
maxRetries?: number;
|
|
234
|
+
maxRetryDelayMs?: number;
|
|
235
|
+
headers?: Record<string, string>;
|
|
236
|
+
metadata?: JsonObject;
|
|
237
|
+
cacheRetention?: CacheRetention;
|
|
238
|
+
deferred?: boolean | {
|
|
239
|
+
window?: "15m" | "1h" | "24h";
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
/** Durable generation attempt retries; the JSON shape of pi-ai `RetryPolicy`. */
|
|
243
|
+
export type ConversationRetryPolicy = {
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
maxRetries: number;
|
|
246
|
+
baseDelayMs: number;
|
|
247
|
+
maxAgentDelayMs?: number;
|
|
248
|
+
};
|
|
249
|
+
export type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {
|
|
250
|
+
/** pi-ai model access used by generation. */
|
|
251
|
+
readonly models: Models;
|
|
252
|
+
readonly registry: RegistryReader<Tool>;
|
|
253
|
+
readonly now?: () => number;
|
|
254
|
+
/** Receives extension failures that do not fail the calling operation. Must not throw. */
|
|
255
|
+
readonly onReport?: (error: unknown) => void;
|
|
256
|
+
};
|
|
257
|
+
/** Live task and what the scheduler would do with it under the current registry. */
|
|
258
|
+
export type TaskInspection = {
|
|
259
|
+
readonly record: TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
260
|
+
readonly state: {
|
|
261
|
+
readonly kind: "running";
|
|
262
|
+
}
|
|
263
|
+
/** The next scheduling pass reserves it; `migrates` when its definition is newer and has `migrate`. */
|
|
264
|
+
| {
|
|
265
|
+
readonly kind: "ready";
|
|
266
|
+
readonly migrates: boolean;
|
|
267
|
+
}
|
|
268
|
+
/** Pending until these tasks are terminal. */
|
|
269
|
+
| {
|
|
270
|
+
readonly kind: "waiting";
|
|
271
|
+
readonly on: readonly TaskId[];
|
|
272
|
+
}
|
|
273
|
+
/** No registered definition can take it; aborting it settles it as `orphaned`. */
|
|
274
|
+
| {
|
|
275
|
+
readonly kind: "blocked";
|
|
276
|
+
readonly reason: "missing_task" | "task_too_old" | "migration_failed";
|
|
277
|
+
readonly error?: unknown;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
/** Point-in-time view of live work: unfinished tasks and submissions, read on the Session line. */
|
|
281
|
+
export type HarnessInspection = {
|
|
282
|
+
readonly scheduling: "paused" | "running" | "closing";
|
|
283
|
+
readonly tasks: readonly TaskInspection[];
|
|
284
|
+
/** Queued and placed submissions, in ID order. */
|
|
285
|
+
readonly submissions: readonly SubmissionRecord[];
|
|
286
|
+
/** Wrapper failures of the current registry snapshot. */
|
|
287
|
+
readonly registry: readonly RegistryFailure[];
|
|
288
|
+
};
|
|
289
|
+
/** Raw active transcript and derived model context. */
|
|
290
|
+
export type ContextView = {
|
|
291
|
+
/** Newest applicable head marker, if any. */
|
|
292
|
+
readonly head: EntryRecord | undefined;
|
|
293
|
+
/** Raw active entries: the head marker followed by non-head entries from its head through the tail. */
|
|
294
|
+
readonly entries: readonly EntryRecord[];
|
|
295
|
+
/** Model context for the next provider request. */
|
|
296
|
+
readonly messages: readonly Message[];
|
|
297
|
+
};
|
|
298
|
+
/** Stateless handle for one conversation, bound to the Harness that returned it. Compare handles by `id`. */
|
|
299
|
+
export interface Conversation {
|
|
300
|
+
readonly id: ConversationId;
|
|
301
|
+
getModel(context: Context): Promise<ModelRef | undefined>;
|
|
302
|
+
setModel(model: ModelRef | undefined, context: Context): Promise<void>;
|
|
303
|
+
getThinkingLevel(context: Context): Promise<ModelThinkingLevel>;
|
|
304
|
+
setThinkingLevel(level: ModelThinkingLevel, context: Context): Promise<void>;
|
|
305
|
+
getActiveTools(context: Context): Promise<readonly string[]>;
|
|
306
|
+
setActiveTools(names: readonly string[], context: Context): Promise<void>;
|
|
307
|
+
/** `{}` when unset. */
|
|
308
|
+
getStreamOptions(context: Context): Promise<ConversationStreamOptions>;
|
|
309
|
+
setStreamOptions(options: ConversationStreamOptions, context: Context): Promise<void>;
|
|
310
|
+
/** The default policy when unset. */
|
|
311
|
+
getRetryPolicy(context: Context): Promise<ConversationRetryPolicy>;
|
|
312
|
+
/** `undefined` removes the configured policy. */
|
|
313
|
+
setRetryPolicy(policy: ConversationRetryPolicy | undefined, context: Context): Promise<void>;
|
|
314
|
+
/**
|
|
315
|
+
* Durably admit user input or a passive entry write. Until the inbox exists, a busy conversation rejects every
|
|
316
|
+
* submission with `ConversationBusy`.
|
|
317
|
+
*/
|
|
318
|
+
submit(submission: SubmissionDraft, context: Context): Promise<Submission>;
|
|
319
|
+
/** Session commit whose `tx.createTask()` defaults to this conversation. */
|
|
320
|
+
commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;
|
|
321
|
+
context(context: Context): Promise<ContextView>;
|
|
322
|
+
/** Newest-first fork-aware history of this conversation. */
|
|
323
|
+
entries(query: Omit<EntryQuery, "conversationId">, limit: number, cursor: Cursor | undefined, context: Context): Promise<Page<EntryRecord, Cursor>>;
|
|
324
|
+
fork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;
|
|
325
|
+
/** Resolve when no live non-background task belongs to this conversation. */
|
|
326
|
+
waitForIdle(context: Context): Promise<void>;
|
|
327
|
+
}
|
|
328
|
+
/** Durable agent harness over one Session. */
|
|
329
|
+
export interface Harness extends Session {
|
|
330
|
+
/**
|
|
331
|
+
* Enable task scheduling. Idempotent; throws after close. Calls that wait for progress (`Conversation.submit()`,
|
|
332
|
+
* `Submission.wait()`, `waitForTask()`, `waitForIdle()`) enable it too.
|
|
333
|
+
*/
|
|
334
|
+
resume(): void;
|
|
335
|
+
/** Return the reserved root conversation, creating it with `init` in one commit when absent. */
|
|
336
|
+
root(context: Context, options?: {
|
|
337
|
+
readonly init?: ConversationInit;
|
|
338
|
+
}): Promise<Conversation>;
|
|
339
|
+
conversation(id: ConversationId, context: Context): Promise<Conversation | undefined>;
|
|
340
|
+
createConversation(options: ConversationCreateOptions, context: Context): Promise<Conversation>;
|
|
341
|
+
getTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;
|
|
342
|
+
/** Live tasks, unsettled submissions, and registry failures. Writes nothing and runs no task code. */
|
|
343
|
+
inspect(context: Context): Promise<HarnessInspection>;
|
|
344
|
+
/** Reacquire a submission, for example after reopen. */
|
|
345
|
+
submission(id: SubmissionId, context: Context): Promise<Submission | undefined>;
|
|
346
|
+
/** `not_found` for an unknown submission or one of another conversation than `conversationId`. */
|
|
347
|
+
abortSubmission(id: SubmissionId, context: Context, conversationId?: ConversationId): Promise<"aborted" | "already_placed" | "settled" | "not_found">;
|
|
348
|
+
/**
|
|
349
|
+
* Commit the abort mark, signal and join an active run invocation, and schedule the abort invocation. A task whose
|
|
350
|
+
* definition cannot take it settles as `orphaned` instead.
|
|
351
|
+
*/
|
|
352
|
+
abortTask(id: TaskId, context: Context): Promise<"marked" | "terminal">;
|
|
353
|
+
/** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */
|
|
354
|
+
waitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;
|
|
355
|
+
/** Resolve when no live non-background task exists. */
|
|
356
|
+
waitForIdle(context: Context): Promise<void>;
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,IAAI,EACJ,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,MA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,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACtG,sGAAsG;IACtG,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACtD,wDAAwD;IACxD,UAAU,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAChF,kGAAkG;IAClG,eAAe,CACd,EAAE,EAAE,YAAY,EAChB,OAAO,EAAE,OAAO,EAChB,cAAc,CAAC,EAAE,cAAc,GAC7B,OAAO,CAAC,SAAS,GAAG,gBAAgB,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC;IACnE;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;IACxE,sFAAsF;IACtF,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,uDAAuD;IACvD,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type {\n\tCacheRetention,\n\tMessage,\n\tModels,\n\tModelThinkingLevel,\n\tTool,\n\tToolResultMessage,\n\tTransport,\n\tUserMessage,\n} from \"@earendil-works/pi-ai\";\nimport type {\n\tConversationId,\n\tConversationOwnership,\n\tConversationRecord,\n\tCursor,\n\tDocumentObserver,\n\tDocumentReader,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tJsonObject,\n\tPage,\n\tSession,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskRecord,\n\tTaskState,\n\tTx,\n} from \"../types.ts\";\n\n/** Provider and model ID resolved through pi-ai `Models`. */\nexport type ModelRef = {\n\treadonly provider: string;\n\treadonly modelId: string;\n};\n\nexport type UserInput = UserMessage[\"content\"];\n\n/** Host submission: user input that may start a run, or a passive entry write. */\nexport type SubmissionDraft = {\n\treadonly requestId?: string;\n} & (\n\t| {\n\t\t\treadonly type: \"input\";\n\t\t\treadonly content: UserInput;\n\t\t\treadonly whenBusy?: \"steer\" | \"followUp\" | \"reject\";\n\t\t\treadonly entry?: never;\n\t }\n\t| {\n\t\t\treadonly type: \"write\";\n\t\t\treadonly entry: EntryDraft;\n\t\t\treadonly content?: never;\n\t\t\treadonly whenBusy?: never;\n\t }\n);\n\nexport type InputSubmissionDraft = Extract<SubmissionDraft, { readonly type: \"input\" }>;\n\nexport type SettledSubmissionRecord = SubmissionRecord & {\n\treadonly status: \"done\" | \"unanswered\";\n};\n\n/** Awaitable host object for one durably admitted submission. */\nexport interface Submission {\n\treadonly id: SubmissionId;\n\tstatus(context: Context): Promise<SubmissionRecord>;\n\twait(context: Context): Promise<SettledSubmissionRecord>;\n\tabort(context: Context): Promise<\"aborted\" | \"already_placed\" | \"settled\">;\n}\n\nexport type SettledTask<R> = TaskRecord<JsonValue, JsonValue, R> & {\n\treadonly state: Extract<TaskState<JsonValue, R>, { readonly status: \"terminal\" }>;\n};\n\n/** Erased executable task definition stored in the registry. */\nexport type AnyTask = {\n\treadonly definition: {\n\t\treadonly name: string;\n\t\treadonly version: number;\n\t\treadonly initial: unknown;\n\t\treadonly phases: Readonly<Record<string, unknown>>;\n\t\treadonly abort: unknown;\n\t\treadonly migrate?: unknown;\n\t\treadonly hooks?: object;\n\t};\n};\n\n/** Hook handler map declared by a task definition. */\nexport type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;\n\n/** Invocation-bound conversation operations available to tools. */\nexport interface ConversationHandle {\n\treadonly id: ConversationId;\n\tsubmit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;\n\tabort(context: Context): Promise<void>;\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n/** Post-tools controls requested by a tool result. */\nexport type ToolControl = {\n\treadonly addTools?: readonly string[];\n\treadonly terminate?: true;\n\treadonly handoff?: string;\n};\n\nexport type ToolExecutionResult = {\n\treadonly content?: ToolResultMessage[\"content\"];\n\treadonly isError?: boolean;\n\treadonly details?: JsonValue;\n\treadonly control?: ToolControl;\n};\n\n/** Operations available to one tool invocation. */\nexport interface ToolExecutionApi extends DocumentObserver, DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly callId: string;\n\t/** Append running output; it becomes the result content when the result omits `content`. */\n\toutput(chunk: string | Uint8Array): void;\n\t/** Replace running details; the last value becomes the result details when the result omits `details`. */\n\tdetails(value: JsonValue, context: Context): Promise<void>;\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n\tcreateTask<I, S extends { phase: string }, R, H extends object>(\n\t\ttask: Task<I, S, R, H>,\n\t\tinput: I,\n\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\tcontext: Context,\n\t): Promise<TaskId<R>>;\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\tconversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;\n}\n\n/** Executable tool registered in a registry. Only pi-ai `Tool` fields enter the transcript. */\nexport type ToolRegistration = Tool & {\n\t/** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */\n\treadonly replay?: \"safe\" | \"unsafe\";\n\treadonly outputLimits?: {\n\t\treadonly maxBytes?: number;\n\t\treadonly maxLines?: number;\n\t\treadonly retain?: \"head\" | \"tail\";\n\t};\n\texecute(args: JsonValue, api: ToolExecutionApi, context: Context): Promise<ToolExecutionResult>;\n};\n\n/** Token for removing registrations. Work already running keeps using what it started with. */\nexport interface Registration {\n\t/** Idempotent; removes exactly the registrations this token covers. */\n\tdispose(): void;\n}\n\n/** Pure decorator; returns a new tool with the same name and never mutates its input. */\nexport type ToolWrapper<Tool extends ToolRegistration> = (tool: Tool) => Tool;\n\n/** Conversation selection for a scoped hook registration. */\nexport type HookScope = {\n\treadonly conversationId: ConversationId;\n\t/** Also match conversations owned, transitively, by tasks of this conversation. */\n\treadonly subtree?: boolean;\n};\n\n/** Input to system prompt section rendering for one request preparation. */\nexport type PromptInput<Tool extends ToolRegistration> = {\n\treadonly conversationId: ConversationId;\n\t/** Active and registered tools in configured order, as offered in this request. */\n\treadonly tools: readonly Tool[];\n\t/** Sections already in effect after replaying the active transcript. */\n\treadonly shown: Readonly<Record<string, string>>;\n\treadonly model?: ModelRef;\n\treadonly thinkingLevel: ModelThinkingLevel;\n\t/** Committed document reads. */\n\treadonly read: DocumentReader;\n};\n\n/** One registered system prompt section; sections render in registry order before each request. */\nexport type PromptSection<Tool extends ToolRegistration> = {\n\treadonly key: string;\n\trender(input: PromptInput<Tool>, context: Context): string | undefined | Promise<string | undefined>;\n\t/** Default true: wrap the text as `<key>\\n...\\n</key>`. */\n\treadonly tag?: boolean;\n};\n\n/** Pure decorator; returns a new section with the same key and never mutates its input. */\nexport type PromptSectionWrapper<Tool extends ToolRegistration> = (section: PromptSection<Tool>) => PromptSection<Tool>;\n\n/** One registered hook handler map for task `K`. */\nexport type HookRegistration<K extends AnyTask> = {\n\treadonly handlers: Partial<HooksOf<K>>;\n\treadonly scope?: HookScope;\n};\n\n/** Wrapper composition failure found while building a snapshot. */\nexport type RegistryFailure = {\n\treadonly kind: \"tool\" | \"section\";\n\t/** Tool name or section key. */\n\treadonly name: string;\n\treadonly error: unknown;\n};\n\n/** Immutable view of one published registry state. */\nexport interface RegistrySnapshot<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Composed tools in registry order; a tool whose wrapper failed is absent. */\n\ttools(): readonly Tool[];\n\ttool(name: string): Tool | undefined;\n\t/** Base tool names in registry order, including tools whose wrappers fail. */\n\ttoolNames(): readonly string[];\n\ttask(name: string): AnyTask | undefined;\n\t/** Hooks registered for tasks with `task`'s name, in registry order. */\n\thooks<K extends AnyTask>(task: K): readonly HookRegistration<K>[];\n\t/** Composed sections in registry order; a section whose wrapper failed is absent. */\n\tsections(): readonly PromptSection<Tool>[];\n\t/** Wrapper failures of this state. */\n\tfailures(): readonly RegistryFailure[];\n\t/** Conversation setups in registry order, the built-in `pi` setup first. */\n\tconversationSetups(): readonly { readonly key: string; readonly setup: ConversationSetup }[];\n}\n\n/** Read side of a registry consumed by a Harness. */\nexport interface RegistryReader<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Immutable view of the whole current registry. */\n\tsnapshot(): RegistrySnapshot<Tool>;\n\t/** Called synchronously after every publication; wakes the scheduler to reconsider blocked tasks. */\n\tsubscribe(listener: () => void): () => void;\n}\n\n/** Application-owned registry of tools, hooks, tasks, and the system prompt. */\nexport interface Registry<Tool extends ToolRegistration = ToolRegistration> extends RegistryReader<Tool> {\n\treadonly tools: {\n\t\tadd(tool: Tool): Registration;\n\t\t/** `key` identifies the wrapper: it orders wrappers of one tool and keeps its position on re-registration. */\n\t\twrap(name: string, key: string, wrapper: ToolWrapper<Tool>): Registration;\n\t\t/** Composed tools of the current state. */\n\t\tlist(): readonly Tool[];\n\t};\n\treadonly hooks: {\n\t\tadd<K extends AnyTask>(\n\t\t\ttask: K,\n\t\t\thandlers: Partial<HooksOf<K>>,\n\t\t\toptions?: { readonly scope?: HookScope; readonly key?: string },\n\t\t): Registration;\n\t};\n\treadonly tasks: {\n\t\tadd(task: AnyTask): Registration;\n\t\tlist(): readonly AnyTask[];\n\t};\n\treadonly conversations: {\n\t\t/** `key` orders setups and keeps its position on re-registration. */\n\t\tsetup(key: string, setup: ConversationSetup): Registration;\n\t};\n\treadonly systemPrompt: {\n\t\tsection(key: string, render: PromptSection<Tool>[\"render\"], options?: { readonly tag?: boolean }): Registration;\n\t\twrap(key: string, wrapperKey: string, wrapper: PromptSectionWrapper<Tool>): Registration;\n\t\t/** Composed sections of the current state. */\n\t\tsections(): readonly PromptSection<Tool>[];\n\t};\n\t/** Stage registrations and disposals made synchronously by `register`, then publish them at once. Cannot nest. */\n\tbatch(register: () => void): Registration;\n}\n\n/**\n * Stages the documents every new conversation gets. Runs inside every Harness commit that creates or forks a\n * conversation, including raw `Tx` creation, after fork copies and before host `init`. Table reads throw, since the\n * conversation write came first; a fork (`conversation.parent`) already holds its copied documents. A throw fails the\n * creating commit.\n */\nexport type ConversationSetup = (\n\ttx: Tx,\n\tconversation: ConversationRecord,\n\tregistry: RegistrySnapshot,\n) => void | Promise<void>;\n\n/**\n * Runs inside the creating commit, after the conversation and its configuration exist. The conversation creation is\n * already a table write, so table reads here throw `ReadAfterWrite`; document access remains available.\n */\nexport type ConversationInit = (tx: Tx, conversationId: ConversationId) => void | Promise<void>;\n\nexport type ConversationCreateOptions = {\n\treadonly ownership: ConversationOwnership;\n\treadonly init?: ConversationInit;\n};\n\n/** Curated pi-ai request options; absent fields use pi-ai defaults. */\nexport type ConversationStreamOptions = {\n\ttransport?: Transport;\n\ttimeoutMs?: number;\n\t/** Provider/SDK retries inside one request attempt. */\n\tmaxRetries?: number;\n\tmaxRetryDelayMs?: number;\n\theaders?: Record<string, string>;\n\tmetadata?: JsonObject;\n\tcacheRetention?: CacheRetention;\n\tdeferred?: boolean | { window?: \"15m\" | \"1h\" | \"24h\" };\n};\n\n/** Durable generation attempt retries; the JSON shape of pi-ai `RetryPolicy`. */\nexport type ConversationRetryPolicy = {\n\tenabled: boolean;\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\tmaxAgentDelayMs?: number;\n};\n\nexport type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {\n\t/** pi-ai model access used by generation. */\n\treadonly models: Models;\n\treadonly registry: RegistryReader<Tool>;\n\treadonly now?: () => number;\n\t/** Receives extension failures that do not fail the calling operation. Must not throw. */\n\treadonly onReport?: (error: unknown) => void;\n};\n\n/** Live task and what the scheduler would do with it under the current registry. */\nexport type TaskInspection = {\n\treadonly record: TaskRecord<JsonValue, JsonValue, JsonValue>;\n\treadonly state: /** An invocation is active. */\n\t\t| { readonly kind: \"running\" }\n\t\t/** The next scheduling pass reserves it; `migrates` when its definition is newer and has `migrate`. */\n\t\t| { readonly kind: \"ready\"; readonly migrates: boolean }\n\t\t/** Pending until these tasks are terminal. */\n\t\t| { readonly kind: \"waiting\"; readonly on: readonly TaskId[] }\n\t\t/** No registered definition can take it; aborting it settles it as `orphaned`. */\n\t\t| {\n\t\t\t\treadonly kind: \"blocked\";\n\t\t\t\treadonly reason: \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\t\t\t\treadonly error?: unknown;\n\t\t };\n};\n\n/** Point-in-time view of live work: unfinished tasks and submissions, read on the Session line. */\nexport type HarnessInspection = {\n\treadonly scheduling: \"paused\" | \"running\" | \"closing\";\n\treadonly tasks: readonly TaskInspection[];\n\t/** Queued and placed submissions, in ID order. */\n\treadonly submissions: readonly SubmissionRecord[];\n\t/** Wrapper failures of the current registry snapshot. */\n\treadonly registry: readonly RegistryFailure[];\n};\n\n/** Raw active transcript and derived model context. */\nexport type ContextView = {\n\t/** Newest applicable head marker, if any. */\n\treadonly head: EntryRecord | undefined;\n\t/** Raw active entries: the head marker followed by non-head entries from its head through the tail. */\n\treadonly entries: readonly EntryRecord[];\n\t/** Model context for the next provider request. */\n\treadonly messages: readonly Message[];\n};\n\n/** Stateless handle for one conversation, bound to the Harness that returned it. Compare handles by `id`. */\nexport interface Conversation {\n\treadonly id: ConversationId;\n\n\tgetModel(context: Context): Promise<ModelRef | undefined>;\n\tsetModel(model: ModelRef | undefined, context: Context): Promise<void>;\n\tgetThinkingLevel(context: Context): Promise<ModelThinkingLevel>;\n\tsetThinkingLevel(level: ModelThinkingLevel, context: Context): Promise<void>;\n\tgetActiveTools(context: Context): Promise<readonly string[]>;\n\tsetActiveTools(names: readonly string[], context: Context): Promise<void>;\n\t/** `{}` when unset. */\n\tgetStreamOptions(context: Context): Promise<ConversationStreamOptions>;\n\tsetStreamOptions(options: ConversationStreamOptions, context: Context): Promise<void>;\n\t/** The default policy when unset. */\n\tgetRetryPolicy(context: Context): Promise<ConversationRetryPolicy>;\n\t/** `undefined` removes the configured policy. */\n\tsetRetryPolicy(policy: ConversationRetryPolicy | undefined, context: Context): Promise<void>;\n\n\t/**\n\t * Durably admit user input or a passive entry write. Until the inbox exists, a busy conversation rejects every\n\t * submission with `ConversationBusy`.\n\t */\n\tsubmit(submission: SubmissionDraft, context: Context): Promise<Submission>;\n\n\t/** Session commit whose `tx.createTask()` defaults to this conversation. */\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tcontext(context: Context): Promise<ContextView>;\n\t/** Newest-first fork-aware history of this conversation. */\n\tentries(\n\t\tquery: Omit<EntryQuery, \"conversationId\">,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\tfork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\t/** Resolve when no live non-background task belongs to this conversation. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n// TODO: decide how Harness exposes subscribeCommits() and subscribeClose(). Their listeners run on the Session line\n// and must not throw or call Session APIs, and Harness close will also join task invocations.\n/** Durable agent harness over one Session. */\nexport interface Harness extends Session {\n\t/**\n\t * Enable task scheduling. Idempotent; throws after close. Calls that wait for progress (`Conversation.submit()`,\n\t * `Submission.wait()`, `waitForTask()`, `waitForIdle()`) enable it too.\n\t */\n\tresume(): void;\n\n\t/** Return the reserved root conversation, creating it with `init` in one commit when absent. */\n\troot(context: Context, options?: { readonly init?: ConversationInit }): Promise<Conversation>;\n\t// Conversation activity (active/idle notifications) is specified with run control in Package 17.\n\tconversation(id: ConversationId, context: Context): Promise<Conversation | undefined>;\n\tcreateConversation(options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\t/** Live tasks, unsettled submissions, and registry failures. Writes nothing and runs no task code. */\n\tinspect(context: Context): Promise<HarnessInspection>;\n\t/** Reacquire a submission, for example after reopen. */\n\tsubmission(id: SubmissionId, context: Context): Promise<Submission | undefined>;\n\t/** `not_found` for an unknown submission or one of another conversation than `conversationId`. */\n\tabortSubmission(\n\t\tid: SubmissionId,\n\t\tcontext: Context,\n\t\tconversationId?: ConversationId,\n\t): Promise<\"aborted\" | \"already_placed\" | \"settled\" | \"not_found\">;\n\t/**\n\t * Commit the abort mark, signal and join an active run invocation, and schedule the abort invocation. A task whose\n\t * definition cannot take it settles as `orphaned` instead.\n\t */\n\tabortTask(id: TaskId, context: Context): Promise<\"marked\" | \"terminal\">;\n\t/** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Resolve when no live non-background task exists. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { Cursor, Page } from "../types.ts";
|
|
3
|
+
/** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */
|
|
4
|
+
export declare class Waiters<K, T> {
|
|
5
|
+
#private;
|
|
6
|
+
add(key: K, context: Context): Promise<T>;
|
|
7
|
+
keys(): K[];
|
|
8
|
+
resolve(key: K, value: T): void;
|
|
9
|
+
rejectAll(error: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
/** Every item of a paginated scan, in page order. */
|
|
12
|
+
export declare function scanAll<T>(scan: (cursor: Cursor | undefined) => Promise<Page<T, Cursor>>): Promise<T[]>;
|
|
13
|
+
export declare function closedError(): Error;
|
|
14
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/harness/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEhD,+GAA+G;AAC/G,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC;;IAGxB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBxC;IAED,IAAI,IAAI,CAAC,EAAE,CAEV;IAED,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAI9B;IAED,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAI9B;CACD;AAED,qDAAqD;AACrD,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAS7G;AAED,wBAAgB,WAAW,IAAI,KAAK,CAEnC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */
|
|
2
|
+
export class Waiters {
|
|
3
|
+
#sets = new Map();
|
|
4
|
+
add(key, context) {
|
|
5
|
+
const signal = context.abortSignal;
|
|
6
|
+
if (signal?.aborted)
|
|
7
|
+
return Promise.reject(signal.reason);
|
|
8
|
+
const waiter = Promise.withResolvers();
|
|
9
|
+
const set = this.#sets.get(key) ?? new Set();
|
|
10
|
+
this.#sets.set(key, set.add(waiter));
|
|
11
|
+
if (signal !== undefined) {
|
|
12
|
+
const onAbort = () => {
|
|
13
|
+
set.delete(waiter);
|
|
14
|
+
if (set.size === 0 && this.#sets.get(key) === set)
|
|
15
|
+
this.#sets.delete(key);
|
|
16
|
+
waiter.reject(signal.reason);
|
|
17
|
+
};
|
|
18
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19
|
+
const detach = () => signal.removeEventListener("abort", onAbort);
|
|
20
|
+
waiter.promise.then(detach, detach);
|
|
21
|
+
}
|
|
22
|
+
return waiter.promise;
|
|
23
|
+
}
|
|
24
|
+
keys() {
|
|
25
|
+
return [...this.#sets.keys()];
|
|
26
|
+
}
|
|
27
|
+
resolve(key, value) {
|
|
28
|
+
const set = this.#sets.get(key);
|
|
29
|
+
this.#sets.delete(key);
|
|
30
|
+
for (const waiter of set ?? [])
|
|
31
|
+
waiter.resolve(value);
|
|
32
|
+
}
|
|
33
|
+
rejectAll(error) {
|
|
34
|
+
const sets = [...this.#sets.values()];
|
|
35
|
+
this.#sets.clear();
|
|
36
|
+
for (const set of sets)
|
|
37
|
+
for (const waiter of set)
|
|
38
|
+
waiter.reject(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Every item of a paginated scan, in page order. */
|
|
42
|
+
export async function scanAll(scan) {
|
|
43
|
+
const items = [];
|
|
44
|
+
let cursor;
|
|
45
|
+
do {
|
|
46
|
+
const page = await scan(cursor);
|
|
47
|
+
items.push(...page.items);
|
|
48
|
+
cursor = page.next;
|
|
49
|
+
} while (cursor !== undefined);
|
|
50
|
+
return items;
|
|
51
|
+
}
|
|
52
|
+
export function closedError() {
|
|
53
|
+
return new Error("Harness is closed");
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
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cesContent":["import type { Context } from \"@earendil-works/chord\";\nimport type { Cursor, Page } from \"../types.ts\";\n\n/** Pending waits by key. Each settles once: through `resolve`, `rejectAll`, or cancellation of its context. */\nexport class Waiters<K, T> {\n\treadonly #sets = new Map<K, Set<PromiseWithResolvers<T>>>();\n\n\tadd(key: K, context: Context): Promise<T> {\n\t\tconst signal = context.abortSignal;\n\t\tif (signal?.aborted) return Promise.reject(signal.reason);\n\t\tconst waiter = Promise.withResolvers<T>();\n\t\tconst set = this.#sets.get(key) ?? new Set();\n\t\tthis.#sets.set(key, set.add(waiter));\n\t\tif (signal !== undefined) {\n\t\t\tconst onAbort = (): void => {\n\t\t\t\tset.delete(waiter);\n\t\t\t\tif (set.size === 0 && this.#sets.get(key) === set) this.#sets.delete(key);\n\t\t\t\twaiter.reject(signal.reason);\n\t\t\t};\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tconst detach = (): void => signal.removeEventListener(\"abort\", onAbort);\n\t\t\twaiter.promise.then(detach, detach);\n\t\t}\n\t\treturn waiter.promise;\n\t}\n\n\tkeys(): K[] {\n\t\treturn [...this.#sets.keys()];\n\t}\n\n\tresolve(key: K, value: T): void {\n\t\tconst set = this.#sets.get(key);\n\t\tthis.#sets.delete(key);\n\t\tfor (const waiter of set ?? []) waiter.resolve(value);\n\t}\n\n\trejectAll(error: unknown): void {\n\t\tconst sets = [...this.#sets.values()];\n\t\tthis.#sets.clear();\n\t\tfor (const set of sets) for (const waiter of set) waiter.reject(error);\n\t}\n}\n\n/** Every item of a paginated scan, in page order. */\nexport async function scanAll<T>(scan: (cursor: Cursor | undefined) => Promise<Page<T, Cursor>>): Promise<T[]> {\n\tconst items: T[] = [];\n\tlet cursor: Cursor | undefined;\n\tdo {\n\t\tconst page = await scan(cursor);\n\t\titems.push(...page.items);\n\t\tcursor = page.next;\n\t} while (cursor !== undefined);\n\treturn items;\n}\n\nexport function closedError(): Error {\n\treturn new Error(\"Harness is closed\");\n}\n"]}
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Id, Seq } from "./types.ts";
|
|
2
|
+
/** Apply an erased ID brand at a trusted numeric allocation or decoding boundary. */
|
|
3
|
+
export declare function idFromNumber<I extends Id<string>>(value: number): I;
|
|
4
|
+
/** Apply the erased commit-sequence brand at a trusted storage boundary. */
|
|
5
|
+
export declare function seqFromNumber(value: number): Seq;
|
|
6
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE1C,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAEnE;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAEhD"}
|
package/dist/ids.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Apply an erased ID brand at a trusted numeric allocation or decoding boundary. */
|
|
2
|
+
export function idFromNumber(value) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
/** Apply the erased commit-sequence brand at a trusted storage boundary. */
|
|
6
|
+
export function seqFromNumber(value) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ids.js.map
|
package/dist/ids.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAuB,KAAa;IAC/D,OAAO,KAAU,CAAC;AACnB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,OAAO,KAAY,CAAC;AACrB,CAAC","sourcesContent":["import type { Id, Seq } from \"./types.ts\";\n\n/** Apply an erased ID brand at a trusted numeric allocation or decoding boundary. */\nexport function idFromNumber<I extends Id<string>>(value: number): I {\n\treturn value as I;\n}\n\n/** Apply the erased commit-sequence brand at a trusted storage boundary. */\nexport function seqFromNumber(value: number): Seq {\n\treturn value as Seq;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
export { defineDoc, defineDocFamily } from "./documents.ts";
|
|
2
|
+
export { AssistantEntry, defineEntry, SystemEntry, ToolResultEntry, UserEntry } from "./entries.ts";
|
|
3
|
+
export { ConversationBusy, ReadAfterWrite, StorageRejected } from "./errors.ts";
|
|
4
|
+
export { ConversationConfig, type ConversationConfigState } from "./harness/config.ts";
|
|
5
|
+
export { type GenerationCheckpoint, type GenerationInput, type GenerationResult, GenerationTask, } from "./harness/generation.ts";
|
|
6
|
+
export { Harness } from "./harness/harness.ts";
|
|
7
|
+
export { LiveDoc, type LiveState } from "./harness/live.ts";
|
|
8
|
+
export { createRegistry } from "./harness/registry.ts";
|
|
9
|
+
export type { AnyTask, ContextView, Conversation, ConversationCreateOptions, ConversationHandle, ConversationInit, ConversationRetryPolicy, ConversationSetup, ConversationStreamOptions, HarnessInspection, HarnessOptions, HookRegistration, HookScope, HooksOf, InputSubmissionDraft, ModelRef, PromptInput, PromptSection, PromptSectionWrapper, Registration, Registry, RegistryFailure, RegistryReader, RegistrySnapshot, SettledSubmissionRecord, SettledTask, Submission, SubmissionDraft, TaskInspection, ToolControl, ToolExecutionApi, ToolExecutionResult, ToolRegistration, ToolWrapper, UserInput, } from "./harness/types.ts";
|
|
10
|
+
export { createSession } from "./session/session.ts";
|
|
1
11
|
export { MemoryStorage } from "./storage/memory.ts";
|
|
2
|
-
export
|
|
12
|
+
export { defineTask } from "./tasks.ts";
|
|
13
|
+
export type { CheckpointInfo, CommitChange, CommitPublication, CommonDocDefinition, ContextEdit, ConversationDocFamilyToken, ConversationDocToken, ConversationId, ConversationOwnership, ConversationQuery, ConversationRecord, Cursor, DocDefinition, DocFamilyDefinition, DocFamilyToken, DocToken, DocumentAddress, DocumentCommitChange, DocumentContent, DocumentCopySource, DocumentCreate, DocumentId, DocumentObserver, DocumentPoint, DocumentQuery, DocumentReader, DocumentRecord, DocumentSemantics, DocumentState, DocumentWatch, Entry, EntryDraft, EntryId, EntryQuery, EntryRecord, Id, JsonObject, LatestConversationSemantics, NextTaskState, Page, PhaseHandler, RewindableConversationDocFamilyToken, RewindableConversationDocToken, RewindableConversationSemantics, RunningTask, Seq, Session, SessionDocFamilyToken, SessionDocToken, Storage, StorageWrite, StoredDocument, SubmissionCreate, SubmissionId, SubmissionQuery, SubmissionRecord, SubmissionSettlement, TableCommitChange, Task, TaskDefinition, TaskDocFamilyToken, TaskDocToken, TaskId, TaskOptions, TaskOutcome, TaskOutcomeError, TaskQuery, TaskRecord, TaskRuntime, TaskState, Tx, TypedEntry, TypedEntryDraft, WatchEnd, WatchHandle, } from "./types.ts";
|
|
3
14
|
export { ROOT_CONVERSATION_ID } from "./types.ts";
|
|
4
15
|
//# 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,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EACN,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,EAAE,EACF,UAAU,EACV,IAAI,EACJ,GAAG,EACH,OAAO,EACP,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,SAAS,
|
|
1
|
+
{"version":3,"file":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UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EACX,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACN,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,EACL,UAAU,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,EAAE,EACF,UAAU,EACV,2BAA2B,EAC3B,aAAa,EACb,IAAI,EACJ,YAAY,EACZ,oCAAoC,EACpC,8BAA8B,EAC9B,+BAA+B,EAC/B,WAAW,EACX,GAAG,EACH,OAAO,EACP,qBAAqB,EACrB,eAAe,EACf,OAAO,EACP,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,EAAE,EACF,UAAU,EACV,eAAe,EACf,QAAQ,EACR,WAAW,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export { defineDoc, defineDocFamily } from "./documents.js";
|
|
2
|
+
export { AssistantEntry, defineEntry, SystemEntry, ToolResultEntry, UserEntry } from "./entries.js";
|
|
3
|
+
export { ConversationBusy, ReadAfterWrite, StorageRejected } from "./errors.js";
|
|
4
|
+
export { ConversationConfig } from "./harness/config.js";
|
|
5
|
+
export { GenerationTask, } from "./harness/generation.js";
|
|
6
|
+
export { Harness } from "./harness/harness.js";
|
|
7
|
+
export { LiveDoc } from "./harness/live.js";
|
|
8
|
+
export { createRegistry } from "./harness/registry.js";
|
|
9
|
+
export { createSession } from "./session/session.js";
|
|
1
10
|
export { MemoryStorage } from "./storage/memory.js";
|
|
11
|
+
export { defineTask } from "./tasks.js";
|
|
2
12
|
export { ROOT_CONVERSATION_ID } from "./types.js";
|
|
3
13
|
//# 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":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAgC,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAIN,cAAc,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAkB,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAsCvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA8ExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { defineDoc, defineDocFamily } from \"./documents.ts\";\nexport { AssistantEntry, defineEntry, SystemEntry, ToolResultEntry, UserEntry } from \"./entries.ts\";\nexport { ConversationBusy, ReadAfterWrite, StorageRejected } from \"./errors.ts\";\nexport { ConversationConfig, type ConversationConfigState } from \"./harness/config.ts\";\nexport {\n\ttype GenerationCheckpoint,\n\ttype GenerationInput,\n\ttype GenerationResult,\n\tGenerationTask,\n} from \"./harness/generation.ts\";\nexport { Harness } from \"./harness/harness.ts\";\nexport { LiveDoc, type LiveState } from \"./harness/live.ts\";\nexport { createRegistry } from \"./harness/registry.ts\";\nexport type {\n\tAnyTask,\n\tContextView,\n\tConversation,\n\tConversationCreateOptions,\n\tConversationHandle,\n\tConversationInit,\n\tConversationRetryPolicy,\n\tConversationSetup,\n\tConversationStreamOptions,\n\tHarnessInspection,\n\tHarnessOptions,\n\tHookRegistration,\n\tHookScope,\n\tHooksOf,\n\tInputSubmissionDraft,\n\tModelRef,\n\tPromptInput,\n\tPromptSection,\n\tPromptSectionWrapper,\n\tRegistration,\n\tRegistry,\n\tRegistryFailure,\n\tRegistryReader,\n\tRegistrySnapshot,\n\tSettledSubmissionRecord,\n\tSettledTask,\n\tSubmission,\n\tSubmissionDraft,\n\tTaskInspection,\n\tToolControl,\n\tToolExecutionApi,\n\tToolExecutionResult,\n\tToolRegistration,\n\tToolWrapper,\n\tUserInput,\n} from \"./harness/types.ts\";\nexport { createSession } from \"./session/session.ts\";\nexport { MemoryStorage } from \"./storage/memory.ts\";\nexport { defineTask } from \"./tasks.ts\";\nexport type {\n\tCheckpointInfo,\n\tCommitChange,\n\tCommitPublication,\n\tCommonDocDefinition,\n\tContextEdit,\n\tConversationDocFamilyToken,\n\tConversationDocToken,\n\tConversationId,\n\tConversationOwnership,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocDefinition,\n\tDocFamilyDefinition,\n\tDocFamilyToken,\n\tDocToken,\n\tDocumentAddress,\n\tDocumentCommitChange,\n\tDocumentContent,\n\tDocumentCopySource,\n\tDocumentCreate,\n\tDocumentId,\n\tDocumentObserver,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentReader,\n\tDocumentRecord,\n\tDocumentSemantics,\n\tDocumentState,\n\tDocumentWatch,\n\tEntry,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tId,\n\tJsonObject,\n\tLatestConversationSemantics,\n\tNextTaskState,\n\tPage,\n\tPhaseHandler,\n\tRewindableConversationDocFamilyToken,\n\tRewindableConversationDocToken,\n\tRewindableConversationSemantics,\n\tRunningTask,\n\tSeq,\n\tSession,\n\tSessionDocFamilyToken,\n\tSessionDocToken,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionCreate,\n\tSubmissionId,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tSubmissionSettlement,\n\tTableCommitChange,\n\tTask,\n\tTaskDefinition,\n\tTaskDocFamilyToken,\n\tTaskDocToken,\n\tTaskId,\n\tTaskOptions,\n\tTaskOutcome,\n\tTaskOutcomeError,\n\tTaskQuery,\n\tTaskRecord,\n\tTaskRuntime,\n\tTaskState,\n\tTx,\n\tTypedEntry,\n\tTypedEntryDraft,\n\tWatchEnd,\n\tWatchHandle,\n} from \"./types.ts\";\nexport { ROOT_CONVERSATION_ID } from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { ConversationId, DocumentCopySource, DocumentCreate, EntryId, Storage } from "../types.ts";
|
|
3
|
+
/** One definition-free document copy to create with a forked conversation. */
|
|
4
|
+
export type ForkDocumentCopy = {
|
|
5
|
+
readonly record: DocumentCreate;
|
|
6
|
+
readonly source: DocumentCopySource;
|
|
7
|
+
};
|
|
8
|
+
/** Select every persisted conversation document copied by one fork. */
|
|
9
|
+
export declare function prepareForkDocumentCopies(storage: Storage, parentConversationId: ConversationId, at: EntryId, childConversationId: ConversationId, context: Context): Promise<readonly ForkDocumentCopy[]>;
|
|
10
|
+
//# sourceMappingURL=forks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forks.d.ts","sourceRoot":"","sources":["../../src/session/forks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,KAAK,EACX,cAAc,EAEd,kBAAkB,EAClB,cAAc,EAId,OAAO,EACP,OAAO,EACP,MAAM,aAAa,CAAC;AAMrB,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;CACpC,CAAC;AAEF,uEAAuE;AACvE,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,OAAO,EAChB,oBAAoB,EAAE,cAAc,EACpC,EAAE,EAAE,OAAO,EACX,mBAAmB,EAAE,cAAc,EACnC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CA2BtC"}
|