wizards 0.2.42 → 0.2.43

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.
Files changed (165) hide show
  1. package/apps/runtime/dist/app.js +37 -3
  2. package/apps/runtime/dist/authoring/guide.js +5 -2
  3. package/apps/runtime/dist/browser/fast/action-space.js +162 -0
  4. package/apps/runtime/dist/browser/fast/classifier.js +91 -0
  5. package/apps/runtime/dist/browser/fast/decide.js +171 -0
  6. package/apps/runtime/dist/browser/fast/driver.js +141 -0
  7. package/apps/runtime/dist/browser/fast/instructions.js +33 -0
  8. package/apps/runtime/dist/browser/fast/run.js +249 -0
  9. package/apps/runtime/dist/browser/fast/span-picker.js +153 -0
  10. package/apps/runtime/dist/browser/fast/text-helper.js +178 -0
  11. package/apps/runtime/dist/browser/snapshot.js +335 -0
  12. package/apps/runtime/dist/db/migrations/tenant/0011_runners.sql +2 -0
  13. package/apps/runtime/dist/db/migrations/tenant/meta/0011_snapshot.json +2956 -0
  14. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
  15. package/apps/runtime/dist/db/schema.js +4 -0
  16. package/apps/runtime/dist/engine/resources.js +109 -0
  17. package/apps/runtime/dist/engine/runner.js +7 -3
  18. package/apps/runtime/dist/engine/steps.js +89 -10
  19. package/apps/runtime/dist/env.js +9 -0
  20. package/apps/runtime/dist/harness/claude.js +9 -1
  21. package/apps/runtime/dist/link-preview.js +4 -3
  22. package/apps/runtime/dist/mcp/tools.js +1 -1
  23. package/apps/runtime/dist/media/conversation.js +177 -0
  24. package/apps/runtime/dist/models.js +17 -0
  25. package/apps/runtime/dist/plugins/loader.js +48 -2
  26. package/apps/runtime/dist/plugins/registry.js +1 -0
  27. package/apps/runtime/dist/plugins/runs.js +205 -0
  28. package/apps/runtime/dist/routes/runs.js +206 -22
  29. package/apps/runtime/dist/routes/studio.js +12 -1
  30. package/apps/runtime/dist/services/cloud.js +1 -0
  31. package/apps/runtime/dist/services/runners.js +138 -0
  32. package/apps/runtime/dist/services/runs.js +83 -45
  33. package/apps/runtime/dist/services/wizard-icon.js +12 -0
  34. package/apps/runtime/dist/services/wizards.js +5 -1
  35. package/apps/runtime/dist/tools/browser.js +426 -97
  36. package/apps/runtime/dist/tools/index.js +50 -3
  37. package/apps/web/dist/assets/ChangelogDialog-8qS5utcR.js +1 -0
  38. package/apps/web/dist/assets/ChatView-Bx1KVCEf.js +10 -0
  39. package/apps/web/dist/assets/{CreditsDialog-DPglouDr.js → CreditsDialog-BCuDsatt.js} +1 -1
  40. package/apps/web/dist/assets/EditorPage-_Sbj-mSD.js +3 -0
  41. package/apps/web/dist/assets/{FlowPreview-CQN5acxA.js → FlowPreview-COgjib4H.js} +1 -1
  42. package/apps/web/dist/assets/{Harness-BFxUFB7B.js → Harness-BaxjV1Ng.js} +2 -2
  43. package/apps/web/dist/assets/HomePage-BlD0wZB0.js +1 -0
  44. package/apps/web/dist/assets/ImportWizard-BZDtNJg1.js +1 -0
  45. package/apps/web/dist/assets/NewWizardPage-Ci_x__p9.js +2 -0
  46. package/apps/web/dist/assets/ProjectPage-NwFut2Z-.js +2 -0
  47. package/apps/web/dist/assets/PublicRunner-rHdvK18v.js +1 -0
  48. package/apps/web/dist/assets/RunDrawer-Dp-JowDX.js +4 -0
  49. package/apps/web/dist/assets/RunnerView-DSlReODC.js +2 -0
  50. package/apps/web/dist/assets/SettingsPage-2Bw-D3hC.js +1 -0
  51. package/apps/web/dist/assets/SetupPage-DHESCsTb.js +1 -0
  52. package/apps/web/dist/assets/SharePage-DdJ-qD-B.js +1 -0
  53. package/apps/web/dist/assets/ThemeSwitch-BkodFy16.js +1 -0
  54. package/apps/web/dist/assets/arrow-right-pf8p4FIz.js +1 -0
  55. package/apps/web/dist/assets/changelog-cmQb-lZW.js +1 -0
  56. package/apps/web/dist/assets/{circle-alert-B0rwkpC7.js → circle-alert-Gn4D6etf.js} +1 -1
  57. package/apps/web/dist/assets/{copy-DgbMaHoj.js → copy-C3D7PBYL.js} +1 -1
  58. package/apps/web/dist/assets/{definition-FVgbAXOo.js → definition-AlI4g-wR.js} +2 -2
  59. package/apps/web/dist/assets/{external-link-pP6YfR9-.js → external-link-M3mEgZA-.js} +1 -1
  60. package/apps/web/dist/assets/globe-BnaeE83w.js +1 -0
  61. package/apps/web/dist/assets/{image-D2X6TWdq.js → image-BuasG4Jr.js} +1 -1
  62. package/apps/web/dist/assets/index-BdrX1tJ4.js +78 -0
  63. package/apps/web/dist/assets/index-D6vcOCCh.css +1 -0
  64. package/apps/web/dist/assets/{lock-BG4mi_lJ.js → lock-CrB_z7n3.js} +1 -1
  65. package/apps/web/dist/assets/{meta-BD9yulXs.js → meta-CT4LmQ7g.js} +1 -1
  66. package/apps/web/dist/assets/mouse-pointer-click-BurvPVO8.js +1 -0
  67. package/apps/web/dist/assets/{pen-line-D54vxrGl.js → pen-line-BA6l84zC.js} +1 -1
  68. package/apps/web/dist/assets/{refresh-cw-DvTgdpdf.js → refresh-cw-DEKCEuIO.js} +1 -1
  69. package/apps/web/dist/assets/{session-CT1AZIlE.js → session-DCcgTTmG.js} +1 -1
  70. package/apps/web/dist/assets/{settings-menu-DJATAPGg.js → settings-menu-C9fE9M0f.js} +1 -1
  71. package/apps/web/dist/assets/star-BwhVXiJM.js +1 -0
  72. package/apps/web/dist/assets/{trash-DAcf34LR.js → trash-WwlTeE_V.js} +1 -1
  73. package/apps/web/dist/assets/{type-BU0mWqf3.js → type-kpWj7Zf1.js} +1 -1
  74. package/apps/web/dist/assets/ui-Wxaw_APn.js +9 -0
  75. package/apps/web/dist/assets/{video-C6qoFAAs.js → video-U-idAC66.js} +1 -1
  76. package/apps/web/dist/assets/volume-2-BwidpioC.js +1 -0
  77. package/apps/web/dist/assets/{wand-sparkles-Bw4tu2An.js → wand-sparkles-DaINku4r.js} +1 -1
  78. package/apps/web/dist/embed.js +119 -4
  79. package/apps/web/dist/index.html +12 -11
  80. package/apps/web/dist/mcp/flow.html +45 -45
  81. package/modules/calls/dist/client.css +3 -0
  82. package/modules/calls/dist/client.js +1 -0
  83. package/modules/calls/engenty.plugin.json +8 -0
  84. package/modules/calls/migrations/0001_init.sql +26 -0
  85. package/modules/calls/package.json +25 -0
  86. package/modules/calls/src/openai.ts +155 -0
  87. package/modules/calls/src/plugin.ts +407 -0
  88. package/modules/calls/src/rules.ts +226 -0
  89. package/modules/calls/src/schema.ts +39 -0
  90. package/modules/calls/src/session.ts +353 -0
  91. package/modules/calls/src/store.ts +124 -0
  92. package/modules/calls/src/twilio.ts +90 -0
  93. package/modules/calls/tsconfig.json +10 -0
  94. package/modules/calls/ui/Settings.tsx +137 -0
  95. package/modules/calls/ui/app.ts +50 -0
  96. package/modules/calls/ui/messages.ts +81 -0
  97. package/modules/calls/ui/parts.tsx +36 -0
  98. package/modules/calls/ui/plugin.tsx +15 -0
  99. package/modules/sms/dist/client.css +3 -0
  100. package/modules/sms/dist/client.js +1 -0
  101. package/modules/sms/engenty.plugin.json +8 -0
  102. package/modules/sms/migrations/0001_init.sql +26 -0
  103. package/modules/sms/package.json +25 -0
  104. package/modules/sms/src/plugin.ts +324 -0
  105. package/modules/sms/src/schema.ts +26 -0
  106. package/modules/sms/src/store.ts +140 -0
  107. package/modules/sms/src/surface.ts +70 -0
  108. package/modules/sms/src/twilio.ts +130 -0
  109. package/modules/sms/tsconfig.json +10 -0
  110. package/modules/sms/ui/Settings.tsx +113 -0
  111. package/modules/sms/ui/Share.tsx +78 -0
  112. package/modules/sms/ui/app.ts +51 -0
  113. package/modules/sms/ui/messages.ts +72 -0
  114. package/modules/sms/ui/parts.tsx +36 -0
  115. package/modules/sms/ui/plugin.tsx +20 -0
  116. package/modules/whatsapp/dist/client.css +3 -0
  117. package/modules/whatsapp/dist/client.js +1 -0
  118. package/modules/whatsapp/engenty.plugin.json +8 -0
  119. package/modules/whatsapp/migrations/0001_init.sql +30 -0
  120. package/modules/whatsapp/package.json +25 -0
  121. package/modules/whatsapp/src/graph.ts +271 -0
  122. package/modules/whatsapp/src/inbound.ts +143 -0
  123. package/modules/whatsapp/src/plugin.ts +369 -0
  124. package/modules/whatsapp/src/schema.ts +32 -0
  125. package/modules/whatsapp/src/store.ts +156 -0
  126. package/modules/whatsapp/src/surface.ts +127 -0
  127. package/modules/whatsapp/tsconfig.json +10 -0
  128. package/modules/whatsapp/ui/Settings.tsx +141 -0
  129. package/modules/whatsapp/ui/Share.tsx +78 -0
  130. package/modules/whatsapp/ui/app.ts +54 -0
  131. package/modules/whatsapp/ui/messages.ts +82 -0
  132. package/modules/whatsapp/ui/parts.tsx +36 -0
  133. package/modules/whatsapp/ui/plugin.tsx +20 -0
  134. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +259 -0
  135. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +17 -0
  136. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.d.ts +174 -0
  137. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +816 -0
  138. package/node_modules/@engenty-wizards/plugin-sdk/package.json +2 -1
  139. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -0
  140. package/node_modules/@engenty-wizards/shared/dist/definition.js +21 -0
  141. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +61 -3
  142. package/node_modules/@engenty-wizards/shared/dist/run.js +16 -0
  143. package/node_modules/@engenty-wizards/shared/dist/runners.d.ts +81 -0
  144. package/node_modules/@engenty-wizards/shared/dist/runners.js +146 -0
  145. package/package.json +1 -1
  146. package/apps/web/dist/assets/ChangelogDialog-BxRBTR8P.js +0 -1
  147. package/apps/web/dist/assets/EditorPage-BKAFzzWk.js +0 -3
  148. package/apps/web/dist/assets/HomePage-BZuwrr-b.js +0 -1
  149. package/apps/web/dist/assets/ImportWizard-JGMemER4.js +0 -1
  150. package/apps/web/dist/assets/NewWizardPage-BwHAsJwj.js +0 -2
  151. package/apps/web/dist/assets/ProjectPage--ijr1jPE.js +0 -2
  152. package/apps/web/dist/assets/PublicRunner-D9Oe-_vs.js +0 -1
  153. package/apps/web/dist/assets/RunDrawer-BfociUm2.js +0 -4
  154. package/apps/web/dist/assets/RunnerView-D2b84UTY.js +0 -2
  155. package/apps/web/dist/assets/SettingsPage-9rk9IRdr.js +0 -1
  156. package/apps/web/dist/assets/SetupPage-BUJh_v9q.js +0 -1
  157. package/apps/web/dist/assets/SharePage-sNJ_s1RE.js +0 -1
  158. package/apps/web/dist/assets/ThemeSwitch-NDTEeh0R.js +0 -1
  159. package/apps/web/dist/assets/arrow-right-C1xLSnNa.js +0 -1
  160. package/apps/web/dist/assets/changelog-BSVi9hHS.js +0 -1
  161. package/apps/web/dist/assets/index-CBjgitjd.js +0 -78
  162. package/apps/web/dist/assets/index-gTcC8eX6.css +0 -1
  163. package/apps/web/dist/assets/star-CaOg5c-D.js +0 -1
  164. package/apps/web/dist/assets/ui-Bxf6zX5k.js +0 -9
  165. package/apps/web/dist/assets/volume-2-Dw4p9Ln4.js +0 -1
