@agentshouse/mdruntime 0.1.0-cf6d5f0a5c9c8 → 0.1.0-cf6e25bcd52f6

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 (185) hide show
  1. package/README.md +21 -8
  2. package/dist/adapter.d.ts +139 -32
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +38 -4
  7. package/dist/attempt.d.ts +16 -0
  8. package/dist/attempt.d.ts.map +1 -0
  9. package/dist/attempt.js +70 -0
  10. package/dist/binary.d.ts +18 -0
  11. package/dist/binary.d.ts.map +1 -0
  12. package/dist/binary.js +8 -0
  13. package/dist/bootstrap.d.ts +32 -9
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +192 -67
  16. package/dist/chain.d.ts +11 -0
  17. package/dist/chain.d.ts.map +1 -0
  18. package/dist/chain.js +64 -0
  19. package/dist/change-set.d.ts +9 -14
  20. package/dist/change-set.d.ts.map +1 -1
  21. package/dist/change-set.js +11 -62
  22. package/dist/change.d.ts +45 -0
  23. package/dist/change.d.ts.map +1 -1
  24. package/dist/change.js +34 -0
  25. package/dist/client.d.ts +33 -14
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +123 -21
  28. package/dist/collection.d.ts +12 -6
  29. package/dist/collection.d.ts.map +1 -1
  30. package/dist/collection.js +51 -76
  31. package/dist/compile.d.ts +16 -0
  32. package/dist/compile.d.ts.map +1 -0
  33. package/dist/compile.js +765 -0
  34. package/dist/connection.d.ts +60 -20
  35. package/dist/connection.d.ts.map +1 -1
  36. package/dist/connection.js +3825 -793
  37. package/dist/conversation.d.ts +42 -12
  38. package/dist/conversation.d.ts.map +1 -1
  39. package/dist/conversation.js +642 -188
  40. package/dist/digest.d.ts +7 -0
  41. package/dist/digest.d.ts.map +1 -0
  42. package/dist/digest.js +113 -0
  43. package/dist/durability.d.ts +5 -1
  44. package/dist/durability.d.ts.map +1 -1
  45. package/dist/durability.js +5 -0
  46. package/dist/entry.d.ts +19 -0
  47. package/dist/entry.d.ts.map +1 -0
  48. package/dist/entry.js +151 -0
  49. package/dist/expectation.d.ts +21 -0
  50. package/dist/expectation.d.ts.map +1 -0
  51. package/dist/expectation.js +70 -0
  52. package/dist/failure.d.ts +13 -0
  53. package/dist/failure.d.ts.map +1 -0
  54. package/dist/failure.js +19 -0
  55. package/dist/fence.d.ts +6 -0
  56. package/dist/fence.d.ts.map +1 -0
  57. package/dist/fence.js +10 -0
  58. package/dist/file.d.ts +2 -19
  59. package/dist/file.d.ts.map +1 -1
  60. package/dist/file.js +7 -122
  61. package/dist/fulltext.d.ts +27 -0
  62. package/dist/fulltext.d.ts.map +1 -0
  63. package/dist/fulltext.js +368 -0
  64. package/dist/host.d.ts +15 -3
  65. package/dist/host.d.ts.map +1 -1
  66. package/dist/host.js +134 -22
  67. package/dist/identity.d.ts +3 -0
  68. package/dist/identity.d.ts.map +1 -1
  69. package/dist/identity.js +9 -0
  70. package/dist/index.d.ts +19 -9
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +8 -0
  73. package/dist/live.d.ts +22 -0
  74. package/dist/live.d.ts.map +1 -0
  75. package/dist/live.js +124 -0
  76. package/dist/media.d.ts +8 -0
  77. package/dist/media.d.ts.map +1 -0
  78. package/dist/media.js +208 -0
  79. package/dist/memory.d.ts +12 -5
  80. package/dist/memory.d.ts.map +1 -1
  81. package/dist/memory.js +128 -29
  82. package/dist/messages.d.ts +28 -0
  83. package/dist/messages.d.ts.map +1 -0
  84. package/dist/messages.js +90 -0
  85. package/dist/model.d.ts +13 -4
  86. package/dist/model.d.ts.map +1 -1
  87. package/dist/model.js +17 -2
  88. package/dist/name.d.ts +4 -0
  89. package/dist/name.d.ts.map +1 -0
  90. package/dist/name.js +122 -0
  91. package/dist/observation.d.ts +20 -2
  92. package/dist/observation.d.ts.map +1 -1
  93. package/dist/observation.js +113 -12
  94. package/dist/open.d.ts +2 -0
  95. package/dist/open.d.ts.map +1 -0
  96. package/dist/open.js +1 -0
  97. package/dist/opened.d.ts +22 -0
  98. package/dist/opened.d.ts.map +1 -0
  99. package/dist/opened.js +107 -0
  100. package/dist/outcome.d.ts +73 -3
  101. package/dist/outcome.d.ts.map +1 -1
  102. package/dist/outcome.js +81 -1
  103. package/dist/overlay.d.ts +15 -5
  104. package/dist/overlay.d.ts.map +1 -1
  105. package/dist/overlay.js +136 -180
  106. package/dist/paths.d.ts +1 -0
  107. package/dist/paths.d.ts.map +1 -1
  108. package/dist/paths.js +4 -0
  109. package/dist/query.d.ts +70 -4
  110. package/dist/query.d.ts.map +1 -1
  111. package/dist/query.js +51 -7
  112. package/dist/reach.d.ts +18 -4
  113. package/dist/reach.d.ts.map +1 -1
  114. package/dist/reach.js +246 -68
  115. package/dist/react.d.ts +12 -8
  116. package/dist/react.d.ts.map +1 -1
  117. package/dist/react.js +8 -17
  118. package/dist/readiness.d.ts +64 -0
  119. package/dist/readiness.d.ts.map +1 -0
  120. package/dist/readiness.js +33 -0
  121. package/dist/reads.d.ts +11 -0
  122. package/dist/reads.d.ts.map +1 -0
  123. package/dist/reads.js +100 -0
  124. package/dist/recovery.d.ts +25 -0
  125. package/dist/recovery.d.ts.map +1 -0
  126. package/dist/recovery.js +198 -0
  127. package/dist/refresh.d.ts +16 -15
  128. package/dist/refresh.d.ts.map +1 -1
  129. package/dist/refresh.js +113 -54
  130. package/dist/replica.d.ts +59 -33
  131. package/dist/replica.d.ts.map +1 -1
  132. package/dist/replica.js +320 -159
  133. package/dist/room-draft.d.ts +41 -9
  134. package/dist/room-draft.d.ts.map +1 -1
  135. package/dist/room-draft.js +185 -36
  136. package/dist/rows.d.ts +37 -35
  137. package/dist/rows.d.ts.map +1 -1
  138. package/dist/rows.js +173 -102
  139. package/dist/save.d.ts +73 -4
  140. package/dist/save.d.ts.map +1 -1
  141. package/dist/save.js +820 -151
  142. package/dist/search.d.ts +41 -29
  143. package/dist/search.d.ts.map +1 -1
  144. package/dist/search.js +37 -105
  145. package/dist/seed.d.ts +16 -0
  146. package/dist/seed.d.ts.map +1 -0
  147. package/dist/seed.js +75 -0
  148. package/dist/shared.d.ts +16 -0
  149. package/dist/shared.d.ts.map +1 -0
  150. package/dist/shared.js +431 -0
  151. package/dist/status.d.ts +11 -2
  152. package/dist/status.d.ts.map +1 -1
  153. package/dist/status.js +3 -9
  154. package/dist/store.d.ts +130 -80
  155. package/dist/store.d.ts.map +1 -1
  156. package/dist/store.js +376 -457
  157. package/dist/stored.d.ts +154 -0
  158. package/dist/stored.d.ts.map +1 -0
  159. package/dist/stored.js +578 -0
  160. package/dist/tables.d.ts +362 -0
  161. package/dist/tables.d.ts.map +1 -0
  162. package/dist/tables.js +627 -0
  163. package/dist/turn.d.ts +9 -0
  164. package/dist/turn.d.ts.map +1 -0
  165. package/dist/turn.js +75 -0
  166. package/dist/validation.d.ts +30 -0
  167. package/dist/validation.d.ts.map +1 -0
  168. package/dist/validation.js +162 -0
  169. package/dist/windows.d.ts +22 -0
  170. package/dist/windows.d.ts.map +1 -0
  171. package/dist/windows.js +89 -0
  172. package/dist/wire.d.ts +172 -33
  173. package/dist/wire.d.ts.map +1 -1
  174. package/dist/wire.js +68 -31
  175. package/dist/words.d.ts +19 -0
  176. package/dist/words.d.ts.map +1 -0
  177. package/dist/words.js +156 -0
  178. package/package.json +26 -15
  179. package/AGENTS.md +0 -253
  180. package/dist/attachment.d.ts +0 -3
  181. package/dist/attachment.d.ts.map +0 -1
  182. package/dist/attachment.js +0 -8
  183. package/dist/read-side.d.ts +0 -18
  184. package/dist/read-side.d.ts.map +0 -1
  185. package/dist/read-side.js +0 -433
