@algolia/wizard 0.48.0 → 0.50.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 +200 -58
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1710,11 +1710,31 @@ async function runStep(state, index, step, appId) {
1710
1710
  durationMs: Date.now() - startedAt
1711
1711
  });
1712
1712
  }
1713
- async function runWorkflow(workflow, appId, resumableState) {
1713
+ var RESUME_OPTION = "Resume";
1714
+ var START_NEW_OPTION = "Start a new one";
1715
+ async function resolveWorkflowState(workflow, appId, options) {
1716
+ const resumed = options?.resumableState !== void 0 ? options.resumableState : await loadResumableState(workflow);
1717
+ if (!resumed) {
1718
+ return initWorkflowState(workflow, nowIso(), appId);
1719
+ }
1720
+ if (options?.skipResumePrompt) {
1721
+ return resumed;
1722
+ }
1723
+ const answer = await useWizard.getState().requestUserInput({
1724
+ prompt: "You have a previous session. Do you want to resume, or start a new one?",
1725
+ promptType: "multipleChoice",
1726
+ options: [RESUME_OPTION, START_NEW_OPTION]
1727
+ });
1728
+ if (answer === START_NEW_OPTION) {
1729
+ await clearWorkflowState(workflow.id);
1730
+ return initWorkflowState(workflow, nowIso(), appId);
1731
+ }
1732
+ return resumed;
1733
+ }
1734
+ async function runWorkflow(workflow, appId, options) {
1714
1735
  const store = useWizard.getState();
1715
1736
  try {
1716
- const resolved2 = resumableState !== void 0 ? resumableState : await loadResumableState(workflow);
1717
- const state = resolved2 ?? initWorkflowState(workflow, nowIso(), appId);
1737
+ const state = await resolveWorkflowState(workflow, appId, options);
1718
1738
  ensureExecutedStepCount(state);
1719
1739
  store.startWorkflow(
1720
1740
  {
@@ -3584,7 +3604,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3584
3604
  // package.json
3585
3605
  var package_default = {
3586
3606
  name: "@algolia/wizard",
3587
- version: "0.48.0",
3607
+ version: "0.50.0",
3588
3608
  description: "Magically implement Algolia functionality in your codebase",
3589
3609
  type: "module",
3590
3610
  engines: {
@@ -4868,9 +4888,168 @@ var defaultWorkflow = {
4868
4888
  ]
4869
4889
  };
4870
4890
 
4891
+ // src/actions/playbookSteps/selectPlaybook.ts
4892
+ import { z as z32 } from "zod";
4893
+
4894
+ // src/lib/dashboardApi/client.ts
4895
+ import "zod";
4896
+ var DASHBOARD_API_BASE_URL = `${PROXY_BASE_URL}/dashboard`;
4897
+ var DashboardApiError = class extends Error {
4898
+ constructor(status, message) {
4899
+ super(message);
4900
+ this.status = status;
4901
+ this.name = "DashboardApiError";
4902
+ }
4903
+ status;
4904
+ };
4905
+ async function dashboardRequest(path, schema, init) {
4906
+ const token = getAuthToken();
4907
+ if (!token) {
4908
+ throw new Error("Not authenticated: no user token available");
4909
+ }
4910
+ const res = await proxyFetch(`${DASHBOARD_API_BASE_URL}${path}`, {
4911
+ ...init,
4912
+ headers: {
4913
+ accept: "application/json",
4914
+ authorization: `Bearer ${token}`,
4915
+ ...init?.headers
4916
+ }
4917
+ });
4918
+ if (!res.ok) {
4919
+ throw new DashboardApiError(
4920
+ res.status,
4921
+ `Dashboard API responded ${res.status} for ${path}`
4922
+ );
4923
+ }
4924
+ const body = await res.json();
4925
+ return { status: res.status, data: schema.parse(body) };
4926
+ }
4927
+
4928
+ // src/lib/dashboardApi/schemas.ts
4929
+ import { z as z31 } from "zod";
4930
+ var playbookSchema = z31.object({
4931
+ slug: z31.string(),
4932
+ category: z31.string().optional(),
4933
+ title: z31.string(),
4934
+ description: z31.string().optional()
4935
+ });
4936
+ var playbooksListSchema = z31.array(playbookSchema);
4937
+
4938
+ // src/lib/dashboardApi/api.ts
4939
+ async function getPlaybooks() {
4940
+ const { data } = await dashboardRequest(
4941
+ "/api/1/playbook-integrations/playbooks",
4942
+ playbooksListSchema
4943
+ );
4944
+ return data;
4945
+ }
4946
+
4947
+ // src/actions/playbookSteps/selectPlaybook.ts
4948
+ var selectPlaybookSchema = z32.object({
4949
+ slug: z32.string()
4950
+ });
4951
+ function persistSlug(ctx, slug) {
4952
+ ctx.setUserInput("playbookSlug", slug);
4953
+ return { slug };
4954
+ }
4955
+ async function selectPlaybookStep(ctx, requestedSlug) {
4956
+ const playbooks = await getPlaybooks();
4957
+ const slugs = playbooks.map((playbook) => playbook.slug);
4958
+ if (slugs.length === 0) {
4959
+ throw new Error("No playbooks are available.");
4960
+ }
4961
+ if (requestedSlug && slugs.includes(requestedSlug)) {
4962
+ return persistSlug(ctx, requestedSlug);
4963
+ }
4964
+ const messages = requestedSlug ? [
4965
+ `"${requestedSlug}" is not a valid playbook. Choose one of the available playbooks:`
4966
+ ] : ["Choose a playbook:"];
4967
+ const selection = await ctx.requestUserInput({
4968
+ prompt: "Which playbook do you want to run?",
4969
+ promptType: "multipleChoice",
4970
+ options: slugs,
4971
+ messages
4972
+ });
4973
+ if (typeof selection !== "string") {
4974
+ throw new Error("selectPlaybook received an unexpected non-text result");
4975
+ }
4976
+ return persistSlug(ctx, selection);
4977
+ }
4978
+
4979
+ // src/lib/cli.ts
4980
+ var USAGE = `Usage: wizard [workflow-id] [options]
4981
+ wizard playbook [playbook-slug] [options]
4982
+
4983
+ Options:
4984
+ --seed <step-id> Start the workflow at the step with this id, with earlier
4985
+ steps pre-filled with test data. Pass with no value to print
4986
+ the step ids. See CONTRIBUTING.md.
4987
+ --no-telemetry Send no telemetry or analytics for this run.
4988
+ --reset-on-run Wipe this project's wizard state (run state, AI consent)
4989
+ before starting, so the run behaves like a first-ever
4990
+ run. Also drops every API key the wizard has
4991
+ stored in your keychain (or, where the platform has none,
4992
+ the encrypted file it falls back to \u2014 see CONTRIBUTING.md),
4993
+ for this project and any other, so later runs create new
4994
+ ones. Your Algolia login is not touched.
4995
+ -h, --help Print this message.`;
4996
+ function parseCliArgs(argv) {
4997
+ const positionals = [];
4998
+ let seed;
4999
+ let telemetry = true;
5000
+ let resetOnRun = false;
5001
+ let help = false;
5002
+ for (let i = 0; i < argv.length; i++) {
5003
+ const arg = argv[i];
5004
+ if (arg === "--seed") {
5005
+ const next = argv[i + 1];
5006
+ if (next !== void 0 && !next.startsWith("-")) {
5007
+ seed = next;
5008
+ i++;
5009
+ } else {
5010
+ seed = null;
5011
+ }
5012
+ } else if (arg.startsWith("--seed=")) {
5013
+ seed = arg.slice("--seed=".length);
5014
+ } else if (arg === "--no-telemetry") {
5015
+ telemetry = false;
5016
+ } else if (arg === "--reset-on-run") {
5017
+ resetOnRun = true;
5018
+ } else if (arg === "--help" || arg === "-h") {
5019
+ help = true;
5020
+ } else if (arg.startsWith("-")) {
5021
+ throw new Error(`Unknown option "${arg}".`);
5022
+ } else {
5023
+ positionals.push(arg);
5024
+ }
5025
+ }
5026
+ return { positionals, seed, telemetry, resetOnRun, help };
5027
+ }
5028
+ function getPlaybookSlugArg(argv = process.argv.slice(2)) {
5029
+ const { positionals } = parseCliArgs(argv);
5030
+ if (positionals[0] !== "playbook") return void 0;
5031
+ return positionals[1];
5032
+ }
5033
+
5034
+ // src/workflows/playbook.ts
5035
+ var playbookWorkflow = {
5036
+ id: "playbook",
5037
+ title: "Playbook Workflow",
5038
+ description: "Select a playbook from the dashboard catalogue and walk through its implementation.",
5039
+ steps: [
5040
+ defineStep({
5041
+ id: "select-playbook",
5042
+ title: "Select playbook",
5043
+ outputSchema: selectPlaybookSchema,
5044
+ run: (ctx) => selectPlaybookStep(ctx, getPlaybookSlugArg())
5045
+ })
5046
+ ]
5047
+ };
5048
+
4871
5049
  // src/workflows/index.ts
4872
5050
  var workflows = {
4873
- [defaultWorkflow.id]: defaultWorkflow
5051
+ [defaultWorkflow.id]: defaultWorkflow,
5052
+ [playbookWorkflow.id]: playbookWorkflow
4874
5053
  };
4875
5054
  function getWorkflow(id) {
4876
5055
  return workflows[id];
@@ -6051,6 +6230,9 @@ var search = {
6051
6230
  ]
6052
6231
  }
6053
6232
  };
6233
+ var selectPlaybook = {
6234
+ slug: "orders"
6235
+ };
6054
6236
  var review = {
6055
6237
  summaryPoints: [
6056
6238
  "Ingested 25 generated Product records into wizard_seed_products.",
@@ -6069,6 +6251,9 @@ var SEEDS = {
6069
6251
  "confirm-framework": confirmFramework2,
6070
6252
  search,
6071
6253
  review
6254
+ },
6255
+ playbook: {
6256
+ "select-playbook": selectPlaybook
6072
6257
  }
6073
6258
  };
6074
6259
  var SEED_USER_INPUTS = {
@@ -6077,6 +6262,9 @@ var SEED_USER_INPUTS = {
6077
6262
  confirmedEntities: confirmEntities2.confirmedEntities,
6078
6263
  ingestionAnalysis: confirmEntities2.ingestionAnalysis,
6079
6264
  implementation: "success"
6265
+ },
6266
+ playbook: {
6267
+ playbookSlug: selectPlaybook.slug
6080
6268
  }
6081
6269
  };
6082
6270
  function formatStepList(workflow, startIndex) {
@@ -6139,7 +6327,9 @@ async function seedWorkflowState(workflow, value) {
6139
6327
  if (!config.aiConsent) {
6140
6328
  config.aiConsent = true;
6141
6329
  await saveConfig(config);
6142
- messages.push("Seed: set aiConsent in the project config (skips the consent prompt).");
6330
+ messages.push(
6331
+ "Seed: set aiConsent in the project config (skips the consent prompt)."
6332
+ );
6143
6333
  }
6144
6334
  if (startIndex === 0) {
6145
6335
  await clearWorkflowState(workflow.id);
@@ -6165,55 +6355,6 @@ async function seedWorkflowState(workflow, value) {
6165
6355
  return { messages };
6166
6356
  }
6167
6357
 
6168
- // src/lib/cli.ts
6169
- var USAGE = `Usage: wizard [workflow-id] [options]
6170
-
6171
- Options:
6172
- --seed <step-id> Start the workflow at the step with this id, with earlier
6173
- steps pre-filled with test data. Pass with no value to print
6174
- the step ids. See CONTRIBUTING.md.
6175
- --no-telemetry Send no telemetry or analytics for this run.
6176
- --reset-on-run Wipe this project's wizard state (run state, AI consent)
6177
- before starting, so the run behaves like a first-ever
6178
- run. Also drops every API key the wizard has
6179
- stored in your keychain (or, where the platform has none,
6180
- the encrypted file it falls back to \u2014 see CONTRIBUTING.md),
6181
- for this project and any other, so later runs create new
6182
- ones. Your Algolia login is not touched.
6183
- -h, --help Print this message.`;
6184
- function parseCliArgs(argv) {
6185
- const positionals = [];
6186
- let seed;
6187
- let telemetry = true;
6188
- let resetOnRun = false;
6189
- let help = false;
6190
- for (let i = 0; i < argv.length; i++) {
6191
- const arg = argv[i];
6192
- if (arg === "--seed") {
6193
- const next = argv[i + 1];
6194
- if (next !== void 0 && !next.startsWith("-")) {
6195
- seed = next;
6196
- i++;
6197
- } else {
6198
- seed = null;
6199
- }
6200
- } else if (arg.startsWith("--seed=")) {
6201
- seed = arg.slice("--seed=".length);
6202
- } else if (arg === "--no-telemetry") {
6203
- telemetry = false;
6204
- } else if (arg === "--reset-on-run") {
6205
- resetOnRun = true;
6206
- } else if (arg === "--help" || arg === "-h") {
6207
- help = true;
6208
- } else if (arg.startsWith("-")) {
6209
- throw new Error(`Unknown option "${arg}".`);
6210
- } else {
6211
- positionals.push(arg);
6212
- }
6213
- }
6214
- return { positionals, seed, telemetry, resetOnRun, help };
6215
- }
6216
-
6217
6358
  // src/lib/resetState.ts
6218
6359
  import { readdir as readdir3, rm as rm2 } from "node:fs/promises";
6219
6360
  import { join as join13 } from "node:path";
@@ -6322,9 +6463,10 @@ ${formatStepList(workflow)}`);
6322
6463
  return 1;
6323
6464
  }
6324
6465
  }
6325
- return workflow;
6466
+ return { workflow, skipResumePrompt: args.seed !== void 0 };
6326
6467
  }
6327
- async function run(workflow) {
6468
+ async function run(opts) {
6469
+ const { workflow, skipResumePrompt } = opts;
6328
6470
  const store = useWizard.getState();
6329
6471
  const instance = render(/* @__PURE__ */ jsx19(App, {}), { incrementalRendering: true });
6330
6472
  await store.waitForStart();
@@ -6369,7 +6511,7 @@ async function run(workflow) {
6369
6511
  await instance.waitUntilExit();
6370
6512
  process.exit(1);
6371
6513
  }
6372
- runWorkflow(workflow, app.id, resumableState);
6514
+ runWorkflow(workflow, app.id, { skipResumePrompt, resumableState });
6373
6515
  }
6374
6516
  await requestTerminalSize();
6375
6517
  var started = await startup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {