@engenty/wizards-runtime 0.13.0 → 0.14.0
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/architect.js +8 -7
- package/apps/runtime/dist/agents/goose-connections.js +82 -0
- package/apps/runtime/dist/agents/space-agent.js +9 -2
- package/apps/runtime/dist/agents/studio-assistant.js +101 -67
- package/apps/runtime/dist/agents/website.js +1 -1
- package/apps/runtime/dist/app.js +17 -1
- package/apps/runtime/dist/assistant/knows.js +6 -5
- package/apps/runtime/dist/authoring/guide.js +25 -5
- package/apps/runtime/dist/broker/account.js +166 -0
- package/apps/runtime/dist/broker/call.js +417 -0
- package/apps/runtime/dist/broker/caller.js +10 -0
- package/apps/runtime/dist/broker/grant.js +152 -0
- package/apps/runtime/dist/broker/host.js +51 -0
- package/apps/runtime/dist/broker/index.js +8 -0
- package/apps/runtime/dist/broker/kept.js +31 -0
- package/apps/runtime/dist/broker/log.js +240 -0
- package/apps/runtime/dist/broker/registry.js +9 -0
- package/apps/runtime/dist/broker/rwx.js +367 -0
- package/apps/runtime/dist/broker/send.js +189 -0
- package/apps/runtime/dist/connectors/builtin.js +1 -1
- package/apps/runtime/dist/connectors/external.js +38 -37
- package/apps/runtime/dist/connectors/index.js +30 -91
- package/apps/runtime/dist/connectors/mail.js +0 -8
- package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
- package/apps/runtime/dist/connectors/smtp.js +1 -1
- package/apps/runtime/dist/connectors/space-connections.js +436 -0
- package/apps/runtime/dist/db/adopt.js +3 -3
- package/apps/runtime/dist/db/client.js +9 -0
- package/apps/runtime/dist/db/live-triggers.js +65 -23
- package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
- package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
- package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
- package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
- package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
- package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
- package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
- package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
- package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
- package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
- package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
- package/apps/runtime/dist/db/schema.js +295 -72
- package/apps/runtime/dist/docs/dev/architecture.md +215 -0
- package/apps/runtime/dist/docs/dev/broker.md +298 -0
- package/apps/runtime/dist/docs/dev/index.md +5 -1
- package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
- package/apps/runtime/dist/docs/dev/meta.json +3 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
- package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
- package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
- package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
- package/apps/runtime/dist/docs/dev/skills.md +16 -9
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +40 -5
- package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
- package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
- package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
- package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
- package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
- package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
- package/apps/runtime/dist/docs/user-guide/index.md +10 -1
- package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
- package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
- package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
- package/apps/runtime/dist/docs/user-guide/space.md +5 -4
- package/apps/runtime/dist/docs/user-guide/together.md +16 -2
- package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
- package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
- package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
- package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
- package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
- package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
- package/apps/runtime/dist/engine/resources.js +43 -12
- package/apps/runtime/dist/engine/runner.js +75 -23
- package/apps/runtime/dist/engine/steps.js +30 -12
- package/apps/runtime/dist/engine/template.js +18 -1
- package/apps/runtime/dist/env.js +9 -4
- package/apps/runtime/dist/index.js +18 -2
- package/apps/runtime/dist/live/feed.js +2 -2
- package/apps/runtime/dist/live/origin.js +2 -2
- package/apps/runtime/dist/live/views.js +51 -26
- package/apps/runtime/dist/manage.js +7 -0
- package/apps/runtime/dist/mcp/flow-app.js +1 -1
- package/apps/runtime/dist/mcp/tools.js +75 -34
- package/apps/runtime/dist/models.js +1 -1
- package/apps/runtime/dist/motion-graphics/project.js +8 -8
- package/apps/runtime/dist/motion-graphics/tools.js +1 -1
- package/apps/runtime/dist/plugins/events.js +2 -2
- package/apps/runtime/dist/plugins/jobs.js +4 -1
- package/apps/runtime/dist/plugins/loader.js +2 -2
- package/apps/runtime/dist/prompts/architect.md +3 -3
- package/apps/runtime/dist/prompts/authoring.md +46 -12
- package/apps/runtime/dist/prompts/goose.md +7 -7
- package/apps/runtime/dist/prompts/mcp.md +6 -6
- package/apps/runtime/dist/prompts/services.md +4 -4
- package/apps/runtime/dist/prompts/step.md +2 -2
- package/apps/runtime/dist/prompts/tools.md +39 -10
- package/apps/runtime/dist/routes/api.js +31 -20
- package/apps/runtime/dist/routes/broker.js +316 -0
- package/apps/runtime/dist/routes/connections.js +71 -0
- package/apps/runtime/dist/routes/delivery.js +25 -0
- package/apps/runtime/dist/routes/discover.js +17 -0
- package/apps/runtime/dist/routes/live.js +11 -1
- package/apps/runtime/dist/routes/person.js +4 -1
- package/apps/runtime/dist/routes/plugins.js +3 -1
- package/apps/runtime/dist/routes/rules.js +26 -0
- package/apps/runtime/dist/routes/runs.js +54 -33
- package/apps/runtime/dist/routes/skills.js +6 -6
- package/apps/runtime/dist/routes/studio.js +153 -144
- package/apps/runtime/dist/routes/work.js +199 -0
- package/apps/runtime/dist/sandbox/index.js +27 -0
- package/apps/runtime/dist/services/access.js +38 -17
- package/apps/runtime/dist/services/api.js +38 -13
- package/apps/runtime/dist/services/architect.js +3 -3
- package/apps/runtime/dist/services/assistant-chats.js +9 -1
- package/apps/runtime/dist/services/brand.js +12 -12
- package/apps/runtime/dist/services/broker-bell.js +69 -0
- package/apps/runtime/dist/services/broker-notify.js +127 -0
- package/apps/runtime/dist/services/client-steps.js +79 -0
- package/apps/runtime/dist/services/cloud.js +42 -42
- package/apps/runtime/dist/services/command-risk.js +51 -0
- package/apps/runtime/dist/services/discover.js +85 -0
- package/apps/runtime/dist/services/knowledge-model.js +13 -13
- package/apps/runtime/dist/services/knowledge.js +117 -80
- package/apps/runtime/dist/services/manage-reports.js +74 -7
- package/apps/runtime/dist/services/members-studio.js +165 -0
- package/apps/runtime/dist/services/onboarding.js +22 -22
- package/apps/runtime/dist/services/package-file.js +1 -1
- package/apps/runtime/dist/services/package.js +22 -22
- package/apps/runtime/dist/services/pages.js +7 -7
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/seen.js +55 -0
- package/apps/runtime/dist/services/shares.js +23 -13
- package/apps/runtime/dist/services/site.js +23 -23
- package/apps/runtime/dist/services/skills-registry.js +15 -15
- package/apps/runtime/dist/services/skills.js +44 -44
- package/apps/runtime/dist/services/space-categories.js +35 -35
- package/apps/runtime/dist/services/space-data.js +130 -111
- package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
- package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
- package/apps/runtime/dist/services/space-origin.js +19 -11
- package/apps/runtime/dist/services/spaces.js +478 -612
- package/apps/runtime/dist/services/synced-spaces.js +668 -0
- package/apps/runtime/dist/services/themes.js +15 -15
- package/apps/runtime/dist/services/widgets.js +6 -6
- package/apps/runtime/dist/services/wizards.js +112 -38
- package/apps/runtime/dist/services/work-ai.js +257 -0
- package/apps/runtime/dist/services/work-approvals.js +104 -0
- package/apps/runtime/dist/services/work-chats.js +908 -0
- package/apps/runtime/dist/services/work-connections.js +90 -0
- package/apps/runtime/dist/services/work-files.js +85 -0
- package/apps/runtime/dist/services/work-mastra.js +73 -0
- package/apps/runtime/dist/services/work-sandbox.js +42 -0
- package/apps/runtime/dist/sharing/files.js +14 -4
- package/apps/runtime/dist/sharing/index.js +40 -39
- package/apps/runtime/dist/sharing/jobs.js +67 -17
- package/apps/runtime/dist/sharing/targets/connector.js +10 -6
- package/apps/runtime/dist/sharing/targets/email.js +10 -8
- package/apps/runtime/dist/sharing/targets/slack.js +10 -8
- package/apps/runtime/dist/sharing/targets/storage.js +6 -4
- package/apps/runtime/dist/store/index.js +14 -3
- package/apps/runtime/dist/store/shared-lists.js +4 -2
- package/apps/runtime/dist/sync/apply.js +2 -2
- package/apps/runtime/dist/sync/client.js +113 -113
- package/apps/runtime/dist/sync/hub.js +41 -41
- package/apps/runtime/dist/sync/log.js +12 -12
- package/apps/runtime/dist/sync/records.js +118 -120
- package/apps/runtime/dist/texts.js +38 -2
- package/apps/runtime/dist/tools/connections.js +112 -0
- package/apps/runtime/dist/tools/connector.js +157 -67
- package/apps/runtime/dist/tools/index.js +28 -13
- package/apps/runtime/dist/tools/mail.js +40 -11
- package/apps/runtime/dist/tools/pages.js +11 -5
- package/apps/runtime/dist/tools/plugin.js +43 -7
- package/apps/runtime/dist/tools/skills.js +1 -1
- package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
- package/apps/runtime/dist/tools/store.js +3 -2
- package/apps/runtime/dist/widgets/step.js +10 -10
- package/apps/web/dist/assets/AboutDialog-DgfeipUc.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-BoYJvgIu.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-Duab4zTO.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-ZrgGpYMC.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.js → FlowPreview-aMfwcPul.js} +1 -1
- package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
- package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-IB18afWN.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-rYbcmPGG.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DviWTLfi.js +9 -0
- package/apps/web/dist/assets/PublicRunner-C2geZhhM.js +1 -0
- package/apps/web/dist/assets/ReadOnly-kSb_Kbdm.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DM2h8N0J.js +2 -0
- package/apps/web/dist/assets/SetupPage-Wfyz6xH4.js +1 -0
- package/apps/web/dist/assets/SharePage-CyWQorWB.js +1 -0
- package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
- package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
- package/apps/web/dist/assets/SpacePage-q4Bk3N7k.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-C2CE6CC3.js +2 -0
- package/apps/web/dist/assets/changelog-B6hN1Cp7.js +1 -0
- package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
- package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
- package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
- package/apps/web/dist/assets/{code-xml-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
- package/apps/web/dist/assets/connection-sign-in-CIiv0t2p.js +1 -0
- package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
- package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
- package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
- package/apps/web/dist/assets/host-DJ7-p0Sc.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
- package/apps/web/dist/assets/index-D2akynS-.js +10 -0
- package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
- package/apps/web/dist/assets/{phone-DhkHteoJ.js → phone-Ctvf-Am-.js} +1 -1
- package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
- package/apps/web/dist/assets/{runners-G-XYaDgR.js → runners-CyIvJIHr.js} +1 -1
- package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
- package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
- package/apps/web/dist/assets/theme-CbTcTFWy.js +11 -0
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
- package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
- package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CVHoxdGM.js → volume-2-CU_oy81Z.js} +1 -1
- package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
- package/apps/web/dist/index.html +17 -10
- package/apps/web/dist/mcp/flow.html +119 -64
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -1
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +150 -8
- package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
- package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
- package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +26 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -2
- package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
- package/node_modules/@engenty/wizards-shared/dist/run.js +85 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
- package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
- package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
- package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
- package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
- package/package.json +4 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/plugin/skills/build-wizard/SKILL.md +1 -1
- package/apps/runtime/dist/services/projects.js +0 -473
- package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +0 -1
- package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
- package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
- package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
- package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
- package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
- package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
- package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
- package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
- package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
- package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
- package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
- package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
- package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
- package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
- package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
- package/apps/web/dist/assets/lock-C0uxcOlq.js +0 -1
- package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
- package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
- package/apps/web/dist/assets/session-BWI-KENJ.js +0 -2
- package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
- package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
- /package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +0 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
2
|
+
import { surfaceComponentsSchema, validateSurface } from "@engenty/wizards-shared/surface";
|
|
3
|
+
import { createTool } from "@mastra/core/tools";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { sortedTools } from "../agents/space-agent.js";
|
|
6
|
+
import { chatTurnWay } from "../agents/subscription.js";
|
|
7
|
+
import { subjectsOfPerson } from "../broker/rwx.js";
|
|
8
|
+
import { currentFeatures } from "../features.js";
|
|
9
|
+
import { HarnessModel } from "../harness/index.js";
|
|
10
|
+
import { managed } from "../manage.js";
|
|
11
|
+
import { attachTools, chatModel, gatewayTools } from "../models.js";
|
|
12
|
+
import { pluginsOf } from "../plugins/registry.js";
|
|
13
|
+
import { prompt } from "../prompts.js";
|
|
14
|
+
import { sandboxCapabilities, shellToolDescription } from "../sandbox/index.js";
|
|
15
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
16
|
+
import { assistantToolPlugin, assistantToolRisk, assistantToolsOf } from "../tools/plugin.js";
|
|
17
|
+
import { clip } from "../tools/shared.js";
|
|
18
|
+
import { skillsBlock, skillToolsOf } from "../tools/skills.js";
|
|
19
|
+
import { roleOf } from "./access.js";
|
|
20
|
+
import { ClientSteps } from "./client-steps.js";
|
|
21
|
+
import { activeSkills } from "./skills.js";
|
|
22
|
+
import { searchKnowledge } from "./space-index.js";
|
|
23
|
+
import { holdCall } from "./work-approvals.js";
|
|
24
|
+
import { workConnectionTools } from "./work-connections.js";
|
|
25
|
+
import { chatSandbox } from "./work-sandbox.js";
|
|
26
|
+
/**
|
|
27
|
+
* What the space's AI gets for one turn of a Work chat (docs/plans/work-chats.md): the model of
|
|
28
|
+
* the way the settings chose, the space's tools, and instructions that stay the same for the
|
|
29
|
+
* space, so the prompt's start is cached. The agent itself is the tenant's (work-mastra.ts); it
|
|
30
|
+
* reads this from the request context.
|
|
31
|
+
*/
|
|
32
|
+
export const TURN_KEY = "workTurn";
|
|
33
|
+
/** A turn stops after this long. */
|
|
34
|
+
export const TURN_MS = 20 * 60_000;
|
|
35
|
+
/** Steps one turn may take. */
|
|
36
|
+
export const MAX_STEPS = 16;
|
|
37
|
+
const instructionsFor = (space, skills) => [
|
|
38
|
+
`You are the AI of the space "${space}" in engenty wizards. The team of the space talks with you and with each other in this chat.`,
|
|
39
|
+
'Each message of a person comes as <user name="…">; answer the person who asked you, in their language, and call them by their name only when it helps.',
|
|
40
|
+
"Before you answer about the space (its clients, matters, files, data), look it up with search_space; say where you found it. When you can't find it, say so.",
|
|
41
|
+
"Write short, plain answers. Use lists or a table where they help. Rows, figures, a comparison or a few questions to the team can be a view instead: show_view.",
|
|
42
|
+
skills,
|
|
43
|
+
]
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.join("\n\n");
|
|
46
|
+
/** The space's skills that count, while the `skills` switch is on. */
|
|
47
|
+
async function spaceSkills(spaceId) {
|
|
48
|
+
return (await currentFeatures()).skills === true ? activeSkills(spaceId) : null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The chat's sandbox (work-sandbox.ts) as the tools see it: `run_command`, and the skills whose
|
|
52
|
+
* scripts may run written into it. None without a chat (an approved call runs alone) or where
|
|
53
|
+
* this server has no sandbox.
|
|
54
|
+
*/
|
|
55
|
+
function sandboxTools(chatId) {
|
|
56
|
+
const caps = chatId ? sandboxCapabilities() : null;
|
|
57
|
+
if (!(caps && chatId)) {
|
|
58
|
+
return { tools: {}, skill: null };
|
|
59
|
+
}
|
|
60
|
+
const handle = () => chatSandbox(chatId);
|
|
61
|
+
const report = (result) => ({
|
|
62
|
+
exitCode: result.exitCode,
|
|
63
|
+
stdout: clip(result.stdout, 8000),
|
|
64
|
+
stderr: clip(result.stderr, 4000),
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
skill: { handle, workdir: caps.workdir },
|
|
68
|
+
tools: {
|
|
69
|
+
run_command: createTool({
|
|
70
|
+
id: "run_command",
|
|
71
|
+
description: shellToolDescription(caps),
|
|
72
|
+
inputSchema: z.object({ command: z.string(), timeoutSeconds: z.number().optional() }),
|
|
73
|
+
execute: async ({ command, timeoutSeconds }) => report(await handle().exec(command, {
|
|
74
|
+
timeoutMs: Math.min((timeoutSeconds ?? 120) * 1000, 600_000),
|
|
75
|
+
})),
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** A view stays this small: what a chat shows at a glance, not a data dump. */
|
|
81
|
+
export const VIEW_MAX_BYTES = 64_000;
|
|
82
|
+
/**
|
|
83
|
+
* The view a turn draws in the chat (docs/plans/work-chats.md, generative UI): components of the
|
|
84
|
+
* surface catalog, the chat's own (Form, Ref, ask) among them, and the data they bind. It is
|
|
85
|
+
* checked here, so the model gets the issues and tries again; the chat draws the call's input
|
|
86
|
+
* once its result says ok. A client as the model calls it like any tool of the space.
|
|
87
|
+
*/
|
|
88
|
+
export const showView = () => createTool({
|
|
89
|
+
id: "show_view",
|
|
90
|
+
description: [
|
|
91
|
+
"Shows a view in the chat: key figures, a table, a chart, a list of files, a form that asks the team. Everyone in the chat sees it.",
|
|
92
|
+
prompt("authoring", "surfaces"),
|
|
93
|
+
prompt("authoring", "surfaces.chat"),
|
|
94
|
+
].join("\n\n"),
|
|
95
|
+
inputSchema: z.object({
|
|
96
|
+
title: z.string().max(120).optional().describe("What the view shows, in a few words"),
|
|
97
|
+
components: surfaceComponentsSchema,
|
|
98
|
+
data: z
|
|
99
|
+
.record(z.string(), z.unknown())
|
|
100
|
+
.default({})
|
|
101
|
+
.describe('What the components bind by {"path": "/key/…"}: the rows and figures you found'),
|
|
102
|
+
}),
|
|
103
|
+
execute: async ({ components, data }) => {
|
|
104
|
+
const bytes = Buffer.byteLength(JSON.stringify({ components, data }));
|
|
105
|
+
const issues = bytes > VIEW_MAX_BYTES
|
|
106
|
+
? [
|
|
107
|
+
`The view is ${bytes} bytes, more than ${VIEW_MAX_BYTES}: show fewer rows or less text.`,
|
|
108
|
+
]
|
|
109
|
+
: validateSurface(components, Object.keys(data ?? {}), { chat: true }).map((i) => i.message);
|
|
110
|
+
return issues.length
|
|
111
|
+
? { ok: false, issues, note: "Nothing was shown. Fix these and call show_view again." }
|
|
112
|
+
: { ok: true, note: "Shown in the chat. Don't repeat what it shows." };
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
/** Whether the model can search the web itself: on Anthropic's API, or through the gateway. */
|
|
116
|
+
const searches = (resolved) => resolved.vendor === "anthropic" || resolved.gateway;
|
|
117
|
+
/**
|
|
118
|
+
* The space's tools for a turn: its knowledge, its skills, the chat's sandbox, the space's
|
|
119
|
+
* connections open to the person (work-connections.ts), the plugins' tools, the web; the plugins
|
|
120
|
+
* and the web the person turned off (`choice`) left out.
|
|
121
|
+
*/
|
|
122
|
+
async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = null, approved = null) {
|
|
123
|
+
const sandbox = sandboxTools(chatId);
|
|
124
|
+
const connections = await workConnectionTools({
|
|
125
|
+
space,
|
|
126
|
+
userId,
|
|
127
|
+
chatId: chatId ?? approved?.chatId ?? null,
|
|
128
|
+
byAdmin: approved?.byAdmin,
|
|
129
|
+
});
|
|
130
|
+
const skills = await spaceSkills(space.id);
|
|
131
|
+
// The turn reads as the person who asked: what they may not read, the AI does not find.
|
|
132
|
+
const who = subjectsOfPerson(userId, await roleOf(userId));
|
|
133
|
+
const tools = {
|
|
134
|
+
search_space: createTool({
|
|
135
|
+
id: "search_space",
|
|
136
|
+
description: "Searches the space's knowledge: its documents, pages, tables and the sources its plugins bring. Returns the best matches with where they are.",
|
|
137
|
+
inputSchema: z.object({ query: z.string().min(2).max(300) }),
|
|
138
|
+
execute: async ({ query }) => {
|
|
139
|
+
const found = await searchKnowledge(space.id, query, { limit: 8, signal, who });
|
|
140
|
+
return { hits: found.hits };
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
show_view: showView(),
|
|
144
|
+
...sandbox.tools,
|
|
145
|
+
...(skills ? skillToolsOf(skills, () => { }, sandbox.skill) : {}),
|
|
146
|
+
...connections.tools,
|
|
147
|
+
...(await assistantToolsOf({
|
|
148
|
+
tenantId: currentTenant(),
|
|
149
|
+
space,
|
|
150
|
+
userId,
|
|
151
|
+
signal,
|
|
152
|
+
emit: () => { },
|
|
153
|
+
changed: () => { },
|
|
154
|
+
card: () => { },
|
|
155
|
+
})),
|
|
156
|
+
};
|
|
157
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
158
|
+
const plugin = tool && typeof tool === "object" ? assistantToolPlugin.get(tool) : undefined;
|
|
159
|
+
if (plugin && choice.pluginsOff?.includes(plugin)) {
|
|
160
|
+
delete tools[name];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (choice.web !== false && resolved?.vendor === "anthropic") {
|
|
164
|
+
tools.web_search = anthropic.tools.webSearch_20250305({ maxUses: 5 });
|
|
165
|
+
}
|
|
166
|
+
else if (choice.web !== false && resolved?.gateway) {
|
|
167
|
+
tools.web_search = gatewayTools.perplexitySearch({ maxResults: 6 });
|
|
168
|
+
}
|
|
169
|
+
return sortedTools(tools);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* What the composer offers for a turn: web search where the model can search, and the plugins
|
|
173
|
+
* whose tools the AI has. A way that isn't ready yet searches nothing.
|
|
174
|
+
*/
|
|
175
|
+
export async function composerTools() {
|
|
176
|
+
const resolved = await chatModel(await chatTurnWay(managed), "standard").catch(() => null);
|
|
177
|
+
const plugins = (await pluginsOf(currentTenant()))
|
|
178
|
+
.filter((p) => p.assistantTools.size > 0)
|
|
179
|
+
.map((p) => ({ id: p.source.id, name: p.source.manifest.name }));
|
|
180
|
+
return { web: Boolean(resolved && searches(resolved)), plugins };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Whether a call of the tool waits for a person's approval: a plugin's tool marked `outside`
|
|
184
|
+
* does, and so does one without a mark (decided: "risk per tool", the safe side); a connection's
|
|
185
|
+
* write, send or delete is marked so too (a confirmed action). The space's own tools only read.
|
|
186
|
+
*/
|
|
187
|
+
const UNMARKED_ASKS = true;
|
|
188
|
+
export function asksFirst(tool) {
|
|
189
|
+
if (!tool || typeof tool !== "object" || !assistantToolRisk.has(tool)) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const risk = assistantToolRisk.get(tool);
|
|
193
|
+
return risk === "outside" || (risk === null && UNMARKED_ASKS);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The gate on the tool: a call that waits for approval doesn't run. It is stored, and the AI is
|
|
197
|
+
* told it waits; Approve runs it later (work-chats.ts). On a client too, since the gate is the
|
|
198
|
+
* tool's own and the client calls the tool.
|
|
199
|
+
*/
|
|
200
|
+
export function gated(tools, turn) {
|
|
201
|
+
return Object.fromEntries(Object.entries(tools).map(([name, tool]) => {
|
|
202
|
+
if (!asksFirst(tool)) {
|
|
203
|
+
return [name, tool];
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
name,
|
|
207
|
+
Object.assign(Object.create(Object.getPrototypeOf(tool)), tool, {
|
|
208
|
+
execute: async (input) => {
|
|
209
|
+
const id = await holdCall(turn, name, input);
|
|
210
|
+
return {
|
|
211
|
+
approval: id,
|
|
212
|
+
status: "waiting",
|
|
213
|
+
note: "Held for a person's approval. Don't call it again: the chat tells you once it is decided.",
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
];
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
/** One tool of the space as it runs once approved, for the person the turn was for. */
|
|
221
|
+
export async function toolToRun(space, userId, name, signal, approved) {
|
|
222
|
+
const tools = await toolsFor(null, space, userId, signal, {}, null, approved);
|
|
223
|
+
return tools[name] ?? null;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Everything a turn of the space's AI needs, made for the person who asked. Calls that reach past
|
|
227
|
+
* the space are held (`gated`); on a client the tools are recorded as they run
|
|
228
|
+
* (client-steps.ts): the client runs them itself. `choice`: what the person chose in the
|
|
229
|
+
* composer.
|
|
230
|
+
*/
|
|
231
|
+
export async function workTurn(turn, signal, steps, choice = {}) {
|
|
232
|
+
const resolved = await chatModel(await chatTurnWay(managed), choice.extra ? "high" : "standard");
|
|
233
|
+
const made = gated(await toolsFor(resolved, turn.space, turn.userId, signal, choice, turn.chatId), turn);
|
|
234
|
+
const tools = resolved.model instanceof HarnessModel ? steps.wrap(made) : made;
|
|
235
|
+
attachTools(resolved, tools);
|
|
236
|
+
const skills = await spaceSkills(turn.space.id);
|
|
237
|
+
const block = skills
|
|
238
|
+
? skillsBlock(skills, { tools: true, sandbox: sandboxCapabilities() !== null })
|
|
239
|
+
: "";
|
|
240
|
+
return { resolved, tools, instructions: instructionsFor(turn.space.name, block) };
|
|
241
|
+
}
|
|
242
|
+
export function lazyTurn(turn, choice = {}) {
|
|
243
|
+
const controller = new AbortController();
|
|
244
|
+
const steps = new ClientSteps();
|
|
245
|
+
let made = null;
|
|
246
|
+
return {
|
|
247
|
+
signal: controller.signal,
|
|
248
|
+
steps,
|
|
249
|
+
get() {
|
|
250
|
+
if (!made) {
|
|
251
|
+
setTimeout(() => controller.abort(new Error("The turn took too long.")), TURN_MS).unref();
|
|
252
|
+
made = workTurn(turn, controller.signal, steps, choice);
|
|
253
|
+
}
|
|
254
|
+
return made;
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { and, asc, desc, eq, inArray } from "drizzle-orm";
|
|
2
|
+
import { nanoid } from "nanoid";
|
|
3
|
+
import { db, schema } from "../db/client.js";
|
|
4
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
5
|
+
import { isAdminRole } from "./access.js";
|
|
6
|
+
import { ServiceError } from "./errors.js";
|
|
7
|
+
const view = (a) => ({
|
|
8
|
+
id: a.id,
|
|
9
|
+
chatId: a.chatId,
|
|
10
|
+
toolName: a.toolName,
|
|
11
|
+
input: a.input ?? null,
|
|
12
|
+
askedBy: a.askedBy,
|
|
13
|
+
heldFor: a.heldFor,
|
|
14
|
+
state: a.state,
|
|
15
|
+
output: a.output ?? null,
|
|
16
|
+
decidedBy: a.decidedBy,
|
|
17
|
+
createdAt: a.createdAt.toISOString(),
|
|
18
|
+
});
|
|
19
|
+
/** Stores a call the gate held; its id goes to the AI and the chat's card. */
|
|
20
|
+
export async function holdCall(turn, toolName, input, heldFor = "asker") {
|
|
21
|
+
const id = nanoid(12);
|
|
22
|
+
await db.insert(schema.chatApproval).values({
|
|
23
|
+
id,
|
|
24
|
+
tenantId: currentTenant(),
|
|
25
|
+
chatId: turn.chatId,
|
|
26
|
+
toolName,
|
|
27
|
+
input: input ?? null,
|
|
28
|
+
askedBy: turn.userId,
|
|
29
|
+
heldFor,
|
|
30
|
+
});
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
export async function approvalsOf(chatId) {
|
|
34
|
+
const rows = await db.query.chatApproval.findMany({
|
|
35
|
+
where: eq(schema.chatApproval.chatId, chatId),
|
|
36
|
+
orderBy: [asc(schema.chatApproval.createdAt)],
|
|
37
|
+
});
|
|
38
|
+
return rows.map(view);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether the person may decide: the turn was theirs, or they own or run the organization. A call
|
|
42
|
+
* held for the admins is theirs alone, whoever asked.
|
|
43
|
+
*/
|
|
44
|
+
export const mayDecide = (user, approval) => isAdminRole(user.role) || (approval.heldFor === "asker" && approval.askedBy === user.id);
|
|
45
|
+
/**
|
|
46
|
+
* Takes the decision, once: only a pending approval of this chat changes, so a second click or a
|
|
47
|
+
* second person gets a conflict and nothing runs twice.
|
|
48
|
+
*/
|
|
49
|
+
export async function takeDecision(user, chatId, id, approve) {
|
|
50
|
+
const found = await db.query.chatApproval.findFirst({
|
|
51
|
+
where: and(eq(schema.chatApproval.id, id), eq(schema.chatApproval.chatId, chatId)),
|
|
52
|
+
});
|
|
53
|
+
if (!found) {
|
|
54
|
+
throw new ServiceError("not_found", "approval not found");
|
|
55
|
+
}
|
|
56
|
+
if (!mayDecide(user, found)) {
|
|
57
|
+
throw new ServiceError("forbidden", found.heldFor === "admins"
|
|
58
|
+
? "only an owner or admin decides"
|
|
59
|
+
: "only who asked, or an owner or admin, decides");
|
|
60
|
+
}
|
|
61
|
+
const [taken] = await db
|
|
62
|
+
.update(schema.chatApproval)
|
|
63
|
+
.set({ state: approve ? "approved" : "denied", decidedBy: user.id, decidedAt: new Date() })
|
|
64
|
+
.where(and(eq(schema.chatApproval.id, id), eq(schema.chatApproval.state, "pending")))
|
|
65
|
+
.returning();
|
|
66
|
+
if (!taken) {
|
|
67
|
+
throw new ServiceError("revision_conflict", "already decided");
|
|
68
|
+
}
|
|
69
|
+
return taken;
|
|
70
|
+
}
|
|
71
|
+
/** What the approved call gave, or why it failed. */
|
|
72
|
+
export async function noteOutcome(id, outcome) {
|
|
73
|
+
await db
|
|
74
|
+
.update(schema.chatApproval)
|
|
75
|
+
.set("error" in outcome
|
|
76
|
+
? { state: "failed", output: { error: outcome.error } }
|
|
77
|
+
: { output: outcome.output ?? null })
|
|
78
|
+
.where(eq(schema.chatApproval.id, id));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The approvals waiting for the person, newest first: the bell. A member sees their own, in the
|
|
82
|
+
* chats they see; an owner or admin every pending call of the organization, those held for the
|
|
83
|
+
* admins among them, in private chats they are not in too (docs/plans/capabilities.md, A7a).
|
|
84
|
+
*/
|
|
85
|
+
export async function waitingFor(user, visibleChatIds) {
|
|
86
|
+
const admin = isAdminRole(user.role);
|
|
87
|
+
if (!(admin || visibleChatIds.length)) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const rows = await db.query.chatApproval.findMany({
|
|
91
|
+
where: and(eq(schema.chatApproval.tenantId, user.tenantId), eq(schema.chatApproval.state, "pending"), admin
|
|
92
|
+
? undefined
|
|
93
|
+
: and(inArray(schema.chatApproval.chatId, visibleChatIds), eq(schema.chatApproval.askedBy, user.id), eq(schema.chatApproval.heldFor, "asker"))),
|
|
94
|
+
orderBy: [desc(schema.chatApproval.createdAt)],
|
|
95
|
+
});
|
|
96
|
+
return rows.map(view);
|
|
97
|
+
}
|
|
98
|
+
/** Whether a tool's result says the call is held: the gate's answer, and a hold for the admins. */
|
|
99
|
+
export function heldBy(output) {
|
|
100
|
+
const o = output;
|
|
101
|
+
return o && typeof o === "object" && typeof o.approval === "string" && o.status === "waiting"
|
|
102
|
+
? o.approval
|
|
103
|
+
: null;
|
|
104
|
+
}
|