@agentshouse/mdruntime 0.1.0-alpha.8 → 0.1.0-c009335e08279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/AGENTS.md +208 -0
  2. package/README.md +44 -0
  3. package/dist/adapter.d.ts +215 -25
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +2 -3
  6. package/dist/attachment.d.ts +3 -0
  7. package/dist/attachment.d.ts.map +1 -0
  8. package/dist/attachment.js +8 -0
  9. package/dist/bootstrap.d.ts +6 -7
  10. package/dist/bootstrap.d.ts.map +1 -1
  11. package/dist/bootstrap.js +31 -28
  12. package/dist/change-set.d.ts +33 -0
  13. package/dist/change-set.d.ts.map +1 -0
  14. package/dist/change-set.js +83 -0
  15. package/dist/change.d.ts +9 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/change.js +6 -5
  18. package/dist/client.d.ts +69 -0
  19. package/dist/client.d.ts.map +1 -0
  20. package/dist/client.js +165 -0
  21. package/dist/collection.d.ts +22 -15
  22. package/dist/collection.d.ts.map +1 -1
  23. package/dist/collection.js +60 -78
  24. package/dist/connection.d.ts +68 -40
  25. package/dist/connection.d.ts.map +1 -1
  26. package/dist/connection.js +1597 -961
  27. package/dist/conversation.d.ts +79 -0
  28. package/dist/conversation.d.ts.map +1 -0
  29. package/dist/conversation.js +557 -0
  30. package/dist/durability.d.ts +8 -3
  31. package/dist/durability.d.ts.map +1 -1
  32. package/dist/durability.js +7 -61
  33. package/dist/file.d.ts +20 -0
  34. package/dist/file.d.ts.map +1 -0
  35. package/dist/file.js +126 -0
  36. package/dist/host.d.ts +13 -0
  37. package/dist/host.d.ts.map +1 -0
  38. package/dist/host.js +175 -0
  39. package/dist/identity.d.ts +1 -0
  40. package/dist/identity.d.ts.map +1 -1
  41. package/dist/identity.js +10 -9
  42. package/dist/index.d.ts +14 -10
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +1 -3
  45. package/dist/log.js +5 -6
  46. package/dist/memory.d.ts +17 -2
  47. package/dist/memory.d.ts.map +1 -1
  48. package/dist/memory.js +268 -113
  49. package/dist/model.d.ts +10 -25
  50. package/dist/model.d.ts.map +1 -1
  51. package/dist/model.js +18 -21
  52. package/dist/observation.d.ts +25 -0
  53. package/dist/observation.d.ts.map +1 -0
  54. package/dist/observation.js +85 -0
  55. package/dist/outcome.d.ts +12 -24
  56. package/dist/outcome.d.ts.map +1 -1
  57. package/dist/outcome.js +1 -13
  58. package/dist/overlay.d.ts +9 -2
  59. package/dist/overlay.d.ts.map +1 -1
  60. package/dist/overlay.js +187 -43
  61. package/dist/paths.d.ts +0 -1
  62. package/dist/paths.d.ts.map +1 -1
  63. package/dist/paths.js +12 -19
  64. package/dist/query.d.ts +210 -9
  65. package/dist/query.d.ts.map +1 -1
  66. package/dist/query.js +420 -15
  67. package/dist/read-side.d.ts +14 -0
  68. package/dist/read-side.d.ts.map +1 -0
  69. package/dist/read-side.js +371 -0
  70. package/dist/refresh.d.ts +4 -5
  71. package/dist/refresh.d.ts.map +1 -1
  72. package/dist/refresh.js +45 -30
  73. package/dist/replica.d.ts +27 -6
  74. package/dist/replica.d.ts.map +1 -1
  75. package/dist/replica.js +233 -30
  76. package/dist/room-draft.d.ts +124 -0
  77. package/dist/room-draft.d.ts.map +1 -0
  78. package/dist/room-draft.js +327 -0
  79. package/dist/rows.d.ts +41 -0
  80. package/dist/rows.d.ts.map +1 -0
  81. package/dist/rows.js +100 -0
  82. package/dist/save.d.ts +10 -6
  83. package/dist/save.d.ts.map +1 -1
  84. package/dist/save.js +266 -333
  85. package/dist/search.d.ts +61 -0
  86. package/dist/search.d.ts.map +1 -0
  87. package/dist/search.js +125 -0
  88. package/dist/status.d.ts +9 -2
  89. package/dist/status.d.ts.map +1 -1
  90. package/dist/status.js +11 -14
  91. package/dist/store.d.ts +75 -18
  92. package/dist/store.d.ts.map +1 -1
  93. package/dist/store.js +358 -97
  94. package/dist/transfer.d.ts +5 -0
  95. package/dist/transfer.d.ts.map +1 -1
  96. package/dist/transfer.js +1 -5
  97. package/dist/wire.d.ts +64 -0
  98. package/dist/wire.d.ts.map +1 -0
  99. package/dist/wire.js +118 -0
  100. package/package.json +15 -13
  101. package/dist/adapter.js.map +0 -1
  102. package/dist/bootstrap.js.map +0 -1
  103. package/dist/change.js.map +0 -1
  104. package/dist/collection.js.map +0 -1
  105. package/dist/connection.js.map +0 -1
  106. package/dist/durability.js.map +0 -1
  107. package/dist/identity.js.map +0 -1
  108. package/dist/index.js.map +0 -1
  109. package/dist/log.js.map +0 -1
  110. package/dist/memory.js.map +0 -1
  111. package/dist/model.js.map +0 -1
  112. package/dist/outcome.js.map +0 -1
  113. package/dist/overlay.js.map +0 -1
  114. package/dist/paths.js.map +0 -1
  115. package/dist/query.js.map +0 -1
  116. package/dist/refresh.js.map +0 -1
  117. package/dist/replica.js.map +0 -1
  118. package/dist/save.js.map +0 -1
  119. package/dist/status.js.map +0 -1
  120. package/dist/store.js.map +0 -1
  121. package/dist/transfer.js.map +0 -1
