dsh-github-copilot 0.4.1 → 0.4.2-alpha.2

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.
@@ -1,4 +1,4 @@
1
- import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-FVf6zjob.js";
1
+ import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-Bl3QCfR0.js";
2
2
  import { z } from "zod";
3
3
  //#region lib/types/diagnostics-analysis.js
4
4
  const RETENTION_MS = 12096e5;
@@ -0,0 +1,509 @@
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_POLICY = "high-cost-v1";
52
+ const AutoAllocationSchema = z.object({
53
+ policyVersion: z.literal(AUTO_ALLOCATION_POLICY),
54
+ selectedModelId: z.string().min(1).max(512),
55
+ candidates: z.array(z.object({
56
+ modelId: z.string().min(1).max(512),
57
+ highCost: z.boolean(),
58
+ previous: z.boolean(),
59
+ weight: z.number().positive().max(1.5),
60
+ expectedShare: z.number().positive().max(1)
61
+ }).strict()).min(1).max(512)
62
+ }).strict().refine((value) => {
63
+ const total = value.candidates.reduce((sum, row) => sum + row.weight, 0);
64
+ return 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 === (row.highCost ? 2 : 10) * (row.previous ? 1.5 : 1) / 10 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
65
+ }, { message: "Invalid allocation policy evidence" });
66
+ function normalizeHighCostModelIds(value) {
67
+ try {
68
+ return normalizeExcludedModelIds(value);
69
+ } catch (cause) {
70
+ if (cause instanceof Error && cause.message === "COPILOT_MODEL_EXCLUSIONS_INVALID") throw new Error("COPILOT_HIGH_COST_MODELS_INVALID");
71
+ throw cause;
72
+ }
73
+ }
74
+ /** Integer policy units avoid cumulative decimal drift; avalanche sequential turn seeds. */
75
+ function allocateAutoModel(pool, highCostModelIds, previousModelId, seed) {
76
+ 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");
77
+ const marked = new Set(normalizeHighCostModelIds(highCostModelIds));
78
+ const rows = pool.map((model) => {
79
+ const highCost = marked.has(model.id);
80
+ const previous = model.id === previousModelId;
81
+ const units = (highCost ? 2 : 10) * (previous ? 1.5 : 1);
82
+ return {
83
+ modelId: model.id,
84
+ highCost,
85
+ previous,
86
+ units
87
+ };
88
+ });
89
+ const total = rows.reduce((sum, row) => sum + row.units, 0);
90
+ let hash = seed >>> 0;
91
+ hash = Math.imul(hash ^ hash >>> 16, 2246822507);
92
+ hash = Math.imul(hash ^ hash >>> 13, 3266489909);
93
+ const point = ((hash ^ hash >>> 16) >>> 0) / 4294967296 * total;
94
+ let boundary = 0;
95
+ const selected = rows.find((row) => {
96
+ boundary += row.units;
97
+ return point < boundary;
98
+ });
99
+ return Object.freeze({
100
+ policyVersion: AUTO_ALLOCATION_POLICY,
101
+ selectedModelId: selected.modelId,
102
+ candidates: Object.freeze(rows.map(({ units, ...row }) => Object.freeze({
103
+ ...row,
104
+ weight: units / 10,
105
+ expectedShare: units / total
106
+ })))
107
+ });
108
+ }
109
+ //#endregion
110
+ //#region lib/types/auto-allocation-diagnostics.js
111
+ const AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS = 1024;
112
+ const AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS = 12096e5;
113
+ const dayMs = 864e5;
114
+ const integer$1 = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
115
+ const version$1 = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
116
+ const allocationRow = z.object({
117
+ day: integer$1.multipleOf(dayMs),
118
+ version: version$1,
119
+ policyVersion: z.string().min(1).max(64),
120
+ modelId: z.string().min(1).max(512),
121
+ targetCategory: z.enum([
122
+ "powerful",
123
+ "versatile",
124
+ "lightweight"
125
+ ]),
126
+ category: z.enum([
127
+ "powerful",
128
+ "versatile",
129
+ "lightweight",
130
+ "unknown"
131
+ ]),
132
+ demand: z.enum([
133
+ "simple",
134
+ "routine",
135
+ "complex",
136
+ "unknown"
137
+ ]),
138
+ assessmentSource: z.enum(["local", "semantic"]),
139
+ method: z.enum(["weighted-distribution", "only-candidate"]),
140
+ fallback: z.boolean(),
141
+ highCost: z.boolean(),
142
+ previous: z.boolean(),
143
+ weight: z.number().positive().max(1.5),
144
+ opportunities: integer$1.min(1),
145
+ expectedSelections: z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER),
146
+ selections: integer$1
147
+ }).strict();
148
+ const noFitRow = z.object({
149
+ day: integer$1.multipleOf(dayMs),
150
+ version: version$1,
151
+ policyVersion: z.string().min(1).max(64),
152
+ targetCategory: z.enum([
153
+ "powerful",
154
+ "versatile",
155
+ "lightweight"
156
+ ]),
157
+ category: z.enum([
158
+ "powerful",
159
+ "versatile",
160
+ "lightweight",
161
+ "unknown"
162
+ ]),
163
+ demand: z.enum([
164
+ "simple",
165
+ "routine",
166
+ "complex",
167
+ "unknown"
168
+ ]),
169
+ assessmentSource: z.enum(["local", "semantic"]),
170
+ decisions: integer$1.min(1)
171
+ }).strict();
172
+ const AutoAllocationDiagnosticsSchema = z.object({
173
+ status: z.enum(["observed", "not-collected"]),
174
+ rows: z.array(allocationRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
175
+ noFitRows: z.array(noFitRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
176
+ observationStart: integer$1.nullable(),
177
+ observationEnd: integer$1.nullable(),
178
+ completeHistory: z.literal(false),
179
+ rowsTruncated: z.boolean(),
180
+ dropped: integer$1,
181
+ expired: integer$1,
182
+ saturated: integer$1,
183
+ restarts: integer$1
184
+ }).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");
185
+ function emptyAutoAllocationDiagnostics() {
186
+ return {
187
+ status: "not-collected",
188
+ rows: [],
189
+ noFitRows: [],
190
+ observationStart: null,
191
+ observationEnd: null,
192
+ completeHistory: false,
193
+ rowsTruncated: false,
194
+ dropped: 0,
195
+ expired: 0,
196
+ saturated: 0,
197
+ restarts: 0
198
+ };
199
+ }
200
+ /** Profile-local rolling aggregates; no per-turn, Session, prompt, or outcome records. */
201
+ var AutoAllocationDiagnosticsCollector = class {
202
+ version;
203
+ changed;
204
+ wall;
205
+ data = emptyAutoAllocationDiagnostics();
206
+ enabled = false;
207
+ constructor(version, changed = () => {}, wall = Date.now) {
208
+ this.version = version;
209
+ this.changed = changed;
210
+ this.wall = wall;
211
+ }
212
+ restore(value, countRestart = true) {
213
+ this.data = AutoAllocationDiagnosticsSchema.parse(value);
214
+ if (countRestart && this.data.status === "observed") {
215
+ this.data.restarts = this.add(this.data.restarts, 1);
216
+ this.expire();
217
+ this.changed();
218
+ }
219
+ }
220
+ setEnabled(enabled) {
221
+ this.enabled = enabled;
222
+ }
223
+ clear() {
224
+ this.data = emptyAutoAllocationDiagnostics();
225
+ this.changed();
226
+ }
227
+ record(explanation) {
228
+ if (!this.enabled) return;
229
+ const now = this.wall();
230
+ this.expire(now);
231
+ const day = Math.floor(now / dayMs) * dayMs;
232
+ this.data.observationStart = this.data.observationStart === null ? day : Math.min(this.data.observationStart, day);
233
+ this.data.observationEnd = this.data.observationEnd === null ? day : Math.max(this.data.observationEnd, day);
234
+ if (explanation.method === "no-fit") {
235
+ const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v1" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source);
236
+ if (row) row.decisions = this.add(row.decisions, 1);
237
+ else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.noFitRows.push({
238
+ day,
239
+ version: this.version,
240
+ policyVersion: AUTO_ALLOCATION_POLICY,
241
+ targetCategory: explanation.targetCategory,
242
+ category: explanation.selectedCategory,
243
+ demand: explanation.assessment.demand,
244
+ assessmentSource: explanation.assessment.source,
245
+ decisions: 1
246
+ });
247
+ else {
248
+ this.data.rowsTruncated = true;
249
+ this.data.dropped = this.add(this.data.dropped, 1);
250
+ }
251
+ this.data.status = "observed";
252
+ this.changed();
253
+ return;
254
+ }
255
+ if (explanation.method !== "weighted-distribution" && explanation.method !== "only-candidate") return;
256
+ const parsed = AutoAllocationSchema.safeParse(explanation.allocation);
257
+ if (!parsed.success || parsed.data.policyVersion !== "high-cost-v1") {
258
+ this.data.dropped = this.add(this.data.dropped, 1);
259
+ this.changed();
260
+ return;
261
+ }
262
+ const allocation = parsed.data;
263
+ for (const candidate of allocation.candidates) {
264
+ 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 === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
265
+ if (row) {
266
+ row.opportunities = this.add(row.opportunities, 1);
267
+ row.expectedSelections = Math.min(Number.MAX_SAFE_INTEGER, row.expectedSelections + candidate.expectedShare);
268
+ if (allocation.selectedModelId === candidate.modelId) row.selections = this.add(row.selections, 1);
269
+ } else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.rows.push({
270
+ day,
271
+ version: this.version,
272
+ policyVersion: allocation.policyVersion,
273
+ modelId: candidate.modelId,
274
+ targetCategory: explanation.targetCategory,
275
+ category: explanation.selectedCategory,
276
+ demand: explanation.assessment.demand,
277
+ assessmentSource: explanation.assessment.source,
278
+ method: explanation.method,
279
+ fallback: explanation.fallback,
280
+ highCost: candidate.highCost,
281
+ previous: candidate.previous,
282
+ weight: candidate.weight,
283
+ opportunities: 1,
284
+ expectedSelections: candidate.expectedShare,
285
+ selections: allocation.selectedModelId === candidate.modelId ? 1 : 0
286
+ });
287
+ else {
288
+ this.data.rowsTruncated = true;
289
+ this.data.dropped = this.add(this.data.dropped, 1);
290
+ }
291
+ }
292
+ this.data.status = "observed";
293
+ this.changed();
294
+ }
295
+ snapshot() {
296
+ this.expire();
297
+ return AutoAllocationDiagnosticsSchema.parse({
298
+ ...this.data,
299
+ rows: this.data.rows.map((row) => ({ ...row })),
300
+ noFitRows: this.data.noFitRows.map((row) => ({ ...row }))
301
+ });
302
+ }
303
+ expire(now = this.wall()) {
304
+ const oldest = Math.floor((now - AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS) / dayMs) * dayMs;
305
+ const rows = this.data.rows.filter((row) => row.day > oldest);
306
+ const noFitRows = this.data.noFitRows.filter((row) => row.day > oldest);
307
+ const removed = this.data.rows.length + this.data.noFitRows.length - rows.length - noFitRows.length;
308
+ if (removed > 0) {
309
+ this.data.rows = rows;
310
+ this.data.noFitRows = noFitRows;
311
+ this.data.expired = this.add(this.data.expired, removed);
312
+ const retainedDays = [...rows, ...noFitRows].map((row) => row.day);
313
+ this.data.observationStart = retainedDays.length ? Math.min(...retainedDays) : null;
314
+ this.data.observationEnd = retainedDays.length ? Math.max(...retainedDays) : null;
315
+ this.changed();
316
+ }
317
+ }
318
+ add(value, amount) {
319
+ if (value > Number.MAX_SAFE_INTEGER - amount) {
320
+ this.data.saturated = Math.min(Number.MAX_SAFE_INTEGER, this.data.saturated + 1);
321
+ return Number.MAX_SAFE_INTEGER;
322
+ }
323
+ return value + amount;
324
+ }
325
+ };
326
+ //#endregion
327
+ //#region lib/types/diagnostics-types.js
328
+ const DIAGNOSTICS_OPERATIONS = [
329
+ "account-global-switch",
330
+ "account-session-select",
331
+ "account-session-inherit",
332
+ "identity-read",
333
+ "identity-flight",
334
+ "compaction",
335
+ "compaction-summary",
336
+ "collection"
337
+ ];
338
+ const DIAGNOSTICS_STAGES = [
339
+ "admitted",
340
+ "rpc-invoked",
341
+ "host-received",
342
+ "identity-validation",
343
+ "model-validation",
344
+ "cas",
345
+ "readback",
346
+ "response-received",
347
+ "decoded",
348
+ "client-settled",
349
+ "summary-attempt",
350
+ "checkpoint-committed",
351
+ "ended",
352
+ "cache-hit",
353
+ "joined-flight",
354
+ "cooldown",
355
+ "dispatched"
356
+ ];
357
+ const DIAGNOSTICS_METRICS = [
358
+ "started",
359
+ "stage",
360
+ "success",
361
+ "no-op",
362
+ "cancelled",
363
+ "policy-rejected",
364
+ "revoked",
365
+ "environment-fault",
366
+ "failed",
367
+ "unknown",
368
+ "interrupted",
369
+ "dropped",
370
+ "paused",
371
+ "expired",
372
+ "clock-discontinuity",
373
+ "pending-sample"
374
+ ];
375
+ const DIAGNOSTICS_REASONS = [
376
+ "none",
377
+ "unknown",
378
+ "rpc-unavailable",
379
+ "decode-invalid",
380
+ "COPILOT_ACCOUNTS_BUSY",
381
+ "COPILOT_ACCOUNTS_CONFLICT",
382
+ "COPILOT_ACCOUNTS_CHANGED",
383
+ "COPILOT_ACCOUNTS_COMMIT_UNCERTAIN",
384
+ "COPILOT_ACCOUNTS_IDENTITY_TIMEOUT",
385
+ "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE",
386
+ "COPILOT_ACCOUNTS_MODELS_FAILED",
387
+ "COPILOT_ACCOUNTS_SETTINGS_UNAVAILABLE",
388
+ "COPILOT_ACCOUNTS_IDENTITY_TLS",
389
+ "COPILOT_ACCOUNTS_IDENTITY_NETWORK",
390
+ "COPILOT_ACCOUNTS_IDENTITY_RATE_LIMITED",
391
+ "COPILOT_ACCOUNTS_IDENTITY_AUTH_REJECTED",
392
+ "COPILOT_ACCOUNTS_IDENTITY_HTTP_ERROR",
393
+ "COPILOT_ACCOUNTS_IDENTITY_INVALID",
394
+ "COPILOT_SESSION_ACCOUNTS_UNAVAILABLE",
395
+ "COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE",
396
+ "COPILOT_SESSION_ACCOUNTS_COMMIT_UNCERTAIN",
397
+ "COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH",
398
+ "CONTEXT_WINDOW_EXCEEDED",
399
+ "COPILOT_MANUAL_RECOVERY_FIXED_PREFIX",
400
+ "COPILOT_MANUAL_RECOVERY_INDIVISIBLE",
401
+ "COPILOT_MANUAL_RECOVERY_CALL_LIMIT",
402
+ "COPILOT_MANUAL_RECOVERY_EMPTY_SUMMARY",
403
+ "COPILOT_MANUAL_RECOVERY_UNBALANCED"
404
+ ];
405
+ const DIAGNOSTICS_MAX_ROWS = 4096;
406
+ const DIAGNOSTICS_MAX_BYTES = 2097152;
407
+ const DIAGNOSTICS_RETENTION_MS = 12096e5;
408
+ const integer = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
409
+ const version = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
410
+ const DiagnosticsRowSchema = z.object({
411
+ hour: integer.multipleOf(36e5),
412
+ version,
413
+ layer: z.enum(["client", "host"]),
414
+ operation: z.enum(DIAGNOSTICS_OPERATIONS),
415
+ stage: z.enum(DIAGNOSTICS_STAGES),
416
+ metric: z.enum(DIAGNOSTICS_METRICS),
417
+ reason: z.enum(DIAGNOSTICS_REASONS),
418
+ bucket: z.number().int().min(0).max(7),
419
+ count: integer.min(1)
420
+ }).strict();
421
+ const DiagnosticsPendingSchema = z.object({
422
+ version,
423
+ operation: z.enum(DIAGNOSTICS_OPERATIONS),
424
+ stage: z.enum(DIAGNOSTICS_STAGES),
425
+ bucket: z.number().int().min(0).max(7),
426
+ count: integer.min(1).max(128)
427
+ }).strict();
428
+ const DiagnosticsSnapshotSchema = z.object({
429
+ schemaVersion: z.literal(1),
430
+ coverageVersion: z.literal(1),
431
+ epoch: integer,
432
+ updatedAt: integer,
433
+ rows: z.array(DiagnosticsRowSchema).max(DIAGNOSTICS_MAX_ROWS),
434
+ autoAllocation: AutoAllocationDiagnosticsSchema.optional(),
435
+ pending: z.array(DiagnosticsPendingSchema).max(128),
436
+ dropped: integer,
437
+ clientDropped: integer,
438
+ clientUnconfirmed: integer,
439
+ saturated: integer,
440
+ evicted: integer,
441
+ interrupted: integer
442
+ }).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");
443
+ const DiagnosticsViewSchema = z.object({
444
+ enabled: z.boolean(),
445
+ autoAllocationEnabled: z.boolean(),
446
+ state: z.enum([
447
+ "loading",
448
+ "ready",
449
+ "unavailable",
450
+ "error"
451
+ ]),
452
+ diagnostic: z.enum([
453
+ "none",
454
+ "storage-unavailable",
455
+ "storage-invalid",
456
+ "storage-write-failed",
457
+ "profile-unavailable",
458
+ "settings-unavailable",
459
+ "settings-conflict",
460
+ "client-report-failed",
461
+ "client-report-revoked",
462
+ "closed"
463
+ ]),
464
+ persistedAt: integer.optional(),
465
+ dirty: z.boolean(),
466
+ snapshot: DiagnosticsSnapshotSchema
467
+ }).strict();
468
+ function diagnosticsBucket(ms) {
469
+ return [
470
+ 100,
471
+ 500,
472
+ 1e3,
473
+ 5e3,
474
+ 15e3,
475
+ 6e4,
476
+ 3e5
477
+ ].findIndex((bound) => ms < bound) === -1 ? 7 : [
478
+ 100,
479
+ 500,
480
+ 1e3,
481
+ 5e3,
482
+ 15e3,
483
+ 6e4,
484
+ 3e5
485
+ ].findIndex((bound) => ms < bound);
486
+ }
487
+ function diagnosticsReason(error) {
488
+ const seen = /* @__PURE__ */ new Set();
489
+ for (let depth = 0; depth < 8 && error instanceof Error && !seen.has(error); depth++) {
490
+ seen.add(error);
491
+ const nativeCode = "code" in error ? error.code : void 0;
492
+ const typed = DIAGNOSTICS_REASONS.find((code) => code !== "none" && code !== "unknown" && code === nativeCode);
493
+ if (typed !== void 0) return typed;
494
+ const message = error.message.slice(0, 4096);
495
+ for (const code of DIAGNOSTICS_REASONS) if (code.startsWith("COPILOT_") || code === "CONTEXT_WINDOW_EXCEEDED") {
496
+ if (new RegExp(`(?:^|[^A-Za-z0-9_])${code}(?:$|[^A-Za-z0-9_])`).test(message)) return code;
497
+ }
498
+ error = error.cause;
499
+ }
500
+ return "unknown";
501
+ }
502
+ function diagnosticsOutcome(reason) {
503
+ if (reason === "COPILOT_ACCOUNTS_BUSY" || reason === "COPILOT_ACCOUNTS_CONFLICT") return "policy-rejected";
504
+ if (reason === "COPILOT_ACCOUNTS_CHANGED") return "revoked";
505
+ if (reason.endsWith("SETTINGS_UNAVAILABLE") || reason === "COPILOT_SESSION_ACCOUNTS_UNAVAILABLE") return "environment-fault";
506
+ return "failed";
507
+ }
508
+ //#endregion
509
+ export { normalizeHighCostModelIds as _, DiagnosticsPendingSchema as a, normalizeExcludedModelIds as b, DiagnosticsViewSchema as c, diagnosticsReason as d, AutoAllocationDiagnosticsCollector as f, allocateAutoModel as g, AutoAllocationSchema as h, DIAGNOSTICS_RETENTION_MS as i, diagnosticsBucket as l, AUTO_ALLOCATION_POLICY as m, DIAGNOSTICS_OPERATIONS as n, DiagnosticsRowSchema as o, emptyAutoAllocationDiagnostics as p, DIAGNOSTICS_REASONS as r, DiagnosticsSnapshotSchema as s, DIAGNOSTICS_MAX_ROWS as t, diagnosticsOutcome as u, ModelExclusionTurns as v, excludedModelSet as y };