@sriinnu/kosha-discovery 1.2.0 → 1.5.0

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 (164) hide show
  1. package/README.md +65 -26
  2. package/dist/aliases.d.ts +6 -1
  3. package/dist/aliases.d.ts.map +1 -1
  4. package/dist/aliases.js +38 -12
  5. package/dist/aliases.js.map +1 -1
  6. package/dist/cache.d.ts.map +1 -1
  7. package/dist/cache.js +25 -2
  8. package/dist/cache.js.map +1 -1
  9. package/dist/claude-generation.d.ts +59 -0
  10. package/dist/claude-generation.d.ts.map +1 -0
  11. package/dist/claude-generation.js +117 -0
  12. package/dist/claude-generation.js.map +1 -0
  13. package/dist/cli-cmd-doctor.d.ts +17 -0
  14. package/dist/cli-cmd-doctor.d.ts.map +1 -0
  15. package/dist/cli-cmd-doctor.js +199 -0
  16. package/dist/cli-cmd-doctor.js.map +1 -0
  17. package/dist/cli-cmd-model.js +2 -2
  18. package/dist/cli-cmd-model.js.map +1 -1
  19. package/dist/cli-cmd-spend.d.ts +10 -0
  20. package/dist/cli-cmd-spend.d.ts.map +1 -0
  21. package/dist/cli-cmd-spend.js +130 -0
  22. package/dist/cli-cmd-spend.js.map +1 -0
  23. package/dist/cli-commands.d.ts +4 -1
  24. package/dist/cli-commands.d.ts.map +1 -1
  25. package/dist/cli-commands.js +10 -2
  26. package/dist/cli-commands.js.map +1 -1
  27. package/dist/cli-format.js.map +1 -1
  28. package/dist/cli-help.d.ts.map +1 -1
  29. package/dist/cli-help.js +4 -2
  30. package/dist/cli-help.js.map +1 -1
  31. package/dist/cli.js +10 -0
  32. package/dist/cli.js.map +1 -1
  33. package/dist/cost.d.ts +152 -0
  34. package/dist/cost.d.ts.map +1 -0
  35. package/dist/cost.js +377 -0
  36. package/dist/cost.js.map +1 -0
  37. package/dist/credentials/resolver.d.ts +10 -0
  38. package/dist/credentials/resolver.d.ts.map +1 -1
  39. package/dist/credentials/resolver.js +64 -31
  40. package/dist/credentials/resolver.js.map +1 -1
  41. package/dist/discovery/anthropic.d.ts +19 -1
  42. package/dist/discovery/anthropic.d.ts.map +1 -1
  43. package/dist/discovery/anthropic.js +112 -8
  44. package/dist/discovery/anthropic.js.map +1 -1
  45. package/dist/discovery/base.d.ts +7 -0
  46. package/dist/discovery/base.d.ts.map +1 -1
  47. package/dist/discovery/base.js +32 -4
  48. package/dist/discovery/base.js.map +1 -1
  49. package/dist/discovery/bedrock.d.ts.map +1 -1
  50. package/dist/discovery/cerebras.d.ts.map +1 -1
  51. package/dist/discovery/cohere.d.ts.map +1 -1
  52. package/dist/discovery/deepinfra.d.ts.map +1 -1
  53. package/dist/discovery/deepseek.d.ts.map +1 -1
  54. package/dist/discovery/fireworks.d.ts.map +1 -1
  55. package/dist/discovery/glm.d.ts.map +1 -1
  56. package/dist/discovery/google.d.ts +3 -1
  57. package/dist/discovery/google.d.ts.map +1 -1
  58. package/dist/discovery/google.js +13 -6
  59. package/dist/discovery/google.js.map +1 -1
  60. package/dist/discovery/groq.d.ts.map +1 -1
  61. package/dist/discovery/index.d.ts +2 -0
  62. package/dist/discovery/index.d.ts.map +1 -1
  63. package/dist/discovery/index.js +6 -0
  64. package/dist/discovery/index.js.map +1 -1
  65. package/dist/discovery/llama-cpp.d.ts.map +1 -1
  66. package/dist/discovery/lmstudio.d.ts +26 -0
  67. package/dist/discovery/lmstudio.d.ts.map +1 -0
  68. package/dist/discovery/lmstudio.js +93 -0
  69. package/dist/discovery/lmstudio.js.map +1 -0
  70. package/dist/discovery/minimax.d.ts.map +1 -1
  71. package/dist/discovery/mistral.d.ts.map +1 -1
  72. package/dist/discovery/moonshot.d.ts.map +1 -1
  73. package/dist/discovery/nvidia.d.ts.map +1 -1
  74. package/dist/discovery/ollama.d.ts.map +1 -1
  75. package/dist/discovery/openai-compatible.d.ts.map +1 -1
  76. package/dist/discovery/openai.d.ts.map +1 -1
  77. package/dist/discovery/openrouter.d.ts +29 -5
  78. package/dist/discovery/openrouter.d.ts.map +1 -1
  79. package/dist/discovery/openrouter.js +56 -18
  80. package/dist/discovery/openrouter.js.map +1 -1
  81. package/dist/discovery/perplexity.d.ts.map +1 -1
  82. package/dist/discovery/promo-overrides.js.map +1 -1
  83. package/dist/discovery/static-direct.d.ts +9 -1
  84. package/dist/discovery/static-direct.d.ts.map +1 -1
  85. package/dist/discovery/static-direct.js +68 -7
  86. package/dist/discovery/static-direct.js.map +1 -1
  87. package/dist/discovery/together.d.ts.map +1 -1
  88. package/dist/discovery/vercel.d.ts.map +1 -1
  89. package/dist/discovery/vertex.d.ts.map +1 -1
  90. package/dist/discovery/vllm.d.ts +26 -0
  91. package/dist/discovery/vllm.d.ts.map +1 -0
  92. package/dist/discovery/vllm.js +93 -0
  93. package/dist/discovery/vllm.js.map +1 -0
  94. package/dist/discovery/zai.d.ts.map +1 -1
  95. package/dist/discovery-contract.d.ts +7 -0
  96. package/dist/discovery-contract.d.ts.map +1 -1
  97. package/dist/discovery-contract.js.map +1 -1
  98. package/dist/discovery-routes.d.ts +9 -0
  99. package/dist/discovery-routes.d.ts.map +1 -1
  100. package/dist/discovery-routes.js +106 -18
  101. package/dist/discovery-routes.js.map +1 -1
  102. package/dist/enrichment/litellm.d.ts +1 -1
  103. package/dist/enrichment/litellm.d.ts.map +1 -1
  104. package/dist/enrichment/litellm.js +3 -3
  105. package/dist/entry.d.ts +14 -0
  106. package/dist/entry.d.ts.map +1 -0
  107. package/dist/entry.js +26 -0
  108. package/dist/entry.js.map +1 -0
  109. package/dist/index.d.ts +10 -0
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +5 -0
  112. package/dist/index.js.map +1 -1
  113. package/dist/mcp-server.d.ts +207 -2
  114. package/dist/mcp-server.d.ts.map +1 -1
  115. package/dist/mcp-server.js +203 -51
  116. package/dist/mcp-server.js.map +1 -1
  117. package/dist/model-features.d.ts.map +1 -1
  118. package/dist/model-features.js +11 -2
  119. package/dist/model-features.js.map +1 -1
  120. package/dist/normalize.d.ts +7 -7
  121. package/dist/normalize.js +8 -8
  122. package/dist/provider-catalog.d.ts.map +1 -1
  123. package/dist/provider-catalog.js +26 -0
  124. package/dist/provider-catalog.js.map +1 -1
  125. package/dist/proxy.d.ts +49 -7
  126. package/dist/proxy.d.ts.map +1 -1
  127. package/dist/proxy.js +754 -89
  128. package/dist/proxy.js.map +1 -1
  129. package/dist/registry-query.js +2 -2
  130. package/dist/registry-query.js.map +1 -1
  131. package/dist/registry-routing.d.ts +65 -0
  132. package/dist/registry-routing.d.ts.map +1 -0
  133. package/dist/registry-routing.js +165 -0
  134. package/dist/registry-routing.js.map +1 -0
  135. package/dist/registry-runtime.d.ts +2 -0
  136. package/dist/registry-runtime.d.ts.map +1 -1
  137. package/dist/registry-runtime.js +159 -15
  138. package/dist/registry-runtime.js.map +1 -1
  139. package/dist/registry-selection.js +6 -0
  140. package/dist/registry-selection.js.map +1 -1
  141. package/dist/registry.d.ts +69 -0
  142. package/dist/registry.d.ts.map +1 -1
  143. package/dist/registry.js +133 -1
  144. package/dist/registry.js.map +1 -1
  145. package/dist/resilience.d.ts +15 -0
  146. package/dist/resilience.d.ts.map +1 -1
  147. package/dist/resilience.js +23 -1
  148. package/dist/resilience.js.map +1 -1
  149. package/dist/server.d.ts +44 -2
  150. package/dist/server.d.ts.map +1 -1
  151. package/dist/server.js +328 -33
  152. package/dist/server.js.map +1 -1
  153. package/dist/tally.d.ts +80 -0
  154. package/dist/tally.d.ts.map +1 -0
  155. package/dist/tally.js +176 -0
  156. package/dist/tally.js.map +1 -0
  157. package/dist/types.d.ts +22 -1
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/wire-anthropic.d.ts +264 -0
  160. package/dist/wire-anthropic.d.ts.map +1 -0
  161. package/dist/wire-anthropic.js +960 -0
  162. package/dist/wire-anthropic.js.map +1 -0
  163. package/package.json +14 -10
  164. package/logo.png +0 -0
