@ddlqhd/agent-sdk 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/{chunk-742JTNYI.js → chunk-D3UZNLZO.js} +570 -77
- package/dist/chunk-D3UZNLZO.js.map +1 -0
- package/dist/{chunk-AJD3DTL7.cjs → chunk-JXAJQGV5.cjs} +756 -107
- package/dist/chunk-JXAJQGV5.cjs.map +1 -0
- package/dist/{chunk-DQFTAD3I.cjs → chunk-NYZD3THB.cjs} +573 -76
- package/dist/chunk-NYZD3THB.cjs.map +1 -0
- package/dist/{chunk-Q3L4GIBG.cjs → chunk-P2X3AMDK.cjs} +115 -117
- package/dist/chunk-P2X3AMDK.cjs.map +1 -0
- package/dist/{chunk-THKEF32L.js → chunk-TKUPLTGJ.js} +110 -114
- package/dist/chunk-TKUPLTGJ.js.map +1 -0
- package/dist/{chunk-DXMVWGLJ.js → chunk-UHENMHUS.js} +744 -100
- package/dist/chunk-UHENMHUS.js.map +1 -0
- package/dist/cli/index.cjs +40 -31
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +14 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/{index-DGPDMbW5.d.cts → index-CnrY1ZA2.d.ts} +36 -14
- package/dist/{index-nEfayAzD.d.ts → index-DzBt4ewK.d.cts} +36 -14
- package/dist/index.cjs +128 -88
- package/dist/index.d.cts +42 -22
- package/dist/index.d.ts +42 -22
- package/dist/index.js +3 -3
- package/dist/models/index.cjs +14 -10
- package/dist/models/index.d.cts +7 -2
- package/dist/models/index.d.ts +7 -2
- package/dist/models/index.js +1 -1
- package/dist/tools/index.cjs +65 -57
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +1 -1
- package/dist/{types-BLf9IqRs.d.cts → types-BUwjMwNH.d.cts} +279 -13
- package/dist/{types-BLf9IqRs.d.ts → types-BUwjMwNH.d.ts} +279 -13
- package/package.json +11 -11
- package/dist/chunk-742JTNYI.js.map +0 -1
- package/dist/chunk-AJD3DTL7.cjs.map +0 -1
- package/dist/chunk-DQFTAD3I.cjs.map +0 -1
- package/dist/chunk-DXMVWGLJ.js.map +0 -1
- package/dist/chunk-Q3L4GIBG.cjs.map +0 -1
- package/dist/chunk-THKEF32L.js.map +0 -1
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../chunk-A3S3AGE3.js';
|
|
3
|
-
export { DEFAULT_GREP_HEAD_LIMIT, FileStorageStrategy, HookManager, MAX_LINE_LENGTH, OUTPUT_CONFIG, OutputHandler, PaginationHintStrategy, SmartTruncateStrategy, ToolRegistry, agentTool, bashTool, buildHookEnv, createAgentTool, createAskUserQuestionTool, createFunctionHook, createOutputHandler, createSkillTool, createTool, editTool, formatAnswerSummary, formatAskUserQuestionPrompt, getAllBuiltinTools, getFileSystemTools, getGlobalRegistry, getGrepTools, getInteractionTools, getSafeBuiltinTools, getShellTools, getSkillTools, getSubagentTools,
|
|
3
|
+
export { DEFAULT_GREP_HEAD_LIMIT, FileStorageStrategy, HookManager, MAX_LINE_LENGTH, OUTPUT_CONFIG, OutputHandler, PaginationHintStrategy, SUBAGENT_EXPLORE_DEFAULT_TOOL_NAMES, SUBAGENT_TYPES, SmartTruncateStrategy, ToolRegistry, agentTool, bashTool, buildHookEnv, createAgentTool, createAskUserQuestionTool, createFunctionHook, createOutputHandler, createSkillTool, createTool, editTool, formatAnswerSummary, formatAskUserQuestionPrompt, getAllBuiltinTools, getFileSystemTools, getGlobalRegistry, getGrepTools, getInteractionTools, getPlanningTools, getSafeBuiltinTools, getShellTools, getSkillTools, getSubagentTools, getWebTools, globTool, grepTool, loadHooksSettingsFromProject, loadHooksSettingsFromUser, matchTool, mergeCommandHookLayers, parseHooksSettingsFile, questionTool, readFileTool, resolveSubagentTypeAppend, subagentExploreDefaultsUnavailableMessage, subagentRequestSchema, todoWriteTool, truncateMatchLineForDisplay, webFetchTool, webSearchTool, writeFileTool } from '../chunk-TKUPLTGJ.js';
|
|
4
4
|
import '../chunk-LOYIGOBZ.js';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -178,6 +178,179 @@ interface Compressor {
|
|
|
178
178
|
compress(messages: Message[], targetTokens: number): Promise<Message[]>;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Agent lifecycle callbacks — **observation only**.
|
|
183
|
+
*
|
|
184
|
+
* Use these for UI, tracing, auditing, and metrics. They must not change execution outcomes.
|
|
185
|
+
* **Interception** (block tool calls, rewrite inputs, policy) belongs to {@link HookManager}
|
|
186
|
+
* and {@link ToolRegistry} execution policy, not to these callbacks.
|
|
187
|
+
*
|
|
188
|
+
* @module
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/** Shared fields on run-level observation contexts */
|
|
192
|
+
interface AgentRunContext {
|
|
193
|
+
sessionId?: string;
|
|
194
|
+
cwd?: string;
|
|
195
|
+
}
|
|
196
|
+
interface AgentRunStartContext extends AgentRunContext {
|
|
197
|
+
/** Original user input length before skill processing */
|
|
198
|
+
inputLength: number;
|
|
199
|
+
/** Input length after skill / template processing */
|
|
200
|
+
processedInputLength: number;
|
|
201
|
+
/** Session id from {@link StreamOptions.sessionId} when resuming */
|
|
202
|
+
resumeSessionId?: string;
|
|
203
|
+
}
|
|
204
|
+
type AgentRunEndReason = 'complete' | 'aborted' | 'error' | 'max_iterations';
|
|
205
|
+
interface AgentRunEndContext extends AgentRunContext {
|
|
206
|
+
reason: AgentRunEndReason;
|
|
207
|
+
iterations: number;
|
|
208
|
+
usage?: TokenUsage;
|
|
209
|
+
error?: Error;
|
|
210
|
+
}
|
|
211
|
+
type SystemMessageSource = 'default_prompt' | 'runtime_prompt' | 'memory';
|
|
212
|
+
type UserMessageSource = 'raw_input' | 'processed_input' | 'interruption_marker';
|
|
213
|
+
interface MessageObservationContext extends AgentRunContext {
|
|
214
|
+
iteration?: number;
|
|
215
|
+
}
|
|
216
|
+
interface ModelRequestStartContext extends AgentRunContext {
|
|
217
|
+
iteration: number;
|
|
218
|
+
messageCount: number;
|
|
219
|
+
toolCount: number;
|
|
220
|
+
temperature?: number;
|
|
221
|
+
maxTokens?: number;
|
|
222
|
+
includeRawStreamEvents?: boolean;
|
|
223
|
+
}
|
|
224
|
+
/** Base context for tool execution observation (Agent layer) */
|
|
225
|
+
interface ToolExecutionBaseContext extends AgentRunContext {
|
|
226
|
+
iteration: number;
|
|
227
|
+
toolCallId: string;
|
|
228
|
+
toolName: string;
|
|
229
|
+
arguments: unknown;
|
|
230
|
+
projectDir?: string;
|
|
231
|
+
agentDepth?: number;
|
|
232
|
+
}
|
|
233
|
+
interface ToolExecutionEndContext extends ToolExecutionBaseContext {
|
|
234
|
+
durationMs: number;
|
|
235
|
+
isError: boolean;
|
|
236
|
+
/** Set when the tool handler threw (distinct from `isError` result) */
|
|
237
|
+
executionError?: Error;
|
|
238
|
+
}
|
|
239
|
+
interface ToolResultObservationContext extends ToolExecutionEndContext {
|
|
240
|
+
result: ToolResult;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Observation callbacks for the tool hook pipeline inside {@link ToolRegistry}.
|
|
244
|
+
* Does not replace {@link HookManager}; it only surfaces what happened.
|
|
245
|
+
*/
|
|
246
|
+
interface ToolHookObserver {
|
|
247
|
+
/** Invoked immediately before a hook pipeline step runs for the given event type */
|
|
248
|
+
onHookStart?: (ctx: HookObservationContext) => void;
|
|
249
|
+
/** Invoked after `preToolUse` with the aggregate allow/deny decision */
|
|
250
|
+
onHookDecision?: (ctx: HookDecisionContext) => void;
|
|
251
|
+
/**
|
|
252
|
+
* Reserved for hook pipeline failures surfaced as `Error` (e.g. future hook instrumentation).
|
|
253
|
+
* Tool handler errors use {@link AgentLifecycleCallbacks.onToolExecutionError}.
|
|
254
|
+
*/
|
|
255
|
+
onHookError?: (error: Error, ctx: HookObservationContext) => void;
|
|
256
|
+
}
|
|
257
|
+
interface HookObservationContext {
|
|
258
|
+
eventType: HookEventType;
|
|
259
|
+
toolName: string;
|
|
260
|
+
toolCallId?: string;
|
|
261
|
+
projectDir?: string;
|
|
262
|
+
}
|
|
263
|
+
interface HookDecisionContext extends HookObservationContext {
|
|
264
|
+
allowed: boolean;
|
|
265
|
+
reason?: string;
|
|
266
|
+
}
|
|
267
|
+
/** Optional second argument to {@link AgentCallbacks.onError} and lifecycle error hooks */
|
|
268
|
+
interface AgentErrorContext {
|
|
269
|
+
phase: 'run' | 'model' | 'tool' | 'hook' | 'persistence' | 'lifecycle_callback';
|
|
270
|
+
iteration?: number;
|
|
271
|
+
toolName?: string;
|
|
272
|
+
toolCallId?: string;
|
|
273
|
+
cause?: unknown;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Structured lifecycle callbacks for {@link Agent}.
|
|
277
|
+
*
|
|
278
|
+
* Prefer these over ad-hoc parsing of {@link StreamEvent} when you need stable, typed observation points.
|
|
279
|
+
*/
|
|
280
|
+
interface AgentLifecycleCallbacks {
|
|
281
|
+
onRunStart?: (ctx: AgentRunStartContext) => void;
|
|
282
|
+
onRunEnd?: (ctx: AgentRunEndContext) => void;
|
|
283
|
+
onRunAbort?: (ctx: AgentRunContext & {
|
|
284
|
+
iteration?: number;
|
|
285
|
+
}) => void;
|
|
286
|
+
onSessionCreate?: (ctx: {
|
|
287
|
+
sessionId?: string;
|
|
288
|
+
}) => void;
|
|
289
|
+
onSessionResume?: (ctx: {
|
|
290
|
+
sessionId: string;
|
|
291
|
+
messageCount: number;
|
|
292
|
+
}) => void;
|
|
293
|
+
onIterationStart?: (ctx: {
|
|
294
|
+
iteration: number;
|
|
295
|
+
messageCount: number;
|
|
296
|
+
toolCount: number;
|
|
297
|
+
} & AgentRunContext) => void;
|
|
298
|
+
onIterationEnd?: (ctx: {
|
|
299
|
+
iteration: number;
|
|
300
|
+
hadToolCalls: boolean;
|
|
301
|
+
} & AgentRunContext) => void;
|
|
302
|
+
onContextCompressed?: (ctx: {
|
|
303
|
+
iteration: number;
|
|
304
|
+
stats: {
|
|
305
|
+
originalMessageCount: number;
|
|
306
|
+
compressedMessageCount: number;
|
|
307
|
+
durationMs: number;
|
|
308
|
+
};
|
|
309
|
+
} & AgentRunContext) => void;
|
|
310
|
+
onSystemMessage?: (message: Message, source: SystemMessageSource, ctx?: MessageObservationContext) => void;
|
|
311
|
+
onUserMessage?: (message: Message, source: UserMessageSource, ctx?: MessageObservationContext) => void;
|
|
312
|
+
onAssistantMessage?: (message: Message, ctx?: MessageObservationContext & {
|
|
313
|
+
iteration: number;
|
|
314
|
+
}) => void;
|
|
315
|
+
onToolMessage?: (message: Message, ctx?: MessageObservationContext & {
|
|
316
|
+
iteration: number;
|
|
317
|
+
toolCallId: string;
|
|
318
|
+
}) => void;
|
|
319
|
+
onMessagePersist?: (ctx: {
|
|
320
|
+
messageCount: number;
|
|
321
|
+
} & AgentRunContext) => void;
|
|
322
|
+
onModelRequestStart?: (ctx: ModelRequestStartContext) => void;
|
|
323
|
+
/**
|
|
324
|
+
* Fired for stream events that originate from the model adapter (see `isModelStreamEventType` / `MODEL_STREAM_EVENT_TYPES`).
|
|
325
|
+
* The same events are also delivered to {@link AgentCallbacks.onEvent}; subscribe to one or dedupe if both are set.
|
|
326
|
+
*/
|
|
327
|
+
onModelEvent?: (event: StreamEvent) => void;
|
|
328
|
+
onModelUsage?: (ctx: {
|
|
329
|
+
usage: TokenUsage;
|
|
330
|
+
iteration?: number;
|
|
331
|
+
phase?: 'input' | 'output';
|
|
332
|
+
} & AgentRunContext) => void;
|
|
333
|
+
/** After the model stream for this iteration is fully flushed, before the assistant message is appended */
|
|
334
|
+
onModelRequestEnd?: (ctx: {
|
|
335
|
+
iteration: number;
|
|
336
|
+
} & AgentRunContext) => void;
|
|
337
|
+
/** When the model stream terminates with {@link StreamEvent} `end` and `reason: 'error'` */
|
|
338
|
+
onModelRequestError?: (error: Error, ctx: AgentErrorContext & {
|
|
339
|
+
iteration: number;
|
|
340
|
+
}) => void;
|
|
341
|
+
onToolCallPlanned?: (toolCall: ToolCall, ctx: {
|
|
342
|
+
iteration: number;
|
|
343
|
+
} & AgentRunContext) => void;
|
|
344
|
+
onToolExecutionStart?: (ctx: ToolExecutionBaseContext) => void;
|
|
345
|
+
onToolExecutionEnd?: (ctx: ToolExecutionEndContext) => void;
|
|
346
|
+
onToolResult?: (ctx: ToolResultObservationContext) => void;
|
|
347
|
+
onToolExecutionError?: (error: Error, ctx: AgentErrorContext) => void;
|
|
348
|
+
/** Bridges to {@link ToolRegistry} hook observation */
|
|
349
|
+
hooks?: ToolHookObserver;
|
|
350
|
+
/** Non-fatal agent-level errors (e.g. stream failure) */
|
|
351
|
+
onAgentError?: (error: Error, ctx: AgentErrorContext) => void;
|
|
352
|
+
}
|
|
353
|
+
|
|
181
354
|
/**
|
|
182
355
|
* 文本内容部分
|
|
183
356
|
*/
|
|
@@ -228,6 +401,56 @@ interface Message {
|
|
|
228
401
|
name?: string;
|
|
229
402
|
timestamp?: number;
|
|
230
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* SDK 日志级别
|
|
406
|
+
*/
|
|
407
|
+
type SDKLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
408
|
+
/**
|
|
409
|
+
* SDK 结构化日志事件
|
|
410
|
+
*/
|
|
411
|
+
interface LogEvent {
|
|
412
|
+
/** 固定来源标识,便于宿主应用统一过滤 */
|
|
413
|
+
source: 'agent-sdk';
|
|
414
|
+
component: 'agent' | 'model' | 'streaming' | 'tooling' | 'memory';
|
|
415
|
+
event: string;
|
|
416
|
+
message?: string;
|
|
417
|
+
provider?: string;
|
|
418
|
+
model?: string;
|
|
419
|
+
operation?: 'stream' | 'complete' | 'compress' | 'tool_call';
|
|
420
|
+
sessionId?: string;
|
|
421
|
+
iteration?: number;
|
|
422
|
+
toolName?: string;
|
|
423
|
+
toolCallId?: string;
|
|
424
|
+
requestId?: string;
|
|
425
|
+
clientRequestId?: string;
|
|
426
|
+
statusCode?: number;
|
|
427
|
+
durationMs?: number;
|
|
428
|
+
errorName?: string;
|
|
429
|
+
errorMessage?: string;
|
|
430
|
+
metadata?: Record<string, unknown>;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* SDK Logger 接口。宿主应用可将其桥接到 pino / winston / OTel 等实现。
|
|
434
|
+
*/
|
|
435
|
+
interface SDKLogger {
|
|
436
|
+
debug?(event: LogEvent): void;
|
|
437
|
+
info?(event: LogEvent): void;
|
|
438
|
+
warn?(event: LogEvent): void;
|
|
439
|
+
error?(event: LogEvent): void;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 日志脱敏与输出控制
|
|
443
|
+
*/
|
|
444
|
+
interface LogRedactionConfig {
|
|
445
|
+
/** 是否记录请求/响应 body,默认 false */
|
|
446
|
+
includeBodies?: boolean;
|
|
447
|
+
/** 是否记录工具调用参数,默认 false */
|
|
448
|
+
includeToolArguments?: boolean;
|
|
449
|
+
/** 单个字符串字段最大保留字符数,默认 4000 */
|
|
450
|
+
maxBodyChars?: number;
|
|
451
|
+
/** 额外需要脱敏的键名(大小写不敏感) */
|
|
452
|
+
redactKeys?: string[];
|
|
453
|
+
}
|
|
231
454
|
/**
|
|
232
455
|
* 系统消息
|
|
233
456
|
*/
|
|
@@ -274,11 +497,19 @@ interface ModelParams {
|
|
|
274
497
|
includeRawStreamEvents?: boolean;
|
|
275
498
|
/** 会话标识;Agent 会在每次模型请求中填入,各适配器自行决定是否映射到 HTTP 请求。 */
|
|
276
499
|
sessionId?: string;
|
|
500
|
+
/** 当前请求使用的 SDK logger。 */
|
|
501
|
+
logger?: SDKLogger;
|
|
502
|
+
/** 当前请求使用的 SDK 日志级别。 */
|
|
503
|
+
logLevel?: SDKLogLevel;
|
|
504
|
+
/** 当前请求使用的日志脱敏策略。 */
|
|
505
|
+
redaction?: LogRedactionConfig;
|
|
277
506
|
}
|
|
278
507
|
/**
|
|
279
508
|
* 流式块类型
|
|
280
509
|
*/
|
|
281
|
-
type StreamChunkType = 'text' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'thinking'
|
|
510
|
+
type StreamChunkType = 'text' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'thinking'
|
|
511
|
+
/** Adapters emit when a discrete thinking block ends (e.g. Anthropic content_block_stop). */
|
|
512
|
+
| 'thinking_block_end' | 'error' | 'done' | 'metadata';
|
|
282
513
|
/**
|
|
283
514
|
* 流式块
|
|
284
515
|
*/
|
|
@@ -460,7 +691,7 @@ interface StorageAdapter {
|
|
|
460
691
|
/**
|
|
461
692
|
* 流式事件类型
|
|
462
693
|
*/
|
|
463
|
-
type StreamEventType = 'text_delta' | 'text_start' | 'text_end' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'tool_result' | 'tool_error' | 'thinking' | 'start' | 'end' | 'model_usage' | 'session_summary' | 'context_compressed';
|
|
694
|
+
type StreamEventType = 'text_delta' | 'text_start' | 'text_end' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'tool_result' | 'tool_error' | 'thinking' | 'thinking_start' | 'thinking_end' | 'start' | 'end' | 'model_usage' | 'session_summary' | 'context_compressed';
|
|
464
695
|
/**
|
|
465
696
|
* Optional fields on any stream event (observability, Claude-style correlation).
|
|
466
697
|
*/
|
|
@@ -513,10 +744,16 @@ type StreamEvent = ({
|
|
|
513
744
|
type: 'tool_error';
|
|
514
745
|
toolCallId: string;
|
|
515
746
|
error: Error;
|
|
747
|
+
} | {
|
|
748
|
+
type: 'thinking_start';
|
|
749
|
+
signature?: string;
|
|
516
750
|
} | {
|
|
517
751
|
type: 'thinking';
|
|
518
752
|
content: string;
|
|
519
753
|
signature?: string;
|
|
754
|
+
} | {
|
|
755
|
+
type: 'thinking_end';
|
|
756
|
+
content?: string;
|
|
520
757
|
} | {
|
|
521
758
|
type: 'model_usage';
|
|
522
759
|
usage: TokenUsage;
|
|
@@ -526,6 +763,7 @@ type StreamEvent = ({
|
|
|
526
763
|
type: 'session_summary';
|
|
527
764
|
/** Authoritative cumulative usage for the completed run (prefer over end.usage when both exist). */
|
|
528
765
|
usage: TokenUsage;
|
|
766
|
+
/** Number of model rounds completed in this stream call (not message count). */
|
|
529
767
|
iterations: number;
|
|
530
768
|
} | {
|
|
531
769
|
type: 'end';
|
|
@@ -534,8 +772,8 @@ type StreamEvent = ({
|
|
|
534
772
|
* Optional usage (e.g. aborted mid-stream). When a session_summary event was emitted, use its usage for totals.
|
|
535
773
|
*/
|
|
536
774
|
usage?: TokenUsage;
|
|
537
|
-
/** Omitted or `complete` = normal completion */
|
|
538
|
-
reason?: 'complete' | 'aborted' | 'error';
|
|
775
|
+
/** Omitted or `complete` = normal completion; `max_iterations` = hit `AgentConfig.maxIterations`. */
|
|
776
|
+
reason?: 'complete' | 'aborted' | 'error' | 'max_iterations';
|
|
539
777
|
error?: Error;
|
|
540
778
|
partialContent?: string;
|
|
541
779
|
} | {
|
|
@@ -546,6 +784,16 @@ type StreamEvent = ({
|
|
|
546
784
|
durationMs: number;
|
|
547
785
|
};
|
|
548
786
|
}) & StreamEventAnnotations;
|
|
787
|
+
/**
|
|
788
|
+
* 模型适配器在一次请求中可能产出的流式事件类型(与 {@link isModelStreamEventType} 共用此列表,避免与 `switch` 双处维护)。
|
|
789
|
+
* 新增 `StreamEvent` 变体时:若属于模型流,请在此数组中追加对应 `type` 字符串。
|
|
790
|
+
*/
|
|
791
|
+
declare const MODEL_STREAM_EVENT_TYPES: readonly ["text_start", "text_delta", "text_end", "tool_call_start", "tool_call_delta", "tool_call", "tool_call_end", "thinking_start", "thinking", "thinking_end", "model_usage"];
|
|
792
|
+
/**
|
|
793
|
+
* 是否为由模型适配器流式产生的事件类型(用于 `lifecycle.onModelEvent` 过滤)。
|
|
794
|
+
* 排除 `start` / `end` / `session_summary` / `context_compressed` / `tool_result` / `tool_error` 等。
|
|
795
|
+
*/
|
|
796
|
+
declare function isModelStreamEventType(type: StreamEventType): boolean;
|
|
549
797
|
/**
|
|
550
798
|
* MCP 服务器配置
|
|
551
799
|
*/
|
|
@@ -558,6 +806,12 @@ interface MCPServerConfig {
|
|
|
558
806
|
command?: string;
|
|
559
807
|
args?: string[];
|
|
560
808
|
env?: Record<string, string>;
|
|
809
|
+
/**
|
|
810
|
+
* stdio 子进程工作目录(仅 `transport === 'stdio'` 时生效)。
|
|
811
|
+
* 经 `Agent.connectMCP` 且未设置或仅空白时,使用 `AgentConfig.cwd`,再否则为当前进程的 `process.cwd()`。
|
|
812
|
+
* 直接使用 `MCPClient` 且未设置时,spawn 不传 `cwd`,子进程继承父进程工作目录(通常即当时的 `process.cwd()`)。
|
|
813
|
+
*/
|
|
814
|
+
cwd?: string;
|
|
561
815
|
/** HTTP 配置 */
|
|
562
816
|
url?: string;
|
|
563
817
|
headers?: Record<string, string>;
|
|
@@ -752,6 +1006,12 @@ interface AgentConfig {
|
|
|
752
1006
|
sessionId?: string;
|
|
753
1007
|
/** 回调函数 */
|
|
754
1008
|
callbacks?: AgentCallbacks;
|
|
1009
|
+
/** SDK logger;由宿主应用决定最终输出位置。 */
|
|
1010
|
+
logger?: SDKLogger;
|
|
1011
|
+
/** SDK 日志级别;省略时可由环境变量控制。 */
|
|
1012
|
+
logLevel?: SDKLogLevel;
|
|
1013
|
+
/** 日志脱敏与 body 输出控制。 */
|
|
1014
|
+
redaction?: LogRedactionConfig;
|
|
755
1015
|
/** 是否启用长期记忆 */
|
|
756
1016
|
memory?: boolean;
|
|
757
1017
|
/** 记忆配置 */
|
|
@@ -784,6 +1044,11 @@ interface AgentConfig {
|
|
|
784
1044
|
allowDangerousTools?: boolean;
|
|
785
1045
|
/** 子代理默认允许工具列表(为空时自动使用安全工具) */
|
|
786
1046
|
defaultAllowedTools?: string[];
|
|
1047
|
+
/**
|
|
1048
|
+
* 按 subagent 类型(general-purpose / explore)覆盖内置追加 system 片段;未设置的类型仍用内置文案。
|
|
1049
|
+
* 设为空字符串表示该类型不追加片段。
|
|
1050
|
+
*/
|
|
1051
|
+
subagentTypePrompts?: Partial<Record<'general-purpose' | 'explore', string>>;
|
|
787
1052
|
};
|
|
788
1053
|
}
|
|
789
1054
|
/**
|
|
@@ -805,17 +1070,18 @@ interface SkillConfig {
|
|
|
805
1070
|
additionalPaths?: string[];
|
|
806
1071
|
}
|
|
807
1072
|
/**
|
|
808
|
-
* Agent
|
|
1073
|
+
* Agent 回调:流式事件 + 可选的结构化生命周期观察。
|
|
1074
|
+
*
|
|
1075
|
+
* - **观察**:`onEvent`、`lifecycle` — 不改变执行结果。
|
|
1076
|
+
* - **拦截**:工具策略与 Hook 见 {@link AgentConfig.hookManager} / `hookConfigDir` 与 {@link ToolRegistry}。
|
|
809
1077
|
*/
|
|
810
1078
|
interface AgentCallbacks {
|
|
811
|
-
/**
|
|
1079
|
+
/** 流式事件回调(与 {@link AgentLifecycleCallbacks.onModelEvent} 互补:后者仅模型侧子集) */
|
|
812
1080
|
onEvent?: (event: StreamEvent) => void;
|
|
813
|
-
/**
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
|
|
817
|
-
/** 错误回调 */
|
|
818
|
-
onError?: (error: Error) => void;
|
|
1081
|
+
/** 结构化生命周期观察 */
|
|
1082
|
+
lifecycle?: AgentLifecycleCallbacks;
|
|
1083
|
+
/** 错误回调;`context` 为可选扩展信息 */
|
|
1084
|
+
onError?: (error: Error, context?: AgentErrorContext) => void;
|
|
819
1085
|
}
|
|
820
1086
|
/**
|
|
821
1087
|
* Agent 执行结果
|
|
@@ -899,4 +1165,4 @@ interface SkillOptions {
|
|
|
899
1165
|
path?: string;
|
|
900
1166
|
}
|
|
901
1167
|
|
|
902
|
-
export { type
|
|
1168
|
+
export { type MCPPromptArgument as $, type AgentConfig as A, type ChatOptions as B, type CLIConfig as C, type CommandHookConfig as D, type CompletionResult as E, type ContentPart as F, type ContextManagerConfig as G, type CreateAskUserQuestionToolOptions as H, type FlatCommandHookEntry as I, type FunctionHook as J, type HookContext as K, type LogEvent as L, type Message as M, type HookDecisionContext as N, type HookEventType as O, type ParsedSkill as P, type HookGroupConfig as Q, HookManager as R, type StorageConfig as S, type ToolResult as T, type HookObservationContext as U, type HookResult as V, type HooksSettings as W, type HooksSettingsFile as X, type ImageContent as Y, type LogRedactionConfig as Z, type MCPOptions as _, type SessionInfo as a, type MCPResourceContent as a0, MODEL_STREAM_EVENT_TYPES as a1, type MessageObservationContext as a2, type MessageRole as a3, type ModelCapabilities as a4, type ModelParams as a5, type ModelRequestStartContext as a6, type RunOptions as a7, type SDKLogLevel as a8, type SessionListOptions as a9, buildHookEnv as aA, createAskUserQuestionTool as aB, createFunctionHook as aC, formatAnswerSummary as aD, formatAskUserQuestionPrompt as aE, getInteractionTools as aF, isModelStreamEventType as aG, matchTool as aH, mergeCommandHookLayers as aI, questionTool as aJ, type SkillConfig as aa, type SkillDefinition as ab, type SkillMetadata as ac, type SkillOptions as ad, type StreamChunkType as ae, type StreamEventAnnotations as af, type StreamEventType as ag, type SystemMessage as ah, type SystemMessageSource as ai, type SystemPromptConfig as aj, type TextContent as ak, type ThinkingContent as al, type ToolCall as am, type ToolExecutionBaseContext as an, type ToolExecutionContext as ao, type ToolExecutionEndContext as ap, type ToolExecutionPolicy as aq, type ToolHandler as ar, type ToolHookObserver as as, type ToolListOptions as at, type ToolMessage as au, type ToolResultMetadata as av, type ToolResultObservationContext as aw, type ToolSchema as ax, type UserMessage as ay, type UserMessageSource as az, type StorageAdapter as b, type MCPServerConfig as c, type ToolDefinition as d, type SystemPrompt as e, type StreamEvent as f, type AgentResult as g, type ModelAdapter as h, type SessionTokenUsage as i, type SDKLogger as j, type TokenUsage as k, type StreamChunk as l, type MemoryConfig as m, type AgentCallbacks as n, type AgentErrorContext as o, type AgentLifecycleCallbacks as p, type AgentModelConfig as q, type AgentRunContext as r, type AgentRunEndContext as s, type AgentRunEndReason as t, type AgentRunStartContext as u, type AskUserQuestionAnswer as v, type AskUserQuestionItem as w, type AskUserQuestionResolver as x, type AssistantMessage as y, type CanUseToolCallback as z };
|