@unifiedcommerce/core 0.1.0 → 0.2.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 (245) hide show
  1. package/dist/auth/setup.d.ts.map +1 -1
  2. package/dist/auth/setup.js +8 -3
  3. package/dist/config/types.d.ts +3 -1
  4. package/dist/config/types.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/interfaces/mcp/server.d.ts +3 -5
  9. package/dist/interfaces/mcp/server.d.ts.map +1 -1
  10. package/dist/interfaces/mcp/server.js +25 -510
  11. package/dist/interfaces/mcp/tool-builder.d.ts +120 -0
  12. package/dist/interfaces/mcp/tool-builder.d.ts.map +1 -0
  13. package/dist/interfaces/mcp/tool-builder.js +224 -0
  14. package/dist/interfaces/mcp/tools/analytics.d.ts +42 -0
  15. package/dist/interfaces/mcp/tools/analytics.d.ts.map +1 -0
  16. package/dist/interfaces/mcp/tools/analytics.js +70 -0
  17. package/dist/interfaces/mcp/tools/cart.d.ts +14 -0
  18. package/dist/interfaces/mcp/tools/cart.d.ts.map +1 -0
  19. package/dist/interfaces/mcp/tools/cart.js +47 -0
  20. package/dist/interfaces/mcp/tools/catalog.d.ts +53 -0
  21. package/dist/interfaces/mcp/tools/catalog.d.ts.map +1 -0
  22. package/dist/interfaces/mcp/tools/catalog.js +284 -0
  23. package/dist/interfaces/mcp/tools/index.d.ts +3 -0
  24. package/dist/interfaces/mcp/tools/index.d.ts.map +1 -0
  25. package/dist/interfaces/mcp/tools/index.js +20 -0
  26. package/dist/interfaces/mcp/tools/inventory.d.ts +27 -0
  27. package/dist/interfaces/mcp/tools/inventory.d.ts.map +1 -0
  28. package/dist/interfaces/mcp/tools/inventory.js +143 -0
  29. package/dist/interfaces/mcp/tools/orders.d.ts +18 -0
  30. package/dist/interfaces/mcp/tools/orders.d.ts.map +1 -0
  31. package/dist/interfaces/mcp/tools/orders.js +82 -0
  32. package/dist/interfaces/mcp/tools/pricing.d.ts +29 -0
  33. package/dist/interfaces/mcp/tools/pricing.d.ts.map +1 -0
  34. package/dist/interfaces/mcp/tools/pricing.js +90 -0
  35. package/dist/interfaces/mcp/tools/promotions.d.ts +44 -0
  36. package/dist/interfaces/mcp/tools/promotions.d.ts.map +1 -0
  37. package/dist/interfaces/mcp/tools/promotions.js +109 -0
  38. package/dist/interfaces/mcp/tools/registry.d.ts +32 -0
  39. package/dist/interfaces/mcp/tools/registry.d.ts.map +1 -0
  40. package/dist/interfaces/mcp/tools/registry.js +55 -0
  41. package/dist/interfaces/mcp/tools/search.d.ts +14 -0
  42. package/dist/interfaces/mcp/tools/search.d.ts.map +1 -0
  43. package/dist/interfaces/mcp/tools/search.js +39 -0
  44. package/dist/interfaces/mcp/tools/webhooks.d.ts +15 -0
  45. package/dist/interfaces/mcp/tools/webhooks.d.ts.map +1 -0
  46. package/dist/interfaces/mcp/tools/webhooks.js +48 -0
  47. package/dist/interfaces/mcp/transport.d.ts +17 -2
  48. package/dist/interfaces/mcp/transport.d.ts.map +1 -1
  49. package/dist/interfaces/mcp/transport.js +91 -44
  50. package/dist/interfaces/rest/router.d.ts.map +1 -1
  51. package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -1
  52. package/dist/interfaces/rest/routes/checkout.js +1 -1
  53. package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
  54. package/dist/interfaces/rest/routes/promotions.js +3 -2
  55. package/dist/kernel/database/adapter.d.ts +8 -0
  56. package/dist/kernel/database/adapter.d.ts.map +1 -1
  57. package/dist/kernel/factory/repository-factory.d.ts.map +1 -1
  58. package/dist/kernel/factory/repository-factory.js +3 -1
  59. package/dist/kernel/local-api.d.ts.map +1 -1
  60. package/dist/kernel/local-api.js +2 -0
  61. package/dist/kernel/plugin/manifest.d.ts +3 -3
  62. package/dist/kernel/plugin/manifest.d.ts.map +1 -1
  63. package/dist/kernel/plugin/manifest.js +36 -7
  64. package/dist/runtime/kernel.d.ts +1 -2
  65. package/dist/runtime/kernel.d.ts.map +1 -1
  66. package/dist/runtime/kernel.js +16 -8
  67. package/dist/runtime/server.d.ts.map +1 -1
  68. package/dist/runtime/server.js +8 -3
  69. package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
  70. package/dist/test-utils/create-pglite-adapter.js +7 -6
  71. package/dist/tsconfig.tsbuildinfo +1 -0
  72. package/package.json +2 -2
  73. package/src/adapters/console-email.ts +0 -43
  74. package/src/auth/access.ts +0 -187
  75. package/src/auth/auth-schema.ts +0 -139
  76. package/src/auth/middleware.ts +0 -161
  77. package/src/auth/org.ts +0 -41
  78. package/src/auth/permissions.ts +0 -28
  79. package/src/auth/setup.ts +0 -169
  80. package/src/auth/system-actor.ts +0 -19
  81. package/src/auth/types.ts +0 -10
  82. package/src/config/defaults.ts +0 -82
  83. package/src/config/define-config.ts +0 -53
  84. package/src/config/types.ts +0 -299
  85. package/src/generated/plugin-capabilities.d.ts +0 -20
  86. package/src/generated/plugin-manifest.ts +0 -23
  87. package/src/generated/plugin-repositories.d.ts +0 -20
  88. package/src/hooks/checkout-completion.ts +0 -262
  89. package/src/hooks/checkout.ts +0 -677
  90. package/src/hooks/order-emails.ts +0 -62
  91. package/src/index.ts +0 -214
  92. package/src/interfaces/mcp/agent-prompt.ts +0 -174
  93. package/src/interfaces/mcp/context-enrichment.ts +0 -177
  94. package/src/interfaces/mcp/server.ts +0 -617
  95. package/src/interfaces/mcp/transport.ts +0 -68
  96. package/src/interfaces/rest/customer-portal.ts +0 -299
  97. package/src/interfaces/rest/index.ts +0 -74
  98. package/src/interfaces/rest/router.ts +0 -334
  99. package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
  100. package/src/interfaces/rest/routes/audit.ts +0 -50
  101. package/src/interfaces/rest/routes/carts.ts +0 -89
  102. package/src/interfaces/rest/routes/catalog.ts +0 -493
  103. package/src/interfaces/rest/routes/checkout.ts +0 -283
  104. package/src/interfaces/rest/routes/inventory.ts +0 -70
  105. package/src/interfaces/rest/routes/media.ts +0 -86
  106. package/src/interfaces/rest/routes/orders.ts +0 -78
  107. package/src/interfaces/rest/routes/payments.ts +0 -60
  108. package/src/interfaces/rest/routes/pricing.ts +0 -57
  109. package/src/interfaces/rest/routes/promotions.ts +0 -92
  110. package/src/interfaces/rest/routes/search.ts +0 -71
  111. package/src/interfaces/rest/routes/webhooks.ts +0 -46
  112. package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
  113. package/src/interfaces/rest/schemas/audit.ts +0 -46
  114. package/src/interfaces/rest/schemas/carts.ts +0 -125
  115. package/src/interfaces/rest/schemas/catalog.ts +0 -450
  116. package/src/interfaces/rest/schemas/checkout.ts +0 -66
  117. package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
  118. package/src/interfaces/rest/schemas/inventory.ts +0 -138
  119. package/src/interfaces/rest/schemas/media.ts +0 -75
  120. package/src/interfaces/rest/schemas/orders.ts +0 -104
  121. package/src/interfaces/rest/schemas/pricing.ts +0 -80
  122. package/src/interfaces/rest/schemas/promotions.ts +0 -110
  123. package/src/interfaces/rest/schemas/responses.ts +0 -85
  124. package/src/interfaces/rest/schemas/search.ts +0 -58
  125. package/src/interfaces/rest/schemas/shared.ts +0 -62
  126. package/src/interfaces/rest/schemas/webhooks.ts +0 -68
  127. package/src/interfaces/rest/utils.ts +0 -104
  128. package/src/interfaces/rest/webhook-router.ts +0 -50
  129. package/src/kernel/compensation/executor.ts +0 -61
  130. package/src/kernel/compensation/types.ts +0 -26
  131. package/src/kernel/database/adapter.ts +0 -13
  132. package/src/kernel/database/drizzle-db.ts +0 -56
  133. package/src/kernel/database/migrate.ts +0 -76
  134. package/src/kernel/database/plugin-types.ts +0 -34
  135. package/src/kernel/database/schema.ts +0 -49
  136. package/src/kernel/database/scoped-db.ts +0 -68
  137. package/src/kernel/database/tx-context.ts +0 -46
  138. package/src/kernel/error-mapper.ts +0 -15
  139. package/src/kernel/errors.ts +0 -89
  140. package/src/kernel/factory/repository-factory.ts +0 -242
  141. package/src/kernel/hooks/create-context.ts +0 -43
  142. package/src/kernel/hooks/executor.ts +0 -88
  143. package/src/kernel/hooks/registry.ts +0 -74
  144. package/src/kernel/hooks/types.ts +0 -52
  145. package/src/kernel/http-error.ts +0 -44
  146. package/src/kernel/jobs/adapter.ts +0 -36
  147. package/src/kernel/jobs/drizzle-adapter.ts +0 -58
  148. package/src/kernel/jobs/runner.ts +0 -153
  149. package/src/kernel/jobs/schema.ts +0 -46
  150. package/src/kernel/jobs/types.ts +0 -30
  151. package/src/kernel/local-api.ts +0 -185
  152. package/src/kernel/plugin/manifest.ts +0 -253
  153. package/src/kernel/query/executor.ts +0 -184
  154. package/src/kernel/query/registry.ts +0 -46
  155. package/src/kernel/result.ts +0 -33
  156. package/src/kernel/schema/extra-columns.ts +0 -37
  157. package/src/kernel/service-registry.ts +0 -76
  158. package/src/kernel/service-timing.ts +0 -89
  159. package/src/kernel/state-machine/machine.ts +0 -101
  160. package/src/modules/analytics/drizzle-adapter.ts +0 -426
  161. package/src/modules/analytics/hooks.ts +0 -11
  162. package/src/modules/analytics/models.ts +0 -125
  163. package/src/modules/analytics/repository/index.ts +0 -6
  164. package/src/modules/analytics/service.ts +0 -245
  165. package/src/modules/analytics/types.ts +0 -180
  166. package/src/modules/audit/hooks.ts +0 -78
  167. package/src/modules/audit/schema.ts +0 -33
  168. package/src/modules/audit/service.ts +0 -151
  169. package/src/modules/cart/access.ts +0 -27
  170. package/src/modules/cart/matcher.ts +0 -26
  171. package/src/modules/cart/repository/index.ts +0 -234
  172. package/src/modules/cart/schema.ts +0 -42
  173. package/src/modules/cart/schemas.ts +0 -38
  174. package/src/modules/cart/service.ts +0 -541
  175. package/src/modules/catalog/repository/index.ts +0 -772
  176. package/src/modules/catalog/schema.ts +0 -203
  177. package/src/modules/catalog/schemas.ts +0 -104
  178. package/src/modules/catalog/service.ts +0 -1544
  179. package/src/modules/customers/repository/index.ts +0 -327
  180. package/src/modules/customers/schema.ts +0 -64
  181. package/src/modules/customers/service.ts +0 -171
  182. package/src/modules/fulfillment/repository/index.ts +0 -426
  183. package/src/modules/fulfillment/schema.ts +0 -101
  184. package/src/modules/fulfillment/service.ts +0 -555
  185. package/src/modules/fulfillment/types.ts +0 -59
  186. package/src/modules/inventory/repository/index.ts +0 -509
  187. package/src/modules/inventory/schema.ts +0 -94
  188. package/src/modules/inventory/schemas.ts +0 -38
  189. package/src/modules/inventory/service.ts +0 -490
  190. package/src/modules/media/adapter.ts +0 -17
  191. package/src/modules/media/repository/index.ts +0 -274
  192. package/src/modules/media/schema.ts +0 -41
  193. package/src/modules/media/service.ts +0 -151
  194. package/src/modules/orders/repository/index.ts +0 -287
  195. package/src/modules/orders/schema.ts +0 -66
  196. package/src/modules/orders/service.ts +0 -619
  197. package/src/modules/orders/stale-order-cleanup.ts +0 -76
  198. package/src/modules/organization/service.ts +0 -191
  199. package/src/modules/payments/adapter.ts +0 -47
  200. package/src/modules/payments/repository/index.ts +0 -6
  201. package/src/modules/payments/service.ts +0 -107
  202. package/src/modules/pricing/repository/index.ts +0 -291
  203. package/src/modules/pricing/schema.ts +0 -71
  204. package/src/modules/pricing/schemas.ts +0 -38
  205. package/src/modules/pricing/service.ts +0 -494
  206. package/src/modules/promotions/repository/index.ts +0 -325
  207. package/src/modules/promotions/schema.ts +0 -62
  208. package/src/modules/promotions/schemas.ts +0 -38
  209. package/src/modules/promotions/service.ts +0 -598
  210. package/src/modules/search/adapter.ts +0 -57
  211. package/src/modules/search/hooks.ts +0 -12
  212. package/src/modules/search/repository/index.ts +0 -6
  213. package/src/modules/search/service.ts +0 -315
  214. package/src/modules/shipping/calculator.ts +0 -188
  215. package/src/modules/shipping/repository/index.ts +0 -6
  216. package/src/modules/shipping/service.ts +0 -51
  217. package/src/modules/tax/adapter.ts +0 -60
  218. package/src/modules/tax/repository/index.ts +0 -6
  219. package/src/modules/tax/service.ts +0 -53
  220. package/src/modules/webhooks/hook.ts +0 -34
  221. package/src/modules/webhooks/repository/index.ts +0 -278
  222. package/src/modules/webhooks/schema.ts +0 -56
  223. package/src/modules/webhooks/service.ts +0 -117
  224. package/src/modules/webhooks/signing.ts +0 -6
  225. package/src/modules/webhooks/ssrf-guard.ts +0 -71
  226. package/src/modules/webhooks/tasks.ts +0 -52
  227. package/src/modules/webhooks/worker.ts +0 -134
  228. package/src/runtime/commerce.ts +0 -145
  229. package/src/runtime/kernel.ts +0 -419
  230. package/src/runtime/logger.ts +0 -36
  231. package/src/runtime/server.ts +0 -349
  232. package/src/runtime/shutdown.ts +0 -43
  233. package/src/test-utils/create-pglite-adapter.ts +0 -129
  234. package/src/test-utils/create-plugin-test-app.ts +0 -128
  235. package/src/test-utils/create-repository-test-harness.ts +0 -16
  236. package/src/test-utils/create-test-config.ts +0 -190
  237. package/src/test-utils/create-test-kernel.ts +0 -7
  238. package/src/test-utils/create-test-plugin-context.ts +0 -75
  239. package/src/test-utils/rest-api-test-utils.ts +0 -265
  240. package/src/test-utils/test-actors.ts +0 -62
  241. package/src/test-utils/typed-hooks.ts +0 -54
  242. package/src/types/commerce-types.ts +0 -34
  243. package/src/utils/id.ts +0 -3
  244. package/src/utils/logger.ts +0 -18
  245. package/src/utils/pagination.ts +0 -22
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Fluent builder for STRAP-pattern MCP tools.
3
+ *
4
+ * Produces a single MCPTool with an `action` enum from multiple
5
+ * action definitions. Each action has its own Zod schema and typed handler.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { toolBuilder } from "@unifiedcommerce/core";
10
+ *
11
+ * mcpTools: (ctx) => {
12
+ * const t = toolBuilder("loyalty", "Manage loyalty points and rewards.");
13
+ *
14
+ * t.action("balance", "Check a customer's point balance and tier.")
15
+ * .input(z.object({ customerId: z.string().describe("Customer UUID") }))
16
+ * .handler(async ({ customerId }, { services }) =>
17
+ * (services as LoyaltyServices).loyalty.getPoints(customerId),
18
+ * );
19
+ *
20
+ * t.action("earn", "Award points to a customer.")
21
+ * .input(z.object({
22
+ * customerId: z.string().describe("Customer UUID"),
23
+ * amount: z.number().int().positive().describe("Points to award"),
24
+ * }))
25
+ * .handler(async ({ customerId, amount }, { services }) =>
26
+ * (services as LoyaltyServices).loyalty.earn(customerId, amount),
27
+ * );
28
+ *
29
+ * return t.build(ctx);
30
+ * },
31
+ * ```
32
+ */
33
+ import { z } from "zod";
34
+ // ─── Action Chain ───────────────────────────────────────────────────────────
35
+ /**
36
+ * Fluent chain returned by `t.action(name, description)`.
37
+ *
38
+ * Generic parameter `TArgs` tracks the inferred input type so that
39
+ * `.handler()` receives fully typed args — no manual casts needed.
40
+ * The type is carried as a plain object type (not z.infer) so consumers
41
+ * don't need `zod` types available at compile time.
42
+ */
43
+ class ActionChain {
44
+ _name;
45
+ _description;
46
+ _actions;
47
+ _input = z.object({});
48
+ _handler;
49
+ constructor(_name, _description, _actions) {
50
+ this._name = _name;
51
+ this._description = _description;
52
+ this._actions = _actions;
53
+ }
54
+ /**
55
+ * Define the Zod input schema for this action.
56
+ * Returns a new chain typed with the inferred output so `.handler()` gets typed args.
57
+ *
58
+ * The dual generic `TSchema` / `TOut` lets TypeScript:
59
+ * 1. Infer `TSchema` from the ZodObject's raw shape (for internal storage)
60
+ * 2. Infer `TOut` from the ZodObject's output type (for handler typing)
61
+ * Since `TOut` is a plain object type (not `z.infer`), the emitted `.d.ts`
62
+ * doesn't require consumers to have `zod` types at compile time.
63
+ */
64
+ input(schema) {
65
+ // oRPC pattern: return a new instance with narrowed generic instead of
66
+ // casting `this`. Eliminates the `as unknown as` variance cast.
67
+ const chain = new ActionChain(this._name, this._description, this._actions);
68
+ chain._input = schema;
69
+ return chain;
70
+ }
71
+ /**
72
+ * Define the handler for this action.
73
+ * Receives typed args (inferred from `.input()`) and a context with services and db.
74
+ * Return any value — it is auto-wrapped in MCP result format.
75
+ */
76
+ handler(fn) {
77
+ this._handler = fn;
78
+ this._actions.push({
79
+ name: this._name,
80
+ description: this._description,
81
+ inputSchema: this._input,
82
+ handler: this._handler,
83
+ });
84
+ }
85
+ }
86
+ // ─── Tool Builder ───────────────────────────────────────────────────────────
87
+ class ToolBuilderImpl {
88
+ _name;
89
+ _description;
90
+ _actions = [];
91
+ constructor(_name, _description) {
92
+ this._name = _name;
93
+ this._description = _description;
94
+ }
95
+ /**
96
+ * Define an action on this STRAP tool.
97
+ * Returns a chain where you call .input(schema).handler(fn).
98
+ */
99
+ action(name, description) {
100
+ return new ActionChain(name, description, this._actions);
101
+ }
102
+ /**
103
+ * Build the MCPTool[] array (always 1 tool) from all registered actions.
104
+ *
105
+ * Automatically:
106
+ * - Creates the `action` enum from action names
107
+ * - Merges all action input schemas (fields become optional)
108
+ * - Generates description listing all actions
109
+ * - Generates switch/case dispatch
110
+ * - Wraps results in MCP content format
111
+ * - Handles errors consistently
112
+ */
113
+ build(ctx) {
114
+ if (this._actions.length === 0)
115
+ return [];
116
+ const actionNames = this._actions.map((a) => a.name);
117
+ // Build combined Zod schema from all action schemas.
118
+ // Each action's fields become optional (since they are only required for their specific action).
119
+ // Then use Zod v4's built-in z.toJSONSchema() for correct conversion.
120
+ const combinedShape = {
121
+ action: z.enum(actionNames).describe("Operation to perform"),
122
+ };
123
+ for (const action of this._actions) {
124
+ const shape = action.inputSchema.shape;
125
+ for (const [key, zodType] of Object.entries(shape)) {
126
+ if (key === "action")
127
+ continue;
128
+ if (combinedShape[key] != null)
129
+ continue;
130
+ // All action-specific fields are optional in the combined schema
131
+ combinedShape[key] = zodType.optional();
132
+ }
133
+ }
134
+ const combinedZodSchema = z.object(combinedShape);
135
+ const jsonSchema = z.toJSONSchema(combinedZodSchema);
136
+ const allProperties = (jsonSchema.properties ?? {});
137
+ // Generate description with action list
138
+ const actionDescriptions = this._actions
139
+ .map((a) => `${a.name} (${a.description})`)
140
+ .join(", ");
141
+ const fullDescription = `${this._description} Actions: ${actionDescriptions}.`;
142
+ // Build the dispatch handler
143
+ const actions = this._actions;
144
+ const handlerCtx = {
145
+ services: ctx.services,
146
+ db: ctx.database.db,
147
+ logger: ctx.logger,
148
+ };
149
+ const tool = {
150
+ name: this._name,
151
+ description: fullDescription,
152
+ inputSchema: {
153
+ type: "object",
154
+ properties: allProperties,
155
+ required: ["action"],
156
+ },
157
+ handler: async (params) => {
158
+ const args = (params != null && typeof params === "object" && !Array.isArray(params))
159
+ ? params
160
+ : {};
161
+ const actionName = args.action;
162
+ if (!actionName) {
163
+ return {
164
+ content: [{ type: "text", text: JSON.stringify({ error: "action is required" }) }],
165
+ };
166
+ }
167
+ const matchedAction = actions.find((a) => a.name === actionName);
168
+ if (!matchedAction) {
169
+ return {
170
+ content: [{
171
+ type: "text",
172
+ text: JSON.stringify({
173
+ error: `Unknown action: ${actionName}. Available: ${actionNames.join(", ")}`,
174
+ }),
175
+ }],
176
+ };
177
+ }
178
+ try {
179
+ // Validate input against action-specific schema
180
+ const parsed = matchedAction.inputSchema.safeParse(args);
181
+ const validatedArgs = parsed.success ? parsed.data : args;
182
+ const result = await matchedAction.handler(validatedArgs, handlerCtx);
183
+ // Check for Result<T> pattern (ok/error)
184
+ if (result != null && typeof result === "object") {
185
+ const r = result;
186
+ if ("ok" in r && r.ok === false && "error" in r) {
187
+ return {
188
+ content: [{ type: "text", text: JSON.stringify({ error: r.error }, null, 2) }],
189
+ };
190
+ }
191
+ if ("ok" in r && r.ok === true && "value" in r) {
192
+ return {
193
+ content: [{ type: "text", text: JSON.stringify(r.value, null, 2) }],
194
+ };
195
+ }
196
+ }
197
+ return {
198
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
199
+ };
200
+ }
201
+ catch (err) {
202
+ return {
203
+ content: [{
204
+ type: "text",
205
+ text: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }, null, 2),
206
+ }],
207
+ };
208
+ }
209
+ },
210
+ };
211
+ return [tool];
212
+ }
213
+ }
214
+ // ─── Public API ─────────────────────────────────────────────────────────────
215
+ /**
216
+ * Create a STRAP-pattern MCP tool builder.
217
+ *
218
+ * @param name - Tool name in snake_case (e.g., "loyalty", "pos_shift")
219
+ * @param description - Base description explaining the tool's domain.
220
+ * Action descriptions are appended automatically.
221
+ */
222
+ export function toolBuilder(name, description) {
223
+ return new ToolBuilderImpl(name, description);
224
+ }
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "./registry.js";
3
+ export declare const analyticsQuery: ToolDefinition<z.ZodObject<{
4
+ measures: z.ZodArray<z.ZodString>;
5
+ dimensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
+ timeDimensions: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
+ dimension: z.ZodString;
8
+ granularity: z.ZodOptional<z.ZodEnum<{
9
+ month: "month";
10
+ day: "day";
11
+ week: "week";
12
+ year: "year";
13
+ }>>;
14
+ dateRange: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodTuple<[z.ZodString, z.ZodString], null>]>>;
15
+ }, z.core.$strip>>>;
16
+ filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
17
+ member: z.ZodString;
18
+ operator: z.ZodEnum<{
19
+ in: "in";
20
+ gt: "gt";
21
+ gte: "gte";
22
+ lt: "lt";
23
+ lte: "lte";
24
+ contains: "contains";
25
+ equals: "equals";
26
+ notEquals: "notEquals";
27
+ notIn: "notIn";
28
+ beforeDate: "beforeDate";
29
+ afterDate: "afterDate";
30
+ inDateRange: "inDateRange";
31
+ }>;
32
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
33
+ }, z.core.$strip>>>;
34
+ order: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
35
+ asc: "asc";
36
+ desc: "desc";
37
+ }>>>;
38
+ limit: z.ZodDefault<z.ZodNumber>;
39
+ }, z.core.$strip>>;
40
+ export declare const analyticsMeta: ToolDefinition<z.ZodObject<{}, z.core.$strip>>;
41
+ export declare const analyticsTools: ToolDefinition[];
42
+ //# sourceMappingURL=analytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/mcp/tools/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkDzB,CAAC;AAEH,eAAO,MAAM,aAAa,gDAYxB,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,cAAc,EAG1C,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "./registry.js";
3
+ import { buildAnalyticsScope } from "../../../modules/analytics/types.js";
4
+ export const analyticsQuery = defineTool({
5
+ name: "analytics_query",
6
+ description: "Query analytics using semantic measures, dimensions, time dimensions, " +
7
+ "and filters. Use when the user asks about revenue, sales trends, order " +
8
+ "metrics, or any business intelligence question. Always call analytics_meta " +
9
+ "first to discover available measures.",
10
+ inputSchema: z.object({
11
+ measures: z.array(z.string()).min(1).describe("Measure names (e.g. Orders.totalRevenue)"),
12
+ dimensions: z.array(z.string()).optional().describe("Dimension names to group by"),
13
+ timeDimensions: z.array(z.object({
14
+ dimension: z.string().describe("Time dimension name"),
15
+ granularity: z.enum(["day", "week", "month", "year"]).optional().describe("Time granularity"),
16
+ dateRange: z.union([
17
+ z.string(),
18
+ z.tuple([z.string(), z.string()]),
19
+ ]).optional().describe("Date range: preset string or [from, to] tuple"),
20
+ })).optional().describe("Time dimensions for trend analysis"),
21
+ filters: z.array(z.object({
22
+ member: z.string().describe("Measure or dimension to filter on"),
23
+ operator: z.enum([
24
+ "equals", "notEquals", "contains", "in", "notIn",
25
+ "gt", "gte", "lt", "lte", "beforeDate", "afterDate", "inDateRange",
26
+ ]).describe("Comparison operator"),
27
+ values: z.array(z.string()).optional().describe("Filter values"),
28
+ })).optional().describe("Query filters"),
29
+ order: z.record(z.string(), z.enum(["asc", "desc"])).optional().describe("Sort order by measure/dimension"),
30
+ limit: z.number().int().positive().default(100).describe("Max rows to return"),
31
+ }),
32
+ async handler({ measures, dimensions, timeDimensions, filters, order, limit }, kernel) {
33
+ const queryParams = {
34
+ measures,
35
+ ...(dimensions != null ? { dimensions } : {}),
36
+ ...(timeDimensions != null
37
+ ? { timeDimensions: timeDimensions }
38
+ : {}),
39
+ ...(filters != null
40
+ ? { filters: filters }
41
+ : {}),
42
+ ...(order != null
43
+ ? { order: order }
44
+ : {}),
45
+ ...(limit !== undefined ? { limit } : {}),
46
+ };
47
+ const analyticsScope = buildAnalyticsScope(kernel.getMCPActor());
48
+ const result = await kernel.services.analytics.query(queryParams, analyticsScope);
49
+ if (!result.ok)
50
+ return { _error: result.error };
51
+ return result.value;
52
+ },
53
+ });
54
+ export const analyticsMeta = defineTool({
55
+ name: "analytics_meta",
56
+ description: "List available analytics measures, dimensions, segments, and models. " +
57
+ "Use this before analytics_query to discover what measures and dimensions " +
58
+ "you can query. Call this first when the user asks analytics questions.",
59
+ inputSchema: z.object({}),
60
+ async handler(_args, kernel) {
61
+ const result = await kernel.services.analytics.getMeta();
62
+ if (!result.ok)
63
+ return { _error: result.error };
64
+ return result.value;
65
+ },
66
+ });
67
+ export const analyticsTools = [
68
+ analyticsQuery,
69
+ analyticsMeta,
70
+ ];
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "./registry.js";
3
+ export declare const cartCreate: ToolDefinition<z.ZodObject<{
4
+ customerId: z.ZodOptional<z.ZodString>;
5
+ currency: z.ZodDefault<z.ZodString>;
6
+ }, z.core.$strip>>;
7
+ export declare const cartAddItem: ToolDefinition<z.ZodObject<{
8
+ cartId: z.ZodString;
9
+ entityId: z.ZodString;
10
+ variantId: z.ZodOptional<z.ZodString>;
11
+ quantity: z.ZodDefault<z.ZodNumber>;
12
+ }, z.core.$strip>>;
13
+ export declare const cartTools: ToolDefinition[];
14
+ //# sourceMappingURL=cart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/mcp/tools/cart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,eAAO,MAAM,UAAU;;;kBAoBrB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;kBAyBtB,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,cAAc,EAGrC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "./registry.js";
3
+ export const cartCreate = defineTool({
4
+ name: "cart_create",
5
+ description: "Create a new shopping cart. Use when the user wants to start a new order " +
6
+ "or add items for purchase. Returns the cart ID for subsequent operations.",
7
+ inputSchema: z.object({
8
+ customerId: z.string().optional().describe("Customer UUID to associate the cart with"),
9
+ currency: z.string().default("USD").describe("Cart currency (ISO 4217)"),
10
+ }),
11
+ async handler({ customerId, currency }, kernel) {
12
+ const result = await kernel.services.cart.create({
13
+ ...(customerId !== undefined ? { customerId } : {}),
14
+ ...(currency !== undefined ? { currency } : {}),
15
+ }, kernel.getMCPActor());
16
+ if (!result.ok)
17
+ return { _error: result.error };
18
+ return result.value;
19
+ },
20
+ });
21
+ export const cartAddItem = defineTool({
22
+ name: "cart_add_item",
23
+ description: "Add an item to a cart. Use when the user wants to add a product to their " +
24
+ "cart. If the entity has variants and no variantId is provided, the call " +
25
+ "fails and returns available variants for selection.",
26
+ inputSchema: z.object({
27
+ cartId: z.string().describe("UUID of the cart"),
28
+ entityId: z.string().describe("UUID of the catalog entity to add"),
29
+ variantId: z.string().optional().describe("Variant UUID (required if entity has variants)"),
30
+ quantity: z.number().int().positive().default(1).describe("Quantity to add"),
31
+ }),
32
+ async handler({ cartId, entityId, variantId, quantity }, kernel) {
33
+ const result = await kernel.services.cart.addItem({
34
+ cartId,
35
+ entityId,
36
+ ...(variantId !== undefined ? { variantId } : {}),
37
+ quantity,
38
+ }, kernel.getMCPActor());
39
+ if (!result.ok)
40
+ return { _error: result.error };
41
+ return result.value;
42
+ },
43
+ });
44
+ export const cartTools = [
45
+ cartCreate,
46
+ cartAddItem,
47
+ ];
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "./registry.js";
3
+ export declare const catalogSearch: ToolDefinition<z.ZodObject<{
4
+ query: z.ZodOptional<z.ZodString>;
5
+ type: z.ZodOptional<z.ZodString>;
6
+ status: z.ZodOptional<z.ZodString>;
7
+ categorySlug: z.ZodOptional<z.ZodString>;
8
+ brandSlug: z.ZodOptional<z.ZodString>;
9
+ page: z.ZodDefault<z.ZodNumber>;
10
+ limit: z.ZodDefault<z.ZodNumber>;
11
+ }, z.core.$strip>>;
12
+ export declare const catalogCreate: ToolDefinition<z.ZodObject<{
13
+ type: z.ZodString;
14
+ slug: z.ZodString;
15
+ title: z.ZodString;
16
+ description: z.ZodOptional<z.ZodString>;
17
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
18
+ }, z.core.$strip>>;
19
+ export declare const catalogGet: ToolDefinition<z.ZodObject<{
20
+ entityId: z.ZodOptional<z.ZodString>;
21
+ slug: z.ZodOptional<z.ZodString>;
22
+ locale: z.ZodDefault<z.ZodString>;
23
+ }, z.core.$strip>>;
24
+ export declare const catalogManage: ToolDefinition<z.ZodObject<{
25
+ action: z.ZodEnum<{
26
+ delete: "delete";
27
+ update: "update";
28
+ publish: "publish";
29
+ archive: "archive";
30
+ discontinue: "discontinue";
31
+ set_attributes: "set_attributes";
32
+ assign_category: "assign_category";
33
+ unassign_category: "unassign_category";
34
+ assign_brand: "assign_brand";
35
+ unassign_brand: "unassign_brand";
36
+ create_variant: "create_variant";
37
+ }>;
38
+ entityId: z.ZodString;
39
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
40
+ isVisible: z.ZodOptional<z.ZodBoolean>;
41
+ locale: z.ZodOptional<z.ZodString>;
42
+ title: z.ZodOptional<z.ZodString>;
43
+ subtitle: z.ZodOptional<z.ZodString>;
44
+ description: z.ZodOptional<z.ZodString>;
45
+ richDescription: z.ZodOptional<z.ZodString>;
46
+ seoTitle: z.ZodOptional<z.ZodString>;
47
+ seoDescription: z.ZodOptional<z.ZodString>;
48
+ categoryId: z.ZodOptional<z.ZodString>;
49
+ brandId: z.ZodOptional<z.ZodString>;
50
+ sku: z.ZodOptional<z.ZodString>;
51
+ }, z.core.$strip>>;
52
+ export declare const catalogTools: ToolDefinition[];
53
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/mcp/tools/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKpD,eAAO,MAAM,aAAa;;;;;;;;kBA+ExB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;kBA+BxB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;kBA8CrB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0HxB,CAAC;AAEH,eAAO,MAAM,YAAY,EAAE,cAAc,EAKxC,CAAC"}