@agentshouse/mdruntime 0.1.0-alpha.25 → 0.1.0-alpha.27
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 +37 -8
- package/dist/client.d.ts +15 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +60 -59
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +19 -10
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +113 -91
- package/dist/connection.js.map +1 -1
- package/dist/conversation.d.ts +4 -1
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +19 -2
- package/dist/conversation.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +19 -39
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/observation.d.ts +25 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +92 -0
- package/dist/observation.js.map +1 -0
- package/dist/query.d.ts +7 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +23 -10
- package/dist/query.js.map +1 -1
- package/dist/read-side.d.ts +5 -1
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +92 -21
- package/dist/read-side.js.map +1 -1
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +155 -0
- package/dist/search.js.map +1 -0
- package/dist/wire.d.ts +3 -2
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -1
- package/dist/wire.js.map +1 -1
- package/package.json +3 -2
package/AGENTS.md
CHANGED
|
@@ -7,12 +7,18 @@ 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, Observe, Types, Room Draft, Save, History, Call, Log,
|
|
10
|
+
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Log,
|
|
11
11
|
storage loss, the reported persistence answer, deployment facts, Sync Status, reauthorization,
|
|
12
12
|
conversation, the chat draft, and Presentation State.
|
|
13
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
|
+
|
|
14
20
|
Each conversation a Provider card names is held complete in the browser.
|
|
15
|
-
Observe one with `observe('conversation', id, { limit }
|
|
21
|
+
Observe one with `observe('conversation', id, { limit })`: the view
|
|
16
22
|
holds its latest `limit` messages, or all of them, oldest first, with the
|
|
17
23
|
growing text and the session summary while it is viewed, and its chat draft.
|
|
18
24
|
`chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
|
|
@@ -22,14 +28,15 @@ queued.
|
|
|
22
28
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
23
29
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
|
24
30
|
|
|
25
|
-
Rooms, Slots, Query, Observe, Types, Room Draft, and Save never touch the
|
|
31
|
+
Rooms, Slots, Query, Search, Observe, Types, Room Draft, and Save never touch the
|
|
32
|
+
network.
|
|
26
33
|
History and Call go to the Provider through the Adapter. Every member of the
|
|
27
34
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
28
35
|
surface returns the authorization, performs a request the App's code
|
|
29
36
|
composes, or exposes the browser store.
|
|
30
37
|
|
|
31
38
|
Read deployment facts with `deploymentFacts()` and observe replacements with
|
|
32
|
-
`observe('deployment-facts'
|
|
39
|
+
`observe('deployment-facts')`. Interpret the opaque value using the
|
|
33
40
|
host's contract. [R038](https://github.com/agentshouse/mdruntime/blob/main/docs/requirements/ledger.md#r038--runtime-host-and-remote-client)
|
|
34
41
|
owns their boundary.
|
|
35
42
|
|
|
@@ -38,8 +45,10 @@ ships in no bundle.
|
|
|
38
45
|
|
|
39
46
|
## Local Query rules
|
|
40
47
|
|
|
41
|
-
`query(q)` answers once from local state; `observe('query', q
|
|
42
|
-
|
|
48
|
+
`query(q)` answers once from local state; `observe('query', q)` holds the whole
|
|
49
|
+
result and hears it again only when it changes, keeping every unchanged Document
|
|
50
|
+
the same object, so a component can tell what changed by identity. A query is
|
|
51
|
+
data:
|
|
43
52
|
|
|
44
53
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
45
54
|
names MD Types, and `any` names the untyped Documents. `pathPrefix` is a
|
|
@@ -72,6 +81,26 @@ the whole result at once and again only when it changes. A query is data:
|
|
|
72
81
|
`unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
|
|
73
82
|
answers an empty result in its place.
|
|
74
83
|
|
|
84
|
+
## Local Search rules
|
|
85
|
+
|
|
86
|
+
`search({ text, documents, conversations, limit })` answers once, by words, from
|
|
87
|
+
local state, with MiniSearch at its default configuration. There is no observed
|
|
88
|
+
search.
|
|
89
|
+
|
|
90
|
+
- **What is found.** A Document by its field values, its sections' headings and
|
|
91
|
+
text, its preamble and its Path; a message by its text. Frontmatter keys, Room
|
|
92
|
+
Drafts, chat drafts and growing text are never found. There are no phrases,
|
|
93
|
+
word forms, typo tolerance or prefix matching.
|
|
94
|
+
- **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
|
|
95
|
+
`pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
|
|
96
|
+
apply before `limit`, which bounds each list; without it every hit returns.
|
|
97
|
+
- **Results.** `{ documents, messages }`, each ranked by `score`, which compares
|
|
98
|
+
hits of one list of one search. A Document hit names its `room`, `path` and
|
|
99
|
+
`type`, a message hit its `conversation` and `identity`, and `matches` maps each
|
|
100
|
+
matched word to the parts it matched in: `fields`, `sections`, `preamble` or
|
|
101
|
+
`path`, or `text`. A hit carries no position; mark the words in the text you
|
|
102
|
+
show. An invalid filter fails with its Local Query error.
|
|
103
|
+
|
|
75
104
|
## Room Draft, Save, and outcome rules
|
|
76
105
|
|
|
77
106
|
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
@@ -130,8 +159,8 @@ a desktop. Its strings are English only, dates and numbers follow the
|
|
|
130
159
|
browser locale, and content is never translated. Light and dark themes come
|
|
131
160
|
from CSS custom properties with the browser's preference as the default and
|
|
132
161
|
an App's override respected. What an App Creator's agent adds carries none
|
|
133
|
-
of these promises by itself. Reading and
|
|
134
|
-
network. Data lives only in the App Creator's browser and with the Provider.
|
|
162
|
+
of these promises by itself. Reading, querying and searching never wait for
|
|
163
|
+
the network. Data lives only in the App Creator's browser and with the Provider.
|
|
135
164
|
|
|
136
165
|
## App code imports only the client entry and never constructs a Runtime
|
|
137
166
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AppRoom, AppSlot, ConnectionRefusal, HistoryQuery, RoomTypes, SavedRoomDraft, SaveResult } from './connection.js';
|
|
2
2
|
import type { HistoryResult } from './adapter.js';
|
|
3
3
|
import type { ChatDraft, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
4
|
+
import { type Observation } from './observation.js';
|
|
4
5
|
import type { CallResult, QueueEntry, SubmissionOutcome } from './outcome.js';
|
|
5
6
|
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
6
7
|
import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
|
|
8
|
+
import type { SearchRequest, SearchResult } from './search.js';
|
|
7
9
|
import type { SyncStatus } from './status.js';
|
|
8
10
|
import { type RuntimePort } from './wire.js';
|
|
9
11
|
export type MdRuntimeClient = {
|
|
@@ -13,6 +15,7 @@ export type MdRuntimeClient = {
|
|
|
13
15
|
(query: DocumentQuery): Promise<DocumentResult>;
|
|
14
16
|
(query: GroupQuery): Promise<GroupResult>;
|
|
15
17
|
};
|
|
18
|
+
search(request: SearchRequest): Promise<SearchResult>;
|
|
16
19
|
types(locator: string): Promise<RoomTypes>;
|
|
17
20
|
syncStatus(): Promise<SyncStatus>;
|
|
18
21
|
roomDraft: {
|
|
@@ -49,20 +52,21 @@ export type MdRuntimeClient = {
|
|
|
49
52
|
persistence(): Promise<boolean>;
|
|
50
53
|
deploymentFacts(): Promise<unknown>;
|
|
51
54
|
observe: {
|
|
52
|
-
(topic: 'deployment-facts'
|
|
53
|
-
(topic: 'rooms'
|
|
54
|
-
(topic: 'connection-refusal'
|
|
55
|
-
(topic: 'storage-loss'
|
|
56
|
-
(topic: 'sync-status'
|
|
57
|
-
(topic: 'query', query: DocumentQuery
|
|
58
|
-
(topic: 'query', query: GroupQuery
|
|
59
|
-
(topic: 'queue', locator: string
|
|
60
|
-
(topic: 'room-drafts'
|
|
61
|
-
(topic: 'presentation'
|
|
62
|
-
(topic: 'conversation', conversation: string, options: ConversationOptions
|
|
55
|
+
(topic: 'deployment-facts'): Promise<Observation<unknown>>;
|
|
56
|
+
(topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
|
|
57
|
+
(topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
|
|
58
|
+
(topic: 'storage-loss'): Promise<Observation<string | null>>;
|
|
59
|
+
(topic: 'sync-status'): Promise<Observation<SyncStatus>>;
|
|
60
|
+
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult>>;
|
|
61
|
+
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult>>;
|
|
62
|
+
(topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
|
|
63
|
+
(topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
|
|
64
|
+
(topic: 'presentation'): Promise<Observation<unknown>>;
|
|
65
|
+
(topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
|
|
63
66
|
};
|
|
64
67
|
reauthorize(): Promise<void>;
|
|
65
68
|
};
|
|
66
69
|
export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
|
|
70
|
+
export type { Observation } from './observation.js';
|
|
67
71
|
export type { RuntimePort } from './wire.js';
|
|
68
72
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAY,KAAK,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EA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,CAAC;QAC7E,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;QACvE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/E,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QACvD,CACE,KAAK,EAAE,cAAc,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC;KAC3C,CAAC;IACF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,eAAe,CAqLnE;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { observed } from './observation.js';
|
|
2
|
+
import { answer, AUTHORIZATION_ENDED, carried, envelope, PORT_CLOSED, PROTOCOL_MISMATCH } from './wire.js';
|
|
2
3
|
export function connectMdRuntime(port) {
|
|
3
4
|
let sequence = 0;
|
|
4
5
|
let refusal = null;
|
|
5
|
-
let ended =
|
|
6
|
+
let ended = null;
|
|
6
7
|
const calls = new Map();
|
|
7
|
-
const
|
|
8
|
-
const
|
|
8
|
+
const opening = new Map();
|
|
9
|
+
const observations = new Map();
|
|
9
10
|
const send = (message)=>{
|
|
10
11
|
port.postMessage(envelope(message));
|
|
11
12
|
};
|
|
13
|
+
function begin(id, topic, first) {
|
|
14
|
+
const handle = observed(first, ()=>{
|
|
15
|
+
observations.delete(id);
|
|
16
|
+
if (refusal === null) send({
|
|
17
|
+
kind: 'stop',
|
|
18
|
+
id
|
|
19
|
+
});
|
|
20
|
+
}, topic === 'query');
|
|
21
|
+
observations.set(id, {
|
|
22
|
+
topic,
|
|
23
|
+
handle
|
|
24
|
+
});
|
|
25
|
+
return handle.observation;
|
|
26
|
+
}
|
|
12
27
|
function refuse(reported) {
|
|
13
28
|
refusal = reported;
|
|
14
|
-
for (const
|
|
15
|
-
|
|
29
|
+
for (const { topic, handle } of observations.values()){
|
|
30
|
+
if (topic === 'connection-refusal') handle.receive(reported);
|
|
31
|
+
}
|
|
16
32
|
const failure = new Error(reported.reason);
|
|
33
|
+
for (const [id, waiting] of opening){
|
|
34
|
+
if (waiting.topic === 'connection-refusal') waiting.settle(begin(id, waiting.topic, reported));
|
|
35
|
+
else waiting.fail(failure);
|
|
36
|
+
}
|
|
37
|
+
opening.clear();
|
|
17
38
|
for (const waiting of calls.values())waiting.fail(failure);
|
|
18
39
|
calls.clear();
|
|
19
|
-
for (const listener of listeners.values()){
|
|
20
|
-
if (listener.topic === 'connection-refusal') listener.notify(reported);
|
|
21
|
-
}
|
|
22
40
|
}
|
|
23
|
-
function end() {
|
|
24
|
-
ended
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
function end(reason) {
|
|
42
|
+
if (ended !== null) return;
|
|
43
|
+
ended = reason;
|
|
44
|
+
const failure = new Error(reason);
|
|
45
|
+
for (const waiting of opening.values())waiting.fail(failure);
|
|
46
|
+
opening.clear();
|
|
28
47
|
for (const waiting of calls.values())waiting.fail(failure);
|
|
29
48
|
calls.clear();
|
|
30
|
-
|
|
49
|
+
for (const { handle } of observations.values())handle.end();
|
|
50
|
+
observations.clear();
|
|
31
51
|
}
|
|
32
52
|
port.addEventListener('message', (event)=>{
|
|
33
53
|
const wire = carried(event.data);
|
|
@@ -43,34 +63,35 @@ export function connectMdRuntime(port) {
|
|
|
43
63
|
return;
|
|
44
64
|
}
|
|
45
65
|
if (message.kind === 'ended') {
|
|
46
|
-
end();
|
|
66
|
+
end(AUTHORIZATION_ENDED);
|
|
47
67
|
return;
|
|
48
68
|
}
|
|
49
69
|
if (message.kind === 'event') {
|
|
50
|
-
|
|
70
|
+
observations.get(message.id)?.handle.receive(message.value);
|
|
51
71
|
return;
|
|
52
72
|
}
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
if (message.kind === 'failure')
|
|
57
|
-
|
|
58
|
-
subscribing.fail(new Error(message.message));
|
|
59
|
-
} else subscribing.settle();
|
|
73
|
+
const waiting = opening.get(message.id);
|
|
74
|
+
if (waiting !== undefined) {
|
|
75
|
+
opening.delete(message.id);
|
|
76
|
+
if (message.kind === 'failure') waiting.fail(new Error(message.message));
|
|
77
|
+
else waiting.settle(begin(message.id, waiting.topic, message.value));
|
|
60
78
|
return;
|
|
61
79
|
}
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
80
|
+
const called = calls.get(message.id);
|
|
81
|
+
if (called === undefined) return;
|
|
64
82
|
calls.delete(message.id);
|
|
65
|
-
if (message.kind === 'failure')
|
|
66
|
-
else
|
|
83
|
+
if (message.kind === 'failure') called.fail(new Error(message.message));
|
|
84
|
+
else called.settle(message.value);
|
|
85
|
+
});
|
|
86
|
+
port.addEventListener('close', ()=>{
|
|
87
|
+
end(PORT_CLOSED);
|
|
67
88
|
});
|
|
68
89
|
port.start();
|
|
69
90
|
send({
|
|
70
91
|
kind: 'hello'
|
|
71
92
|
});
|
|
72
93
|
function ask(member, input) {
|
|
73
|
-
if (ended) return Promise.reject(new Error(
|
|
94
|
+
if (ended !== null) return Promise.reject(new Error(ended));
|
|
74
95
|
if (refusal !== null) return Promise.reject(new Error(refusal.reason));
|
|
75
96
|
const id = sequence += 1;
|
|
76
97
|
return new Promise((settle, fail)=>{
|
|
@@ -86,27 +107,16 @@ export function connectMdRuntime(port) {
|
|
|
86
107
|
});
|
|
87
108
|
});
|
|
88
109
|
}
|
|
89
|
-
function watch(topic, input
|
|
90
|
-
if (ended) return Promise.reject(new Error(
|
|
110
|
+
function watch(topic, input) {
|
|
111
|
+
if (ended !== null) return Promise.reject(new Error(ended));
|
|
91
112
|
const id = sequence += 1;
|
|
92
|
-
listeners.set(id, {
|
|
93
|
-
topic,
|
|
94
|
-
notify
|
|
95
|
-
});
|
|
96
|
-
const end = ()=>{
|
|
97
|
-
if (!listeners.delete(id)) return;
|
|
98
|
-
if (refusal === null) send({
|
|
99
|
-
kind: 'stop',
|
|
100
|
-
id
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
113
|
if (refusal !== null) {
|
|
104
|
-
|
|
105
|
-
return Promise.resolve(end);
|
|
114
|
+
return topic === 'connection-refusal' ? Promise.resolve(begin(id, topic, refusal)) : Promise.reject(new Error(refusal.reason));
|
|
106
115
|
}
|
|
107
116
|
return new Promise((settle, fail)=>{
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
opening.set(id, {
|
|
118
|
+
topic,
|
|
119
|
+
settle,
|
|
110
120
|
fail
|
|
111
121
|
});
|
|
112
122
|
send({
|
|
@@ -123,6 +133,9 @@ export function connectMdRuntime(port) {
|
|
|
123
133
|
query: (query)=>ask('query', [
|
|
124
134
|
query
|
|
125
135
|
]),
|
|
136
|
+
search: (request)=>ask('search', [
|
|
137
|
+
request
|
|
138
|
+
]),
|
|
126
139
|
types: (locator)=>ask('types', [
|
|
127
140
|
locator
|
|
128
141
|
]),
|
|
@@ -210,19 +223,7 @@ export function connectMdRuntime(port) {
|
|
|
210
223
|
storageLoss: ()=>ask('storageLoss', []),
|
|
211
224
|
persistence: ()=>ask('persistence', []),
|
|
212
225
|
deploymentFacts: ()=>ask('deploymentFacts', []),
|
|
213
|
-
observe (topic,
|
|
214
|
-
if (topic === 'conversation') {
|
|
215
|
-
return watch(topic, [
|
|
216
|
-
second,
|
|
217
|
-
third
|
|
218
|
-
], fourth);
|
|
219
|
-
}
|
|
220
|
-
const positional = topic === 'query' || topic === 'queue';
|
|
221
|
-
const notify = positional ? third : second;
|
|
222
|
-
return watch(topic, positional ? [
|
|
223
|
-
second
|
|
224
|
-
] : [], notify);
|
|
225
|
-
},
|
|
226
|
+
observe: (topic, ...input)=>watch(topic, input),
|
|
226
227
|
reauthorize: ()=>ask('reauthorize', [])
|
|
227
228
|
};
|
|
228
229
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/client.ts"],"sourcesContent":["import type {\n AppRoom,\n AppSlot,\n ConnectionRefusal,\n HistoryQuery,\n RoomTypes,\n SavedRoomDraft,\n SaveResult,\n} from './connection.js';\nimport type { HistoryResult } from './adapter.js';\nimport type {\n ChatDraft,\n ConversationEntry,\n ConversationOptions,\n ConversationView,\n} from './conversation.js';\nimport type { CallResult, QueueEntry, SubmissionOutcome } from './outcome.js';\nimport type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';\nimport type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';\nimport type { SyncStatus } from './status.js';\nimport {\n answer,\n AUTHORIZATION_ENDED,\n carried,\n envelope,\n PROTOCOL_MISMATCH,\n type RuntimePort,\n type WireMember,\n type WireRequest,\n type WireTopic,\n} from './wire.js';\n\nexport type MdRuntimeClient = {\n rooms(): Promise<readonly AppRoom[]>;\n slots(): Promise<readonly AppSlot[]>;\n query: {\n (query: DocumentQuery): Promise<DocumentResult>;\n (query: GroupQuery): Promise<GroupResult>;\n };\n types(locator: string): Promise<RoomTypes>;\n syncStatus(): Promise<SyncStatus>;\n roomDraft: {\n list(): Promise<readonly RoomDraft[]>;\n read(room: string, path: string): Promise<RoomDraft | null>;\n write(\n room: string,\n path: string,\n revision: string | null,\n parts: RoomDraftParts,\n ): Promise<RoomDraftWrite>;\n discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;\n };\n save(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;\n outcome(identifier: string): Promise<SubmissionOutcome | null>;\n presentation: {\n read(): Promise<unknown>;\n write(value: unknown): Promise<void>;\n };\n conversation: {\n list(): Promise<readonly ConversationEntry[]>;\n read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;\n create(input: unknown): Promise<CallResult>;\n send(conversation: string): Promise<CallResult>;\n answer(conversation: string, answer: unknown): Promise<CallResult>;\n interrupt(conversation: string): Promise<CallResult>;\n kill(conversation: string): Promise<CallResult>;\n cancel(conversation: string, turn: string): Promise<CallResult>;\n delete(conversation: string): Promise<CallResult>;\n };\n chatDraft: {\n write(conversation: string, draft: ChatDraft): Promise<void>;\n discard(conversation: string): Promise<void>;\n };\n history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryResult>;\n call(name: string, input: unknown): Promise<CallResult>;\n log(): Promise<string>;\n storageLoss(): Promise<string | null>;\n persistence(): Promise<boolean>;\n deploymentFacts(): Promise<unknown>;\n observe: {\n (topic: 'deployment-facts', listener: (value: unknown) => void): Promise<() => void>;\n (topic: 'rooms', listener: (rooms: readonly AppRoom[]) => void): Promise<() => void>;\n (\n topic: 'connection-refusal',\n listener: (refusal: ConnectionRefusal | null) => void,\n ): Promise<() => void>;\n (topic: 'storage-loss', listener: (statement: string | null) => void): Promise<() => void>;\n (topic: 'sync-status', listener: (status: SyncStatus) => void): Promise<() => void>;\n (\n topic: 'query',\n query: DocumentQuery,\n listener: (result: DocumentResult) => void,\n ): Promise<() => void>;\n (\n topic: 'query',\n query: GroupQuery,\n listener: (result: GroupResult) => void,\n ): Promise<() => void>;\n (\n topic: 'queue',\n locator: string,\n listener: (entries: readonly QueueEntry[]) => void,\n ): Promise<() => void>;\n (\n topic: 'room-drafts',\n listener: (roomDrafts: readonly RoomDraft[]) => void,\n ): Promise<() => void>;\n (topic: 'presentation', listener: (value: unknown) => void): Promise<() => void>;\n (\n topic: 'conversation',\n conversation: string,\n options: ConversationOptions,\n listener: (view: ConversationView) => void,\n ): Promise<() => void>;\n };\n reauthorize(): Promise<void>;\n};\n\nexport function connectMdRuntime(port: RuntimePort): MdRuntimeClient {\n let sequence = 0;\n let refusal: ConnectionRefusal | null = null;\n let ended = false;\n const calls = new Map<\n number,\n { settle: (value: unknown) => void; fail: (error: Error) => void }\n >();\n const acks = new Map<number, { settle: () => void; fail: (error: Error) => void }>();\n const listeners = new Map<number, { topic: WireTopic; notify: (value: unknown) => void }>();\n\n const send = (message: WireRequest) => {\n port.postMessage(envelope(message));\n };\n\n function refuse(reported: ConnectionRefusal) {\n refusal = reported;\n for (const waiting of acks.values()) waiting.settle();\n acks.clear();\n const failure = new Error(reported.reason);\n for (const waiting of calls.values()) waiting.fail(failure);\n calls.clear();\n for (const listener of listeners.values()) {\n if (listener.topic === 'connection-refusal') listener.notify(reported);\n }\n }\n\n function end() {\n ended = true;\n const failure = new Error(AUTHORIZATION_ENDED);\n for (const waiting of acks.values()) waiting.fail(failure);\n acks.clear();\n for (const waiting of calls.values()) waiting.fail(failure);\n calls.clear();\n listeners.clear();\n }\n\n port.addEventListener('message', (event) => {\n const wire = carried(event.data);\n if (wire === null) return;\n if (!wire.matching) {\n refuse(PROTOCOL_MISMATCH);\n return;\n }\n const message = answer(wire.message);\n if (message === null) return;\n if (message.kind === 'refusal') {\n refuse(message.refusal);\n return;\n }\n if (message.kind === 'ended') {\n end();\n return;\n }\n if (message.kind === 'event') {\n listeners.get(message.id)?.notify(message.value);\n return;\n }\n const subscribing = acks.get(message.id);\n if (subscribing !== undefined) {\n acks.delete(message.id);\n if (message.kind === 'failure') {\n listeners.delete(message.id);\n subscribing.fail(new Error(message.message));\n } else subscribing.settle();\n return;\n }\n const waiting = calls.get(message.id);\n if (waiting === undefined) return;\n calls.delete(message.id);\n if (message.kind === 'failure') waiting.fail(new Error(message.message));\n else waiting.settle(message.value);\n });\n port.start();\n send({ kind: 'hello' });\n\n function ask<T>(member: WireMember, input: readonly unknown[]): Promise<T> {\n if (ended) return Promise.reject(new Error(AUTHORIZATION_ENDED));\n if (refusal !== null) return Promise.reject(new Error(refusal.reason));\n const id = (sequence += 1);\n return new Promise<T>((settle, fail) => {\n calls.set(id, { settle: settle as (value: unknown) => void, fail });\n send({ kind: 'call', id, member, input });\n });\n }\n\n function watch(\n topic: WireTopic,\n input: readonly unknown[],\n notify: (value: unknown) => void,\n ): Promise<() => void> {\n if (ended) return Promise.reject(new Error(AUTHORIZATION_ENDED));\n const id = (sequence += 1);\n listeners.set(id, { topic, notify });\n const end = () => {\n if (!listeners.delete(id)) return;\n if (refusal === null) send({ kind: 'stop', id });\n };\n if (refusal !== null) {\n if (topic === 'connection-refusal') notify(refusal);\n return Promise.resolve(end);\n }\n return new Promise<() => void>((settle, fail) => {\n acks.set(id, { settle: () => settle(end), fail });\n send({ kind: 'observe', id, topic, input });\n });\n }\n\n return {\n rooms: () => ask<readonly AppRoom[]>('rooms', []),\n slots: () => ask<readonly AppSlot[]>('slots', []),\n query: ((query: DocumentQuery | GroupQuery) =>\n ask('query', [query])) as MdRuntimeClient['query'],\n types: (locator: string) => ask<RoomTypes>('types', [locator]),\n syncStatus: () => ask<SyncStatus>('syncStatus', []),\n roomDraft: {\n list: () => ask<readonly RoomDraft[]>('roomDraft.list', []),\n read: (room: string, path: string) => ask<RoomDraft | null>('roomDraft.read', [room, path]),\n write: (room: string, path: string, revision: string | null, parts: RoomDraftParts) =>\n ask<RoomDraftWrite>('roomDraft.write', [room, path, revision, parts]),\n discard: (room: string, path: string, revision: string) =>\n ask<RoomDraftWrite>('roomDraft.discard', [room, path, revision]),\n },\n save: (room: string, roomDrafts: readonly SavedRoomDraft[]) =>\n ask<SaveResult>('save', [room, roomDrafts]),\n outcome: (identifier: string) => ask<SubmissionOutcome | null>('outcome', [identifier]),\n presentation: {\n read: () => ask<unknown>('presentation.read', []),\n write: (value: unknown) => ask<void>('presentation.write', [value]),\n },\n conversation: {\n list: () => ask<readonly ConversationEntry[]>('conversation.list', []),\n read: (conversation: string, options?: ConversationOptions) =>\n ask<ConversationView>('conversation.read', [conversation, options]),\n create: (input: unknown) => ask<CallResult>('conversation.create', [input]),\n send: (conversation: string) => ask<CallResult>('conversation.send', [conversation]),\n answer: (conversation: string, answer: unknown) =>\n ask<CallResult>('conversation.answer', [conversation, answer]),\n interrupt: (conversation: string) =>\n ask<CallResult>('conversation.interrupt', [conversation]),\n kill: (conversation: string) => ask<CallResult>('conversation.kill', [conversation]),\n cancel: (conversation: string, turn: string) =>\n ask<CallResult>('conversation.cancel', [conversation, turn]),\n delete: (conversation: string) => ask<CallResult>('conversation.delete', [conversation]),\n },\n chatDraft: {\n write: (conversation: string, draft: ChatDraft) =>\n ask<void>('chatDraft.write', [conversation, draft]),\n discard: (conversation: string) => ask<void>('chatDraft.discard', [conversation]),\n },\n history: (locator: string, path: string, query?: HistoryQuery) =>\n ask<HistoryResult>('history', [locator, path, query]),\n call: (name: string, input: unknown) => ask<CallResult>('call', [name, input]),\n log: () => ask<string>('log', []),\n storageLoss: () => ask<string | null>('storageLoss', []),\n persistence: () => ask<boolean>('persistence', []),\n deploymentFacts: () => ask<unknown>('deploymentFacts', []),\n observe(\n topic: WireTopic,\n second: unknown,\n third?: ConversationOptions | ((value: never) => void),\n fourth?: (value: never) => void,\n ) {\n if (topic === 'conversation') {\n return watch(topic, [second, third], fourth as (value: unknown) => void);\n }\n const positional = topic === 'query' || topic === 'queue';\n const notify = (positional ? third : second) as (value: unknown) => void;\n return watch(topic, positional ? [second] : [], notify);\n },\n reauthorize: () => ask<void>('reauthorize', []),\n };\n}\n\nexport type { RuntimePort } from './wire.js';\n"],"names":["answer","AUTHORIZATION_ENDED","carried","envelope","PROTOCOL_MISMATCH","connectMdRuntime","port","sequence","refusal","ended","calls","Map","acks","listeners","send","message","postMessage","refuse","reported","waiting","values","settle","clear","failure","Error","reason","fail","listener","topic","notify","end","addEventListener","event","wire","data","matching","kind","get","id","value","subscribing","undefined","delete","start","ask","member","input","Promise","reject","set","watch","resolve","rooms","slots","query","types","locator","syncStatus","roomDraft","list","read","room","path","write","revision","parts","discard","save","roomDrafts","outcome","identifier","presentation","conversation","options","create","interrupt","kill","cancel","turn","chatDraft","draft","history","call","name","log","storageLoss","persistence","deploymentFacts","observe","second","third","fourth","positional","reauthorize"],"mappings":"AAoBA,SACEA,MAAM,EACNC,mBAAmB,EACnBC,OAAO,EACPC,QAAQ,EACRC,iBAAiB,QAKZ,YAAY;AAwFnB,OAAO,SAASC,iBAAiBC,IAAiB;IAChD,IAAIC,WAAW;IACf,IAAIC,UAAoC;IACxC,IAAIC,QAAQ;IACZ,MAAMC,QAAQ,IAAIC;IAIlB,MAAMC,OAAO,IAAID;IACjB,MAAME,YAAY,IAAIF;IAEtB,MAAMG,OAAO,CAACC;QACZT,KAAKU,WAAW,CAACb,SAASY;IAC5B;IAEA,SAASE,OAAOC,QAA2B;QACzCV,UAAUU;QACV,KAAK,MAAMC,WAAWP,KAAKQ,MAAM,GAAID,QAAQE,MAAM;QACnDT,KAAKU,KAAK;QACV,MAAMC,UAAU,IAAIC,MAAMN,SAASO,MAAM;QACzC,KAAK,MAAMN,WAAWT,MAAMU,MAAM,GAAID,QAAQO,IAAI,CAACH;QACnDb,MAAMY,KAAK;QACX,KAAK,MAAMK,YAAYd,UAAUO,MAAM,GAAI;YACzC,IAAIO,SAASC,KAAK,KAAK,sBAAsBD,SAASE,MAAM,CAACX;QAC/D;IACF;IAEA,SAASY;QACPrB,QAAQ;QACR,MAAMc,UAAU,IAAIC,MAAMvB;QAC1B,KAAK,MAAMkB,WAAWP,KAAKQ,MAAM,GAAID,QAAQO,IAAI,CAACH;QAClDX,KAAKU,KAAK;QACV,KAAK,MAAMH,WAAWT,MAAMU,MAAM,GAAID,QAAQO,IAAI,CAACH;QACnDb,MAAMY,KAAK;QACXT,UAAUS,KAAK;IACjB;IAEAhB,KAAKyB,gBAAgB,CAAC,WAAW,CAACC;QAChC,MAAMC,OAAO/B,QAAQ8B,MAAME,IAAI;QAC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C4B;iBAAa;QAClF;QACAS,SAAS,CAACzB,SAAiBM,MAAcR,QACvCV,IAAmB,WAAW;gBAACY;gBAASM;gBAAMR;aAAM;QACtD4B,MAAM,CAACC,MAAcrC,QAAmBF,IAAgB,QAAQ;gBAACuC;gBAAMrC;aAAM;QAC7EsC,KAAK,IAAMxC,IAAY,OAAO,EAAE;QAChCyC,aAAa,IAAMzC,IAAmB,eAAe,EAAE;QACvD0C,aAAa,IAAM1C,IAAa,eAAe,EAAE;QACjD2C,iBAAiB,IAAM3C,IAAa,mBAAmB,EAAE;QACzD4C,SACE5D,KAAgB,EAChB6D,MAAe,EACfC,KAAsD,EACtDC,MAA+B;YAE/B,IAAI/D,UAAU,gBAAgB;gBAC5B,OAAOsB,MAAMtB,OAAO;oBAAC6D;oBAAQC;iBAAM,EAAEC;YACvC;YACA,MAAMC,aAAahE,UAAU,WAAWA,UAAU;YAClD,MAAMC,SAAU+D,aAAaF,QAAQD;YACrC,OAAOvC,MAAMtB,OAAOgE,aAAa;gBAACH;aAAO,GAAG,EAAE,EAAE5D;QAClD;QACAgE,aAAa,IAAMjD,IAAU,eAAe,EAAE;IAChD;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/client.ts"],"sourcesContent":["import type {\n AppRoom,\n AppSlot,\n ConnectionRefusal,\n HistoryQuery,\n RoomTypes,\n SavedRoomDraft,\n SaveResult,\n} from './connection.js';\nimport type { HistoryResult } from './adapter.js';\nimport type {\n ChatDraft,\n ConversationEntry,\n ConversationOptions,\n ConversationView,\n} from './conversation.js';\nimport { observed, type Observation, type Observed } from './observation.js';\nimport type { CallResult, QueueEntry, SubmissionOutcome } from './outcome.js';\nimport type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';\nimport type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';\nimport type { SearchRequest, SearchResult } from './search.js';\nimport type { SyncStatus } from './status.js';\nimport {\n answer,\n AUTHORIZATION_ENDED,\n carried,\n envelope,\n PORT_CLOSED,\n PROTOCOL_MISMATCH,\n type RuntimePort,\n type WireMember,\n type WireRequest,\n type WireTopic,\n} from './wire.js';\n\nexport type MdRuntimeClient = {\n rooms(): Promise<readonly AppRoom[]>;\n slots(): Promise<readonly AppSlot[]>;\n query: {\n (query: DocumentQuery): Promise<DocumentResult>;\n (query: GroupQuery): Promise<GroupResult>;\n };\n search(request: SearchRequest): Promise<SearchResult>;\n types(locator: string): Promise<RoomTypes>;\n syncStatus(): Promise<SyncStatus>;\n roomDraft: {\n list(): Promise<readonly RoomDraft[]>;\n read(room: string, path: string): Promise<RoomDraft | null>;\n write(\n room: string,\n path: string,\n revision: string | null,\n parts: RoomDraftParts,\n ): Promise<RoomDraftWrite>;\n discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;\n };\n save(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;\n outcome(identifier: string): Promise<SubmissionOutcome | null>;\n presentation: {\n read(): Promise<unknown>;\n write(value: unknown): Promise<void>;\n };\n conversation: {\n list(): Promise<readonly ConversationEntry[]>;\n read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;\n create(input: unknown): Promise<CallResult>;\n send(conversation: string): Promise<CallResult>;\n answer(conversation: string, answer: unknown): Promise<CallResult>;\n interrupt(conversation: string): Promise<CallResult>;\n kill(conversation: string): Promise<CallResult>;\n cancel(conversation: string, turn: string): Promise<CallResult>;\n delete(conversation: string): Promise<CallResult>;\n };\n chatDraft: {\n write(conversation: string, draft: ChatDraft): Promise<void>;\n discard(conversation: string): Promise<void>;\n };\n history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryResult>;\n call(name: string, input: unknown): Promise<CallResult>;\n log(): Promise<string>;\n storageLoss(): Promise<string | null>;\n persistence(): Promise<boolean>;\n deploymentFacts(): Promise<unknown>;\n observe: {\n (topic: 'deployment-facts'): Promise<Observation<unknown>>;\n (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;\n (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;\n (topic: 'storage-loss'): Promise<Observation<string | null>>;\n (topic: 'sync-status'): Promise<Observation<SyncStatus>>;\n (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult>>;\n (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult>>;\n (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;\n (topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;\n (topic: 'presentation'): Promise<Observation<unknown>>;\n (\n topic: 'conversation',\n conversation: string,\n options: ConversationOptions,\n ): Promise<Observation<ConversationView>>;\n };\n reauthorize(): Promise<void>;\n};\n\nexport function connectMdRuntime(port: RuntimePort): MdRuntimeClient {\n let sequence = 0;\n let refusal: ConnectionRefusal | null = null;\n let ended: string | null = null;\n const calls = new Map<\n number,\n { settle: (value: unknown) => void; fail: (error: Error) => void }\n >();\n const opening = new Map<\n number,\n {\n topic: WireTopic;\n settle: (observation: Observation<unknown>) => void;\n fail: (error: Error) => void;\n }\n >();\n const observations = new Map<number, { topic: WireTopic; handle: Observed }>();\n\n const send = (message: WireRequest) => {\n port.postMessage(envelope(message));\n };\n\n function begin(id: number, topic: WireTopic, first: unknown): Observation<unknown> {\n const handle = observed(\n first,\n () => {\n observations.delete(id);\n if (refusal === null) send({ kind: 'stop', id });\n },\n topic === 'query',\n );\n observations.set(id, { topic, handle });\n return handle.observation;\n }\n\n function refuse(reported: ConnectionRefusal) {\n refusal = reported;\n for (const { topic, handle } of observations.values()) {\n if (topic === 'connection-refusal') handle.receive(reported);\n }\n const failure = new Error(reported.reason);\n for (const [id, waiting] of opening) {\n if (waiting.topic === 'connection-refusal')\n waiting.settle(begin(id, waiting.topic, reported));\n else waiting.fail(failure);\n }\n opening.clear();\n for (const waiting of calls.values()) waiting.fail(failure);\n calls.clear();\n }\n\n function end(reason: string) {\n if (ended !== null) return;\n ended = reason;\n const failure = new Error(reason);\n for (const waiting of opening.values()) waiting.fail(failure);\n opening.clear();\n for (const waiting of calls.values()) waiting.fail(failure);\n calls.clear();\n for (const { handle } of observations.values()) handle.end();\n observations.clear();\n }\n\n port.addEventListener('message', (event) => {\n const wire = carried(event.data);\n if (wire === null) return;\n if (!wire.matching) {\n refuse(PROTOCOL_MISMATCH);\n return;\n }\n const message = answer(wire.message);\n if (message === null) return;\n if (message.kind === 'refusal') {\n refuse(message.refusal);\n return;\n }\n if (message.kind === 'ended') {\n end(AUTHORIZATION_ENDED);\n return;\n }\n if (message.kind === 'event') {\n observations.get(message.id)?.handle.receive(message.value);\n return;\n }\n const waiting = opening.get(message.id);\n if (waiting !== undefined) {\n opening.delete(message.id);\n if (message.kind === 'failure') waiting.fail(new Error(message.message));\n else waiting.settle(begin(message.id, waiting.topic, message.value));\n return;\n }\n const called = calls.get(message.id);\n if (called === undefined) return;\n calls.delete(message.id);\n if (message.kind === 'failure') called.fail(new Error(message.message));\n else called.settle(message.value);\n });\n port.addEventListener('close', () => {\n end(PORT_CLOSED);\n });\n port.start();\n send({ kind: 'hello' });\n\n function ask<T>(member: WireMember, input: readonly unknown[]): Promise<T> {\n if (ended !== null) return Promise.reject(new Error(ended));\n if (refusal !== null) return Promise.reject(new Error(refusal.reason));\n const id = (sequence += 1);\n return new Promise<T>((settle, fail) => {\n calls.set(id, { settle: settle as (value: unknown) => void, fail });\n send({ kind: 'call', id, member, input });\n });\n }\n\n function watch(topic: WireTopic, input: readonly unknown[]): Promise<Observation<unknown>> {\n if (ended !== null) return Promise.reject(new Error(ended));\n const id = (sequence += 1);\n if (refusal !== null) {\n return topic === 'connection-refusal'\n ? Promise.resolve(begin(id, topic, refusal))\n : Promise.reject(new Error(refusal.reason));\n }\n return new Promise((settle, fail) => {\n opening.set(id, { topic, settle, fail });\n send({ kind: 'observe', id, topic, input });\n });\n }\n\n return {\n rooms: () => ask<readonly AppRoom[]>('rooms', []),\n slots: () => ask<readonly AppSlot[]>('slots', []),\n query: ((query: DocumentQuery | GroupQuery) =>\n ask('query', [query])) as MdRuntimeClient['query'],\n search: (request: SearchRequest) => ask<SearchResult>('search', [request]),\n types: (locator: string) => ask<RoomTypes>('types', [locator]),\n syncStatus: () => ask<SyncStatus>('syncStatus', []),\n roomDraft: {\n list: () => ask<readonly RoomDraft[]>('roomDraft.list', []),\n read: (room: string, path: string) => ask<RoomDraft | null>('roomDraft.read', [room, path]),\n write: (room: string, path: string, revision: string | null, parts: RoomDraftParts) =>\n ask<RoomDraftWrite>('roomDraft.write', [room, path, revision, parts]),\n discard: (room: string, path: string, revision: string) =>\n ask<RoomDraftWrite>('roomDraft.discard', [room, path, revision]),\n },\n save: (room: string, roomDrafts: readonly SavedRoomDraft[]) =>\n ask<SaveResult>('save', [room, roomDrafts]),\n outcome: (identifier: string) => ask<SubmissionOutcome | null>('outcome', [identifier]),\n presentation: {\n read: () => ask<unknown>('presentation.read', []),\n write: (value: unknown) => ask<void>('presentation.write', [value]),\n },\n conversation: {\n list: () => ask<readonly ConversationEntry[]>('conversation.list', []),\n read: (conversation: string, options?: ConversationOptions) =>\n ask<ConversationView>('conversation.read', [conversation, options]),\n create: (input: unknown) => ask<CallResult>('conversation.create', [input]),\n send: (conversation: string) => ask<CallResult>('conversation.send', [conversation]),\n answer: (conversation: string, answer: unknown) =>\n ask<CallResult>('conversation.answer', [conversation, answer]),\n interrupt: (conversation: string) =>\n ask<CallResult>('conversation.interrupt', [conversation]),\n kill: (conversation: string) => ask<CallResult>('conversation.kill', [conversation]),\n cancel: (conversation: string, turn: string) =>\n ask<CallResult>('conversation.cancel', [conversation, turn]),\n delete: (conversation: string) => ask<CallResult>('conversation.delete', [conversation]),\n },\n chatDraft: {\n write: (conversation: string, draft: ChatDraft) =>\n ask<void>('chatDraft.write', [conversation, draft]),\n discard: (conversation: string) => ask<void>('chatDraft.discard', [conversation]),\n },\n history: (locator: string, path: string, query?: HistoryQuery) =>\n ask<HistoryResult>('history', [locator, path, query]),\n call: (name: string, input: unknown) => ask<CallResult>('call', [name, input]),\n log: () => ask<string>('log', []),\n storageLoss: () => ask<string | null>('storageLoss', []),\n persistence: () => ask<boolean>('persistence', []),\n deploymentFacts: () => ask<unknown>('deploymentFacts', []),\n observe: ((topic: WireTopic, ...input: unknown[]) =>\n watch(topic, input)) as MdRuntimeClient['observe'],\n reauthorize: () => ask<void>('reauthorize', []),\n };\n}\n\nexport type { Observation } from './observation.js';\nexport type { RuntimePort } from './wire.js';\n"],"names":["observed","answer","AUTHORIZATION_ENDED","carried","envelope","PORT_CLOSED","PROTOCOL_MISMATCH","connectMdRuntime","port","sequence","refusal","ended","calls","Map","opening","observations","send","message","postMessage","begin","id","topic","first","handle","delete","kind","set","observation","refuse","reported","values","receive","failure","Error","reason","waiting","settle","fail","clear","end","addEventListener","event","wire","data","matching","get","value","undefined","called","start","ask","member","input","Promise","reject","watch","resolve","rooms","slots","query","search","request","types","locator","syncStatus","roomDraft","list","read","room","path","write","revision","parts","discard","save","roomDrafts","outcome","identifier","presentation","conversation","options","create","interrupt","kill","cancel","turn","chatDraft","draft","history","call","name","log","storageLoss","persistence","deploymentFacts","observe","reauthorize"],"mappings":"AAgBA,SAASA,QAAQ,QAAyC,mBAAmB;AAM7E,SACEC,MAAM,EACNC,mBAAmB,EACnBC,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,iBAAiB,QAKZ,YAAY;AAsEnB,OAAO,SAASC,iBAAiBC,IAAiB;IAChD,IAAIC,WAAW;IACf,IAAIC,UAAoC;IACxC,IAAIC,QAAuB;IAC3B,MAAMC,QAAQ,IAAIC;IAIlB,MAAMC,UAAU,IAAID;IAQpB,MAAME,eAAe,IAAIF;IAEzB,MAAMG,OAAO,CAACC;QACZT,KAAKU,WAAW,CAACd,SAASa;IAC5B;IAEA,SAASE,MAAMC,EAAU,EAAEC,KAAgB,EAAEC,KAAc;QACzD,MAAMC,SAASvB,SACbsB,OACA;YACEP,aAAaS,MAAM,CAACJ;YACpB,IAAIV,YAAY,MAAMM,KAAK;gBAAES,MAAM;gBAAQL;YAAG;QAChD,GACAC,UAAU;QAE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KAAK,IAAMzC,IAAY,OAAO,EAAE;QAChC0C,aAAa,IAAM1C,IAAmB,eAAe,EAAE;QACvD2C,aAAa,IAAM3C,IAAa,eAAe,EAAE;QACjD4C,iBAAiB,IAAM5C,IAAa,mBAAmB,EAAE;QACzD6C,SAAU,CAAC1E,OAAkB,GAAG+B,QAC9BG,MAAMlC,OAAO+B;QACf4C,aAAa,IAAM9C,IAAU,eAAe,EAAE;IAChD;AACF"}
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type TypesResult } from './model.js';
|
|
2
|
+
import { type Observation } from './observation.js';
|
|
2
3
|
import { type DocumentQuery, type DocumentResult, type GroupQuery, type GroupResult } from './query.js';
|
|
4
|
+
import { type SearchRequest, type SearchResult } from './search.js';
|
|
3
5
|
import { type Adapter, type Authorization, type HistoryResult, type ProviderRefusal } from './adapter.js';
|
|
4
6
|
import { type ChatDraftSurface, type ConversationOptions, type ConversationSurface, type ConversationView } from './conversation.js';
|
|
5
7
|
import type { WrittenBy } from './change.js';
|
|
@@ -85,6 +87,7 @@ export type MdRuntime = {
|
|
|
85
87
|
(query: DocumentQuery): Promise<DocumentResult>;
|
|
86
88
|
(query: GroupQuery): Promise<GroupResult>;
|
|
87
89
|
};
|
|
90
|
+
search(request: SearchRequest): Promise<SearchResult>;
|
|
88
91
|
types(locator: string): RoomTypes;
|
|
89
92
|
syncStatus(): SyncStatus;
|
|
90
93
|
roomDraft: RoomDraftSurface;
|
|
@@ -99,18 +102,24 @@ export type MdRuntime = {
|
|
|
99
102
|
storageLoss(): string | null;
|
|
100
103
|
persistence(): boolean;
|
|
101
104
|
observe: {
|
|
102
|
-
(topic: 'rooms'
|
|
103
|
-
(topic: 'connection-refusal'
|
|
104
|
-
(topic: 'storage-loss'
|
|
105
|
-
(topic: 'sync-status'
|
|
106
|
-
(topic: 'query', query: DocumentQuery
|
|
107
|
-
(topic: 'query', query: GroupQuery
|
|
108
|
-
(topic: 'queue', locator: string
|
|
109
|
-
(topic: 'room-drafts'
|
|
110
|
-
(topic: 'presentation', app: string
|
|
111
|
-
(topic: 'conversation', conversation: string, options: ConversationOptions
|
|
105
|
+
(topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
|
|
106
|
+
(topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
|
|
107
|
+
(topic: 'storage-loss'): Promise<Observation<string | null>>;
|
|
108
|
+
(topic: 'sync-status'): Promise<Observation<SyncStatus>>;
|
|
109
|
+
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult>>;
|
|
110
|
+
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult>>;
|
|
111
|
+
(topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
|
|
112
|
+
(topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
|
|
113
|
+
(topic: 'presentation', app: string): Promise<Observation<unknown>>;
|
|
114
|
+
(topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
|
|
112
115
|
};
|
|
113
116
|
reauthorize(): Promise<void>;
|
|
114
117
|
};
|
|
118
|
+
export type RuntimeTopic = 'rooms' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation';
|
|
119
|
+
export type ComposedRuntime = {
|
|
120
|
+
md: MdRuntime;
|
|
121
|
+
watch(topic: RuntimeTopic, input: readonly unknown[], deliver: (message: unknown) => void): () => void;
|
|
122
|
+
};
|
|
115
123
|
export declare function createMdRuntime(options: MdRuntimeOptions): MdRuntime;
|
|
124
|
+
export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
|
|
116
125
|
//# sourceMappingURL=connection.d.ts.map
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,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