@opencow-ai/opencow-agent-sdk 0.4.18 → 0.4.20

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.
@@ -1,13 +1,20 @@
1
- export declare function registerBackgroundAgentAbort(agentId: string, controller: AbortController): void;
1
+ type BackgroundAgentStopActions = {
2
+ abort: () => void;
3
+ stopShells: () => void;
4
+ };
5
+ export declare function registerBackgroundAgentAbort(agentId: string, actions: BackgroundAgentStopActions): void;
2
6
  export declare function unregisterBackgroundAgentAbort(agentId: string): void;
3
7
  /**
4
- * Abort a background sub-agent by id. Returns true if a live controller was
5
- * found and signalled, false if the agent is unknown / already settled.
6
- * The entry stays registered until the run's finally unregisters it the
7
- * run is still draining at this point and its terminal delivery (and any
8
- * late natural-stop marking) still needs the per-run state.
8
+ * Stop a background sub-agent by id and wait for its runAgent finalizer.
9
+ *
10
+ * The first caller synchronously aborts the run and stops its owned shells.
11
+ * Later callers share the same Promise. The Promise resolves only when
12
+ * runAgent unregisters after MCP cleanup and all remaining finalizers.
13
+ * Unknown or already-settled agents are an idempotent completed stop.
9
14
  */
10
- export declare function abortBackgroundAgentById(agentId: string): boolean;
15
+ export declare function abortBackgroundAgentById(agentId: string): Promise<void>;
16
+ export declare function hasBackgroundAgent(agentId: string): boolean;
17
+ export declare function stopBackgroundAgentShellsById(agentId: string): void;
11
18
  /**
12
19
  * Record that the natural-stop path delivered SubagentStop for this run.
13
20
  * No-op when the run is gone (e.g. the fallback delivery in runAgent's
@@ -21,3 +28,4 @@ export declare function markSubagentStopFired(agentId: string): void;
21
28
  * is still needed. Purely a read — the per-run state dies with the entry.
22
29
  */
23
30
  export declare function hasSubagentStopFired(agentId: string): boolean;
31
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { SetAppState } from '../tasks/Task.js';
2
+ type OwnedBackgroundTask = {
3
+ stop: () => Promise<void>;
4
+ settled: Promise<void>;
5
+ };
6
+ /**
7
+ * Query/Session 维度的后台任务所有权。
8
+ *
9
+ * stop() 会先触发每个任务的 stop,再等待任务自身 settled;重复调用共享
10
+ * 同一个 Promise。任务自然结束时会从 scope 自动注销。
11
+ */
12
+ export declare class BackgroundTaskScope {
13
+ private readonly tasks;
14
+ private stopPromise;
15
+ private stopped;
16
+ register(task: OwnedBackgroundTask): () => void;
17
+ stop(): Promise<void>;
18
+ private drain;
19
+ private stopTask;
20
+ }
21
+ /**
22
+ * 用每个 SDK Query 独有的 setAppState 函数作为窄 owner key。
23
+ *
24
+ * 这只负责把深层 shell spawn 路由到已有 scope,不保存 QueryContext,
25
+ * 也不创建第二套 AsyncLocalStorage。
26
+ */
27
+ export declare function bindBackgroundTaskScope(setAppState: SetAppState, scope: BackgroundTaskScope): () => void;
28
+ export declare function getBackgroundTaskScope(setAppState: SetAppState): BackgroundTaskScope | undefined;
29
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencow-ai/opencow-agent-sdk",
3
- "version": "0.4.18",
3
+ "version": "0.4.20",
4
4
  "description": "Claude Code opened to any LLM — OpenAI, Gemini, DeepSeek, Ollama, and 200+ models",
5
5
  "type": "module",
6
6
  "main": "./dist/sdk.js",