@decocms/runtime 0.28.1 → 1.0.0-alpha-candy.2

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 (97) hide show
  1. package/package.json +12 -78
  2. package/scripts/generate-json-schema.ts +24 -0
  3. package/src/asset-server/dev-server-proxy.ts +16 -0
  4. package/src/asset-server/index.ts +44 -0
  5. package/src/bindings/README.md +1 -1
  6. package/src/bindings/binder.ts +2 -5
  7. package/src/bindings/channels.ts +1 -1
  8. package/src/bindings/index.ts +0 -33
  9. package/src/bindings/language-model/utils.ts +0 -91
  10. package/src/bindings.ts +30 -108
  11. package/src/client.ts +1 -145
  12. package/src/index.ts +46 -175
  13. package/src/mcp.ts +8 -165
  14. package/src/proxy.ts +3 -62
  15. package/src/state.ts +1 -30
  16. package/src/tools.ts +336 -0
  17. package/src/wrangler.ts +5 -5
  18. package/tsconfig.json +8 -0
  19. package/dist/admin.d.ts +0 -5
  20. package/dist/admin.js +0 -21
  21. package/dist/admin.js.map +0 -1
  22. package/dist/bindings/deconfig/index.d.ts +0 -12
  23. package/dist/bindings/deconfig/index.js +0 -10
  24. package/dist/bindings/deconfig/index.js.map +0 -1
  25. package/dist/bindings/index.d.ts +0 -2315
  26. package/dist/bindings/index.js +0 -156
  27. package/dist/bindings/index.js.map +0 -1
  28. package/dist/chunk-3AWMDSOH.js +0 -96
  29. package/dist/chunk-3AWMDSOH.js.map +0 -1
  30. package/dist/chunk-4XSQKJLU.js +0 -105
  31. package/dist/chunk-4XSQKJLU.js.map +0 -1
  32. package/dist/chunk-5EYZ2LVM.js +0 -158
  33. package/dist/chunk-5EYZ2LVM.js.map +0 -1
  34. package/dist/chunk-7ITSLORK.js +0 -128
  35. package/dist/chunk-7ITSLORK.js.map +0 -1
  36. package/dist/chunk-I7BWSAN6.js +0 -49
  37. package/dist/chunk-I7BWSAN6.js.map +0 -1
  38. package/dist/chunk-L4OT2YDO.js +0 -27
  39. package/dist/chunk-L4OT2YDO.js.map +0 -1
  40. package/dist/chunk-SHQSNOFL.js +0 -769
  41. package/dist/chunk-SHQSNOFL.js.map +0 -1
  42. package/dist/chunk-UHR3BLMF.js +0 -92
  43. package/dist/chunk-UHR3BLMF.js.map +0 -1
  44. package/dist/chunk-UIJGM3NV.js +0 -518
  45. package/dist/chunk-UIJGM3NV.js.map +0 -1
  46. package/dist/chunk-ZPUT6RN6.js +0 -32
  47. package/dist/chunk-ZPUT6RN6.js.map +0 -1
  48. package/dist/client.d.ts +0 -28
  49. package/dist/client.js +0 -5
  50. package/dist/client.js.map +0 -1
  51. package/dist/d1-store.d.ts +0 -9
  52. package/dist/d1-store.js +0 -4
  53. package/dist/d1-store.js.map +0 -1
  54. package/dist/drizzle.d.ts +0 -49
  55. package/dist/drizzle.js +0 -121
  56. package/dist/drizzle.js.map +0 -1
  57. package/dist/index-LOfgE9a_.d.ts +0 -471
  58. package/dist/index-xKtm7A7B.d.ts +0 -530
  59. package/dist/index.d.ts +0 -10
  60. package/dist/index.js +0 -637
  61. package/dist/index.js.map +0 -1
  62. package/dist/mastra.d.ts +0 -10
  63. package/dist/mastra.js +0 -6
  64. package/dist/mastra.js.map +0 -1
  65. package/dist/mcp-87iLaW9V.d.ts +0 -105
  66. package/dist/mcp-client.d.ts +0 -232
  67. package/dist/mcp-client.js +0 -4
  68. package/dist/mcp-client.js.map +0 -1
  69. package/dist/proxy.d.ts +0 -11
  70. package/dist/proxy.js +0 -5
  71. package/dist/proxy.js.map +0 -1
  72. package/dist/resources.d.ts +0 -362
  73. package/dist/resources.js +0 -4
  74. package/dist/resources.js.map +0 -1
  75. package/dist/views.d.ts +0 -72
  76. package/dist/views.js +0 -4
  77. package/dist/views.js.map +0 -1
  78. package/src/admin.ts +0 -16
  79. package/src/auth.ts +0 -233
  80. package/src/bindings/deconfig/helpers.ts +0 -107
  81. package/src/bindings/deconfig/index.ts +0 -1
  82. package/src/bindings/deconfig/resources.ts +0 -659
  83. package/src/bindings/deconfig/types.ts +0 -106
  84. package/src/bindings/language-model/ai-sdk.ts +0 -87
  85. package/src/bindings/language-model/index.ts +0 -4
  86. package/src/bindings/resources/bindings.ts +0 -99
  87. package/src/bindings/resources/helpers.ts +0 -95
  88. package/src/bindings/resources/schemas.ts +0 -265
  89. package/src/bindings/views.ts +0 -14
  90. package/src/cf-imports.ts +0 -1
  91. package/src/d1-store.ts +0 -34
  92. package/src/deprecated.ts +0 -59
  93. package/src/drizzle.ts +0 -201
  94. package/src/mastra.ts +0 -898
  95. package/src/resources.ts +0 -168
  96. package/src/views.ts +0 -26
  97. package/src/workflow.ts +0 -193
