@decocms/runtime 0.28.1 → 1.0.0-alpha.5

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 (86) hide show
  1. package/config-schema.json +553 -0
  2. package/package.json +15 -76
  3. package/scripts/generate-json-schema.ts +24 -0
  4. package/src/asset-server/dev-server-proxy.ts +16 -0
  5. package/src/asset-server/index.ts +44 -0
  6. package/src/bindings/README.md +1 -1
  7. package/src/bindings/binder.ts +1 -1
  8. package/src/bindings/channels.ts +1 -1
  9. package/src/bindings/deconfig/resources.ts +47 -17
  10. package/src/bindings/deconfig/types.ts +1 -1
  11. package/src/bindings/language-model/ai-sdk.ts +7 -4
  12. package/src/bindings/resources/bindings.ts +1 -1
  13. package/src/bindings/resources/schemas.ts +1 -1
  14. package/src/bindings/views.ts +1 -1
  15. package/src/bindings.ts +8 -7
  16. package/src/index.ts +5 -20
  17. package/src/mastra.ts +1 -229
  18. package/src/mcp.ts +7 -6
  19. package/src/proxy.ts +0 -8
  20. package/src/resources.ts +1 -1
  21. package/src/state.ts +1 -1
  22. package/src/views.ts +1 -1
  23. package/tsconfig.json +8 -0
  24. package/dist/admin.d.ts +0 -5
  25. package/dist/admin.js +0 -21
  26. package/dist/admin.js.map +0 -1
  27. package/dist/bindings/deconfig/index.d.ts +0 -12
  28. package/dist/bindings/deconfig/index.js +0 -10
  29. package/dist/bindings/deconfig/index.js.map +0 -1
  30. package/dist/bindings/index.d.ts +0 -2315
  31. package/dist/bindings/index.js +0 -156
  32. package/dist/bindings/index.js.map +0 -1
  33. package/dist/chunk-3AWMDSOH.js +0 -96
  34. package/dist/chunk-3AWMDSOH.js.map +0 -1
  35. package/dist/chunk-4XSQKJLU.js +0 -105
  36. package/dist/chunk-4XSQKJLU.js.map +0 -1
  37. package/dist/chunk-5EYZ2LVM.js +0 -158
  38. package/dist/chunk-5EYZ2LVM.js.map +0 -1
  39. package/dist/chunk-7ITSLORK.js +0 -128
  40. package/dist/chunk-7ITSLORK.js.map +0 -1
  41. package/dist/chunk-I7BWSAN6.js +0 -49
  42. package/dist/chunk-I7BWSAN6.js.map +0 -1
  43. package/dist/chunk-L4OT2YDO.js +0 -27
  44. package/dist/chunk-L4OT2YDO.js.map +0 -1
  45. package/dist/chunk-SHQSNOFL.js +0 -769
  46. package/dist/chunk-SHQSNOFL.js.map +0 -1
  47. package/dist/chunk-UHR3BLMF.js +0 -92
  48. package/dist/chunk-UHR3BLMF.js.map +0 -1
  49. package/dist/chunk-UIJGM3NV.js +0 -518
  50. package/dist/chunk-UIJGM3NV.js.map +0 -1
  51. package/dist/chunk-ZPUT6RN6.js +0 -32
  52. package/dist/chunk-ZPUT6RN6.js.map +0 -1
  53. package/dist/client.d.ts +0 -28
  54. package/dist/client.js +0 -5
  55. package/dist/client.js.map +0 -1
  56. package/dist/d1-store.d.ts +0 -9
  57. package/dist/d1-store.js +0 -4
  58. package/dist/d1-store.js.map +0 -1
  59. package/dist/drizzle.d.ts +0 -49
  60. package/dist/drizzle.js +0 -121
  61. package/dist/drizzle.js.map +0 -1
  62. package/dist/index-LOfgE9a_.d.ts +0 -471
  63. package/dist/index-xKtm7A7B.d.ts +0 -530
  64. package/dist/index.d.ts +0 -10
  65. package/dist/index.js +0 -637
  66. package/dist/index.js.map +0 -1
  67. package/dist/mastra.d.ts +0 -10
  68. package/dist/mastra.js +0 -6
  69. package/dist/mastra.js.map +0 -1
  70. package/dist/mcp-87iLaW9V.d.ts +0 -105
  71. package/dist/mcp-client.d.ts +0 -232
  72. package/dist/mcp-client.js +0 -4
  73. package/dist/mcp-client.js.map +0 -1
  74. package/dist/proxy.d.ts +0 -11
  75. package/dist/proxy.js +0 -5
  76. package/dist/proxy.js.map +0 -1
  77. package/dist/resources.d.ts +0 -362
  78. package/dist/resources.js +0 -4
  79. package/dist/resources.js.map +0 -1
  80. package/dist/views.d.ts +0 -72
  81. package/dist/views.js +0 -4
  82. package/dist/views.js.map +0 -1
  83. package/src/cf-imports.ts +0 -1
  84. package/src/d1-store.ts +0 -34
  85. package/src/deprecated.ts +0 -59
  86. package/src/workflow.ts +0 -193
