@agentshouse/mdruntime 0.1.0-c5f333dfa0583 → 0.1.0-c5fe3b2cddda7

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 (214) hide show
  1. package/README.md +10 -8
  2. package/dist/adapter.d.ts +39 -40
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +2 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +28 -4
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +16 -8
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +142 -94
  13. package/dist/change-set.d.ts +1 -7
  14. package/dist/change-set.d.ts.map +1 -1
  15. package/dist/change-set.js +1 -4
  16. package/dist/client.d.ts +6 -7
  17. package/dist/client.d.ts.map +1 -1
  18. package/dist/client.js +54 -7
  19. package/dist/collection.d.ts +5 -3
  20. package/dist/collection.d.ts.map +1 -1
  21. package/dist/collection.js +24 -19
  22. package/dist/compile.d.ts +6 -1
  23. package/dist/compile.d.ts.map +1 -1
  24. package/dist/compile.js +94 -33
  25. package/dist/connection.d.ts +8 -7
  26. package/dist/connection.d.ts.map +1 -1
  27. package/dist/connection.js +1160 -1151
  28. package/dist/conversation.d.ts +7 -5
  29. package/dist/conversation.d.ts.map +1 -1
  30. package/dist/conversation.js +171 -55
  31. package/dist/durability.d.ts +1 -5
  32. package/dist/durability.d.ts.map +1 -1
  33. package/dist/durability.js +5 -0
  34. package/dist/entry.d.ts +1 -0
  35. package/dist/entry.d.ts.map +1 -1
  36. package/dist/entry.js +1 -1
  37. package/dist/file.d.ts +2 -11
  38. package/dist/file.d.ts.map +1 -1
  39. package/dist/file.js +6 -4
  40. package/dist/fulltext.d.ts +27 -0
  41. package/dist/fulltext.d.ts.map +1 -0
  42. package/dist/fulltext.js +370 -0
  43. package/dist/host.d.ts +3 -4
  44. package/dist/host.d.ts.map +1 -1
  45. package/dist/host.js +42 -18
  46. package/dist/identity.d.ts +0 -1
  47. package/dist/identity.d.ts.map +1 -1
  48. package/dist/identity.js +0 -3
  49. package/dist/index.d.ts +10 -10
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +4 -3
  52. package/dist/live.d.ts.map +1 -1
  53. package/dist/live.js +2 -1
  54. package/dist/media.d.ts +8 -0
  55. package/dist/media.d.ts.map +1 -0
  56. package/dist/media.js +218 -0
  57. package/dist/memory.d.ts +3 -2
  58. package/dist/memory.d.ts.map +1 -1
  59. package/dist/memory.js +93 -38
  60. package/dist/messages.d.ts +28 -0
  61. package/dist/messages.d.ts.map +1 -0
  62. package/dist/messages.js +90 -0
  63. package/dist/model.d.ts +6 -1
  64. package/dist/model.d.ts.map +1 -1
  65. package/dist/model.js +7 -10
  66. package/dist/observation.d.ts +1 -0
  67. package/dist/observation.d.ts.map +1 -1
  68. package/dist/observation.js +1 -1
  69. package/dist/outcome.d.ts +13 -6
  70. package/dist/outcome.d.ts.map +1 -1
  71. package/dist/outcome.js +16 -5
  72. package/dist/overlay.js +1 -1
  73. package/dist/paths.d.ts +1 -0
  74. package/dist/paths.d.ts.map +1 -1
  75. package/dist/paths.js +4 -0
  76. package/dist/query.d.ts +10 -1
  77. package/dist/query.d.ts.map +1 -1
  78. package/dist/query.js +12 -1
  79. package/dist/reach.d.ts +8 -3
  80. package/dist/reach.d.ts.map +1 -1
  81. package/dist/reach.js +69 -46
  82. package/dist/readiness.d.ts +14 -15
  83. package/dist/readiness.d.ts.map +1 -1
  84. package/dist/readiness.js +2 -8
  85. package/dist/recovery.d.ts +1 -0
  86. package/dist/recovery.d.ts.map +1 -1
  87. package/dist/recovery.js +26 -0
  88. package/dist/refresh.d.ts +9 -4
  89. package/dist/refresh.d.ts.map +1 -1
  90. package/dist/refresh.js +64 -30
  91. package/dist/replica.d.ts +5 -5
  92. package/dist/replica.d.ts.map +1 -1
  93. package/dist/replica.js +4 -7
  94. package/dist/room-draft.d.ts +18 -2
  95. package/dist/room-draft.d.ts.map +1 -1
  96. package/dist/room-draft.js +73 -6
  97. package/dist/rows.d.ts +15 -6
  98. package/dist/rows.d.ts.map +1 -1
  99. package/dist/rows.js +102 -74
  100. package/dist/save.d.ts +2 -0
  101. package/dist/save.d.ts.map +1 -1
  102. package/dist/save.js +13 -7
  103. package/dist/search.d.ts +11 -43
  104. package/dist/search.d.ts.map +1 -1
  105. package/dist/search.js +0 -296
  106. package/dist/shared.d.ts +0 -1
  107. package/dist/shared.d.ts.map +1 -1
  108. package/dist/shared.js +0 -10
  109. package/dist/status.d.ts +4 -3
  110. package/dist/status.d.ts.map +1 -1
  111. package/dist/status.js +3 -1
  112. package/dist/store.d.ts +23 -58
  113. package/dist/store.d.ts.map +1 -1
  114. package/dist/store.js +37 -272
  115. package/dist/stored.d.ts +10 -23
  116. package/dist/stored.d.ts.map +1 -1
  117. package/dist/stored.js +217 -218
  118. package/dist/tables.d.ts +51 -46
  119. package/dist/tables.d.ts.map +1 -1
  120. package/dist/tables.js +94 -53
  121. package/dist/transfer.d.ts +0 -5
  122. package/dist/transfer.d.ts.map +1 -1
  123. package/dist/validation.d.ts +3 -4
  124. package/dist/validation.d.ts.map +1 -1
  125. package/dist/validation.js +35 -96
  126. package/dist/wire.d.ts +5 -5
  127. package/dist/wire.d.ts.map +1 -1
  128. package/dist/wire.js +2 -2
  129. package/dist/words.d.ts +19 -0
  130. package/dist/words.d.ts.map +1 -0
  131. package/dist/words.js +156 -0
  132. package/package.json +11 -19
  133. package/AGENTS.md +0 -312
  134. package/dist/chat/acts.d.ts +0 -33
  135. package/dist/chat/acts.d.ts.map +0 -1
  136. package/dist/chat/acts.js +0 -36
  137. package/dist/chat/context.d.ts +0 -3
  138. package/dist/chat/context.d.ts.map +0 -1
  139. package/dist/chat/context.js +0 -10
  140. package/dist/chat/earlier.d.ts +0 -10
  141. package/dist/chat/earlier.d.ts.map +0 -1
  142. package/dist/chat/earlier.js +0 -54
  143. package/dist/chat/house.d.ts +0 -25
  144. package/dist/chat/house.d.ts.map +0 -1
  145. package/dist/chat/house.js +0 -38
  146. package/dist/chat/input.d.ts +0 -11
  147. package/dist/chat/input.d.ts.map +0 -1
  148. package/dist/chat/input.js +0 -92
  149. package/dist/chat/kit.d.ts +0 -61
  150. package/dist/chat/kit.d.ts.map +0 -1
  151. package/dist/chat/kit.js +0 -123
  152. package/dist/chat/lasting.d.ts +0 -6
  153. package/dist/chat/lasting.d.ts.map +0 -1
  154. package/dist/chat/lasting.js +0 -19
  155. package/dist/chat/list.d.ts +0 -28
  156. package/dist/chat/list.d.ts.map +0 -1
  157. package/dist/chat/list.js +0 -103
  158. package/dist/chat/markdown.d.ts +0 -21
  159. package/dist/chat/markdown.d.ts.map +0 -1
  160. package/dist/chat/markdown.js +0 -246
  161. package/dist/chat/message.d.ts +0 -7
  162. package/dist/chat/message.d.ts.map +0 -1
  163. package/dist/chat/message.js +0 -254
  164. package/dist/chat/messages.d.ts +0 -35
  165. package/dist/chat/messages.d.ts.map +0 -1
  166. package/dist/chat/messages.js +0 -210
  167. package/dist/chat/name.d.ts +0 -7
  168. package/dist/chat/name.d.ts.map +0 -1
  169. package/dist/chat/name.js +0 -37
  170. package/dist/chat/opened.d.ts +0 -12
  171. package/dist/chat/opened.d.ts.map +0 -1
  172. package/dist/chat/opened.js +0 -19
  173. package/dist/chat/overlay.d.ts +0 -32
  174. package/dist/chat/overlay.d.ts.map +0 -1
  175. package/dist/chat/overlay.js +0 -103
  176. package/dist/chat/parts.d.ts +0 -58
  177. package/dist/chat/parts.d.ts.map +0 -1
  178. package/dist/chat/parts.js +0 -120
  179. package/dist/chat/pieces.d.ts +0 -62
  180. package/dist/chat/pieces.d.ts.map +0 -1
  181. package/dist/chat/pieces.js +0 -1110
  182. package/dist/chat/process.d.ts +0 -20
  183. package/dist/chat/process.d.ts.map +0 -1
  184. package/dist/chat/process.js +0 -32
  185. package/dist/chat/provider.d.ts +0 -70
  186. package/dist/chat/provider.d.ts.map +0 -1
  187. package/dist/chat/provider.js +0 -635
  188. package/dist/chat/question.d.ts +0 -9
  189. package/dist/chat/question.d.ts.map +0 -1
  190. package/dist/chat/question.js +0 -69
  191. package/dist/chat/questions.d.ts +0 -31
  192. package/dist/chat/questions.d.ts.map +0 -1
  193. package/dist/chat/questions.js +0 -111
  194. package/dist/chat/read.d.ts +0 -5
  195. package/dist/chat/read.d.ts.map +0 -1
  196. package/dist/chat/read.js +0 -13
  197. package/dist/chat/ready.d.ts +0 -37
  198. package/dist/chat/ready.d.ts.map +0 -1
  199. package/dist/chat/ready.js +0 -93
  200. package/dist/chat/room-file.d.ts +0 -8
  201. package/dist/chat/room-file.d.ts.map +0 -1
  202. package/dist/chat/room-file.js +0 -72
  203. package/dist/chat/steady.d.ts +0 -3
  204. package/dist/chat/steady.d.ts.map +0 -1
  205. package/dist/chat/steady.js +0 -26
  206. package/dist/chat/style.d.ts +0 -4
  207. package/dist/chat/style.d.ts.map +0 -1
  208. package/dist/chat/style.js +0 -307
  209. package/dist/chat.d.ts +0 -15
  210. package/dist/chat.d.ts.map +0 -1
  211. package/dist/chat.js +0 -8
  212. package/dist/reads.d.ts +0 -11
  213. package/dist/reads.d.ts.map +0 -1
  214. package/dist/reads.js +0 -98