package/src/resources.ts DELETED
@@ -1,168 +0,0 @@
1
- import { z } from "zod/v3";
2
- import mimeDb from "mime-db";
3
-
4
- type MimeDb = Record<string, { extensions?: string[] }>;
5
-
6
- const EXTENSION_TO_MIME = (() => {
7
- const map = new Map<string, string>();
8
- Object.entries(mimeDb as MimeDb).forEach(([type, meta]) => {
9
- meta.extensions?.forEach((ext) => {
10
- if (!map.has(ext)) {
11
- map.set(ext, type);
12
- }
13
- });
14
- });
15
- return map;
16
- })();
17
-
18
- function extractExtension(value: string): string | undefined {
19
- if (!value) return undefined;
20
- const trimmed = value.trim();
21
- if (!trimmed) return undefined;
22
-
23
- const sanitized = trimmed.replace(/^[^?#]*/g, (match) => match);
24
- const withoutQuery = sanitized.split(/[?#]/)[0];
25
-
26
- if (withoutQuery.startsWith(".")) {
27
- return withoutQuery.slice(1).toLowerCase();
28
- }
29
-
30
- if (!withoutQuery.includes(".")) {
31
- if (!withoutQuery.includes("/") && !withoutQuery.includes("\\")) {
32
- return withoutQuery.toLowerCase();
33
- }
34
- return undefined;
35
- }
36
-
37
- const lastDot = withoutQuery.lastIndexOf(".");
38
- if (lastDot === -1 || lastDot === withoutQuery.length - 1) return undefined;
39
- return withoutQuery.slice(lastDot + 1).toLowerCase();
40
- }
41
-
42
- // Base Resource Schema (enhanced)
43
- const ResourceSchema = z.object({
44
- name: z.string(),
45
- title: z.string().optional(),
46
- description: z.string().optional(),
47
- uri: z.string().url(),
48
- mimeType: z.string().optional(),
49
- thumbnail: z.string().url().optional(),
50
- timestamp: z.string().datetime().optional(),
51
- size: z.number().positive().optional(),
52
- annotations: z.record(z.string(), z.string()).optional(),
53
- });
54
-
55
- // Tool Input/Output Schemas (unified)
56
- export const ResourcesReadInputSchema = z.object({
57
- name: z.string().describe("Resource type name (e.g., 'Page', 'GoogleDrive')"),
58
- uri: z
59
- .string()
60
- .url()
61
- .describe(
62
- "The URI of the resource to read. It's important to add the url scheme. Use file:// for files. Use https:// or http:// for remote files",
63
- ),
64
- });
65
-
66
- export const ResourcesReadOutputSchema = ResourceSchema.extend({
67
- data: z.string().describe("The resource content as a string"),
68
- type: z
69
- .enum(["text", "blob"])
70
- .describe(
71
- "Type of data: 'text' for plain text, 'blob' for base64-encoded binary",
72
- ),
73
- });
74
-
75
- export const ResourceSearchInputSchema = z.object({
76
- name: z.string().describe("Resource type name (e.g., 'Page', 'GoogleDrive')"),
77
- term: z.string().describe("The term to search for"),
78
- cursor: z.string().optional(),
79
- limit: z.number().positive().optional(),
80
- });
81
-
82
- export const ResourceSearchOutputSchema = z.object({
83
- items: z.array(ResourceSchema),
84
- hasMore: z.boolean(),
85
- nextCursor: z.string().optional(),
86
- });
87
-
88
- export const ResourceCreateInputSchema = z.object({
89
- name: z.string().describe("Resource type name (e.g., 'Page', 'GoogleDrive')"),
90
- resourceName: z
91
- .string()
92
- .describe(
93
- "Name of the specific resource instance. DO NOT ADD EXTENSIONS TO THE NAME",
94
- ),
95
- title: z.string().optional(),
96
- description: z.string().optional(),
97
- content: z
98
- .object({
99
- data: z.string(),
100
- type: z.enum(["text", "blob"]),
101
- mimeType: z.string().optional(),
102
- })
103
- .describe("Content to create the resource with"),
104
- metadata: z.record(z.string(), z.any()).optional(),
105
- });
106
- export const ResourceCreateOutputSchema = ResourceSchema;
107
-
108
- export const ResourceUpdateInputSchema = z.object({
109
- name: z.string().describe("Resource type name (e.g., 'Page', 'GoogleDrive')"),
110
- uri: z.string().url().describe("URI of the resource to update"),
111
- resourceName: z.string().optional(),
112
- title: z.string().optional(),
113
- description: z.string().optional(),
114
- content: z
115
- .object({
116
- data: z.string(),
117
- type: z.enum(["text", "blob"]),
118
- mimeType: z.string().optional(),
119
- })
120
- .optional(),
121
- metadata: z.record(z.string(), z.any()).optional(),
122
- });
123
- export const ResourceUpdateOutputSchema = ResourceSchema;
124
-
125
- export const ResourceDeleteInputSchema = z.object({
126
- name: z.string().describe("Resource type name (e.g., 'Page', 'GoogleDrive')"),
127
- uri: z.string().url().describe("URI of the resource to delete"),
128
- force: z.boolean().optional(),
129
- });
130
- export const ResourceDeleteOutputSchema = z.object({
131
- deletedUri: z.string().url(),
132
- });
133
-
134
- export const ResourcesListInputSchema = z.object({});
135
- export const ResourcesListOutputSchema = z.object({
136
- resources: z.array(
137
- z.object({
138
- name: z.string(),
139
- icon: z.string(),
140
- title: z.string(),
141
- description: z.string(),
142
- hasCreate: z.boolean().optional(),
143
- hasUpdate: z.boolean().optional(),
144
- hasDelete: z.boolean().optional(),
145
- }),
146
- ),
147
- });
148
-
149
- // Export Types
150
- export type Resource = z.infer<typeof ResourceCreateOutputSchema>;
151
- export type ResourcesReadInput = z.infer<typeof ResourcesReadInputSchema>;
152
- export type ResourcesReadOutput = z.infer<typeof ResourcesReadOutputSchema>;
153
- export type ResourcesSearchInput = z.infer<typeof ResourceSearchInputSchema>;
154
- export type ResourcesSearchOutput = z.infer<typeof ResourceSearchOutputSchema>;
155
- export type ResourceCreateInput = z.infer<typeof ResourceCreateInputSchema>;
156
- export type ResourceCreateOutput = z.infer<typeof ResourceCreateOutputSchema>;
157
- export type ResourceUpdateInput = z.infer<typeof ResourceUpdateInputSchema>;
158
- export type ResourceUpdateOutput = z.infer<typeof ResourceUpdateOutputSchema>;
159
- export type ResourceDeleteInput = z.infer<typeof ResourceDeleteInputSchema>;
160
- export type ResourceDeleteOutput = z.infer<typeof ResourceDeleteOutputSchema>;
161
- export type ResourcesListInput = z.infer<typeof ResourcesListInputSchema>;
162
- export type ResourcesListOutput = z.infer<typeof ResourcesListOutputSchema>;
163
-
164
- export const mimeType = (filePathOrExtension: string) => {
165
- const ext = extractExtension(filePathOrExtension);
166
- if (!ext) return "text/plain";
167
- return EXTENSION_TO_MIME.get(ext) ?? "text/plain";
168
- };
package/src/views.ts DELETED
@@ -1,26 +0,0 @@
1
- import { z } from "zod/v3";
2
-
3
- const installBehavior = z.enum(["none", "open", "autoPin"]);
4
-
5
- // New, richer schema with backward-compat fields kept optional
6
- export const ViewsListOutputSchema = z.object({
7
- views: z.array(
8
- z.object({
9
- id: z.string().optional(),
10
- name: z.string().optional(),
11
- title: z.string(),
12
- description: z.string().optional(),
13
- icon: z.string(),
14
- url: z.string().optional(),
15
- // New acceptance rules
16
- mimeTypePattern: z.string().optional(),
17
- resourceName: z.string().optional(),
18
- // Legacy/compat fields
19
- tools: z.array(z.string()).optional().default([]),
20
- prompt: z.string().optional(),
21
- installBehavior: installBehavior.optional(),
22
- }),
23
- ),
24
- });
25
-
26
- export type ViewsListOutput = z.infer<typeof ViewsListOutputSchema>;
package/src/workflow.ts DELETED
@@ -1,193 +0,0 @@
1
- /* oxlint-disable no-explicit-any */
2
- import { type DefaultEnv, type RequestContext, withBindings } from "./index.ts";
3
- import {
4
- type AppContext,
5
- type CreateMCPServerOptions,
6
- isWorkflow,
7
- MCPServer,
8
- } from "./mastra.ts";
9
-
10
- import { D1Store } from "./d1-store.ts";
11
- import { Mastra, type Workflow as MastraWorkflow } from "@mastra/core";
12
- import { RuntimeContext } from "@mastra/core/di";
13
- import { DurableObject } from "./cf-imports.ts";
14
- import { State } from "./state.ts";
15
-
16
- const createRuntimeContext = (env: DefaultEnv, ctx: DurableObjectState) => {
17
- const runtimeContext = new RuntimeContext<AppContext>();
18
- runtimeContext.set("env", env);
19
- runtimeContext.set("ctx", ctx);
20
- return runtimeContext;
21
- };
22
- export interface StartWorkflowArgs {
23
- workflowId: string;
24
- args: unknown;
25
- runId?: string;
26
- ctx: RequestContext;
27
- }
28
-
29
- export interface CancelWorkflowArgs {
30
- workflowId: string;
31
- runId?: string;
32
- ctx: RequestContext;
33
- }
34
-
35
- export interface ResumeWorkflowArgs {
36
- workflowId: string;
37
- runId?: string;
38
- resumeData: unknown;
39
- stepId: string;
40
- ctx: RequestContext;
41
- }
42
- export interface WorkflowDO extends Rpc.DurableObjectBranded {
43
- start: (args: StartWorkflowArgs) => Promise<{ runId: string }>;
44
- cancel: (args: CancelWorkflowArgs) => Promise<{ cancelled: boolean }>;
45
- resume: (args: ResumeWorkflowArgs) => Promise<{ resumed: boolean }>;
46
- }
47
-
48
- export const Workflow = (
49
- server: MCPServer<any, any>,
50
- workflows?: CreateMCPServerOptions["workflows"],
51
- ) => {
52
- return class Workflow
53
- extends DurableObject<DefaultEnv>
54
- implements WorkflowDO
55
- {
56
- constructor(
57
- // @ts-ignore: This is a workaround to fix the type error
58
- // oxlint-disable-next-line ban-types
59
- public override ctx: DurableObjectState<{}>,
60
- public override env: DefaultEnv,
61
- ) {
62
- super(ctx, env);
63
- }
64
-
65
- bindings(ctx: RequestContext) {
66
- return withBindings<DefaultEnv>({
67
- env: this.env,
68
- server,
69
- tokenOrContext: ctx,
70
- });
71
- }
72
-
73
- runWithContext<T>(
74
- ctx: RequestContext,
75
- f: (ctx: DefaultEnv) => Promise<T>,
76
- ): Promise<T> {
77
- const bindings = this.bindings(ctx);
78
- return State.run(
79
- {
80
- ctx: {
81
- waitUntil: this.ctx.waitUntil.bind(this.ctx),
82
- },
83
- env: this.bindings(ctx),
84
- },
85
- () => f(bindings),
86
- );
87
- }
88
-
89
- async #getWorkflow(
90
- workflowId: string,
91
- bindings: DefaultEnv,
92
- ): Promise<{ workflow: MastraWorkflow }> {
93
- const bindedWorkflows = await Promise.all(
94
- workflows?.map(async (workflow) => {
95
- const workflowResult = workflow(bindings);
96
- if (isWorkflow(workflowResult)) {
97
- return { workflow: workflowResult };
98
- }
99
-
100
- return await workflowResult;
101
- }) ?? [],
102
- );
103
- const workflowsMap = Object.fromEntries(
104
- bindedWorkflows.map((w) => [w.workflow.id, w.workflow]),
105
- );
106
- const d1Storage = new D1Store({
107
- client: bindings.DECO_WORKSPACE_DB,
108
- });
109
- const mastra = new Mastra({
110
- storage: d1Storage,
111
- workflows: {
112
- [workflowId]: workflowsMap[workflowId],
113
- },
114
- telemetry: {
115
- enabled: true,
116
- serviceName: `app-${
117
- this.env.DECO_CHAT_SCRIPT_SLUG ?? this.env.DECO_APP_SLUG
118
- }`,
119
- },
120
- });
121
- // since mastra workflows are thenables, so we need to wrap then into an object
122
- return { workflow: mastra.getWorkflow(workflowId) };
123
- }
124
-
125
- start({ workflowId, runId, args, ctx }: StartWorkflowArgs) {
126
- return this.runWithContext(ctx, async (bindings) => {
127
- const { workflow } = await this.#getWorkflow(workflowId, bindings);
128
-
129
- const run = await workflow.createRunAsync({
130
- runId: this.ctx.id.name ?? runId,
131
- });
132
-
133
- const promise = run.start({
134
- inputData: args,
135
- runtimeContext: createRuntimeContext(bindings, this.ctx),
136
- });
137
-
138
- this.ctx.waitUntil(
139
- promise
140
- .then(() => {
141
- console.debug("workflow", run.runId, "finished successfully");
142
- })
143
- .catch((e) => {
144
- console.error("workflow", run.runId, "finished with error", e);
145
- throw e;
146
- }),
147
- );
148
-
149
- return {
150
- runId: run.runId,
151
- };
152
- });
153
- }
154
-
155
- cancel({ workflowId, runId, ctx }: CancelWorkflowArgs) {
156
- return this.runWithContext(ctx, async () => {
157
- const { workflow } = await this.#getWorkflow(
158
- workflowId,
159
- this.bindings(ctx),
160
- );
161
- const run = await workflow.createRunAsync({
162
- runId: this.ctx.id.name ?? runId,
163
- });
164
-
165
- this.ctx.waitUntil(run.cancel());
166
-
167
- return {
168
- cancelled: true,
169
- };
170
- });
171
- }
172
- resume({ workflowId, runId, resumeData, stepId, ctx }: ResumeWorkflowArgs) {
173
- return this.runWithContext(ctx, async (bindings) => {
174
- const { workflow } = await this.#getWorkflow(workflowId, bindings);
175
- const run = await workflow.createRunAsync({
176
- runId: this.ctx.id.name ?? runId,
177
- });
178
-
179
- this.ctx.waitUntil(
180
- run.resume({
181
- resumeData,
182
- step: stepId,
183
- runtimeContext: createRuntimeContext(bindings, this.ctx),
184
- }),
185
- );
186
-
187
- return {
188
- resumed: true,
189
- };
190
- });
191
- }
192
- };
193
- };