@witqq/agent-sdk 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{types-CqvUAYxt.d.ts → agent-C6H2CgJA.d.cts} +139 -102
- package/dist/{types-CqvUAYxt.d.cts → agent-F7oB6eKp.d.ts} +139 -102
- package/dist/auth/index.cjs +72 -1
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +21 -154
- package/dist/auth/index.d.ts +21 -154
- package/dist/auth/index.js +72 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/backends/claude.cjs +480 -261
- package/dist/backends/claude.cjs.map +1 -1
- package/dist/backends/claude.d.cts +3 -1
- package/dist/backends/claude.d.ts +3 -1
- package/dist/backends/claude.js +480 -261
- package/dist/backends/claude.js.map +1 -1
- package/dist/backends/copilot.cjs +337 -112
- package/dist/backends/copilot.cjs.map +1 -1
- package/dist/backends/copilot.d.cts +12 -4
- package/dist/backends/copilot.d.ts +12 -4
- package/dist/backends/copilot.js +337 -112
- package/dist/backends/copilot.js.map +1 -1
- package/dist/backends/mock-llm.cjs +719 -0
- package/dist/backends/mock-llm.cjs.map +1 -0
- package/dist/backends/mock-llm.d.cts +37 -0
- package/dist/backends/mock-llm.d.ts +37 -0
- package/dist/backends/mock-llm.js +717 -0
- package/dist/backends/mock-llm.js.map +1 -0
- package/dist/backends/vercel-ai.cjs +301 -61
- 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 +301 -61
- package/dist/backends/vercel-ai.js.map +1 -1
- package/dist/backends-Cno0gZjy.d.cts +114 -0
- package/dist/backends-Cno0gZjy.d.ts +114 -0
- package/dist/chat/accumulator.cjs +1 -1
- package/dist/chat/accumulator.cjs.map +1 -1
- package/dist/chat/accumulator.d.cts +5 -2
- package/dist/chat/accumulator.d.ts +5 -2
- package/dist/chat/accumulator.js +1 -1
- package/dist/chat/accumulator.js.map +1 -1
- package/dist/chat/backends.cjs +1084 -821
- package/dist/chat/backends.cjs.map +1 -1
- package/dist/chat/backends.d.cts +10 -6
- package/dist/chat/backends.d.ts +10 -6
- package/dist/chat/backends.js +1082 -800
- package/dist/chat/backends.js.map +1 -1
- package/dist/chat/context.cjs +50 -0
- package/dist/chat/context.cjs.map +1 -1
- package/dist/chat/context.d.cts +27 -3
- package/dist/chat/context.d.ts +27 -3
- package/dist/chat/context.js +50 -0
- package/dist/chat/context.js.map +1 -1
- package/dist/chat/core.cjs +60 -27
- package/dist/chat/core.cjs.map +1 -1
- package/dist/chat/core.d.cts +41 -382
- package/dist/chat/core.d.ts +41 -382
- package/dist/chat/core.js +58 -28
- package/dist/chat/core.js.map +1 -1
- package/dist/chat/errors.cjs +48 -26
- package/dist/chat/errors.cjs.map +1 -1
- package/dist/chat/errors.d.cts +6 -31
- package/dist/chat/errors.d.ts +6 -31
- package/dist/chat/errors.js +48 -25
- package/dist/chat/errors.js.map +1 -1
- package/dist/chat/events.cjs.map +1 -1
- package/dist/chat/events.d.cts +6 -2
- package/dist/chat/events.d.ts +6 -2
- package/dist/chat/events.js.map +1 -1
- package/dist/chat/index.cjs +1612 -1125
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +35 -10
- package/dist/chat/index.d.ts +35 -10
- package/dist/chat/index.js +1600 -1097
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react/theme.css +2517 -0
- package/dist/chat/react.cjs +2212 -1158
- package/dist/chat/react.cjs.map +1 -1
- package/dist/chat/react.d.cts +665 -122
- package/dist/chat/react.d.ts +665 -122
- package/dist/chat/react.js +2191 -1156
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/runtime.cjs +405 -186
- package/dist/chat/runtime.cjs.map +1 -1
- package/dist/chat/runtime.d.cts +92 -28
- package/dist/chat/runtime.d.ts +92 -28
- package/dist/chat/runtime.js +405 -186
- package/dist/chat/runtime.js.map +1 -1
- package/dist/chat/server.cjs +2247 -212
- package/dist/chat/server.cjs.map +1 -1
- package/dist/chat/server.d.cts +451 -90
- package/dist/chat/server.d.ts +451 -90
- package/dist/chat/server.js +2234 -213
- package/dist/chat/server.js.map +1 -1
- package/dist/chat/sessions.cjs +64 -66
- package/dist/chat/sessions.cjs.map +1 -1
- package/dist/chat/sessions.d.cts +37 -118
- package/dist/chat/sessions.d.ts +37 -118
- package/dist/chat/sessions.js +65 -67
- package/dist/chat/sessions.js.map +1 -1
- package/dist/chat/sqlite.cjs +536 -0
- package/dist/chat/sqlite.cjs.map +1 -0
- package/dist/chat/sqlite.d.cts +164 -0
- package/dist/chat/sqlite.d.ts +164 -0
- package/dist/chat/sqlite.js +527 -0
- package/dist/chat/sqlite.js.map +1 -0
- package/dist/chat/state.cjs +14 -1
- package/dist/chat/state.cjs.map +1 -1
- package/dist/chat/state.d.cts +5 -2
- package/dist/chat/state.d.ts +5 -2
- package/dist/chat/state.js +14 -1
- package/dist/chat/state.js.map +1 -1
- package/dist/chat/storage.cjs +58 -33
- package/dist/chat/storage.cjs.map +1 -1
- package/dist/chat/storage.d.cts +18 -8
- package/dist/chat/storage.d.ts +18 -8
- package/dist/chat/storage.js +59 -34
- package/dist/chat/storage.js.map +1 -1
- 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-C2oPTYs6.d.ts → in-process-transport-7EIit9Xk.d.ts} +72 -33
- package/dist/{in-process-transport-DG-w5G6k.d.cts → in-process-transport-Ct9YcX8I.d.cts} +72 -33
- package/dist/index.cjs +354 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +294 -123
- package/dist/index.d.ts +294 -123
- package/dist/index.js +347 -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 +1107 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +144 -0
- package/dist/testing.d.ts +144 -0
- package/dist/testing.js +1101 -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-DX1Nhm4N.d.cts → transport-DLWCN18G.d.cts} +5 -4
- package/dist/{transport-D1OaUgRk.d.ts → transport-DsuS-GeM.d.ts} +5 -4
- package/dist/{types-CGF7AEX1.d.cts → types-4vbcmPTp.d.cts} +4 -2
- package/dist/{types-Bh5AhqD-.d.ts → types-BxggH0Yh.d.ts} +4 -2
- package/dist/types-DgtI1hzh.d.ts +364 -0
- package/dist/types-DkSXALKg.d.cts +364 -0
- package/package.json +41 -5
- package/LICENSE +0 -21
- package/README.md +0 -948
- package/dist/errors-BDLbNu9w.d.cts +0 -13
- package/dist/errors-BDLbNu9w.d.ts +0 -13
- package/dist/types-DLZzlJxt.d.ts +0 -39
- package/dist/types-tE0CXwBl.d.cts +0 -39
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { M as ModelInfo, F as FullAgentConfig, I as IAgentService, T as ToolDefinition, U as UsageData } from './agent-C6H2CgJA.cjs';
|
|
2
|
+
import { E as ErrorCode } from './errors-C-so0M4t.cjs';
|
|
3
|
+
import { A as AuthToken } from './types-4vbcmPTp.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @witqq/agent-sdk/chat/backends/types
|
|
7
|
+
*
|
|
8
|
+
* IChatBackend — core backend interface for sending/streaming messages.
|
|
9
|
+
* IResumableBackend — extends IChatBackend with session resume support.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Options for creating a backend adapter */
|
|
13
|
+
interface BackendAdapterOptions {
|
|
14
|
+
/** Agent configuration (model, systemPrompt, tools, etc.) */
|
|
15
|
+
agentConfig: FullAgentConfig;
|
|
16
|
+
/** Pre-created agent service (if adapter should not own lifecycle) */
|
|
17
|
+
agentService?: IAgentService;
|
|
18
|
+
/** Factory for lazy service creation (called on first use, not at construction) */
|
|
19
|
+
agentServiceFactory?: () => IAgentService;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Core chat backend — send, stream, models, validate, dispose.
|
|
23
|
+
* All backends implement this. Resume support is optional.
|
|
24
|
+
*
|
|
25
|
+
* Note: `agentService` is intentionally NOT on this interface.
|
|
26
|
+
* It's an implementation detail exposed on BaseBackendAdapter for
|
|
27
|
+
* advanced consumers who need direct service access.
|
|
28
|
+
*/
|
|
29
|
+
interface IChatBackend {
|
|
30
|
+
/** Backend name (e.g. "copilot", "claude", "vercel-ai") */
|
|
31
|
+
readonly name: string;
|
|
32
|
+
/** Send a message and receive a complete response */
|
|
33
|
+
sendMessage(session: ChatSession, message: string, options?: SendMessageOptions): Promise<ChatMessage>;
|
|
34
|
+
/** Stream a message response as ChatEvents */
|
|
35
|
+
streamMessage(session: ChatSession, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
36
|
+
/** List available models */
|
|
37
|
+
listModels(): Promise<ModelInfo[]>;
|
|
38
|
+
/** Validate backend configuration/credentials */
|
|
39
|
+
validate(): Promise<{
|
|
40
|
+
valid: boolean;
|
|
41
|
+
errors: string[];
|
|
42
|
+
}>;
|
|
43
|
+
/** Dispose resources */
|
|
44
|
+
dispose(): Promise<void>;
|
|
45
|
+
/** Current effective model */
|
|
46
|
+
readonly currentModel: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extended backend with session resume capabilities.
|
|
50
|
+
* Only backends with persistent sessions (Copilot, Claude) implement this.
|
|
51
|
+
* Use `isResumableBackend()` to type-narrow at runtime.
|
|
52
|
+
*/
|
|
53
|
+
interface IResumableBackend extends IChatBackend {
|
|
54
|
+
/** Whether this adapter supports session resume */
|
|
55
|
+
canResume(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Resume a previous session by its backend session ID.
|
|
58
|
+
* Streams events from the resumed session.
|
|
59
|
+
* @throws ChatError with SESSION_EXPIRED if session is no longer valid
|
|
60
|
+
* @throws ChatError with SESSION_NOT_FOUND if session ID is unknown
|
|
61
|
+
*/
|
|
62
|
+
resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
63
|
+
/** The backend session ID from the last stream, or null if not yet streamed */
|
|
64
|
+
readonly backendSessionId: string | null;
|
|
65
|
+
}
|
|
66
|
+
/** Type guard: checks if a backend adapter supports session resume */
|
|
67
|
+
declare function isResumableBackend(adapter: IChatBackend): adapter is IResumableBackend;
|
|
68
|
+
|
|
69
|
+
/** Branded type for unique identifiers */
|
|
70
|
+
type ChatId = string & {
|
|
71
|
+
readonly __brand: "ChatId";
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Generate a new unique ChatId (crypto.randomUUID-based)
|
|
75
|
+
* @returns Branded ChatId string
|
|
76
|
+
*/
|
|
77
|
+
declare function createChatId(): ChatId;
|
|
78
|
+
/**
|
|
79
|
+
* Cast a string to ChatId with UUID format validation.
|
|
80
|
+
* Use this instead of manual `as ChatId` type assertions.
|
|
81
|
+
*
|
|
82
|
+
* @param value - String to validate and cast
|
|
83
|
+
* @returns Branded ChatId
|
|
84
|
+
* @throws {TypeError} If value is not a valid UUID v4 format
|
|
85
|
+
*/
|
|
86
|
+
declare function toChatId(value: string): ChatId;
|
|
87
|
+
/**
|
|
88
|
+
* Accepts either a plain string or branded ChatId for API convenience.
|
|
89
|
+
* Use this in public API signatures so consumers don't need `as ChatId` casts.
|
|
90
|
+
*/
|
|
91
|
+
type ChatIdLike = string | ChatId;
|
|
92
|
+
/** Lifecycle status of a message part (text, reasoning, etc.) */
|
|
93
|
+
type PartStatus = "pending" | "streaming" | "complete" | "error";
|
|
94
|
+
/** Lifecycle status of a tool call within a message */
|
|
95
|
+
type ToolCallStatus = "pending" | "running" | "requires_approval" | "complete" | "error" | "denied";
|
|
96
|
+
/** Lifecycle status of an entire message */
|
|
97
|
+
type MessageStatus = "pending" | "streaming" | "complete" | "error" | "cancelled";
|
|
98
|
+
/** Lifecycle status of a chat session */
|
|
99
|
+
type SessionStatus = "active";
|
|
100
|
+
/** Lifecycle status of the chat runtime */
|
|
101
|
+
type RuntimeStatus = "idle" | "streaming" | "error" | "disposed";
|
|
102
|
+
/** Plain text content part */
|
|
103
|
+
interface TextPart {
|
|
104
|
+
type: "text";
|
|
105
|
+
text: string;
|
|
106
|
+
status: PartStatus;
|
|
107
|
+
}
|
|
108
|
+
/** Model reasoning/thinking content part */
|
|
109
|
+
interface ReasoningPart {
|
|
110
|
+
type: "reasoning";
|
|
111
|
+
text: string;
|
|
112
|
+
status: PartStatus;
|
|
113
|
+
}
|
|
114
|
+
/** Tool invocation part with call ID, arguments, optional result */
|
|
115
|
+
interface ToolCallPart {
|
|
116
|
+
type: "tool_call";
|
|
117
|
+
toolCallId: string;
|
|
118
|
+
name: string;
|
|
119
|
+
args: unknown;
|
|
120
|
+
result?: unknown;
|
|
121
|
+
status: ToolCallStatus;
|
|
122
|
+
error?: string;
|
|
123
|
+
}
|
|
124
|
+
/** Source reference part (URL citation) */
|
|
125
|
+
interface SourcePart {
|
|
126
|
+
type: "source";
|
|
127
|
+
url: string;
|
|
128
|
+
title?: string;
|
|
129
|
+
status: PartStatus;
|
|
130
|
+
}
|
|
131
|
+
/** File attachment part (base64-encoded data) */
|
|
132
|
+
interface FilePart {
|
|
133
|
+
type: "file";
|
|
134
|
+
name: string;
|
|
135
|
+
mimeType: string;
|
|
136
|
+
data: string;
|
|
137
|
+
status: PartStatus;
|
|
138
|
+
}
|
|
139
|
+
/** Union of all message part types */
|
|
140
|
+
type MessagePart = TextPart | ReasoningPart | ToolCallPart | SourcePart | FilePart;
|
|
141
|
+
/** Role of message author */
|
|
142
|
+
type ChatRole = "user" | "assistant" | "system";
|
|
143
|
+
/** Metadata attached to messages — useful preset for the TMetadata generic */
|
|
144
|
+
interface ChatMessageMetadata {
|
|
145
|
+
model?: string;
|
|
146
|
+
backend?: string;
|
|
147
|
+
usage?: UsageData;
|
|
148
|
+
isSummary?: boolean;
|
|
149
|
+
estimatedTokens?: number;
|
|
150
|
+
custom?: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/** Message status */
|
|
153
|
+
type ChatMessageStatus = MessageStatus;
|
|
154
|
+
/** A single chat message — the fundamental unit of conversation */
|
|
155
|
+
interface ChatMessage<TMetadata = unknown> {
|
|
156
|
+
id: ChatId;
|
|
157
|
+
role: ChatRole;
|
|
158
|
+
parts: MessagePart[];
|
|
159
|
+
metadata?: TMetadata;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt?: string;
|
|
162
|
+
status: MessageStatus;
|
|
163
|
+
}
|
|
164
|
+
/** Session configuration snapshot */
|
|
165
|
+
interface ChatSessionConfig {
|
|
166
|
+
model: string;
|
|
167
|
+
backend: string;
|
|
168
|
+
systemPrompt?: string;
|
|
169
|
+
temperature?: number;
|
|
170
|
+
maxTokens?: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Session metadata tracking usage statistics and custom extensions.
|
|
174
|
+
*
|
|
175
|
+
* Updated automatically by session stores on each `addMessage()` call.
|
|
176
|
+
* The generic `TCustom` parameter allows type-safe application-specific
|
|
177
|
+
* metadata via the `custom` field.
|
|
178
|
+
*
|
|
179
|
+
* @typeParam TCustom - Shape of the `custom` field (defaults to `Record<string, unknown>`)
|
|
180
|
+
*/
|
|
181
|
+
interface ChatSessionMetadata<TCustom extends Record<string, unknown> = Record<string, unknown>> {
|
|
182
|
+
/** Number of messages in the session (updated by session store) */
|
|
183
|
+
messageCount: number;
|
|
184
|
+
/** Total token count across all messages in the session */
|
|
185
|
+
totalTokens: number;
|
|
186
|
+
/** Optional tags for session categorization and filtering */
|
|
187
|
+
tags?: string[];
|
|
188
|
+
/** Application-specific metadata — typed via the TCustom generic parameter */
|
|
189
|
+
custom?: TCustom;
|
|
190
|
+
}
|
|
191
|
+
/** Chat session — a conversation with ordered messages (pure serializable data) */
|
|
192
|
+
interface ChatSession<TCustom extends Record<string, unknown> = Record<string, unknown>> {
|
|
193
|
+
id: ChatId;
|
|
194
|
+
title?: string;
|
|
195
|
+
messages: ChatMessage[];
|
|
196
|
+
config: ChatSessionConfig;
|
|
197
|
+
metadata: ChatSessionMetadata<TCustom>;
|
|
198
|
+
status: SessionStatus;
|
|
199
|
+
createdAt: string;
|
|
200
|
+
updatedAt: string;
|
|
201
|
+
backendSessionId?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Reactive wrapper around ChatSession — provides subscribe/getSnapshot for
|
|
205
|
+
* React useSyncExternalStore integration and lastMessage convenience getter.
|
|
206
|
+
* Session stores may optionally return ObservableSession instances.
|
|
207
|
+
*/
|
|
208
|
+
interface ObservableSession<TCustom extends Record<string, unknown> = Record<string, unknown>> extends ChatSession<TCustom> {
|
|
209
|
+
/** Subscribe to session changes (for React useSyncExternalStore) */
|
|
210
|
+
subscribe(callback: () => void): () => void;
|
|
211
|
+
/** Get immutable snapshot of session state (for React useSyncExternalStore) */
|
|
212
|
+
getSnapshot(): ChatSession<TCustom>;
|
|
213
|
+
/** Last message in the session */
|
|
214
|
+
readonly lastMessage: ChatMessage | undefined;
|
|
215
|
+
}
|
|
216
|
+
/** Lightweight session info for listing (without full message array) */
|
|
217
|
+
interface SessionInfo {
|
|
218
|
+
id: ChatId;
|
|
219
|
+
title?: string;
|
|
220
|
+
status: SessionStatus;
|
|
221
|
+
messageCount: number;
|
|
222
|
+
lastMessage?: ChatMessage;
|
|
223
|
+
createdAt: string;
|
|
224
|
+
updatedAt: string;
|
|
225
|
+
}
|
|
226
|
+
/** Events emitted during chat operation */
|
|
227
|
+
type ChatEvent = {
|
|
228
|
+
type: "message:start";
|
|
229
|
+
messageId: ChatId;
|
|
230
|
+
role: ChatRole;
|
|
231
|
+
} | {
|
|
232
|
+
type: "message:delta";
|
|
233
|
+
messageId: ChatId;
|
|
234
|
+
text: string;
|
|
235
|
+
} | {
|
|
236
|
+
type: "message:complete";
|
|
237
|
+
messageId: ChatId;
|
|
238
|
+
message: ChatMessage;
|
|
239
|
+
} | {
|
|
240
|
+
type: "tool:start";
|
|
241
|
+
messageId: ChatId;
|
|
242
|
+
toolCallId: string;
|
|
243
|
+
toolName: string;
|
|
244
|
+
args: Record<string, unknown>;
|
|
245
|
+
} | {
|
|
246
|
+
type: "tool:complete";
|
|
247
|
+
messageId: ChatId;
|
|
248
|
+
toolCallId: string;
|
|
249
|
+
toolName: string;
|
|
250
|
+
result: unknown;
|
|
251
|
+
isError?: boolean;
|
|
252
|
+
} | {
|
|
253
|
+
type: "thinking:start";
|
|
254
|
+
messageId: ChatId;
|
|
255
|
+
} | {
|
|
256
|
+
type: "thinking:delta";
|
|
257
|
+
messageId: ChatId;
|
|
258
|
+
text: string;
|
|
259
|
+
} | {
|
|
260
|
+
type: "thinking:end";
|
|
261
|
+
messageId: ChatId;
|
|
262
|
+
} | {
|
|
263
|
+
type: "permission:request";
|
|
264
|
+
messageId: ChatId;
|
|
265
|
+
toolName: string;
|
|
266
|
+
toolArgs: Record<string, unknown>;
|
|
267
|
+
} | {
|
|
268
|
+
type: "permission:response";
|
|
269
|
+
messageId: ChatId;
|
|
270
|
+
toolName: string;
|
|
271
|
+
allowed: boolean;
|
|
272
|
+
} | {
|
|
273
|
+
type: "usage";
|
|
274
|
+
promptTokens: number;
|
|
275
|
+
completionTokens: number;
|
|
276
|
+
model?: string;
|
|
277
|
+
} | {
|
|
278
|
+
type: "session:created";
|
|
279
|
+
sessionId: ChatId;
|
|
280
|
+
} | {
|
|
281
|
+
type: "session:updated";
|
|
282
|
+
sessionId: ChatId;
|
|
283
|
+
} | {
|
|
284
|
+
type: "error";
|
|
285
|
+
error: string;
|
|
286
|
+
recoverable: boolean;
|
|
287
|
+
code?: ErrorCode;
|
|
288
|
+
messageId?: ChatId;
|
|
289
|
+
} | {
|
|
290
|
+
type: "typing:start";
|
|
291
|
+
} | {
|
|
292
|
+
type: "typing:end";
|
|
293
|
+
} | {
|
|
294
|
+
type: "heartbeat";
|
|
295
|
+
} | {
|
|
296
|
+
type: "done";
|
|
297
|
+
finalOutput?: string;
|
|
298
|
+
finishReason?: string;
|
|
299
|
+
};
|
|
300
|
+
/** All possible ChatEvent type strings */
|
|
301
|
+
type ChatEventType = ChatEvent["type"];
|
|
302
|
+
/** Context passed to ChatMiddleware hooks */
|
|
303
|
+
interface ChatMiddlewareContext {
|
|
304
|
+
sessionId: ChatId;
|
|
305
|
+
signal: AbortSignal;
|
|
306
|
+
}
|
|
307
|
+
/** Runtime-level middleware for the send/receive lifecycle.
|
|
308
|
+
* Different from EventMiddleware which operates at the event bus level. */
|
|
309
|
+
interface ChatMiddleware {
|
|
310
|
+
/** Transform message before sending to backend. Return null to reject the send. */
|
|
311
|
+
onBeforeSend?(message: ChatMessage, context: ChatMiddlewareContext): ChatMessage | null | Promise<ChatMessage | null>;
|
|
312
|
+
/** Transform/intercept stream events */
|
|
313
|
+
onEvent?(event: ChatEvent, context: ChatMiddlewareContext): ChatEvent | null | Promise<ChatEvent | null>;
|
|
314
|
+
/** Transform completed message after receiving from backend */
|
|
315
|
+
onAfterReceive?(message: ChatMessage, context: ChatMiddlewareContext): ChatMessage | Promise<ChatMessage>;
|
|
316
|
+
/** Intercept errors — return null to suppress, return error to propagate */
|
|
317
|
+
onError?(error: Error, context: ChatMiddlewareContext): Error | null | Promise<Error | null>;
|
|
318
|
+
}
|
|
319
|
+
/** Options for sending a message to a provider */
|
|
320
|
+
interface SendMessageOptions {
|
|
321
|
+
signal?: AbortSignal;
|
|
322
|
+
/** Model to use for this request. Required for server-side runtime.send(). */
|
|
323
|
+
model?: string;
|
|
324
|
+
/** Per-call system prompt override (forwarded to the backend agent) */
|
|
325
|
+
systemPrompt?: string;
|
|
326
|
+
context?: Record<string, unknown>;
|
|
327
|
+
/** Additional tools to include in this request */
|
|
328
|
+
tools?: ToolDefinition[];
|
|
329
|
+
}
|
|
330
|
+
/** Options for runtime.send() — requires backend routing info */
|
|
331
|
+
interface RuntimeSendOptions {
|
|
332
|
+
/** Backend to route this request to (key in backends map) */
|
|
333
|
+
backend: string;
|
|
334
|
+
/** Authentication credentials for the backend factory */
|
|
335
|
+
credentials: AuthToken;
|
|
336
|
+
/** Model to use for this request */
|
|
337
|
+
model: string;
|
|
338
|
+
/** Per-call system prompt override (forwarded to the backend agent) */
|
|
339
|
+
systemPrompt?: string;
|
|
340
|
+
/** Abort signal */
|
|
341
|
+
signal?: AbortSignal;
|
|
342
|
+
/** Request-scoped context */
|
|
343
|
+
context?: Record<string, unknown>;
|
|
344
|
+
/** Additional tools */
|
|
345
|
+
tools?: ToolDefinition[];
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* @deprecated IChatProvider has been inlined into IChatBackend.
|
|
349
|
+
* Import IChatBackend from "@witqq/agent-sdk/chat/backends" instead.
|
|
350
|
+
* Kept as type alias for backward compatibility.
|
|
351
|
+
*/
|
|
352
|
+
type IChatProvider = IChatBackend;
|
|
353
|
+
/**
|
|
354
|
+
* Create a simple text ChatMessage.
|
|
355
|
+
*
|
|
356
|
+
* @param text - Message text content
|
|
357
|
+
* @param role - Message role (default: "user")
|
|
358
|
+
* @returns A complete ChatMessage with a single TextPart
|
|
359
|
+
*/
|
|
360
|
+
declare function createTextMessage(text: string, role?: ChatRole): ChatMessage;
|
|
361
|
+
/** Type guard: checks if a session has reactive API (subscribe/getSnapshot) */
|
|
362
|
+
declare function isObservableSession<TCustom extends Record<string, unknown> = Record<string, unknown>>(session: ChatSession<TCustom>): session is ObservableSession<TCustom>;
|
|
363
|
+
|
|
364
|
+
export { type ChatSessionMetadata as A, type BackendAdapterOptions as B, type ChatEventType as C, type FilePart as F, type IChatBackend as I, type MessageStatus as M, type ObservableSession as O, type PartStatus as P, type RuntimeStatus as R, type SendMessageOptions as S, type ToolCallStatus as T, type ChatEvent as a, type ChatId as b, type ChatMessage as c, type IResumableBackend as d, type ChatMiddleware as e, type ChatIdLike as f, type ChatSession as g, type RuntimeSendOptions as h, isResumableBackend as i, type ChatSessionConfig as j, type ChatMessageMetadata as k, type ChatMessageStatus as l, type ChatMiddlewareContext as m, type ChatRole as n, type IChatProvider as o, type MessagePart as p, type ReasoningPart as q, type SessionInfo as r, type SessionStatus as s, type SourcePart as t, type TextPart as u, type ToolCallPart as v, createChatId as w, createTextMessage as x, isObservableSession as y, toChatId as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witqq/agent-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Universal AI agent abstraction layer supporting Copilot CLI, Claude CLI, and Vercel AI SDK backends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -186,6 +186,37 @@
|
|
|
186
186
|
"types": "./dist/chat/server.d.cts",
|
|
187
187
|
"default": "./dist/chat/server.cjs"
|
|
188
188
|
}
|
|
189
|
+
},
|
|
190
|
+
"./chat/react/theme.css": "./dist/chat/react/theme.css",
|
|
191
|
+
"./chat/sqlite": {
|
|
192
|
+
"import": {
|
|
193
|
+
"types": "./dist/chat/sqlite.d.ts",
|
|
194
|
+
"default": "./dist/chat/sqlite.js"
|
|
195
|
+
},
|
|
196
|
+
"require": {
|
|
197
|
+
"types": "./dist/chat/sqlite.d.cts",
|
|
198
|
+
"default": "./dist/chat/sqlite.cjs"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"./testing": {
|
|
202
|
+
"import": {
|
|
203
|
+
"types": "./dist/testing.d.ts",
|
|
204
|
+
"default": "./dist/testing.js"
|
|
205
|
+
},
|
|
206
|
+
"require": {
|
|
207
|
+
"types": "./dist/testing.d.cts",
|
|
208
|
+
"default": "./dist/testing.cjs"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"./mock-llm": {
|
|
212
|
+
"import": {
|
|
213
|
+
"types": "./dist/backends/mock-llm.d.ts",
|
|
214
|
+
"default": "./dist/backends/mock-llm.js"
|
|
215
|
+
},
|
|
216
|
+
"require": {
|
|
217
|
+
"types": "./dist/backends/mock-llm.d.cts",
|
|
218
|
+
"default": "./dist/backends/mock-llm.cjs"
|
|
219
|
+
}
|
|
189
220
|
}
|
|
190
221
|
},
|
|
191
222
|
"files": [
|
|
@@ -193,14 +224,14 @@
|
|
|
193
224
|
"README.md"
|
|
194
225
|
],
|
|
195
226
|
"scripts": {
|
|
196
|
-
"build": "tsup",
|
|
227
|
+
"build": "tsup && mkdir -p dist/chat/react && cp src/chat/react/theme.css dist/chat/react/theme.css",
|
|
197
228
|
"test": "vitest run",
|
|
198
229
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
230
|
+
"test:all": "vitest run && vitest run --config vitest.e2e.config.ts",
|
|
199
231
|
"test:watch": "vitest",
|
|
200
232
|
"typecheck": "tsc --noEmit",
|
|
201
|
-
"lint": "tsc --noEmit",
|
|
202
233
|
"prepublishOnly": "npm run build",
|
|
203
|
-
"
|
|
234
|
+
"docs:api": "typedoc"
|
|
204
235
|
},
|
|
205
236
|
"keywords": [
|
|
206
237
|
"ai",
|
|
@@ -222,6 +253,7 @@
|
|
|
222
253
|
"@github/copilot-sdk": "^0.1.22",
|
|
223
254
|
"@types/react": ">=18",
|
|
224
255
|
"ai": ">=4.0.0",
|
|
256
|
+
"better-sqlite3": ">=9.0.0",
|
|
225
257
|
"react": ">=18",
|
|
226
258
|
"zod": "^3.23.0 || ^4.0.0"
|
|
227
259
|
},
|
|
@@ -243,6 +275,9 @@
|
|
|
243
275
|
},
|
|
244
276
|
"@types/react": {
|
|
245
277
|
"optional": true
|
|
278
|
+
},
|
|
279
|
+
"better-sqlite3": {
|
|
280
|
+
"optional": true
|
|
246
281
|
}
|
|
247
282
|
},
|
|
248
283
|
"devDependencies": {
|
|
@@ -258,8 +293,9 @@
|
|
|
258
293
|
"drizzle-orm": "^0.45.1",
|
|
259
294
|
"jsdom": "^28.1.0",
|
|
260
295
|
"react-dom": "^19.2.4",
|
|
261
|
-
"testfold": "^0.2.1",
|
|
262
296
|
"tsup": "^8.4.0",
|
|
297
|
+
"typedoc": "^0.28.17",
|
|
298
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
263
299
|
"typescript": "^5.8.0",
|
|
264
300
|
"vitest": "^4.0.18",
|
|
265
301
|
"zod": "^4.3.6"
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|