@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/runtime.d.cts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { ChatMiddleware, ChatIdLike, ChatMessage, RuntimeStatus, ChatSession, ChatId, SendMessageOptions, ChatEvent } from '
|
|
2
|
-
import {
|
|
1
|
+
import { I as IChatBackend, e as ChatMiddleware, f as ChatIdLike, c as ChatMessage, R as RuntimeStatus, g as ChatSession, b as ChatId, S as SendMessageOptions, a as ChatEvent, h as RuntimeSendOptions } from '../types-DRgd_9R7.cjs';
|
|
2
|
+
import { T as ToolDefinition, M as ModelInfo } from '../agent-DxY68NZL.cjs';
|
|
3
3
|
import { IChatSessionStore, CreateSessionOptions, SessionListOptions } from './sessions.cjs';
|
|
4
4
|
import { ContextWindowConfig, ContextStats } from './context.cjs';
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import '../errors-
|
|
5
|
+
import { A as AuthToken } from '../types-4vbcmPTp.cjs';
|
|
6
|
+
import { P as ProviderConfig } from '../provider-types-PTSlRPNB.cjs';
|
|
7
|
+
import '../errors-C-so0M4t.cjs';
|
|
8
8
|
import 'zod';
|
|
9
|
+
import './storage.cjs';
|
|
10
|
+
import '../errors-CmVvczxZ.cjs';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @witqq/agent-sdk/chat/runtime
|
|
@@ -24,7 +26,7 @@ import 'zod';
|
|
|
24
26
|
*/
|
|
25
27
|
|
|
26
28
|
/** Factory function that creates a backend adapter on demand */
|
|
27
|
-
type BackendAdapterFactory = () =>
|
|
29
|
+
type BackendAdapterFactory = (credentials: AuthToken) => IChatBackend | Promise<IChatBackend>;
|
|
28
30
|
/** Configuration for creating a chat runtime via createChatRuntime() */
|
|
29
31
|
interface ChatRuntimeOptions {
|
|
30
32
|
/** Map of backend name → adapter factory (lazy creation on first use) */
|
|
@@ -37,10 +39,8 @@ interface ChatRuntimeOptions {
|
|
|
37
39
|
context?: ContextWindowConfig;
|
|
38
40
|
/** Middleware pipeline (optional, applied in order) */
|
|
39
41
|
middleware?: ChatMiddleware[];
|
|
40
|
-
/** Default model override (optional) */
|
|
41
|
-
defaultModel?: string;
|
|
42
42
|
/** Retry configuration for pre-stream connection errors */
|
|
43
|
-
retryConfig?:
|
|
43
|
+
retryConfig?: StreamRetryConfig;
|
|
44
44
|
/**
|
|
45
45
|
* Stream inactivity timeout in milliseconds (optional).
|
|
46
46
|
* When set, aborts the stream if no events arrive within this window.
|
|
@@ -52,46 +52,110 @@ interface ChatRuntimeOptions {
|
|
|
52
52
|
* Use for archiving, logging, or analytics.
|
|
53
53
|
*/
|
|
54
54
|
onContextTrimmed?: (sessionId: ChatIdLike, removedMessages: ChatMessage[]) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Initial tools to register on the runtime.
|
|
57
|
+
* Equivalent to calling `registerTool()` for each tool after creation.
|
|
58
|
+
*/
|
|
59
|
+
tools?: ToolDefinition[];
|
|
55
60
|
}
|
|
56
|
-
/** Retry configuration for pre-stream failures */
|
|
57
|
-
interface
|
|
61
|
+
/** Retry configuration for pre-stream failures (renamed to avoid clash with agent-level RetryConfig) */
|
|
62
|
+
interface StreamRetryConfig {
|
|
58
63
|
/** Maximum number of attempts (default: 1 = no retry) */
|
|
59
64
|
maxAttempts: number;
|
|
60
65
|
/** Delay between retries in milliseconds */
|
|
61
66
|
delayMs: number;
|
|
62
67
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
/** @deprecated Use StreamRetryConfig */
|
|
69
|
+
type RetryConfig = StreamRetryConfig;
|
|
70
|
+
/** Information about a registered backend */
|
|
71
|
+
interface BackendInfo {
|
|
72
|
+
/** Backend name (key in backends map) */
|
|
73
|
+
name: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Provider CRUD operations — separated per Interface Segregation Principle.
|
|
77
|
+
* Implemented by IChatClient (which needs provider management for UI).
|
|
78
|
+
* Not required on IChatRuntime (providers are a handler-layer concern).
|
|
79
|
+
*/
|
|
80
|
+
interface IProviderClient {
|
|
81
|
+
listProviders(): Promise<ProviderConfig[]>;
|
|
82
|
+
createProvider(config: Omit<ProviderConfig, "id" | "createdAt">): Promise<ProviderConfig>;
|
|
83
|
+
updateProvider(id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>): Promise<void>;
|
|
84
|
+
deleteProvider(id: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/** Callback for provider selection changes */
|
|
87
|
+
type SelectionChangeCallback = (providerId: string | null) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Client-side interface for interacting with a remote chat server.
|
|
90
|
+
* Fully self-contained — no shared base with IChatRuntime.
|
|
91
|
+
* Extends IProviderClient for provider CRUD (ISP).
|
|
92
|
+
* Used by React components and remote clients.
|
|
93
|
+
*
|
|
94
|
+
* @typeParam TMetadata - Type-level convenience for message metadata.
|
|
95
|
+
* NOT enforced at the storage boundary — session stores always use `unknown`.
|
|
96
|
+
* Consumers are responsible for metadata shape consistency.
|
|
97
|
+
*/
|
|
98
|
+
interface IChatClient<TMetadata extends Record<string, unknown> = Record<string, unknown>> extends IProviderClient {
|
|
66
99
|
readonly status: RuntimeStatus;
|
|
67
|
-
/** Dispose the runtime and all owned resources */
|
|
68
100
|
dispose(): Promise<void>;
|
|
69
101
|
createSession(options: CreateSessionOptions<TMetadata>): Promise<ChatSession<TMetadata>>;
|
|
70
102
|
getSession(id: ChatIdLike): Promise<ChatSession<TMetadata> | null>;
|
|
71
103
|
listSessions(options?: SessionListOptions): Promise<ChatSession<TMetadata>[]>;
|
|
72
104
|
deleteSession(id: ChatIdLike): Promise<void>;
|
|
73
|
-
archiveSession(id: ChatIdLike): Promise<void>;
|
|
74
105
|
switchSession(id: ChatIdLike): Promise<ChatSession<TMetadata>>;
|
|
75
|
-
/** Currently active session ID (null if none) */
|
|
76
106
|
readonly activeSessionId: ChatId | null;
|
|
107
|
+
/**
|
|
108
|
+
* Send a message. Options are optional — the server handler resolves
|
|
109
|
+
* model and backend from provider selection state.
|
|
110
|
+
* Compare with IChatRuntime.send() where RuntimeSendOptions is required.
|
|
111
|
+
*/
|
|
77
112
|
send(sessionId: ChatIdLike, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
78
113
|
abort(): void;
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
selectProvider(providerId: string): void;
|
|
115
|
+
readonly selectedProviderId: string | null;
|
|
116
|
+
onSelectionChange(callback: SelectionChangeCallback): () => void;
|
|
117
|
+
onSessionChange(callback: () => void): () => void;
|
|
81
118
|
listModels(): Promise<ModelInfo[]>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
119
|
+
listBackends(): Promise<BackendInfo[]>;
|
|
120
|
+
getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Server-side chat runtime. Fully self-contained — no shared base with IChatClient.
|
|
124
|
+
* Manages backend adapters, tools, middleware, and context trimming.
|
|
125
|
+
* Does NOT include client-facing provider CRUD or selection — those are
|
|
126
|
+
* handled by the server handler layer.
|
|
127
|
+
*
|
|
128
|
+
* @typeParam TMetadata - Type-level convenience for message metadata.
|
|
129
|
+
* NOT enforced at the storage boundary — session stores always use `unknown`.
|
|
130
|
+
* Casts in `ChatRuntime.createSession()`/`getSession()` are intentionally unsafe
|
|
131
|
+
* to provide typed access. Consumers are responsible for metadata shape consistency.
|
|
132
|
+
*/
|
|
133
|
+
interface IChatRuntime<TMetadata extends Record<string, unknown> = Record<string, unknown>> {
|
|
134
|
+
readonly status: RuntimeStatus;
|
|
135
|
+
dispose(): Promise<void>;
|
|
136
|
+
createSession(options: CreateSessionOptions<TMetadata>): Promise<ChatSession<TMetadata>>;
|
|
137
|
+
getSession(id: ChatIdLike): Promise<ChatSession<TMetadata> | null>;
|
|
138
|
+
listSessions(options?: SessionListOptions): Promise<ChatSession<TMetadata>[]>;
|
|
139
|
+
deleteSession(id: ChatIdLike): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Send a message. RuntimeSendOptions is required on the server — the caller
|
|
142
|
+
* (usually a handler) must supply backend, model, and credentials.
|
|
143
|
+
* Compare with IChatClient.send() where options are optional.
|
|
144
|
+
*/
|
|
145
|
+
send(sessionId: ChatIdLike, message: string, options: RuntimeSendOptions): AsyncIterable<ChatEvent>;
|
|
146
|
+
abort(): void;
|
|
147
|
+
onSessionChange(callback: () => void): () => void;
|
|
148
|
+
listModels(options?: {
|
|
149
|
+
backend?: string;
|
|
150
|
+
credentials?: AuthToken;
|
|
151
|
+
}): Promise<ModelInfo[]>;
|
|
152
|
+
listBackends(): Promise<BackendInfo[]>;
|
|
86
153
|
registerTool(tool: ToolDefinition): void;
|
|
87
154
|
removeTool(name: string): void;
|
|
88
155
|
readonly registeredTools: ReadonlyMap<string, ToolDefinition>;
|
|
89
156
|
use(middleware: ChatMiddleware): void;
|
|
90
157
|
removeMiddleware(middleware: ChatMiddleware): void;
|
|
91
|
-
|
|
92
|
-
getContextStats(sessionId: ChatIdLike): ContextStats | null;
|
|
93
|
-
/** Subscribe to session mutations (create, delete, archive, message send complete). Returns unsubscribe function. */
|
|
94
|
-
onSessionChange(callback: () => void): () => void;
|
|
158
|
+
getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
|
|
95
159
|
}
|
|
96
160
|
/**
|
|
97
161
|
* Create a fully-wired chat runtime from configuration.
|
|
@@ -115,4 +179,4 @@ interface IChatRuntime<TMetadata extends Record<string, unknown> = Record<string
|
|
|
115
179
|
*/
|
|
116
180
|
declare function createChatRuntime<TMetadata extends Record<string, unknown> = Record<string, unknown>>(options: ChatRuntimeOptions): IChatRuntime<TMetadata>;
|
|
117
181
|
|
|
118
|
-
export { type BackendAdapterFactory, type ChatRuntimeOptions, type IChatRuntime, type RetryConfig, createChatRuntime };
|
|
182
|
+
export { type BackendAdapterFactory, type BackendInfo, type ChatRuntimeOptions, type IChatClient, type IChatRuntime, type IProviderClient, type RetryConfig, type SelectionChangeCallback, type StreamRetryConfig, createChatRuntime };
|
package/dist/chat/runtime.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { ChatMiddleware, ChatIdLike, ChatMessage, RuntimeStatus, ChatSession, ChatId, SendMessageOptions, ChatEvent } from '
|
|
2
|
-
import {
|
|
1
|
+
import { I as IChatBackend, e as ChatMiddleware, f as ChatIdLike, c as ChatMessage, R as RuntimeStatus, g as ChatSession, b as ChatId, S as SendMessageOptions, a as ChatEvent, h as RuntimeSendOptions } from '../types-ajANVzf7.js';
|
|
2
|
+
import { T as ToolDefinition, M as ModelInfo } from '../agent-CW9XbmG_.js';
|
|
3
3
|
import { IChatSessionStore, CreateSessionOptions, SessionListOptions } from './sessions.js';
|
|
4
4
|
import { ContextWindowConfig, ContextStats } from './context.js';
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import '../errors-
|
|
5
|
+
import { A as AuthToken } from '../types-BxggH0Yh.js';
|
|
6
|
+
import { P as ProviderConfig } from '../provider-types-PTSlRPNB.js';
|
|
7
|
+
import '../errors-C-so0M4t.js';
|
|
8
8
|
import 'zod';
|
|
9
|
+
import './storage.js';
|
|
10
|
+
import '../errors-CmVvczxZ.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @witqq/agent-sdk/chat/runtime
|
|
@@ -24,7 +26,7 @@ import 'zod';
|
|
|
24
26
|
*/
|
|
25
27
|
|
|
26
28
|
/** Factory function that creates a backend adapter on demand */
|
|
27
|
-
type BackendAdapterFactory = () =>
|
|
29
|
+
type BackendAdapterFactory = (credentials: AuthToken) => IChatBackend | Promise<IChatBackend>;
|
|
28
30
|
/** Configuration for creating a chat runtime via createChatRuntime() */
|
|
29
31
|
interface ChatRuntimeOptions {
|
|
30
32
|
/** Map of backend name → adapter factory (lazy creation on first use) */
|
|
@@ -37,10 +39,8 @@ interface ChatRuntimeOptions {
|
|
|
37
39
|
context?: ContextWindowConfig;
|
|
38
40
|
/** Middleware pipeline (optional, applied in order) */
|
|
39
41
|
middleware?: ChatMiddleware[];
|
|
40
|
-
/** Default model override (optional) */
|
|
41
|
-
defaultModel?: string;
|
|
42
42
|
/** Retry configuration for pre-stream connection errors */
|
|
43
|
-
retryConfig?:
|
|
43
|
+
retryConfig?: StreamRetryConfig;
|
|
44
44
|
/**
|
|
45
45
|
* Stream inactivity timeout in milliseconds (optional).
|
|
46
46
|
* When set, aborts the stream if no events arrive within this window.
|
|
@@ -52,46 +52,110 @@ interface ChatRuntimeOptions {
|
|
|
52
52
|
* Use for archiving, logging, or analytics.
|
|
53
53
|
*/
|
|
54
54
|
onContextTrimmed?: (sessionId: ChatIdLike, removedMessages: ChatMessage[]) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Initial tools to register on the runtime.
|
|
57
|
+
* Equivalent to calling `registerTool()` for each tool after creation.
|
|
58
|
+
*/
|
|
59
|
+
tools?: ToolDefinition[];
|
|
55
60
|
}
|
|
56
|
-
/** Retry configuration for pre-stream failures */
|
|
57
|
-
interface
|
|
61
|
+
/** Retry configuration for pre-stream failures (renamed to avoid clash with agent-level RetryConfig) */
|
|
62
|
+
interface StreamRetryConfig {
|
|
58
63
|
/** Maximum number of attempts (default: 1 = no retry) */
|
|
59
64
|
maxAttempts: number;
|
|
60
65
|
/** Delay between retries in milliseconds */
|
|
61
66
|
delayMs: number;
|
|
62
67
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
/** @deprecated Use StreamRetryConfig */
|
|
69
|
+
type RetryConfig = StreamRetryConfig;
|
|
70
|
+
/** Information about a registered backend */
|
|
71
|
+
interface BackendInfo {
|
|
72
|
+
/** Backend name (key in backends map) */
|
|
73
|
+
name: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Provider CRUD operations — separated per Interface Segregation Principle.
|
|
77
|
+
* Implemented by IChatClient (which needs provider management for UI).
|
|
78
|
+
* Not required on IChatRuntime (providers are a handler-layer concern).
|
|
79
|
+
*/
|
|
80
|
+
interface IProviderClient {
|
|
81
|
+
listProviders(): Promise<ProviderConfig[]>;
|
|
82
|
+
createProvider(config: Omit<ProviderConfig, "id" | "createdAt">): Promise<ProviderConfig>;
|
|
83
|
+
updateProvider(id: string, changes: Partial<Omit<ProviderConfig, "id" | "createdAt">>): Promise<void>;
|
|
84
|
+
deleteProvider(id: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/** Callback for provider selection changes */
|
|
87
|
+
type SelectionChangeCallback = (providerId: string | null) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Client-side interface for interacting with a remote chat server.
|
|
90
|
+
* Fully self-contained — no shared base with IChatRuntime.
|
|
91
|
+
* Extends IProviderClient for provider CRUD (ISP).
|
|
92
|
+
* Used by React components and remote clients.
|
|
93
|
+
*
|
|
94
|
+
* @typeParam TMetadata - Type-level convenience for message metadata.
|
|
95
|
+
* NOT enforced at the storage boundary — session stores always use `unknown`.
|
|
96
|
+
* Consumers are responsible for metadata shape consistency.
|
|
97
|
+
*/
|
|
98
|
+
interface IChatClient<TMetadata extends Record<string, unknown> = Record<string, unknown>> extends IProviderClient {
|
|
66
99
|
readonly status: RuntimeStatus;
|
|
67
|
-
/** Dispose the runtime and all owned resources */
|
|
68
100
|
dispose(): Promise<void>;
|
|
69
101
|
createSession(options: CreateSessionOptions<TMetadata>): Promise<ChatSession<TMetadata>>;
|
|
70
102
|
getSession(id: ChatIdLike): Promise<ChatSession<TMetadata> | null>;
|
|
71
103
|
listSessions(options?: SessionListOptions): Promise<ChatSession<TMetadata>[]>;
|
|
72
104
|
deleteSession(id: ChatIdLike): Promise<void>;
|
|
73
|
-
archiveSession(id: ChatIdLike): Promise<void>;
|
|
74
105
|
switchSession(id: ChatIdLike): Promise<ChatSession<TMetadata>>;
|
|
75
|
-
/** Currently active session ID (null if none) */
|
|
76
106
|
readonly activeSessionId: ChatId | null;
|
|
107
|
+
/**
|
|
108
|
+
* Send a message. Options are optional — the server handler resolves
|
|
109
|
+
* model and backend from provider selection state.
|
|
110
|
+
* Compare with IChatRuntime.send() where RuntimeSendOptions is required.
|
|
111
|
+
*/
|
|
77
112
|
send(sessionId: ChatIdLike, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
|
|
78
113
|
abort(): void;
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
selectProvider(providerId: string): void;
|
|
115
|
+
readonly selectedProviderId: string | null;
|
|
116
|
+
onSelectionChange(callback: SelectionChangeCallback): () => void;
|
|
117
|
+
onSessionChange(callback: () => void): () => void;
|
|
81
118
|
listModels(): Promise<ModelInfo[]>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
119
|
+
listBackends(): Promise<BackendInfo[]>;
|
|
120
|
+
getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Server-side chat runtime. Fully self-contained — no shared base with IChatClient.
|
|
124
|
+
* Manages backend adapters, tools, middleware, and context trimming.
|
|
125
|
+
* Does NOT include client-facing provider CRUD or selection — those are
|
|
126
|
+
* handled by the server handler layer.
|
|
127
|
+
*
|
|
128
|
+
* @typeParam TMetadata - Type-level convenience for message metadata.
|
|
129
|
+
* NOT enforced at the storage boundary — session stores always use `unknown`.
|
|
130
|
+
* Casts in `ChatRuntime.createSession()`/`getSession()` are intentionally unsafe
|
|
131
|
+
* to provide typed access. Consumers are responsible for metadata shape consistency.
|
|
132
|
+
*/
|
|
133
|
+
interface IChatRuntime<TMetadata extends Record<string, unknown> = Record<string, unknown>> {
|
|
134
|
+
readonly status: RuntimeStatus;
|
|
135
|
+
dispose(): Promise<void>;
|
|
136
|
+
createSession(options: CreateSessionOptions<TMetadata>): Promise<ChatSession<TMetadata>>;
|
|
137
|
+
getSession(id: ChatIdLike): Promise<ChatSession<TMetadata> | null>;
|
|
138
|
+
listSessions(options?: SessionListOptions): Promise<ChatSession<TMetadata>[]>;
|
|
139
|
+
deleteSession(id: ChatIdLike): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Send a message. RuntimeSendOptions is required on the server — the caller
|
|
142
|
+
* (usually a handler) must supply backend, model, and credentials.
|
|
143
|
+
* Compare with IChatClient.send() where options are optional.
|
|
144
|
+
*/
|
|
145
|
+
send(sessionId: ChatIdLike, message: string, options: RuntimeSendOptions): AsyncIterable<ChatEvent>;
|
|
146
|
+
abort(): void;
|
|
147
|
+
onSessionChange(callback: () => void): () => void;
|
|
148
|
+
listModels(options?: {
|
|
149
|
+
backend?: string;
|
|
150
|
+
credentials?: AuthToken;
|
|
151
|
+
}): Promise<ModelInfo[]>;
|
|
152
|
+
listBackends(): Promise<BackendInfo[]>;
|
|
86
153
|
registerTool(tool: ToolDefinition): void;
|
|
87
154
|
removeTool(name: string): void;
|
|
88
155
|
readonly registeredTools: ReadonlyMap<string, ToolDefinition>;
|
|
89
156
|
use(middleware: ChatMiddleware): void;
|
|
90
157
|
removeMiddleware(middleware: ChatMiddleware): void;
|
|
91
|
-
|
|
92
|
-
getContextStats(sessionId: ChatIdLike): ContextStats | null;
|
|
93
|
-
/** Subscribe to session mutations (create, delete, archive, message send complete). Returns unsubscribe function. */
|
|
94
|
-
onSessionChange(callback: () => void): () => void;
|
|
158
|
+
getContextStats(sessionId: ChatIdLike): Promise<ContextStats | null>;
|
|
95
159
|
}
|
|
96
160
|
/**
|
|
97
161
|
* Create a fully-wired chat runtime from configuration.
|
|
@@ -115,4 +179,4 @@ interface IChatRuntime<TMetadata extends Record<string, unknown> = Record<string
|
|
|
115
179
|
*/
|
|
116
180
|
declare function createChatRuntime<TMetadata extends Record<string, unknown> = Record<string, unknown>>(options: ChatRuntimeOptions): IChatRuntime<TMetadata>;
|
|
117
181
|
|
|
118
|
-
export { type BackendAdapterFactory, type ChatRuntimeOptions, type IChatRuntime, type RetryConfig, createChatRuntime };
|
|
182
|
+
export { type BackendAdapterFactory, type BackendInfo, type ChatRuntimeOptions, type IChatClient, type IChatRuntime, type IProviderClient, type RetryConfig, type SelectionChangeCallback, type StreamRetryConfig, createChatRuntime };
|