@witqq/agent-sdk 0.6.0 → 0.7.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 (122) hide show
  1. package/README.md +433 -6
  2. package/dist/auth/index.cjs +188 -1
  3. package/dist/auth/index.cjs.map +1 -1
  4. package/dist/auth/index.d.cts +154 -138
  5. package/dist/auth/index.d.ts +154 -138
  6. package/dist/auth/index.js +188 -2
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/backends/claude.cjs +341 -22
  9. package/dist/backends/claude.cjs.map +1 -1
  10. package/dist/backends/claude.d.cts +2 -1
  11. package/dist/backends/claude.d.ts +2 -1
  12. package/dist/backends/claude.js +341 -22
  13. package/dist/backends/claude.js.map +1 -1
  14. package/dist/backends/copilot.cjs +133 -25
  15. package/dist/backends/copilot.cjs.map +1 -1
  16. package/dist/backends/copilot.d.cts +2 -1
  17. package/dist/backends/copilot.d.ts +2 -1
  18. package/dist/backends/copilot.js +133 -25
  19. package/dist/backends/copilot.js.map +1 -1
  20. package/dist/backends/vercel-ai.cjs +66 -19
  21. package/dist/backends/vercel-ai.cjs.map +1 -1
  22. package/dist/backends/vercel-ai.d.cts +1 -1
  23. package/dist/backends/vercel-ai.d.ts +1 -1
  24. package/dist/backends/vercel-ai.js +66 -19
  25. package/dist/backends/vercel-ai.js.map +1 -1
  26. package/dist/chat/accumulator.cjs +147 -0
  27. package/dist/chat/accumulator.cjs.map +1 -0
  28. package/dist/chat/accumulator.d.cts +61 -0
  29. package/dist/chat/accumulator.d.ts +61 -0
  30. package/dist/chat/accumulator.js +145 -0
  31. package/dist/chat/accumulator.js.map +1 -0
  32. package/dist/chat/backends.cjs +3534 -0
  33. package/dist/chat/backends.cjs.map +1 -0
  34. package/dist/chat/backends.d.cts +62 -0
  35. package/dist/chat/backends.d.ts +62 -0
  36. package/dist/chat/backends.js +3501 -0
  37. package/dist/chat/backends.js.map +1 -0
  38. package/dist/chat/context.cjs +230 -0
  39. package/dist/chat/context.cjs.map +1 -0
  40. package/dist/chat/context.d.cts +167 -0
  41. package/dist/chat/context.d.ts +167 -0
  42. package/dist/chat/context.js +227 -0
  43. package/dist/chat/context.js.map +1 -0
  44. package/dist/chat/core.cjs +282 -0
  45. package/dist/chat/core.cjs.map +1 -0
  46. package/dist/chat/core.d.cts +435 -0
  47. package/dist/chat/core.d.ts +435 -0
  48. package/dist/chat/core.js +261 -0
  49. package/dist/chat/core.js.map +1 -0
  50. package/dist/chat/errors.cjs +251 -0
  51. package/dist/chat/errors.cjs.map +1 -0
  52. package/dist/chat/errors.d.cts +122 -0
  53. package/dist/chat/errors.d.ts +122 -0
  54. package/dist/chat/errors.js +243 -0
  55. package/dist/chat/errors.js.map +1 -0
  56. package/dist/chat/events.cjs +203 -0
  57. package/dist/chat/events.cjs.map +1 -0
  58. package/dist/chat/events.d.cts +241 -0
  59. package/dist/chat/events.d.ts +241 -0
  60. package/dist/chat/events.js +196 -0
  61. package/dist/chat/events.js.map +1 -0
  62. package/dist/chat/index.cjs +5359 -0
  63. package/dist/chat/index.cjs.map +1 -0
  64. package/dist/chat/index.d.cts +52 -0
  65. package/dist/chat/index.d.ts +52 -0
  66. package/dist/chat/index.js +5296 -0
  67. package/dist/chat/index.js.map +1 -0
  68. package/dist/chat/react.cjs +2739 -0
  69. package/dist/chat/react.cjs.map +1 -0
  70. package/dist/chat/react.d.cts +619 -0
  71. package/dist/chat/react.d.ts +619 -0
  72. package/dist/chat/react.js +2714 -0
  73. package/dist/chat/react.js.map +1 -0
  74. package/dist/chat/runtime.cjs +1030 -0
  75. package/dist/chat/runtime.cjs.map +1 -0
  76. package/dist/chat/runtime.d.cts +118 -0
  77. package/dist/chat/runtime.d.ts +118 -0
  78. package/dist/chat/runtime.js +1028 -0
  79. package/dist/chat/runtime.js.map +1 -0
  80. package/dist/chat/server.cjs +643 -0
  81. package/dist/chat/server.cjs.map +1 -0
  82. package/dist/chat/server.d.cts +287 -0
  83. package/dist/chat/server.d.ts +287 -0
  84. package/dist/chat/server.js +617 -0
  85. package/dist/chat/server.js.map +1 -0
  86. package/dist/chat/sessions.cjs +398 -0
  87. package/dist/chat/sessions.cjs.map +1 -0
  88. package/dist/chat/sessions.d.cts +239 -0
  89. package/dist/chat/sessions.d.ts +239 -0
  90. package/dist/chat/sessions.js +394 -0
  91. package/dist/chat/sessions.js.map +1 -0
  92. package/dist/chat/state.cjs +177 -0
  93. package/dist/chat/state.cjs.map +1 -0
  94. package/dist/chat/state.d.cts +92 -0
  95. package/dist/chat/state.d.ts +92 -0
  96. package/dist/chat/state.js +167 -0
  97. package/dist/chat/state.js.map +1 -0
  98. package/dist/chat/storage.cjs +240 -0
  99. package/dist/chat/storage.cjs.map +1 -0
  100. package/dist/chat/storage.d.cts +191 -0
  101. package/dist/chat/storage.d.ts +191 -0
  102. package/dist/chat/storage.js +236 -0
  103. package/dist/chat/storage.js.map +1 -0
  104. package/dist/errors-BDLbNu9w.d.cts +13 -0
  105. package/dist/errors-BDLbNu9w.d.ts +13 -0
  106. package/dist/in-process-transport-C2oPTYs6.d.ts +223 -0
  107. package/dist/in-process-transport-DG-w5G6k.d.cts +223 -0
  108. package/dist/index.cjs +25 -13
  109. package/dist/index.cjs.map +1 -1
  110. package/dist/index.d.cts +32 -4
  111. package/dist/index.d.ts +32 -4
  112. package/dist/index.js +25 -13
  113. package/dist/index.js.map +1 -1
  114. package/dist/transport-D1OaUgRk.d.ts +67 -0
  115. package/dist/transport-DX1Nhm4N.d.cts +67 -0
  116. package/dist/types-Bh5AhqD-.d.ts +141 -0
  117. package/dist/types-CGF7AEX1.d.cts +141 -0
  118. package/dist/{types-BvwNzZCj.d.cts → types-CqvUAYxt.d.cts} +21 -3
  119. package/dist/{types-BvwNzZCj.d.ts → types-CqvUAYxt.d.ts} +21 -3
  120. package/dist/types-DLZzlJxt.d.ts +39 -0
  121. package/dist/types-tE0CXwBl.d.cts +39 -0
  122. package/package.json +149 -2
