@nick3/copilot-api 1.4.4 → 1.4.6

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.
Files changed (28) hide show
  1. package/README.md +16 -8
  2. package/dist/{accounts-manager-BvbpPVp1.js → accounts-manager-B8Y2Y4ab.js} +241 -60
  3. package/dist/accounts-manager-B8Y2Y4ab.js.map +1 -0
  4. package/dist/admin/assets/index-BFvCJZIK.js +57 -0
  5. package/dist/admin/assets/index-CsAeel_7.css +1 -0
  6. package/dist/admin/index.html +2 -2
  7. package/dist/{auth-C_MhaDzM.js → auth-Bt0FGr8C.js} +3 -3
  8. package/dist/{auth-C_MhaDzM.js.map → auth-Bt0FGr8C.js.map} +1 -1
  9. package/dist/{check-usage-Cw1fo31i.js → check-usage-By-sJOch.js} +4 -4
  10. package/dist/{check-usage-Cw1fo31i.js.map → check-usage-By-sJOch.js.map} +1 -1
  11. package/dist/{get-copilot-token-CbzXMTE5.js → get-copilot-token-Q4FXtOE9.js} +2 -2
  12. package/dist/{get-copilot-token-CbzXMTE5.js.map → get-copilot-token-Q4FXtOE9.js.map} +1 -1
  13. package/dist/main.js +3 -3
  14. package/dist/{poll-access-token-BMaaEFhO.js → poll-access-token-Cp_DfHGH.js} +2 -2
  15. package/dist/{poll-access-token-BMaaEFhO.js.map → poll-access-token-Cp_DfHGH.js.map} +1 -1
  16. package/dist/{server-BKsjCvqp.js → server-Cln-GCLU.js} +136 -75
  17. package/dist/server-Cln-GCLU.js.map +1 -0
  18. package/dist/{start-cJXCnfYv.js → start-DH-QnZxL.js} +7 -7
  19. package/dist/start-DH-QnZxL.js.map +1 -0
  20. package/dist/{utils-DkUv9TDj.js → utils-SV0FyqXk.js} +6 -2
  21. package/dist/utils-SV0FyqXk.js.map +1 -0
  22. package/package.json +1 -1
  23. package/dist/accounts-manager-BvbpPVp1.js.map +0 -1
  24. package/dist/admin/assets/index-Y2SvOXge.js +0 -57
  25. package/dist/admin/assets/index-geiCIixE.css +0 -1
  26. package/dist/server-BKsjCvqp.js.map +0 -1
  27. package/dist/start-cJXCnfYv.js.map +0 -1
  28. package/dist/utils-DkUv9TDj.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { PATHS } from "./paths-DoT4SZ8f.js";
2
2
  import { listAccountsFromRegistry } from "./accounts-registry-c7rs5Ed9.js";
3
- import { HTTPError, accountFromState, cacheModels, copilotBaseUrl, copilotHeaders, forwardError, generateRequestIdFromPayload, getCopilotUsage, getRootSessionId, getUUID, isNullish, parseUserIdMetadata, prepareForCompact, prepareInteractionHeaders, sleep, state } from "./utils-DkUv9TDj.js";
4
- import "./get-copilot-token-CbzXMTE5.js";
5
- import { PROVIDER_TYPE_ANTHROPIC, accountsManager, getAliasTargetSet, getAnthropicApiKey, getConfig, getExtraPromptForModel, getModelAliases, getModelAliasesInfo, getModelRefreshIntervalMs, getProviderConfig, getReasoningEffortForModel, getSmallModel, isForceAgentEnabled, isFreeModelLoadBalancingEnabled, isMessageStartInputTokensFallbackEnabled, isMessagesApiEnabled, isResponsesApiContextManagementModel, mergeConfigWithDefaults, shouldCompactUseSmallModel } from "./accounts-manager-BvbpPVp1.js";
3
+ import { HTTPError, accountFromState, cacheModels, copilotBaseUrl, copilotHeaders, forwardError, generateRequestIdFromPayload, getCopilotUsage, getRootSessionId, getUUID, isNullish, parseUserIdMetadata, prepareForCompact, prepareInteractionHeaders, sleep, state } from "./utils-SV0FyqXk.js";
4
+ import "./get-copilot-token-Q4FXtOE9.js";
5
+ import { PROVIDER_TYPE_ANTHROPIC, accountsManager, getAliasTargetSet, getAnthropicApiKey, getConfig, getExtraPromptForModel, getModelAliases, getModelAliasesInfo, getModelRefreshIntervalMs, getProviderConfig, getReasoningEffortForModel, getSmallModel, isAccountAffinityEnabled, isForceAgentEnabled, isMessageStartInputTokensFallbackEnabled, isMessagesApiEnabled, isResponsesApiContextManagementModel, isResponsesApiWebSearchEnabled, mergeConfigWithDefaults, shouldCompactUseSmallModel } from "./accounts-manager-B8Y2Y4ab.js";
6
6
  import consola from "consola";
