hono-apcore 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 (139) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +426 -0
  3. package/dist/a2a/apcore-a2a.service.d.ts +44 -0
  4. package/dist/a2a/apcore-a2a.service.d.ts.map +1 -0
  5. package/dist/a2a/apcore-a2a.service.js +82 -0
  6. package/dist/a2a/apcore-a2a.service.js.map +1 -0
  7. package/dist/a2a/index.d.ts +2 -0
  8. package/dist/a2a/index.d.ts.map +1 -0
  9. package/dist/a2a/index.js +2 -0
  10. package/dist/a2a/index.js.map +1 -0
  11. package/dist/bridge/binding-loader.d.ts +45 -0
  12. package/dist/bridge/binding-loader.d.ts.map +1 -0
  13. package/dist/bridge/binding-loader.js +84 -0
  14. package/dist/bridge/binding-loader.js.map +1 -0
  15. package/dist/bridge/index.d.ts +3 -0
  16. package/dist/bridge/index.d.ts.map +1 -0
  17. package/dist/bridge/index.js +2 -0
  18. package/dist/bridge/index.js.map +1 -0
  19. package/dist/cli/apcore-cli.service.d.ts +50 -0
  20. package/dist/cli/apcore-cli.service.d.ts.map +1 -0
  21. package/dist/cli/apcore-cli.service.js +76 -0
  22. package/dist/cli/apcore-cli.service.js.map +1 -0
  23. package/dist/cli/index.d.ts +2 -0
  24. package/dist/cli/index.d.ts.map +1 -0
  25. package/dist/cli/index.js +2 -0
  26. package/dist/cli/index.js.map +1 -0
  27. package/dist/cli.d.ts +4 -0
  28. package/dist/cli.d.ts.map +1 -0
  29. package/dist/cli.js +247 -0
  30. package/dist/cli.js.map +1 -0
  31. package/dist/config.d.ts +55 -0
  32. package/dist/config.d.ts.map +1 -0
  33. package/dist/config.js +86 -0
  34. package/dist/config.js.map +1 -0
  35. package/dist/constants.d.ts +27 -0
  36. package/dist/constants.d.ts.map +1 -0
  37. package/dist/constants.js +27 -0
  38. package/dist/constants.js.map +1 -0
  39. package/dist/context/hono-context.factory.d.ts +61 -0
  40. package/dist/context/hono-context.factory.d.ts.map +1 -0
  41. package/dist/context/hono-context.factory.js +117 -0
  42. package/dist/context/hono-context.factory.js.map +1 -0
  43. package/dist/context/index.d.ts +3 -0
  44. package/dist/context/index.d.ts.map +1 -0
  45. package/dist/context/index.js +2 -0
  46. package/dist/context/index.js.map +1 -0
  47. package/dist/core/apcore.d.ts +135 -0
  48. package/dist/core/apcore.d.ts.map +1 -0
  49. package/dist/core/apcore.js +257 -0
  50. package/dist/core/apcore.js.map +1 -0
  51. package/dist/core/executor.d.ts +32 -0
  52. package/dist/core/executor.d.ts.map +1 -0
  53. package/dist/core/executor.js +41 -0
  54. package/dist/core/executor.js.map +1 -0
  55. package/dist/core/middleware.d.ts +61 -0
  56. package/dist/core/middleware.d.ts.map +1 -0
  57. package/dist/core/middleware.js +51 -0
  58. package/dist/core/middleware.js.map +1 -0
  59. package/dist/core/registry.d.ts +79 -0
  60. package/dist/core/registry.d.ts.map +1 -0
  61. package/dist/core/registry.js +218 -0
  62. package/dist/core/registry.js.map +1 -0
  63. package/dist/index.d.ts +33 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +71 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/mcp/apcore-mcp.service.d.ts +83 -0
  68. package/dist/mcp/apcore-mcp.service.d.ts.map +1 -0
  69. package/dist/mcp/apcore-mcp.service.js +189 -0
  70. package/dist/mcp/apcore-mcp.service.js.map +1 -0
  71. package/dist/mcp/index.d.ts +5 -0
  72. package/dist/mcp/index.d.ts.map +1 -0
  73. package/dist/mcp/index.js +3 -0
  74. package/dist/mcp/index.js.map +1 -0
  75. package/dist/mcp/mount.d.ts +51 -0
  76. package/dist/mcp/mount.d.ts.map +1 -0
  77. package/dist/mcp/mount.js +95 -0
  78. package/dist/mcp/mount.js.map +1 -0
  79. package/dist/output/index.d.ts +3 -0
  80. package/dist/output/index.d.ts.map +1 -0
  81. package/dist/output/index.js +2 -0
  82. package/dist/output/index.js.map +1 -0
  83. package/dist/output/yaml-writer.d.ts +31 -0
  84. package/dist/output/yaml-writer.d.ts.map +1 -0
  85. package/dist/output/yaml-writer.js +49 -0
  86. package/dist/output/yaml-writer.js.map +1 -0
  87. package/dist/scanners/hono-route-scanner.d.ts +60 -0
  88. package/dist/scanners/hono-route-scanner.d.ts.map +1 -0
  89. package/dist/scanners/hono-route-scanner.js +217 -0
  90. package/dist/scanners/hono-route-scanner.js.map +1 -0
  91. package/dist/scanners/index.d.ts +3 -0
  92. package/dist/scanners/index.d.ts.map +1 -0
  93. package/dist/scanners/index.js +2 -0
  94. package/dist/scanners/index.js.map +1 -0
  95. package/dist/schema/adapters/json-schema.adapter.d.ts +23 -0
  96. package/dist/schema/adapters/json-schema.adapter.d.ts.map +1 -0
  97. package/dist/schema/adapters/json-schema.adapter.js +40 -0
  98. package/dist/schema/adapters/json-schema.adapter.js.map +1 -0
  99. package/dist/schema/adapters/schema-adapter.interface.d.ts +24 -0
  100. package/dist/schema/adapters/schema-adapter.interface.d.ts.map +1 -0
  101. package/dist/schema/adapters/schema-adapter.interface.js +2 -0
  102. package/dist/schema/adapters/schema-adapter.interface.js.map +1 -0
  103. package/dist/schema/adapters/typebox.adapter.d.ts +26 -0
  104. package/dist/schema/adapters/typebox.adapter.d.ts.map +1 -0
  105. package/dist/schema/adapters/typebox.adapter.js +39 -0
  106. package/dist/schema/adapters/typebox.adapter.js.map +1 -0
  107. package/dist/schema/adapters/zod.adapter.d.ts +17 -0
  108. package/dist/schema/adapters/zod.adapter.d.ts.map +1 -0
  109. package/dist/schema/adapters/zod.adapter.js +372 -0
  110. package/dist/schema/adapters/zod.adapter.js.map +1 -0
  111. package/dist/schema/index.d.ts +6 -0
  112. package/dist/schema/index.d.ts.map +1 -0
  113. package/dist/schema/index.js +5 -0
  114. package/dist/schema/index.js.map +1 -0
  115. package/dist/schema/schema-extractor.d.ts +51 -0
  116. package/dist/schema/schema-extractor.d.ts.map +1 -0
  117. package/dist/schema/schema-extractor.js +89 -0
  118. package/dist/schema/schema-extractor.js.map +1 -0
  119. package/dist/tools/define-tool.d.ts +68 -0
  120. package/dist/tools/define-tool.d.ts.map +1 -0
  121. package/dist/tools/define-tool.js +122 -0
  122. package/dist/tools/define-tool.js.map +1 -0
  123. package/dist/tools/index.d.ts +3 -0
  124. package/dist/tools/index.d.ts.map +1 -0
  125. package/dist/tools/index.js +2 -0
  126. package/dist/tools/index.js.map +1 -0
  127. package/dist/types.d.ts +246 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +2 -0
  130. package/dist/types.js.map +1 -0
  131. package/dist/utils/id-generator.d.ts +52 -0
  132. package/dist/utils/id-generator.d.ts.map +1 -0
  133. package/dist/utils/id-generator.js +87 -0
  134. package/dist/utils/id-generator.js.map +1 -0
  135. package/dist/utils/module-factory.d.ts +34 -0
  136. package/dist/utils/module-factory.d.ts.map +1 -0
  137. package/dist/utils/module-factory.js +59 -0
  138. package/dist/utils/module-factory.js.map +1 -0
  139. package/package.json +109 -0
