@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c0105dbd22806

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/AGENTS.md +299 -0
  2. package/README.md +54 -0
  3. package/dist/adapter.d.ts +246 -40
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +1 -10
  6. package/dist/attached-model.d.ts +11 -0
  7. package/dist/attached-model.d.ts.map +1 -0
  8. package/dist/attached-model.js +47 -0
  9. package/dist/attempt.d.ts +16 -0
  10. package/dist/attempt.d.ts.map +1 -0
  11. package/dist/attempt.js +70 -0
  12. package/dist/binary.d.ts +23 -0
  13. package/dist/binary.d.ts.map +1 -0
  14. package/dist/binary.js +8 -0
  15. package/dist/bootstrap.d.ts +17 -7
  16. package/dist/bootstrap.d.ts.map +1 -1
  17. package/dist/bootstrap.js +97 -41
  18. package/dist/change-set.d.ts +33 -0
  19. package/dist/change-set.d.ts.map +1 -0
  20. package/dist/change-set.js +90 -0
  21. package/dist/change.d.ts +24 -0
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +31 -5
  24. package/dist/chat/acts.d.ts +34 -0
  25. package/dist/chat/acts.d.ts.map +1 -0
  26. package/dist/chat/acts.js +36 -0
  27. package/dist/chat/context.d.ts +3 -0
  28. package/dist/chat/context.d.ts.map +1 -0
  29. package/dist/chat/context.js +10 -0
  30. package/dist/chat/input.d.ts +9 -0
  31. package/dist/chat/input.d.ts.map +1 -0
  32. package/dist/chat/input.js +99 -0
  33. package/dist/chat/kit.d.ts +60 -0
  34. package/dist/chat/kit.d.ts.map +1 -0
  35. package/dist/chat/kit.js +123 -0
  36. package/dist/chat/lasting.d.ts +6 -0
  37. package/dist/chat/lasting.d.ts.map +1 -0
  38. package/dist/chat/lasting.js +19 -0
  39. package/dist/chat/list.d.ts +26 -0
  40. package/dist/chat/list.d.ts.map +1 -0
  41. package/dist/chat/list.js +62 -0
  42. package/dist/chat/markdown.d.ts +20 -0
  43. package/dist/chat/markdown.d.ts.map +1 -0
  44. package/dist/chat/markdown.js +188 -0
  45. package/dist/chat/message.d.ts +6 -0
  46. package/dist/chat/message.d.ts.map +1 -0
  47. package/dist/chat/message.js +192 -0
  48. package/dist/chat/messages.d.ts +21 -0
  49. package/dist/chat/messages.d.ts.map +1 -0
  50. package/dist/chat/messages.js +151 -0
  51. package/dist/chat/name.d.ts +6 -0
  52. package/dist/chat/name.d.ts.map +1 -0
  53. package/dist/chat/name.js +37 -0
  54. package/dist/chat/opened.d.ts +11 -0
  55. package/dist/chat/opened.d.ts.map +1 -0
  56. package/dist/chat/opened.js +17 -0
  57. package/dist/chat/overlay.d.ts +31 -0
  58. package/dist/chat/overlay.d.ts.map +1 -0
  59. package/dist/chat/overlay.js +97 -0
  60. package/dist/chat/parts.d.ts +57 -0
  61. package/dist/chat/parts.d.ts.map +1 -0
  62. package/dist/chat/parts.js +119 -0
  63. package/dist/chat/process.d.ts +20 -0
  64. package/dist/chat/process.d.ts.map +1 -0
  65. package/dist/chat/process.js +32 -0
  66. package/dist/chat/provider.d.ts +63 -0
  67. package/dist/chat/provider.d.ts.map +1 -0
  68. package/dist/chat/provider.js +645 -0
  69. package/dist/chat/question.d.ts +9 -0
  70. package/dist/chat/question.d.ts.map +1 -0
  71. package/dist/chat/question.js +80 -0
  72. package/dist/chat/questions.d.ts +31 -0
  73. package/dist/chat/questions.d.ts.map +1 -0
  74. package/dist/chat/questions.js +111 -0
  75. package/dist/chat/read.d.ts +5 -0
  76. package/dist/chat/read.d.ts.map +1 -0
  77. package/dist/chat/read.js +13 -0
  78. package/dist/chat/ready.d.ts +33 -0
  79. package/dist/chat/ready.d.ts.map +1 -0
  80. package/dist/chat/ready.js +91 -0
  81. package/dist/chat/style.d.ts +4 -0
  82. package/dist/chat/style.d.ts.map +1 -0
  83. package/dist/chat/style.js +302 -0
  84. package/dist/chat.d.ts +14 -0
  85. package/dist/chat.d.ts.map +1 -0
  86. package/dist/chat.js +8 -0
  87. package/dist/client.d.ts +49 -33
  88. package/dist/client.d.ts.map +1 -1
  89. package/dist/client.js +164 -183
  90. package/dist/collection.d.ts +9 -17
  91. package/dist/collection.d.ts.map +1 -1
  92. package/dist/collection.js +83 -89
  93. package/dist/connection.d.ts +66 -48
  94. package/dist/connection.d.ts.map +1 -1
  95. package/dist/connection.js +1964 -1173
  96. package/dist/conversation.d.ts +65 -24
  97. package/dist/conversation.d.ts.map +1 -1
  98. package/dist/conversation.js +675 -334
  99. package/dist/durability.js +6 -6
  100. package/dist/entry.d.ts +17 -0
  101. package/dist/entry.d.ts.map +1 -0
  102. package/dist/entry.js +156 -0
  103. package/dist/expectation.d.ts +21 -0
  104. package/dist/expectation.d.ts.map +1 -0
  105. package/dist/expectation.js +70 -0
  106. package/dist/failure.d.ts +13 -0
  107. package/dist/failure.d.ts.map +1 -0
  108. package/dist/failure.js +19 -0
  109. package/dist/fence.d.ts +6 -0
  110. package/dist/fence.d.ts.map +1 -0
  111. package/dist/fence.js +10 -0
  112. package/dist/file.d.ts +2 -2
  113. package/dist/file.d.ts.map +1 -1
  114. package/dist/file.js +48 -71
  115. package/dist/host.d.ts +15 -3
  116. package/dist/host.d.ts.map +1 -1
  117. package/dist/host.js +109 -127
  118. package/dist/identity.d.ts +4 -0
  119. package/dist/identity.d.ts.map +1 -1
  120. package/dist/identity.js +22 -9
  121. package/dist/index.d.ts +17 -11
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +4 -3
  124. package/dist/log.js +5 -6
  125. package/dist/memory.d.ts +19 -8
  126. package/dist/memory.d.ts.map +1 -1
  127. package/dist/memory.js +304 -216
  128. package/dist/model.d.ts +16 -30
  129. package/dist/model.d.ts.map +1 -1
  130. package/dist/model.js +21 -21
  131. package/dist/observation.d.ts +27 -0
  132. package/dist/observation.d.ts.map +1 -0
  133. package/dist/observation.js +95 -0
  134. package/dist/open.d.ts +2 -0
  135. package/dist/open.d.ts.map +1 -0
  136. package/dist/open.js +1 -0
  137. package/dist/outcome.d.ts +37 -31
  138. package/dist/outcome.d.ts.map +1 -1
  139. package/dist/outcome.js +36 -18
  140. package/dist/overlay.d.ts +22 -4
  141. package/dist/overlay.d.ts.map +1 -1
  142. package/dist/overlay.js +236 -54
  143. package/dist/paths.d.ts +0 -2
  144. package/dist/paths.d.ts.map +1 -1
  145. package/dist/paths.js +6 -29
  146. package/dist/query.d.ts +219 -10
  147. package/dist/query.d.ts.map +1 -1
  148. package/dist/query.js +462 -15
  149. package/dist/reach.d.ts +42 -0
  150. package/dist/reach.d.ts.map +1 -0
  151. package/dist/reach.js +294 -0
  152. package/dist/react.d.ts +41 -0
  153. package/dist/react.d.ts.map +1 -0
  154. package/dist/react.js +64 -0
  155. package/dist/read-side.d.ts +18 -0
  156. package/dist/read-side.d.ts.map +1 -0
  157. package/dist/read-side.js +440 -0
  158. package/dist/refresh.d.ts +15 -5
  159. package/dist/refresh.d.ts.map +1 -1
  160. package/dist/refresh.js +64 -41
  161. package/dist/replica.d.ts +28 -5
  162. package/dist/replica.d.ts.map +1 -1
  163. package/dist/replica.js +249 -40
  164. package/dist/room-draft.d.ts +144 -0
  165. package/dist/room-draft.d.ts.map +1 -0
  166. package/dist/room-draft.js +438 -0
  167. package/dist/rows.d.ts +46 -0
  168. package/dist/rows.d.ts.map +1 -0
  169. package/dist/rows.js +145 -0
  170. package/dist/save.d.ts +33 -5
  171. package/dist/save.d.ts.map +1 -1
  172. package/dist/save.js +630 -366
  173. package/dist/search.d.ts +62 -0
  174. package/dist/search.d.ts.map +1 -0
  175. package/dist/search.js +125 -0
  176. package/dist/status.d.ts +6 -8
  177. package/dist/status.d.ts.map +1 -1
  178. package/dist/status.js +8 -20
  179. package/dist/store.d.ts +89 -34
  180. package/dist/store.d.ts.map +1 -1
  181. package/dist/store.js +513 -132
  182. package/dist/transfer.d.ts +5 -0
  183. package/dist/transfer.d.ts.map +1 -1
  184. package/dist/transfer.js +1 -5
  185. package/dist/wire.d.ts +59 -19
  186. package/dist/wire.d.ts.map +1 -1
  187. package/dist/wire.js +88 -105
  188. package/package.json +34 -16
  189. package/dist/adapter.js.map +0 -1
  190. package/dist/bootstrap.js.map +0 -1
  191. package/dist/change.js.map +0 -1
  192. package/dist/client.js.map +0 -1
  193. package/dist/collection.js.map +0 -1
  194. package/dist/connection.js.map +0 -1
  195. package/dist/conversation.js.map +0 -1
  196. package/dist/durability.js.map +0 -1
  197. package/dist/file.js.map +0 -1
  198. package/dist/host.js.map +0 -1
  199. package/dist/identity.js.map +0 -1
  200. package/dist/index.js.map +0 -1
  201. package/dist/log.js.map +0 -1
  202. package/dist/memory.js.map +0 -1
  203. package/dist/model.js.map +0 -1
  204. package/dist/outcome.js.map +0 -1
  205. package/dist/overlay.js.map +0 -1
  206. package/dist/paths.js.map +0 -1
  207. package/dist/query.js.map +0 -1
  208. package/dist/refresh.js.map +0 -1
  209. package/dist/replica.js.map +0 -1
  210. package/dist/save.js.map +0 -1
  211. package/dist/status.js.map +0 -1
  212. package/dist/store.js.map +0 -1
  213. package/dist/transfer.js.map +0 -1
  214. package/dist/wire.js.map +0 -1
