@hop-top/kit 0.5.0-alpha.2 → 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 (188) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +1 -1
  3. package/README.md +48 -480
  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-DgOEOsPB.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -3
  47. package/dist/cli.js +50 -1056
  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-Do8Qji43.d.ts +231 -0
  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--C7Mtsmm.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 -13
  59. package/dist/index.js +40 -5792
  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-VFFLqor9.d.ts → output-CjZWmL8s.d.ts} +29 -130
  75. package/dist/output.d.ts +2 -1
  76. package/dist/output.js +137 -958
  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-D8yWMrTc.d.ts +646 -0
  88. package/dist/serve.d.ts +3 -0
  89. package/dist/serve.js +75 -0
  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 -4
  94. package/dist/tui/index.js +17 -373
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +135 -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 +3 -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 +167 -1
  158. package/src/output/formatters/README.md +50 -0
  159. package/src/output.ts +26 -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.test.ts +1257 -0
  170. package/src/serve.ts +1665 -0
  171. package/src/telemetry/README.md +48 -0
  172. package/src/telemetry/client.ts +5 -5
  173. package/src/toolspec.test.ts +2 -2
  174. package/src/triton/README.md +34 -0
  175. package/src/tui/README.md +42 -0
  176. package/src/wizard.test.ts +7 -7
  177. package/test/llm/conformance-helpers.ts +100 -0
  178. package/test/output/dispatch.test.ts +1 -2
  179. package/test/output/error.test.ts +38 -2
  180. package/test/output/smoke-capture.ts +2 -2
  181. package/test/output/smoke.test.ts +2 -2
  182. package/test/output/taxonomy-contract.test.ts +148 -0
  183. package/test/setup-env.ts +16 -0
  184. package/tsconfig.json +3 -1
  185. package/tsconfig.test.json +10 -0
  186. package/vitest.config.ts +9 -0
  187. package/dist/llm-B5XUWH8T.d.ts +0 -231
  188. package/dist/routellm-PGSt2D1y.d.ts +0 -75
