wizards 0.2.46 → 0.2.48
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/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 +5 -1
- 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/features.js +50 -0
- package/apps/runtime/dist/cli/main.js +4 -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/meta/0012_snapshot.json +3132 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +30 -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 +29 -0
- package/apps/runtime/dist/docs/user/models.md +100 -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 +210 -0
- package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
- package/apps/runtime/dist/engine/runner.js +12 -5
- package/apps/runtime/dist/features.js +123 -0
- package/apps/runtime/dist/manage.js +24 -0
- package/apps/runtime/dist/plugins/discovery.js +11 -0
- package/apps/runtime/dist/plugins/loader.js +12 -0
- package/apps/runtime/dist/routes/internal.js +3 -0
- package/apps/runtime/dist/routes/studio.js +126 -73
- package/apps/runtime/dist/services/assistant-chats.js +267 -0
- package/apps/runtime/dist/services/project-index.js +1 -1
- package/apps/runtime/dist/services/space-origin.js +45 -2
- package/apps/web/dist/assets/{AboutDialog-DkY1j7k6.js → AboutDialog-CuiVGknS.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-820LI5Jt.js → ChangelogDialog-DCEQD3Jd.js} +1 -1
- package/apps/web/dist/assets/ChatView-DFxrG2PD.js +10 -0
- package/apps/web/dist/assets/EditorPage-B5rzKNMy.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-ChXfiMn_.js → FlowPreview-CYoR5DRY.js} +1 -1
- package/apps/web/dist/assets/{Harness-CfUfchNw.js → Harness-DAR1u4Dk.js} +1 -1
- package/apps/web/dist/assets/HomePage-BnYdh_Nx.js +1 -0
- package/apps/web/dist/assets/Marketplace-BDQNwMDB.js +2 -0
- package/apps/web/dist/assets/{NewWizardPage-C3NqEGmg.js → NewWizardPage-DztTEUlG.js} +1 -1
- package/apps/web/dist/assets/ProjectPage-B7-Lqx9a.js +2 -0
- package/apps/web/dist/assets/PublicRunner-CaH3bHHd.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-C9P9aiU6.js → ReadOnly-DnB47DQC.js} +1 -1
- package/apps/web/dist/assets/RunDrawer-Dv0KRqGA.js +4 -0
- package/apps/web/dist/assets/RunnerView-Bzwv1u4j.js +2 -0
- package/apps/web/dist/assets/SettingsPage-oVO7CKvc.js +1 -0
- package/apps/web/dist/assets/SetupPage-D--8cWA0.js +1 -0
- package/apps/web/dist/assets/{SharePage-D5AvnhlY.js → SharePage-DjU08q7T.js} +1 -1
- package/apps/web/dist/assets/ThemeSwitch-C3EJRN06.js +1 -0
- package/apps/web/dist/assets/arrow-right-F7X_SjK9.js +1 -0
- package/apps/web/dist/assets/changelog-BRoVI_JJ.js +1 -0
- package/apps/web/dist/assets/{circle-alert-CPo3Naay.js → circle-alert-DdpaAYgd.js} +1 -1
- package/apps/web/dist/assets/{definition-CQGiBQ4X.js → definition-CHacJYmI.js} +2 -2
- package/apps/web/dist/assets/{external-link-CpU8aJY2.js → external-link-Dfc1VFvS.js} +1 -1
- package/apps/web/dist/assets/index-CX_yxZVQ.js +79 -0
- package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
- package/apps/web/dist/assets/{lock-C_WlXIQ0.js → lock-Bu1wDFs8.js} +1 -1
- package/apps/web/dist/assets/{refresh-cw-Cli5WGnW.js → refresh-cw-BUDPOT39.js} +1 -1
- package/apps/web/dist/assets/{session-miDEdw2c.js → session-Blj2os_v.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-ROT8Lbbj.js → settings-menu-BvxRnNtf.js} +1 -1
- package/apps/web/dist/assets/{sparkles-CP5H-O1E.js → sparkles-DWGJluyV.js} +1 -1
- package/apps/web/dist/assets/{trash-DU-hZpV0.js → trash-D9UB6TtS.js} +1 -1
- package/apps/web/dist/assets/ui-GsuU9WTj.js +9 -0
- package/apps/web/dist/assets/{upload-DMq5N6Fw.js → upload-BngimDBR.js} +1 -1
- package/apps/web/dist/assets/{volume-2-0SfkvOho.js → volume-2-BZju_bOP.js} +1 -1
- package/apps/web/dist/index.html +11 -11
- package/apps/web/dist/mcp/flow.html +51 -51
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +103 -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 +56 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
- package/node_modules/@engenty-wizards/shared/dist/feature-flags.d.ts +54 -0
- package/node_modules/@engenty-wizards/shared/dist/feature-flags.js +46 -0
- package/node_modules/@engenty-wizards/shared/dist/features.d.ts +36 -0
- package/node_modules/@engenty-wizards/shared/dist/features.js +78 -0
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
- package/package.json +1 -1
- package/apps/web/dist/assets/ChatView-DBl0iRMg.js +0 -10
- package/apps/web/dist/assets/EditorPage-BwJ-hqPg.js +0 -3
- package/apps/web/dist/assets/HomePage-BG5OZJkv.js +0 -1
- package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
- package/apps/web/dist/assets/ProjectPage-Btf0TeP_.js +0 -2
- package/apps/web/dist/assets/PublicRunner-BxYinn04.js +0 -1
- package/apps/web/dist/assets/RunDrawer-DfnEMPTq.js +0 -4
- package/apps/web/dist/assets/RunnerView-CLrGb-oq.js +0 -2
- package/apps/web/dist/assets/SettingsPage-FWH84btd.js +0 -1
- package/apps/web/dist/assets/SetupPage-BI0kUNVW.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-C1qYFoYP.js +0 -1
- package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
- package/apps/web/dist/assets/changelog-B6QMrVxX.js +0 -1
- package/apps/web/dist/assets/index-CIO9W4pe.js +0 -78
- package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
- package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feature flags of the core: the parts that ship in the code but are not on for everyone
|
|
3
|
+
* yet (`release`), and the parts a plan includes (`plan`). This file is the list – add a flag
|
|
4
|
+
* here, branch on it with `useFeature("name")` in the studio or `feature("name")` in the
|
|
5
|
+
* runtime, and delete it with its branches once its default became `true`.
|
|
6
|
+
*
|
|
7
|
+
* How a flag gets its value (defaults here → `FEATURES` env → the Manage-App → the `.features`
|
|
8
|
+
* file) lives in features.ts. A plugin's flags are declared in its manifest under `features`
|
|
9
|
+
* and are known as `<plugin id>.<name>`; they do not belong here. No public page lists these.
|
|
10
|
+
*/
|
|
11
|
+
export interface FeatureDeclaration {
|
|
12
|
+
kind: "release" | "plan";
|
|
13
|
+
/** What counts until a layer says otherwise. */
|
|
14
|
+
default: boolean;
|
|
15
|
+
/** A few words for the lists: `wizards features`, the admin's switches. */
|
|
16
|
+
label: string;
|
|
17
|
+
hint?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One entry per flag. `kind: "release"`: on or off for everyone by default, turned on for a
|
|
21
|
+
* team or a machine before the default flips. `kind: "plan"`: on until a plan says `false`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const FEATURES: {
|
|
24
|
+
readonly account: {
|
|
25
|
+
readonly kind: "release";
|
|
26
|
+
readonly default: true;
|
|
27
|
+
readonly label: "Account in a local install";
|
|
28
|
+
readonly hint: "Linking, Settings → Account, the offer to sign in.";
|
|
29
|
+
};
|
|
30
|
+
readonly unsetConnectors: {
|
|
31
|
+
readonly kind: "release";
|
|
32
|
+
readonly default: false;
|
|
33
|
+
readonly label: "Connectors without an OAuth client";
|
|
34
|
+
readonly hint: "Built-in connectors are shown although their client is not set up.";
|
|
35
|
+
};
|
|
36
|
+
readonly site: {
|
|
37
|
+
readonly kind: "release";
|
|
38
|
+
readonly default: false;
|
|
39
|
+
readonly label: "Link to the website in the setup";
|
|
40
|
+
readonly hint: "The local install's setup links the product's site.";
|
|
41
|
+
};
|
|
42
|
+
readonly teamPlans: {
|
|
43
|
+
readonly kind: "release";
|
|
44
|
+
readonly default: false;
|
|
45
|
+
readonly label: "Team plans";
|
|
46
|
+
readonly hint: "The team page in the cloud studio, and plans that carry this switch on the account pages.";
|
|
47
|
+
};
|
|
48
|
+
readonly ownKeys: {
|
|
49
|
+
readonly kind: "plan";
|
|
50
|
+
readonly default: true;
|
|
51
|
+
readonly label: "Own API keys";
|
|
52
|
+
readonly hint: "The team puts its providers' keys into the cloud studio instead of running on credits.";
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feature flags of the core: the parts that ship in the code but are not on for everyone
|
|
3
|
+
* yet (`release`), and the parts a plan includes (`plan`). This file is the list – add a flag
|
|
4
|
+
* here, branch on it with `useFeature("name")` in the studio or `feature("name")` in the
|
|
5
|
+
* runtime, and delete it with its branches once its default became `true`.
|
|
6
|
+
*
|
|
7
|
+
* How a flag gets its value (defaults here → `FEATURES` env → the Manage-App → the `.features`
|
|
8
|
+
* file) lives in features.ts. A plugin's flags are declared in its manifest under `features`
|
|
9
|
+
* and are known as `<plugin id>.<name>`; they do not belong here. No public page lists these.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* One entry per flag. `kind: "release"`: on or off for everyone by default, turned on for a
|
|
13
|
+
* team or a machine before the default flips. `kind: "plan"`: on until a plan says `false`.
|
|
14
|
+
*/
|
|
15
|
+
export const FEATURES = {
|
|
16
|
+
account: {
|
|
17
|
+
kind: "release",
|
|
18
|
+
default: true,
|
|
19
|
+
label: "Account in a local install",
|
|
20
|
+
hint: "Linking, Settings → Account, the offer to sign in.",
|
|
21
|
+
},
|
|
22
|
+
unsetConnectors: {
|
|
23
|
+
kind: "release",
|
|
24
|
+
default: false,
|
|
25
|
+
label: "Connectors without an OAuth client",
|
|
26
|
+
hint: "Built-in connectors are shown although their client is not set up.",
|
|
27
|
+
},
|
|
28
|
+
site: {
|
|
29
|
+
kind: "release",
|
|
30
|
+
default: false,
|
|
31
|
+
label: "Link to the website in the setup",
|
|
32
|
+
hint: "The local install's setup links the product's site.",
|
|
33
|
+
},
|
|
34
|
+
teamPlans: {
|
|
35
|
+
kind: "release",
|
|
36
|
+
default: false,
|
|
37
|
+
label: "Team plans",
|
|
38
|
+
hint: "The team page in the cloud studio, and plans that carry this switch on the account pages.",
|
|
39
|
+
},
|
|
40
|
+
ownKeys: {
|
|
41
|
+
kind: "plan",
|
|
42
|
+
default: true,
|
|
43
|
+
label: "Own API keys",
|
|
44
|
+
hint: "The team puts its providers' keys into the cloud studio instead of running on credits.",
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FEATURES, type FeatureDeclaration } from "./feature-flags.js";
|
|
2
|
+
/**
|
|
3
|
+
* Feature switches: how a flag of feature-flags.ts (or a plugin's manifest) gets its value.
|
|
4
|
+
* The runtime resolves them from the defaults, what the Manage-App says for the team or the
|
|
5
|
+
* linked account, and this install's `.features` file; the studio and plugins read the result.
|
|
6
|
+
*/
|
|
7
|
+
export { FEATURES, type FeatureDeclaration };
|
|
8
|
+
export type FeatureName = keyof typeof FEATURES;
|
|
9
|
+
export type FeatureKind = (typeof FEATURES)[FeatureName]["kind"];
|
|
10
|
+
/** A switch by name; a plugin's own switches carry its id: `contacts.leadScoring`. */
|
|
11
|
+
export type Features = Record<string, boolean>;
|
|
12
|
+
/** `teamPlans`, `contacts.leadScoring`. */
|
|
13
|
+
export declare const FEATURE_NAME: RegExp;
|
|
14
|
+
export declare const FEATURE_NAMES: FeatureName[];
|
|
15
|
+
/** What a manifest declares for one switch; what is left out is a release switch, off, named by its key. */
|
|
16
|
+
export interface FeatureDeclarationInput {
|
|
17
|
+
kind?: "release" | "plan";
|
|
18
|
+
default?: boolean;
|
|
19
|
+
label?: string;
|
|
20
|
+
hint?: string;
|
|
21
|
+
}
|
|
22
|
+
/** A plugin's declarations under its id: `contacts` + `leadScoring` → `contacts.leadScoring`. */
|
|
23
|
+
export declare function declaredByPlugin(pluginId: string, features: Record<string, FeatureDeclarationInput | boolean> | undefined): Record<string, FeatureDeclaration>;
|
|
24
|
+
/** The defaults of these declarations; without any, the core's. */
|
|
25
|
+
export declare function defaultFeatures(declared?: Record<string, FeatureDeclaration>): Features;
|
|
26
|
+
/**
|
|
27
|
+
* Switches in the shape of a `.env` file: one `name=on` or `name=off` per line (`true`/`false`
|
|
28
|
+
* and `1`/`0` count too), `#` starts a comment, anything else is skipped. The `FEATURES`
|
|
29
|
+
* environment variable holds the same, comma-separated. Unknown names are kept: a plugin's
|
|
30
|
+
* switches are not known here.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseFeatures(text: string): Features;
|
|
33
|
+
/** The text of a `.features` file for these switches, one `name=on|off` per line. */
|
|
34
|
+
export declare function formatFeatures(features: Features): string;
|
|
35
|
+
/** Layers laid over each other, the last one winning; null layers are skipped. */
|
|
36
|
+
export declare function resolveFeatures(...layers: (Features | null | undefined)[]): Features;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FEATURES } from "./feature-flags.js";
|
|
2
|
+
/**
|
|
3
|
+
* Feature switches: how a flag of feature-flags.ts (or a plugin's manifest) gets its value.
|
|
4
|
+
* The runtime resolves them from the defaults, what the Manage-App says for the team or the
|
|
5
|
+
* linked account, and this install's `.features` file; the studio and plugins read the result.
|
|
6
|
+
*/
|
|
7
|
+
export { FEATURES };
|
|
8
|
+
/** `teamPlans`, `contacts.leadScoring`. */
|
|
9
|
+
export const FEATURE_NAME = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)?$/;
|
|
10
|
+
export const FEATURE_NAMES = Object.keys(FEATURES);
|
|
11
|
+
/** A plugin's declarations under its id: `contacts` + `leadScoring` → `contacts.leadScoring`. */
|
|
12
|
+
export function declaredByPlugin(pluginId, features) {
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const [key, raw] of Object.entries(features ?? {})) {
|
|
15
|
+
const name = `${pluginId}.${key}`;
|
|
16
|
+
if (!FEATURE_NAME.test(name)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const d = typeof raw === "boolean" ? { default: raw } : raw;
|
|
20
|
+
out[name] = {
|
|
21
|
+
kind: d.kind ?? "release",
|
|
22
|
+
default: d.default ?? false,
|
|
23
|
+
label: d.label ?? key,
|
|
24
|
+
...(d.hint ? { hint: d.hint } : {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
/** The defaults of these declarations; without any, the core's. */
|
|
30
|
+
export function defaultFeatures(declared = FEATURES) {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const [name, d] of Object.entries(declared)) {
|
|
33
|
+
out[name] = d.default;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Switches in the shape of a `.env` file: one `name=on` or `name=off` per line (`true`/`false`
|
|
39
|
+
* and `1`/`0` count too), `#` starts a comment, anything else is skipped. The `FEATURES`
|
|
40
|
+
* environment variable holds the same, comma-separated. Unknown names are kept: a plugin's
|
|
41
|
+
* switches are not known here.
|
|
42
|
+
*/
|
|
43
|
+
export function parseFeatures(text) {
|
|
44
|
+
const out = {};
|
|
45
|
+
for (const raw of text.split(/[\n,]/)) {
|
|
46
|
+
const line = raw.replace(/#.*$/, "").trim();
|
|
47
|
+
if (!line) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const m = /^([A-Za-z0-9.]+)\s*=\s*(\S+)$/.exec(line);
|
|
51
|
+
if (!m?.[1] || !m[2] || !FEATURE_NAME.test(m[1])) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const value = m[2].toLowerCase();
|
|
55
|
+
if (["on", "true", "1"].includes(value)) {
|
|
56
|
+
out[m[1]] = true;
|
|
57
|
+
}
|
|
58
|
+
else if (["off", "false", "0"].includes(value)) {
|
|
59
|
+
out[m[1]] = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/** The text of a `.features` file for these switches, one `name=on|off` per line. */
|
|
65
|
+
export function formatFeatures(features) {
|
|
66
|
+
const lines = Object.entries(features).map(([name, on]) => `${name}=${on ? "on" : "off"}`);
|
|
67
|
+
return lines.length ? `${lines.join("\n")}\n` : "";
|
|
68
|
+
}
|
|
69
|
+
/** Layers laid over each other, the last one winning; null layers are skipped. */
|
|
70
|
+
export function resolveFeatures(...layers) {
|
|
71
|
+
const out = {};
|
|
72
|
+
for (const layer of layers) {
|
|
73
|
+
if (layer) {
|
|
74
|
+
Object.assign(out, layer);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Format, ModelClass, Step, WizardDefinition } from "./definition.js";
|
|
1
|
+
import type { CardOption, Format, ModelClass, Step, WizardDefinition } from "./definition.js";
|
|
2
2
|
import type { ConnectionView, ListDef, ListRow } from "./store.js";
|
|
3
3
|
import type { Surface } from "./surface.js";
|
|
4
4
|
export type RunStatus = "waiting_input" | "running" | "done" | "failed" | "cancelled";
|
|
@@ -406,6 +406,8 @@ export interface RunView {
|
|
|
406
406
|
known?: Record<string, unknown>;
|
|
407
407
|
/** Choices of the current page's fields that come from earlier data (`optionsFrom`). */
|
|
408
408
|
options?: Record<string, string[]>;
|
|
409
|
+
/** The same choices as cards, for fields that have `cards`. */
|
|
410
|
+
cards?: Record<string, CardOption[]>;
|
|
409
411
|
/** The decided fields (`ask`, `group`) of the current page that a decision kept. */
|
|
410
412
|
decidedFields?: string[];
|
|
411
413
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wizards",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.48",
|
|
4
4
|
"description": "Make a wish. Get your wizard. It guides you step by step. Let AI do the work. Runs on your machine, on the AI subscription you already have.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"homepage": "https://engenty.ai",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{t as r}from"./react-dom-DenslgJm.js";import{A as i,B as a,C as o,G as s,J as c,K as l,L as u,M as d,P as f,_ as p,f as m,g as h,j as g,l as _,o as v,x as y,z as b}from"./ui-D92EkdEB.js";import{_ as x,a as S,c as C,d as w,f as T,g as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,u as F,v as I}from"./RunnerView-CLrGb-oq.js";import{t as L}from"./sparkles-CP5H-O1E.js";import{n as R,t as ee}from"./volume-2-0SfkvOho.js";import{O as z,S as B,g as te,o as ne}from"./definition-CQGiBQ4X.js";import{T as re,b as ie,f as ae,h as oe}from"./index-CIO9W4pe.js";var se={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`}]]};se.node;var ce=c(se),le={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};le.node;var ue=c(le),de={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};de.node;var fe=c(de),pe={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`}]]};pe.node;var me=c(pe),he={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`}]]};he.node;var ge=c(he),_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=c(_e),ye=r(),V=e(t(),1),be=`wz.readAloud`,H=typeof window<`u`&&`speechSynthesis`in window&&`SpeechSynthesisUtterance`in window;function xe(){try{return localStorage.getItem(be)===`1`}catch{return!1}}function Se(e){try{localStorage.setItem(be,e?`1`:`0`)}catch{}}function Ce(e){let t=window.speechSynthesis.getVoices(),n=e.slice(0,2);return t.find(t=>t.lang===e&&t.default)??t.find(t=>t.lang===e)??t.find(e=>e.lang.startsWith(n)&&e.default)??t.find(e=>e.lang.startsWith(n))??null}function we(e,t=d,n=!1){if(!H||!e.trim())return;let r=window.speechSynthesis;n&&r.cancel();let i=t===`de`?`de-DE`:`en-US`,a=new SpeechSynthesisUtterance(e.trim().slice(0,2e3));a.lang=i;let o=Ce(i);o&&(a.voice=o),r.speak(a)}function Te(){H&&window.speechSynthesis.cancel()}function Ee(){let[e,t]=(0,V.useState)(()=>H&&xe()),n=(0,V.useCallback)(e=>{t(e),Se(e),e||Te()},[]);return(0,V.useEffect)(()=>{H&&window.speechSynthesis.getVoices()},[]),(0,V.useEffect)(()=>()=>Te(),[]),[e,n]}function De(e,t,n,r){let i=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!e){i.current=null;return}let a=n.map(e=>e.key);if(!i.current){i.current=new Set(a);let e=[...n].reverse().find(e=>e.who===`bot`&&e.spoken!==!1);if(e){let n=r(e.key);n&&we(n,t,!0)}return}let o=n.filter(e=>!i.current?.has(e.key));for(let e of a)i.current.add(e);o.some(e=>e.who===`me`)&&Te();for(let e of o)if(e.who===`bot`&&e.spoken!==!1){let n=r(e.key);n&&we(n,t)}},[e,t,n,r])}var U=e(n(),1),Oe=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function ke({since:e}){let[t,n]=(0,V.useState)(Date.now());if((0,V.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:p(`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)(m,{className:`size-5`}):a})}function Ae({voice:e}){let t=(0,V.useRef)(null),{captions:n}=e;return(0,V.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:p(`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 je({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,o=e.state===`connecting`,[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1);(0,V.useEffect)(()=>{c(i?Date.now():null)},[i]);let d=async()=>{u(!1),await e.start(),n&&await e.startCamera()},h=()=>{e.stop(),u(!0)},g=n||e.camera,_=[...e.captions].reverse().find(e=>e.who===`bot`),v=[...e.captions].reverse().find(e=>e.who===`me`),y=e.speaking?f(`talk.speaking`):e.listening?f(`talk.listening`):i?f(`talk.live`):o?f(`talk.connecting`):l?f(`video.ended`):``;return(0,U.jsxs)(`section`,{className:p(`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??``}),y?(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,U.jsx)(`span`,{className:p(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,y]}):null,(0,U.jsx)(ke,{since:s})]}),(0,U.jsxs)(`div`,{className:p(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,g?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!g&&i&&e.captions.length?`h-[38%]`:g?``:`flex-1`),children:[(0,U.jsxs)(`div`,{className:p(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!g&&`hidden`),children:[(0,U.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:p(`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)(ge,{className:`size-8`}),(0,U.jsx)(`span`,{className:`text-[0.8125rem]`,children:f(`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:[f(`video.you`),e.muted?(0,U.jsx)(ue,{className:`ml-1.5 inline size-3`}):null]})]}),(0,U.jsxs)(`div`,{className:p(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,g?`bg-neutral-900`:`bg-transparent`,g&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,U.jsx)(`div`,{className:p(`rounded-full transition-shadow duration-500`,!g&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!g&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,U.jsx)(z,{kind:t?.wizard.avatar??`round`,size:g?140:200,fluffy:!0,interactive:!1})}),g?(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&&!g?(0,U.jsx)(Ae,{voice:e}):i&&(_||v)?(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:[v?(0,U.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:v.text}):null,_?(0,U.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:_.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:f(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,U.jsx)(ue,{className:`size-5`}):(0,U.jsx)(a,{className:`size-5`})}),(0,U.jsx)(W,{label:f(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(ge,{className:`size-5`})}),e.camera&&Oe?(0,U.jsx)(W,{label:f(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,U.jsx)(k,{className:`size-5`})}):null,(0,U.jsx)(W,{label:f(`video.leave`),danger:!0,onClick:h,children:(0,U.jsx)(fe,{className:`size-5`})})]}):(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:o||!t?.talk,onClick:()=>void d(),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:[o?(0,U.jsx)(m,{className:`size-4`}):n?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(a,{className:`size-5`}),f(l?`video.rejoin`:n?`video.join`:`talk.start`)]}),!l&&!e.error?(0,U.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:f(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Me=e=>ne[e.kind]!==`device`,Ne=1024,Pe=4e3;function Fe(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function Ie(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: ${g(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}: ${Fe(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=Me(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?` = ${Fe(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}": ${Fe(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 Le(e,t,n,r){let[i,a]=(0,V.useState)(`off`),[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1),[d,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(`environment`),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)([]),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=(0,V.useRef)(0),T=(0,V.useRef)(!1);T.current=m;let E=(0,V.useRef)(null),D=(0,V.useRef)(null),O=(0,V.useRef)(null),k=(0,V.useRef)(null),A=(0,V.useRef)(t);A.current=t;let j=(0,V.useRef)(r);j.current=r;let M=(0,V.useRef)(n);M.current=n;let N=(0,V.useRef)(``),P=(0,V.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,V.useCallback)(()=>{let e=S.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,Ne/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,V.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,S.current&&(S.current.srcObject=null),h(!1)},[]),L=(0,V.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;_(n===`user`||n===`environment`?n:t),S.current&&(S.current.srcObject=e,await S.current.play().catch(()=>void 0)),h(!0)}catch(e){c(e.name===`NotAllowedError`?f(`talk.cameraDenied`):e.message)}},[]),R=(0,V.useCallback)(async()=>{let e=g===`user`?`environment`:`user`;I(),await L(e)},[g,I,L]),ee=(0,V.useCallback)(()=>{y(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,V.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),p(!1),y(!1),a(`off`)},[I]);(0,V.useEffect)(()=>()=>z(),[z]);let B=(0,V.useCallback)(async(t,n)=>{let r=A.current,i=j.current,a=M.current;switch(t){case`get_state`:return r?Ie(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`}),s=await o.upload(`/api/runs/${e}/uploads`,a),c=i.values[t.id],l=t.multiple?[...Array.isArray(c)?c:c?[c]:[],s.id]:s.id,u=i.setField(t.id,l);return u?`refused: ${u}`:`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&&Me(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 o.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,V.useCallback)(async()=>{if(!E.current){c(null),x([]),a(`connecting`);try{let t=await o.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`:{p(!0);let e=Date.now()-w.current>Pe?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`:p(!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`;x(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=Ie(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(`${f(`talk.failed`)} (${d.status})`);await r.setRemoteDescription({type:`answer`,sdp:await d.text()})}catch(e){z(),c(e.name===`NotAllowedError`?f(`chat.micDenied`):e.message),a(`error`)}}},[e,B,F,P,z]);return(0,V.useEffect)(()=>{if(i!==`live`||!t)return;let e=Ie(t,r,m);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,m,P]),{state:i,error:s,speaking:l,listening:d,start:te,stop:z,camera:m,facing:g,startCamera:L,stopCamera:I,flipCamera:R,muted:v,toggleMute:ee,captions:b,video:S}}var G=(e,t,n)=>({key:e,who:`bot`,node:t,...n}),K=(e,t,n)=>({key:e,who:`me`,node:t,...n}),Re=(0,V.createContext)(null),q=(0,V.createContext)(null);function ze(){return(0,V.useContext)(q)?.voice??null}function Be({children:e}){let t=(0,V.useContext)(Re);return t?(0,ye.createPortal)(e,t):null}function Ve({header:e,footer:t,children:n}){let[r,i]=(0,V.useState)(null),a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=(0,V.useRef)(!0);return(0,V.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)(Re.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,V.useContext)(q),r=(0,V.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),i=(0,V.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);De(!!n?.readAloud,n?.lang??d,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)(z,{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:p(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?p(`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)(I,{className:`size-3`}),` `,f(`chat.change`)]}):null]},e.key)))}function He(){return(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":f(`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:p(`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)(m,{className:`size-4`}):null,t]})}function Ue({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:o,inputRef:s,onSend:c}){let[d,g]=(0,V.useState)(e),_=(0,V.useRef)(null),b=s??_,S=(0,V.useContext)(q),C=y(d,g,{endpoint:S?`/api/runs/${S.runId}/transcribe`:void 0}),w=!!S&&C.supported&&!o;(0,V.useEffect)(()=>{if(!w)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),C.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,C.toggle]),(0,V.useEffect)(()=>{!ie&&!o&&b.current?.focus()},[o,b]);let T=()=>{i||o||(C.listening&&C.toggle(),c(d)!==!1&&g(``))},E=C.listening?f(`chat.listening`):C.processing?f(`chat.transcribing`):t,D=S?.voice??null,O=!!S?.call,k=S&&!O&&(H||w||D)?(0,U.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[D?(0,U.jsx)(v,{label:f(D.state===`live`?`talk.stop`:D.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":D.state===`live`,disabled:D.state===`connecting`,onClick:()=>D.state===`live`?D.stop():void D.start(),className:p(`size-9`,D.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,D.state===`off`&&S.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:D.state===`connecting`?(0,U.jsx)(m,{className:`size-4`}):D.state===`live`?(0,U.jsx)(fe,{className:`size-4`}):(0,U.jsx)(x,{className:`size-4`})}):null,D?.state===`live`?(0,U.jsx)(v,{label:f(D.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":D.camera,onClick:()=>D.camera?D.stopCamera():void D.startCamera(),className:p(`size-9`,D.camera&&`text-ink`),children:D.camera?(0,U.jsx)(R,{className:`size-4`}):(0,U.jsx)(ge,{className:`size-4`})}):null,H?(0,U.jsx)(v,{label:f(S.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":S.readAloud,onClick:()=>S.setReadAloud(!S.readAloud),className:p(`size-9`,S.readAloud&&`text-ink`),children:S.readAloud?(0,U.jsx)(ee,{className:`size-4`}):(0,U.jsx)(ve,{className:`size-4`})}):null,w?(0,U.jsx)(v,{label:f(C.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":C.listening,disabled:C.processing,onClick:C.toggle,className:p(`size-9`,C.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:C.processing?(0,U.jsx)(m,{className:`size-4`}):C.listening?(0,U.jsx)(u,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,U.jsx)(a,{className:`size-4`})}):null]}):null;return(0,U.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),T()},children:[D&&!O?(0,U.jsx)(`video`,{ref:D.video,muted:!0,playsInline:!0,autoPlay:!0,className:p(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,D.camera?`block`:`hidden`)}):null,(0,U.jsxs)(`div`,{className:p(`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`,o&&`opacity-60`),children:[k,n?(0,U.jsx)(h,{ref:b,minRows:1,maxRows:6,value:d,disabled:o,placeholder:E,autoCapitalize:`sentences`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!ie&&!e.nativeEvent.isComposing&&(e.preventDefault(),T())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,U.jsx)(`input`,{ref:b,...r,value:d,disabled:o,placeholder:E,enterKeyHint:`send`,onChange:e=>g(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":f(`chat.send`),title:f(`chat.send`),disabled:i||o,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)(m,{className:`size-4`}):(0,U.jsx)(l,{className:`size-4`})})]}),C.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:C.error===`denied`?f(`chat.micDenied`):C.error}):O?null:D?.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:D.error}):D?.state===`live`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:D.speaking?f(`talk.speaking`):D.listening?f(`talk.listening`):f(`talk.live`)}):S?.talk&&D?.state===`off`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:f(`talk.hint`)}):null]})}function Q({placeholder:e=f(`chat.above`)}){return(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{disabled:!0,placeholder:e,onSend:()=>!1})})}function We(e){let t=ne[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Ge=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Ke(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Ge(t))return e.required&&!n?f(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return f(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return f(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?f(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?f(`run.filesMin`,{n:t.length,min:e.min}):null}function qe(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 Je({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 Ye({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 Xe({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,U.jsx)(U.Fragment,{children:typeof t==`string`&&t?t:f(`chat.connected`)});if(e.kind===`list`)return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(s,{className:`size-4`}),` `,f(`chat.checked`)]});if(e.kind===`toggle`)return(0,U.jsx)(U.Fragment,{children:f(t===!0?`run.yes`:`run.no`)});if(Ge(t))return(0,U.jsx)(`span`,{className:`italic opacity-80`,children:f(`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(d,{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:i(`/api/runs/${n}/assets/${t}`),alt:``,className:p(`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)(b,{className:`size-4`}),` `,f(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)(a,{className:`size-4`}),` `,f(`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:f(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,U.jsx)(U.Fragment,{children:String(t)})}}function Ze(e,t,n,r,i,a){let o=[G(t,(0,U.jsx)(Ye,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,U.jsx)(Je,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,U.jsx)(Xe,{field:e,value:n[e.id],runId:r})));return o}var Qe=(e,t)=>e.fields.filter(e=>!e.when&&!te(e)||t[e.id]!==void 0&&t[e.id]!==null);function $e(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(...Ze(r,i,e.values,e.id,Qe(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`,f(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function et(e,t){return e.fields.filter(e=>!te(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function tt({view:e,run:t,step:n,before:r}){let i=(0,V.useMemo)(()=>et(n,e),[n,e]),a=e.known??{},[o,s]=(0,V.useState)(()=>A(n,e)),[c,l]=(0,V.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?B(et(n,e),e.known??{},A(n,e)).slice(0,-1).map(e=>e.id):[]),[u,d]=(0,V.useState)({}),[p,m]=(0,V.useState)(!1),[h,g]=(0,V.useState)(!1),_=B(i,a,o),v=_.filter(e=>c.includes(e.id)),y=_.find(e=>!c.includes(e.id)),b=i.length===1?i[0]:void 0,x=v.at(-1),C=x?()=>l(e=>e.filter(e=>e!==x.id)):void 0;(0,V.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=B(i,a,o),r=n.findIndex(t=>e.includes(t.id));r>=0&&(l(n.slice(0,r).map(e=>e.id)),d(t.fieldErrors))},[t.fieldErrors]);let w=e=>{t.submitPage(n.id,e).then(g)},T=(0,V.useContext)(q),E=(0,V.useRef)(o);E.current=o;let D=T?.bindPage,O=(0,V.useRef)(w);O.current=w,(0,V.useEffect)(()=>{if(!D)return;let e=B(i,a,o);return D({step:n,fields:e,values:o,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Ke(r,n)||(s(e=>({...e,[t]:n})),l(e=>e.includes(t)?e:[...e,t]),d({}),null):`no such field on this page`},submit:()=>O.current(E.current)}),()=>D(null)},[D,n,i,a,o]);let k=e=>{if(!y)return!1;let t=Ke(y,e);if(t)return d({[y.id]:t}),!1;let n={...o,[y.id]:e},r=[...c,y.id];return s(n),l(r),d({}),B(i,a,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>c.length?{...e,onEdit:void 0}:e),...Ze(n,`now:${n.id}`,o,e.id,v,b).map((e,t,n)=>t===n.length-1&&e.who===`me`&&y?{...e,onEdit:C}:e)];y?(We(y)===`control`?j.push(G(`now:${n.id}:${y.id}:control`,(0,U.jsx)(S,{field:y,value:o[y.id],values:o,runId:e.id,view:e,closed:e.closed?.[y.id],onChange:e=>s(t=>({...t,[y.id]:e})),onBusy:m}),{wide:!0})):b||j.push(G(`now:${n.id}:${y.id}`,(0,U.jsx)(Je,{field:y}))),u[y.id]&&j.push(G(`now:${n.id}:${y.id}:error`,u[y.id],{tone:`error`}))):t.busy||h?j.push(G(`sending`,(0,U.jsx)(He,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,U.jsx)(Q,{});if(h||!y&&c.length>0&&t.busy)M=(0,U.jsx)(Q,{placeholder:f(`run.working`)});else if(!y)j.push(X(`now:${n.id}:go`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>w(o),children:n.cta||f(`run.next`)}),C?(0,U.jsx)(Z,{onClick:C,disabled:t.busy,children:f(`run.back`)}):null]})));else{let r=We(y),i=!y.required&&y.kind!==`connection`&&y.kind!==`list`?(0,U.jsx)(Z,{onClick:()=>k(void 0),children:f(`chat.skip`)}):null;if(r===`typed`){i&&j.push(X(`now:${n.id}:${y.id}:replies`,i));let e=o[y.id];M=(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{initial:Ge(e)?``:String(e),multiline:y.kind===`textarea`,placeholder:y.placeholder||(b?y.label:f(`chat.placeholder`)),inputProps:nt(y),busy:t.busy,onSend:e=>k(qe(y,e))},y.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${y.id}:replies`,(0,U.jsx)(rt,{field:y,view:e,value:o[y.id],onAnswer:k}),{bare:!0}));else{let e=_.filter(e=>!c.includes(e.id)).length===1;j.push(X(`now:${n.id}:${y.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,disabled:p,onClick:()=>k(o[y.id]),children:e&&n.cta?n.cta:f(`chat.send`)}),i]})))}}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function nt(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 j(e)}}function rt({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,o]=(0,V.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:f(`run.no`)}),(0,U.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:f(`run.yes`)})]});let s=e.options??[];return e.kind===`multiselect`?(0,U.jsxs)(Y,{children:[s.map(e=>(0,U.jsx)(Z,{on:a.includes(e),onClick:()=>o(t=>t.includes(e)?t.filter(t=>t!==e):s.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?f(`chat.send`):f(`chat.skip`)})]}):(0,U.jsxs)(Y,{children:[s.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:f(`chat.skip`)})]})}function it({view:e}){let t=(0,V.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,V.useState)(Date.now());(0,V.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[]);let o=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),s=o.at(-1),c=[...o].reverse().find(ot),l=[...new Set(o.map(e=>e.asset).filter(e=>!!e))];return(0,U.jsxs)(`div`,{className:p(`flex max-w-full flex-col gap-1`,c?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??f(`run.working`),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(He,{}),(0,U.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??f(`run.working`)}),(0,U.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:f(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),s&&s!==c?(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,U.jsx)(L,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,U.jsx)(`span`,{className:`truncate`,children:g(s)})]}):null,c&&e.status===`running`?(0,U.jsx)(ct,{runId:e.id,event:c}):null,l.length?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:l.slice(-6).map(t=>(0,U.jsx)(`img`,{src:i(`/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 at=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function ot(e){return!!e.note&&at.has(e.note.code)}var st=1e4;function ct({runId:e,event:t}){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(`agent`),[s,c]=(0,V.useState)(!1),l=t.note?.code;if((0,V.useEffect)(()=>{l===`personDrives`?a(`person`):l===`agentDrives`&&a(`agent`)},[l]),(0,V.useEffect)(()=>{let t=()=>o.get(`/api/runs/${e}/browser/seat`).then(e=>a(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,st);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,d=async()=>{c(!0);try{let t=await o.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});a(t.seat)}catch{}finally{c(!1)}};return(0,U.jsx)(T,{runId:e,driving:u,caption:g(t),hint:f(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,U.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:p(`flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] shadow-soft transition-colors disabled:opacity-60`,u?`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:[u?(0,U.jsx)(me,{className:`size-3.5`}):(0,U.jsx)(ce,{className:`size-3.5`}),f(u?`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 lt({view:e,run:t,step:n,before:r,asked:i,onNote:a}){let o=e.shown.filter(e=>e.output),[c,l]=(0,V.useState)(o.length===1?o[0].step.id:null),u=(0,V.useRef)(null),d=[...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}),...o.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)(oe,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{l(t.id),u.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)(P,{runId:e.id,list:t}):(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&d.push(G(`review-error`,t.error,{tone:`error`}));let p=n.regenerate&&o.length>0;return d.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)(s,{className:`size-4`}),` `,f(`run.accept`)]}),p&&o.length>1?o.map(({step:e})=>(0,U.jsx)(Z,{on:c===e.id,onClick:()=>l(e.id),children:e.title},e.id)):null]}))),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:d}),p?(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{multiline:!0,inputRef:u,busy:t.busy,placeholder:o.length>1&&!c?f(`run.feedbackPick`):f(`run.feedbackPlaceholder`),disabled:!c,onSend:e=>{let r=e.trim();return!r||!c?!1:(a(r),t.regenerate(n.id,c,r),!0)}})}):(0,U.jsx)(Q,{})]})}function ut({view:e,run:t,step:n,before:r,onRestart:i}){let a=e.shown.filter(e=>e.output),o=`/api/runs/${e.id}`,s=[...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)(ae,{base:o,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,U.jsx)(oe,{base:o,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:f(`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)(C,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return s.push(X(`result:replies`,(0,U.jsxs)(U.Fragment,{children:[a.length?(0,U.jsx)(M,{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)(E,{className:`size-4`}),` `,f(`run.again`)]}):null,e.canBack?(0,U.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:f(`run.back`)}):null,e.keeps?(0,U.jsx)(`span`,{className:`ml-1`,children:(0,U.jsx)(F,{runId:e.id})}):null]}))),(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:s})}function dt({runId:e,onRestart:t,onView:n,header:r,footer:i,talk:a=!1,call:o=!1}){let s=D(e),{view:c}=s,[l,u]=(0,V.useState)(null),p=Le(e,c,s,l);(0,V.useEffect)(()=>{n?.(c)},[c,n]);let[h,g]=Ee(),v=(0,V.useMemo)(()=>({runId:e,lang:c?.lang??d,readAloud:h,setReadAloud:g,voice:c?.talk?p:null,talk:a,call:!!o,bindPage:u}),[e,c?.lang,c?.talk,h,g,p,a,o]);re(c?.status===`running`&&!c.ask),N(c);let[y,b]=(0,V.useState)({}),[x,S]=(0,V.useState)(null);(0,V.useEffect)(()=>{c&&c.status!==`running`&&S(null)},[c]);let C;if(s.notFound)C=(0,U.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:f(`run.notFound`)});else if(!c)C=(0,U.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,U.jsx)(m,{})});else{let e=c.step,n=c.status===`waiting_input`,r=$e(c,c.canBack&&n&&!s.busy?()=>void s.back():void 0);if(c.status===`running`&&c.ask)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`ask:${c.ask.id}`,(0,U.jsx)(w,{runId:c.id,ask:c.ask}),{wide:!0})]}),(0,U.jsx)(Q,{})]});else if(c.status===`running`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,...x?[K(`note`,x)]:[],G(`working:${e?.id}`,(0,U.jsx)(it,{view:c}),{wide:c.events.some(t=>t.stepId===e?.id&&ot(t))?`most`:void 0})]}),(0,U.jsx)(Q,{placeholder:f(`run.working`)})]});else if(c.status===`failed`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`failed`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:f(`run.failed`)}),c.error?(0,U.jsx)(`span`,{className:`mt-0.5 block`,children:(0,U.jsx)(_,{text:c.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:s.busy,onClick:()=>void s.retry(),children:[(0,U.jsx)(E,{className:`size-4`}),` `,f(`run.retry`)]}),c.canBack?(0,U.jsx)(Z,{onClick:()=>void s.back(),disabled:s.busy,children:f(`run.back`)}):null]}))]}),(0,U.jsx)(Q,{})]});else if(c.status===`cancelled`)C=(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`cancelled`,f(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,U.jsxs)(Z,{primary:!0,onClick:t,children:[(0,U.jsx)(E,{className:`size-4`}),` `,f(`run.again`)]}))]:[]]});else if(e?.type===`page`)C=(0,U.jsx)(tt,{view:c,run:s,step:e,before:r},e.id);else if(e?.type===`review`){let t=c.shown.map(e=>e.output?.at??``).join(`|`);C=(0,U.jsx)(lt,{view:c,run:s,step:e,before:r,asked:y[e.id]??[],onNote:t=>{S(t),b(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else C=e?.type===`result`?(0,U.jsx)(ut,{view:c,run:s,step:e,before:r,onRestart:t}):(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:r})}return o?(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,U.jsx)(je,{voice:p,view:c,video:o===`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)(Ve,{footer:i,children:C})})]})}):(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsx)(Ve,{header:r,footer:i,children:C})})}export{J as a,Z as i,Ve as n,X as o,Q as r,ze as s,dt as t};
|