@agentshouse/app-bridge 0.1.0-cfb240c3fb89d → 0.1.0-cfefe363de456

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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { MdRuntimeClient } from './mdruntime/client.js';
1
+ import type { MdRuntimeClient, Open } from './mdruntime/client.js';
2
2
  import type { HouseCalls } from './calls.js';
3
3
  export type { HouseCalls } from './calls.js';
4
- type Open<Value extends string> = Value | (string & {});
5
4
  export type HouseCallInput<Name extends string> = Name extends keyof HouseCalls ? HouseCalls[Name] : unknown;
6
5
  export interface HouseRuntime extends Omit<MdRuntimeClient, 'call'> {
7
6
  call<Name extends Open<keyof HouseCalls>>(name: Name, input: HouseCallInput<Name>): ReturnType<MdRuntimeClient['call']>;
@@ -110,6 +109,20 @@ export interface HouseBrowserRefused extends Error {
110
109
  readonly code: string;
111
110
  readonly retryable: boolean;
112
111
  }
112
+ export interface HouseTrialWithheld {
113
+ readonly code: Open<'house_trial_withheld'>;
114
+ readonly retryable: true;
115
+ }
116
+ export type HouseTask = unknown;
117
+ export type HouseActivation = Open<'committed' | 'abandoned'>;
118
+ export interface HouseCooperation {
119
+ checkpoint(): Promise<void> | void;
120
+ persist(): Promise<void> | void;
121
+ capture(): Promise<HouseTask> | HouseTask;
122
+ restore(task: HouseTask | null): Promise<void> | void;
123
+ ready(): Promise<boolean> | boolean;
124
+ settle(activation: HouseActivation): void;
125
+ }
113
126
  export interface HouseBridge {
114
127
  readonly runtime: Promise<HouseRuntime>;
115
128
  address(): string | null;
@@ -130,6 +143,7 @@ export interface HouseBridge {
130
143
  onStatus(listener: (status: HouseStatus) => void): () => void;
131
144
  messages(listener: (message: HouseAppMessage) => void): () => void;
132
145
  analyticsConsent(choice: HouseAnalyticsChoice): void;
146
+ cooperate(cooperation: HouseCooperation): () => void;
133
147
  }
134
148
  export interface HouseHeld {
135
149
  readonly houseBridge: HouseBridge;
@@ -0,0 +1,13 @@
1
+ export type RuntimeDemand = {
2
+ readonly whole: boolean;
3
+ readonly rooms: readonly string[];
4
+ readonly handles: readonly string[];
5
+ readonly conversations: boolean;
6
+ };
7
+ export declare const WHOLE_DEMAND: RuntimeDemand;
8
+ export declare function demanded(demand: RuntimeDemand, room: {
9
+ readonly locator: string;
10
+ readonly handle: string;
11
+ }): boolean;
12
+ export declare function wider(next: RuntimeDemand, current: RuntimeDemand): boolean;
13
+ export declare function narrower(next: RuntimeDemand, current: RuntimeDemand): boolean;
@@ -238,17 +238,15 @@ export type ContractUnavailable = ProviderRefusal & {
238
238
  export type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization | ContractUnavailable;
239
239
  export type PageToken = string;
240
240
  export type ChangeAuthor = {
241
- kind: 'user';
241
+ kind: Open<'user' | 'site'>;
242
242
  id: string;
243
243
  name: string;
244
- } | {
245
- kind: 'site';
244
+ };
245
+ export type Member = {
246
+ kind: Open<'user'>;
246
247
  id: string;
247
248
  name: string;
248
249
  };
249
- export type Member = Extract<ChangeAuthor, {
250
- kind: 'user';
251
- }>;
252
250
  export type HeadChange = {
253
251
  author: ChangeAuthor | null;
254
252
  time: string;
@@ -446,8 +444,12 @@ export type StreamReceipts = {
446
444
  }): Promise<void>;
447
445
  drop(keys: readonly string[]): Promise<void>;
448
446
  };
447
+ export type AcquiredDemand = {
448
+ rooms: readonly string[];
449
+ conversations: boolean;
450
+ };
449
451
  export type RoomStream = {
450
- hold(rooms: readonly HeldRoom[]): void;
452
+ hold(rooms: readonly HeldRoom[], demand: AcquiredDemand | null): void;
451
453
  reopen(): void;
452
454
  published(locator: string, roomVersion: string): void;
453
455
  observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
@@ -7,6 +7,7 @@ import type { BinaryAnswer, CallResult, HistoryAnswer, Offline, QueueEntry } fro
7
7
  import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
8
8
  import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
9
9
  import type { SearchRequest, SearchResult } from './search.js';
10
+ import type { Readiness } from './readiness.js';
10
11
  import type { SyncStatus } from './status.js';
11
12
  import { type RuntimePort } from './wire.js';
12
13
  export type MdRuntimeClient = {
@@ -52,9 +53,11 @@ export type MdRuntimeClient = {
52
53
  reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
53
54
  log(): Promise<string>;
54
55
  persistence(): Promise<boolean>;
56
+ retry(): Promise<void>;
55
57
  observe: {
56
58
  (topic: 'deployment-facts'): Promise<Observation<unknown>>;
57
59
  (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
60
+ (topic: 'readiness'): Promise<Observation<Readiness>>;
58
61
  (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
59
62
  (topic: 'storage-loss'): Promise<Observation<string | null>>;
60
63
  (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
@@ -75,4 +78,5 @@ export type MdRuntimeClient = {
75
78
  export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
76
79
  export declare function inTurn(client: MdRuntimeClient, work: () => Promise<void>): Promise<void>;
77
80
  export type { Observation } from './observation.js';
78
- export type { RuntimePort } from './wire.js';
81
+ export type { Open } from './open.js';
82
+ export { unanswered, type RuntimePort, type WireMember } from './wire.js';
@@ -13,6 +13,8 @@ import { type SaveRefusal } from './save.js';
13
13
  import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
14
14
  import { type SyncStatus } from './status.js';
15
15
  import { type RuntimeShell } from './durability.js';
16
+ import { type RuntimeDemand } from './acquisition.js';
17
+ import { type CapacityCause, type CodeAvailability, type Persistence, type Readiness, type SearchObligation } from './readiness.js';
16
18
  import { type NarrowedView, type PortReach, type RuntimeView } from './reach.js';
17
19
  export type AppTypedSelection = {
18
20
  roots: readonly string[];
@@ -99,8 +101,10 @@ export type MdRuntime = {
99
101
  reached(locator: string, roomVersion: string, path?: string): boolean;
100
102
  log(): string;
101
103
  persistence(): boolean;
104
+ retry(): Promise<void>;
102
105
  observe: {
103
106
  (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
107
+ (topic: 'readiness'): Promise<Observation<Readiness>>;
104
108
  (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
105
109
  (topic: 'storage-loss'): Promise<Observation<string | null>>;
106
110
  (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
@@ -117,11 +121,19 @@ export type MdRuntime = {
117
121
  };
118
122
  reauthorize(): Promise<void>;
119
123
  };
120
- export type RuntimeTopic = 'rooms' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
124
+ export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
125
+ export type ReadinessPort = {
126
+ readonly target: string;
127
+ readonly code: CodeAvailability;
128
+ readonly capacity: CapacityCause | null;
129
+ readonly search: SearchObligation;
130
+ };
121
131
  export type ComposedRuntime = RuntimeView & {
122
132
  stop(): Promise<void>;
123
133
  lose(locators: readonly string[]): Promise<void>;
124
- within(reach: PortReach | null): NarrowedView;
134
+ acquire(demand: RuntimeDemand): void;
135
+ persisted(answer: Persistence): void;
136
+ within(reach: PortReach | null, port: ReadinessPort): NarrowedView;
125
137
  };
126
138
  export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
127
139
  export {};
@@ -86,6 +86,7 @@ export type ConversationStore = {
86
86
  catchUp(progress: CycleProgress): Promise<void>;
87
87
  resend(progress: CycleProgress): Promise<void>;
88
88
  current(): boolean;
89
+ known(): boolean;
89
90
  reconnected(): void;
90
91
  reopened(): void;
91
92
  watch(conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
@@ -99,4 +100,5 @@ export type ConversationStore = {
99
100
  };
100
101
  export declare function unheldView(conversation: string): ConversationView;
101
102
  export declare const SESSION_STARTED = "Session started";
103
+ export declare function newChat(agent: string): string;
102
104
  export declare function createConversationStore(deps: ConversationDependencies): ConversationStore;
@@ -1,8 +1,14 @@
1
+ import type { Persistence } from './readiness.js';
2
+ export type StorageEstimate = {
3
+ readonly usage: number;
4
+ readonly quota: number;
5
+ };
1
6
  export type RuntimeShell = {
2
- persistentStorage: boolean;
7
+ persistence: Persistence;
3
8
  generation: string | null;
4
9
  keepGeneration(value: string): void | Promise<void>;
5
10
  dropGeneration(): void | Promise<void>;
11
+ estimate?(): Promise<StorageEstimate | null>;
6
12
  };
7
13
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
8
14
  export declare function nextGeneration(stored: string | null, reported: string | null): string;
@@ -29,12 +29,13 @@ export type ModelState = {
29
29
  types: VerifiedModel['types'];
30
30
  };
31
31
  export type TypesResult = {
32
- status: 'unavailable';
32
+ status: Open<'unavailable'>;
33
33
  reason: ModelUnavailableReason;
34
+ types: null;
34
35
  schema?: string | null;
35
36
  revision?: string | null;
36
37
  } | {
37
- status: 'current' | 'cached';
38
+ status: Open<'current' | 'cached'>;
38
39
  identity: string;
39
40
  version: string;
40
41
  verifiedWith: ModelIdentity;
@@ -1,6 +1,7 @@
1
1
  import { type Definition } from '../mdmodel/index.js';
2
2
  import type { HeadChange } from './adapter.js';
3
3
  import type { BinaryFileRecord } from './binary.js';
4
+ import type { Open } from './open.js';
4
5
  export type Value = string | number | boolean | null;
5
6
  export type Predicate = Value | {
6
7
  $eq: Value;
@@ -110,7 +111,7 @@ export type QueryCoverage = {
110
111
  indexes: readonly string[];
111
112
  overlay: readonly string[];
112
113
  };
113
- export type Awaits = 'acquisition' | 'preparation' | 'index';
114
+ export type Awaits = Open<'acquisition' | 'preparation' | 'index'>;
114
115
  export type PendingRoom = {
115
116
  room: string;
116
117
  awaits: Awaits;
@@ -1,7 +1,8 @@
1
1
  import type { ReferrerScope } from './adapter.js';
2
- import type { MdRuntime, RuntimeTopic } from './connection.js';
2
+ import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
3
3
  import type { Plan, PlanReach, QueryResult } from './query.js';
4
- import type { SearchResult } from './search.js';
4
+ import type { Readiness } from './readiness.js';
5
+ import { type SearchResult } from './search.js';
5
6
  export type ReachedDocument = {
6
7
  readonly room: string;
7
8
  readonly path: string;
@@ -19,12 +20,14 @@ export type RuntimeView = {
19
20
  };
20
21
  export type NarrowedView = RuntimeView & {
21
22
  narrow(reach: PortReach | null): void;
23
+ facts(port: ReadinessPort): void;
22
24
  };
23
25
  export type Reachable = RuntimeView & {
24
26
  plan(input: unknown, reach: PortReach | null): Plan;
25
27
  query(plan: Plan): Promise<QueryResult>;
26
28
  watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
27
29
  search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
30
+ watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
28
31
  referrerScope(referrer: unknown): ReferrerScope | null;
29
32
  };
30
33
  export declare function holds(reach: PortReach | null, room: string): boolean;
@@ -38,4 +41,4 @@ export declare function governs(reach: PortReach | null, room: {
38
41
  readonly selection: boolean;
39
42
  };
40
43
  export declare function planReach(reach: PortReach | null): PlanReach | null;
41
- export declare function narrowed(runtime: Reachable, given: PortReach | null): NarrowedView;
44
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
@@ -0,0 +1,52 @@
1
+ import type { Open } from './open.js';
2
+ export type CodeAvailability = Open<'stored' | 'absent'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'indexing' | 'refused' | 'unadmitted'>;
4
+ export type RoomCoverage = {
5
+ readonly room: string;
6
+ readonly state: RoomPreparation;
7
+ };
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'indexing' | 'undeclared'>;
9
+ export type SearchObligation = Open<'required' | 'unused'>;
10
+ export type TargetCoverage = {
11
+ readonly complete: boolean;
12
+ readonly listed: boolean;
13
+ readonly rooms: readonly RoomCoverage[];
14
+ readonly conversations: ConversationCoverage;
15
+ readonly search: SearchObligation;
16
+ };
17
+ export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
18
+ export type Durability = Open<'persistent' | 'best-effort'>;
19
+ export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
20
+ export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
21
+ export type CapacityCause = {
22
+ readonly cause: Open<'insufficient-space' | 'quota-exceeded'>;
23
+ readonly needed: number | null;
24
+ readonly available: number | null;
25
+ };
26
+ export type RefusedRoom = {
27
+ readonly room: string;
28
+ readonly file: string;
29
+ readonly rule: string;
30
+ readonly location: string | null;
31
+ };
32
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'refused' | 'ready' | 'lost'>;
33
+ export type Readiness = {
34
+ readonly status: ReadinessStatus;
35
+ readonly ready: boolean;
36
+ readonly usable: boolean;
37
+ readonly code: CodeAvailability;
38
+ readonly coverage: TargetCoverage;
39
+ readonly durability: Durability;
40
+ readonly persistence: Persistence;
41
+ readonly connection: ConnectionAvailability;
42
+ readonly house: HouseOutcome;
43
+ readonly capacity: CapacityCause | null;
44
+ readonly refused: readonly RefusedRoom[];
45
+ readonly lost: boolean;
46
+ };
47
+ export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
48
+ readonly coverage: Omit<TargetCoverage, 'complete'>;
49
+ readonly established: boolean;
50
+ };
51
+ export declare const SETTLED_ROOMS: ReadonlySet<string>;
52
+ export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -87,7 +87,7 @@ type ChangedUnderneath = {
87
87
  readonly file?: string | null;
88
88
  };
89
89
  export type ReturnReason = ProviderRefusal & {
90
- readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn';
90
+ readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
91
91
  };
92
92
  export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
93
93
  export type RoomDraft = {
@@ -1,3 +1,4 @@
1
+ import type { ProviderRefusal } from './adapter.js';
1
2
  import type { ChangeSet } from './change-set.js';
2
3
  import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
3
4
  import type { Open } from './open.js';
@@ -29,18 +30,23 @@ export type SearchCoverage = {
29
30
  };
30
31
  export type PendingConversation = {
31
32
  conversation: string;
32
- awaits: 'index';
33
- };
34
- export type SearchPending = {
35
- pending: readonly (PendingRoom | PendingConversation)[];
33
+ awaits: Open<'index'>;
36
34
  };
37
35
  export type SearchHits = {
38
36
  documents: readonly DocumentHit[];
39
37
  messages: readonly MessageHit[];
40
38
  };
39
+ export type SearchPending = SearchHits & {
40
+ pending: readonly (PendingRoom | PendingConversation)[];
41
+ coverage: SearchCoverage;
42
+ };
43
+ export type SearchUndeclared = ProviderRefusal & {
44
+ kind: 'undeclared';
45
+ };
41
46
  export type SearchResult = (SearchHits & {
42
47
  coverage: SearchCoverage;
43
- }) | SearchPending;
48
+ }) | SearchPending | SearchUndeclared;
49
+ export declare function undeclaredSearch(): SearchUndeclared;
44
50
  export type SearchedDocument = {
45
51
  room: string;
46
52
  path: string;
@@ -77,7 +83,7 @@ export type SearchIndex = {
77
83
  search(plan: SearchPlan, documents: readonly {
78
84
  room: string;
79
85
  path: string;
80
- }[] | null, conversations: readonly string[]): SearchHits;
86
+ }[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null): SearchHits;
81
87
  };
82
88
  export declare function searchPlanOf(input: unknown): SearchPlan;
83
89
  export declare function createSearchIndex(source: SearchSource): SearchIndex;
@@ -1,9 +1,13 @@
1
1
  import type { Open } from './open.js';
2
+ import type { ProviderRefusal } from './adapter.js';
2
3
  import type { ReturnReason } from './room-draft.js';
3
4
  export type AttentionEntry = {
4
5
  room: string;
5
6
  path: string;
6
7
  returned: ReturnReason;
8
+ } | {
9
+ room: string;
10
+ refusal: ProviderRefusal;
7
11
  };
8
12
  export type SyncStatus = {
9
13
  state: Open<'pending' | 'syncing' | 'synced'>;
@@ -46,6 +46,9 @@ export type PendingState = {
46
46
  readonly upload?: unknown;
47
47
  readonly accepted?: string;
48
48
  };
49
+ export type TargetRecord = {
50
+ established: boolean;
51
+ };
49
52
  export type QueueRecord = {
50
53
  locator: string;
51
54
  pending: readonly {
@@ -82,6 +85,7 @@ export type ChatDraftRecord = {
82
85
  files: readonly ChatDraftFile[];
83
86
  revision: string;
84
87
  submitted?: readonly ChatSubmission[];
88
+ moves?: readonly string[];
85
89
  };
86
90
  export type RecordWrite = {
87
91
  next: ReplicaRecord;
@@ -107,6 +111,8 @@ export type RuntimeStore = {
107
111
  declare(limits: readonly ProviderLimit[], capabilities: readonly Capability[]): Promise<void>;
108
112
  member(): Promise<Member | null>;
109
113
  keepMember(member: Member | null): Promise<void>;
114
+ targets(): Promise<Readonly<Record<string, TargetRecord>>>;
115
+ keepTargets(targets: Readonly<Record<string, TargetRecord>>): Promise<void>;
110
116
  queues(): Promise<readonly QueueRecord[]>;
111
117
  submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
112
118
  accept(locator: string, id: string, roomVersion: string): Promise<void>;
@@ -122,7 +128,7 @@ export type RuntimeStore = {
122
128
  turnArrived(conversation: string, turn: string): Promise<boolean>;
123
129
  dropConversations(conversations: readonly string[]): Promise<void>;
124
130
  chatDrafts(): Promise<readonly ChatDraftRecord[]>;
125
- keepChatDraft(record: ChatDraftRecord): Promise<void>;
131
+ keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
126
132
  dropChatDraft(conversation: string): Promise<void>;
127
133
  keepRoomDraft(record: RoomDraftRecord): Promise<void>;
128
134
  discardRoomDraft(locator: string, path: string): Promise<void>;
@@ -149,4 +155,5 @@ export declare function authoredBy(holder: string): Promise<boolean>;
149
155
  export declare function authoredBinding(): Promise<string | null>;
150
156
  export declare function bindAuthored(binding: string): Promise<void>;
151
157
  export declare function removeRuntimeStore(holder?: string): Promise<boolean>;
158
+ export declare function openDatabase(name: string, version: number, upgrade: (opening: IDBOpenDBRequest, oldVersion: number) => void): Promise<IDBDatabase>;
152
159
  export declare function openRuntimeStore(fenced: (locator: string) => boolean): Promise<RuntimeStore>;
@@ -8,40 +8,140 @@ export type RuntimePort = {
8
8
  start(): void;
9
9
  };
10
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
+ };
11
16
  declare const MEMBERS: {
12
- readonly rooms: 'within';
13
- readonly query: 'within';
14
- readonly search: 'within';
15
- readonly types: 'within';
16
- readonly save: 'within';
17
- readonly history: 'within';
18
- readonly 'binaryFile.read': 'within';
19
- readonly 'binaryFile.readReference': 'within';
20
- readonly call: 'actions';
21
- readonly reached: 'within';
22
- readonly log: 'whole';
23
- readonly persistence: 'runtime';
24
- readonly reauthorize: 'runtime';
25
- readonly 'roomDraft.list': 'within';
26
- readonly 'roomDraft.read': 'within';
27
- readonly 'roomDraft.write': 'within';
28
- readonly 'roomDraft.discard': 'within';
29
- readonly 'presentation.read': 'app';
30
- readonly 'presentation.write': 'app';
31
- readonly 'conversation.list': 'within';
32
- readonly 'conversation.read': 'within';
33
- readonly 'conversation.create': 'within';
34
- readonly 'conversation.send': 'within';
35
- readonly 'conversation.answer': 'within';
36
- readonly 'conversation.interrupt': 'within';
37
- readonly 'conversation.kill': 'within';
38
- readonly 'conversation.cancel': 'within';
39
- readonly 'conversation.delete': 'within';
40
- readonly 'chatDraft.write': 'within';
41
- readonly 'chatDraft.discard': 'within';
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
+ };
42
141
  };
43
142
  declare const TOPICS: {
44
143
  readonly rooms: 'within';
144
+ readonly readiness: 'within';
45
145
  readonly 'connection-refusal': 'runtime';
46
146
  readonly 'storage-loss': 'runtime';
47
147
  readonly 'deployment-facts': 'runtime';
@@ -56,8 +156,8 @@ declare const TOPICS: {
56
156
  readonly conversations: 'within';
57
157
  readonly agents: 'within';
58
158
  };
59
- export declare const WIRE_REACH: {
60
- readonly members: Readonly<Record<string, WireReach>>;
159
+ export declare const WIRE: {
160
+ readonly members: Readonly<Record<string, WireCall>>;
61
161
  readonly topics: Readonly<Record<string, WireReach>>;
62
162
  };
63
163
  export type WireMember = keyof typeof MEMBERS;
@@ -95,6 +195,10 @@ export type WireAnswer = {
95
195
  } | {
96
196
  kind: 'ended';
97
197
  };
198
+ export declare function unanswered(call: {
199
+ readonly id: number;
200
+ readonly member: WireMember;
201
+ }): WireAnswer | null;
98
202
  export declare const AUTHORIZATION_ENDED = "the host authorization ended";
99
203
  export declare const PORT_CLOSED = "the port closed";
100
204
  export declare function request(message: unknown): WireRequest | null;
@@ -1,5 +1,5 @@
1
1
  import type { MdRuntimeClient } from './mdruntime/client.js';
2
- import type { HouseAnalyticsChoice, HouseAppMessage, HouseExternalAnswer, HouseExternalRequest, HouseNavigationMode, HouseRefusal, HouseSourceDownload, HouseSourceTop, HouseStatus, HouseTab } from './index.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,6 +15,9 @@ 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;
package/dist/test-host.js CHANGED
@@ -57,6 +57,7 @@ export function createHouseBridgeTestHost(options = {}) {
57
57
  let published = options.status ?? null;
58
58
  let shown = null;
59
59
  let seen = null;
60
+ let cooperation = null;
60
61
  let attached = () => { };
61
62
  const runtime = new Promise((resolve) => {
62
63
  attached = resolve;
@@ -144,7 +145,19 @@ export function createHouseBridgeTestHost(options = {}) {
144
145
  consents.push(choice);
145
146
  publish({ ...published, analytics: { measures: true, choice } });
146
147
  },
148
+ cooperate(given) {
149
+ cooperation = given;
150
+ return () => {
151
+ if (cooperation === given)
152
+ cooperation = null;
153
+ };
154
+ },
147
155
  };
156
+ function cooperating() {
157
+ if (cooperation === null)
158
+ throw new Error('the App registered no cooperation');
159
+ return cooperation;
160
+ }
148
161
  Object.defineProperty(globalThis, 'houseBridge', { value: bridge, configurable: true });
149
162
  if (published !== null)
150
163
  publish(published);
@@ -169,5 +182,19 @@ export function createHouseBridgeTestHost(options = {}) {
169
182
  attachRuntime(client) {
170
183
  attached(client);
171
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
+ },
172
199
  };
173
200
  }
package/docs/families.md CHANGED
@@ -45,6 +45,15 @@
45
45
  The App reports the visitor's choice with `analyticsConsent('accept')` or
46
46
  `analyticsConsent('decline')`; the shell hands it to House's analytics loader, and
47
47
  the choice never reaches House.
48
+ - **Handoff** - when House hands its runtime over to a newer build, the App keeps
49
+ running, its `runtime` client and observations included: a call it makes
50
+ meanwhile waits for the newer runtime, however long that takes, and is
51
+ answered once, by it; each observation goes on with the newer runtime's
52
+ values; and the status and the address arrive again. A runtime that ended
53
+ before answering has its reads answered by the next one; since it may have
54
+ applied any other call, an act on House is answered the outcome
55
+ `transport-uncertainty`, and every other call, a Save or a draft write among
56
+ them, fails with the retryable code `transport-uncertainty`.
48
57
  - **Site image read** - given a Published Room and an original attachment
49
58
  reference, it answers the web copy's path and metadata, or `null` when no
50
59
  copy exists. The original bytes never cross this bridge at a Site.
@@ -84,6 +93,31 @@
84
93
  after its latest release, as a JPEG `Blob`, or `null` when House holds none
85
94
  or does not answer. A Site's own renderer reads none.
86
95
 
96
+ - **Cooperation** - `cooperate({ checkpoint, persist, capture, restore,
97
+ ready, settle })` lets House activate a newer release of the App while it
98
+ runs, keeping the User's task; the function it returns withdraws it.
99
+ Register it in the entry script, before the first draw, or House treats the
100
+ page as not cooperating and the newer release waits for the App's next
101
+ open. When a newer release is stored, House calls `checkpoint()`, which
102
+ resolves at the App's next safe checkpoint and may never resolve, then
103
+ `persist()`, which makes authored work durable, then `capture()`, which
104
+ answers the meaningful task the App owns, such as the selected record,
105
+ filters, cursor, selection and scroll position, as JSON of at most 65,536
106
+ characters; House keeps the address itself. In the newer release House
107
+ calls `restore(task)` once its document has drawn, so the scroll position
108
+ and focus it sets hold, or `restore(null)` when it opens the release without
109
+ a task, then `ready()`, the App's own check that its local data and
110
+ capabilities work, and finally `settle('committed')` once the release is
111
+ active or `settle('abandoned')` when House returns to the release before
112
+ it, restoring the same task there. A release House opens already active is
113
+ settled `'committed'` at once, after `restore(task)` when House hands it a
114
+ task, and a cooperation registered after House settled is settled at its
115
+ registration. Until `settle('committed')` House fails the release's outside
116
+ calls at once, as offline, those of the workers it starts included, and
117
+ refuses its Saves, write acts and external calls with the retryable code
118
+ `house_trial_withheld`, so a start-up effect is not repeated; run start-up
119
+ effects after `settle('committed')`.
120
+
87
121
  ## The test host
88
122
 
89
123
  `createHouseBridgeTestHost(options)` plays House in one page: it installs a
@@ -106,4 +140,7 @@ given by Site identifier, answers every `install()` `'manual'`, as a browser
106
140
  with no install prompt does, answers every `notifications()` `'unavailable'`,
107
141
  as a browser without push does, settles every `setBadge`, delivers each App
108
142
  message `message({ from, body })` plays, and hands `bridge.runtime` the MD
109
- Runtime client `attachRuntime(client)` gives it.
143
+ Runtime client `attachRuntime(client)` gives it. `checkpoint()` runs the
144
+ registered cooperation's checkpoint, persist and capture and answers the task,
145
+ `restore(task)` runs its restore and answers its readiness check, and
146
+ `settle(activation)` hands it the outcome.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/app-bridge",
3
- "version": "0.1.0-cfb240c3fb89d",
3
+ "version": "0.1.0-cfefe363de456",
4
4
  "description": "Types of the agents.house App bridge House hands every App: navigation, the tab title and icon, ceremonies, installation, notifications and the icon badge, status, Site image reads, App release code, App and Site screenshot reads, and App messages, with an accessor and an in-page test host.",
5
5
  "license": "MIT",
6
6
  "type": "module",