@@ -0,0 +1,67 @@
1
+ import { C as Completer, S as Streamer, T as ToolCaller, a as ToolStreamer, R as ResolvedConfig, b as Request, c as Response, d as ToolDef, e as ToolResponse, f as ToolStream } from './llm-DYuR7_uX.js';
2
+
3
+ /**
4
+ * @packageDocumentation
5
+ *
6
+ * Anthropic Messages API adapter — registers the `anthropic` URI scheme
7
+ * on import. Implements complete, stream, callWithTools and
8
+ * streamWithTools, with extended thinking and prompt caching.
9
+ *
10
+ * URI: `anthropic://<model>[?params]`. Params: `tool_names`
11
+ * (`sanitize` | `strict`), `max_body_bytes`, `max_event_bytes`. The key
12
+ * resolves as `loadConfig` resolves it (the URI's `api_key`, llm.yaml,
13
+ * `ANTHROPIC_API_KEY`, then `LLM_API_KEY`);
14
+ * `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and
15
+ * `ANTHROPIC_WORKSPACE_ID` are read from the environment. The token and
16
+ * workspace header go only to a trusted origin (the default endpoint,
17
+ * `ANTHROPIC_BASE_URL`, llm.yaml `base_url`, `LLM_BASE_URL`, loopback);
18
+ * no credential goes over plain http to a remote host. A hermetic config
19
+ * ({@link ResolvedConfig.hermetic}) reads none of these variables.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import "@hop-top/kit/anthropic";
24
+ * import { createLLM } from "@hop-top/kit/llm";
25
+ *
26
+ * const llm = createLLM("anthropic://claude-sonnet-4-5");
27
+ * const r = await llm.complete({ messages: [{ role: "user", content: "Hi" }] });
28
+ * ```
29
+ */
30
+
31
+ /** The Messages API's default endpoint. */
32
+ declare const ANTHROPIC_DEFAULT_BASE_URL = "https://api.anthropic.com";
33
+ /**
34
+ * Anthropic Messages API adapter over fetch. Construct it directly with
35
+ * a resolved config, or import the module and resolve an `anthropic://`
36
+ * URI.
37
+ */
38
+ declare class AnthropicAdapter implements Completer, Streamer, ToolCaller, ToolStreamer {
39
+ readonly model: string;
40
+ readonly baseURL: string;
41
+ private readonly headers;
42
+ private readonly secrets;
43
+ private readonly limits;
44
+ private readonly toolNames;
45
+ constructor(cfg: ResolvedConfig);
46
+ close(): void;
47
+ complete(req: Request): Promise<Response>;
48
+ callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse>;
49
+ stream(req: Request): ToolStream;
50
+ streamWithTools(req: Request, tools: ToolDef[]): ToolStream;
51
+ private toolNameMap;
52
+ private transport;
53
+ private send;
54
+ private url;
55
+ private openStream;
56
+ private run;
57
+ private buildBody;
58
+ }
59
+
60
+ declare const llmAnthropic_ANTHROPIC_DEFAULT_BASE_URL: typeof ANTHROPIC_DEFAULT_BASE_URL;
61
+ type llmAnthropic_AnthropicAdapter = AnthropicAdapter;
62
+ declare const llmAnthropic_AnthropicAdapter: typeof AnthropicAdapter;
63
+ declare namespace llmAnthropic {
64
+ export { llmAnthropic_ANTHROPIC_DEFAULT_BASE_URL as ANTHROPIC_DEFAULT_BASE_URL, llmAnthropic_AnthropicAdapter as AnthropicAdapter };
65
+ }
66
+
67
+ export { ANTHROPIC_DEFAULT_BASE_URL as A, AnthropicAdapter as a, llmAnthropic as l };
@@ -0,0 +1,2 @@
1
+ import './llm-DYuR7_uX.js';
2
+ export { A as ANTHROPIC_DEFAULT_BASE_URL, a as AnthropicAdapter } from './llm-anthropic-Cd_I2xXB.js';
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkT46YPHKNjs = require('./chunk-T46YPHKN.js');
5
+ require('./chunk-YGYQUFGY.js');
6
+ require('./chunk-PSFYJGDG.js');
7
+ require('./chunk-4UE5TCMQ.js');
8
+ require('./chunk-KVG7YCTS.js');
9
+ require('./chunk-R5U7XKVJ.js');
10
+
11
+
12
+
13
+ exports.ANTHROPIC_DEFAULT_BASE_URL = _chunkT46YPHKNjs.ANTHROPIC_DEFAULT_BASE_URL; exports.AnthropicAdapter = _chunkT46YPHKNjs.AnthropicAdapter;
@@ -0,0 +1,87 @@
1
+ import { C as Completer, S as Streamer, T as ToolCaller, a as ToolStreamer, R as ResolvedConfig, b as Request, c as Response, d as ToolDef, e as ToolResponse, f as ToolStream } from './llm-DYuR7_uX.js';
2
+
3
+ /**
4
+ * @packageDocumentation
5
+ *
6
+ * OpenAI Chat Completions adapter — registers, on import, the schemes
7
+ * `openai`, `openrouter`, `xai`, `lmstudio`, `groq`, `together`,
8
+ * `fireworks`, `deepseek` and `mistral`. Implements complete, stream,
9
+ * callWithTools and streamWithTools.
10
+ *
11
+ * URI: `openai://<model>[?params]`; a host form
12
+ * (`openai://host:port/model`) names a self-hosted OpenAI-compatible
13
+ * server, reached at `http://host:port/v1`; a `base_url` param is used
14
+ * as given. `lmstudio` defaults to `http://localhost:1234/v1` and
15
+ * appends `/v1` to any base URL that lacks it. Params: `tool_names`
16
+ * (`sanitize` | `strict`), `max_body_bytes`, `max_event_bytes`. The key
17
+ * resolves as `loadConfig` resolves it (the URI's `api_key`, llm.yaml,
18
+ * `<SCHEME>_API_KEY`, then `LLM_API_KEY`; `lmstudio` sends none unless
19
+ * the URI or llm.yaml gives one); a blank key sends no
20
+ * Authorization header.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import "@hop-top/kit/openai";
25
+ * import { createLLM } from "@hop-top/kit/llm";
26
+ *
27
+ * const llm = createLLM("openai://gpt-4.1-mini");
28
+ * ```
29
+ */
30
+
31
+ /** Schemes this adapter registers. */
32
+ declare const OPENAI_SCHEMES: readonly ["openai", "openrouter", "xai", "lmstudio", "groq", "together", "fireworks", "deepseek", "mistral"];
33
+ /** OpenAI's API root; schemes without a default below use it. */
34
+ declare const OPENAI_DEFAULT_BASE_URL = "https://api.openai.com/v1";
35
+ /** Each scheme's default API root. */
36
+ declare const OPENAI_BASE_URLS: Readonly<Record<string, string>>;
37
+ /** Options for adapters that speak the OpenAI wire on their own scheme. */
38
+ interface OpenAIAdapterOptions {
39
+ /** Prefix of error messages; defaults to the URI scheme. */
40
+ label?: string;
41
+ }
42
+ /**
43
+ * OpenAI Chat Completions adapter over fetch, for OpenAI and any
44
+ * compatible server.
45
+ */
46
+ declare class OpenAIAdapter implements Completer, Streamer, ToolCaller, ToolStreamer {
47
+ readonly model: string;
48
+ readonly baseURL: string;
49
+ readonly scheme: string;
50
+ private readonly label;
51
+ private readonly headers;
52
+ private readonly secrets;
53
+ private readonly limits;
54
+ private readonly toolNames;
55
+ constructor(cfg: ResolvedConfig, opts?: OpenAIAdapterOptions);
56
+ close(): void;
57
+ complete(req: Request): Promise<Response>;
58
+ callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse>;
59
+ stream(req: Request): ToolStream;
60
+ streamWithTools(req: Request, tools: ToolDef[]): ToolStream;
61
+ private toolNameMap;
62
+ private url;
63
+ private transport;
64
+ private send;
65
+ private openStream;
66
+ private run;
67
+ /**
68
+ * Maps `req`; `tools` are the call's tools, which `req.toolChoice` is
69
+ * checked against (none for a call without tools).
70
+ */
71
+ private buildBody;
72
+ }
73
+ /** `base` ending in `/v1`; one already ending in `/v1` is kept. */
74
+ declare function apiRootV1(base: string): string;
75
+
76
+ declare const llmOpenai_OPENAI_BASE_URLS: typeof OPENAI_BASE_URLS;
77
+ declare const llmOpenai_OPENAI_DEFAULT_BASE_URL: typeof OPENAI_DEFAULT_BASE_URL;
78
+ declare const llmOpenai_OPENAI_SCHEMES: typeof OPENAI_SCHEMES;
79
+ type llmOpenai_OpenAIAdapter = OpenAIAdapter;
80
+ declare const llmOpenai_OpenAIAdapter: typeof OpenAIAdapter;
81
+ type llmOpenai_OpenAIAdapterOptions = OpenAIAdapterOptions;
82
+ declare const llmOpenai_apiRootV1: typeof apiRootV1;
83
+ declare namespace llmOpenai {
84
+ export { llmOpenai_OPENAI_BASE_URLS as OPENAI_BASE_URLS, llmOpenai_OPENAI_DEFAULT_BASE_URL as OPENAI_DEFAULT_BASE_URL, llmOpenai_OPENAI_SCHEMES as OPENAI_SCHEMES, llmOpenai_OpenAIAdapter as OpenAIAdapter, type llmOpenai_OpenAIAdapterOptions as OpenAIAdapterOptions, llmOpenai_apiRootV1 as apiRootV1 };
85
+ }
86
+
87
+ export { OPENAI_BASE_URLS as O, OPENAI_DEFAULT_BASE_URL as a, OPENAI_SCHEMES as b, OpenAIAdapter as c, type OpenAIAdapterOptions as d, apiRootV1 as e, llmOpenai as l };
@@ -0,0 +1,2 @@
1
+ import './llm-DYuR7_uX.js';
2
+ export { O as OPENAI_BASE_URLS, a as OPENAI_DEFAULT_BASE_URL, b as OPENAI_SCHEMES, c as OpenAIAdapter, d as OpenAIAdapterOptions, e as apiRootV1 } from './llm-openai-DyFrucmV.js';
@@ -0,0 +1,19 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+ var _chunkABQSE7AIjs = require('./chunk-ABQSE7AI.js');
8
+ require('./chunk-YGYQUFGY.js');
9
+ require('./chunk-PSFYJGDG.js');
10
+ require('./chunk-4UE5TCMQ.js');
11
+ require('./chunk-KVG7YCTS.js');
12
+ require('./chunk-R5U7XKVJ.js');
13
+
14
+
15
+
16
+
17
+
18
+
19
+ exports.OPENAI_BASE_URLS = _chunkABQSE7AIjs.OPENAI_BASE_URLS; exports.OPENAI_DEFAULT_BASE_URL = _chunkABQSE7AIjs.OPENAI_DEFAULT_BASE_URL; exports.OPENAI_SCHEMES = _chunkABQSE7AIjs.OPENAI_SCHEMES; exports.OpenAIAdapter = _chunkABQSE7AIjs.OpenAIAdapter; exports.apiRootV1 = _chunkABQSE7AIjs.apiRootV1;
package/dist/llm.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as AuthError, C as CapabilityNotSupportedError, a as Client, b as ClientOptions, c as Completer, F as Factory, d as FallbackExhaustedError, L as LLMError, M as Message, e as ModelError, P as Provider, f as ProviderConfig, g as ProviderNotFoundError, R as RateLimitError, h as Request, i as ResolvedConfig, j as Response, S as Streamer, T as Token, k as ToolCall, l as ToolCaller, m as ToolDef, n as ToolResponse, U as URI, o as Usage, p as clearRegistry, q as createLLM, r as isFallbackable, t as loadConfig, u as parseURI, v as register, w as resolve } from './llm-B5XUWH8T.js';
1
+ export { A as ANTHROPIC_TOOL_NAMES, g as APIError, h as AuthError, i as CacheControl, j as CallOp, k as CapabilityNotSupportedError, m as Client, n as ClientOptions, C as Completer, o as ContentPart, D as DEFAULT_MAX_MEDIA_BYTES, p as Declaration, F as Factory, q as FallbackExhaustedError, G as GEMINI_TOOL_NAMES, H as HTTPStatusError, K as KeyEndpointError, L as LLMError, r as LoadOptions, M as MediaSource, s as MediaTooLargeError, t as MediaURLRefusedError, u as Message, v as MissingKeyError, w as ModelError, O as OPENAI_TOOL_NAMES, P as PartType, x as PermissionDeniedError, y as Price, z as Provider, B as ProviderConfig, E as ProviderKey, I as ProviderNotFoundError, J as RateLimitError, b as Request, N as RequestStartedPayload, R as ResolvedConfig, c as Response, Q as ResponseReceivedPayload, U as ResponseTooLargeError, V as StreamOutcome, W as StreamTruncatedError, S as Streamer, X as TOOL_NAMES_PARAM, Y as ThinkingBlock, Z as ThinkingConfig, _ as Token, $ as ToolCall, a0 as ToolCallEvent, a1 as ToolCallEventKind, T as ToolCaller, a2 as ToolChoice, a3 as ToolChoiceMode, d as ToolDef, a4 as ToolNameError, a5 as ToolNameMode, a6 as ToolNameReason, a7 as ToolNameRule, a8 as ToolNames, e as ToolResponse, f as ToolStream, a as ToolStreamer, a9 as URI, aa as URLSourceOptions, ab as Usage, ac as applyAPIKey, ad as checkKeyEndpoint, ae as checkToolChoice, af as checkToolLinkage, ag as clearRegistry, ah as createLLM, ai as credentialsTrusted, aj as declarationOf, ak as fileSource, al as inlineSource, am as isFallbackable, an as isPublicAddress, ao as isValidToolName, ap as loadConfig, aq as parseURI, ar as redactURI, as as register, at as requestStartedPayload, au as resolve, av as responseReceivedPayload, aw as sanitizeToolName, ax as toolNameModeOf, ay as urlSource, az as usageCost } from './llm-DYuR7_uX.js';
package/dist/llm.js CHANGED
@@ -1,356 +1,101 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/llm.ts
21
- var llm_exports = {};
22
- __export(llm_exports, {
23
- AuthError: () => AuthError,
24
- CapabilityNotSupportedError: () => CapabilityNotSupportedError,
25
- FallbackExhaustedError: () => FallbackExhaustedError,
26
- LLMError: () => LLMError,
27
- ModelError: () => ModelError,
28
- ProviderNotFoundError: () => ProviderNotFoundError,
29
- RateLimitError: () => RateLimitError,
30
- clearRegistry: () => clearRegistry,
31
- createLLM: () => createLLM,
32
- isFallbackable: () => isFallbackable,
33
- loadConfig: () => loadConfig,
34
- parseURI: () => parseURI,
35
- register: () => register,
36
- resolve: () => resolve
37
- });
38
- module.exports = __toCommonJS(llm_exports);
39
- var LLMError = class extends Error {
40
- constructor(message) {
41
- super(message);
42
- this.name = "LLMError";
43
- Object.setPrototypeOf(this, new.target.prototype);
44
- }
45
- };
46
- var ProviderNotFoundError = class extends LLMError {
47
- constructor(scheme) {
48
- super(`provider not found: ${scheme}`);
49
- this.name = "ProviderNotFoundError";
50
- this.scheme = scheme;
51
- }
52
- };
53
- var CapabilityNotSupportedError = class extends LLMError {
54
- constructor(capability, provider) {
55
- super(
56
- `capability "${capability}" not supported by provider "${provider}"`
57
- );
58
- this.name = "CapabilityNotSupportedError";
59
- this.capability = capability;
60
- this.provider = provider;
61
- }
62
- };
63
- var AuthError = class extends LLMError {
64
- constructor(provider) {
65
- super(`authentication failed for provider: ${provider}`);
66
- this.name = "AuthError";
67
- this.provider = provider;
68
- }
69
- };
70
- var RateLimitError = class extends LLMError {
71
- constructor(provider, retryAfter) {
72
- super(`rate limit exceeded for provider: ${provider}`);
73
- this.name = "RateLimitError";
74
- this.provider = provider;
75
- this.retryAfter = retryAfter;
76
- this.statusCode = 429;
77
- }
78
- };
79
- var ModelError = class extends LLMError {
80
- constructor(model, provider) {
81
- super(`model "${model}" not available on provider "${provider}"`);
82
- this.name = "ModelError";
83
- this.model = model;
84
- this.provider = provider;
85
- }
86
- };
87
- var FallbackExhaustedError = class extends LLMError {
88
- constructor(errors) {
89
- super(
90
- `all providers exhausted (${errors.length} failures)`
91
- );
92
- this.name = "FallbackExhaustedError";
93
- this.errors = errors;
94
- }
95
- };
96
- function isFallbackable(err) {
97
- if (err instanceof RateLimitError) return true;
98
- if (err instanceof LLMError) {
99
- if (err.code && isConnectionError(err.code)) return true;
100
- if (err.statusCode !== void 0 && err.statusCode >= 500) return true;
101
- return false;
102
- }
103
- const code = err.code;
104
- if (code && isConnectionError(code)) return true;
105
- return false;
106
- }
107
- var CONNECTION_CODES = /* @__PURE__ */ new Set([
108
- "ECONNREFUSED",
109
- "ETIMEDOUT",
110
- "ECONNRESET",
111
- "ENETUNREACH",
112
- "EHOSTUNREACH"
113
- ]);
114
- function isConnectionError(code) {
115
- return CONNECTION_CODES.has(code);
116
- }
117
- function parseURI(raw) {
118
- const sep = "://";
119
- const idx = raw.indexOf(sep);
120
- if (idx < 0) {
121
- throw new LLMError(`invalid LLM URI (missing "://"): ${raw}`);
122
- }
123
- const scheme = raw.slice(0, idx);
124
- if (!scheme) {
125
- throw new LLMError(`invalid LLM URI (empty scheme): ${raw}`);
126
- }
127
- let rest = raw.slice(idx + sep.length);
128
- if (!rest) {
129
- throw new LLMError(`invalid LLM URI (empty model): ${raw}`);
130
- }
131
- let params;
132
- const qIdx = rest.indexOf("?");
133
- if (qIdx >= 0) {
134
- const qs = rest.slice(qIdx + 1);
135
- rest = rest.slice(0, qIdx);
136
- params = {};
137
- for (const pair of qs.split("&")) {
138
- const eqIdx = pair.indexOf("=");
139
- if (eqIdx > 0) {
140
- params[pair.slice(0, eqIdx)] = decodeURIComponent(
141
- pair.slice(eqIdx + 1)
142
- );
143
- }
144
- }
145
- }
146
- if (!rest) {
147
- throw new LLMError(`invalid LLM URI (empty model): ${raw}`);
148
- }
149
- let host;
150
- let model;
151
- const hostPortMatch = rest.match(/^([^/]+:\d+)\/(.+)$/);
152
- if (hostPortMatch) {
153
- host = hostPortMatch[1];
154
- model = hostPortMatch[2];
155
- } else {
156
- model = rest;
157
- }
158
- const uri = { scheme, model };
159
- if (host) uri.host = host;
160
- if (params && Object.keys(params).length > 0) uri.params = params;
161
- return uri;
162
- }
163
- function loadConfig(uriStr) {
164
- const effective = uriStr || process.env["LLM_PROVIDER"];
165
- if (!effective) {
166
- throw new LLMError(
167
- "no LLM URI provided and LLM_PROVIDER env var is not set"
168
- );
169
- }
170
- const uri = parseURI(effective);
171
- const fallbackEnv = process.env["LLM_FALLBACK"];
172
- const fallbacks = fallbackEnv ? fallbackEnv.split(",").map((s) => s.trim()).filter(Boolean) : [];
173
- const provider = {
174
- model: uri.model
175
- };
176
- if (uri.params) provider.params = { ...uri.params };
177
- if (uri.params?.api_key) {
178
- provider.apiKey = uri.params.api_key;
179
- }
180
- if (uri.params?.base_url) {
181
- provider.baseURL = uri.params.base_url;
182
- }
183
- if (uri.host) {
184
- provider.baseURL = `http://${uri.host}`;
185
- }
186
- const envApiKey = process.env["LLM_API_KEY"] || void 0;
187
- const envBaseURL = process.env["LLM_BASE_URL"] || void 0;
188
- if (envApiKey) provider.apiKey = envApiKey;
189
- if (envBaseURL) provider.baseURL = envBaseURL;
190
- return { uri, provider, fallbacks };
191
- }
192
- var registry = /* @__PURE__ */ new Map();
193
- function register(scheme, factory) {
194
- if (registry.has(scheme)) {
195
- throw new LLMError(`provider already registered for scheme: ${scheme}`);
196
- }
197
- registry.set(scheme, factory);
198
- }
199
- function resolve(uriStr) {
200
- const cfg = loadConfig(uriStr);
201
- const factory = registry.get(cfg.uri.scheme);
202
- if (!factory) {
203
- throw new ProviderNotFoundError(cfg.uri.scheme);
204
- }
205
- return factory(cfg);
206
- }
207
- function clearRegistry() {
208
- registry.clear();
209
- }
210
- function createLLM(uri, opts) {
211
- const cfg = loadConfig(uri);
212
- const fallbackURIs = opts?.fallback ?? cfg.fallbacks;
213
- const primary = resolve(uri);
214
- const allURIs = [uri, ...fallbackURIs];
215
- const resolvedProviders = /* @__PURE__ */ new Map();
216
- resolvedProviders.set(0, primary);
217
- function resolveAt(index) {
218
- let p = resolvedProviders.get(index);
219
- if (!p) {
220
- p = resolve(allURIs[index]);
221
- resolvedProviders.set(index, p);
222
- }
223
- return p;
224
- }
225
- async function withFallback(op, fn) {
226
- const errors = [];
227
- for (let i = 0; i < allURIs.length; i++) {
228
- try {
229
- const p = resolveAt(i);
230
- if (!(op in p) || typeof p[op] !== "function") {
231
- throw new CapabilityNotSupportedError(
232
- op,
233
- parseURI(allURIs[i]).scheme
234
- );
235
- }
236
- return await fn(p);
237
- } catch (err) {
238
- const e = err instanceof Error ? err : new Error(String(err));
239
- errors.push(e);
240
- opts?.onError?.(e);
241
- const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
242
- if (!canContinue || i === allURIs.length - 1) {
243
- if (errors.length > 1) {
244
- throw new FallbackExhaustedError(errors);
245
- }
246
- throw e;
247
- }
248
- opts?.onFallback?.(i, i + 1, e);
249
- }
250
- }
251
- throw new FallbackExhaustedError(errors);
252
- }
253
- return {
254
- async complete(request) {
255
- opts?.onRequest?.(request);
256
- const start = Date.now();
257
- const resp = await withFallback(
258
- "complete",
259
- (p) => p.complete(request)
260
- );
261
- opts?.onResponse?.(resp, Date.now() - start);
262
- return resp;
263
- },
264
- stream(request) {
265
- return {
266
- [Symbol.asyncIterator]() {
267
- let inner = null;
268
- let initialized = false;
269
- return {
270
- async next() {
271
- if (!initialized) {
272
- initialized = true;
273
- opts?.onRequest?.(request);
274
- const errors = [];
275
- for (let i = 0; i < allURIs.length; i++) {
276
- try {
277
- const p = resolveAt(i);
278
- if (!("stream" in p) || typeof p.stream !== "function") {
279
- throw new CapabilityNotSupportedError(
280
- "stream",
281
- parseURI(allURIs[i]).scheme
282
- );
283
- }
284
- const iterable = p.stream(request);
285
- const iter = iterable[Symbol.asyncIterator]();
286
- const first = await iter.next();
287
- inner = iter;
288
- return first;
289
- } catch (err) {
290
- const e = err instanceof Error ? err : new Error(String(err));
291
- errors.push(e);
292
- opts?.onError?.(e);
293
- const canContinue = isFallbackable(e) || e instanceof CapabilityNotSupportedError;
294
- if (!canContinue || i === allURIs.length - 1) {
295
- if (errors.length > 1)
296
- throw new FallbackExhaustedError(errors);
297
- throw e;
298
- }
299
- opts?.onFallback?.(i, i + 1, e);
300
- }
301
- }
302
- throw new FallbackExhaustedError(errors);
303
- }
304
- return inner.next();
305
- }
306
- };
307
- }
308
- };
309
- },
310
- async callWithTools(request, tools) {
311
- opts?.onRequest?.(request);
312
- const start = Date.now();
313
- const resp = await withFallback(
314
- "callWithTools",
315
- (p) => p.callWithTools(request, tools)
316
- );
317
- opts?.onResponse?.(
318
- { content: resp.content, role: "assistant" },
319
- Date.now() - start
320
- );
321
- return resp;
322
- },
323
- capabilities() {
324
- const caps = [];
325
- if (primary.complete) caps.push("complete");
326
- if (primary.stream) caps.push("stream");
327
- if (primary.callWithTools) caps.push("callWithTools");
328
- return caps;
329
- },
330
- provider() {
331
- return primary;
332
- },
333
- close() {
334
- for (const p of resolvedProviders.values()) {
335
- p.close();
336
- }
337
- }
338
- };
339
- }
340
- // Annotate the CommonJS export names for ESM import in node:
341
- 0 && (module.exports = {
342
- AuthError,
343
- CapabilityNotSupportedError,
344
- FallbackExhaustedError,
345
- LLMError,
346
- ModelError,
347
- ProviderNotFoundError,
348
- RateLimitError,
349
- clearRegistry,
350
- createLLM,
351
- isFallbackable,
352
- loadConfig,
353
- parseURI,
354
- register,
355
- resolve
356
- });
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ var _chunkPSFYJGDGjs = require('./chunk-PSFYJGDG.js');
50
+ require('./chunk-4UE5TCMQ.js');
51
+ require('./chunk-KVG7YCTS.js');
52
+ require('./chunk-R5U7XKVJ.js');
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ exports.ANTHROPIC_TOOL_NAMES = _chunkPSFYJGDGjs.ANTHROPIC_TOOL_NAMES; exports.APIError = _chunkPSFYJGDGjs.APIError; exports.AuthError = _chunkPSFYJGDGjs.AuthError; exports.CapabilityNotSupportedError = _chunkPSFYJGDGjs.CapabilityNotSupportedError; exports.DEFAULT_MAX_MEDIA_BYTES = _chunkPSFYJGDGjs.DEFAULT_MAX_MEDIA_BYTES; exports.FallbackExhaustedError = _chunkPSFYJGDGjs.FallbackExhaustedError; exports.GEMINI_TOOL_NAMES = _chunkPSFYJGDGjs.GEMINI_TOOL_NAMES; exports.HTTPStatusError = _chunkPSFYJGDGjs.HTTPStatusError; exports.KeyEndpointError = _chunkPSFYJGDGjs.KeyEndpointError; exports.LLMError = _chunkPSFYJGDGjs.LLMError; exports.MediaTooLargeError = _chunkPSFYJGDGjs.MediaTooLargeError; exports.MediaURLRefusedError = _chunkPSFYJGDGjs.MediaURLRefusedError; exports.MissingKeyError = _chunkPSFYJGDGjs.MissingKeyError; exports.ModelError = _chunkPSFYJGDGjs.ModelError; exports.OPENAI_TOOL_NAMES = _chunkPSFYJGDGjs.OPENAI_TOOL_NAMES; exports.PermissionDeniedError = _chunkPSFYJGDGjs.PermissionDeniedError; exports.ProviderNotFoundError = _chunkPSFYJGDGjs.ProviderNotFoundError; exports.RateLimitError = _chunkPSFYJGDGjs.RateLimitError; exports.ResponseTooLargeError = _chunkPSFYJGDGjs.ResponseTooLargeError; exports.StreamTruncatedError = _chunkPSFYJGDGjs.StreamTruncatedError; exports.TOOL_NAMES_PARAM = _chunkPSFYJGDGjs.TOOL_NAMES_PARAM; exports.ToolNameError = _chunkPSFYJGDGjs.ToolNameError; exports.ToolNames = _chunkPSFYJGDGjs.ToolNames; exports.applyAPIKey = _chunkPSFYJGDGjs.applyAPIKey; exports.checkKeyEndpoint = _chunkPSFYJGDGjs.checkKeyEndpoint; exports.checkToolChoice = _chunkPSFYJGDGjs.checkToolChoice; exports.checkToolLinkage = _chunkPSFYJGDGjs.checkToolLinkage; exports.clearRegistry = _chunkPSFYJGDGjs.clearRegistry; exports.createLLM = _chunkPSFYJGDGjs.createLLM; exports.credentialsTrusted = _chunkPSFYJGDGjs.credentialsTrusted; exports.declarationOf = _chunkPSFYJGDGjs.declarationOf; exports.fileSource = _chunkPSFYJGDGjs.fileSource; exports.inlineSource = _chunkPSFYJGDGjs.inlineSource; exports.isFallbackable = _chunkPSFYJGDGjs.isFallbackable; exports.isPublicAddress = _chunkPSFYJGDGjs.isPublicAddress; exports.isValidToolName = _chunkPSFYJGDGjs.isValidToolName; exports.loadConfig = _chunkPSFYJGDGjs.loadConfig; exports.parseURI = _chunkPSFYJGDGjs.parseURI; exports.redactURI = _chunkPSFYJGDGjs.redactURI; exports.register = _chunkPSFYJGDGjs.register; exports.requestStartedPayload = _chunkPSFYJGDGjs.requestStartedPayload; exports.resolve = _chunkPSFYJGDGjs.resolve; exports.responseReceivedPayload = _chunkPSFYJGDGjs.responseReceivedPayload; exports.sanitizeToolName = _chunkPSFYJGDGjs.sanitizeToolName; exports.toolNameModeOf = _chunkPSFYJGDGjs.toolNameModeOf; exports.urlSource = _chunkPSFYJGDGjs.urlSource; exports.usageCost = _chunkPSFYJGDGjs.usageCost;