@agentshouse/mdruntime-adapter 0.1.0-cefdbbefd37e5 → 0.1.0-cf03cdc5ecb06

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 (74) hide show
  1. package/README.md +1 -1
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +34 -11
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +124 -116
  6. package/dist/authored-path.d.ts +54 -3
  7. package/dist/authored-path.d.ts.map +1 -1
  8. package/dist/authored-path.js +142 -11
  9. package/dist/chunks.d.ts +2 -3
  10. package/dist/chunks.d.ts.map +1 -1
  11. package/dist/chunks.js +72 -38
  12. package/dist/discovery.d.ts +25 -5
  13. package/dist/discovery.d.ts.map +1 -1
  14. package/dist/discovery.js +169 -21
  15. package/dist/history.d.ts.map +1 -1
  16. package/dist/history.js +3 -2
  17. package/dist/index.d.ts +7 -9
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +7 -9
  20. package/dist/model.d.ts +5 -5
  21. package/dist/model.d.ts.map +1 -1
  22. package/dist/model.js +17 -27
  23. package/dist/read.d.ts +11 -24
  24. package/dist/read.d.ts.map +1 -1
  25. package/dist/read.js +74 -47
  26. package/dist/refusal.d.ts +5 -1
  27. package/dist/refusal.d.ts.map +1 -1
  28. package/dist/refusal.js +23 -6
  29. package/dist/renamed.d.ts +10 -0
  30. package/dist/renamed.d.ts.map +1 -0
  31. package/dist/renamed.js +20 -0
  32. package/dist/room-query.d.ts +4 -0
  33. package/dist/room-query.d.ts.map +1 -0
  34. package/dist/room-query.js +63 -0
  35. package/dist/search.d.ts.map +1 -1
  36. package/dist/search.js +4 -4
  37. package/dist/session-content/check.d.ts +4 -2
  38. package/dist/session-content/index.d.ts +3 -4
  39. package/dist/session-content/parts.d.ts +16 -88
  40. package/dist/session-content/state.d.ts +21 -23
  41. package/dist/session-content/turn.d.ts +82 -258
  42. package/dist/site.d.ts.map +1 -1
  43. package/dist/site.js +56 -22
  44. package/dist/space-schema.d.ts.map +1 -1
  45. package/dist/space-schema.js +1 -8
  46. package/dist/stream.d.ts +4 -4
  47. package/dist/stream.d.ts.map +1 -1
  48. package/dist/stream.js +143 -79
  49. package/dist/transport.d.ts +68 -14
  50. package/dist/transport.d.ts.map +1 -1
  51. package/dist/transport.js +47 -9
  52. package/dist/uncertain.d.ts +5 -0
  53. package/dist/uncertain.d.ts.map +1 -0
  54. package/dist/uncertain.js +11 -0
  55. package/dist/upload.d.ts +7 -1
  56. package/dist/upload.d.ts.map +1 -1
  57. package/dist/upload.js +49 -6
  58. package/dist/write.d.ts +3 -8
  59. package/dist/write.d.ts.map +1 -1
  60. package/dist/write.js +88 -106
  61. package/package.json +4 -3
  62. package/dist/app-reference.d.ts +0 -1
  63. package/dist/app-reference.d.ts.map +0 -1
  64. package/dist/app-reference.js +0 -2
  65. package/dist/crockford.d.ts +0 -3
  66. package/dist/crockford.d.ts.map +0 -1
  67. package/dist/crockford.js +0 -3
  68. package/dist/house-model.d.ts +0 -830
  69. package/dist/house-model.d.ts.map +0 -1
  70. package/dist/house-model.js +0 -465
  71. package/dist/room-types.d.ts +0 -4
  72. package/dist/room-types.d.ts.map +0 -1
  73. package/dist/room-types.js +0 -135
  74. package/dist/session-content/bounds.d.ts +0 -7
package/dist/site.js CHANGED
@@ -1,18 +1,32 @@
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
1
2
  import { actionOutcome } from './actions.js';
