@algolia/wizard 0.40.0 → 0.41.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.
Files changed (2) hide show
  1. package/dist/main.js +89 -21
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1417,6 +1417,44 @@ function trackActionEnd(ctx) {
1417
1417
  metricTags(ctx.workflowId, ctx.actionId)
1418
1418
  );
1419
1419
  }
1420
+ var MAX_ATTRIBUTE_LENGTH = 500;
1421
+ function truncate2(value) {
1422
+ return value.length <= MAX_ATTRIBUTE_LENGTH ? value : `${value.slice(0, MAX_ATTRIBUTE_LENGTH - 3)}...`;
1423
+ }
1424
+ function readString(source, key) {
1425
+ const value = Reflect.get(source, key);
1426
+ return typeof value === "string" && value.length > 0 ? value : void 0;
1427
+ }
1428
+ function causeAttributes(cause) {
1429
+ if (cause instanceof Error) {
1430
+ return {
1431
+ error_cause_name: cause.name,
1432
+ error_cause: truncate2(cause.message)
1433
+ };
1434
+ }
1435
+ return typeof cause === "string" ? { error_cause: truncate2(cause) } : {};
1436
+ }
1437
+ function providerAttributes(source) {
1438
+ const statusCode = Reflect.get(source, "statusCode");
1439
+ const isRetryable = Reflect.get(source, "isRetryable");
1440
+ const url = readString(source, "url");
1441
+ const responseBody = readString(source, "responseBody");
1442
+ return {
1443
+ ...typeof statusCode === "number" && Number.isFinite(statusCode) && { error_status_code: statusCode },
1444
+ ...typeof isRetryable === "boolean" && { error_retryable: isRetryable },
1445
+ ...url && { error_url: truncate2(url) },
1446
+ ...responseBody && { error_response_body: truncate2(responseBody) }
1447
+ };
1448
+ }
1449
+ function errorAttributes(err) {
1450
+ if (!(err instanceof Error)) return {};
1451
+ const { cause } = err;
1452
+ return {
1453
+ error_name: err.name,
1454
+ ...causeAttributes(cause),
1455
+ ...providerAttributes(cause instanceof Error ? cause : err)
1456
+ };
1457
+ }
1420
1458
  function trackActionError(ctx) {
1421
1459
  const attributes = {
1422
1460
  event: "wizard.action.error",
@@ -1424,7 +1462,8 @@ function trackActionError(ctx) {
1424
1462
  action_id: ctx.actionId,
1425
1463
  action_title: ctx.actionTitle,
1426
1464
  error: ctx.error,
1427
- app_id: ctx.appId
1465
+ app_id: ctx.appId,
1466
+ ...errorAttributes(ctx.cause)
1428
1467
  };
1429
1468
  emitTelemetryLog(
1430
1469
  "error",
@@ -1460,7 +1499,8 @@ function trackWorkflowError(ctx) {
1460
1499
  workflow_id: ctx.workflowId,
1461
1500
  action_id: ctx.actionId,
1462
1501
  error: ctx.error,
1463
- app_id: ctx.appId
1502
+ app_id: ctx.appId,
1503
+ ...errorAttributes(ctx.cause)
1464
1504
  };
1465
1505
  emitTelemetryLog(
1466
1506
  "error",
@@ -1686,14 +1726,16 @@ async function runWorkflow(workflow, appId) {
1686
1726
  appId,
1687
1727
  actionId: failedActionId,
1688
1728
  actionTitle: failedActionTitle,
1689
- error: message
1729
+ error: message,
1730
+ cause: err
1690
1731
  });
1691
1732
  }
1692
1733
  trackWorkflowError({
1693
1734
  workflowId: workflow.id,
1694
1735
  appId,
1695
1736
  error: message,
1696
- actionId: failedActionId
1737
+ actionId: failedActionId,
1738
+ cause: err
1697
1739
  });
1698
1740
  track("Error", {
1699
1741
  step,
@@ -1772,7 +1814,13 @@ var selectIndexStep = async (ctx) => {
1772
1814
  };
1773
1815
 
1774
1816
  // src/lib/agent.ts
1775
- import { ToolLoopAgent, hasToolCall, Output as Output3 } from "ai";
1817
+ import {
1818
+ ToolLoopAgent,
1819
+ hasToolCall,
1820
+ Output as Output3,
1821
+ APICallError,
1822
+ NoOutputGeneratedError
1823
+ } from "ai";
1776
1824
  import { createAnthropic as createAnthropic3 } from "@ai-sdk/anthropic";
1777
1825
  import "zod";
1778
1826
 
@@ -3139,21 +3187,31 @@ var MODEL_BY_SIZE = {
3139
3187
  var MISSING_REPORT_STATUS_ERROR_MESSAGE = "Agent finished without calling reportStatus";
3140
3188
  var MISSING_REPORT_USER_MESSAGE = "This step ran into a problem finishing. Run the wizard again to retry it.";
3141
3189
  var REPORT_STATUS_RETRIES = 2;
3190
+ var PROVIDER_ERROR_USER_MESSAGE = "The AI service had trouble responding. Run the wizard again to retry this step.";
3191
+ function retryKind(err) {
3192
+ if (err instanceof Error && err.message === MISSING_REPORT_STATUS_ERROR_MESSAGE) {
3193
+ return "missingReport";
3194
+ }
3195
+ if (NoOutputGeneratedError.isInstance(err)) return "transientProvider";
3196
+ if (APICallError.isInstance(err) && err.isRetryable) {
3197
+ return "transientProvider";
3198
+ }
3199
+ return null;
3200
+ }
3201
+ function exhaustedError(kind, err) {
3202
+ return kind === "missingReport" ? new Error(MISSING_REPORT_USER_MESSAGE) : new Error(PROVIDER_ERROR_USER_MESSAGE, { cause: err });
3203
+ }
3142
3204
  async function runAgent(req) {
3143
3205
  for (let attempt = 0; attempt <= REPORT_STATUS_RETRIES; attempt++) {
3144
3206
  try {
3145
3207
  return await runAgentAttempt(req, attempt);
3146
3208
  } catch (err) {
3147
- const isMissingReport = err instanceof Error && err.message === MISSING_REPORT_STATUS_ERROR_MESSAGE;
3148
- if (!isMissingReport) {
3149
- throw err;
3150
- }
3151
- if (attempt === REPORT_STATUS_RETRIES) {
3152
- throw new Error(MISSING_REPORT_USER_MESSAGE);
3153
- }
3209
+ const kind = retryKind(err);
3210
+ if (!kind) throw err;
3211
+ if (attempt === REPORT_STATUS_RETRIES) throw exhaustedError(kind, err);
3154
3212
  logger.warn(
3155
- { attempt: attempt + 1 },
3156
- "retrying runAgent after missing reportStatus"
3213
+ { attempt: attempt + 1, err },
3214
+ kind === "missingReport" ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
3157
3215
  );
3158
3216
  }
3159
3217
  }
@@ -3216,18 +3274,28 @@ async function runAgentAttempt(req, attempt) {
3216
3274
  });
3217
3275
  let chunks = [];
3218
3276
  const chunkLimit = 5;
3219
- for await (const chunk of stream.textStream) {
3277
+ let streamError;
3278
+ for await (const part of stream.fullStream) {
3279
+ if (part.type === "error") {
3280
+ streamError = part.error;
3281
+ continue;
3282
+ }
3283
+ if (part.type !== "text-delta") continue;
3220
3284
  if (chunks.length < chunkLimit) {
3221
- chunks.push(chunk);
3285
+ chunks.push(part.text);
3222
3286
  continue;
3223
3287
  }
3224
- chunks.push(chunk);
3288
+ chunks.push(part.text);
3225
3289
  logger.debug(chunks.join(""));
3226
3290
  chunks = [];
3227
3291
  }
3228
3292
  if (chunks.length) {
3229
3293
  logger.debug(chunks.join(""));
3230
3294
  }
3295
+ if (streamError !== void 0) {
3296
+ logger.error({ err: streamError }, "agent stream reported an error");
3297
+ throw streamError;
3298
+ }
3231
3299
  const end = Date.now();
3232
3300
  const usage = await stream.totalUsage;
3233
3301
  logger.info(
@@ -3387,7 +3455,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3387
3455
  // package.json
3388
3456
  var package_default = {
3389
3457
  name: "@algolia/wizard",
3390
- version: "0.40.0",
3458
+ version: "0.41.0",
3391
3459
  description: "Magically implement Algolia functionality in your codebase",
3392
3460
  type: "module",
3393
3461
  engines: {
@@ -5036,7 +5104,7 @@ function logNameColor(entry) {
5036
5104
  return STATUS_COLOR[entry.status] ?? KIND_COLOR[entry.kind];
5037
5105
  }
5038
5106
  var ROW_GAP = 1;
5039
- function truncate2(str, maxWidth) {
5107
+ function truncate3(str, maxWidth) {
5040
5108
  if (maxWidth <= 0) return "";
5041
5109
  return str.length > maxWidth ? `${str.slice(0, maxWidth - 1)}\u2026` : str;
5042
5110
  }
@@ -5068,9 +5136,9 @@ function Logs() {
5068
5136
  const partCount = 2 + (rawPreview ? 1 : 0) + (durationText ? 1 : 0);
5069
5137
  const gaps = (partCount - 1) * ROW_GAP;
5070
5138
  let budget = scroll.width - timestamp.length - durationText.length - gaps;
5071
- const name = truncate2(entry.name, budget);
5139
+ const name = truncate3(entry.name, budget);
5072
5140
  budget -= name.length;
5073
- const preview = rawPreview ? truncate2(rawPreview, budget) : "";
5141
+ const preview = rawPreview ? truncate3(rawPreview, budget) : "";
5074
5142
  return /* @__PURE__ */ jsxs16(Box17, { flexDirection: "row", gap: ROW_GAP, children: [
5075
5143
  /* @__PURE__ */ jsx15(Text17, { color: COLORS.dim, children: timestamp }),
5076
5144
  /* @__PURE__ */ jsx15(Text17, { color: logNameColor(entry), wrap: "truncate", children: name }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {