mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
added format command and added trailing commas to reduce conflicts
This commit is contained in:
@@ -20,7 +20,7 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
|
||||
return {
|
||||
...flow.toJSON(),
|
||||
tasks: flow.tasks.length,
|
||||
connections: flow.connections
|
||||
connections: flow.connections,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
|
||||
errors,
|
||||
response: execution.getResponse(),
|
||||
flow: this.getFlowInfo(flow),
|
||||
logs: execution.logs
|
||||
logs: execution.logs,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
|
||||
override toJSON() {
|
||||
return {
|
||||
...this.config,
|
||||
flows: transformObject(this.flows, (flow) => flow.toJSON())
|
||||
flows: transformObject(this.flows, (flow) => flow.toJSON()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Const, type Static, StringRecord, Type, transformObject } from "core/ut
|
||||
import { TaskMap, TriggerMap } from "flows";
|
||||
|
||||
export const TASKS = {
|
||||
...TaskMap
|
||||
...TaskMap,
|
||||
} as const;
|
||||
|
||||
export const TRIGGERS = TriggerMap;
|
||||
@@ -11,9 +11,9 @@ const taskSchemaObject = transformObject(TASKS, (task, name) => {
|
||||
return Type.Object(
|
||||
{
|
||||
type: Const(name),
|
||||
params: task.cls.schema
|
||||
params: task.cls.schema,
|
||||
},
|
||||
{ title: String(name), additionalProperties: false }
|
||||
{ title: String(name), additionalProperties: false },
|
||||
);
|
||||
});
|
||||
const taskSchema = Type.Union(Object.values(taskSchemaObject));
|
||||
@@ -23,9 +23,9 @@ const triggerSchemaObject = transformObject(TRIGGERS, (trigger, name) => {
|
||||
return Type.Object(
|
||||
{
|
||||
type: Const(name),
|
||||
config: trigger.cls.schema
|
||||
config: trigger.cls.schema,
|
||||
},
|
||||
{ title: String(name), additionalProperties: false }
|
||||
{ title: String(name), additionalProperties: false },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -38,22 +38,22 @@ const connectionSchema = Type.Object({
|
||||
Type.Union([
|
||||
Type.Object(
|
||||
{ type: Const("success") },
|
||||
{ additionalProperties: false, title: "success" }
|
||||
{ additionalProperties: false, title: "success" },
|
||||
),
|
||||
Type.Object(
|
||||
{ type: Const("error") },
|
||||
{ additionalProperties: false, title: "error" }
|
||||
{ additionalProperties: false, title: "error" },
|
||||
),
|
||||
Type.Object(
|
||||
{ type: Const("matches"), path: Type.String(), value: Type.String() },
|
||||
{ additionalProperties: false, title: "matches" }
|
||||
)
|
||||
])
|
||||
{ additionalProperties: false, title: "matches" },
|
||||
),
|
||||
]),
|
||||
),
|
||||
max_retries: Type.Optional(Type.Number())
|
||||
max_retries: Type.Optional(Type.Number()),
|
||||
},
|
||||
{ default: {}, additionalProperties: false }
|
||||
)
|
||||
{ default: {}, additionalProperties: false },
|
||||
),
|
||||
});
|
||||
|
||||
// @todo: rework to have fixed ids per task and connections (and preferrably arrays)
|
||||
@@ -64,21 +64,21 @@ export const flowSchema = Type.Object(
|
||||
tasks: Type.Optional(StringRecord(Type.Union(Object.values(taskSchemaObject)))),
|
||||
connections: Type.Optional(StringRecord(connectionSchema)),
|
||||
start_task: Type.Optional(Type.String()),
|
||||
responding_task: Type.Optional(Type.String())
|
||||
responding_task: Type.Optional(Type.String()),
|
||||
},
|
||||
{
|
||||
additionalProperties: false
|
||||
}
|
||||
additionalProperties: false,
|
||||
},
|
||||
);
|
||||
export type TAppFlowSchema = Static<typeof flowSchema>;
|
||||
|
||||
export const flowsConfigSchema = Type.Object(
|
||||
{
|
||||
basepath: Type.String({ default: "/api/flows" }),
|
||||
flows: StringRecord(flowSchema, { default: {} })
|
||||
flows: StringRecord(flowSchema, { default: {} }),
|
||||
},
|
||||
{
|
||||
default: {},
|
||||
additionalProperties: false
|
||||
}
|
||||
additionalProperties: false,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -127,7 +127,7 @@ export class Execution implements EmitsEvents {
|
||||
if (target_runs > max_retries) {
|
||||
//console.log("*** Task reached max retries", t.name);
|
||||
throw new Error(
|
||||
`Task "${t.name}" reached max retries (${target_runs}/${max_retries})`
|
||||
`Task "${t.name}" reached max retries (${target_runs}/${max_retries})`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ export class Execution implements EmitsEvents {
|
||||
output: input, // @todo: remove
|
||||
error: undefined,
|
||||
success: true,
|
||||
params: input
|
||||
params: input,
|
||||
});
|
||||
|
||||
//graceful && (await new Promise((resolve) => setTimeout(resolve, 100)));
|
||||
|
||||
@@ -163,7 +163,7 @@ export class Flow {
|
||||
tasks: Object.fromEntries(this.tasks.map((t) => [t.name, t.toJSON()])),
|
||||
connections: Object.fromEntries(this.connections.map((c) => [c.id, c.toJSON()])),
|
||||
start_task: this.startTask?.name,
|
||||
responding_task: this.respondingTask?.name
|
||||
responding_task: this.respondingTask?.name,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ export class Flow {
|
||||
tasks[obj.source],
|
||||
tasks[obj.target],
|
||||
{ ...obj.config, condition },
|
||||
id as string
|
||||
id as string,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export class FlowTaskConnector {
|
||||
const outConnections = this.getOutConnections();
|
||||
const definedOutConditions = outConnections.map((c) => c.condition);
|
||||
const hasOutGoingBack = outConnections.some(
|
||||
(c) => this.task(c.target).getDepth() <= ownDepth
|
||||
(c) => this.task(c.target).getDepth() <= ownDepth,
|
||||
);
|
||||
|
||||
if (definedOutConditions.length > 0 && hasOutGoingBack) {
|
||||
@@ -76,7 +76,7 @@ export class FlowTaskConnector {
|
||||
if (lower_only) {
|
||||
const depth = this.getDepth();
|
||||
return this.getInConnections().filter(
|
||||
(c) => c.target === this.source && this.task(c.source).getDepth() < depth
|
||||
(c) => c.target === this.source && this.task(c.source).getDepth() < depth,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export class FlowTaskConnector {
|
||||
getOutConnections(result?: TaskResult): TaskConnection[] {
|
||||
if (result) {
|
||||
return this.flow.connections.filter(
|
||||
(c) => c.source === this.source && c.condition.isMet(result)
|
||||
(c) => c.source === this.source && c.condition.isMet(result),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Task } from "../../tasks/Task";
|
||||
export class RuntimeExecutor {
|
||||
async run(
|
||||
nextTasks: () => Task[],
|
||||
onDone?: (task: Task, result: Awaited<ReturnType<Task["run"]>>) => void
|
||||
onDone?: (task: Task, result: Awaited<ReturnType<Task["run"]>>) => void,
|
||||
) {
|
||||
const tasks = nextTasks();
|
||||
if (tasks.length === 0) {
|
||||
|
||||
@@ -9,9 +9,9 @@ export class EventTrigger extends Trigger<typeof EventTrigger.schema> {
|
||||
static override schema = Type.Composite([
|
||||
Trigger.schema,
|
||||
Type.Object({
|
||||
event: Type.String()
|
||||
event: Type.String(),
|
||||
// add match
|
||||
})
|
||||
}),
|
||||
]);
|
||||
|
||||
override async register(flow: Flow, emgr: EventManager<any>) {
|
||||
@@ -35,7 +35,7 @@ export class EventTrigger extends Trigger<typeof EventTrigger.schema> {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
this.config.mode
|
||||
this.config.mode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ export class HttpTrigger extends Trigger<typeof HttpTrigger.schema> {
|
||||
{
|
||||
path: Type.String({ pattern: "^/.*$" }),
|
||||
method: StringEnum(httpMethods, { default: "GET" }),
|
||||
response_type: StringEnum(["json", "text", "html"], { default: "json" })
|
||||
}
|
||||
response_type: StringEnum(["json", "text", "html"], { default: "json" }),
|
||||
},
|
||||
//{ additionalProperties: false }
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
override async register(flow: Flow, hono: Hono<any>) {
|
||||
|
||||
@@ -10,8 +10,8 @@ export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schem
|
||||
|
||||
static schema = Type.Object(
|
||||
{
|
||||
mode: StringEnum(["sync", "async"], { default: "async" })
|
||||
}
|
||||
mode: StringEnum(["sync", "async"], { default: "async" }),
|
||||
},
|
||||
//{ additionalProperties: false }
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@ export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schem
|
||||
toJSON() {
|
||||
return {
|
||||
type: this.type,
|
||||
config: this.config
|
||||
config: this.config,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ export { Trigger, EventTrigger, HttpTrigger };
|
||||
export const TriggerMap = {
|
||||
manual: { cls: Trigger },
|
||||
event: { cls: EventTrigger },
|
||||
http: { cls: HttpTrigger }
|
||||
http: { cls: HttpTrigger },
|
||||
} as const;
|
||||
export type TriggerMapType = typeof TriggerMap;
|
||||
|
||||
@@ -9,7 +9,7 @@ export {
|
||||
type TaskLog,
|
||||
type InputsMap,
|
||||
ExecutionState,
|
||||
ExecutionEvent
|
||||
ExecutionEvent,
|
||||
} from "./flows/Execution";
|
||||
export { RuntimeExecutor } from "./flows/executors/RuntimeExecutor";
|
||||
export { FlowTaskConnector } from "./flows/FlowTaskConnector";
|
||||
@@ -19,7 +19,7 @@ export {
|
||||
EventTrigger,
|
||||
HttpTrigger,
|
||||
TriggerMap,
|
||||
type TriggerMapType
|
||||
type TriggerMapType,
|
||||
} from "./flows/triggers";
|
||||
|
||||
import { Task } from "./tasks/Task";
|
||||
@@ -34,7 +34,7 @@ export const TaskMap = {
|
||||
fetch: { cls: FetchTask },
|
||||
log: { cls: LogTask },
|
||||
render: { cls: RenderTask },
|
||||
subflow: { cls: SubFlowTask }
|
||||
subflow: { cls: SubFlowTask },
|
||||
} as const;
|
||||
export type TaskMapType = typeof TaskMap;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export type TaskRenderProps<T extends Task = Task> = any;
|
||||
|
||||
export function dynamic<Type extends TSchema>(
|
||||
type: Type,
|
||||
parse?: (val: any | string) => Static<Type>
|
||||
parse?: (val: any | string) => Static<Type>,
|
||||
) {
|
||||
const guessDecode = (val: unknown): Static<Type> => {
|
||||
if (typeof val === "string") {
|
||||
@@ -46,7 +46,7 @@ export function dynamic<Type extends TSchema>(
|
||||
|
||||
return val as Static<Type>;
|
||||
};
|
||||
const title = type.title ?? type.type ? ucFirst(type.type) : "Raw";
|
||||
const title = (type.title ?? type.type) ? ucFirst(type.type) : "Raw";
|
||||
|
||||
return (
|
||||
Type.Transform(Type.Union([{ title, ...type }, Type.String({ title: "Template" })]))
|
||||
@@ -87,7 +87,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
Object.keys(params).length > 0
|
||||
) {
|
||||
throw new Error(
|
||||
`Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}`
|
||||
`Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
static async resolveParams<S extends TSchema>(
|
||||
schema: S,
|
||||
params: any,
|
||||
inputs: object = {}
|
||||
inputs: object = {},
|
||||
): Promise<StaticDecode<S>> {
|
||||
const newParams: any = {};
|
||||
const renderer = new SimpleRenderer(inputs, { strictVariables: true, renderKeys: true });
|
||||
@@ -141,9 +141,9 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
{
|
||||
key,
|
||||
value,
|
||||
error: e.message
|
||||
error: e.message,
|
||||
},
|
||||
"resolve-params"
|
||||
"resolve-params",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
const newParams = await Task.resolveParams(
|
||||
(this.constructor as any).schema,
|
||||
this._params,
|
||||
inputs
|
||||
inputs,
|
||||
);
|
||||
//console.log("--clone:newParams", this.name, newParams);
|
||||
|
||||
@@ -207,7 +207,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
} else {
|
||||
error = {
|
||||
type: "unknown",
|
||||
message: (e as any).message
|
||||
message: (e as any).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
toJSON() {
|
||||
return {
|
||||
type: this.type,
|
||||
params: this.params
|
||||
params: this.params,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ export class TaskConnection {
|
||||
target: this.target.name,
|
||||
config: {
|
||||
...this.config,
|
||||
condition: this.config.condition?.toJSON()
|
||||
}
|
||||
condition: this.config.condition?.toJSON(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export class Condition {
|
||||
private constructor(
|
||||
public type: "success" | "error" | "matches",
|
||||
public path: string = "",
|
||||
public value: any = undefined
|
||||
public value: any = undefined,
|
||||
) {}
|
||||
|
||||
static default() {
|
||||
@@ -96,7 +96,7 @@ export class Condition {
|
||||
return {
|
||||
type: this.type,
|
||||
path: this.path.length === 0 ? undefined : this.path,
|
||||
value: this.value
|
||||
value: this.value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
|
||||
static override schema = Type.Object({
|
||||
url: Type.String({
|
||||
pattern: "^(http|https)://"
|
||||
pattern: "^(http|https)://",
|
||||
}),
|
||||
//method: Type.Optional(Type.Enum(FetchMethodsEnum)),
|
||||
//method: Type.Optional(dynamic(Type.String({ enum: FetchMethods, default: "GET" }))),
|
||||
@@ -22,14 +22,14 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
Type.Array(
|
||||
Type.Object({
|
||||
key: Type.String(),
|
||||
value: Type.String()
|
||||
})
|
||||
value: Type.String(),
|
||||
}),
|
||||
),
|
||||
JSON.parse
|
||||
)
|
||||
JSON.parse,
|
||||
),
|
||||
),
|
||||
body: Type.Optional(dynamic(Type.String())),
|
||||
normal: Type.Optional(dynamic(Type.Number(), Number.parseInt))
|
||||
normal: Type.Optional(dynamic(Type.Number(), Number.parseInt)),
|
||||
});
|
||||
|
||||
protected getBody(): string | undefined {
|
||||
@@ -46,7 +46,7 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
if (!FetchMethods.includes(this.params.method ?? "GET")) {
|
||||
throw this.error("Invalid method", {
|
||||
given: this.params.method,
|
||||
valid: FetchMethods
|
||||
valid: FetchMethods,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
const result = await fetch(this.params.url, {
|
||||
method: this.params.method ?? "GET",
|
||||
headers,
|
||||
body
|
||||
body,
|
||||
});
|
||||
|
||||
//console.log("fetch:response", result);
|
||||
if (!result.ok) {
|
||||
throw this.error("Failed to fetch", {
|
||||
status: result.status,
|
||||
statusText: result.statusText
|
||||
statusText: result.statusText,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export class LogTask extends Task<typeof LogTask.schema> {
|
||||
type = "log";
|
||||
|
||||
static override schema = Type.Object({
|
||||
delay: Type.Number({ default: 10 })
|
||||
delay: Type.Number({ default: 10 }),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
@@ -8,7 +8,7 @@ export class RenderTask<Output extends Record<string, any>> extends Task<
|
||||
type = "render";
|
||||
|
||||
static override schema = Type.Object({
|
||||
render: Type.String()
|
||||
render: Type.String(),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class SubFlowTask<Output extends Record<string, any>> extends Task<
|
||||
static override schema = Type.Object({
|
||||
flow: Type.Any(),
|
||||
input: Type.Optional(dynamic(Type.Any(), JSON.parse)),
|
||||
loop: Type.Optional(Type.Boolean())
|
||||
loop: Type.Optional(Type.Boolean()),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
Reference in New Issue
Block a user