@aexol/spectral 0.9.221 → 0.9.223
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +20 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +286 -80
- package/dist/extensions/aexol-backend-client.d.ts +85 -0
- package/dist/extensions/aexol-backend-client.d.ts.map +1 -0
- package/dist/extensions/aexol-backend-client.js +159 -0
- package/dist/extensions/aexol-mcp.d.ts +10 -6
- package/dist/extensions/aexol-mcp.d.ts.map +1 -1
- package/dist/extensions/aexol-mcp.js +21 -106
- package/dist/extensions/logic-trace-backend-draft.d.ts +68 -0
- package/dist/extensions/logic-trace-backend-draft.d.ts.map +1 -0
- package/dist/extensions/logic-trace-backend-draft.js +171 -0
- package/dist/extensions/logic-trace-validate.d.ts +33 -0
- package/dist/extensions/logic-trace-validate.d.ts.map +1 -0
- package/dist/extensions/logic-trace-validate.js +73 -0
- package/dist/extensions/logic-trace.d.ts +213 -0
- package/dist/extensions/logic-trace.d.ts.map +1 -0
- package/dist/extensions/logic-trace.js +1098 -0
- package/dist/generated/parser/lexer.d.ts +148 -0
- package/dist/generated/parser/lexer.d.ts.map +1 -0
- package/dist/generated/parser/lexer.js +877 -0
- package/dist/generated/parser/mod.d.ts +26 -0
- package/dist/generated/parser/mod.d.ts.map +1 -0
- package/dist/generated/parser/mod.js +30 -0
- package/dist/generated/parser/parser.d.ts +161 -0
- package/dist/generated/parser/parser.d.ts.map +1 -0
- package/dist/generated/parser/parser.js +754 -0
- package/dist/generated/parser/tokenizer.d.ts +107 -0
- package/dist/generated/parser/tokenizer.d.ts.map +1 -0
- package/dist/generated/parser/tokenizer.js +202 -0
- package/dist/generated/parser/validator.d.ts +45 -0
- package/dist/generated/parser/validator.d.ts.map +1 -0
- package/dist/generated/parser/validator.js +202 -0
- package/dist/generated/zeus/const.d.ts.map +1 -1
- package/dist/generated/zeus/const.js +4 -170
- package/dist/generated/zeus/index.d.ts +8 -873
- package/dist/generated/zeus/index.d.ts.map +1 -1
- package/dist/generated/zeus/index.js +0 -7
- package/dist/mcp/ui-stream-types.d.ts +2 -2
- package/dist/memory/tools/share-project-observation.js +1 -1
- package/dist/memory/tools/write-project-observation.d.ts.map +1 -1
- package/dist/memory/tools/write-project-observation.js +4 -3
- package/dist/sdk/agent-core/agent-loop.d.ts.map +1 -1
- package/dist/sdk/agent-core/agent-loop.js +2 -4
- package/dist/sdk/agent-core/harness/types.d.ts +0 -1
- package/dist/sdk/agent-core/harness/types.d.ts.map +1 -1
- package/dist/sdk/agent-core/index.d.ts +0 -8
- package/dist/sdk/agent-core/index.d.ts.map +1 -1
- package/dist/sdk/agent-core/index.js +0 -9
- package/dist/sdk/ai/index.d.ts +1 -0
- package/dist/sdk/ai/index.d.ts.map +1 -1
- package/dist/sdk/ai/index.js +1 -0
- package/dist/sdk/ai/utils/transient-error.d.ts +28 -0
- package/dist/sdk/ai/utils/transient-error.d.ts.map +1 -0
- package/dist/sdk/ai/utils/transient-error.js +55 -0
- package/dist/sdk/coding-agent/core/agent-session.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/agent-session.js +7 -3
- package/dist/sdk/coding-agent/core/extensions/index.d.ts +1 -1
- package/dist/sdk/coding-agent/core/extensions/index.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/extensions/native-extensions.js +2 -2
- package/dist/sdk/coding-agent/core/extensions/types.d.ts +20 -1
- package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts +9 -4
- package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.js +15 -2
- package/dist/sdk/coding-agent/index.d.ts +1 -1
- package/dist/sdk/coding-agent/index.d.ts.map +1 -1
- package/dist/server/agent-bridge/headless-ui.d.ts +20 -0
- package/dist/server/agent-bridge/headless-ui.d.ts.map +1 -0
- package/dist/server/agent-bridge/headless-ui.js +85 -0
- package/dist/server/agent-bridge/pricing.d.ts +54 -0
- package/dist/server/agent-bridge/pricing.d.ts.map +1 -0
- package/dist/server/agent-bridge/pricing.js +226 -0
- package/dist/server/agent-bridge/rehydrate.d.ts +35 -0
- package/dist/server/agent-bridge/rehydrate.d.ts.map +1 -0
- package/dist/server/agent-bridge/rehydrate.js +122 -0
- package/dist/server/agent-bridge/synthetic-model.d.ts +27 -0
- package/dist/server/agent-bridge/synthetic-model.d.ts.map +1 -0
- package/dist/server/agent-bridge/synthetic-model.js +92 -0
- package/dist/server/agent-bridge.d.ts +17 -1
- package/dist/server/agent-bridge.d.ts.map +1 -1
- package/dist/server/agent-bridge.js +81 -496
- package/dist/server/error-humanizer.d.ts +11 -3
- package/dist/server/error-humanizer.d.ts.map +1 -1
- package/dist/server/error-humanizer.js +11 -3
- package/dist/server/session-stream/compaction-events.d.ts +13 -0
- package/dist/server/session-stream/compaction-events.d.ts.map +1 -0
- package/dist/server/session-stream/compaction-events.js +32 -0
- package/dist/server/session-stream/history-prune.d.ts +35 -0
- package/dist/server/session-stream/history-prune.d.ts.map +1 -0
- package/dist/server/session-stream/history-prune.js +182 -0
- package/dist/server/session-stream/memory.d.ts +48 -0
- package/dist/server/session-stream/memory.d.ts.map +1 -0
- package/dist/server/session-stream/memory.js +136 -0
- package/dist/server/session-stream/replay-tail.d.ts +4 -0
- package/dist/server/session-stream/replay-tail.d.ts.map +1 -0
- package/dist/server/session-stream/replay-tail.js +39 -0
- package/dist/server/session-stream/turn-events.d.ts +33 -0
- package/dist/server/session-stream/turn-events.d.ts.map +1 -0
- package/dist/server/session-stream/turn-events.js +65 -0
- package/dist/server/session-stream/turn-silence.d.ts +8 -0
- package/dist/server/session-stream/turn-silence.d.ts.map +1 -0
- package/dist/server/session-stream/turn-silence.js +72 -0
- package/dist/server/session-stream.d.ts +137 -36
- package/dist/server/session-stream.d.ts.map +1 -1
- package/dist/server/session-stream.js +18 -509
- package/dist/server/storage/observation-ranking.d.ts +14 -0
- package/dist/server/storage/observation-ranking.d.ts.map +1 -0
- package/dist/server/storage/observation-ranking.js +37 -0
- package/dist/server/storage/preflight.d.ts +20 -0
- package/dist/server/storage/preflight.d.ts.map +1 -0
- package/dist/server/storage/preflight.js +22 -0
- package/dist/server/storage/project-binding.d.ts +5 -0
- package/dist/server/storage/project-binding.d.ts.map +1 -0
- package/dist/server/storage/project-binding.js +32 -0
- package/dist/server/storage/rows.d.ts +104 -0
- package/dist/server/storage/rows.d.ts.map +1 -0
- package/dist/server/storage/rows.js +2 -0
- package/dist/server/storage/schema.d.ts +20 -0
- package/dist/server/storage/schema.d.ts.map +1 -0
- package/dist/server/storage/schema.js +134 -0
- package/dist/server/storage/types.d.ts +66 -0
- package/dist/server/storage/types.d.ts.map +1 -0
- package/dist/server/storage/types.js +1 -0
- package/dist/server/storage.d.ts +7 -94
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js +6 -224
- package/dist/server/wire.d.ts +19 -0
- package/dist/server/wire.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/sdk/agent-core/harness/agent-harness.d.ts +0 -92
- package/dist/sdk/agent-core/harness/agent-harness.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/agent-harness.js +0 -899
- package/dist/sdk/agent-core/harness/env/nodejs.d.ts +0 -51
- package/dist/sdk/agent-core/harness/env/nodejs.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/env/nodejs.js +0 -485
- package/dist/sdk/agent-core/harness/prompt-templates.d.ts +0 -48
- package/dist/sdk/agent-core/harness/prompt-templates.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/prompt-templates.js +0 -229
- package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts +0 -26
- package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/session/jsonl-repo.js +0 -100
- package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts +0 -33
- package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/session/jsonl-storage.js +0 -230
- package/dist/sdk/agent-core/harness/session/memory-repo.d.ts +0 -18
- package/dist/sdk/agent-core/harness/session/memory-repo.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/session/memory-repo.js +0 -41
- package/dist/sdk/agent-core/harness/session/memory-storage.d.ts +0 -25
- package/dist/sdk/agent-core/harness/session/memory-storage.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/session/memory-storage.js +0 -113
- package/dist/sdk/agent-core/harness/session/repo-utils.d.ts +0 -11
- package/dist/sdk/agent-core/harness/session/repo-utils.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/session/repo-utils.js +0 -38
- package/dist/sdk/agent-core/harness/skills.d.ts +0 -44
- package/dist/sdk/agent-core/harness/skills.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/skills.js +0 -310
- package/dist/sdk/agent-core/harness/utils/shell-output.d.ts +0 -14
- package/dist/sdk/agent-core/harness/utils/shell-output.d.ts.map +0 -1
- package/dist/sdk/agent-core/harness/utils/shell-output.js +0 -125
- package/dist/sdk/agent-core/node.d.ts +0 -3
- package/dist/sdk/agent-core/node.d.ts.map +0 -1
- package/dist/sdk/agent-core/node.js +0 -2
- package/dist/sdk/agent-core/proxy.d.ts +0 -69
- package/dist/sdk/agent-core/proxy.d.ts.map +0 -1
- package/dist/sdk/agent-core/proxy.js +0 -297
|
@@ -62,26 +62,23 @@ import codeOrderExtension from "../extensions/code-order/index.js";
|
|
|
62
62
|
import { BrowserService } from "../extensions/browser/browser-service.js";
|
|
63
63
|
import subagentExt from "../agent/index.js";
|
|
64
64
|
import designerExtension from "../designer/index.js";
|
|
65
|
+
import logicTraceExtension from "../extensions/logic-trace.js";
|
|
65
66
|
import observationalMemory from "../memory/index.js";
|
|
66
67
|
import { OBSERVATIONAL_MEMORY_CONTEXT_CUSTOM_TYPE, OBSERVATIONAL_MEMORY_SNAPSHOT_CUSTOM_TYPE, } from "../memory/types.js";
|
|
67
68
|
import { fetchAllowedModels as defaultFetchAllowedModels, } from "../relay/models-fetch.js";
|
|
68
69
|
import { humanizeProviderError } from "./error-humanizer.js";
|
|
69
|
-
import { createBridgeConfirm, createStdinConfirmIO, } from "./ui/terminal-confirm.js";
|
|
70
70
|
import { readStudioBinding, getBindingFilePath } from "../studio-binding.js";
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const SPECTRAL_PROXY_OPENAI = "spectral-proxy-openai";
|
|
83
|
-
const SPECTRAL_PROXY_USER_MODEL = "spectral-proxy-user-model";
|
|
84
|
-
const KIMI_K2_7_CODE_CONTEXT_WINDOW = 262_144;
|
|
71
|
+
// Facade imports: cohesive helpers extracted verbatim to `./agent-bridge/` modules.
|
|
72
|
+
import { calculateCredits, getModelCost, resolveCreditRatesForModel, } from "./agent-bridge/pricing.js";
|
|
73
|
+
import { SPECTRAL_PROXY_OPENAI, SPECTRAL_PROXY_USER_MODEL, inferSyntheticContextWindow, inferSyntheticOpenAICompat, inferSyntheticThinkingLevelMap, } from "./agent-bridge/synthetic-model.js";
|
|
74
|
+
import { parseWireToolEvents, sanitizeRehydratedBlock, toRestoredMemorySnapshot, } from "./agent-bridge/rehydrate.js";
|
|
75
|
+
import { createHeadlessUIContext } from "./agent-bridge/headless-ui.js";
|
|
76
|
+
// Facade re-exports: moved helpers remain importable from this module so
|
|
77
|
+
// existing (and future) importers of `agent-bridge.js` are unaffected.
|
|
78
|
+
export { bareModelId, calculateCredits, getModelCost, lookupPricing, } from "./agent-bridge/pricing.js";
|
|
79
|
+
export { SPECTRAL_PROXY_OPENAI, SPECTRAL_PROXY_USER_MODEL, inferSyntheticContextWindow, inferSyntheticOpenAICompat, inferSyntheticThinkingLevelMap, } from "./agent-bridge/synthetic-model.js";
|
|
80
|
+
export { parseWireToolEvents, sanitizeRehydratedBlock, toRestoredMemorySnapshot, } from "./agent-bridge/rehydrate.js";
|
|
81
|
+
export { createHeadlessUIContext } from "./agent-bridge/headless-ui.js";
|
|
85
82
|
/**
|
|
86
83
|
* Walk ancestor directories from `cwd` up to the filesystem root, collecting
|
|
87
84
|
* any existing skill directories at the given relative paths (e.g.
|
|
@@ -133,280 +130,7 @@ function extractTextFromContent(content) {
|
|
|
133
130
|
}
|
|
134
131
|
return out;
|
|
135
132
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Token pricing per model (USD per 1M tokens). Matches provider list
|
|
138
|
-
* prices as of May 2026. Used to compute token cost server-side when
|
|
139
|
-
* spectral's own cost field is unavailable (synthetic proxy models are
|
|
140
|
-
* registered with zero cost to avoid agent-side billing).
|
|
141
|
-
*
|
|
142
|
-
* Keys are matched as prefix substrings against modelId, so
|
|
143
|
-
* `"gpt-5"` covers both `gpt-5` and any
|
|
144
|
-
* future point-release.
|
|
145
|
-
*/
|
|
146
|
-
const MODEL_PRICING = [
|
|
147
|
-
// OpenAI models
|
|
148
|
-
{
|
|
149
|
-
prefix: "gpt-5.5",
|
|
150
|
-
input: 1.75,
|
|
151
|
-
output: 14,
|
|
152
|
-
cacheWrite: 14,
|
|
153
|
-
cacheRead: 0.35,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
prefix: "gpt-5.4",
|
|
157
|
-
input: 1.75,
|
|
158
|
-
output: 14,
|
|
159
|
-
cacheWrite: 14,
|
|
160
|
-
cacheRead: 0.35,
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
prefix: "gpt-5.3",
|
|
164
|
-
input: 1.75,
|
|
165
|
-
output: 14,
|
|
166
|
-
cacheWrite: 14,
|
|
167
|
-
cacheRead: 0.35,
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
prefix: "gpt-5.2",
|
|
171
|
-
input: 1.75,
|
|
172
|
-
output: 14,
|
|
173
|
-
cacheWrite: 14,
|
|
174
|
-
cacheRead: 0.35,
|
|
175
|
-
},
|
|
176
|
-
{ prefix: "gpt-5.1", input: 2, output: 8, cacheWrite: 8, cacheRead: 0.5 },
|
|
177
|
-
{ prefix: "gpt-5", input: 1.25, output: 10, cacheWrite: 10, cacheRead: 0.25 },
|
|
178
|
-
{ prefix: "gpt-4.1", input: 2, output: 8, cacheWrite: 8, cacheRead: 0.5 },
|
|
179
|
-
{ prefix: "gpt-4o", input: 2.5, output: 10, cacheWrite: 10, cacheRead: 1.25 },
|
|
180
|
-
{ prefix: "gpt-4-turbo", input: 10, output: 30, cacheWrite: 0, cacheRead: 0 },
|
|
181
|
-
{ prefix: "gpt-4", input: 30, output: 60, cacheWrite: 0, cacheRead: 0 },
|
|
182
|
-
{
|
|
183
|
-
prefix: "gpt-3.5-turbo",
|
|
184
|
-
input: 0.5,
|
|
185
|
-
output: 1.5,
|
|
186
|
-
cacheWrite: 0,
|
|
187
|
-
cacheRead: 0,
|
|
188
|
-
},
|
|
189
|
-
{ prefix: "o1", input: 15, output: 60, cacheWrite: 0, cacheRead: 0 },
|
|
190
|
-
{ prefix: "o3-mini", input: 1.1, output: 4.4, cacheWrite: 0, cacheRead: 0 },
|
|
191
|
-
{ prefix: "o4-mini", input: 1.1, output: 4.4, cacheWrite: 0, cacheRead: 0 },
|
|
192
|
-
// Google Gemini models
|
|
193
|
-
{
|
|
194
|
-
prefix: "gemini-2.5-pro",
|
|
195
|
-
input: 1.25,
|
|
196
|
-
output: 10,
|
|
197
|
-
cacheWrite: 0,
|
|
198
|
-
cacheRead: 0,
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
prefix: "gemini-2.5-flash",
|
|
202
|
-
input: 0.15,
|
|
203
|
-
output: 0.6,
|
|
204
|
-
cacheWrite: 0,
|
|
205
|
-
cacheRead: 0,
|
|
206
|
-
},
|
|
207
|
-
// DeepSeek models
|
|
208
|
-
{
|
|
209
|
-
prefix: "deepseek-v3",
|
|
210
|
-
input: 0.27,
|
|
211
|
-
output: 1.1,
|
|
212
|
-
cacheWrite: 0,
|
|
213
|
-
cacheRead: 0,
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
prefix: "deepseek-r1",
|
|
217
|
-
input: 0.55,
|
|
218
|
-
output: 2.19,
|
|
219
|
-
cacheWrite: 0,
|
|
220
|
-
cacheRead: 0,
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
prefix: "deepseek/deepseek-v3",
|
|
224
|
-
input: 0.27,
|
|
225
|
-
output: 1.1,
|
|
226
|
-
cacheWrite: 0,
|
|
227
|
-
cacheRead: 0,
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
prefix: "deepseek/deepseek-r1",
|
|
231
|
-
input: 0.55,
|
|
232
|
-
output: 2.19,
|
|
233
|
-
cacheWrite: 0,
|
|
234
|
-
cacheRead: 0,
|
|
235
|
-
},
|
|
236
|
-
// Meta Llama models (common via OpenRouter-compatible endpoints)
|
|
237
|
-
{
|
|
238
|
-
prefix: "meta-llama/llama-4",
|
|
239
|
-
input: 0.2,
|
|
240
|
-
output: 0.8,
|
|
241
|
-
cacheWrite: 0,
|
|
242
|
-
cacheRead: 0,
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
prefix: "meta-llama/llama-3.3",
|
|
246
|
-
input: 0.2,
|
|
247
|
-
output: 0.5,
|
|
248
|
-
cacheWrite: 0,
|
|
249
|
-
cacheRead: 0,
|
|
250
|
-
},
|
|
251
|
-
];
|
|
252
|
-
/**
|
|
253
|
-
* Strip vendor prefix to extract the bare model name.
|
|
254
|
-
* e.g. "openai/gpt-5.3-codex" → "gpt-5.3-codex".
|
|
255
|
-
* Returns the original string when no separator is present.
|
|
256
|
-
*/
|
|
257
|
-
function bareModelId(modelId) {
|
|
258
|
-
const idx = modelId.lastIndexOf("/");
|
|
259
|
-
return idx === -1 ? modelId : modelId.slice(idx + 1);
|
|
260
|
-
}
|
|
261
|
-
function inferSyntheticContextWindow(model) {
|
|
262
|
-
if (typeof model.contextWindow === "number" &&
|
|
263
|
-
Number.isFinite(model.contextWindow)) {
|
|
264
|
-
return model.contextWindow;
|
|
265
|
-
}
|
|
266
|
-
const modelId = model.modelId.toLowerCase();
|
|
267
|
-
const bare = bareModelId(modelId);
|
|
268
|
-
if (modelId === "moonshotai/kimi-k2.7-code" ||
|
|
269
|
-
bare === "kimi-k2.7-code" ||
|
|
270
|
-
bare === "local-openrouter-kimi") {
|
|
271
|
-
return KIMI_K2_7_CODE_CONTEXT_WINDOW;
|
|
272
|
-
}
|
|
273
|
-
return 0;
|
|
274
|
-
}
|
|
275
133
|
/** Get model cost from backend credit rates, falling back to hardcoded pricing table. */
|
|
276
|
-
function getModelCost(m) {
|
|
277
|
-
// Prefer backend credit rates when configured
|
|
278
|
-
const hasCredits = m.creditInputPer1M != null ||
|
|
279
|
-
m.creditOutputPer1M != null ||
|
|
280
|
-
m.creditCacheReadPer1M != null ||
|
|
281
|
-
m.creditCacheWritePer1M != null;
|
|
282
|
-
if (hasCredits) {
|
|
283
|
-
return {
|
|
284
|
-
input: m.creditInputPer1M ?? 0,
|
|
285
|
-
output: m.creditOutputPer1M ?? 0,
|
|
286
|
-
cacheRead: m.creditCacheReadPer1M ?? 0,
|
|
287
|
-
cacheWrite: m.creditCacheWritePer1M ?? 0,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
// Fall back to hardcoded pricing table when credits aren't configured
|
|
291
|
-
const pricing = lookupPricing(m.modelId);
|
|
292
|
-
return pricing
|
|
293
|
-
? {
|
|
294
|
-
input: pricing.input,
|
|
295
|
-
output: pricing.output,
|
|
296
|
-
cacheRead: pricing.cacheRead,
|
|
297
|
-
cacheWrite: pricing.cacheWrite,
|
|
298
|
-
}
|
|
299
|
-
: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
300
|
-
}
|
|
301
|
-
/** Look up pricing for a modelId. Returns null when unknown. */
|
|
302
|
-
function lookupPricing(modelId) {
|
|
303
|
-
const bare = bareModelId(modelId);
|
|
304
|
-
for (const entry of MODEL_PRICING) {
|
|
305
|
-
if (modelId.startsWith(entry.prefix) || bare.startsWith(entry.prefix)) {
|
|
306
|
-
return {
|
|
307
|
-
input: entry.input,
|
|
308
|
-
output: entry.output,
|
|
309
|
-
cacheWrite: entry.cacheWrite,
|
|
310
|
-
cacheRead: entry.cacheRead,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
function inferSyntheticThinkingLevelMap(model) {
|
|
317
|
-
if (!model.supportsReasoning)
|
|
318
|
-
return undefined;
|
|
319
|
-
const modelId = model.modelId.toLowerCase();
|
|
320
|
-
const bare = bareModelId(modelId);
|
|
321
|
-
if (model.provider === "built-in" &&
|
|
322
|
-
(modelId.includes("gpt-5") || bare.includes("gpt-5"))) {
|
|
323
|
-
return {
|
|
324
|
-
off: "none",
|
|
325
|
-
minimal: "minimal",
|
|
326
|
-
low: "low",
|
|
327
|
-
medium: "medium",
|
|
328
|
-
high: "high",
|
|
329
|
-
xhigh: "xhigh",
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
return undefined;
|
|
333
|
-
}
|
|
334
|
-
function inferSyntheticOpenAICompat(model) {
|
|
335
|
-
const bare = bareModelId(model.modelId);
|
|
336
|
-
const isDeepSeek = model.provider === "deepseek" ||
|
|
337
|
-
model.modelId.startsWith("deepseek/") ||
|
|
338
|
-
bare.startsWith("deepseek");
|
|
339
|
-
if (isDeepSeek) {
|
|
340
|
-
return {
|
|
341
|
-
thinkingFormat: "deepseek",
|
|
342
|
-
requiresReasoningContentOnAssistantMessages: true,
|
|
343
|
-
supportsDeveloperRole: false,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (model.provider === "built-in") {
|
|
347
|
-
const compat = {
|
|
348
|
-
// Built-in models are proxied through the backend, which forwards a
|
|
349
|
-
// session-affinity key to OpenRouter for prompt-cache sticky routing.
|
|
350
|
-
// Sending the real per-session id from the CLI lets the backend use it
|
|
351
|
-
// instead of a coarser machine/team fallback, maximizing cache hits on
|
|
352
|
-
// large multi-turn agentic prompts.
|
|
353
|
-
sendSessionAffinityHeaders: true,
|
|
354
|
-
};
|
|
355
|
-
if (model.modelId.toLowerCase().includes("gpt-5") ||
|
|
356
|
-
bare.toLowerCase().includes("gpt-5")) {
|
|
357
|
-
compat.thinkingFormat = "openai";
|
|
358
|
-
compat.supportsReasoningEffort = true;
|
|
359
|
-
compat.supportsStore = false;
|
|
360
|
-
}
|
|
361
|
-
return compat;
|
|
362
|
-
}
|
|
363
|
-
if (model.provider === "openrouter") {
|
|
364
|
-
const compat = {
|
|
365
|
-
thinkingFormat: "openrouter",
|
|
366
|
-
};
|
|
367
|
-
return compat;
|
|
368
|
-
}
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Calculate credits from token usage using per-model credit rates.
|
|
373
|
-
*
|
|
374
|
-
* NOTE: We intentionally keep higher precision here (no 2-decimal rounding)
|
|
375
|
-
* so small turns don't collapse to 0.00 in live UI aggregation. Rendering
|
|
376
|
-
* layers decide final display precision.
|
|
377
|
-
*/
|
|
378
|
-
function calculateCredits(inputTokens, outputTokens, cacheReadTokens = 0, cacheWriteTokens = 0, creditInputPer1M, creditOutputPer1M, creditCachedInputPer1M, creditCacheReadPer1M, creditCacheWritePer1M) {
|
|
379
|
-
const inputRate = creditInputPer1M ?? 0;
|
|
380
|
-
const outputRate = creditOutputPer1M ?? 0;
|
|
381
|
-
const cachedInputRate = creditCachedInputPer1M ?? 0;
|
|
382
|
-
const cacheReadRate = creditCacheReadPer1M ?? 0;
|
|
383
|
-
const cacheWriteRate = creditCacheWritePer1M ?? 0;
|
|
384
|
-
const credits = (inputTokens / 1_000_000) * inputRate +
|
|
385
|
-
(outputTokens / 1_000_000) * outputRate +
|
|
386
|
-
(cacheReadTokens / 1_000_000) * cacheReadRate +
|
|
387
|
-
(cacheWriteTokens / 1_000_000) * cacheWriteRate;
|
|
388
|
-
if (inputRate === 0 &&
|
|
389
|
-
outputRate === 0 &&
|
|
390
|
-
cacheReadRate === 0 &&
|
|
391
|
-
cacheWriteRate === 0) {
|
|
392
|
-
if (cachedInputRate > 0) {
|
|
393
|
-
return (((inputTokens + cacheReadTokens + cacheWriteTokens) / 1_000_000) *
|
|
394
|
-
cachedInputRate);
|
|
395
|
-
}
|
|
396
|
-
return 0;
|
|
397
|
-
}
|
|
398
|
-
return credits;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Parse the newline-delimited JSON of wire events persisted alongside an
|
|
402
|
-
* assistant message and extract all tool_call / tool_result events.
|
|
403
|
-
*
|
|
404
|
-
* These are used during session rehydration to reconstruct the full tool
|
|
405
|
-
* interaction history (call → result) so the LLM context is complete —
|
|
406
|
-
* without this, reconnected sessions would see only the assistant text
|
|
407
|
-
* and never the tool results, causing the model to get confused about
|
|
408
|
-
* the conversation state.
|
|
409
|
-
*/
|
|
410
134
|
/**
|
|
411
135
|
* Map a wire `ImageAttachment` onto a spectral `ImageContent` block.
|
|
412
136
|
*
|
|
@@ -434,115 +158,6 @@ function toImageContent(image) {
|
|
|
434
158
|
}
|
|
435
159
|
return null;
|
|
436
160
|
}
|
|
437
|
-
function parseWireToolEvents(eventsJsonl) {
|
|
438
|
-
const toolCalls = [];
|
|
439
|
-
const toolResults = [];
|
|
440
|
-
if (!eventsJsonl)
|
|
441
|
-
return { toolCalls, toolResults };
|
|
442
|
-
for (const line of eventsJsonl.split("\n")) {
|
|
443
|
-
const trimmed = line.trim();
|
|
444
|
-
if (!trimmed)
|
|
445
|
-
continue;
|
|
446
|
-
try {
|
|
447
|
-
const ev = JSON.parse(trimmed);
|
|
448
|
-
if (ev.type === "tool_call") {
|
|
449
|
-
toolCalls.push({
|
|
450
|
-
id: ev.id,
|
|
451
|
-
name: ev.name,
|
|
452
|
-
arguments: ev.args,
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
else if (ev.type === "tool_result") {
|
|
456
|
-
toolResults.push({
|
|
457
|
-
id: ev.id,
|
|
458
|
-
result: ev.result,
|
|
459
|
-
isError: ev.isError ?? false,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
catch {
|
|
464
|
-
// Skip malformed JSON lines — they won't be meaningful for
|
|
465
|
-
// rehydration and we'd rather keep the session alive than fail.
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return { toolCalls, toolResults };
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Safety clean-up for content blocks rehydrated from persisted wire events.
|
|
472
|
-
*
|
|
473
|
-
* Rehydrated tool-result content is bounded for the model-facing context,
|
|
474
|
-
* while the original wire event remains available to the UI for rendering
|
|
475
|
-
* images and other rich results.
|
|
476
|
-
*/
|
|
477
|
-
const MAX_REHYDRATED_TEXT = 100_000;
|
|
478
|
-
/**
|
|
479
|
-
* Ceiling for blocks that already carry an offload footer (`Full output:`).
|
|
480
|
-
* These blocks are a bounded preview + a re-readable path, so cutting them
|
|
481
|
-
* with the generic limit would destroy the footer. Keep them whole up to
|
|
482
|
-
* this size; larger ones lose their middle but keep head + footer.
|
|
483
|
-
*/
|
|
484
|
-
const MAX_REHYDRATED_OFFLOAD_TEXT = 200_000;
|
|
485
|
-
function sanitizeRehydratedBlock(block) {
|
|
486
|
-
// Tool-result image blocks are not accepted by every provider; the raw
|
|
487
|
-
// result remains in events_jsonl for the UI, while the model gets a compact reference.
|
|
488
|
-
if (block.type === "image") {
|
|
489
|
-
// Hosted images carry a url instead of inline bytes — print that rather
|
|
490
|
-
// than a meaningless "0 bytes base64".
|
|
491
|
-
const hostedUrl = typeof block.url === "string" && block.url ? block.url : undefined;
|
|
492
|
-
const descriptor = hostedUrl
|
|
493
|
-
? `[Image: ${block.mimeType ?? "image/png"}, url: ${hostedUrl}]`
|
|
494
|
-
: `[Image: ${block.mimeType ?? "image/png"}, ${(typeof block.data === "string" ? block.data.length : 0).toLocaleString()} bytes base64]`;
|
|
495
|
-
return {
|
|
496
|
-
type: "text",
|
|
497
|
-
text: descriptor +
|
|
498
|
-
`\n(Image data is available in the raw MCP result.)`,
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
// Truncate oversized text blocks to prevent context overflow.
|
|
502
|
-
if (block.type !== "text")
|
|
503
|
-
return block;
|
|
504
|
-
if (block.text.includes("Full output:")) {
|
|
505
|
-
if (block.text.length <= MAX_REHYDRATED_OFFLOAD_TEXT)
|
|
506
|
-
return block;
|
|
507
|
-
// Keep the head (preview) and the tail (offload footer), drop the middle.
|
|
508
|
-
const keepHead = Math.floor(MAX_REHYDRATED_OFFLOAD_TEXT * 0.7);
|
|
509
|
-
const keepTail = MAX_REHYDRATED_OFFLOAD_TEXT - keepHead;
|
|
510
|
-
const omitted = block.text.length - keepHead - keepTail;
|
|
511
|
-
return {
|
|
512
|
-
...block,
|
|
513
|
-
text: block.text.slice(0, keepHead) +
|
|
514
|
-
`\n\n[... ${omitted.toLocaleString()} bytes omitted from rehydrated offload preview ...]\n\n` +
|
|
515
|
-
block.text.slice(block.text.length - keepTail),
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
if (block.text.length <= MAX_REHYDRATED_TEXT)
|
|
519
|
-
return block;
|
|
520
|
-
const omitted = block.text.length - MAX_REHYDRATED_TEXT;
|
|
521
|
-
return {
|
|
522
|
-
...block,
|
|
523
|
-
text: block.text.slice(0, MAX_REHYDRATED_TEXT) +
|
|
524
|
-
`\n\n[truncated — ${omitted.toLocaleString()} bytes omitted]`,
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
function normalizeSnapshotDetails(details) {
|
|
528
|
-
if (details.version === 4)
|
|
529
|
-
return details;
|
|
530
|
-
return {
|
|
531
|
-
type: "observational-memory",
|
|
532
|
-
version: 4,
|
|
533
|
-
observations: details.observations,
|
|
534
|
-
reflections: details.reflections,
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
function toRestoredMemorySnapshot(snapshot) {
|
|
538
|
-
return {
|
|
539
|
-
type: "observational-memory-snapshot",
|
|
540
|
-
version: 1,
|
|
541
|
-
coveredSourceCount: snapshot.coveredSourceCount,
|
|
542
|
-
summary: snapshot.summary,
|
|
543
|
-
details: normalizeSnapshotDetails(snapshot.details),
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
161
|
/**
|
|
547
162
|
* Inactivity-based prompt hang watchdog. Unlike a fixed wall-clock deadline,
|
|
548
163
|
* this only fires when the agent session has emitted NO *meaningful* progress
|
|
@@ -655,9 +270,24 @@ export class AgentBridge {
|
|
|
655
270
|
* timer flushes it once the minimum interval has elapsed.
|
|
656
271
|
*/
|
|
657
272
|
subagentProgressThrottle = new Map();
|
|
273
|
+
/**
|
|
274
|
+
* toolCallId → startedAt captured at `tool_execution_start` so the
|
|
275
|
+
* terminal `tool_result` can carry the real start time (durations
|
|
276
|
+
* end-to-end). Entries with no end event are bounded: more than 2000
|
|
277
|
+
* orphans means ids are never resolving, so the oldest are cleared.
|
|
278
|
+
*/
|
|
279
|
+
toolStartedAt = new Map();
|
|
658
280
|
constructor(opts) {
|
|
659
281
|
this.opts = opts;
|
|
660
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Resolve credit rates for a subagent result. Subagents may run a
|
|
285
|
+
* different model than the parent — see pricing.resolveCreditRatesForModel
|
|
286
|
+
* for the model-matching rule.
|
|
287
|
+
*/
|
|
288
|
+
resolveSubagentCreditRates(modelId) {
|
|
289
|
+
return resolveCreditRatesForModel(modelId, this.allowedModels, this.activeCreditRates);
|
|
290
|
+
}
|
|
661
291
|
/**
|
|
662
292
|
* Create the spectral session, wire up subscription, and return.
|
|
663
293
|
* Throws on creation failure (caller should surface to client).
|
|
@@ -708,6 +338,14 @@ export class AgentBridge {
|
|
|
708
338
|
async (ext) => {
|
|
709
339
|
designerExtension(ext);
|
|
710
340
|
},
|
|
341
|
+
// Logic trace: keeps the ONE logic.aexol file in the bound Studio
|
|
342
|
+
// project refreshed the same way observations are (turn_end +
|
|
343
|
+
// threshold + singleton + passive). Registered BEFORE
|
|
344
|
+
// observationalMemory so its forced session_before_compact flush runs
|
|
345
|
+
// before the memory compaction hook produces the summary.
|
|
346
|
+
async (ext) => {
|
|
347
|
+
logicTraceExtension(ext);
|
|
348
|
+
},
|
|
711
349
|
async (ext) => {
|
|
712
350
|
observationalMemory(ext);
|
|
713
351
|
},
|
|
@@ -1930,6 +1568,10 @@ export class AgentBridge {
|
|
|
1930
1568
|
if (ev.toolName !== "subagent") {
|
|
1931
1569
|
this.startToolExecutionTimer();
|
|
1932
1570
|
}
|
|
1571
|
+
// pi agent events carry no timestamps; Date.now() at emit time is
|
|
1572
|
+
// the same source the subagent tool-progress path uses. Computed once
|
|
1573
|
+
// per execution start so subagent_start and tool_call share the stamp.
|
|
1574
|
+
const startedAt = Date.now();
|
|
1933
1575
|
// Emit subagent_start for subagent tool invocations (Option B frontend panels).
|
|
1934
1576
|
if (ev.toolName === "subagent") {
|
|
1935
1577
|
// The parent prompt is now waiting on the child agent. Pause the
|
|
@@ -1945,6 +1587,7 @@ export class AgentBridge {
|
|
|
1945
1587
|
const se = {
|
|
1946
1588
|
type: "subagent_start",
|
|
1947
1589
|
toolCallId: ev.toolCallId,
|
|
1590
|
+
startedAt,
|
|
1948
1591
|
mode,
|
|
1949
1592
|
agent: typeof args?.agent === "string" ? args.agent : undefined,
|
|
1950
1593
|
task: typeof args?.task === "string" ? args.task : undefined,
|
|
@@ -1963,7 +1606,16 @@ export class AgentBridge {
|
|
|
1963
1606
|
id: ev.toolCallId,
|
|
1964
1607
|
name: ev.toolName,
|
|
1965
1608
|
args: ev.args,
|
|
1609
|
+
startedAt,
|
|
1966
1610
|
});
|
|
1611
|
+
// Persist the same start stamp so the terminal `tool_result` below
|
|
1612
|
+
// can echo it (the wire schema declares `tool_result.startedAt`).
|
|
1613
|
+
this.toolStartedAt.set(ev.toolCallId, startedAt);
|
|
1614
|
+
if (this.toolStartedAt.size > 2000) {
|
|
1615
|
+
const oldest = this.toolStartedAt.keys().next().value;
|
|
1616
|
+
if (oldest !== undefined)
|
|
1617
|
+
this.toolStartedAt.delete(oldest);
|
|
1618
|
+
}
|
|
1967
1619
|
return;
|
|
1968
1620
|
}
|
|
1969
1621
|
case "tool_execution_update": {
|
|
@@ -2075,27 +1727,37 @@ export class AgentBridge {
|
|
|
2075
1727
|
}
|
|
2076
1728
|
return "(no output)";
|
|
2077
1729
|
};
|
|
2078
|
-
const results = details.results.map((r) =>
|
|
2079
|
-
|
|
2080
|
-
agentSource: r.agentSource ?? "unknown",
|
|
2081
|
-
task: r.task,
|
|
2082
|
-
exitCode: r.exitCode,
|
|
2083
|
-
output: getOutput(r.messages),
|
|
2084
|
-
model: r.model,
|
|
2085
|
-
errorMessage: r.errorMessage,
|
|
2086
|
-
stopReason: r.stopReason,
|
|
2087
|
-
step: r.step,
|
|
2088
|
-
systemPrompt: r.systemPrompt,
|
|
2089
|
-
firstMessage: r.firstMessage,
|
|
2090
|
-
usage: {
|
|
1730
|
+
const results = details.results.map((r) => {
|
|
1731
|
+
const usage = {
|
|
2091
1732
|
inputTokens: r.usage?.input ?? 0,
|
|
2092
1733
|
outputTokens: r.usage?.output ?? 0,
|
|
2093
1734
|
cacheReadTokens: r.usage?.cacheRead ?? 0,
|
|
2094
1735
|
cacheWriteTokens: r.usage?.cacheWrite ?? 0,
|
|
2095
1736
|
cost: r.usage?.cost ?? 0,
|
|
2096
1737
|
turns: r.usage?.turns ?? 0,
|
|
2097
|
-
}
|
|
2098
|
-
|
|
1738
|
+
};
|
|
1739
|
+
// Credits use per-subagent-model rates when the model is known
|
|
1740
|
+
// (subagents may run a different model than the parent);
|
|
1741
|
+
// otherwise the parent's active rates apply.
|
|
1742
|
+
const rates = this.resolveSubagentCreditRates(r.model);
|
|
1743
|
+
const creditsUsed = calculateCredits(usage.inputTokens, usage.outputTokens, usage.cacheReadTokens, usage.cacheWriteTokens, rates?.creditInputPer1M, rates?.creditOutputPer1M, rates?.creditCachedInputPer1M, rates?.creditCacheReadPer1M, rates?.creditCacheWritePer1M);
|
|
1744
|
+
return {
|
|
1745
|
+
agent: r.agent,
|
|
1746
|
+
agentSource: r.agentSource ??
|
|
1747
|
+
"unknown",
|
|
1748
|
+
task: r.task,
|
|
1749
|
+
exitCode: r.exitCode,
|
|
1750
|
+
output: getOutput(r.messages),
|
|
1751
|
+
model: r.model,
|
|
1752
|
+
errorMessage: r.errorMessage,
|
|
1753
|
+
stopReason: r.stopReason,
|
|
1754
|
+
step: r.step,
|
|
1755
|
+
systemPrompt: r.systemPrompt,
|
|
1756
|
+
firstMessage: r.firstMessage,
|
|
1757
|
+
attempts: r.attempts,
|
|
1758
|
+
usage: { ...usage, creditsUsed },
|
|
1759
|
+
};
|
|
1760
|
+
});
|
|
2099
1761
|
const totalUsage = results.reduce((acc, r) => ({
|
|
2100
1762
|
inputTokens: acc.inputTokens + r.usage.inputTokens,
|
|
2101
1763
|
outputTokens: acc.outputTokens + r.usage.outputTokens,
|
|
@@ -2103,6 +1765,7 @@ export class AgentBridge {
|
|
|
2103
1765
|
cacheWriteTokens: acc.cacheWriteTokens + r.usage.cacheWriteTokens,
|
|
2104
1766
|
cost: acc.cost + r.usage.cost,
|
|
2105
1767
|
turns: acc.turns + r.usage.turns,
|
|
1768
|
+
creditsUsed: acc.creditsUsed + (r.usage.creditsUsed ?? 0),
|
|
2106
1769
|
}), {
|
|
2107
1770
|
inputTokens: 0,
|
|
2108
1771
|
outputTokens: 0,
|
|
@@ -2110,10 +1773,13 @@ export class AgentBridge {
|
|
|
2110
1773
|
cacheWriteTokens: 0,
|
|
2111
1774
|
cost: 0,
|
|
2112
1775
|
turns: 0,
|
|
1776
|
+
creditsUsed: 0,
|
|
2113
1777
|
});
|
|
2114
1778
|
const se = {
|
|
2115
1779
|
type: "subagent_end",
|
|
2116
1780
|
toolCallId: ev.toolCallId,
|
|
1781
|
+
startedAt: this.toolStartedAt.get(ev.toolCallId),
|
|
1782
|
+
finishedAt: Date.now(),
|
|
2117
1783
|
mode,
|
|
2118
1784
|
results,
|
|
2119
1785
|
totalUsage,
|
|
@@ -2127,7 +1793,10 @@ export class AgentBridge {
|
|
|
2127
1793
|
id: ev.toolCallId,
|
|
2128
1794
|
result: ev.result,
|
|
2129
1795
|
isError: ev.isError,
|
|
1796
|
+
startedAt: this.toolStartedAt.get(ev.toolCallId) ?? Date.now(),
|
|
1797
|
+
finishedAt: Date.now(),
|
|
2130
1798
|
});
|
|
1799
|
+
this.toolStartedAt.delete(ev.toolCallId);
|
|
2131
1800
|
return;
|
|
2132
1801
|
}
|
|
2133
1802
|
case "message_end": {
|
|
@@ -2327,87 +1996,3 @@ export class AgentBridge {
|
|
|
2327
1996
|
}
|
|
2328
1997
|
}
|
|
2329
1998
|
}
|
|
2330
|
-
// ---------------------------------------------------------------------------
|
|
2331
|
-
// Headless UI context
|
|
2332
|
-
// ---------------------------------------------------------------------------
|
|
2333
|
-
/**
|
|
2334
|
-
* Detect the memory subsystem from a notification message text.
|
|
2335
|
-
* The memory extension prefixes all messages with "Observational memory:".
|
|
2336
|
-
*/
|
|
2337
|
-
function detectMemorySystem(message) {
|
|
2338
|
-
if (!message.startsWith("Observational memory:"))
|
|
2339
|
-
return undefined;
|
|
2340
|
-
const lower = message.toLowerCase();
|
|
2341
|
-
if (lower.includes("observer"))
|
|
2342
|
-
return "memory_observer";
|
|
2343
|
-
if (lower.includes("compaction") || lower.includes("compact"))
|
|
2344
|
-
return "memory_compaction";
|
|
2345
|
-
if (lower.includes("reflection") || lower.includes("reflect"))
|
|
2346
|
-
return "memory_reflection";
|
|
2347
|
-
if (lower.includes("pruner") || lower.includes("prune"))
|
|
2348
|
-
return "memory_pruner";
|
|
2349
|
-
// Keep generic observational-memory messages visible in the landing badge.
|
|
2350
|
-
return "memory_observer";
|
|
2351
|
-
}
|
|
2352
|
-
/**
|
|
2353
|
-
* Detect subsystem from notification messages by known prefix.
|
|
2354
|
-
* Returns undefined for generic extension messages without a matching prefix.
|
|
2355
|
-
*/
|
|
2356
|
-
function detectNotifSystem(message) {
|
|
2357
|
-
if (message.startsWith("[spectral-vision]"))
|
|
2358
|
-
return "vision";
|
|
2359
|
-
return detectMemorySystem(message);
|
|
2360
|
-
}
|
|
2361
|
-
/**
|
|
2362
|
-
* Create a minimal ExtensionUIContext that forwards `notify()` calls as
|
|
2363
|
-
* `agent_notification` wire events, and renders `confirm()` as a terminal-
|
|
2364
|
-
* native permission prompt on serve's stdout (the terminal `spectral serve`
|
|
2365
|
-
* runs in) so extensions like desktop-control can request real user approval
|
|
2366
|
-
* while the user chats via the web UI. A prompt also emits an
|
|
2367
|
-
* `agent_notification` ("Approval required in terminal: …") so web users know
|
|
2368
|
-
* to look at the terminal. Confirmations are serialized across sessions and
|
|
2369
|
-
* auto-deny on timeout (SPECTRAL_CONFIRM_TIMEOUT_MS, default 5 min) or when
|
|
2370
|
-
* stdin is not a TTY. All other interactive UI methods (select/input/custom/
|
|
2371
|
-
* editor) remain no-ops resolving `undefined`.
|
|
2372
|
-
*/
|
|
2373
|
-
function createHeadlessUIContext(emit) {
|
|
2374
|
-
const terminalIO = createStdinConfirmIO();
|
|
2375
|
-
// Defer to a Proxy so we don't need to stub every method.
|
|
2376
|
-
// `notify` and `confirm` are the methods called by extensions in serve mode
|
|
2377
|
-
// (observational memory, MCP status bar updates, spectral-vision,
|
|
2378
|
-
// desktop-control).
|
|
2379
|
-
const handler = {
|
|
2380
|
-
get(_target, prop) {
|
|
2381
|
-
if (prop === "notify") {
|
|
2382
|
-
return (message, type, metadata) => {
|
|
2383
|
-
const level = type ?? "info";
|
|
2384
|
-
const system = detectNotifSystem(message);
|
|
2385
|
-
if (system?.startsWith("memory_")) {
|
|
2386
|
-
console.info(`[AgentBridge][memory][${level}] ${message}`);
|
|
2387
|
-
}
|
|
2388
|
-
else if (system === "vision") {
|
|
2389
|
-
console.info(`[AgentBridge][vision][${level}] ${message}`);
|
|
2390
|
-
}
|
|
2391
|
-
emit({
|
|
2392
|
-
type: "agent_notification",
|
|
2393
|
-
message,
|
|
2394
|
-
level,
|
|
2395
|
-
system,
|
|
2396
|
-
dcpLiteTelemetry: metadata?.dcpLiteTelemetry,
|
|
2397
|
-
});
|
|
2398
|
-
};
|
|
2399
|
-
}
|
|
2400
|
-
// All other methods: return a no-op function or undefined.
|
|
2401
|
-
// Methods that return Promises (select, confirm, input, custom, editor)
|
|
2402
|
-
if (prop === "confirm") {
|
|
2403
|
-
return createBridgeConfirm(emit, terminalIO);
|
|
2404
|
-
}
|
|
2405
|
-
// resolve to `undefined`. `confirm` above is the one interactive method
|
|
2406
|
-
// with a real terminal-native implementation.
|
|
2407
|
-
// Methods that set state (setStatus, setWorkingMessage, setWidget, etc.)
|
|
2408
|
-
// are safe to no-op.
|
|
2409
|
-
return () => undefined;
|
|
2410
|
-
},
|
|
2411
|
-
};
|
|
2412
|
-
return new Proxy({}, handler);
|
|
2413
|
-
}
|