@@ -0,0 +1,27 @@
1
+ import { type QueryRoom } from './compile.js';
2
+ import type { Plan } from './query.js';
3
+ import type { HitCursor, SearchWindow } from './search.js';
4
+ import type { Connection } from './tables.js';
5
+ export declare const SEARCH_TABLES: readonly string[];
6
+ export type SearchAsk = {
7
+ readonly text: string;
8
+ readonly limit: number;
9
+ readonly after: readonly [HitCursor, HitCursor] | null;
10
+ readonly total: boolean;
11
+ readonly documents: {
12
+ readonly plan: Plan;
13
+ readonly rooms: readonly QueryRoom[];
14
+ readonly beneath: readonly {
15
+ readonly key: number;
16
+ readonly roots: readonly string[];
17
+ }[];
18
+ } | null;
19
+ readonly conversations: readonly string[];
20
+ };
21
+ export declare function indexDocument(connection: Connection, id: number, path: string, content: string): void;
22
+ export declare function indexMessage(connection: Connection, id: number, text: string): void;
23
+ export declare function unindexDocuments(connection: Connection, ids: Iterable<number>): void;
24
+ export declare function unindexMessages(connection: Connection, ids: Iterable<number>): void;
25
+ export declare function unindexAll(connection: Connection): void;
26
+ export declare function searched(connection: Connection, ask: SearchAsk): SearchWindow;
27
+ //# sourceMappingURL=fulltext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fulltext.d.ts","sourceRoot":"","sources":["../src/fulltext.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAGV,SAAS,EAET,YAAY,EAEb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,aAAa,CAAC;AAoBrD,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAG1C,CAAC;AAsCF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;QACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,OAAO,EAAE,SAAS;YAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;SAAE,EAAE,CAAC;KAC1F,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AA2CF,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,IAAI,CAgBN;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAOnF;AAWD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAEpF;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAEnF;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAIvD;AAkTD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,GAAG,YAAY,CAsB7E"}
@@ -0,0 +1,370 @@
1
+ import { parse } from '@agentshouse/mdmodel';
2
+ import { selected } from './compile.js';
3
+ import { markdownPath } from './rows.js';
4
+ import { indexed, matchClauses, matched, matchExpression, queryTerms, snippet, } from './words.js';
5
+ const TOKENIZER = "porter unicode61 remove_diacritics 2 categories 'L* N* Co M* S*' separators '$+<=>^`|~'";
6
+ const CONTENTLESS = `content='', contentless_delete=1, detail=full, tokenize="${TOKENIZER}"`;
7
+ const DOCUMENTS = 'replica_search';
8
+ const MESSAGES = 'conversation_search';
9
+ export const SEARCH_TABLES = [
10
+ `CREATE VIRTUAL TABLE ${DOCUMENTS} USING fts5(path, fields, sections, preamble, ${CONTENTLESS})`,
11
+ `CREATE VIRTUAL TABLE ${MESSAGES} USING fts5(text, ${CONTENTLESS})`,
12
+ ];
13
+ const CHUNKS = 4096;
14
+ const CHUNK_CHARACTERS = 32_768;
15
+ const CANDIDATES = 5_000;
16
+ const LEAST_WINDOW = 32;
17
+ const SNIPPET_REACH = 80;
18
+ function scalars(value) {
19
+ if (value === null || value === undefined)
20
+ return [];
21
+ if (Array.isArray(value))
22
+ return value.flatMap(scalars);
23
+ if (typeof value === 'object')
24
+ return Object.values(value).flatMap(scalars);
25
+ return [String(value)];
26
+ }
27
+ function partsOf(path, content) {
28
+ if (!markdownPath(path))
29
+ return null;
30
+ const read = parse(content, path);
31
+ if (!read.ok)
32
+ return null;
33
+ return {
34
+ fields: scalars(read.document.fields).join('\n'),
35
+ sections: Object.entries(read.document.sections)
36
+ .map(([heading, text]) => `${heading}\n${text}`)
37
+ .join('\n'),
38
+ preamble: read.document.preamble,
39
+ path,
40
+ };
41
+ }
42
+ function chunked(text) {
43
+ const chunks = [];
44
+ let start = 0;
45
+ do {
46
+ let end = Math.min(text.length, start + CHUNK_CHARACTERS);
47
+ if (end < text.length) {
48
+ const space = text.lastIndexOf(' ', end);
49
+ if (space > start + CHUNK_CHARACTERS / 2)
50
+ end = space;
51
+ else if (/[\ud800-\udbff]/u.test(text[end - 1]))
52
+ end -= 1;
53
+ }
54
+ chunks.push(text.slice(start, end));
55
+ start = end;
56
+ } while (start < text.length && chunks.length < CHUNKS);
57
+ return chunks;
58
+ }
59
+ function rowOf(id, chunk) {
60
+ return id * CHUNKS + chunk;
61
+ }
62
+ export function indexDocument(connection, id, path, content) {
63
+ const parts = partsOf(path, content);
64
+ if (parts === null)
65
+ return;
66
+ chunked(parts.sections).forEach((sections, chunk) => {
67
+ const head = chunk === 0;
68
+ connection.run(`INSERT INTO ${DOCUMENTS} (rowid, path, fields, sections, preamble) VALUES (?, ?, ?, ?, ?)`, [
69
+ rowOf(id, chunk),
70
+ head ? indexed(parts.path) : null,
71
+ head ? indexed(parts.fields) : null,
72
+ indexed(sections),
73
+ head ? indexed(parts.preamble) : null,
74
+ ]);
75
+ });
76
+ }
77
+ export function indexMessage(connection, id, text) {
78
+ chunked(text).forEach((chunk, at) => {
79
+ connection.run(`INSERT INTO ${MESSAGES} (rowid, text) VALUES (?, ?)`, [
80
+ rowOf(id, at),
81
+ indexed(chunk),
82
+ ]);
83
+ });
84
+ }
85
+ function unindexed(connection, table, ids) {
86
+ for (const id of ids) {
87
+ connection.run(`DELETE FROM ${table} WHERE rowid >= ? AND rowid < ?`, [
88
+ rowOf(id, 0),
89
+ rowOf(id + 1, 0),
90
+ ]);
91
+ }
92
+ }
93
+ export function unindexDocuments(connection, ids) {
94
+ unindexed(connection, DOCUMENTS, ids);
95
+ }
96
+ export function unindexMessages(connection, ids) {
97
+ unindexed(connection, MESSAGES, ids);
98
+ }
99
+ export function unindexAll(connection) {
100
+ for (const table of [DOCUMENTS, MESSAGES]) {
101
+ connection.run(`INSERT INTO ${table} (${table}) VALUES ('delete-all')`);
102
+ }
103
+ }
104
+ function pair(left, right) {
105
+ if (left[0] !== right[0])
106
+ return left[0] < right[0] ? -1 : 1;
107
+ if (left[1] !== right[1])
108
+ return left[1] < right[1] ? -1 : 1;
109
+ return 0;
110
+ }
111
+ function byRank(left, right) {
112
+ return right.score - left.score || pair(left.tie, right.tie);
113
+ }
114
+ function beyond(hit, cursor) {
115
+ if (cursor.length === 0)
116
+ return true;
117
+ return (hit.score < cursor[0] || (hit.score === cursor[0] && pair(hit.tie, [cursor[1], cursor[2]]) > 0));
118
+ }
119
+ function rankedWithin(connection, listed, sources, cursor, needed) {
120
+ const { table } = listed;
121
+ let window = Math.max(needed * 2, LEAST_WINDOW);
122
+ for (;;) {
123
+ const rows = [];
124
+ const boundaries = [];
125
+ for (const source of sources) {
126
+ const found = connection.rows(`SELECT rowid, bm25(${table}) AS score FROM ${table} WHERE ${table} MATCH ? ${source.sql} ORDER BY score, rowid LIMIT ?`, [source.expression, ...source.bind, window]);
127
+ for (const row of found)
128
+ rows.push([Number(row.rowid), Number(row.score)]);
129
+ if (found.length === window)
130
+ boundaries.push(-Number(found.at(-1).score));
131
+ }
132
+ rows.sort((left, right) => left[1] - right[1] || left[0] - right[0]);
133
+ const best = new Map();
134
+ for (const [row, score] of rows) {
135
+ const id = Math.floor(row / CHUNKS);
136
+ if (!best.has(id))
137
+ best.set(id, { chunk: row % CHUNKS, score: -score });
138
+ }
139
+ const ties = listed.ties([...best.keys()]);
140
+ const kept = [...best]
141
+ .flatMap(([id, held]) => {
142
+ const tie = ties.get(id);
143
+ return tie === undefined ? [] : [{ id, ...held, tie }];
144
+ })
145
+ .sort(byRank)
146
+ .filter((hit) => beyond(hit, cursor))
147
+ .slice(0, needed);
148
+ const last = kept.at(-1);
149
+ if (boundaries.length === 0)
150
+ return kept;
151
+ if (kept.length === needed &&
152
+ last !== undefined &&
153
+ boundaries.every((boundary) => boundary < last.score)) {
154
+ return kept;
155
+ }
156
+ window *= 4;
157
+ }
158
+ }
159
+ function reaches(connection, listed, expression, reach) {
160
+ const { table, scope } = listed;
161
+ const [counted] = connection.rows(`SELECT count(*) AS held FROM (SELECT rowid FROM ${table} WHERE ${table} MATCH ? AND ${scope.sql} LIMIT ?)`, [expression, ...scope.bind, reach + 1]);
162
+ return Number(counted?.held ?? 0) > reach;
163
+ }
164
+ function candidates(connection, listed, clauses, cursor, needed) {
165
+ const { table, scope } = listed;
166
+ const expression = matchExpression(clauses);
167
+ const within = { sql: `AND ${scope.sql}`, bind: scope.bind };
168
+ let reach = CANDIDATES;
169
+ for (;;) {
170
+ const [edge] = connection.rows(`SELECT rowid FROM ${table} WHERE ${table} MATCH ? ${within.sql} ORDER BY rowid LIMIT 1 OFFSET ?`, [expression, ...within.bind, reach]);
171
+ const floor = edge === undefined ? null : Number(edge.rowid);
172
+ const sources = [
173
+ floor === null
174
+ ? { expression, ...within }
175
+ : { expression, sql: `${within.sql} AND rowid < ?`, bind: [...within.bind, floor] },
176
+ ];
177
+ if (floor !== null) {
178
+ const common = new Set();
179
+ const selective = [];
180
+ const frequent = [];
181
+ for (const clause of clauses) {
182
+ if (clause.kind === 'phrase')
183
+ continue;
184
+ if (clause.kind !== 'term' && common.has(clause.term)) {
185
+ frequent.push(clause);
186
+ continue;
187
+ }
188
+ if (reaches(connection, listed, clause.text, reach)) {
189
+ if (clause.kind === 'term')
190
+ common.add(clause.term);
191
+ frequent.push(clause);
192
+ }
193
+ else
194
+ selective.push(clause);
195
+ }
196
+ const phrase = clauses.find((clause) => clause.kind === 'phrase');
197
+ if (phrase !== undefined) {
198
+ const rare = !clauses
199
+ .filter((clause) => clause.kind === 'term')
200
+ .every((clause) => common.has(clause.term)) ||
201
+ !reaches(connection, listed, phrase.text, reach);
202
+ (rare ? selective : frequent).push(phrase);
203
+ }
204
+ if (selective.length > 0) {
205
+ const chosen = `(${matchExpression(selective)})`;
206
+ const tail = { sql: `${within.sql} AND rowid >= ?`, bind: [...within.bind, floor] };
207
+ if (frequent.length === 0)
208
+ sources.push({ ...tail, expression: chosen });
209
+ else {
210
+ const rest = `(${matchExpression(frequent)})`;
211
+ sources.push({ ...tail, expression: `${chosen} AND ${rest}` }, { ...tail, expression: `${chosen} NOT ${rest}` });
212
+ }
213
+ }
214
+ }
215
+ const kept = rankedWithin(connection, listed, sources, cursor, needed);
216
+ if (floor === null || kept.length >= needed)
217
+ return kept;
218
+ reach *= 4;
219
+ }
220
+ }
221
+ function windowOf(connection, listed, clauses, cursor, limit) {
222
+ if (cursor === null || listed === null || clauses === null)
223
+ return { kept: [], cursor: null };
224
+ const found = candidates(connection, listed, clauses, cursor, limit + 1);
225
+ if (found.length <= limit)
226
+ return { kept: found, cursor: null };
227
+ const kept = found.slice(0, limit);
228
+ const last = kept.at(-1);
229
+ return { kept, cursor: last === undefined ? cursor : [last.score, ...last.tie] };
230
+ }
231
+ function totalOf(connection, listed, clauses) {
232
+ if (listed === null || clauses === null)
233
+ return 0;
234
+ const { table, scope } = listed;
235
+ const [counted] = connection.rows(`SELECT count(DISTINCT rowid / ${CHUNKS}) AS held FROM ${table} WHERE ${table} MATCH ? AND ${scope.sql}`, [matchExpression(clauses), ...scope.bind]);
236
+ return Number(counted?.held ?? 0);
237
+ }
238
+ function ids(found) {
239
+ return JSON.stringify(found);
240
+ }
241
+ function documentsListed(connection, documents) {
242
+ if (documents.rooms.length === 0)
243
+ return null;
244
+ const filter = selected(connection, documents.plan, documents.rooms);
245
+ const outside = {
246
+ sql: "NOT EXISTS (SELECT 1 FROM json_each(?) r WHERE d.key = r.value ->> 0 AND (d.path = r.value ->> 1 OR (d.path >= (r.value ->> 1) || '/' AND d.path < (r.value ->> 1) || '0')))",
247
+ bind: [
248
+ JSON.stringify(documents.beneath.flatMap(({ key, roots }) => roots.map((root) => [key, root]))),
249
+ ],
250
+ };
251
+ const conditions = [filter, outside];
252
+ const locators = new Map(documents.rooms.map(({ key, locator }) => [key, locator]));
253
+ return {
254
+ table: DOCUMENTS,
255
+ scope: {
256
+ sql: `EXISTS (SELECT 1 FROM replica_entries d WHERE d.id = ${DOCUMENTS}.rowid / ${CHUNKS} AND d.type IS NOT NULL AND ${conditions.map(({ sql }) => `(${sql})`).join(' AND ')})`,
257
+ bind: conditions.flatMap(({ bind }) => bind),
258
+ },
259
+ ties(found) {
260
+ const tied = new Map();
261
+ for (const row of connection.rows('SELECT id, key, path FROM replica_entries WHERE id IN (SELECT value FROM json_each(?))', [ids(found)])) {
262
+ const locator = locators.get(Number(row.key));
263
+ if (locator !== undefined)
264
+ tied.set(Number(row.id), [locator, String(row.path)]);
265
+ }
266
+ return tied;
267
+ },
268
+ };
269
+ }
270
+ function messagesListed(connection, conversations) {
271
+ if (conversations.length === 0)
272
+ return null;
273
+ return {
274
+ table: MESSAGES,
275
+ scope: {
276
+ sql: `EXISTS (SELECT 1 FROM conversation_messages m WHERE m.id = ${MESSAGES}.rowid / ${CHUNKS} AND m.conversation IN (SELECT value FROM json_each(?)))`,
277
+ bind: [JSON.stringify(conversations)],
278
+ },
279
+ ties(found) {
280
+ return new Map(connection
281
+ .rows('SELECT id, conversation, identity FROM conversation_messages WHERE id IN (SELECT value FROM json_each(?))', [ids(found)])
282
+ .map((row) => [Number(row.id), [String(row.conversation), String(row.identity)]]));
283
+ },
284
+ };
285
+ }
286
+ function cut(candidates, terms) {
287
+ for (const [part, text] of candidates) {
288
+ const found = snippet(text, terms, SNIPPET_REACH);
289
+ if (found !== null)
290
+ return { snippet: { part, text: found.text, at: [...found.at] } };
291
+ }
292
+ return {};
293
+ }
294
+ function documentHit(connection, hit, terms) {
295
+ const [row] = connection.rows('SELECT type, content FROM replica_entries WHERE id = ?', [hit.id]);
296
+ if (row === undefined)
297
+ return null;
298
+ const [room, path] = hit.tie;
299
+ const parts = typeof row.content === 'string' ? partsOf(path, row.content) : null;
300
+ const whole = parts === null
301
+ ? []
302
+ : [
303
+ ['fields', parts.fields],
304
+ ['sections', parts.sections],
305
+ ['preamble', parts.preamble],
306
+ ['path', parts.path],
307
+ ];
308
+ const matches = {};
309
+ for (const [part, text] of whole) {
310
+ for (const term of matched(text, terms))
311
+ (matches[term] ??= []).push(part);
312
+ }
313
+ const sections = parts === null ? [] : chunked(parts.sections);
314
+ const chunk = parts === null
315
+ ? []
316
+ : hit.chunk === 0
317
+ ? [
318
+ ['fields', parts.fields],
319
+ ['sections', sections[0] ?? ''],
320
+ ['preamble', parts.preamble],
321
+ ['path', parts.path],
322
+ ]
323
+ : [['sections', sections[hit.chunk] ?? '']];
324
+ return {
325
+ room,
326
+ path,
327
+ type: String(row.type),
328
+ score: hit.score,
329
+ matches,
330
+ ...cut(chunk, terms),
331
+ };
332
+ }
333
+ function messageHit(connection, hit, terms) {
334
+ const [row] = connection.rows('SELECT text FROM conversation_messages WHERE id = ?', [hit.id]);
335
+ const text = typeof row?.text === 'string' ? row.text : '';
336
+ const matches = {};
337
+ for (const term of matched(text, terms))
338
+ matches[term] = ['text'];
339
+ const [conversation, identity] = hit.tie;
340
+ return {
341
+ conversation,
342
+ identity,
343
+ score: hit.score,
344
+ matches,
345
+ ...cut([['text', chunked(text)[hit.chunk] ?? '']], terms),
346
+ };
347
+ }
348
+ export function searched(connection, ask) {
349
+ const clauses = matchClauses(ask.text);
350
+ const terms = queryTerms(ask.text);
351
+ const documents = ask.documents === null ? null : documentsListed(connection, ask.documents);
352
+ const messages = messagesListed(connection, ask.conversations);
353
+ const [documentsAfter, messagesAfter] = ask.after ?? [[], []];
354
+ const documentWindow = windowOf(connection, documents, clauses, documentsAfter, ask.limit);
355
+ const messageWindow = windowOf(connection, messages, clauses, messagesAfter, ask.limit);
356
+ const more = documentWindow.cursor !== null || messageWindow.cursor !== null;
357
+ return {
358
+ documents: documentWindow.kept.flatMap((hit) => documentHit(connection, hit, terms) ?? []),
359
+ messages: messageWindow.kept.map((hit) => messageHit(connection, hit, terms)),
360
+ ...(more ? { next: JSON.stringify([documentWindow.cursor, messageWindow.cursor]) } : {}),
361
+ ...(ask.total
362
+ ? {
363
+ total: {
364
+ documents: totalOf(connection, documents, clauses),
365
+ messages: totalOf(connection, messages, clauses),
366
+ },
367
+ }
368
+ : {}),
369
+ };
370
+ }
package/dist/host.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type MdRuntimeOptions } from './connection.js';
2
2
  import type { PortReach } from './reach.js';
3
- import type { CapacityCause, CodeAvailability, Persistence, Readiness, SearchObligation } from './readiness.js';
3
+ import type { CodeAvailability, Persistence, Readiness, SearchObligation, Space } from './readiness.js';
4
4
  import type { EntrySeed } from './seed.js';
5
5
  import { type RuntimePort } from './wire.js';
6
6
  export type MdRuntimeHostOptions = MdRuntimeOptions & {
@@ -11,7 +11,7 @@ export type AttachedPort = {
11
11
  narrow(reach: PortReach): void;
12
12
  readiness(deliver: (readiness: Readiness) => void): () => void;
13
13
  answered(queries: readonly unknown[], done: () => void): void;
14
- code(code: CodeAvailability, capacity: CapacityCause | null): void;
14
+ code(code: CodeAvailability, space: Space | null): void;
15
15
  search(search: SearchObligation): void;
16
16
  };
17
17
  export type MdRuntimeHost = {
@@ -25,8 +25,7 @@ export type MdRuntimeHost = {
25
25
  export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
26
26
  export { entrySeedOf, type EntrySeed } from './seed.js';
27
27
  export type { PortReach, ReachedDocument } from './reach.js';
28
- export type { CapacityCause, CodeAvailability, Persistence, SearchObligation, } from './readiness.js';
28
+ export type { CodeAvailability, Persistence, SearchObligation, Space } from './readiness.js';
29
29
  export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
30
- export { openDatabase, STORE_SCHEMA, transacted } from './store.js';
31
30
  export type { RuntimePort } from './wire.js';
32
31
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EAItB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAGL,KAAK,WAAW,EAOjB,MAAM,WAAW,CAAC;AAInB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC9D,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;IACnE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CACJ,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,gBAAgB,EACvB,MAAM,CAAC,EAAE,gBAAgB,GACxB,YAAY,CAAC;IAChB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAyHF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAsK3E;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,gBAAgB,EAItB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,KAAK,EACN,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAGL,KAAK,WAAW,EAOjB,MAAM,WAAW,CAAC;AAInB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC9D,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IACxD,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CACJ,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,gBAAgB,EACvB,MAAM,CAAC,EAAE,gBAAgB,GACxB,YAAY,CAAC;IAChB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAsIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAuL3E;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/host.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { composeRuntime, } from './connection.js';
2
2
  import { queryKey } from './query.js';
3
+ import { untilAnswered } from './recovery.js';
3
4
  import { described } from './failure.js';
4
- import { endRuntimeStore } from './store.js';
5
5
  import { AUTHORIZATION_ENDED, request, WIRE, } from './wire.js';
6
6
  const NARROWED = new Set(['within', 'whole']);
7
7
  function answered(md, app, writtenBy, member, input) {
@@ -26,8 +26,10 @@ function answered(md, app, writtenBy, member, input) {
26
26
  return md.binaryFile.read(input[0], input[1], input[2]);
27
27
  case 'binaryFile.link':
28
28
  return md.binaryFile.link(input[0], input[1], input[2]);
29
- case 'binaryFile.readReference':
30
- return md.binaryFile.readReference(input[0]);
29
+ case 'binaryFile.show':
30
+ return md.binaryFile.show(input[0], input[1], input[2]);
31
+ case 'binaryFile.attach':
32
+ return md.binaryFile.attach(input[0], input[1]);
31
33
  case 'binaryFile.part':
32
34
  return md.binaryFile.part(input[0], input[1]);
33
35
  case 'call':
@@ -49,7 +51,7 @@ function answered(md, app, writtenBy, member, input) {
49
51
  case 'roomDraft.read':
50
52
  return md.roomDraft.read(input[0], input[1]);
51
53
  case 'roomDraft.write':
52
- return md.roomDraft.write(input[0], input[1], input[2], input[3]);
54
+ return md.roomDraft.write(input[0], input[1], input[2], input[3], input[4]);
53
55
  case 'roomDraft.discard':
54
56
  return md.roomDraft.discard(input[0], input[1], input[2]);
55
57
  case 'presentation.read':
@@ -66,8 +68,6 @@ function answered(md, app, writtenBy, member, input) {
66
68
  return md.conversation.create(input[0]);
67
69
  case 'conversation.send':
68
70
  return md.conversation.send(input[0], input[1], input[2]);
69
- case 'conversation.attach':
70
- return md.conversation.attach(input[0], input[1]);
71
71
  case 'conversation.answer':
72
72
  return md.conversation.answer(input[0], input[1]);
73
73
  case 'conversation.interrupt':
@@ -86,6 +86,14 @@ function answered(md, app, writtenBy, member, input) {
86
86
  return md.chatDraft.discard(input[0]);
87
87
  }
88
88
  }
89
+ function attempted(work) {
90
+ try {
91
+ return Promise.resolve(work());
92
+ }
93
+ catch (error) {
94
+ return Promise.reject(error);
95
+ }
96
+ }
89
97
  function answeredResult(value) {
90
98
  return typeof value === 'object' && value !== null && !('pending' in value);
91
99
  }
@@ -107,6 +115,8 @@ export function serveMdRuntime(options) {
107
115
  const { md } = runtime;
108
116
  const attachments = new Map();
109
117
  let authorized = true;
118
+ let opening = null;
119
+ const opened = () => (opening ??= untilAnswered(() => md.loaded(), closing.signal));
110
120
  const watchFacts = (deliver) => {
111
121
  deliver(structuredClone(deploymentFacts));
112
122
  return () => { };
@@ -115,7 +125,7 @@ export function serveMdRuntime(options) {
115
125
  if (!authorized)
116
126
  throw new Error(AUTHORIZATION_ENDED);
117
127
  const writtenBy = release === undefined ? undefined : { app, release };
118
- let facts = { target: app, code, capacity: null, search };
128
+ let facts = { target: app, code, space: null, search };
119
129
  const view = runtime.within(reach ?? null, facts);
120
130
  const observations = new Map();
121
131
  const followed = new Set();
@@ -158,6 +168,20 @@ export function serveMdRuntime(options) {
158
168
  ? watchFacts(deliver)
159
169
  : (NARROWED.has(WIRE.topics[topic]) ? view : runtime).watch(topic, topic === 'presentation' ? [app] : input, deliver));
160
170
  };
171
+ const reply = async (id, query, pending) => {
172
+ try {
173
+ const value = await pending;
174
+ if (!serving)
175
+ return;
176
+ send({ kind: 'result', id, value });
177
+ if (query !== undefined && answeredResult(value))
178
+ answeredQuery(query);
179
+ }
180
+ catch (error) {
181
+ if (serving)
182
+ send({ kind: 'failure', id, ...described(error) });
183
+ }
184
+ };
161
185
  const serve = async (message) => {
162
186
  if (message.kind === 'hello')
163
187
  return;
@@ -167,24 +191,24 @@ export function serveMdRuntime(options) {
167
191
  return;
168
192
  }
169
193
  try {
170
- if (message.kind !== 'observe' || message.topic !== 'room-drafts')
194
+ if (message.kind !== 'observe')
171
195
  await md.loaded();
196
+ else if (message.topic !== 'room-drafts')
197
+ await opened();
172
198
  if (message.kind === 'observe') {
173
199
  if (serving)
174
200
  observe(message.id, message.topic, message.input);
175
201
  return;
176
202
  }
177
- const value = await answered(NARROWED.has(WIRE.members[message.member].reach) ? view.md : md, app, writtenBy, message.member, message.input);
178
- if (!serving)
179
- return;
180
- send({ kind: 'result', id: message.id, value });
181
- if (message.member === 'query' && answeredResult(value))
182
- answeredQuery(message.input[0]);
183
203
  }
184
204
  catch (error) {
185
205
  if (serving)
186
206
  send({ kind: 'failure', id: message.id, ...described(error) });
207
+ return;
187
208
  }
209
+ const { id, member, input } = message;
210
+ const pending = attempted(() => answered(NARROWED.has(WIRE.members[member].reach) ? view.md : md, app, writtenBy, member, input));
211
+ return reply(id, member === 'query' ? input[0] : undefined, pending);
188
212
  };
189
213
  port.addEventListener('message', (event) => {
190
214
  if (!serving)
@@ -203,10 +227,10 @@ export function serveMdRuntime(options) {
203
227
  if (serving)
204
228
  view.narrow(next);
205
229
  },
206
- code(next, capacity) {
230
+ code(next, space) {
207
231
  if (!serving)
208
232
  return;
209
- facts = { ...facts, code: next, capacity };
233
+ facts = { ...facts, code: next, space };
210
234
  view.facts(facts);
211
235
  },
212
236
  search(next) {
@@ -253,8 +277,9 @@ export function serveMdRuntime(options) {
253
277
  detach();
254
278
  }
255
279
  close();
256
- if (!(await endRuntimeStore(options.database, holder)))
280
+ if (!(await options.database.ask({ kind: 'authored.end', holder: holder ?? null }))) {
257
281
  await options.shell.dropGeneration();
282
+ }
258
283
  },
259
284
  lose(locators) {
260
285
  return runtime.lose(locators);
@@ -266,4 +291,3 @@ export function serveMdRuntime(options) {
266
291
  }
267
292
  export { entrySeedOf } from './seed.js';
268
293
  export { createRecovery, retryDelay, } from './recovery.js';
269
- export { openDatabase, STORE_SCHEMA, transacted } from './store.js';
@@ -3,6 +3,5 @@ export declare function identityTime(identity: string): number;
3
3
  export declare function roomDraftRevision(): string;
4
4
  export declare function chatDraftRevision(): string;
5
5
  export declare function transferIdentity(): string;
6
- export declare function indexGeneration(): string;
7
6
  export declare function binaryLocalId(): string;
8
7
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
package/dist/identity.js CHANGED
@@ -27,9 +27,6 @@ export function chatDraftRevision() {
27
27
  export function transferIdentity() {
28
28
  return randomIdentity();
29
29
  }
30
- export function indexGeneration() {
31
- return randomIdentity();
32
- }
33
30
  export function binaryLocalId() {
34
31
  return randomIdentity();
35
32
  }
package/dist/index.d.ts CHANGED
@@ -1,26 +1,26 @@
1
- export type { AcceptedMessage, AcceptedRoom, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BinaryFile, BinaryLinkResult, BinaryRequest, BinaryResult, ReferrerScope, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction, ConversationAgents, ConversationEvent, ConversationHistories, ConversationHistoryPage, ConversationHistoryRequest, ConversationMessage, ConversationStream, DiscoverResult, DiscoveredRoom, Discovery, DiscoveryScope, HistoryAuthor, HistoryRequest, HistoryResult, HistoryRetention, HistoryRevision, HeldContent, HeldFile, HeldRevisions, HeldRoom, KeptReceipt, ListedConversation, MdModelIdentity, Member, MutationRequest, MutationResult, PageToken, ProviderLimit, ProviderRefusal, RefreshPage, RefreshRequest, RefreshResult, Retention, RetryableRefusal, RevokedAuthorization, RoomModels, RoomNotReadable, RoomStream, RoomStreamEvent, RoomVersionAt, ServiceMode, ServiceModeSignal, StreamReceipts, TransportUncertainty, TurnContext, TurnOperation, TypedSelection, } from './adapter.js';
1
+ export type { AcceptedMessage, AcceptedRoom, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, AttachRequest, AttachResult, Authorization, BinaryFile, BinaryLinkResult, BinaryRequest, BinaryResult, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction, ConversationAgents, ConversationEvent, ConversationHistories, ConversationHistoryPage, ConversationHistoryRequest, ConversationMessage, ConversationStream, DiscoverResult, DiscoveredRoom, Discovery, DiscoveryScope, HistoryAuthor, HistoryRequest, HistoryResult, HistoryRetention, HistoryRevision, HeldContent, HeldFile, HeldRoom, ListedConversation, MdModelIdentity, Member, MutationRequest, MutationResult, PageToken, ProviderLimit, ProviderRefusal, RefreshPage, RefreshRequest, RefreshResult, Retention, RetryableRefusal, RevokedAuthorization, RoomChange, RoomModels, RoomNotReadable, RoomStream, RoomStreamEvent, RoomVersionAt, ServiceMode, ServiceModeSignal, TransportUncertainty, TurnContext, TurnOperation, TypedSelection, } from './adapter.js';
2
2
  export type { Change, ChangeBatch, Precondition, RoomMove, WrittenBy } from './change.js';
3
3
  export type { ChatDraft, ChatDraftSurface, ConversationAgent, ConversationEntry, ConversationOptions, ConversationState, ConversationSurface, ConversationView, RunningTurn, } from './conversation.js';
4
- export type { ChosenFile, FileDeclaration } from './file.js';
5
4
  export type { AppRoom, AppTypedSelection, BinaryFileSurface, ConnectionRefusal, ConnectionRefusalCode, HistoryQuery, MdRuntime, MdRuntimeOptions, PresentationSurface, RoomDraftSurface, RoomSchemas, SavedParts, SavedRoomDraft, SaveResult, } from './connection.js';
6
5
  export type { Observation } from './observation.js';
7
- export type { BinaryAnswer, BinaryLinkAnswer, CallResult, Failure, HistoryAnswer, Offline, QueueEntry, Resolution, Submission, } from './outcome.js';
8
- export type { BinaryFileRecord, BinaryReference } from './binary.js';
6
+ export type { AttachAnswer, BinaryAnswer, BinaryLinkAnswer, CallResult, DownloadAnswer, Failure, HistoryAnswer, Offline, QueueEntry, Resolution, Submission, } from './outcome.js';
7
+ export type { BinaryFileRecord } from './binary.js';
9
8
  export type { RuntimeError } from './failure.js';
10
9
  export type { ChangedPart, FieldValue, ReturnReason, RoomDraft, RoomDraftCreation, RoomDraftParts, RoomDraftWrite, TextParts, } from './room-draft.js';
11
10
  export type { SaveRefusal } from './save.js';
12
- export type { DocumentHit, DocumentPart, MessageHit, PendingConversation, SearchCoverage, SearchHits, SearchPending, SearchRequest, SearchResult, SearchUndeclared, } from './search.js';
11
+ export type { DocumentHit, DocumentPart, MessageHit, MessagePart, SearchCoverage, SearchHits, SearchPending, SearchRequest, SearchResult, SearchUndeclared, Snippet, } from './search.js';
13
12
  export { departure } from './change.js';
14
- export { partsAfter } from './room-draft.js';
13
+ export { partsAfter, partsChanges } from './room-draft.js';
15
14
  export { cutName, nameFrom, transliterated } from './name.js';
16
- export { SESSION_STARTED } from './conversation.js';
15
+ export { HISTORY_CONVERSATIONS, SESSION_STARTED } from './conversation.js';
17
16
  export { changeBatchIdentity } from './identity.js';
18
- export { ROW_WEIGHT, stepped } from './turn.js';
17
+ export { paced, ROW_WEIGHT, stepped } from './turn.js';
18
+ export { untilAnswered } from './recovery.js';
19
19
  export { entriesIn, patching, sortedKeys } from './shared.js';
20
20
  export { attempts, identities, intentOf, type Answered, type Attempt, type Attempts, type Identities, } from './attempt.js';
21
21
  export { expectedList, expecting, type ExpectedOf, type Expecting } from './expectation.js';
22
- export type { RuntimeShell, StorageEstimate } from './durability.js';
23
- export type { CapacityCause, CodeAvailability, ConnectionAvailability, ConversationCoverage, Durability, HouseOutcome, Persistence, Readiness, ReadinessStatus, RefusedRoom, RoomCoverage, RoomPreparation, SearchObligation, TargetCoverage, } from './readiness.js';
22
+ export type { RuntimeShell } from './durability.js';
23
+ export type { CodeAvailability, ConnectionAvailability, ConversationCoverage, Durability, HouseOutcome, Installation, InstallationAmount, InstallationStep, Persistence, Readiness, ReadinessStatus, RoomCoverage, RoomPreparation, SearchObligation, Space, TargetCoverage, } from './readiness.js';
24
24
  export type { AttentionEntry, SyncStatus } from './status.js';
25
25
  export type { Awaits, Backlink, CoveredRoom, Direction, DocumentQuery, DocumentResult, Filter, GroupQuery, GroupResult, Key, LocalQuery, OrderOptions, PendingResult, PendingRoom, Predicate, QueryCoverage, QueryDocument, QueryGroup, QueryResult, QueryRows, Related, Select, Value, Where, } from './query.js';
26
26
  export type { MdType, ModelIdentity, ModelSnapshot, ModelState, ModelResult, TypesResult, ValidationReceipt, } from './model.js';