@jeffreycao/copilot-api 1.12.3 → 1.12.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/dist/main.js CHANGED
@@ -43,7 +43,7 @@ const { auth } = await import("./auth-hKS7kdCx.js");
43
43
  const { checkUsage } = await import("./check-usage-Cq76N0LH.js");
44
44
  const { debug } = await import("./debug-BiX0ewij.js");
45
45
  const { mcp } = await import("./mcp-CTb-DbQH.js");
46
- const { start } = await import("./start-C4Lm5vjd.js");
46
+ const { start } = await import("./start-Q4n3uMt-.js");
47
47
  await runMain(defineCommand({
48
48
  meta: {
49
49
  name: "copilot-api",
@@ -4251,10 +4251,16 @@ const createCompactionContextManagement = (compactThreshold) => [{
4251
4251
  compact_threshold: compactThreshold
4252
4252
  }];
4253
4253
  const applyResponsesApiContextManagement = (payload, maxPromptTokens, compactThresholdRatio = DEFAULT_RESPONSES_COMPACT_THRESHOLD_RATIO) => {
4254
+ if (hasTerminalCompactionTrigger(payload)) return;
4254
4255
  if (payload.context_management !== void 0) return;
4255
4256
  if (!responsesUtilsDependencies.isResponsesApiContextManagementEnabled()) return;
4256
4257
  payload.context_management = createCompactionContextManagement(getModelResponsesApiCompactThreshold(payload.model) ?? resolveResponsesCompactThreshold(maxPromptTokens, compactThresholdRatio));
4257
4258
  };
4259
+ const hasTerminalCompactionTrigger = (payload) => {
4260
+ const { input } = payload;
4261
+ if (!Array.isArray(input) || input.length === 0) return false;
4262
+ return isResponseInputItemType(input.at(-1), "compaction_trigger");
4263
+ };
4258
4264
  const compactInputByLatestCompaction = (payload) => {
4259
4265
  if (!Array.isArray(payload.input) || payload.input.length === 0) return;
4260
4266
  const latestCompactionMessageIndex = getLatestCompactionMessageIndex(payload.input);
@@ -4265,7 +4271,10 @@ const getLatestCompactionMessageIndex = (input) => {
4265
4271
  for (let index = input.length - 1; index >= 0; index -= 1) if (isCompactionInputItem(input[index])) return index;
4266
4272
  };
4267
4273
  const isCompactionInputItem = (value) => {
4268
- return "type" in value && typeof value.type === "string" && value.type === "compaction";
4274
+ return isResponseInputItemType(value, "compaction");
4275
+ };
4276
+ const isResponseInputItemType = (value, type) => {
4277
+ return typeof value === "object" && value !== null && "type" in value && value.type === type;
4269
4278
  };
4270
4279
  const getPayloadItems = (payload) => {
4271
4280
  const result = [];
@@ -6245,4 +6254,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
6245
6254
  //#endregion
6246
6255
  export { server };
6247
6256
 
6248
- //# sourceMappingURL=server-KVt1BdTD.js.map
6257
+ //# sourceMappingURL=server-DT_EVrGN.js.map