@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
package/src/scope-defaults.json
CHANGED
|
@@ -5,68 +5,68 @@
|
|
|
5
5
|
"version": 1,
|
|
6
6
|
"deny": {
|
|
7
7
|
"common": [
|
|
8
|
-
"
|
|
8
|
+
"**/*.key",
|
|
9
|
+
"**/*.pem",
|
|
10
|
+
"**/.env",
|
|
11
|
+
"**/.env.*",
|
|
12
|
+
"**/.git/config",
|
|
13
|
+
"**/credentials*",
|
|
14
|
+
"**/id_ed25519*",
|
|
15
|
+
"**/id_rsa*",
|
|
16
|
+
"**/secrets*",
|
|
9
17
|
"~/.aws/**",
|
|
10
18
|
"~/.azure/**",
|
|
11
19
|
"~/.config/gcloud/**",
|
|
12
20
|
"~/.gnupg/**",
|
|
13
|
-
"~/.pki/**",
|
|
14
21
|
"~/.kube/**",
|
|
15
|
-
"~/.netrc",
|
|
16
|
-
"~/.pgpass",
|
|
17
22
|
"~/.my.cnf",
|
|
23
|
+
"~/.netrc",
|
|
18
24
|
"~/.npmrc",
|
|
25
|
+
"~/.pgpass",
|
|
26
|
+
"~/.pki/**",
|
|
19
27
|
"~/.pypirc",
|
|
20
|
-
"
|
|
21
|
-
"**/.env.*",
|
|
22
|
-
"**/credentials*",
|
|
23
|
-
"**/secrets*",
|
|
24
|
-
"**/*.pem",
|
|
25
|
-
"**/*.key",
|
|
26
|
-
"**/id_rsa*",
|
|
27
|
-
"**/id_ed25519*",
|
|
28
|
-
"**/.git/config"
|
|
28
|
+
"~/.ssh/**"
|
|
29
29
|
],
|
|
30
30
|
"darwin": [
|
|
31
|
-
"~/Library/Keychains/**",
|
|
32
|
-
"~/Library/Cookies/**",
|
|
33
|
-
"~/Library/Application Support/Google/Chrome/**/Cookies*",
|
|
34
|
-
"~/Library/Application Support/Google/Chrome/**/Login Data*",
|
|
35
31
|
"~/Library/Application Support/Arc/User Data/**/Cookies*",
|
|
36
32
|
"~/Library/Application Support/BraveSoftware/Brave-Browser/**/Cookies*",
|
|
37
|
-
"~/Library/Application Support/Microsoft Edge/**/Cookies*",
|
|
38
33
|
"~/Library/Application Support/Firefox/Profiles/**/cookies.sqlite",
|
|
39
34
|
"~/Library/Application Support/Firefox/Profiles/**/key*.db",
|
|
40
|
-
"~/Library/Application Support/Firefox/Profiles/**/logins.json"
|
|
35
|
+
"~/Library/Application Support/Firefox/Profiles/**/logins.json",
|
|
36
|
+
"~/Library/Application Support/Google/Chrome/**/Cookies*",
|
|
37
|
+
"~/Library/Application Support/Google/Chrome/**/Login Data*",
|
|
38
|
+
"~/Library/Application Support/Microsoft Edge/**/Cookies*",
|
|
39
|
+
"~/Library/Cookies/**",
|
|
40
|
+
"~/Library/Keychains/**"
|
|
41
41
|
],
|
|
42
42
|
"linux": [
|
|
43
|
+
"~/.config/BraveSoftware/Brave-Browser/**/Cookies*",
|
|
43
44
|
"~/.config/google-chrome/**/Cookies*",
|
|
44
45
|
"~/.config/google-chrome/**/Login Data*",
|
|
45
|
-
"~/.config/BraveSoftware/Brave-Browser/**/Cookies*",
|
|
46
46
|
"~/.config/microsoft-edge/**/Cookies*",
|
|
47
47
|
"~/.mozilla/firefox/**/cookies.sqlite",
|
|
48
48
|
"~/.mozilla/firefox/**/key*.db",
|
|
49
49
|
"~/.mozilla/firefox/**/logins.json"
|
|
50
50
|
],
|
|
51
51
|
"windows": [
|
|
52
|
-
"%USERPROFILE%/.aws/**",
|
|
53
|
-
"%USERPROFILE%/.azure/**",
|
|
54
52
|
"%APPDATA%/gcloud/**",
|
|
55
|
-
"%USERPROFILE%/.kube/**",
|
|
56
|
-
"%USERPROFILE%/.ssh/**",
|
|
57
53
|
"%APPDATA%/Microsoft/Credentials/**",
|
|
58
|
-
"%LOCALAPPDATA%/Microsoft/Credentials/**",
|
|
59
54
|
"%APPDATA%/Microsoft/Crypto/**",
|
|
60
55
|
"%APPDATA%/Microsoft/Protect/**",
|
|
61
56
|
"%APPDATA%/Microsoft/SystemCertificates/**",
|
|
62
|
-
"%APPDATA%/
|
|
57
|
+
"%APPDATA%/Mozilla/Firefox/Profiles/**/cookies.sqlite",
|
|
58
|
+
"%APPDATA%/Mozilla/Firefox/Profiles/**/key*.db",
|
|
59
|
+
"%APPDATA%/Mozilla/Firefox/Profiles/**/logins.json",
|
|
63
60
|
"%APPDATA%/PuTTY/sessions/**",
|
|
61
|
+
"%APPDATA%/PuTTY/sshhostkeys",
|
|
64
62
|
"%LOCALAPPDATA%/Google/Chrome/User Data/**/Cookies*",
|
|
65
63
|
"%LOCALAPPDATA%/Google/Chrome/User Data/**/Login Data*",
|
|
64
|
+
"%LOCALAPPDATA%/Microsoft/Credentials/**",
|
|
66
65
|
"%LOCALAPPDATA%/Microsoft/Edge/User Data/**/Cookies*",
|
|
67
|
-
"%
|
|
68
|
-
"%
|
|
69
|
-
"%
|
|
66
|
+
"%USERPROFILE%/.aws/**",
|
|
67
|
+
"%USERPROFILE%/.azure/**",
|
|
68
|
+
"%USERPROFILE%/.kube/**",
|
|
69
|
+
"%USERPROFILE%/.ssh/**"
|
|
70
70
|
]
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/serve.ts
CHANGED
|
@@ -74,7 +74,7 @@ export const NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
|
74
74
|
* `serve <name>` ambiguous with a future aggregate form, and is why
|
|
75
75
|
* `--list` is a flag rather than a `serve list` child.
|
|
76
76
|
*/
|
|
77
|
-
export const RESERVED_NAMES: readonly string[] = ['all', '
|
|
77
|
+
export const RESERVED_NAMES: readonly string[] = ['all', 'list', 'none'];
|
|
78
78
|
|
|
79
79
|
/** Reports whether `name` is one of the reserved selector words. */
|
|
80
80
|
export function isReservedName(name: string): boolean {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# telemetry
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
What a TS adopter needs before emitting usage telemetry: the mode gate (`off`, `anon`, `full`), the anonymous rotatable install id, the consent reader, the redactor, and a non-blocking `Client` with jsonl and https sinks. Default-denied: a fresh install never emits. Wrong module for Factor 11 provenance metadata on payloads (`@hop-top/kit/provenance`) and for the compliance checker (`@hop-top/kit/compliance`).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- record an event: `new Client(opts)`, `client.record(event, attrs)`, `await client.shutdown(ms)`
|
|
10
|
+
- know which tier applies: `resolveMode(process.env)`
|
|
11
|
+
- read or rotate the install id: `getInstallId()`, `rotate()`
|
|
12
|
+
- check the operator's decision: `loadConsent()`
|
|
13
|
+
- scrub before your own sink: `redact(value)`, `redactString(s)`
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Client } from '@hop-top/kit/telemetry';
|
|
19
|
+
|
|
20
|
+
const client = new Client({ sink: 'jsonl', sinkFile: '/tmp/kit-events.jsonl', sdkVersion: '0.0.0' });
|
|
21
|
+
client.record('cmd.invoked', { command: 'launch', exit_code: 0 });
|
|
22
|
+
await client.shutdown(5_000);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`record` is a no-op until consent is granted and `KIT_TELEMETRY_MODE` is `anon` or `full`.
|
|
26
|
+
|
|
27
|
+
## Contract
|
|
28
|
+
|
|
29
|
+
- Envelope shape is [`sdk/docs/telemetry-event-schema.md`](../../../docs/telemetry-event-schema.md); keys are wire snake_case.
|
|
30
|
+
- `record` returns synchronously and never throws; the queue is bounded and drops count.
|
|
31
|
+
- Consent and mode are consulted on each `record`, so a live consent flip takes effect without restart.
|
|
32
|
+
- Redactor placeholders are `<redacted:email>`, `<redacted:ipv4>`, `<redacted:ipv6>`, `<redacted:token>`, and `$HOME` for home-path prefixes.
|
|
33
|
+
- The envelope carries a free-form `event` plus `attrs` where Go carries `CommandPath`; this is a documented divergence.
|
|
34
|
+
- Parity: [`sdk/tests/cross-lang/expected/envelope.json`](../../../tests/cross-lang/expected/envelope.json), driven by `sdk/tests/cross-lang/run.sh` from [`fixtures/consent.yaml`](../../../tests/cross-lang/fixtures/consent.yaml) and [`fixtures/install_id.bytes`](../../../tests/cross-lang/fixtures/install_id.bytes).
|
|
35
|
+
|
|
36
|
+
## Neighbours
|
|
37
|
+
|
|
38
|
+
- `@hop-top/kit/provenance`: `_meta` on output payloads
|
|
39
|
+
- `@hop-top/kit/compliance`: 12-factor checks, including the telemetry consent factor
|
|
40
|
+
- `@hop-top/kit/xdg`: state and config paths the install id and consent file live under
|
|
41
|
+
- Go reference: [`go/runtime/telemetry`](../../../../go/runtime/telemetry/README.md); Python port: [`hop_top_kit/telemetry`](../../../py/hop_top_kit/telemetry/README.md)
|
|
42
|
+
|
|
43
|
+
## See also
|
|
44
|
+
|
|
45
|
+
- [`sdk/ts/README.md`](../../README.md), section "Telemetry": env vars, redactor, envelope
|
|
46
|
+
- [`docs/adopters/guides/telemetry.md`](../../../../docs/adopters/guides/telemetry.md)
|
|
47
|
+
- [`docs/adopters/reference/telemetry-compliance.md`](../../../../docs/adopters/reference/telemetry-compliance.md)
|
|
48
|
+
- [`sdk/tests/cross-lang/README.md`](../../../tests/cross-lang/README.md)
|
package/src/telemetry/client.ts
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
* a fail-closed posture.
|
|
19
19
|
* - **Default Mode is Off**: `resolveMode()` is consulted at the same
|
|
20
20
|
* gating step. Anything other than `anon` / `full` no-ops.
|
|
21
|
-
* - **Envelope shape**: matches the cross-language event
|
|
22
|
-
* for the common fields. NOTE:
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* - **Envelope shape**: matches the cross-language event schema
|
|
22
|
+
* for the common fields. NOTE: the TS+Py SDKs diverge from Go by
|
|
23
|
+
* carrying free-form `event` (string) + `attrs` (object) at the
|
|
24
|
+
* envelope root.
|
|
25
25
|
* - **install_id caching**: `getInstallId()` does file I/O; we resolve
|
|
26
26
|
* it lazily and cache the resolved promise.
|
|
27
27
|
*
|
|
@@ -69,7 +69,7 @@ const DEFAULT_QUEUE_SIZE = 1024;
|
|
|
69
69
|
const FLUSH_INTERVAL_MS = 5_000;
|
|
70
70
|
/** Threshold that triggers an early flush before the interval fires. */
|
|
71
71
|
const FLUSH_BATCH_TRIGGER = 64;
|
|
72
|
-
/** HTTPS connect timeout (
|
|
72
|
+
/** HTTPS connect timeout (telemetry must never block the caller). */
|
|
73
73
|
const HTTPS_CONNECT_TIMEOUT_MS = 5_000;
|
|
74
74
|
/** HTTPS overall timeout. */
|
|
75
75
|
const HTTPS_TOTAL_TIMEOUT_MS = 10_000;
|
package/src/toolspec.test.ts
CHANGED
|
@@ -27,8 +27,8 @@ describe("loadToolSpec", () => {
|
|
|
27
27
|
]);
|
|
28
28
|
expect(spec.stateIntrospection!.envVars).toEqual([
|
|
29
29
|
"SPACED_FORMAT",
|
|
30
|
-
"SPACED_LOG_LEVEL",
|
|
31
30
|
"SPACED_LOG_FORMAT",
|
|
31
|
+
"SPACED_LOG_LEVEL",
|
|
32
32
|
]);
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ describe("loadToolSpec", () => {
|
|
|
40
40
|
expect(launch).toBeDefined();
|
|
41
41
|
expect(launch!.intent?.domain).toBe("space");
|
|
42
42
|
expect(launch!.intent?.category).toBe("operations");
|
|
43
|
-
expect(launch!.intent?.tags).toEqual(["
|
|
43
|
+
expect(launch!.intent?.tags).toEqual(["launch", "mission"]);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it("loads contract fields", () => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# triton
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
How to call a model hosted on Triton Inference Server over HTTP with the KServe v2 protocol, including `triton://host:port/model[/version]` URI parsing. Wrong module for chat-style LLM calls (`@hop-top/kit/llm`) and for routing decisions ([`../router`](../router/README.md)).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- parse a configured endpoint: `parseTritonURI(uri)` returns `{ host, port, modelName, modelVersion }`
|
|
10
|
+
- run inference: `new TritonClient(...)` implementing `TritonScorer`
|
|
11
|
+
- liveness: `ServerHealth`
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { parseTritonURI } from './client';
|
|
17
|
+
|
|
18
|
+
console.log(parseTritonURI('triton://localhost:8000/bert_router'));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contract
|
|
22
|
+
|
|
23
|
+
- Request and response bodies are the KServe v2 `InferRequest` / `InferResponse` shapes; tensor `datatype` is one of `TritonDataType`.
|
|
24
|
+
- Failures raise `TritonError`.
|
|
25
|
+
- Not on the package exports map and not in the `tsup` build: reachable only by relative import inside `src/`.
|
|
26
|
+
|
|
27
|
+
## Neighbours
|
|
28
|
+
|
|
29
|
+
- [`../router/bert.ts`](../router/bert.ts): the consumer, through the `TritonInfer` interface
|
|
30
|
+
- `@hop-top/kit/llm`: provider clients for chat completions
|
|
31
|
+
|
|
32
|
+
## See also
|
|
33
|
+
|
|
34
|
+
- [KServe v2 inference protocol](https://kserve.github.io/website/modelserving/inference_api/)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# tui
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
How a TS CLI paints the same terminal widgets as a Go kit CLI: status lines, badges, pills, spinner, progress bar, gradient animation, confirm and list prompts, all themed from `@hop-top/kit/cli`'s `Theme`. Wrong module for structured output (`@hop-top/kit/output`) and for machine-readable progress events (`@hop-top/kit/progress`).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- prefixed status line: `status(theme, text, 'info' | 'success' | 'error' | 'warn')`
|
|
10
|
+
- inline label: `badge(theme, text)`, `pills(theme, items)`
|
|
11
|
+
- long-running step in a TTY: `spinner(theme)`, `progress(theme)`
|
|
12
|
+
- yes/no or pick-one prompt: `confirm(theme, ...)`, `list(theme, ...)`
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { buildTheme } from '@hop-top/kit/cli';
|
|
18
|
+
import { status, badge } from '@hop-top/kit/tui';
|
|
19
|
+
|
|
20
|
+
const theme = buildTheme();
|
|
21
|
+
console.log(status(theme, 'Deployed', 'success'));
|
|
22
|
+
console.log(badge(theme, 'beta'));
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contract
|
|
26
|
+
|
|
27
|
+
- Status symbols, spinner frames and interval, and animation runes come from [`contracts/parity/parity.json`](../../../../contracts/parity/parity.json) through [`parity.ts`](parity.ts); never inline them.
|
|
28
|
+
- [`parity.test.ts`](parity.test.ts) is the block-registry guard: a block declared in the contract without a loader here fails.
|
|
29
|
+
- Every renderer takes `Theme` as its first argument; there is no module-level default theme.
|
|
30
|
+
- Parity: [`contracts/parity/README.md`](../../../../contracts/parity/README.md), table "Declared blocks", rows `status`, `spinner`, `anim`.
|
|
31
|
+
|
|
32
|
+
## Neighbours
|
|
33
|
+
|
|
34
|
+
- `@hop-top/kit/cli`: `Theme`, `buildTheme`, help layout
|
|
35
|
+
- `@hop-top/kit/output`: tables and structured formats
|
|
36
|
+
- `@hop-top/kit/progress`: JSON progress events for non-TTY consumers
|
|
37
|
+
- Go reference: [`go/console/tui`](../../../../go/console/tui/README.md); Python port: [`hop_top_kit/tui`](../../../py/hop_top_kit/tui/README.md)
|
|
38
|
+
|
|
39
|
+
## See also
|
|
40
|
+
|
|
41
|
+
- [`docs/adopters/guides/tui-component-gallery.md`](../../../../docs/adopters/guides/tui-component-gallery.md)
|
|
42
|
+
- [`docs/adopters/guides/cli-parity-guide.md`](../../../../docs/adopters/guides/cli-parity-guide.md)
|
package/src/wizard.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
resultBool,
|
|
17
17
|
resultStrings,
|
|
18
18
|
resultChoice,
|
|
19
|
-
|
|
19
|
+
Step,
|
|
20
20
|
} from "./wizard";
|
|
21
21
|
|
|
22
22
|
// --- construction ---
|
|
@@ -39,11 +39,11 @@ describe("Wizard construction", () => {
|
|
|
39
39
|
it("rejects empty key", () => {
|
|
40
40
|
expect(
|
|
41
41
|
() =>
|
|
42
|
-
new Wizard({
|
|
42
|
+
new Wizard(new Step({
|
|
43
43
|
key: "",
|
|
44
44
|
kind: StepKind.TextInput,
|
|
45
45
|
label: "Name",
|
|
46
|
-
}
|
|
46
|
+
})),
|
|
47
47
|
).toThrow(/key must not be empty/i);
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -56,23 +56,23 @@ describe("Wizard construction", () => {
|
|
|
56
56
|
it("rejects action without fn", () => {
|
|
57
57
|
expect(
|
|
58
58
|
() =>
|
|
59
|
-
new Wizard({
|
|
59
|
+
new Wizard(new Step({
|
|
60
60
|
key: "act",
|
|
61
61
|
kind: StepKind.Action,
|
|
62
62
|
label: "do",
|
|
63
|
-
}
|
|
63
|
+
})),
|
|
64
64
|
).toThrow(/actionFn/i);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it("rejects select without options", () => {
|
|
68
68
|
expect(
|
|
69
69
|
() =>
|
|
70
|
-
new Wizard({
|
|
70
|
+
new Wizard(new Step({
|
|
71
71
|
key: "sel",
|
|
72
72
|
kind: StepKind.Select,
|
|
73
73
|
label: "pick",
|
|
74
74
|
options: [],
|
|
75
|
-
}
|
|
75
|
+
})),
|
|
76
76
|
).toThrow(/options/i);
|
|
77
77
|
});
|
|
78
78
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the llm-v1 conformance runners: the vector file,
|
|
3
|
+
* a loopback HTTP server and env isolation. Test-only.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
+
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
|
|
10
|
+
import type { AddressInfo } from "node:net";
|
|
11
|
+
import { dirname, resolve } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
/** Loads contracts/llm-v1/vectors.json from the repo. */
|
|
15
|
+
export function loadVectors<T>(): T {
|
|
16
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
for (let i = 0; i < 10; i++) {
|
|
18
|
+
const p = resolve(dir, "contracts/llm-v1/vectors.json");
|
|
19
|
+
if (existsSync(p)) return JSON.parse(readFileSync(p, "utf8")) as T;
|
|
20
|
+
dir = dirname(dir);
|
|
21
|
+
}
|
|
22
|
+
throw new Error("contracts/llm-v1/vectors.json not found");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Hit {
|
|
26
|
+
method: string;
|
|
27
|
+
url: string;
|
|
28
|
+
headers: IncomingMessage["headers"];
|
|
29
|
+
body: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FakeServer {
|
|
33
|
+
url: string;
|
|
34
|
+
hits: Hit[];
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A loopback server answering every request with `handler`. */
|
|
39
|
+
export async function fakeServer(
|
|
40
|
+
handler: (hit: Hit, res: ServerResponse, n: number) => void
|
|
41
|
+
): Promise<FakeServer> {
|
|
42
|
+
const hits: Hit[] = [];
|
|
43
|
+
const srv = createServer((req, res) => {
|
|
44
|
+
const chunks: Buffer[] = [];
|
|
45
|
+
req.on("data", (c: Buffer) => chunks.push(c));
|
|
46
|
+
req.on("end", () => {
|
|
47
|
+
const hit: Hit = {
|
|
48
|
+
method: req.method ?? "",
|
|
49
|
+
url: req.url ?? "",
|
|
50
|
+
headers: req.headers,
|
|
51
|
+
body: Buffer.concat(chunks).toString("utf8"),
|
|
52
|
+
};
|
|
53
|
+
hits.push(hit);
|
|
54
|
+
handler(hit, res, hits.length - 1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
await new Promise<void>((r) => srv.listen(0, "127.0.0.1", r));
|
|
58
|
+
const { port } = srv.address() as AddressInfo;
|
|
59
|
+
return {
|
|
60
|
+
url: `http://127.0.0.1:${port}`,
|
|
61
|
+
hits,
|
|
62
|
+
close: () =>
|
|
63
|
+
new Promise<void>((r) => {
|
|
64
|
+
srv.closeAllConnections();
|
|
65
|
+
srv.close(() => r());
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Writes `body` with `contentType` and status 200. */
|
|
71
|
+
export function reply(res: ServerResponse, contentType: string, body: string, status = 200): void {
|
|
72
|
+
res.writeHead(status, { "content-type": contentType });
|
|
73
|
+
res.end(body);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Env vars a runner clears before each vector and restores after. */
|
|
77
|
+
export const LLM_ENV = [
|
|
78
|
+
"ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_BASE_URL",
|
|
79
|
+
"ANTHROPIC_WORKSPACE_ID", "LLM_BASE_URL", "LLM_API_KEY", "LLM_PROVIDER",
|
|
80
|
+
"LLM_FALLBACK", "OPENAI_API_KEY", "ROUTELLM_BASE_URL",
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
/** Snapshots `keys`, clears them, and returns a restore function. */
|
|
84
|
+
export function isolateEnv(keys: string[] = LLM_ENV): () => void {
|
|
85
|
+
const saved = new Map(keys.map((k) => [k, process.env[k]]));
|
|
86
|
+
for (const k of keys) delete process.env[k];
|
|
87
|
+
return () => {
|
|
88
|
+
for (const [k, v] of saved) {
|
|
89
|
+
if (v === undefined) delete process.env[k];
|
|
90
|
+
else process.env[k] = v;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Fails on any key of `obj` outside `allowed`: vectors are strict. */
|
|
96
|
+
export function strictKeys(obj: object, allowed: string[], where: string): void {
|
|
97
|
+
for (const k of Object.keys(obj)) {
|
|
98
|
+
if (!allowed.includes(k)) throw new Error(`${where}: unknown field ${JSON.stringify(k)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -23,7 +23,6 @@ function makeProgram(argv: readonly string[]) {
|
|
|
23
23
|
|
|
24
24
|
function captureStdout(): { restore: () => void; out: () => string } {
|
|
25
25
|
const chunks: Buffer[] = [];
|
|
26
|
-
const original = process.stdout.write.bind(process.stdout);
|
|
27
26
|
const spy = vi.spyOn(process.stdout, 'write').mockImplementation(
|
|
28
27
|
((c: string | Buffer) => {
|
|
29
28
|
chunks.push(Buffer.isBuffer(c) ? c : Buffer.from(c));
|
|
@@ -31,7 +30,7 @@ function captureStdout(): { restore: () => void; out: () => string } {
|
|
|
31
30
|
}) as typeof process.stdout.write,
|
|
32
31
|
);
|
|
33
32
|
return {
|
|
34
|
-
restore: () => spy.mockRestore()
|
|
33
|
+
restore: () => spy.mockRestore(),
|
|
35
34
|
out: () => Buffer.concat(chunks).toString(),
|
|
36
35
|
};
|
|
37
36
|
}
|
|
@@ -2,14 +2,18 @@ import { describe, it, expect } from 'vitest';
|
|
|
2
2
|
import * as yaml from 'js-yaml';
|
|
3
3
|
import {
|
|
4
4
|
CODE_CONFLICT,
|
|
5
|
+
CODE_CONSENT_REFUSED,
|
|
5
6
|
CODE_GENERIC,
|
|
6
7
|
CODE_NOT_FOUND,
|
|
8
|
+
CODE_PREREQUISITE,
|
|
7
9
|
CODE_PROVENANCE_MISSING,
|
|
8
10
|
CODE_RATE_LIMITED,
|
|
9
11
|
CODE_TRANSIENT,
|
|
10
12
|
CODE_UNAUTHORIZED,
|
|
11
13
|
CODE_USAGE,
|
|
14
|
+
EXIT_CONSENT_REFUSED,
|
|
12
15
|
EXIT_GENERIC,
|
|
16
|
+
EXIT_PREREQUISITE,
|
|
13
17
|
EXIT_PROVENANCE_MISSING,
|
|
14
18
|
EXIT_RATE_LIMITED,
|
|
15
19
|
EXIT_TRANSIENT,
|
|
@@ -17,8 +21,10 @@ import {
|
|
|
17
21
|
TRANSIENCE_TRANSIENT,
|
|
18
22
|
TRANSIENCE_UNKNOWN,
|
|
19
23
|
conflictError,
|
|
24
|
+
consentRefusedError,
|
|
20
25
|
genericError,
|
|
21
26
|
notFoundError,
|
|
27
|
+
prerequisiteError,
|
|
22
28
|
provenanceMissingError,
|
|
23
29
|
rateLimitedError,
|
|
24
30
|
renderError,
|
|
@@ -77,6 +83,20 @@ describe('constructors — code/exit/transience', () => {
|
|
|
77
83
|
65,
|
|
78
84
|
TRANSIENCE_PERMANENT,
|
|
79
85
|
],
|
|
86
|
+
[
|
|
87
|
+
'ConsentRefused',
|
|
88
|
+
consentRefusedError('declined'),
|
|
89
|
+
CODE_CONSENT_REFUSED,
|
|
90
|
+
7,
|
|
91
|
+
TRANSIENCE_TRANSIENT,
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
'Prerequisite',
|
|
95
|
+
prerequisiteError('no listener'),
|
|
96
|
+
CODE_PREREQUISITE,
|
|
97
|
+
70,
|
|
98
|
+
TRANSIENCE_TRANSIENT,
|
|
99
|
+
],
|
|
80
100
|
];
|
|
81
101
|
it.each(cases)('%s', (_name, got, wantCode, wantExit, wantTransience) => {
|
|
82
102
|
expect(got.code).toBe(wantCode);
|
|
@@ -84,16 +104,25 @@ describe('constructors — code/exit/transience', () => {
|
|
|
84
104
|
expect(got.transience).toBe(wantTransience);
|
|
85
105
|
});
|
|
86
106
|
|
|
87
|
-
|
|
107
|
+
// Mirrors Go's envelope exit-code table: the 0-6 core taxonomy plus
|
|
108
|
+
// CONSENT_REFUSED 7 and the kit extension band 64/65/70. Uniqueness
|
|
109
|
+
// pins the taxonomy; the per-number assertions pin which class owns
|
|
110
|
+
// which slot, so a port that adds a class at a number Go already
|
|
111
|
+
// spent fails here rather than on a user's machine.
|
|
112
|
+
it('exit-code table is unique and every slot is owned by its Go class', () => {
|
|
88
113
|
const exits = new Map(cases.map(([, e]) => [e.exit_code, e.code]));
|
|
89
|
-
expect(exits.size).toBe(
|
|
114
|
+
expect(exits.size).toBe(10);
|
|
90
115
|
expect(EXIT_GENERIC).toBe(1);
|
|
91
116
|
expect(EXIT_TRANSIENT).toBe(6);
|
|
117
|
+
expect(EXIT_CONSENT_REFUSED).toBe(7);
|
|
92
118
|
expect(EXIT_RATE_LIMITED).toBe(64);
|
|
93
119
|
expect(EXIT_PROVENANCE_MISSING).toBe(65);
|
|
120
|
+
expect(EXIT_PREREQUISITE).toBe(70);
|
|
94
121
|
expect(exits.get(1)).toBe(CODE_GENERIC);
|
|
95
122
|
expect(exits.get(6)).toBe(CODE_TRANSIENT);
|
|
123
|
+
expect(exits.get(7)).toBe(CODE_CONSENT_REFUSED);
|
|
96
124
|
expect(exits.get(65)).toBe(CODE_PROVENANCE_MISSING);
|
|
125
|
+
expect(exits.get(70)).toBe(CODE_PREREQUISITE);
|
|
97
126
|
});
|
|
98
127
|
});
|
|
99
128
|
|
|
@@ -106,6 +135,8 @@ describe('transienceForCode', () => {
|
|
|
106
135
|
[CODE_PROVENANCE_MISSING, TRANSIENCE_PERMANENT],
|
|
107
136
|
[CODE_RATE_LIMITED, TRANSIENCE_TRANSIENT],
|
|
108
137
|
[CODE_TRANSIENT, TRANSIENCE_TRANSIENT],
|
|
138
|
+
[CODE_CONSENT_REFUSED, TRANSIENCE_TRANSIENT],
|
|
139
|
+
[CODE_PREREQUISITE, TRANSIENCE_TRANSIENT],
|
|
109
140
|
[CODE_GENERIC, TRANSIENCE_UNKNOWN],
|
|
110
141
|
['ADOPTER_SPECIFIC', TRANSIENCE_UNKNOWN],
|
|
111
142
|
['', TRANSIENCE_UNKNOWN],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Captures verbatim output for each smoke command
|
|
3
|
-
*
|
|
2
|
+
* Captures verbatim output for each smoke command so a report can
|
|
3
|
+
* include real-world output samples. Run with:
|
|
4
4
|
*
|
|
5
5
|
* pnpm exec tsx test/output/smoke-capture.ts
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Smoke tests mirroring
|
|
2
|
+
* Smoke tests mirroring the manual checklist. Each test exercises a
|
|
3
3
|
* dispatch path end-to-end against an in-memory writer or temp file so the
|
|
4
4
|
* suite is hermetic but covers the same surface a real `cli list` invocation
|
|
5
5
|
* would.
|
|
@@ -44,7 +44,7 @@ const rows = [
|
|
|
44
44
|
{ id: '2', name: 'Bob', status: 'idle' },
|
|
45
45
|
];
|
|
46
46
|
|
|
47
|
-
describe('smoke —
|
|
47
|
+
describe('smoke — checklist', () => {
|
|
48
48
|
it('cli list (default table)', async () => {
|
|
49
49
|
const program = makeProgram([]);
|
|
50
50
|
const cap = captureStdout();
|