@decocms/runtime 0.28.0 → 1.0.0-alpha.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.
- package/package.json +15 -76
- package/scripts/generate-json-schema.ts +24 -0
- package/src/asset-server/dev-server-proxy.ts +16 -0
- package/src/asset-server/index.ts +44 -0
- package/src/bindings/README.md +1 -1
- package/src/bindings/binder.ts +1 -1
- package/src/bindings/channels.ts +1 -1
- package/src/bindings/deconfig/resources.ts +47 -17
- package/src/bindings/deconfig/types.ts +1 -1
- package/src/bindings/index.ts +2 -0
- package/src/bindings/language-model/ai-sdk.ts +7 -4
- package/src/bindings/resources/bindings.ts +1 -1
- package/src/bindings/resources/schemas.ts +1 -1
- package/src/bindings/views.ts +1 -1
- package/src/bindings.ts +8 -7
- package/src/index.ts +5 -20
- package/src/mastra.ts +1 -229
- package/src/mcp.ts +7 -6
- package/src/proxy.ts +0 -8
- package/src/resources.ts +1 -1
- package/src/state.ts +1 -1
- package/src/views.ts +1 -1
- package/tsconfig.json +8 -0
- package/dist/admin.d.ts +0 -5
- package/dist/admin.js +0 -21
- package/dist/admin.js.map +0 -1
- package/dist/bindings/deconfig/index.d.ts +0 -12
- package/dist/bindings/deconfig/index.js +0 -10
- package/dist/bindings/deconfig/index.js.map +0 -1
- package/dist/bindings/index.d.ts +0 -2312
- package/dist/bindings/index.js +0 -135
- package/dist/bindings/index.js.map +0 -1
- package/dist/chunk-3AWMDSOH.js +0 -96
- package/dist/chunk-3AWMDSOH.js.map +0 -1
- package/dist/chunk-4XSQKJLU.js +0 -105
- package/dist/chunk-4XSQKJLU.js.map +0 -1
- package/dist/chunk-5EYZ2LVM.js +0 -158
- package/dist/chunk-5EYZ2LVM.js.map +0 -1
- package/dist/chunk-7ITSLORK.js +0 -128
- package/dist/chunk-7ITSLORK.js.map +0 -1
- package/dist/chunk-I7BWSAN6.js +0 -49
- package/dist/chunk-I7BWSAN6.js.map +0 -1
- package/dist/chunk-L4OT2YDO.js +0 -27
- package/dist/chunk-L4OT2YDO.js.map +0 -1
- package/dist/chunk-SHQSNOFL.js +0 -769
- package/dist/chunk-SHQSNOFL.js.map +0 -1
- package/dist/chunk-UHR3BLMF.js +0 -92
- package/dist/chunk-UHR3BLMF.js.map +0 -1
- package/dist/chunk-UIJGM3NV.js +0 -518
- package/dist/chunk-UIJGM3NV.js.map +0 -1
- package/dist/chunk-ZPUT6RN6.js +0 -32
- package/dist/chunk-ZPUT6RN6.js.map +0 -1
- package/dist/client.d.ts +0 -28
- package/dist/client.js +0 -5
- package/dist/client.js.map +0 -1
- package/dist/d1-store.d.ts +0 -9
- package/dist/d1-store.js +0 -4
- package/dist/d1-store.js.map +0 -1
- package/dist/drizzle.d.ts +0 -49
- package/dist/drizzle.js +0 -121
- package/dist/drizzle.js.map +0 -1
- package/dist/index-B7U9jXW4.d.ts +0 -530
- package/dist/index-uCMd27hU.d.ts +0 -471
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -637
- package/dist/index.js.map +0 -1
- package/dist/mastra.d.ts +0 -10
- package/dist/mastra.js +0 -6
- package/dist/mastra.js.map +0 -1
- package/dist/mcp-DYmQ2RQf.d.ts +0 -105
- package/dist/mcp-client.d.ts +0 -232
- package/dist/mcp-client.js +0 -4
- package/dist/mcp-client.js.map +0 -1
- package/dist/proxy.d.ts +0 -11
- package/dist/proxy.js +0 -5
- package/dist/proxy.js.map +0 -1
- package/dist/resources.d.ts +0 -362
- package/dist/resources.js +0 -4
- package/dist/resources.js.map +0 -1
- package/dist/views.d.ts +0 -72
- package/dist/views.js +0 -4
- package/dist/views.js.map +0 -1
- package/src/cf-imports.ts +0 -1
- package/src/d1-store.ts +0 -34
- package/src/deprecated.ts +0 -59
- package/src/workflow.ts +0 -193
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
|
-
};
|