@agentshouse/mdruntime-adapter 0.1.0-alpha.4 → 0.1.0-alpha.40

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 (50) hide show
  1. package/AGENTS.md +136 -23
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +3 -11
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +176 -236
  6. package/dist/actions.js.map +1 -1
  7. package/dist/adapter.d.ts +3 -1
  8. package/dist/adapter.d.ts.map +1 -1
  9. package/dist/adapter.js +78 -137
  10. package/dist/adapter.js.map +1 -1
  11. package/dist/discovery.d.ts +39 -11
  12. package/dist/discovery.d.ts.map +1 -1
  13. package/dist/discovery.js +153 -39
  14. package/dist/discovery.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/model.d.ts +19 -0
  19. package/dist/model.d.ts.map +1 -0
  20. package/dist/model.js +64 -0
  21. package/dist/model.js.map +1 -0
  22. package/dist/read.d.ts +24 -19
  23. package/dist/read.d.ts.map +1 -1
  24. package/dist/read.js +126 -55
  25. package/dist/read.js.map +1 -1
  26. package/dist/refusal.d.ts +4 -1
  27. package/dist/refusal.d.ts.map +1 -1
  28. package/dist/refusal.js +13 -1
  29. package/dist/refusal.js.map +1 -1
  30. package/dist/site.d.ts +4 -0
  31. package/dist/site.d.ts.map +1 -0
  32. package/dist/site.js +206 -0
  33. package/dist/site.js.map +1 -0
  34. package/dist/stream.d.ts +8 -5
  35. package/dist/stream.d.ts.map +1 -1
  36. package/dist/stream.js +232 -135
  37. package/dist/stream.js.map +1 -1
  38. package/dist/transport.d.ts +39 -29
  39. package/dist/transport.d.ts.map +1 -1
  40. package/dist/transport.js +5 -1
  41. package/dist/transport.js.map +1 -1
  42. package/dist/version.d.ts +14 -0
  43. package/dist/version.d.ts.map +1 -0
  44. package/dist/version.js +29 -0
  45. package/dist/version.js.map +1 -0
  46. package/dist/write.d.ts +6 -0
  47. package/dist/write.d.ts.map +1 -1
  48. package/dist/write.js +51 -9
  49. package/dist/write.js.map +1 -1
  50. package/package.json +4 -12
