@sixb/agent 0.2.2 → 0.2.3

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 (45) hide show
  1. package/dist/artifacts/board-previews.d.ts +41 -0
  2. package/dist/artifacts/board-previews.d.ts.map +1 -0
  3. package/dist/artifacts/layout-check/layout-check.d.ts +38 -6
  4. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
  5. package/dist/artifacts/layout-check/overview.d.ts +17 -0
  6. package/dist/artifacts/layout-check/overview.d.ts.map +1 -0
  7. package/dist/artifacts/materialize.d.ts +56 -24
  8. package/dist/artifacts/materialize.d.ts.map +1 -1
  9. package/dist/artifacts/publish-tool.d.ts +35 -9
  10. package/dist/artifacts/publish-tool.d.ts.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +11195 -10160
  14. package/dist/index.js.map +19 -17
  15. package/dist/sandbox-files.d.ts +19 -0
  16. package/dist/sandbox-files.d.ts.map +1 -1
  17. package/dist/subagent-tools.d.ts +3 -1
  18. package/dist/subagent-tools.d.ts.map +1 -1
  19. package/dist/tools/model-spec.d.ts.map +1 -1
  20. package/dist/tools/tool-files.d.ts.map +1 -1
  21. package/dist/types.d.ts +5 -4
  22. package/dist/types.d.ts.map +1 -1
  23. package/package.json +6 -5
  24. package/src/agent-prompt.ts +4 -4
  25. package/src/artifacts/board-previews.ts +218 -0
  26. package/src/artifacts/layout-check/check.cjs +304 -80
  27. package/src/artifacts/layout-check/layout-check.ts +119 -9
  28. package/src/artifacts/layout-check/overview.ts +291 -0
  29. package/src/artifacts/materialize.ts +181 -55
  30. package/src/artifacts/publish-tool.ts +459 -129
  31. package/src/index.ts +1 -0
  32. package/src/run-environment.ts +4 -5
  33. package/src/sandbox-api-context.ts +1 -1
  34. package/src/sandbox-files.ts +86 -0
  35. package/src/skills/sixb-artifacts/SKILL.md +48 -25
  36. package/src/skills/sixb-artifacts/canvas.md +140 -18
  37. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +1 -1
  38. package/src/skills/sixb-artifacts/page.md +1 -1
  39. package/src/skills/sixb-artifacts/references.md +15 -12
  40. package/src/skills/sixb-artifacts/sheet.md +1 -1
  41. package/src/skills/sixb-artifacts/slides.md +1 -1
  42. package/src/subagent-tools.ts +19 -7
  43. package/src/tools/model-spec.ts +3 -2
  44. package/src/tools/tool-files.ts +3 -1
  45. package/src/types.ts +5 -4
@@ -4,24 +4,31 @@ import {
4
4
  AgentToolPublicError,
5
5
  type ArtifactKind,
6
6
  ArtifactRequestError,
7
- AuthorizationError,
8
7
  type JsonValue,
9
- ObjectQueryExecutionError,
10
8
  type Principal,
11
9
  principalsEqual,
12
10
  } from "@sixb/core"
13
- import { ARTIFACT_KINDS, ARTIFACT_THEME_FILE, parseArtifactTheme } from "@sixb/core/artifacts"
11
+ import {
12
+ ARTIFACT_KINDS,
13
+ ARTIFACT_THEME_FILE,
14
+ CANVAS_FILE,
15
+ type Canvas,
16
+ parseArtifactTheme,
17
+ parseCanvas,
18
+ } from "@sixb/core/artifacts"
14
19
  import {
15
20
  AgentExecutionLostError,
16
21
  type AgentRunArtifacts,
17
22
  type AgentRunFileStore,
23
+ type AgentRunMissingPreview,
18
24
  } from "@sixb/core/internal/agents"
19
- import { frameLayout, serializeArtifactQueryResult } from "@sixb/core/internal/artifacts/frames"
25
+ import { frameLayout } from "@sixb/core/internal/artifacts/frames"
20
26
  import {
21
27
  ARTIFACT_LIMITS,
22
- artifactQueryName,
28
+ answerArtifactQueries,
23
29
  isArtifactId,
24
30
  type PublishedArtifact,
31
+ type RefusedBoardPreview,
25
32
  } from "@sixb/core/internal/artifacts/publish"
26
33
  import { inferFileMediaType } from "@sixb/core/internal/blob-storage"
27
34
  import type { JsonObject, ModelTool } from "@sixb/core/models"
@@ -35,7 +42,9 @@ import {
35
42
  } from "../sandbox-files"
36
43
  import type { AgentSandboxHandle } from "../sandbox-handle"
37
44
  import type { AgentFileBudget } from "../tools/tool-files"
45
+ import { storeCheckedPreviews } from "./board-previews"
38
46
  import {
47
+ type CheckedPreview,
39
48
  type CheckedQuery,
40
49
  checkLayout,
41
50
  type LayoutCheck,
@@ -48,8 +57,9 @@ import {
48
57
  } from "./materialize"
49
58
 
50
59
  const CREATE_TOOL = "publish_artifact"
51
- const VERSION_TOOL = "publish_artifact_version"
52
- type PublishToolName = typeof CREATE_TOOL | typeof VERSION_TOOL
60
+ const UPDATE_TOOL = "update_artifact"
61
+ const OPEN_TOOL = "open_artifact"
62
+ type ArtifactToolName = typeof CREATE_TOOL | typeof UPDATE_TOOL | typeof OPEN_TOOL
53
63
  const SANDBOX_TIMEOUT_MS = 30_000
54
64
  /** The kinds the Agent can create today; each lands with its validator, renderer, and skill. */
55
65
  const PUBLISHABLE_KINDS = ARTIFACT_KINDS
@@ -71,7 +81,7 @@ const TITLE_PROPERTY = {
71
81
  export const PUBLISH_ARTIFACT_TOOL_SPEC = {
72
82
  name: CREATE_TOOL,
73
83
  description:
74
- "Publish a new artifact from a file or directory in the sandbox: a deliverable the user opens beside the conversation. Read the sixb-artifacts skill before the first publish. To change an artifact you already published, use publish_artifact_version. Returns the artifact's id and version; a refusal says what to fix.",
84
+ "Publish a new artifact from a file or directory in the sandbox: a deliverable the user opens beside the conversation. Read the sixb-artifacts skill before the first publish. To change an artifact you already published, use update_artifact. Returns the artifact's id and version; a refusal says what to fix.",
75
85
  inputSchema: {
76
86
  type: "object",
77
87
  properties: {
@@ -84,10 +94,10 @@ export const PUBLISH_ARTIFACT_TOOL_SPEC = {
84
94
  } satisfies JsonObject,
85
95
  } as const
86
96
 
87
- export const PUBLISH_ARTIFACT_VERSION_TOOL_SPEC = {
88
- name: VERSION_TOOL,
97
+ export const UPDATE_ARTIFACT_TOOL_SPEC = {
98
+ name: UPDATE_TOOL,
89
99
  description:
90
- "Publish the next version of an artifact you published, from a file or directory in the sandbox. It keeps its kind, and its earlier versions stay readable. $SIXB_ARTIFACTS lists this conversation's artifacts, each with its latest version under $SIXB_ARTIFACTS_DIR/<id>/. Returns the new version; a refusal says what to fix.",
100
+ "Update an artifact of this conversation, or one an object the user may edit holds, from a file or directory in the sandbox: your files replace its current version's, which stays open, and its kind stays. Versions the user created stay as they are. $SIXB_ARTIFACTS lists this conversation's artifacts, each with its current version under $SIXB_ARTIFACTS_DIR/<id>/; open one it does not list with open_artifact first. Returns the version and revision it wrote; a refusal says what to fix.",
91
101
  inputSchema: {
92
102
  type: "object",
93
103
  properties: {
@@ -100,18 +110,36 @@ export const PUBLISH_ARTIFACT_VERSION_TOOL_SPEC = {
100
110
  } satisfies JsonObject,
101
111
  } as const
102
112
 
113
+ export const OPEN_ARTIFACT_TOOL_SPEC = {
114
+ name: OPEN_TOOL,
115
+ description:
116
+ "Open an artifact $SIXB_ARTIFACTS does not list, such as one a project object holds: its current version is installed under $SIXB_ARTIFACTS_DIR/<id>/ and listed in $SIXB_ARTIFACTS, to read it, or to revise it with update_artifact when the user may change it. Publishes nothing. Returns its title, revision, and whether the user may only read it.",
117
+ inputSchema: {
118
+ type: "object",
119
+ properties: {
120
+ id: { type: "string", description: "The artifact's id, such as art_k3m9q2x7tp." },
121
+ },
122
+ required: ["id"],
123
+ additionalProperties: false,
124
+ } satisfies JsonObject,
125
+ } as const
126
+
103
127
  export interface PublishArtifactToolInput {
104
128
  readonly path: string
105
129
  readonly kind: PublishableKind
106
130
  readonly title: string
107
131
  }
108
132
 
109
- export interface PublishArtifactVersionToolInput {
133
+ export interface UpdateArtifactToolInput {
110
134
  readonly id: string
111
135
  readonly path: string
112
136
  readonly title: string
113
137
  }
114
138
 
139
+ export interface OpenArtifactToolInput {
140
+ readonly id: string
141
+ }
142
+
115
143
  interface PublishToolsInput {
116
144
  /** The run's artifacts, through its session: what it reads as its requester, and publishes. */
117
145
  readonly artifacts: AgentRunArtifacts
@@ -128,14 +156,22 @@ interface PublishToolsInput {
128
156
  }
129
157
 
130
158
  /**
131
- * `publish_artifact` and `publish_artifact_version`: each reads a file or a directory from the
132
- * sandbox, stores its bytes, and publishes them through the run's session, which applies a run's
133
- * rules (see `AgentRunArtifacts.publish`). The version exists when the tool returns, so the
159
+ * `publish_artifact` and `update_artifact`: each reads a file or a directory from the sandbox,
160
+ * stores its bytes, and publishes them through the run's session, which applies a run's rules (see
161
+ * `AgentRunArtifacts.publish`). An update replaces the open version's content, or opens the next
162
+ * version after one the user created. What it wrote exists when the tool returns, so the
134
163
  * conversation shows it mid-turn and a cancelled run keeps it.
164
+ *
165
+ * `open_artifact` installs one the conversation does not list, as the requester reads it, so an
166
+ * update starts from what it holds.
135
167
  */
136
168
  export function createPublishArtifactTools(
137
169
  input: PublishToolsInput
138
- ): readonly [ModelTool<PublishArtifactToolInput>, ModelTool<PublishArtifactVersionToolInput>] {
170
+ ): readonly [
171
+ ModelTool<PublishArtifactToolInput>,
172
+ ModelTool<UpdateArtifactToolInput>,
173
+ ModelTool<OpenArtifactToolInput>,
174
+ ] {
139
175
  return [
140
176
  {
141
177
  ...PUBLISH_ARTIFACT_TOOL_SPEC,
@@ -146,18 +182,25 @@ export function createPublishArtifactTools(
146
182
  errorText: (error) => publishErrorText(error, CREATE_TOOL),
147
183
  },
148
184
  {
149
- ...PUBLISH_ARTIFACT_VERSION_TOOL_SPEC,
150
- parseInput: parsePublishArtifactVersionInput,
185
+ ...UPDATE_ARTIFACT_TOOL_SPEC,
186
+ parseInput: parseUpdateArtifactInput,
151
187
  execute: (request, { signal }) =>
152
- publish(input, VERSION_TOOL, { ...request, target: { artifactId: request.id } }, signal),
153
- toModelOutput: (output) => ({ type: "text", value: publishSummary(output, VERSION_TOOL) }),
154
- errorText: (error) => publishErrorText(error, VERSION_TOOL),
188
+ publish(input, UPDATE_TOOL, { ...request, target: { artifactId: request.id } }, signal),
189
+ toModelOutput: (output) => ({ type: "text", value: publishSummary(output, UPDATE_TOOL) }),
190
+ errorText: (error) => publishErrorText(error, UPDATE_TOOL),
191
+ },
192
+ {
193
+ ...OPEN_ARTIFACT_TOOL_SPEC,
194
+ parseInput: parseOpenArtifactInput,
195
+ execute: (request, { signal }) => open(input, request.id, signal),
196
+ toModelOutput: (output) => ({ type: "text", value: openSummary(output) }),
197
+ errorText: (error) => publishErrorText(error, OPEN_TOOL),
155
198
  },
156
199
  ]
157
200
  }
158
201
 
159
202
  /** A run that lost its conversation stores nothing, and the trace says so instead of "an error". */
160
- function publishErrorText(error: unknown, tool: PublishToolName): string {
203
+ function publishErrorText(error: unknown, tool: ArtifactToolName): string {
161
204
  return error instanceof AgentExecutionLostError
162
205
  ? publishError(tool, "this run no longer holds its conversation, so nothing was published")
163
206
  .message
@@ -167,29 +210,47 @@ function publishErrorText(error: unknown, tool: PublishToolName): string {
167
210
  interface PublishRequest {
168
211
  readonly path: string
169
212
  readonly title: string
170
- /** A new artifact of this kind, or the next version of this artifact. */
213
+ /** A new artifact of this kind, or this artifact's latest version. */
171
214
  readonly target: { readonly kind: PublishableKind } | { readonly artifactId: string }
172
215
  }
173
216
 
174
217
  async function publish(
175
218
  input: PublishToolsInput,
176
- tool: PublishToolName,
219
+ tool: ArtifactToolName,
177
220
  request: PublishRequest,
178
221
  signal: AbortSignal
179
222
  ): Promise<JsonValue> {
180
223
  signal.throwIfAborted()
224
+ const installed = await input.installed
225
+
226
+ // One the conversation does not list, such as an artifact an object holds, is opened first: the
227
+ // Agent revises what it holds instead of writing over it unseen.
228
+ if (
229
+ "artifactId" in request.target &&
230
+ installed.revisionOf(request.target.artifactId) === undefined
231
+ ) {
232
+ const { artifactId } = request.target
233
+ if (!(await input.artifacts.get(artifactId))) throw noArtifact(tool, artifactId)
234
+
235
+ throw publishError(
236
+ tool,
237
+ `artifact '${artifactId}' is not open in this conversation, so nothing was published: call ${OPEN_TOOL} with its id, then revise its copy and update it`
238
+ )
239
+ }
240
+
181
241
  const kind: ArtifactKind =
182
242
  "kind" in request.target
183
243
  ? request.target.kind
184
- : (await updatableArtifact(input, request.target.artifactId, tool)).kind
244
+ : (await updatableArtifact(input, request.target.artifactId, tool, installed)).kind
185
245
  const handle = await input.resolveSandbox()
186
246
  const sources = await listSources(handle, request.path, kind, tool, signal)
187
247
 
188
- // A version of an installed artifact is made from its copy: publishing past the version the copy
189
- // holds would drop whatever was published since.
190
- const installed = await input.installed
191
- const baseVersion =
192
- "artifactId" in request.target ? installed.versionOf(request.target.artifactId) : undefined
248
+ // An installed artifact is updated from its copy: writing past the revision the copy holds would
249
+ // drop whatever was written since. A canvas is merged instead, from the copy's files.
250
+ const base =
251
+ "artifactId" in request.target ? installed.baseOf(request.target.artifactId) : undefined
252
+ const baseRevision =
253
+ "artifactId" in request.target ? installed.revisionOf(request.target.artifactId) : undefined
193
254
 
194
255
  const totalBytes = sources.reduce((sum, source) => sum + source.sizeBytes, 0)
195
256
  if (totalBytes > ARTIFACT_LIMITS.maxVersionBytes) {
@@ -217,8 +278,8 @@ async function publish(
217
278
  if (bytes.byteLength !== source.sizeBytes) {
218
279
  throw publishError(tool, `'${source.path}' changed while it was being read; publish again`)
219
280
  }
220
- // Blob storage keeps identical bytes once, so a file the run already stored, such as one a
221
- // next version keeps, costs the budget nothing again.
281
+ // Blob storage keeps identical bytes once, so a file the run already stored, such as one an
282
+ // update keeps, costs the budget nothing again.
222
283
  reservation.addContent(createHash("sha256").update(bytes).digest("hex"), bytes.byteLength)
223
284
  const fileName = posix.basename(source.path)
224
285
  const fileRef = await input.blobStorage.put({
@@ -237,11 +298,14 @@ async function publish(
237
298
  ...("artifactId" in request.target
238
299
  ? {
239
300
  artifactId: request.target.artifactId,
240
- ...(baseVersion === undefined ? {} : { baseVersion }),
301
+ ...(baseRevision === undefined ? {} : { baseRevision }),
302
+ ...(base ? { baseFiles: base.files } : {}),
241
303
  }
242
304
  : { kind }),
243
305
  title: request.title,
244
306
  files,
307
+ // The layout check pictures a canvas's boards as it checks them.
308
+ rendersPreviews: kind === "canvas",
245
309
  })
246
310
  } catch (error) {
247
311
  // Nothing was published, so the bytes do not count against the run.
@@ -251,12 +315,12 @@ async function publish(
251
315
  error instanceof ArtifactRequestError &&
252
316
  error.code === "artifact_moved" &&
253
317
  "artifactId" in request.target &&
254
- baseVersion !== undefined
318
+ baseRevision !== undefined
255
319
  ) {
256
320
  throw await artifactMoved(
257
321
  input,
258
322
  { installed, handle },
259
- { artifactId: request.target.artifactId, baseVersion },
323
+ { artifactId: request.target.artifactId, baseRevision },
260
324
  signal
261
325
  )
262
326
  }
@@ -272,27 +336,52 @@ async function publish(
272
336
  throw toPublishError(error, tool)
273
337
  }
274
338
 
275
- // The version exists by now: nothing below may read as a failed publish, which the Agent would
339
+ // The write exists by now: nothing below may read as a failed publish, which the Agent would
276
340
  // publish again.
277
- try {
278
- // Revising from $SIXB_ARTIFACTS_DIR must start from this version, not the one before.
279
- await installed.replace(handle.sandbox, published, contents, signal)
280
- } catch (error) {
281
- if (signal.aborted) throw error
282
- console.warn(
283
- `[SixbAgent] Could not install version ${published.version.version} of artifact '${published.artifact.id}':`,
284
- error
285
- )
341
+ const { artifact, version } = published
342
+ // Merged with what others wrote since, the version holds more than the Agent's files: the copy
343
+ // and the check take what it holds.
344
+ const written = published.merged ? await mergedFiles(input, published, signal) : contents
345
+ // The folder the Agent published from moves with the installed copy from now on: after a merge
346
+ // it takes the merged result, and its next update, from there, holds its own changes alone.
347
+ const folder = publishedFolder(handle, request.path, sources)
348
+ if (folder) installed.publishedFrom(artifact.id, folder)
349
+ // Revising from $SIXB_ARTIFACTS_DIR must start from this revision, not the one before. When the
350
+ // merged result cannot be read or installed, the copy, the folder and the base all stay as they
351
+ // were: the next update is merged from that base, and keeps what others wrote.
352
+ let copy: string | undefined
353
+ let installedRevision = written !== undefined
354
+ if (written) {
355
+ try {
356
+ await installed.replace(handle.sandbox, published, written, signal)
357
+ copy = installed.directoryOf(artifact.id)
358
+ } catch (error) {
359
+ if (signal.aborted) throw error
360
+ installedRevision = false
361
+ console.warn(
362
+ `[SixbAgent] Could not install revision ${version.revision} of artifact '${artifact.id}':`,
363
+ error
364
+ )
365
+ }
286
366
  }
287
367
  // A published deck, page, or canvas is laid out in the sandbox's browser, so the Agent sees what
288
- // the reader will, and fixes it in its next version.
368
+ // the reader will, and fixes it in its next update.
289
369
  const layout = frameLayout(kind)
290
- const { outline, entry } = published.version
370
+ const { outline, entry } = version
291
371
  const root = layout ? sources.find((source) => source.path === entry) : undefined
292
- const bytesOf = (path: string) => contents.find((file) => file.path === path)?.bytes
293
- const themeFile = contents.find((file) => file.path === ARTIFACT_THEME_FILE)
372
+ // A merged version is checked from its installed copy, which holds what it holds.
373
+ const checked = published.merged ? (written && copy ? written : undefined) : contents
374
+ const checkDirectory = published.merged
375
+ ? copy && posix.resolve(handle.sandbox.workingDirectory, copy)
376
+ : root && posix.dirname(root.absolutePath)
377
+ const bytesOf = (path: string) => checked?.find((file) => file.path === path)?.bytes
378
+ const themeFile = checked?.find((file) => file.path === ARTIFACT_THEME_FILE)
294
379
  // Publishing has read it already: a version with a theme.json it refused is not here.
295
380
  const theme = themeFile ? parseArtifactTheme(new TextDecoder().decode(themeFile.bytes)) : null
381
+ // A reader sees a canvas's boards as pictures until they open one: the check takes those its
382
+ // boards miss, in every mode. A board kept as it was keeps the pictures it had.
383
+ const missing = outline.kind === "canvas" ? await missingPreviews(input.artifacts, published) : []
384
+ const pictured = new Set(missing.map(({ board }) => board))
296
385
  // What the check opens: a canvas's boards, each at its own size, or the entry.
297
386
  const pages =
298
387
  outline.kind === "canvas"
@@ -301,25 +390,41 @@ async function publish(
301
390
  boards: outline.items.flatMap((item) => {
302
391
  const html = item.type === "board" ? bytesOf(item.file) : undefined
303
392
  return item.type === "board" && html
304
- ? [{ id: item.id, file: item.file, w: item.w, h: item.h, html }]
393
+ ? [
394
+ {
395
+ id: item.id,
396
+ file: item.file,
397
+ w: item.w,
398
+ h: item.h,
399
+ html,
400
+ pictured: pictured.has(item.id),
401
+ },
402
+ ]
305
403
  : []
306
404
  }),
405
+ ...canvasOf(bytesOf(CANVAS_FILE)),
307
406
  }
308
407
  : layout && bytesOf(entry)
309
408
  ? { layout, entry: bytesOf(entry) as Uint8Array }
310
409
  : null
311
410
  let check: LayoutCheck | undefined
312
411
  let queries: CheckedQueries = { answers: {}, warnings: [] }
313
- if (root && pages && (pages.layout !== "canvas" || pages.boards.length > 0)) {
412
+ if (
413
+ checked &&
414
+ checkDirectory &&
415
+ pages &&
416
+ (pages.layout !== "canvas" || pages.boards.length > 0)
417
+ ) {
314
418
  queries = await checkedQueries(input.artifacts, published)
315
419
  signal.throwIfAborted()
316
420
  try {
317
421
  check = await checkLayout({
318
422
  handle,
319
423
  ...pages,
320
- directory: posix.dirname(root.absolutePath),
321
- files: contents.map((file) => file.path),
322
- name: `${published.artifact.id}-v${published.version.version}`,
424
+ directory: checkDirectory,
425
+ files: checked.map((file) => file.path),
426
+ // A revision's check: two updates of one open version never share their pictures.
427
+ name: `${artifact.id}-r${version.revision}`,
323
428
  ...(theme && "theme" in theme ? { theme: theme.theme } : {}),
324
429
  queries: queries.answers,
325
430
  signal,
@@ -330,15 +435,27 @@ async function publish(
330
435
  check = { status: "skipped", reason: "the check failed in the sandbox" }
331
436
  }
332
437
  }
438
+ const previewWarnings =
439
+ check?.status === "checked" && missing.length > 0
440
+ ? await storePreviews({ input, handle, published, missing, checked: check.previews, signal })
441
+ : []
333
442
  return {
334
- artifactId: published.artifact.id,
335
- version: published.version.version,
336
- kind: published.artifact.kind,
337
- title: published.version.title,
443
+ artifactId: artifact.id,
444
+ version: version.version,
445
+ revision: version.revision,
446
+ // An Agent's write always leaves the version open: only the user creates a version.
447
+ open: version.frozenAt === undefined,
448
+ ...(published.merged ? { mergedSince: baseRevision ?? null } : {}),
449
+ ...(installedRevision
450
+ ? {}
451
+ : { notInstalled: true, nextUpdateFrom: installed.revisionOf(artifact.id) ?? null }),
452
+ kind: artifact.kind,
453
+ title: version.title,
338
454
  warnings: [
339
455
  ...published.warnings,
340
456
  ...queries.warnings,
341
457
  ...(check?.status === "checked" ? check.warnings : []),
458
+ ...previewWarnings,
342
459
  ].map(({ code, message, part }) => ({
343
460
  code,
344
461
  message,
@@ -349,12 +466,116 @@ async function publish(
349
466
  : {
350
467
  layoutCheck:
351
468
  check.status === "checked"
352
- ? { screenshots: [...check.screenshots] }
469
+ ? {
470
+ screenshots: [...check.screenshots],
471
+ ...(check.overview ? { overview: check.overview } : {}),
472
+ }
353
473
  : { skipped: check.reason },
354
474
  }),
355
475
  }
356
476
  }
357
477
 
478
+ /**
479
+ * The files of a version merged with what others wrote, as its bytes; none when they cannot be
480
+ * read, and the copy, the folder and the base of the next update then stay as they were.
481
+ */
482
+ async function mergedFiles(
483
+ input: PublishToolsInput,
484
+ published: PublishedArtifact,
485
+ signal: AbortSignal
486
+ ): Promise<PublishedArtifactFile[] | undefined> {
487
+ try {
488
+ return await readArtifactVersionFiles(input.blobStorage, published.version, signal)
489
+ } catch (error) {
490
+ if (signal.aborted) throw error
491
+ console.warn(
492
+ `[SixbAgent] Could not read revision ${published.version.revision} of '${published.artifact.id}', merged:`,
493
+ error
494
+ )
495
+ return undefined
496
+ }
497
+ }
498
+
499
+ /**
500
+ * The boards of the revision just written that miss a picture. A preview never costs a publish:
501
+ * when they cannot be read, the check pictures none and the worker renders what is missing.
502
+ */
503
+ async function missingPreviews(
504
+ artifacts: Pick<AgentRunArtifacts, "missingPreviews">,
505
+ published: PublishedArtifact
506
+ ): Promise<readonly AgentRunMissingPreview[]> {
507
+ try {
508
+ return await artifacts.missingPreviews(writtenAt(published))
509
+ } catch (error) {
510
+ console.warn(
511
+ `[SixbAgent] Could not read which boards of '${published.artifact.id}' miss a preview:`,
512
+ error
513
+ )
514
+ return []
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Hands the pictures the check took over as the revision's previews, and warns of each board one
520
+ * of whose pictures was not kept: it shows its outline in that size and mode. The write exists by
521
+ * now, so a failure is only logged: the worker renders what is still missing, and an update
522
+ * written since gets its own.
523
+ */
524
+ async function storePreviews(context: {
525
+ readonly input: PublishToolsInput
526
+ readonly handle: AgentSandboxHandle
527
+ readonly published: PublishedArtifact
528
+ readonly missing: readonly AgentRunMissingPreview[]
529
+ readonly checked: readonly CheckedPreview[]
530
+ readonly signal: AbortSignal
531
+ }): Promise<LayoutWarning[]> {
532
+ const { input, published, signal } = context
533
+ try {
534
+ const { previews, dropped } = await storeCheckedPreviews({
535
+ handle: context.handle,
536
+ checked: context.checked,
537
+ missing: context.missing,
538
+ blobStorage: input.blobStorage,
539
+ signal,
540
+ })
541
+ const refused = await input.artifacts.storePreviews({ ...writtenAt(published), previews })
542
+ return unkeptPreviewWarnings([...dropped, ...refused])
543
+ } catch (error) {
544
+ if (signal.aborted) throw error
545
+ console.warn(
546
+ `[SixbAgent] Could not keep the previews of revision ${published.version.revision} of '${published.artifact.id}':`,
547
+ error
548
+ )
549
+ return []
550
+ }
551
+ }
552
+
553
+ /** The version a publish wrote, as it left its content. */
554
+ function writtenAt({ artifact, version }: PublishedArtifact) {
555
+ return { artifactId: artifact.id, version: version.version, updatedAt: version.updatedAt }
556
+ }
557
+
558
+ /** One warning per board whose pictures were not all kept, naming each and why. */
559
+ function unkeptPreviewWarnings(unkept: readonly RefusedBoardPreview[]): LayoutWarning[] {
560
+ const boards = [...new Set(unkept.map(({ board }) => board))]
561
+ return boards.map((board) => {
562
+ const pictures = unkept
563
+ .filter((picture) => picture.board === board)
564
+ .map(({ theme, size, reason }) => `the ${size} one in ${theme} mode (${reason})`)
565
+ return {
566
+ code: "preview_not_kept",
567
+ part: board,
568
+ message: `Board '${board}' has no preview for ${pictures.join(", ")}: readers see its outline there until they open it.`,
569
+ }
570
+ })
571
+ }
572
+
573
+ /** A canvas's items, for the check's picture of it as it opens; none when it cannot be read. */
574
+ function canvasOf(bytes: Uint8Array | undefined): { readonly canvas?: Canvas } {
575
+ const parsed = bytes ? parseCanvas(new TextDecoder().decode(bytes)) : undefined
576
+ return parsed && "canvas" in parsed ? { canvas: parsed.canvas } : {}
577
+ }
578
+
358
579
  interface CheckedQueries {
359
580
  readonly answers: Readonly<Record<string, CheckedQuery>>
360
581
  readonly warnings: readonly LayoutWarning[]
@@ -371,22 +592,10 @@ async function checkedQueries(
371
592
  published: PublishedArtifact
372
593
  ): Promise<CheckedQueries> {
373
594
  const { artifact, version } = published
374
- const names = version.files.flatMap((file) => {
375
- const name = artifactQueryName(file.path)
376
- return name === undefined ? [] : [name]
377
- })
378
-
379
- const answers = await Promise.all(
380
- names.map(async (name): Promise<readonly [string, CheckedQuery]> => {
381
- try {
382
- const result = await reader.query(artifact.id, name, { version: version.version })
383
- if (!result) throw new Error(`[SixbAgent] Version ${version.version} is missing.`)
384
-
385
- return [name, { result: serializeArtifactQueryResult(result) }]
386
- } catch (error) {
387
- return [name, { error: queryErrorText(error) }]
388
- }
389
- })
595
+ const answers = Object.entries(
596
+ await answerArtifactQueries(version, (name) =>
597
+ reader.query(artifact.id, name, { version: version.version })
598
+ )
390
599
  )
391
600
 
392
601
  return {
@@ -404,39 +613,34 @@ async function checkedQueries(
404
613
  }
405
614
  }
406
615
 
407
- /** A refusal in the words the API gives a reader; anything else stays internal. */
408
- function queryErrorText(error: unknown): string {
409
- if (
410
- error instanceof ArtifactRequestError ||
411
- error instanceof AuthorizationError ||
412
- error instanceof ObjectQueryExecutionError
413
- ) {
414
- return /[.!?]$/.test(error.message) ? error.message : `${error.message}.`
415
- }
416
-
417
- console.warn("[SixbAgent] A query of the published version did not run:", error)
418
- return "[Sixb] The query could not be read."
419
- }
420
-
421
616
  /** How storing refuses an artifact the requester may not publish to: as if it did not exist. */
422
617
  const UNREACHABLE: ReadonlySet<string> = new Set(["artifact_not_found", "not_shared", "read_only"])
423
618
 
424
619
  /**
425
- * The artifact to publish a version of: one the requester owns, or one this conversation shares
426
- * that they take part in. Another is refused as if it did not exist, even one they could update
427
- * from another conversation: publishing here would share it in this one.
620
+ * The artifact to update: one the requester owns, or one this conversation shares that they take
621
+ * part in. Another is refused as if it did not exist, even one they could update from another
622
+ * conversation: writing it here would share it in this one.
428
623
  */
429
624
  async function updatableArtifact(
430
625
  input: PublishToolsInput,
431
626
  artifactId: string,
432
- tool: PublishToolName
627
+ tool: ArtifactToolName,
628
+ installed?: InstalledArtifacts
433
629
  ): Promise<ArtifactRecord> {
434
630
  const artifact = await input.artifacts.updatable(artifactId)
435
- if (!artifact) throw noArtifact(tool, artifactId)
436
- return artifact
631
+ if (artifact) return artifact
632
+
633
+ // One installed to read is named as such: it exists, and the Agent was told it reads it.
634
+ if (installed?.readOnly(artifactId)) {
635
+ throw publishError(
636
+ tool,
637
+ `you can read artifact '${artifactId}' but not change it, so nothing was published`
638
+ )
639
+ }
640
+ throw noArtifact(tool, artifactId)
437
641
  }
438
642
 
439
- function noArtifact(tool: PublishToolName, artifactId: string): AgentToolPublicError {
643
+ function noArtifact(tool: ArtifactToolName, artifactId: string): AgentToolPublicError {
440
644
  return publishError(
441
645
  tool,
442
646
  `there is no artifact '${artifactId}'. $SIXB_ARTIFACTS lists this conversation's artifacts; to create a new one, call ${CREATE_TOOL}`
@@ -444,9 +648,9 @@ function noArtifact(tool: PublishToolName, artifactId: string): AgentToolPublicE
444
648
  }
445
649
 
446
650
  /**
447
- * The refusal for a version made from a copy the artifact has moved past, such as a person saving
448
- * in the app while the run works. The version it moved to replaces the copy, so the Agent starts
449
- * again from it instead of publishing over it.
651
+ * The refusal for an update made from a copy the artifact has moved past, such as a person saving
652
+ * in the app while the run works. What it moved to replaces the copy, so the Agent starts again
653
+ * from it instead of writing over it.
450
654
  */
451
655
  async function artifactMoved(
452
656
  input: PublishToolsInput,
@@ -454,50 +658,109 @@ async function artifactMoved(
454
658
  installed,
455
659
  handle,
456
660
  }: { readonly installed: InstalledArtifacts; readonly handle: AgentSandboxHandle },
457
- { artifactId, baseVersion }: { readonly artifactId: string; readonly baseVersion: number },
661
+ { artifactId, baseRevision }: { readonly artifactId: string; readonly baseRevision: number },
458
662
  signal: AbortSignal
459
663
  ): Promise<AgentToolPublicError> {
460
664
  // Read as the requester: whatever moved it, it is a version they can read.
461
- const artifact = await updatableArtifact(input, artifactId, VERSION_TOOL)
665
+ const artifact = await updatableArtifact(input, artifactId, UPDATE_TOOL)
462
666
  const latest = await input.artifacts.getVersion(artifactId, artifact.latestVersion)
463
667
  if (!latest) {
464
668
  throw new Error(`[SixbAgent] Version ${artifact.latestVersion} of '${artifactId}' is missing.`)
465
669
  }
466
670
 
467
- const author = principalsEqual(latest.author, input.owner)
468
- ? "its owner"
469
- : `${latest.author.type} '${latest.author.id}'`
671
+ const named = (principal: Principal) =>
672
+ principalsEqual(principal, input.owner) ? "its owner" : `${principal.type} '${principal.id}'`
673
+ const author = named(latest.author)
470
674
  const where =
471
675
  latest.origin === undefined
472
676
  ? `by ${author} outside a conversation, such as in the app`
473
677
  : latest.origin.threadId === input.threadId
474
678
  ? "earlier in this conversation"
475
679
  : `by ${author} in another conversation`
476
- const moved = `artifact '${artifactId}' moved on from version ${baseVersion}, which you started from: version ${latest.version} was published ${where}, so nothing was published`
680
+ const created = latest.frozenBy
681
+ ? `, and then created as a version by ${named(latest.frozenBy)}`
682
+ : ""
683
+ const moved = `artifact '${artifactId}' changed since revision ${baseRevision}, which you started from: it is at revision ${latest.revision}, whose version ${latest.version} was last written ${where}${created}, so nothing was published`
477
684
 
685
+ let folder: string | undefined
478
686
  try {
479
687
  const files = await readArtifactVersionFiles(input.blobStorage, latest, signal)
480
- await installed.replace(handle.sandbox, { artifact, version: latest }, files, signal, {
688
+ folder = await installed.replace(handle.sandbox, { artifact, version: latest }, files, signal, {
481
689
  edited: latest.origin?.threadId !== input.threadId,
482
690
  })
483
691
  } catch (error) {
484
692
  if (signal.aborted) throw error
485
693
  console.warn(
486
- `[SixbAgent] Could not install version ${latest.version} of artifact '${artifactId}':`,
694
+ `[SixbAgent] Could not install revision ${latest.revision} of artifact '${artifactId}':`,
487
695
  error
488
696
  )
489
697
  return publishError(
490
- VERSION_TOOL,
491
- `${moved}. Version ${latest.version} could not be installed in the sandbox, so tell the user you could not build on it`
698
+ UPDATE_TOOL,
699
+ `${moved}. Its revision ${latest.revision} could not be installed in the sandbox, so tell the user you could not build on it`
492
700
  )
493
701
  }
494
702
 
495
703
  return publishError(
496
- VERSION_TOOL,
497
- `${moved}. $SIXB_ARTIFACTS lists version ${latest.version}, installed under $SIXB_ARTIFACTS_DIR/${artifactId}/: start again from it as it is, keep its changes, make yours again, and publish`
704
+ UPDATE_TOOL,
705
+ `${moved}. $SIXB_ARTIFACTS lists revision ${latest.revision}, installed under $SIXB_ARTIFACTS_DIR/${artifactId}/${folder ? ` and written into ${folder}, the folder you published it from` : ""}: start again from it as it is, keep its changes, make yours again, and update it`
498
706
  )
499
707
  }
500
708
 
709
+ /**
710
+ * Installs the artifact's latest version under `$SIXB_ARTIFACTS_DIR/<id>/`, as the requester reads
711
+ * it: to read only, when they may not change it. Opening shares nothing: the conversation shares it
712
+ * once the Agent updates it from that copy.
713
+ */
714
+ async function open(
715
+ input: PublishToolsInput,
716
+ artifactId: string,
717
+ signal: AbortSignal
718
+ ): Promise<JsonValue> {
719
+ signal.throwIfAborted()
720
+ const artifact = await input.artifacts.get(artifactId)
721
+ if (!artifact) throw publishError(OPEN_TOOL, `there is no artifact '${artifactId}' you can read`)
722
+
723
+ const [installed, updatable, latest] = await Promise.all([
724
+ input.installed,
725
+ input.artifacts.updatable(artifactId),
726
+ input.artifacts.getVersion(artifactId, artifact.latestVersion),
727
+ ])
728
+ if (!latest) {
729
+ throw new Error(`[SixbAgent] Version ${artifact.latestVersion} of '${artifactId}' is missing.`)
730
+ }
731
+
732
+ const readOnly = updatable === null
733
+ try {
734
+ const { sandbox } = await input.resolveSandbox()
735
+ const files = await readArtifactVersionFiles(input.blobStorage, latest, signal)
736
+ await installed.replace(sandbox, { artifact, version: latest }, files, signal, {
737
+ edited: latest.origin?.threadId !== input.threadId,
738
+ readOnly,
739
+ })
740
+ } catch (error) {
741
+ if (signal.aborted) throw error
742
+ console.warn(
743
+ `[SixbAgent] Could not install revision ${latest.revision} of artifact '${artifactId}':`,
744
+ error
745
+ )
746
+ throw publishError(
747
+ OPEN_TOOL,
748
+ `its revision ${latest.revision} could not be installed in the sandbox, so tell the user you could not open it`
749
+ )
750
+ }
751
+
752
+ const directory = installed.directoryOf(artifactId)
753
+ return {
754
+ artifactId,
755
+ kind: artifact.kind,
756
+ title: latest.title,
757
+ version: latest.version,
758
+ revision: latest.revision,
759
+ readOnly,
760
+ ...(directory ? { directory } : {}),
761
+ }
762
+ }
763
+
501
764
  interface PublishSource {
502
765
  /** The file's path in the artifact. */
503
766
  readonly path: string
@@ -512,11 +775,24 @@ interface PublishSource {
512
775
  * a dot. A single file publishes alone: a document's Markdown as `document.md`, any other file
513
776
  * under its own name.
514
777
  */
778
+ /** The folder the files were published from, when they were a folder's: one file has none. */
779
+ function publishedFolder(
780
+ handle: AgentSandboxHandle,
781
+ path: string,
782
+ sources: readonly PublishSource[]
783
+ ): { readonly path: string; readonly absolute: string } | undefined {
784
+ const absolute = resolveSandboxPath(handle, path)
785
+ const inFolder = sources.every(
786
+ (source) => source.absolutePath === posix.join(absolute, source.path)
787
+ )
788
+ return inFolder ? { path, absolute } : undefined
789
+ }
790
+
515
791
  async function listSources(
516
792
  handle: AgentSandboxHandle,
517
793
  path: string,
518
794
  kind: ArtifactKind,
519
- tool: PublishToolName,
795
+ tool: ArtifactToolName,
520
796
  signal: AbortSignal
521
797
  ): Promise<PublishSource[]> {
522
798
  let absolutePath: string
@@ -580,15 +856,56 @@ async function listSources(
580
856
  }))
581
857
  }
582
858
 
583
- function publishSummary(output: JsonValue, tool: PublishToolName): string {
859
+ /** What the Agent is told of an artifact it opened: where to read it, and whether it may change it. */
860
+ function openSummary(output: JsonValue): string {
584
861
  if (typeof output !== "object" || output === null || Array.isArray(output)) {
585
862
  return JSON.stringify(output)
586
863
  }
864
+
865
+ const where =
866
+ typeof output.directory === "string"
867
+ ? `installed under ${output.directory}/`
868
+ : "listed in $SIXB_ARTIFACTS, but too large to install"
869
+ return [
870
+ `Opened "${String(output.title)}": artifact ${String(output.artifactId)}, version ${String(output.version)} at revision ${String(output.revision)}, ${where}.`,
871
+ output.readOnly === true
872
+ ? "The user may read it but not change it: do not update it."
873
+ : `To change it, edit a copy of that folder and call ${UPDATE_TOOL} with this id: this conversation then shares it.`,
874
+ ].join(" ")
875
+ }
876
+
877
+ function publishSummary(output: JsonValue, tool: ArtifactToolName): string {
878
+ if (typeof output !== "object" || output === null || Array.isArray(output)) {
879
+ return JSON.stringify(output)
880
+ }
881
+ const written = `artifact ${String(output.artifactId)}, version ${String(output.version)} at revision ${String(output.revision)}`
587
882
  const lines = [
588
- `Published "${String(output.title)}" as artifact ${String(output.artifactId)}, version ${String(output.version)}.`,
883
+ tool === CREATE_TOOL
884
+ ? `Published "${String(output.title)}" as ${written}.`
885
+ : `Updated "${String(output.title)}": ${written}.`,
886
+ output.open === false
887
+ ? "The version is frozen."
888
+ : `The version is open: each update replaces it until the user creates a version. To change it, call ${UPDATE_TOOL} with this id.`,
589
889
  ]
590
- if (tool === CREATE_TOOL) {
591
- lines.push(`To change it, publish its next version with ${VERSION_TOOL} and this id.`)
890
+ const copy = `$SIXB_ARTIFACTS_DIR/${String(output.artifactId)}/`
891
+ const since =
892
+ typeof output.mergedSince === "number"
893
+ ? `, since revision ${output.mergedSince}, which you started from`
894
+ : ""
895
+ const from =
896
+ typeof output.nextUpdateFrom === "number"
897
+ ? `your next update starts from revision ${output.nextUpdateFrom} again`
898
+ : "your next update starts from what it held before"
899
+ if ("mergedSince" in output && output.notInstalled === true) {
900
+ lines.push(
901
+ `Merged with changes made meanwhile${since}, but the merged result could not be installed: your folder and ${copy} still hold your own files, and ${from}, so what others wrote stays. Read the version before editing what others may have changed, and say in your reply that others were editing it.`
902
+ )
903
+ } else if ("mergedSince" in output) {
904
+ lines.push(
905
+ `Merged with changes made meanwhile${since}: your folder now holds the merged result, as does ${copy}. Keep editing from it, and say in your reply that others were editing it.`
906
+ )
907
+ } else if (output.notInstalled === true) {
908
+ lines.push(`This revision could not be installed in ${copy}: ${from}.`)
592
909
  }
593
910
  const warnings = Array.isArray(output.warnings) ? output.warnings : []
594
911
  for (const warning of warnings) {
@@ -616,10 +933,14 @@ function publishSummary(output: JsonValue, tool: PublishToolName): string {
616
933
  const directory = posix.dirname(screenshots[0] ?? "")
617
934
  lines.push(
618
935
  kind === "page"
619
- ? `Layout check: the page as the reader sees it, in light mode or the mode its theme.json pins, is ${directory}/desktop.png at 1280px and ${directory}/phone.png at 390px, each its top 4000px. Open them with view_file, fix what the warnings name, and publish the next version.`
936
+ ? `Layout check: the page as the reader sees it, in light mode or the mode its theme.json pins, is ${directory}/desktop.png at 1280px and ${directory}/phone.png at 390px, each its top 4000px. Open them with view_file, fix what the warnings name, and update the artifact.`
620
937
  : kind === "canvas"
621
- ? `Layout check: each board as the reader sees it, at its own size, in light mode or the mode its theme.json pins, is ${directory}/<id>.png (${screenshots.length} boards). Open them with view_file, fix what the warnings name, and publish the next version.`
622
- : `Layout check: each slide as the reader sees it, in light mode or the mode its theme.json pins, is ${directory}/slide-NN.png (${screenshots.length} slides). Open them with view_file, fix what the warnings name, and publish the next version.`
938
+ ? `Layout check: each board as the reader sees it, at its own size, in light mode or the mode its theme.json pins, is ${directory}/<id>.png (${screenshots.length} boards). Open them with view_file, fix what the warnings name, and update the artifact.${
939
+ typeof check.overview === "string"
940
+ ? ` Open ${check.overview} to see the canvas as it opens, fitted to a 1440×900 window, and check that it reads at that zoom.`
941
+ : ""
942
+ }`
943
+ : `Layout check: each slide as the reader sees it, in light mode or the mode its theme.json pins, is ${directory}/slide-NN.png (${screenshots.length} slides). Open them with view_file, fix what the warnings name, and update the artifact.`
623
944
  )
624
945
  }
625
946
  }
@@ -638,25 +959,34 @@ function parsePublishArtifactInput(value: unknown): PublishArtifactToolInput {
638
959
  }
639
960
  }
640
961
 
641
- function parsePublishArtifactVersionInput(value: unknown): PublishArtifactVersionToolInput {
642
- const input = inputObject(value, VERSION_TOOL, ["id", "path", "title"])
962
+ function parseOpenArtifactInput(value: unknown): OpenArtifactToolInput {
963
+ const input = inputObject(value, OPEN_TOOL, ["id"])
964
+ const id = typeof input.id === "string" ? input.id.trim() : ""
965
+ if (!isArtifactId(id)) {
966
+ throw publishError(OPEN_TOOL, "id must be an artifact id such as art_k3m9q2x7tp")
967
+ }
968
+ return { id }
969
+ }
970
+
971
+ function parseUpdateArtifactInput(value: unknown): UpdateArtifactToolInput {
972
+ const input = inputObject(value, UPDATE_TOOL, ["id", "path", "title"])
643
973
  const id = typeof input.id === "string" ? input.id.trim() : ""
644
974
  if (!isArtifactId(id)) {
645
975
  throw publishError(
646
- VERSION_TOOL,
976
+ UPDATE_TOOL,
647
977
  `id must be an artifact id such as art_k3m9q2x7tp. $SIXB_ARTIFACTS lists this conversation's artifacts; to create a new one, call ${CREATE_TOOL}`
648
978
  )
649
979
  }
650
980
  return {
651
981
  id,
652
- path: pathInput(input.path, VERSION_TOOL),
653
- title: titleInput(input.title, VERSION_TOOL),
982
+ path: pathInput(input.path, UPDATE_TOOL),
983
+ title: titleInput(input.title, UPDATE_TOOL),
654
984
  }
655
985
  }
656
986
 
657
987
  function inputObject(
658
988
  value: unknown,
659
- tool: PublishToolName,
989
+ tool: ArtifactToolName,
660
990
  keys: readonly string[]
661
991
  ): Record<string, unknown> {
662
992
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -668,20 +998,20 @@ function inputObject(
668
998
  return input
669
999
  }
670
1000
 
671
- function pathInput(value: unknown, tool: PublishToolName): string {
1001
+ function pathInput(value: unknown, tool: ArtifactToolName): string {
672
1002
  if (typeof value !== "string" || value.trim().length === 0) {
673
1003
  throw publishError(tool, "path must be a file or directory in the sandbox")
674
1004
  }
675
1005
  return value
676
1006
  }
677
1007
 
678
- function titleInput(value: unknown, tool: PublishToolName): string {
1008
+ function titleInput(value: unknown, tool: ArtifactToolName): string {
679
1009
  if (typeof value !== "string") throw publishError(tool, "title must be text")
680
1010
  return value
681
1011
  }
682
1012
 
683
1013
  /** Refusals the Agent can act on become its error text; anything else stays internal. */
684
- function toPublishError(error: unknown, tool: PublishToolName, path?: string): unknown {
1014
+ function toPublishError(error: unknown, tool: ArtifactToolName, path?: string): unknown {
685
1015
  if (error instanceof SandboxFileError) {
686
1016
  if (error.reason === "not_found" && path !== undefined) {
687
1017
  return publishError(tool, `there is no file or directory at '${path}'`)
@@ -694,7 +1024,7 @@ function toPublishError(error: unknown, tool: PublishToolName, path?: string): u
694
1024
  return error
695
1025
  }
696
1026
 
697
- function publishError(tool: PublishToolName, message: string): AgentToolPublicError {
1027
+ function publishError(tool: ArtifactToolName, message: string): AgentToolPublicError {
698
1028
  const sentence = /[.!?]$/.test(message) ? message : `${message}.`
699
1029
  return new AgentToolPublicError(`[SixbAgent] ${tool} refused: ${sentence}`)
700
1030
  }