genaicode 2.30.0 → 2.31.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 (50) hide show
  1. package/README.md +2 -1
  2. package/dist/agents/artifacts.d.ts +70 -0
  3. package/dist/agents/artifacts.js +310 -0
  4. package/dist/agents/artifacts.js.map +1 -0
  5. package/dist/agents/handoff.js +3 -0
  6. package/dist/agents/handoff.js.map +1 -1
  7. package/dist/agents/mcp-tools.d.ts +25 -0
  8. package/dist/agents/mcp-tools.js +64 -0
  9. package/dist/agents/mcp-tools.js.map +1 -0
  10. package/dist/agents/session.d.ts +18 -1
  11. package/dist/agents/session.js +21 -0
  12. package/dist/agents/session.js.map +1 -1
  13. package/dist/agents/types.d.ts +20 -0
  14. package/dist/agents.d.ts +3 -1
  15. package/dist/agents.js +1 -0
  16. package/dist/agents.js.map +1 -1
  17. package/dist/app-agent/app-agent.d.ts +14 -0
  18. package/dist/app-agent/app-agent.js +16 -0
  19. package/dist/app-agent/app-agent.js.map +1 -1
  20. package/dist/app-agent/http.d.ts +1 -0
  21. package/dist/app-agent/http.js +10 -0
  22. package/dist/app-agent/http.js.map +1 -1
  23. package/dist/app-agent/mcp.d.ts +2 -25
  24. package/dist/app-agent/mcp.js +1 -63
  25. package/dist/app-agent/mcp.js.map +1 -1
  26. package/dist/cli/args.d.ts +2 -0
  27. package/dist/cli/args.js +2 -0
  28. package/dist/cli/args.js.map +1 -1
  29. package/dist/cli/main.d.ts +3 -1
  30. package/dist/cli/main.js +3 -0
  31. package/dist/cli/main.js.map +1 -1
  32. package/dist/react/agent-chat.css +52 -0
  33. package/dist/react/agent-chat.d.ts +9 -1
  34. package/dist/react/agent-chat.js +29 -5
  35. package/dist/react/agent-chat.js.map +1 -1
  36. package/dist/react/app-agent-chat.d.ts +6 -1
  37. package/dist/react/app-agent-chat.js +3 -2
  38. package/dist/react/app-agent-chat.js.map +1 -1
  39. package/dist/react/format.d.ts +1 -0
  40. package/dist/react/format.js +7 -0
  41. package/dist/react/format.js.map +1 -1
  42. package/dist/ui/index.js +90 -90
  43. package/dist/ui/web-client.js +64 -12
  44. package/dist/ui.d.ts +2 -0
  45. package/dist/ui.js.map +1 -1
  46. package/docs/agents.md +49 -0
  47. package/docs/app-agent.md +9 -0
  48. package/docs/cli.md +6 -0
  49. package/docs/react.md +13 -12
  50. 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,CAAC,EAAE,CAAC;KACrD,CAAC,CAAC;AACL,CAAC;AAcD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAA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,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,55 @@ 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
+ const { headers, body } = artifactResponse(found.artifact, found.body);
278
+ res.writeHead(200, headers).end(body);
279
+ });
280
+ ```
281
+
282
+ - The agent gets one MCP tool, `publish_artifact({ title, path | content + format, name? })`, on
283
+ a loopback MCP server behind a bearer token. So it works for the agents that take MCP servers
284
+ in genaicode (claude, codex, codexLive, copilot, muse, museLive, antigravity); the others
285
+ simply do not get the tool. An app with its own MCP server can mount `store.tool()` there
286
+ and pass `{ store }` alone; `createAppAgent` does exactly that (see [app-agent.md](app-agent.md)).
287
+ - Each publish adds an `artifact` entry (`{ id, title, kind, mimeType, bytes, version, path? }`)
288
+ to the running turn. The content is copied into memory at that moment (5 MB each, the newest
289
+ 30 by default); publishing the same `name` again replaces it and keeps the `id`.
290
+ - `<AgentChat artifactUrl={(a) => `/artifacts/${a.id}?v=${a.version}`}>` shows a card with a
291
+ preview; the terminal chat shows a line and `/web` opens the browser.
292
+
293
+ Artifacts are agent-written content, so they are handled as untrusted:
294
+
295
+ - **Files**: only regular files inside `cwd` after resolving symlinks; `.git`, `.genaicode`,
296
+ `.ssh` and similar folders, `.env*`, key and certificate files are refused. This guards
297
+ against a confused or prompt-injected agent, not against one with a shell, which can read
298
+ those files anyway.
299
+ - **Types**: the MIME type comes from the file extension or `format`, never from the agent,
300
+ and everything is sent with `nosniff`. Unknown types download instead of rendering.
301
+ - **HTML**: `artifactResponse()` sends a Content-Security-Policy with `sandbox allow-scripts`
302
+ and `default-src 'none'`: the page runs its own inline code in an origin of its own (no
303
+ cookies, storage or DOM of your app, also when its URL is opened directly) and loads
304
+ nothing from the network, so no CDN scripts either. `<AgentChat>` adds the same sandbox on
305
+ the frame. SVG is shown as an image, or with scripts off when opened directly.
306
+ - **What is left**: a page can still navigate its own frame to another site and carry data in
307
+ that URL; browsers offer no switch for that. The page only knows what the agent put in it,
308
+ but treat a published page like a link the agent sent you.
309
+
261
310
  ## Drivers
262
311
 
263
312
  | 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,19 @@ 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
+ | `foldSteps` | fold each turn's tools and edits into one "N steps" line |
84
+ | `header`, `headerExtras` | replace the header (null for none), or add to its right end |
85
+ | `emptyState`, `placeholder`, `hint` | text before the first turn, in and under the input |
86
+ | `formatToolName(name)`, `disabled`, `autoFocus`, `theme`, `className`, `style` | |
86
87
 
87
88
  Theme it with CSS custom properties on the component or any ancestor: `--gc-bg`,
88
89
  `--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.31.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",