package/AGENTS.md CHANGED
@@ -7,36 +7,149 @@ 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, Query, Observe, Types, Draft, Save, Queue, History, Call, Log,
11
- storage loss, the reported persistence answer, Sync Status, reauthorization,
12
- conversation, the unsent instruction, and Presentation State.
13
-
14
- Rooms, Query, Observe, Types, Draft, and Save never touch the network.
15
- History and Call go to the Provider through the Adapter. Every member of the
10
+ Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Log,
11
+ storage loss, the reported persistence answer, deployment facts, Sync Status, the Service Mode,
12
+ reauthorization, conversation, the chat draft, and Presentation State.
13
+
14
+ Every `observe` resolves, once its first value has arrived, to a handle:
15
+ `current()` is the latest complete value, `subscribe(listener)` hears each later
16
+ value whole and returns its unsubscribe, and `close()` ends the observation.
17
+ Closing the port ends every handle and rejects every pending call and
18
+ observation; a client that reconnects observes again.
19
+
20
+ Each conversation a Provider card names is held complete in the browser.
21
+ Observe one with `observe('conversation', id, { limit })`: the view
22
+ holds its latest `limit` messages, or all of them, oldest first, its chat
23
+ 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.
29
+ `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
30
+ sending it is a Provider Action that needs the Provider reachable and is never
31
+ queued.
32
+
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
+ Rooms, Slots, Query, Search, Observe, Types, Room Draft, and Save never touch the
37
+ network.
38
+ History and Call go to the Provider through the Adapter. Each History revision
39
+ names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
40
+ member of the
16
41
  client is asynchronous. Results are detached snapshots. Nothing in this
17
42
  surface returns the authorization, performs a request the App's code
18
43
  composes, or exposes the browser store.
19
44
 
45
+ Read deployment facts with `deploymentFacts()` and observe replacements with
46
+ `observe('deployment-facts')`. Interpret the opaque value using the
47
+ host's contract.
48
+
20
49
  The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
21
50
  ships in no bundle.
22
51
 
23
- ## Draft, Save, and outcome rules
24
-
25
- A Draft is durable: it survives reload and navigation. Save takes structured
26
- changes, validates locally, and on success appends one Change Batch to that
27
- Room's queue. A local validation failure leaves the Draft and creates
28
- nothing.
52
+ ## Local Query rules
53
+
54
+ `query(q)` answers once from local state; `observe('query', q)` holds the whole
55
+ result and hears it again only when it changes, keeping every unchanged Document
56
+ the same object, so a component can tell what changed by identity. A query is
57
+ data:
58
+
59
+ - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
60
+ names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
61
+ directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
62
+ - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
63
+ `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
64
+ `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
65
+ asks whether it contains the value. Missing, null and empty differ:
66
+ `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
67
+ text and `$size: 0` an empty list. A date compares in calendar order and never
68
+ with a date-time. A reference compares by the Room Path it resolves to.
69
+ Untyped frontmatter is plain values. There is no text containment or regular
70
+ expression.
71
+ - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
72
+ reference `field` points to a matching Document of the same Room.
73
+ `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
74
+ matching Document of the same Room references. Each keeps a Document once.
75
+ - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
76
+ `preamble`, `markdown` and `backlinks`, where `fields` and `sections` are
77
+ `'all'` or a list of names. Room and Path always return; a Markdown Document
78
+ also returns its MD Type. A non-Markdown Document or binary link target returns
79
+ only Room and Path. An unselected part is absent. Select only what a screen
80
+ shows: a list that selects the Markdown hears every edit of it.
81
+ - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
82
+ with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
83
+ `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
84
+ over every match and ordered by `count` or a key. `limit` bounds the Documents
85
+ or the groups.
86
+ - **Results and errors.** A result carries no Room Version: read freshness from
87
+ Rooms and Sync Status. An invalid query fails with `invalid-query`,
88
+ `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
89
+ answers an empty result in its place.
90
+
91
+ ## Local Search rules
92
+
93
+ `search({ text, documents, conversations, limit })` answers once, by words, from
94
+ local state, with MiniSearch at its default configuration. There is no observed
95
+ search.
96
+
97
+ - **What is found.** A Document by its field values, its sections' headings and
98
+ text, its preamble and its Path; a message by its text. Frontmatter keys, Room
99
+ Drafts, chat drafts and growing text are never found. There are no phrases,
100
+ word forms, typo tolerance or prefix matching.
101
+ - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
102
+ `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
103
+ apply before `limit`, which bounds each list; without it every hit returns.
104
+ - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
105
+ hits of one list of one search. A Document hit names its `room`, `path` and
106
+ `type`, a message hit its `conversation` and `identity`, and `matches` maps each
107
+ matched word to the parts it matched in: `fields`, `sections`, `preamble` or
108
+ `path`, or `text`. A hit carries no position; mark the words in the text you
109
+ show. An invalid filter fails with its Local Query error.
110
+
111
+ ## Room Draft, Save, and outcome rules
112
+
113
+ The MD Runtime owns one Room Draft per Room and Path, shared by every App and
114
+ tab. It is durable: it survives reload and navigation. A Room that Discovery
115
+ stops listing takes its Room Drafts, its queue and their outcomes with it.
116
+ Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
117
+ the revision you read, or `null` when there was none, and every part it should
118
+ now change: fields, sections and the preamble, or the whole Markdown, a
119
+ creation, a move, or a removal. A part new to the Room Draft names its base,
120
+ the value you showed when it was opened; the MD Runtime keeps a part's first
121
+ base. A binary link target has a Room Draft too, for a move or a removal, with
122
+ `null` as its base. A write or a discard from an older revision is refused as `stale` with
123
+ the current Room Draft; read it and write again.
124
+
125
+ Save takes one Room and the Room Drafts of it to save, each with its revision,
126
+ validates locally, and on success appends one Change Batch to that Room's
127
+ queue and removes those Room Drafts. It is refused as `stale`, as
128
+ `changed-underneath` naming each part whose base no longer matches the visible
129
+ state, or by a local validation rule, and then creates nothing and leaves every
130
+ Room Draft in place. A directory move or removal is a move or removal part on
131
+ each Document and binary link target beneath it, saved together.
29
132
 
