@bitkyc08/opencodex 2.98.0 → 2.99.0-preview.20261108
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/bin/ocx.mjs +6 -19
- package/gui/dist/assets/{App-6TFtZsUF.css → App-C1hGwaN1.css} +1 -1
- package/gui/dist/assets/App-CWz0areF.js +59 -0
- package/gui/dist/assets/Tray-BosDoskm.js +1 -0
- package/gui/dist/assets/{brand-mark-A03mw_9y.js → brand-mark-DpiBmFGI.js} +1 -1
- package/gui/dist/assets/{index-BjTIN4to.js → index-CAxjGWkm.js} +13 -13
- package/gui/dist/assets/index-bnUWypyz.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-Bf6vpwf8.js → segment-thumb-features-JcszQ18T.js} +1 -1
- package/gui/dist/classic/assets/App-BOEsFmiN.js +58 -0
- package/gui/dist/classic/assets/Tray-5v86r9Az.js +1 -0
- package/gui/dist/classic/assets/{index-DFAFnven.js → index-ClZ_zZ77.js} +13 -13
- package/gui/dist/classic/assets/{quota-summary-C-4HP4_5.js → quota-summary-xwvDtvu7.js} +1 -1
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/adapters/coding-agent/protocol.ts +8 -3
- package/src/adapters/coding-agent/turn.ts +6 -2
- package/src/adapters/command-code.ts +8 -5
- package/src/adapters/devin.ts +11 -1
- package/src/adapters/kiro/stream.ts +5 -4
- package/src/adapters/openai-chat/destination-policy.ts +25 -0
- package/src/adapters/openai-chat/native-content.ts +32 -0
- package/src/adapters/openai-chat/passthrough.ts +14 -1
- package/src/adapters/openai-chat/reasoning-wire.ts +42 -1
- package/src/adapters/openai-chat.ts +2 -2
- package/src/adapters/qoder/adapter.ts +9 -0
- package/src/bridge/response-json.ts +13 -1
- package/src/bridge/sse.ts +112 -22
- package/src/cli/account-affinity-reset.ts +42 -0
- package/src/cli/account.ts +5 -0
- package/src/cli/capabilities-accounts.ts +8 -0
- package/src/cli/capabilities-agents-routing.ts +5 -4
- package/src/cli/message-command.ts +1 -1
- package/src/cli/message-mcp-command.ts +8 -5
- package/src/client/orphan-token-recovery.ts +1 -1
- package/src/codex/autostart-health.ts +4 -2
- package/src/generated/compatibility-version.json +128 -76
- package/src/lib/desktop-cli-handoff.mjs +5 -8
- package/src/lib/failure-detail.ts +5 -2
- package/src/lib/launcher-signal-forwarding.d.mts +8 -0
- package/src/lib/launcher-signal-forwarding.mjs +36 -0
- package/src/lib/privacy.ts +6 -0
- package/src/lib/request-execution-budget.ts +188 -33
- package/src/lib/upstream-validation-detail.ts +47 -0
- package/src/lib/workflow-budget.ts +35 -16
- package/src/messaging/mcp-queue-rpc.ts +7 -3
- package/src/messaging/mcp-queue-server.ts +6 -0
- package/src/messaging/mcp-reply-cursor.ts +34 -0
- package/src/messaging/mcp-reply-tools.ts +93 -0
- package/src/oauth/anthropic-routing.ts +46 -3
- package/src/oauth/anthropic-session-affinity-store.ts +23 -10
- package/src/protocols/codecs/ollama.ts +22 -12
- package/src/providers/registry/entries-extended.ts +14 -0
- package/src/remote/hub-usage.ts +7 -0
- package/src/responses/parser.ts +27 -0
- package/src/responses/reasoning-envelope.ts +4 -0
- package/src/responses/schema.ts +1 -0
- package/src/server/chat-completions.ts +3 -0
- package/src/server/chat-native-sse.ts +14 -10
- package/src/server/chat-native.ts +24 -11
- package/src/server/index/websocket-handler.ts +12 -1
- package/src/server/management/oauth-account-routes.ts +65 -13
- package/src/server/management/route-registry.ts +1 -0
- package/src/server/messages-native.ts +21 -5
- package/src/server/request-log-attempt-recovery.ts +17 -0
- package/src/server/request-log-failure-detail.ts +18 -1
- package/src/server/request-log.ts +5 -18
- package/src/server/responses/account-auto-pause-recovery.ts +29 -1
- package/src/server/responses/adapter-continuation.ts +12 -5
- package/src/server/responses/adapter-dispatch.ts +50 -51
- package/src/server/responses/antigravity-model-denial-recovery.ts +4 -2
- package/src/server/responses/codex-ws-exchange.ts +13 -4
- package/src/server/responses/combo-required-tool-contract.ts +22 -3
- package/src/server/responses/core-codex-account.ts +92 -86
- package/src/server/responses/core-combo-failure.ts +7 -0
- package/src/server/responses/core-combo.ts +11 -4
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/deferred-send-reporter.ts +18 -1
- package/src/server/responses/fetch-helpers.ts +9 -3
- package/src/server/responses/native-continuation-refusal.ts +8 -0
- package/src/server/responses/native-continuation-send.ts +34 -0
- package/src/server/responses/passthrough-delivery.ts +6 -2
- package/src/server/responses/passthrough-dispatch.ts +48 -33
- package/src/server/responses/passthrough-execution.ts +1 -0
- package/src/server/responses/policy-fallback.ts +32 -5
- package/src/server/responses/policy-request-scope.ts +26 -0
- package/src/server/responses/request-prepare.ts +11 -2
- package/src/server/responses/request-send-budget.ts +96 -14
- package/src/server/responses/request-spend-target.ts +19 -0
- package/src/server/responses/request-spend.ts +80 -28
- package/src/server/responses/request-transport.ts +106 -53
- package/src/server/responses/run-turn-execution.ts +3 -0
- package/src/server/responses/sidecar-execution.ts +2 -1
- package/src/server/responses/ws-upstream.ts +2 -1
- package/src/server/workflow-refusal.ts +38 -4
- package/src/server/ws-bridge.ts +10 -3
- package/src/service/desktop-startup.ts +76 -13
- package/src/types/request.ts +2 -1
- package/src/usage/app-breakdown.ts +23 -0
- package/src/usage/summary.ts +34 -1
- package/src/web-search/anthropic-executor.ts +25 -9
- package/src/web-search/loop.ts +3 -1
- package/src/web-search/passthrough-bridge.ts +3 -0
- package/src/web-search/run-turn-loop.ts +3 -1
- package/gui/dist/assets/App-FQ0OtiMJ.js +0 -59
- package/gui/dist/assets/Tray-D2d5wqLq.js +0 -1
- package/gui/dist/assets/index-5REODpG3.css +0 -2
- package/gui/dist/classic/assets/App-C9Eg3nUo.js +0 -58
- package/gui/dist/classic/assets/Tray-B8P8cokE.js +0 -1
|
@@ -10,9 +10,13 @@ export interface DesktopStartupDiagnostic {
|
|
|
10
10
|
/** Durable desktop claim; failed supervision does not release ownership. */
|
|
11
11
|
owned: boolean;
|
|
12
12
|
loginEnabled: boolean;
|
|
13
|
+
/** Whether login registration was verified for the supervising app. */
|
|
14
|
+
loginState?: "enabled" | "disabled" | "unknown";
|
|
13
15
|
/** Verified enabled macOS registration; absence means registration is not credited. */
|
|
14
16
|
loginRegistration?: "loaded" | "registered-not-loaded";
|
|
15
17
|
running: boolean;
|
|
18
|
+
/** The supervision check did not complete; false running alone is not evidence of failure. */
|
|
19
|
+
supervisionUnknown?: boolean;
|
|
16
20
|
viable: boolean;
|
|
17
21
|
/**
|
|
18
22
|
* Proven live parentage; never converts supervision into ownership. macOS and Linux report it
|
|
@@ -24,7 +28,8 @@ export interface DesktopStartupDiagnostic {
|
|
|
24
28
|
|
|
25
29
|
/** A login item alone is insufficient: the same app must supervise this proxy. */
|
|
26
30
|
export function deriveDesktopStartup(facts: Omit<DesktopStartupDiagnostic, "viable">): DesktopStartupDiagnostic {
|
|
27
|
-
return { ...facts,
|
|
31
|
+
return { ...facts, loginState: facts.loginEnabled ? "enabled" : facts.loginState ?? "unknown",
|
|
32
|
+
viable: (facts.owned || facts.supervisor !== undefined) && facts.loginEnabled && facts.running };
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export function desktopLoginStatusSummary(desktop: DesktopStartupDiagnostic): string {
|
|
@@ -96,12 +101,18 @@ function macLoginRegistration(deps: DesktopStartupDeps) {
|
|
|
96
101
|
if (registrationPath !== realpathSync(path) || plistIdentity !== identity(path) || targetIdentity !== identity(registrationPath)
|
|
97
102
|
|| app !== realpathSync(args[0]) || proxy !== realpathSync(join(dirname(app), "ocx"))
|
|
98
103
|
|| appIdentity !== identity(app) || proxyIdentity !== identity(proxy)) return null;
|
|
99
|
-
|
|
104
|
+
const verifiedDisabled = /^\s*disabled services = \{[\s\S]*\}\s*$/.test(disabled)
|
|
105
|
+
&& mentions === 1 && (override === "disabled" || override === "true");
|
|
106
|
+
return { app, proxy, loginEnabled, verifiedDisabled, registrationPath, plistIdentity, targetIdentity, definition, appIdentity, proxyIdentity, disabled };
|
|
100
107
|
};
|
|
101
108
|
const first = capture();
|
|
102
109
|
if (!first) return null;
|
|
103
110
|
const { app, proxy } = first;
|
|
104
|
-
if (!first.loginEnabled)
|
|
111
|
+
if (!first.loginEnabled) {
|
|
112
|
+
const final = first.verifiedDisabled ? capture() : null;
|
|
113
|
+
return { app, proxy, loginEnabled: false, loginState: final && JSON.stringify(first) === JSON.stringify(final)
|
|
114
|
+
? "disabled" as const : "unknown" as const };
|
|
115
|
+
}
|
|
105
116
|
let loaded: string;
|
|
106
117
|
try { loaded = execute("/bin/launchctl", ["print", `${domain}/OpenCodex`]); }
|
|
107
118
|
catch (error) {
|
|
@@ -141,7 +152,7 @@ function macLoginRegistration(deps: DesktopStartupDeps) {
|
|
|
141
152
|
const SMD_SUBMITTED = /^\(submitted by smd\.\d+\)$/;
|
|
142
153
|
const SERVICE_MANAGEMENT = "com.apple.xpc.ServiceManagement";
|
|
143
154
|
|
|
144
|
-
type DesktopLoginFacts = Pick<DesktopStartupDiagnostic, "loginEnabled" | "loginRegistration">;
|
|
155
|
+
type DesktopLoginFacts = Pick<DesktopStartupDiagnostic, "loginEnabled" | "loginRegistration" | "loginState">;
|
|
145
156
|
|
|
146
157
|
/**
|
|
147
158
|
* Start at Login credit for one Desktop app copy. The tray's Start at Login item ports this
|
|
@@ -151,7 +162,7 @@ type DesktopLoginFacts = Pick<DesktopStartupDiagnostic, "loginEnabled" | "loginR
|
|
|
151
162
|
export function macLoginFactsFor(app: string, deps: DesktopStartupDeps): DesktopLoginFacts {
|
|
152
163
|
const login = macLoginRegistration(deps);
|
|
153
164
|
return login !== null && login.app === app
|
|
154
|
-
? { loginEnabled: login.loginEnabled, ...(login.loginRegistration ? { loginRegistration: login.loginRegistration } : {}) }
|
|
165
|
+
? { loginEnabled: login.loginEnabled, ...(login.loginState ? { loginState: login.loginState } : {}), ...(login.loginRegistration ? { loginRegistration: login.loginRegistration } : {}) }
|
|
155
166
|
: { loginEnabled: false };
|
|
156
167
|
}
|
|
157
168
|
|
|
@@ -173,11 +184,54 @@ function diagnoseSupervisedStartup(deps: DesktopStartupDeps, ownerRevision: numb
|
|
|
173
184
|
return deriveDesktopStartup({ owned: false, ...login, running: true, supervisor: { supervisorPid, runtimePid, app } });
|
|
174
185
|
}
|
|
175
186
|
|
|
187
|
+
/** An absent plist is a verified off state only for a stable, independently observed Desktop. */
|
|
188
|
+
function macRegistrationAbsent(deps: DesktopStartupDeps): boolean {
|
|
189
|
+
try {
|
|
190
|
+
lstatSync(join(deps.home ?? homedir(), "Library", "LaunchAgents", "OpenCodex.plist"));
|
|
191
|
+
return false;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return true;
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function diagnoseAbsentMacRegistration(deps: DesktopStartupDeps, owner: ServiceOwnershipResolution): DesktopStartupDiagnostic | undefined {
|
|
199
|
+
if (owner.kind === "unknown") return undefined;
|
|
200
|
+
const owned = owner.kind === "owned" && owner.ownership.owner === "desktop";
|
|
201
|
+
const fallback = owned ? deriveDesktopStartup({ owned: true, loginEnabled: false, running: false, supervisionUnknown: true }) : undefined;
|
|
202
|
+
const ownership = deps.ownership ?? resolveServiceOwnership;
|
|
203
|
+
try {
|
|
204
|
+
const installIdPath = join(deps.home ?? homedir(), "Library", "Application Support", "com.opencodex.desktop", "install-id");
|
|
205
|
+
const installId = owned ? readFileSync(installIdPath, "utf8").trim() : null;
|
|
206
|
+
if (owned && (owner.kind !== "owned" || installId !== owner.ownership.installId)) return fallback;
|
|
207
|
+
const first = inspectDesktopSupervision(deps);
|
|
208
|
+
if (owned && first.kind === "none") {
|
|
209
|
+
const currentOwner = ownership();
|
|
210
|
+
return currentOwner.kind !== "unknown" && sameServiceOwnershipSubject(owner, currentOwner)
|
|
211
|
+
&& macRegistrationAbsent(deps) && readFileSync(installIdPath, "utf8").trim() === installId
|
|
212
|
+
? deriveDesktopStartup({ owned: true, loginEnabled: false, running: false }) : fallback;
|
|
213
|
+
}
|
|
214
|
+
if (first.kind !== "desktop" || !macRegistrationAbsent(deps)) return fallback;
|
|
215
|
+
const final = inspectDesktopSupervision({ ...deps, targetPid: first.runtimePid });
|
|
216
|
+
const currentOwner = ownership();
|
|
217
|
+
if (final.kind !== "desktop" || final.runtimePid !== first.runtimePid || final.supervisorPid !== first.supervisorPid
|
|
218
|
+
|| final.app !== first.app || final.proxy !== first.proxy || currentOwner.kind === "unknown"
|
|
219
|
+
|| !sameServiceOwnershipSubject(owner, currentOwner) || !macRegistrationAbsent(deps)
|
|
220
|
+
|| (owned && readFileSync(installIdPath, "utf8").trim() !== installId)) return fallback;
|
|
221
|
+
return deriveDesktopStartup({ owned, loginEnabled: false, loginState: "disabled", running: true,
|
|
222
|
+
...(!owned ? { supervisor: { supervisorPid: first.supervisorPid, runtimePid: first.runtimePid, app: first.app } } : {}) });
|
|
223
|
+
} catch { return fallback; }
|
|
224
|
+
}
|
|
225
|
+
|
|
176
226
|
/** Read-only macOS desktop ownership, login registration and live parent/child checks. */
|
|
177
227
|
export function diagnoseMacDesktopStartup(deps: DesktopStartupDeps = {}): DesktopStartupDiagnostic | undefined {
|
|
178
228
|
if ((deps.platform ?? process.platform) !== "darwin") return undefined;
|
|
179
229
|
const ownership = deps.ownership ?? resolveServiceOwnership;
|
|
180
230
|
const owner = ownership();
|
|
231
|
+
if (owner.kind === "none" || (owner.kind === "owned" && owner.ownership.owner === "desktop")) {
|
|
232
|
+
try { if (macRegistrationAbsent(deps)) return diagnoseAbsentMacRegistration(deps, owner); }
|
|
233
|
+
catch { /* Unreadable registration is handled by the existing conservative path. */ }
|
|
234
|
+
}
|
|
181
235
|
if (owner.kind === "none") return diagnoseSupervisedStartup(deps, owner.revision, app => macLoginFactsFor(app, deps));
|
|
182
236
|
if (owner.kind !== "owned" || owner.ownership.owner !== "desktop") return undefined;
|
|
183
237
|
const facts: Omit<DesktopStartupDiagnostic, "viable"> = { owned: true, loginEnabled: false, running: false };
|
|
@@ -186,24 +240,33 @@ export function diagnoseMacDesktopStartup(deps: DesktopStartupDeps = {}): Deskto
|
|
|
186
240
|
try {
|
|
187
241
|
const home = deps.home ?? homedir();
|
|
188
242
|
const id = readFileSync(join(home, "Library", "Application Support", "com.opencodex.desktop", "install-id"), "utf8").trim();
|
|
189
|
-
if (id !== owner.ownership.installId) return deriveDesktopStartup(facts);
|
|
243
|
+
if (id !== owner.ownership.installId) return deriveDesktopStartup({ ...facts, supervisionUnknown: true });
|
|
244
|
+
const pid = pidReader();
|
|
245
|
+
const child = pid !== null ? processIdentity(pid, execute) : null;
|
|
246
|
+
const parent = child && child.parent > 1 ? processIdentity(child.parent, execute) : null;
|
|
190
247
|
const login = macLoginRegistration(deps);
|
|
191
|
-
if (!login) return deriveDesktopStartup(facts);
|
|
248
|
+
if (!login) return deriveDesktopStartup({ ...facts, supervisionUnknown: true });
|
|
192
249
|
const { app, proxy } = login;
|
|
193
250
|
facts.loginEnabled = login.loginEnabled;
|
|
251
|
+
facts.loginState = login.loginState;
|
|
194
252
|
if (login.loginRegistration) facts.loginRegistration = login.loginRegistration;
|
|
195
|
-
const pid = pidReader();
|
|
196
253
|
if (pid !== null) {
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
facts.running = child?.executable === proxy && parent?.executable === app && pidReader() === pid
|
|
254
|
+
const finalChild = processIdentity(pid, execute);
|
|
255
|
+
const finalParent = finalChild && finalChild.parent > 1 ? processIdentity(finalChild.parent, execute) : null;
|
|
256
|
+
facts.running = child?.executable === proxy && parent?.executable === app && pidReader() === pid
|
|
257
|
+
&& JSON.stringify(child) === JSON.stringify(finalChild) && JSON.stringify(parent) === JSON.stringify(finalParent);
|
|
200
258
|
}
|
|
201
259
|
const currentOwner = ownership();
|
|
202
|
-
if (currentOwner.kind === "unknown" || !sameServiceOwnershipSubject(owner, currentOwner)
|
|
260
|
+
if (currentOwner.kind === "unknown" || !sameServiceOwnershipSubject(owner, currentOwner) || (pid !== null && !facts.running)) {
|
|
261
|
+
facts.running = false;
|
|
262
|
+
facts.loginEnabled = false;
|
|
263
|
+
facts.loginState = "unknown";
|
|
264
|
+
}
|
|
265
|
+
if (!facts.running && !facts.loginEnabled) facts.loginState = "unknown";
|
|
203
266
|
return deriveDesktopStartup(facts);
|
|
204
267
|
} catch {
|
|
205
268
|
// Unreadable launchd/process evidence never grants protection or releases the claim.
|
|
206
|
-
return deriveDesktopStartup({ ...facts, running: false });
|
|
269
|
+
return deriveDesktopStartup({ ...facts, loginEnabled: false, loginState: "unknown", running: false, supervisionUnknown: true });
|
|
207
270
|
}
|
|
208
271
|
}
|
|
209
272
|
|
package/src/types/request.ts
CHANGED
|
@@ -482,7 +482,8 @@ export type AdapterEvent =
|
|
|
482
482
|
| { type: "thinking_delta"; thinking: string }
|
|
483
483
|
// Anthropic extended-thinking round-trip: signature_delta for the current thinking block, and
|
|
484
484
|
// opaque redacted_thinking blocks. Both must be replayed verbatim or tool-use turns 400.
|
|
485
|
-
|
|
485
|
+
// afterOutput marks a turn-level attestation emitted after text/tools, not a new thinking block.
|
|
486
|
+
| { type: "thinking_signature"; signature: string; afterOutput?: true }
|
|
486
487
|
| { type: "redacted_thinking"; data: string }
|
|
487
488
|
// Kiro reasoning round-trip: the encrypted reasoning blob for the CURRENT assistant turn, tagged
|
|
488
489
|
// with the wire field it arrived on. Never rendered — it only rides the reasoning item's envelope
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { normalizeRecordedClient } from "./client";
|
|
2
|
+
|
|
3
|
+
/** Closed report categories; an absent historical client is kept distinct. */
|
|
4
|
+
export const USAGE_APPS = ["codex", "claude_code", "claude_desktop", "grok", "opencode", "aside", "other", "unknown", "unclassified"] as const;
|
|
5
|
+
export type UsageApp = typeof USAGE_APPS[number];
|
|
6
|
+
|
|
7
|
+
export function usageApp(client: unknown): UsageApp {
|
|
8
|
+
const normalized = normalizeRecordedClient(client);
|
|
9
|
+
if (normalized === undefined) return "unclassified";
|
|
10
|
+
if (normalized === "codex_cli" || normalized === "codex_desktop" || normalized === "codex_ide") return "codex";
|
|
11
|
+
return normalized;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface UsageAppSummary {
|
|
15
|
+
client: UsageApp;
|
|
16
|
+
requests: number;
|
|
17
|
+
measuredRequests: number;
|
|
18
|
+
totalTokens: number;
|
|
19
|
+
estimatedCostUsd?: number;
|
|
20
|
+
pricedRequests: number;
|
|
21
|
+
unpricedRequests: number;
|
|
22
|
+
shareRatio: number;
|
|
23
|
+
}
|
package/src/usage/summary.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { baseProviderLabel } from "../providers/label";
|
|
2
2
|
import { canonicalAntigravityUsageModel } from "../providers/antigravity-models";
|
|
3
3
|
import { usageDisplayTotalTokens } from "./totals";
|
|
4
|
+
import { usageApp, type UsageApp, type UsageAppSummary } from "./app-breakdown";
|
|
4
5
|
import { isLegacyCodexUsage, matchesUsageSource, snapshotConfiguredKeyIds, type UsageSourceFilter } from "./source-filter";
|
|
5
6
|
import type { UsageTimeWindow } from "./time-range";
|
|
6
7
|
import { isUnresolvedRequestedModel, usageModelPriceOptions } from "./model-identity";
|
|
@@ -210,6 +211,7 @@ export interface UsageSummary {
|
|
|
210
211
|
days: UsageDay[];
|
|
211
212
|
models: UsageModel[];
|
|
212
213
|
providers: UsageProvider[];
|
|
214
|
+
apps: UsageAppSummary[];
|
|
213
215
|
accounts: UsageAccount[];
|
|
214
216
|
sourceFilter?: UsageSourceFilter;
|
|
215
217
|
legacyUnclassifiedRequests?: number;
|
|
@@ -779,6 +781,7 @@ interface UsagePartition {
|
|
|
779
781
|
oldestTimestamp: number | null;
|
|
780
782
|
legacyUnclassifiedRequests: number;
|
|
781
783
|
totals: UsageSummaryTotals;
|
|
784
|
+
apps: Map<UsageApp, UsageSummaryTotals>;
|
|
782
785
|
models: Map<string, UsageModelAccumulator>;
|
|
783
786
|
providers?: Map<string, UsageModelAccumulator>;
|
|
784
787
|
accounts: Map<string, UsageAccountAccumulator>;
|
|
@@ -829,6 +832,12 @@ function statusFromRequestFacts(facts: number): UsageStatus {
|
|
|
829
832
|
return (statuses & REQUEST_REPORTED) !== 0 ? "reported" : "unreported";
|
|
830
833
|
}
|
|
831
834
|
|
|
835
|
+
/** A usage-less local or unsent attempt cannot make a request's usage unknown. */
|
|
836
|
+
function attemptStatusFact(attempt: NonNullable<PersistedUsageEntry["attempts"]>[number]): number {
|
|
837
|
+
return attempt.usage || (attempt.sendCount !== 0 && attempt.locallyAnswered !== true)
|
|
838
|
+
? requestStatusFact(attempt.usageStatus) : 0;
|
|
839
|
+
}
|
|
840
|
+
|
|
832
841
|
function blankRequestCounts(): UsageRequestCounts {
|
|
833
842
|
return {
|
|
834
843
|
requests: 0,
|
|
@@ -1086,6 +1095,7 @@ function projectedEntryForFilter(
|
|
|
1086
1095
|
return filterMatchesAttribution(filter, attempt.provider, identity.model);
|
|
1087
1096
|
});
|
|
1088
1097
|
if (attempts.length === 0) return null;
|
|
1098
|
+
const projectedStatus = attempts.length !== entry.attempts.length;
|
|
1089
1099
|
const { usage: _parentUsage, totalTokens: _parentTotalTokens, spend: parentSpend, ...withoutParentUsage } = entry;
|
|
1090
1100
|
return {
|
|
1091
1101
|
entry: {
|
|
@@ -1095,6 +1105,7 @@ function projectedEntryForFilter(
|
|
|
1095
1105
|
// reporting a full-request send count against a partial row.
|
|
1096
1106
|
...(parentSpend && attempts.length === entry.attempts.length ? { spend: parentSpend } : {}),
|
|
1097
1107
|
attempts,
|
|
1108
|
+
...(projectedStatus ? { usageStatus: statusFromRequestFacts(attempts.reduce((facts, attempt) => facts | attemptStatusFact(attempt), 0)) } : {}),
|
|
1098
1109
|
...projectedComboUsage(attempts),
|
|
1099
1110
|
},
|
|
1100
1111
|
comboOverlap: entry.attempts.length > 1,
|
|
@@ -1367,6 +1378,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1367
1378
|
cloned.partitions.set(key, {
|
|
1368
1379
|
...partition,
|
|
1369
1380
|
totals: { ...partition.totals },
|
|
1381
|
+
apps: new Map([...partition.apps].map(([client, totals]) => [client, { ...totals }])),
|
|
1370
1382
|
models,
|
|
1371
1383
|
...(providers ? { providers } : {}),
|
|
1372
1384
|
accounts,
|
|
@@ -1402,6 +1414,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1402
1414
|
oldestTimestamp: null,
|
|
1403
1415
|
legacyUnclassifiedRequests: 0,
|
|
1404
1416
|
totals: blankTotals(),
|
|
1417
|
+
apps: new Map(),
|
|
1405
1418
|
models: new Map(),
|
|
1406
1419
|
...(this.mode === "row-unique" ? { providers: new Map() } : {}),
|
|
1407
1420
|
accounts: new Map(),
|
|
@@ -1606,6 +1619,16 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1606
1619
|
addCacheProvenanceTotals(partition.totals, entry);
|
|
1607
1620
|
addThroughputTotals(partition.totals, entry);
|
|
1608
1621
|
addEstimatedCost(partition.totals, entry, costInfo);
|
|
1622
|
+
const client = usageApp(entry.client);
|
|
1623
|
+
let app = partition.apps.get(client);
|
|
1624
|
+
if (!app) {
|
|
1625
|
+
app = blankTotals();
|
|
1626
|
+
partition.apps.set(client, app);
|
|
1627
|
+
this.estimatedRetainedBytes += ESTIMATED_BREAKDOWN_BYTES;
|
|
1628
|
+
}
|
|
1629
|
+
bumpStatus(app, entry.usageStatus);
|
|
1630
|
+
addTokens(app, entry);
|
|
1631
|
+
addEstimatedCost(app, entry, costInfo);
|
|
1609
1632
|
|
|
1610
1633
|
const requestKey = this.mode === "exact" ? this.requestKey(entry.requestId) : null;
|
|
1611
1634
|
const attributions = usageAttributions(entry);
|
|
@@ -1618,7 +1641,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1618
1641
|
? costInfo.attemptEstimates?.[index] ?? null
|
|
1619
1642
|
: costInfo.estimate;
|
|
1620
1643
|
const ordinal = this.nextOrdinal++;
|
|
1621
|
-
const facts = requestStatusFact(attribution.usageStatus)
|
|
1644
|
+
const facts = (entry.attempts?.length ? attemptStatusFact(entry.attempts[index]!) : requestStatusFact(attribution.usageStatus))
|
|
1622
1645
|
| (estimate ? REQUEST_PRICED : spentNothing(entry.attempts?.[index]) ? 0 : REQUEST_UNPRICED);
|
|
1623
1646
|
const modelKey = this.addModelAttribution(partition, attribution, estimate, ordinal);
|
|
1624
1647
|
modelFacts.set(modelKey, (modelFacts.get(modelKey) ?? 0) | facts);
|
|
@@ -1666,6 +1689,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1666
1689
|
const totals = blankTotals();
|
|
1667
1690
|
const models = new Map<string, UsageModelAccumulator>();
|
|
1668
1691
|
const providers = new Map<string, UsageModelAccumulator>();
|
|
1692
|
+
const apps = new Map<UsageApp, UsageSummaryTotals>();
|
|
1669
1693
|
const accounts = new Map<string, UsageAccountAccumulator>();
|
|
1670
1694
|
const dayAccumulators = new Map<string, UsageDayAccumulator>();
|
|
1671
1695
|
const modelOverlaps: UsageModelOverlap[] = [];
|
|
@@ -1677,6 +1701,11 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1677
1701
|
if (!this.window && since !== null && partition.dayStart < since) continue;
|
|
1678
1702
|
legacyUnclassifiedRequests += partition.legacyUnclassifiedRequests;
|
|
1679
1703
|
mergeTotals(totals, partition.totals);
|
|
1704
|
+
for (const [client, app] of partition.apps) {
|
|
1705
|
+
const combined = apps.get(client) ?? blankTotals();
|
|
1706
|
+
mergeTotals(combined, app);
|
|
1707
|
+
apps.set(client, combined);
|
|
1708
|
+
}
|
|
1680
1709
|
mergeModelMaps(models, partition.models);
|
|
1681
1710
|
if (partition.providers) mergeModelMaps(providers, partition.providers);
|
|
1682
1711
|
modelOverlaps.push(...partition.modelOverlaps.values());
|
|
@@ -1750,6 +1779,9 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1750
1779
|
days,
|
|
1751
1780
|
models: buildUsageModels(models, totals.totalTokens, modelOverlaps),
|
|
1752
1781
|
providers: buildUsageProviders(this.mode === "row-unique" ? providers : models, totals.totalTokens),
|
|
1782
|
+
apps: [...apps].map(([client, app]) => ({ client, requests: app.requests, measuredRequests: app.measuredRequests,
|
|
1783
|
+
totalTokens: app.totalTokens, ...(app.pricedRequests ? { estimatedCostUsd: app.estimatedCostUsd } : {}), pricedRequests: app.pricedRequests,
|
|
1784
|
+
unpricedRequests: app.unpricedRequests + app.unmeteredRequests, shareRatio: totals.totalTokens === 0 ? 0 : Math.min(1, app.totalTokens / totals.totalTokens) })),
|
|
1753
1785
|
accounts: buildUsageAccounts(accounts),
|
|
1754
1786
|
...(this.filter?.sourceFilter ? { sourceFilter: { client: this.filter.sourceFilter.client,
|
|
1755
1787
|
device: { ...this.filter.sourceFilter.device } }, legacyUnclassifiedRequests } : {}),
|
|
@@ -1851,6 +1883,7 @@ export function projectUsageSummary<T extends UsageSummary>(
|
|
|
1851
1883
|
days: projected.days,
|
|
1852
1884
|
models: projected.models,
|
|
1853
1885
|
providers: projected.providers,
|
|
1886
|
+
apps: projected.apps,
|
|
1854
1887
|
accounts: projected.accounts,
|
|
1855
1888
|
...(projected.sourceFilter ? { sourceFilter: projected.sourceFilter, legacyUnclassifiedRequests: projected.legacyUnclassifiedRequests } : {}),
|
|
1856
1889
|
filter: projected.filter,
|
|
@@ -10,7 +10,9 @@ import { sidecarThinkingOff } from "../adapters/anthropic-model-contract";
|
|
|
10
10
|
import { CLAUDE_CODE_HEADERS, claudeCodeSessionId } from "../adapters/client-fingerprint";
|
|
11
11
|
import { signalWithTimeout, cancelBodyOnAbort } from "../lib/abort";
|
|
12
12
|
import { sidecarEnter } from "../lib/sidecar-tracker";
|
|
13
|
-
import { applyUpstreamRecoveryInit, fetchWithResetRetry } from "../lib/upstream-retry";
|
|
13
|
+
import { applyUpstreamRecoveryInit, fetchWithResetRetry, SendBudgetExhaustedError } from "../lib/upstream-retry";
|
|
14
|
+
import type { AuxiliaryModelSend } from "../lib/request-execution-budget";
|
|
15
|
+
import { estimateTokens } from "../lib/token-estimate";
|
|
14
16
|
import { sseFieldValue } from "../lib/sse-decoder";
|
|
15
17
|
import {
|
|
16
18
|
MAX_SIDECAR_RESPONSE_BYTES,
|
|
@@ -251,6 +253,7 @@ export async function runAnthropicWebSearch(
|
|
|
251
253
|
settings: SidecarSettings,
|
|
252
254
|
abortSignal?: AbortSignal,
|
|
253
255
|
config?: OcxConfig,
|
|
256
|
+
dispatchSidecarSend?: AuxiliaryModelSend,
|
|
254
257
|
): Promise<SidecarOutcome> {
|
|
255
258
|
const url = anthropicHelperMessagesUrl(provider.baseUrl);
|
|
256
259
|
let token: string;
|
|
@@ -302,17 +305,29 @@ export async function runAnthropicWebSearch(
|
|
|
302
305
|
const linkedSignal = signalWithTimeout(settings.timeoutMs, abortSignal);
|
|
303
306
|
const sidecarExit = sidecarEnter("web-search");
|
|
304
307
|
const t0 = Date.now();
|
|
308
|
+
const serializedBody = JSON.stringify(body);
|
|
309
|
+
const sendTarget = {
|
|
310
|
+
poolId: snapshot?.provider ?? providerName,
|
|
311
|
+
// Anthropic has no durable identity scope; never borrow the routed Codex account.
|
|
312
|
+
identityId: "",
|
|
313
|
+
targetKey: `anthropic-web-search:${crypto.randomUUID()}`,
|
|
314
|
+
// This helper contains only text/tool definitions; include the full wire envelope conservatively.
|
|
315
|
+
estimate: { inputTokens: Math.max(1, estimateTokens(serializedBody, settings.model)), outputCeilingTokens: body.max_tokens },
|
|
316
|
+
};
|
|
305
317
|
try {
|
|
306
318
|
const res = await fetchWithResetRetry(
|
|
307
319
|
// The replay needs `keepalive: false` to leave the half-closed pooled socket; Bun has
|
|
308
320
|
// ignored a bare `Connection: close` (oven-sh/bun#20492).
|
|
309
|
-
recovery =>
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
321
|
+
recovery => {
|
|
322
|
+
const run = () => dispatch(url, applyUpstreamRecoveryInit({
|
|
323
|
+
method: "POST",
|
|
324
|
+
redirect: "manual",
|
|
325
|
+
headers,
|
|
326
|
+
body: serializedBody,
|
|
327
|
+
signal: linkedSignal.signal,
|
|
328
|
+
}, recovery));
|
|
329
|
+
return dispatchSidecarSend ? dispatchSidecarSend(sendTarget, run) : run();
|
|
330
|
+
},
|
|
316
331
|
{ replaySafe: true, abortSignal: linkedSignal.signal, label: "web-search-sidecar-anthropic" },
|
|
317
332
|
);
|
|
318
333
|
// Guard before any branch reads the body: the failure branch's `res.text()` ran ahead of
|
|
@@ -337,7 +352,8 @@ export async function runAnthropicWebSearch(
|
|
|
337
352
|
detachBodyGuard();
|
|
338
353
|
}
|
|
339
354
|
} catch (e) {
|
|
340
|
-
const kind = e instanceof
|
|
355
|
+
const kind = e instanceof SendBudgetExhaustedError ? "send_budget_exhausted"
|
|
356
|
+
: e instanceof Error && e.name === "TimeoutError" ? "timeout" : "connect_error";
|
|
341
357
|
console.warn(`[web-search] anthropic sidecar ${kind} for query "${query.slice(0, 80)}" (${Date.now() - t0}ms)`);
|
|
342
358
|
return { text: "", sources: [], error: `anthropic sidecar ${kind}` };
|
|
343
359
|
} finally {
|
package/src/web-search/loop.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { markSidecarContextOverflow, sidecarLoopTerminalEvent, upstreamErrorCode
|
|
|
17
17
|
import { markVerifiedModelNotInPlanResponse, MODEL_NOT_IN_PLAN_CODE, UNDECLARED_TOOL_CALL_ERROR_CODE, verifiedPlanRefusalMessage } from "../lib/errors";
|
|
18
18
|
import { runWebSearch, type SidecarOutcome, type SidecarOutcomeRecorder, type SidecarSettings } from "./executor";
|
|
19
19
|
import { runAnthropicWebSearch } from "./anthropic-executor";
|
|
20
|
+
import type { AuxiliaryModelSend } from "../lib/request-execution-budget";
|
|
20
21
|
import { runXaiWebSearch, type XaiSearchOptions } from "./xai-executor";
|
|
21
22
|
import { runGeminiWebSearch } from "./gemini-executor";
|
|
22
23
|
import { runExaWebSearch } from "./exa-executor";
|
|
@@ -373,6 +374,7 @@ export interface WebSearchLoopDeps {
|
|
|
373
374
|
forwardProvider?: OcxProviderConfig;
|
|
374
375
|
/** Required for the anthropic backend: the stored-OAuth provider that runs web_search_20250305. */
|
|
375
376
|
anthropicSidecar?: { providerName: string; provider: OcxProviderConfig; config: OcxConfig };
|
|
377
|
+
dispatchSidecarSend?: AuxiliaryModelSend;
|
|
376
378
|
/** Required for the xai backend: the stored Grok OAuth provider (L7). */
|
|
377
379
|
xaiSidecar?: { providerName: string; provider: OcxProviderConfig };
|
|
378
380
|
/** Required for the gemini backend: the stored Antigravity CCA provider (L8). */
|
|
@@ -1023,7 +1025,7 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
1023
1025
|
// signal would otherwise look like an ordinary degradable failure).
|
|
1024
1026
|
try {
|
|
1025
1027
|
if (backend === "anthropic" && anthropicSidecar) {
|
|
1026
|
-
outcome = await runAnthropicWebSearch(query, anthropicSidecar.providerName, anthropicSidecar.provider, settings, signal, anthropicSidecar.config);
|
|
1028
|
+
outcome = await runAnthropicWebSearch(query, anthropicSidecar.providerName, anthropicSidecar.provider, settings, signal, anthropicSidecar.config, deps.dispatchSidecarSend);
|
|
1027
1029
|
} else if (backend === "xai") {
|
|
1028
1030
|
// L7: stored Grok OAuth to the pinned api.x.ai Responses endpoint; same
|
|
1029
1031
|
// never-throws contract and no Codex/OpenAI pool outcome recording (F5 parity).
|
|
@@ -63,6 +63,7 @@ import { buildWebSearchTool, WEB_SEARCH_TOOL_NAME } from "./synthetic-tool";
|
|
|
63
63
|
import { safeWebSearchSources } from "./sources";
|
|
64
64
|
import { runOllamaWebSearch } from "./ollama-executor";
|
|
65
65
|
import { runAnthropicWebSearch } from "./anthropic-executor";
|
|
66
|
+
import type { AuxiliaryModelSend } from "../lib/request-execution-budget";
|
|
66
67
|
import { runXaiWebSearch, validateXaiSearchOptions } from "./xai-executor";
|
|
67
68
|
import { runGeminiWebSearch } from "./gemini-executor";
|
|
68
69
|
import { runExaWebSearch } from "./exa-executor";
|
|
@@ -831,6 +832,7 @@ export function createOllamaBridgeExecutor(
|
|
|
831
832
|
|
|
832
833
|
/** Per-search credentials and sidecar settings. Secrets stay off the plan object. */
|
|
833
834
|
export interface PassthroughWebSearchBridgeExecutorContext {
|
|
835
|
+
dispatchSidecarSend?: AuxiliaryModelSend;
|
|
834
836
|
providerApiKey?: string;
|
|
835
837
|
auth?: PassthroughWebSearchBridgeAuth;
|
|
836
838
|
hostedTool?: Record<string, unknown>;
|
|
@@ -972,6 +974,7 @@ export function createPassthroughWebSearchBridgeExecutor(
|
|
|
972
974
|
settings,
|
|
973
975
|
querySignal,
|
|
974
976
|
anthropic.config,
|
|
977
|
+
context.dispatchSidecarSend,
|
|
975
978
|
);
|
|
976
979
|
}
|
|
977
980
|
case "xai": {
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
type SidecarOutcomeRecorder,
|
|
32
32
|
} from "./executor";
|
|
33
33
|
import { runAnthropicWebSearch } from "./anthropic-executor";
|
|
34
|
+
import type { AuxiliaryModelSend } from "../lib/request-execution-budget";
|
|
34
35
|
import { runXaiWebSearch } from "./xai-executor";
|
|
35
36
|
import { runGeminiWebSearch } from "./gemini-executor";
|
|
36
37
|
import { runExaWebSearch } from "./exa-executor";
|
|
@@ -55,6 +56,7 @@ export interface RunTurnWebSearchDeps {
|
|
|
55
56
|
exaApiKey?: string;
|
|
56
57
|
abortSignal?: AbortSignal;
|
|
57
58
|
recordSidecarOutcome?: SidecarOutcomeRecorder;
|
|
59
|
+
dispatchSidecarSend?: AuxiliaryModelSend;
|
|
58
60
|
/** Preserve the request's opt-in empty-completion retry before the search cap. */
|
|
59
61
|
emptyCompletionRetry?: boolean;
|
|
60
62
|
/**
|
|
@@ -269,7 +271,7 @@ export async function* runTurnWebSearchLoop(
|
|
|
269
271
|
switch (plan.backend) {
|
|
270
272
|
case "anthropic":
|
|
271
273
|
return plan.anthropicSidecar
|
|
272
|
-
? await runAnthropicWebSearch(query, plan.anthropicSidecar.providerName, plan.anthropicSidecar.provider, plan.settings, signal, plan.anthropicSidecar.config)
|
|
274
|
+
? await runAnthropicWebSearch(query, plan.anthropicSidecar.providerName, plan.anthropicSidecar.provider, plan.settings, signal, plan.anthropicSidecar.config, deps.dispatchSidecarSend)
|
|
273
275
|
: { text: "", sources: [], error: "anthropic backend selected without a resolved sidecar provider" };
|
|
274
276
|
case "xai":
|
|
275
277
|
return plan.xaiSidecar
|