package/src/mastra.ts CHANGED
@@ -6,18 +6,10 @@ import {
6
6
  Tool,
7
7
  type ToolAction,
8
8
  type ToolExecutionContext,
9
- type Workflow,
10
9
  } from "@mastra/core";
11
10
  import { RuntimeContext } from "@mastra/core/di";
12
- import {
13
- createWorkflow,
14
- createStep as mastraCreateStep,
15
- type DefaultEngineType,
16
- type ExecuteFunction,
17
- type Step as MastraStep,
18
- } from "@mastra/core/workflows";
19
11
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
20
- import { z } from "zod/v3";
12
+ import { z } from "zod";
21
13
  import { zodToJsonSchema } from "zod-to-json-schema";
22
14
  import type { DefaultEnv } from "./index.ts";
23
15
  import {
@@ -35,9 +27,6 @@ import {
35
27
  } from "./resources.ts";
36
28
  import { createStateValidationTool, State } from "./state.ts";
37
29
  import { ViewsListOutputSchema } from "./views.ts";
38
- export { createWorkflow };
39
-
40
- export { cloneStep, cloneWorkflow } from "@mastra/core/workflows";
41
30
 
42
31
  export const createRuntimeContext = (prev?: RuntimeContext<AppContext>) => {
43
32
  const runtimeContext = new RuntimeContext<AppContext>();
@@ -207,111 +196,6 @@ export type ExecWithContext<TF extends (...args: any[]) => any> = (
207
196
  },
208
197
  ) => ReturnType<TF>;
209
198
 
210
- export interface Step<
211
- TStepId extends string = string,
212
- // @ts-expect-error - TState is not a ZodObject
213
- TState extends z.ZodObject<any> = z.ZodObject<any, z.$strip>,
214
- TSchemaIn extends z.ZodType<any> = z.ZodType<any>,
215
- TSchemaOut extends z.ZodType<any> = z.ZodType<any>,
216
- TResumeSchema extends z.ZodType<any> = z.ZodType<any>,
217
- TSuspendSchema extends z.ZodType<any> = z.ZodType<any>,
218
- TEngineType = any,
219
- > extends Omit<
220
- MastraStep<
221
- TStepId,
222
- TState,
223
- TSchemaIn,
224
- TSchemaOut,
225
- TResumeSchema,
226
- TSuspendSchema,
227
- TEngineType
228
- >,
229
- "execute"
230
- > {
231
- execute: ExecWithContext<
232
- ExecuteFunction<
233
- z.infer<TState>,
234
- z.infer<TSchemaIn>,
235
- z.infer<TSchemaOut>,
236
- z.infer<TResumeSchema>,
237
- z.infer<TSuspendSchema>,
238
- TEngineType
239
- >
240
- >;
241
- }
242
- export function createStepFromTool<
243
- TSchemaIn extends z.ZodType<any>,
244
- TSchemaOut extends z.ZodType<any>,
245
- TSuspendSchema extends z.ZodType<any>,
246
- TResumeSchema extends z.ZodType<any>,
247
- TContext extends ToolExecutionContext<
248
- TSchemaIn,
249
- TSuspendSchema,
250
- TResumeSchema
251
- >,
252
- >(
253
- tool: Tool<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext> & {
254
- inputSchema: TSchemaIn;
255
- outputSchema: TSchemaOut;
256
- execute: (context: TContext) => Promise<any>;
257
- },
258
- ): Step<
259
- string,
260
- // @ts-expect-error - TSchemaIn is not a ZodType
261
- TSchemaIn,
262
- TSchemaOut,
263
- z.ZodType<any>,
264
- z.ZodType<any>,
265
- DefaultEngineType
266
- > {
267
- // @ts-expect-error - TSchemaIn is not a ZodType
268
- return mastraCreateStep(tool);
269
- }
270
-
271
- export function createStep<
272
- TStepId extends string,
273
- TStepInput extends z.ZodType<any>,
274
- TStepOutput extends z.ZodType<any>,
275
- TResumeSchema extends z.ZodType<any>,
276
- TSuspendSchema extends z.ZodType<any>,
277
- >(opts: {
278
- id: TStepId;
279
- description?: string;
280
- inputSchema: TStepInput;
281
- outputSchema: TStepOutput;
282
- resumeSchema?: TResumeSchema;
283
- suspendSchema?: TSuspendSchema;
284
- execute: ExecWithContext<
285
- // @ts-expect-error - TStepInput is not a ZodObject
286
- ExecuteFunction<
287
- z.infer<TStepInput>,
288
- z.infer<TStepOutput>,
289
- z.infer<TResumeSchema>,
290
- z.infer<TSuspendSchema>,
291
- DefaultEngineType
292
- >
293
- >;
294
- }): Step<
295
- TStepId,
296
- // @ts-expect-error - TStepInput is not a ZodObject
297
- TStepInput,
298
- TStepOutput,
299
- TResumeSchema,
300
- TSuspendSchema,
301
- DefaultEngineType
302
- > {
303
- // @ts-expect-error - TStepInput is not a ZodObject
304
- return mastraCreateStep({
305
- ...opts,
306
- execute: (input) => {
307
- return opts.execute({
308
- ...input,
309
- runtimeContext: createRuntimeContext(input.runtimeContext),
310
- });
311
- },
312
- });
313
- }
314
-
315
199
  export interface ViewExport {
316
200
  title: string;
317
201
  icon: string;
@@ -392,13 +276,6 @@ export interface CreateMCPServerOptions<
392
276
  | ((
393
277
  env: Env & DefaultEnv<TSchema>,
394
278
  ) => CreatedTool[] | Promise<CreatedTool[]>);
395
- workflows?: Array<
396
- (
397
- env: Env & DefaultEnv<TSchema>,
398
- ) => // this is a workaround to allow workflows to be thenables
399
- | Promise<{ workflow: ReturnType<typeof createWorkflow> }>
400
- | ReturnType<typeof createWorkflow>
401
- >;
402
279
  }
403
280
 
404
281
  export type Fetch<TEnv = any> = (
@@ -441,89 +318,6 @@ const decoChatOAuthToolsFor = <TSchema extends z.ZodTypeAny = never>({
441
318
  ];
442
319
  };
443
320
 
444
- const createWorkflowTools = <TEnv = any, TSchema extends z.ZodTypeAny = never>(
445
- workflow: ReturnType<typeof createWorkflow>,
446
- bindings: TEnv & DefaultEnv<TSchema>,
447
- ) => {
448
- const startTool = createTool({
449
- id: `DECO_CHAT_WORKFLOWS_START_${workflow.id}`,
450
- description: workflow.description ?? `Start workflow ${workflow.id}`,
451
- inputSchema:
452
- workflow.inputSchema && "shape" in workflow.inputSchema
453
- ? workflow.inputSchema
454
- : z.object({}),
455
- outputSchema: z.object({
456
- id: z.string(),
457
- }),
458
- execute: async (args) => {
459
- const store = State.getStore();
460
- const runId =
461
- store?.req?.headers.get("x-deco-chat-run-id") ?? crypto.randomUUID();
462
- const workflowDO = bindings.DECO_WORKFLOW_DO.get(
463
- bindings.DECO_WORKFLOW_DO.idFromName(runId),
464
- );
465
-
466
- using result = await workflowDO.start({
467
- workflowId: workflow.id,
468
- args: args.context,
469
- runId,
470
- ctx: bindings.DECO_REQUEST_CONTEXT,
471
- });
472
- return { id: result.runId };
473
- },
474
- });
475
-
476
- const cancelTool = createTool({
477
- id: `DECO_CHAT_WORKFLOWS_CANCEL_${workflow.id}`,
478
- description: `Cancel ${workflow.description ?? `workflow ${workflow.id}`}`,
479
- inputSchema: z.object({ runId: z.string() }),
480
- outputSchema: z.object({ cancelled: z.boolean() }),
481
- execute: async (args) => {
482
- const runId = args.context.runId;
483
- const workflowDO = bindings.DECO_WORKFLOW_DO.get(
484
- bindings.DECO_WORKFLOW_DO.idFromName(runId),
485
- );
486
-
487
- using _ = await workflowDO.cancel({
488
- workflowId: workflow.id,
489
- runId,
490
- ctx: bindings.DECO_REQUEST_CONTEXT,
491
- });
492
-
493
- return { cancelled: true };
494
- },
495
- });
496
-
497
- const resumeTool = createTool({
498
- id: `DECO_CHAT_WORKFLOWS_RESUME_${workflow.id}`,
499
- description: `Resume ${workflow.description ?? `workflow ${workflow.id}`}`,
500
- inputSchema: z.object({
501
- runId: z.string(),
502
- stepId: z.string(),
503
- resumeData: z.any(),
504
- }),
505
- outputSchema: z.object({ resumed: z.boolean() }),
506
- execute: async (args) => {
507
- const runId = args.context.runId;
508
- const workflowDO = bindings.DECO_WORKFLOW_DO.get(
509
- bindings.DECO_WORKFLOW_DO.idFromName(runId),
510
- );
511
-
512
- using _ = await workflowDO.resume({
513
- workflowId: workflow.id,
514
- runId,
515
- resumeData: args.context.resumeData,
516
- stepId: args.context.stepId,
517
- ctx: bindings.DECO_REQUEST_CONTEXT,
518
- });
519
-
520
- return { resumed: true };
521
- },
522
- });
523
-
524
- return [startTool, cancelTool, resumeTool];
525
- };
526
-
527
321
  type CallTool = (opts: {
528
322
  toolCallId: string;
529
323
  toolCallInput: any;
@@ -534,10 +328,6 @@ export type MCPServer<TEnv = any, TSchema extends z.ZodTypeAny = never> = {
534
328
  callTool: CallTool;
535
329
  };
536
330
 
537
- export const isWorkflow = (value: any): value is Workflow => {
538
- return value && !(value instanceof Promise);
539
- };
540
-
541
331
  export const createMCPServer = <
542
332
  TEnv = any,
543
333
  TSchema extends z.ZodTypeAny = never,
@@ -706,24 +496,6 @@ export const createMCPServer = <
706
496
  };
707
497
  const tools = await toolsFn(bindings);
708
498
 
709
- // since mastra workflows are thenables, we need to await and add as a prop
710
- const workflows = await Promise.all(
711
- options.workflows?.map(async (workflow) => {
712
- const workflowResult = workflow(bindings);
713
- if (isWorkflow(workflowResult)) {
714
- return { workflow: workflowResult };
715
- }
716
-
717
- return await workflowResult;
718
- }) ?? [],
719
- ).then((w) => w.map((w) => w.workflow));
720
-
721
- const workflowTools =
722
- workflows?.flatMap((workflow) =>
723
- createWorkflowTools(workflow, bindings),
724
- ) ?? [];
725
-
726
- tools.push(...workflowTools);
727
499
  tools.push(...decoChatOAuthToolsFor<TSchema>(options.oauth));
728
500
  tools.push(createStateValidationTool(options.oauth?.state));
729
501
 
package/src/mcp.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  /* oxlint-disable no-explicit-any */
2
- import { env } from "cloudflare:workers";
3
- import { z } from "zod/v3";
2
+ import { z } from "zod";
4
3
  import type { MCPConnection } from "./connection.ts";
5
- import type { DefaultEnv } from "./index.ts";
6
4
  import { createMCPClientProxy } from "./proxy.ts";
7
5
  import type { ToolBinder } from "@decocms/bindings";
8
6
 
@@ -69,9 +67,11 @@ export const MCPClient = new Proxy(
69
67
  forWorkspace: (
70
68
  workspace: string,
71
69
  token?: string,
70
+ decoCmsApiUrl?: string,
72
71
  ) => MCPClientFetchStub<typeof workspaceTools>;
73
72
  forConnection: <TDefinition extends readonly ToolBinder[]>(
74
73
  connection: MCPConnectionProvider,
74
+ decoCmsApiUrl?: string,
75
75
  ) => MCPClientFetchStub<TDefinition>;
76
76
  },
77
77
  {
@@ -81,20 +81,21 @@ export const MCPClient = new Proxy(
81
81
  }
82
82
 
83
83
  if (name === "forWorkspace") {
84
- return (workspace: string, token?: string) =>
84
+ return (workspace: string, token?: string, decoCmsApiUrl?: string) =>
85
85
  createMCPFetchStub<[]>({
86
86
  workspace,
87
87
  token,
88
- decoCmsApiUrl: (env as DefaultEnv).DECO_API_URL,
88
+ decoCmsApiUrl,
89
89
  });
90
90
  }
91
91
  if (name === "forConnection") {
92
92
  return <TDefinition extends readonly ToolBinder[]>(
93
93
  connection: MCPConnectionProvider,
94
+ decoCmsApiUrl?: string,
94
95
  ) =>
95
96
  createMCPFetchStub<TDefinition>({
96
97
  connection,
97
- decoCmsApiUrl: (env as DefaultEnv).DECO_API_URL,
98
+ decoCmsApiUrl,
98
99
  });
99
100
  }
100
101
  return global[name as keyof typeof global];
package/src/proxy.ts CHANGED
@@ -53,14 +53,6 @@ function supportsToolNameInPath(url: string): boolean {
53
53
  export function createMCPClientProxy<T extends Record<string, unknown>>(
54
54
  options?: CreateStubAPIOptions,
55
55
  ): T {
56
- if (typeof options?.connection === "function") {
57
- // [DEPRECATED] Passing a function as 'connection' is deprecated and will be removed in a future release.
58
- // Please provide a connection object instead.
59
- throw new Error(
60
- "Deprecation Notice: Passing a function as 'connection' is deprecated and will be removed in a future release. Please provide a connection object instead.",
61
- );
62
- }
63
-
64
56
  const mcpPath = options?.mcpPath ?? "/mcp";
65
57
 
66
58
  const connection: MCPConnection = options?.connection || {
package/src/resources.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from "zod/v3";
1
+ import { z } from "zod";
2
2
  import mimeDb from "mime-db";
3
3
 
4
4
  type MimeDb = Record<string, { extensions?: string[] }>;
package/src/state.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
- import { z } from "zod/v3";
2
+ import { z } from "zod";
3
3
  import type { AppContext } from "./mastra.ts";
4
4
  import { createTool } from "./mastra.ts";
5
5
 
package/src/views.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from "zod/v3";
1
+ import { z } from "zod";
2
2
 
3
3
  const installBehavior = z.enum(["none", "open", "autoPin"]);
4
4
 
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["@cloudflare/workers-types"]
5
+ },
6
+ "include": ["src/**/*"],
7
+ "exclude": ["node_modules", "dist", "scripts/**/*"]
8
+ }
package/dist/admin.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare const requestMissingScopes: ({ scopes }: {
2
- scopes: string[];
3
- }) => void;
4
-
5
- export { requestMissingScopes };
package/dist/admin.js DELETED
@@ -1,21 +0,0 @@
1
- import './chunk-I7BWSAN6.js';
2
- import { createChannel } from 'bidc';
3
-
4
- var requestMissingScopes = ({ scopes }) => {
5
- try {
6
- const channel = createChannel();
7
- channel.send({
8
- type: "request_missing_scopes",
9
- payload: {
10
- scopes
11
- }
12
- });
13
- channel.cleanup();
14
- } catch (error) {
15
- console.error("Failed to request missing scopes", error);
16
- }
17
- };
18
-
19
- export { requestMissingScopes };
20
- //# sourceMappingURL=admin.js.map
21
- //# sourceMappingURL=admin.js.map
package/dist/admin.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/admin.ts"],"names":[],"mappings":";;;AAEO,IAAM,oBAAA,GAAuB,CAAC,EAAE,MAAA,EAAO,KAA4B;AACxE,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,aAAA,EAAc;AAC9B,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,MACX,IAAA,EAAM,wBAAA;AAAA,MACN,OAAA,EAAS;AAAA,QACP;AAAA;AACF,KACD,CAAA;AACD,IAAA,OAAA,CAAQ,OAAA,EAAQ;AAAA,EAClB,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,KAAA,CAAM,oCAAoC,KAAK,CAAA;AAAA,EACzD;AACF","file":"admin.js","sourcesContent":["import { createChannel } from \"bidc\";\n\nexport const requestMissingScopes = ({ scopes }: { scopes: string[] }) => {\n try {\n const channel = createChannel();\n channel.send({\n type: \"request_missing_scopes\",\n payload: {\n scopes,\n },\n });\n channel.cleanup();\n } catch (error) {\n console.error(\"Failed to request missing scopes\", error);\n }\n};\n"]}
@@ -1,12 +0,0 @@
1
- export { D as DeconfigClient, i as DeconfigResource, b as DeconfigResourceOptions, E as EnhancedResourcesTools, N as NotFoundError, h as RESOURCE_WATCH_BASE_PATHNAME, R as ResourcesBinding, d as ResourcesTools, U as UserInputError, W as WatchOptions, a as createDeconfigResource } from '../../index-xKtm7A7B.js';
2
- import '@mastra/core';
3
- import '../../index-LOfgE9a_.js';
4
- import '@cloudflare/workers-types';
5
- import 'zod/v3';
6
- import '@mastra/core/di';
7
- import '@mastra/core/workflows';
8
- import '../../resources.js';
9
- import '../../mcp-87iLaW9V.js';
10
- import '@decocms/bindings/connection';
11
- import '@decocms/bindings';
12
- import 'zod';
@@ -1,10 +0,0 @@
1
- export { DeconfigResource, NotFoundError, RESOURCE_WATCH_BASE_PATHNAME, UserInputError, createDeconfigResource } from '../../chunk-SHQSNOFL.js';
2
- import '../../chunk-5EYZ2LVM.js';
3
- import '../../chunk-3AWMDSOH.js';
4
- import '../../chunk-UHR3BLMF.js';
5
- import '../../chunk-UIJGM3NV.js';
6
- import '../../chunk-L4OT2YDO.js';
7
- import '../../chunk-7ITSLORK.js';
8
- import '../../chunk-I7BWSAN6.js';
9
- //# sourceMappingURL=index.js.map
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}