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

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 +4 -2
  2. package/dist/calls.d.ts +953 -0
  3. package/dist/calls.js +1 -0
  4. package/dist/index.d.ts +32 -11
  5. package/dist/mdmodel/blocks.d.ts +10 -0
  6. package/dist/mdmodel/condition.d.ts +148 -0
  7. package/dist/mdmodel/definition.d.ts +79 -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 +21 -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 +8 -0
  18. package/dist/mdmodel/version.d.ts +1 -0
  19. package/dist/mdmodel/yaml.d.ts +55 -0
  20. package/dist/mdruntime/adapter.d.ts +492 -0
  21. package/dist/mdruntime/binary.d.ts +22 -0
  22. package/dist/mdruntime/change-set.d.ts +34 -0
  23. package/dist/mdruntime/change.d.ts +88 -0
  24. package/dist/mdruntime/client.d.ts +86 -0
  25. package/dist/mdruntime/collection.d.ts +39 -0
  26. package/dist/mdruntime/connection.d.ts +146 -0
  27. package/dist/mdruntime/conversation.d.ts +110 -0
  28. package/dist/mdruntime/durability.d.ts +14 -0
  29. package/dist/mdruntime/failure.d.ts +12 -0
  30. package/dist/mdruntime/file.d.ts +19 -0
  31. package/dist/mdruntime/model.d.ts +57 -0
  32. package/dist/mdruntime/observation.d.ts +31 -0
  33. package/dist/mdruntime/open.d.ts +1 -0
  34. package/dist/mdruntime/outcome.d.ts +52 -0
  35. package/dist/mdruntime/overlay.d.ts +28 -0
  36. package/dist/mdruntime/query.d.ts +273 -0
  37. package/dist/mdruntime/reach.d.ts +44 -0
  38. package/dist/mdruntime/readiness.d.ts +52 -0
  39. package/dist/mdruntime/recovery.d.ts +24 -0
  40. package/dist/mdruntime/replica.d.ts +50 -0
  41. package/dist/mdruntime/room-draft.d.ts +155 -0
  42. package/dist/mdruntime/rows.d.ts +38 -0
  43. package/dist/mdruntime/save.d.ts +65 -0
  44. package/dist/mdruntime/search.d.ts +104 -0
  45. package/dist/mdruntime/seed.d.ts +15 -0
  46. package/dist/mdruntime/shared.d.ts +13 -0
  47. package/dist/mdruntime/status.d.ts +26 -0
  48. package/dist/mdruntime/store.d.ts +174 -0
  49. package/dist/mdruntime/transfer.d.ts +9 -0
  50. package/dist/mdruntime/turn.d.ts +8 -0
  51. package/dist/mdruntime/wire.d.ts +222 -0
  52. package/dist/test-host.d.ts +5 -5
  53. package/dist/test-host.js +57 -22
  54. package/docs/families.md +49 -7
  55. package/package.json +1 -4
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 });
@@ -73,13 +99,10 @@ export function createHouseBridgeTestHost(options = {}) {
73
99
  });
74
100
  }
75
101
  const bridge = {
76
- runtime,
102
+ runtime: 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
  }
package/docs/families.md CHANGED
@@ -12,7 +12,9 @@
12
12
  purpose-bound authenticated pages. The shell navigates only to a same-origin
13
13
  absolute path, carries its current address as the return target, and the page
14
14
  returns there when it completes. An App names an address House gave it in a
15
- reading and composes none.
15
+ reading and composes one only for `/bind/<app_ref>`, where the User binds
16
+ its Rooms and connects its account slots, with `?slot=<name>` to open at one
17
+ slot.
16
18
  - **Installation** - `install()` offers the page as a Home-screen app. Where the
17
19
  browser has an install prompt ready the shell shows it and the call resolves
18
20
  `'accepted'` or `'dismissed'` with the User's choice, spending that prompt;
@@ -39,10 +41,21 @@
39
41
  whether the page measures and the visitor's stored analytics choice, and
40
42
  `serviceMode`: `open`, `write-halted` while House refuses writes, so the
41
43
  App can stop retrying them, or `null` while the runtime holds no House
42
- connection. Every status field is camelCase.
44
+ connection. Every status field is camelCase. `onStatus(listener)` and
45
+ `onAddress(listener)` hand a listener the status and the address the bridge
46
+ already holds, then each change.
43
47
  The App reports the visitor's choice with `analyticsConsent('accept')` or
44
48
  `analyticsConsent('decline')`; the shell hands it to House's analytics loader, and
45
49
  the choice never reaches House.
50
+ - **Handoff** - when House hands its runtime over to a newer build, the App keeps
51
+ running, its `runtime` client and observations included: a call it makes
52
+ meanwhile waits for the newer runtime, however long that takes, and is
53
+ answered once, by it; each observation goes on with the newer runtime's
54
+ values; and the status and the address arrive again. A runtime that ended
55
+ before answering has its reads answered by the next one; since it may have
56
+ applied any other call, an act on House is answered the outcome
57
+ `transport-uncertainty`, and every other call, a Save or a draft write among
58
+ them, fails with the retryable code `transport-uncertainty`.
46
59
  - **Site image read** - given a Published Room and an original attachment
47
60
  reference, it answers the web copy's path and metadata, or `null` when no
48
61
  copy exists. The original bytes never cross this bridge at a Site.
@@ -56,14 +69,15 @@
56
69
  refusal is House's `{ error: { code, retryable } }`, `app_release_not_found` for an
57
70
  App with no release; a read House does not answer, or one that outlived
58
71
  the browser's signed-in User, is `null`.
59
- - **External calls** - `callExternal({ url, method, headers, body, slot })`
72
+ - **External calls** - `callExternal({ url, method, headers, body, slot, room_ref })`
60
73
  has House's server send an HTTPS request to one of the release's declared
61
74
  external origins and resolves with the service's `status`, `headers` and its
62
75
  body as `body` text or `body_base64`, or a refusal as House's
63
76
  `{ error: { code, retryable } }`, or `null` when House does not answer. House fills in the
64
- App and its running release; naming an account slot places the key of the
65
- account the User connected to it, which the App never sees, and naming none
66
- sends no key. A Site's call names no slot, and the House panel names an
77
+ App and its running release; naming an account slot and one of the App's
78
+ bound Rooms places the key of the account that Room connects to the slot,
79
+ when the User holds one of the account's roles there, which the App never
80
+ sees, and naming neither sends no key. A Site's call names no slot, and the House panel names an
67
81
  `account` instead. `body_base64` replaces `body` for bytes.
68
82
  - **App messages** - `messages(listener)` hands the listener each message
69
83
  another holder of this App sends to this User's running copies, as `from`,
@@ -82,6 +96,31 @@
82
96
  after its latest release, as a JPEG `Blob`, or `null` when House holds none
83
97
  or does not answer. A Site's own renderer reads none.
84
98
 
99
+ - **Cooperation** - `cooperate({ checkpoint, persist, capture, restore,
100
+ ready, settle })` lets House activate a newer release of the App while it
101
+ runs, keeping the User's task; the function it returns withdraws it.
102
+ Register it in the entry script, before the first draw, or House treats the
103
+ page as not cooperating and the newer release waits for the App's next
104
+ open. When a newer release is stored, House calls `checkpoint()`, which
105
+ resolves at the App's next safe checkpoint and may never resolve, then
106
+ `persist()`, which makes authored work durable, then `capture()`, which
107
+ answers the meaningful task the App owns, such as the selected record,
108
+ filters, cursor, selection and scroll position, as JSON of at most 65,536
109
+ characters; House keeps the address itself. In the newer release House
110
+ calls `restore(task)` once its document has drawn, so the scroll position
111
+ and focus it sets hold, or `restore(null)` when it opens the release without
112
+ a task, then `ready()`, the App's own check that its local data and
113
+ capabilities work, and finally `settle('committed')` once the release is
114
+ active or `settle('abandoned')` when House returns to the release before
115
+ it, restoring the same task there. A release House opens already active is
116
+ settled `'committed'` at once, after `restore(task)` when House hands it a
117
+ task, and a cooperation registered after House settled is settled at its
118
+ registration. Until `settle('committed')` House fails the release's outside
119
+ calls at once, as offline, those of the workers it starts included, and
120
+ refuses its Saves, write acts and external calls with the retryable code
121
+ `house_trial_withheld`, so a start-up effect is not repeated; run start-up
122
+ effects after `settle('committed')`.
123
+
85
124
  ## The test host
86
125
 
87
126
  `createHouseBridgeTestHost(options)` plays House in one page: it installs a
@@ -104,4 +143,7 @@ given by Site identifier, answers every `install()` `'manual'`, as a browser
104
143
  with no install prompt does, answers every `notifications()` `'unavailable'`,
105
144
  as a browser without push does, settles every `setBadge`, delivers each App
106
145
  message `message({ from, body })` plays, and hands `bridge.runtime` the MD
107
- Runtime client `attachRuntime(client)` gives it.
146
+ Runtime client `attachRuntime(client)` gives it. `checkpoint()` runs the
147
+ registered cooperation's checkpoint, persist and capture and answers the task,
148
+ `restore(task)` runs its restore and answers its readiness check, and
149
+ `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-c58a055eeaa71",
3
+ "version": "0.1.0-c599cdbcc172a",
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",
@@ -18,9 +18,6 @@
18
18
  "default": "./dist/test-host.js"
19
19
  }
20
20
  },
21
- "dependencies": {
22
- "@agentshouse/mdruntime": "0.1.0-c967d1ca66fee"
23
- },
24
21
  "files": [
25
22
  "dist",
26
23
  "docs",