@@ -0,0 +1,141 @@
1
+ import { Button, Card, Input, Label, Spinner } from "@engenty-wizards/web/ui";
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
+ import { useEffect, useState } from "react";
4
+ import { type AccountView, api, errorText, KEY, t } from "./app";
5
+ import { Shown } from "./parts";
6
+
7
+ /** Settings → WhatsApp: the number, the token, and what to enter in the Meta app. */
8
+ export function SettingsSection() {
9
+ const cache = useQueryClient();
10
+ const account = useQuery({
11
+ queryKey: [KEY, "account"],
12
+ queryFn: () => api().get<AccountView>("/account"),
13
+ });
14
+ const [form, setForm] = useState({
15
+ phoneNumberId: "",
16
+ number: "",
17
+ accessToken: "",
18
+ appSecret: "",
19
+ template: "",
20
+ });
21
+ const [to, setTo] = useState("");
22
+ useEffect(() => {
23
+ if (account.data) {
24
+ setForm((f) => ({
25
+ ...f,
26
+ phoneNumberId: account.data.phoneNumberId,
27
+ number: account.data.number,
28
+ template: account.data.template,
29
+ }));
30
+ }
31
+ }, [account.data]);
32
+ const refresh = () => cache.invalidateQueries({ queryKey: [KEY] });
33
+ const save = useMutation({
34
+ mutationFn: () =>
35
+ api().put<AccountView>("/account", {
36
+ phoneNumberId: form.phoneNumberId,
37
+ number: form.number,
38
+ accessToken: form.accessToken || undefined,
39
+ appSecret: form.appSecret || undefined,
40
+ template: form.template || null,
41
+ }),
42
+ onSuccess: async () => {
43
+ setForm((f) => ({ ...f, accessToken: "", appSecret: "" }));
44
+ await refresh();
45
+ },
46
+ });
47
+ const remove = useMutation({
48
+ mutationFn: () => api().del<AccountView>("/account"),
49
+ onSuccess: refresh,
50
+ });
51
+ const test = useMutation({
52
+ mutationFn: () => api().post<{ ok: boolean }>("/account/test", { to }),
53
+ });
54
+ const set = (key: keyof typeof form) => (e: React.ChangeEvent<HTMLInputElement>) =>
55
+ setForm((f) => ({ ...f, [key]: e.target.value }));
56
+ const data = account.data;
57
+ return (
58
+ <section className="flex flex-col gap-2.5">
59
+ <h2 className="px-1 font-display font-semibold text-lg leading-tight">{t("title")}</h2>
60
+ <Card className="flex flex-col gap-4 p-5 text-[0.875rem]">
61
+ <p className="text-[0.8125rem] text-ink-3">{t("intro")}</p>
62
+ {account.isLoading ? <Spinner className="mx-auto" /> : null}
63
+ <div>
64
+ <Label hint={t("phoneNumberIdHint")}>{t("phoneNumberId")}</Label>
65
+ <Input value={form.phoneNumberId} onChange={set("phoneNumberId")} autoComplete="off" />
66
+ </div>
67
+ <div>
68
+ <Label hint={t("numberHint")}>{t("number")}</Label>
69
+ <Input value={form.number} onChange={set("number")} inputMode="numeric" />
70
+ </div>
71
+ <div>
72
+ <Label hint={data?.hasToken ? t("tokenKept") : t("tokenHint")}>{t("token")}</Label>
73
+ <Input
74
+ type="password"
75
+ value={form.accessToken}
76
+ onChange={set("accessToken")}
77
+ placeholder={data?.hasToken ? "••••••••" : ""}
78
+ autoComplete="new-password"
79
+ />
80
+ </div>
81
+ <div>
82
+ <Label hint={t("secretHint")}>{t("secret")}</Label>
83
+ <Input
84
+ type="password"
85
+ value={form.appSecret}
86
+ onChange={set("appSecret")}
87
+ placeholder={data?.hasSecret ? "••••••••" : ""}
88
+ autoComplete="new-password"
89
+ />
90
+ </div>
91
+ <div>
92
+ <Label hint={t("templateHint")}>{t("template")}</Label>
93
+ <Input value={form.template} onChange={set("template")} autoComplete="off" />
94
+ </div>
95
+ <div className="flex items-center gap-3">
96
+ <Button onClick={() => save.mutate()} busy={save.isPending}>
97
+ {t("save")}
98
+ </Button>
99
+ {data?.connected ? (
100
+ <Button variant="ghost" onClick={() => remove.mutate()} busy={remove.isPending}>
101
+ {t("disconnect")}
102
+ </Button>
103
+ ) : null}
104
+ {save.isSuccess ? (
105
+ <span className="text-[0.8125rem] text-ink-3">{t("saved")}</span>
106
+ ) : null}
107
+ </div>
108
+ {save.error ? <p className="text-[0.8125rem] text-rose">{errorText(save.error)}</p> : null}
109
+ </Card>
110
+ {data?.connected ? (
111
+ <Card className="flex flex-col gap-4 p-5 text-[0.875rem]">
112
+ <div className="font-medium">{t("meta")}</div>
113
+ <p className="text-[0.8125rem] text-ink-3">{t("metaHint")}</p>
114
+ <Shown label={t("webhook")} value={data.webhook} />
115
+ {data.verifyToken ? <Shown label={t("verifyToken")} value={data.verifyToken} /> : null}
116
+ <div>
117
+ <Label>{t("testTo")}</Label>
118
+ <div className="flex items-center gap-2">
119
+ <Input
120
+ value={to}
121
+ onChange={(e) => setTo(e.target.value)}
122
+ placeholder="+43 660 …"
123
+ inputMode="tel"
124
+ className="max-w-xs"
125
+ />
126
+ <Button variant="secondary" onClick={() => test.mutate()} busy={test.isPending}>
127
+ {t("sendTest")}
128
+ </Button>
129
+ </div>
130
+ {test.isSuccess ? (
131
+ <p className="mt-2 text-[0.8125rem] text-ink-3">{t("testSent")}</p>
132
+ ) : null}
133
+ {test.error ? (
134
+ <p className="mt-2 text-[0.8125rem] text-rose">{errorText(test.error)}</p>
135
+ ) : null}
136
+ </div>
137
+ </Card>
138
+ ) : null}
139
+ </section>
140
+ );
141
+ }
@@ -0,0 +1,78 @@
1
+ import type { StudioShareSectionProps } from "@engenty-wizards/plugin-sdk/studio";
2
+ import { Input } from "@engenty-wizards/web/ui";
3
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
+ import { useMemo, useState } from "react";
5
+ import { renderSVG } from "uqr";
6
+ import { api, type Binding, errorText, KEY, t } from "./app";
7
+ import { CopyButton } from "./parts";
8
+
9
+ /** Under the WhatsApp row of the share dialog: the keyword, the link that writes it, its QR code. */
10
+ export function ShareSection({ wizard }: StudioShareSectionProps) {
11
+ const cache = useQueryClient();
12
+ const binding = useQuery({
13
+ queryKey: [KEY, "binding", wizard.id],
14
+ queryFn: () => api().get<Binding>(`/binding/${wizard.id}`),
15
+ });
16
+ const [draft, setDraft] = useState<string | null>(null);
17
+ const save = useMutation({
18
+ mutationFn: (keyword: string) => api().put<Binding>(`/binding/${wizard.id}`, { keyword }),
19
+ onSuccess: async () => {
20
+ setDraft(null);
21
+ await cache.invalidateQueries({ queryKey: [KEY, "binding", wizard.id] });
22
+ },
23
+ });
24
+ const link = binding.data?.link ?? null;
25
+ const svg = useMemo(
26
+ () => (link ? renderSVG(link, { ecc: "M", border: 1, pixelSize: 6 }) : ""),
27
+ [link],
28
+ );
29
+ if (!binding.data) {
30
+ return null;
31
+ }
32
+ const keyword = draft ?? binding.data.keyword;
33
+ const commit = () => {
34
+ if (draft?.trim() && draft.trim() !== binding.data?.keyword) {
35
+ save.mutate(draft);
36
+ } else {
37
+ setDraft(null);
38
+ }
39
+ };
40
+ return (
41
+ <div className="flex items-start gap-3 rounded-lg bg-paper-2 p-3 text-[0.8125rem]">
42
+ {svg ? (
43
+ <div
44
+ role="img"
45
+ aria-label={t("link")}
46
+ className="size-20 shrink-0 overflow-hidden rounded bg-white [&>svg]:size-full"
47
+ // uqr writes the SVG from the link alone: no markup of anyone else's goes in.
48
+ // biome-ignore lint/security/noDangerouslySetInnerHtml: generated from the URL only
49
+ dangerouslySetInnerHTML={{ __html: svg }}
50
+ />
51
+ ) : null}
52
+ <div className="flex min-w-0 flex-1 flex-col gap-1.5">
53
+ <label className="flex items-center gap-2">
54
+ <span className="shrink-0 text-ink-3">{t("keyword")}</span>
55
+ <Input
56
+ value={keyword}
57
+ onChange={(e) => setDraft(e.target.value)}
58
+ onBlur={commit}
59
+ onKeyDown={(e) => {
60
+ if (e.key === "Enter") {
61
+ e.currentTarget.blur();
62
+ }
63
+ }}
64
+ className="h-8 max-w-xs text-[0.8125rem]"
65
+ />
66
+ </label>
67
+ {link ? (
68
+ <div className="flex min-w-0 items-center gap-1">
69
+ <span className="select-all truncate text-ink-3">{link}</span>
70
+ <CopyButton text={link} />
71
+ </div>
72
+ ) : null}
73
+ <p className="text-ink-3">{t("keywordHint")}</p>
74
+ {save.error ? <p className="text-rose">{errorText(save.error)}</p> : null}
75
+ </div>
76
+ </div>
77
+ );
78
+ }
@@ -0,0 +1,54 @@
1
+ import type { StudioPluginContext } from "@engenty-wizards/plugin-sdk/studio";
2
+ import { messages } from "./messages";
3
+
4
+ /** The studio this half was handed, and its words. */
5
+
6
+ let current: StudioPluginContext | null = null;
7
+ let translate: ((key: string, vars?: Record<string, string | number>) => string) | null = null;
8
+
9
+ export function setStudio(studio: StudioPluginContext) {
10
+ current = studio;
11
+ translate = studio.i18n.register(messages) as typeof translate;
12
+ }
13
+
14
+ export function studio(): StudioPluginContext {
15
+ if (!current) {
16
+ throw new Error("The WhatsApp plugin is not loaded.");
17
+ }
18
+ return current;
19
+ }
20
+
21
+ export type Key = keyof (typeof messages)["de"];
22
+ export const t = (key: Key, vars?: Record<string, string | number>) =>
23
+ translate?.(key, vars) ?? key;
24
+ export const api = () => studio().api;
25
+
26
+ export const KEY = "whatsapp";
27
+
28
+ /** What a failed request says, in the person's language. */
29
+ export function errorText(error: unknown): string {
30
+ const body = (error as { body?: { code?: string; error?: string } } | null)?.body;
31
+ const code = body?.code;
32
+ const message = body?.error ?? (error instanceof Error ? error.message : String(error));
33
+ if (code && `error_${code}` in messages.de) {
34
+ return t(`error_${code}` as Key, { message });
35
+ }
36
+ return t("error_other", { message });
37
+ }
38
+
39
+ export interface AccountView {
40
+ connected: boolean;
41
+ phoneNumberId: string;
42
+ number: string;
43
+ hasToken: boolean;
44
+ hasSecret: boolean;
45
+ template: string;
46
+ verifyToken: string | null;
47
+ webhook: string;
48
+ }
49
+
50
+ export interface Binding {
51
+ keyword: string;
52
+ link: string | null;
53
+ number: string | null;
54
+ }
@@ -0,0 +1,82 @@
1
+ /** The studio half's words. `de` is the source. */
2
+ export const messages = {
3
+ de: {
4
+ title: "WhatsApp",
5
+ intro:
6
+ "Wizards laufen in einem WhatsApp-Thread auf der eigenen Business-Nummer. Dafür braucht es eine Meta-App mit dem Produkt WhatsApp: die ID der Telefonnummer und einen dauerhaften Access Token aus dem Meta-Dashboard.",
7
+ phoneNumberId: "Phone number ID",
8
+ phoneNumberIdHint: "Im Meta-Dashboard unter WhatsApp → API-Setup.",
9
+ number: "Nummer",
10
+ numberHint: "Mit Ländervorwahl, nur Ziffern: 43660…",
11
+ token: "Access Token",
12
+ tokenHint: "Ein dauerhafter Token eines System-Users mit whatsapp_business_messaging.",
13
+ tokenKept: "Ist hinterlegt. Leer lassen, um ihn zu behalten.",
14
+ secret: "App Secret",
15
+ secretHint: "Freiwillig. Damit wird jede Nachricht von Meta auf ihre Signatur geprüft.",
16
+ template: "Template",
17
+ templateHint:
18
+ "Freiwillig. Der Name eines genehmigten Utility-Templates mit einem Platzhalter im Text: damit meldet sich der Wizard nach einem Tag Stille mit dem Link.",
19
+ save: "Speichern",
20
+ saved: "Gespeichert.",
21
+ disconnect: "Trennen",
22
+ meta: "In der Meta-App eintragen",
23
+ metaHint:
24
+ "Unter WhatsApp → Konfiguration: die Webhook-Adresse und den Verify Token eintragen, dann das Feld „messages“ abonnieren.",
25
+ webhook: "Webhook-Adresse",
26
+ verifyToken: "Verify Token",
27
+ copy: "Kopieren",
28
+ copied: "Kopiert",
29
+ testTo: "Testnachricht an",
30
+ sendTest: "Senden",
31
+ testSent: "Angekommen? Dann passt alles.",
32
+ keyword: "Stichwort",
33
+ keywordHint:
34
+ "Wer dieses Wort an die Nummer schreibt, startet den Wizard. Der Link und der QR-Code schreiben es vor.",
35
+ link: "Link",
36
+ error_bad_keyword:
37
+ "Ein Stichwort besteht aus Buchstaben, Ziffern, Leerzeichen und Bindestrichen, bis zu 40.",
38
+ error_keyword_taken: "Ein anderer Wizard hat dieses Stichwort schon.",
39
+ error_no_token: "Es braucht einen Access Token.",
40
+ error_provider: "WhatsApp hat die Nachricht nicht angenommen: {message}",
41
+ error_other: "{message}",
42
+ },
43
+ en: {
44
+ title: "WhatsApp",
45
+ intro:
46
+ "Wizards run in a WhatsApp thread on your own business number. It takes a Meta app with the WhatsApp product: the phone number's ID and a permanent access token from the Meta dashboard.",
47
+ phoneNumberId: "Phone number ID",
48
+ phoneNumberIdHint: "In the Meta dashboard under WhatsApp → API setup.",
49
+ number: "Number",
50
+ numberHint: "With the country code, digits only: 43660…",
51
+ token: "Access token",
52
+ tokenHint: "A permanent token of a system user with whatsapp_business_messaging.",
53
+ tokenKept: "Is set. Leave empty to keep it.",
54
+ secret: "App secret",
55
+ secretHint: "Optional. With it, every message from Meta is checked for its signature.",
56
+ template: "Template",
57
+ templateHint:
58
+ "Optional. The name of an approved utility template with one placeholder in its text: the wizard reaches back with the link after a day of silence.",
59
+ save: "Save",
60
+ saved: "Saved.",
61
+ disconnect: "Disconnect",
62
+ meta: "Enter in the Meta app",
63
+ metaHint:
64
+ "Under WhatsApp → Configuration: enter the webhook address and the verify token, then subscribe to the “messages” field.",
65
+ webhook: "Webhook address",
66
+ verifyToken: "Verify token",
67
+ copy: "Copy",
68
+ copied: "Copied",
69
+ testTo: "Test message to",
70
+ sendTest: "Send",
71
+ testSent: "Arrived? Then everything is set.",
72
+ keyword: "Keyword",
73
+ keywordHint:
74
+ "Whoever writes this word to the number starts the wizard. The link and the QR code write it for them.",
75
+ link: "Link",
76
+ error_bad_keyword: "A keyword is letters, digits, spaces and dashes, up to 40.",
77
+ error_keyword_taken: "Another wizard has this keyword already.",
78
+ error_no_token: "An access token is needed.",
79
+ error_provider: "WhatsApp did not take the message: {message}",
80
+ error_other: "{message}",
81
+ },
82
+ } as const;
@@ -0,0 +1,36 @@
1
+ import { IconButton } from "@engenty-wizards/web/ui";
2
+ import { Check, Copy } from "lucide-react";
3
+ import { useState } from "react";
4
+ import { t } from "./app";
5
+
6
+ /** A value to take along: the webhook address, the verify token, the link. */
7
+ export function CopyButton({ text }: { text: string }) {
8
+ const [done, setDone] = useState(false);
9
+ return (
10
+ <IconButton
11
+ label={t(done ? "copied" : "copy")}
12
+ className="size-8"
13
+ onClick={() => {
14
+ void navigator.clipboard.writeText(text).then(() => {
15
+ setDone(true);
16
+ setTimeout(() => setDone(false), 1500);
17
+ });
18
+ }}
19
+ >
20
+ {done ? <Check className="size-4" /> : <Copy className="size-4" />}
21
+ </IconButton>
22
+ );
23
+ }
24
+
25
+ /** A value shown as it is, with the button that copies it. */
26
+ export function Shown({ label, value }: { label: string; value: string }) {
27
+ return (
28
+ <div className="flex items-center gap-2">
29
+ <div className="min-w-0 flex-1">
30
+ <div className="text-[0.8125rem] text-ink-3">{label}</div>
31
+ <div className="select-all truncate font-mono text-[0.8125rem]">{value}</div>
32
+ </div>
33
+ <CopyButton text={value} />
34
+ </div>
35
+ );
36
+ }
@@ -0,0 +1,20 @@
1
+ import { defineStudioPlugin } from "@engenty-wizards/plugin-sdk/studio";
2
+ import { MessageCircle } from "lucide-react";
3
+ import { setStudio, t } from "./app";
4
+ import { SettingsSection } from "./Settings";
5
+ import { ShareSection } from "./Share";
6
+
7
+ /**
8
+ * The studio half: the number and the token in the settings, and the keyword with its link
9
+ * under the WhatsApp row of the share dialog. Everything talks to src/plugin.ts.
10
+ */
11
+ export default defineStudioPlugin((studio) => {
12
+ setStudio(studio);
13
+ studio.registerSettingsSection({
14
+ id: "whatsapp",
15
+ label: () => t("title"),
16
+ icon: MessageCircle,
17
+ component: SettingsSection,
18
+ });
19
+ studio.registerShareSection({ runner: "whatsapp", component: ShareSection });
20
+ });
@@ -532,8 +532,267 @@ export interface PluginAssistantPage {
532
532
  /** Text for the assistant: the state of the page, in a few lines. Cut at 8,000 characters. */
533
533
  block(space: PluginSpace): string | null | Promise<string | null>;
534
534
  }
