@witqq/agent-sdk 0.7.0 → 0.8.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 (147) hide show
  1. package/README.md +140 -34
  2. package/dist/{types-CqvUAYxt.d.cts → agent-CW9XbmG_.d.ts} +137 -102
  3. package/dist/{types-CqvUAYxt.d.ts → agent-DxY68NZL.d.cts} +137 -102
  4. package/dist/auth/index.cjs +72 -1
  5. package/dist/auth/index.cjs.map +1 -1
  6. package/dist/auth/index.d.cts +21 -154
  7. package/dist/auth/index.d.ts +21 -154
  8. package/dist/auth/index.js +72 -1
  9. package/dist/auth/index.js.map +1 -1
  10. package/dist/backends/claude.cjs +480 -261
  11. package/dist/backends/claude.cjs.map +1 -1
  12. package/dist/backends/claude.d.cts +3 -1
  13. package/dist/backends/claude.d.ts +3 -1
  14. package/dist/backends/claude.js +480 -261
  15. package/dist/backends/claude.js.map +1 -1
  16. package/dist/backends/copilot.cjs +329 -97
  17. package/dist/backends/copilot.cjs.map +1 -1
  18. package/dist/backends/copilot.d.cts +12 -4
  19. package/dist/backends/copilot.d.ts +12 -4
  20. package/dist/backends/copilot.js +329 -97
  21. package/dist/backends/copilot.js.map +1 -1
  22. package/dist/backends/vercel-ai.cjs +294 -61
  23. package/dist/backends/vercel-ai.cjs.map +1 -1
  24. package/dist/backends/vercel-ai.d.cts +3 -1
  25. package/dist/backends/vercel-ai.d.ts +3 -1
  26. package/dist/backends/vercel-ai.js +294 -61
  27. package/dist/backends/vercel-ai.js.map +1 -1
  28. package/dist/backends-BSrsBYFn.d.cts +39 -0
  29. package/dist/backends-BSrsBYFn.d.ts +39 -0
  30. package/dist/chat/accumulator.cjs +1 -1
  31. package/dist/chat/accumulator.cjs.map +1 -1
  32. package/dist/chat/accumulator.d.cts +5 -2
  33. package/dist/chat/accumulator.d.ts +5 -2
  34. package/dist/chat/accumulator.js +1 -1
  35. package/dist/chat/accumulator.js.map +1 -1
  36. package/dist/chat/backends.cjs +736 -746
  37. package/dist/chat/backends.cjs.map +1 -1
  38. package/dist/chat/backends.d.cts +10 -6
  39. package/dist/chat/backends.d.ts +10 -6
  40. package/dist/chat/backends.js +736 -725
  41. package/dist/chat/backends.js.map +1 -1
  42. package/dist/chat/context.cjs +50 -0
  43. package/dist/chat/context.cjs.map +1 -1
  44. package/dist/chat/context.d.cts +27 -3
  45. package/dist/chat/context.d.ts +27 -3
  46. package/dist/chat/context.js +50 -0
  47. package/dist/chat/context.js.map +1 -1
  48. package/dist/chat/core.cjs +25 -2
  49. package/dist/chat/core.cjs.map +1 -1
  50. package/dist/chat/core.d.cts +30 -381
  51. package/dist/chat/core.d.ts +30 -381
  52. package/dist/chat/core.js +24 -3
  53. package/dist/chat/core.js.map +1 -1
  54. package/dist/chat/errors.cjs +48 -26
  55. package/dist/chat/errors.cjs.map +1 -1
  56. package/dist/chat/errors.d.cts +6 -31
  57. package/dist/chat/errors.d.ts +6 -31
  58. package/dist/chat/errors.js +48 -25
  59. package/dist/chat/errors.js.map +1 -1
  60. package/dist/chat/events.cjs.map +1 -1
  61. package/dist/chat/events.d.cts +6 -2
  62. package/dist/chat/events.d.ts +6 -2
  63. package/dist/chat/events.js.map +1 -1
  64. package/dist/chat/index.cjs +1199 -1008
  65. package/dist/chat/index.cjs.map +1 -1
  66. package/dist/chat/index.d.cts +35 -10
  67. package/dist/chat/index.d.ts +35 -10
  68. package/dist/chat/index.js +1196 -987
  69. package/dist/chat/index.js.map +1 -1
  70. package/dist/chat/react/theme.css +2517 -0
  71. package/dist/chat/react.cjs +2003 -1153
  72. package/dist/chat/react.cjs.map +1 -1
  73. package/dist/chat/react.d.cts +590 -121
  74. package/dist/chat/react.d.ts +590 -121
  75. package/dist/chat/react.js +1984 -1151
  76. package/dist/chat/react.js.map +1 -1
  77. package/dist/chat/runtime.cjs +401 -186
  78. package/dist/chat/runtime.cjs.map +1 -1
  79. package/dist/chat/runtime.d.cts +92 -28
  80. package/dist/chat/runtime.d.ts +92 -28
  81. package/dist/chat/runtime.js +401 -186
  82. package/dist/chat/runtime.js.map +1 -1
  83. package/dist/chat/server.cjs +2234 -209
  84. package/dist/chat/server.cjs.map +1 -1
  85. package/dist/chat/server.d.cts +451 -90
  86. package/dist/chat/server.d.ts +451 -90
  87. package/dist/chat/server.js +2221 -210
  88. package/dist/chat/server.js.map +1 -1
  89. package/dist/chat/sessions.cjs +25 -43
  90. package/dist/chat/sessions.cjs.map +1 -1
  91. package/dist/chat/sessions.d.cts +37 -118
  92. package/dist/chat/sessions.d.ts +37 -118
  93. package/dist/chat/sessions.js +25 -43
  94. package/dist/chat/sessions.js.map +1 -1
  95. package/dist/chat/sqlite.cjs +441 -0
  96. package/dist/chat/sqlite.cjs.map +1 -0
  97. package/dist/chat/sqlite.d.cts +128 -0
  98. package/dist/chat/sqlite.d.ts +128 -0
  99. package/dist/chat/sqlite.js +435 -0
  100. package/dist/chat/sqlite.js.map +1 -0
  101. package/dist/chat/state.cjs +14 -1
  102. package/dist/chat/state.cjs.map +1 -1
  103. package/dist/chat/state.d.cts +5 -2
  104. package/dist/chat/state.d.ts +5 -2
  105. package/dist/chat/state.js +14 -1
  106. package/dist/chat/state.js.map +1 -1
  107. package/dist/chat/storage.cjs +19 -10
  108. package/dist/chat/storage.cjs.map +1 -1
  109. package/dist/chat/storage.d.cts +11 -5
  110. package/dist/chat/storage.d.ts +11 -5
  111. package/dist/chat/storage.js +19 -10
  112. package/dist/chat/storage.js.map +1 -1
  113. package/dist/errors-C-so0M4t.d.cts +33 -0
  114. package/dist/errors-C-so0M4t.d.ts +33 -0
  115. package/dist/errors-CmVvczxZ.d.cts +28 -0
  116. package/dist/errors-CmVvczxZ.d.ts +28 -0
  117. package/dist/{in-process-transport-C2oPTYs6.d.ts → in-process-transport-C1JnJGVR.d.ts} +28 -23
  118. package/dist/{in-process-transport-DG-w5G6k.d.cts → in-process-transport-C7DSqPyX.d.cts} +28 -23
  119. package/dist/index.cjs +340 -46
  120. package/dist/index.cjs.map +1 -1
  121. package/dist/index.d.cts +292 -123
  122. package/dist/index.d.ts +292 -123
  123. package/dist/index.js +334 -47
  124. package/dist/index.js.map +1 -1
  125. package/dist/provider-types-PTSlRPNB.d.cts +39 -0
  126. package/dist/provider-types-PTSlRPNB.d.ts +39 -0
  127. package/dist/refresh-manager-B81PpYBr.d.cts +153 -0
  128. package/dist/refresh-manager-Dlv_iNZi.d.ts +153 -0
  129. package/dist/testing.cjs +383 -0
  130. package/dist/testing.cjs.map +1 -0
  131. package/dist/testing.d.cts +132 -0
  132. package/dist/testing.d.ts +132 -0
  133. package/dist/testing.js +377 -0
  134. package/dist/testing.js.map +1 -0
  135. package/dist/token-store-CSUBgYwn.d.ts +48 -0
  136. package/dist/token-store-CuC4hB9Z.d.cts +48 -0
  137. package/dist/{transport-DX1Nhm4N.d.cts → transport-Cdh3M0tS.d.cts} +5 -4
  138. package/dist/{transport-D1OaUgRk.d.ts → transport-Ciap4PWK.d.ts} +5 -4
  139. package/dist/{types-CGF7AEX1.d.cts → types-4vbcmPTp.d.cts} +4 -2
  140. package/dist/{types-Bh5AhqD-.d.ts → types-BxggH0Yh.d.ts} +4 -2
  141. package/dist/types-DRgd_9R7.d.cts +363 -0
  142. package/dist/types-ajANVzf7.d.ts +363 -0
  143. package/package.json +31 -6
  144. package/dist/errors-BDLbNu9w.d.cts +0 -13
  145. package/dist/errors-BDLbNu9w.d.ts +0 -13
  146. package/dist/types-DLZzlJxt.d.ts +0 -39
  147. 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-ajANVzf7.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-CW9XbmG_.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
 
