@agentshouse/kit 0.2.1-ce3d2bb67177c → 0.2.1-ce46b2b55463f

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 (161) hide show
  1. package/README.md +31 -35
  2. package/dist/acp.js +56 -6
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +120 -51
  5. package/dist/api.js +11 -6
  6. package/dist/binaries.js +79 -0
  7. package/dist/bridge.js +30 -26
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +29 -4
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +61 -49
  12. package/dist/connect.js +108 -0
  13. package/dist/connection.js +33 -38
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +325 -141
  16. package/dist/copies.js +720 -247
  17. package/dist/earlier.js +263 -0
  18. package/dist/end.js +4 -5
  19. package/dist/events.js +549 -281
  20. package/dist/files.js +110 -28
  21. package/dist/git-main.js +24 -29
  22. package/dist/git.js +89 -14
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +65 -29
  25. package/dist/house-cli.js +114 -159
  26. package/dist/house-main.js +3 -3
  27. package/dist/instructions.js +29 -11
  28. package/dist/keys.js +238 -0
  29. package/dist/kit-cli.js +16 -6
  30. package/dist/kit-main.js +3 -3
  31. package/dist/login.js +36 -20
  32. package/dist/logout.js +2 -2
  33. package/dist/mcp.js +38 -1
  34. package/dist/owner.js +46 -0
  35. package/dist/placement.js +9 -23
  36. package/dist/refusals.js +37 -21
  37. package/dist/relay.js +21 -0
  38. package/dist/resident.js +109 -65
  39. package/dist/scope.js +12 -4
  40. package/dist/scripts.js +303 -0
  41. package/dist/secret-input.js +1 -1
  42. package/dist/settings.js +188 -0
  43. package/dist/sign-in.js +49 -3
  44. package/dist/silence.js +28 -0
  45. package/dist/skills.js +41 -96
  46. package/dist/supervisor.js +163 -0
  47. package/dist/transcription.js +37 -25
  48. package/dist/translate.js +18 -9
  49. package/dist/update.js +115 -117
  50. package/dist/wire.js +19 -9
  51. package/dist/work.js +9 -2
  52. package/dist/workspace.js +103 -0
  53. package/package.json +25 -21
  54. package/dist/authority-main.js +0 -22
  55. package/dist/bootstrap.json +0 -24
  56. package/dist/chatgpt.js +0 -32
  57. package/dist/clis-main.js +0 -23
  58. package/dist/configure-main.js +0 -6
  59. package/dist/enrol-main.js +0 -10
  60. package/dist/parts.js +0 -82
  61. package/dist/service-main.js +0 -9
  62. package/dist/service.js +0 -55
  63. package/how-we-work.md +0 -33
  64. package/skills/ask-matt/LICENSE +0 -21
  65. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  66. package/skills/ask-matt/SKILL.md +0 -97
  67. package/skills/ask-matt/agents/openai.yaml +0 -5
  68. package/skills/code-review/LICENSE +0 -21
  69. package/skills/code-review/SKILL.md +0 -89
  70. package/skills/code-review/agents/openai.yaml +0 -3
  71. package/skills/codebase-design/DEEPENING.md +0 -37
  72. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  73. package/skills/codebase-design/LICENSE +0 -21
  74. package/skills/codebase-design/SKILL.md +0 -114
  75. package/skills/codebase-design/agents/openai.yaml +0 -3
  76. package/skills/diagnosing-bugs/LICENSE +0 -21
  77. package/skills/diagnosing-bugs/SKILL.md +0 -138
  78. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  79. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  80. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  81. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  82. package/skills/domain-modeling/LICENSE +0 -21
  83. package/skills/domain-modeling/SKILL.md +0 -74
  84. package/skills/domain-modeling/agents/openai.yaml +0 -3
  85. package/skills/grill-me/LICENSE +0 -21
  86. package/skills/grill-me/SKILL.md +0 -7
  87. package/skills/grill-me/agents/openai.yaml +0 -5
  88. package/skills/grill-with-docs/LICENSE +0 -21
  89. package/skills/grill-with-docs/SKILL.md +0 -7
  90. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  91. package/skills/grilling/LICENSE +0 -21
  92. package/skills/grilling/SKILL.md +0 -30
  93. package/skills/grilling/agents/openai.yaml +0 -3
  94. package/skills/handoff/LICENSE +0 -21
  95. package/skills/handoff/SKILL.md +0 -16
  96. package/skills/handoff/agents/openai.yaml +0 -5
  97. package/skills/implement/LICENSE +0 -21
  98. package/skills/implement/SKILL.md +0 -17
  99. package/skills/implement/agents/openai.yaml +0 -5
  100. package/skills/implement-spec/LICENSE +0 -21
  101. package/skills/implement-spec/SKILL.md +0 -40
  102. package/skills/implement-spec/agents/openai.yaml +0 -5
  103. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  104. package/skills/improve-codebase-architecture/LICENSE +0 -21
  105. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  106. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  107. package/skills/pr/CREDITS.md +0 -3
  108. package/skills/pr/LICENSE +0 -21
  109. package/skills/pr/SKILL.md +0 -170
  110. package/skills/pr/agents/openai.yaml +0 -3
  111. package/skills/prototype/LICENSE +0 -21
  112. package/skills/prototype/LOGIC.md +0 -67
  113. package/skills/prototype/SKILL.md +0 -26
  114. package/skills/prototype/UI.md +0 -112
  115. package/skills/prototype/agents/openai.yaml +0 -3
  116. package/skills/research/LICENSE +0 -21
  117. package/skills/research/SKILL.md +0 -12
  118. package/skills/research/agents/openai.yaml +0 -3
  119. package/skills/retro/LICENSE +0 -21
  120. package/skills/retro/SKILL.md +0 -44
  121. package/skills/retro/agents/openai.yaml +0 -5
  122. package/skills/tdd/LICENSE +0 -21
  123. package/skills/tdd/SKILL.md +0 -38
  124. package/skills/tdd/agents/openai.yaml +0 -3
  125. package/skills/tdd/mocking.md +0 -59
  126. package/skills/tdd/tests.md +0 -77
  127. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  128. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  129. package/skills/teach/LICENSE +0 -21
  130. package/skills/teach/MISSION-FORMAT.md +0 -31
  131. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  132. package/skills/teach/SKILL.md +0 -140
  133. package/skills/teach/agents/openai.yaml +0 -5
  134. package/skills/to-questionnaire/LICENSE +0 -21
  135. package/skills/to-questionnaire/SKILL.md +0 -54
  136. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  137. package/skills/to-spec/LICENSE +0 -21
  138. package/skills/to-spec/SKILL.md +0 -75
  139. package/skills/to-spec/agents/openai.yaml +0 -5
  140. package/skills/to-tickets/LICENSE +0 -21
  141. package/skills/to-tickets/SKILL.md +0 -105
  142. package/skills/to-tickets/agents/openai.yaml +0 -5
  143. package/skills/triage/AGENT-BRIEF.md +0 -207
  144. package/skills/triage/LICENSE +0 -21
  145. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  146. package/skills/triage/SKILL.md +0 -112
  147. package/skills/triage/agents/openai.yaml +0 -5
  148. package/skills/wait-what/LICENSE +0 -21
  149. package/skills/wait-what/SKILL.md +0 -7
  150. package/skills/wait-what/agents/openai.yaml +0 -5
  151. package/skills/wayfinder/LICENSE +0 -21
  152. package/skills/wayfinder/SKILL.md +0 -128
  153. package/skills/wayfinder/agents/openai.yaml +0 -5
  154. package/skills/wizard/LICENSE +0 -21
  155. package/skills/wizard/SKILL.md +0 -44
  156. package/skills/wizard/agents/openai.yaml +0 -3
  157. package/skills/wizard/template.sh +0 -223
  158. package/skills/writing-for-agents/LICENSE +0 -21
  159. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  160. package/skills/writing-for-agents/SKILL.md +0 -81
  161. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -1,25 +1,25 @@
