@sarchauhan/chat 0.0.0-stage → 0.0.1
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 +130 -2
- package/dist/blocks.css +291 -0
- package/dist/chat.css +959 -0
- package/dist/chat.select.css +345 -0
- package/dist/chips.css +248 -0
- package/dist/chunk-5SNRYULC.mjs +2201 -0
- package/dist/chunk-5SNRYULC.mjs.map +1 -0
- package/dist/index-DabpPX_p.d.mts +177 -0
- package/dist/index-DabpPX_p.d.ts +177 -0
- package/dist/index.d.mts +382 -0
- package/dist/index.d.ts +382 -0
- package/dist/index.js +4386 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2247 -0
- package/dist/index.mjs.map +1 -0
- package/dist/markdown.css +247 -0
- package/dist/motion/error-state-shake.css +57 -0
- package/dist/motion/icon-swap.css +30 -0
- package/dist/motion/index.css +6 -0
- package/dist/motion/menu-dropdown.css +35 -0
- package/dist/motion/success-check.css +51 -0
- package/dist/motion/text-states-swap.css +28 -0
- package/dist/motion/tokens.css +96 -0
- package/dist/styles.css +11 -0
- package/dist/theme/tokens.css +253 -0
- package/dist/theme/typography.css +115 -0
- package/dist/widgets.css +570 -0
- package/dist/widgets.d.mts +4 -0
- package/dist/widgets.d.ts +4 -0
- package/dist/widgets.js +1996 -0
- package/dist/widgets.js.map +1 -0
- package/dist/widgets.mjs +48 -0
- package/dist/widgets.mjs.map +1 -0
- package/package.json +76 -4
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { AgentWidgetProps, AgentToolPart, AgentWidgetPart, AgentArtifact, AgentSubagent } from '@sarchauhan/protocol';
|
|
3
|
+
import { ComponentType, ReactNode, ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
type WidgetResponse = {
|
|
6
|
+
widgetId?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
actionId?: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
label?: string;
|
|
11
|
+
};
|
|
12
|
+
type WidgetControls = {
|
|
13
|
+
widgetId?: string;
|
|
14
|
+
widgetName: string;
|
|
15
|
+
interactive: boolean;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
respond: (value: unknown, label?: string, actionId?: string) => Promise<void>;
|
|
18
|
+
respondWith: (response: Omit<WidgetResponse, "widgetId" | "name">) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
type ChatWidgetProps<TProps extends AgentWidgetProps = AgentWidgetProps> = {
|
|
21
|
+
id?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
props: TProps;
|
|
24
|
+
interactive?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
onRespond?: (response: WidgetResponse) => void | Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
type ChatWidgetComponent<TProps extends AgentWidgetProps = AgentWidgetProps> = ComponentType<ChatWidgetProps<TProps>>;
|
|
29
|
+
type WidgetComponentProps<TProps extends AgentWidgetProps = AgentWidgetProps> = TProps & {
|
|
30
|
+
widget: WidgetControls;
|
|
31
|
+
};
|
|
32
|
+
type WidgetValue<TProps extends AgentWidgetProps, TValue> = TValue | ((props: TProps, controls: WidgetControls) => TValue);
|
|
33
|
+
type ChatWidgetDefinition<TProps extends AgentWidgetProps = AgentWidgetProps> = {
|
|
34
|
+
name: string;
|
|
35
|
+
component: ComponentType<WidgetComponentProps<TProps>>;
|
|
36
|
+
label?: WidgetValue<TProps, string>;
|
|
37
|
+
title?: WidgetValue<TProps, ReactNode>;
|
|
38
|
+
status?: WidgetValue<TProps, ReactNode>;
|
|
39
|
+
meta?: WidgetValue<TProps, ReactNode>;
|
|
40
|
+
className?: WidgetValue<TProps, string | undefined>;
|
|
41
|
+
shell?: boolean;
|
|
42
|
+
};
|
|
43
|
+
type ChatWidgetEntry<TProps extends AgentWidgetProps = AgentWidgetProps> = ChatWidgetComponent<TProps> | ChatWidgetDefinition<TProps>;
|
|
44
|
+
type ChatWidgetRegistry = Record<string, ChatWidgetEntry>;
|
|
45
|
+
type ChatWidgetInput = Array<ChatWidgetDefinition> | ChatWidgetRegistry;
|
|
46
|
+
type DefineWidgetOptions<TProps extends AgentWidgetProps> = Pick<ChatWidgetDefinition<TProps>, "label" | "title" | "status" | "meta" | "className" | "shell">;
|
|
47
|
+
declare function defineWidget<TProps extends AgentWidgetProps>(name: string, component: ComponentType<WidgetComponentProps<TProps>>, options?: DefineWidgetOptions<TProps>): ChatWidgetDefinition<TProps>;
|
|
48
|
+
declare function createWidgetRegistry(widgets?: ChatWidgetInput): ChatWidgetRegistry;
|
|
49
|
+
type WidgetContextValue = {
|
|
50
|
+
widgets: ChatWidgetRegistry;
|
|
51
|
+
respondToWidget: (response: WidgetResponse) => Promise<void>;
|
|
52
|
+
disabled: boolean;
|
|
53
|
+
};
|
|
54
|
+
type WidgetProviderProps = {
|
|
55
|
+
widgets?: ChatWidgetInput;
|
|
56
|
+
respondToWidget: (response: WidgetResponse) => Promise<void>;
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
children: ReactNode;
|
|
59
|
+
};
|
|
60
|
+
declare function WidgetProvider({ widgets, respondToWidget, disabled, children, }: WidgetProviderProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
declare function useWidgets(): WidgetContextValue;
|
|
62
|
+
|
|
63
|
+
type WidgetState = "running" | "complete" | "error" | "denied" | "approval";
|
|
64
|
+
type ToolWidgetProps = {
|
|
65
|
+
state?: WidgetState;
|
|
66
|
+
error?: string;
|
|
67
|
+
className?: string;
|
|
68
|
+
};
|
|
69
|
+
type ReadFileWidgetProps = ToolWidgetProps & {
|
|
70
|
+
path: string;
|
|
71
|
+
content?: string;
|
|
72
|
+
startLine?: number;
|
|
73
|
+
language?: string;
|
|
74
|
+
maxLines?: number;
|
|
75
|
+
};
|
|
76
|
+
type PatchWidgetProps = ToolWidgetProps & {
|
|
77
|
+
path?: string;
|
|
78
|
+
diff?: string;
|
|
79
|
+
before?: string;
|
|
80
|
+
after?: string;
|
|
81
|
+
maxLines?: number;
|
|
82
|
+
};
|
|
83
|
+
type SearchResult = {
|
|
84
|
+
path: string;
|
|
85
|
+
line?: number;
|
|
86
|
+
text?: string;
|
|
87
|
+
title?: string;
|
|
88
|
+
url?: string;
|
|
89
|
+
};
|
|
90
|
+
type SearchWidgetProps = ToolWidgetProps & {
|
|
91
|
+
query: string;
|
|
92
|
+
results?: SearchResult[];
|
|
93
|
+
total?: number;
|
|
94
|
+
maxResults?: number;
|
|
95
|
+
};
|
|
96
|
+
type QuestionOption = {
|
|
97
|
+
label: string;
|
|
98
|
+
value: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
recommended?: boolean;
|
|
101
|
+
};
|
|
102
|
+
type QuestionAnswer = {
|
|
103
|
+
values: string[];
|
|
104
|
+
text?: string;
|
|
105
|
+
};
|
|
106
|
+
type QuestionWidgetProps = {
|
|
107
|
+
prompt: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
options?: Array<string | QuestionOption>;
|
|
110
|
+
multiple?: boolean;
|
|
111
|
+
allowCustom?: boolean;
|
|
112
|
+
disabled?: boolean;
|
|
113
|
+
onSubmit?: (answer: QuestionAnswer) => void | Promise<void>;
|
|
114
|
+
className?: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
declare function ReadFileWidget({ path, content, startLine, language, maxLines, ...props }: ReadFileWidgetProps): react_jsx_runtime.JSX.Element;
|
|
118
|
+
|
|
119
|
+
declare function PatchWidget({ path, diff: rawDiff, before, after, maxLines, ...props }: PatchWidgetProps): react_jsx_runtime.JSX.Element;
|
|
120
|
+
|
|
121
|
+
declare function SearchWidget({ query, results, total, maxResults, ...props }: SearchWidgetProps): react_jsx_runtime.JSX.Element;
|
|
122
|
+
|
|
123
|
+
declare function QuestionWidget({ prompt, description, options, multiple, allowCustom, disabled, onSubmit, className, }: QuestionWidgetProps): react_jsx_runtime.JSX.Element;
|
|
124
|
+
|
|
125
|
+
/** Defaults are always available; a host registry can override any name. */
|
|
126
|
+
declare const prebuiltWidgets: ChatWidgetRegistry;
|
|
127
|
+
|
|
128
|
+
declare function computeToolState(part: AgentToolPart): WidgetState;
|
|
129
|
+
declare function normalizeSearchResults(value: unknown): SearchResult[];
|
|
130
|
+
/** Convert known tool payloads; unknown or incomplete formats retain the raw tool view. */
|
|
131
|
+
declare function computeToolWidget(part: AgentToolPart): AgentWidgetPart | null;
|
|
132
|
+
type DiffLine = {
|
|
133
|
+
kind: "add" | "remove" | "context" | "header";
|
|
134
|
+
text: string;
|
|
135
|
+
oldLine?: number;
|
|
136
|
+
newLine?: number;
|
|
137
|
+
};
|
|
138
|
+
/** Parse unified diffs (including multiple files) without counting file headers as edits. */
|
|
139
|
+
declare function computeDiff(diff: string): {
|
|
140
|
+
lines: DiffLine[];
|
|
141
|
+
additions: number;
|
|
142
|
+
deletions: number;
|
|
143
|
+
};
|
|
144
|
+
declare function safeResultUrl(url?: string): string | undefined;
|
|
145
|
+
/** Compute a unified replacement hunk with three context lines. Common edges stay out of the diff. */
|
|
146
|
+
declare function computeTextDiff(before: string, after: string, path?: string): string;
|
|
147
|
+
|
|
148
|
+
type ArtifactWidgetProps = {
|
|
149
|
+
artifact: AgentArtifact;
|
|
150
|
+
className?: string;
|
|
151
|
+
};
|
|
152
|
+
type ArtifactsWidgetProps = {
|
|
153
|
+
artifacts: AgentArtifact[];
|
|
154
|
+
className?: string;
|
|
155
|
+
};
|
|
156
|
+
/** Same-origin relative URLs, HTTP(S), blob URLs, and raster-image data URLs only. */
|
|
157
|
+
declare function safeArtifactUrl(value?: string, image?: boolean): string | undefined;
|
|
158
|
+
declare function formatArtifactSize(bytes?: number): string | undefined;
|
|
159
|
+
declare function ArtifactWidget({ artifact, className }: ArtifactWidgetProps): react_jsx_runtime.JSX.Element;
|
|
160
|
+
declare function ArtifactsWidget({ artifacts, className }: ArtifactsWidgetProps): react_jsx_runtime.JSX.Element;
|
|
161
|
+
|
|
162
|
+
type SubagentWidgetProps = {
|
|
163
|
+
subagent: AgentSubagent;
|
|
164
|
+
className?: string;
|
|
165
|
+
};
|
|
166
|
+
declare function SubagentWidget({ subagent, className }: SubagentWidgetProps): react_jsx_runtime.JSX.Element;
|
|
167
|
+
|
|
168
|
+
type ResponsiveDetailProps = {
|
|
169
|
+
title: string;
|
|
170
|
+
description?: string;
|
|
171
|
+
trigger: ReactElement;
|
|
172
|
+
children: ReactNode;
|
|
173
|
+
};
|
|
174
|
+
/** One accessible dialog; CSS changes its presentation to a bottom sheet below 640px. */
|
|
175
|
+
declare function ResponsiveDetail({ title, description, trigger, children }: ResponsiveDetailProps): react_jsx_runtime.JSX.Element;
|
|
176
|
+
|
|
177
|
+
export { ArtifactWidget as A, computeToolState as B, type ChatWidgetInput as C, type DefineWidgetOptions as D, computeToolWidget as E, createWidgetRegistry as F, defineWidget as G, formatArtifactSize as H, normalizeSearchResults as I, prebuiltWidgets as J, safeArtifactUrl as K, safeResultUrl as L, useWidgets as M, PatchWidget as P, type QuestionAnswer as Q, ReadFileWidget as R, type SearchResult as S, type ToolWidgetProps as T, type WidgetComponentProps as W, type ArtifactWidgetProps as a, ArtifactsWidget as b, type ArtifactsWidgetProps as c, type ChatWidgetComponent as d, type ChatWidgetDefinition as e, type ChatWidgetEntry as f, type ChatWidgetProps as g, type ChatWidgetRegistry as h, type DiffLine as i, type PatchWidgetProps as j, type QuestionOption as k, QuestionWidget as l, type QuestionWidgetProps as m, type ReadFileWidgetProps as n, ResponsiveDetail as o, type ResponsiveDetailProps as p, SearchWidget as q, type SearchWidgetProps as r, SubagentWidget as s, type SubagentWidgetProps as t, type WidgetControls as u, WidgetProvider as v, type WidgetResponse as w, type WidgetState as x, computeDiff as y, computeTextDiff as z };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties, Dispatch, HTMLAttributes, RefObject } from 'react';
|
|
3
|
+
import * as _sarchauhan_adapter from '@sarchauhan/adapter';
|
|
4
|
+
import { ChatAdapter, ChatMessage, ChatStatus, ChatThread } from '@sarchauhan/adapter';
|
|
5
|
+
export { ChatAdapter, ChatMessage, ChatMessagePart, ChatRole, ChatStatus, ChatThread, EditMessageInput, SendMessageInput, defineAdapter } from '@sarchauhan/adapter';
|
|
6
|
+
import { C as ChatWidgetInput } from './index-DabpPX_p.mjs';
|
|
7
|
+
export { A as ArtifactWidget, a as ArtifactWidgetProps, b as ArtifactsWidget, c as ArtifactsWidgetProps, d as ChatWidgetComponent, e as ChatWidgetDefinition, f as ChatWidgetEntry, g as ChatWidgetProps, h as ChatWidgetRegistry, D as DefineWidgetOptions, i as DiffLine, P as PatchWidget, j as PatchWidgetProps, Q as QuestionAnswer, k as QuestionOption, l as QuestionWidget, m as QuestionWidgetProps, R as ReadFileWidget, n as ReadFileWidgetProps, o as ResponsiveDetail, p as ResponsiveDetailProps, S as SearchResult, q as SearchWidget, r as SearchWidgetProps, s as SubagentWidget, t as SubagentWidgetProps, T as ToolWidgetProps, W as WidgetComponentProps, u as WidgetControls, v as WidgetProvider, w as WidgetResponse, x as WidgetState, y as computeDiff, z as computeTextDiff, B as computeToolState, E as computeToolWidget, F as createWidgetRegistry, G as defineWidget, H as formatArtifactSize, I as normalizeSearchResults, J as prebuiltWidgets, K as safeArtifactUrl, L as safeResultUrl, M as useWidgets } from './index-DabpPX_p.mjs';
|
|
8
|
+
import { AgentDataPart, AgentWidgetPart } from '@sarchauhan/protocol';
|
|
9
|
+
export { AgentArtifact, AgentEvent, AgentMessage, AgentPart, AgentSubagent, AgentSubagentState, AgentToolPart, AgentWidgetPart, applyAgentEvent, createAgentMessageState, createArtifactData, createSubagentData, createWidgetData, normalizeAgentMessage, normalizeAgentParts, parseArtifact, parseSubagent, reduceAgentEvents } from '@sarchauhan/protocol';
|
|
10
|
+
|
|
11
|
+
type ChatTheme = "light" | "dark" | "system";
|
|
12
|
+
type ThemeContextValue = {
|
|
13
|
+
theme: ChatTheme;
|
|
14
|
+
resolvedTheme: "light" | "dark";
|
|
15
|
+
setTheme: (theme: ChatTheme) => void;
|
|
16
|
+
toggleTheme: () => void;
|
|
17
|
+
};
|
|
18
|
+
type ThemeProviderProps = {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
defaultTheme?: ChatTheme;
|
|
21
|
+
theme?: ChatTheme;
|
|
22
|
+
onThemeChange?: (theme: ChatTheme) => void;
|
|
23
|
+
storageKey?: string;
|
|
24
|
+
};
|
|
25
|
+
declare function ThemeProvider({ children, defaultTheme, theme: controlledTheme, onThemeChange, storageKey, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
declare function useTheme(): ThemeContextValue;
|
|
27
|
+
|
|
28
|
+
type ComposerCollapsedVariant = "pill" | "circle";
|
|
29
|
+
declare const ChatComposer: ({ showModelSelector, collapsedVariant, defaultExpanded, }: {
|
|
30
|
+
showModelSelector?: boolean;
|
|
31
|
+
/** Resting shape when the composer is empty and blurred. Default is the wide pill. */
|
|
32
|
+
collapsedVariant?: ComposerCollapsedVariant;
|
|
33
|
+
/** Open on the large composer. Used so a story can show the model picker without a click. */
|
|
34
|
+
defaultExpanded?: boolean;
|
|
35
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
36
|
+
|
|
37
|
+
type BaseWidgetProps = {
|
|
38
|
+
label: string;
|
|
39
|
+
title: ReactNode;
|
|
40
|
+
status?: ReactNode;
|
|
41
|
+
meta?: ReactNode;
|
|
42
|
+
className?: string;
|
|
43
|
+
children?: ReactNode;
|
|
44
|
+
};
|
|
45
|
+
declare function BaseWidget({ label, title, status, meta, className, children, }: BaseWidgetProps): react_jsx_runtime.JSX.Element;
|
|
46
|
+
|
|
47
|
+
type ChatProps = {
|
|
48
|
+
adapter: ChatAdapter;
|
|
49
|
+
className?: string;
|
|
50
|
+
defaultThreadId?: string;
|
|
51
|
+
defaultProvider?: string;
|
|
52
|
+
registryUrl?: string;
|
|
53
|
+
style?: CSSProperties;
|
|
54
|
+
/** Widget map or defineWidget(...) array. */
|
|
55
|
+
widgets?: ChatWidgetInput;
|
|
56
|
+
/** Controlled theme. Omit to manage theme internally. */
|
|
57
|
+
theme?: ChatTheme;
|
|
58
|
+
defaultTheme?: ChatTheme;
|
|
59
|
+
onThemeChange?: (theme: ChatTheme) => void;
|
|
60
|
+
showThemeToggle?: boolean;
|
|
61
|
+
showModelSelector?: boolean;
|
|
62
|
+
collapsedVariant?: ComposerCollapsedVariant;
|
|
63
|
+
defaultExpanded?: boolean;
|
|
64
|
+
};
|
|
65
|
+
declare function Chat({ adapter, className, defaultThreadId, defaultProvider, registryUrl, style, widgets, theme, defaultTheme, onThemeChange, showThemeToggle, showModelSelector, collapsedVariant, defaultExpanded, }: ChatProps): react_jsx_runtime.JSX.Element;
|
|
66
|
+
|
|
67
|
+
declare enum ProviderId {
|
|
68
|
+
SYMPHONY = "symphony",
|
|
69
|
+
MOCK = "mock",
|
|
70
|
+
OPENAI = "openai",
|
|
71
|
+
GOOGLE = "google",
|
|
72
|
+
GEMINI = "gemini",
|
|
73
|
+
CLAUDE = "anthropic",
|
|
74
|
+
GROK = "grok",
|
|
75
|
+
OLLAMA = "ollama",
|
|
76
|
+
LOCAL = "local"
|
|
77
|
+
}
|
|
78
|
+
type RegistryModel = {
|
|
79
|
+
id: string;
|
|
80
|
+
label: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
thinkingLevels?: string[];
|
|
83
|
+
};
|
|
84
|
+
type RegistryProvider = {
|
|
85
|
+
/** Known `ProviderId` values or a Symphony / custom registry id. */
|
|
86
|
+
id: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
label: string;
|
|
89
|
+
logo?: string;
|
|
90
|
+
defaultModel: string;
|
|
91
|
+
models: RegistryModel[];
|
|
92
|
+
};
|
|
93
|
+
type RegistryConfig = {
|
|
94
|
+
defaultProviderId: string;
|
|
95
|
+
providers: RegistryProvider[];
|
|
96
|
+
};
|
|
97
|
+
declare const isProviderId: (value: unknown) => value is ProviderId;
|
|
98
|
+
declare const parseRegistryConfig: (value: unknown) => RegistryConfig | undefined;
|
|
99
|
+
type ChatReference = {
|
|
100
|
+
id: string;
|
|
101
|
+
text: string;
|
|
102
|
+
};
|
|
103
|
+
/** File part carried on the existing send payload. `url` is a data URL. */
|
|
104
|
+
type ComposerFile = {
|
|
105
|
+
mediaType: string;
|
|
106
|
+
url: string;
|
|
107
|
+
filename?: string;
|
|
108
|
+
};
|
|
109
|
+
type ComposerAttachment = ComposerFile & {
|
|
110
|
+
id: string;
|
|
111
|
+
filename: string;
|
|
112
|
+
};
|
|
113
|
+
type SendMessage = (message: {
|
|
114
|
+
text: string;
|
|
115
|
+
files?: ComposerFile[];
|
|
116
|
+
}, options?: {
|
|
117
|
+
body?: {
|
|
118
|
+
provider?: string;
|
|
119
|
+
model?: string;
|
|
120
|
+
};
|
|
121
|
+
}) => Promise<void>;
|
|
122
|
+
|
|
123
|
+
type ChatContextProviderProps = {
|
|
124
|
+
adapter: ChatAdapter;
|
|
125
|
+
children: ReactNode;
|
|
126
|
+
defaultProvider?: string;
|
|
127
|
+
defaultThreadId?: string;
|
|
128
|
+
registryUrl?: string;
|
|
129
|
+
};
|
|
130
|
+
declare function ChatContextProvider({ adapter, children, defaultProvider, defaultThreadId, registryUrl, }: ChatContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
131
|
+
|
|
132
|
+
type ComposerContextValue = {
|
|
133
|
+
input: string;
|
|
134
|
+
setInput: (value: string) => void;
|
|
135
|
+
references: ChatReference[];
|
|
136
|
+
addReference: (text: string) => void;
|
|
137
|
+
removeReference: (id: string) => void;
|
|
138
|
+
clearReferences: () => void;
|
|
139
|
+
attachments: ComposerAttachment[];
|
|
140
|
+
addFiles: (files: FileList | readonly File[]) => Promise<void>;
|
|
141
|
+
removeAttachment: (id: string) => void;
|
|
142
|
+
disabled: boolean;
|
|
143
|
+
canSend: boolean;
|
|
144
|
+
submitInput: () => Promise<void>;
|
|
145
|
+
};
|
|
146
|
+
declare function useComposer(): ComposerContextValue;
|
|
147
|
+
|
|
148
|
+
type MessagesContextValue = {
|
|
149
|
+
messages: ChatMessage[];
|
|
150
|
+
status: ChatStatus;
|
|
151
|
+
isSending: boolean;
|
|
152
|
+
isWaitingForResponse: boolean;
|
|
153
|
+
sendMessage: SendMessage;
|
|
154
|
+
editAndResendMessage: (messageId: string, text: string) => Promise<void>;
|
|
155
|
+
stopResponse: () => void;
|
|
156
|
+
};
|
|
157
|
+
declare function useMessages(): MessagesContextValue;
|
|
158
|
+
|
|
159
|
+
type ModelContextValue = {
|
|
160
|
+
registry: RegistryConfig;
|
|
161
|
+
provider: string;
|
|
162
|
+
model: string;
|
|
163
|
+
thinkingLevels: Record<string, string>;
|
|
164
|
+
getThinkingLevel: (providerId: string, modelId: string) => string | undefined;
|
|
165
|
+
setThinkingLevel: (providerId: string, modelId: string, level: string) => void;
|
|
166
|
+
setProvider: (provider: string, model?: string) => void;
|
|
167
|
+
setModel: (model: string) => void;
|
|
168
|
+
providerRef: React.MutableRefObject<string>;
|
|
169
|
+
modelRef: React.MutableRefObject<string>;
|
|
170
|
+
thinkingLevelsRef: React.MutableRefObject<Record<string, string>>;
|
|
171
|
+
};
|
|
172
|
+
declare function useModel(): ModelContextValue;
|
|
173
|
+
|
|
174
|
+
type ThreadContextValue = {
|
|
175
|
+
threads: ChatThread[];
|
|
176
|
+
activeThreadId: string | null;
|
|
177
|
+
isLoadingThread: boolean;
|
|
178
|
+
activeThreadIdRef: React.MutableRefObject<string | null>;
|
|
179
|
+
setThreads: React.Dispatch<React.SetStateAction<ChatThread[]>>;
|
|
180
|
+
setIsLoadingThread: React.Dispatch<React.SetStateAction<boolean>>;
|
|
181
|
+
selectThread: (threadId: string) => Promise<void>;
|
|
182
|
+
createThread: () => Promise<void>;
|
|
183
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
184
|
+
};
|
|
185
|
+
declare function useThread(): ThreadContextValue;
|
|
186
|
+
|
|
187
|
+
type CompatAction = {
|
|
188
|
+
type: "setInput";
|
|
189
|
+
data: {
|
|
190
|
+
input: string;
|
|
191
|
+
};
|
|
192
|
+
} | {
|
|
193
|
+
type: "setProvider";
|
|
194
|
+
data: {
|
|
195
|
+
provider: string;
|
|
196
|
+
model?: string;
|
|
197
|
+
};
|
|
198
|
+
} | {
|
|
199
|
+
type: "setModel";
|
|
200
|
+
data: {
|
|
201
|
+
model: string;
|
|
202
|
+
};
|
|
203
|
+
} | {
|
|
204
|
+
type: "addReference";
|
|
205
|
+
data: {
|
|
206
|
+
text: string;
|
|
207
|
+
};
|
|
208
|
+
} | {
|
|
209
|
+
type: "removeReference";
|
|
210
|
+
data: {
|
|
211
|
+
id: string;
|
|
212
|
+
};
|
|
213
|
+
} | {
|
|
214
|
+
type: "clearReferences";
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Compatibility facade over split contexts.
|
|
218
|
+
* Prefer useComposer / useMessages / useModel / useThread in UI components
|
|
219
|
+
* so typing and streaming do not share one render subscription.
|
|
220
|
+
*/
|
|
221
|
+
declare function useChat(): {
|
|
222
|
+
state: {
|
|
223
|
+
input: string;
|
|
224
|
+
provider: string;
|
|
225
|
+
model: string;
|
|
226
|
+
references: ChatReference[];
|
|
227
|
+
disabled: boolean;
|
|
228
|
+
sendDisabled: boolean;
|
|
229
|
+
};
|
|
230
|
+
dispatch: Dispatch<CompatAction>;
|
|
231
|
+
messages: _sarchauhan_adapter.ChatMessage[];
|
|
232
|
+
status: _sarchauhan_adapter.ChatStatus;
|
|
233
|
+
activeThreadId: string | null;
|
|
234
|
+
threads: _sarchauhan_adapter.ChatThread[];
|
|
235
|
+
isLoadingThread: boolean;
|
|
236
|
+
registry: RegistryConfig;
|
|
237
|
+
sendMessage: SendMessage;
|
|
238
|
+
submitInput: () => Promise<void>;
|
|
239
|
+
editAndResendMessage: (messageId: string, text: string) => Promise<void>;
|
|
240
|
+
stopResponse: () => void;
|
|
241
|
+
selectThread: (threadId: string) => Promise<void>;
|
|
242
|
+
createThread: () => Promise<void>;
|
|
243
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
declare const Message: () => react_jsx_runtime.JSX.Element;
|
|
247
|
+
|
|
248
|
+
type MessageFeedbackProps = {
|
|
249
|
+
responseText: string;
|
|
250
|
+
onRegenerate: () => void;
|
|
251
|
+
canRegenerate: boolean;
|
|
252
|
+
disabled?: boolean;
|
|
253
|
+
};
|
|
254
|
+
declare const MessageFeedback: ({ responseText, onRegenerate, canRegenerate, disabled, }: MessageFeedbackProps) => react_jsx_runtime.JSX.Element | null;
|
|
255
|
+
|
|
256
|
+
declare const MessageUsage: ({ parts }: {
|
|
257
|
+
parts: AgentDataPart[];
|
|
258
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
259
|
+
|
|
260
|
+
declare const formatElapsed: (milliseconds: number, showTenths?: boolean) => string;
|
|
261
|
+
declare const formatElapsedWords: (milliseconds: number) => string;
|
|
262
|
+
type LoadingStateProps = {
|
|
263
|
+
label?: string;
|
|
264
|
+
compact?: boolean;
|
|
265
|
+
};
|
|
266
|
+
declare const LoadingState: ({ label, compact }: LoadingStateProps) => react_jsx_runtime.JSX.Element;
|
|
267
|
+
|
|
268
|
+
type ThinkingBlockProps = {
|
|
269
|
+
isComplete: boolean;
|
|
270
|
+
elapsedMs?: number;
|
|
271
|
+
children?: ReactNode;
|
|
272
|
+
};
|
|
273
|
+
declare const ThinkingBlock: ({ isComplete, elapsedMs, children }: ThinkingBlockProps) => react_jsx_runtime.JSX.Element;
|
|
274
|
+
|
|
275
|
+
type MessageContentProps = {
|
|
276
|
+
parts: Array<{
|
|
277
|
+
type: string;
|
|
278
|
+
[key: string]: unknown;
|
|
279
|
+
}>;
|
|
280
|
+
isUser?: boolean;
|
|
281
|
+
};
|
|
282
|
+
declare const MessageContent: ({ parts, isUser }: MessageContentProps) => react_jsx_runtime.JSX.Element;
|
|
283
|
+
|
|
284
|
+
declare function ThemeToggle({ className }: {
|
|
285
|
+
className?: string;
|
|
286
|
+
}): react_jsx_runtime.JSX.Element;
|
|
287
|
+
|
|
288
|
+
declare function WidgetRenderer({ part, pending, }: {
|
|
289
|
+
part: AgentWidgetPart;
|
|
290
|
+
pending?: boolean;
|
|
291
|
+
}): react_jsx_runtime.JSX.Element;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Public motion class names and data-attribute hooks from the
|
|
295
|
+
* transitions.dev recipes packaged with `@sarchauhan/chat`.
|
|
296
|
+
*
|
|
297
|
+
* Consumers should import these constants instead of hard-coding
|
|
298
|
+
* `t-*` strings so class names stay autocomplete-safe and typechecked.
|
|
299
|
+
*/
|
|
300
|
+
declare const motion: {
|
|
301
|
+
readonly textSwap: "t-text-swap";
|
|
302
|
+
readonly isExit: "is-exit";
|
|
303
|
+
readonly isEnterStart: "is-enter-start";
|
|
304
|
+
readonly iconSwap: "t-icon-swap";
|
|
305
|
+
readonly icon: "t-icon";
|
|
306
|
+
readonly successCheck: "t-success-check";
|
|
307
|
+
readonly dropdown: "t-dropdown";
|
|
308
|
+
readonly isOpen: "is-open";
|
|
309
|
+
readonly isClosing: "is-closing";
|
|
310
|
+
readonly inputWrap: "t-input-wrap";
|
|
311
|
+
readonly input: "t-input";
|
|
312
|
+
readonly errorMsg: "t-error-msg";
|
|
313
|
+
readonly isError: "is-error";
|
|
314
|
+
readonly isShaking: "is-shaking";
|
|
315
|
+
};
|
|
316
|
+
type MotionClass = (typeof motion)[keyof typeof motion];
|
|
317
|
+
declare const iconSwapStates: readonly ["a", "b"];
|
|
318
|
+
type IconSwapState = (typeof iconSwapStates)[number];
|
|
319
|
+
declare const successCheckStates: readonly ["out", "in"];
|
|
320
|
+
type SuccessCheckState = (typeof successCheckStates)[number];
|
|
321
|
+
declare const dropdownOrigins: readonly ["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"];
|
|
322
|
+
type DropdownOrigin = (typeof dropdownOrigins)[number];
|
|
323
|
+
declare const motionData: {
|
|
324
|
+
readonly state: "data-state";
|
|
325
|
+
readonly icon: "data-icon";
|
|
326
|
+
readonly origin: "data-origin";
|
|
327
|
+
readonly open: "data-open";
|
|
328
|
+
};
|
|
329
|
+
declare const dropdownPhases: readonly ["rest", "open", "closing"];
|
|
330
|
+
type DropdownPhase = (typeof dropdownPhases)[number];
|
|
331
|
+
|
|
332
|
+
declare const prefersReducedMotion: () => boolean;
|
|
333
|
+
declare const motionRoot: (node?: Element | null) => Element | null;
|
|
334
|
+
/** Read a duration custom property (ms) from `.chat-root`, with a numeric fallback. */
|
|
335
|
+
declare const readDurationMs: (name: string, fallback: number, node?: Element | null) => number;
|
|
336
|
+
type SwapTextOptions = {
|
|
337
|
+
onSwap?: () => void;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Three-phase text swap from transitions.dev (04-text-states-swap):
|
|
341
|
+
* exit → swap content → enter-start (no transition) → rest.
|
|
342
|
+
*/
|
|
343
|
+
declare const swapText: (el: HTMLElement, next: string, options?: SwapTextOptions) => number | undefined;
|
|
344
|
+
declare const openDropdown: (el: HTMLElement) => void;
|
|
345
|
+
declare const closeDropdown: (el: HTMLElement, onClosed?: () => void) => number;
|
|
346
|
+
type TriggerErrorShakeOptions = {
|
|
347
|
+
/** Keep `.is-error` after the shake (persistent tool errors). Default: auto-revert. */
|
|
348
|
+
revert?: boolean;
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Replay the error shake from a clean baseline (12-error-state-shake).
|
|
352
|
+
* `.is-error` and `.is-shaking` stay orthogonal so the shake can restart
|
|
353
|
+
* without flickering the error treatment.
|
|
354
|
+
*/
|
|
355
|
+
declare const triggerErrorShake: (wrap: HTMLElement, options?: TriggerErrorShakeOptions) => void;
|
|
356
|
+
declare const clearErrorShake: (wrap: HTMLElement) => void;
|
|
357
|
+
/** Measure an SVG path and set stroke-dasharray for the success-check draw. */
|
|
358
|
+
declare const calibrateCheckPath: (path: SVGPathElement) => void;
|
|
359
|
+
|
|
360
|
+
type TextSwapProps = {
|
|
361
|
+
text: string;
|
|
362
|
+
} & Omit<HTMLAttributes<HTMLSpanElement>, "children">;
|
|
363
|
+
/**
|
|
364
|
+
* Status-line text that swaps in place (transitions.dev text-states-swap).
|
|
365
|
+
* React keeps the outgoing string painted until the exit phase finishes.
|
|
366
|
+
*/
|
|
367
|
+
declare function TextSwap({ text, className, ...props }: TextSwapProps): react_jsx_runtime.JSX.Element;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Keep a dropdown mounted through the close tween and apply the
|
|
371
|
+
* documented `.is-open` / `.is-closing` hooks (05-menu-dropdown).
|
|
372
|
+
*
|
|
373
|
+
* Mounts at rest (pre-scale, opacity 0), then adds `.is-open` on the
|
|
374
|
+
* next frame so the open transition actually plays.
|
|
375
|
+
*/
|
|
376
|
+
declare function useDropdownPresence(open: boolean, root?: Element | RefObject<Element | null> | null): {
|
|
377
|
+
readonly mounted: boolean;
|
|
378
|
+
readonly phase: "open" | "rest" | "closing";
|
|
379
|
+
readonly className: "is-open" | "is-closing" | undefined;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export { BaseWidget, type BaseWidgetProps, Chat, ChatComposer, ChatContextProvider, type ChatReference, type ChatTheme, ChatWidgetInput, type ComposerAttachment, type ComposerCollapsedVariant, type ComposerFile, type DropdownOrigin, type DropdownPhase, type IconSwapState, LoadingState, Message, MessageContent, MessageFeedback, MessageUsage, type MotionClass, ProviderId, type RegistryConfig, type RegistryModel, type RegistryProvider, type SendMessage, type SuccessCheckState, TextSwap, ThemeProvider, ThemeToggle, ThinkingBlock, WidgetRenderer, calibrateCheckPath, clearErrorShake, closeDropdown, dropdownOrigins, formatElapsed, formatElapsedWords, iconSwapStates, isProviderId, motion, motionData, motionRoot, openDropdown, parseRegistryConfig, prefersReducedMotion, readDurationMs, successCheckStates, swapText, triggerErrorShake, useChat, useComposer, useDropdownPresence, useMessages, useModel, useTheme, useThread };
|