@humain/humain-code 0.4.8 → 0.4.9
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 +22 -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 +70 -47
- package/dist/bundle/chunks/{chunk-TIAXGIMN.js → chunk-4LAKI5IL.js} +9 -9
- 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-GNOKILVU.js → chunk-6FVNSW6B.js} +88 -65
- package/dist/bundle/chunks/{chunk-RXHSJSYY.js → chunk-6KAMTNN3.js} +1 -1
- package/dist/bundle/chunks/{chunk-SKIP6KJV.js → chunk-7Z5MWPYE.js} +1 -1
- 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-ROSZII6E.js → chunk-EMYNPLY5.js} +1 -1
- package/dist/bundle/chunks/{chunk-PYU5BR3Z.js → chunk-JOKJ3CEL.js} +2 -2
- package/dist/bundle/chunks/chunk-MVYV6MJY.js +23 -0
- package/dist/bundle/chunks/{chunk-ILRBME2Y.js → chunk-P4YMUUSK.js} +314 -311
- package/dist/bundle/chunks/{chunk-PBBQBIHY.js → chunk-RBKDBF5G.js} +1 -1
- package/dist/bundle/chunks/{chunk-YURQPD6Y.js → chunk-RYC5BYVE.js} +1 -2
- package/dist/bundle/chunks/chunk-VEYTRNQC.js +5 -0
- 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/{cloudflare-workers-ai-system-one-YPOLSCPT.js → cloudflare-workers-ai-system-one-FZ3UQCZ7.js} +1 -1
- package/dist/bundle/chunks/{compat-J5FTRJ6S.js → compat-HEUVP6UJ.js} +3 -3
- package/dist/bundle/chunks/{dist-6FQCCUSC.js → dist-NU2EIVT6.js} +485 -446
- package/dist/bundle/chunks/{dist-N7XDUAAO.js → dist-VNSMKBZ6.js} +3 -3
- package/dist/bundle/chunks/{extract-56PXVZVW.js → extract-PYRMDATF.js} +2 -2
- package/dist/bundle/chunks/{google-generative-ai-TS4ZE2RO.js → google-generative-ai-H2F5Y5H2.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-MJK2SMNE.js → google-vertex-LFWD2AOO.js} +3 -3
- package/dist/bundle/chunks/host-6ZA6LK4C.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/{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/{typesafe-system-one-PAYJECQK.js → typesafe-system-one-TTC7YCO3.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-TT2VTOSY.js → virtual-modules-NPWQ6NBS.js} +2 -2
- package/dist/bundle/cli-runtime.js +2 -2
- package/dist/bundle/flow/assets/contract.json +1 -1
- package/dist/bundle/flow/package.json +1 -1
- package/dist/bundle/index.js +5 -5
- package/dist/bundle/rpc-entry.js +2 -2
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +353 -29
- package/docs/flow.md +12 -9
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -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/host-2ARI7PQ5.js +0 -2
- package/dist/bundle/chunks/openai-responses-LNSCERKH.js +0 -23
|
@@ -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 = {
|
package/docs/flow.md
CHANGED
|
@@ -24,7 +24,7 @@ Flags are honored only before or after the goal text. A `--flag` between goal wo
|
|
|
24
24
|
|
|
25
25
|
Auto mode:
|
|
26
26
|
|
|
27
|
-
-
|
|
27
|
+
- Frozen Flow runs classify the goal with rules first. SMALL and MEDIUM start one implementer without LLM triage. Rules-large runs may use LLM triage to refine the size; an explicit admission size skips triage.
|
|
28
28
|
- There is no approval step. Runs auto-approve by default. `--yes` and `-y` are accepted as no-ops.
|
|
29
29
|
- The command parses flags and starts the run in the background; the command handler returns while the run continues. Triage and workflow signal collection run inside the run, so the first dispatch is not instant.
|
|
30
30
|
|
|
@@ -35,12 +35,14 @@ Flow has four workflow levels: `direct`, `checked`, `led`, `full`.
|
|
|
35
35
|
| Size | Workflow | Meaning |
|
|
36
36
|
|---|---|---|
|
|
37
37
|
| small | `checked` | one implementer plus deterministic repo checks |
|
|
38
|
-
| medium | `
|
|
38
|
+
| medium | `checked` | the SMALL pipeline until evaluation justifies a separate tier |
|
|
39
39
|
| large | `full` | architect, recon, several leads, review, QA |
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
SMALL and MEDIUM dispatch exactly one implementer, then deterministic checks. They dispatch no architect, scouts, lead, independent reviewer, LLM QA, or repair agent. Missing or unavailable checks are never replaced with an LLM verdict. When a run discovers no checks, or its only non-passing checks are provably unavailable in this environment, verification passes with `evidence_status: unverified_checks_unavailable` and a verification warning; it is never reported as verified. Real check failures still fail the run, pre-existing failures settle as warnings, and recovery runs still require real checks. Scope and candidate-integrity checks still apply.
|
|
42
42
|
|
|
43
|
-
A
|
|
43
|
+
A legacy `checked` run outside this size-based pipeline in a repository with no discovered deterministic checks passes when the independent review passes. It reports `evidence_status: unverified_checks_unavailable` as a warning in the run summary, `run.log`, and the ledger, and starts no repair. A review FAIL still fails. `direct` runs and continuations or recovery runs still require deterministic checks.
|
|
44
|
+
|
|
45
|
+
A `led` or `full` run with no discoverable deterministic checks settles the same way when the mandatory independent review passes and QA passes: `succeeded` with `evidence_status: unverified_checks_unavailable` as a warning, one QA dispatch, and no repair. A QA FAIL or review FAIL still fails the run. If checks appear during the run (at the run root, git root, verify root, or a changed file's package directories), the exception no longer applies. When no round was attested, the report's verification target shows the last observed candidate identity with `, not attested`, and prints `HEAD unborn` for a tree without commits.
|
|
44
46
|
|
|
45
47
|
Before any agent changes the candidate, Flow runs each discovered deterministic check once on the untouched tree (baseline). A check that fails after the change with only failures it already had at baseline (same check, configuration and exit code, no new diagnostic) is pre-existing and does not fail the run; a check that newly fails or gains any new diagnostic still fails and goes through repair. CLI and web runs behave the same: the run summary names the pre-existing checks, states that Flow did not change files to fix them, and suggests a follow-up run to fix them; the ledger gets a content-free `warning` event (`preexisting_check_failures`, opaque check ids only). Flow does not repair pre-existing failures within the run. The baseline runs before the run-start change observation, so files the checks write (for example `tsbuildinfo`, caches, snapshots) are not counted as the run's changes. Read-only tasks, runs without discovered deterministic checks, continuations and recovery runs take no baseline.
|
|
46
48
|
|
|
@@ -48,9 +50,9 @@ The candidate identity normally comes from git. When git is missing (`ENOENT`) o
|
|
|
48
50
|
|
|
49
51
|
Each run writes its diagnostics under `<STATE_ROOT>/runs/<runId>/`. A repeated dispatch with the same task id (for example a QA re-dispatch) writes its stderr log as `<taskId>.attempt-N.stderr.log` (N = 2, 3, ...); the first attempt keeps `<taskId>.stderr.log`. `<taskId>.events.jsonl` and `<taskId>.prompt.md` are shared across attempts.
|
|
50
52
|
|
|
51
|
-
The
|
|
53
|
+
The run path uses `decideSize` and `sizeToWorkflow`. Telemetry retains the classified size (`medium` remains `medium`) even when SMALL and MEDIUM share the same execution pipeline.
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
For LARGE and legacy runs, workflow routing still applies:
|
|
54
56
|
|
|
55
57
|
- A router reads repository evidence: risk path globs, interface changes across packages, candidate file count, nearby tests, and discovered checks. High risk or a protected path forces `full`. Wide scope or unresolved scope gives `led`. A single localized low-risk file with tests gives `direct`. Otherwise `checked`.
|
|
56
58
|
- The workflow mode controls how much of this applies: `off` (no routing), `observe` (default in `method.json`; plans and records, runs lead/full hierarchy), `enforce` (also runs the flat `direct`/`checked` path). Show or persist it with `/flow-models workflow [off|observe|enforce|default]`. The env var `HUMAIN_ORCHESTRATOR_WORKFLOW_MODE` overrides the saved setting.
|
|
@@ -59,14 +61,15 @@ What `/flow` does today to pick a level:
|
|
|
59
61
|
|
|
60
62
|
### Size override
|
|
61
63
|
|
|
62
|
-
There is still no user-facing `--size` flag on `/flow` (`--size` in the goal is not applied; see warning above). A size override comes only from a `FlowRunAdmissionV1` `sizeOverride` (`hc --flow-admission <file>`). With
|
|
64
|
+
There is still no user-facing `--size` flag on `/flow` (`--size` in the goal is not applied; see warning above). A size override comes only from a `FlowRunAdmissionV1` `sizeOverride` (`hc --flow-admission <file>`). With admission `sizeOverride: "small"` or `"medium"`, the run uses one implementer and deterministic checks regardless of advisory workflow floors. Only an explicit implementer scope-growth report can request the LARGE pipeline; actual out-of-candidate writes still block verification. A user-facing CLI `--size` flag is `(planned)` (plan section 3 A3 deliverable 3; section 3 D2 deliverable 1).
|
|
63
65
|
|
|
64
66
|
### Escalation
|
|
65
67
|
|
|
66
|
-
- A fresh
|
|
68
|
+
- A fresh SMALL or MEDIUM run can escalate once to LARGE when the implementer's final report ends with `SCOPE_GROWTH: large`, a blank line, and `STATUS: partial` or `STATUS: completed`. The profile must allow escalation, and scope safety and retry-budget gates still apply. Deterministic check failures alone never trigger this transition.
|
|
69
|
+
- A legacy flat run (`direct`/`checked`) can escalate once to `led` when progress-aware repair requests escalation and retry budget remains. Prior work and failure evidence carry forward. An escalated re-run is never escalated flat again. This only applies in `enforce` mode, because flat runs happen only there.
|
|
67
70
|
- Escalation is not guaranteed. Provider failures, unsafe or unverified scope, blocked work, a read-only task, and an exhausted or explicit retry budget can stop the run without escalation (`src/pipeline/run-orchestration.ts:3090-3137,3351-3365`; `src/pipeline/repair-policy.ts:130-144`).
|
|
68
71
|
- On verification failure, retry leads can move up one lead capability tier.
|
|
69
|
-
-
|
|
72
|
+
- SMALL/MEDIUM scope-growth transitions emit the original size and destination `large` in escalation telemetry. LARGE keeps its existing architecture and verification pipeline.
|
|
70
73
|
|
|
71
74
|
## `--profile`
|
|
72
75
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humain/humain-code",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@humain/humain-code",
|
|
9
|
-
"version": "0.4.
|
|
9
|
+
"version": "0.4.9",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@humain/humain-code-contracts": "0.4.
|
|
12
|
+
"@humain/humain-code-contracts": "0.4.9",
|
|
13
13
|
"@aws-sdk/client-bedrock-runtime": "3.1146.0",
|
|
14
14
|
"@earendil-works/pi-agent-core": "1.1.0",
|
|
15
15
|
"@earendil-works/pi-ai": "1.1.0",
|
|
@@ -1024,9 +1024,9 @@
|
|
|
1024
1024
|
"hasInstallScript": true
|
|
1025
1025
|
},
|
|
1026
1026
|
"node_modules/@humain/humain-code-contracts": {
|
|
1027
|
-
"version": "0.4.
|
|
1028
|
-
"resolved": "https://registry.npmjs.org/@humain/humain-code-contracts/-/humain-code-contracts-0.4.
|
|
1029
|
-
"integrity": "sha512-
|
|
1027
|
+
"version": "0.4.9",
|
|
1028
|
+
"resolved": "https://registry.npmjs.org/@humain/humain-code-contracts/-/humain-code-contracts-0.4.9.tgz",
|
|
1029
|
+
"integrity": "sha512-I/faw9SaHLRwJYusadiDCdcm/Das0ISRLX9QrHlKeYIYHjvn6MffFMzp9PMJbT1AEiZIjeO7bXfNsmr198t73A==",
|
|
1030
1030
|
"license": "MIT",
|
|
1031
1031
|
"dependencies": {
|
|
1032
1032
|
"typebox": "1.3.35"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humain/humain-code",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"humainTerminalConfig": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"prepublishOnly": "npm run clean && npm run build && npm run shrinkwrap"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@humain/humain-code-contracts": "0.4.
|
|
89
|
+
"@humain/humain-code-contracts": "0.4.9",
|
|
90
90
|
"@aws-sdk/client-bedrock-runtime": "3.1146.0",
|
|
91
91
|
"@earendil-works/pi-agent-core": "1.1.0",
|
|
92
92
|
"@earendil-works/pi-ai": "1.1.0",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
var MAX_SEQUENCE=(1n<<41n)-1n,lastOrdinaryTimestamp=-1,sequence;function uuidv7(timestampMs){let requestedTimestamp=timestampMs??Date.now();if(!Number.isInteger(requestedTimestamp)||requestedTimestamp<0||requestedTimestamp>0xffffffffffff)throw new RangeError(`UUIDv7 timestamp must be an integer between 0 and ${0xffffffffffff}`);let effectiveTimestamp=timestampMs===void 0?Math.max(requestedTimestamp,lastOrdinaryTimestamp):timestampMs;timestampMs===void 0&&(lastOrdinaryTimestamp=effectiveTimestamp);
|
|
3
|
-
let bytes=new Uint8Array(16);if(globalThis.crypto.getRandomValues(bytes),sequence===void 0)sequence=BigInt(bytes[1])<<32n|BigInt(bytes[2])<<24n|BigInt(bytes[3])<<16n|BigInt(bytes[4])<<8n|BigInt(bytes[5]);else{if(sequence===MAX_SEQUENCE)throw new RangeError("UUIDv7 generator sequence exhausted");sequence++}let timestamp=BigInt(effectiveTimestamp);for(let index=5;index>=0;index--)bytes[index]=Number(timestamp>>BigInt((5-index)*8))&255;bytes[6]=112|Number(sequence>>37n&0x0fn),bytes[7]=Number(sequence>>
|
|
4
|
-
29n&0xffn),bytes[8]=128|Number(sequence>>23n&0x3fn),bytes[9]=Number(sequence>>15n&0xffn),bytes[10]=Number(sequence>>7n&0xffn),bytes[11]=Number((sequence&0x7fn)<<1n)|bytes[11]&1;let hex=Array.from(bytes,byte=>byte.toString(16).padStart(2,"0"));return`${hex.slice(0,4).join("")}-${hex.slice(4,6).join("")}-${hex.slice(6,8).join("")}-${hex.slice(8,10).join("")}-${hex.slice(10).join("")}`}export{uuidv7};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
function normalizeProviderError(error){if(!(error instanceof Error))return{message:safeJsonStringify(error),messageCarriesBody:!1};let sdkError=error,status=extractStatus(sdkError),body=extractBody(sdkError),messageCarriesBody=body===void 0||error.message.includes(body);return{status,body,message:error.message,messageCarriesBody}}function extractStatus(error){if(typeof error.statusCode=="number")return error.statusCode;if(typeof error.status=="number")return error.status;if(typeof error.$metadata?.
|
|
3
|
-
httpStatusCode=="number")return error.$metadata.httpStatusCode;if(typeof error.$response?.statusCode=="number")return error.$response.statusCode}function extractBody(error){let bodyText=pickBodyText(error);if(bodyText===void 0)return;let trimmed=bodyText.trim();if(trimmed.length!==0)return truncateErrorText(trimmed,4e3)}function pickBodyText(error){if(typeof error.body=="string")return error.body;if(isPlainNonEmptyObject(error.error))return safeJsonStringify(error.error);let responseBody=error.$response?.
|
|
4
|
-
body;if(typeof responseBody=="string")return responseBody;if(!isReadableStreamLike(responseBody)&&isPlainNonEmptyObject(responseBody))return safeJsonStringify(responseBody)}function isReadableStreamLike(value){return typeof value=="object"&&value!==null&&"pipe"in value&&typeof value.pipe=="function"}function isPlainNonEmptyObject(value){if(typeof value!="object"||value===null)return!1;let proto=Object.getPrototypeOf(value);return proto!==Object.prototype&&proto!==null?!1:Object.keys(value).length>
|
|
5
|
-
0}function formatProviderError(norm,prefix){return norm.messageCarriesBody||norm.status===void 0||norm.body===void 0?prefix!==void 0&&norm.status!==void 0?`${prefix} (${norm.status}): ${norm.message}`:norm.message:prefix!==void 0?`${prefix} (${norm.status}): ${norm.body}`:`${norm.status}: ${norm.body}`}function truncateErrorText(text,maxChars){return text.length<=maxChars?text:`${text.slice(0,maxChars)}... [truncated ${text.length-maxChars} chars]`}function safeJsonStringify(value){try{let serialized=JSON.
|
|
6
|
-
stringify(value);return serialized===void 0?String(value):serialized}catch{return String(value)}}export{normalizeProviderError,formatProviderError};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
function isProviderError(error){return!(error instanceof Error)||!("status"in error)||!("headers"in error)?!1:(error.status===void 0||typeof error.status=="number")&&(error.headers===void 0||error.headers instanceof Headers)}function isRetryableProviderError(error){let shouldRetry=error.headers?.get("x-should-retry");return shouldRetry==="true"?!0:shouldRetry==="false"?!1:error.status===void 0?!0:error.status===408||error.status===409||error.status===429||typeof error.status=="number"&&error.status>=
|
|
3
|
-
500}function validateServerRetryDelayMs(delayMs,maxRetryDelayMs,providerErrorMessage){let maxDelayMs=maxRetryDelayMs??6e4;if(maxDelayMs>0&&delayMs>maxDelayMs)throw new Error(`Server requested ${Math.ceil(delayMs/1e3)}s retry delay (max: ${Math.ceil(maxDelayMs/1e3)}s). ${providerErrorMessage}`);return delayMs}function getRetryDelayMs(error,retryIndex,maxRetryDelayMs){let retryAfterMs=error.headers?.get("retry-after-ms");if(retryAfterMs){let value=Number.parseFloat(retryAfterMs);if(Number.isFinite(
|
|
4
|
-
value))return validateServerRetryDelayMs(value,maxRetryDelayMs,error.message)}let retryAfter=error.headers?.get("retry-after");if(retryAfter){let seconds=Number.parseFloat(retryAfter),delayMs=Number.isNaN(seconds)?Date.parse(retryAfter)-Date.now():seconds*1e3;if(Number.isFinite(delayMs))return validateServerRetryDelayMs(delayMs,maxRetryDelayMs,error.message)}return Math.min(.5*2**retryIndex,8)*1e3*(1-Math.random()*.25)}function createAbortError(){let error=new Error("Request aborted");return error.
|
|
5
|
-
name="AbortError",error}function abortableSleep(ms,signal){return new Promise((resolve,reject)=>{if(signal?.aborted){reject(createAbortError());return}let onAbort=()=>{clearTimeout(timeout),reject(createAbortError())},timeout=setTimeout(()=>{signal?.removeEventListener("abort",onAbort),resolve()},Math.max(0,ms));signal?.addEventListener("abort",onAbort,{once:!0})})}async function retryProviderRequest(request,options={}){let maxRetries=options.maxRetries??0,retriesRemaining=maxRetries;for(;;)try{
|
|
6
|
-
return await request()}catch(error){if(options.signal?.aborted)throw createAbortError();if(retriesRemaining<=0||!isProviderError(error)||!isRetryableProviderError(error)||error.status!==void 0&&options.noRetryStatuses?.includes(error.status))throw error;let retryIndex=maxRetries-retriesRemaining;retriesRemaining--,await abortableSleep(getRetryDelayMs(error,retryIndex,options.maxRetryDelayMs),options.signal)}}export{retryProviderRequest};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{buildSessionContext,resizeImage}from"./chunk-ROSZII6E.js";import{getAgentDir}from"./chunk-3E4SMILM.js";import"./chunk-OTXURGIO.js";import"./chunk-DBL35X7L.js";import"./chunk-GVVRXZHN.js";import"./chunk-WPLW452J.js";import"./chunk-YURQPD6Y.js";import"./chunk-AKA7HNO3.js";import"./chunk-QMUIATLD.js";import"./chunk-BHM75BJJ.js";import"./chunk-JXWJOIH4.js";export{buildSessionContext,getAgentDir,resizeImage};
|