@agentrq/agentrq-ws 0.18.7 → 0.19.0

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.
package/README.md CHANGED
@@ -48,7 +48,7 @@ Node 20.6 or newer.
48
48
  | `task create <title>` | Create a task, with `--clear-context` to send `/clear` to the agent first |
49
49
  | `task status <taskId> <status>` | Set a task's status |
50
50
  | `task help [action]` | The server's help for its `task` tool: every action, or one action's payload |
51
- | `reply <taskId> <text>` | Send a message to a task |
51
+ | `reply <taskId> <text>` | Send a message to a task; `--ui @card.json` adds an A2UI v1.0 card, the text its fallback |
52
52
  | `attachment get <id> --task <taskId>` | Download an attachment to a file |
53
53
  | `memory load [name]` | Read a workspace memory (defaults to the index); its version goes to stderr |
54
54
  | `memory save [name] --content … [--version N]` | Replace a workspace memory; `--version` is the one `memory load` printed, required to change one that exists |
@@ -65,7 +65,7 @@ Node 20.6 or newer.
65
65
  | `pano delete <id>` | Delete a Pano doc |
66
66
  | `pano help [action]` | The server's help for its `pano` tool: every action, or one action's payload |
67
67
  | `event publish <name>` | Publish a named event |
68
- | `ask <taskId> <message>` | Ask the human a question and wait |
68
+ | `ask <taskId> <message>` | Ask the human a question and wait; `--ui @card.json` asks with an A2UI v1.0 card whose Button answers |
69
69
  | `site-tools [q]` | List the websites shared with this workspace from the Chrome extension, and their tools' names and descriptions; `q` ranks the tools, `--pattern` filters them by a regular expression, `--limit`/`--offset` page |
70
70
  | `site-tool <site> <tool>` | Show one shared website's tool in full, with its input schema |
71
71
  | `call-site-tool <site> <tool> --task <taskId>` | Run a shared website's tool in the human's Chrome, with `--args '{…}'` |
@@ -99,6 +99,14 @@ The server takes at most 4 MiB per request, and base64 adds a third, so a file
99
99
  over about 3 MiB is refused before anything is sent: gzip it first. Files that
100
100
  fit only on their own go one `reply` each.
101
101
 
102
+ A card goes with `--ui`, A2UI v1.0 messages as a JSON array; its images name
103
+ files attached to the same reply as `attachment:<filename>`, so they must fit
104
+ one request together:
105
+
106
+ ```bash
107
+ agentrq-ws reply 0isnjTCkpW5 "PR opened, coverage chart attached" --ui @card.json --attach ./chart.png
108
+ ```
109
+
102
110
  **Downloading** writes a file and prints where it went. With no `--out` it lands
103
111
  in the OS temp directory:
104
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentrq/agentrq-ws",
3
- "version": "0.18.7",
3
+ "version": "0.19.0",
4
4
  "description": "AgentRQ workspace client \u2014 drive an AgentRQ workspace from the command line, using the workspace's own .mcp.json",
5
5
  "keywords": [
6
6
  "agentrq",
package/src/commands.js CHANGED
@@ -42,6 +42,15 @@ export async function resolveText(value, { stdin, what }) {
42
42
  return value
43
43
  }
44
44
 
45
+ /**
46
+ * Refuses a command that reads more than one of its inputs, named by the
47
+ * keys of inputs, from stdin: the first read takes all of it.
48
+ */
49
+ export function oneStdin(inputs) {
50
+ const piped = Object.keys(inputs).filter((name) => inputs[name] === '-')
51
+ if (piped.length > 1) throw new UserError(`only one input can come from stdin (-): ${piped.join(' and ')} both ask for it`)
52
+ }
53
+
45
54
  /** Build the attachment array for a tool call from repeated --attach flags. */
46
55
  export function collectAttachments(values) {
47
56
  const paths = asArray(values.attach)
@@ -168,6 +177,7 @@ function printPanoDoc(result, { idOnly = false } = {}) {
168
177
  /** The ops of pano edit: --ops (a JSON array, as the tool takes it), then --replace/--with, then --append. */
169
178
  async function panoEditOps(ctx) {
170
179
  const { ops, replace, with: newString, append } = ctx.values
180
+ oneStdin({ '--ops': ops, '--append': append })
171
181
  const out = []
172
182
  if (ops !== undefined) {
173
183
  let parsed
@@ -322,25 +332,38 @@ export const COMMANDS = [
322
332
  },
323
333
  {
324
334
  path: ['reply'],
325
- summary: 'Send a message to a task, optionally with files attached',
326
- usage: 'agentrq-ws reply <taskId> <text|@file|-> [--attach PATH]...',
335
+ summary: 'Send a message to a task, optionally with files attached and an A2UI card',
336
+ usage: 'agentrq-ws reply <taskId> <text|@file|-> [--attach PATH]... [--ui JSON|@file|-]',
327
337
  options: {
328
338
  attach: { type: 'string', multiple: true, description: 'File to attach (repeatable)' },
339
+ ui: {
340
+ type: 'string',
341
+ description: "A2UI v1.0 messages as a JSON array (@file supported): a card shown with the text as its fallback; its media name attached files as attachment:<filename>",
342
+ },
329
343
  },
330
344
  async run(ctx) {
331
345
  const taskId = requirePositional(ctx.positionals, 0, 'taskId')
332
346
  const raw = requirePositional(ctx.positionals, 1, 'text')
347
+ oneStdin({ 'the text': raw, '--ui': ctx.values.ui })
333
348
  const text = await resolveText(raw, { stdin: ctx.stdin, what: 'the reply text' })
349
+ const ui = await readUI(ctx)
350
+ const card = ui === undefined ? {} : { ui }
334
351
  const attachments = collectAttachments(ctx.values)
335
- if (!attachments) return ctx.client.callAction('task', 'reply', { taskId, text }, ['reply', { chatId: taskId, text }])
352
+ if (!attachments) {
353
+ return ctx.client.callAction('task', 'reply', { taskId, text, ...card }, ['reply', { chatId: taskId, text, ...card }])
354
+ }
336
355
  // Files too large to share one request go one reply per group, the text
337
356
  // with the first and the rest labelled by their position.
338
- const batches = batchAttachments(attachments, Buffer.byteLength(JSON.stringify(text)))
357
+ const batches = batchAttachments(attachments, Buffer.byteLength(JSON.stringify({ text, ui })))
358
+ // A card names its files, so they must arrive in the same reply.
359
+ if (ui !== undefined && batches.length > 1) {
360
+ throw new UserError('the attachments do not fit one request together, and a card needs its files in its own reply: attach fewer')
361
+ }
339
362
  const outcomes = []
340
363
  for (const [i, group] of batches.entries()) {
341
364
  const body = i === 0 ? text : `Attachments ${i + 1}/${batches.length}: ${group.map((a) => a.filename).join(', ')}`
342
- const payload = { taskId, text: body, attachments: group }
343
- outcomes.push(await ctx.client.callAction('task', 'reply', payload, ['reply', { chatId: taskId, text: body, attachments: group }]))
365
+ const payload = { taskId, text: body, attachments: group, ...card }
366
+ outcomes.push(await ctx.client.callAction('task', 'reply', payload, ['reply', { chatId: taskId, text: body, attachments: group, ...card }]))
344
367
  }
345
368
  if (outcomes.length === 1) return outcomes[0]
346
369
  return { text: outcomes.map((o) => o.text).join('\n'), result: outcomes.at(-1).result }
@@ -593,17 +616,22 @@ export const COMMANDS = [
593
616
  {
594
617
  path: ['ask'],
595
618
  summary: 'Ask the human a question and wait for the answer',
596
- usage: 'agentrq-ws ask <taskId> <message> [--field name[:type[:description]]]... [--url URL]',
619
+ usage: 'agentrq-ws ask <taskId> <message> [--field name[:type[:description]]]... [--url URL] [--ui JSON|@file|-]',
597
620
  options: {
598
- mode: { type: 'string', short: 'm', description: "'form' or 'url' (inferred when omitted)" },
621
+ mode: { type: 'string', short: 'm', description: "'form', 'url' or 'a2ui' (inferred when omitted)" },
599
622
  field: { type: 'string', multiple: true, description: 'Form field, e.g. branch:string:Which branch' },
600
623
  schema: { type: 'string', description: 'Full requestedSchema as JSON (@file supported)' },
601
624
  url: { type: 'string', short: 'u', description: 'Link to show the human (mode=url)' },
625
+ ui: {
626
+ type: 'string',
627
+ description: "The question as an A2UI v1.0 card, a JSON array of messages (@file supported; mode=a2ui): a Button's click answers, the message its fallback",
628
+ },
602
629
  timeout: { type: 'string', description: 'Seconds to wait, max 3600 (default 3600)' },
603
630
  },
604
631
  async run(ctx) {
605
632
  const taskId = requirePositional(ctx.positionals, 0, 'taskId')
606
633
  const message = requirePositional(ctx.positionals, 1, 'message')
634
+ oneStdin({ '--schema': ctx.values.schema, '--ui': ctx.values.ui })
607
635
  let requestedSchema = buildRequestedSchema(ctx.values)
608
636
  if (ctx.values.schema !== undefined) {
609
637
  const raw = await resolveText(ctx.values.schema, { stdin: ctx.stdin, what: 'the schema' })
@@ -615,17 +643,20 @@ export const COMMANDS = [
615
643
  }
616
644
  // The mode is almost always implied by which of the two was given, and
617
645
  // making somebody state it as well is ceremony.
618
- const mode = ctx.values.mode || (ctx.values.url ? 'url' : 'form')
646
+ const ui = await readUI(ctx)
647
+ const mode = ctx.values.mode || (ui !== undefined ? 'a2ui' : ctx.values.url ? 'url' : 'form')
619
648
  if (mode === 'url' && !ctx.values.url) throw new UserError('mode=url needs --url')
620
649
  if (mode === 'form' && !requestedSchema) {
621
650
  throw new UserError('mode=form needs at least one --field (or --schema)')
622
651
  }
652
+ if (mode === 'a2ui' && ui === undefined) throw new UserError('mode=a2ui needs --ui')
623
653
  const payload = {
624
654
  taskId,
625
655
  message,
626
656
  mode,
627
657
  requestedSchema,
628
658
  url: ctx.values.url,
659
+ ui,
629
660
  timeoutSeconds: ctx.values.timeout ? Number(ctx.values.timeout) : undefined,
630
661
  }
631
662
  return ctx.client.callAction('task', 'elicit', payload, ['elicit', payload])
@@ -725,6 +756,17 @@ function pano(ctx, action, payload) {
725
756
  return ctx.client.callAction('pano', action, payload, ['pano', { action, ...payload }])
726
757
  }
727
758
 
759
+ /** --ui as JSON, from inline, @file or stdin; not given is undefined. */
760
+ async function readUI(ctx) {
761
+ if (ctx.values.ui === undefined) return undefined
762
+ const raw = await resolveText(ctx.values.ui, { stdin: ctx.stdin, what: 'the ui' })
763
+ try {
764
+ return JSON.parse(raw)
765
+ } catch (err) {
766
+ throw new UserError(`--ui is not valid JSON: ${err.message}`)
767
+ }
768
+ }
769
+
728
770
  /** --args as JSON, from inline, @file or stdin; nothing given is {}. */
729
771
  async function readArgs(ctx) {
730
772
  const raw = await resolveText(ctx.values.args, { stdin: ctx.stdin, what: 'the arguments' })