setup-agent 0.0.4 → 0.0.6
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.
- package/README.md +6 -4
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +44 -11
- package/dist/cli.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +8 -4
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/protocol.d.ts +21 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +30 -1
- package/dist/protocol.js.map +1 -1
- package/package.json +8 -8
- package/src/cli.test.ts +151 -0
- package/src/cli.ts +58 -9
- package/src/host.test.ts +153 -6
- package/src/host.ts +27 -7
- package/src/index.ts +3 -0
- package/src/protocol.test.ts +137 -0
- package/src/protocol.ts +93 -2
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport {\n StatewireReject,\n getStateHost,\n useStatewireCommands,\n useStatewireState,\n} from \"statewire/host\";\nimport {\n classifyChoiceAnswer,\n currentPlan,\n initialCheckoutState,\n isAgentPresent,\n isClosed,\n isValidModelAnswer,\n parsePreviewUrl,\n} from \"./protocol\";\nimport type { Checkout } from \"./protocol\";\n\nconst reject = (reason: Checkout.RejectionReason, message: string) =>\n new StatewireReject(message, { payload: { reason } });\n\nconst useCheckoutHost = (restored: unknown) => {\n const [state] = useStatewireState<Checkout.State>(() => {\n const initial = initialCheckoutState();\n if (restored === undefined) return initial;\n const snapshot = restored as Partial<Checkout.State>;\n if (snapshot.version !== 2) return initial;\n return {\n ...initial,\n ...snapshot,\n agent: { ...initial.agent, ...snapshot.agent },\n };\n });\n\n const requireOpen = () => {\n if (state.createdAt === null) {\n throw reject(\"not-created\", \"the setup has not been created yet\");\n }\n if (isClosed(state)) {\n throw reject(\"closed\", `the setup is ${state.status}`);\n }\n };\n\n const requireStarted = () => {\n requireOpen();\n if (state.status === \"waiting\") {\n throw reject(\n \"planning-not-started\",\n 'ask the user to return to their browser and click \"Begin plan\"; wait with \"wait start\"',\n );\n }\n };\n\n const requireInstalling = () => {\n requireOpen();\n if (state.status !== \"installing\") {\n throw reject(\n \"plan-required\",\n \"steps run once the user has approved a plan; submit one with plan\",\n );\n }\n };\n\n const findStep = (stepId: string) => {\n const step = state.steps.find((candidate) => candidate.id === stepId);\n if (!step) throw reject(\"unknown-step\", `no step \"${stepId}\"`);\n return step;\n };\n\n const findInput = (inputId: string) => {\n const input = state.inputs.find((candidate) => candidate.id === inputId);\n if (!input) throw reject(\"unknown-input\", `no input \"${inputId}\"`);\n if (input.status !== \"open\") {\n throw reject(\"input-closed\", `input \"${inputId}\" is ${input.status}`);\n }\n return input;\n };\n\n const touchAgent = () => {\n state.agent.lastSeenAt = Date.now();\n state.agent.connected = true;\n };\n\n const ask = (seed: Checkout.InputSeed & { stepId?: string }) => {\n const kind = seed.kind ?? \"text\";\n if (kind === \"product\") {\n if (!seed.product) {\n throw reject(\"invalid-input\", \"a product input names a product\");\n }\n if (state.products.some((product) => product.slug === seed.product)) {\n throw reject(\n \"invalid-input\",\n `\"${seed.product}\" is already part of this setup`,\n );\n }\n } else if (kind !== \"text\" && !seed.options?.length) {\n throw reject(\"invalid-input\", `a ${kind} input needs options`);\n }\n if (\n seed.multiple &&\n (kind !== \"choice\" ||\n seed.options?.some((option) => option.variants?.length))\n ) {\n throw reject(\n \"invalid-input\",\n \"only a choice whose options have no variants accepts several answers\",\n );\n }\n const unique = (ids: readonly string[]) => new Set(ids).size === ids.length;\n if (\n !unique(seed.options?.map((option) => option.id) ?? []) ||\n seed.options?.some(\n (option) =>\n !unique(option.variants?.map((variant) => variant.id) ?? []),\n )\n ) {\n throw reject(\"invalid-input\", \"option and variant ids must be unique\");\n }\n if (\n seed.options?.some(\n (option) =>\n option.id.includes(\":\") ||\n option.variants?.some((variant) => variant.id.includes(\":\")),\n )\n ) {\n throw reject(\n \"invalid-input\",\n 'option and variant ids cannot contain \":\", which separates them in an answer',\n );\n }\n if (\n seed.default !== undefined &&\n !seed.options?.some((option) => option.id === seed.default)\n ) {\n throw reject(\n \"invalid-input\",\n `no option \"${seed.default}\" to default to`,\n );\n }\n if (seed.stepId !== undefined) findStep(seed.stepId);\n const id = `q${state.inputs.length + 1}`;\n const stepId =\n seed.stepId ?? state.steps.find((step) => step.status === \"active\")?.id;\n state.inputs.push({\n id,\n phase: state.status,\n kind,\n ...(seed.preset !== undefined && { preset: seed.preset }),\n prompt: seed.prompt,\n ...(seed.placeholder !== undefined && { placeholder: seed.placeholder }),\n ...(seed.options !== undefined && { options: seed.options }),\n ...(seed.multiple && { multiple: true }),\n ...(kind === \"product\" && { product: seed.product }),\n ...(seed.default !== undefined && { default: seed.default }),\n ...(seed.help !== undefined && { help: seed.help }),\n optional: seed.optional ?? false,\n status: \"open\",\n ...(stepId !== undefined && { stepId }),\n createdAt: Date.now(),\n });\n return { inputId: id };\n };\n\n const dismissOpenInputs = () => {\n for (const input of state.inputs) {\n if (input.status === \"open\") {\n input.status = \"dismissed\";\n input.answeredAt = Date.now();\n }\n }\n };\n\n const log = (text: string, stepId?: string) => {\n state.log.push({\n id: `l${state.log.length + 1}`,\n role: \"agent\",\n phase: state.status,\n at: Date.now(),\n text,\n ...(stepId !== undefined && { stepId }),\n });\n };\n\n const updateStep = (\n step: Checkout.Step,\n status: Checkout.StepStatus,\n note?: string,\n ) => {\n const changed = step.status !== status;\n step.status = status;\n if (note !== undefined) step.note = note;\n if (changed && (status === \"done\" || status === \"skipped\")) {\n log(\n `${status === \"done\" ? \"Completed\" : \"Skipped\"}: ${step.title}${step.note ? `\\n\\n${step.note}` : \"\"}`,\n step.id,\n );\n }\n };\n\n const commands = useStatewireCommands<Checkout.Commands>({\n \"checkout/create\": ({ id, products, instructions }) => {\n if (state.id === id) {\n throw reject(\"already-created\", \"the setup already exists\");\n }\n const fresh = initialCheckoutState();\n if (!isAgentPresent(state)) state.agent = fresh.agent;\n state.id = id;\n state.status = fresh.status;\n delete state.completion;\n state.plans = fresh.plans;\n state.steps = fresh.steps;\n state.inputs = fresh.inputs;\n state.log = fresh.log;\n state.createdAt = Date.now();\n state.instructions = instructions?.trim() ?? \"\";\n state.products = products.map((product) => ({\n slug: product.slug,\n name: product.name,\n ...(product.guide !== undefined && { guide: product.guide }),\n }));\n },\n \"checkout/begin-plan\": () => {\n requireOpen();\n if (state.status === \"waiting\") state.status = \"planning\";\n },\n \"checkout/answer\": ({ inputId, answer, note }) => {\n requireOpen();\n const input = findInput(inputId);\n if (\n input.kind === \"choice\" &&\n classifyChoiceAnswer(input, answer) === \"invalid\"\n ) {\n throw reject(\n \"invalid-answer\",\n input.multiple\n ? `\"${answer}\" is not a JSON array of option ids`\n : `\"${answer}\" names an option without a valid variant`,\n );\n }\n if (input.kind === \"model\" && !isValidModelAnswer(input, answer)) {\n throw reject(\n \"invalid-answer\",\n \"a model answer is JSON with provider and model\",\n );\n }\n if (input.kind === \"product\") {\n throw reject(\n \"invalid-answer\",\n \"a product input is answered with checkout/add-product\",\n );\n }\n if (input.kind === \"text\" && answer.trim() === \"\") {\n throw reject(\"invalid-answer\", \"an answer cannot be empty\");\n }\n input.status = \"answered\";\n input.answeredAt = Date.now();\n input.answer = answer;\n if (note !== undefined && note.trim() !== \"\") input.note = note.trim();\n },\n \"checkout/add-product\": ({ inputId, product }) => {\n requireOpen();\n const input = findInput(inputId);\n if (input.kind !== \"product\" || input.product !== product.slug) {\n throw reject(\n \"invalid-answer\",\n `input \"${inputId}\" does not propose \"${product.slug}\"`,\n );\n }\n if (!state.products.some((entry) => entry.slug === product.slug)) {\n state.products.push({\n slug: product.slug,\n name: product.name,\n ...(product.guide !== undefined && { guide: product.guide }),\n });\n }\n input.status = \"answered\";\n input.answer = \"added\";\n input.answeredAt = Date.now();\n },\n \"checkout/message\": ({ text }) => {\n requireOpen();\n if (text.trim() === \"\")\n throw reject(\"empty-message\", \"a message cannot be empty\");\n const stepId = state.steps.find((step) => step.status === \"active\")?.id;\n state.log.push({\n id: `l${state.log.length + 1}`,\n role: \"user\",\n phase: state.status,\n ...(stepId !== undefined && { stepId }),\n at: Date.now(),\n text: text.trim(),\n });\n },\n \"agent/ack\": ({ messageId }) => {\n requireOpen();\n const message = state.log.find(\n (entry) => entry.id === messageId && entry.role === \"user\",\n );\n if (!message)\n throw reject(\"unknown-message\", `no user message \"${messageId}\"`);\n message.acknowledgedAt ??= Date.now();\n },\n \"checkout/dismiss\": ({ inputId }) => {\n requireOpen();\n const input = findInput(inputId);\n input.status = \"dismissed\";\n input.answeredAt = Date.now();\n },\n \"checkout/plan\": (params) => {\n requireOpen();\n const plan = currentPlan(state);\n if (plan === undefined) {\n throw reject(\"no-plan\", \"the agent has not proposed a plan yet\");\n }\n if (plan.status !== \"proposed\") {\n throw reject(\"plan-decided\", `the plan is already ${plan.status}`);\n }\n if (params.decision === \"approve\") {\n plan.status = \"approved\";\n plan.decidedAt = Date.now();\n state.status = \"installing\";\n return;\n }\n if (params.feedback.trim() === \"\") {\n throw reject(\"feedback-required\", \"say what should change\");\n }\n plan.status = \"changes-requested\";\n plan.decidedAt = Date.now();\n plan.feedback = params.feedback.trim();\n },\n \"checkout/cancel\": () => {\n if (state.createdAt === null || isClosed(state)) return;\n state.status = \"cancelled\";\n dismissOpenInputs();\n },\n \"checkout/finish\": () => {\n requireOpen();\n if (state.completion === undefined) {\n throw reject(\n \"finish-not-proposed\",\n \"the agent has not proposed to finish yet\",\n );\n }\n dismissOpenInputs();\n state.status = \"done\";\n log(\"Setup complete.\");\n },\n \"agent/intro\": ({ kind } = {}) => {\n requireOpen();\n if (state.agent.introducedAt === null) {\n state.agent.introducedAt = Date.now();\n }\n if (kind !== undefined) state.agent.kind = kind;\n },\n \"agent/hello\": ({ cwd, kind } = {}) => {\n touchAgent();\n if (cwd !== undefined) state.agent.cwd = cwd;\n if (kind !== undefined) state.agent.kind = kind;\n },\n \"agent/heartbeat\": () => {\n touchAgent();\n },\n \"agent/bye\": () => {\n state.agent.connected = false;\n },\n \"agent/plan\": ({ markdown }) => {\n requireStarted();\n touchAgent();\n if (markdown.trim() === \"\") {\n throw reject(\"empty-plan\", \"the plan is empty\");\n }\n if (state.status === \"installing\") {\n throw reject(\"plan-decided\", \"the plan is already approved\");\n }\n const revision = state.plans.length + 1;\n state.plans.push({\n revision,\n markdown: markdown.trim(),\n status: \"proposed\",\n submittedAt: Date.now(),\n });\n return { revision };\n },\n \"agent/add-step\": ({ title, detail, product, active }) => {\n requireInstalling();\n if (\n product !== undefined &&\n !state.products.some((candidate) => candidate.slug === product)\n ) {\n throw reject(\"unknown-product\", `no product \"${product}\"`);\n }\n const id = `s${state.steps.length + 1}`;\n state.steps.push({\n id,\n title,\n ...(detail !== undefined && { detail }),\n status: active ? \"active\" : \"pending\",\n ...(product !== undefined && { product }),\n createdAt: Date.now(),\n });\n return { stepId: id };\n },\n \"agent/step\": ({ stepId, status, note }) => {\n requireInstalling();\n const step = findStep(stepId);\n updateStep(step, status, note);\n },\n \"agent/ask\": (seed) => {\n requireStarted();\n touchAgent();\n return ask(seed);\n },\n \"agent/log\": ({ text }) => {\n requireOpen();\n touchAgent();\n const stepId = state.steps.find((step) => step.status === \"active\")?.id;\n log(text, stepId);\n },\n \"agent/done\": ({ summary, preview } = {}) => {\n requireInstalling();\n const previewUrl = parsePreviewUrl(preview?.trim());\n if (preview !== undefined && !previewUrl) {\n throw reject(\n \"invalid-preview\",\n \"a preview is an http URL on localhost, such as http://localhost:3000\",\n );\n }\n touchAgent();\n for (const step of state.steps) {\n if (step.status === \"pending\" || step.status === \"active\") {\n updateStep(step, \"done\");\n }\n }\n log(summary?.trim() || \"Everything is installed.\");\n state.completion = {\n proposedAt: Date.now(),\n ...(previewUrl && { preview: previewUrl.href }),\n };\n },\n });\n\n const source = getStateHost(state)!;\n return {\n state,\n commands,\n snapshot: source.snapshot,\n subscribe: (listener: () => void) => {\n source.setOnChange(listener);\n return () => source.setOnChange(null);\n },\n };\n};\n\n/** The setup statewire host; pass the durable object's restored snapshot. */\nexport const CheckoutHost = (restored?: unknown) =>\n resource(useCheckoutHost)(restored);\n\nexport type { Checkout } from \"./protocol\";\n"],"mappings":";;;;AAkBA,MAAM,UAAU,QAAkC,YAChD,IAAI,gBAAgB,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAEtD,MAAM,mBAAmB,aAAsB;CAC7C,MAAM,CAAC,SAAS,wBAAwC;EACtD,MAAM,UAAU,qBAAqB;EACrC,IAAI,aAAa,KAAA,GAAW,OAAO;EACnC,MAAM,WAAW;EACjB,IAAI,SAAS,YAAY,GAAG,OAAO;EACnC,OAAO;GACL,GAAG;GACH,GAAG;GACH,OAAO;IAAE,GAAG,QAAQ;IAAO,GAAG,SAAS;GAAM;EAC/C;CACF,CAAC;CAED,MAAM,oBAAoB;EACxB,IAAI,MAAM,cAAc,MACtB,MAAM,OAAO,eAAe,oCAAoC;EAElE,IAAI,SAAS,KAAK,GAChB,MAAM,OAAO,UAAU,gBAAgB,MAAM,QAAQ;CAEzD;CAEA,MAAM,uBAAuB;EAC3B,YAAY;EACZ,IAAI,MAAM,WAAW,WACnB,MAAM,OACJ,wBACA,4FACF;CAEJ;CAEA,MAAM,0BAA0B;EAC9B,YAAY;EACZ,IAAI,MAAM,WAAW,cACnB,MAAM,OACJ,iBACA,mEACF;CAEJ;CAEA,MAAM,YAAY,WAAmB;EACnC,MAAM,OAAO,MAAM,MAAM,MAAM,cAAc,UAAU,OAAO,MAAM;EACpE,IAAI,CAAC,MAAM,MAAM,OAAO,gBAAgB,YAAY,OAAO,EAAE;EAC7D,OAAO;CACT;CAEA,MAAM,aAAa,YAAoB;EACrC,MAAM,QAAQ,MAAM,OAAO,MAAM,cAAc,UAAU,OAAO,OAAO;EACvE,IAAI,CAAC,OAAO,MAAM,OAAO,iBA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B;GAClB,MAAM,aAAa,gBAAgB,SAAS,KAAK,CAAC;GAClD,IAAI,YAAY,KAAA,KAAa,CAAC,YAC5B,MAAM,OACJ,mBACA,sEACF;GAEF,WAAW;GACX,KAAK,MAAM,QAAQ,MAAM,OACvB,IAAI,KAAK,WAAW,aAAa,KAAK,WAAW,UAC/C,WAAW,MAAM,MAAM;GAG3B,IAAI,SAAS,KAAK,KAAK,0BAA0B;GACjD,MAAM,aAAa;IACjB,YAAY,KAAK,IAAI;IACrB,GAAI,cAAc,EAAE,SAAS,WAAW,KAAK;GAC/C;EACF;CACF,CAAC;CAED,MAAM,SAAS,aAAa,KAAK;CACjC,OAAO;EACL;EACA;EACA,UAAU,OAAO;EACjB,YAAY,aAAyB;GACnC,OAAO,YAAY,QAAQ;GAC3B,aAAa,OAAO,YAAY,IAAI;EACtC;CACF;AACF;;AAGA,MAAa,gBAAgB,aAC3B,SAAS,eAAe,CAAC,CAAC,QAAQ"}
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport {\n StatewireReject,\n getStateHost,\n useStatewireCommands,\n useStatewireState,\n} from \"statewire/host\";\nimport {\n classifyChoiceAnswer,\n currentPlan,\n initialCheckoutState,\n isAgentPresent,\n isClosed,\n isValidModelAnswer,\n isValidEntryPointAnswer,\n isValidEntryPointInput,\n parseEntryPointOptions,\n parsePreviewUrl,\n} from \"./protocol\";\nimport type { Checkout } from \"./protocol\";\n\nconst reject = (reason: Checkout.RejectionReason, message: string) =>\n new StatewireReject(message, { payload: { reason } });\n\nconst useCheckoutHost = (restored: unknown) => {\n const [state] = useStatewireState<Checkout.State>(() => {\n const initial = initialCheckoutState();\n if (restored === undefined) return initial;\n const snapshot = restored as Partial<Checkout.State>;\n if (snapshot.version !== 2) return initial;\n return {\n ...initial,\n ...snapshot,\n agent: { ...initial.agent, ...snapshot.agent },\n };\n });\n\n const requireOpen = () => {\n if (state.createdAt === null) {\n throw reject(\"not-created\", \"the setup has not been created yet\");\n }\n if (isClosed(state)) {\n throw reject(\"closed\", `the setup is ${state.status}`);\n }\n };\n\n const requireStarted = () => {\n requireOpen();\n if (state.status === \"waiting\") {\n throw reject(\n \"planning-not-started\",\n 'ask the user to return to their browser and click \"Begin plan\"; wait with \"wait start\"',\n );\n }\n };\n\n const requireInstalling = () => {\n requireOpen();\n if (state.status !== \"installing\") {\n throw reject(\n \"plan-required\",\n \"steps run once the user has approved a plan; submit one with plan\",\n );\n }\n };\n\n const findStep = (stepId: string) => {\n const step = state.steps.find((candidate) => candidate.id === stepId);\n if (!step) throw reject(\"unknown-step\", `no step \"${stepId}\"`);\n return step;\n };\n\n const findInput = (inputId: string) => {\n const input = state.inputs.find((candidate) => candidate.id === inputId);\n if (!input) throw reject(\"unknown-input\", `no input \"${inputId}\"`);\n if (input.status !== \"open\") {\n throw reject(\"input-closed\", `input \"${inputId}\" is ${input.status}`);\n }\n return input;\n };\n\n const touchAgent = () => {\n state.agent.lastSeenAt = Date.now();\n state.agent.connected = true;\n };\n\n const ask = (seed: Checkout.InputSeed & { stepId?: string }) => {\n const kind = seed.kind ?? \"text\";\n const options =\n kind === \"entry-point\"\n ? parseEntryPointOptions(seed.options)\n : seed.options;\n if (kind === \"entry-point\" && !isValidEntryPointInput(seed)) {\n throw reject(\n \"invalid-input\",\n \"an entry-point input needs a prompt and 1–3 distinct options with descriptions, form factors, placements and triggers; at most one is recommended\",\n );\n }\n if (kind === \"product\") {\n if (!seed.product) {\n throw reject(\"invalid-input\", \"a product input names a product\");\n }\n if (state.products.some((product) => product.slug === seed.product)) {\n throw reject(\n \"invalid-input\",\n `\"${seed.product}\" is already part of this setup`,\n );\n }\n } else if (kind !== \"text\" && !seed.options?.length) {\n throw reject(\"invalid-input\", `a ${kind} input needs options`);\n }\n if (\n seed.multiple &&\n (kind !== \"choice\" ||\n seed.options?.some((option) => option.variants?.length))\n ) {\n throw reject(\n \"invalid-input\",\n \"only a choice whose options have no variants accepts several answers\",\n );\n }\n const unique = (ids: readonly string[]) => new Set(ids).size === ids.length;\n if (\n !unique(seed.options?.map((option) => option.id) ?? []) ||\n seed.options?.some(\n (option) =>\n !unique(option.variants?.map((variant) => variant.id) ?? []),\n )\n ) {\n throw reject(\"invalid-input\", \"option and variant ids must be unique\");\n }\n if (\n seed.options?.some(\n (option) =>\n option.id.includes(\":\") ||\n option.variants?.some((variant) => variant.id.includes(\":\")),\n )\n ) {\n throw reject(\n \"invalid-input\",\n 'option and variant ids cannot contain \":\", which separates them in an answer',\n );\n }\n if (\n seed.default !== undefined &&\n !seed.options?.some((option) => option.id === seed.default)\n ) {\n throw reject(\n \"invalid-input\",\n `no option \"${seed.default}\" to default to`,\n );\n }\n if (seed.stepId !== undefined) findStep(seed.stepId);\n const id = `q${state.inputs.length + 1}`;\n const stepId =\n seed.stepId ?? state.steps.find((step) => step.status === \"active\")?.id;\n state.inputs.push({\n id,\n phase: state.status,\n kind,\n ...(seed.preset !== undefined && { preset: seed.preset }),\n prompt: seed.prompt,\n ...(seed.placeholder !== undefined && { placeholder: seed.placeholder }),\n ...(options !== undefined && { options }),\n ...(seed.multiple && { multiple: true }),\n ...(kind === \"product\" && { product: seed.product }),\n ...(seed.default !== undefined && { default: seed.default }),\n ...(seed.help !== undefined && { help: seed.help }),\n optional: seed.optional ?? false,\n status: \"open\",\n ...(stepId !== undefined && { stepId }),\n createdAt: Date.now(),\n });\n return { inputId: id };\n };\n\n const dismissOpenInputs = () => {\n for (const input of state.inputs) {\n if (input.status === \"open\") {\n input.status = \"dismissed\";\n input.answeredAt = Date.now();\n }\n }\n };\n\n const log = (text: string, stepId?: string) => {\n state.log.push({\n id: `l${state.log.length + 1}`,\n role: \"agent\",\n phase: state.status,\n at: Date.now(),\n text,\n ...(stepId !== undefined && { stepId }),\n });\n };\n\n const updateStep = (\n step: Checkout.Step,\n status: Checkout.StepStatus,\n note?: string,\n ) => {\n const changed = step.status !== status;\n step.status = status;\n if (note !== undefined) step.note = note;\n if (changed && (status === \"done\" || status === \"skipped\")) {\n log(\n `${status === \"done\" ? \"Completed\" : \"Skipped\"}: ${step.title}${step.note ? `\\n\\n${step.note}` : \"\"}`,\n step.id,\n );\n }\n };\n\n const commands = useStatewireCommands<Checkout.Commands>({\n \"checkout/create\": ({ id, products, instructions }) => {\n if (state.id === id) {\n throw reject(\"already-created\", \"the setup already exists\");\n }\n const fresh = initialCheckoutState();\n if (!isAgentPresent(state)) state.agent = fresh.agent;\n state.id = id;\n state.status = fresh.status;\n delete state.completion;\n state.plans = fresh.plans;\n state.steps = fresh.steps;\n state.inputs = fresh.inputs;\n state.log = fresh.log;\n state.createdAt = Date.now();\n state.instructions = instructions?.trim() ?? \"\";\n state.products = products.map((product) => ({\n slug: product.slug,\n name: product.name,\n ...(product.guide !== undefined && { guide: product.guide }),\n }));\n },\n \"checkout/begin-plan\": () => {\n requireOpen();\n if (state.status === \"waiting\") state.status = \"planning\";\n },\n \"checkout/answer\": ({ inputId, answer, note }) => {\n requireOpen();\n const input = findInput(inputId);\n if (\n input.kind === \"choice\" &&\n classifyChoiceAnswer(input, answer) === \"invalid\"\n ) {\n throw reject(\n \"invalid-answer\",\n input.multiple\n ? `\"${answer}\" is not a JSON array of option ids`\n : `\"${answer}\" names an option without a valid variant`,\n );\n }\n if (\n input.kind === \"entry-point\" &&\n !isValidEntryPointAnswer(input, answer)\n ) {\n throw reject(\"invalid-answer\", \"an entry-point answer is an option id\");\n }\n if (input.kind === \"model\" && !isValidModelAnswer(input, answer)) {\n throw reject(\n \"invalid-answer\",\n \"a model answer is JSON with provider and model\",\n );\n }\n if (input.kind === \"product\") {\n throw reject(\n \"invalid-answer\",\n \"a product input is answered with checkout/add-product\",\n );\n }\n if (input.kind === \"text\" && answer.trim() === \"\") {\n throw reject(\"invalid-answer\", \"an answer cannot be empty\");\n }\n input.status = \"answered\";\n input.answeredAt = Date.now();\n input.answer = answer;\n if (note !== undefined && note.trim() !== \"\") input.note = note.trim();\n },\n \"checkout/add-product\": ({ inputId, product }) => {\n requireOpen();\n const input = findInput(inputId);\n if (input.kind !== \"product\" || input.product !== product.slug) {\n throw reject(\n \"invalid-answer\",\n `input \"${inputId}\" does not propose \"${product.slug}\"`,\n );\n }\n if (!state.products.some((entry) => entry.slug === product.slug)) {\n state.products.push({\n slug: product.slug,\n name: product.name,\n ...(product.guide !== undefined && { guide: product.guide }),\n });\n }\n input.status = \"answered\";\n input.answer = \"added\";\n input.answeredAt = Date.now();\n },\n \"checkout/message\": ({ text }) => {\n requireOpen();\n if (text.trim() === \"\")\n throw reject(\"empty-message\", \"a message cannot be empty\");\n const stepId = state.steps.find((step) => step.status === \"active\")?.id;\n state.log.push({\n id: `l${state.log.length + 1}`,\n role: \"user\",\n phase: state.status,\n ...(stepId !== undefined && { stepId }),\n at: Date.now(),\n text: text.trim(),\n });\n },\n \"agent/ack\": ({ messageId }) => {\n requireOpen();\n const message = state.log.find(\n (entry) => entry.id === messageId && entry.role === \"user\",\n );\n if (!message)\n throw reject(\"unknown-message\", `no user message \"${messageId}\"`);\n message.acknowledgedAt ??= Date.now();\n },\n \"checkout/dismiss\": ({ inputId }) => {\n requireOpen();\n const input = findInput(inputId);\n input.status = \"dismissed\";\n input.answeredAt = Date.now();\n },\n \"checkout/plan\": (params) => {\n requireOpen();\n const plan = currentPlan(state);\n if (plan === undefined) {\n throw reject(\"no-plan\", \"the agent has not proposed a plan yet\");\n }\n if (plan.status !== \"proposed\") {\n throw reject(\"plan-decided\", `the plan is already ${plan.status}`);\n }\n if (params.decision === \"approve\") {\n plan.status = \"approved\";\n plan.decidedAt = Date.now();\n state.status = \"installing\";\n return;\n }\n if (params.feedback.trim() === \"\") {\n throw reject(\"feedback-required\", \"say what should change\");\n }\n plan.status = \"changes-requested\";\n plan.decidedAt = Date.now();\n plan.feedback = params.feedback.trim();\n },\n \"checkout/cancel\": ({ id } = {}) => {\n if (state.createdAt === null || isClosed(state)) return;\n if (id !== undefined && id !== state.id) return;\n state.status = \"cancelled\";\n dismissOpenInputs();\n },\n \"checkout/finish\": () => {\n requireOpen();\n if (state.completion === undefined) {\n throw reject(\n \"finish-not-proposed\",\n \"the agent has not proposed to finish yet\",\n );\n }\n dismissOpenInputs();\n state.status = \"done\";\n log(\"Setup complete.\");\n },\n \"agent/intro\": ({ kind } = {}) => {\n requireOpen();\n if (state.agent.introducedAt === null) {\n state.agent.introducedAt = Date.now();\n }\n if (kind !== undefined) state.agent.kind = kind;\n },\n \"agent/hello\": ({ cwd, kind } = {}) => {\n touchAgent();\n if (cwd !== undefined) state.agent.cwd = cwd;\n if (kind !== undefined) state.agent.kind = kind;\n },\n \"agent/heartbeat\": () => {\n touchAgent();\n },\n \"agent/bye\": () => {\n state.agent.connected = false;\n },\n \"agent/plan\": ({ markdown }) => {\n requireStarted();\n touchAgent();\n if (markdown.trim() === \"\") {\n throw reject(\"empty-plan\", \"the plan is empty\");\n }\n if (state.status === \"installing\") {\n throw reject(\"plan-decided\", \"the plan is already approved\");\n }\n const revision = state.plans.length + 1;\n state.plans.push({\n revision,\n markdown: markdown.trim(),\n status: \"proposed\",\n submittedAt: Date.now(),\n });\n return { revision };\n },\n \"agent/add-step\": ({ title, detail, product, active }) => {\n requireInstalling();\n if (product !== undefined && product.trim() === \"\") {\n throw reject(\n \"invalid-input\",\n \"a step's product identifier cannot be empty\",\n );\n }\n const id = `s${state.steps.length + 1}`;\n state.steps.push({\n id,\n title,\n ...(detail !== undefined && { detail }),\n status: active ? \"active\" : \"pending\",\n ...(product !== undefined && { product }),\n createdAt: Date.now(),\n });\n return { stepId: id };\n },\n \"agent/step\": ({ stepId, status, note }) => {\n requireInstalling();\n const step = findStep(stepId);\n updateStep(step, status, note);\n },\n \"agent/ask\": (seed) => {\n requireStarted();\n touchAgent();\n return ask(seed);\n },\n \"agent/log\": ({ text }) => {\n requireOpen();\n touchAgent();\n const stepId = state.steps.find((step) => step.status === \"active\")?.id;\n log(text, stepId);\n },\n \"agent/done\": ({ summary, preview } = {}) => {\n requireInstalling();\n const previewUrl = parsePreviewUrl(preview?.trim());\n if (preview !== undefined && !previewUrl) {\n throw reject(\n \"invalid-preview\",\n \"a preview is an http URL on localhost, such as http://localhost:3000\",\n );\n }\n touchAgent();\n for (const step of state.steps) {\n if (step.status === \"pending\" || step.status === \"active\") {\n updateStep(step, \"done\");\n }\n }\n log(summary?.trim() || \"Everything is installed.\");\n state.completion = {\n proposedAt: Date.now(),\n ...(previewUrl && { preview: previewUrl.href }),\n };\n },\n });\n\n const source = getStateHost(state)!;\n return {\n state,\n commands,\n snapshot: source.snapshot,\n subscribe: (listener: () => void) => {\n source.setOnChange(listener);\n return () => source.setOnChange(null);\n },\n };\n};\n\n/** The setup statewire host; pass the durable object's restored snapshot. */\nexport const CheckoutHost = (restored?: unknown) =>\n resource(useCheckoutHost)(restored);\n\nexport type { Checkout } from \"./protocol\";\n"],"mappings":";;;;AAqBA,MAAM,UAAU,QAAkC,YAChD,IAAI,gBAAgB,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAEtD,MAAM,mBAAmB,aAAsB;CAC7C,MAAM,CAAC,SAAS,wBAAwC;EACtD,MAAM,UAAU,qBAAqB;EACrC,IAAI,aAAa,KAAA,GAAW,OAAO;EACnC,MAAM,WAAW;EACjB,IAAI,SAAS,YAAY,GAAG,OAAO;EACnC,OAAO;GACL,GAAG;GACH,GAAG;GACH,OAAO;IAAE,GAAG,QAAQ;IAAO,GAAG,SAAS;GAAM;EAC/C;CACF,CAAC;CAED,MAAM,oBAAoB;EACxB,IAAI,MAAM,cAAc,MACtB,MAAM,OAAO,eAAe,oCAAoC;EAElE,IAAI,SAAS,KAAK,GAChB,MAAM,OAAO,UAAU,gBAAgB,MAAM,QAAQ;CAEzD;CAEA,MAAM,uBAAuB;EAC3B,YAAY;EACZ,IAAI,MAAM,WAAW,WACnB,MAAM,OACJ,wBACA,4FACF;CAEJ;CAEA,MAAM,0BAA0B;EAC9B,YAAY;EACZ,IAAI,MAAM,WAAW,cACnB,MAAM,OAC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js";
|
|
2
|
-
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, initialCheckoutState, finishProposed, followedUpSinceProposal, isAgentPresent, isClosed, isOptionIcon, isValidModelAnswer, openInputs, parseChoiceAnswer, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress, } from "./protocol.js";
|
|
2
|
+
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, initialCheckoutState, finishProposed, followedUpSinceProposal, isAgentPresent, isClosed, isOptionIcon, isValidModelAnswer, isValidEntryPointAnswer, isValidEntryPointInput, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress, } from "./protocol.js";
|
|
3
3
|
export { INPUT_PRESETS, isPresetId, presetInput } from "./presets.js";
|
|
4
4
|
export type { PresetId, PresetOverrides } from "./presets.js";
|
|
5
5
|
export { connectCheckout } from "./client.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,sBAAmB;AACvD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,YAAY,GACb,sBAAmB;AACpB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,qBAAkB;AACnE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,qBAAkB;AAC3D,OAAO,EAAE,eAAe,EAAE,oBAAiB;AAC3C,YAAY,EAAE,cAAc,EAAE,oBAAiB"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,sBAAmB;AACvD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,YAAY,GACb,sBAAmB;AACpB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,qBAAkB;AACnE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,qBAAkB;AAC3D,OAAO,EAAE,eAAe,EAAE,oBAAiB;AAC3C,YAAY,EAAE,cAAc,EAAE,oBAAiB"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { connectCheckout } from "./client.js";
|
|
2
2
|
import { INPUT_PRESETS, isPresetId, presetInput } from "./presets.js";
|
|
3
|
-
import { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isValidModelAnswer, openInputs, parseChoiceAnswer, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress } from "./protocol.js";
|
|
4
|
-
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, INPUT_PRESETS, OPTION_ICONS, classifyChoiceAnswer, connectCheckout, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isPresetId, isValidModelAnswer, openInputs, parseChoiceAnswer, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, presetInput, stepProgress };
|
|
3
|
+
import { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isValidEntryPointAnswer, isValidEntryPointInput, isValidModelAnswer, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress } from "./protocol.js";
|
|
4
|
+
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, INPUT_PRESETS, OPTION_ICONS, classifyChoiceAnswer, connectCheckout, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isPresetId, isValidEntryPointAnswer, isValidEntryPointInput, isValidModelAnswer, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, presetInput, stepProgress };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -23,7 +23,19 @@ export declare namespace Checkout {
|
|
|
23
23
|
* another product depends on. The browser owns the catalog, so it answers
|
|
24
24
|
* with `checkout/add-product`; dismissing the input declines.
|
|
25
25
|
*/
|
|
26
|
-
type InputKind = "text" | "choice" | "model" | "product";
|
|
26
|
+
type InputKind = "text" | "choice" | "model" | "product" | "entry-point";
|
|
27
|
+
type EntryPoint = {
|
|
28
|
+
formFactor: "modal" | "sidebar" | "full-page";
|
|
29
|
+
placement: string;
|
|
30
|
+
trigger: string;
|
|
31
|
+
recommended?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type EntryPointOption = {
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
description: string;
|
|
37
|
+
entryPoint: EntryPoint;
|
|
38
|
+
};
|
|
27
39
|
type ChoiceVariant = {
|
|
28
40
|
id: string;
|
|
29
41
|
label: string;
|
|
@@ -36,6 +48,7 @@ export declare namespace Checkout {
|
|
|
36
48
|
icon?: string;
|
|
37
49
|
/** A second pick under this option, such as the language of a framework. */
|
|
38
50
|
variants?: ChoiceVariant[];
|
|
51
|
+
entryPoint?: EntryPoint;
|
|
39
52
|
};
|
|
40
53
|
/** A short nudge for users who need help choosing, with a longer guide to link to. */
|
|
41
54
|
type InputHelp = {
|
|
@@ -192,7 +205,10 @@ export declare namespace Checkout {
|
|
|
192
205
|
inputId: string;
|
|
193
206
|
}) => void;
|
|
194
207
|
"checkout/plan": (params: PlanDecision) => void;
|
|
195
|
-
|
|
208
|
+
/** A cancel that names another checkout than the current one is a no-op. */
|
|
209
|
+
"checkout/cancel": (params?: {
|
|
210
|
+
id?: string;
|
|
211
|
+
}) => void;
|
|
196
212
|
"checkout/finish": () => void;
|
|
197
213
|
"agent/intro": (params: {
|
|
198
214
|
kind?: string;
|
|
@@ -275,6 +291,9 @@ type ChoiceAnswerKind = "option" | "custom" | "invalid";
|
|
|
275
291
|
* or the array is empty, "custom" when any entry is the user's own text.
|
|
276
292
|
*/
|
|
277
293
|
export declare const classifyChoiceAnswer: (input: Checkout.Input, answer: string) => ChoiceAnswerKind;
|
|
294
|
+
export declare const parseEntryPointOptions: (value: unknown) => Checkout.EntryPointOption[] | undefined;
|
|
295
|
+
export declare const isValidEntryPointInput: (input: Checkout.InputSeed) => boolean;
|
|
296
|
+
export declare const isValidEntryPointAnswer: (input: Checkout.Input, answer: string) => boolean;
|
|
278
297
|
/** The model answer an input holds, or `undefined` when the text is not one. */
|
|
279
298
|
export declare const parseModelAnswer: (answer: string) => Checkout.ModelAnswer | undefined;
|
|
280
299
|
/** Whether `answer` is a model answer naming one of the input's providers. */
|
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,yBAAiB,QAAQ,CAAC;IACxB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8DAA8D;AAC9D,eAAO,MAAM,YAAY,+aA4Cf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,UACD,CAAC;AAEtD,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM;;;CAK/C,CAAC;AAEF,4GAA4G;AAC5G,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,KAAG,MAAM,EAAE,GAAG,SAW/D,CAAC;AAEF,KAAK,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAiBxD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,QAAQ,CAAC,KAAK,EACrB,QAAQ,MAAM,KACb,gBAOF,CAAC;AAKF,eAAO,MAAM,sBAAsB,GACjC,OAAO,OAAO,KACb,QAAQ,CAAC,gBAAgB,EAAE,GAAG,SA6ChC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,OAAO,QAAQ,CAAC,SAAS,YAW/D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,QAAQ,CAAC,KAAK,EACrB,QAAQ,MAAM,YACmD,CAAC;AASpE,gFAAgF;AAChF,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,KACb,QAAQ,CAAC,WAAW,GAAG,SAoBzB,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,GAAI,OAAO,QAAQ,CAAC,KAAK,EAAE,QAAQ,MAAM,YAMvE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,QAAQ,CAAC,KAAK;;;CAKhD,CAAC"}
|
package/dist/protocol.js
CHANGED
|
@@ -143,6 +143,35 @@ const classifyChoiceAnswer = (input, answer) => {
|
|
|
143
143
|
if (kinds.includes("invalid")) return "invalid";
|
|
144
144
|
return kinds.includes("custom") ? "custom" : "option";
|
|
145
145
|
};
|
|
146
|
+
const isEntryPointText = (value, max) => typeof value === "string" && value.trim() !== "" && value.length <= max;
|
|
147
|
+
const parseEntryPointOptions = (value) => {
|
|
148
|
+
if (!Array.isArray(value) || value.length < 1 || value.length > 3) return void 0;
|
|
149
|
+
const options = [];
|
|
150
|
+
for (const candidate of value) {
|
|
151
|
+
if (typeof candidate !== "object" || candidate === null) return void 0;
|
|
152
|
+
const { id, label, description, entryPoint, variants } = candidate;
|
|
153
|
+
if (typeof id !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/.test(id) || options.some((option) => option.id === id) || !isEntryPointText(label, 160) || !isEntryPointText(description, 1e3) || variants !== void 0 || typeof entryPoint !== "object" || entryPoint === null) return void 0;
|
|
154
|
+
const { formFactor, placement, trigger, recommended } = entryPoint;
|
|
155
|
+
if (formFactor !== "modal" && formFactor !== "sidebar" && formFactor !== "full-page" || !isEntryPointText(placement, 400) || !isEntryPointText(trigger, 400) || recommended !== void 0 && typeof recommended !== "boolean") return void 0;
|
|
156
|
+
options.push({
|
|
157
|
+
id,
|
|
158
|
+
label,
|
|
159
|
+
description,
|
|
160
|
+
entryPoint: {
|
|
161
|
+
formFactor,
|
|
162
|
+
placement,
|
|
163
|
+
trigger,
|
|
164
|
+
...recommended !== void 0 && { recommended }
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return options.filter((option) => option.entryPoint.recommended).length <= 1 ? options : void 0;
|
|
169
|
+
};
|
|
170
|
+
const isValidEntryPointInput = (input) => {
|
|
171
|
+
const options = parseEntryPointOptions(input.options);
|
|
172
|
+
return input.kind === "entry-point" && isEntryPointText(input.prompt, 1e3) && options !== void 0 && input.multiple === void 0 && input.help === void 0 && (input.default === void 0 || options.some((option) => option.id === input.default));
|
|
173
|
+
};
|
|
174
|
+
const isValidEntryPointAnswer = (input, answer) => input.options?.some((option) => option.id === answer) ?? false;
|
|
146
175
|
const REASONING_EFFORTS = /* @__PURE__ */ new Set([
|
|
147
176
|
"low",
|
|
148
177
|
"medium",
|
|
@@ -181,6 +210,6 @@ const stepProgress = (state) => ({
|
|
|
181
210
|
done: state.steps.filter((step) => step.status === "done" || step.status === "skipped").length
|
|
182
211
|
});
|
|
183
212
|
//#endregion
|
|
184
|
-
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isValidModelAnswer, openInputs, parseChoiceAnswer, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress };
|
|
213
|
+
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isOptionIcon, isValidEntryPointAnswer, isValidEntryPointInput, isValidModelAnswer, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress };
|
|
185
214
|
|
|
186
215
|
//# sourceMappingURL=protocol.js.map
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","names":[],"sources":["../src/protocol.ts"],"sourcesContent":["export namespace Checkout {\n export type StepStatus =\n | \"pending\"\n | \"active\"\n | \"done\"\n | \"skipped\"\n | \"blocked\";\n\n /** A unit of install work the agent declared; the catalog seeds none. */\n export type Step = {\n id: string;\n title: string;\n detail?: string;\n status: StepStatus;\n note?: string;\n /** The product this step belongs to, when the agent said. */\n product?: string;\n createdAt: number;\n };\n\n export type Product = {\n slug: string;\n name: string;\n /** The install reference the agent fetches while planning. */\n guide?: string;\n };\n\n export type InputStatus = \"open\" | \"answered\" | \"dismissed\";\n\n /**\n * product: the agent proposes adding a product to this checkout, such as one\n * another product depends on. The browser owns the catalog, so it answers\n * with `checkout/add-product`; dismissing the input declines.\n */\n export type InputKind = \"text\" | \"choice\" | \"model\" | \"product\";\n\n export type ChoiceVariant = { id: string; label: string };\n\n export type ChoiceOption = {\n id: string;\n label: string;\n description?: string;\n /** A name from OPTION_ICONS, or the key of a brand mark on a preset option; unknown keys render without one. */\n icon?: string;\n /** A second pick under this option, such as the language of a framework. */\n variants?: ChoiceVariant[];\n };\n\n /** A short nudge for users who need help choosing, with a longer guide to link to. */\n export type InputHelp = { summary: string; href?: string };\n\n /**\n * The answer to a model input, stored as JSON text. The API key itself is\n * never part of it: the browser deposits it with the checkout and the\n * agent's `env` command writes it straight to a file.\n */\n export type ModelAnswer = {\n provider: string;\n model: string;\n reasoningEffort?: \"low\" | \"medium\" | \"high\";\n };\n\n /**\n * A choice answer is an option id, `<option>:<variant>` when the option has\n * variants, or the user's own text when none of the options fit; a multiple\n * choice answers a JSON array of those. A model answer is a JSON-encoded\n * ModelAnswer whose provider is one of the options.\n */\n export type Input = {\n phase: Status;\n id: string;\n kind: InputKind;\n /** The standard input this was built from, when it was. */\n preset?: string;\n prompt: string;\n placeholder?: string;\n options?: ChoiceOption[];\n /** The user may pick any number of options; the answer is a JSON array. */\n multiple?: true;\n /** The slug a product input proposes. */\n product?: string;\n default?: string;\n help?: InputHelp;\n optional: boolean;\n status: InputStatus;\n answer?: string;\n /** A remark the user attached to the answer. */\n note?: string;\n stepId?: string;\n createdAt: number;\n answeredAt?: number;\n };\n\n export type LogEntry = {\n phase: Status;\n id: string;\n role: \"agent\" | \"user\";\n acknowledgedAt?: number;\n at: number;\n text: string;\n /** The step that was active when the line was posted; none while planning. */\n stepId?: string;\n };\n\n export type PlanStatus = \"proposed\" | \"approved\" | \"changes-requested\";\n\n /** One revision of the agent's plan. Markdown the browser renders. */\n export type Plan = {\n revision: number;\n markdown: string;\n status: PlanStatus;\n submittedAt: number;\n decidedAt?: number;\n /** What the user asked to change, when they did. */\n feedback?: string;\n };\n\n /**\n * waiting: no agent has joined. planning: the agent investigates and\n * proposes a plan. installing: the plan is approved and steps run.\n */\n export type Status =\n | \"waiting\"\n | \"planning\"\n | \"installing\"\n | \"done\"\n | \"cancelled\";\n\n /**\n * The agent's proposal to close the checkout. Only the user closes it, and\n * they may keep messaging the agent instead; a later `done` renews it.\n * `preview` is the loopback URL of a dev server the agent left running for\n * the user to try before they close.\n */\n export type Completion = { proposedAt: number; preview?: string };\n\n export type State = {\n version: 2;\n /** The id the browser gave the current checkout; a create with another id replaces it on the same link. */\n id: string | null;\n status: Status;\n completion?: Completion;\n createdAt: number | null;\n products: Product[];\n instructions: string;\n agent: {\n lastSeenAt: number | null;\n /** False once the agent's stream said goodbye; heartbeats set it again. */\n connected: boolean;\n cwd: string | null;\n /** The coding agent that ran the command, as the CLI detected it from its environment. */\n kind: string | null;\n /** When the command was first run against this checkout, before the agent joined the stream. */\n introducedAt: number | null;\n };\n /** Every revision in order; the last one is current. */\n plans: Plan[];\n steps: Step[];\n inputs: Input[];\n log: LogEntry[];\n };\n\n export type ProductSeed = { slug: string; name: string; guide?: string };\n\n export type InputSeed = {\n kind?: InputKind;\n preset?: string;\n prompt: string;\n placeholder?: string;\n options?: ChoiceOption[];\n multiple?: true;\n product?: string;\n default?: string;\n help?: InputHelp;\n optional?: boolean;\n };\n\n export type PlanDecision =\n | { decision: \"approve\" }\n | { decision: \"revise\"; feedback: string };\n\n export type Commands = {\n \"checkout/create\": (params: {\n id: string;\n products: ProductSeed[];\n instructions?: string;\n }) => void;\n \"checkout/begin-plan\": () => void;\n \"checkout/answer\": (params: {\n inputId: string;\n answer: string;\n note?: string;\n }) => void;\n \"checkout/add-product\": (params: {\n inputId: string;\n product: ProductSeed;\n }) => void;\n \"checkout/message\": (params: { text: string }) => void;\n \"agent/ack\": (params: { messageId: string }) => void;\n \"checkout/dismiss\": (params: { inputId: string }) => void;\n \"checkout/plan\": (params: PlanDecision) => void;\n \"checkout/cancel\": () => void;\n \"checkout/finish\": () => void;\n \"agent/intro\": (params: { kind?: string }) => void;\n \"agent/hello\": (params: { cwd?: string; kind?: string }) => void;\n \"agent/heartbeat\": () => void;\n \"agent/bye\": () => void;\n \"agent/plan\": (params: { markdown: string }) => { revision: number };\n \"agent/add-step\": (params: {\n title: string;\n detail?: string;\n product?: string;\n /** Start the step in the same call. */\n active?: boolean;\n }) => { stepId: string };\n \"agent/step\": (params: {\n stepId: string;\n status: StepStatus;\n note?: string;\n }) => void;\n \"agent/ask\": (params: InputSeed & { stepId?: string }) => {\n inputId: string;\n };\n \"agent/log\": (params: { text: string }) => void;\n \"agent/done\": (params?: { summary?: string; preview?: string }) => void;\n };\n\n export type RejectionReason =\n | \"already-created\"\n | \"not-created\"\n | \"closed\"\n | \"planning-not-started\"\n | \"plan-required\"\n | \"no-plan\"\n | \"plan-decided\"\n | \"finish-not-proposed\"\n | \"feedback-required\"\n | \"empty-plan\"\n | \"unknown-step\"\n | \"unknown-product\"\n | \"unknown-input\"\n | \"input-closed\"\n | \"invalid-input\"\n | \"invalid-answer\"\n | \"invalid-preview\"\n | \"empty-message\"\n | \"unknown-message\";\n}\n\nexport const AGENT_PRESENCE_MS = 15_000;\nexport const AGENT_HEARTBEAT_MS = 5_000;\n\nexport const initialCheckoutState = (): Checkout.State => ({\n version: 2,\n id: null,\n status: \"waiting\",\n createdAt: null,\n products: [],\n instructions: \"\",\n agent: {\n lastSeenAt: null,\n connected: false,\n cwd: null,\n kind: null,\n introducedAt: null,\n },\n plans: [],\n steps: [],\n inputs: [],\n log: [],\n});\n\nexport const isAgentPresent = (state: Checkout.State, now = Date.now()) =>\n state.agent.connected &&\n state.agent.lastSeenAt !== null &&\n now - state.agent.lastSeenAt < AGENT_PRESENCE_MS;\n\nexport const isClosed = (state: Checkout.State) =>\n state.status === \"done\" || state.status === \"cancelled\";\n\n/** True while the agent's proposal to close waits for the user. */\nexport const finishProposed = (state: Checkout.State) =>\n !isClosed(state) && state.completion !== undefined;\n\n/** True while a message the user sent after the agent proposed to close still waits for the agent. */\nexport const followedUpSinceProposal = (state: Checkout.State) => {\n const proposedAt = state.completion?.proposedAt;\n return (\n proposedAt !== undefined &&\n state.log.some(\n (entry) =>\n entry.role === \"user\" &&\n entry.at > proposedAt &&\n entry.acknowledgedAt === undefined,\n )\n );\n};\n\nconst LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/**\n * The URL a preview names, or `undefined` unless it is an http(s) URL on this\n * machine's loopback interface. The browser opens it, so nothing else passes.\n */\nexport const parsePreviewUrl = (value: string | undefined) => {\n if (!value) return undefined;\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return undefined;\n }\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return undefined;\n if (url.username !== \"\" || url.password !== \"\") return undefined;\n const loopback =\n LOOPBACK_HOSTS.has(url.hostname) || url.hostname.endsWith(\".localhost\");\n return loopback ? url : undefined;\n};\n\nexport const openInputs = (state: Checkout.State) =>\n state.inputs.filter((input) => input.status === \"open\");\n\n/** The current plan revision, or `undefined` before the agent proposed one. */\nexport const currentPlan = (state: Checkout.State): Checkout.Plan | undefined =>\n state.plans.at(-1);\n\n/** True while a proposed plan waits for the user's decision. */\nexport const planNeedsReview = (state: Checkout.State) =>\n !isClosed(state) && currentPlan(state)?.status === \"proposed\";\n\n/** The icons an agent can put on its own options, by name. */\nexport const OPTION_ICONS = [\n \"code\",\n \"terminal\",\n \"braces\",\n \"git-branch\",\n \"package\",\n \"database\",\n \"server\",\n \"cloud\",\n \"globe\",\n \"monitor\",\n \"smartphone\",\n \"key\",\n \"lock\",\n \"shield\",\n \"brain\",\n \"sparkles\",\n \"bot\",\n \"workflow\",\n \"file\",\n \"folder\",\n \"book\",\n \"table\",\n \"image\",\n \"video\",\n \"mic\",\n \"speech\",\n \"paperclip\",\n \"message\",\n \"mail\",\n \"bell\",\n \"calendar\",\n \"clock\",\n \"user\",\n \"users\",\n \"settings\",\n \"wrench\",\n \"plug\",\n \"link\",\n \"palette\",\n \"search\",\n \"zap\",\n \"check\",\n \"question\",\n] as const;\n\nexport type OptionIcon = (typeof OPTION_ICONS)[number];\n\nexport const isOptionIcon = (value: string): value is OptionIcon =>\n (OPTION_ICONS as readonly string[]).includes(value);\n\nexport const parseChoiceAnswer = (answer: string) => {\n const parts = answer.split(\":\");\n if (parts.length > 2) return { option: answer };\n const [option = \"\", variant] = parts;\n return { option, ...(variant !== undefined && { variant }) };\n};\n\n/** The entries of a multiple choice answer, or `undefined` when the text is not a JSON array of strings. */\nexport const parseMultipleAnswer = (answer: string): string[] | undefined => {\n let value: unknown;\n try {\n value = JSON.parse(answer);\n } catch {\n return undefined;\n }\n return Array.isArray(value) &&\n value.every((entry) => typeof entry === \"string\")\n ? value\n : undefined;\n};\n\ntype ChoiceAnswerKind = \"option\" | \"custom\" | \"invalid\";\n\nconst classifyChoiceEntry = (\n input: Checkout.Input,\n answer: string,\n): ChoiceAnswerKind => {\n const { option, variant } = parseChoiceAnswer(answer);\n const match = input.options?.find((candidate) => candidate.id === option);\n if (!match) return answer.trim() === \"\" ? \"invalid\" : \"custom\";\n if (!match.variants || match.variants.length === 0) {\n return variant === undefined ? \"option\" : \"invalid\";\n }\n return match.variants.some((candidate) => candidate.id === variant)\n ? \"option\"\n : \"invalid\";\n};\n\n/**\n * \"option\" when `answer` names one of the input's options (with a variant\n * when the option has them), \"custom\" for the user's own text, \"invalid\"\n * for an option named without its variant or with an unknown one. A\n * multiple choice is classified entry by entry: \"invalid\" when any entry is\n * or the array is empty, \"custom\" when any entry is the user's own text.\n */\nexport const classifyChoiceAnswer = (\n input: Checkout.Input,\n answer: string,\n): ChoiceAnswerKind => {\n if (!input.multiple) return classifyChoiceEntry(input, answer);\n const entries = parseMultipleAnswer(answer);\n if (!entries || entries.length === 0) return \"invalid\";\n const kinds = entries.map((entry) => classifyChoiceEntry(input, entry));\n if (kinds.includes(\"invalid\")) return \"invalid\";\n return kinds.includes(\"custom\") ? \"custom\" : \"option\";\n};\n\nconst REASONING_EFFORTS = new Set([\"low\", \"medium\", \"high\"]);\n\nconst isReasoningEffort = (\n value: unknown,\n): value is NonNullable<Checkout.ModelAnswer[\"reasoningEffort\"]> =>\n typeof value === \"string\" && REASONING_EFFORTS.has(value);\n\n/** The model answer an input holds, or `undefined` when the text is not one. */\nexport const parseModelAnswer = (\n answer: string,\n): Checkout.ModelAnswer | undefined => {\n let value: unknown;\n try {\n value = JSON.parse(answer);\n } catch {\n return undefined;\n }\n if (typeof value !== \"object\" || value === null) return undefined;\n const { provider, model, reasoningEffort } = value as Record<string, unknown>;\n if (\n typeof provider !== \"string\" ||\n typeof model !== \"string\" ||\n provider === \"\" ||\n model === \"\"\n ) {\n return undefined;\n }\n if (reasoningEffort === undefined) return { provider, model };\n if (!isReasoningEffort(reasoningEffort)) return undefined;\n return { provider, model, reasoningEffort };\n};\n\n/** Whether `answer` is a model answer naming one of the input's providers. */\nexport const isValidModelAnswer = (input: Checkout.Input, answer: string) => {\n const parsed = parseModelAnswer(answer);\n return (\n parsed !== undefined &&\n (input.options?.some((option) => option.id === parsed.provider) ?? false)\n );\n};\n\nexport const stepProgress = (state: Checkout.State) => ({\n total: state.steps.length,\n done: state.steps.filter(\n (step) => step.status === \"done\" || step.status === \"skipped\",\n ).length,\n});\n"],"mappings":";AAyPA,MAAa,oBAAoB;AACjC,MAAa,qBAAqB;AAElC,MAAa,8BAA8C;CACzD,SAAS;CACT,IAAI;CACJ,QAAQ;CACR,WAAW;CACX,UAAU,CAAC;CACX,cAAc;CACd,OAAO;EACL,YAAY;EACZ,WAAW;EACX,KAAK;EACL,MAAM;EACN,cAAc;CAChB;CACA,OAAO,CAAC;CACR,OAAO,CAAC;CACR,QAAQ,CAAC;CACT,KAAK,CAAC;AACR;AAEA,MAAa,kBAAkB,OAAuB,MAAM,KAAK,IAAI,MACnE,MAAM,MAAM,aACZ,MAAM,MAAM,eAAe,QAC3B,MAAM,MAAM,MAAM,aAAA;AAEpB,MAAa,YAAY,UACvB,MAAM,WAAW,UAAU,MAAM,WAAW;;AAG9C,MAAa,kBAAkB,UAC7B,C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;CAC3B,QAAQ;EACN;CACF;CACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CACxD,MAAM,EAAE,UAAU,OAAO,oBAAoB;CAC7C,IACE,OAAO,aAAa,YACpB,OAAO,UAAU,YACjB,aAAa,MACb,UAAU,IAEV;CAEF,IAAI,oBAAoB,KAAA,GAAW,OAAO;EAAE;EAAU;CAAM;CAC5D,IAAI,CAAC,kBAAkB,eAAe,GAAG,OAAO,KAAA;CAChD,OAAO;EAAE;EAAU;EAAO;CAAgB;AAC5C;;AAGA,MAAa,sBAAsB,OAAuB,WAAmB;CAC3E,MAAM,SAAS,iBAAiB,MAAM;CACtC,OACE,WAAW,KAAA,MACV,MAAM,SAAS,MAAM,WAAW,OAAO,OAAO,OAAO,QAAQ,KAAK;AAEvE;AAEA,MAAa,gBAAgB,WAA2B;CACtD,OAAO,MAAM,MAAM;CACnB,MAAM,MAAM,MAAM,QACf,SAAS,KAAK,WAAW,UAAU,KAAK,WAAW,SACtD,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"protocol.js","names":[],"sources":["../src/protocol.ts"],"sourcesContent":["export namespace Checkout {\n export type StepStatus =\n | \"pending\"\n | \"active\"\n | \"done\"\n | \"skipped\"\n | \"blocked\";\n\n /** A unit of install work the agent declared; the catalog seeds none. */\n export type Step = {\n id: string;\n title: string;\n detail?: string;\n status: StepStatus;\n note?: string;\n /** The product this step belongs to, when the agent said. */\n product?: string;\n createdAt: number;\n };\n\n export type Product = {\n slug: string;\n name: string;\n /** The install reference the agent fetches while planning. */\n guide?: string;\n };\n\n export type InputStatus = \"open\" | \"answered\" | \"dismissed\";\n\n /**\n * product: the agent proposes adding a product to this checkout, such as one\n * another product depends on. The browser owns the catalog, so it answers\n * with `checkout/add-product`; dismissing the input declines.\n */\n export type InputKind =\n | \"text\"\n | \"choice\"\n | \"model\"\n | \"product\"\n | \"entry-point\";\n\n export type EntryPoint = {\n formFactor: \"modal\" | \"sidebar\" | \"full-page\";\n placement: string;\n trigger: string;\n recommended?: boolean;\n };\n\n export type EntryPointOption = {\n id: string;\n label: string;\n description: string;\n entryPoint: EntryPoint;\n };\n\n export type ChoiceVariant = { id: string; label: string };\n\n export type ChoiceOption = {\n id: string;\n label: string;\n description?: string;\n /** A name from OPTION_ICONS, or the key of a brand mark on a preset option; unknown keys render without one. */\n icon?: string;\n /** A second pick under this option, such as the language of a framework. */\n variants?: ChoiceVariant[];\n entryPoint?: EntryPoint;\n };\n\n /** A short nudge for users who need help choosing, with a longer guide to link to. */\n export type InputHelp = { summary: string; href?: string };\n\n /**\n * The answer to a model input, stored as JSON text. The API key itself is\n * never part of it: the browser deposits it with the checkout and the\n * agent's `env` command writes it straight to a file.\n */\n export type ModelAnswer = {\n provider: string;\n model: string;\n reasoningEffort?: \"low\" | \"medium\" | \"high\";\n };\n\n /**\n * A choice answer is an option id, `<option>:<variant>` when the option has\n * variants, or the user's own text when none of the options fit; a multiple\n * choice answers a JSON array of those. A model answer is a JSON-encoded\n * ModelAnswer whose provider is one of the options.\n */\n export type Input = {\n phase: Status;\n id: string;\n kind: InputKind;\n /** The standard input this was built from, when it was. */\n preset?: string;\n prompt: string;\n placeholder?: string;\n options?: ChoiceOption[];\n /** The user may pick any number of options; the answer is a JSON array. */\n multiple?: true;\n /** The slug a product input proposes. */\n product?: string;\n default?: string;\n help?: InputHelp;\n optional: boolean;\n status: InputStatus;\n answer?: string;\n /** A remark the user attached to the answer. */\n note?: string;\n stepId?: string;\n createdAt: number;\n answeredAt?: number;\n };\n\n export type LogEntry = {\n phase: Status;\n id: string;\n role: \"agent\" | \"user\";\n acknowledgedAt?: number;\n at: number;\n text: string;\n /** The step that was active when the line was posted; none while planning. */\n stepId?: string;\n };\n\n export type PlanStatus = \"proposed\" | \"approved\" | \"changes-requested\";\n\n /** One revision of the agent's plan. Markdown the browser renders. */\n export type Plan = {\n revision: number;\n markdown: string;\n status: PlanStatus;\n submittedAt: number;\n decidedAt?: number;\n /** What the user asked to change, when they did. */\n feedback?: string;\n };\n\n /**\n * waiting: no agent has joined. planning: the agent investigates and\n * proposes a plan. installing: the plan is approved and steps run.\n */\n export type Status =\n | \"waiting\"\n | \"planning\"\n | \"installing\"\n | \"done\"\n | \"cancelled\";\n\n /**\n * The agent's proposal to close the checkout. Only the user closes it, and\n * they may keep messaging the agent instead; a later `done` renews it.\n * `preview` is the loopback URL of a dev server the agent left running for\n * the user to try before they close.\n */\n export type Completion = { proposedAt: number; preview?: string };\n\n export type State = {\n version: 2;\n /** The id the browser gave the current checkout; a create with another id replaces it on the same link. */\n id: string | null;\n status: Status;\n completion?: Completion;\n createdAt: number | null;\n products: Product[];\n instructions: string;\n agent: {\n lastSeenAt: number | null;\n /** False once the agent's stream said goodbye; heartbeats set it again. */\n connected: boolean;\n cwd: string | null;\n /** The coding agent that ran the command, as the CLI detected it from its environment. */\n kind: string | null;\n /** When the command was first run against this checkout, before the agent joined the stream. */\n introducedAt: number | null;\n };\n /** Every revision in order; the last one is current. */\n plans: Plan[];\n steps: Step[];\n inputs: Input[];\n log: LogEntry[];\n };\n\n export type ProductSeed = { slug: string; name: string; guide?: string };\n\n export type InputSeed = {\n kind?: InputKind;\n preset?: string;\n prompt: string;\n placeholder?: string;\n options?: ChoiceOption[];\n multiple?: true;\n product?: string;\n default?: string;\n help?: InputHelp;\n optional?: boolean;\n };\n\n export type PlanDecision =\n | { decision: \"approve\" }\n | { decision: \"revise\"; feedback: string };\n\n export type Commands = {\n \"checkout/create\": (params: {\n id: string;\n products: ProductSeed[];\n instructions?: string;\n }) => void;\n \"checkout/begin-plan\": () => void;\n \"checkout/answer\": (params: {\n inputId: string;\n answer: string;\n note?: string;\n }) => void;\n \"checkout/add-product\": (params: {\n inputId: string;\n product: ProductSeed;\n }) => void;\n \"checkout/message\": (params: { text: string }) => void;\n \"agent/ack\": (params: { messageId: string }) => void;\n \"checkout/dismiss\": (params: { inputId: string }) => void;\n \"checkout/plan\": (params: PlanDecision) => void;\n /** A cancel that names another checkout than the current one is a no-op. */\n \"checkout/cancel\": (params?: { id?: string }) => void;\n \"checkout/finish\": () => void;\n \"agent/intro\": (params: { kind?: string }) => void;\n \"agent/hello\": (params: { cwd?: string; kind?: string }) => void;\n \"agent/heartbeat\": () => void;\n \"agent/bye\": () => void;\n \"agent/plan\": (params: { markdown: string }) => { revision: number };\n \"agent/add-step\": (params: {\n title: string;\n detail?: string;\n product?: string;\n /** Start the step in the same call. */\n active?: boolean;\n }) => { stepId: string };\n \"agent/step\": (params: {\n stepId: string;\n status: StepStatus;\n note?: string;\n }) => void;\n \"agent/ask\": (params: InputSeed & { stepId?: string }) => {\n inputId: string;\n };\n \"agent/log\": (params: { text: string }) => void;\n \"agent/done\": (params?: { summary?: string; preview?: string }) => void;\n };\n\n export type RejectionReason =\n | \"already-created\"\n | \"not-created\"\n | \"closed\"\n | \"planning-not-started\"\n | \"plan-required\"\n | \"no-plan\"\n | \"plan-decided\"\n | \"finish-not-proposed\"\n | \"feedback-required\"\n | \"empty-plan\"\n | \"unknown-step\"\n | \"unknown-product\"\n | \"unknown-input\"\n | \"input-closed\"\n | \"invalid-input\"\n | \"invalid-answer\"\n | \"invalid-preview\"\n | \"empty-message\"\n | \"unknown-message\";\n}\n\nexport const AGENT_PRESENCE_MS = 15_000;\nexport const AGENT_HEARTBEAT_MS = 5_000;\n\nexport const initialCheckoutState = (): Checkout.State => ({\n version: 2,\n id: null,\n status: \"waiting\",\n createdAt: null,\n products: [],\n instructions: \"\",\n agent: {\n lastSeenAt: null,\n connected: false,\n cwd: null,\n kind: null,\n introducedAt: null,\n },\n plans: [],\n steps: [],\n inputs: [],\n log: [],\n});\n\nexport const isAgentPresent = (state: Checkout.State, now = Date.now()) =>\n state.agent.connected &&\n state.agent.lastSeenAt !== null &&\n now - state.agent.lastSeenAt < AGENT_PRESENCE_MS;\n\nexport const isClosed = (state: Checkout.State) =>\n state.status === \"done\" || state.status === \"cancelled\";\n\n/** True while the agent's proposal to close waits for the user. */\nexport const finishProposed = (state: Checkout.State) =>\n !isClosed(state) && state.completion !== undefined;\n\n/** True while a message the user sent after the agent proposed to close still waits for the agent. */\nexport const followedUpSinceProposal = (state: Checkout.State) => {\n const proposedAt = state.completion?.proposedAt;\n return (\n proposedAt !== undefined &&\n state.log.some(\n (entry) =>\n entry.role === \"user\" &&\n entry.at > proposedAt &&\n entry.acknowledgedAt === undefined,\n )\n );\n};\n\nconst LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/**\n * The URL a preview names, or `undefined` unless it is an http(s) URL on this\n * machine's loopback interface. The browser opens it, so nothing else passes.\n */\nexport const parsePreviewUrl = (value: string | undefined) => {\n if (!value) return undefined;\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return undefined;\n }\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return undefined;\n if (url.username !== \"\" || url.password !== \"\") return undefined;\n const loopback =\n LOOPBACK_HOSTS.has(url.hostname) || url.hostname.endsWith(\".localhost\");\n return loopback ? url : undefined;\n};\n\nexport const openInputs = (state: Checkout.State) =>\n state.inputs.filter((input) => input.status === \"open\");\n\n/** The current plan revision, or `undefined` before the agent proposed one. */\nexport const currentPlan = (state: Checkout.State): Checkout.Plan | undefined =>\n state.plans.at(-1);\n\n/** True while a proposed plan waits for the user's decision. */\nexport const planNeedsReview = (state: Checkout.State) =>\n !isClosed(state) && currentPlan(state)?.status === \"proposed\";\n\n/** The icons an agent can put on its own options, by name. */\nexport const OPTION_ICONS = [\n \"code\",\n \"terminal\",\n \"braces\",\n \"git-branch\",\n \"package\",\n \"database\",\n \"server\",\n \"cloud\",\n \"globe\",\n \"monitor\",\n \"smartphone\",\n \"key\",\n \"lock\",\n \"shield\",\n \"brain\",\n \"sparkles\",\n \"bot\",\n \"workflow\",\n \"file\",\n \"folder\",\n \"book\",\n \"table\",\n \"image\",\n \"video\",\n \"mic\",\n \"speech\",\n \"paperclip\",\n \"message\",\n \"mail\",\n \"bell\",\n \"calendar\",\n \"clock\",\n \"user\",\n \"users\",\n \"settings\",\n \"wrench\",\n \"plug\",\n \"link\",\n \"palette\",\n \"search\",\n \"zap\",\n \"check\",\n \"question\",\n] as const;\n\nexport type OptionIcon = (typeof OPTION_ICONS)[number];\n\nexport const isOptionIcon = (value: string): value is OptionIcon =>\n (OPTION_ICONS as readonly string[]).includes(value);\n\nexport const parseChoiceAnswer = (answer: string) => {\n const parts = answer.split(\":\");\n if (parts.length > 2) return { option: answer };\n const [option = \"\", variant] = parts;\n return { option, ...(variant !== undefined && { variant }) };\n};\n\n/** The entries of a multiple choice answer, or `undefined` when the text is not a JSON array of strings. */\nexport const parseMultipleAnswer = (answer: string): string[] | undefined => {\n let value: unknown;\n try {\n value = JSON.parse(answer);\n } catch {\n return undefined;\n }\n return Array.isArray(value) &&\n value.every((entry) => typeof entry === \"string\")\n ? value\n : undefined;\n};\n\ntype ChoiceAnswerKind = \"option\" | \"custom\" | \"invalid\";\n\nconst classifyChoiceEntry = (\n input: Checkout.Input,\n answer: string,\n): ChoiceAnswerKind => {\n const { option, variant } = parseChoiceAnswer(answer);\n const match = input.options?.find((candidate) => candidate.id === option);\n if (!match) return answer.trim() === \"\" ? \"invalid\" : \"custom\";\n if (!match.variants || match.variants.length === 0) {\n return variant === undefined ? \"option\" : \"invalid\";\n }\n return match.variants.some((candidate) => candidate.id === variant)\n ? \"option\"\n : \"invalid\";\n};\n\n/**\n * \"option\" when `answer` names one of the input's options (with a variant\n * when the option has them), \"custom\" for the user's own text, \"invalid\"\n * for an option named without its variant or with an unknown one. A\n * multiple choice is classified entry by entry: \"invalid\" when any entry is\n * or the array is empty, \"custom\" when any entry is the user's own text.\n */\nexport const classifyChoiceAnswer = (\n input: Checkout.Input,\n answer: string,\n): ChoiceAnswerKind => {\n if (!input.multiple) return classifyChoiceEntry(input, answer);\n const entries = parseMultipleAnswer(answer);\n if (!entries || entries.length === 0) return \"invalid\";\n const kinds = entries.map((entry) => classifyChoiceEntry(input, entry));\n if (kinds.includes(\"invalid\")) return \"invalid\";\n return kinds.includes(\"custom\") ? \"custom\" : \"option\";\n};\n\nconst isEntryPointText = (value: unknown, max: number): value is string =>\n typeof value === \"string\" && value.trim() !== \"\" && value.length <= max;\n\nexport const parseEntryPointOptions = (\n value: unknown,\n): Checkout.EntryPointOption[] | undefined => {\n if (!Array.isArray(value) || value.length < 1 || value.length > 3)\n return undefined;\n const options: Checkout.EntryPointOption[] = [];\n for (const candidate of value) {\n if (typeof candidate !== \"object\" || candidate === null) return undefined;\n const { id, label, description, entryPoint, variants } =\n candidate as Record<string, unknown>;\n if (\n typeof id !== \"string\" ||\n !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/.test(id) ||\n options.some((option) => option.id === id) ||\n !isEntryPointText(label, 160) ||\n !isEntryPointText(description, 1000) ||\n variants !== undefined ||\n typeof entryPoint !== \"object\" ||\n entryPoint === null\n )\n return undefined;\n const { formFactor, placement, trigger, recommended } =\n entryPoint as Record<string, unknown>;\n if (\n (formFactor !== \"modal\" &&\n formFactor !== \"sidebar\" &&\n formFactor !== \"full-page\") ||\n !isEntryPointText(placement, 400) ||\n !isEntryPointText(trigger, 400) ||\n (recommended !== undefined && typeof recommended !== \"boolean\")\n )\n return undefined;\n options.push({\n id,\n label,\n description,\n entryPoint: {\n formFactor,\n placement,\n trigger,\n ...(recommended !== undefined && { recommended }),\n },\n });\n }\n return options.filter((option) => option.entryPoint.recommended).length <= 1\n ? options\n : undefined;\n};\n\nexport const isValidEntryPointInput = (input: Checkout.InputSeed) => {\n const options = parseEntryPointOptions(input.options);\n return (\n input.kind === \"entry-point\" &&\n isEntryPointText(input.prompt, 1000) &&\n options !== undefined &&\n input.multiple === undefined &&\n input.help === undefined &&\n (input.default === undefined ||\n options.some((option) => option.id === input.default))\n );\n};\n\nexport const isValidEntryPointAnswer = (\n input: Checkout.Input,\n answer: string,\n) => input.options?.some((option) => option.id === answer) ?? false;\n\nconst REASONING_EFFORTS = new Set([\"low\", \"medium\", \"high\"]);\n\nconst isReasoningEffort = (\n value: unknown,\n): value is NonNullable<Checkout.ModelAnswer[\"reasoningEffort\"]> =>\n typeof value === \"string\" && REASONING_EFFORTS.has(value);\n\n/** The model answer an input holds, or `undefined` when the text is not one. */\nexport const parseModelAnswer = (\n answer: string,\n): Checkout.ModelAnswer | undefined => {\n let value: unknown;\n try {\n value = JSON.parse(answer);\n } catch {\n return undefined;\n }\n if (typeof value !== \"object\" || value === null) return undefined;\n const { provider, model, reasoningEffort } = value as Record<string, unknown>;\n if (\n typeof provider !== \"string\" ||\n typeof model !== \"string\" ||\n provider === \"\" ||\n model === \"\"\n ) {\n return undefined;\n }\n if (reasoningEffort === undefined) return { provider, model };\n if (!isReasoningEffort(reasoningEffort)) return undefined;\n return { provider, model, reasoningEffort };\n};\n\n/** Whether `answer` is a model answer naming one of the input's providers. */\nexport const isValidModelAnswer = (input: Checkout.Input, answer: string) => {\n const parsed = parseModelAnswer(answer);\n return (\n parsed !== undefined &&\n (input.options?.some((option) => option.id === parsed.provider) ?? false)\n );\n};\n\nexport const stepProgress = (state: Checkout.State) => ({\n total: state.steps.length,\n done: state.steps.filter(\n (step) => step.status === \"done\" || step.status === \"skipped\",\n ).length,\n});\n"],"mappings":";AA8QA,MAAa,oBAAoB;AACjC,MAAa,qBAAqB;AAElC,MAAa,8BAA8C;CACzD,SAAS;CACT,IAAI;CACJ,QAAQ;CACR,WAAW;CACX,UAAU,CAAC;CACX,cAAc;CACd,OAAO;EACL,YAAY;EACZ,WAAW;EACX,KAAK;EACL,MAAM;EACN,cAAc;CAChB;CACA,OAAO,CAAC;CACR,OAAO,CAAC;CACR,QAAQ,CAAC;CACT,KAAK,CAAC;AACR;AAEA,MAAa,kBAAkB,OAAuB,MAAM,KAAK,IAAI,MACnE,MAAM,MAAM,aACZ,MAAM,MAAM,eAAe,QAC3B,MAAM,MAAM,MAAM,aAAA;AAEpB,MAAa,YAAY,UACvB,MAAM,WAAW,UAAU,MAAM,WAAW;;AAG9C,MAAa,kBAAkB,U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M,qBACJ,UAEA,OAAO,UAAU,YAAY,kBAAkB,IAAI,KAAK;;AAG1D,MAAa,oBACX,WACqC;CACrC,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,MAAM;CAC3B,QAAQ;EACN;CACF;CACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CACxD,MAAM,EAAE,UAAU,OAAO,oBAAoB;CAC7C,IACE,OAAO,aAAa,YACpB,OAAO,UAAU,YACjB,aAAa,MACb,UAAU,IAEV;CAEF,IAAI,oBAAoB,KAAA,GAAW,OAAO;EAAE;EAAU;CAAM;CAC5D,IAAI,CAAC,kBAAkB,eAAe,GAAG,OAAO,KAAA;CAChD,OAAO;EAAE;EAAU;EAAO;CAAgB;AAC5C;;AAGA,MAAa,sBAAsB,OAAuB,WAAmB;CAC3E,MAAM,SAAS,iBAAiB,MAAM;CACtC,OACE,WAAW,KAAA,MACV,MAAM,SAAS,MAAM,WAAW,OAAO,OAAO,OAAO,QAAQ,KAAK;AAEvE;AAEA,MAAa,gBAAgB,WAA2B;CACtD,OAAO,MAAM,MAAM;CACnB,MAAM,MAAM,MAAM,QACf,SAAS,KAAK,WAAW,UAAU,KAAK,WAAW,SACtD,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "setup-agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A live setup shared between a browser and the coding agent installing the products in it, on Statewire",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.assistant-ui.com/",
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"README.md"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@assistant-ui/tap": "^0.9.
|
|
47
|
-
"statewire": "^0.
|
|
46
|
+
"@assistant-ui/tap": "^0.9.24",
|
|
47
|
+
"statewire": "^0.20.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
51
|
-
"@types/node": "^26.
|
|
52
|
-
"@types/react": "^19.
|
|
53
|
-
"react": "^19.
|
|
50
|
+
"@assistant-ui/x-buildutils": "0.0.31",
|
|
51
|
+
"@types/node": "^26.6.5",
|
|
52
|
+
"@types/react": "^19.3.0",
|
|
53
|
+
"react": "^19.3.1",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
|
-
"vitest": "^5.0.
|
|
55
|
+
"vitest": "^5.0.5"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=20"
|
package/src/cli.test.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
HELP,
|
|
15
15
|
INSTRUCTIONS,
|
|
16
16
|
askSeed,
|
|
17
|
+
agentInstructions,
|
|
17
18
|
diffEvents,
|
|
18
19
|
detectAgentKind,
|
|
19
20
|
isDirectInvocation,
|
|
@@ -23,6 +24,17 @@ import {
|
|
|
23
24
|
} from "./cli";
|
|
24
25
|
|
|
25
26
|
describe("the agent's briefing", () => {
|
|
27
|
+
it("preserves the published instructions export and setup-created event wording", () => {
|
|
28
|
+
expect(INSTRUCTIONS).toBe(agentInstructions);
|
|
29
|
+
expect(typeof HELP).toBe("string");
|
|
30
|
+
expect(INSTRUCTIONS("https://example.test/session")).toContain(
|
|
31
|
+
'"setup.created"',
|
|
32
|
+
);
|
|
33
|
+
expect(INSTRUCTIONS("https://example.test/session")).not.toContain(
|
|
34
|
+
'"checkout.created"',
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
26
38
|
it("describes a setup without the wording of a purchase", () => {
|
|
27
39
|
const briefing = HELP + INSTRUCTIONS("https://example.test/session");
|
|
28
40
|
expect(briefing).not.toMatch(/\b(?:cart|shop|checkout|purchase)\b/i);
|
|
@@ -57,6 +69,96 @@ describe("askSeed", () => {
|
|
|
57
69
|
}
|
|
58
70
|
};
|
|
59
71
|
|
|
72
|
+
const entryPoints = [
|
|
73
|
+
{
|
|
74
|
+
id: "ticket-modal",
|
|
75
|
+
label: "Ticket reply modal",
|
|
76
|
+
description: "Draft a response without leaving the support ticket.",
|
|
77
|
+
entryPoint: {
|
|
78
|
+
formFactor: "modal",
|
|
79
|
+
placement: "Above the ticket detail page",
|
|
80
|
+
trigger: "Draft reply button in the ticket toolbar",
|
|
81
|
+
recommended: true,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
it("asks an entry-point question preserving contextual choices and exact default", () => {
|
|
87
|
+
expect(
|
|
88
|
+
parse([
|
|
89
|
+
"Where should support agents draft replies?",
|
|
90
|
+
"--entry-points",
|
|
91
|
+
JSON.stringify(entryPoints),
|
|
92
|
+
"--default",
|
|
93
|
+
"ticket-modal",
|
|
94
|
+
"--step",
|
|
95
|
+
"s1",
|
|
96
|
+
"--wait",
|
|
97
|
+
]),
|
|
98
|
+
).toEqual({
|
|
99
|
+
kind: "entry-point",
|
|
100
|
+
prompt: "Where should support agents draft replies?",
|
|
101
|
+
options: entryPoints,
|
|
102
|
+
default: "ticket-modal",
|
|
103
|
+
stepId: "s1",
|
|
104
|
+
optional: false,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("refuses malformed JSON, defaults and conflicting input flags", () => {
|
|
109
|
+
expect(withExit(() => parse(["Where?", "--entry-points", "{"]))).toContain(
|
|
110
|
+
"JSON array",
|
|
111
|
+
);
|
|
112
|
+
expect(withExit(() => parse(["Where?", "--entry-points"]))).toContain(
|
|
113
|
+
"JSON array",
|
|
114
|
+
);
|
|
115
|
+
expect(withExit(() => parse(["Where?", "--entry-points", "[]"]))).toContain(
|
|
116
|
+
"unique options",
|
|
117
|
+
);
|
|
118
|
+
expect(
|
|
119
|
+
withExit(() =>
|
|
120
|
+
parse([
|
|
121
|
+
"Where?",
|
|
122
|
+
"--entry-points",
|
|
123
|
+
JSON.stringify(entryPoints),
|
|
124
|
+
"--default",
|
|
125
|
+
"unknown",
|
|
126
|
+
]),
|
|
127
|
+
),
|
|
128
|
+
).toContain('no option "unknown"');
|
|
129
|
+
for (const flag of [
|
|
130
|
+
"--preset",
|
|
131
|
+
"--choices",
|
|
132
|
+
"--product",
|
|
133
|
+
"--multiple",
|
|
134
|
+
"--icons",
|
|
135
|
+
"--placeholder",
|
|
136
|
+
"--single",
|
|
137
|
+
"--only",
|
|
138
|
+
]) {
|
|
139
|
+
expect(
|
|
140
|
+
withExit(() =>
|
|
141
|
+
parse([
|
|
142
|
+
"Where?",
|
|
143
|
+
"--entry-points",
|
|
144
|
+
JSON.stringify(entryPoints),
|
|
145
|
+
flag,
|
|
146
|
+
"x",
|
|
147
|
+
]),
|
|
148
|
+
),
|
|
149
|
+
).toContain("cannot be combined");
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("keeps the legacy product command decoder", () => {
|
|
154
|
+
expect(parse(["Add it?", "--product", "assistant-ui"])).toEqual({
|
|
155
|
+
kind: "product",
|
|
156
|
+
prompt: "Add it?",
|
|
157
|
+
product: "assistant-ui",
|
|
158
|
+
optional: false,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
60
162
|
it("asks a multi-select choice with an icon on every option by default", () => {
|
|
61
163
|
expect(
|
|
62
164
|
parse([
|
|
@@ -400,6 +502,55 @@ describe("begin planning", () => {
|
|
|
400
502
|
);
|
|
401
503
|
});
|
|
402
504
|
|
|
505
|
+
describe("agent instructions", () => {
|
|
506
|
+
it("discovers related products and asks contextual entry points before the plan", () => {
|
|
507
|
+
const instructions = agentInstructions(
|
|
508
|
+
"http://localhost:18892/checkout/session",
|
|
509
|
+
);
|
|
510
|
+
expect(instructions).toContain(
|
|
511
|
+
"products are starting names and guide references",
|
|
512
|
+
);
|
|
513
|
+
expect(instructions).toContain(
|
|
514
|
+
"The starting list does not restrict the implementation",
|
|
515
|
+
);
|
|
516
|
+
expect(instructions).toContain("only 1–3 sensible alternatives");
|
|
517
|
+
expect(instructions).toContain(
|
|
518
|
+
"two options may use the same form factor in different places",
|
|
519
|
+
);
|
|
520
|
+
expect(instructions).toContain("--entry-points '<JSON array>'");
|
|
521
|
+
expect(instructions).not.toContain("--product assistant-ui");
|
|
522
|
+
expect(instructions.indexOf("--entry-points")).toBeLessThan(
|
|
523
|
+
instructions.indexOf("plan --file"),
|
|
524
|
+
);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it("waits for the entry-point answer before the plan is submitted", () => {
|
|
528
|
+
const ask = agentInstructions("http://localhost:18892/checkout/session")
|
|
529
|
+
.split("\n")
|
|
530
|
+
.find((line) => line.includes("--entry-points '<JSON array>'"));
|
|
531
|
+
expect(ask?.trim().endsWith("--wait")).toBe(true);
|
|
532
|
+
expect(ask).not.toContain("--default");
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("skips the entry-point question for a setup that puts no assistant in the app", () => {
|
|
536
|
+
const instructions = agentInstructions(
|
|
537
|
+
"http://localhost:18892/checkout/session",
|
|
538
|
+
);
|
|
539
|
+
expect(instructions).toContain(
|
|
540
|
+
"When the setup puts an assistant in the app, ask how users should access it",
|
|
541
|
+
);
|
|
542
|
+
expect(instructions).toContain(
|
|
543
|
+
"Skip this question when no product's guide installs an assistant",
|
|
544
|
+
);
|
|
545
|
+
expect(instructions).toContain(
|
|
546
|
+
"When you ask it, do not submit the plan before the user picks an entry point.",
|
|
547
|
+
);
|
|
548
|
+
expect(instructions).not.toContain(
|
|
549
|
+
"recommendation. Do not submit the plan before the user picks an entry point.",
|
|
550
|
+
);
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
|
|
403
554
|
describe("writeEnvSecret", () => {
|
|
404
555
|
const tempDir = async () => {
|
|
405
556
|
const dir = await mkdtemp(join(tmpdir(), "setup-agent-"));
|