@hop-top/kit 0.5.0-alpha.3 → 0.5.0-alpha.5
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.
- package/CHANGELOG.md +52 -0
- package/LICENSE +1 -1
- package/README.md +47 -575
- package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
- package/dist/aim.d.ts +1 -1
- package/dist/aim.js +13 -414
- package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
- package/dist/alias.d.ts +1 -1
- package/dist/alias.js +18 -206
- package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +10 -164
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-72XZWQX7.js +504 -0
- package/dist/chunk-ABQSE7AI.js +513 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-GGWJRWWA.js +309 -0
- package/dist/chunk-IQXEISMC.js +142 -0
- package/dist/chunk-IXVQ62NZ.js +334 -0
- package/dist/chunk-JTMPNXVQ.js +1491 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-MUIQVU6E.js +251 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-PSFYJGDG.js +1445 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QPUCXQXT.js +67 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-S45UHXQF.js +182 -0
- package/dist/chunk-T46YPHKN.js +669 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-WWUKGJB5.js +90 -0
- package/dist/chunk-YGYQUFGY.js +219 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/chunk-ZC5TZYZJ.js +609 -0
- package/dist/{cli-DLygZLi9.d.ts → cli-8rfITnv4.d.ts} +13 -4
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +51 -1057
- package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
- package/dist/config.d.ts +1 -1
- package/dist/config.js +6 -78
- package/dist/errcorrect.js +8 -68
- package/dist/{error-DISJKeDu.d.ts → error-Do8Qji43.d.ts} +88 -1
- package/dist/id/index.d.ts +1 -1
- package/dist/id/index.js +14 -65
- package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
- package/dist/{index-Bc5c7Ty5.d.ts → index-DEyjGoo2.d.ts} +1 -1
- package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
- package/dist/index.d.ts +18 -15
- package/dist/index.js +39 -6722
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -1
- package/dist/llm.js +101 -356
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +155 -1453
- package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
- package/dist/netpolicy.d.ts +1 -1
- package/dist/netpolicy.js +25 -118
- package/dist/{output-4aXs91GY.d.ts → output-CjZWmL8s.d.ts} +28 -4
- package/dist/output.d.ts +2 -2
- package/dist/output.js +137 -971
- package/dist/progress.js +6 -55
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -2
- package/dist/routellm.js +13 -255
- package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.js +4 -98
- package/dist/safety.js +6 -43
- package/dist/scope.js +20 -377
- package/dist/{serve-DE-jscpb.d.ts → serve-D8yWMrTc.d.ts} +2 -2
- package/dist/serve.d.ts +2 -2
- package/dist/serve.js +75 -1019
- package/dist/sqlstore.js +6 -39
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.js +24 -608
- package/dist/tui/index.d.ts +5 -5
- package/dist/tui/index.js +17 -374
- package/dist/upgrade.js +6 -114
- package/dist/xdg.js +14 -128
- package/package.json +130 -25
- package/src/README.md +15 -0
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +78 -13
- package/src/completion-values.test.ts +10 -10
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config.test.ts +187 -1
- package/src/config.ts +173 -7
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +12 -0
- package/src/index.ts +2 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/mcp/README.md +57 -0
- package/src/mcp/conformance.test.ts +24 -3
- package/src/mcp/dispatch.ts +4 -4
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +6 -0
- package/src/mcp/legacy.ts +21 -8
- package/src/mcp/mcp.test.ts +14 -4
- package/src/mcp/modern-confirm.ts +1 -1
- package/src/mcp/modern.ts +12 -11
- package/src/mcp/tasks.ts +1 -1
- package/src/mcp/types.ts +80 -8
- package/src/netpolicy.test.ts +78 -0
- package/src/netpolicy.ts +28 -3
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/error.ts +144 -1
- package/src/output/formatters/README.md +50 -0
- package/src/output.ts +24 -1
- package/src/published-types.test.ts +115 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.ts +1 -1
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.ts +5 -5
- package/src/toolspec.test.ts +2 -2
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +33 -2
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/dist/llm-B5XUWH8T.d.ts +0 -231
- 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,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,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,
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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;
|