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
|
@@ -22,6 +22,17 @@ export interface PluginManifest {
|
|
|
22
22
|
studio?: string;
|
|
23
23
|
/** The studio half's styles, built. Default `dist/client.css`. */
|
|
24
24
|
styles?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The plugin's feature switches, by short name; each is known as `<id>.<name>` everywhere
|
|
27
|
+
* (`wizards features`, the `.features` file, the Manage-App's admin). `true`/`false` is the
|
|
28
|
+
* default alone; a `plan` switch is one a plan includes.
|
|
29
|
+
*/
|
|
30
|
+
features?: Record<string, boolean | {
|
|
31
|
+
kind?: "release" | "plan";
|
|
32
|
+
default?: boolean;
|
|
33
|
+
label?: string;
|
|
34
|
+
hint?: string;
|
|
35
|
+
}>;
|
|
25
36
|
}
|
|
26
37
|
export type PluginRole = "owner" | "admin" | "member";
|
|
27
38
|
/** The signed-in person a request acts as. */
|
|
@@ -297,6 +308,28 @@ export interface PluginDocumentResult {
|
|
|
297
308
|
/** Why a person should look at it: hardly readable, or not readable at all. */
|
|
298
309
|
review: string | null;
|
|
299
310
|
}
|
|
311
|
+
/** A page of a space, as a plugin reads it. */
|
|
312
|
+
export interface PluginSpacePage {
|
|
313
|
+
id: string;
|
|
314
|
+
title: string;
|
|
315
|
+
/** How a step names it: `pages/…`. */
|
|
316
|
+
path: string;
|
|
317
|
+
parentId: string | null;
|
|
318
|
+
markdown: string;
|
|
319
|
+
/** The plugin that wrote it, or null for one made in the studio or uploaded. */
|
|
320
|
+
origin: string | null;
|
|
321
|
+
originKey: string | null;
|
|
322
|
+
updatedAt: string;
|
|
323
|
+
}
|
|
324
|
+
/** A file of a space, as a plugin reads it. */
|
|
325
|
+
export interface PluginSpaceFile {
|
|
326
|
+
id: string;
|
|
327
|
+
name: string;
|
|
328
|
+
mime: string;
|
|
329
|
+
size: number;
|
|
330
|
+
kind: "logo" | "asset" | "document";
|
|
331
|
+
updatedAt: string;
|
|
332
|
+
}
|
|
300
333
|
/** What a plugin wrote into a space. */
|
|
301
334
|
export interface PluginSpaceItem {
|
|
302
335
|
key: string;
|
|
@@ -345,6 +378,19 @@ export interface PluginSpaceData {
|
|
|
345
378
|
putDocument(input: PluginDocumentInput): Promise<PluginDocumentResult>;
|
|
346
379
|
/** Everything the plugin wrote into the space. */
|
|
347
380
|
list(space: string): Promise<PluginSpaceItem[]>;
|
|
381
|
+
/**
|
|
382
|
+
* The space's own pages (not a wizard's), whoever wrote them, with their Markdown: for a
|
|
383
|
+
* plugin that reads what the space knows. `parent`: only the pages under that page.
|
|
384
|
+
*/
|
|
385
|
+
readPages(space: string, opts?: {
|
|
386
|
+
parent?: string;
|
|
387
|
+
}): Promise<PluginSpacePage[]>;
|
|
388
|
+
/** The space's files of a kind (`document` when left out), newest first. */
|
|
389
|
+
files(space: string, kind?: "logo" | "asset" | "document"): Promise<PluginSpaceFile[]>;
|
|
390
|
+
/** One file of the space with its bytes: a price list someone dropped into Wissen. */
|
|
391
|
+
readFile(space: string, fileId: string): Promise<PluginSpaceFile & {
|
|
392
|
+
data: Uint8Array;
|
|
393
|
+
}>;
|
|
348
394
|
/** Takes out one key, or every item of the plugin in the space; what a person changed stays. */
|
|
349
395
|
remove(space: string, key?: string): Promise<number>;
|
|
350
396
|
/**
|
|
@@ -397,6 +443,11 @@ export interface PluginWebPage {
|
|
|
397
443
|
url: string;
|
|
398
444
|
text: string;
|
|
399
445
|
}[];
|
|
446
|
+
/**
|
|
447
|
+
* The page's structured data: its `application/ld+json` blocks, parsed, a `@graph` spread
|
|
448
|
+
* out. A shop's product page says title, price, availability and image here exactly.
|
|
449
|
+
*/
|
|
450
|
+
jsonld: unknown[];
|
|
400
451
|
}
|
|
401
452
|
export interface PluginWeb {
|
|
402
453
|
/**
|
|
@@ -475,16 +526,30 @@ export interface PluginConnection {
|
|
|
475
526
|
* the tokens sealed, refreshes them, and on a local install connects Google through the linked
|
|
476
527
|
* account's Manage-App, as it does for wizards.
|
|
477
528
|
*/
|
|
529
|
+
/** A connector a plugin may connect: signed in with OAuth, or with keys the person types. */
|
|
530
|
+
export interface PluginConnectorOffer {
|
|
531
|
+
id: string;
|
|
532
|
+
name: string;
|
|
533
|
+
auth: "oauth2" | "api_key";
|
|
534
|
+
/** `api_key`: what to ask the person for, in this order. */
|
|
535
|
+
fields?: {
|
|
536
|
+
key: string;
|
|
537
|
+
label: string;
|
|
538
|
+
placeholder?: string;
|
|
539
|
+
/** Default: true. */
|
|
540
|
+
required?: boolean;
|
|
541
|
+
/** A password field: never shown again. */
|
|
542
|
+
secret?: boolean;
|
|
543
|
+
}[];
|
|
544
|
+
}
|
|
478
545
|
export interface PluginConnections {
|
|
479
546
|
/** Of these connector ids, the ones a person can connect on this runtime now, with their names. */
|
|
480
|
-
available(connectors: string[]): Promise<
|
|
481
|
-
id: string;
|
|
482
|
-
name: string;
|
|
483
|
-
}[]>;
|
|
547
|
+
available(connectors: string[]): Promise<PluginConnectorOffer[]>;
|
|
484
548
|
/**
|
|
485
|
-
* The provider's sign-in page. Open it in a window: when the person
|
|
486
|
-
* `{ type: "wizards:connected", ok }` to the studio and closes.
|
|
487
|
-
* actions the plugin will call; only the rights they need are
|
|
549
|
+
* The provider's sign-in page of an `oauth2` connector. Open it in a window: when the person
|
|
550
|
+
* is done, the window posts `{ type: "wizards:connected", ok }` to the studio and closes.
|
|
551
|
+
* `actions` are the connector's actions the plugin will call; only the rights they need are
|
|
552
|
+
* asked for.
|
|
488
553
|
*/
|
|
489
554
|
start(input: {
|
|
490
555
|
space: string;
|
|
@@ -493,6 +558,18 @@ export interface PluginConnections {
|
|
|
493
558
|
}): Promise<{
|
|
494
559
|
url: string;
|
|
495
560
|
}>;
|
|
561
|
+
/**
|
|
562
|
+
* Connects an `api_key` connector with the keys the person typed (`fields` of the offer, by
|
|
563
|
+
* key). The connector tries them once first; keys it refuses throw an error with the status
|
|
564
|
+
* `400` and the code `credentials`, whose message says what was wrong. The same account
|
|
565
|
+
* connected again for the space replaces the first connection's keys and actions.
|
|
566
|
+
*/
|
|
567
|
+
connect(input: {
|
|
568
|
+
space: string;
|
|
569
|
+
connector: string;
|
|
570
|
+
actions: string[];
|
|
571
|
+
credentials: Record<string, string>;
|
|
572
|
+
}): Promise<PluginConnection>;
|
|
496
573
|
/** What is connected for the space, the newest first. */
|
|
497
574
|
list(space: string): Promise<PluginConnection[]>;
|
|
498
575
|
/** One connection by its id, or null. */
|
|
@@ -775,6 +852,13 @@ export interface PluginRuns {
|
|
|
775
852
|
text: string;
|
|
776
853
|
}>;
|
|
777
854
|
}
|
|
855
|
+
/** Keys a plugin keeps: sealed with the runtime's own key, as it seals a connection's tokens. */
|
|
856
|
+
export interface PluginSecrets {
|
|
857
|
+
/** Anything that is JSON, as a sealed string to keep in a table. */
|
|
858
|
+
seal(value: unknown): string;
|
|
859
|
+
/** What was sealed, or null when it was sealed on another install. */
|
|
860
|
+
unseal<T = unknown>(sealed: string): T | null;
|
|
861
|
+
}
|
|
778
862
|
export interface PluginServerApi {
|
|
779
863
|
registerHttpRoute(route: PluginRoute): void;
|
|
780
864
|
/** A runner the owner can switch on per wizard. */
|
|
@@ -833,6 +917,8 @@ export interface PluginServerApi {
|
|
|
833
917
|
generate<T = undefined>(request: PluginGenerateRequest<T>): Promise<PluginGenerateResult<T>>;
|
|
834
918
|
/** Accounts the plugin connects for a space, through the runtime's built-in connectors. */
|
|
835
919
|
connections: PluginConnections;
|
|
920
|
+
/** Keys of the plugin's own (a shop's API tokens), sealed before they go into a table. */
|
|
921
|
+
secrets: PluginSecrets;
|
|
836
922
|
/** A wizard the plugin brings as a template. */
|
|
837
923
|
registerStarter(starter: PluginStarter): void;
|
|
838
924
|
/** Something to undo when the plugin unloads or reloads: a timer, a socket. */
|
|
@@ -845,6 +931,16 @@ export interface WizardsPluginApi {
|
|
|
845
931
|
config: {
|
|
846
932
|
get(key: string): string | undefined;
|
|
847
933
|
};
|
|
934
|
+
/**
|
|
935
|
+
* Feature switches of the tenant at hand: the runtime's own (`teamPlans`) and the plugin's,
|
|
936
|
+
* named with its id (`contacts.leadScoring`), as the Manage-App, the install's `.features`
|
|
937
|
+
* file or `FEATURES` set them. Off unless something turned a switch on.
|
|
938
|
+
*/
|
|
939
|
+
features: {
|
|
940
|
+
/** `has("leadScoring")` asks for the plugin's own switch; a full name (`teamPlans`) for any. */
|
|
941
|
+
has(name: string): Promise<boolean>;
|
|
942
|
+
all(): Promise<Record<string, boolean>>;
|
|
943
|
+
};
|
|
848
944
|
log: {
|
|
849
945
|
info(...args: unknown[]): void;
|
|
850
946
|
warn(...args: unknown[]): void;
|
|
@@ -96,15 +96,56 @@ export interface StudioSpace {
|
|
|
96
96
|
/** Synced from a local install, or on a runtime where nothing is built: shown, not changed. */
|
|
97
97
|
readOnly: boolean;
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
99
|
+
/** A row under the assistant's hello: a question the person asks with one click. */
|
|
100
|
+
export interface StudioAssistantSuggestion {
|
|
101
|
+
label: string;
|
|
102
|
+
/** What is sent; the label where left out. */
|
|
103
|
+
message?: string;
|
|
104
|
+
/** Put into the field to finish ("The loafer costs … now") instead of sent at once. */
|
|
105
|
+
fill?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** The studio's assistant on a plugin's page: what it says before the first message. */
|
|
100
108
|
export interface StudioAssistantProps {
|
|
101
109
|
title?: string;
|
|
102
110
|
hello?: string;
|
|
103
111
|
/** The input's placeholder: an example of what to ask. */
|
|
104
112
|
placeholder?: string;
|
|
113
|
+
/** Up to three questions under the hello. */
|
|
114
|
+
suggestions?: StudioAssistantSuggestion[];
|
|
105
115
|
/** The assistant changed something: read the page's data again. */
|
|
106
116
|
onChanged?: () => void;
|
|
107
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* What a plugin's page shows, for the assistant: it goes up with every message, beside the
|
|
120
|
+
* page's address and title. At most 16 KiB together.
|
|
121
|
+
*/
|
|
122
|
+
export interface StudioAssistantPage extends StudioAssistantProps {
|
|
123
|
+
/** An item the page has open. */
|
|
124
|
+
open?: {
|
|
125
|
+
kind: string;
|
|
126
|
+
id?: string;
|
|
127
|
+
label: string;
|
|
128
|
+
};
|
|
129
|
+
/** Ids of what the person picked. */
|
|
130
|
+
selection?: string[];
|
|
131
|
+
/** A line on what the page holds: "12 products · 3 without a price". */
|
|
132
|
+
summary?: string;
|
|
133
|
+
/** Fields of the page with their values. */
|
|
134
|
+
fields?: {
|
|
135
|
+
id: string;
|
|
136
|
+
label: string;
|
|
137
|
+
value: unknown;
|
|
138
|
+
}[];
|
|
139
|
+
/** A page of full-height tables: the assistant starts small here. */
|
|
140
|
+
compact?: boolean;
|
|
141
|
+
}
|
|
142
|
+
/** A tool the assistant may run in the page: the shop's "filter the products". */
|
|
143
|
+
export interface StudioAssistantTool {
|
|
144
|
+
/** What it does, for the model. */
|
|
145
|
+
description: string;
|
|
146
|
+
/** Its arguments as JSON Schema (`{ type: "object", properties: { … } }`). */
|
|
147
|
+
parameters?: Record<string, unknown>;
|
|
148
|
+
}
|
|
108
149
|
export interface StudioMe {
|
|
109
150
|
user: {
|
|
110
151
|
id: string;
|
|
@@ -144,11 +185,24 @@ export interface StudioPluginContext {
|
|
|
144
185
|
to?: string;
|
|
145
186
|
}[]): void;
|
|
146
187
|
/**
|
|
147
|
-
* The
|
|
148
|
-
*
|
|
149
|
-
*
|
|
188
|
+
* The studio's assistant stands on every page; on a plugin's page this tells it what to say
|
|
189
|
+
* there (title, hello, suggestions, placeholder) and what to read again when it changed
|
|
190
|
+
* something. It talks from the plugin's page: it gets what the server half's
|
|
191
|
+
* `registerAssistantContext` says and uses the plugin's assistant tools first. Place it once,
|
|
192
|
+
* anywhere in the page; it draws nothing.
|
|
150
193
|
*/
|
|
151
194
|
Assistant: ComponentType<StudioAssistantProps>;
|
|
195
|
+
/**
|
|
196
|
+
* A hook: what the page shows, for the assistant — an open item, a selection, a summary,
|
|
197
|
+
* fields — and its words. Data may change on every render; it is read when the person sends.
|
|
198
|
+
*/
|
|
199
|
+
useAssistantPage(page: StudioAssistantPage): void;
|
|
200
|
+
/**
|
|
201
|
+
* A hook: a tool the assistant may run in the page while it is shown. Its name is prefixed
|
|
202
|
+
* with the plugin's id (`shop_filter_products`). `run` gets the arguments and returns what the
|
|
203
|
+
* assistant learns; it may change what the page shows, never save.
|
|
204
|
+
*/
|
|
205
|
+
useAssistantTool(name: string, tool: StudioAssistantTool, run: (args: Record<string, unknown>) => unknown | Promise<unknown>): void;
|
|
152
206
|
i18n: {
|
|
153
207
|
/** Takes the plugin's words and gives the function that reads them in the language in effect. */
|
|
154
208
|
register<M extends StudioMessages>(messages: M): (key: keyof M["de"] & string, vars?: Record<string, string | number>) => string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The studio's assistant between the browser and the runtime: what a page tells it, the tools
|
|
4
|
+
* the browser runs, and the events of a turn. The events are our own, shaped like AG-UI's
|
|
5
|
+
* (docs.ag-ui.com): message and tool-call ids and AG-UI's field names, so a later switch is a
|
|
6
|
+
* rename on both ends.
|
|
7
|
+
*/
|
|
8
|
+
/** A page's snapshot is cut to this many bytes of JSON. */
|
|
9
|
+
export declare const ASSISTANT_PAGE_BYTES: number;
|
|
10
|
+
/** What the page the person writes from shows; it goes up with every message. */
|
|
11
|
+
export declare const assistantPageSchema: z.ZodObject<{
|
|
12
|
+
route: z.ZodString;
|
|
13
|
+
title: z.ZodOptional<z.ZodString>;
|
|
14
|
+
view: z.ZodOptional<z.ZodString>;
|
|
15
|
+
open: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
kind: z.ZodString;
|
|
17
|
+
id: z.ZodOptional<z.ZodString>;
|
|
18
|
+
label: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
selection: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
22
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
label: z.ZodString;
|
|
25
|
+
value: z.ZodUnknown;
|
|
26
|
+
}, z.core.$strip>>>;
|
|
27
|
+
plugin: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type AssistantPage = z.infer<typeof assistantPageSchema>;
|
|
30
|
+
/** A tool the browser runs (AG-UI's `Tool`): its arguments as JSON Schema. */
|
|
31
|
+
export declare const browserToolSchema: z.ZodObject<{
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
description: z.ZodString;
|
|
34
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
export type BrowserTool = z.infer<typeof browserToolSchema>;
|
|
37
|
+
/** The browser waits no longer for a tool than this; the runtime neither. */
|
|
38
|
+
export declare const BROWSER_TOOL_TIMEOUT_MS = 60000;
|
|
39
|
+
/** What the browser sends to start a turn (AG-UI's `RunAgentInput`, cut to what we use). */
|
|
40
|
+
export declare const assistantTurnSchema: z.ZodObject<{
|
|
41
|
+
message: z.ZodString;
|
|
42
|
+
projectId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
route: z.ZodString;
|
|
45
|
+
title: z.ZodOptional<z.ZodString>;
|
|
46
|
+
view: z.ZodOptional<z.ZodString>;
|
|
47
|
+
open: z.ZodOptional<z.ZodObject<{
|
|
48
|
+
kind: z.ZodString;
|
|
49
|
+
id: z.ZodOptional<z.ZodString>;
|
|
50
|
+
label: z.ZodString;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
selection: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
54
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
label: z.ZodString;
|
|
57
|
+
value: z.ZodUnknown;
|
|
58
|
+
}, z.core.$strip>>>;
|
|
59
|
+
plugin: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
description: z.ZodString;
|
|
64
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
65
|
+
}, z.core.$strip>>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export type AssistantTurn = z.input<typeof assistantTurnSchema>;
|
|
68
|
+
/** The events of a turn, by SSE event name. */
|
|
69
|
+
export interface AssistantEvents {
|
|
70
|
+
/** The turn started; `messageId` is the stored message of the person. */
|
|
71
|
+
run_started: {
|
|
72
|
+
threadId: string;
|
|
73
|
+
runId: string;
|
|
74
|
+
messageId: string;
|
|
75
|
+
};
|
|
76
|
+
text: {
|
|
77
|
+
messageId: string;
|
|
78
|
+
delta: string;
|
|
79
|
+
};
|
|
80
|
+
/** What the assistant does right now, in a few words. */
|
|
81
|
+
activity: {
|
|
82
|
+
label: string;
|
|
83
|
+
};
|
|
84
|
+
tool_call: {
|
|
85
|
+
toolCallId: string;
|
|
86
|
+
toolCallName: string;
|
|
87
|
+
args: unknown;
|
|
88
|
+
};
|
|
89
|
+
tool_result: {
|
|
90
|
+
toolCallId: string;
|
|
91
|
+
content: string;
|
|
92
|
+
};
|
|
93
|
+
/** A plugin's tool returned what its card in the chat draws. */
|
|
94
|
+
card: {
|
|
95
|
+
toolCallId?: string;
|
|
96
|
+
plugin: string;
|
|
97
|
+
tool: string;
|
|
98
|
+
data: unknown;
|
|
99
|
+
};
|
|
100
|
+
/** The space or a plugin's data changed: the page reads its data again. */
|
|
101
|
+
changed: Record<string, never>;
|
|
102
|
+
done: {
|
|
103
|
+
messageId: string;
|
|
104
|
+
reply: string;
|
|
105
|
+
changed: boolean;
|
|
106
|
+
};
|
|
107
|
+
error: {
|
|
108
|
+
message: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** Where the assistant stands on the screen, per person. */
|
|
112
|
+
export declare const ASSISTANT_LAYOUTS: readonly ["bottom", "sidebar", "avatar"];
|
|
113
|
+
export type AssistantLayout = (typeof ASSISTANT_LAYOUTS)[number];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The studio's assistant between the browser and the runtime: what a page tells it, the tools
|
|
4
|
+
* the browser runs, and the events of a turn. The events are our own, shaped like AG-UI's
|
|
5
|
+
* (docs.ag-ui.com): message and tool-call ids and AG-UI's field names, so a later switch is a
|
|
6
|
+
* rename on both ends.
|
|
7
|
+
*/
|
|
8
|
+
/** A page's snapshot is cut to this many bytes of JSON. */
|
|
9
|
+
export const ASSISTANT_PAGE_BYTES = 16 * 1024;
|
|
10
|
+
/** What the page the person writes from shows; it goes up with every message. */
|
|
11
|
+
export const assistantPageSchema = z.object({
|
|
12
|
+
/** The studio's address: `/shop`, `/space/knowledge`. */
|
|
13
|
+
route: z.string().max(400),
|
|
14
|
+
/** What the top bar's trail says the page is. */
|
|
15
|
+
title: z.string().max(200).optional(),
|
|
16
|
+
/** The section in view: "Display and checkout". */
|
|
17
|
+
view: z.string().max(200).optional(),
|
|
18
|
+
/** An item the page has open. */
|
|
19
|
+
open: z
|
|
20
|
+
.object({
|
|
21
|
+
kind: z.string().max(60),
|
|
22
|
+
id: z.string().max(120).optional(),
|
|
23
|
+
label: z.string().max(200),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
/** Ids of what the person picked. */
|
|
27
|
+
selection: z.array(z.string().max(120)).max(100).optional(),
|
|
28
|
+
/** A line on what the page holds: "0 products · no source · prices incl. VAT". */
|
|
29
|
+
summary: z.string().max(2000).optional(),
|
|
30
|
+
/** Fields of the page with their values. */
|
|
31
|
+
fields: z
|
|
32
|
+
.array(z.object({ id: z.string().max(120), label: z.string().max(200), value: z.unknown() }))
|
|
33
|
+
.max(60)
|
|
34
|
+
.optional(),
|
|
35
|
+
/** The plugin whose page it is. */
|
|
36
|
+
plugin: z.string().max(60).optional(),
|
|
37
|
+
});
|
|
38
|
+
/** A tool the browser runs (AG-UI's `Tool`): its arguments as JSON Schema. */
|
|
39
|
+
export const browserToolSchema = z.object({
|
|
40
|
+
name: z.string().regex(/^[a-z][a-z0-9_]{1,62}$/),
|
|
41
|
+
description: z.string().max(2000),
|
|
42
|
+
parameters: z.record(z.string(), z.unknown()),
|
|
43
|
+
});
|
|
44
|
+
/** The browser waits no longer for a tool than this; the runtime neither. */
|
|
45
|
+
export const BROWSER_TOOL_TIMEOUT_MS = 60_000;
|
|
46
|
+
/** What the browser sends to start a turn (AG-UI's `RunAgentInput`, cut to what we use). */
|
|
47
|
+
export const assistantTurnSchema = z.object({
|
|
48
|
+
message: z.string().min(1).max(8000),
|
|
49
|
+
/** The space the page shows; its tools need it. */
|
|
50
|
+
projectId: z.string().max(80).optional(),
|
|
51
|
+
page: assistantPageSchema.optional(),
|
|
52
|
+
tools: z.array(browserToolSchema).max(40).default([]),
|
|
53
|
+
});
|
|
54
|
+
/** Where the assistant stands on the screen, per person. */
|
|
55
|
+
export const ASSISTANT_LAYOUTS = ["bottom", "sidebar", "avatar"];
|
|
@@ -129,6 +129,25 @@ export declare const whenSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
129
129
|
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
130
130
|
}, z.core.$strip>>]>;
|
|
131
131
|
export type When = z.infer<typeof whenSchema>;
|
|
132
|
+
/** What a card of a choice shows: the columns of the table the choices come from. */
|
|
133
|
+
export declare const cardsSchema: z.ZodObject<{
|
|
134
|
+
label: z.ZodString;
|
|
135
|
+
value: z.ZodOptional<z.ZodString>;
|
|
136
|
+
image: z.ZodOptional<z.ZodString>;
|
|
137
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
138
|
+
meta: z.ZodOptional<z.ZodString>;
|
|
139
|
+
link: z.ZodOptional<z.ZodString>;
|
|
140
|
+
}, z.core.$strip>;
|
|
141
|
+
export type CardsDef = z.infer<typeof cardsSchema>;
|
|
142
|
+
/** A choice drawn as a card, as the runner gets it. */
|
|
143
|
+
export interface CardOption {
|
|
144
|
+
value: string;
|
|
145
|
+
label: string;
|
|
146
|
+
image?: string;
|
|
147
|
+
subtitle?: string;
|
|
148
|
+
meta?: string;
|
|
149
|
+
link?: string;
|
|
150
|
+
}
|
|
132
151
|
export declare const fieldSchema: z.ZodObject<{
|
|
133
152
|
id: z.ZodString;
|
|
134
153
|
label: z.ZodString;
|
|
@@ -210,6 +229,14 @@ export declare const fieldSchema: z.ZodObject<{
|
|
|
210
229
|
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
211
230
|
}, z.core.$strip>>]>>;
|
|
212
231
|
optionsFrom: z.ZodOptional<z.ZodString>;
|
|
232
|
+
cards: z.ZodOptional<z.ZodObject<{
|
|
233
|
+
label: z.ZodString;
|
|
234
|
+
value: z.ZodOptional<z.ZodString>;
|
|
235
|
+
image: z.ZodOptional<z.ZodString>;
|
|
236
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
237
|
+
meta: z.ZodOptional<z.ZodString>;
|
|
238
|
+
link: z.ZodOptional<z.ZodString>;
|
|
239
|
+
}, z.core.$strip>>;
|
|
213
240
|
ask: z.ZodOptional<z.ZodString>;
|
|
214
241
|
group: z.ZodOptional<z.ZodString>;
|
|
215
242
|
}, z.core.$strip>;
|
|
@@ -350,6 +377,14 @@ export declare const pageStepSchema: z.ZodObject<{
|
|
|
350
377
|
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
351
378
|
}, z.core.$strip>>]>>;
|
|
352
379
|
optionsFrom: z.ZodOptional<z.ZodString>;
|
|
380
|
+
cards: z.ZodOptional<z.ZodObject<{
|
|
381
|
+
label: z.ZodString;
|
|
382
|
+
value: z.ZodOptional<z.ZodString>;
|
|
383
|
+
image: z.ZodOptional<z.ZodString>;
|
|
384
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
385
|
+
meta: z.ZodOptional<z.ZodString>;
|
|
386
|
+
link: z.ZodOptional<z.ZodString>;
|
|
387
|
+
}, z.core.$strip>>;
|
|
353
388
|
ask: z.ZodOptional<z.ZodString>;
|
|
354
389
|
group: z.ZodOptional<z.ZodString>;
|
|
355
390
|
}, z.core.$strip>>;
|
|
@@ -1025,6 +1060,14 @@ export declare const stepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1025
1060
|
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
1026
1061
|
}, z.core.$strip>>]>>;
|
|
1027
1062
|
optionsFrom: z.ZodOptional<z.ZodString>;
|
|
1063
|
+
cards: z.ZodOptional<z.ZodObject<{
|
|
1064
|
+
label: z.ZodString;
|
|
1065
|
+
value: z.ZodOptional<z.ZodString>;
|
|
1066
|
+
image: z.ZodOptional<z.ZodString>;
|
|
1067
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
1068
|
+
meta: z.ZodOptional<z.ZodString>;
|
|
1069
|
+
link: z.ZodOptional<z.ZodString>;
|
|
1070
|
+
}, z.core.$strip>>;
|
|
1028
1071
|
ask: z.ZodOptional<z.ZodString>;
|
|
1029
1072
|
group: z.ZodOptional<z.ZodString>;
|
|
1030
1073
|
}, z.core.$strip>>;
|
|
@@ -1951,6 +1994,14 @@ export declare const wizardSchema: z.ZodObject<{
|
|
|
1951
1994
|
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
1952
1995
|
}, z.core.$strip>>]>>;
|
|
1953
1996
|
optionsFrom: z.ZodOptional<z.ZodString>;
|
|
1997
|
+
cards: z.ZodOptional<z.ZodObject<{
|
|
1998
|
+
label: z.ZodString;
|
|
1999
|
+
value: z.ZodOptional<z.ZodString>;
|
|
2000
|
+
image: z.ZodOptional<z.ZodString>;
|
|
2001
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
2002
|
+
meta: z.ZodOptional<z.ZodString>;
|
|
2003
|
+
link: z.ZodOptional<z.ZodString>;
|
|
2004
|
+
}, z.core.$strip>>;
|
|
1954
2005
|
ask: z.ZodOptional<z.ZodString>;
|
|
1955
2006
|
group: z.ZodOptional<z.ZodString>;
|
|
1956
2007
|
}, z.core.$strip>>;
|
|
@@ -2586,7 +2637,11 @@ export declare function optionsFromData(ref: string, outputs: Record<string, {
|
|
|
2586
2637
|
rows: {
|
|
2587
2638
|
cells: Record<string, unknown>;
|
|
2588
2639
|
}[];
|
|
2589
|
-
}
|
|
2640
|
+
}>, cards?: CardsDef): string[];
|
|
2641
|
+
/** The rows of a table output as cards: what `optionsFrom` with `cards` finds in the run. */
|
|
2642
|
+
export declare function cardsFromData(ref: string, outputs: Record<string, {
|
|
2643
|
+
json?: unknown;
|
|
2644
|
+
}>, cards: CardsDef): CardOption[];
|
|
2590
2645
|
/** An offered appointment time read on its own clock: the offset it was written with. */
|
|
2591
2646
|
export interface SlotTime {
|
|
2592
2647
|
/** The calendar day there: "2026-10-12". */
|
|
@@ -161,6 +161,15 @@ export const conditionSchema = z.object({
|
|
|
161
161
|
});
|
|
162
162
|
/** One condition, or several that must all hold. */
|
|
163
163
|
export const whenSchema = z.union([conditionSchema, z.array(conditionSchema).min(1)]);
|
|
164
|
+
/** What a card of a choice shows: the columns of the table the choices come from. */
|
|
165
|
+
export const cardsSchema = z.object({
|
|
166
|
+
label: z.string().min(1),
|
|
167
|
+
value: z.string().optional(),
|
|
168
|
+
image: z.string().optional(),
|
|
169
|
+
subtitle: z.string().optional(),
|
|
170
|
+
meta: z.string().optional(),
|
|
171
|
+
link: z.string().optional(),
|
|
172
|
+
});
|
|
164
173
|
export const fieldSchema = z.object({
|
|
165
174
|
id,
|
|
166
175
|
label: z.string().min(1),
|
|
@@ -215,6 +224,12 @@ export const fieldSchema = z.object({
|
|
|
215
224
|
* of a stored list ("lists.<id>.<column>"). `options` stand in while that data is empty.
|
|
216
225
|
*/
|
|
217
226
|
optionsFrom: z.string().optional(),
|
|
227
|
+
/**
|
|
228
|
+
* select / multiselect with `optionsFrom` naming a table output ("steps.<id>.<key>"): each row
|
|
229
|
+
* is a choice drawn as a card. The columns that hold what the card shows; `value` (default:
|
|
230
|
+
* `label`) is what the answer holds, `link` a page the card opens.
|
|
231
|
+
*/
|
|
232
|
+
cards: cardsSchema.optional(),
|
|
218
233
|
/**
|
|
219
234
|
* The field is shown when a decision, made as the run reaches the page, finds this statement
|
|
220
235
|
* true of the run ("The complaint is about a damaged article").
|
|
@@ -847,7 +862,7 @@ export function validateWizard(def, files) {
|
|
|
847
862
|
return [];
|
|
848
863
|
};
|
|
849
864
|
/** Why an `optionsFrom` reference finds nothing, or null when it is fine. */
|
|
850
|
-
const optionsFromProblem = (raw) => {
|
|
865
|
+
const optionsFromProblem = (raw, cards) => {
|
|
851
866
|
const [head, from, key, column, ...more] = dataRef(raw).split(".");
|
|
852
867
|
if (head === "lists" && from && key && !column) {
|
|
853
868
|
const list = def.lists?.find((l) => l.id === from);
|
|
@@ -878,7 +893,16 @@ export function validateWizard(def, files) {
|
|
|
878
893
|
? null
|
|
879
894
|
: `"optionsFrom": "${from}.${key}" is not a table with the column "${column}".`;
|
|
880
895
|
}
|
|
881
|
-
|
|
896
|
+
if (cards) {
|
|
897
|
+
if (out.kind !== "table") {
|
|
898
|
+
return `"cards": "${from}.${key}" is not a table.`;
|
|
899
|
+
}
|
|
900
|
+
const missing = Object.values(cards).find((c) => out.columns?.length && !out.columns.includes(c));
|
|
901
|
+
return missing ? `"cards": table "${from}.${key}" has no column "${missing}".` : null;
|
|
902
|
+
}
|
|
903
|
+
return out.kind === "list"
|
|
904
|
+
? null
|
|
905
|
+
: `"optionsFrom": "${from}.${key}" is not a list (a table takes a column, or "cards").`;
|
|
882
906
|
}
|
|
883
907
|
return `"optionsFrom" is "steps.<id>.<key>", "steps.<id>.<key>.<column>" or "lists.<id>.<column>".`;
|
|
884
908
|
};
|
|
@@ -930,11 +954,19 @@ export function validateWizard(def, files) {
|
|
|
930
954
|
if (field.optionsFrom) {
|
|
931
955
|
const problem = field.kind !== "select" && field.kind !== "multiselect" && field.kind !== "slot"
|
|
932
956
|
? `"optionsFrom" fills the choices of a select, multiselect or slot; kind is "${field.kind}".`
|
|
933
|
-
:
|
|
957
|
+
: field.cards && field.kind === "slot"
|
|
958
|
+
? '"cards" draws the choices of a select or multiselect, not of a slot.'
|
|
959
|
+
: optionsFromProblem(field.optionsFrom, field.cards);
|
|
934
960
|
if (problem) {
|
|
935
961
|
issues.push({ stepId: step.id, message: `Field "${field.id}": ${problem}` });
|
|
936
962
|
}
|
|
937
963
|
}
|
|
964
|
+
else if (field.cards) {
|
|
965
|
+
issues.push({
|
|
966
|
+
stepId: step.id,
|
|
967
|
+
message: `Field "${field.id}": "cards" needs "optionsFrom" naming a table output.`,
|
|
968
|
+
});
|
|
969
|
+
}
|
|
938
970
|
if (field.prefill) {
|
|
939
971
|
const ref = dataRef(field.prefill);
|
|
940
972
|
if (ref.split(".")[0] !== "steps") {
|
|
@@ -1366,7 +1398,10 @@ export const MAX_DATA_OPTIONS = 100;
|
|
|
1366
1398
|
* column of a table output, or one column of a stored list — as text, without duplicates and
|
|
1367
1399
|
* empties. Empty when the data is not there (yet).
|
|
1368
1400
|
*/
|
|
1369
|
-
export function optionsFromData(ref, outputs, lists = {}) {
|
|
1401
|
+
export function optionsFromData(ref, outputs, lists = {}, cards) {
|
|
1402
|
+
if (cards) {
|
|
1403
|
+
return cardsFromData(ref, outputs, cards).map((c) => c.value);
|
|
1404
|
+
}
|
|
1370
1405
|
const [head, id, key, column, ...more] = dataRef(ref).split(".");
|
|
1371
1406
|
let raw = [];
|
|
1372
1407
|
if (head === "lists" && id && key && !column) {
|
|
@@ -1396,6 +1431,61 @@ export function optionsFromData(ref, outputs, lists = {}) {
|
|
|
1396
1431
|
}
|
|
1397
1432
|
return [...seen];
|
|
1398
1433
|
}
|
|
1434
|
+
/** The rows of a table output as cards: what `optionsFrom` with `cards` finds in the run. */
|
|
1435
|
+
export function cardsFromData(ref, outputs, cards) {
|
|
1436
|
+
const [head, id, key, ...more] = dataRef(ref).split(".");
|
|
1437
|
+
if (head !== "steps" || !id || !key || more.length) {
|
|
1438
|
+
return [];
|
|
1439
|
+
}
|
|
1440
|
+
const json = outputs[id]?.json;
|
|
1441
|
+
const rows = json && typeof json === "object" ? json[key] : undefined;
|
|
1442
|
+
if (!Array.isArray(rows)) {
|
|
1443
|
+
return [];
|
|
1444
|
+
}
|
|
1445
|
+
const cell = (row, column, max = 200) => {
|
|
1446
|
+
const v = column ? row[column] : undefined;
|
|
1447
|
+
if (v === null || v === undefined || typeof v === "object") {
|
|
1448
|
+
return "";
|
|
1449
|
+
}
|
|
1450
|
+
return String(v).trim().slice(0, max);
|
|
1451
|
+
};
|
|
1452
|
+
const out = [];
|
|
1453
|
+
const seen = new Set();
|
|
1454
|
+
for (const raw of rows) {
|
|
1455
|
+
if (!raw || typeof raw !== "object") {
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
const row = raw;
|
|
1459
|
+
const label = cell(row, cards.label);
|
|
1460
|
+
const value = cell(row, cards.value) || label;
|
|
1461
|
+
if (!value || seen.has(value)) {
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
seen.add(value);
|
|
1465
|
+
const card = { value, label: label || value };
|
|
1466
|
+
const image = cell(row, cards.image, 2000);
|
|
1467
|
+
const link = cell(row, cards.link, 2000);
|
|
1468
|
+
const subtitle = cell(row, cards.subtitle, 300);
|
|
1469
|
+
const meta = cell(row, cards.meta, 80);
|
|
1470
|
+
if (/^(https?:|data:|\/)/.test(image) || /^[a-zA-Z0-9_-]{6,64}$/.test(image)) {
|
|
1471
|
+
card.image = image;
|
|
1472
|
+
}
|
|
1473
|
+
if (/^https?:\/\//.test(link)) {
|
|
1474
|
+
card.link = link;
|
|
1475
|
+
}
|
|
1476
|
+
if (subtitle) {
|
|
1477
|
+
card.subtitle = subtitle;
|
|
1478
|
+
}
|
|
1479
|
+
if (meta) {
|
|
1480
|
+
card.meta = meta;
|
|
1481
|
+
}
|
|
1482
|
+
out.push(card);
|
|
1483
|
+
if (out.length >= MAX_DATA_OPTIONS) {
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
return out;
|
|
1488
|
+
}
|
|
1399
1489
|
// ---------------------------------------------------------------------------
|
|
1400
1490
|
// Appointment times
|
|
1401
1491
|
const SLOT_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|