@agentshouse/mdruntime 0.1.0-alpha.22 → 0.1.0-alpha.24
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 +34 -18
- package/dist/bootstrap.d.ts +1 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +2 -2
- package/dist/bootstrap.js.map +1 -1
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js.map +1 -1
- package/dist/client.d.ts +9 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -20
- package/dist/client.js.map +1 -1
- package/dist/collection.d.ts +2 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +11 -16
- package/dist/collection.js.map +1 -1
- package/dist/connection.d.ts +15 -20
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +399 -299
- package/dist/connection.js.map +1 -1
- package/dist/durability.js +1 -1
- package/dist/durability.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +12 -14
- package/dist/host.js.map +1 -1
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +10 -24
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -1
- package/dist/model.js.map +1 -1
- package/dist/outcome.d.ts +17 -20
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -21
- package/dist/outcome.js.map +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +1 -1
- package/dist/overlay.js.map +1 -1
- package/dist/refresh.d.ts +1 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +2 -2
- package/dist/refresh.js.map +1 -1
- package/dist/replica.d.ts +3 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +59 -5
- package/dist/replica.js.map +1 -1
- package/dist/room-draft.d.ts +124 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +403 -0
- package/dist/room-draft.js.map +1 -0
- package/dist/save.d.ts +4 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +41 -130
- package/dist/save.js.map +1 -1
- package/dist/status.d.ts +4 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js.map +1 -1
- package/dist/store.d.ts +18 -12
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +43 -34
- package/dist/store.js.map +1 -1
- package/dist/wire.d.ts +3 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -7
- package/dist/wire.js.map +1 -1
- package/package.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ 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, Draft, Save,
|
|
10
|
+
Rooms, Slots, Query, 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
|
|
|
@@ -22,7 +22,7 @@ queued.
|
|
|
22
22
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
23
23
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
|
24
24
|
|
|
25
|
-
Rooms, Slots, Query, Observe, Types, Draft, and Save never touch the network.
|
|
25
|
+
Rooms, Slots, Query, Observe, Types, Room Draft, and Save never touch the network.
|
|
26
26
|
History and Call go to the Provider through the Adapter. Every member of the
|
|
27
27
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
28
28
|
surface returns the authorization, performs a request the App's code
|
|
@@ -36,24 +36,40 @@ owns their boundary.
|
|
|
36
36
|
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
37
37
|
ships in no bundle.
|
|
38
38
|
|
|
39
|
-
## Draft, Save, and outcome rules
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
## Room Draft, Save, and outcome rules
|
|
40
|
+
|
|
41
|
+
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
42
|
+
tab. It is durable: it survives reload and navigation. A Room that Discovery
|
|
43
|
+
stops listing takes its Room Drafts, its queue and their outcomes with it.
|
|
44
|
+
Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
|
|
45
|
+
the revision you read, or `null` when there was none, and every part it should
|
|
46
|
+
now change: fields, sections and the preamble, or the whole Markdown, a
|
|
47
|
+
creation, a move, or a removal. A part new to the Room Draft names its base,
|
|
48
|
+
the value you showed when it was opened; the MD Runtime keeps a part's first
|
|
49
|
+
base. A write or a discard from an older revision is refused as `stale` with
|
|
50
|
+
the current Room Draft; read it and write again.
|
|
51
|
+
|
|
52
|
+
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
53
|
+
validates locally, and on success appends one Change Batch to that Room's
|
|
54
|
+
queue and removes those Room Drafts. It is refused as `stale`, as
|
|
55
|
+
`changed-underneath` naming each part whose base no longer matches the visible
|
|
56
|
+
state, or by a local validation rule, and then creates nothing and leaves every
|
|
57
|
+
Room Draft in place. A directory move is a move part on each Document beneath
|
|
58
|
+
it, saved together.
|
|
46
59
|
|
|
47
60
|
Outcomes follow the Provider's answer. Accepted advances the confirmed
|
|
48
|
-
layer. Conflicted and Rejected
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
layer. Conflicted and Rejected, an expired outcome record, and a change that no
|
|
62
|
+
longer applies over the Room each leave the queue and return as Room Drafts on
|
|
63
|
+
the Documents they changed, marked with why: the Provider's structured refusal
|
|
64
|
+
code and fields as returned, not known to have applied, or withdrawn locally.
|
|
65
|
+
The rest of the queue keeps synchronizing, and Sync Status requires attention
|
|
66
|
+
until each returned Room Draft is saved again or discarded. `outcome` answers
|
|
67
|
+
the saved Change Batch's outcome, and `null` while it is Pending. Transport
|
|
68
|
+
failure and Provider unavailability keep work Pending and do not infer a
|
|
69
|
+
rejection. A refusal the Provider marks retryable stays Pending until the reset
|
|
70
|
+
it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
71
|
+
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
72
|
+
combines, reorders, or rebases.
|
|
57
73
|
|
|
58
74
|
## The neutrality rule
|
|
59
75
|
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AttachedModelBinding } from './model.js';
|
|
2
1
|
import type { ModelState } from './model.js';
|
|
3
2
|
import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom } from './adapter.js';
|
|
4
3
|
import { type ConfirmedLayer } from './replica.js';
|
|
@@ -10,5 +9,5 @@ export type BootstrapOutcome = {
|
|
|
10
9
|
export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom, models: {
|
|
11
10
|
collection: ModelState;
|
|
12
11
|
selection: ModelState;
|
|
13
|
-
}
|
|
12
|
+
}): Promise<BootstrapOutcome>;
|
|
14
13
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC7C,WAAW,GACX,cAAc,CAAC;AAEnB,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,GACxD,OAAO,CAAC,gBAAgB,CAAC,CAyC3B"}
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readStaged } from './replica.js';
|
|
2
2
|
import { unconfirmed } from './transfer.js';
|
|
3
|
-
export async function bootstrapRoom(adapter, authorization, room, models
|
|
3
|
+
export async function bootstrapRoom(adapter, authorization, room, models) {
|
|
4
4
|
const first = await adapter.bootstrap(authorization, {
|
|
5
5
|
locator: room.locator,
|
|
6
6
|
selection: room.replica.selection
|
|
@@ -45,7 +45,7 @@ export async function bootstrapRoom(adapter, authorization, room, models, bindin
|
|
|
45
45
|
...binaryTargets
|
|
46
46
|
].sort(),
|
|
47
47
|
revisions
|
|
48
|
-
}
|
|
48
|
+
});
|
|
49
49
|
return confirmed === null ? unconfirmed : {
|
|
50
50
|
kind: 'staged',
|
|
51
51
|
confirmed
|
package/dist/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/bootstrap.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/bootstrap.ts"],"sourcesContent":["import type { ModelState } from './model.js';\nimport type { Adapter, AdapterFailure, Authorization, DiscoveredRoom } from './adapter.js';\nimport { readStaged, type ConfirmedLayer } from './replica.js';\nimport { unconfirmed, type Unconfirmed } from './transfer.js';\n\nexport type BootstrapOutcome =\n | { kind: 'staged'; confirmed: ConfirmedLayer }\n | Unconfirmed\n | AdapterFailure;\n\nexport async function bootstrapRoom(\n adapter: Adapter,\n authorization: Authorization,\n room: DiscoveredRoom,\n models: { collection: ModelState; selection: ModelState },\n): Promise<BootstrapOutcome> {\n const first = await adapter.bootstrap(authorization, {\n locator: room.locator,\n selection: room.replica.selection,\n });\n if (first.kind !== 'bootstrap') return first;\n const roomVersion = first.roomVersion;\n const documents: Record<string, string> = { ...first.documents };\n const revisions: Record<string, string> = { ...first.revisions };\n const binaryTargets = new Set(first.binaryTargets);\n let pageToken = first.pageToken;\n while (pageToken !== undefined) {\n const page = await adapter.bootstrap(authorization, {\n locator: room.locator,\n selection: room.replica.selection,\n pageToken,\n });\n if (page.kind !== 'bootstrap') return page;\n if (page.roomVersion !== roomVersion) return unconfirmed;\n Object.assign(documents, page.documents);\n Object.assign(revisions, page.revisions);\n for (const target of page.binaryTargets) binaryTargets.add(target);\n pageToken = page.pageToken;\n }\n const confirmed = readStaged({\n locator: room.locator,\n collectionRoot: room.collectionRoot,\n name: room.name,\n operations: room.operations,\n replica: room.replica,\n attachedModel: room.attachedModel,\n model: models.collection,\n typedSelection: room.typedSelection ?? null,\n selectionModel: models.selection,\n providerOwnedPaths: room.providerOwnedPaths,\n roomVersion,\n documents,\n binaryTargets: [...binaryTargets].sort(),\n revisions,\n });\n return confirmed === null ? unconfirmed : { kind: 'staged', confirmed };\n}\n"],"names":["readStaged","unconfirmed","bootstrapRoom","adapter","authorization","room","models","first","bootstrap","locator","selection","replica","kind","roomVersion","documents","revisions","binaryTargets","Set","pageToken","undefined","page","Object","assign","target","add","confirmed","collectionRoot","name","operations","attachedModel","model","collection","typedSelection","selectionModel","providerOwnedPaths","sort"],"mappings":"AAEA,SAASA,UAAU,QAA6B,eAAe;AAC/D,SAASC,WAAW,QAA0B,gBA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gB3B,OAAOI,SAAS;QAChCwB,oBAAoB7B,KAAK6B,kBAAkB;QAC3CrB;QACAC;QACAE,eAAe;eAAIA;SAAc,CAACmB,IAAI;QACtCpB;IACF;IACA,OAAOU,cAAc,OAAOxB,cAAc;QAAEW,MAAM;QAAUa;IAAU;AACxE"}
|
package/dist/change.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export type Change = {
|
|
|
17
17
|
readonly path: string;
|
|
18
18
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
19
19
|
readonly sections: Readonly<Record<string, string>>;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'create';
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly content: string;
|
|
20
24
|
} | {
|
|
21
25
|
readonly kind: 'replace';
|
|
22
26
|
readonly path: string;
|
package/dist/change.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5E;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,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":["/workspace/packages/mdruntime/src/change.ts"],"sourcesContent":["export type Change =\n | {\n readonly kind: 'field';\n readonly path: string;\n readonly name: string;\n readonly value: unknown;\n }\n | {\n readonly kind: 'section';\n readonly path: string;\n readonly name: string;\n readonly value: string;\n }\n | { readonly kind: 'preamble'; readonly path: string; readonly value: string }\n | {\n readonly kind: 'create';\n readonly path: string;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly sections: Readonly<Record<string, string>>;\n }\n | { readonly kind: 'replace'; readonly path: string; readonly content: string }\n | { readonly kind: 'move'; readonly path: string; readonly to: string }\n | { readonly kind: 'remove'; readonly path: string };\n\nexport type Precondition =\n | {\n readonly kind: 'field';\n readonly path: string;\n readonly name: string;\n readonly value: unknown;\n }\n | {\n readonly kind: 'section';\n readonly path: string;\n readonly name: string;\n readonly value: string;\n }\n | { readonly kind: 'preamble'; readonly path: string; readonly value: string }\n | { readonly kind: 'revision'; readonly path: string; readonly revision: string }\n | { readonly kind: 'present'; readonly path: string }\n | { readonly kind: 'absent'; readonly path: string };\n\nexport type WrittenBy = { readonly app: string; readonly release: string };\n\nexport type ChangeBatch = {\n validation?: import('./model.js').ValidationReceipt;\n readonly id: string;\n readonly baseRoomVersion: string;\n readonly changes: readonly Change[];\n readonly preconditions: readonly Precondition[];\n readonly writtenBy?: WrittenBy;\n};\n\nfunction frozen<T>(value: T): T {\n if (Array.isArray(value)) return Object.freeze(value.map((item) => frozen(item))) as T;\n if (value === null || typeof value !== 'object') return value;\n const copy: Record<string, unknown> = {};\n for (const [name, item] of Object.entries(value)) copy[name] = frozen(item);\n return Object.freeze(copy) as T;\n}\n\nexport function immutable(batch: ChangeBatch): ChangeBatch {\n return frozen(batch);\n}\n"],"names":["frozen","value","Array","isArray","Object","freeze","map","item","copy","name","entries","immutable","batch"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/change.ts"],"sourcesContent":["export type Change =\n | {\n readonly kind: 'field';\n readonly path: string;\n readonly name: string;\n readonly value: unknown;\n }\n | {\n readonly kind: 'section';\n readonly path: string;\n readonly name: string;\n readonly value: string;\n }\n | { readonly kind: 'preamble'; readonly path: string; readonly value: string }\n | {\n readonly kind: 'create';\n readonly path: string;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly sections: Readonly<Record<string, string>>;\n }\n | { readonly kind: 'create'; readonly path: string; readonly content: string }\n | { readonly kind: 'replace'; readonly path: string; readonly content: string }\n | { readonly kind: 'move'; readonly path: string; readonly to: string }\n | { readonly kind: 'remove'; readonly path: string };\n\nexport type Precondition =\n | {\n readonly kind: 'field';\n readonly path: string;\n readonly name: string;\n readonly value: unknown;\n }\n | {\n readonly kind: 'section';\n readonly path: string;\n readonly name: string;\n readonly value: string;\n }\n | { readonly kind: 'preamble'; readonly path: string; readonly value: string }\n | { readonly kind: 'revision'; readonly path: string; readonly revision: string }\n | { readonly kind: 'present'; readonly path: string }\n | { readonly kind: 'absent'; readonly path: string };\n\nexport type WrittenBy = { readonly app: string; readonly release: string };\n\nexport type ChangeBatch = {\n validation?: import('./model.js').ValidationReceipt;\n readonly id: string;\n readonly baseRoomVersion: string;\n readonly changes: readonly Change[];\n readonly preconditions: readonly Precondition[];\n readonly writtenBy?: WrittenBy;\n};\n\nfunction frozen<T>(value: T): T {\n if (Array.isArray(value)) return Object.freeze(value.map((item) => frozen(item))) as T;\n if (value === null || typeof value !== 'object') return value;\n const copy: Record<string, unknown> = {};\n for (const [name, item] of Object.entries(value)) copy[name] = frozen(item);\n return Object.freeze(copy) as T;\n}\n\nexport function immutable(batch: ChangeBatch): ChangeBatch {\n return frozen(batch);\n}\n"],"names":["frozen","value","Array","isArray","Object","freeze","map","item","copy","name","entries","immutable","batch"],"mappings":"AAsDA,SAASA,OAAUC,KAAQ;IACzB,IAAIC,MAAMC,OAAO,CAACF,QAAQ,OAAOG,OAAOC,MAAM,CAACJ,MAAMK,GAAG,CAAC,CAACC,OAASP,OAAOO;IAC1E,IAAIN,UAAU,QAAQ,OAAOA,UAAU,UAAU,OAAOA;IACxD,MAAMO,OAAgC,CAAC;IACvC,KAAK,MAAM,CAACC,MAAMF,KAAK,IAAIH,OAAOM,OAAO,CAACT,OAAQO,IAAI,CAACC,KAAK,GAAGT,OAAOO;IACtE,OAAOH,OAAOC,MAAM,CAACG;AACvB;AAEA,OAAO,SAASG,UAAUC,KAAkB;IAC1C,OAAOZ,OAAOY;AAChB"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { QueryOptions, QueryResult } from '@agentshouse/query';
|
|
2
|
-
import type {
|
|
3
|
-
import type { AppRoom, AppSlot, ConnectionRefusal, DraftEntry, HistoryQuery, RoomTypes, SaveResult } from './connection.js';
|
|
2
|
+
import type { AppRoom, AppSlot, ConnectionRefusal, HistoryQuery, RoomTypes, SavedRoomDraft, SaveResult } from './connection.js';
|
|
4
3
|
import type { HistoryResult } from './adapter.js';
|
|
5
4
|
import type { ChatDraft, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
6
5
|
import type { CallResult, QueueEntry, SubmissionOutcome } from './outcome.js';
|
|
6
|
+
import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
|
|
7
7
|
import type { SyncStatus } from './status.js';
|
|
8
8
|
import { type RuntimePort } from './wire.js';
|
|
9
9
|
export type MdRuntimeClient = {
|
|
@@ -12,17 +12,14 @@ export type MdRuntimeClient = {
|
|
|
12
12
|
query(options?: QueryOptions): Promise<QueryResult>;
|
|
13
13
|
types(locator: string): Promise<RoomTypes>;
|
|
14
14
|
syncStatus(): Promise<SyncStatus>;
|
|
15
|
-
|
|
16
|
-
list(): Promise<readonly
|
|
17
|
-
read(
|
|
18
|
-
|
|
19
|
-
discard(
|
|
15
|
+
roomDraft: {
|
|
16
|
+
list(): Promise<readonly RoomDraft[]>;
|
|
17
|
+
read(room: string, path: string): Promise<RoomDraft | null>;
|
|
18
|
+
write(room: string, path: string, revision: string | null, parts: RoomDraftParts): Promise<RoomDraftWrite>;
|
|
19
|
+
discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
|
|
20
20
|
};
|
|
21
|
-
save(
|
|
21
|
+
save(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;
|
|
22
22
|
outcome(identifier: string): Promise<SubmissionOutcome | null>;
|
|
23
|
-
queue: {
|
|
24
|
-
discard(locator: string, identifier: string): Promise<void>;
|
|
25
|
-
};
|
|
26
23
|
presentation: {
|
|
27
24
|
read(): Promise<unknown>;
|
|
28
25
|
write(value: unknown): Promise<void>;
|
|
@@ -56,7 +53,7 @@ export type MdRuntimeClient = {
|
|
|
56
53
|
(topic: 'sync-status', listener: (status: SyncStatus) => void): Promise<() => void>;
|
|
57
54
|
(topic: 'query', query: QueryOptions, listener: (result: QueryResult) => void): Promise<() => void>;
|
|
58
55
|
(topic: 'queue', locator: string, listener: (entries: readonly QueueEntry[]) => void): Promise<() => void>;
|
|
59
|
-
(topic: 'drafts', listener: (
|
|
56
|
+
(topic: 'room-drafts', listener: (roomDrafts: readonly RoomDraft[]) => void): Promise<() => void>;
|
|
60
57
|
(topic: 'presentation', listener: (value: unknown) => void): Promise<() => void>;
|
|
61
58
|
(topic: 'conversation', conversation: string, options: ConversationOptions, listener: (view: ConversationView) => void): Promise<() => void>;
|
|
62
59
|
};
|
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,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,SAAS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,CAAC,MAAM,IAAI,CAAC,CAAC;QACpF,CACE,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GACtC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACvB,CACE,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,KAAK,IAAI,GACjD,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACvB,CACE,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,KAAK,IAAI,GACnD,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACvB,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACjF,CACE,KAAK,EAAE,cAAc,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GACzC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;KACxB,CAAC;IACF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,eAAe,CA2KnE;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -127,36 +127,31 @@ export function connectMdRuntime(port) {
|
|
|
127
127
|
locator
|
|
128
128
|
]),
|
|
129
129
|
syncStatus: ()=>ask('syncStatus', []),
|
|
130
|
-
|
|
131
|
-
list: ()=>ask('
|
|
132
|
-
read: (
|
|
133
|
-
|
|
130
|
+
roomDraft: {
|
|
131
|
+
list: ()=>ask('roomDraft.list', []),
|
|
132
|
+
read: (room, path)=>ask('roomDraft.read', [
|
|
133
|
+
room,
|
|
134
134
|
path
|
|
135
135
|
]),
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
write: (room, path, revision, parts)=>ask('roomDraft.write', [
|
|
137
|
+
room,
|
|
138
138
|
path,
|
|
139
|
-
|
|
139
|
+
revision,
|
|
140
|
+
parts
|
|
140
141
|
]),
|
|
141
|
-
discard: (
|
|
142
|
-
|
|
143
|
-
path
|
|
142
|
+
discard: (room, path, revision)=>ask('roomDraft.discard', [
|
|
143
|
+
room,
|
|
144
|
+
path,
|
|
145
|
+
revision
|
|
144
146
|
])
|
|
145
147
|
},
|
|
146
|
-
save: (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
replacing
|
|
148
|
+
save: (room, roomDrafts)=>ask('save', [
|
|
149
|
+
room,
|
|
150
|
+
roomDrafts
|
|
150
151
|
]),
|
|
151
152
|
outcome: (identifier)=>ask('outcome', [
|
|
152
153
|
identifier
|
|
153
154
|
]),
|
|
154
|
-
queue: {
|
|
155
|
-
discard: (locator, identifier)=>ask('queue.discard', [
|
|
156
|
-
locator,
|
|
157
|
-
identifier
|
|
158
|
-
])
|
|
159
|
-
},
|
|
160
155
|
presentation: {
|
|
161
156
|
read: ()=>ask('presentation.read', []),
|
|
162
157
|
write: (value)=>ask('presentation.write', [
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/client.ts"],"sourcesContent":["import type { QueryOptions, QueryResult } from '@agentshouse/query';\nimport type { Change } from './change.js';\nimport type {\n AppRoom,\n AppSlot,\n ConnectionRefusal,\n DraftEntry,\n HistoryQuery,\n RoomTypes,\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 { 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(options?: QueryOptions): Promise<QueryResult>;\n types(locator: string): Promise<RoomTypes>;\n syncStatus(): Promise<SyncStatus>;\n draft: {\n list(): Promise<readonly DraftEntry[]>;\n read(locator: string, path: string): Promise<unknown>;\n replace(locator: string, path: string, content: unknown): Promise<void>;\n discard(locator: string, path: string): Promise<void>;\n };\n save(locator: string, changes: readonly Change[], replacing?: string): Promise<SaveResult>;\n outcome(identifier: string): Promise<SubmissionOutcome | null>;\n queue: { discard(locator: string, identifier: string): Promise<void> };\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: QueryOptions,\n listener: (result: QueryResult) => void,\n ): Promise<() => void>;\n (\n topic: 'queue',\n locator: string,\n listener: (entries: readonly QueueEntry[]) => void,\n ): Promise<() => void>;\n (topic: 'drafts', listener: (drafts: readonly DraftEntry[]) => void): 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: (options?: QueryOptions) => ask<QueryResult>('query', [options]),\n types: (locator: string) => ask<RoomTypes>('types', [locator]),\n syncStatus: () => ask<SyncStatus>('syncStatus', []),\n draft: {\n list: () => ask<readonly DraftEntry[]>('draft.list', []),\n read: (locator: string, path: string) => ask<unknown>('draft.read', [locator, path]),\n replace: (locator: string, path: string, content: unknown) =>\n ask<void>('draft.replace', [locator, path, content]),\n discard: (locator: string, path: string) => ask<void>('draft.discard', [locator, path]),\n },\n save: (locator: string, changes: readonly Change[], replacing?: string) =>\n ask<SaveResult>('save', [locator, changes, replacing]),\n outcome: (identifier: string) => ask<SubmissionOutcome | null>('outcome', [identifier]),\n queue: {\n discard: (locator: string, identifier: string) =>\n ask<void>('queue.discard', [locator, identifier]),\n },\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: QueryOptions | string | ((value: never) => void),\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","options","types","locator","syncStatus","draft","list","read","path","replace","content","discard","save","changes","replacing","outcome","identifier","queue","presentation","write","conversation","create","interrupt","kill","cancel","turn","chatDraft","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;AAyEnB,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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9B,IAAgB,0BAA0B;oBAAC8B;iBAAa;YAC1DG,MAAM,CAACH,eAAyB9B,IAAgB,qBAAqB;oBAAC8B;iBAAa;YACnFI,QAAQ,CAACJ,cAAsBK,OAC7BnC,IAAgB,uBAAuB;oBAAC8B;oBAAcK;iBAAK;YAC7DrC,QAAQ,CAACgC,eAAyB9B,IAAgB,uBAAuB;oBAAC8B;iBAAa;QACzF;QACAM,WAAW;YACTP,OAAO,CAACC,cAAsBf,QAC5Bf,IAAU,mBAAmB;oBAAC8B;oBAAcf;iBAAM;YACpDM,SAAS,CAACS,eAAyB9B,IAAU,qBAAqB;oBAAC8B;iBAAa;QAClF;QACAO,SAAS,CAACxB,SAAiBK,MAAcR,QACvCV,IAAmB,WAAW;gBAACa;gBAASK;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,MAAwD,EACxDC,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 { QueryOptions, QueryResult } from '@agentshouse/query';\nimport 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 { 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(options?: QueryOptions): Promise<QueryResult>;\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: QueryOptions,\n listener: (result: QueryResult) => 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: (options?: QueryOptions) => ask<QueryResult>('query', [options]),\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: QueryOptions | string | ((value: never) => void),\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","options","types","locator","syncStatus","roomDraft","list","read","room","path","write","revision","parts","discard","save","roomDrafts","outcome","identifier","presentation","conversation","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;AAgFnB,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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U+D,aAAaF,QAAQD;YACrC,OAAOvC,MAAMtB,OAAOgE,aAAa;gBAACH;aAAO,GAAG,EAAE,EAAE5D;QAClD;QACAgE,aAAa,IAAMjD,IAAU,eAAe,EAAE;IAChD;AACF"}
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { type Document, type Validation } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { Selector } from '@agentshouse/query';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ModelState } from './model.js';
|
|
4
4
|
import type { MdModelIdentity } from './adapter.js';
|
|
5
5
|
export declare const MD_MODEL: MdModelIdentity;
|
|
6
6
|
export declare const PRESENTED: Selector;
|
|
7
|
-
export type MdType = {
|
|
8
|
-
name: string;
|
|
9
|
-
path: string;
|
|
10
|
-
fields: Readonly<Record<string, unknown>>;
|
|
11
|
-
sections: Readonly<Record<string, unknown>>;
|
|
12
|
-
};
|
|
13
7
|
export type Collection = {
|
|
14
8
|
documents: Readonly<Record<string, Document>>;
|
|
15
9
|
composition: Composition;
|
|
@@ -23,7 +17,6 @@ export type Composition = {
|
|
|
23
17
|
} | null;
|
|
24
18
|
};
|
|
25
19
|
export declare function governing(composition: Composition, path: string): ModelState;
|
|
26
|
-
export declare function typesAt(composition: Composition, path: string): readonly MdType[];
|
|
27
20
|
export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: {
|
|
28
21
|
text: Readonly<Record<string, string>>;
|
|
29
22
|
collection: Collection;
|
|
@@ -33,7 +26,5 @@ export declare function readCollection(text: Readonly<Record<string, string>>, c
|
|
|
33
26
|
collection: Collection;
|
|
34
27
|
}): Collection | null;
|
|
35
28
|
export declare function validRoot(root: unknown): root is string;
|
|
36
|
-
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition
|
|
37
|
-
source?: 'content' | 'model';
|
|
38
|
-
};
|
|
29
|
+
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
|
|
39
30
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,eAAO,MAAM,SAAS,EAAE,QAAyC,CAAC;AAIlE,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE,CAAC;AASF,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAC5E,UAAU,CAYZ;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAC5E,UAAU,GAAG,IAAI,CAenB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AA0CD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,WAAW,EAAE,WAAW,GACvB,UAAU,CA0CZ"}
|
package/dist/collection.js
CHANGED
|
@@ -9,16 +9,15 @@ export const PRESENTED = {
|
|
|
9
9
|
$regex: '\\.md$'
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
+
const NO_TYPES = {
|
|
13
|
+
types: {}
|
|
14
|
+
};
|
|
12
15
|
function selected(composition, path) {
|
|
13
16
|
return composition.selection !== null && composition.selection.roots.some((root)=>beneath(root, path));
|
|
14
17
|
}
|
|
15
18
|
export function governing(composition, path) {
|
|
16
19
|
return composition.selection !== null && selected(composition, path) ? composition.selection.model : composition.model;
|
|
17
20
|
}
|
|
18
|
-
export function typesAt(composition, path) {
|
|
19
|
-
const model = governing(composition, path);
|
|
20
|
-
return model.status === 'unavailable' ? [] : model.types;
|
|
21
|
-
}
|
|
22
21
|
export function parseCollection(text, composition, previous) {
|
|
23
22
|
const documents = {};
|
|
24
23
|
for (const path of Object.keys(text).sort()){
|
|
@@ -48,8 +47,8 @@ export function validRoot(root) {
|
|
|
48
47
|
function member(path, root) {
|
|
49
48
|
return root === '' || path.startsWith(`${root}/`);
|
|
50
49
|
}
|
|
51
|
-
function validateAgainst(documents, binaryTargets, prefix, model
|
|
52
|
-
if (model.status === 'unavailable'
|
|
50
|
+
function validateAgainst(documents, binaryTargets, prefix, model) {
|
|
51
|
+
if (model.status === 'unavailable') {
|
|
53
52
|
const typed = Object.entries(documents).find(([, content])=>{
|
|
54
53
|
const parsed = parse(content);
|
|
55
54
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
@@ -60,16 +59,12 @@ function validateAgainst(documents, binaryTargets, prefix, model, binding) {
|
|
|
60
59
|
file: `${prefix}${typed[0]}`,
|
|
61
60
|
version: VERSION
|
|
62
61
|
};
|
|
63
|
-
return validate(documents, {
|
|
64
|
-
binaryTargets
|
|
65
|
-
});
|
|
66
62
|
}
|
|
67
|
-
const verdict =
|
|
68
|
-
model: model.snapshot,
|
|
69
|
-
documents,
|
|
63
|
+
const verdict = validate(documents, {
|
|
70
64
|
binaryTargets
|
|
65
|
+
}, model.status === 'unavailable' ? NO_TYPES : {
|
|
66
|
+
types: model.types
|
|
71
67
|
});
|
|
72
|
-
if (verdict.verdict === 'refuse' && verdict.source === 'model') return verdict;
|
|
73
68
|
if (verdict.verdict === 'accept') return verdict;
|
|
74
69
|
return {
|
|
75
70
|
...verdict,
|
|
@@ -79,7 +74,7 @@ function validateAgainst(documents, binaryTargets, prefix, model, binding) {
|
|
|
79
74
|
}
|
|
80
75
|
};
|
|
81
76
|
}
|
|
82
|
-
export function validateCollection(text, binaryTargets, composition
|
|
77
|
+
export function validateCollection(text, binaryTargets, composition) {
|
|
83
78
|
const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
|
|
84
79
|
const collection = {};
|
|
85
80
|
const selection = {};
|
|
@@ -107,10 +102,10 @@ export function validateCollection(text, binaryTargets, composition, binding) {
|
|
|
107
102
|
}
|
|
108
103
|
}
|
|
109
104
|
const verdicts = [
|
|
110
|
-
validateAgainst(collection, binaryTargets.filter((path)=>member(path, composition.collectionRoot)).map((path)=>path.slice(prefix.length)), prefix, composition.model
|
|
105
|
+
validateAgainst(collection, binaryTargets.filter((path)=>member(path, composition.collectionRoot)).map((path)=>path.slice(prefix.length)), prefix, composition.model)
|
|
111
106
|
];
|
|
112
107
|
if (composition.selection !== null) {
|
|
113
|
-
verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)), '', composition.selection.model
|
|
108
|
+
verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)), '', composition.selection.model));
|
|
114
109
|
}
|
|
115
110
|
const refusals = verdicts.filter((verdict)=>verdict.verdict === 'refuse');
|
|
116
111
|
if (refusals.length === 0) return verdicts[0];
|
package/dist/collection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/collection.ts"],"sourcesContent":["import { parse, validate, VERSION, type Document, type Validation } from '@agentshouse/mdmodel';\nimport type { Selector } from '@agentshouse/query';\nimport { beneath, normalize } from './paths.js';\nimport type { AttachedModelBinding, ModelState } from './model.js';\nimport type { MdModelIdentity } from './adapter.js';\n\nexport const MD_MODEL: MdModelIdentity = { identity: '@agentshouse/mdmodel', version: VERSION };\n\nexport const PRESENTED: Selector = { path: { $regex: '\\\\.md$' } };\n\nexport type MdType = {\n name: string;\n path: string;\n fields: Readonly<Record<string, unknown>>;\n sections: Readonly<Record<string, unknown>>;\n};\n\nexport type Collection = {\n documents: Readonly<Record<string, Document>>;\n composition: Composition;\n};\n\nexport type Composition = {\n collectionRoot: string;\n model: ModelState;\n selection: { roots: readonly string[]; model: ModelState } | null;\n};\n\nfunction selected(composition: Composition, path: string): boolean {\n return (\n composition.selection !== null &&\n composition.selection.roots.some((root) => beneath(root, path))\n );\n}\n\nexport function governing(composition: Composition, path: string): ModelState {\n return composition.selection !== null && selected(composition, path)\n ? composition.selection.model\n : composition.model;\n}\n\nexport function typesAt(composition: Composition, path: string): readonly MdType[] {\n const model = governing(composition, path);\n return model.status === 'unavailable' ? [] : model.types;\n}\n\nexport function parseCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection {\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const retained = previous?.collection.documents[path];\n if (retained !== undefined && previous?.text[path] === text[path]) {\n documents[path] = retained;\n continue;\n }\n const parsed = parse(text[path], path);\n if (parsed.ok) documents[path] = parsed.document;\n }\n return { documents, composition };\n}\n\nexport function readCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection | null {\n if (!validRoot(composition.collectionRoot)) return null;\n const collection = parseCollection(text, composition, previous);\n if (Object.keys(collection.documents).length !== Object.keys(text).length) return null;\n if (\n Object.entries(collection.documents).some(\n ([path, document]) =>\n !member(path, composition.collectionRoot) &&\n !selected(composition, path) &&\n document.type !== undefined &&\n document.type !== 'any',\n )\n )\n return null;\n return collection;\n}\n\nexport function validRoot(root: unknown): root is string {\n return typeof root === 'string' && normalize(root) === root;\n}\n\nfunction member(path: string, root: string): boolean {\n return root === '' || path.startsWith(`${root}/`);\n}\n\ntype Refusal = Extract<Validation, { verdict: 'refuse' }> & { source?: 'content' | 'model' };\n\nfunction validateAgainst(\n documents: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n prefix: string,\n model: ModelState,\n binding: AttachedModelBinding | null,\n): Validation & { source?: 'content' | 'model' } {\n if (model.status === 'unavailable' || binding === null) {\n const typed = Object.entries(documents).find(([, content]) => {\n const parsed = parse(content);\n return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';\n });\n if (typed !== undefined)\n return {\n verdict: 'refuse',\n rule: 'model-unavailable',\n file: `${prefix}${typed[0]}`,\n version: VERSION,\n };\n return validate(documents, { binaryTargets });\n }\n const verdict = binding.validate({ model: model.snapshot, documents, binaryTargets });\n if (verdict.verdict === 'refuse' && verdict.source === 'model') return verdict;\n if (verdict.verdict === 'accept') return verdict;\n return {\n ...verdict,\n file: `${prefix}${verdict.file}`,\n ...(verdict.referrers === undefined\n ? {}\n : { referrers: verdict.referrers.map((path) => `${prefix}${path}`) }),\n };\n}\n\nexport function validateCollection(\n text: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n composition: Composition,\n binding: AttachedModelBinding | null,\n): Validation & { source?: 'content' | 'model' } {\n const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;\n const collection: Record<string, string> = {};\n const selection: Record<string, string> = {};\n for (const [path, content] of Object.entries(text)) {\n if (member(path, composition.collectionRoot)) {\n collection[path.slice(prefix.length)] = content;\n continue;\n }\n if (selected(composition, path)) {\n selection[path] = content;\n continue;\n }\n const parsed = parse(content, path);\n if (!parsed.ok) return { verdict: 'refuse', ...parsed.refusal };\n if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {\n return { verdict: 'refuse', rule: 'outside-collection-type', file: path, version: VERSION };\n }\n }\n const verdicts = [\n validateAgainst(\n collection,\n binaryTargets\n .filter((path) => member(path, composition.collectionRoot))\n .map((path) => path.slice(prefix.length)),\n prefix,\n composition.model,\n binding,\n ),\n ];\n if (composition.selection !== null) {\n verdicts.push(\n validateAgainst(\n selection,\n binaryTargets.filter((path) => selected(composition, path)),\n '',\n composition.selection.model,\n binding,\n ),\n );\n }\n const refusals = verdicts.filter((verdict): verdict is Refusal => verdict.verdict === 'refuse');\n if (refusals.length === 0) return verdicts[0];\n return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];\n}\n"],"names":["parse","validate","VERSION","beneath","normalize","MD_MODEL","identity","version","PRESENTED","path","$regex","selected","composition","selection","roots","some","root","governing","model","typesAt","status","types","parseCollection","text","previous","documents","Object","keys","sort","retained","collection","undefined","parsed","ok","document","readCollection","validRoot","collectionRoot","length","entries","member","type","startsWith","validateAgainst","binaryTargets","prefix","binding","typed","find","content","verdict","rule","file","snapshot","source","referrers","map","validateCollection","slice","refusal","hasOwn","fields","verdicts","filter","push","refusals"],"mappings":"AAAA,SAASA,KAAK,EAAEC,QAAQ,EAAEC,OAAO,QAAwC,uBAAuB;AAEhG,SAASC,OAAO,EAAEC,SAAS,QAAQ,aAAa;AAIhD,OAAO,MAAMC,WAA4B;IAAEC,UAAU;IAAwBC,SAASL;AAAQ,EAAE;AAEhG,OAAO,MAAMM,YAAsB;IAAEC,MAAM;QAAEC,QAAQ;IAAS;AAAE,EAAE;AAoBlE,SAASC,SAASC,WAAwB,EAAEH,IAAY;IACtD,OACEG,YAAYC,SAAS,KAAK,QAC1BD,YAAYC,SAAS,CAACC,KAAK,CAACC,IAAI,CAAC,CAACC,OAASb,QAAQa,MAAMP;AAE7D;AAEA,OAAO,SAASQ,UAAUL,WAAwB,EAAEH,IAAY;IAC9D,OAAOG,YAAYC,SAAS,KAAK,QAAQF,SAASC,aAAaH,QAC3DG,YAAYC,SAAS,CAACK,KAAK,GAC3BN,YAAYM,KAAK;AACvB;AAEA,OAAO,SAASC,QAAQP,WAAwB,EAAEH,IAAY;IAC5D,MAAMS,QAAQD,UAAUL,aAAaH;IACrC,OAAOS,MAAME,MAAM,KAAK,gBAAgB,EAAE,GAAGF,MAAMG,KAAK;AAC1D;AAEA,OAAO,SAASC,gBACdC,IAAsC,EACtCX,WAAwB,EACxBY,QAA6E;IAE7E,MAAMC,YAAsC,CAAC;IAC7C,KAAK,MAAMhB,QAAQiB,OAAOC,IAAI,CAACJ,MAAMK,IAAI,GAAI;QAC3C,MAAMC,WAAWL,UAAUM,WAAWL,SAAS,CAAChB,KAAK;QACrD,IAAIoB,aAAaE,aAAaP,UAAUD,IAAI,CAACd,KAAK,KAAKc,IAAI,CAACd,KAAK,EAAE;YACjEgB,SAAS,CAAChB,KAAK,GAAGoB;YAClB;QACF;QACA,MAAMG,SAAShC,MAAMuB,IAAI,CAACd,KAAK,EAAEA;QACjC,IAAIuB,OAA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;QAC9D,IAAIjC,OAAOkC,MAAM,CAAC5B,OAAOE,QAAQ,CAAC2B,MAAM,EAAE,WAAW7B,OAAOE,QAAQ,CAAC2B,MAAM,CAACpB,IAAI,KAAK,OAAO;YAC1F,OAAO;gBAAES,SAAS;gBAAUC,MAAM;gBAA2BC,MAAM3C;gBAAMF,SAASL;YAAQ;QAC5F;IACF;IACA,MAAM4D,WAAW;QACfnB,gBACEb,YACAc,cACGmB,MAAM,CAAC,CAACtD,OAAS+B,OAAO/B,MAAMG,YAAYyB,cAAc,GACxDmB,GAAG,CAAC,CAAC/C,OAASA,KAAKiD,KAAK,CAACb,OAAOP,MAAM,IACzCO,QACAjC,YAAYM,KAAK,EACjB4B;KAEH;IACD,IAAIlC,YAAYC,SAAS,KAAK,MAAM;QAClCiD,SAASE,IAAI,CACXrB,gBACE9B,WACA+B,cAAcmB,MAAM,CAAC,CAACtD,OAASE,SAASC,aAAaH,QACrD,IACAG,YAAYC,SAAS,CAACK,KAAK,EAC3B4B;IAGN;IACA,MAAMmB,WAAWH,SAASC,MAAM,CAAC,CAACb,UAAgCA,QAAQA,OAAO,KAAK;IACtF,IAAIe,SAAS3B,MAAM,KAAK,GAAG,OAAOwB,QAAQ,CAAC,EAAE;IAC7C,OAAOG,SAASjB,IAAI,CAAC,CAACW,UAAYA,QAAQR,IAAI,KAAK,wBAAwBc,QAAQ,CAAC,EAAE;AACxF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/collection.ts"],"sourcesContent":["import {\n parse,\n validate,\n VERSION,\n type Document,\n type Validation,\n type VerifiedModel,\n} from '@agentshouse/mdmodel';\nimport type { Selector } from '@agentshouse/query';\nimport { beneath, normalize } from './paths.js';\nimport type { ModelState } from './model.js';\nimport type { MdModelIdentity } from './adapter.js';\n\nexport const MD_MODEL: MdModelIdentity = { identity: '@agentshouse/mdmodel', version: VERSION };\n\nexport const PRESENTED: Selector = { path: { $regex: '\\\\.md$' } };\n\nconst NO_TYPES: VerifiedModel = { types: {} };\n\nexport type Collection = {\n documents: Readonly<Record<string, Document>>;\n composition: Composition;\n};\n\nexport type Composition = {\n collectionRoot: string;\n model: ModelState;\n selection: { roots: readonly string[]; model: ModelState } | null;\n};\n\nfunction selected(composition: Composition, path: string): boolean {\n return (\n composition.selection !== null &&\n composition.selection.roots.some((root) => beneath(root, path))\n );\n}\n\nexport function governing(composition: Composition, path: string): ModelState {\n return composition.selection !== null && selected(composition, path)\n ? composition.selection.model\n : composition.model;\n}\n\nexport function parseCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection {\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const retained = previous?.collection.documents[path];\n if (retained !== undefined && previous?.text[path] === text[path]) {\n documents[path] = retained;\n continue;\n }\n const parsed = parse(text[path], path);\n if (parsed.ok) documents[path] = parsed.document;\n }\n return { documents, composition };\n}\n\nexport function readCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection | null {\n if (!validRoot(composition.collectionRoot)) return null;\n const collection = parseCollection(text, composition, previous);\n if (Object.keys(collection.documents).length !== Object.keys(text).length) return null;\n if (\n Object.entries(collection.documents).some(\n ([path, document]) =>\n !member(path, composition.collectionRoot) &&\n !selected(composition, path) &&\n document.type !== undefined &&\n document.type !== 'any',\n )\n )\n return null;\n return collection;\n}\n\nexport function validRoot(root: unknown): root is string {\n return typeof root === 'string' && normalize(root) === root;\n}\n\nfunction member(path: string, root: string): boolean {\n return root === '' || path.startsWith(`${root}/`);\n}\n\ntype Refusal = Extract<Validation, { verdict: 'refuse' }>;\n\nfunction validateAgainst(\n documents: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n prefix: string,\n model: ModelState,\n): Validation {\n if (model.status === 'unavailable') {\n const typed = Object.entries(documents).find(([, content]) => {\n const parsed = parse(content);\n return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';\n });\n if (typed !== undefined)\n return {\n verdict: 'refuse',\n rule: 'model-unavailable',\n file: `${prefix}${typed[0]}`,\n version: VERSION,\n };\n }\n const verdict = validate(\n documents,\n { binaryTargets },\n model.status === 'unavailable' ? NO_TYPES : { types: model.types },\n );\n if (verdict.verdict === 'accept') return verdict;\n return {\n ...verdict,\n file: `${prefix}${verdict.file}`,\n ...(verdict.referrers === undefined\n ? {}\n : { referrers: verdict.referrers.map((path) => `${prefix}${path}`) }),\n };\n}\n\nexport function validateCollection(\n text: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n composition: Composition,\n): Validation {\n const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;\n const collection: Record<string, string> = {};\n const selection: Record<string, string> = {};\n for (const [path, content] of Object.entries(text)) {\n if (member(path, composition.collectionRoot)) {\n collection[path.slice(prefix.length)] = content;\n continue;\n }\n if (selected(composition, path)) {\n selection[path] = content;\n continue;\n }\n const parsed = parse(content, path);\n if (!parsed.ok) return { verdict: 'refuse', ...parsed.refusal };\n if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {\n return { verdict: 'refuse', rule: 'outside-collection-type', file: path, version: VERSION };\n }\n }\n const verdicts = [\n validateAgainst(\n collection,\n binaryTargets\n .filter((path) => member(path, composition.collectionRoot))\n .map((path) => path.slice(prefix.length)),\n prefix,\n composition.model,\n ),\n ];\n if (composition.selection !== null) {\n verdicts.push(\n validateAgainst(\n selection,\n binaryTargets.filter((path) => selected(composition, path)),\n '',\n composition.selection.model,\n ),\n );\n }\n const refusals = verdicts.filter((verdict): verdict is Refusal => verdict.verdict === 'refuse');\n if (refusals.length === 0) return verdicts[0];\n return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];\n}\n"],"names":["parse","validate","VERSION","beneath","normalize","MD_MODEL","identity","version","PRESENTED","path","$regex","NO_TYPES","types","selected","composition","selection","roots","some","root","governing","model","parseCollection","text","previous","documents","Object","keys","sort","retained","collection","undefined","parsed","ok","document","readCollection","validRoot","collectionRoot","length","entries","member","type","startsWith","validateAgainst","binaryTargets","prefix","status","typed","find","content","verdict","rule","file","referrers","map","validateCollection","slice","refusal","hasOwn","fields","verdicts","filter","push","refusals"],"mappings":"AAAA,SACEA,KAAK,EACLC,QAAQ,EACRC,OAAO,QAIF,uBAAuB;AAE9B,SAASC,OAAO,EAAEC,SAAS,QAAQ,aAAa;AAIhD,OAAO,MAAMC,WAA4B;IAAEC,UAAU;IAAwBC,SAASL;AAAQ,EAAE;AAEhG,OAAO,MAAMM,YAAsB;IAAEC,MAAM;QAAEC,QAAQ;IAAS;AAAE,EAAE;AAElE,MAAMC,WAA0B;IAAEC,OAAO,CAAC;AAAE;AAa5C,SAASC,SAASC,WAAwB,EAAEL,IAAY;IACtD,OACEK,YAAYC,SAAS,KAAK,QAC1BD,YAAYC,SAAS,CAACC,KAAK,CAACC,IAAI,CAAC,CAACC,OAASf,QAAQe,MAAMT;AAE7D;AAEA,OAAO,SAASU,UAAUL,WAAwB,EAAEL,IAAY;IAC9D,OAAOK,YAAYC,SAAS,KAAK,QAAQF,SAASC,aAAaL,QAC3DK,YAAYC,SAAS,CAACK,KAAK,GAC3BN,YAAYM,KAAK;AACvB;AAEA,OAAO,SAASC,gBACdC,IAAsC,EACtCR,WAAwB,EACxBS,QAA6E;IAE7E,MAAMC,YAAsC,CAAC;IAC7C,KAAK,MAAMf,QAAQgB,OAAOC,IAAI,CAACJ,MAAMK,IAAI,GAAI;QAC3C,MAAMC,WAAWL,UAAUM,WAAWL,SAAS,CAACf,KAAK;QACrD,IAAImB,aAAaE,aAAaP,UAAUD,IAAI,CAACb,KAAK,KAAKa,IAAI,CAACb,KAAK,EAAE;YACjEe,SAAS,CAACf,KAAK,GAAGmB;YAClB;QACF;QACA,MAAMG,SAAS/B,MAAMsB,IAAI,CAACb,KAAK,EAAEA;QACjC,IAAIsB,OAAOC,EAAE,EAAER,SAAS,CAACf,KAAK,GAAGsB,OAAOE,Q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