@algolia/wizard 0.70.0 → 0.72.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 +121 -22
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1969,7 +1969,7 @@ function identify(traits) {
1969
1969
  // package.json
1970
1970
  var package_default = {
1971
1971
  name: "@algolia/wizard",
1972
- version: "0.70.0",
1972
+ version: "0.72.0",
1973
1973
  description: "Magically implement Algolia functionality in your codebase",
1974
1974
  type: "module",
1975
1975
  engines: {
@@ -3440,6 +3440,12 @@ var DEFAULT_TOOL_LIMITS = {
3440
3440
  match: 100,
3441
3441
  shell: 50
3442
3442
  };
3443
+ var EMPTY_TOOL_COUNTS = {
3444
+ list: 0,
3445
+ search: 0,
3446
+ read: 0,
3447
+ shell: 0
3448
+ };
3443
3449
  var DEFAULT_SHELL_TIMEOUT_MS = 10 * 60 * 1e3;
3444
3450
  async function refuseByDefault() {
3445
3451
  return "reject";
@@ -3458,11 +3464,14 @@ function createToolContext(limits = DEFAULT_TOOL_LIMITS, cwd = process.cwd(), sh
3458
3464
  root: cwd,
3459
3465
  cwd,
3460
3466
  limits: { ...limits },
3461
- counts: { list: 0, search: 0, read: 0, shell: 0 },
3467
+ counts: { ...EMPTY_TOOL_COUNTS },
3462
3468
  shell: shell2,
3463
3469
  reviewed: []
3464
3470
  };
3465
3471
  }
3472
+ function resetToolCounts(ctx) {
3473
+ Object.assign(ctx.counts, EMPTY_TOOL_COUNTS);
3474
+ }
3466
3475
 
3467
3476
  // src/lib/tools/utils/runShell.ts
3468
3477
  var SIGKILL_DELAY_MS = 5e3;
@@ -4128,10 +4137,21 @@ var MISSING_REPORT_STATUS_ERROR_MESSAGE = "Agent finished without calling report
4128
4137
  var MISSING_REPORT_USER_MESSAGE = "This step ran into a problem finishing. Run the wizard again to retry it.";
4129
4138
  var REPORT_STATUS_RETRIES = 2;
4130
4139
  var ATTEMPT_NUMBER_OFFSET = 1;
4140
+ var INITIAL_ATTEMPT = 0;
4131
4141
  var PROVIDER_ERROR_USER_MESSAGE = "The AI service had trouble responding. Run the wizard again to retry this step.";
4142
+ var MissingReportError = class extends Error {
4143
+ atStepLimit;
4144
+ constructor(atStepLimit) {
4145
+ super(MISSING_REPORT_STATUS_ERROR_MESSAGE);
4146
+ this.atStepLimit = atStepLimit;
4147
+ }
4148
+ };
4149
+ function isMissingReportRetry(kind) {
4150
+ return kind === "missingReport" || kind === "missingReportAtStepLimit";
4151
+ }
4132
4152
  function retryKind(err) {
4133
- if (err instanceof Error && err.message === MISSING_REPORT_STATUS_ERROR_MESSAGE) {
4134
- return "missingReport";
4153
+ if (err instanceof MissingReportError) {
4154
+ return err.atStepLimit ? "missingReportAtStepLimit" : "missingReport";
4135
4155
  }
4136
4156
  if (NoOutputGeneratedError.isInstance(err)) return "transientProvider";
4137
4157
  if (APICallError.isInstance(err) && err.isRetryable) {
@@ -4140,37 +4160,42 @@ function retryKind(err) {
4140
4160
  return null;
4141
4161
  }
4142
4162
  function exhaustedError(kind, err) {
4143
- return kind === "missingReport" ? new Error(MISSING_REPORT_USER_MESSAGE) : new Error(PROVIDER_ERROR_USER_MESSAGE, { cause: err });
4163
+ return isMissingReportRetry(kind) ? new Error(MISSING_REPORT_USER_MESSAGE) : new Error(PROVIDER_ERROR_USER_MESSAGE, { cause: err });
4144
4164
  }
4145
4165
  async function runAgent(req) {
4146
- for (let attempt = 0; attempt <= REPORT_STATUS_RETRIES; attempt++) {
4166
+ let retryReason = null;
4167
+ for (let attempt = INITIAL_ATTEMPT; attempt <= REPORT_STATUS_RETRIES; attempt++) {
4147
4168
  try {
4148
- return await runAgentAttempt(req, attempt);
4169
+ return await runAgentAttempt(req, attempt, retryReason);
4149
4170
  } catch (err) {
4150
4171
  const kind = retryKind(err);
4151
4172
  if (!kind) throw err;
4152
4173
  if (attempt === REPORT_STATUS_RETRIES) throw exhaustedError(kind, err);
4174
+ retryReason = kind === "transientProvider" && isMissingReportRetry(retryReason) ? retryReason : kind;
4153
4175
  logger.warn(
4154
4176
  { attempt: attempt + 1, err },
4155
- kind === "missingReport" ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
4177
+ isMissingReportRetry(kind) ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
4156
4178
  );
4157
4179
  }
4158
4180
  }
4159
4181
  throw new Error("unreachable");
4160
4182
  }
4161
- async function runAgentAttempt(req, attempt) {
4183
+ async function runAgentAttempt(req, attempt, retryReason) {
4162
4184
  const start = Date.now();
4163
4185
  const profileName = req.modelProfile ?? "implementation" /* implementation */;
4164
4186
  const profile = getModelProfile(profileName);
4165
- const modelOptions = providerOptionsForProfile(profileName);
4187
+ const profileOptions = providerOptionsForProfile(profileName);
4188
+ const forceReport = retryReason === "missingReport";
4189
+ const modelOptions = forceReport ? { thinking: { type: "disabled" } } : profileOptions;
4166
4190
  logger.info(
4167
4191
  {
4168
4192
  startedAt: new Date(start).toISOString(),
4169
4193
  operation: req.operation,
4170
4194
  profile: profileName,
4171
4195
  model: profile.model,
4172
- effort: profile.effort,
4173
- thinking: profile.thinking
4196
+ effort: forceReport ? void 0 : profile.effort,
4197
+ thinking: forceReport ? "disabled" : profile.thinking,
4198
+ retryReason
4174
4199
  },
4175
4200
  "runAgent started"
4176
4201
  );
@@ -4184,6 +4209,7 @@ async function runAgentAttempt(req, attempt) {
4184
4209
  fetch: proxyFetch
4185
4210
  });
4186
4211
  const toolContext = req.toolContext ?? createToolContext();
4212
+ if (attempt > INITIAL_ATTEMPT) resetToolCounts(toolContext);
4187
4213
  const readTools = ["readFile", "searchFiles", "listFiles"];
4188
4214
  const hasReadTools = !req.tools || req.tools.some((t) => readTools.includes(t));
4189
4215
  const instructions = [
@@ -4195,8 +4221,14 @@ async function runAgentAttempt(req, attempt) {
4195
4221
  // Last so a retry does not bust the cached tools+system prefix from
4196
4222
  // the first attempt. Inspect-and-continue, not start over: implement
4197
4223
  // shares the worktree and toolContext across attempts.
4198
- ...attempt > 0 ? [
4199
- "This run is a retry after a previous attempt that did not finish. Files, shell commands, or ingestion may already have been applied in this workspace \u2014 inspect what is already there and continue from it rather than repeating that work."
4224
+ ...retryReason === "missingReport" ? hasReadTools ? [
4225
+ "The previous attempt ended without reportStatus. Do not repeat side effects. Use the available read tools to inspect existing work if needed, then call reportStatus."
4226
+ ] : [
4227
+ "The previous attempt ended without reportStatus. Do not repeat side effects. Call reportStatus now."
4228
+ ] : retryReason === "missingReportAtStepLimit" ? [
4229
+ "The previous attempt reached its step limit without reportStatus and may be incomplete. Inspect existing work, finish only the remaining work, avoid repeated side effects, and call reportStatus."
4230
+ ] : attempt > 0 ? [
4231
+ "This run is a retry after a transient AI service error. Files, shell commands, or ingestion may already have been applied in this workspace \u2014 inspect what is already there and continue from it rather than repeating that work."
4200
4232
  ] : []
4201
4233
  ];
4202
4234
  const agent = new ToolLoopAgent({
@@ -4304,7 +4336,8 @@ async function runAgentAttempt(req, attempt) {
4304
4336
  },
4305
4337
  "Agent finished without calling reportStatus"
4306
4338
  );
4307
- throw new Error(MISSING_REPORT_STATUS_ERROR_MESSAGE);
4339
+ const incomplete = steps.length >= profile.maxSteps || lastStep?.finishReason !== "stop";
4340
+ throw new MissingReportError(incomplete);
4308
4341
  }
4309
4342
  const result = report.output;
4310
4343
  if (result.status !== "success") {
@@ -5995,13 +6028,21 @@ import { z as z32 } from "zod";
5995
6028
  import "zod";
5996
6029
  var DASHBOARD_API_BASE_URL = `${PROXY_BASE_URL}/dashboard`;
5997
6030
  var DashboardApiError = class extends Error {
5998
- constructor(status, message) {
5999
- super(message);
6031
+ constructor(status, body) {
6032
+ super("Couldn't complete the request.");
6000
6033
  this.status = status;
6034
+ this.body = body;
6001
6035
  this.name = "DashboardApiError";
6002
6036
  }
6003
6037
  status;
6038
+ body;
6039
+ errorBody() {
6040
+ return isRecord(this.body) ? this.body : void 0;
6041
+ }
6004
6042
  };
6043
+ function isRecord(value) {
6044
+ return !!value && typeof value === "object" && !Array.isArray(value);
6045
+ }
6005
6046
  async function dashboardRequest(path, schema, init) {
6006
6047
  const token = getAuthToken();
6007
6048
  if (!token) {
@@ -6016,17 +6057,24 @@ async function dashboardRequest(path, schema, init) {
6016
6057
  }
6017
6058
  });
6018
6059
  if (!res.ok) {
6019
- throw new DashboardApiError(
6020
- res.status,
6021
- `Dashboard API responded ${res.status} for ${path}`
6022
- );
6060
+ throw await dashboardError(res);
6023
6061
  }
6024
6062
  const body = await res.json();
6025
6063
  return { status: res.status, data: schema.parse(body) };
6026
6064
  }
6065
+ async function dashboardError(res) {
6066
+ try {
6067
+ return new DashboardApiError(res.status, await res.json());
6068
+ } catch {
6069
+ return new DashboardApiError(res.status, void 0);
6070
+ }
6071
+ }
6027
6072
 
6028
6073
  // src/lib/dashboardApi/schemas.ts
6029
6074
  import { z as z31 } from "zod";
6075
+ var messageResponseSchema = z31.object({
6076
+ message: z31.string()
6077
+ });
6030
6078
  var playbookSchema = z31.object({
6031
6079
  slug: z31.string(),
6032
6080
  category: z31.string().optional(),
@@ -6034,6 +6082,57 @@ var playbookSchema = z31.object({
6034
6082
  description: z31.string().optional()
6035
6083
  });
6036
6084
  var playbooksListSchema = z31.array(playbookSchema);
6085
+ var playbookExecutionStepSchema = z31.enum([
6086
+ "assessment",
6087
+ "optimization",
6088
+ "implement"
6089
+ ]);
6090
+ var playbookExecutionStepStatusSchema = z31.enum([
6091
+ "not_started",
6092
+ "in_progress",
6093
+ "done",
6094
+ "error"
6095
+ ]);
6096
+ var schemaComparisonEntrySchema = z31.object({
6097
+ canonical_attr: z31.string(),
6098
+ canonical_type: z31.array(z31.string()),
6099
+ canonical_roles: z31.array(z31.string()),
6100
+ canonical_required: z31.boolean(),
6101
+ index_attr: z31.string().nullable(),
6102
+ index_type: z31.array(z31.string()).nullable(),
6103
+ index_required: z31.boolean().nullable(),
6104
+ status: z31.string(),
6105
+ mapping_confidence: z31.number()
6106
+ });
6107
+ var settingsRecommendationSchema = z31.record(
6108
+ z31.string(),
6109
+ z31.object({
6110
+ current: z31.any(),
6111
+ recommended: z31.any()
6112
+ })
6113
+ );
6114
+ var assessmentResultSchema = z31.object({
6115
+ ready: z31.boolean(),
6116
+ schema_comparison: z31.array(schemaComparisonEntrySchema),
6117
+ settings_recommendation: settingsRecommendationSchema
6118
+ });
6119
+ var playbookExecutionSchema = z31.object({
6120
+ uuid: z31.string(),
6121
+ playbook_slug: z31.string(),
6122
+ application_id: z31.string(),
6123
+ source_index_name: z31.string(),
6124
+ current_step: playbookExecutionStepSchema,
6125
+ step_status: playbookExecutionStepStatusSchema,
6126
+ status_reason: z31.string().nullable(),
6127
+ completed: z31.boolean(),
6128
+ assessment_result: assessmentResultSchema.nullable(),
6129
+ settings_snapshot: z31.json().nullable(),
6130
+ created_at: z31.iso.datetime()
6131
+ });
6132
+ var playbookExecutionCreateResponseSchema = playbookExecutionSchema.extend({
6133
+ resumed: z31.boolean(),
6134
+ sample_data: z31.boolean()
6135
+ });
6037
6136
 
6038
6137
  // src/lib/dashboardApi/api.ts
6039
6138
  async function getPlaybooks() {
@@ -7556,7 +7655,7 @@ function delay(ms) {
7556
7655
  // package.json with { type: 'json' }
7557
7656
  var package_default2 = {
7558
7657
  name: "@algolia/wizard",
7559
- version: "0.70.0",
7658
+ version: "0.72.0",
7560
7659
  description: "Magically implement Algolia functionality in your codebase",
7561
7660
  type: "module",
7562
7661
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.70.0",
3
+ "version": "0.72.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {