@agentshouse/app-bridge 0.1.0-c58a055eeaa71 → 0.1.0-c646d0da70608

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 (55) hide show
  1. package/README.md +3 -1
  2. package/dist/calls.d.ts +117 -0
  3. package/dist/calls.js +1 -0
  4. package/dist/index.d.ts +23 -11
  5. package/dist/mdmodel/blocks.d.ts +10 -0
  6. package/dist/mdmodel/condition.d.ts +149 -0
  7. package/dist/mdmodel/definition.d.ts +65 -0
  8. package/dist/mdmodel/divide.d.ts +2 -0
  9. package/dist/mdmodel/document.d.ts +15 -0
  10. package/dist/mdmodel/fields.d.ts +5 -0
  11. package/dist/mdmodel/index.d.ts +18 -0
  12. package/dist/mdmodel/paths.d.ts +17 -0
  13. package/dist/mdmodel/profile.d.ts +5 -0
  14. package/dist/mdmodel/project.d.ts +20 -0
  15. package/dist/mdmodel/references.d.ts +3 -0
  16. package/dist/mdmodel/types.d.ts +143 -0
  17. package/dist/mdmodel/validate.d.ts +7 -0
  18. package/dist/mdmodel/version.d.ts +1 -0
  19. package/dist/mdmodel/yaml.d.ts +55 -0
  20. package/dist/mdruntime/acquisition.d.ts +13 -0
  21. package/dist/mdruntime/adapter.d.ts +475 -0
  22. package/dist/mdruntime/binary.d.ts +22 -0
  23. package/dist/mdruntime/change-set.d.ts +34 -0
  24. package/dist/mdruntime/change.d.ts +88 -0
  25. package/dist/mdruntime/client.d.ts +82 -0
  26. package/dist/mdruntime/collection.d.ts +38 -0
  27. package/dist/mdruntime/connection.d.ts +138 -0
  28. package/dist/mdruntime/conversation.d.ts +104 -0
  29. package/dist/mdruntime/durability.d.ts +14 -0
  30. package/dist/mdruntime/failure.d.ts +12 -0
  31. package/dist/mdruntime/file.d.ts +19 -0
  32. package/dist/mdruntime/model.d.ts +57 -0
  33. package/dist/mdruntime/observation.d.ts +29 -0
  34. package/dist/mdruntime/open.d.ts +1 -0
  35. package/dist/mdruntime/outcome.d.ts +46 -0
  36. package/dist/mdruntime/overlay.d.ts +26 -0
  37. package/dist/mdruntime/query.d.ts +247 -0
  38. package/dist/mdruntime/reach.d.ts +45 -0
  39. package/dist/mdruntime/readiness.d.ts +52 -0
  40. package/dist/mdruntime/recovery.d.ts +24 -0
  41. package/dist/mdruntime/replica.d.ts +45 -0
  42. package/dist/mdruntime/room-draft.d.ts +143 -0
  43. package/dist/mdruntime/rows.d.ts +36 -0
  44. package/dist/mdruntime/save.d.ts +63 -0
  45. package/dist/mdruntime/search.d.ts +84 -0
  46. package/dist/mdruntime/shared.d.ts +10 -0
  47. package/dist/mdruntime/status.d.ts +26 -0
  48. package/dist/mdruntime/store.d.ts +160 -0
  49. package/dist/mdruntime/transfer.d.ts +9 -0
  50. package/dist/mdruntime/turn.d.ts +6 -0
  51. package/dist/mdruntime/wire.d.ts +206 -0
  52. package/dist/test-host.d.ts +5 -5
  53. package/dist/test-host.js +56 -21
  54. package/docs/families.md +41 -2
  55. package/package.json +1 -4