535
+ /** What a runner can take in and show; the runtime works out per wizard how far it gets. */
536
+ export interface PluginRunnerCapabilities {
537
+ /** The field kinds the runner asks itself (`text`, `select`, `image`, …); the rest hand off. */
538
+ input: string[];
539
+ output: {
540
+ /** What it shows as it is: `text`, `data`, `image`, `video`, `voice`, `document`, `dashboard`, `widget`, `film`, `surface`. */
541
+ shows: string[];
542
+ /** What it shows as a picture with a link to the real thing. Anything else is a link. */
543
+ pictures: string[];
544
+ };
545
+ /** A sign-in is typed on a page the model never sees: only a browser can take it. */
546
+ asks: ("confirm" | "login")[];
547
+ review: ("accept" | "regenerate" | "edit")[];
548
+ /** Stays through a step that takes minutes, with a note now and then. */
549
+ waits: boolean;
550
+ /** How a link to the run page reaches the person for what the runner cannot do itself. */
551
+ handoff: ("screen" | "thread" | "sms" | "push")[];
552
+ }
553
+ /** What a page runner's handler gets: the wizard behind the address, nobody signed in. */
554
+ export interface PluginRunnerRequest {
555
+ request: Request;
556
+ tenantId: string;
557
+ wizard: {
558
+ id: string;
559
+ token: string;
560
+ title: string;
561
+ };
562
+ /** The rest of the address below `/w/<token>/<runner>`. */
563
+ path: string;
564
+ query: URLSearchParams;
565
+ }
566
+ /**
567
+ * A runner: a door a wizard runs through, beside the built-in page and chat. A `page` runner is
568
+ * served at `/w/<token>/<id>` for every wizard that switched it on; a `channel` runner has an
569
+ * address of its own (a number, a bot) and drives runs from its webhooks.
570
+ */
571
+ export interface PluginRunner {
572
+ /** Lower case, digits and "-", at most 24 characters; the sub-path of the wizard's address. */
573
+ id: string;
574
+ label: {
575
+ de: string;
576
+ en: string;
577
+ };
578
+ kind: "page" | "channel";
579
+ capabilities: PluginRunnerCapabilities;
580
+ /** A page runner: what its address answers with. */
581
+ page?(request: PluginRunnerRequest): Response | Promise<Response>;
582
+ /**
583
+ * Why the runner cannot be used in the current tenant right now, in the owner's words ("Not
584
+ * connected: Settings → WhatsApp"), or null when it can. Asked inside the tenant whenever the
585
+ * studio lists the runners; a runner with a problem cannot be switched on.
586
+ */
587
+ problem?(): string | null | Promise<string | null>;
588
+ }
589
+ /** How a run answers a review: accept it, with edited texts where the review allows, or ask for one of the shown steps again. */
590
+ export type PluginReviewAction = {
591
+ type: "accept";
592
+ edits?: Record<string, string>;
593
+ } | {
594
+ type: "regenerate";
595
+ target: string;
596
+ note: string;
597
+ items?: number[];
598
+ };
599
+ /** A field of the page a run waits for, as the report lists it. */
600
+ export interface PluginRunField {
601
+ id: string;
602
+ label: string;
603
+ kind: string;
604
+ required: boolean;
605
+ options?: string[];
606
+ placeholder?: string;
607
+ help?: string;
608
+ default?: unknown;
609
+ value?: unknown;
610
+ columns?: unknown;
611
+ /** An image or file field that takes several: the value is then a list of asset ids. */
612
+ multiple?: boolean;
613
+ /** Answerable as a value; false for what only the person's device gives (a file, a signature). */
614
+ inChat: boolean;
615
+ /** A condition on earlier answers; the field is asked only while it holds. */
616
+ when?: unknown;
617
+ /** Whether `when` holds on what is known now. */
618
+ shown?: boolean;
619
+ }
620
+ /** What a run waits for: a page, a review, or a question of a running step. */
621
+ export type PluginRunWaiting = {
622
+ page: string;
623
+ title: string;
624
+ known: Record<string, unknown>;
625
+ fields: PluginRunField[];
626
+ hint: string;
627
+ } | {
628
+ review: string;
629
+ title: string;
630
+ show: string[];
631
+ editable: boolean;
632
+ hint: string;
633
+ } | {
634
+ ask: string;
635
+ kind: "confirm";
636
+ reason: string;
637
+ service: string;
638
+ action: string;
639
+ input: string;
640
+ hint: string;
641
+ } | {
642
+ ask: string;
643
+ kind: "login";
644
+ reason: string;
645
+ site: string;
646
+ hint: string;
647
+ };
648
+ /** What a run did so far, as the MCP tools report it: outputs with signed links, cost, errors. */
649
+ export interface PluginRunReport {
650
+ runId: string;
651
+ wizardId: string;
652
+ mode: "test" | "live";
653
+ /** The wizard's language: what to say to the person in. */
654
+ lang: "de" | "en";
655
+ status: "waiting_input" | "running" | "done" | "failed" | "cancelled";
656
+ step: {
657
+ id: string;
658
+ type: string;
659
+ title: string;
660
+ } | null;
661
+ passed: string[];
662
+ waitingFor?: PluginRunWaiting;
663
+ error: string | null;
664
+ credits: number;
665
+ events: {
666
+ step: string | null;
667
+ type: string;
668
+ message: string;
669
+ }[];
670
+ outputs: {
671
+ stepId: string;
672
+ title: string;
673
+ text?: string;
674
+ json?: string;
675
+ assets: {
676
+ name: string;
677
+ mime: string;
678
+ url: string;
679
+ }[];
680
+ /** Signed download links by format, valid one hour. */
681
+ downloads: Record<string, string>;
682
+ /** A signed link to the output as a PNG, for a door that shows a picture with a link; null where it is one already, or has no picture. */
683
+ picture: string | null;
684
+ }[];
685
+ /** The run page, for what the door cannot do itself. */
686
+ browserUrl: string | null;
687
+ }
688
+ /** Something changed on a run: a new event, or its status (`event` null). */
689
+ export interface PluginRunSignal {
690
+ runId: string;
691
+ event: {
692
+ id: number;
693
+ at: string;
694
+ stepId: string | null;
695
+ type: "step_started" | "step_done" | "tool" | "info" | "error";
696
+ message: string;
697
+ /** The same as the run page shows it, in both languages; null for free text. */
698
+ note: {
699
+ code: string;
700
+ text: {
701
+ de: string;
702
+ en: string;
703
+ };
704
+ } | null;
705
+ } | null;
706
+ }
707
+ /**
708
+ * Runs a plugin's door drives: the functions behind the MCP tools, on the public path. The
709
+ * plugin keeps who the person is; the runtime keeps only a hash of it as the run's visitor, so
710
+ * what the wizard remembers is theirs on the run page too.
711
+ */
712
+ export interface PluginRuns {
713
+ /** Starts a live run of a published wizard, by its share token or id, for a person of the door. */
714
+ start(input: ({
715
+ token: string;
716
+ } | {
717
+ wizardId: string;
718
+ }) & {
719
+ person: {
720
+ channel: string;
721
+ id: string;
722
+ };
723
+ /** Answers for the first page; what did not fit comes back as `refused`. */
724
+ answers?: Record<string, unknown>;
725
+ /** Kept on the run; default: the plugin's id. */
726
+ runner?: string;
727
+ }): Promise<{
728
+ runId: string;
729
+ /** Opens the run's own routes (`/api/runs/<id>?rt=…`); `handoffUrl` carries it. */
730
+ ticket: string;
731
+ refused: {
732
+ field: string;
733
+ message: string;
734
+ }[] | null;
735
+ }>;
736
+ /**
737
+ * The run as it stands, after waiting up to `waitSeconds` (at most 45) while it works. A door
738
+ * that asks a page one field at a time passes what it has as `draft`: the fields' `shown` is
739
+ * then worked out on those answers, so a field whose condition depends on another of the same
740
+ * page comes and goes as it would on the screen.
741
+ */
742
+ report(runId: string, options?: {
743
+ waitSeconds?: number;
744
+ draft?: Record<string, unknown>;
745
+ }): Promise<PluginRunReport>;
746
+ /** The published wizards of the tenant that switched the given runner on: what the door offers. */
747
+ wizards(runner: string): Promise<{
748
+ wizardId: string;
749
+ token: string;
750
+ title: string;
751
+ lang: "de" | "en";
752
+ }[]>;
753
+ answerPage(runId: string, stepId: string, values: Record<string, unknown>): Promise<void>;
754
+ review(runId: string, stepId: string, action: PluginReviewAction): Promise<void>;
755
+ /** A running step asks before it changes something in a connected account: allow it once, or skip. */
756
+ answerAsk(runId: string, askId: string, answer: "allow" | "skip"): Promise<void>;
757
+ control(runId: string, action: "back" | "retry" | "cancel"): Promise<void>;
758
+ /** Hears every change of the run until the function returned is called. */
759
+ subscribe(runId: string, listener: (signal: PluginRunSignal) => void): () => void;
760
+ /** The run page with the run's ticket: the link to send the person for what the door cannot do. */
761
+ handoffUrl(runId: string): Promise<string>;
762
+ /** A file of the person (a photo sent in the thread): the asset id goes into a field with `answerPage`. */
763
+ upload(runId: string, file: {
764
+ data: Uint8Array | ArrayBuffer;
765
+ mime: string;
766
+ name: string;
767
+ }): Promise<{
768
+ assetId: string;
769
+ }>;
770
+ /** What is said in a recording of the person (a voice message), written down and charged to the run. */
771
+ transcribe(runId: string, file: {
772
+ data: Uint8Array | ArrayBuffer;
773
+ mime: string;
774
+ }): Promise<{
775
+ text: string;
776
+ }>;
777
+ }
535
778
  export interface PluginServerApi {
536
779
  registerHttpRoute(route: PluginRoute): void;
780
+ /** A runner the owner can switch on per wizard. */
781
+ registerRunner(runner: PluginRunner): void;
782
+ /** Runs the plugin's door drives. */
783
+ runs: PluginRuns;
784
+ /**
785
+ * The tenant's realtime speech model, for a live conversation a plugin drives itself (a call):
786
+ * the key and the model the chat's live voice runs on. Throws with the status `503` and the
787
+ * code `no_model` while none is set up.
788
+ */
789
+ speech: {
790
+ conversation(): Promise<{
791
+ provider: "openai";
792
+ apiKey: string;
793
+ model: string;
794
+ }>;
795
+ };
537
796
  registerTool<S extends z.ZodType>(tool: PluginTool<S>): void;
538
797
  /** A block and tools for every agent step of a space's wizards. */
539
798
  registerSpaceContext(context: PluginSpaceContext): void;