30
133
  Outcomes follow the Provider's answer. Accepted advances the confirmed
31
- layer. Conflicted and Rejected leave the head in place, carry the affected
32
- current state and the Provider's structured refusal code and fields as
33
- returned, and block that Room's queue. The App's code resolves a head by
34
- discarding it or by saving a corrected Change Batch that replaces it in
35
- place. Transport failure and Provider unavailability keep work Pending and
36
- do not infer a rejection. A refusal the Provider marks retryable stays
37
- Pending until the reset it names; the MD Runtime retries the same Change
38
- Batch identity and payload and never infers an outcome from transport
39
- uncertainty. The MD Runtime never combines, reorders, or rebases.
134
+ layer. Conflicted and Rejected, an expired outcome record, and a change that no
135
+ longer applies over the Room each leave the queue and return as Room Drafts on
136
+ the Documents they changed, marked with why: the Provider's structured refusal
137
+ code and fields as returned, not known to have applied, or withdrawn locally.
138
+ The rest of the queue keeps synchronizing, and Sync Status requires attention
139
+ until each returned Room Draft is saved again or discarded. `outcome` answers
140
+ the saved Change Batch's outcome, and `null` while it is Pending. Transport
141
+ failure and Provider unavailability keep work Pending and do not infer a
142
+ rejection. A refusal the Provider marks retryable stays Pending until the reset
143
+ it names; the MD Runtime retries the same Change Batch identity and payload and
144
+ never infers an outcome from transport uncertainty. The MD Runtime never
145
+ combines, reorders, or rebases.
146
+
147
+ `serviceMode()` and `observe('service-mode')` answer the Provider's Service
148
+ Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
149
+ its Change Batch waits unsent, and the queue is submitted in order once the
150
+ Provider reopens writes. An Action is never held: a write the Provider refuses
151
+ for the halt returns that refusal to its caller. Show the Provider as read-only
152
+ instead of retrying.
40
153
 
41
154
  ## The neutrality rule
42
155
 
@@ -61,8 +174,8 @@ a desktop. Its strings are English only, dates and numbers follow the
61
174
  browser locale, and content is never translated. Light and dark themes come
62
175
  from CSS custom properties with the browser's preference as the default and
63
176
  an App's override respected. What an App Creator's agent adds carries none
64
- of these promises by itself. Reading and querying never wait for the
65
- network. Data lives only in the App Creator's browser and with the Provider.
177
+ of these promises by itself. Reading, querying and searching never wait for
178
+ the network. Data lives only in the App Creator's browser and with the Provider.
66
179
 
67
180
  ## App code imports only the client entry and never constructs a Runtime
