genaicode 2.31.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.
- package/README.md +1 -0
- package/dist/agents/artifacts.d.ts +16 -6
- package/dist/agents/artifacts.js +74 -23
- package/dist/agents/artifacts.js.map +1 -1
- package/dist/agents/handoff.d.ts +14 -3
- package/dist/agents/handoff.js +55 -5
- package/dist/agents/handoff.js.map +1 -1
- package/dist/agents/session.d.ts +11 -0
- package/dist/agents/session.js +22 -5
- package/dist/agents/session.js.map +1 -1
- package/dist/agents/types.d.ts +2 -2
- package/dist/agents.d.ts +1 -1
- package/dist/app-agent/http.js +2 -2
- package/dist/app-agent/http.js.map +1 -1
- package/dist/browser/fake-model.d.ts +43 -0
- package/dist/browser/fake-model.js +133 -0
- package/dist/browser/fake-model.js.map +1 -0
- package/dist/browser/language-model.d.ts +74 -0
- package/dist/browser/language-model.js +83 -0
- package/dist/browser/language-model.js.map +1 -0
- package/dist/browser/nano.d.ts +83 -0
- package/dist/browser/nano.js +610 -0
- package/dist/browser/nano.js.map +1 -0
- package/dist/browser/page-agent.d.ts +74 -0
- package/dist/browser/page-agent.js +339 -0
- package/dist/browser/page-agent.js.map +1 -0
- package/dist/browser/tools.d.ts +36 -0
- package/dist/browser/tools.js +190 -0
- package/dist/browser/tools.js.map +1 -0
- package/dist/browser/webmcp.d.ts +32 -0
- package/dist/browser/webmcp.js +150 -0
- package/dist/browser/webmcp.js.map +1 -0
- package/dist/browser.d.ts +39 -0
- package/dist/browser.js +32 -0
- package/dist/browser.js.map +1 -0
- package/dist/react/agent-chat.css +174 -0
- package/dist/react/agent-chat.d.ts +23 -2
- package/dist/react/agent-chat.js +114 -13
- package/dist/react/agent-chat.js.map +1 -1
- package/dist/react/app-agent-chat.d.ts +2 -0
- package/dist/react/app-agent-chat.js +1 -1
- package/dist/react/app-agent-chat.js.map +1 -1
- package/dist/react/attachments.d.ts +41 -0
- package/dist/react/attachments.js +162 -0
- package/dist/react/attachments.js.map +1 -0
- package/dist/react/page-agent-chat.d.ts +38 -0
- package/dist/react/page-agent-chat.js +40 -0
- package/dist/react/page-agent-chat.js.map +1 -0
- package/dist/react.d.ts +7 -2
- package/dist/react.js +3 -1
- package/dist/react.js.map +1 -1
- package/dist/ui/index.js +82 -78
- package/dist/ui/web-client.js +187 -12
- package/docs/agents.md +26 -4
- package/docs/browser.md +200 -0
- package/docs/react.md +14 -13
- package/docs/semver.md +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/browser/tools.ts"],"names":[],"mappings":"AAuBA,kDAAkD;AAClD,MAAM,UAAU,QAAQ,CAAC,MAAkC;IACzD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC3D,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAQ,MAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjF,OAAQ,MAA2B,CAAC,IAAI,CAAC;QAC3C,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAAC,IAAmC;IAClE,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,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H,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","sourceRoot":"","sources":["../../src/browser/webmcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAiB,MAAM,YAAY,CAAC;AA2BvE,SAAS,YAAY;IACnB,MAAM,UAAU,GAAI,UAA6D,CAAC,QAAQ,EAAE,YAAY,CAAC;IACzG,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,UAAU;QAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC/G,MAAM,WAAW,GAAI,UAA8D,CAAC,SAAS,EAAE,YAAY,CAAC;IAC5G,IAAI,WAAW,IAAI,OAAO,WAAW,CAAC,YAAY,KAAK,UAAU;QAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACjH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,qHAAqH;AACrH,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,EAAE,KAAK,SAAS,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAA0B,EAAE,UAA+B,EAAE;IACxF,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;IAC7B,IAAI,CAAC,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QAClF,OAAO,OAAO,CAAC,WAAY,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAsB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,MAAqC;IACxD,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAA4B,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,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';
|
package/dist/browser.js
ADDED
|
@@ -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"}
|
|
@@ -585,6 +585,39 @@ iframe.gc-artifact-view {
|
|
|
585
585
|
height: min(60vh, 520px);
|
|
586
586
|
resize: vertical;
|
|
587
587
|
}
|
|
588
|
+
audio.gc-artifact-view {
|
|
589
|
+
background: transparent;
|
|
590
|
+
padding: 8px 10px;
|
|
591
|
+
width: calc(100% - 20px);
|
|
592
|
+
box-sizing: content-box;
|
|
593
|
+
}
|
|
594
|
+
video.gc-artifact-view {
|
|
595
|
+
background: #000;
|
|
596
|
+
max-height: 70vh;
|
|
597
|
+
}
|
|
598
|
+
.gc-artifact-submit {
|
|
599
|
+
display: flex;
|
|
600
|
+
flex-direction: column;
|
|
601
|
+
gap: 6px;
|
|
602
|
+
padding: 8px 10px;
|
|
603
|
+
border-top: 1px solid var(--_border);
|
|
604
|
+
}
|
|
605
|
+
.gc-artifact-submit-text {
|
|
606
|
+
color: var(--_muted);
|
|
607
|
+
font-size: 0.87em;
|
|
608
|
+
}
|
|
609
|
+
.gc-artifact-submit-data {
|
|
610
|
+
margin: 0;
|
|
611
|
+
max-height: 180px;
|
|
612
|
+
overflow: auto;
|
|
613
|
+
font-size: 0.87em;
|
|
614
|
+
white-space: pre-wrap;
|
|
615
|
+
overflow-wrap: anywhere;
|
|
616
|
+
}
|
|
617
|
+
.gc-artifact-submit-actions {
|
|
618
|
+
display: flex;
|
|
619
|
+
gap: 8px;
|
|
620
|
+
}
|
|
588
621
|
img.gc-artifact-view {
|
|
589
622
|
height: auto;
|
|
590
623
|
max-height: 70vh;
|
|
@@ -623,6 +656,125 @@ img.gc-artifact-view {
|
|
|
623
656
|
border-radius: 14px;
|
|
624
657
|
padding: 8px 8px 8px 14px;
|
|
625
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
|
+
}
|
|
626
778
|
.gc-box:focus-within {
|
|
627
779
|
border-color: var(--_accent);
|
|
628
780
|
}
|
|
@@ -809,3 +961,25 @@ img.gc-artifact-view {
|
|
|
809
961
|
color: var(--_muted);
|
|
810
962
|
font-size: 0.87em;
|
|
811
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
|
-
/**
|
|
20
|
-
|
|
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. */
|
|
@@ -43,6 +53,12 @@ export interface AgentChatProps {
|
|
|
43
53
|
artifactUrl?(artifact: Artifact): string | undefined;
|
|
44
54
|
/** Replaces the default artifact card. Return undefined to keep the default. */
|
|
45
55
|
renderArtifact?(artifact: Artifact, url: string | undefined): ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* A page the agent published asked to send `data` back (a filled-in form, a choice) and the
|
|
58
|
+
* user confirmed it on the card. Default: `onSend(artifactSubmission(artifact, data))`, so the
|
|
59
|
+
* agent gets it as the user's next message. Pass null to let no page send anything.
|
|
60
|
+
*/
|
|
61
|
+
onArtifactSubmit?: ((artifact: Artifact, data: unknown) => void) | null;
|
|
46
62
|
/** Host content after a turn (approval cards, links...). */
|
|
47
63
|
renderAfterTurn?(turn: SessionTurn, index: number): ReactNode;
|
|
48
64
|
/** Host content at the end of the transcript, after the last turn. */
|
|
@@ -78,3 +94,8 @@ export interface AgentChatProps {
|
|
|
78
94
|
* token; the host owns the `AgentSession`. Import `genaicode/react/styles.css` once.
|
|
79
95
|
*/
|
|
80
96
|
export declare function AgentChat(props: AgentChatProps): import("react").JSX.Element;
|
|
97
|
+
/**
|
|
98
|
+
* The message that carries what the user sent from an artifact (`onArtifactSubmit`) to the
|
|
99
|
+
* agent: it names the artifact and holds `data` as JSON.
|
|
100
|
+
*/
|
|
101
|
+
export declare function artifactSubmission(artifact: Pick<Artifact, 'title' | 'name'>, data: unknown): string;
|