@bastani/atomic 0.9.4-alpha.5 → 0.9.4-alpha.7
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/CHANGELOG.md +55 -0
- package/dist/builtin/cursor/CHANGELOG.md +6 -0
- package/dist/builtin/cursor/package.json +4 -4
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/package.json +4 -4
- package/dist/builtin/subagents/CHANGELOG.md +20 -0
- package/dist/builtin/subagents/package.json +4 -4
- package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +11 -1
- package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +11 -1
- package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +2 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-step.ts +27 -4
- package/dist/builtin/subagents/src/runs/background/subagent-runner-streaming.ts +25 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-dynamic-step.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-step.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-types.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +3 -1
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +22 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +15 -5
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +5 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +4 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +4 -1
- package/dist/builtin/subagents/src/runs/shared/attempt-watchdog.ts +126 -0
- package/dist/builtin/subagents/src/runs/shared/model-candidate-filter.ts +53 -0
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +52 -53
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +2 -0
- package/dist/builtin/subagents/src/shared/model-info.ts +16 -0
- package/dist/builtin/subagents/src/shared/types-config.ts +2 -0
- package/dist/builtin/web-access/CHANGELOG.md +6 -0
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +12 -0
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +34 -4
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +13 -25
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +2 -0
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +11 -3
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -1
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +11 -4
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +2 -2
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts +7 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +26 -4
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +3 -1
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/copilot-model-catalog.d.ts +25 -74
- package/dist/core/copilot-model-catalog.d.ts.map +1 -1
- package/dist/core/copilot-model-catalog.js +118 -68
- package/dist/core/copilot-model-catalog.js.map +1 -1
- package/dist/core/copilot-model-synthesis.d.ts +10 -0
- package/dist/core/copilot-model-synthesis.d.ts.map +1 -0
- package/dist/core/copilot-model-synthesis.js +89 -0
- package/dist/core/copilot-model-synthesis.js.map +1 -0
- package/dist/core/extensions/api-types.d.ts +2 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +3 -3
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/session-events.d.ts +7 -1
- package/dist/core/extensions/session-events.d.ts.map +1 -1
- package/dist/core/extensions/session-events.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +28 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/model-registry-builtins.d.ts.map +1 -1
- package/dist/core/model-registry-builtins.js +21 -3
- package/dist/core/model-registry-builtins.js.map +1 -1
- package/dist/core/model-resolver-defaults.d.ts.map +1 -1
- package/dist/core/model-resolver-defaults.js +1 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +2 -1
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +2 -12
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +8 -16
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/settings-manager-resource-accessors.d.ts +1 -0
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-resource-accessors.js +11 -0
- package/dist/core/settings-manager-resource-accessors.js.map +1 -1
- package/dist/core/settings-manager-ui-accessors.d.ts +2 -0
- package/dist/core/settings-manager-ui-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-ui-accessors.js +9 -0
- package/dist/core/settings-manager-ui-accessors.js.map +1 -1
- package/dist/core/settings-types.d.ts +2 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/timings.d.ts +7 -5
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +42 -24
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/read-selectors.d.ts.map +1 -1
- package/dist/core/tools/read-selectors.js +19 -1
- package/dist/core/tools/read-selectors.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +12 -23
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +14 -5
- package/dist/main-session.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -15
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +1 -0
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +5 -5
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +1 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +6 -2
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +16 -5
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +1 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-editor-actions.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-editor-actions.js +1 -0
- package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.js +1 -0
- package/dist/modes/interactive/interactive-extension-context.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +2 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +1 -0
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +4 -3
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +1 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +28 -51
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +27 -51
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +19 -0
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +26 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/rpc-entry.d.ts +3 -0
- package/dist/rpc-entry.d.ts.map +1 -0
- package/dist/rpc-entry.js +12 -0
- package/dist/rpc-entry.js.map +1 -0
- package/dist/utils/image-convert.d.ts +1 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +21 -15
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js +41 -0
- package/dist/utils/mime.js.map +1 -1
- package/docs/extensions.md +11 -0
- package/docs/models.md +3 -3
- package/docs/providers.md +1 -1
- package/docs/rpc.md +60 -2
- package/docs/sdk.md +1 -1
- package/docs/settings.md +4 -1
- package/docs/subagents.md +6 -0
- package/docs/workflows.md +2 -0
- package/npm-shrinkwrap.json +138 -140
- package/package.json +15 -10
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { AgentSessionInternalSurface as AgentSession } from "./agent-session-methods.ts";
|
|
2
2
|
export declare function _installAgentToolHooks(this: AgentSession): void;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Install a prepareNextTurnWithContext hook so that extension tool changes
|
|
5
|
+
* (e.g. setActiveTools) and before_agent_start systemPrompt overrides are
|
|
6
|
+
* applied to the next provider request within the same run.
|
|
7
|
+
*/
|
|
8
|
+
export declare function _installAgentNextTurnRefresh(this: AgentSession): void;
|
|
4
9
|
export declare const agentSessionToolHooksMethods: {
|
|
5
10
|
_installAgentToolHooks: typeof _installAgentToolHooks;
|
|
11
|
+
_installAgentNextTurnRefresh: typeof _installAgentNextTurnRefresh;
|
|
6
12
|
};
|
|
7
13
|
//# sourceMappingURL=agent-session-tool-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-hooks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-session-tool-hooks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG9F,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAkE/D;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAqBrE;AAED,eAAO,MAAM,4BAA4B;;;CAGxC,CAAC","sourcesContent":["import type { PrepareNextTurnContext } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\treturn await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult({\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\tcontent: result.content,\n\t\t\t\t\tdetails: result.details,\n\t\t\t\t\tisError,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\tconst extensionReplacement = hookResult\n\t\t\t? {\n\t\t\t\t\tcontent: hookResult.content,\n\t\t\t\t\tdetails: hookResult.details,\n\t\t\t\t\tisError: hookResult.isError ?? isError,\n\t\t\t\t}\n\t\t\t: undefined;\n\t\tconst finalResult = hookResult\n\t\t\t? {\n\t\t\t\t\tcontent: hookResult.content ?? result.content,\n\t\t\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\t\t\tdetails: hookResult.details ?? result.details,\n\t\t\t\t}\n\t\t\t: result;\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\treturn redirectReplacement ?? extensionReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\tthis.agent.prepareNextTurnWithContext = async (turn, signal) => {\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? turn.context;\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tsystemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
|
|
@@ -62,11 +62,33 @@ export function _installAgentToolHooks() {
|
|
|
62
62
|
return redirectReplacement ?? extensionReplacement;
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Install a prepareNextTurnWithContext hook so that extension tool changes
|
|
67
|
+
* (e.g. setActiveTools) and before_agent_start systemPrompt overrides are
|
|
68
|
+
* applied to the next provider request within the same run.
|
|
69
|
+
*/
|
|
70
|
+
export function _installAgentNextTurnRefresh() {
|
|
71
|
+
const previousPrepareNextTurnWithContext = this.agent.prepareNextTurnWithContext ??
|
|
72
|
+
(this.agent.prepareNextTurn
|
|
73
|
+
? async (_turn, signal) => await this.agent.prepareNextTurn?.(signal)
|
|
74
|
+
: undefined);
|
|
75
|
+
this.agent.prepareNextTurnWithContext = async (turn, signal) => {
|
|
76
|
+
const previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);
|
|
77
|
+
const previousContext = previousSnapshot?.context ?? turn.context;
|
|
78
|
+
return {
|
|
79
|
+
...previousSnapshot,
|
|
80
|
+
context: {
|
|
81
|
+
...previousContext,
|
|
82
|
+
systemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,
|
|
83
|
+
tools: this.agent.state.tools.slice(),
|
|
84
|
+
},
|
|
85
|
+
model: this.agent.state.model,
|
|
86
|
+
thinkingLevel: this.agent.state.thinkingLevel,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
69
90
|
export const agentSessionToolHooksMethods = {
|
|
70
91
|
_installAgentToolHooks,
|
|
92
|
+
_installAgentNextTurnRefresh,
|
|
71
93
|
};
|
|
72
94
|
//# sourceMappingURL=agent-session-tool-hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC;QAE5B,IAAI,CAAC;YACJ,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC;gBAChC,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,UAAU,EAAE,QAAQ,CAAC,EAAE;gBACvB,KAAK,EAAE,IAA+B;aACtC,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;gBAC1B,MAAM,GAAG,CAAC;YACX,CAAC;YACD,MAAM,IAAI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AI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa;SAC7C,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,sBAAsB;IACtB,4BAA4B;CAC5B,CAAC","sourcesContent":["import type { PrepareNextTurnContext } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\treturn await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult({\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\tcontent: result.content,\n\t\t\t\t\tdetails: result.details,\n\t\t\t\t\tisError,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\tconst extensionReplacement = hookResult\n\t\t\t? {\n\t\t\t\t\tcontent: hookResult.content,\n\t\t\t\t\tdetails: hookResult.details,\n\t\t\t\t\tisError: hookResult.isError ?? isError,\n\t\t\t\t}\n\t\t\t: undefined;\n\t\tconst finalResult = hookResult\n\t\t\t? {\n\t\t\t\t\tcontent: hookResult.content ?? result.content,\n\t\t\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\t\t\tdetails: hookResult.details ?? result.details,\n\t\t\t\t}\n\t\t\t: result;\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\treturn redirectReplacement ?? extensionReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\tthis.agent.prepareNextTurnWithContext = async (turn, signal) => {\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? turn.context;\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tsystemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tree.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAGrE;AAMD;;;;;;;;;;GAUG;AAEH,wBAAsB,YAAY,CAAC,IAAI,EAAE,YAAY,EACpD,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/G,OAAO,CAAC;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAuL5G;AAED;;GAEG;AAEH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,YAAY,GAAG,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAetG;AAGD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAS5H;AAED;;GAEG;AAEH,eAAO,MAAM,uBAAuB;;;;;CAKnC,CAAC","sourcesContent":["import type { BranchSummaryEntry } from \"./session-manager.ts\";\nimport { collectEntriesForBranchSummary, generateBranchSummary } from \"./compaction/index.ts\";\nimport type { SessionBeforeTreeResult, TreePreparation } from \"./extensions/index.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\n\nexport function setSessionName(this: AgentSession, name: string): void {\n\tthis.sessionManager.appendSessionInfo(name);\n\tthis._emit({ type: \"session_info_changed\", name: this.sessionManager.getSessionName() });\n}\n\n// =========================================================================\n// Tree Navigation\n// =========================================================================\n\n/**\n * Navigate to a different node in the session tree.\n * Unlike fork() which creates a new session file, this stays in the same file.\n *\n * @param targetId The entry ID to navigate to\n * @param options.summarize Whether user wants to summarize abandoned branch\n * @param options.customInstructions Custom instructions for summarizer\n * @param options.replaceInstructions If true, customInstructions replaces the default prompt\n * @param options.label Label to attach to the branch summary entry\n * @returns Result with editorText (if user message) and cancelled status\n */\n\nexport async function navigateTree(this: AgentSession, \n\ttargetId: string,\n\toptions: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string } = {},\n): Promise<{ editorText?: string; cancelled: boolean; aborted?: boolean; summaryEntry?: BranchSummaryEntry }> {\n\tconst oldLeafId = this.sessionManager.getLeafId();\n\n\t// No-op if already at target\n\tif (targetId === oldLeafId) {\n\t\treturn { cancelled: false };\n\t}\n\n\t// Model required for summarization\n\tif (options.summarize && !this.model) {\n\t\tthrow new Error(\"No model available for summarization\");\n\t}\n\n\tconst targetEntry = this.sessionManager.getEntry(targetId);\n\tif (!targetEntry) {\n\t\tthrow new Error(`Entry ${targetId} not found`);\n\t}\n\n\t// Collect entries to summarize (from old leaf to common ancestor)\n\tconst { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(\n\t\tthis.sessionManager,\n\t\toldLeafId,\n\t\ttargetId,\n\t);\n\n\t// Prepare event data - mutable so extensions can override\n\tlet customInstructions = options.customInstructions;\n\tlet replaceInstructions = options.replaceInstructions;\n\tlet label = options.label;\n\n\tconst preparation: TreePreparation = {\n\t\ttargetId,\n\t\toldLeafId,\n\t\tcommonAncestorId,\n\t\tentriesToSummarize,\n\t\tuserWantsSummary: options.summarize ?? false,\n\t\tcustomInstructions,\n\t\treplaceInstructions,\n\t\tlabel,\n\t};\n\n\t// Set up abort controller for summarization\n\tthis._branchSummaryAbortController = new AbortController();\n\n\ttry {\n\t\tlet extensionSummary: { summary: string; details?: unknown } | undefined;\n\t\tlet fromExtension = false;\n\n\t\t// Emit session_before_tree event\n\t\tif (this._extensionRunner.hasHandlers(\"session_before_tree\")) {\n\t\t\tconst result = (await this._extensionRunner.emit({\n\t\t\t\ttype: \"session_before_tree\",\n\t\t\t\tpreparation,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t})) as SessionBeforeTreeResult | undefined;\n\n\t\t\tif (result?.cancel) {\n\t\t\t\treturn { cancelled: true };\n\t\t\t}\n\n\t\t\tif (result?.summary && options.summarize) {\n\t\t\t\textensionSummary = result.summary;\n\t\t\t\tfromExtension = true;\n\t\t\t}\n\n\t\t\t// Allow extensions to override instructions and label\n\t\t\tif (result?.customInstructions !== undefined) {\n\t\t\t\tcustomInstructions = result.customInstructions;\n\t\t\t}\n\t\t\tif (result?.replaceInstructions !== undefined) {\n\t\t\t\treplaceInstructions = result.replaceInstructions;\n\t\t\t}\n\t\t\tif (result?.label !== undefined) {\n\t\t\t\tlabel = result.label;\n\t\t\t}\n\t\t}\n\n\t\t// Run default summarizer if needed\n\t\tlet summaryText: string | undefined;\n\t\tlet summaryDetails: unknown;\n\t\tif (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {\n\t\t\tconst model = this.model!;\n\t\t\tconst { apiKey, headers } = await this._getRequiredRequestAuth(model);\n\t\t\tconst branchSummarySettings = this.settingsManager.getBranchSummarySettings();\n\t\t\tconst result = await generateBranchSummary(entriesToSummarize, {\n\t\t\t\tmodel,\n\t\t\t\tapiKey,\n\t\t\t\theaders,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t\tcustomInstructions,\n\t\t\t\treplaceInstructions,\n\t\t\t\treserveTokens: branchSummarySettings.reserveTokens,\n\t\t\t\tstreamFn: this.agent.streamFn,\n\t\t\t});\n\t\t\tif (result.aborted) {\n\t\t\t\treturn { cancelled: true, aborted: true };\n\t\t\t}\n\t\t\tif (result.error) {\n\t\t\t\tthrow new Error(result.error);\n\t\t\t}\n\t\t\tsummaryText = result.summary;\n\t\t\tsummaryDetails = {\n\t\t\t\treadFiles: result.readFiles || [],\n\t\t\t\tmodifiedFiles: result.modifiedFiles || [],\n\t\t\t};\n\t\t} else if (extensionSummary) {\n\t\t\tsummaryText = extensionSummary.summary;\n\t\t\tsummaryDetails = extensionSummary.details;\n\t\t}\n\n\t\t// Determine the new leaf position based on target type\n\t\tlet newLeafId: string | null;\n\t\tlet editorText: string | undefined;\n\n\t\tif (targetEntry.type === \"message\" && targetEntry.message.role === \"user\") {\n\t\t\t// User message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText = this._extractUserMessageText(targetEntry.message.content);\n\t\t} else if (targetEntry.type === \"custom_message\") {\n\t\t\t// Custom message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText =\n\t\t\t\ttypeof targetEntry.content === \"string\"\n\t\t\t\t\t? targetEntry.content\n\t\t\t\t\t: targetEntry.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t} else {\n\t\t\t// Non-user message: leaf = selected node\n\t\t\tnewLeafId = targetId;\n\t\t}\n\n\t\t// Switch leaf (with or without summary)\n\t\t// Summary is attached at the navigation target position (newLeafId), not the old branch\n\t\tlet summaryEntry: BranchSummaryEntry | undefined;\n\t\tif (summaryText) {\n\t\t\t// Create summary at target position (can be null for root)\n\t\t\tconst summaryId = this.sessionManager.branchWithSummary(\n\t\t\t\tnewLeafId,\n\t\t\t\tsummaryText,\n\t\t\t\tsummaryDetails,\n\t\t\t\tfromExtension,\n\t\t\t);\n\t\t\tsummaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;\n\n\t\t\t// Attach label to the summary entry\n\t\t\tif (label) {\n\t\t\t\tthis.sessionManager.appendLabelChange(summaryId, label);\n\t\t\t}\n\t\t} else if (newLeafId === null) {\n\t\t\t// No summary, navigating to root - reset leaf\n\t\t\tthis.sessionManager.resetLeaf();\n\t\t} else {\n\t\t\t// No summary, navigating to non-root\n\t\t\tthis.sessionManager.branch(newLeafId);\n\t\t}\n\n\t\t// Attach label to target entry when not summarizing (no summary entry to label)\n\t\tif (label && !summaryText) {\n\t\t\tthis.sessionManager.appendLabelChange(targetId, label);\n\t\t}\n\n\t\t// Update agent state\n\t\tconst sessionContext = this.sessionManager.buildSessionContext();\n\t\tthis.agent.state.messages = sessionContext.messages;\n\t\tthis._applyContextWindowReplay(sessionContext.contextWindow);\n\n\t\t// Emit session_tree event\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_tree\",\n\t\t\tnewLeafId: this.sessionManager.getLeafId(),\n\t\t\toldLeafId,\n\t\t\tsummaryEntry,\n\t\t\tfromExtension: summaryText ? fromExtension : undefined,\n\t\t});\n\n\t\t// Emit to custom tools\n\n\t\treturn { editorText, cancelled: false, summaryEntry };\n\t} finally {\n\t\tthis._branchSummaryAbortController = undefined;\n\t}\n}\n\n/**\n * Get all user messages from session for fork selector.\n */\n\nexport function getUserMessagesForForking(this: AgentSession): Array<{ entryId: string; text: string }> {\n\tconst entries = this.sessionManager.getEntries();\n\tconst result: Array<{ entryId: string; text: string }> = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role !== \"user\") continue;\n\n\t\tconst text = this._extractUserMessageText(entry.message.content);\n\t\tif (text) {\n\t\t\tresult.push({ entryId: entry.id, text });\n\t\t}\n\t}\n\n\treturn result;\n}\n\n\nexport function _extractUserMessageText(this: AgentSession, content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\treturn content\n\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t.map((c) => c.text)\n\t\t\t.join(\"\");\n\t}\n\treturn \"\";\n}\n\n/**\n * Get session statistics.\n */\n\nexport const agentSessionTreeMethods = {\n\tsetSessionName,\n\tnavigateTree,\n\tgetUserMessagesForForking,\n\t_extractUserMessageText,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-tree.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAKrE;AAMD;;;;;;;;;;GAUG;AAEH,wBAAsB,YAAY,CAAC,IAAI,EAAE,YAAY,EACpD,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/G,OAAO,CAAC;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAuL5G;AAED;;GAEG;AAEH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,YAAY,GAAG,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAetG;AAGD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAS5H;AAED;;GAEG;AAEH,eAAO,MAAM,uBAAuB;;;;;CAKnC,CAAC","sourcesContent":["import type { BranchSummaryEntry } from \"./session-manager.ts\";\nimport { collectEntriesForBranchSummary, generateBranchSummary } from \"./compaction/index.ts\";\nimport type { SessionBeforeTreeResult, TreePreparation } from \"./extensions/index.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\n\nexport function setSessionName(this: AgentSession, name: string): void {\n\tthis.sessionManager.appendSessionInfo(name);\n\tconst event = { type: \"session_info_changed\", name: this.sessionManager.getSessionName() } as const;\n\tthis._emit(event);\n\tvoid this._extensionRunner.emit(event);\n}\n\n// =========================================================================\n// Tree Navigation\n// =========================================================================\n\n/**\n * Navigate to a different node in the session tree.\n * Unlike fork() which creates a new session file, this stays in the same file.\n *\n * @param targetId The entry ID to navigate to\n * @param options.summarize Whether user wants to summarize abandoned branch\n * @param options.customInstructions Custom instructions for summarizer\n * @param options.replaceInstructions If true, customInstructions replaces the default prompt\n * @param options.label Label to attach to the branch summary entry\n * @returns Result with editorText (if user message) and cancelled status\n */\n\nexport async function navigateTree(this: AgentSession, \n\ttargetId: string,\n\toptions: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string } = {},\n): Promise<{ editorText?: string; cancelled: boolean; aborted?: boolean; summaryEntry?: BranchSummaryEntry }> {\n\tconst oldLeafId = this.sessionManager.getLeafId();\n\n\t// No-op if already at target\n\tif (targetId === oldLeafId) {\n\t\treturn { cancelled: false };\n\t}\n\n\t// Model required for summarization\n\tif (options.summarize && !this.model) {\n\t\tthrow new Error(\"No model available for summarization\");\n\t}\n\n\tconst targetEntry = this.sessionManager.getEntry(targetId);\n\tif (!targetEntry) {\n\t\tthrow new Error(`Entry ${targetId} not found`);\n\t}\n\n\t// Collect entries to summarize (from old leaf to common ancestor)\n\tconst { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(\n\t\tthis.sessionManager,\n\t\toldLeafId,\n\t\ttargetId,\n\t);\n\n\t// Prepare event data - mutable so extensions can override\n\tlet customInstructions = options.customInstructions;\n\tlet replaceInstructions = options.replaceInstructions;\n\tlet label = options.label;\n\n\tconst preparation: TreePreparation = {\n\t\ttargetId,\n\t\toldLeafId,\n\t\tcommonAncestorId,\n\t\tentriesToSummarize,\n\t\tuserWantsSummary: options.summarize ?? false,\n\t\tcustomInstructions,\n\t\treplaceInstructions,\n\t\tlabel,\n\t};\n\n\t// Set up abort controller for summarization\n\tthis._branchSummaryAbortController = new AbortController();\n\n\ttry {\n\t\tlet extensionSummary: { summary: string; details?: unknown } | undefined;\n\t\tlet fromExtension = false;\n\n\t\t// Emit session_before_tree event\n\t\tif (this._extensionRunner.hasHandlers(\"session_before_tree\")) {\n\t\t\tconst result = (await this._extensionRunner.emit({\n\t\t\t\ttype: \"session_before_tree\",\n\t\t\t\tpreparation,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t})) as SessionBeforeTreeResult | undefined;\n\n\t\t\tif (result?.cancel) {\n\t\t\t\treturn { cancelled: true };\n\t\t\t}\n\n\t\t\tif (result?.summary && options.summarize) {\n\t\t\t\textensionSummary = result.summary;\n\t\t\t\tfromExtension = true;\n\t\t\t}\n\n\t\t\t// Allow extensions to override instructions and label\n\t\t\tif (result?.customInstructions !== undefined) {\n\t\t\t\tcustomInstructions = result.customInstructions;\n\t\t\t}\n\t\t\tif (result?.replaceInstructions !== undefined) {\n\t\t\t\treplaceInstructions = result.replaceInstructions;\n\t\t\t}\n\t\t\tif (result?.label !== undefined) {\n\t\t\t\tlabel = result.label;\n\t\t\t}\n\t\t}\n\n\t\t// Run default summarizer if needed\n\t\tlet summaryText: string | undefined;\n\t\tlet summaryDetails: unknown;\n\t\tif (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {\n\t\t\tconst model = this.model!;\n\t\t\tconst { apiKey, headers } = await this._getRequiredRequestAuth(model);\n\t\t\tconst branchSummarySettings = this.settingsManager.getBranchSummarySettings();\n\t\t\tconst result = await generateBranchSummary(entriesToSummarize, {\n\t\t\t\tmodel,\n\t\t\t\tapiKey,\n\t\t\t\theaders,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t\tcustomInstructions,\n\t\t\t\treplaceInstructions,\n\t\t\t\treserveTokens: branchSummarySettings.reserveTokens,\n\t\t\t\tstreamFn: this.agent.streamFn,\n\t\t\t});\n\t\t\tif (result.aborted) {\n\t\t\t\treturn { cancelled: true, aborted: true };\n\t\t\t}\n\t\t\tif (result.error) {\n\t\t\t\tthrow new Error(result.error);\n\t\t\t}\n\t\t\tsummaryText = result.summary;\n\t\t\tsummaryDetails = {\n\t\t\t\treadFiles: result.readFiles || [],\n\t\t\t\tmodifiedFiles: result.modifiedFiles || [],\n\t\t\t};\n\t\t} else if (extensionSummary) {\n\t\t\tsummaryText = extensionSummary.summary;\n\t\t\tsummaryDetails = extensionSummary.details;\n\t\t}\n\n\t\t// Determine the new leaf position based on target type\n\t\tlet newLeafId: string | null;\n\t\tlet editorText: string | undefined;\n\n\t\tif (targetEntry.type === \"message\" && targetEntry.message.role === \"user\") {\n\t\t\t// User message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText = this._extractUserMessageText(targetEntry.message.content);\n\t\t} else if (targetEntry.type === \"custom_message\") {\n\t\t\t// Custom message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText =\n\t\t\t\ttypeof targetEntry.content === \"string\"\n\t\t\t\t\t? targetEntry.content\n\t\t\t\t\t: targetEntry.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t} else {\n\t\t\t// Non-user message: leaf = selected node\n\t\t\tnewLeafId = targetId;\n\t\t}\n\n\t\t// Switch leaf (with or without summary)\n\t\t// Summary is attached at the navigation target position (newLeafId), not the old branch\n\t\tlet summaryEntry: BranchSummaryEntry | undefined;\n\t\tif (summaryText) {\n\t\t\t// Create summary at target position (can be null for root)\n\t\t\tconst summaryId = this.sessionManager.branchWithSummary(\n\t\t\t\tnewLeafId,\n\t\t\t\tsummaryText,\n\t\t\t\tsummaryDetails,\n\t\t\t\tfromExtension,\n\t\t\t);\n\t\t\tsummaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;\n\n\t\t\t// Attach label to the summary entry\n\t\t\tif (label) {\n\t\t\t\tthis.sessionManager.appendLabelChange(summaryId, label);\n\t\t\t}\n\t\t} else if (newLeafId === null) {\n\t\t\t// No summary, navigating to root - reset leaf\n\t\t\tthis.sessionManager.resetLeaf();\n\t\t} else {\n\t\t\t// No summary, navigating to non-root\n\t\t\tthis.sessionManager.branch(newLeafId);\n\t\t}\n\n\t\t// Attach label to target entry when not summarizing (no summary entry to label)\n\t\tif (label && !summaryText) {\n\t\t\tthis.sessionManager.appendLabelChange(targetId, label);\n\t\t}\n\n\t\t// Update agent state\n\t\tconst sessionContext = this.sessionManager.buildSessionContext();\n\t\tthis.agent.state.messages = sessionContext.messages;\n\t\tthis._applyContextWindowReplay(sessionContext.contextWindow);\n\n\t\t// Emit session_tree event\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_tree\",\n\t\t\tnewLeafId: this.sessionManager.getLeafId(),\n\t\t\toldLeafId,\n\t\t\tsummaryEntry,\n\t\t\tfromExtension: summaryText ? fromExtension : undefined,\n\t\t});\n\n\t\t// Emit to custom tools\n\n\t\treturn { editorText, cancelled: false, summaryEntry };\n\t} finally {\n\t\tthis._branchSummaryAbortController = undefined;\n\t}\n}\n\n/**\n * Get all user messages from session for fork selector.\n */\n\nexport function getUserMessagesForForking(this: AgentSession): Array<{ entryId: string; text: string }> {\n\tconst entries = this.sessionManager.getEntries();\n\tconst result: Array<{ entryId: string; text: string }> = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role !== \"user\") continue;\n\n\t\tconst text = this._extractUserMessageText(entry.message.content);\n\t\tif (text) {\n\t\t\tresult.push({ entryId: entry.id, text });\n\t\t}\n\t}\n\n\treturn result;\n}\n\n\nexport function _extractUserMessageText(this: AgentSession, content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\treturn content\n\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t.map((c) => c.text)\n\t\t\t.join(\"\");\n\t}\n\treturn \"\";\n}\n\n/**\n * Get session statistics.\n */\n\nexport const agentSessionTreeMethods = {\n\tsetSessionName,\n\tnavigateTree,\n\tgetUserMessagesForForking,\n\t_extractUserMessageText,\n};\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { collectEntriesForBranchSummary, generateBranchSummary } from "./compaction/index.js";
|
|
2
2
|
export function setSessionName(name) {
|
|
3
3
|
this.sessionManager.appendSessionInfo(name);
|
|
4
|
-
|
|
4
|
+
const event = { type: "session_info_changed", name: this.sessionManager.getSessionName() };
|
|
5
|
+
this._emit(event);
|
|
6
|
+
void this._extensionRunner.emit(event);
|
|
5
7
|
}
|
|
6
8
|
// =========================================================================
|
|
7
9
|
// Tree Navigation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tree.js","sourceRoot":"","sources":["../../src/core/agent-session-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,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AE,CAAC;IAE5D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,SAAS;QACvC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,SAAS;QAE5C,MAAM,IAAI,GAAG,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,IAAI,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAGD,MAAM,UAAU,uBAAuB,CAAqB,OAAwD;IACnH,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,OAAO;aACZ,MAAM,CAAC,CAAC,CAAC,EAAuC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;aACrE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAClB,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;GAEG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACtC,cAAc;IACd,YAAY;IACZ,yBAAyB;IACzB,uBAAuB;CACvB,CAAC","sourcesContent":["import type { BranchSummaryEntry } from \"./session-manager.ts\";\nimport { collectEntriesForBranchSummary, generateBranchSummary } from \"./compaction/index.ts\";\nimport type { SessionBeforeTreeResult, TreePreparation } from \"./extensions/index.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\n\nexport function setSessionName(this: AgentSession, name: string): void {\n\tthis.sessionManager.appendSessionInfo(name);\n\tthis._emit({ type: \"session_info_changed\", name: this.sessionManager.getSessionName() });\n}\n\n// =========================================================================\n// Tree Navigation\n// =========================================================================\n\n/**\n * Navigate to a different node in the session tree.\n * Unlike fork() which creates a new session file, this stays in the same file.\n *\n * @param targetId The entry ID to navigate to\n * @param options.summarize Whether user wants to summarize abandoned branch\n * @param options.customInstructions Custom instructions for summarizer\n * @param options.replaceInstructions If true, customInstructions replaces the default prompt\n * @param options.label Label to attach to the branch summary entry\n * @returns Result with editorText (if user message) and cancelled status\n */\n\nexport async function navigateTree(this: AgentSession, \n\ttargetId: string,\n\toptions: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string } = {},\n): Promise<{ editorText?: string; cancelled: boolean; aborted?: boolean; summaryEntry?: BranchSummaryEntry }> {\n\tconst oldLeafId = this.sessionManager.getLeafId();\n\n\t// No-op if already at target\n\tif (targetId === oldLeafId) {\n\t\treturn { cancelled: false };\n\t}\n\n\t// Model required for summarization\n\tif (options.summarize && !this.model) {\n\t\tthrow new Error(\"No model available for summarization\");\n\t}\n\n\tconst targetEntry = this.sessionManager.getEntry(targetId);\n\tif (!targetEntry) {\n\t\tthrow new Error(`Entry ${targetId} not found`);\n\t}\n\n\t// Collect entries to summarize (from old leaf to common ancestor)\n\tconst { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(\n\t\tthis.sessionManager,\n\t\toldLeafId,\n\t\ttargetId,\n\t);\n\n\t// Prepare event data - mutable so extensions can override\n\tlet customInstructions = options.customInstructions;\n\tlet replaceInstructions = options.replaceInstructions;\n\tlet label = options.label;\n\n\tconst preparation: TreePreparation = {\n\t\ttargetId,\n\t\toldLeafId,\n\t\tcommonAncestorId,\n\t\tentriesToSummarize,\n\t\tuserWantsSummary: options.summarize ?? false,\n\t\tcustomInstructions,\n\t\treplaceInstructions,\n\t\tlabel,\n\t};\n\n\t// Set up abort controller for summarization\n\tthis._branchSummaryAbortController = new AbortController();\n\n\ttry {\n\t\tlet extensionSummary: { summary: string; details?: unknown } | undefined;\n\t\tlet fromExtension = false;\n\n\t\t// Emit session_before_tree event\n\t\tif (this._extensionRunner.hasHandlers(\"session_before_tree\")) {\n\t\t\tconst result = (await this._extensionRunner.emit({\n\t\t\t\ttype: \"session_before_tree\",\n\t\t\t\tpreparation,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t})) as SessionBeforeTreeResult | undefined;\n\n\t\t\tif (result?.cancel) {\n\t\t\t\treturn { cancelled: true };\n\t\t\t}\n\n\t\t\tif (result?.summary && options.summarize) {\n\t\t\t\textensionSummary = result.summary;\n\t\t\t\tfromExtension = true;\n\t\t\t}\n\n\t\t\t// Allow extensions to override instructions and label\n\t\t\tif (result?.customInstructions !== undefined) {\n\t\t\t\tcustomInstructions = result.customInstructions;\n\t\t\t}\n\t\t\tif (result?.replaceInstructions !== undefined) {\n\t\t\t\treplaceInstructions = result.replaceInstructions;\n\t\t\t}\n\t\t\tif (result?.label !== undefined) {\n\t\t\t\tlabel = result.label;\n\t\t\t}\n\t\t}\n\n\t\t// Run default summarizer if needed\n\t\tlet summaryText: string | undefined;\n\t\tlet summaryDetails: unknown;\n\t\tif (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {\n\t\t\tconst model = this.model!;\n\t\t\tconst { apiKey, headers } = await this._getRequiredRequestAuth(model);\n\t\t\tconst branchSummarySettings = this.settingsManager.getBranchSummarySettings();\n\t\t\tconst result = await generateBranchSummary(entriesToSummarize, {\n\t\t\t\tmodel,\n\t\t\t\tapiKey,\n\t\t\t\theaders,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t\tcustomInstructions,\n\t\t\t\treplaceInstructions,\n\t\t\t\treserveTokens: branchSummarySettings.reserveTokens,\n\t\t\t\tstreamFn: this.agent.streamFn,\n\t\t\t});\n\t\t\tif (result.aborted) {\n\t\t\t\treturn { cancelled: true, aborted: true };\n\t\t\t}\n\t\t\tif (result.error) {\n\t\t\t\tthrow new Error(result.error);\n\t\t\t}\n\t\t\tsummaryText = result.summary;\n\t\t\tsummaryDetails = {\n\t\t\t\treadFiles: result.readFiles || [],\n\t\t\t\tmodifiedFiles: result.modifiedFiles || [],\n\t\t\t};\n\t\t} else if (extensionSummary) {\n\t\t\tsummaryText = extensionSummary.summary;\n\t\t\tsummaryDetails = extensionSummary.details;\n\t\t}\n\n\t\t// Determine the new leaf position based on target type\n\t\tlet newLeafId: string | null;\n\t\tlet editorText: string | undefined;\n\n\t\tif (targetEntry.type === \"message\" && targetEntry.message.role === \"user\") {\n\t\t\t// User message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText = this._extractUserMessageText(targetEntry.message.content);\n\t\t} else if (targetEntry.type === \"custom_message\") {\n\t\t\t// Custom message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText =\n\t\t\t\ttypeof targetEntry.content === \"string\"\n\t\t\t\t\t? targetEntry.content\n\t\t\t\t\t: targetEntry.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t} else {\n\t\t\t// Non-user message: leaf = selected node\n\t\t\tnewLeafId = targetId;\n\t\t}\n\n\t\t// Switch leaf (with or without summary)\n\t\t// Summary is attached at the navigation target position (newLeafId), not the old branch\n\t\tlet summaryEntry: BranchSummaryEntry | undefined;\n\t\tif (summaryText) {\n\t\t\t// Create summary at target position (can be null for root)\n\t\t\tconst summaryId = this.sessionManager.branchWithSummary(\n\t\t\t\tnewLeafId,\n\t\t\t\tsummaryText,\n\t\t\t\tsummaryDetails,\n\t\t\t\tfromExtension,\n\t\t\t);\n\t\t\tsummaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;\n\n\t\t\t// Attach label to the summary entry\n\t\t\tif (label) {\n\t\t\t\tthis.sessionManager.appendLabelChange(summaryId, label);\n\t\t\t}\n\t\t} else if (newLeafId === null) {\n\t\t\t// No summary, navigating to root - reset leaf\n\t\t\tthis.sessionManager.resetLeaf();\n\t\t} else {\n\t\t\t// No summary, navigating to non-root\n\t\t\tthis.sessionManager.branch(newLeafId);\n\t\t}\n\n\t\t// Attach label to target entry when not summarizing (no summary entry to label)\n\t\tif (label && !summaryText) {\n\t\t\tthis.sessionManager.appendLabelChange(targetId, label);\n\t\t}\n\n\t\t// Update agent state\n\t\tconst sessionContext = this.sessionManager.buildSessionContext();\n\t\tthis.agent.state.messages = sessionContext.messages;\n\t\tthis._applyContextWindowReplay(sessionContext.contextWindow);\n\n\t\t// Emit session_tree event\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_tree\",\n\t\t\tnewLeafId: this.sessionManager.getLeafId(),\n\t\t\toldLeafId,\n\t\t\tsummaryEntry,\n\t\t\tfromExtension: summaryText ? fromExtension : undefined,\n\t\t});\n\n\t\t// Emit to custom tools\n\n\t\treturn { editorText, cancelled: false, summaryEntry };\n\t} finally {\n\t\tthis._branchSummaryAbortController = undefined;\n\t}\n}\n\n/**\n * Get all user messages from session for fork selector.\n */\n\nexport function getUserMessagesForForking(this: AgentSession): Array<{ entryId: string; text: string }> {\n\tconst entries = this.sessionManager.getEntries();\n\tconst result: Array<{ entryId: string; text: string }> = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role !== \"user\") continue;\n\n\t\tconst text = this._extractUserMessageText(entry.message.content);\n\t\tif (text) {\n\t\t\tresult.push({ entryId: entry.id, text });\n\t\t}\n\t}\n\n\treturn result;\n}\n\n\nexport function _extractUserMessageText(this: AgentSession, content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\treturn content\n\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t.map((c) => c.text)\n\t\t\t.join(\"\");\n\t}\n\treturn \"\";\n}\n\n/**\n * Get session statistics.\n */\n\nexport const agentSessionTreeMethods = {\n\tsetSessionName,\n\tnavigateTree,\n\tgetUserMessagesForForking,\n\t_extractUserMessageText,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-tree.js","sourceRoot":"","sources":["../../src/core/agent-session-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI9F,MAAM,UAAU,cAAc,CAAqB,IAAY;IAC9D,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,EAAW,CAAC;IACpG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClB,KAAK,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,4EAA4E;AAC5E,kBAAkB;AAClB,4EAA4E;AAE5E;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,QAAgB,EAChB,OAAO,GAAwG,EAAE;IAEjH,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;IAElD,6BAA6B;IAC7B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,mCAAmC;IACnC,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,MAAM,I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,CAAC;AACX,CAAC;AAED;;GAEG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACtC,cAAc;IACd,YAAY;IACZ,yBAAyB;IACzB,uBAAuB;CACvB,CAAC","sourcesContent":["import type { BranchSummaryEntry } from \"./session-manager.ts\";\nimport { collectEntriesForBranchSummary, generateBranchSummary } from \"./compaction/index.ts\";\nimport type { SessionBeforeTreeResult, TreePreparation } from \"./extensions/index.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\n\nexport function setSessionName(this: AgentSession, name: string): void {\n\tthis.sessionManager.appendSessionInfo(name);\n\tconst event = { type: \"session_info_changed\", name: this.sessionManager.getSessionName() } as const;\n\tthis._emit(event);\n\tvoid this._extensionRunner.emit(event);\n}\n\n// =========================================================================\n// Tree Navigation\n// =========================================================================\n\n/**\n * Navigate to a different node in the session tree.\n * Unlike fork() which creates a new session file, this stays in the same file.\n *\n * @param targetId The entry ID to navigate to\n * @param options.summarize Whether user wants to summarize abandoned branch\n * @param options.customInstructions Custom instructions for summarizer\n * @param options.replaceInstructions If true, customInstructions replaces the default prompt\n * @param options.label Label to attach to the branch summary entry\n * @returns Result with editorText (if user message) and cancelled status\n */\n\nexport async function navigateTree(this: AgentSession, \n\ttargetId: string,\n\toptions: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string } = {},\n): Promise<{ editorText?: string; cancelled: boolean; aborted?: boolean; summaryEntry?: BranchSummaryEntry }> {\n\tconst oldLeafId = this.sessionManager.getLeafId();\n\n\t// No-op if already at target\n\tif (targetId === oldLeafId) {\n\t\treturn { cancelled: false };\n\t}\n\n\t// Model required for summarization\n\tif (options.summarize && !this.model) {\n\t\tthrow new Error(\"No model available for summarization\");\n\t}\n\n\tconst targetEntry = this.sessionManager.getEntry(targetId);\n\tif (!targetEntry) {\n\t\tthrow new Error(`Entry ${targetId} not found`);\n\t}\n\n\t// Collect entries to summarize (from old leaf to common ancestor)\n\tconst { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(\n\t\tthis.sessionManager,\n\t\toldLeafId,\n\t\ttargetId,\n\t);\n\n\t// Prepare event data - mutable so extensions can override\n\tlet customInstructions = options.customInstructions;\n\tlet replaceInstructions = options.replaceInstructions;\n\tlet label = options.label;\n\n\tconst preparation: TreePreparation = {\n\t\ttargetId,\n\t\toldLeafId,\n\t\tcommonAncestorId,\n\t\tentriesToSummarize,\n\t\tuserWantsSummary: options.summarize ?? false,\n\t\tcustomInstructions,\n\t\treplaceInstructions,\n\t\tlabel,\n\t};\n\n\t// Set up abort controller for summarization\n\tthis._branchSummaryAbortController = new AbortController();\n\n\ttry {\n\t\tlet extensionSummary: { summary: string; details?: unknown } | undefined;\n\t\tlet fromExtension = false;\n\n\t\t// Emit session_before_tree event\n\t\tif (this._extensionRunner.hasHandlers(\"session_before_tree\")) {\n\t\t\tconst result = (await this._extensionRunner.emit({\n\t\t\t\ttype: \"session_before_tree\",\n\t\t\t\tpreparation,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t})) as SessionBeforeTreeResult | undefined;\n\n\t\t\tif (result?.cancel) {\n\t\t\t\treturn { cancelled: true };\n\t\t\t}\n\n\t\t\tif (result?.summary && options.summarize) {\n\t\t\t\textensionSummary = result.summary;\n\t\t\t\tfromExtension = true;\n\t\t\t}\n\n\t\t\t// Allow extensions to override instructions and label\n\t\t\tif (result?.customInstructions !== undefined) {\n\t\t\t\tcustomInstructions = result.customInstructions;\n\t\t\t}\n\t\t\tif (result?.replaceInstructions !== undefined) {\n\t\t\t\treplaceInstructions = result.replaceInstructions;\n\t\t\t}\n\t\t\tif (result?.label !== undefined) {\n\t\t\t\tlabel = result.label;\n\t\t\t}\n\t\t}\n\n\t\t// Run default summarizer if needed\n\t\tlet summaryText: string | undefined;\n\t\tlet summaryDetails: unknown;\n\t\tif (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {\n\t\t\tconst model = this.model!;\n\t\t\tconst { apiKey, headers } = await this._getRequiredRequestAuth(model);\n\t\t\tconst branchSummarySettings = this.settingsManager.getBranchSummarySettings();\n\t\t\tconst result = await generateBranchSummary(entriesToSummarize, {\n\t\t\t\tmodel,\n\t\t\t\tapiKey,\n\t\t\t\theaders,\n\t\t\t\tsignal: this._branchSummaryAbortController.signal,\n\t\t\t\tcustomInstructions,\n\t\t\t\treplaceInstructions,\n\t\t\t\treserveTokens: branchSummarySettings.reserveTokens,\n\t\t\t\tstreamFn: this.agent.streamFn,\n\t\t\t});\n\t\t\tif (result.aborted) {\n\t\t\t\treturn { cancelled: true, aborted: true };\n\t\t\t}\n\t\t\tif (result.error) {\n\t\t\t\tthrow new Error(result.error);\n\t\t\t}\n\t\t\tsummaryText = result.summary;\n\t\t\tsummaryDetails = {\n\t\t\t\treadFiles: result.readFiles || [],\n\t\t\t\tmodifiedFiles: result.modifiedFiles || [],\n\t\t\t};\n\t\t} else if (extensionSummary) {\n\t\t\tsummaryText = extensionSummary.summary;\n\t\t\tsummaryDetails = extensionSummary.details;\n\t\t}\n\n\t\t// Determine the new leaf position based on target type\n\t\tlet newLeafId: string | null;\n\t\tlet editorText: string | undefined;\n\n\t\tif (targetEntry.type === \"message\" && targetEntry.message.role === \"user\") {\n\t\t\t// User message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText = this._extractUserMessageText(targetEntry.message.content);\n\t\t} else if (targetEntry.type === \"custom_message\") {\n\t\t\t// Custom message: leaf = parent (null if root), text goes to editor\n\t\t\tnewLeafId = targetEntry.parentId;\n\t\t\teditorText =\n\t\t\t\ttypeof targetEntry.content === \"string\"\n\t\t\t\t\t? targetEntry.content\n\t\t\t\t\t: targetEntry.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t} else {\n\t\t\t// Non-user message: leaf = selected node\n\t\t\tnewLeafId = targetId;\n\t\t}\n\n\t\t// Switch leaf (with or without summary)\n\t\t// Summary is attached at the navigation target position (newLeafId), not the old branch\n\t\tlet summaryEntry: BranchSummaryEntry | undefined;\n\t\tif (summaryText) {\n\t\t\t// Create summary at target position (can be null for root)\n\t\t\tconst summaryId = this.sessionManager.branchWithSummary(\n\t\t\t\tnewLeafId,\n\t\t\t\tsummaryText,\n\t\t\t\tsummaryDetails,\n\t\t\t\tfromExtension,\n\t\t\t);\n\t\t\tsummaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;\n\n\t\t\t// Attach label to the summary entry\n\t\t\tif (label) {\n\t\t\t\tthis.sessionManager.appendLabelChange(summaryId, label);\n\t\t\t}\n\t\t} else if (newLeafId === null) {\n\t\t\t// No summary, navigating to root - reset leaf\n\t\t\tthis.sessionManager.resetLeaf();\n\t\t} else {\n\t\t\t// No summary, navigating to non-root\n\t\t\tthis.sessionManager.branch(newLeafId);\n\t\t}\n\n\t\t// Attach label to target entry when not summarizing (no summary entry to label)\n\t\tif (label && !summaryText) {\n\t\t\tthis.sessionManager.appendLabelChange(targetId, label);\n\t\t}\n\n\t\t// Update agent state\n\t\tconst sessionContext = this.sessionManager.buildSessionContext();\n\t\tthis.agent.state.messages = sessionContext.messages;\n\t\tthis._applyContextWindowReplay(sessionContext.contextWindow);\n\n\t\t// Emit session_tree event\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_tree\",\n\t\t\tnewLeafId: this.sessionManager.getLeafId(),\n\t\t\toldLeafId,\n\t\t\tsummaryEntry,\n\t\t\tfromExtension: summaryText ? fromExtension : undefined,\n\t\t});\n\n\t\t// Emit to custom tools\n\n\t\treturn { editorText, cancelled: false, summaryEntry };\n\t} finally {\n\t\tthis._branchSummaryAbortController = undefined;\n\t}\n}\n\n/**\n * Get all user messages from session for fork selector.\n */\n\nexport function getUserMessagesForForking(this: AgentSession): Array<{ entryId: string; text: string }> {\n\tconst entries = this.sessionManager.getEntries();\n\tconst result: Array<{ entryId: string; text: string }> = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role !== \"user\") continue;\n\n\t\tconst text = this._extractUserMessageText(entry.message.content);\n\t\tif (text) {\n\t\t\tresult.push({ entryId: entry.id, text });\n\t\t}\n\t}\n\n\treturn result;\n}\n\n\nexport function _extractUserMessageText(this: AgentSession, content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\treturn content\n\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t.map((c) => c.text)\n\t\t\t.join(\"\");\n\t}\n\treturn \"\";\n}\n\n/**\n * Get session statistics.\n */\n\nexport const agentSessionTreeMethods = {\n\tsetSessionName,\n\tnavigateTree,\n\tgetUserMessagesForForking,\n\t_extractUserMessageText,\n};\n"]}
|
|
@@ -75,6 +75,7 @@ export declare class AgentSession {
|
|
|
75
75
|
protected _toolPromptGuidelines: Map<string, string[]>;
|
|
76
76
|
protected _baseSystemPrompt: string;
|
|
77
77
|
protected _baseSystemPromptOptions: BuildSystemPromptOptions;
|
|
78
|
+
protected _systemPromptOverride?: string;
|
|
78
79
|
protected _lastAssistantMessage: AssistantMessage | undefined;
|
|
79
80
|
constructor(config: AgentSessionConfig);
|
|
80
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session.d.ts","sourceRoot":"","sources":["../../src/core/agent-session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAA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AG,SAAS,CAAa;IAE1E,YAAY,MAAM,EAAE,kBAAkB,EAyBrC;CACD;AAED,MAAM,WAAW,YAAa,SAAQ,yBAAyB;CAAG","sourcesContent":["/**\n * AgentSession - Core abstraction for agent lifecycle and session management.\n *\n * The historical import path is preserved here as a facade. Responsibilities are\n * implemented in sibling modules by lifecycle area so each authored source file\n * stays below the repository file-length gate.\n */\n\nimport type {\n\tAgent,\n\tAgentTool,\n\tThinkingLevel,\n} from \"@earendil-works/pi-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport type { BuildSystemPromptOptions } from \"./system-prompt.ts\";\nimport { installAgentSessionAccessors } from \"./agent-session-accessors.ts\";\nimport { agentSessionAutoCompactionMethods } from \"./agent-session-auto-compaction.ts\";\nimport { agentSessionBashMethods } from \"./agent-session-bash.ts\";\nimport { agentSessionCompactionMethods } from \"./agent-session-compaction.ts\";\nimport { agentSessionEventsMethods } from \"./agent-session-events.ts\";\nimport { agentSessionExportMethods } from \"./agent-session-export.ts\";\nimport { agentSessionExtensionBindingsMethods } from \"./agent-session-extension-bindings.ts\";\nimport type { AgentSessionInternalSurface, AgentSessionPublicSurface } from \"./agent-session-methods.ts\";\nimport { agentSessionMessageQueueMethods } from \"./agent-session-message-queue.ts\";\nimport { agentSessionModelsMethods } from \"./agent-session-models.ts\";\nimport { agentSessionPromptMethods } from \"./agent-session-prompt.ts\";\nimport { agentSessionRetryMethods } from \"./agent-session-retry.ts\";\nimport { agentSessionStateMethods } from \"./agent-session-state.ts\";\nimport { agentSessionToolHooksMethods } from \"./agent-session-tool-hooks.ts\";\nimport { agentSessionToolRegistryMethods } from \"./agent-session-tool-registry.ts\";\nimport { agentSessionTreeMethods } from \"./agent-session-tree.ts\";\nimport type {\n\tAgentSessionConfig,\n\tAgentSessionEventListener,\n\tInterruptQueueHold,\n\tToolDefinitionEntry,\n} from \"./agent-session-types.ts\";\nimport type {\n\tExtensionCommandContextActions,\n\tExtensionErrorListener,\n\tExtensionMode,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tOrchestrationContext,\n\tSessionStartEvent,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\n\nexport type {\n\tAgentSessionConfig,\n\tAgentSessionEvent,\n\tAgentSessionEventListener,\n\tExtensionBindings,\n\tModelCycleResult,\n\tPromptOptions,\n\tSessionStats,\n} from \"./agent-session-types.ts\";\nexport { parseSkillBlock } from \"./agent-session-skill-block.ts\";\nexport type { ParsedSkillBlock } from \"./agent-session-skill-block.ts\";\n\nexport class AgentSession {\n\treadonly agent: Agent;\n\treadonly sessionManager: SessionManager;\n\treadonly settingsManager: SettingsManager;\n\n\tprotected _scopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\tprotected _unsubscribeAgent?: () => void;\n\tprotected _eventListeners: AgentSessionEventListener[] = [];\n\tprotected _agentEventQueue: Promise<void> = Promise.resolve();\n\tprotected _steeringMessages: string[] = [];\n\tprotected _followUpMessages: string[] = [];\n\tprotected _interruptDeliveryQueue: Promise<void> = Promise.resolve();\n\tprotected _pendingInterruptDeliveries = 0;\n\tprotected _activeInterruptQueueHold: InterruptQueueHold | undefined = undefined;\n\tprotected _activeInterruptAbortMessage: string | undefined = undefined;\n\tprotected _pendingNextTurnMessages: CustomMessage[] = [];\n\tprotected _compactionAbortController: AbortController | undefined = undefined;\n\tprotected _autoCompactionAbortController: AbortController | undefined = undefined;\n\tprotected _overflowRecoveryAttempted = false;\n\tprotected _branchSummaryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAttempt = 0;\n\tprotected _retryPromise: Promise<void> | undefined = undefined;\n\tprotected _retryResolve: (() => void) | undefined = undefined;\n\tprotected _bashAbortController: AbortController | undefined = undefined;\n\tprotected _pendingBashMessages: BashExecutionMessage[] = [];\n\tprotected _extensionRunner!: ExtensionRunner;\n\tprotected _turnIndex = 0;\n\tprotected _resourceLoader: ResourceLoader;\n\tprotected _customTools: ToolDefinition[];\n\tprotected _baseToolDefinitions: Map<string, ToolDefinition> = new Map();\n\tprotected _cwd: string;\n\tprotected _extensionRunnerRef?: { current?: ExtensionRunner };\n\tprotected _initialActiveToolNames?: string[];\n\tprotected _allowedToolNames?: Set<string>;\n\tprotected _excludedToolNames?: Set<string>;\n\tprotected _baseToolsOverride?: Record<string, AgentTool>;\n\tprotected _sessionStartEvent: SessionStartEvent;\n\tprotected _orchestrationContext?: OrchestrationContext;\n\tprotected _extensionUIContext?: ExtensionUIContext;\n\tprotected _extensionMode: ExtensionMode = \"print\";\n\tprotected _extensionCommandContextActions?: ExtensionCommandContextActions;\n\tprotected _extensionShutdownHandler?: () => void;\n\tprotected _extensionErrorListener?: ExtensionErrorListener;\n\tprotected _extensionErrorUnsubscriber?: () => void;\n\tprotected _modelRegistry: ModelRegistry;\n\tprotected _toolRegistry: Map<string, AgentTool> = new Map();\n\tprotected _toolDefinitions: Map<string, ToolDefinitionEntry> = new Map();\n\tprotected _toolPromptSnippets: Map<string, string> = new Map();\n\tprotected _toolPromptGuidelines: Map<string, string[]> = new Map();\n\tprotected _baseSystemPrompt = \"\";\n\tprotected _baseSystemPromptOptions!: BuildSystemPromptOptions;\n\tprotected _lastAssistantMessage: AssistantMessage | undefined = undefined;\n\n\tconstructor(config: AgentSessionConfig) {\n\t\tthis.agent = config.agent;\n\t\tthis.sessionManager = config.sessionManager;\n\t\tthis.settingsManager = config.settingsManager;\n\t\tthis._scopedModels = config.scopedModels ?? [];\n\t\tthis._resourceLoader = config.resourceLoader;\n\t\tthis._customTools = config.customTools ?? [];\n\t\tthis._cwd = config.cwd;\n\t\tthis._modelRegistry = config.modelRegistry;\n\t\tthis._extensionRunnerRef = config.extensionRunnerRef;\n\t\tthis._initialActiveToolNames = config.initialActiveToolNames;\n\t\tthis._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;\n\t\tthis._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;\n\t\tthis._baseToolsOverride = config.baseToolsOverride;\n\t\tthis._sessionStartEvent = config.sessionStartEvent ?? { type: \"session_start\", reason: \"startup\" };\n\t\tthis._orchestrationContext = config.orchestrationContext;\n\n\t\tconst internals = this as unknown as AgentSessionInternalSurface;\n\t\tinternals._handleAgentEvent = internals._handleAgentEvent.bind(this);\n\t\tthis._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);\n\t\tinternals._installAgentToolHooks();\n\t\tinternals._buildRuntime({\n\t\t\tactiveToolNames: this._initialActiveToolNames,\n\t\t\tincludeAllExtensionTools: true,\n\t\t});\n\t}\n}\n\nexport interface AgentSession extends AgentSessionPublicSurface {}\n\ninstallAgentSessionAccessors(AgentSession.prototype as unknown as AgentSessionInternalSurface);\nObject.assign(\n\tAgentSession.prototype,\n\tagentSessionToolHooksMethods,\n\tagentSessionEventsMethods,\n\tagentSessionStateMethods,\n\tagentSessionPromptMethods,\n\tagentSessionMessageQueueMethods,\n\tagentSessionModelsMethods,\n\tagentSessionCompactionMethods,\n\tagentSessionAutoCompactionMethods,\n\tagentSessionExtensionBindingsMethods,\n\tagentSessionToolRegistryMethods,\n\tagentSessionRetryMethods,\n\tagentSessionBashMethods,\n\tagentSessionTreeMethods,\n\tagentSessionExportMethods,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session.d.ts","sourceRoot":"","sources":["../../src/core/agent-session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,KAAK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SAAS,CAAC,iBAAiB,SAAM;IACjC,SAAS,CAAC,wBAAwB,EAAG,wBAAwB,CAAC;IAC9D,SAAS,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACzC,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,GAAG,SAAS,CAAa;IAE1E,YAAY,MAAM,EAAE,kBAAkB,EA0BrC;CACD;AAED,MAAM,WAAW,YAAa,SAAQ,yBAAyB;CAAG","sourcesContent":["/**\n * AgentSession - Core abstraction for agent lifecycle and session management.\n *\n * The historical import path is preserved here as a facade. Responsibilities are\n * implemented in sibling modules by lifecycle area so each authored source file\n * stays below the repository file-length gate.\n */\n\nimport type {\n\tAgent,\n\tAgentTool,\n\tThinkingLevel,\n} from \"@earendil-works/pi-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport type { BuildSystemPromptOptions } from \"./system-prompt.ts\";\nimport { installAgentSessionAccessors } from \"./agent-session-accessors.ts\";\nimport { agentSessionAutoCompactionMethods } from \"./agent-session-auto-compaction.ts\";\nimport { agentSessionBashMethods } from \"./agent-session-bash.ts\";\nimport { agentSessionCompactionMethods } from \"./agent-session-compaction.ts\";\nimport { agentSessionEventsMethods } from \"./agent-session-events.ts\";\nimport { agentSessionExportMethods } from \"./agent-session-export.ts\";\nimport { agentSessionExtensionBindingsMethods } from \"./agent-session-extension-bindings.ts\";\nimport type { AgentSessionInternalSurface, AgentSessionPublicSurface } from \"./agent-session-methods.ts\";\nimport { agentSessionMessageQueueMethods } from \"./agent-session-message-queue.ts\";\nimport { agentSessionModelsMethods } from \"./agent-session-models.ts\";\nimport { agentSessionPromptMethods } from \"./agent-session-prompt.ts\";\nimport { agentSessionRetryMethods } from \"./agent-session-retry.ts\";\nimport { agentSessionStateMethods } from \"./agent-session-state.ts\";\nimport { agentSessionToolHooksMethods } from \"./agent-session-tool-hooks.ts\";\nimport { agentSessionToolRegistryMethods } from \"./agent-session-tool-registry.ts\";\nimport { agentSessionTreeMethods } from \"./agent-session-tree.ts\";\nimport type {\n\tAgentSessionConfig,\n\tAgentSessionEventListener,\n\tInterruptQueueHold,\n\tToolDefinitionEntry,\n} from \"./agent-session-types.ts\";\nimport type {\n\tExtensionCommandContextActions,\n\tExtensionErrorListener,\n\tExtensionMode,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tOrchestrationContext,\n\tSessionStartEvent,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\n\nexport type {\n\tAgentSessionConfig,\n\tAgentSessionEvent,\n\tAgentSessionEventListener,\n\tExtensionBindings,\n\tModelCycleResult,\n\tPromptOptions,\n\tSessionStats,\n} from \"./agent-session-types.ts\";\nexport { parseSkillBlock } from \"./agent-session-skill-block.ts\";\nexport type { ParsedSkillBlock } from \"./agent-session-skill-block.ts\";\n\nexport class AgentSession {\n\treadonly agent: Agent;\n\treadonly sessionManager: SessionManager;\n\treadonly settingsManager: SettingsManager;\n\n\tprotected _scopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\tprotected _unsubscribeAgent?: () => void;\n\tprotected _eventListeners: AgentSessionEventListener[] = [];\n\tprotected _agentEventQueue: Promise<void> = Promise.resolve();\n\tprotected _steeringMessages: string[] = [];\n\tprotected _followUpMessages: string[] = [];\n\tprotected _interruptDeliveryQueue: Promise<void> = Promise.resolve();\n\tprotected _pendingInterruptDeliveries = 0;\n\tprotected _activeInterruptQueueHold: InterruptQueueHold | undefined = undefined;\n\tprotected _activeInterruptAbortMessage: string | undefined = undefined;\n\tprotected _pendingNextTurnMessages: CustomMessage[] = [];\n\tprotected _compactionAbortController: AbortController | undefined = undefined;\n\tprotected _autoCompactionAbortController: AbortController | undefined = undefined;\n\tprotected _overflowRecoveryAttempted = false;\n\tprotected _branchSummaryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAttempt = 0;\n\tprotected _retryPromise: Promise<void> | undefined = undefined;\n\tprotected _retryResolve: (() => void) | undefined = undefined;\n\tprotected _bashAbortController: AbortController | undefined = undefined;\n\tprotected _pendingBashMessages: BashExecutionMessage[] = [];\n\tprotected _extensionRunner!: ExtensionRunner;\n\tprotected _turnIndex = 0;\n\tprotected _resourceLoader: ResourceLoader;\n\tprotected _customTools: ToolDefinition[];\n\tprotected _baseToolDefinitions: Map<string, ToolDefinition> = new Map();\n\tprotected _cwd: string;\n\tprotected _extensionRunnerRef?: { current?: ExtensionRunner };\n\tprotected _initialActiveToolNames?: string[];\n\tprotected _allowedToolNames?: Set<string>;\n\tprotected _excludedToolNames?: Set<string>;\n\tprotected _baseToolsOverride?: Record<string, AgentTool>;\n\tprotected _sessionStartEvent: SessionStartEvent;\n\tprotected _orchestrationContext?: OrchestrationContext;\n\tprotected _extensionUIContext?: ExtensionUIContext;\n\tprotected _extensionMode: ExtensionMode = \"print\";\n\tprotected _extensionCommandContextActions?: ExtensionCommandContextActions;\n\tprotected _extensionShutdownHandler?: () => void;\n\tprotected _extensionErrorListener?: ExtensionErrorListener;\n\tprotected _extensionErrorUnsubscriber?: () => void;\n\tprotected _modelRegistry: ModelRegistry;\n\tprotected _toolRegistry: Map<string, AgentTool> = new Map();\n\tprotected _toolDefinitions: Map<string, ToolDefinitionEntry> = new Map();\n\tprotected _toolPromptSnippets: Map<string, string> = new Map();\n\tprotected _toolPromptGuidelines: Map<string, string[]> = new Map();\n\tprotected _baseSystemPrompt = \"\";\n\tprotected _baseSystemPromptOptions!: BuildSystemPromptOptions;\n\tprotected _systemPromptOverride?: string;\n\tprotected _lastAssistantMessage: AssistantMessage | undefined = undefined;\n\n\tconstructor(config: AgentSessionConfig) {\n\t\tthis.agent = config.agent;\n\t\tthis.sessionManager = config.sessionManager;\n\t\tthis.settingsManager = config.settingsManager;\n\t\tthis._scopedModels = config.scopedModels ?? [];\n\t\tthis._resourceLoader = config.resourceLoader;\n\t\tthis._customTools = config.customTools ?? [];\n\t\tthis._cwd = config.cwd;\n\t\tthis._modelRegistry = config.modelRegistry;\n\t\tthis._extensionRunnerRef = config.extensionRunnerRef;\n\t\tthis._initialActiveToolNames = config.initialActiveToolNames;\n\t\tthis._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;\n\t\tthis._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;\n\t\tthis._baseToolsOverride = config.baseToolsOverride;\n\t\tthis._sessionStartEvent = config.sessionStartEvent ?? { type: \"session_start\", reason: \"startup\" };\n\t\tthis._orchestrationContext = config.orchestrationContext;\n\n\t\tconst internals = this as unknown as AgentSessionInternalSurface;\n\t\tinternals._handleAgentEvent = internals._handleAgentEvent.bind(this);\n\t\tthis._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);\n\t\tinternals._installAgentToolHooks();\n\t\tinternals._installAgentNextTurnRefresh();\n\t\tinternals._buildRuntime({\n\t\t\tactiveToolNames: this._initialActiveToolNames,\n\t\t\tincludeAllExtensionTools: true,\n\t\t});\n\t}\n}\n\nexport interface AgentSession extends AgentSessionPublicSurface {}\n\ninstallAgentSessionAccessors(AgentSession.prototype as unknown as AgentSessionInternalSurface);\nObject.assign(\n\tAgentSession.prototype,\n\tagentSessionToolHooksMethods,\n\tagentSessionEventsMethods,\n\tagentSessionStateMethods,\n\tagentSessionPromptMethods,\n\tagentSessionMessageQueueMethods,\n\tagentSessionModelsMethods,\n\tagentSessionCompactionMethods,\n\tagentSessionAutoCompactionMethods,\n\tagentSessionExtensionBindingsMethods,\n\tagentSessionToolRegistryMethods,\n\tagentSessionRetryMethods,\n\tagentSessionBashMethods,\n\tagentSessionTreeMethods,\n\tagentSessionExportMethods,\n);\n"]}
|
|
@@ -70,6 +70,7 @@ export class AgentSession {
|
|
|
70
70
|
internals._handleAgentEvent = internals._handleAgentEvent.bind(this);
|
|
71
71
|
this._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);
|
|
72
72
|
internals._installAgentToolHooks();
|
|
73
|
+
internals._installAgentNextTurnRefresh();
|
|
73
74
|
internals._buildRuntime({
|
|
74
75
|
activeToolNames: this._initialActiveToolNames,
|
|
75
76
|
includeAllExtensionTools: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session.js","sourceRoot":"","sources":["../../src/core/agent-session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,oCAAoC,EAAE,MAAM,uCAAuC,CAAC;AAE7F,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AA2BlE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE,MAAM,OAAO,YAAY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CAAC;YACvB,eAAe,EAAE,IAAI,CAAC,uBAAuB;YAC7C,wBAAwB,EAAE,IAAI;SAC9B,CAAC,CAAC;IACJ,CAAC;CACD;AAID,4BAA4B,CAAC,YAAY,CAAC,SAAmD,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,CACZ,YAAY,CAAC,SAAS,EACtB,4BAA4B,EAC5B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EACzB,6BAA6B,EAC7B,iCAAiC,EACjC,oCAAoC,EACpC,+BAA+B,EAC/B,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,CACzB,CAAC","sourcesContent":["/**\n * AgentSession - Core abstraction for agent lifecycle and session management.\n *\n * The historical import path is preserved here as a facade. Responsibilities are\n * implemented in sibling modules by lifecycle area so each authored source file\n * stays below the repository file-length gate.\n */\n\nimport type {\n\tAgent,\n\tAgentTool,\n\tThinkingLevel,\n} from \"@earendil-works/pi-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport type { BuildSystemPromptOptions } from \"./system-prompt.ts\";\nimport { installAgentSessionAccessors } from \"./agent-session-accessors.ts\";\nimport { agentSessionAutoCompactionMethods } from \"./agent-session-auto-compaction.ts\";\nimport { agentSessionBashMethods } from \"./agent-session-bash.ts\";\nimport { agentSessionCompactionMethods } from \"./agent-session-compaction.ts\";\nimport { agentSessionEventsMethods } from \"./agent-session-events.ts\";\nimport { agentSessionExportMethods } from \"./agent-session-export.ts\";\nimport { agentSessionExtensionBindingsMethods } from \"./agent-session-extension-bindings.ts\";\nimport type { AgentSessionInternalSurface, AgentSessionPublicSurface } from \"./agent-session-methods.ts\";\nimport { agentSessionMessageQueueMethods } from \"./agent-session-message-queue.ts\";\nimport { agentSessionModelsMethods } from \"./agent-session-models.ts\";\nimport { agentSessionPromptMethods } from \"./agent-session-prompt.ts\";\nimport { agentSessionRetryMethods } from \"./agent-session-retry.ts\";\nimport { agentSessionStateMethods } from \"./agent-session-state.ts\";\nimport { agentSessionToolHooksMethods } from \"./agent-session-tool-hooks.ts\";\nimport { agentSessionToolRegistryMethods } from \"./agent-session-tool-registry.ts\";\nimport { agentSessionTreeMethods } from \"./agent-session-tree.ts\";\nimport type {\n\tAgentSessionConfig,\n\tAgentSessionEventListener,\n\tInterruptQueueHold,\n\tToolDefinitionEntry,\n} from \"./agent-session-types.ts\";\nimport type {\n\tExtensionCommandContextActions,\n\tExtensionErrorListener,\n\tExtensionMode,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tOrchestrationContext,\n\tSessionStartEvent,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\n\nexport type {\n\tAgentSessionConfig,\n\tAgentSessionEvent,\n\tAgentSessionEventListener,\n\tExtensionBindings,\n\tModelCycleResult,\n\tPromptOptions,\n\tSessionStats,\n} from \"./agent-session-types.ts\";\nexport { parseSkillBlock } from \"./agent-session-skill-block.ts\";\nexport type { ParsedSkillBlock } from \"./agent-session-skill-block.ts\";\n\nexport class AgentSession {\n\treadonly agent: Agent;\n\treadonly sessionManager: SessionManager;\n\treadonly settingsManager: SettingsManager;\n\n\tprotected _scopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\tprotected _unsubscribeAgent?: () => void;\n\tprotected _eventListeners: AgentSessionEventListener[] = [];\n\tprotected _agentEventQueue: Promise<void> = Promise.resolve();\n\tprotected _steeringMessages: string[] = [];\n\tprotected _followUpMessages: string[] = [];\n\tprotected _interruptDeliveryQueue: Promise<void> = Promise.resolve();\n\tprotected _pendingInterruptDeliveries = 0;\n\tprotected _activeInterruptQueueHold: InterruptQueueHold | undefined = undefined;\n\tprotected _activeInterruptAbortMessage: string | undefined = undefined;\n\tprotected _pendingNextTurnMessages: CustomMessage[] = [];\n\tprotected _compactionAbortController: AbortController | undefined = undefined;\n\tprotected _autoCompactionAbortController: AbortController | undefined = undefined;\n\tprotected _overflowRecoveryAttempted = false;\n\tprotected _branchSummaryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAttempt = 0;\n\tprotected _retryPromise: Promise<void> | undefined = undefined;\n\tprotected _retryResolve: (() => void) | undefined = undefined;\n\tprotected _bashAbortController: AbortController | undefined = undefined;\n\tprotected _pendingBashMessages: BashExecutionMessage[] = [];\n\tprotected _extensionRunner!: ExtensionRunner;\n\tprotected _turnIndex = 0;\n\tprotected _resourceLoader: ResourceLoader;\n\tprotected _customTools: ToolDefinition[];\n\tprotected _baseToolDefinitions: Map<string, ToolDefinition> = new Map();\n\tprotected _cwd: string;\n\tprotected _extensionRunnerRef?: { current?: ExtensionRunner };\n\tprotected _initialActiveToolNames?: string[];\n\tprotected _allowedToolNames?: Set<string>;\n\tprotected _excludedToolNames?: Set<string>;\n\tprotected _baseToolsOverride?: Record<string, AgentTool>;\n\tprotected _sessionStartEvent: SessionStartEvent;\n\tprotected _orchestrationContext?: OrchestrationContext;\n\tprotected _extensionUIContext?: ExtensionUIContext;\n\tprotected _extensionMode: ExtensionMode = \"print\";\n\tprotected _extensionCommandContextActions?: ExtensionCommandContextActions;\n\tprotected _extensionShutdownHandler?: () => void;\n\tprotected _extensionErrorListener?: ExtensionErrorListener;\n\tprotected _extensionErrorUnsubscriber?: () => void;\n\tprotected _modelRegistry: ModelRegistry;\n\tprotected _toolRegistry: Map<string, AgentTool> = new Map();\n\tprotected _toolDefinitions: Map<string, ToolDefinitionEntry> = new Map();\n\tprotected _toolPromptSnippets: Map<string, string> = new Map();\n\tprotected _toolPromptGuidelines: Map<string, string[]> = new Map();\n\tprotected _baseSystemPrompt = \"\";\n\tprotected _baseSystemPromptOptions!: BuildSystemPromptOptions;\n\tprotected _lastAssistantMessage: AssistantMessage | undefined = undefined;\n\n\tconstructor(config: AgentSessionConfig) {\n\t\tthis.agent = config.agent;\n\t\tthis.sessionManager = config.sessionManager;\n\t\tthis.settingsManager = config.settingsManager;\n\t\tthis._scopedModels = config.scopedModels ?? [];\n\t\tthis._resourceLoader = config.resourceLoader;\n\t\tthis._customTools = config.customTools ?? [];\n\t\tthis._cwd = config.cwd;\n\t\tthis._modelRegistry = config.modelRegistry;\n\t\tthis._extensionRunnerRef = config.extensionRunnerRef;\n\t\tthis._initialActiveToolNames = config.initialActiveToolNames;\n\t\tthis._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;\n\t\tthis._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;\n\t\tthis._baseToolsOverride = config.baseToolsOverride;\n\t\tthis._sessionStartEvent = config.sessionStartEvent ?? { type: \"session_start\", reason: \"startup\" };\n\t\tthis._orchestrationContext = config.orchestrationContext;\n\n\t\tconst internals = this as unknown as AgentSessionInternalSurface;\n\t\tinternals._handleAgentEvent = internals._handleAgentEvent.bind(this);\n\t\tthis._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);\n\t\tinternals._installAgentToolHooks();\n\t\tinternals._buildRuntime({\n\t\t\tactiveToolNames: this._initialActiveToolNames,\n\t\t\tincludeAllExtensionTools: true,\n\t\t});\n\t}\n}\n\nexport interface AgentSession extends AgentSessionPublicSurface {}\n\ninstallAgentSessionAccessors(AgentSession.prototype as unknown as AgentSessionInternalSurface);\nObject.assign(\n\tAgentSession.prototype,\n\tagentSessionToolHooksMethods,\n\tagentSessionEventsMethods,\n\tagentSessionStateMethods,\n\tagentSessionPromptMethods,\n\tagentSessionMessageQueueMethods,\n\tagentSessionModelsMethods,\n\tagentSessionCompactionMethods,\n\tagentSessionAutoCompactionMethods,\n\tagentSessionExtensionBindingsMethods,\n\tagentSessionToolRegistryMethods,\n\tagentSessionRetryMethods,\n\tagentSessionBashMethods,\n\tagentSessionTreeMethods,\n\tagentSessionExportMethods,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session.js","sourceRoot":"","sources":["../../src/core/agent-session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,oCAAoC,EAAE,MAAM,uCAAuC,CAAC;AAE7F,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AA2BlE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE,MAAM,OAAO,YAAY;IAuDxB,YAAY,MAA0B;QAhD5B,oBAAe,GAAgC,EAAE,CAAC;QAClD,qBAAgB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QACpD,sBAAiB,GAAa,EAAE,CAAC;QACjC,sBAAiB,GAAa,EAAE,CAAC;QACjC,4BAAuB,GAAkB,OAAO,CAAC,OAAO,E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,MAAM,CACZ,YAAY,CAAC,SAAS,EACtB,4BAA4B,EAC5B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,EACzB,6BAA6B,EAC7B,iCAAiC,EACjC,oCAAoC,EACpC,+BAA+B,EAC/B,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,CACzB,CAAC","sourcesContent":["/**\n * AgentSession - Core abstraction for agent lifecycle and session management.\n *\n * The historical import path is preserved here as a facade. Responsibilities are\n * implemented in sibling modules by lifecycle area so each authored source file\n * stays below the repository file-length gate.\n */\n\nimport type {\n\tAgent,\n\tAgentTool,\n\tThinkingLevel,\n} from \"@earendil-works/pi-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport type { BuildSystemPromptOptions } from \"./system-prompt.ts\";\nimport { installAgentSessionAccessors } from \"./agent-session-accessors.ts\";\nimport { agentSessionAutoCompactionMethods } from \"./agent-session-auto-compaction.ts\";\nimport { agentSessionBashMethods } from \"./agent-session-bash.ts\";\nimport { agentSessionCompactionMethods } from \"./agent-session-compaction.ts\";\nimport { agentSessionEventsMethods } from \"./agent-session-events.ts\";\nimport { agentSessionExportMethods } from \"./agent-session-export.ts\";\nimport { agentSessionExtensionBindingsMethods } from \"./agent-session-extension-bindings.ts\";\nimport type { AgentSessionInternalSurface, AgentSessionPublicSurface } from \"./agent-session-methods.ts\";\nimport { agentSessionMessageQueueMethods } from \"./agent-session-message-queue.ts\";\nimport { agentSessionModelsMethods } from \"./agent-session-models.ts\";\nimport { agentSessionPromptMethods } from \"./agent-session-prompt.ts\";\nimport { agentSessionRetryMethods } from \"./agent-session-retry.ts\";\nimport { agentSessionStateMethods } from \"./agent-session-state.ts\";\nimport { agentSessionToolHooksMethods } from \"./agent-session-tool-hooks.ts\";\nimport { agentSessionToolRegistryMethods } from \"./agent-session-tool-registry.ts\";\nimport { agentSessionTreeMethods } from \"./agent-session-tree.ts\";\nimport type {\n\tAgentSessionConfig,\n\tAgentSessionEventListener,\n\tInterruptQueueHold,\n\tToolDefinitionEntry,\n} from \"./agent-session-types.ts\";\nimport type {\n\tExtensionCommandContextActions,\n\tExtensionErrorListener,\n\tExtensionMode,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tOrchestrationContext,\n\tSessionStartEvent,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\n\nexport type {\n\tAgentSessionConfig,\n\tAgentSessionEvent,\n\tAgentSessionEventListener,\n\tExtensionBindings,\n\tModelCycleResult,\n\tPromptOptions,\n\tSessionStats,\n} from \"./agent-session-types.ts\";\nexport { parseSkillBlock } from \"./agent-session-skill-block.ts\";\nexport type { ParsedSkillBlock } from \"./agent-session-skill-block.ts\";\n\nexport class AgentSession {\n\treadonly agent: Agent;\n\treadonly sessionManager: SessionManager;\n\treadonly settingsManager: SettingsManager;\n\n\tprotected _scopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\tprotected _unsubscribeAgent?: () => void;\n\tprotected _eventListeners: AgentSessionEventListener[] = [];\n\tprotected _agentEventQueue: Promise<void> = Promise.resolve();\n\tprotected _steeringMessages: string[] = [];\n\tprotected _followUpMessages: string[] = [];\n\tprotected _interruptDeliveryQueue: Promise<void> = Promise.resolve();\n\tprotected _pendingInterruptDeliveries = 0;\n\tprotected _activeInterruptQueueHold: InterruptQueueHold | undefined = undefined;\n\tprotected _activeInterruptAbortMessage: string | undefined = undefined;\n\tprotected _pendingNextTurnMessages: CustomMessage[] = [];\n\tprotected _compactionAbortController: AbortController | undefined = undefined;\n\tprotected _autoCompactionAbortController: AbortController | undefined = undefined;\n\tprotected _overflowRecoveryAttempted = false;\n\tprotected _branchSummaryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAbortController: AbortController | undefined = undefined;\n\tprotected _retryAttempt = 0;\n\tprotected _retryPromise: Promise<void> | undefined = undefined;\n\tprotected _retryResolve: (() => void) | undefined = undefined;\n\tprotected _bashAbortController: AbortController | undefined = undefined;\n\tprotected _pendingBashMessages: BashExecutionMessage[] = [];\n\tprotected _extensionRunner!: ExtensionRunner;\n\tprotected _turnIndex = 0;\n\tprotected _resourceLoader: ResourceLoader;\n\tprotected _customTools: ToolDefinition[];\n\tprotected _baseToolDefinitions: Map<string, ToolDefinition> = new Map();\n\tprotected _cwd: string;\n\tprotected _extensionRunnerRef?: { current?: ExtensionRunner };\n\tprotected _initialActiveToolNames?: string[];\n\tprotected _allowedToolNames?: Set<string>;\n\tprotected _excludedToolNames?: Set<string>;\n\tprotected _baseToolsOverride?: Record<string, AgentTool>;\n\tprotected _sessionStartEvent: SessionStartEvent;\n\tprotected _orchestrationContext?: OrchestrationContext;\n\tprotected _extensionUIContext?: ExtensionUIContext;\n\tprotected _extensionMode: ExtensionMode = \"print\";\n\tprotected _extensionCommandContextActions?: ExtensionCommandContextActions;\n\tprotected _extensionShutdownHandler?: () => void;\n\tprotected _extensionErrorListener?: ExtensionErrorListener;\n\tprotected _extensionErrorUnsubscriber?: () => void;\n\tprotected _modelRegistry: ModelRegistry;\n\tprotected _toolRegistry: Map<string, AgentTool> = new Map();\n\tprotected _toolDefinitions: Map<string, ToolDefinitionEntry> = new Map();\n\tprotected _toolPromptSnippets: Map<string, string> = new Map();\n\tprotected _toolPromptGuidelines: Map<string, string[]> = new Map();\n\tprotected _baseSystemPrompt = \"\";\n\tprotected _baseSystemPromptOptions!: BuildSystemPromptOptions;\n\tprotected _systemPromptOverride?: string;\n\tprotected _lastAssistantMessage: AssistantMessage | undefined = undefined;\n\n\tconstructor(config: AgentSessionConfig) {\n\t\tthis.agent = config.agent;\n\t\tthis.sessionManager = config.sessionManager;\n\t\tthis.settingsManager = config.settingsManager;\n\t\tthis._scopedModels = config.scopedModels ?? [];\n\t\tthis._resourceLoader = config.resourceLoader;\n\t\tthis._customTools = config.customTools ?? [];\n\t\tthis._cwd = config.cwd;\n\t\tthis._modelRegistry = config.modelRegistry;\n\t\tthis._extensionRunnerRef = config.extensionRunnerRef;\n\t\tthis._initialActiveToolNames = config.initialActiveToolNames;\n\t\tthis._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;\n\t\tthis._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;\n\t\tthis._baseToolsOverride = config.baseToolsOverride;\n\t\tthis._sessionStartEvent = config.sessionStartEvent ?? { type: \"session_start\", reason: \"startup\" };\n\t\tthis._orchestrationContext = config.orchestrationContext;\n\n\t\tconst internals = this as unknown as AgentSessionInternalSurface;\n\t\tinternals._handleAgentEvent = internals._handleAgentEvent.bind(this);\n\t\tthis._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);\n\t\tinternals._installAgentToolHooks();\n\t\tinternals._installAgentNextTurnRefresh();\n\t\tinternals._buildRuntime({\n\t\t\tactiveToolNames: this._initialActiveToolNames,\n\t\t\tincludeAllExtensionTools: true,\n\t\t});\n\t}\n}\n\nexport interface AgentSession extends AgentSessionPublicSurface {}\n\ninstallAgentSessionAccessors(AgentSession.prototype as unknown as AgentSessionInternalSurface);\nObject.assign(\n\tAgentSession.prototype,\n\tagentSessionToolHooksMethods,\n\tagentSessionEventsMethods,\n\tagentSessionStateMethods,\n\tagentSessionPromptMethods,\n\tagentSessionMessageQueueMethods,\n\tagentSessionModelsMethods,\n\tagentSessionCompactionMethods,\n\tagentSessionAutoCompactionMethods,\n\tagentSessionExtensionBindingsMethods,\n\tagentSessionToolRegistryMethods,\n\tagentSessionRetryMethods,\n\tagentSessionBashMethods,\n\tagentSessionTreeMethods,\n\tagentSessionExportMethods,\n);\n"]}
|
|
@@ -1,53 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* GitHub's Copilot API (CAPI) exposes distinct model limits via `GET {baseUrl}/models`:
|
|
5
|
-
*
|
|
6
|
-
* - `capabilities.limits.max_context_window_tokens` is the model's total context capacity
|
|
7
|
-
* (prompt + completion reserve).
|
|
8
|
-
* - `capabilities.limits.max_prompt_tokens` is the maximum prompt/input budget Atomic can safely
|
|
9
|
-
* fill before the provider must reserve output tokens.
|
|
10
|
-
* - `billing.token_prices.<tier>.context_max` is a prompt-token billing/selection threshold. The
|
|
11
|
-
* `default` tier is the short prompt budget (e.g. gpt-5.5 272k, Claude 200k); a
|
|
12
|
-
* `long_context` tier adds a selectable larger prompt budget (e.g. gpt-5.5 922k, Claude 936k).
|
|
13
|
-
*
|
|
14
|
-
* Atomic shows the model's full context window for the selectable long tier (the
|
|
15
|
-
* `max_context_window_tokens` total, e.g. 1_000_000/1_050_000), matching how the native `openai/*`
|
|
16
|
-
* and `anthropic/*` providers advertise these models. Because GitHub enforces a lower server-side
|
|
17
|
-
* prompt cap (`max_prompt_tokens`, e.g. 936k/922k) below that total, the prompt cap is retained as
|
|
18
|
-
* an internal effective input budget (`CopilotModelContext.maxInputTokens`) that drives compaction
|
|
19
|
-
* thresholds and the overflow-recovery guard, so the branded total can be displayed without
|
|
20
|
-
* overrunning the server limit. The default (short) tier stays at the `default` billing tier's
|
|
21
|
-
* prompt budget.
|
|
22
|
-
*
|
|
23
|
-
* This data is intentionally NOT baked into a static map: GitHub adds/removes models and retiers
|
|
24
|
-
* windows over time (e.g. a model that disappears from the catalog), so a hardcoded snapshot goes
|
|
25
|
-
* stale. Instead the catalog is fetched live (gated on the user actually having the GitHub Copilot
|
|
26
|
-
* provider) and cached on disk for a short TTL, exactly like the Copilot CLI.
|
|
27
|
-
*/
|
|
28
|
-
/** Resolved input-token context window(s) for a single Copilot model. */
|
|
1
|
+
/** GitHub Copilot CAPI model catalog parsing, active state, and disk cache. */
|
|
2
|
+
/** Resolved input-token context window(s) and optional synthesis metadata for a single Copilot model. */
|
|
29
3
|
export interface CopilotModelContext {
|
|
30
|
-
/**
|
|
31
|
-
* Base/displayed context window — shown in the footer. The default tier's `context_max`, or the
|
|
32
|
-
* model-level `max_prompt_tokens` fallback otherwise.
|
|
33
|
-
*/
|
|
34
4
|
contextWindow: number;
|
|
35
|
-
/**
|
|
36
|
-
* Selectable windows (`[default, long]`) when the model exposes a `long_context` tier larger than
|
|
37
|
-
* its default; absent for single-window models. The long entry is the model's full
|
|
38
|
-
* `max_context_window_tokens` (total capacity) when advertised, matching `openai/*` and
|
|
39
|
-
* `anthropic/*`.
|
|
40
|
-
*/
|
|
41
5
|
contextWindowOptions?: readonly number[];
|
|
42
|
-
/**
|
|
43
|
-
* Hard prompt/input cap (`max_prompt_tokens`) when it sits below the displayed long window. Used
|
|
44
|
-
* as the effective input budget for compaction thresholds and overflow recovery so the branded
|
|
45
|
-
* total can be shown without overrunning GitHub's server-side prompt limit. Absent when the
|
|
46
|
-
* displayed window already equals the input cap.
|
|
47
|
-
*/
|
|
48
6
|
maxInputTokens?: number;
|
|
7
|
+
maxTokens?: number;
|
|
8
|
+
displayName?: string;
|
|
9
|
+
vendor?: string;
|
|
10
|
+
supportedEndpoints?: readonly string[];
|
|
11
|
+
supports?: CopilotModelSupports;
|
|
12
|
+
limits?: CopilotModelLimits;
|
|
13
|
+
modelPickerEnabled?: boolean;
|
|
14
|
+
policyState?: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface CopilotModelSupports {
|
|
18
|
+
adaptiveThinking?: boolean;
|
|
19
|
+
maxThinkingBudget?: boolean;
|
|
20
|
+
minThinkingBudget?: boolean;
|
|
21
|
+
parallelToolCalls?: boolean;
|
|
22
|
+
reasoningEffort?: boolean;
|
|
23
|
+
reasoningEffortLevels?: readonly string[];
|
|
24
|
+
streaming?: boolean;
|
|
25
|
+
structuredOutputs?: boolean;
|
|
26
|
+
toolCalls?: boolean;
|
|
27
|
+
vision?: boolean;
|
|
49
28
|
}
|
|
50
|
-
/** Map of model id → resolved
|
|
29
|
+
/** Map of model id → resolved context window(s) plus optional synthesis metadata. */
|
|
51
30
|
export type CopilotModelCatalog = ReadonlyMap<string, CopilotModelContext>;
|
|
52
31
|
/** Safety fallback when a model reports neither `max_prompt_tokens` nor `max_context_window_tokens`. */
|
|
53
32
|
export declare const COPILOT_CONTEXT_WINDOW_FALLBACK = 128000;
|
|
@@ -72,39 +51,15 @@ export declare function copilotTokenFromEnvironment(env?: CopilotEnvironment): s
|
|
|
72
51
|
/** Disk-cache freshness window, matching the Copilot CLI's list-models cache TTL. */
|
|
73
52
|
export declare const COPILOT_CATALOG_CACHE_TTL_MS: number;
|
|
74
53
|
/** Current on-disk cache schema version. */
|
|
75
|
-
export declare const COPILOT_CATALOG_CACHE_VERSION:
|
|
76
|
-
/**
|
|
77
|
-
* Resolve the Copilot CAPI base URL.
|
|
78
|
-
*
|
|
79
|
-
* Copilot access tokens embed a `proxy-ep=proxy.<host>` segment; the API host is the same host with
|
|
80
|
-
* `proxy.` swapped for `api.`. Env-token routing resolves explicit `COPILOT_API_TARGET` /
|
|
81
|
-
* `GITHUB_COPILOT_BASE_URL` overrides, then `GITHUB_SERVER_URL` (`*.ghe.com` ->
|
|
82
|
-
* `copilot-api.<tenant>.ghe.com`, other non-github.com -> `api.enterprise.githubcopilot.com`),
|
|
83
|
-
* then the public Copilot routing hub `api.githubcopilot.com` for `COPILOT_GITHUB_TOKEN`. Stored
|
|
84
|
-
* OAuth credentials still fall back to the generated individual host when no token route is known.
|
|
85
|
-
*/
|
|
54
|
+
export declare const COPILOT_CATALOG_CACHE_VERSION: 5;
|
|
86
55
|
export declare function copilotApiBaseUrlFromToken(token: string | undefined, enterpriseDomain?: string, env?: CopilotEnvironment): string;
|
|
87
|
-
/** Raw token limits parsed from a CAPI model entry. */
|
|
88
56
|
export interface CopilotModelLimits {
|
|
89
|
-
/** `capabilities.limits.max_prompt_tokens` — maximum prompt/input budget (the hard input cap). */
|
|
90
57
|
maxPromptTokens?: number;
|
|
91
|
-
/** `capabilities.limits.max_context_window_tokens` — total context capacity (the displayed long tier). */
|
|
92
58
|
maxContextWindowTokens?: number;
|
|
93
|
-
/** `capabilities.limits.max_output_tokens` — output reserve; derives the input cap when `max_prompt_tokens` is absent. */
|
|
94
59
|
maxOutputTokens?: number;
|
|
95
|
-
/** `billing.token_prices.default.context_max` — default-tier prompt threshold. */
|
|
96
60
|
defaultContextMax?: number;
|
|
97
|
-
/** `billing.token_prices.long_context.context_max` — long-context prompt threshold. */
|
|
98
61
|
longContextMax?: number;
|
|
99
62
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Resolve a model's input-token context window(s) from its CAPI limits.
|
|
102
|
-
*
|
|
103
|
-
* `contextWindow` is the model's base input budget — the default tier's `context_max` when tiered,
|
|
104
|
-
* otherwise `max_prompt_tokens ?? max_context_window_tokens ?? 128_000`. A `long_context` tier that
|
|
105
|
-
* is larger than the base adds a second selectable window. Returns `undefined` when the entry
|
|
106
|
-
* carries no usable limit signal at all.
|
|
107
|
-
*/
|
|
108
63
|
export declare function resolveCopilotModelContext(limits: CopilotModelLimits): CopilotModelContext | undefined;
|
|
109
64
|
/**
|
|
110
65
|
* Parse a raw CAPI `/models` response body into an input-token context-window catalog.
|
|
@@ -140,13 +95,9 @@ export interface ReadCopilotCatalogCacheOptions {
|
|
|
140
95
|
/** Freshness window; defaults to {@link COPILOT_CATALOG_CACHE_TTL_MS}. */
|
|
141
96
|
ttlMs?: number;
|
|
142
97
|
}
|
|
143
|
-
/** Read a fresh, host-matching catalog from the cache file, or `undefined` if missing/stale/invalid. */
|
|
144
98
|
export declare function readCopilotCatalogCache(path: string, options: ReadCopilotCatalogCacheOptions): CopilotModelCatalog | undefined;
|
|
145
|
-
/** Write the catalog to the cache file (creating parent dirs). Best-effort; never throws. */
|
|
146
99
|
export declare function writeCopilotCatalogCache(path: string, baseUrl: string, catalog: CopilotModelCatalog, now?: number): void;
|
|
147
|
-
/** Host component of a base URL, for matching {@link readCopilotCatalogCache} `host`. */
|
|
148
100
|
export declare function copilotCatalogCacheHost(baseUrl: string): string;
|
|
149
|
-
/** Standard on-disk cache path for the Copilot model catalog under an agent directory. */
|
|
150
101
|
export declare function copilotCatalogCachePath(agentDir: string): string;
|
|
151
102
|
/**
|
|
152
103
|
* Seed the active catalog synchronously from the on-disk cache, gated on a Copilot access token.
|