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
@@ -0,0 +1,122 @@
1
+ import { createScannedModule, enrichSchemaDescriptions } from 'apcore-toolkit';
2
+ import { defaultSchemaExtractor } from '../schema/schema-extractor.js';
3
+ import { generateModuleId, normalizeMethodName, applyModulePrefix } from '../utils/id-generator.js';
4
+ import { EMPTY_OBJECT_SCHEMA, normalizeResult, toModuleAnnotations, } from '../utils/module-factory.js';
5
+ /**
6
+ * Identity helper that gives a tool literal full type inference and a single
7
+ * obvious place to look for the shape.
8
+ *
9
+ * This is the Hono counterpart to NestJS's `@ApTool` decorator: Hono has no
10
+ * classes or DI container to decorate, so a tool is a plain object carrying
11
+ * its own metadata and handler.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const listTodos = defineTool({
16
+ * namespace: 'todo',
17
+ * name: 'list',
18
+ * description: 'List all todos',
19
+ * inputSchema: Type.Object({ done: Type.Optional(Type.Boolean()) }),
20
+ * annotations: { readonly: true, idempotent: true },
21
+ * handler: (inputs) => ({ todos: store.filter(...) }),
22
+ * });
23
+ * ```
24
+ */
25
+ export function defineTool(definition) {
26
+ return definition;
27
+ }
28
+ /**
29
+ * Group several tools under one namespace, applying shared tags and
30
+ * annotations to each.
31
+ *
32
+ * The record key becomes the tool's `name` when the entry does not set one,
33
+ * so `{ list: {...} }` under namespace `todo` yields `todo.list`.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const todoTools = defineToolset({
38
+ * namespace: 'todo',
39
+ * tags: ['todo'],
40
+ * tools: {
41
+ * list: { description: 'List todos', handler: list },
42
+ * create: { description: 'Add a todo', handler: create },
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ export function defineToolset(options) {
48
+ const { namespace, description, tags, annotations, tools } = options;
49
+ return Object.entries(tools).map(([key, tool]) => ({
50
+ ...tool,
51
+ namespace,
52
+ name: tool.name ?? key,
53
+ description: tool.description || description || key,
54
+ tags: tool.tags ?? tags,
55
+ annotations: tool.annotations ?? annotations,
56
+ }));
57
+ }
58
+ /** Resolve the module ID a tool definition will be registered under. */
59
+ export function resolveToolId(tool, modulePrefix) {
60
+ if (tool.id != null) {
61
+ return applyModulePrefix(tool.id, modulePrefix);
62
+ }
63
+ // An anonymous handler written inline picks up the property key as its
64
+ // name — `{ handler: () => {} }` yields `"handler"` — which would silently
65
+ // produce a module called `<namespace>.handler`, so it is not a usable
66
+ // fallback.
67
+ const inferred = tool.handler.name === 'handler' ? '' : tool.handler.name;
68
+ const name = tool.name ?? inferred;
69
+ if (!name) {
70
+ throw new Error('Tool definition needs an "id", a "name", or a named handler function to derive its module ID from.');
71
+ }
72
+ const base = generateModuleId(tool.namespace ?? '', normalizeMethodName(name), false, null);
73
+ return applyModulePrefix(base, modulePrefix);
74
+ }
75
+ function extractSchema(extractor, input, moduleId, field) {
76
+ if (input == null)
77
+ return { ...EMPTY_OBJECT_SCHEMA };
78
+ try {
79
+ return extractor.extractJsonSchema(input);
80
+ }
81
+ catch (err) {
82
+ const reason = err instanceof Error ? err.message : String(err);
83
+ throw new Error(`Failed to extract ${field} for tool "${moduleId}": ${reason}`);
84
+ }
85
+ }
86
+ /**
87
+ * Convert a {@link ApToolDefinition} into the toolkit's `ScannedModule`
88
+ * intermediate plus the bound execute function the registry needs.
89
+ *
90
+ * Schemas are normalised to JSON Schema, and JSDoc on the handler fills in
91
+ * missing documentation and per-parameter descriptions.
92
+ */
93
+ export function toolToScannedModule(tool, options = {}) {
94
+ const extractor = options.schemaExtractor ?? defaultSchemaExtractor;
95
+ const moduleId = resolveToolId(tool, options.modulePrefix);
96
+ let inputSchema = extractSchema(extractor, tool.inputSchema, moduleId, 'inputSchema');
97
+ const outputSchema = extractSchema(extractor, tool.outputSchema, moduleId, 'outputSchema');
98
+ // JavaScript gives no runtime access to a function's leading comments — the
99
+ // way Python reads a docstring — so per-parameter prose is declared with the
100
+ // explicit `params` field instead of inferred from JSDoc.
101
+ if (tool.params && Object.keys(tool.params).length > 0) {
102
+ inputSchema = enrichSchemaDescriptions(inputSchema, tool.params);
103
+ }
104
+ const tags = [...new Set([...(tool.tags ?? []), ...(options.tags ?? [])])];
105
+ const module = createScannedModule({
106
+ moduleId,
107
+ description: tool.description,
108
+ inputSchema,
109
+ outputSchema,
110
+ tags,
111
+ target: tool.handler.name || moduleId,
112
+ annotations: toModuleAnnotations(tool.annotations),
113
+ documentation: tool.documentation ?? null,
114
+ examples: tool.examples ?? [],
115
+ });
116
+ const execute = async (inputs, context) => {
117
+ const raw = await tool.handler(inputs, context);
118
+ return normalizeResult(raw);
119
+ };
120
+ return { module, execute };
121
+ }
122
+ //# sourceMappingURL=define-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-tool.js","sourceRoot":"","sources":["../../src/tools/define-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE/E,OAAO,EAAmB,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,iBAAiB,EAA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E;IAC5E,6EAA6E;IAC7E,0DAA0D;IAC1D,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvD,WAAW,GAAG,wBAAwB,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,MAAM,MAAM,GAAG,mBAAmB,CAAC;QACjC,QAAQ;QACR,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW;QACX,YAAY;QACZ,IAAI;QACJ,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ;QACrC,WAAW,EAAE,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC;QAClD,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI;QACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;KAC9B,CAAC,CAAC;IAEH,MAAM,OAAO,GAAmB,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QACxD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChD,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { defineTool, defineToolset, resolveToolId, toolToScannedModule } from './define-tool.js';
2
+ export type { ToolConversionOptions } from './define-tool.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjG,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { defineTool, defineToolset, resolveToolId, toolToScannedModule } from './define-tool.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,246 @@
1
+ export type { ModuleAnnotations, ModuleExample, Module, Context, Identity, ModuleDescriptor, PreflightResult, PreflightCheckResult, ValidationResult, } from 'apcore-js';
2
+ /** Annotations describing tool behaviour characteristics. */
3
+ export interface ApToolAnnotations {
4
+ readonly?: boolean;
5
+ destructive?: boolean;
6
+ idempotent?: boolean;
7
+ requiresApproval?: boolean;
8
+ openWorld?: boolean;
9
+ streaming?: boolean;
10
+ cacheable?: boolean;
11
+ cacheTtl?: number;
12
+ cacheKeyFields?: string[] | null;
13
+ paginated?: boolean;
14
+ paginationStyle?: 'cursor' | 'offset' | 'page';
15
+ }
16
+ /** Example entry for a tool invocation. */
17
+ export interface ApToolExample {
18
+ title: string;
19
+ inputs: Record<string, unknown>;
20
+ output: Record<string, unknown>;
21
+ description?: string;
22
+ }
23
+ /**
24
+ * Handler signature for a tool defined with {@link defineTool}.
25
+ *
26
+ * `inputs` is the validated argument object; `context` is the apcore
27
+ * `Context` for the current call (identity, trace, data), or `undefined`
28
+ * when the caller did not supply one.
29
+ */
30
+ export type ApToolHandler = (inputs: Record<string, unknown>, context?: unknown) => unknown | Promise<unknown>;
31
+ /**
32
+ * A tool definition — the Hono counterpart to NestJS's `@ApTool` decorator.
33
+ *
34
+ * Either `id` or `name` must be present: `id` is used verbatim, while `name`
35
+ * is combined with `namespace` to produce `"<namespace>.<name>"`.
36
+ */
37
+ export interface ApToolDefinition {
38
+ /** Fully-qualified module ID. Takes precedence over `namespace`/`name`. */
39
+ id?: string;
40
+ /** Namespace segment of the generated module ID. */
41
+ namespace?: string;
42
+ /** Name segment of the generated module ID (snake_cased if camelCase). */
43
+ name?: string;
44
+ /** Human-readable description surfaced to AI clients. Required. */
45
+ description: string;
46
+ /** TypeBox, Zod, or plain JSON Schema describing the inputs. */
47
+ inputSchema?: unknown;
48
+ /** TypeBox, Zod, or plain JSON Schema describing the output. */
49
+ outputSchema?: unknown;
50
+ annotations?: ApToolAnnotations | null;
51
+ tags?: string[];
52
+ documentation?: string | null;
53
+ examples?: ApToolExample[];
54
+ /**
55
+ * Per-parameter prose merged into the input schema's property descriptions.
56
+ *
57
+ * JavaScript cannot read a function's leading comments at run time — the way
58
+ * Python reads a docstring — so parameter documentation is declared here
59
+ * rather than inferred from JSDoc.
60
+ */
61
+ params?: Record<string, string>;
62
+ /** The function executed when the tool is called. */
63
+ handler: ApToolHandler;
64
+ }
65
+ /** Shared defaults applied to every tool in a {@link defineToolset} group. */
66
+ export interface ApToolsetOptions {
67
+ namespace: string;
68
+ description?: string | null;
69
+ tags?: string[];
70
+ annotations?: ApToolAnnotations | null;
71
+ tools: Record<string, Omit<ApToolDefinition, 'namespace' | 'name' | 'description'> & {
72
+ name?: string;
73
+ /** Falls back to the toolset description, then the record key. */
74
+ description?: string;
75
+ }>;
76
+ }
77
+ /** Options accepted by {@link createApcore} / the {@link HonoApcore} constructor. */
78
+ export interface HonoApcoreOptions {
79
+ /** Directory scanned by `Registry.discover()` for filesystem extensions. */
80
+ extensionsDir?: string | null;
81
+ /** apcore `ACL` instance enforced by the Executor on every call. */
82
+ acl?: unknown | null;
83
+ /** apcore `Middleware` instances installed on the Executor. */
84
+ middleware?: unknown[];
85
+ /** Path to a YAML bindings file loaded during {@link HonoApcore.init}. */
86
+ bindings?: string | null;
87
+ /** Tools registered eagerly during construction. */
88
+ tools?: ApToolDefinition[];
89
+ /** MCP surface configuration. Presence enables the MCP service. */
90
+ mcp?: ApcoreMcpOptions;
91
+ /** CLI surface configuration. Presence enables the CLI service. */
92
+ cli?: ApcoreCliOptions;
93
+ /** A2A surface configuration. Presence enables the A2A service. */
94
+ a2a?: ApcoreA2aOptions;
95
+ /** Route-scanner configuration used by {@link HonoApcore.scanRoutes}. */
96
+ routes?: RouteScanOptions;
97
+ /** Overrides merged over the `APCORE_*` environment settings. */
98
+ settings?: Partial<import('./config.js').ApcoreSettings>;
99
+ }
100
+ /** Options for the MCP surface. Mirrors `apcore-mcp`'s serve options. */
101
+ export interface ApcoreMcpOptions {
102
+ transport?: 'stdio' | 'streamable-http' | 'sse';
103
+ host?: string;
104
+ port?: number;
105
+ name?: string;
106
+ version?: string;
107
+ tags?: string[] | null;
108
+ prefix?: string | null;
109
+ explorer?: boolean;
110
+ explorerPrefix?: string;
111
+ allowExecute?: boolean;
112
+ explorerTitle?: string;
113
+ explorerProjectName?: string;
114
+ explorerProjectUrl?: string;
115
+ dynamic?: boolean;
116
+ validateInputs?: boolean;
117
+ logLevel?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR' | 'CRITICAL';
118
+ onStartup?: () => void | Promise<void>;
119
+ onShutdown?: () => void | Promise<void>;
120
+ metricsCollector?: unknown;
121
+ authenticator?: unknown;
122
+ requireAuth?: boolean;
123
+ exemptPaths?: string[];
124
+ approvalHandler?: unknown;
125
+ outputFormatter?: (result: Record<string, unknown>) => string;
126
+ /** Enable the full observability stack (metrics + usage middleware). */
127
+ observability?: unknown;
128
+ /** Built-in output format ("json", "csv", "jsonl"). */
129
+ outputFormat?: 'json' | 'csv' | 'jsonl';
130
+ /** Redact sensitive fields from tool output. Default: true. */
131
+ redactOutput?: boolean;
132
+ /** Attach a pipeline trace to tool responses. Default: false. */
133
+ trace?: boolean;
134
+ /** Execution strategy name. */
135
+ strategy?: string;
136
+ /** Additional apcore middleware installed on the MCP executor. */
137
+ mcpMiddleware?: unknown[];
138
+ /** Optional ACL instance for this MCP server. */
139
+ mcpAcl?: unknown;
140
+ /** Pluggable ApprovalStore for async approval polling. */
141
+ approvalStore?: unknown;
142
+ /** Callback invoked when a new approval is requested. */
143
+ approvalNotify?: (approvalId: string, moduleId: string, args: Record<string, unknown>) => Promise<void>;
144
+ }
145
+ /** Options for mounting the MCP endpoint into a Hono app. */
146
+ export interface MountMcpOptions {
147
+ /** Path the MCP endpoint is served at. Default: `"/mcp"`. */
148
+ endpoint?: string;
149
+ /** Enable the Tool Explorer UI. Defaults to the MCP surface setting. */
150
+ explorer?: boolean;
151
+ /** URL prefix for the Explorer. Default: `"/explorer"`. */
152
+ explorerPrefix?: string;
153
+ /** Allow tool execution from the Explorer UI. */
154
+ allowExecute?: boolean;
155
+ /** Also mount `/health` and `/metrics`. Default: true. */
156
+ builtinRoutes?: boolean;
157
+ }
158
+ /** Options for the CLI surface. */
159
+ export interface ApcoreCliOptions {
160
+ /** Path to the extensions directory (default: `./extensions`). */
161
+ extensionsDir?: string;
162
+ /** Program name shown in help output. */
163
+ progName?: string;
164
+ /** Show built-in apcore options in `--help`. Default: false. */
165
+ verboseHelp?: boolean;
166
+ /** Base URL for online documentation. */
167
+ docsUrl?: string | null;
168
+ }
169
+ /** Options for the A2A surface. */
170
+ export interface ApcoreA2aOptions {
171
+ name?: string;
172
+ description?: string;
173
+ version?: string;
174
+ url?: string;
175
+ host?: string;
176
+ /** Port for a standalone A2A server. Omit to embed via `asyncServe()`. */
177
+ port?: number;
178
+ auth?: unknown;
179
+ taskStore?: unknown;
180
+ corsOrigins?: string[];
181
+ explorer?: boolean;
182
+ explorerPrefix?: string;
183
+ executionTimeout?: number;
184
+ metrics?: boolean;
185
+ logLevel?: string;
186
+ shutdownTimeout?: number;
187
+ }
188
+ /** Options controlling how Hono routes are turned into apcore modules. */
189
+ export interface RouteScanOptions {
190
+ /** Prefix prepended to every generated module ID. */
191
+ modulePrefix?: string;
192
+ /** Only scan routes whose path matches one of these glob-ish patterns. */
193
+ includePaths?: string[];
194
+ /** Skip routes whose path matches one of these patterns. */
195
+ excludePaths?: string[];
196
+ /** Skip these HTTP methods. Default: `["HEAD", "OPTIONS"]`. */
197
+ excludeMethods?: string[];
198
+ /** Regex applied to generated module IDs — only matches are kept. */
199
+ include?: string;
200
+ /** Regex applied to generated module IDs — matches are removed. */
201
+ exclude?: string;
202
+ /** Tags attached to every scanned module. Default: `["http"]`. */
203
+ tags?: string[];
204
+ /** Per-route overrides keyed by `"<METHOD> <path>"`. */
205
+ overrides?: Record<string, RouteOverride>;
206
+ /** Base URL used when replaying requests through `app.request()`. */
207
+ baseUrl?: string;
208
+ }
209
+ /** Per-route metadata overrides applied during scanning. */
210
+ export interface RouteOverride {
211
+ id?: string;
212
+ description?: string;
213
+ inputSchema?: unknown;
214
+ outputSchema?: unknown;
215
+ annotations?: ApToolAnnotations | null;
216
+ tags?: string[];
217
+ documentation?: string | null;
218
+ examples?: ApToolExample[];
219
+ /** Skip this route entirely. */
220
+ skip?: boolean;
221
+ }
222
+ /** Options for registering a single method of a plain object as a module. */
223
+ export interface RegisterMethodOptions {
224
+ instance: object;
225
+ method: string;
226
+ description: string;
227
+ id?: string;
228
+ inputSchema?: unknown;
229
+ outputSchema?: unknown;
230
+ annotations?: ApToolAnnotations;
231
+ tags?: string[];
232
+ documentation?: string | null;
233
+ examples?: ApToolExample[];
234
+ }
235
+ /** Options for registering every method of an object at once. */
236
+ export interface RegisterObjectOptions {
237
+ instance: object;
238
+ description?: string;
239
+ methods: string[] | '*';
240
+ exclude?: string[];
241
+ namespace?: string;
242
+ annotations?: ApToolAnnotations;
243
+ tags?: string[];
244
+ methodOptions?: Record<string, Partial<RegisterMethodOptions>>;
245
+ }
246
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"m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,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;CAChE"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Convert a PascalCase or camelCase string to snake_case.
3
+ *
4
+ * Handles consecutive uppercase letters (acronyms) by inserting an
5
+ * underscore before the last uppercase letter of the run when it is
6
+ * followed by a lowercase letter — `"HTTPClient"` becomes `"http_client"`.
7
+ */
8
+ export declare function toSnakeCase(value: string): string;
9
+ /**
10
+ * Normalise a service/object name into a namespace segment: strip a trailing
11
+ * service suffix, then convert the remainder to snake_case.
12
+ *
13
+ * A name consisting *only* of a suffix is kept as-is (lowercased) rather than
14
+ * collapsing to an empty string.
15
+ *
16
+ * @example
17
+ * normalizeName('TodoService') // 'todo'
18
+ * normalizeName('WeatherRoutes') // 'weather'
19
+ * normalizeName('HTTPClient') // 'http_client'
20
+ */
21
+ export declare function normalizeName(name: string): string;
22
+ /**
23
+ * Normalise a method / tool name by converting camelCase to snake_case.
24
+ *
25
+ * @example
26
+ * normalizeMethodName('sendEmail') // 'send_email'
27
+ * normalizeMethodName('send_email') // 'send_email'
28
+ */
29
+ export declare function normalizeMethodName(name: string): string;
30
+ /**
31
+ * Build a fully-qualified module ID of the form `"namespace.name"`.
32
+ *
33
+ * @param namespace - Namespace portion of the ID.
34
+ * @param name - Name portion of the ID.
35
+ * @param normalizeInputs - Apply {@link normalizeName} / {@link normalizeMethodName}
36
+ * to the two segments before joining.
37
+ * @param explicitId - Returned verbatim when non-null, bypassing generation.
38
+ *
39
+ * @example
40
+ * generateModuleId('todo', 'list') // 'todo.list'
41
+ * generateModuleId('TodoService', 'listAll', true) // 'todo.list_all'
42
+ * generateModuleId('a', 'b', false, 'custom.override') // 'custom.override'
43
+ */
44
+ export declare function generateModuleId(namespace: string, name: string, normalizeInputs?: boolean, explicitId?: string | null): string;
45
+ /**
46
+ * Prepend a module-ID prefix, inserting the separating dot only when needed.
47
+ *
48
+ * An empty prefix returns the ID unchanged, and a prefix that already ends
49
+ * with `"."` is not given a second one.
50
+ */
51
+ export declare function applyModulePrefix(moduleId: string, prefix?: string): string;
52
+ //# sourceMappingURL=id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.d.ts","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAUD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWlD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,eAAe,CAAC,EAAE,OAAO,EACzB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,MAAM,CASR;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAG3E"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Convert a PascalCase or camelCase string to snake_case.
3
+ *
4
+ * Handles consecutive uppercase letters (acronyms) by inserting an
5
+ * underscore before the last uppercase letter of the run when it is
6
+ * followed by a lowercase letter — `"HTTPClient"` becomes `"http_client"`.
7
+ */
8
+ export function toSnakeCase(value) {
9
+ return value
10
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
11
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
12
+ .replace(/[\s-]+/g, '_')
13
+ .toLowerCase();
14
+ }
15
+ /**
16
+ * Suffixes stripped from handler/object names before normalisation.
17
+ *
18
+ * Hono has no class conventions of its own, so this covers the names people
19
+ * actually give the plain service objects they register.
20
+ */
21
+ const SERVICE_SUFFIXES = ['Service', 'Handler', 'Handlers', 'Controller', 'Routes', 'Router'];
22
+ /**
23
+ * Normalise a service/object name into a namespace segment: strip a trailing
24
+ * service suffix, then convert the remainder to snake_case.
25
+ *
26
+ * A name consisting *only* of a suffix is kept as-is (lowercased) rather than
27
+ * collapsing to an empty string.
28
+ *
29
+ * @example
30
+ * normalizeName('TodoService') // 'todo'
31
+ * normalizeName('WeatherRoutes') // 'weather'
32
+ * normalizeName('HTTPClient') // 'http_client'
33
+ */
34
+ export function normalizeName(name) {
35
+ let stripped = name;
36
+ for (const suffix of SERVICE_SUFFIXES) {
37
+ if (name.endsWith(suffix) && name.length > suffix.length) {
38
+ stripped = name.slice(0, -suffix.length);
39
+ break;
40
+ }
41
+ }
42
+ return toSnakeCase(stripped);
43
+ }
44
+ /**
45
+ * Normalise a method / tool name by converting camelCase to snake_case.
46
+ *
47
+ * @example
48
+ * normalizeMethodName('sendEmail') // 'send_email'
49
+ * normalizeMethodName('send_email') // 'send_email'
50
+ */
51
+ export function normalizeMethodName(name) {
52
+ return toSnakeCase(name);
53
+ }
54
+ /**
55
+ * Build a fully-qualified module ID of the form `"namespace.name"`.
56
+ *
57
+ * @param namespace - Namespace portion of the ID.
58
+ * @param name - Name portion of the ID.
59
+ * @param normalizeInputs - Apply {@link normalizeName} / {@link normalizeMethodName}
60
+ * to the two segments before joining.
61
+ * @param explicitId - Returned verbatim when non-null, bypassing generation.
62
+ *
63
+ * @example
64
+ * generateModuleId('todo', 'list') // 'todo.list'
65
+ * generateModuleId('TodoService', 'listAll', true) // 'todo.list_all'
66
+ * generateModuleId('a', 'b', false, 'custom.override') // 'custom.override'
67
+ */
68
+ export function generateModuleId(namespace, name, normalizeInputs, explicitId) {
69
+ if (explicitId != null) {
70
+ return explicitId;
71
+ }
72
+ const ns = normalizeInputs ? normalizeName(namespace) : namespace;
73
+ const n = normalizeInputs ? normalizeMethodName(name) : name;
74
+ return ns.length > 0 ? `${ns}.${n}` : n;
75
+ }
76
+ /**
77
+ * Prepend a module-ID prefix, inserting the separating dot only when needed.
78
+ *
79
+ * An empty prefix returns the ID unchanged, and a prefix that already ends
80
+ * with `"."` is not given a second one.
81
+ */
82
+ export function applyModulePrefix(moduleId, prefix) {
83
+ if (!prefix)
84
+ return moduleId;
85
+ return prefix.endsWith('.') ? `${prefix}${moduleId}` : `${prefix}.${moduleId}`;
86
+ }
87
+ //# sourceMappingURL=id-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,KAAK;SACT,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;SACzC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,WAAW,EAAE,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE9F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,QAAQ,GAAG,IAAI,CAAC;IAEpB,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,M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 import type { ApToolAnnotations } from '../types.js';
5
+ /**
6
+ * Execute-function signature for Hono-bound modules.
7
+ *
8
+ * Unlike apcore-toolkit's `RegistryWriter` — which resolves a `target` string
9
+ * via dynamic import — a Hono integration already holds the closure, so the
10
+ * bound function is passed in directly.
11
+ */
12
+ export type BoundExecuteFn = (inputs: Record<string, unknown>, context: unknown) => Promise<Record<string, unknown>> | Record<string, unknown>;
13
+ /**
14
+ * Normalise a raw handler return value to a plain `Record<string, unknown>`.
15
+ *
16
+ * `null` / `undefined` become `{}`; arrays and primitives are wrapped as
17
+ * `{ result }` so every module honours the object-output contract.
18
+ */
19
+ export declare function normalizeResult(raw: unknown): Record<string, unknown>;
20
+ /**
21
+ * Widen partial {@link ApToolAnnotations} (all-optional booleans) into a full
22
+ * `ModuleAnnotations` by spreading over apcore-js's `DEFAULT_ANNOTATIONS`.
23
+ *
24
+ * Returns `null` when the input is nullish.
25
+ */
26
+ export declare function toModuleAnnotations(partial: ApToolAnnotations | null | undefined): ModuleAnnotations | null;
27
+ /**
28
+ * Convert a toolkit {@link ScannedModule} plus a pre-bound execute function
29
+ * into an apcore-js `FunctionModule` ready for registry registration.
30
+ */
31
+ export declare function scannedModuleToFunctionModule(mod: ScannedModule, execute: BoundExecuteFn): FunctionModule;
32
+ /** An empty JSON Schema object, used when a tool declares no schema. */
33
+ export declare const EMPTY_OBJECT_SCHEMA: Record<string, unknown>;
34
+ //# sourceMappingURL=module-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-factory.d.ts","sourceRoot":"","sources":["../../src/utils/module-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA4C,MAAM,WAAW,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,WAAW,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIrE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAC5C,iBAAiB,GAAG,IAAI,CAG1B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,cAAc,GACtB,cAAc,CAuBhB;AAED,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAGtD,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { FunctionModule, DEFAULT_ANNOTATIONS, jsonSchemaToTypeBox } from 'apcore-js';
2
+ import { annotationsToDict } from 'apcore-toolkit';
3
+ /**
4
+ * Normalise a raw handler return value to a plain `Record<string, unknown>`.
5
+ *
6
+ * `null` / `undefined` become `{}`; arrays and primitives are wrapped as
7
+ * `{ result }` so every module honours the object-output contract.
8
+ */
9
+ export function normalizeResult(raw) {
10
+ if (raw === null || raw === undefined)
11
+ return {};
12
+ if (typeof raw === 'object' && !Array.isArray(raw))
13
+ return raw;
14
+ return { result: raw };
15
+ }
16
+ /**
17
+ * Widen partial {@link ApToolAnnotations} (all-optional booleans) into a full
18
+ * `ModuleAnnotations` by spreading over apcore-js's `DEFAULT_ANNOTATIONS`.
19
+ *
20
+ * Returns `null` when the input is nullish.
21
+ */
22
+ export function toModuleAnnotations(partial) {
23
+ if (partial == null)
24
+ return null;
25
+ return { ...DEFAULT_ANNOTATIONS, ...partial };
26
+ }
27
+ /**
28
+ * Convert a toolkit {@link ScannedModule} plus a pre-bound execute function
29
+ * into an apcore-js `FunctionModule` ready for registry registration.
30
+ */
31
+ export function scannedModuleToFunctionModule(mod, execute) {
32
+ // Strip internal keys (leading underscore) from metadata so they do not
33
+ // leak into the module's public descriptor.
34
+ const cleanMetadata = {};
35
+ for (const [k, v] of Object.entries(mod.metadata)) {
36
+ if (!k.startsWith('_')) {
37
+ cleanMetadata[k] = v;
38
+ }
39
+ }
40
+ return new FunctionModule({
41
+ execute,
42
+ moduleId: mod.moduleId,
43
+ inputSchema: jsonSchemaToTypeBox(mod.inputSchema),
44
+ outputSchema: jsonSchemaToTypeBox(mod.outputSchema),
45
+ description: mod.description,
46
+ documentation: mod.documentation,
47
+ tags: mod.tags.length > 0 ? [...mod.tags] : null,
48
+ version: mod.version,
49
+ annotations: annotationsToDict(mod.annotations),
50
+ metadata: Object.keys(cleanMetadata).length > 0 ? cleanMetadata : null,
51
+ examples: mod.examples.length > 0 ? [...mod.examples] : null,
52
+ });
53
+ }
54
+ /** An empty JSON Schema object, used when a tool declares no schema. */
55
+ export const EMPTY_OBJECT_SCHEMA = Object.freeze({
56
+ type: 'object',
57
+ properties: {},
58
+ });
59
+ //# sourceMappingURL=module-factory.js.map