genaicode 2.30.0 → 2.32.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.
Files changed (54) hide show
  1. package/README.md +2 -1
  2. package/dist/agents/artifacts.d.ts +80 -0
  3. package/dist/agents/artifacts.js +361 -0
  4. package/dist/agents/artifacts.js.map +1 -0
  5. package/dist/agents/handoff.d.ts +14 -3
  6. package/dist/agents/handoff.js +57 -4
  7. package/dist/agents/handoff.js.map +1 -1
  8. package/dist/agents/mcp-tools.d.ts +25 -0
  9. package/dist/agents/mcp-tools.js +64 -0
  10. package/dist/agents/mcp-tools.js.map +1 -0
  11. package/dist/agents/session.d.ts +18 -1
  12. package/dist/agents/session.js +43 -5
  13. package/dist/agents/session.js.map +1 -1
  14. package/dist/agents/types.d.ts +20 -0
  15. package/dist/agents.d.ts +3 -1
  16. package/dist/agents.js +1 -0
  17. package/dist/agents.js.map +1 -1
  18. package/dist/app-agent/app-agent.d.ts +14 -0
  19. package/dist/app-agent/app-agent.js +16 -0
  20. package/dist/app-agent/app-agent.js.map +1 -1
  21. package/dist/app-agent/http.d.ts +1 -0
  22. package/dist/app-agent/http.js +10 -0
  23. package/dist/app-agent/http.js.map +1 -1
  24. package/dist/app-agent/mcp.d.ts +2 -25
  25. package/dist/app-agent/mcp.js +1 -63
  26. package/dist/app-agent/mcp.js.map +1 -1
  27. package/dist/cli/args.d.ts +2 -0
  28. package/dist/cli/args.js +2 -0
  29. package/dist/cli/args.js.map +1 -1
  30. package/dist/cli/main.d.ts +3 -1
  31. package/dist/cli/main.js +3 -0
  32. package/dist/cli/main.js.map +1 -1
  33. package/dist/react/agent-chat.css +85 -0
  34. package/dist/react/agent-chat.d.ts +20 -1
  35. package/dist/react/agent-chat.js +102 -5
  36. package/dist/react/agent-chat.js.map +1 -1
  37. package/dist/react/app-agent-chat.d.ts +8 -1
  38. package/dist/react/app-agent-chat.js +3 -2
  39. package/dist/react/app-agent-chat.js.map +1 -1
  40. package/dist/react/format.d.ts +1 -0
  41. package/dist/react/format.js +7 -0
  42. package/dist/react/format.js.map +1 -1
  43. package/dist/react.d.ts +1 -1
  44. package/dist/react.js +1 -1
  45. package/dist/react.js.map +1 -1
  46. package/dist/ui/index.js +95 -91
  47. package/dist/ui/web-client.js +98 -12
  48. package/dist/ui.d.ts +2 -0
  49. package/dist/ui.js.map +1 -1
  50. package/docs/agents.md +71 -0
  51. package/docs/app-agent.md +9 -0
  52. package/docs/cli.md +6 -0
  53. package/docs/react.md +14 -12
  54. package/package.json +2 -1
package/dist/ui.d.ts CHANGED
@@ -31,6 +31,8 @@ export interface EmbeddedWebOptions {
31
31
  transformPrompt?(prompt: string): string;
32
32
  /** Approve every permission request without asking. */
33
33
  approveAll?: boolean;
34
+ /** Let the agent publish artifacts (pages, images, documents) the UI shows. Default true. */
35
+ artifacts?: boolean;
34
36
  /** Bark when the agent needs the user or finishes, while the tab is hidden. Default true. */
35
37
  bark?: boolean;
36
38
  /** Origins of the pages that show the UI in a frame. Read per request. Default: none. */
package/dist/ui.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAiC,MAAM,qBAAqB,CAAC;AA0EnF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA2B;IAChE,MAAM,EAAE,GAAG,MAAM,aAAa,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,gBAAgB,CAAC;QACzB,GAAG,OAAO;QACV,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,aAAa,EAAE;QACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,EAAE;QAC5C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,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,OAAO,CAAC,MAAM,IAAI,aAAa,EAAE;QACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,EAAE;QAC5C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;KACrD,CAAC,CAAC;AACL,CAAC;AAcD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IAC9D,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,GAAG,OAAO,EAAE,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IAChE,OAAO,aAAa,CAClB,CAAC,cAAc,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,CAAC,EAC/F,EAAE,aAAa,EAAE,GAAG,EAAE,CACvB,CAAC;AACJ,CAAC;AAED,uGAAuG;AACvG,SAAS,aAAa;IACpB,MAAM,MAAM,GAAW,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IACtE,OAAO,MAAM,CAAC,MAAM,CAAsB,CAAC;AAC7C,CAAC;AAED,SAAS,cAAc;IACrB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAQ,OAAO,CAAC,iBAAiB,CAAyB,CAAC,OAAO,CAAC;AACrE,CAAC"}
package/docs/agents.md CHANGED
@@ -258,6 +258,77 @@ session.send('Now cover it with a test'); // resumes the same agent session
258
258
  while turns, the queue and steered input keep the text given to `send()`.
259
259
  - `<AgentChat>` from `genaicode/react` renders `state` in a React page (see the README).
260
260
 
261
+ ### Artifacts
262
+
263
+ An agent can publish something for the user to look at instead of describing it: a report or
264
+ chart as a self-contained HTML page, an image, a Markdown document. `genaicode chat` and
265
+ `genaicode ui` turn this on by default (`--no-artifacts` turns it off); in code:
266
+
267
+ ```ts
268
+ import { artifactResponse, createAgentSession, startArtifactChannel } from 'genaicode/agents';
269
+
270
+ const artifacts = await startArtifactChannel({ cwd });
271
+ const session = createAgentSession({ agent: claude(), cwd, artifacts });
272
+
273
+ // Your server shows the content. The id is unguessable; serve it without your session cookie in mind.
274
+ app.get('/artifacts/:id', (req, res) => {
275
+ const found = artifacts.store.read(req.params.id);
276
+ if (!found) return res.status(404).end();
277
+ // The Range header lets audio and video seek.
278
+ const { status, headers, body } = artifactResponse(found.artifact, found.body, { range: req.headers.range });
279
+ res.writeHead(status, headers).end(body);
280
+ });
281
+ ```
282
+
283
+ - The agent gets one MCP tool, `publish_artifact({ title, path | content + format, name? })`, on
284
+ a loopback MCP server behind a bearer token. So it works for the agents that take MCP servers
285
+ in genaicode (claude, codex, codexLive, copilot, muse, museLive, antigravity); the others
286
+ simply do not get the tool. An app with its own MCP server can mount `store.tool()` there
287
+ and pass `{ store }` alone; `createAppAgent` does exactly that (see [app-agent.md](app-agent.md)).
288
+ - Each publish adds an `artifact` entry (`{ id, title, kind, mimeType, bytes, version, path? }`)
289
+ to the running turn. The content is copied into memory at that moment (5 MB each, 50 MB for
290
+ audio and video, the newest 30 and 200 MB in all by default: `maxBytes`, `maxMediaBytes`,
291
+ `maxArtifacts`, `maxTotalBytes`); publishing the same `name` again replaces it and keeps the `id`.
292
+ - `<AgentChat artifactUrl={(a) => `/artifacts/${a.id}?v=${a.version}`}>` shows a card with a
293
+ preview; the terminal chat shows a line and `/web` opens the browser.
294
+ - **Media**: files ending in png, jpg, gif, webp, avif or svg show as a picture (screenshots),
295
+ mp3, wav, ogg, opus, m4a, aac or flac in an audio player, mp4, m4v, webm, mov or ogv in a
296
+ video player. Media is published from a file (`path`), not as `content`. Your page's own
297
+ Content-Security-Policy has to allow `img-src`, `media-src` and `frame-src` for the address
298
+ you serve artifacts at.
299
+ - **Pages that answer back**: a published page can ask the user something (a questionnaire, a
300
+ choice between mockups) and hand the answer to the agent by calling
301
+ `parent.postMessage({ genaicode: 'submit', data }, '*')`, e.g. from a button. `<AgentChat>`
302
+ takes that only from the frame of that card, shows the user the JSON that would be sent and
303
+ waits for **Send to agent**; then `onArtifactSubmit(artifact, data)` runs, by default
304
+ `onSend(artifactSubmission(artifact, data))`, so the agent reads it as the user's next
305
+ message. Pass `onArtifactSubmit={null}` to turn it off. Nothing is sent without that click,
306
+ and a page opened in a tab of its own has nobody to send to.
307
+ - **Other agents**: the store belongs to the session, not the agent. After `setAgent()` or a
308
+ failover the cards still open, the next agent gets the same tool, and its handoff lists what
309
+ was published (title, `name`, kind, version, source file) so it can replace an artifact under
310
+ the same `name`. Pages and documents that were published as `content` are written into the
311
+ handoff transcript, since they exist nowhere else.
312
+
313
+ Artifacts are agent-written content, so they are handled as untrusted:
314
+
315
+ - **Files**: only regular files inside `cwd` after resolving symlinks; `.git`, `.genaicode`,
316
+ `.ssh` and similar folders, `.env*`, key and certificate files are refused. This guards
317
+ against a confused or prompt-injected agent, not against one with a shell, which can read
318
+ those files anyway.
319
+ - **Types**: the MIME type comes from the file extension or `format`, never from the agent,
320
+ and everything is sent with `nosniff`. Unknown types download instead of rendering.
321
+ - **HTML**: `artifactResponse()` sends a Content-Security-Policy with `sandbox allow-scripts`
322
+ and `default-src 'none'`: the page runs its own inline code in an origin of its own (no
323
+ cookies, storage or DOM of your app, also when its URL is opened directly) and loads
324
+ nothing from the network, so no CDN scripts either. `<AgentChat>` adds the same sandbox on
325
+ the frame. SVG is shown as an image, or with scripts off when opened directly.
326
+ - **Answers from a page** are data from agent-written code: they reach the agent only after
327
+ the user saw and confirmed them, at most 20 KB of JSON at a time.
328
+ - **What is left**: a page can still navigate its own frame to another site and carry data in
329
+ that URL; browsers offer no switch for that. The page only knows what the agent put in it,
330
+ but treat a published page like a link the agent sent you.
331
+
261
332
  ## Drivers
262
333
 
263
334
  | Driver | Command | Mode | Notes |
package/docs/app-agent.md CHANGED
@@ -51,6 +51,15 @@ import 'genaicode/react/styles.css';
51
51
  <img alt="A shop admin with the agent drawer: the agent proposed a refund, waiting for Approve." src="media/screenshots/app-agent.png" width="80%">
52
52
  </p>
53
53
 
54
+ The agent can also show the user something instead of describing it: a report, a chart or a
55
+ table as a self-contained HTML page, an image, a Markdown document. It calls
56
+ `publish_artifact` (turn it on with `artifacts: true`), the chat shows a card, and the card opens a preview. The handler serves
57
+ the content at `/api/agent/artifacts/:id` behind `authorize` like every other route, with
58
+ headers that sandbox it: the page runs in an origin of its own, with no network and no access
59
+ to your app's cookies, storage or DOM (see [agents.md](agents.md#artifacts)). In `dev` mode the
60
+ agent can publish a file from `dev.cwd`; in `use` mode only content it writes. An app that
61
+ draws its own chat instead of `AppAgentChat` renders the `artifact` transcript entries itself.
62
+
54
63
  A read tool may return `{ text, images: [{ mimeType: 'image/png', data }] }` instead of a
55
64
  string, so the agent can look at what it changed, e.g. a screenshot of the app.
56
65
 
package/docs/cli.md CHANGED
@@ -80,6 +80,12 @@ The terminal UI rings the terminal bell instead. `/bark off` (or the Bark button
80
80
  prompt, e.g. `genaicode ui --mcp game=http://127.0.0.1:7777/mcp` from a game editor whose
81
81
  running game serves tools there. Only the agents that take MCP servers in genaicode (claude,
82
82
  codex, copilot) are offered then.
83
+ The agent can publish artifacts: a report, chart or mockup as a self-contained HTML page, an
84
+ image, a Markdown document. The browser UI shows each as a card that opens a preview; the
85
+ terminal shows a line, and `/web` opens the browser on the same session. Pages run in a
86
+ sandboxed frame with no network and no access to the UI (see
87
+ [agents.md](agents.md#artifacts)). Agents that take MCP servers get the tool;
88
+ `--no-artifacts` leaves it out.
83
89
  An app that starts `genaicode ui` itself can add `--exit-with-stdin` and stop it by closing
84
90
  its stdin, which also reaches the server when a launcher such as npx sits in between.
85
91
 
package/docs/react.md CHANGED
@@ -71,18 +71,20 @@ HTML; links open in a new tab; GFM tables, strikethrough and task lists), collap
71
71
  own approval requests, queued prompts and a working indicator, and an input where Enter
72
72
  sends, Shift+Enter adds a line and Esc stops. Props:
73
73
 
74
- | Prop | |
75
- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
76
- | `state` | `SessionState`, or null before there is a session |
77
- | `onSend(text)`, `onStop()` | Enter or Send; Stop or Esc. No `onStop`, no Stop button |
78
- | `onApprove(id, decision)` | answers `state.approvals`; without it they show as waiting |
79
- | `renderPrompt(text, turn?)` | how a sent prompt shows (return null to hide it) |
80
- | `renderAfterTurn(turn, i)`, `renderFooter()` | your content after a turn, or at the end |
81
- | `notices` | `{ id, afterTurn, text, tone? }[]`: your own lines between turns |
82
- | `foldSteps` | fold each turn's tools and edits into one "N steps" line |
83
- | `header`, `headerExtras` | replace the header (null for none), or add to its right end |
84
- | `emptyState`, `placeholder`, `hint` | text before the first turn, in and under the input |
85
- | `formatToolName(name)`, `disabled`, `autoFocus`, `theme`, `className`, `style` | |
74
+ | Prop | |
75
+ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
76
+ | `state` | `SessionState`, or null before there is a session |
77
+ | `onSend(text)`, `onStop()` | Enter or Send; Stop or Esc. No `onStop`, no Stop button |
78
+ | `onApprove(id, decision)` | answers `state.approvals`; without it they show as waiting |
79
+ | `renderPrompt(text, turn?)` | how a sent prompt shows (return null to hide it) |
80
+ | `renderAfterTurn(turn, i)`, `renderFooter()` | your content after a turn, or at the end |
81
+ | `notices` | `{ id, afterTurn, text, tone? }[]`: your own lines between turns |
82
+ | `artifactUrl(artifact)`, `renderArtifact(artifact, url)` | where your server serves a published artifact; your own card ([artifacts](agents.md#artifacts)) |
83
+ | `onArtifactSubmit(artifact, data)` | a page the agent published sent data and the user confirmed it; default sends it as a message; `null` turns it off |
84
+ | `foldSteps` | fold each turn's tools and edits into one "N steps" line |
85
+ | `header`, `headerExtras` | replace the header (null for none), or add to its right end |
86
+ | `emptyState`, `placeholder`, `hint` | text before the first turn, in and under the input |
87
+ | `formatToolName(name)`, `disabled`, `autoFocus`, `theme`, `className`, `style` | |
86
88
 
87
89
  Theme it with CSS custom properties on the component or any ancestor: `--gc-bg`,
88
90
  `--gc-panel`, `--gc-border`, `--gc-text`, `--gc-muted`, `--gc-accent`, `--gc-accent-text`,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "genaicode",
3
- "version": "2.30.0",
3
+ "version": "2.32.0",
4
4
  "description": "Drive the coding-agent CLIs you already have (Claude Code, Codex, Copilot, Cursor, Gemini, opencode...) behind one API and one CLI, plus a thin provider-neutral LLM layer.",
5
5
  "author": "Grzegorz Tańczyk",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/gtanczyk/genaicode.git"
9
9
  },
10
+ "homepage": "https://grzegorz.tanczyk.pl/genaicode/",
10
11
  "keywords": [
11
12
  "llm",
12
13
  "ai",