@witqq/agent-sdk 0.6.1 → 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 (145) hide show
  1. package/README.md +539 -6
  2. package/dist/{types-BvwNzZCj.d.cts → agent-CW9XbmG_.d.ts} +148 -95
  3. package/dist/{types-BvwNzZCj.d.ts → agent-DxY68NZL.d.cts} +148 -95
  4. package/dist/auth/index.cjs +260 -2
  5. package/dist/auth/index.cjs.map +1 -1
  6. package/dist/auth/index.d.cts +21 -138
  7. package/dist/auth/index.d.ts +21 -138
  8. package/dist/auth/index.js +260 -3
  9. package/dist/auth/index.js.map +1 -1
  10. package/dist/backends/claude.cjs +653 -140
  11. package/dist/backends/claude.cjs.map +1 -1
  12. package/dist/backends/claude.d.cts +4 -1
  13. package/dist/backends/claude.d.ts +4 -1
  14. package/dist/backends/claude.js +653 -140
  15. package/dist/backends/claude.js.map +1 -1
  16. package/dist/backends/copilot.cjs +428 -88
  17. package/dist/backends/copilot.cjs.map +1 -1
  18. package/dist/backends/copilot.d.cts +13 -4
  19. package/dist/backends/copilot.d.ts +13 -4
  20. package/dist/backends/copilot.js +428 -88
  21. package/dist/backends/copilot.js.map +1 -1
  22. package/dist/backends/vercel-ai.cjs +349 -77
  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 +349 -77
  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 +147 -0
  31. package/dist/chat/accumulator.cjs.map +1 -0
  32. package/dist/chat/accumulator.d.cts +64 -0
  33. package/dist/chat/accumulator.d.ts +64 -0
  34. package/dist/chat/accumulator.js +145 -0
  35. package/dist/chat/accumulator.js.map +1 -0
  36. package/dist/chat/backends.cjs +3524 -0
  37. package/dist/chat/backends.cjs.map +1 -0
  38. package/dist/chat/backends.d.cts +66 -0
  39. package/dist/chat/backends.d.ts +66 -0
  40. package/dist/chat/backends.js +3512 -0
  41. package/dist/chat/backends.js.map +1 -0
  42. package/dist/chat/context.cjs +280 -0
  43. package/dist/chat/context.cjs.map +1 -0
  44. package/dist/chat/context.d.cts +191 -0
  45. package/dist/chat/context.d.ts +191 -0
  46. package/dist/chat/context.js +277 -0
  47. package/dist/chat/context.js.map +1 -0
  48. package/dist/chat/core.cjs +305 -0
  49. package/dist/chat/core.cjs.map +1 -0
  50. package/dist/chat/core.d.cts +84 -0
  51. package/dist/chat/core.d.ts +84 -0
  52. package/dist/chat/core.js +282 -0
  53. package/dist/chat/core.js.map +1 -0
  54. package/dist/chat/errors.cjs +273 -0
  55. package/dist/chat/errors.cjs.map +1 -0
  56. package/dist/chat/errors.d.cts +97 -0
  57. package/dist/chat/errors.d.ts +97 -0
  58. package/dist/chat/errors.js +266 -0
  59. package/dist/chat/errors.js.map +1 -0
  60. package/dist/chat/events.cjs +203 -0
  61. package/dist/chat/events.cjs.map +1 -0
  62. package/dist/chat/events.d.cts +245 -0
  63. package/dist/chat/events.d.ts +245 -0
  64. package/dist/chat/events.js +196 -0
  65. package/dist/chat/events.js.map +1 -0
  66. package/dist/chat/index.cjs +5550 -0
  67. package/dist/chat/index.cjs.map +1 -0
  68. package/dist/chat/index.d.cts +77 -0
  69. package/dist/chat/index.d.ts +77 -0
  70. package/dist/chat/index.js +5505 -0
  71. package/dist/chat/index.js.map +1 -0
  72. package/dist/chat/react/theme.css +2517 -0
  73. package/dist/chat/react.cjs +3589 -0
  74. package/dist/chat/react.cjs.map +1 -0
  75. package/dist/chat/react.d.cts +1088 -0
  76. package/dist/chat/react.d.ts +1088 -0
  77. package/dist/chat/react.js +3547 -0
  78. package/dist/chat/react.js.map +1 -0
  79. package/dist/chat/runtime.cjs +1245 -0
  80. package/dist/chat/runtime.cjs.map +1 -0
  81. package/dist/chat/runtime.d.cts +182 -0
  82. package/dist/chat/runtime.d.ts +182 -0
  83. package/dist/chat/runtime.js +1243 -0
  84. package/dist/chat/runtime.js.map +1 -0
  85. package/dist/chat/server.cjs +2668 -0
  86. package/dist/chat/server.cjs.map +1 -0
  87. package/dist/chat/server.d.cts +648 -0
  88. package/dist/chat/server.d.ts +648 -0
  89. package/dist/chat/server.js +2628 -0
  90. package/dist/chat/server.js.map +1 -0
  91. package/dist/chat/sessions.cjs +380 -0
  92. package/dist/chat/sessions.cjs.map +1 -0
  93. package/dist/chat/sessions.d.cts +158 -0
  94. package/dist/chat/sessions.d.ts +158 -0
  95. package/dist/chat/sessions.js +376 -0
  96. package/dist/chat/sessions.js.map +1 -0
  97. package/dist/chat/sqlite.cjs +441 -0
  98. package/dist/chat/sqlite.cjs.map +1 -0
  99. package/dist/chat/sqlite.d.cts +128 -0
  100. package/dist/chat/sqlite.d.ts +128 -0
  101. package/dist/chat/sqlite.js +435 -0
  102. package/dist/chat/sqlite.js.map +1 -0
  103. package/dist/chat/state.cjs +190 -0
  104. package/dist/chat/state.cjs.map +1 -0
  105. package/dist/chat/state.d.cts +95 -0
  106. package/dist/chat/state.d.ts +95 -0
  107. package/dist/chat/state.js +180 -0
  108. package/dist/chat/state.js.map +1 -0
  109. package/dist/chat/storage.cjs +249 -0
  110. package/dist/chat/storage.cjs.map +1 -0
  111. package/dist/chat/storage.d.cts +197 -0
  112. package/dist/chat/storage.d.ts +197 -0
  113. package/dist/chat/storage.js +245 -0
  114. package/dist/chat/storage.js.map +1 -0
  115. package/dist/errors-C-so0M4t.d.cts +33 -0
  116. package/dist/errors-C-so0M4t.d.ts +33 -0
  117. package/dist/errors-CmVvczxZ.d.cts +28 -0
  118. package/dist/errors-CmVvczxZ.d.ts +28 -0
  119. package/dist/in-process-transport-C1JnJGVR.d.ts +228 -0
  120. package/dist/in-process-transport-C7DSqPyX.d.cts +228 -0
  121. package/dist/index.cjs +365 -59
  122. package/dist/index.cjs.map +1 -1
  123. package/dist/index.d.cts +322 -125
  124. package/dist/index.d.ts +322 -125
  125. package/dist/index.js +359 -60
  126. package/dist/index.js.map +1 -1
  127. package/dist/provider-types-PTSlRPNB.d.cts +39 -0
  128. package/dist/provider-types-PTSlRPNB.d.ts +39 -0
  129. package/dist/refresh-manager-B81PpYBr.d.cts +153 -0
  130. package/dist/refresh-manager-Dlv_iNZi.d.ts +153 -0
  131. package/dist/testing.cjs +383 -0
  132. package/dist/testing.cjs.map +1 -0
  133. package/dist/testing.d.cts +132 -0
  134. package/dist/testing.d.ts +132 -0
  135. package/dist/testing.js +377 -0
  136. package/dist/testing.js.map +1 -0
  137. package/dist/token-store-CSUBgYwn.d.ts +48 -0
  138. package/dist/token-store-CuC4hB9Z.d.cts +48 -0
  139. package/dist/transport-Cdh3M0tS.d.cts +68 -0
  140. package/dist/transport-Ciap4PWK.d.ts +68 -0
  141. package/dist/types-4vbcmPTp.d.cts +143 -0
  142. package/dist/types-BxggH0Yh.d.ts +143 -0
  143. package/dist/types-DRgd_9R7.d.cts +363 -0
  144. package/dist/types-ajANVzf7.d.ts +363 -0
  145. package/package.json +178 -6
