create-curb 1.22.0-preview.1 → 1.22.0-preview.3
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 +17 -1
- package/RELEASE_NOTES.md +10 -0
- package/bin/create-curb.js +25 -5
- package/package.json +1 -1
- package/templates/booking/README.md +46 -0
- package/templates/booking/context/services.md +10 -0
- package/templates/booking/src/agent/agent.tsx +181 -0
- package/templates/booking/src/agent/calendar.ts +23 -0
- package/templates/booking/src/agent/services/skill.tsx +22 -0
- package/templates/support/README.md +46 -0
- package/templates/support/context/returns.md +9 -0
- package/templates/support/context/shipping.md +9 -0
- package/templates/support/src/agent/agent.tsx +159 -0
- package/templates/support/src/agent/returns/skill.tsx +23 -0
- package/templates/support/src/agent/shipping/skill.tsx +19 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<a href="https://www.apache.org/licenses/LICENSE-2.0"><img alt="License" src="https://img.shields.io/npm/l/create-curb.js.svg?style=for-the-badge&labelColor=000000"></a>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
`create-curb.js` creates a Curb voice agent in one command. You need Node.js 22.12 or newer.
|
|
11
|
+
`create-curb.js` creates a Curb voice agent in one command. You need Node.js 22.12 or newer, on Linux or macOS, or on Windows through WSL.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm create curb.js my-agent
|
|
@@ -41,6 +41,22 @@ npm create curb.js my-agent -- --llm anthropic --tts elevenlabs
|
|
|
41
41
|
|
|
42
42
|
`npm create curb.js -- --help` lists every option.
|
|
43
43
|
|
|
44
|
+
## Templates
|
|
45
|
+
|
|
46
|
+
The project starts as a demo assistant. `--template` starts it closer to what you build:
|
|
47
|
+
|
|
48
|
+
| Template | Starts as |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `default` | Juno, a personal assistant that shows how Curb works |
|
|
51
|
+
| `support` | Mara, customer support: order lookup, returns and shipping policies, tickets |
|
|
52
|
+
| `booking` | Lena, appointment booking: free slots, booking and cancelling, a price list |
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm create curb.js my-agent -- --template support
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The sample company, orders and calendar are made up: replace them with your own.
|
|
59
|
+
|
|
44
60
|
## Previews
|
|
45
61
|
|
|
46
62
|
To try the newest preview, create the project with `npm create curb.js@preview my-agent`.
|
package/RELEASE_NOTES.md
CHANGED
package/bin/create-curb.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// `npm create curb.js my-agent`: scaffolds a new agent project from templates/default
|
|
2
|
+
// `npm create curb.js my-agent`: scaffolds a new agent project from templates/default (or the
|
|
3
|
+
// template --template names), pinned
|
|
3
4
|
// to the curb.js release with this package's version, so `npm create curb.js@preview` gives a
|
|
4
5
|
// project on the matching preview. It asks nothing: the project runs on KugelAudio
|
|
5
6
|
// (LLM, speech-to-text, text-to-speech) unless flags pick other providers, and
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
readFileSync,
|
|
13
14
|
readdirSync,
|
|
14
15
|
renameSync,
|
|
16
|
+
rmSync,
|
|
15
17
|
statSync,
|
|
16
18
|
writeFileSync,
|
|
17
19
|
} from "node:fs";
|
|
@@ -42,6 +44,8 @@ Options:
|
|
|
42
44
|
--stt-model <id> STT model id (provider default otherwise)
|
|
43
45
|
--tts-model <id> TTS model id (provider default otherwise)
|
|
44
46
|
--llm-base-url <url> Endpoint for --llm openai-compatible
|
|
47
|
+
--template <name> default | support | booking (default default): Juno, a demo
|
|
48
|
+
assistant; Mara, customer support; Lena, appointment booking.
|
|
45
49
|
--framework <spec> Dependency spec for the "curb" package (a version or
|
|
46
50
|
file:/path). Defaults to the local framework checkout,
|
|
47
51
|
else the curb.js release that matches this package.
|
|
@@ -71,6 +75,7 @@ function fail(message) {
|
|
|
71
75
|
const args = scaffoldArgs(process.argv.slice(2));
|
|
72
76
|
let targetArg;
|
|
73
77
|
let frameworkSpec;
|
|
78
|
+
let template = "default";
|
|
74
79
|
let skipInstall = false;
|
|
75
80
|
let skipGit = false;
|
|
76
81
|
// Provider/model selections passed as flags.
|
|
@@ -84,7 +89,8 @@ for (let index = 0; index < args.length; index += 1) {
|
|
|
84
89
|
index += 1;
|
|
85
90
|
return value;
|
|
86
91
|
};
|
|
87
|
-
if (arg === "--
|
|
92
|
+
if (arg === "--template") template = takeValue("--template");
|
|
93
|
+
else if (arg === "--framework") frameworkSpec = takeValue("--framework");
|
|
88
94
|
else if (arg === "--stt") cli.stt = takeValue("--stt");
|
|
89
95
|
else if (arg === "--llm") cli.llm = takeValue("--llm");
|
|
90
96
|
else if (arg === "--tts") cli.tts = takeValue("--tts");
|
|
@@ -109,6 +115,12 @@ const targetDir = resolve(targetArg);
|
|
|
109
115
|
|
|
110
116
|
// Package dir of this CLI, used to find bundled templates.
|
|
111
117
|
const pkgDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
118
|
+
// templates/default is the whole project; every other template is only the part that differs
|
|
119
|
+
// (src/agent, context and README.md) and is laid over it, so the shared files exist once.
|
|
120
|
+
const templatesDir = join(pkgDir, "templates");
|
|
121
|
+
const DEFAULT_STARTER_SENTENCE = "The project starts as Juno, a demo assistant: replace\nher prompt, skills and tools with the user's agent";
|
|
122
|
+
const TEMPLATES = readdirSync(templatesDir).sort((a, b) => (a === "default" ? -1 : b === "default" ? 1 : a.localeCompare(b)));
|
|
123
|
+
if (!TEMPLATES.includes(template)) fail(`Invalid --template "${template}". Choose one of: ${TEMPLATES.join(", ")}.`);
|
|
112
124
|
// A repo checkout installs the sibling framework package; a published copy, curb.js from npm.
|
|
113
125
|
const localFramework = resolve(pkgDir, "../framework");
|
|
114
126
|
const repoCheckout = existsSync(join(localFramework, "package.json"));
|
|
@@ -305,10 +317,18 @@ seedKeysFromEnv();
|
|
|
305
317
|
const envValues = finalizeEnv();
|
|
306
318
|
|
|
307
319
|
// -------------------------------------------------------------- copy template
|
|
308
|
-
const templateDir = resolve(dirname(fileURLToPath(import.meta.url)), "../templates/default");
|
|
309
320
|
try {
|
|
310
321
|
mkdirSync(targetDir, { recursive: true });
|
|
311
|
-
cpSync(
|
|
322
|
+
cpSync(join(templatesDir, "default"), targetDir, { recursive: true });
|
|
323
|
+
if (template !== "default") {
|
|
324
|
+
for (const part of ["src/agent", "context"]) rmSync(join(targetDir, part), { recursive: true, force: true });
|
|
325
|
+
cpSync(join(templatesDir, template), targetDir, { recursive: true });
|
|
326
|
+
// AGENTS.md is shared; only its sentence about the starting agent depends on the template.
|
|
327
|
+
const guidePath = join(targetDir, "AGENTS.md");
|
|
328
|
+
const guide = readFileSync(guidePath, "utf8");
|
|
329
|
+
if (!guide.includes(DEFAULT_STARTER_SENTENCE)) fail("create-curb.js: templates/default/AGENTS.md lost the sentence this installer rewrites.");
|
|
330
|
+
writeFileSync(guidePath, guide.replace(DEFAULT_STARTER_SENTENCE, () => "The project starts as a demo agent (README.md names it): replace\nits prompt, skills and tools with the user's agent"));
|
|
331
|
+
}
|
|
312
332
|
} catch (error) {
|
|
313
333
|
fail(`Cannot create the project in ${targetDir} (${error.code ?? error.message}). Choose a directory you can write to.`);
|
|
314
334
|
}
|
|
@@ -354,7 +374,7 @@ const TEMPLATE_AGENT_TAG =
|
|
|
354
374
|
const agentPath = join(targetDir, "src/agent/agent.tsx");
|
|
355
375
|
const templateAgent = readFileSync(agentPath, "utf8");
|
|
356
376
|
if (!templateAgent.includes(TEMPLATE_PROVIDER_IMPORT) || !templateAgent.includes(TEMPLATE_AGENT_TAG)) {
|
|
357
|
-
fail(
|
|
377
|
+
fail(`create-curb.js: templates/${template}/src/agent/agent.tsx no longer has the provider lines this installer rewrites.`);
|
|
358
378
|
}
|
|
359
379
|
const providers = providerSource(answers);
|
|
360
380
|
writeFileSync(
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# {{APP_NAME}}
|
|
2
|
+
|
|
3
|
+
A voice agent built with **curb.js**: React renders the agent's prompt, knowledge and tools
|
|
4
|
+
instead of HTML. It starts as **Lena**, a booking agent for a made-up hair and beauty studio. The company, the sample data and the policies are
|
|
5
|
+
made up: replace them with your own.
|
|
6
|
+
|
|
7
|
+
## Run it
|
|
8
|
+
|
|
9
|
+
Sign in with `npx curb login`; there is no key to copy. Every curb command in this folder then
|
|
10
|
+
runs on your login. Prefer an API key (CI, a server)? Set `KUGELAUDIO_API_KEY` in `.env`.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx curb login # sign in in the browser; Curb uses your login
|
|
14
|
+
npm run dev # preview, chat and voice on http://127.0.0.1:4000
|
|
15
|
+
npx curb check # types, render and warnings
|
|
16
|
+
npx curb say "Hello" # one caller turn in the terminal, no browser
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Try it
|
|
20
|
+
|
|
21
|
+
- **"I'd like a haircut tomorrow."** Lena asks which time, checks `list_free_slots`, reads the booking back and only then calls `book_appointment`.
|
|
22
|
+
- **"How much is coloring?"** Lena opens the services skill, whose price list is `context/services.md`.
|
|
23
|
+
- **"Cancel my booking."** The `cancel_appointment` tool exists only once a booking exists.
|
|
24
|
+
|
|
25
|
+
## Where things live
|
|
26
|
+
|
|
27
|
+
- `src/agent/agent.tsx`: the agent, where every conversation starts: its providers
|
|
28
|
+
(`<Agent llm stt tts>`), system prompt, skills index, and its tools.
|
|
29
|
+
- `src/agent/<name>/skill.tsx`: one folder per skill, opened only when the conversation needs it.
|
|
30
|
+
- `context/`: markdown the skills read. Edit it and the agent's answers change live.
|
|
31
|
+
|
|
32
|
+
## Deploy to KugelAudio
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx curb login
|
|
36
|
+
npx curb secrets push
|
|
37
|
+
npx curb deploy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`deploy` prints the playground URL where you can call the live agent. Your `.env` is never
|
|
41
|
+
uploaded; `secrets push` sends its values and prints only their names.
|
|
42
|
+
|
|
43
|
+
## Learn more
|
|
44
|
+
|
|
45
|
+
`AGENTS.md` briefs coding agents (and you) on the rules; `CLAUDE.md` imports it for Claude Code.
|
|
46
|
+
The full guide is in `node_modules/curb/docs/agent-guide/`.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Services and prices
|
|
2
|
+
|
|
3
|
+
Edit this file with your real services: Lena's answers hot-reload, no restart needed.
|
|
4
|
+
|
|
5
|
+
- **Haircut:** 45 minutes, 38 euros
|
|
6
|
+
- **Coloring:** 90 minutes, from 75 euros, depending on length
|
|
7
|
+
- **Styling:** 30 minutes, 25 euros
|
|
8
|
+
- **Manicure:** 40 minutes, 30 euros
|
|
9
|
+
|
|
10
|
+
Every appointment is booked as one hour, so there is time to arrive and settle in.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
GlobalTools,
|
|
4
|
+
Skill,
|
|
5
|
+
Skills,
|
|
6
|
+
SystemPrompt,
|
|
7
|
+
Text,
|
|
8
|
+
Tool,
|
|
9
|
+
createAgentStore,
|
|
10
|
+
defineAgent,
|
|
11
|
+
z,
|
|
12
|
+
} from "curb";
|
|
13
|
+
import { kugelaudio } from "curb/providers";
|
|
14
|
+
import { type Appointment, addAppointment, removeAppointment } from "./calendar.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Lena, the booking agent of Birch Street Studio, a made-up hair and beauty studio. This file is
|
|
18
|
+
* the agent level, where every call starts: her prompt, the calendar and its tools, and the
|
|
19
|
+
* skill she opens for questions about services. Replace the studio, the services in context/
|
|
20
|
+
* and the in-memory calendar with your own booking system; the shape (system prompt, skills
|
|
21
|
+
* index, tools, store) stays.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** Opening hours as plain numbers; the calendar is generated from today's date at runtime. */
|
|
25
|
+
const FIRST_HOUR = 9;
|
|
26
|
+
const LAST_HOUR = 16;
|
|
27
|
+
const SERVICES = ["haircut", "coloring", "styling", "manicure"] as const;
|
|
28
|
+
|
|
29
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
30
|
+
const hours = Array.from({ length: LAST_HOUR - FIRST_HOUR + 1 }, (_, i) => `${pad(FIRST_HOUR + i)}:00`);
|
|
31
|
+
|
|
32
|
+
/** The studio is closed on weekends: an ISO date (YYYY-MM-DD) is open on weekdays only. */
|
|
33
|
+
const isOpenDay = (date: string) => {
|
|
34
|
+
const day = new Date(`${date}T00:00:00Z`).getUTCDay();
|
|
35
|
+
return day !== 0 && day !== 6;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const useCalendar = createAgentStore<{
|
|
39
|
+
appointments: Appointment[];
|
|
40
|
+
nextNumber: number;
|
|
41
|
+
add: (appointment: Omit<Appointment, "id">) => Appointment;
|
|
42
|
+
cancel: (id: string) => boolean;
|
|
43
|
+
}>("lena", (set, get) => ({
|
|
44
|
+
appointments: [],
|
|
45
|
+
nextNumber: 1,
|
|
46
|
+
add: (appointment) => {
|
|
47
|
+
const { book, created } = addAppointment({ appointments: get().appointments, nextNumber: get().nextNumber }, appointment);
|
|
48
|
+
set({ appointments: book.appointments, nextNumber: book.nextNumber });
|
|
49
|
+
return created;
|
|
50
|
+
},
|
|
51
|
+
cancel: (id) => {
|
|
52
|
+
const { book, removed } = removeAppointment({ appointments: get().appointments, nextNumber: get().nextNumber }, id);
|
|
53
|
+
set({ appointments: book.appointments });
|
|
54
|
+
return removed;
|
|
55
|
+
},
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
const slotsSchema = z.object({
|
|
59
|
+
date: z.iso.date().describe("The day to check, as YYYY-MM-DD. Work it out from today's date in your context."),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const bookSchema = z.object({
|
|
63
|
+
service: z.enum(SERVICES).describe("The service the caller wants."),
|
|
64
|
+
date: z.iso.date().describe("The day, as YYYY-MM-DD."),
|
|
65
|
+
time: z.string().regex(/^\d{2}:00$/).describe("The start time on the hour, 24-hour HH:00, one of the free slots."),
|
|
66
|
+
name: z.string().min(1).describe("The caller's name, as they said it."),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const cancelSchema = z.object({
|
|
70
|
+
id: z.string().min(1).describe("The booking number from the list of bookings in your context, for example B-1."),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Lena's calendar, in her context from the first turn. A booking updates the store, the
|
|
75
|
+
* component re-renders, and the model's context changes. The cancel tool is structural: it does
|
|
76
|
+
* not exist for the model until at least one booking exists.
|
|
77
|
+
*/
|
|
78
|
+
function Calendar() {
|
|
79
|
+
const appointments = useCalendar((s) => s.appointments);
|
|
80
|
+
const add = useCalendar((s) => s.add);
|
|
81
|
+
const cancel = useCalendar((s) => s.cancel);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<Text>{`Opening hours: weekdays, ${hours[0]} to ${hours[hours.length - 1]} start times, one hour each. Closed on weekends.`}</Text>
|
|
86
|
+
<Text>
|
|
87
|
+
{appointments.length === 0
|
|
88
|
+
? "No bookings on this call."
|
|
89
|
+
: `Bookings on this call: ${appointments
|
|
90
|
+
.map((a) => `${a.id} ${a.name}, ${a.service}, ${a.date} ${a.time}`)
|
|
91
|
+
.join("; ")}.`}
|
|
92
|
+
</Text>
|
|
93
|
+
|
|
94
|
+
<GlobalTools>
|
|
95
|
+
<Tool
|
|
96
|
+
schema={slotsSchema}
|
|
97
|
+
name="list_free_slots"
|
|
98
|
+
description="List the free start times on a given day."
|
|
99
|
+
onSubmit={(input) => {
|
|
100
|
+
if (!isOpenDay(input.date)) return { ok: true, message: `Closed on ${input.date}: no free slots.` };
|
|
101
|
+
const taken = appointments.filter((a) => a.date === input.date).map((a) => a.time);
|
|
102
|
+
const free = hours.filter((time) => !taken.includes(time));
|
|
103
|
+
return { ok: true, message: free.length > 0 ? `Free on ${input.date}: ${free.join(", ")}.` : `Fully booked on ${input.date}.` };
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
<Tool
|
|
107
|
+
schema={bookSchema}
|
|
108
|
+
name="book_appointment"
|
|
109
|
+
description="Book an appointment in a free slot. Call it only after the caller confirmed service, day, time and name."
|
|
110
|
+
onSubmit={(input) => {
|
|
111
|
+
if (!isOpenDay(input.date) || !hours.includes(input.time)) {
|
|
112
|
+
return { ok: false, message: "That is outside opening hours. Offer another slot from list_free_slots." };
|
|
113
|
+
}
|
|
114
|
+
if (appointments.some((a) => a.date === input.date && a.time === input.time)) {
|
|
115
|
+
return { ok: false, message: "That slot is taken. Offer another slot from list_free_slots." };
|
|
116
|
+
}
|
|
117
|
+
const created = add(input);
|
|
118
|
+
return { ok: true, message: `Booked as ${created.id}. Read the day, time and booking number back to the caller.` };
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
{appointments.length > 0 ? (
|
|
122
|
+
<Tool
|
|
123
|
+
schema={cancelSchema}
|
|
124
|
+
name="cancel_appointment"
|
|
125
|
+
description="Cancel a booking from the list of bookings in your context, after the caller asked to cancel it."
|
|
126
|
+
onSubmit={(input) => {
|
|
127
|
+
if (!cancel(input.id)) return { ok: false, message: `No booking ${input.id}. Use a number from the list.` };
|
|
128
|
+
return { ok: true, message: `${input.id} is cancelled.` };
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
) : (
|
|
132
|
+
<Text>The cancel_appointment tool appears once a booking exists.</Text>
|
|
133
|
+
)}
|
|
134
|
+
</GlobalTools>
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function App() {
|
|
140
|
+
// The providers Lena talks through; their keys live in .env. She listens and speaks in
|
|
141
|
+
// English: another language sets `language` on both stt and tts, with a voice that speaks it.
|
|
142
|
+
return (
|
|
143
|
+
<Agent llm={kugelaudio.llm()} stt={kugelaudio.stt({ language: "en" })} tts={kugelaudio.tts()}>
|
|
144
|
+
<SystemPrompt>{`
|
|
145
|
+
You are Lena, the booking agent of Birch Street Studio, a hair and beauty studio.
|
|
146
|
+
|
|
147
|
+
You can:
|
|
148
|
+
- book an appointment for a haircut, coloring, styling or a manicure,
|
|
149
|
+
- cancel a booking made on this call,
|
|
150
|
+
- answer questions about the services and prices.
|
|
151
|
+
|
|
152
|
+
Slots exist only in list_free_slots, and a booking exists only after book_appointment answered: never name a free time you did not get from the tool, and never say something is booked before it answered. Before booking, read service, day, time and name back and wait for a yes.
|
|
153
|
+
|
|
154
|
+
Greet the caller as Lena from Birch Street Studio and tell them you are an AI assistant.
|
|
155
|
+
Ask what they would like to book. Be warm and brief: one or two sentences per reply, because the caller listens.
|
|
156
|
+
`}</SystemPrompt>
|
|
157
|
+
{/* Each link's routing description is the target skill's meta.description. */}
|
|
158
|
+
<Skills>
|
|
159
|
+
<Skill path="/services">Services and prices</Skill>
|
|
160
|
+
</Skills>
|
|
161
|
+
<Calendar />
|
|
162
|
+
</Agent>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export const agent = defineAgent({
|
|
167
|
+
app: App,
|
|
168
|
+
// Voice calls open with Lena's greeting; "user" waits for the caller instead.
|
|
169
|
+
firstTurn: "agent",
|
|
170
|
+
// The calendar works in UTC dates. Set the zone your studio is in, so "today" matches the caller.
|
|
171
|
+
// timeZone: "Europe/Berlin",
|
|
172
|
+
preview: {
|
|
173
|
+
suggestedPrompts: [
|
|
174
|
+
"I'd like a haircut tomorrow",
|
|
175
|
+
"What is free this week?",
|
|
176
|
+
"How much is coloring?",
|
|
177
|
+
"Cancel my booking",
|
|
178
|
+
],
|
|
179
|
+
chatPlaceholder: "What would you like to book?",
|
|
180
|
+
},
|
|
181
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The calendar's rules as plain functions, so they run without the framework. A booking number
|
|
3
|
+
* comes from a counter that only goes up: counting the list instead hands out a number twice
|
|
4
|
+
* after a cancellation, and one cancel would then remove both bookings.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type Appointment = { id: string; service: string; date: string; time: string; name: string };
|
|
8
|
+
export type Book = { appointments: Appointment[]; nextNumber: number };
|
|
9
|
+
|
|
10
|
+
export function addAppointment(book: Book, appointment: Omit<Appointment, "id">) {
|
|
11
|
+
const created = { ...appointment, id: `B-${book.nextNumber}` };
|
|
12
|
+
return {
|
|
13
|
+
book: { appointments: [...book.appointments, created], nextNumber: book.nextNumber + 1 },
|
|
14
|
+
created,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function removeAppointment(book: Book, id: string) {
|
|
19
|
+
return {
|
|
20
|
+
book: { ...book, appointments: book.appointments.filter((a) => a.id !== id) },
|
|
21
|
+
removed: book.appointments.some((a) => a.id === id),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Instruction, Text, type SkillMeta } from "curb";
|
|
2
|
+
|
|
3
|
+
export const meta: SkillMeta = {
|
|
4
|
+
title: "Services and prices",
|
|
5
|
+
description: "Use when the caller asks what the studio offers, how long a service takes or what it costs.",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A file-backed skill: the price list lives in context/services.md and reaches the model through
|
|
10
|
+
* <Text src>. Edit the markdown and Lena's answers change live, no restart needed.
|
|
11
|
+
*/
|
|
12
|
+
export default function Services() {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<Instruction>{`
|
|
16
|
+
Answer only from the list below. A service not on it is one the studio does not offer:
|
|
17
|
+
say so, and offer one that is. Prices are what the studio charges; do not add or discount.
|
|
18
|
+
`}</Instruction>
|
|
19
|
+
<Text src="services.md" />
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# {{APP_NAME}}
|
|
2
|
+
|
|
3
|
+
A voice agent built with **curb.js**: React renders the agent's prompt, knowledge and tools
|
|
4
|
+
instead of HTML. It starts as **Mara**, a customer support agent for a made-up online shop. The company, the sample data and the policies are
|
|
5
|
+
made up: replace them with your own.
|
|
6
|
+
|
|
7
|
+
## Run it
|
|
8
|
+
|
|
9
|
+
Sign in with `npx curb login`; there is no key to copy. Every curb command in this folder then
|
|
10
|
+
runs on your login. Prefer an API key (CI, a server)? Set `KUGELAUDIO_API_KEY` in `.env`.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx curb login # sign in in the browser; Curb uses your login
|
|
14
|
+
npm run dev # preview, chat and voice on http://127.0.0.1:4000
|
|
15
|
+
npx curb check # types, render and warnings
|
|
16
|
+
npx curb say "Hello" # one caller turn in the terminal, no browser
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Try it
|
|
20
|
+
|
|
21
|
+
- **"Where is order NW-1002?"** The `find_order` tool reads the order list and Mara answers from it.
|
|
22
|
+
- **"My backpack arrived damaged."** Mara opens the returns skill, whose policy is `context/returns.md`, and opens a ticket with `open_ticket`.
|
|
23
|
+
- **"I want to talk to a person."** The `hand_over_to_team` tool exists only once a ticket is open, so Mara cannot offer it before.
|
|
24
|
+
|
|
25
|
+
## Where things live
|
|
26
|
+
|
|
27
|
+
- `src/agent/agent.tsx`: the agent, where every conversation starts: its providers
|
|
28
|
+
(`<Agent llm stt tts>`), system prompt, skills index, and its tools.
|
|
29
|
+
- `src/agent/<name>/skill.tsx`: one folder per skill, opened only when the conversation needs it.
|
|
30
|
+
- `context/`: markdown the skills read. Edit it and the agent's answers change live.
|
|
31
|
+
|
|
32
|
+
## Deploy to KugelAudio
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx curb login
|
|
36
|
+
npx curb secrets push
|
|
37
|
+
npx curb deploy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`deploy` prints the playground URL where you can call the live agent. Your `.env` is never
|
|
41
|
+
uploaded; `secrets push` sends its values and prints only their names.
|
|
42
|
+
|
|
43
|
+
## Learn more
|
|
44
|
+
|
|
45
|
+
`AGENTS.md` briefs coding agents (and you) on the rules; `CLAUDE.md` imports it for Claude Code.
|
|
46
|
+
The full guide is in `node_modules/curb/docs/agent-guide/`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Returns and refunds
|
|
2
|
+
|
|
3
|
+
Edit this file with your real policy: Mara's answers hot-reload, no restart needed.
|
|
4
|
+
|
|
5
|
+
- Unused items can be returned within 30 days of delivery.
|
|
6
|
+
- Return shipping is free for damaged or wrong items, and paid by the customer otherwise.
|
|
7
|
+
- A refund goes back to the original payment method after the returned item arrives.
|
|
8
|
+
- Worn or washed items cannot be returned.
|
|
9
|
+
- An exchange is a return plus a new order.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Shipping and delivery
|
|
2
|
+
|
|
3
|
+
Edit this file with your real shipping terms: Mara's answers hot-reload, no restart needed.
|
|
4
|
+
|
|
5
|
+
- Orders are packed within one working day.
|
|
6
|
+
- Standard delivery takes three to five working days.
|
|
7
|
+
- Shipping is free above an order value of 50 euros, and costs 4.90 euros below it.
|
|
8
|
+
- A tracking link is sent by email when the parcel ships.
|
|
9
|
+
- A parcel that has not arrived ten working days after shipping counts as lost.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
GlobalTools,
|
|
4
|
+
Skill,
|
|
5
|
+
Skills,
|
|
6
|
+
SystemPrompt,
|
|
7
|
+
Text,
|
|
8
|
+
Tool,
|
|
9
|
+
createAgentStore,
|
|
10
|
+
defineAgent,
|
|
11
|
+
z,
|
|
12
|
+
} from "curb";
|
|
13
|
+
import { kugelaudio } from "curb/providers";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mara, the customer support agent of Northwind Outdoor, a made-up shop. This file is the agent
|
|
17
|
+
* level, where every call starts: her prompt, the order lookup, the ticket list and the skills
|
|
18
|
+
* she opens only when needed. Replace the shop, the sample orders and the policies in context/
|
|
19
|
+
* with your own; the shape (system prompt, skills index, tools, store) stays.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export type Order = { id: string; item: string; status: "packed" | "shipped" | "delivered"; carrier?: string };
|
|
23
|
+
export type Ticket = { id: string; category: string; summary: string; orderId?: string };
|
|
24
|
+
|
|
25
|
+
/** Sample orders. Replace this with a call to your shop's API inside the find_order tool. */
|
|
26
|
+
export const ORDERS: Order[] = [
|
|
27
|
+
{ id: "NW-1001", item: "Trail backpack, 35 liters", status: "delivered" },
|
|
28
|
+
{ id: "NW-1002", item: "Insulated bottle, two-pack", status: "shipped", carrier: "ParcelPost" },
|
|
29
|
+
{ id: "NW-1003", item: "Rain jacket, size M", status: "packed" },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export const useSupport = createAgentStore<{
|
|
33
|
+
tickets: Ticket[];
|
|
34
|
+
openTicket: (ticket: Omit<Ticket, "id">) => Ticket;
|
|
35
|
+
}>("mara", (set, get) => ({
|
|
36
|
+
tickets: [],
|
|
37
|
+
openTicket: (ticket) => {
|
|
38
|
+
const created = { ...ticket, id: `T-${get().tickets.length + 1}` };
|
|
39
|
+
set((state) => ({ tickets: [...state.tickets, created] }));
|
|
40
|
+
return created;
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const findOrderSchema = z.object({
|
|
45
|
+
orderId: z
|
|
46
|
+
.string()
|
|
47
|
+
.min(1)
|
|
48
|
+
.describe("The order number the caller read out, for example NW-1001. Ask for it if they have not said it."),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const openTicketSchema = z.object({
|
|
52
|
+
category: z.enum(["damaged", "missing", "return", "other"]).describe("What the caller's problem is about."),
|
|
53
|
+
summary: z.string().min(1).describe("One or two sentences a colleague can act on without calling back."),
|
|
54
|
+
orderId: z.string().optional().describe("The order the ticket is about, when the caller named one."),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Mara's tools, in her context from the first turn. find_order reads the order list; open_ticket
|
|
59
|
+
* writes to the store, so the ticket count in her context changes with it. The handover tool is
|
|
60
|
+
* structural: it does not exist for the model until a ticket is open, so no prompt can route
|
|
61
|
+
* around it.
|
|
62
|
+
*/
|
|
63
|
+
function SupportDesk() {
|
|
64
|
+
const tickets = useSupport((s) => s.tickets);
|
|
65
|
+
const openTicket = useSupport((s) => s.openTicket);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<Text>
|
|
70
|
+
{tickets.length === 0
|
|
71
|
+
? "No tickets opened on this call."
|
|
72
|
+
: `Tickets opened on this call: ${tickets.map((t) => `${t.id} (${t.category})`).join(", ")}.`}
|
|
73
|
+
</Text>
|
|
74
|
+
|
|
75
|
+
<GlobalTools>
|
|
76
|
+
<Tool
|
|
77
|
+
schema={findOrderSchema}
|
|
78
|
+
name="find_order"
|
|
79
|
+
description="Look up an order by its number and get its item and delivery status."
|
|
80
|
+
onSubmit={(input) => {
|
|
81
|
+
const order = ORDERS.find((o) => o.id.toLowerCase() === input.orderId.trim().toLowerCase());
|
|
82
|
+
if (!order) {
|
|
83
|
+
return { ok: false, message: `No order ${input.orderId}. Ask the caller to read the number again.` };
|
|
84
|
+
}
|
|
85
|
+
const carrier = order.carrier ? ` with ${order.carrier}` : "";
|
|
86
|
+
return { ok: true, message: `${order.id}: ${order.item}, ${order.status}${carrier}.` };
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
<Tool
|
|
90
|
+
schema={openTicketSchema}
|
|
91
|
+
name="open_ticket"
|
|
92
|
+
description="Open a support ticket for a problem you cannot solve on the call. A colleague follows up by email."
|
|
93
|
+
onSubmit={(input) => {
|
|
94
|
+
const ticket = openTicket(input);
|
|
95
|
+
return { ok: true, message: `Ticket ${ticket.id} opened. Tell the caller a colleague replies by email.` };
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
{tickets.length > 0 ? (
|
|
99
|
+
<Tool
|
|
100
|
+
name="hand_over_to_team"
|
|
101
|
+
description="Tell the caller a person will call back today about the latest ticket. Use it only when the caller asks for a person."
|
|
102
|
+
onSubmit={() => ({
|
|
103
|
+
ok: true,
|
|
104
|
+
message: `A callback is noted on ticket ${tickets[tickets.length - 1].id}. Say that the team calls back today.`,
|
|
105
|
+
})}
|
|
106
|
+
/>
|
|
107
|
+
) : (
|
|
108
|
+
<Text>The hand_over_to_team tool appears once a ticket is open.</Text>
|
|
109
|
+
)}
|
|
110
|
+
</GlobalTools>
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function App() {
|
|
116
|
+
// The providers Mara talks through; their keys live in .env. She listens and speaks in
|
|
117
|
+
// English: another language sets `language` on both stt and tts, with a voice that speaks it.
|
|
118
|
+
return (
|
|
119
|
+
<Agent llm={kugelaudio.llm()} stt={kugelaudio.stt({ language: "en" })} tts={kugelaudio.tts()}>
|
|
120
|
+
<SystemPrompt>{`
|
|
121
|
+
You are Mara, the phone support agent of Northwind Outdoor, an online shop for hiking gear.
|
|
122
|
+
|
|
123
|
+
You can:
|
|
124
|
+
- look up an order and tell the caller where it is,
|
|
125
|
+
- explain the return and shipping policies,
|
|
126
|
+
- open a support ticket when you cannot solve the problem on the call.
|
|
127
|
+
|
|
128
|
+
State an order's status only after find_order answered, and say a ticket is open only after open_ticket answered. Never promise a refund: refunds are decided by the team after the ticket.
|
|
129
|
+
|
|
130
|
+
Greet the caller as Mara from Northwind Outdoor and tell them you are an AI assistant.
|
|
131
|
+
Ask how you can help. Ask for the order number before anything that depends on an order.
|
|
132
|
+
Be warm and brief: one or two sentences per reply, because the caller listens.
|
|
133
|
+
`}</SystemPrompt>
|
|
134
|
+
{/* Each link's routing description is the target skill's meta.description. */}
|
|
135
|
+
<Skills>
|
|
136
|
+
<Skill path="/returns">Returns and refunds</Skill>
|
|
137
|
+
<Skill path="/shipping">Shipping and delivery</Skill>
|
|
138
|
+
</Skills>
|
|
139
|
+
<SupportDesk />
|
|
140
|
+
</Agent>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const agent = defineAgent({
|
|
145
|
+
app: App,
|
|
146
|
+
// Voice calls open with Mara's greeting; "user" waits for the caller instead.
|
|
147
|
+
firstTurn: "agent",
|
|
148
|
+
// Every turn tells the model today's date and time in this zone (default "UTC").
|
|
149
|
+
// timeZone: "Europe/Berlin",
|
|
150
|
+
preview: {
|
|
151
|
+
suggestedPrompts: [
|
|
152
|
+
"Where is order NW-1002?",
|
|
153
|
+
"My backpack arrived damaged",
|
|
154
|
+
"How do I return a jacket?",
|
|
155
|
+
"I want to talk to a person",
|
|
156
|
+
],
|
|
157
|
+
chatPlaceholder: "How can we help?",
|
|
158
|
+
},
|
|
159
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Instruction, Text, type SkillMeta } from "curb";
|
|
2
|
+
|
|
3
|
+
export const meta: SkillMeta = {
|
|
4
|
+
title: "Returns and refunds",
|
|
5
|
+
description: "Use when the caller asks about returning an item, a refund, an exchange or a damaged product.",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A file-backed skill: the policy lives in context/returns.md and reaches the model through
|
|
10
|
+
* <Text src>. Edit the markdown and Mara's answers change live, no restart needed.
|
|
11
|
+
*/
|
|
12
|
+
export default function Returns() {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<Instruction>{`
|
|
16
|
+
Answer only from the policy below. For a damaged or wrong item, ask for the order number,
|
|
17
|
+
look it up with find_order, then open a ticket with category "damaged" or "return".
|
|
18
|
+
Never promise a refund or a date: the team decides after the ticket.
|
|
19
|
+
`}</Instruction>
|
|
20
|
+
<Text src="returns.md" />
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Instruction, Text, type SkillMeta } from "curb";
|
|
2
|
+
|
|
3
|
+
export const meta: SkillMeta = {
|
|
4
|
+
title: "Shipping and delivery",
|
|
5
|
+
description: "Use when the caller asks where a parcel is, how long delivery takes or what shipping costs.",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export default function Shipping() {
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<Instruction>{`
|
|
12
|
+
For a specific parcel, ask for the order number and use find_order: the lookup is the
|
|
13
|
+
truth, the policy below is only for general questions. If an order is shipped but the
|
|
14
|
+
caller says it never arrived, open a ticket with category "missing".
|
|
15
|
+
`}</Instruction>
|
|
16
|
+
<Text src="shipping.md" />
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
19
|
+
}
|