@agentshouse/mdruntime-adapter 0.1.0-cec9e6243b0a4 → 0.1.0-ceda07a375a48

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 (61) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +122 -22
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +24 -137
  5. package/dist/adapter.d.ts.map +1 -1
  6. package/dist/adapter.js +204 -201
  7. package/dist/app-reference.d.ts +2 -0
  8. package/dist/app-reference.d.ts.map +1 -0
  9. package/dist/app-reference.js +2 -0
  10. package/dist/crockford.d.ts +4 -0
  11. package/dist/crockford.d.ts.map +1 -0
  12. package/dist/crockford.js +3 -0
  13. package/dist/discovery.d.ts +6 -10
  14. package/dist/discovery.d.ts.map +1 -1
  15. package/dist/discovery.js +36 -32
  16. package/dist/gather.d.ts +1 -2
  17. package/dist/gather.d.ts.map +1 -1
  18. package/dist/gather.js +5 -15
  19. package/dist/house-model.d.ts +2935 -0
  20. package/dist/house-model.d.ts.map +1 -0
  21. package/dist/house-model.js +1613 -0
  22. package/dist/index.d.ts +8 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +7 -1
  25. package/dist/model.d.ts +5 -1
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +11 -13
  28. package/dist/part.d.ts +14 -0
  29. package/dist/part.d.ts.map +1 -0
  30. package/dist/part.js +90 -0
  31. package/dist/read.d.ts +53 -27
  32. package/dist/read.d.ts.map +1 -1
  33. package/dist/read.js +262 -158
  34. package/dist/room-stream.d.ts +19 -0
  35. package/dist/room-stream.d.ts.map +1 -0
  36. package/dist/room-stream.js +57 -0
  37. package/dist/room-types.d.ts +7 -0
  38. package/dist/room-types.d.ts.map +1 -0
  39. package/dist/room-types.js +126 -0
  40. package/dist/site.d.ts.map +1 -1
  41. package/dist/site.js +47 -112
  42. package/dist/stream.d.ts +3 -3
  43. package/dist/stream.d.ts.map +1 -1
  44. package/dist/stream.js +65 -39
  45. package/dist/transport.d.ts +31 -8
  46. package/dist/transport.d.ts.map +1 -1
  47. package/dist/transport.js +2 -1
  48. package/dist/upload.d.ts +12 -0
  49. package/dist/upload.d.ts.map +1 -0
  50. package/dist/upload.js +63 -0
  51. package/dist/write.d.ts +16 -1
  52. package/dist/write.d.ts.map +1 -1
  53. package/dist/write.js +100 -55
  54. package/package.json +8 -4
  55. package/AGENTS.md +0 -299
  56. package/dist/handed.d.ts +0 -15
  57. package/dist/handed.d.ts.map +0 -1
  58. package/dist/handed.js +0 -38
  59. package/dist/referrer.d.ts +0 -7
  60. package/dist/referrer.d.ts.map +0 -1
  61. package/dist/referrer.js +0 -35
@@ -0,0 +1,126 @@
1
+ import { APP_REFERENCE_PATTERN } from './app-reference.js';
2
+ import { HOUSE_MODEL_TYPES } from './house-model.js';
3
+ export const INBOX_CHANNEL_KINDS = [
4
+ 'telegram-bot',
5
+ 'telegram-business',
6
+ 'whatsapp',
7
+ 'messenger',
8
+ 'instagram',
9
+ 'viber',
10
+ 'tiktok',
11
+ ];
12
+ export const INBOX_CHAT_TYPE = 'inbox-chat';
13
+ export const INBOX_MESSAGE_TYPE = 'inbox-message';
14
+ export const HOUSE_NAMEABLE_ROOM_TYPES = [INBOX_CHAT_TYPE, INBOX_MESSAGE_TYPE];
15
+ const WAYFINDING_MAP_TYPE = 'wayfinding-map';
16
+ const WAYFINDING_TICKET_TYPE = 'wayfinding-ticket';
17
+ const WAYFINDING_MAP_SECTIONS = [
18
+ 'Destination',
19
+ 'Notes',
20
+ 'Decisions so far',
21
+ 'Not yet specified',
22
+ 'Out of scope',
23
+ ];
24
+ const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
25
+ const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
26
+ const ASSIGNEE = [
27
+ ' type: object',
28
+ ' properties:',
29
+ ' user: { type: string, format: uuid }',
30
+ ...AGENT,
31
+ ];
32
+ export const HOUSE_ROOM_TYPES = [
33
+ `${INBOX_CHAT_TYPE}:`,
34
+ ' properties:',
35
+ ' inbox: { type: string, format: uuid }',
36
+ ` channel: { enum: [${INBOX_CHANNEL_KINDS.join(', ')}] }`,
37
+ ` chat: ${IDENTITY}`,
38
+ ' customer:',
39
+ ' type: object',
40
+ ' properties:',
41
+ ' name: { type: string }',
42
+ ` username: ${IDENTITY}`,
43
+ ` phone: ${IDENTITY}`,
44
+ ' assignee:',
45
+ ...ASSIGNEE,
46
+ ' return_to:',
47
+ ' type: object',
48
+ ' properties:',
49
+ ...AGENT,
50
+ ' conversation: { type: string, format: uuid }',
51
+ ' required: [inbox, channel, chat, customer]',
52
+ `${INBOX_MESSAGE_TYPE}:`,
53
+ ' properties:',
54
+ ' direction: { enum: [in, out] }',
55
+ ' sender:',
56
+ ' type: object',
57
+ ' properties:',
58
+ ' name: { type: string }',
59
+ ` username: ${IDENTITY}`,
60
+ ' sent_at: { type: string, format: date-time }',
61
+ ` channel_message: ${IDENTITY}`,
62
+ ' state: { enum: [sending, sent, failed] }',
63
+ ' reason: { type: string }',
64
+ ' labelled: { const: true }',
65
+ ' reactions:',
66
+ ' type: array',
67
+ ' items:',
68
+ ' type: object',
69
+ ' properties:',
70
+ ' reaction: { type: string, minLength: 1 }',
71
+ ' sender:',
72
+ ' type: object',
73
+ ' properties:',
74
+ ` id: ${IDENTITY}`,
75
+ ' name: { type: string }',
76
+ ` username: ${IDENTITY}`,
77
+ ' count: { type: integer, minimum: 1 }',
78
+ ' required: [reaction]',
79
+ ` post: ${IDENTITY}`,
80
+ ' assignee:',
81
+ ...ASSIGNEE,
82
+ ' sent_outside: { const: true }',
83
+ ' template:',
84
+ ' type: object',
85
+ ' properties:',
86
+ ' name: { type: string, minLength: 1 }',
87
+ ' language: { type: string, minLength: 1 }',
88
+ ' required: [name, language]',
89
+ ' values:',
90
+ ' type: object',
91
+ ' additionalProperties: { type: string }',
92
+ ' withheld: { const: true }',
93
+ ' required: [direction]',
94
+ ' if: { properties: { direction: { const: in } } }',
95
+ ' then: { required: [sent_at] }',
96
+ `${WAYFINDING_MAP_TYPE}:`,
97
+ ' properties:',
98
+ ' title: { type: string }',
99
+ ' required: [title]',
100
+ ' sections:',
101
+ ...WAYFINDING_MAP_SECTIONS.map((name) => ` ${name}: { kind: text, required: true }`),
102
+ `${WAYFINDING_TICKET_TYPE}:`,
103
+ ' properties:',
104
+ ' title: { type: string }',
105
+ ' kind: { enum: [research, prototype, grilling, task] }',
106
+ ' status: { enum: [open, in-progress, done, out-of-scope] }',
107
+ ` map: { type: string, reference: ${WAYFINDING_MAP_TYPE} }`,
108
+ ` blocked_by: { type: array, items: { type: string, reference: ${WAYFINDING_TICKET_TYPE} } }`,
109
+ ' assignee:',
110
+ ...ASSIGNEE,
111
+ ' conversation: { type: string, format: uuid }',
112
+ ` app: { type: string, pattern: '${APP_REFERENCE_PATTERN.source}' }`,
113
+ ' required: [title, kind, status, map, blocked_by]',
114
+ ' sections:',
115
+ ' Question: { kind: text }',
116
+ ' Answer: { kind: text }',
117
+ ' allOf:',
118
+ ' - if: { properties: { status: { enum: [in-progress, done, out-of-scope] } }, required: [status] }',
119
+ ' then: { required: [assignee] }',
120
+ ' else: { properties: { assignee: false } }',
121
+ ' - if: { properties: { assignee: { required: [agent] } }, required: [assignee] }',
122
+ ' else: { properties: { conversation: false } }',
123
+ ' - if: { properties: { status: { enum: [done, out-of-scope] } }, required: [status] }',
124
+ ' then: { sections: { Answer: { kind: text, required: true } } }',
125
+ HOUSE_MODEL_TYPES,
126
+ ].join('\n');
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;AA2BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAyCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAwR1F"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;AAwBhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAgCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAqN1F"}
package/dist/site.js CHANGED
@@ -1,12 +1,13 @@
1
+ import { stepped } from '@agentshouse/mdruntime';
1
2
  import { actionOutcome, SITE_SUBMIT } from './actions.js';
2
3
  import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
3
- import { partModels, streamedModels, viewModels } from './model.js';
4
- import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, siteBootstrapNext, siteBootstrapOffset, viewOf, wholeView, } from './read.js';
5
- import { sha256Hex } from './digest.js';
4
+ import { streamedModels, viewModels } from './model.js';
5
+ import { bootstrapping, parseEnumeration, refreshFrom, viewOf, wholeView, } from './read.js';
6
+ import { roomStreams } from './room-stream.js';
6
7
  import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
8
+ import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
7
9
  import { houseNotifications } from './stream.js';
8
- import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILE_RECORD, SITE_FILES, } from './transport.js';
9
- import { houseReferrer } from './referrer.js';
10
+ import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILES, } from './transport.js';
10
11
  import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
11
12
  const UNCERTAIN = { kind: 'transport-uncertainty' };
12
13
  function unfound() {
@@ -18,32 +19,21 @@ function siteRoom(tracked) {
18
19
  locator: tracked.locator,
19
20
  handle: tracked.handle,
20
21
  roomVersion: roomVersion(tracked),
21
- operations: { read: [''], sync: [''], write: [], delete: [] },
22
- replica: { selection: tracked.locator, admission: 'admitted' },
22
+ operations: { write: [], delete: [] },
23
+ replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
23
24
  providerOwnedPaths: [],
24
25
  };
25
26
  }
26
- function settled(refused) {
27
- return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
28
- }
29
27
  export function createSiteAdapter(transport, snapshot = false) {
30
28
  const notifications = houseNotifications(transport, 'site');
31
29
  const tracked = new Map();
32
- function published(referrer) {
33
- const named = houseReferrer(referrer, tracked);
34
- return named === null || !tracked.has(named.locator) ? null : named;
35
- }
30
+ const read = new Map();
31
+ const rooms = roomStreams('site');
36
32
  function fileRoute(request) {
37
- const named = published(request.kind === 'path' ? { room: request.locator, path: request.path } : request.referrer);
38
- if (named === null) {
39
- return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
40
- }
41
- if (request.fileRef === undefined)
42
- return unfound();
43
- const { room_ref, path, record } = named.referrer;
44
- return `${SITE_FILES}${room_ref}/${encodeURIComponent(request.fileRef)}/${path === undefined
45
- ? `${SITE_FILE_RECORD}/${encodeURIComponent(record)}`
46
- : encodeURIComponent(path)}`;
33
+ const entry = tracked.get(request.locator);
34
+ if (entry === undefined)
35
+ return { kind: 'room-not-readable', locator: request.locator };
36
+ return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
47
37
  }
48
38
  async function enumerated(entry, from, page) {
49
39
  const answer = await transport.door(SITE_DOOR_ENUMERATE, {
@@ -68,73 +58,35 @@ export function createSiteAdapter(transport, snapshot = false) {
68
58
  const first = await enumerated(entry, from);
69
59
  return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
70
60
  }
71
- async function bootstrapPart(entry, after, offset) {
72
- const query = [
73
- ...(after === null ? [] : [`after=${encodeURIComponent(after)}`]),
74
- ...(offset === null ? [] : [`offset=${offset}`]),
75
- ];
76
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${query.length === 0 ? '' : `?${query.join('&')}`}`);
77
- const classified = classifyDoor(answer.status, answer.body, entry.locator);
78
- if (classified !== null)
79
- return { failure: classified };
80
- const scope = parseSiteBootstrap(answer.body);
81
- return scope === null ? { failure: UNCERTAIN } : { body: answer.body, scope };
61
+ async function openedRoom(entry, arriving, signal) {
62
+ const cut = read.get(entry.locator);
63
+ const answered = await transport.streamed(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
64
+ if (answered.room === null)
65
+ return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
66
+ const head = await rooms.head(entry, answered.room, arriving, signal);
67
+ const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
68
+ if (at !== null)
69
+ read.set(entry.locator, at.position);
70
+ return head;
82
71
  }
83
- async function assembled(entry, scope, path, offset) {
84
- const opened = scope.contents.at(-1);
85
- if (opened === undefined || opened.path !== path || opened.content.length !== offset) {
86
- return UNCERTAIN;
87
- }
88
- let text = opened.content;
89
- for (;;) {
90
- const part = await bootstrapPart(entry, path, text.length);
91
- if ('failure' in part)
92
- return part.failure;
93
- const [piece] = part.scope.contents;
94
- if (piece === undefined ||
95
- part.scope.contents.length !== 1 ||
96
- piece.path !== path ||
97
- piece.content.length === 0) {
98
- return UNCERTAIN;
99
- }
100
- text += piece.content;
101
- const more = siteBootstrapOffset(part.body);
102
- if (more === null)
103
- break;
104
- if (more !== text.length)
105
- return UNCERTAIN;
106
- }
107
- const file = scope.files.find((held) => held.path === path);
108
- if (file === undefined || (await sha256Hex(text)) !== file.version)
109
- return UNCERTAIN;
110
- return { ...scope, contents: [...scope.contents.slice(0, -1), { path, content: text }] };
111
- }
112
- async function caughtUp(entry, after) {
113
- const part = await bootstrapPart(entry, after, null);
114
- if ('failure' in part)
72
+ async function streamedPage(entry, token) {
73
+ const part = await rooms.part(entry, token);
74
+ if ('kind' in part)
115
75
  return part;
116
- const next = siteBootstrapNext(part.body);
117
- const offset = siteBootstrapOffset(part.body);
118
- if (offset !== null) {
119
- if (next === null)
120
- return { failure: UNCERTAIN };
121
- const scope = await assembled(entry, part.scope, next, offset);
122
- return 'kind' in scope ? { failure: scope } : { scope, next };
123
- }
124
- const { scope } = part;
125
- if (after !== null || next !== null || roomVersion(scope) === roomVersion(entry)) {
126
- return { scope, next };
127
- }
128
- const view = await enumeration(entry, scope);
129
- if ('kind' in view)
130
- return { failure: settled(view) };
131
- return { scope: advancedScope(scope, view), next: null };
76
+ notifications.reach(entry.authority, part.scope);
77
+ const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
78
+ return {
79
+ ...page,
80
+ ...(part.models === undefined ? {} : { models: part.models }),
81
+ ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
82
+ bytes: part.bytes,
83
+ };
132
84
  }
133
85
  async function refreshed(entry, fromRoomVersion) {
134
86
  const from = logPosition(fromRoomVersion);
135
87
  if (from === null)
136
88
  return { kind: 'beyond-horizon' };
137
- const streamed = notifications.advance(entry, from);
89
+ const streamed = await stepped(notifications.advance(entry, from));
138
90
  if (streamed !== null) {
139
91
  const models = await streamedModels(streamed.schemas, entry, 'site');
140
92
  return models === undefined ? streamed.page : { ...streamed.page, models };
@@ -143,7 +95,7 @@ export function createSiteAdapter(transport, snapshot = false) {
143
95
  if ('kind' in view)
144
96
  return view;
145
97
  notifications.reach(entry.authority, view);
146
- const answer = refreshFrom(view, fromRoomVersion);
98
+ const answer = await refreshFrom(view, fromRoomVersion);
147
99
  if (answer.kind !== 'net-advancement')
148
100
  return answer;
149
101
  const models = await viewModels(view, entry);
@@ -152,6 +104,8 @@ export function createSiteAdapter(transport, snapshot = false) {
152
104
  return {
153
105
  localSaves: true,
154
106
  exhaustiveDiscovery: true,
107
+ roomTypes: HOUSE_ROOM_TYPES,
108
+ nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
155
109
  async authorize() {
156
110
  return {};
157
111
  },
@@ -174,24 +128,9 @@ export function createSiteAdapter(transport, snapshot = false) {
174
128
  const entry = tracked.get(request.locator);
175
129
  if (entry === undefined)
176
130
  return { kind: 'room-not-readable', locator: request.locator };
177
- const continued = request.pageToken === undefined
178
- ? null
179
- : JSON.parse(request.pageToken);
180
- const held = await caughtUp(entry, continued?.after ?? null);
181
- if ('failure' in held)
182
- return held.failure;
183
- notifications.reach(entry.authority, held.scope);
184
- const seen = [
185
- ...(continued?.seen ?? []),
186
- ...entry.schemas.filter((schema) => held.scope.files.some((file) => file.path === schema)),
187
- ];
188
- const models = await partModels(held.scope, entry, new Set(seen), held.next === null);
189
- const continuation = held.next === null ? null : { after: held.next, seen };
190
- return {
191
- ...bootstrapOf(held.scope),
192
- ...(models === undefined ? {} : { models }),
193
- ...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
194
- };
131
+ return request.pageToken === undefined
132
+ ? openedRoom(entry, request.arriving, request.signal)
133
+ : streamedPage(entry, request.pageToken);
195
134
  },
196
135
  async refresh(_authorization, request) {
197
136
  const entry = tracked.get(request.locator);
@@ -209,6 +148,9 @@ export function createSiteAdapter(transport, snapshot = false) {
209
148
  async mutate() {
210
149
  return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
211
150
  },
151
+ async attach() {
152
+ return { kind: 'rejected', code: 'write-grant', fields: {}, retryable: false };
153
+ },
212
154
  async history() {
213
155
  return { kind: 'no-history' };
214
156
  },
@@ -219,8 +161,8 @@ export function createSiteAdapter(transport, snapshot = false) {
219
161
  const read = await transport.download(route);
220
162
  if (read.status === 404)
221
163
  return unfound();
222
- return read.status === 200 && read.blob !== null
223
- ? { kind: 'binary', blob: read.blob }
164
+ return read.status === 200 && read.body !== null
165
+ ? { kind: 'binary', body: read.body, mediaType: read.mediaType }
224
166
  : UNCERTAIN;
225
167
  },
226
168
  async link(_authorization, request) {
@@ -233,13 +175,6 @@ export function createSiteAdapter(transport, snapshot = false) {
233
175
  name: request.path.slice(request.path.lastIndexOf('/') + 1),
234
176
  };
235
177
  },
236
- referrerScope(referrer) {
237
- const named = published(referrer);
238
- if (named === null)
239
- return null;
240
- const { path } = named.referrer;
241
- return { kind: 'room', locator: named.locator, ...(path === undefined ? {} : { path }) };
242
- },
243
178
  reached(locator, version, target) {
244
179
  return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
245
180
  },
package/dist/stream.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal, StreamReceipts } from '@agentshouse/mdruntime';
1
+ import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal, type StreamReceipts } from '@agentshouse/mdruntime';
2
2
  import type { TrackedAuthority } from './discovery.js';
3
3
  import type { HouseDoor, HouseHeldRoom, HouseMode, HouseStreamEntry } from './transport.js';
4
4
  import { type LogPosition } from './version.js';
5
5
  export type HeldRevision = (path: string, revision: string) => boolean;
6
6
  export type StreamedAdvancement = {
7
7
  page: RefreshPage;
8
- entries: readonly HouseStreamEntry[];
9
8
  schemas: ReadonlyMap<string, HouseStreamEntry>;
10
9
  };
11
10
  export type HouseNotifications = {
@@ -16,7 +15,8 @@ export type HouseNotifications = {
16
15
  reopen(): void;
17
16
  track(authorities: readonly TrackedAuthority[]): void;
18
17
  reach(authority: string, at: LogPosition): void;
19
- advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
18
+ edited(tracked: TrackedAuthority, from: LogPosition): readonly string[];
19
+ advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
20
20
  conversations: ConversationStream;
21
21
  serviceMode: ServiceModeSignal;
22
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"m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G,IAAI,CAAC;IACtD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,MAAM,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,MAAM,EAAE,CAAC;IACxE,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,EACjB,KAAK,CAAC,EAAE,YAAY,GACnB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAoFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAkkB5F"}
package/dist/stream.js CHANGED
@@ -1,6 +1,7 @@
1
- import { acceptedMessage } from './actions.js';
1
+ import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { acceptedMessage, cursorPosition } from './actions.js';
2
3
  import { sha256Hex } from './digest.js';
3
- import { binaryFileOf, headChange, identities } from './read.js';
4
+ import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
4
5
  import { roomVersion } from './version.js';
5
6
  const HELD_FRAMES_MAX = 256;
6
7
  function turnOperation(frame) {
@@ -15,6 +16,8 @@ function listedConversation(listed) {
15
16
  created: listed.created_at,
16
17
  finished: listed.finished_at,
17
18
  outcome: listed.outcome,
19
+ waiting: listed.waiting,
20
+ newest: listed.newest === null ? null : cursorPosition(listed.newest),
18
21
  };
19
22
  }
20
23
  function position(value) {
@@ -111,7 +114,10 @@ export function houseNotifications(transport, mode) {
111
114
  event.kind === 'questions' ||
112
115
  event.kind === 'process' ||
113
116
  event.kind === 'commands' ||
114
- event.kind === 'options') {
117
+ event.kind === 'options' ||
118
+ event.kind === 'starting' ||
119
+ event.kind === 'link' ||
120
+ event.kind === 'deliveries') {
115
121
  live.add(event.conversation);
116
122
  }
117
123
  for (const observer of conversationObservers)
@@ -157,6 +163,18 @@ export function houseNotifications(transport, mode) {
157
163
  emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
158
164
  return;
159
165
  }
166
+ if (frame.type === 'starting') {
167
+ emitConversation({ kind: 'starting', conversation, step: frame.step });
168
+ return;
169
+ }
170
+ if (frame.type === 'link') {
171
+ emitConversation({ kind: 'link', conversation, connected: frame.connected });
172
+ return;
173
+ }
174
+ if (frame.type === 'deliveries') {
175
+ emitConversation({ kind: 'deliveries', conversation, unknown: [...frame.unknown] });
176
+ return;
177
+ }
160
178
  if (frame.type === 'interactions') {
161
179
  emitConversation({
162
180
  kind: 'questions',
@@ -372,15 +390,21 @@ export function houseNotifications(transport, mode) {
372
390
  frame.type === 'process' ||
373
391
  frame.type === 'commands' ||
374
392
  frame.type === 'options' ||
393
+ frame.type === 'starting' ||
394
+ frame.type === 'link' ||
395
+ frame.type === 'deliveries' ||
375
396
  frame.type === 'interactions' ||
376
397
  frame.type === 'message') {
377
398
  converse(frame);
378
399
  return;
379
400
  }
380
401
  if (frame.type === 'part')
381
- return stage(frame, via);
402
+ return ahead(() => stage(frame, via));
382
403
  if (frame.type === 'carried')
383
- return carried(frame);
404
+ return ahead(() => carried(frame));
405
+ }
406
+ function ahead(work) {
407
+ return receipts === null ? work() : receipts.ahead(work);
384
408
  }
385
409
  function publish(frame, entries) {
386
410
  const at = position(frame.position);
@@ -536,7 +560,18 @@ export function houseNotifications(transport, mode) {
536
560
  held,
537
561
  });
538
562
  },
539
- advance(tracked, from, holds) {
563
+ edited(tracked, from) {
564
+ const line = lines.get(tracked.authority);
565
+ const start = position(from.position);
566
+ if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
567
+ return [];
568
+ return [
569
+ ...new Set(line.frames
570
+ .filter((frame) => frame.position > start)
571
+ .flatMap((frame) => frame.entries.flatMap((entry) => entry.kind === 'edited' && entry.revision !== undefined ? [entry.path] : []))),
572
+ ];
573
+ },
574
+ *advance(tracked, from, holds) {
540
575
  const line = lines.get(tracked.authority);
541
576
  const start = position(from.position);
542
577
  if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
@@ -545,36 +580,26 @@ export function houseNotifications(transport, mode) {
545
580
  const first = pending[0];
546
581
  if (first === undefined || first.after > start)
547
582
  return null;
548
- const documents = {};
549
- const revisions = {};
550
- const changes = {};
551
- const binaryFiles = {};
552
- const removals = [];
553
- const applied = [];
583
+ const answer = answering();
554
584
  const schemas = new Map();
555
- const forget = (path) => {
556
- delete documents[path];
557
- delete revisions[path];
558
- delete changes[path];
559
- delete binaryFiles[path];
560
- const removed = removals.indexOf(path);
561
- if (removed !== -1)
562
- removals.splice(removed, 1);
563
- };
564
585
  for (const frame of pending) {
565
586
  for (const entry of frame.entries) {
587
+ yield ROW_WEIGHT + (entry.text?.length ?? 0);
588
+ if (entry.kind === 'folder') {
589
+ folded(answer, entry.path, entry.removed === true);
590
+ continue;
591
+ }
566
592
  if (entry.kind === 'edited' &&
567
593
  entry.revision !== undefined &&
568
594
  holds?.(entry.path, entry.revision) === true) {
569
- forget(entry.path);
595
+ forgotten(answer, entry.path);
570
596
  continue;
571
597
  }
572
- applied.push(entry);
573
- if (tracked.schemas.includes(entry.path))
598
+ if (entry.path === tracked.schema)
574
599
  schemas.set(entry.path, entry);
575
600
  if (entry.kind === 'removed') {
576
- forget(entry.path);
577
- removals.push(entry.path);
601
+ forgotten(answer, entry.path);
602
+ answer.removals.add(entry.path);
578
603
  continue;
579
604
  }
580
605
  const binary = binaryFileOf(entry);
@@ -585,32 +610,33 @@ export function houseNotifications(transport, mode) {
585
610
  const head = headChange(entry);
586
611
  if (head === null)
587
612
  return null;
588
- forget(entry.path);
613
+ forgotten(answer, entry.path);
589
614
  if (binary === undefined)
590
- documents[entry.path] = entry.text;
615
+ answer.documents.set(entry.path, entry.text);
591
616
  else
592
- binaryFiles[entry.path] = binary;
617
+ answer.binaryFiles.set(entry.path, binary);
593
618
  const revision = entry.revision ?? binary?.sha256;
594
619
  if (revision !== undefined)
595
- revisions[entry.path] = revision;
620
+ revised(answer, entry.path, revision);
596
621
  if (head !== undefined)
597
- changes[entry.path] = head;
622
+ answer.changes.set(entry.path, head);
598
623
  }
599
624
  }
600
625
  const last = pending.at(-1);
601
- lines.set(tracked.authority, { ...line, frames: pending, held: last.position });
626
+ const current = lines.get(tracked.authority);
627
+ if (current?.logEpoch === line.logEpoch) {
628
+ lines.set(tracked.authority, {
629
+ ...current,
630
+ frames: current.frames.filter((frame) => frame.position > start),
631
+ held: current.held !== null && current.held > last.position ? current.held : last.position,
632
+ });
633
+ }
602
634
  return {
603
635
  page: {
604
636
  kind: 'net-advancement',
605
637
  roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
606
- documents,
607
- revisions,
608
- ...identities(revisions),
609
- changes,
610
- binaryFiles,
611
- removals: removals.sort(),
638
+ ...(yield* answered(answer)),
612
639
  },
613
- entries: applied,
614
640
  schemas,
615
641
  };
616
642
  },