wizards 0.2.47 → 0.2.49
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 +2 -1
- package/apps/runtime/dist/agents/{project-assistant.js → studio-assistant.js} +199 -69
- package/apps/runtime/dist/agents/website.js +25 -2
- package/apps/runtime/dist/app.js +2 -1
- package/apps/runtime/dist/apple/wizards-apple +0 -0
- package/apps/runtime/dist/assistant/browser.js +26 -0
- package/apps/runtime/dist/assistant/docs.js +158 -0
- package/apps/runtime/dist/assistant/knows.js +325 -0
- package/apps/runtime/dist/assistant/primer.js +26 -0
- package/apps/runtime/dist/authoring/guide.js +5 -0
- package/apps/runtime/dist/cli/status.js +1 -1
- package/apps/runtime/dist/connectors/plugin-connections.js +123 -29
- package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +40 -0
- package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +3132 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +3139 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
- package/apps/runtime/dist/db/schema.js +35 -0
- package/apps/runtime/dist/docs/dev/index.md +34 -0
- package/apps/runtime/dist/docs/dev/meta.json +7 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +70 -0
- package/apps/runtime/dist/docs/dev/plugins/events.md +86 -0
- package/apps/runtime/dist/docs/dev/plugins/examples.md +99 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +72 -0
- package/apps/runtime/dist/docs/dev/plugins/layout.md +88 -0
- package/apps/runtime/dist/docs/dev/plugins/meta.json +29 -0
- package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +59 -0
- package/apps/runtime/dist/docs/dev/plugins/quick-start.md +92 -0
- package/apps/runtime/dist/docs/dev/plugins/reference.md +298 -0
- package/apps/runtime/dist/docs/dev/plugins/reloading.md +75 -0
- package/apps/runtime/dist/docs/dev/plugins/routes.md +123 -0
- package/apps/runtime/dist/docs/dev/plugins/runners.md +184 -0
- package/apps/runtime/dist/docs/dev/plugins/server.md +191 -0
- package/apps/runtime/dist/docs/dev/plugins/shipping.md +98 -0
- package/apps/runtime/dist/docs/dev/plugins/space.md +260 -0
- package/apps/runtime/dist/docs/dev/plugins/starters.md +62 -0
- package/apps/runtime/dist/docs/dev/plugins/studio.md +261 -0
- package/apps/runtime/dist/docs/dev/plugins/styling.md +109 -0
- package/apps/runtime/dist/docs/dev/plugins/tables.md +102 -0
- package/apps/runtime/dist/docs/dev/plugins/tools.md +128 -0
- package/apps/runtime/dist/docs/meta.json +3 -0
- package/apps/runtime/dist/docs/user/ai-apps.md +99 -0
- package/apps/runtime/dist/docs/user/assistant.md +52 -0
- package/apps/runtime/dist/docs/user/build-a-wizard.md +79 -0
- package/apps/runtime/dist/docs/user/command-line.md +76 -0
- package/apps/runtime/dist/docs/user/connectors.md +80 -0
- package/apps/runtime/dist/docs/user/data.md +61 -0
- package/apps/runtime/dist/docs/user/first-start.md +42 -0
- package/apps/runtime/dist/docs/user/index.md +45 -0
- package/apps/runtime/dist/docs/user/install.md +76 -0
- package/apps/runtime/dist/docs/user/meta.json +30 -0
- package/apps/runtime/dist/docs/user/models.md +125 -0
- package/apps/runtime/dist/docs/user/plugins.md +61 -0
- package/apps/runtime/dist/docs/user/run.md +92 -0
- package/apps/runtime/dist/docs/user/server.md +50 -0
- package/apps/runtime/dist/docs/user/space.md +97 -0
- package/apps/runtime/dist/docs/user/steps.md +196 -0
- package/apps/runtime/dist/docs/user/test-and-share.md +216 -0
- package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
- package/apps/runtime/dist/docs/user/wordpress.md +103 -0
- package/apps/runtime/dist/engine/device.js +182 -0
- package/apps/runtime/dist/engine/events.js +3 -0
- package/apps/runtime/dist/engine/input.js +3 -0
- package/apps/runtime/dist/engine/prepare.js +1 -0
- package/apps/runtime/dist/engine/requirements.js +6 -109
- package/apps/runtime/dist/engine/runner.js +13 -5
- package/apps/runtime/dist/engine/steps.js +2 -1
- package/apps/runtime/dist/env.js +1 -1
- package/apps/runtime/dist/harness/apple.js +258 -0
- package/apps/runtime/dist/harness/model.js +3 -1
- package/apps/runtime/dist/manage.js +11 -0
- package/apps/runtime/dist/mcp/auth.js +3 -0
- package/apps/runtime/dist/mcp/scopes.js +11 -2
- package/apps/runtime/dist/media/transcribe.js +6 -1
- package/apps/runtime/dist/models.js +63 -9
- package/apps/runtime/dist/plugins/loader.js +2 -0
- package/apps/runtime/dist/routes/api.js +232 -1
- package/apps/runtime/dist/routes/plugins.js +6 -2
- package/apps/runtime/dist/routes/runs.js +65 -3
- package/apps/runtime/dist/routes/studio.js +130 -69
- package/apps/runtime/dist/services/api.js +244 -0
- package/apps/runtime/dist/services/assistant-chats.js +267 -0
- package/apps/runtime/dist/services/engenty-shapes.js +1 -1
- package/apps/runtime/dist/services/package.js +77 -9
- package/apps/runtime/dist/services/project-index.js +1 -1
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/site.js +262 -0
- package/apps/runtime/dist/services/space-origin.js +45 -2
- package/apps/web/dist/assets/AboutDialog-6CCpWqAl.js +1 -0
- package/apps/web/dist/assets/ChangelogDialog-ApswqjRk.js +1 -0
- package/apps/web/dist/assets/ChatView-D7N2QyGS.js +10 -0
- package/apps/web/dist/assets/EditorPage-CbtYQTWj.js +3 -0
- package/apps/web/dist/assets/FlowPreview-KTaelucs.js +1 -0
- package/apps/web/dist/assets/{Harness-zKMptCzB.js → Harness-_mD1Stm4.js} +2 -2
- package/apps/web/dist/assets/Marketplace-DKQ9j4OC.js +2 -0
- package/apps/web/dist/assets/NewWizardPage-CoCCRcoi.js +1 -0
- package/apps/web/dist/assets/ProjectPage-DDLh_qxi.js +2 -0
- package/apps/web/dist/assets/PublicRunner-Lpu-BY5w.js +1 -0
- package/apps/web/dist/assets/ReadOnly-ClY8xMQS.js +1 -0
- package/apps/web/dist/assets/RunDrawer-JXG5wZp7.js +4 -0
- package/apps/web/dist/assets/RunnerView-BlUSqfqB.js +1 -0
- package/apps/web/dist/assets/SettingsPage-V_E267hI.js +1 -0
- package/apps/web/dist/assets/SetupPage-Dvoze8cZ.js +1 -0
- package/apps/web/dist/assets/SharePage-DBcp_npb.js +1 -0
- package/apps/web/dist/assets/brand-CNF5NxD9.js +2 -0
- package/apps/web/dist/assets/changelog-CmZrNHwc.js +1 -0
- package/apps/web/dist/assets/circle-alert-r2qc1Vej.js +1 -0
- package/apps/web/dist/assets/engenty-eXZ-EAwd.js +1 -0
- package/apps/web/dist/assets/esm-DZeij_95.js +7 -0
- package/apps/web/dist/assets/{fluffy-engenty-D7rFrNcJ.js → fluffy-engenty-ClRou7yu.js} +1 -1
- package/apps/web/dist/assets/index-BbogBDv_.js +11 -0
- package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
- package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +1 -0
- package/apps/web/dist/assets/lock-N-C6-ZeG.js +1 -0
- package/apps/web/dist/assets/logo-C4V2_3Ar.js +1 -0
- package/apps/web/dist/assets/oss-credits-BQQX0kvk.js +1 -0
- package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +228 -0
- package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
- package/apps/web/dist/assets/session-Cpg5S8B3.js +1 -0
- package/apps/web/dist/assets/settings-menu-C7m2i7Sf.js +1 -0
- package/apps/web/dist/assets/ui-DKcggL84.js +133 -0
- package/apps/web/dist/assets/upload-D24SDj7W.js +1 -0
- package/apps/web/dist/assets/useMutation-DKyQXgyj.js +1 -0
- package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +1 -0
- package/apps/web/dist/assets/volume-2-C-Y7-S4b.js +1 -0
- package/apps/web/dist/embed.js +57 -8
- package/apps/web/dist/index.html +12 -16
- package/apps/web/dist/mcp/flow.html +435 -207
- package/modules/calls/dist/client.css +1 -1
- package/modules/sms/dist/client.css +1 -1
- package/modules/whatsapp/dist/client.css +1 -1
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +82 -7
- package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +58 -4
- package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +113 -0
- package/node_modules/@engenty-wizards/shared/dist/assistant.js +55 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +58 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
- package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +71 -0
- package/node_modules/@engenty-wizards/shared/dist/fit.js +381 -0
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
- package/package.json +1 -1
- package/apps/web/dist/assets/AboutDialog-t7bpiasT.js +0 -1
- package/apps/web/dist/assets/ChangelogDialog-B87yS6aN.js +0 -1
- package/apps/web/dist/assets/ChatView-Dm764bYy.js +0 -10
- package/apps/web/dist/assets/EditorPage-BG_Ue2iC.js +0 -3
- package/apps/web/dist/assets/FlowPreview-ChXfiMn_.js +0 -1
- package/apps/web/dist/assets/HomePage-BXSg5P5k.js +0 -1
- package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-C3NqEGmg.js +0 -1
- package/apps/web/dist/assets/ProjectPage-D6Fy7uTV.js +0 -2
- package/apps/web/dist/assets/PublicRunner-ChgJs0C9.js +0 -1
- package/apps/web/dist/assets/ReadOnly-C9P9aiU6.js +0 -1
- package/apps/web/dist/assets/RunDrawer-CvIKLphz.js +0 -4
- package/apps/web/dist/assets/RunnerView-Bmayop7s.js +0 -2
- package/apps/web/dist/assets/SettingsPage-QkwtRFoD.js +0 -1
- package/apps/web/dist/assets/SetupPage-B3IOQLO3.js +0 -1
- package/apps/web/dist/assets/SharePage-C3QEzicl.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-3IzIOlNz.js +0 -1
- package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
- package/apps/web/dist/assets/changelog-Du2gWzlN.js +0 -1
- package/apps/web/dist/assets/circle-alert-CPo3Naay.js +0 -1
- package/apps/web/dist/assets/definition-CQGiBQ4X.js +0 -56
- package/apps/web/dist/assets/engenty-Cm8yZLON.js +0 -1
- package/apps/web/dist/assets/esm-rJY59Ixx.js +0 -7
- package/apps/web/dist/assets/external-link-CpU8aJY2.js +0 -1
- package/apps/web/dist/assets/index-Cz6c1S5g.js +0 -78
- package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
- package/apps/web/dist/assets/jsx-runtime-D3jfb0Ew.js +0 -1
- package/apps/web/dist/assets/lock-C_WlXIQ0.js +0 -1
- package/apps/web/dist/assets/logo-C80CWCDM.js +0 -1
- package/apps/web/dist/assets/oss-credits-CIxnNZor.js +0 -1
- package/apps/web/dist/assets/react-dom-DenslgJm.js +0 -1
- package/apps/web/dist/assets/refresh-cw-Cli5WGnW.js +0 -1
- package/apps/web/dist/assets/session-miDEdw2c.js +0 -1
- package/apps/web/dist/assets/settings-menu-ROT8Lbbj.js +0 -1
- package/apps/web/dist/assets/sparkles-CP5H-O1E.js +0 -1
- package/apps/web/dist/assets/trash-DU-hZpV0.js +0 -1
- package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
- package/apps/web/dist/assets/upload-DMq5N6Fw.js +0 -1
- package/apps/web/dist/assets/useMutation-DKcIz55V.js +0 -1
- package/apps/web/dist/assets/volume-2-0SfkvOho.js +0 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { factKey, PROJECT_LIMITS } from "@engenty-wizards/shared/projects";
|
|
2
|
+
import { nanoid } from "nanoid";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { runStudioAssistant } from "../agents/studio-assistant.js";
|
|
5
|
+
import { canSpend } from "../credits/credits.js";
|
|
6
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
7
|
+
import { projectWritable, requireWritable } from "./access.js";
|
|
8
|
+
import { apiSpace, apiSpaceDetails } from "./api.js";
|
|
9
|
+
import { openChat, turnHistory } from "./assistant-chats.js";
|
|
10
|
+
import { mainLogoId } from "./brand.js";
|
|
11
|
+
import { ServiceError } from "./errors.js";
|
|
12
|
+
import { addProjectFile } from "./project-files.js";
|
|
13
|
+
import { brandColorSchema, ownedProject, updateProject } from "./projects.js";
|
|
14
|
+
import { listOrigin, putOriginPage, removeOrigin } from "./space-data.js";
|
|
15
|
+
/*
|
|
16
|
+
* A website reads itself into a space: the WordPress plugin sends what the site says about
|
|
17
|
+
* itself (name, tagline, logo, the theme's colours, contact details) and its pages as text. The
|
|
18
|
+
* pages go into Wissen under the origin `wordpress`, the empty details of the space are filled
|
|
19
|
+
* from what the site states, and the space assistant reads the rest (about, facts from the
|
|
20
|
+
* imprint) as it does when an admin gives it a website. It takes a minute: the call starts a job
|
|
21
|
+
* the client asks after.
|
|
22
|
+
*/
|
|
23
|
+
export const SITE_ORIGIN = "wordpress";
|
|
24
|
+
export const siteSchema = z.object({
|
|
25
|
+
spaceId: z.string().optional(),
|
|
26
|
+
url: z.string().url().max(500),
|
|
27
|
+
name: z.string().max(120).default(""),
|
|
28
|
+
tagline: z.string().max(500).default(""),
|
|
29
|
+
language: z.string().max(20).optional(),
|
|
30
|
+
/** Facts the site states plainly: e-mail, phone, the shop's address. */
|
|
31
|
+
facts: z
|
|
32
|
+
.array(z.object({ label: z.string().min(1).max(80), value: z.string().min(1).max(4000) }))
|
|
33
|
+
.max(40)
|
|
34
|
+
.default([]),
|
|
35
|
+
colors: z.array(brandColorSchema).max(PROJECT_LIMITS.colors).default([]),
|
|
36
|
+
logo: z
|
|
37
|
+
.object({
|
|
38
|
+
name: z.string().max(200),
|
|
39
|
+
mime: z.string().max(100),
|
|
40
|
+
/** Base64. */
|
|
41
|
+
data: z.string().max(4_000_000),
|
|
42
|
+
})
|
|
43
|
+
.nullish(),
|
|
44
|
+
pages: z
|
|
45
|
+
.array(z.object({
|
|
46
|
+
key: z.string().min(1).max(200),
|
|
47
|
+
title: z.string().max(300),
|
|
48
|
+
url: z.string().max(1000).optional(),
|
|
49
|
+
/** What the page is to the site: `imprint`, `contact`, `privacy`, `about`, `front`, `page`, `product`. */
|
|
50
|
+
role: z.string().max(40).optional(),
|
|
51
|
+
markdown: z.string().max(60_000),
|
|
52
|
+
}))
|
|
53
|
+
.max(60)
|
|
54
|
+
.default([]),
|
|
55
|
+
/** Let the space assistant fill in about and facts; false writes only what the site states. */
|
|
56
|
+
assist: z.boolean().default(true),
|
|
57
|
+
});
|
|
58
|
+
const jobs = new Map();
|
|
59
|
+
const KEEP_MS = 60 * 60 * 1000;
|
|
60
|
+
function forget() {
|
|
61
|
+
const old = Date.now() - KEEP_MS;
|
|
62
|
+
for (const [id, job] of jobs) {
|
|
63
|
+
if (job.startedAt < old) {
|
|
64
|
+
jobs.delete(id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** What the site states, written where the space has nothing yet; the admin's own stays. */
|
|
69
|
+
async function fillFromSite(userId, projectId, input) {
|
|
70
|
+
const p = await ownedProject(userId, projectId);
|
|
71
|
+
const facts = [...p.facts];
|
|
72
|
+
for (const f of input.facts) {
|
|
73
|
+
const label = f.label.trim();
|
|
74
|
+
if (facts.some((x) => x.label.toLowerCase() === label.toLowerCase())) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (facts.length >= PROJECT_LIMITS.facts) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
facts.push({
|
|
81
|
+
key: factKey(label, facts.map((x) => x.key)),
|
|
82
|
+
label,
|
|
83
|
+
value: f.value.trim(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const website = facts.some((x) => /^(website|webseite)$/i.test(x.label));
|
|
87
|
+
if (!website && facts.length < PROJECT_LIMITS.facts) {
|
|
88
|
+
facts.push({
|
|
89
|
+
key: factKey("Website", facts.map((x) => x.key)),
|
|
90
|
+
label: "Website",
|
|
91
|
+
value: input.url,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
await updateProject(userId, projectId, {
|
|
95
|
+
brand: {
|
|
96
|
+
...(p.brand.name ? {} : input.name ? { name: input.name } : {}),
|
|
97
|
+
...(p.brand.about ? {} : input.tagline ? { about: input.tagline } : {}),
|
|
98
|
+
...(p.brand.colors?.length || !input.colors.length
|
|
99
|
+
? {}
|
|
100
|
+
: { colors: input.colors.map((c) => ({ ...c, value: c.value.toLowerCase() })) }),
|
|
101
|
+
},
|
|
102
|
+
facts,
|
|
103
|
+
});
|
|
104
|
+
if (input.logo && !(await mainLogoId(projectId))) {
|
|
105
|
+
await addProjectFile(projectId, {
|
|
106
|
+
kind: "logo",
|
|
107
|
+
name: input.logo.name,
|
|
108
|
+
mime: input.logo.mime,
|
|
109
|
+
data: new Uint8Array(Buffer.from(input.logo.data, "base64")),
|
|
110
|
+
description: `Logo von ${input.url}`,
|
|
111
|
+
source: input.url,
|
|
112
|
+
}).catch((err) => console.warn("[site] logo:", err.message));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The site's pages as Wissen: the same page again rewrites, a page gone from the site goes. */
|
|
116
|
+
async function writePages(projectId, input) {
|
|
117
|
+
const keys = new Set();
|
|
118
|
+
for (const page of input.pages) {
|
|
119
|
+
if (!page.markdown.trim()) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
keys.add(page.key);
|
|
123
|
+
await putOriginPage(SITE_ORIGIN, {
|
|
124
|
+
space: projectId,
|
|
125
|
+
key: page.key,
|
|
126
|
+
label: page.url ?? null,
|
|
127
|
+
title: page.title || page.url || "Seite",
|
|
128
|
+
markdown: page.url ? `Quelle: ${page.url}\n\n${page.markdown}` : page.markdown,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const item of await listOrigin(SITE_ORIGIN, projectId)) {
|
|
132
|
+
if (item.kind === "page" && !keys.has(item.key)) {
|
|
133
|
+
await removeOrigin(SITE_ORIGIN, projectId, item.key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return keys.size;
|
|
137
|
+
}
|
|
138
|
+
/** What the assistant gets: the site's own statements, and the pages that carry the details. */
|
|
139
|
+
function assistMessage(input) {
|
|
140
|
+
const telling = ["imprint", "contact", "about", "front"];
|
|
141
|
+
const pages = [...input.pages]
|
|
142
|
+
.sort((a, b) => {
|
|
143
|
+
const rank = (r) => (telling.includes(r ?? "") ? telling.indexOf(r ?? "") : 9);
|
|
144
|
+
return rank(a.role) - rank(b.role);
|
|
145
|
+
})
|
|
146
|
+
.slice(0, 6)
|
|
147
|
+
.map((p) => `## ${p.title}${p.url ? ` (${p.url})` : ""}${p.role ? ` [${p.role}]` : ""}\n\n${p.markdown.slice(0, 6000)}`);
|
|
148
|
+
return [
|
|
149
|
+
`Das ist die WordPress-Website ${input.url}. Fülle den Space aus dem, was sie über sich sagt: Titel, eine Beschreibung (about), Fakten (Adresse, Telefon, E-Mail, UID, Firmenbuch, Öffnungszeiten, wer sie betreibt) und die Farben, falls noch keine da sind. Ihre Seiten stehen schon in Wissen; schreib sie nicht ab.`,
|
|
150
|
+
"Die Angaben unten kommen direkt aus WordPress. Lies die Website mit read_website nur, wenn etwas Wichtiges fehlt. Erfinde nichts.",
|
|
151
|
+
`Name: ${input.name || "—"}\nUntertitel: ${input.tagline || "—"}\nSprache: ${input.language ?? "—"}`,
|
|
152
|
+
input.facts.length
|
|
153
|
+
? `Angaben der Website:\n${input.facts.map((f) => `- ${f.label}: ${f.value}`).join("\n")}`
|
|
154
|
+
: "",
|
|
155
|
+
input.colors.length
|
|
156
|
+
? `Farben des Themes: ${input.colors.map((c) => `${c.name} ${c.value}`).join(", ")}`
|
|
157
|
+
: "",
|
|
158
|
+
pages.length ? `Seiten:\n\n${pages.join("\n\n")}` : "",
|
|
159
|
+
]
|
|
160
|
+
.filter(Boolean)
|
|
161
|
+
.join("\n\n")
|
|
162
|
+
.slice(0, 7900);
|
|
163
|
+
}
|
|
164
|
+
async function work(job, projectId, input) {
|
|
165
|
+
try {
|
|
166
|
+
job.activity = "Übernimmt die Angaben der Website …";
|
|
167
|
+
await fillFromSite(job.userId, projectId, input);
|
|
168
|
+
job.activity = "Schreibt die Seiten in Wissen …";
|
|
169
|
+
job.pages = await writePages(projectId, input);
|
|
170
|
+
if (input.assist && (await canSpend())) {
|
|
171
|
+
job.activity = "Liest die Angaben …";
|
|
172
|
+
const project = await ownedProject(job.userId, projectId);
|
|
173
|
+
// The person's open assistant chat gives the context; the turn is not stored in it.
|
|
174
|
+
const chat = await openChat(job.user);
|
|
175
|
+
const result = await runStudioAssistant({
|
|
176
|
+
user: job.user,
|
|
177
|
+
chat,
|
|
178
|
+
history: await turnHistory(job.user, chat),
|
|
179
|
+
project,
|
|
180
|
+
writable: await projectWritable(project),
|
|
181
|
+
message: assistMessage(input),
|
|
182
|
+
page: null,
|
|
183
|
+
browserTools: [],
|
|
184
|
+
lang: input.language?.toLowerCase().startsWith("en") ? "en" : "de",
|
|
185
|
+
onActivity: (label) => {
|
|
186
|
+
job.activity = label;
|
|
187
|
+
},
|
|
188
|
+
// No studio page is open: the browser's tools are not offered.
|
|
189
|
+
callBrowser: async () => ({ error: "No page is open." }),
|
|
190
|
+
}).catch((err) => {
|
|
191
|
+
// What the site states is written; the assistant's part is a bonus.
|
|
192
|
+
console.warn("[site] assistant:", err.message);
|
|
193
|
+
return null;
|
|
194
|
+
});
|
|
195
|
+
job.reply = result?.reply ?? "";
|
|
196
|
+
}
|
|
197
|
+
job.space = await apiSpaceDetails(job.userId, projectId);
|
|
198
|
+
job.status = "done";
|
|
199
|
+
job.activity = "";
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
job.status = "failed";
|
|
203
|
+
job.error =
|
|
204
|
+
err instanceof ServiceError ? err.message : "Die Website ließ sich nicht übernehmen.";
|
|
205
|
+
console.error("[site]", err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Starts reading a website into the caller's space; answers at once with the job. Called inside
|
|
210
|
+
* the caller's tenant and role, which the job keeps.
|
|
211
|
+
*/
|
|
212
|
+
export async function startSiteJob(who, input) {
|
|
213
|
+
forget();
|
|
214
|
+
const { userId } = who;
|
|
215
|
+
const space = await apiSpace(userId, input.spaceId);
|
|
216
|
+
const running = [...jobs.values()].find((j) => j.tenantId === currentTenant() && j.status === "running");
|
|
217
|
+
if (running) {
|
|
218
|
+
return siteJobView(running);
|
|
219
|
+
}
|
|
220
|
+
// Refused here and not in the job: a space from a local install, or a plan that builds nothing.
|
|
221
|
+
await requireWritable(space);
|
|
222
|
+
const job = {
|
|
223
|
+
id: nanoid(12),
|
|
224
|
+
tenantId: currentTenant(),
|
|
225
|
+
userId,
|
|
226
|
+
user: {
|
|
227
|
+
id: userId,
|
|
228
|
+
tenantId: who.tenantId,
|
|
229
|
+
role: who.role,
|
|
230
|
+
name: who.name ?? "",
|
|
231
|
+
email: who.email ?? "",
|
|
232
|
+
},
|
|
233
|
+
status: "running",
|
|
234
|
+
activity: "Beginnt …",
|
|
235
|
+
startedAt: Date.now(),
|
|
236
|
+
pages: 0,
|
|
237
|
+
reply: "",
|
|
238
|
+
error: null,
|
|
239
|
+
space: null,
|
|
240
|
+
};
|
|
241
|
+
jobs.set(job.id, job);
|
|
242
|
+
void work(job, space.id, input);
|
|
243
|
+
return siteJobView(job);
|
|
244
|
+
}
|
|
245
|
+
function siteJobView(job) {
|
|
246
|
+
return {
|
|
247
|
+
id: job.id,
|
|
248
|
+
status: job.status,
|
|
249
|
+
activity: job.activity,
|
|
250
|
+
pages: job.pages,
|
|
251
|
+
reply: job.reply,
|
|
252
|
+
error: job.error,
|
|
253
|
+
space: job.space,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export function siteJob(jobId) {
|
|
257
|
+
const job = jobs.get(jobId);
|
|
258
|
+
if (!job || job.tenantId !== currentTenant()) {
|
|
259
|
+
throw new ServiceError("not_found", "Diesen Vorgang gibt es nicht (mehr).");
|
|
260
|
+
}
|
|
261
|
+
return siteJobView(job);
|
|
262
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { and, eq } from "drizzle-orm";
|
|
1
|
+
import { and, desc, eq, isNull } from "drizzle-orm";
|
|
2
2
|
import { db, schema } from "../db/client.js";
|
|
3
3
|
import { UnreadableDocument } from "../documents/parse.js";
|
|
4
4
|
import { ServiceError } from "./errors.js";
|
|
5
5
|
import { filePaths, pageTree, tablePaths } from "./knowledge.js";
|
|
6
6
|
import { convertDocument, fillCategories, summarizeValues } from "./knowledge-model.js";
|
|
7
|
-
import { putOriginFile } from "./project-files.js";
|
|
7
|
+
import { projectFileContent, putOriginFile } from "./project-files.js";
|
|
8
8
|
import { queueIndex } from "./project-index.js";
|
|
9
9
|
import { putCategory, setItemCategories } from "./space-categories.js";
|
|
10
10
|
import { listOrigin, putOriginPage, putOriginTable, removeOrigin } from "./space-data.js";
|
|
@@ -157,6 +157,49 @@ export function originData(origin) {
|
|
|
157
157
|
: null;
|
|
158
158
|
return { id, path, state: "written", items, review };
|
|
159
159
|
},
|
|
160
|
+
async readPages(space, opts) {
|
|
161
|
+
const tree = await pageTree(space);
|
|
162
|
+
const rows = await db.query.spacePage.findMany({
|
|
163
|
+
where: and(eq(schema.spacePage.projectId, space), isNull(schema.spacePage.wizardId), opts?.parent ? eq(schema.spacePage.parentId, opts.parent) : undefined),
|
|
164
|
+
orderBy: [schema.spacePage.position, schema.spacePage.title],
|
|
165
|
+
});
|
|
166
|
+
return rows.map((r) => ({
|
|
167
|
+
id: r.id,
|
|
168
|
+
title: r.title,
|
|
169
|
+
path: tree.get(r.id)?.path ?? `pages/${r.slug ?? r.id}`,
|
|
170
|
+
parentId: r.parentId,
|
|
171
|
+
markdown: r.markdown,
|
|
172
|
+
origin: r.origin,
|
|
173
|
+
originKey: r.originKey,
|
|
174
|
+
updatedAt: r.updatedAt.toISOString(),
|
|
175
|
+
}));
|
|
176
|
+
},
|
|
177
|
+
async files(space, kind = "document") {
|
|
178
|
+
const rows = await db.query.projectFile.findMany({
|
|
179
|
+
where: and(eq(schema.projectFile.projectId, space), eq(schema.projectFile.kind, kind), eq(schema.projectFile.status, "ready")),
|
|
180
|
+
orderBy: [desc(schema.projectFile.updatedAt)],
|
|
181
|
+
});
|
|
182
|
+
return rows.map((r) => ({
|
|
183
|
+
id: r.id,
|
|
184
|
+
name: r.name,
|
|
185
|
+
mime: r.mime,
|
|
186
|
+
size: r.size,
|
|
187
|
+
kind: r.kind,
|
|
188
|
+
updatedAt: r.updatedAt.toISOString(),
|
|
189
|
+
}));
|
|
190
|
+
},
|
|
191
|
+
async readFile(space, fileId) {
|
|
192
|
+
const { row, data } = await projectFileContent(space, fileId);
|
|
193
|
+
return {
|
|
194
|
+
id: row.id,
|
|
195
|
+
name: row.name,
|
|
196
|
+
mime: row.mime,
|
|
197
|
+
size: row.size,
|
|
198
|
+
kind: row.kind,
|
|
199
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
200
|
+
data: new Uint8Array(data),
|
|
201
|
+
};
|
|
202
|
+
},
|
|
160
203
|
list: (space) => listOrigin(origin, space),
|
|
161
204
|
remove: (space, key) => removeOrigin(origin, space, key),
|
|
162
205
|
summarize: (space, category, value) => summarizeValues(space, category, value),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{t as r}from"./logo-C4V2_3Ar.js";import{t as i}from"./preload-helper-CNEI7N0N.js";import{Ct as a,Gt as o,Mt as s,Tt as c,Wt as l,Yt as u,_t as d,ct as f,lt as p,mt as m,ot as h,rt as g,st as _,xt as v,yt as y}from"./ui-DKcggL84.js";import{$ as b,v as x}from"./index-BbogBDv_.js";import{c as S,f as C}from"./settings-menu-C7m2i7Sf.js";import{ReleaseNotes as w,loadReleases as T,releaseDate as E,releaseLabel as D}from"./ChangelogDialog-ApswqjRk.js";var O=e(t(),1),k=[{name:`engenty wizards`,description:{de:`KI-Wizards aus einer Beschreibung, mit einem Link geteilt.`,en:`AI wizards built from a description, shared with a link.`},homepage:`https://github.com/engenty/engenty-wizards`,license:`FSL-1.1-MIT`},{name:`engenty`,description:{de:`Konnektoren, Datentabellen, Suche und die Engenties stammen aus dem engenty-Framework.`,en:`Connectors, data tables, search and the engenties come from the engenty framework.`},homepage:`https://github.com/engenty/engenty`,license:`FSL-1.1-MIT`}],A=[{name:`Mastra`,description:{de:`Agent-Framework hinter den KI-Schritten.`,en:`Agent framework behind the AI steps.`},homepage:`https://github.com/mastra-ai/mastra`,license:`Apache-2.0`},{name:`AI SDK`,description:{de:`Modell-Aufrufe für Text, Bild, Video und Sprache.`,en:`Model calls for text, image, video and speech.`},homepage:`https://github.com/vercel/ai`,license:`Apache-2.0`},{name:`Model Context Protocol`,description:{de:`MCP-Server zum Bauen von Wizards, MCP-Client für Werkzeuge der Schritte.`,en:`MCP server for building wizards, MCP client for the steps' tools.`},homepage:`https://github.com/modelcontextprotocol/typescript-sdk`,license:`MIT`},{name:`Hono`,description:{de:`HTTP-API der Runtime.`,en:`The runtime's HTTP API.`},homepage:`https://github.com/honojs/hono`,license:`MIT`},{name:`Drizzle ORM`,description:{de:`Schema und Migrationen der Datenbanken.`,en:`Schema and migrations of the databases.`},homepage:`https://github.com/drizzle-team/drizzle-orm`,license:`Apache-2.0`},{name:`libSQL`,description:{de:`Eine Datenbank je Mandant, lokal als Datei oder bei Turso.`,en:`One database per tenant, a local file or at Turso.`},homepage:`https://github.com/tursodatabase/libsql`,license:`MIT`},{name:`Playwright`,description:{de:`Browser-Schritte sowie PDF- und PNG-Export.`,en:`Browser steps and the PDF and PNG export.`},homepage:`https://github.com/microsoft/playwright`,license:`Apache-2.0`},{name:`agentOS`,description:{de:`Sandbox für Code-Schritte ohne Docker.`,en:`Sandbox for code steps without Docker.`},homepage:`https://github.com/rivet-dev/agentos`,license:`Apache-2.0`},{name:`React`,description:{de:`UI-Bibliothek der Web-App.`,en:`UI library of the web app.`},homepage:`https://github.com/facebook/react`,license:`MIT`},{name:`Vite`,description:{de:`Build-Werkzeug der Web-App.`,en:`Build tool of the web app.`},homepage:`https://github.com/vitejs/vite`,license:`MIT`},{name:`Tailwind CSS`,description:{de:`Styling der Oberfläche.`,en:`Styling of the interface.`},homepage:`https://github.com/tailwindlabs/tailwindcss`,license:`MIT`},{name:`React Flow`,description:{de:`Das Diagramm der Schritte im Editor.`,en:`The diagram of steps in the editor.`},homepage:`https://github.com/xyflow/xyflow`,license:`MIT`},{name:`TanStack Query`,description:{de:`Server-Daten in der Web-App.`,en:`Server data in the web app.`},homepage:`https://github.com/TanStack/query`,license:`MIT`},{name:`xterm.js`,description:{de:`Das Terminal auf der Seite, in dem sich KI-Clients anmelden.`,en:`The terminal on the page where AI clients sign in.`},homepage:`https://github.com/xtermjs/xterm.js`,license:`MIT`},{name:`Lucide`,description:{de:`Icons.`,en:`Icons.`},homepage:`https://github.com/lucide-icons/lucide`,license:`ISC`},{name:`Geist & Geist Mono`,description:{de:`Schrift der Oberfläche.`,en:`Typeface of the interface.`},homepage:`https://github.com/vercel/geist-font`,license:`OFL-1.1`},{name:`Space Grotesk`,description:{de:`Schrift der Überschriften.`,en:`Typeface of the headings.`},homepage:`https://github.com/floriankarsten/space-grotesk`,license:`OFL-1.1`},{name:`git-cliff`,description:{de:`Erzeugt den Changelog aus den Commits.`,en:`Generates the changelog from the commits.`},homepage:`https://github.com/orhun/git-cliff`,license:`MIT OR Apache-2.0`}],j=e(n(),1),M=(e,...t)=>t.some(t=>t?.toLowerCase().includes(e));function N({name:e,homepage:t,version:n,license:r,description:i}){return(0,j.jsxs)(`li`,{className:`py-2.5`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2.5 gap-y-0.5`,children:[t?(0,j.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 font-medium text-[0.875rem] text-ink underline-offset-4 hover:underline`,children:[e,(0,j.jsx)(l,{"aria-hidden":!0,className:`size-3 text-ink-4`})]}):(0,j.jsx)(`span`,{className:`font-medium text-[0.875rem] text-ink`,children:e}),n?(0,j.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:n}):null,(0,j.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:r})]}),i?(0,j.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:i}):null]})}function P({title:e,hint:t,children:n}){return(0,j.jsxs)(`section`,{className:`mt-6`,children:[(0,j.jsx)(`h3`,{className:`border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:e}),t?(0,j.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-ink-3`,children:t}):null,n]})}function F({credits:e}){return(0,j.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:e.map(e=>(0,j.jsx)(N,{name:e.name,homepage:e.homepage,license:e.license,description:e.description[v]},e.name))})}function I({label:e,packages:t}){return(0,j.jsxs)(`div`,{className:`mt-4`,children:[(0,j.jsx)(`h4`,{className:`font-medium text-[0.75rem] text-ink-3 tracking-wide`,children:e}),(0,j.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:t.map(e=>(0,j.jsx)(N,{...e},e.name))})]})}function L({active:e}){let[t,n]=(0,O.useState)(null),[r,o]=(0,O.useState)(``);(0,O.useEffect)(()=>{if(!e||t)return;let r=!1;return i(()=>import(`./oss-credits-BQQX0kvk.js`).then(e=>{r||n(e.default)}),[]),()=>{r=!0}},[e,t]),(0,O.useEffect)(()=>{e||o(``)},[e]);let s=r.trim().toLowerCase(),c=e=>s?e.filter(e=>M(s,e.name,e.license,e.description.de,e.description.en)):e,l=e=>s?e.filter(e=>M(s,e.name,e.license,e.version)):e,u=c(k),d=c(A),f=t?[{id:`shared`,label:a(`about.creditsShared`),packages:l(t.shared)},...t.groups.map(e=>({id:e.id,label:e.label,packages:l(e.packages)}))].filter(e=>e.packages.length>0):[],h=u.length===0&&d.length===0&&f.length===0;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:`mb-4 text-[0.875rem] text-ink-3`,children:a(`about.creditsHint`)}),(0,j.jsx)(p,{type:`search`,value:r,placeholder:a(`about.search`),onChange:e=>o(e.target.value)}),u.length>0?(0,j.jsx)(P,{title:a(`about.creditsProduct`),children:(0,j.jsx)(F,{credits:u})}):null,d.length>0?(0,j.jsx)(P,{title:a(`about.creditsBuiltWith`),children:(0,j.jsx)(F,{credits:d})}):null,t===null?(0,j.jsx)(`div`,{className:`flex justify-center py-10 text-ink-3`,children:(0,j.jsx)(m,{})}):f.length>0?(0,j.jsx)(P,{title:a(`about.creditsDeps`),hint:s?void 0:a(`about.creditsDepsHint`),children:f.map(e=>(0,j.jsx)(I,{label:e.label,packages:e.packages},e.id))}):null,t!==null&&h?(0,j.jsx)(_,{children:a(`about.noMatches`)}):null]})}var R=[`new`,`earlier`,`credits`],z=e=>a(e===`new`?`about.tab.new`:e===`earlier`?`about.tab.earlier`:`about.credits`),B=e=>e===1?a(`about.change`):a(`about.changes`,{n:e});function V({open:e,onClose:t,me:n}){let i=n?.mode===`local`,{status:p,data:_,latest:v,check:k,apply:A,busy:M,progress:N}=x(i&&e),[P,F]=(0,O.useState)(null),[I,V]=(0,O.useState)(`new`),H=C(R.indexOf(I)),U=_?.newer&&v?v:b;(0,O.useEffect)(()=>{if(!e)return;let t=!1;return F(null),T(U===`0.2.49`?void 0:U).then(e=>{t||F(e)}),()=>{t=!0}},[e,U]);let W=P?.find(e=>e.version===`v${U}`)??P?.[0]??null,G=P?.filter(e=>e!==W)??[],K=i?_?.kind??null:`cloud`,q=_?.checkedAt?new Date(_.checkedAt).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):null;return(0,j.jsxs)(h,{open:e,onClose:t,wide:!0,height:`tall`,children:[(0,j.jsx)(`div`,{className:`-mt-2 -mr-2 sticky top-0 z-10 flex h-0 justify-end`,children:(0,j.jsx)(f,{label:a(`common.close`),onClick:t,children:(0,j.jsx)(c,{className:`size-4`})})}),(0,j.jsxs)(`div`,{className:`flex flex-col items-center pt-4 text-center`,children:[(0,j.jsx)(r,{size:96}),(0,j.jsxs)(`div`,{className:`mt-4 font-display font-semibold text-[1.5rem] tracking-tight`,children:[`engenty`,(0,j.jsx)(`span`,{className:`text-ember`,children:`.`}),(0,j.jsx)(`span`,{className:`ml-1.5 font-normal text-ink-3`,children:`wizards`})]}),(0,j.jsxs)(`div`,{className:`mt-1 text-[0.9375rem] text-ink-3 tabular-nums`,children:[a(`about.version`,{v:b}),K?` · ${a(`about.kind.${K}`)}`:``]})]}),i?(0,j.jsxs)(`div`,{className:`mt-5 flex flex-col items-center gap-3 text-center text-[0.875rem] text-ink-2`,children:[p.isPending||k.isPending?(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,j.jsx)(m,{className:`size-4 text-ember-strong`}),a(`about.update.checking`)]}):N?(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[M?(0,j.jsx)(m,{className:`size-4 text-ember-strong`}):null,N]}):_?.newer&&v?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5 font-medium text-ink`,children:[(0,j.jsx)(o,{className:`size-4 shrink-0 text-ember-strong`}),a(`about.update.available`,{v})]}),_.canApply?null:(0,j.jsx)(`p`,{className:`text-ink-3`,children:a(`about.update.manual`)})]}):_?.enabled?_.latest===null?(0,j.jsx)(`p`,{children:a(`about.update.unknown`)}):(0,j.jsxs)(`p`,{children:[a(`about.update.upToDate`),q?(0,j.jsxs)(`span`,{className:`text-ink-4`,children:[` `,`· `,a(`about.update.checkedAt`,{when:q})]}):null]}):(0,j.jsx)(`p`,{children:a(`about.update.off`)}),M||p.isPending?null:(0,j.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[_?.newer&&_.canApply&&_.applying!==`running`?(0,j.jsxs)(g,{size:`sm`,disabled:A.isPending,onClick:()=>A.mutate(),children:[(0,j.jsx)(o,{className:`size-4`}),` `,a(`about.update.install`)]}):null,_?.newer&&_.url?(0,j.jsxs)(g,{size:`sm`,variant:`secondary`,onClick:()=>window.open(_.url??``,`_blank`),children:[a(`about.update.release`),` `,(0,j.jsx)(l,{className:`size-4`})]}):null,_?.enabled===!1?null:(0,j.jsxs)(g,{size:`sm`,variant:`secondary`,disabled:k.isPending,onClick:()=>k.mutate(),children:[(0,j.jsx)(s,{className:y(`size-4`,k.isPending&&`animate-spin`)}),` `,a(`about.update.check`)]})]})]}):null,(0,j.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,j.jsx)(d,{value:I,onChange:V,options:R.map(e=>({id:e,label:z(e)})),label:a(`about.title`)})}),(0,j.jsxs)(`div`,{className:y(`mt-5`,S(H)),children:[I===`new`?P===null?(0,j.jsx)(`div`,{className:`flex justify-center py-6 text-ink-3`,children:(0,j.jsx)(m,{})}):W?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`h3`,{className:`flex items-baseline gap-3 border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:[D(W),(0,j.jsx)(`span`,{className:`font-normal font-sans text-[0.8125rem] text-ink-3 tabular-nums`,children:E(W)})]}),(0,j.jsx)(`div`,{className:`mt-3`,children:(0,j.jsx)(w,{release:W})})]}):(0,j.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:a(`about.changelogEmpty`)}):null,I===`earlier`?(0,j.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:G.map(e=>(0,j.jsxs)(`details`,{className:`group/r py-2`,children:[(0,j.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-baseline gap-3 text-[0.875rem] [&::-webkit-details-marker]:hidden`,children:[(0,j.jsx)(u,{className:`size-3.5 shrink-0 self-center text-ink-4 transition group-open/r:rotate-90`}),(0,j.jsx)(`span`,{className:`font-medium text-ink tabular-nums`,children:D(e)}),(0,j.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:E(e)}),(0,j.jsx)(`span`,{className:`ml-auto text-[0.8125rem] text-ink-4`,children:B(e.commits.length)})]}),(0,j.jsx)(`div`,{className:`mt-2 pl-6`,children:(0,j.jsx)(w,{release:e})})]},e.version??`unreleased`))}):null,I===`credits`?(0,j.jsx)(L,{active:!0}):null]},I)]})}export{V as AboutDialog};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{t as r}from"./preload-helper-CNEI7N0N.js";import{Ct as i,lt as a,mt as o,ot as s,st as c,yt as l}from"./ui-DKcggL84.js";var u=e(t(),1),d=e(n(),1);function f(e){switch(e.group){case`Added`:return{label:`NEW`,dot:`bg-moss`};case`Fixed`:return{label:`FIXED`,dot:`bg-amber`};case`Changed`:return{label:`CHANGED`,dot:`bg-cobalt`};case`Performance`:return{label:`PERFORMANCE`,dot:`bg-ember`};case`Deploy`:return{label:`DEPLOY`,dot:`bg-ink-4`};case`Docs`:return{label:`DOCS`,dot:`bg-ink-4`};default:return{label:`OTHER`,dot:`bg-ink-4`}}}var p=e=>e.version?e.version.replace(/^v/,``):i(`about.unreleased`),m=e=>e.timestamp?new Date(e.timestamp*1e3).toISOString().slice(0,10):``,h=e=>e.charAt(0).toUpperCase()+e.slice(1);function g(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=[];for(let t of e){if(`${p(t)} ${m(t)}`.toLowerCase().includes(n)){r.push(t);continue}let e=t.commits.filter(e=>`${f(e).label} ${e.scope??``} ${e.message}`.toLowerCase().includes(n));e.length>0&&r.push({...t,commits:e})}return r}async function _(e){if(e)try{let t=await fetch(`https://raw.githubusercontent.com/engenty/engenty-wizards/v${e}/apps/web/src/about/changelog.json`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return await t.json()}catch{}return(await r(async()=>{let{default:e}=await import(`./changelog-CmZrNHwc.js`);return{default:e}},[])).default}function v({release:e}){return(0,d.jsx)(`ul`,{className:`flex flex-col gap-2`,children:e.commits.map(e=>{let t=f(e);return(0,d.jsxs)(`li`,{className:`flex items-start gap-2.5 text-[0.875rem]`,children:[(0,d.jsx)(`span`,{className:l(`mt-[7px] size-1.5 shrink-0 rounded-full`,t.dot)}),(0,d.jsxs)(`span`,{className:`min-w-0 text-ink-2`,children:[(0,d.jsxs)(`span`,{className:`font-semibold text-[0.75rem] text-ink tracking-wide`,children:[t.label,e.scope?` [${e.scope}]`:``]}),` `,h(e.message),e.breaking?(0,d.jsx)(`span`,{className:`ml-1.5 rounded-full bg-rose-tint px-1.5 py-0.5 font-medium text-[0.75rem] text-rose`,children:i(`about.breaking`)}):null]})]},e.id)})})}function y({open:e,onClose:t,version:n}){let[r,l]=(0,u.useState)(null),[f,h]=(0,u.useState)(``);(0,u.useEffect)(()=>{if(!e||r)return;let t=!1;return _(n).then(e=>{t||l(e)}),()=>{t=!0}},[e,r,n]),(0,u.useEffect)(()=>{e||h(``)},[e]);let y=r?g(r,f):[];return(0,d.jsxs)(s,{open:e,onClose:t,title:i(`about.changelog`),wide:!0,height:`tall`,children:[(0,d.jsx)(`p`,{className:`-mt-3 mb-4 text-[0.875rem] text-ink-3`,children:i(`about.changelogHint`)}),r===null?(0,d.jsx)(`div`,{className:`flex justify-center py-10 text-ink-3`,children:(0,d.jsx)(o,{})}):r.length===0?(0,d.jsx)(c,{children:i(`about.changelogEmpty`)}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(a,{type:`search`,value:f,placeholder:i(`about.search`),onChange:e=>h(e.target.value)}),y.length===0?(0,d.jsx)(c,{children:i(`about.noMatches`)}):null,y.map(e=>(0,d.jsxs)(`section`,{className:`mt-6`,children:[(0,d.jsxs)(`h3`,{className:`flex items-baseline gap-3 border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:[p(e),(0,d.jsx)(`span`,{className:`font-normal font-sans text-[0.8125rem] text-ink-3 tabular-nums`,children:m(e)})]}),(0,d.jsx)(`div`,{className:`mt-3`,children:(0,d.jsx)(v,{release:e})})]},e.version??`unreleased`))]})]})}export{y as ChangelogDialog,v as ReleaseNotes,_ as loadReleases,m as releaseDate,p as releaseLabel};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,At as i,C as a,Ct as o,D as s,E as c,Et as l,H as u,J as d,Lt as f,N as p,Ot as m,Pt as h,Q as g,Qt as _,S as v,T as y,X as b,Z as x,a as S,b as C,bt as w,ct as T,dt as E,en as D,f as O,g as k,h as A,i as j,in as M,jt as N,kt as P,m as F,mt as I,vt as L,w as ee,xt as R,yt as z,zt as B}from"./ui-DKcggL84.js";import{r as te}from"./brand-CNF5NxD9.js";import{n as ne,r as re}from"./RunnerView-BlUSqfqB.js";import{t as ie}from"./volume-2-C-Y7-S4b.js";import{J as ae,X as oe,Y as se,at as ce,ft as le,nt as ue,t as de}from"./index-BbogBDv_.js";var fe={name:`hand`,size:24,node:[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]};fe.node;var pe=M(fe),me={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};me.node;var he=M(me),ge={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};ge.node;var V=M(ge),_e={name:`volume-x`,size:24,node:[[`path`,{d:`M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z`,key:`1p7khw`}],[`path`,{d:`m16.5 14.5 5-5`,key:`cul3yw`}],[`path`,{d:`m16.5 9.5 5 5`,key:`1akey5`}]]};_e.node;var ve=M(_e),ye=le(),H=e(t(),1),U=e(n(),1),be=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function xe({since:e}){let[t,n]=(0,H.useState)(Date.now());if((0,H.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),!e)return null;let r=Math.max(0,Math.floor((t-e)/1e3)),i=String(Math.floor(r/60)).padStart(2,`0`),a=String(r%60).padStart(2,`0`);return(0,U.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function W({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,U.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className:z(`flex size-12 items-center justify-center rounded-full transition disabled:opacity-50`,n?`bg-rose text-white hover:brightness-110`:t===!1?`bg-white text-neutral-900 hover:bg-white/90`:`bg-white/15 text-white hover:bg-white/25`),children:r?(0,U.jsx)(I,{className:`size-5`}):a})}function Se({voice:e}){let t=(0,H.useRef)(null),{captions:n}=e;return(0,H.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,U.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,U.jsx)(`li`,{className:z(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,U.jsx)(`div`,{ref:t})]})}):null}function Ce({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,a=e.state===`connecting`,[s,c]=(0,H.useState)(null),[u,d]=(0,H.useState)(!1);(0,H.useEffect)(()=>{c(i?Date.now():null)},[i]);let f=async()=>{d(!1),await e.start(),n&&await e.startCamera()},p=()=>{e.stop(),d(!0)},h=n||e.camera,g=[...e.captions].reverse().find(e=>e.who===`bot`),_=[...e.captions].reverse().find(e=>e.who===`me`),v=e.speaking?o(`talk.speaking`):e.listening?o(`talk.listening`):i?o(`talk.live`):a?o(`talk.connecting`):u?o(`video.ended`):``;return(0,U.jsxs)(`section`,{className:z(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,U.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),v?(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,U.jsx)(`span`,{className:z(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,v]}):null,(0,U.jsx)(xe,{since:s})]}),(0,U.jsxs)(`div`,{className:z(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,h?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!h&&i&&e.captions.length?`h-[38%]`:h?``:`flex-1`),children:[(0,U.jsxs)(`div`,{className:z(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!h&&`hidden`),children:[(0,U.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:z(`absolute inset-0 h-full w-full object-cover`,e.facing===`user`&&`-scale-x-100`,e.camera?`block`:`hidden`)}),e.camera?null:(0,U.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,U.jsx)(V,{className:`size-8`}),(0,U.jsx)(`span`,{className:`text-[0.8125rem]`,children:o(`video.cameraOff`)})]}),(0,U.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[o(`video.you`),e.muted?(0,U.jsx)(ce,{className:`ml-1.5 inline size-3`}):null]})]}),(0,U.jsxs)(`div`,{className:z(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,h?`bg-neutral-900`:`bg-transparent`,h&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,U.jsx)(`div`,{className:z(`rounded-full transition-shadow duration-500`,!h&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!h&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,U.jsx)(te,{kind:t?.wizard.avatar??`round`,size:h?140:200,fluffy:!0,interactive:!1})}),h?(0,U.jsx)(`span`,{className:`absolute bottom-2 left-3 max-w-[85%] truncate rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:t?.wizard.title??``}):null]})]}),i&&!h?(0,U.jsx)(Se,{voice:e}):i&&(g||_)?(0,U.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[_?(0,U.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:_.text}):null,g?(0,U.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:g.text}):null]})}):null,e.error?(0,U.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,U.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(W,{label:o(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,U.jsx)(ce,{className:`size-5`}):(0,U.jsx)(B,{className:`size-5`})}),(0,U.jsx)(W,{label:o(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,U.jsx)(l,{className:`size-5`}):(0,U.jsx)(V,{className:`size-5`})}),e.camera&&be?(0,U.jsx)(W,{label:o(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,U.jsx)(m,{className:`size-5`})}):null,(0,U.jsx)(W,{label:o(`video.leave`),danger:!0,onClick:p,children:(0,U.jsx)(ue,{className:`size-5`})})]}):(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:a||!t?.talk,onClick:()=>void f(),className:`flex h-12 items-center gap-2 rounded-full bg-emerald-500 px-6 font-medium text-[0.9375rem] text-white transition hover:brightness-110 disabled:opacity-50`,children:[a?(0,U.jsx)(I,{className:`size-4`}):n?(0,U.jsx)(l,{className:`size-5`}):(0,U.jsx)(B,{className:`size-5`}),o(u?`video.rejoin`:n?`video.join`:`talk.start`)]}),!u&&!e.error?(0,U.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:o(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var we=e=>p[e.kind]!==`device`,Te=1024,Ee=4e3;function De(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function Oe(e,t,n=!1){let r=[`status: ${e.status}`,`camera: ${n?`on`:`off`}`];if(e.ask)return r.push(e.ask.kind===`confirm`?`question: the step wants to "${e.ask.action.summary}" in ${e.ask.service}; answer_ask allows or skips it`:`question: a sign-in at ${e.ask.site.host}; the person types it on the screen, wait`),r.join(`
|
|
2
|
+
`);if(e.status===`running`){let t=[...e.events].reverse().find(e=>e.type===`tool`||e.type===`info`||e.type===`step_started`);return r.push(`working on: ${e.step?.title??``}`),t&&r.push(`doing: ${w(t)}`),r.join(`
|
|
3
|
+
`)}if(e.status===`done`){r.push(`done. made:`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.title}: ${De(n?.text,400)||`(a file, on the screen)`}`);return r.join(`
|
|
4
|
+
`)}if(e.status===`failed`)return r.push(`failed: ${e.error??``}; go_back or the person retries on the screen`),r.join(`
|
|
5
|
+
`);if(t){r.push(`page: ${t.step.title}`);for(let e of t.fields){let n=t.values[e.id],i=n!=null&&n!==``,a=we(e)?`by voice`:e.kind===`image`?`with the camera (take_photo) or on the screen`:`on the screen only`,o=e.options?.length?`; options: ${e.options.join(` | `)}`:``;r.push(`- field ${e.id} (${e.kind}${e.required?`, required`:``}, ${a}): ${e.label}${e.help?` – ${e.help}`:``}${o}${i?` = ${De(String(Array.isArray(n)?n.join(`, `):n),120)}`:` = (open)`}`)}return r.join(`
|
|
6
|
+
`)}if(e.step?.type===`review`){r.push(`review: ${e.step.title}`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.id} "${t.title}": ${De(n?.text,600)||`(a picture or file, on the screen)`}`);return r.push(`regenerate allowed: ${e.step.regenerate?`yes`:`no`}`),r.join(`
|
|
7
|
+
`)}return r.push(`step: ${e.step?.title??``}`),r.join(`
|
|
8
|
+
`)}function ke(e,t,n,r){let[i,a]=(0,H.useState)(`off`),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(!1),[h,g]=(0,H.useState)(`environment`),[_,v]=(0,H.useState)(!1),[y,b]=(0,H.useState)([]),x=(0,H.useRef)(null),C=(0,H.useRef)(null),w=(0,H.useRef)(0),T=(0,H.useRef)(!1);T.current=p;let E=(0,H.useRef)(null),D=(0,H.useRef)(null),O=(0,H.useRef)(null),k=(0,H.useRef)(null),A=(0,H.useRef)(t);A.current=t;let j=(0,H.useRef)(r);j.current=r;let M=(0,H.useRef)(n);M.current=n;let N=(0,H.useRef)(``),P=(0,H.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,H.useCallback)(()=>{let e=x.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,Te/e.videoWidth),n=document.createElement(`canvas`);return n.width=Math.round(e.videoWidth*t),n.height=Math.round(e.videoHeight*t),n.getContext(`2d`)?.drawImage(e,0,0,n.width,n.height),n.toDataURL(`image/jpeg`,.75)},[]),I=(0,H.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,x.current&&(x.current.srcObject=null),m(!1)},[]),L=(0,H.useCallback)(async e=>{if(C.current)return;let t=e??`environment`;try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:t},width:{ideal:1280}},audio:!1});C.current=e;let n=e.getVideoTracks()[0]?.getSettings().facingMode;g(n===`user`||n===`environment`?n:t),x.current&&(x.current.srcObject=e,await x.current.play().catch(()=>void 0)),m(!0)}catch(e){c(e.name===`NotAllowedError`?o(`talk.cameraDenied`):e.message)}},[]),ee=(0,H.useCallback)(async()=>{let e=h===`user`?`environment`:`user`;I(),await L(e)},[h,I,L]),R=(0,H.useCallback)(()=>{v(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,H.useCallback)(()=>{I(),D.current?.close(),D.current=null,E.current?.close(),E.current=null;for(let e of k.current?.getTracks()??[])e.stop();k.current=null,O.current&&=(O.current.srcObject=null,O.current.remove(),null),N.current=``,u(!1),f(!1),v(!1),a(`off`)},[I]);(0,H.useEffect)(()=>()=>z(),[z]);let B=(0,H.useCallback)(async(t,n)=>{let r=A.current,i=j.current,a=M.current;switch(t){case`get_state`:return r?Oe(r,i,T.current):`no run`;case`look`:{let e=F();return e?(P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows right now`},{type:`input_image`,image_url:e}]}}),`a picture arrived as the next message`):`the camera is off; ask the person to switch it on`}case`take_photo`:{if(!i)return`no page is open`;let t=i.fields.find(e=>e.id===String(n.field??``));if(t?.kind!==`image`)return`no such photo field on this page`;let r=F();if(!r)return`the camera is off; ask the person to switch it on`;try{let n=await(await fetch(r)).blob(),a=new File([n],`photo-${Date.now()}.jpg`,{type:`image/jpeg`}),o=await S.upload(`/api/runs/${e}/uploads`,a),s=i.values[t.id],c=t.multiple?[...Array.isArray(s)?s:s?[s]:[],o.id]:o.id,l=i.setField(t.id,c);return l?`refused: ${l}`:`the photo is in the field`}catch(e){return`failed: ${e.message}`}}case`set_field`:{if(!i)return`no page is open`;let e=i.setField(String(n.field??``),n.value);return e?`refused: ${e}`:`kept`}case`submit_page`:{if(!i)return`no page is open`;let e=i.fields.filter(e=>e.required&&we(e)&&e.kind!==`toggle`&&(i.values[e.id]===void 0||i.values[e.id]===null||i.values[e.id]===``));return e.length?`still open: ${e.map(e=>e.id).join(`, `)}`:(i.submit(),`sent; wait for the next state`)}case`accept_review`:return r?.step?.type===`review`?await a.accept(r.step.id)?`accepted`:a.error??`refused`:`no review is open`;case`regenerate`:return r?.step?.type===`review`?await a.regenerate(r.step.id,String(n.target??``),String(n.note??``))?`the wizard makes it again; wait`:a.error??`refused`:`no review is open`;case`answer_ask`:if(!r?.ask)return`no question is open`;try{return await S.post(`/api/runs/${e}/ask/${r.ask.id}`,{type:n.allow?`done`:`skip`}),n.allow?`allowed`:`skipped`}catch(e){return`refused: ${e.message}`}case`go_back`:return await a.back()?`went back; wait for the state`:a.error??`refused`;default:return`unknown tool ${t}`}},[e,F,P]),te=(0,H.useCallback)(async()=>{if(!E.current){c(null),b([]),a(`connecting`);try{let t=await S.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:!0});k.current=n;let r=new RTCPeerConnection;E.current=r;let i=document.createElement(`audio`);i.autoplay=!0,i.setAttribute(`playsinline`,``),document.body.append(i),O.current=i,r.ontrack=e=>{i.srcObject=e.streams[0]};for(let e of n.getTracks())r.addTrack(e,n);let s=r.createDataChannel(`oai-events`);D.current=s,s.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`output_audio_buffer.started`:u(!0);break;case`output_audio_buffer.stopped`:case`output_audio_buffer.cleared`:u(!1);break;case`input_audio_buffer.speech_started`:{f(!0);let e=Date.now()-w.current>Ee?F():null;e&&(w.current=Date.now(),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows while speaking`},{type:`input_image`,image_url:e}]}}));break}case`input_audio_buffer.speech_stopped`:f(!1);break;case`response.output_audio_transcript.done`:case`conversation.item.input_audio_transcription.completed`:{let e=String(t.transcript??``).trim();if(e){let n=t.type===`response.output_audio_transcript.done`?`bot`:`me`;b(t=>[...t.slice(-199),{id:`${Date.now()}:${n}`,who:n,text:e}])}break}case`response.function_call_arguments.done`:{let e=String(t.name??``),n=String(t.call_id??``),r={};try{r=JSON.parse(String(t.arguments??`{}`))}catch{}B(e,r).then(e=>{P({type:`conversation.item.create`,item:{type:`function_call_output`,call_id:n,output:e}}),P({type:`response.create`})});break}case`error`:c(String(t.error?.message??`error`))}},s.onopen=()=>{a(`live`);let e=A.current;e&&(N.current=Oe(e,j.current,T.current),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${N.current}\n\nGreet the person in one sentence and ask the first open field.`}]}}),P({type:`response.create`}))},s.onclose=()=>{E.current===r&&z()};let l=await r.createOffer();await r.setLocalDescription(l);let d=await fetch(t.endpoint,{method:`POST`,headers:{authorization:`Bearer ${t.clientSecret}`,"content-type":`application/sdp`},body:l.sdp});if(!d.ok)throw Error(`${o(`talk.failed`)} (${d.status})`);await r.setRemoteDescription({type:`answer`,sdp:await d.text()})}catch(e){z(),c(e.name===`NotAllowedError`?o(`chat.micDenied`):e.message),a(`error`)}}},[e,B,F,P,z]);return(0,H.useEffect)(()=>{if(i!==`live`||!t)return;let e=Oe(t,r,p);if(e===N.current)return;let n=N.current;N.current=e,P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${e}`}]}}),(t.status===`running`&&n.startsWith(`status: running`)&&!n.includes(`working on: `)||t.status!==`running`||n.split(`
|
|
9
|
+
`)[1]!==e.split(`
|
|
10
|
+
`)[1])&&P({type:`response.create`})},[i,t,r,p,P]),{state:i,error:s,speaking:l,listening:d,start:te,stop:z,camera:p,facing:h,startCamera:L,stopCamera:I,flipCamera:ee,muted:_,toggleMute:R,captions:y,video:x}}var G=(e,t,n)=>({key:e,who:`bot`,node:t,...n}),K=(e,t,n)=>({key:e,who:`me`,node:t,...n}),Ae=(0,H.createContext)(null),q=(0,H.createContext)(null);function je(){return(0,H.useContext)(q)?.voice??null}function Me({children:e}){let t=(0,H.useContext)(Ae);return t?(0,ye.createPortal)(e,t):null}function Ne({header:e,footer:t,children:n}){let[r,i]=(0,H.useState)(null),a=(0,H.useRef)(null),o=(0,H.useRef)(null),s=(0,H.useRef)(!0);return(0,H.useLayoutEffect)(()=>{let e=a.current,t=o.current;if(!e||!t)return;let n=e.scrollTop,r=()=>{e.scrollHeight-e.scrollTop-e.clientHeight<120?s.current=!0:e.scrollTop<n&&(s.current=!1),n=e.scrollTop},i=null,c=new ResizeObserver(()=>{let r=t.querySelector(`[data-anchor]`);r&&r!==i?(i=r,e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-12,s.current=!1,n=e.scrollTop):s.current&&(e.scrollTop=e.scrollHeight)});return e.scrollTop=e.scrollHeight,e.addEventListener(`scroll`,r,{passive:!0}),c.observe(t),c.observe(e),()=>{c.disconnect(),e.removeEventListener(`scroll`,r)}},[]),(0,U.jsx)(Ae.Provider,{value:r,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,U.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,U.jsx)(`div`,{ref:o,className:`mx-auto flex w-full max-w-[760px] flex-col gap-3 px-3 pt-5 pb-4 sm:px-6`,children:n})}),(0,U.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,U.jsx)(`div`,{ref:i,className:`mx-auto w-full max-w-[760px] px-3 pt-3 sm:px-6`}),t]})]})})}function J({avatar:e,lines:t}){let n=(0,H.useContext)(q),r=(0,H.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),i=(0,H.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);oe(!!n?.readAloud,n?.lang??R,r,i);let a=[];for(let e of t){let t=a.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):a.push({who:e.who,lines:[e]})}return a.map((t,n)=>t.who===`bot`?(0,U.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,U.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,U.jsx)(te,{kind:e,size:30,interactive:n>=a.length-2})}),(0,U.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,U.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className:z(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?z(`w-full bg-card p-4 shadow-soft ring-1 ring-border-soft`,e.wide===`most`&&`md:w-4/5`):`max-w-[min(36rem,100%)] bg-card px-4 py-2.5 shadow-soft ring-1 ring-border-soft`),e.tone===`error`&&`bg-rose-tint text-rose shadow-none ring-0`),children:e.node},e.key))})]},t.lines[0].key):t.lines.map(e=>(0,U.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,U.jsx)(`div`,{className:`max-w-[min(32rem,100%)] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-4 py-2.5 text-[0.9375rem] text-primary-foreground leading-relaxed`,children:e.node}),e.onEdit?(0,U.jsxs)(`button`,{type:`button`,onClick:e.onEdit,className:`inline-flex items-center gap-1 px-1 text-[0.75rem] text-ink-4 transition hover:text-ink-2 coarse:min-h-9`,children:[(0,U.jsx)(h,{className:`size-3`}),` `,o(`chat.change`)]}):null]},e.key)))}function Pe(){return(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":o(`run.working`),children:[0,1,2].map(e=>(0,U.jsx)(`span`,{className:`size-1.5 animate-typing rounded-full bg-ink-3`,style:{animationDelay:`${e*160}ms`}},e))})}function Y({children:e}){return(0,U.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,U.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,U.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className:z(`inline-flex h-10 items-center gap-1.5 rounded-full px-4 font-medium text-[0.875rem] transition active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 coarse:h-11`,n?`bg-primary text-primary-foreground hover:brightness-[1.06]`:r?`bg-ember-tint text-ink ring-1 ring-ember`:`bg-card text-ink-2 ring-1 ring-input hover:text-ink hover:ring-ink-4`),children:[a?(0,U.jsx)(I,{className:`size-4`}):null,t]})}function Fe({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:a,inputRef:s,onSend:c}){let[u,d]=(0,H.useState)(e),f=(0,H.useRef)(null),p=s??f,m=(0,H.useContext)(q),h=j(u,d,{endpoint:m?`/api/runs/${m.runId}/transcribe`:void 0}),g=!!m&&h.supported&&!a;(0,H.useEffect)(()=>{if(!g)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),h.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,h.toggle]),(0,H.useEffect)(()=>{!b&&!a&&p.current?.focus()},[a,p]);let _=()=>{i||a||(h.listening&&h.toggle(),c(u)!==!1&&d(``))},v=h.listening?o(`chat.listening`):h.processing?o(`chat.transcribing`):t,y=m?.voice??null,x=!!m?.call,S=m&&!x&&(ae||g||y)?(0,U.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[y?(0,U.jsx)(T,{label:o(y.state===`live`?`talk.stop`:y.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":y.state===`live`,disabled:y.state===`connecting`,onClick:()=>y.state===`live`?y.stop():void y.start(),className:z(`size-9`,y.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,y.state===`off`&&m.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:y.state===`connecting`?(0,U.jsx)(I,{className:`size-4`}):y.state===`live`?(0,U.jsx)(ue,{className:`size-4`}):(0,U.jsx)(re,{className:`size-4`})}):null,y?.state===`live`?(0,U.jsx)(T,{label:o(y.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":y.camera,onClick:()=>y.camera?y.stopCamera():void y.startCamera(),className:z(`size-9`,y.camera&&`text-ink`),children:y.camera?(0,U.jsx)(l,{className:`size-4`}):(0,U.jsx)(V,{className:`size-4`})}):null,ae?(0,U.jsx)(T,{label:o(m.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":m.readAloud,onClick:()=>m.setReadAloud(!m.readAloud),className:z(`size-9`,m.readAloud&&`text-ink`),children:m.readAloud?(0,U.jsx)(ie,{className:`size-4`}):(0,U.jsx)(ve,{className:`size-4`})}):null,g?(0,U.jsx)(T,{label:o(h.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":h.listening,disabled:h.processing,onClick:h.toggle,className:z(`size-9`,h.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:h.processing?(0,U.jsx)(I,{className:`size-4`}):h.listening?(0,U.jsx)(P,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,U.jsx)(B,{className:`size-4`})}):null]}):null;return(0,U.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),_()},children:[y&&!x?(0,U.jsx)(`video`,{ref:y.video,muted:!0,playsInline:!0,autoPlay:!0,className:z(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,y.camera?`block`:`hidden`)}):null,(0,U.jsxs)(`div`,{className:z(`flex items-end gap-1 rounded-[1.375rem] border border-input bg-card pr-1.5 pl-1 transition focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,a&&`opacity-60`),children:[S,n?(0,U.jsx)(L,{ref:p,minRows:1,maxRows:6,value:u,disabled:a,placeholder:v,autoCapitalize:`sentences`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!b&&!e.nativeEvent.isComposing&&(e.preventDefault(),_())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,U.jsx)(`input`,{ref:p,...r,value:u,disabled:a,placeholder:v,enterKeyHint:`send`,onChange:e=>d(e.target.value),className:`h-11 min-w-0 flex-1 bg-transparent px-3 text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,U.jsx)(`button`,{type:`submit`,"aria-label":o(`chat.send`),title:o(`chat.send`),disabled:i||a,className:`mb-1 flex size-9 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:brightness-[1.06] disabled:opacity-40`,children:i?(0,U.jsx)(I,{className:`size-4`}):(0,U.jsx)(D,{className:`size-4`})})]}),h.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:h.error===`denied`?o(`chat.micDenied`):h.error}):x?null:y?.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:y.error}):y?.state===`live`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:y.speaking?o(`talk.speaking`):y.listening?o(`talk.listening`):o(`talk.live`)}):m?.talk&&y?.state===`off`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:o(`talk.hint`)}):null]})}function Q({placeholder:e=o(`chat.above`)}){return(0,U.jsx)(Me,{children:(0,U.jsx)(Fe,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Ie(e){let t=p[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Le=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Re(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Le(t))return e.required&&!n?o(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return o(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return o(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?o(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?o(`run.filesMin`,{n:t.length,min:e.min}):null}function ze(e,t){let n=e.kind===`textarea`?t.replace(/\s+$/,``):t.trim();if(n)return e.kind===`url`&&!/^[a-z][a-z0-9+.-]*:/i.test(n)?`https://${n}`:n}function Be({field:e}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,U.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function Ve({step:e,only:t}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,U.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function He({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,U.jsx)(U.Fragment,{children:typeof t==`string`&&t?t:o(`chat.connected`)});if(e.kind===`list`)return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(_,{className:`size-4`}),` `,o(`chat.checked`)]});if(e.kind===`toggle`)return(0,U.jsx)(U.Fragment,{children:o(t===!0?`run.yes`:`run.no`)});if(Le(t))return(0,U.jsx)(`span`,{className:`italic opacity-80`,children:o(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,U.jsx)(U.Fragment,{children:t.join(`, `)});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,U.jsx)(U.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(R,{dateStyle:`long`}).format(e)})}case`color`:return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,U.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,U.jsx)(`img`,{src:O(`/api/runs/${n}/assets/${t}`),alt:``,className:z(`h-16 rounded-lg bg-white`,e.kind===`image`?`w-16 object-cover`:`object-contain px-1`)},t))});case`file`:{let e=Array.isArray(t)?t.length:1;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(f,{className:`size-4`}),` `,o(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(B,{className:`size-4`}),` `,o(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,U.jsx)(U.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,U.jsx)(U.Fragment,{children:o(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,U.jsx)(U.Fragment,{children:String(t)})}}function Ue(e,t,n,r,i,a){let o=[G(t,(0,U.jsx)(Ve,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,U.jsx)(Be,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,U.jsx)(He,{field:e,value:n[e.id],runId:r})));return o}var We=(e,t)=>e.fields.filter(e=>!e.when&&!u(e)||t[e.id]!==void 0&&t[e.id]!==null);function Ge(e,t){let n=[];e.wizard.description&&n.push(G(`hello`,e.wizard.description)),e.wizard.intro&&n.push(G(`intro`,e.wizard.intro));for(let[t,r]of e.answered.entries()){let i=`${t}:${r.id}`;if(r.type===`page`){let t=r.fields.length===1?r.fields[0]:void 0;n.push(...Ue(r,i,e.values,e.id,We(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,U.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${i}:a`,o(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function Ke(e,t){return e.fields.filter(e=>!u(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function qe({view:e,run:t,step:n,before:r}){let i=(0,H.useMemo)(()=>Ke(n,e),[n,e]),a=e.known??{},[s,c]=(0,H.useState)(()=>F(n,e)),[l,u]=(0,H.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?d(Ke(n,e),e.known??{},F(n,e)).slice(0,-1).map(e=>e.id):[]),[f,p]=(0,H.useState)({}),[m,h]=(0,H.useState)(!1),[g,_]=(0,H.useState)(!1),y=d(i,a,s),b=y.filter(e=>l.includes(e.id)),x=y.find(e=>!l.includes(e.id)),S=i.length===1?i[0]:void 0,C=b.at(-1),w=C?()=>u(e=>e.filter(e=>e!==C.id)):void 0;(0,H.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=d(i,a,s),r=n.findIndex(t=>e.includes(t.id));r>=0&&(u(n.slice(0,r).map(e=>e.id)),p(t.fieldErrors))},[t.fieldErrors]);let T=e=>{t.submitPage(n.id,e).then(_)},E=(0,H.useContext)(q),D=(0,H.useRef)(s);D.current=s;let O=E?.bindPage,k=(0,H.useRef)(T);k.current=T,(0,H.useEffect)(()=>{if(!O)return;let e=d(i,a,s);return O({step:n,fields:e,values:s,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Re(r,n)||(c(e=>({...e,[t]:n})),u(e=>e.includes(t)?e:[...e,t]),p({}),null):`no such field on this page`},submit:()=>k.current(D.current)}),()=>O(null)},[O,n,i,a,s]);let A=e=>{if(!x)return!1;let t=Re(x,e);if(t)return p({[x.id]:t}),!1;let n={...s,[x.id]:e},r=[...l,x.id];return c(n),u(r),p({}),d(i,a,n).some(e=>!r.includes(e.id))||T(n),!0},j=[...r.map(e=>l.length?{...e,onEdit:void 0}:e),...Ue(n,`now:${n.id}`,s,e.id,b,S).map((e,t,n)=>t===n.length-1&&e.who===`me`&&x?{...e,onEdit:w}:e)];x?(Ie(x)===`control`?j.push(G(`now:${n.id}:${x.id}:control`,(0,U.jsx)(v,{field:x,value:s[x.id],values:s,runId:e.id,view:e,closed:e.closed?.[x.id],onChange:e=>c(t=>({...t,[x.id]:e})),onBusy:h}),{wide:!0})):S||j.push(G(`now:${n.id}:${x.id}`,(0,U.jsx)(Be,{field:x}))),f[x.id]&&j.push(G(`now:${n.id}:${x.id}:error`,f[x.id],{tone:`error`}))):t.busy||g?j.push(G(`sending`,(0,U.jsx)(Pe,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,U.jsx)(Q,{});if(g||!x&&l.length>0&&t.busy)M=(0,U.jsx)(Q,{placeholder:o(`run.working`)});else if(!x)j.push(X(`now:${n.id}:go`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>T(s),children:n.cta||o(`run.next`)}),w?(0,U.jsx)(Z,{onClick:w,disabled:t.busy,children:o(`run.back`)}):null]})));else{let r=Ie(x),i=!x.required&&x.kind!==`connection`&&x.kind!==`list`?(0,U.jsx)(Z,{onClick:()=>A(void 0),children:o(`chat.skip`)}):null;if(r===`typed`){i&&j.push(X(`now:${n.id}:${x.id}:replies`,i));let e=s[x.id];M=(0,U.jsx)(Me,{children:(0,U.jsx)(Fe,{initial:Le(e)?``:String(e),multiline:x.kind===`textarea`,placeholder:x.placeholder||(S?x.label:o(`chat.placeholder`)),inputProps:Je(x),busy:t.busy,onSend:e=>A(ze(x,e))},x.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${x.id}:replies`,(0,U.jsx)(Ye,{field:x,view:e,value:s[x.id],onAnswer:A}),{bare:!0}));else{let e=y.filter(e=>!l.includes(e.id)).length===1;j.push(X(`now:${n.id}:${x.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,disabled:m,onClick:()=>A(s[x.id]),children:e&&n.cta?n.cta:o(`chat.send`)}),i]})))}}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function Je(e){switch(e.kind){case`number`:return{inputMode:`decimal`,autoComplete:`off`};case`email`:return{type:`email`,inputMode:`email`,autoComplete:`email`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`url`:return{inputMode:`url`,autoComplete:`url`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`date`:return{type:`date`};default:return a(e)}}function Ye({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,s]=(0,H.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,U.jsxs)(Y,{children:[(0,U.jsx)(Z,{on:n===!1,disabled:i.has(`false`),onClick:()=>r(!1),children:o(`run.no`)}),(0,U.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:o(`run.yes`)})]});let c=e.options??[];return e.kind===`multiselect`?(0,U.jsxs)(Y,{children:[c.map(e=>(0,U.jsx)(Z,{on:a.includes(e),onClick:()=>s(t=>t.includes(e)?t.filter(t=>t!==e):c.filter(n=>n===e||t.includes(n))),children:e},e)),(0,U.jsx)(Z,{primary:!0,disabled:e.required&&!a.length,onClick:()=>r(a),children:a.length||e.required?o(`chat.send`):o(`chat.skip`)})]}):(0,U.jsxs)(Y,{children:[c.map(e=>(0,U.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:e},e)),e.required?null:(0,U.jsx)(Z,{onClick:()=>r(void 0),children:o(`chat.skip`)})]})}function Xe({view:e}){let t=(0,H.useMemo)(()=>[...e.events].reverse().find(t=>t.type===`step_started`&&t.stepId===e.step?.id),[e.events,e.step?.id]),n=t?new Date(t.at).getTime():Date.now(),[r,a]=(0,H.useState)(Date.now());(0,H.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[]);let s=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),c=s.at(-1),l=[...s].reverse().find(Qe),u=[...new Set(s.map(e=>e.asset).filter(e=>!!e))];return(0,U.jsxs)(`div`,{className:z(`flex max-w-full flex-col gap-1`,l?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??o(`run.working`),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(Pe,{}),(0,U.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??o(`run.working`)}),(0,U.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:o(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),c&&c!==l?(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,U.jsx)(i,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,U.jsx)(`span`,{className:`truncate`,children:w(c)})]}):null,l&&e.status===`running`?(0,U.jsx)(et,{runId:e.id,event:l}):null,u.length?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:u.slice(-6).map(t=>(0,U.jsx)(`img`,{src:O(`/api/runs/${e.id}/assets/${t}`),alt:``,className:`size-14 rounded-lg bg-paper-2 object-cover ring-1 ring-border-soft`},t))}):null]})}var Ze=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function Qe(e){return!!e.note&&Ze.has(e.note.code)}var $e=1e4;function et({runId:e,event:t}){let[n,i]=(0,H.useState)(null),[a,s]=(0,H.useState)(`agent`),[c,l]=(0,H.useState)(!1),u=t.note?.code;if((0,H.useEffect)(()=>{u===`personDrives`?s(`person`):u===`agentDrives`&&s(`agent`)},[u]),(0,H.useEffect)(()=>{let t=()=>S.get(`/api/runs/${e}/browser/seat`).then(e=>s(e.seat)).catch(()=>void 0);if(t(),a!==`person`)return;let n=setInterval(t,$e);return()=>clearInterval(n)},[e,a]),n!==null&&n>=t.id)return null;let d=a===`person`,f=async()=>{l(!0);try{let t=await S.post(`/api/runs/${e}/browser/seat`,{to:d?`agent`:`person`});s(t.seat)}catch{}finally{l(!1)}};return(0,U.jsx)(r,{runId:e,driving:d,caption:w(t),hint:o(`browser.driving`),onBroken:()=>i(t.id),className:`mt-1.5`,action:(0,U.jsxs)(`button`,{type:`button`,disabled:c,onClick:()=>void f(),className:z(`flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] shadow-soft transition-colors disabled:opacity-60`,d?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-card/90 text-ink ring-1 ring-border-soft backdrop-blur hover:bg-card`),children:[d?(0,U.jsx)(he,{className:`size-3.5`}):(0,U.jsx)(pe,{className:`size-3.5`}),o(d?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,U.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function tt({view:e,run:t,step:n,before:r,asked:i,onNote:a}){let s=e.shown.filter(e=>e.output),[l,u]=(0,H.useState)(s.length===1?s[0].step.id:null),d=(0,H.useRef)(null),f=[...r,...i.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.description}):null]}),{anchor:!0}),...s.map(({step:t,output:r})=>G(`review:${n.id}:${t.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.title}),(0,U.jsx)(C,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{u(t.id),d.current?.focus()}:void 0})]}),{wide:!0})),...e.lists.map(t=>G(`review:${n.id}:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.def.title}),t.def.check?(0,U.jsx)(ee,{runId:e.id,list:t}):(0,U.jsx)(c,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&f.push(G(`review-error`,t.error,{tone:`error`}));let p=n.regenerate&&s.length>0;return f.push(X(`review:${n.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,U.jsx)(_,{className:`size-4`}),` `,o(`run.accept`)]}),p&&s.length>1?s.map(({step:e})=>(0,U.jsx)(Z,{on:l===e.id,onClick:()=>u(e.id),children:e.title},e.id)):null]}))),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:f}),p?(0,U.jsx)(Me,{children:(0,U.jsx)(Fe,{multiline:!0,inputRef:d,busy:t.busy,placeholder:s.length>1&&!l?o(`run.feedbackPick`):o(`run.feedbackPlaceholder`),disabled:!l,onSend:e=>{let r=e.trim();return!r||!l?!1:(a(r),t.regenerate(n.id,l,r),!0)}})}):(0,U.jsx)(Q,{})]})}function nt({view:e,run:t,step:n,before:r,onRestart:i}){let a=e.shown.filter(e=>e.output),l=`/api/runs/${e.id}`,u=[...r,G(`result:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.message}):null]}),{anchor:!0}),...a.map(({step:e,output:t,formats:n,label:r})=>G(`result:${e.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(k,{base:l,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,U.jsx)(C,{base:l,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,U.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:o(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(y,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,U.jsx)(c,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return u.push(X(`result:replies`,(0,U.jsxs)(U.Fragment,{children:[a.length?(0,U.jsx)(de,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,i?(0,U.jsxs)(Z,{onClick:i,children:[(0,U.jsx)(N,{className:`size-4`}),` `,o(`run.again`)]}):null,e.canBack?(0,U.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:o(`run.back`)}):null,e.keeps?(0,U.jsx)(`span`,{className:`ml-1`,children:(0,U.jsx)(s,{runId:e.id})}):null]}))),(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:u})}function rt({runId:e,onRestart:t,onView:n,header:r,footer:i,talk:a=!1,call:s=!1}){let c=ne(e),{view:l}=c,[u,d]=(0,H.useState)(null),f=ke(e,l,c,u);(0,H.useEffect)(()=>{n?.(l)},[l,n]);let[p,m]=se(),h=(0,H.useMemo)(()=>({runId:e,lang:l?.lang??R,readAloud:p,setReadAloud:m,voice:l?.talk?f:null,talk:a,call:!!s,bindPage:d}),[e,l?.lang,l?.talk,p,m,f,a,s]);x(l?.status===`running`&&!l.ask),A(l);let[_,v]=(0,H.useState)({}),[y,b]=(0,H.useState)(null);(0,H.useEffect)(()=>{l&&l.status!==`running`&&b(null)},[l]);let S;if(c.notFound)S=(0,U.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:o(`run.notFound`)});else if(!l)S=(0,U.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,U.jsx)(I,{})});else{let e=l.step,n=l.status===`waiting_input`,r=Ge(l,l.canBack&&n&&!c.busy?()=>void c.back():void 0);if(l.status===`running`&&l.ask)S=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,U.jsx)(g,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,U.jsx)(Q,{})]});else if(l.status===`running`)S=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...y?[K(`note`,y)]:[],G(`working:${e?.id}`,(0,U.jsx)(Xe,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&Qe(t))?`most`:void 0})]}),(0,U.jsx)(Q,{placeholder:o(`run.working`)})]});else if(l.status===`failed`)S=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`failed`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:o(`run.failed`)}),l.error?(0,U.jsx)(`span`,{className:`mt-0.5 block`,children:(0,U.jsx)(E,{text:l.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:c.busy,onClick:()=>void c.retry(),children:[(0,U.jsx)(N,{className:`size-4`}),` `,o(`run.retry`)]}),l.canBack?(0,U.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:o(`run.back`)}):null]}))]}),(0,U.jsx)(Q,{})]});else if(l.status===`cancelled`)S=(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,o(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,U.jsxs)(Z,{primary:!0,onClick:t,children:[(0,U.jsx)(N,{className:`size-4`}),` `,o(`run.again`)]}))]:[]]});else if(e?.type===`page`)S=(0,U.jsx)(qe,{view:l,run:c,step:e,before:r},e.id);else if(e?.type===`review`){let t=l.shown.map(e=>e.output?.at??``).join(`|`);S=(0,U.jsx)(tt,{view:l,run:c,step:e,before:r,asked:_[e.id]??[],onNote:t=>{b(t),v(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else S=e?.type===`result`?(0,U.jsx)(nt,{view:l,run:c,step:e,before:r,onRestart:t}):(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:r})}return s?(0,U.jsx)(q.Provider,{value:h,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,U.jsx)(Ce,{voice:f,view:l,video:s===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,U.jsx)(`aside`,{className:`flex min-h-0 flex-1 flex-col border-border-soft border-t lg:w-[420px] lg:flex-none lg:border-t-0 lg:border-l`,children:(0,U.jsx)(Ne,{footer:i,children:S})})]})}):(0,U.jsx)(q.Provider,{value:h,children:(0,U.jsx)(Ne,{header:r,footer:i,children:S})})}export{J as a,Z as i,Ne as n,X as o,Q as r,je as s,rt as t};
|