dsh-github-copilot 0.1.0-alpha.1.dsh.0.2.1.alpha.5
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/AGENTS.md +439 -0
- package/CHANGELOG.md +875 -0
- package/CONTRIBUTING.md +55 -0
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/README.zh.md +341 -0
- package/SECURITY.md +29 -0
- package/cordis.patch.yml +16 -0
- package/deployment-baseline.json +1580 -0
- package/docs/account-management-experience.md +143 -0
- package/docs/agent-readiness.md +110 -0
- package/docs/auto-high-cost.md +255 -0
- package/docs/auto-iteration-review.json +22 -0
- package/docs/auto-review-sampling.md +60 -0
- package/docs/auto-task-routing.md +341 -0
- package/docs/automatic-model-routing.md +236 -0
- package/docs/copilot-accounts.md +424 -0
- package/docs/copilot-compaction.md +148 -0
- package/docs/copilot-usage.md +133 -0
- package/docs/dual-model.md +66 -0
- package/docs/evidence-driven-iteration.md +86 -0
- package/docs/image-input-compatibility.md +64 -0
- package/docs/images/copilot-accounts-credits.png +0 -0
- package/docs/images/copilot-accounts.png +0 -0
- package/docs/images/copilot-current-provenance.json +39 -0
- package/docs/images/copilot-model-preferences.png +0 -0
- package/docs/images/copilot-search-routing.png +0 -0
- package/docs/images/copilot-session-continuation.png +0 -0
- package/docs/images/dual-model-desktop.png +0 -0
- package/docs/images/dual-model-mobile.png +0 -0
- package/docs/images/dual-model-provenance.json +35 -0
- package/docs/images/parent-model-follow.png +0 -0
- package/docs/manual-compaction-recovery.md +109 -0
- package/docs/mockups/copilot-account-dropdown.html +71 -0
- package/docs/mockups/copilot-account-management.html +393 -0
- package/docs/model-compatibility-acceptance.md +182 -0
- package/docs/npm-distribution.md +202 -0
- package/docs/official-first-016-alpha2.md +66 -0
- package/docs/official-first-020-rc1.md +32 -0
- package/docs/official-first-020-rc2.md +17 -0
- package/docs/official-first-021-alpha4.md +157 -0
- package/docs/official-first-021-alpha5.md +83 -0
- package/docs/plugin-diagnostics.md +605 -0
- package/docs/session-continuation.md +141 -0
- package/docs/session-search-routing.md +133 -0
- package/docs/single-route-migration.md +131 -0
- package/docs/web-lifecycle-rc2.md +55 -0
- package/lib/client.js +13236 -0
- package/lib/client.js.map +1 -0
- package/lib/copilot-identity-DRZY_d2X.js +15 -0
- package/lib/diagnostics-analysis-io.js +78 -0
- package/lib/diagnostics-analysis.js +427 -0
- package/lib/diagnostics-types-CF-qg8Do.js +708 -0
- package/lib/index.js +15661 -0
- package/lib/manual-compaction-recovery.js +485 -0
- package/lib/remote.js +1507 -0
- package/lib/request-budget-DLY_aRq0.js +87 -0
- package/lib/routed-web.js +120 -0
- package/lib/search-routing-CV2hs8as.js +792 -0
- package/lib/types/account-dropdown.d.ts +22 -0
- package/lib/types/account-model-auth.d.ts +15 -0
- package/lib/types/account-model-catalog.d.ts +70 -0
- package/lib/types/account-model-source.d.ts +85 -0
- package/lib/types/agent-compaction.d.ts +4 -0
- package/lib/types/authorization-code-clipboard.d.ts +4 -0
- package/lib/types/authorization-controller.d.ts +121 -0
- package/lib/types/auto-allocation-card.d.ts +9 -0
- package/lib/types/auto-allocation-diagnostics.d.ts +126 -0
- package/lib/types/auto-allocation-evidence.d.ts +44 -0
- package/lib/types/auto-allocation.d.ts +47 -0
- package/lib/types/auto-assessment-evidence.d.ts +111 -0
- package/lib/types/auto-model-host.d.ts +30 -0
- package/lib/types/auto-model-intent.d.ts +36 -0
- package/lib/types/auto-model-presentation.d.ts +57 -0
- package/lib/types/auto-model-routing.d.ts +64 -0
- package/lib/types/auto-review-sampling.d.ts +6 -0
- package/lib/types/auto-selection-explanation.d.ts +9 -0
- package/lib/types/auto-task-assessment.d.ts +49 -0
- package/lib/types/auto-task-classifier.d.ts +10 -0
- package/lib/types/background-compaction.d.ts +30 -0
- package/lib/types/client.d.ts +129 -0
- package/lib/types/compact-account.d.ts +42 -0
- package/lib/types/compaction-continuation-ui.d.ts +29 -0
- package/lib/types/compaction-continuation.d.ts +48 -0
- package/lib/types/compaction-input-estimate.d.ts +28 -0
- package/lib/types/compaction-pressure.d.ts +23 -0
- package/lib/types/compaction-replay.d.ts +18 -0
- package/lib/types/compatibility.d.ts +17 -0
- package/lib/types/composer-notice-style.d.ts +7 -0
- package/lib/types/config.d.ts +141 -0
- package/lib/types/content-file.d.ts +10 -0
- package/lib/types/context-evidence-ui.d.ts +28 -0
- package/lib/types/context-evidence.d.ts +256 -0
- package/lib/types/context-usage.d.ts +4 -0
- package/lib/types/copilot-account-presentation.d.ts +7 -0
- package/lib/types/copilot-accounts-card.d.ts +43 -0
- package/lib/types/copilot-accounts-host.d.ts +93 -0
- package/lib/types/copilot-accounts-remote.d.ts +85 -0
- package/lib/types/copilot-accounts-types.d.ts +43 -0
- package/lib/types/copilot-auth.d.ts +31 -0
- package/lib/types/copilot-grant.d.ts +11 -0
- package/lib/types/copilot-identity.d.ts +11 -0
- package/lib/types/copilot-request.d.ts +11 -0
- package/lib/types/copilot-stream-liveness.d.ts +23 -0
- package/lib/types/copilot-usage-card.d.ts +51 -0
- package/lib/types/copilot-usage-host.d.ts +61 -0
- package/lib/types/copilot-usage-normalize.d.ts +9 -0
- package/lib/types/copilot-usage-remote.d.ts +63 -0
- package/lib/types/copilot-usage-types.d.ts +20 -0
- package/lib/types/copilot-usage-ui.d.ts +4 -0
- package/lib/types/current-provider.d.ts +59 -0
- package/lib/types/deepseek-search-fallback.d.ts +11 -0
- package/lib/types/diagnostics-analysis-io.d.ts +23 -0
- package/lib/types/diagnostics-analysis.d.ts +298 -0
- package/lib/types/diagnostics-card.d.ts +12 -0
- package/lib/types/diagnostics-client.d.ts +13 -0
- package/lib/types/diagnostics-collector.d.ts +50 -0
- package/lib/types/diagnostics-host.d.ts +183 -0
- package/lib/types/diagnostics-remote.d.ts +113 -0
- package/lib/types/diagnostics-types.d.ts +893 -0
- package/lib/types/dual-model-host.d.ts +119 -0
- package/lib/types/dual-model-remote.d.ts +63 -0
- package/lib/types/dual-model-types.d.ts +34 -0
- package/lib/types/external-link.d.ts +3 -0
- package/lib/types/failure.d.ts +38 -0
- package/lib/types/http.d.ts +48 -0
- package/lib/types/image-input-admission.d.ts +5 -0
- package/lib/types/index.d.ts +39 -0
- package/lib/types/manual-compaction-recovery.d.ts +67 -0
- package/lib/types/migration-status.d.ts +50 -0
- package/lib/types/model-exclusions.d.ts +15 -0
- package/lib/types/model-preferences-card.d.ts +9 -0
- package/lib/types/model-protocol.d.ts +31 -0
- package/lib/types/native-select-style.d.ts +4 -0
- package/lib/types/native-settings-style.d.ts +10 -0
- package/lib/types/parent-model-follow-card.d.ts +32 -0
- package/lib/types/parent-model-follow.d.ts +44 -0
- package/lib/types/pi-provider-bridge.d.ts +22 -0
- package/lib/types/plan.d.ts +148 -0
- package/lib/types/pre-step-pressure.d.ts +8 -0
- package/lib/types/preview-provider.d.ts +77 -0
- package/lib/types/preview-route.d.ts +76 -0
- package/lib/types/probe.d.ts +39 -0
- package/lib/types/remote-codec.d.ts +10 -0
- package/lib/types/remote.d.ts +202 -0
- package/lib/types/replay-recovery-host.d.ts +28 -0
- package/lib/types/replay-recovery-remote.d.ts +14 -0
- package/lib/types/replay-recovery-types.d.ts +24 -0
- package/lib/types/replay-recovery-ui.d.ts +28 -0
- package/lib/types/replay-recovery.d.ts +17 -0
- package/lib/types/request-body-composition.d.ts +17 -0
- package/lib/types/request-body-evidence.d.ts +37 -0
- package/lib/types/request-body-timeout-marker.d.ts +2 -0
- package/lib/types/request-body-timeout.d.ts +4 -0
- package/lib/types/request-budget.d.ts +58 -0
- package/lib/types/request-diagnostics.d.ts +278 -0
- package/lib/types/request-upload-evidence.d.ts +23 -0
- package/lib/types/response-error-body.d.ts +3 -0
- package/lib/types/responses-reasoning-text.d.ts +24 -0
- package/lib/types/responses-reasoning.d.ts +7 -0
- package/lib/types/responses-replay-compat.d.ts +31 -0
- package/lib/types/responses-request-compression.d.ts +33 -0
- package/lib/types/route-ownership.d.ts +70 -0
- package/lib/types/routed-web.d.ts +50 -0
- package/lib/types/search-backend.d.ts +16 -0
- package/lib/types/search-routing-host.d.ts +19 -0
- package/lib/types/search-routing-policy.d.ts +18 -0
- package/lib/types/search-routing-remote.d.ts +20 -0
- package/lib/types/search-routing.d.ts +43 -0
- package/lib/types/search-tool-routing.d.ts +22 -0
- package/lib/types/serialize.d.ts +106 -0
- package/lib/types/session-accounts-controller.d.ts +20 -0
- package/lib/types/session-accounts-host.d.ts +33 -0
- package/lib/types/session-accounts-remote.d.ts +114 -0
- package/lib/types/session-accounts.d.ts +38 -0
- package/lib/types/session-continuation-host.d.ts +45 -0
- package/lib/types/session-continuation-remote.d.ts +22 -0
- package/lib/types/session-continuation-types.d.ts +62 -0
- package/lib/types/session-continuation-ui.d.ts +49 -0
- package/lib/types/session-continuation.d.ts +14 -0
- package/lib/types/settings-reader.d.ts +16 -0
- package/lib/types/sse.d.ts +28 -0
- package/lib/types/temporary-models.d.ts +25 -0
- package/lib/types/tool-schema-compat.d.ts +17 -0
- package/lib/types/traditional-search.d.ts +17 -0
- package/lib/types/turn-model-provenance.d.ts +45 -0
- package/lib/types/turn-request-models.d.ts +55 -0
- package/lib/types/turn-selection-card.d.ts +24 -0
- package/lib/types/turn-selection-host.d.ts +35 -0
- package/lib/types/turn-selection-remote.d.ts +17 -0
- package/lib/types/turn-selection.d.ts +186 -0
- package/lib/types/turn-usage-evidence.d.ts +66 -0
- package/lib/types/turn-usage-notice.d.ts +7 -0
- package/lib/types/types.d.ts +69 -0
- package/lib/types/usage.d.ts +26 -0
- package/lib/types/watchdog.d.ts +22 -0
- package/lib/types/web-delegate.d.ts +12 -0
- package/lib/types/web-search-routing-card.d.ts +16 -0
- package/lib/types/web-search-routing-config.d.ts +12 -0
- package/lib/types/wire-anthropic.d.ts +37 -0
- package/lib/types/wire.d.ts +56 -0
- package/lib/web-delegate.js +9 -0
- package/output/auto-model-mockup/index.html +207 -0
- package/package.json +261 -0
- package/scripts/analyze-diagnostics.mjs +91 -0
- package/scripts/check-search-composition.mjs +191 -0
- package/scripts/iteration-review.mjs +53 -0
- package/scripts/release-policy.mjs +353 -0
- package/scripts/select-core-release.mjs +11 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import { s as autoModelPreference } from "./copilot-identity-DRZY_d2X.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const MAX_MODEL_ID_LENGTH = 512;
|
|
4
|
+
/** Admission is bound to the native turn and its request signal, not the global picker. */
|
|
5
|
+
var ModelExclusionTurns = class {
|
|
6
|
+
turns = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
signals = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
admit(owner, turn, model, signal, excluded) {
|
|
9
|
+
const previous = this.turns.get(owner);
|
|
10
|
+
if (signal.aborted || excluded.has(model) && (previous?.turn !== turn || previous.model !== model)) {
|
|
11
|
+
if (previous?.turn !== turn) this.turns.delete(owner);
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
this.turns.set(owner, {
|
|
15
|
+
turn,
|
|
16
|
+
model
|
|
17
|
+
});
|
|
18
|
+
this.signals.set(signal, {
|
|
19
|
+
owner,
|
|
20
|
+
turn,
|
|
21
|
+
model
|
|
22
|
+
});
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
permits(signal, model) {
|
|
26
|
+
if (signal === void 0 || signal.aborted) return false;
|
|
27
|
+
const admitted = this.signals.get(signal);
|
|
28
|
+
if (admitted?.model !== model) return false;
|
|
29
|
+
const current = this.turns.get(admitted.owner);
|
|
30
|
+
return current?.turn === admitted.turn && current.model === model;
|
|
31
|
+
}
|
|
32
|
+
end(owner) {
|
|
33
|
+
this.turns.delete(owner);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function normalizeExcludedModelIds(value) {
|
|
37
|
+
if (value === void 0) return [];
|
|
38
|
+
if (!Array.isArray(value) || value.length > 512) throw new Error("COPILOT_MODEL_EXCLUSIONS_INVALID");
|
|
39
|
+
const ids = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const candidate of value) {
|
|
41
|
+
if (typeof candidate !== "string" || candidate.length === 0 || candidate.length > MAX_MODEL_ID_LENGTH || candidate.trim() !== candidate || autoModelPreference(candidate) !== void 0) throw new Error("COPILOT_MODEL_EXCLUSIONS_INVALID");
|
|
42
|
+
ids.add(candidate);
|
|
43
|
+
}
|
|
44
|
+
return [...ids].toSorted();
|
|
45
|
+
}
|
|
46
|
+
function excludedModelSet(value) {
|
|
47
|
+
return new Set(normalizeExcludedModelIds(value));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region lib/types/auto-allocation.js
|
|
51
|
+
const AUTO_ALLOCATION_POLICIES = [
|
|
52
|
+
"high-cost-v1",
|
|
53
|
+
"high-cost-v2",
|
|
54
|
+
"high-cost-v3",
|
|
55
|
+
"high-cost-v4"
|
|
56
|
+
];
|
|
57
|
+
const AUTO_ALLOCATION_POLICY = "high-cost-v4";
|
|
58
|
+
const categories = [
|
|
59
|
+
"powerful",
|
|
60
|
+
"versatile",
|
|
61
|
+
"lightweight",
|
|
62
|
+
"unknown"
|
|
63
|
+
];
|
|
64
|
+
function autoCategoryWeight(category, target) {
|
|
65
|
+
if (category === "unknown") return .02;
|
|
66
|
+
return [
|
|
67
|
+
1,
|
|
68
|
+
.25,
|
|
69
|
+
.05
|
|
70
|
+
][(target === "powerful" ? [
|
|
71
|
+
"powerful",
|
|
72
|
+
"versatile",
|
|
73
|
+
"lightweight"
|
|
74
|
+
] : target === "lightweight" ? [
|
|
75
|
+
"lightweight",
|
|
76
|
+
"versatile",
|
|
77
|
+
"powerful"
|
|
78
|
+
] : [
|
|
79
|
+
"versatile",
|
|
80
|
+
"powerful",
|
|
81
|
+
"lightweight"
|
|
82
|
+
]).indexOf(category)];
|
|
83
|
+
}
|
|
84
|
+
const AutoAllocationSchema = z.object({
|
|
85
|
+
policyVersion: z.enum(AUTO_ALLOCATION_POLICIES),
|
|
86
|
+
targetCategory: z.enum([
|
|
87
|
+
"powerful",
|
|
88
|
+
"versatile",
|
|
89
|
+
"lightweight"
|
|
90
|
+
]).optional(),
|
|
91
|
+
deferredHighCostCount: z.number().int().min(0).max(511).optional(),
|
|
92
|
+
selectedModelId: z.string().min(1).max(512),
|
|
93
|
+
candidates: z.array(z.object({
|
|
94
|
+
modelId: z.string().min(1).max(512),
|
|
95
|
+
category: z.enum(categories).optional(),
|
|
96
|
+
categoryWeight: z.number().positive().max(1).optional(),
|
|
97
|
+
highCost: z.boolean(),
|
|
98
|
+
previous: z.boolean(),
|
|
99
|
+
weight: z.number().positive().max(1.5),
|
|
100
|
+
expectedShare: z.number().positive().max(1)
|
|
101
|
+
}).strict()).min(1).max(512)
|
|
102
|
+
}).strict().refine((value) => {
|
|
103
|
+
const total = value.candidates.reduce((sum, row) => sum + row.weight, 0);
|
|
104
|
+
const legacy = value.policyVersion === "high-cost-v1";
|
|
105
|
+
const soft = value.policyVersion === "high-cost-v4";
|
|
106
|
+
const decay = value.policyVersion === "high-cost-v3" || soft;
|
|
107
|
+
const categoryValid = soft ? value.targetCategory !== void 0 && value.candidates.every((row) => row.category !== void 0 && row.categoryWeight === autoCategoryWeight(row.category, value.targetCategory)) : value.targetCategory === void 0 && value.candidates.every((row) => row.category === void 0 && row.categoryWeight === void 0);
|
|
108
|
+
const tierValid = legacy || decay ? value.deferredHighCostCount === void 0 : value.deferredHighCostCount !== void 0 && value.candidates.length + value.deferredHighCostCount <= 512 && value.candidates.every((row) => row.highCost === value.candidates[0].highCost) && (!value.candidates[0].highCost || value.deferredHighCostCount === 0);
|
|
109
|
+
return categoryValid && tierValid && new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (decay && row.highCost && row.previous ? 2 : (row.highCost ? 20 : 100) * (row.previous && (legacy || !row.highCost) ? 1.5 : 1)) * (soft ? Math.round(row.categoryWeight * 100) : 100) / 1e4 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
|
|
110
|
+
}, { message: "Invalid allocation policy evidence" });
|
|
111
|
+
function normalizeHighCostModelIds(value) {
|
|
112
|
+
try {
|
|
113
|
+
return normalizeExcludedModelIds(value);
|
|
114
|
+
} catch (cause) {
|
|
115
|
+
if (cause instanceof Error && cause.message === "COPILOT_MODEL_EXCLUSIONS_INVALID") throw new Error("COPILOT_HIGH_COST_MODELS_INVALID");
|
|
116
|
+
throw cause;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Integer policy units avoid cumulative decimal drift; avalanche sequential turn seeds. */
|
|
120
|
+
function allocateAutoModel(pool, highCostModelIds, previousModelId, seed, targetCategory = "powerful") {
|
|
121
|
+
if (!Number.isSafeInteger(seed) || pool.length === 0 || pool.length > 512 || normalizeExcludedModelIds(pool.map((model) => model.id)).length !== pool.length) throw new Error("COPILOT_AUTO_ALLOCATION_INVALID");
|
|
122
|
+
const marked = new Set(normalizeHighCostModelIds(highCostModelIds));
|
|
123
|
+
const rows = pool.map((model) => {
|
|
124
|
+
const highCost = marked.has(model.id);
|
|
125
|
+
const previous = model.id === previousModelId;
|
|
126
|
+
const category = model.category ?? "unknown";
|
|
127
|
+
const categoryWeight = autoCategoryWeight(category, targetCategory);
|
|
128
|
+
const units = (highCost ? previous ? 2 : 20 : previous ? 150 : 100) * Math.round(categoryWeight * 100);
|
|
129
|
+
return {
|
|
130
|
+
modelId: model.id,
|
|
131
|
+
category,
|
|
132
|
+
categoryWeight,
|
|
133
|
+
highCost,
|
|
134
|
+
previous,
|
|
135
|
+
units
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const total = rows.reduce((sum, row) => sum + row.units, 0);
|
|
139
|
+
let hash = seed >>> 0;
|
|
140
|
+
hash = Math.imul(hash ^ hash >>> 16, 2246822507);
|
|
141
|
+
hash = Math.imul(hash ^ hash >>> 13, 3266489909);
|
|
142
|
+
const point = ((hash ^ hash >>> 16) >>> 0) / 4294967296 * total;
|
|
143
|
+
let boundary = 0;
|
|
144
|
+
const selected = rows.find((row) => {
|
|
145
|
+
boundary += row.units;
|
|
146
|
+
return point < boundary;
|
|
147
|
+
});
|
|
148
|
+
return Object.freeze({
|
|
149
|
+
policyVersion: AUTO_ALLOCATION_POLICY,
|
|
150
|
+
targetCategory,
|
|
151
|
+
selectedModelId: selected.modelId,
|
|
152
|
+
candidates: Object.freeze(rows.map(({ units, ...row }) => Object.freeze({
|
|
153
|
+
...row,
|
|
154
|
+
weight: units / 1e4,
|
|
155
|
+
expectedShare: units / total
|
|
156
|
+
})))
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region lib/types/auto-allocation-diagnostics.js
|
|
161
|
+
const AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS = 1024;
|
|
162
|
+
const AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS = 12096e5;
|
|
163
|
+
const dayMs = 864e5;
|
|
164
|
+
const integer$2 = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
165
|
+
const version$1 = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
|
|
166
|
+
const assessmentOutcome = z.enum([
|
|
167
|
+
"local-known",
|
|
168
|
+
"local-unknown",
|
|
169
|
+
"semantic-known",
|
|
170
|
+
"semantic-unknown",
|
|
171
|
+
"disabled",
|
|
172
|
+
"unavailable",
|
|
173
|
+
"invalid-result",
|
|
174
|
+
"timeout",
|
|
175
|
+
"failed",
|
|
176
|
+
"context-omitted"
|
|
177
|
+
]);
|
|
178
|
+
const allocationRow = z.object({
|
|
179
|
+
day: integer$2.multipleOf(dayMs),
|
|
180
|
+
version: version$1,
|
|
181
|
+
policyVersion: z.string().min(1).max(64),
|
|
182
|
+
modelId: z.string().min(1).max(512),
|
|
183
|
+
targetCategory: z.enum([
|
|
184
|
+
"powerful",
|
|
185
|
+
"versatile",
|
|
186
|
+
"lightweight"
|
|
187
|
+
]),
|
|
188
|
+
category: z.enum([
|
|
189
|
+
"powerful",
|
|
190
|
+
"versatile",
|
|
191
|
+
"lightweight",
|
|
192
|
+
"unknown"
|
|
193
|
+
]),
|
|
194
|
+
demand: z.enum([
|
|
195
|
+
"simple",
|
|
196
|
+
"routine",
|
|
197
|
+
"complex",
|
|
198
|
+
"unknown"
|
|
199
|
+
]),
|
|
200
|
+
assessmentSource: z.enum(["local", "semantic"]),
|
|
201
|
+
assessmentOutcome: assessmentOutcome.optional(),
|
|
202
|
+
method: z.enum(["weighted-distribution", "only-candidate"]),
|
|
203
|
+
fallback: z.boolean(),
|
|
204
|
+
highCost: z.boolean(),
|
|
205
|
+
previous: z.boolean(),
|
|
206
|
+
weight: z.number().positive().max(1.5),
|
|
207
|
+
opportunities: integer$2.min(1),
|
|
208
|
+
expectedSelections: z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
209
|
+
selections: integer$2
|
|
210
|
+
}).strict();
|
|
211
|
+
const noFitRow = z.object({
|
|
212
|
+
day: integer$2.multipleOf(dayMs),
|
|
213
|
+
version: version$1,
|
|
214
|
+
policyVersion: z.string().min(1).max(64),
|
|
215
|
+
targetCategory: z.enum([
|
|
216
|
+
"powerful",
|
|
217
|
+
"versatile",
|
|
218
|
+
"lightweight"
|
|
219
|
+
]),
|
|
220
|
+
category: z.enum([
|
|
221
|
+
"powerful",
|
|
222
|
+
"versatile",
|
|
223
|
+
"lightweight",
|
|
224
|
+
"unknown"
|
|
225
|
+
]),
|
|
226
|
+
demand: z.enum([
|
|
227
|
+
"simple",
|
|
228
|
+
"routine",
|
|
229
|
+
"complex",
|
|
230
|
+
"unknown"
|
|
231
|
+
]),
|
|
232
|
+
assessmentSource: z.enum(["local", "semantic"]),
|
|
233
|
+
assessmentOutcome: assessmentOutcome.optional(),
|
|
234
|
+
decisions: integer$2.min(1)
|
|
235
|
+
}).strict();
|
|
236
|
+
const AutoAllocationDiagnosticsSchema = z.object({
|
|
237
|
+
status: z.enum(["observed", "not-collected"]),
|
|
238
|
+
rows: z.array(allocationRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
|
|
239
|
+
noFitRows: z.array(noFitRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
|
|
240
|
+
observationStart: integer$2.nullable(),
|
|
241
|
+
observationEnd: integer$2.nullable(),
|
|
242
|
+
completeHistory: z.literal(false),
|
|
243
|
+
rowsTruncated: z.boolean(),
|
|
244
|
+
dropped: integer$2,
|
|
245
|
+
expired: integer$2,
|
|
246
|
+
saturated: integer$2,
|
|
247
|
+
restarts: integer$2
|
|
248
|
+
}).strict().refine((value) => JSON.stringify(value).length <= 15e5, "Auto allocation diagnostic capacity exceeded").refine((value) => value.rows.length + value.noFitRows.length <= AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS, "Auto allocation row capacity exceeded").refine(({ observationStart, observationEnd }) => observationStart === null ? observationEnd === null : observationEnd !== null && observationEnd >= observationStart, "Auto allocation observation window is inconsistent");
|
|
249
|
+
function emptyAutoAllocationDiagnostics() {
|
|
250
|
+
return {
|
|
251
|
+
status: "not-collected",
|
|
252
|
+
rows: [],
|
|
253
|
+
noFitRows: [],
|
|
254
|
+
observationStart: null,
|
|
255
|
+
observationEnd: null,
|
|
256
|
+
completeHistory: false,
|
|
257
|
+
rowsTruncated: false,
|
|
258
|
+
dropped: 0,
|
|
259
|
+
expired: 0,
|
|
260
|
+
saturated: 0,
|
|
261
|
+
restarts: 0
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** Profile-local rolling aggregates; no per-turn, Session, prompt, or execution-outcome records. */
|
|
265
|
+
var AutoAllocationDiagnosticsCollector = class {
|
|
266
|
+
version;
|
|
267
|
+
changed;
|
|
268
|
+
wall;
|
|
269
|
+
data = emptyAutoAllocationDiagnostics();
|
|
270
|
+
enabled = false;
|
|
271
|
+
constructor(version, changed = () => {}, wall = Date.now) {
|
|
272
|
+
this.version = version;
|
|
273
|
+
this.changed = changed;
|
|
274
|
+
this.wall = wall;
|
|
275
|
+
}
|
|
276
|
+
restore(value, countRestart = true) {
|
|
277
|
+
this.data = AutoAllocationDiagnosticsSchema.parse(value);
|
|
278
|
+
if (countRestart && this.data.status === "observed") {
|
|
279
|
+
this.data.restarts = this.add(this.data.restarts, 1);
|
|
280
|
+
this.expire();
|
|
281
|
+
this.changed();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
setEnabled(enabled) {
|
|
285
|
+
this.enabled = enabled;
|
|
286
|
+
}
|
|
287
|
+
clear() {
|
|
288
|
+
this.data = emptyAutoAllocationDiagnostics();
|
|
289
|
+
this.changed();
|
|
290
|
+
}
|
|
291
|
+
record(explanation) {
|
|
292
|
+
if (!this.enabled) return;
|
|
293
|
+
const now = this.wall();
|
|
294
|
+
this.expire(now);
|
|
295
|
+
const day = Math.floor(now / dayMs) * dayMs;
|
|
296
|
+
const assessment = explanation.assessment;
|
|
297
|
+
const outcome = assessment.diagnostic ?? (assessment.source === "local" ? assessment.demand === "unknown" ? "local-unknown" : "local-known" : assessment.demand === "unknown" ? "semantic-unknown" : "semantic-known");
|
|
298
|
+
this.data.observationStart = this.data.observationStart === null ? day : Math.min(this.data.observationStart, day);
|
|
299
|
+
this.data.observationEnd = this.data.observationEnd === null ? day : Math.max(this.data.observationEnd, day);
|
|
300
|
+
if (explanation.method === "no-fit") {
|
|
301
|
+
const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v4" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome);
|
|
302
|
+
if (row) row.decisions = this.add(row.decisions, 1);
|
|
303
|
+
else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.noFitRows.push({
|
|
304
|
+
day,
|
|
305
|
+
version: this.version,
|
|
306
|
+
policyVersion: AUTO_ALLOCATION_POLICY,
|
|
307
|
+
targetCategory: explanation.targetCategory,
|
|
308
|
+
category: explanation.selectedCategory,
|
|
309
|
+
demand: explanation.assessment.demand,
|
|
310
|
+
assessmentSource: explanation.assessment.source,
|
|
311
|
+
assessmentOutcome: outcome,
|
|
312
|
+
decisions: 1
|
|
313
|
+
});
|
|
314
|
+
else {
|
|
315
|
+
this.data.rowsTruncated = true;
|
|
316
|
+
this.data.dropped = this.add(this.data.dropped, 1);
|
|
317
|
+
}
|
|
318
|
+
this.data.status = "observed";
|
|
319
|
+
this.changed();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (explanation.method !== "weighted-distribution" && explanation.method !== "only-candidate") return;
|
|
323
|
+
const parsed = AutoAllocationSchema.safeParse(explanation.allocation);
|
|
324
|
+
if (!parsed.success || parsed.data.policyVersion !== "high-cost-v4") {
|
|
325
|
+
this.data.dropped = this.add(this.data.dropped, 1);
|
|
326
|
+
this.changed();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const allocation = parsed.data;
|
|
330
|
+
for (const candidate of allocation.candidates) {
|
|
331
|
+
const category = candidate.category ?? explanation.selectedCategory;
|
|
332
|
+
const row = this.data.rows.find((item) => item.day === day && item.version === this.version && item.policyVersion === allocation.policyVersion && item.modelId === candidate.modelId && item.targetCategory === explanation.targetCategory && item.category === category && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
|
|
333
|
+
if (row) {
|
|
334
|
+
row.opportunities = this.add(row.opportunities, 1);
|
|
335
|
+
row.expectedSelections = Math.min(Number.MAX_SAFE_INTEGER, row.expectedSelections + candidate.expectedShare);
|
|
336
|
+
if (allocation.selectedModelId === candidate.modelId) row.selections = this.add(row.selections, 1);
|
|
337
|
+
} else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.rows.push({
|
|
338
|
+
day,
|
|
339
|
+
version: this.version,
|
|
340
|
+
policyVersion: allocation.policyVersion,
|
|
341
|
+
modelId: candidate.modelId,
|
|
342
|
+
targetCategory: explanation.targetCategory,
|
|
343
|
+
category,
|
|
344
|
+
demand: explanation.assessment.demand,
|
|
345
|
+
assessmentSource: explanation.assessment.source,
|
|
346
|
+
method: explanation.method,
|
|
347
|
+
fallback: explanation.fallback,
|
|
348
|
+
assessmentOutcome: outcome,
|
|
349
|
+
highCost: candidate.highCost,
|
|
350
|
+
previous: candidate.previous,
|
|
351
|
+
weight: candidate.weight,
|
|
352
|
+
opportunities: 1,
|
|
353
|
+
expectedSelections: candidate.expectedShare,
|
|
354
|
+
selections: allocation.selectedModelId === candidate.modelId ? 1 : 0
|
|
355
|
+
});
|
|
356
|
+
else {
|
|
357
|
+
this.data.rowsTruncated = true;
|
|
358
|
+
this.data.dropped = this.add(this.data.dropped, 1);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
this.data.status = "observed";
|
|
362
|
+
this.changed();
|
|
363
|
+
}
|
|
364
|
+
snapshot() {
|
|
365
|
+
this.expire();
|
|
366
|
+
return AutoAllocationDiagnosticsSchema.parse({
|
|
367
|
+
...this.data,
|
|
368
|
+
rows: this.data.rows.map((row) => ({ ...row })),
|
|
369
|
+
noFitRows: this.data.noFitRows.map((row) => ({ ...row }))
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
expire(now = this.wall()) {
|
|
373
|
+
const oldest = Math.floor((now - AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS) / dayMs) * dayMs;
|
|
374
|
+
const rows = this.data.rows.filter((row) => row.day > oldest);
|
|
375
|
+
const noFitRows = this.data.noFitRows.filter((row) => row.day > oldest);
|
|
376
|
+
const removed = this.data.rows.length + this.data.noFitRows.length - rows.length - noFitRows.length;
|
|
377
|
+
if (removed > 0) {
|
|
378
|
+
this.data.rows = rows;
|
|
379
|
+
this.data.noFitRows = noFitRows;
|
|
380
|
+
this.data.expired = this.add(this.data.expired, removed);
|
|
381
|
+
const retainedDays = [...rows, ...noFitRows].map((row) => row.day);
|
|
382
|
+
this.data.observationStart = retainedDays.length ? Math.min(...retainedDays) : null;
|
|
383
|
+
this.data.observationEnd = retainedDays.length ? Math.max(...retainedDays) : null;
|
|
384
|
+
this.changed();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
add(value, amount) {
|
|
388
|
+
if (value > Number.MAX_SAFE_INTEGER - amount) {
|
|
389
|
+
this.data.saturated = Math.min(Number.MAX_SAFE_INTEGER, this.data.saturated + 1);
|
|
390
|
+
return Number.MAX_SAFE_INTEGER;
|
|
391
|
+
}
|
|
392
|
+
return value + amount;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region lib/types/request-diagnostics.js
|
|
397
|
+
const integer$1 = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
398
|
+
const composition = z.discriminatedUnion("state", [z.object({
|
|
399
|
+
state: z.literal("complete"),
|
|
400
|
+
totalBytes: integer$1,
|
|
401
|
+
conversationBytes: integer$1,
|
|
402
|
+
toolSchemaBytes: integer$1,
|
|
403
|
+
systemBytes: integer$1,
|
|
404
|
+
otherBytes: integer$1,
|
|
405
|
+
imageBlockBytes: integer$1,
|
|
406
|
+
opaqueReplayBytes: integer$1,
|
|
407
|
+
remainingConversationBytes: integer$1
|
|
408
|
+
}).strict(), z.object({
|
|
409
|
+
state: z.enum([
|
|
410
|
+
"unavailable",
|
|
411
|
+
"size-limit",
|
|
412
|
+
"work-limit",
|
|
413
|
+
"invalid-json",
|
|
414
|
+
"unsupported-shape",
|
|
415
|
+
"cancelled",
|
|
416
|
+
"time-limit"
|
|
417
|
+
]),
|
|
418
|
+
totalBytes: integer$1.optional()
|
|
419
|
+
}).strict()]);
|
|
420
|
+
const upload = z.discriminatedUnion("state", [
|
|
421
|
+
z.object({
|
|
422
|
+
state: z.literal("observed"),
|
|
423
|
+
bodyWrite: z.enum(["observed", "not-observed"]),
|
|
424
|
+
bodyWriteCompleteMs: integer$1.optional(),
|
|
425
|
+
nativeResponseHeadersMs: integer$1.optional(),
|
|
426
|
+
alpn: z.enum([
|
|
427
|
+
"h2",
|
|
428
|
+
"http/1.1",
|
|
429
|
+
"unavailable"
|
|
430
|
+
]),
|
|
431
|
+
nodeWritableBufferBytes: integer$1.optional()
|
|
432
|
+
}).strict(),
|
|
433
|
+
z.object({ state: z.enum(["unavailable", "work-limit"]) }).strict(),
|
|
434
|
+
z.object({
|
|
435
|
+
state: z.literal("ambiguous"),
|
|
436
|
+
requestCount: integer$1
|
|
437
|
+
}).strict()
|
|
438
|
+
]);
|
|
439
|
+
const REQUEST_DIAGNOSTICS_RETENTION_MS = 864e5;
|
|
440
|
+
const CredentialChangeReasonSchema = z.enum([
|
|
441
|
+
"qualified",
|
|
442
|
+
"unknown-source",
|
|
443
|
+
"account-changed",
|
|
444
|
+
"endpoint-changed",
|
|
445
|
+
"entitlements-changed",
|
|
446
|
+
"expired",
|
|
447
|
+
"auth-mismatch",
|
|
448
|
+
"duplicate-notification",
|
|
449
|
+
"missing-notification",
|
|
450
|
+
"commit-mismatch",
|
|
451
|
+
"write-failed",
|
|
452
|
+
"write-conflict"
|
|
453
|
+
]);
|
|
454
|
+
const CredentialChangeSchema = z.object({
|
|
455
|
+
changeId: z.string().uuid(),
|
|
456
|
+
observedAt: integer$1,
|
|
457
|
+
version: z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/),
|
|
458
|
+
phase: z.enum(["notification", "commit"]),
|
|
459
|
+
reason: CredentialChangeReasonSchema,
|
|
460
|
+
preparing: integer$1,
|
|
461
|
+
dispatched: integer$1,
|
|
462
|
+
alreadyAborted: integer$1,
|
|
463
|
+
preserved: integer$1,
|
|
464
|
+
revoked: integer$1
|
|
465
|
+
}).strict();
|
|
466
|
+
const RequestDiagnosticSchema = z.object({
|
|
467
|
+
streamId: z.string().uuid(),
|
|
468
|
+
dispatchIndex: integer$1.min(1),
|
|
469
|
+
version: z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/),
|
|
470
|
+
startedAt: integer$1,
|
|
471
|
+
elapsedMs: integer$1,
|
|
472
|
+
model: z.string().max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/),
|
|
473
|
+
protocol: z.enum([
|
|
474
|
+
"openai-responses",
|
|
475
|
+
"openai-completions",
|
|
476
|
+
"anthropic-messages"
|
|
477
|
+
]),
|
|
478
|
+
composition,
|
|
479
|
+
encoding: z.enum([
|
|
480
|
+
"identity",
|
|
481
|
+
"gzip",
|
|
482
|
+
"unknown"
|
|
483
|
+
]),
|
|
484
|
+
wireBytes: integer$1.optional(),
|
|
485
|
+
upload: upload.optional(),
|
|
486
|
+
responseHeadersMs: integer$1.optional(),
|
|
487
|
+
httpStatus: integer$1.min(100).max(599).optional(),
|
|
488
|
+
outcome: z.enum([
|
|
489
|
+
"http-error",
|
|
490
|
+
"transport-error",
|
|
491
|
+
"stream-done",
|
|
492
|
+
"stream-error",
|
|
493
|
+
"cancelled",
|
|
494
|
+
"interrupted"
|
|
495
|
+
]),
|
|
496
|
+
reason: z.enum([
|
|
497
|
+
"none",
|
|
498
|
+
"unknown",
|
|
499
|
+
"request-body-timeout",
|
|
500
|
+
"caller-abort",
|
|
501
|
+
"credential-changed",
|
|
502
|
+
"disposed",
|
|
503
|
+
"byte-idle-timeout",
|
|
504
|
+
"signal-abort"
|
|
505
|
+
])
|
|
506
|
+
}).strict();
|
|
507
|
+
const RequestDiagnosticsSchema = z.object({
|
|
508
|
+
rows: z.array(RequestDiagnosticSchema).max(128),
|
|
509
|
+
dropped: integer$1,
|
|
510
|
+
evicted: integer$1,
|
|
511
|
+
pending: integer$1.max(128).optional(),
|
|
512
|
+
interruptedOnReopen: integer$1.optional(),
|
|
513
|
+
credentialChanges: z.object({
|
|
514
|
+
rows: z.array(CredentialChangeSchema).max(128),
|
|
515
|
+
dropped: integer$1,
|
|
516
|
+
evicted: integer$1,
|
|
517
|
+
pending: integer$1.max(128).optional(),
|
|
518
|
+
interruptedOnReopen: integer$1.optional()
|
|
519
|
+
}).strict().optional()
|
|
520
|
+
}).strict();
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region lib/types/diagnostics-types.js
|
|
523
|
+
const DIAGNOSTICS_OPERATIONS = [
|
|
524
|
+
"account-global-switch",
|
|
525
|
+
"account-session-select",
|
|
526
|
+
"account-session-inherit",
|
|
527
|
+
"identity-read",
|
|
528
|
+
"identity-flight",
|
|
529
|
+
"compaction",
|
|
530
|
+
"compaction-summary",
|
|
531
|
+
"collection"
|
|
532
|
+
];
|
|
533
|
+
const DIAGNOSTICS_STAGES = [
|
|
534
|
+
"admitted",
|
|
535
|
+
"rpc-invoked",
|
|
536
|
+
"host-received",
|
|
537
|
+
"identity-validation",
|
|
538
|
+
"model-validation",
|
|
539
|
+
"cas",
|
|
540
|
+
"readback",
|
|
541
|
+
"response-received",
|
|
542
|
+
"decoded",
|
|
543
|
+
"client-settled",
|
|
544
|
+
"summary-attempt",
|
|
545
|
+
"checkpoint-committed",
|
|
546
|
+
"ended",
|
|
547
|
+
"cache-hit",
|
|
548
|
+
"joined-flight",
|
|
549
|
+
"cooldown",
|
|
550
|
+
"dispatched"
|
|
551
|
+
];
|
|
552
|
+
const DIAGNOSTICS_METRICS = [
|
|
553
|
+
"started",
|
|
554
|
+
"stage",
|
|
555
|
+
"success",
|
|
556
|
+
"no-op",
|
|
557
|
+
"cancelled",
|
|
558
|
+
"policy-rejected",
|
|
559
|
+
"revoked",
|
|
560
|
+
"environment-fault",
|
|
561
|
+
"failed",
|
|
562
|
+
"unknown",
|
|
563
|
+
"interrupted",
|
|
564
|
+
"dropped",
|
|
565
|
+
"paused",
|
|
566
|
+
"expired",
|
|
567
|
+
"clock-discontinuity",
|
|
568
|
+
"pending-sample"
|
|
569
|
+
];
|
|
570
|
+
const DIAGNOSTICS_REASONS = [
|
|
571
|
+
"none",
|
|
572
|
+
"unknown",
|
|
573
|
+
"rpc-unavailable",
|
|
574
|
+
"decode-invalid",
|
|
575
|
+
"COPILOT_ACCOUNTS_BUSY",
|
|
576
|
+
"COPILOT_ACCOUNTS_CONFLICT",
|
|
577
|
+
"COPILOT_ACCOUNTS_CHANGED",
|
|
578
|
+
"COPILOT_ACCOUNTS_COMMIT_UNCERTAIN",
|
|
579
|
+
"COPILOT_ACCOUNTS_IDENTITY_TIMEOUT",
|
|
580
|
+
"COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE",
|
|
581
|
+
"COPILOT_ACCOUNTS_MODELS_FAILED",
|
|
582
|
+
"COPILOT_ACCOUNTS_SETTINGS_UNAVAILABLE",
|
|
583
|
+
"COPILOT_ACCOUNTS_IDENTITY_TLS",
|
|
584
|
+
"COPILOT_ACCOUNTS_IDENTITY_NETWORK",
|
|
585
|
+
"COPILOT_ACCOUNTS_IDENTITY_RATE_LIMITED",
|
|
586
|
+
"COPILOT_ACCOUNTS_IDENTITY_AUTH_REJECTED",
|
|
587
|
+
"COPILOT_ACCOUNTS_IDENTITY_HTTP_ERROR",
|
|
588
|
+
"COPILOT_ACCOUNTS_IDENTITY_INVALID",
|
|
589
|
+
"COPILOT_SESSION_ACCOUNTS_UNAVAILABLE",
|
|
590
|
+
"COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE",
|
|
591
|
+
"COPILOT_SESSION_ACCOUNTS_COMMIT_UNCERTAIN",
|
|
592
|
+
"COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH",
|
|
593
|
+
"CONTEXT_WINDOW_EXCEEDED",
|
|
594
|
+
"COPILOT_MANUAL_RECOVERY_FIXED_PREFIX",
|
|
595
|
+
"COPILOT_MANUAL_RECOVERY_INDIVISIBLE",
|
|
596
|
+
"COPILOT_MANUAL_RECOVERY_TOKEN_METER_UNAVAILABLE",
|
|
597
|
+
"COPILOT_MANUAL_RECOVERY_TOKEN_ESTIMATE_INVALID",
|
|
598
|
+
"COPILOT_MANUAL_RECOVERY_CALL_LIMIT",
|
|
599
|
+
"COPILOT_MANUAL_RECOVERY_EMPTY_SUMMARY",
|
|
600
|
+
"COPILOT_MANUAL_RECOVERY_UNBALANCED"
|
|
601
|
+
];
|
|
602
|
+
const DIAGNOSTICS_MAX_ROWS = 4096;
|
|
603
|
+
const DIAGNOSTICS_MAX_BYTES = 2097152;
|
|
604
|
+
const DIAGNOSTICS_RETENTION_MS = 12096e5;
|
|
605
|
+
const integer = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
606
|
+
const version = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
|
|
607
|
+
const DiagnosticsRowSchema = z.object({
|
|
608
|
+
hour: integer.multipleOf(36e5),
|
|
609
|
+
version,
|
|
610
|
+
layer: z.enum(["client", "host"]),
|
|
611
|
+
operation: z.enum(DIAGNOSTICS_OPERATIONS),
|
|
612
|
+
stage: z.enum(DIAGNOSTICS_STAGES),
|
|
613
|
+
metric: z.enum(DIAGNOSTICS_METRICS),
|
|
614
|
+
reason: z.enum(DIAGNOSTICS_REASONS),
|
|
615
|
+
bucket: z.number().int().min(0).max(7),
|
|
616
|
+
count: integer.min(1)
|
|
617
|
+
}).strict();
|
|
618
|
+
const DiagnosticsPendingSchema = z.object({
|
|
619
|
+
version,
|
|
620
|
+
operation: z.enum(DIAGNOSTICS_OPERATIONS),
|
|
621
|
+
stage: z.enum(DIAGNOSTICS_STAGES),
|
|
622
|
+
bucket: z.number().int().min(0).max(7),
|
|
623
|
+
count: integer.min(1).max(128)
|
|
624
|
+
}).strict();
|
|
625
|
+
const DiagnosticsSnapshotSchema = z.object({
|
|
626
|
+
schemaVersion: z.literal(1),
|
|
627
|
+
coverageVersion: z.literal(1),
|
|
628
|
+
epoch: integer,
|
|
629
|
+
updatedAt: integer,
|
|
630
|
+
rows: z.array(DiagnosticsRowSchema).max(DIAGNOSTICS_MAX_ROWS),
|
|
631
|
+
autoAllocation: AutoAllocationDiagnosticsSchema.optional(),
|
|
632
|
+
requests: RequestDiagnosticsSchema.optional(),
|
|
633
|
+
pending: z.array(DiagnosticsPendingSchema).max(128),
|
|
634
|
+
dropped: integer,
|
|
635
|
+
clientDropped: integer,
|
|
636
|
+
clientUnconfirmed: integer,
|
|
637
|
+
saturated: integer,
|
|
638
|
+
evicted: integer,
|
|
639
|
+
interrupted: integer
|
|
640
|
+
}).strict().refine((value) => value.pending.reduce((sum, row) => sum + row.count, 0) <= 128, "Diagnostics pending capacity exceeded").refine((value) => JSON.stringify(value).length <= DIAGNOSTICS_MAX_BYTES, "Diagnostics capacity exceeded");
|
|
641
|
+
const DiagnosticsViewSchema = z.object({
|
|
642
|
+
enabled: z.boolean(),
|
|
643
|
+
autoAllocationEnabled: z.boolean(),
|
|
644
|
+
requestEnabled: z.boolean().optional(),
|
|
645
|
+
state: z.enum([
|
|
646
|
+
"loading",
|
|
647
|
+
"ready",
|
|
648
|
+
"unavailable",
|
|
649
|
+
"error"
|
|
650
|
+
]),
|
|
651
|
+
diagnostic: z.enum([
|
|
652
|
+
"none",
|
|
653
|
+
"storage-unavailable",
|
|
654
|
+
"storage-invalid",
|
|
655
|
+
"storage-write-failed",
|
|
656
|
+
"profile-unavailable",
|
|
657
|
+
"settings-unavailable",
|
|
658
|
+
"settings-conflict",
|
|
659
|
+
"client-report-failed",
|
|
660
|
+
"client-report-revoked",
|
|
661
|
+
"closed"
|
|
662
|
+
]),
|
|
663
|
+
persistedAt: integer.optional(),
|
|
664
|
+
dirty: z.boolean(),
|
|
665
|
+
snapshot: DiagnosticsSnapshotSchema
|
|
666
|
+
}).strict();
|
|
667
|
+
function diagnosticsBucket(ms) {
|
|
668
|
+
return [
|
|
669
|
+
100,
|
|
670
|
+
500,
|
|
671
|
+
1e3,
|
|
672
|
+
5e3,
|
|
673
|
+
15e3,
|
|
674
|
+
6e4,
|
|
675
|
+
3e5
|
|
676
|
+
].findIndex((bound) => ms < bound) === -1 ? 7 : [
|
|
677
|
+
100,
|
|
678
|
+
500,
|
|
679
|
+
1e3,
|
|
680
|
+
5e3,
|
|
681
|
+
15e3,
|
|
682
|
+
6e4,
|
|
683
|
+
3e5
|
|
684
|
+
].findIndex((bound) => ms < bound);
|
|
685
|
+
}
|
|
686
|
+
function diagnosticsReason(error) {
|
|
687
|
+
const seen = /* @__PURE__ */ new Set();
|
|
688
|
+
for (let depth = 0; depth < 8 && error instanceof Error && !seen.has(error); depth++) {
|
|
689
|
+
seen.add(error);
|
|
690
|
+
const nativeCode = "code" in error ? error.code : void 0;
|
|
691
|
+
const typed = DIAGNOSTICS_REASONS.find((code) => code !== "none" && code !== "unknown" && code === nativeCode);
|
|
692
|
+
if (typed !== void 0) return typed;
|
|
693
|
+
const message = error.message.slice(0, 4096);
|
|
694
|
+
for (const code of DIAGNOSTICS_REASONS) if (code.startsWith("COPILOT_") || code === "CONTEXT_WINDOW_EXCEEDED") {
|
|
695
|
+
if (new RegExp(`(?:^|[^A-Za-z0-9_])${code}(?:$|[^A-Za-z0-9_])`).test(message)) return code;
|
|
696
|
+
}
|
|
697
|
+
error = error.cause;
|
|
698
|
+
}
|
|
699
|
+
return "unknown";
|
|
700
|
+
}
|
|
701
|
+
function diagnosticsOutcome(reason) {
|
|
702
|
+
if (reason === "COPILOT_ACCOUNTS_BUSY" || reason === "COPILOT_ACCOUNTS_CONFLICT") return "policy-rejected";
|
|
703
|
+
if (reason === "COPILOT_ACCOUNTS_CHANGED") return "revoked";
|
|
704
|
+
if (reason.endsWith("SETTINGS_UNAVAILABLE") || reason === "COPILOT_SESSION_ACCOUNTS_UNAVAILABLE") return "environment-fault";
|
|
705
|
+
return "failed";
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
export { excludedModelSet as C, ModelExclusionTurns as S, AUTO_ALLOCATION_POLICIES as _, DiagnosticsPendingSchema as a, allocateAutoModel as b, DiagnosticsViewSchema as c, diagnosticsReason as d, CredentialChangeSchema as f, emptyAutoAllocationDiagnostics as g, AutoAllocationDiagnosticsCollector as h, DIAGNOSTICS_RETENTION_MS as i, diagnosticsBucket as l, RequestDiagnosticSchema as m, DIAGNOSTICS_OPERATIONS as n, DiagnosticsRowSchema as o, REQUEST_DIAGNOSTICS_RETENTION_MS as p, DIAGNOSTICS_REASONS as r, DiagnosticsSnapshotSchema as s, DIAGNOSTICS_MAX_ROWS as t, diagnosticsOutcome as u, AUTO_ALLOCATION_POLICY as v, normalizeExcludedModelIds as w, normalizeHighCostModelIds as x, AutoAllocationSchema as y };
|