@algolia/wizard 0.43.0 → 0.44.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 +103 -51
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -3472,7 +3472,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3472
3472
  // package.json
3473
3473
  var package_default = {
3474
3474
  name: "@algolia/wizard",
3475
- version: "0.43.0",
3475
+ version: "0.44.0",
3476
3476
  description: "Magically implement Algolia functionality in your codebase",
3477
3477
  type: "module",
3478
3478
  engines: {
@@ -3727,6 +3727,7 @@ async function promptUser(ctx, params) {
3727
3727
  table,
3728
3728
  secondary,
3729
3729
  cancelable,
3730
+ error,
3730
3731
  onSubmit
3731
3732
  } = params;
3732
3733
  const question = promptContent.find((c) => c.type === "question")?.value ?? "";
@@ -3741,7 +3742,8 @@ async function promptUser(ctx, params) {
3741
3742
  table,
3742
3743
  secondary,
3743
3744
  cancelable,
3744
- helpText
3745
+ helpText,
3746
+ error
3745
3747
  });
3746
3748
  ctx.setUserInput(workflowStateKey, selection);
3747
3749
  onSubmit();
@@ -3755,68 +3757,118 @@ var confirmEntitiesSchema = z26.object({
3755
3757
  ingestionAnalysis: ingestionAnalysisSchema.shape.ingestionAnalysis.optional(),
3756
3758
  confirmedEntities: confirmedEntitiesFieldSchema
3757
3759
  });
3760
+ var SUGGEST_ENTITY = "Suggest a different entity\u2026";
3761
+ async function askEntityName(ctx, opts) {
3762
+ const blankHint = opts?.blankHint ?? "cancel";
3763
+ const declared = await promptUser(ctx, {
3764
+ workflowStateKey: "confirmedEntities",
3765
+ promptType: "textInput",
3766
+ error: opts?.error,
3767
+ promptContent: [
3768
+ ...opts?.message ? [{ type: "message", value: opts.message }] : [],
3769
+ {
3770
+ type: "question",
3771
+ value: `Name an entity to search for (leave blank to ${blankHint}):`
3772
+ }
3773
+ ],
3774
+ onSubmit: () => {
3775
+ }
3776
+ });
3777
+ if (typeof declared !== "string" || declared.trim() === "") return null;
3778
+ return declared.trim();
3779
+ }
3780
+ function sameEntityName(a, b) {
3781
+ return a.toLowerCase() === b.toLowerCase();
3782
+ }
3783
+ async function resolveSuggestedEntity(ctx, declaredName) {
3784
+ ctx.setUserInput("confirmedEntities", [declaredName]);
3785
+ ctx.clearNotices();
3786
+ ctx.notify({
3787
+ messages: [
3788
+ `Scanning the codebase for the entity "${declaredName}" and other domain models`
3789
+ ]
3790
+ });
3791
+ const rerun = await runAnalysis("ingestion", [
3792
+ `The user has confirmed the codebase contains an entity named "${declaredName}". Focus your search on locating this entity, the file path(s) where it is defined, and its indexable attribute keys.`
3793
+ ]);
3794
+ const detected = rerun.ingestionAnalysis ?? [];
3795
+ const found = detected.some((e) => sameEntityName(e.name, declaredName));
3796
+ track("AI Wizard Suggest Different Entity", {
3797
+ entity_name: declaredName,
3798
+ found
3799
+ });
3800
+ if (!found) return { found: false };
3801
+ ctx.setUserInput("ingestionAnalysis", detected);
3802
+ return { found: true, entities: detected };
3803
+ }
3758
3804
  async function confirmEntities(ctx) {
3759
3805
  const scan = ctx.getStepOutput("project-scan");
3760
3806
  let entities = scan.ingestionAnalysis;
3761
3807
  if (!entities?.length) {
3762
- const declared = await promptUser(ctx, {
3808
+ let nameError = void 0;
3809
+ for (; ; ) {
3810
+ const declaredName = await askEntityName(ctx, {
3811
+ message: nameError ? void 0 : "We couldn't detect any entities to ingest in this codebase.",
3812
+ error: nameError,
3813
+ blankHint: "cancel"
3814
+ });
3815
+ if (declaredName === null) {
3816
+ throw new Error("User declined to specify an entity \u2014 analysis halted.");
3817
+ }
3818
+ const resolved2 = await resolveSuggestedEntity(ctx, declaredName);
3819
+ if (resolved2.found) {
3820
+ entities = resolved2.entities;
3821
+ break;
3822
+ }
3823
+ nameError = `We couldn't find "${declaredName}"`;
3824
+ }
3825
+ }
3826
+ let listError = void 0;
3827
+ for (; ; ) {
3828
+ const selection = await promptUser(ctx, {
3763
3829
  workflowStateKey: "confirmedEntities",
3764
- promptType: "textInput",
3830
+ promptType: "multipleChoice",
3831
+ cancelable: true,
3832
+ error: listError,
3833
+ secondary: [
3834
+ ...entities.map((e) => ({
3835
+ kind: "text",
3836
+ value: e.attributes.join(", ") || "\u2014"
3837
+ })),
3838
+ { kind: "text", value: "\u2014" }
3839
+ ],
3765
3840
  promptContent: [
3766
- {
3767
- type: "message",
3768
- value: "We couldn't detect any entities to ingest in this codebase."
3769
- },
3770
- {
3771
- type: "question",
3772
- value: "Name an entity to search for (leave blank to cancel):"
3773
- }
3841
+ { type: "question", value: "Pick the entity to index" },
3842
+ ...entities.map((e) => ({ type: "option", value: e.name })),
3843
+ { type: "option", value: SUGGEST_ENTITY }
3774
3844
  ],
3775
3845
  onSubmit: () => {
3776
3846
  }
3777
3847
  });
3778
- if (typeof declared !== "string" || declared.trim() === "") {
3779
- throw new Error("User declined to specify an entity \u2014 analysis halted.");
3780
- }
3781
- const declaredName = declared.trim();
3782
- ctx.setUserInput("confirmedEntities", [declaredName]);
3783
- const rerun = await runAnalysis("ingestion", [
3784
- `The user has confirmed the codebase contains an entity named "${declaredName}". Focus your search on locating this entity, the file path(s) where it is defined, and its indexable attribute keys.`
3785
- ]);
3786
- entities = rerun.ingestionAnalysis;
3787
- ctx.setUserInput("ingestionAnalysis", entities);
3788
- if (!entities?.length) {
3789
- throw new Error(
3790
- `Could not locate the "${declaredName}" entity in this codebase \u2014 analysis halted.`
3791
- );
3848
+ listError = void 0;
3849
+ if (selection === SUGGEST_ENTITY) {
3850
+ const declaredName = await askEntityName(ctx, {
3851
+ blankHint: "go back"
3852
+ });
3853
+ if (declaredName === null) continue;
3854
+ const resolved2 = await resolveSuggestedEntity(ctx, declaredName);
3855
+ if (!resolved2.found) {
3856
+ listError = `We couldn't find "${declaredName}"`;
3857
+ continue;
3858
+ }
3859
+ entities = resolved2.entities;
3860
+ continue;
3792
3861
  }
3793
- }
3794
- const selection = await promptUser(ctx, {
3795
- workflowStateKey: "confirmedEntities",
3796
- promptType: "multipleChoice",
3797
- // A Cancel row lets the user halt here (the single-select equivalent of the
3798
- // old multi-select Cancel); its 'cancel' sentinel matches no entity below.
3799
- cancelable: true,
3800
- secondary: entities.map((e) => ({
3801
- kind: "text",
3802
- value: e.attributes.join(", ") || "\u2014"
3803
- })),
3804
- promptContent: [
3805
- { type: "question", value: "Pick the entity to index" },
3806
- ...entities.map((e) => ({ type: "option", value: e.name }))
3807
- ],
3808
- onSubmit: () => {
3862
+ const confirmed2 = typeof selection === "string" ? entities.filter((e) => e.name === selection) : [];
3863
+ if (confirmed2.length === 0) {
3864
+ throw new Error("User cancelled entity selection \u2014 analysis halted.");
3809
3865
  }
3810
- });
3811
- const confirmed2 = typeof selection === "string" ? entities.filter((e) => e.name === selection) : [];
3812
- if (confirmed2.length === 0) {
3813
- throw new Error("User cancelled entity selection \u2014 analysis halted.");
3866
+ ctx.setUserInput("confirmedEntities", confirmed2);
3867
+ track("AI Wizard Entities Confirmed", {
3868
+ entities: toEntitySummary(confirmed2)
3869
+ });
3870
+ return { ingestionAnalysis: entities, confirmedEntities: confirmed2 };
3814
3871
  }
3815
- ctx.setUserInput("confirmedEntities", confirmed2);
3816
- track("AI Wizard Entities Confirmed", {
3817
- entities: toEntitySummary(confirmed2)
3818
- });
3819
- return { ingestionAnalysis: entities, confirmedEntities: confirmed2 };
3820
3872
  }
3821
3873
 
3822
3874
  // src/actions/review.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {