@witqq/agent-sdk 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/{types-CqvUAYxt.d.ts → agent-C6H2CgJA.d.cts} +139 -102
  2. package/dist/{types-CqvUAYxt.d.cts → agent-F7oB6eKp.d.ts} +139 -102
  3. package/dist/auth/index.cjs +72 -1
  4. package/dist/auth/index.cjs.map +1 -1
  5. package/dist/auth/index.d.cts +21 -154
  6. package/dist/auth/index.d.ts +21 -154
  7. package/dist/auth/index.js +72 -1
  8. package/dist/auth/index.js.map +1 -1
  9. package/dist/backends/claude.cjs +480 -261
  10. package/dist/backends/claude.cjs.map +1 -1
  11. package/dist/backends/claude.d.cts +3 -1
  12. package/dist/backends/claude.d.ts +3 -1
  13. package/dist/backends/claude.js +480 -261
  14. package/dist/backends/claude.js.map +1 -1
  15. package/dist/backends/copilot.cjs +337 -112
  16. package/dist/backends/copilot.cjs.map +1 -1
  17. package/dist/backends/copilot.d.cts +12 -4
  18. package/dist/backends/copilot.d.ts +12 -4
  19. package/dist/backends/copilot.js +337 -112
  20. package/dist/backends/copilot.js.map +1 -1
  21. package/dist/backends/mock-llm.cjs +719 -0
  22. package/dist/backends/mock-llm.cjs.map +1 -0
  23. package/dist/backends/mock-llm.d.cts +37 -0
  24. package/dist/backends/mock-llm.d.ts +37 -0
  25. package/dist/backends/mock-llm.js +717 -0
  26. package/dist/backends/mock-llm.js.map +1 -0
  27. package/dist/backends/vercel-ai.cjs +301 -61
  28. package/dist/backends/vercel-ai.cjs.map +1 -1
  29. package/dist/backends/vercel-ai.d.cts +3 -1
  30. package/dist/backends/vercel-ai.d.ts +3 -1
  31. package/dist/backends/vercel-ai.js +301 -61
  32. package/dist/backends/vercel-ai.js.map +1 -1
  33. package/dist/backends-Cno0gZjy.d.cts +114 -0
  34. package/dist/backends-Cno0gZjy.d.ts +114 -0
  35. package/dist/chat/accumulator.cjs +1 -1
  36. package/dist/chat/accumulator.cjs.map +1 -1
  37. package/dist/chat/accumulator.d.cts +5 -2
  38. package/dist/chat/accumulator.d.ts +5 -2
  39. package/dist/chat/accumulator.js +1 -1
  40. package/dist/chat/accumulator.js.map +1 -1
  41. package/dist/chat/backends.cjs +1084 -821
  42. package/dist/chat/backends.cjs.map +1 -1
  43. package/dist/chat/backends.d.cts +10 -6
  44. package/dist/chat/backends.d.ts +10 -6
  45. package/dist/chat/backends.js +1082 -800
  46. package/dist/chat/backends.js.map +1 -1
  47. package/dist/chat/context.cjs +50 -0
  48. package/dist/chat/context.cjs.map +1 -1
  49. package/dist/chat/context.d.cts +27 -3
  50. package/dist/chat/context.d.ts +27 -3
  51. package/dist/chat/context.js +50 -0
  52. package/dist/chat/context.js.map +1 -1
  53. package/dist/chat/core.cjs +60 -27
  54. package/dist/chat/core.cjs.map +1 -1
  55. package/dist/chat/core.d.cts +41 -382
  56. package/dist/chat/core.d.ts +41 -382
  57. package/dist/chat/core.js +58 -28
  58. package/dist/chat/core.js.map +1 -1
  59. package/dist/chat/errors.cjs +48 -26
  60. package/dist/chat/errors.cjs.map +1 -1
  61. package/dist/chat/errors.d.cts +6 -31
  62. package/dist/chat/errors.d.ts +6 -31
  63. package/dist/chat/errors.js +48 -25
  64. package/dist/chat/errors.js.map +1 -1
  65. package/dist/chat/events.cjs.map +1 -1
  66. package/dist/chat/events.d.cts +6 -2
  67. package/dist/chat/events.d.ts +6 -2
  68. package/dist/chat/events.js.map +1 -1
  69. package/dist/chat/index.cjs +1612 -1125
  70. package/dist/chat/index.cjs.map +1 -1
  71. package/dist/chat/index.d.cts +35 -10
  72. package/dist/chat/index.d.ts +35 -10
  73. package/dist/chat/index.js +1600 -1097
  74. package/dist/chat/index.js.map +1 -1
  75. package/dist/chat/react/theme.css +2517 -0
  76. package/dist/chat/react.cjs +2212 -1158
  77. package/dist/chat/react.cjs.map +1 -1
  78. package/dist/chat/react.d.cts +665 -122
  79. package/dist/chat/react.d.ts +665 -122
  80. package/dist/chat/react.js +2191 -1156
  81. package/dist/chat/react.js.map +1 -1
  82. package/dist/chat/runtime.cjs +405 -186
  83. package/dist/chat/runtime.cjs.map +1 -1
  84. package/dist/chat/runtime.d.cts +92 -28
  85. package/dist/chat/runtime.d.ts +92 -28
  86. package/dist/chat/runtime.js +405 -186
  87. package/dist/chat/runtime.js.map +1 -1
  88. package/dist/chat/server.cjs +2247 -212
  89. package/dist/chat/server.cjs.map +1 -1
  90. package/dist/chat/server.d.cts +451 -90
  91. package/dist/chat/server.d.ts +451 -90
  92. package/dist/chat/server.js +2234 -213
  93. package/dist/chat/server.js.map +1 -1
  94. package/dist/chat/sessions.cjs +64 -66
  95. package/dist/chat/sessions.cjs.map +1 -1
  96. package/dist/chat/sessions.d.cts +37 -118
  97. package/dist/chat/sessions.d.ts +37 -118
  98. package/dist/chat/sessions.js +65 -67
  99. package/dist/chat/sessions.js.map +1 -1
  100. package/dist/chat/sqlite.cjs +536 -0
  101. package/dist/chat/sqlite.cjs.map +1 -0
  102. package/dist/chat/sqlite.d.cts +164 -0
  103. package/dist/chat/sqlite.d.ts +164 -0
  104. package/dist/chat/sqlite.js +527 -0
  105. package/dist/chat/sqlite.js.map +1 -0
  106. package/dist/chat/state.cjs +14 -1
  107. package/dist/chat/state.cjs.map +1 -1
  108. package/dist/chat/state.d.cts +5 -2
  109. package/dist/chat/state.d.ts +5 -2
  110. package/dist/chat/state.js +14 -1
  111. package/dist/chat/state.js.map +1 -1
  112. package/dist/chat/storage.cjs +58 -33
  113. package/dist/chat/storage.cjs.map +1 -1
  114. package/dist/chat/storage.d.cts +18 -8
  115. package/dist/chat/storage.d.ts +18 -8
  116. package/dist/chat/storage.js +59 -34
  117. package/dist/chat/storage.js.map +1 -1
  118. package/dist/errors-C-so0M4t.d.cts +33 -0
  119. package/dist/errors-C-so0M4t.d.ts +33 -0
  120. package/dist/errors-CmVvczxZ.d.cts +28 -0
  121. package/dist/errors-CmVvczxZ.d.ts +28 -0
  122. package/dist/{in-process-transport-C2oPTYs6.d.ts → in-process-transport-7EIit9Xk.d.ts} +72 -33
  123. package/dist/{in-process-transport-DG-w5G6k.d.cts → in-process-transport-Ct9YcX8I.d.cts} +72 -33
  124. package/dist/index.cjs +354 -60
  125. package/dist/index.cjs.map +1 -1
  126. package/dist/index.d.cts +294 -123
  127. package/dist/index.d.ts +294 -123
  128. package/dist/index.js +347 -60
  129. package/dist/index.js.map +1 -1
  130. package/dist/provider-types-PTSlRPNB.d.cts +39 -0
  131. package/dist/provider-types-PTSlRPNB.d.ts +39 -0
  132. package/dist/refresh-manager-B81PpYBr.d.cts +153 -0
  133. package/dist/refresh-manager-Dlv_iNZi.d.ts +153 -0
  134. package/dist/testing.cjs +1107 -0
  135. package/dist/testing.cjs.map +1 -0
  136. package/dist/testing.d.cts +144 -0
  137. package/dist/testing.d.ts +144 -0
  138. package/dist/testing.js +1101 -0
  139. package/dist/testing.js.map +1 -0
  140. package/dist/token-store-CSUBgYwn.d.ts +48 -0
  141. package/dist/token-store-CuC4hB9Z.d.cts +48 -0
  142. package/dist/{transport-DX1Nhm4N.d.cts → transport-DLWCN18G.d.cts} +5 -4
  143. package/dist/{transport-D1OaUgRk.d.ts → transport-DsuS-GeM.d.ts} +5 -4
  144. package/dist/{types-CGF7AEX1.d.cts → types-4vbcmPTp.d.cts} +4 -2
  145. package/dist/{types-Bh5AhqD-.d.ts → types-BxggH0Yh.d.ts} +4 -2
  146. package/dist/types-DgtI1hzh.d.ts +364 -0
  147. package/dist/types-DkSXALKg.d.cts +364 -0
  148. package/package.json +41 -5
  149. package/LICENSE +0 -21
  150. package/README.md +0 -948
  151. package/dist/errors-BDLbNu9w.d.cts +0 -13
  152. package/dist/errors-BDLbNu9w.d.ts +0 -13
  153. package/dist/types-DLZzlJxt.d.ts +0 -39
  154. package/dist/types-tE0CXwBl.d.cts +0 -39
@@ -1,34 +1,35 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { IChatRuntime } from './runtime.js';
4
- import { ChatMessage, RuntimeStatus, SessionInfo, TextPart, ReasoningPart, ToolCallPart, SourcePart, FilePart, ChatSession, ChatEvent, ChatId, ChatIdLike, SendMessageOptions, ChatMiddleware } from './core.js';
5
- import { A as AuthToken } from '../types-Bh5AhqD-.js';
6
- import { d as ModelInfo$1, T as ToolDefinition } from '../types-CqvUAYxt.js';
7
- import { CreateSessionOptions, SessionListOptions } from './sessions.js';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { IChatClient, BackendInfo, SelectionChangeCallback } from './runtime.js';
4
+ import { c as ChatMessage, R as RuntimeStatus, r as SessionInfo, u as TextPart, q as ReasoningPart, v as ToolCallPart, t as SourcePart, F as FilePart, g as ChatSession, a as ChatEvent, b as ChatId, f as ChatIdLike, S as SendMessageOptions } from '../types-DgtI1hzh.js';
5
+ import { A as AuthToken } from '../types-BxggH0Yh.js';
6
+ import { P as ProviderConfig } from '../provider-types-PTSlRPNB.js';
8
7
  import { ContextStats } from './context.js';
9
- import '../types-DLZzlJxt.js';
10
- import '../errors-BDLbNu9w.js';
8
+ import { M as ModelInfo } from '../agent-F7oB6eKp.js';
9
+ import { CreateSessionOptions, SessionListOptions } from './sessions.js';
10
+ import '../errors-C-so0M4t.js';
11
11
  import 'zod';
12
12
  import './storage.js';
13
+ import '../errors-CmVvczxZ.js';
13
14
 
14
15
  /** Props for ChatProvider. */
15
16
  interface ChatProviderProps {
16
- /** The chat runtime instance to provide to descendants. */
17
- runtime: IChatRuntime;
17
+ /** The chat runtime or client instance to provide to descendants. Accepts IChatClient (or any structurally compatible type). */
18
+ runtime: IChatClient;
18
19
  children: ReactNode;
19
20
  }
20
21
  /**
21
- * React context provider wrapping IChatRuntime.
22
+ * React context provider wrapping IChatClient.
22
23
  * All chat hooks must be used within a ChatProvider.
23
24
  */
24
- declare function ChatProvider({ runtime, children }: ChatProviderProps): react.FunctionComponentElement<react.ProviderProps<IChatRuntime<Record<string, unknown>> | null>>;
25
+ declare function ChatProvider({ runtime, children }: ChatProviderProps): react.FunctionComponentElement<react.ProviderProps<IChatClient<Record<string, unknown>> | null>>;
25
26
  /**
26
- * Access the IChatRuntime from context.
27
+ * Access the IChatClient from context.
27
28
  * Must be used within a ChatProvider.
28
29
  *
29
30
  * @throws {Error} If used outside ChatProvider
30
31
  */
31
- declare function useChatRuntime(): IChatRuntime;
32
+ declare function useChatRuntime(): IChatClient;
32
33
 
33
34
  /** Options for the useChat hook. */
34
35
  interface UseChatOptions {
@@ -36,6 +37,15 @@ interface UseChatOptions {
36
37
  sessionId?: string;
37
38
  /** Called on error during send. */
38
39
  onError?: (error: Error) => void;
40
+ /** Auto-dismiss errors after this many ms (0 = disabled, default: 0). */
41
+ autoDismissMs?: number;
42
+ }
43
+ /** Token usage data from the last completed response. */
44
+ interface ChatUsage {
45
+ promptTokens: number;
46
+ completionTokens: number;
47
+ totalTokens: number;
48
+ model?: string;
39
49
  }
40
50
  /** Return value from useChat. */
41
51
  interface UseChatReturn {
@@ -55,8 +65,12 @@ interface UseChatReturn {
55
65
  error: Error | null;
56
66
  /** Clear the error state. */
57
67
  clearError: () => void;
68
+ /** Retry the last failed message. No-op if no error or no last user message. */
69
+ retryLastMessage: () => Promise<void>;
58
70
  /** Create a new session, resetting messages. */
59
71
  newSession: () => Promise<string>;
72
+ /** Token usage from the last completed response. */
73
+ usage: ChatUsage | null;
60
74
  }
61
75
  /**
62
76
  * Convenience hook for chat interaction.
@@ -107,7 +121,7 @@ interface UseSessionsReturn {
107
121
  /**
108
122
  * Reactive session list hook.
109
123
  * Subscribes to `runtime.onSessionChange()` and refreshes the list automatically
110
- * on create, delete, archive, and message send completion.
124
+ * on create, delete, and message send completion.
111
125
  */
112
126
  declare function useSessions(): UseSessionsReturn;
113
127
 
@@ -148,7 +162,7 @@ interface ToolCallViewProps {
148
162
  }
149
163
  /**
150
164
  * Headless tool call display component.
151
- * Shows tool name, status, args, result, and approval buttons when needed.
165
+ * Shows tool name, status, collapsible args/result, and approval buttons when needed.
152
166
  */
153
167
  declare function ToolCallView({ part, onApprove, onDeny, renderArgs, renderResult }: ToolCallViewProps): ReactNode;
154
168
 
@@ -192,18 +206,67 @@ interface MarkdownRendererProps {
192
206
  */
193
207
  declare function MarkdownRenderer(props: MarkdownRendererProps): ReactNode;
194
208
 
209
+ /** Configuration for message list virtualization. */
210
+ interface VirtualizeOptions {
211
+ /** Estimated height of each message item in pixels (default: 80). */
212
+ estimatedItemHeight?: number;
213
+ /** Number of extra items to render above and below the visible area (default: 3). */
214
+ overscan?: number;
215
+ }
216
+ /** Result of the useVirtualMessages hook. */
217
+ interface VirtualMessagesResult<T> {
218
+ /** Slice of items to actually render. */
219
+ visibleItems: T[];
220
+ /** Start index in the original array. */
221
+ startIndex: number;
222
+ /** End index (exclusive) in the original array. */
223
+ endIndex: number;
224
+ /** Height of the spacer above rendered items (px). */
225
+ topSpacerHeight: number;
226
+ /** Height of the spacer below rendered items (px). */
227
+ bottomSpacerHeight: number;
228
+ /** Total estimated height of all items (px). */
229
+ totalHeight: number;
230
+ /** Scroll event handler to attach to the container. */
231
+ onScroll: (event: {
232
+ currentTarget: {
233
+ scrollTop: number;
234
+ clientHeight: number;
235
+ };
236
+ }) => void;
237
+ /** Ref callback to measure container on mount. */
238
+ containerRef: (el: HTMLElement | null) => void;
239
+ }
240
+ /**
241
+ * Hook providing windowed rendering for a list of items.
242
+ *
243
+ * Only items within the visible viewport (plus overscan) are returned.
244
+ * Consumers render top/bottom spacer divs to preserve scroll position.
245
+ *
246
+ * @param items - Full array of items
247
+ * @param options - Virtualization config
248
+ */
249
+ declare function useVirtualMessages<T>(items: readonly T[], options?: VirtualizeOptions): VirtualMessagesResult<T>;
250
+
195
251
  /** Props for the Thread component. */
196
252
  interface ThreadProps {
197
253
  messages: ChatMessage[];
198
254
  isGenerating?: boolean;
199
255
  autoScroll?: boolean;
200
256
  className?: string;
257
+ /**
258
+ * Enable windowed rendering for large message lists.
259
+ * Pass `true` for defaults or an options object.
260
+ * When enabled, only visible messages (plus overscan) are mounted.
261
+ */
262
+ virtualize?: boolean | VirtualizeOptions;
201
263
  }
202
264
  /**
203
265
  * Headless thread component wrapping a scrollable message list.
204
266
  * Auto-scrolls to bottom when new messages arrive unless user has scrolled up.
267
+ * Shows a scroll-to-bottom button when scrolled up and an empty state when no messages.
205
268
  */
206
- declare function Thread({ messages, isGenerating, autoScroll, className, }: ThreadProps): ReactNode;
269
+ declare function Thread({ messages, isGenerating, autoScroll, className, virtualize, }: ThreadProps): ReactNode;
207
270
 
208
271
  /** Props for the Composer component. */
209
272
  interface ComposerProps {
@@ -270,6 +333,10 @@ declare function ThreadList({ sessions, activeSessionId, onSelect, onCreate, onD
270
333
  type SSEStatus = "idle" | "connecting" | "open" | "closed" | "error";
271
334
  /** Options for the useSSE hook. */
272
335
  interface UseSSEOptions {
336
+ /** HTTP method (default: "GET") */
337
+ method?: "GET" | "POST";
338
+ /** Request body for POST requests (JSON-serialized automatically) */
339
+ body?: unknown;
273
340
  headers?: Record<string, string>;
274
341
  onEvent?: (event: ChatEvent) => void;
275
342
  onError?: (error: Error) => void;
@@ -294,9 +361,9 @@ interface ModelOption {
294
361
  id: string;
295
362
  name: string;
296
363
  tier?: string;
364
+ /** Provider/backend name for multi-provider context. */
365
+ provider?: string;
297
366
  }
298
- /** @deprecated Use ModelOption instead — renamed to avoid collision with core ModelInfo */
299
- type ModelInfo = ModelOption;
300
367
  /** Return type for the useModels hook. */
301
368
  interface UseModelsReturn {
302
369
  models: ModelOption[];
@@ -317,55 +384,14 @@ interface ModelSelectorProps {
317
384
  onSelect: (modelId: string) => void;
318
385
  placeholder?: string;
319
386
  className?: string;
387
+ /** Allow free-text model input when models list is empty. Default: true. */
388
+ allowFreeText?: boolean;
320
389
  }
321
390
  /**
322
391
  * Dropdown model selector with search and keyboard navigation.
392
+ * Falls back to a free-text input when models list is empty.
323
393
  */
324
- declare function ModelSelector({ models, selectedModel, onSelect, placeholder, className, }: ModelSelectorProps): ReactNode;
325
-
326
- /** Supported auth backends. */
327
- type AuthBackend = "copilot" | "claude" | "api-key";
328
- /** Auth status state machine: idle → pending → authenticated | error. */
329
- type AuthStatus = "idle" | "pending" | "authenticated" | "error";
330
- /** Options for the useAuth hook. */
331
- interface UseAuthOptions {
332
- backend: AuthBackend;
333
- onAuthenticated?: (token: AuthToken) => void;
334
- }
335
- /** Return value from useAuth. */
336
- interface UseAuthReturn {
337
- status: AuthStatus;
338
- error: Error | null;
339
- startDeviceFlow: () => Promise<void>;
340
- deviceCode: string | null;
341
- verificationUrl: string | null;
342
- startOAuthFlow: () => Promise<void>;
343
- authorizeUrl: string | null;
344
- completeOAuth: (codeOrUrl: string) => Promise<void>;
345
- submitApiKey: (key: string) => void;
346
- token: AuthToken | null;
347
- reset: () => void;
348
- }
349
- /**
350
- * Hook for multi-backend authentication.
351
- *
352
- * Wraps CopilotAuth (Device Flow), ClaudeAuth (OAuth+PKCE),
353
- * and plain API key validation into a unified React state machine.
354
- *
355
- * @deprecated Use `useRemoteAuth` instead for browser contexts.
356
- * `useAuth` directly instantiates auth classes which require `node:crypto`
357
- * (via ClaudeAuth). The `useRemoteAuth` hook delegates authentication to
358
- * server endpoints (createAuthHandler), avoiding browser crypto dependencies.
359
- *
360
- * Migration: replace `useAuth({ backend })` with
361
- * `useRemoteAuth({ backend, baseUrl: "/api/auth" })`.
362
- * Note: the `"api-key"` backend is renamed to `"vercel-ai"` in useRemoteAuth,
363
- * and `submitApiKey` is now async (returns Promise<void>).
364
- * The return interface is otherwise compatible — `startDeviceFlow`, `startOAuthFlow`,
365
- * `completeOAuth`, `submitApiKey`, `token`, `status`, `error`, `reset`
366
- * all work the same way.
367
- */
368
- declare function useAuth(options: UseAuthOptions): UseAuthReturn;
394
+ declare function ModelSelector({ models, selectedModel, onSelect, placeholder, className, allowFreeText, }: ModelSelectorProps): ReactNode;
369
395
 
370
396
  /**
371
397
  * @witqq/agent-sdk/chat/react — useRemoteAuth
@@ -440,8 +466,8 @@ declare function useRemoteAuth(options: UseRemoteAuthOptions): UseRemoteAuthRetu
440
466
  * Lifecycle hook that orchestrates auth → runtime → session.
441
467
  *
442
468
  * On mount, checks for saved auth tokens and auto-restores.
443
- * Once authenticated, creates a RemoteChatRuntime and initial session.
444
- * Exposes readiness phase, the runtime instance, and the auth sub-hook.
469
+ * Once authenticated, creates a RemoteChatClient and initial session.
470
+ * Exposes readiness phase, the client instance, and the auth sub-hook.
445
471
  */
446
472
 
447
473
  /** Lifecycle phase for the useRemoteChat hook. */
@@ -460,15 +486,13 @@ interface UseRemoteChatOptions {
460
486
  fetch?: typeof globalThis.fetch;
461
487
  /** Optional headers for all requests. */
462
488
  headers?: Record<string, string>;
463
- /** Auto-restore saved tokens on mount (default: true). */
464
- autoRestore?: boolean;
465
489
  }
466
490
  /** Return value from useRemoteChat. */
467
491
  interface UseRemoteChatReturn {
468
492
  /** Current lifecycle phase. */
469
493
  phase: RemoteChatPhase;
470
- /** Chat runtime (null until phase = "ready"). */
471
- runtime: IChatRuntime | null;
494
+ /** Chat client (null until phase = "ready"). */
495
+ runtime: IChatClient | null;
472
496
  /** Initial session ID (null until phase = "ready"). */
473
497
  sessionId: string | null;
474
498
  /** Auth sub-hook for manual auth control. */
@@ -501,39 +525,441 @@ interface UseRemoteChatReturn {
501
525
  */
502
526
  declare function useRemoteChat(options: UseRemoteChatOptions): UseRemoteChatReturn;
503
527
 
504
- /** Props for the AuthDialog component. */
505
- interface AuthDialogProps {
506
- backends: AuthBackend[];
507
- selectedBackend?: AuthBackend;
508
- onBackendChange?: (backend: AuthBackend) => void;
509
- onAuthenticated?: (token: AuthToken) => void;
510
- renderCopilotFlow?: (state: {
511
- deviceCode: string;
512
- verificationUrl: string;
513
- status: AuthStatus;
514
- }) => ReactNode;
515
- renderClaudeFlow?: (state: {
516
- authorizeUrl: string | null;
517
- status: AuthStatus;
518
- completeOAuth: (code: string) => Promise<void>;
519
- }) => ReactNode;
520
- renderApiKeyFlow?: (state: {
521
- submitApiKey: (key: string) => void;
522
- status: AuthStatus;
523
- }) => ReactNode;
528
+ /**
529
+ * Props passed to per-backend auth form components.
530
+ * Each backend implements its own form using these props.
531
+ */
532
+ interface AuthFormProps {
533
+ /** The remote auth hook instance, pre-configured for this backend. */
534
+ auth: UseRemoteAuthReturn;
535
+ /** Called when authentication completes successfully. */
536
+ onAuthComplete: () => void;
537
+ }
538
+ /** A backend auth form component. */
539
+ type AuthFormComponent = (props: AuthFormProps) => ReactNode;
540
+
541
+ /**
542
+ * Copilot (GitHub) auth form — device flow.
543
+ *
544
+ * Shows "Authenticate with GitHub" button → device code + verification URL →
545
+ * "Waiting..." "✓ Authenticated" + "Continue →".
546
+ *
547
+ * Co-located with the Copilot backend.
548
+ */
549
+ declare function CopilotAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
550
+
551
+ /**
552
+ * Claude auth form — OAuth Authorization Code + PKCE.
553
+ *
554
+ * Shows "Authenticate with Claude" button → authorize URL link +
555
+ * paste-code input + "Submit" button.
556
+ *
557
+ * Co-located with the Claude backend.
558
+ */
559
+ declare function ClaudeAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
560
+
561
+ /**
562
+ * Vercel AI auth form — API key + optional base URL.
563
+ *
564
+ * Shows base URL input + API key input + "Connect" button.
565
+ *
566
+ * Co-located with the Vercel AI backend.
567
+ */
568
+ declare function VercelAIAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
569
+
570
+ /** Props for the BackendSelector component. */
571
+ interface BackendSelectorProps {
572
+ backends: BackendInfo[];
573
+ onSelect: (name: string) => void;
574
+ className?: string;
575
+ }
576
+ /**
577
+ * Headless backend selector showing registered backends with active indicator.
578
+ * Uses data attributes for styling:
579
+ * - `[data-backend-selector]` on root
580
+ * - `[data-backend-item]` on each item
581
+ * - `[data-backend-active="true"]` on the active backend
582
+ * - `[data-backend-name]` with backend name value
583
+ */
584
+ declare function BackendSelector({ backends, onSelect, className, }: BackendSelectorProps): ReactNode;
585
+
586
+ /** Return type for the useBackends hook. */
587
+ interface UseBackendsReturn {
588
+ backends: BackendInfo[];
589
+ isLoading: boolean;
590
+ error: Error | null;
591
+ refresh: () => void;
592
+ }
593
+ /**
594
+ * Hook for discovering registered backends and switching between them.
595
+ */
596
+ declare function useBackends(): UseBackendsReturn;
597
+
598
+ /** Return type for the useProviders hook. */
599
+ interface UseProvidersReturn {
600
+ providers: ProviderConfig[];
601
+ isLoading: boolean;
602
+ error: Error | null;
603
+ refresh: () => void;
604
+ createProvider: (config: Omit<ProviderConfig, "id" | "createdAt">) => Promise<void>;
605
+ updateProvider: (id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>) => Promise<void>;
606
+ deleteProvider: (id: string) => Promise<void>;
607
+ selectProvider: (id: string) => void;
608
+ }
609
+ /**
610
+ * Hook for managing providers (backend + model combos).
611
+ * Requires an IChatClient with provider methods (e.g. RemoteChatClient).
612
+ */
613
+ declare function useProviders(): UseProvidersReturn;
614
+
615
+ /** Props for the ProviderSelector component. */
616
+ interface ProviderSelectorProps {
617
+ providers: ProviderConfig[];
618
+ activeProviderId?: string;
619
+ onSelect: (id: string) => void;
620
+ onSettingsClick?: () => void;
621
+ className?: string;
622
+ }
623
+ /**
624
+ * Headless dropdown for selecting a configured provider.
625
+ * Uses data attributes for styling hooks. Follows ModelSelector pattern.
626
+ */
627
+ declare function ProviderSelector({ providers, activeProviderId, onSelect, onSettingsClick, className, }: ProviderSelectorProps): ReactNode;
628
+
629
+ /** A unified item rendered in the ProviderModelSelector dropdown. */
630
+ interface ProviderModelItem {
631
+ id: string;
632
+ label: string;
633
+ sublabel?: string;
634
+ tier?: string;
635
+ type: "provider" | "model";
636
+ }
637
+ /** Props for the ProviderModelSelector component. */
638
+ interface ProviderModelSelectorProps {
639
+ /** Configured providers (backend + model combos). When non-empty, provider mode is used. */
640
+ providers?: ProviderConfig[];
641
+ /** Available models. Used when providers is empty or undefined. */
642
+ models?: ModelOption[];
643
+ /** Currently selected provider ID. */
644
+ activeProviderId?: string;
645
+ /** Currently selected model ID (fallback mode). */
646
+ selectedModel?: string;
647
+ /** Called when a provider is selected. */
648
+ onSelectProvider?: (id: string) => void;
649
+ /** Called when a model is selected (fallback mode). */
650
+ onSelectModel?: (modelId: string) => void;
651
+ /** Called when settings gear is clicked. */
652
+ onSettingsClick?: () => void;
653
+ /** Placeholder text for the trigger button. */
654
+ placeholder?: string;
655
+ className?: string;
656
+ }
657
+ /**
658
+ * Unified selector that shows providers when available, falls back to model list.
659
+ * Replaces the need for separate ProviderSelector + ModelSelector in ChatUI.
660
+ */
661
+ declare function ProviderModelSelector({ providers, models, activeProviderId, selectedModel, onSelectProvider, onSelectModel, onSettingsClick, placeholder, className, }: ProviderModelSelectorProps): ReactNode;
662
+
663
+ /** Props for the ProviderSettings component. */
664
+ interface ProviderSettingsProps {
665
+ providers: ProviderConfig[];
666
+ onClose?: () => void;
667
+ onProviderCreated?: (p: ProviderConfig) => void;
668
+ onProviderDeleted?: (id: string) => void;
669
+ onProviderUpdated?: (id: string, changes: {
670
+ model?: string;
671
+ label?: string;
672
+ }) => void;
673
+ /** Called when authentication succeeds (before configure step). Parent should refresh providers. */
674
+ onAuthCompleted?: (backend: string) => void;
675
+ authBaseUrl?: string;
676
+ className?: string;
677
+ }
678
+ /**
679
+ * Headless settings panel for managing providers.
680
+ * States: list (all providers), add (new provider flow), edit (existing).
681
+ */
682
+ declare function ProviderSettings({ providers, onClose, onProviderCreated, onProviderDeleted, onProviderUpdated, onAuthCompleted, authBaseUrl, className, }: ProviderSettingsProps): ReactNode;
683
+
684
+ /** Props for the ContextStatsDisplay component. */
685
+ interface ContextStatsDisplayProps {
686
+ /** Context stats from runtime.getContextStats(sessionId). Null = nothing to display. */
687
+ stats: ContextStats | null;
688
+ /** CSS class on the root element. */
689
+ className?: string;
690
+ }
691
+ /**
692
+ * Headless component displaying context window statistics.
693
+ *
694
+ * When real usage data is available (realPromptTokens + modelContextWindow),
695
+ * displays actual token usage and model context window size.
696
+ * When real data is not yet available (before first API response), returns null.
697
+ *
698
+ * All elements use `data-*` attributes for CSS styling — no inline styles.
699
+ */
700
+ declare function ContextStatsDisplay({ stats, className }: ContextStatsDisplayProps): ReactNode;
701
+
702
+ /**
703
+ * @witqq/agent-sdk/chat/react — ChatUI
704
+ *
705
+ * Composite component that wires Thread, Composer, ThreadList, ModelSelector,
706
+ * and ProviderSettings into a complete chat interface. Consumers get a full AI chat
707
+ * in ~3 lines:
708
+ *
709
+ * import { ChatUI } from "@witqq/agent-sdk/chat/react";
710
+ * <ChatUI runtime={myRuntime} />
711
+ *
712
+ * Slot system: replace any sub-component while keeping all others as defaults.
713
+ *
714
+ * Built from composable sub-components: ChatLayout, ChatHeader, ChatInputArea,
715
+ * ChatSettingsOverlay — each usable independently for custom layouts.
716
+ */
717
+
718
+ /** Slot overrides for ChatUI sub-components. */
719
+ interface ChatUISlots {
720
+ /** Replace the Thread component. */
721
+ thread?: ComponentType<ThreadProps>;
722
+ /** Replace the Composer component. */
723
+ composer?: ComponentType<ComposerProps>;
724
+ /** Replace the ThreadList (sidebar) component. */
725
+ threadList?: ComponentType<ThreadListProps>;
726
+ /** Replace the ModelSelector component (used in header when no providers). */
727
+ modelSelector?: ComponentType<ModelSelectorProps>;
728
+ /** Replace the BackendSelector component. */
729
+ backendSelector?: ComponentType<BackendSelectorProps>;
730
+ /** Replace the ProviderSelector component (legacy, use providerModelSelector). */
731
+ providerSelector?: ComponentType<ProviderSelectorProps>;
732
+ /** Replace the unified ProviderModelSelector component (near composer). */
733
+ providerModelSelector?: ComponentType<ProviderModelSelectorProps>;
734
+ /** Replace the ProviderSettings component. */
735
+ providerSettings?: ComponentType<ProviderSettingsProps>;
736
+ /** Replace the ContextStatsDisplay component. */
737
+ contextStats?: ComponentType<ContextStatsDisplayProps>;
738
+ /** Custom auth dialog element rendered when provided. */
739
+ authDialog?: ReactNode;
740
+ /** Custom message renderer (forwarded to ThreadProvider). */
741
+ renderMessage?: (message: ChatMessage, index: number) => ReactNode;
742
+ /** Custom tool call renderer (forwarded to ThreadProvider). */
743
+ renderToolCall?: (part: ToolCallPart, index: number) => ReactNode;
744
+ /** Custom thinking block renderer (forwarded to ThreadProvider). */
745
+ renderThinkingBlock?: (part: ReasoningPart, index: number) => ReactNode;
746
+ }
747
+ /** Props for the ChatUI composite component. */
748
+ interface ChatUIProps {
749
+ /** The chat runtime or client instance. ChatUI wraps it in ChatProvider. Accepts IChatClient. */
750
+ runtime: IChatClient;
751
+ /** Slot overrides for sub-components. */
752
+ slots?: ChatUISlots;
753
+ /** CSS class on the root element. */
754
+ className?: string;
755
+ /** Show the session sidebar. Default: true. */
756
+ showSidebar?: boolean;
757
+ /** Show the model selector header. Default: true. */
758
+ showModelSelector?: boolean;
759
+ /** Show the backend selector in header. Default: false. */
760
+ showBackendSelector?: boolean;
761
+ /** Show the provider selector near composer. Default: auto (true when providers available). */
762
+ showProviderSelector?: boolean;
763
+ /** Base URL for auth API (needed by ProviderSettings). */
764
+ authBaseUrl?: string;
765
+ /** Placeholder text for the Composer textarea. */
766
+ placeholder?: string;
767
+ }
768
+ /**
769
+ * Composite chat component — complete AI chat interface in one import.
770
+ *
771
+ * ```tsx
772
+ * import { ChatUI } from "@witqq/agent-sdk/chat/react";
773
+ *
774
+ * function App() {
775
+ * return <ChatUI runtime={myRuntime} />;
776
+ * }
777
+ * ```
778
+ */
779
+ declare function ChatUI({ runtime, ...rest }: ChatUIProps): ReactNode;
780
+
781
+ /**
782
+ * @witqq/agent-sdk/chat/react — ChatLayout
783
+ *
784
+ * Pure layout container for chat interfaces. Renders sidebar + main area
785
+ * without any logic or state. ChatUI uses this internally.
786
+ */
787
+
788
+ /** Props for the ChatLayout component. */
789
+ interface ChatLayoutProps {
790
+ /** Main chat content (thread, input area, etc.). */
791
+ children: ReactNode;
792
+ /** Sidebar content (thread list, session list, etc.). */
793
+ sidebar?: ReactNode;
794
+ /** Modal/overlay content. Accepts a single node or array of nodes. */
795
+ overlay?: ReactNode | ReactNode[];
796
+ /** CSS class on the root element. */
524
797
  className?: string;
525
798
  }
526
799
  /**
527
- * Multi-backend auth dialog component.
800
+ * Pure layout container — flex row with optional sidebar and overlay.
801
+ *
802
+ * Renders `[data-chat-ui]` root with:
803
+ * - overlay (rendered first for z-index stacking)
804
+ * - sidebar (rendered before main content)
805
+ * - children (main chat area)
806
+ */
807
+ declare function ChatLayout({ children, sidebar, overlay, className }: ChatLayoutProps): ReactNode;
808
+
809
+ /**
810
+ * @witqq/agent-sdk/chat/react — ChatHeader
528
811
  *
529
- * Headless component that renders backend selector buttons and
530
- * per-backend auth flows. Uses data attributes for styling hooks.
531
- * Supports custom render props for each flow type.
812
+ * Selector composition for the chat header area. Renders backend selector,
813
+ * model selector, or nothing based on configuration.
532
814
  */
533
- declare function AuthDialog({ backends, selectedBackend: controlledBackend, onBackendChange, onAuthenticated, renderCopilotFlow, renderClaudeFlow, renderApiKeyFlow, className, }: AuthDialogProps): ReactNode;
534
815
 
816
+ /** Props for the ChatHeader component. */
817
+ interface ChatHeaderProps {
818
+ /** Whether to show backend selector. Default: false. */
819
+ showBackendSelector?: boolean;
820
+ /** Whether to show model selector. Default: true. */
821
+ showModelSelector?: boolean;
822
+ /** Whether providers are configured (hides model selector when true). */
823
+ hasProviders?: boolean;
824
+ /** Available backends list. */
825
+ backends?: BackendInfo[];
826
+ /** Available models list. */
827
+ models?: ModelOption[];
828
+ /** Currently selected model. */
829
+ selectedModel?: string;
830
+ /** Backend selection handler. */
831
+ onBackendSelect?: (name: string) => void;
832
+ /** Model selection handler. */
833
+ onModelSelect?: (modelId: string) => void;
834
+ /** Slot override for BackendSelector. */
835
+ BackendSelectorComponent?: ComponentType<BackendSelectorProps>;
836
+ /** Slot override for ModelSelector. */
837
+ ModelSelectorComponent?: ComponentType<ModelSelectorProps>;
838
+ }
839
+ /**
840
+ * Header area with backend and model selectors.
841
+ * Returns null when no selectors need to be shown.
842
+ */
843
+ declare function ChatHeader({ showBackendSelector, showModelSelector, hasProviders, backends, models, selectedModel, onBackendSelect, onModelSelect, BackendSelectorComponent: BSC, ModelSelectorComponent: MSC, }: ChatHeaderProps): ReactNode;
844
+
845
+ /**
846
+ * @witqq/agent-sdk/chat/react — ChatInputArea
847
+ *
848
+ * Input area combining the unified provider/model selector with the composer.
849
+ */
850
+
851
+ /** Props for the ChatInputArea component. */
852
+ interface ChatInputAreaProps {
853
+ /** Send message handler. */
854
+ onSend: (message: string) => void;
855
+ /** Stop generation handler. */
856
+ onStop?: () => void;
857
+ /** Whether generation is in progress. */
858
+ isGenerating?: boolean;
859
+ /** Placeholder text for the textarea. */
860
+ placeholder?: string;
861
+ /** Available providers. */
862
+ providers?: ProviderConfig[];
863
+ /** Available models. */
864
+ models?: ModelOption[];
865
+ /** Active provider ID. */
866
+ activeProviderId?: string;
867
+ /** Selected model. */
868
+ selectedModel?: string;
869
+ /** Provider selection handler. */
870
+ onSelectProvider?: (id: string) => void;
871
+ /** Model selection handler. */
872
+ onSelectModel?: (modelId: string) => void;
873
+ /** Settings button handler. */
874
+ onSettingsClick?: () => void;
875
+ /** Slot override for Composer. */
876
+ ComposerComponent?: ComponentType<ComposerProps>;
877
+ /** Slot override for ProviderModelSelector. */
878
+ ProviderModelSelectorComponent?: ComponentType<ProviderModelSelectorProps>;
879
+ /** Token usage data to display. */
880
+ usage?: ChatUsage | null;
881
+ }
535
882
  /**
536
- * Client-side runtime adapter that implements IChatRuntime by delegating
883
+ * Input area unified selector + composer in a `[data-chat-input-area]` container.
884
+ */
885
+ declare function ChatInputArea({ onSend, onStop, isGenerating, placeholder, providers, models, activeProviderId, selectedModel, onSelectProvider, onSelectModel, onSettingsClick, ComposerComponent: CC, ProviderModelSelectorComponent: PMSC, usage, }: ChatInputAreaProps): ReactNode;
886
+
887
+ /**
888
+ * @witqq/agent-sdk/chat/react — ChatSettingsOverlay
889
+ *
890
+ * Modal overlay for provider settings management.
891
+ * Features: backdrop click-to-close, ESC key handler, focus trap.
892
+ */
893
+
894
+ /** Props for the ChatSettingsOverlay component. */
895
+ interface ChatSettingsOverlayProps {
896
+ /** Whether the overlay is visible. */
897
+ open: boolean;
898
+ /** Close handler. */
899
+ onClose: () => void;
900
+ /** Available providers. */
901
+ providers?: ProviderConfig[];
902
+ /** Auth API base URL. */
903
+ authBaseUrl?: string;
904
+ /** Provider created handler. */
905
+ onProviderCreated?: (provider: {
906
+ backend: string;
907
+ model: string;
908
+ label?: string;
909
+ }) => void;
910
+ /** Provider deleted handler. */
911
+ onProviderDeleted?: (id: string) => void;
912
+ /** Provider updated handler. */
913
+ onProviderUpdated?: (id: string, changes: Partial<ProviderConfig>) => void;
914
+ /** Called when authentication succeeds. Parent should refresh providers. */
915
+ onAuthCompleted?: (backend: string) => void;
916
+ /** Slot override for ProviderSettings. */
917
+ ProviderSettingsComponent?: ComponentType<ProviderSettingsProps>;
918
+ }
919
+ /**
920
+ * Settings modal — renders `[data-provider-settings-overlay]` when open.
921
+ * Returns null when closed.
922
+ * Backdrop click and Escape key close the overlay with exit animation.
923
+ * Focus is trapped within the overlay content.
924
+ */
925
+ declare function ChatSettingsOverlay({ open, onClose, providers, authBaseUrl, onProviderCreated, onProviderDeleted, onProviderUpdated, onAuthCompleted, ProviderSettingsComponent: PSC, }: ChatSettingsOverlayProps): ReactNode;
926
+
927
+ /** Props for the UsageBadge component. */
928
+ interface UsageBadgeProps {
929
+ usage: ChatUsage | null;
930
+ className?: string;
931
+ }
932
+ /** Compact token usage display. Shows prompt/completion/total tokens. */
933
+ declare function UsageBadge({ usage, className }: UsageBadgeProps): ReactNode;
934
+
935
+ /** Props for PermissionDialog. */
936
+ interface PermissionDialogProps {
937
+ /** List of pending tool requests awaiting approval. */
938
+ requests: PendingToolRequest[];
939
+ /** Called when user approves a tool call. */
940
+ onApprove: (toolCallId: string) => void;
941
+ /** Called when user denies a tool call. */
942
+ onDeny: (toolCallId: string) => void;
943
+ /** Optional: approve all pending at once. */
944
+ onApproveAll?: () => void;
945
+ /** Optional: deny all pending at once. */
946
+ onDenyAll?: () => void;
947
+ /** Custom renderer for tool arguments. */
948
+ renderArgs?: (args: Record<string, unknown>, toolName: string) => ReactNode;
949
+ className?: string;
950
+ }
951
+ /**
952
+ * Headless permission dialog component for tool approval flows.
953
+ *
954
+ * Renders a list of pending tool calls with approve/deny buttons.
955
+ * Uses `data-*` attributes for styling — no built-in styles.
956
+ *
957
+ * Returns `null` when there are no pending requests.
958
+ */
959
+ declare function PermissionDialog({ requests, onApprove, onDeny, onApproveAll, onDenyAll, renderArgs, className, }: PermissionDialogProps): ReactNode;
960
+
961
+ /**
962
+ * Client-side adapter that implements IChatClient by delegating
537
963
  * operations over HTTP/SSE to a remote server.
538
964
  *
539
965
  * Bridges the gap between SDK React hooks (which require an in-process runtime)
@@ -541,30 +967,35 @@ declare function AuthDialog({ backends, selectedBackend: controlledBackend, onBa
541
967
  *
542
968
  * @example
543
969
  * ```ts
544
- * import { RemoteChatRuntime } from "@witqq/agent-sdk/chat/react";
970
+ * import { RemoteChatClient } from "@witqq/agent-sdk/chat/react";
545
971
  * import { ChatProvider } from "@witqq/agent-sdk/chat/react";
546
972
  *
547
- * const runtime = new RemoteChatRuntime({ baseUrl: "/api" });
548
- * <ChatProvider runtime={runtime}> ... </ChatProvider>
973
+ * const client = new RemoteChatClient({ baseUrl: "/api" });
974
+ * <ChatProvider runtime={client}> ... </ChatProvider>
549
975
  * ```
550
976
  */
551
977
 
552
978
  /**
553
979
  * Standard server endpoint contract.
554
- * Server implementations expose these routes to work with RemoteChatRuntime.
980
+ * Server implementations expose these routes to work with RemoteChatClient.
555
981
  *
556
982
  * POST {baseUrl}/sessions/create — Create session
557
983
  * GET {baseUrl}/sessions/{id} — Get session
558
984
  * GET {baseUrl}/sessions — List sessions
559
985
  * DELETE {baseUrl}/sessions/{id} — Delete session
560
- * POST {baseUrl}/sessions/{id}/archiveArchive session
986
+ * GET {baseUrl}/sessions/{id}/context-statsGet context window stats
561
987
  * POST {baseUrl}/send — Send message (SSE stream response)
562
988
  * POST {baseUrl}/abort — Abort current stream
563
989
  * GET {baseUrl}/models — List models
564
- * POST {baseUrl}/backend/switch Switch backend
990
+ * GET {baseUrl}/backends List backends
565
991
  * POST {baseUrl}/model/switch — Switch model
992
+ * POST {baseUrl}/provider/switch — Switch provider (backend + model)
993
+ * GET {baseUrl}/providers — List providers
994
+ * POST {baseUrl}/providers — Create provider
995
+ * PUT {baseUrl}/providers/{id} — Update provider
996
+ * DELETE {baseUrl}/providers/{id} — Delete provider
566
997
  */
567
- interface RemoteChatRuntimeOptions {
998
+ interface RemoteChatClientOptions {
568
999
  /** Base URL for API endpoints (e.g. "/api" or "https://example.com/api") */
569
1000
  baseUrl: string;
570
1001
  /** Optional headers for all requests (e.g. auth tokens) */
@@ -572,48 +1003,160 @@ interface RemoteChatRuntimeOptions {
572
1003
  /** Custom fetch implementation for testability */
573
1004
  fetch?: typeof globalThis.fetch;
574
1005
  }
575
- declare class RemoteChatRuntime implements IChatRuntime {
1006
+ declare class RemoteChatClient implements IChatClient {
576
1007
  private _status;
577
1008
  private _activeSessionId;
578
- private _currentBackend;
579
- private _currentModel;
1009
+ private _selectedProviderId;
580
1010
  private _abortController;
581
- private readonly _tools;
582
- private readonly _middlewares;
583
1011
  private readonly baseUrl;
584
1012
  private readonly headers;
585
1013
  private readonly _fetch;
586
- constructor(options: RemoteChatRuntimeOptions);
1014
+ private readonly _selectionListeners;
1015
+ constructor(options: RemoteChatClientOptions);
587
1016
  get status(): RuntimeStatus;
588
1017
  dispose(): Promise<void>;
589
1018
  private assertNotDisposed;
1019
+ get selectedProviderId(): string | null;
1020
+ selectProvider(providerId: string): void;
1021
+ onSelectionChange(callback: SelectionChangeCallback): () => void;
1022
+ private _notifySelectionChange;
590
1023
  get activeSessionId(): ChatId | null;
591
1024
  createSession(options: CreateSessionOptions): Promise<ChatSession>;
592
1025
  getSession(id: ChatIdLike): Promise<ChatSession | null>;
593
1026
  listSessions(_options?: SessionListOptions): Promise<ChatSession[]>;
594
1027
  deleteSession(id: ChatIdLike): Promise<void>;
595
- archiveSession(id: ChatIdLike): Promise<void>;
1028
+ /**
1029
+ * Fetch context window stats from server.
1030
+ * Returns null if stats not available (e.g. no messages sent yet).
1031
+ */
1032
+ getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
596
1033
  switchSession(id: ChatIdLike): Promise<ChatSession>;
597
1034
  send(sessionId: ChatIdLike, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
598
1035
  abort(): void;
599
- get currentBackend(): string;
600
- get currentModel(): string | undefined;
601
- switchBackend(name: string): Promise<void>;
602
- switchModel(model: string): void;
603
- listModels(): Promise<ModelInfo$1[]>;
604
- get registeredTools(): ReadonlyMap<string, ToolDefinition>;
605
- registerTool(tool: ToolDefinition): void;
606
- removeTool(name: string): void;
607
- use(middleware: ChatMiddleware): void;
608
- removeMiddleware(middleware: ChatMiddleware): void;
609
- getContextStats(_sessionId: ChatIdLike): ContextStats | null;
1036
+ listModels(): Promise<ModelInfo[]>;
1037
+ listBackends(): Promise<BackendInfo[]>;
1038
+ listProviders(): Promise<ProviderConfig[]>;
1039
+ createProvider(config: Omit<ProviderConfig, "id" | "createdAt">): Promise<ProviderConfig>;
1040
+ updateProvider(id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>): Promise<void>;
1041
+ deleteProvider(id: string): Promise<void>;
610
1042
  private readonly _sessionListeners;
611
1043
  onSessionChange(callback: () => void): () => void;
612
1044
  private _notifySessionChange;
613
1045
  private _get;
614
1046
  private _post;
615
1047
  private _delete;
1048
+ private _put;
616
1049
  private _parseSSEStream;
617
1050
  }
618
1051
 
619
- export { type AuthBackend, AuthDialog, type AuthDialogProps, type AuthStatus, ChatProvider, Composer, type ComposerProps, MarkdownRenderer, type MarkdownRendererProps, Message, type MessageProps, type ModelInfo, type ModelOption, ModelSelector, type ModelSelectorProps, type PendingToolRequest, type RemoteAuthBackend, type RemoteAuthStatus, type RemoteChatPhase, RemoteChatRuntime, type RemoteChatRuntimeOptions, type SSEStatus, ThinkingBlock, type ThinkingBlockProps, Thread, ThreadList, type ThreadListProps, type ThreadProps, ThreadProvider, type ThreadProviderProps, type ThreadSlotOverrides, ToolCallView, type ToolCallViewProps, type UseAuthOptions, type UseAuthReturn, type UseChatOptions, type UseChatReturn, type UseMessagesOptions, type UseMessagesReturn, type UseModelsReturn, type UseRemoteAuthOptions, type UseRemoteAuthReturn, type UseRemoteChatOptions, type UseRemoteChatReturn, type UseSSEOptions, type UseSSEReturn, type UseSessionsReturn, type UseToolApprovalReturn, useAuth, useChat, useChatRuntime, useMessages, useModels, useOptionalThreadSlots, useRemoteAuth, useRemoteChat, useSSE, useSessions, useThreadSlots, useToolApproval };
1052
+ /**
1053
+ * @witqq/agent-sdk/chat/react — useCopilotAuth
1054
+ *
1055
+ * Server-delegated Copilot Device Flow authentication hook.
1056
+ * Independently usable — does not require useRemoteAuth orchestrator.
1057
+ */
1058
+
1059
+ /** Options for useCopilotAuth. */
1060
+ interface UseCopilotAuthOptions {
1061
+ /** Base URL of the auth server (e.g. "/api/auth") */
1062
+ baseUrl: string;
1063
+ /** Called after successful authentication */
1064
+ onAuthenticated?: (token: AuthToken) => void;
1065
+ /** Called on authentication error */
1066
+ onError?: (error: Error) => void;
1067
+ /** Optional fetch override (for testing) */
1068
+ fetch?: typeof globalThis.fetch;
1069
+ /** Optional headers for all requests */
1070
+ headers?: Record<string, string>;
1071
+ }
1072
+ /** Return value from useCopilotAuth. */
1073
+ interface UseCopilotAuthReturn {
1074
+ status: "idle" | "pending" | "authenticated" | "error";
1075
+ error: Error | null;
1076
+ token: AuthToken | null;
1077
+ deviceCode: string | null;
1078
+ verificationUrl: string | null;
1079
+ /** Start the device flow. Shows deviceCode and verificationUrl, then polls for completion. */
1080
+ start: () => Promise<void>;
1081
+ reset: () => void;
1082
+ }
1083
+ /**
1084
+ * Copilot Device Flow authentication.
1085
+ * Starts device flow on server, provides code/URL for user, polls until complete.
1086
+ */
1087
+ declare function useCopilotAuth(options: UseCopilotAuthOptions): UseCopilotAuthReturn;
1088
+
1089
+ /**
1090
+ * @witqq/agent-sdk/chat/react — useClaudeAuth
1091
+ *
1092
+ * Server-delegated Claude OAuth + PKCE authentication hook.
1093
+ * Independently usable — does not require useRemoteAuth orchestrator.
1094
+ */
1095
+
1096
+ /** Options for useClaudeAuth. */
1097
+ interface UseClaudeAuthOptions {
1098
+ /** Base URL of the auth server (e.g. "/api/auth") */
1099
+ baseUrl: string;
1100
+ /** Called after successful authentication */
1101
+ onAuthenticated?: (token: AuthToken) => void;
1102
+ /** Called on authentication error */
1103
+ onError?: (error: Error) => void;
1104
+ /** Optional fetch override (for testing) */
1105
+ fetch?: typeof globalThis.fetch;
1106
+ /** Optional headers for all requests */
1107
+ headers?: Record<string, string>;
1108
+ }
1109
+ /** Return value from useClaudeAuth. */
1110
+ interface UseClaudeAuthReturn {
1111
+ status: "idle" | "pending" | "authenticated" | "error";
1112
+ error: Error | null;
1113
+ token: AuthToken | null;
1114
+ authorizeUrl: string | null;
1115
+ /** Start OAuth flow. Sets authorizeUrl for user redirect. */
1116
+ start: () => Promise<void>;
1117
+ /** Complete OAuth after redirect. Pass the code or callback URL. */
1118
+ complete: (codeOrUrl: string) => Promise<void>;
1119
+ reset: () => void;
1120
+ }
1121
+ /**
1122
+ * Claude OAuth + PKCE authentication.
1123
+ * Two-step flow: start() gets authorizeUrl → user redirects → complete(code) finishes.
1124
+ */
1125
+ declare function useClaudeAuth(options: UseClaudeAuthOptions): UseClaudeAuthReturn;
1126
+
1127
+ /**
1128
+ * @witqq/agent-sdk/chat/react — useApiKeyAuth
1129
+ *
1130
+ * Server-delegated API key authentication hook (for Vercel AI / OpenRouter / etc.).
1131
+ * Independently usable — does not require useRemoteAuth orchestrator.
1132
+ */
1133
+
1134
+ /** Options for useApiKeyAuth. */
1135
+ interface UseApiKeyAuthOptions {
1136
+ /** Base URL of the auth server (e.g. "/api/auth") */
1137
+ baseUrl: string;
1138
+ /** Called after successful authentication */
1139
+ onAuthenticated?: (token: AuthToken) => void;
1140
+ /** Called on authentication error */
1141
+ onError?: (error: Error) => void;
1142
+ /** Optional fetch override (for testing) */
1143
+ fetch?: typeof globalThis.fetch;
1144
+ /** Optional headers for all requests */
1145
+ headers?: Record<string, string>;
1146
+ }
1147
+ /** Return value from useApiKeyAuth. */
1148
+ interface UseApiKeyAuthReturn {
1149
+ status: "idle" | "pending" | "authenticated" | "error";
1150
+ error: Error | null;
1151
+ token: AuthToken | null;
1152
+ /** Submit an API key (and optional provider base URL). */
1153
+ submit: (key: string, apiBaseUrl?: string) => Promise<void>;
1154
+ reset: () => void;
1155
+ }
1156
+ /**
1157
+ * API key authentication.
1158
+ * Sends key to server for validation and storage.
1159
+ */
1160
+ declare function useApiKeyAuth(options: UseApiKeyAuthOptions): UseApiKeyAuthReturn;
1161
+
1162
+ export { type AuthFormComponent, type AuthFormProps, BackendSelector, type BackendSelectorProps, ChatHeader, type ChatHeaderProps, ChatInputArea, type ChatInputAreaProps, ChatLayout, type ChatLayoutProps, ChatProvider, ChatSettingsOverlay, type ChatSettingsOverlayProps, ChatUI, type ChatUIProps, type ChatUISlots, type ChatUsage, ClaudeAuthForm, Composer, type ComposerProps, ContextStatsDisplay, type ContextStatsDisplayProps, CopilotAuthForm, MarkdownRenderer, type MarkdownRendererProps, Message, type MessageProps, type ModelOption, ModelSelector, type ModelSelectorProps, type PendingToolRequest, PermissionDialog, type PermissionDialogProps, type ProviderModelItem, ProviderModelSelector, type ProviderModelSelectorProps, ProviderSelector, type ProviderSelectorProps, ProviderSettings, type ProviderSettingsProps, type RemoteAuthBackend, type RemoteAuthStatus, RemoteChatClient, type RemoteChatClientOptions, type RemoteChatPhase, type SSEStatus, ThinkingBlock, type ThinkingBlockProps, Thread, ThreadList, type ThreadListProps, type ThreadProps, ThreadProvider, type ThreadProviderProps, type ThreadSlotOverrides, ToolCallView, type ToolCallViewProps, UsageBadge, type UsageBadgeProps, type UseApiKeyAuthOptions, type UseApiKeyAuthReturn, type UseBackendsReturn, type UseChatOptions, type UseChatReturn, type UseClaudeAuthOptions, type UseClaudeAuthReturn, type UseCopilotAuthOptions, type UseCopilotAuthReturn, type UseMessagesOptions, type UseMessagesReturn, type UseModelsReturn, type UseProvidersReturn, type UseRemoteAuthOptions, type UseRemoteAuthReturn, type UseRemoteChatOptions, type UseRemoteChatReturn, type UseSSEOptions, type UseSSEReturn, type UseSessionsReturn, type UseToolApprovalReturn, VercelAIAuthForm, type VirtualMessagesResult, type VirtualizeOptions, useApiKeyAuth, useBackends, useChat, useChatRuntime, useClaudeAuth, useCopilotAuth, useMessages, useModels, useOptionalThreadSlots, useProviders, useRemoteAuth, useRemoteChat, useSSE, useSessions, useThreadSlots, useToolApproval, useVirtualMessages };