@agentshouse/app-bridge 0.1.0-ccf413b4e709d → 0.1.0-ccf6bf7d473e2

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.
Files changed (110) hide show
  1. package/README.md +11 -9
  2. package/dist/index.d.ts +588 -7
  3. package/dist/mdmodel/body.d.ts +84 -0
  4. package/dist/mdmodel/built-in.d.ts +3 -0
  5. package/dist/mdmodel/crockford.d.ts +3 -0
  6. package/dist/mdmodel/definition.d.ts +90 -0
  7. package/dist/mdmodel/divide.d.ts +2 -0
  8. package/dist/mdmodel/document.d.ts +22 -0
  9. package/dist/mdmodel/event.d.ts +76 -0
  10. package/dist/mdmodel/facts.d.ts +14 -0
  11. package/dist/mdmodel/fields.d.ts +5 -0
  12. package/dist/mdmodel/house-model.d.ts +826 -0
  13. package/dist/mdmodel/house-references.d.ts +3 -0
  14. package/dist/mdmodel/index.d.ts +42 -0
  15. package/dist/mdmodel/kinds.d.ts +17 -0
  16. package/dist/mdmodel/markdown.d.ts +74 -0
  17. package/dist/mdmodel/media-type.d.ts +71 -0
  18. package/dist/mdmodel/paths.d.ts +34 -0
  19. package/dist/mdmodel/pattern.d.ts +9 -0
  20. package/dist/mdmodel/project.d.ts +21 -0
  21. package/dist/mdmodel/query/language.d.ts +253 -0
  22. package/dist/mdmodel/query/match.d.ts +13 -0
  23. package/dist/mdmodel/query/rows.d.ts +31 -0
  24. package/dist/mdmodel/query/sql.d.ts +38 -0
  25. package/dist/mdmodel/references.d.ts +3 -0
  26. package/dist/mdmodel/reserved.d.ts +5 -0
  27. package/dist/mdmodel/room-types.d.ts +6 -0
  28. package/dist/mdmodel/types.d.ts +181 -0
  29. package/dist/mdmodel/validate.d.ts +35 -0
  30. package/dist/mdmodel/version.d.ts +1 -0
  31. package/dist/mdmodel/yaml.d.ts +55 -0
  32. package/dist/mdruntime/actions.d.ts +25 -0
  33. package/dist/mdruntime/adapter.d.ts +540 -0
  34. package/dist/mdruntime/attached-model.d.ts +6 -0
  35. package/dist/mdruntime/binary.d.ts +17 -0
  36. package/dist/mdruntime/bootstrap.d.ts +43 -0
  37. package/dist/mdruntime/cell.d.ts +5 -0
  38. package/dist/mdruntime/chain.d.ts +11 -0
  39. package/dist/mdruntime/change-set.d.ts +31 -0
  40. package/dist/mdruntime/change.d.ts +119 -0
  41. package/dist/mdruntime/client.d.ts +97 -0
  42. package/dist/mdruntime/collection.d.ts +46 -0
  43. package/dist/mdruntime/compile.d.ts +17 -0
  44. package/dist/mdruntime/conversation-live.d.ts +146 -0
  45. package/dist/mdruntime/conversation-row.d.ts +32 -0
  46. package/dist/mdruntime/conversation.d.ts +135 -0
  47. package/dist/mdruntime/declaration.d.ts +9 -0
  48. package/dist/mdruntime/durability.d.ts +30 -0
  49. package/dist/mdruntime/failure.d.ts +15 -0
  50. package/dist/mdruntime/figures.d.ts +48 -0
  51. package/dist/mdruntime/holdings.d.ts +28 -0
  52. package/dist/mdruntime/identity.d.ts +5 -0
  53. package/dist/mdruntime/listing.d.ts +47 -0
  54. package/dist/mdruntime/live.d.ts +22 -0
  55. package/dist/mdruntime/media.d.ts +7 -0
  56. package/dist/mdruntime/messages.d.ts +55 -0
  57. package/dist/mdruntime/model.d.ts +54 -0
  58. package/dist/mdruntime/observation.d.ts +45 -0
  59. package/dist/mdruntime/open.d.ts +1 -0
  60. package/dist/mdruntime/opened.d.ts +21 -0
  61. package/dist/mdruntime/outcome.d.ts +94 -0
  62. package/dist/mdruntime/overlay.d.ts +29 -0
  63. package/dist/mdruntime/preparation.d.ts +19 -0
  64. package/dist/mdruntime/presence.d.ts +51 -0
  65. package/dist/mdruntime/query.d.ts +87 -0
  66. package/dist/mdruntime/reach.d.ts +55 -0
  67. package/dist/mdruntime/readiness.d.ts +48 -0
  68. package/dist/mdruntime/reads.d.ts +38 -0
  69. package/dist/mdruntime/recovery.d.ts +27 -0
  70. package/dist/mdruntime/refresh.d.ts +26 -0
  71. package/dist/mdruntime/replica.d.ts +62 -0
  72. package/dist/mdruntime/retried.d.ts +29 -0
  73. package/dist/mdruntime/room-draft.d.ts +172 -0
  74. package/dist/mdruntime/room-drafts.d.ts +23 -0
  75. package/dist/mdruntime/runtime.d.ts +33 -0
  76. package/dist/mdruntime/save.d.ts +58 -0
  77. package/dist/mdruntime/saves.d.ts +31 -0
  78. package/dist/mdruntime/search.d.ts +21 -0
  79. package/dist/mdruntime/seed.d.ts +24 -0
  80. package/dist/mdruntime/socket/admission.d.ts +6 -0
  81. package/dist/mdruntime/socket/answers.d.ts +5 -0
  82. package/dist/mdruntime/socket/lanes.d.ts +27 -0
  83. package/dist/mdruntime/socket/session.d.ts +37 -0
  84. package/dist/mdruntime/socket.d.ts +66 -0
  85. package/dist/mdruntime/source.d.ts +53 -0
  86. package/dist/mdruntime/status.d.ts +25 -0
  87. package/dist/mdruntime/store/installs.d.ts +29 -0
  88. package/dist/mdruntime/store/readiness.d.ts +9 -0
  89. package/dist/mdruntime/store/records.d.ts +214 -0
  90. package/dist/mdruntime/store/room-held.d.ts +7 -0
  91. package/dist/mdruntime/store/space.d.ts +10 -0
  92. package/dist/mdruntime/store/watchers.d.ts +16 -0
  93. package/dist/mdruntime/store/writes.d.ts +23 -0
  94. package/dist/mdruntime/store.d.ts +121 -0
  95. package/dist/mdruntime/stored.d.ts +156 -0
  96. package/dist/mdruntime/surface.d.ts +88 -0
  97. package/dist/mdruntime/tables.d.ts +414 -0
  98. package/dist/mdruntime/tallies.d.ts +17 -0
  99. package/dist/mdruntime/transfer.d.ts +4 -0
  100. package/dist/mdruntime/wire.d.ts +295 -0
  101. package/dist/session-content/bounds.d.ts +7 -0
  102. package/dist/session-content/check.d.ts +18 -0
  103. package/dist/session-content/index.d.ts +7 -0
  104. package/dist/session-content/parts.d.ts +103 -0
  105. package/dist/session-content/state.d.ts +61 -0
  106. package/dist/session-content/turn.d.ts +328 -0
  107. package/dist/test-host.d.ts +8 -2
  108. package/dist/test-host.js +48 -12
  109. package/docs/families.md +70 -20
  110. package/package.json +8 -6
