@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.
Files changed (130) hide show
  1. package/dist/chunk-56RA53VS.js +37 -0
  2. package/dist/chunk-CZJ75YTV.js +969 -0
  3. package/dist/chunk-QGM4M3NI.js +37 -0
  4. package/dist/http.cjs +1772 -0
  5. package/dist/http.d.cts +49 -0
  6. package/dist/http.d.ts +49 -0
  7. package/dist/http.js +748 -0
  8. package/dist/index.cjs +2436 -0
  9. package/dist/index.d.cts +436 -0
  10. package/dist/index.d.ts +436 -0
  11. package/dist/index.js +1434 -0
  12. package/dist/proxy-ClPcDgsO.d.cts +283 -0
  13. package/dist/proxy-qpda1ANS.d.ts +283 -0
  14. package/dist/proxy.cjs +148 -0
  15. package/dist/proxy.d.cts +6 -0
  16. package/dist/proxy.d.ts +6 -0
  17. package/dist/proxy.js +90 -0
  18. package/dist/testing.cjs +865 -0
  19. package/dist/testing.d.cts +12 -0
  20. package/dist/testing.d.ts +12 -0
  21. package/dist/testing.js +831 -0
  22. package/dist/tunnels-BviBEaih.d.cts +12 -0
  23. package/dist/tunnels-DFHNgmN7.d.ts +12 -0
  24. package/dist/types-C6JC9oTm.d.cts +21 -0
  25. package/dist/types-C6JC9oTm.d.ts +21 -0
  26. package/package.json +47 -0
  27. package/src/__tests__/sqlite-integration.test.ts +384 -0
  28. package/src/credential/d1-vault.ts +134 -0
  29. package/src/credential/memory-vault.ts +50 -0
  30. package/src/credential/types.ts +16 -0
  31. package/src/d1/__tests__/sqlite-adapter.test.ts +75 -0
  32. package/src/d1/sqlite-adapter.ts +59 -0
  33. package/src/d1/types.ts +22 -0
  34. package/src/federation/__tests__/d1-peer-store.test.ts +218 -0
  35. package/src/federation/__tests__/peer-client.test.ts +205 -0
  36. package/src/federation/__tests__/peer-store.test.ts +114 -0
  37. package/src/federation/d1-peer-store.ts +164 -0
  38. package/src/federation/peer-backend.ts +60 -0
  39. package/src/federation/peer-client.ts +122 -0
  40. package/src/federation/peer-store.ts +45 -0
  41. package/src/federation/types.ts +39 -0
  42. package/src/http/app.ts +152 -0
  43. package/src/http/lib/dns.ts +30 -0
  44. package/src/http/middleware/admin-auth.ts +18 -0
  45. package/src/http/middleware/agent-auth.ts +27 -0
  46. package/src/http/middleware/publish-auth.ts +39 -0
  47. package/src/http/routes/__tests__/federation.test.ts +364 -0
  48. package/src/http/routes/__tests__/peers.test.ts +290 -0
  49. package/src/http/routes/__tests__/proxy.test.ts +159 -0
  50. package/src/http/routes/auth.ts +39 -0
  51. package/src/http/routes/byok.ts +62 -0
  52. package/src/http/routes/credentials.ts +40 -0
  53. package/src/http/routes/domains.ts +174 -0
  54. package/src/http/routes/federation.ts +170 -0
  55. package/src/http/routes/fs.ts +89 -0
  56. package/src/http/routes/peers.ts +103 -0
  57. package/src/http/routes/proxy.ts +57 -0
  58. package/src/http/routes/registry.ts +222 -0
  59. package/src/http/routes/tunnels.ts +124 -0
  60. package/src/http.ts +9 -0
  61. package/src/index.ts +63 -0
  62. package/src/metering/d1-store.ts +123 -0
  63. package/src/metering/memory-store.ts +29 -0
  64. package/src/metering/pricing-guard.ts +68 -0
  65. package/src/metering/types.ts +25 -0
  66. package/src/onboard/apis-guru.ts +64 -0
  67. package/src/onboard/index.ts +4 -0
  68. package/src/onboard/manifest.ts +362 -0
  69. package/src/onboard/pipeline.ts +214 -0
  70. package/src/onboard/types.ts +72 -0
  71. package/src/proxy/__tests__/tool-registry.test.ts +93 -0
  72. package/src/proxy/tool-registry.ts +122 -0
  73. package/src/proxy.ts +12 -0
  74. package/src/registry/context7-backend.ts +93 -0
  75. package/src/registry/context7.ts +54 -0
  76. package/src/registry/d1-store.ts +242 -0
  77. package/src/registry/memory-store.ts +101 -0
  78. package/src/registry/openapi-compiler.ts +284 -0
  79. package/src/registry/resolver.ts +196 -0
  80. package/src/registry/rpc-compiler.ts +142 -0
  81. package/src/registry/skill-parser.ts +119 -0
  82. package/src/registry/skill-to-config.ts +239 -0
  83. package/src/registry/source-refresher.ts +83 -0
  84. package/src/registry/types.ts +129 -0
  85. package/src/registry/virtual-files.ts +76 -0
  86. package/src/testing/sqlite-d1.ts +64 -0
  87. package/src/testing.ts +2 -0
  88. package/src/tunnel/__tests__/cloudflare-provider.test.ts +255 -0
  89. package/src/tunnel/__tests__/tunnel.test.ts +542 -0
  90. package/src/tunnel/cloudflare-provider.ts +121 -0
  91. package/src/tunnel/memory-store.ts +30 -0
  92. package/src/tunnel/types.ts +28 -0
  93. package/test/credential/d1-vault.test.ts +127 -0
  94. package/test/credential/injection.test.ts +67 -0
  95. package/test/credential/memory-vault.test.ts +63 -0
  96. package/test/http/app.test.ts +300 -0
  97. package/test/http/byok-e2e.test.ts +240 -0
  98. package/test/http/byok.test.ts +115 -0
  99. package/test/http/credentials.test.ts +57 -0
  100. package/test/http/e2e.test.ts +260 -0
  101. package/test/integration/authenticated-apis.test.ts +185 -0
  102. package/test/integration/free-apis-e2e.test.ts +222 -0
  103. package/test/metering/d1-store.test.ts +82 -0
  104. package/test/metering/memory-store.test.ts +76 -0
  105. package/test/metering/pricing-guard.test.ts +108 -0
  106. package/test/onboard/apis-guru.test.ts +57 -0
  107. package/test/onboard/e2e.test.ts +70 -0
  108. package/test/onboard/pipeline.test.ts +318 -0
  109. package/test/onboard/real-apis.test.ts +483 -0
  110. package/test/registry/compilation-correctness.test.ts +132 -0
  111. package/test/registry/context7-backend.test.ts +88 -0
  112. package/test/registry/context7-e2e.test.ts +92 -0
  113. package/test/registry/context7.test.ts +73 -0
  114. package/test/registry/d1-store.test.ts +184 -0
  115. package/test/registry/integration.test.ts +129 -0
  116. package/test/registry/lazy-mount.test.ts +138 -0
  117. package/test/registry/memory-store.test.ts +171 -0
  118. package/test/registry/openapi-compiler.test.ts +267 -0
  119. package/test/registry/openapi-e2e.test.ts +154 -0
  120. package/test/registry/passthrough-e2e.test.ts +109 -0
  121. package/test/registry/resolver-peer.test.ts +299 -0
  122. package/test/registry/resolver.test.ts +228 -0
  123. package/test/registry/rpc-compiler.test.ts +112 -0
  124. package/test/registry/skill-parser.test.ts +151 -0
  125. package/test/registry/skill-to-config.test.ts +151 -0
  126. package/test/registry/skill-to-rpc-config.test.ts +142 -0
  127. package/test/registry/source-refresher.test.ts +90 -0
  128. package/test/registry/virtual-files.test.ts +96 -0
  129. package/tsconfig.json +4 -0
  130. package/tsup.config.ts +8 -0
@@ -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';
@@ -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
+ };