@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,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic adapter beyond the llm-v1 vectors: registry resolution and
|
|
3
|
+
* key sources, the endpoint gate, and a tool round with thinking
|
|
4
|
+
* replayed through the outcome.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
8
|
+
|
|
9
|
+
import { KeyEndpointError, LLMError, createLLM, resolve, type Token } from "./llm";
|
|
10
|
+
import { AnthropicAdapter } from "./llm-anthropic";
|
|
11
|
+
import {
|
|
12
|
+
fakeServer,
|
|
13
|
+
isolateEnv,
|
|
14
|
+
reply,
|
|
15
|
+
type FakeServer,
|
|
16
|
+
} from "../test/llm/conformance-helpers";
|
|
17
|
+
|
|
18
|
+
let restoreEnv: () => void;
|
|
19
|
+
const servers: FakeServer[] = [];
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
restoreEnv = isolateEnv();
|
|
22
|
+
});
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
restoreEnv();
|
|
25
|
+
await Promise.all(servers.splice(0).map((s) => s.close()));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
async function server(handler: Parameters<typeof fakeServer>[0]): Promise<FakeServer> {
|
|
29
|
+
const s = await fakeServer(handler);
|
|
30
|
+
servers.push(s);
|
|
31
|
+
return s;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const OK = JSON.stringify({
|
|
35
|
+
type: "message",
|
|
36
|
+
role: "assistant",
|
|
37
|
+
content: [{ type: "text", text: "ok" }],
|
|
38
|
+
stop_reason: "end_turn",
|
|
39
|
+
usage: { input_tokens: 1, output_tokens: 1 },
|
|
40
|
+
});
|
|
41
|
+
const HI = [{ role: "user", content: "Hi" }];
|
|
42
|
+
|
|
43
|
+
describe("anthropic registry", () => {
|
|
44
|
+
it("resolves anthropic:// with ANTHROPIC_API_KEY to a trusted base", async () => {
|
|
45
|
+
const s = await server((_h, res) => reply(res, "application/json", OK));
|
|
46
|
+
process.env["ANTHROPIC_API_KEY"] = "env-key";
|
|
47
|
+
process.env["ANTHROPIC_BASE_URL"] = s.url;
|
|
48
|
+
const r = await resolve("anthropic://claude-x").complete!({ messages: HI });
|
|
49
|
+
expect(r.content).toBe("ok");
|
|
50
|
+
expect(s.hits[0]!.url).toBe("/v1/messages");
|
|
51
|
+
expect(s.hits[0]!.headers["x-api-key"]).toBe("env-key");
|
|
52
|
+
expect(JSON.parse(s.hits[0]!.body).model).toBe("claude-x");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("keeps an env key off an endpoint only the URI names", () => {
|
|
56
|
+
process.env["ANTHROPIC_API_KEY"] = "env-key";
|
|
57
|
+
expect(() => resolve("anthropic://m?base_url=https://evil.example.test")).toThrow(
|
|
58
|
+
KeyEndpointError
|
|
59
|
+
);
|
|
60
|
+
expect(() =>
|
|
61
|
+
resolve("anthropic://m?base_url=https://gw.example.test&api_key=uri-key")
|
|
62
|
+
).not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("requires a key and a parseable base URL", () => {
|
|
66
|
+
expect(() => resolve("anthropic://m")).toThrow(/API key required/);
|
|
67
|
+
expect(
|
|
68
|
+
() =>
|
|
69
|
+
new AnthropicAdapter({
|
|
70
|
+
uri: { scheme: "anthropic", model: "m" },
|
|
71
|
+
provider: { model: "m", apiKey: "k", baseURL: "::nope?api_key=secret-value" },
|
|
72
|
+
fallbacks: [],
|
|
73
|
+
})
|
|
74
|
+
).toThrow(LLMError);
|
|
75
|
+
try {
|
|
76
|
+
new AnthropicAdapter({
|
|
77
|
+
uri: { scheme: "anthropic", model: "m" },
|
|
78
|
+
provider: { model: "m", apiKey: "k", baseURL: "::nope?api_key=secret-value" },
|
|
79
|
+
fallbacks: [],
|
|
80
|
+
});
|
|
81
|
+
} catch (e) {
|
|
82
|
+
expect((e as Error).message).not.toContain("secret-value");
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("refuses the key over plain http to a remote host", () => {
|
|
87
|
+
process.env["ANTHROPIC_API_KEY"] = "env-key";
|
|
88
|
+
process.env["ANTHROPIC_BASE_URL"] = "http://gw.example.test";
|
|
89
|
+
expect(() => resolve("anthropic://m")).toThrow(KeyEndpointError);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("refuses an unknown tool_names mode at construction", () => {
|
|
93
|
+
process.env["ANTHROPIC_API_KEY"] = "env-key";
|
|
94
|
+
expect(() => resolve("anthropic://m?tool_names=loose")).toThrow(/tool_names/);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("anthropic tool round", () => {
|
|
99
|
+
it("streams thinking, then replays the outcome in the next turn", async () => {
|
|
100
|
+
const events = [
|
|
101
|
+
{ type: "message_start", message: { content: [], usage: { input_tokens: 3, output_tokens: 0 } } },
|
|
102
|
+
{ type: "content_block_start", index: 0, content_block: { type: "thinking", thinking: "", signature: "" } },
|
|
103
|
+
{ type: "content_block_delta", index: 0, delta: { type: "thinking_delta", thinking: "hmm" } },
|
|
104
|
+
{ type: "content_block_delta", index: 0, delta: { type: "signature_delta", signature: "sig" } },
|
|
105
|
+
{ type: "content_block_stop", index: 0 },
|
|
106
|
+
{ type: "content_block_start", index: 1, content_block: { type: "tool_use", id: "t1", name: "pane_open", input: {} } },
|
|
107
|
+
{ type: "content_block_delta", index: 1, delta: { type: "input_json_delta", partial_json: '{"id":' } },
|
|
108
|
+
{ type: "content_block_delta", index: 1, delta: { type: "input_json_delta", partial_json: "7}" } },
|
|
109
|
+
{ type: "content_block_stop", index: 1 },
|
|
110
|
+
{ type: "message_delta", delta: { stop_reason: "tool_use" }, usage: { output_tokens: 9 } },
|
|
111
|
+
{ type: "message_stop" },
|
|
112
|
+
];
|
|
113
|
+
const s = await server((_h, res, n) =>
|
|
114
|
+
n === 0
|
|
115
|
+
? reply(res, "text/event-stream", events.map((e) => `data: ${JSON.stringify(e)}\n\n`).join(""))
|
|
116
|
+
: reply(res, "application/json", OK)
|
|
117
|
+
);
|
|
118
|
+
process.env["ANTHROPIC_API_KEY"] = "k";
|
|
119
|
+
process.env["ANTHROPIC_BASE_URL"] = s.url;
|
|
120
|
+
const client = createLLM("anthropic://m");
|
|
121
|
+
const tools = [{ name: "pane.open", description: "", parameters: undefined }];
|
|
122
|
+
const req = { messages: HI, maxTokens: 4096, thinking: { budgetTokens: 2048 } };
|
|
123
|
+
const st = client.streamWithTools(req, tools);
|
|
124
|
+
const toks: Token[] = [];
|
|
125
|
+
for await (const t of st) toks.push(t);
|
|
126
|
+
expect(toks).toEqual([
|
|
127
|
+
{ content: "", thinking: "hmm", done: false },
|
|
128
|
+
{ content: "", done: true },
|
|
129
|
+
]);
|
|
130
|
+
const out = st.outcome()!;
|
|
131
|
+
expect(out.toolCalls).toEqual([{ id: "t1", name: "pane.open", arguments: { id: 7 } }]);
|
|
132
|
+
expect(out.thinking).toEqual([{ thinking: "hmm", signature: "sig", redacted: "" }]);
|
|
133
|
+
|
|
134
|
+
await client.callWithTools(
|
|
135
|
+
{
|
|
136
|
+
...req,
|
|
137
|
+
messages: [
|
|
138
|
+
...HI,
|
|
139
|
+
{ role: "assistant", content: out.content, toolCalls: out.toolCalls, thinking: out.thinking },
|
|
140
|
+
{ role: "tool", content: "opened", toolCallId: "t1" },
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
tools
|
|
144
|
+
);
|
|
145
|
+
const body = JSON.parse(s.hits[1]!.body);
|
|
146
|
+
expect(body.messages[1].content).toEqual([
|
|
147
|
+
{ type: "thinking", thinking: "hmm", signature: "sig" },
|
|
148
|
+
{ type: "tool_use", id: "t1", name: "pane_open", input: { id: 7 } },
|
|
149
|
+
]);
|
|
150
|
+
expect(body.tools[0].name).toBe("pane_open");
|
|
151
|
+
});
|
|
152
|
+
});
|