{"draft":null,"from":4,"to":5,"files":[{"path":"client/src/api.ts","added":43,"removed":5,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -50,7 +50,7 @@\n \tWhereAnswer,\n \tWhyAnswer,\n } from \"./history-answers.ts\";\n-import type { Ask, Draft, DraftBody, News as IssueNews, IssuePage, IssueRow } from \"./issues-wire.ts\";\n+import type { Ask, Attachment, Draft, DraftBody, News as IssueNews, IssuePage, IssueRow } from \"./issues-wire.ts\";\n import type { Modes } from \"./modes.ts\";\n \n export * from \"./api-answers.ts\";\n@@ -65,7 +65,7 @@\n } from \"./box-run.ts\";\n export * from \"./ci-answers.ts\";\n export * from \"./history-answers.ts\";\n-export type { Ask, Draft, DraftBody, IssueNews, IssuePage, IssueRow };\n+export type { Ask, Attachment, Draft, DraftBody, IssueNews, IssuePage, IssueRow };\n \n /**\n  * How long a call may take: the base, plus 1 s for each 100 KB it sends\n@@ -400,10 +400,39 @@\n \t\t}\n \t}\n \n-\tissueOpen(body: DraftBody & { title: string }): Promise<{ id: number; news?: IssueNews }> {\n+\tissueOpen(body: DraftBody & { title: string; attachments?: string[] }): Promise<{ id: number; news?: IssueNews }> {\n \t\treturn this.#issues(\"POST\", this.agentPath(\"issue\"), body);\n \t}\n \n+\t/** Uploads an image to the Issues Worker (abso issue 171): it checks the type by the bytes, strips metadata and answers its id. */\n+\tasync attachmentUpload(bytes: Uint8Array, name: string): Promise<Attachment> {\n+\t\tif (this.issuesServer === undefined)\n+\t\t\tthrow new ApiError(`${this.config.server} has no Issues Worker beside it; AVCS_ISSUES_SERVER names one`);\n+\t\tconst path = this.agentPath(\"attachments\");\n+\t\tlet res: Response;\n+\t\ttry {\n+\t\t\tres = await fetch(this.url(path, this.issuesServer), {\n+\t\t\t\tmethod: \"POST\",\n+\t\t\t\theaders: { ...this.headers(\"application/octet-stream\"), \"x-avcs-name\": encodeURIComponent(name) },\n+\t\t\t\tbody: bytes as Uint8Array<ArrayBuffer>,\n+\t\t\t\tsignal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),\n+\t\t\t});\n+\t\t} catch (err) {\n+\t\t\tconst e = err as Error;\n+\t\t\tthrow new ApiError(\n+\t\t\t\t`could not reach ${this.issuesServer}: ${(e.cause as Error | undefined)?.message ?? e.message}`,\n+\t\t\t);\n+\t\t}\n+\t\tconst text = await res.text();\n+\t\tif (!res.ok) throw new ApiError(`uploading ${name} answered ${res.status}: ${errorSentence(text)}`, res.status);\n+\t\treturn JSON.parse(text) as Attachment;\n+\t}\n+\n+\t/** Where an attachment is served. */\n+\tattachmentUrl(id: string): string {\n+\t\treturn this.url(`/attachments/${id}`, this.issuesServer);\n+\t}\n+\n \t/** An edit (abso issue 3): it tells the issue's watchers, and `also`, unless `notify` is false. null clears a parent or Agent. */\n \tissueEdit(\n \t\tid: number,\n@@ -422,8 +451,17 @@\n \t\treturn this.#issues(\"POST\", this.agentPath(`issue/${id}/edit`), body);\n \t}\n \n-\tissueComment(id: number, text: string, objection = false): Promise<{ id: number; news?: IssueNews }> {\n-\t\treturn this.#issues(\"POST\", this.agentPath(`issue/${id}/comment`), { text, ...(objection ? { objection } : {}) });\n+\tissueComment(\n+\t\tid: number,\n+\t\ttext: string,\n+\t\tobjection = false,\n+\t\tattachments: readonly string[] = [],\n+\t): Promise<{ id: number; news?: IssueNews }> {\n+\t\treturn this.#issues(\"POST\", this.agentPath(`issue/${id}/comment`), {\n+\t\t\ttext,\n+\t\t\t...(objection ? { objection } : {}),\n+\t\t\t...(attachments.length > 0 ? { attachments } : {}),\n+\t\t});\n \t}\n \n \tissueDrop(id: number): Promise<{ news?: IssueNews }> {"}],"unmatched":[]}