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

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 (64) hide show
  1. package/README.md +11 -9
  2. package/dist/index.d.ts +867 -5
  3. package/dist/mdmodel/blocks.d.ts +10 -0
  4. package/dist/mdmodel/definition.d.ts +81 -0
  5. package/dist/mdmodel/divide.d.ts +2 -0
  6. package/dist/mdmodel/document.d.ts +15 -0
  7. package/dist/mdmodel/event.d.ts +77 -0
  8. package/dist/mdmodel/facts.d.ts +14 -0
  9. package/dist/mdmodel/fields.d.ts +5 -0
  10. package/dist/mdmodel/index.d.ts +32 -0
  11. package/dist/mdmodel/kinds.d.ts +18 -0
  12. package/dist/mdmodel/links.d.ts +28 -0
  13. package/dist/mdmodel/paths.d.ts +25 -0
  14. package/dist/mdmodel/profile.d.ts +5 -0
  15. package/dist/mdmodel/project.d.ts +21 -0
  16. package/dist/mdmodel/query/language.d.ts +222 -0
  17. package/dist/mdmodel/query/match.d.ts +13 -0
  18. package/dist/mdmodel/query/rows.d.ts +31 -0
  19. package/dist/mdmodel/query/sql.d.ts +38 -0
  20. package/dist/mdmodel/references.d.ts +3 -0
  21. package/dist/mdmodel/reserved.d.ts +4 -0
  22. package/dist/mdmodel/types.d.ts +174 -0
  23. package/dist/mdmodel/validate.d.ts +32 -0
  24. package/dist/mdmodel/version.d.ts +1 -0
  25. package/dist/mdmodel/yaml.d.ts +55 -0
  26. package/dist/mdruntime/adapter.d.ts +546 -0
  27. package/dist/mdruntime/binary.d.ts +17 -0
  28. package/dist/mdruntime/chain.d.ts +11 -0
  29. package/dist/mdruntime/change-set.d.ts +27 -0
  30. package/dist/mdruntime/change.d.ts +118 -0
  31. package/dist/mdruntime/client.d.ts +94 -0
  32. package/dist/mdruntime/collection.d.ts +28 -0
  33. package/dist/mdruntime/compile.d.ts +10 -0
  34. package/dist/mdruntime/connection.d.ts +154 -0
  35. package/dist/mdruntime/conversation.d.ts +119 -0
  36. package/dist/mdruntime/durability.d.ts +17 -0
  37. package/dist/mdruntime/failure.d.ts +12 -0
  38. package/dist/mdruntime/identity.d.ts +5 -0
  39. package/dist/mdruntime/media.d.ts +7 -0
  40. package/dist/mdruntime/messages.d.ts +27 -0
  41. package/dist/mdruntime/model.d.ts +57 -0
  42. package/dist/mdruntime/observation.d.ts +44 -0
  43. package/dist/mdruntime/open.d.ts +1 -0
  44. package/dist/mdruntime/opened.d.ts +21 -0
  45. package/dist/mdruntime/outcome.d.ts +84 -0
  46. package/dist/mdruntime/overlay.d.ts +24 -0
  47. package/dist/mdruntime/query.d.ts +78 -0
  48. package/dist/mdruntime/reach.d.ts +53 -0
  49. package/dist/mdruntime/readiness.d.ts +49 -0
  50. package/dist/mdruntime/recovery.d.ts +25 -0
  51. package/dist/mdruntime/replica.d.ts +70 -0
  52. package/dist/mdruntime/room-draft.d.ts +174 -0
  53. package/dist/mdruntime/save.d.ts +102 -0
  54. package/dist/mdruntime/search.d.ts +21 -0
  55. package/dist/mdruntime/seed.d.ts +15 -0
  56. package/dist/mdruntime/status.d.ts +27 -0
  57. package/dist/mdruntime/store.d.ts +151 -0
  58. package/dist/mdruntime/stored.d.ts +128 -0
  59. package/dist/mdruntime/tables.d.ts +326 -0
  60. package/dist/mdruntime/wire.d.ts +243 -0
  61. package/dist/test-host.d.ts +8 -2
  62. package/dist/test-host.js +48 -11
  63. package/docs/families.md +69 -13
  64. package/package.json +8 -6
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,12 +29,28 @@ 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 = [];
35
50
  const consents = [];