package/dist/wire.js CHANGED
@@ -1,35 +1,48 @@
1
+ import { UNCERTAIN } from './outcome.js';
1
2
  const MEMBERS = {
2
- rooms: 'within',
3
- query: 'within',
4
- search: 'within',
5
- types: 'within',
6
- save: 'within',
7
- history: 'within',
8
- call: 'actions',
9
- reached: 'within',
10
- log: 'whole',
11
- persistence: 'runtime',
12
- reauthorize: 'runtime',
13
- 'roomDraft.list': 'within',
14
- 'roomDraft.read': 'within',
15
- 'roomDraft.write': 'within',
16
- 'roomDraft.discard': 'within',
17
- 'presentation.read': 'app',
18
- 'presentation.write': 'app',
19
- 'conversation.list': 'within',
20
- 'conversation.read': 'within',
21
- 'conversation.create': 'within',
22
- 'conversation.send': 'within',
23
- 'conversation.answer': 'within',
24
- 'conversation.interrupt': 'within',
25
- 'conversation.kill': 'within',
26
- 'conversation.cancel': 'within',
27
- 'conversation.delete': 'within',
28
- 'chatDraft.write': 'within',
29
- 'chatDraft.discard': 'within',
3
+ rooms: { reach: 'within', effect: 'read' },
4
+ query: { reach: 'within', effect: 'read' },
5
+ search: { reach: 'within', effect: 'read' },
6
+ types: { reach: 'within', effect: 'read' },
7
+ save: { reach: 'within', effect: 'write' },
8
+ saveParts: { reach: 'within', effect: 'write' },
9
+ history: { reach: 'within', effect: 'read' },
10
+ resolve: { reach: 'within', effect: 'read' },
11
+ 'binaryFile.read': { reach: 'within', effect: 'read' },
12
+ 'binaryFile.link': { reach: 'within', effect: 'read' },
13
+ 'binaryFile.show': { reach: 'within', effect: 'read' },
14
+ 'binaryFile.attach': { reach: 'within', effect: 'action' },
15
+ 'binaryFile.part': { reach: 'within', effect: 'read' },
16
+ call: { reach: 'actions', effect: 'action' },
17
+ reached: { reach: 'within', effect: 'read' },
18
+ log: { reach: 'whole', effect: 'read' },
19
+ cleanUp: { reach: 'whole', effect: 'write' },
20
+ persistence: { reach: 'runtime', effect: 'read' },
21
+ retry: { reach: 'runtime', effect: 'write' },
22
+ reauthorize: { reach: 'runtime', effect: 'write' },
23
+ 'roomDraft.list': { reach: 'within', effect: 'read' },
24
+ 'roomDraft.read': { reach: 'within', effect: 'read' },
25
+ 'roomDraft.write': { reach: 'within', effect: 'write' },
26
+ 'roomDraft.discard': { reach: 'within', effect: 'write' },
27
+ 'presentation.read': { reach: 'app', effect: 'read' },
28
+ 'presentation.write': { reach: 'app', effect: 'write' },
29
+ 'presentation.edit': { reach: 'app', effect: 'write' },
30
+ 'conversation.list': { reach: 'within', effect: 'read' },
31
+ 'conversation.read': { reach: 'within', effect: 'read' },
32
+ 'conversation.create': { reach: 'within', effect: 'action' },
33
+ 'conversation.send': { reach: 'within', effect: 'action' },
34
+ 'conversation.answer': { reach: 'within', effect: 'action' },
35
+ 'conversation.interrupt': { reach: 'within', effect: 'action' },
36
+ 'conversation.kill': { reach: 'within', effect: 'action' },
37
+ 'conversation.cancel': { reach: 'within', effect: 'action' },
38
+ 'conversation.delete': { reach: 'within', effect: 'action' },
39
+ 'chatDraft.write': { reach: 'within', effect: 'write' },
40
+ 'chatDraft.prepend': { reach: 'within', effect: 'write' },
41
+ 'chatDraft.discard': { reach: 'within', effect: 'write' },
30
42
  };
31
43
  const TOPICS = {
32
44
  rooms: 'within',
45
+ readiness: 'within',
33
46
  'connection-refusal': 'runtime',
34
47
  'storage-loss': 'runtime',
35
48
  'deployment-facts': 'runtime',
@@ -42,8 +55,23 @@ const TOPICS = {
42
55
  presentation: 'app',
43
56
  conversation: 'within',
44
57
  conversations: 'within',
58
+ agents: 'within',
45
59
  };
46
- export const WIRE_REACH = { members: MEMBERS, topics: TOPICS };
60
+ export const WIRE = { members: MEMBERS, topics: TOPICS };
61
+ export function unanswered(call) {
62
+ const { effect } = MEMBERS[call.member];
63
+ if (effect === 'read')
64
+ return null;
65
+ if (effect === 'action')
66
+ return { kind: 'result', id: call.id, value: UNCERTAIN };
67
+ return {
68
+ kind: 'failure',
69
+ id: call.id,
70
+ message: UNCERTAIN.code,
71
+ code: UNCERTAIN.code,
72
+ retryable: UNCERTAIN.retryable,
73
+ };
74
+ }
47
75
  export const AUTHORIZATION_ENDED = 'the host authorization ended';
48
76
  export const PORT_CLOSED = 'the port closed';
49
77
  function body(message) {
@@ -103,8 +131,17 @@ export function answer(message) {
103
131
  return { kind: 'result', id: shape.id, value: record.value };
104
132
  if (shape.kind === 'event')
105
133
  return { kind: 'event', id: shape.id, value: record.value };
106
- if (shape.kind === 'failure' && typeof record.message === 'string') {
107
- return { kind: 'failure', id: shape.id, message: record.message };
134
+ if (shape.kind === 'failure' &&
135
+ typeof record.message === 'string' &&
136
+ typeof record.code === 'string' &&
137
+ typeof record.retryable === 'boolean') {
138
+ return {
139
+ kind: 'failure',
140
+ id: shape.id,
141
+ message: record.message,
142
+ code: record.code,
143
+ retryable: record.retryable,
144
+ };
108
145
  }
109
146
  return null;
110
147
  }
@@ -0,0 +1,19 @@
1
+ export type Clause = {
2
+ readonly text: string;
3
+ readonly kind: 'term' | 'stem' | 'prefix' | 'phrase';
4
+ readonly term: string;
5
+ };
6
+ export type Located = {
7
+ readonly start: number;
8
+ readonly end: number;
9
+ };
10
+ export declare function indexed(text: string): string;
11
+ export declare function matchClauses(text: string): Clause[] | null;
12
+ export declare function matchExpression(clauses: readonly Clause[]): string;
13
+ export declare function queryTerms(text: string): string[];
14
+ export declare function snippet(part: string, terms: readonly string[], reach: number): {
15
+ readonly text: string;
16
+ readonly at: readonly [number, number];
17
+ } | null;
18
+ export declare function matched(part: string, terms: readonly string[]): string[];
19
+ //# sourceMappingURL=words.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"words.d.ts","sourceRoot":"","sources":["../src/words.ts"],"names":[],"mappings":"AA0BA,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAYvE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C;AAgBD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAiB1D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAElE;AAMD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjD;AAyDD,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,KAAK,EAAE,MAAM,GACZ;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,IAAI,CAW1E;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAQxE"}
package/dist/words.js ADDED
@@ -0,0 +1,156 @@
1
+ const SPACELESS = /(?:[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}\p{Script=Hangul}]\p{M}*)+/gu;
2
+ const SPACELESS_TERM = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}\p{Script=Hangul}]/u;
3
+ const TOKEN = /(?![\x00-\x7f])\p{S}\p{M}*|[\p{L}\p{N}\p{M}\p{Co}]+/gu;
4
+ const SYMBOL = /(?![\x00-\x7f])\p{S}\p{M}*/gu;
5
+ const MARKED = /([\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}])\p{M}+/gu;
6
+ const INFLECTED = /^[\p{Script=Cyrillic}\p{Script=Greek}]+$/u;
7
+ const FOLD = /\p{M}+/gu;
8
+ const ASCII = /^[\x00-\x7f]$/;
9
+ const PREFIXED_LETTERS = 2;
10
+ const INFLECTED_LETTERS = 4;
11
+ const PHRASE_TERMS = { least: 2, most: 6 };
12
+ const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
13
+ function bigrams(run) {
14
+ const characters = Array.from(run);
15
+ if (characters.length < 2)
16
+ return ` ${run} `;
17
+ const pairs = [];
18
+ for (let index = 0; index + 1 < characters.length; index += 1) {
19
+ pairs.push(characters[index] + characters[index + 1]);
20
+ }
21
+ return ` ${pairs.join(' ')} `;
22
+ }
23
+ export function indexed(text) {
24
+ return text
25
+ .normalize('NFKD')
26
+ .replace(MARKED, '$1')
27
+ .normalize('NFKC')
28
+ .replace(SPACELESS, bigrams)
29
+ .replace(SYMBOL, (symbol) => ` ${symbol.replace(FOLD, '')} `);
30
+ }
31
+ function tokens(text) {
32
+ return [...text.matchAll(TOKEN)].map(([token]) => token.toLowerCase());
33
+ }
34
+ function quoted(token) {
35
+ return `"${token.replaceAll('"', '""')}"`;
36
+ }
37
+ function truncated(term) {
38
+ const letters = Array.from(term);
39
+ if (!INFLECTED.test(term) || letters.length < INFLECTED_LETTERS)
40
+ return null;
41
+ return letters.slice(0, letters.length - (letters.length >= 6 ? 2 : 1)).join('');
42
+ }
43
+ export function matchClauses(text) {
44
+ const terms = tokens(indexed(text));
45
+ if (terms.length === 0)
46
+ return null;
47
+ const unique = [...new Set(terms)];
48
+ const clauses = unique.map((term) => ({ text: quoted(term), kind: 'term', term }));
49
+ for (const term of unique) {
50
+ const stem = truncated(term);
51
+ if (stem !== null)
52
+ clauses.push({ text: `${quoted(stem)}*`, kind: 'stem', term });
53
+ }
54
+ const last = terms[terms.length - 1];
55
+ if (!/\s$/u.test(text) && Array.from(last).length >= PREFIXED_LETTERS) {
56
+ clauses.push({ text: `${quoted(last)}*`, kind: 'prefix', term: last });
57
+ }
58
+ if (terms.length >= PHRASE_TERMS.least && terms.length <= PHRASE_TERMS.most) {
59
+ clauses.push({ text: quoted(terms.join(' ')), kind: 'phrase', term: terms.join(' ') });
60
+ }
61
+ return clauses;
62
+ }
63
+ export function matchExpression(clauses) {
64
+ return clauses.map(({ text }) => text).join(' OR ');
65
+ }
66
+ function folded(text) {
67
+ return text.normalize('NFKD').replace(FOLD, '').toLowerCase();
68
+ }
69
+ export function queryTerms(text) {
70
+ return [...new Set(tokens(text.normalize('NFKC')).map(folded))];
71
+ }
72
+ function agrees(token, term) {
73
+ if (SPACELESS_TERM.test(term))
74
+ return token.includes(term);
75
+ if (token.startsWith(term))
76
+ return true;
77
+ return token.length >= 3 && term.startsWith(token.slice(0, Math.max(3, token.length - 2)));
78
+ }
79
+ function inside(token, offset, term) {
80
+ const pieces = [...GRAPHEMES.segment(token)];
81
+ const owner = [];
82
+ let joined = '';
83
+ for (const [at, { segment }] of pieces.entries()) {
84
+ const part = folded(segment);
85
+ joined += part;
86
+ for (let index = 0; index < part.length; index += 1)
87
+ owner.push(at);
88
+ }
89
+ const found = joined.indexOf(term);
90
+ if (found < 0)
91
+ return null;
92
+ const first = pieces[owner[found]];
93
+ const last = pieces[owner[found + term.length - 1]];
94
+ return { start: offset + first.index, end: offset + last.index + last.segment.length };
95
+ }
96
+ function locate(part, terms) {
97
+ for (const match of part.matchAll(TOKEN)) {
98
+ const token = folded(match[0]);
99
+ for (const term of terms) {
100
+ if (!agrees(token, term))
101
+ continue;
102
+ if (!SPACELESS_TERM.test(term)) {
103
+ return { start: match.index, end: match.index + match[0].length };
104
+ }
105
+ const found = inside(match[0], match.index, term);
106
+ if (found !== null)
107
+ return found;
108
+ }
109
+ }
110
+ return null;
111
+ }
112
+ function settled(part, index) {
113
+ if (index <= 0 || index >= part.length)
114
+ return true;
115
+ const before = part[index - 1];
116
+ const after = part[index];
117
+ if (before === '\n')
118
+ return true;
119
+ return ASCII.test(before) && ASCII.test(after) && !(before === '\r' && after === '\n');
120
+ }
121
+ function edgesAround(part, low, high) {
122
+ let from = Math.max(0, low);
123
+ while (!settled(part, from))
124
+ from -= 1;
125
+ let to = Math.min(part.length, high);
126
+ while (!settled(part, to))
127
+ to += 1;
128
+ const edges = [...GRAPHEMES.segment(part.slice(from, to))].map(({ index }) => from + index);
129
+ edges.push(to);
130
+ return edges;
131
+ }
132
+ export function snippet(part, terms, reach) {
133
+ const located = locate(part, terms);
134
+ if (located === null)
135
+ return null;
136
+ const edges = edgesAround(part, located.start - 2 * reach, located.end + 2 * reach);
137
+ const last = (limit) => edges.filter((edge) => edge <= limit).at(-1) ?? edges[0];
138
+ const first = (limit) => edges.find((edge) => edge >= limit) ?? edges[edges.length - 1];
139
+ const from = last(located.start);
140
+ const to = Math.max(first(Math.min(located.end, from + reach)), first(from + 1));
141
+ const start = first(Math.max(0, from - reach));
142
+ const end = last(Math.min(part.length, to + reach));
143
+ return { text: part.slice(start, end), at: [from - start, to - start] };
144
+ }
145
+ export function matched(part, terms) {
146
+ const found = new Set();
147
+ for (const match of part.matchAll(TOKEN)) {
148
+ const token = folded(match[0]);
149
+ for (const term of terms)
150
+ if (agrees(token, term))
151
+ found.add(term);
152
+ if (found.size === terms.length)
153
+ break;
154
+ }
155
+ return [...found];
156
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-cf6d5f0a5c9c8",
3
+ "version": "0.1.0-cf6e25bcd52f6",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,48 +9,59 @@
9
9
  "access": "public"
10
10
  },
11
11
  "engines": {
12
- "node": ">=24.21.0"
12
+ "node": ">=24.22.1"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "./host": {
20
20
  "types": "./dist/host.d.ts",
21
- "import": "./dist/host.js"
21
+ "default": "./dist/host.js"
22
22
  },
23
23
  "./client": {
24
24
  "types": "./dist/client.d.ts",
25
- "import": "./dist/client.js"
25
+ "default": "./dist/client.js"
26
+ },
27
+ "./entry": {
28
+ "types": "./dist/entry.d.ts",
29
+ "default": "./dist/entry.js"
26
30
  },
27
31
  "./memory": {
28
32
  "types": "./dist/memory.d.ts",
29
- "import": "./dist/memory.js"
33
+ "default": "./dist/memory.js"
34
+ },
35
+ "./tables": {
36
+ "types": "./dist/tables.d.ts",
37
+ "default": "./dist/tables.js"
30
38
  },
31
39
  "./react": {
32
40
  "types": "./dist/react.d.ts",
33
- "import": "./dist/react.js"
41
+ "default": "./dist/react.js"
42
+ },
43
+ "./digest": {
44
+ "types": "./dist/digest.d.ts",
45
+ "default": "./dist/digest.js"
34
46
  },
35
47
  "./package.json": "./package.json"
36
48
  },
37
49
  "files": [
38
50
  "dist",
39
- "AGENTS.md",
51
+ "!dist/chat.*",
52
+ "!dist/chat/",
40
53
  "README.md",
41
54
  "LICENSE"
42
55
  ],
43
56
  "dependencies": {
44
- "@agentshouse/mdmodel": "0.1.0-c64dbada0730d",
45
- "@tanstack/db": "0.9.2",
46
- "minisearch": "7.2.0"
57
+ "@agentshouse/mdmodel": "0.1.0-c9952fa046c11"
47
58
  },
48
59
  "peerDependencies": {
49
60
  "react": ">=18"
50
61
  },
51
- "peerDependenciesMeta": {
52
- "react": {
53
- "optional": true
54
- }
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/agentshouse/core.git",
65
+ "directory": "mdruntime/packages/mdruntime"
55
66
  }
56
67
  }
package/AGENTS.md DELETED
@@ -1,253 +0,0 @@
1
- # Instructions for the App Creator's agent
2
-
3
- These instructions address an agent in an environment with Git. Obtain the
4
- App Repository, change it, build, and push. They are documentation, not
5
- enforcement.
6
-
7
- ## The MD Runtime API
8
-
9
- App code reaches the MD Runtime through the remote client. The surfaces are
10
- Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
- the reported persistence answer, reauthorization, conversation, the chat draft,
12
- and Presentation State. Sync Status, the Service Mode, the storage-loss
13
- statement, the deployment facts and the signed-in member are observations only.
14
-
15
- The host attaches each port with its reach, and every member and observation
16
- answers within it: a Room outside it answers as one the replica does not hold,
17
- Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
- shows only those Documents and the Types of the models that govern them, and
19
- without conversations the conversation members, the chat draft and the
20
- conversation observation hold none.
21
- A change of the reach reaches every open observation as its new value, a query
22
- keeping every unchanged Document the same object.
23
-
24
- Every `observe` resolves, once its first value has arrived, to a handle:
25
- `current()` is the latest complete value, `subscribe(listener)` hears each later
26
- value whole and returns its unsubscribe, and `close()` ends the observation.
27
- Closing the port ends every handle and rejects every pending call and
28
- observation; a client that reconnects observes again.
29
-
30
- Each conversation the Provider's conversation list names is held complete in the
31
- browser. `conversation.list()` and `observe('conversations')` answer each with its
32
- Agent's identity and name, its name, created and finished times, last outcome and live
33
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
34
- and `started`, when the running turn began, or `null`.
35
- Observe one with `observe('conversation', id, { limit })`: the view
36
- holds its latest `limit` messages, or all of them, oldest first, its chat
37
- draft, and what the Provider streams for it whether or not anything views it:
38
- the running `turn` with its message parts and its context in use and window, the
39
- open questions, the process state, and the CLI's commands and options. These live
40
- only in memory: the message accepted under the turn's id replaces the running turn,
41
- and none of them is stored or searchable.
42
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
43
- sending it is a Provider Action that needs the Provider reachable and is never
44
- queued.
45
-
46
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
47
- that its Documents link by the Provider's reference, ordered by `reference`,
48
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
49
- `entry`. They are as the Provider last declared them and hold no bytes;
50
- open one through the Provider Action that serves it.
51
-
52
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
53
- touch the network.
54
- History and Call go to the Provider through the Adapter. A Call result whose
55
- effect the Provider places in a Room carries `at`, that Room and Room Version;
56
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
57
- reached it, and the MD Runtime keeps refreshing that Room until it has;
58
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
59
- that document was written at a later Room Version. Each History revision
60
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
61
- History of a Path no current document holds answers the removed document's
62
- revisions with `deleted: true`, newest first; that revision is what a link to
63
- the Path opens. Every
64
- member of the
65
- client is asynchronous. Results are detached snapshots. Nothing in this
66
- surface returns the authorization, performs a request the App's code
67
- composes, or exposes the browser store.
68
-
69
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
70
- opaque value using the host's contract.
71
-
72
- `observe('member')` answers who uses the App: the User the Provider signed in,
73
- `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
74
- whose `change.author.id` equals its `id` is that User's own. It is `null` until
75
- the Provider first names one, and where it names none, such as a Site. The
76
- MD Runtime keeps it with the Local Replicas, so it answers offline once known,
77
- and every port hears the next member the Provider names; signing out answers
78
- `null`, then ends the observation with the authorization. It is the only way App code learns who
79
- uses it.
80
-
81
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
82
- ships in no bundle.
83
-
84
- ## Local Query rules
85
-
86
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
87
- result and hears it again only when it changes, keeping every unchanged Document
88
- the same object, so a component can tell what changed by identity. A query is
89
- data:
90
-
91
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
92
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
93
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
94
- - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
95
- `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
96
- meets a list applies to every item and a number names one item. `where` names
97
- pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
98
- when any item satisfies it. A bare value is equality; the operators are `$eq`,
99
- `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
100
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
101
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
102
- text and `$size: 0` an empty list. A date compares in calendar order and never
103
- with a date-time. A reference compares by the Room Path it resolves to.
104
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
105
- values. There is no text containment or regular
106
- expression.
107
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
108
- reference at pointer `field`, at any depth, points to a matching Document of the
109
- same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
110
- matching Document of the same Room references. Each keeps a Document once.
111
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
112
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
113
- list of pointers and `sections` `'all'` or a list of names. Selected pointers
114
- return the frontmatter holding only them, nested as written. A backlink names
115
- the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
116
- Document also returns its MD Type. A non-Markdown Document or binary link
117
- target returns only Room and Path. An unselected part is absent. Select only
118
- what a screen shows: a list that selects the Markdown hears every edit of it.
119
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
120
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
121
- or `null` for a write the Provider made itself, and `time` is the Provider's
122
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
123
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
124
- saved write takes the Provider's own once it is Accepted. A
125
- Room's last change is its Document with the latest `time`.
126
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
127
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
128
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
129
- over every match and ordered by `count` or a key. A sort or group takes only a
130
- pointer that holds one value. `limit` bounds the Documents or the groups.
131
- - **Results and errors.** A result carries no Room Version: read freshness from
132
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
133
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
134
- answers an empty result in its place.
135
-
136
- ## Local Search rules
137
-
138
- `search({ text, documents, conversations, limit })` answers once, by words, from
139
- local state, with MiniSearch at its default configuration. There is no observed
140
- search.
141
-
142
- - **What is found.** A Document by its field values, its sections' headings and
143
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
144
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
145
- word forms, typo tolerance or prefix matching.
146
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
147
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
148
- apply before `limit`, which bounds each list; without it every hit returns.
149
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
150
- hits of one list of one search. A Document hit names its `room`, `path` and
151
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
152
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
153
- `path`, or `text`. A hit carries no position; mark the words in the text you
154
- show. An invalid filter fails with its Local Query error.
155
-
156
- ## Room Draft, Save, and outcome rules
157
-
158
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
159
- tab. It is durable: it survives reload and navigation. A Room that Discovery
160
- stops listing takes its Room Drafts and its queue with it.
161
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
162
- the revision you read, or `null` when there was none, and every part it should
163
- now change: fields, sections and the preamble, or the whole Markdown, a
164
- creation, a move, or a removal. A part new to the Room Draft names its base,
165
- the value you showed when it was opened; the MD Runtime keeps a part's first
166
- base. A binary link target has a Room Draft too, for a move or a removal, with
167
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
168
- the current Room Draft; read it and write again.
169
-
170
- Save takes one Room and the Room Drafts of it to save, each with its revision,
171
- validates locally, and on success appends one Change Batch to that Room's
172
- queue and removes those Room Drafts. It is refused as `stale`, as
173
- `changed-underneath` naming each part whose base no longer matches the visible
174
- state, or by a local validation rule, and then creates nothing and leaves every
175
- Room Draft in place. A directory move or removal is a move or removal part on
176
- each Document and binary link target beneath it, saved together.
177
-
178
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
179
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
180
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
181
- longer applies over the Room each leave the queue and return as Room Drafts on
182
- the Documents they changed, marked with why: the Provider's structured refusal
183
- code and fields as returned, not known to have applied, or withdrawn locally.
184
- The rest of the queue keeps synchronizing, and Sync Status requires attention
185
- until each returned Room Draft is saved again or discarded. A Change Batch
186
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
187
- Pending one, and a returned Room Draft says why it returned. Transport
188
- failure and Provider unavailability keep work Pending and do not infer a
189
- rejection. A refusal the Provider marks retryable stays Pending until the reset
190
- it names; the MD Runtime retries the same Change Batch identity and payload and
191
- never infers an outcome from transport uncertainty. The MD Runtime never
192
- combines, reorders, or rebases.
193
-
194
- `observe('service-mode')` answers the Provider's Service
195
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
196
- its Change Batch waits unsent, and the queue is submitted in order once the
197
- Provider reopens writes. An Action is never held: a write the Provider refuses
198
- for the halt returns that refusal to its caller. Show the Provider as read-only
199
- instead of retrying.
200
-
201
- ## The neutrality rule
202
-
203
- No module outside an Adapter package imports, names, or special-cases a
204
- Provider. MD UI and every App reach data only through the client entry.
205
-
206
- ## Content-safety rules
207
-
208
- The Provider authorization belongs to the Runtime host and is never readable
209
- by the App's code. The App's code reaches the network only at the external
210
- origins its manifest declares, empty by default, and the Provider enforces
211
- that set. Every request to the Provider itself goes through the MD Runtime.
212
- Rendered Markdown never executes scripts, renders raw HTML only for the
213
- details and summary elements, and loads images and other resources only from
214
- origins the Provider's policy allows.
215
-
216
- ## Launch promises MD UI keeps
217
-
218
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
219
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
220
- a desktop. Its strings are English only, dates and numbers follow the
221
- browser locale, and content is never translated. Light and dark themes come
222
- from CSS custom properties with the browser's preference as the default and
223
- an App's override respected. What an App Creator's agent adds carries none
224
- of these promises by itself. Reading, querying and searching never wait for
225
- the network. Data lives only in the App Creator's browser and with the Provider.
226
-
227
- ## App code takes the client its host hands it and never constructs a Runtime
228
-
229
- App code takes the client its host hands it: in House,
230
- `houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
231
- client House built into the page. It never constructs a Runtime or a client.
232
- It imports only types from `@agentshouse/mdruntime/client`, does not call
233
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
234
- the host entry, or the Adapter package. Hosts and tests use those entries; the
235
- served App does not.
236
-
237
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
238
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
239
- the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
240
- first value arrives, then `{ state: 'ready', value }`, re-rendering on each
241
- change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
242
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
243
- already there, keeping the bases its parts have, or onto a new one, and saves
244
- them together. A refused Save leaves the Room Drafts for the App to save again
245
- or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
246
- roomDrafts)` is that save outside a component. A react-admin or Refine App
247
- reads and writes its Rooms through the data providers of
248
- `@agentshouse/mdruntime-families`.
249
-
250
- ## What an agent must never do
251
-
252
- An agent must never read the authorization, load code from a Room, call the
253
- Provider directly, or rebase a refused Change Batch.
@@ -1,3 +0,0 @@
1
- import type { RoomAttachment } from './adapter.js';
2
- export declare function declaredAttachments(pages: readonly (readonly RoomAttachment[])[]): readonly RoomAttachment[];
3
- //# sourceMappingURL=attachment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,GAC5C,SAAS,cAAc,EAAE,CAQ3B"}
@@ -1,8 +0,0 @@
1
- export function declaredAttachments(pages) {
2
- const byReference = new Map();
3
- for (const page of pages) {
4
- for (const attachment of page)
5
- byReference.set(attachment.reference, attachment);
6
- }
7
- return [...byReference.values()].sort((left, right) => left.reference < right.reference ? -1 : left.reference > right.reference ? 1 : 0);
8
- }