@agentshouse/app-bridge 0.1.0-cf2e2ca943fbc → 0.1.0-cf304386b60e3
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 +21 -16
- package/dist/index.d.ts +1075 -0
- package/dist/index.js +1 -0
- package/dist/mdmodel/blocks.d.ts +10 -0
- package/dist/mdmodel/definition.d.ts +81 -0
- package/dist/mdmodel/divide.d.ts +2 -0
- package/dist/mdmodel/document.d.ts +16 -0
- package/dist/mdmodel/event.d.ts +77 -0
- package/dist/mdmodel/facts.d.ts +14 -0
- package/dist/mdmodel/fields.d.ts +5 -0
- package/dist/mdmodel/index.d.ts +33 -0
- package/dist/mdmodel/kinds.d.ts +18 -0
- package/dist/mdmodel/links.d.ts +28 -0
- package/dist/mdmodel/paths.d.ts +25 -0
- package/dist/mdmodel/pattern.d.ts +9 -0
- package/dist/mdmodel/profile.d.ts +5 -0
- package/dist/mdmodel/project.d.ts +21 -0
- package/dist/mdmodel/query/language.d.ts +253 -0
- package/dist/mdmodel/query/match.d.ts +13 -0
- package/dist/mdmodel/query/rows.d.ts +31 -0
- package/dist/mdmodel/query/sql.d.ts +38 -0
- package/dist/mdmodel/references.d.ts +3 -0
- package/dist/mdmodel/reserved.d.ts +4 -0
- package/dist/mdmodel/types.d.ts +178 -0
- package/dist/mdmodel/validate.d.ts +33 -0
- package/dist/mdmodel/version.d.ts +1 -0
- package/dist/mdmodel/yaml.d.ts +55 -0
- package/dist/mdruntime/adapter.d.ts +546 -0
- package/dist/mdruntime/attached-model.d.ts +7 -0
- package/dist/mdruntime/binary.d.ts +17 -0
- package/dist/mdruntime/bootstrap.d.ts +43 -0
- package/dist/mdruntime/chain.d.ts +11 -0
- package/dist/mdruntime/change-set.d.ts +27 -0
- package/dist/mdruntime/change.d.ts +119 -0
- package/dist/mdruntime/client.d.ts +100 -0
- package/dist/mdruntime/collection.d.ts +28 -0
- package/dist/mdruntime/compile.d.ts +15 -0
- package/dist/mdruntime/connection.d.ts +129 -0
- package/dist/mdruntime/conversation-row.d.ts +32 -0
- package/dist/mdruntime/conversation.d.ts +127 -0
- package/dist/mdruntime/durability.d.ts +17 -0
- package/dist/mdruntime/failure.d.ts +12 -0
- package/dist/mdruntime/figures.d.ts +47 -0
- package/dist/mdruntime/identity.d.ts +5 -0
- package/dist/mdruntime/job.d.ts +32 -0
- package/dist/mdruntime/live.d.ts +22 -0
- package/dist/mdruntime/log.d.ts +5 -0
- package/dist/mdruntime/media.d.ts +7 -0
- package/dist/mdruntime/messages.d.ts +51 -0
- package/dist/mdruntime/model.d.ts +55 -0
- package/dist/mdruntime/observation.d.ts +44 -0
- package/dist/mdruntime/open.d.ts +1 -0
- package/dist/mdruntime/opened.d.ts +21 -0
- package/dist/mdruntime/outcome.d.ts +85 -0
- package/dist/mdruntime/overlay.d.ts +25 -0
- package/dist/mdruntime/query.d.ts +88 -0
- package/dist/mdruntime/reach.d.ts +53 -0
- package/dist/mdruntime/readiness.d.ts +49 -0
- package/dist/mdruntime/reads.d.ts +35 -0
- package/dist/mdruntime/recovery.d.ts +25 -0
- package/dist/mdruntime/refresh.d.ts +26 -0
- package/dist/mdruntime/replica.d.ts +67 -0
- package/dist/mdruntime/room-draft.d.ts +174 -0
- package/dist/mdruntime/room-drafts.d.ts +28 -0
- package/dist/mdruntime/save.d.ts +102 -0
- package/dist/mdruntime/saves.d.ts +95 -0
- package/dist/mdruntime/search.d.ts +21 -0
- package/dist/mdruntime/seed.d.ts +29 -0
- package/dist/mdruntime/socket/admission.d.ts +6 -0
- package/dist/mdruntime/socket/answers.d.ts +5 -0
- package/dist/mdruntime/socket.d.ts +42 -0
- package/dist/mdruntime/source.d.ts +60 -0
- package/dist/mdruntime/status.d.ts +25 -0
- package/dist/mdruntime/store/fences.d.ts +15 -0
- package/dist/mdruntime/store/installs.d.ts +29 -0
- package/dist/mdruntime/store/records.d.ts +211 -0
- package/dist/mdruntime/store/room-held.d.ts +7 -0
- package/dist/mdruntime/store/watchers.d.ts +14 -0
- package/dist/mdruntime/store/writes.d.ts +23 -0
- package/dist/mdruntime/store.d.ts +86 -0
- package/dist/mdruntime/stored.d.ts +155 -0
- package/dist/mdruntime/tables.d.ts +406 -0
- package/dist/mdruntime/tallies.d.ts +17 -0
- package/dist/mdruntime/transfer.d.ts +4 -0
- package/dist/mdruntime/turn.d.ts +8 -0
- package/dist/mdruntime/wire.d.ts +249 -0
- package/dist/{client/src/test-host.d.ts → test-host.d.ts} +10 -8
- package/dist/test-host.js +190 -0
- package/docs/families.md +101 -45
- package/package.json +12 -10
- package/dist/client/src/bridge.d.ts +0 -38
- package/dist/client/src/bridge.js +0 -320
- package/dist/client/src/index.d.ts +0 -3
- package/dist/client/src/index.js +0 -2
- package/dist/client/src/test-host.js +0 -185
- package/dist/client/src/wire.d.ts +0 -215
- package/dist/client/src/wire.js +0 -1
- package/dist/src/apps/remainder.d.ts +0 -2
- package/dist/src/apps/remainder.js +0 -16
- package/dist/src/apps/tab.d.ts +0 -6
- package/dist/src/apps/tab.js +0 -27
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChangeSet } from './change-set.js';
|
|
2
|
+
import { type KeyedResult, type QueryMessage } from './observation.js';
|
|
3
|
+
import type { PendingResult, Plan, QueryCoverage } from './query.js';
|
|
4
|
+
import type { Fail } from './reach.js';
|
|
5
|
+
import type { QueryRoom } from './tables.js';
|
|
6
|
+
export type Cover = {
|
|
7
|
+
coverage: QueryCoverage;
|
|
8
|
+
rooms: readonly QueryRoom[];
|
|
9
|
+
} | PendingResult;
|
|
10
|
+
export type Ran = KeyedResult & {
|
|
11
|
+
readonly current: () => boolean;
|
|
12
|
+
};
|
|
13
|
+
export type Run = (plan: Plan, cover: () => Promise<Cover>) => Promise<Ran>;
|
|
14
|
+
type Listener = (message: QueryMessage) => void;
|
|
15
|
+
export type LiveQueries<H> = {
|
|
16
|
+
touched(set: ChangeSet): void;
|
|
17
|
+
recover(): void;
|
|
18
|
+
watch(plan: Plan, identity: string, cover: (held: H) => Cover, deliver: Listener, failed: Fail): () => void;
|
|
19
|
+
close(): void;
|
|
20
|
+
};
|
|
21
|
+
export declare function createLiveQueries<H>(run: Run, holding: () => Promise<H>): LiveQueries<H>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import { type ShownAnswer } from './outcome.js';
|
|
3
|
+
export declare const ROOM_MEDIA = "room-media";
|
|
4
|
+
type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
|
|
5
|
+
export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
|
|
6
|
+
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient, registry?: CustomElementRegistry): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AcceptedMessage } from './adapter.js';
|
|
2
|
+
import type { JobMarker } from './job.js';
|
|
3
|
+
import type { Connection } from './tables.js';
|
|
4
|
+
export declare const MESSAGE_TABLES: readonly string[];
|
|
5
|
+
export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n substr(asking.text, 1, 512) AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
6
|
+
export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
|
|
7
|
+
export type HeldConversation = {
|
|
8
|
+
readonly conversation: string;
|
|
9
|
+
readonly read: string | null | undefined;
|
|
10
|
+
readonly partial: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type MessageWindow = {
|
|
13
|
+
readonly messages: AcceptedMessage[];
|
|
14
|
+
readonly more: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type HeldSource = {
|
|
17
|
+
readonly source: unknown;
|
|
18
|
+
readonly sender: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type HeldRow = {
|
|
21
|
+
readonly conversation: string;
|
|
22
|
+
readonly said: {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly role: string | null;
|
|
25
|
+
readonly at: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly failure: string | null;
|
|
28
|
+
readonly opened: HeldSource | null;
|
|
29
|
+
readonly asking: (HeldSource & {
|
|
30
|
+
readonly identity: string;
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly at: string | null;
|
|
33
|
+
}) | null;
|
|
34
|
+
};
|
|
35
|
+
export type ConversationWrite = {
|
|
36
|
+
readonly conversation: string;
|
|
37
|
+
readonly messages: readonly AcceptedMessage[];
|
|
38
|
+
readonly read?: {
|
|
39
|
+
readonly at: string | null;
|
|
40
|
+
readonly partial: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
44
|
+
export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
|
|
45
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
46
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
47
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
48
|
+
export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
|
|
49
|
+
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
50
|
+
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
51
|
+
export declare function forgottenMessages(connection: Connection): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Definition, VerifiedModel } from '../mdmodel/index.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
3
|
+
export type ModelIdentity = {
|
|
4
|
+
identity: string;
|
|
5
|
+
version: string;
|
|
6
|
+
};
|
|
7
|
+
export type ModelSnapshot = ModelIdentity & {
|
|
8
|
+
schema: string | null;
|
|
9
|
+
revision: string | null;
|
|
10
|
+
};
|
|
11
|
+
export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired'>;
|
|
12
|
+
export type ModelResult = {
|
|
13
|
+
kind: 'model';
|
|
14
|
+
snapshot: ModelSnapshot;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'model-unavailable';
|
|
17
|
+
reason: ModelUnavailableReason;
|
|
18
|
+
};
|
|
19
|
+
export type MdType = Definition;
|
|
20
|
+
export type ModelState = {
|
|
21
|
+
status: 'unavailable';
|
|
22
|
+
reason: ModelUnavailableReason;
|
|
23
|
+
} | {
|
|
24
|
+
status: 'current' | 'cached';
|
|
25
|
+
snapshot: ModelSnapshot;
|
|
26
|
+
verifiedWith: ModelIdentity;
|
|
27
|
+
types: VerifiedModel['types'];
|
|
28
|
+
};
|
|
29
|
+
export type StoredModel = Extract<ModelState, {
|
|
30
|
+
status: 'unavailable';
|
|
31
|
+
}> | Omit<Extract<ModelState, {
|
|
32
|
+
status: 'current' | 'cached';
|
|
33
|
+
}>, 'types'>;
|
|
34
|
+
export type TypesResult = {
|
|
35
|
+
status: Open<'unavailable'>;
|
|
36
|
+
reason: ModelUnavailableReason;
|
|
37
|
+
types: null;
|
|
38
|
+
} | {
|
|
39
|
+
status: Open<'current' | 'cached'>;
|
|
40
|
+
identity: string;
|
|
41
|
+
version: string;
|
|
42
|
+
verifiedWith: ModelIdentity;
|
|
43
|
+
types: readonly MdType[];
|
|
44
|
+
schema: string | null;
|
|
45
|
+
revision: string | null;
|
|
46
|
+
};
|
|
47
|
+
export type ValidationReceipt = {
|
|
48
|
+
identity: string;
|
|
49
|
+
version: string;
|
|
50
|
+
source: Open<'current' | 'cached'>;
|
|
51
|
+
};
|
|
52
|
+
export declare const NO_MODEL: ModelState;
|
|
53
|
+
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
54
|
+
export declare function modelTypes(state: ModelState): TypesResult;
|
|
55
|
+
export declare function storedModel(state: ModelState): StoredModel;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
2
|
+
export type Observation<T> = {
|
|
3
|
+
current(): T;
|
|
4
|
+
subscribe(listener: (value: T) => void): () => void;
|
|
5
|
+
close(): void;
|
|
6
|
+
};
|
|
7
|
+
export type RowKey = string | number;
|
|
8
|
+
export type KeyedResult = {
|
|
9
|
+
result: QueryResult;
|
|
10
|
+
keys: readonly RowKey[];
|
|
11
|
+
};
|
|
12
|
+
export type QueryChange = {
|
|
13
|
+
changed: readonly (readonly [RowKey, QueryDocument | QueryGroup])[];
|
|
14
|
+
removed: readonly RowKey[];
|
|
15
|
+
order: readonly RowKey[] | null;
|
|
16
|
+
coverage?: QueryCoverage;
|
|
17
|
+
next?: string | null;
|
|
18
|
+
total?: number;
|
|
19
|
+
};
|
|
20
|
+
export type QueryMessage = KeyedResult | QueryChange;
|
|
21
|
+
export type Observed = {
|
|
22
|
+
observation: Observation<unknown>;
|
|
23
|
+
receive(message: unknown): void;
|
|
24
|
+
end(): void;
|
|
25
|
+
};
|
|
26
|
+
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
27
|
+
export declare function whole(message: QueryMessage): message is KeyedResult;
|
|
28
|
+
export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
|
|
29
|
+
export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
|
|
30
|
+
export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
31
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
32
|
+
export type Digest = {
|
|
33
|
+
readonly pending: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly keys: readonly RowKey[];
|
|
36
|
+
readonly rows: ReadonlyMap<RowKey, number>;
|
|
37
|
+
readonly coverage: string;
|
|
38
|
+
readonly next: string | undefined;
|
|
39
|
+
readonly total: number | undefined;
|
|
40
|
+
};
|
|
41
|
+
export declare function hashed(text: string): number;
|
|
42
|
+
export declare function digestOf({ result, keys }: KeyedResult): Digest;
|
|
43
|
+
export declare function digestApplied(digest: Digest, message: QueryMessage): Digest;
|
|
44
|
+
export declare function changeOf(previous: Digest, next: KeyedResult): QueryMessage | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Open<Value extends string> = Value | (string & {});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BinaryResult } from './adapter.js';
|
|
2
|
+
import { type RuntimeDatabase } from './tables.js';
|
|
3
|
+
export type OpenedName = {
|
|
4
|
+
readonly locator: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly revision: string;
|
|
7
|
+
};
|
|
8
|
+
export type KeptBinary = {
|
|
9
|
+
readonly kind: 'binary';
|
|
10
|
+
readonly file: string;
|
|
11
|
+
readonly byteLength: number;
|
|
12
|
+
readonly mediaType: string;
|
|
13
|
+
};
|
|
14
|
+
export type KeptResult = KeptBinary | Exclude<BinaryResult, {
|
|
15
|
+
kind: 'binary';
|
|
16
|
+
}>;
|
|
17
|
+
export type OpenedFiles = {
|
|
18
|
+
find(name: OpenedName): Promise<KeptBinary | null>;
|
|
19
|
+
fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
|
|
20
|
+
};
|
|
21
|
+
export declare function openedFiles(database: RuntimeDatabase, fenced: (locator: string) => boolean): OpenedFiles;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
|
|
2
|
+
import type { ChangeBatch } from './change.js';
|
|
3
|
+
import type { KeptBinary, KeptResult } from './opened.js';
|
|
4
|
+
type Refused<Kind extends string> = ProviderRefusal & {
|
|
5
|
+
kind: Kind;
|
|
6
|
+
};
|
|
7
|
+
export type Failure = Refused<'transport-uncertainty'> | Refused<'revoked-authorization'> | (Refused<'room-not-readable'> & {
|
|
8
|
+
locator: string;
|
|
9
|
+
}) | (Refused<'room-locked'> & {
|
|
10
|
+
locator: string;
|
|
11
|
+
}) | ScopedRefusal;
|
|
12
|
+
export type CallResult = {
|
|
13
|
+
kind: 'action';
|
|
14
|
+
result: unknown;
|
|
15
|
+
at?: RoomVersionAt;
|
|
16
|
+
} | Refused<'rejected'> | Refused<'undeclared'> | Failure;
|
|
17
|
+
export type HistoryAnswer = Exclude<HistoryResult, {
|
|
18
|
+
kind: Failure['kind'];
|
|
19
|
+
}> | Failure;
|
|
20
|
+
type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
|
|
21
|
+
export type BinaryAnswer = {
|
|
22
|
+
kind: 'binary';
|
|
23
|
+
stream: ReadableStream<Uint8Array>;
|
|
24
|
+
byteLength: number;
|
|
25
|
+
mediaType: string;
|
|
26
|
+
} | BinaryRefusal;
|
|
27
|
+
export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
|
|
28
|
+
export type BinaryLinkAnswer = {
|
|
29
|
+
kind: 'link';
|
|
30
|
+
url: string;
|
|
31
|
+
name: string;
|
|
32
|
+
mediaType: string;
|
|
33
|
+
} | Refused<'rejected'> | Refused<'absent'> | Failure;
|
|
34
|
+
export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
|
|
35
|
+
export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
|
|
36
|
+
export type AttachAnswer = {
|
|
37
|
+
kind: 'attached';
|
|
38
|
+
path: string;
|
|
39
|
+
} | Offline | Refused<'rejected'> | Failure;
|
|
40
|
+
export type DownloadAnswer = {
|
|
41
|
+
kind: 'started';
|
|
42
|
+
} | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
|
|
43
|
+
export type Resolution = {
|
|
44
|
+
readonly kind: 'document';
|
|
45
|
+
readonly room: string;
|
|
46
|
+
readonly path: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'deleted';
|
|
49
|
+
readonly room: string;
|
|
50
|
+
readonly path: string;
|
|
51
|
+
readonly revision: HistoryRevision;
|
|
52
|
+
} | Refused<'unreadable'> | Refused<'absent'> | Failure;
|
|
53
|
+
export declare const UNREADABLE: Refused<'unreadable'>;
|
|
54
|
+
export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
|
|
55
|
+
export declare const ABSENT_TARGET: Refused<'absent'>;
|
|
56
|
+
export declare function absentBinary(path: string): Refused<'absent'>;
|
|
57
|
+
export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
|
|
58
|
+
export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
|
|
59
|
+
export declare function attachAnswer(result: AttachResult): AttachAnswer;
|
|
60
|
+
export declare const ROOM_LOCKED = "room-locked";
|
|
61
|
+
export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
|
|
62
|
+
locator: string;
|
|
63
|
+
};
|
|
64
|
+
export type Offline = {
|
|
65
|
+
readonly kind: 'offline';
|
|
66
|
+
};
|
|
67
|
+
export declare const OFFLINE: Offline;
|
|
68
|
+
export declare function answeredResult(value: unknown): boolean;
|
|
69
|
+
export declare const UNCERTAIN: Failure;
|
|
70
|
+
export declare function undeclared(name: string): CallResult;
|
|
71
|
+
export declare function failure(result: AdapterFailure): Failure;
|
|
72
|
+
export declare function calledResult(result: ActionResult): CallResult;
|
|
73
|
+
export declare function historyAnswer(result: HistoryResult): HistoryAnswer;
|
|
74
|
+
export type Submission = {
|
|
75
|
+
readonly state: 'waiting' | 'submitted';
|
|
76
|
+
} | {
|
|
77
|
+
readonly state: 'reset';
|
|
78
|
+
readonly reset: string;
|
|
79
|
+
};
|
|
80
|
+
export type QueueEntry = {
|
|
81
|
+
readonly batch: ChangeBatch;
|
|
82
|
+
} & (Submission | {
|
|
83
|
+
readonly state: 'local';
|
|
84
|
+
});
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BinaryFile, HeadChange } from './adapter.js';
|
|
2
|
+
import type { ChangeBatch } from './change.js';
|
|
3
|
+
export type Heads = {
|
|
4
|
+
revisions: Readonly<Record<string, string>>;
|
|
5
|
+
fileIds: Readonly<Record<string, string>>;
|
|
6
|
+
created: Readonly<Record<string, string>>;
|
|
7
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
8
|
+
};
|
|
9
|
+
export type HeldBinary = ({
|
|
10
|
+
readonly state: 'accepted';
|
|
11
|
+
} & BinaryFile) | {
|
|
12
|
+
readonly state: 'pending';
|
|
13
|
+
readonly localId: string;
|
|
14
|
+
readonly byteLength: number;
|
|
15
|
+
readonly mediaType: string;
|
|
16
|
+
readonly sha256: string;
|
|
17
|
+
};
|
|
18
|
+
export type Layer = Heads & {
|
|
19
|
+
documents: Readonly<Record<string, string>>;
|
|
20
|
+
binaries: Readonly<Record<string, HeldBinary>>;
|
|
21
|
+
};
|
|
22
|
+
export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
|
|
23
|
+
export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
|
|
24
|
+
export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
|
|
25
|
+
export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Generator<number, Layer, void>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type HeldRooms, type QueryPlan } from '../mdmodel/index.js';
|
|
2
|
+
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
4
|
+
import type { Open } from './open.js';
|
|
5
|
+
export type Backlink = {
|
|
6
|
+
path: string;
|
|
7
|
+
type: string;
|
|
8
|
+
field: string;
|
|
9
|
+
};
|
|
10
|
+
export type QueryDocument = {
|
|
11
|
+
room: string;
|
|
12
|
+
path: string;
|
|
13
|
+
type?: string;
|
|
14
|
+
fields?: Readonly<Record<string, unknown>>;
|
|
15
|
+
sections?: Readonly<Record<string, string>>;
|
|
16
|
+
preamble?: string;
|
|
17
|
+
markdown?: string;
|
|
18
|
+
backlinks?: readonly Backlink[];
|
|
19
|
+
change?: HeadChange | null;
|
|
20
|
+
fileId?: string | null;
|
|
21
|
+
revision?: string | null;
|
|
22
|
+
binaryFile?: BinaryFileRecord;
|
|
23
|
+
size?: number | null;
|
|
24
|
+
created?: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type GroupTotal = {
|
|
27
|
+
count: number;
|
|
28
|
+
size: number;
|
|
29
|
+
};
|
|
30
|
+
export type QueryGroup = {
|
|
31
|
+
key: readonly unknown[];
|
|
32
|
+
count: number;
|
|
33
|
+
documents?: GroupTotal;
|
|
34
|
+
files?: GroupTotal;
|
|
35
|
+
updated?: string | null;
|
|
36
|
+
greatest?: unknown;
|
|
37
|
+
};
|
|
38
|
+
export type CoveredRoom = {
|
|
39
|
+
room: string;
|
|
40
|
+
generation: string;
|
|
41
|
+
current: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type QueryCoverage = {
|
|
44
|
+
rooms: readonly CoveredRoom[];
|
|
45
|
+
indexes: readonly string[];
|
|
46
|
+
overlay: readonly string[];
|
|
47
|
+
};
|
|
48
|
+
export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
|
|
49
|
+
export type PendingRoom = {
|
|
50
|
+
room: string;
|
|
51
|
+
awaits: Awaits;
|
|
52
|
+
};
|
|
53
|
+
export type PendingResult = {
|
|
54
|
+
pending: readonly PendingRoom[];
|
|
55
|
+
};
|
|
56
|
+
export type DocumentRows = {
|
|
57
|
+
documents: readonly QueryDocument[];
|
|
58
|
+
next?: string;
|
|
59
|
+
total?: number;
|
|
60
|
+
};
|
|
61
|
+
export type GroupRows = {
|
|
62
|
+
groups: readonly QueryGroup[];
|
|
63
|
+
next?: string;
|
|
64
|
+
total?: number;
|
|
65
|
+
};
|
|
66
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
67
|
+
export type DocumentResult = DocumentRows & {
|
|
68
|
+
coverage: QueryCoverage;
|
|
69
|
+
};
|
|
70
|
+
export type GroupResult = GroupRows & {
|
|
71
|
+
coverage: QueryCoverage;
|
|
72
|
+
};
|
|
73
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
74
|
+
export type PlanArea = {
|
|
75
|
+
room: string;
|
|
76
|
+
path: string;
|
|
77
|
+
open: readonly string[];
|
|
78
|
+
};
|
|
79
|
+
export type PlanReach = {
|
|
80
|
+
rooms: readonly string[];
|
|
81
|
+
documents: readonly string[];
|
|
82
|
+
areas: readonly PlanArea[];
|
|
83
|
+
};
|
|
84
|
+
export type Plan = QueryPlan & {
|
|
85
|
+
reach: PlanReach | null;
|
|
86
|
+
locked: readonly string[];
|
|
87
|
+
};
|
|
88
|
+
export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AppRoom, MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
|
|
2
|
+
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
|
+
import type { Readiness } from './readiness.js';
|
|
4
|
+
import type { SearchResult } from './search.js';
|
|
5
|
+
export type ReachedDocument = {
|
|
6
|
+
readonly room: string;
|
|
7
|
+
readonly path: string;
|
|
8
|
+
};
|
|
9
|
+
export type ReachedArea = {
|
|
10
|
+
readonly room: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly open: readonly string[];
|
|
13
|
+
};
|
|
14
|
+
export type PortReach = {
|
|
15
|
+
readonly rooms: readonly string[];
|
|
16
|
+
readonly documents: readonly ReachedDocument[];
|
|
17
|
+
readonly areas?: readonly ReachedArea[];
|
|
18
|
+
readonly conversations: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type Deliver = (message: unknown) => void;
|
|
21
|
+
export type Fail = (error: unknown) => void;
|
|
22
|
+
export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
|
|
23
|
+
export type RuntimeView = {
|
|
24
|
+
md: MdRuntime;
|
|
25
|
+
watch: Watch;
|
|
26
|
+
};
|
|
27
|
+
export type NarrowedView = RuntimeView & {
|
|
28
|
+
narrow(reach: PortReach | null): void;
|
|
29
|
+
};
|
|
30
|
+
export type Reachable = RuntimeView & {
|
|
31
|
+
plan(input: unknown, reach: PortReach | null): Promise<Plan>;
|
|
32
|
+
query(plan: Plan): Promise<QueryResult>;
|
|
33
|
+
watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
|
|
34
|
+
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
35
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
|
|
36
|
+
locked(room: string): Promise<boolean>;
|
|
37
|
+
lockedRooms(): Promise<readonly string[]>;
|
|
38
|
+
watchLocks(notify: () => void): () => void;
|
|
39
|
+
located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
|
|
40
|
+
room(locator: string): Promise<AppRoom | undefined>;
|
|
41
|
+
};
|
|
42
|
+
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
43
|
+
export declare function governs(reach: PortReach | null, room: {
|
|
44
|
+
readonly locator: string;
|
|
45
|
+
readonly typedSelection: {
|
|
46
|
+
roots: readonly string[];
|
|
47
|
+
} | null;
|
|
48
|
+
}): {
|
|
49
|
+
readonly collection: boolean;
|
|
50
|
+
readonly selection: boolean;
|
|
51
|
+
};
|
|
52
|
+
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
53
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Open } from './open.js';
|
|
2
|
+
export type CodeAvailability = Open<'stored' | 'absent'>;
|
|
3
|
+
export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
|
|
4
|
+
export type RoomCoverage = {
|
|
5
|
+
readonly room: string;
|
|
6
|
+
readonly state: RoomPreparation;
|
|
7
|
+
};
|
|
8
|
+
export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
|
|
9
|
+
export type TargetCoverage = {
|
|
10
|
+
readonly complete: boolean;
|
|
11
|
+
readonly listed: boolean;
|
|
12
|
+
readonly rooms: readonly RoomCoverage[];
|
|
13
|
+
readonly conversations: ConversationCoverage;
|
|
14
|
+
};
|
|
15
|
+
export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
|
|
16
|
+
export type Durability = Open<'persistent' | 'best-effort'>;
|
|
17
|
+
export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
|
|
18
|
+
export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
|
|
19
|
+
export type Space = Open<'full'>;
|
|
20
|
+
export type InstallationStep = Open<'downloading' | 'writing' | 'replaying'>;
|
|
21
|
+
export type InstallationAmount = {
|
|
22
|
+
readonly done: number;
|
|
23
|
+
readonly total: number;
|
|
24
|
+
};
|
|
25
|
+
export type Installation = {
|
|
26
|
+
readonly step: InstallationStep | null;
|
|
27
|
+
readonly rooms: InstallationAmount;
|
|
28
|
+
readonly bytes: InstallationAmount;
|
|
29
|
+
};
|
|
30
|
+
export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
|
|
31
|
+
export type Readiness = {
|
|
32
|
+
readonly status: ReadinessStatus;
|
|
33
|
+
readonly ready: boolean;
|
|
34
|
+
readonly usable: boolean;
|
|
35
|
+
readonly code: CodeAvailability;
|
|
36
|
+
readonly coverage: TargetCoverage;
|
|
37
|
+
readonly durability: Durability;
|
|
38
|
+
readonly persistence: Persistence;
|
|
39
|
+
readonly connection: ConnectionAvailability;
|
|
40
|
+
readonly house: HouseOutcome;
|
|
41
|
+
readonly space: Space | null;
|
|
42
|
+
readonly installation: Installation;
|
|
43
|
+
readonly lost: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
|
|
46
|
+
readonly coverage: Omit<TargetCoverage, 'complete'>;
|
|
47
|
+
readonly established: boolean;
|
|
48
|
+
};
|
|
49
|
+
export declare function readinessOf(facts: ReadinessFacts): Readiness;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type CallResult } from './outcome.js';
|
|
2
|
+
import type { Recovery } from './recovery.js';
|
|
3
|
+
import type { Connection, RuntimeDatabase } from './tables.js';
|
|
4
|
+
export declare const READ_TABLES: readonly string[];
|
|
5
|
+
export type ReadAt = {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly input: string;
|
|
8
|
+
readonly build: string;
|
|
9
|
+
};
|
|
10
|
+
export type ObservedRead = {
|
|
11
|
+
readonly answer: unknown;
|
|
12
|
+
readonly failure: CallResult | null;
|
|
13
|
+
readonly kept: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ReadAnswers = {
|
|
16
|
+
watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
|
|
17
|
+
again(): void;
|
|
18
|
+
reopened(): void;
|
|
19
|
+
};
|
|
20
|
+
export type ReadAnswersOptions = {
|
|
21
|
+
readonly database: RuntimeDatabase;
|
|
22
|
+
readonly build: string;
|
|
23
|
+
readonly unkept: readonly string[];
|
|
24
|
+
readonly leading: readonly string[];
|
|
25
|
+
readonly recovery: Recovery;
|
|
26
|
+
call(name: string, input: unknown): Promise<CallResult>;
|
|
27
|
+
online(): boolean;
|
|
28
|
+
closed(): boolean;
|
|
29
|
+
full(): boolean;
|
|
30
|
+
filled(): void;
|
|
31
|
+
};
|
|
32
|
+
export declare function storedRead(connection: Connection, { name, input, build }: ReadAt): string | null;
|
|
33
|
+
export declare function keptRead(connection: Connection, { name, input, build }: ReadAt, answer: string): null;
|
|
34
|
+
export declare function readsOfOtherBuildsForgotten(connection: Connection, build: string): null;
|
|
35
|
+
export declare function readAnswers(options: ReadAnswersOptions): ReadAnswers;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Attempted = 'done' | 'again' | {
|
|
2
|
+
readonly at: number;
|
|
3
|
+
};
|
|
4
|
+
export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
|
|
5
|
+
export type AttemptOptions = {
|
|
6
|
+
readonly at?: number;
|
|
7
|
+
readonly again?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type RecoveryOptions = {
|
|
10
|
+
readonly firstMs?: number;
|
|
11
|
+
readonly maxMs?: number;
|
|
12
|
+
readonly attempts?: number;
|
|
13
|
+
readonly inFlight?: number;
|
|
14
|
+
};
|
|
15
|
+
export type Recovery = {
|
|
16
|
+
attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
|
|
17
|
+
pending(intent: string): boolean;
|
|
18
|
+
resume(): void;
|
|
19
|
+
cancel(intent: string): void;
|
|
20
|
+
scope(inFlight?: number): Recovery;
|
|
21
|
+
retire(): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
|
|
24
|
+
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
|
|
25
|
+
export declare function createRecovery(options?: RecoveryOptions): Recovery;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AdapterFailure, Authorization, RefreshPage, RefreshRequest, RefreshResult, RetryableRefusal } from './adapter.js';
|
|
2
|
+
import type { Remodel } from './bootstrap.js';
|
|
3
|
+
import type { ReplicaRecord } from './replica.js';
|
|
4
|
+
import type { RefreshedPage } from './store.js';
|
|
5
|
+
import type { HeldEntry, StoredEntry } from './tables.js';
|
|
6
|
+
import { type Unconfirmed } from './transfer.js';
|
|
7
|
+
export type Advancement = {
|
|
8
|
+
kind: 'still-current';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'advanced';
|
|
11
|
+
record: ReplicaRecord;
|
|
12
|
+
changed: ReadonlySet<string>;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'beyond-horizon';
|
|
15
|
+
} | RetryableRefusal | Unconfirmed | AdapterFailure;
|
|
16
|
+
export type Refresher = (authorization: Authorization, request: RefreshRequest) => Promise<RefreshResult>;
|
|
17
|
+
export type Refreshing = {
|
|
18
|
+
turn(): void;
|
|
19
|
+
prior(paths: readonly string[]): Promise<ReadonlyMap<string, HeldEntry>>;
|
|
20
|
+
later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
|
|
21
|
+
stage(page: RefreshedPage): Promise<boolean>;
|
|
22
|
+
};
|
|
23
|
+
type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'binaryFiles'>;
|
|
24
|
+
export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
|
|
25
|
+
export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
|
|
26
|
+
export {};
|