@agentshouse/mdruntime 0.1.0-cd26b960b7262 → 0.1.0-cd35ccee27a19

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 (153) hide show
  1. package/dist/acceptance.d.ts +0 -3
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +58 -135
  4. package/dist/actions.js +5 -5
  5. package/dist/adapter.d.ts +26 -45
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/bootstrap.d.ts +1 -1
  8. package/dist/bootstrap.d.ts.map +1 -1
  9. package/dist/bootstrap.js +6 -19
  10. package/dist/change-set.d.ts +4 -0
  11. package/dist/change-set.d.ts.map +1 -1
  12. package/dist/change-set.js +6 -0
  13. package/dist/client.d.ts +4 -11
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +21 -8
  16. package/dist/collection.d.ts +22 -4
  17. package/dist/collection.d.ts.map +1 -1
  18. package/dist/collection.js +12 -2
  19. package/dist/connection.d.ts.map +1 -1
  20. package/dist/connection.js +17 -13
  21. package/dist/conversation-live.d.ts +5 -5
  22. package/dist/conversation-live.d.ts.map +1 -1
  23. package/dist/conversation-live.js +7 -6
  24. package/dist/conversation.d.ts +18 -6
  25. package/dist/conversation.d.ts.map +1 -1
  26. package/dist/conversation.js +115 -82
  27. package/dist/declaration.d.ts +10 -0
  28. package/dist/declaration.d.ts.map +1 -0
  29. package/dist/declaration.js +24 -0
  30. package/dist/discovery.d.ts.map +1 -1
  31. package/dist/discovery.js +11 -38
  32. package/dist/failure.d.ts +1 -0
  33. package/dist/failure.d.ts.map +1 -1
  34. package/dist/failure.js +3 -0
  35. package/dist/host.d.ts +17 -2
  36. package/dist/host.d.ts.map +1 -1
  37. package/dist/host.js +34 -4
  38. package/dist/index.d.ts +6 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +4 -2
  41. package/dist/install.d.ts +0 -2
  42. package/dist/install.d.ts.map +1 -1
  43. package/dist/install.js +47 -63
  44. package/dist/lifecycle.d.ts +1 -1
  45. package/dist/lifecycle.d.ts.map +1 -1
  46. package/dist/lifecycle.js +28 -24
  47. package/dist/listing.d.ts +6 -11
  48. package/dist/listing.d.ts.map +1 -1
  49. package/dist/listing.js +25 -62
  50. package/dist/live.d.ts.map +1 -1
  51. package/dist/live.js +3 -1
  52. package/dist/locks.d.ts +2 -4
  53. package/dist/locks.d.ts.map +1 -1
  54. package/dist/locks.js +10 -38
  55. package/dist/lost.d.ts.map +1 -1
  56. package/dist/lost.js +10 -21
  57. package/dist/memory.d.ts +4 -2
  58. package/dist/memory.d.ts.map +1 -1
  59. package/dist/memory.js +22 -9
  60. package/dist/messages.d.ts +0 -3
  61. package/dist/messages.d.ts.map +1 -1
  62. package/dist/messages.js +5 -17
  63. package/dist/model.d.ts +0 -1
  64. package/dist/model.d.ts.map +1 -1
  65. package/dist/model.js +0 -5
  66. package/dist/models.d.ts +4 -8
  67. package/dist/models.d.ts.map +1 -1
  68. package/dist/models.js +97 -136
  69. package/dist/opened.d.ts +1 -1
  70. package/dist/opened.d.ts.map +1 -1
  71. package/dist/opened.js +2 -2
  72. package/dist/opening.d.ts.map +1 -1
  73. package/dist/opening.js +6 -4
  74. package/dist/overlay.d.ts +2 -1
  75. package/dist/overlay.d.ts.map +1 -1
  76. package/dist/overlay.js +32 -21
  77. package/dist/page-metadata.d.ts +8 -0
  78. package/dist/page-metadata.d.ts.map +1 -0
  79. package/dist/page-metadata.js +19 -0
  80. package/dist/parts.d.ts +3 -52
  81. package/dist/parts.d.ts.map +1 -1
  82. package/dist/parts.js +15 -120
  83. package/dist/preparation.d.ts.map +1 -1
  84. package/dist/preparation.js +20 -13
  85. package/dist/presence.d.ts +52 -0
  86. package/dist/presence.d.ts.map +1 -0
  87. package/dist/presence.js +220 -0
  88. package/dist/queries.d.ts.map +1 -1
  89. package/dist/queries.js +4 -6
  90. package/dist/queue.d.ts +40 -0
  91. package/dist/queue.d.ts.map +1 -0
  92. package/dist/queue.js +455 -0
  93. package/dist/reach.d.ts.map +1 -1
  94. package/dist/reach.js +23 -4
  95. package/dist/reads.d.ts.map +1 -1
  96. package/dist/reads.js +4 -1
  97. package/dist/refresh.js +2 -2
  98. package/dist/refusal.d.ts.map +1 -1
  99. package/dist/refusal.js +5 -3
  100. package/dist/replica.d.ts +5 -11
  101. package/dist/replica.d.ts.map +1 -1
  102. package/dist/replica.js +12 -14
  103. package/dist/room-draft.d.ts +3 -3
  104. package/dist/room-draft.d.ts.map +1 -1
  105. package/dist/room-draft.js +33 -49
  106. package/dist/room-drafts.js +3 -3
  107. package/dist/rows.d.ts.map +1 -1
  108. package/dist/rows.js +3 -4
  109. package/dist/runtime.d.ts +7 -16
  110. package/dist/runtime.d.ts.map +1 -1
  111. package/dist/save.d.ts +41 -90
  112. package/dist/save.d.ts.map +1 -1
  113. package/dist/save.js +220 -110
  114. package/dist/saves.d.ts +2 -40
  115. package/dist/saves.d.ts.map +1 -1
  116. package/dist/saves.js +106 -698
  117. package/dist/seed.js +2 -2
  118. package/dist/shown.d.ts +4 -3
  119. package/dist/shown.d.ts.map +1 -1
  120. package/dist/shown.js +24 -26
  121. package/dist/socket.d.ts +0 -3
  122. package/dist/socket.d.ts.map +1 -1
  123. package/dist/socket.js +0 -5
  124. package/dist/store/records.d.ts +2 -2
  125. package/dist/store/records.d.ts.map +1 -1
  126. package/dist/store/records.js +2 -3
  127. package/dist/store.d.ts +8 -5
  128. package/dist/store.d.ts.map +1 -1
  129. package/dist/store.js +32 -12
  130. package/dist/stored.d.ts.map +1 -1
  131. package/dist/stored.js +3 -3
  132. package/dist/surface.d.ts.map +1 -1
  133. package/dist/surface.js +8 -8
  134. package/dist/sync.d.ts.map +1 -1
  135. package/dist/sync.js +55 -66
  136. package/dist/tables.d.ts +0 -4
  137. package/dist/tables.d.ts.map +1 -1
  138. package/dist/tables.js +1 -4
  139. package/dist/validation.d.ts.map +1 -1
  140. package/dist/validation.js +2 -2
  141. package/dist/wire.d.ts +40 -4
  142. package/dist/wire.d.ts.map +1 -1
  143. package/dist/wire.js +12 -3
  144. package/package.json +3 -2
  145. package/dist/job.d.ts +0 -33
  146. package/dist/job.d.ts.map +0 -1
  147. package/dist/job.js +0 -54
  148. package/dist/socket/rooms.d.ts +0 -44
  149. package/dist/socket/rooms.d.ts.map +0 -1
  150. package/dist/socket/rooms.js +0 -90
  151. package/dist/store/fences.d.ts +0 -16
  152. package/dist/store/fences.d.ts.map +0 -1
  153. package/dist/store/fences.js +0 -26