1
- import { client, RequestError, } from '@agentclientprotocol/sdk';
1
+ import { client, } from '@agentclientprotocol/sdk';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
3
  import { mkdir } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { unlessAborted } from './abort.js';
6
- import { startAdapter } from './acp.js';
6
+ import { signedOut, startAdapter } from './acp.js';
7
+ import { formAnswered, grokQuestionAnswered, permissionAllowed, PLAN_APPROVED } from './afk.js';
7
8
  import { finalRefusal, HouseRefusal } from './api.js';
8
9
  import { openBridge } from './bridge.js';
9
10
  import { CLIS } from './clis.js';
11
+ import { Content } from './content.js';
10
12
  import { answeredFailure, readerFor } from './events.js';
11
- import { inspectedFile, linkedPaths, storeRefusal, uploaded } from './files.js';
13
+ import { fileInfo, linkedPaths, storeRefusal, uploaded } from './files.js';
14
+ import { grokPlanAnswer, grokPlanForm, grokQuestionAnswer, grokQuestionForm } from './grok.js';
12
15
  import { agentBase } from './home.js';
13
16
  import { instructions } from './instructions.js';
14
- import { Parts } from './parts.js';
15
17
  import { refusalOf } from './refusals.js';
16
18
  import { relayed } from './relay.js';
17
19
  import { killMarked, Scope } from './scope.js';
18
20
  import { holdSecretInput } from './secret-input.js';
19
- import { createHowWeWork } from './skills.js';
20
21
  import { transcribe } from './transcription.js';
21
22
  import { workFor } from './work.js';
22
- const SIGNED_OUT = RequestError.authRequired().code;
23
23
  const KILLED = 'the conversation was killed';
24
24
  const INTERRUPTED = 'the conversation was interrupted';
25
25
  const REFUSED = 'the CLI refused the prompt';
@@ -35,6 +35,27 @@ const NO_SESSION = "the Agent's CLI did not open a session";
35
35
  const NO_RESUME = "the Agent's CLI could not resume this conversation";
36
36
  const NOT_SIGNED_IN = "the Agent's CLI is not signed in; sign it in on the Agent's machine";
37
37
  const NO_SETTINGS = "the Agent's CLI refused the Agent's model, mode or effort";
38
+ const UNSTEERED = "the Agent's CLI did not take the message into its running turn";
39
+ const TAKEN_OUT = 'the message was taken out before it started';
40
+ const QUIET = {
41
+ title: null,
42
+ context: null,
43
+ limits: [],
44
+ cost: null,
45
+ tokens: null,
46
+ duration: null,
47
+ files: { count: 0, added: 0, removed: 0 },
48
+ branch: null,
49
+ worktree: null,
50
+ pull: null,
51
+ model: null,
52
+ effort: null,
53
+ mode: null,
54
+ suggestion: null,
55
+ running: [],
56
+ };
57
+ // A reader tells a working run from a stopped one by the minute, and House keeps no finer figure, so a run reports no oftener.
58
+ const ACTIVITY_REPORT_MS = 60_000;
38
59
  class NotStarted extends Error {
39
60
  }
40
61
  class ResumeRefused extends NotStarted {
@@ -47,26 +68,41 @@ async function step(reason, work) {
47
68
  throw new NotStarted(typeof reason === 'string' ? reason : reason(error), { cause: error });
48
69
  }
49
70
  }
50
- function signedOut(error) {
51
- return typeof error === 'object' && error !== null && error.code === SIGNED_OUT;
52
- }
53
71
  function unopened(reason) {
54
72
  return (error) => (signedOut(error) ? NOT_SIGNED_IN : reason);
55
73
  }
56
74
  // A start-up step is shown only once it has lasted a second, so a quick start shows none of them.
57
75
  const STARTING_SHOWN_AFTER_MS = 1_000;
76
+ function turnOf(conversation, turn) {
77
+ return { conversation: conversation.id, turn: turn.id };
78
+ }
58
79
  function unbridged(error) {
59
80
  return (finalRefusal(error) ? ENDED[refusalOf(error.text)?.code ?? ''] : undefined) ?? NO_CONNECTION;
60
81
  }
61
- const EXIT_PLAN_MODE = {
82
+ const GROK_PLAN = {
83
+ parse(value) {
84
+ return value;
85
+ },
86
+ };
87
+ const GROK_QUESTION = {
62
88
  parse(value) {
63
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
64
- throw new Error('_x.ai/exit_plan_mode needs an object');
65
- }
66
89
  return value;
67
90
  },
68
91
  };
