@agentshouse/mdruntime-adapter 0.1.0-c9f1e531ad7c8 → 0.1.0-cacce09fc82c6

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/AGENTS.md CHANGED
@@ -7,9 +7,19 @@ enforcement.
7
7
  ## The MD Runtime API
8
8
 
9
9
  App code reaches the MD Runtime through the remote client. The surfaces are
10
- Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
- storage loss, the reported persistence answer, deployment facts, Sync Status, the Service Mode,
12
- reauthorization, conversation, the chat draft, and Presentation State.
10
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
+ the reported persistence answer, reauthorization, conversation, the chat draft,
12
+ and Presentation State. Sync Status, the Service Mode, the storage-loss
13
+ statement, the deployment facts and the signed-in member are observations only.
14
+
15
+ The host attaches each port with its reach, and every member and observation
16
+ answers within it: a Room outside it answers as one the replica does not hold,
17
+ Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
+ shows only those Documents and the Types of the models that govern them, and
19
+ without conversations the conversation members, the chat draft and the
20
+ conversation observation hold none.
21
+ A change of the reach reaches every open observation as its new value, a query
22
+ keeping every unchanged Document the same object.
13
23
 
14
24
  Every `observe` resolves, once its first value has arrived, to a handle:
15
25
  `current()` is the latest complete value, `subscribe(listener)` hears each later
@@ -17,29 +27,29 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
17
27
  Closing the port ends every handle and rejects every pending call and
18
28
  observation; a client that reconnects observes again.
19
29
 
20
- Each conversation a Provider card names is held complete in the browser.
30
+ Each conversation the Provider's conversation list names is held complete in the
31
+ browser. `conversation.list()` and `observe('conversations')` answer each with its
32
+ Agent's identity and name, its name, created and finished times, last outcome and live
33
+ `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
34
+ and `started`, when the running turn began, or `null`.
21
35
  Observe one with `observe('conversation', id, { limit })`: the view
22
36
  holds its latest `limit` messages, or all of them, oldest first, its chat
23
37
  draft, and what the Provider streams for it whether or not anything views it:
24
- the growing text and plan of the running turn, the open questions, the process
25
- state, the CLI's commands and options, and the latest `workingNote`. These live
26
- only in memory: the turn's accepted message replaces its growing text and plan,
27
- a working note is never part of a message, and none of them is stored or
28
- searchable.
38
+ the running `turn` with its message parts and its context in use and window, the
39
+ open questions, the process state, and the CLI's commands and options. These live
40
+ only in memory: the message accepted under the turn's id replaces the running turn,
41
+ and none of them is stored or searchable.
29
42
  `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
30
43
  sending it is a Provider Action that needs the Provider reachable and is never
31
44
  queued.
32
45
 
33
- Slots answers each Slot the Provider declares, in its order, with its entries
34
- in order, each a Room and its segment; a Room two Slots list is the same Room.
35
-
36
46
  Each Room in Rooms lists its `attachments`, the files the Provider holds for it
37
47
  that its Documents link by the Provider's reference, ordered by `reference`,
38
48
  each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
39
49
  `entry`. They are as the Provider last declared them and hold no bytes;
40
50
  open one through the Provider Action that serves it.
41
51
 
42
- Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
52
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
43
53
  touch the network.
44
54
  History and Call go to the Provider through the Adapter. A Call result whose
45
55
  effect the Provider places in a Room carries `at`, that Room and Room Version;
@@ -47,15 +57,26 @@ effect the Provider places in a Room carries `at`, that Room and Room Version;
47
57
  reached it, and the MD Runtime keeps refreshing that Room until it has;
48
58
  `reached(room, roomVersion, path)` answers whether the held confirmed copy of
49
59
  that document was written at a later Room Version. Each History revision
50
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
60
+ names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
61
+ History of a Path no current document holds answers the removed document's
62
+ revisions with `deleted: true`, newest first; that revision is what a link to
63
+ the Path opens. Every
51
64
  member of the
52
65
  client is asynchronous. Results are detached snapshots. Nothing in this
53
66
  surface returns the authorization, performs a request the App's code
54
67
  composes, or exposes the browser store.
55
68
 