@@ -1,10 +1,11 @@
1
- import type { ConversationEvent, ConversationMessage, ProcessCommand, RunningSubagent, SessionOption, TurnContext } from './adapter.js';
1
+ import { type Part, type SessionState } from '@agentshouse/session-content';
2
+ import type { AgentEnvironment, ConversationEvent, ConversationMessage, ProcessCommand, SessionOption } from './adapter.js';
2
3
  import { type ChangeSet } from './change-set.js';
3
4
  import { type LiveConversations } from './conversation-live.js';
4
5
  import { type ConversationHeld } from './conversation-row.js';
5
- import type { OpenJob } from './job.js';
6
6
  import type { Open } from './open.js';
7
7
  import { type CallResult, type Offline } from './outcome.js';
8
+ import type { ChatRequest } from './source.js';
8
9
  import type { CycleProgress } from './status.js';
9
10
  import type { RuntimeStore } from './store.js';
10
11
  export type ConversationState = Open<'working' | 'asking' | 'idle'>;
@@ -29,12 +30,13 @@ export type ConversationEntry = ConversationHeld & {
29
30
  export type ConversationAgent = {
30
31
  identity: string;
31
32
  name: string;
33
+ cli?: string;
34
+ environment?: AgentEnvironment;
32
35
  };
33
36
  export type RunningTurn = {
34
37
  turn: string;
35
38
  started: string | null;
36
- parts: readonly unknown[];
37
- context: TurnContext | null;
39
+ parts: readonly Part[];
38
40
  };
39
41
  export type ChatDraft = {
40
42
  text: string;
@@ -61,16 +63,17 @@ export type ConversationView = {
61
63
  commands: readonly ProcessCommand[];
62
64
  options: readonly SessionOption[];
63
65
  starting: string | null;
64
- subagents: readonly RunningSubagent[];
66
+ state: SessionState | null;
65
67
  link: {
66
68
  connected: boolean;
67
69
  } | null;
70
+ deliveryWaiting: readonly string[];
68
71
  deliveryUnknown: readonly string[];
69
72
  chatDraft: (ChatDraft & {
70
73
  readonly revision: string;
71
74
  }) | null;
72
- jobs: readonly OpenJob[];
73
75
  };
76
+ export type RequestDecision = 'approve' | 'decline';
74
77
  export type ConversationSurface = {
75
78
  list(): Promise<readonly ConversationEntry[]>;
76
79
  read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
@@ -80,6 +83,15 @@ export type ConversationSurface = {
80
83
  interrupt(conversation: string): Promise<CallResult>;
81
84
  kill(conversation: string): Promise<CallResult>;
82
85
  delete(conversation: string): Promise<CallResult>;
86
+ takeOut(conversation: string, message: string, operation: string): Promise<CallResult>;
87
+ decide(request: ChatRequest, decision: RequestDecision, operation: string): Promise<CallResult>;
88
+ rename(conversation: string, name: string, operation: string): Promise<CallResult>;
89
+ option(conversation: string, option: string, value: string | boolean, operation: string): Promise<CallResult>;
90
+ retry(conversation: string, message: string, operation: string): Promise<CallResult>;
91
+ pins(): Promise<readonly string[]>;
92
+ pin(figures: readonly string[]): Promise<void>;
93
+ openedTurns(): Promise<Readonly<Record<string, string>>>;
94
+ openTurn(conversation: string, turn: string): Promise<void>;
83
95
  };
84
96
  export type ConversationAnswer = {
85
97
  interaction_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,iBAAiB,EAEjB,mBAAmB,EAEnB,cAAc,EACd,eAAe,EACf,aAAa,EACb,WAAW,EAEZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAIL,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzE,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,UAAU,CAAC;AACnD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,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,iBAyB3F;AAED,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,iBAuB1F;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,iBAAiB,EACxB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GACxC,MAAM,IAAI,CAkCZ;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GACvD,MAAM,IAAI,CAIZ;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GACtD,MAAM,IAAI,CAKZ;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI,CAEnF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,GAAG,IAAI,CA0BjG"}
@@ -1,12 +1,14 @@
1
1
  import { cursorOf, decodedCursor } from '@agentshouse/mdmodel';
2
+ import { applied, isTurn, standingState, } from '@agentshouse/session-content';
2
3
  import { conversationChangeSet } from './change-set.js';
3
4
  import { FACTS, QUIET, } from './conversation-live.js';
4
5
  import { heldFacts } from './conversation-row.js';
5
- import { runtimeError } from './failure.js';
6
+ import { runtimeError, uncaught } from './failure.js';
6
7
  import { refusedForSpace } from './durability.js';
7
8
  import { changeBatchIdentity, chatDraftRevision } from './identity.js';
8
9
  import { OFFLINE } from './outcome.js';
9
- import { jobsOf, runningLine } from './parts.js';
10
+ import { runningLine } from './parts.js';
11
+ import { record, text } from './read.js';
10
12
  import { openQuestion, questionAsked } from './questions.js';
11
13
  import { untilAnswered } from './recovery.js';
12
14
  import { capped, FROM_START, messageOrder, precedes } from './windows.js';
@@ -21,11 +23,11 @@ export function unheldView(conversation) {
21
23
  commands: [],
22
24
  options: [],
23
25
  starting: null,
24
- subagents: [],
26
+ state: null,
25
27
  link: null,
28
+ deliveryWaiting: [],
26
29
  deliveryUnknown: [],
27
30
  chatDraft: null,
28
- jobs: [],
29
31
  };
30
32
  }
31
33
  export const SESSION_STARTED = 'Session started';
@@ -42,52 +44,15 @@ function creationOf(input) {
42
44
  }
43
45
  function startedTurn(turn, operation) {
44
46
  if (operation.op === 'begin')
45
- return { turn, started: operation.at, parts: [], context: null };
46
- if (operation.op === 'context') {
47
- return {
48
- turn,
49
- started: null,
50
- parts: [],
51
- context: { used: operation.used, window: operation.window },
52
- };
53
- }
54
- return operation.op === 'start' && operation.index === 0
55
- ? { turn, started: null, parts: [structuredClone(operation.part)], context: null }
56
- : null;
57
- }
58
- function changedFields(part, operation) {
59
- if (operation.op === 'append') {
60
- return { text: `${String(part.text ?? '')}${operation.text}` };
61
- }
62
- if (operation.op === 'status') {
63
- return { status: operation.status, result: structuredClone(operation.result) };
64
- }
65
- if (operation.op === 'count')
66
- return { count: operation.count };
67
- return { entries: structuredClone(operation.entries) };
47
+ return { turn, started: operation.at, parts: [] };
48
+ const parts = applied([], operation);
49
+ return parts === null ? null : { turn, started: null, parts };
68
50
  }
69
51
  function appliedTurn(held, operation) {
70
52
  if (operation.op === 'begin')
71
53
  return { ...held, started: operation.at };
72
- if (operation.op === 'context') {
73
- return { ...held, context: { used: operation.used, window: operation.window } };
74
- }
75
- if (operation.op === 'start') {
76
- if (operation.index !== 0 && operation.index !== held.parts.length)
77
- return null;
78
- return {
79
- ...held,
80
- parts: [...held.parts.slice(0, operation.index), structuredClone(operation.part)],
81
- };
82
- }
83
- const part = held.parts[operation.index];
84
- if (typeof part !== 'object' || part === null)
85
- return null;
86
- const changed = { ...part, ...changedFields(part, operation) };
87
- return {
88
- ...held,
89
- parts: held.parts.map((kept, at) => (at === operation.index ? changed : kept)),
90
- };
54
+ const parts = applied(held.parts, operation);
55
+ return parts === null ? null : { ...held, parts };
91
56
  }
92
57
  function windowOf(held, arriving, limit) {
93
58
  const byIdentity = new Map(held.map((message) => [message.identity, message]));
@@ -110,7 +75,7 @@ function frameOf(asked, messages, more, total) {
110
75
  };
111
76
  }
112
77
  function newestOf(arriving, from) {
113
- return arriving.reduce((top, message) => (top === null || message.position > top ? message.position : top), from);
78
+ return arriving.reduce((top, message) => (top === null || message.change > top ? message.change : top), from);
114
79
  }
115
80
  function acceptedMessage(value) {
116
81
  if (typeof value !== 'object' || value === null)
@@ -119,6 +84,7 @@ function acceptedMessage(value) {
119
84
  if (typeof record.identity !== 'string' ||
120
85
  typeof record.turn !== 'string' ||
121
86
  typeof record.position !== 'string' ||
87
+ typeof record.change !== 'string' ||
122
88
  typeof record.text !== 'string') {
123
89
  return null;
124
90
  }
@@ -126,6 +92,7 @@ function acceptedMessage(value) {
126
92
  identity: record.identity,
127
93
  turn: record.turn,
128
94
  position: record.position,
95
+ change: record.change,
129
96
  text: record.text,
130
97
  message: structuredClone(record.message),
131
98
  };
@@ -237,7 +204,7 @@ function returned(draft, submission, others) {
237
204
  revision: chatDraftRevision(),
238
205
  }, others);
239
206
  }
240
- function viewOf(alive, conversation, held, frame, draft, ended, marked) {
207
+ function viewOf(alive, conversation, held, frame, draft, ended) {
241
208
  const facts = alive.liveOf(conversation);
242
209
  return {
243
210
  conversation,
@@ -255,26 +222,37 @@ function viewOf(alive, conversation, held, frame, draft, ended, marked) {
255
222
  commands: structuredClone(facts.commands),
256
223
  options: structuredClone(facts.options),
257
224
  starting: facts.starting,
258
- subagents: structuredClone(facts.subagents),
225
+ state: sessionOf(facts, held, ended),
259
226
  link: facts.link === null ? null : { ...facts.link },
227
+ deliveryWaiting: [...facts.deliveryWaiting],
260
228
  deliveryUnknown: [...facts.deliveryUnknown],
261
229
  chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
262
- jobs: facts.process?.running === false
263
- ? []
264
- : jobsOf(marked.filter(({ at }) => ended === null || at > ended), facts.turn),
265
230
  };
266
231
  }
232
+ function sessionOf(facts, held, ended) {
233
+ if (facts.state !== null)
234
+ return structuredClone(facts.state);
235
+ const saved = [...held]
236
+ .reverse()
237
+ .map(({ message }) => record(message))
238
+ .find(({ content }) => isTurn(content));
239
+ const at = saved === undefined ? null : text(saved, 'accepted_at');
240
+ if (saved === undefined || !isTurn(saved.content) || at === null)
241
+ return null;
242
+ const down = facts.process?.running === false;
243
+ return structuredClone(standingState(saved.content.state, at, down ? at : ended));
244
+ }
267
245
  function emit(alive, conversation) {
268
246
  if (alive.deps.closed())
269
247
  return;
270
248
  for (const view of alive.views()) {
271
- const { window, draft, ended, marked } = view.held.now();
249
+ const { window, draft, ended } = view.held.now();
272
250
  if (view.conversation !== conversation || window === null)
273
251
  continue;
274
252
  const ready = view.ready();
275
253
  if (ready.length === 0)
276
254
  continue;
277
- const value = viewOf(alive, conversation, window, sharedFrame(view, window), draft, ended, marked);
255
+ const value = viewOf(alive, conversation, window, sharedFrame(view, window), draft, ended);
278
256
  for (const watcher of ready)
279
257
  watcher.notify(value);
280
258
  }
@@ -285,23 +263,18 @@ function sharedFrame(view, window) {
285
263
  }
286
264
  async function slide(alive, local, conversation, arriving) {
287
265
  let count;
288
- let marked;
289
266
  for (const view of alive.views()) {
290
267
  const { held } = view;
291
268
  const { window, total } = held.now();
292
269
  if (view.conversation !== conversation || window === null)
293
270
  continue;
294
271
  if (arriving === null) {
295
- held.set({ window: [], marked: [], more: false, total: total === null ? null : 0 });
272
+ held.set({ window: [], more: false, total: total === null ? null : 0 });
296
273
  continue;
297
274
  }
298
275
  const joining = arriving.filter((message) => precedes(message, view.asked.before));
299
276
  const next = windowOf(window, joining, view.asked.limit);
300
277
  held.set({ window: next.messages, more: held.now().more || next.dropped });
301
- if (arriving.length > 0) {
302
- marked ??= await local.jobMarkers(conversation);
303
- held.set({ marked });
304
- }
305
278
  if (held.now().total !== null && arriving.length > 0) {
306
279
  count ??= await local.messageCount(conversation);
307
280
  held.set({ total: count });
@@ -399,7 +372,7 @@ function listChanged(alive, change) {
399
372
  list.some(({ conversation }) => !replicated.has(conversation)))) {
400
373
  alive.deps.again();
401
374
  }
402
- }, () => { });
375
+ }, uncaught);
403
376
  }
404
377
  function endedAnew(alive, list) {
405
378
  const entries = new Map(list.map((entry) => [entry.conversation, entry]));
@@ -415,7 +388,10 @@ function endedAnew(alive, list) {
415
388
  function shownList(alive, work) {
416
389
  const reading = heldList(alive);
417
390
  alive.inOrder(async () => {
418
- const list = await reading.catch(() => null);
391
+ const list = await reading.catch((error) => {
392
+ uncaught(error);
393
+ return null;
394
+ });
419
395
  if (list === null || alive.deps.closed())
420
396
  return;
421
397
  work(list);
@@ -468,15 +444,24 @@ export function conversationsLearned(alive) {
468
444
  shownList(alive, (list) => alive.agentListeners.welcome(agents(alive, list)));
469
445
  }
470
446
  function agents(alive, list) {
471
- const named = new Map();
472
- for (const agent of alive.held.now().listedAgents ?? [])
473
- named.set(agent.agent, agent);
447
+ const read = new Map((alive.held.now().listedAgents ?? []).map((one) => [one.agent, one]));
448
+ const named = new Map(read);
474
449
  for (const entry of list) {
475
450
  named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
476
451
  }
477
452
  return [...named]
478
453
  .filter(([, agent]) => !agent.retired)
479
- .map(([identity, agent]) => ({ identity, name: agent.name }))
454
+ .map(([identity, agent]) => {
455
+ const held = read.get(identity);
456
+ return held === undefined
457
+ ? { identity, name: agent.name }
458
+ : {
459
+ identity,
460
+ name: agent.name,
461
+ cli: held.cli,
462
+ environment: structuredClone(held.environment),
463
+ };
464
+ })
480
465
  .sort((left, right) => left.name === right.name
481
466
  ? left.identity.localeCompare(right.identity)
482
467
  : left.name.localeCompare(right.name));
@@ -550,8 +535,9 @@ function openingEnded(alive) {
550
535
  commands: facts.has('commands') ? QUIET.commands : held.commands,
551
536
  options: facts.has('options') ? QUIET.options : held.options,
552
537
  starting: facts.has('starting') ? QUIET.starting : held.starting,
553
- subagents: facts.has('subagents') ? QUIET.subagents : held.subagents,
538
+ state: facts.has('state') ? QUIET.state : held.state,
554
539
  link: facts.has('link') ? QUIET.link : held.link,
540
+ deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
555
541
  deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
556
542
  });
557
543
  emit(alive, conversation);
@@ -634,7 +620,7 @@ function retiredDrafts(alive, list) {
634
620
  held.some(({ conversation }) => retiredChat(conversation, list))) {
635
621
  alive.deps.again();
636
622
  }
637
- }, () => { });
623
+ }, uncaught);
638
624
  }
639
625
  function settleBehind(alive, list) {
640
626
  void alive.deps
@@ -660,21 +646,19 @@ function settleBehind(alive, list) {
660
646
  alive.deps.settled();
661
647
  if (owed)
662
648
  alive.deps.again();
663
- }, () => { });
649
+ }, uncaught);
664
650
  }
665
651
  function keep(alive, conversation, message) {
666
652
  return alive.deps.durably(async (local) => {
667
653
  if (!alive.held.now().replicated.has(conversation))
668
654
  return;
669
655
  const read = (await readsOf(local, [conversation])).get(conversation)?.read;
670
- const advances = read !== undefined &&
671
- !alive.behind(conversation) &&
672
- (read === null || message.position > read);
656
+ const advances = read !== undefined && !alive.behind(conversation) && (read === null || message.change > read);
673
657
  await sealed(alive, local, conversation, new Set([message.turn]));
674
658
  await local.keepMessages({
675
659
  conversation,
676
660
  messages: [message],
677
- ...(advances ? { read: { at: message.position, partial: false } } : {}),
661
+ ...(advances ? { read: { at: message.change, partial: false } } : {}),
678
662
  });
679
663
  sealTurns(alive, conversation, new Set([message.turn]));
680
664
  await slide(alive, local, conversation, [message]);
@@ -786,8 +770,8 @@ function heard(alive, event) {
786
770
  live(alive, conversation, { starting: event.step });
787
771
  return;
788
772
  }
789
- if (event.kind === 'subagents') {
790
- live(alive, conversation, { subagents: structuredClone(event.subagents) });
773
+ if (event.kind === 'state') {
774
+ live(alive, conversation, { state: structuredClone(event.state) });
791
775
  return;
792
776
  }
793
777
  if (event.kind === 'link') {
@@ -795,13 +779,16 @@ function heard(alive, event) {
795
779
  return;
796
780
  }
797
781
  if (event.kind === 'deliveries') {
798
- live(alive, conversation, { deliveryUnknown: [...event.unknown] });
782
+ live(alive, conversation, {
783
+ deliveryWaiting: [...event.waiting],
784
+ deliveryUnknown: [...event.unknown],
785
+ });
799
786
  return;
800
787
  }
801
788
  const arriving = acceptedMessage(event.message);
802
789
  if (arriving === null)
803
790
  return;
804
- alive.heardAt(conversation, arriving.position);
791
+ alive.heardAt(conversation, arriving.change);
805
792
  if (alive.held.now().replicated.has(conversation)) {
806
793
  if (alive.deps.full()) {
807
794
  alive.gapOpened(conversation);
@@ -810,6 +797,8 @@ function heard(alive, event) {
810
797
  void keep(alive, conversation, arriving).catch((error) => {
811
798
  if (refusedForSpace(error))
812
799
  alive.gapOpened(conversation);
800
+ else
801
+ uncaught(error);
813
802
  });
814
803
  return;
815
804
  }
@@ -948,8 +937,7 @@ export function conversationSurface(alive) {
948
937
  return alive.deps.durably(async (local) => {
949
938
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
950
939
  const total = asked.total ? await local.messageCount(conversation, phrase) : null;
951
- const marked = await local.jobMarkers(conversation);
952
- return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), (await local.chatDraft(conversation)) ?? null, await endedIn(alive, conversation), marked));
940
+ return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), (await local.chatDraft(conversation)) ?? null, await endedIn(alive, conversation)));
953
941
  });
954
942
  },
955
943
  async create(input) {
@@ -1001,6 +989,52 @@ export function conversationSurface(alive) {
1001
989
  delete(conversation) {
1002
990
  return invoke(alive, 'conversations/delete', conversation);
1003
991
  },
992
+ takeOut(conversation, message, operation) {
993
+ return invoke(alive, 'conversations/take-out', conversation, {
994
+ message_id: message,
995
+ operation_id: operation,
996
+ });
997
+ },
998
+ decide({ request, room, message }, decision, operation) {
999
+ return alive.deps.call('agent-functions/decide', {
1000
+ room_ref: room,
1001
+ request,
1002
+ ...(message === undefined ? {} : { message }),
1003
+ decision,
1004
+ operation_id: operation,
1005
+ });
1006
+ },
1007
+ rename(conversation, name, operation) {
1008
+ return invoke(alive, 'conversations/rename', conversation, { name, operation_id: operation });
1009
+ },
1010
+ option(conversation, option, value, operation) {
1011
+ return invoke(alive, 'conversations/option/set', conversation, {
1012
+ option,
1013
+ value,
1014
+ operation_id: operation,
1015
+ });
1016
+ },
1017
+ retry(conversation, message, operation) {
1018
+ return invoke(alive, 'conversations/retry', conversation, {
1019
+ message_id: message,
1020
+ operation_id: operation,
1021
+ });
1022
+ },
1023
+ async pins() {
1024
+ return (await (await alive.deps.local()).facts()).chatPins;
1025
+ },
1026
+ pin(figures) {
1027
+ return alive.deps.durably((local) => local.fact('chatPins', [...figures]));
1028
+ },
1029
+ async openedTurns() {
1030
+ return (await (await alive.deps.local()).facts()).openedTurns;
1031
+ },
1032
+ openTurn(conversation, turn) {
1033
+ return alive.deps.durably(async (local) => {
1034
+ const { openedTurns } = await local.facts();
1035
+ await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
1036
+ });
1037
+ },
1004
1038
  };
1005
1039
  }
1006
1040
  export function chatDraftSurface(alive) {
@@ -1126,16 +1160,15 @@ export function watchConversation(alive, conversation, options, deliver) {
1126
1160
  held.set({ draft: (await local.chatDraft(conversation)) ?? null });
1127
1161
  held.set({ ended: await endedIn(alive, conversation) });
1128
1162
  held.set({ window: messages });
1129
- held.set({ marked: await local.jobMarkers(conversation) });
1130
1163
  held.set({ more });
1131
1164
  held.set({ total: asked.total ? await local.messageCount(conversation) : null });
1132
1165
  }), reading.signal)
