pilotswarm-sdk 0.5.63 → 0.5.65
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/api/src/admin-diagnostics.d.ts +12 -0
- package/api/src/admin-diagnostics.js +38 -1
- package/api/src/http-api-transport.js +26 -0
- package/api/src/protocol.js +15 -0
- package/dist/activity-routing.d.ts +21 -0
- package/dist/activity-routing.d.ts.map +1 -0
- package/dist/activity-routing.js +32 -0
- package/dist/activity-routing.js.map +1 -0
- package/dist/agent-discovery.d.ts +35 -0
- package/dist/agent-discovery.d.ts.map +1 -0
- package/dist/agent-discovery.js +107 -0
- package/dist/agent-discovery.js.map +1 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +94 -12
- package/dist/client.js.map +1 -1
- package/dist/cms-migrations.d.ts.map +1 -1
- package/dist/cms-migrations.js +4 -0
- package/dist/cms-migrations.js.map +1 -1
- package/dist/cms.d.ts +3 -0
- package/dist/cms.d.ts.map +1 -1
- package/dist/cms.js +7 -0
- package/dist/cms.js.map +1 -1
- package/dist/feature-flag-cache.d.ts +40 -0
- package/dist/feature-flag-cache.d.ts.map +1 -0
- package/dist/feature-flag-cache.js +125 -0
- package/dist/feature-flag-cache.js.map +1 -0
- package/dist/feature-flags.d.ts +68 -0
- package/dist/feature-flags.d.ts.map +1 -0
- package/dist/feature-flags.js +45 -0
- package/dist/feature-flags.js.map +1 -0
- package/dist/feature-store.d.ts +55 -0
- package/dist/feature-store.d.ts.map +1 -0
- package/dist/feature-store.js +106 -0
- package/dist/feature-store.js.map +1 -0
- package/dist/feature-tools.d.ts +94 -0
- package/dist/feature-tools.d.ts.map +1 -0
- package/dist/feature-tools.js +60 -0
- package/dist/feature-tools.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/managed-session.d.ts +4 -0
- package/dist/managed-session.d.ts.map +1 -1
- package/dist/managed-session.js +120 -23
- package/dist/managed-session.js.map +1 -1
- package/dist/management-client.d.ts +18 -0
- package/dist/management-client.d.ts.map +1 -1
- package/dist/management-client.js +19 -0
- package/dist/management-client.js.map +1 -1
- package/dist/migrations/feature-flags-0077.d.ts +3 -0
- package/dist/migrations/feature-flags-0077.d.ts.map +1 -0
- package/dist/migrations/feature-flags-0077.js +271 -0
- package/dist/migrations/feature-flags-0077.js.map +1 -0
- package/dist/migrations/native-tasks-default-policy-0078.d.ts +3 -0
- package/dist/migrations/native-tasks-default-policy-0078.d.ts.map +1 -0
- package/dist/migrations/native-tasks-default-policy-0078.js +21 -0
- package/dist/migrations/native-tasks-default-policy-0078.js.map +1 -0
- package/dist/native-subagents.d.ts +25 -0
- package/dist/native-subagents.d.ts.map +1 -0
- package/dist/native-subagents.js +191 -0
- package/dist/native-subagents.js.map +1 -0
- package/dist/native-task-observer.d.ts +87 -0
- package/dist/native-task-observer.d.ts.map +1 -0
- package/dist/native-task-observer.js +268 -0
- package/dist/native-task-observer.js.map +1 -0
- package/dist/orchestration/agents.d.ts +8 -3
- package/dist/orchestration/agents.d.ts.map +1 -1
- package/dist/orchestration/agents.js +87 -36
- package/dist/orchestration/agents.js.map +1 -1
- package/dist/orchestration/index.d.ts +2 -2
- package/dist/orchestration/index.js +1 -1
- package/dist/orchestration/lifecycle.js +1 -1
- package/dist/orchestration/lifecycle.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +1 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +18 -4
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/turn.d.ts.map +1 -1
- package/dist/orchestration/turn.js +3 -5
- package/dist/orchestration/turn.js.map +1 -1
- package/dist/orchestration-registry.d.ts.map +1 -1
- package/dist/orchestration-registry.js +12 -2
- package/dist/orchestration-registry.js.map +1 -1
- package/dist/orchestration-version.d.ts +1 -1
- package/dist/orchestration-version.js +1 -1
- package/dist/orchestration.d.ts +2 -2
- package/dist/orchestration.js +1 -1
- package/dist/orchestration_1_0_46.d.ts +1 -1
- package/dist/orchestration_1_0_47.d.ts +1 -1
- package/dist/orchestration_1_0_48.d.ts +1 -1
- package/dist/orchestration_1_0_49.d.ts +1 -1
- package/dist/orchestration_1_0_50.d.ts +1 -1
- package/dist/orchestration_1_0_73/agents.d.ts +61 -0
- package/dist/orchestration_1_0_73/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/agents.js +843 -0
- package/dist/orchestration_1_0_73/agents.js.map +1 -0
- package/dist/orchestration_1_0_73/index.d.ts +24 -0
- package/dist/orchestration_1_0_73/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/index.js +13 -0
- package/dist/orchestration_1_0_73/index.js.map +1 -0
- package/dist/orchestration_1_0_73/lifecycle.d.ts +51 -0
- package/dist/orchestration_1_0_73/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/lifecycle.js +981 -0
- package/dist/orchestration_1_0_73/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_73/queue.d.ts +20 -0
- package/dist/orchestration_1_0_73/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/queue.js +894 -0
- package/dist/orchestration_1_0_73/queue.js.map +1 -0
- package/dist/orchestration_1_0_73/runtime.d.ts +31 -0
- package/dist/orchestration_1_0_73/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/runtime.js +230 -0
- package/dist/orchestration_1_0_73/runtime.js.map +1 -0
- package/dist/orchestration_1_0_73/state.d.ts +214 -0
- package/dist/orchestration_1_0_73/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/state.js +178 -0
- package/dist/orchestration_1_0_73/state.js.map +1 -0
- package/dist/orchestration_1_0_73/turn.d.ts +34 -0
- package/dist/orchestration_1_0_73/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/turn.js +1435 -0
- package/dist/orchestration_1_0_73/turn.js.map +1 -0
- package/dist/orchestration_1_0_73/utils.d.ts +39 -0
- package/dist/orchestration_1_0_73/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_73/utils.js +322 -0
- package/dist/orchestration_1_0_73/utils.js.map +1 -0
- package/dist/orchestration_1_0_74/agents.d.ts +61 -0
- package/dist/orchestration_1_0_74/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/agents.js +889 -0
- package/dist/orchestration_1_0_74/agents.js.map +1 -0
- package/dist/orchestration_1_0_74/index.d.ts +24 -0
- package/dist/orchestration_1_0_74/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/index.js +13 -0
- package/dist/orchestration_1_0_74/index.js.map +1 -0
- package/dist/orchestration_1_0_74/lifecycle.d.ts +51 -0
- package/dist/orchestration_1_0_74/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/lifecycle.js +981 -0
- package/dist/orchestration_1_0_74/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_74/queue.d.ts +20 -0
- package/dist/orchestration_1_0_74/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/queue.js +894 -0
- package/dist/orchestration_1_0_74/queue.js.map +1 -0
- package/dist/orchestration_1_0_74/runtime.d.ts +31 -0
- package/dist/orchestration_1_0_74/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/runtime.js +232 -0
- package/dist/orchestration_1_0_74/runtime.js.map +1 -0
- package/dist/orchestration_1_0_74/state.d.ts +214 -0
- package/dist/orchestration_1_0_74/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/state.js +178 -0
- package/dist/orchestration_1_0_74/state.js.map +1 -0
- package/dist/orchestration_1_0_74/turn.d.ts +34 -0
- package/dist/orchestration_1_0_74/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/turn.js +1435 -0
- package/dist/orchestration_1_0_74/turn.js.map +1 -0
- package/dist/orchestration_1_0_74/utils.d.ts +39 -0
- package/dist/orchestration_1_0_74/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_74/utils.js +322 -0
- package/dist/orchestration_1_0_74/utils.js.map +1 -0
- package/dist/orchestration_1_0_75/agents.d.ts +61 -0
- package/dist/orchestration_1_0_75/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/agents.js +887 -0
- package/dist/orchestration_1_0_75/agents.js.map +1 -0
- package/dist/orchestration_1_0_75/index.d.ts +24 -0
- package/dist/orchestration_1_0_75/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/index.js +13 -0
- package/dist/orchestration_1_0_75/index.js.map +1 -0
- package/dist/orchestration_1_0_75/lifecycle.d.ts +51 -0
- package/dist/orchestration_1_0_75/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/lifecycle.js +981 -0
- package/dist/orchestration_1_0_75/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_75/queue.d.ts +20 -0
- package/dist/orchestration_1_0_75/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/queue.js +894 -0
- package/dist/orchestration_1_0_75/queue.js.map +1 -0
- package/dist/orchestration_1_0_75/runtime.d.ts +31 -0
- package/dist/orchestration_1_0_75/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/runtime.js +239 -0
- package/dist/orchestration_1_0_75/runtime.js.map +1 -0
- package/dist/orchestration_1_0_75/state.d.ts +214 -0
- package/dist/orchestration_1_0_75/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/state.js +178 -0
- package/dist/orchestration_1_0_75/state.js.map +1 -0
- package/dist/orchestration_1_0_75/turn.d.ts +34 -0
- package/dist/orchestration_1_0_75/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/turn.js +1435 -0
- package/dist/orchestration_1_0_75/turn.js.map +1 -0
- package/dist/orchestration_1_0_75/utils.d.ts +39 -0
- package/dist/orchestration_1_0_75/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_75/utils.js +322 -0
- package/dist/orchestration_1_0_75/utils.js.map +1 -0
- package/dist/orchestration_1_0_76/agents.d.ts +61 -0
- package/dist/orchestration_1_0_76/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/agents.js +865 -0
- package/dist/orchestration_1_0_76/agents.js.map +1 -0
- package/dist/orchestration_1_0_76/index.d.ts +24 -0
- package/dist/orchestration_1_0_76/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/index.js +13 -0
- package/dist/orchestration_1_0_76/index.js.map +1 -0
- package/dist/orchestration_1_0_76/lifecycle.d.ts +51 -0
- package/dist/orchestration_1_0_76/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/lifecycle.js +981 -0
- package/dist/orchestration_1_0_76/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_76/queue.d.ts +20 -0
- package/dist/orchestration_1_0_76/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/queue.js +894 -0
- package/dist/orchestration_1_0_76/queue.js.map +1 -0
- package/dist/orchestration_1_0_76/runtime.d.ts +31 -0
- package/dist/orchestration_1_0_76/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/runtime.js +239 -0
- package/dist/orchestration_1_0_76/runtime.js.map +1 -0
- package/dist/orchestration_1_0_76/state.d.ts +214 -0
- package/dist/orchestration_1_0_76/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/state.js +178 -0
- package/dist/orchestration_1_0_76/state.js.map +1 -0
- package/dist/orchestration_1_0_76/turn.d.ts +34 -0
- package/dist/orchestration_1_0_76/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/turn.js +1435 -0
- package/dist/orchestration_1_0_76/turn.js.map +1 -0
- package/dist/orchestration_1_0_76/utils.d.ts +39 -0
- package/dist/orchestration_1_0_76/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_76/utils.js +322 -0
- package/dist/orchestration_1_0_76/utils.js.map +1 -0
- package/dist/orchestration_1_0_77/agents.d.ts +66 -0
- package/dist/orchestration_1_0_77/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/agents.js +895 -0
- package/dist/orchestration_1_0_77/agents.js.map +1 -0
- package/dist/orchestration_1_0_77/index.d.ts +24 -0
- package/dist/orchestration_1_0_77/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/index.js +13 -0
- package/dist/orchestration_1_0_77/index.js.map +1 -0
- package/dist/orchestration_1_0_77/lifecycle.d.ts +51 -0
- package/dist/orchestration_1_0_77/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/lifecycle.js +981 -0
- package/dist/orchestration_1_0_77/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_77/queue.d.ts +20 -0
- package/dist/orchestration_1_0_77/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/queue.js +894 -0
- package/dist/orchestration_1_0_77/queue.js.map +1 -0
- package/dist/orchestration_1_0_77/runtime.d.ts +31 -0
- package/dist/orchestration_1_0_77/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/runtime.js +239 -0
- package/dist/orchestration_1_0_77/runtime.js.map +1 -0
- package/dist/orchestration_1_0_77/state.d.ts +214 -0
- package/dist/orchestration_1_0_77/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/state.js +178 -0
- package/dist/orchestration_1_0_77/state.js.map +1 -0
- package/dist/orchestration_1_0_77/turn.d.ts +34 -0
- package/dist/orchestration_1_0_77/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/turn.js +1433 -0
- package/dist/orchestration_1_0_77/turn.js.map +1 -0
- package/dist/orchestration_1_0_77/utils.d.ts +39 -0
- package/dist/orchestration_1_0_77/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_77/utils.js +322 -0
- package/dist/orchestration_1_0_77/utils.js.map +1 -0
- package/dist/reserved-tool-names.d.ts +5 -0
- package/dist/reserved-tool-names.d.ts.map +1 -0
- package/dist/reserved-tool-names.js +102 -0
- package/dist/reserved-tool-names.js.map +1 -0
- package/dist/session-manager.d.ts +31 -1
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +343 -102
- package/dist/session-manager.js.map +1 -1
- package/dist/session-proxy.d.ts +28 -3
- package/dist/session-proxy.d.ts.map +1 -1
- package/dist/session-proxy.js +192 -71
- package/dist/session-proxy.js.map +1 -1
- package/dist/session-store.d.ts +2 -0
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +18 -2
- package/dist/session-store.js.map +1 -1
- package/dist/types.d.ts +25 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/web/generated-op-methods.d.ts +96 -0
- package/dist/web/generated-op-methods.d.ts.map +1 -1
- package/dist/web/generated-op-methods.js +24 -0
- package/dist/web/generated-op-methods.js.map +1 -1
- package/dist/web/web-management-client.d.ts +13 -0
- package/dist/web/web-management-client.d.ts.map +1 -1
- package/dist/web/web-management-client.js +12 -0
- package/dist/web/web-management-client.js.map +1 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +150 -110
- package/dist/worker.js.map +1 -1
- package/package.json +4 -3
- package/plugins/mgmt/agents/pilotswarm.agent.md +18 -1
- package/plugins/mgmt/agents/resourcemgr.agent.md +18 -1
- package/plugins/system/agents/default.agent.md +16 -7
package/dist/managed-session.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNativeChildEvent, settleNativeSubagents, guardNativeExternalTools } from "./native-subagents.js";
|
|
1
2
|
import { defineTool } from "@github/copilot-sdk";
|
|
2
3
|
import { normalizeCanvasResponseContract as normalizeCanvasContractShared } from "./canvas-app-manifest.js";
|
|
3
4
|
// One list gates BOTH halves of every manager tool: the declaration in the
|
|
@@ -7,6 +8,7 @@ import { holdsManagerBundle } from "./agent-manager-tools.js";
|
|
|
7
8
|
// the declarations in systemToolDefs() and the handlers in runTurn().
|
|
8
9
|
import { holdsProviderTools, providerToolDefs, providerToolsUnavailable } from "./provider-tools.js";
|
|
9
10
|
import { LiveTurnCoalescer } from "./live-turn.js";
|
|
11
|
+
import { NativeTaskObserver } from "./native-task-observer.js";
|
|
10
12
|
const DEFAULT_WAIT_TOOL_DESCRIPTION = "The ONLY way to wait, pause, delay, or pause-before-retry inside a turn: a durable timer that survives " +
|
|
11
13
|
"restarts and may resume on a different worker (set preserveWorkerAffinity=true for node-local work). " +
|
|
12
14
|
"NEVER use bash sleep, setTimeout, setInterval, or any other external timing mechanism. " +
|
|
@@ -615,6 +617,16 @@ export class ManagedSession {
|
|
|
615
617
|
}
|
|
616
618
|
/** Set for the duration of runTurn(); read by the lock-bypassing stop path. */
|
|
617
619
|
activeTurn = null;
|
|
620
|
+
nativeFeatureRevoked = false;
|
|
621
|
+
canAdmitNativeTask() {
|
|
622
|
+
return this.config.nativeSubagents === "sync" && !this.nativeFeatureRevoked
|
|
623
|
+
&& (this.config.nativeFeatureAllowed?.() ?? false);
|
|
624
|
+
}
|
|
625
|
+
/** A cached OFF is sticky for this turn, even if the next poll is ON. */
|
|
626
|
+
refreshNativeFeaturePolicy() {
|
|
627
|
+
if (this.activeTurn && !this.canAdmitNativeTask())
|
|
628
|
+
this.nativeFeatureRevoked = true;
|
|
629
|
+
}
|
|
618
630
|
/** Set only by requestStop(); classifies the turn unwind as "stopped". */
|
|
619
631
|
stopRequest = null;
|
|
620
632
|
/** Resolver for the current turn's completion promise — hang escalation hook. */
|
|
@@ -910,11 +922,12 @@ export class ManagedSession {
|
|
|
910
922
|
"If the user explicitly asks you to use sub-agents, delegation, fan-out, or parallel processing, you should comply within runtime limits instead of collapsing the work into a direct answer. " +
|
|
911
923
|
"If the user did not explicitly ask for delegation, use your judgment about whether parallel work is actually helpful. " +
|
|
912
924
|
"Each agent adds cost, so avoid unnecessary fan-out when delegation was not requested. " +
|
|
913
|
-
"For KNOWN user-creatable agents, pass agent_name. The agent's
|
|
925
|
+
"For KNOWN user-creatable agents, pass agent_name. The agent's instructions, tools, and startup requirement load automatically; task supplies your assignment. " +
|
|
926
|
+
"Before choosing a custom child, check the available static and published agent definitions with ps_list_agents unless the current catalog already identifies a suitable specialist. Select by role, source access, and capabilities, then pass the exact agent_name from the list and task for the assignment. Prefer a suitable named specialist over recreating it as a generic child. " +
|
|
914
927
|
"You MAY spawn multiple concurrent instances of the same agent_name (e.g. one per bug or per shard); they each get their own conversation. The only caps are the global maximum concurrent sub-agents and the maximum nesting depth. " +
|
|
915
928
|
"Sub-agents do NOT auto-terminate when they finish their task \u2014 they stay alive idle, ready for follow-up via message_agent. YOU are responsible for closing each child with complete_agent (graceful), cancel_agent (interrupt), or delete_agent (forceful) when you no longer need it. " +
|
|
916
929
|
"Worker-managed system agents are NOT valid spawn_agent targets; if one is missing, the workers likely need to be restarted. " +
|
|
917
|
-
"For CUSTOM agents (ad-hoc tasks), pass task instead. " +
|
|
930
|
+
"For CUSTOM agents (ad-hoc tasks), pass task instead. Do not attach package-owned names through tool_names; select their named agent through ps_list_agents so its instructions, tools, and startup requirement stay together. " +
|
|
918
931
|
"Call ps_list_agents to see all available named agents you CAN spawn. " +
|
|
919
932
|
"By default, sub-agents inherit the parent's model. " +
|
|
920
933
|
"If you want to override the model, call list_available_models first and use only an exact provider:model value returned there. " +
|
|
@@ -925,11 +938,11 @@ export class ManagedSession {
|
|
|
925
938
|
properties: {
|
|
926
939
|
agent_name: {
|
|
927
940
|
type: "string",
|
|
928
|
-
description: "Name of a known user-creatable agent to spawn (from ps_list_agents). The agent's
|
|
941
|
+
description: "Name of a known user-creatable agent to spawn (from ps_list_agents). The agent's instructions, tools, and startup requirement are loaded automatically. Optionally pass task for a specific assignment; otherwise its initial prompt is used. Do not override system_message or tool_names. Worker-managed system agents are not valid here.",
|
|
929
942
|
},
|
|
930
943
|
task: {
|
|
931
944
|
type: "string",
|
|
932
|
-
description: "
|
|
945
|
+
description: "The assignment for the child, whether named or custom. This becomes its first prompt while a named agent retains its instructions, tools, and startup requirement. Required for custom agents; optional for named agents, whose initial prompt is the default.",
|
|
933
946
|
},
|
|
934
947
|
model: {
|
|
935
948
|
type: "string",
|
|
@@ -1124,9 +1137,29 @@ export class ManagedSession {
|
|
|
1124
1137
|
* misclassified as a retryable error.
|
|
1125
1138
|
*/
|
|
1126
1139
|
async runTurn(prompt, opts) {
|
|
1140
|
+
this.nativeFeatureRevoked = false;
|
|
1127
1141
|
this.activeTurn = { turnIndex: opts?.turnIndex ?? -1, startedAt: Date.now() };
|
|
1142
|
+
let result;
|
|
1143
|
+
let turnError;
|
|
1144
|
+
let failed = false;
|
|
1128
1145
|
try {
|
|
1129
|
-
|
|
1146
|
+
try {
|
|
1147
|
+
// Also retire native tasks restored from an interrupted worker.
|
|
1148
|
+
if (this.config.nativeSubagents === "sync")
|
|
1149
|
+
await settleNativeSubagents(this.copilotSession);
|
|
1150
|
+
result = await this._runTurnInner(prompt, opts);
|
|
1151
|
+
}
|
|
1152
|
+
catch (err) {
|
|
1153
|
+
failed = true;
|
|
1154
|
+
turnError = err;
|
|
1155
|
+
}
|
|
1156
|
+
// Cleanup failures must escape stop/error classification: the
|
|
1157
|
+
// activity cannot commit a snapshot with native work still live.
|
|
1158
|
+
if (this.config.nativeSubagents === "sync")
|
|
1159
|
+
await settleNativeSubagents(this.copilotSession, {
|
|
1160
|
+
rejectRunning: result?.type === "completed" && !this.stopRequest,
|
|
1161
|
+
});
|
|
1162
|
+
// A stop can arrive DURING cleanup. Classify only after it settles.
|
|
1130
1163
|
if (this.stopRequest) {
|
|
1131
1164
|
return {
|
|
1132
1165
|
type: "stopped",
|
|
@@ -1134,14 +1167,10 @@ export class ManagedSession {
|
|
|
1134
1167
|
...(result?.events ? { events: result.events } : {}),
|
|
1135
1168
|
};
|
|
1136
1169
|
}
|
|
1170
|
+
if (failed)
|
|
1171
|
+
throw turnError;
|
|
1137
1172
|
return result;
|
|
1138
1173
|
}
|
|
1139
|
-
catch (err) {
|
|
1140
|
-
if (this.stopRequest) {
|
|
1141
|
-
return { type: "stopped", reason: this.stopRequest.reason };
|
|
1142
|
-
}
|
|
1143
|
-
throw err;
|
|
1144
|
-
}
|
|
1145
1174
|
finally {
|
|
1146
1175
|
this.activeTurn = null;
|
|
1147
1176
|
this.stopRequest = null;
|
|
@@ -1989,14 +2018,15 @@ export class ManagedSession {
|
|
|
1989
2018
|
});
|
|
1990
2019
|
// Build sub-agent tools
|
|
1991
2020
|
const spawnAgentTool = defineTool("spawn_agent", {
|
|
1992
|
-
description: "Spawn a sub-agent. For KNOWN user-creatable agents, pass agent_name
|
|
1993
|
-
"The agent's
|
|
1994
|
-
"Do
|
|
2021
|
+
description: "Spawn a sub-agent. For KNOWN user-creatable agents, pass agent_name. " +
|
|
2022
|
+
"The agent's instructions, tools, and startup requirement load automatically; task supplies your assignment. " +
|
|
2023
|
+
"Do not override system_message or tool_names when using agent_name. " +
|
|
2024
|
+
"Before choosing a custom child, check the available static and published agent definitions with ps_list_agents unless the current catalog already identifies a suitable specialist. Select by role, source access, and capabilities, then pass the exact agent_name from the list and task for the assignment. Prefer a suitable named specialist over recreating it as a generic child. " +
|
|
1995
2025
|
"Calling spawn_agent does NOT finish your turn. After it succeeds, continue executing the rest of your workflow in the SAME turn unless you intentionally call wait, wait_for_agents, ask_user, or give your final answer. " +
|
|
1996
2026
|
"Call ps_list_agents to see all available named agents you CAN spawn. " +
|
|
1997
2027
|
"Worker-managed system agents are not valid spawn_agent targets; if one is missing, the workers likely need to be restarted. " +
|
|
1998
|
-
"For CUSTOM agents (ad-hoc tasks), pass task instead — no agent_name is needed. " +
|
|
1999
|
-
"
|
|
2028
|
+
"For CUSTOM agents (ad-hoc tasks), pass task instead — no agent_name is needed. Do not attach package-owned names through tool_names; select their named agent through ps_list_agents so its instructions, tools, and startup requirement stay together. " +
|
|
2029
|
+
"Use a custom agent when no available named definition fits the task. " +
|
|
2000
2030
|
"If you want a different model, call list_available_models first and use only an exact provider:model value from that list. " +
|
|
2001
2031
|
"If you want different reasoning power, also use only a reasoning_effort value listed for that model. " +
|
|
2002
2032
|
"Never invent, guess, or shorten model names.",
|
|
@@ -2005,11 +2035,11 @@ export class ManagedSession {
|
|
|
2005
2035
|
properties: {
|
|
2006
2036
|
agent_name: {
|
|
2007
2037
|
type: "string",
|
|
2008
|
-
description: "Name of a known user-creatable agent to spawn (from ps_list_agents).
|
|
2038
|
+
description: "Name of a known user-creatable agent to spawn (from ps_list_agents). Its instructions, tools, and startup requirement load automatically. Optionally pass task for an assignment; otherwise its initial prompt is used. Do not override system_message or tool_names. Worker-managed system agents are not valid here.",
|
|
2009
2039
|
},
|
|
2010
2040
|
task: {
|
|
2011
2041
|
type: "string",
|
|
2012
|
-
description: "
|
|
2042
|
+
description: "The assignment for the child, whether named or custom. A named agent retains its instructions, tools, and startup requirement. Required for custom agents; optional for named agents, whose initial prompt is the default.",
|
|
2013
2043
|
},
|
|
2014
2044
|
model: {
|
|
2015
2045
|
type: "string",
|
|
@@ -2047,8 +2077,11 @@ export class ManagedSession {
|
|
|
2047
2077
|
handler: async (args) => {
|
|
2048
2078
|
if (hasTerminalTurnBoundary(turnState))
|
|
2049
2079
|
return blockedAfterTurnBoundary("spawn_agent");
|
|
2080
|
+
if (Object.hasOwn(args, "required_tool") || Object.hasOwn(args, "requiredTool")) {
|
|
2081
|
+
return "Error: required_tool is no longer supported by spawn_agent. Use ps_list_agents to find a suitable named agent, then pass its exact agent_name and your assignment in task.";
|
|
2082
|
+
}
|
|
2050
2083
|
if (!args.agent_name && !args.task) {
|
|
2051
|
-
return "Error:
|
|
2084
|
+
return "Error: agent_name or task is required.";
|
|
2052
2085
|
}
|
|
2053
2086
|
const reasoningEffort = args.reasoning_effort ? normalizeReasoningEffort(args.reasoning_effort) : undefined;
|
|
2054
2087
|
if (args.reasoning_effort && !reasoningEffort) {
|
|
@@ -2058,7 +2091,10 @@ export class ManagedSession {
|
|
|
2058
2091
|
return "Error: context_tier must be one of default, long_context.";
|
|
2059
2092
|
}
|
|
2060
2093
|
if (controlBridge) {
|
|
2061
|
-
return await controlBridge.spawnAgent({
|
|
2094
|
+
return await controlBridge.spawnAgent({
|
|
2095
|
+
...args,
|
|
2096
|
+
...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
|
|
2097
|
+
});
|
|
2062
2098
|
}
|
|
2063
2099
|
turnState.pendingActions.push({
|
|
2064
2100
|
type: "spawn_agent",
|
|
@@ -2500,7 +2536,8 @@ export class ManagedSession {
|
|
|
2500
2536
|
// registerTools from the public types (it was always @internal) but
|
|
2501
2537
|
// ships it unchanged in dist/session.js — cast until a public
|
|
2502
2538
|
// handler-refresh API exists.
|
|
2503
|
-
this.copilotSession.registerTools(
|
|
2539
|
+
this.copilotSession.registerTools(this.config.nativeSubagents === "sync"
|
|
2540
|
+
? guardNativeExternalTools(allTools, this.copilotSession.sessionId) : allTools);
|
|
2504
2541
|
// Collect the final assistant content and all events via on()
|
|
2505
2542
|
let finalContent;
|
|
2506
2543
|
const collectedEvents = [];
|
|
@@ -2531,6 +2568,19 @@ export class ManagedSession {
|
|
|
2531
2568
|
catch { }
|
|
2532
2569
|
})
|
|
2533
2570
|
: null;
|
|
2571
|
+
const nativeTasks = this.config.nativeSubagents === "sync"
|
|
2572
|
+
? new NativeTaskObserver(this.copilotSession, {
|
|
2573
|
+
turnIndex: opts?.turnIndex,
|
|
2574
|
+
emit: (event) => {
|
|
2575
|
+
if (event.eventType !== "session.native_tasks_tick")
|
|
2576
|
+
collectedEvents.push(event);
|
|
2577
|
+
try {
|
|
2578
|
+
opts?.onEvent?.(event);
|
|
2579
|
+
}
|
|
2580
|
+
catch { }
|
|
2581
|
+
},
|
|
2582
|
+
})
|
|
2583
|
+
: null;
|
|
2534
2584
|
// Note: we used to emit a synthetic `assistant.streaming_progress`
|
|
2535
2585
|
// heartbeat into CMS for the activity pane. The user found those
|
|
2536
2586
|
// rows noisy compared to the actual reasoning snapshots, so the
|
|
@@ -2657,6 +2707,30 @@ export class ManagedSession {
|
|
|
2657
2707
|
eventData.durableSessionId = durableSessionId;
|
|
2658
2708
|
}
|
|
2659
2709
|
}
|
|
2710
|
+
nativeTasks?.observe({ ...event, data: eventData });
|
|
2711
|
+
// This empty ephemeral event only invalidates the CLI task
|
|
2712
|
+
// registry. It is neither activity nor durable history.
|
|
2713
|
+
if (eventType === "session.background_tasks_changed")
|
|
2714
|
+
return;
|
|
2715
|
+
if (isNativeChildEvent(event)) {
|
|
2716
|
+
// Child events share the parent subscription. Keep usage
|
|
2717
|
+
// in the existing accounting stream, but namespace child
|
|
2718
|
+
// transcript/tools so they cannot settle parent state or
|
|
2719
|
+
// satisfy a required parent tool invocation.
|
|
2720
|
+
if (/delta|streaming/.test(eventType))
|
|
2721
|
+
return;
|
|
2722
|
+
const nativeEvent = {
|
|
2723
|
+
eventType: eventType === "assistant.usage" || eventType.startsWith("subagent.")
|
|
2724
|
+
? eventType : `native.${eventType}`,
|
|
2725
|
+
data: { ...eventData, nativeAgentId: event.agentId ?? eventData.nativeAgentId ?? eventData.parentToolCallId },
|
|
2726
|
+
};
|
|
2727
|
+
collectedEvents.push(nativeEvent);
|
|
2728
|
+
try {
|
|
2729
|
+
opts?.onEvent?.(nativeEvent);
|
|
2730
|
+
}
|
|
2731
|
+
catch { }
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2660
2734
|
const captured = { eventType, data: eventData };
|
|
2661
2735
|
if (eventType === "session.error" && isBenignPostCompletionQueryError(eventData)) {
|
|
2662
2736
|
deferredSessionError = captured;
|
|
@@ -2782,6 +2856,8 @@ export class ManagedSession {
|
|
|
2782
2856
|
}
|
|
2783
2857
|
}));
|
|
2784
2858
|
unsubscribers.push(this.copilotSession.on("assistant.reasoning", (event) => {
|
|
2859
|
+
if (isNativeChildEvent(event))
|
|
2860
|
+
return;
|
|
2785
2861
|
currentReasoning = String(extractReasoningText(event?.data ?? event) || "").trim();
|
|
2786
2862
|
if (currentReasoning) {
|
|
2787
2863
|
lastPublishedReasoning = currentReasoning;
|
|
@@ -2790,6 +2866,8 @@ export class ManagedSession {
|
|
|
2790
2866
|
}));
|
|
2791
2867
|
for (const eventType of ["assistant.reasoning_delta", "reasoning_delta"]) {
|
|
2792
2868
|
unsubscribers.push(this.copilotSession.on(eventType, (event) => {
|
|
2869
|
+
if (isNativeChildEvent(event))
|
|
2870
|
+
return;
|
|
2793
2871
|
currentReasoning = mergeReasoningText(currentReasoning, extractReasoningText(event?.data ?? event));
|
|
2794
2872
|
publishReasoningSnapshot(eventType);
|
|
2795
2873
|
}));
|
|
@@ -2797,6 +2875,8 @@ export class ManagedSession {
|
|
|
2797
2875
|
// Stream deltas to the caller if requested
|
|
2798
2876
|
if (opts?.onDelta) {
|
|
2799
2877
|
unsubscribers.push(this.copilotSession.on("assistant.message_delta", (event) => {
|
|
2878
|
+
if (isNativeChildEvent(event))
|
|
2879
|
+
return;
|
|
2800
2880
|
if (opts.requiredTool && !hasInvokedTool(collectedEvents, opts.requiredTool))
|
|
2801
2881
|
return;
|
|
2802
2882
|
if (event.data?.deltaContent) {
|
|
@@ -2807,11 +2887,15 @@ export class ManagedSession {
|
|
|
2807
2887
|
// Notify caller of tool execution starts
|
|
2808
2888
|
if (opts?.onToolStart) {
|
|
2809
2889
|
unsubscribers.push(this.copilotSession.on("tool.execution_start", (event) => {
|
|
2890
|
+
if (isNativeChildEvent(event))
|
|
2891
|
+
return;
|
|
2810
2892
|
opts.onToolStart(event.data?.toolName ?? "unknown", event.data?.toolArgs);
|
|
2811
2893
|
}));
|
|
2812
2894
|
}
|
|
2813
2895
|
// session.idle = turn finished (normal completion or post-abort)
|
|
2814
|
-
unsubscribers.push(this.copilotSession.on("session.idle", () => {
|
|
2896
|
+
unsubscribers.push(this.copilotSession.on("session.idle", (event) => {
|
|
2897
|
+
if (isNativeChildEvent(event))
|
|
2898
|
+
return;
|
|
2815
2899
|
flushStreamingProgress(true);
|
|
2816
2900
|
publishReasoningSnapshot("session.idle", true);
|
|
2817
2901
|
liveTurn?.finishTurn();
|
|
@@ -2862,7 +2946,9 @@ export class ManagedSession {
|
|
|
2862
2946
|
// the model's response to a mid-turn correction without tearing down the
|
|
2863
2947
|
// event subscriptions set up above.
|
|
2864
2948
|
const waitForNextIdle = () => new Promise((resolve) => {
|
|
2865
|
-
const unsub = this.copilotSession.on("session.idle", () => {
|
|
2949
|
+
const unsub = this.copilotSession.on("session.idle", (event) => {
|
|
2950
|
+
if (isNativeChildEvent(event))
|
|
2951
|
+
return;
|
|
2866
2952
|
flushStreamingProgress(true);
|
|
2867
2953
|
publishReasoningSnapshot("session.idle", true);
|
|
2868
2954
|
liveTurn?.finishTurn();
|
|
@@ -3062,6 +3148,7 @@ export class ManagedSession {
|
|
|
3062
3148
|
// live row anyway so reconnecting viewers cannot see stale text.
|
|
3063
3149
|
liveTurn?.finishTurn();
|
|
3064
3150
|
liveTurn?.dispose();
|
|
3151
|
+
nativeTasks?.finish(this.stopRequest ? "cancelled" : "interrupted");
|
|
3065
3152
|
// Always clean up subscriptions
|
|
3066
3153
|
for (const unsub of unsubscribers)
|
|
3067
3154
|
unsub();
|
|
@@ -3149,6 +3236,10 @@ export class ManagedSession {
|
|
|
3149
3236
|
* Update configuration for the next turn.
|
|
3150
3237
|
*/
|
|
3151
3238
|
updateConfig(config) {
|
|
3239
|
+
if (config.nativeFeatureAllowed !== undefined)
|
|
3240
|
+
this.config.nativeFeatureAllowed = config.nativeFeatureAllowed;
|
|
3241
|
+
if (config.featureToolFingerprint !== undefined)
|
|
3242
|
+
this.config.featureToolFingerprint = config.featureToolFingerprint;
|
|
3152
3243
|
if (config.model !== undefined)
|
|
3153
3244
|
this.config.model = config.model;
|
|
3154
3245
|
if (Object.prototype.hasOwnProperty.call(config, "reasoningEffort"))
|
|
@@ -3183,6 +3274,12 @@ export class ManagedSession {
|
|
|
3183
3274
|
const nextProviderFingerprint = config.providerFingerprint !== undefined
|
|
3184
3275
|
? config.providerFingerprint ?? null
|
|
3185
3276
|
: currentProviderFingerprint;
|
|
3277
|
+
if (config.nativeSubagents !== undefined
|
|
3278
|
+
&& config.nativeSubagents !== (this.config.nativeSubagents ?? "off"))
|
|
3279
|
+
return true;
|
|
3280
|
+
if (config.featureToolFingerprint !== undefined
|
|
3281
|
+
&& config.featureToolFingerprint !== this.config.featureToolFingerprint)
|
|
3282
|
+
return true;
|
|
3186
3283
|
return Boolean((currentModel || nextModel)
|
|
3187
3284
|
&& (currentModel !== nextModel
|
|
3188
3285
|
|| currentReasoningEffort !== nextReasoningEffort
|