@@ -0,0 +1,52 @@
1
+ export { ChatEvent, ChatEventType, ChatId, ChatIdLike, ChatMessage, ChatMessageMetadata, ChatMessageStatus, ChatMiddleware, ChatMiddlewareContext, ChatRole, ChatSession, ChatSessionConfig, FilePart, IChatProvider, MessagePart, MessageStatus, PartStatus, ReasoningPart, RuntimeStatus, SendMessageOptions, SessionInfo, SessionStatus, SourcePart, TextPart, ToolCallPart, ToolCallStatus, adaptAgentEvents, agentEventToChatEvent, createChatId, fromAgentMessage, getMessageReasoning, getMessageText, getMessageToolCalls, isChatEvent, isChatMessage, isChatSession, isFilePart, isMessagePart, isReasoningPart, isSourcePart, isTextPart, isToolCallPart, toAgentMessage, toChatId } from './core.cjs';
2
+ export { BackendAdapterFactory, ChatRuntimeOptions, IChatRuntime, RetryConfig, createChatRuntime } from './runtime.cjs';
3
+ export { CreateSessionOptions, FileSessionStore, IChatSessionStore, InMemorySessionStore, PaginatedMessages } from './sessions.cjs';
4
+ export { ChatError, ChatErrorCode, ChatError as ChatSDKError, ExponentialBackoffStrategy, classifyError, isRetryable, withRetry } from './errors.cjs';
5
+ export { B as BackendAdapterOptions, I as IBackendAdapter } from '../types-tE0CXwBl.cjs';
6
+ export { B as BaseBackendAdapter, C as ClaudeChatAdapter, a as CopilotChatAdapter, I as InProcessChatTransport, V as VercelAIChatAdapter, W as WsChatTransport } from '../in-process-transport-DG-w5G6k.cjs';
7
+ export { I as IChatTransport, S as SSEChatTransport, s as streamToTransport } from '../transport-DX1Nhm4N.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
+ import '../types-CqvUAYxt.cjs';
12
+ import 'zod';
13
+ import './storage.cjs';
14
+ import '../errors-BDLbNu9w.cjs';
15
+
16
+ /**
17
+ * @witqq/agent-sdk - Stream Watchdog
18
+ *
19
+ * Activity-based timeout wrapper for async event streams.
20
+ * Aborts the stream if no events arrive within a configurable inactivity window.
21
+ * Timer resets on each received event.
22
+ */
23
+ /** Stream watchdog configuration */
24
+ interface StreamWatchdogConfig {
25
+ /** Maximum inactivity time in milliseconds before aborting the stream */
26
+ timeoutMs: number;
27
+ /** AbortSignal to link with (watchdog aborts when this signal fires) */
28
+ signal?: AbortSignal;
29
+ }
30
+ /**
31
+ * Wraps an async iterable with an activity timeout.
32
+ * If no event arrives within `timeoutMs`, the stream is aborted with a ChatError.
33
+ * The timer resets after each received event.
34
+ *
35
+ * Uses Promise.race() so even if the source iterator is stuck on an
36
+ * unresolvable promise, the timeout fires and aborts iteration.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const watched = withStreamWatchdog(adapter.streamMessage(session, msg), {
41
+ * timeoutMs: 30000,
42
+ * signal: abortController.signal,
43
+ * });
44
+ *
45
+ * for await (const event of watched) {
46
+ * // Each event resets the 30s inactivity timer
47
+ * }
48
+ * ```
49
+ */
50
+ declare function withStreamWatchdog<T>(source: AsyncIterable<T>, config: StreamWatchdogConfig): AsyncGenerator<T>;
51
+
52
+ export { type StreamWatchdogConfig, withStreamWatchdog };
@@ -0,0 +1,52 @@
1
+ export { ChatEvent, ChatEventType, ChatId, ChatIdLike, ChatMessage, ChatMessageMetadata, ChatMessageStatus, ChatMiddleware, ChatMiddlewareContext, ChatRole, ChatSession, ChatSessionConfig, FilePart, IChatProvider, MessagePart, MessageStatus, PartStatus, ReasoningPart, RuntimeStatus, SendMessageOptions, SessionInfo, SessionStatus, SourcePart, TextPart, ToolCallPart, ToolCallStatus, adaptAgentEvents, agentEventToChatEvent, createChatId, fromAgentMessage, getMessageReasoning, getMessageText, getMessageToolCalls, isChatEvent, isChatMessage, isChatSession, isFilePart, isMessagePart, isReasoningPart, isSourcePart, isTextPart, isToolCallPart, toAgentMessage, toChatId } from './core.js';
2
+ export { BackendAdapterFactory, ChatRuntimeOptions, IChatRuntime, RetryConfig, createChatRuntime } from './runtime.js';
3
+ export { CreateSessionOptions, FileSessionStore, IChatSessionStore, InMemorySessionStore, PaginatedMessages } from './sessions.js';
4
+ export { ChatError, ChatErrorCode, ChatError as ChatSDKError, ExponentialBackoffStrategy, classifyError, isRetryable, withRetry } from './errors.js';
5
+ export { B as BackendAdapterOptions, I as IBackendAdapter } from '../types-DLZzlJxt.js';
6
+ export { B as BaseBackendAdapter, C as ClaudeChatAdapter, a as CopilotChatAdapter, I as InProcessChatTransport, V as VercelAIChatAdapter, W as WsChatTransport } from '../in-process-transport-C2oPTYs6.js';
7
+ export { I as IChatTransport, S as SSEChatTransport, s as streamToTransport } from '../transport-D1OaUgRk.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
+ import '../types-CqvUAYxt.js';
12
+ import 'zod';
13
+ import './storage.js';
14
+ import '../errors-BDLbNu9w.js';
15
+
16
+ /**
17
+ * @witqq/agent-sdk - Stream Watchdog
18
+ *
19
+ * Activity-based timeout wrapper for async event streams.
20
+ * Aborts the stream if no events arrive within a configurable inactivity window.
21
+ * Timer resets on each received event.
22
+ */
23
+ /** Stream watchdog configuration */
24
+ interface StreamWatchdogConfig {
25
+ /** Maximum inactivity time in milliseconds before aborting the stream */
26
+ timeoutMs: number;
27
+ /** AbortSignal to link with (watchdog aborts when this signal fires) */
28
+ signal?: AbortSignal;
29
+ }
30
+ /**
31
+ * Wraps an async iterable with an activity timeout.
32
+ * If no event arrives within `timeoutMs`, the stream is aborted with a ChatError.
33
+ * The timer resets after each received event.
34
+ *
35
+ * Uses Promise.race() so even if the source iterator is stuck on an
36
+ * unresolvable promise, the timeout fires and aborts iteration.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const watched = withStreamWatchdog(adapter.streamMessage(session, msg), {
41
+ * timeoutMs: 30000,
42
+ * signal: abortController.signal,
43
+ * });
44
+ *
45
+ * for await (const event of watched) {
46
+ * // Each event resets the 30s inactivity timer
47
+ * }
48
+ * ```
49
+ */
50
+ declare function withStreamWatchdog<T>(source: AsyncIterable<T>, config: StreamWatchdogConfig): AsyncGenerator<T>;
51
+
52
+ export { type StreamWatchdogConfig, withStreamWatchdog };