7
7
  import fs, { readFile } from "node:fs/promises";
8
8
  import * as path$1 from "node:path";
@@ -189,66 +189,69 @@ function getAdminDbUserVersion(db = getAdminDb()) {
189
189
  return 0;
190
190
  }
191
191
  }
192
- function migrateAdminDb(db) {
193
- const current = db.query("PRAGMA user_version;").get()?.user_version ?? 0;
194
- if (current >= 4) return;
195
- if (current < 1) db.run(`
196
- CREATE TABLE IF NOT EXISTS request_log (
197
- id INTEGER PRIMARY KEY AUTOINCREMENT,
198
- request_id TEXT NOT NULL UNIQUE,
192
+ function migrateV1(db) {
193
+ db.run(`
194
+ CREATE TABLE IF NOT EXISTS request_log (
195
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
196
+ request_id TEXT NOT NULL UNIQUE,
199
197
 
200
- started_at_ms INTEGER NOT NULL,
201
- finished_at_ms INTEGER,
202
- duration_ms INTEGER,
203
- ttfb_ms INTEGER,
198
+ started_at_ms INTEGER NOT NULL,
199
+ finished_at_ms INTEGER,
200
+ duration_ms INTEGER,
201
+ ttfb_ms INTEGER,
204
202
 
205
- method TEXT NOT NULL,
206
- path TEXT NOT NULL,
207
- upstream_endpoint TEXT,
208
- stream INTEGER NOT NULL DEFAULT 0,
203
+ method TEXT NOT NULL,
204
+ path TEXT NOT NULL,
205
+ upstream_endpoint TEXT,
206
+ stream INTEGER NOT NULL DEFAULT 0,
209
207
 
210
- account_id TEXT,
211
- account_type TEXT,
212
- cost_units REAL,
213
- client_model TEXT,
214
- upstream_model TEXT,
208
+ account_id TEXT,
209
+ account_type TEXT,
210
+ cost_units REAL,
211
+ client_model TEXT,
212
+ upstream_model TEXT,
215
213
 
216
- client_ip TEXT,
217
- client_ip_source TEXT,
218
- user_agent TEXT,
214
+ client_ip TEXT,
215
+ client_ip_source TEXT,
216
+ user_agent TEXT,
219
217
 
220
- tokens_input INTEGER,
221
- tokens_output INTEGER,
222
- tokens_total INTEGER,
223
- tokens_cached_input INTEGER,
224
- usage_json TEXT,
218
+ tokens_input INTEGER,
219
+ tokens_output INTEGER,
220
+ tokens_total INTEGER,
221
+ tokens_cached_input INTEGER,
222
+ usage_json TEXT,
225
223
 
226
- premium_remaining_before REAL,
227
- premium_remaining_after REAL,
228
- premium_remaining_diff REAL,
229
- premium_unlimited_before INTEGER,
230
- premium_unlimited_after INTEGER,
224
+ premium_remaining_before REAL,
225
+ premium_remaining_after REAL,
226
+ premium_remaining_diff REAL,
227
+ premium_unlimited_before INTEGER,
228
+ premium_unlimited_after INTEGER,
231
229
 
232
- http_status INTEGER,
233
- error_name TEXT,
234
- error_status INTEGER,
235
- error_message TEXT,
236
- selection_failure_reason TEXT
237
- );
230
+ http_status INTEGER,
231
+ error_name TEXT,
232
+ error_status INTEGER,
233
+ error_message TEXT,
234
+ selection_failure_reason TEXT
235
+ );
238
236
 
239
- CREATE INDEX IF NOT EXISTS idx_request_log_started_at
240
- ON request_log(started_at_ms DESC);
241
- CREATE INDEX IF NOT EXISTS idx_request_log_account_started_at
242
- ON request_log(account_id, started_at_ms DESC);
243
- CREATE INDEX IF NOT EXISTS idx_request_log_model_started_at
244
- ON request_log(upstream_model, started_at_ms DESC);
245
- CREATE INDEX IF NOT EXISTS idx_request_log_endpoint_started_at
246
- ON request_log(upstream_endpoint, started_at_ms DESC);
247
- CREATE INDEX IF NOT EXISTS idx_request_log_status_started_at
248
- ON request_log(http_status, started_at_ms DESC);
237
+ CREATE INDEX IF NOT EXISTS idx_request_log_started_at
238
+ ON request_log(started_at_ms DESC);
239
+ CREATE INDEX IF NOT EXISTS idx_request_log_account_started_at
240
+ ON request_log(account_id, started_at_ms DESC);
241
+ CREATE INDEX IF NOT EXISTS idx_request_log_model_started_at
242
+ ON request_log(upstream_model, started_at_ms DESC);
243
+ CREATE INDEX IF NOT EXISTS idx_request_log_endpoint_started_at
244
+ ON request_log(upstream_endpoint, started_at_ms DESC);
245
+ CREATE INDEX IF NOT EXISTS idx_request_log_status_started_at
246
+ ON request_log(http_status, started_at_ms DESC);
249
247
 
250
- PRAGMA user_version = 1;
251
- `);
248
+ PRAGMA user_version = 1;
249
+ `);
250
+ }
251
+ function migrateAdminDb(db) {
252
+ const current = db.query("PRAGMA user_version;").get()?.user_version ?? 0;
253
+ if (current >= 5) return;
254
+ if (current < 1) migrateV1(db);
252
255
  if (current < 2) db.run(`
253
256
  ALTER TABLE request_log ADD COLUMN user_id TEXT;
254
257
  ALTER TABLE request_log ADD COLUMN safety_identifier TEXT;
@@ -283,6 +286,12 @@ function migrateAdminDb(db) {
283
286
 
284
287
  PRAGMA user_version = 4;
285
288
  `);
289
+ if (current < 5) db.run(`
290
+ ALTER TABLE request_log ADD COLUMN affinity_hit INTEGER;
291
+ ALTER TABLE request_log ADD COLUMN affinity_cache_key TEXT;
292
+
293
+ PRAGMA user_version = 5;
294
+ `);
286
295
  }
