@teamkeel/functions-runtime 0.451.2 → 0.452.1
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/dist/index.cjs +37 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4060,6 +4060,23 @@ var defaultOpts = {
|
|
|
4060
4060
|
retries: 4,
|
|
4061
4061
|
timeout: 6e4
|
|
4062
4062
|
};
|
|
4063
|
+
async function insertNewStep(db, runId, name, stage) {
|
|
4064
|
+
await db.transaction().execute(async (trx) => {
|
|
4065
|
+
await trx.selectFrom("keel.flow_run").select("id").where("id", "=", runId).forUpdate().executeTakeFirst();
|
|
4066
|
+
const existing = await trx.selectFrom("keel.flow_step").select("id").where("run_id", "=", runId).where("name", "=", name).where("status", "=", "NEW" /* NEW */).executeTakeFirst();
|
|
4067
|
+
if (existing) {
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
await trx.insertInto("keel.flow_step").values({
|
|
4071
|
+
run_id: runId,
|
|
4072
|
+
name,
|
|
4073
|
+
stage,
|
|
4074
|
+
status: "NEW" /* NEW */,
|
|
4075
|
+
type: "FUNCTION" /* FUNCTION */
|
|
4076
|
+
}).execute();
|
|
4077
|
+
});
|
|
4078
|
+
}
|
|
4079
|
+
__name(insertNewStep, "insertNewStep");
|
|
4063
4080
|
function createFlowContext(runId, data, action, callback, element, spanId, ctx) {
|
|
4064
4081
|
const usedNames = /* @__PURE__ */ new Set();
|
|
4065
4082
|
return {
|
|
@@ -4077,12 +4094,15 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4077
4094
|
step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
|
|
4078
4095
|
return withSpan(`Step - ${name}`, async (span) => {
|
|
4079
4096
|
return withUserSpan(span, async () => {
|
|
4097
|
+
span.setAttribute("step.type", "FUNCTION" /* FUNCTION */);
|
|
4098
|
+
span.setAttribute("step.name", name);
|
|
4080
4099
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
4081
4100
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
4082
4101
|
options.retries = options.retries ?? defaultOpts.retries;
|
|
4083
4102
|
options.timeout = options.timeout ?? defaultOpts.timeout;
|
|
4084
4103
|
const db = useDatabase();
|
|
4085
4104
|
if (usedNames.has(name)) {
|
|
4105
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4086
4106
|
await db.insertInto("keel.flow_step").values({
|
|
4087
4107
|
run_id: runId,
|
|
4088
4108
|
name,
|
|
@@ -4119,6 +4139,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4119
4139
|
}
|
|
4120
4140
|
if (completedSteps.length === 1) {
|
|
4121
4141
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4142
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4122
4143
|
return completedSteps[0].value;
|
|
4123
4144
|
}
|
|
4124
4145
|
if (newSteps.length === 1) {
|
|
@@ -4140,18 +4161,14 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4140
4161
|
error: e instanceof Error ? e.message : "An error occurred"
|
|
4141
4162
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
4142
4163
|
if (failedSteps.length >= options.retries || e instanceof NonRetriableError) {
|
|
4164
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4143
4165
|
if (options.onFailure) {
|
|
4144
4166
|
await options.onFailure();
|
|
4145
4167
|
}
|
|
4146
4168
|
throw new ExhuastedRetriesDisrupt();
|
|
4147
4169
|
}
|
|
4148
|
-
await db.
|
|
4149
|
-
|
|
4150
|
-
name,
|
|
4151
|
-
stage: options.stage,
|
|
4152
|
-
status: "NEW" /* NEW */,
|
|
4153
|
-
type: "FUNCTION" /* FUNCTION */
|
|
4154
|
-
}).returningAll().executeTakeFirst();
|
|
4170
|
+
await insertNewStep(db, runId, name, options.stage);
|
|
4171
|
+
span.setAttribute("step.status", "NEW" /* NEW */);
|
|
4155
4172
|
throw new StepCreatedDisrupt(
|
|
4156
4173
|
options.retryPolicy ? new Date(
|
|
4157
4174
|
Date.now() + options.retryPolicy(failedSteps.length + 1)
|
|
@@ -4164,16 +4181,12 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4164
4181
|
spanId,
|
|
4165
4182
|
endTime: /* @__PURE__ */ new Date()
|
|
4166
4183
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
4184
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4167
4185
|
return result;
|
|
4168
4186
|
}
|
|
4169
|
-
await db.
|
|
4170
|
-
run_id: runId,
|
|
4171
|
-
name,
|
|
4172
|
-
stage: options.stage,
|
|
4173
|
-
status: "NEW" /* NEW */,
|
|
4174
|
-
type: "FUNCTION" /* FUNCTION */
|
|
4175
|
-
}).returningAll().executeTakeFirst();
|
|
4187
|
+
await insertNewStep(db, runId, name, options.stage);
|
|
4176
4188
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4189
|
+
span.setAttribute("step.status", "NEW" /* NEW */);
|
|
4177
4190
|
throw new StepCreatedDisrupt();
|
|
4178
4191
|
});
|
|
4179
4192
|
});
|
|
@@ -4182,9 +4195,12 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4182
4195
|
page: /* @__PURE__ */ __name((async (name, options) => {
|
|
4183
4196
|
return withSpan(`Page - ${name}`, async (span) => {
|
|
4184
4197
|
return withUserSpan(span, async () => {
|
|
4198
|
+
span.setAttribute("step.type", "UI" /* UI */);
|
|
4199
|
+
span.setAttribute("step.name", name);
|
|
4185
4200
|
const db = useDatabase();
|
|
4186
4201
|
const isCallback = element && callback;
|
|
4187
4202
|
if (usedNames.has(name)) {
|
|
4203
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4188
4204
|
await db.insertInto("keel.flow_step").values({
|
|
4189
4205
|
run_id: runId,
|
|
4190
4206
|
name,
|
|
@@ -4201,6 +4217,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4201
4217
|
let step = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("name", "=", name).selectAll().executeTakeFirst();
|
|
4202
4218
|
if (step && step.status === "COMPLETED" /* COMPLETED */) {
|
|
4203
4219
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4220
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4204
4221
|
const parsedData2 = transformRichDataTypes(step.value);
|
|
4205
4222
|
if (step.action) {
|
|
4206
4223
|
return { data: parsedData2, action: step.action };
|
|
@@ -4217,6 +4234,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4217
4234
|
startTime: /* @__PURE__ */ new Date()
|
|
4218
4235
|
}).returningAll().executeTakeFirst();
|
|
4219
4236
|
span.setAttribute("rendered", true);
|
|
4237
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4220
4238
|
throw new UIRenderDisrupt(
|
|
4221
4239
|
step?.id,
|
|
4222
4240
|
(await page(options, null, null)).page
|
|
@@ -4224,6 +4242,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4224
4242
|
}
|
|
4225
4243
|
if (isCallback) {
|
|
4226
4244
|
span.setAttribute("callback", callback);
|
|
4245
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4227
4246
|
try {
|
|
4228
4247
|
const response = await callbackFn(
|
|
4229
4248
|
options.content,
|
|
@@ -4243,6 +4262,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4243
4262
|
}
|
|
4244
4263
|
}
|
|
4245
4264
|
if (!data) {
|
|
4265
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4246
4266
|
throw new UIRenderDisrupt(
|
|
4247
4267
|
step?.id,
|
|
4248
4268
|
(await page(options, null, null)).page
|
|
@@ -4255,8 +4275,10 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4255
4275
|
}
|
|
4256
4276
|
} catch (e) {
|
|
4257
4277
|
if (e instanceof UIRenderDisrupt) {
|
|
4278
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4258
4279
|
throw e;
|
|
4259
4280
|
}
|
|
4281
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4260
4282
|
await db.updateTable("keel.flow_step").set({
|
|
4261
4283
|
status: "FAILED" /* FAILED */,
|
|
4262
4284
|
spanId,
|
|
@@ -4272,6 +4294,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4272
4294
|
spanId,
|
|
4273
4295
|
endTime: /* @__PURE__ */ new Date()
|
|
4274
4296
|
}).where("id", "=", step.id).returningAll().executeTakeFirst();
|
|
4297
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4275
4298
|
const parsedData = transformRichDataTypes(data);
|
|
4276
4299
|
if (action) {
|
|
4277
4300
|
return { data: parsedData, action };
|