@agentshouse/mdruntime 0.1.0-ce531b51ff088 → 0.1.0-ce5c5bb29be5a

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 +24 -11
  2. package/dist/adapter.d.ts +172 -48
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +1 -9
  5. package/dist/attached-model.d.ts +15 -0
  6. package/dist/attached-model.d.ts.map +1 -0
  7. package/dist/attached-model.js +81 -0
  8. package/dist/attempt.d.ts +16 -0
  9. package/dist/attempt.d.ts.map +1 -0
  10. package/dist/attempt.js +70 -0
  11. package/dist/binary.d.ts +18 -0
  12. package/dist/binary.d.ts.map +1 -0
  13. package/dist/binary.js +8 -0
  14. package/dist/bootstrap.d.ts +36 -6
  15. package/dist/bootstrap.d.ts.map +1 -1
  16. package/dist/bootstrap.js +199 -48
  17. package/dist/chain.d.ts +11 -0
  18. package/dist/chain.d.ts.map +1 -0
  19. package/dist/chain.js +64 -0
  20. package/dist/change-set.d.ts +9 -14
  21. package/dist/change-set.d.ts.map +1 -1
  22. package/dist/change-set.js +11 -56
  23. package/dist/change.d.ts +45 -0
  24. package/dist/change.d.ts.map +1 -1
  25. package/dist/change.js +34 -0
  26. package/dist/client.d.ts +37 -15
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +159 -29
  29. package/dist/collection.d.ts +12 -14
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +52 -56
  32. package/dist/compile.d.ts +16 -0
  33. package/dist/compile.d.ts.map +1 -0
  34. package/dist/compile.js +773 -0
  35. package/dist/connection.d.ts +67 -28
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +3911 -1044
  38. package/dist/conversation.d.ts +59 -18
  39. package/dist/conversation.d.ts.map +1 -1
  40. package/dist/conversation.js +849 -248
  41. package/dist/digest.d.ts +7 -0
  42. package/dist/digest.d.ts.map +1 -0
  43. package/dist/digest.js +113 -0
  44. package/dist/durability.d.ts +4 -1
  45. package/dist/durability.d.ts.map +1 -1
  46. package/dist/durability.js +5 -0
  47. package/dist/entry.d.ts +20 -0
  48. package/dist/entry.d.ts.map +1 -0
  49. package/dist/entry.js +151 -0
  50. package/dist/expectation.d.ts +21 -0
  51. package/dist/expectation.d.ts.map +1 -0
  52. package/dist/expectation.js +70 -0
  53. package/dist/failure.d.ts +13 -0
  54. package/dist/failure.d.ts.map +1 -0
  55. package/dist/failure.js +19 -0
  56. package/dist/fence.d.ts +6 -0
  57. package/dist/fence.d.ts.map +1 -0
  58. package/dist/fence.js +10 -0
  59. package/dist/file.d.ts +2 -19
  60. package/dist/file.d.ts.map +1 -1
  61. package/dist/file.js +7 -122
  62. package/dist/fulltext.d.ts +27 -0
  63. package/dist/fulltext.d.ts.map +1 -0
  64. package/dist/fulltext.js +370 -0
  65. package/dist/host.d.ts +20 -2
  66. package/dist/host.d.ts.map +1 -1
  67. package/dist/host.js +166 -48
  68. package/dist/identity.d.ts +4 -0
  69. package/dist/identity.d.ts.map +1 -1
  70. package/dist/identity.js +16 -1
  71. package/dist/index.d.ts +20 -9
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +9 -0
  74. package/dist/live.d.ts +22 -0
  75. package/dist/live.d.ts.map +1 -0
  76. package/dist/live.js +124 -0
  77. package/dist/media.d.ts +8 -0
  78. package/dist/media.d.ts.map +1 -0
  79. package/dist/media.js +218 -0
  80. package/dist/memory.d.ts +22 -8
  81. package/dist/memory.d.ts.map +1 -1
  82. package/dist/memory.js +208 -47
  83. package/dist/messages.d.ts +28 -0
  84. package/dist/messages.d.ts.map +1 -0
  85. package/dist/messages.js +90 -0
  86. package/dist/model.d.ts +22 -14
  87. package/dist/model.d.ts.map +1 -1
  88. package/dist/model.js +13 -4
  89. package/dist/name.d.ts +4 -0
  90. package/dist/name.d.ts.map +1 -0
  91. package/dist/name.js +122 -0
  92. package/dist/observation.d.ts +21 -1
  93. package/dist/observation.d.ts.map +1 -1
  94. package/dist/observation.js +128 -17
  95. package/dist/open.d.ts +2 -0
  96. package/dist/open.d.ts.map +1 -0
  97. package/dist/open.js +1 -0
  98. package/dist/opened.d.ts +22 -0
  99. package/dist/opened.d.ts.map +1 -0
  100. package/dist/opened.js +107 -0
  101. package/dist/outcome.d.ts +72 -5
  102. package/dist/outcome.d.ts.map +1 -1
  103. package/dist/outcome.js +81 -1
  104. package/dist/overlay.d.ts +15 -5
  105. package/dist/overlay.d.ts.map +1 -1
  106. package/dist/overlay.js +136 -180
  107. package/dist/paths.d.ts +1 -1
  108. package/dist/paths.d.ts.map +1 -1
  109. package/dist/paths.js +4 -16
  110. package/dist/query.d.ts +78 -7
  111. package/dist/query.d.ts.map +1 -1
  112. package/dist/query.js +126 -43
  113. package/dist/reach.d.ts +54 -0
  114. package/dist/reach.d.ts.map +1 -0
  115. package/dist/reach.js +448 -0
  116. package/dist/react.d.ts +43 -0
  117. package/dist/react.d.ts.map +1 -0
  118. package/dist/react.js +54 -0
  119. package/dist/readiness.d.ts +52 -0
  120. package/dist/readiness.d.ts.map +1 -0
  121. package/dist/readiness.js +27 -0
  122. package/dist/recovery.d.ts +26 -0
  123. package/dist/recovery.d.ts.map +1 -0
  124. package/dist/recovery.js +224 -0
  125. package/dist/refresh.d.ts +19 -7
  126. package/dist/refresh.d.ts.map +1 -1
  127. package/dist/refresh.js +125 -53
  128. package/dist/replica.d.ts +58 -33
  129. package/dist/replica.d.ts.map +1 -1
  130. package/dist/replica.js +320 -158
  131. package/dist/room-draft.d.ts +60 -10
  132. package/dist/room-draft.d.ts.map +1 -1
  133. package/dist/room-draft.js +227 -42
  134. package/dist/rows.d.ts +39 -34
  135. package/dist/rows.d.ts.map +1 -1
  136. package/dist/rows.js +195 -81
  137. package/dist/save.d.ts +74 -6
  138. package/dist/save.d.ts.map +1 -1
  139. package/dist/save.js +898 -181
  140. package/dist/search.d.ts +41 -29
  141. package/dist/search.d.ts.map +1 -1
  142. package/dist/search.js +37 -105
  143. package/dist/seed.d.ts +16 -0
  144. package/dist/seed.d.ts.map +1 -0
  145. package/dist/seed.js +75 -0
  146. package/dist/shared.d.ts +15 -0
  147. package/dist/shared.d.ts.map +1 -0
  148. package/dist/shared.js +421 -0
  149. package/dist/status.d.ts +7 -2
  150. package/dist/status.d.ts.map +1 -1
  151. package/dist/status.js +3 -9
  152. package/dist/store.d.ts +109 -59
  153. package/dist/store.d.ts.map +1 -1
  154. package/dist/store.js +323 -344
  155. package/dist/stored.d.ts +130 -0
  156. package/dist/stored.d.ts.map +1 -0
  157. package/dist/stored.js +560 -0
  158. package/dist/tables.d.ts +325 -0
  159. package/dist/tables.d.ts.map +1 -0
  160. package/dist/tables.js +578 -0
  161. package/dist/transfer.d.ts +0 -5
  162. package/dist/transfer.d.ts.map +1 -1
  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 +29 -0
  167. package/dist/validation.d.ts.map +1 -0
  168. package/dist/validation.js +101 -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 +194 -19
  173. package/dist/wire.d.ts.map +1 -1
  174. package/dist/wire.js +90 -61
  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 +33 -10
  179. package/AGENTS.md +0 -207
  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 -14
  184. package/dist/read-side.d.ts.map +0 -1
  185. package/dist/read-side.js +0 -371
