@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.cjs
CHANGED
|
@@ -4093,6 +4093,23 @@ var defaultOpts = {
|
|
|
4093
4093
|
retries: 4,
|
|
4094
4094
|
timeout: 6e4
|
|
4095
4095
|
};
|
|
4096
|
+
async function insertNewStep(db, runId, name, stage) {
|
|
4097
|
+
await db.transaction().execute(async (trx) => {
|
|
4098
|
+
await trx.selectFrom("keel.flow_run").select("id").where("id", "=", runId).forUpdate().executeTakeFirst();
|
|
4099
|
+
const existing = await trx.selectFrom("keel.flow_step").select("id").where("run_id", "=", runId).where("name", "=", name).where("status", "=", "NEW" /* NEW */).executeTakeFirst();
|
|
4100
|
+
if (existing) {
|
|
4101
|
+
return;
|
|
4102
|
+
}
|
|
4103
|
+
await trx.insertInto("keel.flow_step").values({
|
|
4104
|
+
run_id: runId,
|
|
4105
|
+
name,
|
|
4106
|
+
stage,
|
|
4107
|
+
status: "NEW" /* NEW */,
|
|
4108
|
+
type: "FUNCTION" /* FUNCTION */
|
|
4109
|
+
}).execute();
|
|
4110
|
+
});
|
|
4111
|
+
}
|
|
4112
|
+
__name(insertNewStep, "insertNewStep");
|
|
4096
4113
|
function createFlowContext(runId, data, action, callback, element, spanId, ctx) {
|
|
4097
4114
|
const usedNames = /* @__PURE__ */ new Set();
|
|
4098
4115
|
return {
|
|
@@ -4110,12 +4127,15 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4110
4127
|
step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
|
|
4111
4128
|
return withSpan(`Step - ${name}`, async (span) => {
|
|
4112
4129
|
return withUserSpan(span, async () => {
|
|
4130
|
+
span.setAttribute("step.type", "FUNCTION" /* FUNCTION */);
|
|
4131
|
+
span.setAttribute("step.name", name);
|
|
4113
4132
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
4114
4133
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
4115
4134
|
options.retries = options.retries ?? defaultOpts.retries;
|
|
4116
4135
|
options.timeout = options.timeout ?? defaultOpts.timeout;
|
|
4117
4136
|
const db = useDatabase();
|
|
4118
4137
|
if (usedNames.has(name)) {
|
|
4138
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4119
4139
|
await db.insertInto("keel.flow_step").values({
|
|
4120
4140
|
run_id: runId,
|
|
4121
4141
|
name,
|
|
@@ -4152,6 +4172,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4152
4172
|
}
|
|
4153
4173
|
if (completedSteps.length === 1) {
|
|
4154
4174
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4175
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4155
4176
|
return completedSteps[0].value;
|
|
4156
4177
|
}
|
|
4157
4178
|
if (newSteps.length === 1) {
|
|
@@ -4173,18 +4194,14 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4173
4194
|
error: e instanceof Error ? e.message : "An error occurred"
|
|
4174
4195
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
4175
4196
|
if (failedSteps.length >= options.retries || e instanceof NonRetriableError) {
|
|
4197
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4176
4198
|
if (options.onFailure) {
|
|
4177
4199
|
await options.onFailure();
|
|
4178
4200
|
}
|
|
4179
4201
|
throw new ExhuastedRetriesDisrupt();
|
|
4180
4202
|
}
|
|
4181
|
-
await db.
|
|
4182
|
-
|
|
4183
|
-
name,
|
|
4184
|
-
stage: options.stage,
|
|
4185
|
-
status: "NEW" /* NEW */,
|
|
4186
|
-
type: "FUNCTION" /* FUNCTION */
|
|
4187
|
-
}).returningAll().executeTakeFirst();
|
|
4203
|
+
await insertNewStep(db, runId, name, options.stage);
|
|
4204
|
+
span.setAttribute("step.status", "NEW" /* NEW */);
|
|
4188
4205
|
throw new StepCreatedDisrupt(
|
|
4189
4206
|
options.retryPolicy ? new Date(
|
|
4190
4207
|
Date.now() + options.retryPolicy(failedSteps.length + 1)
|
|
@@ -4197,16 +4214,12 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4197
4214
|
spanId,
|
|
4198
4215
|
endTime: /* @__PURE__ */ new Date()
|
|
4199
4216
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
4217
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4200
4218
|
return result;
|
|
4201
4219
|
}
|
|
4202
|
-
await db.
|
|
4203
|
-
run_id: runId,
|
|
4204
|
-
name,
|
|
4205
|
-
stage: options.stage,
|
|
4206
|
-
status: "NEW" /* NEW */,
|
|
4207
|
-
type: "FUNCTION" /* FUNCTION */
|
|
4208
|
-
}).returningAll().executeTakeFirst();
|
|
4220
|
+
await insertNewStep(db, runId, name, options.stage);
|
|
4209
4221
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4222
|
+
span.setAttribute("step.status", "NEW" /* NEW */);
|
|
4210
4223
|
throw new StepCreatedDisrupt();
|
|
4211
4224
|
});
|
|
4212
4225
|
});
|
|
@@ -4215,9 +4228,12 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4215
4228
|
page: /* @__PURE__ */ __name((async (name, options) => {
|
|
4216
4229
|
return withSpan(`Page - ${name}`, async (span) => {
|
|
4217
4230
|
return withUserSpan(span, async () => {
|
|
4231
|
+
span.setAttribute("step.type", "UI" /* UI */);
|
|
4232
|
+
span.setAttribute("step.name", name);
|
|
4218
4233
|
const db = useDatabase();
|
|
4219
4234
|
const isCallback = element && callback;
|
|
4220
4235
|
if (usedNames.has(name)) {
|
|
4236
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4221
4237
|
await db.insertInto("keel.flow_step").values({
|
|
4222
4238
|
run_id: runId,
|
|
4223
4239
|
name,
|
|
@@ -4234,6 +4250,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4234
4250
|
let step = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("name", "=", name).selectAll().executeTakeFirst();
|
|
4235
4251
|
if (step && step.status === "COMPLETED" /* COMPLETED */) {
|
|
4236
4252
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4253
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4237
4254
|
const parsedData2 = transformRichDataTypes(step.value);
|
|
4238
4255
|
if (step.action) {
|
|
4239
4256
|
return { data: parsedData2, action: step.action };
|
|
@@ -4250,6 +4267,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4250
4267
|
startTime: /* @__PURE__ */ new Date()
|
|
4251
4268
|
}).returningAll().executeTakeFirst();
|
|
4252
4269
|
span.setAttribute("rendered", true);
|
|
4270
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4253
4271
|
throw new UIRenderDisrupt(
|
|
4254
4272
|
step?.id,
|
|
4255
4273
|
(await page(options, null, null)).page
|
|
@@ -4257,6 +4275,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4257
4275
|
}
|
|
4258
4276
|
if (isCallback) {
|
|
4259
4277
|
span.setAttribute("callback", callback);
|
|
4278
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4260
4279
|
try {
|
|
4261
4280
|
const response = await callbackFn(
|
|
4262
4281
|
options.content,
|
|
@@ -4276,6 +4295,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4276
4295
|
}
|
|
4277
4296
|
}
|
|
4278
4297
|
if (!data) {
|
|
4298
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4279
4299
|
throw new UIRenderDisrupt(
|
|
4280
4300
|
step?.id,
|
|
4281
4301
|
(await page(options, null, null)).page
|
|
@@ -4288,8 +4308,10 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4288
4308
|
}
|
|
4289
4309
|
} catch (e) {
|
|
4290
4310
|
if (e instanceof UIRenderDisrupt) {
|
|
4311
|
+
span.setAttribute("step.status", "PENDING" /* PENDING */);
|
|
4291
4312
|
throw e;
|
|
4292
4313
|
}
|
|
4314
|
+
span.setAttribute("step.status", "FAILED" /* FAILED */);
|
|
4293
4315
|
await db.updateTable("keel.flow_step").set({
|
|
4294
4316
|
status: "FAILED" /* FAILED */,
|
|
4295
4317
|
spanId,
|
|
@@ -4305,6 +4327,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
|
|
|
4305
4327
|
spanId,
|
|
4306
4328
|
endTime: /* @__PURE__ */ new Date()
|
|
4307
4329
|
}).where("id", "=", step.id).returningAll().executeTakeFirst();
|
|
4330
|
+
span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
|
|
4308
4331
|
const parsedData = transformRichDataTypes(data);
|
|
4309
4332
|
if (action) {
|
|
4310
4333
|
return { data: parsedData, action };
|