package/dist/entry.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * kosha-discovery — "am I the process entry point?" helper.
3
+ *
4
+ * `import.meta.url === \`file://${process.argv[1]}\`` breaks on symlinked bins
5
+ * (global npm installs point argv[1] at the link, import.meta.url at the
6
+ * target), relative invocations, and paths with spaces. Resolving argv[1]
7
+ * through realpath + pathToFileURL handles all three, and the try/catch keeps
8
+ * test runners (which import the module without argv[1] pointing at it) from
9
+ * ever starting a server or a stdio loop.
10
+ * @module
11
+ */
12
+ import { realpathSync } from "node:fs";
13
+ import { pathToFileURL } from "node:url";
14
+ /** True when the module at `importMetaUrl` is the script Node was asked to run. */
15
+ export function isMainModule(importMetaUrl) {
16
+ try {
17
+ const entry = process.argv[1];
18
+ if (!entry)
19
+ return false;
20
+ return importMetaUrl === pathToFileURL(realpathSync(entry)).href;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,aAAqB;IACjD,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,OAAO,aAAa,KAAK,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -10,6 +10,16 @@ export { AliasResolver, DEFAULT_ALIASES } from "./aliases.js";
10
10
  export { KoshaCache } from "./cache.js";
11
11
  export { DISCOVERY_SCHEMA_VERSION, discoveryRoles, makeModelKey, rawCapabilitiesForModel, trustedCapabilitiesForModel, } from "./discovery-contract.js";
12
12
  export type { DiscoveryBindingHintsV1, DiscoveryBindingQuery, DiscoveryChangeV1, DiscoveryCheapestCandidateV1, DiscoveryCheapestResultV1, DiscoveryCredentialPrompt, DiscoveryDeltaV1, DiscoveryHealthRecord, DiscoveryModelV1, DiscoveryProviderV1, DiscoveryRoleDefinition, DiscoverySnapshotV1, TrustedCapability, } from "./discovery-contract.js";
13
+ export { parseRouteStrategy, ROUTE_STRATEGIES, } from "./registry-routing.js";
14
+ export type { RankedRoute, RouteHealth, RouteStrategy } from "./registry-routing.js";
15
+ export { actualCostFromUsage, appendLedgerEntry, DEFAULT_LEDGER_PATH, estimateRequestCost, isRequestRow, ledgerRowUsd, readMonthlyBudgetUsd, readSpendForMonth, readTenantBudgetUsd, } from "./cost.js";
16
+ export type { ActualUsageCost, CostEstimate, LedgerEntry, UsageShape } from "./cost.js";
17
+ export { estimateUsdCost, normalizeTokenUsage, tallyCosts } from "./tally.js";
18
+ export type { NormalizedTokenUsage, TallyCall, TallyModelSubtotal, TallyResult, TokenUsage, UsdCostBreakdown, } from "./tally.js";
19
+ export { claudeEffortLadder, claudeSamplingSupport, claudeSupportsForcedToolChoice, claudeSupportsNativeJsonSchema, claudeSupportsPrefill, parseClaudeGeneration, } from "./claude-generation.js";
20
+ export type { ClaudeEffort, ClaudeGeneration, SamplingSupport } from "./claude-generation.js";
21
+ export { coerceOpenAIChatRequest, toOpenAIUsage, translateAnthropicStreamToOpenAI, translateAnthropicToOpenAI, translateOpenAIToAnthropic, translateOpenAIToAnthropicWithNotes, UnsupportedWireContentError, } from "./wire-anthropic.js";
22
+ export type { AnthropicContentBlock, AnthropicMessagesRequest, AnthropicMessagesResponse, AnthropicStreamTranslation, AnthropicUsage, OpenAIChatRequest, OpenAIChatResponse, OpenAIToolCall, OpenAIUsage, WireTranslation, } from "./wire-anthropic.js";
13
23
  export { extractModelVersion, extractOriginProvider, normalizeModelId } from "./normalize.js";
14
24
  export { inferTokenizerFamily } from "./tokenizer-family.js";
15
25
  export { inferParallelToolCalls, inferStructuredOutputModes, inferToolDialect } from "./model-features.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,GAC3B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EACN,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,YAAY,EACX,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,YAAY,EACZ,aAAa,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,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,GACX,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,YAAY,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,eAAe,EAAE,aAAa,CAAC,CAM3H"}
package/dist/index.js CHANGED
@@ -9,6 +9,11 @@ export { ModelRegistry } from "./registry.js";
9
9
  export { AliasResolver, DEFAULT_ALIASES } from "./aliases.js";
10
10
  export { KoshaCache } from "./cache.js";
11
11
  export { DISCOVERY_SCHEMA_VERSION, discoveryRoles, makeModelKey, rawCapabilitiesForModel, trustedCapabilitiesForModel, } from "./discovery-contract.js";
12
+ export { parseRouteStrategy, ROUTE_STRATEGIES, } from "./registry-routing.js";
13
+ export { actualCostFromUsage, appendLedgerEntry, DEFAULT_LEDGER_PATH, estimateRequestCost, isRequestRow, ledgerRowUsd, readMonthlyBudgetUsd, readSpendForMonth, readTenantBudgetUsd, } from "./cost.js";
14
+ export { estimateUsdCost, normalizeTokenUsage, tallyCosts } from "./tally.js";
15
+ export { claudeEffortLadder, claudeSamplingSupport, claudeSupportsForcedToolChoice, claudeSupportsNativeJsonSchema, claudeSupportsPrefill, parseClaudeGeneration, } from "./claude-generation.js";
16
+ export { coerceOpenAIChatRequest, toOpenAIUsage, translateAnthropicStreamToOpenAI, translateAnthropicToOpenAI, translateOpenAIToAnthropic, translateOpenAIToAnthropicWithNotes, UnsupportedWireContentError, } from "./wire-anthropic.js";
12
17
  export { extractModelVersion, extractOriginProvider, normalizeModelId } from "./normalize.js";
13
18
  export { inferTokenizerFamily } from "./tokenizer-family.js";
14
19
  export { inferParallelToolCalls, inferStructuredOutputModes, inferToolDialect } from "./model-features.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,GAC3B,MAAM,yBAAyB,CAAC;AAgBjC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EACN,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAkC/B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAyC;IAC1E,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC1B,OAAO,QAAQ,CAAC;AACjB,CA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M,uBAAuB,CAAC;AAkC/B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAyC;IAC1E,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC1B,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -1,18 +1,223 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * kosha-discovery — MCP server (stdio transport, protocol 2024-11-05).
3
+ * kosha-discovery — MCP server (stdio transport).
4
4
  *
5
5
  * Exposes the local kosha registry as MCP tools so AI agents can query
6
6
  * model pricing, routing, and health without HTTP.
7
7
  *
8
+ * Protocol: JSON-RPC 2.0 over newline-delimited stdio. The server speaks
9
+ * every MCP revision in {@link MCP_PROTOCOL_VERSIONS} and echoes the
10
+ * client's requested revision back when it is one of them (otherwise it
11
+ * answers with the newest it supports, per the MCP negotiation rule).
12
+ *
8
13
  * Tools:
9
14
  * kosha_query_models — list / filter models
10
15
  * kosha_cheapest_model — cheapest model meeting requirements
16
+ * kosha_ranked_routes — strategy-ranked routes (cheapest / fastest / reliable / balanced)
11
17
  * kosha_model_detail — full detail for one model
12
18
  * kosha_model_routes — all provider routes for a model
13
19
  * kosha_resolve_alias — alias → canonical ID
14
20
  * kosha_provider_health — provider auth + error status
21
+ * kosha_context_strategy — context-management advice for a long conversation
22
+ *
23
+ * The JSON-RPC handler ({@link handleJsonRpc}) is exported and pure over an
24
+ * injected registry loader so it can be unit-tested; the stdio loop only
25
+ * starts when this file is the process entry point.
15
26
  * @module
16
27
  */
17
- export {};
28
+ import { ModelRegistry } from "./registry.js";
29
+ /** Package version, read from package.json so `serverInfo.version` never drifts from the release. */
30
+ export declare const KOSHA_MCP_VERSION: string;
31
+ /** MCP protocol revisions this server implements, newest first. */
32
+ export declare const MCP_PROTOCOL_VERSIONS: readonly string[];
33
+ /**
34
+ * Pick the protocol revision to answer an `initialize` with: the client's
35
+ * own when we support it, otherwise our newest (the client then decides
36
+ * whether to proceed).
37
+ */
38
+ export declare function negotiateProtocolVersion(requested: unknown): string;
39
+ export interface JsonRpcMessage {
40
+ jsonrpc: "2.0";
41
+ id?: string | number | null;
42
+ method?: string;
43
+ params?: unknown;
44
+ result?: unknown;
45
+ error?: {
46
+ code: number;
47
+ message: string;
48
+ };
49
+ }
50
+ export declare const TOOLS: readonly [{
51
+ readonly name: "kosha_query_models";
52
+ readonly description: "List AI models from the local kosha registry. Optionally filter by provider, mode, or capability tag. Returns id, provider, name, mode, context window, capabilities, and pricing.";
53
+ readonly inputSchema: {
54
+ readonly type: "object";
55
+ readonly properties: {
56
+ readonly provider: {
57
+ readonly type: "string";
58
+ readonly description: "Provider ID (e.g. anthropic, openai, groq, openrouter)";
59
+ };
60
+ readonly mode: {
61
+ readonly type: "string";
62
+ readonly enum: readonly ["chat", "embedding", "image", "video", "audio", "moderation", "rerank"];
63
+ readonly description: "Primary model mode";
64
+ };
65
+ readonly capability: {
66
+ readonly type: "string";
67
+ readonly description: "Capability tag (e.g. vision, tool_use, code, reasoning)";
68
+ };
69
+ readonly limit: {
70
+ readonly type: "number";
71
+ readonly description: "Max results to return (default 20)";
72
+ };
73
+ };
74
+ };
75
+ }, {
76
+ readonly name: "kosha_cheapest_model";
77
+ readonly description: "Find the cheapest AI model that meets your requirements. Returns ranked matches with per-million token pricing. Use this before routing a request to pick the most cost-effective option.";
78
+ readonly inputSchema: {
79
+ readonly type: "object";
80
+ readonly properties: {
81
+ readonly capability: {
82
+ readonly type: "string";
83
+ readonly description: "Required capability (e.g. tool_use, vision, code, reasoning)";
84
+ };
85
+ readonly min_context_k: {
86
+ readonly type: "number";
87
+ readonly description: "Minimum context window in thousands of tokens (e.g. 128 means 128k)";
88
+ };
89
+ readonly provider: {
90
+ readonly type: "string";
91
+ readonly description: "Pin to a specific provider";
92
+ };
93
+ readonly limit: {
94
+ readonly type: "number";
95
+ readonly description: "Number of ranked results (default 5)";
96
+ };
97
+ };
98
+ };
99
+ }, {
100
+ readonly name: "kosha_ranked_routes";
101
+ readonly description: "Rank chat-model routes by strategy: cheapest (price only), fastest (observed p95 latency), reliable (circuit-breaker state plus timeout / auth-error history), or balanced (weighted blend of all three). Providers whose breaker is open always sort last, so the result doubles as a failover order. Accepts the same filters as kosha_cheapest_model.";
102
+ readonly inputSchema: {
103
+ readonly type: "object";
104
+ readonly properties: {
105
+ readonly strategy: {
106
+ readonly type: "string";
107
+ readonly enum: readonly ["cheapest", "fastest", "reliable", "balanced"];
108
+ readonly description: "Ranking strategy";
109
+ };
110
+ readonly capability: {
111
+ readonly type: "string";
112
+ readonly description: "Required capability tag (e.g. tool_use, vision)";
113
+ };
114
+ readonly min_context_k: {
115
+ readonly type: "number";
116
+ readonly description: "Minimum context window in thousands of tokens";
117
+ };
118
+ readonly provider: {
119
+ readonly type: "string";
120
+ readonly description: "Pin to a specific provider";
121
+ };
122
+ readonly limit: {
123
+ readonly type: "number";
124
+ readonly description: "Number of ranked results (default 5)";
125
+ };
126
+ };
127
+ readonly required: readonly ["strategy"];
128
+ };
129
+ }, {
130
+ readonly name: "kosha_model_detail";
131
+ readonly description: "Get full details for a specific model — pricing, capabilities, context window, tool dialect, structured output modes, status, and deprecation info.";
132
+ readonly inputSchema: {
133
+ readonly type: "object";
134
+ readonly properties: {
135
+ readonly model: {
136
+ readonly type: "string";
137
+ readonly description: "Model ID or alias (e.g. sonnet, claude-sonnet-5, gpt-4o, deepseek-v3)";
138
+ };
139
+ };
140
+ readonly required: readonly ["model"];
141
+ };
142
+ }, {
143
+ readonly name: "kosha_model_routes";
144
+ readonly description: "List all serving-layer routes for a model (direct provider, OpenRouter, Bedrock, Vertex, etc.) with pricing per route. Useful for finding the cheapest or most available path to a specific model.";
145
+ readonly inputSchema: {
146
+ readonly type: "object";
147
+ readonly properties: {
148
+ readonly model: {
149
+ readonly type: "string";
150
+ readonly description: "Model ID or alias";
151
+ };
152
+ };
153
+ readonly required: readonly ["model"];
154
+ };
155
+ }, {
156
+ readonly name: "kosha_resolve_alias";
157
+ readonly description: "Resolve a model alias or short name to its canonical ID and provider.";
158
+ readonly inputSchema: {
159
+ readonly type: "object";
160
+ readonly properties: {
161
+ readonly alias: {
162
+ readonly type: "string";
163
+ readonly description: "Short name or alias (e.g. sonnet, opus, haiku, gpt-4o-mini, gemini-flash)";
164
+ };
165
+ };
166
+ readonly required: readonly ["alias"];
167
+ };
168
+ }, {
169
+ readonly name: "kosha_provider_health";
170
+ readonly description: "Get authentication and health status for all discovered providers. Shows which providers are active, which need credentials, and any recent discovery errors.";
171
+ readonly inputSchema: {
172
+ readonly type: "object";
173
+ readonly properties: {
174
+ readonly provider: {
175
+ readonly type: "string";
176
+ readonly description: "Filter to a specific provider ID";
177
+ };
178
+ };
179
+ };
180
+ }, {
181
+ readonly name: "kosha_context_strategy";
182
+ readonly description: "Advise on context management for a long-running conversation. Given a model and current token usage, returns ranked options (continue, enable prompt cache, compact + continue, switch to long-context tier, switch model, batch offload) with rough cost-per-turn math. Useful before deciding whether to summarize, swap models, or just keep going.";
183
+ readonly inputSchema: {
184
+ readonly type: "object";
185
+ readonly properties: {
186
+ readonly model: {
187
+ readonly type: "string";
188
+ readonly description: "Model ID or alias the caller is currently using";
189
+ };
190
+ readonly current_tokens: {
191
+ readonly type: "number";
192
+ readonly description: "Approximate token count of the conversation so far";
193
+ };
194
+ readonly expected_output_tokens: {
195
+ readonly type: "number";
196
+ readonly description: "Tokens the next reply is expected to produce (default 1024)";
197
+ };
198
+ readonly expected_remaining_turns: {
199
+ readonly type: "number";
200
+ readonly description: "How many more turns the caller plans (default 5)";
201
+ };
202
+ };
203
+ readonly required: readonly ["model", "current_tokens"];
204
+ };
205
+ }];
206
+ /** Dependencies the JSON-RPC handler needs; injected so tests can supply a fixture registry. */
207
+ export interface McpDeps {
208
+ registry: () => Promise<ModelRegistry>;
209
+ }
210
+ export declare function callTool(name: string, args: Record<string, unknown>, deps?: McpDeps): Promise<unknown>;
211
+ /**
212
+ * Handle one JSON-RPC request and return the response, or `null` for
213
+ * notifications (which carry no id and expect no reply).
214
+ *
215
+ * Tool *execution* failures come back as a successful `tools/call` result
216
+ * with `isError: true`, per the MCP spec, so the model can read the message
217
+ * and recover; only protocol-level problems (unknown method, unknown tool,
218
+ * malformed params) surface as JSON-RPC errors.
219
+ */
220
+ export declare function handleJsonRpc(msg: JsonRpcMessage, deps?: McpDeps): Promise<JsonRpcMessage | null>;
221
+ /** Start the newline-delimited JSON-RPC loop over stdio. */
222
+ export declare function runStdioServer(deps?: McpDeps): void;
18
223
  //# sourceMappingURL=mcp-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG"}
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAQ9C,qGAAqG;AACrG,eAAO,MAAM,iBAAiB,EAAE,MAO5B,CAAC;AAEL,mEAAmE;AACnE,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAA+C,CAAC;AAEnG;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAGnE;AAMD,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;I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