@@ -0,0 +1,84 @@
1
+ import type { ChangeSet } from './change-set.js';
2
+ import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
3
+ import type { Open } from './open.js';
4
+ export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
5
+ export type SearchRequest = {
6
+ text: string;
7
+ documents?: Filter;
8
+ conversations?: readonly string[];
9
+ limit?: number;
10
+ };
11
+ export type DocumentHit = {
12
+ room: string;
13
+ path: string;
14
+ type: string;
15
+ score: number;
16
+ matches: Readonly<Record<string, readonly DocumentPart[]>>;
17
+ };
18
+ export type MessageHit = {
19
+ conversation: string;
20
+ identity: string;
21
+ score: number;
22
+ matches: Readonly<Record<string, readonly Open<'text'>[]>>;
23
+ };
24
+ export type SearchCoverage = {
25
+ rooms: readonly CoveredRoom[];
26
+ conversations: readonly string[];
27
+ index: string;
28
+ overlay: readonly string[];
29
+ };
30
+ export type PendingConversation = {
31
+ conversation: string;
32
+ awaits: Open<'index'>;
33
+ };
34
+ export type SearchHits = {
35
+ documents: readonly DocumentHit[];
36
+ messages: readonly MessageHit[];
37
+ };
38
+ export type SearchPending = SearchHits & {
39
+ pending: readonly (PendingRoom | PendingConversation)[];
40
+ coverage: SearchCoverage;
41
+ };
42
+ export type SearchResult = (SearchHits & {
43
+ coverage: SearchCoverage;
44
+ }) | SearchPending;
45
+ export type SearchedDocument = {
46
+ room: string;
47
+ path: string;
48
+ type: string;
49
+ fields: Readonly<Record<string, unknown>>;
50
+ preamble: string;
51
+ sections: Readonly<Record<string, string>>;
52
+ };
53
+ export type SearchedMessage = {
54
+ conversation: string;
55
+ identity: string;
56
+ text: string;
57
+ };
58
+ export type SearchSource = {
59
+ room(room: string): readonly string[];
60
+ document(room: string, path: string): SearchedDocument | null;
61
+ };
62
+ export type SearchPlan = {
63
+ text: string;
64
+ documents: unknown;
65
+ conversations: readonly string[] | null;
66
+ limit: number | null;
67
+ };
68
+ export type SearchIndex = {
69
+ generation(): string;
70
+ rooms(): ReadonlySet<string>;
71
+ conversations(): ReadonlySet<string>;
72
+ indexRoom(room: string): Promise<void>;
73
+ indexMessages(conversation: string, messages: readonly SearchedMessage[], whole: boolean): void;
74
+ forget(rooms: readonly string[]): void;
75
+ changed(set: ChangeSet): void;
76
+ changes(): number;
77
+ caughtUp(): Promise<void>;
78
+ search(plan: SearchPlan, documents: readonly {
79
+ room: string;
80
+ path: string;
81
+ }[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null): SearchHits;
82
+ };
83
+ export declare function searchPlanOf(input: unknown): SearchPlan;
84
+ export declare function createSearchIndex(source: SearchSource): SearchIndex;
@@ -0,0 +1,10 @@
1
+ export type Paths<V> = Readonly<Record<string, V>>;
2
+ type Weigh<V> = (key: string, value: V) => number;
3
+ export declare function shared<V>(map: Paths<V>): Paths<V>;
4
+ export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
5
+ export declare function tally<V>(map: Paths<V>, weigh: Weigh<V>): number;
6
+ export declare function sizeOf<V>(map: Paths<V>): number;
7
+ export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
8
+ export declare function drafted<V>(base: Paths<V>): Record<string, V>;
9
+ export declare function settled<V>(draft: Record<string, V>): Paths<V>;
10
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { Open } from './open.js';
2
+ import type { ProviderRefusal } from './adapter.js';
3
+ import type { ReturnReason } from './room-draft.js';
4
+ export type AttentionEntry = {
5
+ room: string;
6
+ path: string;
7
+ returned: ReturnReason;
8
+ } | {
9
+ room: string;
10
+ refusal: ProviderRefusal;
11
+ };
12
+ export type SyncStatus = {
13
+ state: Open<'pending' | 'syncing' | 'synced'>;
14
+ lastCompleted: string | null;
15
+ providerUnreachable: boolean;
16
+ attentionRequired: readonly AttentionEntry[];
17
+ reset: string | null;
18
+ };
19
+ export type CycleProgress = {
20
+ complete: boolean;
21
+ reachable: boolean;
22
+ };
23
+ export declare const STARTING: SyncStatus;
24
+ export declare function transferring(status: SyncStatus): SyncStatus;
25
+ export declare function saving(status: SyncStatus): SyncStatus;
26
+ export declare function same(one: SyncStatus, other: SyncStatus): boolean;
@@ -0,0 +1,160 @@
1
+ import type { ModelState } from './model.js';
2
+ import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission, TypedSelection } from './adapter.js';
3
+ import type { AcceptedMessage, KeptReceipt } from './adapter.js';
4
+ import type { ChangeBatch } from './change.js';
5
+ import { type HeldBinary } from './overlay.js';
6
+ import type { ChatDraftFile } from './file.js';
7
+ import type { Submission } from './outcome.js';
8
+ import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
9
+ export declare const STORE_SCHEMA = 25;
10
+ export declare const AUTHORED_SCHEMA = 2;
11
+ export type ReplicaRecord = {
12
+ locator: string;
13
+ name: string;
14
+ handle: string;
15
+ operations: OperationScopes;
16
+ replica: ReplicaAdmission;
17
+ model: ModelState;
18
+ typedSelection: TypedSelection | null;
19
+ selectionModel: ModelState;
20
+ providerOwnedPaths: readonly string[];
21
+ roomVersion: string;
22
+ transfer: string;
23
+ documents: Readonly<Record<string, string>>;
24
+ binaries: Readonly<Record<string, HeldBinary>>;
25
+ revisions: Readonly<Record<string, string>>;
26
+ changes: Readonly<Record<string, HeadChange>>;
27
+ written: Readonly<Record<string, string>>;
28
+ };
29
+ export type StagedLayer = Pick<ReplicaRecord, 'documents' | 'binaries' | 'revisions' | 'changes' | 'written'>;
30
+ export type TransferRecord = {
31
+ locator: string;
32
+ transfer: string;
33
+ selection: string;
34
+ from: string;
35
+ last: string;
36
+ pageToken: string | null;
37
+ models: {
38
+ collection: ModelState;
39
+ selection: ModelState;
40
+ };
41
+ };
42
+ export type PendingState = {
43
+ readonly drafts: readonly SavedDraft[];
44
+ readonly submission: Submission;
45
+ readonly lost: boolean;
46
+ readonly upload?: unknown;
47
+ readonly accepted?: string;
48
+ };
49
+ export type TargetRecord = {
50
+ established: boolean;
51
+ search: boolean;
52
+ };
53
+ export type QueueRecord = {
54
+ locator: string;
55
+ pending: readonly {
56
+ batch: ChangeBatch;
57
+ state: PendingState;
58
+ }[];
59
+ };
60
+ export type PresentationRecord = {
61
+ app: string;
62
+ value: unknown;
63
+ };
64
+ export type HeldConversation = {
65
+ conversation: string;
66
+ read: string | null | undefined;
67
+ partial: boolean;
68
+ };
69
+ export type ConversationWrite = {
70
+ conversation: string;
71
+ messages: readonly AcceptedMessage[];
72
+ read?: {
73
+ at: string | null;
74
+ partial: boolean;
75
+ };
76
+ };
77
+ export type ChatSubmission = {
78
+ readonly operation: string;
79
+ readonly text: string;
80
+ readonly files: readonly ChatDraftFile[];
81
+ readonly turn: string | null;
82
+ };
83
+ export type ChatDraftRecord = {
84
+ conversation: string;
85
+ text: string;
86
+ files: readonly ChatDraftFile[];
87
+ revision: string;
88
+ submitted?: readonly ChatSubmission[];
89
+ moves?: readonly string[];
90
+ };
91
+ export type RecordWrite = {
92
+ next: ReplicaRecord;
93
+ previous: ReplicaRecord | null;
94
+ stored?: StagedLayer;
95
+ };
96
+ export type AuthoredWrite = {
97
+ locator: string;
98
+ queue: readonly ChangeBatch[];
99
+ saved?: ReadonlyMap<string, readonly SavedDraft[]>;
100
+ roomDrafts?: readonly RoomDraftRecord[];
101
+ consumedRoomDrafts?: readonly string[];
102
+ };
103
+ export type RuntimeStore = {
104
+ all(): Promise<readonly ReplicaRecord[]>;
105
+ keepAuthored(input: AuthoredWrite): Promise<void>;
106
+ write(input: RecordWrite): Promise<void>;
107
+ revokeModels(records: readonly ReplicaRecord[]): Promise<void>;
108
+ lastCompleted(): Promise<string | null>;
109
+ complete(at: string): Promise<void>;
110
+ providerLimits(): Promise<readonly ProviderLimit[]>;
111
+ capabilities(): Promise<readonly Capability[]>;
112
+ declare(limits: readonly ProviderLimit[], capabilities: readonly Capability[]): Promise<void>;
113
+ member(): Promise<Member | null>;
114
+ keepMember(member: Member | null): Promise<void>;
115
+ targets(): Promise<Readonly<Record<string, TargetRecord>>>;
116
+ keepTargets(targets: Readonly<Record<string, TargetRecord>>): Promise<void>;
117
+ queues(): Promise<readonly QueueRecord[]>;
118
+ submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
119
+ accept(locator: string, id: string, roomVersion: string): Promise<void>;
120
+ keepUpload(locator: string, id: string, upload: unknown): Promise<void>;
121
+ roomDrafts(): Promise<readonly RoomDraftRecord[]>;
122
+ presentation(): Promise<readonly PresentationRecord[]>;
123
+ present(record: PresentationRecord): Promise<void>;
124
+ conversations(): Promise<readonly HeldConversation[]>;
125
+ keepMessages(write: ConversationWrite): Promise<void>;
126
+ messageWindow(conversation: string, limit: number | undefined): Promise<AcceptedMessage[]>;
127
+ messagesAfter(conversation: string, identity: string | null): Promise<AcceptedMessage[]>;
128
+ messageIdentities(conversation: string): Promise<readonly string[]>;
129
+ turnArrived(conversation: string, turn: string): Promise<boolean>;
130
+ dropConversations(conversations: readonly string[]): Promise<void>;
131
+ chatDrafts(): Promise<readonly ChatDraftRecord[]>;
132
+ keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
133
+ dropChatDraft(conversation: string): Promise<void>;
134
+ keepRoomDraft(record: RoomDraftRecord): Promise<void>;
135
+ discardRoomDraft(locator: string, path: string): Promise<void>;
136
+ fences(): Promise<readonly string[]>;
137
+ erase(locators: readonly string[]): Promise<void>;
138
+ discard(locator: string): Promise<void>;
139
+ transfers(): Promise<readonly TransferRecord[]>;
140
+ staged(record: TransferRecord): Promise<StagedLayer>;
141
+ stage(record: TransferRecord, page: StagedLayer): Promise<void>;
142
+ abandon(locator: string): Promise<void>;
143
+ receivedHeads(): Promise<readonly KeptReceipt[]>;
144
+ receivedParts(key: string, count: number): Promise<readonly unknown[]>;
145
+ keepReceived(key: string, head: unknown, part?: {
146
+ index: number;
147
+ value: unknown;
148
+ }): Promise<void>;
149
+ dropReceived(keys: readonly string[]): Promise<void>;
150
+ generation(): Promise<string | null>;
151
+ rememberGeneration(value: string): Promise<void>;
152
+ close(): void;
153
+ };
154
+ export declare function authoredHolder(): Promise<string | null>;
155
+ export declare function authoredBy(holder: string): Promise<boolean>;
156
+ export declare function authoredBinding(): Promise<string | null>;
157
+ export declare function bindAuthored(binding: string): Promise<void>;
158
+ export declare function removeRuntimeStore(holder?: string): Promise<boolean>;
159
+ export declare function openDatabase(name: string, version: number, upgrade: (opening: IDBOpenDBRequest, oldVersion: number) => void): Promise<IDBDatabase>;
160
+ export declare function openRuntimeStore(fenced: (locator: string) => boolean): Promise<RuntimeStore>;
@@ -0,0 +1,9 @@
1
+ import type { Refusal } from '../mdmodel/index.js';
2
+ export type Unconfirmed = {
3
+ kind: 'unconfirmed';
4
+ };
5
+ export type Refused = {
6
+ kind: 'refused';
7
+ refusal: Refusal;
8
+ };
9
+ export declare const unconfirmed: Unconfirmed;
@@ -0,0 +1,6 @@
1
+ export declare function yielded(): Promise<void>;
2
+ export declare const ROW_WEIGHT = 256;
3
+ export type Later<T> = T | Promise<T>;
4
+ export declare function after<T, R>(value: Later<T>, next: (value: T) => R): Later<R>;
5
+ export declare function inUnits<T>(items: Iterable<T>, each: (item: T) => number): Later<void>;
6
+ export declare function inChunks<T>(items: readonly T[], weigh: (item: T) => number, each: (chunk: readonly T[]) => void): Promise<void>;
@@ -0,0 +1,206 @@
1
+ import type { ConnectionRefusal } from './connection.js';
2
+ import type { Described } from './failure.js';
3
+ export type RuntimePort = {
4
+ postMessage(message: unknown): void;
5
+ addEventListener(type: 'message' | 'close', listener: (event: {
6
+ data?: unknown;
7
+ }) => void): void;
8
+ start(): void;
9
+ };
10
+ export type WireReach = 'within' | 'app' | 'runtime' | 'actions' | 'whole';
11
+ export type WireEffect = 'read' | 'write' | 'action';
12
+ export type WireCall = {
13
+ readonly reach: WireReach;
14
+ readonly effect: WireEffect;
15
+ };
16
+ declare const MEMBERS: {
17
+ readonly rooms: {
18
+ readonly reach: 'within';
19
+ readonly effect: 'read';
20
+ };
21
+ readonly query: {
22
+ readonly reach: 'within';
23
+ readonly effect: 'read';
24
+ };
25
+ readonly search: {
26
+ readonly reach: 'within';
27
+ readonly effect: 'read';
28
+ };
29
+ readonly types: {
30
+ readonly reach: 'within';
31
+ readonly effect: 'read';
32
+ };
33
+ readonly save: {
34
+ readonly reach: 'within';
35
+ readonly effect: 'write';
36
+ };
37
+ readonly history: {
38
+ readonly reach: 'within';
39
+ readonly effect: 'read';
40
+ };
41
+ readonly 'binaryFile.read': {
42
+ readonly reach: 'within';
43
+ readonly effect: 'read';
44
+ };
45
+ readonly 'binaryFile.readReference': {
46
+ readonly reach: 'within';
47
+ readonly effect: 'read';
48
+ };
49
+ readonly call: {
50
+ readonly reach: 'actions';
51
+ readonly effect: 'action';
52
+ };
53
+ readonly reached: {
54
+ readonly reach: 'within';
55
+ readonly effect: 'read';
56
+ };
57
+ readonly log: {
58
+ readonly reach: 'whole';
59
+ readonly effect: 'read';
60
+ };
61
+ readonly persistence: {
62
+ readonly reach: 'runtime';
63
+ readonly effect: 'read';
64
+ };
65
+ readonly retry: {
66
+ readonly reach: 'runtime';
67
+ readonly effect: 'write';
68
+ };
69
+ readonly reauthorize: {
70
+ readonly reach: 'runtime';
71
+ readonly effect: 'write';
72
+ };
73
+ readonly 'roomDraft.list': {
74
+ readonly reach: 'within';
75
+ readonly effect: 'read';
76
+ };
77
+ readonly 'roomDraft.read': {
78
+ readonly reach: 'within';
79
+ readonly effect: 'read';
80
+ };
81
+ readonly 'roomDraft.write': {
82
+ readonly reach: 'within';
83
+ readonly effect: 'write';
84
+ };
85
+ readonly 'roomDraft.discard': {
86
+ readonly reach: 'within';
87
+ readonly effect: 'write';
88
+ };
89
+ readonly 'presentation.read': {
90
+ readonly reach: 'app';
91
+ readonly effect: 'read';
92
+ };
93
+ readonly 'presentation.write': {
94
+ readonly reach: 'app';
95
+ readonly effect: 'write';
96
+ };
97
+ readonly 'conversation.list': {
98
+ readonly reach: 'within';
99
+ readonly effect: 'read';
100
+ };
101
+ readonly 'conversation.read': {
102
+ readonly reach: 'within';
103
+ readonly effect: 'read';
104
+ };
105
+ readonly 'conversation.create': {
106
+ readonly reach: 'within';
107
+ readonly effect: 'action';
108
+ };
109
+ readonly 'conversation.send': {
110
+ readonly reach: 'within';
111
+ readonly effect: 'action';
112
+ };
113
+ readonly 'conversation.answer': {
114
+ readonly reach: 'within';
115
+ readonly effect: 'action';
116
+ };
117
+ readonly 'conversation.interrupt': {
118
+ readonly reach: 'within';
119
+ readonly effect: 'action';
120
+ };
121
+ readonly 'conversation.kill': {
122
+ readonly reach: 'within';
123
+ readonly effect: 'action';
124
+ };
125
+ readonly 'conversation.cancel': {
126
+ readonly reach: 'within';
127
+ readonly effect: 'action';
128
+ };
129
+ readonly 'conversation.delete': {
130
+ readonly reach: 'within';
131
+ readonly effect: 'action';
132
+ };
133
+ readonly 'chatDraft.write': {
134
+ readonly reach: 'within';
135
+ readonly effect: 'write';
136
+ };
137
+ readonly 'chatDraft.discard': {
138
+ readonly reach: 'within';
139
+ readonly effect: 'write';
140
+ };
141
+ };
142
+ declare const TOPICS: {
143
+ readonly rooms: 'within';
144
+ readonly readiness: 'within';
145
+ readonly 'connection-refusal': 'runtime';
146
+ readonly 'storage-loss': 'runtime';
147
+ readonly 'deployment-facts': 'runtime';
148
+ readonly 'sync-status': 'within';
149
+ readonly 'service-mode': 'runtime';
150
+ readonly member: 'runtime';
151
+ readonly query: 'within';
152
+ readonly queue: 'within';
153
+ readonly 'room-drafts': 'within';
154
+ readonly presentation: 'app';
155
+ readonly conversation: 'within';
156
+ readonly conversations: 'within';
157
+ readonly agents: 'within';
158
+ };
159
+ export declare const WIRE: {
160
+ readonly members: Readonly<Record<string, WireCall>>;
161
+ readonly topics: Readonly<Record<string, WireReach>>;
162
+ };
163
+ export type WireMember = keyof typeof MEMBERS;
164
+ export type WireTopic = keyof typeof TOPICS;
165
+ export type WireRequest = {
166
+ kind: 'hello';
167
+ } | {
168
+ kind: 'call';
169
+ id: number;
170
+ member: WireMember;
171
+ input: readonly unknown[];
172
+ } | {
173
+ kind: 'observe';
174
+ id: number;
175
+ topic: WireTopic;
176
+ input: readonly unknown[];
177
+ } | {
178
+ kind: 'stop';
179
+ id: number;
180
+ };
181
+ export type WireAnswer = {
182
+ kind: 'result';
183
+ id: number;
184
+ value: unknown;
185
+ } | ({
186
+ kind: 'failure';
187
+ id: number;
188
+ } & Described) | {
189
+ kind: 'event';
190
+ id: number;
191
+ value: unknown;
192
+ } | {
193
+ kind: 'refusal';
194
+ refusal: ConnectionRefusal;
195
+ } | {
196
+ kind: 'ended';
197
+ };
198
+ export declare function unanswered(call: {
199
+ readonly id: number;
200
+ readonly member: WireMember;
201
+ }): WireAnswer | null;
202
+ export declare const AUTHORIZATION_ENDED = "the host authorization ended";
203
+ export declare const PORT_CLOSED = "the port closed";
204
+ export declare function request(message: unknown): WireRequest | null;
205
+ export declare function answer(message: unknown): WireAnswer | null;
206
+ export {};
@@ -1,5 +1,5 @@
1
- import type { MdRuntimeClient } from '@agentshouse/mdruntime/client';
2
- import type { HouseAnalyticsChoice, HouseAppMessage, HouseExternalAnswer, HouseExternalRequest, HouseImageCopy, HouseNavigationMode, HouseRefusal, HouseSourceDownload, HouseSourceTop, HouseStatus, HouseTab } from './index.js';
1
+ import type { MdRuntimeClient } from './mdruntime/client.js';
2
+ import type { HouseActivation, HouseAnalyticsChoice, HouseAppMessage, HouseExternalAnswer, HouseExternalRequest, HouseNavigationMode, HouseRefusal, HouseSourceDownload, HouseSourceTop, HouseStatus, HouseTab, HouseTask } from './index.js';
3
3
  export interface HouseBridgeNavigation {
4
4
  readonly mode: HouseNavigationMode;
5
5
  readonly address: string;
@@ -15,13 +15,13 @@ export interface HouseBridgeTestHost {
15
15
  publish(status: HouseStatus): void;
16
16
  message(message: HouseAppMessage): void;
17
17
  attachRuntime(runtime: MdRuntimeClient): void;
18
+ checkpoint(): Promise<HouseTask>;
19
+ restore(task: HouseTask | null): Promise<boolean>;
20
+ settle(activation: HouseActivation): void;
18
21
  }
19
22
  export interface HouseBridgeTestHostOptions {
20
23
  readonly address?: string;
21
24
  readonly status?: HouseStatus;
22
- readonly images?: readonly (HouseImageCopy & {
23
- readonly room: string;
24
- })[];
25
25
  readonly sources?: readonly {
26
26
  readonly top: HouseSourceTop;
27
27
  readonly download: HouseSourceDownload;
package/dist/test-host.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const HOST_ORIGIN = 'https://house.invalid';
2
- const ADDRESS_MAX_CHARS = 1000;
2
+ const ADDRESS_MAX_CHARS = 64 * 1024;
3
3
  function sameOriginPath(value) {
4
4
  if (typeof value !== 'string')
5
5
  return null;
@@ -29,6 +29,21 @@ function navigationRefused(address) {
29
29
  address,
30
30
  });
31
31
  }
32
+ function followHeld(listeners, listener, held) {
33
+ let following = true;
34
+ queueMicrotask(() => {
35
+ if (!following)
36
+ return;
37
+ listeners.add(listener);
38
+ const value = held();
39
+ if (value !== null)
40
+ listener(value);
41
+ });
42
+ return () => {
43
+ following = false;
44
+ listeners.delete(listener);
45
+ };
46
+ }
32
47
  export function createHouseBridgeTestHost(options = {}) {
33
48
  const navigations = [];
34
49
  const ceremonies = [];
@@ -42,6 +57,7 @@ export function createHouseBridgeTestHost(options = {}) {
42
57
  let published = options.status ?? null;
43
58
  let shown = null;
44
59
  let seen = null;
60
+ let cooperation = null;
45
61
  let attached = () => { };
46
62
  const runtime = new Promise((resolve) => {
47
63
  attached = resolve;
@@ -63,7 +79,17 @@ export function createHouseBridgeTestHost(options = {}) {
63
79
  });
64
80
  }
65
81
  function navigate(mode, asked) {
66
- const target = sameOriginPath(asked);
82
+ let path = asked;
83
+ if (/^https?:\/\//i.test(asked)) {
84
+ try {
85
+ const target = new URL(asked);
86
+ path = target.origin === HOST_ORIGIN ? target.pathname + target.search + target.hash : '';
87
+ }
88
+ catch {
89
+ path = '';
90
+ }
91
+ }
92
+ const target = sameOriginPath(path);
67
93
  if (target === null)
68
94
  return Promise.reject(navigationRefused(asked));
69
95
  navigations.push({ mode, address: target });
@@ -76,10 +102,7 @@ export function createHouseBridgeTestHost(options = {}) {
76
102
  runtime,
77
103
  address: () => shown,
78
104
  onAddress(listener) {
79
- addressListeners.add(listener);
80
- return () => {
81
- addressListeners.delete(listener);
82
- };
105
+ return followHeld(addressListeners, listener, () => shown);
83
106
  },
84
107
  push: (asked) => navigate('push', asked),
85
108
  replace: (asked) => navigate('replace', asked),
@@ -96,17 +119,6 @@ export function createHouseBridgeTestHost(options = {}) {
96
119
  setTab(tab) {
97
120
  tabs.push(tab);
98
121
  },
99
- readAttachment(room, attachment) {
100
- const image = options.images?.find((entry) => entry.room === room && entry.attachment === attachment);
101
- return Promise.resolve(image === undefined
102
- ? null
103
- : {
104
- attachment: image.attachment,
105
- copy: image.copy,
106
- name: image.name,
107
- media_type: image.media_type,
108
- });
109
- },
110
122
  sourceTop: (app) => Promise.resolve(options.sources?.find((entry) => entry.top.app_ref === app)?.top ?? null),
111
123
  sourceDownload: (app) => Promise.resolve(options.sources?.find((entry) => entry.top.app_ref === app)?.download ?? null),
112
124
  callExternal(request) {
@@ -117,10 +129,7 @@ export function createHouseBridgeTestHost(options = {}) {
117
129
  readSiteScreenshot: (site) => Promise.resolve(options.siteScreenshots?.[site] ?? null),
118
130
  status: () => seen,
119
131
  onStatus(listener) {
120
- statusListeners.add(listener);
121
- return () => {
122
- statusListeners.delete(listener);
123
- };
132
+ return followHeld(statusListeners, listener, () => seen);
124
133
  },
125
134
  messages(listener) {
126
135
  messageListeners.add(listener);
@@ -136,7 +145,19 @@ export function createHouseBridgeTestHost(options = {}) {
136
145
  consents.push(choice);
137
146
  publish({ ...published, analytics: { measures: true, choice } });
138
147
  },
148
+ cooperate(given) {
149
+ cooperation = given;
150
+ return () => {
151
+ if (cooperation === given)
152
+ cooperation = null;
153
+ };
154
+ },
139
155
  };
156
+ function cooperating() {
157
+ if (cooperation === null)
158
+ throw new Error('the App registered no cooperation');
159
+ return cooperation;
160
+ }
140
161
  Object.defineProperty(globalThis, 'houseBridge', { value: bridge, configurable: true });
141
162
  if (published !== null)
142
163
  publish(published);
@@ -161,5 +182,19 @@ export function createHouseBridgeTestHost(options = {}) {
161
182
  attachRuntime(client) {
162
183
  attached(client);
163
184
  },
185
+ async checkpoint() {
186
+ const held = cooperating();
187
+ await held.checkpoint();
188
+ await held.persist();
189
+ return JSON.parse(JSON.stringify((await held.capture()) ?? null));
190
+ },
191
+ async restore(task) {
192
+ const held = cooperating();
193
+ await held.restore(task);
194
+ return (await held.ready()) === true;
195
+ },
196
+ settle(activation) {
197
+ cooperating().settle(activation);
198
+ },
164
199
  };
165
200
  }