@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
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1393 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime Profile - separates provider, auth, billing, and history concerns.
|
|
5
|
+
*/
|
|
6
|
+
type RuntimeProviderKind = 'sanqian-sdk' | 'vercel-ai-sdk' | 'fake' | 'replay';
|
|
7
|
+
type ExecutionTarget = 'local-sanqian' | 'local-byok';
|
|
8
|
+
type AuthMode = 'none' | 'local-provider-key';
|
|
9
|
+
type BillingMode = 'host-managed' | 'user-provider-billing';
|
|
10
|
+
type HistoryLocation = 'local';
|
|
11
|
+
interface RuntimeProfile {
|
|
12
|
+
providerKind: RuntimeProviderKind;
|
|
13
|
+
executionTarget: ExecutionTarget;
|
|
14
|
+
authMode: AuthMode;
|
|
15
|
+
billingMode: BillingMode;
|
|
16
|
+
historyLocation: HistoryLocation;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Runtime Stream Events - normalized event protocol for all providers.
|
|
21
|
+
*/
|
|
22
|
+
interface RuntimeToolCall {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
arguments: string;
|
|
26
|
+
}
|
|
27
|
+
interface RuntimeInterrupt {
|
|
28
|
+
type: string;
|
|
29
|
+
payload: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface RuntimeToolExecutionMetadata {
|
|
32
|
+
status?: 'pending' | 'running' | 'completed' | 'error' | 'cancelled' | string;
|
|
33
|
+
actionRequired?: string;
|
|
34
|
+
settingsTab?: string;
|
|
35
|
+
settingsSubTab?: string;
|
|
36
|
+
commandExitCode?: number;
|
|
37
|
+
durationMs?: number;
|
|
38
|
+
sandboxed?: boolean;
|
|
39
|
+
timedOut?: boolean;
|
|
40
|
+
truncated?: boolean;
|
|
41
|
+
stdoutPath?: string;
|
|
42
|
+
stderrPath?: string;
|
|
43
|
+
presentation?: string;
|
|
44
|
+
}
|
|
45
|
+
type RuntimeStreamEvent = {
|
|
46
|
+
type: 'start';
|
|
47
|
+
runId?: string;
|
|
48
|
+
conversationId?: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'text';
|
|
51
|
+
content: string;
|
|
52
|
+
} | {
|
|
53
|
+
type: 'thinking';
|
|
54
|
+
content: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'tool_call';
|
|
57
|
+
toolCall: RuntimeToolCall;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'tool_args_chunk';
|
|
60
|
+
toolCallId: string;
|
|
61
|
+
toolName: string;
|
|
62
|
+
chunk: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'tool_args';
|
|
65
|
+
toolCallId: string;
|
|
66
|
+
toolName: string;
|
|
67
|
+
args: Record<string, unknown>;
|
|
68
|
+
} | ({
|
|
69
|
+
type: 'tool_result';
|
|
70
|
+
toolCallId: string;
|
|
71
|
+
result?: unknown;
|
|
72
|
+
success?: boolean;
|
|
73
|
+
error?: string;
|
|
74
|
+
} & RuntimeToolExecutionMetadata) | {
|
|
75
|
+
type: 'interrupt';
|
|
76
|
+
runId?: string;
|
|
77
|
+
interrupt: RuntimeInterrupt;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'cancelled';
|
|
80
|
+
runId?: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'done';
|
|
83
|
+
conversationId: string;
|
|
84
|
+
title?: string;
|
|
85
|
+
} | {
|
|
86
|
+
type: 'error';
|
|
87
|
+
error: string;
|
|
88
|
+
code?: string;
|
|
89
|
+
};
|
|
90
|
+
interface RuntimeUsage {
|
|
91
|
+
promptTokens?: number;
|
|
92
|
+
completionTokens?: number;
|
|
93
|
+
totalTokens?: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Runtime Provider - the core abstraction that all providers implement.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
interface RuntimeProviderCapabilities {
|
|
101
|
+
streamingText: boolean;
|
|
102
|
+
reasoning: boolean;
|
|
103
|
+
toolCalling: boolean;
|
|
104
|
+
parallelToolCalls: boolean;
|
|
105
|
+
toolArgsStreaming: boolean;
|
|
106
|
+
abort: boolean;
|
|
107
|
+
hitl: boolean;
|
|
108
|
+
conversations: boolean;
|
|
109
|
+
sessionResources: boolean;
|
|
110
|
+
resourcePicker: boolean;
|
|
111
|
+
embeddings: boolean;
|
|
112
|
+
rerank: boolean;
|
|
113
|
+
}
|
|
114
|
+
type RuntimeConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
115
|
+
type RuntimeConnectionErrorCode = 'NOT_FOUND' | 'CONNECTION_FAILED' | 'WEBSOCKET_ERROR' | 'AUTH_ERROR' | 'TIMEOUT' | 'UNKNOWN' | (string & {});
|
|
116
|
+
interface RuntimeConnectionSnapshot {
|
|
117
|
+
status: RuntimeConnectionStatus;
|
|
118
|
+
isConnected: boolean;
|
|
119
|
+
error?: string;
|
|
120
|
+
errorCode?: RuntimeConnectionErrorCode;
|
|
121
|
+
lastChangedAt: number;
|
|
122
|
+
}
|
|
123
|
+
interface RuntimeChatRequest {
|
|
124
|
+
agentId: string;
|
|
125
|
+
messages: RuntimeMessage[];
|
|
126
|
+
conversationId?: string | null;
|
|
127
|
+
providerInstanceId?: string;
|
|
128
|
+
operationId?: string;
|
|
129
|
+
tools?: RuntimeToolDefinition[];
|
|
130
|
+
contexts?: RuntimeContext[];
|
|
131
|
+
resources?: RuntimeResourceRef[];
|
|
132
|
+
sessionResources?: RuntimeResource[];
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
}
|
|
135
|
+
interface RuntimeChatResponse {
|
|
136
|
+
content: string;
|
|
137
|
+
conversationId?: string;
|
|
138
|
+
usage?: RuntimeUsage;
|
|
139
|
+
toolResults?: RuntimeToolExecutionResult[];
|
|
140
|
+
}
|
|
141
|
+
interface RuntimeChatStreamRequest {
|
|
142
|
+
agentId: string;
|
|
143
|
+
messages: RuntimeMessage[];
|
|
144
|
+
conversationId?: string | null;
|
|
145
|
+
providerInstanceId?: string;
|
|
146
|
+
operationId?: string;
|
|
147
|
+
tools?: RuntimeToolDefinition[];
|
|
148
|
+
contexts?: RuntimeContext[];
|
|
149
|
+
resources?: RuntimeResourceRef[];
|
|
150
|
+
sessionResources?: RuntimeResource[];
|
|
151
|
+
signal?: AbortSignal;
|
|
152
|
+
}
|
|
153
|
+
interface RuntimeMessage {
|
|
154
|
+
role: 'user' | 'assistant' | 'system';
|
|
155
|
+
content: string;
|
|
156
|
+
}
|
|
157
|
+
interface RuntimeContext {
|
|
158
|
+
id: string;
|
|
159
|
+
content: string;
|
|
160
|
+
}
|
|
161
|
+
interface RuntimeResourceRef {
|
|
162
|
+
providerId: string;
|
|
163
|
+
resourceId: string;
|
|
164
|
+
}
|
|
165
|
+
interface RuntimeResource {
|
|
166
|
+
id: string;
|
|
167
|
+
title: string;
|
|
168
|
+
content: string;
|
|
169
|
+
summary?: string;
|
|
170
|
+
}
|
|
171
|
+
interface RuntimeToolDefinition {
|
|
172
|
+
name: string;
|
|
173
|
+
description: string;
|
|
174
|
+
parameters: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
interface RuntimeToolExecutionResult {
|
|
177
|
+
toolCallId: string;
|
|
178
|
+
result?: unknown;
|
|
179
|
+
success: boolean;
|
|
180
|
+
error?: string;
|
|
181
|
+
}
|
|
182
|
+
interface RuntimeProviderDescriptor {
|
|
183
|
+
id: string;
|
|
184
|
+
kind: RuntimeProviderKind;
|
|
185
|
+
displayName: string;
|
|
186
|
+
capabilities: RuntimeProviderCapabilities;
|
|
187
|
+
}
|
|
188
|
+
interface RuntimeProvider {
|
|
189
|
+
readonly id: string;
|
|
190
|
+
readonly kind: RuntimeProviderKind;
|
|
191
|
+
readonly displayName: string;
|
|
192
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
193
|
+
ensureReady(): Promise<void>;
|
|
194
|
+
dispose?(): Promise<void>;
|
|
195
|
+
isConnected?(): boolean;
|
|
196
|
+
getConnectionSnapshot?(): RuntimeConnectionSnapshot;
|
|
197
|
+
onConnectionChange?(callback: (snapshot: RuntimeConnectionSnapshot) => void): () => void;
|
|
198
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
199
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
200
|
+
cancel?(runId: string): Promise<void>;
|
|
201
|
+
sendPermissionResponse?(input: RuntimePermissionResponse): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
interface RuntimePermissionResponse {
|
|
204
|
+
runId: string;
|
|
205
|
+
toolCallId: string;
|
|
206
|
+
decision: 'approve' | 'deny' | 'cancel';
|
|
207
|
+
reason?: string;
|
|
208
|
+
response?: RuntimeHitlResponse;
|
|
209
|
+
}
|
|
210
|
+
interface RuntimeHitlResponse {
|
|
211
|
+
approved?: boolean;
|
|
212
|
+
remember?: boolean;
|
|
213
|
+
answer?: string;
|
|
214
|
+
selected_indices?: number[];
|
|
215
|
+
cancelled?: boolean;
|
|
216
|
+
timed_out?: boolean;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Agent Registry - provider-neutral agent configuration.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
type RuntimeAgentId = 'assistant' | 'writing' | 'generator' | 'formatter';
|
|
224
|
+
type AgentExecutionMode = 'chat' | 'task' | 'formatter' | 'summary';
|
|
225
|
+
interface RuntimeAgentConfig {
|
|
226
|
+
id: RuntimeAgentId | string;
|
|
227
|
+
name: string;
|
|
228
|
+
description?: string;
|
|
229
|
+
systemPrompt: string;
|
|
230
|
+
tools: string[];
|
|
231
|
+
executionMode?: AgentExecutionMode;
|
|
232
|
+
capabilities?: Partial<RuntimeProviderCapabilities>;
|
|
233
|
+
}
|
|
234
|
+
interface AgentIdResolver {
|
|
235
|
+
toRuntimeAgentId(input: string): RuntimeAgentId | string;
|
|
236
|
+
toProviderAgentId(shortId: RuntimeAgentId | string): Promise<string>;
|
|
237
|
+
isProviderManagedId(input: string): boolean;
|
|
238
|
+
}
|
|
239
|
+
interface RuntimeAgentRegistry {
|
|
240
|
+
register(config: RuntimeAgentConfig): void;
|
|
241
|
+
get(id: RuntimeAgentId | string): RuntimeAgentConfig | undefined;
|
|
242
|
+
list(): RuntimeAgentConfig[];
|
|
243
|
+
getToolsForAgent(id: RuntimeAgentId | string): RuntimeToolDefinition[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Tool Registry - provider-neutral tool registration and execution.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
type ToolCategory = 'read-only' | 'local-file-read' | 'local-file-write' | 'note-mutation' | 'notebook-mutation' | 'network' | 'dangerous';
|
|
251
|
+
interface RuntimeToolMetadata {
|
|
252
|
+
category: ToolCategory;
|
|
253
|
+
readOnlyHint?: boolean;
|
|
254
|
+
destructiveHint?: boolean;
|
|
255
|
+
idempotentHint?: boolean;
|
|
256
|
+
}
|
|
257
|
+
type RuntimeToolHandler = (args: Record<string, unknown>, context?: RuntimeToolExecutionContext) => Promise<unknown>;
|
|
258
|
+
interface RuntimeToolExecutionContext {
|
|
259
|
+
toolCallId: string;
|
|
260
|
+
signal?: AbortSignal;
|
|
261
|
+
}
|
|
262
|
+
interface RuntimeToolExecutionInput {
|
|
263
|
+
toolCallId: string;
|
|
264
|
+
name: string;
|
|
265
|
+
args: Record<string, unknown>;
|
|
266
|
+
signal?: AbortSignal;
|
|
267
|
+
}
|
|
268
|
+
interface RuntimeToolRegistration {
|
|
269
|
+
definition: RuntimeToolDefinition;
|
|
270
|
+
handler: RuntimeToolHandler;
|
|
271
|
+
metadata: RuntimeToolMetadata;
|
|
272
|
+
}
|
|
273
|
+
interface RuntimeToolRegistry {
|
|
274
|
+
register(tool: RuntimeToolDefinition, handler: RuntimeToolHandler, metadata?: Partial<RuntimeToolMetadata>): void;
|
|
275
|
+
get(name: string): RuntimeToolRegistration | undefined;
|
|
276
|
+
list(): RuntimeToolRegistration[];
|
|
277
|
+
execute(input: RuntimeToolExecutionInput): Promise<RuntimeToolExecutionResult>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Create a tool registry instance.
|
|
281
|
+
*/
|
|
282
|
+
declare function createToolRegistry(): RuntimeToolRegistry;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Permission Policy - controls mutation tool execution with HITL support.
|
|
286
|
+
*
|
|
287
|
+
* The runtime evaluates permissions before executing mutation tools.
|
|
288
|
+
* When a tool requires approval, the runtime emits an 'interrupt' event
|
|
289
|
+
* and waits for the UI to respond via the pending permission table.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
type PermissionDecision = {
|
|
293
|
+
type: 'allow';
|
|
294
|
+
} | {
|
|
295
|
+
type: 'deny';
|
|
296
|
+
reason: string;
|
|
297
|
+
} | {
|
|
298
|
+
type: 'ask';
|
|
299
|
+
interrupt: RuntimeInterrupt;
|
|
300
|
+
};
|
|
301
|
+
interface PermissionPolicy {
|
|
302
|
+
evaluate(input: RuntimeToolExecutionInput): Promise<PermissionDecision>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Pending permission request -- tracks an in-flight approval request.
|
|
306
|
+
*/
|
|
307
|
+
interface PendingPermission {
|
|
308
|
+
id: string;
|
|
309
|
+
toolCallId: string;
|
|
310
|
+
toolName: string;
|
|
311
|
+
args: Record<string, unknown>;
|
|
312
|
+
createdAt: number;
|
|
313
|
+
resolve: (decision: 'approve' | 'deny' | 'cancel') => void;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Permission Gate -- manages pending permission requests and resolution.
|
|
317
|
+
*
|
|
318
|
+
* Used by VercelProvider to enforce local HITL before mutation tool execution.
|
|
319
|
+
* SanqianProvider delegates HITL to the Sanqian backend.
|
|
320
|
+
*/
|
|
321
|
+
interface PermissionGate {
|
|
322
|
+
/** Evaluate and potentially block tool execution. Returns the final decision. */
|
|
323
|
+
requestPermission(input: RuntimeToolExecutionInput): Promise<PermissionDecision>;
|
|
324
|
+
/** Resolve a pending permission request (called when UI responds). */
|
|
325
|
+
resolvePermission(id: string, decision: 'approve' | 'deny' | 'cancel'): void;
|
|
326
|
+
/** Cancel all pending permissions (called on provider switch or stream cancel). */
|
|
327
|
+
cancelAll(reason: string): void;
|
|
328
|
+
/** Get all pending permission requests. */
|
|
329
|
+
listPending(): PendingPermission[];
|
|
330
|
+
/** Listen for new permission requests (for emitting interrupt events). */
|
|
331
|
+
onPermissionRequest(listener: (pending: PendingPermission) => void): () => void;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Create a permission gate that uses a policy and tool registry
|
|
335
|
+
* to decide whether tools need approval.
|
|
336
|
+
*/
|
|
337
|
+
declare function createPermissionGate(policy: PermissionPolicy): PermissionGate;
|
|
338
|
+
/**
|
|
339
|
+
* Default policy: allow all tools.
|
|
340
|
+
*/
|
|
341
|
+
declare function createDefaultPermissionPolicy(): PermissionPolicy;
|
|
342
|
+
/**
|
|
343
|
+
* Category-based policy: allow read-only, ask for mutations.
|
|
344
|
+
*/
|
|
345
|
+
declare function createCategoryPermissionPolicy(registry: RuntimeToolRegistry): PermissionPolicy;
|
|
346
|
+
/**
|
|
347
|
+
* Sanitize tool error messages -- strip file paths, SQL errors, and secrets.
|
|
348
|
+
*/
|
|
349
|
+
declare function redactToolError(error: string): string;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Conversation Store - provider-scoped conversation persistence.
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
interface ConversationInfo {
|
|
356
|
+
id: string;
|
|
357
|
+
providerId: string;
|
|
358
|
+
agentId?: string;
|
|
359
|
+
title: string;
|
|
360
|
+
createdAt: string;
|
|
361
|
+
updatedAt: string;
|
|
362
|
+
messageCount: number;
|
|
363
|
+
}
|
|
364
|
+
interface ConversationDetail extends ConversationInfo {
|
|
365
|
+
messages: RuntimeConversationMessage[];
|
|
366
|
+
}
|
|
367
|
+
interface RuntimeConversationMessage extends RuntimeMessage {
|
|
368
|
+
id: string;
|
|
369
|
+
timestamp: string;
|
|
370
|
+
toolCalls?: Array<{
|
|
371
|
+
id: string;
|
|
372
|
+
name: string;
|
|
373
|
+
args: Record<string, unknown>;
|
|
374
|
+
result?: unknown;
|
|
375
|
+
}>;
|
|
376
|
+
}
|
|
377
|
+
interface ConversationPatch {
|
|
378
|
+
title?: string;
|
|
379
|
+
}
|
|
380
|
+
interface ListConversationsInput {
|
|
381
|
+
providerId?: string;
|
|
382
|
+
agentId?: string;
|
|
383
|
+
limit?: number;
|
|
384
|
+
offset?: number;
|
|
385
|
+
}
|
|
386
|
+
interface ConversationPage {
|
|
387
|
+
conversations: ConversationInfo[];
|
|
388
|
+
total: number;
|
|
389
|
+
}
|
|
390
|
+
interface GetConversationInput {
|
|
391
|
+
messageLimit?: number;
|
|
392
|
+
}
|
|
393
|
+
interface CreateConversationInput {
|
|
394
|
+
providerId: string;
|
|
395
|
+
agentId?: string;
|
|
396
|
+
title?: string;
|
|
397
|
+
}
|
|
398
|
+
interface ConversationStore {
|
|
399
|
+
list(input: ListConversationsInput): Promise<ConversationPage>;
|
|
400
|
+
get(id: string, input?: GetConversationInput): Promise<ConversationDetail | null>;
|
|
401
|
+
create(input: CreateConversationInput): Promise<ConversationDetail>;
|
|
402
|
+
appendMessages(id: string, messages: RuntimeConversationMessage[]): Promise<void>;
|
|
403
|
+
update(id: string, patch: ConversationPatch): Promise<void>;
|
|
404
|
+
delete(id: string): Promise<void>;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* In-memory conversation store for playground/testing.
|
|
408
|
+
*/
|
|
409
|
+
declare function createMemoryConversationStore(): ConversationStore;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Active Work Tracking - manages in-flight AI operations.
|
|
413
|
+
*/
|
|
414
|
+
type ActiveRuntimeWorkKind = 'chat-panel-stream' | 'inline-chat-stream' | 'agent-task' | 'summary-generation' | 'embedding-indexing' | 'rerank-request';
|
|
415
|
+
interface ActiveRuntimeWork {
|
|
416
|
+
id: string;
|
|
417
|
+
kind: ActiveRuntimeWorkKind;
|
|
418
|
+
providerId: string;
|
|
419
|
+
startedAt: number;
|
|
420
|
+
abort: () => void;
|
|
421
|
+
}
|
|
422
|
+
interface ActiveWorkTracker {
|
|
423
|
+
register(work: ActiveRuntimeWork): void;
|
|
424
|
+
unregister(id: string): void;
|
|
425
|
+
list(): ActiveRuntimeWork[];
|
|
426
|
+
listByProvider(providerId: string): ActiveRuntimeWork[];
|
|
427
|
+
cancelAll(reason: string): Promise<void>;
|
|
428
|
+
cancelByProvider(providerId: string, reason: string): Promise<void>;
|
|
429
|
+
}
|
|
430
|
+
declare function createActiveWorkTracker(): ActiveWorkTracker;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* AI Feature Readiness - replaces Sanqian-only feature readiness.
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
interface AiFeatureRuntimeState {
|
|
437
|
+
enabled: boolean;
|
|
438
|
+
activeProviderId: string | null;
|
|
439
|
+
activeProviderKind: RuntimeProviderKind | null;
|
|
440
|
+
ready: boolean;
|
|
441
|
+
capabilities: RuntimeProviderCapabilities;
|
|
442
|
+
source: 'runtime-provider' | 'sanqian-discovery' | 'manual-disabled';
|
|
443
|
+
lastError?: string;
|
|
444
|
+
}
|
|
445
|
+
declare const EMPTY_CAPABILITIES: RuntimeProviderCapabilities;
|
|
446
|
+
declare function createDisabledState(): AiFeatureRuntimeState;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Secret Store - host-supplied secret storage interface.
|
|
450
|
+
*/
|
|
451
|
+
interface SecretRef {
|
|
452
|
+
id: string;
|
|
453
|
+
providerInstanceId: string;
|
|
454
|
+
}
|
|
455
|
+
interface SecretDescriptor {
|
|
456
|
+
id: string;
|
|
457
|
+
providerInstanceId: string;
|
|
458
|
+
label?: string;
|
|
459
|
+
maskedValue?: string;
|
|
460
|
+
createdAt: number;
|
|
461
|
+
updatedAt: number;
|
|
462
|
+
}
|
|
463
|
+
interface StoreSecretInput {
|
|
464
|
+
providerInstanceId: string;
|
|
465
|
+
label?: string;
|
|
466
|
+
value: string;
|
|
467
|
+
}
|
|
468
|
+
interface RuntimeSecretStore {
|
|
469
|
+
put(input: StoreSecretInput): Promise<SecretRef>;
|
|
470
|
+
get(ref: SecretRef): Promise<string>;
|
|
471
|
+
delete(ref: SecretRef): Promise<void>;
|
|
472
|
+
describe(ref: SecretRef): Promise<SecretDescriptor>;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* In-memory secret store for playground/testing. NOT for production.
|
|
476
|
+
*/
|
|
477
|
+
declare function createMemorySecretStore(): RuntimeSecretStore;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Runtime Session Manager - provider switching state machine.
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
interface ProviderInstanceConfig {
|
|
484
|
+
id: string;
|
|
485
|
+
provider: RuntimeProvider;
|
|
486
|
+
}
|
|
487
|
+
interface SwitchOptions {
|
|
488
|
+
ifBusy: 'cancel-active-work';
|
|
489
|
+
timeoutMs?: number;
|
|
490
|
+
}
|
|
491
|
+
interface SwitchResult {
|
|
492
|
+
success: boolean;
|
|
493
|
+
previousProviderId?: string;
|
|
494
|
+
newProviderId?: string;
|
|
495
|
+
error?: string;
|
|
496
|
+
}
|
|
497
|
+
interface ProviderChangedEvent {
|
|
498
|
+
previousProviderId: string | null;
|
|
499
|
+
newProviderId: string | null;
|
|
500
|
+
capabilities: RuntimeProviderCapabilities;
|
|
501
|
+
}
|
|
502
|
+
interface RuntimeSessionManager {
|
|
503
|
+
getActiveProvider(): RuntimeProvider | null;
|
|
504
|
+
getActiveDescriptor(): RuntimeProviderDescriptor | null;
|
|
505
|
+
getRuntimeState(): AiFeatureRuntimeState;
|
|
506
|
+
switchProvider(config: ProviderInstanceConfig, options?: SwitchOptions): Promise<SwitchResult>;
|
|
507
|
+
cancelAll(reason: string): Promise<void>;
|
|
508
|
+
onProviderChanged(listener: (event: ProviderChangedEvent) => void): () => void;
|
|
509
|
+
}
|
|
510
|
+
declare function createSessionManager(workTracker: ActiveWorkTracker): RuntimeSessionManager;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Task Pipeline - two-step agent task flow (content agent -> formatter agent).
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
interface RuntimeTaskPipelineInput {
|
|
517
|
+
taskId: string;
|
|
518
|
+
contentAgentId: string;
|
|
519
|
+
contentMessages: RuntimeMessage[];
|
|
520
|
+
formatterConfig: RuntimeAgentConfig;
|
|
521
|
+
outputTools: RuntimeToolDefinition[];
|
|
522
|
+
outputContext: unknown;
|
|
523
|
+
signal?: AbortSignal;
|
|
524
|
+
outputFormat?: 'auto' | 'paragraph' | 'list' | 'table' | 'code' | 'quote';
|
|
525
|
+
}
|
|
526
|
+
interface RuntimeTaskPipeline {
|
|
527
|
+
executeWithFormatter(input: RuntimeTaskPipelineInput): AsyncIterable<RuntimeStreamEvent>;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Create a task pipeline that uses a RuntimeProvider for both content and formatter steps.
|
|
531
|
+
*
|
|
532
|
+
* The pipeline:
|
|
533
|
+
* 1. Runs the content agent to generate raw text
|
|
534
|
+
* 2. Runs the formatter agent with output tools to structure the result
|
|
535
|
+
*
|
|
536
|
+
* Cancellation via AbortSignal stops both steps.
|
|
537
|
+
*/
|
|
538
|
+
declare function createTaskPipeline(getProvider: () => RuntimeProvider | null): RuntimeTaskPipeline;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Embedding and Rerank Provider contracts.
|
|
542
|
+
*
|
|
543
|
+
* Notes owns the vector DB, chunks, indexing queue, and stale-vector cleanup.
|
|
544
|
+
* The runtime owns provider contracts, readiness, and model-change signals.
|
|
545
|
+
*
|
|
546
|
+
* Key invariant: chat provider switching must NOT silently change
|
|
547
|
+
* the embedding provider or mutate the vector index.
|
|
548
|
+
*/
|
|
549
|
+
interface EmbeddingProviderConfig {
|
|
550
|
+
id: string;
|
|
551
|
+
model: string;
|
|
552
|
+
dimensions: number;
|
|
553
|
+
apiUrl?: string;
|
|
554
|
+
apiKey?: string;
|
|
555
|
+
}
|
|
556
|
+
interface EmbeddingProvider {
|
|
557
|
+
readonly id: string;
|
|
558
|
+
readonly model: string;
|
|
559
|
+
readonly dimensions: number;
|
|
560
|
+
ensureReady(): Promise<void>;
|
|
561
|
+
dispose?(): Promise<void>;
|
|
562
|
+
/** Embed multiple texts in a single batch. */
|
|
563
|
+
embedMany(texts: string[], options?: {
|
|
564
|
+
signal?: AbortSignal;
|
|
565
|
+
}): Promise<number[][]>;
|
|
566
|
+
/** Embed a single text. */
|
|
567
|
+
embed(text: string, options?: {
|
|
568
|
+
signal?: AbortSignal;
|
|
569
|
+
}): Promise<number[]>;
|
|
570
|
+
/** Test the embedding API connection. */
|
|
571
|
+
test?(): Promise<{
|
|
572
|
+
success: boolean;
|
|
573
|
+
dimensions?: number;
|
|
574
|
+
error?: string;
|
|
575
|
+
}>;
|
|
576
|
+
}
|
|
577
|
+
interface RerankInput {
|
|
578
|
+
query: string;
|
|
579
|
+
documents: Array<{
|
|
580
|
+
id: string;
|
|
581
|
+
text: string;
|
|
582
|
+
}>;
|
|
583
|
+
topN?: number;
|
|
584
|
+
}
|
|
585
|
+
interface RerankResultItem {
|
|
586
|
+
id: string;
|
|
587
|
+
score: number;
|
|
588
|
+
index: number;
|
|
589
|
+
}
|
|
590
|
+
interface RerankResult {
|
|
591
|
+
results: RerankResultItem[];
|
|
592
|
+
}
|
|
593
|
+
interface RerankProvider {
|
|
594
|
+
readonly id: string;
|
|
595
|
+
readonly model: string;
|
|
596
|
+
ensureReady(): Promise<void>;
|
|
597
|
+
dispose?(): Promise<void>;
|
|
598
|
+
rerank(input: RerankInput, options?: {
|
|
599
|
+
signal?: AbortSignal;
|
|
600
|
+
}): Promise<RerankResult>;
|
|
601
|
+
/** Test the rerank API connection. */
|
|
602
|
+
test?(): Promise<{
|
|
603
|
+
success: boolean;
|
|
604
|
+
error?: string;
|
|
605
|
+
}>;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Model change event -- emitted when embedding model/dimensions change.
|
|
609
|
+
* Notes should pause indexing, mark vectors stale, and schedule rebuild.
|
|
610
|
+
*/
|
|
611
|
+
interface EmbeddingModelChangeEvent {
|
|
612
|
+
previousModel: string | null;
|
|
613
|
+
previousDimensions: number | null;
|
|
614
|
+
newModel: string;
|
|
615
|
+
newDimensions: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Embedding session -- manages active embedding/rerank providers
|
|
619
|
+
* separately from the chat provider.
|
|
620
|
+
*/
|
|
621
|
+
interface EmbeddingSession {
|
|
622
|
+
getEmbeddingProvider(): EmbeddingProvider | null;
|
|
623
|
+
getRerankProvider(): RerankProvider | null;
|
|
624
|
+
setEmbeddingProvider(provider: EmbeddingProvider): Promise<EmbeddingModelChangeEvent | null>;
|
|
625
|
+
setRerankProvider(provider: RerankProvider): Promise<void>;
|
|
626
|
+
clearEmbeddingProvider(): Promise<EmbeddingModelChangeEvent | null>;
|
|
627
|
+
clearRerankProvider(): Promise<void>;
|
|
628
|
+
onModelChange(listener: (event: EmbeddingModelChangeEvent) => void): () => void;
|
|
629
|
+
}
|
|
630
|
+
declare function createEmbeddingSession(): EmbeddingSession;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* ChatRuntimeBridge - the interface sanqian-chat ChatPanel consumes.
|
|
634
|
+
*
|
|
635
|
+
* Replaces CommonChatSdk + StreamHandlerSdk at the main-process IPC layer.
|
|
636
|
+
* The renderer ChatAdapter remains stable; only the IPC implementation
|
|
637
|
+
* routes through this bridge.
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
interface ResourceProviderInfo {
|
|
641
|
+
id: string;
|
|
642
|
+
name: string;
|
|
643
|
+
description: string;
|
|
644
|
+
appName: string;
|
|
645
|
+
hasGetList?: boolean;
|
|
646
|
+
hasGetCurrent?: boolean;
|
|
647
|
+
}
|
|
648
|
+
interface ResourceListRequest {
|
|
649
|
+
providerId: string;
|
|
650
|
+
query?: string;
|
|
651
|
+
offset?: number;
|
|
652
|
+
limit?: number;
|
|
653
|
+
}
|
|
654
|
+
interface ResourceListPage {
|
|
655
|
+
items: Array<{
|
|
656
|
+
id: string;
|
|
657
|
+
title: string;
|
|
658
|
+
summary?: string;
|
|
659
|
+
[key: string]: unknown;
|
|
660
|
+
}>;
|
|
661
|
+
hasMore?: boolean;
|
|
662
|
+
}
|
|
663
|
+
interface BridgeSessionResource {
|
|
664
|
+
id: string;
|
|
665
|
+
title: string;
|
|
666
|
+
content: string;
|
|
667
|
+
summary?: string;
|
|
668
|
+
}
|
|
669
|
+
interface RuntimeSessionResourceEvent {
|
|
670
|
+
type: 'resource_pushed' | 'resource_removed' | 'resources_cleared';
|
|
671
|
+
resource?: BridgeSessionResource;
|
|
672
|
+
resourceId?: string;
|
|
673
|
+
appName?: string;
|
|
674
|
+
}
|
|
675
|
+
interface ChatRuntimeBridge {
|
|
676
|
+
ensureReady(): Promise<void>;
|
|
677
|
+
isConnected(): boolean;
|
|
678
|
+
getRuntimeState(): AiFeatureRuntimeState;
|
|
679
|
+
getCapabilities(): RuntimeProviderCapabilities;
|
|
680
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
681
|
+
cancelStream?(input: {
|
|
682
|
+
streamId?: string;
|
|
683
|
+
runId?: string;
|
|
684
|
+
}): Promise<void>;
|
|
685
|
+
sendPermissionResponse?(input: RuntimePermissionResponse): Promise<void>;
|
|
686
|
+
listConversations(input: ListConversationsInput): Promise<ConversationPage>;
|
|
687
|
+
getConversation(id: string, input?: GetConversationInput): Promise<ConversationDetail | null>;
|
|
688
|
+
deleteConversation(id: string): Promise<void>;
|
|
689
|
+
listResourceProviders?(): Promise<ResourceProviderInfo[]>;
|
|
690
|
+
getResourceList?(input: ResourceListRequest): Promise<ResourceListPage>;
|
|
691
|
+
getSessionResources?(): BridgeSessionResource[];
|
|
692
|
+
fetchSessionResources?(agentId?: string): Promise<BridgeSessionResource[]>;
|
|
693
|
+
removeSessionResource?(id: string): Promise<void>;
|
|
694
|
+
onSessionResourceEvent?(listener: (event: RuntimeSessionResourceEvent) => void): () => void;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Resolve AI feature visibility from runtime state.
|
|
698
|
+
*
|
|
699
|
+
* showAIFeatures=auto means:
|
|
700
|
+
* - show if runtime provider is configured and ready, OR
|
|
701
|
+
* - show if Sanqian is installed and usable
|
|
702
|
+
*/
|
|
703
|
+
declare function resolveAiFeaturesFromRuntime(preference: 'auto' | 'enabled' | 'disabled', runtimeState: AiFeatureRuntimeState, sanqianInstalled: boolean): boolean;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* ChatRuntimeBridge implementation -- connects RuntimeSessionManager
|
|
707
|
+
* to the ChatRuntimeBridge interface that sanqian-chat ChatPanel consumes.
|
|
708
|
+
*
|
|
709
|
+
* Manages:
|
|
710
|
+
* - Stream ID -> AbortController mapping (replaces Notes' activeStreams map)
|
|
711
|
+
* - Stream ID -> runId mapping (for HITL routing)
|
|
712
|
+
* - Capability-gated resource/session methods
|
|
713
|
+
* - Conversation routing through ConversationStore
|
|
714
|
+
*/
|
|
715
|
+
|
|
716
|
+
interface ActiveStream {
|
|
717
|
+
streamId: string;
|
|
718
|
+
runId: string | null;
|
|
719
|
+
abortController: AbortController;
|
|
720
|
+
cancelled: boolean;
|
|
721
|
+
}
|
|
722
|
+
interface ChatRuntimeBridgeConfig {
|
|
723
|
+
sessionManager: RuntimeSessionManager;
|
|
724
|
+
conversationStore: ConversationStore;
|
|
725
|
+
permissionGate?: PermissionGate;
|
|
726
|
+
}
|
|
727
|
+
declare function createChatRuntimeBridge(config: ChatRuntimeBridgeConfig): ChatRuntimeBridge & {
|
|
728
|
+
/** Visible for testing: active stream tracking */
|
|
729
|
+
getActiveStreams(): Map<string, ActiveStream>;
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Output Operations Queue - manages formatter tool output operations.
|
|
734
|
+
*
|
|
735
|
+
* Mirrors Notes' editor-agent.ts: initTaskOutput -> queueOp -> commitTaskOutput.
|
|
736
|
+
* The pipeline initializes a pending ops queue per task, formatter tools
|
|
737
|
+
* append operations, and on completion the queue is committed (sent to editor).
|
|
738
|
+
*/
|
|
739
|
+
type OutputOperationType = 'paragraph' | 'list' | 'table' | 'html' | 'heading' | 'codeBlock' | 'blockquote' | 'noteRef';
|
|
740
|
+
interface OutputOperation {
|
|
741
|
+
type: OutputOperationType;
|
|
742
|
+
content: unknown;
|
|
743
|
+
}
|
|
744
|
+
interface EditorOutputContext {
|
|
745
|
+
targetBlockId: string;
|
|
746
|
+
blockIds?: string[];
|
|
747
|
+
pageId: string;
|
|
748
|
+
notebookId: string | null;
|
|
749
|
+
processMode: 'append' | 'replace';
|
|
750
|
+
outputBlockId: string | null;
|
|
751
|
+
}
|
|
752
|
+
interface PendingOutputOps {
|
|
753
|
+
context: EditorOutputContext;
|
|
754
|
+
operations: OutputOperation[];
|
|
755
|
+
}
|
|
756
|
+
interface InsertOutputData {
|
|
757
|
+
taskId: string;
|
|
758
|
+
context: EditorOutputContext;
|
|
759
|
+
operations: OutputOperation[];
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Validate output operation content structure.
|
|
763
|
+
* Returns error message if invalid, null if valid.
|
|
764
|
+
*/
|
|
765
|
+
declare function validateOutputContent(type: OutputOperationType, content: unknown): string | null;
|
|
766
|
+
/**
|
|
767
|
+
* Output Operations Manager - manages pending operations per task.
|
|
768
|
+
*
|
|
769
|
+
* Lifecycle:
|
|
770
|
+
* 1. initTaskOutput(taskId, context) -- create pending queue
|
|
771
|
+
* 2. queueOp(taskId, type, content) -- formatter tools call this
|
|
772
|
+
* 3. commitTaskOutput(taskId) -- flush to editor
|
|
773
|
+
* 4. clearTaskOutput(taskId) -- discard on cancel/error
|
|
774
|
+
*/
|
|
775
|
+
interface OutputOperationsManager {
|
|
776
|
+
initTaskOutput(taskId: string, context: EditorOutputContext): void;
|
|
777
|
+
queueOp(taskId: string, type: OutputOperationType, content: unknown): {
|
|
778
|
+
success: boolean;
|
|
779
|
+
error?: string;
|
|
780
|
+
};
|
|
781
|
+
getTaskOutput(taskId: string): PendingOutputOps | null;
|
|
782
|
+
commitTaskOutput(taskId: string): InsertOutputData | null;
|
|
783
|
+
clearTaskOutput(taskId: string): void;
|
|
784
|
+
}
|
|
785
|
+
declare function createOutputOperationsManager(): OutputOperationsManager;
|
|
786
|
+
|
|
787
|
+
interface SdkToolDefinition {
|
|
788
|
+
name: string;
|
|
789
|
+
description: string;
|
|
790
|
+
parameters?: Record<string, unknown>;
|
|
791
|
+
handler?: (args: Record<string, unknown>) => Promise<unknown>;
|
|
792
|
+
}
|
|
793
|
+
interface SdkContextProvider {
|
|
794
|
+
id: string;
|
|
795
|
+
name: string;
|
|
796
|
+
description: string;
|
|
797
|
+
getCurrent?: () => Promise<{
|
|
798
|
+
content: string;
|
|
799
|
+
} | null>;
|
|
800
|
+
getList?: (options?: {
|
|
801
|
+
query?: string;
|
|
802
|
+
offset?: number;
|
|
803
|
+
limit?: number;
|
|
804
|
+
}) => Promise<{
|
|
805
|
+
items: Array<{
|
|
806
|
+
id: string;
|
|
807
|
+
title: string;
|
|
808
|
+
summary?: string;
|
|
809
|
+
[key: string]: unknown;
|
|
810
|
+
}>;
|
|
811
|
+
hasMore?: boolean;
|
|
812
|
+
}>;
|
|
813
|
+
getById?: (id: string) => Promise<{
|
|
814
|
+
id: string;
|
|
815
|
+
content: string;
|
|
816
|
+
title?: string;
|
|
817
|
+
[key: string]: unknown;
|
|
818
|
+
} | null>;
|
|
819
|
+
}
|
|
820
|
+
interface SdkAgentConfig {
|
|
821
|
+
agent_id: string;
|
|
822
|
+
name: string;
|
|
823
|
+
description?: string;
|
|
824
|
+
system_prompt?: string;
|
|
825
|
+
tools?: string[];
|
|
826
|
+
skills?: string[];
|
|
827
|
+
attached_contexts?: string[];
|
|
828
|
+
}
|
|
829
|
+
interface SdkChatMessage {
|
|
830
|
+
role: 'user' | 'assistant' | 'system';
|
|
831
|
+
content: string;
|
|
832
|
+
}
|
|
833
|
+
interface SdkChatResponse {
|
|
834
|
+
message: {
|
|
835
|
+
content: string;
|
|
836
|
+
role: string;
|
|
837
|
+
};
|
|
838
|
+
conversationId: string;
|
|
839
|
+
title?: string;
|
|
840
|
+
usage?: {
|
|
841
|
+
prompt_tokens?: number;
|
|
842
|
+
completion_tokens?: number;
|
|
843
|
+
total_tokens?: number;
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
interface SdkChatStreamEvent {
|
|
847
|
+
type: 'start' | 'text' | 'thinking' | 'tool_call' | 'tool_args_chunk' | 'tool_args' | 'tool_result' | 'done' | 'error' | 'interrupt' | 'cancelled';
|
|
848
|
+
content?: string;
|
|
849
|
+
tool_call?: {
|
|
850
|
+
id: string;
|
|
851
|
+
function: {
|
|
852
|
+
name: string;
|
|
853
|
+
arguments: string;
|
|
854
|
+
};
|
|
855
|
+
};
|
|
856
|
+
tool_call_id?: string;
|
|
857
|
+
tool_name?: string;
|
|
858
|
+
chunk?: string;
|
|
859
|
+
args?: Record<string, unknown>;
|
|
860
|
+
result?: unknown;
|
|
861
|
+
success?: boolean;
|
|
862
|
+
error?: string;
|
|
863
|
+
status?: string;
|
|
864
|
+
conversationId?: string;
|
|
865
|
+
title?: string;
|
|
866
|
+
run_id?: string;
|
|
867
|
+
interrupt_type?: string;
|
|
868
|
+
interrupt_payload?: unknown;
|
|
869
|
+
action_required?: string;
|
|
870
|
+
settings_tab?: string;
|
|
871
|
+
settings_sub_tab?: string;
|
|
872
|
+
command_exit_code?: number;
|
|
873
|
+
duration_ms?: number;
|
|
874
|
+
sandboxed?: boolean;
|
|
875
|
+
timed_out?: boolean;
|
|
876
|
+
truncated?: boolean;
|
|
877
|
+
stdout_path?: string;
|
|
878
|
+
stderr_path?: string;
|
|
879
|
+
presentation?: string;
|
|
880
|
+
}
|
|
881
|
+
interface SdkConversationInfo {
|
|
882
|
+
conversation_id: string;
|
|
883
|
+
agent_id: string;
|
|
884
|
+
title?: string;
|
|
885
|
+
message_count: number;
|
|
886
|
+
created_at?: string;
|
|
887
|
+
updated_at?: string;
|
|
888
|
+
}
|
|
889
|
+
interface SdkConversationDetail extends SdkConversationInfo {
|
|
890
|
+
messages?: Array<{
|
|
891
|
+
id: string;
|
|
892
|
+
role: string;
|
|
893
|
+
content: string;
|
|
894
|
+
tool_calls?: unknown;
|
|
895
|
+
tool_call_id?: string | null;
|
|
896
|
+
thinking?: string | null;
|
|
897
|
+
created_at?: string;
|
|
898
|
+
message_id?: number;
|
|
899
|
+
}>;
|
|
900
|
+
}
|
|
901
|
+
interface SdkHitlResponse {
|
|
902
|
+
approved?: boolean;
|
|
903
|
+
remember?: boolean;
|
|
904
|
+
answer?: string;
|
|
905
|
+
selected_indices?: number[];
|
|
906
|
+
cancelled?: boolean;
|
|
907
|
+
timed_out?: boolean;
|
|
908
|
+
}
|
|
909
|
+
interface SdkSessionResource {
|
|
910
|
+
id?: string;
|
|
911
|
+
title: string;
|
|
912
|
+
content: string;
|
|
913
|
+
summary?: string;
|
|
914
|
+
}
|
|
915
|
+
interface SdkStoredSessionResource extends SdkSessionResource {
|
|
916
|
+
fullId: string;
|
|
917
|
+
appName: string;
|
|
918
|
+
pushedAt: string;
|
|
919
|
+
}
|
|
920
|
+
interface SdkEmbeddingConfig {
|
|
921
|
+
available: boolean;
|
|
922
|
+
apiUrl?: string;
|
|
923
|
+
apiKey?: string;
|
|
924
|
+
modelName?: string;
|
|
925
|
+
dimensions?: number;
|
|
926
|
+
}
|
|
927
|
+
interface SdkRerankConfig {
|
|
928
|
+
available: boolean;
|
|
929
|
+
apiUrl?: string;
|
|
930
|
+
apiKey?: string;
|
|
931
|
+
modelName?: string;
|
|
932
|
+
}
|
|
933
|
+
type SdkEventName = 'connected' | 'disconnected' | 'registered' | 'error' | 'tool_call' | 'resourcePushed' | 'resourceRemoved';
|
|
934
|
+
interface SanqianSdkPort {
|
|
935
|
+
connect(): Promise<void>;
|
|
936
|
+
disconnect(): Promise<void>;
|
|
937
|
+
ensureReady(): Promise<void>;
|
|
938
|
+
isConnected(): boolean;
|
|
939
|
+
acquireReconnect(): void;
|
|
940
|
+
releaseReconnect(): void;
|
|
941
|
+
on(event: SdkEventName, handler: (...args: unknown[]) => void): void;
|
|
942
|
+
off(event: SdkEventName, handler: (...args: unknown[]) => void): void;
|
|
943
|
+
removeAllListeners(): void;
|
|
944
|
+
createAgent(config: SdkAgentConfig): Promise<{
|
|
945
|
+
agent_id: string;
|
|
946
|
+
}>;
|
|
947
|
+
chat(agentId: string, messages: SdkChatMessage[], options?: {
|
|
948
|
+
conversationId?: string;
|
|
949
|
+
persistHistory?: boolean;
|
|
950
|
+
}): Promise<SdkChatResponse>;
|
|
951
|
+
chatStream(agentId: string, messages: SdkChatMessage[], options?: {
|
|
952
|
+
conversationId?: string;
|
|
953
|
+
persistHistory?: boolean;
|
|
954
|
+
attachedContexts?: string[];
|
|
955
|
+
attachedResources?: string[];
|
|
956
|
+
sessionResources?: string[];
|
|
957
|
+
signal?: AbortSignal;
|
|
958
|
+
}): AsyncGenerator<SdkChatStreamEvent>;
|
|
959
|
+
cancelRun(runId: string): void;
|
|
960
|
+
sendHitlResponse(runId: string, response: SdkHitlResponse): void;
|
|
961
|
+
listConversations(options: {
|
|
962
|
+
agentId?: string;
|
|
963
|
+
limit?: number;
|
|
964
|
+
offset?: number;
|
|
965
|
+
}): Promise<{
|
|
966
|
+
conversations: SdkConversationInfo[];
|
|
967
|
+
total: number;
|
|
968
|
+
}>;
|
|
969
|
+
getConversation(id: string, options?: {
|
|
970
|
+
messageLimit?: number;
|
|
971
|
+
}): Promise<SdkConversationDetail>;
|
|
972
|
+
deleteConversation(id: string): Promise<void>;
|
|
973
|
+
getSessionResources(): SdkStoredSessionResource[];
|
|
974
|
+
pushResource(resource: SdkSessionResource): Promise<SdkStoredSessionResource>;
|
|
975
|
+
removeResource(resourceId: string): Promise<void>;
|
|
976
|
+
fetchSessionResources?(agentId?: string): Promise<SdkStoredSessionResource[]>;
|
|
977
|
+
getEmbeddingConfig(): Promise<SdkEmbeddingConfig>;
|
|
978
|
+
getRerankConfig(): Promise<SdkRerankConfig>;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* SanqianProvider - RuntimeProvider backed by @yushaw/sanqian-sdk.
|
|
983
|
+
*
|
|
984
|
+
* Absorbs the responsibilities of SanqianAppClient:
|
|
985
|
+
* - App registration with tools and contexts
|
|
986
|
+
* - Private agent sync (assistant, writing, generator, formatter)
|
|
987
|
+
* - Chat streaming with AbortSignal forwarding
|
|
988
|
+
* - Event conversion to RuntimeStreamEvent
|
|
989
|
+
* - Conversation proxy
|
|
990
|
+
* - HITL proxy
|
|
991
|
+
* - Session resource proxy
|
|
992
|
+
* - Embedding/rerank config fetch
|
|
993
|
+
*/
|
|
994
|
+
|
|
995
|
+
interface SanqianProviderConfig {
|
|
996
|
+
/** Provider instance ID */
|
|
997
|
+
id?: string;
|
|
998
|
+
/** Display name */
|
|
999
|
+
displayName?: string;
|
|
1000
|
+
/** App name for Sanqian registration */
|
|
1001
|
+
appName: string;
|
|
1002
|
+
/** App version */
|
|
1003
|
+
appVersion: string;
|
|
1004
|
+
/** SDK port (inject for testing, or create from real SDK) */
|
|
1005
|
+
sdk: SanqianSdkPort;
|
|
1006
|
+
/** Agent configs to register */
|
|
1007
|
+
agents?: RuntimeAgentConfig[];
|
|
1008
|
+
/** Tool definitions to register with Sanqian */
|
|
1009
|
+
tools?: SdkToolDefinition[];
|
|
1010
|
+
/** Context providers to register with Sanqian */
|
|
1011
|
+
contexts?: SdkContextProvider[];
|
|
1012
|
+
}
|
|
1013
|
+
declare class SanqianProvider implements RuntimeProvider {
|
|
1014
|
+
readonly id: string;
|
|
1015
|
+
readonly kind: RuntimeProviderKind;
|
|
1016
|
+
readonly displayName: string;
|
|
1017
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
1018
|
+
private sdk;
|
|
1019
|
+
private appName;
|
|
1020
|
+
private agentConfigs;
|
|
1021
|
+
private agentIdResolver;
|
|
1022
|
+
private disposed;
|
|
1023
|
+
private ready;
|
|
1024
|
+
private connectionStatus;
|
|
1025
|
+
private connectionError;
|
|
1026
|
+
private connectionErrorCode;
|
|
1027
|
+
private connectionLastChangedAt;
|
|
1028
|
+
private readonly connectionListeners;
|
|
1029
|
+
private readonly handleSdkConnected;
|
|
1030
|
+
private readonly handleSdkDisconnected;
|
|
1031
|
+
private readonly handleSdkError;
|
|
1032
|
+
constructor(config: SanqianProviderConfig);
|
|
1033
|
+
ensureReady(): Promise<void>;
|
|
1034
|
+
dispose(): Promise<void>;
|
|
1035
|
+
isDisposed(): boolean;
|
|
1036
|
+
private syncAgents;
|
|
1037
|
+
/**
|
|
1038
|
+
* Get the registered Sanqian agent ID for a runtime agent ID.
|
|
1039
|
+
*/
|
|
1040
|
+
resolveAgentId(shortId: string): Promise<string>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Get the runtime agent ID for a registered Sanqian agent ID.
|
|
1043
|
+
*/
|
|
1044
|
+
normalizeAgentId(registeredId: string): string;
|
|
1045
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
1046
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
1047
|
+
cancel(runId: string): Promise<void>;
|
|
1048
|
+
sendPermissionResponse(input: RuntimePermissionResponse): Promise<void>;
|
|
1049
|
+
listConversations(options?: {
|
|
1050
|
+
agentId?: string;
|
|
1051
|
+
limit?: number;
|
|
1052
|
+
offset?: number;
|
|
1053
|
+
}): Promise<{
|
|
1054
|
+
conversations: SdkConversationInfo[];
|
|
1055
|
+
total: number;
|
|
1056
|
+
}>;
|
|
1057
|
+
getConversation(id: string, options?: {
|
|
1058
|
+
messageLimit?: number;
|
|
1059
|
+
}): Promise<SdkConversationDetail>;
|
|
1060
|
+
deleteConversation(id: string): Promise<void>;
|
|
1061
|
+
getSessionResources(): SdkStoredSessionResource[];
|
|
1062
|
+
pushResource(resource: SdkSessionResource): Promise<SdkStoredSessionResource>;
|
|
1063
|
+
removeResource(resourceId: string): Promise<void>;
|
|
1064
|
+
getEmbeddingConfig(): Promise<SdkEmbeddingConfig | null>;
|
|
1065
|
+
getRerankConfig(): Promise<SdkRerankConfig | null>;
|
|
1066
|
+
acquireReconnect(): void;
|
|
1067
|
+
releaseReconnect(): void;
|
|
1068
|
+
isConnected(): boolean;
|
|
1069
|
+
getConnectionSnapshot(): RuntimeConnectionSnapshot;
|
|
1070
|
+
onConnectionChange(callback: (snapshot: RuntimeConnectionSnapshot) => void): () => void;
|
|
1071
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
1072
|
+
off(event: string, handler: (...args: unknown[]) => void): void;
|
|
1073
|
+
listAvailableAgents(): Promise<unknown[]>;
|
|
1074
|
+
private ensureNotDisposed;
|
|
1075
|
+
private registerConnectionEvents;
|
|
1076
|
+
private unregisterConnectionEvents;
|
|
1077
|
+
private updateConnection;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Agent ID Resolver - maps short runtime agent IDs to Sanqian registered IDs.
|
|
1082
|
+
*
|
|
1083
|
+
* Sanqian registers agents with format "appName:agentId" (e.g. "sanqian-notes:assistant").
|
|
1084
|
+
* The runtime uses short IDs ("assistant", "writing", etc.).
|
|
1085
|
+
* This resolver bridges the two.
|
|
1086
|
+
*/
|
|
1087
|
+
|
|
1088
|
+
declare function createSanqianAgentIdResolver(appName: string): AgentIdResolver & {
|
|
1089
|
+
setMapping(shortId: string, registeredId: string): void;
|
|
1090
|
+
clearMappings(): void;
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Convert Sanqian SDK stream events to RuntimeStreamEvent.
|
|
1095
|
+
*/
|
|
1096
|
+
|
|
1097
|
+
declare function convertSdkStreamEvent(event: SdkChatStreamEvent): RuntimeStreamEvent | null;
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* MockSanqianSdk - deterministic SDK mock for testing SanqianProvider.
|
|
1101
|
+
*
|
|
1102
|
+
* Simulates Sanqian backend behavior without network or real backend.
|
|
1103
|
+
*/
|
|
1104
|
+
|
|
1105
|
+
interface MockScenario {
|
|
1106
|
+
agentId?: string;
|
|
1107
|
+
chatResponse?: string;
|
|
1108
|
+
streamEvents?: SdkChatStreamEvent[];
|
|
1109
|
+
error?: string;
|
|
1110
|
+
}
|
|
1111
|
+
interface MockSdkConfig {
|
|
1112
|
+
appName?: string;
|
|
1113
|
+
connected?: boolean;
|
|
1114
|
+
readinessError?: string;
|
|
1115
|
+
scenarios?: MockScenario[];
|
|
1116
|
+
embeddingConfig?: SdkEmbeddingConfig;
|
|
1117
|
+
rerankConfig?: SdkRerankConfig;
|
|
1118
|
+
}
|
|
1119
|
+
declare class MockSanqianSdk implements SanqianSdkPort {
|
|
1120
|
+
private appName;
|
|
1121
|
+
private connected;
|
|
1122
|
+
private readinessError;
|
|
1123
|
+
private scenarios;
|
|
1124
|
+
private agents;
|
|
1125
|
+
private conversations;
|
|
1126
|
+
private sessionResources;
|
|
1127
|
+
private listeners;
|
|
1128
|
+
private embeddingConfig;
|
|
1129
|
+
private rerankConfig;
|
|
1130
|
+
readonly connectCalls: number[];
|
|
1131
|
+
readonly disconnectCalls: number[];
|
|
1132
|
+
readonly ensureReadyCalls: number[];
|
|
1133
|
+
readonly createAgentCalls: SdkAgentConfig[];
|
|
1134
|
+
readonly chatCalls: Array<{
|
|
1135
|
+
agentId: string;
|
|
1136
|
+
messages: SdkChatMessage[];
|
|
1137
|
+
options?: unknown;
|
|
1138
|
+
}>;
|
|
1139
|
+
readonly chatStreamCalls: Array<{
|
|
1140
|
+
agentId: string;
|
|
1141
|
+
messages: SdkChatMessage[];
|
|
1142
|
+
options?: unknown;
|
|
1143
|
+
}>;
|
|
1144
|
+
readonly cancelRunCalls: string[];
|
|
1145
|
+
readonly hitlResponseCalls: Array<{
|
|
1146
|
+
runId: string;
|
|
1147
|
+
response: SdkHitlResponse;
|
|
1148
|
+
}>;
|
|
1149
|
+
constructor(config?: MockSdkConfig);
|
|
1150
|
+
connect(): Promise<void>;
|
|
1151
|
+
disconnect(): Promise<void>;
|
|
1152
|
+
ensureReady(): Promise<void>;
|
|
1153
|
+
isConnected(): boolean;
|
|
1154
|
+
acquireReconnect(): void;
|
|
1155
|
+
releaseReconnect(): void;
|
|
1156
|
+
on(event: SdkEventName, handler: (...args: unknown[]) => void): void;
|
|
1157
|
+
off(event: SdkEventName, handler: (...args: unknown[]) => void): void;
|
|
1158
|
+
removeAllListeners(): void;
|
|
1159
|
+
private emit;
|
|
1160
|
+
createAgent(config: SdkAgentConfig): Promise<{
|
|
1161
|
+
agent_id: string;
|
|
1162
|
+
}>;
|
|
1163
|
+
chat(agentId: string, messages: SdkChatMessage[], options?: {
|
|
1164
|
+
conversationId?: string;
|
|
1165
|
+
persistHistory?: boolean;
|
|
1166
|
+
}): Promise<SdkChatResponse>;
|
|
1167
|
+
chatStream(agentId: string, messages: SdkChatMessage[], options?: {
|
|
1168
|
+
conversationId?: string;
|
|
1169
|
+
signal?: AbortSignal;
|
|
1170
|
+
attachedResources?: string[];
|
|
1171
|
+
sessionResources?: string[];
|
|
1172
|
+
}): AsyncGenerator<SdkChatStreamEvent>;
|
|
1173
|
+
cancelRun(runId: string): void;
|
|
1174
|
+
sendHitlResponse(runId: string, response: SdkHitlResponse): void;
|
|
1175
|
+
listConversations(options: {
|
|
1176
|
+
agentId?: string;
|
|
1177
|
+
limit?: number;
|
|
1178
|
+
offset?: number;
|
|
1179
|
+
}): Promise<{
|
|
1180
|
+
conversations: SdkConversationInfo[];
|
|
1181
|
+
total: number;
|
|
1182
|
+
}>;
|
|
1183
|
+
getConversation(id: string): Promise<SdkConversationDetail>;
|
|
1184
|
+
deleteConversation(id: string): Promise<void>;
|
|
1185
|
+
/** Test helper: seed a conversation */
|
|
1186
|
+
seedConversation(detail: SdkConversationDetail): void;
|
|
1187
|
+
getSessionResources(): SdkStoredSessionResource[];
|
|
1188
|
+
pushResource(resource: SdkSessionResource): Promise<SdkStoredSessionResource>;
|
|
1189
|
+
removeResource(resourceId: string): Promise<void>;
|
|
1190
|
+
fetchSessionResources(): Promise<SdkStoredSessionResource[]>;
|
|
1191
|
+
getEmbeddingConfig(): Promise<SdkEmbeddingConfig>;
|
|
1192
|
+
getRerankConfig(): Promise<SdkRerankConfig>;
|
|
1193
|
+
private findScenario;
|
|
1194
|
+
/** Simulate readiness failure for testing rollback */
|
|
1195
|
+
setReadinessError(error: string | null): void;
|
|
1196
|
+
/** Force connection state for testing */
|
|
1197
|
+
setConnected(connected: boolean): void;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Sanqian Embedding Provider - uses embedding config from Sanqian backend.
|
|
1202
|
+
*
|
|
1203
|
+
* Calls OpenAI-compatible embedding API with config fetched from Sanqian SDK.
|
|
1204
|
+
* This is the same code path Notes currently uses in embedding/api.ts.
|
|
1205
|
+
*/
|
|
1206
|
+
|
|
1207
|
+
interface SanqianEmbeddingConfig {
|
|
1208
|
+
apiUrl: string;
|
|
1209
|
+
apiKey: string;
|
|
1210
|
+
modelName: string;
|
|
1211
|
+
dimensions: number;
|
|
1212
|
+
/** 'openai' | 'zhipu' | 'local' */
|
|
1213
|
+
apiType?: string;
|
|
1214
|
+
}
|
|
1215
|
+
declare class SanqianEmbeddingProvider implements EmbeddingProvider {
|
|
1216
|
+
readonly id: string;
|
|
1217
|
+
readonly model: string;
|
|
1218
|
+
readonly dimensions: number;
|
|
1219
|
+
private config;
|
|
1220
|
+
private disposed;
|
|
1221
|
+
constructor(config: SanqianEmbeddingConfig, id?: string);
|
|
1222
|
+
ensureReady(): Promise<void>;
|
|
1223
|
+
dispose(): Promise<void>;
|
|
1224
|
+
embedMany(texts: string[], options?: {
|
|
1225
|
+
signal?: AbortSignal;
|
|
1226
|
+
}): Promise<number[][]>;
|
|
1227
|
+
embed(text: string, options?: {
|
|
1228
|
+
signal?: AbortSignal;
|
|
1229
|
+
}): Promise<number[]>;
|
|
1230
|
+
test(): Promise<{
|
|
1231
|
+
success: boolean;
|
|
1232
|
+
dimensions?: number;
|
|
1233
|
+
error?: string;
|
|
1234
|
+
}>;
|
|
1235
|
+
private callApi;
|
|
1236
|
+
private callOllama;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* Sanqian Rerank Provider - calls rerank API with config from Sanqian backend.
|
|
1241
|
+
*
|
|
1242
|
+
* Supports Zhipu BigModel, Cohere, and other OpenAI-compatible rerank APIs.
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1245
|
+
interface SanqianRerankConfig {
|
|
1246
|
+
apiUrl: string;
|
|
1247
|
+
apiKey: string;
|
|
1248
|
+
modelName: string;
|
|
1249
|
+
}
|
|
1250
|
+
declare class SanqianRerankProvider implements RerankProvider {
|
|
1251
|
+
readonly id: string;
|
|
1252
|
+
readonly model: string;
|
|
1253
|
+
private config;
|
|
1254
|
+
private disposed;
|
|
1255
|
+
constructor(config: SanqianRerankConfig, id?: string);
|
|
1256
|
+
ensureReady(): Promise<void>;
|
|
1257
|
+
dispose(): Promise<void>;
|
|
1258
|
+
rerank(input: RerankInput, options?: {
|
|
1259
|
+
signal?: AbortSignal;
|
|
1260
|
+
}): Promise<RerankResult>;
|
|
1261
|
+
test(): Promise<{
|
|
1262
|
+
success: boolean;
|
|
1263
|
+
error?: string;
|
|
1264
|
+
}>;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* VercelProvider - RuntimeProvider backed by Vercel AI SDK.
|
|
1269
|
+
*
|
|
1270
|
+
* Uses @ai-sdk/openai-compatible for DeepSeek/OpenAI-compatible endpoints.
|
|
1271
|
+
* Supports local BYOK mode where users provide their own API keys.
|
|
1272
|
+
*
|
|
1273
|
+
* Key differences from SanqianProvider:
|
|
1274
|
+
* - Tool execution happens locally (not on a remote backend)
|
|
1275
|
+
* - Conversations are stored locally via ConversationStore
|
|
1276
|
+
* - HITL/permissions are enforced locally before tool execution
|
|
1277
|
+
* - No session resources or resource picker (capability-disabled)
|
|
1278
|
+
* - Formatter pipeline runs as two local streamText() calls
|
|
1279
|
+
*/
|
|
1280
|
+
|
|
1281
|
+
interface VercelProviderConfig {
|
|
1282
|
+
id?: string;
|
|
1283
|
+
displayName?: string;
|
|
1284
|
+
/** API key for the provider */
|
|
1285
|
+
apiKey: string;
|
|
1286
|
+
/** Base URL (e.g. https://api.deepseek.com) */
|
|
1287
|
+
baseURL: string;
|
|
1288
|
+
/** Model name (e.g. deepseek-chat) */
|
|
1289
|
+
model: string;
|
|
1290
|
+
/** Provider name for display */
|
|
1291
|
+
providerName?: string;
|
|
1292
|
+
/** Agent configs (system prompts, tool lists) */
|
|
1293
|
+
agents?: RuntimeAgentConfig[];
|
|
1294
|
+
/** Tool registry for local tool execution */
|
|
1295
|
+
toolRegistry?: RuntimeToolRegistry;
|
|
1296
|
+
/** Max tool call steps per request */
|
|
1297
|
+
maxSteps?: number;
|
|
1298
|
+
}
|
|
1299
|
+
declare class VercelProvider implements RuntimeProvider {
|
|
1300
|
+
readonly id: string;
|
|
1301
|
+
readonly kind: RuntimeProviderKind;
|
|
1302
|
+
readonly displayName: string;
|
|
1303
|
+
readonly capabilities: RuntimeProviderCapabilities;
|
|
1304
|
+
private apiKey;
|
|
1305
|
+
private baseURL;
|
|
1306
|
+
private modelName;
|
|
1307
|
+
private providerName;
|
|
1308
|
+
private agentConfigs;
|
|
1309
|
+
private toolRegistry;
|
|
1310
|
+
private maxSteps;
|
|
1311
|
+
private disposed;
|
|
1312
|
+
private ready;
|
|
1313
|
+
constructor(config: VercelProviderConfig);
|
|
1314
|
+
ensureReady(): Promise<void>;
|
|
1315
|
+
dispose(): Promise<void>;
|
|
1316
|
+
isDisposed(): boolean;
|
|
1317
|
+
chat(input: RuntimeChatRequest): Promise<RuntimeChatResponse>;
|
|
1318
|
+
chatStream(input: RuntimeChatStreamRequest): AsyncIterable<RuntimeStreamEvent>;
|
|
1319
|
+
cancel(_runId: string): Promise<void>;
|
|
1320
|
+
sendPermissionResponse(_input: RuntimePermissionResponse): Promise<void>;
|
|
1321
|
+
private createProvider;
|
|
1322
|
+
private buildMessages;
|
|
1323
|
+
private resolveTools;
|
|
1324
|
+
private redactSecrets;
|
|
1325
|
+
private ensureNotDisposed;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Convert runtime tool definitions to Vercel AI SDK tools.
|
|
1330
|
+
*
|
|
1331
|
+
* Bypasses the `tool()` helper because AI SDK v5/v6 has a bug where
|
|
1332
|
+
* `tool()` returns `{ parameters }` but `prepareToolsAndToolChoice`
|
|
1333
|
+
* reads `inputSchema` (vercel/ai#7924, PR #15249 -- canary only).
|
|
1334
|
+
*
|
|
1335
|
+
* Instead, we construct tool objects with `inputSchema` directly,
|
|
1336
|
+
* using zod v3 schemas for correct JSON Schema serialization.
|
|
1337
|
+
*/
|
|
1338
|
+
|
|
1339
|
+
interface VercelToolLike {
|
|
1340
|
+
type: 'function';
|
|
1341
|
+
description: string;
|
|
1342
|
+
inputSchema: z.ZodTypeAny;
|
|
1343
|
+
execute?: (args: Record<string, unknown>) => Promise<unknown>;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Convert runtime tool definitions to Vercel AI SDK-compatible tool objects.
|
|
1347
|
+
*
|
|
1348
|
+
* Returns objects with `inputSchema` (not `parameters`) to match what
|
|
1349
|
+
* `prepareToolsAndToolChoice` expects internally.
|
|
1350
|
+
*/
|
|
1351
|
+
declare function convertToolsForVercel(tools: RuntimeToolDefinition[], registry: RuntimeToolRegistry | null, options?: {
|
|
1352
|
+
signal?: AbortSignal;
|
|
1353
|
+
}): Record<string, VercelToolLike>;
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Vercel Embedding Provider - uses Vercel AI SDK's embedMany for BYOK mode.
|
|
1357
|
+
*
|
|
1358
|
+
* Wraps @ai-sdk/openai-compatible to call any OpenAI-compatible embedding API
|
|
1359
|
+
* using the host's own API key.
|
|
1360
|
+
*/
|
|
1361
|
+
|
|
1362
|
+
interface VercelEmbeddingConfig {
|
|
1363
|
+
apiKey: string;
|
|
1364
|
+
baseURL: string;
|
|
1365
|
+
model: string;
|
|
1366
|
+
dimensions: number;
|
|
1367
|
+
providerName?: string;
|
|
1368
|
+
}
|
|
1369
|
+
declare class VercelEmbeddingProvider implements EmbeddingProvider {
|
|
1370
|
+
readonly id: string;
|
|
1371
|
+
readonly model: string;
|
|
1372
|
+
readonly dimensions: number;
|
|
1373
|
+
private config;
|
|
1374
|
+
private disposed;
|
|
1375
|
+
constructor(config: VercelEmbeddingConfig, id?: string);
|
|
1376
|
+
ensureReady(): Promise<void>;
|
|
1377
|
+
dispose(): Promise<void>;
|
|
1378
|
+
embedMany(texts: string[], options?: {
|
|
1379
|
+
signal?: AbortSignal;
|
|
1380
|
+
}): Promise<number[][]>;
|
|
1381
|
+
embed(text: string, options?: {
|
|
1382
|
+
signal?: AbortSignal;
|
|
1383
|
+
}): Promise<number[]>;
|
|
1384
|
+
test(): Promise<{
|
|
1385
|
+
success: boolean;
|
|
1386
|
+
dimensions?: number;
|
|
1387
|
+
error?: string;
|
|
1388
|
+
}>;
|
|
1389
|
+
private createProvider;
|
|
1390
|
+
private redact;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
export { type ActiveRuntimeWork, type ActiveRuntimeWorkKind, type ActiveStream, type ActiveWorkTracker, type AgentExecutionMode, type AgentIdResolver, type AiFeatureRuntimeState, type AuthMode, type BillingMode, type BridgeSessionResource, type ChatRuntimeBridge, type ChatRuntimeBridgeConfig, type ConversationDetail, type ConversationInfo, type ConversationPage, type ConversationPatch, type ConversationStore, type CreateConversationInput, EMPTY_CAPABILITIES, type EditorOutputContext, type EmbeddingModelChangeEvent, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingSession, type ExecutionTarget, type GetConversationInput, type HistoryLocation, type InsertOutputData, type ListConversationsInput, MockSanqianSdk, type MockScenario, type MockSdkConfig, type OutputOperation, type OutputOperationType, type OutputOperationsManager, type PendingOutputOps, type PendingPermission, type PermissionDecision, type PermissionGate, type PermissionPolicy, type ProviderChangedEvent, type ProviderInstanceConfig, type RerankInput, type RerankProvider, type RerankResult, type RerankResultItem, type ResourceListPage, type ResourceListRequest, type ResourceProviderInfo, type RuntimeAgentConfig, type RuntimeAgentId, type RuntimeAgentRegistry, type RuntimeChatRequest, type RuntimeChatResponse, type RuntimeChatStreamRequest, type RuntimeConnectionErrorCode, type RuntimeConnectionSnapshot, type RuntimeConnectionStatus, type RuntimeContext, type RuntimeConversationMessage, type RuntimeHitlResponse, type RuntimeInterrupt, type RuntimeMessage, type RuntimePermissionResponse, type RuntimeProfile, type RuntimeProvider, type RuntimeProviderCapabilities, type RuntimeProviderDescriptor, type RuntimeProviderKind, type RuntimeResource, type RuntimeResourceRef, type RuntimeSecretStore, type RuntimeSessionManager, type RuntimeSessionResourceEvent, type RuntimeStreamEvent, type RuntimeTaskPipeline, type RuntimeTaskPipelineInput, type RuntimeToolCall, type RuntimeToolDefinition, type RuntimeToolExecutionContext, type RuntimeToolExecutionInput, type RuntimeToolExecutionMetadata, type RuntimeToolExecutionResult, type RuntimeToolHandler, type RuntimeToolMetadata, type RuntimeToolRegistration, type RuntimeToolRegistry, type RuntimeUsage, type SanqianEmbeddingConfig, SanqianEmbeddingProvider, SanqianProvider, type SanqianProviderConfig, type SanqianRerankConfig, SanqianRerankProvider, type SanqianSdkPort, type SecretDescriptor, type SecretRef, type StoreSecretInput, type SwitchOptions, type SwitchResult, type ToolCategory, type VercelEmbeddingConfig, VercelEmbeddingProvider, VercelProvider, type VercelProviderConfig, convertSdkStreamEvent, convertToolsForVercel, createActiveWorkTracker, createCategoryPermissionPolicy, createChatRuntimeBridge, createDefaultPermissionPolicy, createDisabledState, createEmbeddingSession, createMemoryConversationStore, createMemorySecretStore, createOutputOperationsManager, createPermissionGate, createSanqianAgentIdResolver, createSessionManager, createTaskPipeline, createToolRegistry, redactToolError, resolveAiFeaturesFromRuntime, validateOutputContent };
|