@teamkeel/functions-runtime 0.451.1 → 0.452.0

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 CHANGED
@@ -4110,12 +4110,15 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4110
4110
  step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
4111
4111
  return withSpan(`Step - ${name}`, async (span) => {
4112
4112
  return withUserSpan(span, async () => {
4113
+ span.setAttribute("step.type", "FUNCTION" /* FUNCTION */);
4114
+ span.setAttribute("step.name", name);
4113
4115
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
4114
4116
  const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
4115
4117
  options.retries = options.retries ?? defaultOpts.retries;
4116
4118
  options.timeout = options.timeout ?? defaultOpts.timeout;
4117
4119
  const db = useDatabase();
4118
4120
  if (usedNames.has(name)) {
4121
+ span.setAttribute("step.status", "FAILED" /* FAILED */);
4119
4122
  await db.insertInto("keel.flow_step").values({
4120
4123
  run_id: runId,
4121
4124
  name,
@@ -4152,6 +4155,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4152
4155
  }
4153
4156
  if (completedSteps.length === 1) {
4154
4157
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4158
+ span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
4155
4159
  return completedSteps[0].value;
4156
4160
  }
4157
4161
  if (newSteps.length === 1) {
@@ -4173,6 +4177,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4173
4177
  error: e instanceof Error ? e.message : "An error occurred"
4174
4178
  }).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
4175
4179
  if (failedSteps.length >= options.retries || e instanceof NonRetriableError) {
4180
+ span.setAttribute("step.status", "FAILED" /* FAILED */);
4176
4181
  if (options.onFailure) {
4177
4182
  await options.onFailure();
4178
4183
  }
@@ -4185,6 +4190,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4185
4190
  status: "NEW" /* NEW */,
4186
4191
  type: "FUNCTION" /* FUNCTION */
4187
4192
  }).returningAll().executeTakeFirst();
4193
+ span.setAttribute("step.status", "NEW" /* NEW */);
4188
4194
  throw new StepCreatedDisrupt(
4189
4195
  options.retryPolicy ? new Date(
4190
4196
  Date.now() + options.retryPolicy(failedSteps.length + 1)
@@ -4197,6 +4203,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4197
4203
  spanId,
4198
4204
  endTime: /* @__PURE__ */ new Date()
4199
4205
  }).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
4206
+ span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
4200
4207
  return result;
4201
4208
  }
4202
4209
  await db.insertInto("keel.flow_step").values({
@@ -4207,6 +4214,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4207
4214
  type: "FUNCTION" /* FUNCTION */
4208
4215
  }).returningAll().executeTakeFirst();
4209
4216
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4217
+ span.setAttribute("step.status", "NEW" /* NEW */);
4210
4218
  throw new StepCreatedDisrupt();
4211
4219
  });
4212
4220
  });
@@ -4215,9 +4223,12 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4215
4223
  page: /* @__PURE__ */ __name((async (name, options) => {
4216
4224
  return withSpan(`Page - ${name}`, async (span) => {
4217
4225
  return withUserSpan(span, async () => {
4226
+ span.setAttribute("step.type", "UI" /* UI */);
4227
+ span.setAttribute("step.name", name);
4218
4228
  const db = useDatabase();
4219
4229
  const isCallback = element && callback;
4220
4230
  if (usedNames.has(name)) {
4231
+ span.setAttribute("step.status", "FAILED" /* FAILED */);
4221
4232
  await db.insertInto("keel.flow_step").values({
4222
4233
  run_id: runId,
4223
4234
  name,
@@ -4234,6 +4245,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4234
4245
  let step = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("name", "=", name).selectAll().executeTakeFirst();
4235
4246
  if (step && step.status === "COMPLETED" /* COMPLETED */) {
4236
4247
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4248
+ span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
4237
4249
  const parsedData2 = transformRichDataTypes(step.value);
4238
4250
  if (step.action) {
4239
4251
  return { data: parsedData2, action: step.action };
@@ -4250,6 +4262,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4250
4262
  startTime: /* @__PURE__ */ new Date()
4251
4263
  }).returningAll().executeTakeFirst();
4252
4264
  span.setAttribute("rendered", true);
4265
+ span.setAttribute("step.status", "PENDING" /* PENDING */);
4253
4266
  throw new UIRenderDisrupt(
4254
4267
  step?.id,
4255
4268
  (await page(options, null, null)).page
@@ -4257,6 +4270,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4257
4270
  }
4258
4271
  if (isCallback) {
4259
4272
  span.setAttribute("callback", callback);
4273
+ span.setAttribute("step.status", "PENDING" /* PENDING */);
4260
4274
  try {
4261
4275
  const response = await callbackFn(
4262
4276
  options.content,
@@ -4276,6 +4290,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4276
4290
  }
4277
4291
  }
4278
4292
  if (!data) {
4293
+ span.setAttribute("step.status", "PENDING" /* PENDING */);
4279
4294
  throw new UIRenderDisrupt(
4280
4295
  step?.id,
4281
4296
  (await page(options, null, null)).page
@@ -4288,8 +4303,10 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4288
4303
  }
4289
4304
  } catch (e) {
4290
4305
  if (e instanceof UIRenderDisrupt) {
4306
+ span.setAttribute("step.status", "PENDING" /* PENDING */);
4291
4307
  throw e;
4292
4308
  }
4309
+ span.setAttribute("step.status", "FAILED" /* FAILED */);
4293
4310
  await db.updateTable("keel.flow_step").set({
4294
4311
  status: "FAILED" /* FAILED */,
4295
4312
  spanId,
@@ -4305,6 +4322,7 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4305
4322
  spanId,
4306
4323
  endTime: /* @__PURE__ */ new Date()
4307
4324
  }).where("id", "=", step.id).returningAll().executeTakeFirst();
4325
+ span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
4308
4326
  const parsedData = transformRichDataTypes(data);
4309
4327
  if (action) {
4310
4328
  return { data: parsedData, action };