@@ -202,6 +216,7 @@ interface ThreadProps {
202
216
  /**
203
217
  * Headless thread component wrapping a scrollable message list.
204
218
  * Auto-scrolls to bottom when new messages arrive unless user has scrolled up.
219
+ * Shows a scroll-to-bottom button when scrolled up and an empty state when no messages.
205
220
  */
206
221
  declare function Thread({ messages, isGenerating, autoScroll, className, }: ThreadProps): ReactNode;
207
222
 
@@ -270,6 +285,10 @@ declare function ThreadList({ sessions, activeSessionId, onSelect, onCreate, onD
270
285
  type SSEStatus = "idle" | "connecting" | "open" | "closed" | "error";
271
286
  /** Options for the useSSE hook. */
272
287
  interface UseSSEOptions {
288
+ /** HTTP method (default: "GET") */
289
+ method?: "GET" | "POST";
290
+ /** Request body for POST requests (JSON-serialized automatically) */
291
+ body?: unknown;
273
292
  headers?: Record<string, string>;
274
293
  onEvent?: (event: ChatEvent) => void;
275
294
  onError?: (error: Error) => void;
@@ -294,9 +313,9 @@ interface ModelOption {
294
313
  id: string;
295
314
  name: string;
296
315
  tier?: string;
316
+ /** Provider/backend name for multi-provider context. */
317
+ provider?: string;
297
318
  }
298
- /** @deprecated Use ModelOption instead — renamed to avoid collision with core ModelInfo */
299
- type ModelInfo = ModelOption;
300
319
  /** Return type for the useModels hook. */
301
320
  interface UseModelsReturn {
302
321
  models: ModelOption[];
@@ -317,55 +336,14 @@ interface ModelSelectorProps {
317
336
  onSelect: (modelId: string) => void;
318
337
  placeholder?: string;
319
338
  className?: string;
339
+ /** Allow free-text model input when models list is empty. Default: true. */
340
+ allowFreeText?: boolean;
320
341
  }
321
342
  /**
322
343
  * Dropdown model selector with search and keyboard navigation.
344
+ * Falls back to a free-text input when models list is empty.
323
345
  */
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;
346
+ declare function ModelSelector({ models, selectedModel, onSelect, placeholder, className, allowFreeText, }: ModelSelectorProps): ReactNode;
369
347
 
370
348
  /**
371
349
  * @witqq/agent-sdk/chat/react — useRemoteAuth
@@ -440,8 +418,8 @@ declare function useRemoteAuth(options: UseRemoteAuthOptions): UseRemoteAuthRetu
440
418
  * Lifecycle hook that orchestrates auth → runtime → session.
441
419
  *
442
420
  * 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.
421
+ * Once authenticated, creates a RemoteChatClient and initial session.
422
+ * Exposes readiness phase, the client instance, and the auth sub-hook.
445
423
  */
446
424
 
447
425
  /** Lifecycle phase for the useRemoteChat hook. */
@@ -460,15 +438,13 @@ interface UseRemoteChatOptions {
460
438
  fetch?: typeof globalThis.fetch;
461
439
  /** Optional headers for all requests. */
462
440
  headers?: Record<string, string>;
463
- /** Auto-restore saved tokens on mount (default: true). */
464
- autoRestore?: boolean;
465
441
  }
466
442
  /** Return value from useRemoteChat. */
467
443
  interface UseRemoteChatReturn {
468
444
  /** Current lifecycle phase. */
469
445
  phase: RemoteChatPhase;
470
- /** Chat runtime (null until phase = "ready"). */
471
- runtime: IChatRuntime | null;
446
+ /** Chat client (null until phase = "ready"). */
447
+ runtime: IChatClient | null;
472
448
  /** Initial session ID (null until phase = "ready"). */
473
449
  sessionId: string | null;
474
450
  /** Auth sub-hook for manual auth control. */
@@ -501,39 +477,415 @@ interface UseRemoteChatReturn {
501
477
  */
502
478
  declare function useRemoteChat(options: UseRemoteChatOptions): UseRemoteChatReturn;
503
479
 
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;
480
+ /**
481
+ * Props passed to per-backend auth form components.
482
+ * Each backend implements its own form using these props.
483
+ */
484
+ interface AuthFormProps {
485
+ /** The remote auth hook instance, pre-configured for this backend. */
486
+ auth: UseRemoteAuthReturn;
487
+ /** Called when authentication completes successfully. */
488
+ onAuthComplete: () => void;
489
+ }
490
+ /** A backend auth form component. */
491
+ type AuthFormComponent = (props: AuthFormProps) => ReactNode;
492
+
493
+ /**
494
+ * Copilot (GitHub) auth form — device flow.
495
+ *
496
+ * Shows "Authenticate with GitHub" button → device code + verification URL →
497
+ * "Waiting..." "✓ Authenticated" + "Continue →".
498
+ *
499
+ * Co-located with the Copilot backend.
500
+ */
501
+ declare function CopilotAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
502
+
503
+ /**
504
+ * Claude auth form — OAuth Authorization Code + PKCE.
505
+ *
506
+ * Shows "Authenticate with Claude" button → authorize URL link +
507
+ * paste-code input + "Submit" button.
508
+ *
509
+ * Co-located with the Claude backend.
510
+ */
511
+ declare function ClaudeAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
512
+
513
+ /**
514
+ * Vercel AI auth form — API key + optional base URL.
515
+ *
516
+ * Shows base URL input + API key input + "Connect" button.
517
+ *
518
+ * Co-located with the Vercel AI backend.
519
+ */
520
+ declare function VercelAIAuthForm({ auth, onAuthComplete }: AuthFormProps): ReactNode;
521
+
522
+ /** Props for the BackendSelector component. */
523
+ interface BackendSelectorProps {
524
+ backends: BackendInfo[];
525
+ onSelect: (name: string) => void;
526
+ className?: string;
527
+ }
528
+ /**
529
+ * Headless backend selector showing registered backends with active indicator.
530
+ * Uses data attributes for styling:
531
+ * - `[data-backend-selector]` on root
532
+ * - `[data-backend-item]` on each item
533
+ * - `[data-backend-active="true"]` on the active backend
534
+ * - `[data-backend-name]` with backend name value
535
+ */
536
+ declare function BackendSelector({ backends, onSelect, className, }: BackendSelectorProps): ReactNode;
537
+
538
+ /** Return type for the useBackends hook. */
539
+ interface UseBackendsReturn {
540
+ backends: BackendInfo[];
541
+ isLoading: boolean;
542
+ error: Error | null;
543
+ refresh: () => void;
544
+ }
545
+ /**
546
+ * Hook for discovering registered backends and switching between them.
547
+ */
548
+ declare function useBackends(): UseBackendsReturn;
549
+
550
+ /** Return type for the useProviders hook. */
551
+ interface UseProvidersReturn {
552
+ providers: ProviderConfig[];
553
+ isLoading: boolean;
554
+ error: Error | null;
555
+ refresh: () => void;
556
+ createProvider: (config: Omit<ProviderConfig, "id" | "createdAt">) => Promise<void>;
557
+ updateProvider: (id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>) => Promise<void>;
558
+ deleteProvider: (id: string) => Promise<void>;
559
+ selectProvider: (id: string) => void;
560
+ }
561
+ /**
562
+ * Hook for managing providers (backend + model combos).
563
+ * Requires an IChatClient with provider methods (e.g. RemoteChatClient).
564
+ */
565
+ declare function useProviders(): UseProvidersReturn;
566
+
567
+ /** Props for the ProviderSelector component. */
568
+ interface ProviderSelectorProps {
569
+ providers: ProviderConfig[];
570
+ activeProviderId?: string;
571
+ onSelect: (id: string) => void;
572
+ onSettingsClick?: () => void;
573
+ className?: string;
574
+ }
575
+ /**
576
+ * Headless dropdown for selecting a configured provider.
577
+ * Uses data attributes for styling hooks. Follows ModelSelector pattern.
578
+ */
579
+ declare function ProviderSelector({ providers, activeProviderId, onSelect, onSettingsClick, className, }: ProviderSelectorProps): ReactNode;
580
+
581
+ /** A unified item rendered in the ProviderModelSelector dropdown. */
582
+ interface ProviderModelItem {
583
+ id: string;
584
+ label: string;
585
+ sublabel?: string;
586
+ tier?: string;
587
+ type: "provider" | "model";
588
+ }
589
+ /** Props for the ProviderModelSelector component. */
590
+ interface ProviderModelSelectorProps {
591
+ /** Configured providers (backend + model combos). When non-empty, provider mode is used. */
592
+ providers?: ProviderConfig[];
593
+ /** Available models. Used when providers is empty or undefined. */
594
+ models?: ModelOption[];
595
+ /** Currently selected provider ID. */
596
+ activeProviderId?: string;
597
+ /** Currently selected model ID (fallback mode). */
598
+ selectedModel?: string;
599
+ /** Called when a provider is selected. */
600
+ onSelectProvider?: (id: string) => void;
601
+ /** Called when a model is selected (fallback mode). */
602
+ onSelectModel?: (modelId: string) => void;
603
+ /** Called when settings gear is clicked. */
604
+ onSettingsClick?: () => void;
605
+ /** Placeholder text for the trigger button. */
606
+ placeholder?: string;
607
+ className?: string;
608
+ }
609
+ /**
610
+ * Unified selector that shows providers when available, falls back to model list.
611
+ * Replaces the need for separate ProviderSelector + ModelSelector in ChatUI.
612
+ */
613
+ declare function ProviderModelSelector({ providers, models, activeProviderId, selectedModel, onSelectProvider, onSelectModel, onSettingsClick, placeholder, className, }: ProviderModelSelectorProps): ReactNode;
614
+
615
+ /** Props for the ProviderSettings component. */
616
+ interface ProviderSettingsProps {
617
+ providers: ProviderConfig[];
618
+ onClose?: () => void;
619
+ onProviderCreated?: (p: ProviderConfig) => void;
620
+ onProviderDeleted?: (id: string) => void;
621
+ onProviderUpdated?: (id: string, changes: {
622
+ model?: string;
623
+ label?: string;
624
+ }) => void;
625
+ /** Called when authentication succeeds (before configure step). Parent should refresh providers. */
626
+ onAuthCompleted?: (backend: string) => void;
627
+ authBaseUrl?: string;
628
+ className?: string;
629
+ }
630
+ /**
631
+ * Headless settings panel for managing providers.
632
+ * States: list (all providers), add (new provider flow), edit (existing).
633
+ */
634
+ declare function ProviderSettings({ providers, onClose, onProviderCreated, onProviderDeleted, onProviderUpdated, onAuthCompleted, authBaseUrl, className, }: ProviderSettingsProps): ReactNode;
635
+
636
+ /** Props for the ContextStatsDisplay component. */
637
+ interface ContextStatsDisplayProps {
638
+ /** Context stats from runtime.getContextStats(sessionId). Null = nothing to display. */
639
+ stats: ContextStats | null;
640
+ /** CSS class on the root element. */
641
+ className?: string;
642
+ }
643
+ /**
644
+ * Headless component displaying context window statistics.
645
+ *
646
+ * When real usage data is available (realPromptTokens + modelContextWindow),
647
+ * displays actual token usage and model context window size.
648
+ * When real data is not yet available (before first API response), returns null.
649
+ *
650
+ * All elements use `data-*` attributes for CSS styling — no inline styles.
651
+ */
652
+ declare function ContextStatsDisplay({ stats, className }: ContextStatsDisplayProps): ReactNode;
653
+
654
+ /**
655
+ * @witqq/agent-sdk/chat/react — ChatUI
656
+ *
657
+ * Composite component that wires Thread, Composer, ThreadList, ModelSelector,
658
+ * and ProviderSettings into a complete chat interface. Consumers get a full AI chat
659
+ * in ~3 lines:
660
+ *
661
+ * import { ChatUI } from "@witqq/agent-sdk/chat/react";
662
+ * <ChatUI runtime={myRuntime} />
663
+ *
664
+ * Slot system: replace any sub-component while keeping all others as defaults.
665
+ *
666
+ * Built from composable sub-components: ChatLayout, ChatHeader, ChatInputArea,
667
+ * ChatSettingsOverlay — each usable independently for custom layouts.
668
+ */
669
+
670
+ /** Slot overrides for ChatUI sub-components. */
671
+ interface ChatUISlots {
672
+ /** Replace the Thread component. */
673
+ thread?: ComponentType<ThreadProps>;
674
+ /** Replace the Composer component. */
675
+ composer?: ComponentType<ComposerProps>;
676
+ /** Replace the ThreadList (sidebar) component. */
677
+ threadList?: ComponentType<ThreadListProps>;
678
+ /** Replace the ModelSelector component (used in header when no providers). */
679
+ modelSelector?: ComponentType<ModelSelectorProps>;
680
+ /** Replace the BackendSelector component. */
681
+ backendSelector?: ComponentType<BackendSelectorProps>;
682
+ /** Replace the ProviderSelector component (legacy, use providerModelSelector). */
683
+ providerSelector?: ComponentType<ProviderSelectorProps>;
684
+ /** Replace the unified ProviderModelSelector component (near composer). */
685
+ providerModelSelector?: ComponentType<ProviderModelSelectorProps>;
686
+ /** Replace the ProviderSettings component. */
687
+ providerSettings?: ComponentType<ProviderSettingsProps>;
688
+ /** Replace the ContextStatsDisplay component. */
689
+ contextStats?: ComponentType<ContextStatsDisplayProps>;
690
+ /** Custom auth dialog element rendered when provided. */
691
+ authDialog?: ReactNode;
692
+ /** Custom message renderer (forwarded to ThreadProvider). */
693
+ renderMessage?: (message: ChatMessage, index: number) => ReactNode;
694
+ /** Custom tool call renderer (forwarded to ThreadProvider). */
695
+ renderToolCall?: (part: ToolCallPart, index: number) => ReactNode;
696
+ /** Custom thinking block renderer (forwarded to ThreadProvider). */
697
+ renderThinkingBlock?: (part: ReasoningPart, index: number) => ReactNode;
698
+ }
699
+ /** Props for the ChatUI composite component. */
700
+ interface ChatUIProps {
701
+ /** The chat runtime or client instance. ChatUI wraps it in ChatProvider. Accepts IChatClient. */
702
+ runtime: IChatClient;
703
+ /** Slot overrides for sub-components. */
704
+ slots?: ChatUISlots;
705
+ /** CSS class on the root element. */
706
+ className?: string;
707
+ /** Show the session sidebar. Default: true. */
708
+ showSidebar?: boolean;
709
+ /** Show the model selector header. Default: true. */
710
+ showModelSelector?: boolean;
711
+ /** Show the backend selector in header. Default: false. */
712
+ showBackendSelector?: boolean;
713
+ /** Show the provider selector near composer. Default: auto (true when providers available). */
714
+ showProviderSelector?: boolean;
715
+ /** Base URL for auth API (needed by ProviderSettings). */
716
+ authBaseUrl?: string;
717
+ /** Placeholder text for the Composer textarea. */
718
+ placeholder?: string;
719
+ }
720
+ /**
721
+ * Composite chat component — complete AI chat interface in one import.
722
+ *
723
+ * ```tsx
724
+ * import { ChatUI } from "@witqq/agent-sdk/chat/react";
725
+ *
726
+ * function App() {
727
+ * return <ChatUI runtime={myRuntime} />;
728
+ * }
729
+ * ```
730
+ */
731
+ declare function ChatUI({ runtime, ...rest }: ChatUIProps): ReactNode;
732
+
733
+ /**
734
+ * @witqq/agent-sdk/chat/react — ChatLayout
735
+ *
736
+ * Pure layout container for chat interfaces. Renders sidebar + main area
737
+ * without any logic or state. ChatUI uses this internally.
738
+ */
739
+
740
+ /** Props for the ChatLayout component. */
741
+ interface ChatLayoutProps {
742
+ /** Main chat content (thread, input area, etc.). */
743
+ children: ReactNode;
744
+ /** Sidebar content (thread list, session list, etc.). */
745
+ sidebar?: ReactNode;
746
+ /** Modal/overlay content. Accepts a single node or array of nodes. */
747
+ overlay?: ReactNode | ReactNode[];
748
+ /** CSS class on the root element. */
524
749
  className?: string;
525
750
  }
526
751
  /**
527
- * Multi-backend auth dialog component.
752
+ * Pure layout container — flex row with optional sidebar and overlay.
528
753
  *
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.
754
+ * Renders `[data-chat-ui]` root with:
755
+ * - overlay (rendered first for z-index stacking)
756
+ * - sidebar (rendered before main content)
757
+ * - children (main chat area)
532
758
  */
533
- declare function AuthDialog({ backends, selectedBackend: controlledBackend, onBackendChange, onAuthenticated, renderCopilotFlow, renderClaudeFlow, renderApiKeyFlow, className, }: AuthDialogProps): ReactNode;
759
+ declare function ChatLayout({ children, sidebar, overlay, className }: ChatLayoutProps): ReactNode;
534
760
 
535
761
  /**
536
- * Client-side runtime adapter that implements IChatRuntime by delegating
762
+ * @witqq/agent-sdk/chat/react ChatHeader
763
+ *
764
+ * Selector composition for the chat header area. Renders backend selector,
765
+ * model selector, or nothing based on configuration.
766
+ */
767
+
768
+ /** Props for the ChatHeader component. */
769
+ interface ChatHeaderProps {
770
+ /** Whether to show backend selector. Default: false. */
771
+ showBackendSelector?: boolean;
772
+ /** Whether to show model selector. Default: true. */
773
+ showModelSelector?: boolean;
774
+ /** Whether providers are configured (hides model selector when true). */
775
+ hasProviders?: boolean;
776
+ /** Available backends list. */
777
+ backends?: BackendInfo[];
778
+ /** Available models list. */
779
+ models?: ModelOption[];
780
+ /** Currently selected model. */
781
+ selectedModel?: string;
782
+ /** Backend selection handler. */
783
+ onBackendSelect?: (name: string) => void;
784
+ /** Model selection handler. */
785
+ onModelSelect?: (modelId: string) => void;
786
+ /** Slot override for BackendSelector. */
787
+ BackendSelectorComponent?: ComponentType<BackendSelectorProps>;
788
+ /** Slot override for ModelSelector. */
789
+ ModelSelectorComponent?: ComponentType<ModelSelectorProps>;
790
+ }
791
+ /**
792
+ * Header area with backend and model selectors.
793
+ * Returns null when no selectors need to be shown.
794
+ */
795
+ declare function ChatHeader({ showBackendSelector, showModelSelector, hasProviders, backends, models, selectedModel, onBackendSelect, onModelSelect, BackendSelectorComponent: BSC, ModelSelectorComponent: MSC, }: ChatHeaderProps): ReactNode;
796
+
797
+ /**
798
+ * @witqq/agent-sdk/chat/react — ChatInputArea
799
+ *
800
+ * Input area combining the unified provider/model selector with the composer.
801
+ */
802
+
803
+ /** Props for the ChatInputArea component. */
804
+ interface ChatInputAreaProps {
805
+ /** Send message handler. */
806
+ onSend: (message: string) => void;
807
+ /** Stop generation handler. */
808
+ onStop?: () => void;
809
+ /** Whether generation is in progress. */
810
+ isGenerating?: boolean;
811
+ /** Placeholder text for the textarea. */
812
+ placeholder?: string;
813
+ /** Available providers. */
814
+ providers?: ProviderConfig[];
815
+ /** Available models. */
816
+ models?: ModelOption[];
817
+ /** Active provider ID. */
818
+ activeProviderId?: string;
819
+ /** Selected model. */
820
+ selectedModel?: string;
821
+ /** Provider selection handler. */
822
+ onSelectProvider?: (id: string) => void;
823
+ /** Model selection handler. */
824
+ onSelectModel?: (modelId: string) => void;
825
+ /** Settings button handler. */
826
+ onSettingsClick?: () => void;
827
+ /** Slot override for Composer. */
828
+ ComposerComponent?: ComponentType<ComposerProps>;
829
+ /** Slot override for ProviderModelSelector. */
830
+ ProviderModelSelectorComponent?: ComponentType<ProviderModelSelectorProps>;
831
+ /** Token usage data to display. */
832
+ usage?: ChatUsage | null;
833
+ }
834
+ /**
835
+ * Input area — unified selector + composer in a `[data-chat-input-area]` container.
836
+ */
837
+ declare function ChatInputArea({ onSend, onStop, isGenerating, placeholder, providers, models, activeProviderId, selectedModel, onSelectProvider, onSelectModel, onSettingsClick, ComposerComponent: CC, ProviderModelSelectorComponent: PMSC, usage, }: ChatInputAreaProps): ReactNode;
838
+
839
+ /**
840
+ * @witqq/agent-sdk/chat/react — ChatSettingsOverlay
841
+ *
842
+ * Modal overlay for provider settings management.
843
+ * Features: backdrop click-to-close, ESC key handler, focus trap.
844
+ */
845
+
846
+ /** Props for the ChatSettingsOverlay component. */
847
+ interface ChatSettingsOverlayProps {
848
+ /** Whether the overlay is visible. */
849
+ open: boolean;
850
+ /** Close handler. */
851
+ onClose: () => void;
852
+ /** Available providers. */
853
+ providers?: ProviderConfig[];
854
+ /** Auth API base URL. */
855
+ authBaseUrl?: string;
856
+ /** Provider created handler. */
857
+ onProviderCreated?: (provider: {
858
+ backend: string;
859
+ model: string;
860
+ label?: string;
861
+ }) => void;
862
+ /** Provider deleted handler. */
863
+ onProviderDeleted?: (id: string) => void;
864
+ /** Provider updated handler. */
865
+ onProviderUpdated?: (id: string, changes: Partial<ProviderConfig>) => void;
866
+ /** Called when authentication succeeds. Parent should refresh providers. */
867
+ onAuthCompleted?: (backend: string) => void;
868
+ /** Slot override for ProviderSettings. */
869
+ ProviderSettingsComponent?: ComponentType<ProviderSettingsProps>;
870
+ }
871
+ /**
872
+ * Settings modal — renders `[data-provider-settings-overlay]` when open.
873
+ * Returns null when closed.
874
+ * Backdrop click and Escape key close the overlay with exit animation.
875
+ * Focus is trapped within the overlay content.
876
+ */
877
+ declare function ChatSettingsOverlay({ open, onClose, providers, authBaseUrl, onProviderCreated, onProviderDeleted, onProviderUpdated, onAuthCompleted, ProviderSettingsComponent: PSC, }: ChatSettingsOverlayProps): ReactNode;
878
+
879
+ /** Props for the UsageBadge component. */
880
+ interface UsageBadgeProps {
881
+ usage: ChatUsage | null;
882
+ className?: string;
883
+ }
884
+ /** Compact token usage display. Shows prompt/completion/total tokens. */
885
+ declare function UsageBadge({ usage, className }: UsageBadgeProps): ReactNode;
886
+
887
+ /**
888
+ * Client-side adapter that implements IChatClient by delegating
537
889
  * operations over HTTP/SSE to a remote server.
538
890
  *
539
891
  * Bridges the gap between SDK React hooks (which require an in-process runtime)
@@ -541,30 +893,35 @@ declare function AuthDialog({ backends, selectedBackend: controlledBackend, onBa
541
893
  *
542
894
  * @example
543
895
  * ```ts
544
- * import { RemoteChatRuntime } from "@witqq/agent-sdk/chat/react";
896
+ * import { RemoteChatClient } from "@witqq/agent-sdk/chat/react";
545
897
  * import { ChatProvider } from "@witqq/agent-sdk/chat/react";
546
898
  *
547
- * const runtime = new RemoteChatRuntime({ baseUrl: "/api" });
548
- * <ChatProvider runtime={runtime}> ... </ChatProvider>
899
+ * const client = new RemoteChatClient({ baseUrl: "/api" });
900
+ * <ChatProvider runtime={client}> ... </ChatProvider>
549
901
  * ```
550
902
  */
551
903
 
552
904
  /**
553
905
  * Standard server endpoint contract.
554
- * Server implementations expose these routes to work with RemoteChatRuntime.
906
+ * Server implementations expose these routes to work with RemoteChatClient.
555
907
  *
556
908
  * POST {baseUrl}/sessions/create — Create session
557
909
  * GET {baseUrl}/sessions/{id} — Get session
558
910
  * GET {baseUrl}/sessions — List sessions
559
911
  * DELETE {baseUrl}/sessions/{id} — Delete session
560
- * POST {baseUrl}/sessions/{id}/archiveArchive session
912
+ * GET {baseUrl}/sessions/{id}/context-statsGet context window stats
561
913
  * POST {baseUrl}/send — Send message (SSE stream response)
562
914
  * POST {baseUrl}/abort — Abort current stream
563
915
  * GET {baseUrl}/models — List models
564
- * POST {baseUrl}/backend/switch Switch backend
916
+ * GET {baseUrl}/backends List backends
565
917
  * POST {baseUrl}/model/switch — Switch model
918
+ * POST {baseUrl}/provider/switch — Switch provider (backend + model)
919
+ * GET {baseUrl}/providers — List providers
920
+ * POST {baseUrl}/providers — Create provider
921
+ * PUT {baseUrl}/providers/{id} — Update provider
922
+ * DELETE {baseUrl}/providers/{id} — Delete provider
566
923
  */
567
- interface RemoteChatRuntimeOptions {
924
+ interface RemoteChatClientOptions {
568
925
  /** Base URL for API endpoints (e.g. "/api" or "https://example.com/api") */
569
926
  baseUrl: string;
570
927
  /** Optional headers for all requests (e.g. auth tokens) */
@@ -572,48 +929,160 @@ interface RemoteChatRuntimeOptions {
572
929
  /** Custom fetch implementation for testability */
573
930
  fetch?: typeof globalThis.fetch;
574
931
  }
575
- declare class RemoteChatRuntime implements IChatRuntime {
932
+ declare class RemoteChatClient implements IChatClient {
576
933
  private _status;
577
934
  private _activeSessionId;
578
- private _currentBackend;
579
- private _currentModel;
935
+ private _selectedProviderId;
580
936
  private _abortController;
581
- private readonly _tools;
582
- private readonly _middlewares;
583
937
  private readonly baseUrl;
584
938
  private readonly headers;
585
939
  private readonly _fetch;
586
- constructor(options: RemoteChatRuntimeOptions);
940
+ private readonly _selectionListeners;
941
+ constructor(options: RemoteChatClientOptions);
587
942
  get status(): RuntimeStatus;
588
943
  dispose(): Promise<void>;
589
944
  private assertNotDisposed;
945
+ get selectedProviderId(): string | null;
946
+ selectProvider(providerId: string): void;
947
+ onSelectionChange(callback: SelectionChangeCallback): () => void;
948
+ private _notifySelectionChange;
590
949
  get activeSessionId(): ChatId | null;
591
950
  createSession(options: CreateSessionOptions): Promise<ChatSession>;
592
951
  getSession(id: ChatIdLike): Promise<ChatSession | null>;
593
952
  listSessions(_options?: SessionListOptions): Promise<ChatSession[]>;
594
953
  deleteSession(id: ChatIdLike): Promise<void>;
595
- archiveSession(id: ChatIdLike): Promise<void>;
954
+ /**
955
+ * Fetch context window stats from server.
956
+ * Returns null if stats not available (e.g. no messages sent yet).
957
+ */
958
+ getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
596
959
  switchSession(id: ChatIdLike): Promise<ChatSession>;
597
960
  send(sessionId: ChatIdLike, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
598
961
  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;
962
+ listModels(): Promise<ModelInfo[]>;
963
+ listBackends(): Promise<BackendInfo[]>;
964
+ listProviders(): Promise<ProviderConfig[]>;
965
+ createProvider(config: Omit<ProviderConfig, "id" | "createdAt">): Promise<ProviderConfig>;
966
+ updateProvider(id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>): Promise<void>;
967
+ deleteProvider(id: string): Promise<void>;
610
968
  private readonly _sessionListeners;
611
969
  onSessionChange(callback: () => void): () => void;
612
970
  private _notifySessionChange;
613
971
  private _get;
614
972
  private _post;
615
973
  private _delete;
974
+ private _put;
616
975
  private _parseSSEStream;
617
976
  }
618
977
 
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 };
978
+ /**
979
+ * @witqq/agent-sdk/chat/react — useCopilotAuth
980
+ *
981
+ * Server-delegated Copilot Device Flow authentication hook.
982
+ * Independently usable — does not require useRemoteAuth orchestrator.
983
+ */
984
+
985
+ /** Options for useCopilotAuth. */
986
+ interface UseCopilotAuthOptions {
987
+ /** Base URL of the auth server (e.g. "/api/auth") */
988
+ baseUrl: string;
989
+ /** Called after successful authentication */
990
+ onAuthenticated?: (token: AuthToken) => void;
991
+ /** Called on authentication error */
992
+ onError?: (error: Error) => void;
993
+ /** Optional fetch override (for testing) */
994
+ fetch?: typeof globalThis.fetch;
995
+ /** Optional headers for all requests */
996
+ headers?: Record<string, string>;
997
+ }
998
+ /** Return value from useCopilotAuth. */
999
+ interface UseCopilotAuthReturn {
1000
+ status: "idle" | "pending" | "authenticated" | "error";
1001
+ error: Error | null;
1002
+ token: AuthToken | null;
1003
+ deviceCode: string | null;
1004
+ verificationUrl: string | null;
1005
+ /** Start the device flow. Shows deviceCode and verificationUrl, then polls for completion. */
1006
+ start: () => Promise<void>;
1007
+ reset: () => void;
1008
+ }
1009
+ /**
1010
+ * Copilot Device Flow authentication.
1011
+ * Starts device flow on server, provides code/URL for user, polls until complete.
1012
+ */
1013
+ declare function useCopilotAuth(options: UseCopilotAuthOptions): UseCopilotAuthReturn;
1014
+
1015
+ /**
1016
+ * @witqq/agent-sdk/chat/react — useClaudeAuth
1017
+ *
1018
+ * Server-delegated Claude OAuth + PKCE authentication hook.
1019
+ * Independently usable — does not require useRemoteAuth orchestrator.
1020
+ */
1021
+
1022
+ /** Options for useClaudeAuth. */
1023
+ interface UseClaudeAuthOptions {
1024
+ /** Base URL of the auth server (e.g. "/api/auth") */
1025
+ baseUrl: string;
1026
+ /** Called after successful authentication */
1027
+ onAuthenticated?: (token: AuthToken) => void;
1028
+ /** Called on authentication error */
1029
+ onError?: (error: Error) => void;
1030
+ /** Optional fetch override (for testing) */
1031
+ fetch?: typeof globalThis.fetch;
1032
+ /** Optional headers for all requests */
1033
+ headers?: Record<string, string>;
1034
+ }
1035
+ /** Return value from useClaudeAuth. */
1036
+ interface UseClaudeAuthReturn {
1037
+ status: "idle" | "pending" | "authenticated" | "error";
1038
+ error: Error | null;
1039
+ token: AuthToken | null;
1040
+ authorizeUrl: string | null;
1041
+ /** Start OAuth flow. Sets authorizeUrl for user redirect. */
1042
+ start: () => Promise<void>;
1043
+ /** Complete OAuth after redirect. Pass the code or callback URL. */
1044
+ complete: (codeOrUrl: string) => Promise<void>;
1045
+ reset: () => void;
1046
+ }
1047
+ /**
1048
+ * Claude OAuth + PKCE authentication.
1049
+ * Two-step flow: start() gets authorizeUrl → user redirects → complete(code) finishes.
1050
+ */
1051
+ declare function useClaudeAuth(options: UseClaudeAuthOptions): UseClaudeAuthReturn;
1052
+
1053
+ /**
1054
+ * @witqq/agent-sdk/chat/react — useApiKeyAuth
1055
+ *
1056
+ * Server-delegated API key authentication hook (for Vercel AI / OpenRouter / etc.).
1057
+ * Independently usable — does not require useRemoteAuth orchestrator.
1058
+ */
1059
+
1060
+ /** Options for useApiKeyAuth. */
1061
+ interface UseApiKeyAuthOptions {
1062
+ /** Base URL of the auth server (e.g. "/api/auth") */
1063
+ baseUrl: string;
1064
+ /** Called after successful authentication */
1065
+ onAuthenticated?: (token: AuthToken) => void;
1066
+ /** Called on authentication error */
1067
+ onError?: (error: Error) => void;
1068
+ /** Optional fetch override (for testing) */
1069
+ fetch?: typeof globalThis.fetch;
1070
+ /** Optional headers for all requests */
1071
+ headers?: Record<string, string>;
1072
+ }
1073
+ /** Return value from useApiKeyAuth. */
1074
+ interface UseApiKeyAuthReturn {
1075
+ status: "idle" | "pending" | "authenticated" | "error";
1076
+ error: Error | null;
1077
+ token: AuthToken | null;
1078
+ /** Submit an API key (and optional provider base URL). */
1079
+ submit: (key: string, apiBaseUrl?: string) => Promise<void>;
1080
+ reset: () => void;
1081
+ }
1082
+ /**
1083
+ * API key authentication.
1084
+ * Sends key to server for validation and storage.
1085
+ */
1086
+ declare function useApiKeyAuth(options: UseApiKeyAuthOptions): UseApiKeyAuthReturn;
1087
+
1088
+ 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, 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, useApiKeyAuth, useBackends, useChat, useChatRuntime, useClaudeAuth, useCopilotAuth, useMessages, useModels, useOptionalThreadSlots, useProviders, useRemoteAuth, useRemoteChat, useSSE, useSessions, useThreadSlots, useToolApproval };