@@ -0,0 +1,77 @@
1
+ export { B as BackendAdapterOptions, a as ChatEvent, C as ChatEventType, b as ChatId, f as ChatIdLike, c as ChatMessage, k as ChatMessageMetadata, l as ChatMessageStatus, e as ChatMiddleware, m as ChatMiddlewareContext, n as ChatRole, g as ChatSession, j as ChatSessionConfig, F as FilePart, I as IChatBackend, o as IChatProvider, d as IResumableBackend, p as MessagePart, M as MessageStatus, O as ObservableSession, P as PartStatus, q as ReasoningPart, h as RuntimeSendOptions, R as RuntimeStatus, S as SendMessageOptions, r as SessionInfo, s as SessionStatus, t as SourcePart, u as TextPart, v as ToolCallPart, T as ToolCallStatus, w as createChatId, x as createTextMessage, y as isObservableSession, i as isResumableBackend, z as toChatId } from '../types-DRgd_9R7.cjs';
2
+ export { adaptAgentEvents, agentEventToChatEvent, fromAgentMessage, getMessageReasoning, getMessageText, getMessageToolCalls, isChatEvent, isChatMessage, isChatSession, isFilePart, isMessagePart, isReasoningPart, isSourcePart, isTextPart, isToolCallPart, toAgentMessage } from './core.cjs';
3
+ export { BackendAdapterFactory, BackendInfo, ChatRuntimeOptions, IChatClient, IChatRuntime, IProviderClient, RetryConfig, SelectionChangeCallback, StreamRetryConfig, createChatRuntime } from './runtime.cjs';
4
+ export { CreateSessionOptions, FileSessionStore, IChatSessionStore, ISessionReader, ISessionWriter, InMemorySessionStore, PaginatedMessages } from './sessions.cjs';
5
+ export { ChatError, ExponentialBackoffStrategy, classifyError, isRetryable, withRetry } from './errors.cjs';
6
+ export { B as BaseBackendAdapter, C as ClaudeChatAdapter, b as CopilotChatAdapter, I as InProcessChatTransport, V as VercelAIChatAdapter, f as WsChatTransport } from '../in-process-transport-C7DSqPyX.cjs';
7
+ export { I as IChatTransport, S as SSEChatTransport, s as streamToTransport } from '../transport-Cdh3M0tS.cjs';
8
+ export { ContextStats, ContextWindowConfig, ContextWindowManager, ContextWindowResult, OverflowStrategy, estimateTokens } from './context.cjs';
9
+ export { MessageAccumulator } from './accumulator.cjs';
10
+ export { ChatEventBus, TypedEventEmitter } from './events.cjs';
11
+ export { I as IProviderStore, P as ProviderConfig } from '../provider-types-PTSlRPNB.cjs';
12
+ export { E as ErrorCode } from '../errors-C-so0M4t.cjs';
13
+ import '../agent-DxY68NZL.cjs';
14
+ import 'zod';
15
+ import '../types-4vbcmPTp.cjs';
16
+ import '../errors-CmVvczxZ.cjs';
17
+ import './storage.cjs';
18
+ import '../backends-BSrsBYFn.cjs';
19
+
20
+ /**
21
+ * Generic listener set utility for subscribe/notify patterns.
22
+ *
23
+ * Encapsulates the recurring pattern of:
24
+ * - Set<callback> storage
25
+ * - add(callback) → unsubscribe function
26
+ * - notify(...args) with try/catch per listener
27
+ * - clear() for disposal
28
+ */
29
+ declare class ListenerSet<T extends (...args: any[]) => void> {
30
+ private readonly _listeners;
31
+ /** Add a listener. Returns an unsubscribe function. */
32
+ add(callback: T): () => void;
33
+ /** Notify all listeners with the given arguments. Errors are isolated per listener. */
34
+ notify(...args: Parameters<T>): void;
35
+ /** Remove all listeners. */
36
+ clear(): void;
37
+ /** Current number of listeners. */
38
+ get size(): number;
39
+ }
40
+
41
+ /**
42
+ * @witqq/agent-sdk - Stream Watchdog
43
+ *
44
+ * Activity-based timeout wrapper for async event streams.
45
+ * Aborts the stream if no events arrive within a configurable inactivity window.
46
+ * Timer resets on each received event.
47
+ */
48
+ /** Stream watchdog configuration */
49
+ interface StreamWatchdogConfig {
50
+ /** Maximum inactivity time in milliseconds before aborting the stream */
51
+ timeoutMs: number;
52
+ /** AbortSignal to link with (watchdog aborts when this signal fires) */
53
+ signal?: AbortSignal;
54
+ }
55
+ /**
56
+ * Wraps an async iterable with an activity timeout.
57
+ * If no event arrives within `timeoutMs`, the stream is aborted with a ChatError.
58
+ * The timer resets after each received event.
59
+ *
60
+ * Uses Promise.race() so even if the source iterator is stuck on an
61
+ * unresolvable promise, the timeout fires and aborts iteration.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const watched = withStreamWatchdog(adapter.streamMessage(session, msg), {
66
+ * timeoutMs: 30000,
67
+ * signal: abortController.signal,
68
+ * });
69
+ *
70
+ * for await (const event of watched) {
71
+ * // Each event resets the 30s inactivity timer
72
+ * }
73
+ * ```
74
+ */
75
+ declare function withStreamWatchdog<T>(source: AsyncIterable<T>, config: StreamWatchdogConfig): AsyncGenerator<T>;
76
+
77
+ export { ListenerSet, type StreamWatchdogConfig, withStreamWatchdog };
@@ -0,0 +1,77 @@
1
+ export { B as BackendAdapterOptions, a as ChatEvent, C as ChatEventType, b as ChatId, f as ChatIdLike, c as ChatMessage, k as ChatMessageMetadata, l as ChatMessageStatus, e as ChatMiddleware, m as ChatMiddlewareContext, n as ChatRole, g as ChatSession, j as ChatSessionConfig, F as FilePart, I as IChatBackend, o as IChatProvider, d as IResumableBackend, p as MessagePart, M as MessageStatus, O as ObservableSession, P as PartStatus, q as ReasoningPart, h as RuntimeSendOptions, R as RuntimeStatus, S as SendMessageOptions, r as SessionInfo, s as SessionStatus, t as SourcePart, u as TextPart, v as ToolCallPart, T as ToolCallStatus, w as createChatId, x as createTextMessage, y as isObservableSession, i as isResumableBackend, z as toChatId } from '../types-ajANVzf7.js';
2
+ export { adaptAgentEvents, agentEventToChatEvent, fromAgentMessage, getMessageReasoning, getMessageText, getMessageToolCalls, isChatEvent, isChatMessage, isChatSession, isFilePart, isMessagePart, isReasoningPart, isSourcePart, isTextPart, isToolCallPart, toAgentMessage } from './core.js';
3
+ export { BackendAdapterFactory, BackendInfo, ChatRuntimeOptions, IChatClient, IChatRuntime, IProviderClient, RetryConfig, SelectionChangeCallback, StreamRetryConfig, createChatRuntime } from './runtime.js';
4
+ export { CreateSessionOptions, FileSessionStore, IChatSessionStore, ISessionReader, ISessionWriter, InMemorySessionStore, PaginatedMessages } from './sessions.js';
5
+ export { ChatError, ExponentialBackoffStrategy, classifyError, isRetryable, withRetry } from './errors.js';
6
+ export { B as BaseBackendAdapter, C as ClaudeChatAdapter, b as CopilotChatAdapter, I as InProcessChatTransport, V as VercelAIChatAdapter, f as WsChatTransport } from '../in-process-transport-C1JnJGVR.js';
7
+ export { I as IChatTransport, S as SSEChatTransport, s as streamToTransport } from '../transport-Ciap4PWK.js';
8
+ export { ContextStats, ContextWindowConfig, ContextWindowManager, ContextWindowResult, OverflowStrategy, estimateTokens } from './context.js';
9
+ export { MessageAccumulator } from './accumulator.js';
10
+ export { ChatEventBus, TypedEventEmitter } from './events.js';
11
+ export { I as IProviderStore, P as ProviderConfig } from '../provider-types-PTSlRPNB.js';
12
+ export { E as ErrorCode } from '../errors-C-so0M4t.js';
13
+ import '../agent-CW9XbmG_.js';
14
+ import 'zod';
15
+ import '../types-BxggH0Yh.js';
16
+ import '../errors-CmVvczxZ.js';
17
+ import './storage.js';
18
+ import '../backends-BSrsBYFn.js';
19
+
20
+ /**
21
+ * Generic listener set utility for subscribe/notify patterns.
22
+ *
23
+ * Encapsulates the recurring pattern of:
24
+ * - Set<callback> storage
25
+ * - add(callback) → unsubscribe function
26
+ * - notify(...args) with try/catch per listener
27
+ * - clear() for disposal
28
+ */
29
+ declare class ListenerSet<T extends (...args: any[]) => void> {
30
+ private readonly _listeners;
31
+ /** Add a listener. Returns an unsubscribe function. */
32
+ add(callback: T): () => void;
33
+ /** Notify all listeners with the given arguments. Errors are isolated per listener. */
34
+ notify(...args: Parameters<T>): void;
35
+ /** Remove all listeners. */
36
+ clear(): void;
37
+ /** Current number of listeners. */
38
+ get size(): number;
39
+ }
40
+
41
+ /**
42
+ * @witqq/agent-sdk - Stream Watchdog
43
+ *
44
+ * Activity-based timeout wrapper for async event streams.
45
+ * Aborts the stream if no events arrive within a configurable inactivity window.
46
+ * Timer resets on each received event.
47
+ */
48
+ /** Stream watchdog configuration */
49
+ interface StreamWatchdogConfig {
50
+ /** Maximum inactivity time in milliseconds before aborting the stream */
51
+ timeoutMs: number;
52
+ /** AbortSignal to link with (watchdog aborts when this signal fires) */
53
+ signal?: AbortSignal;
54
+ }
55
+ /**
56
+ * Wraps an async iterable with an activity timeout.
57
+ * If no event arrives within `timeoutMs`, the stream is aborted with a ChatError.
58
+ * The timer resets after each received event.
59
+ *
60
+ * Uses Promise.race() so even if the source iterator is stuck on an
61
+ * unresolvable promise, the timeout fires and aborts iteration.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const watched = withStreamWatchdog(adapter.streamMessage(session, msg), {
66
+ * timeoutMs: 30000,
67
+ * signal: abortController.signal,
68
+ * });
69
+ *
70
+ * for await (const event of watched) {
71
+ * // Each event resets the 30s inactivity timer
72
+ * }
73
+ * ```
74
+ */
75
+ declare function withStreamWatchdog<T>(source: AsyncIterable<T>, config: StreamWatchdogConfig): AsyncGenerator<T>;
76
+
77
+ export { ListenerSet, type StreamWatchdogConfig, withStreamWatchdog };