@nkmc/gateway 0.1.0
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/dist/chunk-56RA53VS.js +37 -0
- package/dist/chunk-CZJ75YTV.js +969 -0
- package/dist/chunk-QGM4M3NI.js +37 -0
- package/dist/http.cjs +1772 -0
- package/dist/http.d.cts +49 -0
- package/dist/http.d.ts +49 -0
- package/dist/http.js +748 -0
- package/dist/index.cjs +2436 -0
- package/dist/index.d.cts +436 -0
- package/dist/index.d.ts +436 -0
- package/dist/index.js +1434 -0
- package/dist/proxy-ClPcDgsO.d.cts +283 -0
- package/dist/proxy-qpda1ANS.d.ts +283 -0
- package/dist/proxy.cjs +148 -0
- package/dist/proxy.d.cts +6 -0
- package/dist/proxy.d.ts +6 -0
- package/dist/proxy.js +90 -0
- package/dist/testing.cjs +865 -0
- package/dist/testing.d.cts +12 -0
- package/dist/testing.d.ts +12 -0
- package/dist/testing.js +831 -0
- package/dist/tunnels-BviBEaih.d.cts +12 -0
- package/dist/tunnels-DFHNgmN7.d.ts +12 -0
- package/dist/types-C6JC9oTm.d.cts +21 -0
- package/dist/types-C6JC9oTm.d.ts +21 -0
- package/package.json +47 -0
- package/src/__tests__/sqlite-integration.test.ts +384 -0
- package/src/credential/d1-vault.ts +134 -0
- package/src/credential/memory-vault.ts +50 -0
- package/src/credential/types.ts +16 -0
- package/src/d1/__tests__/sqlite-adapter.test.ts +75 -0
- package/src/d1/sqlite-adapter.ts +59 -0
- package/src/d1/types.ts +22 -0
- package/src/federation/__tests__/d1-peer-store.test.ts +218 -0
- package/src/federation/__tests__/peer-client.test.ts +205 -0
- package/src/federation/__tests__/peer-store.test.ts +114 -0
- package/src/federation/d1-peer-store.ts +164 -0
- package/src/federation/peer-backend.ts +60 -0
- package/src/federation/peer-client.ts +122 -0
- package/src/federation/peer-store.ts +45 -0
- package/src/federation/types.ts +39 -0
- package/src/http/app.ts +152 -0
- package/src/http/lib/dns.ts +30 -0
- package/src/http/middleware/admin-auth.ts +18 -0
- package/src/http/middleware/agent-auth.ts +27 -0
- package/src/http/middleware/publish-auth.ts +39 -0
- package/src/http/routes/__tests__/federation.test.ts +364 -0
- package/src/http/routes/__tests__/peers.test.ts +290 -0
- package/src/http/routes/__tests__/proxy.test.ts +159 -0
- package/src/http/routes/auth.ts +39 -0
- package/src/http/routes/byok.ts +62 -0
- package/src/http/routes/credentials.ts +40 -0
- package/src/http/routes/domains.ts +174 -0
- package/src/http/routes/federation.ts +170 -0
- package/src/http/routes/fs.ts +89 -0
- package/src/http/routes/peers.ts +103 -0
- package/src/http/routes/proxy.ts +57 -0
- package/src/http/routes/registry.ts +222 -0
- package/src/http/routes/tunnels.ts +124 -0
- package/src/http.ts +9 -0
- package/src/index.ts +63 -0
- package/src/metering/d1-store.ts +123 -0
- package/src/metering/memory-store.ts +29 -0
- package/src/metering/pricing-guard.ts +68 -0
- package/src/metering/types.ts +25 -0
- package/src/onboard/apis-guru.ts +64 -0
- package/src/onboard/index.ts +4 -0
- package/src/onboard/manifest.ts +362 -0
- package/src/onboard/pipeline.ts +214 -0
- package/src/onboard/types.ts +72 -0
- package/src/proxy/__tests__/tool-registry.test.ts +93 -0
- package/src/proxy/tool-registry.ts +122 -0
- package/src/proxy.ts +12 -0
- package/src/registry/context7-backend.ts +93 -0
- package/src/registry/context7.ts +54 -0
- package/src/registry/d1-store.ts +242 -0
- package/src/registry/memory-store.ts +101 -0
- package/src/registry/openapi-compiler.ts +284 -0
- package/src/registry/resolver.ts +196 -0
- package/src/registry/rpc-compiler.ts +142 -0
- package/src/registry/skill-parser.ts +119 -0
- package/src/registry/skill-to-config.ts +239 -0
- package/src/registry/source-refresher.ts +83 -0
- package/src/registry/types.ts +129 -0
- package/src/registry/virtual-files.ts +76 -0
- package/src/testing/sqlite-d1.ts +64 -0
- package/src/testing.ts +2 -0
- package/src/tunnel/__tests__/cloudflare-provider.test.ts +255 -0
- package/src/tunnel/__tests__/tunnel.test.ts +542 -0
- package/src/tunnel/cloudflare-provider.ts +121 -0
- package/src/tunnel/memory-store.ts +30 -0
- package/src/tunnel/types.ts +28 -0
- package/test/credential/d1-vault.test.ts +127 -0
- package/test/credential/injection.test.ts +67 -0
- package/test/credential/memory-vault.test.ts +63 -0
- package/test/http/app.test.ts +300 -0
- package/test/http/byok-e2e.test.ts +240 -0
- package/test/http/byok.test.ts +115 -0
- package/test/http/credentials.test.ts +57 -0
- package/test/http/e2e.test.ts +260 -0
- package/test/integration/authenticated-apis.test.ts +185 -0
- package/test/integration/free-apis-e2e.test.ts +222 -0
- package/test/metering/d1-store.test.ts +82 -0
- package/test/metering/memory-store.test.ts +76 -0
- package/test/metering/pricing-guard.test.ts +108 -0
- package/test/onboard/apis-guru.test.ts +57 -0
- package/test/onboard/e2e.test.ts +70 -0
- package/test/onboard/pipeline.test.ts +318 -0
- package/test/onboard/real-apis.test.ts +483 -0
- package/test/registry/compilation-correctness.test.ts +132 -0
- package/test/registry/context7-backend.test.ts +88 -0
- package/test/registry/context7-e2e.test.ts +92 -0
- package/test/registry/context7.test.ts +73 -0
- package/test/registry/d1-store.test.ts +184 -0
- package/test/registry/integration.test.ts +129 -0
- package/test/registry/lazy-mount.test.ts +138 -0
- package/test/registry/memory-store.test.ts +171 -0
- package/test/registry/openapi-compiler.test.ts +267 -0
- package/test/registry/openapi-e2e.test.ts +154 -0
- package/test/registry/passthrough-e2e.test.ts +109 -0
- package/test/registry/resolver-peer.test.ts +299 -0
- package/test/registry/resolver.test.ts +228 -0
- package/test/registry/rpc-compiler.test.ts +112 -0
- package/test/registry/skill-parser.test.ts +151 -0
- package/test/registry/skill-to-config.test.ts +151 -0
- package/test/registry/skill-to-rpc-config.test.ts +142 -0
- package/test/registry/source-refresher.test.ts +90 -0
- package/test/registry/virtual-files.test.ts +96 -0
- package/tsconfig.json +4 -0
- package/tsup.config.ts +8 -0
package/dist/proxy.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { A as AuthField, o as ExecResult, p as ProxyRouteOptions, q as ToolDefinition, r as ToolRegistry, s as createDefaultToolRegistry, t as proxyRoutes } from './proxy-ClPcDgsO.cjs';
|
|
2
|
+
import '@nkmc/agent-fs';
|
|
3
|
+
import 'hono/types';
|
|
4
|
+
import 'hono';
|
|
5
|
+
import 'jose';
|
|
6
|
+
import './types-C6JC9oTm.cjs';
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { A as AuthField, o as ExecResult, p as ProxyRouteOptions, q as ToolDefinition, r as ToolRegistry, s as createDefaultToolRegistry, t as proxyRoutes } from './proxy-qpda1ANS.js';
|
|
2
|
+
import '@nkmc/agent-fs';
|
|
3
|
+
import 'hono/types';
|
|
4
|
+
import 'hono';
|
|
5
|
+
import 'jose';
|
|
6
|
+
import './types-C6JC9oTm.js';
|
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
proxyRoutes
|
|
3
|
+
} from "./chunk-56RA53VS.js";
|
|
4
|
+
import "./chunk-QGM4M3NI.js";
|
|
5
|
+
|
|
6
|
+
// src/proxy/tool-registry.ts
|
|
7
|
+
var ToolRegistry = class {
|
|
8
|
+
tools = /* @__PURE__ */ new Map();
|
|
9
|
+
/** Register a tool definition. Overwrites any existing entry with the same name. */
|
|
10
|
+
register(tool) {
|
|
11
|
+
this.tools.set(tool.name, tool);
|
|
12
|
+
}
|
|
13
|
+
/** Look up a tool by name. Returns null if not found. */
|
|
14
|
+
get(name) {
|
|
15
|
+
return this.tools.get(name) ?? null;
|
|
16
|
+
}
|
|
17
|
+
/** Return all registered tool definitions. */
|
|
18
|
+
list() {
|
|
19
|
+
return [...this.tools.values()];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build a record of environment variables for the given tool by
|
|
23
|
+
* extracting the requested fields from the HttpAuth credential.
|
|
24
|
+
*
|
|
25
|
+
* If the auth type does not contain the requested field (e.g.
|
|
26
|
+
* requesting "token" from a basic-auth credential), that env var
|
|
27
|
+
* is silently omitted.
|
|
28
|
+
*/
|
|
29
|
+
buildEnv(tool, auth) {
|
|
30
|
+
const env = {};
|
|
31
|
+
for (const [envVar, field] of Object.entries(tool.envMapping)) {
|
|
32
|
+
const value = extractField(auth, field);
|
|
33
|
+
if (value !== void 0) {
|
|
34
|
+
env[envVar] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return env;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function extractField(auth, field) {
|
|
41
|
+
switch (field) {
|
|
42
|
+
case "token":
|
|
43
|
+
return auth.type === "bearer" ? auth.token : void 0;
|
|
44
|
+
case "key":
|
|
45
|
+
return auth.type === "api-key" ? auth.key : void 0;
|
|
46
|
+
case "username":
|
|
47
|
+
return auth.type === "basic" ? auth.username : void 0;
|
|
48
|
+
case "password":
|
|
49
|
+
return auth.type === "basic" ? auth.password : void 0;
|
|
50
|
+
default:
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function createDefaultToolRegistry() {
|
|
55
|
+
const registry = new ToolRegistry();
|
|
56
|
+
registry.register({
|
|
57
|
+
name: "gh",
|
|
58
|
+
credentialDomain: "github.com",
|
|
59
|
+
envMapping: { GH_TOKEN: "token" }
|
|
60
|
+
});
|
|
61
|
+
registry.register({
|
|
62
|
+
name: "stripe",
|
|
63
|
+
credentialDomain: "api.stripe.com",
|
|
64
|
+
envMapping: { STRIPE_API_KEY: "key" }
|
|
65
|
+
});
|
|
66
|
+
registry.register({
|
|
67
|
+
name: "openai",
|
|
68
|
+
credentialDomain: "api.openai.com",
|
|
69
|
+
envMapping: { OPENAI_API_KEY: "key" }
|
|
70
|
+
});
|
|
71
|
+
registry.register({
|
|
72
|
+
name: "anthropic",
|
|
73
|
+
credentialDomain: "api.anthropic.com",
|
|
74
|
+
envMapping: { ANTHROPIC_API_KEY: "key" }
|
|
75
|
+
});
|
|
76
|
+
registry.register({
|
|
77
|
+
name: "aws",
|
|
78
|
+
credentialDomain: "aws.amazon.com",
|
|
79
|
+
envMapping: {
|
|
80
|
+
AWS_ACCESS_KEY_ID: "username",
|
|
81
|
+
AWS_SECRET_ACCESS_KEY: "password"
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return registry;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
ToolRegistry,
|
|
88
|
+
createDefaultToolRegistry,
|
|
89
|
+
proxyRoutes
|
|
90
|
+
};
|