package/dist/wire.js CHANGED
@@ -1,63 +1,79 @@
1
- export const RUNTIME_WIRE_PROTOCOL = 8;
2
- export const PROTOCOL_MISMATCH = {
3
- reason: 'client-host-protocol-mismatch',
4
- reauthorizationOffered: false,
5
- refusal: null,
1
+ import { UNCERTAIN } from './outcome.js';
2
+ const MEMBERS = {
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' },
6
42
  };
7
- const MEMBERS = [
8
- 'rooms',
9
- 'query',
10
- 'search',
11
- 'types',
12
- 'save',
13
- 'history',
14
- 'call',
15
- 'reached',
16
- 'log',
17
- 'persistence',
18
- 'reauthorize',
19
- 'roomDraft.list',
20
- 'roomDraft.read',
21
- 'roomDraft.write',
22
- 'roomDraft.discard',
23
- 'presentation.read',
24
- 'presentation.write',
25
- 'conversation.list',
26
- 'conversation.read',
27
- 'conversation.create',
28
- 'conversation.send',
29
- 'conversation.answer',
30
- 'conversation.interrupt',
31
- 'conversation.kill',
32
- 'conversation.cancel',
33
- 'conversation.delete',
34
- 'chatDraft.write',
35
- 'chatDraft.discard',
36
- ];
37
- const TOPICS = [
38
- 'rooms',
39
- 'connection-refusal',
40
- 'storage-loss',
41
- 'deployment-facts',
42
- 'sync-status',
43
- 'service-mode',
44
- 'query',
45
- 'queue',
46
- 'room-drafts',
47
- 'presentation',
48
- 'conversation',
49
- ];
50
- export const AUTHORIZATION_ENDED = 'the host authorization ended';
51
- export const PORT_CLOSED = 'the port closed';
52
- export function envelope(message) {
53
- return { mdRuntime: RUNTIME_WIRE_PROTOCOL, message };
54
- }
55
- export function carried(data) {
56
- if (typeof data !== 'object' || data === null || !('mdRuntime' in data))
43
+ const TOPICS = {
44
+ rooms: 'within',
45
+ readiness: 'within',
46
+ 'connection-refusal': 'runtime',
47
+ 'storage-loss': 'runtime',
48
+ 'deployment-facts': 'runtime',
49
+ 'sync-status': 'within',
50
+ 'service-mode': 'runtime',
51
+ member: 'runtime',
52
+ query: 'within',
53
+ queue: 'within',
54
+ 'room-drafts': 'within',
55
+ presentation: 'app',
56
+ conversation: 'within',
57
+ conversations: 'within',
58
+ agents: 'within',
59
+ };
60
+ export const WIRE = { members: MEMBERS, topics: TOPICS };
61
+ export function unanswered(call) {
62
+ const { effect } = MEMBERS[call.member];
63
+ if (effect === 'read')
57
64
  return null;
58
- const record = data;
59
- return { matching: record.mdRuntime === RUNTIME_WIRE_PROTOCOL, message: record.message };
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
+ };
60
74
  }
75
+ export const AUTHORIZATION_ENDED = 'the host authorization ended';
76
+ export const PORT_CLOSED = 'the port closed';
61
77
  function body(message) {
62
78
  if (typeof message !== 'object' || message === null)
63
79
  return null;
@@ -77,7 +93,9 @@ export function request(message) {
77
93
  return { kind: 'stop', id: shape.id };
78
94
  if (!Array.isArray(record.input))
79
95
  return null;
80
- if (shape.kind === 'call' && MEMBERS.includes(record.member)) {
96
+ if (shape.kind === 'call' &&
97
+ typeof record.member === 'string' &&
98
+ Object.hasOwn(MEMBERS, record.member)) {
81
99
  return {
82
100
  kind: 'call',
83
101
  id: shape.id,
@@ -85,7 +103,9 @@ export function request(message) {
85
103
  input: record.input,
86
104
  };
87
105
  }
88
- if (shape.kind === 'observe' && TOPICS.includes(record.topic)) {
106
+ if (shape.kind === 'observe' &&
107
+ typeof record.topic === 'string' &&
108
+ Object.hasOwn(TOPICS, record.topic)) {
89
109
  return {
90
110
  kind: 'observe',
91
111
  id: shape.id,
@@ -111,8 +131,17 @@ export function answer(message) {
111
131
  return { kind: 'result', id: shape.id, value: record.value };
112
132
  if (shape.kind === 'event')
113
133
  return { kind: 'event', id: shape.id, value: record.value };
114
- if (shape.kind === 'failure' && typeof record.message === 'string') {
115
- 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
+ };
116
145
  }
117
146
  return null;
118
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-ce531b51ff088",
3
+ "version": "0.1.0-ce5c5bb29be5a",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,36 +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"
38
+ },
39
+ "./react": {
40
+ "types": "./dist/react.d.ts",
41
+ "default": "./dist/react.js"
42
+ },
43
+ "./digest": {
44
+ "types": "./dist/digest.d.ts",
45
+ "default": "./dist/digest.js"
30
46
  },
31
47
  "./package.json": "./package.json"
32
48
  },
33
49
  "files": [
34
50
  "dist",
35
- "AGENTS.md",
51
+ "!dist/chat.*",
52
+ "!dist/chat/",
36
53
  "README.md",
37
54
  "LICENSE"
38
55
  ],
39
56
  "dependencies": {
40
- "@agentshouse/mdmodel": "0.1.0-ce804f6363a19",
41
- "@tanstack/db": "0.9.2",
42
- "minisearch": "7.2.0"
57
+ "@agentshouse/mdmodel": "0.1.0-c96c61ea31316"
58
+ },
59
+ "peerDependencies": {
60
+ "react": ">=18"
61
+ },
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/agentshouse/core.git",
65
+ "directory": "mdruntime/packages/mdruntime"
43
66
  }
44
67
  }
package/AGENTS.md DELETED
@@ -1,207 +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 and the deployment facts are observations only.
14
-
15
- Every `observe` resolves, once its first value has arrived, to a handle:
16
- `current()` is the latest complete value, `subscribe(listener)` hears each later
17
- value whole and returns its unsubscribe, and `close()` ends the observation.
18
- Closing the port ends every handle and rejects every pending call and
19
- observation; a client that reconnects observes again.
20
-
21
- Each conversation a Provider card names is held complete in the browser.
22
- Observe one with `observe('conversation', id, { limit })`: the view
23
- holds its latest `limit` messages, or all of them, oldest first, its chat
24
- draft, and what the Provider streams for it whether or not anything views it:
25
- the running `turn` with its message parts and its context in use and window, the
26
- open questions, the process state, and the CLI's commands and options. These live
27
- only in memory: the message accepted under the turn's id replaces the running turn,
28
- and none of them is stored or searchable.
29
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
30
- sending it is a Provider Action that needs the Provider reachable and is never
31
- queued.
32
-
33
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
34
- that its Documents link by the Provider's reference, ordered by `reference`,
35
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
36
- `entry`. They are as the Provider last declared them and hold no bytes;
37
- open one through the Provider Action that serves it.
38
-
39
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
40
- touch the network.
41
- History and Call go to the Provider through the Adapter. A Call result whose
42
- effect the Provider places in a Room carries `at`, that Room and Room Version;
43
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
44
- reached it, and the MD Runtime keeps refreshing that Room until it has;
45
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
46
- that document was written at a later Room Version. Each History revision
47
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
48
- member of the
49
- client is asynchronous. Results are detached snapshots. Nothing in this
50
- surface returns the authorization, performs a request the App's code
51
- composes, or exposes the browser store.
52
-
53
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
54
- opaque value using the host's contract.
55
-
56
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
57
- ships in no bundle.
58
-
59
- ## Local Query rules
60
-
61
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
62
- result and hears it again only when it changes, keeping every unchanged Document
63
- the same object, so a component can tell what changed by identity. A query is
64
- data:
65
-
66
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
67
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
68
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
69
- - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
70
- `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
71
- `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
72
- asks whether it contains the value. Missing, null and empty differ:
73
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
74
- text and `$size: 0` an empty list. A date compares in calendar order and never
75
- with a date-time. A reference compares by the Room Path it resolves to.
76
- Untyped frontmatter is plain values. There is no text containment or regular
77
- expression.
78
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
79
- reference `field` points to a matching Document of the same Room.
80
- `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
81
- matching Document of the same Room references. Each keeps a Document once.
82
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
83
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
84
- are `'all'` or a list of names. Room and Path always return; a Markdown
85
- Document also returns its MD Type. A non-Markdown Document or binary link
86
- target returns only Room and Path. An unselected part is absent. Select only
87
- what a screen shows: a list that selects the Markdown hears every edit of it.
88
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
89
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
90
- or `null` for a write the Provider made itself, and `time` is the Provider's
91
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
92
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
93
- saved write takes the Provider's own once it is Accepted and refreshed. A
94
- Room's last change is its Document with the latest `time`.
95
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
96
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
97
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
98
- over every match and ordered by `count` or a key. `limit` bounds the Documents
99
- or the groups.
100
- - **Results and errors.** A result carries no Room Version: read freshness from
101
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
102
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
103
- answers an empty result in its place.
104
-
105
- ## Local Search rules
106
-
107
- `search({ text, documents, conversations, limit })` answers once, by words, from
108
- local state, with MiniSearch at its default configuration. There is no observed
109
- search.
110
-
111
- - **What is found.** A Document by its field values, its sections' headings and
112
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
113
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
114
- word forms, typo tolerance or prefix matching.
115
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
116
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
117
- apply before `limit`, which bounds each list; without it every hit returns.
118
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
119
- hits of one list of one search. A Document hit names its `room`, `path` and
120
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
121
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
122
- `path`, or `text`. A hit carries no position; mark the words in the text you
123
- show. An invalid filter fails with its Local Query error.
124
-
125
- ## Room Draft, Save, and outcome rules
126
-
127
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
128
- tab. It is durable: it survives reload and navigation. A Room that Discovery
129
- stops listing takes its Room Drafts and its queue with it.
130
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
131
- the revision you read, or `null` when there was none, and every part it should
132
- now change: fields, sections and the preamble, or the whole Markdown, a
133
- creation, a move, or a removal. A part new to the Room Draft names its base,
134
- the value you showed when it was opened; the MD Runtime keeps a part's first
135
- base. A binary link target has a Room Draft too, for a move or a removal, with
136
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
137
- the current Room Draft; read it and write again.
138
-
139
- Save takes one Room and the Room Drafts of it to save, each with its revision,
140
- validates locally, and on success appends one Change Batch to that Room's
141
- queue and removes those Room Drafts. It is refused as `stale`, as
142
- `changed-underneath` naming each part whose base no longer matches the visible
143
- state, or by a local validation rule, and then creates nothing and leaves every
144
- Room Draft in place. A directory move or removal is a move or removal part on
145
- each Document and binary link target beneath it, saved together.
146
-
147
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
148
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
149
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
150
- longer applies over the Room each leave the queue and return as Room Drafts on
151
- the Documents they changed, marked with why: the Provider's structured refusal
152
- code and fields as returned, not known to have applied, or withdrawn locally.
153
- The rest of the queue keeps synchronizing, and Sync Status requires attention
154
- until each returned Room Draft is saved again or discarded. A Change Batch
155
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
156
- Pending one, and a returned Room Draft says why it returned. Transport
157
- failure and Provider unavailability keep work Pending and do not infer a
158
- rejection. A refusal the Provider marks retryable stays Pending until the reset
159
- it names; the MD Runtime retries the same Change Batch identity and payload and
160
- never infers an outcome from transport uncertainty. The MD Runtime never
161
- combines, reorders, or rebases.
162
-
163
- `observe('service-mode')` answers the Provider's Service
164
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
165
- its Change Batch waits unsent, and the queue is submitted in order once the
166
- Provider reopens writes. An Action is never held: a write the Provider refuses
167
- for the halt returns that refusal to its caller. Show the Provider as read-only
168
- instead of retrying.
169
-
170
- ## The neutrality rule
171
-
172
- No module outside an Adapter package imports, names, or special-cases a
173
- Provider. MD UI and every App reach data only through the client entry.
174
-
175
- ## Content-safety rules
176
-
177
- The Provider authorization belongs to the Runtime host and is never readable
178
- by the App's code. The App's code reaches the network only at the external
179
- origins its manifest declares, empty by default, and the Provider enforces
180
- that set. Every request to the Provider itself goes through the MD Runtime.
181
- Rendered Markdown never executes scripts, renders raw HTML only for the
182
- details and summary elements, and loads images and other resources only from
183
- origins the Provider's policy allows.
184
-
185
- ## Launch promises MD UI keeps
186
-
187
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
188
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
189
- a desktop. Its strings are English only, dates and numbers follow the
190
- browser locale, and content is never translated. Light and dark themes come
191
- from CSS custom properties with the browser's preference as the default and
192
- an App's override respected. What an App Creator's agent adds carries none
193
- of these promises by itself. Reading, querying and searching never wait for
194
- the network. Data lives only in the App Creator's browser and with the Provider.
195
-
196
- ## App code imports only the client entry and never constructs a Runtime
197
-
198
- App code imports only `@agentshouse/mdruntime/client` and calls
199
- `connectMdRuntime` on the port the host hands it. It never constructs a
200
- Runtime. It does not import the package main, the host entry, or the Adapter
201
- package, and it does not call `serveMdRuntime`. Hosts
202
- and tests use those entries; the served App does not.
203
-
204
- ## What an agent must never do
205
-
206
- An agent must never read the authorization, load code from a Room, call the
207
- 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
- }