@listdoing/core 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 +1441 -0
- package/dist/index.d.ts +1441 -0
- package/dist/index.js +3940 -0
- package/dist/index.mjs +3879 -0
- package/package.json +24 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1441 @@
|
|
|
1
|
+
/** Trigger rule (Airflow-style) — determines when a node should execute */
|
|
2
|
+
type TriggerRule = 'all_success' | 'one_success' | 'none_failed' | 'all_done' | 'always';
|
|
3
|
+
/** Retry policy with exponential backoff */
|
|
4
|
+
interface RetryPolicy {
|
|
5
|
+
maxRetries: number;
|
|
6
|
+
backoffMs?: number;
|
|
7
|
+
maxBackoffMs?: number;
|
|
8
|
+
retryOn?: ('timeout' | 'llm_error' | 'tool_error' | 'any')[];
|
|
9
|
+
}
|
|
10
|
+
/** Fallback/degradation strategy */
|
|
11
|
+
interface FallbackStrategy {
|
|
12
|
+
type: 'bypass' | 'fallback' | 'compensate';
|
|
13
|
+
/** Fallback type: replacement prompt */
|
|
14
|
+
fallbackPrompt?: string;
|
|
15
|
+
/** Fallback type: available tools */
|
|
16
|
+
fallbackTools?: string[];
|
|
17
|
+
/** Compensate type: nodeId → compensation prompt */
|
|
18
|
+
compensations?: Record<string, string>;
|
|
19
|
+
maxTurns?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Sub-Agent configuration — per-node overrides */
|
|
22
|
+
interface SubAgentConfig {
|
|
23
|
+
systemPrompt?: string;
|
|
24
|
+
model?: string;
|
|
25
|
+
temperature?: number;
|
|
26
|
+
tools?: string[];
|
|
27
|
+
maxTurns?: number;
|
|
28
|
+
canSpawnSubAgents?: boolean;
|
|
29
|
+
maxDepth?: number;
|
|
30
|
+
}
|
|
31
|
+
/** DAG node definition */
|
|
32
|
+
interface GraphNode {
|
|
33
|
+
id: string;
|
|
34
|
+
goal: string;
|
|
35
|
+
dependsOn: string[];
|
|
36
|
+
triggerRule?: TriggerRule;
|
|
37
|
+
agent?: SubAgentConfig;
|
|
38
|
+
retry?: RetryPolicy;
|
|
39
|
+
fallback?: FallbackStrategy;
|
|
40
|
+
timeout?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Node execution status */
|
|
43
|
+
type NodeStatus = 'pending' | 'running' | 'done' | 'failed' | 'bypassed' | 'skipped' | 'compensating';
|
|
44
|
+
/** Node execution result */
|
|
45
|
+
interface NodeResult {
|
|
46
|
+
nodeId: string;
|
|
47
|
+
status: NodeStatus;
|
|
48
|
+
output?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
tokenUsage: {
|
|
51
|
+
input: number;
|
|
52
|
+
output: number;
|
|
53
|
+
};
|
|
54
|
+
duration: number;
|
|
55
|
+
retryCount: number;
|
|
56
|
+
sessionId?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Graph execution plan */
|
|
59
|
+
interface GraphPlan {
|
|
60
|
+
id: string;
|
|
61
|
+
goal: string;
|
|
62
|
+
nodes: GraphNode[];
|
|
63
|
+
levels: string[][];
|
|
64
|
+
status: 'planning' | 'executing' | 'completed' | 'failed' | 'partial';
|
|
65
|
+
results: Record<string, NodeResult>;
|
|
66
|
+
createdAt: number;
|
|
67
|
+
updatedAt: number;
|
|
68
|
+
totalTokenUsage: {
|
|
69
|
+
input: number;
|
|
70
|
+
output: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Graph progress stats */
|
|
74
|
+
interface GraphProgress {
|
|
75
|
+
total: number;
|
|
76
|
+
done: number;
|
|
77
|
+
failed: number;
|
|
78
|
+
bypassed: number;
|
|
79
|
+
running: number;
|
|
80
|
+
pending: number;
|
|
81
|
+
percentage: number;
|
|
82
|
+
}
|
|
83
|
+
/** Graph checkpoint for resumption */
|
|
84
|
+
interface GraphCheckpoint {
|
|
85
|
+
planId: string;
|
|
86
|
+
completedNodes: string[];
|
|
87
|
+
runningNodes: string[];
|
|
88
|
+
parentId: string;
|
|
89
|
+
timestamp: number;
|
|
90
|
+
}
|
|
91
|
+
/** Sub-graph definition for SkillDefinition.subgraph */
|
|
92
|
+
interface GraphDefinition {
|
|
93
|
+
nodes: GraphNode[];
|
|
94
|
+
aggregation?: 'last' | 'concat' | 'custom';
|
|
95
|
+
aggregationPrompt?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ContentBlock = {
|
|
99
|
+
type: 'text';
|
|
100
|
+
text: string;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'image';
|
|
103
|
+
data: string;
|
|
104
|
+
mimeType: string;
|
|
105
|
+
} | {
|
|
106
|
+
type: 'resource';
|
|
107
|
+
resource: {
|
|
108
|
+
uri: string;
|
|
109
|
+
mimeType?: string;
|
|
110
|
+
text?: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
interface SkillResult {
|
|
114
|
+
content: ContentBlock[];
|
|
115
|
+
isError?: boolean;
|
|
116
|
+
}
|
|
117
|
+
type SkillTier = 'system' | 'extension' | 'user';
|
|
118
|
+
declare const SENSITIVE_PERMISSIONS: Set<string>;
|
|
119
|
+
type PermissionMode = 'strict' | 'standard' | 'trusted';
|
|
120
|
+
type PermissionPolicy = 'auto' | 'approval' | 'force-approval' | 'disabled';
|
|
121
|
+
/** Default policy table for each permission mode */
|
|
122
|
+
declare const PERMISSION_MODE_DEFAULTS: Record<PermissionMode, Record<string, PermissionPolicy>>;
|
|
123
|
+
interface SkillDefinition {
|
|
124
|
+
name: string;
|
|
125
|
+
description: string;
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: 'object';
|
|
128
|
+
properties: Record<string, any>;
|
|
129
|
+
required?: string[];
|
|
130
|
+
};
|
|
131
|
+
location?: 'local' | 'server' | 'auto';
|
|
132
|
+
tags?: string[];
|
|
133
|
+
permissions?: string[];
|
|
134
|
+
/** Fine-grained capability mapping: key = operation identifier within the skill, value = required sub-permissions.
|
|
135
|
+
* Used by the permission system for action-level policy resolution.
|
|
136
|
+
* Does NOT go to LLM context — only used at execution time. */
|
|
137
|
+
capabilityMap?: Record<string, string[]>;
|
|
138
|
+
/** Whether this skill can safely execute concurrently with other skills in the same turn.
|
|
139
|
+
* true (default) = safe for parallel execution (read-only / stateless / independent resources)
|
|
140
|
+
* false = must run sequentially (mutates shared state: DOM, filesystem, global store, etc.)
|
|
141
|
+
* When ANY tool in a batch is parallelSafe:false, the entire batch falls back to sequential.
|
|
142
|
+
* Future extension point: resourceAccess() for fine-grained conflict detection. */
|
|
143
|
+
parallelSafe?: boolean;
|
|
144
|
+
tier?: SkillTier;
|
|
145
|
+
timeout?: number;
|
|
146
|
+
/** Direct handler (execution mode: call) */
|
|
147
|
+
handler?: SkillHandler;
|
|
148
|
+
/** Agent-based skill: model autonomously loops using tools */
|
|
149
|
+
agentLoop?: {
|
|
150
|
+
instruction: string;
|
|
151
|
+
tools?: string[];
|
|
152
|
+
maxTurns?: number;
|
|
153
|
+
};
|
|
154
|
+
/** Multi-step predefined workflow (execution mode: workflow) */
|
|
155
|
+
workflow?: WorkflowDefinition;
|
|
156
|
+
/** @deprecated Use `workflow` instead. Kept for Claw compatibility, auto-mapped to `workflow`. */
|
|
157
|
+
_clawWorkflow?: WorkflowDefinition;
|
|
158
|
+
/** DAG sub-graph skill definition */
|
|
159
|
+
subgraph?: GraphDefinition;
|
|
160
|
+
/** Pack name (set by useSkillPack, for tracking source) */
|
|
161
|
+
_packName?: string;
|
|
162
|
+
}
|
|
163
|
+
type SkillHandler = (params: Record<string, any>, context: SkillContext) => Promise<SkillResult>;
|
|
164
|
+
interface SkillContext {
|
|
165
|
+
sessionId: string;
|
|
166
|
+
agent?: any;
|
|
167
|
+
signal: AbortSignal;
|
|
168
|
+
/** Current SubAgent instance (if executing inside a graph node) */
|
|
169
|
+
subAgent?: any;
|
|
170
|
+
/** Nesting depth, 0 = top-level */
|
|
171
|
+
depth: number;
|
|
172
|
+
/**
|
|
173
|
+
* Directly invoke another skill by name. No LLM loop, no approval needed.
|
|
174
|
+
* The calling skill's code logic decides when and what to call.
|
|
175
|
+
* Available in SDK (browser) mode; server-side skills return an error if invoked.
|
|
176
|
+
* @param skillName - Name of the registered skill to invoke
|
|
177
|
+
* @param params - Parameters matching the target skill's inputSchema
|
|
178
|
+
* @returns Structured SkillResult from the invoked skill
|
|
179
|
+
*/
|
|
180
|
+
invoke?: (skillName: string, params: Record<string, any>) => Promise<SkillResult>;
|
|
181
|
+
}
|
|
182
|
+
interface SkillWorker {
|
|
183
|
+
execute(def: SkillDefinition, params: Record<string, any>, ctx: SkillContext): Promise<SkillResult>;
|
|
184
|
+
}
|
|
185
|
+
interface ISkillProvider {
|
|
186
|
+
loadSkills(registry: any, options?: {
|
|
187
|
+
disable?: string[];
|
|
188
|
+
enable?: string[];
|
|
189
|
+
tiers?: SkillTier[];
|
|
190
|
+
permissions?: string[];
|
|
191
|
+
}): void;
|
|
192
|
+
}
|
|
193
|
+
interface WorkflowDefinition {
|
|
194
|
+
steps: WorkflowStep[];
|
|
195
|
+
}
|
|
196
|
+
interface SkillPack<TConfig extends Record<string, any> = Record<string, any>> {
|
|
197
|
+
name: string;
|
|
198
|
+
version?: string;
|
|
199
|
+
runtime?: 'browser' | 'node' | 'both';
|
|
200
|
+
configSchema?: {
|
|
201
|
+
type: 'object';
|
|
202
|
+
properties: Record<string, any>;
|
|
203
|
+
required?: string[];
|
|
204
|
+
};
|
|
205
|
+
create(config: TConfig, env: SkillPackEnv): SkillPackResult;
|
|
206
|
+
}
|
|
207
|
+
interface SkillPackEnv {
|
|
208
|
+
runtime: 'browser' | 'node';
|
|
209
|
+
hasAgent: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface SkillPackResult {
|
|
212
|
+
skills: SkillDefinition[];
|
|
213
|
+
destroy?: () => void | Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
interface SkillPackRegistration {
|
|
216
|
+
packName: string;
|
|
217
|
+
skills: string[];
|
|
218
|
+
destroy?: () => void | Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
interface WorkflowStep {
|
|
221
|
+
name: string;
|
|
222
|
+
tools: string[];
|
|
223
|
+
prompt: string;
|
|
224
|
+
/** Max turns for this step's chatInner call (default: 10) */
|
|
225
|
+
maxTurns?: number;
|
|
226
|
+
/** DAG dependency: list of step names this step depends on. Absent = depends on previous step (backward compat) */
|
|
227
|
+
dependsOn?: string[];
|
|
228
|
+
/** Trigger rule for DAG execution */
|
|
229
|
+
triggerRule?: TriggerRule;
|
|
230
|
+
/** Sub-Agent config for this step */
|
|
231
|
+
agent?: SubAgentConfig;
|
|
232
|
+
/** Retry policy for this step */
|
|
233
|
+
retry?: RetryPolicy;
|
|
234
|
+
/** Fallback strategy for this step */
|
|
235
|
+
fallback?: FallbackStrategy;
|
|
236
|
+
}
|
|
237
|
+
interface WorkflowProgress {
|
|
238
|
+
current: number;
|
|
239
|
+
total: number;
|
|
240
|
+
percentage: number;
|
|
241
|
+
completedSteps: string[];
|
|
242
|
+
failedSteps: string[];
|
|
243
|
+
}
|
|
244
|
+
interface LLMAdapterConfig {
|
|
245
|
+
adapter: 'openai' | 'anthropic' | 'ollama' | 'custom';
|
|
246
|
+
model: string;
|
|
247
|
+
baseUrl?: string;
|
|
248
|
+
apiKey?: string;
|
|
249
|
+
headers?: Record<string, string>;
|
|
250
|
+
temperature?: number;
|
|
251
|
+
maxTokens?: number;
|
|
252
|
+
/** Custom adapter: response path for content */
|
|
253
|
+
responsePath?: string;
|
|
254
|
+
/** Custom adapter: response path for tool_calls */
|
|
255
|
+
toolCallsPath?: string;
|
|
256
|
+
/** Custom adapter: request transformer (client-only, JS function) */
|
|
257
|
+
transformRequest?: (messages: Message[], tools: ToolDef[], options: any) => any;
|
|
258
|
+
/** Custom adapter: response transformer (client-only, JS function) */
|
|
259
|
+
transformResponse?: (response: any) => StandardLLMResponse;
|
|
260
|
+
/** Extra fields to merge into the request body (e.g. token, api_url for third-party proxies) */
|
|
261
|
+
extraBody?: Record<string, any>;
|
|
262
|
+
}
|
|
263
|
+
interface StandardLLMResponse {
|
|
264
|
+
content: string;
|
|
265
|
+
reasoning?: string;
|
|
266
|
+
toolCalls?: ToolCall[];
|
|
267
|
+
usage?: {
|
|
268
|
+
input: number;
|
|
269
|
+
output: number;
|
|
270
|
+
};
|
|
271
|
+
finishReason?: string;
|
|
272
|
+
}
|
|
273
|
+
interface ToolCall {
|
|
274
|
+
id: string;
|
|
275
|
+
name: string;
|
|
276
|
+
arguments: Record<string, any>;
|
|
277
|
+
}
|
|
278
|
+
interface ToolDef {
|
|
279
|
+
name: string;
|
|
280
|
+
description: string;
|
|
281
|
+
inputSchema: {
|
|
282
|
+
type: 'object';
|
|
283
|
+
properties: Record<string, any>;
|
|
284
|
+
required?: string[];
|
|
285
|
+
};
|
|
286
|
+
/** ACP extension: execution mode */
|
|
287
|
+
mode?: 'call' | 'loop' | 'workflow';
|
|
288
|
+
/** ACP extension: estimated turns for loop mode */
|
|
289
|
+
estimatedTurns?: number;
|
|
290
|
+
/** ACP extension: step count for workflow mode */
|
|
291
|
+
stepCount?: number;
|
|
292
|
+
/** Skill tier (used for filtering, not sent to LLM) */
|
|
293
|
+
tier?: SkillTier;
|
|
294
|
+
/** Permission categories (used for filtering, not sent to LLM) */
|
|
295
|
+
permissions?: string[];
|
|
296
|
+
/** Whether this tool is safe for parallel execution (from SkillDefinition.parallelSafe, not sent to LLM) */
|
|
297
|
+
parallelSafe?: boolean;
|
|
298
|
+
}
|
|
299
|
+
interface FileInput {
|
|
300
|
+
data: string;
|
|
301
|
+
mimeType: string;
|
|
302
|
+
filename?: string;
|
|
303
|
+
}
|
|
304
|
+
interface Message {
|
|
305
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
306
|
+
content: string | ContentBlock[];
|
|
307
|
+
toolCallId?: string;
|
|
308
|
+
toolCalls?: ToolCall[];
|
|
309
|
+
}
|
|
310
|
+
interface Session {
|
|
311
|
+
id: string;
|
|
312
|
+
title?: string;
|
|
313
|
+
createdAt: number;
|
|
314
|
+
updatedAt: number;
|
|
315
|
+
meta?: Record<string, any>;
|
|
316
|
+
messageCount: number;
|
|
317
|
+
artifactCount: number;
|
|
318
|
+
summary?: string;
|
|
319
|
+
tokenCount: number;
|
|
320
|
+
status: 'active' | 'archived';
|
|
321
|
+
tags?: string[];
|
|
322
|
+
systemPrompt?: string;
|
|
323
|
+
messages: Message[];
|
|
324
|
+
}
|
|
325
|
+
interface ChatOptions {
|
|
326
|
+
sessionId?: string;
|
|
327
|
+
requireApproval?: string[];
|
|
328
|
+
/** Skip all approval checks for this chat call (overrides everything) */
|
|
329
|
+
autoApprove?: boolean;
|
|
330
|
+
/** Override permission mode for this chat call */
|
|
331
|
+
permissionMode?: PermissionMode;
|
|
332
|
+
maxTurns?: number;
|
|
333
|
+
/** Restrict available tools by name */
|
|
334
|
+
tools?: string[];
|
|
335
|
+
/** Filter tools by permission category (union with tools) */
|
|
336
|
+
toolsByPermission?: string[];
|
|
337
|
+
/** Enable task planning mode: LLM decomposes goal into steps before executing */
|
|
338
|
+
taskMode?: 'plan' | 'graph';
|
|
339
|
+
/** Max retries per step on failure (default: 1) */
|
|
340
|
+
stepRetryCount?: number;
|
|
341
|
+
/** Whether to continue executing remaining steps when one fails (default: true) */
|
|
342
|
+
continueOnStepFailure?: boolean;
|
|
343
|
+
/** Current nesting depth (0 = top-level, increments when SubAgent calls chatInner) */
|
|
344
|
+
depth?: number;
|
|
345
|
+
/** Graph execution config (used when taskMode='graph') */
|
|
346
|
+
graphConfig?: {
|
|
347
|
+
retryPolicy?: RetryPolicy;
|
|
348
|
+
fallbackStrategy?: FallbackStrategy;
|
|
349
|
+
defaultTriggerRule?: TriggerRule;
|
|
350
|
+
maxConcurrency?: number;
|
|
351
|
+
maxDepth?: number;
|
|
352
|
+
};
|
|
353
|
+
/** Attached files/images to include with the message */
|
|
354
|
+
attachments?: FileInput[];
|
|
355
|
+
}
|
|
356
|
+
interface ChatResult {
|
|
357
|
+
reply: string;
|
|
358
|
+
sessionId: string;
|
|
359
|
+
executionTrace: ExecutionTrace[];
|
|
360
|
+
tokenUsage: {
|
|
361
|
+
input: number;
|
|
362
|
+
output: number;
|
|
363
|
+
};
|
|
364
|
+
totalDuration: number;
|
|
365
|
+
}
|
|
366
|
+
interface ExecutionTrace {
|
|
367
|
+
turn: number;
|
|
368
|
+
/** Whether tools in this turn were executed in parallel */
|
|
369
|
+
parallel?: boolean;
|
|
370
|
+
toolCalls: {
|
|
371
|
+
callId: string;
|
|
372
|
+
toolName: string;
|
|
373
|
+
location: 'local' | 'server';
|
|
374
|
+
arguments: Record<string, any>;
|
|
375
|
+
result: {
|
|
376
|
+
isError: boolean;
|
|
377
|
+
summary?: string;
|
|
378
|
+
};
|
|
379
|
+
duration: number;
|
|
380
|
+
}[];
|
|
381
|
+
}
|
|
382
|
+
type StreamEvent = {
|
|
383
|
+
type: 'llm_thinking';
|
|
384
|
+
content: string;
|
|
385
|
+
} | {
|
|
386
|
+
type: 'llm_text';
|
|
387
|
+
content: string;
|
|
388
|
+
} | {
|
|
389
|
+
type: 'tool_call';
|
|
390
|
+
callId: string;
|
|
391
|
+
toolName: string;
|
|
392
|
+
arguments: Record<string, any>;
|
|
393
|
+
location: 'local' | 'server';
|
|
394
|
+
} | {
|
|
395
|
+
type: 'tool_result';
|
|
396
|
+
callId: string;
|
|
397
|
+
toolName: string;
|
|
398
|
+
isError: boolean;
|
|
399
|
+
summary?: string;
|
|
400
|
+
duration: number;
|
|
401
|
+
} | {
|
|
402
|
+
type: 'tool_approval';
|
|
403
|
+
callId: string;
|
|
404
|
+
toolName: string;
|
|
405
|
+
arguments: Record<string, any>;
|
|
406
|
+
} | {
|
|
407
|
+
type: 'task:plan';
|
|
408
|
+
plan: any;
|
|
409
|
+
} | {
|
|
410
|
+
type: 'task:step_start';
|
|
411
|
+
step: any;
|
|
412
|
+
progress: any;
|
|
413
|
+
} | {
|
|
414
|
+
type: 'task:step_complete';
|
|
415
|
+
step: any;
|
|
416
|
+
progress: any;
|
|
417
|
+
} | {
|
|
418
|
+
type: 'task:step_failed';
|
|
419
|
+
step: any;
|
|
420
|
+
progress: any;
|
|
421
|
+
} | {
|
|
422
|
+
type: 'workflow:step_start';
|
|
423
|
+
step: WorkflowStep;
|
|
424
|
+
stepIndex: number;
|
|
425
|
+
progress: WorkflowProgress;
|
|
426
|
+
} | {
|
|
427
|
+
type: 'workflow:step_complete';
|
|
428
|
+
step: WorkflowStep;
|
|
429
|
+
stepIndex: number;
|
|
430
|
+
output: string;
|
|
431
|
+
progress: WorkflowProgress;
|
|
432
|
+
} | {
|
|
433
|
+
type: 'workflow:step_failed';
|
|
434
|
+
step: WorkflowStep;
|
|
435
|
+
stepIndex: number;
|
|
436
|
+
error: string;
|
|
437
|
+
progress: WorkflowProgress;
|
|
438
|
+
} | {
|
|
439
|
+
type: 'subagent:spawn';
|
|
440
|
+
nodeId: string;
|
|
441
|
+
sessionId: string;
|
|
442
|
+
goal: string;
|
|
443
|
+
depth: number;
|
|
444
|
+
} | {
|
|
445
|
+
type: 'subagent:progress';
|
|
446
|
+
nodeId: string;
|
|
447
|
+
sessionId: string;
|
|
448
|
+
turn: number;
|
|
449
|
+
maxTurns: number;
|
|
450
|
+
} | {
|
|
451
|
+
type: 'subagent:complete';
|
|
452
|
+
nodeId: string;
|
|
453
|
+
sessionId: string;
|
|
454
|
+
output: string;
|
|
455
|
+
tokenUsage: {
|
|
456
|
+
input: number;
|
|
457
|
+
output: number;
|
|
458
|
+
};
|
|
459
|
+
} | {
|
|
460
|
+
type: 'subagent:fail';
|
|
461
|
+
nodeId: string;
|
|
462
|
+
sessionId: string;
|
|
463
|
+
error: string;
|
|
464
|
+
retryCount: number;
|
|
465
|
+
willRetry: boolean;
|
|
466
|
+
} | {
|
|
467
|
+
type: 'subagent:bypass';
|
|
468
|
+
nodeId: string;
|
|
469
|
+
reason: string;
|
|
470
|
+
} | {
|
|
471
|
+
type: 'subagent:fallback';
|
|
472
|
+
nodeId: string;
|
|
473
|
+
fallbackType: string;
|
|
474
|
+
} | {
|
|
475
|
+
type: 'subagent:compensate';
|
|
476
|
+
nodeId: string;
|
|
477
|
+
compensatingNodeId: string;
|
|
478
|
+
} | {
|
|
479
|
+
type: 'graph:plan';
|
|
480
|
+
plan: GraphPlan;
|
|
481
|
+
} | {
|
|
482
|
+
type: 'graph:level_start';
|
|
483
|
+
level: number;
|
|
484
|
+
nodeIds: string[];
|
|
485
|
+
} | {
|
|
486
|
+
type: 'graph:level_complete';
|
|
487
|
+
level: number;
|
|
488
|
+
results: NodeResult[];
|
|
489
|
+
} | {
|
|
490
|
+
type: 'graph:complete';
|
|
491
|
+
plan: GraphPlan;
|
|
492
|
+
progress: GraphProgress;
|
|
493
|
+
} | {
|
|
494
|
+
type: 'graph:failed';
|
|
495
|
+
plan: GraphPlan;
|
|
496
|
+
failedNodes: string[];
|
|
497
|
+
} | {
|
|
498
|
+
type: 'done';
|
|
499
|
+
reply: string;
|
|
500
|
+
tokenUsage: {
|
|
501
|
+
input: number;
|
|
502
|
+
output: number;
|
|
503
|
+
};
|
|
504
|
+
totalDuration: number;
|
|
505
|
+
} | {
|
|
506
|
+
type: 'error';
|
|
507
|
+
code: number;
|
|
508
|
+
message: string;
|
|
509
|
+
};
|
|
510
|
+
interface LdoingConfig {
|
|
511
|
+
llm: LLMAdapterConfig;
|
|
512
|
+
serverUrl?: string;
|
|
513
|
+
authToken?: string;
|
|
514
|
+
/** Custom headers sent on every request (health, MCP, LLM) */
|
|
515
|
+
headers?: Record<string, string>;
|
|
516
|
+
systemPrompt?: string;
|
|
517
|
+
context?: ContextConfig;
|
|
518
|
+
skills?: SkillsConfig;
|
|
519
|
+
limits?: LimitsConfig;
|
|
520
|
+
persistence?: IPersistence;
|
|
521
|
+
skillProvider?: ISkillProvider;
|
|
522
|
+
runtime?: 'browser' | 'node';
|
|
523
|
+
/** Permission mode: 'strict' | 'standard' | 'trusted' (default: 'standard') */
|
|
524
|
+
permissionMode?: PermissionMode;
|
|
525
|
+
/** Per-permission policy overrides (key = sub-permission, value = policy) */
|
|
526
|
+
permissionOverrides?: Record<string, PermissionPolicy>;
|
|
527
|
+
}
|
|
528
|
+
interface ContextConfig {
|
|
529
|
+
maxTokens?: number;
|
|
530
|
+
contextLength?: number;
|
|
531
|
+
outputReserve?: number;
|
|
532
|
+
autoCompress?: boolean;
|
|
533
|
+
compressThreshold?: number;
|
|
534
|
+
historyStrategy?: {
|
|
535
|
+
type: 'sliding_window' | 'token_budget' | 'relevance' | 'summary' | 'hybrid';
|
|
536
|
+
rules?: any[];
|
|
537
|
+
};
|
|
538
|
+
syncToServer?: boolean;
|
|
539
|
+
}
|
|
540
|
+
interface SkillsConfig {
|
|
541
|
+
loadDefaults?: boolean;
|
|
542
|
+
disable?: string[];
|
|
543
|
+
enable?: string[];
|
|
544
|
+
tiers?: SkillTier[];
|
|
545
|
+
permissions?: string[];
|
|
546
|
+
}
|
|
547
|
+
interface LimitsConfig {
|
|
548
|
+
maxToolCallsPerTurn?: number;
|
|
549
|
+
maxTurnsPerChat?: number;
|
|
550
|
+
skillTimeout?: number;
|
|
551
|
+
}
|
|
552
|
+
interface InitResult {
|
|
553
|
+
agentId: string;
|
|
554
|
+
mode: 'local' | 'remote' | 'hybrid';
|
|
555
|
+
llm: {
|
|
556
|
+
connected: boolean;
|
|
557
|
+
provider: string;
|
|
558
|
+
model: string;
|
|
559
|
+
};
|
|
560
|
+
capabilities: {
|
|
561
|
+
localSkills: string[];
|
|
562
|
+
serverSkills: string[];
|
|
563
|
+
llmProxy: boolean;
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
interface InstallOptions {
|
|
567
|
+
version?: string;
|
|
568
|
+
url?: string;
|
|
569
|
+
path?: string;
|
|
570
|
+
config?: Record<string, any>;
|
|
571
|
+
}
|
|
572
|
+
interface ILLMAdapter {
|
|
573
|
+
chat(messages: Message[], tools: ToolDef[], options?: {
|
|
574
|
+
signal?: AbortSignal;
|
|
575
|
+
}): Promise<StandardLLMResponse>;
|
|
576
|
+
chatStream?(messages: Message[], tools: ToolDef[], options?: {
|
|
577
|
+
signal?: AbortSignal;
|
|
578
|
+
}): AsyncIterable<StreamEvent>;
|
|
579
|
+
}
|
|
580
|
+
interface ITransport {
|
|
581
|
+
send(method: string, params: any): Promise<any>;
|
|
582
|
+
notify(method: string, params: any): void;
|
|
583
|
+
}
|
|
584
|
+
interface IPersistence {
|
|
585
|
+
saveSession(session: Session): Promise<void>;
|
|
586
|
+
loadSession(sessionId: string): Promise<Session | null>;
|
|
587
|
+
listSessions(options?: {
|
|
588
|
+
status?: string;
|
|
589
|
+
limit?: number;
|
|
590
|
+
offset?: number;
|
|
591
|
+
}): Promise<Session[]>;
|
|
592
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
593
|
+
saveSetting(key: string, value: any): Promise<void>;
|
|
594
|
+
loadSetting(key: string): Promise<any>;
|
|
595
|
+
}
|
|
596
|
+
type SkillSource = {
|
|
597
|
+
type: 'builtin' | 'inline' | 'file' | 'installed';
|
|
598
|
+
path?: string;
|
|
599
|
+
installedAt?: number;
|
|
600
|
+
format?: 'yaml' | 'skill-md' | 'prompt-md';
|
|
601
|
+
};
|
|
602
|
+
interface LoadedSkill {
|
|
603
|
+
definition: SkillDefinition;
|
|
604
|
+
handler?: SkillHandler;
|
|
605
|
+
source?: SkillSource;
|
|
606
|
+
}
|
|
607
|
+
interface SkillInstallRequest {
|
|
608
|
+
source: 'path';
|
|
609
|
+
path: string;
|
|
610
|
+
config?: Record<string, any>;
|
|
611
|
+
}
|
|
612
|
+
interface SkillInstallResult {
|
|
613
|
+
name: string;
|
|
614
|
+
format: 'yaml' | 'skill-md' | 'prompt-md';
|
|
615
|
+
source: SkillSource;
|
|
616
|
+
}
|
|
617
|
+
interface CodeExecutionConfig {
|
|
618
|
+
/** Whether code execution skills are enabled (default: true) */
|
|
619
|
+
enabled?: boolean;
|
|
620
|
+
/** Allowed languages (default: ['javascript', 'python']) */
|
|
621
|
+
languages?: ('javascript' | 'python')[];
|
|
622
|
+
/** Maximum execution timeout in ms (default: 30000) */
|
|
623
|
+
maxTimeout?: number;
|
|
624
|
+
/** Maximum output length in characters (default: 50000) */
|
|
625
|
+
maxOutputLength?: number;
|
|
626
|
+
/** Allowed directories for script_run (default: [process.cwd()]) */
|
|
627
|
+
allowedScriptDirs?: string[];
|
|
628
|
+
/** Path to Python executable (default: 'python3' on unix, 'python' on win32) */
|
|
629
|
+
pythonPath?: string;
|
|
630
|
+
/** Path to Node executable (default: 'node') */
|
|
631
|
+
nodePath?: string;
|
|
632
|
+
/** Working directory for code_eval (default: os.tmpdir()) */
|
|
633
|
+
sandboxDir?: string;
|
|
634
|
+
}
|
|
635
|
+
interface UploadConfig {
|
|
636
|
+
/** Temporary directory for uploaded files (default: os.tmpdir()) */
|
|
637
|
+
tempDir?: string;
|
|
638
|
+
/** Max file size in bytes (default: 10 * 1024 * 1024 = 10MB) */
|
|
639
|
+
maxFileSize?: number;
|
|
640
|
+
/** Allowed MIME types (default: all) */
|
|
641
|
+
allowedMimeTypes?: string[];
|
|
642
|
+
}
|
|
643
|
+
interface ServerConfig {
|
|
644
|
+
port?: number;
|
|
645
|
+
host?: string;
|
|
646
|
+
skillsDir?: string;
|
|
647
|
+
auth?: {
|
|
648
|
+
apiKey?: string;
|
|
649
|
+
jwtSecret?: string;
|
|
650
|
+
};
|
|
651
|
+
llm?: {
|
|
652
|
+
adapter: 'openai' | 'anthropic' | 'ollama';
|
|
653
|
+
model: string;
|
|
654
|
+
baseUrl?: string;
|
|
655
|
+
apiKey?: string;
|
|
656
|
+
headers?: Record<string, string>;
|
|
657
|
+
};
|
|
658
|
+
/** Code execution skill configuration */
|
|
659
|
+
codeExecution?: CodeExecutionConfig;
|
|
660
|
+
/** File upload configuration */
|
|
661
|
+
upload?: UploadConfig;
|
|
662
|
+
}
|
|
663
|
+
interface JsonRpcRequest {
|
|
664
|
+
jsonrpc: '2.0';
|
|
665
|
+
id?: number | string;
|
|
666
|
+
method: string;
|
|
667
|
+
params?: any;
|
|
668
|
+
}
|
|
669
|
+
interface JsonRpcResponse {
|
|
670
|
+
jsonrpc: '2.0';
|
|
671
|
+
id?: number | string | null;
|
|
672
|
+
result?: any;
|
|
673
|
+
error?: {
|
|
674
|
+
code: number;
|
|
675
|
+
message: string;
|
|
676
|
+
data?: any;
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
declare const ACPErrorCodes: {
|
|
680
|
+
readonly AGENT_NOT_INITIALIZED: -32100;
|
|
681
|
+
readonly SKILL_NOT_FOUND: -32101;
|
|
682
|
+
readonly SKILL_HANDLER_NOT_REGISTERED: -32102;
|
|
683
|
+
readonly SKILL_REGISTRATION_FAILED: -32103;
|
|
684
|
+
readonly SKILL_EXECUTION_FAILED: -32104;
|
|
685
|
+
readonly SKILL_EXECUTION_TIMEOUT: -32105;
|
|
686
|
+
readonly SKILL_PERMISSION_DENIED: -32106;
|
|
687
|
+
readonly SKILL_PERMISSION_DISABLED: -32109;
|
|
688
|
+
readonly SKILL_REJECTED: -32107;
|
|
689
|
+
readonly SKILL_LOCATION_UNAVAILABLE: -32108;
|
|
690
|
+
readonly SESSION_NOT_FOUND: -32110;
|
|
691
|
+
readonly CONTEXT_OVERFLOW: -32120;
|
|
692
|
+
readonly CONTEXT_COMPRESS_FAILED: -32121;
|
|
693
|
+
readonly CONTEXT_SYNC_FAILED: -32122;
|
|
694
|
+
readonly LLM_CALL_FAILED: -32130;
|
|
695
|
+
readonly LLM_TOKEN_LIMIT: -32131;
|
|
696
|
+
readonly LLM_RATE_LIMIT: -32132;
|
|
697
|
+
readonly LLM_PROVIDER_UNAVAILABLE: -32133;
|
|
698
|
+
readonly TOKEN_BUDGET_EXCEEDED: -32134;
|
|
699
|
+
readonly TASK_PLAN_FAILED: -32160;
|
|
700
|
+
readonly TASK_STEP_FAILED: -32161;
|
|
701
|
+
readonly GRAPH_PLAN_FAILED: -32170;
|
|
702
|
+
readonly GRAPH_CYCLE_DETECTED: -32171;
|
|
703
|
+
readonly GRAPH_NODE_FAILED: -32172;
|
|
704
|
+
readonly GRAPH_EXECUTION_ABORTED: -32173;
|
|
705
|
+
readonly SUBAGENT_DEPTH_EXCEEDED: -32174;
|
|
706
|
+
readonly SUBAGENT_TIMEOUT: -32175;
|
|
707
|
+
readonly CODE_EXEC_DISABLED: -32180;
|
|
708
|
+
readonly CODE_EXEC_TIMEOUT: -32181;
|
|
709
|
+
readonly CODE_EXEC_LANGUAGE_NOT_SUPPORTED: -32182;
|
|
710
|
+
readonly CODE_EXEC_PATH_NOT_ALLOWED: -32183;
|
|
711
|
+
readonly PERSISTENCE_ERROR: -32140;
|
|
712
|
+
readonly TRANSPORT_ERROR: -32141;
|
|
713
|
+
readonly AUTH_REQUIRED: -32150;
|
|
714
|
+
readonly AUTH_FAILED: -32151;
|
|
715
|
+
readonly AUTH_FORBIDDEN: -32152;
|
|
716
|
+
readonly SERVER_UNAVAILABLE: -32153;
|
|
717
|
+
};
|
|
718
|
+
declare class ACPError extends Error {
|
|
719
|
+
code: number;
|
|
720
|
+
data?: any;
|
|
721
|
+
constructor(code: number, message: string, data?: any);
|
|
722
|
+
toJSON(): {
|
|
723
|
+
code: number;
|
|
724
|
+
message: string;
|
|
725
|
+
data: any;
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* OpenAI-compatible LLM adapter.
|
|
731
|
+
* Works with OpenAI, OneAPI, FastGPT, Azure OpenAI, and any compatible proxy.
|
|
732
|
+
*/
|
|
733
|
+
declare class OpenAIAdapter implements ILLMAdapter {
|
|
734
|
+
private config;
|
|
735
|
+
private contentAdapter;
|
|
736
|
+
constructor(config: LLMAdapterConfig);
|
|
737
|
+
private getBaseUrl;
|
|
738
|
+
private getEndpoint;
|
|
739
|
+
private buildHeaders;
|
|
740
|
+
private messagesToOpenAI;
|
|
741
|
+
private toolsToOpenAI;
|
|
742
|
+
chat(messages: Message[], tools: ToolDef[], options?: {
|
|
743
|
+
signal?: AbortSignal;
|
|
744
|
+
}): Promise<StandardLLMResponse>;
|
|
745
|
+
/**
|
|
746
|
+
* Stream LLM responses token-by-token via SSE.
|
|
747
|
+
* Yields StreamEvent for each token or tool_call delta.
|
|
748
|
+
* Collects the full response and returns it at the end.
|
|
749
|
+
*/
|
|
750
|
+
chatStream(messages: Message[], tools: ToolDef[], options?: {
|
|
751
|
+
signal?: AbortSignal;
|
|
752
|
+
}): AsyncGenerator<StreamEvent>;
|
|
753
|
+
/**
|
|
754
|
+
* Check if the error response indicates context length exceeded.
|
|
755
|
+
* Throws ACPError with CONTEXT_OVERFLOW code if detected.
|
|
756
|
+
*/
|
|
757
|
+
private checkContextOverflow;
|
|
758
|
+
private parseResponse;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
declare class SkillRegistry {
|
|
762
|
+
private skills;
|
|
763
|
+
register(skill: SkillDefinition): void;
|
|
764
|
+
unregister(name: string): boolean;
|
|
765
|
+
get(name: string): SkillDefinition | undefined;
|
|
766
|
+
getHandler(name: string): SkillHandler | undefined;
|
|
767
|
+
list(): SkillDefinition[];
|
|
768
|
+
listToolDefs(filter?: {
|
|
769
|
+
tiers?: SkillTier[];
|
|
770
|
+
permissions?: string[];
|
|
771
|
+
}): ToolDef[];
|
|
772
|
+
has(name: string): boolean;
|
|
773
|
+
clear(): void;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
declare class SkillExecutor {
|
|
777
|
+
private registry;
|
|
778
|
+
private worker;
|
|
779
|
+
constructor(registry: SkillRegistry, worker?: SkillWorker);
|
|
780
|
+
getWorker(): SkillWorker;
|
|
781
|
+
getRegistry(): SkillRegistry;
|
|
782
|
+
execute(name: string, params: Record<string, any>, context: SkillContext): Promise<SkillResult>;
|
|
783
|
+
/**
|
|
784
|
+
* Directly invoke a skill by name — used by ctx.invoke().
|
|
785
|
+
* No LLM loop, no approval. Shares parent's signal and timeout context.
|
|
786
|
+
*/
|
|
787
|
+
invokeDirect(name: string, params: Record<string, any>, context: SkillContext): Promise<SkillResult>;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Connection info for an MCP Server.
|
|
792
|
+
*/
|
|
793
|
+
interface McpServerConnection {
|
|
794
|
+
name: string;
|
|
795
|
+
transport: 'stdio' | 'http';
|
|
796
|
+
toolDefs: ToolDef[];
|
|
797
|
+
call(toolName: string, args: Record<string, any>): Promise<any>;
|
|
798
|
+
disconnect(): Promise<void>;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* MCP Router — manages connections to external MCP Servers
|
|
802
|
+
* and routes tool calls with `mcp:` prefix.
|
|
803
|
+
*/
|
|
804
|
+
declare class McpRouter {
|
|
805
|
+
private connections;
|
|
806
|
+
/**
|
|
807
|
+
* Register an MCP Server connection.
|
|
808
|
+
*/
|
|
809
|
+
connect(connection: McpServerConnection): void;
|
|
810
|
+
/**
|
|
811
|
+
* Disconnect and remove an MCP Server.
|
|
812
|
+
*/
|
|
813
|
+
disconnect(name: string): Promise<void>;
|
|
814
|
+
/**
|
|
815
|
+
* Disconnect all MCP Servers.
|
|
816
|
+
*/
|
|
817
|
+
disconnectAll(): Promise<void>;
|
|
818
|
+
/**
|
|
819
|
+
* List all connected MCP Servers and their tools.
|
|
820
|
+
*/
|
|
821
|
+
listConnections(): {
|
|
822
|
+
name: string;
|
|
823
|
+
transport: string;
|
|
824
|
+
tools: string[];
|
|
825
|
+
}[];
|
|
826
|
+
/**
|
|
827
|
+
* Check if a tool name has the `mcp:` prefix.
|
|
828
|
+
*/
|
|
829
|
+
isMcpTool(toolName: string): boolean;
|
|
830
|
+
/**
|
|
831
|
+
* Parse an `mcp:` prefixed tool name into server name and tool name.
|
|
832
|
+
* "mcp:github/list_prs" → { server: "github", tool: "list_prs" }
|
|
833
|
+
*/
|
|
834
|
+
parseMcpToolName(prefixedName: string): {
|
|
835
|
+
server: string;
|
|
836
|
+
tool: string;
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* Route a tool call to the appropriate MCP Server.
|
|
840
|
+
*/
|
|
841
|
+
call(prefixedName: string, args: Record<string, any>): Promise<any>;
|
|
842
|
+
/**
|
|
843
|
+
* Resolve `mcp:` prefixed tool names from a tools list to ToolDef[].
|
|
844
|
+
* Non-mcp names are silently skipped.
|
|
845
|
+
*/
|
|
846
|
+
resolveToolDefs(mcpToolNames: string[]): ToolDef[];
|
|
847
|
+
/**
|
|
848
|
+
* Check if a specific MCP server is connected.
|
|
849
|
+
*/
|
|
850
|
+
isConnected(serverName: string): boolean;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
declare class SessionManager {
|
|
854
|
+
private sessions;
|
|
855
|
+
create(options?: {
|
|
856
|
+
title?: string;
|
|
857
|
+
meta?: Record<string, any>;
|
|
858
|
+
systemPrompt?: string;
|
|
859
|
+
}): Session;
|
|
860
|
+
get(sessionId: string): Session | undefined;
|
|
861
|
+
getOrThrow(sessionId: string): Session;
|
|
862
|
+
list(options?: {
|
|
863
|
+
status?: string;
|
|
864
|
+
limit?: number;
|
|
865
|
+
offset?: number;
|
|
866
|
+
}): Session[];
|
|
867
|
+
search(query: string, options?: {
|
|
868
|
+
limit?: number;
|
|
869
|
+
includeArchived?: boolean;
|
|
870
|
+
}): Array<{
|
|
871
|
+
sessionId: string;
|
|
872
|
+
title?: string;
|
|
873
|
+
summary?: string;
|
|
874
|
+
relevanceScore: number;
|
|
875
|
+
messageCount: number;
|
|
876
|
+
updatedAt: number;
|
|
877
|
+
}>;
|
|
878
|
+
addMessage(sessionId: string, message: Message): void;
|
|
879
|
+
delete(sessionId: string): boolean;
|
|
880
|
+
archive(sessionId: string): void;
|
|
881
|
+
merge(fromId: string, toId: string, strategy?: 'full' | 'summary' | 'summary_and_artifacts'): void;
|
|
882
|
+
private createSummary;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
interface BuildWindowResult {
|
|
886
|
+
messages: Message[];
|
|
887
|
+
usedTokens: number;
|
|
888
|
+
budget: number;
|
|
889
|
+
}
|
|
890
|
+
declare class ContextManager {
|
|
891
|
+
private config;
|
|
892
|
+
private model;
|
|
893
|
+
constructor(config?: ContextConfig, model?: string);
|
|
894
|
+
/** Update model (called when LLM config changes) */
|
|
895
|
+
setModel(model: string): void;
|
|
896
|
+
/** Compute the token budget for the current model & config */
|
|
897
|
+
getBudget(): number;
|
|
898
|
+
/**
|
|
899
|
+
* Build the context window for a session — the actual messages sent to the LLM.
|
|
900
|
+
* Now accepts tools to account for tool-definition token cost, and returns
|
|
901
|
+
* token usage statistics so callers can decide whether to compress.
|
|
902
|
+
*/
|
|
903
|
+
buildWindow(messages: Message[], systemPrompt?: string, tools?: ToolDef[], maxTokens?: number): BuildWindowResult;
|
|
904
|
+
/**
|
|
905
|
+
* Ensure context fits within budget. Triggers auto-compression when
|
|
906
|
+
* usage exceeds the configured threshold.
|
|
907
|
+
*/
|
|
908
|
+
ensureContextFits(messages: Message[], systemPrompt: string | undefined, tools: ToolDef[], model?: string): {
|
|
909
|
+
messages: Message[];
|
|
910
|
+
wasCompressed: boolean;
|
|
911
|
+
};
|
|
912
|
+
/**
|
|
913
|
+
* Compress context by summarizing older messages.
|
|
914
|
+
*/
|
|
915
|
+
compress(messages: Message[], strategy?: 'sliding_window' | 'token_budget' | 'summary' | 'hybrid'): {
|
|
916
|
+
messages: Message[];
|
|
917
|
+
beforeTokens: number;
|
|
918
|
+
afterTokens: number;
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Search across messages for relevant content.
|
|
922
|
+
*/
|
|
923
|
+
search(allSessionMessages: Map<string, Message[]>, query: string, options?: {
|
|
924
|
+
limit?: number;
|
|
925
|
+
scope?: string;
|
|
926
|
+
}): Array<{
|
|
927
|
+
sessionId: string;
|
|
928
|
+
relevanceScore: number;
|
|
929
|
+
content: string;
|
|
930
|
+
source: string;
|
|
931
|
+
}>;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
type StepStatus = 'pending' | 'running' | 'done' | 'failed' | 'skipped';
|
|
935
|
+
type TaskPlanStatus = 'planning' | 'executing' | 'completed' | 'failed' | 'paused';
|
|
936
|
+
interface StepPlan {
|
|
937
|
+
id: string;
|
|
938
|
+
index: number;
|
|
939
|
+
goal: string;
|
|
940
|
+
tools?: string[];
|
|
941
|
+
status: StepStatus;
|
|
942
|
+
result?: StepResult;
|
|
943
|
+
retryCount: number;
|
|
944
|
+
}
|
|
945
|
+
interface StepResult {
|
|
946
|
+
output: string;
|
|
947
|
+
toolCalls: number;
|
|
948
|
+
tokenUsage: {
|
|
949
|
+
input: number;
|
|
950
|
+
output: number;
|
|
951
|
+
};
|
|
952
|
+
duration: number;
|
|
953
|
+
error?: string;
|
|
954
|
+
}
|
|
955
|
+
interface TaskPlan {
|
|
956
|
+
id: string;
|
|
957
|
+
goal: string;
|
|
958
|
+
steps: StepPlan[];
|
|
959
|
+
status: TaskPlanStatus;
|
|
960
|
+
createdAt: number;
|
|
961
|
+
updatedAt: number;
|
|
962
|
+
totalTokenUsage: {
|
|
963
|
+
input: number;
|
|
964
|
+
output: number;
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
interface TaskProgress {
|
|
968
|
+
current: number;
|
|
969
|
+
total: number;
|
|
970
|
+
percentage: number;
|
|
971
|
+
}
|
|
972
|
+
interface TaskCheckpoint {
|
|
973
|
+
planId: string;
|
|
974
|
+
currentStepIndex: number;
|
|
975
|
+
sessionId: string;
|
|
976
|
+
timestamp: number;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Local transport — direct method calls within the same process.
|
|
981
|
+
* Zero overhead, used when SDK runs without a server.
|
|
982
|
+
*/
|
|
983
|
+
declare class LocalTransport implements ITransport {
|
|
984
|
+
private handlers;
|
|
985
|
+
registerHandler(method: string, handler: (params: any) => Promise<any>): void;
|
|
986
|
+
send(method: string, params: any): Promise<any>;
|
|
987
|
+
notify(_method: string, _params: any): void;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* HTTP transport — communicates with ListDoing Server via JSON-RPC 2.0 over HTTP.
|
|
992
|
+
*/
|
|
993
|
+
declare class HttpTransport implements ITransport {
|
|
994
|
+
private baseUrl;
|
|
995
|
+
private authToken?;
|
|
996
|
+
private customHeaders?;
|
|
997
|
+
private sessionId?;
|
|
998
|
+
private requestId;
|
|
999
|
+
constructor(baseUrl: string, authToken?: string, customHeaders?: Record<string, string>);
|
|
1000
|
+
setSessionId(id: string): void;
|
|
1001
|
+
setAuthToken(token: string): void;
|
|
1002
|
+
private buildHeaders;
|
|
1003
|
+
send(method: string, params: any): Promise<any>;
|
|
1004
|
+
notify(method: string, params: any): void;
|
|
1005
|
+
/**
|
|
1006
|
+
* Stream a chat request via SSE.
|
|
1007
|
+
*/
|
|
1008
|
+
streamChat(method: string, params: any): AsyncGenerator<{
|
|
1009
|
+
method: string;
|
|
1010
|
+
params: any;
|
|
1011
|
+
} | {
|
|
1012
|
+
id: number;
|
|
1013
|
+
result: any;
|
|
1014
|
+
}>;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
type EventHandler = (event: any) => void;
|
|
1018
|
+
declare function detectRuntime(): 'browser' | 'node';
|
|
1019
|
+
declare class Ldoing {
|
|
1020
|
+
protected config: LdoingConfig;
|
|
1021
|
+
private agentId;
|
|
1022
|
+
private initialized;
|
|
1023
|
+
private startTime;
|
|
1024
|
+
protected llmAdapter: OpenAIAdapter;
|
|
1025
|
+
protected skillRegistry: SkillRegistry;
|
|
1026
|
+
protected skillExecutor: SkillExecutor;
|
|
1027
|
+
protected mcpRouter: McpRouter;
|
|
1028
|
+
protected sessionManager: SessionManager;
|
|
1029
|
+
protected contextManager: ContextManager;
|
|
1030
|
+
protected transport: LocalTransport | HttpTransport;
|
|
1031
|
+
protected persistence: IPersistence;
|
|
1032
|
+
private currentSessionId;
|
|
1033
|
+
private abortControllers;
|
|
1034
|
+
private approvalResolvers;
|
|
1035
|
+
private eventHandlers;
|
|
1036
|
+
private tokenCalibrationRatio;
|
|
1037
|
+
constructor(config: LdoingConfig);
|
|
1038
|
+
init(): Promise<InitResult>;
|
|
1039
|
+
destroy(): Promise<void>;
|
|
1040
|
+
getStatus(): {
|
|
1041
|
+
agentId: string;
|
|
1042
|
+
mode: string;
|
|
1043
|
+
uptime: number;
|
|
1044
|
+
activeSessions: number;
|
|
1045
|
+
loadedSkills: number;
|
|
1046
|
+
llm: {
|
|
1047
|
+
adapter: "custom" | "openai" | "anthropic" | "ollama";
|
|
1048
|
+
model: string;
|
|
1049
|
+
connected: boolean;
|
|
1050
|
+
};
|
|
1051
|
+
};
|
|
1052
|
+
chat(message: string | ContentBlock[], options?: ChatOptions): Promise<ChatResult>;
|
|
1053
|
+
chatStream(message: string | ContentBlock[], options?: ChatOptions): AsyncGenerator<StreamEvent>;
|
|
1054
|
+
abort(sessionId?: string): Promise<void>;
|
|
1055
|
+
approveTool(callId: string, approved: boolean, _reason?: string): void;
|
|
1056
|
+
private waitForApproval;
|
|
1057
|
+
registerSkill(skill: SkillDefinition): void;
|
|
1058
|
+
unregisterSkill(name: string): void;
|
|
1059
|
+
listSkills(): SkillDefinition[];
|
|
1060
|
+
useSkillPack(pack: SkillPack, config?: Record<string, any>): SkillPackRegistration;
|
|
1061
|
+
unuseSkillPack(registration: SkillPackRegistration): void;
|
|
1062
|
+
private createAgentLoopHandler;
|
|
1063
|
+
/** Internal chat for agentLoop/workflow/sub-agent execution. Condenses inner messages after completion. */
|
|
1064
|
+
chatInner(prompt: string, sessionId: string, options?: ChatOptions): Promise<ChatResult>;
|
|
1065
|
+
private chatWithPlan;
|
|
1066
|
+
private chatStreamWithPlan;
|
|
1067
|
+
resumeTask(sessionId: string, options?: ChatOptions): Promise<ChatResult>;
|
|
1068
|
+
getTaskPlan(sessionId: string): TaskPlan | null;
|
|
1069
|
+
/** Get current session ID (used by SubAgent for parent reference) */
|
|
1070
|
+
getCurrentSessionId(): string | null;
|
|
1071
|
+
private chatWithGraph;
|
|
1072
|
+
private chatStreamWithGraph;
|
|
1073
|
+
/** Resume a graph execution from checkpoint */
|
|
1074
|
+
resumeGraph(sessionId: string, options?: ChatOptions): Promise<ChatResult>;
|
|
1075
|
+
/** Get graph plan from session */
|
|
1076
|
+
getGraphPlan(sessionId: string): GraphPlan | null;
|
|
1077
|
+
private createWorkflowHandler;
|
|
1078
|
+
/** Create DAG workflow handler — steps with dependsOn are executed via GraphExecutor */
|
|
1079
|
+
private createDagWorkflowHandler;
|
|
1080
|
+
/** Create subgraph handler for SkillDefinition.subgraph */
|
|
1081
|
+
private createSubgraphHandler;
|
|
1082
|
+
installSkill(_source: string, _name?: string, _options?: InstallOptions): Promise<void>;
|
|
1083
|
+
uninstallSkill(_name: string): Promise<void>;
|
|
1084
|
+
createSession(options?: {
|
|
1085
|
+
title?: string;
|
|
1086
|
+
meta?: Record<string, any>;
|
|
1087
|
+
systemPrompt?: string;
|
|
1088
|
+
}): Session;
|
|
1089
|
+
getSession(sessionId: string): Session | undefined;
|
|
1090
|
+
listSessions(options?: {
|
|
1091
|
+
status?: string;
|
|
1092
|
+
limit?: number;
|
|
1093
|
+
offset?: number;
|
|
1094
|
+
}): Session[];
|
|
1095
|
+
searchSessions(query: string, options?: {
|
|
1096
|
+
limit?: number;
|
|
1097
|
+
includeArchived?: boolean;
|
|
1098
|
+
}): {
|
|
1099
|
+
sessionId: string;
|
|
1100
|
+
title?: string;
|
|
1101
|
+
summary?: string;
|
|
1102
|
+
relevanceScore: number;
|
|
1103
|
+
messageCount: number;
|
|
1104
|
+
updatedAt: number;
|
|
1105
|
+
}[];
|
|
1106
|
+
mergeSessions(fromId: string, toId: string, strategy?: 'full' | 'summary' | 'summary_and_artifacts'): void;
|
|
1107
|
+
deleteSession(sessionId: string): void;
|
|
1108
|
+
archiveSession(sessionId: string): void;
|
|
1109
|
+
getContext(sessionId: string, format?: 'messages' | 'summary' | 'window'): Message[] | string;
|
|
1110
|
+
searchContext(query: string, options?: {
|
|
1111
|
+
limit?: number;
|
|
1112
|
+
scope?: string;
|
|
1113
|
+
}): {
|
|
1114
|
+
sessionId: string;
|
|
1115
|
+
relevanceScore: number;
|
|
1116
|
+
content: string;
|
|
1117
|
+
source: string;
|
|
1118
|
+
}[];
|
|
1119
|
+
compressContext(sessionId: string, strategy?: 'sliding_window' | 'token_budget' | 'summary' | 'hybrid'): {
|
|
1120
|
+
beforeTokens: number;
|
|
1121
|
+
afterTokens: number;
|
|
1122
|
+
compressionRatio: number;
|
|
1123
|
+
};
|
|
1124
|
+
configure(config: Partial<LdoingConfig>): void;
|
|
1125
|
+
on(event: string, handler: EventHandler): void;
|
|
1126
|
+
off(event: string, handler: EventHandler): void;
|
|
1127
|
+
private emit;
|
|
1128
|
+
/**
|
|
1129
|
+
* Stream LLM response token-by-token via the adapter's chatStream.
|
|
1130
|
+
* Forwards llm_text events to the caller and collects the full StandardLLMResponse.
|
|
1131
|
+
*/
|
|
1132
|
+
private streamLlmResponse;
|
|
1133
|
+
/**
|
|
1134
|
+
* Resolve tool list: filter by tier/permission/name + add MCP tool definitions.
|
|
1135
|
+
*
|
|
1136
|
+
* - No allowedTools & no toolsByPermission → only system tier tools
|
|
1137
|
+
* - allowedTools only → filter by name (backward compat)
|
|
1138
|
+
* - toolsByPermission (with or without allowedTools) → union of permission-matched + name-matched
|
|
1139
|
+
*/
|
|
1140
|
+
private resolveTools;
|
|
1141
|
+
/**
|
|
1142
|
+
* Compute auto-approval set: non-system tier tools with sensitive permissions
|
|
1143
|
+
* are automatically added to the approval set.
|
|
1144
|
+
*/
|
|
1145
|
+
private computeAutoApproval;
|
|
1146
|
+
/**
|
|
1147
|
+
* Check permission policy for a tool call using the full permission system.
|
|
1148
|
+
* Returns the policy: 'auto' | 'approval' | 'force-approval' | 'disabled'
|
|
1149
|
+
*/
|
|
1150
|
+
private checkToolPermission;
|
|
1151
|
+
private planToolExecution;
|
|
1152
|
+
private processApprovalQueue;
|
|
1153
|
+
private executeToolBatch;
|
|
1154
|
+
private executeToolBatchStream;
|
|
1155
|
+
/**
|
|
1156
|
+
* Execute a tool call, routing mcp: prefixed tools to McpRouter.
|
|
1157
|
+
*/
|
|
1158
|
+
private executeToolCall;
|
|
1159
|
+
private ensureInitialized;
|
|
1160
|
+
private ensureSession;
|
|
1161
|
+
/** Resolve system prompt — can be overridden by subclasses to inject context */
|
|
1162
|
+
protected resolveSystemPrompt(sessionId: string, base: string): string;
|
|
1163
|
+
private buildUserContent;
|
|
1164
|
+
private addToolResult;
|
|
1165
|
+
private executeServerSkill;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Interpolate {{var}} template variables.
|
|
1170
|
+
* Supports: {{inputs.xxx}}, {{steps.stepName.output}}
|
|
1171
|
+
* Dot-path resolution for nested objects; missing values → empty string.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function interpolateTemplate(template: string, variables: {
|
|
1174
|
+
inputs: Record<string, any>;
|
|
1175
|
+
steps: Record<string, {
|
|
1176
|
+
output: string;
|
|
1177
|
+
}>;
|
|
1178
|
+
}): string;
|
|
1179
|
+
/** agentLoop-specific interpolation (only inputs, no steps) */
|
|
1180
|
+
declare function interpolateInstruction(instruction: string, inputs: Record<string, any>): string;
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Resolve the effective policy for a specific tool call.
|
|
1184
|
+
*
|
|
1185
|
+
* Priority (high → low):
|
|
1186
|
+
* 1. Chat-level autoApprove → 'auto'
|
|
1187
|
+
* 2. Chat-level permissionMode + permissionOverrides
|
|
1188
|
+
* 3. Global permissionMode + permissionOverrides
|
|
1189
|
+
* 4. Chat-level requireApproval → 'force-approval'
|
|
1190
|
+
* 5. CapabilityMap fine-grained lookup
|
|
1191
|
+
* 6. Fallback: coarse-grained permissions lookup
|
|
1192
|
+
* 7. Default for unknown permissions: 'auto' in trusted, 'approval' otherwise
|
|
1193
|
+
*/
|
|
1194
|
+
declare function resolvePermissionPolicy(params: {
|
|
1195
|
+
/** Skill definition being called */
|
|
1196
|
+
skill: SkillDefinition;
|
|
1197
|
+
/** Tool call arguments (used to look up capabilityMap key) */
|
|
1198
|
+
args: Record<string, any>;
|
|
1199
|
+
/** Global permission mode from Ldoing config */
|
|
1200
|
+
globalMode: PermissionMode;
|
|
1201
|
+
/** Global per-permission overrides from Ldoing config */
|
|
1202
|
+
globalOverrides?: Record<string, PermissionPolicy>;
|
|
1203
|
+
/** Chat-level autoApprove flag */
|
|
1204
|
+
autoApprove?: boolean;
|
|
1205
|
+
/** Chat-level permission mode override */
|
|
1206
|
+
chatMode?: PermissionMode;
|
|
1207
|
+
/** Chat-level requireApproval list (tool names) */
|
|
1208
|
+
requireApproval?: Set<string>;
|
|
1209
|
+
}): PermissionPolicy;
|
|
1210
|
+
|
|
1211
|
+
interface ModelCapabilities {
|
|
1212
|
+
contextLength: number;
|
|
1213
|
+
supportsImages?: boolean;
|
|
1214
|
+
supportedImageTypes?: string[];
|
|
1215
|
+
maxImageSize?: number;
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Resolve the context length (max input tokens) for a given model.
|
|
1219
|
+
* Strategy: exact match → prefix match → conservative default (4096).
|
|
1220
|
+
*/
|
|
1221
|
+
declare function resolveModelContextLength(model: string, override?: number): number;
|
|
1222
|
+
/**
|
|
1223
|
+
* Resolve model capabilities (image support, context length, etc.)
|
|
1224
|
+
* Strategy: exact match → prefix match → conservative default.
|
|
1225
|
+
*/
|
|
1226
|
+
declare function resolveModelCapabilities(model: string): ModelCapabilities;
|
|
1227
|
+
|
|
1228
|
+
declare function estimateTextTokens(text: string): number;
|
|
1229
|
+
declare function estimateMessageTokens(msg: Message): number;
|
|
1230
|
+
declare function estimateToolDefTokens(tool: ToolDef): number;
|
|
1231
|
+
declare function estimateRequestTokens(messages: Message[], tools: ToolDef[], systemPrompt?: string): number;
|
|
1232
|
+
|
|
1233
|
+
declare class MemoryPersistence implements IPersistence {
|
|
1234
|
+
private sessions;
|
|
1235
|
+
private settings;
|
|
1236
|
+
saveSession(session: Session): Promise<void>;
|
|
1237
|
+
loadSession(sessionId: string): Promise<Session | null>;
|
|
1238
|
+
listSessions(options?: {
|
|
1239
|
+
status?: string;
|
|
1240
|
+
limit?: number;
|
|
1241
|
+
offset?: number;
|
|
1242
|
+
}): Promise<Session[]>;
|
|
1243
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
1244
|
+
saveSetting(key: string, value: any): Promise<void>;
|
|
1245
|
+
loadSetting(key: string): Promise<any>;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* TaskPlanner: calls LLM to decompose a user goal into a structured step plan.
|
|
1250
|
+
*/
|
|
1251
|
+
declare class TaskPlanner {
|
|
1252
|
+
private llmAdapter;
|
|
1253
|
+
constructor(llmAdapter: ILLMAdapter);
|
|
1254
|
+
plan(goal: string, availableTools: ToolDef[]): Promise<TaskPlan>;
|
|
1255
|
+
private buildPlanningPrompt;
|
|
1256
|
+
private parsePlan;
|
|
1257
|
+
private extractSteps;
|
|
1258
|
+
private extractJSON;
|
|
1259
|
+
private makeStep;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
type Emitter$1 = (event: string, data: any) => void;
|
|
1263
|
+
/**
|
|
1264
|
+
* PlanTracker: tracks step execution status, emits progress events,
|
|
1265
|
+
* persists plan/checkpoint to Session.meta.
|
|
1266
|
+
*/
|
|
1267
|
+
declare class PlanTracker {
|
|
1268
|
+
private plan;
|
|
1269
|
+
private sessionId;
|
|
1270
|
+
private emit;
|
|
1271
|
+
constructor(plan: TaskPlan, sessionId: string, emit: Emitter$1);
|
|
1272
|
+
/** Mark the plan as executing */
|
|
1273
|
+
startExecuting(): void;
|
|
1274
|
+
/** Mark a step as running */
|
|
1275
|
+
startStep(index: number): void;
|
|
1276
|
+
/** Mark a step as done with its result */
|
|
1277
|
+
completeStep(index: number, result: StepResult): void;
|
|
1278
|
+
/** Mark a step as failed */
|
|
1279
|
+
failStep(index: number, result: StepResult): void;
|
|
1280
|
+
/** Mark a step as skipped */
|
|
1281
|
+
skipStep(index: number): void;
|
|
1282
|
+
/** Set plan status */
|
|
1283
|
+
setPlanStatus(status: TaskPlanStatus): void;
|
|
1284
|
+
/** Get current progress */
|
|
1285
|
+
getProgress(): TaskProgress;
|
|
1286
|
+
/** Get the plan */
|
|
1287
|
+
getPlan(): TaskPlan;
|
|
1288
|
+
/** Find the index of the first step matching a status */
|
|
1289
|
+
findStepIndex(status: StepStatus): number;
|
|
1290
|
+
/** Persist plan to session.meta */
|
|
1291
|
+
persistPlan(session: Session): void;
|
|
1292
|
+
/** Save checkpoint (current execution position) */
|
|
1293
|
+
saveCheckpoint(session: Session, currentStepIndex: number): TaskCheckpoint;
|
|
1294
|
+
/** Load plan from session.meta */
|
|
1295
|
+
static loadPlan(session: Session): TaskPlan | null;
|
|
1296
|
+
/** Load checkpoint from session.meta */
|
|
1297
|
+
static loadCheckpoint(session: Session): TaskCheckpoint | null;
|
|
1298
|
+
/** Clear checkpoint from session.meta */
|
|
1299
|
+
static clearCheckpoint(session: Session): void;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* TaskGraph: DAG construction with topological sort (Kahn's algorithm).
|
|
1304
|
+
* Validates acyclicity and dependency references, computes parallelizable levels.
|
|
1305
|
+
*/
|
|
1306
|
+
declare class TaskGraph {
|
|
1307
|
+
private nodes;
|
|
1308
|
+
private levels;
|
|
1309
|
+
constructor(nodes: GraphNode[]);
|
|
1310
|
+
/** Validate: no cycles, all dependency references valid */
|
|
1311
|
+
validate(): {
|
|
1312
|
+
valid: boolean;
|
|
1313
|
+
errors: string[];
|
|
1314
|
+
};
|
|
1315
|
+
/** Kahn's algorithm topological sort → level list (same level = parallelizable) */
|
|
1316
|
+
computeLevels(): string[][];
|
|
1317
|
+
private computeLevelsUnsafe;
|
|
1318
|
+
getLevel(level: number): GraphNode[];
|
|
1319
|
+
getLevelCount(): number;
|
|
1320
|
+
getNode(id: string): GraphNode | undefined;
|
|
1321
|
+
getAllNodes(): GraphNode[];
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* GraphPlanner: generates DAG plans with dependency relationships.
|
|
1326
|
+
* Prompts the LLM to output a JSON array of nodes with id, goal, dependsOn, tools.
|
|
1327
|
+
*/
|
|
1328
|
+
declare class GraphPlanner {
|
|
1329
|
+
protected llmAdapter: ILLMAdapter;
|
|
1330
|
+
constructor(llmAdapter: ILLMAdapter);
|
|
1331
|
+
planGraph(goal: string, availableTools: ToolDef[]): Promise<GraphPlan>;
|
|
1332
|
+
private buildGraphPlanningPrompt;
|
|
1333
|
+
private parseGraphPlan;
|
|
1334
|
+
private extractGraphNodes;
|
|
1335
|
+
private extractJSON;
|
|
1336
|
+
/** Fallback: create a sequential graph (each node depends on the previous one) */
|
|
1337
|
+
private fallbackSequentialGraph;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
type Emitter = (event: string, data: any) => void;
|
|
1341
|
+
/**
|
|
1342
|
+
* GraphExecutor: executes a DAG plan level-by-level with concurrency control,
|
|
1343
|
+
* trigger rules, retry with exponential backoff, fallback strategies, and circuit breaking.
|
|
1344
|
+
*/
|
|
1345
|
+
declare class GraphExecutor {
|
|
1346
|
+
private graph;
|
|
1347
|
+
private plan;
|
|
1348
|
+
private parentAgent;
|
|
1349
|
+
private maxConcurrency;
|
|
1350
|
+
private maxDepth;
|
|
1351
|
+
private baseDepth;
|
|
1352
|
+
private abortController;
|
|
1353
|
+
private toolFailureCount;
|
|
1354
|
+
private emit;
|
|
1355
|
+
constructor(options: {
|
|
1356
|
+
graph: TaskGraph;
|
|
1357
|
+
parentAgent: Ldoing;
|
|
1358
|
+
plan: GraphPlan;
|
|
1359
|
+
maxConcurrency?: number;
|
|
1360
|
+
maxDepth?: number;
|
|
1361
|
+
baseDepth?: number;
|
|
1362
|
+
emit: Emitter;
|
|
1363
|
+
});
|
|
1364
|
+
/** Execute the entire graph, level by level */
|
|
1365
|
+
execute(): Promise<GraphPlan>;
|
|
1366
|
+
/** Execute a single level — nodes run concurrently (limited by maxConcurrency) */
|
|
1367
|
+
private executeLevel;
|
|
1368
|
+
/** Execute a single node with retry + fallback */
|
|
1369
|
+
private executeNode;
|
|
1370
|
+
/** Check if a node should execute based on its trigger rule and upstream results */
|
|
1371
|
+
private shouldRun;
|
|
1372
|
+
/** Execute with retry (exponential backoff) */
|
|
1373
|
+
private executeWithRetry;
|
|
1374
|
+
/** Run a SubAgent for a node */
|
|
1375
|
+
private runSubAgent;
|
|
1376
|
+
/** Fallback handling: bypass / fallback / compensate */
|
|
1377
|
+
private runFallback;
|
|
1378
|
+
/** Circuit breaker: check if a tool has failed too many times */
|
|
1379
|
+
private isToolCircuitOpen;
|
|
1380
|
+
/** Track tool failures for circuit breaking */
|
|
1381
|
+
private trackToolFailures;
|
|
1382
|
+
/** Get execution progress */
|
|
1383
|
+
getProgress(): GraphProgress;
|
|
1384
|
+
/** Abort all sub-agents */
|
|
1385
|
+
abort(): void;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* SubAgent: independent child agent with isolated session.
|
|
1390
|
+
* Does not reuse parent session — creates its own via parent's SessionManager.
|
|
1391
|
+
*/
|
|
1392
|
+
declare class SubAgent {
|
|
1393
|
+
readonly id: string;
|
|
1394
|
+
readonly nodeId: string;
|
|
1395
|
+
readonly depth: number;
|
|
1396
|
+
private config;
|
|
1397
|
+
private parentAgent;
|
|
1398
|
+
private sessionId;
|
|
1399
|
+
private abortController;
|
|
1400
|
+
private status;
|
|
1401
|
+
constructor(options: {
|
|
1402
|
+
nodeId: string;
|
|
1403
|
+
parentAgent: Ldoing;
|
|
1404
|
+
config: SubAgentConfig;
|
|
1405
|
+
depth: number;
|
|
1406
|
+
parentSignal?: AbortSignal;
|
|
1407
|
+
});
|
|
1408
|
+
/** Execute the sub-agent task with upstream outputs as context */
|
|
1409
|
+
execute(goal: string, upstreamOutputs: Record<string, string>): Promise<NodeResult>;
|
|
1410
|
+
/** Abort the sub-agent */
|
|
1411
|
+
abort(): void;
|
|
1412
|
+
getStatus(): string;
|
|
1413
|
+
private buildPrompt;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/** Extract plain text from Message.content (string or ContentBlock[]) */
|
|
1417
|
+
declare function contentToString(content: string | ContentBlock[]): string;
|
|
1418
|
+
/** Extract a preview (first N characters) from Message.content */
|
|
1419
|
+
declare function contentToPreview(content: string | ContentBlock[], maxLen?: number): string;
|
|
1420
|
+
/** Estimate token count for ContentBlock[] */
|
|
1421
|
+
declare function estimateContentTokens(blocks: ContentBlock[]): number;
|
|
1422
|
+
/** Convert FileInput[] to ContentBlock[] */
|
|
1423
|
+
declare function fileInputsToContentBlocks(files: FileInput[]): ContentBlock[];
|
|
1424
|
+
|
|
1425
|
+
interface IContentAdapter {
|
|
1426
|
+
/** Convert ContentBlock[] to the provider's wire format */
|
|
1427
|
+
formatContent(blocks: ContentBlock[]): any[];
|
|
1428
|
+
/** Convert Message.content (string or ContentBlock[]) to the provider's message content format */
|
|
1429
|
+
formatMessageContent(content: string | ContentBlock[]): string | any[];
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* OpenAI content adapter.
|
|
1434
|
+
* Converts ContentBlock[] to OpenAI's multimodal message content format.
|
|
1435
|
+
*/
|
|
1436
|
+
declare class OpenAIContentAdapter implements IContentAdapter {
|
|
1437
|
+
formatContent(blocks: ContentBlock[]): any[];
|
|
1438
|
+
formatMessageContent(content: string | ContentBlock[]): string | any[];
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
export { ACPError, ACPErrorCodes, type BuildWindowResult, type ChatOptions, type ChatResult, type CodeExecutionConfig, type ContentBlock, type ContextConfig, ContextManager, type ExecutionTrace, type FallbackStrategy, type FileInput, type GraphCheckpoint, type GraphDefinition, GraphExecutor, type GraphNode, type GraphPlan, GraphPlanner, type GraphProgress, HttpTransport, type IContentAdapter, type ILLMAdapter, type IPersistence, type ISkillProvider, type ITransport, type InitResult, type InstallOptions, type JsonRpcRequest, type JsonRpcResponse, type LLMAdapterConfig, Ldoing, type LdoingConfig, type LimitsConfig, type LoadedSkill, LocalTransport, McpRouter, type McpServerConnection, MemoryPersistence, type Message, type ModelCapabilities, type NodeResult, type NodeStatus, OpenAIAdapter, OpenAIContentAdapter, PERMISSION_MODE_DEFAULTS, type PermissionMode, type PermissionPolicy, PlanTracker, type RetryPolicy, SENSITIVE_PERMISSIONS, type ServerConfig, type Session, SessionManager, type SkillContext, type SkillDefinition, SkillExecutor, type SkillHandler, type SkillInstallRequest, type SkillInstallResult, type SkillPack, type SkillPackEnv, type SkillPackRegistration, type SkillPackResult, SkillRegistry, type SkillResult, type SkillSource, type SkillTier, type SkillWorker, type SkillsConfig, type StandardLLMResponse, type StepPlan, type StepResult, type StepStatus, type StreamEvent, SubAgent, type SubAgentConfig, type TaskCheckpoint, TaskGraph, type TaskPlan, type TaskPlanStatus, TaskPlanner, type TaskProgress, type ToolCall, type ToolDef, type TriggerRule, type UploadConfig, type WorkflowDefinition, type WorkflowProgress, type WorkflowStep, contentToPreview, contentToString, detectRuntime, estimateContentTokens, estimateMessageTokens, estimateRequestTokens, estimateTextTokens, estimateToolDefTokens, fileInputsToContentBlocks, interpolateInstruction, interpolateTemplate, resolveModelCapabilities, resolveModelContextLength, resolvePermissionPolicy };
|