1133
1166
  .then(() => {
1134
1167
  if (alive.deps.closed() || !view.admit(watcher))
1135
1168
  return;
1136
- const { window, draft, ended, marked } = held.now();
1169
+ const { window, draft, ended } = held.now();
1137
1170
  const shown = window ?? [];
1138
- watcher.notify(viewOf(alive, conversation, shown, sharedFrame(view, shown), draft, ended, marked));
1171
+ watcher.notify(viewOf(alive, conversation, shown, sharedFrame(view, shown), draft, ended));
1139
1172
  })
1140
1173
  .catch(() => { });
1141
1174
  return () => {
@@ -0,0 +1,10 @@
1
+ import type { DiscoveredRoom, OperationScopes, PathRule, RoomDeclaration } from './adapter.js';
2
+ export type WriteRefusal = {
3
+ readonly code: 'room-root' | 'provider-owned-path' | 'invalid-path' | `${keyof OperationScopes}-grant`;
4
+ readonly path: string;
5
+ };
6
+ export type WriteRule = (path: string, needs: readonly (keyof OperationScopes)[]) => WriteRefusal | null;
7
+ export declare function declared({ locator: _locator, roomVersion: _roomVersion, ...declaration }: DiscoveredRoom): RoomDeclaration;
8
+ export declare function sameDeclaration(left: RoomDeclaration, right: RoomDeclaration): boolean;
9
+ export declare function writeRule({ operations, providerOwnedPaths, authoredPaths, }: Pick<RoomDeclaration, 'operations' | 'providerOwnedPaths' | 'authoredPaths'>, pathRule: PathRule, local: boolean): WriteRule;
10
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../src/declaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/F,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,IAAI,EACT,WAAW,GACX,qBAAqB,GACrB,cAAc,GACd,GAAG,MAAM,eAAe,QAAQ,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,CAAC,MAAM,eAAe,CAAC,EAAE,KACtC,YAAY,GAAG,IAAI,CAAC;AAEzB,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EAAE,QAAQ,EACjB,WAAW,EAAE,YAAY,EACzB,GAAG,WAAW,EACf,EAAE,cAAc,GAAG,eAAe,CAElC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAEtF;AAED,wBAAgB,SAAS,CACvB,EACE,UAAU,EACV,kBAAkB,EAClB,aAAa,GACd,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,GAAG,oBAAoB,GAAG,eAAe,CAAC,EAC/E,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,OAAO,GACb,SAAS,CAYX"}
@@ -0,0 +1,24 @@
1
+ import { equalValue } from '@agentshouse/mdmodel';
2
+ import { authoredAt, covered, normalize } from './paths.js';
3
+ export function declared({ locator: _locator, roomVersion: _roomVersion, ...declaration }) {
4
+ return declaration;
5
+ }
6
+ export function sameDeclaration(left, right) {
7
+ return equalValue(left, right);
8
+ }
9
+ export function writeRule({ operations, providerOwnedPaths, authoredPaths, }, pathRule, local) {
10
+ return (path, needs) => {
11
+ const normalized = normalize(path);
12
+ if (normalized === null || normalized === '')
13
+ return { code: 'room-root', path };
14
+ if (covered(providerOwnedPaths, normalized) || !authoredAt(authoredPaths, normalized)) {
15
+ return { code: 'provider-owned-path', path: normalized };
16
+ }
17
+ if (!pathRule(normalized))
18
+ return { code: 'invalid-path', path: normalized };
19
+ if (local)
20
+ return null;
21
+ const missing = needs.find((operation) => !covered(operations[operation], normalized));
22
+ return missing === undefined ? null : { code: `${missing}-grant`, path: normalized };
23
+ };
24
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EACT,cAAc,EACd,MAAM,EAEP,MAAM,cAAc,CAAC;AAQtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,C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ChB,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CA0CpC;AAUD,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,iBAI1F;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,cAAc,EAAE,GAAG,IAAI,CAAC,CA+D3C"}
package/dist/discovery.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { validRoot } from './collection.js';
2
- import { admitted, list, listHeld } from './listing.js';
3
- import { confirmLocks, lockedRooms, relocked } from './locks.js';
2
+ import { lockedRooms, relocked } from './locks.js';
4
3
  import { loseRooms } from './lost.js';
5
4
  import { cachedModels } from './models.js';
6
5
  import { beneath } from './paths.js';
@@ -11,7 +10,7 @@ function within(root, path) {
11
10
  }
12
11
  function declaredSelection(room) {
13
12
  const selection = room.typedSelection;
14
- if (selection === undefined)
13
+ if (selection === null)
15
14
  return true;
16
15
  if (!Array.isArray(selection.roots) || selection.roots.length === 0)
17
16
  return false;
@@ -37,60 +36,34 @@ export function malformed(listed) {
37
36
  return null;
38
37
  }
39
38
  export async function applyDiscovery(runtime, found, started, left) {
40
- const { store, socket } = runtime;
41
- const { rooms } = socket;
39
+ const { store, socket, presence } = runtime;
42
40
  const lockedBefore = await lockedRooms(runtime);
43
41
  const local = await store.open();
44
- const stillFenced = new Set(await local.fences());
42
+ const fenced = new Set(await local.fences());
45
43
  const relisting = found
46
44
  .map(({ locator }) => locator)
47
- .filter((locator) => {
48
- const fence = store.fences.of(locator);
49
- return stillFenced.has(locator) && (fence === undefined || fence.at < started);
50
- });
51
- const relisted = relisting.length === 0
45
+ .filter((locator) => fenced.has(locator) && presence.liftable(locator, started));
46
+ const unfenced = relisting.length === 0
52
47
  ? new Set()
53
48
  : await store.durably((held) => held.unfence(relisting));
54
- for (const { locator } of found) {
55
- const fence = store.fences.of(locator);
56
- if (fence === undefined || fence.at >= started)
57
- continue;
58
- if (relisted.has(locator) || (!stillFenced.has(locator) && !fence.written)) {
59
- store.fences.lift(locator);
60
- }
61
- }
49
+ const clear = found.filter(({ locator }) => !fenced.has(locator) || unfenced.has(locator));
50
+ for (const { locator } of clear)
51
+ presence.lift(locator, started, unfenced.has(locator));
62
52
  const kept = await local.held();
63
53
  await loseRooms(runtime, found
64
54
  .filter((room) => room.replica.admission !== 'admitted' &&
65
55
  (kept.held.has(room.locator) || store.installs.of(room.locator).transfer !== null))
66
56
  .map((room) => room.locator));
67
- const listed = found.filter(({ locator }) => !store.fences.has(locator) && (!stillFenced.has(locator) || relisted.has(locator)));
68
- const listedLocatorsNow = new Set(listed.map((room) => room.locator));
69
- for (const locator of listedLocatorsNow)
70
- rooms.stand(locator, { refusal: null });
71
- if (left === undefined)
72
- rooms.undiscoverAll();
73
- for (const room of listed)
74
- rooms.discover(room);
75
57
  const named = new Set(found.map((room) => room.locator));
76
58
  await loseRooms(runtime, left ??
77
59
  [
78
60
  ...new Set([
79
- ...rooms.declarations().keys(),
61
+ ...presence.rooms().map(({ locator }) => locator),
80
62
  ...kept.held,
81
63
  ...store.installs.transferring(),
82
64
  ]),
83
65
  ].filter((locator) => !named.has(locator)));
84
- const held = await store.rooms(listed.map((room) => room.locator));
85
- for (const room of listed) {
86
- const record = held.get(room.locator)?.record;
87
- if (record !== undefined && record.replica.selection !== room.replica.selection) {
88
- listHeld(runtime, room.locator);
89
- continue;
90
- }
91
- list(runtime, room, admitted(runtime, room));
92
- }
93
- confirmLocks(runtime, listed);
66
+ const listed = presence.list(clear, { whole: left === undefined, live: socket.isOpen() });
94
67
  socket.session.set({ roomsListed: true });
95
68
  emitRooms(runtime);
96
69
  await relocked(runtime, lockedBefore);
package/dist/failure.d.ts CHANGED
@@ -9,5 +9,6 @@ export type Described = {
9
9
  };
10
10
  export declare function runtimeError(code: string, message?: string, retryable?: boolean): RuntimeError;
11
11
  export declare function failed(error: unknown): RuntimeError;
12
+ export declare function uncaught(error: unknown): void;
12
13
  export declare function described(error: unknown): Described;
13
14
  //# sourceMappingURL=failure.d.ts.map
@@ -1 +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"}
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,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAGnD"}
package/dist/failure.js CHANGED
@@ -13,6 +13,9 @@ export function failed(error) {
13
13
  return error;
14
14
  return runtimeError('runtime-failure', error instanceof Error ? error.message : String(error));
15
15
  }
16
+ export function uncaught(error) {
17
+ reportError(error);
18
+ }
16
19
  export function described(error) {
17
20
  const { message, code, retryable } = failed(error);
18
21
  return { message, code, retryable };