56
- Read deployment facts with `deploymentFacts()` and observe replacements with
57
- `observe('deployment-facts')`. Interpret the opaque value using the
58
- host's contract.
69
+ Read the deployment facts with `observe('deployment-facts')`. Interpret the
70
+ opaque value using the host's contract.
71
+
72
+ `observe('member')` answers who uses the App: the User the Provider signed in,
73
+ `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
74
+ whose `change.author.id` equals its `id` is that User's own. It is `null` until
75
+ the Provider first names one, and where it names none, such as a Site. The
76
+ MD Runtime keeps it with the Local Replicas, so it answers offline once known,
77
+ and every port hears the next member the Provider names; signing out answers
78
+ `null`, then ends the observation with the authorization. It is the only way App code learns who
79
+ uses it.
59
80
 
60
81
  The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
61
82
  ships in no bundle.
@@ -70,22 +91,28 @@ data:
70
91
  - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
71
92
  names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
72
93
  directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
73
- - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
74
- `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
75
- `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
76
- asks whether it contains the value. Missing, null and empty differ:
94
+ - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
95
+ `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
96
+ meets a list applies to every item and a number names one item. `where` names
97
+ pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
98
+ when any item satisfies it. A bare value is equality; the operators are `$eq`,
99
+ `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
100
+ `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
77
101
  `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
78
102
  text and `$size: 0` an empty list. A date compares in calendar order and never
79
103
  with a date-time. A reference compares by the Room Path it resolves to.
80
- Untyped frontmatter is plain values. There is no text containment or regular
104
+ Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
105
+ values. There is no text containment or regular
81
106
  expression.
82
107
  - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
83
- reference `field` points to a matching Document of the same Room.
84
- `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
108
+ reference at pointer `field`, at any depth, points to a matching Document of the
109
+ same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
85
110
  matching Document of the same Room references. Each keeps a Document once.
86
111
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
87
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
88
- are `'all'` or a list of names. Room and Path always return; a Markdown
112
+ `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
113
+ list of pointers and `sections` `'all'` or a list of names. Selected pointers
114
+ return the frontmatter holding only them, nested as written. A backlink names
115
+ the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
89
116
  Document also returns its MD Type. A non-Markdown Document or binary link
90
117
  target returns only Room and Path. An unselected part is absent. Select only
91
118
  what a screen shows: a list that selects the Markdown hears every edit of it.
@@ -94,13 +121,13 @@ data:
94
121
  or `null` for a write the Provider made itself, and `time` is the Provider's
95
122
  ISO 8601 change time. It is `null` where the Provider delivered no time, as at
96
123
  a Site. An unsent edit or move keeps it, an unsent creation has none, and a
97
- saved write takes the Provider's own once it is Accepted and refreshed. A
124
+ saved write takes the Provider's own once it is Accepted. A
98
125
  Room's last change is its Document with the latest `time`.
99
126
  - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
100
127
  with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
101
128
  `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
102
- over every match and ordered by `count` or a key. `limit` bounds the Documents
103
- or the groups.
129
+ over every match and ordered by `count` or a key. A sort or group takes only a
130
+ pointer that holds one value. `limit` bounds the Documents or the groups.
104
131
  - **Results and errors.** A result carries no Room Version: read freshness from
105
132
  Rooms and Sync Status. An invalid query fails with `invalid-query`,
106
133
  `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
@@ -114,7 +141,7 @@ search.
114
141
 
115
142
  - **What is found.** A Document by its field values, its sections' headings and
116
143
  text, its preamble and its Path; a message by its text. Frontmatter keys, Room
117
- Drafts, chat drafts and growing text are never found. There are no phrases,
144
+ Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
118
145
  word forms, typo tolerance or prefix matching.
119
146
  - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
120
147
  `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
@@ -130,7 +157,7 @@ search.
130
157
 
131
158
  The MD Runtime owns one Room Draft per Room and Path, shared by every App and
132
159
  tab. It is durable: it survives reload and navigation. A Room that Discovery
133
- stops listing takes its Room Drafts, its queue and their outcomes with it.
160
+ stops listing takes its Room Drafts and its queue with it.
134
161
  Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
135
162
  the revision you read, or `null` when there was none, and every part it should
136
163
  now change: fields, sections and the preamble, or the whole Markdown, a
@@ -150,20 +177,21 @@ each Document and binary link target beneath it, saved together.
150
177
 
151
178
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
152
179
  queue, drawn over the confirmed layer, until the confirmed layer reaches the
153
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired outcome record, and a change that no
180
+ Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
154
181
  longer applies over the Room each leave the queue and return as Room Drafts on
155
182
  the Documents they changed, marked with why: the Provider's structured refusal
156
183
  code and fields as returned, not known to have applied, or withdrawn locally.
157
184
  The rest of the queue keeps synchronizing, and Sync Status requires attention
158
- until each returned Room Draft is saved again or discarded. `outcome` answers
159
- the saved Change Batch's outcome, and `null` while it is Pending. Transport
185
+ until each returned Room Draft is saved again or discarded. A Change Batch
186
+ keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
187
+ Pending one, and a returned Room Draft says why it returned. Transport
160
188
  failure and Provider unavailability keep work Pending and do not infer a
161
189
  rejection. A refusal the Provider marks retryable stays Pending until the reset
162
190
  it names; the MD Runtime retries the same Change Batch identity and payload and
163
191
  never infers an outcome from transport uncertainty. The MD Runtime never
164
192
  combines, reorders, or rebases.
165
193
 
166
- `serviceMode()` and `observe('service-mode')` answer the Provider's Service
194
+ `observe('service-mode')` answers the Provider's Service
167
195
  Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
168
196
  its Change Batch waits unsent, and the queue is submitted in order once the
169
197
  Provider reopens writes. An Action is never held: a write the Provider refuses
@@ -196,13 +224,28 @@ an App's override respected. What an App Creator's agent adds carries none
196
224
  of these promises by itself. Reading, querying and searching never wait for
197
225
  the network. Data lives only in the App Creator's browser and with the Provider.
198
226
 
199
- ## App code imports only the client entry and never constructs a Runtime
200
-
201
- App code imports only `@agentshouse/mdruntime/client` and calls
202
- `connectMdRuntime` on the port the host hands it. It never constructs a
203
- Runtime. It does not import the package main, the host entry, or the Adapter
204
- package, and it does not call `createMdRuntime` or `serveMdRuntime`. Hosts
205
- and tests use those entries; the served App does not.
227
+ ## App code takes the client its host hands it and never constructs a Runtime
228
+
229
+ App code takes the client its host hands it: in House,
230
+ `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
231
+ client House built into the page. It never constructs a Runtime or a client.
232
+ It imports only types from `@agentshouse/mdruntime/client`, does not call
233
+ `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
234
+ the host entry, or the Adapter package. Hosts and tests use those entries; the
235
+ served App does not.
236
+
237
+ A React App may observe and save through `@agentshouse/mdruntime/react`, which
238
+ names React as a peer dependency. `useObserve(client, topic, ...input)` takes
239
+ the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
240
+ first value arrives, then `{ state: 'ready', value }`, re-rendering on each
241
+ change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
242
+ `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
243
+ already there, keeping the bases its parts have, or onto a new one, and saves
244
+ them together. A refused Save leaves the Room Drafts for the App to save again
245
+ or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
246
+ roomDrafts)` is that save outside a component. A react-admin or Refine App
247
+ reads and writes its Rooms through the data providers of
248
+ `@agentshouse/mdruntime-families`.
206
249
 
207
250
  ## What an agent must never do
208
251
 
package/README.md CHANGED
@@ -19,12 +19,12 @@ import { serveMdRuntime } from '@agentshouse/mdruntime/host';
19
19
  import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
20
20
 
21
21
  const adapter = createAgentsHouseAdapter({ transport, authorize });
22
- const host = serveMdRuntime({ adapter, shell, requiredGuarantees: [] });
22
+ const host = serveMdRuntime({ adapter, shell });
23
23
  host.attach(port, 'my-app');
24
24
  ```
25
25
 
26
- App code never imports this package; it reaches the Runtime only through
27
- `@agentshouse/mdruntime/client`. The rules an App's agent follows are in the
26
+ App code never imports this package; it reaches the Runtime only through the
27
+ client its host hands it. The rules an App's agent follows are in the
28
28
  package's `AGENTS.md`.
29
29
 
30
30
  ## License
package/dist/actions.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
- export declare const HOUSE_CONVERSATION_CARDS: ConversationCards;
3
+ export declare function houseConversationAgents(locator: string): ConversationAgents;
4
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
5
5
  export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
6
6
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,eAAO,MAAM,wBAAwB,EAAE,iBAKtC,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAGxB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { changeBatchIdentity, } from '@agentshouse/mdruntime';
2
2
  import { doorRefusal } from './refusal.js';
3
- import { PRIVATE_LOCATOR } from './transport.js';
4
3
  const HISTORY_PAGE = 100;
5
4
  const HISTORY_CONVERSATIONS = 64;
6
5
  const OCTET_STREAM = 'application/octet-stream';
@@ -13,12 +12,9 @@ const CONVERSATION_ROUTES = new Map([
13
12
  ['conversation.delete', '/door/conversations/delete'],
14
13
  ['conversation.history', '/door/conversations/history'],
15
14
  ]);
16
- export const HOUSE_CONVERSATION_CARDS = {
17
- locator: PRIVATE_LOCATOR,
18
- type: 'house-conversation',
19
- identity: 'conversation',
20
- agent: 'agent',
21
- };
15
+ export function houseConversationAgents(locator) {
16
+ return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
17
+ }
22
18
  export function declaredActions(routes) {
23
19
  const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
24
20
  return routes.map((route) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkZpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAWd,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAOL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAyBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAsBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0WpF"}