@anuma/sdk 6.14.2 → 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.
- package/dist/client/index.cjs +13 -0
- package/dist/client/index.d.mts +187 -1
- package/dist/client/index.d.ts +187 -1
- package/dist/client/index.mjs +11 -0
- package/dist/expo/{chunk-O25LUKBK.mjs → chunk-4Z2X4UYQ.mjs} +73 -9
- package/dist/expo/{chunk-M4JSLFTQ.mjs → chunk-A2G6TRUK.mjs} +1 -1
- package/dist/expo/{chunk-JA7CDJCA.mjs → chunk-TNMPAE3V.mjs} +2 -2
- package/dist/{react/consolidate-LSDBMQDW.mjs → expo/consolidate-ZM5JNULQ.mjs} +2 -2
- package/dist/expo/index.cjs +183 -82
- package/dist/expo/index.mjs +118 -77
- package/dist/expo/{recall-JYVHWU6N.mjs → recall-FJQTIMYT.mjs} +2 -2
- package/dist/react/{chunk-O25LUKBK.mjs → chunk-4Z2X4UYQ.mjs} +73 -9
- package/dist/react/{chunk-2XLHV2XW.mjs → chunk-7X7BNMGS.mjs} +1 -1
- package/dist/react/{chunk-DNSPMVBY.mjs → chunk-YSL3J4K4.mjs} +2 -2
- package/dist/{expo/consolidate-S3KFA2WT.mjs → react/consolidate-7NMKF7UC.mjs} +2 -2
- package/dist/react/index.cjs +183 -82
- package/dist/react/index.mjs +118 -77
- package/dist/react/{recall-2BWBJWGG.mjs → recall-UVVZGRVF.mjs} +2 -2
- package/dist/server/{chunk-GP6YY6H5.mjs → chunk-4LPSEROP.mjs} +1 -1
- package/dist/server/{chunk-O7TB36P3.mjs → chunk-ARYSRI4Z.mjs} +2 -2
- package/dist/server/{chunk-7D3RI25K.mjs → chunk-BSCEZOIW.mjs} +73 -9
- package/dist/server/{consolidate-Z2JJP7LW.mjs → consolidate-MSAXASHL.mjs} +2 -2
- package/dist/server/index.cjs +183 -82
- package/dist/server/index.mjs +118 -77
- package/dist/server/{recall-VHU372MK.mjs → recall-OVSSDRYU.mjs} +2 -2
- package/package.json +2 -2
package/dist/expo/index.mjs
CHANGED
|
@@ -132,7 +132,7 @@ import {
|
|
|
132
132
|
upsertMessageOp,
|
|
133
133
|
useEncryption,
|
|
134
134
|
vaultMemoryToStored
|
|
135
|
-
} from "./chunk-
|
|
135
|
+
} from "./chunk-TNMPAE3V.mjs";
|
|
136
136
|
import {
|
|
137
137
|
PII_PATTERNS,
|
|
138
138
|
PiiRedactor,
|
|
@@ -140,21 +140,23 @@ import {
|
|
|
140
140
|
isPiiRedactor,
|
|
141
141
|
notifyConsolidationFallback,
|
|
142
142
|
resolvePiiRedactor
|
|
143
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-A2G6TRUK.mjs";
|
|
144
144
|
import {
|
|
145
145
|
INTERNAL_FLOW_MARKER,
|
|
146
146
|
callPortalJsonCompletion,
|
|
147
147
|
consoleLogger,
|
|
148
|
+
extractCompletionContent,
|
|
148
149
|
extractJsonCandidate,
|
|
149
150
|
getLogger,
|
|
150
151
|
noopLogger,
|
|
152
|
+
requiresResponsesTransport,
|
|
151
153
|
resolvePortalAuthHeaders,
|
|
152
154
|
setLogger,
|
|
153
155
|
supportsResponseFormat,
|
|
154
156
|
taskTypeHeader,
|
|
155
157
|
validateEndpointOverride,
|
|
156
158
|
withInternalFlowMarker
|
|
157
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
158
160
|
import {
|
|
159
161
|
BASE_URL,
|
|
160
162
|
MCP_R2_DOMAIN,
|
|
@@ -6868,7 +6870,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
6868
6870
|
content: m.content,
|
|
6869
6871
|
similarity: m.similarity
|
|
6870
6872
|
}));
|
|
6871
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
6873
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-ZM5JNULQ.mjs");
|
|
6872
6874
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
6873
6875
|
if (decision.action === "create") return null;
|
|
6874
6876
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -8092,6 +8094,9 @@ var DEFAULT_BASE_URL = BASE_URL;
|
|
|
8092
8094
|
var DEFAULT_MODEL3 = "anthropic/claude-sonnet-4-6";
|
|
8093
8095
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
8094
8096
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
8097
|
+
var MIN_RETRY_BUDGET_MS = 2e3;
|
|
8098
|
+
var MIN_RESPONSES_OUTPUT_TOKENS = 2048;
|
|
8099
|
+
var SCHEMA_FALLBACK_SKIP_STATUSES = /* @__PURE__ */ new Set([401, 403, 404, 408, 409, 413, 425, 429]);
|
|
8095
8100
|
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.
|
|
8096
8101
|
|
|
8097
8102
|
Rules:
|
|
@@ -8123,14 +8128,9 @@ ${m.content}`).join("\n\n");
|
|
|
8123
8128
|
const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
8124
8129
|
const model = options.llmModel ?? DEFAULT_MODEL3;
|
|
8125
8130
|
const wantsStructured = !!options.responseSchema;
|
|
8126
|
-
const
|
|
8131
|
+
const useResponsesTransport = requiresResponsesTransport(model);
|
|
8132
|
+
const sendResponseFormat = wantsStructured && !useResponsesTransport && supportsResponseFormat(model, "json_schema");
|
|
8127
8133
|
const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
8128
|
-
const systemPrompt = wantsStructured && !sendResponseFormat ? `${basePrompt}
|
|
8129
|
-
|
|
8130
|
-
Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
|
|
8131
|
-
${JSON.stringify(
|
|
8132
|
-
options.responseSchema
|
|
8133
|
-
)}` : basePrompt;
|
|
8134
8134
|
const userMessage = [
|
|
8135
8135
|
`Question:
|
|
8136
8136
|
${trimmed}`,
|
|
@@ -8140,85 +8140,121 @@ ${evidence}`
|
|
|
8140
8140
|
].join("\n\n");
|
|
8141
8141
|
const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
8142
8142
|
const fetchImpl = options.fetchFn ?? fetch;
|
|
8143
|
+
const buildBody = (useResponseFormat) => {
|
|
8144
|
+
const systemPrompt = wantsStructured && !useResponseFormat ? `${basePrompt}
|
|
8145
|
+
|
|
8146
|
+
Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
|
|
8147
|
+
${JSON.stringify(
|
|
8148
|
+
options.responseSchema
|
|
8149
|
+
)}` : basePrompt;
|
|
8150
|
+
const messages = [
|
|
8151
|
+
{ role: "system", content: systemPrompt },
|
|
8152
|
+
{ role: "user", content: userMessage }
|
|
8153
|
+
];
|
|
8154
|
+
if (useResponsesTransport) {
|
|
8155
|
+
return JSON.stringify({
|
|
8156
|
+
model,
|
|
8157
|
+
// Same system+user pair under the Responses-API field names: `input`
|
|
8158
|
+
// for the turns, `max_output_tokens` for the cap. Sending the
|
|
8159
|
+
// chat-completions spelling here is silently ignored, which caps the
|
|
8160
|
+
// answer at the portal default.
|
|
8161
|
+
input: messages,
|
|
8162
|
+
max_output_tokens: Math.max(maxTokens, MIN_RESPONSES_OUTPUT_TOKENS)
|
|
8163
|
+
});
|
|
8164
|
+
}
|
|
8165
|
+
return JSON.stringify({
|
|
8166
|
+
model,
|
|
8167
|
+
// Modern OpenAI field; the portal reads only `max_completion_tokens`
|
|
8168
|
+
// (the deprecated `max_tokens` is silently ignored → falls back to the
|
|
8169
|
+
// portal's default output cap and truncates the answer).
|
|
8170
|
+
max_completion_tokens: maxTokens,
|
|
8171
|
+
messages,
|
|
8172
|
+
...useResponseFormat && {
|
|
8173
|
+
response_format: {
|
|
8174
|
+
type: "json_schema",
|
|
8175
|
+
json_schema: { name: "reflect_output", schema: options.responseSchema }
|
|
8176
|
+
}
|
|
8177
|
+
}
|
|
8178
|
+
});
|
|
8179
|
+
};
|
|
8143
8180
|
const log = getLogger();
|
|
8144
8181
|
const authHeaders = await resolvePortalAuthHeaders(options, "memory/reflect");
|
|
8145
8182
|
if (authHeaders === null) return baseResult;
|
|
8146
|
-
const controller = new AbortController();
|
|
8147
8183
|
const deadline = Date.now() + REQUEST_TIMEOUT_MS;
|
|
8148
8184
|
const remaining = () => Math.max(0, deadline - Date.now());
|
|
8149
|
-
const
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
}
|
|
8176
|
-
}
|
|
8177
|
-
}),
|
|
8178
|
-
signal: controller.signal
|
|
8179
|
-
});
|
|
8180
|
-
} catch (err) {
|
|
8185
|
+
const endpoint = useResponsesTransport ? "/api/v1/responses" : "/api/v1/chat/completions";
|
|
8186
|
+
const sendOnce = async (useResponseFormat) => {
|
|
8187
|
+
const controller = new AbortController();
|
|
8188
|
+
const timer = setTimeout(() => controller.abort(), remaining());
|
|
8189
|
+
let response;
|
|
8190
|
+
try {
|
|
8191
|
+
response = await fetchImpl(`${baseUrl}${endpoint}`, {
|
|
8192
|
+
method: "POST",
|
|
8193
|
+
// No task type unless the caller named one — an undeclared task adds no
|
|
8194
|
+
// header at all, which is what keeps user-facing reflect() unlabelled.
|
|
8195
|
+
headers: {
|
|
8196
|
+
...authHeaders,
|
|
8197
|
+
...taskTypeHeader(options.taskType),
|
|
8198
|
+
"Content-Type": "application/json"
|
|
8199
|
+
},
|
|
8200
|
+
body: buildBody(useResponseFormat),
|
|
8201
|
+
signal: controller.signal
|
|
8202
|
+
});
|
|
8203
|
+
} catch (err) {
|
|
8204
|
+
clearTimeout(timer);
|
|
8205
|
+
log.warn("[memory/reflect] portal request failed", {
|
|
8206
|
+
err: err instanceof Error ? err.message : String(err),
|
|
8207
|
+
baseUrl
|
|
8208
|
+
});
|
|
8209
|
+
return { kind: "error" };
|
|
8210
|
+
}
|
|
8181
8211
|
clearTimeout(timer);
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8212
|
+
if (!response.ok) {
|
|
8213
|
+
return { kind: "http", status: response.status, statusText: response.statusText };
|
|
8214
|
+
}
|
|
8215
|
+
const bodyTimer = setTimeout(() => controller.abort(), remaining());
|
|
8216
|
+
try {
|
|
8217
|
+
const body = await response.json();
|
|
8218
|
+
clearTimeout(bodyTimer);
|
|
8219
|
+
return { kind: "ok", body };
|
|
8220
|
+
} catch (err) {
|
|
8221
|
+
clearTimeout(bodyTimer);
|
|
8222
|
+
log.warn("[memory/reflect] failed to parse portal response body", {
|
|
8223
|
+
err: err instanceof Error ? err.message : String(err)
|
|
8224
|
+
});
|
|
8225
|
+
return { kind: "error" };
|
|
8226
|
+
}
|
|
8227
|
+
};
|
|
8228
|
+
let attempt = await sendOnce(sendResponseFormat);
|
|
8229
|
+
let schemaFallbackUsed = false;
|
|
8230
|
+
const budgetLeftMs = remaining();
|
|
8231
|
+
if (attempt.kind === "http" && sendResponseFormat && !SCHEMA_FALLBACK_SKIP_STATUSES.has(attempt.status) && budgetLeftMs >= MIN_RETRY_BUDGET_MS) {
|
|
8232
|
+
log.warn("[memory/reflect] response_format json_schema rejected; retrying schema-in-prompt", {
|
|
8233
|
+
status: attempt.status,
|
|
8234
|
+
statusText: attempt.statusText,
|
|
8235
|
+
model,
|
|
8236
|
+
taskType: options.taskType,
|
|
8237
|
+
budgetLeftMs
|
|
8185
8238
|
});
|
|
8186
|
-
|
|
8239
|
+
schemaFallbackUsed = true;
|
|
8240
|
+
attempt = await sendOnce(false);
|
|
8187
8241
|
}
|
|
8188
|
-
|
|
8189
|
-
if (
|
|
8242
|
+
if (attempt.kind === "error") return baseResult;
|
|
8243
|
+
if (attempt.kind === "http") {
|
|
8190
8244
|
log.warn("[memory/reflect] portal returned non-OK", {
|
|
8191
|
-
status:
|
|
8192
|
-
statusText:
|
|
8245
|
+
status: attempt.status,
|
|
8246
|
+
statusText: attempt.statusText,
|
|
8247
|
+
// Distinguishes "the fallback ran and still failed" from "never tried".
|
|
8248
|
+
schemaFallbackUsed
|
|
8193
8249
|
});
|
|
8194
8250
|
return baseResult;
|
|
8195
8251
|
}
|
|
8196
|
-
|
|
8197
|
-
let body;
|
|
8198
|
-
try {
|
|
8199
|
-
body = await response.json();
|
|
8200
|
-
} catch (err) {
|
|
8201
|
-
clearTimeout(bodyTimer);
|
|
8202
|
-
log.warn("[memory/reflect] failed to parse portal response body", {
|
|
8203
|
-
err: err instanceof Error ? err.message : String(err)
|
|
8204
|
-
});
|
|
8205
|
-
return baseResult;
|
|
8206
|
-
}
|
|
8207
|
-
clearTimeout(bodyTimer);
|
|
8208
|
-
return parseAnswer(body, baseResult, !!options.responseSchema);
|
|
8252
|
+
return parseAnswer(attempt.body, baseResult, !!options.responseSchema);
|
|
8209
8253
|
}
|
|
8210
8254
|
function parseAnswer(body, base, parseSchema) {
|
|
8211
8255
|
if (typeof body !== "object" || body === null) return base;
|
|
8212
8256
|
const obj = body;
|
|
8213
|
-
const
|
|
8214
|
-
let text12 = "";
|
|
8215
|
-
if (Array.isArray(choices) && choices.length > 0) {
|
|
8216
|
-
const message = choices[0].message;
|
|
8217
|
-
if (typeof message === "object" && message !== null) {
|
|
8218
|
-
const content = message.content;
|
|
8219
|
-
if (typeof content === "string") text12 = content;
|
|
8220
|
-
}
|
|
8221
|
-
}
|
|
8257
|
+
const text12 = extractCompletionContent(obj) ?? "";
|
|
8222
8258
|
const usage = obj.usage;
|
|
8223
8259
|
let structuredOutput;
|
|
8224
8260
|
if (parseSchema && text12) {
|
|
@@ -8230,14 +8266,19 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
8230
8266
|
});
|
|
8231
8267
|
}
|
|
8232
8268
|
}
|
|
8269
|
+
const promptTokens = usage?.prompt_tokens ?? usage?.input_tokens ?? 0;
|
|
8270
|
+
const completionTokens = usage?.completion_tokens ?? usage?.output_tokens ?? 0;
|
|
8233
8271
|
return {
|
|
8234
8272
|
text: text12,
|
|
8235
8273
|
...structuredOutput !== void 0 && { structuredOutput },
|
|
8236
8274
|
basedOn: base.basedOn,
|
|
8237
8275
|
usage: {
|
|
8238
|
-
promptTokens
|
|
8239
|
-
completionTokens
|
|
8240
|
-
|
|
8276
|
+
promptTokens,
|
|
8277
|
+
completionTokens,
|
|
8278
|
+
// Derived when absent: the Responses API reports the two component counts
|
|
8279
|
+
// and does not always send a total, which would otherwise report zero
|
|
8280
|
+
// spend for a call that plainly cost something.
|
|
8281
|
+
totalTokens: usage?.total_tokens ?? promptTokens + completionTokens
|
|
8241
8282
|
}
|
|
8242
8283
|
};
|
|
8243
8284
|
}
|
|
@@ -70,6 +70,34 @@ function supportsResponseFormat(model, variant = "json_object") {
|
|
|
70
70
|
const allow = variant === "json_schema" ? RESPONSE_SCHEMA_OK : RESPONSE_FORMAT_OK;
|
|
71
71
|
return model.split("/").some((seg) => allow.has(seg));
|
|
72
72
|
}
|
|
73
|
+
var RESPONSES_ONLY_MODEL_PREFIXES = ["gpt-5.6"];
|
|
74
|
+
function requiresResponsesTransport(model) {
|
|
75
|
+
return model.split("/").some((seg) => RESPONSES_ONLY_MODEL_PREFIXES.some((prefix) => seg.startsWith(prefix)));
|
|
76
|
+
}
|
|
77
|
+
var CHAT_TO_RESPONSES_FIELDS = {
|
|
78
|
+
max_completion_tokens: "max_output_tokens"
|
|
79
|
+
};
|
|
80
|
+
function responsesExtra(extra) {
|
|
81
|
+
if (!extra) return {};
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
84
|
+
const target = CHAT_TO_RESPONSES_FIELDS[key] ?? key;
|
|
85
|
+
if (target !== key && target in extra) continue;
|
|
86
|
+
out[target] = value;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
var FOREIGN_ENDPOINT_SUFFIX = {
|
|
91
|
+
chat: "/responses",
|
|
92
|
+
responses: "/chat/completions"
|
|
93
|
+
};
|
|
94
|
+
function assertTransportMatchesEndpoint(transport, endpoint) {
|
|
95
|
+
const foreign = FOREIGN_ENDPOINT_SUFFIX[transport];
|
|
96
|
+
if (!endpoint.endsWith(foreign)) return;
|
|
97
|
+
throw new Error(
|
|
98
|
+
`endpointOverride "${endpoint}" is the other transport's endpoint, but transport is "${transport}". The request body is built for the transport, so this sends the wrong shape and 400s without retry.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
73
101
|
var RETRYABLE_HTTP = /* @__PURE__ */ new Set([408, 409, 425, 429]);
|
|
74
102
|
function isRetryableStatus(status) {
|
|
75
103
|
return status >= 500 || RETRYABLE_HTTP.has(status);
|
|
@@ -111,13 +139,14 @@ async function resolvePortalAuthHeaders(auth, tag) {
|
|
|
111
139
|
}
|
|
112
140
|
async function callPortalJsonCompletion(req) {
|
|
113
141
|
const log = getLogger();
|
|
114
|
-
let endpoint = "/api/v1/chat/completions";
|
|
142
|
+
let endpoint = req.transport === "responses" ? "/api/v1/responses" : "/api/v1/chat/completions";
|
|
115
143
|
if (req.endpointOverride !== void 0) {
|
|
116
144
|
const overrideValidation = validateEndpointOverride(req.endpointOverride);
|
|
117
145
|
if (!overrideValidation.valid) {
|
|
118
146
|
throw new Error(overrideValidation.message);
|
|
119
147
|
}
|
|
120
148
|
endpoint = overrideValidation.endpoint;
|
|
149
|
+
assertTransportMatchesEndpoint(req.transport ?? "chat", endpoint);
|
|
121
150
|
}
|
|
122
151
|
const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
|
|
123
152
|
const startedAt = Date.now();
|
|
@@ -179,8 +208,8 @@ async function attemptPortalJson(req, endpoint) {
|
|
|
179
208
|
const authHeaders = await resolvePortalAuthHeaders(req, req.tag);
|
|
180
209
|
if (authHeaders === null)
|
|
181
210
|
return { kind: "terminal", code: "auth-unavailable", reason: "auth unavailable (no token)" };
|
|
182
|
-
const
|
|
183
|
-
const prefill =
|
|
211
|
+
const usesPrefill = req.transport !== "responses" && req.model.startsWith("anthropic/");
|
|
212
|
+
const prefill = usesPrefill ? "{" : "";
|
|
184
213
|
const messages = [
|
|
185
214
|
// Every caller of this helper is a first-party BACKGROUND op (fact extraction,
|
|
186
215
|
// topic sweep, consolidation, classifiers, graph traversal, query
|
|
@@ -199,13 +228,34 @@ async function attemptPortalJson(req, endpoint) {
|
|
|
199
228
|
const supportsJsonObjectFormat = supportsResponseFormat(req.model);
|
|
200
229
|
const controller = new AbortController();
|
|
201
230
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
202
|
-
const requestBody = {
|
|
231
|
+
const requestBody = req.transport === "responses" ? {
|
|
232
|
+
model: req.model,
|
|
233
|
+
// Same system+user pair under the Responses-API field name. No prefill
|
|
234
|
+
// entry to strip: `usesPrefill` is false on this transport, so it was
|
|
235
|
+
// never pushed and the response-side restore is disarmed with it. An
|
|
236
|
+
// earlier version pushed it and sliced it back off here, which left
|
|
237
|
+
// `prefill` truthy and the restore still armed — the fix belonged at
|
|
238
|
+
// the decision, not at the two symptoms.
|
|
239
|
+
input: messages,
|
|
240
|
+
...req.reasoning && { reasoning: req.reasoning },
|
|
241
|
+
// NO response_format. The Responses API spells structured output
|
|
242
|
+
// differently (`text.format`), and it is unverified against this
|
|
243
|
+
// portal — so this transport relies on the same strict-JSON system
|
|
244
|
+
// prompt plus `extractJsonCandidate` that every response_format-
|
|
245
|
+
// rejecting model already relies on. Verified end to end on dev:
|
|
246
|
+
// luna returns clean parseable JSON here without it. Add the field
|
|
247
|
+
// only with a per-provider check, exactly as RESPONSE_FORMAT_OK was
|
|
248
|
+
// earned.
|
|
249
|
+
...responsesExtra(req.extra)
|
|
250
|
+
} : {
|
|
203
251
|
model: req.model,
|
|
204
252
|
messages,
|
|
205
253
|
...supportsJsonObjectFormat && { response_format: { type: "json_object" } },
|
|
206
254
|
...req.extra
|
|
207
255
|
};
|
|
208
|
-
if (!supportsJsonObjectFormat)
|
|
256
|
+
if (req.transport === "responses" || !supportsJsonObjectFormat) {
|
|
257
|
+
delete requestBody.response_format;
|
|
258
|
+
}
|
|
209
259
|
let response;
|
|
210
260
|
try {
|
|
211
261
|
response = await fetchImpl(`${baseUrl}${endpoint}`, {
|
|
@@ -335,13 +385,15 @@ function logPortalUsage(body, tag) {
|
|
|
335
385
|
const root = asRecord(body);
|
|
336
386
|
if (!root) return;
|
|
337
387
|
const usage = asRecord(root.usage);
|
|
338
|
-
const promptTokens = asCount(usage?.prompt_tokens);
|
|
339
|
-
const completionTokens = asCount(usage?.completion_tokens);
|
|
388
|
+
const promptTokens = asCount(usage?.prompt_tokens) ?? asCount(usage?.input_tokens);
|
|
389
|
+
const completionTokens = asCount(usage?.completion_tokens) ?? asCount(usage?.output_tokens);
|
|
340
390
|
if (promptTokens === void 0 && completionTokens === void 0) return;
|
|
341
|
-
const cachedTokens = asCount(asRecord(root.portal)?.cached_tokens) ?? asCount(asRecord(usage?.prompt_tokens_details)?.cached_tokens) ?? 0;
|
|
391
|
+
const cachedTokens = asCount(asRecord(root.portal)?.cached_tokens) ?? asCount(asRecord(usage?.prompt_tokens_details)?.cached_tokens) ?? asCount(asRecord(usage?.input_tokens_details)?.cached_tokens) ?? 0;
|
|
392
|
+
const reasoningTokens = asCount(asRecord(usage?.output_tokens_details)?.reasoning_tokens) ?? asCount(asRecord(usage?.completion_tokens_details)?.reasoning_tokens);
|
|
342
393
|
const parts = [];
|
|
343
394
|
if (promptTokens !== void 0) parts.push(`prompt=${promptTokens}`);
|
|
344
395
|
if (completionTokens !== void 0) parts.push(`completion=${completionTokens}`);
|
|
396
|
+
if (reasoningTokens !== void 0) parts.push(`reasoning=${reasoningTokens}`);
|
|
345
397
|
parts.push(`cached=${cachedTokens}`);
|
|
346
398
|
getLogger().debug(`[${tag}] usage ${parts.join(" ")}`);
|
|
347
399
|
} catch {
|
|
@@ -349,12 +401,22 @@ function logPortalUsage(body, tag) {
|
|
|
349
401
|
}
|
|
350
402
|
function extractCompletionContent(body) {
|
|
351
403
|
if (typeof body !== "object" || body === null) return null;
|
|
404
|
+
const responsesText = extractResponsesContent(body);
|
|
405
|
+
if (responsesText !== null) return responsesText;
|
|
352
406
|
const choices = body.choices;
|
|
353
407
|
if (!Array.isArray(choices) || choices.length === 0) return null;
|
|
354
408
|
const first = choices[0];
|
|
355
409
|
const content = first?.message?.content;
|
|
356
410
|
return typeof content === "string" ? content : null;
|
|
357
411
|
}
|
|
412
|
+
function extractResponsesContent(body) {
|
|
413
|
+
const root = asRecord(body);
|
|
414
|
+
if (!root) return null;
|
|
415
|
+
if (typeof root.output_text === "string" && root.output_text !== "") return root.output_text;
|
|
416
|
+
if (!Array.isArray(root.output)) return null;
|
|
417
|
+
const text = 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("");
|
|
418
|
+
return text;
|
|
419
|
+
}
|
|
358
420
|
|
|
359
421
|
export {
|
|
360
422
|
consoleLogger,
|
|
@@ -366,7 +428,9 @@ export {
|
|
|
366
428
|
withInternalFlowMarker,
|
|
367
429
|
taskTypeHeader,
|
|
368
430
|
supportsResponseFormat,
|
|
431
|
+
requiresResponsesTransport,
|
|
369
432
|
resolvePortalAuthHeaders,
|
|
370
433
|
callPortalJsonCompletion,
|
|
371
|
-
extractJsonCandidate
|
|
434
|
+
extractJsonCandidate,
|
|
435
|
+
extractCompletionContent
|
|
372
436
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callPortalJsonCompletion,
|
|
3
3
|
getLogger
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
5
5
|
import {
|
|
6
6
|
BASE_URL,
|
|
7
7
|
createClientConfig
|
|
@@ -7169,7 +7169,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
7169
7169
|
subQueries = decomp.subQueries;
|
|
7170
7170
|
}
|
|
7171
7171
|
}
|
|
7172
|
-
const { recall: recall2 } = await import("./recall-
|
|
7172
|
+
const { recall: recall2 } = await import("./recall-UVVZGRVF.mjs");
|
|
7173
7173
|
let recallDegraded = [];
|
|
7174
7174
|
const result = await recall2(
|
|
7175
7175
|
query,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
notifyConsolidationFallback,
|
|
3
3
|
resolvePiiRedactor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7X7BNMGS.mjs";
|
|
5
5
|
import {
|
|
6
6
|
callPortalJsonCompletion
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
8
8
|
import "./chunk-GYKJOWEO.mjs";
|
|
9
9
|
|
|
10
10
|
// src/lib/memory/consolidate.ts
|