2
3
  import { chunkedHead, chunkPart, siteChunkList } from './chunks.js';
3
4
  import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
4
- import { spaceSchemas } from './space-schema.js';
5
- import { discoveryFailure } from './refusal.js';
5
+ import { answeredFailure, discoveryFailure } from './refusal.js';
6
6
  import { admittedPath } from './authored-path.js';
7
- import { HOUSE_TYPED_PATHS } from './house-model.js';
8
- import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
7
+ import { siteQuery } from './room-query.js';
9
8
  import { houseNotifications } from './stream.js';
10
- import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITES_SUBMISSIONS_CREATE, } from './transport.js';
9
+ import { houseSiteRoute, SITE_DOOR_ACTS, SITE_DOOR_TOOL, SITE_FILES, } from './transport.js';
10
+ import { UNANSWERED, unusable } from './uncertain.js';
11
11
  import { followsVersion, reachedVersion, roomVersion } from './version.js';
12
- const UNCERTAIN = { kind: 'transport-uncertainty' };
12
+ function siteDoorRequest(request) {
13
+ const { op, ...input } = (request.input ?? {});
14
+ if (request.name !== SITE_DOOR_TOOL || typeof op !== 'string')
15
+ return request;
16
+ const named = Object.entries(SITE_DOOR_ACTS).find(([, act]) => act.op === op);
17
+ return named === undefined ? request : { ...request, name: named[0], input };
18
+ }
13
19
  function unfound() {
14
20
  return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
15
21
  }
22
+ function siteCopies(copies) {
23
+ if (copies === null || copies === undefined)
24
+ return [];
25
+ return copies.split(', ').map((offered) => {
26
+ const [url = '', width = ''] = offered.split(' ');
27
+ return { url, width: Number.parseInt(width, 10) };
28
+ });
29
+ }
16
30
  function siteRoom(tracked) {
17
31
  return {
18
32
  name: tracked.handle,
@@ -27,14 +41,13 @@ function siteRoom(tracked) {
27
41
  };
28
42
  }
29
43
  export function createSiteAdapter(transport, snapshot = false) {
30
- const spaces = spaceSchemas();
31
44
  const notifications = houseNotifications(transport, 'site', {
32
45
  opened: async () => {
33
46
  const found = await discovered();
34
47
  return found.kind === 'discovery' ? found : null;
35
48
  },
36
49
  changed: () => null,
37
- }, spaces);
50
+ });
38
51
  const tracked = new Map();
39
52
  const chunked = new Map();