@@ -0,0 +1,55 @@
1
+ import type { AppRoom } from './listing.js';
2
+ import type { ReadinessPort } from './preparation.js';
3
+ import type { MdRuntime, RuntimeTopic } from './surface.js';
4
+ import type { Plan, PlanReach, QueryResult } from './query.js';
5
+ import type { Readiness } from './readiness.js';
6
+ import type { SearchResult } from './search.js';
7
+ export type ReachedDocument = {
8
+ readonly room: string;
9
+ readonly path: string;
10
+ };
11
+ export type ReachedArea = {
12
+ readonly room: string;
13
+ readonly path: string;
14
+ readonly open: readonly string[];
15
+ };
16
+ export type PortReach = {
17
+ readonly rooms: readonly string[];
18
+ readonly documents: readonly ReachedDocument[];
19
+ readonly areas?: readonly ReachedArea[];
20
+ readonly conversations: boolean;
21
+ };
22
+ export type Deliver = (message: unknown) => void;
23
+ export type Fail = (error: unknown) => void;
24
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
25
+ export type RuntimeView = {
26
+ md: MdRuntime;
27
+ watch: Watch;
28
+ };
29
+ export type NarrowedView = RuntimeView & {
30
+ narrow(reach: PortReach | null): void;
31
+ };
32
+ export type Reachable = RuntimeView & {
33
+ plan(input: unknown, reach: PortReach | null): Promise<Plan>;
34
+ query(plan: Plan): Promise<QueryResult>;
35
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
36
+ search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
37
+ watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
38
+ locked(room: string): Promise<boolean>;
39
+ lockedRooms(): Promise<readonly string[]>;
40
+ watchLocks(notify: () => void): () => void;
41
+ located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
42
+ room(locator: string): Promise<AppRoom | undefined>;
43
+ };
44
+ export declare function holds(reach: PortReach | null, room: string): boolean;
45
+ export declare function governs(reach: PortReach | null, room: {
46
+ readonly locator: string;
47
+ readonly typedSelection: {
48
+ roots: readonly string[];
49
+ } | null;
50
+ }): {
51
+ readonly collection: boolean;
52
+ readonly selection: boolean;
53
+ };
54
+ export declare function planReach(reach: PortReach | null): PlanReach | null;
55
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -0,0 +1,48 @@
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' | 'memory'>;
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 bytes: InstallationAmount;
28
+ };
29
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
30
+ export type Readiness = {
31
+ readonly status: ReadinessStatus;
32
+ readonly ready: boolean;
33
+ readonly usable: boolean;
34
+ readonly code: CodeAvailability;
35
+ readonly coverage: TargetCoverage;
36
+ readonly durability: Durability;
37
+ readonly persistence: Persistence;
38
+ readonly connection: ConnectionAvailability;
39
+ readonly house: HouseOutcome;
40
+ readonly space: Space | null;
41
+ readonly installation: Installation;
42
+ readonly lost: boolean;
43
+ };
44
+ export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
45
+ readonly coverage: Omit<TargetCoverage, 'complete'>;
46
+ readonly established: boolean;
47
+ };
48
+ export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -0,0 +1,38 @@
1
+ import { type CallResult } from './outcome.js';
2
+ import type { Recovery } from './recovery.js';
3
+ import type { Attempt, Retries } from './retried.js';
4
+ import type { Connection, RuntimeDatabase } from './tables.js';
5
+ export declare const READ_TABLES: readonly string[];
6
+ export type ReadAt = {
7
+ readonly name: string;
8
+ readonly input: string;
9
+ readonly build: string;
10
+ };
11
+ export type ObservedRead = {
12
+ readonly answer: unknown;
13
+ readonly failure: CallResult | null;
14
+ readonly kept: boolean;
15
+ };
16
+ export type ReadAnswers = {
17
+ watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
18
+ again(): void;
19
+ reopened(): void;
20
+ };
21
+ export type ReadAnswersOptions = {
22
+ readonly database: RuntimeDatabase;
23
+ readonly build: string;
24
+ readonly unkept: readonly string[];
25
+ readonly leading: readonly string[];
26
+ readonly recovery: Recovery;
27
+ readonly retries: Retries;
28
+ call(name: string, input: unknown, attempt: Attempt): Promise<CallResult>;
29
+ online(): boolean;
30
+ streaming(): boolean;
31
+ closed(): boolean;
32
+ full(): boolean;
33
+ filled(): void;
34
+ };
35
+ export declare function storedRead(connection: Connection, { name, input, build }: ReadAt): string | null;
36
+ export declare function keptRead(connection: Connection, { name, input, build }: ReadAt, answer: string): null;
37
+ export declare function readsOfOtherBuildsForgotten(connection: Connection, build: string): null;
38
+ export declare function readAnswers(options: ReadAnswersOptions): ReadAnswers;
@@ -0,0 +1,27 @@
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
+ again(): void;
20
+ waits(wake: () => void): () => void;
21
+ cancel(intent: string): void;
22
+ scope(inFlight?: number): Recovery;
23
+ retire(): Promise<void>;
24
+ };
25
+ export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
26
+ export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean, owner?: Recovery): Promise<T>;
27
+ 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 {};
@@ -0,0 +1,62 @@
1
+ import { type TypedPath } from '../mdmodel/index.js';
2
+ import type { BootstrapInventory, SavedFacts, MutationResult, RoomDeclaration, TypedSelection } from './adapter.js';
3
+ import { type ChangeBatch, type Precondition } from './change.js';
4
+ import { type Collection, type Composition } from './collection.js';
5
+ import { type ModelState } from './model.js';
6
+ import { type Layer } from './overlay.js';
7
+ import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
8
+ export type ReplicaRecord = {
9
+ readonly locator: string;
10
+ readonly declaration: RoomDeclaration;
11
+ readonly model: ModelState;
12
+ readonly roomVersion: string;
13
+ readonly transfer: string;
14
+ readonly inventory: BootstrapInventory;
15
+ readonly key: number;
16
+ };
17
+ export type HeldReplica = {
18
+ readonly record: ReplicaRecord;
19
+ readonly queue: readonly ChangeBatch[];
20
+ readonly overlaid: ReadonlySet<string>;
21
+ };
22
+ export type VisibleLayer = Layer & {
23
+ readonly collection: Collection;
24
+ };
25
+ export type Slice = Layer & {
26
+ readonly written: Readonly<Record<string, string>>;
27
+ readonly facts: Readonly<Record<string, SavedFacts>>;
28
+ readonly held: ReadonlySet<string>;
29
+ };
30
+ export declare function compositionOf(model: ModelState, typedSelection: TypedSelection | null, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
31
+ export declare function storedRecord(record: ReplicaRecord): string;
32
+ export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
33
+ export type LayerEntry = Omit<StoredEntry, 'facts'>;
34
+ export declare function entryAt(layer: Layer & {
35
+ readonly written?: Readonly<Record<string, string>>;
36
+ }, path: string): LayerEntry | null;
37
+ export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
38
+ export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
39
+ export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
40
+ export type Replayed = {
41
+ readonly visible: VisibleLayer;
42
+ readonly touched: ReadonlySet<string>;
43
+ };
44
+ export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
45
+ export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
46
+ export declare function holds(layer: Layer, preconditions: readonly Precondition[], composition: Composition): boolean;
47
+ export declare function landed(batch: ChangeBatch, confirmed: Layer, composition: Composition, current?: Readonly<Record<string, string>>): boolean;
48
+ export type Standing = {
49
+ readonly withdrawn: readonly ChangeBatch[];
50
+ readonly kept: readonly ChangeBatch[];
51
+ };
52
+ export declare function standing(confirmed: Slice, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean, locator: string, composition: Composition): Generator<number, Standing, void>;
53
+ type Accepted = Extract<MutationResult, {
54
+ kind: 'accepted';
55
+ }>;
56
+ export type Returned = {
57
+ readonly set: readonly StoredEntry[];
58
+ readonly removed: readonly string[];
59
+ };
60
+ export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
61
+ export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
62
+ export {};
@@ -0,0 +1,29 @@
1
+ import { type RuntimeShell } from './durability.js';
2
+ export declare const STEPS: readonly ['database', 'sign_in', 'connection', 'code', 'download', 'conversations', 'sending', 'reading'];
3
+ export type Step = (typeof STEPS)[number];
4
+ export type RetriedFailure = {
5
+ readonly step: Step;
6
+ readonly answered: false;
7
+ } | {
8
+ readonly step: Step;
9
+ readonly answered: true;
10
+ readonly error: unknown;
11
+ };
12
+ export type Uncertain = {
13
+ readonly failure?: unknown;
14
+ };
15
+ export type Attempt = {
16
+ readonly step: Step;
17
+ readonly instance: string;
18
+ };
19
+ export declare class Unanswered extends Error {
20
+ }
21
+ export declare function uncertainError(uncertainty: Uncertain): unknown;
22
+ export type Retries = {
23
+ failed(step: Step, instance: string, error: unknown): void;
24
+ unanswered(step: Step, instance: string): void;
25
+ uncertain(step: Step, instance: string, uncertainty: Uncertain): void;
26
+ succeeded(step: Step, instance: string): void;
27
+ };
28
+ export declare function createRetries(shell: Pick<RuntimeShell, 'retried' | 'succeeded'>): Retries;
29
+ export declare function retrying<T>(retries: Retries, step: Step, instance: string, ask: () => Promise<T>): () => Promise<T>;
@@ -0,0 +1,172 @@
1
+ import { type DefinitionOf } from '../mdmodel/index.js';
2
+ import type { ProviderRefusal } from './adapter.js';
3
+ import type { Open } from './open.js';
4
+ import type { Change, Precondition } from './change.js';
5
+ import type { VisibleLayer } from './replica.js';
6
+ export type FieldValue = {
7
+ readonly value: unknown;
8
+ } | null;
9
+ export type RoomDraftCreation = {
10
+ readonly type: string;
11
+ readonly fields: Readonly<Record<string, unknown>>;
12
+ readonly sections: Readonly<Record<string, string>>;
13
+ } | {
14
+ readonly markdown: string;
15
+ };
16
+ export type RoomDraftParts = {
17
+ readonly fields?: Readonly<Record<string, {
18
+ readonly value: unknown;
19
+ readonly base?: FieldValue;
20
+ }>>;
21
+ readonly sections?: Readonly<Record<string, {
22
+ readonly value: string;
23
+ readonly base?: string;
24
+ }>>;
25
+ readonly preamble?: {
26
+ readonly value: string;
27
+ readonly base?: string;
28
+ };
29
+ readonly markdown?: {
30
+ readonly value: string;
31
+ readonly base?: string;
32
+ };
33
+ readonly creation?: RoomDraftCreation;
34
+ readonly move?: {
35
+ readonly to: string;
36
+ readonly room?: string;
37
+ readonly base?: string | null;
38
+ };
39
+ readonly removal?: {
40
+ readonly base?: string | null;
41
+ };
42
+ readonly file?: {
43
+ readonly blob: Blob;
44
+ readonly base?: string | null;
45
+ };
46
+ };
47
+ export type HeldFile = {
48
+ readonly localId: string;
49
+ readonly name?: string;
50
+ readonly byteLength: number;
51
+ readonly mediaType: string;
52
+ readonly sha256: string;
53
+ readonly base: string | null;
54
+ };
55
+ type HeldParts = {
56
+ readonly fields?: Readonly<Record<string, {
57
+ readonly value: unknown;
58
+ readonly base: FieldValue;
59
+ }>>;
60
+ readonly sections?: Readonly<Record<string, {
61
+ readonly value: string;
62
+ readonly base: string;
63
+ }>>;
64
+ readonly preamble?: {
65
+ readonly value: string;
66
+ readonly base: string;
67
+ };
68
+ readonly markdown?: {
69
+ readonly value: string;
70
+ readonly base: string;
71
+ };
72
+ readonly creation?: RoomDraftCreation;
73
+ readonly move?: {
74
+ readonly to: string;
75
+ readonly room?: string;
76
+ readonly base: string | null;
77
+ };
78
+ readonly removal?: {
79
+ readonly base: string | null;
80
+ };
81
+ readonly file?: HeldFile;
82
+ };
83
+ type ChangedUnderneath = {
84
+ readonly fields?: Readonly<Record<string, FieldValue>>;
85
+ readonly sections?: Readonly<Record<string, string | null>>;
86
+ readonly preamble?: string | null;
87
+ readonly markdown?: string | null;
88
+ readonly creation?: string;
89
+ readonly move?: string | null;
90
+ readonly removal?: string | null;
91
+ readonly file?: string | null;
92
+ };
93
+ export type ReturnReason = ProviderRefusal & {
94
+ readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
95
+ };
96
+ export declare function returnedBy(): ReturnReason;
97
+ export type RoomDraft = {
98
+ readonly room: string;
99
+ readonly path: string;
100
+ readonly revision: string;
101
+ readonly parts: HeldParts;
102
+ readonly changedUnderneath: ChangedUnderneath;
103
+ readonly returned: ReturnReason | null;
104
+ };
105
+ export type RoomDraftWrite = {
106
+ readonly outcome: 'written';
107
+ readonly roomDraft: RoomDraft | null;
108
+ } | {
109
+ readonly outcome: 'stale';
110
+ readonly current: RoomDraft | null;
111
+ };
112
+ export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
113
+ export type ChangedPart = {
114
+ readonly path: string;
115
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
116
+ readonly name?: string;
117
+ };
118
+ export type RoomDraftRecord = {
119
+ readonly locator: string;
120
+ readonly path: string;
121
+ readonly revision: string;
122
+ readonly parts: HeldParts;
123
+ readonly returned: ReturnReason | null;
124
+ };
125
+ export type SavedDraft = {
126
+ readonly path: string;
127
+ readonly parts: HeldParts;
128
+ };
129
+ export declare function readParts(value: unknown, path: string): RoomDraftParts;
130
+ export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
131
+ export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
132
+ export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
133
+ export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
134
+ export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
135
+ export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
136
+ export declare function lineEnded(text: string): string;
137
+ export type TextParts = {
138
+ readonly fields?: Readonly<Record<string, {
139
+ readonly value: unknown;
140
+ }>>;
141
+ readonly sections?: Readonly<Record<string, {
142
+ readonly value: string;
143
+ }>>;
144
+ readonly preamble?: {
145
+ readonly value: string;
146
+ };
147
+ };
148
+ export declare function partsAfter(markdown: string, parts: TextParts, definitions?: DefinitionOf): string | null;
149
+ export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts, definitions?: DefinitionOf): HeldParts | null;
150
+ export declare function moveTarget(move: {
151
+ readonly to: string;
152
+ }): string;
153
+ export declare function readSavedParts(named: readonly {
154
+ readonly path: string;
155
+ readonly parts: unknown;
156
+ }[]): readonly {
157
+ readonly path: string;
158
+ readonly parts: RoomDraftParts;
159
+ }[];
160
+ export declare function partsChanges(named: readonly {
161
+ readonly path: string;
162
+ readonly parts: unknown;
163
+ }[]): {
164
+ readonly changes: readonly Change[];
165
+ readonly preconditions: readonly Precondition[];
166
+ };
167
+ export declare function changesOf(path: string, parts: HeldParts): {
168
+ changes: readonly Change[];
169
+ bases: readonly Precondition[];
170
+ };
171
+ export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
172
+ export {};
@@ -0,0 +1,23 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
@@ -0,0 +1,33 @@
1
+ import type { RoomDeclaration, TypedPath } from './adapter.js';
2
+ import type { RuntimeShell } from './durability.js';
3
+ import type { LiveConversations } from './conversation-live.js';
4
+ import type { WriteRule } from './declaration.js';
5
+ import type { FiguresRead } from './figures.js';
6
+ import type { LiveQueries } from './live.js';
7
+ import type { ModelState } from './model.js';
8
+ import type { Presence } from './presence.js';
9
+ import type { ReadAnswers } from './reads.js';
10
+ import type { Recovery } from './recovery.js';
11
+ import type { Retries } from './retried.js';
12
+ import type { RuntimeSocket } from './socket.js';
13
+ import type { HeldCover, Store } from './store.js';
14
+ import type { schemaTypes } from './attached-model.js';
15
+ export type Runtime = {
16
+ readonly store: Store;
17
+ readonly socket: RuntimeSocket;
18
+ readonly presence: Presence;
19
+ readonly recovery: Recovery;
20
+ readonly retries: Retries;
21
+ readonly shell: RuntimeShell;
22
+ readonly localSaves: boolean;
23
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
24
+ readonly builtIn: ModelState;
25
+ readonly typedPaths: readonly TypedPath[];
26
+ readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
27
+ readonly usableWhenHeld: readonly string[];
28
+ readonly build: string;
29
+ readonly conversations: LiveConversations;
30
+ readonly liveQueries: LiveQueries<HeldCover>;
31
+ readonly figures: FiguresRead;
32
+ readonly lastAnswers: ReadAnswers;
33
+ };
@@ -0,0 +1,58 @@
1
+ import { type Validation } from '../mdmodel/index.js';
2
+ import type { ProviderLimit } from './adapter.js';
3
+ import { type ChangeBatch, type WrittenBy } from './change.js';
4
+ import { type Composition } from './collection.js';
5
+ import type { WriteRule } from './declaration.js';
6
+ import { type Layer } from './overlay.js';
7
+ import type { ReplicaRecord, VisibleLayer } from './replica.js';
8
+ import { type ChangedPart, type RoomDraftRecord, type SavedDraft } from './room-draft.js';
9
+ export type SaveRefusal = {
10
+ code: string;
11
+ retryable: boolean;
12
+ file?: string;
13
+ location?: string;
14
+ line?: number;
15
+ referrers?: readonly string[];
16
+ parts?: readonly ChangedPart[];
17
+ };
18
+ export type SaveAsk = {
19
+ readonly saved: readonly SavedDraft[];
20
+ readonly consumed: ReadonlySet<string>;
21
+ readonly writtenBy?: WrittenBy;
22
+ readonly local: boolean;
23
+ readonly providerLimits: readonly ProviderLimit[];
24
+ };
25
+ export type SavingRoom = {
26
+ readonly record: ReplicaRecord;
27
+ readonly rule: WriteRule;
28
+ readonly composition: Composition;
29
+ readonly queue: readonly ChangeBatch[];
30
+ readonly changeable: ReadonlySet<string>;
31
+ readonly saved: ReadonlyMap<string, readonly SavedDraft[]>;
32
+ readonly replay: (queue: readonly ChangeBatch[]) => Generator<number, VisibleLayer, void>;
33
+ readonly folders: ReadonlySet<string>;
34
+ readonly modelled: boolean;
35
+ readonly drafts: ReadonlyMap<string, RoomDraftRecord>;
36
+ readonly validate: Validator;
37
+ };
38
+ export type PlannedRoom = {
39
+ readonly locator: string;
40
+ readonly queue: readonly ChangeBatch[];
41
+ readonly saved: ReadonlyMap<string, readonly SavedDraft[]>;
42
+ readonly consumed: readonly string[];
43
+ readonly carried: readonly RoomDraftRecord[];
44
+ };
45
+ export type SavePlan = {
46
+ readonly kind: 'refused';
47
+ readonly refusal: SaveRefusal;
48
+ } | {
49
+ readonly kind: 'planned';
50
+ readonly identifier: string;
51
+ readonly rooms: readonly PlannedRoom[];
52
+ };
53
+ export type Validator = (resulting: Layer, touched: readonly string[]) => Promise<Validation>;
54
+ export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
55
+ export declare function rewriting(batch: ChangeBatch, locator: string): boolean;
56
+ export declare function effectiveIn(batch: ChangeBatch, locator: string, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
57
+ export declare function destination(locator: string, saved: readonly SavedDraft[]): string | null;
58
+ export declare function planSave(ask: SaveAsk, room: SavingRoom, into?: SavingRoom): Promise<SavePlan>;
@@ -0,0 +1,31 @@
1
+ import { type ChangeBatch, type WrittenBy } from './change.js';
2
+ import { type AttachAnswer, type BinaryLinkAnswer, type HeldBinaryAnswer, type HeldShownAnswer } from './outcome.js';
3
+ import { type RoomDraftParts } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import { type SaveRefusal } from './save.js';
6
+ import type { Store } from './store.js';
7
+ export type SaveResult = {
8
+ outcome: 'saved';
9
+ identifier: string;
10
+ } | ({
11
+ outcome: 'refused';
12
+ } & SaveRefusal);
13
+ export type SavedRoomDraft = {
14
+ readonly path: string;
15
+ readonly revision: string;
16
+ };
17
+ export type SavedParts = {
18
+ readonly path: string;
19
+ readonly parts: RoomDraftParts;
20
+ };
21
+ export type BinaryFileSurface = {
22
+ read(room: string, path: string, revision?: string): Promise<HeldBinaryAnswer>;
23
+ link(room: string, path: string, revision?: string): Promise<BinaryLinkAnswer>;
24
+ show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
25
+ attach(room: string, file: File): Promise<AttachAnswer>;
26
+ part(file: string, part: number): Promise<Uint8Array | null>;
27
+ };
28
+ export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
29
+ export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
30
+ export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
31
+ export declare function binaryFileSurface(runtime: Runtime): BinaryFileSurface;
@@ -0,0 +1,21 @@
1
+ import type { ProviderRefusal, SearchHit } from './adapter.js';
2
+ import type { Failure, Offline } from './outcome.js';
3
+ export type SearchRequest = {
4
+ text: string;
5
+ rooms?: readonly string[];
6
+ };
7
+ export type { SearchHit } from './adapter.js';
8
+ export type SearchFound = {
9
+ kind: 'found';
10
+ documents: readonly SearchHit[];
11
+ };
12
+ export type SearchResult = SearchFound | Offline | (ProviderRefusal & {
13
+ kind: 'rejected';
14
+ }) | (ProviderRefusal & {
15
+ kind: 'undeclared';
16
+ }) | Failure;
17
+ export type SearchPlan = {
18
+ text: string;
19
+ rooms: readonly string[] | null;
20
+ };
21
+ export declare function searchPlanOf(input: unknown): SearchPlan;
@@ -0,0 +1,24 @@
1
+ import type { Cover } from './live.js';
2
+ import { type KeyedResult } from './observation.js';
3
+ import type { Plan, QueryRows } from './query.js';
4
+ import type { Deliver } from './reach.js';
5
+ import type { Runtime } from './runtime.js';
6
+ import type { HeldCover, Store } from './store.js';
7
+ export type EntrySeed = {
8
+ readonly at: Readonly<Record<string, string>>;
9
+ readonly queries: readonly {
10
+ readonly query: unknown;
11
+ readonly rows: QueryRows;
12
+ }[];
13
+ };
14
+ export type Seeded = {
15
+ readonly rows: QueryRows;
16
+ readonly at: Readonly<Record<string, string>>;
17
+ };
18
+ type SeededWatch = (coverOf: (cover: Cover, held: HeldCover) => Cover, deliver: (message: unknown) => void) => () => void;
19
+ export declare function entrySeedOf(value: unknown): EntrySeed | null;
20
+ export declare function seededResult(seed: Seeded): KeyedResult;
21
+ export declare function seedApplies(runtime: Runtime, plan: Plan, held: HeldCover): Seeded | null;
22
+ export declare function keepEntrySeed(store: Store, entry: EntrySeed): void;
23
+ export declare function watchSeeded(runtime: Runtime, plan: Plan, deliver: Deliver, watch: SeededWatch): () => void;
24
+ export {};
@@ -0,0 +1,6 @@
1
+ export type Admission = {
2
+ heldStream(): Promise<() => void>;
3
+ unqueued(): Promise<void>;
4
+ queued(text: number): () => void;
5
+ };
6
+ export declare function createAdmission(): Admission;