@agentshouse/mdruntime 0.1.0-c5d81e5d5cb58 → 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 (79) hide show
  1. package/dist/adapter.d.ts +15 -28
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/bootstrap.d.ts +7 -14
  4. package/dist/bootstrap.d.ts.map +1 -1
  5. package/dist/bootstrap.js +82 -107
  6. package/dist/collection.d.ts +0 -3
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +1 -17
  9. package/dist/compile.d.ts.map +1 -1
  10. package/dist/compile.js +16 -8
  11. package/dist/connection.d.ts +0 -1
  12. package/dist/connection.d.ts.map +1 -1
  13. package/dist/connection.js +455 -688
  14. package/dist/conversation.d.ts +2 -3
  15. package/dist/conversation.d.ts.map +1 -1
  16. package/dist/conversation.js +56 -10
  17. package/dist/durability.d.ts +0 -1
  18. package/dist/durability.d.ts.map +1 -1
  19. package/dist/entry.d.ts +1 -0
  20. package/dist/entry.d.ts.map +1 -1
  21. package/dist/entry.js +1 -1
  22. package/dist/fulltext.d.ts.map +1 -1
  23. package/dist/fulltext.js +7 -5
  24. package/dist/host.d.ts +0 -1
  25. package/dist/host.d.ts.map +1 -1
  26. package/dist/host.js +6 -4
  27. package/dist/index.d.ts +4 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -1
  30. package/dist/media.d.ts +1 -1
  31. package/dist/media.d.ts.map +1 -1
  32. package/dist/media.js +19 -9
  33. package/dist/memory.d.ts +2 -1
  34. package/dist/memory.d.ts.map +1 -1
  35. package/dist/memory.js +50 -20
  36. package/dist/model.d.ts +0 -1
  37. package/dist/model.d.ts.map +1 -1
  38. package/dist/model.js +0 -9
  39. package/dist/outcome.d.ts +0 -3
  40. package/dist/outcome.d.ts.map +1 -1
  41. package/dist/reach.js +1 -1
  42. package/dist/readiness.d.ts +3 -15
  43. package/dist/readiness.d.ts.map +1 -1
  44. package/dist/readiness.js +4 -10
  45. package/dist/recovery.d.ts +1 -0
  46. package/dist/recovery.d.ts.map +1 -1
  47. package/dist/recovery.js +26 -0
  48. package/dist/refresh.d.ts +5 -4
  49. package/dist/refresh.d.ts.map +1 -1
  50. package/dist/refresh.js +4 -4
  51. package/dist/replica.d.ts +1 -2
  52. package/dist/replica.d.ts.map +1 -1
  53. package/dist/replica.js +0 -4
  54. package/dist/room-draft.d.ts +17 -2
  55. package/dist/room-draft.d.ts.map +1 -1
  56. package/dist/room-draft.js +40 -6
  57. package/dist/shared.d.ts +0 -1
  58. package/dist/shared.d.ts.map +1 -1
  59. package/dist/shared.js +0 -10
  60. package/dist/status.d.ts +0 -4
  61. package/dist/status.d.ts.map +1 -1
  62. package/dist/store.d.ts +6 -29
  63. package/dist/store.d.ts.map +1 -1
  64. package/dist/store.js +7 -63
  65. package/dist/stored.d.ts +1 -25
  66. package/dist/stored.d.ts.map +1 -1
  67. package/dist/stored.js +51 -115
  68. package/dist/tables.d.ts +3 -40
  69. package/dist/tables.d.ts.map +1 -1
  70. package/dist/tables.js +3 -52
  71. package/dist/transfer.d.ts +0 -5
  72. package/dist/transfer.d.ts.map +1 -1
  73. package/dist/validation.d.ts +3 -4
  74. package/dist/validation.d.ts.map +1 -1
  75. package/dist/validation.js +35 -96
  76. package/package.json +2 -2
  77. package/dist/reads.d.ts +0 -11
  78. package/dist/reads.d.ts.map +0 -1
  79. package/dist/reads.js +0 -100
@@ -1,6 +1,5 @@
1
- import { assess, checkDocument, parse, parseFrontmatter, resolves, verdicts, } from '@agentshouse/mdmodel';
2
- import { governing, selected } from './collection.js';
3
- import { sameTyping } from './model.js';
1
+ import { assess, parse, parseFrontmatter, verdicts, } from '@agentshouse/mdmodel';
2
+ import { selected } from './collection.js';
4
3
  import { paced, ROW_WEIGHT, yielded } from './turn.js';
5
4
  const NO_TYPES = { types: {} };
6
5
  function modelOf(model) {
@@ -60,103 +59,43 @@ function declared(content) {
60
59
  const read = parseFrontmatter(content);
61
60
  return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
62
61
  }
63
- function typedIn(content) {
64
- const type = declared(content);
65
- return type !== undefined && type !== 'any';
62
+ function shifted({ was, now }) {
63
+ return ((now === undefined) !== (was === undefined) ||
64
+ (now === null) !== (was === null) ||
65
+ declared(now) !== declared(was));
66
66
  }
67
- export function sameComposition(left, right) {
68
- return (sameTyping(left.model, right.model) &&
69
- (left.selection === null || right.selection === null
70
- ? left.selection === right.selection
71
- : sameTyping(left.selection.model, right.selection.model)) &&
72
- JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
73
- }
74
- function checked(path, content, composition) {
75
- const model = governing(composition, path);
76
- return checkDocument(path, content, modelOf(model), { anyRoom: true });
77
- }
78
- async function reachingAll(checks, composition, next) {
79
- const targets = [
80
- ...new Set(checks.flatMap(({ check }) => check.ok ? check.references.flatMap(({ target }) => (target === null ? [] : [target])) : [])),
81
- ];
82
- const known = await next(targets);
67
+ const PAGE_TEXT = 1 << 20;
68
+ export async function validatedNeighbourhood(changes, composition, source) {
83
69
  const pace = paced();
84
- for (const { path, check } of checks) {
85
- if (!check.ok)
86
- return false;
87
- const part = (other) => selected(composition, other) === selected(composition, path);
88
- const resolved = check.references.every((reference) => resolves(reference, (other) => (part(other) ? known.get(other)?.type : undefined), (other) => part(other) && known.get(other)?.binary === true));
89
- if (!resolved)
90
- return false;
91
- await pace((check.references.length + 1) * ROW_WEIGHT);
70
+ const changedAt = new Set();
71
+ const moved = [];
72
+ for (const change of changes) {
73
+ changedAt.add(change.path);
74
+ if (shifted(change))
75
+ moved.push(change.path);
76
+ await pace((change.now?.length ?? 0) + (change.was?.length ?? 0) + ROW_WEIGHT);
92
77
  }
93
- return true;
94
- }
95
- export async function changedCleanly(changes, previous, composition, source) {
96
- if (!sameComposition(previous, composition))
97
- return false;
98
- const changedAt = new Map(changes.map((change) => [change.path, change]));
99
- const next = async (paths) => {
100
- const asked = paths.filter((path) => !changedAt.has(path));
101
- const known = new Map(await source.lookup(asked));
102
- for (const path of paths) {
103
- const change = changedAt.get(path);
104
- if (change === undefined)
78
+ const referring = moved.length === 0
79
+ ? []
80
+ : (await source.referrers(moved)).filter((path) => !changedAt.has(path));
81
+ const texts = await source.texts(referring);
82
+ const total = changes.length + referring.length;
83
+ let at = 0;
84
+ const walk = async () => {
85
+ const entries = [];
86
+ let text = 0;
87
+ while (at < total && text < PAGE_TEXT) {
88
+ const change = changes[at];
89
+ const path = change?.path ?? referring[at - changes.length];
90
+ const content = change === undefined ? texts.get(path) : change.now;
91
+ at += 1;
92
+ text += ROW_WEIGHT;
93
+ if (content === undefined || content === null)
105
94
  continue;
106
- if (change.now === undefined)
107
- known.delete(path);
108
- else
109
- known.set(path, { type: declared(change.now), binary: change.now === null });
95
+ entries.push({ path, content });
96
+ text += content.length;
110
97
  }
111
- return known;
98
+ return { entries, next: at < total ? String(at) : null };
112
99
  };
113
- const shifted = [];
114
- const checks = [];
115
- const pace = paced();
116
- for (const { path, was, now } of changes) {
117
- await pace((now?.length ?? 0) + (was?.length ?? 0) + ROW_WEIGHT);
118
- const modeled = governing(composition, path).status !== 'unavailable';
119
- if ((now === undefined) !== (was === undefined) ||
120
- declared(now) !== declared(was) ||
121
- (now === null) !== (was === null)) {
122
- shifted.push(path);
123
- }
124
- if (!modeled && typedIn(was) && !typedIn(now))
125
- return false;
126
- if (now === undefined)
127
- continue;
128
- if (now === null)
129
- return false;
130
- if (!modeled) {
131
- if (declared(now) === undefined)
132
- return false;
133
- if (typedIn(now))
134
- continue;
135
- const check = checked(path, now, composition);
136
- if (!check.ok)
137
- return false;
138
- checks.push({ path, check });
139
- continue;
140
- }
141
- checks.push({ path, check: checked(path, now, composition) });
142
- }
143
- if (!(await reachingAll(checks, composition, next)))
144
- return false;
145
- if (shifted.length === 0)
146
- return true;
147
- if (source.referrers === null)
148
- return false;
149
- const files = (await source.referrers(shifted)).filter((file) => !changedAt.has(file));
150
- if (files.length === 0)
151
- return true;
152
- const texts = await source.texts(files);
153
- const rechecked = [];
154
- for (const file of files) {
155
- const content = texts.get(file);
156
- if (content === undefined || content === null)
157
- return false;
158
- await pace(content.length + ROW_WEIGHT);
159
- rechecked.push({ path: file, check: checked(file, content, composition) });
160
- }
161
- return reachingAll(rechecked, composition, next);
100
+ return validatedCollection(walk, source.lookup, composition);
162
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-c5d81e5d5cb58",
3
+ "version": "0.1.0-c5fe3b2cddda7",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -54,7 +54,7 @@
54
54
  "LICENSE"
55
55
  ],
56
56
  "dependencies": {
57
- "@agentshouse/mdmodel": "0.1.0-c9952fa046c11"
57
+ "@agentshouse/mdmodel": "0.1.0-c96c61ea31316"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": ">=18"
package/dist/reads.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { Adapter } from './adapter.js';
2
- import type { Reads } from './bootstrap.js';
3
- export type DoorReads = Reads & {
4
- carried(locator: string): number;
5
- finished(locator: string, turn: number): void;
6
- opened(): void;
7
- applied(): void;
8
- lost(): void;
9
- };
10
- export declare function doorReads(adapter: Adapter, declaration: (locator: string) => unknown, generation: () => number): DoorReads;
11
- //# sourceMappingURL=reads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG;IAC9B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAkCF,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,EACzC,UAAU,EAAE,MAAM,MAAM,GACvB,SAAS,CA4FX"}
package/dist/reads.js DELETED
@@ -1,100 +0,0 @@
1
- function declaredAs(declaration) {
2
- if (declaration === null || typeof declaration !== 'object')
3
- return declaration;
4
- const { roomVersion: _version, ...declared } = declaration;
5
- return declared;
6
- }
7
- function sameHeld(one, other) {
8
- return one === other;
9
- }
10
- function failed(answer) {
11
- return answer?.kind === 'transport-uncertainty';
12
- }
13
- function continues(answer) {
14
- const page = answer;
15
- return page?.kind === 'net-advancement' && page.pageToken !== undefined;
16
- }
17
- export function doorReads(adapter, declaration, generation) {
18
- const reading = new Map();
19
- const taken = new Map();
20
- let carrying = false;
21
- function joined(read, authorization, request, ask) {
22
- const key = `${read} ${request.locator} ${request.pageToken ?? ''}`;
23
- const { held, received, ...named } = request;
24
- const asked = JSON.stringify([declaredAs(declaration(request.locator)), named]);
25
- const asking = generation();
26
- const current = reading.get(key);
27
- if (current !== undefined &&
28
- current.authorization === authorization &&
29
- current.asked === asked &&
30
- sameHeld(current.held, held) &&
31
- current.received === received &&
32
- (!current.settled || current.holder < asking)) {
33
- if (current.settled && !current.continued)
34
- reading.delete(key);
35
- else
36
- current.holder = Math.max(current.holder, asking);
37
- if (current.from === asking)
38
- return current.answer;
39
- const again = () => joined(read, authorization, request, ask);
40
- return current.answer.then((answer) => {
41
- if (failed(answer))
42
- return again();
43
- taken.set(request.locator, (taken.get(request.locator) ?? 0) + 1);
44
- return answer;
45
- }, again);
46
- }
47
- const answer = ask();
48
- const sent = {
49
- locator: request.locator,
50
- authorization,
51
- asked,
52
- held,
53
- received,
54
- answer,
55
- from: asking,
56
- holder: asking,
57
- settled: false,
58
- continued: false,
59
- };
60
- reading.set(key, sent);
61
- const settled = (result, kept) => {
62
- sent.settled = true;
63
- sent.continued = kept && read === 'refresh' && continues(result);
64
- if (reading.get(key) !== sent)
65
- return;
66
- const live = sent.holder === generation();
67
- if (!kept || (live ? !sent.continued : !carrying))
68
- reading.delete(key);
69
- };
70
- answer.then((result) => settled(result, !failed(result)), () => settled(null, false));
71
- return answer;
72
- }
73
- return {
74
- bootstrap: (authorization, request) => joined('bootstrap', authorization, request, () => adapter.bootstrap(authorization, request)),
75
- refresh: (authorization, request) => joined('refresh', authorization, request, () => adapter.refresh(authorization, request)),
76
- reached: (locator, roomVersion, target) => adapter.reached(locator, roomVersion, target),
77
- carried: (locator) => taken.get(locator) ?? 0,
78
- finished(locator, turn) {
79
- for (const [key, held] of reading) {
80
- if (held.locator !== locator || !held.settled || held.holder !== turn)
81
- continue;
82
- if (turn === generation() || !carrying)
83
- reading.delete(key);
84
- }
85
- },
86
- opened() {
87
- carrying = true;
88
- },
89
- applied() {
90
- carrying = false;
91
- for (const [key, held] of reading) {
92
- if (held.settled && held.holder !== generation())
93
- reading.delete(key);
94
- }
95
- },
96
- lost() {
97
- reading.clear();
98
- },
99
- };
100
- }