40
53
  function fileRoute(request) {
@@ -48,7 +61,7 @@ export function createSiteAdapter(transport, snapshot = false) {
48
61
  const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
49
62
  if ('kind' in listed)
50
63
  return listed;
51
- const head = await chunkedHead(listed, entry, spaces);
64
+ const head = await chunkedHead(listed, entry);
52
65
  if (head.kind === 'bootstrap')
53
66
  chunked.set(entry.locator, listed);
54
67
  return head;
@@ -57,10 +70,10 @@ export function createSiteAdapter(transport, snapshot = false) {
57
70
  const room = chunked.get(entry.locator);
58
71
  const address = room?.chunks.get(id);
59
72
  if (room === undefined || address === undefined)
60
- return UNCERTAIN;
73
+ return UNANSWERED;
61
74
  const read = await transport.download(address.url);
62
75
  if (read.status !== 200)
63
- return UNCERTAIN;
76
+ return answeredFailure(read.status, null);
64
77
  return chunkPart(read.body, room, id, arriving);
65
78
  }
66
79
  async function discovered() {
@@ -70,18 +83,24 @@ export function createSiteAdapter(transport, snapshot = false) {
70
83
  return failed;
71
84
  const document = parseSiteDiscovery(answer.body);
72
85
  if (document === null)
73
- return UNCERTAIN;
86
+ return unusable();
74
87
  const entries = siteTracked(document);
75
88
  tracked.clear();
76
89
  for (const entry of entries)
77
90
  tracked.set(entry.locator, entry);
78
91
  notifications.track(entries);
79
- return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
92
+ return {
93
+ ...mapDiscovery(document, entries.map(siteRoom), siteCapabilities()),
94
+ queriesOnly: document.queriesOnly.map(({ roomRef, roomHandle }) => ({
95
+ locator: roomRef,
96
+ handle: roomHandle,
97
+ name: roomHandle,
98
+ })),
99
+ };
80
100
  }
81
101
  return {
82
102
  localSaves: true,
83
103
  roomTypes: HOUSE_ROOM_TYPES,
84
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
85
104
  typedPaths: HOUSE_TYPED_PATHS,
86
105
  pathRule: admittedPath,
87
106
  async authorize() {
@@ -103,7 +122,7 @@ export function createSiteAdapter(transport, snapshot = false) {
103
122
  if (entry === undefined)
104
123
  return { kind: 'room-not-readable', locator: request.locator };
105
124
  if (request.pageToken !== undefined)
106
- return UNCERTAIN;
125
+ return UNANSWERED;
107
126
  return request.fromRoomVersion === roomVersion(entry)
108
127
  ? { kind: 'still-current' }
109
128
  : { kind: 'beyond-horizon' };
@@ -119,6 +138,7 @@ export function createSiteAdapter(transport, snapshot = false) {
119
138
  async history() {
120
139
  return { kind: 'no-history' };
121
140
  },
141
+ queryHouse: (_authorization, request) => siteQuery(transport, request),
122
142
  async binary(_authorization, request) {
123
143
  const route = fileRoute(request);
124
144
  if (typeof route !== 'string')
@@ -126,11 +146,21 @@ export function createSiteAdapter(transport, snapshot = false) {
126
146
  const read = await transport.download(route);
127
147
  if (read.status === 404)
128
148
  return unfound();
129
- return read.status === 200 && read.body !== null
130
- ? { kind: 'binary', body: read.body, mediaType: read.mediaType }
131
- : UNCERTAIN;
149
+ if (read.status !== 200)
150
+ return answeredFailure(read.status, null);
151
+ if (read.body === null)
152
+ return unusable();
153
+ return {
154
+ kind: 'binary',
155
+ body: read.body,
156
+ mediaType: read.mediaType,
157
+ url: route,
158
+ copies: siteCopies(read.copies),
159
+ };
132
160
  },
133
161
  async link(_authorization, request) {
162
+ if (request.kind === 'key')
163
+ return unfound();
134
164
  const route = fileRoute(request);
135
165
  if (typeof route !== 'string')
136
166
  return route;
@@ -146,8 +176,12 @@ export function createSiteAdapter(transport, snapshot = false) {
146
176
  follows(_locator, version, next) {
147
177
  return followsVersion(version, next);
148
178
  },
149
- async action(_authorization, request) {
150
- if (request.name !== SITES_SUBMISSIONS_CREATE) {
179
+ async action(_authorization, asked) {
180
+ const request = siteDoorRequest(asked);
181
+ const route = Object.hasOwn(SITE_DOOR_ACTS, request.name)
182
+ ? SITE_DOOR_ACTS[request.name].route
183
+ : null;
184
+ if (route === null) {
151
185
  return {
152
186
  kind: 'rejected',
153
187
  code: 'action-unimplemented',
@@ -156,8 +190,8 @@ export function createSiteAdapter(transport, snapshot = false) {
156
190
  };
157
191
  }
158
192
  if (!transport.online())
159
- return UNCERTAIN;
160
- return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITES_SUBMISSIONS_CREATE, request.input);
193
+ return UNANSWERED;
194
+ return actionOutcome(await transport.door(route, request.input), request.name, request.input);
161
195
  },
162
196
  roomStream: snapshot
163
197
  ? undefined
@@ -1 +1 @@
1
- {"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAY3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
1
+ {"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAO3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -1,16 +1,9 @@
1
- const HELD_TEXTS = 16;
2
1
  export function spaceSchemas() {
3
2
  const texts = new Map();
4
3
  const key = (space, revision) => `${space} ${revision}`;
5
4
  return {
6
5
  held: (space, revision) => texts.get(key(space, revision)),
7
- keep(space, revision, text) {
8
- const named = key(space, revision);
9
- texts.delete(named);
10
- texts.set(named, text);
11
- if (texts.size > HELD_TEXTS)
12
- texts.delete(texts.keys().next().value);
13
- },
6
+ keep: (space, revision, text) => void texts.set(key(space, revision), text),
14
7
  };
15
8
  }
16
9
  export function spaceIdentity(space) {
package/dist/stream.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { type AuthorityChange, type Discovery, type ConversationStream, type HeldRoom, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
1
+ import { type AuthorityChange, type Discovery, type ConversationStream, type HeldRoom, type RoomStreamEvent, type RunStream, type ServiceModeSignal } from '@agentshouse/mdruntime';
2
2
  import type { TrackedAuthority } from './discovery.js';
3
- import type { SpaceSchemas } from './space-schema.js';
4
3
  import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
5
4
  export type HouseOpeningFrame = Extract<HouseStreamFrame, {
6
5
  type: 'opening';
@@ -11,7 +10,7 @@ export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
11
10
  export type HouseDiscovering = {
12
11
  opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
13
12
  changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
14
- expired?(authorities: readonly string[]): void;
13
+ expired?(entries: readonly TrackedAuthority[]): void;
15
14
  };
16
15
  export type HouseNotifications = {
17
16
  runtime: string;
@@ -19,6 +18,7 @@ export type HouseNotifications = {
19
18
  send(rooms: readonly HeldRoom[]): void;
20
19
  track(authorities: readonly TrackedAuthority[]): void;
21
20
  conversations: ConversationStream;
21
+ runs: RunStream;
22
22
  serviceMode: ServiceModeSignal;
23
23
  };
24
- export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering, spaces: SpaceSchemas): HouseNotifications;
24
+ export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,QAAQ,EAGb,K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,EAAE,GAAG,IAAI,CAAC;IACtD,aAAa,EAAE,kBAAkB,CAAC;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAiHF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CA2apB"}
package/dist/stream.js CHANGED
@@ -1,41 +1,66 @@
1
+ import { parse } from '@agentshouse/mdmodel';
1
2
  import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
2
3
  import { acceptedMessage, changeCursor, houseHistory } from './history.js';
3
- import { keptSpaceSchemas, streamedModels } from './model.js';
4
- import { answered, answering, binaryFileOf, createdOf, folded, forgotten, headChange, revised, } from './read.js';
5
- import { classifyDoor } from './refusal.js';
6
- import { houseDoorRoute, } from './transport.js';
4
+ import { spaceSchemaTexts, streamedModels } from './model.js';
5
+ import { spaceSchemas } from './space-schema.js';
6
+ import { answered, answering, documentEntry, folded, forgotten, kept, } from './read.js';
7
7
  import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
8
+ const CURRENT_RUN_STATES = new Set(['awaiting_approval', 'started']);
9
+ const NO_RUN_MARKS = { rooms: {}, sent: null };
10
+ function heardRun(request) {
11
+ const read = parse(`---\n${request.document}---\n`);
12
+ if (!read.ok)
13
+ throw new Error(`the stream carried request ${request.name} as no document`);
14
+ const fields = read.document.fields;
15
+ return {
16
+ room: request.room_ref,
17
+ name: request.name,
18
+ document: request.document,
19
+ current: CURRENT_RUN_STATES.has(fields.state),
20
+ starter: typeof fields.requester === 'string' ? fields.requester : null,
21
+ };
22
+ }
8
23
  function turnOperation(frame) {
9
24
  return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
10
25
  }
11
- async function houseAgents(transport) {
12
- const answer = await transport.door(houseDoorRoute('agents/list'), {});
13
- if (classifyDoor(answer.status, answer.body, 'agents/list')?.kind === 'transport-uncertainty') {
14
- throw new Error();
15
- }
16
- const agents = answer.status === 200 ? answer.body?.agents : null;
17
- if (!Array.isArray(agents))
18
- return null;
19
- return agents.flatMap((one) => {
20
- const { id, name, retired_at: retired } = (one ?? {});
21
- return typeof id === 'string' && typeof name === 'string'
22
- ? [{ agent: id, name, retired: retired !== null && retired !== undefined }]
23
- : [];
24
- });
26
+ function listedAgent(agent) {
27
+ return {
28
+ id: agent.id,
29
+ name: agent.name,
30
+ revision: agent.revision,
31
+ environment: agent.environment,
32
+ environment_name: agent.environment_name,
33
+ environment_connected: agent.environment_connected,
34
+ launch_directory: agent.launch_directory,
35
+ cli: agent.cli,
36
+ model: agent.model,
37
+ effort: agent.effort,
38
+ model_fixed: agent.model_fixed,
39
+ mode: agent.mode,
40
+ base_instructions: agent.base_instructions,
41
+ compaction_threshold: agent.compaction_threshold,
42
+ compaction_words: agent.compaction_words,
43
+ in_telegram: agent.in_telegram,
44
+ telegram_messages: agent.telegram_messages,
45
+ created: agent.created,
46
+ retired_at: agent.retired_at,
47
+ };
25
48
  }
26
49
  function listedConversation(listed) {
27
50
  return {
28
51
  conversation: listed.conversation_id,
29
52
  agent: listed.agent_id,
30
- agentName: listed.agent_name,
31
- agentRetired: listed.agent_retired,
32
53
  name: listed.name,
33
54
  created: listed.created_at,
34
- finished: listed.finished_at,
35
55
  outcome: listed.outcome,
36
56
  waiting: listed.waiting,
37
57
  newest: listed.newest === null ? null : changeCursor(listed.newest),
38
58
  processEnded: listed.process_ended_at,
59
+ activity: listed.activity,
60
+ subject: listed.subject,
61
+ room: listed.room_ref,
62
+ model: listed.model,
63
+ effort: listed.effort,
39
64
  };
40
65
  }
41
66
  function position(value) {
@@ -43,61 +68,55 @@ function position(value) {
43
68
  return null;
44
69
  return BigInt(value);
45
70
  }
46
- function* changed(tracked, entries, version, schemas) {
71
+ function* changed(tracked, entries, version, mode, schemas) {
47
72
  const answer = answering();
48
73
  for (const entry of entries) {
49
- yield ROW_WEIGHT + (entry.text?.length ?? 0);
74
+ yield ROW_WEIGHT + (entry.content?.length ?? 0);
50
75
  if (entry.kind === 'folder') {
51
76
  folded(answer, entry.path, entry.removed === true);
52
77
  continue;
53
78
  }
54
- if (entry.path === tracked.schema)
55
- schemas.set(entry.path, entry);
56
- forgotten(answer, entry.path);
57
- if (entry.space !== undefined) {
58
- answer.removals.add(entry.path);
59
- continue;
60
- }
61
79
  if (entry.kind === 'removed') {
80
+ if (entry.path === tracked.schema)
81
+ schemas.set(entry.path, null);
82
+ forgotten(answer, entry.path);
62
83
  answer.removals.add(entry.path);
63
84
  continue;
64
85
  }
65
- const binary = binaryFileOf(entry);
66
- if (binary === undefined)
67
- answer.documents.set(entry.path, entry.text ?? '');
68
- else if (binary !== null)
69
- answer.binaryFiles.set(entry.path, binary);
70
- if (binary === undefined && entry.facts !== undefined)
71
- answer.facts.set(entry.path, entry.facts);
72
- const revision = entry.revision ?? binary?.sha256;
73
- if (revision !== undefined)
74
- revised(answer, entry.path, revision);
75
- const head = headChange(entry);
76
- if (head)
77
- answer.changes.set(entry.path, head);
78
- const created = createdOf(entry);
79
- if (created)
80
- answer.created.set(entry.path, created);
86
+ const file = documentEntry(entry, mode);
87
+ if (file === null)
88
+ throw new Error(`the stream carried ${entry.path} as no file`);
89
+ if (entry.path === tracked.schema)
90
+ schemas.set(entry.path, file);
91
+ forgotten(answer, file.path);
92
+ if (file.space === undefined)
93
+ kept(answer, file);
94
+ else
95
+ answer.removals.add(file.path);
81
96
  }
82
97
  return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
83
98
  }
84
- async function changePage(tracked, entries, version, mode, spaces, whole) {
99
+ async function changePage(tracked, entries, version, mode, whole) {
85
100
  const schemas = new Map();
86
- const page = await stepped(changed(tracked, entries, version, schemas));
87
- const models = await streamedModels(schemas, tracked, mode, spaces, whole);
101
+ const page = await stepped(changed(tracked, entries, version, mode, schemas));
102
+ const models = await streamedModels(schemas, tracked, whole);
88
103
  return models === undefined ? page : { ...page, models };
89
104
  }
90
- export function houseNotifications(transport, mode, discovering, spaces) {
105
+ export function houseNotifications(transport, mode, discovering) {
91
106
  const stream = transport.stream;
92
107
  const staged = new Map();
108
+ let spaces = spaceSchemas();
93
109
  let socket = null;
94
110
  const tracking = new Map();
111
+ const located = new Map();
95
112
  const observers = new Set();
96
113
  const replaying = new Map();
97
114
  const conversationObservers = new Set();
115
+ const runObservers = new Set();
98
116
  const modeObservers = new Set();
99
117
  let replicated = [];
100
118
  let listedCursor = null;
119
+ let runMarks = NO_RUN_MARKS;
101
120
  const unanswered = [];
102
121
  const heldAtZero = new Set();
103
122
  const live = new Set();
@@ -113,6 +132,10 @@ export function houseNotifications(transport, mode, discovering, spaces) {
113
132
  held.push(event);
114
133
  }
115
134
  }
135
+ function emitRun(event) {
136
+ for (const observer of runObservers)
137
+ observer(event);
138
+ }
116
139
  function emitConversation(event) {
117
140
  if (event.kind === 'turn' ||
118
141
  event.kind === 'questions' ||
@@ -121,7 +144,6 @@ export function houseNotifications(transport, mode, discovering, spaces) {
121
144
  event.kind === 'options' ||
122
145
  event.kind === 'starting' ||
123
146
  event.kind === 'state' ||
124
- event.kind === 'link' ||
125
147
  event.kind === 'deliveries') {
126
148
  live.add(event.conversation);
127
149
  }
@@ -133,6 +155,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
133
155
  announced = null;
134
156
  socket = next;
135
157
  staged.clear();
158
+ spaces = spaceSchemas();
136
159
  unanswered.length = 0;
137
160
  heldAtZero.clear();
138
161
  const gapped = new Set([...replicated, ...live]);
@@ -153,9 +176,9 @@ export function houseNotifications(transport, mode, discovering, spaces) {
153
176
  }
154
177
  announced = { kind: 'discovered', discovery };
155
178
  emit(announced);
156
- }, () => {
179
+ }, (failure) => {
157
180
  if (socket === via)
158
- via.close();
181
+ via.close(failure);
159
182
  });
160
183
  }
161
184
  function converse(frame) {
@@ -198,10 +221,6 @@ export function houseNotifications(transport, mode, discovering, spaces) {
198
221
  emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
199
222
  return;
200
223
  }
201
- if (frame.type === 'link') {
202
- emitConversation({ kind: 'link', conversation, connected: frame.connected });
203
- return;
204
- }
205
224
  if (frame.type === 'deliveries') {
206
225
  emitConversation({
207
226
  kind: 'deliveries',
@@ -225,6 +244,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
225
244
  emitConversation({ kind: 'accepted-message', conversation, message });
226
245
  }
227
246
  function stage(frame, via) {
247
+ const entries = spaceSchemaTexts(frame.entries, spaces);
228
248
  const held = staged.get(frame.carry);
229
249
  if (frame.index !== (held?.parts ?? 0)) {
230
250
  staged.delete(frame.carry);
@@ -237,8 +257,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
237
257
  }
238
258
  }
239
259
  const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
240
- keptSpaceSchemas(frame.entries, spaces);
241
- next.entries.push(...frame.entries);
260
+ next.entries.push(...entries);
242
261
  next.parts += 1;
243
262
  staged.set(frame.carry, next);
244
263
  via?.received(frame.authority, frame.carry, frame.index);
@@ -265,13 +284,39 @@ export function houseNotifications(transport, mode, discovering, spaces) {
265
284
  return;
266
285
  }
267
286
  if (frame.type === 'caught_up') {
268
- discovering.expired?.(frame.expired);
287
+ const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
288
+ discovering.expired?.(expired);
269
289
  emit({
270
290
  kind: 'caught-up',
271
- expired: [
272
- ...frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
273
- ...(unanswered.shift() ?? []),
274
- ],
291
+ expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
292
+ });
293
+ return;
294
+ }
295
+ if (frame.type === 'report') {
296
+ emit({ kind: 'reported' });
297
+ return;
298
+ }
299
+ if (frame.type === 'request') {
300
+ const room = frame.request.room_ref;
301
+ emitRun({
302
+ kind: 'run',
303
+ run: heardRun(frame.request),
304
+ listing: tracking.has(room) ? room : null,
305
+ });
306
+ return;
307
+ }
308
+ if (frame.type === 'request_removed') {
309
+ emitRun({ kind: 'removed', room: frame.room_ref, name: frame.request });
310
+ return;
311
+ }
312
+ if (frame.type === 'requests') {
313
+ emitRun({
314
+ kind: 'runs',
315
+ listing: frame.room_ref,
316
+ runs: frame.requests.map(heardRun),
317
+ whole: frame.whole,
318
+ more: frame.more,
319
+ mark: frame.cursor,
275
320
  });
276
321
  return;
277
322
  }
@@ -284,6 +329,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
284
329
  if (frame.type === 'conversations') {
285
330
  emitConversation({
286
331
  kind: 'list',
332
+ agents: frame.agents.map(listedAgent),
287
333
  entries: frame.conversations.map(listedConversation),
288
334
  whole: frame.whole,
289
335
  more: frame.more,
@@ -295,6 +341,10 @@ export function houseNotifications(transport, mode, discovering, spaces) {
295
341
  emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
296
342
  return;
297
343
  }
344
+ if (frame.type === 'agent') {
345
+ emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
346
+ return;
347
+ }
298
348
  if (frame.type === 'conversation_deleted') {
299
349
  emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
300
350
  return;
@@ -305,7 +355,6 @@ export function houseNotifications(transport, mode, discovering, spaces) {
305
355
  frame.type === 'options' ||
306
356
  frame.type === 'starting' ||
307
357
  frame.type === 'state' ||
308
- frame.type === 'link' ||
309
358
  frame.type === 'deliveries' ||
310
359
  frame.type === 'interactions' ||
311
360
  frame.type === 'message') {
@@ -332,7 +381,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
332
381
  locator: tracked.locator,
333
382
  from,
334
383
  roomVersion: version,
335
- read: () => changePage(tracked, entries, version, mode, spaces, from === null),
384
+ read: () => changePage(tracked, entries, version, mode, from === null),
336
385
  });
337
386
  }
338
387
  }
@@ -343,6 +392,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
343
392
  announced = null;
344
393
  socket = null;
345
394
  staged.clear();
395
+ spaces = spaceSchemas();
346
396
  unanswered.length = 0;
347
397
  heldAtZero.clear();
348
398
  emit({ kind: 'closed', revoked, lost, authorityChanged });
@@ -370,12 +420,18 @@ export function houseNotifications(transport, mode, discovering, spaces) {
370
420
  conversationObservers.delete(notify);
371
421
  };
372
422
  },
373
- ...(mode === 'credential'
374
- ? {
375
- agents: () => houseAgents(transport),
376
- history: (request) => houseHistory(transport, request),
377
- }
378
- : {}),
423
+ ...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
424
+ },
425
+ runs: {
426
+ hold(marks) {
427
+ runMarks = marks;
428
+ },
429
+ observe(notify) {
430
+ runObservers.add(notify);
431
+ return () => {
432
+ runObservers.delete(notify);
433
+ };
434
+ },
379
435
  },
380
436
  observe(notify) {
381
437
  observers.add(notify);
@@ -400,14 +456,13 @@ export function houseNotifications(transport, mode, discovering, spaces) {
400
456
  announced = null;
401
457
  if (socket === null)
402
458
  return;
403
- const entries = new Map([...tracking.values()].flat().map((tracked) => [tracked.locator, tracked]));
404
459
  const named = rooms.flatMap((room) => {
405
- const entry = entries.get(room.locator);
460
+ const entry = located.get(room.locator);
406
461
  const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
407
462
  return entry === undefined || at === null ? [] : [{ entry, at }];
408
463
  });
409
464
  const unheld = rooms.flatMap((room) => {
410
- const entry = entries.get(room.locator);
465
+ const entry = located.get(room.locator);
411
466
  return entry === undefined || room.roomVersion !== null ? [] : [entry];
412
467
  });
413
468
  for (const { entry, at } of named) {
@@ -420,10 +475,14 @@ export function houseNotifications(transport, mode, discovering, spaces) {
420
475
  heldAtZero.delete(entry.authority);
421
476
  const site = mode === 'site';
422
477
  unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
478
+ const marked = (held) => {
479
+ const mark = runMarks.rooms[held.authority];
480
+ return mark === undefined ? held : { ...held, requests: mark };
481
+ };
423
482
  socket.hold([
424
- ...named.map(({ entry, at }) => presented(entry.authority, at)),
425
- ...(site ? [] : unheld).map((entry) => presented(entry.authority, { position: '0', logEpoch: entry.logEpoch })),
426
- ], runtime, listedCursor);
483
+ ...named.map(({ entry, at }) => marked(presented(entry.authority, at))),
484
+ ...(site ? [] : unheld).map((entry) => marked(presented(entry.authority, { position: '0', logEpoch: entry.logEpoch }))),
485
+ ], runtime, listedCursor, runMarks.sent ?? undefined);
427
486
  if (site)
428
487
  return;
429
488
  const made = unheld.filter((entry) => entry.position === '0');
@@ -435,16 +494,21 @@ export function houseNotifications(transport, mode, discovering, spaces) {
435
494
  locator: entry.locator,
436
495
  from: null,
437
496
  roomVersion: version,
438
- read: () => changePage(entry, [], version, mode, spaces, true),
497
+ read: () => changePage(entry, [], version, mode, true),
439
498
  });
440
499
  }
441
500
  });
442
501
  },
443
502
  track(entries) {
444
503
  tracking.clear();
504
+ located.clear();
445
505
  for (const entry of entries) {
446
506
  tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
447
507
  }
508
+ for (const held of tracking.values()) {
509
+ for (const entry of held)
510
+ located.set(entry.locator, entry);
511
+ }
448
512
  for (const [carry, held] of staged) {
449
513
  if (!tracking.has(held.authority))
450
514
  staged.delete(carry);