wizards 0.2.47 → 0.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/apps/runtime/dist/agents/{project-assistant.js → studio-assistant.js} +199 -69
- package/apps/runtime/dist/agents/website.js +25 -2
- package/apps/runtime/dist/app.js +2 -1
- package/apps/runtime/dist/apple/wizards-apple +0 -0
- package/apps/runtime/dist/assistant/browser.js +26 -0
- package/apps/runtime/dist/assistant/docs.js +158 -0
- package/apps/runtime/dist/assistant/knows.js +325 -0
- package/apps/runtime/dist/assistant/primer.js +26 -0
- package/apps/runtime/dist/authoring/guide.js +5 -0
- package/apps/runtime/dist/cli/status.js +1 -1
- package/apps/runtime/dist/connectors/plugin-connections.js +123 -29
- package/apps/runtime/dist/db/migrations/tenant/0012_assistant_chat.sql +40 -0
- package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0012_snapshot.json +3132 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +3139 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
- package/apps/runtime/dist/db/schema.js +35 -0
- package/apps/runtime/dist/docs/dev/index.md +34 -0
- package/apps/runtime/dist/docs/dev/meta.json +7 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +70 -0
- package/apps/runtime/dist/docs/dev/plugins/events.md +86 -0
- package/apps/runtime/dist/docs/dev/plugins/examples.md +99 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +72 -0
- package/apps/runtime/dist/docs/dev/plugins/layout.md +88 -0
- package/apps/runtime/dist/docs/dev/plugins/meta.json +29 -0
- package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +59 -0
- package/apps/runtime/dist/docs/dev/plugins/quick-start.md +92 -0
- package/apps/runtime/dist/docs/dev/plugins/reference.md +298 -0
- package/apps/runtime/dist/docs/dev/plugins/reloading.md +75 -0
- package/apps/runtime/dist/docs/dev/plugins/routes.md +123 -0
- package/apps/runtime/dist/docs/dev/plugins/runners.md +184 -0
- package/apps/runtime/dist/docs/dev/plugins/server.md +191 -0
- package/apps/runtime/dist/docs/dev/plugins/shipping.md +98 -0
- package/apps/runtime/dist/docs/dev/plugins/space.md +260 -0
- package/apps/runtime/dist/docs/dev/plugins/starters.md +62 -0
- package/apps/runtime/dist/docs/dev/plugins/studio.md +261 -0
- package/apps/runtime/dist/docs/dev/plugins/styling.md +109 -0
- package/apps/runtime/dist/docs/dev/plugins/tables.md +102 -0
- package/apps/runtime/dist/docs/dev/plugins/tools.md +128 -0
- package/apps/runtime/dist/docs/meta.json +3 -0
- package/apps/runtime/dist/docs/user/ai-apps.md +99 -0
- package/apps/runtime/dist/docs/user/assistant.md +52 -0
- package/apps/runtime/dist/docs/user/build-a-wizard.md +79 -0
- package/apps/runtime/dist/docs/user/command-line.md +76 -0
- package/apps/runtime/dist/docs/user/connectors.md +80 -0
- package/apps/runtime/dist/docs/user/data.md +61 -0
- package/apps/runtime/dist/docs/user/first-start.md +42 -0
- package/apps/runtime/dist/docs/user/index.md +45 -0
- package/apps/runtime/dist/docs/user/install.md +76 -0
- package/apps/runtime/dist/docs/user/meta.json +30 -0
- package/apps/runtime/dist/docs/user/models.md +125 -0
- package/apps/runtime/dist/docs/user/plugins.md +61 -0
- package/apps/runtime/dist/docs/user/run.md +92 -0
- package/apps/runtime/dist/docs/user/server.md +50 -0
- package/apps/runtime/dist/docs/user/space.md +97 -0
- package/apps/runtime/dist/docs/user/steps.md +196 -0
- package/apps/runtime/dist/docs/user/test-and-share.md +216 -0
- package/apps/runtime/dist/docs/user/troubleshooting.md +57 -0
- package/apps/runtime/dist/docs/user/wordpress.md +103 -0
- package/apps/runtime/dist/engine/device.js +182 -0
- package/apps/runtime/dist/engine/events.js +3 -0
- package/apps/runtime/dist/engine/input.js +3 -0
- package/apps/runtime/dist/engine/prepare.js +1 -0
- package/apps/runtime/dist/engine/requirements.js +6 -109
- package/apps/runtime/dist/engine/runner.js +13 -5
- package/apps/runtime/dist/engine/steps.js +2 -1
- package/apps/runtime/dist/env.js +1 -1
- package/apps/runtime/dist/harness/apple.js +258 -0
- package/apps/runtime/dist/harness/model.js +3 -1
- package/apps/runtime/dist/manage.js +11 -0
- package/apps/runtime/dist/mcp/auth.js +3 -0
- package/apps/runtime/dist/mcp/scopes.js +11 -2
- package/apps/runtime/dist/media/transcribe.js +6 -1
- package/apps/runtime/dist/models.js +63 -9
- package/apps/runtime/dist/plugins/loader.js +2 -0
- package/apps/runtime/dist/routes/api.js +232 -1
- package/apps/runtime/dist/routes/plugins.js +6 -2
- package/apps/runtime/dist/routes/runs.js +65 -3
- package/apps/runtime/dist/routes/studio.js +130 -69
- package/apps/runtime/dist/services/api.js +244 -0
- package/apps/runtime/dist/services/assistant-chats.js +267 -0
- package/apps/runtime/dist/services/engenty-shapes.js +1 -1
- package/apps/runtime/dist/services/package.js +77 -9
- package/apps/runtime/dist/services/project-index.js +1 -1
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/site.js +262 -0
- package/apps/runtime/dist/services/space-origin.js +45 -2
- package/apps/web/dist/assets/AboutDialog-6CCpWqAl.js +1 -0
- package/apps/web/dist/assets/ChangelogDialog-ApswqjRk.js +1 -0
- package/apps/web/dist/assets/ChatView-D7N2QyGS.js +10 -0
- package/apps/web/dist/assets/EditorPage-CbtYQTWj.js +3 -0
- package/apps/web/dist/assets/FlowPreview-KTaelucs.js +1 -0
- package/apps/web/dist/assets/{Harness-zKMptCzB.js → Harness-_mD1Stm4.js} +2 -2
- package/apps/web/dist/assets/Marketplace-DKQ9j4OC.js +2 -0
- package/apps/web/dist/assets/NewWizardPage-CoCCRcoi.js +1 -0
- package/apps/web/dist/assets/ProjectPage-DDLh_qxi.js +2 -0
- package/apps/web/dist/assets/PublicRunner-Lpu-BY5w.js +1 -0
- package/apps/web/dist/assets/ReadOnly-ClY8xMQS.js +1 -0
- package/apps/web/dist/assets/RunDrawer-JXG5wZp7.js +4 -0
- package/apps/web/dist/assets/RunnerView-BlUSqfqB.js +1 -0
- package/apps/web/dist/assets/SettingsPage-V_E267hI.js +1 -0
- package/apps/web/dist/assets/SetupPage-Dvoze8cZ.js +1 -0
- package/apps/web/dist/assets/SharePage-DBcp_npb.js +1 -0
- package/apps/web/dist/assets/brand-CNF5NxD9.js +2 -0
- package/apps/web/dist/assets/changelog-CmZrNHwc.js +1 -0
- package/apps/web/dist/assets/circle-alert-r2qc1Vej.js +1 -0
- package/apps/web/dist/assets/engenty-eXZ-EAwd.js +1 -0
- package/apps/web/dist/assets/esm-DZeij_95.js +7 -0
- package/apps/web/dist/assets/{fluffy-engenty-D7rFrNcJ.js → fluffy-engenty-ClRou7yu.js} +1 -1
- package/apps/web/dist/assets/index-BbogBDv_.js +11 -0
- package/apps/web/dist/assets/index-Dr0bv52Q.css +1 -0
- package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +1 -0
- package/apps/web/dist/assets/lock-N-C6-ZeG.js +1 -0
- package/apps/web/dist/assets/logo-C4V2_3Ar.js +1 -0
- package/apps/web/dist/assets/oss-credits-BQQX0kvk.js +1 -0
- package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +228 -0
- package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
- package/apps/web/dist/assets/session-Cpg5S8B3.js +1 -0
- package/apps/web/dist/assets/settings-menu-C7m2i7Sf.js +1 -0
- package/apps/web/dist/assets/ui-DKcggL84.js +133 -0
- package/apps/web/dist/assets/upload-D24SDj7W.js +1 -0
- package/apps/web/dist/assets/useMutation-DKyQXgyj.js +1 -0
- package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +1 -0
- package/apps/web/dist/assets/volume-2-C-Y7-S4b.js +1 -0
- package/apps/web/dist/embed.js +57 -8
- package/apps/web/dist/index.html +12 -16
- package/apps/web/dist/mcp/flow.html +435 -207
- package/modules/calls/dist/client.css +1 -1
- package/modules/sms/dist/client.css +1 -1
- package/modules/whatsapp/dist/client.css +1 -1
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +82 -7
- package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +58 -4
- package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +113 -0
- package/node_modules/@engenty-wizards/shared/dist/assistant.js +55 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +58 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.js +94 -4
- package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +71 -0
- package/node_modules/@engenty-wizards/shared/dist/fit.js +381 -0
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +3 -1
- package/package.json +1 -1
- package/apps/web/dist/assets/AboutDialog-t7bpiasT.js +0 -1
- package/apps/web/dist/assets/ChangelogDialog-B87yS6aN.js +0 -1
- package/apps/web/dist/assets/ChatView-Dm764bYy.js +0 -10
- package/apps/web/dist/assets/EditorPage-BG_Ue2iC.js +0 -3
- package/apps/web/dist/assets/FlowPreview-ChXfiMn_.js +0 -1
- package/apps/web/dist/assets/HomePage-BXSg5P5k.js +0 -1
- package/apps/web/dist/assets/Marketplace-BWhUJ4UX.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-C3NqEGmg.js +0 -1
- package/apps/web/dist/assets/ProjectPage-D6Fy7uTV.js +0 -2
- package/apps/web/dist/assets/PublicRunner-ChgJs0C9.js +0 -1
- package/apps/web/dist/assets/ReadOnly-C9P9aiU6.js +0 -1
- package/apps/web/dist/assets/RunDrawer-CvIKLphz.js +0 -4
- package/apps/web/dist/assets/RunnerView-Bmayop7s.js +0 -2
- package/apps/web/dist/assets/SettingsPage-QkwtRFoD.js +0 -1
- package/apps/web/dist/assets/SetupPage-B3IOQLO3.js +0 -1
- package/apps/web/dist/assets/SharePage-C3QEzicl.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-3IzIOlNz.js +0 -1
- package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +0 -1
- package/apps/web/dist/assets/changelog-Du2gWzlN.js +0 -1
- package/apps/web/dist/assets/circle-alert-CPo3Naay.js +0 -1
- package/apps/web/dist/assets/definition-CQGiBQ4X.js +0 -56
- package/apps/web/dist/assets/engenty-Cm8yZLON.js +0 -1
- package/apps/web/dist/assets/esm-rJY59Ixx.js +0 -7
- package/apps/web/dist/assets/external-link-CpU8aJY2.js +0 -1
- package/apps/web/dist/assets/index-Cz6c1S5g.js +0 -78
- package/apps/web/dist/assets/index-DKHClEy3.css +0 -1
- package/apps/web/dist/assets/jsx-runtime-D3jfb0Ew.js +0 -1
- package/apps/web/dist/assets/lock-C_WlXIQ0.js +0 -1
- package/apps/web/dist/assets/logo-C80CWCDM.js +0 -1
- package/apps/web/dist/assets/oss-credits-CIxnNZor.js +0 -1
- package/apps/web/dist/assets/react-dom-DenslgJm.js +0 -1
- package/apps/web/dist/assets/refresh-cw-Cli5WGnW.js +0 -1
- package/apps/web/dist/assets/session-miDEdw2c.js +0 -1
- package/apps/web/dist/assets/settings-menu-ROT8Lbbj.js +0 -1
- package/apps/web/dist/assets/sparkles-CP5H-O1E.js +0 -1
- package/apps/web/dist/assets/trash-DU-hZpV0.js +0 -1
- package/apps/web/dist/assets/ui-D92EkdEB.js +0 -9
- package/apps/web/dist/assets/upload-DMq5N6Fw.js +0 -1
- package/apps/web/dist/assets/useMutation-DKcIz55V.js +0 -1
- package/apps/web/dist/assets/volume-2-0SfkvOho.js +0 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import { and, desc, eq, inArray } from "drizzle-orm";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { accountOverview, accountToken, linkedAccount } from "../auth/account.js";
|
|
5
|
+
import { authoringGuide } from "../authoring/guide.js";
|
|
6
|
+
import { listConnectors } from "../connectors/external.js";
|
|
7
|
+
import { db, schema } from "../db/client.js";
|
|
8
|
+
import { env } from "../env.js";
|
|
9
|
+
import { detectHarnesses } from "../harness/index.js";
|
|
10
|
+
import { managed, publicPlans, tenantInfo, tenantUsage } from "../manage.js";
|
|
11
|
+
import { classWays } from "../models.js";
|
|
12
|
+
import { pluginToolsOf } from "../plugins/registry.js";
|
|
13
|
+
import { earlierChats, readChat, searchChats } from "../services/assistant-chats.js";
|
|
14
|
+
import { asLang, marketplaceDetail, searchMarketplace } from "../services/marketplace.js";
|
|
15
|
+
import { listWizards } from "../services/wizards.js";
|
|
16
|
+
import { attempt } from "../tools/shared.js";
|
|
17
|
+
import { readDoc, searchDocs } from "./docs.js";
|
|
18
|
+
/** Where the account lives: the runtime's Manage-App, or the account a local install links. */
|
|
19
|
+
const accountBase = () => (managed ? env.manage.url : env.local.accountUrl);
|
|
20
|
+
async function usageOf(tenantId) {
|
|
21
|
+
if (managed) {
|
|
22
|
+
return tenantUsage(tenantId, 3);
|
|
23
|
+
}
|
|
24
|
+
const token = await accountToken();
|
|
25
|
+
if (!token) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const res = await fetch(`${env.local.accountUrl}/v1/me/usage?months=3`, {
|
|
29
|
+
headers: { authorization: `Bearer ${token}` },
|
|
30
|
+
signal: AbortSignal.timeout(10_000),
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
throw new Error(`The account answered ${res.status}.`);
|
|
34
|
+
}
|
|
35
|
+
return (await res.json());
|
|
36
|
+
}
|
|
37
|
+
const NOT_LINKED = "This install is not linked to an account. Settings › Account signs one in; then credits, cloud publishing and plans apply. Docs and the gallery work without one.";
|
|
38
|
+
export function knowsTools(ctx) {
|
|
39
|
+
const { user } = ctx;
|
|
40
|
+
return {
|
|
41
|
+
docs_search: createTool({
|
|
42
|
+
id: "docs_search",
|
|
43
|
+
description: "Search the engenty wizards user guide and plugin guide of this installed version. Gives the best sections with an excerpt and their engenty.ai/docs link. Use it before you explain how something works.",
|
|
44
|
+
inputSchema: z.object({ query: z.string().min(2).max(200) }),
|
|
45
|
+
execute: async ({ query }) => {
|
|
46
|
+
ctx.doing(ctx.lang === "de" ? "Liest in der Anleitung …" : "Reading the guide …");
|
|
47
|
+
return { hits: searchDocs(query) };
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
docs_read: createTool({
|
|
51
|
+
id: "docs_read",
|
|
52
|
+
description: "Read one page of the guides by its id from docs_search (user/steps, dev/plugins/tools), from a character on.",
|
|
53
|
+
inputSchema: z.object({
|
|
54
|
+
page: z.string().min(1).max(200),
|
|
55
|
+
from: z.number().int().min(0).optional(),
|
|
56
|
+
}),
|
|
57
|
+
execute: async ({ page, from }) => {
|
|
58
|
+
ctx.doing(ctx.lang === "de" ? "Liest in der Anleitung …" : "Reading the guide …");
|
|
59
|
+
return readDoc(page, from ?? 0);
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
authoring_guide: createTool({
|
|
63
|
+
id: "authoring_guide",
|
|
64
|
+
description: "The authoring guide the wizard editor and AI apps build with: how a wizard is written (steps, fields, flows, tools, outputs, model classes). Long: read it in parts with `from`.",
|
|
65
|
+
inputSchema: z.object({ from: z.number().int().min(0).optional() }),
|
|
66
|
+
execute: ({ from }) => attempt(async () => {
|
|
67
|
+
ctx.doing(ctx.lang === "de" ? "Liest die Bauanleitung …" : "Reading the authoring guide …");
|
|
68
|
+
const guide = authoringGuide(ctx.project?.mcpServers ?? [], ctx.project ? await listConnectors(ctx.project.id) : [], await pluginToolsOf(user.tenantId));
|
|
69
|
+
const start = Math.min(from ?? 0, guide.length);
|
|
70
|
+
return {
|
|
71
|
+
text: guide.slice(start, start + 14_000),
|
|
72
|
+
next: start + 14_000 < guide.length ? start + 14_000 : null,
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
gallery_search: createTool({
|
|
77
|
+
id: "gallery_search",
|
|
78
|
+
description: "Search the gallery of wizard templates (engenty.ai/wizards and the plugins' starters): title, pitch, what it needs that this install has no model for, and its price per run in credits.",
|
|
79
|
+
inputSchema: z.object({ query: z.string().max(200).optional() }),
|
|
80
|
+
execute: ({ query }) => attempt(async () => {
|
|
81
|
+
ctx.doing(ctx.lang === "de" ? "Sucht in der Galerie …" : "Searching the gallery …");
|
|
82
|
+
const found = await searchMarketplace({
|
|
83
|
+
q: query ?? "",
|
|
84
|
+
lang: asLang(ctx.lang),
|
|
85
|
+
limit: 8,
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
total: found.total,
|
|
89
|
+
offline: found.offline,
|
|
90
|
+
entries: found.entries.map((e) => ({
|
|
91
|
+
id: e.id,
|
|
92
|
+
title: e.title,
|
|
93
|
+
pitch: e.pitch,
|
|
94
|
+
formats: e.formats,
|
|
95
|
+
steps: e.steps,
|
|
96
|
+
credits: e.credits,
|
|
97
|
+
missing: e.missing,
|
|
98
|
+
needsPlugins: e.needs ?? [],
|
|
99
|
+
plugin: e.plugin?.name,
|
|
100
|
+
})),
|
|
101
|
+
};
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
gallery_detail: createTool({
|
|
105
|
+
id: "gallery_detail",
|
|
106
|
+
description: "One template of the gallery: what it does, its steps, what it makes and needs.",
|
|
107
|
+
inputSchema: z.object({ id: z.string().min(1).max(120) }),
|
|
108
|
+
execute: ({ id }) => attempt(async () => {
|
|
109
|
+
const found = await marketplaceDetail(id, asLang(ctx.lang));
|
|
110
|
+
if (!found) {
|
|
111
|
+
return { error: "No such template." };
|
|
112
|
+
}
|
|
113
|
+
const { terms: _terms, hash: _hash, ...rest } = found;
|
|
114
|
+
return rest;
|
|
115
|
+
}),
|
|
116
|
+
}),
|
|
117
|
+
plans: createTool({
|
|
118
|
+
id: "plans",
|
|
119
|
+
description: "The plans teams can be on (Free, Pro, Team): price a month, monthly credits, limits, and the credit packages to buy on top. Live from the account service.",
|
|
120
|
+
inputSchema: z.object({}),
|
|
121
|
+
execute: () => attempt(async () => {
|
|
122
|
+
ctx.doing(ctx.lang === "de" ? "Sieht die Pläne nach …" : "Looking up the plans …");
|
|
123
|
+
const plans = await publicPlans(accountBase());
|
|
124
|
+
return { ...plans, billingPage: `${accountBase()}/billing` };
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
account: createTool({
|
|
128
|
+
id: "account",
|
|
129
|
+
description: "The person, their team, their role, the team's plan, the credit balance and credits that end on a date.",
|
|
130
|
+
inputSchema: z.object({}),
|
|
131
|
+
execute: () => attempt(async () => {
|
|
132
|
+
ctx.doing(ctx.lang === "de" ? "Sieht das Konto nach …" : "Looking up the account …");
|
|
133
|
+
if (managed) {
|
|
134
|
+
const info = await tenantInfo(user.tenantId, true);
|
|
135
|
+
return {
|
|
136
|
+
person: { name: user.name, email: user.email, role: user.role },
|
|
137
|
+
team: { name: info.name, plan: info.plan?.name ?? null, status: info.status },
|
|
138
|
+
balanceCredits: Math.floor(info.balanceCredits),
|
|
139
|
+
limits: info.limits,
|
|
140
|
+
billingPage: `${env.manage.url}/billing`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (!(await linkedAccount())) {
|
|
144
|
+
return { linked: false, note: NOT_LINKED };
|
|
145
|
+
}
|
|
146
|
+
const overview = await accountOverview();
|
|
147
|
+
if (!overview) {
|
|
148
|
+
return {
|
|
149
|
+
linked: true,
|
|
150
|
+
signedIn: false,
|
|
151
|
+
note: "The sign-in ran out: Settings › Account signs in again.",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
linked: true,
|
|
156
|
+
person: overview.user,
|
|
157
|
+
team: { name: overview.tenant.name, role: overview.tenant.role },
|
|
158
|
+
plan: overview.tenant.plan?.name ?? null,
|
|
159
|
+
balanceCredits: Math.floor(overview.tenant.balanceCredits),
|
|
160
|
+
expiring: overview.tenant.expiring ?? [],
|
|
161
|
+
billingPage: `${env.local.accountUrl}/billing`,
|
|
162
|
+
};
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
usage: createTool({
|
|
166
|
+
id: "usage",
|
|
167
|
+
description: "Credits the team used per month (the last three), and the runs and wizards that cost the most.",
|
|
168
|
+
inputSchema: z.object({}),
|
|
169
|
+
execute: () => attempt(async () => {
|
|
170
|
+
ctx.doing(ctx.lang === "de" ? "Sieht den Verbrauch nach …" : "Looking up the usage …");
|
|
171
|
+
if (!(managed || (await linkedAccount()))) {
|
|
172
|
+
return { linked: false, note: NOT_LINKED };
|
|
173
|
+
}
|
|
174
|
+
const usage = await usageOf(user.tenantId);
|
|
175
|
+
if (!usage) {
|
|
176
|
+
return { note: "The sign-in ran out: Settings › Account signs in again." };
|
|
177
|
+
}
|
|
178
|
+
const runIds = [...new Set(usage.months.flatMap((m) => m.runs.map((r) => r.runId)))];
|
|
179
|
+
const runs = runIds.length
|
|
180
|
+
? await db
|
|
181
|
+
.select({ id: schema.run.id, wizard: schema.wizard.title, mode: schema.run.mode })
|
|
182
|
+
.from(schema.run)
|
|
183
|
+
.innerJoin(schema.wizard, eq(schema.wizard.id, schema.run.wizardId))
|
|
184
|
+
.where(inArray(schema.run.id, runIds))
|
|
185
|
+
: [];
|
|
186
|
+
const byRun = new Map(runs.map((r) => [r.id, r]));
|
|
187
|
+
return {
|
|
188
|
+
months: usage.months.map((m) => {
|
|
189
|
+
const perWizard = new Map();
|
|
190
|
+
for (const r of m.runs) {
|
|
191
|
+
const title = byRun.get(r.runId)?.wizard ?? "(a run of another install)";
|
|
192
|
+
perWizard.set(title, (perWizard.get(title) ?? 0) + r.credits);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
month: m.month,
|
|
196
|
+
credits: m.credits,
|
|
197
|
+
wizards: [...perWizard.entries()]
|
|
198
|
+
.map(([wizard, credits]) => ({
|
|
199
|
+
wizard,
|
|
200
|
+
credits: Math.round(credits * 100) / 100,
|
|
201
|
+
}))
|
|
202
|
+
.sort((a, b) => b.credits - a.credits)
|
|
203
|
+
.slice(0, 10),
|
|
204
|
+
};
|
|
205
|
+
}),
|
|
206
|
+
};
|
|
207
|
+
}),
|
|
208
|
+
}),
|
|
209
|
+
wizards: createTool({
|
|
210
|
+
id: "wizards",
|
|
211
|
+
description: "The space's wizards: title, description, published or draft, whether its link is on, steps, last change.",
|
|
212
|
+
inputSchema: z.object({}),
|
|
213
|
+
execute: () => attempt(async () => {
|
|
214
|
+
if (!ctx.project) {
|
|
215
|
+
return { note: "No space is open." };
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
wizards: (await listWizards(user.id, ctx.project.id)).map((w) => ({
|
|
219
|
+
id: w.id,
|
|
220
|
+
title: w.title,
|
|
221
|
+
description: w.description,
|
|
222
|
+
published: w.published,
|
|
223
|
+
linkOn: w.shareEnabled,
|
|
224
|
+
steps: w.stepCount,
|
|
225
|
+
updatedAt: w.updatedAt,
|
|
226
|
+
editor: `/edit/${w.id}`,
|
|
227
|
+
})),
|
|
228
|
+
};
|
|
229
|
+
}),
|
|
230
|
+
}),
|
|
231
|
+
runs: createTool({
|
|
232
|
+
id: "runs",
|
|
233
|
+
description: "The space's latest runs, newest first: wizard, test or live, status, the error of a failed one.",
|
|
234
|
+
inputSchema: z.object({
|
|
235
|
+
status: z.enum(["failed", "done", "running", "waiting_input", "cancelled"]).optional(),
|
|
236
|
+
limit: z.number().int().min(1).max(40).optional(),
|
|
237
|
+
}),
|
|
238
|
+
execute: ({ status, limit }) => attempt(async () => {
|
|
239
|
+
if (!ctx.project) {
|
|
240
|
+
return { note: "No space is open." };
|
|
241
|
+
}
|
|
242
|
+
const rows = await db
|
|
243
|
+
.select({
|
|
244
|
+
id: schema.run.id,
|
|
245
|
+
wizard: schema.wizard.title,
|
|
246
|
+
wizardId: schema.wizard.id,
|
|
247
|
+
mode: schema.run.mode,
|
|
248
|
+
status: schema.run.status,
|
|
249
|
+
error: schema.run.error,
|
|
250
|
+
runner: schema.run.runner,
|
|
251
|
+
createdAt: schema.run.createdAt,
|
|
252
|
+
})
|
|
253
|
+
.from(schema.run)
|
|
254
|
+
.innerJoin(schema.wizard, eq(schema.wizard.id, schema.run.wizardId))
|
|
255
|
+
.where(and(eq(schema.wizard.projectId, ctx.project.id), status ? eq(schema.run.status, status) : undefined))
|
|
256
|
+
.orderBy(desc(schema.run.createdAt))
|
|
257
|
+
.limit(limit ?? 15);
|
|
258
|
+
return {
|
|
259
|
+
runs: rows.map((r) => ({
|
|
260
|
+
...r,
|
|
261
|
+
error: r.error?.slice(0, 400) ?? null,
|
|
262
|
+
createdAt: r.createdAt.toISOString(),
|
|
263
|
+
})),
|
|
264
|
+
};
|
|
265
|
+
}),
|
|
266
|
+
}),
|
|
267
|
+
models: createTool({
|
|
268
|
+
id: "models",
|
|
269
|
+
description: "What thinks and makes for this install, per model class: an installed AI client, an own key, a local model, credits, or nothing (with the problem). Also which AI clients are installed and signed in.",
|
|
270
|
+
inputSchema: z.object({}),
|
|
271
|
+
execute: () => attempt(async () => {
|
|
272
|
+
ctx.doing(ctx.lang === "de" ? "Sieht die Modelle nach …" : "Looking up the models …");
|
|
273
|
+
return {
|
|
274
|
+
classes: await classWays(),
|
|
275
|
+
clients: managed
|
|
276
|
+
? []
|
|
277
|
+
: (await detectHarnesses()).map((h) => ({
|
|
278
|
+
id: h.id,
|
|
279
|
+
installed: Boolean(h.version),
|
|
280
|
+
signedIn: h.auth !== "none",
|
|
281
|
+
})),
|
|
282
|
+
page: "/settings/models",
|
|
283
|
+
};
|
|
284
|
+
}),
|
|
285
|
+
}),
|
|
286
|
+
chats_search: createTool({
|
|
287
|
+
id: "chats_search",
|
|
288
|
+
description: "Search the person's earlier chats with you (their messages and summaries) for words: what was asked, changed or decided before.",
|
|
289
|
+
inputSchema: z.object({ query: z.string().min(3).max(200) }),
|
|
290
|
+
execute: ({ query }) => attempt(async () => {
|
|
291
|
+
ctx.doing(ctx.lang === "de" ? "Sucht in früheren Chats …" : "Searching earlier chats …");
|
|
292
|
+
const hits = (await searchChats(user, query)).filter((h) => h.chatId !== ctx.chatId);
|
|
293
|
+
return {
|
|
294
|
+
hits,
|
|
295
|
+
recent: hits.length
|
|
296
|
+
? undefined
|
|
297
|
+
: (await earlierChats(user, 10)).map((c) => ({
|
|
298
|
+
id: c.id,
|
|
299
|
+
title: c.title,
|
|
300
|
+
closedAt: c.closedAt,
|
|
301
|
+
})),
|
|
302
|
+
};
|
|
303
|
+
}),
|
|
304
|
+
}),
|
|
305
|
+
chat_read: createTool({
|
|
306
|
+
id: "chat_read",
|
|
307
|
+
description: "Read one earlier chat by its id (from chats_search): its summary and messages.",
|
|
308
|
+
inputSchema: z.object({ id: z.string().min(1).max(40) }),
|
|
309
|
+
execute: ({ id }) => attempt(async () => {
|
|
310
|
+
const chat = await readChat(user, id);
|
|
311
|
+
return {
|
|
312
|
+
title: chat.title,
|
|
313
|
+
summary: chat.summary,
|
|
314
|
+
startedAt: chat.startedAt,
|
|
315
|
+
closedAt: chat.closedAt,
|
|
316
|
+
messages: chat.messages.slice(-40).map((m) => ({
|
|
317
|
+
role: m.role,
|
|
318
|
+
text: m.content.slice(0, 2000),
|
|
319
|
+
at: m.createdAt,
|
|
320
|
+
})),
|
|
321
|
+
};
|
|
322
|
+
}),
|
|
323
|
+
}),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What engenty wizards is, on one page, in every turn of the studio assistant. Written from the
|
|
3
|
+
* user guide (docs/content/user/index.md and the pages it links); the details are a docs_search
|
|
4
|
+
* away.
|
|
5
|
+
*/
|
|
6
|
+
export const PRIMER = `ENGENTY WIZARDS IN ONE PAGE
|
|
7
|
+
engenty wizards turns something done again and again into a wizard: pages that ask what it needs, AI steps that do the work, and a link to share. It runs on the person's own computer (a "local install" at ~/.engenty/wizards, studio at /studio) or in the cloud at engenty.ai with an account.
|
|
8
|
+
|
|
9
|
+
Words
|
|
10
|
+
- Studio: where wizards are built. Home lists the space's wizards; the editor (/edit/<id>) shows a wizard's flow as a diagram with its own chat (the architect) that builds and changes it.
|
|
11
|
+
- Wizard: a flow of steps a person walks through on a link. Step kinds: a page (fields to fill in), an AI step (an agent with tools: web search, reading files, writing documents, images, video, pages, other services), a review, and the result.
|
|
12
|
+
- Run: one person going through a wizard once. Results lists every run that reached its result.
|
|
13
|
+
- Space: what all wizards of a team know. Its page has four parts: Info & brand (title, about, logos, colours, assets, facts), Wissen / Knowledge (pages, tables and files the AI steps look things up in, kept apart by typed Kategorien), Data (tables and pages the wizards keep) and Results (finished runs).
|
|
14
|
+
- Model class: the kind of model a step needs (Classifier, Standard, High, Highest for text; Image, Video, Speech, Audio). Which model serves a class is a setting (Settings › Models), not part of the wizard.
|
|
15
|
+
|
|
16
|
+
Thinking: an installed AI client on the person's subscription (Claude Code, Codex, Gemini CLI, Cursor Agent), own API keys (OpenAI, Anthropic, Google, fal.ai, ElevenLabs, Replicate, Vercel AI Gateway), a local model (Ollama), or engenty credits from an account. Settings › Models shows which way serves each class and what is missing.
|
|
17
|
+
|
|
18
|
+
Sharing: Test runs a draft. Publish makes a version live behind a link. Share holds the link, the tag for a website, a QR code, channels (the page, the chat, and what plugins add: WhatsApp, SMS, calls) and the link's settings (on/off, runs per day, a new address). With an account, what is published on a local install also runs in the cloud, on the account's credits, while the computer is off.
|
|
19
|
+
|
|
20
|
+
AI apps: the install is an MCP server; Claude Desktop, Cursor, Codex and others build and run wizards through it (Settings › AI apps).
|
|
21
|
+
|
|
22
|
+
Plugins add pages to the studio (a Shop, a Termin-Planer), settings sections, sections of the space page, tools for AI steps and for this assistant, and channels. Settings › Plugins lists what is installed.
|
|
23
|
+
|
|
24
|
+
Account and plans: an account is optional on a local install; it brings credits, cloud publishing, sync and Pro modules. In the cloud, teams are on a plan (Free, Pro, Team) with monthly credits; credits can be topped up on the account's billing page. Plans, prices and the balance come from the account (tools: plans, account, usage), never from memory.
|
|
25
|
+
|
|
26
|
+
Studio addresses: / (home), /new (a new wizard), /edit/<id> (the editor), /space/info, /space/knowledge, /space/data, /space/results, /settings/account, /settings/team (cloud), /settings/connectors, /settings/models, /settings/integrate (AI apps), /settings/plugins, and the pages plugins add.`;
|
|
@@ -101,6 +101,11 @@ type Field = {
|
|
|
101
101
|
optionsFrom?: "steps.<id>.<key>" | "steps.<id>.<key>.<column>" | "lists.<id>.<column>"
|
|
102
102
|
// select / multiselect / slot: the choices come from earlier data — a "list" output, one column of a
|
|
103
103
|
// "table" output, or a column of a stored list. "options" stand in while that data is empty.
|
|
104
|
+
cards?: { label, value?, image?, subtitle?, meta?, link? }
|
|
105
|
+
// select / multiselect with optionsFrom "steps.<id>.<key>" naming a TABLE output: every row is a
|
|
106
|
+
// choice drawn as a card. Each entry names a column of that table: label (the title), value (what the
|
|
107
|
+
// answer holds, default the label — an id column when there is one), image (a URL or asset id),
|
|
108
|
+
// subtitle, meta (a price), link (a page "Details" opens). Products, places, candidates to pick.
|
|
104
109
|
}
|
|
105
110
|
// kinds: text textarea number select multiselect date email url toggle color image file items connection list
|
|
106
111
|
// location audio signature slot
|
|
@@ -57,7 +57,7 @@ export async function status(paths, checks) {
|
|
|
57
57
|
problems.push(`${tilde(paths.home)} cannot be written to.`);
|
|
58
58
|
}
|
|
59
59
|
if (!clients.some((state) => state.path)) {
|
|
60
|
-
console.log(` ${no} No AI client: the studio needs an API key or
|
|
60
|
+
console.log(` ${no} No AI client: the studio needs an API key, Ollama or Apple Intelligence (a Mac) instead. ${dim("`setup` installs one.")}`);
|
|
61
61
|
}
|
|
62
62
|
for (const problem of problems) {
|
|
63
63
|
console.log(` ${bad} ${problem}`);
|
|
@@ -14,6 +14,59 @@ function oauthConnector(id) {
|
|
|
14
14
|
}
|
|
15
15
|
return connector;
|
|
16
16
|
}
|
|
17
|
+
/** A built-in connector a plugin may connect: signed in, or with keys. */
|
|
18
|
+
function connectorOf(id) {
|
|
19
|
+
const connector = builtinConnector(id);
|
|
20
|
+
if (!connector || connector.auth.kind === "browser") {
|
|
21
|
+
throw new Error(`"${id}" is not a built-in connector a plugin can connect.`);
|
|
22
|
+
}
|
|
23
|
+
return connector;
|
|
24
|
+
}
|
|
25
|
+
/** The actions a connection is made for exist on the connector. */
|
|
26
|
+
function knownActions(connector, actions) {
|
|
27
|
+
for (const id of actions) {
|
|
28
|
+
if (!connector.actions.some((a) => a.id === id)) {
|
|
29
|
+
throw new Error(`${connector.name} has no action "${id}".`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [...new Set(actions)];
|
|
33
|
+
}
|
|
34
|
+
async function spaceExists(space) {
|
|
35
|
+
const project = await db.query.project.findFirst({
|
|
36
|
+
where: eq(schema.project.id, space),
|
|
37
|
+
columns: { id: true },
|
|
38
|
+
});
|
|
39
|
+
if (!project) {
|
|
40
|
+
throw new Error(`There is no space "${space}".`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Keeps a connection: the same account for the same space again replaces the first one. */
|
|
44
|
+
async function keep(input) {
|
|
45
|
+
const same = await db.query.pluginConnection.findFirst({
|
|
46
|
+
where: and(eq(schema.pluginConnection.plugin, input.plugin), eq(schema.pluginConnection.projectId, input.projectId), eq(schema.pluginConnection.connector, input.connector), eq(schema.pluginConnection.label, input.label)),
|
|
47
|
+
});
|
|
48
|
+
if (same) {
|
|
49
|
+
const [row] = await db
|
|
50
|
+
.update(schema.pluginConnection)
|
|
51
|
+
.set({ actions: input.actions, data: seal(input.stored), updatedAt: new Date() })
|
|
52
|
+
.where(eq(schema.pluginConnection.id, same.id))
|
|
53
|
+
.returning();
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
const [row] = await db
|
|
57
|
+
.insert(schema.pluginConnection)
|
|
58
|
+
.values({
|
|
59
|
+
id: nanoid(14),
|
|
60
|
+
plugin: input.plugin,
|
|
61
|
+
projectId: input.projectId,
|
|
62
|
+
connector: input.connector,
|
|
63
|
+
label: input.label,
|
|
64
|
+
actions: input.actions,
|
|
65
|
+
data: seal(input.stored),
|
|
66
|
+
})
|
|
67
|
+
.returning();
|
|
68
|
+
return row;
|
|
69
|
+
}
|
|
17
70
|
/** The provider rights the named actions need, and the connector's own base rights. */
|
|
18
71
|
function scopesOf(connector, actions) {
|
|
19
72
|
const scopes = new Set(connector.auth.kind === "oauth2" ? connector.auth.oauth2.baseScopes : []);
|
|
@@ -73,26 +126,14 @@ export async function finishPluginOAuth(answer, rawState) {
|
|
|
73
126
|
scopes: tokens.grantedScopes,
|
|
74
127
|
...("ticket" in answer ? { via: "account" } : {}),
|
|
75
128
|
};
|
|
76
|
-
|
|
77
|
-
|
|
129
|
+
await keep({
|
|
130
|
+
plugin: state.plugin,
|
|
131
|
+
projectId: state.projectId,
|
|
132
|
+
connector: connector.id,
|
|
133
|
+
label: account.label,
|
|
134
|
+
actions: state.actions,
|
|
135
|
+
stored,
|
|
78
136
|
});
|
|
79
|
-
if (same) {
|
|
80
|
-
await db
|
|
81
|
-
.update(schema.pluginConnection)
|
|
82
|
-
.set({ actions: state.actions, data: seal(stored), updatedAt: new Date() })
|
|
83
|
-
.where(eq(schema.pluginConnection.id, same.id));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
await db.insert(schema.pluginConnection).values({
|
|
87
|
-
id: nanoid(14),
|
|
88
|
-
plugin: state.plugin,
|
|
89
|
-
projectId: state.projectId,
|
|
90
|
-
connector: connector.id,
|
|
91
|
-
label: account.label,
|
|
92
|
-
actions: state.actions,
|
|
93
|
-
data: seal(stored),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
137
|
return { plugin: state.plugin, projectId: state.projectId };
|
|
97
138
|
}
|
|
98
139
|
/** The tokens of a connection, refreshed when they run out within five minutes. */
|
|
@@ -161,9 +202,23 @@ export function pluginConnections(plugin) {
|
|
|
161
202
|
const out = [];
|
|
162
203
|
for (const id of ids) {
|
|
163
204
|
const connector = builtinConnector(id);
|
|
164
|
-
if (connector
|
|
165
|
-
|
|
205
|
+
if (!connector || connector.auth.kind === "browser" || !(await usable(connector))) {
|
|
206
|
+
continue;
|
|
166
207
|
}
|
|
208
|
+
out.push(connector.auth.kind === "api_key"
|
|
209
|
+
? {
|
|
210
|
+
id,
|
|
211
|
+
name: connector.name,
|
|
212
|
+
auth: "api_key",
|
|
213
|
+
fields: connector.auth.apiKey.fields.map((f) => ({
|
|
214
|
+
key: f.key,
|
|
215
|
+
label: f.label,
|
|
216
|
+
...(f.placeholder ? { placeholder: f.placeholder } : {}),
|
|
217
|
+
...(f.required === false ? { required: false } : {}),
|
|
218
|
+
...(f.secret ? { secret: true } : {}),
|
|
219
|
+
})),
|
|
220
|
+
}
|
|
221
|
+
: { id, name: connector.name, auth: "oauth2" });
|
|
167
222
|
}
|
|
168
223
|
return out;
|
|
169
224
|
},
|
|
@@ -172,13 +227,7 @@ export function pluginConnections(plugin) {
|
|
|
172
227
|
if (connector.auth.kind !== "oauth2") {
|
|
173
228
|
throw new Error("not an oauth connector");
|
|
174
229
|
}
|
|
175
|
-
|
|
176
|
-
where: eq(schema.project.id, space),
|
|
177
|
-
columns: { id: true },
|
|
178
|
-
});
|
|
179
|
-
if (!project) {
|
|
180
|
-
throw new Error(`There is no space "${space}".`);
|
|
181
|
-
}
|
|
230
|
+
await spaceExists(space);
|
|
182
231
|
const scopes = scopesOf(connector, actions);
|
|
183
232
|
const base = {
|
|
184
233
|
plugin,
|
|
@@ -212,6 +261,51 @@ export function pluginConnections(plugin) {
|
|
|
212
261
|
});
|
|
213
262
|
return { url };
|
|
214
263
|
},
|
|
264
|
+
async connect({ space, connector: connectorId, actions, credentials }) {
|
|
265
|
+
const connector = connectorOf(connectorId);
|
|
266
|
+
if (connector.auth.kind !== "api_key") {
|
|
267
|
+
throw new Error(`${connector.name} is connected by signing in: use start.`);
|
|
268
|
+
}
|
|
269
|
+
await spaceExists(space);
|
|
270
|
+
const wanted = knownActions(connector, actions);
|
|
271
|
+
const keys = {};
|
|
272
|
+
for (const field of connector.auth.apiKey.fields) {
|
|
273
|
+
const value = String(credentials[field.key] ?? "").trim();
|
|
274
|
+
if (!value && field.required !== false) {
|
|
275
|
+
throw Object.assign(new Error(`"${field.label}" is missing.`), {
|
|
276
|
+
status: 400,
|
|
277
|
+
code: "credentials",
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (value) {
|
|
281
|
+
keys[field.key] = value.slice(0, 500);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
let account;
|
|
285
|
+
try {
|
|
286
|
+
account = await connector.auth.apiKey.verify(keys, connectorFetch);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
throw Object.assign(new Error(String(err?.message ?? err).slice(0, 300)), {
|
|
290
|
+
status: 400,
|
|
291
|
+
code: "credentials",
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
const row = await keep({
|
|
295
|
+
plugin,
|
|
296
|
+
projectId: space,
|
|
297
|
+
connector: connector.id,
|
|
298
|
+
label: account.label,
|
|
299
|
+
actions: wanted,
|
|
300
|
+
stored: {
|
|
301
|
+
accessToken: JSON.stringify(keys),
|
|
302
|
+
refreshToken: null,
|
|
303
|
+
expiresAt: null,
|
|
304
|
+
scopes: [],
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
return view(row);
|
|
308
|
+
},
|
|
215
309
|
async list(space) {
|
|
216
310
|
const rows = await db.query.pluginConnection.findMany({
|
|
217
311
|
where: and(eq(schema.pluginConnection.plugin, plugin), eq(schema.pluginConnection.projectId, space)),
|
|
@@ -231,7 +325,7 @@ export function pluginConnections(plugin) {
|
|
|
231
325
|
if (!row.actions.includes(actionId)) {
|
|
232
326
|
throw new Error(`The connection was not made for "${actionId}". Connect it again.`);
|
|
233
327
|
}
|
|
234
|
-
const connector =
|
|
328
|
+
const connector = connectorOf(row.connector);
|
|
235
329
|
const action = connector.actions.find((a) => a.id === actionId);
|
|
236
330
|
if (!action) {
|
|
237
331
|
throw new Error(`${connector.name} has no action "${actionId}".`);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
CREATE TABLE `assistant_chat` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`tenant_id` text NOT NULL,
|
|
4
|
+
`user_id` text NOT NULL,
|
|
5
|
+
`title` text,
|
|
6
|
+
`summary` text,
|
|
7
|
+
`folded` integer DEFAULT 0 NOT NULL,
|
|
8
|
+
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
|
9
|
+
`closed_at` integer
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE INDEX `assistant_chat_user` ON `assistant_chat` (`tenant_id`,`user_id`,`closed_at`);--> statement-breakpoint
|
|
13
|
+
CREATE TABLE `assistant_message` (
|
|
14
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
15
|
+
`chat_id` text NOT NULL,
|
|
16
|
+
`role` text NOT NULL,
|
|
17
|
+
`content` text NOT NULL,
|
|
18
|
+
`cards` text,
|
|
19
|
+
`tool_calls` text,
|
|
20
|
+
`page` text,
|
|
21
|
+
`changed` integer DEFAULT false NOT NULL,
|
|
22
|
+
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
|
23
|
+
FOREIGN KEY (`chat_id`) REFERENCES `assistant_chat`(`id`) ON UPDATE no action ON DELETE cascade
|
|
24
|
+
);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
CREATE INDEX `assistant_message_chat` ON `assistant_message` (`chat_id`,`created_at`);--> statement-breakpoint
|
|
27
|
+
CREATE VIRTUAL TABLE `assistant_search` USING fts5(`chat_id` UNINDEXED, `message_id` UNINDEXED, `text`, tokenize='trigram remove_diacritics 1');--> statement-breakpoint
|
|
28
|
+
CREATE TRIGGER `assistant_message_search_ai` AFTER INSERT ON `assistant_message` BEGIN
|
|
29
|
+
INSERT INTO `assistant_search`(`chat_id`, `message_id`, `text`) VALUES (new.chat_id, new.id, new.content);
|
|
30
|
+
END;--> statement-breakpoint
|
|
31
|
+
CREATE TRIGGER `assistant_message_search_ad` AFTER DELETE ON `assistant_message` BEGIN
|
|
32
|
+
DELETE FROM `assistant_search` WHERE `message_id` = old.id;
|
|
33
|
+
END;--> statement-breakpoint
|
|
34
|
+
CREATE TRIGGER `assistant_chat_search_au` AFTER UPDATE OF `title`, `summary`, `closed_at` ON `assistant_chat` WHEN new.closed_at IS NOT NULL BEGIN
|
|
35
|
+
DELETE FROM `assistant_search` WHERE `chat_id` = new.id AND `message_id` IS NULL;
|
|
36
|
+
INSERT INTO `assistant_search`(`chat_id`, `message_id`, `text`) VALUES (new.id, NULL, coalesce(new.title, '') || char(10) || coalesce(new.summary, ''));
|
|
37
|
+
END;--> statement-breakpoint
|
|
38
|
+
CREATE TRIGGER `assistant_chat_search_ad` AFTER DELETE ON `assistant_chat` BEGIN
|
|
39
|
+
DELETE FROM `assistant_search` WHERE `chat_id` = old.id AND `message_id` IS NULL;
|
|
40
|
+
END;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `run` ADD `origin` text;
|