@humain/humain-code 0.4.8 → 0.4.10
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/CHANGELOG.md +44 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/{anthropic-messages-YMPB2HJ7.js → anthropic-messages-UNHXXOD4.js} +3 -3
- package/dist/bundle/chunks/{azure-openai-responses-PDHOT7UC.js → azure-openai-responses-4QRYJCC2.js} +2 -2
- package/dist/bundle/chunks/bedrock-converse-stream.js +109 -92
- package/dist/bundle/chunks/{chunk-GNOKILVU.js → chunk-2QTTNAD4.js} +3385 -3947
- package/dist/bundle/chunks/{chunk-II2442A2.js → chunk-5CDES42D.js} +1 -1
- package/dist/bundle/chunks/{chunk-IMR3ZJM5.js → chunk-5XD3DHYL.js} +1 -1
- package/dist/bundle/chunks/{chunk-RXHSJSYY.js → chunk-6KAMTNN3.js} +1 -1
- package/dist/bundle/chunks/chunk-76X5KOIA.js +28 -0
- package/dist/bundle/chunks/{chunk-KRMTBTWU.js → chunk-77EWF2NW.js} +1 -1
- package/dist/bundle/chunks/{chunk-SKIP6KJV.js → chunk-7Z5MWPYE.js} +1 -1
- package/dist/bundle/chunks/{chunk-PBBQBIHY.js → chunk-AS2Y2MO6.js} +37 -37
- package/dist/bundle/chunks/{chunk-TIAXGIMN.js → chunk-AUFEF24K.js} +10 -10
- package/dist/bundle/chunks/{chunk-ILRBME2Y.js → chunk-BCF7KZ3R.js} +757 -745
- package/dist/bundle/chunks/{chunk-WPLW452J.js → chunk-DZ5C66IU.js} +1 -1
- package/dist/bundle/chunks/{chunk-2W5PWUPO.js → chunk-EDKZRYWJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-W2QRCQBX.js → chunk-FF26YENK.js} +3 -4
- package/dist/bundle/chunks/{chunk-UZ5FVVCP.js → chunk-HMWAH7ZY.js} +1 -1
- package/dist/bundle/chunks/{chunk-F7UMX5BV.js → chunk-HSDTSUZE.js} +13 -2
- package/dist/bundle/chunks/chunk-I2ZWZAIV.js +751 -0
- package/dist/bundle/chunks/{chunk-GUUAEK6G.js → chunk-LCOHFEZZ.js} +1 -1
- package/dist/bundle/chunks/chunk-MVYV6MJY.js +23 -0
- package/dist/bundle/chunks/{chunk-Z5LYSSTY.js → chunk-QSPDLT2R.js} +2 -2
- package/dist/bundle/chunks/{chunk-UBQSONVR.js → chunk-R5VIAWGA.js} +103 -145
- package/dist/bundle/chunks/{chunk-YURQPD6Y.js → chunk-RYC5BYVE.js} +1 -2
- package/dist/bundle/chunks/{chunk-ROSZII6E.js → chunk-V5ZF7Q7L.js} +1 -1
- package/dist/bundle/chunks/chunk-VEYTRNQC.js +5 -0
- package/dist/bundle/chunks/{chunk-LQ4S7CRR.js → chunk-VYIIPF57.js} +1 -1
- package/dist/bundle/chunks/chunk-WBJN6PEI.js +43 -0
- package/dist/bundle/chunks/{chunk-SWRU4BOC.js → chunk-XGO43DKL.js} +1 -1
- package/dist/bundle/chunks/{chunk-PMISFIBM.js → chunk-XMHLSV3I.js} +1 -1
- package/dist/bundle/chunks/{chunk-3E4SMILM.js → chunk-YJBE3IGR.js} +14 -14
- package/dist/bundle/chunks/{chunk-OTXURGIO.js → chunk-YKZGL4MB.js} +1 -1
- package/dist/bundle/chunks/chunk-Z33NNMNB.js +6 -0
- package/dist/bundle/chunks/{cli-ZKT34WPW.js → cli-5ACW3WND.js} +2 -2
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-YPOLSCPT.js → cloudflare-workers-ai-system-one-FZ3UQCZ7.js} +1 -1
- package/dist/bundle/chunks/{compat-J5FTRJ6S.js → compat-TQKA4I7M.js} +3 -3
- package/dist/bundle/chunks/{dist-N7XDUAAO.js → dist-VNSMKBZ6.js} +3 -3
- package/dist/bundle/chunks/{dist-6FQCCUSC.js → dist-WHC67QRM.js} +1077 -912
- package/dist/bundle/chunks/dist-cjs-RL2OCAP2.js +179 -0
- package/dist/bundle/chunks/{easter-egg-3d-5KKDWEIA.js → easter-egg-3d-3L3IKAT6.js} +1 -1
- package/dist/bundle/chunks/{esm-NCUV2DF7.js → esm-763X2IA7.js} +1 -1
- package/dist/bundle/chunks/event-streams-R5OECII4.js +2 -0
- package/dist/bundle/chunks/{execute-OSBDNQU5.js → execute-4X6G65NZ.js} +1 -1
- package/dist/bundle/chunks/{extract-56PXVZVW.js → extract-DLZ425VI.js} +4 -4
- package/dist/bundle/chunks/github-copilot.js +32 -31
- package/dist/bundle/chunks/{google-generative-ai-TS4ZE2RO.js → google-generative-ai-JD2FVOIX.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-MJK2SMNE.js → google-vertex-PFBMDCBW.js} +3 -3
- package/dist/bundle/chunks/host-4J7H7KDS.js +2 -0
- package/dist/bundle/chunks/{llama-cpp-classify-5KAR326J.js → llama-cpp-classify-AGCW7HYN.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-XA2ZGSAH.js → mistral-conversations-D74NZ65O.js} +2 -2
- package/dist/bundle/chunks/{node-XGNY74WT.js → node-W47VUEGE.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-Y6NRWMOI.js → openai-codex-responses-JAAA7MSS.js} +3 -3
- package/dist/bundle/chunks/{openai-completions-FY77MIZH.js → openai-completions-PGPMGQPU.js} +34 -33
- package/dist/bundle/chunks/{openai-decisions-MKH4OJHH.js → openai-decisions-QQ4MEABI.js} +1 -1
- package/dist/bundle/chunks/openai-responses-FG2R2M4L.js +23 -0
- package/dist/bundle/chunks/{openrouter-images-R3QMMLPH.js → openrouter-images-NTBP3UUE.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-LYJZPRST.js → pi-messages-JD4O7KIP.js} +1 -1
- package/dist/bundle/chunks/{runtime-JFLZUNYP.js → runtime-SI76JZNE.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-PAYJECQK.js → typesafe-system-one-TTC7YCO3.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-ID2GA4GE.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/assets/contract.json +1 -1
- package/dist/bundle/flow/package.json +1 -1
- package/dist/bundle/index.js +17 -17
- package/dist/bundle/rpc-entry.js +3 -2
- package/dist/core/account-reporting.d.ts +109 -0
- package/dist/core/account-reporting.d.ts.map +1 -0
- package/dist/core/account-reporting.js +328 -0
- package/dist/core/account-reporting.js.map +1 -0
- package/dist/core/agent-session.d.ts +22 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +131 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-account-reporting.d.ts +76 -0
- package/dist/core/anthropic-account-reporting.d.ts.map +1 -0
- package/dist/core/anthropic-account-reporting.js +380 -0
- package/dist/core/anthropic-account-reporting.js.map +1 -0
- package/dist/core/bedrock-account-reporting.d.ts +82 -0
- package/dist/core/bedrock-account-reporting.d.ts.map +1 -0
- package/dist/core/bedrock-account-reporting.js +402 -0
- package/dist/core/bedrock-account-reporting.js.map +1 -0
- package/dist/core/model-runtime.d.ts +17 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +64 -10
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +4 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +10 -3
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +353 -29
- package/dist/humain/flow-accounts-host.d.ts +120 -0
- package/dist/humain/flow-accounts-host.d.ts.map +1 -0
- package/dist/humain/flow-accounts-host.js +346 -0
- package/dist/humain/flow-accounts-host.js.map +1 -0
- package/dist/humain/flow-command.d.ts +28 -0
- package/dist/humain/flow-command.d.ts.map +1 -0
- package/dist/humain/flow-command.js +226 -0
- package/dist/humain/flow-command.js.map +1 -0
- package/dist/humain/flow-loader.d.ts +4 -2
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +120 -91
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/node-account-failure.d.ts +18 -0
- package/dist/humain/node-account-failure.d.ts.map +1 -0
- package/dist/humain/node-account-failure.js +73 -0
- package/dist/humain/node-account-failure.js.map +1 -0
- package/dist/humain/node-account-fallback.d.ts +85 -0
- package/dist/humain/node-account-fallback.d.ts.map +1 -0
- package/dist/humain/node-account-fallback.js +175 -0
- package/dist/humain/node-account-fallback.js.map +1 -0
- package/dist/humain/node-http.d.ts.map +1 -1
- package/dist/humain/node-http.js +11 -0
- package/dist/humain/node-http.js.map +1 -1
- package/dist/humain/node-provider.d.ts +4 -0
- package/dist/humain/node-provider.d.ts.map +1 -1
- package/dist/humain/node-provider.js +11 -0
- package/dist/humain/node-provider.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +2 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +5 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +26 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +242 -19
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/flow-profiles.md +57 -5
- package/docs/flow.md +130 -45
- package/docs/providers.md +37 -0
- package/npm-shrinkwrap.json +48 -6
- package/package.json +3 -2
- package/dist/bundle/chunks/chunk-AKA7HNO3.js +0 -4
- package/dist/bundle/chunks/chunk-JYWVRJYG.js +0 -6
- package/dist/bundle/chunks/chunk-MEIYGK5O.js +0 -6
- package/dist/bundle/chunks/chunk-PYU5BR3Z.js +0 -27
- package/dist/bundle/chunks/event-streams-CGCQQL5M.js +0 -2
- package/dist/bundle/chunks/host-2ARI7PQ5.js +0 -2
- package/dist/bundle/chunks/openai-responses-LNSCERKH.js +0 -23
- package/dist/bundle/chunks/virtual-modules-TT2VTOSY.js +0 -5
|
@@ -242,32 +242,68 @@ function clampThinkingLevel(model, level) {
|
|
|
242
242
|
|
|
243
243
|
// packages/ai/src/utils/error-body.ts
|
|
244
244
|
var MAX_PROVIDER_ERROR_BODY_CHARS = 4e3;
|
|
245
|
+
var MAX_PROVIDER_ERROR_INPUT_CHARS = 64 * 1024;
|
|
246
|
+
var OVERSIZED_ERROR_TEXT = "Provider error text exceeded 65536 characters";
|
|
247
|
+
var UNPARSEABLE_ERROR_TEXT = "Unparseable structured provider error";
|
|
245
248
|
function normalizeProviderError(error) {
|
|
246
249
|
if (!(error instanceof Error)) {
|
|
247
|
-
return {
|
|
250
|
+
return {
|
|
251
|
+
message: truncateErrorText(safeJsonStringify(error), MAX_PROVIDER_ERROR_BODY_CHARS),
|
|
252
|
+
messageCarriesBody: false
|
|
253
|
+
};
|
|
248
254
|
}
|
|
249
255
|
const sdkError = error;
|
|
250
256
|
const status = extractStatus(sdkError);
|
|
251
257
|
const body = extractBody(sdkError);
|
|
252
|
-
|
|
258
|
+
let message = body === "[REDACTED]" ? body : truncateErrorText(error.message, MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
259
|
+
const transport = transportEvidence(error);
|
|
260
|
+
if (transport.transportCode && TRANSPORT_CODES.has(transport.transportCode) && !message.includes(transport.transportCode)) {
|
|
261
|
+
message = truncateErrorText(`${message} (${transport.transportCode})`, MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
262
|
+
}
|
|
263
|
+
const messageCarriesBody = body === void 0 || message !== "[REDACTED]" && message.includes(body);
|
|
253
264
|
return {
|
|
254
265
|
status,
|
|
255
266
|
body,
|
|
256
|
-
message
|
|
257
|
-
messageCarriesBody
|
|
267
|
+
message,
|
|
268
|
+
messageCarriesBody,
|
|
269
|
+
...transport
|
|
258
270
|
};
|
|
259
271
|
}
|
|
272
|
+
function transportEvidence(error) {
|
|
273
|
+
let candidate = error;
|
|
274
|
+
let transportCode;
|
|
275
|
+
let transportName;
|
|
276
|
+
for (let depth = 0; depth < 8 && candidate && typeof candidate === "object"; depth++) {
|
|
277
|
+
const nested = candidate;
|
|
278
|
+
const status = extractStatus(nested);
|
|
279
|
+
if (status !== void 0 && status >= 400 || nested.name === "AbortError" || nested.constructor?.name === "APIUserAbortError")
|
|
280
|
+
return {};
|
|
281
|
+
if (typeof nested.code === "string" && TRANSPORT_CODES.has(nested.code)) transportCode ??= nested.code;
|
|
282
|
+
for (const name of [nested.name, nested.constructor?.name]) {
|
|
283
|
+
if (["TimeoutError", "APIConnectionTimeoutError", "APIConnectionError"].includes(name)) transportName ??= name;
|
|
284
|
+
}
|
|
285
|
+
candidate = nested.cause;
|
|
286
|
+
}
|
|
287
|
+
transportCode ??= transportName;
|
|
288
|
+
return transportCode ? { transportCode } : {};
|
|
289
|
+
}
|
|
290
|
+
function appendProviderTransportDiagnostic(message, error) {
|
|
291
|
+
if (message.stopReason !== "error" || !error.transportCode) return;
|
|
292
|
+
appendAssistantMessageDiagnostic(message, {
|
|
293
|
+
type: "provider_transport_error",
|
|
294
|
+
timestamp: Date.now(),
|
|
295
|
+
details: { reason: "provider_unreachable", code: error.transportCode }
|
|
296
|
+
});
|
|
297
|
+
}
|
|
260
298
|
function extractStatus(error) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (typeof error.$response?.statusCode === "number") return error.$response.statusCode;
|
|
265
|
-
return void 0;
|
|
299
|
+
return [error.statusCode, error.status, error.$metadata?.httpStatusCode, error.$response?.statusCode].find(
|
|
300
|
+
(value) => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 599
|
|
301
|
+
);
|
|
266
302
|
}
|
|
267
303
|
function extractBody(error) {
|
|
268
304
|
const bodyText = pickBodyText(error);
|
|
269
305
|
if (bodyText === void 0) return void 0;
|
|
270
|
-
const trimmed = bodyText.trim();
|
|
306
|
+
const trimmed = sanitizeErrorText(bodyText).trim();
|
|
271
307
|
if (trimmed.length === 0) return void 0;
|
|
272
308
|
return truncateErrorText(trimmed, MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
273
309
|
}
|
|
@@ -276,6 +312,8 @@ function pickBodyText(error) {
|
|
|
276
312
|
if (isPlainNonEmptyObject(error.error)) return safeJsonStringify(error.error);
|
|
277
313
|
const responseBody = error.$response?.body;
|
|
278
314
|
if (typeof responseBody === "string") return responseBody;
|
|
315
|
+
if (responseBody instanceof Uint8Array)
|
|
316
|
+
return responseBody.byteLength > MAX_PROVIDER_ERROR_INPUT_CHARS ? OVERSIZED_ERROR_TEXT : new TextDecoder().decode(responseBody);
|
|
279
317
|
if (isReadableStreamLike(responseBody)) return void 0;
|
|
280
318
|
if (isPlainNonEmptyObject(responseBody)) return safeJsonStringify(responseBody);
|
|
281
319
|
return void 0;
|
|
@@ -290,17 +328,193 @@ function isPlainNonEmptyObject(value) {
|
|
|
290
328
|
return Object.keys(value).length > 0;
|
|
291
329
|
}
|
|
292
330
|
function truncateErrorText(text, maxChars) {
|
|
293
|
-
|
|
294
|
-
|
|
331
|
+
let clean = sanitizeErrorText(text);
|
|
332
|
+
const cap = Number.isFinite(maxChars) ? Math.max(0, Math.floor(maxChars)) : MAX_PROVIDER_ERROR_BODY_CHARS;
|
|
333
|
+
if (clean.length <= cap) return clean;
|
|
334
|
+
const start = clean.search(/[{[]/);
|
|
335
|
+
if (start >= 0) {
|
|
336
|
+
try {
|
|
337
|
+
const parsed = JSON.parse(clean.slice(start));
|
|
338
|
+
clean = clean.slice(0, start) + summarizeErrorValue(parsed);
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const suffix = "... [truncated]";
|
|
343
|
+
return cap < suffix.length ? suffix.slice(0, cap) : `${clean.slice(0, cap - suffix.length).replace(/\[[^\]]*$/, "")}${suffix}`;
|
|
295
344
|
}
|
|
296
345
|
function safeJsonStringify(value) {
|
|
297
346
|
try {
|
|
298
|
-
const serialized = JSON.stringify(value)
|
|
299
|
-
|
|
347
|
+
const serialized = JSON.stringify(value, (key, nested) => {
|
|
348
|
+
if (nested !== null && typeof nested === "object" && hasSensitiveLabel(nested, true)) {
|
|
349
|
+
return Array.isArray(nested) ? ["[REDACTED]"] : "[REDACTED]";
|
|
350
|
+
}
|
|
351
|
+
const label = normalizeErrorLabel(key);
|
|
352
|
+
if (hasAmbiguousErrorControls(key) || SENSITIVE_KEY.test(label) || /headers?/i.test(label) || Array.isArray(nested) && nested.some((item) => typeof item === "string" && SENSITIVE_KEY.test(normalizeErrorLabel(item))) || nested !== null && typeof nested === "object" && Object.entries(nested).some(
|
|
353
|
+
([name, item]) => typeof item === "string" && SENSITIVE_HEADER_NAME.test(normalizeErrorLabel(item)) || /^(?:name|key|header|header[-_]?name|header[-_]?key|field[-_]?name|label|identifier)$/i.test(
|
|
354
|
+
normalizeErrorLabel(name)
|
|
355
|
+
) && hasSensitiveLabel(item)
|
|
356
|
+
))
|
|
357
|
+
return "[REDACTED]";
|
|
358
|
+
if (Array.isArray(nested) && hasSensitiveLabel(nested)) return ["[REDACTED]"];
|
|
359
|
+
if (nested !== null && typeof nested === "object" && !Array.isArray(nested)) {
|
|
360
|
+
const entries = Object.entries(nested);
|
|
361
|
+
if (entries.some(([name]) => sanitizePlainText(name) !== stripErrorControls(name))) {
|
|
362
|
+
return Object.fromEntries(
|
|
363
|
+
entries.map(
|
|
364
|
+
([name, value2]) => sanitizePlainText(name) !== stripErrorControls(name) ? [sanitizePlainText(name), "[REDACTED]"] : [name, value2]
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return typeof nested === "string" ? sanitizeErrorText(nested) : nested;
|
|
370
|
+
});
|
|
371
|
+
if (serialized !== void 0 && serialized.length > MAX_PROVIDER_ERROR_INPUT_CHARS)
|
|
372
|
+
return truncateErrorText(summarizeErrorValue(JSON.parse(serialized)), MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
373
|
+
return serialized === void 0 ? sanitizePlainText(String(value)) : serialized;
|
|
300
374
|
} catch {
|
|
301
|
-
return
|
|
375
|
+
return "[Unserializable provider error]";
|
|
302
376
|
}
|
|
303
377
|
}
|
|
378
|
+
function summarizeErrorValue(value) {
|
|
379
|
+
if (typeof value === "string") {
|
|
380
|
+
try {
|
|
381
|
+
return summarizeErrorValue(JSON.parse(value));
|
|
382
|
+
} catch {
|
|
383
|
+
return sanitizePlainText(value);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
387
|
+
const entries = Object.entries(value);
|
|
388
|
+
const reasons = ["message", "error", "reason", "detail"];
|
|
389
|
+
entries.sort(
|
|
390
|
+
([left], [right]) => (reasons.includes(left) ? reasons.indexOf(left) : reasons.length) - (reasons.includes(right) ? reasons.indexOf(right) : reasons.length)
|
|
391
|
+
);
|
|
392
|
+
const parts = [];
|
|
393
|
+
let length = 0;
|
|
394
|
+
for (const [, nested] of entries) {
|
|
395
|
+
const part = truncateErrorText(summarizeErrorValue(nested), MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
396
|
+
parts.push(part);
|
|
397
|
+
length += part.length + 2;
|
|
398
|
+
if (length >= MAX_PROVIDER_ERROR_BODY_CHARS) break;
|
|
399
|
+
}
|
|
400
|
+
return truncateErrorText(parts.join("; "), MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
401
|
+
}
|
|
402
|
+
var TRANSPORT_CODES = /* @__PURE__ */ new Set([
|
|
403
|
+
"ECONNREFUSED",
|
|
404
|
+
"ECONNRESET",
|
|
405
|
+
"ETIMEDOUT",
|
|
406
|
+
"ENOTFOUND",
|
|
407
|
+
"EAI_AGAIN",
|
|
408
|
+
"EHOSTUNREACH",
|
|
409
|
+
"ENETUNREACH",
|
|
410
|
+
"EPIPE",
|
|
411
|
+
"EPROTO",
|
|
412
|
+
"CERT_HAS_EXPIRED",
|
|
413
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
414
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
415
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
416
|
+
"ERR_TLS_CERT_ALTNAME_INVALID",
|
|
417
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
418
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
419
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
420
|
+
"UND_ERR_SOCKET"
|
|
421
|
+
]);
|
|
422
|
+
var SENSITIVE_KEY = /(?:authorization|cookie|(?:api[-_\s]*key)|token|password|passwd|secret|credential|signature|private[-_\s]*key)/i;
|
|
423
|
+
var SENSITIVE_HEADER_NAME = /^(?:[a-z0-9]+[-_])*(?:authorization|cookie|(?:api|private|secret)[-_\s]*key|(?:access|refresh|session|security)[-_\s]*token|token|password|passwd|secret|credentials?|signature)$/i;
|
|
424
|
+
function sanitizeErrorText(text) {
|
|
425
|
+
if (text.length > MAX_PROVIDER_ERROR_INPUT_CHARS) return OVERSIZED_ERROR_TEXT;
|
|
426
|
+
try {
|
|
427
|
+
const parsed = JSON.parse(text);
|
|
428
|
+
if (parsed !== null && typeof parsed === "object") return safeJsonStringify(parsed);
|
|
429
|
+
if (typeof parsed === "string") return sanitizeErrorText(parsed);
|
|
430
|
+
} catch {
|
|
431
|
+
const start = text.search(/[{[]/);
|
|
432
|
+
if (start > 0) {
|
|
433
|
+
try {
|
|
434
|
+
const parsed = JSON.parse(text.slice(start));
|
|
435
|
+
return sanitizePlainText(text.slice(0, start)) + safeJsonStringify(parsed);
|
|
436
|
+
} catch {
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return sanitizePlainText(text);
|
|
441
|
+
}
|
|
442
|
+
function hasSensitiveLabel(value, ambiguityOnly = false) {
|
|
443
|
+
const pending = [value];
|
|
444
|
+
const seen = /* @__PURE__ */ new Set();
|
|
445
|
+
let scanned = 0;
|
|
446
|
+
while (pending.length > 0) {
|
|
447
|
+
if (++scanned > 1024) return true;
|
|
448
|
+
const item = pending.pop();
|
|
449
|
+
if (typeof item === "string") {
|
|
450
|
+
if (item.length > MAX_PROVIDER_ERROR_INPUT_CHARS) return true;
|
|
451
|
+
if (hasAmbiguousErrorControls(item) || !ambiguityOnly && SENSITIVE_HEADER_NAME.test(normalizeErrorLabel(item)))
|
|
452
|
+
return true;
|
|
453
|
+
try {
|
|
454
|
+
const decoded = JSON.parse(ambiguityOnly ? item : stripErrorControls(item, " "));
|
|
455
|
+
if (typeof decoded === "string" || decoded !== null && typeof decoded === "object") pending.push(decoded);
|
|
456
|
+
} catch {
|
|
457
|
+
const sanitized = sanitizePlainText(item);
|
|
458
|
+
if (ambiguityOnly ? sanitized === UNPARSEABLE_ERROR_TEXT : sanitized !== stripErrorControls(item))
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (item !== null && typeof item === "object") {
|
|
463
|
+
if (seen.has(item)) return true;
|
|
464
|
+
seen.add(item);
|
|
465
|
+
const entries = Object.entries(item);
|
|
466
|
+
if (entries.length * 2 + pending.length > 1024) return true;
|
|
467
|
+
for (const [name, nested] of entries) {
|
|
468
|
+
if (ambiguityOnly && hasAmbiguousErrorKey(name)) return true;
|
|
469
|
+
if (!ambiguityOnly) pending.push(name);
|
|
470
|
+
pending.push(nested);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
function hasAmbiguousErrorKey(name) {
|
|
477
|
+
return name.length > MAX_PROVIDER_ERROR_INPUT_CHARS || name !== normalizeErrorLabel(name) || sanitizePlainText(name) === UNPARSEABLE_ERROR_TEXT;
|
|
478
|
+
}
|
|
479
|
+
function normalizeErrorLabel(text) {
|
|
480
|
+
return stripErrorControls(text).replace(/[\s\p{Default_Ignorable_Code_Point}]/gu, "").trim().replace(/:+$/, "").trim();
|
|
481
|
+
}
|
|
482
|
+
var ERROR_TERMINAL_SEQUENCES = /(?:\x1b\]|\x9d)[\s\S]*?(?:\x07|\x1b\\|\x9c|$)|\x1b[PX^_][\s\S]*?(?:\x1b\\|$)|(?:\x1b\[|\x9b)[0-?]*[ -/]*[@-~]|\x1b[@-_]/g;
|
|
483
|
+
var ERROR_CONTROLS = /[\x00-\x08\x0b-\x1f\x7f-\x9f\p{Cf}\p{Default_Ignorable_Code_Point}]/gu;
|
|
484
|
+
function hasAmbiguousErrorControls(text) {
|
|
485
|
+
const unstyled = text.replace(
|
|
486
|
+
ERROR_TERMINAL_SEQUENCES,
|
|
487
|
+
(sequence2) => (sequence2.startsWith("\x1B[") || sequence2.startsWith("\x9B")) && sequence2.endsWith("m") ? "" : sequence2
|
|
488
|
+
);
|
|
489
|
+
return unstyled.search(ERROR_CONTROLS) >= 0;
|
|
490
|
+
}
|
|
491
|
+
function stripErrorControls(text, replacement = "") {
|
|
492
|
+
return text.replace(ERROR_TERMINAL_SEQUENCES, replacement).replace(ERROR_CONTROLS, replacement);
|
|
493
|
+
}
|
|
494
|
+
function sanitizePlainText(text) {
|
|
495
|
+
if (text.length > MAX_PROVIDER_ERROR_INPUT_CHARS) return OVERSIZED_ERROR_TEXT;
|
|
496
|
+
const boundaries = stripErrorControls(text, " ");
|
|
497
|
+
const clean = stripErrorControls(text);
|
|
498
|
+
if ((/[@?#<>]/.test(clean) || clean.split(/\s+/).some((part) => {
|
|
499
|
+
const start = part.search(/(?:https?|wss?|ftp):|[/\\]/i);
|
|
500
|
+
return start >= 0 && /["']/.test(part.slice(start));
|
|
501
|
+
})) && /(?:https?|wss?|ftp):|[/\\]/i.test(clean.replace(/\s/g, "")))
|
|
502
|
+
return "[REDACTED]";
|
|
503
|
+
if (/\\["/bfnrtu]/i.test(boundaries)) return UNPARSEABLE_ERROR_TEXT;
|
|
504
|
+
const structure = clean.replaceAll("[REDACTED]", "").replaceAll("[truncated]", "").replace(/\b[a-z_$][\w$]*(?:\[\d+\])+/gi, "");
|
|
505
|
+
if (/[{}[\]]/.test(structure)) return UNPARSEABLE_ERROR_TEXT;
|
|
506
|
+
if (hasAmbiguousErrorControls(text)) return "[REDACTED]";
|
|
507
|
+
if (SENSITIVE_KEY.test(normalizeErrorLabel(clean)) || /\b(?:B\s*e\s*a\s*r\s*e\s*r|B\s*a\s*s\s*i\s*c)\s/i.test(boundaries) || /\b(?:B\s*e\s*a\s*r\s*e\s*r|B\s*a\s*s\s*i\s*c)\s/i.test(clean))
|
|
508
|
+
return "[REDACTED]";
|
|
509
|
+
const tokenText = clean.replace(/[\t\n\u2028\u2029]/g, "");
|
|
510
|
+
const redacted = tokenText.replace(/[\w-]+(?:\.[\w-]+)*/g, (token) => {
|
|
511
|
+
const segments = token.split(".");
|
|
512
|
+
return /\b(?:sk-|glpat-|gh[pousr]_|github_pat_|xox[baprs]-)[\w-]+|\b(?:AKIA|ASIA)[A-Z0-9]{16}\b|\bAIza[\w-]{35}/.test(
|
|
513
|
+
token
|
|
514
|
+
) || segments.length >= 3 && /\beyJ[\w-]+$/.test(segments[0]) ? "[REDACTED]" : token;
|
|
515
|
+
});
|
|
516
|
+
return redacted === tokenText ? clean : "[REDACTED]";
|
|
517
|
+
}
|
|
304
518
|
|
|
305
519
|
// packages/ai/src/utils/headers.ts
|
|
306
520
|
function providerHeadersToRecord(...headerSources) {
|
|
@@ -1162,11 +1376,15 @@ var stream = (model, context, options = {}) => {
|
|
|
1162
1376
|
const supportsStrictMode = model.compat?.supportsStrictMode ?? false;
|
|
1163
1377
|
client = new BedrockRuntimeClient(config);
|
|
1164
1378
|
let observedRawResponse = false;
|
|
1165
|
-
|
|
1166
|
-
|
|
1379
|
+
addResponseHeadersMiddleware(
|
|
1380
|
+
client,
|
|
1381
|
+
options.onResponse,
|
|
1382
|
+
model,
|
|
1383
|
+
() => {
|
|
1167
1384
|
observedRawResponse = true;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1385
|
+
},
|
|
1386
|
+
options.timeoutMs
|
|
1387
|
+
);
|
|
1170
1388
|
const customHeaders = providerHeadersToRecord(options.headers);
|
|
1171
1389
|
if (customHeaders) {
|
|
1172
1390
|
addCustomHeadersMiddleware(client, customHeaders);
|
|
@@ -1268,6 +1486,7 @@ var stream = (model, context, options = {}) => {
|
|
|
1268
1486
|
}
|
|
1269
1487
|
output.stopReason = options.signal?.aborted ? "aborted" : "error";
|
|
1270
1488
|
output.errorMessage = formatBedrockError(error);
|
|
1489
|
+
appendProviderTransportDiagnostic(output, normalizeProviderError(error));
|
|
1271
1490
|
if (output.stopReason === "error") {
|
|
1272
1491
|
appendBedrockFailureDiagnostic(output, error, responseRequestId);
|
|
1273
1492
|
}
|
|
@@ -1289,19 +1508,18 @@ var BEDROCK_ERROR_PREFIXES = {
|
|
|
1289
1508
|
var BEDROCK_DATA_RETENTION_DOCS_URL = "https://docs.aws.amazon.com/bedrock/latest/userguide/data-retention.html";
|
|
1290
1509
|
function formatBedrockError(error) {
|
|
1291
1510
|
const norm = normalizeProviderError(error);
|
|
1292
|
-
const
|
|
1511
|
+
const modeled = error instanceof BedrockRuntimeServiceException && error.name.endsWith("Exception") && norm.message !== "UnknownError";
|
|
1512
|
+
const core = modeled || norm.status === void 0 ? norm.message : `${norm.status}: ${norm.body ?? norm.message.split("\n Deserialization error:")[0]}`;
|
|
1293
1513
|
const dataRetentionHint = /data retention mode/i.test(core) ? ` See ${BEDROCK_DATA_RETENTION_DOCS_URL} for supported data retention modes.` : "";
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
return `${prefix}: ${core}${dataRetentionHint}`;
|
|
1297
|
-
}
|
|
1298
|
-
return `${core}${dataRetentionHint}`;
|
|
1514
|
+
const prefix = error instanceof BedrockRuntimeServiceException ? `${BEDROCK_ERROR_PREFIXES[error.name] ?? error.name}: ` : "";
|
|
1515
|
+
return `${truncateErrorText(`${prefix}${core}`, MAX_PROVIDER_ERROR_BODY_CHARS - dataRetentionHint.length)}${dataRetentionHint}`;
|
|
1299
1516
|
}
|
|
1300
1517
|
var MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS = 200;
|
|
1301
1518
|
function normalizeDiagnosticValue(value) {
|
|
1302
1519
|
if (typeof value !== "string") return void 0;
|
|
1303
1520
|
const trimmed = value.trim();
|
|
1304
|
-
if (trimmed.length === 0 || trimmed.length > MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS)
|
|
1521
|
+
if (trimmed.length === 0 || trimmed.length > MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS || !/^[a-zA-Z0-9._:/-]+$/.test(trimmed) || truncateErrorText(trimmed, MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS) !== trimmed)
|
|
1522
|
+
return void 0;
|
|
1305
1523
|
return trimmed;
|
|
1306
1524
|
}
|
|
1307
1525
|
function extractBedrockErrorCode(error) {
|
|
@@ -1318,6 +1536,16 @@ function appendBedrockFailureDiagnostic(output, error, fallbackRequestId) {
|
|
|
1318
1536
|
if (requestId !== void 0) details.requestId = requestId;
|
|
1319
1537
|
if (Object.keys(details).length === 0) return;
|
|
1320
1538
|
appendAssistantMessageDiagnostic(output, { type: "bedrock_response_failure", timestamp: Date.now(), details });
|
|
1539
|
+
if (typeof details.status === "number" && details.status >= 400 && details.status <= 599) {
|
|
1540
|
+
appendAssistantMessageDiagnostic(output, {
|
|
1541
|
+
type: "provider_http_error",
|
|
1542
|
+
timestamp: Date.now(),
|
|
1543
|
+
details: {
|
|
1544
|
+
status: details.status,
|
|
1545
|
+
retryable: details.status === 408 || details.status === 429 || details.status >= 500
|
|
1546
|
+
}
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1321
1549
|
}
|
|
1322
1550
|
var RESERVED_HEADER_EXACT = /* @__PURE__ */ new Set(["authorization", "host"]);
|
|
1323
1551
|
function isReservedHeader(key) {
|
|
@@ -1359,17 +1587,113 @@ function toProviderResponse(response) {
|
|
|
1359
1587
|
if (!isSmithyHttpResponse(response)) return void 0;
|
|
1360
1588
|
return { status: response.statusCode, headers: { ...response.headers } };
|
|
1361
1589
|
}
|
|
1362
|
-
function addResponseHeadersMiddleware(client, onResponse, model, onObserved) {
|
|
1590
|
+
function addResponseHeadersMiddleware(client, onResponse, model, onObserved, timeoutMs) {
|
|
1591
|
+
if (timeoutMs !== void 0 && (!Number.isFinite(timeoutMs) || timeoutMs < 0 || timeoutMs > 2 ** 31 - 1)) {
|
|
1592
|
+
throw new Error("Invalid Bedrock timeoutMs");
|
|
1593
|
+
}
|
|
1363
1594
|
const middleware = (next) => async (args) => {
|
|
1364
1595
|
const result = await next(args);
|
|
1365
1596
|
const providerResponse = toProviderResponse(result.response);
|
|
1366
1597
|
if (providerResponse) {
|
|
1367
1598
|
onObserved();
|
|
1368
|
-
await onResponse(providerResponse, model);
|
|
1599
|
+
await onResponse?.(providerResponse, model);
|
|
1600
|
+
}
|
|
1601
|
+
if (isSmithyHttpResponse(result.response) && (result.response.statusCode < 200 || result.response.statusCode >= 300)) {
|
|
1602
|
+
try {
|
|
1603
|
+
await captureBedrockErrorBody(result.response, timeoutMs);
|
|
1604
|
+
} catch (error) {
|
|
1605
|
+
throw Object.assign(new Error(normalizeProviderError(error).message), {
|
|
1606
|
+
$metadata: {
|
|
1607
|
+
httpStatusCode: result.response.statusCode,
|
|
1608
|
+
requestId: result.response.headers["x-amzn-requestid"] ?? result.response.headers["x-amzn-request-id"]
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1369
1612
|
}
|
|
1370
1613
|
return result;
|
|
1371
1614
|
};
|
|
1372
|
-
client.middlewareStack.add(middleware, { step: "deserialize", name: "pi-ai-response-headers" });
|
|
1615
|
+
client.middlewareStack.add(middleware, { step: "deserialize", name: "pi-ai-response-headers", priority: "low" });
|
|
1616
|
+
}
|
|
1617
|
+
var MAX_BEDROCK_ERROR_BODY_BYTES = 64 * 1024;
|
|
1618
|
+
var BEDROCK_MODELED_ERRORS = /* @__PURE__ */ new Set([
|
|
1619
|
+
...Object.keys(BEDROCK_ERROR_PREFIXES),
|
|
1620
|
+
"AccessDeniedException",
|
|
1621
|
+
"ModelErrorException",
|
|
1622
|
+
"ModelNotReadyException",
|
|
1623
|
+
"ModelTimeoutException",
|
|
1624
|
+
"ResourceNotFoundException"
|
|
1625
|
+
]);
|
|
1626
|
+
async function captureBedrockErrorBody(response, timeoutMs) {
|
|
1627
|
+
const body = response.body;
|
|
1628
|
+
let bytes;
|
|
1629
|
+
let oversized = false;
|
|
1630
|
+
if (typeof body === "string") {
|
|
1631
|
+
bytes = new TextEncoder().encode(body.slice(0, MAX_BEDROCK_ERROR_BODY_BYTES));
|
|
1632
|
+
oversized = body.length > MAX_BEDROCK_ERROR_BODY_BYTES || bytes.byteLength > MAX_BEDROCK_ERROR_BODY_BYTES;
|
|
1633
|
+
} else if (body instanceof Uint8Array) {
|
|
1634
|
+
bytes = body;
|
|
1635
|
+
oversized = bytes.byteLength > MAX_BEDROCK_ERROR_BODY_BYTES;
|
|
1636
|
+
} else if (body && typeof body === "object" && Symbol.asyncIterator in body) {
|
|
1637
|
+
const readable = body;
|
|
1638
|
+
const iterator = readable[Symbol.asyncIterator]();
|
|
1639
|
+
const chunks = [];
|
|
1640
|
+
let size = 0;
|
|
1641
|
+
let finished = false;
|
|
1642
|
+
let timer;
|
|
1643
|
+
const timeout = timeoutMs ? new Promise((_resolve, reject) => {
|
|
1644
|
+
timer = setTimeout(
|
|
1645
|
+
() => reject(new Error(`Provider error body read timed out after ${timeoutMs}ms`)),
|
|
1646
|
+
timeoutMs
|
|
1647
|
+
);
|
|
1648
|
+
}) : void 0;
|
|
1649
|
+
try {
|
|
1650
|
+
while (true) {
|
|
1651
|
+
const next = iterator.next();
|
|
1652
|
+
const item = await (timeout ? Promise.race([next, timeout]) : next);
|
|
1653
|
+
if (item.done) {
|
|
1654
|
+
finished = true;
|
|
1655
|
+
break;
|
|
1656
|
+
}
|
|
1657
|
+
const chunk = item.value;
|
|
1658
|
+
const retained = chunk.subarray(0, MAX_BEDROCK_ERROR_BODY_BYTES - size);
|
|
1659
|
+
chunks.push(retained);
|
|
1660
|
+
size += retained.byteLength;
|
|
1661
|
+
if (retained.byteLength < chunk.byteLength) {
|
|
1662
|
+
oversized = true;
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
} finally {
|
|
1667
|
+
clearTimeout(timer);
|
|
1668
|
+
if (!finished) {
|
|
1669
|
+
readable.destroy?.();
|
|
1670
|
+
void iterator.return?.().catch(() => {
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
bytes = new Uint8Array(size);
|
|
1675
|
+
let offset = 0;
|
|
1676
|
+
for (const chunk of chunks) {
|
|
1677
|
+
bytes.set(chunk, offset);
|
|
1678
|
+
offset += chunk.byteLength;
|
|
1679
|
+
}
|
|
1680
|
+
} else {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (oversized) {
|
|
1684
|
+
const parsed = parseStreamingJson(
|
|
1685
|
+
new TextDecoder().decode(bytes.subarray(0, MAX_BEDROCK_ERROR_BODY_BYTES))
|
|
1686
|
+
);
|
|
1687
|
+
const code = typeof parsed?.__type === "string" ? parsed.__type.split("#").pop() : void 0;
|
|
1688
|
+
response.body = new TextEncoder().encode(
|
|
1689
|
+
JSON.stringify({
|
|
1690
|
+
...code && BEDROCK_MODELED_ERRORS.has(code) ? { __type: code } : {},
|
|
1691
|
+
message: "Provider error body exceeded 65536 bytes"
|
|
1692
|
+
})
|
|
1693
|
+
);
|
|
1694
|
+
} else {
|
|
1695
|
+
response.body = bytes;
|
|
1696
|
+
}
|
|
1373
1697
|
}
|
|
1374
1698
|
var streamSimple = (model, context, options) => {
|
|
1375
1699
|
const base = {
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import { AccountReporter, type AccountReportTarget, type AccountUsageReport } from "../core/account-reporting.ts";
|
|
3
|
+
import { type AnthropicReportingCredentialProvider } from "../core/anthropic-account-reporting.ts";
|
|
4
|
+
import { type BedrockReportCollectorDeps } from "../core/bedrock-account-reporting.ts";
|
|
5
|
+
import type { ExtensionContext } from "../core/extensions/types.ts";
|
|
6
|
+
import type { ModelRegistry } from "../core/model-registry.ts";
|
|
7
|
+
import type { AccountInfo, AccountSource, ModelRuntime } from "../core/model-runtime.ts";
|
|
8
|
+
import { type NodeAccountFallbackPolicy, type NodeAccountView, type NodeFallbackAssessment } from "./node-account-fallback.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Session-bound bridge that lets Flow drive host-owned account dialogs and catalog readiness.
|
|
11
|
+
* Credentials never cross it: every value is non-secret metadata or a model catalog.
|
|
12
|
+
*/
|
|
13
|
+
export type FlowCatalogState = {
|
|
14
|
+
state: "ready";
|
|
15
|
+
models: readonly Model<Api>[];
|
|
16
|
+
} | {
|
|
17
|
+
state: "unavailable";
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export interface FlowAccountsHost {
|
|
21
|
+
/**
|
|
22
|
+
* Resolves after the user finishes or cancels the account interaction. Cancelling through the signal ends the
|
|
23
|
+
* dialog; sign-ins, account switches and removals already completed stay in effect.
|
|
24
|
+
*/
|
|
25
|
+
openAccounts(signal: AbortSignal): Promise<void>;
|
|
26
|
+
/** Explicit action: refresh the provider's catalog for the selected account, allowing network access. */
|
|
27
|
+
refreshCatalog(providerId: string, signal: AbortSignal): Promise<FlowCatalogState>;
|
|
28
|
+
/**
|
|
29
|
+
* Explicit "Refresh usage" action. The only path that reaches a reporting transport; listing accounts and opening
|
|
30
|
+
* Advanced never call it. Resolves to a labelled report and never throws for unavailable data.
|
|
31
|
+
*/
|
|
32
|
+
refreshAccountUsage(target: AccountReportTarget, signal: AbortSignal): Promise<AccountUsageReport>;
|
|
33
|
+
/** Opt-in HUMAIN Node key fallback: current policy, aliases, labels and setup warnings. No network. */
|
|
34
|
+
getNodeFallback(signal: AbortSignal): Promise<FlowNodeFallbackState>;
|
|
35
|
+
/** Validate and persist policy and labels outside the credential store, then return the new state. */
|
|
36
|
+
updateNodeFallback(update: FlowNodeFallbackUpdate, signal: AbortSignal): Promise<FlowNodeFallbackState>;
|
|
37
|
+
/** Whether `text` contains a stored HUMAIN Node key. Only the answer crosses the bridge, never a key. */
|
|
38
|
+
labelContainsStoredKey(text: string, signal: AbortSignal): Promise<boolean>;
|
|
39
|
+
}
|
|
40
|
+
export declare const FLOW_ACCOUNTS_UNAVAILABLE = "Account interaction unavailable";
|
|
41
|
+
/** Bind a host to the registry of the current session. Rebinding supersedes the previous generation. */
|
|
42
|
+
export declare function bindFlowAccountsHost(registry: ModelRegistry, host: FlowAccountsHost): () => void;
|
|
43
|
+
/** Look up the host by actual registry identity. Only the terminal UI owns secure dialogs. */
|
|
44
|
+
export declare function getFlowAccountsHost(ctx: Pick<ExtensionContext, "modelRegistry" | "mode">): FlowAccountsHost | undefined;
|
|
45
|
+
/** Secret-free account metadata. `endpoint` is the HUMAIN Node base URL; `region` the stored Bedrock region. */
|
|
46
|
+
export interface FlowAccountMetadata extends AccountInfo {
|
|
47
|
+
endpoint?: string;
|
|
48
|
+
region?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface FlowAccountSourceMetadata extends AccountSource {
|
|
51
|
+
endpoint?: string;
|
|
52
|
+
/** Stored Bedrock region of the auth.json provider configuration. */
|
|
53
|
+
region?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface FlowProviderAccountMetadata {
|
|
56
|
+
providerId: string;
|
|
57
|
+
accounts: FlowAccountMetadata[];
|
|
58
|
+
sources: FlowAccountSourceMetadata[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Enumerate accounts and sources from stored metadata only. This never resolves credentials, refreshes OAuth,
|
|
62
|
+
* runs credential commands, or touches the network; `accounts.list/sources` are side-effect-free by contract.
|
|
63
|
+
*/
|
|
64
|
+
export declare function listFlowAccountMetadata(runtime: ModelRuntime, providerId: string, signal: AbortSignal, ambientEnv?: NodeJS.ProcessEnv): Promise<FlowProviderAccountMetadata>;
|
|
65
|
+
export declare const NODE_USAGE_UNSUPPORTED = "Usage reporting is not yet supported for HUMAIN Node.";
|
|
66
|
+
export declare const BEDROCK_USAGE_NOTE = "Usage reporting reads Amazon CloudWatch metrics and needs AWS credentials saved through Connect, with a region. A Bedrock API key cannot report usage.";
|
|
67
|
+
export declare const FLOW_ACCOUNT_PERSISTENCE_NOTICE = "Sign-in and account changes take effect immediately and are not undone by cancelling setup.";
|
|
68
|
+
/** Advanced details for the selected provider. Configured and effective never mean verified. */
|
|
69
|
+
export declare function formatFlowAccountAdvanced(providerId: string, providerName: string, metadata: FlowProviderAccountMetadata): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Wait for the selected key's catalog. HUMAIN Node discovery uses the network, so call this only after an explicit
|
|
72
|
+
* account or catalog action. Anything short of a fresh, non-empty catalog for the same selected key is unavailable;
|
|
73
|
+
* models are never invented or carried over from another key.
|
|
74
|
+
*/
|
|
75
|
+
export declare function refreshFlowCatalog(runtime: ModelRuntime, providerId: string, signal: AbortSignal): Promise<FlowCatalogState>;
|
|
76
|
+
/** Secret-free state for the Node fallback setup step. `accounts` lists stored Node API-key accounts in pool order. */
|
|
77
|
+
export interface FlowNodeFallbackState extends NodeFallbackAssessment {
|
|
78
|
+
policy: Required<NodeAccountFallbackPolicy>;
|
|
79
|
+
accounts: NodeAccountView[];
|
|
80
|
+
}
|
|
81
|
+
export interface FlowNodeFallbackUpdate {
|
|
82
|
+
policy?: Partial<NodeAccountFallbackPolicy>;
|
|
83
|
+
/** Per account key. `null` clears a label. */
|
|
84
|
+
labels?: Record<string, {
|
|
85
|
+
nodeUser?: string | null;
|
|
86
|
+
environment?: string | null;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/** Read the policy and labels. Uses stored metadata only: no credential resolution, refresh or network access. */
|
|
90
|
+
export declare function readFlowNodeFallbackState(runtime: ModelRuntime, signal: AbortSignal, ambientEnv?: NodeJS.ProcessEnv): Promise<FlowNodeFallbackState>;
|
|
91
|
+
/** True when `text` would embed a stored Node API key. Stored metadata only: no refresh, no network. */
|
|
92
|
+
export declare function nodeLabelContainsStoredKey(runtime: ModelRuntime, text: string, signal: AbortSignal): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Persist the opt-in fallback policy and user labels. Keys are only referenced by their stored account key; unknown
|
|
95
|
+
* or duplicate keys, oversized or key-bearing labels are rejected before anything is written.
|
|
96
|
+
*/
|
|
97
|
+
export declare function updateFlowNodeFallback(runtime: ModelRuntime, update: FlowNodeFallbackUpdate, signal: AbortSignal, ambientEnv?: NodeJS.ProcessEnv): Promise<FlowNodeFallbackState>;
|
|
98
|
+
/** Providers whose Advanced view offers "Refresh usage". Node reports its own exact unsupported text instead. */
|
|
99
|
+
export declare const FLOW_USAGE_REPORTING_PROVIDERS: ReadonlySet<string>;
|
|
100
|
+
export interface FlowAccountReporterOptions {
|
|
101
|
+
/**
|
|
102
|
+
* Explicitly provisioned Anthropic Admin API reporting credentials. The host has no supported secure provisioning
|
|
103
|
+
* for them today, so this is normally absent and organization reporting reads "reporting credentials not configured".
|
|
104
|
+
*/
|
|
105
|
+
organizationCredentials?: AnthropicReportingCredentialProvider;
|
|
106
|
+
fetch?: typeof fetch;
|
|
107
|
+
now?: () => number;
|
|
108
|
+
/** SDK client factory for Bedrock CloudWatch reporting. Defaults to the official AWS SDK client. */
|
|
109
|
+
openBedrockClient?: BedrockReportCollectorDeps["openClient"];
|
|
110
|
+
}
|
|
111
|
+
/** Build the session reporter. Nothing is fetched or resolved until `refreshAccountUsage` is called. */
|
|
112
|
+
export declare function createFlowAccountReporter(runtime: ModelRuntime, options?: FlowAccountReporterOptions): AccountReporter;
|
|
113
|
+
/** UTC calendar day containing `now`: the reporting period for window-based sources. */
|
|
114
|
+
export declare function utcDayPeriod(now: number): AccountReportTarget["period"];
|
|
115
|
+
/**
|
|
116
|
+
* Targets for "Refresh usage" from stored metadata: the selected account (Bedrock: with its stored region), plus
|
|
117
|
+
* Anthropic organization reporting as its own source. `openai` API accounts and every other provider have none: their usage is never inferred.
|
|
118
|
+
*/
|
|
119
|
+
export declare function flowUsageTargets(providerId: string, metadata: FlowProviderAccountMetadata, now: number): AccountReportTarget[];
|
|
120
|
+
//# sourceMappingURL=flow-accounts-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-accounts-host.d.ts","sourceRoot":"","sources":["../../src/humain/flow-accounts-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEN,KAAK,oCAAoC,EAGzC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAGN,KAAK,0BAA0B,EAI/B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAKN,KAAK,yBAAyB,EAE9B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,MAAM,4BAA4B,CAAC;AAGpC;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACzB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAA;CAAE,GACjD;IAAE,KAAK,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,yGAAyG;IACzG,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,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