genaicode 2.32.0 → 2.33.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 (41) hide show
  1. package/README.md +1 -0
  2. package/dist/agents/session.d.ts +11 -0
  3. package/dist/agents/session.js.map +1 -1
  4. package/dist/browser/fake-model.d.ts +43 -0
  5. package/dist/browser/fake-model.js +133 -0
  6. package/dist/browser/fake-model.js.map +1 -0
  7. package/dist/browser/language-model.d.ts +74 -0
  8. package/dist/browser/language-model.js +83 -0
  9. package/dist/browser/language-model.js.map +1 -0
  10. package/dist/browser/nano.d.ts +83 -0
  11. package/dist/browser/nano.js +610 -0
  12. package/dist/browser/nano.js.map +1 -0
  13. package/dist/browser/page-agent.d.ts +74 -0
  14. package/dist/browser/page-agent.js +339 -0
  15. package/dist/browser/page-agent.js.map +1 -0
  16. package/dist/browser/tools.d.ts +36 -0
  17. package/dist/browser/tools.js +190 -0
  18. package/dist/browser/tools.js.map +1 -0
  19. package/dist/browser/webmcp.d.ts +32 -0
  20. package/dist/browser/webmcp.js +150 -0
  21. package/dist/browser/webmcp.js.map +1 -0
  22. package/dist/browser.d.ts +39 -0
  23. package/dist/browser.js +32 -0
  24. package/dist/browser.js.map +1 -0
  25. package/dist/react/agent-chat.css +141 -0
  26. package/dist/react/agent-chat.d.ts +12 -2
  27. package/dist/react/agent-chat.js +32 -4
  28. package/dist/react/agent-chat.js.map +1 -1
  29. package/dist/react/attachments.d.ts +41 -0
  30. package/dist/react/attachments.js +162 -0
  31. package/dist/react/attachments.js.map +1 -0
  32. package/dist/react/page-agent-chat.d.ts +38 -0
  33. package/dist/react/page-agent-chat.js +40 -0
  34. package/dist/react/page-agent-chat.js.map +1 -0
  35. package/dist/react.d.ts +6 -1
  36. package/dist/react.js +2 -0
  37. package/dist/react.js.map +1 -1
  38. package/dist/ui/web-client.js +154 -13
  39. package/docs/browser.md +200 -0
  40. package/docs/semver.md +2 -0
  41. package/package.json +5 -1
@@ -0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ACrD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;gBAAE,SAAS;YAClD,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;YACjC,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAClE,KAAK,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,OAAO;gBAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;YACnE,IAAI,QAAQ,CAAC,QAAQ,CAAC;gBAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;iBAC5D,IAAI,OAAO,CAAC,MAAM;gBAAE,SAAS;iBAC7B,IAAI,MAAM,CAAC,oBAAoB,KAAK,KAAK;gBAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;iBAC5F,IAAI,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAAE,KAAK,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9G,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type PageTool } from './tools.js';
2
+ export interface ExposeWebMcpOptions {
3
+ /**
4
+ * Ask the user before a `write` tool runs for an outside agent; resolve false to refuse.
5
+ * Default: the browser's own `confirm()` dialog with the tool's summary.
6
+ */
7
+ confirm?(tool: PageTool, args: Record<string, unknown>): boolean | Promise<boolean>;
8
+ /** Called after every call an outside agent made, e.g. to show it on the page. */
9
+ onCall?(call: {
10
+ tool: string;
11
+ args: Record<string, unknown>;
12
+ output?: string;
13
+ error?: string;
14
+ }): void;
15
+ }
16
+ /** Whether this browser has WebMCP, so agents outside the page (the browser's own, extensions) can see its tools. */
17
+ export declare function webMcpSupported(): boolean;
18
+ /**
19
+ * Offer the page's tools to agents outside it over WebMCP (`document.modelContext`): the
20
+ * browser's own assistant or an extension can then call the same functions your in-page agent
21
+ * uses, instead of guessing at the DOM. `write` tools are marked consequential and run only
22
+ * after `confirm`. Does nothing where WebMCP is missing. Returns a function that takes the
23
+ * tools back.
24
+ */
25
+ export declare function exposeWebMcp(tools: readonly PageTool[], options?: ExposeWebMcpOptions): () => void;
26
+ /**
27
+ * The tools this page has registered over WebMCP, by any script or by annotated forms, as
28
+ * `PageTool`s: pass them to `nano` or `createPageAgent` and the in-page agent uses what the
29
+ * page already offers other agents. Tools not marked read-only count as `write`. Empty where the
30
+ * browser cannot list tools (`getTools` is in the WebMCP draft, not in every implementation).
31
+ */
32
+ export declare function webMcpTools(): Promise<PageTool[]>;
@@ -0,0 +1,150 @@
1
+ import { argumentProblems, toolText } from './tools.js';
2
+ function modelContext() {
3
+ const onDocument = globalThis.document?.modelContext;
4
+ if (onDocument && typeof onDocument.registerTool === 'function')
5
+ return { context: onDocument, legacy: false };
6
+ const onNavigator = globalThis.navigator?.modelContext;
7
+ if (onNavigator && typeof onNavigator.registerTool === 'function')
8
+ return { context: onNavigator, legacy: true };
9
+ return undefined;
10
+ }
11
+ /** Whether this browser has WebMCP, so agents outside the page (the browser's own, extensions) can see its tools. */
12
+ export function webMcpSupported() {
13
+ return modelContext() !== undefined;
14
+ }
15
+ /**
16
+ * Offer the page's tools to agents outside it over WebMCP (`document.modelContext`): the
17
+ * browser's own assistant or an extension can then call the same functions your in-page agent
18
+ * uses, instead of guessing at the DOM. `write` tools are marked consequential and run only
19
+ * after `confirm`. Does nothing where WebMCP is missing. Returns a function that takes the
20
+ * tools back.
21
+ */
22
+ export function exposeWebMcp(tools, options = {}) {
23
+ const found = modelContext();
24
+ if (!found)
25
+ return () => { };
26
+ const { context, legacy } = found;
27
+ const controller = new AbortController();
28
+ const registered = [];
29
+ let removed = false;
30
+ // Browsers that unregister by the signal have no `unregisterTool`.
31
+ const unregister = (name) => {
32
+ try {
33
+ const pending = context.unregisterTool?.(name);
34
+ if (pending instanceof Promise)
35
+ pending.catch(() => { });
36
+ }
37
+ catch {
38
+ // Already gone with the signal.
39
+ }
40
+ };
41
+ for (const tool of tools) {
42
+ const execute = async (input) => {
43
+ const args = input && typeof input === 'object' ? input : {};
44
+ try {
45
+ const problems = argumentProblems(tool, args);
46
+ if (problems.length)
47
+ throw new Error(`Bad arguments: ${problems.join('; ')}.`);
48
+ tool.validate?.(args);
49
+ if (tool.write) {
50
+ const allowed = options.confirm
51
+ ? await options.confirm(tool, args)
52
+ : defaultConfirm(tool.summary?.(args) ?? `${tool.name} ${JSON.stringify(args)}`);
53
+ if (!allowed)
54
+ throw new Error('The user declined this action.');
55
+ }
56
+ const output = toolText(await tool.run(args, controller.signal));
57
+ options.onCall?.({ tool: tool.name, args, output });
58
+ // The first implementations expect an MCP tool result; the draft takes any value.
59
+ return legacy ? { content: [{ type: 'text', text: output }] } : output;
60
+ }
61
+ catch (error) {
62
+ const message = error instanceof Error ? error.message : String(error);
63
+ options.onCall?.({ tool: tool.name, args, error: message });
64
+ if (legacy)
65
+ return { content: [{ type: 'text', text: message }], isError: true };
66
+ throw error;
67
+ }
68
+ };
69
+ try {
70
+ const pending = context.registerTool({
71
+ name: tool.name,
72
+ description: tool.description,
73
+ inputSchema: tool.inputSchema ?? { type: 'object', properties: {} },
74
+ annotations: { readOnlyHint: !tool.write, consequentialHint: !!tool.write },
75
+ execute,
76
+ }, { signal: controller.signal });
77
+ // The draft returns a promise. Only a tool that really registered is ours to take back:
78
+ // a refused one (a taken name) belongs to another script.
79
+ if (pending instanceof Promise) {
80
+ pending.then(() => (removed ? unregister(tool.name) : registered.push(tool.name)), () => { });
81
+ }
82
+ else {
83
+ registered.push(tool.name);
84
+ }
85
+ }
86
+ catch {
87
+ // A name another script registered, or a schema this browser refuses: skip the tool.
88
+ }
89
+ }
90
+ return () => {
91
+ removed = true;
92
+ controller.abort();
93
+ for (const name of registered.splice(0))
94
+ unregister(name);
95
+ };
96
+ }
97
+ function defaultConfirm(summary) {
98
+ const ask = globalThis.confirm;
99
+ return typeof ask === 'function' ? ask(`An AI agent wants to: ${summary}`) : false;
100
+ }
101
+ /**
102
+ * The tools this page has registered over WebMCP, by any script or by annotated forms, as
103
+ * `PageTool`s: pass them to `nano` or `createPageAgent` and the in-page agent uses what the
104
+ * page already offers other agents. Tools not marked read-only count as `write`. Empty where the
105
+ * browser cannot list tools (`getTools` is in the WebMCP draft, not in every implementation).
106
+ */
107
+ export async function webMcpTools() {
108
+ const context = modelContext()?.context;
109
+ if (!context || typeof context.getTools !== 'function' || typeof context.executeTool !== 'function')
110
+ return [];
111
+ let listed;
112
+ try {
113
+ listed = await context.getTools();
114
+ }
115
+ catch {
116
+ return [];
117
+ }
118
+ return listed.map((tool) => ({
119
+ name: tool.name,
120
+ description: tool.description ?? '',
121
+ inputSchema: parseSchema(tool.inputSchema),
122
+ write: tool.annotations?.readOnlyHint !== true,
123
+ run: (args, signal) => execute(context, tool, args, signal),
124
+ }));
125
+ }
126
+ /** The draft passes the arguments as an object; Chrome's first builds want them as JSON text. */
127
+ async function execute(context, tool, args, signal) {
128
+ try {
129
+ return await context.executeTool(tool, args, { signal });
130
+ }
131
+ catch (error) {
132
+ // Refused before the tool ran, so trying the other form cannot run it twice.
133
+ if (!(error instanceof Error) || !/parse input/i.test(error.message))
134
+ throw error;
135
+ return context.executeTool(tool, JSON.stringify(args), { signal });
136
+ }
137
+ }
138
+ function parseSchema(schema) {
139
+ if (!schema)
140
+ return undefined;
141
+ if (typeof schema !== 'string')
142
+ return schema;
143
+ try {
144
+ return JSON.parse(schema);
145
+ }
146
+ catch {
147
+ return undefined;
148
+ }
149
+ }
150
+ //# sourceMappingURL=webmcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webmcp.js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,0 +1,39 @@
1
+ /**
2
+ * `genaicode/browser`: an agent that runs in the page, on the browser's built-in model (Gemini
3
+ * Nano through Chrome's Prompt API), and the page's tools offered to outside agents over WebMCP.
4
+ * No server, no key, no cost per token. Nothing here imports Node.
5
+ *
6
+ * ```ts
7
+ * import { createPageAgent, exposeWebMcp, type PageTool } from 'genaicode/browser';
8
+ *
9
+ * const tools: PageTool[] = [
10
+ * { name: 'list_products', description: 'The products in the shop.', run: () => products },
11
+ * {
12
+ * name: 'add_to_cart',
13
+ * description: 'Put a product in the cart.',
14
+ * inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
15
+ * write: true, // the user approves it first
16
+ * run: ({ id }) => cart.add(String(id)),
17
+ * },
18
+ * ];
19
+ *
20
+ * const assistant = createPageAgent({ instructions: 'You help shoppers on Example Shop.', tools });
21
+ * exposeWebMcp(tools); // the same tools for the browser's own agent
22
+ * ```
23
+ *
24
+ * Draw it with `<PageAgentChat agent={assistant} />` from `genaicode/react`.
25
+ */
26
+ export { nano, briefing } from './browser/nano.js';
27
+ export type { NanoAgent, NanoModelCall, NanoOptions, NanoTask } from './browser/nano.js';
28
+ export { createPageAgent } from './browser/page-agent.js';
29
+ export type { PageAgent, PageAgentOptions, PageAgentState, PageModelStatus } from './browser/page-agent.js';
30
+ export { exposeWebMcp, webMcpSupported, webMcpTools } from './browser/webmcp.js';
31
+ export type { ExposeWebMcpOptions } from './browser/webmcp.js';
32
+ export { argumentProblems, toolText } from './browser/tools.js';
33
+ export type { PageTool, PageToolOutput } from './browser/tools.js';
34
+ export { builtInLanguageModel, languageModelAvailability } from './browser/language-model.js';
35
+ export type { LanguageModelAvailability, LanguageModelCreateOptions, LanguageModelFactory, LanguageModelMessage, LanguageModelPromptOptions, LanguageModelSession, } from './browser/language-model.js';
36
+ export { fakeLanguageModel } from './browser/fake-model.js';
37
+ export type { FakeCall, FakeReply } from './browser/fake-model.js';
38
+ export type { SessionEntry, SessionState, SessionTurn } from './agents/session.js';
39
+ export type { AgentEvent, AgentResult, AgentRun, AgentTask, ApprovalDecision, ApprovalRequest, CodingAgent, } from './agents/types.js';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `genaicode/browser`: an agent that runs in the page, on the browser's built-in model (Gemini
3
+ * Nano through Chrome's Prompt API), and the page's tools offered to outside agents over WebMCP.
4
+ * No server, no key, no cost per token. Nothing here imports Node.
5
+ *
6
+ * ```ts
7
+ * import { createPageAgent, exposeWebMcp, type PageTool } from 'genaicode/browser';
8
+ *
9
+ * const tools: PageTool[] = [
10
+ * { name: 'list_products', description: 'The products in the shop.', run: () => products },
11
+ * {
12
+ * name: 'add_to_cart',
13
+ * description: 'Put a product in the cart.',
14
+ * inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
15
+ * write: true, // the user approves it first
16
+ * run: ({ id }) => cart.add(String(id)),
17
+ * },
18
+ * ];
19
+ *
20
+ * const assistant = createPageAgent({ instructions: 'You help shoppers on Example Shop.', tools });
21
+ * exposeWebMcp(tools); // the same tools for the browser's own agent
22
+ * ```
23
+ *
24
+ * Draw it with `<PageAgentChat agent={assistant} />` from `genaicode/react`.
25
+ */
26
+ export { nano, briefing } from './browser/nano.js';
27
+ export { createPageAgent } from './browser/page-agent.js';
28
+ export { exposeWebMcp, webMcpSupported, webMcpTools } from './browser/webmcp.js';
29
+ export { argumentProblems, toolText } from './browser/tools.js';
30
+ export { builtInLanguageModel, languageModelAvailability } from './browser/language-model.js';
31
+ export { fakeLanguageModel } from './browser/fake-model.js';
32
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAS9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -656,6 +656,125 @@ img.gc-artifact-view {
656
656
  border-radius: 14px;
657
657
  padding: 8px 8px 8px 14px;
658
658
  }
659
+ .gc-box .gc-icon {
660
+ display: grid;
661
+ place-items: center;
662
+ width: 32px;
663
+ height: 32px;
664
+ padding: 0;
665
+ flex: none;
666
+ color: var(--_muted);
667
+ margin-left: -6px;
668
+ background: transparent;
669
+ border-color: transparent;
670
+ }
671
+ .gc-box .gc-icon + .gc-icon {
672
+ margin-left: -4px;
673
+ }
674
+ .gc-box .gc-icon:hover:not(:disabled) {
675
+ color: var(--_text);
676
+ }
677
+ .gc-box .gc-icon.gc-recording {
678
+ color: #fff;
679
+ background: var(--_danger, #e5484d);
680
+ border-color: transparent;
681
+ animation: gc-recording 1.2s ease-in-out infinite;
682
+ }
683
+ @keyframes gc-recording {
684
+ 50% {
685
+ box-shadow: 0 0 0 5px color-mix(in srgb, var(--_danger, #e5484d) 30%, transparent);
686
+ }
687
+ }
688
+ /* With attachments the field takes the whole first row; the buttons sit under it. */
689
+ .gc-box.gc-stacked {
690
+ flex-wrap: wrap;
691
+ align-items: center;
692
+ padding: 8px 8px 8px 14px;
693
+ }
694
+ .gc-box.gc-stacked textarea {
695
+ flex: 1 0 100%;
696
+ }
697
+ .gc-box .gc-grow {
698
+ flex: 1;
699
+ }
700
+ .gc-attachments {
701
+ display: flex;
702
+ flex-wrap: wrap;
703
+ gap: 6px;
704
+ margin-bottom: 8px;
705
+ }
706
+ .gc-attachments.gc-sent {
707
+ justify-content: flex-end;
708
+ align-items: flex-end;
709
+ margin: 6px 0 0;
710
+ }
711
+ .gc-attachment {
712
+ display: inline-flex;
713
+ align-items: center;
714
+ gap: 6px;
715
+ max-width: 100%;
716
+ font-size: 0.85em;
717
+ background: var(--_bg);
718
+ border: 1px solid var(--_border);
719
+ border-radius: 10px;
720
+ padding: 4px 6px 4px 8px;
721
+ }
722
+ .gc-attachment img {
723
+ width: 28px;
724
+ height: 28px;
725
+ border-radius: 6px;
726
+ object-fit: cover;
727
+ margin-left: -4px;
728
+ }
729
+ .gc-attachment i {
730
+ font-style: normal;
731
+ color: var(--_muted);
732
+ }
733
+ .gc-attachment-name {
734
+ overflow: hidden;
735
+ text-overflow: ellipsis;
736
+ white-space: nowrap;
737
+ max-width: 16em;
738
+ }
739
+ .gc-attachment small {
740
+ color: var(--_faint);
741
+ white-space: nowrap;
742
+ }
743
+ .gc-attachment button {
744
+ border: 0;
745
+ background: transparent;
746
+ color: var(--_muted);
747
+ cursor: pointer;
748
+ font-size: 1.1em;
749
+ line-height: 1;
750
+ padding: 2px 4px;
751
+ border-radius: 6px;
752
+ }
753
+ .gc-attachment button:hover {
754
+ color: var(--_text);
755
+ background: var(--_border);
756
+ }
757
+ .gc-attachment-image {
758
+ max-width: min(240px, 70%);
759
+ max-height: 180px;
760
+ border-radius: 12px;
761
+ border: 1px solid var(--_border);
762
+ object-fit: cover;
763
+ }
764
+ .gc-attachment-audio {
765
+ height: 36px;
766
+ max-width: 100%;
767
+ }
768
+ .gc-attach-problem {
769
+ font-size: 0.85em;
770
+ color: var(--_danger, #e5484d);
771
+ margin-bottom: 8px;
772
+ }
773
+ @media (prefers-reduced-motion: reduce) {
774
+ .gc-box .gc-icon.gc-recording {
775
+ animation: none;
776
+ }
777
+ }
659
778
  .gc-box:focus-within {
660
779
  border-color: var(--_accent);
661
780
  }
@@ -842,3 +961,25 @@ img.gc-artifact-view {
842
961
  color: var(--_muted);
843
962
  font-size: 0.87em;
844
963
  }
964
+
965
+ /* <PageAgentChat>: the on-device model's download and load */
966
+ .gc-page-model {
967
+ display: flex;
968
+ flex-direction: column;
969
+ align-items: stretch;
970
+ gap: 6px;
971
+ min-width: min(320px, 100%);
972
+ white-space: normal;
973
+ }
974
+ .gc-page-model progress {
975
+ width: 100%;
976
+ height: 6px;
977
+ accent-color: var(--_accent);
978
+ }
979
+ .gc-page-model small {
980
+ opacity: 0.8;
981
+ }
982
+ .gc-page-download {
983
+ max-width: 34em;
984
+ margin: 12px auto;
985
+ }
@@ -1,6 +1,7 @@
1
1
  import { type CSSProperties, type ReactNode } from 'react';
2
2
  import type { SessionState, SessionTurn } from '../agents/session.js';
3
3
  import type { ApprovalDecision, Artifact } from '../agents/types.js';
4
+ import { type ChatAttachments } from './attachments.js';
4
5
  /** A line from the host itself (not the agent), shown between turns. */
5
6
  export interface ChatNotice {
6
7
  /** Stable key. */
@@ -16,8 +17,17 @@ export interface AgentChatProps {
16
17
  * yet) shows an empty, idle chat the user can type into.
17
18
  */
18
19
  state: SessionState | null | undefined;
19
- /** The user sent `text` (Enter or the Send button). Whitespace-only input is not sent. */
20
- onSend(text: string): void;
20
+ /**
21
+ * The user sent `text` (Enter or the Send button). Whitespace-only input is not sent, unless
22
+ * files go with it: `files` is there when `attachments` is on and the user attached some.
23
+ */
24
+ onSend(text: string, files?: File[]): void;
25
+ /**
26
+ * Let the user send files with a prompt: an attach button, paste and drop, and with `voice` a
27
+ * microphone that records a voice message. Without it the composer takes text only. The host
28
+ * decides what an agent can do with a file, so set `accept` to what it handles.
29
+ */
30
+ attachments?: ChatAttachments;
21
31
  /** The user pressed Stop or Esc while the agent works. Without it there is no Stop button. */
22
32
  onStop?(): void;
23
33
  /** Offer Stop (button and Esc) while the agent is idle too: the host runs something of its own. */
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useRef, useState, } from 'react';
3
3
  import { describeFailover } from '../agents/failover.js';
4
+ import { PendingAttachments, TurnAttachments, useAttachments } from './attachments.js';
4
5
  import { useFollowScroll } from './follow-scroll.js';
5
6
  import { formatBytes, formatDuration, formatUsage, limitChips, relativePath, shortId, toolArgument, toolLabel, turnFooter, } from './format.js';
6
7
  import { Markdown } from './markdown.js';
@@ -30,12 +31,32 @@ export function AgentChat(props) {
30
31
  const rootClass = ['gc-chat', props.className].filter(Boolean).join(' ');
31
32
  const theme = props.theme && props.theme !== 'auto' ? props.theme : undefined;
32
33
  const agentName = state.agent || 'the agent';
34
+ const attached = useAttachments(props.attachments);
35
+ const picker = useRef(null);
36
+ const sendable = (!!draft.trim() || attached.files.length > 0) && !props.disabled && !attached.recording;
33
37
  const send = () => {
34
- if (!draft.trim() || props.disabled)
38
+ if (!sendable)
35
39
  return;
36
40
  follow();
37
- props.onSend(draft);
41
+ if (attached.files.length)
42
+ props.onSend(draft, attached.files);
43
+ else
44
+ props.onSend(draft);
38
45
  setDraft('');
46
+ attached.clear();
47
+ };
48
+ const onPaste = (event) => {
49
+ if (!attached.enabled || !event.clipboardData.files.length)
50
+ return;
51
+ // A copied image comes as a file; pasted text goes into the box as usual.
52
+ event.preventDefault();
53
+ attached.add(event.clipboardData.files);
54
+ };
55
+ const onDrop = (event) => {
56
+ if (!attached.enabled || !event.dataTransfer.files.length)
57
+ return;
58
+ event.preventDefault();
59
+ attached.add(event.dataTransfer.files);
39
60
  };
40
61
  const onKeyDown = (event) => {
41
62
  if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {
@@ -79,7 +100,14 @@ export function AgentChat(props) {
79
100
  : null, items, footer !== undefined && footer !== null && footer !== false ? (_jsx("div", { className: "gc-footer-slot", children: footer })) : null] }) }), _jsxs("div", { className: "gc-composer", children: [state.queued.length ? (_jsx("div", { className: "gc-queued", children: state.queued.map((prompt, i) => {
80
101
  const shown = props.renderPrompt ? props.renderPrompt(prompt) : prompt;
81
102
  return shown === null || shown === undefined || shown === false ? null : _jsxs("span", { children: ["\u23F8 ", shown] }, i);
82
- }) })) : null, _jsxs("div", { className: "gc-box", children: [_jsx("textarea", { ref: input, rows: 1, autoFocus: props.autoFocus, value: draft, placeholder: placeholder, "aria-label": "Message", onChange: (event) => setDraft(event.target.value), onKeyDown: onKeyDown }), (running || props.canStop) && props.onStop ? (_jsx("button", { type: "button", className: "gc-btn gc-danger", onClick: () => props.onStop?.(), children: "Stop" })) : null, _jsx("button", { type: "button", className: "gc-btn gc-primary", disabled: !draft.trim() || props.disabled, onClick: send, children: running ? (state.canSteer ? 'Steer' : 'Queue') : 'Send' })] }), props.hint === null ? null : (_jsx("div", { className: "gc-hint", children: props.hint ?? `Enter to send · Shift+Enter for a new line${props.onStop ? ' · Esc stops' : ''}` }))] })] }));
103
+ }) })) : null, attached.enabled ? _jsx(PendingAttachments, { files: attached.files, onRemove: attached.remove }) : null, attached.problem ? (_jsx("div", { className: "gc-attach-problem", role: "alert", children: attached.problem })) : null, _jsxs("div", { className: attached.enabled ? 'gc-box gc-stacked' : 'gc-box', onDrop: onDrop, onDragOver: (event) => {
104
+ if (attached.enabled)
105
+ event.preventDefault();
106
+ }, children: [_jsx("textarea", { ref: input, rows: 1, autoFocus: props.autoFocus, value: draft, placeholder: placeholder, "aria-label": "Message", onChange: (event) => setDraft(event.target.value), onKeyDown: onKeyDown, onPaste: onPaste }), attached.enabled ? (_jsxs(_Fragment, { children: [_jsx("input", { ref: picker, type: "file", multiple: true, hidden: true, accept: attached.accept, onChange: (event) => {
107
+ if (event.target.files)
108
+ attached.add(event.target.files);
109
+ event.target.value = '';
110
+ } }), _jsx("button", { type: "button", className: "gc-btn gc-icon", "aria-label": "Attach files", title: "Attach files (or paste, or drop them here)", disabled: attached.files.length >= attached.max, onClick: () => picker.current?.click(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "16", height: "16", "aria-hidden": "true", children: _jsx("path", { d: "M21 11.5l-8.6 8.6a5.5 5.5 0 01-7.8-7.8l9-9a3.7 3.7 0 015.2 5.2l-9 9a1.8 1.8 0 01-2.6-2.6l8.3-8.3", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), attached.canRecord ? (_jsx("button", { type: "button", className: `gc-btn gc-icon${attached.recording ? ' gc-recording' : ''}`, "aria-label": attached.recording ? 'Stop recording' : 'Record a voice message', "aria-pressed": attached.recording, title: attached.recording ? 'Stop recording' : 'Record a voice message', disabled: !attached.recording && attached.files.length >= attached.max, onClick: () => void attached.toggleRecording(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "16", height: "16", "aria-hidden": "true", children: _jsx("path", { d: "M12 3a3 3 0 00-3 3v6a3 3 0 006 0V6a3 3 0 00-3-3zM5.5 11.5a6.5 6.5 0 0013 0M12 18v3", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) })) : null, _jsx("span", { className: "gc-grow" })] })) : null, (running || props.canStop) && props.onStop ? (_jsx("button", { type: "button", className: "gc-btn gc-danger", onClick: () => props.onStop?.(), children: "Stop" })) : null, _jsx("button", { type: "button", className: "gc-btn gc-primary", disabled: !sendable, onClick: send, children: running ? (state.canSteer ? 'Steer' : 'Queue') : 'Send' })] }), props.hint === null ? null : (_jsx("div", { className: "gc-hint", children: props.hint ?? `Enter to send · Shift+Enter for a new line${props.onStop ? ' · Esc stops' : ''}` }))] })] }));
83
111
  }
84
112
  const NO_SESSION = {
85
113
  agent: '',
@@ -107,7 +135,7 @@ function Turn({ turn, now, cwd, pending, onApprove, prompt, toolName, artifactUr
107
135
  const bad = turn.result && !turn.result.ok;
108
136
  const shown = prompt ? prompt(turn.prompt, turn) : turn.prompt;
109
137
  const entry = (item, i) => (_jsx(Entry, { entry: item, agent: turn.agent, cwd: cwd, pending: pending, onApprove: onApprove, prompt: prompt, toolName: toolName, artifactUrl: artifactUrl, renderArtifact: renderArtifact, submitArtifact: submitArtifact }, i));
110
- return (_jsxs("section", { className: "gc-turn", children: [shown === null || shown === undefined || shown === false ? null : _jsx("div", { className: "gc-prompt", children: shown }), turn.entries.length ? (_jsxs("div", { className: "gc-agent-row", children: [_jsx("div", { className: "gc-avatar", title: turn.agent, "aria-hidden": "true", children: turn.agent.slice(0, 2) }), _jsx("div", { className: "gc-steps", children: fold ? (_jsx(Folded, { turn: turn, pending: pending, toolName: toolName, entry: entry })) : (turn.entries.map(entry)) })] })) : null, running ? (_jsxs("div", { className: "gc-working", children: [_jsx("span", { className: "gc-spin" }), " ", turn.agent, " is working", _jsxs("span", { "aria-hidden": "true", children: ["\u00B7 ", formatDuration(now - turn.startedAt)] })] })) : (_jsxs("div", { className: `gc-turn-footer${bad ? ' gc-bad' : ''}`, children: [turnFooter(turn, now), " \u00B7 ", turn.agent] }))] }));
138
+ return (_jsxs("section", { className: "gc-turn", children: [shown === null || shown === undefined || shown === false || (shown === '' && turn.attachments?.length) ? null : (_jsx("div", { className: "gc-prompt", children: shown })), _jsx(TurnAttachments, { items: turn.attachments }), turn.entries.length ? (_jsxs("div", { className: "gc-agent-row", children: [_jsx("div", { className: "gc-avatar", title: turn.agent, "aria-hidden": "true", children: turn.agent.slice(0, 2) }), _jsx("div", { className: "gc-steps", children: fold ? (_jsx(Folded, { turn: turn, pending: pending, toolName: toolName, entry: entry })) : (turn.entries.map(entry)) })] })) : null, running ? (_jsxs("div", { className: "gc-working", children: [_jsx("span", { className: "gc-spin" }), " ", turn.agent, " is working", _jsxs("span", { "aria-hidden": "true", children: ["\u00B7 ", formatDuration(now - turn.startedAt)] })] })) : (_jsxs("div", { className: `gc-turn-footer${bad ? ' gc-bad' : ''}`, children: [turnFooter(turn, now), " \u00B7 ", turn.agent] }))] }));
111
139
  }
112
140
  /** `foldSteps`: the work in one closed line, then what the user has to see. */
113
141
  function Folded({ turn, pending, toolName, entry, }) {