@yushaw/sanqian-ai-sdk 0.1.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/index.d.mts +1393 -0
- package/dist/index.d.ts +1393 -0
- package/dist/index.js +2117 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2065 -0
- package/dist/index.mjs.map +1 -0
- package/dist/testing.d.mts +363 -0
- package/dist/testing.d.ts +363 -0
- package/dist/testing.js +221 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.mjs +192 -0
- package/dist/testing.mjs.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Profile - separates provider, auth, billing, and history concerns.
|
|
3
|
+
*/
|
|
4
|
+
type RuntimeProviderKind = 'sanqian-sdk' | 'vercel-ai-sdk' | 'fake' | 'replay';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Runtime Stream Events - normalized event protocol for all providers.
|
|
8
|
+
*/
|
|
9
|
+
interface RuntimeToolCall {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: string;
|
|
13
|
+
}
|
|
14
|
+
interface RuntimeInterrupt {
|
|
15
|
+
type: string;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface RuntimeToolExecutionMetadata {
|
|
19
|
+
status?: 'pending' | 'running' | 'completed' | 'error' | 'cancelled' | string;
|
|
20
|
+
actionRequired?: string;
|
|
21
|
+
settingsTab?: string;
|
|
22
|
+
settingsSubTab?: string;
|
|
23
|
+
commandExitCode?: number;
|
|
24
|
+
durationMs?: number;
|
|
25
|
+
sandboxed?: boolean;
|
|
26
|
+
timedOut?: boolean;
|
|
27
|
+
truncated?: boolean;
|
|
28
|
+
stdoutPath?: string;
|
|
29
|
+
stderrPath?: string;
|
|
30
|
+
presentation?: string;
|
|
31
|
+
}
|
|
32
|
+
type RuntimeStreamEvent = {
|
|
33
|
+
type: 'start';
|
|
34
|
+
runId?: string;
|
|
35
|
+
conversationId?: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'text';
|
|
38
|
+
content: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'thinking';
|
|
41
|
+
content: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'tool_call';
|
|
44
|
+
toolCall: RuntimeToolCall;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'tool_args_chunk';
|
|
47
|
+
toolCallId: string;
|
|
48
|
+
toolName: string;
|
|
49
|
+
chunk: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'tool_args';
|
|
52
|
+
toolCallId: string;
|
|
53
|
+
toolName: string;
|
|
54
|
+
args: Record<string, unknown>;
|
|
55
|
+
} | ({
|
|
56
|
+
type: 'tool_result';
|
|
57
|
+
toolCallId: string;
|
|
58
|
+
result?: unknown;
|
|
59
|
+
success?: boolean;
|
|
60
|
+
error?: string;
|
|
61
|
+
} & RuntimeToolExecutionMetadata) | {
|
|
62
|
+
type: 'interrupt';
|
|
63
|
+
runId?: string;
|
|
64
|
+
interrupt: RuntimeInterrupt;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'cancelled';
|
|
67
|
+
runId?: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'done';
|
|
70
|
+
conversationId: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'error';
|
|
74
|
+
error: string;
|
|
75
|
+
code?: string;
|
|
76
|
+
};
|
|
77
|
+
interface RuntimeUsage {
|
|
78
|
+
promptTokens?: number;
|
|
79
|
+
completionTokens?: number;
|
|
80
|
+
totalTokens?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Runtime Provider - the core abstraction that all providers implement.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
interface RuntimeProviderCapabilities {
|
|
88
|
+
streamingText: boolean;
|
|
89
|
+
reasoning: boolean;
|
|
90
|
+
toolCalling: boolean;
|
|
91
|
+
parallelToolCalls: boolean;
|
|
92
|
+
toolArgsStreaming: boolean;
|
|
93
|
+
abort: boolean;
|
|
94
|
+
hitl: boolean;
|
|
95
|
+
conversations: boolean;
|
|
96
|
+
sessionResources: boolean;
|
|
97
|
+
resourcePicker: boolean;
|
|
98
|
+
embeddings: boolean;
|
|
99
|
+
rerank: boolean;
|
|
100
|
+
}
|
|
101
|
+
type RuntimeConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
102
|
+
type RuntimeConnectionErrorCode = 'NOT_FOUND' | 'CONNECTION_FAILED' | 'WEBSOCKET_ERROR' | 'AUTH_ERROR' | 'TIMEOUT' | 'UNKNOWN' | (string & {});
|
|
103
|
+
interface RuntimeConnectionSnapshot {
|
|
104
|
+
status: RuntimeConnectionStatus;
|
|
105
|
+
isConnected: boolean;
|
|
106
|
+
error?: string;
|
|
107
|
+
errorCode?: RuntimeConnectionErrorCode;
|
|
108
|
+
lastChangedAt: number;
|
|
109
|
+
}
|
|
110
|
+
interface RuntimeChatRequest {
|
|
111
|
+
agentId: string;
|
|
112
|
+
messages: RuntimeMessage[];
|
|
113
|
+
conversationId?: string | null;
|
|
114
|
+
providerInstanceId?: string;
|
|
115
|
+
operationId?: string;
|
|
116
|
+
tools?: RuntimeToolDefinition[];
|
|
117
|
+
contexts?: RuntimeContext[];
|
|
118
|
+
resources?: RuntimeResourceRef[];
|
|
119
|
+
sessionResources?: RuntimeResource[];
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}
|
|
122
|
+
interface RuntimeChatResponse {
|
|
123
|
+
content: string;
|
|
124
|
+
conversationId?: string;
|
|
125
|
+
usage?: RuntimeUsage;
|
|
126
|
+
toolResults?: RuntimeToolExecutionResult[];
|
|
127
|
+
}
|
|
128
|
+
interface RuntimeChatStreamRequest {
|
|
129
|
+
agentId: string;
|
|
130
|
+
messages: RuntimeMessage[];
|
|
131
|
+
conversationId?: string | null;
|
|
132
|
+
providerInstanceId?: string;
|
|
133
|
+
operationId?: string;
|
|
134
|
+
tools?: RuntimeToolDefinition[];
|
|
135
|
+
contexts?: RuntimeContext[];
|
|
136
|
+
resources?: RuntimeResourceRef[];
|
|
137
|
+
sessionResources?: RuntimeResource[];
|
|
138
|
+
signal?: AbortSignal;
|
|
139
|
+
}
|
|
140
|
+
interface RuntimeMessage {
|
|
141
|
+
role: 'user' | 'assistant' | 'system';
|
|
142
|
+
content: string;
|
|
143
|
+
}
|
|
144
|
+
interface RuntimeContext {
|
|
145
|
+
id: string;
|
|
146
|
+
content: string;
|
|
147
|
+
}
|
|
148
|
+
interface RuntimeResourceRef {
|
|
149
|
+
providerId: string;
|
|
150
|
+
resourceId: string;
|
|
151
|
+
}
|
|
152
|
+
interface RuntimeResource {
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
content: string;
|
|
156
|
+
summary?: string;
|
|
157
|
+
}
|
|
158
|
+
interface RuntimeToolDefinition {
|
|
159
|
+
name: string;
|
|
160
|
+
description: string;
|
|
161
|
+
parameters: Record<string, unknown>;
|
|
162
|
+
}
|
|
163
|
+
interface RuntimeToolExecutionResult {
|
|
164
|
+
toolCallId: string;
|
|
165
|
+
result?: unknown;
|
|
166
|
+
success: boolean;
|
|
167
|
+
error?: string;
|
|
168
|
+
}
|
|
169
|
+
interface RuntimeProvider {
|
|
170
|
+
readonly id: string;
|
|
171
|
+
readonly kind: RuntimeProviderKind;
|
|
172
|
+
readonly displayName: string;
|
|
173
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
174
|
+
ensureReady(): Promise<void>;
|
|
175
|
+
dispose?(): Promise<void>;
|
|
176
|
+
isConnected?(): boolean;
|
|
177
|
+
getConnectionSnapshot?(): RuntimeConnectionSnapshot;
|
|
178
|
+
onConnectionChange?(callback: (snapshot: RuntimeConnectionSnapshot) => void): () => void;
|
|
179
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
180
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
181
|
+
cancel?(runId: string): Promise<void>;
|
|
182
|
+
sendPermissionResponse?(input: RuntimePermissionResponse): Promise<void>;
|
|
183
|
+
}
|
|
184
|
+
interface RuntimePermissionResponse {
|
|
185
|
+
runId: string;
|
|
186
|
+
toolCallId: string;
|
|
187
|
+
decision: 'approve' | 'deny' | 'cancel';
|
|
188
|
+
reason?: string;
|
|
189
|
+
response?: RuntimeHitlResponse;
|
|
190
|
+
}
|
|
191
|
+
interface RuntimeHitlResponse {
|
|
192
|
+
approved?: boolean;
|
|
193
|
+
remember?: boolean;
|
|
194
|
+
answer?: string;
|
|
195
|
+
selected_indices?: number[];
|
|
196
|
+
cancelled?: boolean;
|
|
197
|
+
timed_out?: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface EmbeddingProvider {
|
|
201
|
+
readonly id: string;
|
|
202
|
+
readonly model: string;
|
|
203
|
+
readonly dimensions: number;
|
|
204
|
+
ensureReady(): Promise<void>;
|
|
205
|
+
dispose?(): Promise<void>;
|
|
206
|
+
/** Embed multiple texts in a single batch. */
|
|
207
|
+
embedMany(texts: string[], options?: {
|
|
208
|
+
signal?: AbortSignal;
|
|
209
|
+
}): Promise<number[][]>;
|
|
210
|
+
/** Embed a single text. */
|
|
211
|
+
embed(text: string, options?: {
|
|
212
|
+
signal?: AbortSignal;
|
|
213
|
+
}): Promise<number[]>;
|
|
214
|
+
/** Test the embedding API connection. */
|
|
215
|
+
test?(): Promise<{
|
|
216
|
+
success: boolean;
|
|
217
|
+
dimensions?: number;
|
|
218
|
+
error?: string;
|
|
219
|
+
}>;
|
|
220
|
+
}
|
|
221
|
+
interface RerankInput {
|
|
222
|
+
query: string;
|
|
223
|
+
documents: Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
text: string;
|
|
226
|
+
}>;
|
|
227
|
+
topN?: number;
|
|
228
|
+
}
|
|
229
|
+
interface RerankResultItem {
|
|
230
|
+
id: string;
|
|
231
|
+
score: number;
|
|
232
|
+
index: number;
|
|
233
|
+
}
|
|
234
|
+
interface RerankResult {
|
|
235
|
+
results: RerankResultItem[];
|
|
236
|
+
}
|
|
237
|
+
interface RerankProvider {
|
|
238
|
+
readonly id: string;
|
|
239
|
+
readonly model: string;
|
|
240
|
+
ensureReady(): Promise<void>;
|
|
241
|
+
dispose?(): Promise<void>;
|
|
242
|
+
rerank(input: RerankInput, options?: {
|
|
243
|
+
signal?: AbortSignal;
|
|
244
|
+
}): Promise<RerankResult>;
|
|
245
|
+
/** Test the rerank API connection. */
|
|
246
|
+
test?(): Promise<{
|
|
247
|
+
success: boolean;
|
|
248
|
+
error?: string;
|
|
249
|
+
}>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Fake Provider - deterministic provider for testing runtime contracts.
|
|
254
|
+
*
|
|
255
|
+
* Supports scripted responses, tool calls, cancellation, and error scenarios.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
interface FakeStreamStep {
|
|
259
|
+
delay?: number;
|
|
260
|
+
event: RuntimeStreamEvent;
|
|
261
|
+
}
|
|
262
|
+
interface FakeScenario {
|
|
263
|
+
/** Match by agentId (undefined = match all) */
|
|
264
|
+
agentId?: string;
|
|
265
|
+
/** Non-streaming response */
|
|
266
|
+
response?: string;
|
|
267
|
+
/** Streaming steps */
|
|
268
|
+
stream?: FakeStreamStep[];
|
|
269
|
+
/** Throw error on call */
|
|
270
|
+
error?: string;
|
|
271
|
+
}
|
|
272
|
+
interface FakeProviderConfig {
|
|
273
|
+
id?: string;
|
|
274
|
+
displayName?: string;
|
|
275
|
+
capabilities?: Partial<RuntimeProviderCapabilities>;
|
|
276
|
+
scenarios?: FakeScenario[];
|
|
277
|
+
/** Default stream for unmatched calls */
|
|
278
|
+
defaultResponse?: string;
|
|
279
|
+
/** Whether ensureReady() should fail */
|
|
280
|
+
readinessError?: string;
|
|
281
|
+
}
|
|
282
|
+
declare class FakeProvider implements RuntimeProvider {
|
|
283
|
+
readonly id: string;
|
|
284
|
+
readonly kind: RuntimeProviderKind;
|
|
285
|
+
readonly displayName: string;
|
|
286
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
287
|
+
private scenarios;
|
|
288
|
+
private defaultResponse;
|
|
289
|
+
private readinessError;
|
|
290
|
+
private disposed;
|
|
291
|
+
/** Track calls for assertions */
|
|
292
|
+
readonly chatCalls: RuntimeChatRequest[];
|
|
293
|
+
readonly chatStreamCalls: RuntimeChatStreamRequest[];
|
|
294
|
+
readonly cancelCalls: string[];
|
|
295
|
+
readonly permissionResponses: RuntimePermissionResponse[];
|
|
296
|
+
constructor(config?: FakeProviderConfig);
|
|
297
|
+
ensureReady(): Promise<void>;
|
|
298
|
+
dispose(): Promise<void>;
|
|
299
|
+
isDisposed(): boolean;
|
|
300
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
301
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
302
|
+
cancel(runId: string): Promise<void>;
|
|
303
|
+
sendPermissionResponse(input: RuntimePermissionResponse): Promise<void>;
|
|
304
|
+
private findScenario;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Fake Embedding/Rerank providers for testing.
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
interface FakeEmbeddingConfig {
|
|
312
|
+
id?: string;
|
|
313
|
+
model?: string;
|
|
314
|
+
dimensions?: number;
|
|
315
|
+
readinessError?: string;
|
|
316
|
+
}
|
|
317
|
+
declare class FakeEmbeddingProvider implements EmbeddingProvider {
|
|
318
|
+
readonly id: string;
|
|
319
|
+
readonly model: string;
|
|
320
|
+
readonly dimensions: number;
|
|
321
|
+
private readinessError;
|
|
322
|
+
private disposed;
|
|
323
|
+
readonly embedCalls: string[][];
|
|
324
|
+
constructor(config?: FakeEmbeddingConfig);
|
|
325
|
+
ensureReady(): Promise<void>;
|
|
326
|
+
dispose(): Promise<void>;
|
|
327
|
+
isDisposed(): boolean;
|
|
328
|
+
embedMany(texts: string[], _opts?: {
|
|
329
|
+
signal?: AbortSignal;
|
|
330
|
+
}): Promise<number[][]>;
|
|
331
|
+
embed(text: string, options?: {
|
|
332
|
+
signal?: AbortSignal;
|
|
333
|
+
}): Promise<number[]>;
|
|
334
|
+
test(): Promise<{
|
|
335
|
+
success: boolean;
|
|
336
|
+
dimensions?: number;
|
|
337
|
+
error?: string;
|
|
338
|
+
}>;
|
|
339
|
+
private deterministicVector;
|
|
340
|
+
}
|
|
341
|
+
interface FakeRerankConfig {
|
|
342
|
+
id?: string;
|
|
343
|
+
model?: string;
|
|
344
|
+
readinessError?: string;
|
|
345
|
+
}
|
|
346
|
+
declare class FakeRerankProvider implements RerankProvider {
|
|
347
|
+
readonly id: string;
|
|
348
|
+
readonly model: string;
|
|
349
|
+
private readinessError;
|
|
350
|
+
private disposed;
|
|
351
|
+
readonly rerankCalls: RerankInput[];
|
|
352
|
+
constructor(config?: FakeRerankConfig);
|
|
353
|
+
ensureReady(): Promise<void>;
|
|
354
|
+
dispose(): Promise<void>;
|
|
355
|
+
isDisposed(): boolean;
|
|
356
|
+
rerank(input: RerankInput): Promise<RerankResult>;
|
|
357
|
+
test(): Promise<{
|
|
358
|
+
success: boolean;
|
|
359
|
+
error?: string;
|
|
360
|
+
}>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export { type FakeEmbeddingConfig, FakeEmbeddingProvider, FakeProvider, type FakeProviderConfig, type FakeRerankConfig, FakeRerankProvider, type FakeScenario, type FakeStreamStep };
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Profile - separates provider, auth, billing, and history concerns.
|
|
3
|
+
*/
|
|
4
|
+
type RuntimeProviderKind = 'sanqian-sdk' | 'vercel-ai-sdk' | 'fake' | 'replay';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Runtime Stream Events - normalized event protocol for all providers.
|
|
8
|
+
*/
|
|
9
|
+
interface RuntimeToolCall {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: string;
|
|
13
|
+
}
|
|
14
|
+
interface RuntimeInterrupt {
|
|
15
|
+
type: string;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface RuntimeToolExecutionMetadata {
|
|
19
|
+
status?: 'pending' | 'running' | 'completed' | 'error' | 'cancelled' | string;
|
|
20
|
+
actionRequired?: string;
|
|
21
|
+
settingsTab?: string;
|
|
22
|
+
settingsSubTab?: string;
|
|
23
|
+
commandExitCode?: number;
|
|
24
|
+
durationMs?: number;
|
|
25
|
+
sandboxed?: boolean;
|
|
26
|
+
timedOut?: boolean;
|
|
27
|
+
truncated?: boolean;
|
|
28
|
+
stdoutPath?: string;
|
|
29
|
+
stderrPath?: string;
|
|
30
|
+
presentation?: string;
|
|
31
|
+
}
|
|
32
|
+
type RuntimeStreamEvent = {
|
|
33
|
+
type: 'start';
|
|
34
|
+
runId?: string;
|
|
35
|
+
conversationId?: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'text';
|
|
38
|
+
content: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'thinking';
|
|
41
|
+
content: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'tool_call';
|
|
44
|
+
toolCall: RuntimeToolCall;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'tool_args_chunk';
|
|
47
|
+
toolCallId: string;
|
|
48
|
+
toolName: string;
|
|
49
|
+
chunk: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'tool_args';
|
|
52
|
+
toolCallId: string;
|
|
53
|
+
toolName: string;
|
|
54
|
+
args: Record<string, unknown>;
|
|
55
|
+
} | ({
|
|
56
|
+
type: 'tool_result';
|
|
57
|
+
toolCallId: string;
|
|
58
|
+
result?: unknown;
|
|
59
|
+
success?: boolean;
|
|
60
|
+
error?: string;
|
|
61
|
+
} & RuntimeToolExecutionMetadata) | {
|
|
62
|
+
type: 'interrupt';
|
|
63
|
+
runId?: string;
|
|
64
|
+
interrupt: RuntimeInterrupt;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'cancelled';
|
|
67
|
+
runId?: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'done';
|
|
70
|
+
conversationId: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'error';
|
|
74
|
+
error: string;
|
|
75
|
+
code?: string;
|
|
76
|
+
};
|
|
77
|
+
interface RuntimeUsage {
|
|
78
|
+
promptTokens?: number;
|
|
79
|
+
completionTokens?: number;
|
|
80
|
+
totalTokens?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Runtime Provider - the core abstraction that all providers implement.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
interface RuntimeProviderCapabilities {
|
|
88
|
+
streamingText: boolean;
|
|
89
|
+
reasoning: boolean;
|
|
90
|
+
toolCalling: boolean;
|
|
91
|
+
parallelToolCalls: boolean;
|
|
92
|
+
toolArgsStreaming: boolean;
|
|
93
|
+
abort: boolean;
|
|
94
|
+
hitl: boolean;
|
|
95
|
+
conversations: boolean;
|
|
96
|
+
sessionResources: boolean;
|
|
97
|
+
resourcePicker: boolean;
|
|
98
|
+
embeddings: boolean;
|
|
99
|
+
rerank: boolean;
|
|
100
|
+
}
|
|
101
|
+
type RuntimeConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
102
|
+
type RuntimeConnectionErrorCode = 'NOT_FOUND' | 'CONNECTION_FAILED' | 'WEBSOCKET_ERROR' | 'AUTH_ERROR' | 'TIMEOUT' | 'UNKNOWN' | (string & {});
|
|
103
|
+
interface RuntimeConnectionSnapshot {
|
|
104
|
+
status: RuntimeConnectionStatus;
|
|
105
|
+
isConnected: boolean;
|
|
106
|
+
error?: string;
|
|
107
|
+
errorCode?: RuntimeConnectionErrorCode;
|
|
108
|
+
lastChangedAt: number;
|
|
109
|
+
}
|
|
110
|
+
interface RuntimeChatRequest {
|
|
111
|
+
agentId: string;
|
|
112
|
+
messages: RuntimeMessage[];
|
|
113
|
+
conversationId?: string | null;
|
|
114
|
+
providerInstanceId?: string;
|
|
115
|
+
operationId?: string;
|
|
116
|
+
tools?: RuntimeToolDefinition[];
|
|
117
|
+
contexts?: RuntimeContext[];
|
|
118
|
+
resources?: RuntimeResourceRef[];
|
|
119
|
+
sessionResources?: RuntimeResource[];
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}
|
|
122
|
+
interface RuntimeChatResponse {
|
|
123
|
+
content: string;
|
|
124
|
+
conversationId?: string;
|
|
125
|
+
usage?: RuntimeUsage;
|
|
126
|
+
toolResults?: RuntimeToolExecutionResult[];
|
|
127
|
+
}
|
|
128
|
+
interface RuntimeChatStreamRequest {
|
|
129
|
+
agentId: string;
|
|
130
|
+
messages: RuntimeMessage[];
|
|
131
|
+
conversationId?: string | null;
|
|
132
|
+
providerInstanceId?: string;
|
|
133
|
+
operationId?: string;
|
|
134
|
+
tools?: RuntimeToolDefinition[];
|
|
135
|
+
contexts?: RuntimeContext[];
|
|
136
|
+
resources?: RuntimeResourceRef[];
|
|
137
|
+
sessionResources?: RuntimeResource[];
|
|
138
|
+
signal?: AbortSignal;
|
|
139
|
+
}
|
|
140
|
+
interface RuntimeMessage {
|
|
141
|
+
role: 'user' | 'assistant' | 'system';
|
|
142
|
+
content: string;
|
|
143
|
+
}
|
|
144
|
+
interface RuntimeContext {
|
|
145
|
+
id: string;
|
|
146
|
+
content: string;
|
|
147
|
+
}
|
|
148
|
+
interface RuntimeResourceRef {
|
|
149
|
+
providerId: string;
|
|
150
|
+
resourceId: string;
|
|
151
|
+
}
|
|
152
|
+
interface RuntimeResource {
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
content: string;
|
|
156
|
+
summary?: string;
|
|
157
|
+
}
|
|
158
|
+
interface RuntimeToolDefinition {
|
|
159
|
+
name: string;
|
|
160
|
+
description: string;
|
|
161
|
+
parameters: Record<string, unknown>;
|
|
162
|
+
}
|
|
163
|
+
interface RuntimeToolExecutionResult {
|
|
164
|
+
toolCallId: string;
|
|
165
|
+
result?: unknown;
|
|
166
|
+
success: boolean;
|
|
167
|
+
error?: string;
|
|
168
|
+
}
|
|
169
|
+
interface RuntimeProvider {
|
|
170
|
+
readonly id: string;
|
|
171
|
+
readonly kind: RuntimeProviderKind;
|
|
172
|
+
readonly displayName: string;
|
|
173
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
174
|
+
ensureReady(): Promise<void>;
|
|
175
|
+
dispose?(): Promise<void>;
|
|
176
|
+
isConnected?(): boolean;
|
|
177
|
+
getConnectionSnapshot?(): RuntimeConnectionSnapshot;
|
|
178
|
+
onConnectionChange?(callback: (snapshot: RuntimeConnectionSnapshot) => void): () => void;
|
|
179
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
180
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
181
|
+
cancel?(runId: string): Promise<void>;
|
|
182
|
+
sendPermissionResponse?(input: RuntimePermissionResponse): Promise<void>;
|
|
183
|
+
}
|
|
184
|
+
interface RuntimePermissionResponse {
|
|
185
|
+
runId: string;
|
|
186
|
+
toolCallId: string;
|
|
187
|
+
decision: 'approve' | 'deny' | 'cancel';
|
|
188
|
+
reason?: string;
|
|
189
|
+
response?: RuntimeHitlResponse;
|
|
190
|
+
}
|
|
191
|
+
interface RuntimeHitlResponse {
|
|
192
|
+
approved?: boolean;
|
|
193
|
+
remember?: boolean;
|
|
194
|
+
answer?: string;
|
|
195
|
+
selected_indices?: number[];
|
|
196
|
+
cancelled?: boolean;
|
|
197
|
+
timed_out?: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface EmbeddingProvider {
|
|
201
|
+
readonly id: string;
|
|
202
|
+
readonly model: string;
|
|
203
|
+
readonly dimensions: number;
|
|
204
|
+
ensureReady(): Promise<void>;
|
|
205
|
+
dispose?(): Promise<void>;
|
|
206
|
+
/** Embed multiple texts in a single batch. */
|
|
207
|
+
embedMany(texts: string[], options?: {
|
|
208
|
+
signal?: AbortSignal;
|
|
209
|
+
}): Promise<number[][]>;
|
|
210
|
+
/** Embed a single text. */
|
|
211
|
+
embed(text: string, options?: {
|
|
212
|
+
signal?: AbortSignal;
|
|
213
|
+
}): Promise<number[]>;
|
|
214
|
+
/** Test the embedding API connection. */
|
|
215
|
+
test?(): Promise<{
|
|
216
|
+
success: boolean;
|
|
217
|
+
dimensions?: number;
|
|
218
|
+
error?: string;
|
|
219
|
+
}>;
|
|
220
|
+
}
|
|
221
|
+
interface RerankInput {
|
|
222
|
+
query: string;
|
|
223
|
+
documents: Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
text: string;
|
|
226
|
+
}>;
|
|
227
|
+
topN?: number;
|
|
228
|
+
}
|
|
229
|
+
interface RerankResultItem {
|
|
230
|
+
id: string;
|
|
231
|
+
score: number;
|
|
232
|
+
index: number;
|
|
233
|
+
}
|
|
234
|
+
interface RerankResult {
|
|
235
|
+
results: RerankResultItem[];
|
|
236
|
+
}
|
|
237
|
+
interface RerankProvider {
|
|
238
|
+
readonly id: string;
|
|
239
|
+
readonly model: string;
|
|
240
|
+
ensureReady(): Promise<void>;
|
|
241
|
+
dispose?(): Promise<void>;
|
|
242
|
+
rerank(input: RerankInput, options?: {
|
|
243
|
+
signal?: AbortSignal;
|
|
244
|
+
}): Promise<RerankResult>;
|
|
245
|
+
/** Test the rerank API connection. */
|
|
246
|
+
test?(): Promise<{
|
|
247
|
+
success: boolean;
|
|
248
|
+
error?: string;
|
|
249
|
+
}>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Fake Provider - deterministic provider for testing runtime contracts.
|
|
254
|
+
*
|
|
255
|
+
* Supports scripted responses, tool calls, cancellation, and error scenarios.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
interface FakeStreamStep {
|
|
259
|
+
delay?: number;
|
|
260
|
+
event: RuntimeStreamEvent;
|
|
261
|
+
}
|
|
262
|
+
interface FakeScenario {
|
|
263
|
+
/** Match by agentId (undefined = match all) */
|
|
264
|
+
agentId?: string;
|
|
265
|
+
/** Non-streaming response */
|
|
266
|
+
response?: string;
|
|
267
|
+
/** Streaming steps */
|
|
268
|
+
stream?: FakeStreamStep[];
|
|
269
|
+
/** Throw error on call */
|
|
270
|
+
error?: string;
|
|
271
|
+
}
|
|
272
|
+
interface FakeProviderConfig {
|
|
273
|
+
id?: string;
|
|
274
|
+
displayName?: string;
|
|
275
|
+
capabilities?: Partial<RuntimeProviderCapabilities>;
|
|
276
|
+
scenarios?: FakeScenario[];
|
|
277
|
+
/** Default stream for unmatched calls */
|
|
278
|
+
defaultResponse?: string;
|
|
279
|
+
/** Whether ensureReady() should fail */
|
|
280
|
+
readinessError?: string;
|
|
281
|
+
}
|
|
282
|
+
declare class FakeProvider implements RuntimeProvider {
|
|
283
|
+
readonly id: string;
|
|
284
|
+
readonly kind: RuntimeProviderKind;
|
|
285
|
+
readonly displayName: string;
|
|
286
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
287
|
+
private scenarios;
|
|
288
|
+
private defaultResponse;
|
|
289
|
+
private readinessError;
|
|
290
|
+
private disposed;
|
|
291
|
+
/** Track calls for assertions */
|
|
292
|
+
readonly chatCalls: RuntimeChatRequest[];
|
|
293
|
+
readonly chatStreamCalls: RuntimeChatStreamRequest[];
|
|
294
|
+
readonly cancelCalls: string[];
|
|
295
|
+
readonly permissionResponses: RuntimePermissionResponse[];
|
|
296
|
+
constructor(config?: FakeProviderConfig);
|
|
297
|
+
ensureReady(): Promise<void>;
|
|
298
|
+
dispose(): Promise<void>;
|
|
299
|
+
isDisposed(): boolean;
|
|
300
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
301
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
302
|
+
cancel(runId: string): Promise<void>;
|
|
303
|
+
sendPermissionResponse(input: RuntimePermissionResponse): Promise<void>;
|
|
304
|
+
private findScenario;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Fake Embedding/Rerank providers for testing.
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
interface FakeEmbeddingConfig {
|
|
312
|
+
id?: string;
|
|
313
|
+
model?: string;
|
|
314
|
+
dimensions?: number;
|
|
315
|
+
readinessError?: string;
|
|
316
|
+
}
|
|
317
|
+
declare class FakeEmbeddingProvider implements EmbeddingProvider {
|
|
318
|
+
readonly id: string;
|
|
319
|
+
readonly model: string;
|
|
320
|
+
readonly dimensions: number;
|
|
321
|
+
private readinessError;
|
|
322
|
+
private disposed;
|
|
323
|
+
readonly embedCalls: string[][];
|
|
324
|
+
constructor(config?: FakeEmbeddingConfig);
|
|
325
|
+
ensureReady(): Promise<void>;
|
|
326
|
+
dispose(): Promise<void>;
|
|
327
|
+
isDisposed(): boolean;
|
|
328
|
+
embedMany(texts: string[], _opts?: {
|
|
329
|
+
signal?: AbortSignal;
|
|
330
|
+
}): Promise<number[][]>;
|
|
331
|
+
embed(text: string, options?: {
|
|
332
|
+
signal?: AbortSignal;
|
|
333
|
+
}): Promise<number[]>;
|
|
334
|
+
test(): Promise<{
|
|
335
|
+
success: boolean;
|
|
336
|
+
dimensions?: number;
|
|
337
|
+
error?: string;
|
|
338
|
+
}>;
|
|
339
|
+
private deterministicVector;
|
|
340
|
+
}
|
|
341
|
+
interface FakeRerankConfig {
|
|
342
|
+
id?: string;
|
|
343
|
+
model?: string;
|
|
344
|
+
readinessError?: string;
|
|
345
|
+
}
|
|
346
|
+
declare class FakeRerankProvider implements RerankProvider {
|
|
347
|
+
readonly id: string;
|
|
348
|
+
readonly model: string;
|
|
349
|
+
private readinessError;
|
|
350
|
+
private disposed;
|
|
351
|
+
readonly rerankCalls: RerankInput[];
|
|
352
|
+
constructor(config?: FakeRerankConfig);
|
|
353
|
+
ensureReady(): Promise<void>;
|
|
354
|
+
dispose(): Promise<void>;
|
|
355
|
+
isDisposed(): boolean;
|
|
356
|
+
rerank(input: RerankInput): Promise<RerankResult>;
|
|
357
|
+
test(): Promise<{
|
|
358
|
+
success: boolean;
|
|
359
|
+
error?: string;
|
|
360
|
+
}>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export { type FakeEmbeddingConfig, FakeEmbeddingProvider, FakeProvider, type FakeProviderConfig, type FakeRerankConfig, FakeRerankProvider, type FakeScenario, type FakeStreamStep };
|