@canonical/summon-core 0.31.0 → 0.32.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 (97) hide show
  1. package/dist/esm/execute/GeneratorResult.js +13 -0
  2. package/dist/esm/execute/GeneratorResult.js.map +1 -0
  3. package/dist/esm/execute/collectAnswers.js +92 -0
  4. package/dist/esm/execute/collectAnswers.js.map +1 -0
  5. package/dist/esm/execute/execute.js +73 -0
  6. package/dist/esm/execute/execute.js.map +1 -0
  7. package/dist/esm/execute/index.js +4 -0
  8. package/dist/esm/execute/index.js.map +1 -0
  9. package/dist/esm/execute/validateAnswers.js +47 -0
  10. package/dist/esm/execute/validateAnswers.js.map +1 -0
  11. package/dist/esm/format/effects.js +581 -0
  12. package/dist/esm/format/effects.js.map +1 -0
  13. package/dist/esm/format/index.js +2 -0
  14. package/dist/esm/format/index.js.map +1 -0
  15. package/dist/esm/index.js +8 -1
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/prompt/answerPromptWithDefaults.js +26 -0
  18. package/dist/esm/prompt/answerPromptWithDefaults.js.map +1 -0
  19. package/dist/esm/prompt/autoPrompt.js +50 -0
  20. package/dist/esm/prompt/autoPrompt.js.map +1 -0
  21. package/dist/esm/prompt/index.js +12 -0
  22. package/dist/esm/prompt/index.js.map +1 -0
  23. package/dist/esm/prompt/ink/Spinner.js +18 -0
  24. package/dist/esm/prompt/ink/Spinner.js.map +1 -0
  25. package/dist/esm/prompt/ink/Wizard.js +107 -0
  26. package/dist/esm/prompt/ink/Wizard.js.map +1 -0
  27. package/dist/esm/prompt/ink/mount.js +41 -0
  28. package/dist/esm/prompt/ink/mount.js.map +1 -0
  29. package/dist/esm/prompt/ink/prompts.js +144 -0
  30. package/dist/esm/prompt/ink/prompts.js.map +1 -0
  31. package/dist/esm/prompt/ink/session.js +176 -0
  32. package/dist/esm/prompt/ink/session.js.map +1 -0
  33. package/dist/esm/prompt/inkPrompt.js +55 -0
  34. package/dist/esm/prompt/inkPrompt.js.map +1 -0
  35. package/dist/esm/prompt/mcpPrompt.js +29 -0
  36. package/dist/esm/prompt/mcpPrompt.js.map +1 -0
  37. package/dist/esm/prompt/types.js +12 -0
  38. package/dist/esm/prompt/types.js.map +1 -0
  39. package/dist/esm/run/index.js +2 -0
  40. package/dist/esm/run/index.js.map +1 -0
  41. package/dist/esm/run/runGeneratorTask.js +63 -0
  42. package/dist/esm/run/runGeneratorTask.js.map +1 -0
  43. package/dist/esm/stamp/createGeneratorStamp.js +19 -0
  44. package/dist/esm/stamp/createGeneratorStamp.js.map +1 -0
  45. package/dist/esm/stamp/createStampOnEffectStart.js +23 -0
  46. package/dist/esm/stamp/createStampOnEffectStart.js.map +1 -0
  47. package/dist/esm/stamp/index.js +2 -0
  48. package/dist/esm/stamp/index.js.map +1 -1
  49. package/dist/types/execute/GeneratorResult.d.ts +23 -0
  50. package/dist/types/execute/GeneratorResult.d.ts.map +1 -0
  51. package/dist/types/execute/collectAnswers.d.ts +52 -0
  52. package/dist/types/execute/collectAnswers.d.ts.map +1 -0
  53. package/dist/types/execute/execute.d.ts +57 -0
  54. package/dist/types/execute/execute.d.ts.map +1 -0
  55. package/dist/types/execute/index.d.ts +6 -0
  56. package/dist/types/execute/index.d.ts.map +1 -0
  57. package/dist/types/execute/validateAnswers.d.ts +23 -0
  58. package/dist/types/execute/validateAnswers.d.ts.map +1 -0
  59. package/dist/types/format/effects.d.ts +86 -0
  60. package/dist/types/format/effects.d.ts.map +1 -0
  61. package/dist/types/format/index.d.ts +2 -0
  62. package/dist/types/format/index.d.ts.map +1 -0
  63. package/dist/types/index.d.ts +8 -1
  64. package/dist/types/index.d.ts.map +1 -1
  65. package/dist/types/prompt/answerPromptWithDefaults.d.ts +17 -0
  66. package/dist/types/prompt/answerPromptWithDefaults.d.ts.map +1 -0
  67. package/dist/types/prompt/autoPrompt.d.ts +35 -0
  68. package/dist/types/prompt/autoPrompt.d.ts.map +1 -0
  69. package/dist/types/prompt/index.d.ts +14 -0
  70. package/dist/types/prompt/index.d.ts.map +1 -0
  71. package/dist/types/prompt/ink/Spinner.d.ts +11 -0
  72. package/dist/types/prompt/ink/Spinner.d.ts.map +1 -0
  73. package/dist/types/prompt/ink/Wizard.d.ts +14 -0
  74. package/dist/types/prompt/ink/Wizard.d.ts.map +1 -0
  75. package/dist/types/prompt/ink/mount.d.ts +31 -0
  76. package/dist/types/prompt/ink/mount.d.ts.map +1 -0
  77. package/dist/types/prompt/ink/prompts.d.ts +26 -0
  78. package/dist/types/prompt/ink/prompts.d.ts.map +1 -0
  79. package/dist/types/prompt/ink/session.d.ts +103 -0
  80. package/dist/types/prompt/ink/session.d.ts.map +1 -0
  81. package/dist/types/prompt/inkPrompt.d.ts +64 -0
  82. package/dist/types/prompt/inkPrompt.d.ts.map +1 -0
  83. package/dist/types/prompt/mcpPrompt.d.ts +20 -0
  84. package/dist/types/prompt/mcpPrompt.d.ts.map +1 -0
  85. package/dist/types/prompt/types.d.ts +23 -0
  86. package/dist/types/prompt/types.d.ts.map +1 -0
  87. package/dist/types/run/index.d.ts +3 -0
  88. package/dist/types/run/index.d.ts.map +1 -0
  89. package/dist/types/run/runGeneratorTask.d.ts +51 -0
  90. package/dist/types/run/runGeneratorTask.d.ts.map +1 -0
  91. package/dist/types/stamp/createGeneratorStamp.d.ts +16 -0
  92. package/dist/types/stamp/createGeneratorStamp.d.ts.map +1 -0
  93. package/dist/types/stamp/createStampOnEffectStart.d.ts +17 -0
  94. package/dist/types/stamp/createStampOnEffectStart.d.ts.map +1 -0
  95. package/dist/types/stamp/index.d.ts +2 -0
  96. package/dist/types/stamp/index.d.ts.map +1 -1
  97. package/package.json +17 -10
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The non-interactive prompt strategy: flags/args + defaults, with a structured
3
+ * failure for a missing required answer.
4
+ *
5
+ * This is the evolved `answerPromptWithDefaults` the seam calls for `--yes`, a
6
+ * non-interactive terminal, or CI. Because {@link collectAnswers} only emits a
7
+ * `Prompt` effect for a prompt NOT already provided, this handler is reached
8
+ * only for unprovided answers: it returns the prompt's declared default, or —
9
+ * when a prompt has no default (a required, unprovided answer) — rejects with a
10
+ * structured `MISSING_REQUIRED_ANSWER` task error rather than silently
11
+ * substituting a bare `""` / first-choice value (the old exit-3 safety).
12
+ */
13
+ import { TaskExecutionError } from "@canonical/task";
14
+ /** The task-error code raised when a required answer is neither provided nor defaulted. */
15
+ export const MISSING_REQUIRED_ANSWER = "MISSING_REQUIRED_ANSWER";
16
+ /** Convert a camelCase answer key to its kebab-case CLI flag form. */
17
+ const toKebab = (name) => name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
18
+ /**
19
+ * Build the structured error for a required, unprovided answer.
20
+ *
21
+ * @param effect - The `Prompt` effect whose answer is missing.
22
+ * @param noun - How to name the missing input in the message ("flag" / "argument").
23
+ * @returns A {@link TaskExecutionError} the interpreter routes as a task failure.
24
+ */
25
+ export function missingRequiredError(effect, noun = "flag") {
26
+ const { name, message } = effect.question;
27
+ return new TaskExecutionError({
28
+ code: MISSING_REQUIRED_ANSWER,
29
+ message: `Missing required ${noun} --${toKebab(name)} (${message}). Provide it non-interactively, or run interactively to be prompted.`,
30
+ context: { answer: name },
31
+ });
32
+ }
33
+ /**
34
+ * A prompt handler that resolves each unprovided prompt to its default, or
35
+ * fails with {@link missingRequiredError} when no default exists.
36
+ *
37
+ * @param _params - The already-provided answers (accepted for symmetry with the
38
+ * other strategies; {@link collectAnswers} has already filtered these out, so
39
+ * this handler only ever sees unprovided prompts).
40
+ * @returns The non-interactive {@link PromptHandler}.
41
+ */
42
+ export default function autoPrompt(_params = {}) {
43
+ return (effect) => {
44
+ const q = effect.question;
45
+ if (q.default !== undefined)
46
+ return Promise.resolve(q.default);
47
+ return Promise.reject(missingRequiredError(effect, "flag"));
48
+ };
49
+ }
50
+ //# sourceMappingURL=autoPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoPrompt.js","sourceRoot":"","sources":["../../../src/prompt/autoPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,sEAAsE;AACtE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACvC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAoB,EACpB,OAA4B,MAAM;IAElC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC1C,OAAO,IAAI,kBAAkB,CAAC;QAC5B,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,oBAAoB,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,uEAAuE;QACvI,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KAC1B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,UAA6C,EAAE;IAE/C,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC1B,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The prompt-strategy barrel. STATIC exports only — no JSX, no static
3
+ * `import` of `ink`/`react`. The Ink strategy ({@link inkPrompt}) reaches its
4
+ * React UI ONLY through `await import("./ink/mount.js")` on first draw, so
5
+ * importing this barrel (or summon-core's root) never loads React. The
6
+ * lazy-React guard test enforces exactly this boundary.
7
+ */
8
+ export { default as answerPromptWithDefaults } from "./answerPromptWithDefaults.js";
9
+ export { default as autoPrompt, MISSING_REQUIRED_ANSWER, missingRequiredError, } from "./autoPrompt.js";
10
+ export { default as inkPrompt } from "./inkPrompt.js";
11
+ export { default as mcpPrompt } from "./mcpPrompt.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EACL,OAAO,IAAI,UAAU,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A minimal braille loading spinner. Under `prompt/ink/**` — dynamic-only.
4
+ */
5
+ import { Box, Text } from "ink";
6
+ import { useEffect, useState } from "react";
7
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
8
+ export const Spinner = ({ color = "cyan", label }) => {
9
+ const [frameIndex, setFrameIndex] = useState(0);
10
+ useEffect(() => {
11
+ const timer = setInterval(() => {
12
+ setFrameIndex((prev) => (prev + 1) % frames.length);
13
+ }, 80);
14
+ return () => clearInterval(timer);
15
+ }, []);
16
+ return (_jsxs(Box, { children: [_jsx(Text, { color: color, children: frames[frameIndex] }), label && _jsxs(Text, { children: [" ", label] })] }));
17
+ };
18
+ //# sourceMappingURL=Spinner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spinner.js","sourceRoot":"","sources":["../../../../src/prompt/ink/Spinner.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AASlE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAgB,EAAE,EAAE;IACjE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,aAAa,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,MAAC,GAAG,eACF,KAAC,IAAI,IAAC,KAAK,EAAE,KAAK,YAAG,MAAM,CAAC,UAAU,CAAC,GAAQ,EAC9C,KAAK,IAAI,MAAC,IAAI,oBAAG,KAAK,IAAQ,IAC3B,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The root Ink view — a pure projection of {@link SessionController} state.
4
+ * Under `prompt/ink/**` — dynamic-only. Ported from the summon wizard's App,
5
+ * but it OWNS no execution: the seam runs the task; this view only renders the
6
+ * prompt sequence, the preview/confirm gate, live progress, and the outcome.
7
+ */
8
+ import { describeEffect } from "@canonical/task";
9
+ import { Box, Text, useInput } from "ink";
10
+ import { useEffect, useState } from "react";
11
+ import { AnswersTable, ProgressHeader, QuestionView } from "./prompts.js";
12
+ import { Spinner } from "./Spinner.js";
13
+ /** A compact summary of the effects the confirm gate is about to apply. */
14
+ const EffectsSummary = ({ effects }) => {
15
+ const files = new Set();
16
+ const dirs = new Set();
17
+ const links = new Set();
18
+ let commands = 0;
19
+ for (const effect of effects) {
20
+ switch (effect._tag) {
21
+ case "WriteFile":
22
+ case "AppendFile":
23
+ files.add(effect.path);
24
+ break;
25
+ case "MakeDir":
26
+ dirs.add(effect.path);
27
+ break;
28
+ case "Symlink":
29
+ links.add(effect.path);
30
+ break;
31
+ case "Exec":
32
+ commands++;
33
+ break;
34
+ }
35
+ }
36
+ const rows = [];
37
+ if (files.size > 0)
38
+ rows.push({
39
+ label: `File${files.size > 1 ? "s" : ""} to create`,
40
+ count: files.size,
41
+ });
42
+ if (dirs.size > 0)
43
+ rows.push({
44
+ label: `Director${dirs.size > 1 ? "ies" : "y"} to create`,
45
+ count: dirs.size,
46
+ });
47
+ if (links.size > 0)
48
+ rows.push({
49
+ label: `Symlink${links.size > 1 ? "s" : ""} to create`,
50
+ count: links.size,
51
+ });
52
+ if (commands > 0)
53
+ rows.push({
54
+ label: `Command${commands > 1 ? "s" : ""} to run`,
55
+ count: commands,
56
+ });
57
+ if (rows.length === 0) {
58
+ return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, children: "No operations planned." }) }));
59
+ }
60
+ const width = Math.max(...rows.map((r) => r.label.length));
61
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, dimColor: true, children: "Operations:" }), rows.map((row) => (_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [" ", row.label.padEnd(width), " "] }), _jsx(Text, { color: "green", children: row.count })] }, row.label)))] }));
62
+ };
63
+ /** Live progress: the file effects completed so far. */
64
+ const Progress = ({ state }) => {
65
+ const shown = state.progress.filter((t) => t.effect._tag !== "Log" &&
66
+ t.effect._tag !== "Exists" &&
67
+ t.effect._tag !== "ReadFile" &&
68
+ t.effect._tag !== "ReadContext" &&
69
+ t.effect._tag !== "WriteContext" &&
70
+ t.effect._tag !== "Prompt" &&
71
+ t.effect._tag !== "Parallel" &&
72
+ t.effect._tag !== "Race");
73
+ return (_jsxs(Box, { flexDirection: "column", children: [shown.map((t, i) => (
74
+ // biome-ignore lint/suspicious/noArrayIndexKey: append-only progress; a path may repeat
75
+ _jsxs(Text, { children: [_jsx(Text, { color: "green", children: "\u2713" }), " ", describeEffect(t.effect)] }, `${t.effect._tag}-${i}`))), state.phase === "executing" && (_jsx(Box, { children: _jsx(Spinner, { color: "blue", label: "Generating\u2026" }) }))] }));
76
+ };
77
+ /** The wizard view — subscribes to the controller and renders its phase. */
78
+ export const Wizard = ({ controller }) => {
79
+ const [state, setState] = useState(controller.getSnapshot());
80
+ useEffect(() => controller.subscribe(() => setState(controller.getSnapshot())), [controller]);
81
+ // Ctrl-C cancels from any phase (Ink is mounted with exitOnCtrlC:false, so the
82
+ // key reaches here). Cancelling rejects the pending prompt, failing the task.
83
+ useInput((input, key) => {
84
+ if (key.ctrl && input === "c")
85
+ controller.cancel();
86
+ });
87
+ useInput((input, key) => {
88
+ if (state.phase !== "confirming")
89
+ return;
90
+ if (key.return || input.toLowerCase() === "y")
91
+ controller.submitConfirm(true);
92
+ else if (input.toLowerCase() === "n" || key.escape)
93
+ controller.submitConfirm(false);
94
+ }, { isActive: state.phase === "confirming" });
95
+ const { generator } = state;
96
+ return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "magenta", children: generator.meta.name }), _jsxs(Text, { dimColor: true, children: [" v", generator.meta.version] })] }), state.phase === "idle" && _jsx(Spinner, { label: "Loading\u2026" }), state.phase === "prompting" && state.activeQuestion && (_jsxs(Box, { flexDirection: "column", children: [_jsx(ProgressHeader, { current: state.step, total: state.total }), _jsx(AnswersTable, { prompts: generator.prompts, answers: state.answers }), _jsx(QuestionView, { question: state.activeQuestion.question, onSubmit: (value) => controller.submitAnswer(value), onCancel: () => controller.cancel() })] })), state.phase === "confirming" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(AnswersTable, { prompts: generator.prompts, answers: state.answers }), _jsx(EffectsSummary, { effects: state.previewEffects }), _jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: "Proceed? " }), _jsx(Text, { dimColor: true, children: "(Y/n)" })] })] })), (state.phase === "executing" || state.phase === "complete") && (_jsx(Progress, { state: state })), state.phase === "complete" && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "green", children: "\u2713 Generation complete!" }) })), state.phase === "cancelled" &&
97
+ (() => {
98
+ // Truthful (H2): a Ctrl-C mid-execution may have written some files
99
+ // before the abort landed, so count the completed write-like effects
100
+ // the session already tracked rather than always claiming none.
101
+ const written = state.progress.filter((t) => ["WriteFile", "AppendFile", "Symlink", "CopyFile"].includes(t.effect._tag)).length;
102
+ return (_jsxs(Text, { color: "yellow", children: ["\u2717 Cancelled.", " ", written === 0
103
+ ? "No files were written."
104
+ : `${written} file(s) were written.`] }));
105
+ })(), state.phase === "error" && (_jsxs(Text, { color: "red", children: ["\u2717 Error: ", state.error?.message] }))] }));
106
+ };
107
+ //# sourceMappingURL=Wizard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wizard.js","sourceRoot":"","sources":["../../../../src/prompt/ink/Wizard.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ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,IAAI,CAC9D,KAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,GAAI,CAC3B,EAEA,KAAK,CAAC,KAAK,KAAK,UAAU,IAAI,CAC7B,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,KAAC,IAAI,IAAC,KAAK,EAAC,OAAO,4CAA8B,GAC7C,CACP,EAEA,KAAK,CAAC,KAAK,KAAK,WAAW;gBAC1B,CAAC,GAAG,EAAE;oBACJ,oEAAoE;oBACpE,qEAAqE;oBACrE,gEAAgE;oBAChE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC1C,CAAC,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,QAAQ,CACzD,CAAC,CAAC,MAAM,CAAC,IAAI,CACd,CACF,CAAC,MAAM,CAAC;oBACT,OAAO,CACL,MAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,kCACL,GAAG,EACf,OAAO,KAAK,CAAC;gCACZ,CAAC,CAAC,wBAAwB;gCAC1B,CAAC,CAAC,GAAG,OAAO,wBAAwB,IACjC,CACR,CAAC;gBACJ,CAAC,CAAC,EAAE,EAEL,KAAK,CAAC,KAAK,KAAK,OAAO,IAAI,CAC1B,MAAC,IAAI,IAAC,KAAK,EAAC,KAAK,+BAAW,KAAK,CAAC,KAAK,EAAE,OAAO,IAAQ,CACzD,IACG,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from "ink";
3
+ import { SessionController } from "./session.js";
4
+ import { Wizard } from "./Wizard.js";
5
+ /**
6
+ * Mount the wizard for a generator and return its seam handle.
7
+ *
8
+ * @param generator - The generator being run.
9
+ * @param options - The abort signal.
10
+ * @returns The {@link MountedSession} the prompt handler and effect callbacks drive.
11
+ * @note Impure — renders an Ink app to stderr and reads stdin.
12
+ */
13
+ export function mountPromptSession(generator, options = {}) {
14
+ // Thread the run's cancel (H2): an in-Ink Ctrl-C/escape calls
15
+ // controller.cancel(), which invokes this to abort the interpreter.
16
+ const controller = new SessionController(generator, options.onCancel);
17
+ const instance = render(_jsx(Wizard, { controller: controller }), {
18
+ stdout: process.stderr,
19
+ stdin: process.stdin,
20
+ exitOnCtrlC: false,
21
+ });
22
+ const { signal } = options;
23
+ const onAbort = () => controller.cancel();
24
+ signal?.addEventListener("abort", onAbort);
25
+ let disposed = false;
26
+ return {
27
+ answerPrompt: (effect) => controller.request(effect),
28
+ reportEffectStart: (effect) => controller.reportEffectStart(effect),
29
+ reportEffectComplete: (effect, duration) => controller.reportEffectComplete(effect, duration),
30
+ reportLog: (level, message) => controller.reportLog(level, message),
31
+ dispose: () => {
32
+ if (disposed)
33
+ return;
34
+ disposed = true;
35
+ controller.markComplete();
36
+ signal?.removeEventListener("abort", onAbort);
37
+ instance.unmount();
38
+ },
39
+ };
40
+ }
41
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../../src/prompt/ink/mount.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAA8B,EAC9B,UAA4B,EAAE;IAE9B,8DAA8D;IAC9D,oEAAoE;IACpE,MAAM,UAAU,GAAG,IAAI,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAC,MAAM,IAAC,UAAU,EAAE,UAAU,GAAI,EAAE;QAC1D,MAAM,EAAE,OAAO,CAAC,MAAuC;QACvD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;IAEH,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;IAChD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE3C,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO;QACL,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;QACpD,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;QACnE,oBAAoB,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CACzC,UAAU,CAAC,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC;QACnD,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC;QACnE,OAAO,EAAE,GAAG,EAAE;YACZ,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,UAAU,CAAC,YAAY,EAAE,CAAC;YAC1B,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,144 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text, useInput } from "ink";
3
+ import SelectInput from "ink-select-input";
4
+ import TextInput from "ink-text-input";
5
+ import { useCallback, useEffect, useState } from "react";
6
+ /** Format an answer value for the completed-answers table. */
7
+ export const formatAnswerValue = (value, prompt) => {
8
+ if (value === undefined || value === null)
9
+ return "";
10
+ if (prompt.type === "confirm")
11
+ return value ? "Yes" : "No";
12
+ if (prompt.type === "select" && prompt.choices) {
13
+ const choice = prompt.choices.find((c) => c.value === value);
14
+ return choice?.label ?? String(value);
15
+ }
16
+ if (prompt.type === "multiselect" && Array.isArray(value)) {
17
+ if (value.length === 0)
18
+ return "None";
19
+ if (prompt.choices) {
20
+ return value
21
+ .map((v) => prompt.choices?.find((c) => c.value === v)?.label ?? v)
22
+ .join(", ");
23
+ }
24
+ return value.join(", ");
25
+ }
26
+ return String(value);
27
+ };
28
+ /** The completed-answers table (aligned, borderless). */
29
+ export const AnswersTable = ({ prompts, answers, }) => {
30
+ const active = prompts.filter((p) => {
31
+ if (p.when && p.when(answers) !== true)
32
+ return false;
33
+ return p.name in answers;
34
+ });
35
+ if (active.length === 0)
36
+ return null;
37
+ const width = Math.max(...active.map((p) => p.message.length));
38
+ return (_jsx(Box, { flexDirection: "column", marginBottom: 1, children: active.map((prompt) => (_jsxs(Box, { children: [_jsx(Text, { color: "green", children: "\u2714 " }), _jsx(Text, { dimColor: true, children: prompt.message.padEnd(width) }), _jsx(Text, { dimColor: true, children: " " }), _jsx(Text, { color: "cyan", children: formatAnswerValue(answers[prompt.name], prompt) })] }, prompt.name))) }));
39
+ };
40
+ /** The "Step N of M" progress header. */
41
+ export const ProgressHeader = ({ current, total, }) => (_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { dimColor: true, children: ["Step ", current, " of ", total] }) }));
42
+ const TextQuestion = ({ question, onSubmit, onCancel, }) => {
43
+ const [value, setValue] = useState(String(question.default ?? ""));
44
+ const [error, setError] = useState(null);
45
+ useEffect(() => {
46
+ setValue(String(question.default ?? ""));
47
+ setError(null);
48
+ }, [question.default]);
49
+ const handleSubmit = useCallback((val) => {
50
+ if (question.validate) {
51
+ const result = question.validate(val);
52
+ if (result !== true) {
53
+ setError(typeof result === "string" ? result : "Invalid input");
54
+ return;
55
+ }
56
+ }
57
+ onSubmit(val);
58
+ }, [question, onSubmit]);
59
+ useInput((_input, key) => {
60
+ if (key.escape)
61
+ onCancel();
62
+ });
63
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: question.message })] }), _jsx(Box, { marginLeft: 2, children: _jsx(TextInput, { value: value, onChange: setValue, onSubmit: handleSubmit }) }), error && (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "red", children: ["\u2718 ", error] }) }))] }));
64
+ };
65
+ const ConfirmQuestion = ({ question, onSubmit, onCancel, }) => {
66
+ const defaultValue = Boolean(question.default);
67
+ useInput((input, key) => {
68
+ if (input.toLowerCase() === "y")
69
+ onSubmit(true);
70
+ else if (input.toLowerCase() === "n")
71
+ onSubmit(false);
72
+ else if (key.return)
73
+ onSubmit(defaultValue);
74
+ else if (key.escape)
75
+ onCancel();
76
+ });
77
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsxs(Text, { bold: true, children: [question.message, " "] }), _jsxs(Text, { dimColor: true, children: ["(", defaultValue ? "Y/n" : "y/N", ")"] })] }));
78
+ };
79
+ const SelectQuestion = ({ question, onSubmit, onCancel, }) => {
80
+ const items = question.choices.map((c) => ({
81
+ label: c.label,
82
+ value: c.value,
83
+ }));
84
+ const initialIndex = question.default
85
+ ? items.findIndex((i) => i.value === question.default)
86
+ : 0;
87
+ useInput((_input, key) => {
88
+ if (key.escape)
89
+ onCancel();
90
+ });
91
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: question.message }), _jsx(Text, { dimColor: true, children: " (\u2191\u2193 to select, enter to confirm)" })] }), _jsx(Box, { marginLeft: 2, children: _jsx(SelectInput, { items: items, initialIndex: initialIndex >= 0 ? initialIndex : 0, onSelect: (item) => onSubmit(item.value) }) })] }));
92
+ };
93
+ const MultiselectQuestion = ({ question, onSubmit, onCancel, }) => {
94
+ const choices = question.choices;
95
+ const [selected, setSelected] = useState(new Set(question.default));
96
+ const [highlighted, setHighlighted] = useState(0);
97
+ useInput((input, key) => {
98
+ if (key.escape) {
99
+ onCancel();
100
+ return;
101
+ }
102
+ if (key.upArrow) {
103
+ setHighlighted((p) => (p > 0 ? p - 1 : choices.length - 1));
104
+ }
105
+ else if (key.downArrow) {
106
+ setHighlighted((p) => (p < choices.length - 1 ? p + 1 : 0));
107
+ }
108
+ else if (input === " ") {
109
+ const choice = choices[highlighted];
110
+ if (choice) {
111
+ setSelected((prev) => {
112
+ const next = new Set(prev);
113
+ if (next.has(choice.value))
114
+ next.delete(choice.value);
115
+ else
116
+ next.add(choice.value);
117
+ return next;
118
+ });
119
+ }
120
+ }
121
+ else if (key.return) {
122
+ onSubmit([...selected]);
123
+ }
124
+ });
125
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: question.message }), _jsx(Text, { dimColor: true, children: " (space to toggle, enter to confirm)" })] }), _jsx(Box, { marginLeft: 2, flexDirection: "column", children: choices.map((choice, i) => {
126
+ const isHi = i === highlighted;
127
+ const isSel = selected.has(choice.value);
128
+ return (_jsxs(Box, { children: [_jsx(Text, { color: isHi ? "magenta" : undefined, children: isHi ? "› " : " " }), _jsx(Text, { color: isSel ? "green" : "gray", children: isSel ? "◉ " : "○ " }), _jsx(Text, { color: isSel ? undefined : "gray", children: choice.label })] }, choice.value));
129
+ }) })] }));
130
+ };
131
+ /** Render the widget for a single {@link PromptQuestion}. */
132
+ export const QuestionView = ({ question, onSubmit, onCancel, }) => {
133
+ switch (question.type) {
134
+ case "text":
135
+ return (_jsx(TextQuestion, { question: question, onSubmit: onSubmit, onCancel: onCancel }));
136
+ case "confirm":
137
+ return (_jsx(ConfirmQuestion, { question: question, onSubmit: onSubmit, onCancel: onCancel }));
138
+ case "select":
139
+ return (_jsx(SelectQuestion, { question: question, onSubmit: onSubmit, onCancel: onCancel }));
140
+ case "multiselect":
141
+ return (_jsx(MultiselectQuestion, { question: question, onSubmit: onSubmit, onCancel: onCancel }));
142
+ }
143
+ };
144
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../../src/prompt/ink/prompts.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGzD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAc,EACd,MAAkD,EAC1C,EAAE;IACV,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAC7D,OAAO,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QACtC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,KAAK;iBACT,GAAG,CAAC,CAAC,CAAC,EAAE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sits between the seam (which drives the task and calls it per `Prompt`
5
+ * effect + per completed effect) and the React `<Wizard>` view (which
6
+ * subscribes to it). This split keeps the answer/preview/progress state machine
7
+ * out of React and lets the view be a pure projection of controller state.
8
+ *
9
+ * Lives under `prompt/ink/**`, so it is only ever reached through the dynamic
10
+ * `import("./mount.js")` boundary — it never lands in summon-core's static
11
+ * graph, even though it carries no JSX itself.
12
+ */
13
+ import { dryRun, TaskExecutionError, } from "@canonical/task";
14
+ import { CONFIRM_ANSWER_KEY, GENERATOR_CANCELLED, } from "../../execute/execute.js";
15
+ /** Count the prompts that apply given the answers so far (respecting `when`). */
16
+ function countApplicable(generator, answers) {
17
+ return generator.prompts.filter((p) => !p.when || p.when(answers) === true)
18
+ .length;
19
+ }
20
+ /**
21
+ * The controller: a tiny observable state machine driving the Ink wizard.
22
+ */
23
+ export class SessionController {
24
+ onUserCancel;
25
+ current;
26
+ listeners = new Set();
27
+ pending;
28
+ executionStart = 0;
29
+ /**
30
+ * @param generator - The generator being run.
31
+ * @param onUserCancel - Invoked once when the user cancels (Ctrl-C / escape).
32
+ * The seam wires this to the run's `AbortController.abort()`, so a Ctrl-C
33
+ * DURING execution actually interrupts the interpreter (its
34
+ * `checkInterrupted` fires between effects) instead of only rejecting a
35
+ * — by then non-existent — pending prompt. `abort()` is idempotent, so the
36
+ * signal→cancel→abort path cannot loop.
37
+ */
38
+ constructor(generator, onUserCancel) {
39
+ this.onUserCancel = onUserCancel;
40
+ this.current = {
41
+ phase: "idle",
42
+ generator,
43
+ answers: {},
44
+ step: 0,
45
+ total: countApplicable(generator, {}),
46
+ previewEffects: [],
47
+ progress: [],
48
+ };
49
+ }
50
+ /** Subscribe to state changes; returns an unsubscribe function. */
51
+ subscribe = (listener) => {
52
+ this.listeners.add(listener);
53
+ return () => {
54
+ this.listeners.delete(listener);
55
+ };
56
+ };
57
+ /** The current immutable snapshot (stable identity between changes). */
58
+ getSnapshot = () => this.current;
59
+ set(next) {
60
+ this.current = { ...this.current, ...next };
61
+ for (const listener of this.listeners)
62
+ listener();
63
+ }
64
+ // ---- seam → controller ---------------------------------------------------
65
+ /**
66
+ * A `Prompt` effect arrived from the running task. Returns a promise the
67
+ * view resolves once the user answers (or the run is cancelled).
68
+ */
69
+ request(effect) {
70
+ return new Promise((resolve, reject) => {
71
+ const isConfirm = effect.question.name === CONFIRM_ANSWER_KEY;
72
+ this.pending = { effect, isConfirm, resolve, reject };
73
+ if (isConfirm) {
74
+ let previewEffects = [];
75
+ try {
76
+ previewEffects = dryRun(this.current.generator.generate(this.current.answers)).effects;
77
+ }
78
+ catch {
79
+ previewEffects = [];
80
+ }
81
+ this.set({ phase: "confirming", previewEffects });
82
+ }
83
+ else {
84
+ const answered = Object.keys(this.current.answers).length;
85
+ this.set({
86
+ phase: "prompting",
87
+ activeQuestion: effect,
88
+ step: answered + 1,
89
+ total: countApplicable(this.current.generator, this.current.answers),
90
+ });
91
+ }
92
+ });
93
+ }
94
+ /** Feed effect start (kept for seam symmetry; progress rides completion). */
95
+ reportEffectStart(_effect) {
96
+ // No-op: the live view is driven by reportEffectComplete.
97
+ }
98
+ /** Record a completed effect for the live progress view. */
99
+ reportEffectComplete(effect, _duration) {
100
+ const timestamp = this.executionStart > 0 ? performance.now() - this.executionStart : 0;
101
+ this.set({
102
+ phase: this.current.phase === "cancelled" ? "cancelled" : "executing",
103
+ progress: [...this.current.progress, { effect, timestamp }],
104
+ });
105
+ }
106
+ /** A task log line (kept for parity; not surfaced by the default view). */
107
+ reportLog(_level, _message) { }
108
+ /** Mark the run complete (the view flashes a completion summary). */
109
+ markComplete() {
110
+ if (this.current.phase === "cancelled" || this.current.phase === "error")
111
+ return;
112
+ this.set({ phase: "complete" });
113
+ }
114
+ /** Mark the run failed. */
115
+ markError(error) {
116
+ this.set({ phase: "error", error });
117
+ }
118
+ // ---- view → controller ---------------------------------------------------
119
+ /** The user answered the active (non-confirm) prompt. */
120
+ submitAnswer(value) {
121
+ const pending = this.pending;
122
+ if (!pending || pending.isConfirm)
123
+ return;
124
+ this.pending = undefined;
125
+ this.current = {
126
+ ...this.current,
127
+ answers: {
128
+ ...this.current.answers,
129
+ [pending.effect.question.name]: value,
130
+ },
131
+ activeQuestion: undefined,
132
+ };
133
+ for (const listener of this.listeners)
134
+ listener();
135
+ pending.resolve(value);
136
+ }
137
+ /** The user answered the confirm gate. */
138
+ submitConfirm(proceed) {
139
+ const pending = this.pending;
140
+ if (!pending || !pending.isConfirm)
141
+ return;
142
+ this.pending = undefined;
143
+ if (proceed)
144
+ this.executionStart = performance.now();
145
+ this.set({ phase: proceed ? "executing" : "cancelled" });
146
+ pending.resolve(proceed);
147
+ }
148
+ /**
149
+ * The user cancelled (Ctrl-C / escape). Two things must happen, and both are
150
+ * safe to run whether or not a prompt is pending:
151
+ *
152
+ * 1. (H2) Abort the run via `onUserCancel` — a Ctrl-C mid-execution has no
153
+ * pending prompt to reject, so the abort is what actually stops the
154
+ * interpreter (its `checkInterrupted` throws `TASK_INTERRUPTED`).
155
+ * 2. (H1) Reject any pending prompt with a `TaskExecutionError` carrying
156
+ * `GENERATOR_CANCELLED` — NOT a bare `Error`. The interpreter only
157
+ * preserves a thrown error's `.code` for a `TaskExecutionError`; a bare
158
+ * Error flattens to `INTERNAL`, which the CLI boundary renders as a scary
159
+ * "please report this issue" (exit 1). Carrying the code routes an
160
+ * at-prompt cancel through the same clean "Cancelled." (exit 0) path as
161
+ * declining the confirm gate. The reject fails the current `Prompt` effect
162
+ * before the drive loop reaches its next `checkInterrupted`, so it wins
163
+ * deterministically over the concurrent abort.
164
+ */
165
+ cancel() {
166
+ const pending = this.pending;
167
+ this.pending = undefined;
168
+ this.onUserCancel?.();
169
+ this.set({ phase: "cancelled" });
170
+ pending?.reject(new TaskExecutionError({
171
+ code: GENERATOR_CANCELLED,
172
+ message: "Cancelled.",
173
+ }));
174
+ }
175
+ }
176
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../../src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