package/dist/cli.js ADDED
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from 'node:util';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { resolve as resolvePath } from 'node:path';
6
+ import { formatModules } from 'apcore-toolkit';
7
+ import { HonoApcore } from './core/apcore.js';
8
+ import { HonoRouteScanner } from './scanners/hono-route-scanner.js';
9
+ import { renderBindingsYaml, writeBindingsFile } from './output/yaml-writer.js';
10
+ import { ApcoreMcpService } from './mcp/apcore-mcp.service.js';
11
+ import { loadSettings, toMcpTransport } from './config.js';
12
+ const USAGE = `hono-apcore — expose a Hono app as apcore modules
13
+
14
+ Usage:
15
+ hono-apcore <command> <entry> [options]
16
+
17
+ Commands:
18
+ scan Scan the app's routes and print or write the module bindings
19
+ serve Scan, then start an MCP server exposing the modules as tools
20
+ export Write OpenAI-compatible tool definitions as JSON
21
+
22
+ Entry:
23
+ <path>[:<export>] Module to import. <export> defaults to "default", then "app".
24
+ TypeScript entries need a loader, e.g.
25
+ npx tsx node_modules/.bin/hono-apcore scan ./src/app.ts
26
+
27
+ Options:
28
+ --out <file> scan/export: write to this file instead of stdout
29
+ --format <fmt> scan: yaml | json | markdown | table (default: table)
30
+ --transport <t> serve: stdio | http | sse (default: $APCORE_TRANSPORT)
31
+ --host <host> serve: bind address (default: $APCORE_HOST)
32
+ --port <n> serve: bind port (default: $APCORE_PORT)
33
+ --explorer serve: enable the MCP Tool Explorer UI
34
+ --allow-execute serve: allow tool execution from the Explorer
35
+ --name <name> serve: MCP server name
36
+ --bindings <file> Load additional modules from a YAML bindings file
37
+ --prefix <str> Prefix prepended to generated module IDs
38
+ --include <regex> Keep only module IDs matching this pattern
39
+ --exclude <regex> Drop module IDs matching this pattern
40
+ -h, --help Show this help
41
+ -v, --version Show the package version
42
+ `;
43
+ function isHonoApp(value) {
44
+ return (value !== null &&
45
+ typeof value === 'object' &&
46
+ Array.isArray(value.routes) &&
47
+ typeof value.request === 'function');
48
+ }
49
+ /**
50
+ * Duck-typed rather than `instanceof`: the entry may have been built against a
51
+ * different copy of this package (a workspace link, two versions in the tree),
52
+ * and a real instance under a second copy is still the instance the user meant.
53
+ */
54
+ function isHonoApcore(value) {
55
+ if (value === null || typeof value !== 'object')
56
+ return false;
57
+ const candidate = value;
58
+ return (typeof candidate.registerTool === 'function' &&
59
+ typeof candidate.scanRoutes === 'function' &&
60
+ typeof candidate.init === 'function' &&
61
+ candidate.registry !== undefined &&
62
+ candidate.executor !== undefined);
63
+ }
64
+ /**
65
+ * Import the entry module and work out which export is the Hono app and
66
+ * which — if any — is a pre-configured {@link HonoApcore}.
67
+ */
68
+ async function resolveEntry(spec) {
69
+ const separator = spec.lastIndexOf(':');
70
+ // A Windows drive letter ("C:\...") is not an export separator.
71
+ const hasExport = separator > 1;
72
+ const modulePath = hasExport ? spec.slice(0, separator) : spec;
73
+ const exportName = hasExport ? spec.slice(separator + 1) : undefined;
74
+ const url = pathToFileURL(resolvePath(process.cwd(), modulePath)).href;
75
+ const mod = (await import(url));
76
+ const named = exportName ? mod[exportName] : undefined;
77
+ if (exportName && named === undefined) {
78
+ throw new Error(`Entry module "${modulePath}" has no export named "${exportName}".`);
79
+ }
80
+ const candidate = named ?? mod['default'] ?? mod['app'];
81
+ // A configured instance may be exported under any name — apps commonly call
82
+ // it `ap`, because `apcore` is already taken by the middleware import.
83
+ const instance = (isHonoApcore(candidate) ? candidate : undefined) ??
84
+ Object.values(mod).find(isHonoApcore) ??
85
+ new HonoApcore();
86
+ const app = isHonoApp(candidate)
87
+ ? candidate
88
+ : isHonoApp(mod['app'])
89
+ ? mod['app']
90
+ : isHonoApp(mod['default'])
91
+ ? mod['default']
92
+ : null;
93
+ return { instance, app };
94
+ }
95
+ /** Scan the app's routes without registering, for `scan` and `export` output. */
96
+ function scanModules(app, options) {
97
+ if (!app)
98
+ return [];
99
+ return new HonoRouteScanner().scan(app, options);
100
+ }
101
+ /**
102
+ * Build the scan options for a command: the entry's own configuration first,
103
+ * then the CLI flags. A flag that was not passed leaves the entry's value
104
+ * alone, so `scan` reports the same modules the app itself registers.
105
+ */
106
+ function routeOptions(values, instance) {
107
+ const base = instance?.routeOptions ?? {
108
+ modulePrefix: loadSettings().modulePrefix || undefined,
109
+ includePaths: loadSettings().includePaths,
110
+ excludePaths: loadSettings().excludePaths,
111
+ };
112
+ const overrides = {};
113
+ if (values['prefix'] !== undefined)
114
+ overrides.modulePrefix = values['prefix'];
115
+ if (values['include'] !== undefined)
116
+ overrides.include = values['include'];
117
+ if (values['exclude'] !== undefined)
118
+ overrides.exclude = values['exclude'];
119
+ return { ...base, ...overrides };
120
+ }
121
+ async function emit(content, out) {
122
+ if (out) {
123
+ await writeFile(out, content, 'utf-8');
124
+ process.stdout.write(`Wrote ${out}\n`);
125
+ }
126
+ else {
127
+ process.stdout.write(content.endsWith('\n') ? content : `${content}\n`);
128
+ }
129
+ }
130
+ async function commandScan(entry, values) {
131
+ const { app, instance } = await resolveEntry(entry);
132
+ if (!app) {
133
+ throw new Error('Entry module does not export a Hono app — nothing to scan.');
134
+ }
135
+ const modules = scanModules(app, routeOptions(values, instance));
136
+ const format = values['format'] ?? 'table';
137
+ const out = values['out'];
138
+ if (format === 'yaml') {
139
+ if (out) {
140
+ await writeBindingsFile(modules, out);
141
+ process.stdout.write(`Wrote ${out} (${modules.length} modules)\n`);
142
+ return;
143
+ }
144
+ await emit(renderBindingsYaml(modules));
145
+ return;
146
+ }
147
+ if (format === 'json') {
148
+ await emit(JSON.stringify(formatModules(modules, { style: 'json' }), null, 2), out);
149
+ return;
150
+ }
151
+ const style = format === 'markdown' ? 'markdown' : 'table-row';
152
+ await emit(String(formatModules(modules, { style })), out);
153
+ }
154
+ async function commandServe(entry, values) {
155
+ const { instance, app } = await resolveEntry(entry);
156
+ const settings = loadSettings();
157
+ await instance.init(app ?? undefined, routeOptions(values, instance));
158
+ if (values['bindings']) {
159
+ await instance.loadBindings(values['bindings']);
160
+ }
161
+ // A zero-config entry (a bare Hono app) still gets an MCP surface here, so
162
+ // `hono-apcore serve ./src/app.ts` works without touching the app's source.
163
+ const mcp = instance.mcp ?? new ApcoreMcpService(instance.registry, instance.executor, {});
164
+ const transport = toMcpTransport((values['transport'] ?? settings.transport));
165
+ const port = values['port'] !== undefined ? Number(values['port']) : undefined;
166
+ process.stderr.write(`hono-apcore: serving ${instance.registry.count} modules over ${transport}\n`);
167
+ await mcp.start({
168
+ transport,
169
+ host: values['host'],
170
+ port: Number.isFinite(port) ? port : undefined,
171
+ explorer: values['explorer'],
172
+ allowExecute: values['allow-execute'],
173
+ name: values['name'],
174
+ });
175
+ }
176
+ async function commandExport(entry, values) {
177
+ const { instance, app } = await resolveEntry(entry);
178
+ await instance.init(app ?? undefined, routeOptions(values, instance));
179
+ const mcp = instance.mcp ?? new ApcoreMcpService(instance.registry, instance.executor, {});
180
+ const tools = await mcp.toOpenaiTools();
181
+ await emit(JSON.stringify(tools, null, 2), values['out']);
182
+ }
183
+ /** Parse argv and dispatch. Exported so tests can drive the CLI directly. */
184
+ export async function main(argv = process.argv.slice(2)) {
185
+ const { values, positionals } = parseArgs({
186
+ args: argv,
187
+ allowPositionals: true,
188
+ options: {
189
+ out: { type: 'string' },
190
+ format: { type: 'string' },
191
+ transport: { type: 'string' },
192
+ host: { type: 'string' },
193
+ port: { type: 'string' },
194
+ explorer: { type: 'boolean' },
195
+ 'allow-execute': { type: 'boolean' },
196
+ name: { type: 'string' },
197
+ bindings: { type: 'string' },
198
+ prefix: { type: 'string' },
199
+ include: { type: 'string' },
200
+ exclude: { type: 'string' },
201
+ help: { type: 'boolean', short: 'h' },
202
+ version: { type: 'boolean', short: 'v' },
203
+ },
204
+ });
205
+ if (values.version) {
206
+ const { VERSION } = await import('apcore-js');
207
+ process.stdout.write(`hono-apcore (apcore-js ${VERSION})\n`);
208
+ return 0;
209
+ }
210
+ if (values.help || positionals.length === 0) {
211
+ process.stdout.write(USAGE);
212
+ return 0;
213
+ }
214
+ const [command, entry] = positionals;
215
+ if (!entry) {
216
+ process.stderr.write(`hono-apcore: "${command}" needs an entry module.\n\n${USAGE}`);
217
+ return 2;
218
+ }
219
+ switch (command) {
220
+ case 'scan':
221
+ await commandScan(entry, values);
222
+ return 0;
223
+ case 'serve':
224
+ await commandServe(entry, values);
225
+ return 0;
226
+ case 'export':
227
+ await commandExport(entry, values);
228
+ return 0;
229
+ default:
230
+ process.stderr.write(`hono-apcore: unknown command "${command}".\n\n${USAGE}`);
231
+ return 2;
232
+ }
233
+ }
234
+ const invokedDirectly = process.argv[1] !== undefined &&
235
+ import.meta.url === pathToFileURL(process.argv[1]).href;
236
+ if (invokedDirectly) {
237
+ main()
238
+ .then((code) => {
239
+ if (code !== 0)
240
+ process.exitCode = code;
241
+ })
242
+ .catch((err) => {
243
+ process.stderr.write(`hono-apcore: ${err instanceof Error ? err.message : String(err)}\n`);
244
+ process.exitCode = 1;
245
+ });
246
+ }
247
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
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AAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The canonical `APCORE_*` settings every apcore framework integration
3
+ * implements with identical names, types, and defaults.
4
+ *
5
+ * Values are read from `process.env` (or any object passed to
6
+ * {@link loadSettings}) and normalised into this camelCase shape.
7
+ */
8
+ export interface ApcoreSettings {
9
+ /** `APCORE_ENABLED` — master switch. */
10
+ enabled: boolean;
11
+ /** `APCORE_DEBUG` — verbose logging / introspection. */
12
+ debug: boolean;
13
+ /** `APCORE_SCANNERS` — enabled scanner identifiers. */
14
+ scanners: string[];
15
+ /** `APCORE_INCLUDE_PATHS` — route patterns to include (empty = all). */
16
+ includePaths: string[];
17
+ /** `APCORE_EXCLUDE_PATHS` — route patterns to exclude. */
18
+ excludePaths: string[];
19
+ /** `APCORE_MODULE_PREFIX` — prefix prepended to generated module IDs. */
20
+ modulePrefix: string;
21
+ /** `APCORE_AUTH_ENABLED` — require auth for MCP/A2A endpoints. */
22
+ authEnabled: boolean;
23
+ /** `APCORE_AUTH_STRATEGY` — `bearer` / `session` / `custom`. */
24
+ authStrategy: 'bearer' | 'session' | 'custom';
25
+ /** `APCORE_TRANSPORT` — MCP transport: `stdio` / `http` / `sse`. */
26
+ transport: 'stdio' | 'http' | 'sse';
27
+ /** `APCORE_HOST` — bind address when transport is not stdio. */
28
+ host: string;
29
+ /** `APCORE_PORT` — bind port when transport is not stdio. */
30
+ port: number;
31
+ }
32
+ /** Authoritative defaults, shared across every apcore integration. */
33
+ export declare const APCORE_SETTING_DEFAULTS: Readonly<ApcoreSettings>;
34
+ /** Minimal shape of an environment source (`process.env` satisfies it). */
35
+ export type EnvSource = Record<string, string | undefined>;
36
+ /**
37
+ * Read the canonical `APCORE_*` settings from an environment source.
38
+ *
39
+ * Unset or unparseable variables fall back to {@link APCORE_SETTING_DEFAULTS}.
40
+ * `overrides` win over the environment, letting code configure the same
41
+ * knobs without mutating `process.env`.
42
+ *
43
+ * @param env - Environment source. Defaults to `process.env` when available.
44
+ * @param overrides - Values that take precedence over the environment.
45
+ */
46
+ export declare function loadSettings(env?: EnvSource, overrides?: Partial<ApcoreSettings>): ApcoreSettings;
47
+ /**
48
+ * Translate the canonical `APCORE_TRANSPORT` value to the transport name
49
+ * `apcore-mcp` expects.
50
+ *
51
+ * `"http"` is the ecosystem-wide spelling; `apcore-mcp` calls the same
52
+ * transport `"streamable-http"`.
53
+ */
54
+ export declare function toMcpTransport(transport: ApcoreSettings['transport']): 'stdio' | 'streamable-http' | 'sse';
55
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,KAAK,EAAE,OAAO,CAAC;IACf,uDAAuD;IACvD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,wEAAwE;IACxE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0DAA0D;IAC1D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,WAAW,EAAE,OAAO,CAAC;IACrB,gEAAgE;IAChE,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC9C,oEAAoE;IACpE,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACpC,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,cAAc,CAY3D,CAAC;AAEH,2EAA2E;AAC3E,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAoC3D;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,GAAG,GAAE,SAA6D,EAClE,SAAS,GAAE,OAAO,CAAC,cAAc,CAAM,GACtC,cAAc,CA0BhB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,cAAc,CAAC,WAAW,CAAC,GACrC,OAAO,GAAG,iBAAiB,GAAG,KAAK,CAErC"}
package/dist/config.js ADDED
@@ -0,0 +1,86 @@
1
+ import { APCORE_ENV_PREFIX } from './constants.js';
2
+ /** Authoritative defaults, shared across every apcore integration. */
3
+ export const APCORE_SETTING_DEFAULTS = Object.freeze({
4
+ enabled: true,
5
+ debug: false,
6
+ scanners: ['auto'],
7
+ includePaths: [],
8
+ excludePaths: [],
9
+ modulePrefix: '',
10
+ authEnabled: false,
11
+ authStrategy: 'bearer',
12
+ transport: 'stdio',
13
+ host: '0.0.0.0',
14
+ port: 8808,
15
+ });
16
+ function parseBool(raw, fallback) {
17
+ if (raw === undefined)
18
+ return fallback;
19
+ const value = raw.trim().toLowerCase();
20
+ if (value === 'true' || value === '1' || value === 'yes' || value === 'on')
21
+ return true;
22
+ if (value === 'false' || value === '0' || value === 'no' || value === 'off')
23
+ return false;
24
+ return fallback;
25
+ }
26
+ function parseList(raw, fallback) {
27
+ if (raw === undefined)
28
+ return [...fallback];
29
+ const items = raw
30
+ .split(',')
31
+ .map((item) => item.trim())
32
+ .filter((item) => item.length > 0);
33
+ return items;
34
+ }
35
+ function parsePort(raw, fallback) {
36
+ if (raw === undefined)
37
+ return fallback;
38
+ const value = Number.parseInt(raw, 10);
39
+ if (!Number.isInteger(value) || value < 0 || value > 65535)
40
+ return fallback;
41
+ return value;
42
+ }
43
+ function parseEnum(raw, allowed, fallback) {
44
+ if (raw === undefined)
45
+ return fallback;
46
+ const value = raw.trim().toLowerCase();
47
+ return allowed.includes(value) ? value : fallback;
48
+ }
49
+ /**
50
+ * Read the canonical `APCORE_*` settings from an environment source.
51
+ *
52
+ * Unset or unparseable variables fall back to {@link APCORE_SETTING_DEFAULTS}.
53
+ * `overrides` win over the environment, letting code configure the same
54
+ * knobs without mutating `process.env`.
55
+ *
56
+ * @param env - Environment source. Defaults to `process.env` when available.
57
+ * @param overrides - Values that take precedence over the environment.
58
+ */
59
+ export function loadSettings(env = typeof process !== 'undefined' ? process.env : {}, overrides = {}) {
60
+ const key = (name) => env[`${APCORE_ENV_PREFIX}${name}`];
61
+ const fromEnv = {
62
+ enabled: parseBool(key('ENABLED'), APCORE_SETTING_DEFAULTS.enabled),
63
+ debug: parseBool(key('DEBUG'), APCORE_SETTING_DEFAULTS.debug),
64
+ scanners: parseList(key('SCANNERS'), APCORE_SETTING_DEFAULTS.scanners),
65
+ includePaths: parseList(key('INCLUDE_PATHS'), APCORE_SETTING_DEFAULTS.includePaths),
66
+ excludePaths: parseList(key('EXCLUDE_PATHS'), APCORE_SETTING_DEFAULTS.excludePaths),
67
+ modulePrefix: key('MODULE_PREFIX') ?? APCORE_SETTING_DEFAULTS.modulePrefix,
68
+ authEnabled: parseBool(key('AUTH_ENABLED'), APCORE_SETTING_DEFAULTS.authEnabled),
69
+ authStrategy: parseEnum(key('AUTH_STRATEGY'), ['bearer', 'session', 'custom'], APCORE_SETTING_DEFAULTS.authStrategy),
70
+ transport: parseEnum(key('TRANSPORT'), ['stdio', 'http', 'sse'], APCORE_SETTING_DEFAULTS.transport),
71
+ host: key('HOST') ?? APCORE_SETTING_DEFAULTS.host,
72
+ port: parsePort(key('PORT'), APCORE_SETTING_DEFAULTS.port),
73
+ };
74
+ return { ...fromEnv, ...overrides };
75
+ }
76
+ /**
77
+ * Translate the canonical `APCORE_TRANSPORT` value to the transport name
78
+ * `apcore-mcp` expects.
79
+ *
80
+ * `"http"` is the ecosystem-wide spelling; `apcore-mcp` calls the same
81
+ * transport `"streamable-http"`.
82
+ */
83
+ export function toMcpTransport(transport) {
84
+ return transport === 'http' ? 'streamable-http' : transport;
85
+ }
86
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAkCnD,sEAAsE;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAA6B,MAAM,CAAC,MAAM,CAAC;IAC7E,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,CAAC,MAAM,CAAC;IAClB,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,QAAQ;IACtB,SAAS,EAAE,OAAO;IAClB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AAKH,SAAS,SAAS,CAAC,GAAuB,EAAE,QAAiB;IAC3D,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvC,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACxF,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1F,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,SAAS,CAAC,GAAuB,EAAE,QAAkB;IAC5D,IAAI,GAAG,KAAK,SAAS;QAAE,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,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Hono context variable key holding the {@link HonoApcore} instance.
3
+ *
4
+ * Read it with `c.get(APCORE_VAR)` — or, with types, via `getApcore(c)`.
5
+ */
6
+ export declare const APCORE_VAR: "apcore";
7
+ /**
8
+ * Hono context variable key holding the per-request apcore `Context`
9
+ * built by {@link HonoContextFactory}.
10
+ */
11
+ export declare const APCORE_CONTEXT_VAR: "apcoreContext";
12
+ /** Default path the embedded MCP endpoint is mounted at. */
13
+ export declare const DEFAULT_MCP_ENDPOINT = "/mcp";
14
+ /** Default URL prefix for the MCP Tool Explorer UI. */
15
+ export declare const DEFAULT_EXPLORER_PREFIX = "/explorer";
16
+ /**
17
+ * Sentinel header `@hono/node-server` looks for to learn that a handler has
18
+ * already written the response directly to the Node `ServerResponse`.
19
+ *
20
+ * Mirrors `RESPONSE_ALREADY_SENT` from `@hono/node-server/utils/response`;
21
+ * inlined so mounting MCP does not force a hard dependency on the Node
22
+ * adapter in edge builds.
23
+ */
24
+ export declare const HONO_ALREADY_SENT_HEADER = "x-hono-already-sent";
25
+ /** Environment-variable prefix for all `APCORE_*` settings. */
26
+ export declare const APCORE_ENV_PREFIX = "APCORE_";
27
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAG,QAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAG,eAAwB,CAAC;AAE3D,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAE3C,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,cAAc,CAAC;AAEnD;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,wBAAwB,CAAC;AAE9D,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,YAAY,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Hono context variable key holding the {@link HonoApcore} instance.
3
+ *
4
+ * Read it with `c.get(APCORE_VAR)` — or, with types, via `getApcore(c)`.
5
+ */
6
+ export const APCORE_VAR = 'apcore';
7
+ /**
8
+ * Hono context variable key holding the per-request apcore `Context`
9
+ * built by {@link HonoContextFactory}.
10
+ */
11
+ export const APCORE_CONTEXT_VAR = 'apcoreContext';
12
+ /** Default path the embedded MCP endpoint is mounted at. */
13
+ export const DEFAULT_MCP_ENDPOINT = '/mcp';
14
+ /** Default URL prefix for the MCP Tool Explorer UI. */
15
+ export const DEFAULT_EXPLORER_PREFIX = '/explorer';
16
+ /**
17
+ * Sentinel header `@hono/node-server` looks for to learn that a handler has
18
+ * already written the response directly to the Node `ServerResponse`.
19
+ *
20
+ * Mirrors `RESPONSE_ALREADY_SENT` from `@hono/node-server/utils/response`;
21
+ * inlined so mounting MCP does not force a hard dependency on the Node
22
+ * adapter in edge builds.
23
+ */
24
+ export const HONO_ALREADY_SENT_HEADER = 'x-hono-already-sent';
25
+ /** Environment-variable prefix for all `APCORE_*` settings. */
26
+ export const APCORE_ENV_PREFIX = 'APCORE_';
27
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAwB,CAAC;AAE3D,4DAA4D;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE3C,uDAAuD;AACvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAE9D,+DAA+D;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { Context as ApcoreContext } from 'apcore-js';
2
+ import type { Identity } from 'apcore-js';
3
+ /**
4
+ * Anything this factory can read request headers from.
5
+ *
6
+ * Covers a Hono `Context` (`c`), a raw web `Request`, a bare `Headers`
7
+ * instance, and the plain header record a Node handler sees — so the same
8
+ * factory serves routes, middleware, and tests.
9
+ */
10
+ export type HeaderSource = Headers | Request | {
11
+ req: {
12
+ raw: Request;
13
+ };
14
+ } | {
15
+ headers: Headers | Record<string, string | string[] | undefined>;
16
+ };
17
+ /**
18
+ * Reduce any {@link HeaderSource} to a `Headers` instance.
19
+ *
20
+ * `Headers` already matches header names case-insensitively, so downstream
21
+ * lookups need no normalisation of their own.
22
+ */
23
+ export declare function toHeaders(source: HeaderSource): Headers;
24
+ /**
25
+ * Builds apcore `Context` objects from Hono requests.
26
+ *
27
+ * **Identity resolution**, in order:
28
+ * 1. `x-user-id` header
29
+ * 2. `Authorization: Bearer <token>` (identity id `"bearer"`)
30
+ * 3. `x-roles` alone — a demo shortcut for role-based ACL without auth
31
+ * 4. anonymous
32
+ *
33
+ * **W3C Trace Context** — a `traceparent` header supplies the trace id.
34
+ * Strict 32-hex validation and rejection of W3C-invalid ids happen inside
35
+ * `Context.create`, not here (PROTOCOL_SPEC §10.5).
36
+ *
37
+ * **Correlation id** — `x-correlation-id` (or `x-request-id`) is copied into
38
+ * `context.data["x-correlation-id"]` so existing log pipelines keep working.
39
+ *
40
+ * Pass a `resolveIdentity` override to plug in real authentication: whatever
41
+ * it returns wins over the header heuristics above.
42
+ */
43
+ export declare class HonoContextFactory {
44
+ private readonly options;
45
+ constructor(options?: {
46
+ /** Custom identity resolver; returning `null` falls back to the headers. */
47
+ resolveIdentity?: (headers: Headers) => Identity | null;
48
+ /** Extra `context.data` entries merged over the built-in ones. */
49
+ data?: (headers: Headers) => Record<string, unknown>;
50
+ });
51
+ /** Create an apcore `Context` from a Hono context, `Request`, or headers. */
52
+ createContext(source: HeaderSource): ApcoreContext;
53
+ private extractTraceParent;
54
+ private extractIdentity;
55
+ /** Parse the comma-separated `x-roles` header into a role list. */
56
+ private extractRoles;
57
+ private extractData;
58
+ }
59
+ /** Shared factory used by the default `apcore()` middleware. */
60
+ export declare const defaultContextFactory: HonoContextFactory;
61
+ //# sourceMappingURL=hono-context.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono-context.factory.d.ts","sourceRoot":"","sources":["../../src/context/hono-context.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAgC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,WAAW,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,OAAO,GACP;IAAE,GAAG,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACzB;IAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;CAAE,CAAC;AAWzE;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAsBvD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,GAAE;QACxB,4EAA4E;QAC5E,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;QACxD,kEAAkE;QAClE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjD;IAGR,6EAA6E;IAC7E,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa;IAWlD,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,eAAe;IAyBvB,mEAAmE;IACnE,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,WAAW;CAQpB;AAED,gEAAgE;AAChE,eAAO,MAAM,qBAAqB,oBAA2B,CAAC"}