@runappsai/agent 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +162 -2
- package/dist/agent-core.umd.js +266 -0
- package/dist/agent.d.ts +222 -0
- package/dist/agent.js +1331 -0
- package/dist/agent.umd.js +732 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +4 -0
- package/dist/chat-theme.d.ts +24 -0
- package/dist/chat-theme.js +101 -0
- package/dist/chat.d.ts +271 -0
- package/dist/chat.js +4097 -0
- package/dist/compaction.d.ts +48 -0
- package/dist/compaction.js +208 -0
- package/dist/completion.d.ts +29 -0
- package/dist/completion.js +88 -0
- package/dist/context.d.ts +44 -0
- package/dist/context.js +177 -0
- package/dist/debug-panel.d.ts +40 -0
- package/dist/debug-panel.js +262 -0
- package/dist/dialogs.d.ts +7 -0
- package/dist/dialogs.js +231 -0
- package/dist/directory-fs.d.ts +5 -0
- package/dist/directory-fs.js +118 -0
- package/dist/dom.d.ts +83 -0
- package/dist/dom.js +163 -0
- package/dist/edit.d.ts +22 -0
- package/dist/edit.js +133 -0
- package/dist/file-guard.d.ts +46 -0
- package/dist/file-guard.js +153 -0
- package/dist/file-tools.d.ts +16 -0
- package/dist/file-tools.js +339 -0
- package/dist/files-panel.d.ts +60 -0
- package/dist/files-panel.js +613 -0
- package/dist/index.cjs +4848 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +44 -0
- package/dist/json-schema.d.ts +3 -0
- package/dist/json-schema.js +141 -0
- package/dist/llm.d.ts +95 -0
- package/dist/llm.js +5 -0
- package/dist/markdown.d.ts +4 -0
- package/dist/markdown.js +265 -0
- package/dist/mcp.d.ts +82 -0
- package/dist/mcp.js +325 -0
- package/dist/node.cjs +402 -0
- package/dist/node.d.ts +78 -0
- package/dist/node.js +432 -0
- package/dist/pdf.d.ts +52 -0
- package/dist/pdf.js +77 -0
- package/dist/provider.d.ts +135 -0
- package/dist/provider.js +181 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.js +219 -0
- package/dist/select.d.ts +30 -0
- package/dist/select.js +185 -0
- package/dist/skill-zips.d.ts +28 -0
- package/dist/skill-zips.js +123 -0
- package/dist/skills.d.ts +20 -0
- package/dist/skills.js +111 -0
- package/dist/templates.d.ts +24 -0
- package/dist/templates.js +136 -0
- package/dist/tool.d.ts +28 -0
- package/dist/tool.js +102 -0
- package/dist/types.d.ts +571 -0
- package/dist/types.js +7 -0
- package/dist/ui.cjs +6246 -0
- package/dist/ui.d.ts +6 -0
- package/dist/ui.js +11 -0
- package/dist/vlist.d.ts +80 -0
- package/dist/vlist.js +277 -0
- package/dist/workspace.d.ts +343 -0
- package/dist/workspace.js +1203 -0
- package/dist/zip.d.ts +26 -0
- package/dist/zip.js +204 -0
- package/docs/agent.md +228 -0
- package/docs/chat-ui.md +307 -0
- package/docs/node.md +135 -0
- package/docs/providers.md +176 -0
- package/docs/reference.md +143 -0
- package/docs/skills.md +131 -0
- package/docs/tools.md +254 -0
- package/docs/workspace.md +198 -0
- package/package.json +59 -4
package/dist/browser.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The colour tokens, as `--ra-<name>` custom properties on `.ra-chat`. */
|
|
2
|
+
export declare const CHAT_COLOR_TOKENS: readonly ["bg", "panel", "subtle", "muted", "fg", "fg-muted", "border", "accent", "accent-fg", "accent-subtle", "accent-muted", "user-bg", "link", "ok", "red", "red-subtle", "warn-fg", "warn-bg", "warn-border", "shadow", "shadow-md"];
|
|
3
|
+
/** Tokens that are the same in light and dark: fonts. */
|
|
4
|
+
export declare const CHAT_SHARED_TOKENS: readonly ["font", "mono"];
|
|
5
|
+
export type ChatColorToken = (typeof CHAT_COLOR_TOKENS)[number];
|
|
6
|
+
export type ChatToken = ChatColorToken | (typeof CHAT_SHARED_TOKENS)[number];
|
|
7
|
+
/** Token values by name (`accent`) or full property (`--ra-accent`). */
|
|
8
|
+
export type ChatVars = Partial<Record<ChatToken | `--ra-${ChatToken}`, string>>;
|
|
9
|
+
/** A palette: its light and dark values (tokens it leaves out keep the default palette's). */
|
|
10
|
+
export interface ChatPalette {
|
|
11
|
+
light: Partial<Record<ChatColorToken, string>>;
|
|
12
|
+
dark: Partial<Record<ChatColorToken, string>>;
|
|
13
|
+
}
|
|
14
|
+
/** The built-in palettes; `claude` is the default and defines every token. */
|
|
15
|
+
export declare const CHAT_PALETTES: Record<"claude" | "violet" | "slate" | "forest", ChatPalette>;
|
|
16
|
+
/**
|
|
17
|
+
* The token rules. They sit in `:where()`, so they weigh nothing: a host
|
|
18
|
+
* rule as plain as `.ra-chat { --ra-accent: … }` overrides them (and
|
|
19
|
+
* `.ra-chat[data-scheme=dark] { … }` for dark only). Order matters among
|
|
20
|
+
* them: default light, default dark, then each palette's light and dark.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tokenCSS(): string;
|
|
23
|
+
/** `accent` or `--ra-accent` → `--ra-accent`. */
|
|
24
|
+
export declare const tokenProp: (key: string) => string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// The chat's look as data: CSS custom properties (`--ra-*`) with a value
|
|
2
|
+
// for light and for dark, a few built-in palettes, and the per-instance
|
|
3
|
+
// overrides a host passes to renderChat. The rules in chat.ts only use
|
|
4
|
+
// these variables, so a palette or a host stylesheet restyles everything.
|
|
5
|
+
/** The colour tokens, as `--ra-<name>` custom properties on `.ra-chat`. */
|
|
6
|
+
export const CHAT_COLOR_TOKENS = [
|
|
7
|
+
"bg", "panel", "subtle", "muted", "fg", "fg-muted", "border",
|
|
8
|
+
"accent", "accent-fg", "accent-subtle", "accent-muted",
|
|
9
|
+
"user-bg", "link", "ok", "red", "red-subtle",
|
|
10
|
+
"warn-fg", "warn-bg", "warn-border", "shadow", "shadow-md",
|
|
11
|
+
];
|
|
12
|
+
/** Tokens that are the same in light and dark: fonts. */
|
|
13
|
+
export const CHAT_SHARED_TOKENS = ["font", "mono"];
|
|
14
|
+
const FONT = '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue","PingFang SC","Noto Sans SC",Arial,sans-serif';
|
|
15
|
+
const MONO = 'ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace';
|
|
16
|
+
/** The built-in palettes; `claude` is the default and defines every token. */
|
|
17
|
+
export const CHAT_PALETTES = {
|
|
18
|
+
// Ivory and warm charcoal, a coral accent, neutral user bubbles, blue links.
|
|
19
|
+
claude: {
|
|
20
|
+
light: {
|
|
21
|
+
bg: "#faf9f5", panel: "#ffffff", subtle: "#f5f4ee", muted: "#f0eee6", fg: "#141413", "fg-muted": "#73726c", border: "#e5e3da",
|
|
22
|
+
accent: "#d97757", "accent-fg": "#b85a3a", "accent-subtle": "#f7e8e1", "accent-muted": "#efcbbd",
|
|
23
|
+
"user-bg": "#f0eee6", link: "#2b6cb0", ok: "#3d8b5a", red: "#b53333", "red-subtle": "#f9ebe9",
|
|
24
|
+
"warn-fg": "#a15c07", "warn-bg": "#fdf6e7", "warn-border": "#f0d9a8",
|
|
25
|
+
shadow: "0 1px 2px rgba(31,30,29,.06)", "shadow-md": "0 6px 20px rgba(31,30,29,.12),0 1px 3px rgba(31,30,29,.08)",
|
|
26
|
+
},
|
|
27
|
+
dark: {
|
|
28
|
+
bg: "#262624", panel: "#30302e", subtle: "#2b2a28", muted: "#343432", fg: "#f5f4ee", "fg-muted": "#a3a19a", border: "#3d3d3a",
|
|
29
|
+
accent: "#d97757", "accent-fg": "#e8957a", "accent-subtle": "rgba(217,119,87,.14)", "accent-muted": "rgba(217,119,87,.32)",
|
|
30
|
+
"user-bg": "#1f1e1d", link: "#7aaeea", ok: "#6bbf86", red: "#e57373", "red-subtle": "rgba(229,115,115,.12)",
|
|
31
|
+
"warn-fg": "#f0b45c", "warn-bg": "rgba(240,180,92,.08)", "warn-border": "rgba(240,180,92,.28)",
|
|
32
|
+
shadow: "0 1px 2px rgba(0,0,0,.3)", "shadow-md": "0 6px 20px rgba(0,0,0,.45),0 1px 3px rgba(0,0,0,.3)",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// Cool grays and violet (the harness app's Chakra palette).
|
|
36
|
+
violet: {
|
|
37
|
+
light: {
|
|
38
|
+
bg: "#ffffff", panel: "#ffffff", subtle: "#fafafa", muted: "#f4f4f5", fg: "#09090b", "fg-muted": "#52525b", border: "#e4e4e7",
|
|
39
|
+
accent: "#9333ea", "accent-fg": "#7e22ce", "accent-subtle": "#f3e8ff", "accent-muted": "#e9d5ff",
|
|
40
|
+
"user-bg": "#f3e8ff", link: "#7e22ce", ok: "#16a34a", red: "#dc2626", "red-subtle": "#fef2f2",
|
|
41
|
+
},
|
|
42
|
+
dark: {
|
|
43
|
+
bg: "#09090b", panel: "#09090b", subtle: "#101014", muted: "#18181b", fg: "#fafafa", "fg-muted": "#a1a1aa", border: "#27272a",
|
|
44
|
+
accent: "#9333ea", "accent-fg": "#d8b4fe", "accent-subtle": "#3b0764", "accent-muted": "#581c87",
|
|
45
|
+
"user-bg": "#3b0764", link: "#d8b4fe", ok: "#4ade80", red: "#f87171", "red-subtle": "#2a1215",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
// Neutral grays and a blue accent.
|
|
49
|
+
slate: {
|
|
50
|
+
light: {
|
|
51
|
+
bg: "#ffffff", panel: "#ffffff", subtle: "#f9f9f9", muted: "#f3f3f3", fg: "#0d0d0d", "fg-muted": "#5d5d5d", border: "#e5e5e5",
|
|
52
|
+
accent: "#2563eb", "accent-fg": "#1d4ed8", "accent-subtle": "#eff4ff", "accent-muted": "#c7d7fe",
|
|
53
|
+
"user-bg": "#f3f3f3", link: "#2563eb", ok: "#16a34a", red: "#dc2626", "red-subtle": "#fef2f2",
|
|
54
|
+
},
|
|
55
|
+
dark: {
|
|
56
|
+
bg: "#212121", panel: "#2a2a2a", subtle: "#262626", muted: "#303030", fg: "#ececec", "fg-muted": "#a0a0a0", border: "#383838",
|
|
57
|
+
accent: "#3b82f6", "accent-fg": "#93b4fd", "accent-subtle": "rgba(59,130,246,.15)", "accent-muted": "rgba(59,130,246,.35)",
|
|
58
|
+
"user-bg": "#303030", link: "#7cacf8", ok: "#4ade80", red: "#f87171", "red-subtle": "rgba(248,113,113,.12)",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
// Soft green-grays and a green accent.
|
|
62
|
+
forest: {
|
|
63
|
+
light: {
|
|
64
|
+
bg: "#fbfcfa", panel: "#ffffff", subtle: "#f5f7f3", muted: "#eef2eb", fg: "#14201a", "fg-muted": "#5f6b63", border: "#e1e7dd",
|
|
65
|
+
accent: "#2f855a", "accent-fg": "#276749", "accent-subtle": "#e6f4ec", "accent-muted": "#b9e0c9",
|
|
66
|
+
"user-bg": "#eef2eb", link: "#2b6cb0", ok: "#2f855a", red: "#c53030", "red-subtle": "#fdecec",
|
|
67
|
+
},
|
|
68
|
+
dark: {
|
|
69
|
+
bg: "#1a201c", panel: "#222a25", subtle: "#1e2520", muted: "#283029", fg: "#eef3ee", "fg-muted": "#9aa79e", border: "#334037",
|
|
70
|
+
accent: "#48bb78", "accent-fg": "#7fd3a2", "accent-subtle": "rgba(72,187,120,.14)", "accent-muted": "rgba(72,187,120,.32)",
|
|
71
|
+
"user-bg": "#141a16", link: "#7aaeea", ok: "#68d391", red: "#fc8181", "red-subtle": "rgba(252,129,129,.12)",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const decl = (vals) => Object.entries(vals).map(([k, v]) => `--ra-${k}:${v}`).join(";");
|
|
76
|
+
/**
|
|
77
|
+
* The token rules. They sit in `:where()`, so they weigh nothing: a host
|
|
78
|
+
* rule as plain as `.ra-chat { --ra-accent: … }` overrides them (and
|
|
79
|
+
* `.ra-chat[data-scheme=dark] { … }` for dark only). Order matters among
|
|
80
|
+
* them: default light, default dark, then each palette's light and dark.
|
|
81
|
+
*/
|
|
82
|
+
export function tokenCSS() {
|
|
83
|
+
const base = CHAT_PALETTES.claude;
|
|
84
|
+
// `.ra-ui` gives the same tokens to a host's own element (a page's sidebar using selectBox):
|
|
85
|
+
// dark follows the system unless it says data-scheme="light".
|
|
86
|
+
const out = [
|
|
87
|
+
`:where(.ra-chat, .ra-ui){--ra-font:${FONT};--ra-mono:${MONO};${decl(base.light)}}`,
|
|
88
|
+
`:where(.ra-chat[data-scheme=dark], .ra-ui[data-scheme=dark]){${decl(base.dark)};color-scheme:dark}`,
|
|
89
|
+
`@media (prefers-color-scheme: dark){:where(.ra-ui:not([data-scheme=light])){${decl(base.dark)};color-scheme:dark}}`,
|
|
90
|
+
];
|
|
91
|
+
for (const [name, p] of Object.entries(CHAT_PALETTES)) {
|
|
92
|
+
if (name === "claude")
|
|
93
|
+
continue;
|
|
94
|
+
out.push(`:where(.ra-chat[data-palette=${name}], .ra-ui[data-palette=${name}]){${decl(p.light)}}`);
|
|
95
|
+
out.push(`:where(.ra-chat[data-palette=${name}][data-scheme=dark], .ra-ui[data-palette=${name}][data-scheme=dark]){${decl(p.dark)}}`);
|
|
96
|
+
out.push(`@media (prefers-color-scheme: dark){:where(.ra-ui[data-palette=${name}]:not([data-scheme=light])){${decl(p.dark)}}}`);
|
|
97
|
+
}
|
|
98
|
+
return out.join("\n");
|
|
99
|
+
}
|
|
100
|
+
/** `accent` or `--ra-accent` → `--ra-accent`. */
|
|
101
|
+
export const tokenProp = (key) => (key.startsWith("--") ? key : `--ra-${key}`);
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { type SelectBox } from "./select.js";
|
|
2
|
+
import { CHAT_PALETTES, type ChatPalette, type ChatVars } from "./chat-theme.js";
|
|
3
|
+
import { Agent } from "./index.js";
|
|
4
|
+
import type { ModelProvider, RunAppsClientLike, Workspace, AgentOptions, AgentUI, RunResult } from "./index.js";
|
|
5
|
+
export interface ChatOptions extends Omit<AgentOptions, "workspace"> {
|
|
6
|
+
/**
|
|
7
|
+
* Where the model calls go (required unless `agent` is given): a
|
|
8
|
+
* ModelProvider — `openAIProvider({ baseURL, apiKey })`, `runappsProvider(client)`
|
|
9
|
+
* or one of your own.
|
|
10
|
+
*/
|
|
11
|
+
provider?: ModelProvider | RunAppsClientLike;
|
|
12
|
+
/** A RunApps SDK client: the same as `provider: runappsProvider(client)`. */
|
|
13
|
+
client?: RunAppsClientLike;
|
|
14
|
+
/**
|
|
15
|
+
* One workspace shared by every session, or a function making one per
|
|
16
|
+
* session from the session's id — `(id) => openWorkspace(client, { id, skills })`
|
|
17
|
+
* gives each conversation its own directory (files, skills, memory).
|
|
18
|
+
*/
|
|
19
|
+
workspace?: Workspace | null | ((sessionId: string) => Workspace | Promise<Workspace>);
|
|
20
|
+
/** An agent the host made itself; its own `ui` answers questions, and the session menu is off. */
|
|
21
|
+
agent?: Agent;
|
|
22
|
+
/**
|
|
23
|
+
* Which session to open: `true` (default) continues the one this app
|
|
24
|
+
* last had open in this browser (a new chat when there is none), a
|
|
25
|
+
* string names one, `false` always starts a new one. An `id` in the
|
|
26
|
+
* agent options wins over all of these.
|
|
27
|
+
*/
|
|
28
|
+
resume?: boolean | string;
|
|
29
|
+
/** Header title (default `appName`, else "Assistant"); `false` hides the header. */
|
|
30
|
+
title?: string | false;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** Shown while the transcript is empty: text, HTML element, or nothing. */
|
|
33
|
+
/**
|
|
34
|
+
* What an empty conversation shows: a line of text, your own element
|
|
35
|
+
* (any HTML), `{ icon, title, text, align }` for an icon (SVG markup or
|
|
36
|
+
* an element), a heading and a line under it, or `null` for nothing.
|
|
37
|
+
*/
|
|
38
|
+
emptyState?: string | HTMLElement | null | {
|
|
39
|
+
icon?: string | HTMLElement;
|
|
40
|
+
title?: string;
|
|
41
|
+
text?: string;
|
|
42
|
+
align?: "center" | "start";
|
|
43
|
+
};
|
|
44
|
+
/** Starter prompts offered in the empty state; a click puts one in the composer (an object: its `label` on the button, its `prompt` in the composer). */
|
|
45
|
+
suggestions?: Array<string | {
|
|
46
|
+
label: string;
|
|
47
|
+
prompt: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* The conversation list and *New chat* (default: on when the chat makes
|
|
51
|
+
* its agents and has a workspace). Off — or with your own `agent` — the
|
|
52
|
+
* chat keeps one conversation and the header has a *Clear* button that
|
|
53
|
+
* starts it over instead (`chat.clear()`).
|
|
54
|
+
*/
|
|
55
|
+
sessions?: boolean;
|
|
56
|
+
/** The Skills button in the header: the skills, uploading a zip, removing one (default: on when the agent has a workspace). */
|
|
57
|
+
skillsMenu?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The settings gear in the header (default: on when the chat owns its
|
|
60
|
+
* agent): model, max turns, max output, tool permissions. What the user
|
|
61
|
+
* picks is kept per app in localStorage and applied to every session
|
|
62
|
+
* over the host's options.
|
|
63
|
+
*/
|
|
64
|
+
settings?: boolean;
|
|
65
|
+
/** Dialog language (default: the document's). */
|
|
66
|
+
locale?: "zh" | "en";
|
|
67
|
+
/** `"auto"` (default) follows the system; `"light"` / `"dark"` force one. */
|
|
68
|
+
theme?: "auto" | "light" | "dark";
|
|
69
|
+
/**
|
|
70
|
+
* Colours: a built-in palette by name — `"claude"` (default: ivory and
|
|
71
|
+
* warm charcoal, coral accent), `"violet"`, `"slate"` (neutral, blue
|
|
72
|
+
* accent), `"forest"` — or a palette of your own (`{ light, dark }`
|
|
73
|
+
* token values; tokens left out keep the default's).
|
|
74
|
+
*/
|
|
75
|
+
palette?: keyof typeof CHAT_PALETTES | ChatPalette;
|
|
76
|
+
/**
|
|
77
|
+
* Token overrides on top of the palette, by name (`accent`, `font`) or
|
|
78
|
+
* property (`--ra-accent`); `{ light, dark }` sets them per scheme.
|
|
79
|
+
* A host stylesheet can do the same: `.ra-chat { --ra-accent: … }`.
|
|
80
|
+
*/
|
|
81
|
+
vars?: ChatVars | {
|
|
82
|
+
light?: ChatVars;
|
|
83
|
+
dark?: ChatVars;
|
|
84
|
+
};
|
|
85
|
+
/** Extra class names on the chat's root, for host CSS. */
|
|
86
|
+
className?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Debug mode: a Debug button in the header opens what the agent did —
|
|
89
|
+
* the call chain (runs, turns, tool calls with arguments and results),
|
|
90
|
+
* the requests sent to the model with their responses, the event log,
|
|
91
|
+
* the context (system prompt, messages, limits) and the tools. Off by
|
|
92
|
+
* default; `setDebug()` switches it while mounted.
|
|
93
|
+
*/
|
|
94
|
+
debug?: boolean;
|
|
95
|
+
/** Show the context ring in the header; a click opens the context use and the spending (default on). */
|
|
96
|
+
showUsage?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Files attached to a message (paperclip, drag and drop, paste; default
|
|
99
|
+
* on): each is saved in the session's directory under `uploadsDir` and
|
|
100
|
+
* named in the message, so the agent reads it with `read_file`; an
|
|
101
|
+
* image is also sent to the model as a picture. Without a workspace,
|
|
102
|
+
* text files go inline. `false` turns the feature off.
|
|
103
|
+
*/
|
|
104
|
+
attachments?: boolean;
|
|
105
|
+
/** Where attached files are saved in the directory (default `/uploads`). */
|
|
106
|
+
uploadsDir?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Called when a link in the conversation (a reply, its thinking, a tool
|
|
109
|
+
* card) is clicked, before the chat's own handling: return `true` when you
|
|
110
|
+
* handled it (open your own viewer for your app's links), anything else to
|
|
111
|
+
* let the chat open it.
|
|
112
|
+
*/
|
|
113
|
+
onLink?: (href: string, text: string) => boolean | void;
|
|
114
|
+
/** A tool card's file path becomes a link that calls this. */
|
|
115
|
+
onOpenFile?: (path: string) => void;
|
|
116
|
+
/** The "Tool permissions" choice in the settings panel (default on). `false` for an app that decides when to ask itself (its own settings, its tools' `confirm`). */
|
|
117
|
+
permissionsSetting?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Your app's own state to put back on a rewind (an editor's text, a form):
|
|
120
|
+
* `take()` runs as each message is sent and its value is kept with the
|
|
121
|
+
* conversation (it must survive structured cloning, and needs a
|
|
122
|
+
* workspace); rewinding to a message offers `label` as a checkbox and
|
|
123
|
+
* calls `restore(value)` with what `take()` returned then.
|
|
124
|
+
*/
|
|
125
|
+
rewindState?: {
|
|
126
|
+
label: string;
|
|
127
|
+
take(): unknown | Promise<unknown>;
|
|
128
|
+
restore(value: unknown): void | Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
/** The Files button and panel (default: on with a workspace). `false` for a host with its own file view (file links then go to `onOpenFile`). */
|
|
131
|
+
files?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Suggest the user's next message: a built-in tool the model calls with
|
|
134
|
+
* its final reply when an obvious next request follows (it ends the run,
|
|
135
|
+
* so it costs no further call); the suggestion shows greyed in the empty
|
|
136
|
+
* input and Tab takes it. Off by default.
|
|
137
|
+
*/
|
|
138
|
+
nextPrompt?: boolean;
|
|
139
|
+
/** Buttons of your own for the header, placed before the settings gear. */
|
|
140
|
+
headerActions?: HTMLElement[];
|
|
141
|
+
/**
|
|
142
|
+
* Tabs of your own in the gear's panel, after the chat's own ("Model"):
|
|
143
|
+
* each holds toggles or choices the chat draws (applied with the panel's
|
|
144
|
+
* Apply, put back by its Reset when they have a `default`) or elements of
|
|
145
|
+
* yours placed as they are. The chat only shows them; you keep and use
|
|
146
|
+
* their values.
|
|
147
|
+
*/
|
|
148
|
+
settingsTabs?: SettingsTab[];
|
|
149
|
+
/** Buttons of your own at the header's far end, after the settings gear (a close or collapse button). */
|
|
150
|
+
headerEnd?: HTMLElement[];
|
|
151
|
+
/** A panel of your own right above the composer (a plan, a status); you show, hide and update it. */
|
|
152
|
+
composerTop?: HTMLElement;
|
|
153
|
+
/**
|
|
154
|
+
* Buttons of your own in the composer's toolbar, after the attach button
|
|
155
|
+
* ("Analyse the backtest", "Explain the selection"). An element is placed as
|
|
156
|
+
* it is and keeps your styles; a `ComposerAction` is drawn like the chat's
|
|
157
|
+
* own buttons and changed later with `updateComposerAction(id, …)`.
|
|
158
|
+
*/
|
|
159
|
+
composerActions?: Array<HTMLElement | ComposerAction>;
|
|
160
|
+
/** Called with each session's agent as the chat opens it (the first one, a new chat, a resumed one). */
|
|
161
|
+
onSession?: (agent: Agent) => void;
|
|
162
|
+
}
|
|
163
|
+
/** A setting of the host's in the gear's panel. */
|
|
164
|
+
export type SettingsField = {
|
|
165
|
+
id: string;
|
|
166
|
+
label: string;
|
|
167
|
+
/** A line under the label. */
|
|
168
|
+
hint?: string;
|
|
169
|
+
} & ({
|
|
170
|
+
type: "toggle";
|
|
171
|
+
value: () => boolean;
|
|
172
|
+
onChange: (v: boolean) => void;
|
|
173
|
+
default?: boolean;
|
|
174
|
+
} | {
|
|
175
|
+
type: "select";
|
|
176
|
+
options: Array<{
|
|
177
|
+
value: string;
|
|
178
|
+
label: string;
|
|
179
|
+
note?: string;
|
|
180
|
+
}>;
|
|
181
|
+
value: () => string;
|
|
182
|
+
onChange: (v: string) => void;
|
|
183
|
+
default?: string;
|
|
184
|
+
});
|
|
185
|
+
/** A tab of the host's in the gear's panel. */
|
|
186
|
+
export interface SettingsTab {
|
|
187
|
+
label: string;
|
|
188
|
+
fields: Array<SettingsField | HTMLElement>;
|
|
189
|
+
}
|
|
190
|
+
/** A button of the host's in the composer's toolbar. */
|
|
191
|
+
export interface ComposerAction {
|
|
192
|
+
/** Names it for `updateComposerAction`. */
|
|
193
|
+
id?: string;
|
|
194
|
+
label: string;
|
|
195
|
+
/** An SVG (or any HTML) drawn before the label. */
|
|
196
|
+
icon?: string;
|
|
197
|
+
/** The tooltip (default: the label). */
|
|
198
|
+
title?: string;
|
|
199
|
+
/** Only the icon, the label as tooltip (needs an icon). */
|
|
200
|
+
iconOnly?: boolean;
|
|
201
|
+
hidden?: boolean;
|
|
202
|
+
disabled?: boolean;
|
|
203
|
+
onClick: () => void;
|
|
204
|
+
}
|
|
205
|
+
export interface ChatHandle {
|
|
206
|
+
/** The current session's agent (set once `ready` resolves when the workspace is made per session). */
|
|
207
|
+
readonly agent: Agent;
|
|
208
|
+
/** Resolves once the first session is open and drawn. */
|
|
209
|
+
readonly ready: Promise<void>;
|
|
210
|
+
readonly element: HTMLElement;
|
|
211
|
+
/** The inline dialogs; a host tool may use them too. */
|
|
212
|
+
readonly ui: AgentUI;
|
|
213
|
+
/** Sends a message as if typed (queued when the agent is busy). */
|
|
214
|
+
prompt(text: string): Promise<RunResult>;
|
|
215
|
+
setInput(text: string): void;
|
|
216
|
+
/** Puts `text` into the composer at the cursor (spaced from what is around it), keeping what was typed. */
|
|
217
|
+
insertText(text: string): void;
|
|
218
|
+
/** Starts a fresh conversation (a new agent with the same options). */
|
|
219
|
+
newSession(): Promise<Agent>;
|
|
220
|
+
/** Continues a saved session of the workspace. */
|
|
221
|
+
resume(id: string): Promise<Agent>;
|
|
222
|
+
/** Deletes a saved session (and the directory made for it); the current one is replaced by a new chat. */
|
|
223
|
+
deleteSession(id: string): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Puts something of your app into the next message, shown as a chip in
|
|
226
|
+
* the composer like an attached file: what the user picked on your page,
|
|
227
|
+
* the selected text of a document, a record. `label` is what the chip and
|
|
228
|
+
* the sent message show; `text` is what the model reads with the message.
|
|
229
|
+
* An item with the same `id` replaces the one before. Returns a function
|
|
230
|
+
* that takes it out again (it also goes when the message is sent, or by
|
|
231
|
+
* its ×).
|
|
232
|
+
*/
|
|
233
|
+
addContext(item: {
|
|
234
|
+
id?: string;
|
|
235
|
+
label: string;
|
|
236
|
+
text: string;
|
|
237
|
+
title?: string;
|
|
238
|
+
icon?: string;
|
|
239
|
+
}): () => void;
|
|
240
|
+
/** Starts the open conversation over (same id): stops it and drops its messages, queue and usage. Files stay. */
|
|
241
|
+
clear(): Promise<void>;
|
|
242
|
+
/** Re-reads the workspace's skills and templates for `/` completion (after installing a skill). */
|
|
243
|
+
refresh(): Promise<void>;
|
|
244
|
+
/** Shows or hides the Debug button and panel. */
|
|
245
|
+
setDebug(on: boolean): void;
|
|
246
|
+
/** Changes a `composerActions` button by its id: label, icon, title, hidden, disabled, onClick. */
|
|
247
|
+
updateComposerAction(id: string, patch: Partial<Omit<ComposerAction, "id">>): void;
|
|
248
|
+
/** Changes the look while mounted: light/dark, palette, token overrides (each left out stays). */
|
|
249
|
+
setAppearance(opts: {
|
|
250
|
+
theme?: "auto" | "light" | "dark";
|
|
251
|
+
palette?: keyof typeof CHAT_PALETTES | ChatPalette;
|
|
252
|
+
vars?: ChatVars | {
|
|
253
|
+
light?: ChatVars;
|
|
254
|
+
dark?: ChatVars;
|
|
255
|
+
};
|
|
256
|
+
}): void;
|
|
257
|
+
/** Removes the chat; an agent the chat made is stopped (a host's `agent` is left running). */
|
|
258
|
+
unmount(): void;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gives a page's own `<select>` the chat's dropdown: the select stays (hidden) and in step — its
|
|
262
|
+
* `value` and `change` work as before — and a selectBox shows in its place. `host` positions the
|
|
263
|
+
* list (a positioned element with the class `ra-ui`, or the chat's root).
|
|
264
|
+
*/
|
|
265
|
+
export declare function enhanceSelect(select: HTMLSelectElement, host: HTMLElement, opts?: {
|
|
266
|
+
filterAt?: number;
|
|
267
|
+
filterLabel?: string;
|
|
268
|
+
}): SelectBox & {
|
|
269
|
+
destroy(): void;
|
|
270
|
+
};
|
|
271
|
+
export declare function renderChat(target: HTMLElement, opts: ChatOptions): ChatHandle;
|