@codespring-app/use-agent 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.
@@ -0,0 +1,212 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties, ReactNode, PropsWithChildren } from 'react';
3
+ import { a as AgentClient, f as AgentSession, S as SessionSnapshot, d as AgentEvent, k as SubmitOptions, l as SubmitTurnResponse, B as BrowserAgentClientOptions } from './client-Bz3eVQXx.js';
4
+ export { m as createBrowserClient } from './client-Bz3eVQXx.js';
5
+
6
+ interface AgentTheme {
7
+ canvas: string;
8
+ ink: string;
9
+ inkSecondary: string;
10
+ inkTertiary: string;
11
+ well: string;
12
+ hairline: string;
13
+ statusGood: string;
14
+ statusBad: string;
15
+ statusWarn: string;
16
+ accent: string;
17
+ fontFamily: string;
18
+ monoFamily: string;
19
+ contentMaxWidth: number | string;
20
+ containerRadius: number | string;
21
+ wellRadius: number | string;
22
+ }
23
+ /** Stable CSS custom-property names supported by every default component. */
24
+ declare const agentThemeVariables: Readonly<{
25
+ canvas: "--codespring-agent-canvas";
26
+ ink: "--codespring-agent-ink";
27
+ inkSecondary: "--codespring-agent-ink-secondary";
28
+ inkTertiary: "--codespring-agent-ink-tertiary";
29
+ well: "--codespring-agent-well";
30
+ hairline: "--codespring-agent-hairline";
31
+ statusGood: "--codespring-agent-status-good";
32
+ statusBad: "--codespring-agent-status-bad";
33
+ statusWarn: "--codespring-agent-status-warn";
34
+ accent: "--codespring-agent-accent";
35
+ fontFamily: "--codespring-agent-font-family";
36
+ monoFamily: "--codespring-agent-mono-family";
37
+ contentMaxWidth: "--codespring-agent-content-max-width";
38
+ containerRadius: "--codespring-agent-container-radius";
39
+ wellRadius: "--codespring-agent-well-radius";
40
+ }>;
41
+ interface AgentCopy {
42
+ title: string;
43
+ empty: string;
44
+ loading: string;
45
+ thinking: string;
46
+ placeholder: string;
47
+ send: string;
48
+ sending: string;
49
+ failed: string;
50
+ cancelled: string;
51
+ userLabel: string;
52
+ assistantLabel: string;
53
+ toolRunning: string;
54
+ toolCompleted: string;
55
+ toolFailed: string;
56
+ toolApprovalRequired: string;
57
+ }
58
+ declare const paperLightTheme: Readonly<AgentTheme>;
59
+ declare const paperDarkTheme: Readonly<AgentTheme>;
60
+ declare const defaultAgentCopy: Readonly<AgentCopy>;
61
+ interface AgentAppearance {
62
+ readonly theme: Readonly<AgentTheme>;
63
+ readonly copy: Readonly<AgentCopy>;
64
+ }
65
+ interface CreateAgentAppearanceOptions {
66
+ mode?: "light" | "dark";
67
+ theme?: Partial<AgentTheme>;
68
+ copy?: Partial<AgentCopy>;
69
+ }
70
+ declare function createAgentAppearance({ mode, theme, copy, }?: CreateAgentAppearanceOptions): AgentAppearance;
71
+ declare const paperAppearance: AgentAppearance;
72
+ declare const paperDarkAppearance: AgentAppearance;
73
+ interface AgentContextValue {
74
+ client: AgentClient;
75
+ theme: AgentTheme;
76
+ copy: AgentCopy;
77
+ stores: Map<string, SessionStore>;
78
+ }
79
+ interface AgentProviderProps extends PropsWithChildren {
80
+ client: AgentClient;
81
+ appearance?: AgentAppearance;
82
+ theme?: Partial<AgentTheme>;
83
+ copy?: Partial<AgentCopy>;
84
+ }
85
+ declare function AgentProvider({ client, appearance, theme, copy, children, }: AgentProviderProps): react.FunctionComponentElement<react.ProviderProps<AgentContextValue | null>>;
86
+ declare function useAgentClient(): AgentClient;
87
+ interface CreateAgentClientOptions {
88
+ endpoint: string;
89
+ clientTokenEndpoint: string;
90
+ fetch?: BrowserAgentClientOptions["fetch"];
91
+ credentials?: RequestCredentials;
92
+ clientTokenTtlMs?: number;
93
+ refreshSkewMs?: number;
94
+ }
95
+ /** Creates one stable browser client with an in-memory, deduplicated client-token cache. */
96
+ declare function createAgentClient({ endpoint, clientTokenEndpoint, fetch: fetchImplementation, credentials, clientTokenTtlMs, refreshSkewMs, }: CreateAgentClientOptions): AgentClient;
97
+ declare function useAgentTheme(): AgentTheme;
98
+ declare function useAgentCopy(): AgentCopy;
99
+ type AgentMessageStatus = "completed" | "streaming" | "failed" | "cancelled";
100
+ interface AgentChatMessage {
101
+ id: string;
102
+ turnId: string;
103
+ role: "user" | "assistant";
104
+ content: string;
105
+ status: AgentMessageStatus;
106
+ createdAt: string;
107
+ eventId: number;
108
+ }
109
+ type AgentToolCallStatus = "proposed" | "running" | "completed" | "failed" | "approval_required";
110
+ /** Pure reducer for consumers that want CodeSpring's durable event semantics with custom UI. */
111
+ declare function reduceAgentMessages(events: readonly AgentEvent[]): AgentChatMessage[];
112
+ /** Pure reducer for durable server, MCP, and client tool activity. */
113
+ declare function reduceAgentToolCalls(events: readonly AgentEvent[]): AgentToolCall[];
114
+ interface SessionState {
115
+ status: "idle" | "loading" | "ready" | "error";
116
+ snapshot: SessionSnapshot | null;
117
+ events: AgentEvent[];
118
+ messages: AgentChatMessage[];
119
+ toolCalls: AgentToolCall[];
120
+ error: Error | null;
121
+ }
122
+ declare class SessionStore {
123
+ readonly session: AgentSession;
124
+ private state;
125
+ private readonly listeners;
126
+ private controller;
127
+ private refreshTimer;
128
+ constructor(session: AgentSession);
129
+ subscribe: (listener: () => void) => () => void;
130
+ getSnapshot: () => SessionState;
131
+ getServerSnapshot: () => SessionState;
132
+ private setState;
133
+ private scheduleRefresh;
134
+ refresh(): Promise<void>;
135
+ dispose(): void;
136
+ }
137
+ interface AgentSessionResult extends SessionState {
138
+ session: AgentSession;
139
+ refresh: () => Promise<void>;
140
+ submit: (content: string, options?: SubmitOptions) => Promise<SubmitTurnResponse>;
141
+ cancel: (turnId: string) => Promise<void>;
142
+ }
143
+ declare function useAgentSession(sessionId: string): AgentSessionResult;
144
+ declare function useAgentMessages(sessionId: string): AgentChatMessage[];
145
+ declare function useAgentToolCalls(sessionId: string): AgentToolCall[];
146
+ interface StyledProps {
147
+ className?: string;
148
+ style?: CSSProperties;
149
+ }
150
+ interface AgentMessageProps extends StyledProps {
151
+ message: AgentChatMessage;
152
+ theme?: Partial<AgentTheme>;
153
+ copy?: Partial<AgentCopy>;
154
+ }
155
+ declare function AgentMessage({ message, className, style, theme, copy }: AgentMessageProps): react.JSX.Element;
156
+ interface AgentToolCallProps extends StyledProps {
157
+ toolCall: AgentToolCall;
158
+ theme?: Partial<AgentTheme>;
159
+ copy?: Partial<AgentCopy>;
160
+ }
161
+ interface AgentToolCall {
162
+ id: string;
163
+ turnId: string;
164
+ name: string;
165
+ label: string;
166
+ summary?: string;
167
+ status: AgentToolCallStatus;
168
+ input?: unknown;
169
+ output?: unknown;
170
+ createdAt: string;
171
+ eventId: number;
172
+ }
173
+ declare function AgentToolCall({ toolCall, className, style, theme, copy }: AgentToolCallProps): react.JSX.Element;
174
+ interface AgentMessageListProps extends StyledProps {
175
+ messages: readonly AgentChatMessage[];
176
+ toolCalls?: readonly AgentToolCall[];
177
+ isWorking?: boolean;
178
+ renderMessage?: (message: AgentChatMessage) => ReactNode;
179
+ renderToolCall?: (toolCall: AgentToolCall) => ReactNode;
180
+ theme?: Partial<AgentTheme>;
181
+ copy?: Partial<AgentCopy>;
182
+ }
183
+ declare function AgentMessageList({ messages, toolCalls, isWorking, renderMessage, renderToolCall, className, style, theme, copy, }: AgentMessageListProps): react.JSX.Element;
184
+ interface AgentComposerProps extends StyledProps {
185
+ value: string;
186
+ onChange: (value: string) => void;
187
+ onSubmit: () => void | Promise<void>;
188
+ disabled?: boolean;
189
+ error?: string | null;
190
+ leadingActions?: ReactNode;
191
+ trailingActions?: ReactNode;
192
+ onCancel?: () => void | Promise<void>;
193
+ theme?: Partial<AgentTheme>;
194
+ copy?: Partial<AgentCopy>;
195
+ }
196
+ declare function AgentComposer({ value, onChange, onSubmit, disabled, error, leadingActions, trailingActions, onCancel, className, style, theme, copy, }: AgentComposerProps): react.JSX.Element;
197
+ interface AgentChatProps extends StyledProps {
198
+ sessionId: string;
199
+ header?: ReactNode;
200
+ composerLeadingActions?: ReactNode;
201
+ composerTrailingActions?: ReactNode;
202
+ /** @deprecated Prefer the header slot; the default chat has no header. */
203
+ title?: string;
204
+ theme?: Partial<AgentTheme>;
205
+ copy?: Partial<AgentCopy>;
206
+ renderMessage?: (message: AgentChatMessage) => ReactNode;
207
+ renderToolCall?: (toolCall: AgentToolCall) => ReactNode;
208
+ onError?: (error: Error) => void;
209
+ }
210
+ declare function AgentChat({ sessionId, header, composerLeadingActions, composerTrailingActions, title, className, style, theme, copy, renderMessage, renderToolCall, onError, }: AgentChatProps): react.JSX.Element;
211
+
212
+ export { type AgentAppearance, AgentChat, type AgentChatMessage, type AgentChatProps, AgentComposer, type AgentComposerProps, type AgentCopy, AgentMessage, AgentMessageList, type AgentMessageListProps, type AgentMessageProps, type AgentMessageStatus, AgentProvider, type AgentProviderProps, type AgentSessionResult, type AgentTheme, AgentToolCall, type AgentToolCallProps, type AgentToolCallStatus, BrowserAgentClientOptions, type CreateAgentAppearanceOptions, type CreateAgentClientOptions, SessionSnapshot, agentThemeVariables, createAgentAppearance, createAgentClient, defaultAgentCopy, paperAppearance, paperDarkAppearance, paperDarkTheme, paperLightTheme, reduceAgentMessages, reduceAgentToolCalls, useAgentClient, useAgentCopy, useAgentMessages, useAgentSession, useAgentTheme, useAgentToolCalls };