@bastani/atomic 0.9.4-alpha.6 → 0.9.4-alpha.8
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 +20 -0
- package/dist/builtin/cursor/package.json +3 -3
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +14 -0
- package/dist/builtin/subagents/agents/code-simplifier.md +1 -1
- package/dist/builtin/subagents/agents/codebase-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +1 -1
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/debugger.md +1 -1
- package/dist/builtin/subagents/agents/worker.md +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- 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/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +16 -0
- package/dist/builtin/workflows/builtin/deep-research-codebase-utils.ts +8 -1
- package/dist/builtin/workflows/builtin/goal-runner.ts +14 -1
- package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +5 -2
- package/dist/builtin/workflows/builtin/ralph-models.ts +44 -9
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +34 -4
- 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 +10 -2
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -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/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/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/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/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/docs/models.md +3 -3
- package/docs/providers.md +1 -1
- package/docs/rpc.md +2 -2
- package/docs/sdk.md +1 -1
- package/docs/settings.md +2 -1
- package/docs/subagents.md +6 -0
- package/docs/workflows.md +3 -1
- package/npm-shrinkwrap.json +27 -27
- package/package.json +6 -6
|
@@ -75,17 +75,20 @@ export async function runOpenClaudeDesignWorkflow(ctx: OpenClaudeDesignContext):
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const designModelConfig = {
|
|
78
|
-
model: "anthropic/claude-fable-5:
|
|
78
|
+
model: "anthropic/claude-fable-5:high",
|
|
79
79
|
fallbackModels: [
|
|
80
80
|
"github-copilot/claude-opus-4.8 (1m):xhigh",
|
|
81
81
|
"anthropic/claude-opus-4-8:xhigh",
|
|
82
82
|
"zai/glm-5.2:xhigh",
|
|
83
83
|
"zai-coding-cn/glm-5.2:xhigh",
|
|
84
|
+
"github-copilot/claude-sonnet-5 (1m):high",
|
|
84
85
|
"github-copilot/claude-sonnet-4.6 (1m):high",
|
|
86
|
+
"anthropic/claude-sonnet-5:high",
|
|
85
87
|
"anthropic/claude-sonnet-4-6:high",
|
|
86
|
-
"openrouter/anthropic/claude-fable-5:
|
|
88
|
+
"openrouter/anthropic/claude-fable-5:high",
|
|
87
89
|
"openrouter/anthropic/claude-opus-4-8:xhigh",
|
|
88
90
|
"openrouter/z-ai/glm-5.2:xhigh",
|
|
91
|
+
"openrouter/anthropic/claude-sonnet-5:high",
|
|
89
92
|
"openrouter/anthropic/claude-sonnet-4-6:high"
|
|
90
93
|
],
|
|
91
94
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { reviewDecisionSchema } from "./ralph-core.js";
|
|
2
2
|
|
|
3
3
|
export const promptEngineerModelConfig = {
|
|
4
|
-
model: "anthropic/claude-fable-5:
|
|
4
|
+
model: "anthropic/claude-fable-5:high",
|
|
5
5
|
fallbackModels: [
|
|
6
6
|
"openai-codex/gpt-5.5:xhigh",
|
|
7
7
|
"github-copilot/gpt-5.5:xhigh",
|
|
@@ -10,16 +10,22 @@ export const promptEngineerModelConfig = {
|
|
|
10
10
|
"anthropic/claude-opus-4-8:xhigh",
|
|
11
11
|
"zai/glm-5.2:xhigh",
|
|
12
12
|
"zai-coding-cn/glm-5.2:xhigh",
|
|
13
|
+
"github-copilot/claude-sonnet-5 (1m):high",
|
|
14
|
+
"anthropic/claude-sonnet-5:high",
|
|
15
|
+
"github-copilot/claude-sonnet-4.6 (1m):high",
|
|
16
|
+
"anthropic/claude-sonnet-4-6:high",
|
|
13
17
|
"github-copilot/gemini-3.5-flash (1m):high",
|
|
14
18
|
"google/gemini-3.5-flash:high",
|
|
15
19
|
"google-vertex/gemini-3.5-flash:high",
|
|
16
20
|
"github-copilot/gemini-3.1-pro-preview (1m):high",
|
|
17
21
|
"google/gemini-3.1-pro-preview:high",
|
|
18
22
|
"google-vertex/gemini-3.1-pro-preview:high",
|
|
19
|
-
"openrouter/anthropic/claude-fable-5:
|
|
23
|
+
"openrouter/anthropic/claude-fable-5:high",
|
|
20
24
|
"openrouter/openai/gpt-5.5:xhigh",
|
|
21
25
|
"openrouter/anthropic/claude-opus-4-8:xhigh",
|
|
22
26
|
"openrouter/z-ai/glm-5.2:xhigh",
|
|
27
|
+
"openrouter/anthropic/claude-sonnet-5:high",
|
|
28
|
+
"openrouter/anthropic/claude-sonnet-4-6:high",
|
|
23
29
|
"openrouter/google/gemini-3.5-flash:high",
|
|
24
30
|
"openrouter/google/gemini-3.1-pro-preview:high"
|
|
25
31
|
],
|
|
@@ -35,6 +41,10 @@ export const researchModelConfig = {
|
|
|
35
41
|
"anthropic/claude-opus-4-8:medium",
|
|
36
42
|
"zai/glm-5.2:medium",
|
|
37
43
|
"zai-coding-cn/glm-5.2:medium",
|
|
44
|
+
"github-copilot/claude-sonnet-5 (1m):medium",
|
|
45
|
+
"anthropic/claude-sonnet-5:medium",
|
|
46
|
+
"github-copilot/claude-sonnet-4.6 (1m):medium",
|
|
47
|
+
"anthropic/claude-sonnet-4-6:medium",
|
|
38
48
|
"github-copilot/gemini-3.5-flash (1m):medium",
|
|
39
49
|
"google/gemini-3.5-flash:medium",
|
|
40
50
|
"google-vertex/gemini-3.5-flash:medium",
|
|
@@ -44,6 +54,8 @@ export const researchModelConfig = {
|
|
|
44
54
|
"openrouter/openai/gpt-5.5:medium",
|
|
45
55
|
"openrouter/anthropic/claude-opus-4-8:medium",
|
|
46
56
|
"openrouter/z-ai/glm-5.2:medium",
|
|
57
|
+
"openrouter/anthropic/claude-sonnet-5:medium",
|
|
58
|
+
"openrouter/anthropic/claude-sonnet-4-6:medium",
|
|
47
59
|
"openrouter/google/gemini-3.5-flash:medium",
|
|
48
60
|
"openrouter/google/gemini-3.1-pro-preview:medium"
|
|
49
61
|
],
|
|
@@ -59,6 +71,10 @@ export const orchestratorModelConfig = {
|
|
|
59
71
|
"anthropic/claude-opus-4-8:medium",
|
|
60
72
|
"zai/glm-5.2:medium",
|
|
61
73
|
"zai-coding-cn/glm-5.2:medium",
|
|
74
|
+
"github-copilot/claude-sonnet-5 (1m):medium",
|
|
75
|
+
"anthropic/claude-sonnet-5:medium",
|
|
76
|
+
"github-copilot/claude-sonnet-4.6 (1m):medium",
|
|
77
|
+
"anthropic/claude-sonnet-4-6:medium",
|
|
62
78
|
"github-copilot/gemini-3.5-flash (1m):medium",
|
|
63
79
|
"google/gemini-3.5-flash:medium",
|
|
64
80
|
"google-vertex/gemini-3.5-flash:medium",
|
|
@@ -68,6 +84,8 @@ export const orchestratorModelConfig = {
|
|
|
68
84
|
"openrouter/openai/gpt-5.5:medium",
|
|
69
85
|
"openrouter/anthropic/claude-opus-4-8:medium",
|
|
70
86
|
"openrouter/z-ai/glm-5.2:medium",
|
|
87
|
+
"openrouter/anthropic/claude-sonnet-5:medium",
|
|
88
|
+
"openrouter/anthropic/claude-sonnet-4-6:medium",
|
|
71
89
|
"openrouter/google/gemini-3.5-flash:medium",
|
|
72
90
|
"openrouter/google/gemini-3.1-pro-preview:medium"
|
|
73
91
|
],
|
|
@@ -75,7 +93,7 @@ export const orchestratorModelConfig = {
|
|
|
75
93
|
};
|
|
76
94
|
|
|
77
95
|
export const reviewerAModelConfig = {
|
|
78
|
-
model: "anthropic/claude-fable-5:
|
|
96
|
+
model: "anthropic/claude-fable-5:high",
|
|
79
97
|
fallbackModels: [
|
|
80
98
|
"github-copilot/claude-opus-4.8 (1m):xhigh",
|
|
81
99
|
"anthropic/claude-opus-4-8:xhigh",
|
|
@@ -84,16 +102,22 @@ export const reviewerAModelConfig = {
|
|
|
84
102
|
"openai/gpt-5.5:xhigh",
|
|
85
103
|
"zai/glm-5.2:xhigh",
|
|
86
104
|
"zai-coding-cn/glm-5.2:xhigh",
|
|
105
|
+
"github-copilot/claude-sonnet-5 (1m):high",
|
|
106
|
+
"anthropic/claude-sonnet-5:high",
|
|
107
|
+
"github-copilot/claude-sonnet-4.6 (1m):high",
|
|
108
|
+
"anthropic/claude-sonnet-4-6:high",
|
|
87
109
|
"github-copilot/gemini-3.5-flash (1m):high",
|
|
88
110
|
"google/gemini-3.5-flash:high",
|
|
89
111
|
"google-vertex/gemini-3.5-flash:high",
|
|
90
112
|
"github-copilot/gemini-3.1-pro-preview (1m):high",
|
|
91
113
|
"google/gemini-3.1-pro-preview:high",
|
|
92
114
|
"google-vertex/gemini-3.1-pro-preview:high",
|
|
93
|
-
"openrouter/anthropic/claude-fable-5:
|
|
115
|
+
"openrouter/anthropic/claude-fable-5:high",
|
|
94
116
|
"openrouter/anthropic/claude-opus-4-8:xhigh",
|
|
95
117
|
"openrouter/openai/gpt-5.5:xhigh",
|
|
96
118
|
"openrouter/z-ai/glm-5.2:xhigh",
|
|
119
|
+
"openrouter/anthropic/claude-sonnet-5:high",
|
|
120
|
+
"openrouter/anthropic/claude-sonnet-4-6:high",
|
|
97
121
|
"openrouter/google/gemini-3.5-flash:high",
|
|
98
122
|
"openrouter/google/gemini-3.1-pro-preview:high"
|
|
99
123
|
],
|
|
@@ -106,11 +130,15 @@ export const reviewerBModelConfig = {
|
|
|
106
130
|
fallbackModels: [
|
|
107
131
|
"github-copilot/gpt-5.5:xhigh",
|
|
108
132
|
"openai/gpt-5.5:xhigh",
|
|
109
|
-
"anthropic/claude-fable-5:
|
|
133
|
+
"anthropic/claude-fable-5:high",
|
|
110
134
|
"github-copilot/claude-opus-4.8 (1m):xhigh",
|
|
111
135
|
"anthropic/claude-opus-4-8:xhigh",
|
|
112
136
|
"zai/glm-5.2:xhigh",
|
|
113
137
|
"zai-coding-cn/glm-5.2:xhigh",
|
|
138
|
+
"github-copilot/claude-sonnet-5 (1m):high",
|
|
139
|
+
"anthropic/claude-sonnet-5:high",
|
|
140
|
+
"github-copilot/claude-sonnet-4.6 (1m):high",
|
|
141
|
+
"anthropic/claude-sonnet-4-6:high",
|
|
114
142
|
"github-copilot/gemini-3.5-flash (1m):high",
|
|
115
143
|
"google/gemini-3.5-flash:high",
|
|
116
144
|
"google-vertex/gemini-3.5-flash:high",
|
|
@@ -118,9 +146,11 @@ export const reviewerBModelConfig = {
|
|
|
118
146
|
"google/gemini-3.1-pro-preview:high",
|
|
119
147
|
"google-vertex/gemini-3.1-pro-preview:high",
|
|
120
148
|
"openrouter/openai/gpt-5.5:xhigh",
|
|
121
|
-
"openrouter/anthropic/claude-fable-5:
|
|
149
|
+
"openrouter/anthropic/claude-fable-5:high",
|
|
122
150
|
"openrouter/anthropic/claude-opus-4-8:xhigh",
|
|
123
151
|
"openrouter/z-ai/glm-5.2:xhigh",
|
|
152
|
+
"openrouter/anthropic/claude-sonnet-5:high",
|
|
153
|
+
"openrouter/anthropic/claude-sonnet-4-6:high",
|
|
124
154
|
"openrouter/google/gemini-3.5-flash:high",
|
|
125
155
|
"openrouter/google/gemini-3.1-pro-preview:high"
|
|
126
156
|
],
|
|
@@ -141,11 +171,17 @@ export const reviewerCModelConfig = {
|
|
|
141
171
|
"openai-codex/gpt-5.5:xhigh",
|
|
142
172
|
"github-copilot/gpt-5.5:xhigh",
|
|
143
173
|
"openai/gpt-5.5:xhigh",
|
|
144
|
-
"anthropic/claude-fable-5:
|
|
174
|
+
"anthropic/claude-fable-5:high",
|
|
145
175
|
"github-copilot/claude-opus-4.8 (1m):xhigh",
|
|
146
176
|
"anthropic/claude-opus-4-8:xhigh",
|
|
147
|
-
"
|
|
177
|
+
"github-copilot/claude-sonnet-5 (1m):high",
|
|
178
|
+
"anthropic/claude-sonnet-5:high",
|
|
179
|
+
"github-copilot/claude-sonnet-4.6 (1m):high",
|
|
180
|
+
"anthropic/claude-sonnet-4-6:high",
|
|
181
|
+
"openrouter/anthropic/claude-fable-5:high",
|
|
148
182
|
"openrouter/anthropic/claude-opus-4-8:xhigh",
|
|
183
|
+
"openrouter/anthropic/claude-sonnet-5:high",
|
|
184
|
+
"openrouter/anthropic/claude-sonnet-4-6:high",
|
|
149
185
|
"openrouter/openai/gpt-5.5:xhigh",
|
|
150
186
|
"openrouter/z-ai/glm-5.2:xhigh",
|
|
151
187
|
"openrouter/google/gemini-3.5-flash:high",
|
|
@@ -154,4 +190,3 @@ export const reviewerCModelConfig = {
|
|
|
154
190
|
excludedTools: ["ask_user_question"],
|
|
155
191
|
schema: reviewDecisionSchema,
|
|
156
192
|
};
|
|
157
|
-
|
|
@@ -51,6 +51,7 @@ export type ModelFallbackFailureKind =
|
|
|
51
51
|
| "network_timeout"
|
|
52
52
|
| "transport_error"
|
|
53
53
|
| "model_unavailable"
|
|
54
|
+
| "request_incompatible"
|
|
54
55
|
| "cancelled"
|
|
55
56
|
| "task_failure"
|
|
56
57
|
| "unknown";
|
|
@@ -79,6 +80,7 @@ const FALLBACKABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Se
|
|
|
79
80
|
"network_timeout",
|
|
80
81
|
"transport_error",
|
|
81
82
|
"model_unavailable",
|
|
83
|
+
"request_incompatible",
|
|
82
84
|
]);
|
|
83
85
|
|
|
84
86
|
function asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
@@ -157,6 +159,9 @@ function normalizeCode(value: string | number | undefined): string | undefined {
|
|
|
157
159
|
|
|
158
160
|
function kindFromStatus(status: number | undefined): ModelFallbackFailureKind | undefined {
|
|
159
161
|
switch (status) {
|
|
162
|
+
case 400:
|
|
163
|
+
case 413: case 422:
|
|
164
|
+
return "request_incompatible";
|
|
160
165
|
case 401:
|
|
161
166
|
case 403:
|
|
162
167
|
return "auth_on_candidate_provider";
|
|
@@ -193,6 +198,15 @@ function refusalKindFromCode(code: string | number | undefined): ModelFallbackFa
|
|
|
193
198
|
}
|
|
194
199
|
}
|
|
195
200
|
|
|
201
|
+
const REQUEST_INCOMPATIBLE_CODES: ReadonlySet<string> = new Set([
|
|
202
|
+
"invalid_request", "invalid_request_error", "bad_request", "context_length_exceeded",
|
|
203
|
+
"request_too_large", "too_large", "request_entity_too_large", "max_tokens",
|
|
204
|
+
"max_context_length", "context_window_exceeded",
|
|
205
|
+
]);
|
|
206
|
+
function requestIncompatibleKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {
|
|
207
|
+
const normalizedCode = normalizeCode(code);
|
|
208
|
+
return normalizedCode !== undefined && REQUEST_INCOMPATIBLE_CODES.has(normalizedCode) ? "request_incompatible" : undefined;
|
|
209
|
+
}
|
|
196
210
|
function kindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {
|
|
197
211
|
const normalizedCode = normalizeCode(code);
|
|
198
212
|
if (normalizedCode === undefined) return undefined;
|
|
@@ -200,6 +214,8 @@ function kindFromCode(code: string | number | undefined): ModelFallbackFailureKi
|
|
|
200
214
|
if (refusalKind !== undefined) return refusalKind;
|
|
201
215
|
const httpStatusKind = kindFromStatus(integerFrom(code));
|
|
202
216
|
if (httpStatusKind !== undefined) return httpStatusKind;
|
|
217
|
+
const requestIncompatibleKind = requestIncompatibleKindFromCode(code);
|
|
218
|
+
if (requestIncompatibleKind !== undefined) return requestIncompatibleKind;
|
|
203
219
|
|
|
204
220
|
switch (normalizedCode) {
|
|
205
221
|
case "auth":
|
|
@@ -248,6 +264,18 @@ function kindFromCode(code: string | number | undefined): ModelFallbackFailureKi
|
|
|
248
264
|
}
|
|
249
265
|
}
|
|
250
266
|
|
|
267
|
+
const REQUEST_INCOMPATIBLE_FAILURE_PATTERNS: readonly RegExp[] = [
|
|
268
|
+
/\bcontext[_\s-]?length(?:[_\s-]?exceeded)?\b/i,
|
|
269
|
+
/\bcontext[_\s-]?window(?:[_\s-]?exceeded)?\b/i,
|
|
270
|
+
/\bmax[_\s-]?context\b/i,
|
|
271
|
+
/\bmax[_\s-]?tokens?\b/i,
|
|
272
|
+
/\brequest(?:[_\s-]?entity)?[_\s-]?too[_\s-]?large\b/i,
|
|
273
|
+
/\btoo[_\s-]?large\b/i,
|
|
274
|
+
/\b(?:unsupported|unknown|invalid)\s+(?:tool|parameter|function)\b/i,
|
|
275
|
+
/\b(?:tool|parameter|function)\s+(?:not\s+(?:supported|found|allowed)|unknown|invalid)\b/i,
|
|
276
|
+
/\binvalid[_\s-]?request(?:[_\s-]?error)?\b/i,
|
|
277
|
+
/\bbad[_\s-]?request\b/i,
|
|
278
|
+
];
|
|
251
279
|
const PROVIDER_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [
|
|
252
280
|
/\bfinish[_\s-]?reason\b[^\n]*\bcontent[_\s-]?filter\b/i,
|
|
253
281
|
/\bcontent[_\s-]?filter(?:ed|ing)?\b/i,
|
|
@@ -283,6 +311,7 @@ function fallbackKindFromMessage(message: string, name: string | undefined): Mod
|
|
|
283
311
|
if (refusalKind !== undefined) return refusalKind;
|
|
284
312
|
const transportOutageKind = transportOutageKindFromMessage(message);
|
|
285
313
|
if (transportOutageKind !== undefined) return transportOutageKind;
|
|
314
|
+
if (REQUEST_INCOMPATIBLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return "request_incompatible";
|
|
286
315
|
const nameKind = kindFromCode(name);
|
|
287
316
|
if (nameKind !== undefined) return nameKind;
|
|
288
317
|
if (!RETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return undefined;
|
|
@@ -371,9 +400,6 @@ function structuredSignal(
|
|
|
371
400
|
const directRefusalSignal = classifyAssistantRefusalSignal(value, source);
|
|
372
401
|
if (directRefusalSignal !== undefined) return directRefusalSignal;
|
|
373
402
|
|
|
374
|
-
const directMessageSignal = fallbackSignalFromDirectMessage(value, source);
|
|
375
|
-
if (directMessageSignal !== undefined) return directMessageSignal;
|
|
376
|
-
|
|
377
403
|
const codeKind = kindFromCode(codeFrom(value));
|
|
378
404
|
const nameKind = kindFromCode(errorName(value));
|
|
379
405
|
if (codeKind === "cancelled" || nameKind === "cancelled") return makeSignal("cancelled", value, source);
|
|
@@ -387,7 +413,6 @@ function structuredSignal(
|
|
|
387
413
|
if (isRefusalSignal(diagnosticSignal)) return diagnosticSignal;
|
|
388
414
|
firstNestedFallbackSignal ??= diagnosticSignal;
|
|
389
415
|
}
|
|
390
|
-
|
|
391
416
|
const cause = causeOf(value);
|
|
392
417
|
const causeSignal = structuredSignal(cause, nestedSeen, source)
|
|
393
418
|
?? fallbackSignalFromMessage(cause, source);
|
|
@@ -396,6 +421,11 @@ function structuredSignal(
|
|
|
396
421
|
firstNestedFallbackSignal ??= causeSignal;
|
|
397
422
|
}
|
|
398
423
|
|
|
424
|
+
// Direct-message classification runs after nested traversal so a generic wrapper
|
|
425
|
+
// ("invalid request"/"400 bad request") cannot mask a non-retryable nested signal.
|
|
426
|
+
const directMessageSignal = fallbackSignalFromDirectMessage(value, source);
|
|
427
|
+
if (directMessageSignal !== undefined) return directMessageSignal;
|
|
428
|
+
|
|
399
429
|
const statusKind = kindFromStatus(statusFrom(value));
|
|
400
430
|
if (statusKind !== undefined) return makeSignal(statusKind, value, source);
|
|
401
431
|
if (codeKind !== undefined) return makeSignal(codeKind, value, source);
|
|
@@ -17,6 +17,7 @@ export declare function buildExtensionResourcePaths(this: AgentSession, entries:
|
|
|
17
17
|
}>;
|
|
18
18
|
export declare function getExtensionSourceLabel(this: AgentSession, extensionPath: string): string;
|
|
19
19
|
export declare function _applyExtensionBindings(this: AgentSession, runner: ExtensionRunner): void;
|
|
20
|
+
export declare function refreshCurrentModelFromRegistry(this: AgentSession): void;
|
|
20
21
|
export declare function _refreshCurrentModelFromRegistry(this: AgentSession): void;
|
|
21
22
|
export declare function _bindExtensionCore(this: AgentSession, runner: ExtensionRunner): void;
|
|
22
23
|
export declare function reload(this: AgentSession): Promise<void>;
|
|
@@ -30,6 +31,7 @@ export declare const agentSessionExtensionBindingsMethods: {
|
|
|
30
31
|
buildExtensionResourcePaths: typeof buildExtensionResourcePaths;
|
|
31
32
|
getExtensionSourceLabel: typeof getExtensionSourceLabel;
|
|
32
33
|
_applyExtensionBindings: typeof _applyExtensionBindings;
|
|
34
|
+
refreshCurrentModelFromRegistry: typeof refreshCurrentModelFromRegistry;
|
|
33
35
|
_refreshCurrentModelFromRegistry: typeof _refreshCurrentModelFromRegistry;
|
|
34
36
|
_bindExtensionCore: typeof _bindExtensionCore;
|
|
35
37
|
reload: typeof reload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-extension-bindings.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-extension-bindings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAsB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBnG;AAGD,wBAAsB,6BAA6B,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBnH;AAGD,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,KAAK,CAAC;IAC/H,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,WAAW,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxF,CAAC,CAcD;AAGD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAOzF;AAGD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAQzF;AAGD,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAiBzE;AAGD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CA+GpF;AAGD,wBAAsB,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB9D;AAMD;;;GAGG;AAEH,eAAO,MAAM,oCAAoC;;;;;;;;;CAShD,CAAC","sourcesContent":["import { basename, dirname } from \"node:path\";\nimport { resetApiProviders } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ExtensionBindings } from \"./agent-session-types.ts\";\nimport type { ExtensionRunner } from \"./extensions/index.ts\";\nimport type { ResourceExtensionPaths } from \"./resource-loader.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { SlashCommandInfo } from \"./slash-commands.ts\";\n\nexport async function bindExtensions(this: AgentSession, bindings: ExtensionBindings): Promise<void> {\n\tif (bindings.uiContext !== undefined) {\n\t\tthis._extensionUIContext = bindings.uiContext;\n\t}\n\tif (bindings.mode !== undefined) {\n\t\tthis._extensionMode = bindings.mode;\n\t}\n\tif (bindings.commandContextActions !== undefined) {\n\t\tthis._extensionCommandContextActions = bindings.commandContextActions;\n\t}\n\tif (bindings.shutdownHandler !== undefined) {\n\t\tthis._extensionShutdownHandler = bindings.shutdownHandler;\n\t}\n\tif (bindings.onError !== undefined) {\n\t\tthis._extensionErrorListener = bindings.onError;\n\t}\n\n\tthis._applyExtensionBindings(this._extensionRunner);\n\tawait this._extensionRunner.emit(this._sessionStartEvent);\n\tawait this.extendResourcesFromExtensions(this._sessionStartEvent.reason === \"reload\" ? \"reload\" : \"startup\");\n}\n\n\nexport async function extendResourcesFromExtensions(this: AgentSession, reason: \"startup\" | \"reload\"): Promise<void> {\n\tif (!this._extensionRunner.hasHandlers(\"resources_discover\")) {\n\t\treturn;\n\t}\n\n\tconst { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(\n\t\tthis._cwd,\n\t\treason,\n\t);\n\n\tif (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {\n\t\treturn;\n\t}\n\n\tconst extensionPaths: ResourceExtensionPaths = {\n\t\tskillPaths: this.buildExtensionResourcePaths(skillPaths),\n\t\tpromptPaths: this.buildExtensionResourcePaths(promptPaths),\n\t\tthemePaths: this.buildExtensionResourcePaths(themePaths),\n\t};\n\n\tthis._resourceLoader.extendResources(extensionPaths);\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n\nexport function buildExtensionResourcePaths(this: AgentSession, entries: Array<{ path: string; extensionPath: string }>): Array<{\n\tpath: string;\n\tmetadata: { source: string; scope: \"temporary\"; origin: \"top-level\"; baseDir?: string };\n}> {\n\treturn entries.map((entry) => {\n\t\tconst source = this.getExtensionSourceLabel(entry.extensionPath);\n\t\tconst baseDir = entry.extensionPath.startsWith(\"<\") ? undefined : dirname(entry.extensionPath);\n\t\treturn {\n\t\t\tpath: entry.path,\n\t\t\tmetadata: {\n\t\t\t\tsource,\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t\tbaseDir,\n\t\t\t},\n\t\t};\n\t});\n}\n\n\nexport function getExtensionSourceLabel(this: AgentSession, extensionPath: string): string {\n\tif (extensionPath.startsWith(\"<\")) {\n\t\treturn `extension:${extensionPath.replace(/[<>]/g, \"\")}`;\n\t}\n\tconst base = basename(extensionPath);\n\tconst name = base.replace(/\\.(ts|js)$/, \"\");\n\treturn `extension:${name}`;\n}\n\n\nexport function _applyExtensionBindings(this: AgentSession, runner: ExtensionRunner): void {\n\trunner.setUIContext(this._extensionUIContext, this._extensionMode);\n\trunner.bindCommandContext(this._extensionCommandContextActions);\n\n\tthis._extensionErrorUnsubscriber?.();\n\tthis._extensionErrorUnsubscriber = this._extensionErrorListener\n\t\t? runner.onError(this._extensionErrorListener)\n\t\t: undefined;\n}\n\n\nexport function _refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tconst currentModel = this.model;\n\tif (!currentModel) {\n\t\treturn;\n\t}\n\n\tconst refreshedModel = this._modelRegistry.find(currentModel.provider, currentModel.id);\n\tif (!refreshedModel || refreshedModel === currentModel) {\n\t\treturn;\n\t}\n\n\tconst replay = this._getResumeContextWindowReplayForModel(refreshedModel);\n\tthis.agent.state.model = replay.model;\n\tif (currentModel.contextWindow !== replay.contextWindow) {\n\t\tthis._emit({ type: \"context_window_changed\", contextWindow: replay.contextWindow });\n\t}\n\tthis._refreshBaseSystemPromptFromActiveTools();\n}\n\n\nexport function _bindExtensionCore(this: AgentSession, runner: ExtensionRunner): void {\n\tconst getCommands = (): SlashCommandInfo[] => {\n\t\tconst extensionCommands: SlashCommandInfo[] = runner.getRegisteredCommands().map((command) => ({\n\t\t\tname: command.invocationName,\n\t\t\tdescription: command.description,\n\t\t\tsource: \"extension\",\n\t\t\tsourceInfo: command.sourceInfo,\n\t\t}));\n\n\t\tconst templates: SlashCommandInfo[] = this.promptTemplates.map((template) => ({\n\t\t\tname: template.name,\n\t\t\tdescription: template.description,\n\t\t\tsource: \"prompt\",\n\t\t\tsourceInfo: template.sourceInfo,\n\t\t}));\n\n\t\tconst skills: SlashCommandInfo[] = this._resourceLoader.getSkills().skills.map((skill) => ({\n\t\t\tname: `skill:${skill.name}`,\n\t\t\tdescription: skill.description,\n\t\t\tsource: \"skill\",\n\t\t\tsourceInfo: skill.sourceInfo,\n\t\t}));\n\n\t\treturn [...extensionCommands, ...templates, ...skills];\n\t};\n\n\trunner.bindCore(\n\t\t{\n\t\t\tsendMessage: (message, options) => {\n\t\t\t\tthis.sendCustomMessage(message, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tsendUserMessage: (content, options) => {\n\t\t\t\tthis.sendUserMessage(content, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_user_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntry: (customType, data) => {\n\t\t\t\tthis.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tsetSessionName: (name) => {\n\t\t\t\tthis.setSessionName(name);\n\t\t\t},\n\t\t\tgetSessionName: () => {\n\t\t\t\treturn this.sessionManager.getSessionName();\n\t\t\t},\n\t\t\tsetLabel: (entryId, label) => {\n\t\t\t\tthis.sessionManager.appendLabelChange(entryId, label);\n\t\t\t},\n\t\t\tgetActiveTools: () => this.getActiveToolNames(),\n\t\t\tgetAllTools: () => this.getAllTools(),\n\t\t\tsetActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),\n\t\t\trefreshTools: () => this._refreshToolRegistry(),\n\t\t\tgetCommands,\n\t\t\tsetModel: async (model) => {\n\t\t\t\tif (!this.modelRegistry.hasConfiguredAuth(model)) return false;\n\t\t\t\tawait this.setModel(model);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tgetThinkingLevel: () => this.thinkingLevel,\n\t\t\tsetThinkingLevel: (level) => this.setThinkingLevel(level),\n\t\t},\n\t\t{\n\t\t\tgetModel: () => this.model,\n\t\t\tisIdle: () => !this.isStreaming,\n\t\t\tisProjectTrusted: () => this.settingsManager.isProjectTrusted(),\n\t\t\tgetSignal: () => this.agent.signal,\n\t\t\tabort: () => this.abort(),\n\t\t\thasPendingMessages: () => this.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis._extensionShutdownHandler?.();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.compact({\n\t\t\t\t\t\t\t...(options?.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t\t\t\t\t...(options?.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t\t\t\t\t...(options?.query === undefined ? {} : { query: options.query }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.systemPrompt,\n\t\t\tgetSystemPromptOptions: () => this._baseSystemPromptOptions,\n\t\t},\n\t\t{\n\t\t\tregisterProvider: (name, config) => {\n\t\t\t\tthis._modelRegistry.registerProvider(name, config);\n\t\t\t\tthis._refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t\tunregisterProvider: (name) => {\n\t\t\t\tthis._modelRegistry.unregisterProvider(name);\n\t\t\t\tthis._refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t},\n\t);\n}\n\n\nexport async function reload(this: AgentSession): Promise<void> {\n\tconst previousFlagValues = this._extensionRunner.getFlagValues();\n\tawait emitSessionShutdownEvent(this._extensionRunner, { type: \"session_shutdown\", reason: \"reload\" });\n\tawait this.settingsManager.reload();\n\tresetApiProviders();\n\tawait this._resourceLoader.reload();\n\tthis._buildRuntime({\n\t\tactiveToolNames: this.getActiveToolNames(),\n\t\tflagValues: previousFlagValues,\n\t\tincludeAllExtensionTools: true,\n\t});\n\n\tconst hasBindings =\n\t\tthis._extensionUIContext ||\n\t\tthis._extensionCommandContextActions ||\n\t\tthis._extensionShutdownHandler ||\n\t\tthis._extensionErrorListener;\n\tif (hasBindings) {\n\t\tawait this._extensionRunner.emit({ type: \"session_start\", reason: \"reload\" });\n\t\tawait this.extendResourcesFromExtensions(\"reload\");\n\t}\n}\n\n// =========================================================================\n// Auto-Retry\n// =========================================================================\n\n/**\n * Check if an error is retryable (overloaded, rate limit, server errors).\n * Context overflow errors are NOT retryable (handled by compaction instead).\n */\n\nexport const agentSessionExtensionBindingsMethods = {\n\tbindExtensions,\n\textendResourcesFromExtensions,\n\tbuildExtensionResourcePaths,\n\tgetExtensionSourceLabel,\n\t_applyExtensionBindings,\n\t_refreshCurrentModelFromRegistry,\n\t_bindExtensionCore,\n\treload,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-extension-bindings.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-extension-bindings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE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CAAC,IAAI,CAAC,CAqB9D;AAMD;;;GAGG;AAEH,eAAO,MAAM,oCAAoC;;;;;;;;;;CAUhD,CAAC","sourcesContent":["import { basename, dirname } from \"node:path\";\nimport { resetApiProviders } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ExtensionBindings } from \"./agent-session-types.ts\";\nimport type { ExtensionRunner } from \"./extensions/index.ts\";\nimport type { ResourceExtensionPaths } from \"./resource-loader.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { SlashCommandInfo } from \"./slash-commands.ts\";\n\nexport async function bindExtensions(this: AgentSession, bindings: ExtensionBindings): Promise<void> {\n\tif (bindings.uiContext !== undefined) {\n\t\tthis._extensionUIContext = bindings.uiContext;\n\t}\n\tif (bindings.mode !== undefined) {\n\t\tthis._extensionMode = bindings.mode;\n\t}\n\tif (bindings.commandContextActions !== undefined) {\n\t\tthis._extensionCommandContextActions = bindings.commandContextActions;\n\t}\n\tif (bindings.shutdownHandler !== undefined) {\n\t\tthis._extensionShutdownHandler = bindings.shutdownHandler;\n\t}\n\tif (bindings.onError !== undefined) {\n\t\tthis._extensionErrorListener = bindings.onError;\n\t}\n\n\tthis._applyExtensionBindings(this._extensionRunner);\n\tawait this._extensionRunner.emit(this._sessionStartEvent);\n\tawait this.extendResourcesFromExtensions(this._sessionStartEvent.reason === \"reload\" ? \"reload\" : \"startup\");\n}\n\n\nexport async function extendResourcesFromExtensions(this: AgentSession, reason: \"startup\" | \"reload\"): Promise<void> {\n\tif (!this._extensionRunner.hasHandlers(\"resources_discover\")) {\n\t\treturn;\n\t}\n\n\tconst { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(\n\t\tthis._cwd,\n\t\treason,\n\t);\n\n\tif (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {\n\t\treturn;\n\t}\n\n\tconst extensionPaths: ResourceExtensionPaths = {\n\t\tskillPaths: this.buildExtensionResourcePaths(skillPaths),\n\t\tpromptPaths: this.buildExtensionResourcePaths(promptPaths),\n\t\tthemePaths: this.buildExtensionResourcePaths(themePaths),\n\t};\n\n\tthis._resourceLoader.extendResources(extensionPaths);\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n\nexport function buildExtensionResourcePaths(this: AgentSession, entries: Array<{ path: string; extensionPath: string }>): Array<{\n\tpath: string;\n\tmetadata: { source: string; scope: \"temporary\"; origin: \"top-level\"; baseDir?: string };\n}> {\n\treturn entries.map((entry) => {\n\t\tconst source = this.getExtensionSourceLabel(entry.extensionPath);\n\t\tconst baseDir = entry.extensionPath.startsWith(\"<\") ? undefined : dirname(entry.extensionPath);\n\t\treturn {\n\t\t\tpath: entry.path,\n\t\t\tmetadata: {\n\t\t\t\tsource,\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t\tbaseDir,\n\t\t\t},\n\t\t};\n\t});\n}\n\n\nexport function getExtensionSourceLabel(this: AgentSession, extensionPath: string): string {\n\tif (extensionPath.startsWith(\"<\")) {\n\t\treturn `extension:${extensionPath.replace(/[<>]/g, \"\")}`;\n\t}\n\tconst base = basename(extensionPath);\n\tconst name = base.replace(/\\.(ts|js)$/, \"\");\n\treturn `extension:${name}`;\n}\n\n\nexport function _applyExtensionBindings(this: AgentSession, runner: ExtensionRunner): void {\n\trunner.setUIContext(this._extensionUIContext, this._extensionMode);\n\trunner.bindCommandContext(this._extensionCommandContextActions);\n\n\tthis._extensionErrorUnsubscriber?.();\n\tthis._extensionErrorUnsubscriber = this._extensionErrorListener\n\t\t? runner.onError(this._extensionErrorListener)\n\t\t: undefined;\n}\n\n\nexport function refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tthis._refreshCurrentModelFromRegistry();\n}\n\nexport function _refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tconst currentModel = this.model;\n\tif (!currentModel) {\n\t\treturn;\n\t}\n\n\tconst refreshedModel = this._modelRegistry.find(currentModel.provider, currentModel.id);\n\tif (!refreshedModel || refreshedModel === currentModel) {\n\t\treturn;\n\t}\n\n\tconst previousModel = currentModel;\n\tconst previousThinkingLevel = this.thinkingLevel;\n\tconst replay = this._getResumeContextWindowReplayForModel(refreshedModel);\n\tthis.agent.state.model = replay.model;\n\tif (currentModel.contextWindow !== replay.contextWindow) {\n\t\tthis._emit({ type: \"context_window_changed\", contextWindow: replay.contextWindow });\n\t}\n\tthis.setThinkingLevel(previousThinkingLevel);\n\tthis._refreshBaseSystemPromptFromActiveTools();\n\tthis._emit({ type: \"model_changed\", model: replay.model, previousModel, source: \"restore\" });\n}\n\n\nexport function _bindExtensionCore(this: AgentSession, runner: ExtensionRunner): void {\n\tconst getCommands = (): SlashCommandInfo[] => {\n\t\tconst extensionCommands: SlashCommandInfo[] = runner.getRegisteredCommands().map((command) => ({\n\t\t\tname: command.invocationName,\n\t\t\tdescription: command.description,\n\t\t\tsource: \"extension\",\n\t\t\tsourceInfo: command.sourceInfo,\n\t\t}));\n\n\t\tconst templates: SlashCommandInfo[] = this.promptTemplates.map((template) => ({\n\t\t\tname: template.name,\n\t\t\tdescription: template.description,\n\t\t\tsource: \"prompt\",\n\t\t\tsourceInfo: template.sourceInfo,\n\t\t}));\n\n\t\tconst skills: SlashCommandInfo[] = this._resourceLoader.getSkills().skills.map((skill) => ({\n\t\t\tname: `skill:${skill.name}`,\n\t\t\tdescription: skill.description,\n\t\t\tsource: \"skill\",\n\t\t\tsourceInfo: skill.sourceInfo,\n\t\t}));\n\n\t\treturn [...extensionCommands, ...templates, ...skills];\n\t};\n\n\trunner.bindCore(\n\t\t{\n\t\t\tsendMessage: (message, options) => {\n\t\t\t\tthis.sendCustomMessage(message, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tsendUserMessage: (content, options) => {\n\t\t\t\tthis.sendUserMessage(content, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_user_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntry: (customType, data) => {\n\t\t\t\tthis.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tsetSessionName: (name) => {\n\t\t\t\tthis.setSessionName(name);\n\t\t\t},\n\t\t\tgetSessionName: () => {\n\t\t\t\treturn this.sessionManager.getSessionName();\n\t\t\t},\n\t\t\tsetLabel: (entryId, label) => {\n\t\t\t\tthis.sessionManager.appendLabelChange(entryId, label);\n\t\t\t},\n\t\t\tgetActiveTools: () => this.getActiveToolNames(),\n\t\t\tgetAllTools: () => this.getAllTools(),\n\t\t\tsetActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),\n\t\t\trefreshTools: () => this._refreshToolRegistry(),\n\t\t\tgetCommands,\n\t\t\tsetModel: async (model) => {\n\t\t\t\tif (!this.modelRegistry.hasConfiguredAuth(model)) return false;\n\t\t\t\tawait this.setModel(model);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tgetThinkingLevel: () => this.thinkingLevel,\n\t\t\tsetThinkingLevel: (level) => this.setThinkingLevel(level),\n\t\t},\n\t\t{\n\t\t\tgetModel: () => this.model,\n\t\t\tisIdle: () => !this.isStreaming,\n\t\t\tisProjectTrusted: () => this.settingsManager.isProjectTrusted(),\n\t\t\tgetSignal: () => this.agent.signal,\n\t\t\tabort: () => this.abort(),\n\t\t\thasPendingMessages: () => this.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis._extensionShutdownHandler?.();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.compact({\n\t\t\t\t\t\t\t...(options?.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t\t\t\t\t...(options?.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t\t\t\t\t...(options?.query === undefined ? {} : { query: options.query }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.systemPrompt,\n\t\t\tgetSystemPromptOptions: () => this._baseSystemPromptOptions,\n\t\t},\n\t\t{\n\t\t\tregisterProvider: (name, config) => {\n\t\t\t\tthis._modelRegistry.registerProvider(name, config);\n\t\t\t\tthis.refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t\tunregisterProvider: (name) => {\n\t\t\t\tthis._modelRegistry.unregisterProvider(name);\n\t\t\t\tthis.refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t},\n\t);\n}\n\n\nexport async function reload(this: AgentSession): Promise<void> {\n\tconst previousFlagValues = this._extensionRunner.getFlagValues();\n\tawait emitSessionShutdownEvent(this._extensionRunner, { type: \"session_shutdown\", reason: \"reload\" });\n\tawait this.settingsManager.reload();\n\tresetApiProviders();\n\tawait this._resourceLoader.reload();\n\tthis._buildRuntime({\n\t\tactiveToolNames: this.getActiveToolNames(),\n\t\tflagValues: previousFlagValues,\n\t\tincludeAllExtensionTools: true,\n\t});\n\n\tconst hasBindings =\n\t\tthis._extensionUIContext ||\n\t\tthis._extensionCommandContextActions ||\n\t\tthis._extensionShutdownHandler ||\n\t\tthis._extensionErrorListener;\n\tif (hasBindings) {\n\t\tawait this._extensionRunner.emit({ type: \"session_start\", reason: \"reload\" });\n\t\tawait this.extendResourcesFromExtensions(\"reload\");\n\t}\n}\n\n// =========================================================================\n// Auto-Retry\n// =========================================================================\n\n/**\n * Check if an error is retryable (overloaded, rate limit, server errors).\n * Context overflow errors are NOT retryable (handled by compaction instead).\n */\n\nexport const agentSessionExtensionBindingsMethods = {\n\tbindExtensions,\n\textendResourcesFromExtensions,\n\tbuildExtensionResourcePaths,\n\tgetExtensionSourceLabel,\n\t_applyExtensionBindings,\n\trefreshCurrentModelFromRegistry,\n\t_refreshCurrentModelFromRegistry,\n\t_bindExtensionCore,\n\treload,\n};\n"]}
|
|
@@ -69,6 +69,9 @@ export function _applyExtensionBindings(runner) {
|
|
|
69
69
|
? runner.onError(this._extensionErrorListener)
|
|
70
70
|
: undefined;
|
|
71
71
|
}
|
|
72
|
+
export function refreshCurrentModelFromRegistry() {
|
|
73
|
+
this._refreshCurrentModelFromRegistry();
|
|
74
|
+
}
|
|
72
75
|
export function _refreshCurrentModelFromRegistry() {
|
|
73
76
|
const currentModel = this.model;
|
|
74
77
|
if (!currentModel) {
|
|
@@ -78,12 +81,16 @@ export function _refreshCurrentModelFromRegistry() {
|
|
|
78
81
|
if (!refreshedModel || refreshedModel === currentModel) {
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
84
|
+
const previousModel = currentModel;
|
|
85
|
+
const previousThinkingLevel = this.thinkingLevel;
|
|
81
86
|
const replay = this._getResumeContextWindowReplayForModel(refreshedModel);
|
|
82
87
|
this.agent.state.model = replay.model;
|
|
83
88
|
if (currentModel.contextWindow !== replay.contextWindow) {
|
|
84
89
|
this._emit({ type: "context_window_changed", contextWindow: replay.contextWindow });
|
|
85
90
|
}
|
|
91
|
+
this.setThinkingLevel(previousThinkingLevel);
|
|
86
92
|
this._refreshBaseSystemPromptFromActiveTools();
|
|
93
|
+
this._emit({ type: "model_changed", model: replay.model, previousModel, source: "restore" });
|
|
87
94
|
}
|
|
88
95
|
export function _bindExtensionCore(runner) {
|
|
89
96
|
const getCommands = () => {
|
|
@@ -183,11 +190,11 @@ export function _bindExtensionCore(runner) {
|
|
|
183
190
|
}, {
|
|
184
191
|
registerProvider: (name, config) => {
|
|
185
192
|
this._modelRegistry.registerProvider(name, config);
|
|
186
|
-
this.
|
|
193
|
+
this.refreshCurrentModelFromRegistry();
|
|
187
194
|
},
|
|
188
195
|
unregisterProvider: (name) => {
|
|
189
196
|
this._modelRegistry.unregisterProvider(name);
|
|
190
|
-
this.
|
|
197
|
+
this.refreshCurrentModelFromRegistry();
|
|
191
198
|
},
|
|
192
199
|
});
|
|
193
200
|
}
|
|
@@ -224,6 +231,7 @@ export const agentSessionExtensionBindingsMethods = {
|
|
|
224
231
|
buildExtensionResourcePaths,
|
|
225
232
|
getExtensionSourceLabel,
|
|
226
233
|
_applyExtensionBindings,
|
|
234
|
+
refreshCurrentModelFromRegistry,
|
|
227
235
|
_refreshCurrentModelFromRegistry,
|
|
228
236
|
_bindExtensionCore,
|
|
229
237
|
reload,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-extension-bindings.js","sourceRoot":"","sources":["../../src/core/agent-session-extension-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAqB,QAA2B;IACnF,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,QAAQ,CAAC,SAAS,CAAC;IAC/C,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC;IACrC,CAAC;IACD,IAAI,QAA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C;AAGD,MAAM,CAAC,KAAK,UAAU,MAAM;IAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,CAAC;IACjE,MAAM,wBAAwB,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;IACpC,iBAAiB,EAAE,CAAC;IACpB,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;IACpC,IAAI,CAAC,aAAa,CAAC;QAClB,eAAe,EAAE,IAAI,CAAC,kBAAkB,EAAE;QAC1C,UAAU,EAAE,kBAAkB;QAC9B,wBAAwB,EAAE,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,WAAW,GAChB,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,+BAA+B;QACpC,IAAI,CAAC,yBAAyB;QAC9B,IAAI,CAAC,uBAAuB,CAAC;IAC9B,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9E,MAAM,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;AACF,CAAC;AAED,4EAA4E;AAC5E,aAAa;AACb,4EAA4E;AAE5E;;;GAGG;AAEH,MAAM,CAAC,MAAM,oCAAoC,GAAG;IACnD,cAAc;IACd,6BAA6B;IAC7B,2BAA2B;IAC3B,uBAAuB;IACvB,uBAAuB;IACvB,gCAAgC;IAChC,kBAAkB;IAClB,MAAM;CACN,CAAC","sourcesContent":["import { basename, dirname } from \"node:path\";\nimport { resetApiProviders } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ExtensionBindings } from \"./agent-session-types.ts\";\nimport type { ExtensionRunner } from \"./extensions/index.ts\";\nimport type { ResourceExtensionPaths } from \"./resource-loader.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { SlashCommandInfo } from \"./slash-commands.ts\";\n\nexport async function bindExtensions(this: AgentSession, bindings: ExtensionBindings): Promise<void> {\n\tif (bindings.uiContext !== undefined) {\n\t\tthis._extensionUIContext = bindings.uiContext;\n\t}\n\tif (bindings.mode !== undefined) {\n\t\tthis._extensionMode = bindings.mode;\n\t}\n\tif (bindings.commandContextActions !== undefined) {\n\t\tthis._extensionCommandContextActions = bindings.commandContextActions;\n\t}\n\tif (bindings.shutdownHandler !== undefined) {\n\t\tthis._extensionShutdownHandler = bindings.shutdownHandler;\n\t}\n\tif (bindings.onError !== undefined) {\n\t\tthis._extensionErrorListener = bindings.onError;\n\t}\n\n\tthis._applyExtensionBindings(this._extensionRunner);\n\tawait this._extensionRunner.emit(this._sessionStartEvent);\n\tawait this.extendResourcesFromExtensions(this._sessionStartEvent.reason === \"reload\" ? \"reload\" : \"startup\");\n}\n\n\nexport async function extendResourcesFromExtensions(this: AgentSession, reason: \"startup\" | \"reload\"): Promise<void> {\n\tif (!this._extensionRunner.hasHandlers(\"resources_discover\")) {\n\t\treturn;\n\t}\n\n\tconst { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(\n\t\tthis._cwd,\n\t\treason,\n\t);\n\n\tif (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {\n\t\treturn;\n\t}\n\n\tconst extensionPaths: ResourceExtensionPaths = {\n\t\tskillPaths: this.buildExtensionResourcePaths(skillPaths),\n\t\tpromptPaths: this.buildExtensionResourcePaths(promptPaths),\n\t\tthemePaths: this.buildExtensionResourcePaths(themePaths),\n\t};\n\n\tthis._resourceLoader.extendResources(extensionPaths);\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n\nexport function buildExtensionResourcePaths(this: AgentSession, entries: Array<{ path: string; extensionPath: string }>): Array<{\n\tpath: string;\n\tmetadata: { source: string; scope: \"temporary\"; origin: \"top-level\"; baseDir?: string };\n}> {\n\treturn entries.map((entry) => {\n\t\tconst source = this.getExtensionSourceLabel(entry.extensionPath);\n\t\tconst baseDir = entry.extensionPath.startsWith(\"<\") ? undefined : dirname(entry.extensionPath);\n\t\treturn {\n\t\t\tpath: entry.path,\n\t\t\tmetadata: {\n\t\t\t\tsource,\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t\tbaseDir,\n\t\t\t},\n\t\t};\n\t});\n}\n\n\nexport function getExtensionSourceLabel(this: AgentSession, extensionPath: string): string {\n\tif (extensionPath.startsWith(\"<\")) {\n\t\treturn `extension:${extensionPath.replace(/[<>]/g, \"\")}`;\n\t}\n\tconst base = basename(extensionPath);\n\tconst name = base.replace(/\\.(ts|js)$/, \"\");\n\treturn `extension:${name}`;\n}\n\n\nexport function _applyExtensionBindings(this: AgentSession, runner: ExtensionRunner): void {\n\trunner.setUIContext(this._extensionUIContext, this._extensionMode);\n\trunner.bindCommandContext(this._extensionCommandContextActions);\n\n\tthis._extensionErrorUnsubscriber?.();\n\tthis._extensionErrorUnsubscriber = this._extensionErrorListener\n\t\t? runner.onError(this._extensionErrorListener)\n\t\t: undefined;\n}\n\n\nexport function _refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tconst currentModel = this.model;\n\tif (!currentModel) {\n\t\treturn;\n\t}\n\n\tconst refreshedModel = this._modelRegistry.find(currentModel.provider, currentModel.id);\n\tif (!refreshedModel || refreshedModel === currentModel) {\n\t\treturn;\n\t}\n\n\tconst replay = this._getResumeContextWindowReplayForModel(refreshedModel);\n\tthis.agent.state.model = replay.model;\n\tif (currentModel.contextWindow !== replay.contextWindow) {\n\t\tthis._emit({ type: \"context_window_changed\", contextWindow: replay.contextWindow });\n\t}\n\tthis._refreshBaseSystemPromptFromActiveTools();\n}\n\n\nexport function _bindExtensionCore(this: AgentSession, runner: ExtensionRunner): void {\n\tconst getCommands = (): SlashCommandInfo[] => {\n\t\tconst extensionCommands: SlashCommandInfo[] = runner.getRegisteredCommands().map((command) => ({\n\t\t\tname: command.invocationName,\n\t\t\tdescription: command.description,\n\t\t\tsource: \"extension\",\n\t\t\tsourceInfo: command.sourceInfo,\n\t\t}));\n\n\t\tconst templates: SlashCommandInfo[] = this.promptTemplates.map((template) => ({\n\t\t\tname: template.name,\n\t\t\tdescription: template.description,\n\t\t\tsource: \"prompt\",\n\t\t\tsourceInfo: template.sourceInfo,\n\t\t}));\n\n\t\tconst skills: SlashCommandInfo[] = this._resourceLoader.getSkills().skills.map((skill) => ({\n\t\t\tname: `skill:${skill.name}`,\n\t\t\tdescription: skill.description,\n\t\t\tsource: \"skill\",\n\t\t\tsourceInfo: skill.sourceInfo,\n\t\t}));\n\n\t\treturn [...extensionCommands, ...templates, ...skills];\n\t};\n\n\trunner.bindCore(\n\t\t{\n\t\t\tsendMessage: (message, options) => {\n\t\t\t\tthis.sendCustomMessage(message, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tsendUserMessage: (content, options) => {\n\t\t\t\tthis.sendUserMessage(content, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_user_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntry: (customType, data) => {\n\t\t\t\tthis.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tsetSessionName: (name) => {\n\t\t\t\tthis.setSessionName(name);\n\t\t\t},\n\t\t\tgetSessionName: () => {\n\t\t\t\treturn this.sessionManager.getSessionName();\n\t\t\t},\n\t\t\tsetLabel: (entryId, label) => {\n\t\t\t\tthis.sessionManager.appendLabelChange(entryId, label);\n\t\t\t},\n\t\t\tgetActiveTools: () => this.getActiveToolNames(),\n\t\t\tgetAllTools: () => this.getAllTools(),\n\t\t\tsetActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),\n\t\t\trefreshTools: () => this._refreshToolRegistry(),\n\t\t\tgetCommands,\n\t\t\tsetModel: async (model) => {\n\t\t\t\tif (!this.modelRegistry.hasConfiguredAuth(model)) return false;\n\t\t\t\tawait this.setModel(model);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tgetThinkingLevel: () => this.thinkingLevel,\n\t\t\tsetThinkingLevel: (level) => this.setThinkingLevel(level),\n\t\t},\n\t\t{\n\t\t\tgetModel: () => this.model,\n\t\t\tisIdle: () => !this.isStreaming,\n\t\t\tisProjectTrusted: () => this.settingsManager.isProjectTrusted(),\n\t\t\tgetSignal: () => this.agent.signal,\n\t\t\tabort: () => this.abort(),\n\t\t\thasPendingMessages: () => this.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis._extensionShutdownHandler?.();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.compact({\n\t\t\t\t\t\t\t...(options?.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t\t\t\t\t...(options?.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t\t\t\t\t...(options?.query === undefined ? {} : { query: options.query }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.systemPrompt,\n\t\t\tgetSystemPromptOptions: () => this._baseSystemPromptOptions,\n\t\t},\n\t\t{\n\t\t\tregisterProvider: (name, config) => {\n\t\t\t\tthis._modelRegistry.registerProvider(name, config);\n\t\t\t\tthis._refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t\tunregisterProvider: (name) => {\n\t\t\t\tthis._modelRegistry.unregisterProvider(name);\n\t\t\t\tthis._refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t},\n\t);\n}\n\n\nexport async function reload(this: AgentSession): Promise<void> {\n\tconst previousFlagValues = this._extensionRunner.getFlagValues();\n\tawait emitSessionShutdownEvent(this._extensionRunner, { type: \"session_shutdown\", reason: \"reload\" });\n\tawait this.settingsManager.reload();\n\tresetApiProviders();\n\tawait this._resourceLoader.reload();\n\tthis._buildRuntime({\n\t\tactiveToolNames: this.getActiveToolNames(),\n\t\tflagValues: previousFlagValues,\n\t\tincludeAllExtensionTools: true,\n\t});\n\n\tconst hasBindings =\n\t\tthis._extensionUIContext ||\n\t\tthis._extensionCommandContextActions ||\n\t\tthis._extensionShutdownHandler ||\n\t\tthis._extensionErrorListener;\n\tif (hasBindings) {\n\t\tawait this._extensionRunner.emit({ type: \"session_start\", reason: \"reload\" });\n\t\tawait this.extendResourcesFromExtensions(\"reload\");\n\t}\n}\n\n// =========================================================================\n// Auto-Retry\n// =========================================================================\n\n/**\n * Check if an error is retryable (overloaded, rate limit, server errors).\n * Context overflow errors are NOT retryable (handled by compaction instead).\n */\n\nexport const agentSessionExtensionBindingsMethods = {\n\tbindExtensions,\n\textendResourcesFromExtensions,\n\tbuildExtensionResourcePaths,\n\tgetExtensionSourceLabel,\n\t_applyExtensionBindings,\n\t_refreshCurrentModelFromRegistry,\n\t_bindExtensionCore,\n\treload,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-extension-bindings.js","sourceRoot":"","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AAe,CAAC,MAAM,EAAE,CAAC;IACpC,IAAI,CAAC,aAAa,CAAC;QAClB,eAAe,EAAE,IAAI,CAAC,kBAAkB,EAAE;QAC1C,UAAU,EAAE,kBAAkB;QAC9B,wBAAwB,EAAE,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,WAAW,GAChB,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,+BAA+B;QACpC,IAAI,CAAC,yBAAyB;QAC9B,IAAI,CAAC,uBAAuB,CAAC;IAC9B,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9E,MAAM,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;AACF,CAAC;AAED,4EAA4E;AAC5E,aAAa;AACb,4EAA4E;AAE5E;;;GAGG;AAEH,MAAM,CAAC,MAAM,oCAAoC,GAAG;IACnD,cAAc;IACd,6BAA6B;IAC7B,2BAA2B;IAC3B,uBAAuB;IACvB,uBAAuB;IACvB,+BAA+B;IAC/B,gCAAgC;IAChC,kBAAkB;IAClB,MAAM;CACN,CAAC","sourcesContent":["import { basename, dirname } from \"node:path\";\nimport { resetApiProviders } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ExtensionBindings } from \"./agent-session-types.ts\";\nimport type { ExtensionRunner } from \"./extensions/index.ts\";\nimport type { ResourceExtensionPaths } from \"./resource-loader.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { SlashCommandInfo } from \"./slash-commands.ts\";\n\nexport async function bindExtensions(this: AgentSession, bindings: ExtensionBindings): Promise<void> {\n\tif (bindings.uiContext !== undefined) {\n\t\tthis._extensionUIContext = bindings.uiContext;\n\t}\n\tif (bindings.mode !== undefined) {\n\t\tthis._extensionMode = bindings.mode;\n\t}\n\tif (bindings.commandContextActions !== undefined) {\n\t\tthis._extensionCommandContextActions = bindings.commandContextActions;\n\t}\n\tif (bindings.shutdownHandler !== undefined) {\n\t\tthis._extensionShutdownHandler = bindings.shutdownHandler;\n\t}\n\tif (bindings.onError !== undefined) {\n\t\tthis._extensionErrorListener = bindings.onError;\n\t}\n\n\tthis._applyExtensionBindings(this._extensionRunner);\n\tawait this._extensionRunner.emit(this._sessionStartEvent);\n\tawait this.extendResourcesFromExtensions(this._sessionStartEvent.reason === \"reload\" ? \"reload\" : \"startup\");\n}\n\n\nexport async function extendResourcesFromExtensions(this: AgentSession, reason: \"startup\" | \"reload\"): Promise<void> {\n\tif (!this._extensionRunner.hasHandlers(\"resources_discover\")) {\n\t\treturn;\n\t}\n\n\tconst { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(\n\t\tthis._cwd,\n\t\treason,\n\t);\n\n\tif (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {\n\t\treturn;\n\t}\n\n\tconst extensionPaths: ResourceExtensionPaths = {\n\t\tskillPaths: this.buildExtensionResourcePaths(skillPaths),\n\t\tpromptPaths: this.buildExtensionResourcePaths(promptPaths),\n\t\tthemePaths: this.buildExtensionResourcePaths(themePaths),\n\t};\n\n\tthis._resourceLoader.extendResources(extensionPaths);\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n\nexport function buildExtensionResourcePaths(this: AgentSession, entries: Array<{ path: string; extensionPath: string }>): Array<{\n\tpath: string;\n\tmetadata: { source: string; scope: \"temporary\"; origin: \"top-level\"; baseDir?: string };\n}> {\n\treturn entries.map((entry) => {\n\t\tconst source = this.getExtensionSourceLabel(entry.extensionPath);\n\t\tconst baseDir = entry.extensionPath.startsWith(\"<\") ? undefined : dirname(entry.extensionPath);\n\t\treturn {\n\t\t\tpath: entry.path,\n\t\t\tmetadata: {\n\t\t\t\tsource,\n\t\t\t\tscope: \"temporary\",\n\t\t\t\torigin: \"top-level\",\n\t\t\t\tbaseDir,\n\t\t\t},\n\t\t};\n\t});\n}\n\n\nexport function getExtensionSourceLabel(this: AgentSession, extensionPath: string): string {\n\tif (extensionPath.startsWith(\"<\")) {\n\t\treturn `extension:${extensionPath.replace(/[<>]/g, \"\")}`;\n\t}\n\tconst base = basename(extensionPath);\n\tconst name = base.replace(/\\.(ts|js)$/, \"\");\n\treturn `extension:${name}`;\n}\n\n\nexport function _applyExtensionBindings(this: AgentSession, runner: ExtensionRunner): void {\n\trunner.setUIContext(this._extensionUIContext, this._extensionMode);\n\trunner.bindCommandContext(this._extensionCommandContextActions);\n\n\tthis._extensionErrorUnsubscriber?.();\n\tthis._extensionErrorUnsubscriber = this._extensionErrorListener\n\t\t? runner.onError(this._extensionErrorListener)\n\t\t: undefined;\n}\n\n\nexport function refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tthis._refreshCurrentModelFromRegistry();\n}\n\nexport function _refreshCurrentModelFromRegistry(this: AgentSession): void {\n\tconst currentModel = this.model;\n\tif (!currentModel) {\n\t\treturn;\n\t}\n\n\tconst refreshedModel = this._modelRegistry.find(currentModel.provider, currentModel.id);\n\tif (!refreshedModel || refreshedModel === currentModel) {\n\t\treturn;\n\t}\n\n\tconst previousModel = currentModel;\n\tconst previousThinkingLevel = this.thinkingLevel;\n\tconst replay = this._getResumeContextWindowReplayForModel(refreshedModel);\n\tthis.agent.state.model = replay.model;\n\tif (currentModel.contextWindow !== replay.contextWindow) {\n\t\tthis._emit({ type: \"context_window_changed\", contextWindow: replay.contextWindow });\n\t}\n\tthis.setThinkingLevel(previousThinkingLevel);\n\tthis._refreshBaseSystemPromptFromActiveTools();\n\tthis._emit({ type: \"model_changed\", model: replay.model, previousModel, source: \"restore\" });\n}\n\n\nexport function _bindExtensionCore(this: AgentSession, runner: ExtensionRunner): void {\n\tconst getCommands = (): SlashCommandInfo[] => {\n\t\tconst extensionCommands: SlashCommandInfo[] = runner.getRegisteredCommands().map((command) => ({\n\t\t\tname: command.invocationName,\n\t\t\tdescription: command.description,\n\t\t\tsource: \"extension\",\n\t\t\tsourceInfo: command.sourceInfo,\n\t\t}));\n\n\t\tconst templates: SlashCommandInfo[] = this.promptTemplates.map((template) => ({\n\t\t\tname: template.name,\n\t\t\tdescription: template.description,\n\t\t\tsource: \"prompt\",\n\t\t\tsourceInfo: template.sourceInfo,\n\t\t}));\n\n\t\tconst skills: SlashCommandInfo[] = this._resourceLoader.getSkills().skills.map((skill) => ({\n\t\t\tname: `skill:${skill.name}`,\n\t\t\tdescription: skill.description,\n\t\t\tsource: \"skill\",\n\t\t\tsourceInfo: skill.sourceInfo,\n\t\t}));\n\n\t\treturn [...extensionCommands, ...templates, ...skills];\n\t};\n\n\trunner.bindCore(\n\t\t{\n\t\t\tsendMessage: (message, options) => {\n\t\t\t\tthis.sendCustomMessage(message, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tsendUserMessage: (content, options) => {\n\t\t\t\tthis.sendUserMessage(content, options).catch((err) => {\n\t\t\t\t\trunner.emitError({\n\t\t\t\t\t\textensionPath: \"<runtime>\",\n\t\t\t\t\t\tevent: \"send_user_message\",\n\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntry: (customType, data) => {\n\t\t\t\tthis.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tsetSessionName: (name) => {\n\t\t\t\tthis.setSessionName(name);\n\t\t\t},\n\t\t\tgetSessionName: () => {\n\t\t\t\treturn this.sessionManager.getSessionName();\n\t\t\t},\n\t\t\tsetLabel: (entryId, label) => {\n\t\t\t\tthis.sessionManager.appendLabelChange(entryId, label);\n\t\t\t},\n\t\t\tgetActiveTools: () => this.getActiveToolNames(),\n\t\t\tgetAllTools: () => this.getAllTools(),\n\t\t\tsetActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),\n\t\t\trefreshTools: () => this._refreshToolRegistry(),\n\t\t\tgetCommands,\n\t\t\tsetModel: async (model) => {\n\t\t\t\tif (!this.modelRegistry.hasConfiguredAuth(model)) return false;\n\t\t\t\tawait this.setModel(model);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tgetThinkingLevel: () => this.thinkingLevel,\n\t\t\tsetThinkingLevel: (level) => this.setThinkingLevel(level),\n\t\t},\n\t\t{\n\t\t\tgetModel: () => this.model,\n\t\t\tisIdle: () => !this.isStreaming,\n\t\t\tisProjectTrusted: () => this.settingsManager.isProjectTrusted(),\n\t\t\tgetSignal: () => this.agent.signal,\n\t\t\tabort: () => this.abort(),\n\t\t\thasPendingMessages: () => this.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis._extensionShutdownHandler?.();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.compact({\n\t\t\t\t\t\t\t...(options?.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t\t\t\t\t...(options?.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t\t\t\t\t...(options?.query === undefined ? {} : { query: options.query }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.systemPrompt,\n\t\t\tgetSystemPromptOptions: () => this._baseSystemPromptOptions,\n\t\t},\n\t\t{\n\t\t\tregisterProvider: (name, config) => {\n\t\t\t\tthis._modelRegistry.registerProvider(name, config);\n\t\t\t\tthis.refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t\tunregisterProvider: (name) => {\n\t\t\t\tthis._modelRegistry.unregisterProvider(name);\n\t\t\t\tthis.refreshCurrentModelFromRegistry();\n\t\t\t},\n\t\t},\n\t);\n}\n\n\nexport async function reload(this: AgentSession): Promise<void> {\n\tconst previousFlagValues = this._extensionRunner.getFlagValues();\n\tawait emitSessionShutdownEvent(this._extensionRunner, { type: \"session_shutdown\", reason: \"reload\" });\n\tawait this.settingsManager.reload();\n\tresetApiProviders();\n\tawait this._resourceLoader.reload();\n\tthis._buildRuntime({\n\t\tactiveToolNames: this.getActiveToolNames(),\n\t\tflagValues: previousFlagValues,\n\t\tincludeAllExtensionTools: true,\n\t});\n\n\tconst hasBindings =\n\t\tthis._extensionUIContext ||\n\t\tthis._extensionCommandContextActions ||\n\t\tthis._extensionShutdownHandler ||\n\t\tthis._extensionErrorListener;\n\tif (hasBindings) {\n\t\tawait this._extensionRunner.emit({ type: \"session_start\", reason: \"reload\" });\n\t\tawait this.extendResourcesFromExtensions(\"reload\");\n\t}\n}\n\n// =========================================================================\n// Auto-Retry\n// =========================================================================\n\n/**\n * Check if an error is retryable (overloaded, rate limit, server errors).\n * Context overflow errors are NOT retryable (handled by compaction instead).\n */\n\nexport const agentSessionExtensionBindingsMethods = {\n\tbindExtensions,\n\textendResourcesFromExtensions,\n\tbuildExtensionResourcePaths,\n\tgetExtensionSourceLabel,\n\t_applyExtensionBindings,\n\trefreshCurrentModelFromRegistry,\n\t_refreshCurrentModelFromRegistry,\n\t_bindExtensionCore,\n\treload,\n};\n"]}
|
|
@@ -188,6 +188,7 @@ export interface AgentSessionMethodSurface {
|
|
|
188
188
|
getExtensionSourceLabel(extensionPath: string): string;
|
|
189
189
|
_applyExtensionBindings(runner: ExtensionRunner): void;
|
|
190
190
|
_refreshCurrentModelFromRegistry(): void;
|
|
191
|
+
refreshCurrentModelFromRegistry(): void;
|
|
191
192
|
_bindExtensionCore(runner: ExtensionRunner): void;
|
|
192
193
|
_refreshToolRegistry(options?: {
|
|
193
194
|
activeToolNames?: string[];
|
|
@@ -239,7 +240,7 @@ export interface AgentSessionMethodSurface {
|
|
|
239
240
|
createReplacedSessionContext(): ReplacedSessionContext;
|
|
240
241
|
hasExtensionHandlers(eventType: string): boolean;
|
|
241
242
|
}
|
|
242
|
-
export interface AgentSessionPublicSurface extends Pick<AgentSessionMethodSurface, "orchestrationContext" | "modelRegistry" | "state" | "model" | "thinkingLevel" | "isStreaming" | "systemPrompt" | "retryAttempt" | "isCompacting" | "messages" | "steeringMode" | "followUpMode" | "sessionFile" | "sessionId" | "sessionName" | "scopedModels" | "promptTemplates" | "pendingMessageCount" | "resourceLoader" | "autoCompactionEnabled" | "isRetrying" | "autoRetryEnabled" | "isBashRunning" | "hasPendingBashMessages" | "extensionRunner" | "subscribe" | "dispose" | "getActiveToolNames" | "getAllTools" | "getToolDefinition" | "setActiveToolsByName" | "setScopedModels" | "prompt" | "steer" | "followUp" | "sendCustomMessage" | "sendUserMessage" | "clearQueue" | "getSteeringMessages" | "getFollowUpMessages" | "abort" | "setModel" | "cycleModel" | "setThinkingLevel" | "cycleThinkingLevel" | "getAvailableThinkingLevels" | "supportsThinking" | "getAvailableContextWindows" | "supportsContextWindowSelection" | "setContextWindow" | "setSteeringMode" | "setFollowUpMode" | "compact" | "contextCompact" | "abortCompaction" | "abortBranchSummary" | "setAutoCompactionEnabled" | "bindExtensions" | "reload" | "abortRetry" | "setAutoRetryEnabled" | "executeBash" | "recordBashResult" | "abortBash" | "setSessionName" | "navigateTree" | "getUserMessagesForForking" | "getSessionStats" | "getContextUsage" | "exportToHtml" | "exportToJsonl" | "getLastAssistantText" | "createReplacedSessionContext" | "hasExtensionHandlers"> {
|
|
243
|
+
export interface AgentSessionPublicSurface extends Pick<AgentSessionMethodSurface, "orchestrationContext" | "modelRegistry" | "state" | "model" | "thinkingLevel" | "isStreaming" | "systemPrompt" | "retryAttempt" | "isCompacting" | "messages" | "steeringMode" | "followUpMode" | "sessionFile" | "sessionId" | "sessionName" | "scopedModels" | "promptTemplates" | "pendingMessageCount" | "resourceLoader" | "autoCompactionEnabled" | "isRetrying" | "autoRetryEnabled" | "isBashRunning" | "hasPendingBashMessages" | "extensionRunner" | "subscribe" | "dispose" | "getActiveToolNames" | "getAllTools" | "getToolDefinition" | "setActiveToolsByName" | "setScopedModels" | "prompt" | "steer" | "followUp" | "sendCustomMessage" | "sendUserMessage" | "clearQueue" | "getSteeringMessages" | "getFollowUpMessages" | "abort" | "setModel" | "cycleModel" | "setThinkingLevel" | "cycleThinkingLevel" | "getAvailableThinkingLevels" | "supportsThinking" | "getAvailableContextWindows" | "supportsContextWindowSelection" | "setContextWindow" | "setSteeringMode" | "setFollowUpMode" | "compact" | "contextCompact" | "abortCompaction" | "abortBranchSummary" | "setAutoCompactionEnabled" | "bindExtensions" | "refreshCurrentModelFromRegistry" | "reload" | "abortRetry" | "setAutoRetryEnabled" | "executeBash" | "recordBashResult" | "abortBash" | "setSessionName" | "navigateTree" | "getUserMessagesForForking" | "getSessionStats" | "getContextUsage" | "exportToHtml" | "exportToJsonl" | "getLastAssistantText" | "createReplacedSessionContext" | "hasExtensionHandlers"> {
|
|
243
244
|
readonly agent: Agent;
|
|
244
245
|
readonly sessionManager: SessionManager;
|
|
245
246
|
readonly settingsManager: SettingsManager;
|