dsh-github-copilot 0.4.0-alpha.81 → 0.4.0-alpha.82

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/lib/client.js CHANGED
@@ -5968,14 +5968,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5968
5968
  const CHAT_NODE_SLOT = "conversation.chat.node";
5969
5969
  const ASSISTANT_KEY = "assistant-step";
5970
5970
  const noop$3 = () => {};
5971
- function record$5(value) {
5971
+ function record$6(value) {
5972
5972
  return typeof value === "object" && value !== null;
5973
5973
  }
5974
5974
  function sequence$1(value) {
5975
5975
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
5976
5976
  }
5977
5977
  function eventLocation(event) {
5978
- if (!record$5(event) || !record$5(event.data)) return void 0;
5978
+ if (!record$6(event) || !record$6(event.data)) return void 0;
5979
5979
  const { turn, step } = event.data;
5980
5980
  return sequence$1(turn) && sequence$1(step) ? {
5981
5981
  turn,
@@ -5983,9 +5983,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5983
5983
  } : void 0;
5984
5984
  }
5985
5985
  function messageOrigin(event) {
5986
- if (!record$5(event) || event.type !== "assistant/message" || event.surfaceOp !== "append" || !sequence$1(event.seq) || !record$5(event.data) || !record$5(event.data.message)) return void 0;
5986
+ if (!record$6(event) || event.type !== "assistant/message" || event.surfaceOp !== "append" || !sequence$1(event.seq) || !record$6(event.data) || !record$6(event.data.message)) return void 0;
5987
5987
  const source = event.data.message.source;
5988
- if (!record$5(source) || typeof source.provider !== "string" || source.provider.trim() === "" || typeof source.model !== "string" || source.model.trim() === "") return void 0;
5988
+ if (!record$6(source) || typeof source.provider !== "string" || source.provider.trim() === "" || typeof source.model !== "string" || source.model.trim() === "") return void 0;
5989
5989
  return {
5990
5990
  seq: event.seq,
5991
5991
  provider: source.provider,
@@ -5996,7 +5996,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5996
5996
  const assistantOriginDefinition = {
5997
5997
  kind: ASSISTANT_ORIGIN_KEY,
5998
5998
  match(event) {
5999
- if (!record$5(event)) return null;
5999
+ if (!record$6(event)) return null;
6000
6000
  const location = eventLocation(event);
6001
6001
  if (location === void 0) return null;
6002
6002
  if (event.type === "step/start") return {
@@ -6011,14 +6011,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6011
6011
  },
6012
6012
  start(_context, match) {
6013
6013
  const location = eventLocation(match.event);
6014
- if (location === void 0 || !record$5(match.event) || match.event.type !== "step/start") throw new Error("COPILOT_REASONING_ORIGIN_START: expected step/start");
6014
+ if (location === void 0 || !record$6(match.event) || match.event.type !== "step/start") throw new Error("COPILOT_REASONING_ORIGIN_START: expected step/start");
6015
6015
  return {
6016
6016
  ...location,
6017
6017
  origin: void 0
6018
6018
  };
6019
6019
  },
6020
6020
  update(context, match) {
6021
- if (!record$5(match.event) || match.event.type !== "assistant/message" || match.event.surfaceOp !== "append") return context.state;
6021
+ if (!record$6(match.event) || match.event.type !== "assistant/message" || match.event.surfaceOp !== "append") return context.state;
6022
6022
  return {
6023
6023
  ...context.state,
6024
6024
  origin: messageOrigin(match.event)
@@ -6029,7 +6029,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6029
6029
  let state = context.state;
6030
6030
  if (state === void 0) for (const match of context.matches) {
6031
6031
  const event = match.event;
6032
- if (!record$5(event) || event.type !== "assistant/message" || event.surfaceOp !== "append") continue;
6032
+ if (!record$6(event) || event.type !== "assistant/message" || event.surfaceOp !== "append") continue;
6033
6033
  const location = eventLocation(event);
6034
6034
  if (location !== void 0) state = {
6035
6035
  ...location,
@@ -6050,12 +6050,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6050
6050
  };
6051
6051
  /** Shallow UI-only projection. Unchanged input retains its exact props identity. */
6052
6052
  function projectReasoningPresentation(props, origin) {
6053
- if (!record$5(props) || !record$5(props.node) || props.node.kind !== ASSISTANT_KEY || !record$5(props.node.data) || !record$5(origin)) return props;
6053
+ if (!record$6(props) || !record$6(props.node) || props.node.kind !== ASSISTANT_KEY || !record$6(props.node.data) || !record$6(origin)) return props;
6054
6054
  const node = props.node;
6055
6055
  const data = node.data;
6056
- if (data.status !== "settled" || !record$5(data.finalNode) || !sequence$1(data.finalNode.seq) || origin.seq !== data.finalNode.seq) return props;
6056
+ if (data.status !== "settled" || !record$6(data.finalNode) || !sequence$1(data.finalNode.seq) || origin.seq !== data.finalNode.seq) return props;
6057
6057
  if (!(origin.provider === "github-copilot" || origin.provider === "github-copilot-preview") || typeof origin.model !== "string" || origin.model.trim() === "" || !Array.isArray(data.blocks)) return props;
6058
- const blocks = data.blocks.filter((block) => !(record$5(block) && block.kind === "reasoning" && typeof block.text === "string" && block.text.trim() === ""));
6058
+ const blocks = data.blocks.filter((block) => !(record$6(block) && block.kind === "reasoning" && typeof block.text === "string" && block.text.trim() === ""));
6059
6059
  if (blocks.length === data.blocks.length) return props;
6060
6060
  return {
6061
6061
  ...props,
@@ -6074,12 +6074,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6074
6074
  };
6075
6075
  function originSource(props) {
6076
6076
  const node = props.node;
6077
- if (!record$5(node) || !record$5(node.location) || node.location.kind !== "step" || !record$5(node.location.step) || !record$5(node.location.step.data)) return missingOriginSource;
6077
+ if (!record$6(node) || !record$6(node.location) || node.location.kind !== "step" || !record$6(node.location.step) || !record$6(node.location.step.data)) return missingOriginSource;
6078
6078
  const store = node.location.step.data;
6079
6079
  if (typeof store.source !== "function") return missingOriginSource;
6080
6080
  try {
6081
6081
  const source = store.source(ASSISTANT_ORIGIN_KEY);
6082
- if (!record$5(source) || typeof source.getSnapshot !== "function" || typeof source.subscribe !== "function") return missingOriginSource;
6082
+ if (!record$6(source) || typeof source.getSnapshot !== "function" || typeof source.subscribe !== "function") return missingOriginSource;
6083
6083
  return source;
6084
6084
  } catch {
6085
6085
  return missingOriginSource;
@@ -6093,7 +6093,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6093
6093
  */
6094
6094
  function supportedNative(entry) {
6095
6095
  const component = entry.component;
6096
- return (entry.options.priority ?? 0) === 0 && entry.locale === "chat" && entry.options.id === void 0 && entry.options.order === void 0 && entry.options.label === void 0 && entry.inject === void 0 && entry.store === void 0 && entry.children === void 0 && entry.select === void 0 && record$5(component) && component.$$typeof === Symbol.for("react.memo") && typeof component.type === "function" && component.type.name === "AssistantNodeView";
6096
+ return (entry.options.priority ?? 0) === 0 && entry.locale === "chat" && entry.options.id === void 0 && entry.options.order === void 0 && entry.options.label === void 0 && entry.inject === void 0 && entry.store === void 0 && entry.children === void 0 && entry.select === void 0 && record$6(component) && component.$$typeof === Symbol.for("react.memo") && typeof component.type === "function" && component.type.name === "AssistantNodeView";
6097
6097
  }
6098
6098
  /**
6099
6099
  * Optional Client enhancement. The caller owns the returned disposer in its
@@ -6103,13 +6103,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6103
6103
  const { diagnostic } = capabilities;
6104
6104
  const slotsCandidate = capabilities.slots;
6105
6105
  const conversation = capabilities.uiConversation;
6106
- if (!record$5(slotsCandidate) || ![
6106
+ if (!record$6(slotsCandidate) || ![
6107
6107
  "entries",
6108
6108
  "spec",
6109
6109
  "subscribe",
6110
6110
  "inject",
6111
6111
  "register"
6112
- ].every((key) => typeof slotsCandidate[key] === "function") || !record$5(conversation) || !record$5(conversation.events) || typeof conversation.events.register !== "function") {
6112
+ ].every((key) => typeof slotsCandidate[key] === "function") || !record$6(conversation) || !record$6(conversation.events) || typeof conversation.events.register !== "function") {
6113
6113
  diagnostic("COPILOT_REASONING_PRESENTATION_UNAVAILABLE");
6114
6114
  return noop$3;
6115
6115
  }
@@ -6214,14 +6214,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6214
6214
  //#endregion
6215
6215
  //#region lib/types/turn-model-provenance.js
6216
6216
  const TURN_MODEL_PROVENANCE_KEY = "github-copilot-turn-model-provenance";
6217
- function record$4(value) {
6217
+ function record$5(value) {
6218
6218
  return typeof value === "object" && value !== null;
6219
6219
  }
6220
6220
  function isTurnModelProvenance(value) {
6221
- return record$4(value) && typeof value.ended === "boolean" && typeof value.incomplete === "boolean" && Array.isArray(value.routes) && value.routes.every((route) => record$4(route) && typeof route.provider === "string" && route.provider.trim() !== "" && typeof route.model === "string" && route.model.trim() !== "");
6221
+ return record$5(value) && typeof value.ended === "boolean" && typeof value.incomplete === "boolean" && Array.isArray(value.routes) && value.routes.every((route) => record$5(route) && typeof route.provider === "string" && route.provider.trim() !== "" && typeof route.model === "string" && route.model.trim() !== "");
6222
6222
  }
6223
- function coordinates(event) {
6224
- if (!record$4(event) || typeof event.type !== "string" || !record$4(event.data) || !Number.isSafeInteger(event.data.turn) || typeof event.data.turn !== "number" || event.data.turn < 0 || ![
6223
+ function coordinates$1(event) {
6224
+ if (!record$5(event) || typeof event.type !== "string" || !record$5(event.data) || !Number.isSafeInteger(event.data.turn) || typeof event.data.turn !== "number" || event.data.turn < 0 || ![
6225
6225
  "turn/start",
6226
6226
  "turn/end",
6227
6227
  "step/start",
@@ -6237,8 +6237,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6237
6237
  data: event.data
6238
6238
  };
6239
6239
  }
6240
- function fold(state, event) {
6241
- const parsed = coordinates(event);
6240
+ function fold$1(state, event) {
6241
+ const parsed = coordinates$1(event);
6242
6242
  if (parsed === void 0 || state !== void 0 && state.turn !== parsed.turn) return state;
6243
6243
  const hasStart = state?.hasStart === true || parsed.type === "turn/start";
6244
6244
  const routes = state?.value.routes ?? [];
@@ -6254,8 +6254,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6254
6254
  let missing = false;
6255
6255
  let route;
6256
6256
  if (parsed.type === "assistant/message") {
6257
- const source = record$4(parsed.data.message) ? parsed.data.message.source : void 0;
6258
- if (record$4(source) && typeof source.provider === "string" && source.provider.trim() !== "" && typeof source.model === "string" && source.model.trim() !== "") route = {
6257
+ const source = record$5(parsed.data.message) ? parsed.data.message.source : void 0;
6258
+ if (record$5(source) && typeof source.provider === "string" && source.provider.trim() !== "" && typeof source.model === "string" && source.model.trim() !== "") route = {
6259
6259
  provider: source.provider,
6260
6260
  model: source.model
6261
6261
  };
@@ -6276,23 +6276,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6276
6276
  const turnModelProvenanceDefinition = {
6277
6277
  kind: TURN_MODEL_PROVENANCE_KEY,
6278
6278
  match(event) {
6279
- const parsed = coordinates(event);
6279
+ const parsed = coordinates$1(event);
6280
6280
  return parsed ? {
6281
6281
  id: String(parsed.turn),
6282
6282
  role: parsed.type === "turn/start" ? "start" : "update"
6283
6283
  } : null;
6284
6284
  },
6285
6285
  start(_context, match) {
6286
- const state = fold(void 0, match.event);
6286
+ const state = fold$1(void 0, match.event);
6287
6287
  if (!state) throw new Error("COPILOT_MODEL_PROVENANCE_START");
6288
6288
  return state;
6289
6289
  },
6290
6290
  update(context, match) {
6291
- return fold(context.state, match.event) ?? context.state;
6291
+ return fold$1(context.state, match.event) ?? context.state;
6292
6292
  },
6293
6293
  buildLocationData(context, scope, previous) {
6294
6294
  if (scope !== "turn") return null;
6295
- const state = context.state ?? context.matches.reduce((state, match) => fold(state, match.event), void 0);
6295
+ const state = context.state ?? context.matches.reduce((state, match) => fold$1(state, match.event), void 0);
6296
6296
  if (!state) return null;
6297
6297
  const value = {
6298
6298
  ...state.value,
@@ -6481,6 +6481,231 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6481
6481
  }, zh ? "关闭" : "Close")) : null);
6482
6482
  }
6483
6483
  //#endregion
6484
+ //#region lib/types/turn-usage-evidence.js
6485
+ const TURN_USAGE_EVIDENCE_KEY = "github-copilot-turn-usage-evidence";
6486
+ function record$4(value) {
6487
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6488
+ }
6489
+ function count$1(value) {
6490
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
6491
+ }
6492
+ function isTurnUsageEvidence(value) {
6493
+ return record$4(value) && typeof value.ended === "boolean" && typeof value.hasStart === "boolean" && count$1(value.localPreDispatchBlocks) && count$1(value.unreportedAttempts);
6494
+ }
6495
+ function coordinates(event) {
6496
+ if (!record$4(event) || typeof event.type !== "string" || !record$4(event.data) || !count$1(event.data.turn) || ![
6497
+ "turn/start",
6498
+ "turn/end",
6499
+ "assistant/message",
6500
+ "assistant/attempt"
6501
+ ].includes(event.type)) return void 0;
6502
+ if (event.type === "assistant/message" && event.surfaceOp !== "append") return void 0;
6503
+ return {
6504
+ turn: event.data.turn,
6505
+ type: event.type,
6506
+ data: event.data
6507
+ };
6508
+ }
6509
+ function unreported(type, data) {
6510
+ if (type === "assistant/message" && data.usage !== void 0) return false;
6511
+ return !Array.isArray(data.stream) || !data.stream.some((entry) => record$4(entry) && entry.type === "chunk" && record$4(entry.chunk) && entry.chunk.type === "usage" && entry.chunk.usage !== void 0);
6512
+ }
6513
+ /** Recognize only our recorded finish-only diagnostic; never infer dispatch from a generic error. */
6514
+ function localBlock(data) {
6515
+ if (!Array.isArray(data.stream) || data.stream.length !== 1) return false;
6516
+ const entry = data.stream[0];
6517
+ if (!record$4(entry) || entry.type !== "chunk" || !record$4(entry.chunk) || entry.chunk.type !== "finish" || !record$4(entry.chunk.reason) || entry.chunk.reason.kind !== "error" || !record$4(entry.chunk.reason.failure)) return false;
6518
+ const failure = entry.chunk.reason.failure;
6519
+ if (failure.code !== "CONTEXT_WINDOW_EXCEEDED" || typeof failure.message !== "string" || failure.message.length > 256) return false;
6520
+ const match = /^Copilot local estimated input budget exceeded \((\d+) estimated tokens > (\d+) budget tokens\); requesting stock compaction before provider dispatch\.$/.exec(failure.message);
6521
+ if (!match) return false;
6522
+ const estimate = Number(match[1]), budget = Number(match[2]);
6523
+ return count$1(estimate) && count$1(budget) && budget > 0 && estimate > budget;
6524
+ }
6525
+ function fold(state, event) {
6526
+ const parsed = coordinates(event);
6527
+ if (!parsed || state !== void 0 && state.turn !== parsed.turn) return state;
6528
+ const value = state?.value ?? {
6529
+ ended: false,
6530
+ hasStart: false,
6531
+ localPreDispatchBlocks: 0,
6532
+ unreportedAttempts: 0
6533
+ };
6534
+ const missing = (parsed.type === "assistant/message" || parsed.type === "assistant/attempt") && unreported(parsed.type, parsed.data);
6535
+ const local = missing && parsed.type === "assistant/attempt" && localBlock(parsed.data);
6536
+ return {
6537
+ turn: parsed.turn,
6538
+ value: {
6539
+ ended: value.ended || parsed.type === "turn/end",
6540
+ hasStart: value.hasStart || parsed.type === "turn/start",
6541
+ localPreDispatchBlocks: Math.min(Number.MAX_SAFE_INTEGER, value.localPreDispatchBlocks + (local ? 1 : 0)),
6542
+ unreportedAttempts: Math.min(Number.MAX_SAFE_INTEGER, value.unreportedAttempts + (missing && !local ? 1 : 0))
6543
+ }
6544
+ };
6545
+ }
6546
+ /** Native completed-tail evidence gates the notice; native totals are never replaced. */
6547
+ function turnUsageDiagnostic(turn, tail, evidence, copilot) {
6548
+ if (!count$1(turn) || !record$4(tail) || tail.turn !== turn || !count$1(tail.seq) || tail.tokenUsage !== void 0) return void 0;
6549
+ const parsed = isTurnUsageEvidence(evidence) && evidence.ended ? evidence : void 0;
6550
+ if (!copilot && (parsed?.localPreDispatchBlocks ?? 0) === 0) return void 0;
6551
+ return {
6552
+ localPreDispatchBlocks: parsed?.localPreDispatchBlocks ?? 0,
6553
+ unreportedAttempts: parsed?.unreportedAttempts ?? 0,
6554
+ incompleteHistory: parsed?.hasStart !== true
6555
+ };
6556
+ }
6557
+ /** Diagnostic event counts only, not a competing usage total or billing projection. */
6558
+ const turnUsageEvidenceDefinition = {
6559
+ kind: TURN_USAGE_EVIDENCE_KEY,
6560
+ match(event) {
6561
+ const parsed = coordinates(event);
6562
+ return parsed ? {
6563
+ id: String(parsed.turn),
6564
+ role: parsed.type === "turn/start" ? "start" : "update"
6565
+ } : null;
6566
+ },
6567
+ start(_context, match) {
6568
+ const state = fold(void 0, match.event);
6569
+ if (!state) throw new Error("COPILOT_TURN_USAGE_EVIDENCE_START");
6570
+ return state;
6571
+ },
6572
+ update(context, match) {
6573
+ return fold(context.state, match.event) ?? context.state;
6574
+ },
6575
+ buildLocationData(context, scope, previous) {
6576
+ if (scope !== "turn") return null;
6577
+ const state = context.state ?? context.matches.reduce((state, match) => fold(state, match.event), void 0);
6578
+ if (!state) return null;
6579
+ const value = state.value;
6580
+ if (previous?.turn === state.turn && previous.value.ended === value.ended && previous.value.hasStart === value.hasStart && previous.value.localPreDispatchBlocks === value.localPreDispatchBlocks && previous.value.unreportedAttempts === value.unreportedAttempts) return previous;
6581
+ return {
6582
+ kind: "turn",
6583
+ turn: state.turn,
6584
+ key: TURN_USAGE_EVIDENCE_KEY,
6585
+ value
6586
+ };
6587
+ }
6588
+ };
6589
+ //#endregion
6590
+ //#region lib/types/turn-usage-notice.js
6591
+ function TurnUsageNotice({ diagnostic, locale = "en" }) {
6592
+ const zh = locale.startsWith("zh");
6593
+ const id = (0, react.useId)();
6594
+ const [open, setOpen] = (0, react.useState)(false);
6595
+ const [position, setPosition] = (0, react.useState)({
6596
+ left: 12,
6597
+ top: 12
6598
+ });
6599
+ const trigger = (0, react.useRef)(null);
6600
+ const panel = (0, react.useRef)(null);
6601
+ const close = (0, react.useRef)(null);
6602
+ const label = zh ? "本轮 Usage 不可用" : "Turn Usage unavailable";
6603
+ (0, react.useLayoutEffect)(() => {
6604
+ if (!open) return;
6605
+ panel.current?.showPopover?.();
6606
+ const place = () => {
6607
+ const a = trigger.current?.getBoundingClientRect(), b = panel.current?.getBoundingClientRect();
6608
+ if (a && b) setPosition({
6609
+ left: Math.max(12, Math.min(a.left, innerWidth - b.width - 12)),
6610
+ top: Math.max(12, Math.min(a.top - b.height - 8, innerHeight - b.height - 12))
6611
+ });
6612
+ };
6613
+ place();
6614
+ close.current?.focus();
6615
+ window.addEventListener("resize", place);
6616
+ window.addEventListener("scroll", place, true);
6617
+ return () => {
6618
+ window.removeEventListener("resize", place);
6619
+ window.removeEventListener("scroll", place, true);
6620
+ };
6621
+ }, [open]);
6622
+ (0, react.useEffect)(() => {
6623
+ if (!open) return;
6624
+ const outside = (event) => {
6625
+ if (event.target instanceof Node && !panel.current?.contains(event.target) && !trigger.current?.contains(event.target)) setOpen(false);
6626
+ };
6627
+ const key = (event) => {
6628
+ if (event.key === "Escape") {
6629
+ event.preventDefault();
6630
+ setOpen(false);
6631
+ trigger.current?.focus();
6632
+ }
6633
+ };
6634
+ document.addEventListener("pointerdown", outside);
6635
+ document.addEventListener("focusin", outside);
6636
+ document.addEventListener("keydown", key);
6637
+ return () => {
6638
+ document.removeEventListener("pointerdown", outside);
6639
+ document.removeEventListener("focusin", outside);
6640
+ document.removeEventListener("keydown", key);
6641
+ };
6642
+ }, [open]);
6643
+ const button = {
6644
+ font: "inherit",
6645
+ color: "inherit",
6646
+ background: "transparent",
6647
+ border: "1px solid var(--dsw-alias-border-main, GrayText)",
6648
+ borderRadius: 6,
6649
+ cursor: "pointer"
6650
+ };
6651
+ return (0, react.createElement)("span", { style: {
6652
+ order: 2,
6653
+ display: "inline-flex",
6654
+ minWidth: 0,
6655
+ maxWidth: "100%",
6656
+ fontSize: "var(--dsh-content-font-size-secondary, 13px)",
6657
+ color: "var(--dsw-alias-label-tertiary, GrayText)"
6658
+ } }, (0, react.createElement)("button", {
6659
+ ref: trigger,
6660
+ type: "button",
6661
+ style: {
6662
+ ...button,
6663
+ minWidth: 0,
6664
+ overflow: "hidden",
6665
+ textOverflow: "ellipsis",
6666
+ whiteSpace: "nowrap"
6667
+ },
6668
+ title: label,
6669
+ "aria-expanded": open,
6670
+ "aria-controls": open ? id : void 0,
6671
+ "aria-haspopup": "dialog",
6672
+ onClick: () => setOpen((value) => !value)
6673
+ }, label), open ? (0, react.createElement)("div", {
6674
+ ref: panel,
6675
+ id,
6676
+ popover: "manual",
6677
+ role: "dialog",
6678
+ "aria-label": label,
6679
+ style: {
6680
+ position: "fixed",
6681
+ inset: "auto",
6682
+ ...position,
6683
+ margin: 0,
6684
+ zIndex: 1e3,
6685
+ width: 340,
6686
+ maxWidth: "calc(100vw - 24px)",
6687
+ maxHeight: `calc(100dvh - ${position.top + 12}px)`,
6688
+ boxSizing: "border-box",
6689
+ overflowY: "auto",
6690
+ overflowWrap: "anywhere",
6691
+ padding: 16,
6692
+ borderRadius: 12,
6693
+ border: button.border,
6694
+ background: "var(--dsw-alias-bg-layer-2, Canvas)",
6695
+ color: "var(--dsw-alias-label-primary, CanvasText)",
6696
+ lineHeight: 1.6
6697
+ }
6698
+ }, (0, react.createElement)("strong", null, label), (0, react.createElement)("p", null, zh ? "原生统计无法证明本轮所有尝试的完整总量。部分步骤有用量,不代表整轮总量已知。" : "Native accounting cannot prove a complete total for every attempt in this turn. Reported usage on some steps is not a complete turn total."), diagnostic.localPreDispatchBlocks > 0 ? (0, react.createElement)("p", null, zh ? `记录中有 ${diagnostic.localPreDispatchBlocks} 次插件发出前的本地输入预算拦截,未记录供应商用量。后续压缩恢复不会补齐这些尝试的用量。` : `The history records ${diagnostic.localPreDispatchBlocks} local input-budget ${diagnostic.localPreDispatchBlocks === 1 ? "block" : "blocks"} before provider dispatch, with no reported provider usage. Subsequent compaction recovery does not fill in those attempts' usage.`) : null, diagnostic.unreportedAttempts > 0 ? (0, react.createElement)("p", null, zh ? `另有 ${diagnostic.unreportedAttempts} 次完成或失败记录未带用量样本;不能据此判断请求是否发出或计费。` : `${diagnostic.unreportedAttempts} other ${diagnostic.unreportedAttempts === 1 ? "settlement has" : "settlements have"} no reported usage sample; this does not establish whether a request was sent or billed.`) : null, diagnostic.incompleteHistory ? (0, react.createElement)("p", null, zh ? "本页未保留完整轮次证据;以上记录可能不完整。" : "Complete turn evidence is not retained on this page; these records may be incomplete.") : null, diagnostic.localPreDispatchBlocks === 0 && diagnostic.unreportedAttempts === 0 ? (0, react.createElement)("p", null, zh ? "现有证据无法确定原因;缺失的生命周期或无效用量也会使原生统计不可用。" : "The available evidence does not identify a cause; missing lifecycle boundaries or invalid usage can also make native accounting unavailable.") : null, (0, react.createElement)("p", null, zh ? "这是只读说明,不是零用量、部分合计或当前上下文占用。原生 Usage、用量记录与压缩恢复均保持不变。" : "This read-only explanation is not zero usage, a partial total or current context occupancy. Native Usage, usage records and compaction recovery remain unchanged."), (0, react.createElement)("button", {
6699
+ ref: close,
6700
+ type: "button",
6701
+ style: button,
6702
+ onClick: () => {
6703
+ setOpen(false);
6704
+ trigger.current?.focus();
6705
+ }
6706
+ }, zh ? "关闭" : "Close")) : null);
6707
+ }
6708
+ //#endregion
6484
6709
  //#region lib/types/auto-model-presentation.js
6485
6710
  const AUTO_MODEL_ATTRIBUTION_KEY = "github-copilot-auto-model-attribution";
6486
6711
  const SLOT = "conversation.chat.assistant-actions";
@@ -6556,14 +6781,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6556
6781
  getSnapshot: () => void 0,
6557
6782
  subscribe: () => noop$2
6558
6783
  };
6559
- function sourceOf(props, key, diagnostic) {
6784
+ function sourceOf(props, key, diagnostic, failure = "COPILOT_TURN_SELECTION_PROJECTION_FAILED") {
6560
6785
  const turn = props.turn;
6561
6786
  if (!record$3(turn) || !record$3(turn.data) || typeof turn.data.source !== "function") return missingSource;
6562
6787
  try {
6563
6788
  const source = turn.data.source(key);
6564
6789
  return record$3(source) && typeof source.getSnapshot === "function" && typeof source.subscribe === "function" ? source : missingSource;
6565
6790
  } catch {
6566
- diagnostic("COPILOT_TURN_SELECTION_PROJECTION_FAILED");
6791
+ diagnostic(failure);
6567
6792
  return missingSource;
6568
6793
  }
6569
6794
  }
@@ -6632,6 +6857,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6632
6857
  const value = react.useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
6633
6858
  const provenanceSource = sourceOf(props, TURN_MODEL_PROVENANCE_KEY, props.diagnostic);
6634
6859
  const provenance = react.useSyncExternalStore(provenanceSource.subscribe, provenanceSource.getSnapshot, provenanceSource.getSnapshot);
6860
+ const usageSource = sourceOf(props, TURN_USAGE_EVIDENCE_KEY, props.diagnostic, "COPILOT_TURN_USAGE_PROJECTION_FAILED");
6861
+ const usageEvidence = react.useSyncExternalStore(usageSource.subscribe, usageSource.getSnapshot, usageSource.getSnapshot);
6635
6862
  const parsed = attribution({
6636
6863
  type: "github-copilot/auto-model-decision",
6637
6864
  data: {
@@ -6645,7 +6872,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6645
6872
  if (evidence?.ended !== true && !nativeCompleted) return null;
6646
6873
  if (evidence === void 0) props.diagnostic("COPILOT_TURN_SELECTION_PROVENANCE_UNAVAILABLE");
6647
6874
  const nativeRoutes = nativeCompleted && record$3(native?.tokenUsage) && Array.isArray(native.tokenUsage.routes) ? native.tokenUsage.routes : [];
6648
- if (!(evidence?.routes ?? nativeRoutes).some((route) => record$3(route) && (route.provider === "github-copilot-preview" || route.provider === "github-copilot") && typeof route.model === "string" && route.model.trim() !== "") && parsed === void 0 && live.mode === "unknown") return null;
6875
+ const copilot = (evidence?.routes ?? nativeRoutes).some((route) => record$3(route) && (route.provider === "github-copilot-preview" || route.provider === "github-copilot") && typeof route.model === "string" && route.model.trim() !== "");
6876
+ const usageDiagnostic = turn === void 0 ? void 0 : turnUsageDiagnostic(turn, native, usageEvidence, copilot);
6877
+ if (!copilot && parsed === void 0 && live.mode === "unknown" && usageDiagnostic === void 0) return null;
6878
+ if (usageDiagnostic !== void 0 && !isTurnUsageEvidence(usageEvidence)) props.diagnostic("COPILOT_TURN_USAGE_EVIDENCE_UNAVAILABLE");
6649
6879
  const selection = live.mode !== "unknown" ? live : parsed?.preference ? {
6650
6880
  mode: "auto",
6651
6881
  preference: parsed.preference,
@@ -6653,13 +6883,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6653
6883
  candidateCount: parsed.candidateCount,
6654
6884
  fittingCandidateCount: parsed.fittingCandidateCount
6655
6885
  } : { mode: "unknown" };
6656
- return react.createElement(TurnSelectionCard, {
6886
+ return react.createElement(react.Fragment, null, react.createElement(TurnSelectionCard, {
6657
6887
  selection,
6658
6888
  locale: language,
6659
6889
  incomplete: evidence?.incomplete ?? true,
6660
6890
  readState: selection.mode === "unknown" ? readState : "ready",
6661
6891
  retry: props.remote === void 0 ? void 0 : () => setReadAttempt((value) => value + 1)
6662
- });
6892
+ }), usageDiagnostic === void 0 ? null : react.createElement(TurnUsageNotice, {
6893
+ diagnostic: usageDiagnostic,
6894
+ locale: language
6895
+ }));
6663
6896
  }
6664
6897
  function installAutoModelProjections(capabilities) {
6665
6898
  if (!record$3(capabilities.uiConversation) || !record$3(capabilities.uiConversation.events) || typeof capabilities.uiConversation.events.register !== "function") {
@@ -6669,6 +6902,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6669
6902
  const events = capabilities.uiConversation.events;
6670
6903
  let removeDefinition = noop$2;
6671
6904
  let removeProvenance = noop$2;
6905
+ let removeUsage = noop$2;
6672
6906
  try {
6673
6907
  removeDefinition = events.register(autoModelAttributionDefinition);
6674
6908
  removeProvenance = events.register(turnModelProvenanceDefinition);
@@ -6678,7 +6912,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6678
6912
  capabilities.diagnostic("COPILOT_AUTO_PROJECTIONS_FAILED");
6679
6913
  return noop$2;
6680
6914
  }
6915
+ try {
6916
+ removeUsage = events.register(turnUsageEvidenceDefinition);
6917
+ } catch {
6918
+ capabilities.diagnostic("COPILOT_TURN_USAGE_PROJECTION_FAILED");
6919
+ }
6681
6920
  return () => {
6921
+ removeUsage();
6682
6922
  removeProvenance();
6683
6923
  removeDefinition();
6684
6924
  };