@@ -1,11 +1,10 @@
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
- import { type ConfirmedLayer } from './replica.js';
3
+ import { type Staged } from './replica.js';
5
4
  import { type Unconfirmed } from './transfer.js';
6
- export type BootstrapOutcome = {
7
- kind: 'staged';
8
- confirmed: ConfirmedLayer;
9
- } | Unconfirmed | AdapterFailure;
10
- export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom, model: ModelState, binding: AttachedModelBinding | null): Promise<BootstrapOutcome>;
5
+ export type BootstrapOutcome = Staged | Unconfirmed | AdapterFailure;
6
+ export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom, models: {
7
+ collection: ModelState;
8
+ selection: ModelState;
9
+ }, continuing: () => boolean): Promise<BootstrapOutcome>;
11
10
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,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,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,oBAAoB,GAAG,IAAI,GACnC,OAAO,CAAC,gBAAgB,CAAC,CA0C3B"}
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,EACV,OAAO,EACP,cAAc,EACd,aAAa,EACb,cAAc,EAGf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,GAAG,cAAc,CAAC;AAErE,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,EACzD,UAAU,EAAE,MAAM,OAAO,GACxB,OAAO,CAAC,gBAAgB,CAAC,CA+C3B"}
package/dist/bootstrap.js CHANGED
@@ -1,53 +1,56 @@
1
+ import { declaredAttachments } from './attachment.js';
1
2
  import { readStaged } from './replica.js';
2
3
  import { unconfirmed } from './transfer.js';
