@anuma/sdk 6.15.0 → 6.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  notifyConsolidationFallback,
3
3
  resolvePiiRedactor
4
- } from "./chunk-DIUQLXEH.mjs";
4
+ } from "./chunk-7X7BNMGS.mjs";
5
5
  import {
6
6
  callPortalJsonCompletion
7
- } from "./chunk-3V3BBJLH.mjs";
7
+ } from "./chunk-4Z2X4UYQ.mjs";
8
8
  import "./chunk-GYKJOWEO.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts
@@ -6429,6 +6429,9 @@ function supportsResponseFormat(model, variant = "json_object") {
6429
6429
  const allow = variant === "json_schema" ? RESPONSE_SCHEMA_OK : RESPONSE_FORMAT_OK;
6430
6430
  return model.split("/").some((seg) => allow.has(seg));
6431
6431
  }
6432
+ function requiresResponsesTransport(model) {
6433
+ return model.split("/").some((seg) => RESPONSES_ONLY_MODEL_PREFIXES.some((prefix) => seg.startsWith(prefix)));
6434
+ }
6432
6435
  function responsesExtra(extra) {
6433
6436
  if (!extra) return {};
6434
6437
  const out = {};
@@ -6764,7 +6767,7 @@ function extractResponsesContent(body) {
6764
6767
  const text12 = root.output.filter((item) => asRecord(item)?.type === "message").flatMap((item) => Array.isArray(item.content) ? item.content : []).map((part) => asRecord(part)?.text).filter((t) => typeof t === "string").join("");
6765
6768
  return text12;
6766
6769
  }
6767
- var RESPONSE_FORMAT_OK, RESPONSE_SCHEMA_OK, JSON_CONTRACT_REMINDER, CHAT_TO_RESPONSES_FIELDS, FOREIGN_ENDPOINT_SUFFIX, RETRYABLE_HTTP;
6770
+ var RESPONSE_FORMAT_OK, RESPONSE_SCHEMA_OK, JSON_CONTRACT_REMINDER, RESPONSES_ONLY_MODEL_PREFIXES, CHAT_TO_RESPONSES_FIELDS, FOREIGN_ENDPOINT_SUFFIX, RETRYABLE_HTTP;
6768
6771
  var init_portalLlm = __esm({
6769
6772
  "src/lib/memory/portalLlm.ts"() {
6770
6773
  "use strict";
@@ -6776,6 +6779,7 @@ var init_portalLlm = __esm({
6776
6779
  RESPONSE_FORMAT_OK = /* @__PURE__ */ new Set(["openai", "inclusionai", "deepseek"]);
6777
6780
  RESPONSE_SCHEMA_OK = /* @__PURE__ */ new Set(["openai"]);
6778
6781
  JSON_CONTRACT_REMINDER = "Output ONLY the strict JSON object requested. No prose, no explanation, no markdown.";
6782
+ RESPONSES_ONLY_MODEL_PREFIXES = ["gpt-5.6"];
6779
6783
  CHAT_TO_RESPONSES_FIELDS = {
6780
6784
  max_completion_tokens: "max_output_tokens"
6781
6785
  };
@@ -19115,6 +19119,9 @@ var DEFAULT_BASE_URL2 = BASE_URL;
19115
19119
  var DEFAULT_MODEL4 = "anthropic/claude-sonnet-4-6";
19116
19120
  var DEFAULT_MAX_TOKENS = 4096;
19117
19121
  var REQUEST_TIMEOUT_MS = 6e4;
19122
+ var MIN_RETRY_BUDGET_MS = 2e3;
19123
+ var MIN_RESPONSES_OUTPUT_TOKENS = 2048;
19124
+ var SCHEMA_FALLBACK_SKIP_STATUSES = /* @__PURE__ */ new Set([401, 403, 404, 408, 409, 413, 425, 429]);
19118
19125
  var DEFAULT_SYSTEM_PROMPT = `You are a personal assistant with access to the user's memory. Answer the user's question using the supplied memories as evidence.
19119
19126
 
19120
19127
  Rules:
@@ -19146,14 +19153,9 @@ ${m.content}`).join("\n\n");
19146
19153
  const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL2;
19147
19154
  const model = options.llmModel ?? DEFAULT_MODEL4;
19148
19155
  const wantsStructured = !!options.responseSchema;
19149
- const sendResponseFormat = wantsStructured && supportsResponseFormat(model, "json_schema");
19156
+ const useResponsesTransport = requiresResponsesTransport(model);
19157
+ const sendResponseFormat = wantsStructured && !useResponsesTransport && supportsResponseFormat(model, "json_schema");
19150
19158
  const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
19151
- const systemPrompt = wantsStructured && !sendResponseFormat ? `${basePrompt}
19152
-
19153
- Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
19154
- ${JSON.stringify(
19155
- options.responseSchema
19156
- )}` : basePrompt;
19157
19159
  const userMessage = [
19158
19160
  `Question:
19159
19161
  ${trimmed}`,
@@ -19163,85 +19165,121 @@ ${evidence}`
19163
19165
  ].join("\n\n");
19164
19166
  const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
19165
19167
  const fetchImpl = options.fetchFn ?? fetch;
19168
+ const buildBody = (useResponseFormat) => {
19169
+ const systemPrompt = wantsStructured && !useResponseFormat ? `${basePrompt}
19170
+
19171
+ Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
19172
+ ${JSON.stringify(
19173
+ options.responseSchema
19174
+ )}` : basePrompt;
19175
+ const messages = [
19176
+ { role: "system", content: systemPrompt },
19177
+ { role: "user", content: userMessage }
19178
+ ];
19179
+ if (useResponsesTransport) {
19180
+ return JSON.stringify({
19181
+ model,
19182
+ // Same system+user pair under the Responses-API field names: `input`
19183
+ // for the turns, `max_output_tokens` for the cap. Sending the
19184
+ // chat-completions spelling here is silently ignored, which caps the
19185
+ // answer at the portal default.
19186
+ input: messages,
19187
+ max_output_tokens: Math.max(maxTokens, MIN_RESPONSES_OUTPUT_TOKENS)
19188
+ });
19189
+ }
19190
+ return JSON.stringify({
19191
+ model,
19192
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
19193
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
19194
+ // portal's default output cap and truncates the answer).
19195
+ max_completion_tokens: maxTokens,
19196
+ messages,
19197
+ ...useResponseFormat && {
19198
+ response_format: {
19199
+ type: "json_schema",
19200
+ json_schema: { name: "reflect_output", schema: options.responseSchema }
19201
+ }
19202
+ }
19203
+ });
19204
+ };
19166
19205
  const log = getLogger();
19167
19206
  const authHeaders = await resolvePortalAuthHeaders(options, "memory/reflect");
19168
19207
  if (authHeaders === null) return baseResult;
19169
- const controller = new AbortController();
19170
19208
  const deadline = Date.now() + REQUEST_TIMEOUT_MS;
19171
19209
  const remaining = () => Math.max(0, deadline - Date.now());
19172
- const timer = setTimeout(() => controller.abort(), remaining());
19173
- let response;
19174
- try {
19175
- response = await fetchImpl(`${baseUrl}/api/v1/chat/completions`, {
19176
- method: "POST",
19177
- // No task type unless the caller named one — an undeclared task adds no
19178
- // header at all, which is what keeps user-facing reflect() unlabelled.
19179
- headers: {
19180
- ...authHeaders,
19181
- ...taskTypeHeader(options.taskType),
19182
- "Content-Type": "application/json"
19183
- },
19184
- body: JSON.stringify({
19185
- model,
19186
- // Modern OpenAI field; the portal reads only `max_completion_tokens`
19187
- // (the deprecated `max_tokens` is silently ignored → falls back to the
19188
- // portal's default output cap and truncates the answer).
19189
- max_completion_tokens: maxTokens,
19190
- messages: [
19191
- { role: "system", content: systemPrompt },
19192
- { role: "user", content: userMessage }
19193
- ],
19194
- ...sendResponseFormat && {
19195
- response_format: {
19196
- type: "json_schema",
19197
- json_schema: { name: "reflect_output", schema: options.responseSchema }
19198
- }
19199
- }
19200
- }),
19201
- signal: controller.signal
19202
- });
19203
- } catch (err) {
19210
+ const endpoint = useResponsesTransport ? "/api/v1/responses" : "/api/v1/chat/completions";
19211
+ const sendOnce = async (useResponseFormat) => {
19212
+ const controller = new AbortController();
19213
+ const timer = setTimeout(() => controller.abort(), remaining());
19214
+ let response;
19215
+ try {
19216
+ response = await fetchImpl(`${baseUrl}${endpoint}`, {
19217
+ method: "POST",
19218
+ // No task type unless the caller named one — an undeclared task adds no
19219
+ // header at all, which is what keeps user-facing reflect() unlabelled.
19220
+ headers: {
19221
+ ...authHeaders,
19222
+ ...taskTypeHeader(options.taskType),
19223
+ "Content-Type": "application/json"
19224
+ },
19225
+ body: buildBody(useResponseFormat),
19226
+ signal: controller.signal
19227
+ });
19228
+ } catch (err) {
19229
+ clearTimeout(timer);
19230
+ log.warn("[memory/reflect] portal request failed", {
19231
+ err: err instanceof Error ? err.message : String(err),
19232
+ baseUrl
19233
+ });
19234
+ return { kind: "error" };
19235
+ }
19204
19236
  clearTimeout(timer);
19205
- log.warn("[memory/reflect] portal request failed", {
19206
- err: err instanceof Error ? err.message : String(err),
19207
- baseUrl
19237
+ if (!response.ok) {
19238
+ return { kind: "http", status: response.status, statusText: response.statusText };
19239
+ }
19240
+ const bodyTimer = setTimeout(() => controller.abort(), remaining());
19241
+ try {
19242
+ const body = await response.json();
19243
+ clearTimeout(bodyTimer);
19244
+ return { kind: "ok", body };
19245
+ } catch (err) {
19246
+ clearTimeout(bodyTimer);
19247
+ log.warn("[memory/reflect] failed to parse portal response body", {
19248
+ err: err instanceof Error ? err.message : String(err)
19249
+ });
19250
+ return { kind: "error" };
19251
+ }
19252
+ };
19253
+ let attempt = await sendOnce(sendResponseFormat);
19254
+ let schemaFallbackUsed = false;
19255
+ const budgetLeftMs = remaining();
19256
+ if (attempt.kind === "http" && sendResponseFormat && !SCHEMA_FALLBACK_SKIP_STATUSES.has(attempt.status) && budgetLeftMs >= MIN_RETRY_BUDGET_MS) {
19257
+ log.warn("[memory/reflect] response_format json_schema rejected; retrying schema-in-prompt", {
19258
+ status: attempt.status,
19259
+ statusText: attempt.statusText,
19260
+ model,
19261
+ taskType: options.taskType,
19262
+ budgetLeftMs
19208
19263
  });
19209
- return baseResult;
19264
+ schemaFallbackUsed = true;
19265
+ attempt = await sendOnce(false);
19210
19266
  }
19211
- clearTimeout(timer);
19212
- if (!response.ok) {
19267
+ if (attempt.kind === "error") return baseResult;
19268
+ if (attempt.kind === "http") {
19213
19269
  log.warn("[memory/reflect] portal returned non-OK", {
19214
- status: response.status,
19215
- statusText: response.statusText
19216
- });
19217
- return baseResult;
19218
- }
19219
- const bodyTimer = setTimeout(() => controller.abort(), remaining());
19220
- let body;
19221
- try {
19222
- body = await response.json();
19223
- } catch (err) {
19224
- clearTimeout(bodyTimer);
19225
- log.warn("[memory/reflect] failed to parse portal response body", {
19226
- err: err instanceof Error ? err.message : String(err)
19270
+ status: attempt.status,
19271
+ statusText: attempt.statusText,
19272
+ // Distinguishes "the fallback ran and still failed" from "never tried".
19273
+ schemaFallbackUsed
19227
19274
  });
19228
19275
  return baseResult;
19229
19276
  }
19230
- clearTimeout(bodyTimer);
19231
- return parseAnswer(body, baseResult, !!options.responseSchema);
19277
+ return parseAnswer(attempt.body, baseResult, !!options.responseSchema);
19232
19278
  }
19233
19279
  function parseAnswer(body, base, parseSchema) {
19234
19280
  if (typeof body !== "object" || body === null) return base;
19235
19281
  const obj = body;
19236
- const choices = obj.choices;
19237
- let text12 = "";
19238
- if (Array.isArray(choices) && choices.length > 0) {
19239
- const message = choices[0].message;
19240
- if (typeof message === "object" && message !== null) {
19241
- const content = message.content;
19242
- if (typeof content === "string") text12 = content;
19243
- }
19244
- }
19282
+ const text12 = extractCompletionContent(obj) ?? "";
19245
19283
  const usage = obj.usage;
19246
19284
  let structuredOutput;
19247
19285
  if (parseSchema && text12) {
@@ -19253,14 +19291,19 @@ function parseAnswer(body, base, parseSchema) {
19253
19291
  });
19254
19292
  }
19255
19293
  }
19294
+ const promptTokens = usage?.prompt_tokens ?? usage?.input_tokens ?? 0;
19295
+ const completionTokens = usage?.completion_tokens ?? usage?.output_tokens ?? 0;
19256
19296
  return {
19257
19297
  text: text12,
19258
19298
  ...structuredOutput !== void 0 && { structuredOutput },
19259
19299
  basedOn: base.basedOn,
19260
19300
  usage: {
19261
- promptTokens: usage?.prompt_tokens ?? 0,
19262
- completionTokens: usage?.completion_tokens ?? 0,
19263
- totalTokens: usage?.total_tokens ?? 0
19301
+ promptTokens,
19302
+ completionTokens,
19303
+ // Derived when absent: the Responses API reports the two component counts
19304
+ // and does not always send a total, which would otherwise report zero
19305
+ // spend for a call that plainly cost something.
19306
+ totalTokens: usage?.total_tokens ?? promptTokens + completionTokens
19264
19307
  }
19265
19308
  };
19266
19309
  }
@@ -178,28 +178,30 @@ import {
178
178
  updateVaultMemoryOp,
179
179
  useEncryption,
180
180
  vaultMemoryToStored
181
- } from "./chunk-PDKKPAXP.mjs";
181
+ } from "./chunk-YSL3J4K4.mjs";
182
182
  import {
183
183
  PiiRedactor,
184
184
  createStreamingDeAnonymizer,
185
185
  isPiiRedactor,
186
186
  notifyConsolidationFallback,
187
187
  resolvePiiRedactor
188
- } from "./chunk-2GNOTRG4.mjs";
188
+ } from "./chunk-7X7BNMGS.mjs";
189
189
  import {
190
190
  INTERNAL_FLOW_MARKER,
191
191
  callPortalJsonCompletion,
192
192
  consoleLogger,
193
+ extractCompletionContent,
193
194
  extractJsonCandidate,
194
195
  getLogger,
195
196
  noopLogger,
197
+ requiresResponsesTransport,
196
198
  resolvePortalAuthHeaders,
197
199
  setLogger,
198
200
  supportsResponseFormat,
199
201
  taskTypeHeader,
200
202
  validateEndpointOverride,
201
203
  withInternalFlowMarker
202
- } from "./chunk-3V3BBJLH.mjs";
204
+ } from "./chunk-4Z2X4UYQ.mjs";
203
205
  import {
204
206
  BASE_URL,
205
207
  MCP_R2_DOMAIN,
@@ -7686,7 +7688,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
7686
7688
  content: m.content,
7687
7689
  similarity: m.similarity
7688
7690
  }));
7689
- const { consolidateMemory: doConsolidate } = await import("./consolidate-Y2XWEZRQ.mjs");
7691
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-7NMKF7UC.mjs");
7690
7692
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
7691
7693
  if (decision.action === "create") return null;
7692
7694
  if (decision.action === "supersede" && decision.content) {
@@ -8910,6 +8912,9 @@ var DEFAULT_BASE_URL = BASE_URL;
8910
8912
  var DEFAULT_MODEL3 = "anthropic/claude-sonnet-4-6";
8911
8913
  var DEFAULT_MAX_TOKENS = 4096;
8912
8914
  var REQUEST_TIMEOUT_MS = 6e4;
8915
+ var MIN_RETRY_BUDGET_MS = 2e3;
8916
+ var MIN_RESPONSES_OUTPUT_TOKENS = 2048;
8917
+ var SCHEMA_FALLBACK_SKIP_STATUSES = /* @__PURE__ */ new Set([401, 403, 404, 408, 409, 413, 425, 429]);
8913
8918
  var DEFAULT_SYSTEM_PROMPT = `You are a personal assistant with access to the user's memory. Answer the user's question using the supplied memories as evidence.
8914
8919
 
8915
8920
  Rules:
@@ -8941,14 +8946,9 @@ ${m.content}`).join("\n\n");
8941
8946
  const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
8942
8947
  const model = options.llmModel ?? DEFAULT_MODEL3;
8943
8948
  const wantsStructured = !!options.responseSchema;
8944
- const sendResponseFormat = wantsStructured && supportsResponseFormat(model, "json_schema");
8949
+ const useResponsesTransport = requiresResponsesTransport(model);
8950
+ const sendResponseFormat = wantsStructured && !useResponsesTransport && supportsResponseFormat(model, "json_schema");
8945
8951
  const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
8946
- const systemPrompt = wantsStructured && !sendResponseFormat ? `${basePrompt}
8947
-
8948
- Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
8949
- ${JSON.stringify(
8950
- options.responseSchema
8951
- )}` : basePrompt;
8952
8952
  const userMessage = [
8953
8953
  `Question:
8954
8954
  ${trimmed}`,
@@ -8958,85 +8958,121 @@ ${evidence}`
8958
8958
  ].join("\n\n");
8959
8959
  const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
8960
8960
  const fetchImpl = options.fetchFn ?? fetch;
8961
+ const buildBody = (useResponseFormat) => {
8962
+ const systemPrompt = wantsStructured && !useResponseFormat ? `${basePrompt}
8963
+
8964
+ Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
8965
+ ${JSON.stringify(
8966
+ options.responseSchema
8967
+ )}` : basePrompt;
8968
+ const messages = [
8969
+ { role: "system", content: systemPrompt },
8970
+ { role: "user", content: userMessage }
8971
+ ];
8972
+ if (useResponsesTransport) {
8973
+ return JSON.stringify({
8974
+ model,
8975
+ // Same system+user pair under the Responses-API field names: `input`
8976
+ // for the turns, `max_output_tokens` for the cap. Sending the
8977
+ // chat-completions spelling here is silently ignored, which caps the
8978
+ // answer at the portal default.
8979
+ input: messages,
8980
+ max_output_tokens: Math.max(maxTokens, MIN_RESPONSES_OUTPUT_TOKENS)
8981
+ });
8982
+ }
8983
+ return JSON.stringify({
8984
+ model,
8985
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
8986
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
8987
+ // portal's default output cap and truncates the answer).
8988
+ max_completion_tokens: maxTokens,
8989
+ messages,
8990
+ ...useResponseFormat && {
8991
+ response_format: {
8992
+ type: "json_schema",
8993
+ json_schema: { name: "reflect_output", schema: options.responseSchema }
8994
+ }
8995
+ }
8996
+ });
8997
+ };
8961
8998
  const log = getLogger();
8962
8999
  const authHeaders = await resolvePortalAuthHeaders(options, "memory/reflect");
8963
9000
  if (authHeaders === null) return baseResult;
8964
- const controller = new AbortController();
8965
9001
  const deadline = Date.now() + REQUEST_TIMEOUT_MS;
8966
9002
  const remaining = () => Math.max(0, deadline - Date.now());
8967
- const timer = setTimeout(() => controller.abort(), remaining());
8968
- let response;
8969
- try {
8970
- response = await fetchImpl(`${baseUrl}/api/v1/chat/completions`, {
8971
- method: "POST",
8972
- // No task type unless the caller named one — an undeclared task adds no
8973
- // header at all, which is what keeps user-facing reflect() unlabelled.
8974
- headers: {
8975
- ...authHeaders,
8976
- ...taskTypeHeader(options.taskType),
8977
- "Content-Type": "application/json"
8978
- },
8979
- body: JSON.stringify({
8980
- model,
8981
- // Modern OpenAI field; the portal reads only `max_completion_tokens`
8982
- // (the deprecated `max_tokens` is silently ignored → falls back to the
8983
- // portal's default output cap and truncates the answer).
8984
- max_completion_tokens: maxTokens,
8985
- messages: [
8986
- { role: "system", content: systemPrompt },
8987
- { role: "user", content: userMessage }
8988
- ],
8989
- ...sendResponseFormat && {
8990
- response_format: {
8991
- type: "json_schema",
8992
- json_schema: { name: "reflect_output", schema: options.responseSchema }
8993
- }
8994
- }
8995
- }),
8996
- signal: controller.signal
8997
- });
8998
- } catch (err) {
9003
+ const endpoint = useResponsesTransport ? "/api/v1/responses" : "/api/v1/chat/completions";
9004
+ const sendOnce = async (useResponseFormat) => {
9005
+ const controller = new AbortController();
9006
+ const timer = setTimeout(() => controller.abort(), remaining());
9007
+ let response;
9008
+ try {
9009
+ response = await fetchImpl(`${baseUrl}${endpoint}`, {
9010
+ method: "POST",
9011
+ // No task type unless the caller named one — an undeclared task adds no
9012
+ // header at all, which is what keeps user-facing reflect() unlabelled.
9013
+ headers: {
9014
+ ...authHeaders,
9015
+ ...taskTypeHeader(options.taskType),
9016
+ "Content-Type": "application/json"
9017
+ },
9018
+ body: buildBody(useResponseFormat),
9019
+ signal: controller.signal
9020
+ });
9021
+ } catch (err) {
9022
+ clearTimeout(timer);
9023
+ log.warn("[memory/reflect] portal request failed", {
9024
+ err: err instanceof Error ? err.message : String(err),
9025
+ baseUrl
9026
+ });
9027
+ return { kind: "error" };
9028
+ }
8999
9029
  clearTimeout(timer);
9000
- log.warn("[memory/reflect] portal request failed", {
9001
- err: err instanceof Error ? err.message : String(err),
9002
- baseUrl
9030
+ if (!response.ok) {
9031
+ return { kind: "http", status: response.status, statusText: response.statusText };
9032
+ }
9033
+ const bodyTimer = setTimeout(() => controller.abort(), remaining());
9034
+ try {
9035
+ const body = await response.json();
9036
+ clearTimeout(bodyTimer);
9037
+ return { kind: "ok", body };
9038
+ } catch (err) {
9039
+ clearTimeout(bodyTimer);
9040
+ log.warn("[memory/reflect] failed to parse portal response body", {
9041
+ err: err instanceof Error ? err.message : String(err)
9042
+ });
9043
+ return { kind: "error" };
9044
+ }
9045
+ };
9046
+ let attempt = await sendOnce(sendResponseFormat);
9047
+ let schemaFallbackUsed = false;
9048
+ const budgetLeftMs = remaining();
9049
+ if (attempt.kind === "http" && sendResponseFormat && !SCHEMA_FALLBACK_SKIP_STATUSES.has(attempt.status) && budgetLeftMs >= MIN_RETRY_BUDGET_MS) {
9050
+ log.warn("[memory/reflect] response_format json_schema rejected; retrying schema-in-prompt", {
9051
+ status: attempt.status,
9052
+ statusText: attempt.statusText,
9053
+ model,
9054
+ taskType: options.taskType,
9055
+ budgetLeftMs
9003
9056
  });
9004
- return baseResult;
9057
+ schemaFallbackUsed = true;
9058
+ attempt = await sendOnce(false);
9005
9059
  }
9006
- clearTimeout(timer);
9007
- if (!response.ok) {
9060
+ if (attempt.kind === "error") return baseResult;
9061
+ if (attempt.kind === "http") {
9008
9062
  log.warn("[memory/reflect] portal returned non-OK", {
9009
- status: response.status,
9010
- statusText: response.statusText
9063
+ status: attempt.status,
9064
+ statusText: attempt.statusText,
9065
+ // Distinguishes "the fallback ran and still failed" from "never tried".
9066
+ schemaFallbackUsed
9011
9067
  });
9012
9068
  return baseResult;
9013
9069
  }
9014
- const bodyTimer = setTimeout(() => controller.abort(), remaining());
9015
- let body;
9016
- try {
9017
- body = await response.json();
9018
- } catch (err) {
9019
- clearTimeout(bodyTimer);
9020
- log.warn("[memory/reflect] failed to parse portal response body", {
9021
- err: err instanceof Error ? err.message : String(err)
9022
- });
9023
- return baseResult;
9024
- }
9025
- clearTimeout(bodyTimer);
9026
- return parseAnswer(body, baseResult, !!options.responseSchema);
9070
+ return parseAnswer(attempt.body, baseResult, !!options.responseSchema);
9027
9071
  }
9028
9072
  function parseAnswer(body, base, parseSchema) {
9029
9073
  if (typeof body !== "object" || body === null) return base;
9030
9074
  const obj = body;
9031
- const choices = obj.choices;
9032
- let text12 = "";
9033
- if (Array.isArray(choices) && choices.length > 0) {
9034
- const message = choices[0].message;
9035
- if (typeof message === "object" && message !== null) {
9036
- const content = message.content;
9037
- if (typeof content === "string") text12 = content;
9038
- }
9039
- }
9075
+ const text12 = extractCompletionContent(obj) ?? "";
9040
9076
  const usage = obj.usage;
9041
9077
  let structuredOutput;
9042
9078
  if (parseSchema && text12) {
@@ -9048,14 +9084,19 @@ function parseAnswer(body, base, parseSchema) {
9048
9084
  });
9049
9085
  }
9050
9086
  }
9087
+ const promptTokens = usage?.prompt_tokens ?? usage?.input_tokens ?? 0;
9088
+ const completionTokens = usage?.completion_tokens ?? usage?.output_tokens ?? 0;
9051
9089
  return {
9052
9090
  text: text12,
9053
9091
  ...structuredOutput !== void 0 && { structuredOutput },
9054
9092
  basedOn: base.basedOn,
9055
9093
  usage: {
9056
- promptTokens: usage?.prompt_tokens ?? 0,
9057
- completionTokens: usage?.completion_tokens ?? 0,
9058
- totalTokens: usage?.total_tokens ?? 0
9094
+ promptTokens,
9095
+ completionTokens,
9096
+ // Derived when absent: the Responses API reports the two component counts
9097
+ // and does not always send a total, which would otherwise report zero
9098
+ // spend for a call that plainly cost something.
9099
+ totalTokens: usage?.total_tokens ?? promptTokens + completionTokens
9059
9100
  }
9060
9101
  };
9061
9102
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-PDKKPAXP.mjs";
4
- import "./chunk-3V3BBJLH.mjs";
3
+ } from "./chunk-YSL3J4K4.mjs";
4
+ import "./chunk-4Z2X4UYQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
7
7
  recall
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getLogger
3
- } from "./chunk-H4G3DLDJ.mjs";
3
+ } from "./chunk-BSCEZOIW.mjs";
4
4
 
5
5
  // src/lib/pii/patterns.ts
6
6
  function luhnCheck(digits) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  callPortalJsonCompletion,
3
3
  getLogger
4
- } from "./chunk-H4G3DLDJ.mjs";
4
+ } from "./chunk-BSCEZOIW.mjs";
5
5
  import {
6
6
  BASE_URL,
7
7
  __commonJS,
@@ -20923,7 +20923,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
20923
20923
  subQueries = decomp.subQueries;
20924
20924
  }
20925
20925
  }
20926
- const { recall: recall2 } = await import("./recall-EODNEKIA.mjs");
20926
+ const { recall: recall2 } = await import("./recall-OVSSDRYU.mjs");
20927
20927
  let recallDegraded = [];
20928
20928
  const result = await recall2(
20929
20929
  query,
@@ -57,6 +57,10 @@ function supportsResponseFormat(model, variant = "json_object") {
57
57
  const allow = variant === "json_schema" ? RESPONSE_SCHEMA_OK : RESPONSE_FORMAT_OK;
58
58
  return model.split("/").some((seg) => allow.has(seg));
59
59
  }
60
+ var RESPONSES_ONLY_MODEL_PREFIXES = ["gpt-5.6"];
61
+ function requiresResponsesTransport(model) {
62
+ return model.split("/").some((seg) => RESPONSES_ONLY_MODEL_PREFIXES.some((prefix) => seg.startsWith(prefix)));
63
+ }
60
64
  var CHAT_TO_RESPONSES_FIELDS = {
61
65
  max_completion_tokens: "max_output_tokens"
62
66
  };
@@ -408,7 +412,9 @@ export {
408
412
  taskTypeHeader,
409
413
  validateEndpointOverride,
410
414
  supportsResponseFormat,
415
+ requiresResponsesTransport,
411
416
  resolvePortalAuthHeaders,
412
417
  callPortalJsonCompletion,
413
- extractJsonCandidate
418
+ extractJsonCandidate,
419
+ extractCompletionContent
414
420
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  notifyConsolidationFallback,
3
3
  resolvePiiRedactor
4
- } from "./chunk-JPLFOSB2.mjs";
4
+ } from "./chunk-4LPSEROP.mjs";
5
5
  import {
6
6
  callPortalJsonCompletion
7
- } from "./chunk-H4G3DLDJ.mjs";
7
+ } from "./chunk-BSCEZOIW.mjs";
8
8
  import "./chunk-3RPGXXPZ.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts