feat(server): enhance script execution and workflow management
- Introduced compileWorkflowScripts function to parse and validate workflow scripts, supporting both linear and DAG execution modes. - Added runLinearSteps and runDagSteps functions for executing compiled workflows based on their structure. - Updated createRegistry function to utilize the new workflow compilation and execution logic. - Enhanced script sandbox with meta extraction and instantiation capabilities for better script management. - Improved API endpoints to return script metadata and handle errors more effectively. - Removed deprecated scripts and updated workflows to reflect new structure and functionality.
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
export const NEW_SCRIPT_TEMPLATE = `export default async function main(ctx) {
|
||||
export const NEW_SCRIPT_TEMPLATE = `async function main(ctx) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
main.meta = {
|
||||
description: "",
|
||||
config: {},
|
||||
input: {},
|
||||
output: {},
|
||||
example: {
|
||||
data: {},
|
||||
config: {},
|
||||
},
|
||||
};
|
||||
|
||||
export default main;
|
||||
`;
|
||||
|
||||
export const DEFAULT_INPUT_CONTEXT = `{
|
||||
@@ -23,3 +36,28 @@ export function prettyJson(value) {
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultsFromFields(fields) {
|
||||
if (fields == null || typeof fields !== "object" || Array.isArray(fields)) return {};
|
||||
/** @type {Record<string, unknown>} */
|
||||
const out = {};
|
||||
for (const [key, spec] of Object.entries(fields)) {
|
||||
if (spec && typeof spec === "object" && "default" in spec) {
|
||||
out[key] = spec.default;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function contextFromMeta(meta) {
|
||||
if (meta?.example && typeof meta.example === "object" && !Array.isArray(meta.example)) {
|
||||
return {
|
||||
data: "data" in meta.example ? meta.example.data : {},
|
||||
config: "config" in meta.example ? meta.example.config ?? {} : {},
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: defaultsFromFields(meta?.input),
|
||||
config: defaultsFromFields(meta?.config),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user