@@ -1,11 +1,11 @@
1
- const STORAGE_LOSS_STATEMENT = 'Unsynchronized Drafts and Pending Changes were lost.';
1
+ const STORAGE_LOSS_CODE = 'storage-loss';
2
2
  export function detectStorageLoss(stored, reported) {
3
- if (reported === null || reported === stored) return null;
4
- return STORAGE_LOSS_STATEMENT;
3
+ if (reported === null || reported === stored)
4
+ return null;
5
+ return STORAGE_LOSS_CODE;
5
6
  }
6
7
  export function nextGeneration(stored, reported) {
7
- if (stored !== null && (reported === null || reported === stored)) return stored;
8
+ if (stored !== null && (reported === null || reported === stored))
9
+ return stored;
8
10
  return crypto.randomUUID();
9
11
  }
10
-
11
- //# sourceMappingURL=durability.js.map
@@ -0,0 +1,17 @@
1
+ import { type QueryResult } from './query.js';
2
+ export { QueryError } from './query.js';
3
+ export type EntryRoom = {
4
+ locator: string;
5
+ schema: string | null;
6
+ documents: Readonly<Record<string, string>>;
7
+ };
8
+ export type EntryArguments = Readonly<Record<string, string>>;
9
+ export type EntryParameterKind = 'string' | 'integer' | 'number' | 'boolean';
10
+ export declare function boundQuery(template: unknown, args: EntryArguments): unknown;
11
+ export declare function entryParameters(template: unknown): readonly string[];
12
+ export declare function entryRefusal(template: unknown): string | null;
13
+ export type EntryScope = {
14
+ results(queries: Readonly<Record<string, unknown>>): Promise<Record<string, QueryResult>>;
15
+ };
16
+ export declare function entryScope(rooms: readonly EntryRoom[]): EntryScope;
17
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AA0D7E,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAE3E;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAMpE;AAkCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQ7D;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;CAC3F,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,UAAU,CAqDlE"}
package/dist/entry.js ADDED
@@ -0,0 +1,156 @@
1
+ import { attachedModel } from './attached-model.js';
2
+ import { collectionOf, passingDocument } from './collection.js';
3
+ import { NO_MODEL } from './model.js';
4
+ import { invalid, planOf, plain, QueryError, } from './query.js';
5
+ import { createReadSide } from './read-side.js';
6
+ import { rowsOf } from './rows.js';
7
+ export { QueryError } from './query.js';
8
+ const PARAMETER = '$param';
9
+ const KIND = 'as';
10
+ const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
11
+ const NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/u;
12
+ function parameterOf(value) {
13
+ if (!plain(value) || !Object.hasOwn(value, PARAMETER))
14
+ return null;
15
+ const { [PARAMETER]: name, [KIND]: kind = 'string', ...rest } = value;
16
+ if (typeof name !== 'string' || Object.keys(rest).length > 0)
17
+ return null;
18
+ if (kind !== 'string' && kind !== 'integer' && kind !== 'number' && kind !== 'boolean') {
19
+ return null;
20
+ }
21
+ return { name, kind };
22
+ }
23
+ function converted(text, kind, at) {
24
+ if (kind === 'string')
25
+ return text;
26
+ if (kind === 'boolean') {
27
+ if (text === 'true' || text === 'false')
28
+ return text === 'true';
29
+ return invalid(at, 'expects true or false');
30
+ }
31
+ if (!(kind === 'integer' ? INTEGER : NUMBER).test(text))
32
+ invalid(at, `expects ${kind === 'integer' ? 'an integer' : 'a number'}`);
33
+ const number = Number(text);
34
+ if (!Number.isFinite(number) || (kind === 'integer' && !Number.isSafeInteger(number))) {
35
+ invalid(at, 'is out of range');
36
+ }
37
+ return number;
38
+ }
39
+ function bound(template, args, at) {
40
+ const parameter = parameterOf(template);
41
+ if (parameter !== null) {
42
+ const text = args[parameter.name];
43
+ if (text === undefined || !Object.hasOwn(args, parameter.name)) {
44
+ invalid(at, `names the parameter ${parameter.name}, which the route lacks`);
45
+ }
46
+ return converted(text, parameter.kind, at);
47
+ }
48
+ if (Array.isArray(template)) {
49
+ return template.map((item, index) => bound(item, args, `${at}[${index}]`));
50
+ }
51
+ if (plain(template)) {
52
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [
53
+ name,
54
+ bound(value, args, at === '' ? name : `${at}.${name}`),
55
+ ]));
56
+ }
57
+ return template;
58
+ }
59
+ export function boundQuery(template, args) {
60
+ return bound(template, args, '');
61
+ }
62
+ export function entryParameters(template) {
63
+ const parameter = parameterOf(template);
64
+ if (parameter !== null)
65
+ return [parameter.name];
66
+ if (Array.isArray(template))
67
+ return [...new Set(template.flatMap(entryParameters))];
68
+ if (plain(template))
69
+ return [...new Set(Object.values(template).flatMap(entryParameters))];
70
+ return [];
71
+ }
72
+ const SAMPLED = {
73
+ direction: 'asc',
74
+ nulls: 'last',
75
+ stringSort: 'lexical',
76
+ locale: 'en',
77
+ limit: 0,
78
+ pathPrefix: 'entry',
79
+ field: '/entry',
80
+ fields: '/entry',
81
+ types: 'any',
82
+ $in: 'entry',
83
+ $nin: 'entry',
84
+ $all: 'entry',
85
+ $size: 0,
86
+ $exists: true,
87
+ $gt: 0,
88
+ $gte: 0,
89
+ $lt: 0,
90
+ $lte: 0,
91
+ };
92
+ function sampled(template, key) {
93
+ if (parameterOf(template) !== null)
94
+ return Object.hasOwn(SAMPLED, key) ? SAMPLED[key] : null;
95
+ if (Array.isArray(template))
96
+ return template.map((item) => sampled(item, key));
97
+ if (plain(template)) {
98
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [name, sampled(value, name)]));
99
+ }
100
+ return template;
101
+ }
102
+ export function entryRefusal(template) {
103
+ try {
104
+ planOf(sampled(template, ''), { listed: false, rooms: [] });
105
+ return null;
106
+ }
107
+ catch (error) {
108
+ if (error instanceof QueryError)
109
+ return error.message;
110
+ throw error;
111
+ }
112
+ }
113
+ export function entryScope(rooms) {
114
+ const readSide = createReadSide();
115
+ const held = [];
116
+ const documents = rooms.flatMap((room) => {
117
+ const model = attachedModel({
118
+ kind: 'model',
119
+ snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
120
+ }, NO_MODEL).state;
121
+ held.push({
122
+ locator: room.locator,
123
+ available: model.status !== 'unavailable',
124
+ types: model.status === 'unavailable' ? [] : Object.values(model.types),
125
+ });
126
+ const composition = { model, selection: null };
127
+ const collection = collectionOf(room.documents, composition);
128
+ return Object.keys(room.documents)
129
+ .sort()
130
+ .map((path) => ({
131
+ locator: room.locator,
132
+ path,
133
+ before: [],
134
+ after: rowsOf(room.locator, path, passingDocument(collection, path) ?? null, composition, null, null),
135
+ }));
136
+ });
137
+ readSide.apply({
138
+ documents,
139
+ drafts: [],
140
+ rooms: [],
141
+ queues: [],
142
+ presentations: [],
143
+ messages: [],
144
+ conversations: [],
145
+ });
146
+ const planned = { listed: true, rooms: held };
147
+ return {
148
+ async results(queries) {
149
+ const results = {};
150
+ for (const [name, query] of Object.entries(queries)) {
151
+ results[name] = await readSide.query(planOf(query, planned));
152
+ }
153
+ return results;
154
+ },
155
+ };
156
+ }
@@ -0,0 +1,21 @@
1
+ export type ExpectedOf<E extends {
2
+ readonly key: string;
3
+ }> = E | readonly E[] | null;
4
+ export type Expecting<E extends {
5
+ readonly key: string;
6
+ }> = {
7
+ subscribe(listener: () => void): () => void;
8
+ version(): number;
9
+ begin(): number;
10
+ expect(act: number, expected: ExpectedOf<E>, settled?: (one: E) => boolean): void;
11
+ drop(act: number): void;
12
+ heard(shown: (one: E) => boolean): void;
13
+ drawn(): readonly E[];
14
+ };
15
+ export declare function expectedList<E extends {
16
+ readonly key: string;
17
+ }>(expected: ExpectedOf<E>): readonly E[];
18
+ export declare function expecting<E extends {
19
+ readonly key: string;
20
+ }>(): Expecting<E>;
21
+ //# sourceMappingURL=expectation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expectation.d.ts","sourceRoot":"","sources":["../src/expectation.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC;AAErF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,IAAI;IAC1D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,OAAO,IAAI,MAAM,CAAC;IAClB,KAAK,IAAI,MAAM,CAAC;IAChB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IAClF,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,SAAS,CAAC,EAAE,CAAC;CACvB,CAAC;AAIF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC7D,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GACtB,SAAS,CAAC,EAAE,CAGd;AAwBD,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,SAAS,CAAC,CAAC,CAAC,CA4C5E"}
@@ -0,0 +1,70 @@
1
+ export function expectedList(expected) {
2
+ if (expected === null)
3
+ return [];
4
+ return 'key' in expected ? [expected] : expected;
5
+ }
6
+ function superseded(entries, at) {
7
+ const key = entries[at]?.expectation.key;
8
+ return entries.slice(at + 1).some((later) => later.expectation.key === key);
9
+ }
10
+ function unended(entries, ends) {
11
+ const ended = new Set();
12
+ const kept = [];
13
+ for (const one of [...entries].reverse()) {
14
+ if (ended.has(one.expectation.key))
15
+ continue;
16
+ if (ends(one.expectation))
17
+ ended.add(one.expectation.key);
18
+ else
19
+ kept.unshift(one);
20
+ }
21
+ return kept;
22
+ }
23
+ export function expecting() {
24
+ let entries = [];
25
+ let version = 0;
26
+ let acts = 0;
27
+ const listeners = new Set();
28
+ const set = (next) => {
29
+ if (next.length === entries.length && next.every((one, at) => one === entries[at]))
30
+ return;
31
+ entries = next;
32
+ version += 1;
33
+ for (const listener of listeners)
34
+ listener();
35
+ };
36
+ return {
37
+ subscribe(listener) {
38
+ listeners.add(listener);
39
+ return () => {
40
+ listeners.delete(listener);
41
+ };
42
+ },
43
+ version: () => version,
44
+ begin() {
45
+ acts += 1;
46
+ return acts;
47
+ },
48
+ expect(act, expected, settled = () => false) {
49
+ const fresh = expectedList(expected);
50
+ if (fresh.length === 0)
51
+ return;
52
+ const keys = new Set(fresh.map((one) => one.key));
53
+ const kept = entries.filter((one) => one.act !== act || !keys.has(one.expectation.key));
54
+ const over = new Set(kept.map((one) => one.expectation.key));
55
+ set([
56
+ ...kept,
57
+ ...fresh
58
+ .filter((one) => over.has(one.key) || !settled(one))
59
+ .map((expectation) => ({ act, expectation })),
60
+ ]);
61
+ },
62
+ drop(act) {
63
+ set(entries.filter((one) => one.act !== act));
64
+ },
65
+ heard(shown) {
66
+ set(unended(entries, shown));
67
+ },
68
+ drawn: () => entries.flatMap((one, at) => (superseded(entries, at) ? [] : [one.expectation])),
69
+ };
70
+ }
@@ -0,0 +1,13 @@
1
+ export type RuntimeError = Error & {
2
+ readonly code: string;
3
+ readonly retryable: boolean;
4
+ };
5
+ export type Described = {
6
+ message: string;
7
+ code: string;
8
+ retryable: boolean;
9
+ };
10
+ export declare function runtimeError(code: string, message?: string, retryable?: boolean): RuntimeError;
11
+ export declare function failed(error: unknown): RuntimeError;
12
+ export declare function described(error: unknown): Described;
13
+ //# sourceMappingURL=failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1F,MAAM,MAAM,SAAS,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAa,EACtB,SAAS,UAAQ,GAChB,YAAY,CAEd;AAYD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAGnD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAGnD"}
@@ -0,0 +1,19 @@
1
+ export function runtimeError(code, message = code, retryable = false) {
2
+ return Object.assign(new Error(message), { code, retryable });
3
+ }
4
+ function coded(error) {
5
+ return (error instanceof Error &&
6
+ 'code' in error &&
7
+ typeof error.code === 'string' &&
8
+ 'retryable' in error &&
9
+ typeof error.retryable === 'boolean');
10
+ }
11
+ export function failed(error) {
12
+ if (coded(error))
13
+ return error;
14
+ return runtimeError('runtime-failure', error instanceof Error ? error.message : String(error));
15
+ }
16
+ export function described(error) {
17
+ const { message, code, retryable } = failed(error);
18
+ return { message, code, retryable };
19
+ }
@@ -0,0 +1,6 @@
1
+ export declare class FencedMap<V> extends Map<string, V> {
2
+ #private;
3
+ constructor(fenced: (locator: string) => boolean);
4
+ set(locator: string, value: V): this;
5
+ }
6
+ //# sourceMappingURL=fence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../src/fence.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;;IAG9C,YAAY,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,EAG/C;IAEQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAE5C;CACF"}
package/dist/fence.js ADDED
@@ -0,0 +1,10 @@
1
+ export class FencedMap extends Map {
2
+ #fenced;
3
+ constructor(fenced) {
4
+ super();
5
+ this.#fenced = fenced;
6
+ }
7
+ set(locator, value) {
8
+ return this.#fenced(locator) ? this : super.set(locator, value);
9
+ }
10
+ }
package/dist/file.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type InstructionFile = {
1
+ export type ChatDraftFile = {
2
2
  name: string;
3
3
  blob: Blob;
4
4
  };
@@ -16,5 +16,5 @@ export type Extent = {
16
16
  };
17
17
  export declare function extentOf(bytes: Uint8Array): Extent | null;
18
18
  export declare function hexDigest(digest: ArrayBuffer): string;
19
- export declare function declaredFile(file: InstructionFile): Promise<FileDeclaration>;
19
+ export declare function declaredFile(file: ChatDraftFile): Promise<FileDeclaration>;
20
20
  //# sourceMappingURL=file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA2GvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAQzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAErD;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAUlF"}
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA2GvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAQzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAErD;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAUhF"}
package/dist/file.js CHANGED
@@ -1,138 +1,117 @@
1
- const PNG_SIGNATURE = [
2
- 0x89,
3
- 0x50,
4
- 0x4e,
5
- 0x47,
6
- 0x0d,
7
- 0x0a,
8
- 0x1a,
9
- 0x0a
10
- ];
11
- const WEBP_SYNC = [
12
- 0x9d,
13
- 0x01,
14
- 0x2a
15
- ];
16
- const SHAPELESS_JPEG_MARKERS = new Set([
17
- 0xc4,
18
- 0xc8,
19
- 0xcc
20
- ]);
21
- const BMFF_CONTAINERS = new Set([
22
- 'meta',
23
- 'iprp',
24
- 'ipco'
25
- ]);
1
+ const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
2
+ const WEBP_SYNC = [0x9d, 0x01, 0x2a];
3
+ const SHAPELESS_JPEG_MARKERS = new Set([0xc4, 0xc8, 0xcc]);
4
+ const BMFF_CONTAINERS = new Set(['meta', 'iprp', 'ipco']);
26
5
  function starts(bytes, signature, at = 0) {
27
- return signature.every((value, index)=>bytes[at + index] === value);
6
+ return signature.every((value, index) => bytes[at + index] === value);
28
7
  }
29
8
  function text(bytes, at, length) {
30
9
  return String.fromCharCode(...bytes.subarray(at, at + length));
31
10
  }
32
11
  function bigEndian(bytes, at, length) {
33
12
  let value = 0;
34
- for(let index = 0; index < length; index += 1)value = value * 256 + (bytes[at + index] ?? 0);
13
+ for (let index = 0; index < length; index += 1)
14
+ value = value * 256 + (bytes[at + index] ?? 0);
35
15
  return value;
36
16
  }
37
17
  function littleEndian(bytes, at, length) {
38
18
  let value = 0;
39
- for(let index = length - 1; index >= 0; index -= 1)value = value * 256 + (bytes[at + index] ?? 0);
19
+ for (let index = length - 1; index >= 0; index -= 1)
20
+ value = value * 256 + (bytes[at + index] ?? 0);
40
21
  return value;
41
22
  }
42
23
  function pngExtent(bytes) {
43
- if (bytes.length < 24 || !starts(bytes, PNG_SIGNATURE)) return null;
44
- if (text(bytes, 12, 4) !== 'IHDR') return null;
45
- return {
46
- width: bigEndian(bytes, 16, 4),
47
- height: bigEndian(bytes, 20, 4)
48
- };
24
+ if (bytes.length < 24 || !starts(bytes, PNG_SIGNATURE))
25
+ return null;
26
+ if (text(bytes, 12, 4) !== 'IHDR')
27
+ return null;
28
+ return { width: bigEndian(bytes, 16, 4), height: bigEndian(bytes, 20, 4) };
49
29
  }
50
30
  function gifExtent(bytes) {
51
- if (bytes.length < 10 || text(bytes, 0, 3) !== 'GIF') return null;
52
- return {
53
- width: littleEndian(bytes, 6, 2),
54
- height: littleEndian(bytes, 8, 2)
55
- };
31
+ if (bytes.length < 10 || text(bytes, 0, 3) !== 'GIF')
32
+ return null;
33
+ return { width: littleEndian(bytes, 6, 2), height: littleEndian(bytes, 8, 2) };
56
34
  }
57
35
  function jpegExtent(bytes) {
58
- if (bytes.length < 4 || bytes[0] !== 0xff || bytes[1] !== 0xd8) return null;
36
+ if (bytes.length < 4 || bytes[0] !== 0xff || bytes[1] !== 0xd8)
37
+ return null;
59
38
  let at = 2;
60
- while(at + 9 < bytes.length){
61
- if (bytes[at] !== 0xff) return null;
39
+ while (at + 9 < bytes.length) {
40
+ if (bytes[at] !== 0xff)
41
+ return null;
62
42
  const marker = bytes[at + 1] ?? 0;
63
- if (marker === 0xd8 || marker === 0x01 || marker >= 0xd0 && marker <= 0xd7) {
43
+ if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
64
44
  at += 2;
65
45
  continue;
66
46
  }
67
47
  const length = bigEndian(bytes, at + 2, 2);
68
48
  if (marker >= 0xc0 && marker <= 0xcf && !SHAPELESS_JPEG_MARKERS.has(marker)) {
69
- return {
70
- width: bigEndian(bytes, at + 7, 2),
71
- height: bigEndian(bytes, at + 5, 2)
72
- };
49
+ return { width: bigEndian(bytes, at + 7, 2), height: bigEndian(bytes, at + 5, 2) };
73
50
  }
74
- if (length < 2) return null;
51
+ if (length < 2)
52
+ return null;
75
53
  at += 2 + length;
76
54
  }
77
55
  return null;
78
56
  }
79
57
  function webpExtent(bytes) {
80
- if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') return null;
58
+ if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP')
59
+ return null;
81
60
  const chunk = text(bytes, 12, 4);
82
61
  if (chunk === 'VP8X') {
83
62
  return {
84
63
  width: littleEndian(bytes, 24, 3) + 1,
85
- height: littleEndian(bytes, 27, 3) + 1
64
+ height: littleEndian(bytes, 27, 3) + 1,
86
65
  };
87
66
  }
88
67
  if (chunk === 'VP8 ' && starts(bytes, WEBP_SYNC, 23)) {
89
68
  return {
90
69
  width: littleEndian(bytes, 26, 2) & 0x3fff,
91
- height: littleEndian(bytes, 28, 2) & 0x3fff
70
+ height: littleEndian(bytes, 28, 2) & 0x3fff,
92
71
  };
93
72
  }
94
73
  if (chunk === 'VP8L' && bytes[20] === 0x2f) {
95
74
  const packed = littleEndian(bytes, 21, 4);
96
- return {
97
- width: (packed & 0x3fff) + 1,
98
- height: (packed >>> 14 & 0x3fff) + 1
99
- };
75
+ return { width: (packed & 0x3fff) + 1, height: ((packed >>> 14) & 0x3fff) + 1 };
100
76
  }
101
77
  return null;
102
78
  }
103
79
  function spatialExtent(bytes, from, to) {
104
80
  let at = from;
105
- while(at + 8 <= to){
81
+ while (at + 8 <= to) {
106
82
  const size = bigEndian(bytes, at, 4);
107
83
  const name = text(bytes, at + 4, 4);
108
84
  const end = size === 0 ? to : at + size;
109
- if (size === 1 || end <= at || end > to) return null;
85
+ if (size === 1 || end <= at || end > to)
86
+ return null;
110
87
  if (name === 'ispe') {
111
- if (end < at + 20) return null;
112
- return {
113
- width: bigEndian(bytes, at + 12, 4),
114
- height: bigEndian(bytes, at + 16, 4)
115
- };
88
+ if (end < at + 20)
89
+ return null;
90
+ return { width: bigEndian(bytes, at + 12, 4), height: bigEndian(bytes, at + 16, 4) };
116
91
  }
117
92
  if (BMFF_CONTAINERS.has(name)) {
118
93
  const inner = spatialExtent(bytes, at + (name === 'meta' ? 12 : 8), end);
119
- if (inner !== null) return inner;
94
+ if (inner !== null)
95
+ return inner;
120
96
  }
121
97
  at = end;
122
98
  }
123
99
  return null;
124
100
  }
125
101
  function bmffExtent(bytes) {
126
- if (bytes.length < 16 || text(bytes, 4, 4) !== 'ftyp') return null;
102
+ if (bytes.length < 16 || text(bytes, 4, 4) !== 'ftyp')
103
+ return null;
127
104
  return spatialExtent(bytes, 0, bytes.length);
128
105
  }
129
106
  export function extentOf(bytes) {
130
- return pngExtent(bytes) ?? jpegExtent(bytes) ?? gifExtent(bytes) ?? webpExtent(bytes) ?? bmffExtent(bytes);
107
+ return (pngExtent(bytes) ??
108
+ jpegExtent(bytes) ??
109
+ gifExtent(bytes) ??
110
+ webpExtent(bytes) ??
111
+ bmffExtent(bytes));
131
112
  }
132
113
  export function hexDigest(digest) {
133
- return [
134
- ...new Uint8Array(digest)
135
- ].map((value)=>value.toString(16).padStart(2, '0')).join('');
114
+ return [...new Uint8Array(digest)].map((value) => value.toString(16).padStart(2, '0')).join('');
136
115
  }
137
116
  export async function declaredFile(file) {
138
117
  const bytes = new Uint8Array(await file.blob.arrayBuffer());
@@ -142,8 +121,6 @@ export async function declaredFile(file) {
142
121
  mediaType: file.blob.type,
143
122
  byteLength: bytes.byteLength,
144
123
  contentHash: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
145
- ...extent === null ? {} : extent
124
+ ...(extent === null ? {} : extent),
146
125
  };
147
126
  }
148
-
149
- //# sourceMappingURL=file.js.map
package/dist/host.d.ts CHANGED
@@ -1,9 +1,21 @@
1
1
  import { type MdRuntimeOptions } from './connection.js';
2
+ import type { PortReach } from './reach.js';
2
3
  import { type RuntimePort } from './wire.js';
4
+ export type MdRuntimeHostOptions = MdRuntimeOptions & {
5
+ deploymentFacts?: unknown;
6
+ };
7
+ export type AttachedPort = {
8
+ detach(): void;
9
+ narrow(reach: PortReach): void;
10
+ };
3
11
  export type MdRuntimeHost = {
4
- attach(port: RuntimePort, app: string): () => void;
5
- endAuthorization(): Promise<void>;
12
+ attach(port: RuntimePort, app: string, release?: string, reach?: PortReach): AttachedPort;
13
+ endAuthorization(holder?: string): Promise<void>;
14
+ lose(locators: readonly string[]): Promise<void>;
15
+ stop(): Promise<void>;
6
16
  };
7
- export declare function serveMdRuntime(options: MdRuntimeOptions): MdRuntimeHost;
17
+ export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
18
+ export type { PortReach, ReachedDocument } from './reach.js';
19
+ export { AUTHORED_SCHEMA, authoredBy, authoredHolder, STORE_SCHEMA } from './store.js';
8
20
  export type { RuntimePort } from './wire.js';
9
21
  //# 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,EACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAML,KAAK,WAAW,EAKjB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IACnD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC,CAAC;AA2GF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAuFvE;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,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;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IAC1F,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;AAsFF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAoH3E;AAED,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvF,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}