@witqq/agent-sdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -34
- package/dist/{types-CqvUAYxt.d.cts → agent-CW9XbmG_.d.ts} +137 -102
- package/dist/{types-CqvUAYxt.d.ts → agent-DxY68NZL.d.cts} +137 -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 +329 -97
- 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 +329 -97
- package/dist/backends/copilot.js.map +1 -1
- package/dist/backends/vercel-ai.cjs +294 -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 +294 -61
- 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 +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 +736 -746
- 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 +736 -725
- 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 +25 -2
- package/dist/chat/core.cjs.map +1 -1
- package/dist/chat/core.d.cts +30 -381
- package/dist/chat/core.d.ts +30 -381
- package/dist/chat/core.js +24 -3
- 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 +1199 -1008
- 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 +1196 -987
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react/theme.css +2517 -0
- package/dist/chat/react.cjs +2003 -1153
- package/dist/chat/react.cjs.map +1 -1
- package/dist/chat/react.d.cts +590 -121
- package/dist/chat/react.d.ts +590 -121
- package/dist/chat/react.js +1984 -1151
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/runtime.cjs +401 -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 +401 -186
- package/dist/chat/runtime.js.map +1 -1
- package/dist/chat/server.cjs +2234 -209
- 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 +2221 -210
- package/dist/chat/server.js.map +1 -1
- package/dist/chat/sessions.cjs +25 -43
- 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 +25 -43
- package/dist/chat/sessions.js.map +1 -1
- 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 +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 +19 -10
- package/dist/chat/storage.cjs.map +1 -1
- package/dist/chat/storage.d.cts +11 -5
- package/dist/chat/storage.d.ts +11 -5
- package/dist/chat/storage.js +19 -10
- 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-C1JnJGVR.d.ts} +28 -23
- package/dist/{in-process-transport-DG-w5G6k.d.cts → in-process-transport-C7DSqPyX.d.cts} +28 -23
- package/dist/index.cjs +340 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +292 -123
- package/dist/index.d.ts +292 -123
- package/dist/index.js +334 -47
- 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-DX1Nhm4N.d.cts → transport-Cdh3M0tS.d.cts} +5 -4
- package/dist/{transport-D1OaUgRk.d.ts → transport-Ciap4PWK.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-DRgd_9R7.d.cts +363 -0
- package/dist/types-ajANVzf7.d.ts +363 -0
- package/package.json +31 -6
- 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
package/dist/chat/sessions.d.cts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as ChatId, g as ChatSession, c as ChatMessage, j as ChatSessionConfig } from '../types-DRgd_9R7.cjs';
|
|
2
2
|
import { IStorageAdapter } from './storage.cjs';
|
|
3
3
|
export { StorageError } from './storage.cjs';
|
|
4
|
-
import '../
|
|
4
|
+
import '../agent-DxY68NZL.cjs';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../errors-
|
|
6
|
+
import '../errors-C-so0M4t.cjs';
|
|
7
|
+
import '../types-4vbcmPTp.cjs';
|
|
8
|
+
import '../errors-CmVvczxZ.cjs';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @witqq/agent-sdk/chat/sessions
|
|
@@ -52,121 +54,47 @@ interface SessionSearchOptions {
|
|
|
52
54
|
limit?: number;
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const store = new InMemorySessionStore();
|
|
61
|
-
* const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
|
|
62
|
-
* await store.appendMessage(session.id, message);
|
|
63
|
-
* const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });
|
|
64
|
-
* ```
|
|
57
|
+
* Read-only session operations.
|
|
58
|
+
* Consumers needing read-only access (dashboards, analytics) implement only this.
|
|
65
59
|
*/
|
|
66
|
-
interface
|
|
67
|
-
/**
|
|
68
|
-
* Create a new session with defaults.
|
|
69
|
-
* @param options - Session creation options
|
|
70
|
-
* @returns The created session
|
|
71
|
-
*/
|
|
72
|
-
createSession(options: CreateSessionOptions): Promise<ChatSession>;
|
|
73
|
-
/**
|
|
74
|
-
* Retrieve a session by ID.
|
|
75
|
-
* @param id - Session ID
|
|
76
|
-
* @returns The session, or `null` if not found
|
|
77
|
-
*/
|
|
60
|
+
interface ISessionReader {
|
|
78
61
|
getSession(id: ChatId): Promise<ChatSession | null>;
|
|
79
|
-
/**
|
|
80
|
-
* List sessions with optional filtering, sorting, and pagination.
|
|
81
|
-
* @param options - List options
|
|
82
|
-
* @returns Array of sessions
|
|
83
|
-
*/
|
|
84
62
|
listSessions(options?: SessionListOptions): Promise<ChatSession[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Update session title.
|
|
87
|
-
* @param id - Session ID
|
|
88
|
-
* @param title - New title
|
|
89
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
90
|
-
*/
|
|
91
|
-
updateTitle(id: ChatId, title: string): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Update session configuration.
|
|
94
|
-
* @param id - Session ID
|
|
95
|
-
* @param config - Partial config to merge
|
|
96
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
97
|
-
*/
|
|
98
|
-
updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Delete a session by ID.
|
|
101
|
-
* @param id - Session ID
|
|
102
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
103
|
-
*/
|
|
104
|
-
deleteSession(id: ChatId): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Append a single message to a session.
|
|
107
|
-
* Updates session metadata (messageCount, updatedAt).
|
|
108
|
-
* @param sessionId - Session ID
|
|
109
|
-
* @param message - Message to append
|
|
110
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
111
|
-
*/
|
|
112
|
-
appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Append multiple messages to a session in bulk.
|
|
115
|
-
* No-op if messages array is empty.
|
|
116
|
-
* @param sessionId - Session ID
|
|
117
|
-
* @param messages - Messages to append
|
|
118
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
119
|
-
*/
|
|
120
|
-
saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
|
|
121
|
-
/**
|
|
122
|
-
* Get paginated messages from a session.
|
|
123
|
-
* @param sessionId - Session ID
|
|
124
|
-
* @param options - Pagination options (limit, offset)
|
|
125
|
-
* @returns Paginated messages result
|
|
126
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
127
|
-
*/
|
|
128
63
|
loadMessages(sessionId: ChatId, options?: {
|
|
129
64
|
limit?: number;
|
|
130
65
|
offset?: number;
|
|
131
66
|
}): Promise<PaginatedMessages>;
|
|
132
|
-
/**
|
|
133
|
-
* Archive a session (set status to "archived").
|
|
134
|
-
* @param id - Session ID
|
|
135
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
136
|
-
*/
|
|
137
|
-
archiveSession(id: ChatId): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Unarchive a session (set status back to "active").
|
|
140
|
-
* @param id - Session ID
|
|
141
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
142
|
-
*/
|
|
143
|
-
unarchiveSession(id: ChatId): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Search sessions by title and message content.
|
|
146
|
-
* Case-insensitive substring match.
|
|
147
|
-
* @param options - Search query and limit
|
|
148
|
-
* @returns Matching sessions (without full message content)
|
|
149
|
-
*/
|
|
150
67
|
searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
|
|
151
|
-
/**
|
|
152
|
-
* Return the number of stored sessions.
|
|
153
|
-
*/
|
|
154
68
|
count(): Promise<number>;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Write/mutate session operations.
|
|
72
|
+
* Consumers needing full access implement both ISessionReader & ISessionWriter.
|
|
73
|
+
*/
|
|
74
|
+
interface ISessionWriter {
|
|
75
|
+
createSession(options: CreateSessionOptions): Promise<ChatSession>;
|
|
76
|
+
updateTitle(id: ChatId, title: string): Promise<void>;
|
|
77
|
+
updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
|
|
78
|
+
deleteSession(id: ChatId): Promise<void>;
|
|
79
|
+
appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
80
|
+
saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
|
|
158
81
|
clear(): Promise<void>;
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
82
|
+
/** Release any resources held by this store (optional). */
|
|
83
|
+
dispose?(): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Full session store interface — union of reader and writer.
|
|
87
|
+
* Backward-compatible: all existing implementations continue to work.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const store = new InMemorySessionStore();
|
|
92
|
+
* const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
|
|
93
|
+
* await store.appendMessage(session.id, message);
|
|
94
|
+
* const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
interface IChatSessionStore extends ISessionReader, ISessionWriter {
|
|
170
98
|
}
|
|
171
99
|
/**
|
|
172
100
|
* Base session store implementation backed by any `IStorageAdapter<ChatSession>`.
|
|
@@ -187,18 +115,9 @@ declare class BaseSessionStore implements IChatSessionStore {
|
|
|
187
115
|
limit?: number;
|
|
188
116
|
offset?: number;
|
|
189
117
|
}): Promise<PaginatedMessages>;
|
|
190
|
-
archiveSession(id: ChatId): Promise<void>;
|
|
191
|
-
unarchiveSession(id: ChatId): Promise<void>;
|
|
192
118
|
searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
|
|
193
119
|
count(): Promise<number>;
|
|
194
120
|
clear(): Promise<void>;
|
|
195
|
-
/** @deprecated Use `appendMessage()` instead */
|
|
196
|
-
addMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
197
|
-
/** @deprecated Use `loadMessages()` instead */
|
|
198
|
-
getMessages(sessionId: ChatId, options?: {
|
|
199
|
-
limit?: number;
|
|
200
|
-
offset?: number;
|
|
201
|
-
}): Promise<PaginatedMessages>;
|
|
202
121
|
}
|
|
203
122
|
/**
|
|
204
123
|
* In-memory session store. Data is lost when the process exits.
|
|
@@ -236,4 +155,4 @@ declare class FileSessionStore extends BaseSessionStore {
|
|
|
236
155
|
constructor(options: FileSessionStoreOptions);
|
|
237
156
|
}
|
|
238
157
|
|
|
239
|
-
export { type CreateSessionOptions, FileSessionStore, type FileSessionStoreOptions, type IChatSessionStore, InMemorySessionStore, type PaginatedMessages, type SessionListOptions, type SessionSearchOptions };
|
|
158
|
+
export { type CreateSessionOptions, FileSessionStore, type FileSessionStoreOptions, type IChatSessionStore, type ISessionReader, type ISessionWriter, InMemorySessionStore, type PaginatedMessages, type SessionListOptions, type SessionSearchOptions };
|
package/dist/chat/sessions.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as ChatId, g as ChatSession, c as ChatMessage, j as ChatSessionConfig } from '../types-ajANVzf7.js';
|
|
2
2
|
import { IStorageAdapter } from './storage.js';
|
|
3
3
|
export { StorageError } from './storage.js';
|
|
4
|
-
import '../
|
|
4
|
+
import '../agent-CW9XbmG_.js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../errors-
|
|
6
|
+
import '../errors-C-so0M4t.js';
|
|
7
|
+
import '../types-BxggH0Yh.js';
|
|
8
|
+
import '../errors-CmVvczxZ.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @witqq/agent-sdk/chat/sessions
|
|
@@ -52,121 +54,47 @@ interface SessionSearchOptions {
|
|
|
52
54
|
limit?: number;
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const store = new InMemorySessionStore();
|
|
61
|
-
* const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
|
|
62
|
-
* await store.appendMessage(session.id, message);
|
|
63
|
-
* const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });
|
|
64
|
-
* ```
|
|
57
|
+
* Read-only session operations.
|
|
58
|
+
* Consumers needing read-only access (dashboards, analytics) implement only this.
|
|
65
59
|
*/
|
|
66
|
-
interface
|
|
67
|
-
/**
|
|
68
|
-
* Create a new session with defaults.
|
|
69
|
-
* @param options - Session creation options
|
|
70
|
-
* @returns The created session
|
|
71
|
-
*/
|
|
72
|
-
createSession(options: CreateSessionOptions): Promise<ChatSession>;
|
|
73
|
-
/**
|
|
74
|
-
* Retrieve a session by ID.
|
|
75
|
-
* @param id - Session ID
|
|
76
|
-
* @returns The session, or `null` if not found
|
|
77
|
-
*/
|
|
60
|
+
interface ISessionReader {
|
|
78
61
|
getSession(id: ChatId): Promise<ChatSession | null>;
|
|
79
|
-
/**
|
|
80
|
-
* List sessions with optional filtering, sorting, and pagination.
|
|
81
|
-
* @param options - List options
|
|
82
|
-
* @returns Array of sessions
|
|
83
|
-
*/
|
|
84
62
|
listSessions(options?: SessionListOptions): Promise<ChatSession[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Update session title.
|
|
87
|
-
* @param id - Session ID
|
|
88
|
-
* @param title - New title
|
|
89
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
90
|
-
*/
|
|
91
|
-
updateTitle(id: ChatId, title: string): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Update session configuration.
|
|
94
|
-
* @param id - Session ID
|
|
95
|
-
* @param config - Partial config to merge
|
|
96
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
97
|
-
*/
|
|
98
|
-
updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Delete a session by ID.
|
|
101
|
-
* @param id - Session ID
|
|
102
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
103
|
-
*/
|
|
104
|
-
deleteSession(id: ChatId): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Append a single message to a session.
|
|
107
|
-
* Updates session metadata (messageCount, updatedAt).
|
|
108
|
-
* @param sessionId - Session ID
|
|
109
|
-
* @param message - Message to append
|
|
110
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
111
|
-
*/
|
|
112
|
-
appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Append multiple messages to a session in bulk.
|
|
115
|
-
* No-op if messages array is empty.
|
|
116
|
-
* @param sessionId - Session ID
|
|
117
|
-
* @param messages - Messages to append
|
|
118
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
119
|
-
*/
|
|
120
|
-
saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
|
|
121
|
-
/**
|
|
122
|
-
* Get paginated messages from a session.
|
|
123
|
-
* @param sessionId - Session ID
|
|
124
|
-
* @param options - Pagination options (limit, offset)
|
|
125
|
-
* @returns Paginated messages result
|
|
126
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
127
|
-
*/
|
|
128
63
|
loadMessages(sessionId: ChatId, options?: {
|
|
129
64
|
limit?: number;
|
|
130
65
|
offset?: number;
|
|
131
66
|
}): Promise<PaginatedMessages>;
|
|
132
|
-
/**
|
|
133
|
-
* Archive a session (set status to "archived").
|
|
134
|
-
* @param id - Session ID
|
|
135
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
136
|
-
*/
|
|
137
|
-
archiveSession(id: ChatId): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Unarchive a session (set status back to "active").
|
|
140
|
-
* @param id - Session ID
|
|
141
|
-
* @throws {StorageError} with code `NOT_FOUND` if session doesn't exist
|
|
142
|
-
*/
|
|
143
|
-
unarchiveSession(id: ChatId): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Search sessions by title and message content.
|
|
146
|
-
* Case-insensitive substring match.
|
|
147
|
-
* @param options - Search query and limit
|
|
148
|
-
* @returns Matching sessions (without full message content)
|
|
149
|
-
*/
|
|
150
67
|
searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
|
|
151
|
-
/**
|
|
152
|
-
* Return the number of stored sessions.
|
|
153
|
-
*/
|
|
154
68
|
count(): Promise<number>;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Write/mutate session operations.
|
|
72
|
+
* Consumers needing full access implement both ISessionReader & ISessionWriter.
|
|
73
|
+
*/
|
|
74
|
+
interface ISessionWriter {
|
|
75
|
+
createSession(options: CreateSessionOptions): Promise<ChatSession>;
|
|
76
|
+
updateTitle(id: ChatId, title: string): Promise<void>;
|
|
77
|
+
updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
|
|
78
|
+
deleteSession(id: ChatId): Promise<void>;
|
|
79
|
+
appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
80
|
+
saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
|
|
158
81
|
clear(): Promise<void>;
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
82
|
+
/** Release any resources held by this store (optional). */
|
|
83
|
+
dispose?(): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Full session store interface — union of reader and writer.
|
|
87
|
+
* Backward-compatible: all existing implementations continue to work.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const store = new InMemorySessionStore();
|
|
92
|
+
* const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
|
|
93
|
+
* await store.appendMessage(session.id, message);
|
|
94
|
+
* const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
interface IChatSessionStore extends ISessionReader, ISessionWriter {
|
|
170
98
|
}
|
|
171
99
|
/**
|
|
172
100
|
* Base session store implementation backed by any `IStorageAdapter<ChatSession>`.
|
|
@@ -187,18 +115,9 @@ declare class BaseSessionStore implements IChatSessionStore {
|
|
|
187
115
|
limit?: number;
|
|
188
116
|
offset?: number;
|
|
189
117
|
}): Promise<PaginatedMessages>;
|
|
190
|
-
archiveSession(id: ChatId): Promise<void>;
|
|
191
|
-
unarchiveSession(id: ChatId): Promise<void>;
|
|
192
118
|
searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
|
|
193
119
|
count(): Promise<number>;
|
|
194
120
|
clear(): Promise<void>;
|
|
195
|
-
/** @deprecated Use `appendMessage()` instead */
|
|
196
|
-
addMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
|
|
197
|
-
/** @deprecated Use `loadMessages()` instead */
|
|
198
|
-
getMessages(sessionId: ChatId, options?: {
|
|
199
|
-
limit?: number;
|
|
200
|
-
offset?: number;
|
|
201
|
-
}): Promise<PaginatedMessages>;
|
|
202
121
|
}
|
|
203
122
|
/**
|
|
204
123
|
* In-memory session store. Data is lost when the process exits.
|
|
@@ -236,4 +155,4 @@ declare class FileSessionStore extends BaseSessionStore {
|
|
|
236
155
|
constructor(options: FileSessionStoreOptions);
|
|
237
156
|
}
|
|
238
157
|
|
|
239
|
-
export { type CreateSessionOptions, FileSessionStore, type FileSessionStoreOptions, type IChatSessionStore, InMemorySessionStore, type PaginatedMessages, type SessionListOptions, type SessionSearchOptions };
|
|
158
|
+
export { type CreateSessionOptions, FileSessionStore, type FileSessionStoreOptions, type IChatSessionStore, type ISessionReader, type ISessionWriter, InMemorySessionStore, type PaginatedMessages, type SessionListOptions, type SessionSearchOptions };
|
package/dist/chat/sessions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, unlinkSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
|
|
4
|
-
// src/chat/
|
|
4
|
+
// src/chat/types.ts
|
|
5
5
|
function createChatId() {
|
|
6
6
|
return crypto.randomUUID();
|
|
7
7
|
}
|
|
@@ -10,9 +10,18 @@ function createChatId() {
|
|
|
10
10
|
var AgentSDKError = class extends Error {
|
|
11
11
|
/** @internal Marker for cross-bundle identity checks */
|
|
12
12
|
_agentSDKError = true;
|
|
13
|
+
/** Machine-readable error code. Prefer values from the ErrorCode enum. */
|
|
14
|
+
code;
|
|
15
|
+
/** Whether this error is safe to retry */
|
|
16
|
+
retryable;
|
|
17
|
+
/** HTTP status code hint for error classification */
|
|
18
|
+
httpStatus;
|
|
13
19
|
constructor(message, options) {
|
|
14
20
|
super(message, options);
|
|
15
21
|
this.name = "AgentSDKError";
|
|
22
|
+
this.code = options?.code;
|
|
23
|
+
this.retryable = options?.retryable ?? false;
|
|
24
|
+
this.httpStatus = options?.httpStatus;
|
|
16
25
|
}
|
|
17
26
|
/** Check if an error is an AgentSDKError (works across bundled copies) */
|
|
18
27
|
static is(error) {
|
|
@@ -22,7 +31,7 @@ var AgentSDKError = class extends Error {
|
|
|
22
31
|
|
|
23
32
|
// src/chat/storage.ts
|
|
24
33
|
var StorageError = class extends AgentSDKError {
|
|
25
|
-
/** Machine-readable error code */
|
|
34
|
+
/** Machine-readable error code from the unified ErrorCode enum */
|
|
26
35
|
code;
|
|
27
36
|
constructor(message, code) {
|
|
28
37
|
super(message);
|
|
@@ -59,7 +68,7 @@ var InMemoryStorage = class {
|
|
|
59
68
|
if (this.data.has(key)) {
|
|
60
69
|
throw new StorageError(
|
|
61
70
|
`Item with key "${key}" already exists`,
|
|
62
|
-
"
|
|
71
|
+
"STORAGE_DUPLICATE_KEY" /* STORAGE_DUPLICATE_KEY */
|
|
63
72
|
);
|
|
64
73
|
}
|
|
65
74
|
this.data.set(key, structuredClone(item));
|
|
@@ -69,7 +78,7 @@ var InMemoryStorage = class {
|
|
|
69
78
|
if (!this.data.has(key)) {
|
|
70
79
|
throw new StorageError(
|
|
71
80
|
`Item with key "${key}" not found`,
|
|
72
|
-
"
|
|
81
|
+
"STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */
|
|
73
82
|
);
|
|
74
83
|
}
|
|
75
84
|
this.data.set(key, structuredClone(item));
|
|
@@ -79,7 +88,7 @@ var InMemoryStorage = class {
|
|
|
79
88
|
if (!this.data.has(key)) {
|
|
80
89
|
throw new StorageError(
|
|
81
90
|
`Item with key "${key}" not found`,
|
|
82
|
-
"
|
|
91
|
+
"STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */
|
|
83
92
|
);
|
|
84
93
|
}
|
|
85
94
|
this.data.delete(key);
|
|
@@ -144,7 +153,7 @@ var FileStorage = class {
|
|
|
144
153
|
if (existsSync(filePath)) {
|
|
145
154
|
throw new StorageError(
|
|
146
155
|
`Item with key "${key}" already exists`,
|
|
147
|
-
"
|
|
156
|
+
"STORAGE_DUPLICATE_KEY" /* STORAGE_DUPLICATE_KEY */
|
|
148
157
|
);
|
|
149
158
|
}
|
|
150
159
|
this.writeFile(filePath, item);
|
|
@@ -155,7 +164,7 @@ var FileStorage = class {
|
|
|
155
164
|
if (!existsSync(filePath)) {
|
|
156
165
|
throw new StorageError(
|
|
157
166
|
`Item with key "${key}" not found`,
|
|
158
|
-
"
|
|
167
|
+
"STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */
|
|
159
168
|
);
|
|
160
169
|
}
|
|
161
170
|
this.writeFile(filePath, item);
|
|
@@ -166,7 +175,7 @@ var FileStorage = class {
|
|
|
166
175
|
if (!existsSync(filePath)) {
|
|
167
176
|
throw new StorageError(
|
|
168
177
|
`Item with key "${key}" not found`,
|
|
169
|
-
"
|
|
178
|
+
"STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */
|
|
170
179
|
);
|
|
171
180
|
}
|
|
172
181
|
unlinkSync(filePath);
|
|
@@ -212,12 +221,12 @@ var FileStorage = class {
|
|
|
212
221
|
if (error instanceof SyntaxError) {
|
|
213
222
|
throw new StorageError(
|
|
214
223
|
`Failed to parse file: ${filePath}`,
|
|
215
|
-
"
|
|
224
|
+
"STORAGE_SERIALIZATION_ERROR" /* STORAGE_SERIALIZATION_ERROR */
|
|
216
225
|
);
|
|
217
226
|
}
|
|
218
227
|
throw new StorageError(
|
|
219
228
|
`Failed to read file: ${filePath}`,
|
|
220
|
-
"
|
|
229
|
+
"STORAGE_IO_ERROR" /* STORAGE_IO_ERROR */
|
|
221
230
|
);
|
|
222
231
|
}
|
|
223
232
|
}
|
|
@@ -228,7 +237,7 @@ var FileStorage = class {
|
|
|
228
237
|
} catch {
|
|
229
238
|
throw new StorageError(
|
|
230
239
|
`Failed to write file: ${filePath}`,
|
|
231
|
-
"
|
|
240
|
+
"STORAGE_IO_ERROR" /* STORAGE_IO_ERROR */
|
|
232
241
|
);
|
|
233
242
|
}
|
|
234
243
|
}
|
|
@@ -273,7 +282,7 @@ var BaseSessionStore = class {
|
|
|
273
282
|
async updateTitle(id, title) {
|
|
274
283
|
const session = await this.adapter.get(id);
|
|
275
284
|
if (!session) {
|
|
276
|
-
throw new StorageError(`Session "${id}" not found`, "
|
|
285
|
+
throw new StorageError(`Session "${id}" not found`, "STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */);
|
|
277
286
|
}
|
|
278
287
|
session.title = title;
|
|
279
288
|
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -282,7 +291,7 @@ var BaseSessionStore = class {
|
|
|
282
291
|
async updateConfig(id, config) {
|
|
283
292
|
const session = await this.adapter.get(id);
|
|
284
293
|
if (!session) {
|
|
285
|
-
throw new StorageError(`Session "${id}" not found`, "
|
|
294
|
+
throw new StorageError(`Session "${id}" not found`, "STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */);
|
|
286
295
|
}
|
|
287
296
|
session.config = { ...session.config, ...config };
|
|
288
297
|
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -294,7 +303,7 @@ var BaseSessionStore = class {
|
|
|
294
303
|
async appendMessage(sessionId, message) {
|
|
295
304
|
const session = await this.adapter.get(sessionId);
|
|
296
305
|
if (!session) {
|
|
297
|
-
throw new StorageError(`Session "${sessionId}" not found`, "
|
|
306
|
+
throw new StorageError(`Session "${sessionId}" not found`, "STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */);
|
|
298
307
|
}
|
|
299
308
|
session.messages.push(structuredClone(message));
|
|
300
309
|
session.metadata.messageCount = session.messages.length;
|
|
@@ -305,7 +314,7 @@ var BaseSessionStore = class {
|
|
|
305
314
|
if (messages.length === 0) return;
|
|
306
315
|
const session = await this.adapter.get(sessionId);
|
|
307
316
|
if (!session) {
|
|
308
|
-
throw new StorageError(`Session "${sessionId}" not found`, "
|
|
317
|
+
throw new StorageError(`Session "${sessionId}" not found`, "STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */);
|
|
309
318
|
}
|
|
310
319
|
for (const msg of messages) {
|
|
311
320
|
session.messages.push(structuredClone(msg));
|
|
@@ -317,7 +326,7 @@ var BaseSessionStore = class {
|
|
|
317
326
|
async loadMessages(sessionId, options) {
|
|
318
327
|
const session = await this.adapter.get(sessionId);
|
|
319
328
|
if (!session) {
|
|
320
|
-
throw new StorageError(`Session "${sessionId}" not found`, "
|
|
329
|
+
throw new StorageError(`Session "${sessionId}" not found`, "STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */);
|
|
321
330
|
}
|
|
322
331
|
const total = session.messages.length;
|
|
323
332
|
const offset = options?.offset ?? 0;
|
|
@@ -329,24 +338,6 @@ var BaseSessionStore = class {
|
|
|
329
338
|
hasMore: offset + limit < total
|
|
330
339
|
};
|
|
331
340
|
}
|
|
332
|
-
async archiveSession(id) {
|
|
333
|
-
const session = await this.adapter.get(id);
|
|
334
|
-
if (!session) {
|
|
335
|
-
throw new StorageError(`Session "${id}" not found`, "NOT_FOUND");
|
|
336
|
-
}
|
|
337
|
-
session.status = "archived";
|
|
338
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
339
|
-
await this.adapter.update(id, session);
|
|
340
|
-
}
|
|
341
|
-
async unarchiveSession(id) {
|
|
342
|
-
const session = await this.adapter.get(id);
|
|
343
|
-
if (!session) {
|
|
344
|
-
throw new StorageError(`Session "${id}" not found`, "NOT_FOUND");
|
|
345
|
-
}
|
|
346
|
-
session.status = "active";
|
|
347
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
348
|
-
await this.adapter.update(id, session);
|
|
349
|
-
}
|
|
350
341
|
async searchSessions(options) {
|
|
351
342
|
const query = options.query.toLowerCase();
|
|
352
343
|
const limit = options.limit ?? 20;
|
|
@@ -368,15 +359,6 @@ var BaseSessionStore = class {
|
|
|
368
359
|
async clear() {
|
|
369
360
|
return this.adapter.clear();
|
|
370
361
|
}
|
|
371
|
-
// ── Deprecated Aliases ──────────────────────────────────────
|
|
372
|
-
/** @deprecated Use `appendMessage()` instead */
|
|
373
|
-
async addMessage(sessionId, message) {
|
|
374
|
-
return this.appendMessage(sessionId, message);
|
|
375
|
-
}
|
|
376
|
-
/** @deprecated Use `loadMessages()` instead */
|
|
377
|
-
async getMessages(sessionId, options) {
|
|
378
|
-
return this.loadMessages(sessionId, options);
|
|
379
|
-
}
|
|
380
362
|
};
|
|
381
363
|
var InMemorySessionStore = class extends BaseSessionStore {
|
|
382
364
|
constructor() {
|