@earendil-works/pi-durable 0.87.0 → 0.99.0
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 +72 -1
- 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 +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- 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 +60 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +681 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/sqlite/database.d.ts +30 -0
- package/dist/storage/sqlite/database.d.ts.map +1 -0
- package/dist/storage/sqlite/database.js +2 -0
- package/dist/storage/sqlite/database.js.map +1 -0
- package/dist/storage/sqlite/index.d.ts +4 -0
- package/dist/storage/sqlite/index.d.ts.map +1 -0
- package/dist/storage/sqlite/index.js +3 -0
- package/dist/storage/sqlite/index.js.map +1 -0
- package/dist/storage/sqlite/migrations.d.ts +11 -0
- package/dist/storage/sqlite/migrations.d.ts.map +1 -0
- package/dist/storage/sqlite/migrations.js +111 -0
- package/dist/storage/sqlite/migrations.js.map +1 -0
- package/dist/storage/sqlite/node.d.ts +25 -0
- package/dist/storage/sqlite/node.d.ts.map +1 -0
- package/dist/storage/sqlite/node.js +97 -0
- package/dist/storage/sqlite/node.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +51 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/storage/sqlite/storage.js +628 -0
- package/dist/storage/sqlite/storage.js.map +1 -0
- 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 +525 -78
- 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 +90 -102
- package/docs/pico-v5-handoff.md +493 -253
- package/docs/pico-v5.md +1901 -848
- package/package.json +47 -5
- package/dist/memory-storage.d.ts +0 -37
- package/dist/memory-storage.d.ts.map +0 -1
- package/dist/memory-storage.js +0 -322
- package/dist/memory-storage.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,12 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
Durable conversation, task, and document runtime for Pi.
|
|
4
4
|
|
|
5
|
-
This package contains the Pico runtime. Its current public API provides
|
|
5
|
+
This package contains the Pico runtime. Its current public API provides durable record contracts and memory, JSONL, and SQLite storage implementations:
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
import { MemoryStorage, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
The root export is runtime-neutral. Storage implementations also have explicit subpaths:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { MemoryStorage } from "@earendil-works/pi-durable/storage/memory";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Node applications can open file-backed JSONL or SQLite storage through Node-only subpaths:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
21
|
+
import { openNodeJsonlStorage } from "@earendil-works/pi-durable/storage/jsonl/node";
|
|
22
|
+
import { openNodeSqliteStorage } from "@earendil-works/pi-durable/storage/sqlite/node";
|
|
23
|
+
|
|
24
|
+
const jsonl = await openNodeJsonlStorage("./session", BACKGROUND_CONTEXT);
|
|
25
|
+
const sqlite = await openNodeSqliteStorage("./session.sqlite");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The portable JSONL core accepts the `FileSystem` capability exported from `@earendil-works/pi-durable/env`. Its `fsync` option defaults to `false`; enabling it flushes affected sidecars before appending the main commit marker. One `JsonlStorage` owner must serialize writes to a storage directory; cross-process locking and ID allocation are not supported.
|
|
29
|
+
|
|
30
|
+
The portable SQLite core, minimal database facade, and ordered schema migrations are exported from `@earendil-works/pi-durable/storage/sqlite`. Adapters for synchronous SQLite environments such as Bun and Cloudflare Durable Objects can implement that facade without importing Node APIs. Remote asynchronous APIs such as Cloudflare D1 cannot implement this synchronous facade; they require a dedicated `Storage` backend.
|
|
31
|
+
|
|
32
|
+
The Node adapter uses WAL mode with `synchronous = NORMAL` and checkpoints the WAL on close. Acknowledged commits survive process crashes, but the newest commits may be lost after a power or host failure. One `SqliteStorage` owner must serialize writes to a database file; cross-process ID allocation is not supported.
|
|
33
|
+
|
|
34
|
+
## Storage conformance
|
|
35
|
+
|
|
36
|
+
Storage adapters can register the runner-independent conformance cases through the testing entry. The convenience adapter accepts Vitest/Jest-compatible runner functions without importing either package:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { registerStorageConformance } from "@earendil-works/pi-durable/testing";
|
|
40
|
+
import { describe, expect, it } from "vitest";
|
|
41
|
+
|
|
42
|
+
registerStorageConformance({ describe, expect, it }, "Some Custom Storage", async (use) => {
|
|
43
|
+
const storage = await openCustomStorage();
|
|
44
|
+
try {
|
|
45
|
+
await use(storage);
|
|
46
|
+
} finally {
|
|
47
|
+
await closeStorage(storage);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The provider must call and await `use` exactly once with isolated storage. Other runners can use `createStorageConformance` with their own `StorageConformanceAssertions` implementation.
|
|
53
|
+
|
|
54
|
+
## Storage benchmarks
|
|
55
|
+
|
|
56
|
+
From this package directory:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm run bench:storage
|
|
60
|
+
npm run bench:storage:memory
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The timing suite runs shared deterministic workloads against the built-in memory, JSONL, and SQLite adapters. Third-party adapters can import the same seeds and workload definitions from `@earendil-works/pi-durable/testing` and use their platform's timing runner:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import {
|
|
67
|
+
seedStorageBenchmark,
|
|
68
|
+
seedStorageWriteBenchmark,
|
|
69
|
+
STORAGE_READ_BENCHMARKS,
|
|
70
|
+
STORAGE_WRITE_BENCHMARKS,
|
|
71
|
+
} from "@earendil-works/pi-durable/testing";
|
|
72
|
+
|
|
73
|
+
const dataset = await seedStorageBenchmark(readStorage);
|
|
74
|
+
await STORAGE_READ_BENCHMARKS[0].run(readStorage, dataset);
|
|
75
|
+
|
|
76
|
+
await seedStorageWriteBenchmark(freshWriteStorage);
|
|
77
|
+
await STORAGE_WRITE_BENCHMARKS[0].run(freshWriteStorage);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Read scenarios reuse one seeded store; each write sample requires a fresh seeded store. The workloads cover representative commits, indexed reads, pagination, fork traversal, document replay, historical reads, and persistent-backend reopen. The footprint suite measures each built-in adapter in a separate process at 1k and 10k scales and reports heap, RSS, external memory, file counts, and on-disk JSONL/SQLite size. These synthetic workloads are baselines for regression analysis, not production capacity limits or CI pass/fail thresholds.
|
|
81
|
+
|
|
11
82
|
The normative design and implementation sequence are in:
|
|
12
83
|
|
|
13
84
|
- [`docs/pico-v5.md`](docs/pico-v5.md)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { Op } from "@earendil-works/chord/delta";
|
|
3
|
+
import type { CheckpointInfo, CommonDocDefinition, ConversationDocFamilyToken, ConversationDocToken, DocumentAddress, DocumentCreate, DocumentId, DocumentRecord, DocumentSemantics, JsonObject, LatestConversationSemantics, RewindableConversationDocFamilyToken, RewindableConversationDocToken, RewindableConversationSemantics, SessionDocFamilyToken, SessionDocToken, StoredDocument, TaskDocFamilyToken, TaskDocToken } from "./types.ts";
|
|
4
|
+
type FamilyInput<T extends JsonObject, I extends JsonValue> = Omit<CommonDocDefinition<T>, "initial"> & {
|
|
5
|
+
readonly family: true;
|
|
6
|
+
initial(seed: I): T;
|
|
7
|
+
};
|
|
8
|
+
/** Define a Session-scoped singleton document. */
|
|
9
|
+
export declare function defineDoc<T extends JsonObject>(definition: CommonDocDefinition<T> & {
|
|
10
|
+
readonly scope: "session";
|
|
11
|
+
}): SessionDocToken<T>;
|
|
12
|
+
/** Define a latest-only conversation singleton document. */
|
|
13
|
+
export declare function defineDoc<T extends JsonObject>(definition: CommonDocDefinition<T> & LatestConversationSemantics): ConversationDocToken<T>;
|
|
14
|
+
/** Define a rewindable conversation singleton document. */
|
|
15
|
+
export declare function defineDoc<T extends JsonObject>(definition: CommonDocDefinition<T> & RewindableConversationSemantics): RewindableConversationDocToken<T>;
|
|
16
|
+
/** Define a task-scoped singleton document. */
|
|
17
|
+
export declare function defineDoc<T extends JsonObject>(definition: CommonDocDefinition<T> & {
|
|
18
|
+
readonly scope: "task";
|
|
19
|
+
}): TaskDocToken<T>;
|
|
20
|
+
/** Define a Session-scoped document family. */
|
|
21
|
+
export declare function defineDocFamily<T extends JsonObject, I extends JsonValue>(definition: FamilyInput<T, I> & {
|
|
22
|
+
readonly scope: "session";
|
|
23
|
+
}): SessionDocFamilyToken<T, I>;
|
|
24
|
+
/** Define a latest-only conversation document family. */
|
|
25
|
+
export declare function defineDocFamily<T extends JsonObject, I extends JsonValue>(definition: FamilyInput<T, I> & LatestConversationSemantics): ConversationDocFamilyToken<T, I>;
|
|
26
|
+
/** Define a rewindable conversation document family. */
|
|
27
|
+
export declare function defineDocFamily<T extends JsonObject, I extends JsonValue>(definition: FamilyInput<T, I> & RewindableConversationSemantics): RewindableConversationDocFamilyToken<T, I>;
|
|
28
|
+
/** Define a task-scoped document family. */
|
|
29
|
+
export declare function defineDocFamily<T extends JsonObject, I extends JsonValue>(definition: FamilyInput<T, I> & {
|
|
30
|
+
readonly scope: "task";
|
|
31
|
+
}): TaskDocFamilyToken<T, I>;
|
|
32
|
+
/** Erased definition shape used by the Session after overload resolution. */
|
|
33
|
+
export type AnyDocDefinition = DocumentSemantics & {
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly version: number;
|
|
36
|
+
readonly family?: true;
|
|
37
|
+
initial(seed?: JsonValue): JsonObject;
|
|
38
|
+
migrate?(value: JsonObject, fromVersion: number): JsonObject;
|
|
39
|
+
checkpointWhen?(value: Readonly<JsonObject>, ops: readonly Op[], info: CheckpointInfo): boolean;
|
|
40
|
+
};
|
|
41
|
+
/** Erased singleton or family token. */
|
|
42
|
+
export type AnyDocToken = {
|
|
43
|
+
readonly definition: AnyDocDefinition;
|
|
44
|
+
};
|
|
45
|
+
/** Logical address plus its string identity for maps. */
|
|
46
|
+
export type ResolvedAddress = {
|
|
47
|
+
readonly address: DocumentAddress;
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly nextArgument: number;
|
|
50
|
+
};
|
|
51
|
+
/** Resolve an overloaded argument list and return the index after the owner and family key. */
|
|
52
|
+
export declare function resolveAddress(definition: AnyDocDefinition, args: readonly unknown[]): ResolvedAddress;
|
|
53
|
+
/** Stable string identity of one logical address. */
|
|
54
|
+
export declare function addressId(address: DocumentAddress): string;
|
|
55
|
+
/** Build the storage create record for a new incarnation at an address. */
|
|
56
|
+
export declare function documentCreate(definition: AnyDocDefinition, address: DocumentAddress, id: DocumentId): DocumentCreate;
|
|
57
|
+
/** Reject typed access whose token disagrees with the persisted scope, history, or fork semantics. */
|
|
58
|
+
export declare function checkRecordScope(definition: AnyDocDefinition, record: DocumentCreate | DocumentRecord): void;
|
|
59
|
+
/** Reject typed access to a stored version the supplied definition cannot use. */
|
|
60
|
+
export declare function checkRecordVersion(definition: AnyDocDefinition, record: DocumentCreate | DocumentRecord, version: number): void;
|
|
61
|
+
/** Validate and materialize a detached stored value for typed access. */
|
|
62
|
+
export declare function materializeDocument(definition: AnyDocDefinition, stored: StoredDocument): JsonObject;
|
|
63
|
+
/** Validate and materialize one detached value before its first persisted incarnation. */
|
|
64
|
+
export declare function materializeDocumentValue(definition: AnyDocDefinition, record: DocumentCreate | DocumentRecord, version: number, value: JsonObject): JsonObject;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAC;AAEtD,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,0BA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AAE,MAAM,EACf,KAAK,EAAE,UAAU,GACf,UAAU,CAKZ"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { copyJson } from "@earendil-works/chord";
|
|
2
|
+
import { idFromNumber } from "./ids.js";
|
|
3
|
+
export function defineDoc(definition) {
|
|
4
|
+
validateDefinition(definition);
|
|
5
|
+
return { definition };
|
|
6
|
+
}
|
|
7
|
+
export function defineDocFamily(definition) {
|
|
8
|
+
validateDefinition(definition);
|
|
9
|
+
return { definition };
|
|
10
|
+
}
|
|
11
|
+
function validateDefinition(definition) {
|
|
12
|
+
if (!Number.isSafeInteger(definition.version) || definition.version < 1) {
|
|
13
|
+
throw new TypeError(`Document ${definition.kind} version must be a positive integer`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Resolve an overloaded argument list and return the index after the owner and family key. */
|
|
17
|
+
export function resolveAddress(definition, args) {
|
|
18
|
+
let index = 0;
|
|
19
|
+
let scope;
|
|
20
|
+
switch (definition.scope) {
|
|
21
|
+
case "session":
|
|
22
|
+
scope = { kind: "session" };
|
|
23
|
+
break;
|
|
24
|
+
case "conversation":
|
|
25
|
+
scope = { kind: "conversation", conversationId: ownerId(args[index++], definition) };
|
|
26
|
+
break;
|
|
27
|
+
case "task":
|
|
28
|
+
scope = { kind: "task", taskId: ownerId(args[index++], definition) };
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const key = definition.family === true ? args[index++] : undefined;
|
|
32
|
+
const address = key === undefined ? { kind: definition.kind, scope } : { kind: definition.kind, scope, key };
|
|
33
|
+
return { address, id: addressId(address), nextArgument: index };
|
|
34
|
+
}
|
|
35
|
+
function ownerId(value, definition) {
|
|
36
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
37
|
+
throw new TypeError(`Document ${definition.kind} requires a ${definition.scope} ID`);
|
|
38
|
+
}
|
|
39
|
+
return idFromNumber(value);
|
|
40
|
+
}
|
|
41
|
+
/** Stable string identity of one logical address. */
|
|
42
|
+
export function addressId(address) {
|
|
43
|
+
const owner = address.scope.kind === "session"
|
|
44
|
+
? null
|
|
45
|
+
: address.scope.kind === "conversation"
|
|
46
|
+
? address.scope.conversationId
|
|
47
|
+
: address.scope.taskId;
|
|
48
|
+
return JSON.stringify([address.kind, address.scope.kind, owner, address.key ?? null]);
|
|
49
|
+
}
|
|
50
|
+
/** Build the storage create record for a new incarnation at an address. */
|
|
51
|
+
export function documentCreate(definition, address, id) {
|
|
52
|
+
const key = address.key === undefined ? {} : { key: address.key };
|
|
53
|
+
switch (address.scope.kind) {
|
|
54
|
+
case "session":
|
|
55
|
+
return { id, kind: address.kind, ...key, scope: address.scope };
|
|
56
|
+
case "task":
|
|
57
|
+
return { id, kind: address.kind, ...key, scope: address.scope };
|
|
58
|
+
case "conversation":
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
kind: address.kind,
|
|
62
|
+
...key,
|
|
63
|
+
scope: address.scope,
|
|
64
|
+
history: definition.history,
|
|
65
|
+
fork: definition.fork,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Reject typed access whose token disagrees with the persisted scope, history, or fork semantics. */
|
|
70
|
+
export function checkRecordScope(definition, record) {
|
|
71
|
+
if (record.scope.kind !== definition.scope ||
|
|
72
|
+
(record.scope.kind === "conversation" &&
|
|
73
|
+
(record.history !== definition.history || record.fork !== definition.fork))) {
|
|
74
|
+
throw new TypeError(`Document ${record.id} (${record.kind}) does not match the supplied definition semantics`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Reject typed access to a stored version the supplied definition cannot use. */
|
|
78
|
+
export function checkRecordVersion(definition, record, version) {
|
|
79
|
+
if (version > definition.version) {
|
|
80
|
+
throw new Error(`Document ${record.id} (${record.kind}) has newer version ${version} than ${definition.version}`);
|
|
81
|
+
}
|
|
82
|
+
if (version < definition.version && definition.migrate === undefined) {
|
|
83
|
+
throw new Error(`Document ${record.id} (${record.kind}) requires migration from version ${version}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Validate and materialize a detached stored value for typed access. */
|
|
87
|
+
export function materializeDocument(definition, stored) {
|
|
88
|
+
return materializeDocumentValue(definition, stored.record, stored.version, stored.value);
|
|
89
|
+
}
|
|
90
|
+
/** Validate and materialize one detached value before its first persisted incarnation. */
|
|
91
|
+
export function materializeDocumentValue(definition, record, version, value) {
|
|
92
|
+
checkRecordScope(definition, record);
|
|
93
|
+
checkRecordVersion(definition, record, version);
|
|
94
|
+
if (version === definition.version)
|
|
95
|
+
return value;
|
|
96
|
+
return copyJson(definition.migrate(value, version));
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAmDxC,MAAM,UAAU,SAAS,CAAuB,UAA4B;IAC3E,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,EAAE,UAAU,EAAE,CAAC;AACvB,CAAC;AAkBD,MAAM,UAAU,eAAe,CAC9B,UAAqC;IAErC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,EAAE,UAAU,EAAE,CAAC;AACvB,CAAC;AAeD,SAAS,kBAAkB,CAAC,UAA4B;IACvD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,SAAS,CAAC,YAAY,UAAU,CAAC,IAAI,qCAAqC,CAAC,CAAC;IACvF,CAAC;AACF,CAAC;AASD,+FAA+F;AAC/F,MAAM,UAAU,cAAc,CAAC,UAA4B,EAAE,IAAwB;IACpF,IAAI,KAAK,GAAG,CAAC,CA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AAU,wBAAwB,CACvC,UAA4B,EAC5B,MAAuC,EACvC,OAAe,EACf,KAAiB;IAEjB,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrC,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,UAAU,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IACjD,OAAO,QAAQ,CAAC,UAAU,CAAC,OAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAe,CAAC;AACpE,CAAC","sourcesContent":["import { copyJson, type JsonValue } from \"@earendil-works/chord\";\nimport type { Op } from \"@earendil-works/chord/delta\";\nimport { idFromNumber } from \"./ids.ts\";\nimport type {\n\tCheckpointInfo,\n\tCommonDocDefinition,\n\tConversationDocFamilyToken,\n\tConversationDocToken,\n\tConversationId,\n\tDocDefinition,\n\tDocFamilyDefinition,\n\tDocFamilyToken,\n\tDocToken,\n\tDocumentAddress,\n\tDocumentCreate,\n\tDocumentId,\n\tDocumentRecord,\n\tDocumentSemantics,\n\tId,\n\tJsonObject,\n\tLatestConversationSemantics,\n\tRewindableConversationDocFamilyToken,\n\tRewindableConversationDocToken,\n\tRewindableConversationSemantics,\n\tSessionDocFamilyToken,\n\tSessionDocToken,\n\tStoredDocument,\n\tTaskDocFamilyToken,\n\tTaskDocToken,\n\tTaskId,\n} from \"./types.ts\";\n\ntype FamilyInput<T extends JsonObject, I extends JsonValue> = Omit<CommonDocDefinition<T>, \"initial\"> & {\n\treadonly family: true;\n\tinitial(seed: I): T;\n};\n\n/** Define a Session-scoped singleton document. */\nexport function defineDoc<T extends JsonObject>(\n\tdefinition: CommonDocDefinition<T> & { readonly scope: \"session\" },\n): SessionDocToken<T>;\n/** Define a latest-only conversation singleton document. */\nexport function defineDoc<T extends JsonObject>(\n\tdefinition: CommonDocDefinition<T> & LatestConversationSemantics,\n): ConversationDocToken<T>;\n/** Define a rewindable conversation singleton document. */\nexport function defineDoc<T extends JsonObject>(\n\tdefinition: CommonDocDefinition<T> & RewindableConversationSemantics,\n): RewindableConversationDocToken<T>;\n/** Define a task-scoped singleton document. */\nexport function defineDoc<T extends JsonObject>(\n\tdefinition: CommonDocDefinition<T> & { readonly scope: \"task\" },\n): TaskDocToken<T>;\nexport function defineDoc<T extends JsonObject>(definition: DocDefinition<T>): DocToken<T, DocDefinition<T>> {\n\tvalidateDefinition(definition);\n\treturn { definition };\n}\n\n/** Define a Session-scoped document family. */\nexport function defineDocFamily<T extends JsonObject, I extends JsonValue>(\n\tdefinition: FamilyInput<T, I> & { readonly scope: \"session\" },\n): SessionDocFamilyToken<T, I>;\n/** Define a latest-only conversation document family. */\nexport function defineDocFamily<T extends JsonObject, I extends JsonValue>(\n\tdefinition: FamilyInput<T, I> & LatestConversationSemantics,\n): ConversationDocFamilyToken<T, I>;\n/** Define a rewindable conversation document family. */\nexport function defineDocFamily<T extends JsonObject, I extends JsonValue>(\n\tdefinition: FamilyInput<T, I> & RewindableConversationSemantics,\n): RewindableConversationDocFamilyToken<T, I>;\n/** Define a task-scoped document family. */\nexport function defineDocFamily<T extends JsonObject, I extends JsonValue>(\n\tdefinition: FamilyInput<T, I> & { readonly scope: \"task\" },\n): TaskDocFamilyToken<T, I>;\nexport function defineDocFamily<T extends JsonObject, I extends JsonValue>(\n\tdefinition: DocFamilyDefinition<T, I>,\n): DocFamilyToken<T, I, DocFamilyDefinition<T, I>> {\n\tvalidateDefinition(definition);\n\treturn { definition };\n}\n\n/** Erased definition shape used by the Session after overload resolution. */\nexport type AnyDocDefinition = DocumentSemantics & {\n\treadonly kind: string;\n\treadonly version: number;\n\treadonly family?: true;\n\tinitial(seed?: JsonValue): JsonObject;\n\tmigrate?(value: JsonObject, fromVersion: number): JsonObject;\n\tcheckpointWhen?(value: Readonly<JsonObject>, ops: readonly Op[], info: CheckpointInfo): boolean;\n};\n\n/** Erased singleton or family token. */\nexport type AnyDocToken = { readonly definition: AnyDocDefinition };\n\nfunction validateDefinition(definition: AnyDocDefinition): void {\n\tif (!Number.isSafeInteger(definition.version) || definition.version < 1) {\n\t\tthrow new TypeError(`Document ${definition.kind} version must be a positive integer`);\n\t}\n}\n\n/** Logical address plus its string identity for maps. */\nexport type ResolvedAddress = {\n\treadonly address: DocumentAddress;\n\treadonly id: string;\n\treadonly nextArgument: number;\n};\n\n/** Resolve an overloaded argument list and return the index after the owner and family key. */\nexport function resolveAddress(definition: AnyDocDefinition, args: readonly unknown[]): ResolvedAddress {\n\tlet index = 0;\n\tlet scope: DocumentAddress[\"scope\"];\n\tswitch (definition.scope) {\n\t\tcase \"session\":\n\t\t\tscope = { kind: \"session\" };\n\t\t\tbreak;\n\t\tcase \"conversation\":\n\t\t\tscope = { kind: \"conversation\", conversationId: ownerId<ConversationId>(args[index++], definition) };\n\t\t\tbreak;\n\t\tcase \"task\":\n\t\t\tscope = { kind: \"task\", taskId: ownerId<TaskId>(args[index++], definition) };\n\t\t\tbreak;\n\t}\n\tconst key = definition.family === true ? (args[index++] as string) : undefined;\n\tconst address: DocumentAddress =\n\t\tkey === undefined ? { kind: definition.kind, scope } : { kind: definition.kind, scope, key };\n\treturn { address, id: addressId(address), nextArgument: index };\n}\n\nfunction ownerId<I extends Id<string>>(value: unknown, definition: AnyDocDefinition): I {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value)) {\n\t\tthrow new TypeError(`Document ${definition.kind} requires a ${definition.scope} ID`);\n\t}\n\treturn idFromNumber<I>(value);\n}\n\n/** Stable string identity of one logical address. */\nexport function addressId(address: DocumentAddress): string {\n\tconst owner =\n\t\taddress.scope.kind === \"session\"\n\t\t\t? null\n\t\t\t: address.scope.kind === \"conversation\"\n\t\t\t\t? address.scope.conversationId\n\t\t\t\t: address.scope.taskId;\n\treturn JSON.stringify([address.kind, address.scope.kind, owner, address.key ?? null]);\n}\n\n/** Build the storage create record for a new incarnation at an address. */\nexport function documentCreate(definition: AnyDocDefinition, address: DocumentAddress, id: DocumentId): DocumentCreate {\n\tconst key = address.key === undefined ? {} : { key: address.key };\n\tswitch (address.scope.kind) {\n\t\tcase \"session\":\n\t\t\treturn { id, kind: address.kind, ...key, scope: address.scope };\n\t\tcase \"task\":\n\t\t\treturn { id, kind: address.kind, ...key, scope: address.scope };\n\t\tcase \"conversation\":\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tkind: address.kind,\n\t\t\t\t...key,\n\t\t\t\tscope: address.scope,\n\t\t\t\thistory: definition.history!,\n\t\t\t\tfork: definition.fork!,\n\t\t\t} as DocumentCreate;\n\t}\n}\n\n/** Reject typed access whose token disagrees with the persisted scope, history, or fork semantics. */\nexport function checkRecordScope(definition: AnyDocDefinition, record: DocumentCreate | DocumentRecord): void {\n\tif (\n\t\trecord.scope.kind !== definition.scope ||\n\t\t(record.scope.kind === \"conversation\" &&\n\t\t\t(record.history !== definition.history || record.fork !== definition.fork))\n\t) {\n\t\tthrow new TypeError(`Document ${record.id} (${record.kind}) does not match the supplied definition semantics`);\n\t}\n}\n\n/** Reject typed access to a stored version the supplied definition cannot use. */\nexport function checkRecordVersion(\n\tdefinition: AnyDocDefinition,\n\trecord: DocumentCreate | DocumentRecord,\n\tversion: number,\n): void {\n\tif (version > definition.version) {\n\t\tthrow new Error(`Document ${record.id} (${record.kind}) has newer version ${version} than ${definition.version}`);\n\t}\n\tif (version < definition.version && definition.migrate === undefined) {\n\t\tthrow new Error(`Document ${record.id} (${record.kind}) requires migration from version ${version}`);\n\t}\n}\n\n/** Validate and materialize a detached stored value for typed access. */\nexport function materializeDocument(definition: AnyDocDefinition, stored: StoredDocument): JsonObject {\n\treturn materializeDocumentValue(definition, stored.record, stored.version, stored.value);\n}\n\n/** Validate and materialize one detached value before its first persisted incarnation. */\nexport function materializeDocumentValue(\n\tdefinition: AnyDocDefinition,\n\trecord: DocumentCreate | DocumentRecord,\n\tversion: number,\n\tvalue: JsonObject,\n): JsonObject {\n\tcheckRecordScope(definition, record);\n\tcheckRecordVersion(definition, record, version);\n\tif (version === definition.version) return value;\n\treturn copyJson(definition.migrate!(value, version)) as JsonObject;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { Entry } from "./types.ts";
|
|
3
|
+
/** Define a typed entry kind whose `is()` guard narrows by `EntryRecord.kind`. */
|
|
4
|
+
export declare function defineEntry<D extends JsonValue = never>(kind: string): Entry<D>;
|
|
5
|
+
/** User input: `model` is `[UserMessage]`. Written by submissions. */
|
|
6
|
+
export declare const UserEntry: Entry<never>;
|
|
7
|
+
/** Provider result with any stop reason: `model` is `[AssistantMessage]`. Written by generation. */
|
|
8
|
+
export declare const AssistantEntry: Entry<never>;
|
|
9
|
+
/** Positional prompt and tool change: `model` is `[SystemMessage]` with empty `content`. */
|
|
10
|
+
export declare const SystemEntry: Entry<never>;
|
|
11
|
+
/** Tool result: `model` is `[ToolResultMessage]`. Written by tool tasks. */
|
|
12
|
+
export declare const ToolResultEntry: Entry<never>;
|
|
13
|
+
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../src/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAA2B,MAAM,YAAY,CAAC;AAEjE,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAM/E;AAED,sEAAsE;AACtE,eAAO,MAAM,SAAS,cAAyB,CAAC;AAChD,oGAAoG;AACpG,eAAO,MAAM,cAAc,cAA8B,CAAC;AAC1D,4FAA4F;AAC5F,eAAO,MAAM,WAAW,cAA2B,CAAC;AACpD,4EAA4E;AAC5E,eAAO,MAAM,eAAe,cAAgC,CAAC"}
|
package/dist/entries.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Define a typed entry kind whose `is()` guard narrows by `EntryRecord.kind`. */
|
|
2
|
+
export function defineEntry(kind) {
|
|
3
|
+
if (typeof kind !== "string" || kind.length === 0)
|
|
4
|
+
throw new TypeError("Entry kind must be a non-empty string");
|
|
5
|
+
return {
|
|
6
|
+
kind,
|
|
7
|
+
is: (entry) => entry !== undefined && entry.kind === kind,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** User input: `model` is `[UserMessage]`. Written by submissions. */
|
|
11
|
+
export const UserEntry = defineEntry("pi.user");
|
|
12
|
+
/** Provider result with any stop reason: `model` is `[AssistantMessage]`. Written by generation. */
|
|
13
|
+
export const AssistantEntry = defineEntry("pi.assistant");
|
|
14
|
+
/** Positional prompt and tool change: `model` is `[SystemMessage]` with empty `content`. */
|
|
15
|
+
export const SystemEntry = defineEntry("pi.system");
|
|
16
|
+
/** Tool result: `model` is `[ToolResultMessage]`. Written by tool tasks. */
|
|
17
|
+
export const ToolResultEntry = defineEntry("pi.tool-result");
|
|
18
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../src/entries.ts"],"names":[],"mappings":"AAGA,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAA8B,IAAY;IACpE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAChH,OAAO;QACN,IAAI;QACJ,EAAE,EAAE,CAAC,KAA8B,EAA0B,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;KAC1G,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AAChD,oGAAoG;AACpG,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;AAC1D,4FAA4F;AAC5F,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;AACpD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import type { JsonValue } from \"@earendil-works/chord\";\nimport type { Entry, EntryRecord, TypedEntry } from \"./types.ts\";\n\n/** Define a typed entry kind whose `is()` guard narrows by `EntryRecord.kind`. */\nexport function defineEntry<D extends JsonValue = never>(kind: string): Entry<D> {\n\tif (typeof kind !== \"string\" || kind.length === 0) throw new TypeError(\"Entry kind must be a non-empty string\");\n\treturn {\n\t\tkind,\n\t\tis: (entry: EntryRecord | undefined): entry is TypedEntry<D> => entry !== undefined && entry.kind === kind,\n\t};\n}\n\n/** User input: `model` is `[UserMessage]`. Written by submissions. */\nexport const UserEntry = defineEntry(\"pi.user\");\n/** Provider result with any stop reason: `model` is `[AssistantMessage]`. Written by generation. */\nexport const AssistantEntry = defineEntry(\"pi.assistant\");\n/** Positional prompt and tool change: `model` is `[SystemMessage]` with empty `content`. */\nexport const SystemEntry = defineEntry(\"pi.system\");\n/** Tool result: `model` is `[ToolResultMessage]`. Written by tool tasks. */\nexport const ToolResultEntry = defineEntry(\"pi.tool-result\");\n"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { TruncationResult } from "./utils/truncate.ts";
|
|
3
|
+
/** Result of a fallible operation. Expected failures are returned instead of thrown. */
|
|
4
|
+
export type Result<TValue, TError> = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: TValue;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: TError;
|
|
10
|
+
};
|
|
11
|
+
export declare function ok<TValue, TError>(value: TValue): Result<TValue, TError>;
|
|
12
|
+
export declare function err<TValue, TError>(error: TError): Result<TValue, TError>;
|
|
13
|
+
export declare function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue;
|
|
14
|
+
export declare function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined;
|
|
15
|
+
export declare function toError(error: unknown): Error;
|
|
16
|
+
export type FileKind = "file" | "directory" | "symlink";
|
|
17
|
+
export type FileErrorCode = "aborted" | "not_found" | "permission_denied" | "not_directory" | "is_directory" | "invalid" | "not_supported" | "unknown";
|
|
18
|
+
export declare class FileError extends Error {
|
|
19
|
+
code: FileErrorCode;
|
|
20
|
+
path?: string;
|
|
21
|
+
constructor(code: FileErrorCode, message: string, path?: string, cause?: Error);
|
|
22
|
+
}
|
|
23
|
+
export type ExecutionErrorCode = "aborted" | "timeout" | "shell_unavailable" | "spawn_error" | "callback_error" | "unknown";
|
|
24
|
+
export declare class ExecutionError extends Error {
|
|
25
|
+
code: ExecutionErrorCode;
|
|
26
|
+
constructor(code: ExecutionErrorCode, message: string, cause?: Error);
|
|
27
|
+
}
|
|
28
|
+
export interface FileInfo {
|
|
29
|
+
name: string;
|
|
30
|
+
path: string;
|
|
31
|
+
kind: FileKind;
|
|
32
|
+
size: number;
|
|
33
|
+
mtimeMs: number;
|
|
34
|
+
}
|
|
35
|
+
export interface TextLine {
|
|
36
|
+
text: string;
|
|
37
|
+
terminated: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface TextLineReader {
|
|
40
|
+
readLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;
|
|
41
|
+
close(context: Context): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/** Portable filesystem capability. Operations return failures rather than throwing. */
|
|
44
|
+
export interface FileSystem {
|
|
45
|
+
cwd: string;
|
|
46
|
+
absolutePath(path: string, context: Context): Promise<Result<string, FileError>>;
|
|
47
|
+
joinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;
|
|
48
|
+
readTextFile(path: string, context: Context): Promise<Result<string, FileError>>;
|
|
49
|
+
openTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;
|
|
50
|
+
readTextLines(path: string, options: {
|
|
51
|
+
maxLines?: number;
|
|
52
|
+
} | undefined, context: Context): Promise<Result<string[], FileError>>;
|
|
53
|
+
readBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;
|
|
54
|
+
writeFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;
|
|
55
|
+
appendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;
|
|
56
|
+
/** Truncate or extend a file to exactly `size` bytes. */
|
|
57
|
+
truncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;
|
|
58
|
+
/** Flush file contents and metadata needed to retrieve them from an open file handle. */
|
|
59
|
+
flushFile(path: string, context: Context): Promise<Result<void, FileError>>;
|
|
60
|
+
renameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;
|
|
61
|
+
fileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;
|
|
62
|
+
listDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;
|
|
63
|
+
canonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;
|
|
64
|
+
exists(path: string, context: Context): Promise<Result<boolean, FileError>>;
|
|
65
|
+
createDir(path: string, options: {
|
|
66
|
+
recursive?: boolean;
|
|
67
|
+
} | undefined, context: Context): Promise<Result<void, FileError>>;
|
|
68
|
+
remove(path: string, options: {
|
|
69
|
+
recursive?: boolean;
|
|
70
|
+
force?: boolean;
|
|
71
|
+
} | undefined, context: Context): Promise<Result<void, FileError>>;
|
|
72
|
+
createTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;
|
|
73
|
+
createTempFile(options: {
|
|
74
|
+
prefix?: string;
|
|
75
|
+
suffix?: string;
|
|
76
|
+
} | undefined, context: Context): Promise<Result<string, FileError>>;
|
|
77
|
+
cleanup(context: Context): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
export type ShellOutputRetention = "head" | "tail";
|
|
80
|
+
export interface ShellOutputLimits {
|
|
81
|
+
maxBytes: number;
|
|
82
|
+
maxLines: number;
|
|
83
|
+
retain?: ShellOutputRetention;
|
|
84
|
+
}
|
|
85
|
+
export interface ShellOutputCaptureOptions {
|
|
86
|
+
limits: ShellOutputLimits;
|
|
87
|
+
spill?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export type ShellOutputTruncation = Omit<TruncationResult, "content">;
|
|
90
|
+
export interface ShellOutputMetadata {
|
|
91
|
+
truncation: ShellOutputTruncation;
|
|
92
|
+
spillPath?: string;
|
|
93
|
+
lastLineBytes?: number;
|
|
94
|
+
}
|
|
95
|
+
export interface ShellOutputView extends ShellOutputMetadata {
|
|
96
|
+
text: string;
|
|
97
|
+
}
|
|
98
|
+
export type ShellOutputUpdate = {
|
|
99
|
+
kind: "replace";
|
|
100
|
+
output: ShellOutputView;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "append";
|
|
103
|
+
text: string;
|
|
104
|
+
metadata: ShellOutputMetadata;
|
|
105
|
+
} | {
|
|
106
|
+
kind: "slide";
|
|
107
|
+
drop: number;
|
|
108
|
+
text: string;
|
|
109
|
+
metadata: ShellOutputMetadata;
|
|
110
|
+
} | {
|
|
111
|
+
kind: "metadata";
|
|
112
|
+
metadata: ShellOutputMetadata;
|
|
113
|
+
};
|
|
114
|
+
export interface ShellExecResult extends ShellOutputMetadata {
|
|
115
|
+
exitCode: number;
|
|
116
|
+
}
|
|
117
|
+
export interface ShellExecOptions {
|
|
118
|
+
cwd?: string;
|
|
119
|
+
env?: Record<string, string>;
|
|
120
|
+
inheritEnv?: boolean;
|
|
121
|
+
timeout?: number;
|
|
122
|
+
capture?: ShellOutputCaptureOptions;
|
|
123
|
+
onUpdate?: (update: ShellOutputUpdate, context: Context) => void;
|
|
124
|
+
}
|
|
125
|
+
export interface Shell {
|
|
126
|
+
exec(command: string, options: ShellExecOptions | undefined, context: Context): Promise<Result<ShellExecResult, ExecutionError>>;
|
|
127
|
+
cleanup(context: Context): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
export interface ExecutionEnv extends FileSystem, Shell {
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,wFAAwF;AACxF,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,wBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExE;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAGjF;AAED,wBAAgB,cAAc,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAEhH;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQ7C;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;AAExD,MAAM,MAAM,aAAa,GACtB,SAAS,GACT,WAAW,GACX,mBAAmB,GACnB,eAAe,GACf,cA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AAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,mBAAmB,CAAA;CAAE,GAC5E;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEvD,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC3D,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,yBAAyB,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACjE;AAED,MAAM,WAAW,KAAK;IACrB,IAAI,CACH,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,YAAa,SAAQ,UAAU,EAAE,KAAK;CAAG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function ok(value) {
|
|
2
|
+
return { ok: true, value };
|
|
3
|
+
}
|
|
4
|
+
export function err(error) {
|
|
5
|
+
return { ok: false, error };
|
|
6
|
+
}
|
|
7
|
+
export function getOrThrow(result) {
|
|
8
|
+
if (!result.ok)
|
|
9
|
+
throw result.error;
|
|
10
|
+
return result.value;
|
|
11
|
+
}
|
|
12
|
+
export function getOrUndefined(result) {
|
|
13
|
+
return result.ok ? result.value : undefined;
|
|
14
|
+
}
|
|
15
|
+
export function toError(error) {
|
|
16
|
+
if (error instanceof Error)
|
|
17
|
+
return error;
|
|
18
|
+
if (typeof error === "string")
|
|
19
|
+
return new Error(error);
|
|
20
|
+
try {
|
|
21
|
+
return new Error(JSON.stringify(error));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return new Error(String(error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class FileError extends Error {
|
|
28
|
+
code;
|
|
29
|
+
path;
|
|
30
|
+
constructor(code, message, path, cause) {
|
|
31
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
32
|
+
this.name = "FileError";
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.path = path;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class ExecutionError extends Error {
|
|
38
|
+
code;
|
|
39
|
+
constructor(code, message, cause) {
|
|
40
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
41
|
+
this.name = "ExecutionError";
|
|
42
|
+
this.code = code;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,EAAE,CAAiB,KAAa;IAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,GAAG,CAAiB,KAAa;IAChD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAiB,MAA8B;IACxE,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;IACnC,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc,CAAgC,MAA8B;IAC3F,OAAO,MAAM,CAAC,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\nimport type { TruncationResult } from \"./utils/truncate.ts\";\n\n/** Result of a fallible operation. Expected failures are returned instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\nexport class FileError extends Error {\n\tpublic code: FileErrorCode;\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\nexport class ExecutionError extends Error {\n\tpublic code: ExecutionErrorCode;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface FileInfo {\n\tname: string;\n\tpath: string;\n\tkind: FileKind;\n\tsize: number;\n\tmtimeMs: number;\n}\n\nexport interface TextLine {\n\ttext: string;\n\tterminated: boolean;\n}\n\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Portable filesystem capability. Operations return failures rather than throwing. */\nexport interface FileSystem {\n\tcwd: string;\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Truncate or extend a file to exactly `size` bytes. */\n\ttruncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;\n\t/** Flush file contents and metadata needed to retrieve them from an open file handle. */\n\tflushFile(path: string, context: Context): Promise<Result<void, FileError>>;\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport type ShellOutputRetention = \"head\" | \"tail\";\n\nexport interface ShellOutputLimits {\n\tmaxBytes: number;\n\tmaxLines: number;\n\tretain?: ShellOutputRetention;\n}\n\nexport interface ShellOutputCaptureOptions {\n\tlimits: ShellOutputLimits;\n\tspill?: boolean;\n}\n\nexport type ShellOutputTruncation = Omit<TruncationResult, \"content\">;\n\nexport interface ShellOutputMetadata {\n\ttruncation: ShellOutputTruncation;\n\tspillPath?: string;\n\tlastLineBytes?: number;\n}\n\nexport interface ShellOutputView extends ShellOutputMetadata {\n\ttext: string;\n}\n\nexport type ShellOutputUpdate =\n\t| { kind: \"replace\"; output: ShellOutputView }\n\t| { kind: \"append\"; text: string; metadata: ShellOutputMetadata }\n\t| { kind: \"slide\"; drop: number; text: string; metadata: ShellOutputMetadata }\n\t| { kind: \"metadata\"; metadata: ShellOutputMetadata };\n\nexport interface ShellExecResult extends ShellOutputMetadata {\n\texitCode: number;\n}\n\nexport interface ShellExecOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tinheritEnv?: boolean;\n\ttimeout?: number;\n\tcapture?: ShellOutputCaptureOptions;\n\tonUpdate?: (update: ShellOutputUpdate, context: Context) => void;\n}\n\nexport interface Shell {\n\texec(\n\t\tcommand: string,\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport interface ExecutionEnv extends FileSystem, Shell {}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ExecutionEnv, ExecutionError, FileError, type FileInfo, type Result, type ShellExecOptions, type ShellExecResult, type TextLineReader } from "./index.ts";
|
|
3
|
+
export declare class NodeExecutionEnv implements ExecutionEnv {
|
|
4
|
+
cwd: string;
|
|
5
|
+
private shellPath?;
|
|
6
|
+
private shellEnv?;
|
|
7
|
+
private activeChildPids;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
cwd: string;
|
|
10
|
+
shellPath?: string;
|
|
11
|
+
shellEnv?: NodeJS.ProcessEnv;
|
|
12
|
+
});
|
|
13
|
+
absolutePath(path: string, _context: Context): Promise<Result<string, FileError>>;
|
|
14
|
+
joinPath(parts: string[], _context: Context): Promise<Result<string, FileError>>;
|
|
15
|
+
exec(command: string, options: ShellExecOptions | undefined, context: Context): Promise<Result<ShellExecResult, ExecutionError>>;
|
|
16
|
+
openTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;
|
|
17
|
+
readTextFile(path: string, context: Context): Promise<Result<string, FileError>>;
|
|
18
|
+
readTextLines(path: string, options: {
|
|
19
|
+
maxLines?: number;
|
|
20
|
+
} | undefined, context: Context): Promise<Result<string[], FileError>>;
|
|
21
|
+
readBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;
|
|
22
|
+
writeFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;
|
|
23
|
+
appendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;
|
|
24
|
+
truncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;
|
|
25
|
+
flushFile(path: string, context: Context): Promise<Result<void, FileError>>;
|
|
26
|
+
renameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;
|
|
27
|
+
fileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;
|
|
28
|
+
listDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;
|
|
29
|
+
canonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;
|
|
30
|
+
exists(path: string, context: Context): Promise<Result<boolean, FileError>>;
|
|
31
|
+
createDir(path: string, options: {
|
|
32
|
+
recursive?: boolean;
|
|
33
|
+
} | undefined, context: Context): Promise<Result<void, FileError>>;
|
|
34
|
+
remove(path: string, options: {
|
|
35
|
+
recursive?: boolean;
|
|
36
|
+
force?: boolean;
|
|
37
|
+
} | undefined, context: Context): Promise<Result<void, FileError>>;
|
|
38
|
+
createTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;
|
|
39
|
+
createTempFile(options: {
|
|
40
|
+
prefix?: string;
|
|
41
|
+
suffix?: string;
|
|
42
|
+
} | undefined, context: Context): Promise<Result<string, FileError>>;
|
|
43
|
+
cleanup(_context: Context): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/env/node.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACN,KAAK,YAAY,EACjB,cAAc,EAEd,SAAS,EACT,KAAK,QAAQ,EAGb,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,KAAK,cAAc,EAEnB,MAAM,YAAY,CAAC;AAkZpB,qBAAa,gBAAiB,YAAW,YAAY;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAoB;IACrC,OAAO,CAAC,eAAe,CAAqB;IAE5C,YAAY,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;KAAE,EAIrF;IAEK,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAA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