69
- export const CONVERSATION_METHODS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
92
+ function addedTokens(sum, tokens) {
93
+ if (sum === null)
94
+ return tokens;
95
+ return {
96
+ input: sum.input + tokens.input,
97
+ output: sum.output + tokens.output,
98
+ cache_read: sum.cache_read + tokens.cache_read,
99
+ cache_write: sum.cache_write + tokens.cache_write,
100
+ };
101
+ }
102
+ function cliSaid(error) {
103
+ const details = error?.data?.details;
104
+ return typeof details === 'string' && details !== '' ? `${causeOf(error)}: ${details}` : causeOf(error);
105
+ }
70
106
  function causeOf(error) {
71
107
  return error instanceof Error ? error.message : String(error);
72
108
  }
@@ -74,13 +110,15 @@ function answeredWith(error) {
74
110
  return { failure: signedOut(error) ? 'signed_out' : 'error', cause: causeOf(error) };
75
111
  }
76
112
  function exitedWith(running, cause) {
77
- return running.killed ? { failure: 'killed', cause: KILLED } : { failure: 'exited', cause };
113
+ if (running.killed)
114
+ return { failure: 'killed', cause: KILLED };
115
+ return { failure: running.adapter.silent() ? 'silent' : 'exited', cause };
78
116
  }
79
117
  function answerMessage(request, response) {
80
118
  return `The User answered a question you asked earlier.\nQuestion: ${JSON.stringify(request)}\nAnswer: ${JSON.stringify(response)}`;
81
119
  }
