@hop-top/kit 0.5.0-alpha.3 → 0.5.0-alpha.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 (187) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +1 -1
  3. package/README.md +47 -575
  4. package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
  5. package/dist/aim.d.ts +1 -1
  6. package/dist/aim.js +13 -414
  7. package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
  8. package/dist/alias.d.ts +1 -1
  9. package/dist/alias.js +18 -206
  10. package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
  11. package/dist/api.d.ts +1 -1
  12. package/dist/api.js +10 -164
  13. package/dist/auth.js +6 -40
  14. package/dist/chunk-3FIKGFKI.js +54 -0
  15. package/dist/chunk-4UE5TCMQ.js +104 -0
  16. package/dist/chunk-6HFAEZ52.js +29 -0
  17. package/dist/chunk-6SVOHNIC.js +17 -0
  18. package/dist/chunk-72XZWQX7.js +504 -0
  19. package/dist/chunk-ABQSE7AI.js +513 -0
  20. package/dist/chunk-BDNNPRX6.js +41 -0
  21. package/dist/chunk-BRNEKPWX.js +37 -0
  22. package/dist/chunk-CSJWB6D3.js +151 -0
  23. package/dist/chunk-GGWJRWWA.js +309 -0
  24. package/dist/chunk-IQXEISMC.js +142 -0
  25. package/dist/chunk-JTMPNXVQ.js +1491 -0
  26. package/dist/chunk-KVG7YCTS.js +115 -0
  27. package/dist/chunk-L23O2FFE.js +51 -0
  28. package/dist/chunk-MQXYDYRD.js +968 -0
  29. package/dist/chunk-MUIQVU6E.js +251 -0
  30. package/dist/chunk-POR5L2DG.js +247 -0
  31. package/dist/chunk-PSFYJGDG.js +1445 -0
  32. package/dist/chunk-QJVSKKRQ.js +369 -0
  33. package/dist/chunk-QPUCXQXT.js +67 -0
  34. package/dist/chunk-R5U7XKVJ.js +16 -0
  35. package/dist/chunk-S45UHXQF.js +182 -0
  36. package/dist/chunk-T46YPHKN.js +669 -0
  37. package/dist/chunk-UIOOOK6M.js +334 -0
  38. package/dist/chunk-UKZIAQA7.js +26 -0
  39. package/dist/chunk-WBVO43HU.js +355 -0
  40. package/dist/chunk-WTYDHXPW.js +574 -0
  41. package/dist/chunk-WUOAQVOA.js +86 -0
  42. package/dist/chunk-WWUKGJB5.js +90 -0
  43. package/dist/chunk-YGYQUFGY.js +219 -0
  44. package/dist/chunk-YOBAUCVN.js +583 -0
  45. package/dist/{cli-DLygZLi9.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -4
  47. package/dist/cli.js +50 -1057
  48. package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
  49. package/dist/config.d.ts +1 -1
  50. package/dist/config.js +6 -78
  51. package/dist/errcorrect.js +8 -68
  52. package/dist/{error-DISJKeDu.d.ts → error-Do8Qji43.d.ts} +88 -1
  53. package/dist/id/index.d.ts +1 -1
  54. package/dist/id/index.js +14 -65
  55. package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
  56. package/dist/{index-Bc5c7Ty5.d.ts → index-DEyjGoo2.d.ts} +1 -1
  57. package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
  58. package/dist/index.d.ts +18 -15
  59. package/dist/index.js +39 -6722
  60. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  61. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  62. package/dist/llm-anthropic.d.ts +2 -0
  63. package/dist/llm-anthropic.js +13 -0
  64. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  65. package/dist/llm-openai.d.ts +2 -0
  66. package/dist/llm-openai.js +19 -0
  67. package/dist/llm.d.ts +1 -1
  68. package/dist/llm.js +101 -356
  69. package/dist/mcp/index.d.ts +2 -1
  70. package/dist/mcp/index.js +155 -1453
  71. package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
  72. package/dist/netpolicy.d.ts +1 -1
  73. package/dist/netpolicy.js +25 -118
  74. package/dist/{output-4aXs91GY.d.ts → output-CjZWmL8s.d.ts} +28 -4
  75. package/dist/output.d.ts +2 -2
  76. package/dist/output.js +137 -971
  77. package/dist/progress.js +6 -55
  78. package/dist/provenance.js +6 -31
  79. package/dist/routellm-B0nv59mH.d.ts +111 -0
  80. package/dist/routellm.d.ts +2 -2
  81. package/dist/routellm.js +13 -255
  82. package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
  83. package/dist/rpc.d.ts +2 -2
  84. package/dist/rpc.js +4 -98
  85. package/dist/safety.js +6 -43
  86. package/dist/scope.js +20 -377
  87. package/dist/{serve-DE-jscpb.d.ts → serve-D8yWMrTc.d.ts} +2 -2
  88. package/dist/serve.d.ts +2 -2
  89. package/dist/serve.js +75 -1019
  90. package/dist/sqlstore.js +6 -39
  91. package/dist/stream.js +8 -51
  92. package/dist/telemetry/index.js +24 -608
  93. package/dist/tui/index.d.ts +5 -5
  94. package/dist/tui/index.js +17 -374
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +130 -25
  98. package/src/README.md +15 -0
  99. package/src/cli.test.ts +56 -1
  100. package/src/cli.ts +24 -4
  101. package/src/completion-values.test.ts +10 -10
  102. package/src/compliance.test.ts +196 -2
  103. package/src/compliance.ts +440 -20
  104. package/src/config.test.ts +187 -1
  105. package/src/config.ts +173 -7
  106. package/src/gen/crud_pb.ts +7 -7
  107. package/src/id/README.md +38 -0
  108. package/src/id/contract.test.ts +1 -1
  109. package/src/id/index.test.ts +1 -1
  110. package/src/id/index.ts +3 -2
  111. package/src/index.test.ts +12 -0
  112. package/src/index.ts +2 -0
  113. package/src/llm-anthropic.conformance.test.ts +1135 -0
  114. package/src/llm-anthropic.test.ts +152 -0
  115. package/src/llm-anthropic.ts +940 -0
  116. package/src/llm-choice-hermetic.test.ts +335 -0
  117. package/src/llm-config.test.ts +232 -0
  118. package/src/llm-config.ts +106 -0
  119. package/src/llm-endpoint.ts +254 -0
  120. package/src/llm-error.ts +17 -0
  121. package/src/llm-errors.ts +152 -0
  122. package/src/llm-file.ts +126 -0
  123. package/src/llm-http.ts +317 -0
  124. package/src/llm-keys.ts +167 -0
  125. package/src/llm-media.conformance.test.ts +87 -0
  126. package/src/llm-media.test.ts +279 -0
  127. package/src/llm-media.ts +322 -0
  128. package/src/llm-openai.conformance.test.ts +407 -0
  129. package/src/llm-openai.test.ts +510 -0
  130. package/src/llm-openai.ts +708 -0
  131. package/src/llm-payload.ts +155 -0
  132. package/src/llm-quote.ts +46 -0
  133. package/src/llm-routellm.conformance.test.ts +44 -0
  134. package/src/llm-toolnames.conformance.test.ts +112 -0
  135. package/src/llm-toolnames.test.ts +132 -0
  136. package/src/llm-toolnames.ts +298 -0
  137. package/src/llm-uri.ts +99 -0
  138. package/src/llm.test.ts +43 -15
  139. package/src/llm.toolcall.test.ts +175 -0
  140. package/src/llm.ts +602 -190
  141. package/src/mcp/README.md +57 -0
  142. package/src/mcp/conformance.test.ts +24 -3
  143. package/src/mcp/dispatch.ts +4 -4
  144. package/src/mcp/identity.test.ts +166 -0
  145. package/src/mcp/identity.ts +72 -0
  146. package/src/mcp/index.ts +6 -0
  147. package/src/mcp/legacy.ts +21 -8
  148. package/src/mcp/mcp.test.ts +14 -4
  149. package/src/mcp/modern-confirm.ts +1 -1
  150. package/src/mcp/modern.ts +12 -11
  151. package/src/mcp/tasks.ts +1 -1
  152. package/src/mcp/types.ts +80 -8
  153. package/src/netpolicy.test.ts +78 -0
  154. package/src/netpolicy.ts +28 -3
  155. package/src/output/README.md +46 -0
  156. package/src/output/builtins.ts +5 -5
  157. package/src/output/error.ts +144 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +24 -1
  160. package/src/published-types.test.ts +115 -0
  161. package/src/routellm.test.ts +209 -28
  162. package/src/routellm.toolcall.test.ts +521 -0
  163. package/src/routellm.ts +213 -177
  164. package/src/router/README.md +44 -0
  165. package/src/router/server.test.ts +41 -0
  166. package/src/router/server.ts +11 -0
  167. package/src/safety.test.ts +19 -9
  168. package/src/scope-defaults.json +29 -29
  169. package/src/serve.ts +1 -1
  170. package/src/telemetry/README.md +48 -0
  171. package/src/telemetry/client.ts +5 -5
  172. package/src/toolspec.test.ts +2 -2
  173. package/src/triton/README.md +34 -0
  174. package/src/tui/README.md +42 -0
  175. package/src/wizard.test.ts +7 -7
  176. package/test/llm/conformance-helpers.ts +100 -0
  177. package/test/output/dispatch.test.ts +1 -2
  178. package/test/output/error.test.ts +33 -2
  179. package/test/output/smoke-capture.ts +2 -2
  180. package/test/output/smoke.test.ts +2 -2
  181. package/test/output/taxonomy-contract.test.ts +148 -0
  182. package/test/setup-env.ts +16 -0
  183. package/tsconfig.json +3 -1
  184. package/tsconfig.test.json +10 -0
  185. package/vitest.config.ts +9 -0
  186. package/dist/llm-B5XUWH8T.d.ts +0 -231
  187. package/dist/routellm-PGSt2D1y.d.ts +0 -75
@@ -0,0 +1,148 @@
1
+ // Cross-language exit-taxonomy contract loader.
2
+ //
3
+ // Loads contracts/exit-taxonomy-v1/taxonomy.json — generated from
4
+ // go/console/output/envelope, the single source of truth — and asserts
5
+ // this TS SDK's table agrees with it on every class, every exit number
6
+ // and every transience.
7
+ //
8
+ // A failure here means Go's taxonomy moved and this port did not follow.
9
+ // That is the exact drift this contract exists to catch: when Go gained
10
+ // CONSENT_REFUSED 7 and PREREQUISITE 70, all four SDK ports silently
11
+ // kept the old nine-class table for two releases, and
12
+ // transienceForCode returned 'unknown' where Go returned 'transient' —
13
+ // so four runtimes handed agents wrong retry guidance.
14
+ //
15
+ // Fix by adding the missing class here, not by editing the contract:
16
+ // the contract is regenerated from Go, never hand-edited.
17
+
18
+ import { existsSync, readFileSync } from 'node:fs';
19
+ import { dirname, resolve } from 'node:path';
20
+ import { fileURLToPath } from 'node:url';
21
+
22
+ import { describe, it, expect } from 'vitest';
23
+
24
+ import {
25
+ exitClasses,
26
+ exitCodeForClass,
27
+ transienceForCode,
28
+ } from '../../src/output/error';
29
+
30
+ interface TaxonomyClass {
31
+ readonly class: string;
32
+ readonly exit: number;
33
+ readonly transience: string;
34
+ }
35
+
36
+ interface BandSlot {
37
+ readonly exit: number;
38
+ readonly class: string;
39
+ readonly owner: string;
40
+ }
41
+
42
+ interface TaxonomyContract {
43
+ readonly version: string;
44
+ readonly source: string;
45
+ readonly transiences: ReadonlyArray<string>;
46
+ readonly classes: ReadonlyArray<TaxonomyClass>;
47
+ readonly extension_band: ReadonlyArray<BandSlot>;
48
+ }
49
+
50
+ // Walk up from this test file's directory until we hit a directory
51
+ // holding contracts/exit-taxonomy-v1/taxonomy.json. Robust against both
52
+ // `vitest run` (CWD = sdk/ts) and IDE-driven invocations whose CWD may
53
+ // vary.
54
+ function locateContract(): string {
55
+ const here = dirname(fileURLToPath(import.meta.url));
56
+ let dir = here;
57
+ for (let i = 0; i < 10; i++) {
58
+ const candidate = resolve(
59
+ dir,
60
+ 'contracts',
61
+ 'exit-taxonomy-v1',
62
+ 'taxonomy.json',
63
+ );
64
+ if (existsSync(candidate)) return candidate;
65
+ const parent = dirname(dir);
66
+ if (parent === dir) break;
67
+ dir = parent;
68
+ }
69
+ throw new Error(
70
+ `contracts/exit-taxonomy-v1/taxonomy.json: not found walking up from ${here}`,
71
+ );
72
+ }
73
+
74
+ const CONTRACT: TaxonomyContract = JSON.parse(
75
+ readFileSync(locateContract(), 'utf8'),
76
+ ) as TaxonomyContract;
77
+
78
+ // The slots envelope itself owns. The conformance-tree slots (66-69)
79
+ // are recorded in the contract so a new allocation cannot double-book a
80
+ // number, but no SDK port is expected to export them.
81
+ const ENVELOPE_OWNER = 'hop.top/kit/go/console/output/envelope';
82
+
83
+ describe('exit-taxonomy-v1 contract metadata', () => {
84
+ it('pins version and source', () => {
85
+ expect(CONTRACT.version).toBe('v1');
86
+ expect(CONTRACT.source).toBe(ENVELOPE_OWNER);
87
+ expect(CONTRACT.classes.length).toBeGreaterThan(0);
88
+ });
89
+ });
90
+
91
+ describe('exit-taxonomy-v1: this port matches the contract', () => {
92
+ // Membership in both directions. A port carrying an extra class Go
93
+ // does not define is as much a divergence as a port missing one: an
94
+ // adopter branching on it gets a number no other runtime produces.
95
+ it('declares exactly the contract classes, in contract order', () => {
96
+ expect(exitClasses()).toEqual(CONTRACT.classes.map((c) => c.class));
97
+ });
98
+
99
+ it.each(CONTRACT.classes.map((c) => [c.class, c] as const))(
100
+ '%s resolves to the contract exit and transience',
101
+ (_name, row) => {
102
+ expect(exitCodeForClass(row.class)).toBe(row.exit);
103
+ expect(transienceForCode(row.class)).toBe(row.transience);
104
+ },
105
+ );
106
+
107
+ // The transience vocabulary is itself a contract: an agent branching
108
+ // on a fourth string has no defined behavior.
109
+ it('answers only with the contract transience vocabulary', () => {
110
+ for (const row of CONTRACT.classes) {
111
+ expect(CONTRACT.transiences).toContain(transienceForCode(row.class));
112
+ }
113
+ });
114
+
115
+ // An unknown class must resolve to nothing rather than to a fallback
116
+ // number. A built-in fallback is what turns "kit added a class and
117
+ // this port never copied it" into an assertion against exit 1 that
118
+ // reads as a real failure rather than a stale table.
119
+ it('does not invent a code for an adopter-defined class', () => {
120
+ expect(exitCodeForClass('ADOPTER_SPECIFIC')).toBeUndefined();
121
+ expect(transienceForCode('ADOPTER_SPECIFIC')).toBe('unknown');
122
+ });
123
+ });
124
+
125
+ describe('exit-taxonomy-v1 extension band', () => {
126
+ it('exports every band slot envelope owns', () => {
127
+ const owned = CONTRACT.extension_band.filter(
128
+ (s) => s.owner === ENVELOPE_OWNER,
129
+ );
130
+ expect(owned.length).toBeGreaterThan(0);
131
+ for (const slot of owned) {
132
+ expect(exitCodeForClass(slot.class)).toBe(slot.exit);
133
+ }
134
+ });
135
+
136
+ // Slots owned elsewhere must NOT be claimed here. A port that
137
+ // exported LEAK_DETECTED would be minting a number the conformance
138
+ // tree owns, which is the collision the band record exists to stop.
139
+ it('leaves slots owned by other packages unclaimed', () => {
140
+ const foreign = CONTRACT.extension_band.filter(
141
+ (s) => s.owner !== ENVELOPE_OWNER,
142
+ );
143
+ expect(foreign.length).toBeGreaterThan(0);
144
+ for (const slot of foreign) {
145
+ expect(exitCodeForClass(slot.class)).toBeUndefined();
146
+ }
147
+ });
148
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Vitest setup: points XDG_CONFIG_HOME at an empty temp dir per test
3
+ * file, so a developer's own config (llm.yaml included) never reaches
4
+ * a test. A test that needs a config writes it there or sets its own.
5
+ *
6
+ * @internal
7
+ */
8
+
9
+ import { mkdtempSync, rmSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { afterAll } from "vitest";
13
+
14
+ const dir = mkdtempSync(join(tmpdir(), "kit-ts-xdg-"));
15
+ process.env["XDG_CONFIG_HOME"] = dir;
16
+ afterAll(() => rmSync(dir, { recursive: true, force: true }));
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
4
5
  "module": "CommonJS",
5
6
  "declaration": true,
6
7
  "outDir": "./dist",
@@ -8,5 +9,6 @@
8
9
  "esModuleInterop": true,
9
10
  "resolveJsonModule": true
10
11
  },
11
- "include": ["src"]
12
+ "include": ["src"],
13
+ "exclude": ["src/**/*.test.ts"]
12
14
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler"
7
+ },
8
+ "include": ["src", "test"],
9
+ "exclude": []
10
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ // Every test file starts with an empty XDG config home, so no
6
+ // developer's llm.yaml (or other config) reaches a test.
7
+ setupFiles: ["test/setup-env.ts"],
8
+ },
9
+ });
@@ -1,231 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * LLM client facade — mirrors Go `llm` package interfaces as TS types.
5
- *
6
- * Provides URI parsing, config loading, provider registry, Client facade
7
- * with fallback, and typed errors. Adapter implementations (OpenAI,
8
- * Anthropic, Ollama) are deferred; register them via {@link register}.
9
- *
10
- * @example
11
- * ```ts
12
- * import { createLLM, register } from '@hop-top/kit/llm';
13
- *
14
- * register('mock', (cfg) => ({ complete: async (r) => ({ content: 'hi', role: 'assistant' }), close() {} }));
15
- * const client = createLLM('mock://model-1');
16
- * const resp = await client.complete({ messages: [{ role: 'user', content: 'hello' }] });
17
- * ```
18
- */
19
- interface Message {
20
- role: string;
21
- content: string;
22
- }
23
- interface Request {
24
- messages: Message[];
25
- model?: string;
26
- temperature?: number;
27
- maxTokens?: number;
28
- stopSequences?: string[];
29
- extensions?: Record<string, unknown>;
30
- }
31
- interface Response {
32
- content: string;
33
- role: string;
34
- usage?: Usage;
35
- finishReason?: string;
36
- }
37
- interface Usage {
38
- promptTokens: number;
39
- completionTokens: number;
40
- totalTokens: number;
41
- }
42
- interface Token {
43
- content: string;
44
- done: boolean;
45
- }
46
- interface ToolDef {
47
- name: string;
48
- description: string;
49
- parameters: unknown;
50
- }
51
- interface ToolCall {
52
- id: string;
53
- name: string;
54
- arguments: unknown;
55
- }
56
- interface ToolResponse {
57
- content: string;
58
- toolCalls: ToolCall[];
59
- }
60
- interface Completer {
61
- complete(req: Request): Promise<Response>;
62
- }
63
- interface Streamer {
64
- stream(req: Request): AsyncIterable<Token>;
65
- }
66
- interface ToolCaller {
67
- callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse>;
68
- }
69
- interface Provider extends Partial<Completer & Streamer & ToolCaller> {
70
- close(): void;
71
- }
72
- interface URI {
73
- scheme: string;
74
- model: string;
75
- host?: string;
76
- params?: Record<string, string>;
77
- }
78
- interface ProviderConfig {
79
- apiKey?: string;
80
- baseURL?: string;
81
- model: string;
82
- params?: Record<string, string>;
83
- extras?: Record<string, unknown>;
84
- }
85
- interface ResolvedConfig {
86
- uri: URI;
87
- provider: ProviderConfig;
88
- fallbacks: string[];
89
- }
90
- declare class LLMError extends Error {
91
- statusCode?: number;
92
- code?: string;
93
- constructor(message: string);
94
- }
95
- declare class ProviderNotFoundError extends LLMError {
96
- scheme: string;
97
- constructor(scheme: string);
98
- }
99
- declare class CapabilityNotSupportedError extends LLMError {
100
- capability: string;
101
- provider: string;
102
- constructor(capability: string, provider: string);
103
- }
104
- declare class AuthError extends LLMError {
105
- provider: string;
106
- constructor(provider: string);
107
- }
108
- declare class RateLimitError extends LLMError {
109
- provider: string;
110
- retryAfter?: number;
111
- constructor(provider: string, retryAfter?: number);
112
- }
113
- declare class ModelError extends LLMError {
114
- model: string;
115
- provider: string;
116
- constructor(model: string, provider: string);
117
- }
118
- declare class FallbackExhaustedError extends LLMError {
119
- errors: Error[];
120
- constructor(errors: Error[]);
121
- }
122
- /**
123
- * Returns true when `err` should trigger a fallback attempt.
124
- *
125
- * Fallbackable conditions:
126
- * - LLMError with statusCode >= 500
127
- * - RateLimitError (429)
128
- * - Connection/timeout errors (ECONNREFUSED, ETIMEDOUT, ECONNRESET)
129
- */
130
- declare function isFallbackable(err: Error): boolean;
131
- /**
132
- * Parses an LLM URI string into its components.
133
- *
134
- * Format: `scheme://[host[:port]/]model[?params]`
135
- *
136
- * When the path portion contains a host:port prefix (detected by the
137
- * presence of a numeric port), the first segment is treated as host.
138
- * Otherwise the entire path is the model name.
139
- */
140
- declare function parseURI(raw: string): URI;
141
- /**
142
- * Builds a {@link ResolvedConfig} from a URI string + env vars.
143
- *
144
- * When `uriStr` is empty/undefined, falls back to `LLM_PROVIDER`
145
- * env var as a full default URI. If neither is provided, throws.
146
- *
147
- * URI query params `api_key` and `base_url` populate provider
148
- * config. If `uri.host` is set, it derives a baseURL. Env vars
149
- * `LLM_API_KEY` and `LLM_BASE_URL` override last.
150
- *
151
- * Env vars:
152
- * - `LLM_PROVIDER` — full default URI when no arg provided
153
- * - `LLM_API_KEY` — overrides provider API key
154
- * - `LLM_BASE_URL` — overrides provider base URL
155
- * - `LLM_FALLBACK` — comma-separated fallback URIs
156
- */
157
- declare function loadConfig(uriStr?: string): ResolvedConfig;
158
- type Factory = (cfg: ResolvedConfig) => Provider;
159
- /** Register a provider factory for the given URI scheme. */
160
- declare function register(scheme: string, factory: Factory): void;
161
- /** Resolve a URI to a Provider instance via the registry. */
162
- declare function resolve(uriStr: string): Provider;
163
- /** Clear the registry (for tests). */
164
- declare function clearRegistry(): void;
165
- interface ClientOptions {
166
- fallback?: string[];
167
- onRequest?: (req: Request) => void;
168
- onResponse?: (resp: Response, durationMs: number) => void;
169
- onError?: (err: Error) => void;
170
- onFallback?: (from: number, to: number, err: Error) => void;
171
- }
172
- interface Client {
173
- complete(req: Request): Promise<Response>;
174
- stream(req: Request): AsyncIterable<Token>;
175
- callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse>;
176
- capabilities(): string[];
177
- provider(): Provider;
178
- close(): void;
179
- }
180
- /**
181
- * Create an LLM client with fallback support and event hooks.
182
- *
183
- * The returned Client delegates to the provider resolved from `uri`.
184
- * On fallbackable errors, it tries each fallback URI in order.
185
- */
186
- declare function createLLM(uri: string, opts?: ClientOptions): Client;
187
-
188
- type llm_AuthError = AuthError;
189
- declare const llm_AuthError: typeof AuthError;
190
- type llm_CapabilityNotSupportedError = CapabilityNotSupportedError;
191
- declare const llm_CapabilityNotSupportedError: typeof CapabilityNotSupportedError;
192
- type llm_Client = Client;
193
- type llm_ClientOptions = ClientOptions;
194
- type llm_Completer = Completer;
195
- type llm_Factory = Factory;
196
- type llm_FallbackExhaustedError = FallbackExhaustedError;
197
- declare const llm_FallbackExhaustedError: typeof FallbackExhaustedError;
198
- type llm_LLMError = LLMError;
199
- declare const llm_LLMError: typeof LLMError;
200
- type llm_Message = Message;
201
- type llm_ModelError = ModelError;
202
- declare const llm_ModelError: typeof ModelError;
203
- type llm_Provider = Provider;
204
- type llm_ProviderConfig = ProviderConfig;
205
- type llm_ProviderNotFoundError = ProviderNotFoundError;
206
- declare const llm_ProviderNotFoundError: typeof ProviderNotFoundError;
207
- type llm_RateLimitError = RateLimitError;
208
- declare const llm_RateLimitError: typeof RateLimitError;
209
- type llm_Request = Request;
210
- type llm_ResolvedConfig = ResolvedConfig;
211
- type llm_Response = Response;
212
- type llm_Streamer = Streamer;
213
- type llm_Token = Token;
214
- type llm_ToolCall = ToolCall;
215
- type llm_ToolCaller = ToolCaller;
216
- type llm_ToolDef = ToolDef;
217
- type llm_ToolResponse = ToolResponse;
218
- type llm_URI = URI;
219
- type llm_Usage = Usage;
220
- declare const llm_clearRegistry: typeof clearRegistry;
221
- declare const llm_createLLM: typeof createLLM;
222
- declare const llm_isFallbackable: typeof isFallbackable;
223
- declare const llm_loadConfig: typeof loadConfig;
224
- declare const llm_parseURI: typeof parseURI;
225
- declare const llm_register: typeof register;
226
- declare const llm_resolve: typeof resolve;
227
- declare namespace llm {
228
- export { llm_AuthError as AuthError, llm_CapabilityNotSupportedError as CapabilityNotSupportedError, type llm_Client as Client, type llm_ClientOptions as ClientOptions, type llm_Completer as Completer, type llm_Factory as Factory, llm_FallbackExhaustedError as FallbackExhaustedError, llm_LLMError as LLMError, type llm_Message as Message, llm_ModelError as ModelError, type llm_Provider as Provider, type llm_ProviderConfig as ProviderConfig, llm_ProviderNotFoundError as ProviderNotFoundError, llm_RateLimitError as RateLimitError, type llm_Request as Request, type llm_ResolvedConfig as ResolvedConfig, type llm_Response as Response, type llm_Streamer as Streamer, type llm_Token as Token, type llm_ToolCall as ToolCall, type llm_ToolCaller as ToolCaller, type llm_ToolDef as ToolDef, type llm_ToolResponse as ToolResponse, type llm_URI as URI, type llm_Usage as Usage, llm_clearRegistry as clearRegistry, llm_createLLM as createLLM, llm_isFallbackable as isFallbackable, llm_loadConfig as loadConfig, llm_parseURI as parseURI, llm_register as register, llm_resolve as resolve };
229
- }
230
-
231
- export { AuthError as A, CapabilityNotSupportedError as C, type Factory as F, LLMError as L, type Message as M, type Provider as P, RateLimitError as R, type Streamer as S, type Token as T, type URI as U, type Client as a, type ClientOptions as b, type Completer as c, FallbackExhaustedError as d, ModelError as e, type ProviderConfig as f, ProviderNotFoundError as g, type Request as h, type ResolvedConfig as i, type Response as j, type ToolCall as k, type ToolCaller as l, type ToolDef as m, type ToolResponse as n, type Usage as o, clearRegistry as p, createLLM as q, isFallbackable as r, llm as s, loadConfig as t, parseURI as u, register as v, resolve as w };
@@ -1,75 +0,0 @@
1
- import { c as Completer, S as Streamer, i as ResolvedConfig, h as Request, j as Response, T as Token } from './llm-B5XUWH8T.js';
2
-
3
- /**
4
- * @packageDocumentation
5
- *
6
- * RouteLLM adapter — registers the `routellm` URI scheme.
7
- *
8
- * URI format: `routellm://router_name:threshold` (e.g. `routellm://mf:0.7`).
9
- *
10
- * Delegates HTTP completions to an OpenAI-compatible endpoint on the
11
- * RouteLLM server, translating the model field into the server's
12
- * expected `router-[name]-[threshold]` format.
13
- */
14
-
15
- interface EvaConfig {
16
- contracts: string[];
17
- enforce: boolean;
18
- }
19
- interface RouterConfig {
20
- baseUrl: string;
21
- grpcPort: number;
22
- strongModel: string;
23
- weakModel: string;
24
- routers: string[];
25
- routerConfig: Record<string, unknown>;
26
- eva: EvaConfig;
27
- autostart: boolean;
28
- }
29
- /**
30
- * Extract and validate RouteLLM configuration from provider extras.
31
- * Environment variables override all other sources.
32
- */
33
- declare function parseRouterConfig(extras?: Record<string, unknown>): RouterConfig;
34
- interface ParsedModel {
35
- routerName: string;
36
- threshold: number;
37
- }
38
- /**
39
- * Split a model string of the form `router_name:threshold` into its
40
- * components.
41
- */
42
- declare function parseModelField(model: string): ParsedModel;
43
- /**
44
- * RouteLLM adapter implementing Completer and Streamer.
45
- *
46
- * Delegates to an OpenAI-compatible HTTP endpoint on the RouteLLM
47
- * server using the standard fetch API.
48
- */
49
- declare class RouteLLMAdapter implements Completer, Streamer {
50
- readonly config: RouterConfig;
51
- readonly routerName: string;
52
- readonly threshold: number;
53
- private readonly _baseUrl;
54
- private readonly _serverModel;
55
- private readonly _apiKey;
56
- constructor(cfg: ResolvedConfig);
57
- complete(req: Request): Promise<Response>;
58
- stream(req: Request): AsyncGenerator<Token>;
59
- close(): void;
60
- private _buildBody;
61
- private _post;
62
- }
63
-
64
- type routellm_EvaConfig = EvaConfig;
65
- type routellm_ParsedModel = ParsedModel;
66
- type routellm_RouteLLMAdapter = RouteLLMAdapter;
67
- declare const routellm_RouteLLMAdapter: typeof RouteLLMAdapter;
68
- type routellm_RouterConfig = RouterConfig;
69
- declare const routellm_parseModelField: typeof parseModelField;
70
- declare const routellm_parseRouterConfig: typeof parseRouterConfig;
71
- declare namespace routellm {
72
- export { type routellm_EvaConfig as EvaConfig, type routellm_ParsedModel as ParsedModel, routellm_RouteLLMAdapter as RouteLLMAdapter, type routellm_RouterConfig as RouterConfig, routellm_parseModelField as parseModelField, routellm_parseRouterConfig as parseRouterConfig };
73
- }
74
-
75
- export { type EvaConfig as E, type ParsedModel as P, RouteLLMAdapter as R, type RouterConfig as a, parseRouterConfig as b, parseModelField as p, routellm as r };