dsh-github-copilot 0.4.0-alpha.57 → 0.4.0-alpha.58

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
@@ -2495,6 +2495,66 @@ window.__ModuleLoader__.load({
2495
2495
  });
2496
2496
  };
2497
2497
  });
2498
+ const $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
2499
+ def.inclusive = false;
2500
+ $ZodUnion.init(inst, def);
2501
+ const _super = inst._zod.parse;
2502
+ defineLazyInternal(inst, "propValues", (zod) => {
2503
+ const propValues = {};
2504
+ for (const option of zod.def.options) {
2505
+ const pv = option._zod.propValues;
2506
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
2507
+ for (const [k, v] of Object.entries(pv)) {
2508
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) assignProp(propValues, k, /* @__PURE__ */ new Set());
2509
+ for (const val of v) propValues[k].add(val);
2510
+ }
2511
+ }
2512
+ return propValues;
2513
+ });
2514
+ def.options.forEach((option, i) => {
2515
+ const propShape = propShapes.get(option._zod.def);
2516
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) throw new Error(`Invalid discriminated union option at index "${i}"`);
2517
+ });
2518
+ const disc = cached(() => {
2519
+ const opts = def.options;
2520
+ const map = /* @__PURE__ */ new Map();
2521
+ for (const o of opts) {
2522
+ const values = o._zod.propValues?.[def.discriminator];
2523
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
2524
+ for (const v of values) {
2525
+ if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
2526
+ map.set(v, o);
2527
+ }
2528
+ }
2529
+ return map;
2530
+ });
2531
+ inst._zod.parse = (payload, ctx) => {
2532
+ const input = payload.value;
2533
+ if (!isObject(input)) {
2534
+ payload.issues.push({
2535
+ code: "invalid_type",
2536
+ expected: "object",
2537
+ input,
2538
+ inst
2539
+ });
2540
+ return payload;
2541
+ }
2542
+ const opt = disc.value.get(input?.[def.discriminator]);
2543
+ if (opt) return opt._zod.run(payload, ctx);
2544
+ if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
2545
+ payload.issues.push({
2546
+ code: "invalid_union",
2547
+ errors: [],
2548
+ note: "No matching discriminator",
2549
+ discriminator: def.discriminator,
2550
+ options: Array.from(disc.value.keys()),
2551
+ input,
2552
+ path: [def.discriminator],
2553
+ inst
2554
+ });
2555
+ return payload;
2556
+ };
2557
+ });
2498
2558
  const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
2499
2559
  $ZodType.init(inst, def);
2500
2560
  inst._zod.parse = (payload, ctx) => {
@@ -5142,6 +5202,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5142
5202
  ...normalizeParams(params)
5143
5203
  });
5144
5204
  }
5205
+ const ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
5206
+ ZodUnion.init(inst, def);
5207
+ $ZodDiscriminatedUnion.init(inst, def);
5208
+ });
5209
+ function discriminatedUnion(discriminator, options, params) {
5210
+ return new ZodDiscriminatedUnion({
5211
+ type: "union",
5212
+ options,
5213
+ discriminator,
5214
+ ...normalizeParams(params)
5215
+ });
5216
+ }
5145
5217
  const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
5146
5218
  $ZodIntersection.init(inst, def);
5147
5219
  ZodType.init(inst, def);
@@ -5418,7 +5490,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5418
5490
  expectedRevision: revision
5419
5491
  }).strict();
5420
5492
  const DualModelCreateResultSchema = object({ sessionId: id }).strict();
5421
- const contribution$3 = {
5493
+ const contribution$4 = {
5422
5494
  package: "dsh-github-copilot",
5423
5495
  descriptors: [
5424
5496
  {
@@ -5466,7 +5538,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5466
5538
  supported: boolean(),
5467
5539
  providers: array(object({ id: string().min(1).max(512) }).strict()).max(512)
5468
5540
  }).strict();
5469
- const contribution$2 = {
5541
+ const contribution$3 = {
5470
5542
  package: "dsh-github-copilot",
5471
5543
  descriptors: [{
5472
5544
  id: "dsh-github-copilot:githubCopilotSearchRouting.providers",
@@ -5559,7 +5631,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5559
5631
  if (view.remaining !== void 0 && view.percentUsed !== void 0 && Math.abs((1 - view.remaining / view.limit) * 100 - view.percentUsed) > 1) invalid();
5560
5632
  }
5561
5633
  });
5562
- const contribution$1 = {
5634
+ const contribution$2 = {
5563
5635
  package: "dsh-github-copilot",
5564
5636
  descriptors: ["get", "refresh"].map((method) => ({
5565
5637
  id: `dsh-github-copilot:githubCopilotUsage.${method}`,
@@ -5572,6 +5644,57 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5572
5644
  }))
5573
5645
  };
5574
5646
  //#endregion
5647
+ //#region lib/types/turn-selection.js
5648
+ const TurnSelectionSchema = discriminatedUnion("mode", [
5649
+ object({ mode: literal("unknown") }).strict(),
5650
+ object({ mode: literal("manual") }).strict(),
5651
+ object({
5652
+ mode: literal("auto"),
5653
+ preference: _enum([
5654
+ "efficiency",
5655
+ "balance",
5656
+ "intelligence"
5657
+ ]),
5658
+ reason: _enum([
5659
+ "short-text-turn",
5660
+ "standard-turn",
5661
+ "large-structured-turn",
5662
+ "image-capability"
5663
+ ]),
5664
+ candidateCount: number().int().positive(),
5665
+ fittingCandidateCount: number().int().nonnegative().optional()
5666
+ }).strict()
5667
+ ]);
5668
+ //#endregion
5669
+ //#region lib/types/turn-selection-remote.js
5670
+ const contribution$1 = {
5671
+ package: "dsh-github-copilot",
5672
+ descriptors: [{
5673
+ id: "dsh-github-copilot:githubCopilotTurnSelection.get",
5674
+ namespace: "githubCopilotTurnSelection",
5675
+ service: "githubCopilotTurnSelection",
5676
+ method: "get",
5677
+ invocation: { kind: "direct" },
5678
+ scope: {
5679
+ context: "agent",
5680
+ wire: "agentId"
5681
+ },
5682
+ parameters: [{
5683
+ name: "agent",
5684
+ wire: "agentId",
5685
+ source: "lookup",
5686
+ lookup: "agent",
5687
+ codec: strictRemoteCodec("@deepseek-ai/dsh-session/types#SessionId", string().min(1).max(256))
5688
+ }, {
5689
+ name: "turn",
5690
+ wire: "turn",
5691
+ source: "json",
5692
+ codec: strictRemoteCodec("dsh-github-copilot#TurnSelectionTurn", number().int().nonnegative().max(Number.MAX_SAFE_INTEGER))
5693
+ }],
5694
+ result: strictRemoteCodec("dsh-github-copilot#TurnSelection", TurnSelectionSchema)
5695
+ }]
5696
+ };
5697
+ //#endregion
5575
5698
  //#region lib/types/remote.js
5576
5699
  /**
5577
5700
  * Client-safe Remote contribution for the plugin-owned authorization bridge.
@@ -5729,6 +5852,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5729
5852
  parameters: [],
5730
5853
  result: strictRemoteCodec(GITHUB_COPILOT_MIGRATION_STATUS_TYPE_SYMBOL, GitHubCopilotMigrationStatusSchema)
5731
5854
  },
5855
+ ...contribution$4.descriptors,
5732
5856
  ...contribution$3.descriptors,
5733
5857
  ...contribution$2.descriptors,
5734
5858
  ...contribution$1.descriptors
@@ -5742,14 +5866,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5742
5866
  const CHAT_NODE_SLOT = "conversation.chat.node";
5743
5867
  const ASSISTANT_KEY = "assistant-step";
5744
5868
  const noop$2 = () => {};
5745
- function record$3(value) {
5869
+ function record$4(value) {
5746
5870
  return typeof value === "object" && value !== null;
5747
5871
  }
5748
5872
  function sequence$1(value) {
5749
5873
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
5750
5874
  }
5751
5875
  function eventLocation(event) {
5752
- if (!record$3(event) || !record$3(event.data)) return void 0;
5876
+ if (!record$4(event) || !record$4(event.data)) return void 0;
5753
5877
  const { turn, step } = event.data;
5754
5878
  return sequence$1(turn) && sequence$1(step) ? {
5755
5879
  turn,
@@ -5757,9 +5881,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5757
5881
  } : void 0;
5758
5882
  }
5759
5883
  function messageOrigin(event) {
5760
- if (!record$3(event) || event.type !== "assistant/message" || event.surfaceOp !== "append" || !sequence$1(event.seq) || !record$3(event.data) || !record$3(event.data.message)) return void 0;
5884
+ if (!record$4(event) || event.type !== "assistant/message" || event.surfaceOp !== "append" || !sequence$1(event.seq) || !record$4(event.data) || !record$4(event.data.message)) return void 0;
5761
5885
  const source = event.data.message.source;
5762
- if (!record$3(source) || typeof source.provider !== "string" || source.provider.trim() === "" || typeof source.model !== "string" || source.model.trim() === "") return void 0;
5886
+ if (!record$4(source) || typeof source.provider !== "string" || source.provider.trim() === "" || typeof source.model !== "string" || source.model.trim() === "") return void 0;
5763
5887
  return {
5764
5888
  seq: event.seq,
5765
5889
  provider: source.provider,
@@ -5770,7 +5894,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5770
5894
  const assistantOriginDefinition = {
5771
5895
  kind: ASSISTANT_ORIGIN_KEY,
5772
5896
  match(event) {
5773
- if (!record$3(event)) return null;
5897
+ if (!record$4(event)) return null;
5774
5898
  const location = eventLocation(event);
5775
5899
  if (location === void 0) return null;
5776
5900
  if (event.type === "step/start") return {
@@ -5785,14 +5909,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5785
5909
  },
5786
5910
  start(_context, match) {
5787
5911
  const location = eventLocation(match.event);
5788
- if (location === void 0 || !record$3(match.event) || match.event.type !== "step/start") throw new Error("COPILOT_REASONING_ORIGIN_START: expected step/start");
5912
+ if (location === void 0 || !record$4(match.event) || match.event.type !== "step/start") throw new Error("COPILOT_REASONING_ORIGIN_START: expected step/start");
5789
5913
  return {
5790
5914
  ...location,
5791
5915
  origin: void 0
5792
5916
  };
5793
5917
  },
5794
5918
  update(context, match) {
5795
- if (!record$3(match.event) || match.event.type !== "assistant/message" || match.event.surfaceOp !== "append") return context.state;
5919
+ if (!record$4(match.event) || match.event.type !== "assistant/message" || match.event.surfaceOp !== "append") return context.state;
5796
5920
  return {
5797
5921
  ...context.state,
5798
5922
  origin: messageOrigin(match.event)
@@ -5803,7 +5927,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5803
5927
  let state = context.state;
5804
5928
  if (state === void 0) for (const match of context.matches) {
5805
5929
  const event = match.event;
5806
- if (!record$3(event) || event.type !== "assistant/message" || event.surfaceOp !== "append") continue;
5930
+ if (!record$4(event) || event.type !== "assistant/message" || event.surfaceOp !== "append") continue;
5807
5931
  const location = eventLocation(event);
5808
5932
  if (location !== void 0) state = {
5809
5933
  ...location,
@@ -5824,12 +5948,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5824
5948
  };
5825
5949
  /** Shallow UI-only projection. Unchanged input retains its exact props identity. */
5826
5950
  function projectReasoningPresentation(props, origin) {
5827
- if (!record$3(props) || !record$3(props.node) || props.node.kind !== ASSISTANT_KEY || !record$3(props.node.data) || !record$3(origin)) return props;
5951
+ if (!record$4(props) || !record$4(props.node) || props.node.kind !== ASSISTANT_KEY || !record$4(props.node.data) || !record$4(origin)) return props;
5828
5952
  const node = props.node;
5829
5953
  const data = node.data;
5830
- if (data.status !== "settled" || !record$3(data.finalNode) || !sequence$1(data.finalNode.seq) || origin.seq !== data.finalNode.seq) return props;
5954
+ if (data.status !== "settled" || !record$4(data.finalNode) || !sequence$1(data.finalNode.seq) || origin.seq !== data.finalNode.seq) return props;
5831
5955
  if (!(origin.provider === "github-copilot" || origin.provider === "github-copilot-preview") || typeof origin.model !== "string" || origin.model.trim() === "" || !Array.isArray(data.blocks)) return props;
5832
- const blocks = data.blocks.filter((block) => !(record$3(block) && block.kind === "reasoning" && typeof block.text === "string" && block.text.trim() === ""));
5956
+ const blocks = data.blocks.filter((block) => !(record$4(block) && block.kind === "reasoning" && typeof block.text === "string" && block.text.trim() === ""));
5833
5957
  if (blocks.length === data.blocks.length) return props;
5834
5958
  return {
5835
5959
  ...props,
@@ -5848,12 +5972,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5848
5972
  };
5849
5973
  function originSource(props) {
5850
5974
  const node = props.node;
5851
- if (!record$3(node) || !record$3(node.location) || node.location.kind !== "step" || !record$3(node.location.step) || !record$3(node.location.step.data)) return missingOriginSource;
5975
+ if (!record$4(node) || !record$4(node.location) || node.location.kind !== "step" || !record$4(node.location.step) || !record$4(node.location.step.data)) return missingOriginSource;
5852
5976
  const store = node.location.step.data;
5853
5977
  if (typeof store.source !== "function") return missingOriginSource;
5854
5978
  try {
5855
5979
  const source = store.source(ASSISTANT_ORIGIN_KEY);
5856
- if (!record$3(source) || typeof source.getSnapshot !== "function" || typeof source.subscribe !== "function") return missingOriginSource;
5980
+ if (!record$4(source) || typeof source.getSnapshot !== "function" || typeof source.subscribe !== "function") return missingOriginSource;
5857
5981
  return source;
5858
5982
  } catch {
5859
5983
  return missingOriginSource;
@@ -5867,7 +5991,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5867
5991
  */
5868
5992
  function supportedNative(entry) {
5869
5993
  const component = entry.component;
5870
- 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$3(component) && component.$$typeof === Symbol.for("react.memo") && typeof component.type === "function" && component.type.name === "AssistantNodeView";
5994
+ 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$4(component) && component.$$typeof === Symbol.for("react.memo") && typeof component.type === "function" && component.type.name === "AssistantNodeView";
5871
5995
  }
5872
5996
  /**
5873
5997
  * Optional Client enhancement. The caller owns the returned disposer in its
@@ -5877,13 +6001,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5877
6001
  const { diagnostic } = capabilities;
5878
6002
  const slotsCandidate = capabilities.slots;
5879
6003
  const conversation = capabilities.uiConversation;
5880
- if (!record$3(slotsCandidate) || ![
6004
+ if (!record$4(slotsCandidate) || ![
5881
6005
  "entries",
5882
6006
  "spec",
5883
6007
  "subscribe",
5884
6008
  "inject",
5885
6009
  "register"
5886
- ].every((key) => typeof slotsCandidate[key] === "function") || !record$3(conversation) || !record$3(conversation.events) || typeof conversation.events.register !== "function") {
6010
+ ].every((key) => typeof slotsCandidate[key] === "function") || !record$4(conversation) || !record$4(conversation.events) || typeof conversation.events.register !== "function") {
5887
6011
  diagnostic("COPILOT_REASONING_PRESENTATION_UNAVAILABLE");
5888
6012
  return noop$2;
5889
6013
  }
@@ -5986,9 +6110,232 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5986
6110
  };
5987
6111
  }
5988
6112
  //#endregion
6113
+ //#region lib/types/turn-model-provenance.js
6114
+ const TURN_MODEL_PROVENANCE_KEY = "github-copilot-turn-model-provenance";
6115
+ function record$3(value) {
6116
+ return typeof value === "object" && value !== null;
6117
+ }
6118
+ function isTurnModelProvenance(value) {
6119
+ return record$3(value) && typeof value.ended === "boolean" && typeof value.incomplete === "boolean" && Array.isArray(value.routes) && value.routes.every((route) => record$3(route) && typeof route.provider === "string" && route.provider.trim() !== "" && typeof route.model === "string" && route.model.trim() !== "");
6120
+ }
6121
+ function coordinates(event) {
6122
+ if (!record$3(event) || typeof event.type !== "string" || !record$3(event.data) || !Number.isSafeInteger(event.data.turn) || typeof event.data.turn !== "number" || event.data.turn < 0 || ![
6123
+ "turn/start",
6124
+ "turn/end",
6125
+ "step/start",
6126
+ "step/end",
6127
+ "assistant/message",
6128
+ "assistant/attempt",
6129
+ "llm/retry"
6130
+ ].includes(event.type)) return void 0;
6131
+ if (event.type === "assistant/message" && event.surfaceOp !== "append") return void 0;
6132
+ return {
6133
+ turn: event.data.turn,
6134
+ type: event.type,
6135
+ data: event.data
6136
+ };
6137
+ }
6138
+ function fold(state, event) {
6139
+ const parsed = coordinates(event);
6140
+ if (parsed === void 0 || state !== void 0 && state.turn !== parsed.turn) return state;
6141
+ const hasStart = state?.hasStart === true || parsed.type === "turn/start";
6142
+ const routes = state?.value.routes ?? [];
6143
+ const step = typeof parsed.data.step === "number" && Number.isSafeInteger(parsed.data.step) ? parsed.data.step : void 0;
6144
+ let openSteps = state?.openSteps ?? [];
6145
+ if (parsed.type === "step/start" && step !== void 0 && !openSteps.includes(step)) openSteps = [...openSteps, step];
6146
+ const unrecorded = parsed.type === "turn/end" && openSteps.length > 0 || parsed.type === "step/end" && step !== void 0 && openSteps.includes(step);
6147
+ if ([
6148
+ "assistant/message",
6149
+ "assistant/attempt",
6150
+ "step/end"
6151
+ ].includes(parsed.type)) openSteps = openSteps.filter((value) => value !== step);
6152
+ let missing = false;
6153
+ let route;
6154
+ if (parsed.type === "assistant/message") {
6155
+ const source = record$3(parsed.data.message) ? parsed.data.message.source : void 0;
6156
+ if (record$3(source) && typeof source.provider === "string" && source.provider.trim() !== "" && typeof source.model === "string" && source.model.trim() !== "") route = {
6157
+ provider: source.provider,
6158
+ model: source.model
6159
+ };
6160
+ else missing = true;
6161
+ }
6162
+ return {
6163
+ turn: parsed.turn,
6164
+ hasStart,
6165
+ openSteps,
6166
+ value: {
6167
+ routes: route && !routes.some((value) => value.provider === route.provider && value.model === route.model) ? [...routes, route] : routes,
6168
+ incomplete: state?.value.incomplete === true || missing || unrecorded || parsed.type === "assistant/attempt" || parsed.type === "llm/retry",
6169
+ ended: state?.value.ended === true || parsed.type === "turn/end"
6170
+ }
6171
+ };
6172
+ }
6173
+ /** Read provenance only; native Core retains attempt accounting and token totals. */
6174
+ const turnModelProvenanceDefinition = {
6175
+ kind: TURN_MODEL_PROVENANCE_KEY,
6176
+ match(event) {
6177
+ const parsed = coordinates(event);
6178
+ return parsed ? {
6179
+ id: String(parsed.turn),
6180
+ role: parsed.type === "turn/start" ? "start" : "update"
6181
+ } : null;
6182
+ },
6183
+ start(_context, match) {
6184
+ const state = fold(void 0, match.event);
6185
+ if (!state) throw new Error("COPILOT_MODEL_PROVENANCE_START");
6186
+ return state;
6187
+ },
6188
+ update(context, match) {
6189
+ return fold(context.state, match.event) ?? context.state;
6190
+ },
6191
+ buildLocationData(context, scope, previous) {
6192
+ if (scope !== "turn") return null;
6193
+ const state = context.state ?? context.matches.reduce((state, match) => fold(state, match.event), void 0);
6194
+ if (!state) return null;
6195
+ const value = {
6196
+ ...state.value,
6197
+ incomplete: state.value.incomplete || !state.hasStart
6198
+ };
6199
+ if (previous?.turn === state.turn && previous.value.ended === value.ended && previous.value.incomplete === value.incomplete && previous.value.routes.length === value.routes.length && previous.value.routes.every((route, index) => route.provider === value.routes[index]?.provider && route.model === value.routes[index]?.model)) return previous;
6200
+ return {
6201
+ kind: "turn",
6202
+ turn: state.turn,
6203
+ key: TURN_MODEL_PROVENANCE_KEY,
6204
+ value
6205
+ };
6206
+ }
6207
+ };
6208
+ //#endregion
6209
+ //#region lib/types/turn-selection-card.js
6210
+ function TurnSelectionCard({ selection, locale = "en", incomplete = false }) {
6211
+ const zh = locale.startsWith("zh");
6212
+ const id = (0, react.useId)();
6213
+ const [open, setOpen] = (0, react.useState)(false);
6214
+ const [position, setPosition] = (0, react.useState)({
6215
+ left: 12,
6216
+ top: 12
6217
+ });
6218
+ const trigger = (0, react.useRef)(null);
6219
+ const panel = (0, react.useRef)(null);
6220
+ const close = (0, react.useRef)(null);
6221
+ (0, react.useLayoutEffect)(() => {
6222
+ if (!open) return;
6223
+ panel.current?.showPopover?.();
6224
+ const place = () => {
6225
+ const a = trigger.current?.getBoundingClientRect(), b = panel.current?.getBoundingClientRect();
6226
+ if (a && b) setPosition({
6227
+ left: Math.max(12, Math.min(a.left, innerWidth - b.width - 12)),
6228
+ top: Math.max(12, Math.min(a.top - b.height - 8, innerHeight - b.height - 12))
6229
+ });
6230
+ };
6231
+ place();
6232
+ close.current?.focus();
6233
+ window.addEventListener("resize", place);
6234
+ window.addEventListener("scroll", place, true);
6235
+ return () => {
6236
+ window.removeEventListener("resize", place);
6237
+ window.removeEventListener("scroll", place, true);
6238
+ };
6239
+ }, [open]);
6240
+ (0, react.useEffect)(() => {
6241
+ if (!open) return;
6242
+ const outside = (event) => {
6243
+ if (event.target instanceof Node && !panel.current?.contains(event.target) && !trigger.current?.contains(event.target)) setOpen(false);
6244
+ };
6245
+ const key = (event) => {
6246
+ if (event.key === "Escape") {
6247
+ event.preventDefault();
6248
+ setOpen(false);
6249
+ trigger.current?.focus();
6250
+ }
6251
+ };
6252
+ document.addEventListener("pointerdown", outside);
6253
+ document.addEventListener("focusin", outside);
6254
+ document.addEventListener("keydown", key);
6255
+ return () => {
6256
+ document.removeEventListener("pointerdown", outside);
6257
+ document.removeEventListener("focusin", outside);
6258
+ document.removeEventListener("keydown", key);
6259
+ };
6260
+ }, [open]);
6261
+ const label = selection.mode === "auto" ? `Auto (${selection.preference})` : selection.mode === "manual" ? zh ? "手动" : "Manual" : zh ? "选择方式未知" : "Selection unknown";
6262
+ const reason = selection.mode !== "auto" ? "" : {
6263
+ "short-text-turn": zh ? "短文本轮次" : "Short text turn",
6264
+ "standard-turn": zh ? "常规轮次" : "Standard turn",
6265
+ "large-structured-turn": zh ? "较大结构化轮次" : "Large structured turn",
6266
+ "image-capability": zh ? "需要图片能力" : "Image capability required"
6267
+ }[selection.reason];
6268
+ const button = {
6269
+ font: "inherit",
6270
+ color: "inherit",
6271
+ background: "transparent",
6272
+ border: "1px solid var(--dsw-alias-border-main, GrayText)",
6273
+ borderRadius: 6,
6274
+ cursor: "pointer"
6275
+ };
6276
+ return (0, react.createElement)("span", { style: {
6277
+ order: 1,
6278
+ display: "inline-flex",
6279
+ flexWrap: "wrap",
6280
+ alignItems: "center",
6281
+ gap: 4,
6282
+ minWidth: 0,
6283
+ maxWidth: "100%",
6284
+ fontSize: "var(--dsh-content-font-size-secondary, 13px)",
6285
+ color: "var(--dsw-alias-label-tertiary, GrayText)"
6286
+ } }, (0, react.createElement)("span", { title: selection.mode === "unknown" ? zh ? "本轮选择记录未保留;不从当前选择推断历史。" : "No retained selection evidence; the current picker is not historical evidence." : void 0 }, label), selection.mode === "auto" || incomplete ? (0, react.createElement)("button", {
6287
+ ref: trigger,
6288
+ type: "button",
6289
+ style: {
6290
+ ...button,
6291
+ width: 24,
6292
+ height: 24,
6293
+ flexShrink: 0
6294
+ },
6295
+ "aria-label": zh ? "本轮选择记录" : "Turn selection evidence",
6296
+ "aria-expanded": open,
6297
+ "aria-controls": open ? id : void 0,
6298
+ "aria-haspopup": "dialog",
6299
+ onClick: () => setOpen((value) => !value)
6300
+ }, "ⓘ") : null, open ? (0, react.createElement)("div", {
6301
+ ref: panel,
6302
+ id,
6303
+ popover: "manual",
6304
+ role: "dialog",
6305
+ "aria-label": zh ? "本轮选择记录" : "Turn selection evidence",
6306
+ style: {
6307
+ position: "fixed",
6308
+ inset: "auto",
6309
+ ...position,
6310
+ margin: 0,
6311
+ zIndex: 1e3,
6312
+ width: 300,
6313
+ maxWidth: "calc(100vw - 24px)",
6314
+ maxHeight: `calc(100dvh - ${position.top + 12}px)`,
6315
+ overflowY: "auto",
6316
+ overflowWrap: "anywhere",
6317
+ boxSizing: "border-box",
6318
+ padding: 16,
6319
+ borderRadius: 12,
6320
+ border: button.border,
6321
+ background: "var(--dsw-alias-bg-layer-2, Canvas)",
6322
+ color: "var(--dsw-alias-label-primary, CanvasText)",
6323
+ lineHeight: 1.6
6324
+ }
6325
+ }, (0, react.createElement)("strong", null, zh ? "本轮选择记录" : "Turn selection evidence"), selection.mode === "auto" ? (0, react.createElement)("p", null, `${reason}. `, zh ? `容量偏好:${selection.preference}。` : `Capacity preference: ${selection.preference}. `, zh ? `从 ${selection.candidateCount} 个合格模型中选择。` : `Selected from ${selection.candidateCount} eligible models.`, selection.fittingCandidateCount === void 0 ? "" : zh ? `其中 ${selection.fittingCandidateCount} 个可容纳估算输入。` : ` ${selection.fittingCandidateCount} fit the estimated input.`) : null, incomplete ? (0, react.createElement)("p", null, zh ? "模型归属不完整:部分尝试或历史未记录模型。原生 Usage 保持不变。" : "Model attribution is incomplete: some attempts or history have no recorded model. Native Usage is unchanged.") : null, (0, react.createElement)("p", null, zh ? "此记录说明选择方式,不证明执行;实际模型以原生 Usage 为准。" : "Selection evidence is not execution proof; see native Usage for recorded models."), (0, react.createElement)("button", {
6326
+ ref: close,
6327
+ type: "button",
6328
+ style: button,
6329
+ onClick: () => {
6330
+ setOpen(false);
6331
+ trigger.current?.focus();
6332
+ }
6333
+ }, zh ? "关闭" : "Close")) : null);
6334
+ }
6335
+ //#endregion
5989
6336
  //#region lib/types/auto-model-presentation.js
5990
6337
  const AUTO_MODEL_ATTRIBUTION_KEY = "github-copilot-auto-model-attribution";
5991
- const SLOT = "conversation.chat.turnTail";
6338
+ const SLOT = "conversation.chat.assistant-actions";
5992
6339
  const noop$1 = () => {};
5993
6340
  function record$2(value) {
5994
6341
  return typeof value === "object" && value !== null;
@@ -6061,65 +6408,86 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6061
6408
  getSnapshot: () => void 0,
6062
6409
  subscribe: () => noop$1
6063
6410
  };
6064
- function sourceOf(props) {
6411
+ function sourceOf(props, key, diagnostic) {
6065
6412
  const turn = props.turn;
6066
6413
  if (!record$2(turn) || !record$2(turn.data) || typeof turn.data.source !== "function") return missingSource;
6067
6414
  try {
6068
- const source = turn.data.source(AUTO_MODEL_ATTRIBUTION_KEY);
6415
+ const source = turn.data.source(key);
6069
6416
  return record$2(source) && typeof source.getSnapshot === "function" && typeof source.subscribe === "function" ? source : missingSource;
6070
6417
  } catch {
6418
+ diagnostic("COPILOT_TURN_SELECTION_PROJECTION_FAILED");
6071
6419
  return missingSource;
6072
6420
  }
6073
6421
  }
6074
- /** Inline footer chrome: after the settled clock, hidden until the message is hovered. */
6075
- const AUTO_ATTRIBUTION_STYLE = [
6076
- "[data-turn-tail]:has(> [data-copilot-auto-attribution]){flex-direction:row;flex-wrap:wrap;align-items:center;gap:0 8px}",
6077
- "[data-turn-tail]>[data-copilot-auto-attribution]{order:1;display:inline-flex;align-items:center;gap:6px;margin:0;padding-left:4px;color:var(--dsw-alias-label-tertiary,var(--text-muted,#667085));font-size:14px;line-height:24px;white-space:nowrap}",
6078
- "@media (hover:hover){[data-time-hover-root]>[data-copilot-auto-attribution]{opacity:0;transition:opacity 80ms ease}",
6079
- "[data-time-hover-root]:hover>[data-copilot-auto-attribution],[data-time-hover-root]:focus-within>[data-copilot-auto-attribution]{opacity:1}}"
6080
- ].join("");
6081
- const AUTO_ATTRIBUTION_STYLE_ID = "dsh-copilot-auto-attribution-style";
6082
- function ensureAttributionStyle() {
6083
- if (typeof document === "undefined" || document.getElementById(AUTO_ATTRIBUTION_STYLE_ID)) return;
6084
- const style = document.createElement("style");
6085
- style.id = AUTO_ATTRIBUTION_STYLE_ID;
6086
- style.textContent = AUTO_ATTRIBUTION_STYLE;
6087
- document.head.appendChild(style);
6088
- }
6089
- function reasonText(value) {
6090
- const reason = value.reason === "short-text-turn" ? "Short text turn" : value.reason === "large-structured-turn" ? "Large structured turn" : value.reason === "image-capability" ? "Image-capable model required" : "Standard turn";
6091
- const fitInfo = value.fittingCandidateCount !== void 0 && value.fittingCandidateCount < value.candidateCount ? `; ${value.fittingCandidateCount} of ${value.candidateCount} models can fit turn context` : "";
6092
- return `${reason}; ${value.preference ?? "balance"} capacity preference; selected from ${value.candidateCount} eligible account model${value.candidateCount === 1 ? "" : "s"}${fitInfo}.`;
6422
+ function findTurn(snapshot, messageId) {
6423
+ if (!record$2(snapshot) || !(snapshot.nodes instanceof Map) || typeof messageId !== "string") return void 0;
6424
+ for (const node of snapshot.nodes.values()) {
6425
+ if (!record$2(node) || node.kind !== "turn-tail" || !record$2(node.data) || !record$2(node.data.closing)) continue;
6426
+ const closing = node.data.closing;
6427
+ if (record$2(closing.finalNode) && closing.finalNode.messageId === messageId && record$2(node.location)) return node.location.turn;
6428
+ }
6093
6429
  }
6094
6430
  function Attribution(props) {
6095
- const source = sourceOf(props);
6431
+ const [live, setLive] = react.useState({ mode: "unknown" });
6432
+ const turn = record$2(props.turn) && sequence(props.turn.turn) ? props.turn.turn : void 0;
6433
+ const sessionId = typeof props.sessionId === "string" ? props.sessionId : void 0;
6434
+ react.useEffect(() => {
6435
+ setLive({ mode: "unknown" });
6436
+ if (turn === void 0 || sessionId === void 0 || props.remote === void 0) return;
6437
+ let active = true;
6438
+ props.remote.get(sessionId, turn).then((result) => {
6439
+ if (!active) return;
6440
+ const parsed = result.ok ? TurnSelectionSchema.safeParse(result.value) : void 0;
6441
+ if (parsed?.success) setLive(parsed.data);
6442
+ else props.diagnostic("COPILOT_TURN_SELECTION_READ_FAILED");
6443
+ }, () => {
6444
+ if (active) props.diagnostic("COPILOT_TURN_SELECTION_READ_FAILED");
6445
+ });
6446
+ return () => {
6447
+ active = false;
6448
+ };
6449
+ }, [
6450
+ props.remote,
6451
+ sessionId,
6452
+ turn,
6453
+ props.diagnostic
6454
+ ]);
6455
+ const language = react.useSyncExternalStore(props.locale ? (listener) => props.locale.subscribe(listener) : () => noop$1, () => props.locale?.getLocale().active ?? "en", () => "en");
6456
+ const source = sourceOf(props, AUTO_MODEL_ATTRIBUTION_KEY, props.diagnostic);
6096
6457
  const value = react.useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
6097
- const [open, setOpen] = react.useState(false);
6098
- react.useEffect(ensureAttributionStyle, []);
6099
- if (!record$2(value) || typeof value.model !== "string" || typeof value.provider !== "string" || !sequence(value.candidateCount)) return null;
6100
- const parsed = value;
6101
- return react.createElement("span", { "data-copilot-auto-attribution": "" }, react.createElement("span", null, `Auto${parsed.preference === void 0 || parsed.preference === "balance" ? "" : ` (${parsed.preference})`} · ${parsed.model}`), react.createElement("button", {
6102
- type: "button",
6103
- "aria-label": "Why this model",
6104
- "aria-expanded": open,
6105
- title: open ? reasonText(parsed) : "Why this model",
6106
- onClick: () => setOpen((current) => !current),
6107
- style: {
6108
- width: 18,
6109
- height: 18,
6110
- padding: 0,
6111
- borderRadius: "50%",
6112
- border: "1px solid currentColor",
6113
- color: "inherit",
6114
- background: "transparent",
6115
- cursor: "pointer",
6116
- fontSize: 11,
6117
- lineHeight: "16px"
6458
+ const provenanceSource = sourceOf(props, TURN_MODEL_PROVENANCE_KEY, props.diagnostic);
6459
+ const provenance = react.useSyncExternalStore(provenanceSource.subscribe, provenanceSource.getSnapshot, provenanceSource.getSnapshot);
6460
+ const parsed = attribution({
6461
+ type: "github-copilot/auto-model-decision",
6462
+ data: {
6463
+ ...record$2(value) ? value : {},
6464
+ turn: 0
6118
6465
  }
6119
- }, "?"), open ? react.createElement("span", { role: "status" }, reasonText(parsed)) : null);
6466
+ })?.value;
6467
+ const evidence = isTurnModelProvenance(provenance) ? provenance : void 0;
6468
+ if (evidence?.ended !== true) return null;
6469
+ if (!evidence.routes.some((route) => route.provider === "github-copilot-preview" || route.provider === "github-copilot") && parsed === void 0 && live.mode === "unknown") return null;
6470
+ const selection = live.mode !== "unknown" ? live : parsed?.preference ? {
6471
+ mode: "auto",
6472
+ preference: parsed.preference,
6473
+ reason: parsed.reason,
6474
+ candidateCount: parsed.candidateCount,
6475
+ fittingCandidateCount: parsed.fittingCandidateCount
6476
+ } : { mode: "unknown" };
6477
+ return react.createElement(TurnSelectionCard, {
6478
+ selection,
6479
+ locale: language,
6480
+ incomplete: evidence.incomplete
6481
+ });
6120
6482
  }
6121
6483
  function installAutoModelPresentation(capabilities) {
6122
- const { diagnostic } = capabilities;
6484
+ const diagnosed = /* @__PURE__ */ new Set();
6485
+ const diagnostic = (code) => {
6486
+ if (!diagnosed.has(code)) {
6487
+ diagnosed.add(code);
6488
+ capabilities.diagnostic(code);
6489
+ }
6490
+ };
6123
6491
  const slotsCandidate = capabilities.slots;
6124
6492
  if (!record$2(slotsCandidate) || ![
6125
6493
  "spec",
@@ -6131,29 +6499,54 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6131
6499
  }
6132
6500
  const slots = slotsCandidate;
6133
6501
  const events = capabilities.uiConversation.events;
6502
+ const face = record$2(capabilities.remote) ? capabilities.remote.githubCopilotTurnSelection : void 0;
6503
+ const remote = record$2(face) && typeof face.get === "function" ? face : void 0;
6504
+ const locale = record$2(capabilities.locale) && typeof capabilities.locale.getLocale === "function" && typeof capabilities.locale.subscribe === "function" ? capabilities.locale : void 0;
6505
+ if (!remote) diagnostic("COPILOT_TURN_SELECTION_REMOTE_UNAVAILABLE");
6506
+ function Entry(props) {
6507
+ if (typeof props.useChat !== "function") {
6508
+ diagnostic("COPILOT_TURN_SELECTION_CHAT_RUNTIME_UNAVAILABLE");
6509
+ return null;
6510
+ }
6511
+ const useChat = props.useChat;
6512
+ const turn = useChat((snapshot) => findTurn(snapshot, props.messageId));
6513
+ if (!record$2(turn) || !sequence(turn.turn)) return null;
6514
+ return react.createElement(Attribution, {
6515
+ ...props,
6516
+ key: `${props.sessionId}:${turn.turn}`,
6517
+ turn,
6518
+ remote,
6519
+ locale,
6520
+ diagnostic
6521
+ });
6522
+ }
6134
6523
  let removeDefinition = noop$1;
6524
+ let removeProvenance = noop$1;
6135
6525
  let removeInjection = noop$1;
6136
6526
  try {
6137
6527
  removeDefinition = events.register(autoModelAttributionDefinition);
6528
+ removeProvenance = events.register(turnModelProvenanceDefinition);
6138
6529
  removeInjection = slots.inject(SLOT, () => {
6139
6530
  if (slots.spec(SLOT)?.kind !== "list" || slots.spec(SLOT)?.scope !== "session") {
6140
- diagnostic("COPILOT_AUTO_TURN_TAIL_UNAVAILABLE");
6531
+ diagnostic("COPILOT_AUTO_ACTIONS_SLOT_UNAVAILABLE");
6141
6532
  return noop$1;
6142
6533
  }
6143
6534
  return slots.register({
6144
6535
  name: SLOT,
6145
6536
  id: "github-copilot-auto-model",
6146
6537
  order: 20
6147
- }, Attribution);
6538
+ }, Entry);
6148
6539
  });
6149
6540
  } catch {
6150
6541
  removeInjection();
6542
+ removeProvenance();
6151
6543
  removeDefinition();
6152
6544
  diagnostic("COPILOT_AUTO_PRESENTATION_FAILED");
6153
6545
  return noop$1;
6154
6546
  }
6155
6547
  return () => {
6156
6548
  removeInjection();
6549
+ removeProvenance();
6157
6550
  removeDefinition();
6158
6551
  };
6159
6552
  }
@@ -8441,6 +8834,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8441
8834
  const capabilities = {
8442
8835
  slots: scope.slots,
8443
8836
  uiConversation: scope.get("uiConversation"),
8837
+ remote: scope.remote,
8838
+ locale: scope.get("locale"),
8444
8839
  diagnostic: (code) => scope.logger.warn(`[github-copilot] ${code}`)
8445
8840
  };
8446
8841
  const reasoning = installReasoningPresentation(capabilities);