setup-agent 0.0.8 → 0.1.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.
- package/README.md +31 -0
- package/dist/agents.d.ts +33 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +221 -0
- package/dist/agents.js.map +1 -0
- package/dist/browser.d.ts +40 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +91 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +38 -49
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +89 -180
- package/dist/cli.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +13 -0
- 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/needs.d.ts +62 -0
- package/dist/needs.d.ts.map +1 -0
- package/dist/needs.js +184 -0
- package/dist/needs.js.map +1 -0
- package/dist/protocol.d.ts +16 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +8 -1
- package/dist/protocol.js.map +1 -1
- package/dist/sdk.d.ts +48 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +97 -0
- package/dist/sdk.js.map +1 -0
- package/dist/stream.d.ts +93 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +184 -0
- package/dist/stream.js.map +1 -0
- package/package.json +16 -2
- package/src/agents.test.ts +137 -0
- package/src/agents.ts +243 -0
- package/src/browser.test.ts +192 -0
- package/src/browser.ts +146 -0
- package/src/cli.test.ts +78 -0
- package/src/cli.ts +189 -258
- package/src/host.test.ts +25 -0
- package/src/host.ts +7 -0
- package/src/index.ts +1 -0
- package/src/needs.test.ts +180 -0
- package/src/needs.ts +273 -0
- package/src/protocol.ts +17 -0
- package/src/sdk.test.ts +111 -0
- package/src/sdk.ts +145 -0
- package/src/stream.test.ts +223 -0
- package/src/stream.ts +314 -0
package/dist/needs.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { classifyChoiceAnswer, currentPlan, finishProposed, isClosed, isValidEntryPointAnswer, isValidModelAnswer, openInputs, parseModelAnswer, parseMultipleAnswer } from "./protocol.js";
|
|
2
|
+
// src/needs.ts
|
|
3
|
+
/** What the setup waits on the user for right now, oldest first. */
|
|
4
|
+
const pendingNeeds = (state) => {
|
|
5
|
+
if (state.createdAt === null || isClosed(state)) return [];
|
|
6
|
+
const needs = openInputs(state).map((input) => ({
|
|
7
|
+
id: input.id,
|
|
8
|
+
kind: "input",
|
|
9
|
+
input
|
|
10
|
+
}));
|
|
11
|
+
const plan = currentPlan(state);
|
|
12
|
+
if (plan?.status === "proposed") needs.push({
|
|
13
|
+
id: "plan",
|
|
14
|
+
kind: "plan",
|
|
15
|
+
plan
|
|
16
|
+
});
|
|
17
|
+
if (finishProposed(state) && !state.log.some((entry) => entry.role === "user" && entry.at > state.completion.proposedAt)) needs.push({
|
|
18
|
+
id: "finish",
|
|
19
|
+
kind: "finish",
|
|
20
|
+
completion: state.completion
|
|
21
|
+
});
|
|
22
|
+
return needs;
|
|
23
|
+
};
|
|
24
|
+
/** Tells one need from a later one with the same id, such as a new plan revision. */
|
|
25
|
+
const needKey = (need) => need.kind === "input" ? `input:${need.input.id}:${need.input.createdAt}` : need.kind === "plan" ? `plan:${need.plan.revision}:${need.plan.submittedAt}` : `finish:${need.completion.proposedAt}`;
|
|
26
|
+
/** Options as the ids an answer names: `<option>:<variant>` for an option with variants. */
|
|
27
|
+
const optionList = (input) => (input.options ?? []).flatMap((option) => {
|
|
28
|
+
const where = option.entryPoint ? ` (${option.entryPoint.formFactor}; ${option.entryPoint.placement}; ${option.entryPoint.trigger})` : "";
|
|
29
|
+
const description = `${option.description ?? ""}${where}`.trim();
|
|
30
|
+
const entry = (id, label) => ({
|
|
31
|
+
id,
|
|
32
|
+
label,
|
|
33
|
+
...description && { description }
|
|
34
|
+
});
|
|
35
|
+
return option.variants?.length ? option.variants.map((variant) => entry(`${option.id}:${variant.id}`, `${option.label} (${variant.label})`)) : [entry(option.id, option.label)];
|
|
36
|
+
});
|
|
37
|
+
const ANSWER_FORMATS = {
|
|
38
|
+
text: "the user's text, as one shell word",
|
|
39
|
+
product: "add or decline",
|
|
40
|
+
model: "<provider>:<model>, such as openai:gpt-5",
|
|
41
|
+
"entry-point": "one option id",
|
|
42
|
+
choice: "one option id, or the user's own text"
|
|
43
|
+
};
|
|
44
|
+
const terminalQuestion = (need) => {
|
|
45
|
+
if (need.kind === "plan") return {
|
|
46
|
+
question: "Approve the setup plan? Show the user the plan you proposed and ask whether to go ahead or what to change.",
|
|
47
|
+
options: [{
|
|
48
|
+
id: "approve",
|
|
49
|
+
label: "Approve the plan"
|
|
50
|
+
}, {
|
|
51
|
+
id: "revise",
|
|
52
|
+
label: "Ask for changes (pass --feedback)"
|
|
53
|
+
}],
|
|
54
|
+
answerFormat: "approve, or revise --feedback \"<what to change>\""
|
|
55
|
+
};
|
|
56
|
+
if (need.kind === "finish") return {
|
|
57
|
+
question: `Everything is installed${need.completion.preview ? ` and running at ${need.completion.preview}` : ""}. Close the setup, or keep going?`,
|
|
58
|
+
options: [{
|
|
59
|
+
id: "close",
|
|
60
|
+
label: "Close the setup"
|
|
61
|
+
}],
|
|
62
|
+
answerFormat: "close; if the user wants more, do it and run done again instead"
|
|
63
|
+
};
|
|
64
|
+
const { input } = need;
|
|
65
|
+
const options = input.kind === "product" ? [{
|
|
66
|
+
id: "add",
|
|
67
|
+
label: `Add ${input.product ?? "the product"}`
|
|
68
|
+
}, {
|
|
69
|
+
id: "decline",
|
|
70
|
+
label: "Leave it out"
|
|
71
|
+
}] : input.kind === "text" ? void 0 : optionList(input);
|
|
72
|
+
return {
|
|
73
|
+
question: `${input.prompt.trim() || "Your agent needs an answer."}${input.optional ? " (optional; --dismiss skips it)" : ""}${input.kind === "model" ? " The API key is not typed here: the user adds it to the project's env file themselves." : ""}`,
|
|
74
|
+
...options && { options },
|
|
75
|
+
...input.multiple && { multiple: true },
|
|
76
|
+
answerFormat: input.multiple ? "option ids separated by commas, or the user's own text" : ANSWER_FORMATS[input.kind]
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/** The question as one line: the prompt, then its options. */
|
|
80
|
+
const formatTerminalQuestion = ({ question, options, multiple }) => options ? `${question} Options${multiple ? ", any number" : ""}: ${options.map((option) => `${option.id} (${option.label}${option.description ? `: ${option.description}` : ""})`).join(", ")}.` : question;
|
|
81
|
+
const ids = (input) => optionList(input).map((option) => option.id).join(", ");
|
|
82
|
+
/** `value` as the wire answer `input` takes, or an error naming the shape it needs. */
|
|
83
|
+
const wireAnswer = (input, value) => {
|
|
84
|
+
const trimmed = value.trim();
|
|
85
|
+
if (input.kind === "model") {
|
|
86
|
+
const at = trimmed.indexOf(":");
|
|
87
|
+
const json = trimmed.startsWith("{") ? trimmed : JSON.stringify({
|
|
88
|
+
provider: trimmed.slice(0, at),
|
|
89
|
+
model: trimmed.slice(at + 1)
|
|
90
|
+
});
|
|
91
|
+
if (at <= 0 && !trimmed.startsWith("{")) throw new Error(`a model answer is "<provider>:<model>", such as openai:gpt-5`);
|
|
92
|
+
if (!isValidModelAnswer(input, json)) throw new Error(`a model answer names one of the providers: ${ids(input)}`);
|
|
93
|
+
return JSON.stringify(parseModelAnswer(json));
|
|
94
|
+
}
|
|
95
|
+
if (input.kind === "entry-point") {
|
|
96
|
+
if (!isValidEntryPointAnswer(input, trimmed)) throw new Error(`an entry-point answer is one of: ${ids(input)}`);
|
|
97
|
+
return trimmed;
|
|
98
|
+
}
|
|
99
|
+
if (input.kind === "choice") {
|
|
100
|
+
const answer = input.multiple && parseMultipleAnswer(trimmed) === void 0 ? JSON.stringify(trimmed.split(",").map((entry) => entry.trim()).filter(Boolean)) : trimmed;
|
|
101
|
+
if (classifyChoiceAnswer(input, answer) === "invalid") throw new Error(`"${value}" names an option without a valid variant; pick from: ${ids(input)}`);
|
|
102
|
+
return answer;
|
|
103
|
+
}
|
|
104
|
+
if (trimmed === "") throw new Error("an answer cannot be empty");
|
|
105
|
+
return value;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Answers a need from the agent's side, with what the user said in the
|
|
109
|
+
* agent's own conversation: an input, the plan (`approve` or `revise` with
|
|
110
|
+
* feedback) or the proposal to close (`close`).
|
|
111
|
+
*/
|
|
112
|
+
const answerNeed = async (client, id, value, options = {}) => {
|
|
113
|
+
const state = client.state;
|
|
114
|
+
if (state === void 0) throw new Error("the setup has no state");
|
|
115
|
+
const { commands } = client;
|
|
116
|
+
if (id === "plan") {
|
|
117
|
+
const plan = currentPlan(state);
|
|
118
|
+
if (plan === void 0) throw new Error("no plan has been proposed");
|
|
119
|
+
const feedback = options.feedback?.trim();
|
|
120
|
+
if (value !== "approve" && (value !== "revise" || !feedback)) throw new Error("answer the plan with approve, or revise --feedback \"<what to change>\"");
|
|
121
|
+
await commands["checkout/plan"]({
|
|
122
|
+
...state.id !== null && { id: state.id },
|
|
123
|
+
revision: plan.revision,
|
|
124
|
+
...value === "approve" ? { decision: "approve" } : {
|
|
125
|
+
decision: "revise",
|
|
126
|
+
feedback
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
ok: true,
|
|
131
|
+
id,
|
|
132
|
+
decision: value
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (id === "finish") {
|
|
136
|
+
if (!pendingNeeds(state).some((need) => need.id === "finish")) throw new Error("no proposal to close is waiting; finish the user's follow-up and run done again");
|
|
137
|
+
if (value !== "close") throw new Error("answer finish with close; if the user wants more, do it and run done again");
|
|
138
|
+
await commands["checkout/finish"]();
|
|
139
|
+
return {
|
|
140
|
+
ok: true,
|
|
141
|
+
id,
|
|
142
|
+
status: "done"
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const input = state.inputs.find((candidate) => candidate.id === id);
|
|
146
|
+
if (input === void 0) throw new Error(`no input "${id}"`);
|
|
147
|
+
if (input.status !== "open") throw new Error(`input "${id}" is already ${input.status}`);
|
|
148
|
+
if (options.dismiss && !input.optional) throw new Error(`input "${id}" is required; answer it instead`);
|
|
149
|
+
if (options.dismiss || input.kind === "product" && value === "decline") {
|
|
150
|
+
await commands["checkout/dismiss"]({ inputId: id });
|
|
151
|
+
return {
|
|
152
|
+
ok: true,
|
|
153
|
+
id,
|
|
154
|
+
status: "dismissed"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (value === void 0) throw new Error(`usage: answer ${id} <answer>`);
|
|
158
|
+
if (input.kind === "product") {
|
|
159
|
+
if (value !== "add") throw new Error("answer a product with add or decline");
|
|
160
|
+
const slug = input.product ?? "";
|
|
161
|
+
await commands["checkout/add-product"]({
|
|
162
|
+
inputId: id,
|
|
163
|
+
product: {
|
|
164
|
+
slug,
|
|
165
|
+
name: slug
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
const note = options.note?.trim();
|
|
170
|
+
await commands["checkout/answer"]({
|
|
171
|
+
inputId: id,
|
|
172
|
+
answer: wireAnswer(input, value),
|
|
173
|
+
...note && { note }
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
ok: true,
|
|
178
|
+
id,
|
|
179
|
+
status: "answered"
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
export { answerNeed, formatTerminalQuestion, needKey, pendingNeeds, terminalQuestion };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=needs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"needs.js","names":[],"sources":["../src/needs.ts"],"sourcesContent":["import type { CheckoutClient } from \"./client\";\nimport {\n classifyChoiceAnswer,\n currentPlan,\n finishProposed,\n isClosed,\n isValidEntryPointAnswer,\n isValidModelAnswer,\n parseModelAnswer,\n openInputs,\n parseMultipleAnswer,\n} from \"./protocol\";\nimport type { Checkout } from \"./protocol\";\n\n/**\n * Something the setup waits on the user for: an open question, a proposed\n * plan, or the agent's proposal to close. `id` is what `answer` takes: the\n * input id, `plan` or `finish`.\n */\nexport type SetupNeed =\n | { id: string; kind: \"input\"; input: Checkout.Input }\n | { id: \"plan\"; kind: \"plan\"; plan: Checkout.Plan }\n | { id: \"finish\"; kind: \"finish\"; completion: Checkout.Completion };\n\n/** What the setup waits on the user for right now, oldest first. */\nexport const pendingNeeds = (state: Checkout.State): SetupNeed[] => {\n if (state.createdAt === null || isClosed(state)) return [];\n const needs: SetupNeed[] = openInputs(state).map((input) => ({\n id: input.id,\n kind: \"input\",\n input,\n }));\n const plan = currentPlan(state);\n if (plan?.status === \"proposed\")\n needs.push({ id: \"plan\", kind: \"plan\", plan });\n // Any message after the proposal, acknowledged or not, means more work first.\n if (\n finishProposed(state) &&\n !state.log.some(\n (entry) =>\n entry.role === \"user\" && entry.at > state.completion!.proposedAt,\n )\n )\n needs.push({ id: \"finish\", kind: \"finish\", completion: state.completion! });\n return needs;\n};\n\n/** Tells one need from a later one with the same id, such as a new plan revision. */\nexport const needKey = (need: SetupNeed) =>\n need.kind === \"input\"\n ? `input:${need.input.id}:${need.input.createdAt}`\n : need.kind === \"plan\"\n ? `plan:${need.plan.revision}:${need.plan.submittedAt}`\n : `finish:${need.completion.proposedAt}`;\n\ntype NeedOption = { id: string; label: string; description?: string };\n\n/** A need as a question the agent can put to the user in its own conversation. */\nexport type TerminalQuestion = {\n question: string;\n options?: NeedOption[];\n multiple?: true;\n /** The shape of the answer, as the `answer` command takes it. */\n answerFormat: string;\n};\n\n/** Options as the ids an answer names: `<option>:<variant>` for an option with variants. */\nconst optionList = (input: Checkout.Input): NeedOption[] =>\n (input.options ?? []).flatMap((option) => {\n const where = option.entryPoint\n ? ` (${option.entryPoint.formFactor}; ${option.entryPoint.placement}; ${option.entryPoint.trigger})`\n : \"\";\n const description = `${option.description ?? \"\"}${where}`.trim();\n const entry = (id: string, label: string) => ({\n id,\n label,\n ...(description && { description }),\n });\n return option.variants?.length\n ? option.variants.map((variant) =>\n entry(\n `${option.id}:${variant.id}`,\n `${option.label} (${variant.label})`,\n ),\n )\n : [entry(option.id, option.label)];\n });\n\nconst ANSWER_FORMATS: Record<Checkout.InputKind, string> = {\n text: \"the user's text, as one shell word\",\n product: \"add or decline\",\n model: \"<provider>:<model>, such as openai:gpt-5\",\n \"entry-point\": \"one option id\",\n choice: \"one option id, or the user's own text\",\n};\n\nexport const terminalQuestion = (need: SetupNeed): TerminalQuestion => {\n if (need.kind === \"plan\")\n return {\n question:\n \"Approve the setup plan? Show the user the plan you proposed and ask whether to go ahead or what to change.\",\n options: [\n { id: \"approve\", label: \"Approve the plan\" },\n { id: \"revise\", label: \"Ask for changes (pass --feedback)\" },\n ],\n answerFormat: 'approve, or revise --feedback \"<what to change>\"',\n };\n if (need.kind === \"finish\")\n return {\n question: `Everything is installed${need.completion.preview ? ` and running at ${need.completion.preview}` : \"\"}. Close the setup, or keep going?`,\n options: [{ id: \"close\", label: \"Close the setup\" }],\n answerFormat:\n \"close; if the user wants more, do it and run done again instead\",\n };\n const { input } = need;\n const options =\n input.kind === \"product\"\n ? [\n { id: \"add\", label: `Add ${input.product ?? \"the product\"}` },\n { id: \"decline\", label: \"Leave it out\" },\n ]\n : input.kind === \"text\"\n ? undefined\n : optionList(input);\n return {\n question: `${input.prompt.trim() || \"Your agent needs an answer.\"}${input.optional ? \" (optional; --dismiss skips it)\" : \"\"}${input.kind === \"model\" ? \" The API key is not typed here: the user adds it to the project's env file themselves.\" : \"\"}`,\n ...(options && { options }),\n ...(input.multiple && { multiple: true as const }),\n answerFormat: input.multiple\n ? \"option ids separated by commas, or the user's own text\"\n : ANSWER_FORMATS[input.kind],\n };\n};\n\n/** The question as one line: the prompt, then its options. */\nexport const formatTerminalQuestion = ({\n question,\n options,\n multiple,\n}: TerminalQuestion) =>\n options\n ? `${question} Options${multiple ? \", any number\" : \"\"}: ${options\n .map(\n (option) =>\n `${option.id} (${option.label}${option.description ? `: ${option.description}` : \"\"})`,\n )\n .join(\", \")}.`\n : question;\n\nconst ids = (input: Checkout.Input) =>\n optionList(input)\n .map((option) => option.id)\n .join(\", \");\n\n/** `value` as the wire answer `input` takes, or an error naming the shape it needs. */\nconst wireAnswer = (input: Checkout.Input, value: string) => {\n const trimmed = value.trim();\n if (input.kind === \"model\") {\n const at = trimmed.indexOf(\":\");\n const json = trimmed.startsWith(\"{\")\n ? trimmed\n : JSON.stringify({\n provider: trimmed.slice(0, at),\n model: trimmed.slice(at + 1),\n });\n if (at <= 0 && !trimmed.startsWith(\"{\"))\n throw new Error(\n `a model answer is \"<provider>:<model>\", such as openai:gpt-5`,\n );\n if (!isValidModelAnswer(input, json))\n throw new Error(\n `a model answer names one of the providers: ${ids(input)}`,\n );\n // Only the documented fields; anything else (a key, say) never reaches the setup.\n return JSON.stringify(parseModelAnswer(json));\n }\n if (input.kind === \"entry-point\") {\n if (!isValidEntryPointAnswer(input, trimmed))\n throw new Error(`an entry-point answer is one of: ${ids(input)}`);\n return trimmed;\n }\n if (input.kind === \"choice\") {\n const answer =\n input.multiple && parseMultipleAnswer(trimmed) === undefined\n ? JSON.stringify(\n trimmed\n .split(\",\")\n .map((entry) => entry.trim())\n .filter(Boolean),\n )\n : trimmed;\n if (classifyChoiceAnswer(input, answer) === \"invalid\")\n throw new Error(\n `\"${value}\" names an option without a valid variant; pick from: ${ids(input)}`,\n );\n return answer;\n }\n if (trimmed === \"\") throw new Error(\"an answer cannot be empty\");\n return value;\n};\n\n/**\n * Answers a need from the agent's side, with what the user said in the\n * agent's own conversation: an input, the plan (`approve` or `revise` with\n * feedback) or the proposal to close (`close`).\n */\nexport const answerNeed = async (\n client: Pick<CheckoutClient, \"state\" | \"commands\">,\n id: string,\n value: string | undefined,\n options: { note?: string; feedback?: string; dismiss?: boolean } = {},\n) => {\n const state = client.state;\n if (state === undefined) throw new Error(\"the setup has no state\");\n const { commands } = client;\n if (id === \"plan\") {\n const plan = currentPlan(state);\n if (plan === undefined) throw new Error(\"no plan has been proposed\");\n const feedback = options.feedback?.trim();\n if (value !== \"approve\" && (value !== \"revise\" || !feedback))\n throw new Error(\n 'answer the plan with approve, or revise --feedback \"<what to change>\"',\n );\n await commands[\"checkout/plan\"]({\n ...(state.id !== null && { id: state.id }),\n revision: plan.revision,\n ...(value === \"approve\"\n ? { decision: \"approve\" as const }\n : { decision: \"revise\" as const, feedback: feedback! }),\n });\n return { ok: true, id, decision: value };\n }\n if (id === \"finish\") {\n if (!pendingNeeds(state).some((need) => need.id === \"finish\"))\n throw new Error(\n \"no proposal to close is waiting; finish the user's follow-up and run done again\",\n );\n if (value !== \"close\")\n throw new Error(\n \"answer finish with close; if the user wants more, do it and run done again\",\n );\n await commands[\"checkout/finish\"]();\n return { ok: true, id, status: \"done\" };\n }\n const input = state.inputs.find((candidate) => candidate.id === id);\n if (input === undefined) throw new Error(`no input \"${id}\"`);\n if (input.status !== \"open\")\n throw new Error(`input \"${id}\" is already ${input.status}`);\n if (options.dismiss && !input.optional)\n throw new Error(`input \"${id}\" is required; answer it instead`);\n if (options.dismiss || (input.kind === \"product\" && value === \"decline\")) {\n await commands[\"checkout/dismiss\"]({ inputId: id });\n return { ok: true, id, status: \"dismissed\" };\n }\n if (value === undefined) throw new Error(`usage: answer ${id} <answer>`);\n if (input.kind === \"product\") {\n if (value !== \"add\")\n throw new Error(\"answer a product with add or decline\");\n const slug = input.product ?? \"\";\n await commands[\"checkout/add-product\"]({\n inputId: id,\n product: { slug, name: slug },\n });\n } else {\n const note = options.note?.trim();\n await commands[\"checkout/answer\"]({\n inputId: id,\n answer: wireAnswer(input, value),\n ...(note && { note }),\n });\n }\n return { ok: true, id, status: \"answered\" };\n};\n"],"mappings":";;;AAyBA,MAAa,gBAAgB,UAAuC;CAClE,IAAI,MAAM,cAAc,QAAQ,SAAS,KAAK,GAAG,OAAO,CAAC;CACzD,MAAM,QAAqB,WAAW,KAAK,CAAC,CAAC,KAAK,WAAW;EAC3D,IAAI,MAAM;EACV,MAAM;EACN;CACF,EAAE;CACF,MAAM,OAAO,Y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T,QAAQ,WAAW,OAAO,KAAK;GAC/B,GAAI,QAAQ,EAAE,KAAK;EACrB,CAAC;CACH;CACA,OAAO;EAAE,IAAI;EAAM;EAAI,QAAQ;CAAW;AAC5C"}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -151,6 +151,15 @@ export declare namespace Checkout {
|
|
|
151
151
|
/** When the command was first run against this checkout, before the agent joined the stream. */
|
|
152
152
|
introducedAt: number | null;
|
|
153
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* The setup page in the user's browser, while one has joined the link.
|
|
156
|
+
* Absent on hosts older than browser presence.
|
|
157
|
+
*/
|
|
158
|
+
browser?: {
|
|
159
|
+
lastSeenAt: number | null;
|
|
160
|
+
/** False once the page said goodbye; heartbeats set it again. */
|
|
161
|
+
connected: boolean;
|
|
162
|
+
};
|
|
154
163
|
/** Every revision in order; the last one is current. */
|
|
155
164
|
plans: Plan[];
|
|
156
165
|
steps: Step[];
|
|
@@ -226,6 +235,10 @@ export declare namespace Checkout {
|
|
|
226
235
|
}) => void;
|
|
227
236
|
"agent/heartbeat": () => void;
|
|
228
237
|
"agent/bye": () => void;
|
|
238
|
+
/** The setup page is open and joined; sent every BROWSER_HEARTBEAT_MS. */
|
|
239
|
+
"browser/heartbeat": () => void;
|
|
240
|
+
/** The setup page is closing. */
|
|
241
|
+
"browser/bye": () => void;
|
|
229
242
|
"agent/plan": (params: {
|
|
230
243
|
markdown: string;
|
|
231
244
|
}) => {
|
|
@@ -262,6 +275,9 @@ export declare namespace Checkout {
|
|
|
262
275
|
}
|
|
263
276
|
export declare const AGENT_PRESENCE_MS = 15000;
|
|
264
277
|
export declare const AGENT_HEARTBEAT_MS = 5000;
|
|
278
|
+
/** A background tab's timers slow down, so a browser counts as present for longer than an agent. */
|
|
279
|
+
export declare const BROWSER_PRESENCE_MS = 20000;
|
|
280
|
+
export declare const BROWSER_HEARTBEAT_MS = 5000;
|
|
265
281
|
export declare const initialCheckoutState: () => Checkout.State;
|
|
266
282
|
export declare const isAgentPresent: (state: Checkout.State, now?: number) => boolean;
|
|
267
283
|
export declare const isClosed: (state: Checkout.State) => boolean;
|
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,KAAY,UAAU,GAClB,SAAS,GACT,QAAQ,GACR,MAAM,GACN,SAAS,GACT,SAAS,CAAC;IAEd,yEAAyE;IACzE,KAAY,IAAI,GAAG;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,UAAU,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,6DAA6D;QAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF,KAAY,OAAO,GAAG;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,8DAA8D;QAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF,KAAY,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;IAE5D;;;;OAIG;IACH,KAAY,SAAS,GACjB,MAAM,GACN,QAAQ,GACR,OAAO,GACP,SAAS,GACT,aAAa,CAAC;IAElB,KAAY,UAAU,GAAG;QACvB,UAAU,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;QAC9C,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IAEF,KAAY,gBAAgB,GAAG;QAC7B,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,UAAU,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MAAM,YAMvE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,QAAQ,CAAC,KAAK;;;CAKhD,CAAC"}
|
package/dist/protocol.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// src/protocol.ts
|
|
2
2
|
const AGENT_PRESENCE_MS = 15e3;
|
|
3
3
|
const AGENT_HEARTBEAT_MS = 5e3;
|
|
4
|
+
/** A background tab's timers slow down, so a browser counts as present for longer than an agent. */
|
|
5
|
+
const BROWSER_PRESENCE_MS = 2e4;
|
|
6
|
+
const BROWSER_HEARTBEAT_MS = 5e3;
|
|
4
7
|
const initialCheckoutState = () => ({
|
|
5
8
|
version: 2,
|
|
6
9
|
id: null,
|
|
@@ -15,6 +18,10 @@ const initialCheckoutState = () => ({
|
|
|
15
18
|
kind: null,
|
|
16
19
|
introducedAt: null
|
|
17
20
|
},
|
|
21
|
+
browser: {
|
|
22
|
+
lastSeenAt: null,
|
|
23
|
+
connected: false
|
|
24
|
+
},
|
|
18
25
|
plans: [],
|
|
19
26
|
steps: [],
|
|
20
27
|
inputs: [],
|
|
@@ -211,6 +218,6 @@ const stepProgress = (state) => ({
|
|
|
211
218
|
total: state.steps.length,
|
|
212
219
|
done: state.steps.filter((step) => step.status === "done" || step.status === "skipped").length
|
|
213
220
|
});
|
|
214
|
-
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isLoopbackHostname, isOptionIcon, isValidEntryPointAnswer, isValidEntryPointInput, isValidModelAnswer, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress };
|
|
221
|
+
export { AGENT_HEARTBEAT_MS, AGENT_PRESENCE_MS, BROWSER_HEARTBEAT_MS, BROWSER_PRESENCE_MS, OPTION_ICONS, classifyChoiceAnswer, currentPlan, finishProposed, followedUpSinceProposal, initialCheckoutState, isAgentPresent, isClosed, isLoopbackHostname, isOptionIcon, isValidEntryPointAnswer, isValidEntryPointInput, isValidModelAnswer, openInputs, parseChoiceAnswer, parseEntryPointOptions, parseModelAnswer, parseMultipleAnswer, parsePreviewUrl, planNeedsReview, stepProgress };
|
|
215
222
|
|
|
216
223
|
//# 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 =\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 redeemKeyHash?: string;\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 redeemKeyHash?: string;\n optional?: boolean;\n };\n\n export type PlanDecision = {\n /** The setup the browser reviewed; omitted by legacy clients. */\n id?: string;\n /** The plan revision the browser reviewed; omitted by legacy clients. */\n revision?: number;\n } & ({ decision: \"approve\" } | { 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 | \"stale-plan\"\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 return isLoopbackHostname(url.hostname) ? url : undefined;\n};\n\n/** True for a hostname that names this machine. */\nexport const isLoopbackHostname = (hostname: string) =>\n LOOPBACK_HOSTS.has(hostname) || hostname.endsWith(\".localhost\");\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":";AAoRA,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,CAAC,SAAS,KAAK,KAAK,MAAM,eAAe,KAAA;;AAG3C,MAAa,2BAA2B,UAA0B;CAChE,MAAM,aAAa,MAAM,YAAY;CACrC,OACE,eAAe,KAAA,KACf,MAAM,IAAI,MACP,UACC,MAAM,SAAS,UACf,MAAM,K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AQ;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 redeemKeyHash?: string;\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 /**\n * The setup page in the user's browser, while one has joined the link.\n * Absent on hosts older than browser presence.\n */\n browser?: {\n lastSeenAt: number | null;\n /** False once the page said goodbye; heartbeats set it again. */\n connected: boolean;\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 redeemKeyHash?: string;\n optional?: boolean;\n };\n\n export type PlanDecision = {\n /** The setup the browser reviewed; omitted by legacy clients. */\n id?: string;\n /** The plan revision the browser reviewed; omitted by legacy clients. */\n revision?: number;\n } & ({ decision: \"approve\" } | { 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 /** The setup page is open and joined; sent every BROWSER_HEARTBEAT_MS. */\n \"browser/heartbeat\": () => void;\n /** The setup page is closing. */\n \"browser/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 | \"stale-plan\"\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/** A background tab's timers slow down, so a browser counts as present for longer than an agent. */\nexport const BROWSER_PRESENCE_MS = 20_000;\nexport const BROWSER_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 browser: { lastSeenAt: null, connected: false },\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 return isLoopbackHostname(url.hostname) ? url : undefined;\n};\n\n/** True for a hostname that names this machine. */\nexport const isLoopbackHostname = (hostname: string) =>\n LOOPBACK_HOSTS.has(hostname) || hostname.endsWith(\".localhost\");\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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AS,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/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CheckoutClient } from "./client.js";
|
|
2
|
+
import type { Checkout } from "./protocol.js";
|
|
3
|
+
import type { FollowSetupOptions } from "./stream.js";
|
|
4
|
+
export type SetupSession = {
|
|
5
|
+
linkId: string;
|
|
6
|
+
setupId: string;
|
|
7
|
+
/** The URL every setup command takes. */
|
|
8
|
+
agentUrl: string;
|
|
9
|
+
/** The page the user follows the setup on. */
|
|
10
|
+
browserUrl: string;
|
|
11
|
+
products: Checkout.ProductSeed[];
|
|
12
|
+
};
|
|
13
|
+
export type RunAgentSetupOptions = {
|
|
14
|
+
/** The setup server, such as https://checkout.assistant-ui.com. */
|
|
15
|
+
server: string;
|
|
16
|
+
/** The setup app the browser opens, such as https://setup.assistant-ui.com. */
|
|
17
|
+
setupAppUrl: string;
|
|
18
|
+
products: Checkout.ProductSeed[];
|
|
19
|
+
/** How the agent invokes setup commands, before the URL: `npx assistant-ui@latest setup`. */
|
|
20
|
+
command: string;
|
|
21
|
+
/** What the product calls this, for the briefing's first line. */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** False for `--no-open`: the agent asks the user itself. */
|
|
24
|
+
canOpen?: boolean;
|
|
25
|
+
/** Opens the setup page; the default browser by default. */
|
|
26
|
+
open?: (url: string) => void;
|
|
27
|
+
/** Called once the session exists, before the briefing prints. */
|
|
28
|
+
onSession?: (session: SetupSession) => void;
|
|
29
|
+
write?: (text: string) => void;
|
|
30
|
+
env?: NodeJS.ProcessEnv;
|
|
31
|
+
connect?: (url: string) => Promise<CheckoutClient>;
|
|
32
|
+
stream?: Pick<FollowSetupOptions, "print" | "agent">;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* `<tool> setup` for a coding agent, in one call: opens a new link on the
|
|
36
|
+
* setup server, creates a setup there and starts planning, prints the
|
|
37
|
+
* briefing, then streams the setup and opens the browser only when it waits
|
|
38
|
+
* on the user. Resolves with the running stream; the caller stops it (on
|
|
39
|
+
* SIGINT, say) and disposes the client.
|
|
40
|
+
*/
|
|
41
|
+
export declare const runAgentSetup: (options: RunAgentSetupOptions) => Promise<{
|
|
42
|
+
session: SetupSession;
|
|
43
|
+
stream: {
|
|
44
|
+
stop: () => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
client: CheckoutClient;
|
|
47
|
+
}>;
|
|
48
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAiB;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAmB;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAiB;AAYnD,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;IACjC,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,kEAAkE;IAClE,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC5C,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACnD,MAAM,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;CACtD,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAU,SAAS,oBAAoB;;;;;;EA4ChE,CAAC"}
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { detectAgentKind } from "./agents.js";
|
|
2
|
+
import { connectCheckout } from "./client.js";
|
|
3
|
+
import { followSetup, setupPageUrl, shellWord } from "./stream.js";
|
|
4
|
+
import { agentInstructions } from "./cli.js";
|
|
5
|
+
import { randomInt } from "node:crypto";
|
|
6
|
+
// src/sdk.ts
|
|
7
|
+
/**
|
|
8
|
+
* `<tool> setup` for coding agents, for a CLI to embed. `runAgentSetup` is
|
|
9
|
+
* the whole command; route `<tool> setup <url> <step> ...` to
|
|
10
|
+
* `runSetupCommand` from `setup-agent/cli`. Node only.
|
|
11
|
+
*/
|
|
12
|
+
/** A random id in the alphabet and length the setup page uses for its own. */
|
|
13
|
+
const createSetupId = () => Array.from({ length: 12 }, () => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[randomInt(62)]).join("");
|
|
14
|
+
/** What the agent reads first in the output of a setup command that keeps running. */
|
|
15
|
+
const setupBriefing = (session, { command, name = "Setup", canOpen = true }) => {
|
|
16
|
+
const url = shellWord(session.agentUrl);
|
|
17
|
+
return `${name} is running. This command keeps running: it is the setup's stream.
|
|
18
|
+
|
|
19
|
+
1. Keep it running in the background until the setup ends. If you started it in the foreground, stop it and resume it in the background (Claude Code: Bash with run_in_background; Codex and other agents: add > "\${TMPDIR:-/tmp}/setup-${session.linkId}.log" 2>&1 & and read that file):
|
|
20
|
+
${command} ${url} stream${canOpen ? "" : " --no-open"}
|
|
21
|
+
2. Read its new output as it arrives. Each line after this briefing is a JSON array of events.
|
|
22
|
+
3. Run every other command in another shell: ${command} ${url} <command>.
|
|
23
|
+
4. ${canOpen ? "Setup opens the user's browser by itself when you ask the user something; do not open it yourself." : `Setup will not open a browser (--no-open). Give the user ${session.browserUrl} once, or ask in your own conversation.`} On an "input.needed" event, do what its message says; to answer from here, run its "answer" command with the user's reply.
|
|
24
|
+
|
|
25
|
+
${agentInstructions(session.agentUrl, {
|
|
26
|
+
command,
|
|
27
|
+
startedByAgent: {
|
|
28
|
+
browserUrl: session.browserUrl,
|
|
29
|
+
streaming: true,
|
|
30
|
+
opened: canOpen
|
|
31
|
+
}
|
|
32
|
+
})}
|
|
33
|
+
Setup page, if the user asks for it: ${session.browserUrl}
|
|
34
|
+
|
|
35
|
+
Current setup:
|
|
36
|
+
${JSON.stringify({
|
|
37
|
+
status: "planning",
|
|
38
|
+
products: session.products
|
|
39
|
+
})}
|
|
40
|
+
`;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* `<tool> setup` for a coding agent, in one call: opens a new link on the
|
|
44
|
+
* setup server, creates a setup there and starts planning, prints the
|
|
45
|
+
* briefing, then streams the setup and opens the browser only when it waits
|
|
46
|
+
* on the user. Resolves with the running stream; the caller stops it (on
|
|
47
|
+
* SIGINT, say) and disposes the client.
|
|
48
|
+
*/
|
|
49
|
+
const runAgentSetup = async (options) => {
|
|
50
|
+
const connect = options.connect ?? connectCheckout;
|
|
51
|
+
const linkId = createSetupId();
|
|
52
|
+
const setupId = createSetupId();
|
|
53
|
+
const agentUrl = `${options.server.replace(/\/$/, "")}/${linkId}`;
|
|
54
|
+
const client = await connect(agentUrl);
|
|
55
|
+
try {
|
|
56
|
+
const kind = detectAgentKind(options.env);
|
|
57
|
+
await client.commands["checkout/create"]({
|
|
58
|
+
id: setupId,
|
|
59
|
+
products: options.products
|
|
60
|
+
});
|
|
61
|
+
await client.commands["checkout/begin-plan"]();
|
|
62
|
+
await client.commands["agent/intro"]({ ...kind !== void 0 && { kind } });
|
|
63
|
+
const session = {
|
|
64
|
+
linkId,
|
|
65
|
+
setupId,
|
|
66
|
+
agentUrl,
|
|
67
|
+
browserUrl: setupPageUrl(options.setupAppUrl, linkId, setupId),
|
|
68
|
+
products: options.products
|
|
69
|
+
};
|
|
70
|
+
options.onSession?.(session);
|
|
71
|
+
(options.write ?? ((text) => process.stdout.write(text)))(setupBriefing(session, options));
|
|
72
|
+
return {
|
|
73
|
+
session,
|
|
74
|
+
stream: await followSetup(client, {
|
|
75
|
+
...options.stream,
|
|
76
|
+
agent: {
|
|
77
|
+
...kind !== void 0 && { kind },
|
|
78
|
+
...options.stream?.agent
|
|
79
|
+
},
|
|
80
|
+
browser: {
|
|
81
|
+
setupAppUrl: options.setupAppUrl,
|
|
82
|
+
linkId,
|
|
83
|
+
answerCommand: `${options.command} ${shellWord(agentUrl)} answer`,
|
|
84
|
+
...options.open && { open: options.open },
|
|
85
|
+
...options.canOpen !== void 0 && { canOpen: options.canOpen }
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
client
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
client.dispose();
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
export { runAgentSetup };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":[],"sources":["../src/sdk.ts"],"sourcesContent":["/**\n * `<tool> setup` for coding agents, for a CLI to embed. `runAgentSetup` is\n * the whole command; route `<tool> setup <url> <step> ...` to\n * `runSetupCommand` from `setup-agent/cli`. Node only.\n */\nimport { randomInt } from \"node:crypto\";\nimport { detectAgentKind } from \"./agents\";\nimport { agentInstructions } from \"./cli\";\nimport { connectCheckout } from \"./client\";\nimport type { CheckoutClient } from \"./client\";\nimport type { Checkout } from \"./protocol\";\nimport { followSetup, setupPageUrl, shellWord } from \"./stream\";\nimport type { FollowSetupOptions } from \"./stream\";\n\n/** A random id in the alphabet and length the setup page uses for its own. */\nconst createSetupId = () =>\n Array.from(\n { length: 12 },\n () =>\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"[\n randomInt(62)\n ]!,\n ).join(\"\");\n\nexport type SetupSession = {\n linkId: string;\n setupId: string;\n /** The URL every setup command takes. */\n agentUrl: string;\n /** The page the user follows the setup on. */\n browserUrl: string;\n products: Checkout.ProductSeed[];\n};\n\nexport type RunAgentSetupOptions = {\n /** The setup server, such as https://checkout.assistant-ui.com. */\n server: string;\n /** The setup app the browser opens, such as https://setup.assistant-ui.com. */\n setupAppUrl: string;\n products: Checkout.ProductSeed[];\n /** How the agent invokes setup commands, before the URL: `npx assistant-ui@latest setup`. */\n command: string;\n /** What the product calls this, for the briefing's first line. */\n name?: string;\n /** False for `--no-open`: the agent asks the user itself. */\n canOpen?: boolean;\n /** Opens the setup page; the default browser by default. */\n open?: (url: string) => void;\n /** Called once the session exists, before the briefing prints. */\n onSession?: (session: SetupSession) => void;\n write?: (text: string) => void;\n env?: NodeJS.ProcessEnv;\n connect?: (url: string) => Promise<CheckoutClient>;\n stream?: Pick<FollowSetupOptions, \"print\" | \"agent\">;\n};\n\n/** What the agent reads first in the output of a setup command that keeps running. */\nconst setupBriefing = (\n session: SetupSession,\n {\n command,\n name = \"Setup\",\n canOpen = true,\n }: Pick<RunAgentSetupOptions, \"command\" | \"name\" | \"canOpen\">,\n) => {\n const url = shellWord(session.agentUrl);\n return `${name} is running. This command keeps running: it is the setup's stream.\n\n1. Keep it running in the background until the setup ends. If you started it in the foreground, stop it and resume it in the background (Claude Code: Bash with run_in_background; Codex and other agents: add > \"\\${TMPDIR:-/tmp}/setup-${session.linkId}.log\" 2>&1 & and read that file):\n ${command} ${url} stream${canOpen ? \"\" : \" --no-open\"}\n2. Read its new output as it arrives. Each line after this briefing is a JSON array of events.\n3. Run every other command in another shell: ${command} ${url} <command>.\n4. ${\n canOpen\n ? \"Setup opens the user's browser by itself when you ask the user something; do not open it yourself.\"\n : `Setup will not open a browser (--no-open). Give the user ${session.browserUrl} once, or ask in your own conversation.`\n } On an \"input.needed\" event, do what its message says; to answer from here, run its \"answer\" command with the user's reply.\n\n${agentInstructions(session.agentUrl, {\n command,\n startedByAgent: {\n browserUrl: session.browserUrl,\n streaming: true,\n opened: canOpen,\n },\n})}\nSetup page, if the user asks for it: ${session.browserUrl}\n\nCurrent setup:\n${JSON.stringify({ status: \"planning\", products: session.products })}\n`;\n};\n\n/**\n * `<tool> setup` for a coding agent, in one call: opens a new link on the\n * setup server, creates a setup there and starts planning, prints the\n * briefing, then streams the setup and opens the browser only when it waits\n * on the user. Resolves with the running stream; the caller stops it (on\n * SIGINT, say) and disposes the client.\n */\nexport const runAgentSetup = async (options: RunAgentSetupOptions) => {\n const connect = options.connect ?? connectCheckout;\n const linkId = createSetupId();\n const setupId = createSetupId();\n const agentUrl = `${options.server.replace(/\\/$/, \"\")}/${linkId}`;\n const client = await connect(agentUrl);\n try {\n const kind = detectAgentKind(options.env);\n await client.commands[\"checkout/create\"]({\n id: setupId,\n products: options.products,\n });\n await client.commands[\"checkout/begin-plan\"]();\n // The agent shows as connected once the stream says hello with the cwd.\n await client.commands[\"agent/intro\"]({\n ...(kind !== undefined && { kind }),\n });\n const session: SetupSession = {\n linkId,\n setupId,\n agentUrl,\n browserUrl: setupPageUrl(options.setupAppUrl, linkId, setupId),\n products: options.products,\n };\n options.onSession?.(session);\n (options.write ?? ((text) => process.stdout.write(text)))(\n setupBriefing(session, options),\n );\n const stream = await followSetup(client, {\n ...options.stream,\n agent: { ...(kind !== undefined && { kind }), ...options.stream?.agent },\n browser: {\n setupAppUrl: options.setupAppUrl,\n linkId,\n answerCommand: `${options.command} ${shellWord(agentUrl)} answer`,\n ...(options.open && { open: options.open }),\n ...(options.canOpen !== undefined && { canOpen: options.canOpen }),\n },\n });\n return { session, stream, client };\n } catch (error) {\n client.dispose();\n throw error;\n }\n};\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,sBACJ,MAAM,KACJ,EAAE,QAAQ,GAAG,SAEX,iEACE,UAAU,EAAE,EAElB,CAAC,CAAC,KAAK,EAAE;;AAmCX,MAAM,iBACJ,SACA,EACE,SACA,OAAO,SACP,UAAU,WAET;CACH,MAAM,MAAM,UAAU,QAAQ,QAAQ;CACtC,OAAO,GAAG,KAAK;;2OAE0N,QAAQ,OAAO;IACtP,QAAQ,GAAG,IAAI,SAAS,UAAU,KAAK,aAAa;;+CAET,QAAQ,GAAG,IAAI;KAE1D,UACI,uGACA,4DAA4D,QAAQ,WAAW,yCACpF;;EAED,kBAAkB,QAAQ,UAAU;EACpC;EACA,gBAAgB;GACd,YAAY,QAAQ;GACpB,WAAW;GACX,QAAQ;EACV;CACF,CAAC,EAAE;uCACoC,QAAQ,WAAW;;;EAGxD,KAAK,UAAU;EAAE,QAAQ;EAAY,UAAU,QAAQ;CAAS,CAAC,EAAE;;AAErE;;;;;;;;AASA,MAAa,gBAAgB,OAAO,YAAkC;CACpE,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,SAAS,cAAc;CAC7B,MAAM,UAAU,cAAc;CAC9B,MAAM,WAAW,GAAG,QAAQ,OAAO,QAAQ,OAAO,EAAE,EAAE,GAAG;CACzD,MAAM,SAAS,MAAM,QAAQ,QAAQ;CACrC,IAAI;EACF,MAAM,OAAO,gBAAgB,QAAQ,GAAG;EACxC,MA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