36
51
  const tabs = [];
37
52
  const externalCalls = [];
53
+ const chats = [];
38
54
  const addressListeners = new Set();
39
55
  const statusListeners = new Set();
40
56
  const messageListeners = new Set();
@@ -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,24 @@ export function createHouseBridgeTestHost(options = {}) {
73
99
  });
74
100
  }
75
101
  const bridge = {
76
- runtime,
102
+ runtime: runtime,
103
+ chat: {
104
+ mount(element, options = {}) {
105
+ const chat = { element, options, mounted: true };
106
+ chats.push(chat);
107
+ return Promise.resolve({
108
+ update(next) {
109
+ chat.options = next;
110
+ },
111
+ unmount() {
112
+ chat.mounted = false;
113
+ },
114
+ });
115
+ },
116
+ },
77
117
  address: () => shown,
78
118
  onAddress(listener) {
79
- addressListeners.add(listener);
80
- return () => {
81
- addressListeners.delete(listener);
82
- };
119
+ return followHeld(addressListeners, listener, () => shown);
83
120
  },
84
121
  push: (asked) => navigate('push', asked),
85
122
  replace: (asked) => navigate('replace', asked),
@@ -92,6 +129,7 @@ export function createHouseBridgeTestHost(options = {}) {
92
129
  },
93
130
  install: () => Promise.resolve('manual'),
94
131
  notifications: () => Promise.resolve('unavailable'),
132
+ telegram: () => Promise.resolve({ state: 'unavailable', name: null, username: null }),
95
133
  setBadge: () => Promise.resolve(),
96
134
  setTab(tab) {
97
135
  tabs.push(tab);
@@ -106,10 +144,7 @@ export function createHouseBridgeTestHost(options = {}) {
106
144
  readSiteScreenshot: (site) => Promise.resolve(options.siteScreenshots?.[site] ?? null),
107
145
  status: () => seen,
108
146
  onStatus(listener) {
109
- statusListeners.add(listener);
110
- return () => {
111
- statusListeners.delete(listener);
112
- };
147
+ return followHeld(statusListeners, listener, () => seen);
113
148
  },
114
149
  messages(listener) {
115
150
  messageListeners.add(listener);
@@ -125,6 +160,7 @@ export function createHouseBridgeTestHost(options = {}) {
125
160
  consents.push(choice);
126
161
  publish({ ...published, analytics: { measures: true, choice } });
127
162
  },
163
+ cooperate: () => () => { },
128
164
  };
129
165
  Object.defineProperty(globalThis, 'houseBridge', { value: bridge, configurable: true });
130
166
  if (published !== null)
@@ -132,6 +168,7 @@ export function createHouseBridgeTestHost(options = {}) {
132
168
  arrive(current);
133
169
  return {
134
170
  navigations,
171
+ chats,
135
172
  ceremonies,
136
173
  consents,
137
174
  tabs,
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, with `?slot=<name>` to open at one slot, and `/sign-out`, which
17
+ signs the User out and opens sign-in.
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;
@@ -32,6 +34,18 @@
32
34
  click. `setBadge(unread)` takes the identifiers of the Human Notifications
33
35
  unread in this storage and sets the icon's badge to their number, or clears
34
36
  it at none, where the browser shows one.
37
+ - **Telegram** - House's own panel alone, refused to an App or a Site the same
38
+ way. `telegram()` answers `{ state, name, username }`: `state` is
39
+ `'available'` where the page runs inside a House bot's Mini App that gave it
40
+ Telegram's launch data naming an account, with that account's `name` and its
41
+ `username` or `null`, and `'unavailable'` with both `null` elsewhere.
42
+ `telegram(true)` links the signed-in User to that account and answers
43
+ `'linked'` with it; where the User's sign-in is
44
+ not recent, the page goes to sign in again, and nothing links until a later
45
+ `telegram(true)`.
46
+ Telegram's refusal rejects with an error coded `linked_elsewhere`,
47
+ `rate_limited` or `refused`, and a failed request with the browser's own
48
+ error name.
35
49
  - **Status** - the App reference the runtime client is attached under,
36
50
  `preferences`: the `roomRef` and Path of the App's own preferences document,
37
51
  or `null` until the runtime holds that Room, sync
@@ -39,12 +53,27 @@
39
53
  whether the page measures and the visitor's stored analytics choice, and
40
54
  `serviceMode`: `open`, `write-halted` while House refuses writes, so the
41
55
  App can stop retrying them, or `null` while the runtime holds no House
42
- connection. Every status field is camelCase.
56
+ connection. Every status field is camelCase. `onStatus(listener)` and
57
+ `onAddress(listener)` hand a listener the status and the address the bridge
58
+ already holds, then each change.
43
59
  The App reports the visitor's choice with `analyticsConsent('accept')` or
44
60
  `analyticsConsent('decline')`; the shell hands it to House's analytics loader, and
45
61
  the choice never reaches House.
46
- - **Site image read** - given a Published Room and an original attachment
47
- reference, it answers the web copy's path and metadata, or `null` when no
62
+ - **Releases and builds** - an open App keeps the release it loaded: a newer
63
+ release, or a newer House build, takes effect at the App's next load, offline
64
+ too once the browser stored it. When one tab loads a newer House build, the
65
+ other House tabs reload into it; Room Drafts, chat drafts and unsent changes
66
+ survive the reload.
67
+ - **A runtime that ends** - when the browser ends House's runtime under an open
68
+ App, the App keeps running, its `runtime` client and observations included:
69
+ each observation goes on with the next runtime's values, and the status and
70
+ the address arrive again. A runtime that ended before answering has its reads
71
+ answered by the next one; since it may have applied any other call, an act on
72
+ House is answered the outcome `transport-uncertainty`, and every other call,
73
+ a Save or a draft write among them, fails with the retryable code
74
+ `transport-uncertainty`.
75
+ - **Site image read** - given a Published Room and the Path of one of its
76
+ binary entries, it answers the web copy's path and metadata, or `null` when no
48
77
  copy exists. The original bytes never cross this bridge at a Site.
49
78
  - **App release code** - `sourceTop(app, release)` answers the top level of
50
79
  the latest successful release of an App the User may use: its folders, its
@@ -56,21 +85,21 @@
56
85
  refusal is House's `{ error: { code, retryable } }`, `app_release_not_found` for an
57
86
  App with no release; a read House does not answer, or one that outlived
58
87
  the browser's signed-in User, is `null`.
59
- - **External calls** - `callExternal({ url, method, headers, body, slot })`
88
+ - **External calls** - `callExternal({ url, method, headers, body, room_ref })`
60
89
  has House's server send an HTTPS request to one of the release's declared
61
90
  external origins and resolves with the service's `status`, `headers` and its
62
91
  body as `body` text or `body_base64`, or a refusal as House's
63
92
  `{ 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
67
- `account` instead. `body_base64` replaces `body` for bytes.
93
+ App and its running release. A `room_ref` names a Room the signed-in User binds to the App
94
+ in a `write` slot, and House adds that Room's Service key for the URL's origin, which App
95
+ code never sees; a call naming no Room carries no key, and a Site's call names no Room.
96
+ `body_base64` replaces `body` for bytes.
68
97
  - **App messages** - `messages(listener)` hands the listener each message
69
98
  another holder of this App sends to this User's running copies, as `from`,
70
99
  the sender's User id, and `body`, the JSON value they sent, until the
71
100
  function it returns is called. App code sends one through the Runtime's
72
- `call('message.send', { to, body })` with the recipient's User id and
73
- a body of at most 32 KiB of JSON; House fills in the App and relays it only
101
+ `call('apps/messages/send', { to, body })` with the recipient's User id and
102
+ a body of at most 32 kB of JSON; House fills in the App and relays it only
74
103
  to copies running now, storing nothing. The panel sends none.
75
104
  - **App screenshot read** - given an App reference, `readScreenshot(app)`
76
105
  answers the image this browser captured of that App's screen the first time
@@ -82,6 +111,30 @@
82
111
  after its latest release, as a JPEG `Blob`, or `null` when House holds none
83
112
  or does not answer. A Site's own renderer reads none.
84
113
 
114
+ - **Chat** - `chat.mount(element, options)` places House's Chat, the one chat
115
+ in which the User's Agent conversations show, in `element` over the page's
116
+ `runtime` client, and resolves to a handle: `update(options)` replaces its
117
+ options and `unmount()` removes it. House serves the Chat with the page and
118
+ keeps it current, so the App installs and bundles nothing for it. The
119
+ options: `conversation` opens one, `null` for a new chat, `agent` is the
120
+ Agent a new chat goes to, `showChats` adds its conversation list, `width` is
121
+ `full`, the element, or `3/4`, `1/2` or `1/3` of the window docked at its
122
+ right edge, `onOpen` hears each conversation it opens as
123
+ `{ conversation, agent }`, and `onLink` takes a link without a scheme in
124
+ place of the browser. CSS custom properties named `--chat-*` on the element
125
+ or an ancestor set its look. It shows conversations only to a release that
126
+ declares them. A Site and the House panel have none: their call rejects with
127
+ an error named and coded `NotSupportedError`, with `retryable` false.
128
+
129
+ - **First place** - `cooperate({ placed })` tells House when the page has
130
+ drawn the place it opened on; the function it returns withdraws it. Register
131
+ it in the entry script, before the first draw. `placed()` resolves once the
132
+ page has drawn that place with what it shows: House keeps its
133
+ first-preparation surface over a page registered by its first draw until
134
+ then, and lifts it at the first draw of a page that registered none, so the
135
+ User goes from the surface to a drawn place in one change. House asks the
136
+ page for nothing else.
137
+
85
138
  ## The test host
86
139
 
87
140
  `createHouseBridgeTestHost(options)` plays House in one page: it installs a
@@ -102,6 +155,9 @@ records in `tabs` each `setTab`, answers a release code read from the
102
155
  by App reference and `readSiteScreenshot` from the `siteScreenshots` it was
103
156
  given by Site identifier, answers every `install()` `'manual'`, as a browser
104
157
  with no install prompt does, answers every `notifications()` `'unavailable'`,
105
- as a browser without push does, settles every `setBadge`, delivers each App
158
+ as a browser without push does, settles every `setBadge`, records in `chats`
159
+ each Chat `chat.mount` places, with its `element`, the `options` it was last
160
+ given and whether it is still `mounted`, drawing nothing, delivers each App
106
161
  message `message({ from, body })` plays, and hands `bridge.runtime` the MD
107
- Runtime client `attachRuntime(client)` gives it.
162
+ Runtime client `attachRuntime(client)` gives it. It takes a `cooperate` and
163
+ never calls `placed()`.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentshouse/app-bridge",
3
- "version": "0.1.0-ccf413b4e709d",
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.",
3
+ "version": "0.1.0-cd2df7704a056",
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, App messages and the Chat, with an accessor and an in-page test host.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -18,13 +18,15 @@
18
18
  "default": "./dist/test-host.js"
19
19
  }
20
20
  },
21
- "dependencies": {
22
- "@agentshouse/mdruntime": "0.1.0-c2aaa9c0e3ca4"
23
- },
24
21
  "files": [
25
22
  "dist",
26
23
  "docs",
27
24
  "README.md",
28
25
  "LICENSE"
29
- ]
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/agentshouse/core.git",
30
+ "directory": "client"
31
+ }
30
32
  }