82
- async function sentPart(url, bytes) {
83
- const answer = await fetch(relayed(url), { method: 'PUT', body: bytes });
120
+ async function sentPart(url, bytes, headers) {
121
+ const answer = await fetch(relayed(url), { method: 'PUT', headers, body: bytes });
84
122
  await answer.arrayBuffer();
85
123
  if (!answer.ok)
86
124
  throw storeRefusal('upload', answer.status);
@@ -98,24 +136,29 @@ function refusal(conversation, error) {
98
136
  function audioOf(result) {
99
137
  if (result.isError === true)
100
138
  return null;
101
- const file = inspectedFile(result.content.map((content) => content.text).join('\n'));
139
+ const file = fileInfo(result.content.map((content) => content.text).join('\n'));
102
140
  return file?.media_type?.startsWith('audio/') === true ? file : null;
103
141
  }
104
142
  function marker(bridge) {
105
143
  return `HOUSE_BRIDGE=${bridge.env.HOUSE_BRIDGE}`;
106
144
  }
145
+ function steers(adapter) {
146
+ return adapter.initialized._meta?.steering?.supported === true;
147
+ }
107
148
  class Turn {
108
149
  id = randomUUID();
109
- parts;
150
+ content;
110
151
  questions = 0;
111
152
  secrets = 0;
112
153
  prompted = false;
154
+ steered = false;
113
155
  taken = null;
114
156
  ended = false;
157
+ quietUntil = Infinity;
115
158
  images = 0;
116
159
  uploads = [];
117
160
  constructor(emit) {
118
- this.parts = new Parts(emit);
161
+ this.content = new Content(emit);
119
162
  }
120
163
  }
121
164
  class Conversation {
@@ -126,12 +169,16 @@ class Conversation {
126
169
  commands = null;
127
170
  options = null;
128
171
  exitUntold = false;
129
- context = null;
172
+ afk = false;
173
+ reader = null;
174
+ state = QUIET;
175
+ sentState = null;
176
+ tokens = null;
130
177
  leftovers = new Set();
131
178
  waiting = [];
179
+ done = false;
132
180
  sending = null;
133
- subagents = new Map();
134
- held = [];
181
+ subagents = new Set();
135
182
  opening = null;
136
183
  bridge = null;
137
184
  launch = null;
@@ -140,7 +187,7 @@ class Conversation {
140
187
  killed = new AbortController();
141
188
  interrupts = 0;
142
189
  interrupted = new AbortController();
143
- open = 0;
190
+ turns = new Set();
144
191
  queue = Promise.resolve();
145
192
  reports = Promise.resolve();
146
193
  starting = null;
@@ -166,6 +213,7 @@ export class Conversations {
166
213
  questions = new Map();
167
214
  reporting = 0;
168
215
  watched = false;
216
+ stopping = false;
169
217
  constructor(kit) {
170
218
  this.kit = kit;
171
219
  // A process or a durable schedule ends without a report, so the Kit looks at both again every two seconds.
@@ -174,6 +222,8 @@ export class Conversations {
174
222
  call(call) {
175
223
  void this.kit.calls.carry(call.input_id, () => {
176
224
  const conversation = this.conversation(call.conversation_id);
225
+ if (call.kind === 'open' || call.kind === 'message')
226
+ conversation.afk = call.afk === true;
177
227
  if (call.kind === 'kill') {
178
228
  conversation.kills++;
179
229
  conversation.killed.abort(new Error(KILLED));
@@ -196,7 +246,7 @@ export class Conversations {
196
246
  for (const conversation of this.conversations.values()) {
197
247
  const turn = conversation.turn;
198
248
  const asking = turn !== null && turn.questions > 0 && turn.secrets === 0;
199
- if (conversation.open > (asking ? 1 : 0))
249
+ if (conversation.turns.size > (asking ? 1 : 0))
200
250
  return false;
201
251
  }
202
252
  const conversations = [...this.conversations.values()];
@@ -205,7 +255,10 @@ export class Conversations {
205
255
  return !conversations.some((conversation) => conversation.running?.scope.working() || [...conversation.leftovers].some((scope) => scope.working()));
206
256
  }
207
257
  quiet() {
208
- return this.idle() && [...this.conversations.values()].every((conversation) => conversation.open === 0);
258
+ return this.idle() && !this.turnOpen();
259
+ }
260
+ turnOpen() {
261
+ return [...this.conversations.values()].some((conversation) => conversation.turns.size > 0);
209
262
  }
210
263
  look() {
211
264
  for (const conversation of this.conversations.values()) {
@@ -218,11 +271,20 @@ export class Conversations {
218
271
  }
219
272
  this.kit.changed();
220
273
  }
274
+ stopped() {
275
+ this.stopping = true;
276
+ for (const conversation of this.conversations.values()) {
277
+ if (conversation.running !== null)
278
+ this.process(conversation, false);
279
+ }
280
+ }
221
281
  opened() {
222
282
  this.watched = false;
223
283
  for (const conversation of this.conversations.values()) {
224
- if (conversation.running !== null)
284
+ if (conversation.running !== null) {
225
285
  this.facts(conversation);
286
+ this.stateChanged(conversation, true);
287
+ }
226
288
  else if (conversation.exitUntold)
227
289
  this.process(conversation, false);
228
290
  if (conversation.untold || conversation.told !== null)
@@ -249,14 +311,21 @@ export class Conversations {
249
311
  }
250
312
  async carry(conversation, call) {
251
313
  if (call.kind === 'open')
252
- return { result: this.open(conversation, call) };
314
+ return this.open(conversation, call);
253
315
  if (call.kind === 'message')
254
316
  return this.message(conversation, call);
317
+ if (call.kind === 'done') {
318
+ conversation.done = true;
319
+ this.next(conversation);
320
+ return { result: Promise.resolve({}) };
321
+ }
322
+ if (call.kind === 'take_out')
323
+ return { result: Promise.resolve(this.takeOut(conversation, call.message_id)) };
255
324
  await this.launched(conversation);
256
325
  if (call.kind === 'interrupt') {
257
326
  if (--conversation.interrupts === 0)
258
327
  conversation.interrupted = new AbortController();
259
- await this.interrupt(conversation, String(call.turn_id));
328
+ await this.interrupt(conversation, call.turn_id);
260
329
  }
261
330
  if (call.kind === 'kill') {
262
331
  await this.kill(conversation);
@@ -265,9 +334,9 @@ export class Conversations {
265
334
  conversation.killed = new AbortController();
266
335
  }
267
336
  if (call.kind === 'option')
268
- await this.option(conversation, String(call.option), call.value);
337
+ await this.option(conversation, call.option, call.value);
269
338
  if (call.kind === 'answer') {
270
- const question = this.questions.get(String(call.interaction_id));
339
+ const question = this.questions.get(call.interaction_id);
271
340
  if (question === undefined) {
272
341
  const text = answerMessage(call.request, call.response);
273
342
  return this.message(conversation, { ...call, text, first: false, message_id: null });
@@ -276,11 +345,25 @@ export class Conversations {
276
345
  }
277
346
  return { result: Promise.resolve({}) };
278
347
  }
279
- open(conversation, call) {
280
- if (conversation.running !== null)
281
- return Promise.resolve({});
348
+ takeOut(conversation, messageId) {
349
+ const index = conversation.waiting.findIndex((waiting) => waiting.call.message_id === messageId);
350
+ if (index === -1)
351
+ return { started: true };
352
+ const [waiting] = conversation.waiting.splice(index, 1);
353
+ waiting.settle({ refused: TAKEN_OUT });
354
+ return {};
355
+ }
356
+ async open(conversation, call) {
357
+ await this.stop(conversation);
282
358
  const launch = conversation.launch ?? this.launch(conversation, this.route(conversation, call.agent_id), null, true);
283
- return launch.session.then((session) => ({ provider_session_id: session }), (error) => ({ refused: refusal(conversation, error) }));
359
+ return {
360
+ result: launch.session.then((session) => ({ provider_session_id: session }), (error) => ({ refused: refusal(conversation, error) })),
361
+ };
362
+ }
363
+ async stop(conversation) {
364
+ const running = conversation.running;
365
+ running?.scope.kill();
366
+ await running?.adapter.exited;
284
367
  }
285
368
  launch(conversation, route, sessionId, empty) {
286
369
  let opened;
@@ -314,12 +397,15 @@ export class Conversations {
314
397
  const bridge = conversation.running === null ? conversation.launch?.bridge : Promise.resolve(conversation.running.bridge);
315
398
  if (bridge === undefined)
316
399
  return null;
317
- const read = Promise.all([bridge, this.kit.copies.mapping()]).then(([opened, copies]) => instructions(opened, route.base_instructions, copies));
400
+ const read = bridge.then((opened) => instructions(opened, route.base_instructions));
318
401
  read.catch(() => undefined);
319
402
  return read;
320
403
  }
321
404
  async message(conversation, call) {
322
- const content = [{ type: 'text', text: String(call.text) }];
405
+ const content = [
406
+ ...(call.recent === undefined ? [] : [{ type: 'text', text: call.recent }]),
407
+ { type: 'text', text: call.text },
408
+ ];
323
409
  let route;
324
410
  let instructing = null;
325
411
  try {
@@ -327,7 +413,7 @@ export class Conversations {
327
413
  if (call.first === true)
328
414
  instructing = this.instructed(conversation, route);
329
415
  if (call.message_id !== null)
330
- content.push(...(await this.transcribed(conversation, String(call.message_id), String(call.text))));
416
+ content.push(...(await this.transcribed(conversation, call.message_id, call.text)));
331
417
  if (conversation.kills > 0)
332
418
  throw new Error(KILLED);
333
419
  }
@@ -337,21 +423,71 @@ export class Conversations {
337
423
  return { result: Promise.resolve({ refused: refusal(conversation, error) }) };
338
424
  }
339
425
  conversation.preparing = null;
340
- return {
341
- result: new Promise((settle) => {
342
- conversation.waiting.push({ call, route, content, instructing, settle });
343
- this.next(conversation);
344
- }),
345
- };
426
+ const { promise, resolve: settle } = Promise.withResolvers();
427
+ const waiting = { call, route, content, instructing, settle };
428
+ if (call.at_once === true && conversation.turns.size > 0)
429
+ await this.atOnce(conversation, waiting);
430
+ else
431
+ conversation.waiting.push(waiting);
432
+ this.next(conversation);
433
+ return { result: promise };
434
+ }
435
+ async atOnce(conversation, waiting) {
436
+ while (conversation.sending !== null)
437
+ await conversation.sending;
438
+ const running = conversation.running;
439
+ if (running !== null && conversation.turns.size > 0 && steers(running.adapter)) {
440
+ conversation.sending = this.steer(conversation, running, waiting);
441
+ await conversation.sending;
442
+ conversation.sending = null;
443
+ return;
444
+ }
445
+ this.ahead(conversation, waiting);
446
+ if (conversation.turns.size > 0)
447
+ await this.cancel(conversation);
448
+ }
449
+ ahead(conversation, waiting) {
450
+ const behind = conversation.waiting.findIndex((held) => held.call.at_once !== true);
451
+ conversation.waiting.splice(behind === -1 ? conversation.waiting.length : behind, 0, waiting);
452
+ }
453
+ async steer(conversation, running, waiting) {
454
+ let outcome;
455
+ try {
456
+ ({ outcome } = await running.adapter.connection.agent.request('_session/steering', {
457
+ sessionId: running.sessionId,
458
+ prompt: waiting.content,
459
+ _meta: { steering: { idleBehavior: 'promptRequired' } },
460
+ }));
461
+ }
462
+ catch (error) {
463
+ outcome = error;
464
+ }
465
+ if (outcome === 'promptRequired') {
466
+ this.ahead(conversation, waiting);
467
+ }
468
+ else if (outcome === 'injected' || outcome === 'startedNewTurn') {
469
+ if (outcome === 'injected') {
470
+ for (const turn of conversation.turns)
471
+ turn.steered ||= turn.prompted;
472
+ }
473
+ this.kit.calls.keepResult(waiting.call.input_id, {});
474
+ waiting.settle({});
475
+ }
476
+ else {
477
+ const cause = outcome instanceof Error ? outcome : new Error(`the CLI answered ${JSON.stringify(outcome)}`);
478
+ waiting.settle({ refused: refusal(conversation, new NotStarted(UNSTEERED, { cause })) });
479
+ }
346
480
  }
347
481
  next(conversation) {
348
- if (conversation.sending !== null || conversation.open > 0)
482
+ if (this.stopping || conversation.sending !== null || conversation.turns.size > 0)
349
483
  return;
350
484
  const waiting = conversation.waiting.shift();
351
485
  if (waiting === undefined) {
352
486
  const step = conversation.preparing ?? (conversation.launch === null ? null : 'session');
353
487
  if (conversation.starting !== step)
354
488
  this.starts(conversation, step);
489
+ if (conversation.done && conversation.launch === null)
490
+ void this.stop(conversation).catch(logged);
355
491
  return;
356
492
  }
357
493
  conversation.sending = this.send(conversation, waiting).finally(() => {
@@ -400,7 +536,7 @@ export class Conversations {
400
536
  return;
401
537
  }
402
538
  this.starts(conversation, null);
403
- this.prompt(conversation, [...prompt, ...waiting.content], () => this.kit.calls.keepResult(String(call.input_id), result));
539
+ this.prompt(conversation, [...prompt, ...waiting.content], () => this.kit.calls.keepResult(call.input_id, result));
404
540
  waiting.settle(result);
405
541
  }
406
542
  starts(conversation, step) {
@@ -442,7 +578,7 @@ export class Conversations {
442
578
  const blocks = [];
443
579
  try {
444
580
  const bridge = await step(unbridged, unlessAborted(this.bridged(conversation), killed));
445
- const read = async (path) => audioOf(await step(unbridged, unlessAborted(bridge.tool('inspect', { path }), signal)));
581
+ const read = async (path) => audioOf(await step(unbridged, unlessAborted(bridge.tool('info', { path }), signal)));
446
582
  for (const path of paths) {
447
583
  let answered = await read(path);
448
584
  if (answered === null)
@@ -456,8 +592,7 @@ export class Conversations {
456
592
  throw new Error(`${path} is no longer an audio file`);
457
593
  return address;
458
594
  }, signal);
459
- const transcript = `/kit/conversations/${conversation.id}/messages/${messageId}/transcripts`;
460
- await step(unbridged, unlessAborted(this.kit.house.deliver(transcript, { path, text: said }, () => !signal.aborted), signal));
595
+ await step(unbridged, unlessAborted(this.kit.house.deliver('transcripts/keep', { conversation: conversation.id, message: messageId, path, text: said }, () => !signal.aborted), signal));
461
596
  blocks.push({ type: 'text', text: `${path}\nTranscript: ${said}` });
462
597
  }
463
598
  }
@@ -492,7 +627,11 @@ export class Conversations {
492
627
  void bridging.then((bridge) => bridge.close(), () => undefined);
493
628
  }
494
629
  async interrupt(conversation, turnId) {
495
- if (conversation.running === null || conversation.turn?.id !== turnId)
630
+ if ([...conversation.turns].some((turn) => turn.id === turnId))
631
+ await this.cancel(conversation);
632
+ }
633
+ async cancel(conversation) {
634
+ if (conversation.running === null)
496
635
  return;
497
636
  await conversation.running.adapter.connection.agent.notify('session/cancel', {
498
637
  sessionId: conversation.running.sessionId,
@@ -518,6 +657,9 @@ export class Conversations {
518
657
  if (running === null)
519
658
  return;
520
659
  try {
660
+ if (conversation.options?.find(({ id }) => id === option)?.category === 'mode') {
661
+ throw new Error(`conversation ${conversation.id} keeps the mode its Agent's launch settings name`);
662
+ }
521
663
  running.reader.requested(option, value);
522
664
  const answered = await running.adapter.connection.agent.request('session/set_config_option', {
523
665
  sessionId: running.sessionId,
@@ -548,10 +690,12 @@ export class Conversations {
548
690
  const route = await routed;
549
691
  const reader = readerFor(route.kind);
550
692
  reader.session = sessionId;
693
+ conversation.reader = reader;
551
694
  const app = client({ name: '@agentshouse/kit' })
552
- .onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
553
- .onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
554
- .onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
695
+ .onRequest('session/request_permission', ({ params, signal }) => conversation.afk ? permissionAllowed(params) : this.ask(conversation, 'session/request_permission', params, false, signal))
696
+ .onRequest('elicitation/create', ({ params, signal }) => conversation.afk ? formAnswered(route.kind, params) : this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
697
+ .onRequest('_x.ai/exit_plan_mode', GROK_PLAN, async ({ params, signal }) => conversation.afk ? PLAN_APPROVED : grokPlanAnswer(await this.askForm(conversation, grokPlanForm(params), signal)))
698
+ .onRequest('_x.ai/ask_user_question', GROK_QUESTION, async ({ params, signal }) => conversation.afk ? grokQuestionAnswered(params) : grokQuestionAnswer(await this.askForm(conversation, grokQuestionForm(params), signal)));
555
699
  const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
556
700
  const bridging = this.bridged(conversation);
557
701
  const bridge = await step(unbridged, bridging);
@@ -560,14 +704,15 @@ export class Conversations {
560
704
  throw new Error(KILLED);
561
705
  }
562
706
  conversation.opening = bridge;
563
- const work = workFor(route.kind, route.working_directory, () => this.kit.changed());
707
+ const work = workFor(route.kind, route.working_directory, () => this.kit.changed(), (message) => this.tapped(conversation, reader, message));
564
708
  const scope = new Scope(marker(bridge), randomUUID(), cli);
565
709
  let adapter = null;
566
710
  try {
567
- await unlessAborted(createHowWeWork(bridge), conversation.killed.signal);
568
711
  bridged(bridge);
569
712
  await CLIS[route.kind].allowHouse(bridge.env.PATH);
570
713
  const streamed = await step(NO_CONNECTION, work.open(cli));
714
+ if (this.stopping)
715
+ throw new Error(KILLED);
571
716
  adapter = await step(NO_START, startAdapter(route.kind, cli, route.working_directory, app, (message) => {
572
717
  work.read(message);
573
718
  this.read(conversation, reader, message);
@@ -575,18 +720,17 @@ export class Conversations {
575
720
  void adapter.exited.then(() => this.closeBridge(conversation, bridging, bridge));
576
721
  const agent = adapter.connection.agent;
577
722
  const cwd = route.working_directory;
578
- const _meta = CLIS[route.kind].sessionMeta(bridge.env.HOUSE_BRIDGE, conversation.id);
723
+ const _meta = CLIS[route.kind].sessionMeta(bridge.env.HOUSE_BRIDGE);
579
724
  const resumed = sessionId === null ? null : await this.resume(conversation, route.kind, adapter, { sessionId, cwd, mcpServers: [], _meta }, empty);
580
725
  const opened = resumed ?? (await step(unopened(NO_SESSION), agent.request('session/new', { cwd, mcpServers: [], _meta })));
581
726
  reader.session = opened.sessionId;
582
- if (opened.sessionId !== sessionId && CLIS[route.kind].renames) {
583
- const prompt = [{ type: 'text', text: `/rename ${conversation.id}` }];
584
- await step(unopened(NO_SESSION), agent.request('session/prompt', { sessionId: opened.sessionId, prompt }));
585
- }
727
+ if (opened.sessionId !== conversation.session)
728
+ conversation.state = QUIET;
586
729
  const running = { adapter, bridging, bridge, sessionId: opened.sessionId, killed: false, reader, work, scope };
587
730
  const options = await step(NO_SETTINGS, this.launchSettings(running, route, opened.configOptions ?? []));
588
731
  void work.settled().then(() => scope.record());
589
732
  conversation.running = running;
733
+ adapter.turn(conversation.turns.size > 0);
590
734
  conversation.session = running.sessionId;
591
735
  conversation.options = options;
592
736
  this.facts(conversation);
@@ -653,6 +797,8 @@ export class Conversations {
653
797
  conversation.running = null;
654
798
  conversation.commands = null;
655
799
  conversation.options = null;
800
+ conversation.subagents.clear();
801
+ this.stated(conversation, { running: [] });
656
802
  for (const [id, question] of this.questions) {
657
803
  if (question.conversation === conversation)
658
804
  this.questions.delete(id);
@@ -669,6 +815,16 @@ export class Conversations {
669
815
  if (conversation.options !== null)
670
816
  this.options(conversation, conversation.options);
671
817
  }
818
+ stated(conversation, change) {
819
+ conversation.state = { ...conversation.state, ...change };
820
+ this.stateChanged(conversation, false);
821
+ }
822
+ stateChanged(conversation, again) {
823
+ const state = JSON.stringify(conversation.state);
824
+ if (!again && state === conversation.sentState)
825
+ return;
826
+ conversation.sentState = this.kit.send({ type: 'state', conversation_id: conversation.id, state: conversation.state }) ? state : null;
827
+ }
672
828
  commands(conversation, commands) {
673
829
  conversation.commands = commands;
674
830
  if (conversation.running === null)
@@ -679,11 +835,16 @@ export class Conversations {
679
835
  if (conversation.running === null)
680
836
  return;
681
837
  conversation.options = options;
682
- this.kit.send({ type: 'options', conversation_id: conversation.id, options });
838
+ this.kit.send({ type: 'options', conversation_id: conversation.id, options: options.filter((option) => option.category !== 'mode') });
839
+ const chosen = (category) => {
840
+ const value = options.find((option) => option.category === category)?.currentValue;
841
+ return value === undefined ? null : String(value);
842
+ };
843
+ this.stated(conversation, { model: chosen('model'), effort: chosen('thought_level'), mode: chosen('mode') });
683
844
  }
684
- deliver(conversation, turn, event, body) {
845
+ deliver(conversation, act, request, current) {
685
846
  this.reporting++;
686
- const delivered = conversation.reports.then(async () => this.kit.house.deliver(`/kit/conversations/${conversation.id}/turns/${turn.id}/${event}`, await body));
847
+ const delivered = conversation.reports.then(async () => this.kit.house.deliver(act, await request, current));
687
848
  conversation.reports = delivered
688
849
  .catch(() => undefined)
689
850
  .finally(() => {
@@ -695,21 +856,26 @@ export class Conversations {
695
856
  write(conversation, turn, operation) {
696
857
  if (turn.ended || !this.watched)
697
858
  return;
698
- this.kit.send({ type: 'turn', conversation_id: conversation.id, turn_id: turn.id, ...operation });
859
+ this.kit.send({ type: 'turn', conversation_id: conversation.id, turn_id: turn.id, operation });
699
860
  }
700
861
  replay(conversation, turn) {
701
- for (const operation of turn.parts.operations())
862
+ for (const operation of turn.content.operations())
702
863
  this.write(conversation, turn, operation);
703
864
  }
704
865
  begin(conversation) {
705
866
  const turn = new Turn((operation) => this.write(conversation, turn, operation));
706
- conversation.open++;
707
- void this.deliver(conversation, turn, 'started', {}).catch(logged);
867
+ conversation.turns.add(turn);
868
+ conversation.running?.adapter.turn(true);
869
+ void this.deliver(conversation, 'turns/start', turnOf(conversation, turn))
870
+ .then((answer) => {
871
+ if (answer.run === true)
872
+ turn.quietUntil = Date.now() + ACTIVITY_REPORT_MS;
873
+ })
874
+ .catch(logged);
708
875
  conversation.turn = turn;
709
- if (conversation.context !== null)
710
- turn.parts.measure(conversation.context);
711
- for (const part of conversation.held.splice(0))
712
- turn.parts.start(part);
876
+ this.stated(conversation, { suggestion: null });
877
+ for (const event of conversation.reader?.began() ?? [])
878
+ this.event(conversation, event);
713
879
  this.kit.changed();
714
880
  return turn;
715
881
  }
@@ -718,22 +884,25 @@ export class Conversations {
718
884
  return;
719
885
  if (failed !== null)
720
886
  logged(new Error(`conversation ${conversation.id} turn ${turn.id} failed: ${failed.cause}`));
721
- if (conversation.turn === turn) {
722
- for (const event of conversation.running?.reader.closeTurn() ?? [])
723
- this.apply(conversation, turn, event);
724
- }
887
+ if (conversation.turn === turn)
888
+ conversation.reader?.closeTurn();
725
889
  if (notice !== null)
726
- turn.parts.start({ type: 'marker', marker: 'retry', text: notice });
890
+ turn.content.add({ type: 'notice', kind: 'error', text: notice });
727
891
  turn.ended = true;
728
- conversation.open--;
892
+ conversation.turns.delete(turn);
893
+ conversation.running?.adapter.turn(conversation.turns.size > 0);
729
894
  if (conversation.turn === turn)
730
895
  conversation.turn = null;
896
+ const tokens = conversation.tokens;
897
+ conversation.tokens = null;
898
+ if (tokens !== null)
899
+ this.stated(conversation, { tokens: addedTokens(conversation.state.tokens, tokens) });
731
900
  const body = Promise.allSettled(turn.uploads).then(() => ({
732
- parts: turn.parts.saved(),
733
- context: turn.parts.context,
901
+ ...turnOf(conversation, turn),
902
+ content: { parts: turn.content.parts, tokens, state: conversation.state },
734
903
  ...(failed === null ? {} : { failed: failed.failure }),
735
904
  }));
736
- void this.deliver(conversation, turn, 'ended', body).catch(logged);
905
+ void this.deliver(conversation, 'turns/end', body).catch(logged);
737
906
  this.next(conversation);
738
907
  this.kit.changed();
739
908
  }
@@ -758,11 +927,11 @@ export class Conversations {
758
927
  }
759
928
  else {
760
929
  this.took(turn);
761
- if (conversation.open === 1 && conversation.running === running) {
930
+ if (conversation.turns.size === 1 && conversation.turns.has(turn) && conversation.running === running) {
762
931
  running.adapter.retire();
763
932
  this.detach(conversation, running);
764
933
  }
765
- this.end(conversation, turn, answeredWith(error));
934
+ this.end(conversation, turn, answeredWith(error), cliSaid(error));
766
935
  }
767
936
  });
768
937
  }
@@ -771,19 +940,24 @@ export class Conversations {
771
940
  this.took(turn);
772
941
  return turn;
773
942
  }
774
- ended(conversation) {
943
+ ended(conversation, stop) {
775
944
  const turn = conversation.turn;
776
945
  if (turn === null)
777
946
  return;
778
- if (!turn.prompted) {
779
- this.end(conversation, turn, null);
780
- }
781
- else {
782
- for (const event of conversation.running?.reader.closeTurn() ?? [])
783
- this.apply(conversation, turn, event);
784
- conversation.turn = null;
785
- this.kit.changed();
947
+ const held = stop !== null && !turn.steered && [...conversation.subagents].some((key) => turn.content.holds(key));
948
+ if (!turn.prompted || held) {
949
+ this.took(turn);
950
+ this.end(conversation, turn, stop === 'refusal' ? { failure: 'refused', cause: REFUSED } : null);
951
+ return;
786
952
  }
953
+ if (stop !== null)
954
+ return;
955
+ conversation.reader?.closeTurn();
956
+ conversation.turn = null;
957
+ this.kit.changed();
958
+ }
959
+ askForm(conversation, form, signal) {
960
+ return this.ask(conversation, 'elicitation/create', form, false, signal);
787
961
  }
788
962
  async ask(conversation, method, params, secret, signal) {
789
963
  const turn = this.started(conversation);
@@ -791,7 +965,8 @@ export class Conversations {
791
965
  const answered = new Promise((answer, fail) => {
792
966
  this.questions.set(interactionId, { conversation, answer: (response) => answer(response) });
793
967
  signal.addEventListener('abort', () => answer(null), { once: true });
794
- this.deliver(conversation, turn, 'interactions', {
968
+ this.deliver(conversation, 'conversations/interaction/ask', {
969
+ ...turnOf(conversation, turn),
795
970
  interaction_id: interactionId,
796
971
  request: { method, params },
797
972
  secret,
@@ -832,6 +1007,22 @@ export class Conversations {
832
1007
  read(conversation, reader, message) {
833
1008
  for (const event of reader.read(message))
834
1009
  this.event(conversation, event);
1010
+ this.reportActivity(conversation);
1011
+ }
1012
+ tapped(conversation, reader, message) {
1013
+ for (const event of reader.tap(message))
1014
+ this.event(conversation, event);
1015
+ }
1016
+ reportActivity(conversation) {
1017
+ const turn = conversation.turn;
1018
+ if (turn === null || Date.now() < turn.quietUntil)
1019
+ return;
1020
+ turn.quietUntil = Infinity;
1021
+ void this.deliver(conversation, 'turns/activity/report', turnOf(conversation, turn), () => false)
1022
+ .catch(logged)
1023
+ .finally(() => {
1024
+ turn.quietUntil = Date.now() + ACTIVITY_REPORT_MS;
1025
+ });
835
1026
  }
836
1027
  event(conversation, event) {
837
1028
  switch (event.kind) {
@@ -839,7 +1030,7 @@ export class Conversations {
839
1030
  this.started(conversation);
840
1031
  return;
841
1032
  case 'ended':
842
- this.ended(conversation);
1033
+ this.ended(conversation, event.stop);
843
1034
  return;
844
1035
  case 'commands':
845
1036
  this.commands(conversation, event.commands);
@@ -847,20 +1038,20 @@ export class Conversations {
847
1038
  case 'options':
848
1039
  this.options(conversation, event.options);
849
1040
  return;
850
- case 'context':
851
- conversation.context = { used: event.used, window: event.window };
852
- conversation.turn?.parts.measure(conversation.context);
1041
+ case 'state':
1042
+ this.stated(conversation, event.state);
853
1043
  return;
854
- case 'subagent-done':
855
- this.subagentDone(conversation, event.id, event.result);
1044
+ case 'tokens':
1045
+ conversation.tokens = addedTokens(conversation.tokens, event.tokens);
856
1046
  return;
857
- case 'marker':
858
- case 'image':
859
- if (conversation.turn !== null)
860
- break;
861
- if (event.kind === 'marker' && event.marker === 'job')
862
- conversation.held.push({ type: 'marker', marker: 'job', text: event.text });
1047
+ case 'call':
1048
+ this.called(conversation, event);
863
1049
  return;
1050
+ case 'notice':
1051
+ case 'image':
1052
+ if (conversation.turn === null)
1053
+ return;
1054
+ break;
864
1055
  }
865
1056
  this.apply(conversation, this.started(conversation), event);
866
1057
  }
@@ -872,67 +1063,60 @@ export class Conversations {
872
1063
  apply(conversation, turn, event) {
873
1064
  switch (event.kind) {
874
1065
  case 'text':
875
- case 'reasoning':
876
- turn.parts.write(event.kind, event.id, event.text);
877
- return;
878
- case 'command':
879
- turn.parts.command();
880
- return;
881
- case 'subagent': {
882
- const index = turn.parts.start({ type: 'subagent', description: event.description, status: 'running', result: null });
883
- conversation.subagents.set(event.id, { description: event.description, turn, index });
884
- return;
885
- }
886
- case 'message':
887
- turn.parts.start({ type: 'message', command: event.command, target: event.target });
1066
+ turn.content.write(event.id, event.text);
888
1067
  return;
889
- case 'marker':
890
- turn.parts.start({ type: 'marker', marker: event.marker, text: event.text });
891
- return;
892
- case 'plan':
893
- turn.parts.plan(event.entries);
1068
+ case 'notice':
1069
+ turn.content.add({ type: 'notice', kind: event.notice, text: event.text });
894
1070
  return;
895
1071
  case 'image':
896
- turn.uploads.push(this.image(conversation, turn, turn.parts.reserve(), event.data, event.mediaType));
1072
+ turn.uploads.push(this.image(conversation, turn, event.data, event.mediaType));
897
1073
  this.kit.changed();
898
1074
  return;
899
1075
  }
900
1076
  }
901
- subagentDone(conversation, id, result) {
902
- const subagent = conversation.subagents.get(id);
903
- if (subagent === undefined)
1077
+ // A sub-agent's calls count only in the turn that holds the call that started it, and a call's later changes only in the turn that counted it.
1078
+ called(conversation, event) {
1079
+ if (event.running === true)
1080
+ conversation.subagents.add(event.key);
1081
+ if (event.running === false)
1082
+ conversation.subagents.delete(event.key);
1083
+ const turn = conversation.turn;
1084
+ if (!event.first) {
1085
+ if (turn?.content.holds(event.key))
1086
+ turn.content.call(event.key, event.parent, event.call);
904
1087
  return;
905
- conversation.subagents.delete(id);
906
- if (subagent.turn === conversation.turn) {
907
- subagent.turn.parts.done(subagent.index, result);
1088
+ }
1089
+ if (event.parent !== null) {
1090
+ turn?.content.call(event.key, event.parent, event.call);
908
1091
  return;
909
1092
  }
910
- const part = { type: 'subagent', description: subagent.description, status: 'done', result };
911
- if (conversation.turn === null)
912
- conversation.held.push(part);
913
- else
914
- conversation.turn.parts.start(part);
1093
+ this.started(conversation).content.call(event.key, null, event.call);
915
1094
  }
916
- async image(conversation, turn, reserved, data, mediaType) {
1095
+ async image(conversation, turn, data, mediaType) {
917
1096
  const bytes = Buffer.from(data, 'base64');
918
1097
  const name = `image-${++turn.images}.${mediaType.split('/')[1]}`;
1098
+ const sha256 = createHash('sha256').update(bytes).digest('hex');
919
1099
  try {
920
- const declared = (await this.deliver(conversation, turn, 'images', {
1100
+ const declared = (await this.deliver(conversation, 'turns/images/declare', {
1101
+ ...turnOf(conversation, turn),
921
1102
  name,
922
1103
  media_type: mediaType,
923
1104
  bytes: bytes.length,
924
- sha256: createHash('sha256').update(bytes).digest('hex'),
1105
+ sha256,
925
1106
  }));
926
1107
  const saved = await uploaded(declared.upload, {
1108
+ name,
927
1109
  bytes: bytes.length,
928
- send: (url, start, end) => sentPart(url, bytes.subarray(start, end)),
929
- finish: (upload) => this.kit.house.deliver('/kit/uploads/finish', { upload }),
1110
+ sha256,
1111
+ read: (start, end) => [bytes.subarray(start, end)],
1112
+ send: (url, start, end, headers) => sentPart(url, bytes.subarray(start, end), headers),
1113
+ finish: (upload, partSha256) => this.kit.house.deliver('uploads/finish', { upload, part_sha256: partSha256 }),
930
1114
  });
931
- turn.parts.arrive({ type: 'image', file: saved.path, name, media_type: mediaType }, reserved);
1115
+ turn.content.arrived({ type: 'image', file: saved.path, name, media_type: mediaType });
932
1116
  }
933
1117
  catch (error) {
934
1118
  const cause = error instanceof HouseRefusal ? (refusalOf(error.text)?.text ?? causeOf(error)) : causeOf(error);
935
- turn.parts.arrive({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${cause}` }, reserved);
1119
+ turn.content.arrived({ type: 'notice', kind: 'error', text: `${name} was not saved: ${cause}` });
936
1120
  }
937
1121
  }
938
1122
  }