@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.
- package/README.md +539 -6
- package/dist/{types-BvwNzZCj.d.cts → agent-CW9XbmG_.d.ts} +148 -95
- package/dist/{types-BvwNzZCj.d.ts → agent-DxY68NZL.d.cts} +148 -95
- package/dist/auth/index.cjs +260 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +21 -138
- package/dist/auth/index.d.ts +21 -138
- package/dist/auth/index.js +260 -3
- package/dist/auth/index.js.map +1 -1
- package/dist/backends/claude.cjs +653 -140
- package/dist/backends/claude.cjs.map +1 -1
- package/dist/backends/claude.d.cts +4 -1
- package/dist/backends/claude.d.ts +4 -1
- package/dist/backends/claude.js +653 -140
- package/dist/backends/claude.js.map +1 -1
- package/dist/backends/copilot.cjs +428 -88
- package/dist/backends/copilot.cjs.map +1 -1
- package/dist/backends/copilot.d.cts +13 -4
- package/dist/backends/copilot.d.ts +13 -4
- package/dist/backends/copilot.js +428 -88
- package/dist/backends/copilot.js.map +1 -1
- package/dist/backends/vercel-ai.cjs +349 -77
- package/dist/backends/vercel-ai.cjs.map +1 -1
- package/dist/backends/vercel-ai.d.cts +3 -1
- package/dist/backends/vercel-ai.d.ts +3 -1
- package/dist/backends/vercel-ai.js +349 -77
- package/dist/backends/vercel-ai.js.map +1 -1
- package/dist/backends-BSrsBYFn.d.cts +39 -0
- package/dist/backends-BSrsBYFn.d.ts +39 -0
- package/dist/chat/accumulator.cjs +147 -0
- package/dist/chat/accumulator.cjs.map +1 -0
- package/dist/chat/accumulator.d.cts +64 -0
- package/dist/chat/accumulator.d.ts +64 -0
- package/dist/chat/accumulator.js +145 -0
- package/dist/chat/accumulator.js.map +1 -0
- package/dist/chat/backends.cjs +3524 -0
- package/dist/chat/backends.cjs.map +1 -0
- package/dist/chat/backends.d.cts +66 -0
- package/dist/chat/backends.d.ts +66 -0
- package/dist/chat/backends.js +3512 -0
- package/dist/chat/backends.js.map +1 -0
- package/dist/chat/context.cjs +280 -0
- package/dist/chat/context.cjs.map +1 -0
- package/dist/chat/context.d.cts +191 -0
- package/dist/chat/context.d.ts +191 -0
- package/dist/chat/context.js +277 -0
- package/dist/chat/context.js.map +1 -0
- package/dist/chat/core.cjs +305 -0
- package/dist/chat/core.cjs.map +1 -0
- package/dist/chat/core.d.cts +84 -0
- package/dist/chat/core.d.ts +84 -0
- package/dist/chat/core.js +282 -0
- package/dist/chat/core.js.map +1 -0
- package/dist/chat/errors.cjs +273 -0
- package/dist/chat/errors.cjs.map +1 -0
- package/dist/chat/errors.d.cts +97 -0
- package/dist/chat/errors.d.ts +97 -0
- package/dist/chat/errors.js +266 -0
- package/dist/chat/errors.js.map +1 -0
- package/dist/chat/events.cjs +203 -0
- package/dist/chat/events.cjs.map +1 -0
- package/dist/chat/events.d.cts +245 -0
- package/dist/chat/events.d.ts +245 -0
- package/dist/chat/events.js +196 -0
- package/dist/chat/events.js.map +1 -0
- package/dist/chat/index.cjs +5550 -0
- package/dist/chat/index.cjs.map +1 -0
- package/dist/chat/index.d.cts +77 -0
- package/dist/chat/index.d.ts +77 -0
- package/dist/chat/index.js +5505 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/react/theme.css +2517 -0
- package/dist/chat/react.cjs +3589 -0
- package/dist/chat/react.cjs.map +1 -0
- package/dist/chat/react.d.cts +1088 -0
- package/dist/chat/react.d.ts +1088 -0
- package/dist/chat/react.js +3547 -0
- package/dist/chat/react.js.map +1 -0
- package/dist/chat/runtime.cjs +1245 -0
- package/dist/chat/runtime.cjs.map +1 -0
- package/dist/chat/runtime.d.cts +182 -0
- package/dist/chat/runtime.d.ts +182 -0
- package/dist/chat/runtime.js +1243 -0
- package/dist/chat/runtime.js.map +1 -0
- package/dist/chat/server.cjs +2668 -0
- package/dist/chat/server.cjs.map +1 -0
- package/dist/chat/server.d.cts +648 -0
- package/dist/chat/server.d.ts +648 -0
- package/dist/chat/server.js +2628 -0
- package/dist/chat/server.js.map +1 -0
- package/dist/chat/sessions.cjs +380 -0
- package/dist/chat/sessions.cjs.map +1 -0
- package/dist/chat/sessions.d.cts +158 -0
- package/dist/chat/sessions.d.ts +158 -0
- package/dist/chat/sessions.js +376 -0
- package/dist/chat/sessions.js.map +1 -0
- package/dist/chat/sqlite.cjs +441 -0
- package/dist/chat/sqlite.cjs.map +1 -0
- package/dist/chat/sqlite.d.cts +128 -0
- package/dist/chat/sqlite.d.ts +128 -0
- package/dist/chat/sqlite.js +435 -0
- package/dist/chat/sqlite.js.map +1 -0
- package/dist/chat/state.cjs +190 -0
- package/dist/chat/state.cjs.map +1 -0
- package/dist/chat/state.d.cts +95 -0
- package/dist/chat/state.d.ts +95 -0
- package/dist/chat/state.js +180 -0
- package/dist/chat/state.js.map +1 -0
- package/dist/chat/storage.cjs +249 -0
- package/dist/chat/storage.cjs.map +1 -0
- package/dist/chat/storage.d.cts +197 -0
- package/dist/chat/storage.d.ts +197 -0
- package/dist/chat/storage.js +245 -0
- package/dist/chat/storage.js.map +1 -0
- package/dist/errors-C-so0M4t.d.cts +33 -0
- package/dist/errors-C-so0M4t.d.ts +33 -0
- package/dist/errors-CmVvczxZ.d.cts +28 -0
- package/dist/errors-CmVvczxZ.d.ts +28 -0
- package/dist/in-process-transport-C1JnJGVR.d.ts +228 -0
- package/dist/in-process-transport-C7DSqPyX.d.cts +228 -0
- package/dist/index.cjs +365 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +322 -125
- package/dist/index.d.ts +322 -125
- package/dist/index.js +359 -60
- package/dist/index.js.map +1 -1
- package/dist/provider-types-PTSlRPNB.d.cts +39 -0
- package/dist/provider-types-PTSlRPNB.d.ts +39 -0
- package/dist/refresh-manager-B81PpYBr.d.cts +153 -0
- package/dist/refresh-manager-Dlv_iNZi.d.ts +153 -0
- package/dist/testing.cjs +383 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +132 -0
- package/dist/testing.d.ts +132 -0
- package/dist/testing.js +377 -0
- package/dist/testing.js.map +1 -0
- package/dist/token-store-CSUBgYwn.d.ts +48 -0
- package/dist/token-store-CuC4hB9Z.d.cts +48 -0
- package/dist/transport-Cdh3M0tS.d.cts +68 -0
- package/dist/transport-Ciap4PWK.d.ts +68 -0
- package/dist/types-4vbcmPTp.d.cts +143 -0
- package/dist/types-BxggH0Yh.d.ts +143 -0
- package/dist/types-DRgd_9R7.d.cts +363 -0
- package/dist/types-ajANVzf7.d.ts +363 -0
- package/package.json +178 -6
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Unified error codes for all SDK errors — single source of truth. */
|
|
2
|
+
declare enum ErrorCode {
|
|
3
|
+
AUTH_EXPIRED = "AUTH_EXPIRED",
|
|
4
|
+
AUTH_INVALID = "AUTH_INVALID",
|
|
5
|
+
RATE_LIMIT = "RATE_LIMIT",
|
|
6
|
+
NETWORK = "NETWORK",
|
|
7
|
+
TIMEOUT = "TIMEOUT",
|
|
8
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
9
|
+
MODEL_NOT_FOUND = "MODEL_NOT_FOUND",
|
|
10
|
+
MODEL_OVERLOADED = "MODEL_OVERLOADED",
|
|
11
|
+
CONTEXT_OVERFLOW = "CONTEXT_OVERFLOW",
|
|
12
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
13
|
+
INVALID_RESPONSE = "INVALID_RESPONSE",
|
|
14
|
+
REENTRANCY = "REENTRANCY",
|
|
15
|
+
DISPOSED = "DISPOSED",
|
|
16
|
+
ABORTED = "ABORTED",
|
|
17
|
+
INVALID_TRANSITION = "INVALID_TRANSITION",
|
|
18
|
+
DEPENDENCY_MISSING = "DEPENDENCY_MISSING",
|
|
19
|
+
BACKEND_NOT_INSTALLED = "BACKEND_NOT_INSTALLED",
|
|
20
|
+
TOOL_EXECUTION = "TOOL_EXECUTION",
|
|
21
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
22
|
+
SESSION_NOT_FOUND = "SESSION_NOT_FOUND",
|
|
23
|
+
SESSION_EXPIRED = "SESSION_EXPIRED",
|
|
24
|
+
PROVIDER_NOT_FOUND = "PROVIDER_NOT_FOUND",
|
|
25
|
+
AUTH_REQUIRED = "AUTH_REQUIRED",
|
|
26
|
+
STORAGE_ERROR = "STORAGE_ERROR",
|
|
27
|
+
STORAGE_NOT_FOUND = "STORAGE_NOT_FOUND",
|
|
28
|
+
STORAGE_DUPLICATE_KEY = "STORAGE_DUPLICATE_KEY",
|
|
29
|
+
STORAGE_IO_ERROR = "STORAGE_IO_ERROR",
|
|
30
|
+
STORAGE_SERIALIZATION_ERROR = "STORAGE_SERIALIZATION_ERROR"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { ErrorCode as E };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Unified error codes for all SDK errors — single source of truth. */
|
|
2
|
+
declare enum ErrorCode {
|
|
3
|
+
AUTH_EXPIRED = "AUTH_EXPIRED",
|
|
4
|
+
AUTH_INVALID = "AUTH_INVALID",
|
|
5
|
+
RATE_LIMIT = "RATE_LIMIT",
|
|
6
|
+
NETWORK = "NETWORK",
|
|
7
|
+
TIMEOUT = "TIMEOUT",
|
|
8
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
9
|
+
MODEL_NOT_FOUND = "MODEL_NOT_FOUND",
|
|
10
|
+
MODEL_OVERLOADED = "MODEL_OVERLOADED",
|
|
11
|
+
CONTEXT_OVERFLOW = "CONTEXT_OVERFLOW",
|
|
12
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
13
|
+
INVALID_RESPONSE = "INVALID_RESPONSE",
|
|
14
|
+
REENTRANCY = "REENTRANCY",
|
|
15
|
+
DISPOSED = "DISPOSED",
|
|
16
|
+
ABORTED = "ABORTED",
|
|
17
|
+
INVALID_TRANSITION = "INVALID_TRANSITION",
|
|
18
|
+
DEPENDENCY_MISSING = "DEPENDENCY_MISSING",
|
|
19
|
+
BACKEND_NOT_INSTALLED = "BACKEND_NOT_INSTALLED",
|
|
20
|
+
TOOL_EXECUTION = "TOOL_EXECUTION",
|
|
21
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
22
|
+
SESSION_NOT_FOUND = "SESSION_NOT_FOUND",
|
|
23
|
+
SESSION_EXPIRED = "SESSION_EXPIRED",
|
|
24
|
+
PROVIDER_NOT_FOUND = "PROVIDER_NOT_FOUND",
|
|
25
|
+
AUTH_REQUIRED = "AUTH_REQUIRED",
|
|
26
|
+
STORAGE_ERROR = "STORAGE_ERROR",
|
|
27
|
+
STORAGE_NOT_FOUND = "STORAGE_NOT_FOUND",
|
|
28
|
+
STORAGE_DUPLICATE_KEY = "STORAGE_DUPLICATE_KEY",
|
|
29
|
+
STORAGE_IO_ERROR = "STORAGE_IO_ERROR",
|
|
30
|
+
STORAGE_SERIALIZATION_ERROR = "STORAGE_SERIALIZATION_ERROR"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { ErrorCode as E };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Options for constructing an AgentSDKError */
|
|
2
|
+
interface AgentSDKErrorOptions extends ErrorOptions {
|
|
3
|
+
/** Machine-readable error code */
|
|
4
|
+
code?: string;
|
|
5
|
+
/** Whether this error is retryable (default: false) */
|
|
6
|
+
retryable?: boolean;
|
|
7
|
+
/** HTTP status code hint (e.g. 401, 429, 500) */
|
|
8
|
+
httpStatus?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Base error class for agent-sdk.
|
|
11
|
+
*
|
|
12
|
+
* Use `AgentSDKError.is(err)` for reliable cross-module `instanceof` checks
|
|
13
|
+
* (works across separately bundled entry points where `instanceof` may fail). */
|
|
14
|
+
declare class AgentSDKError extends Error {
|
|
15
|
+
/** @internal Marker for cross-bundle identity checks */
|
|
16
|
+
readonly _agentSDKError: true;
|
|
17
|
+
/** Machine-readable error code. Prefer values from the ErrorCode enum. */
|
|
18
|
+
readonly code?: string;
|
|
19
|
+
/** Whether this error is safe to retry */
|
|
20
|
+
readonly retryable: boolean;
|
|
21
|
+
/** HTTP status code hint for error classification */
|
|
22
|
+
readonly httpStatus?: number;
|
|
23
|
+
constructor(message: string, options?: AgentSDKErrorOptions);
|
|
24
|
+
/** Check if an error is an AgentSDKError (works across bundled copies) */
|
|
25
|
+
static is(error: unknown): error is AgentSDKError;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { AgentSDKError as A };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Options for constructing an AgentSDKError */
|
|
2
|
+
interface AgentSDKErrorOptions extends ErrorOptions {
|
|
3
|
+
/** Machine-readable error code */
|
|
4
|
+
code?: string;
|
|
5
|
+
/** Whether this error is retryable (default: false) */
|
|
6
|
+
retryable?: boolean;
|
|
7
|
+
/** HTTP status code hint (e.g. 401, 429, 500) */
|
|
8
|
+
httpStatus?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Base error class for agent-sdk.
|
|
11
|
+
*
|
|
12
|
+
* Use `AgentSDKError.is(err)` for reliable cross-module `instanceof` checks
|
|
13
|
+
* (works across separately bundled entry points where `instanceof` may fail). */
|
|
14
|
+
declare class AgentSDKError extends Error {
|
|
15
|
+
/** @internal Marker for cross-bundle identity checks */
|
|
16
|
+
readonly _agentSDKError: true;
|
|
17
|
+
/** Machine-readable error code. Prefer values from the ErrorCode enum. */
|
|
18
|
+
readonly code?: string;
|
|
19
|
+
/** Whether this error is safe to retry */
|
|
20
|
+
readonly retryable: boolean;
|
|
21
|
+
/** HTTP status code hint for error classification */
|
|
22
|
+
readonly httpStatus?: number;
|
|
23
|
+
constructor(message: string, options?: AgentSDKErrorOptions);
|
|
24
|
+
/** Check if an error is an AgentSDKError (works across bundled copies) */
|
|
25
|
+
static is(error: unknown): error is AgentSDKError;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { AgentSDKError as A };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { I as IChatBackend, B as BackendAdapterOptions, g as ChatSession, S as SendMessageOptions, c as ChatMessage, a as ChatEvent, d as IResumableBackend } from './types-ajANVzf7.js';
|
|
2
|
+
import { F as FullAgentConfig, I as IAgentService, c as IAgent, d as Message, M as ModelInfo } from './agent-CW9XbmG_.js';
|
|
3
|
+
import { C as CopilotBackendOptions, a as ClaudeBackendOptions, V as VercelAIBackendOptions } from './backends-BSrsBYFn.js';
|
|
4
|
+
import { I as IChatTransport } from './transport-Ciap4PWK.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @witqq/agent-sdk/chat/backends/base
|
|
8
|
+
*
|
|
9
|
+
* Abstract base class for backend adapters. Provides shared lifecycle
|
|
10
|
+
* management, event bridge via adaptAgentEvents(), and tool forwarding.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Abstract base for backend adapters implementing IChatBackend (core only).
|
|
15
|
+
* Subclasses implement createService() for backend-specific service creation.
|
|
16
|
+
* Resume support is NOT required — subclasses can implement IResumableBackend separately.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class BaseBackendAdapter implements IChatBackend {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
private _agentService;
|
|
21
|
+
private _agentServiceFactory;
|
|
22
|
+
private _disposed;
|
|
23
|
+
protected readonly _agentConfig: FullAgentConfig;
|
|
24
|
+
private _ownsService;
|
|
25
|
+
private _currentAgent;
|
|
26
|
+
constructor(name: string, options: BackendAdapterOptions);
|
|
27
|
+
/** Subclasses create their specific IAgentService */
|
|
28
|
+
protected abstract createService(): IAgentService;
|
|
29
|
+
get agentService(): IAgentService;
|
|
30
|
+
get currentModel(): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated No-op. Tools are passed per-call via SendMessageOptions.tools.
|
|
33
|
+
* Kept for backward compatibility with code that calls setTools() directly.
|
|
34
|
+
*/
|
|
35
|
+
setTools(): void;
|
|
36
|
+
sendMessage(session: ChatSession, message: string, options?: SendMessageOptions): Promise<ChatMessage>;
|
|
37
|
+
streamMessage(session: ChatSession, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
38
|
+
/**
|
|
39
|
+
* Shared streaming helper: bridges agent events to chat events.
|
|
40
|
+
* Used by both streamMessage() and resume() to avoid duplication.
|
|
41
|
+
*/
|
|
42
|
+
protected streamAgentEvents(agent: IAgent, messages: Message[], options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
43
|
+
listModels(): Promise<ModelInfo[]>;
|
|
44
|
+
validate(): Promise<{
|
|
45
|
+
valid: boolean;
|
|
46
|
+
errors: string[];
|
|
47
|
+
}>;
|
|
48
|
+
dispose(): Promise<void>;
|
|
49
|
+
/** Get or create an agent. Model is passed per-call via RunOptions.
|
|
50
|
+
* Tools are passed per-call via SendMessageOptions — not baked into config.
|
|
51
|
+
* For persistent sessions, reuses agent when model matches. */
|
|
52
|
+
protected getOrCreateAgent(options?: SendMessageOptions): IAgent;
|
|
53
|
+
/** Subclasses capture backend session ID from agent after streaming */
|
|
54
|
+
protected abstract captureSessionId(agent: IAgent): void;
|
|
55
|
+
protected assertNotDisposed(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @witqq/agent-sdk/chat/backends/copilot
|
|
60
|
+
*
|
|
61
|
+
* CopilotChatAdapter wraps CopilotAgentService for chat use.
|
|
62
|
+
* Supports persistent session mode for canResume/resume.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/** Options for creating a CopilotChatAdapter */
|
|
66
|
+
interface CopilotChatAdapterOptions extends BackendAdapterOptions {
|
|
67
|
+
/** Copilot backend options (cliPath, token, etc.) */
|
|
68
|
+
copilotOptions?: CopilotBackendOptions;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Backend adapter for GitHub Copilot CLI.
|
|
72
|
+
* Uses persistent session mode for session resume via CLI session ID.
|
|
73
|
+
*/
|
|
74
|
+
declare class CopilotChatAdapter extends BaseBackendAdapter implements IResumableBackend {
|
|
75
|
+
private _backendSessionId;
|
|
76
|
+
private readonly _copilotOptions?;
|
|
77
|
+
constructor(options: CopilotChatAdapterOptions);
|
|
78
|
+
protected createService(): IAgentService;
|
|
79
|
+
get backendSessionId(): string | null;
|
|
80
|
+
canResume(): boolean;
|
|
81
|
+
resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
82
|
+
protected captureSessionId(agent: IAgent): void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @witqq/agent-sdk/chat/backends/claude
|
|
87
|
+
*
|
|
88
|
+
* ClaudeChatAdapter wraps ClaudeAgentService for chat use.
|
|
89
|
+
* Supports persistent session mode with Claude's session_id for resume.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/** Options for creating a ClaudeChatAdapter */
|
|
93
|
+
interface ClaudeChatAdapterOptions extends BackendAdapterOptions {
|
|
94
|
+
/** Claude backend options (cliPath, model, etc.) */
|
|
95
|
+
claudeOptions?: ClaudeBackendOptions;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Backend adapter for Claude CLI.
|
|
99
|
+
* Uses persistent session mode for session resume via Claude's session_id.
|
|
100
|
+
*/
|
|
101
|
+
declare class ClaudeChatAdapter extends BaseBackendAdapter implements IResumableBackend {
|
|
102
|
+
private _backendSessionId;
|
|
103
|
+
private readonly _claudeOptions?;
|
|
104
|
+
constructor(options: ClaudeChatAdapterOptions);
|
|
105
|
+
protected createService(): IAgentService;
|
|
106
|
+
get backendSessionId(): string | null;
|
|
107
|
+
canResume(): boolean;
|
|
108
|
+
resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
109
|
+
protected captureSessionId(agent: IAgent): void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @witqq/agent-sdk/chat/backends/vercel-ai
|
|
114
|
+
*
|
|
115
|
+
* VercelAIChatAdapter wraps VercelAIAgentService for chat use.
|
|
116
|
+
* Stateless adapter — implements IChatBackend only (no resume support).
|
|
117
|
+
* Each streamMessage/sendMessage creates a fresh agent (per-call session mode).
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/** Options for creating a VercelAIChatAdapter */
|
|
121
|
+
interface VercelAIChatAdapterOptions extends BackendAdapterOptions {
|
|
122
|
+
/** Vercel AI backend options (baseURL, apiKey, provider, etc.) */
|
|
123
|
+
vercelOptions?: VercelAIBackendOptions;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Backend adapter for Vercel AI SDK (API-based).
|
|
127
|
+
* Stateless — each call creates a fresh agent. Does not support resume.
|
|
128
|
+
* Implements IChatBackend only (no IResumableBackend).
|
|
129
|
+
*/
|
|
130
|
+
declare class VercelAIChatAdapter extends BaseBackendAdapter {
|
|
131
|
+
private readonly _vercelOptions?;
|
|
132
|
+
constructor(options: VercelAIChatAdapterOptions);
|
|
133
|
+
protected createService(): IAgentService;
|
|
134
|
+
protected captureSessionId(_agent: IAgent): void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @witqq/agent-sdk - WebSocket Chat Transport
|
|
139
|
+
*
|
|
140
|
+
* IChatTransport implementation over WebSocket connections.
|
|
141
|
+
* Accepts a WebSocket-like abstraction compatible with `ws`, native WebSocket, etc.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
/** Ready states matching the WebSocket spec (ws, browser, Deno, Bun) */
|
|
145
|
+
declare const WS_READY_STATE: {
|
|
146
|
+
readonly CONNECTING: 0;
|
|
147
|
+
readonly OPEN: 1;
|
|
148
|
+
readonly CLOSING: 2;
|
|
149
|
+
readonly CLOSED: 3;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Minimal WebSocket interface compatible with `ws`, browser WebSocket, Deno, Bun.
|
|
153
|
+
* Only the methods/properties used by WsChatTransport.
|
|
154
|
+
*/
|
|
155
|
+
interface WebSocketLike {
|
|
156
|
+
readonly readyState: number;
|
|
157
|
+
send(data: string): void;
|
|
158
|
+
close(code?: number, reason?: string): void;
|
|
159
|
+
addEventListener(type: "close", listener: () => void): void;
|
|
160
|
+
addEventListener(type: "error", listener: (err: unknown) => void): void;
|
|
161
|
+
}
|
|
162
|
+
/** Configuration options for WsChatTransport */
|
|
163
|
+
interface WsTransportOptions {
|
|
164
|
+
/** Heartbeat interval in ms. 0 or undefined disables heartbeat. */
|
|
165
|
+
heartbeatMs?: number;
|
|
166
|
+
/** Custom JSON serializer (defaults to JSON.stringify) */
|
|
167
|
+
serialize?: (event: ChatEvent) => string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* WebSocket transport for ChatEvent streaming.
|
|
171
|
+
* Sends events as JSON messages over a WebSocket connection.
|
|
172
|
+
*/
|
|
173
|
+
declare class WsChatTransport implements IChatTransport {
|
|
174
|
+
private readonly ws;
|
|
175
|
+
private readonly serialize;
|
|
176
|
+
private _open;
|
|
177
|
+
private _heartbeatTimer;
|
|
178
|
+
constructor(ws: WebSocketLike, options?: WsTransportOptions);
|
|
179
|
+
get isOpen(): boolean;
|
|
180
|
+
send(event: ChatEvent): void;
|
|
181
|
+
close(): void;
|
|
182
|
+
error(err: Error): void;
|
|
183
|
+
private _cleanup;
|
|
184
|
+
private _clearHeartbeat;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @witqq/agent-sdk - In-Process Chat Transport
|
|
189
|
+
*
|
|
190
|
+
* IChatTransport implementation for zero-network communication.
|
|
191
|
+
* Events are pushed into an internal buffer and consumed via async iteration.
|
|
192
|
+
* Useful for testing, embedded runtimes, CLI tools, and in-process communication.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* In-process transport for ChatEvent streaming.
|
|
197
|
+
* Producer pushes events via IChatTransport.send(), consumer reads via async iteration.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const transport = new InProcessChatTransport();
|
|
202
|
+
*
|
|
203
|
+
* // Consumer side (async iteration)
|
|
204
|
+
* (async () => {
|
|
205
|
+
* for await (const event of transport) {
|
|
206
|
+
* console.log("Received:", event);
|
|
207
|
+
* }
|
|
208
|
+
* })();
|
|
209
|
+
*
|
|
210
|
+
* // Producer side (via streamToTransport or manual)
|
|
211
|
+
* transport.send({ type: "message:start", messageId, role: "assistant" });
|
|
212
|
+
* transport.send({ type: "message:delta", messageId, text: "Hello" });
|
|
213
|
+
* transport.close();
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class InProcessChatTransport implements IChatTransport {
|
|
217
|
+
private _open;
|
|
218
|
+
private _buffer;
|
|
219
|
+
private _resolve;
|
|
220
|
+
private _error;
|
|
221
|
+
get isOpen(): boolean;
|
|
222
|
+
send(event: ChatEvent): void;
|
|
223
|
+
close(): void;
|
|
224
|
+
error(err: Error): void;
|
|
225
|
+
[Symbol.asyncIterator](): AsyncIterator<ChatEvent>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { BaseBackendAdapter as B, ClaudeChatAdapter as C, InProcessChatTransport as I, VercelAIChatAdapter as V, WS_READY_STATE as W, type ClaudeChatAdapterOptions as a, CopilotChatAdapter as b, type CopilotChatAdapterOptions as c, type VercelAIChatAdapterOptions as d, type WebSocketLike as e, WsChatTransport as f, type WsTransportOptions as g };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { I as IChatBackend, B as BackendAdapterOptions, g as ChatSession, S as SendMessageOptions, c as ChatMessage, a as ChatEvent, d as IResumableBackend } from './types-DRgd_9R7.cjs';
|
|
2
|
+
import { F as FullAgentConfig, I as IAgentService, c as IAgent, d as Message, M as ModelInfo } from './agent-DxY68NZL.cjs';
|
|
3
|
+
import { C as CopilotBackendOptions, a as ClaudeBackendOptions, V as VercelAIBackendOptions } from './backends-BSrsBYFn.cjs';
|
|
4
|
+
import { I as IChatTransport } from './transport-Cdh3M0tS.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @witqq/agent-sdk/chat/backends/base
|
|
8
|
+
*
|
|
9
|
+
* Abstract base class for backend adapters. Provides shared lifecycle
|
|
10
|
+
* management, event bridge via adaptAgentEvents(), and tool forwarding.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Abstract base for backend adapters implementing IChatBackend (core only).
|
|
15
|
+
* Subclasses implement createService() for backend-specific service creation.
|
|
16
|
+
* Resume support is NOT required — subclasses can implement IResumableBackend separately.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class BaseBackendAdapter implements IChatBackend {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
private _agentService;
|
|
21
|
+
private _agentServiceFactory;
|
|
22
|
+
private _disposed;
|
|
23
|
+
protected readonly _agentConfig: FullAgentConfig;
|
|
24
|
+
private _ownsService;
|
|
25
|
+
private _currentAgent;
|
|
26
|
+
constructor(name: string, options: BackendAdapterOptions);
|
|
27
|
+
/** Subclasses create their specific IAgentService */
|
|
28
|
+
protected abstract createService(): IAgentService;
|
|
29
|
+
get agentService(): IAgentService;
|
|
30
|
+
get currentModel(): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated No-op. Tools are passed per-call via SendMessageOptions.tools.
|
|
33
|
+
* Kept for backward compatibility with code that calls setTools() directly.
|
|
34
|
+
*/
|
|
35
|
+
setTools(): void;
|
|
36
|
+
sendMessage(session: ChatSession, message: string, options?: SendMessageOptions): Promise<ChatMessage>;
|
|
37
|
+
streamMessage(session: ChatSession, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
38
|
+
/**
|
|
39
|
+
* Shared streaming helper: bridges agent events to chat events.
|
|
40
|
+
* Used by both streamMessage() and resume() to avoid duplication.
|
|
41
|
+
*/
|
|
42
|
+
protected streamAgentEvents(agent: IAgent, messages: Message[], options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
43
|
+
listModels(): Promise<ModelInfo[]>;
|
|
44
|
+
validate(): Promise<{
|
|
45
|
+
valid: boolean;
|
|
46
|
+
errors: string[];
|
|
47
|
+
}>;
|
|
48
|
+
dispose(): Promise<void>;
|
|
49
|
+
/** Get or create an agent. Model is passed per-call via RunOptions.
|
|
50
|
+
* Tools are passed per-call via SendMessageOptions — not baked into config.
|
|
51
|
+
* For persistent sessions, reuses agent when model matches. */
|
|
52
|
+
protected getOrCreateAgent(options?: SendMessageOptions): IAgent;
|
|
53
|
+
/** Subclasses capture backend session ID from agent after streaming */
|
|
54
|
+
protected abstract captureSessionId(agent: IAgent): void;
|
|
55
|
+
protected assertNotDisposed(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @witqq/agent-sdk/chat/backends/copilot
|
|
60
|
+
*
|
|
61
|
+
* CopilotChatAdapter wraps CopilotAgentService for chat use.
|
|
62
|
+
* Supports persistent session mode for canResume/resume.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/** Options for creating a CopilotChatAdapter */
|
|
66
|
+
interface CopilotChatAdapterOptions extends BackendAdapterOptions {
|
|
67
|
+
/** Copilot backend options (cliPath, token, etc.) */
|
|
68
|
+
copilotOptions?: CopilotBackendOptions;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Backend adapter for GitHub Copilot CLI.
|
|
72
|
+
* Uses persistent session mode for session resume via CLI session ID.
|
|
73
|
+
*/
|
|
74
|
+
declare class CopilotChatAdapter extends BaseBackendAdapter implements IResumableBackend {
|
|
75
|
+
private _backendSessionId;
|
|
76
|
+
private readonly _copilotOptions?;
|
|
77
|
+
constructor(options: CopilotChatAdapterOptions);
|
|
78
|
+
protected createService(): IAgentService;
|
|
79
|
+
get backendSessionId(): string | null;
|
|
80
|
+
canResume(): boolean;
|
|
81
|
+
resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
82
|
+
protected captureSessionId(agent: IAgent): void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @witqq/agent-sdk/chat/backends/claude
|
|
87
|
+
*
|
|
88
|
+
* ClaudeChatAdapter wraps ClaudeAgentService for chat use.
|
|
89
|
+
* Supports persistent session mode with Claude's session_id for resume.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/** Options for creating a ClaudeChatAdapter */
|
|
93
|
+
interface ClaudeChatAdapterOptions extends BackendAdapterOptions {
|
|
94
|
+
/** Claude backend options (cliPath, model, etc.) */
|
|
95
|
+
claudeOptions?: ClaudeBackendOptions;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Backend adapter for Claude CLI.
|
|
99
|
+
* Uses persistent session mode for session resume via Claude's session_id.
|
|
100
|
+
*/
|
|
101
|
+
declare class ClaudeChatAdapter extends BaseBackendAdapter implements IResumableBackend {
|
|
102
|
+
private _backendSessionId;
|
|
103
|
+
private readonly _claudeOptions?;
|
|
104
|
+
constructor(options: ClaudeChatAdapterOptions);
|
|
105
|
+
protected createService(): IAgentService;
|
|
106
|
+
get backendSessionId(): string | null;
|
|
107
|
+
canResume(): boolean;
|
|
108
|
+
resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
109
|
+
protected captureSessionId(agent: IAgent): void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @witqq/agent-sdk/chat/backends/vercel-ai
|
|
114
|
+
*
|
|
115
|
+
* VercelAIChatAdapter wraps VercelAIAgentService for chat use.
|
|
116
|
+
* Stateless adapter — implements IChatBackend only (no resume support).
|
|
117
|
+
* Each streamMessage/sendMessage creates a fresh agent (per-call session mode).
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/** Options for creating a VercelAIChatAdapter */
|
|
121
|
+
interface VercelAIChatAdapterOptions extends BackendAdapterOptions {
|
|
122
|
+
/** Vercel AI backend options (baseURL, apiKey, provider, etc.) */
|
|
123
|
+
vercelOptions?: VercelAIBackendOptions;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Backend adapter for Vercel AI SDK (API-based).
|
|
127
|
+
* Stateless — each call creates a fresh agent. Does not support resume.
|
|
128
|
+
* Implements IChatBackend only (no IResumableBackend).
|
|
129
|
+
*/
|
|
130
|
+
declare class VercelAIChatAdapter extends BaseBackendAdapter {
|
|
131
|
+
private readonly _vercelOptions?;
|
|
132
|
+
constructor(options: VercelAIChatAdapterOptions);
|
|
133
|
+
protected createService(): IAgentService;
|
|
134
|
+
protected captureSessionId(_agent: IAgent): void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @witqq/agent-sdk - WebSocket Chat Transport
|
|
139
|
+
*
|
|
140
|
+
* IChatTransport implementation over WebSocket connections.
|
|
141
|
+
* Accepts a WebSocket-like abstraction compatible with `ws`, native WebSocket, etc.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
/** Ready states matching the WebSocket spec (ws, browser, Deno, Bun) */
|
|
145
|
+
declare const WS_READY_STATE: {
|
|
146
|
+
readonly CONNECTING: 0;
|
|
147
|
+
readonly OPEN: 1;
|
|
148
|
+
readonly CLOSING: 2;
|
|
149
|
+
readonly CLOSED: 3;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Minimal WebSocket interface compatible with `ws`, browser WebSocket, Deno, Bun.
|
|
153
|
+
* Only the methods/properties used by WsChatTransport.
|
|
154
|
+
*/
|
|
155
|
+
interface WebSocketLike {
|
|
156
|
+
readonly readyState: number;
|
|
157
|
+
send(data: string): void;
|
|
158
|
+
close(code?: number, reason?: string): void;
|
|
159
|
+
addEventListener(type: "close", listener: () => void): void;
|
|
160
|
+
addEventListener(type: "error", listener: (err: unknown) => void): void;
|
|
161
|
+
}
|
|
162
|
+
/** Configuration options for WsChatTransport */
|
|
163
|
+
interface WsTransportOptions {
|
|
164
|
+
/** Heartbeat interval in ms. 0 or undefined disables heartbeat. */
|
|
165
|
+
heartbeatMs?: number;
|
|
166
|
+
/** Custom JSON serializer (defaults to JSON.stringify) */
|
|
167
|
+
serialize?: (event: ChatEvent) => string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* WebSocket transport for ChatEvent streaming.
|
|
171
|
+
* Sends events as JSON messages over a WebSocket connection.
|
|
172
|
+
*/
|
|
173
|
+
declare class WsChatTransport implements IChatTransport {
|
|
174
|
+
private readonly ws;
|
|
175
|
+
private readonly serialize;
|
|
176
|
+
private _open;
|
|
177
|
+
private _heartbeatTimer;
|
|
178
|
+
constructor(ws: WebSocketLike, options?: WsTransportOptions);
|
|
179
|
+
get isOpen(): boolean;
|
|
180
|
+
send(event: ChatEvent): void;
|
|
181
|
+
close(): void;
|
|
182
|
+
error(err: Error): void;
|
|
183
|
+
private _cleanup;
|
|
184
|
+
private _clearHeartbeat;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @witqq/agent-sdk - In-Process Chat Transport
|
|
189
|
+
*
|
|
190
|
+
* IChatTransport implementation for zero-network communication.
|
|
191
|
+
* Events are pushed into an internal buffer and consumed via async iteration.
|
|
192
|
+
* Useful for testing, embedded runtimes, CLI tools, and in-process communication.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* In-process transport for ChatEvent streaming.
|
|
197
|
+
* Producer pushes events via IChatTransport.send(), consumer reads via async iteration.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const transport = new InProcessChatTransport();
|
|
202
|
+
*
|
|
203
|
+
* // Consumer side (async iteration)
|
|
204
|
+
* (async () => {
|
|
205
|
+
* for await (const event of transport) {
|
|
206
|
+
* console.log("Received:", event);
|
|
207
|
+
* }
|
|
208
|
+
* })();
|
|
209
|
+
*
|
|
210
|
+
* // Producer side (via streamToTransport or manual)
|
|
211
|
+
* transport.send({ type: "message:start", messageId, role: "assistant" });
|
|
212
|
+
* transport.send({ type: "message:delta", messageId, text: "Hello" });
|
|
213
|
+
* transport.close();
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class InProcessChatTransport implements IChatTransport {
|
|
217
|
+
private _open;
|
|
218
|
+
private _buffer;
|
|
219
|
+
private _resolve;
|
|
220
|
+
private _error;
|
|
221
|
+
get isOpen(): boolean;
|
|
222
|
+
send(event: ChatEvent): void;
|
|
223
|
+
close(): void;
|
|
224
|
+
error(err: Error): void;
|
|
225
|
+
[Symbol.asyncIterator](): AsyncIterator<ChatEvent>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { BaseBackendAdapter as B, ClaudeChatAdapter as C, InProcessChatTransport as I, VercelAIChatAdapter as V, WS_READY_STATE as W, type ClaudeChatAdapterOptions as a, CopilotChatAdapter as b, type CopilotChatAdapterOptions as c, type VercelAIChatAdapterOptions as d, type WebSocketLike as e, WsChatTransport as f, type WsTransportOptions as g };
|