@algolia/wizard 0.103.0-rc.217.763 → 0.103.0-rc.217.764

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 +76 -70
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -2467,7 +2467,7 @@ async function ensureApplication(resumeAppId) {
2467
2467
  // package.json
2468
2468
  var package_default = {
2469
2469
  name: "@algolia/wizard",
2470
- version: "0.103.0-rc.217.763",
2470
+ version: "0.103.0-rc.217.764",
2471
2471
  description: "Magically implement Algolia functionality in your codebase",
2472
2472
  type: "module",
2473
2473
  engines: {
@@ -3909,82 +3909,87 @@ function writeCredentialsTool(ctx) {
3909
3909
  if (!targetIndex) {
3910
3910
  return "Error: no target index is set for this run, so a scoped write key cannot be provisioned.";
3911
3911
  }
3912
- let existing = "";
3913
- let present;
3914
- try {
3915
- const targetError = await validateSafeWriteTarget(ctx, resolved2.target);
3916
- if (targetError) return targetError;
3912
+ return withFileLock(resolved2.target, async () => {
3913
+ let existing = "";
3914
+ let present;
3917
3915
  try {
3918
- existing = await readFile7(resolved2.target, "utf8");
3916
+ const targetError = await validateSafeWriteTarget(
3917
+ ctx,
3918
+ resolved2.target
3919
+ );
3920
+ if (targetError) return targetError;
3921
+ try {
3922
+ existing = await readFile7(resolved2.target, "utf8");
3923
+ } catch (err) {
3924
+ if (err.code !== "ENOENT") throw err;
3925
+ }
3926
+ present = [APP_ID_VAR, API_KEY_VAR].filter(
3927
+ (name) => readEnv(existing, name) !== null
3928
+ );
3919
3929
  } catch (err) {
3920
- if (err.code !== "ENOENT") throw err;
3930
+ return `Error writing credentials to ${filePath}: ${err.message}`;
3921
3931
  }
3922
- present = [APP_ID_VAR, API_KEY_VAR].filter(
3923
- (name) => readEnv(existing, name) !== null
3924
- );
3925
- } catch (err) {
3926
- return `Error writing credentials to ${filePath}: ${err.message}`;
3927
- }
3928
- const credentials = [];
3929
- const notes = [];
3930
- const fileAppId = readEnv(existing, APP_ID_VAR);
3931
- const fileKey = readEnv(existing, API_KEY_VAR);
3932
- const fileIndex = readEnv(existing, INDEX_NAME_VAR);
3933
- if (fileAppId === null || fileKey === null) {
3934
- try {
3935
- const selected = (await requireApplication(ctx.appId)).id;
3936
- if (fileAppId === null) credentials.push([APP_ID_VAR, selected]);
3937
- if (fileKey === null) {
3938
- if (fileAppId !== null && fileAppId !== selected) {
3932
+ const credentials = [];
3933
+ const notes = [];
3934
+ const fileAppId = readEnv(existing, APP_ID_VAR);
3935
+ const fileKey = readEnv(existing, API_KEY_VAR);
3936
+ const fileIndex = readEnv(existing, INDEX_NAME_VAR);
3937
+ if (fileAppId === null || fileKey === null) {
3938
+ try {
3939
+ const selected = (await requireApplication(ctx.appId)).id;
3940
+ if (fileAppId === null) credentials.push([APP_ID_VAR, selected]);
3941
+ if (fileKey === null) {
3942
+ if (fileAppId !== null && fileAppId !== selected) {
3943
+ notes.push(
3944
+ `No ${API_KEY_VAR} was provisioned: ${filePath} names application ${fileAppId}, but ${selected} is selected. Tell the user to remove ${APP_ID_VAR} from ${filePath} and re-run so a matching pair can be written, or to fill in a ${API_KEY_VAR} for ${fileAppId} by hand.`
3945
+ );
3946
+ } else {
3947
+ credentials.push([
3948
+ API_KEY_VAR,
3949
+ (await resolveWriteKey(targetIndex, selected)).key
3950
+ ]);
3951
+ }
3952
+ } else {
3939
3953
  notes.push(
3940
- `No ${API_KEY_VAR} was provisioned: ${filePath} names application ${fileAppId}, but ${selected} is selected. Tell the user to remove ${APP_ID_VAR} from ${filePath} and re-run so a matching pair can be written, or to fill in a ${API_KEY_VAR} for ${fileAppId} by hand.`
3954
+ `The existing ${API_KEY_VAR} must belong to application ${selected} or writes will fail.`
3941
3955
  );
3942
- } else {
3943
- credentials.push([
3944
- API_KEY_VAR,
3945
- (await resolveWriteKey(targetIndex, selected)).key
3946
- ]);
3947
3956
  }
3948
- } else {
3949
- notes.push(
3950
- `The existing ${API_KEY_VAR} must belong to application ${selected} or writes will fail.`
3951
- );
3957
+ } catch (err) {
3958
+ return `Error: could not resolve Algolia credentials (${err.message})`;
3952
3959
  }
3953
- } catch (err) {
3954
- return `Error: could not resolve Algolia credentials (${err.message})`;
3955
3960
  }
3956
- }
3957
- let wrote;
3958
- try {
3959
- const updated = [
3960
- ...credentials,
3961
- // Unconditional, unlike the credentials: the write key is scoped to
3962
- // the run's index, so a stale name left in the file earns a 403.
3963
- [INDEX_NAME_VAR, targetIndex]
3964
- ].reduce(
3965
- (content, [name, value]) => upsertEnv(content, name, value),
3966
- existing
3967
- );
3968
- const writeError = await safeWriteFile(ctx, resolved2.target, updated);
3969
- if (writeError) return writeError;
3970
- const sentences = [
3971
- `Wrote ${[...credentials.map(([name]) => name), INDEX_NAME_VAR].join(", ")} to ${filePath}.`
3972
- ];
3973
- if (fileIndex !== null && fileIndex !== targetIndex) {
3974
- sentences.push(
3975
- `That replaced the ${INDEX_NAME_VAR} already there ("${fileIndex}"), which this run does not target.`
3976
- );
3977
- }
3978
- if (present.length > 0) {
3979
- sentences.push(
3980
- `Skipped ${present.join(" and ")}: already defined there.`
3961
+ let wrote;
3962
+ try {
3963
+ const updated = [
3964
+ ...credentials,
3965
+ // Unconditional, unlike the credentials: the write key is scoped to
3966
+ // the run's index, so a stale name left in the file earns a 403.
3967
+ [INDEX_NAME_VAR, targetIndex]
3968
+ ].reduce(
3969
+ (content, [name, value]) => upsertEnv(content, name, value),
3970
+ existing
3981
3971
  );
3972
+ const writeError = await safeWriteFile(ctx, resolved2.target, updated);
3973
+ if (writeError) return writeError;
3974
+ const sentences = [
3975
+ `Wrote ${[...credentials.map(([name]) => name), INDEX_NAME_VAR].join(", ")} to ${filePath}.`
3976
+ ];
3977
+ if (fileIndex !== null && fileIndex !== targetIndex) {
3978
+ sentences.push(
3979
+ `That replaced the ${INDEX_NAME_VAR} already there ("${fileIndex}"), which this run does not target.`
3980
+ );
3981
+ }
3982
+ if (present.length > 0) {
3983
+ sentences.push(
3984
+ `Skipped ${present.join(" and ")}: already defined there.`
3985
+ );
3986
+ }
3987
+ wrote = [...sentences, ...notes].join(" ");
3988
+ } catch (err) {
3989
+ return `Error writing credentials to ${filePath}: ${err.message}`;
3982
3990
  }
3983
- wrote = [...sentences, ...notes].join(" ");
3984
- } catch (err) {
3985
- return `Error writing credentials to ${filePath}: ${err.message}`;
3986
- }
3987
- return wrote + await gitIgnoreOutcome(ctx, resolved2.target);
3991
+ return wrote + await gitIgnoreOutcome(ctx, resolved2.target);
3992
+ });
3988
3993
  }
3989
3994
  });
3990
3995
  }
@@ -5738,7 +5743,7 @@ async function runAgentAttempt(req, attempt, retryReason, continuation) {
5738
5743
  continuation: continuation?.number ?? 0,
5739
5744
  durationMs: end - start,
5740
5745
  usage,
5741
- stepCount: totalSteps,
5746
+ stepCount,
5742
5747
  hitStepLimit,
5743
5748
  finishReason
5744
5749
  });
@@ -5750,7 +5755,8 @@ async function runAgentAttempt(req, attempt, retryReason, continuation) {
5750
5755
  profile: profileName,
5751
5756
  model: profile.model,
5752
5757
  usage,
5753
- stepCount: totalSteps,
5758
+ stepCount,
5759
+ totalSteps,
5754
5760
  maxSteps,
5755
5761
  hitStepLimit,
5756
5762
  finishReason
@@ -10174,7 +10180,7 @@ async function resetProjectState() {
10174
10180
  // package.json with { type: 'json' }
10175
10181
  var package_default2 = {
10176
10182
  name: "@algolia/wizard",
10177
- version: "0.103.0-rc.217.763",
10183
+ version: "0.103.0-rc.217.764",
10178
10184
  description: "Magically implement Algolia functionality in your codebase",
10179
10185
  type: "module",
10180
10186
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.103.0-rc.217.763",
3
+ "version": "0.103.0-rc.217.764",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {