@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- 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 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- 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 +71 -0
- package/src/index.ts +46 -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/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -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.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- 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/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
package/src/routellm.ts
CHANGED
|
@@ -3,24 +3,37 @@
|
|
|
3
3
|
*
|
|
4
4
|
* RouteLLM adapter — registers the `routellm` URI scheme.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* The model field takes either shape a RouteLLM server advertises on
|
|
7
|
+
* `/v1/models`, as in Go:
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* - `router_name:threshold` — `routellm://mf:0.7`, sent as the server's
|
|
10
|
+
* `router-[name]-[threshold]` model. The client picks both.
|
|
11
|
+
* - tier name — `routellm://private`, sent verbatim. The server resolves
|
|
12
|
+
* router and threshold from its own tier config.
|
|
13
|
+
*
|
|
14
|
+
* Delegates to the openai adapter (`@hop-top/kit/openai`) pointed
|
|
15
|
+
* at the RouteLLM server's OpenAI-compatible endpoint.
|
|
16
|
+
* Importing this module registers the openai schemes too.
|
|
11
17
|
*/
|
|
12
18
|
|
|
13
19
|
import {
|
|
14
20
|
type Completer,
|
|
15
21
|
type Streamer,
|
|
22
|
+
type ToolCaller,
|
|
23
|
+
type ToolStreamer,
|
|
24
|
+
type ToolDef,
|
|
25
|
+
type ToolResponse,
|
|
26
|
+
type ToolStream,
|
|
16
27
|
type Request,
|
|
17
28
|
type Response,
|
|
18
|
-
type Token,
|
|
19
29
|
type ResolvedConfig,
|
|
20
30
|
type Provider,
|
|
21
31
|
LLMError,
|
|
32
|
+
TOOL_NAMES_PARAM,
|
|
22
33
|
register,
|
|
34
|
+
toolNameModeOf,
|
|
23
35
|
} from "./llm";
|
|
36
|
+
import { OpenAIAdapter, apiRootV1 } from "./llm-openai";
|
|
24
37
|
|
|
25
38
|
// ─── RouterConfig ─────────────────────────────────────────────────────────────
|
|
26
39
|
|
|
@@ -55,10 +68,13 @@ function defaultRouterConfig(): RouterConfig {
|
|
|
55
68
|
|
|
56
69
|
/**
|
|
57
70
|
* Extract and validate RouteLLM configuration from provider extras.
|
|
58
|
-
* Environment variables
|
|
71
|
+
* Environment variables (`ROUTELLM_BASE_URL`, `ROUTELLM_STRONG_MODEL`,
|
|
72
|
+
* `ROUTELLM_WEAK_MODEL`, `ROUTELLM_ROUTERS`) override all other
|
|
73
|
+
* sources; with `opts.hermetic` none is read.
|
|
59
74
|
*/
|
|
60
75
|
export function parseRouterConfig(
|
|
61
|
-
extras?: Record<string, unknown
|
|
76
|
+
extras?: Record<string, unknown>,
|
|
77
|
+
opts: { hermetic?: boolean } = {}
|
|
62
78
|
): RouterConfig {
|
|
63
79
|
const cfg = defaultRouterConfig();
|
|
64
80
|
|
|
@@ -107,6 +123,8 @@ export function parseRouterConfig(
|
|
|
107
123
|
}
|
|
108
124
|
}
|
|
109
125
|
|
|
126
|
+
if (opts.hermetic) return cfg;
|
|
127
|
+
|
|
110
128
|
// Environment variable overrides (highest precedence).
|
|
111
129
|
const envBaseUrl = process.env["ROUTELLM_BASE_URL"];
|
|
112
130
|
if (envBaseUrl) cfg.baseUrl = envBaseUrl;
|
|
@@ -130,225 +148,237 @@ export function parseRouterConfig(
|
|
|
130
148
|
|
|
131
149
|
// ─── Model field parsing ──────────────────────────────────────────────────────
|
|
132
150
|
|
|
151
|
+
/**
|
|
152
|
+
* The model field classified. `isTier` selects `tier`; otherwise
|
|
153
|
+
* `routerName` and `threshold` hold the client-selected pair. The
|
|
154
|
+
* unused shape stays at `""` / `0`.
|
|
155
|
+
*/
|
|
133
156
|
export interface ParsedModel {
|
|
157
|
+
isTier: boolean;
|
|
158
|
+
tier: string;
|
|
134
159
|
routerName: string;
|
|
135
160
|
threshold: number;
|
|
136
161
|
}
|
|
137
162
|
|
|
163
|
+
const MODEL_REQUIRED =
|
|
164
|
+
"model field is required (router_name:threshold or tier name)";
|
|
165
|
+
|
|
166
|
+
const DECIMAL_FLOAT = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
167
|
+
const HEX_FLOAT =
|
|
168
|
+
/^([+-]?)0[xX]([0-9a-fA-F]*)(?:\.([0-9a-fA-F]*))?[pP]([+-]?\d+)$/;
|
|
169
|
+
|
|
138
170
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
171
|
+
* Go's underscore rule for float literals: an underscore must sit
|
|
172
|
+
* between digits, or between a base prefix and a digit.
|
|
141
173
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
function underscoreOK(text: string): boolean {
|
|
175
|
+
let s = text;
|
|
176
|
+
if (s[0] === "+" || s[0] === "-") s = s.slice(1);
|
|
177
|
+
let saw = "^"; // ^ start, 0 digit or prefix, _ underscore, ! other
|
|
178
|
+
let i = 0;
|
|
179
|
+
let hex = false;
|
|
180
|
+
const p = s[1]?.toLowerCase();
|
|
181
|
+
if (s.length >= 2 && s[0] === "0" && (p === "b" || p === "o" || p === "x")) {
|
|
182
|
+
i = 2;
|
|
183
|
+
saw = "0";
|
|
184
|
+
hex = p === "x";
|
|
147
185
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
)
|
|
186
|
+
for (; i < s.length; i++) {
|
|
187
|
+
const c = s[i]!;
|
|
188
|
+
if ((c >= "0" && c <= "9") || (hex && /[a-fA-F]/.test(c))) {
|
|
189
|
+
saw = "0";
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (c === "_") {
|
|
193
|
+
if (saw !== "0") return false;
|
|
194
|
+
saw = "_";
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (saw === "_") return false;
|
|
198
|
+
saw = "!";
|
|
155
199
|
}
|
|
200
|
+
return saw !== "_";
|
|
201
|
+
}
|
|
156
202
|
|
|
157
|
-
|
|
158
|
-
|
|
203
|
+
/**
|
|
204
|
+
* A finite float in the syntax Go's `strconv.ParseFloat` accepts
|
|
205
|
+
* (decimal or hex mantissa, underscores between digits), else
|
|
206
|
+
* `undefined`. Infinities, NaN and out-of-range values are not.
|
|
207
|
+
*/
|
|
208
|
+
function parseFiniteFloat(text: string): number | undefined {
|
|
209
|
+
if (text.includes("_")) {
|
|
210
|
+
if (!underscoreOK(text)) return undefined;
|
|
211
|
+
text = text.replace(/_/g, "");
|
|
212
|
+
}
|
|
213
|
+
let v: number;
|
|
214
|
+
if (DECIMAL_FLOAT.test(text)) {
|
|
215
|
+
v = Number(text);
|
|
216
|
+
} else {
|
|
217
|
+
const m = HEX_FLOAT.exec(text);
|
|
218
|
+
if (!m) return undefined;
|
|
219
|
+
const [, sign, int = "", frac = "", exp = "0"] = m;
|
|
220
|
+
if (!int && !frac) return undefined;
|
|
221
|
+
v = parseInt(int + frac || "0", 16) * 2 ** (Number(exp) - 4 * frac.length);
|
|
222
|
+
if (sign === "-") v = -v;
|
|
223
|
+
}
|
|
224
|
+
return Number.isFinite(v) ? v : undefined;
|
|
225
|
+
}
|
|
159
226
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Format a float as Go's `strconv.FormatFloat(f, 'f', -1, 64)`: the
|
|
229
|
+
* shortest round-tripping digits, never an exponent, `-0` kept.
|
|
230
|
+
*/
|
|
231
|
+
function formatFloat(v: number): string {
|
|
232
|
+
if (Object.is(v, -0)) return "-0";
|
|
233
|
+
const sign = v < 0 ? "-" : "";
|
|
234
|
+
const repr = String(Math.abs(v));
|
|
235
|
+
const e = repr.indexOf("e");
|
|
236
|
+
if (e < 0) return sign + repr;
|
|
237
|
+
const exp = Number(repr.slice(e + 1));
|
|
238
|
+
const digits = repr.slice(0, e).replace(".", "");
|
|
239
|
+
const point = 1 + exp; // position of the decimal point in digits
|
|
240
|
+
if (point <= 0) return `${sign}0.${"0".repeat(-point)}${digits}`;
|
|
241
|
+
if (point >= digits.length) {
|
|
242
|
+
return sign + digits + "0".repeat(point - digits.length);
|
|
165
243
|
}
|
|
244
|
+
return `${sign}${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
245
|
+
}
|
|
166
246
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
247
|
+
/**
|
|
248
|
+
* Classify the model field as a `router_name:threshold` pair or a tier
|
|
249
|
+
* name, exactly as Go does.
|
|
250
|
+
*
|
|
251
|
+
* The shapes are told apart by the text after the last colon: when it
|
|
252
|
+
* parses as a finite float (Go `ParseFloat` syntax) the model is a
|
|
253
|
+
* router pair, else a tier sent verbatim — so a tier name may contain
|
|
254
|
+
* colons and `mf:abc` is a tier. A leading or trailing colon leaves a
|
|
255
|
+
* tier. The threshold range is checked by the adapter, not here; an
|
|
256
|
+
* unknown tier fails at the server.
|
|
257
|
+
*/
|
|
258
|
+
export function parseModelField(model: string): ParsedModel {
|
|
259
|
+
if (!model) throw new LLMError(MODEL_REQUIRED);
|
|
260
|
+
|
|
261
|
+
const idx = model.lastIndexOf(":");
|
|
262
|
+
if (idx > 0 && idx < model.length - 1) {
|
|
263
|
+
const threshold = parseFiniteFloat(model.slice(idx + 1));
|
|
264
|
+
if (threshold !== undefined) {
|
|
265
|
+
return {
|
|
266
|
+
isTier: false,
|
|
267
|
+
tier: "",
|
|
268
|
+
routerName: model.slice(0, idx),
|
|
269
|
+
threshold,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
170
272
|
}
|
|
171
273
|
|
|
172
|
-
return { routerName, threshold };
|
|
274
|
+
return { isTier: true, tier: model, routerName: "", threshold: 0 };
|
|
173
275
|
}
|
|
174
276
|
|
|
175
277
|
// ─── Adapter ──────────────────────────────────────────────────────────────────
|
|
176
278
|
|
|
177
279
|
/**
|
|
178
|
-
* RouteLLM adapter
|
|
280
|
+
* RouteLLM adapter: complete, stream, callWithTools and streamWithTools.
|
|
179
281
|
*
|
|
180
|
-
* Delegates to an
|
|
181
|
-
* server
|
|
282
|
+
* Delegates to an inner {@link OpenAIAdapter} pointed at the RouteLLM
|
|
283
|
+
* server's OpenAI-compatible `/v1` API, so tool calling, tool names
|
|
284
|
+
* (openai rule, `?tool_names=`), size limits, retries and the
|
|
285
|
+
* credential guard are the openai adapter's.
|
|
182
286
|
*/
|
|
183
|
-
export class RouteLLMAdapter
|
|
287
|
+
export class RouteLLMAdapter
|
|
288
|
+
implements Completer, Streamer, ToolCaller, ToolStreamer
|
|
289
|
+
{
|
|
184
290
|
readonly config: RouterConfig;
|
|
291
|
+
/** Client-selected router; `""` for a tier. */
|
|
185
292
|
readonly routerName: string;
|
|
293
|
+
/** Client-selected threshold; `0` for a tier (see {@link isTier}). */
|
|
186
294
|
readonly threshold: number;
|
|
295
|
+
/** Server-resolved tier name; `""` for a router pair. */
|
|
296
|
+
readonly tier: string;
|
|
297
|
+
/** The API root requests go to: the resolved base URL plus `/v1`. */
|
|
298
|
+
readonly baseURL: string;
|
|
187
299
|
|
|
188
|
-
private readonly
|
|
189
|
-
private readonly _serverModel: string;
|
|
190
|
-
private readonly _apiKey: string;
|
|
300
|
+
private readonly inner: OpenAIAdapter;
|
|
191
301
|
|
|
192
302
|
constructor(cfg: ResolvedConfig) {
|
|
193
|
-
this.config = parseRouterConfig(cfg.provider.extras);
|
|
303
|
+
this.config = parseRouterConfig(cfg.provider.extras, { hermetic: cfg.hermetic });
|
|
304
|
+
// The server speaks the OpenAI wire: its tool-name rule applies.
|
|
305
|
+
// Checked here so an unknown mode fails construction.
|
|
306
|
+
toolNameModeOf(cfg.provider.params);
|
|
194
307
|
|
|
195
308
|
const model = cfg.provider.model || cfg.uri.model;
|
|
309
|
+
if (!model) throw new LLMError(`routellm: ${MODEL_REQUIRED}`);
|
|
196
310
|
const parsed = parseModelField(model);
|
|
197
311
|
this.routerName = parsed.routerName;
|
|
198
312
|
this.threshold = parsed.threshold;
|
|
313
|
+
this.tier = parsed.tier;
|
|
199
314
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
315
|
+
// A tier travels verbatim; a router pair becomes
|
|
316
|
+
// router-[name]-[threshold].
|
|
317
|
+
let serverModel = parsed.tier;
|
|
318
|
+
if (!parsed.isTier) {
|
|
319
|
+
if (this.threshold < 0 || this.threshold > 1) {
|
|
320
|
+
throw new LLMError(
|
|
321
|
+
`routellm: threshold ${this.threshold.toFixed(4)} out of range [0, 1]`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
serverModel = `router-${this.routerName}-${formatFloat(this.threshold)}`;
|
|
204
325
|
}
|
|
205
326
|
|
|
206
|
-
//
|
|
207
|
-
|
|
327
|
+
// Resolve base URL: provider (URI base_url or host, LLM_BASE_URL) >
|
|
328
|
+
// router config (ROUTELLM_BASE_URL > extras routellm.base_url) >
|
|
329
|
+
// default, as in Go.
|
|
330
|
+
this.baseURL = apiRootV1(cfg.provider.baseURL || this.config.baseUrl);
|
|
208
331
|
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
332
|
+
// The inner adapter takes the params it owns.
|
|
333
|
+
const params: Record<string, string> = {};
|
|
334
|
+
for (const k of [TOOL_NAMES_PARAM, "max_body_bytes", "max_event_bytes"]) {
|
|
335
|
+
const v = cfg.provider.params?.[k];
|
|
336
|
+
if (v !== undefined) params[k] = v;
|
|
213
337
|
}
|
|
214
|
-
this.
|
|
215
|
-
|
|
338
|
+
this.inner = new OpenAIAdapter(
|
|
339
|
+
{
|
|
340
|
+
uri: { scheme: "routellm", model },
|
|
341
|
+
provider: {
|
|
342
|
+
apiKey: cfg.provider.apiKey,
|
|
343
|
+
baseURL: this.baseURL,
|
|
344
|
+
model: serverModel,
|
|
345
|
+
params,
|
|
346
|
+
},
|
|
347
|
+
fallbacks: [],
|
|
348
|
+
hermetic: cfg.hermetic,
|
|
349
|
+
},
|
|
350
|
+
{ label: "routellm" }
|
|
351
|
+
);
|
|
216
352
|
}
|
|
217
353
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const finishReason = choice?.finish_reason ?? "";
|
|
226
|
-
|
|
227
|
-
const usage = data.usage
|
|
228
|
-
? {
|
|
229
|
-
promptTokens: data.usage.prompt_tokens ?? 0,
|
|
230
|
-
completionTokens: data.usage.completion_tokens ?? 0,
|
|
231
|
-
totalTokens: data.usage.total_tokens ?? 0,
|
|
232
|
-
}
|
|
233
|
-
: undefined;
|
|
234
|
-
|
|
235
|
-
return { content, role: "assistant", usage, finishReason };
|
|
354
|
+
/**
|
|
355
|
+
* Whether the adapter targets a server-resolved tier rather than a
|
|
356
|
+
* client-selected pair; use it instead of `threshold === 0`, which is
|
|
357
|
+
* also a valid client threshold.
|
|
358
|
+
*/
|
|
359
|
+
isTier(): boolean {
|
|
360
|
+
return this.tier !== "";
|
|
236
361
|
}
|
|
237
362
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const resp = await this._post("/v1/chat/completions", body);
|
|
241
|
-
|
|
242
|
-
if (!resp.body) {
|
|
243
|
-
throw new LLMError("routellm: streaming response has no body");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const reader = resp.body.getReader();
|
|
247
|
-
const decoder = new TextDecoder();
|
|
248
|
-
let buf = "";
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
for (;;) {
|
|
252
|
-
const { done, value } = await reader.read();
|
|
253
|
-
if (done) break;
|
|
254
|
-
|
|
255
|
-
buf += decoder.decode(value, { stream: true });
|
|
256
|
-
const lines = buf.split("\n");
|
|
257
|
-
buf = lines.pop() ?? "";
|
|
258
|
-
|
|
259
|
-
for (const line of lines) {
|
|
260
|
-
const trimmed = line.trim();
|
|
261
|
-
if (!trimmed || !trimmed.startsWith("data: ")) continue;
|
|
262
|
-
const payload = trimmed.slice(6);
|
|
263
|
-
if (payload === "[DONE]") {
|
|
264
|
-
yield { content: "", done: true };
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const chunk = JSON.parse(payload) as OpenAIStreamChunk;
|
|
269
|
-
const delta = chunk.choices?.[0]?.delta;
|
|
270
|
-
const content = delta?.content ?? "";
|
|
271
|
-
const isDone = chunk.choices?.[0]?.finish_reason != null;
|
|
272
|
-
yield { content, done: isDone };
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
} finally {
|
|
276
|
-
reader.releaseLock();
|
|
277
|
-
}
|
|
363
|
+
complete(req: Request): Promise<Response> {
|
|
364
|
+
return this.inner.complete(req);
|
|
278
365
|
}
|
|
279
366
|
|
|
280
|
-
|
|
281
|
-
|
|
367
|
+
stream(req: Request): ToolStream {
|
|
368
|
+
return this.inner.stream(req);
|
|
282
369
|
}
|
|
283
370
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
private _buildBody(
|
|
287
|
-
req: Request,
|
|
288
|
-
stream: boolean
|
|
289
|
-
): Record<string, unknown> {
|
|
290
|
-
const body: Record<string, unknown> = {
|
|
291
|
-
model: this._serverModel,
|
|
292
|
-
messages: req.messages.map((m) => ({
|
|
293
|
-
role: m.role,
|
|
294
|
-
content: m.content,
|
|
295
|
-
})),
|
|
296
|
-
stream,
|
|
297
|
-
};
|
|
298
|
-
if (req.temperature !== undefined) body["temperature"] = req.temperature;
|
|
299
|
-
if (req.maxTokens !== undefined) body["max_tokens"] = req.maxTokens;
|
|
300
|
-
if (req.stopSequences?.length) body["stop"] = req.stopSequences;
|
|
301
|
-
return body;
|
|
371
|
+
callWithTools(req: Request, tools: ToolDef[]): Promise<ToolResponse> {
|
|
372
|
+
return this.inner.callWithTools(req, tools);
|
|
302
373
|
}
|
|
303
374
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
body: Record<string, unknown>
|
|
307
|
-
): Promise<globalThis.Response> {
|
|
308
|
-
const url = `${this._baseUrl}${path}`;
|
|
309
|
-
const headers: Record<string, string> = {
|
|
310
|
-
"Content-Type": "application/json",
|
|
311
|
-
};
|
|
312
|
-
if (this._apiKey) {
|
|
313
|
-
headers["Authorization"] = `Bearer ${this._apiKey}`;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const resp = await fetch(url, {
|
|
317
|
-
method: "POST",
|
|
318
|
-
headers,
|
|
319
|
-
body: JSON.stringify(body),
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
if (!resp.ok) {
|
|
323
|
-
const text = await resp.text().catch(() => "");
|
|
324
|
-
throw new LLMError(
|
|
325
|
-
`routellm: HTTP ${resp.status} from ${url}: ${text}`
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return resp;
|
|
375
|
+
streamWithTools(req: Request, tools: ToolDef[]): ToolStream {
|
|
376
|
+
return this.inner.streamWithTools(req, tools);
|
|
330
377
|
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// ─── OpenAI-compatible response types (internal) ──────────────────────────────
|
|
334
|
-
|
|
335
|
-
interface OpenAIChatResponse {
|
|
336
|
-
choices?: {
|
|
337
|
-
message?: { content?: string; role?: string };
|
|
338
|
-
finish_reason?: string;
|
|
339
|
-
}[];
|
|
340
|
-
usage?: {
|
|
341
|
-
prompt_tokens?: number;
|
|
342
|
-
completion_tokens?: number;
|
|
343
|
-
total_tokens?: number;
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
378
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
finish_reason?: string | null;
|
|
351
|
-
}[];
|
|
379
|
+
close(): void {
|
|
380
|
+
this.inner.close();
|
|
381
|
+
}
|
|
352
382
|
}
|
|
353
383
|
|
|
354
384
|
// ─── Registration ─────────────────────────────────────────────────────────────
|
|
@@ -358,8 +388,14 @@ function routellmFactory(cfg: ResolvedConfig): Provider {
|
|
|
358
388
|
return {
|
|
359
389
|
complete: (req) => adapter.complete(req),
|
|
360
390
|
stream: (req) => adapter.stream(req),
|
|
391
|
+
callWithTools: (req, tools) => adapter.callWithTools(req, tools),
|
|
392
|
+
streamWithTools: (req, tools) => adapter.streamWithTools(req, tools),
|
|
361
393
|
close: () => adapter.close(),
|
|
362
394
|
};
|
|
363
395
|
}
|
|
364
396
|
|
|
365
|
-
|
|
397
|
+
// A local router: ROUTELLM_API_KEY is sent when set and never
|
|
398
|
+
// required, so LLM_API_KEY is not lent to it.
|
|
399
|
+
register("routellm", routellmFactory, {
|
|
400
|
+
key: { envVars: ["ROUTELLM_API_KEY"], optional: true },
|
|
401
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# router
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
How a prompt is scored and sent to a strong or a weak model: the RouteLLM `Router` interface, the scoring routers (`random`, `mf`, `sw`, `bert`), the `Controller` that owns thresholds and middleware, and a Hono handler exposing `/v1/chat/completions`. Wrong module for calling a RouteLLM server from a client (`@hop-top/kit/routellm` registers the `routellm://` URI scheme) and for provider clients (`@hop-top/kit/llm`).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- pick a model for a prompt in-process: `new Controller({ strongModel, weakModel, routers })` then `controller.route(prompt, routerName, threshold)`
|
|
10
|
+
- add a scorer: implement `Router.score(prompt): Promise<number>` in `[0, 1]`
|
|
11
|
+
- pre-route by intent: `IntentModelSelector` middleware in [`intent.ts`](intent.ts)
|
|
12
|
+
- serve OpenAI-compatible routing: [`server.ts`](server.ts)
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Controller } from './controller';
|
|
18
|
+
import { RandomRouter } from './random';
|
|
19
|
+
|
|
20
|
+
const controller = new Controller({
|
|
21
|
+
strongModel: 'gpt-4',
|
|
22
|
+
weakModel: 'gpt-3.5-turbo',
|
|
23
|
+
routers: { random: new RandomRouter() },
|
|
24
|
+
});
|
|
25
|
+
console.log(await controller.route('hello', 'random', 0.5));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Contract
|
|
29
|
+
|
|
30
|
+
- `score` returns the strong-model win-rate estimate; `score >= threshold` selects `pair.strong`, else `pair.weak`.
|
|
31
|
+
- Server model names use the `router-<name>-<threshold>` form parsed by `parseModelName`.
|
|
32
|
+
- Not on the package exports map and not in the `tsup` build: reachable only by relative import inside `src/`.
|
|
33
|
+
- `bert` scores through the KServe client in [`../triton`](../triton/README.md); `mf` and `sw` take an embedding function.
|
|
34
|
+
|
|
35
|
+
## Neighbours
|
|
36
|
+
|
|
37
|
+
- `@hop-top/kit/routellm`: client-side `routellm://name:threshold` adapter
|
|
38
|
+
- `@hop-top/kit/llm`: provider registry and `Client` facade
|
|
39
|
+
- [`../triton`](../triton/README.md): inference transport for `bert`
|
|
40
|
+
- Go: `go/console/cli/router`, the `kit llm router` subcommand tree
|
|
41
|
+
|
|
42
|
+
## See also
|
|
43
|
+
|
|
44
|
+
- [`docs/adopters/reference/go-primitives.md`](../../../../docs/adopters/reference/go-primitives.md)
|
|
@@ -191,3 +191,44 @@ describe("server /v1/chat/completions", () => {
|
|
|
191
191
|
expect(router.score).toHaveBeenCalledWith("route me");
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
describe("server tool-call linkage", () => {
|
|
196
|
+
it("forwards assistant tool_calls and tool_call_id upstream", async () => {
|
|
197
|
+
const upstream = mockUpstream();
|
|
198
|
+
const app = makeApp(0.9, upstream);
|
|
199
|
+
|
|
200
|
+
const body: ChatCompletionRequest = {
|
|
201
|
+
model: "router-mf-0.5",
|
|
202
|
+
messages: [
|
|
203
|
+
{ role: "user", content: "Weather?" },
|
|
204
|
+
{
|
|
205
|
+
role: "assistant",
|
|
206
|
+
content: "",
|
|
207
|
+
tool_calls: [
|
|
208
|
+
{
|
|
209
|
+
id: "call_1",
|
|
210
|
+
type: "function",
|
|
211
|
+
function: { name: "get_weather", arguments: '{"city":"NYC"}' },
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
{ role: "tool", content: "sunny", tool_call_id: "call_1" },
|
|
216
|
+
],
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const res = await app.request("/v1/chat/completions", {
|
|
220
|
+
method: "POST",
|
|
221
|
+
headers: { "Content-Type": "application/json" },
|
|
222
|
+
body: JSON.stringify(body),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(res.status).toBe(200);
|
|
226
|
+
const sent = (upstream as ReturnType<typeof vi.fn>).mock
|
|
227
|
+
.calls[0][0] as ChatCompletionRequest;
|
|
228
|
+
expect(sent.messages[1].tool_calls?.[0].id).toBe("call_1");
|
|
229
|
+
expect(sent.messages[1].tool_calls?.[0].function.arguments).toBe(
|
|
230
|
+
'{"city":"NYC"}',
|
|
231
|
+
);
|
|
232
|
+
expect(sent.messages[2].tool_call_id).toBe("call_1");
|
|
233
|
+
});
|
|
234
|
+
});
|
package/src/router/server.ts
CHANGED
|
@@ -16,6 +16,17 @@ import { RoutingError } from "./router";
|
|
|
16
16
|
export interface ChatMessage {
|
|
17
17
|
role: string;
|
|
18
18
|
content: string;
|
|
19
|
+
/** Assistant turn: the tool calls the model made. */
|
|
20
|
+
tool_calls?: ChatToolCall[];
|
|
21
|
+
/** Role `tool`: the `ChatToolCall.id` this result answers. */
|
|
22
|
+
tool_call_id?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** An OpenAI assistant tool call; `arguments` is a JSON-encoded string. */
|
|
26
|
+
export interface ChatToolCall {
|
|
27
|
+
id: string;
|
|
28
|
+
type?: string;
|
|
29
|
+
function: { name: string; arguments: string };
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
export interface ChatCompletionRequest {
|
package/src/safety.test.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
2
|
import { safetyGuard } from './safety';
|
|
3
3
|
|
|
4
|
+
// A piped (non-TTY) stdout has no `isTTY` at all; `@types/node` types it
|
|
5
|
+
// as a plain `boolean`, so model the absent value via defineProperty.
|
|
6
|
+
function setStdoutTTY(value: boolean | undefined): void {
|
|
7
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
8
|
+
value,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
describe('safetyGuard', () => {
|
|
5
|
-
const origIsTTY = process.stdout.isTTY;
|
|
15
|
+
const origIsTTY: boolean | undefined = process.stdout.isTTY;
|
|
6
16
|
|
|
7
17
|
afterEach(() => {
|
|
8
|
-
|
|
18
|
+
setStdoutTTY(origIsTTY);
|
|
9
19
|
});
|
|
10
20
|
|
|
11
21
|
it('read level always passes', () => {
|
|
@@ -13,27 +23,27 @@ describe('safetyGuard', () => {
|
|
|
13
23
|
});
|
|
14
24
|
|
|
15
25
|
it('read level passes even in non-TTY', () => {
|
|
16
|
-
|
|
26
|
+
setStdoutTTY(undefined);
|
|
17
27
|
expect(() => safetyGuard('read')).not.toThrow();
|
|
18
28
|
});
|
|
19
29
|
|
|
20
30
|
it('caution level passes in TTY', () => {
|
|
21
|
-
|
|
31
|
+
setStdoutTTY(true);
|
|
22
32
|
expect(() => safetyGuard('caution')).not.toThrow();
|
|
23
33
|
});
|
|
24
34
|
|
|
25
35
|
it('caution level requires --force in non-TTY', () => {
|
|
26
|
-
|
|
36
|
+
setStdoutTTY(undefined);
|
|
27
37
|
expect(() => safetyGuard('caution')).toThrow(/--force/);
|
|
28
38
|
});
|
|
29
39
|
|
|
30
40
|
it('caution level passes with force in non-TTY', () => {
|
|
31
|
-
|
|
41
|
+
setStdoutTTY(undefined);
|
|
32
42
|
expect(() => safetyGuard('caution', { force: true })).not.toThrow();
|
|
33
43
|
});
|
|
34
44
|
|
|
35
45
|
it('dangerous level throws without --force', () => {
|
|
36
|
-
|
|
46
|
+
setStdoutTTY(true);
|
|
37
47
|
expect(() => safetyGuard('dangerous')).toThrow(/--force/);
|
|
38
48
|
});
|
|
39
49
|
|
|
@@ -42,12 +52,12 @@ describe('safetyGuard', () => {
|
|
|
42
52
|
});
|
|
43
53
|
|
|
44
54
|
it('dangerous level requires --force in non-TTY', () => {
|
|
45
|
-
|
|
55
|
+
setStdoutTTY(undefined);
|
|
46
56
|
expect(() => safetyGuard('dangerous')).toThrow(/--force/);
|
|
47
57
|
});
|
|
48
58
|
|
|
49
59
|
it('dangerous level passes with --force in non-TTY', () => {
|
|
50
|
-
|
|
60
|
+
setStdoutTTY(undefined);
|
|
51
61
|
expect(() => safetyGuard('dangerous', { force: true })).not.toThrow();
|
|
52
62
|
});
|
|
53
63
|
});
|