@listdoing/core 0.1.5 → 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/dist/index.d.mts CHANGED
@@ -143,6 +143,8 @@ interface SkillDefinition {
143
143
  parallelSafe?: boolean;
144
144
  tier?: SkillTier;
145
145
  timeout?: number;
146
+ /** Opt in only for handlers whose late side effects are controlled by the host. */
147
+ timeoutMode?: 'cooperative' | 'deadline';
146
148
  /** Direct handler (execution mode: call) */
147
149
  handler?: SkillHandler;
148
150
  /** Agent-based skill: model autonomously loops using tools */
@@ -163,6 +165,8 @@ interface SkillDefinition {
163
165
  type SkillHandler = (params: Record<string, any>, context: SkillContext) => Promise<SkillResult>;
164
166
  interface SkillContext {
165
167
  sessionId: string;
168
+ /** Stable business deduplication key for a Server tool call, when provided. */
169
+ idempotencyKey?: string;
166
170
  agent?: any;
167
171
  signal: AbortSignal;
168
172
  /** Current SubAgent instance (if executing inside a graph node) */
@@ -242,6 +246,19 @@ interface WorkflowProgress {
242
246
  failedSteps: string[];
243
247
  }
244
248
  interface LLMAdapterConfig {
249
+ /** Disabled by default. Covers headers, response body and retry delays. */
250
+ requestTimeoutMs?: number;
251
+ /** Disabled by default. Maximum wait between streaming chunks. */
252
+ streamIdleTimeoutMs?: number;
253
+ /** Opt in for providers that reliably emit finish_reason or [DONE]. */
254
+ strictStream?: boolean;
255
+ /** Opt in to provider-reported prompt cache usage. Streaming requests may include stream_options. */
256
+ collectPromptCacheUsage?: boolean;
257
+ /** Retries only HTTP 429/502/503/504 before consuming a response. Default: no retries. */
258
+ retry?: {
259
+ maxRetries?: number;
260
+ baseDelayMs?: number;
261
+ };
245
262
  adapter: 'openai' | 'anthropic' | 'ollama' | 'custom';
246
263
  model: string;
247
264
  baseUrl?: string;
@@ -268,12 +285,20 @@ interface StandardLLMResponse {
268
285
  input: number;
269
286
  output: number;
270
287
  };
288
+ promptCacheUsage?: PromptCacheUsage;
271
289
  finishReason?: string;
272
290
  }
291
+ interface PromptCacheUsage {
292
+ inputTokens?: number;
293
+ cachedTokens?: number;
294
+ cacheWriteTokens?: number;
295
+ }
273
296
  interface ToolCall {
274
297
  id: string;
275
298
  name: string;
276
299
  arguments: Record<string, any>;
300
+ /** Adapter detected invalid arguments; the handler must not be invoked. */
301
+ parseError?: string;
277
302
  }
278
303
  interface ToolDef {
279
304
  name: string;
@@ -322,7 +347,18 @@ interface Session {
322
347
  systemPrompt?: string;
323
348
  messages: Message[];
324
349
  }
350
+ /** Instructions and local tools scoped to one chat invocation. */
351
+ interface ChatRunContext {
352
+ systemPromptSuffix?: string;
353
+ skills?: readonly SkillDefinition[];
354
+ /** @internal A run-local interaction skill that must execute alone in its tool batch. */
355
+ exclusiveSkill?: string;
356
+ }
325
357
  interface ChatOptions {
358
+ /** Optional, transient context. It is not written to the session. */
359
+ runContext?: ChatRunContext;
360
+ /** Optional parent cancellation, also used by nested tasks. */
361
+ signal?: AbortSignal;
326
362
  sessionId?: string;
327
363
  requireApproval?: string[];
328
364
  /** Skip all approval checks for this chat call (overrides everything) */
@@ -356,6 +392,7 @@ interface ChatOptions {
356
392
  _skipLock?: boolean;
357
393
  }
358
394
  interface ChatResult {
395
+ terminationReason?: 'stop' | 'max_turns' | 'cancelled';
359
396
  reply: string;
360
397
  sessionId: string;
361
398
  executionTrace: ExecutionTrace[];
@@ -510,13 +547,31 @@ type StreamEvent = {
510
547
  output: number;
511
548
  };
512
549
  totalDuration: number;
550
+ terminationReason?: 'stop' | 'max_turns' | 'cancelled';
513
551
  } | {
514
552
  type: 'error';
515
553
  code: number;
516
554
  message: string;
517
555
  };
556
+ type LLMProxyMode = 'backend' | 'listdoing-server';
557
+ type McpConnectionStatus = 'not-configured' | 'unchecked' | 'connected' | 'failed';
558
+ interface LLMRouteStatus {
559
+ mode: LLMProxyMode | 'legacy';
560
+ endpoint: string;
561
+ verified: boolean;
562
+ }
518
563
  interface LdoingConfig {
564
+ /** Observability only: exceptions in this callback never interrupt the agent. */
565
+ onDiagnostic?: (event: {
566
+ kind: string;
567
+ sessionId?: string;
568
+ message: string;
569
+ model?: string;
570
+ promptCacheUsage?: PromptCacheUsage;
571
+ }) => void;
519
572
  llm: LLMAdapterConfig;
573
+ /** Opt in to explicit proxy routing. Omit to keep legacy routing. */
574
+ llmProxyMode?: LLMProxyMode;
520
575
  serverUrl?: string;
521
576
  authToken?: string;
522
577
  /** Custom headers sent on every request (health, MCP, LLM) */
@@ -558,6 +613,8 @@ interface ContextConfig {
558
613
  syncToServer?: boolean;
559
614
  }
560
615
  interface SkillsConfig {
616
+ /** Opt-in JSON Schema validation; legacy definitions remain accepted by default. */
617
+ validateInputs?: boolean;
561
618
  loadDefaults?: boolean;
562
619
  disable?: string[];
563
620
  enable?: string[];
@@ -572,6 +629,8 @@ interface LimitsConfig {
572
629
  interface InitResult {
573
630
  agentId: string;
574
631
  mode: 'local' | 'remote' | 'hybrid';
632
+ llmRoute?: LLMRouteStatus;
633
+ mcpStatus?: McpConnectionStatus;
575
634
  llm: {
576
635
  connected: boolean;
577
636
  provider: string;
@@ -598,7 +657,9 @@ interface ILLMAdapter {
598
657
  }): AsyncIterable<StreamEvent>;
599
658
  }
600
659
  interface ITransport {
601
- send(method: string, params: any): Promise<any>;
660
+ send(method: string, params: any, options?: {
661
+ signal?: AbortSignal;
662
+ }): Promise<any>;
602
663
  notify(method: string, params: any): void;
603
664
  }
604
665
  interface IPersistence {
@@ -653,12 +714,37 @@ interface CodeExecutionConfig {
653
714
  sandboxDir?: string;
654
715
  }
655
716
  interface UploadConfig {
656
- /** Temporary directory for uploaded files (default: os.tmpdir()) */
717
+ /** Temporary directory for uploaded files (default: listdoing-uploads inside os.tmpdir()) */
657
718
  tempDir?: string;
658
719
  /** Max file size in bytes (default: 10 * 1024 * 1024 = 10MB) */
659
720
  maxFileSize?: number;
660
721
  /** Allowed MIME types (default: all) */
661
722
  allowedMimeTypes?: string[];
723
+ /** Maximum file count per batch. */
724
+ maxFiles?: number;
725
+ /** Maximum combined bytes per request. */
726
+ maxTotalSize?: number;
727
+ /** Combined disk quota for temporary files. */
728
+ maxStoredSize?: number;
729
+ /** Lifetime of temporary files in milliseconds. */
730
+ ttlMs?: number;
731
+ }
732
+ type ServerPermission = 'model' | 'agent' | 'tools' | 'admin';
733
+ interface ServerScopePolicy {
734
+ allowedTools?: readonly string[];
735
+ maxActiveRuns?: number;
736
+ maxProxyRequests?: number;
737
+ requestsPerMinute?: number;
738
+ }
739
+ interface ServerCoordinator {
740
+ /** Acquire sorted, scoped keys exclusively for the lifetime of work. */
741
+ withLock<T>(scope: string, keys: readonly string[], signal: AbortSignal, work: () => Promise<T>): Promise<T>;
742
+ /** Optional shared admission for a principal on multiple replicas. */
743
+ admit?(scope: string, requestsPerMinute: number): Promise<boolean>;
744
+ }
745
+ interface ServerPersistenceFactory {
746
+ (scope: string): IPersistence | Promise<IPersistence>;
747
+ ready?(): boolean | Promise<boolean>;
662
748
  }
663
749
  interface ServerConfig {
664
750
  port?: number;
@@ -666,14 +752,48 @@ interface ServerConfig {
666
752
  skillsDir?: string;
667
753
  auth?: {
668
754
  apiKey?: string;
755
+ keys?: {
756
+ key: string;
757
+ scope: string;
758
+ permissions: ServerPermission[];
759
+ }[];
669
760
  jwtSecret?: string;
761
+ jwtIssuer?: string;
762
+ jwtAudience?: string;
763
+ jwtPermissions?: ServerPermission[];
670
764
  };
671
- llm?: {
672
- adapter: 'openai' | 'anthropic' | 'ollama';
673
- model: string;
674
- baseUrl?: string;
675
- apiKey?: string;
676
- headers?: Record<string, string>;
765
+ llm?: LLMAdapterConfig;
766
+ /** Routes available to remote clients. Unspecified permits all configured route families. */
767
+ routes?: ServerPermission[];
768
+ /** Browser origins allowed by CORS. Disabled by default. */
769
+ corsOrigins?: string[];
770
+ /** Skill defaults are opt-in. The allowlist also applies to programmatic skills and MCP tools. */
771
+ tools?: {
772
+ builtins?: string[];
773
+ allow?: string[];
774
+ requireApproval?: string[];
775
+ };
776
+ /** Separate durable storage for each authenticated scope. */
777
+ persistence?: ServerPersistenceFactory;
778
+ coordinator?: ServerCoordinator;
779
+ scopePolicy?: (scope: string) => ServerScopePolicy | undefined;
780
+ readiness?: () => boolean | Promise<boolean>;
781
+ shutdownGraceMs?: number;
782
+ context?: ContextConfig;
783
+ /** Server-side boundaries for API calls and model proxy requests. */
784
+ limits?: {
785
+ maxTurnsPerChat?: number;
786
+ maxActiveRuns?: number;
787
+ maxActiveProxyRequests?: number;
788
+ maxSessionsPerScope?: number;
789
+ maxScopes?: number;
790
+ maxRuntimeScopesIdleMs?: number;
791
+ maxJournalEntriesPerScope?: number;
792
+ maxNonStreamingResponseBytes?: number;
793
+ approvalTimeoutMs?: number;
794
+ requestTimeoutMs?: number;
795
+ proxyIdleTimeoutMs?: number;
796
+ allowedModels?: string[];
677
797
  };
678
798
  /** Code execution skill configuration */
679
799
  codeExecution?: CodeExecutionConfig;
@@ -714,6 +834,7 @@ declare const ACPErrorCodes: {
714
834
  readonly LLM_CALL_FAILED: -32130;
715
835
  readonly LLM_EMPTY_RESPONSE: -32135;
716
836
  readonly LLM_TOKEN_LIMIT: -32131;
837
+ readonly LLM_PROXY_CONFIG_INVALID: -32136;
717
838
  readonly LLM_RATE_LIMIT: -32132;
718
839
  readonly LLM_PROVIDER_UNAVAILABLE: -32133;
719
840
  readonly TOKEN_BUDGET_EXCEEDED: -32134;
@@ -753,11 +874,19 @@ declare class ACPError extends Error {
753
874
  * Works with OpenAI, OneAPI, FastGPT, Azure OpenAI, and any compatible proxy.
754
875
  */
755
876
  declare class OpenAIAdapter implements ILLMAdapter {
877
+ private options?;
756
878
  private config;
757
879
  private contentAdapter;
758
- constructor(config: LLMAdapterConfig);
880
+ private verified;
881
+ constructor(config: LLMAdapterConfig, options?: {
882
+ rejectRedirects?: boolean;
883
+ } | undefined);
759
884
  private getBaseUrl;
760
885
  private getEndpoint;
886
+ getConnectionStatus(): {
887
+ endpoint: string;
888
+ verified: boolean;
889
+ };
761
890
  private buildHeaders;
762
891
  private messagesToOpenAI;
763
892
  private toolsToOpenAI;
@@ -772,12 +901,19 @@ declare class OpenAIAdapter implements ILLMAdapter {
772
901
  chatStream(messages: Message[], tools: ToolDef[], options?: {
773
902
  signal?: AbortSignal;
774
903
  }): AsyncGenerator<StreamEvent>;
904
+ private parseToolCall;
905
+ private createRequest;
906
+ private fetchResponse;
907
+ private readChunk;
775
908
  /**
776
909
  * Check if the error response indicates context length exceeded.
777
910
  * Throws ACPError with CONTEXT_OVERFLOW code if detected.
778
911
  */
779
912
  private checkContextOverflow;
913
+ /** AbortError for the given signal — used so a cancelled stream surfaces an abort, not a parse error. */
914
+ private throwIfAborted;
780
915
  private parseResponse;
916
+ private parsePromptCacheUsage;
781
917
  }
782
918
 
783
919
  declare class SkillRegistry {
@@ -785,6 +921,8 @@ declare class SkillRegistry {
785
921
  register(skill: SkillDefinition): void;
786
922
  unregister(name: string): boolean;
787
923
  get(name: string): SkillDefinition | undefined;
924
+ /** Identity of this registration, replaced on every register call. */
925
+ getRegistrationIdentity(skill: SkillDefinition): object;
788
926
  getHandler(name: string): SkillHandler | undefined;
789
927
  list(): SkillDefinition[];
790
928
  listToolDefs(filter?: {
@@ -796,12 +934,17 @@ declare class SkillRegistry {
796
934
  }
797
935
 
798
936
  declare class SkillExecutor {
937
+ private options?;
799
938
  private registry;
800
939
  private worker;
801
- constructor(registry: SkillRegistry, worker?: SkillWorker);
940
+ private validators;
941
+ constructor(registry: SkillRegistry, worker?: SkillWorker, options?: {
942
+ validateInputs?: boolean;
943
+ } | undefined);
802
944
  getWorker(): SkillWorker;
803
945
  getRegistry(): SkillRegistry;
804
946
  execute(name: string, params: Record<string, any>, context: SkillContext): Promise<SkillResult>;
947
+ private getValidator;
805
948
  /**
806
949
  * Directly invoke a skill by name — used by ctx.invoke().
807
950
  * No LLM loop, no approval. Shares parent's signal and timeout context.
@@ -816,7 +959,9 @@ interface McpServerConnection {
816
959
  name: string;
817
960
  transport: 'stdio' | 'http';
818
961
  toolDefs: ToolDef[];
819
- call(toolName: string, args: Record<string, any>): Promise<any>;
962
+ call(toolName: string, args: Record<string, any>, options?: {
963
+ signal?: AbortSignal;
964
+ }): Promise<any>;
820
965
  disconnect(): Promise<void>;
821
966
  }
822
967
  /**
@@ -860,7 +1005,9 @@ declare class McpRouter {
860
1005
  /**
861
1006
  * Route a tool call to the appropriate MCP Server.
862
1007
  */
863
- call(prefixedName: string, args: Record<string, any>): Promise<any>;
1008
+ call(prefixedName: string, args: Record<string, any>, options?: {
1009
+ signal?: AbortSignal;
1010
+ }): Promise<any>;
864
1011
  /**
865
1012
  * Resolve `mcp:` prefixed tool names from a tools list to ToolDef[].
866
1013
  * Non-mcp names are silently skipped.
@@ -872,6 +1019,7 @@ declare class McpRouter {
872
1019
  isConnected(serverName: string): boolean;
873
1020
  }
874
1021
 
1022
+ type SessionMergeStrategy = 'full' | 'summary' | 'summary_and_artifacts';
875
1023
  declare class SessionManager {
876
1024
  private sessions;
877
1025
  create(options?: {
@@ -880,6 +1028,7 @@ declare class SessionManager {
880
1028
  systemPrompt?: string;
881
1029
  }): Session;
882
1030
  get(sessionId: string): Session | undefined;
1031
+ restore(session: Session): void;
883
1032
  getOrThrow(sessionId: string): Session;
884
1033
  list(options?: {
885
1034
  status?: string;
@@ -900,8 +1049,9 @@ declare class SessionManager {
900
1049
  addMessage(sessionId: string, message: Message): void;
901
1050
  delete(sessionId: string): boolean;
902
1051
  archive(sessionId: string): void;
903
- merge(fromId: string, toId: string, strategy?: 'full' | 'summary' | 'summary_and_artifacts'): void;
904
- private createSummary;
1052
+ merge(fromId: string, toId: string, strategy?: SessionMergeStrategy): void;
1053
+ static mergeContent(from: Session, to: Session, strategy?: SessionMergeStrategy): void;
1054
+ private static createSummary;
905
1055
  }
906
1056
 
907
1057
  /**
@@ -926,7 +1076,9 @@ interface CompressResult {
926
1076
  interface EnsureContextFitsResult {
927
1077
  messages: Message[];
928
1078
  wasCompressed: boolean;
1079
+ /** Estimated full input before compression, including the system prompt and tools. */
929
1080
  beforeTokens?: number;
1081
+ /** Estimated input of the request window built from the compressed messages. */
930
1082
  afterTokens?: number;
931
1083
  }
932
1084
  declare class ContextManager {
@@ -952,6 +1104,10 @@ declare class ContextManager {
952
1104
  * summarization (when a summarizer is set and enabled) over mechanical truncation.
953
1105
  */
954
1106
  ensureContextFits(messages: Message[], systemPrompt: string | undefined, tools: ToolDef[], model?: string, signal?: AbortSignal): Promise<EnsureContextFitsResult>;
1107
+ /** Build one smaller request after a provider rejects the current window. */
1108
+ compressForOverflow(messages: Message[], rejected: BuildWindowResult, systemPrompt: string, tools: ToolDef[], signal: AbortSignal): Promise<(CompressResult & {
1109
+ window: BuildWindowResult;
1110
+ }) | undefined>;
955
1111
  /**
956
1112
  * Compress context by summarizing older messages. When strategy is
957
1113
  * 'llm_summary' (or resolved via config) it uses the injected summarizer,
@@ -1049,12 +1205,16 @@ declare class HttpTransport implements ITransport {
1049
1205
  setSessionId(id: string): void;
1050
1206
  setAuthToken(token: string): void;
1051
1207
  private buildHeaders;
1052
- send(method: string, params: any): Promise<any>;
1208
+ send(method: string, params: any, options?: {
1209
+ signal?: AbortSignal;
1210
+ }): Promise<any>;
1053
1211
  notify(method: string, params: any): void;
1054
1212
  /**
1055
1213
  * Stream a chat request via SSE.
1056
1214
  */
1057
- streamChat(method: string, params: any): AsyncGenerator<{
1215
+ streamChat(method: string, params: any, options?: {
1216
+ signal?: AbortSignal;
1217
+ }): AsyncGenerator<{
1058
1218
  method: string;
1059
1219
  params: any;
1060
1220
  } | {
@@ -1070,6 +1230,8 @@ declare class Ldoing {
1070
1230
  private agentId;
1071
1231
  private initialized;
1072
1232
  private startTime;
1233
+ private mcpStatus;
1234
+ private discoveredServerSkills;
1073
1235
  protected llmAdapter: OpenAIAdapter;
1074
1236
  protected skillRegistry: SkillRegistry;
1075
1237
  protected skillExecutor: SkillExecutor;
@@ -1080,45 +1242,45 @@ declare class Ldoing {
1080
1242
  protected persistence: IPersistence;
1081
1243
  private currentSessionId;
1082
1244
  private abortControllers;
1245
+ private runContexts;
1083
1246
  private runningSessions;
1084
1247
  private approvalResolvers;
1248
+ private sessionStorageQueues;
1249
+ private managingSessions;
1250
+ private compressingSessions;
1085
1251
  private eventHandlers;
1086
1252
  private tokenCalibrationRatio;
1087
1253
  constructor(config: LdoingConfig);
1088
1254
  init(): Promise<InitResult>;
1089
1255
  destroy(): Promise<void>;
1090
1256
  getStatus(): {
1091
- agentId: string;
1092
- mode: string;
1093
- uptime: number;
1094
- activeSessions: number;
1095
- loadedSkills: number;
1096
1257
  llm: {
1097
1258
  adapter: "custom" | "openai" | "anthropic" | "ollama";
1098
1259
  model: string;
1099
1260
  connected: boolean;
1100
1261
  };
1262
+ mcpStatus: McpConnectionStatus;
1263
+ llmRoute?: LLMRouteStatus;
1264
+ agentId: string;
1265
+ mode: string;
1266
+ uptime: number;
1267
+ activeSessions: number;
1268
+ loadedSkills: number;
1101
1269
  };
1270
+ private getConnectionDetails;
1102
1271
  chat(message: string | ContentBlock[], options?: ChatOptions): Promise<ChatResult>;
1103
1272
  chatStream(message: string | ContentBlock[], options?: ChatOptions): AsyncGenerator<StreamEvent>;
1104
1273
  abort(sessionId?: string): Promise<void>;
1105
1274
  /**
1106
1275
  * 在启动新的 agent loop 前获取会话锁。
1107
1276
  * 根据并发策略处理正在运行的旧请求:
1108
- * - 'abort' (默认): 中止旧请求,等待其真正退出,清理半截消息,然后返回
1277
+ * - 'abort' (默认): 中止旧请求,等待其真正退出,发送前修复未配对消息,然后返回
1109
1278
  * - 'reject': 若已有运行请求,抛错
1110
1279
  * - 'queue': 预留,当前回退到 'abort'
1111
1280
  *
1112
1281
  * 返回一个 release 函数,agent loop 结束时必须调用以释放锁。
1113
1282
  */
1114
1283
  private acquireSessionLock;
1115
- /**
1116
- * 清理被 abort 打断的半截消息:
1117
- * 如果 session.messages 最后一条是 assistant 且带 tool_calls,
1118
- * 但后面没有对应的 tool 消息,则删除这条 assistant。
1119
- * 避免下次 LLM 调用因 tool_calls 未配对而报错。
1120
- */
1121
- private cleanupInterruptedMessages;
1122
1284
  approveTool(callId: string, approved: boolean, _reason?: string): void;
1123
1285
  private waitForApproval;
1124
1286
  registerSkill(skill: SkillDefinition): void;
@@ -1152,6 +1314,7 @@ declare class Ldoing {
1152
1314
  title?: string;
1153
1315
  meta?: Record<string, any>;
1154
1316
  systemPrompt?: string;
1317
+ activate?: boolean;
1155
1318
  }): Session;
1156
1319
  getSession(sessionId: string): Session | undefined;
1157
1320
  listSessions(options?: {
@@ -1172,7 +1335,22 @@ declare class Ldoing {
1172
1335
  }[];
1173
1336
  mergeSessions(fromId: string, toId: string, strategy?: 'full' | 'summary' | 'summary_and_artifacts'): void;
1174
1337
  deleteSession(sessionId: string): void;
1338
+ private removeLiveSession;
1175
1339
  archiveSession(sessionId: string): void;
1340
+ /** List committed history without loading it into the Agent. */
1341
+ listStoredSessions(options?: Parameters<IPersistence['listSessions']>[0]): Promise<Session[]>;
1342
+ /** Load one stored session on demand. A live session takes precedence. */
1343
+ restoreSession(sessionId: string, options?: {
1344
+ activate?: boolean;
1345
+ }): Promise<Session | null>;
1346
+ /** Archive a stored or live session, publishing the update after commit. */
1347
+ archiveStoredSession(sessionId: string): Promise<void>;
1348
+ /** Commit an idle session, then release its live copy. Restore it by ID when needed. */
1349
+ unloadSession(sessionId: string): Promise<boolean>;
1350
+ /** Merge history into the target session and commit the target. */
1351
+ mergeStoredSessions(fromId: string, toId: string, strategy?: SessionMergeStrategy): Promise<void>;
1352
+ /** Delete committed and live history, including when a chat save is pending. */
1353
+ deleteStoredSession(sessionId: string): Promise<void>;
1176
1354
  getContext(sessionId: string, format?: 'messages' | 'summary' | 'window'): Message[] | string;
1177
1355
  searchContext(query: string, options?: {
1178
1356
  limit?: number;
@@ -1188,13 +1366,14 @@ declare class Ldoing {
1188
1366
  afterTokens: number;
1189
1367
  compressionRatio: number;
1190
1368
  }>;
1369
+ private prepareOverflowRetry;
1191
1370
  configure(config: Partial<LdoingConfig>): void;
1371
+ private configureProxy;
1192
1372
  on(event: string, handler: EventHandler): void;
1193
1373
  off(event: string, handler: EventHandler): void;
1194
1374
  private emit;
1195
1375
  /**
1196
- * Stream LLM response token-by-token via the adapter's chatStream.
1197
- * Forwards llm_text events to the caller and collects the full StandardLLMResponse.
1376
+ * Forward streaming events, or emit the complete response for a non-streaming adapter.
1198
1377
  */
1199
1378
  private streamLlmResponse;
1200
1379
  /**
@@ -1218,12 +1397,26 @@ declare class Ldoing {
1218
1397
  private planToolExecution;
1219
1398
  private processApprovalQueue;
1220
1399
  private executeToolBatch;
1400
+ private streamToolBatch;
1221
1401
  private executeToolBatchStream;
1222
1402
  /**
1223
1403
  * Execute a tool call, routing mcp: prefixed tools to McpRouter.
1224
1404
  */
1225
1405
  private executeToolCall;
1406
+ private prepareRunContext;
1407
+ private buildRunSystemPrompt;
1408
+ private listRunTools;
1409
+ private beginExecution;
1410
+ private ensureSessionIsNotBeingManaged;
1411
+ private manageSessionStorage;
1412
+ private readSessionForStorage;
1413
+ private requireSessionForStorage;
1414
+ private commitStoredSession;
1415
+ private snapshotSession;
1416
+ private queueSessionStorage;
1417
+ private saveSessionSafely;
1226
1418
  private ensureInitialized;
1419
+ private reportPromptCacheUsage;
1227
1420
  private ensureSession;
1228
1421
  /** Resolve system prompt — can be overridden by subclasses to inject context */
1229
1422
  protected resolveSystemPrompt(sessionId: string, base: string): string;
@@ -1318,7 +1511,7 @@ declare class MemoryPersistence implements IPersistence {
1318
1511
  declare class TaskPlanner {
1319
1512
  private llmAdapter;
1320
1513
  constructor(llmAdapter: ILLMAdapter);
1321
- plan(goal: string, availableTools: ToolDef[]): Promise<TaskPlan>;
1514
+ plan(goal: string, availableTools: ToolDef[], signal?: AbortSignal): Promise<TaskPlan>;
1322
1515
  private buildPlanningPrompt;
1323
1516
  private parsePlan;
1324
1517
  private extractSteps;
@@ -1395,7 +1588,7 @@ declare class TaskGraph {
1395
1588
  declare class GraphPlanner {
1396
1589
  protected llmAdapter: ILLMAdapter;
1397
1590
  constructor(llmAdapter: ILLMAdapter);
1398
- planGraph(goal: string, availableTools: ToolDef[]): Promise<GraphPlan>;
1591
+ planGraph(goal: string, availableTools: ToolDef[], signal?: AbortSignal): Promise<GraphPlan>;
1399
1592
  private buildGraphPlanningPrompt;
1400
1593
  private parseGraphPlan;
1401
1594
  private extractGraphNodes;
@@ -1419,14 +1612,18 @@ declare class GraphExecutor {
1419
1612
  private abortController;
1420
1613
  private toolFailureCount;
1421
1614
  private emit;
1615
+ private unlinkParent;
1616
+ private onNodeSettled?;
1422
1617
  constructor(options: {
1423
1618
  graph: TaskGraph;
1424
1619
  parentAgent: Ldoing;
1620
+ parentSignal?: AbortSignal;
1425
1621
  plan: GraphPlan;
1426
1622
  maxConcurrency?: number;
1427
1623
  maxDepth?: number;
1428
1624
  baseDepth?: number;
1429
1625
  emit: Emitter;
1626
+ onNodeSettled?: (nodeId: string) => Promise<void>;
1430
1627
  });
1431
1628
  /** Execute the entire graph, level by level */
1432
1629
  execute(): Promise<GraphPlan>;
@@ -1464,6 +1661,7 @@ declare class SubAgent {
1464
1661
  private parentAgent;
1465
1662
  private sessionId;
1466
1663
  private abortController;
1664
+ private unlinkParent;
1467
1665
  private status;
1468
1666
  constructor(options: {
1469
1667
  nodeId: string;
@@ -1505,4 +1703,4 @@ declare class OpenAIContentAdapter implements IContentAdapter {
1505
1703
  formatMessageContent(content: string | ContentBlock[]): string | any[];
1506
1704
  }
1507
1705
 
1508
- 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 };
1706
+ export { ACPError, ACPErrorCodes, type BuildWindowResult, type ChatOptions, type ChatResult, type ChatRunContext, 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, type LLMProxyMode, type LLMRouteStatus, Ldoing, type LdoingConfig, type LimitsConfig, type LoadedSkill, LocalTransport, type McpConnectionStatus, McpRouter, type McpServerConnection, MemoryPersistence, type Message, type ModelCapabilities, type NodeResult, type NodeStatus, OpenAIAdapter, OpenAIContentAdapter, PERMISSION_MODE_DEFAULTS, type PermissionMode, type PermissionPolicy, PlanTracker, type PromptCacheUsage, type RetryPolicy, SENSITIVE_PERMISSIONS, type ServerConfig, type ServerCoordinator, type ServerPermission, type ServerPersistenceFactory, type ServerScopePolicy, 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 };