68
181
 
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # `@agentshouse/mdruntime-adapter`
2
+
3
+ The [Agents House](https://agents.house) Adapter for
4
+ [`@agentshouse/mdruntime`](https://www.npmjs.com/package/@agentshouse/mdruntime):
5
+ it connects a Runtime host to Agents House as its Provider.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @agentshouse/mdruntime-adapter @agentshouse/mdruntime
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ A Runtime host creates the Adapter and passes it to the Runtime:
16
+
17
+ ```ts
18
+ import { serveMdRuntime } from '@agentshouse/mdruntime/host';
19
+ import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
20
+
21
+ const adapter = createAgentsHouseAdapter({ transport, authorize });
22
+ const host = serveMdRuntime({ adapter, shell, requiredGuarantees: [] });
23
+ host.attach(port, 'my-app');
24
+ ```
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
28
+ [`AGENTS.md`](AGENTS.md).
29
+
30
+ ## License
31
+
32
+ MIT
package/dist/actions.d.ts CHANGED
@@ -1,16 +1,8 @@
1
- import { type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
- export declare const CONVERSATION_ACTIONS: readonly ['conversation.create', 'conversation.send', 'conversation.answer', 'conversation.interrupt', 'conversation.kill', 'conversation.cancel', 'conversation.delete', 'conversation.history'];
4
- export declare const HOUSE_ACTS: readonly ['conversations/interaction/read', 'conversations/originals/read', 'apps/read', 'apps/customize', 'rooms/read', 'rooms/access/read', 'rooms/access/invitations', 'rooms/access/entries', 'rooms/access/invite', 'rooms/access/invitation-cancel', 'rooms/access/revoke', 'rooms/access/leave', 'rooms/roles/define', 'rooms/roles/remove', 'rooms/roles/assign', 'rooms/roles/unassign', 'rooms/settings/processing/read', 'rooms/settings/processing/write', 'profiles/create', 'profiles/read', 'profiles/edit', 'profiles/duplicate', 'profiles/delegate', 'agents/create', 'agents/read', 'routines/requests', 'routines/access', 'routines/owned', 'routines/granted', 'routines/grant', 'routines/send', 'routines/cancel', 'routines/start', 'routines/schedules', 'routines/schedules/create', 'routines/schedules/enabled', 'account/security/read', 'storage/inventory', 'storage/usage', 'usage/statement', 'storage/blob-store', 'storage/blob-store/select', 'storage/connections', 'storage/archive', 'storage/archive/status', 'environments/read', 'environments/create', 'environments/start', 'environments/stop', 'environments/delete', 'environments/renewals/read', 'environments/work/read', 'nodes/read'];
5
- export declare const HOUSE_PROVIDER_ACTIONS: readonly ["conversation.create", "conversation.send", "conversation.answer", "conversation.interrupt", "conversation.kill", "conversation.cancel", "conversation.delete", "conversation.history", "conversations/interaction/read", "conversations/originals/read", "apps/read", "apps/customize", "rooms/read", "rooms/access/read", "rooms/access/invitations", "rooms/access/entries", "rooms/access/invite", "rooms/access/invitation-cancel", "rooms/access/revoke", "rooms/access/leave", "rooms/roles/define", "rooms/roles/remove", "rooms/roles/assign", "rooms/roles/unassign", "rooms/settings/processing/read", "rooms/settings/processing/write", "profiles/create", "profiles/read", "profiles/edit", "profiles/duplicate", "profiles/delegate", "agents/create", "agents/read", "routines/requests", "routines/access", "routines/owned", "routines/granted", "routines/grant", "routines/send", "routines/cancel", "routines/start", "routines/schedules", "routines/schedules/create", "routines/schedules/enabled", "account/security/read", "storage/inventory", "storage/usage", "usage/statement", "storage/blob-store", "storage/blob-store/select", "storage/connections", "storage/archive", "storage/archive/status", "environments/read", "environments/create", "environments/start", "environments/stop", "environments/delete", "environments/renewals/read", "environments/work/read", "nodes/read"];
6
- export declare const HISTORY_PAGE = 100;
7
3
  export declare const HOUSE_CONVERSATION_CARDS: ConversationCards;
8
- export declare function declaredActions(): readonly ActionDeclaration[];
4
+ export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
9
5
  export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
10
6
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
11
- export declare function readConversationHistory(transport: HouseTransport, conversationId: string): Promise<{
12
- messages: unknown[];
13
- } | {
14
- outcome: ActionResult;
15
- }>;
7
+ export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
16
8
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,eAAO,MAAM,oBAAoB,YAC/B,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,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