@engenty/wizards-runtime 0.13.0 → 0.14.1
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 +26 -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/{0027_space_skill.sql → 0030_space_skill.sql} +8 -8
- 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-SpDcn8VZ.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-Bgnm_3dk.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-DAnjV6cZ.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-B98C-9Nv.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-D8IYLg_S.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-DlBt0Mfq.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DC1kAi3x.js +9 -0
- package/apps/web/dist/assets/PublicRunner-D6lKP0j8.js +1 -0
- package/apps/web/dist/assets/ReadOnly-DFsuKPCw.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DkHeCO2c.js +2 -0
- package/apps/web/dist/assets/SetupPage-DZ8xRkfS.js +1 -0
- package/apps/web/dist/assets/SharePage-494ZPsjQ.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-CWlU_BZP.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-BKNkNJyG.js +2 -0
- package/apps/web/dist/assets/changelog-BhMZS-rs.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-Cngd_QDO.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-C0WQlRKB.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-ClVtdDUZ.js +10 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -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-BCau3f6O.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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { formatTableCell } from "@engenty/wizards-shared/engenty/data-tables";
|
|
2
2
|
import { slugOf, } from "@engenty/wizards-shared/knowledge";
|
|
3
3
|
import { and, asc, count, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
|
4
|
+
import { assertRwx, pageResources, readable, tableResources } from "../broker/rwx.js";
|
|
4
5
|
import { db, schema } from "../db/client.js";
|
|
5
6
|
import { embeddingModel, systemOneAccess } from "../models.js";
|
|
6
7
|
import { prompt } from "../prompts.js";
|
|
7
8
|
import { notFound, ServiceError } from "./errors.js";
|
|
8
|
-
import { ownedProject } from "./projects.js";
|
|
9
9
|
import { categoryLines, categoryRows, dateOf, filterItems, itemCategoriesOf, listCategories, numberOf, } from "./space-categories.js";
|
|
10
|
+
import { ownedSpace } from "./spaces.js";
|
|
10
11
|
/** Gives each item without a slug one, unique among its siblings, and keeps it. */
|
|
11
12
|
async function slugsFor(rows, siblingsOf, save) {
|
|
12
13
|
const taken = new Map();
|
|
@@ -37,14 +38,14 @@ async function slugsFor(rows, siblingsOf, save) {
|
|
|
37
38
|
return out;
|
|
38
39
|
}
|
|
39
40
|
/** A slug for a new page among its siblings, or a new table among the space's tables. */
|
|
40
|
-
export async function freeSlug(
|
|
41
|
+
export async function freeSlug(spaceId, title, of, except) {
|
|
41
42
|
const rows = of === "table"
|
|
42
43
|
? await db.query.spaceTable.findMany({
|
|
43
|
-
where: and(eq(schema.spaceTable.
|
|
44
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)),
|
|
44
45
|
columns: { id: true, slug: true },
|
|
45
46
|
})
|
|
46
47
|
: await db.query.spacePage.findMany({
|
|
47
|
-
where: and(eq(schema.spacePage.
|
|
48
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId), of.parentId
|
|
48
49
|
? eq(schema.spacePage.parentId, of.parentId)
|
|
49
50
|
: isNull(schema.spacePage.parentId)),
|
|
50
51
|
columns: { id: true, slug: true },
|
|
@@ -58,9 +59,9 @@ export async function freeSlug(projectId, title, of, except) {
|
|
|
58
59
|
return slug;
|
|
59
60
|
}
|
|
60
61
|
/** The space's own pages with their paths, by id. */
|
|
61
|
-
export async function pageTree(
|
|
62
|
+
export async function pageTree(spaceId) {
|
|
62
63
|
const rows = await db.query.spacePage.findMany({
|
|
63
|
-
where: and(eq(schema.spacePage.
|
|
64
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)),
|
|
64
65
|
columns: { id: true, parentId: true, title: true, slug: true, position: true },
|
|
65
66
|
orderBy: [asc(schema.spacePage.position), asc(schema.spacePage.title)],
|
|
66
67
|
});
|
|
@@ -97,9 +98,9 @@ export async function pageTree(projectId) {
|
|
|
97
98
|
return out;
|
|
98
99
|
}
|
|
99
100
|
/** The space's own tables with their paths, by id. */
|
|
100
|
-
export async function tablePaths(
|
|
101
|
+
export async function tablePaths(spaceId) {
|
|
101
102
|
const rows = await db.query.spaceTable.findMany({
|
|
102
|
-
where: and(eq(schema.spaceTable.
|
|
103
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)),
|
|
103
104
|
columns: { id: true, slug: true, title: true },
|
|
104
105
|
orderBy: [asc(schema.spaceTable.createdAt)],
|
|
105
106
|
});
|
|
@@ -107,11 +108,11 @@ export async function tablePaths(projectId) {
|
|
|
107
108
|
return new Map(rows.map((r) => [r.id, `tables/${slugs.get(r.id)}`]));
|
|
108
109
|
}
|
|
109
110
|
/** The space's documents with their paths, by id: their names, made unique. */
|
|
110
|
-
export async function filePaths(
|
|
111
|
-
const rows = await db.query.
|
|
112
|
-
where: and(eq(schema.
|
|
111
|
+
export async function filePaths(spaceId) {
|
|
112
|
+
const rows = await db.query.spaceFile.findMany({
|
|
113
|
+
where: and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.kind, "document")),
|
|
113
114
|
columns: { id: true, name: true },
|
|
114
|
-
orderBy: [asc(schema.
|
|
115
|
+
orderBy: [asc(schema.spaceFile.createdAt)],
|
|
115
116
|
});
|
|
116
117
|
const taken = new Set();
|
|
117
118
|
const out = new Map();
|
|
@@ -133,24 +134,24 @@ const cleanPath = (path) => path
|
|
|
133
134
|
.replace(/\.(md|csv)$/i, "")
|
|
134
135
|
.toLowerCase();
|
|
135
136
|
/** What a path names; null when nothing in the space has it. */
|
|
136
|
-
export async function resolvePath(
|
|
137
|
+
export async function resolvePath(spaceId, path) {
|
|
137
138
|
const want = cleanPath(path);
|
|
138
139
|
if (want.startsWith("pages/")) {
|
|
139
|
-
for (const node of (await pageTree(
|
|
140
|
+
for (const node of (await pageTree(spaceId)).values()) {
|
|
140
141
|
if (node.path === want) {
|
|
141
142
|
return { kind: "page", id: node.id, path: node.path };
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
else if (want.startsWith("tables/")) {
|
|
146
|
-
for (const [id, p] of await tablePaths(
|
|
147
|
+
for (const [id, p] of await tablePaths(spaceId)) {
|
|
147
148
|
if (p === want) {
|
|
148
149
|
return { kind: "table", id, path: p };
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
else if (want.startsWith("files/")) {
|
|
153
|
-
for (const [id, p] of await filePaths(
|
|
154
|
+
for (const [id, p] of await filePaths(spaceId)) {
|
|
154
155
|
if (p.toLowerCase() === want) {
|
|
155
156
|
return { kind: "file", id, path: p };
|
|
156
157
|
}
|
|
@@ -160,38 +161,48 @@ export async function resolvePath(projectId, path) {
|
|
|
160
161
|
}
|
|
161
162
|
// --- what the studio lists ---------------------------------------------------------
|
|
162
163
|
/** Files a page or a table was read from: they stand behind it, not on their own. */
|
|
163
|
-
async function convertedFiles(
|
|
164
|
+
async function convertedFiles(spaceId) {
|
|
164
165
|
const [pages, tables] = await Promise.all([
|
|
165
166
|
db
|
|
166
167
|
.selectDistinct({ id: schema.spacePage.fileId })
|
|
167
168
|
.from(schema.spacePage)
|
|
168
|
-
.where(and(eq(schema.spacePage.
|
|
169
|
+
.where(and(eq(schema.spacePage.spaceId, spaceId), isNotNull(schema.spacePage.fileId))),
|
|
169
170
|
db
|
|
170
171
|
.selectDistinct({ id: schema.spaceTable.fileId })
|
|
171
172
|
.from(schema.spaceTable)
|
|
172
|
-
.where(and(eq(schema.spaceTable.
|
|
173
|
+
.where(and(eq(schema.spaceTable.spaceId, spaceId), isNotNull(schema.spaceTable.fileId))),
|
|
173
174
|
]);
|
|
174
175
|
return new Set([...pages, ...tables].map((r) => r.id));
|
|
175
176
|
}
|
|
176
|
-
/**
|
|
177
|
-
|
|
178
|
-
const
|
|
177
|
+
/** The items among these the subjects may read, each with the document it was made from. */
|
|
178
|
+
async function readableItems(spaceId, who, items) {
|
|
179
|
+
const ok = await readable(spaceId, who, items.map((i) => i.kind === "file"
|
|
180
|
+
? { kind: "document", id: i.id }
|
|
181
|
+
: { kind: i.kind, id: i.id, fileId: i.fileId }));
|
|
182
|
+
return items.filter((i) => ok.has(i.id));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Everything Knowledge holds that `who` may read: pages (sub-pages counted under them), tables,
|
|
186
|
+
* files, categories.
|
|
187
|
+
*/
|
|
188
|
+
export async function listKnowledge(userId, spaceId, who) {
|
|
189
|
+
const space = await ownedSpace(userId, spaceId);
|
|
179
190
|
const [tree, tables, rowCounts, files, converted, categories, embeddings, checker] = await Promise.all([
|
|
180
|
-
pageTree(
|
|
191
|
+
pageTree(space.id),
|
|
181
192
|
db.query.spaceTable.findMany({
|
|
182
|
-
where: and(eq(schema.spaceTable.
|
|
193
|
+
where: and(eq(schema.spaceTable.spaceId, space.id), isNull(schema.spaceTable.wizardId)),
|
|
183
194
|
}),
|
|
184
195
|
db
|
|
185
196
|
.select({ tableId: schema.spaceTableRow.tableId, n: count() })
|
|
186
197
|
.from(schema.spaceTableRow)
|
|
187
198
|
.innerJoin(schema.spaceTable, eq(schema.spaceTable.id, schema.spaceTableRow.tableId))
|
|
188
|
-
.where(and(eq(schema.spaceTable.
|
|
199
|
+
.where(and(eq(schema.spaceTable.spaceId, space.id), isNull(schema.spaceTable.wizardId)))
|
|
189
200
|
.groupBy(schema.spaceTableRow.tableId),
|
|
190
|
-
db.query.
|
|
191
|
-
where: and(eq(schema.
|
|
201
|
+
db.query.spaceFile.findMany({
|
|
202
|
+
where: and(eq(schema.spaceFile.spaceId, space.id), eq(schema.spaceFile.kind, "document")),
|
|
192
203
|
}),
|
|
193
|
-
convertedFiles(
|
|
194
|
-
listCategories(
|
|
204
|
+
convertedFiles(space.id),
|
|
205
|
+
listCategories(space.id),
|
|
195
206
|
embeddingModel()
|
|
196
207
|
.then(Boolean)
|
|
197
208
|
.catch(() => false),
|
|
@@ -199,10 +210,10 @@ export async function listKnowledge(userId, projectId) {
|
|
|
199
210
|
.then(Boolean)
|
|
200
211
|
.catch(() => false),
|
|
201
212
|
]);
|
|
202
|
-
const tPaths = await tablePaths(
|
|
203
|
-
const fPaths = await filePaths(
|
|
213
|
+
const tPaths = await tablePaths(space.id);
|
|
214
|
+
const fPaths = await filePaths(space.id);
|
|
204
215
|
const pages = await db.query.spacePage.findMany({
|
|
205
|
-
where: and(eq(schema.spacePage.
|
|
216
|
+
where: and(eq(schema.spacePage.spaceId, space.id), isNull(schema.spacePage.wizardId), isNull(schema.spacePage.parentId)),
|
|
206
217
|
columns: { markdown: false },
|
|
207
218
|
});
|
|
208
219
|
const children = new Map();
|
|
@@ -276,10 +287,15 @@ export async function listKnowledge(userId, projectId) {
|
|
|
276
287
|
})),
|
|
277
288
|
];
|
|
278
289
|
items.sort((a, b) => a.title.localeCompare(b.title, "de"));
|
|
279
|
-
return {
|
|
290
|
+
return {
|
|
291
|
+
items: await readableItems(space.id, who, items),
|
|
292
|
+
categories,
|
|
293
|
+
embeddings,
|
|
294
|
+
checked: checker,
|
|
295
|
+
};
|
|
280
296
|
}
|
|
281
297
|
/** A value opened in the studio: its summary, and the items and rows that have it. */
|
|
282
|
-
export async function valueContents(userId, valueId) {
|
|
298
|
+
export async function valueContents(userId, valueId, who) {
|
|
283
299
|
const value = await db.query.spaceCategoryValue.findFirst({
|
|
284
300
|
where: eq(schema.spaceCategoryValue.id, valueId),
|
|
285
301
|
});
|
|
@@ -291,7 +307,7 @@ export async function valueContents(userId, valueId) {
|
|
|
291
307
|
if (!(value && category)) {
|
|
292
308
|
throw notFound();
|
|
293
309
|
}
|
|
294
|
-
const
|
|
310
|
+
const space = await ownedSpace(userId, category.spaceId);
|
|
295
311
|
const having = await db.query.spaceItemCategory.findMany({
|
|
296
312
|
where: eq(schema.spaceItemCategory.valueId, value.id),
|
|
297
313
|
});
|
|
@@ -301,32 +317,35 @@ export async function valueContents(userId, valueId) {
|
|
|
301
317
|
category: { id: category.id, name: category.name },
|
|
302
318
|
summary: value.summary,
|
|
303
319
|
summaryAt: value.summaryAt?.toISOString() ?? null,
|
|
304
|
-
...(await itemsHaving(userId,
|
|
320
|
+
...(await itemsHaving(userId, space.id, having, who)),
|
|
305
321
|
};
|
|
306
322
|
}
|
|
307
323
|
/** Everything that has a category, whatever its value: what the category's page lists. */
|
|
308
|
-
export async function categoryContents(userId, categoryId) {
|
|
324
|
+
export async function categoryContents(userId, categoryId, who) {
|
|
309
325
|
const category = await db.query.spaceCategory.findFirst({
|
|
310
326
|
where: eq(schema.spaceCategory.id, categoryId),
|
|
311
327
|
});
|
|
312
328
|
if (!category) {
|
|
313
329
|
throw notFound();
|
|
314
330
|
}
|
|
315
|
-
const
|
|
331
|
+
const space = await ownedSpace(userId, category.spaceId);
|
|
316
332
|
const having = await db.query.spaceItemCategory.findMany({
|
|
317
333
|
where: eq(schema.spaceItemCategory.categoryId, category.id),
|
|
318
334
|
});
|
|
319
|
-
return itemsHaving(userId,
|
|
335
|
+
return itemsHaving(userId, space.id, having, who);
|
|
320
336
|
}
|
|
321
|
-
/**
|
|
322
|
-
|
|
323
|
-
|
|
337
|
+
/**
|
|
338
|
+
* The items rows of `space_item_category` name, as the studio lists them, and rows by table;
|
|
339
|
+
* only what `who` may read.
|
|
340
|
+
*/
|
|
341
|
+
async function itemsHaving(userId, spaceId, having, who) {
|
|
342
|
+
const space = { id: spaceId };
|
|
324
343
|
const pageIds = having.flatMap((h) => (h.pageId ? [h.pageId] : []));
|
|
325
344
|
const tableIds = having.flatMap((h) => (h.tableId ? [h.tableId] : []));
|
|
326
345
|
const fileIds = having.flatMap((h) => (h.fileId ? [h.fileId] : []));
|
|
327
346
|
const rowIds = having.flatMap((h) => (h.rowId ? [h.rowId] : []));
|
|
328
|
-
const all = await listKnowledge(userId,
|
|
329
|
-
const tree = await pageTree(
|
|
347
|
+
const all = await listKnowledge(userId, space.id, who);
|
|
348
|
+
const tree = await pageTree(space.id);
|
|
330
349
|
const subPages = pageIds.filter((id) => !all.items.some((i) => i.key === `p:${id}`));
|
|
331
350
|
const subItems = [];
|
|
332
351
|
if (subPages.length) {
|
|
@@ -364,12 +383,19 @@ async function itemsHaving(userId, projectId, having) {
|
|
|
364
383
|
rowTables.set(r.tableId, (rowTables.get(r.tableId) ?? 0) + 1);
|
|
365
384
|
}
|
|
366
385
|
}
|
|
386
|
+
// A row is read as its table is.
|
|
387
|
+
const readTables = await readable(space.id, who, await tableResources([...rowTables.keys()]));
|
|
388
|
+
for (const tableId of [...rowTables.keys()]) {
|
|
389
|
+
if (!readTables.has(tableId)) {
|
|
390
|
+
rowTables.delete(tableId);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
367
393
|
return {
|
|
368
394
|
items: [
|
|
369
395
|
...all.items.filter((i) => (i.kind === "page" && pageIds.includes(i.id)) ||
|
|
370
396
|
(i.kind === "table" && tableIds.includes(i.id)) ||
|
|
371
397
|
(i.kind === "file" && fileIds.includes(i.id))),
|
|
372
|
-
...subItems,
|
|
398
|
+
...(await readableItems(space.id, who, subItems)),
|
|
373
399
|
],
|
|
374
400
|
rows: [...rowTables].map(([tableId, n]) => ({
|
|
375
401
|
tableId,
|
|
@@ -380,7 +406,7 @@ async function itemsHaving(userId, projectId, having) {
|
|
|
380
406
|
}
|
|
381
407
|
/** What the studio shows around a page of Knowledge: where it stands, its sub-pages, its origin. */
|
|
382
408
|
export async function knowledgePage(page) {
|
|
383
|
-
const tree = await pageTree(page.
|
|
409
|
+
const tree = await pageTree(page.spaceId);
|
|
384
410
|
const node = tree.get(page.id);
|
|
385
411
|
const parents = [];
|
|
386
412
|
for (let at = node?.parentId ? tree.get(node.parentId) : undefined; at;) {
|
|
@@ -392,8 +418,8 @@ export async function knowledgePage(page) {
|
|
|
392
418
|
.sort((a, b) => a.position - b.position || a.title.localeCompare(b.title, "de"))
|
|
393
419
|
.map((n) => ({ id: n.id, title: n.title, path: n.path }));
|
|
394
420
|
const file = page.fileId
|
|
395
|
-
? await db.query.
|
|
396
|
-
where: eq(schema.
|
|
421
|
+
? await db.query.spaceFile.findFirst({
|
|
422
|
+
where: eq(schema.spaceFile.id, page.fileId),
|
|
397
423
|
columns: { id: true, name: true, mime: true },
|
|
398
424
|
})
|
|
399
425
|
: undefined;
|
|
@@ -448,24 +474,25 @@ function sectionOf(markdown, wanted) {
|
|
|
448
474
|
* original, its parent and sub-pages) and its Markdown, or one section of it. Long pages come in
|
|
449
475
|
* parts: `from` continues where the last part ended.
|
|
450
476
|
*/
|
|
451
|
-
export async function readPage(
|
|
452
|
-
const found = await resolvePath(
|
|
477
|
+
export async function readPage(spaceId, path, opts, who) {
|
|
478
|
+
const found = await resolvePath(spaceId, path);
|
|
453
479
|
if (found?.kind !== "page") {
|
|
454
|
-
throw new ServiceError("not_found", `No page "${path}".
|
|
480
|
+
throw new ServiceError("not_found", `No page "${path}". space_list or space_search name the pages there are.`);
|
|
455
481
|
}
|
|
456
482
|
const page = await db.query.spacePage.findFirst({ where: eq(schema.spacePage.id, found.id) });
|
|
457
483
|
if (!page) {
|
|
458
484
|
throw notFound();
|
|
459
485
|
}
|
|
460
|
-
|
|
486
|
+
await assertRwx(spaceId, who, { kind: "page", id: page.id, fileId: page.fileId }, "r");
|
|
487
|
+
const tree = await pageTree(spaceId);
|
|
461
488
|
const node = tree.get(page.id);
|
|
462
|
-
const categories = await categoryRows(
|
|
489
|
+
const categories = await categoryRows(spaceId);
|
|
463
490
|
const lines = categoryLines(categories, (await itemCategoriesOf([{ pageId: page.id }])).get(`p:${page.id}`));
|
|
464
491
|
const children = [...tree.values()]
|
|
465
492
|
.filter((n) => n.parentId === page.id)
|
|
466
493
|
.sort((a, b) => a.position - b.position)
|
|
467
494
|
.map((n) => n.path);
|
|
468
|
-
const original = page.fileId ? (await filePaths(
|
|
495
|
+
const original = page.fileId ? (await filePaths(spaceId)).get(page.fileId) : undefined;
|
|
469
496
|
const front = [
|
|
470
497
|
"---",
|
|
471
498
|
`title: ${yamlValue(page.title)}`,
|
|
@@ -480,7 +507,7 @@ export async function readPage(projectId, path, opts = {}) {
|
|
|
480
507
|
...(page.originLabel ? [`source: ${yamlValue(page.originLabel)}`] : []),
|
|
481
508
|
...(original ? [`original: ${original}`] : []),
|
|
482
509
|
...(children.length ? ["sub-pages:", ...children.slice(0, 200).map((c) => ` - ${c}`)] : []),
|
|
483
|
-
...(children.length > 200 ? [` # … ${children.length - 200} more, see
|
|
510
|
+
...(children.length > 200 ? [` # … ${children.length - 200} more, see space_list`] : []),
|
|
484
511
|
"---",
|
|
485
512
|
].join("\n");
|
|
486
513
|
let text = page.markdown;
|
|
@@ -538,15 +565,16 @@ const csvCell = (value) => /[",\n;]/.test(value) ? `"${value.replace(/"/g, '""')
|
|
|
538
565
|
* A table as a step reads it: its rows as CSV, filtered by its columns (by their names), a few
|
|
539
566
|
* hundred at a time.
|
|
540
567
|
*/
|
|
541
|
-
export async function readTable(
|
|
542
|
-
const found = await resolvePath(
|
|
568
|
+
export async function readTable(spaceId, path, opts, who) {
|
|
569
|
+
const found = await resolvePath(spaceId, path);
|
|
543
570
|
if (found?.kind !== "table") {
|
|
544
|
-
throw new ServiceError("not_found", `No table "${path}".
|
|
571
|
+
throw new ServiceError("not_found", `No table "${path}". space_list or space_search name the tables there are.`);
|
|
545
572
|
}
|
|
546
573
|
const table = await db.query.spaceTable.findFirst({ where: eq(schema.spaceTable.id, found.id) });
|
|
547
574
|
if (!table) {
|
|
548
575
|
throw notFound();
|
|
549
576
|
}
|
|
577
|
+
await assertRwx(spaceId, who, { kind: "table", id: table.id, fileId: table.fileId }, "r");
|
|
550
578
|
const byName = (name) => table.columns.find((c) => c.name.toLowerCase() === name.trim().toLowerCase() || c.id === name.trim());
|
|
551
579
|
const filters = Object.entries(opts.where ?? {}).map(([name, w]) => {
|
|
552
580
|
const column = byName(name);
|
|
@@ -587,11 +615,11 @@ export async function readTable(projectId, path, opts = {}) {
|
|
|
587
615
|
};
|
|
588
616
|
}
|
|
589
617
|
/**
|
|
590
|
-
* For
|
|
591
|
-
* has; with one, the items it leaves, with their paths and categories.
|
|
618
|
+
* For space_list: without a filter, the categories with their values and how many items each
|
|
619
|
+
* has; with one, the items it leaves that `who` may read, with their paths and categories.
|
|
592
620
|
*/
|
|
593
|
-
export async function listForStep(
|
|
594
|
-
const categories = await listCategories(
|
|
621
|
+
export async function listForStep(spaceId, where, who) {
|
|
622
|
+
const categories = await listCategories(spaceId);
|
|
595
623
|
const taken = categories.filter((c) => !c.proposed);
|
|
596
624
|
if (!Object.keys(where ?? {}).length) {
|
|
597
625
|
return {
|
|
@@ -608,16 +636,20 @@ export async function listForStep(projectId, where) {
|
|
|
608
636
|
hint: 'Pass `where` to list the items of values, e.g. { "Baustelle": "Graz Süd" }.',
|
|
609
637
|
};
|
|
610
638
|
}
|
|
611
|
-
const filtered = await filterItems(
|
|
639
|
+
const filtered = await filterItems(spaceId, where);
|
|
612
640
|
const [tree, tPaths, fPaths] = await Promise.all([
|
|
613
|
-
pageTree(
|
|
614
|
-
tablePaths(
|
|
615
|
-
filePaths(
|
|
641
|
+
pageTree(spaceId),
|
|
642
|
+
tablePaths(spaceId),
|
|
643
|
+
filePaths(spaceId),
|
|
616
644
|
]);
|
|
645
|
+
const okPages = await readable(spaceId, who, await pageResources([...(filtered?.pages ?? [])]));
|
|
646
|
+
const okFiles = await readable(spaceId, who, [...(filtered?.files ?? [])].map((id) => ({ kind: "document", id })));
|
|
647
|
+
const pages = [...(filtered?.pages ?? [])].filter((id) => okPages.has(id));
|
|
648
|
+
const files = [...(filtered?.files ?? [])].filter((id) => okFiles.has(id));
|
|
617
649
|
const refs = [
|
|
618
|
-
...
|
|
650
|
+
...pages.map((pageId) => ({ pageId })),
|
|
619
651
|
...[...(filtered?.tables ?? [])].map((tableId) => ({ tableId })),
|
|
620
|
-
...
|
|
652
|
+
...files.map((fileId) => ({ fileId })),
|
|
621
653
|
];
|
|
622
654
|
const cats = await itemCategoriesOf(refs);
|
|
623
655
|
// Rows whose table is not left as a whole: by their table, with how many.
|
|
@@ -633,8 +665,11 @@ export async function listForStep(projectId, where) {
|
|
|
633
665
|
}
|
|
634
666
|
}
|
|
635
667
|
}
|
|
668
|
+
// A table, and the rows of one, as its holder may read it.
|
|
669
|
+
const okTables = await readable(spaceId, who, await tableResources([...(filtered?.tables ?? []), ...rowTables.keys()]));
|
|
670
|
+
const tables = [...(filtered?.tables ?? [])].filter((id) => okTables.has(id));
|
|
636
671
|
const items = [
|
|
637
|
-
...
|
|
672
|
+
...pages
|
|
638
673
|
.map((id) => tree.get(id))
|
|
639
674
|
.filter((n) => Boolean(n))
|
|
640
675
|
.sort((a, b) => a.path.localeCompare(b.path))
|
|
@@ -643,17 +678,19 @@ export async function listForStep(projectId, where) {
|
|
|
643
678
|
title: n.title,
|
|
644
679
|
categories: categoryLines(taken, cats.get(`p:${n.id}`)),
|
|
645
680
|
})),
|
|
646
|
-
...
|
|
681
|
+
...tables.map((id) => ({
|
|
647
682
|
path: tPaths.get(id) ?? "",
|
|
648
683
|
title: "",
|
|
649
684
|
categories: categoryLines(taken, cats.get(`t:${id}`)),
|
|
650
685
|
})),
|
|
651
|
-
...[...rowTables]
|
|
686
|
+
...[...rowTables]
|
|
687
|
+
.filter(([id]) => okTables.has(id))
|
|
688
|
+
.map(([id, n]) => ({
|
|
652
689
|
path: tPaths.get(id) ?? "",
|
|
653
690
|
title: `${n} rows match: read them with table_read and the same values as its columns`,
|
|
654
691
|
categories: [],
|
|
655
692
|
})),
|
|
656
|
-
...
|
|
693
|
+
...files.map((id) => ({
|
|
657
694
|
path: fPaths.get(id) ?? "",
|
|
658
695
|
title: "",
|
|
659
696
|
categories: categoryLines(taken, cats.get(`f:${id}`)),
|
|
@@ -662,20 +699,20 @@ export async function listForStep(projectId, where) {
|
|
|
662
699
|
return { items: items.slice(0, 200), total: items.length };
|
|
663
700
|
}
|
|
664
701
|
/** How much Knowledge a space holds: what the block of the steps' instructions says. */
|
|
665
|
-
export async function knowledgeCounts(
|
|
702
|
+
export async function knowledgeCounts(spaceId) {
|
|
666
703
|
const [pages, tables, files] = await Promise.all([
|
|
667
704
|
db
|
|
668
705
|
.select({ n: count() })
|
|
669
706
|
.from(schema.spacePage)
|
|
670
|
-
.where(and(eq(schema.spacePage.
|
|
707
|
+
.where(and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId))),
|
|
671
708
|
db
|
|
672
709
|
.select({ n: count() })
|
|
673
710
|
.from(schema.spaceTable)
|
|
674
|
-
.where(and(eq(schema.spaceTable.
|
|
711
|
+
.where(and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId))),
|
|
675
712
|
db
|
|
676
713
|
.select({ n: count() })
|
|
677
|
-
.from(schema.
|
|
678
|
-
.where(and(eq(schema.
|
|
714
|
+
.from(schema.spaceFile)
|
|
715
|
+
.where(and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.kind, "document"))),
|
|
679
716
|
]);
|
|
680
717
|
return { pages: pages[0].n, tables: tables[0].n, files: files[0].n };
|
|
681
718
|
}
|
|
@@ -683,12 +720,12 @@ export async function knowledgeCounts(projectId) {
|
|
|
683
720
|
* What every step of the space is told about Knowledge: how much there is, the categories to filter
|
|
684
721
|
* by, the tools to find and read. Empty when Knowledge is.
|
|
685
722
|
*/
|
|
686
|
-
export async function knowledgeBlock(
|
|
687
|
-
const counts = await knowledgeCounts(
|
|
723
|
+
export async function knowledgeBlock(spaceId) {
|
|
724
|
+
const counts = await knowledgeCounts(spaceId);
|
|
688
725
|
if (!(counts.pages || counts.tables || counts.files)) {
|
|
689
726
|
return "";
|
|
690
727
|
}
|
|
691
|
-
const categories = (await listCategories(
|
|
728
|
+
const categories = (await listCategories(spaceId)).filter((c) => !c.proposed && c.count);
|
|
692
729
|
const what = [
|
|
693
730
|
counts.pages ? `${counts.pages} pages` : "",
|
|
694
731
|
counts.tables ? `${counts.tables} tables` : "",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { capabilitiesOf, effortOf } from "@engenty/wizards-shared/marketplace";
|
|
2
2
|
import { resultsOf } from "@engenty/wizards-shared/marketplace-entry";
|
|
3
3
|
import { and, eq, inArray } from "drizzle-orm";
|
|
4
|
+
import { onCritical } from "../broker/index.js";
|
|
4
5
|
import { db, knownTenants, schema, withTenant } from "../db/client.js";
|
|
5
6
|
import { env } from "../env.js";
|
|
6
|
-
import { managed, postRunReport, putWizards } from "../manage.js";
|
|
7
|
+
import { managed, postBrokerReport, postRunReport, putWizards } from "../manage.js";
|
|
7
8
|
import { currentTenant } from "../tenants/tenant.js";
|
|
8
9
|
import { pageLangOf, pageSteps } from "./pages.js";
|
|
9
10
|
/**
|
|
@@ -15,12 +16,12 @@ let last = Promise.resolve();
|
|
|
15
16
|
/** The team's wizards as the admin app lists them: the published version where there is one. */
|
|
16
17
|
export async function wizardsReport() {
|
|
17
18
|
const tenantId = currentTenant();
|
|
18
|
-
const [wizards,
|
|
19
|
+
const [wizards, spaceRows] = await Promise.all([
|
|
19
20
|
db.select().from(schema.wizard).where(eq(schema.wizard.tenantId, tenantId)),
|
|
20
21
|
db
|
|
21
|
-
.select({ id: schema.
|
|
22
|
-
.from(schema.
|
|
23
|
-
.where(eq(schema.
|
|
22
|
+
.select({ id: schema.space.id, name: schema.space.name })
|
|
23
|
+
.from(schema.space)
|
|
24
|
+
.where(eq(schema.space.tenantId, tenantId)),
|
|
24
25
|
]);
|
|
25
26
|
const published = wizards.filter((w) => w.publishedVersion !== null);
|
|
26
27
|
const versions = published.length
|
|
@@ -34,7 +35,7 @@ export async function wizardsReport() {
|
|
|
34
35
|
.from(schema.wizardVersion)
|
|
35
36
|
.where(inArray(schema.wizardVersion.wizardId, published.map((w) => w.id)))
|
|
36
37
|
: [];
|
|
37
|
-
const spaces = new Map(
|
|
38
|
+
const spaces = new Map(spaceRows.map((p) => [p.id, p.name]));
|
|
38
39
|
return {
|
|
39
40
|
wizards: wizards.map((w) => {
|
|
40
41
|
const live = versions.find((v) => v.wizardId === w.id && v.version === w.publishedVersion);
|
|
@@ -45,7 +46,7 @@ export async function wizardsReport() {
|
|
|
45
46
|
description: (def.description ?? "").slice(0, 1000),
|
|
46
47
|
avatar: def.avatar ?? "round",
|
|
47
48
|
lang: (def.lang ?? "de").slice(0, 5),
|
|
48
|
-
space: spaces.has(w.
|
|
49
|
+
space: spaces.has(w.spaceId) ? { id: w.spaceId, name: spaces.get(w.spaceId) } : null,
|
|
49
50
|
published: Boolean(live),
|
|
50
51
|
publishedAt: live?.createdAt.toISOString() ?? null,
|
|
51
52
|
template: w.starter ? { id: w.starter, revision: w.starterRevision ?? null } : null,
|
|
@@ -191,3 +192,69 @@ export function reportRun(runId, status) {
|
|
|
191
192
|
console.warn(`[reports] run ${runId}:`, err.message);
|
|
192
193
|
});
|
|
193
194
|
}
|
|
195
|
+
// --- the broker's critical lines ---------------------------------------------------------------
|
|
196
|
+
/** How often the lines that are not a guest's go out. */
|
|
197
|
+
const DAILY_MS = 24 * 3600_000;
|
|
198
|
+
/** How many lines one report carries at most. */
|
|
199
|
+
const REPORT_LINES = 200;
|
|
200
|
+
/** A line as the admin app takes it: who, where, what, the outcome; never the input. */
|
|
201
|
+
export function criticalLine(row) {
|
|
202
|
+
return {
|
|
203
|
+
id: row.id,
|
|
204
|
+
at: row.at.toISOString(),
|
|
205
|
+
kind: row.criticalKind,
|
|
206
|
+
who: { kind: row.whoKind, id: row.whoId },
|
|
207
|
+
where: { runId: row.runId, chatId: row.chatId, wizardId: row.wizardId, spaceId: row.spaceId },
|
|
208
|
+
connection: row.connectionId,
|
|
209
|
+
action: row.actionId,
|
|
210
|
+
actionKind: row.kind,
|
|
211
|
+
outcome: row.outcome,
|
|
212
|
+
rule: row.rule,
|
|
213
|
+
result: row.result,
|
|
214
|
+
reason: (row.reason ?? "").slice(0, 500),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const kept = new Map();
|
|
218
|
+
function post(tenantId, rows, batch) {
|
|
219
|
+
if (!rows.length) {
|
|
220
|
+
return Promise.resolve();
|
|
221
|
+
}
|
|
222
|
+
return postBrokerReport(tenantId, { batch, lines: rows.map(criticalLine) }).then(() => undefined, (err) => console.warn(`[reports] broker ${tenantId}:`, err.message));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Hears every critical row (broker/log.ts): a guest's goes to the admin app at once – someone at a
|
|
226
|
+
* wizard's link reached for what the rules keep from them; the rest wait for the daily report.
|
|
227
|
+
*/
|
|
228
|
+
export function reportCritical(row) {
|
|
229
|
+
if (!managed) {
|
|
230
|
+
return Promise.resolve();
|
|
231
|
+
}
|
|
232
|
+
const tenantId = currentTenant();
|
|
233
|
+
if (row.whoKind === "guest") {
|
|
234
|
+
return post(tenantId, [row], "at_once");
|
|
235
|
+
}
|
|
236
|
+
const rows = kept.get(tenantId) ?? [];
|
|
237
|
+
rows.push(row);
|
|
238
|
+
kept.set(tenantId, rows.slice(-REPORT_LINES));
|
|
239
|
+
return Promise.resolve();
|
|
240
|
+
}
|
|
241
|
+
/** The daily report: what was kept for each tenant, one tenant after the other. */
|
|
242
|
+
export async function reportCriticalDaily() {
|
|
243
|
+
for (const [tenantId, rows] of [...kept]) {
|
|
244
|
+
kept.delete(tenantId);
|
|
245
|
+
await post(tenantId, rows, "daily");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** Starts hearing the broker and the daily report; the handle stops both. */
|
|
249
|
+
export function startCriticalReports() {
|
|
250
|
+
if (!managed) {
|
|
251
|
+
return () => undefined;
|
|
252
|
+
}
|
|
253
|
+
const off = onCritical((row) => void reportCritical(row));
|
|
254
|
+
const timer = setInterval(() => void reportCriticalDaily(), DAILY_MS);
|
|
255
|
+
timer.unref?.();
|
|
256
|
+
return () => {
|
|
257
|
+
off();
|
|
258
|
+
clearInterval(timer);
|
|
259
|
+
};
|
|
260
|
+
}
|