@yh-ui/ai-sdk 0.1.21
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/LICENSE +21 -0
- package/README.md +309 -0
- package/dist/agent-enhanced.cjs +292 -0
- package/dist/agent-enhanced.d.ts +143 -0
- package/dist/agent-enhanced.mjs +267 -0
- package/dist/cache-adapter.cjs +99 -0
- package/dist/cache-adapter.d.ts +42 -0
- package/dist/cache-adapter.mjs +95 -0
- package/dist/future.cjs +882 -0
- package/dist/future.d.ts +519 -0
- package/dist/future.mjs +765 -0
- package/dist/index.cjs +913 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.mjs +217 -0
- package/dist/langchain.cjs +363 -0
- package/dist/langchain.d.ts +232 -0
- package/dist/langchain.mjs +319 -0
- package/dist/loaders.cjs +110 -0
- package/dist/loaders.d.ts +58 -0
- package/dist/loaders.mjs +76 -0
- package/dist/mcp-server.cjs +265 -0
- package/dist/mcp-server.d.ts +186 -0
- package/dist/mcp-server.mjs +234 -0
- package/dist/mcp.cjs +370 -0
- package/dist/mcp.d.ts +206 -0
- package/dist/mcp.mjs +354 -0
- package/dist/observability.cjs +150 -0
- package/dist/observability.d.ts +112 -0
- package/dist/observability.mjs +117 -0
- package/dist/rag-production.cjs +95 -0
- package/dist/rag-production.d.ts +43 -0
- package/dist/rag-production.mjs +85 -0
- package/dist/rate-limit.cjs +73 -0
- package/dist/rate-limit.d.ts +55 -0
- package/dist/rate-limit.mjs +51 -0
- package/dist/vector-store.cjs +63 -0
- package/dist/vector-store.d.ts +74 -0
- package/dist/vector-store.mjs +55 -0
- package/dist/vue/index.cjs +1023 -0
- package/dist/vue/index.d.ts +627 -0
- package/dist/vue/index.mjs +913 -0
- package/package.json +87 -0
package/dist/future.d.ts
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YH-UI AI SDK - 前瞻性功能模块
|
|
3
|
+
*
|
|
4
|
+
* 面向 AI 发展未来的能力集成:
|
|
5
|
+
* - Agent 编排框架 (Plan-Execute, ReAct)
|
|
6
|
+
* - 多模态支持 (视觉/语音/视频理解)
|
|
7
|
+
* - RAG 检索增强生成
|
|
8
|
+
* - 思维链 CoT 推理
|
|
9
|
+
* - 智能上下文压缩
|
|
10
|
+
* - 成本控制
|
|
11
|
+
* - 可观测性
|
|
12
|
+
* - AI 安全护栏
|
|
13
|
+
*/
|
|
14
|
+
export interface AgentStep {
|
|
15
|
+
id: string;
|
|
16
|
+
type: 'thought' | 'action' | 'observation' | 'result';
|
|
17
|
+
content: string;
|
|
18
|
+
toolName?: string;
|
|
19
|
+
toolInput?: Record<string, unknown>;
|
|
20
|
+
toolOutput?: unknown;
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
}
|
|
23
|
+
export interface AgentConfig {
|
|
24
|
+
/** Agent 类型 */
|
|
25
|
+
type: 'react' | 'plan-execute' | 'chat';
|
|
26
|
+
/** 最大迭代次数 */
|
|
27
|
+
maxIterations?: number;
|
|
28
|
+
/** 最大工具调用次数 */
|
|
29
|
+
maxToolCalls?: number;
|
|
30
|
+
/** 是否返回推理过程 */
|
|
31
|
+
returnReasoning?: boolean;
|
|
32
|
+
/** 工具列表 */
|
|
33
|
+
tools?: AgentTool[];
|
|
34
|
+
/** 停止条件 */
|
|
35
|
+
stopConditions?: StopCondition[];
|
|
36
|
+
/** 错误处理 */
|
|
37
|
+
onError?: (error: Error, step: AgentStep) => void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export interface AgentTool {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
parameters: Record<string, unknown>;
|
|
43
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
44
|
+
}
|
|
45
|
+
export interface StopCondition {
|
|
46
|
+
type: 'max_iterations' | 'max_tool_calls' | 'contains' | 'custom';
|
|
47
|
+
value?: string | number | ((output: string) => boolean);
|
|
48
|
+
}
|
|
49
|
+
export interface AgentResult {
|
|
50
|
+
output: string;
|
|
51
|
+
reasoning?: AgentStep[];
|
|
52
|
+
toolCalls: number;
|
|
53
|
+
finished: boolean;
|
|
54
|
+
error?: Error;
|
|
55
|
+
}
|
|
56
|
+
export interface MultiModalContent {
|
|
57
|
+
type: 'text' | 'image' | 'audio' | 'video' | 'image_url';
|
|
58
|
+
text?: string;
|
|
59
|
+
url?: string;
|
|
60
|
+
base64?: string;
|
|
61
|
+
mimeType?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface MultiModalMessage {
|
|
64
|
+
role: 'user' | 'assistant';
|
|
65
|
+
content: MultiModalContent[];
|
|
66
|
+
}
|
|
67
|
+
export interface VisionAnalysisOptions {
|
|
68
|
+
/** 图像描述 */
|
|
69
|
+
detail?: 'low' | 'high' | 'auto';
|
|
70
|
+
/** 额外提示 */
|
|
71
|
+
prompt?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface DocumentChunk {
|
|
74
|
+
id: string;
|
|
75
|
+
content: string;
|
|
76
|
+
embedding?: number[];
|
|
77
|
+
metadata: Record<string, unknown>;
|
|
78
|
+
score?: number;
|
|
79
|
+
}
|
|
80
|
+
export interface RAGConfig {
|
|
81
|
+
/** 知识库 ID */
|
|
82
|
+
knowledgeBaseId?: string;
|
|
83
|
+
/** 检索文档数量 */
|
|
84
|
+
topK?: number;
|
|
85
|
+
/** 相似度阈值 */
|
|
86
|
+
similarityThreshold?: number;
|
|
87
|
+
/** 是否包含源信息 */
|
|
88
|
+
includeSources?: boolean;
|
|
89
|
+
/** 检索策略 */
|
|
90
|
+
strategy?: 'similarity' | 'mmr' | 'hybrid';
|
|
91
|
+
}
|
|
92
|
+
export interface RAGResult {
|
|
93
|
+
answer: string;
|
|
94
|
+
sources: Array<{
|
|
95
|
+
content: string;
|
|
96
|
+
metadata: Record<string, unknown>;
|
|
97
|
+
score: number;
|
|
98
|
+
}>;
|
|
99
|
+
contextUsed: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ReasoningStep {
|
|
102
|
+
id: string;
|
|
103
|
+
content: string;
|
|
104
|
+
type: 'analysis' | 'reflection' | 'conclusion' | 'action';
|
|
105
|
+
children?: ReasoningStep[];
|
|
106
|
+
}
|
|
107
|
+
export interface CoTConfig {
|
|
108
|
+
/** 推理模式 */
|
|
109
|
+
mode: 'standard' | 'chain' | 'tree' | 'tabular';
|
|
110
|
+
/** 最大深度 */
|
|
111
|
+
maxDepth?: number;
|
|
112
|
+
/** 是否显示置信度 */
|
|
113
|
+
showConfidence?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface CompressionConfig {
|
|
116
|
+
/** 压缩策略 */
|
|
117
|
+
strategy: 'summary' | 'extract' | 'prune';
|
|
118
|
+
/** 目标 token 数 */
|
|
119
|
+
targetTokens?: number;
|
|
120
|
+
/** 保留关键信息 */
|
|
121
|
+
preserveKeyInfo?: string[];
|
|
122
|
+
}
|
|
123
|
+
export interface CompressionResult {
|
|
124
|
+
compressedContent: string;
|
|
125
|
+
originalTokens: number;
|
|
126
|
+
compressedTokens: number;
|
|
127
|
+
compressionRatio: number;
|
|
128
|
+
extractedKeyInfo?: string[];
|
|
129
|
+
}
|
|
130
|
+
export interface TokenUsage {
|
|
131
|
+
prompt: number;
|
|
132
|
+
completion: number;
|
|
133
|
+
total: number;
|
|
134
|
+
cached?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface CostConfig {
|
|
137
|
+
/** 每月预算 (美元) */
|
|
138
|
+
monthlyBudget?: number;
|
|
139
|
+
/** 单次请求最大 token */
|
|
140
|
+
maxTokensPerRequest?: number;
|
|
141
|
+
/** 警告阈值 */
|
|
142
|
+
warningThreshold?: number;
|
|
143
|
+
}
|
|
144
|
+
export interface CostTracking {
|
|
145
|
+
totalCost: number;
|
|
146
|
+
dailyCost: Record<string, number>;
|
|
147
|
+
usage: TokenUsage;
|
|
148
|
+
budget: CostConfig;
|
|
149
|
+
remaining: number;
|
|
150
|
+
}
|
|
151
|
+
export interface TraceEvent {
|
|
152
|
+
id: string;
|
|
153
|
+
type: 'request' | 'response' | 'tool_call' | 'tool_result' | 'error' | 'custom';
|
|
154
|
+
timestamp: Date;
|
|
155
|
+
data: Record<string, unknown>;
|
|
156
|
+
duration?: number;
|
|
157
|
+
parentId?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface TraceSpan {
|
|
160
|
+
id: string;
|
|
161
|
+
name: string;
|
|
162
|
+
startTime: Date;
|
|
163
|
+
endTime?: Date;
|
|
164
|
+
events: TraceEvent[];
|
|
165
|
+
attributes: Record<string, unknown>;
|
|
166
|
+
children: TraceSpan[];
|
|
167
|
+
}
|
|
168
|
+
export interface SafetyRule {
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
type: 'content_filter' | 'input_validation' | 'output_filter' | 'tool_permission';
|
|
172
|
+
pattern?: string | RegExp;
|
|
173
|
+
customCheck?: (content: string) => boolean | Promise<boolean>;
|
|
174
|
+
action: 'block' | 'warn' | 'replace';
|
|
175
|
+
replacement?: string;
|
|
176
|
+
}
|
|
177
|
+
export interface SafetyResult {
|
|
178
|
+
passed: boolean;
|
|
179
|
+
violations: Array<{
|
|
180
|
+
rule: SafetyRule;
|
|
181
|
+
content: string;
|
|
182
|
+
action: 'blocked' | 'warned' | 'replaced';
|
|
183
|
+
replacedContent?: string;
|
|
184
|
+
}>;
|
|
185
|
+
}
|
|
186
|
+
export interface SchemaDefinition {
|
|
187
|
+
type: 'object' | 'array' | 'union';
|
|
188
|
+
properties?: Record<string, SchemaProperty>;
|
|
189
|
+
required?: string[];
|
|
190
|
+
description?: string;
|
|
191
|
+
}
|
|
192
|
+
export interface SchemaProperty {
|
|
193
|
+
type: string;
|
|
194
|
+
description?: string;
|
|
195
|
+
enum?: string[];
|
|
196
|
+
items?: SchemaProperty;
|
|
197
|
+
properties?: Record<string, SchemaProperty>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* ReAct Agent - 推理 + 行动
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const { run, steps, isRunning } = useReActAgent({
|
|
205
|
+
* tools: [searchTool, calculatorTool],
|
|
206
|
+
* maxIterations: 10,
|
|
207
|
+
* returnReasoning: true
|
|
208
|
+
* })
|
|
209
|
+
*
|
|
210
|
+
* const result = await run('北京的人口是多少?用中文回答')
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export declare function useReActAgent(config: AgentConfig): {
|
|
214
|
+
steps: import("vue").Ref<{
|
|
215
|
+
id: string;
|
|
216
|
+
type: "thought" | "action" | "observation" | "result";
|
|
217
|
+
content: string;
|
|
218
|
+
toolName?: string | undefined;
|
|
219
|
+
toolInput?: Record<string, unknown> | undefined;
|
|
220
|
+
toolOutput?: unknown;
|
|
221
|
+
timestamp: Date;
|
|
222
|
+
}[], AgentStep[] | {
|
|
223
|
+
id: string;
|
|
224
|
+
type: "thought" | "action" | "observation" | "result";
|
|
225
|
+
content: string;
|
|
226
|
+
toolName?: string | undefined;
|
|
227
|
+
toolInput?: Record<string, unknown> | undefined;
|
|
228
|
+
toolOutput?: unknown;
|
|
229
|
+
timestamp: Date;
|
|
230
|
+
}[]>;
|
|
231
|
+
isRunning: import("vue").Ref<boolean, boolean>;
|
|
232
|
+
currentOutput: import("vue").Ref<string, string>;
|
|
233
|
+
toolCallCount: import("vue").Ref<number, number>;
|
|
234
|
+
run: (input: string, executeFn: (prompt: string) => Promise<string>) => Promise<AgentResult>;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Plan-Execute Agent - 计划 + 执行
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* const agent = createPlanExecuteAgent({
|
|
242
|
+
* tools: [searchTool, calculatorTool]
|
|
243
|
+
* })
|
|
244
|
+
*
|
|
245
|
+
* const result = await agent.execute('帮我查北京人口,然后计算增长')
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare function createPlanExecuteAgent(config: {
|
|
249
|
+
tools?: AgentTool[];
|
|
250
|
+
maxSteps?: number;
|
|
251
|
+
}): {
|
|
252
|
+
plans: import("vue").Ref<{
|
|
253
|
+
id: string;
|
|
254
|
+
description: string;
|
|
255
|
+
status: "pending" | "completed" | "failed";
|
|
256
|
+
}[], {
|
|
257
|
+
id: string;
|
|
258
|
+
description: string;
|
|
259
|
+
status: "pending" | "completed" | "failed";
|
|
260
|
+
}[] | {
|
|
261
|
+
id: string;
|
|
262
|
+
description: string;
|
|
263
|
+
status: "pending" | "completed" | "failed";
|
|
264
|
+
}[]>;
|
|
265
|
+
currentPlan: import("vue").Ref<string | null, string | null>;
|
|
266
|
+
results: import("vue").Ref<Record<string, unknown>, Record<string, unknown>>;
|
|
267
|
+
execute: (task: string, llm: (prompt: string) => Promise<string>) => Promise<{
|
|
268
|
+
result: string;
|
|
269
|
+
plan: {
|
|
270
|
+
id: string;
|
|
271
|
+
description: string;
|
|
272
|
+
status: "pending" | "completed" | "failed";
|
|
273
|
+
}[];
|
|
274
|
+
results: Record<string, unknown>;
|
|
275
|
+
}>;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* 创建多模态消息
|
|
279
|
+
*/
|
|
280
|
+
export declare function createMultiModalMessage(role: 'user' | 'assistant', contents: MultiModalContent[]): MultiModalMessage;
|
|
281
|
+
/**
|
|
282
|
+
* 从文件创建图像内容
|
|
283
|
+
*/
|
|
284
|
+
export declare function createImageContent(source: 'url' | 'base64', value: string, mimeType?: string): MultiModalContent;
|
|
285
|
+
/**
|
|
286
|
+
* 图像 URL 内容
|
|
287
|
+
*/
|
|
288
|
+
export declare function createImageUrlContent(url: string, detail?: 'low' | 'high' | 'auto'): MultiModalContent;
|
|
289
|
+
/**
|
|
290
|
+
* 音频内容
|
|
291
|
+
*/
|
|
292
|
+
export declare function createAudioContent(base64: string, mimeType?: string): MultiModalContent;
|
|
293
|
+
/**
|
|
294
|
+
* 视频内容
|
|
295
|
+
*/
|
|
296
|
+
export declare function createVideoContent(base64: string, mimeType?: string): MultiModalContent;
|
|
297
|
+
/**
|
|
298
|
+
* 创建 RAG 系统
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* const rag = createRAGSystem({
|
|
303
|
+
* knowledgeBaseId: 'my-kb',
|
|
304
|
+
* topK: 5,
|
|
305
|
+
* similarityThreshold: 0.7
|
|
306
|
+
* })
|
|
307
|
+
*
|
|
308
|
+
* const result = await rag.query('什么是 TypeScript?')
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export declare function createRAGSystem(config: RAGConfig): {
|
|
312
|
+
addDocuments: (documents: Array<{
|
|
313
|
+
content: string;
|
|
314
|
+
metadata?: Record<string, unknown>;
|
|
315
|
+
}>) => Promise<DocumentChunk[]>;
|
|
316
|
+
retrieve: (query: string, k?: number) => Promise<DocumentChunk[]>;
|
|
317
|
+
query: (question: string, llm: (prompt: string) => Promise<string>) => Promise<RAGResult>;
|
|
318
|
+
clear: () => void;
|
|
319
|
+
config: {
|
|
320
|
+
topK: number;
|
|
321
|
+
similarityThreshold: number;
|
|
322
|
+
strategy: "similarity" | "mmr" | "hybrid";
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* 创建思维链推理器
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```ts
|
|
330
|
+
* const cot = createChainOfThought({
|
|
331
|
+
* mode: 'chain',
|
|
332
|
+
* showConfidence: true
|
|
333
|
+
* })
|
|
334
|
+
*
|
|
335
|
+
* const result = await cot.think('分析这个问题的解决步骤')
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
export declare function createChainOfThought(config?: CoTConfig): {
|
|
339
|
+
think: (problem: string, llm: (prompt: string) => Promise<string>) => Promise<{
|
|
340
|
+
result: string;
|
|
341
|
+
reasoning: ReasoningStep[];
|
|
342
|
+
}>;
|
|
343
|
+
addStep: (step: Omit<ReasoningStep, "id">) => void;
|
|
344
|
+
clear: () => void;
|
|
345
|
+
reasoningSteps: import("vue").Ref<{
|
|
346
|
+
id: string;
|
|
347
|
+
content: string;
|
|
348
|
+
type: "analysis" | "reflection" | "conclusion" | "action";
|
|
349
|
+
children?: /*elided*/ any[] | undefined;
|
|
350
|
+
}[], ReasoningStep[] | {
|
|
351
|
+
id: string;
|
|
352
|
+
content: string;
|
|
353
|
+
type: "analysis" | "reflection" | "conclusion" | "action";
|
|
354
|
+
children?: /*elided*/ any[] | undefined;
|
|
355
|
+
}[]>;
|
|
356
|
+
config: {
|
|
357
|
+
mode: "standard" | "chain" | "tree" | "tabular";
|
|
358
|
+
maxDepth: number;
|
|
359
|
+
showConfidence: boolean;
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* 创建上下文压缩器
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* const compressor = createContextCompressor({
|
|
368
|
+
* strategy: 'summary',
|
|
369
|
+
* targetTokens: 2000
|
|
370
|
+
* })
|
|
371
|
+
*
|
|
372
|
+
* const result = await compressor.compress(messages)
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
export declare function createContextCompressor(config: CompressionConfig): {
|
|
376
|
+
compress: (content: string | Array<{
|
|
377
|
+
role: string;
|
|
378
|
+
content: string;
|
|
379
|
+
}>, llm?: (prompt: string) => Promise<string>) => Promise<CompressionResult>;
|
|
380
|
+
estimateTokens: (text: string) => number;
|
|
381
|
+
config: {
|
|
382
|
+
strategy: "summary" | "extract" | "prune";
|
|
383
|
+
targetTokens: number;
|
|
384
|
+
preserveKeyInfo: string[];
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* 创建成本追踪器
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* const costTracker = createCostTracker({
|
|
393
|
+
* monthlyBudget: 100,
|
|
394
|
+
* warningThreshold: 0.8
|
|
395
|
+
* })
|
|
396
|
+
*
|
|
397
|
+
* costTracker.track({ prompt: 1000, completion: 500 })
|
|
398
|
+
* console.log(costTracker.getStatus())
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
export declare function createCostTracker(config?: CostConfig): {
|
|
402
|
+
track: (usage: TokenUsage, _model?: string) => void;
|
|
403
|
+
calculateCost: (usage: TokenUsage, model: string) => number;
|
|
404
|
+
getStatus: () => CostTracking;
|
|
405
|
+
isOverBudget: () => boolean;
|
|
406
|
+
shouldWarn: () => boolean;
|
|
407
|
+
checkRequestLimit: (tokens: number) => {
|
|
408
|
+
allowed: boolean;
|
|
409
|
+
reason?: string;
|
|
410
|
+
};
|
|
411
|
+
reset: () => void;
|
|
412
|
+
pricing: Record<string, {
|
|
413
|
+
prompt: number;
|
|
414
|
+
completion: number;
|
|
415
|
+
}>;
|
|
416
|
+
config: {
|
|
417
|
+
monthlyBudget: number;
|
|
418
|
+
maxTokensPerRequest: number;
|
|
419
|
+
warningThreshold: number;
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* 创建追踪器
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* const tracer = createTracer()
|
|
428
|
+
*
|
|
429
|
+
* const span = tracer.startSpan('chat')
|
|
430
|
+
* // ... do something
|
|
431
|
+
* tracer.endSpan(span)
|
|
432
|
+
*
|
|
433
|
+
* const events = tracer.getEvents()
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
export declare function createTracer(): {
|
|
437
|
+
startSpan: (name: string, attributes?: Record<string, unknown>) => string;
|
|
438
|
+
endSpan: (id: string, attributes?: Record<string, unknown>) => void;
|
|
439
|
+
addEvent: (event: Omit<TraceEvent, "id" | "timestamp">) => void;
|
|
440
|
+
recordRequest: (config: Record<string, unknown>, spanId?: string) => void;
|
|
441
|
+
recordResponse: (response: unknown, duration?: number, spanId?: string) => void;
|
|
442
|
+
recordError: (error: Error, context?: Record<string, unknown>, spanId?: string) => void;
|
|
443
|
+
getEvents: () => {
|
|
444
|
+
id: string;
|
|
445
|
+
type: "request" | "response" | "tool_call" | "tool_result" | "error" | "custom";
|
|
446
|
+
timestamp: Date;
|
|
447
|
+
data: Record<string, unknown>;
|
|
448
|
+
duration?: number | undefined;
|
|
449
|
+
parentId?: string | undefined;
|
|
450
|
+
}[];
|
|
451
|
+
getSpans: () => {
|
|
452
|
+
id: string;
|
|
453
|
+
name: string;
|
|
454
|
+
startTime: Date;
|
|
455
|
+
endTime?: Date | undefined;
|
|
456
|
+
events: {
|
|
457
|
+
id: string;
|
|
458
|
+
type: "request" | "response" | "tool_call" | "tool_result" | "error" | "custom";
|
|
459
|
+
timestamp: Date;
|
|
460
|
+
data: Record<string, unknown>;
|
|
461
|
+
duration?: number | undefined;
|
|
462
|
+
parentId?: string | undefined;
|
|
463
|
+
}[];
|
|
464
|
+
attributes: Record<string, unknown>;
|
|
465
|
+
children: /*elided*/ any[];
|
|
466
|
+
}[];
|
|
467
|
+
clear: () => void;
|
|
468
|
+
exportJSON: () => string;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* 创建安全过滤器
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* const safety = createSafetyFilter({
|
|
476
|
+
* rules: [
|
|
477
|
+
* { id: '1', name: '敏感词', type: 'content_filter', pattern: '暴力|赌博', action: 'block' }
|
|
478
|
+
* ]
|
|
479
|
+
* })
|
|
480
|
+
*
|
|
481
|
+
* const result = await safety.check('这是一条正常消息')
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
export declare function createSafetyFilter(config: {
|
|
485
|
+
rules: SafetyRule[];
|
|
486
|
+
}): {
|
|
487
|
+
check: (content: string) => Promise<SafetyResult>;
|
|
488
|
+
addRule: (rule: SafetyRule) => void;
|
|
489
|
+
removeRule: (ruleId: string) => void;
|
|
490
|
+
createPresetRules: (type: "strict" | "moderate" | "lenient") => void;
|
|
491
|
+
rules: SafetyRule[];
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* 从 Zod schema 创建结构化输出
|
|
495
|
+
*/
|
|
496
|
+
export declare function fromZodSchema<_T>(schema: unknown): {
|
|
497
|
+
type: string;
|
|
498
|
+
schema: unknown;
|
|
499
|
+
toJSONSchema: () => unknown;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* 创建 JSON Schema 定义
|
|
503
|
+
*/
|
|
504
|
+
export declare function createJSONSchema(definition: SchemaDefinition): SchemaDefinition;
|
|
505
|
+
/**
|
|
506
|
+
* 常用 Schema 构建器
|
|
507
|
+
*/
|
|
508
|
+
export declare const schema: {
|
|
509
|
+
string: (description?: string) => SchemaProperty;
|
|
510
|
+
number: (description?: string) => SchemaProperty;
|
|
511
|
+
boolean: (description?: string) => SchemaProperty;
|
|
512
|
+
enum: <T extends string>(values: T[], description?: string) => SchemaProperty;
|
|
513
|
+
array: (items: SchemaProperty) => SchemaProperty;
|
|
514
|
+
object: (properties: Record<string, SchemaProperty>, required?: string[]) => SchemaDefinition;
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* 解析结构化输出
|
|
518
|
+
*/
|
|
519
|
+
export declare function parseStructuredOutput<T>(output: string, _schema: SchemaDefinition): T | null;
|