3
- export async function bootstrapRoom(adapter, authorization, room, model, binding) {
4
+ export async function bootstrapRoom(adapter, authorization, room, models, continuing) {
4
5
  const first = await adapter.bootstrap(authorization, {
5
6
  locator: room.locator,
6
- selection: room.replica.selection
7
+ selection: room.replica.selection,
7
8
  });
8
- if (first.kind !== 'bootstrap') return first;
9
+ if (first.kind !== 'bootstrap')
10
+ return first;
9
11
  const roomVersion = first.roomVersion;
10
- const documents = {
11
- ...first.documents
12
- };
13
- const revisions = {
14
- ...first.revisions
15
- };
12
+ const documents = { ...first.documents };
13
+ const revisions = { ...first.revisions };
14
+ const changes = { ...first.changes };
16
15
  const binaryTargets = new Set(first.binaryTargets);
16
+ const attachments = [first.attachments ?? []];
17
17
  let pageToken = first.pageToken;
18
- while(pageToken !== undefined){
18
+ while (pageToken !== undefined) {
19
+ if (!continuing())
20
+ return unconfirmed;
19
21
  const page = await adapter.bootstrap(authorization, {
20
22
  locator: room.locator,
21
23
  selection: room.replica.selection,
22
- pageToken
24
+ pageToken,
23
25
  });
24
- if (page.kind !== 'bootstrap') return page;
25
- if (page.roomVersion !== roomVersion) return unconfirmed;
26
+ if (page.kind !== 'bootstrap')
27
+ return page;
28
+ if (page.roomVersion !== roomVersion)
29
+ return unconfirmed;
26
30
  Object.assign(documents, page.documents);
27
31
  Object.assign(revisions, page.revisions);
28
- for (const target of page.binaryTargets)binaryTargets.add(target);
32
+ Object.assign(changes, page.changes);
33
+ for (const target of page.binaryTargets)
34
+ binaryTargets.add(target);
35
+ attachments.push(page.attachments ?? []);
29
36
  pageToken = page.pageToken;
30
37
  }
31
- const confirmed = readStaged({
38
+ return readStaged({
32
39
  locator: room.locator,
33
- collectionRoot: room.collectionRoot,
34
40
  name: room.name,
35
41
  operations: room.operations,
36
42
  replica: room.replica,
37
43
  attachedModel: room.attachedModel,
38
- model,
44
+ model: models.collection,
45
+ typedSelection: room.typedSelection ?? null,
46
+ selectionModel: models.selection,
39
47
  providerOwnedPaths: room.providerOwnedPaths,
40
48
  roomVersion,
41
49
  documents,
42
- binaryTargets: [
43
- ...binaryTargets
44
- ].sort(),
45
- revisions
46
- }, binding);
47
- return confirmed === null ? unconfirmed : {
48
- kind: 'staged',
49
- confirmed
50
- };
50
+ binaryTargets: [...binaryTargets].sort(),
51
+ revisions,
52
+ changes,
53
+ written: Object.fromEntries(Object.keys(documents).map((path) => [path, roomVersion])),
54
+ attachments: declaredAttachments(attachments),
55
+ });
51
56
  }
52
-
53
- //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1,33 @@
1
+ import { type Replica } from './replica.js';
2
+ import { type Row } from './rows.js';
3
+ export type DocumentChange = {
4
+ locator: string;
5
+ path: string;
6
+ before: readonly Row[];
7
+ after: readonly Row[];
8
+ };
9
+ export type MessageChange = {
10
+ conversation: string;
11
+ identity: string;
12
+ };
13
+ export type ChangeSet = {
14
+ documents: readonly DocumentChange[];
15
+ drafts: readonly {
16
+ locator: string;
17
+ path: string;
18
+ }[];
19
+ rooms: readonly string[];
20
+ queues: readonly string[];
21
+ presentations: readonly string[];
22
+ messages: readonly MessageChange[];
23
+ conversations: readonly string[];
24
+ };
25
+ export declare function changeSet(locator: string, before: Replica | null, after: Replica | null, changed?: {
26
+ drafts?: readonly string[];
27
+ room?: boolean;
28
+ queue?: boolean;
29
+ presentation?: string;
30
+ }): ChangeSet;
31
+ export declare function conversationChangeSet(messages: readonly MessageChange[], conversations: readonly string[]): ChangeSet;
32
+ export declare function mergeChangeSets(sets: readonly ChangeSet[]): ChangeSet;
33
+ //# s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BAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,SAAS,CAUX;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAUrE"}
@@ -0,0 +1,83 @@
1
+ import { sameChange } from './overlay.js';
2
+ import { beneath } from './paths.js';
3
+ import { compositionOf, sameMembership } from './replica.js';
4
+ import { rowsOf } from './rows.js';
5
+ function rowsAt(locator, replica, path) {
6
+ if (replica === null)
7
+ return [];
8
+ const document = replica.visible.collection.documents[path];
9
+ if (document === undefined && !replica.visible.binaryTargets.includes(path)) {
10
+ return [];
11
+ }
12
+ return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), replica.visible.changes[path] ?? null);
13
+ }
14
+ function modelShape(model) {
15
+ return model.status === 'unavailable' ? 'unavailable' : JSON.stringify(model.types);
16
+ }
17
+ export function changeSet(locator, before, after, changed = {}) {
18
+ const paths = new Set([
19
+ ...Object.keys(before?.visible.documents ?? {}),
20
+ ...Object.keys(after?.visible.documents ?? {}),
21
+ ...(before?.visible.binaryTargets ?? []),
22
+ ...(after?.visible.binaryTargets ?? []),
23
+ ]);
24
+ const documents = [];
25
+ const oldRoom = before?.confirmed.record;
26
+ const newRoom = after?.confirmed.record;
27
+ const collectionChanged = oldRoom !== undefined &&
28
+ newRoom !== undefined &&
29
+ modelShape(oldRoom.model) !== modelShape(newRoom.model);
30
+ const selectionChanged = oldRoom !== undefined &&
31
+ newRoom !== undefined &&
32
+ modelShape(oldRoom.selectionModel) !== modelShape(newRoom.selectionModel);
33
+ const reclassified = oldRoom !== undefined && newRoom !== undefined && !sameMembership(oldRoom, newRoom);
34
+ for (const path of paths) {
35
+ const selected = newRoom?.typedSelection?.roots.some((root) => beneath(root, path)) ?? false;
36
+ const retyped = selected ? selectionChanged : collectionChanged;
37
+ if (before?.visible.documents[path] === after?.visible.documents[path] &&
38
+ before?.visible.binaryTargets.includes(path) ===
39
+ after?.visible.binaryTargets.includes(path) &&
40
+ before?.visible.revisions[path] === after?.visible.revisions[path] &&
41
+ sameChange(before?.visible.changes[path], after?.visible.changes[path]) &&
42
+ !retyped &&
43
+ !reclassified)
44
+ continue;
45
+ documents.push({
46
+ locator,
47
+ path,
48
+ before: rowsAt(locator, before, path),
49
+ after: rowsAt(locator, after, path),
50
+ });
51
+ }
52
+ return {
53
+ documents,
54
+ drafts: (changed.drafts ?? []).map((path) => ({ locator, path })),
55
+ rooms: changed.room ? [locator] : [],
56
+ queues: changed.queue ? [locator] : [],
57
+ presentations: changed.presentation === undefined ? [] : [changed.presentation],
58
+ messages: [],
59
+ conversations: [],
60
+ };
61
+ }
62
+ export function conversationChangeSet(messages, conversations) {
63
+ return {
64
+ documents: [],
65
+ drafts: [],
66
+ rooms: [],
67
+ queues: [],
68
+ presentations: [],
69
+ messages,
70
+ conversations: [...new Set(conversations)],
71
+ };
72
+ }
73
+ export function mergeChangeSets(sets) {
74
+ return {
75
+ documents: sets.flatMap((set) => set.documents),
76
+ drafts: sets.flatMap((set) => set.drafts),
77
+ rooms: [...new Set(sets.flatMap((set) => set.rooms))],
78
+ queues: [...new Set(sets.flatMap((set) => set.queues))],
79
+ presentations: [...new Set(sets.flatMap((set) => set.presentations))],
80
+ messages: sets.flatMap((set) => set.messages),
81
+ conversations: [...new Set(sets.flatMap((set) => set.conversations))],
82
+ };
83
+ }
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;
@@ -54,12 +58,17 @@ export type Precondition = {
54
58
  readonly kind: 'absent';
55
59
  readonly path: string;
56
60
  };