287
296
 
288
297
  //#endregion
@@ -434,13 +443,15 @@ var RequestHistoryStore = class {
434
443
  error_name,
435
444
  error_status,
436
445
  error_message,
437
- selection_failure_reason
446
+ selection_failure_reason,
447
+ affinity_hit,
448
+ affinity_cache_key
438
449
  ) VALUES (
439
450
  ?,?,?,?,?,?,?,?,
440
451
  ?,?,?,?,?,?,?,?,
441
452
  ?,?,?,?,?,?,?,?,
442
453
  ?,?,?,?,?,?,?,?,
443
- ?,?,?,?,?
454
+ ?,?,?,?,?,?,?
444
455
  );
445
456
  `);
446
457
  this.getByRequestIdStmt = db.query("SELECT * FROM request_log WHERE request_id = ? LIMIT 1;");
@@ -499,7 +510,9 @@ var RequestHistoryStore = class {
499
510
  toDbNull(record.errorName),
500
511
  toDbNull(record.errorStatus),
501
512
  toDbNull(record.errorMessage),
502
- toDbNull(record.selectionFailureReason)
513
+ toDbNull(record.selectionFailureReason),
514
+ toDbBool(record.affinityHit),
515
+ toDbNull(record.affinityCacheKey)
503
516
  ];
504
517
  this.insertStmt.run(...args);
505
518
  } catch (error) {
@@ -763,7 +776,7 @@ const CONFIG_KEYS = new Set([
763
776
  "auth",
764
777
  "extraPrompts",
765
778
  "smallModel",
766
- "freeModelLoadBalancing",
779
+ "accountAffinity",
767
780
  "apiKey",
768
781
  "anthropicApiKey",
769
782
  "providers",
@@ -776,7 +789,8 @@ const CONFIG_KEYS = new Set([
776
789
  "compactUseSmallModel",
777
790
  "messageStartInputTokensFallback",
778
791
  "modelRefreshIntervalHours",
779
- "useMessagesApi"
792
+ "useMessagesApi",
793
+ "useResponsesApiWebSearch"
780
794
  ]);
781
795
  const REASONING_EFFORTS = new Set([
782
796
  "none",
@@ -1124,7 +1138,7 @@ const CONFIG_PATCH_HANDLERS = {
1124
1138
  auth: applyAuthConfig,
1125
1139
  extraPrompts: applyExtraPrompts,
1126
1140
  smallModel: (next, value) => applyOptionalString(next, "smallModel", value),
1127
- freeModelLoadBalancing: (next, value) => applyOptionalBoolean(next, "freeModelLoadBalancing", value),
1141
+ accountAffinity: (next, value) => applyOptionalBoolean(next, "accountAffinity", value),
1128
1142
  apiKey: (next, value) => applyOptionalString(next, "apiKey", value),
1129
1143
  anthropicApiKey: (next, value) => applyOptionalString(next, "anthropicApiKey", value),
1130
1144
  providers: applyProvidersConfig,
@@ -1137,7 +1151,8 @@ const CONFIG_PATCH_HANDLERS = {
1137
1151
  compactUseSmallModel: (next, value) => applyOptionalBoolean(next, "compactUseSmallModel", value),
1138
1152
  messageStartInputTokensFallback: (next, value) => applyOptionalBoolean(next, "messageStartInputTokensFallback", value),
1139
1153
  modelRefreshIntervalHours: (next, value) => applyOptionalNumber(next, "modelRefreshIntervalHours", value),
1140
- useMessagesApi: (next, value) => applyOptionalBoolean(next, "useMessagesApi", value)
1154
+ useMessagesApi: (next, value) => applyOptionalBoolean(next, "useMessagesApi", value),
1155
+ useResponsesApiWebSearch: (next, value) => applyOptionalBoolean(next, "useResponsesApiWebSearch", value)
1141
1156
  };
1142
1157
  function applyConfigPatch(base, input) {
1143
1158
  const next = { ...base };
@@ -1215,7 +1230,7 @@ adminApiRoutes.post("/config", async (c) => {
1215
1230
  try {
1216
1231
  await writeConfigFile(result.config);
1217
1232
  const merged = mergeConfigWithDefaults();
1218
- accountsManager.setFreeModelLoadBalancingEnabled(isFreeModelLoadBalancingEnabled());
1233
+ accountsManager.setAccountAffinityEnabled(isAccountAffinityEnabled());
1219
1234
  accountsManager.setModelsRefreshIntervalMs(getModelRefreshIntervalMs());
1220
1235
  return c.json({
1221
1236
  ...merged,
@@ -2520,7 +2535,10 @@ async function handleCompletion$1(c) {
2520
2535
  const selection = await accountsManager.selectAccountForRequest([{
2521
2536
  modelId: clientModel,
2522
2537
  endpoint: CHAT_COMPLETIONS_ENDPOINT$1
2523
- }]);
2538
+ }], {
2539
+ promptCacheKey: normalizedPromptCacheKey,
2540
+ safetyIdentifier: normalizedSafetyIdentifier
2541
+ });
2524
2542
  if (!selection.ok) {
2525
2543
  recordSelectionFailure$2(store, {
2526
2544
  request,
@@ -2534,6 +2552,8 @@ async function handleCompletion$1(c) {
2534
2552
  });
2535
2553
  }
2536
2554
  const { account, selectedModel } = selection;
2555
+ request.affinityHit = selection.affinityHit;
2556
+ request.affinityCacheKey = selection.affinityCacheKey;
2537
2557
  const upstreamPayload = {
2538
2558
  ...payload,
2539
2559
  model: selectedModel.id
@@ -2605,6 +2625,8 @@ function insertRequestLog$2(store, request, record) {
2605
2625
  promptCacheKey: request.promptCacheKey,
2606
2626
  initiator: request.initiator,
2607
2627
  upstreamRequestId: request.upstreamRequestId,
2628
+ affinityHit: request.affinityHit,
2629
+ affinityCacheKey: request.affinityCacheKey,
2608
2630
  ...record
2609
2631
  });
2610
2632
  }
@@ -2657,6 +2679,7 @@ async function handleStreamingRequest(params) {
2657
2679
  upstreamRequestId: request.upstreamRequestId,
2658
2680
  sessionId: request.upstreamSessionId
2659
2681
  });
2682
+ selection.confirmAffinity?.();
2660
2683
  } catch (error) {
2661
2684
  return handleUpstreamCreateError$1({
2662
2685
  store,
@@ -2844,6 +2867,7 @@ async function handleNonStreamingRequest(params) {
2844
2867
  upstreamRequestId: request.upstreamRequestId,
2845
2868
  sessionId: request.upstreamSessionId
2846
2869
  });
2870
+ selection.confirmAffinity?.();
2847
2871
  finishedAtMs = Date.now();
2848
2872
  if (!isNonStreaming$1(response)) {
2849
2873
  logger$6.debug("Unexpected streaming response");
@@ -3239,6 +3263,21 @@ const maybeBlockOriginalModelName = (context) => {
3239
3263
  }
3240
3264
  });
3241
3265
  };
3266
+ const compactSystemPromptStart = "You are a helpful AI assistant tasked with summarizing conversations";
3267
+ const compactUserMessageStart = "CRITICAL: Respond with TEXT ONLY. Do NOT call any tools.";
3268
+ const hasCompactUserMessage = (messages) => {
3269
+ const lastMsg = messages.at(-1);
3270
+ if (!lastMsg || lastMsg.role !== "user") return false;
3271
+ if (typeof lastMsg.content === "string") return lastMsg.content.startsWith(compactUserMessageStart);
3272
+ if (!Array.isArray(lastMsg.content)) return false;
3273
+ return lastMsg.content.some((block) => block.type === "text" && typeof block.text === "string" && block.text.startsWith(compactUserMessageStart));
3274
+ };
3275
+ const isCompactRequest = (anthropicPayload) => {
3276
+ const system = anthropicPayload.system;
3277
+ if (typeof system === "string" && system.startsWith(compactSystemPromptStart)) return true;
3278
+ if (Array.isArray(system) && system.some((msg) => typeof msg.text === "string" && msg.text.startsWith(compactSystemPromptStart))) return true;
3279
+ return hasCompactUserMessage(anthropicPayload.messages);
3280
+ };
3242
3281
 
3243
3282
  //#endregion
3244
3283
  //#region src/routes/messages/non-stream-translation.ts
@@ -4482,7 +4521,15 @@ const containsVisionContent = (value) => {
4482
4521
 
4483
4522
  //#endregion
4484
4523
  //#region src/services/copilot/create-messages.ts
4524
+ const isAgentMessage = (msg) => {
4525
+ if (msg.role === "assistant") return true;
4526
+ if (Array.isArray(msg.content)) {
4527
+ if (msg.content.every((block) => block.type === "tool_result") && msg.content.length > 0) return true;
4528
+ }
4529
+ return false;
4530
+ };
4485
4531
  const getMessagesInitiator = (payload) => {
4532
+ if (isForceAgentEnabled()) return payload.messages.some((msg) => isAgentMessage(msg)) ? "agent" : "user";
4486
4533
  const lastMessage = payload.messages.at(-1);
4487
4534
  if (!lastMessage || lastMessage.role !== "user") return "agent";
4488
4535
  if (!Array.isArray(lastMessage.content)) return "user";
@@ -4839,7 +4886,6 @@ const logger$5 = createHandlerLogger("messages-handler");
4839
4886
  const CHAT_COMPLETIONS_ENDPOINT = "/chat/completions";
4840
4887
  const RESPONSES_ENDPOINT$1 = "/responses";
4841
4888
  const MESSAGES_ENDPOINT = "/v1/messages";
4842
- const compactSystemPromptStart = "You are a helpful AI assistant tasked with summarizing conversations";
4843
4889
  async function handleCompletion(c) {
4844
4890
  await checkRateLimit(state);
4845
4891
  const store = getRequestHistoryStore();
@@ -4907,7 +4953,11 @@ async function handleCompletion(c) {
4907
4953
  modelId: endpointModel?.id ?? openAIPayload.model,
4908
4954
  endpoint: CHAT_COMPLETIONS_ENDPOINT
4909
4955
  });
4910
- const selection = await accountsManager.selectAccountForRequest(candidates);
4956
+ const selection = await accountsManager.selectAccountForRequest(candidates, {
4957
+ promptCacheKey: normalizedPromptCacheKey,
4958
+ sessionId,
4959
+ safetyIdentifier: normalizedSafetyIdentifier
4960
+ });
4911
4961
  if (!selection.ok) return handleSelectionFailure({
4912
4962
  c,
4913
4963
  store,
@@ -4952,7 +5002,10 @@ async function handleCompletion(c) {
4952
5002
  costUnits,
4953
5003
  upstreamRequestId,
4954
5004
  premiumRemainingBefore,
4955
- premiumUnlimitedBefore
5005
+ premiumUnlimitedBefore,
5006
+ confirmAffinity: selection.confirmAffinity,
5007
+ affinityHit: selection.affinityHit,
5008
+ affinityCacheKey: selection.affinityCacheKey
4956
5009
  };
4957
5010
  if (endpoint === MESSAGES_ENDPOINT) return await handleWithMessagesApi({
4958
5011
  c,
@@ -5002,6 +5055,7 @@ const handleWithChatCompletions = async (params) => {
5002
5055
  sessionId,
5003
5056
  isCompact
5004
5057
  });
5058
+ instr.confirmAffinity?.();
5005
5059
  } catch (error) {
5006
5060
  return await handleChatCompletionsCreateError({
5007
5061
  error,
@@ -5050,6 +5104,7 @@ const handleWithResponsesApi = async (params) => {
5050
5104
  sessionId,
5051
5105
  isCompact
5052
5106
  }, ctx);
5107
+ instr.confirmAffinity?.();
5053
5108
  } catch (error) {
5054
5109
  return await handleResponsesCreateError({
5055
5110
  error,
@@ -5095,6 +5150,8 @@ function insertRequestLog$1(instr, record) {
5095
5150
  promptCacheKey: instr.promptCacheKey,
5096
5151
  initiator: instr.initiator,
5097
5152
  upstreamRequestId: instr.upstreamRequestId,
5153
+ affinityHit: instr.affinityHit,
5154
+ affinityCacheKey: instr.affinityCacheKey,
5098
5155
  clientModel,
5099
5156
  upstreamEndpoint,
5100
5157
  accountId: account.id,
@@ -5526,6 +5583,7 @@ const handleWithMessagesApi = async (params) => {
5526
5583
  sessionId,
5527
5584
  isCompact
5528
5585
  });
5586
+ instr.confirmAffinity?.();
5529
5587
  } catch (error) {
5530
5588
  return await handleMessagesCreateError({
5531
5589
  error,
@@ -5555,12 +5613,6 @@ const getAnthropicEffortForModel = (model) => {
5555
5613
  if (reasoningEffort === "none" || reasoningEffort === "minimal") return "low";
5556
5614
  return reasoningEffort;
5557
5615
  };
5558
- const isCompactRequest = (anthropicPayload) => {
5559
- const system = anthropicPayload.system;
5560
- if (typeof system === "string") return system.startsWith(compactSystemPromptStart);
5561
- if (!Array.isArray(system)) return false;
5562
- return system.some((msg) => typeof msg.text === "string" && msg.text.startsWith(compactSystemPromptStart));
5563
- };
5564
5616
 
5565
5617
  //#endregion
5566
5618
  //#region src/routes/messages/route.ts
@@ -5896,7 +5948,7 @@ const handleResponses = async (c) => {
5896
5948
  const payload = await c.req.json();
5897
5949
  const clientModel = payload.model;
5898
5950
  logger$1.debug("Responses request payload:", JSON.stringify(payload));
5899
- removeWebSearchTool(payload);
5951
+ if (!isResponsesApiWebSearchEnabled()) removeWebSearchTool(payload);
5900
5952
  compactInputByLatestCompaction(payload);
5901
5953
  const streamRequested = Boolean(payload.stream);
5902
5954
  const { initiator: initialInitiator } = getResponsesRequestOptions(payload);
@@ -5923,7 +5975,10 @@ const handleResponses = async (c) => {
5923
5975
  const selection = await accountsManager.selectAccountForRequest([{
5924
5976
  modelId: clientModel,
5925
5977
  endpoint: RESPONSES_ENDPOINT
5926
- }]);
5978
+ }], {
5979
+ promptCacheKey: normalizedPromptCacheKey,
5980
+ safetyIdentifier: normalizedSafetyIdentifier
5981
+ });
5927
5982
  if (!selection.ok) {
5928
5983
  recordSelectionFailure(store, {
5929
5984
  request,
@@ -5934,6 +5989,8 @@ const handleResponses = async (c) => {
5934
5989
  return selectionFailureResponse(c, { reason: selection.reason });
5935
5990
  }
5936
5991
  const { account, selectedModel } = selection;
5992
+ request.affinityHit = selection.affinityHit;
5993
+ request.affinityCacheKey = selection.affinityCacheKey;
5937
5994
  const upstreamPayload = {
5938
5995
  ...payload,
5939
5996
  model: selectedModel.id
@@ -6009,6 +6066,8 @@ function insertRequestLog(store, request, record) {
6009
6066
  promptCacheKey: request.promptCacheKey,
6010
6067
  initiator: request.initiator,
6011
6068
  upstreamRequestId: request.upstreamRequestId,
6069
+ affinityHit: request.affinityHit,
6070
+ affinityCacheKey: request.affinityCacheKey,
6012
6071
  ...record
6013
6072
  });
6014
6073
  }
@@ -6064,6 +6123,7 @@ async function handleStreamingResponses(params) {
6064
6123
  upstreamRequestId: request.upstreamRequestId,
6065
6124
  sessionId: request.upstreamSessionId
6066
6125
  }, accountCtx);
6126
+ selection.confirmAffinity?.();
6067
6127
  } catch (error) {
6068
6128
  return handleUpstreamCreateError({
6069
6129
  store,
@@ -6250,6 +6310,7 @@ async function handleNonStreamingResponses(params) {
6250
6310
  upstreamRequestId: request.upstreamRequestId,
6251
6311
  sessionId: request.upstreamSessionId
6252
6312
  }, accountCtx);
6313
+ selection.confirmAffinity?.();
6253
6314
  finishedAtMs = Date.now();
6254
6315
  const streamResponse = handleUnexpectedResponsesStream(c, response);
6255
6316
  if (streamResponse) return streamResponse;
@@ -6434,4 +6495,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
6434
6495
 
6435
6496
  //#endregion
6436
6497
  export { server };
6437
- //# sourceMappingURL=server-BKsjCvqp.js.map
6498
+ //# sourceMappingURL=server-Cln-GCLU.js.map