opencode-queue 0.7.0 → 0.7.1

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 (2) hide show
  1. package/index.ts +22 -18
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -17,22 +17,22 @@ type Ask = { type: string; properties: { id: string; sessionID: string; question
17
17
  type Post = (input: { url: string; path?: Record<string, string>; body?: unknown; headers?: Record<string, string> }) => Promise<{ response?: Response; error?: unknown } | undefined>
18
18
 
19
19
  type Item =
20
- | { kind: "prompt"; info: Info; text: string; parts: InputPart[] }
21
- | { kind: "command"; info: Info; text: string; cmd: string; args: string; files: FilePartInput[] }
22
- | { kind: "shell"; info: Info; text: string; shell: string }
20
+ | { kind: "prompt"; info: Info; label: string; body: string; parts: InputPart[] }
21
+ | { kind: "command"; info: Info; source: string; cmd: string; args: string; files: FilePartInput[] }
22
+ | { kind: "shell"; info: Info; source: string; shell: string }
23
23
 
24
24
  type Op =
25
25
  | { kind: "list" }
26
26
  | { kind: "clear"; indices: number[] }
27
27
  | { kind: "flush" }
28
- | { kind: "invalid"; text: string }
29
- | { kind: "prompt"; text: string; body: string }
30
- | { kind: "command"; text: string; cmd: string; args: string }
31
- | { kind: "shell"; text: string; shell: string }
28
+ | { kind: "invalid"; message: string }
29
+ | { kind: "prompt"; label: string; body: string }
30
+ | { kind: "command"; source: string; cmd: string; args: string }
31
+ | { kind: "shell"; source: string; shell: string }
32
32
 
33
33
  type ControlOp = Extract<Op, { kind: "list" | "clear" | "flush" }>
34
34
 
35
- const label = (body: string, files: number) => {
35
+ const brief = (body: string, files: number) => {
36
36
  const text = body.trim() || `${files} attachment${files === 1 ? "" : "s"}`
37
37
  return text.length > 72 ? `${text.slice(0, 69)}...` : text
38
38
  }
@@ -46,21 +46,21 @@ const parse = (body: string, files = 0): Op => {
46
46
  if (clear) {
47
47
  const values = clear[1]?.trim().split(/\s+/) ?? []
48
48
  const indices = values.map(Number)
49
- if (values.some((value) => !ITEM_NUMBER.test(value)) || indices.some((index) => !Number.isSafeInteger(index))) return { kind: "invalid", text: "Queue clear expects one or more positive item numbers" }
49
+ if (values.some((value) => !ITEM_NUMBER.test(value)) || indices.some((index) => !Number.isSafeInteger(index))) return { kind: "invalid", message: "Queue clear expects one or more positive item numbers" }
50
50
  return { kind: "clear", indices }
51
51
  }
52
52
  }
53
53
 
54
54
  if (text.startsWith("!")) {
55
55
  const shell = text.slice(1).trim()
56
- if (!shell) return { kind: "invalid", text: "Queue shell command is empty" }
57
- if (files) return { kind: "invalid", text: "Queued shell commands do not support attachments" }
58
- return { kind: "shell", text, shell }
56
+ if (!shell) return { kind: "invalid", message: "Queue shell command is empty" }
57
+ if (files) return { kind: "invalid", message: "Queued shell commands do not support attachments" }
58
+ return { kind: "shell", source: text, shell }
59
59
  }
60
60
 
61
61
  const match = text.match(CMD)
62
- if (match) return { kind: "command", text, cmd: match[1], args: match[2] ?? "" }
63
- return { kind: "prompt", text: label(body, files), body }
62
+ if (match) return { kind: "command", source: text, cmd: match[1], args: match[2] ?? "" }
63
+ return { kind: "prompt", label: brief(body, files), body }
64
64
  }
65
65
 
66
66
  const trailing = (text: string) => (text.trim() === "/queue" ? "" : text.match(SUFFIX)?.[1])
@@ -216,7 +216,11 @@ export const QueuePlugin: Plugin = async ({ client }) => {
216
216
  }
217
217
 
218
218
  const manage = async (sid: string, op: ControlOp) => {
219
- if (op.kind === "list") return (queue.get(sid) ?? []).map((item, i) => `${i + 1}. ${item.text}`).join("\n") || "Queue is empty"
219
+ if (op.kind === "list") {
220
+ return (queue.get(sid) ?? [])
221
+ .map((item, i) => `${i + 1}. ${item.kind === "prompt" ? (item.body.trim() ? item.body : item.label) : item.source}`)
222
+ .join("\n") || "Queue is empty"
223
+ }
220
224
  if (op.kind === "clear") return clear(sid, op.indices)
221
225
 
222
226
  const result = await flush(sid)
@@ -272,7 +276,7 @@ export const QueuePlugin: Plugin = async ({ client }) => {
272
276
  const op = parse(body, parts.length)
273
277
 
274
278
  if (control(op)) return stop(await manage(sid, op))
275
- if (op.kind === "invalid") return stop(op.text, "error")
279
+ if (op.kind === "invalid") return stop(op.message, "error")
276
280
 
277
281
  if (!busy.has(sid)) {
278
282
  if (op.kind === "shell") {
@@ -310,7 +314,7 @@ export const QueuePlugin: Plugin = async ({ client }) => {
310
314
 
311
315
  if (op.kind === "invalid") {
312
316
  hide(output.message.id, text)
313
- await toast(op.text, "error", 5000)
317
+ await toast(op.message, "error", 5000)
314
318
  return
315
319
  }
316
320
 
@@ -346,7 +350,7 @@ export const QueuePlugin: Plugin = async ({ client }) => {
346
350
 
347
351
  queue.set(sid, [...(queue.get(sid) ?? []), item])
348
352
  hide(output.message.id, text)
349
- await toast(`Queued: ${item.text}`, "info")
353
+ await toast(`Queued: ${item.kind === "prompt" ? item.label : item.source}`, "info")
350
354
  },
351
355
  "experimental.chat.messages.transform": async (_, output) => {
352
356
  output.messages = output.messages.filter((msg) => !hidden.has(msg.info.id))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "opencode-queue",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "type": "module",
6
6
  "description": "Queue OpenCode prompts and slash commands until the agent is idle",
7
7
  "main": "./index.ts",