61
+ export type WrittenBy = {
62
+ readonly app: string;
63
+ readonly release: string;
64
+ };
57
65
  export type ChangeBatch = {
58
66
  validation?: import('./model.js').ValidationReceipt;
59
67
  readonly id: string;
60
68
  readonly baseRoomVersion: string;
61
69
  readonly changes: readonly Change[];
62
70
  readonly preconditions: readonly Precondition[];
71
+ readonly writtenBy?: WrittenBy;
63
72
  };
64
73
  export declare function immutable(batch: ChangeBatch): ChangeBatch;
65
74
  //# sourceMappingURL=change.d.ts.map
@@ -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,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,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AAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,EAAE,OAAO,YAAY,EAAE,iBAAiB,CAAC;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CAChC,CAAC;AAUF,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAEzD"}
package/dist/change.js CHANGED
@@ -1,12 +1,13 @@
1
1
  function frozen(value) {
2
- if (Array.isArray(value)) return Object.freeze(value.map((item)=>frozen(item)));
3
- if (value === null || typeof value !== 'object') return value;
2
+ if (Array.isArray(value))
3
+ return Object.freeze(value.map((item) => frozen(item)));
4
+ if (value === null || typeof value !== 'object')
5
+ return value;
4
6
  const copy = {};
5
- for (const [name, item] of Object.entries(value))copy[name] = frozen(item);
7
+ for (const [name, item] of Object.entries(value))
8
+ copy[name] = frozen(item);
6
9
  return Object.freeze(copy);
7
10
  }
8
11
  export function immutable(batch) {
9
12
  return frozen(batch);
10
13
  }
11
-
12
- //# sourceMappingURL=change.js.map
@@ -0,0 +1,69 @@
1
+ import type { AppRoom, ConnectionRefusal, HistoryQuery, RoomTypes, SavedRoomDraft, SaveResult } from './connection.js';
2
+ import type { HistoryResult, ServiceMode } from './adapter.js';
3
+ import type { ChatDraft, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
4
+ import { type Observation } from './observation.js';
5
+ import type { CallResult, QueueEntry } from './outcome.js';
6
+ import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
7
+ import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
8
+ import type { SearchRequest, SearchResult } from './search.js';
9
+ import type { SyncStatus } from './status.js';
10
+ import { type RuntimePort } from './wire.js';
11
+ export type MdRuntimeClient = {
12
+ rooms(): Promise<readonly AppRoom[]>;
13
+ query: {
14
+ (query: DocumentQuery): Promise<DocumentResult>;
15
+ (query: GroupQuery): Promise<GroupResult>;
16
+ };
17
+ search(request: SearchRequest): Promise<SearchResult>;
18
+ types(locator: string): Promise<RoomTypes>;
19
+ roomDraft: {
20
+ list(): Promise<readonly RoomDraft[]>;
21
+ read(room: string, path: string): Promise<RoomDraft | null>;
22
+ write(room: string, path: string, revision: string | null, parts: RoomDraftParts): Promise<RoomDraftWrite>;
23
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
24
+ };
25
+ save(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;
26
+ presentation: {
27
+ read(): Promise<unknown>;
28
+ write(value: unknown): Promise<void>;
29
+ };
30
+ conversation: {
31
+ list(): Promise<readonly ConversationEntry[]>;
32
+ read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
33
+ create(input: unknown): Promise<CallResult>;
34
+ send(conversation: string): Promise<CallResult>;
35
+ answer(conversation: string, answer: unknown): Promise<CallResult>;
36
+ interrupt(conversation: string): Promise<CallResult>;
37
+ kill(conversation: string): Promise<CallResult>;
38
+ cancel(conversation: string, turn: string): Promise<CallResult>;
39
+ delete(conversation: string): Promise<CallResult>;
40
+ };
41
+ chatDraft: {
42
+ write(conversation: string, draft: ChatDraft): Promise<void>;
43
+ discard(conversation: string): Promise<void>;
44
+ };
45
+ history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryResult>;
46
+ call(name: string, input: unknown): Promise<CallResult>;
47
+ reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
48
+ log(): Promise<string>;
49
+ persistence(): Promise<boolean>;
50
+ observe: {
51
+ (topic: 'deployment-facts'): Promise<Observation<unknown>>;
52
+ (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
53
+ (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
54
+ (topic: 'storage-loss'): Promise<Observation<string | null>>;
55
+ (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
56
+ (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
57
+ (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult>>;
58
+ (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult>>;
59
+ (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
60
+ (topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
61
+ (topic: 'presentation'): Promise<Observation<unknown>>;
62
+ (topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
63
+ };
64
+ reauthorize(): Promise<void>;
65
+ };
66
+ export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
67
+ export type { Observation } from './observation.js';
68
+ export type { RuntimePort } from './wire.js';
69
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA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E,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,CAkLnE;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,165 @@
1
+ import { observed } from './observation.js';
2
+ import { answer, AUTHORIZATION_ENDED, carried, envelope, PORT_CLOSED, PROTOCOL_MISMATCH, } from './wire.js';
3
+ export function connectMdRuntime(port) {
4
+ let sequence = 0;
5
+ let refusal = null;
6
+ let ended = null;
7
+ const calls = new Map();
8
+ const opening = new Map();
9
+ const observations = new Map();
10
+ const send = (message) => {
11
+ port.postMessage(envelope(message));
12
+ };
13
+ function begin(id, topic, first) {
14
+ const handle = observed(first, () => {
15
+ observations.delete(id);
16
+ if (refusal === null)
17
+ send({ kind: 'stop', id });
18
+ }, topic === 'query');
19
+ observations.set(id, { topic, handle });
20
+ return handle.observation;
21
+ }
22
+ function refuse(reported) {
23
+ refusal = reported;
24
+ for (const { topic, handle } of observations.values()) {
25
+ if (topic === 'connection-refusal')
26
+ handle.receive(reported);
27
+ }
28
+ const failure = new Error(reported.reason);
29
+ for (const [id, waiting] of opening) {
30
+ if (waiting.topic === 'connection-refusal')
31
+ waiting.settle(begin(id, waiting.topic, reported));
32
+ else
33
+ waiting.fail(failure);
34
+ }
35
+ opening.clear();
36
+ for (const waiting of calls.values())
37
+ waiting.fail(failure);
38
+ calls.clear();
39
+ }
40
+ function end(reason) {
41
+ if (ended !== null)
42
+ return;
43
+ ended = reason;
44
+ const failure = new Error(reason);
45
+ for (const waiting of opening.values())
46
+ waiting.fail(failure);
47
+ opening.clear();
48
+ for (const waiting of calls.values())
49
+ waiting.fail(failure);
50
+ calls.clear();
51
+ for (const { handle } of observations.values())
52
+ handle.end();
53
+ observations.clear();
54
+ }
55
+ port.addEventListener('message', (event) => {
56
+ const wire = carried(event.data);
57
+ if (wire === null)
58
+ return;
59
+ if (!wire.matching) {
60
+ refuse(PROTOCOL_MISMATCH);
61
+ return;
62
+ }
63
+ const message = answer(wire.message);
64
+ if (message === null)
65
+ return;
66
+ if (message.kind === 'refusal') {
67
+ refuse(message.refusal);
68
+ return;
69
+ }
70
+ if (message.kind === 'ended') {
71
+ end(AUTHORIZATION_ENDED);
72
+ return;
73
+ }
74
+ if (message.kind === 'event') {
75
+ observations.get(message.id)?.handle.receive(message.value);
76
+ return;
77
+ }
78
+ const waiting = opening.get(message.id);
79
+ if (waiting !== undefined) {
80
+ opening.delete(message.id);
81
+ if (message.kind === 'failure')
82
+ waiting.fail(new Error(message.message));
83
+ else
84
+ waiting.settle(begin(message.id, waiting.topic, message.value));
85
+ return;
86
+ }
87
+ const called = calls.get(message.id);
88
+ if (called === undefined)
89
+ return;
90
+ calls.delete(message.id);
91
+ if (message.kind === 'failure')
92
+ called.fail(new Error(message.message));
93
+ else
94
+ called.settle(message.value);
95
+ });
96
+ port.addEventListener('close', () => {
97
+ end(PORT_CLOSED);
98
+ });
99
+ port.start();
100
+ send({ kind: 'hello' });
101
+ function ask(member, input) {
102
+ if (ended !== null)
103
+ return Promise.reject(new Error(ended));
104
+ if (refusal !== null)
105
+ return Promise.reject(new Error(refusal.reason));
106
+ const id = (sequence += 1);
107
+ return new Promise((settle, fail) => {
108
+ calls.set(id, { settle: settle, fail });
109
+ send({ kind: 'call', id, member, input });
110
+ });
111
+ }
112
+ function watch(topic, input) {
113
+ if (ended !== null)
114
+ return Promise.reject(new Error(ended));
115
+ const id = (sequence += 1);
116
+ if (refusal !== null) {
117
+ return topic === 'connection-refusal'
118
+ ? Promise.resolve(begin(id, topic, refusal))
119
+ : Promise.reject(new Error(refusal.reason));
120
+ }
121
+ return new Promise((settle, fail) => {
122
+ opening.set(id, { topic, settle, fail });
123
+ send({ kind: 'observe', id, topic, input });
124
+ });
125
+ }
126
+ return {
127
+ rooms: () => ask('rooms', []),
128
+ query: ((query) => ask('query', [query])),
129
+ search: (request) => ask('search', [request]),
130
+ types: (locator) => ask('types', [locator]),
131
+ roomDraft: {
132
+ list: () => ask('roomDraft.list', []),
133
+ read: (room, path) => ask('roomDraft.read', [room, path]),
134
+ write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
135
+ discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
136
+ },
137
+ save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
138
+ presentation: {
139
+ read: () => ask('presentation.read', []),
140
+ write: (value) => ask('presentation.write', [value]),
141
+ },
142
+ conversation: {
143
+ list: () => ask('conversation.list', []),
144
+ read: (conversation, options) => ask('conversation.read', [conversation, options]),
145
+ create: (input) => ask('conversation.create', [input]),
146
+ send: (conversation) => ask('conversation.send', [conversation]),
147
+ answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
148
+ interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
149
+ kill: (conversation) => ask('conversation.kill', [conversation]),
150
+ cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
151
+ delete: (conversation) => ask('conversation.delete', [conversation]),
152
+ },
153
+ chatDraft: {
154
+ write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
155
+ discard: (conversation) => ask('chatDraft.discard', [conversation]),
156
+ },
157
+ history: (locator, path, query) => ask('history', [locator, path, query]),
158
+ call: (name, input) => ask('call', [name, input]),
159
+ reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
160
+ log: () => ask('log', []),
161
+ persistence: () => ask('persistence', []),
162
+ observe: ((topic, ...input) => watch(topic, input)),
163
+ reauthorize: () => ask('reauthorize', []),
164
+ };
165
+ }
@@ -1,23 +1,30 @@
1
1
  import { type Document, type Validation } from '@agentshouse/mdmodel';
2
- import type { Selector } from '@agentshouse/query';
3
- import type { AttachedModelBinding, ModelState } from './model.js';
2
+ import type { ModelState } from './model.js';
4
3
  import type { MdModelIdentity } from './adapter.js';
4
+ import type { Refused } from './transfer.js';
5
5
  export declare const MD_MODEL: MdModelIdentity;
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
6
  export type Collection = {
14
7
  documents: Readonly<Record<string, Document>>;
15
- types: readonly MdType[];
8
+ composition: Composition;
16
9
  };
17
- export declare function parseCollection(text: Readonly<Record<string, string>>, model: ModelState): Collection;
18
- export declare function readCollection(text: Readonly<Record<string, string>>, collectionRoot: string, model: ModelState): Collection | null;
19
- export declare function validRoot(root: unknown): root is string;
20
- export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], collectionRoot: string, model: ModelState, binding: AttachedModelBinding | null): Validation & {
21
- source?: 'content' | 'model';
10
+ export type Composition = {
11
+ model: ModelState;
12
+ selection: {
13
+ roots: readonly string[];
14
+ model: ModelState;
15
+ } | null;
22
16
  };
17
+ export declare function governing(composition: Composition, path: string): ModelState;
18
+ type Previous = {
19
+ text: Readonly<Record<string, string>>;
20
+ collection: Collection;
21
+ };
22
+ export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
23
+ export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
24
+ kind: 'read';
25
+ collection: Collection;
26
+ } | Refused;
27
+ export declare function validRoot(root: unknown): root is string;
28
+ export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
29
+ export {};
23
30
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,eAAO,MAAM,SAAS,EAAE,QAAyC,CAAC;AAElE,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,E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