@oscharko-dev/keiko 0.3.11 → 0.3.13

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 (209) hide show
  1. package/dist/ui/csp-hashes.json +13 -13
  2. package/dist/ui/static/404.html +1 -1
  3. package/dist/ui/static/__next.__PAGE__.txt +2 -2
  4. package/dist/ui/static/__next._full.txt +3 -3
  5. package/dist/ui/static/__next._head.txt +1 -1
  6. package/dist/ui/static/__next._index.txt +1 -1
  7. package/dist/ui/static/__next._tree.txt +1 -1
  8. package/dist/ui/static/_next/static/chunks/{0ovebg0sbcqct.js → 089ft_ee-2y20.js} +1 -1
  9. package/dist/ui/static/_next/static/chunks/09ifk61aybcwe.js +1 -0
  10. package/dist/ui/static/_next/static/chunks/0spfmty-r-rqj.js +1 -0
  11. package/dist/ui/static/_next/static/chunks/{2b7g5wrm7slyv.js → 123hx5vnwghyp.js} +1 -1
  12. package/dist/ui/static/_next/static/chunks/1aad3wmm8b0h_.js +1 -0
  13. package/dist/ui/static/_next/static/chunks/1s1u4fx4mdurk.js +1 -0
  14. package/dist/ui/static/_next/static/chunks/{2ksqufkg3ptp1.js → 26sy339azhbd8.js} +1 -1
  15. package/dist/ui/static/_next/static/chunks/2bshxlpms4hq2.js +1 -0
  16. package/dist/ui/static/_next/static/chunks/{2ohow-fui5d_w.js → 2c9gq9vpyd9sm.js} +1 -1
  17. package/dist/ui/static/_next/static/chunks/{3mw_ni1a9rykb.js → 2iqsdgq5z7zi-.js} +1 -1
  18. package/dist/ui/static/_next/static/chunks/{0d5rtaf3-jc-x.js → 2iuxjus3qppec.js} +1 -1
  19. package/dist/ui/static/_next/static/chunks/2t0ktf1dxwv0_.js +1 -0
  20. package/dist/ui/static/_next/static/chunks/2xgtm8mmbv8mx.js +1 -0
  21. package/dist/ui/static/_next/static/chunks/3od_e1_j5aq-u.js +1 -0
  22. package/dist/ui/static/_not-found/__next._full.txt +1 -1
  23. package/dist/ui/static/_not-found/__next._head.txt +1 -1
  24. package/dist/ui/static/_not-found/__next._index.txt +1 -1
  25. package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +1 -1
  26. package/dist/ui/static/_not-found/__next._not-found.txt +1 -1
  27. package/dist/ui/static/_not-found/__next._tree.txt +1 -1
  28. package/dist/ui/static/_not-found.html +1 -1
  29. package/dist/ui/static/_not-found.txt +1 -1
  30. package/dist/ui/static/atlassian-connectors/__next._full.txt +5 -5
  31. package/dist/ui/static/atlassian-connectors/__next._head.txt +1 -1
  32. package/dist/ui/static/atlassian-connectors/__next._index.txt +1 -1
  33. package/dist/ui/static/atlassian-connectors/__next._tree.txt +1 -1
  34. package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.__PAGE__.txt +2 -2
  35. package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.txt +2 -2
  36. package/dist/ui/static/atlassian-connectors.html +1 -1
  37. package/dist/ui/static/atlassian-connectors.txt +5 -5
  38. package/dist/ui/static/index.html +1 -1
  39. package/dist/ui/static/index.txt +3 -3
  40. package/dist/ui/static/launch/__next._full.txt +3 -3
  41. package/dist/ui/static/launch/__next._head.txt +1 -1
  42. package/dist/ui/static/launch/__next._index.txt +1 -1
  43. package/dist/ui/static/launch/__next._tree.txt +1 -1
  44. package/dist/ui/static/launch/__next.launch.__PAGE__.txt +2 -2
  45. package/dist/ui/static/launch/__next.launch.txt +1 -1
  46. package/dist/ui/static/launch.html +1 -1
  47. package/dist/ui/static/launch.txt +3 -3
  48. package/dist/ui/static/local-knowledge/__next._full.txt +3 -3
  49. package/dist/ui/static/local-knowledge/__next._head.txt +1 -1
  50. package/dist/ui/static/local-knowledge/__next._index.txt +1 -1
  51. package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
  52. package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +2 -2
  53. package/dist/ui/static/local-knowledge/__next.local-knowledge.txt +1 -1
  54. package/dist/ui/static/local-knowledge/capsule/__next._full.txt +5 -5
  55. package/dist/ui/static/local-knowledge/capsule/__next._head.txt +1 -1
  56. package/dist/ui/static/local-knowledge/capsule/__next._index.txt +1 -1
  57. package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +1 -1
  58. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +2 -2
  59. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.txt +2 -2
  60. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.txt +1 -1
  61. package/dist/ui/static/local-knowledge/capsule.html +1 -1
  62. package/dist/ui/static/local-knowledge/capsule.txt +5 -5
  63. package/dist/ui/static/local-knowledge.html +1 -1
  64. package/dist/ui/static/local-knowledge.txt +3 -3
  65. package/node_modules/@oscharko-dev/keiko-cli/package.json +13 -13
  66. package/node_modules/@oscharko-dev/keiko-connectors/package.json +3 -3
  67. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.d.ts +79 -1
  68. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.d.ts.map +1 -1
  69. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.js +116 -0
  70. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +5 -5
  71. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts.map +1 -1
  72. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +4 -4
  73. package/node_modules/@oscharko-dev/keiko-contracts/dist/local-knowledge-records.d.ts +10 -0
  74. package/node_modules/@oscharko-dev/keiko-contracts/dist/local-knowledge-records.d.ts.map +1 -1
  75. package/node_modules/@oscharko-dev/keiko-contracts/dist/local-knowledge-records.js +8 -0
  76. package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
  77. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
  78. package/node_modules/@oscharko-dev/keiko-evidence/dist/version.d.ts +1 -1
  79. package/node_modules/@oscharko-dev/keiko-evidence/dist/version.js +1 -1
  80. package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
  81. package/node_modules/@oscharko-dev/keiko-git/package.json +1 -1
  82. package/node_modules/@oscharko-dev/keiko-harness/dist/version.d.ts +1 -1
  83. package/node_modules/@oscharko-dev/keiko-harness/dist/version.js +1 -1
  84. package/node_modules/@oscharko-dev/keiko-harness/package.json +6 -6
  85. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/index.d.ts +1 -1
  86. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/index.d.ts.map +1 -1
  87. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/index.js +1 -1
  88. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/persist.d.ts +1 -0
  89. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/persist.d.ts.map +1 -1
  90. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/persist.js +8 -0
  91. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/types.d.ts +2 -0
  92. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/types.d.ts.map +1 -1
  93. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/discovery/types.js +8 -0
  94. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/bounded-indexing.d.ts +2 -0
  95. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/bounded-indexing.d.ts.map +1 -1
  96. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/bounded-indexing.js +1 -0
  97. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/embedding-batcher.d.ts.map +1 -1
  98. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/embedding-batcher.js +53 -14
  99. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.d.ts +3 -0
  100. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.d.ts.map +1 -1
  101. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.js +163 -9
  102. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/types.d.ts +1 -0
  103. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/types.d.ts.map +1 -1
  104. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod-progress.d.ts.map +1 -1
  105. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod-progress.js +2 -0
  106. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.d.ts +1 -1
  107. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.js +1 -1
  108. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +5 -5
  109. package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.d.ts +1 -1
  110. package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.js +1 -1
  111. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
  112. package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.d.ts +1 -1
  113. package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.js +1 -1
  114. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
  115. package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.d.ts +1 -1
  116. package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.js +1 -1
  117. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
  118. package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.d.ts +1 -1
  119. package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.js +1 -1
  120. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
  121. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.d.ts +1 -1
  122. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.js +1 -1
  123. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
  124. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.d.ts.map +1 -1
  125. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.js +13 -0
  126. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.d.ts +2 -0
  127. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.d.ts.map +1 -1
  128. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.js +26 -6
  129. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.d.ts +1 -1
  130. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.js +1 -1
  131. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +3 -3
  132. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
  133. package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
  134. package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
  135. package/node_modules/@oscharko-dev/keiko-security/dist/version.d.ts +1 -1
  136. package/node_modules/@oscharko-dev/keiko-security/dist/version.js +1 -1
  137. package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
  138. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts.map +1 -1
  139. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.js +28 -17
  140. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts +22 -1
  141. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
  142. package/node_modules/@oscharko-dev/keiko-server/dist/deps.js +19 -0
  143. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.d.ts +5 -1
  144. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.d.ts.map +1 -1
  145. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.js +1 -0
  146. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts +3 -0
  147. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts.map +1 -1
  148. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.js +80 -4
  149. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
  150. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +306 -50
  151. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.d.ts.map +1 -1
  152. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.js +12 -2
  153. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.d.ts +1 -0
  154. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.d.ts.map +1 -1
  155. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.js +132 -14
  156. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation.d.ts.map +1 -1
  157. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation.js +5 -2
  158. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.d.ts.map +1 -1
  159. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.js +13 -6
  160. package/node_modules/@oscharko-dev/keiko-server/package.json +21 -21
  161. package/node_modules/@oscharko-dev/keiko-tools/dist/version.d.ts +1 -1
  162. package/node_modules/@oscharko-dev/keiko-tools/dist/version.js +1 -1
  163. package/node_modules/@oscharko-dev/keiko-tools/package.json +5 -5
  164. package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
  165. package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
  166. package/node_modules/@oscharko-dev/keiko-workspace/dist/version.d.ts +1 -1
  167. package/node_modules/@oscharko-dev/keiko-workspace/dist/version.js +1 -1
  168. package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
  169. package/package.json +25 -25
  170. package/release-impact.catalog.json +112 -4
  171. package/vendor/{oscharko-dev-keiko-cli-0.3.11.tgz → oscharko-dev-keiko-cli-0.3.13.tgz} +0 -0
  172. package/vendor/{oscharko-dev-keiko-connectors-0.3.11.tgz → oscharko-dev-keiko-connectors-0.3.13.tgz} +0 -0
  173. package/vendor/oscharko-dev-keiko-contracts-0.3.13.tgz +0 -0
  174. package/vendor/{oscharko-dev-keiko-evaluations-0.3.11.tgz → oscharko-dev-keiko-evaluations-0.3.13.tgz} +0 -0
  175. package/vendor/{oscharko-dev-keiko-evidence-0.3.11.tgz → oscharko-dev-keiko-evidence-0.3.13.tgz} +0 -0
  176. package/vendor/{oscharko-dev-keiko-git-0.3.11.tgz → oscharko-dev-keiko-git-0.3.13.tgz} +0 -0
  177. package/vendor/{oscharko-dev-keiko-harness-0.3.11.tgz → oscharko-dev-keiko-harness-0.3.13.tgz} +0 -0
  178. package/vendor/oscharko-dev-keiko-local-knowledge-0.3.13.tgz +0 -0
  179. package/vendor/{oscharko-dev-keiko-memory-capture-0.3.11.tgz → oscharko-dev-keiko-memory-capture-0.3.13.tgz} +0 -0
  180. package/vendor/{oscharko-dev-keiko-memory-consolidation-0.3.11.tgz → oscharko-dev-keiko-memory-consolidation-0.3.13.tgz} +0 -0
  181. package/vendor/oscharko-dev-keiko-memory-governance-0.3.13.tgz +0 -0
  182. package/vendor/{oscharko-dev-keiko-memory-retrieval-0.3.11.tgz → oscharko-dev-keiko-memory-retrieval-0.3.13.tgz} +0 -0
  183. package/vendor/{oscharko-dev-keiko-memory-vault-0.3.11.tgz → oscharko-dev-keiko-memory-vault-0.3.13.tgz} +0 -0
  184. package/vendor/oscharko-dev-keiko-model-gateway-0.3.13.tgz +0 -0
  185. package/vendor/{oscharko-dev-keiko-quality-intelligence-0.3.11.tgz → oscharko-dev-keiko-quality-intelligence-0.3.13.tgz} +0 -0
  186. package/vendor/{oscharko-dev-keiko-sandbox-0.3.11.tgz → oscharko-dev-keiko-sandbox-0.3.13.tgz} +0 -0
  187. package/vendor/{oscharko-dev-keiko-sdk-0.3.11.tgz → oscharko-dev-keiko-sdk-0.3.13.tgz} +0 -0
  188. package/vendor/{oscharko-dev-keiko-security-0.3.11.tgz → oscharko-dev-keiko-security-0.3.13.tgz} +0 -0
  189. package/vendor/oscharko-dev-keiko-server-0.3.13.tgz +0 -0
  190. package/vendor/{oscharko-dev-keiko-tools-0.3.11.tgz → oscharko-dev-keiko-tools-0.3.13.tgz} +0 -0
  191. package/vendor/{oscharko-dev-keiko-verification-0.3.11.tgz → oscharko-dev-keiko-verification-0.3.13.tgz} +0 -0
  192. package/vendor/{oscharko-dev-keiko-workflows-0.3.11.tgz → oscharko-dev-keiko-workflows-0.3.13.tgz} +0 -0
  193. package/vendor/{oscharko-dev-keiko-workspace-0.3.11.tgz → oscharko-dev-keiko-workspace-0.3.13.tgz} +0 -0
  194. package/dist/ui/static/_next/static/chunks/08ix9sw49a3s7.js +0 -1
  195. package/dist/ui/static/_next/static/chunks/0w6kppo4hx2wx.js +0 -1
  196. package/dist/ui/static/_next/static/chunks/1kfsvai94yvr2.js +0 -1
  197. package/dist/ui/static/_next/static/chunks/1qio8iqevt0mg.js +0 -1
  198. package/dist/ui/static/_next/static/chunks/1ziptu5xlzq_p.js +0 -1
  199. package/dist/ui/static/_next/static/chunks/2bpupnd-k7bgu.js +0 -1
  200. package/dist/ui/static/_next/static/chunks/2sji-23jqwpol.js +0 -1
  201. package/dist/ui/static/_next/static/chunks/3r74c2jeognx2.js +0 -1
  202. package/vendor/oscharko-dev-keiko-contracts-0.3.11.tgz +0 -0
  203. package/vendor/oscharko-dev-keiko-local-knowledge-0.3.11.tgz +0 -0
  204. package/vendor/oscharko-dev-keiko-memory-governance-0.3.11.tgz +0 -0
  205. package/vendor/oscharko-dev-keiko-model-gateway-0.3.11.tgz +0 -0
  206. package/vendor/oscharko-dev-keiko-server-0.3.11.tgz +0 -0
  207. /package/dist/ui/static/_next/static/{TE3T4DCedlDBoFwpbxasE → iwhpaHGb663ka5R3lhZBj}/_buildManifest.js +0 -0
  208. /package/dist/ui/static/_next/static/{TE3T4DCedlDBoFwpbxasE → iwhpaHGb663ka5R3lhZBj}/_clientMiddlewareManifest.js +0 -0
  209. /package/dist/ui/static/_next/static/{TE3T4DCedlDBoFwpbxasE → iwhpaHGb663ka5R3lhZBj}/_ssgManifest.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import { isConversationEligibleModel, listConfiguredCapabilities, requestGatewayReadinessChatCompletion, requestOpenAIEmbedding, vectorL2Norm, } from "@oscharko-dev/keiko-model-gateway";
2
2
  import { readJsonCapped, readSseStream } from "@oscharko-dev/keiko-model-gateway/internal/http";
3
- import { gatewayVerificationFromProbeOutcome, maxUtf8BytesForTokenBudget, } from "@oscharko-dev/keiko-contracts";
3
+ import { gatewayVerificationFromProbeOutcome, maxUtf8BytesForTokenBudget, preferredConversationModelOrder, } from "@oscharko-dev/keiko-contracts";
4
4
  import { currentConversationReady, currentGatewayConfig } from "./deps.js";
5
5
  import { newCorrelationId } from "./correlation.js";
6
6
  import { emitServerDiagnostic, serverDiagnosticFromError } from "./diagnostics-log.js";
@@ -847,16 +847,37 @@ requestCorrelationId) {
847
847
  // rejected as "not ready" until the user manually verified each model in the settings dialog.
848
848
  // When a conversation guard finds no CURRENT-GENERATION observation for the model, verify on
849
849
  // demand with the minimal chat probe. The admission stays honest — the probe must actually
850
- // pass, and an existing current-generation "not ready" observation is respected without a
851
- // re-probe. Concurrent callers share one in-flight probe per model.
850
+ // pass. Concurrent callers share one in-flight probe per model.
852
851
  const onDemandReadinessProbes = new Map();
852
+ // A failed probe must not pin the model for the whole configuration generation: a transient
853
+ // gateway outage would brick every chat surface until a manual re-probe or restart (the
854
+ // readiness twin of the 0.3.11 endless-indexing incident). It must not be re-probed on every
855
+ // request either — each probe can burn the full provider timeout against a dead gateway. So a
856
+ // current-generation non-ready observation answers the guard only within this window; after it,
857
+ // the next conversation attempt re-probes and either heals or refreshes the pin.
858
+ export const NOT_READY_REPROBE_COOLDOWN_MS = 30_000;
859
+ function withinNotReadyCooldown(holder, modelId) {
860
+ const observation = holder.verifiedCapability(modelId);
861
+ if (observation?.generation !== holder.generation())
862
+ return false;
863
+ // Only an EXPLICIT failed chat probe earns a cooldown. An observation without a
864
+ // conversationReady field (e.g. a capability record carrying other probe fields) is unknown
865
+ // readiness, and unknown must probe immediately — never sit out a 30-second admission block
866
+ // (review finding on #3220).
867
+ if (observation.fields.conversationReady !== false)
868
+ return false;
869
+ const ageMs = Date.now() - Date.parse(observation.checkedAt);
870
+ // Malformed AND future timestamps fail open toward probing — never toward a pin: NaN and
871
+ // negative ages both miss the [0, cooldown) window.
872
+ return ageMs >= 0 && ageMs < NOT_READY_REPROBE_COOLDOWN_MS;
873
+ }
853
874
  export async function ensureOnDemandConversationReadiness(deps, modelId) {
854
875
  const holder = deps.gatewayConfig;
855
876
  if (holder === undefined || modelId.length === 0)
856
877
  return;
857
878
  if (currentConversationReady(deps, modelId))
858
879
  return;
859
- if (holder.verifiedCapability(modelId)?.generation === holder.generation())
880
+ if (withinNotReadyCooldown(holder, modelId))
860
881
  return;
861
882
  // The in-flight key carries the generation: a config replaced mid-probe must not hand the
862
883
  // NEW generation's caller the OLD generation's discarded report.
@@ -897,6 +918,61 @@ async function runOnDemandReadinessProbe(deps, holder, modelId) {
897
918
  holder.recordVerifiedCapability(modelId, { conversationReady: false }, new Date().toISOString(), generation);
898
919
  }
899
920
  }
921
+ // Chat creation without an explicit model must not die on an unsuitable FIRST list entry
922
+ // (customer field incident: an OCR model at position 1 legitimately fails the chat probe;
923
+ // the single-model on-demand check then recorded not-ready and stopped, so every chat
924
+ // create failed until a suitable model was probed MANUALLY). When the requested default is
925
+ // not conversation-ready, walk the remaining configured chat models — mode-declared
926
+ // candidates first (keiko-contracts conversationDefaultRank) — until one verifies; the
927
+ // default-model selection then prefers the verified one.
928
+ //
929
+ // The walk is BOUNDED: probes are serial and each can burn the full provider timeout, so an
930
+ // aggregate budget caps what one interactive create may wait (the unbounded-sum lesson of the
931
+ // 0.3.11 embedding ladder, applied here). A probe that outlives the budget keeps running in
932
+ // the shared in-flight map — its observation lands for the NEXT attempt — but this request
933
+ // stops waiting.
934
+ export const CHAT_MODEL_WALK_BUDGET_MS = 45_000;
935
+ async function settledWithinBudget(probe, budgetMs) {
936
+ let timer;
937
+ const expired = new Promise((resolve) => {
938
+ timer = setTimeout(() => {
939
+ resolve(false);
940
+ }, budgetMs);
941
+ });
942
+ try {
943
+ return await Promise.race([probe.then(() => true), expired]);
944
+ }
945
+ finally {
946
+ clearTimeout(timer);
947
+ }
948
+ }
949
+ function conversationWalkCandidates(deps, requestedModelId) {
950
+ const config = currentGatewayConfig(deps);
951
+ if (config === undefined)
952
+ return [];
953
+ return preferredConversationModelOrder(listConfiguredCapabilities(config).filter((capability) => capability.kind === "chat" && capability.id !== requestedModelId));
954
+ }
955
+ export async function ensureAnyConversationReadyChatModel(deps, requestedModelId) {
956
+ // The budget covers the REQUESTED model's probe too (review finding on the first cut):
957
+ // computed after it, a hanging gateway burned the full provider timeout before the budget
958
+ // even started. The interactive create never waits longer than the budget, full stop.
959
+ const deadlineAt = Date.now() + CHAT_MODEL_WALK_BUDGET_MS;
960
+ const firstProbe = ensureOnDemandConversationReadiness(deps, requestedModelId);
961
+ if (!(await settledWithinBudget(firstProbe, CHAT_MODEL_WALK_BUDGET_MS)))
962
+ return;
963
+ if (currentConversationReady(deps, requestedModelId))
964
+ return;
965
+ for (const capability of conversationWalkCandidates(deps, requestedModelId)) {
966
+ const remainingMs = deadlineAt - Date.now();
967
+ if (remainingMs <= 0)
968
+ return;
969
+ const probe = ensureOnDemandConversationReadiness(deps, capability.id);
970
+ if (!(await settledWithinBudget(probe, remainingMs)))
971
+ return;
972
+ if (currentConversationReady(deps, capability.id))
973
+ return;
974
+ }
975
+ }
900
976
  export async function handleGatewayReadiness(ctx, deps) {
901
977
  const body = await readJsonBody(ctx.req);
902
978
  if ("status" in body)
@@ -1 +1 @@
1
- {"version":3,"file":"gateway-setup.d.ts","sourceRoot":"","sources":["../src/gateway-setup.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAGV,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AAMvC,OAAO,KAAK,EAEV,aAAa,EAMd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAEV,uBAAuB,EAIvB,aAAa,EAEd,MAAM,WAAW,CAAC;AAwBnB,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAgFzC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM1D;AA0zBD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB;AA4LD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO/E;AA2CD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE1E;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,CAkC7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAElE;AAOD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAE7E;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,CAE3F;AAkVD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAO5B;AA+uFD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAuBhF;AAmqBD,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CAmBtB;AAuMD,oGAAoG;AACpG,wBAAsB,sCAAsC,CAC1D,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CA2BtB"}
1
+ {"version":3,"file":"gateway-setup.d.ts","sourceRoot":"","sources":["../src/gateway-setup.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAIV,uBAAuB,EAExB,MAAM,+BAA+B,CAAC;AAMvC,OAAO,KAAK,EAEV,aAAa,EAOd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAEV,uBAAuB,EAIvB,aAAa,EAEd,MAAM,WAAW,CAAC;AAwBnB,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAqFzC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM1D;AAm0BD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB;AAwLD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO/E;AAmGD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG1E;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,CAqD7E;AAwBD,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAElE;AAOD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAE7E;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,CAE3F;AAkWD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAO5B;AAi8FD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAuBhF;AAisBD,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CAmBtB;AAuMD,oGAAoG;AACpG,wBAAsB,sCAAsC,CAC1D,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CA2BtB"}
@@ -5,8 +5,8 @@
5
5
  import { randomUUID } from "node:crypto";
6
6
  import { existsSync, readFileSync } from "node:fs";
7
7
  import { resolveEvidenceDir } from "@oscharko-dev/keiko-evidence";
8
- import { apiKeyHeaderValue, ConfigInvalidError, DEFAULT_API_KEY_HEADER_NAME, ERROR_CODES, Gateway, GATEWAY_CONFIG_SCHEMA_VERSION, createDefaultChatCapability, createDefaultEmbeddingCapability, findConfiguredCapability, GatewayError, isLikelyEmbeddingModelId, isVoiceCapability, listConfiguredCapabilities, loadConfigFromFile, modelSupportsRealtimeVoice, modelSupportsSpeechInput, modelSupportsSpeechOutput, normalizeApiKeyHeaderName, parseGatewayConfig, selectRealtimeVoiceModel, selectSpeechOutputModel, selectSpeechToTextModel, toSafeObject, validateBaseUrl, PROVIDER_ENDPOINT_STYLES, REALTIME_AUTH_MODES, VOICE_PROVIDER_LOCALITIES, } from "@oscharko-dev/keiko-model-gateway";
9
- import { GATEWAY_SETUP_AUDIT_SCHEMA_VERSION, validateGatewaySetupAuditRecord, } from "@oscharko-dev/keiko-contracts";
8
+ import { apiKeyHeaderValue, ConfigInvalidError, DEFAULT_API_KEY_HEADER_NAME, ERROR_CODES, Gateway, GATEWAY_CONFIG_SCHEMA_VERSION, createDefaultChatCapability, createDefaultEmbeddingCapability, findConfiguredCapability, GatewayError, isLikelyEmbeddingModelId, isVoiceCapability, listConfiguredCapabilities, loadConfigFromFile, modelSupportsRealtimeVoice, modelSupportsSpeechInput, modelSupportsSpeechOutput, normalizeApiKeyHeaderName, parseGatewayConfig, requestOpenAIEmbedding, selectRealtimeVoiceModel, selectSpeechOutputModel, selectSpeechToTextModel, toSafeObject, validateBaseUrl, PROVIDER_ENDPOINT_STYLES, REALTIME_AUTH_MODES, VOICE_PROVIDER_LOCALITIES, } from "@oscharko-dev/keiko-model-gateway";
9
+ import { boundedUnsupportedReason, GATEWAY_SETUP_AUDIT_SCHEMA_VERSION, isChatCompatibleDeclaredMode, modelKindForDeclaredMode, validateGatewaySetupAuditRecord, } from "@oscharko-dev/keiko-contracts";
10
10
  import { classifyOutboundHost, gatewayFetch, readJsonCapped, } from "@oscharko-dev/keiko-model-gateway/internal/http";
11
11
  import { errorBody } from "./routes.js";
12
12
  import { currentGatewayConfig, currentGatewayEgressConfig } from "./deps.js";
@@ -28,7 +28,11 @@ const DEPLOYMENT_SMOKE_TIMEOUT_MS = 30_000;
28
28
  const FIGMA_CREDENTIAL_SMOKE_TIMEOUT_MS = 15_000;
29
29
  const FIGMA_CREDENTIAL_SMOKE_RESPONSE_BYTES = 64_000;
30
30
  const SETUP_SMOKE_CONCURRENCY = 4;
31
- const CHAT_COMPATIBLE_MODES = new Set(["chat", "completion", "responses"]);
31
+ // The chat vocabulary lives in the contract table (modelKindForDeclaredMode); this predicate
32
+ // only adapts it to the local "no declaration" case.
33
+ function declaresChatCompatibleMode(mode) {
34
+ return mode !== undefined && isChatCompatibleDeclaredMode(mode);
35
+ }
32
36
  const IMAGE_INPUT_ID_PATTERNS = [
33
37
  /(?:^|[-_/. ])(?:vision|multimodal|multi-modal|llava|pixtral|omni|gpt-4o)(?:$|[-_/. ])/i,
34
38
  /(?:^|[-_/. ])vl(?:$|[-_/. ])/i,
@@ -304,6 +308,9 @@ function discoveredCapabilityFields(discovered) {
304
308
  ? {}
305
309
  : { maxOutputTokens: discovered.maxOutputTokens }),
306
310
  ...(discovered?.toolCalling === undefined ? {} : { toolCalling: discovered.toolCalling }),
311
+ ...(discovered?.chatModeDeclared === undefined
312
+ ? {}
313
+ : { chatModeDeclared: discovered.chatModeDeclared }),
307
314
  };
308
315
  }
309
316
  function workflowCapabilityFields(modelId, baseCapability, existing, workflowEligibleModelIds) {
@@ -533,10 +540,16 @@ function metadataFromDiscoveryItem(item) {
533
540
  "supports_function_calling",
534
541
  "supportsFunctionCalling",
535
542
  ]);
543
+ // An affirmative chat-compatible `mode` declaration ranks the model ahead of mode-less
544
+ // entries as the conversation default (keiko-contracts conversationDefaultRank). Only ever
545
+ // true — declared NON-chat modes never reach the chat list, and "no mode" is no signal.
546
+ const mode = modelModeFromDiscoveryItem(item);
547
+ const chatModeDeclared = declaresChatCompatibleMode(mode);
536
548
  return {
537
549
  ...(contextWindow === undefined ? {} : { contextWindow }),
538
550
  ...(maxOutputTokens === undefined ? {} : { maxOutputTokens }),
539
551
  ...(toolCalling === undefined ? {} : { toolCalling }),
552
+ ...(chatModeDeclared ? { chatModeDeclared } : {}),
540
553
  };
541
554
  }
542
555
  function stringsFromValue(value) {
@@ -857,9 +870,6 @@ function modelModeFromDiscoveryItem(item) {
857
870
  }
858
871
  return undefined;
859
872
  }
860
- function isExplicitlyEmbeddingModel(item) {
861
- return modelModeFromDiscoveryItem(item) === "embedding";
862
- }
863
873
  // Issue #144: exported as part of the discovery-normalization seam so a
864
874
  // sibling test file can drive it with synthetic payloads. Behaviour unchanged
865
875
  // — only the visibility is widened.
@@ -869,8 +879,29 @@ export function isExplicitlyNonChatModel(item) {
869
879
  return true;
870
880
  }
871
881
  const mode = modelModeFromDiscoveryItem(item);
872
- return mode !== undefined && !CHAT_COMPATIBLE_MODES.has(mode);
882
+ return mode !== undefined && !declaresChatCompatibleMode(mode);
883
+ }
884
+ function isUnsupportedEntry(entry) {
885
+ return entry.kind === "unsupported" && entry.reason !== undefined;
886
+ }
887
+ // Classification WITHOUT a declaration: the id heuristic is all a `/models`-only gateway gives us.
888
+ function classifyUndeclaredDiscoveryItem(item, id, metadata) {
889
+ if (isLikelyEmbeddingModelId(id)) {
890
+ return { id, kind: "embedding", supportsImageInput: false, metadata };
891
+ }
892
+ return {
893
+ id,
894
+ kind: "chat",
895
+ supportsImageInput: supportsImageInputFromDiscoveryItem(item, id),
896
+ metadata,
897
+ };
873
898
  }
899
+ // A DECLARED mode is authoritative; the id heuristic is only the no-declaration fallback.
900
+ // Field incident (LiteLLM customer, 2026-08): the old order let a name beat the declaration, so a
901
+ // `mode: "rerank"` endpoint named "bge-reranker-v2-m3" was stored as this gateway's embedding
902
+ // model, bound to every new Knowledge Pod, and indexing wrote zero vectors. Keiko is
903
+ // model-agnostic — the customer hosts whatever models they like, so only the gateway's own
904
+ // statement about a model can decide its role.
874
905
  function classifyDiscoveryItem(item) {
875
906
  if (!isRecord(item)) {
876
907
  return undefined;
@@ -880,22 +911,41 @@ function classifyDiscoveryItem(item) {
880
911
  return undefined;
881
912
  }
882
913
  const metadata = metadataFromDiscoveryItem(item);
883
- if (isExplicitlyEmbeddingModel(item)) {
884
- return { id, kind: "embedding", supportsImageInput: false, metadata };
885
- }
886
- if (isExplicitlyNonChatModel(item)) {
887
- return isLikelyEmbeddingModelId(id)
888
- ? { id, kind: "embedding", supportsImageInput: false, metadata }
889
- : undefined;
890
- }
891
- return isLikelyEmbeddingModelId(id)
892
- ? { id, kind: "embedding", supportsImageInput: false, metadata }
893
- : {
914
+ const declaredMode = modelModeFromDiscoveryItem(item);
915
+ if (declaredMode !== undefined) {
916
+ const role = modelKindForDeclaredMode(declaredMode);
917
+ if (role === "unsupported") {
918
+ // The reason is drawn from a CLOSED vocabulary. A declared mode is gateway-controlled text of
919
+ // unbounded shape; echoing it verbatim would put foreign strings into the diagnostic channel
920
+ // and the setup response, which the redaction rules forbid.
921
+ const reason = boundedUnsupportedReason(declaredMode);
922
+ return { id, kind: "unsupported", supportsImageInput: false, metadata, reason };
923
+ }
924
+ if (role === "embedding") {
925
+ return { id, kind: "embedding", supportsImageInput: false, metadata };
926
+ }
927
+ return {
894
928
  id,
895
929
  kind: "chat",
896
930
  supportsImageInput: supportsImageInputFromDiscoveryItem(item, id),
897
931
  metadata,
898
932
  };
933
+ }
934
+ // No declaration. `capabilities.chat_completion === false` states what the model is NOT, which
935
+ // is not a role: an embedding model legitimately carries it. So the id heuristic still decides,
936
+ // exactly as before — it just cannot fall through to "chat".
937
+ if (isExplicitlyNonChatModel(item)) {
938
+ return isLikelyEmbeddingModelId(id)
939
+ ? { id, kind: "embedding", supportsImageInput: false, metadata }
940
+ : {
941
+ id,
942
+ kind: "unsupported",
943
+ supportsImageInput: false,
944
+ metadata,
945
+ reason: "not-chat-capable",
946
+ };
947
+ }
948
+ return classifyUndeclaredDiscoveryItem(item, id, metadata);
899
949
  }
900
950
  // Issue #144: exported as part of the discovery-normalization seam. Gateway setup now returns
901
951
  // embedding-capable records so setup can persist them for Local Knowledge while keeping them out of
@@ -903,7 +953,8 @@ function classifyDiscoveryItem(item) {
903
953
  // Returns undefined for unknown/non-record/unsupported/malformed input so
904
954
  // callers can drop the entry silently and keep healthy peers.
905
955
  export function modelIdFromDiscoveryItem(item) {
906
- return classifyDiscoveryItem(item)?.id;
956
+ const classified = classifyDiscoveryItem(item);
957
+ return classified === undefined || classified.kind === "unsupported" ? undefined : classified.id;
907
958
  }
908
959
  // Issue #144: exported as part of the discovery-normalization seam. Throws on schema-level
909
960
  // malformation (no data array) and on the "every entry filtered" terminal case so the caller
@@ -912,37 +963,69 @@ export function parseModelDiscovery(payload) {
912
963
  if (!isRecord(payload) || !Array.isArray(payload.data)) {
913
964
  throw new Error("model discovery response must contain a data array");
914
965
  }
915
- const entries = [];
916
- const seen = new Set();
966
+ // First occurrence wins, with ONE exception: a usable entry replaces an unsupported one for the
967
+ // same id. A LiteLLM `model_name` is a routing alias that can front several deployments, and an
968
+ // unusable one listed first must not shadow the usable duplicate behind it.
969
+ const byId = new Map();
917
970
  for (const item of payload.data) {
918
971
  const classified = classifyDiscoveryItem(item);
919
- if (classified !== undefined && !seen.has(classified.id)) {
920
- seen.add(classified.id);
921
- entries.push(classified);
972
+ if (classified === undefined)
973
+ continue;
974
+ const existing = byId.get(classified.id);
975
+ if (existing === undefined ||
976
+ (existing.kind === "unsupported" && classified.kind !== "unsupported")) {
977
+ byId.set(classified.id, classified);
922
978
  }
923
979
  }
980
+ const entries = [...byId.values()];
924
981
  // KEIKO-0325: raise a truncation flag alongside the limited slice so callers can
925
982
  // surface "N of M models discovered; add the rest by deployment name" instead of the
926
983
  // pre-fix silent drop. Kept optional-and-off-by-default so a fitting-within-cap
927
984
  // discovery does not carry a redundant `truncated: false` on the wire.
928
- const wasTruncated = entries.length > MAX_DISCOVERED_MODELS;
929
- const limited = entries.slice(0, MAX_DISCOVERED_MODELS);
930
- if (limited.length === 0) {
931
- throw new Error("model discovery returned no model ids");
932
- }
985
+ // Recognised-but-unusable models are reported, never configured: they get no provider entry and
986
+ // no slot in any selection list, but the operator learns they exist and why they were skipped.
987
+ // They are partitioned BEFORE the cap — a gateway listing 60 audio endpoints ahead of its chat
988
+ // aliases must not push the chat models past MAX_DISCOVERED_MODELS.
989
+ const unsupported = entries.filter(isUnsupportedEntry);
990
+ const usableEntries = entries.filter((entry) => entry.kind !== "unsupported");
991
+ const wasTruncated = usableEntries.length > MAX_DISCOVERED_MODELS;
992
+ const usable = usableEntries.slice(0, MAX_DISCOVERED_MODELS);
993
+ assertDiscoveryYieldedUsableModels(usable, unsupported);
933
994
  return {
934
- modelIds: limited.map((entry) => entry.id),
935
- chatModelIds: limited.filter((entry) => entry.kind === "chat").map((entry) => entry.id),
936
- embeddingModelIds: limited
995
+ modelIds: usable.map((entry) => entry.id),
996
+ chatModelIds: usable.filter((entry) => entry.kind === "chat").map((entry) => entry.id),
997
+ embeddingModelIds: usable
937
998
  .filter((entry) => entry.kind === "embedding")
938
999
  .map((entry) => entry.id),
939
- imageInputModelIds: limited
1000
+ imageInputModelIds: usable
940
1001
  .filter((entry) => entry.kind === "chat" && entry.supportsImageInput)
941
1002
  .map((entry) => entry.id),
942
- modelMetadata: Object.fromEntries(limited.map((entry) => [entry.id, entry.metadata])),
1003
+ modelMetadata: Object.fromEntries(usable.map((entry) => [entry.id, entry.metadata])),
1004
+ ...(unsupported.length > 0
1005
+ ? {
1006
+ unsupportedModels: unsupported.map((entry) => ({
1007
+ id: entry.id,
1008
+ reason: entry.reason,
1009
+ })),
1010
+ }
1011
+ : {}),
943
1012
  ...(wasTruncated ? { truncated: true } : {}),
944
1013
  };
945
1014
  }
1015
+ function assertDiscoveryYieldedUsableModels(usable, unsupported) {
1016
+ if (usable.length > 0)
1017
+ return;
1018
+ const terminal = unsupported.length > 0
1019
+ ? discoveryTerminal("model discovery found only models this gateway declared as unsupported modes", "DISCOVERY_ALL_ENTRIES_UNSUPPORTED")
1020
+ : discoveryTerminal("model discovery returned no model ids", "DISCOVERY_EMPTY");
1021
+ throw terminal;
1022
+ }
1023
+ // Tags a discovery terminal so the caller can tell "this gateway has no /model/info" (fall back to
1024
+ // /models) from "the endpoint answered and the answer is unusable" (surface it). Mirrors the
1025
+ // existing httpStatus tagging on fetch failures.
1026
+ function discoveryTerminal(message, code) {
1027
+ return Object.assign(new Error(message), { discoveryCode: code });
1028
+ }
946
1029
  export function parseModelList(payload) {
947
1030
  return parseModelDiscovery(payload).modelIds;
948
1031
  }
@@ -979,14 +1062,28 @@ async function fetchDiscoveryJson(url, apiKey, apiKeyHeaderName, egress) {
979
1062
  throw new Error("model discovery response was not readable JSON");
980
1063
  }
981
1064
  }
1065
+ // `/model/info` is a LiteLLM management route. Plenty of healthy deployments refuse it — an
1066
+ // ingress that exposes only /v1/*, a virtual key without management scope, a rate-limited proxy —
1067
+ // and they have always set up fine by degrading to the mode-free /models list. Losing mode
1068
+ // enrichment is not a silent failure: a genuinely bad credential still fails the chat smoke test
1069
+ // loudly. So EVERY transport or HTTP outcome falls back, exactly as before.
1070
+ //
1071
+ // Exactly one outcome must NOT fall back: the endpoint answered, Keiko understood every entry, and
1072
+ // every one declared a mode with no lane. Falling back there would re-read the same models from
1073
+ // /models WITHOUT their declarations and hand them to the id heuristic — resurrecting the very
1074
+ // misclassification this change exists to prevent.
1075
+ function modelInfoAnswerIsUnusable(cause) {
1076
+ return (cause?.discoveryCode ===
1077
+ "DISCOVERY_ALL_ENTRIES_UNSUPPORTED");
1078
+ }
982
1079
  async function discoverLiteLlmModelInfo(baseUrl, apiKey, apiKeyHeaderName, egress) {
983
1080
  for (const endpoint of modelInfoEndpointCandidates(baseUrl)) {
984
1081
  try {
985
1082
  return parseModelDiscovery(await fetchDiscoveryJson(endpoint, apiKey, apiKeyHeaderName, egress));
986
1083
  }
987
- catch {
988
- // /model/info is a LiteLLM-specific enrichment endpoint. If it is absent or blocked,
989
- // continue with OpenAI-compatible /models discovery so customer gateways are not broken.
1084
+ catch (cause) {
1085
+ if (modelInfoAnswerIsUnusable(cause) && cause instanceof Error)
1086
+ throw cause;
990
1087
  }
991
1088
  }
992
1089
  return undefined;
@@ -1263,6 +1360,63 @@ async function defaultGatewaySetupTester(config, candidateModelIds) {
1263
1360
  }, SETUP_SMOKE_CONCURRENCY);
1264
1361
  return { testedModelIds, responseFormatModelIds };
1265
1362
  }
1363
+ // Field incident (LiteLLM customer, 2026-08): chat models were smoke-tested, embedding models were
1364
+ // persisted on the strength of a classification alone. A model the gateway DECLARES as an embedding
1365
+ // engine but which cannot answer /embeddings was bound to every new Knowledge Pod, and indexing
1366
+ // wrote zero vectors with no earlier signal. One real request per candidate closes that gap; the
1367
+ // four-input space fingerprint stays where it belongs (the pod's first indexing preflight), because
1368
+ // on CPU-served hardware four inputs per model would make setup crawl.
1369
+ const EMBEDDING_PROBE_INPUT = "Keiko embedding setup probe";
1370
+ // One embedding request against the model, using the SAME endpoint protocol the provider will
1371
+ // persist with — an Azure deployment path must not be probed at the OpenAI-compatible URL, or the
1372
+ // probe measures a 404 that production would never see.
1373
+ async function embedOnceForProbe(provider, modelId) {
1374
+ return requestOpenAIEmbedding({
1375
+ endpoint: provider.baseUrl,
1376
+ apiKey: provider.apiKey,
1377
+ ...(provider.apiKeyHeaderName !== undefined
1378
+ ? { apiKeyHeaderName: provider.apiKeyHeaderName }
1379
+ : {}),
1380
+ ...(provider.egress !== undefined ? { egress: provider.egress } : {}),
1381
+ ...(provider.endpointStyle !== undefined ? { endpointStyle: provider.endpointStyle } : {}),
1382
+ ...(provider.apiVersion !== undefined ? { apiVersion: provider.apiVersion } : {}),
1383
+ modelId,
1384
+ input: EMBEDDING_PROBE_INPUT,
1385
+ timeoutMs: provider.timeoutMs,
1386
+ });
1387
+ }
1388
+ // Transient kinds get exactly ONE retry, matching the chat lane's `maxRetries: 1`: a single
1389
+ // rate-limit or cold-start blip must not permanently exclude a working embedding model, and
1390
+ // requestOpenAIEmbedding is a bare transport that does no retrying of its own.
1391
+ const RETRYABLE_PROBE_KINDS = new Set([
1392
+ "rate-limited",
1393
+ "timeout",
1394
+ "transport",
1395
+ ]);
1396
+ // An immediate retry against a gateway that just answered 429 answers 429 again, so it would burn a
1397
+ // request and change nothing. One short pause, matching the chat lane's backoff base.
1398
+ const EMBEDDING_PROBE_RETRY_DELAY_MS = 500;
1399
+ async function defaultGatewayEmbeddingProbe(config, candidateModelIds) {
1400
+ return passingCandidates(candidateModelIds, async (modelId) => {
1401
+ const provider = config.providers.find((entry) => entry.modelId === modelId);
1402
+ if (provider === undefined)
1403
+ throw new Error("embedding candidate has no provider entry");
1404
+ let outcome = await embedOnceForProbe(provider, modelId);
1405
+ if (!outcome.ok && RETRYABLE_PROBE_KINDS.has(outcome.kind)) {
1406
+ await new Promise((resolve) => setTimeout(resolve, EMBEDDING_PROBE_RETRY_DELAY_MS));
1407
+ outcome = await embedOnceForProbe(provider, modelId);
1408
+ }
1409
+ // The per-model verdict is what the operator acts on, and it travels in
1410
+ // droppedEmbeddingModelIds / unverifiedEmbeddingModelIds. passingCandidates drops the
1411
+ // rejection, which is the intended contract here: a failed candidate is not admitted.
1412
+ if (!outcome.ok || outcome.value.vector.length === 0) {
1413
+ throw new Error("embedding probe returned no usable vector");
1414
+ }
1415
+ }, SETUP_SMOKE_CONCURRENCY);
1416
+ }
1417
+ function gatewayEmbeddingProbe(deps) {
1418
+ return deps.gatewayEmbeddingProbe ?? defaultGatewayEmbeddingProbe;
1419
+ }
1266
1420
  function gatewaySetupTester(deps) {
1267
1421
  return deps.gatewaySetupTester ?? defaultGatewaySetupTester;
1268
1422
  }
@@ -2706,6 +2860,9 @@ function normalizeDiscoveryResult(result) {
2706
2860
  // so downstream setup can surface "N of M models discovered" instead of the
2707
2861
  // pre-fix silent drop past MAX_DISCOVERED_MODELS.
2708
2862
  ...(result.truncated === true ? { truncated: true } : {}),
2863
+ ...(result.unsupportedModels !== undefined
2864
+ ? { unsupportedModels: result.unsupportedModels }
2865
+ : {}),
2709
2866
  };
2710
2867
  }
2711
2868
  return normalizeLegacyDiscoveryResult(result);
@@ -2914,6 +3071,61 @@ function reportDiscoveryTruncation(diagnostics, candidateModels) {
2914
3071
  retainedModelCount: candidateModels.modelIds.length,
2915
3072
  });
2916
3073
  }
3074
+ function probeConfigForModels(input, modelIds, smokeTimeoutMs) {
3075
+ return parseGatewayConfig(withInheritedEgress(buildRawConfig(input.baseUrl, input.apiKey, modelIds, candidateProbeOptions(input, smokeTimeoutMs)), input.egress), input.env, linkLocalGatewayOverrideOptions(input.env));
3076
+ }
3077
+ // The candidate config carries only the chat models, so the probe needs its own provider view over
3078
+ // the embedding candidates — same endpoint, credential, protocol and timeout.
3079
+ function embeddingProbeConfigFor(input, candidateModels, smokeTimeoutMs, fallback) {
3080
+ if (candidateModels.embeddingModelIds.length === 0)
3081
+ return fallback;
3082
+ return probeConfigForModels(input, candidateModels.embeddingModelIds, smokeTimeoutMs);
3083
+ }
3084
+ // Probe-gated embedding admission. A NEW candidate must answer a real embedding request before it
3085
+ // is persisted as this gateway's embedding model. A STORED one that fails is RETAINED and reported
3086
+ // unverified: a transient endpoint outage during a re-save must never unpin the embedding model of
3087
+ // every working Knowledge Pod (that would be a worse failure than the one this closes).
3088
+ async function admitEmbeddingCandidates(input, probeConfig, candidates) {
3089
+ if (candidates.length === 0) {
3090
+ return { admitted: candidates, retainedUnverified: [], droppedUnverified: [] };
3091
+ }
3092
+ // Probe-gating applies to every model whose ROLE Keiko inferred. Only an explicit ROLE assertion
3093
+ // is exempt: a stored embedding capability, or an embedding id the client asserted. Deployment
3094
+ // NAMES are deliberately NOT exempt — naming a deployment states its identity, not its role; the
3095
+ // role there still comes from Keiko's own id heuristic, which is exactly what the probe corrects.
3096
+ const asserted = new Set([...input.storedEmbeddingModelIds, ...input.submittedEmbeddingModelIds]);
3097
+ const answered = new Set(await input.embeddingProbe(probeConfig, candidates));
3098
+ const admitted = candidates.filter((id) => answered.has(id) || asserted.has(id));
3099
+ // Split the failures: an asserted model stays configured and is flagged; an inferred one is gone.
3100
+ const failed = candidates.filter((id) => !answered.has(id));
3101
+ return {
3102
+ admitted,
3103
+ retainedUnverified: failed.filter((id) => asserted.has(id)),
3104
+ droppedUnverified: failed.filter((id) => !asserted.has(id)),
3105
+ };
3106
+ }
3107
+ // Body-free counterpart to reportDiscoveryTruncation: counts and reason codes only, never a model
3108
+ // id or an endpoint. Ids belong in the setup RESPONSE, which the operator sees; the diagnostic
3109
+ // channel stays free of gateway inventory.
3110
+ function reportUnusableDiscoveredModels(diagnostics, unsupported, admission) {
3111
+ const retained = admission.retainedUnverified.length;
3112
+ const dropped = admission.droppedUnverified.length;
3113
+ if (unsupported.length === 0 && retained === 0 && dropped === 0)
3114
+ return;
3115
+ emitServerDiagnostic(diagnostics, {
3116
+ correlationId: randomUUID(),
3117
+ timestamp: new Date().toISOString(),
3118
+ operation: "POST /api/gateway/setup",
3119
+ source: "gateway-setup.discovery",
3120
+ errorClass: "GatewayDiscoveryUnusableModels",
3121
+ message: "Setup skipped models the gateway declared as unsupported modes or that failed the embedding probe.",
3122
+ code: "GATEWAY_DISCOVERY_UNUSABLE_MODELS",
3123
+ unsupportedModelCount: unsupported.length,
3124
+ unsupportedReasons: [...new Set(unsupported.map((entry) => entry.reason))].sort((a, b) => a.localeCompare(b)),
3125
+ unverifiedEmbeddingModelCount: retained,
3126
+ droppedEmbeddingModelCount: dropped,
3127
+ });
3128
+ }
2917
3129
  async function verifySetupCandidate(input) {
2918
3130
  // Defence-in-depth: never send the credential to a candidate URL that has not passed the same
2919
3131
  // scheme/credential/loopback validation as the originally submitted base URL.
@@ -2924,17 +3136,36 @@ async function verifySetupCandidate(input) {
2924
3136
  const smokeTimeoutMs = input.deploymentNames.length > 0
2925
3137
  ? DEPLOYMENT_SMOKE_TIMEOUT_MS
2926
3138
  : DISCOVERED_MODEL_SMOKE_TIMEOUT_MS;
2927
- const candidateRawConfig = buildRawConfig(input.baseUrl, input.apiKey, candidateModels.chatModelIds, candidateProbeOptions(input, smokeTimeoutMs));
2928
- const candidateConfig = parseGatewayConfig(withInheritedEgress(candidateRawConfig, input.egress), input.env, linkLocalGatewayOverrideOptions(input.env));
3139
+ const candidateConfig = probeConfigForModels(input, candidateModels.chatModelIds, smokeTimeoutMs);
3140
+ const embeddingAdmission = await admitEmbeddingCandidates(input, embeddingProbeConfigFor(input, candidateModels, smokeTimeoutMs, candidateConfig), candidateModels.embeddingModelIds);
3141
+ const admittedModels = {
3142
+ ...candidateModels,
3143
+ embeddingModelIds: embeddingAdmission.admitted,
3144
+ };
3145
+ // Emitted BEFORE the chat smoke test: the tester throws on an all-rejected gateway, and the
3146
+ // record of what discovery refused is most valuable for exactly that failed attempt.
3147
+ reportUnusableDiscoveredModels(input.diagnostics, candidateModels.unsupportedModels ?? [], embeddingAdmission);
2929
3148
  const testResult = normalizeSetupTestResult(await input.tester(candidateConfig, candidateModels.chatModelIds));
2930
3149
  assertImageInputModelsWereTested(input.imageInputModelIds, testResult.testedModelIds);
2931
- const rawConfigWithOptionalBlocks = finalRawConfigForTestedSetup(input, testResult, candidateModels);
3150
+ const rawConfigWithOptionalBlocks = finalRawConfigForTestedSetup(input, testResult, admittedModels);
2932
3151
  const config = parseGatewayConfig(withInheritedEgress(rawConfigWithOptionalBlocks, input.egress), input.env, linkLocalGatewayOverrideOptions(input.env));
3152
+ return verifiedSetupResult(rawConfigWithOptionalBlocks, config, testResult, candidateModels, embeddingAdmission);
3153
+ }
3154
+ function verifiedSetupResult(rawConfig, config, testResult, candidateModels, embeddingAdmission) {
2933
3155
  return {
2934
- rawConfig: rawConfigWithOptionalBlocks,
3156
+ rawConfig,
2935
3157
  config,
2936
3158
  testedModelIds: testResult.testedModelIds,
2937
- skippedModelIds: skippedModelIdsForSetup(candidateModels.modelIds, testResult.testedModelIds, candidateModels.embeddingModelIds),
3159
+ skippedModelIds: skippedModelIdsForSetup(candidateModels.modelIds, testResult.testedModelIds, embeddingAdmission.admitted),
3160
+ ...(candidateModels.unsupportedModels !== undefined
3161
+ ? { unsupportedModels: candidateModels.unsupportedModels }
3162
+ : {}),
3163
+ ...(embeddingAdmission.retainedUnverified.length > 0
3164
+ ? { unverifiedEmbeddingModelIds: embeddingAdmission.retainedUnverified }
3165
+ : {}),
3166
+ ...(embeddingAdmission.droppedUnverified.length > 0
3167
+ ? { droppedEmbeddingModelIds: embeddingAdmission.droppedUnverified }
3168
+ : {}),
2938
3169
  };
2939
3170
  }
2940
3171
  // KEIKO-0497 (#2901): configuring the gateway points the product at an outbound endpoint and can
@@ -3025,7 +3256,7 @@ function recordGatewaySetupAudit(deps, request, config, outcome) {
3025
3256
  }));
3026
3257
  }
3027
3258
  }
3028
- function setupSuccessResult(config, testedModelIds, skippedModelIds) {
3259
+ function setupSuccessResult(config, testedModelIds, skippedModelIds, discoveryReport = {}) {
3029
3260
  const testedModelId = testedModelIds[0] ?? "unknown";
3030
3261
  return {
3031
3262
  status: 200,
@@ -3034,6 +3265,17 @@ function setupSuccessResult(config, testedModelIds, skippedModelIds) {
3034
3265
  testedModelId,
3035
3266
  testedModelIds,
3036
3267
  skippedModelIds,
3268
+ // The operator learns which models the gateway offered that Keiko will not use, and why —
3269
+ // silence here is what made a misconfigured gateway undiagnosable in the field.
3270
+ ...(discoveryReport.unsupportedModels !== undefined
3271
+ ? { unsupportedModels: discoveryReport.unsupportedModels }
3272
+ : {}),
3273
+ ...(discoveryReport.unverifiedEmbeddingModelIds !== undefined
3274
+ ? { unverifiedEmbeddingModelIds: discoveryReport.unverifiedEmbeddingModelIds }
3275
+ : {}),
3276
+ ...(discoveryReport.droppedEmbeddingModelIds !== undefined
3277
+ ? { droppedEmbeddingModelIds: discoveryReport.droppedEmbeddingModelIds }
3278
+ : {}),
3037
3279
  providerCount: config.providers.length,
3038
3280
  models: listConfiguredCapabilities(config),
3039
3281
  config: toSafeObject(config),
@@ -3195,10 +3437,21 @@ function finalizeVerifiedCandidate(verified, current, deps, gatewayConfig, reque
3195
3437
  : withDiskGatewayEgress(verified.rawConfig, gatewayConfig.storagePath, deps), gatewayConfig.storagePath, deps);
3196
3438
  gatewayConfig.set(verified.config, true);
3197
3439
  recordGatewaySetupAudit(deps, request, verified.config, "candidate-accepted");
3198
- return setupSuccessResult(verified.config, verified.testedModelIds, verified.skippedModelIds);
3440
+ return setupSuccessResult(verified.config, verified.testedModelIds, verified.skippedModelIds, {
3441
+ ...(verified.unsupportedModels !== undefined
3442
+ ? { unsupportedModels: verified.unsupportedModels }
3443
+ : {}),
3444
+ ...(verified.unverifiedEmbeddingModelIds !== undefined
3445
+ ? { unverifiedEmbeddingModelIds: verified.unverifiedEmbeddingModelIds }
3446
+ : {}),
3447
+ ...(verified.droppedEmbeddingModelIds !== undefined
3448
+ ? { droppedEmbeddingModelIds: verified.droppedEmbeddingModelIds }
3449
+ : {}),
3450
+ });
3199
3451
  }
3200
- async function trySetupCandidate(baseUrl, request, deps, gatewayConfig, tester, discovery, current) {
3452
+ async function trySetupCandidate(baseUrl, request, deps, gatewayConfig, seams, current) {
3201
3453
  const verified = await verifySetupCandidate({
3454
+ embeddingProbe: seams.embeddingProbe,
3202
3455
  preserveExisting: request.preserveExisting,
3203
3456
  baseUrl,
3204
3457
  apiKey: request.apiKey,
@@ -3219,8 +3472,8 @@ async function trySetupCandidate(baseUrl, request, deps, gatewayConfig, tester,
3219
3472
  ? request.workflowEligibleModelIds
3220
3473
  : undefined,
3221
3474
  voiceProviders: request.voiceProviders,
3222
- tester,
3223
- discovery,
3475
+ tester: seams.tester,
3476
+ discovery: seams.discovery,
3224
3477
  env: deps.env,
3225
3478
  egress: egressForCandidateValidation(deps),
3226
3479
  figmaAccessToken: request.figmaAccessToken,
@@ -3458,8 +3711,11 @@ function shouldRequireDeploymentNames(request, baseUrlCandidates, env) {
3458
3711
  return baseUrlCandidates.some((baseUrl) => isAzureFoundryBaseUrl(baseUrl));
3459
3712
  }
3460
3713
  async function verifyAndSaveGatewaySetup(request, current, deps, gatewayConfig) {
3461
- const tester = gatewaySetupTester(deps);
3462
- const discovery = deps.gatewayModelDiscovery ?? defaultGatewayModelDiscovery;
3714
+ const seams = {
3715
+ tester: gatewaySetupTester(deps),
3716
+ embeddingProbe: gatewayEmbeddingProbe(deps),
3717
+ discovery: deps.gatewayModelDiscovery ?? defaultGatewayModelDiscovery,
3718
+ };
3463
3719
  const figmaFailure = await verifySubmittedFigmaCredential(request, deps);
3464
3720
  if (figmaFailure !== undefined) {
3465
3721
  return figmaFailure;
@@ -3471,7 +3727,7 @@ async function verifyAndSaveGatewaySetup(request, current, deps, gatewayConfig)
3471
3727
  const errors = [];
3472
3728
  for (const baseUrl of baseUrlCandidates) {
3473
3729
  try {
3474
- return await trySetupCandidate(baseUrl, request, deps, gatewayConfig, tester, discovery, current);
3730
+ return await trySetupCandidate(baseUrl, request, deps, gatewayConfig, seams, current);
3475
3731
  }
3476
3732
  catch (error) {
3477
3733
  reportSetupVerificationFailure(deps, error, request.correlationId, "gateway.setup.provider-verify");