@humain/humain-code 0.5.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/README.md +5 -3
  3. package/dist/agent-monitor/client.d.ts +2 -2
  4. package/dist/agent-monitor/client.d.ts.map +1 -1
  5. package/dist/agent-monitor/client.js +3 -2
  6. package/dist/agent-monitor/client.js.map +1 -1
  7. package/dist/bundle/chunks/anthropic.js +10 -9
  8. package/dist/bundle/chunks/{chunk-DR37WKFZ.js → chunk-AO6FF5JL.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-Q3SFYT2X.js → chunk-EY3LZOUP.js} +1356 -1358
  10. package/dist/bundle/chunks/{chunk-T3HXWZG4.js → chunk-L2VKM23Q.js} +76 -2
  11. package/dist/bundle/chunks/{chunk-5C4VL2AR.js → chunk-ODJUBJK2.js} +2 -2
  12. package/dist/bundle/chunks/{chunk-A6YBWW4T.js → chunk-UJLCKIMZ.js} +646 -495
  13. package/dist/bundle/chunks/{chunk-476XBL3W.js → chunk-Y3OPKKDR.js} +3 -77
  14. package/dist/bundle/chunks/{cli-VXU7OWFU.js → cli-ENEFJH2B.js} +1 -1
  15. package/dist/bundle/chunks/{compat-S2IBVV6V.js → compat-CJBWWYHE.js} +1 -1
  16. package/dist/bundle/chunks/{dist-645GFIWH.js → dist-RKNCFFGM.js} +2 -2
  17. package/dist/bundle/chunks/github-copilot.js +28 -26
  18. package/dist/bundle/chunks/openai-chatgpt.js +2 -2
  19. package/dist/bundle/chunks/openai-codex.js +10 -9
  20. package/dist/bundle/chunks/openrouter.js +10 -9
  21. package/dist/bundle/chunks/radius.js +9 -8
  22. package/dist/bundle/chunks/{runtime-5VFZTMWL.js → runtime-K3F2QDQP.js} +1 -1
  23. package/dist/bundle/chunks/{virtual-modules-GU6AW5ZK.js → virtual-modules-5D6QIJPN.js} +2 -2
  24. package/dist/bundle/cli-runtime.js +1 -1
  25. package/dist/bundle/index.js +4 -4
  26. package/dist/bundle/rpc-entry.js +1 -1
  27. package/dist/core/model-resolver.d.ts.map +1 -1
  28. package/dist/core/model-resolver.js +19 -1
  29. package/dist/core/model-resolver.js.map +1 -1
  30. package/dist/core/model-runtime.d.ts.map +1 -1
  31. package/dist/core/model-runtime.js +24 -2
  32. package/dist/core/model-runtime.js.map +1 -1
  33. package/dist/core/safe-credential-error.d.ts +11 -0
  34. package/dist/core/safe-credential-error.d.ts.map +1 -0
  35. package/dist/core/safe-credential-error.js +14 -0
  36. package/dist/core/safe-credential-error.js.map +1 -0
  37. package/dist/core/sdk.d.ts.map +1 -1
  38. package/dist/core/sdk.js +4 -1
  39. package/dist/core/sdk.js.map +1 -1
  40. package/dist/core/settings-schema.d.ts +3 -0
  41. package/dist/core/settings-schema.d.ts.map +1 -1
  42. package/dist/core/settings-schema.js +6 -0
  43. package/dist/core/settings-schema.js.map +1 -1
  44. package/dist/humain/gateway/catalog.d.ts +36 -0
  45. package/dist/humain/gateway/catalog.d.ts.map +1 -0
  46. package/dist/humain/gateway/catalog.js +74 -0
  47. package/dist/humain/gateway/catalog.js.map +1 -0
  48. package/dist/humain/gateway/client.d.ts +58 -0
  49. package/dist/humain/gateway/client.d.ts.map +1 -0
  50. package/dist/humain/gateway/client.js +212 -0
  51. package/dist/humain/gateway/client.js.map +1 -0
  52. package/dist/humain/gateway/constants.d.ts +23 -0
  53. package/dist/humain/gateway/constants.d.ts.map +1 -0
  54. package/dist/humain/gateway/constants.js +32 -0
  55. package/dist/humain/gateway/constants.js.map +1 -0
  56. package/dist/humain/gateway/http.d.ts +18 -0
  57. package/dist/humain/gateway/http.d.ts.map +1 -0
  58. package/dist/humain/gateway/http.js +274 -0
  59. package/dist/humain/gateway/http.js.map +1 -0
  60. package/dist/humain/gateway/login.d.ts +13 -0
  61. package/dist/humain/gateway/login.d.ts.map +1 -0
  62. package/dist/humain/gateway/login.js +121 -0
  63. package/dist/humain/gateway/login.js.map +1 -0
  64. package/dist/humain/gateway/provider.d.ts +34 -0
  65. package/dist/humain/gateway/provider.d.ts.map +1 -0
  66. package/dist/humain/gateway/provider.js +253 -0
  67. package/dist/humain/gateway/provider.js.map +1 -0
  68. package/dist/humain/gateway/secret-store.d.ts +19 -0
  69. package/dist/humain/gateway/secret-store.d.ts.map +1 -0
  70. package/dist/humain/gateway/secret-store.js +252 -0
  71. package/dist/humain/gateway/secret-store.js.map +1 -0
  72. package/dist/humain/gateway/session-store.d.ts +42 -0
  73. package/dist/humain/gateway/session-store.d.ts.map +1 -0
  74. package/dist/humain/gateway/session-store.js +175 -0
  75. package/dist/humain/gateway/session-store.js.map +1 -0
  76. package/dist/humain/index.d.ts.map +1 -1
  77. package/dist/humain/index.js +2 -0
  78. package/dist/humain/index.js.map +1 -1
  79. package/dist/humain/login-menu.d.ts +14 -0
  80. package/dist/humain/login-menu.d.ts.map +1 -0
  81. package/dist/humain/login-menu.js +21 -0
  82. package/dist/humain/login-menu.js.map +1 -0
  83. package/dist/humain/node-http.d.ts.map +1 -1
  84. package/dist/humain/node-http.js +6 -31
  85. package/dist/humain/node-http.js.map +1 -1
  86. package/dist/humain/redact-assistant-message.d.ts +4 -0
  87. package/dist/humain/redact-assistant-message.d.ts.map +1 -0
  88. package/dist/humain/redact-assistant-message.js +34 -0
  89. package/dist/humain/redact-assistant-message.js.map +1 -0
  90. package/dist/main.d.ts.map +1 -1
  91. package/dist/main.js +17 -4
  92. package/dist/main.js.map +1 -1
  93. package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
  94. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  95. package/dist/modes/interactive/components/login-dialog.js +3 -2
  96. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  97. package/dist/modes/interactive/components/model-selector.d.ts +11 -0
  98. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  99. package/dist/modes/interactive/components/model-selector.js +16 -3
  100. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  101. package/dist/modes/interactive/components/radius-login-selector.d.ts +5 -4
  102. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
  103. package/dist/modes/interactive/components/radius-login-selector.js +11 -9
  104. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
  105. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  106. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  107. package/dist/modes/interactive/interactive-mode.js +53 -36
  108. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  109. package/dist/utils/sleep.d.ts +1 -1
  110. package/dist/utils/sleep.d.ts.map +1 -1
  111. package/dist/utils/sleep.js +10 -6
  112. package/dist/utils/sleep.js.map +1 -1
  113. package/docs/assets/humain-code-logo.svg +8 -0
  114. package/docs/humain-code.md +13 -1
  115. package/docs/index.md +1 -1
  116. package/docs/models.md +3 -1
  117. package/docs/providers.md +58 -2
  118. package/docs/quickstart.md +8 -1
  119. package/npm-shrinkwrap.json +2 -2
  120. package/package.json +1 -1
  121. package/schemas/settings.schema.json +19 -0
@@ -1 +1 @@
1
- {"version":3,"file":"node-http.js","sourceRoot":"","sources":["../../src/humain/node-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,UAAU,GAKV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,SAAS,WAAW,CAAC,KAAc;IAClC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5G,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC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AS,IAAI,iBAAiB,SAAS,EAAE;qBACzC;yBACC,MAAM,CAAC,OAAO,CAAC;yBACf,IAAI,CAAC,IAAI,CAAC,CACZ,CAAC;oBACF,IAAI,SAAS,EAAE,CAAC;wBACf,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG;4BACzB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;4BAClC,EAAE,IAAI,EAAE,qBAAqB,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;yBAC1E,CAAC;oBACH,CAAC;gBACF,CAAC;gBACD,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;IACN,CAAC,CAAC,CAAC;IACJ,OAAO;QACN,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC;QACxE,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;KAC7E,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEvent,\n\ttype JsonObject,\n\ttype JsonValue,\n\tlazyStream,\n\ttype Model,\n\ttype ProviderStreams,\n\ttype SimpleStreamOptions,\n\ttype TranscriptContext,\n} from \"@earendil-works/pi-ai\";\nimport { classifyNodeAccountFailure } from \"./node-account-failure.ts\";\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (value === null || typeof value === \"boolean\" || typeof value === \"number\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (typeof value !== \"object\") return false;\n\treturn Object.values(value).every(isJsonValue);\n}\n\nconst PERMANENT_LIMIT_CODES = new Set([\n\t\"weekly_cap_exceeded\",\n\t\"quota_exceeded\",\n\t\"partner_credit_limit_exceeded\",\n\t\"insufficient_quota\",\n\t\"billing_hard_limit_reached\",\n]);\n\nexport function withHumainNodeHttp(api: ProviderStreams): ProviderStreams {\n\tconst run = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: SimpleStreamOptions | undefined,\n\t\tsimple: boolean,\n\t) =>\n\t\tlazyStream(model, async () => {\n\t\t\tlet httpError: JsonObject | undefined;\n\t\t\tlet requestId: string | null = null;\n\t\t\tlet retryAfter: string | null = null;\n\t\t\tconst key = options?.apiKey;\n\t\t\tconst redact = (value: string): string => (key ? value.replaceAll(key, \"[redacted]\") : value);\n\t\t\tconst redactJson = (value: JsonValue): JsonValue => {\n\t\t\t\tif (typeof value === \"string\") return redact(value);\n\t\t\t\tif (Array.isArray(value)) return value.map(redactJson);\n\t\t\t\tif (value !== null && typeof value === \"object\") {\n\t\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t\tObject.entries(value).map(([name, value]) => [redact(name), redactJson(value)]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t};\n\t\t\tconst fetcher = options?.fetch ?? globalThis.fetch;\n\t\t\tconst requestOptions = {\n\t\t\t\t...options,\n\t\t\t\t// The Anthropic adapter must not interpret a gateway key as an OAuth token.\n\t\t\t\tapiKey: model.api === \"anthropic-messages\" ? \"humain-node\" : key,\n\t\t\t\tfetch: async (input: Parameters<typeof fetch>[0], init?: RequestInit): Promise<Response> => {\n\t\t\t\t\tconst headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));\n\t\t\t\t\tif (key) headers.set(\"Authorization\", `Bearer ${key}`);\n\t\t\t\t\theaders.delete(\"x-api-key\");\n\t\t\t\t\tif (model.api === \"anthropic-messages\") {\n\t\t\t\t\t\t// The SDK appends /v1/messages?beta=true; Node exposes <configured base>/messages.\n\t\t\t\t\t\tconst url = `${model.baseUrl.replace(/\\/+$/u, \"\")}/messages`;\n\t\t\t\t\t\tinput = input instanceof Request ? new Request(url, input) : url;\n\t\t\t\t\t\theaders.delete(\"anthropic-beta\");\n\t\t\t\t\t}\n\t\t\t\t\trequestId = null;\n\t\t\t\t\tretryAfter = null;\n\t\t\t\t\thttpError = undefined;\n\t\t\t\t\tconst response = await fetcher(input, { ...init, headers, redirect: \"error\" });\n\t\t\t\t\trequestId = response.headers.get(\"x-request-id\");\n\t\t\t\t\tretryAfter = response.headers.get(\"retry-after\");\n\t\t\t\t\tif (response.ok) return response;\n\t\t\t\t\tconst responseBody: unknown = await response\n\t\t\t\t\t\t.clone()\n\t\t\t\t\t\t.json()\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tconst payload = isJsonValue(responseBody) ? responseBody : undefined;\n\t\t\t\t\tconst error =\n\t\t\t\t\t\ttypeof payload === \"object\" && payload !== null && \"error\" in payload ? payload.error : undefined;\n\t\t\t\t\tconst code =\n\t\t\t\t\t\ttypeof error === \"object\" && error !== null\n\t\t\t\t\t\t\t? \"code\" in error && typeof error.code === \"string\"\n\t\t\t\t\t\t\t\t? error.code\n\t\t\t\t\t\t\t\t: \"type\" in error && typeof error.type === \"string\"\n\t\t\t\t\t\t\t\t\t? error.type\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tlet retryable =\n\t\t\t\t\t\t!PERMANENT_LIMIT_CODES.has(code ?? \"\") &&\n\t\t\t\t\t\tresponse.headers.get(\"x-should-retry\") !== \"false\" &&\n\t\t\t\t\t\t([408, 409, 429].includes(response.status) || response.status >= 500);\n\t\t\t\t\thttpError = { status: response.status, retryable };\n\t\t\t\t\tif (code !== undefined) httpError.code = redact(code);\n\t\t\t\t\t// Lets the session switch to another configured Node key without re-reading the response.\n\t\t\t\t\tconst accountFailure = classifyNodeAccountFailure(response.status, responseBody, response.headers);\n\t\t\t\t\tif (accountFailure) {\n\t\t\t\t\t\thttpError.nodeAccountFailure = {\n\t\t\t\t\t\t\treason: accountFailure.reason,\n\t\t\t\t\t\t\t...(accountFailure.retryAfterMs === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { retryAfterMs: accountFailure.retryAfterMs }),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (retryAfter) {\n\t\t\t\t\t\tconst retryAt = /^\\d+(?:\\.\\d+)?$/u.test(retryAfter)\n\t\t\t\t\t\t\t? Date.now() + Number(retryAfter) * 1000\n\t\t\t\t\t\t\t: Date.parse(retryAfter);\n\t\t\t\t\t\tif (Number.isFinite(retryAt)) {\n\t\t\t\t\t\t\tconst delay = retryAt - Date.now();\n\t\t\t\t\t\t\tconst maxDelay = options?.maxRetryDelayMs ?? 60_000;\n\t\t\t\t\t\t\t// Fail instead of shortening a server delay or overflowing the JS timer.\n\t\t\t\t\t\t\tif (delay > 2_147_483_647 || (maxDelay > 0 && delay > maxDelay)) {\n\t\t\t\t\t\t\t\tretryable = false;\n\t\t\t\t\t\t\t\thttpError.retryable = false;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thttpError.retryAt = retryAt;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!retryable) {\n\t\t\t\t\t\tconst responseHeaders = new Headers(response.headers);\n\t\t\t\t\t\tresponseHeaders.set(\"x-should-retry\", \"false\");\n\t\t\t\t\t\treturn new Response(response.body, {\n\t\t\t\t\t\t\tstatus: response.status,\n\t\t\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\t\t\theaders: responseHeaders,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst source = simple\n\t\t\t\t? api.streamSimple(model, context, requestOptions)\n\t\t\t\t: api.stream(model, context, requestOptions);\n\t\t\treturn (async function* (): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\tfor await (const event of source) {\n\t\t\t\t\tif (event.type === \"done\" || event.type === \"error\") {\n\t\t\t\t\t\tconst message = event.type === \"done\" ? event.message : event.error;\n\t\t\t\t\t\tif (message.diagnostics) {\n\t\t\t\t\t\t\tmessage.diagnostics = message.diagnostics.map((diagnostic) => ({\n\t\t\t\t\t\t\t\t...diagnostic,\n\t\t\t\t\t\t\t\ttype: redact(diagnostic.type),\n\t\t\t\t\t\t\t\t...(diagnostic.error && {\n\t\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\t\t...diagnostic.error,\n\t\t\t\t\t\t\t\t\t\tmessage: redact(diagnostic.error.message),\n\t\t\t\t\t\t\t\t\t\t...(diagnostic.error.name && { name: redact(diagnostic.error.name) }),\n\t\t\t\t\t\t\t\t\t\t...(diagnostic.error.stack && { stack: redact(diagnostic.error.stack) }),\n\t\t\t\t\t\t\t\t\t\t...(typeof diagnostic.error.code === \"string\" && { code: redact(diagnostic.error.code) }),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t...(diagnostic.details && { details: redactJson(diagnostic.details) as JsonObject }),\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (event.type === \"error\") {\n\t\t\t\t\t\tevent.error.errorMessage = redact(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tevent.error.errorMessage ?? \"HUMAIN Node request failed\",\n\t\t\t\t\t\t\t\thttpError?.code && `code: ${httpError.code}`,\n\t\t\t\t\t\t\t\thttpError?.status === 401 && \"Run /login humain-node to replace the API key.\",\n\t\t\t\t\t\t\t\thttpError?.status === 404 &&\n\t\t\t\t\t\t\t\t\thttpError.code === \"model_not_found\" &&\n\t\t\t\t\t\t\t\t\t\"Use /model to refresh the catalog and choose an available model (or restart with --list-models).\",\n\t\t\t\t\t\t\t\tretryAfter && `Retry-After: ${retryAfter}`,\n\t\t\t\t\t\t\t\trequestId && `X-Request-ID: ${requestId}`,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t.join(\"; \"),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (httpError) {\n\t\t\t\t\t\t\tevent.error.diagnostics = [\n\t\t\t\t\t\t\t\t...(event.error.diagnostics ?? []),\n\t\t\t\t\t\t\t\t{ type: \"provider_http_error\", timestamp: Date.now(), details: httpError },\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tyield event;\n\t\t\t\t}\n\t\t\t})();\n\t\t});\n\treturn {\n\t\tstream: (model, context, options) => run(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => run(model, context, options, true),\n\t};\n}\n"]}
1
+ {"version":3,"file":"node-http.js","sourceRoot":"","sources":["../../src/humain/node-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,UAAU,GAKV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,SAAS,WAAW,CAAC,KAAc;IAClC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5G,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACrC,qBAAqB;IACrB,gBAAgB;IAChB,+BAA+B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E,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC;QACxE,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;KAC7E,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEvent,\n\ttype JsonObject,\n\ttype JsonValue,\n\tlazyStream,\n\ttype Model,\n\ttype ProviderStreams,\n\ttype SimpleStreamOptions,\n\ttype TranscriptContext,\n} from \"@earendil-works/pi-ai\";\nimport { classifyNodeAccountFailure } from \"./node-account-failure.ts\";\nimport { redactAssistantMessage } from \"./redact-assistant-message.ts\";\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (value === null || typeof value === \"boolean\" || typeof value === \"number\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (typeof value !== \"object\") return false;\n\treturn Object.values(value).every(isJsonValue);\n}\n\nconst PERMANENT_LIMIT_CODES = new Set([\n\t\"weekly_cap_exceeded\",\n\t\"quota_exceeded\",\n\t\"partner_credit_limit_exceeded\",\n\t\"insufficient_quota\",\n\t\"billing_hard_limit_reached\",\n]);\n\nexport function withHumainNodeHttp(api: ProviderStreams): ProviderStreams {\n\tconst run = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: SimpleStreamOptions | undefined,\n\t\tsimple: boolean,\n\t) =>\n\t\tlazyStream(model, async () => {\n\t\t\tlet httpError: JsonObject | undefined;\n\t\t\tlet requestId: string | null = null;\n\t\t\tlet retryAfter: string | null = null;\n\t\t\tconst key = options?.apiKey;\n\t\t\tconst redact = (value: string): string => (key ? value.replaceAll(key, \"[redacted]\") : value);\n\t\t\tconst fetcher = options?.fetch ?? globalThis.fetch;\n\t\t\tconst requestOptions = {\n\t\t\t\t...options,\n\t\t\t\t// The Anthropic adapter must not interpret a gateway key as an OAuth token.\n\t\t\t\tapiKey: model.api === \"anthropic-messages\" ? \"humain-node\" : key,\n\t\t\t\tfetch: async (input: Parameters<typeof fetch>[0], init?: RequestInit): Promise<Response> => {\n\t\t\t\t\tconst headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));\n\t\t\t\t\tif (key) headers.set(\"Authorization\", `Bearer ${key}`);\n\t\t\t\t\theaders.delete(\"x-api-key\");\n\t\t\t\t\tif (model.api === \"anthropic-messages\") {\n\t\t\t\t\t\t// The SDK appends /v1/messages?beta=true; Node exposes <configured base>/messages.\n\t\t\t\t\t\tconst url = `${model.baseUrl.replace(/\\/+$/u, \"\")}/messages`;\n\t\t\t\t\t\tinput = input instanceof Request ? new Request(url, input) : url;\n\t\t\t\t\t\theaders.delete(\"anthropic-beta\");\n\t\t\t\t\t}\n\t\t\t\t\trequestId = null;\n\t\t\t\t\tretryAfter = null;\n\t\t\t\t\thttpError = undefined;\n\t\t\t\t\tconst response = await fetcher(input, { ...init, headers, redirect: \"error\" });\n\t\t\t\t\trequestId = response.headers.get(\"x-request-id\");\n\t\t\t\t\tretryAfter = response.headers.get(\"retry-after\");\n\t\t\t\t\tif (response.ok) return response;\n\t\t\t\t\tconst responseBody: unknown = await response\n\t\t\t\t\t\t.clone()\n\t\t\t\t\t\t.json()\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tconst payload = isJsonValue(responseBody) ? responseBody : undefined;\n\t\t\t\t\tconst error =\n\t\t\t\t\t\ttypeof payload === \"object\" && payload !== null && \"error\" in payload ? payload.error : undefined;\n\t\t\t\t\tconst code =\n\t\t\t\t\t\ttypeof error === \"object\" && error !== null\n\t\t\t\t\t\t\t? \"code\" in error && typeof error.code === \"string\"\n\t\t\t\t\t\t\t\t? error.code\n\t\t\t\t\t\t\t\t: \"type\" in error && typeof error.type === \"string\"\n\t\t\t\t\t\t\t\t\t? error.type\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tlet retryable =\n\t\t\t\t\t\t!PERMANENT_LIMIT_CODES.has(code ?? \"\") &&\n\t\t\t\t\t\tresponse.headers.get(\"x-should-retry\") !== \"false\" &&\n\t\t\t\t\t\t([408, 409, 429].includes(response.status) || response.status >= 500);\n\t\t\t\t\thttpError = { status: response.status, retryable };\n\t\t\t\t\tif (code !== undefined) httpError.code = redact(code);\n\t\t\t\t\t// Lets the session switch to another configured Node key without re-reading the response.\n\t\t\t\t\tconst accountFailure = classifyNodeAccountFailure(response.status, responseBody, response.headers);\n\t\t\t\t\tif (accountFailure) {\n\t\t\t\t\t\thttpError.nodeAccountFailure = {\n\t\t\t\t\t\t\treason: accountFailure.reason,\n\t\t\t\t\t\t\t...(accountFailure.retryAfterMs === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { retryAfterMs: accountFailure.retryAfterMs }),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (retryAfter) {\n\t\t\t\t\t\tconst retryAt = /^\\d+(?:\\.\\d+)?$/u.test(retryAfter)\n\t\t\t\t\t\t\t? Date.now() + Number(retryAfter) * 1000\n\t\t\t\t\t\t\t: Date.parse(retryAfter);\n\t\t\t\t\t\tif (Number.isFinite(retryAt)) {\n\t\t\t\t\t\t\tconst delay = retryAt - Date.now();\n\t\t\t\t\t\t\tconst maxDelay = options?.maxRetryDelayMs ?? 60_000;\n\t\t\t\t\t\t\t// Fail instead of shortening a server delay or overflowing the JS timer.\n\t\t\t\t\t\t\tif (delay > 2_147_483_647 || (maxDelay > 0 && delay > maxDelay)) {\n\t\t\t\t\t\t\t\tretryable = false;\n\t\t\t\t\t\t\t\thttpError.retryable = false;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thttpError.retryAt = retryAt;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!retryable) {\n\t\t\t\t\t\tconst responseHeaders = new Headers(response.headers);\n\t\t\t\t\t\tresponseHeaders.set(\"x-should-retry\", \"false\");\n\t\t\t\t\t\treturn new Response(response.body, {\n\t\t\t\t\t\t\tstatus: response.status,\n\t\t\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\t\t\theaders: responseHeaders,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst source = simple\n\t\t\t\t? api.streamSimple(model, context, requestOptions)\n\t\t\t\t: api.stream(model, context, requestOptions);\n\t\t\treturn (async function* (): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\tfor await (const event of source) {\n\t\t\t\t\tif (event.type === \"done\") redactAssistantMessage(event.message, key);\n\t\t\t\t\tif (event.type === \"error\") {\n\t\t\t\t\t\tevent.error.errorMessage = [\n\t\t\t\t\t\t\tevent.error.errorMessage ?? \"HUMAIN Node request failed\",\n\t\t\t\t\t\t\thttpError?.code && `code: ${httpError.code}`,\n\t\t\t\t\t\t\thttpError?.status === 401 && \"Run /login humain-node to replace the API key.\",\n\t\t\t\t\t\t\thttpError?.status === 404 &&\n\t\t\t\t\t\t\t\thttpError.code === \"model_not_found\" &&\n\t\t\t\t\t\t\t\t\"Use /model to refresh the catalog and choose an available model (or restart with --list-models).\",\n\t\t\t\t\t\t\tretryAfter && `Retry-After: ${retryAfter}`,\n\t\t\t\t\t\t\trequestId && `X-Request-ID: ${requestId}`,\n\t\t\t\t\t\t]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(\"; \");\n\t\t\t\t\t\tif (httpError) {\n\t\t\t\t\t\t\tevent.error.diagnostics = [\n\t\t\t\t\t\t\t\t...(event.error.diagnostics ?? []),\n\t\t\t\t\t\t\t\t{ type: \"provider_http_error\", timestamp: Date.now(), details: httpError },\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tredactAssistantMessage(event.error, key);\n\t\t\t\t\t}\n\t\t\t\t\tyield event;\n\t\t\t\t}\n\t\t\t})();\n\t\t});\n\treturn {\n\t\tstream: (model, context, options) => run(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => run(model, context, options, true),\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
2
+ /** Replaces `key` with `[redacted]` in the error message and every diagnostic of `message`. */
3
+ export declare function redactAssistantMessage(message: AssistantMessage, key: string | undefined): void;
4
+ //# sourceMappingURL=redact-assistant-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-assistant-message.d.ts","sourceRoot":"","sources":["../../src/humain/redact-assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,uBAAuB,CAAC;AAErF,+FAA+F;AAC/F,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CA2B/F"}
@@ -0,0 +1,34 @@
1
+ /** Replaces `key` with `[redacted]` in the error message and every diagnostic of `message`. */
2
+ export function redactAssistantMessage(message, key) {
3
+ if (!key)
4
+ return;
5
+ const redact = (value) => value.replaceAll(key, "[redacted]");
6
+ const redactJson = (value) => {
7
+ if (typeof value === "string")
8
+ return redact(value);
9
+ if (Array.isArray(value))
10
+ return value.map(redactJson);
11
+ if (value !== null && typeof value === "object") {
12
+ return Object.fromEntries(Object.entries(value).map(([name, value]) => [redact(name), redactJson(value)]));
13
+ }
14
+ return value;
15
+ };
16
+ message.errorMessage &&= redact(message.errorMessage);
17
+ if (!message.diagnostics)
18
+ return;
19
+ message.diagnostics = message.diagnostics.map((diagnostic) => ({
20
+ ...diagnostic,
21
+ type: redact(diagnostic.type),
22
+ ...(diagnostic.error && {
23
+ error: {
24
+ ...diagnostic.error,
25
+ message: redact(diagnostic.error.message),
26
+ ...(diagnostic.error.name && { name: redact(diagnostic.error.name) }),
27
+ ...(diagnostic.error.stack && { stack: redact(diagnostic.error.stack) }),
28
+ ...(typeof diagnostic.error.code === "string" && { code: redact(diagnostic.error.code) }),
29
+ },
30
+ }),
31
+ ...(diagnostic.details && { details: redactJson(diagnostic.details) }),
32
+ }));
33
+ }
34
+ //# sourceMappingURL=redact-assistant-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-assistant-message.js","sourceRoot":"","sources":["../../src/humain/redact-assistant-message.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,MAAM,UAAU,sBAAsB,CAAC,OAAyB,EAAE,GAAuB;IACxF,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAC9E,MAAM,UAAU,GAAG,CAAC,KAAgB,EAAa,EAAE;QAClD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACjD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5G,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC;IACF,OAAO,CAAC,YAAY,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,WAAW;QAAE,OAAO;IACjC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC9D,GAAG,UAAU;QACb,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;QAC7B,GAAG,CAAC,UAAU,CAAC,KAAK,IAAI;YACvB,KAAK,EAAE;gBACN,GAAG,UAAU,CAAC,KAAK;gBACnB,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC;gBACzC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrE,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxE,GAAG,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;aACzF;SACD,CAAC;QACF,GAAG,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAe,EAAE,CAAC;KACpF,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AssistantMessage, JsonObject, JsonValue } from \"@earendil-works/pi-ai\";\n\n/** Replaces `key` with `[redacted]` in the error message and every diagnostic of `message`. */\nexport function redactAssistantMessage(message: AssistantMessage, key: string | undefined): void {\n\tif (!key) return;\n\tconst redact = (value: string): string => value.replaceAll(key, \"[redacted]\");\n\tconst redactJson = (value: JsonValue): JsonValue => {\n\t\tif (typeof value === \"string\") return redact(value);\n\t\tif (Array.isArray(value)) return value.map(redactJson);\n\t\tif (value !== null && typeof value === \"object\") {\n\t\t\treturn Object.fromEntries(Object.entries(value).map(([name, value]) => [redact(name), redactJson(value)]));\n\t\t}\n\t\treturn value;\n\t};\n\tmessage.errorMessage &&= redact(message.errorMessage);\n\tif (!message.diagnostics) return;\n\tmessage.diagnostics = message.diagnostics.map((diagnostic) => ({\n\t\t...diagnostic,\n\t\ttype: redact(diagnostic.type),\n\t\t...(diagnostic.error && {\n\t\t\terror: {\n\t\t\t\t...diagnostic.error,\n\t\t\t\tmessage: redact(diagnostic.error.message),\n\t\t\t\t...(diagnostic.error.name && { name: redact(diagnostic.error.name) }),\n\t\t\t\t...(diagnostic.error.stack && { stack: redact(diagnostic.error.stack) }),\n\t\t\t\t...(typeof diagnostic.error.code === \"string\" && { code: redact(diagnostic.error.code) }),\n\t\t\t},\n\t\t}),\n\t\t...(diagnostic.details && { details: redactJson(diagnostic.details) as JsonObject }),\n\t}));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AASH,OAAO,EAAE,KAAK,IAAI,EAA0D,MAAM,eAAe,CAAC;AA8ClG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAalE,OAAO,EAAwB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA6T7D,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,IAAI,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,eAAe,EAAE,eAAe,GAC9B,OAAO,CAAC,cAAc,CAAC,CAsFzB;AAyHD,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;CACvC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM/G;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,iBA+kB/D"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AASH,OAAO,EAAE,KAAK,IAAI,EAA0D,MAAM,eAAe,CAAC;AA8ClG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAalE,OAAO,EAAwB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA+T7D,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,IAAI,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,eAAe,EAAE,eAAe,GAC9B,OAAO,CAAC,cAAc,CAAC,CAsFzB;AAyHD,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;CACvC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM/G;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,iBA4lB/D"}
package/dist/main.js CHANGED
@@ -46,6 +46,8 @@ import { getTraceEnvSecrets } from "./core/trace/redaction.js";
46
46
  import { hasTrustRequiringProjectResources, ProjectTrustStore } from "./core/trust-manager.js";
47
47
  import { builtInExtensions, createAgentMonitorFactory, createAutoSessionNamerFactory, createCoordinationFactory, } from "./extensions/index.js";
48
48
  import { loadMcpCommand } from "./extensions/mcp/cli.lazy.js";
49
+ import { HUMAIN_GATEWAY_PROVIDER } from "./humain/gateway/constants.js";
50
+ import { revokeGatewayOrphans, shouldReconcileGatewayOnStartup } from "./humain/gateway/provider.js";
49
51
  import { getHumainBundledExtensionFactories, getHumainDefaultPackageSources, HUMAIN_FORGE_CWD_ENV, } from "./humain/index.js";
50
52
  import { HUMAIN_NODE_PROVIDER } from "./humain/node-provider.js";
51
53
  import { ensureOmniRouteReady, isOmniRouteEnabled, OMNIROUTE_HINT } from "./humain/omniroute.js";
@@ -782,17 +784,28 @@ export async function main(args, options) {
782
784
  })),
783
785
  ];
784
786
  if (!parsed.help &&
785
- process.env.PI_OFFLINE === undefined &&
786
- modelRuntime.hasConfiguredAuth(HUMAIN_NODE_PROVIDER)) {
787
+ shouldReconcileGatewayOnStartup(appMode, process.env.PI_OFFLINE !== undefined, parsed.listModels !== undefined)) {
788
+ // Revokes sessions left by /logout in the background; startup never waits for the network.
789
+ // The warning shows only when the cleanup fails before startup diagnostics are rendered.
790
+ void revokeGatewayOrphans().catch(() => {
791
+ diagnostics.push({
792
+ type: "warning",
793
+ message: "HUMAIN Gateway sign-out cleanup failed; it will be retried on the next start.",
794
+ });
795
+ });
796
+ }
797
+ // Discovered catalogs must be loaded before the saved model is restored.
798
+ const discoveredProviders = [HUMAIN_NODE_PROVIDER, HUMAIN_GATEWAY_PROVIDER].filter((id) => modelRuntime.hasConfiguredAuth(id));
799
+ if (!parsed.help && process.env.PI_OFFLINE === undefined && discoveredProviders.length > 0) {
787
800
  const result = await modelRuntime.refresh({
788
- providers: [HUMAIN_NODE_PROVIDER],
801
+ providers: discoveredProviders,
789
802
  signal: AbortSignal.timeout(15_000),
790
803
  });
791
804
  for (const error of result.errors.values()) {
792
805
  diagnostics.push({ type: "warning", message: error.message });
793
806
  }
794
807
  if (result.aborted) {
795
- diagnostics.push({ type: "warning", message: "HUMAIN Node model discovery timed out" });
808
+ diagnostics.push({ type: "warning", message: "HUMAIN model discovery timed out" });
796
809
  }
797
810
  }
798
811
  const modelPatterns = parsed.models ?? settingsManager.getEnabledModels();