@agent-native/core 0.101.14 → 0.102.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/corpus/README.md +1 -1
- package/corpus/core/CHANGELOG.md +12 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/cli/templates-meta.ts +13 -0
- package/corpus/core/src/client/agent-page/AgentTabsPage.tsx +1 -1
- package/corpus/core/src/client/org/OrgSwitcher.tsx +2 -0
- package/corpus/templates/analytics/changelog/2026-07-15-fixed-the-agent-discarding-a-successful-dashboard-edit-and-r.md +6 -0
- package/corpus/templates/analytics/server/lib/real-data-actions.ts +30 -1
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +15 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +59 -4
- package/corpus/templates/content/actions/prepare-builder-source-review.ts +9 -0
- package/corpus/templates/content/actions/preview-builder-source-review.ts +6 -4
- package/corpus/templates/content/app/components/editor/DescriptionField.tsx +10 -2
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +4 -0
- package/corpus/templates/content/changelog/2026-07-15-page-and-database-descriptions-now-use-a-clean-single-line-f.md +6 -0
- package/corpus/templates/content/changelog/2026-07-15-selected-builder-reviews-now-load-only-the-chosen-rows-avoid.md +6 -0
- package/corpus/templates/content/shared/api.ts +1 -0
- package/corpus/templates/tasks/.agents/commands/visual-plan.md +9 -0
- package/corpus/templates/tasks/.agents/commands/visual-recap.md +8 -0
- package/corpus/templates/tasks/.agents/skills/actions/SKILL.md +492 -0
- package/corpus/templates/tasks/.agents/skills/adding-a-feature/SKILL.md +189 -0
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +76 -0
- package/corpus/templates/tasks/.agents/skills/agent-watchdog/README.md +43 -0
- package/corpus/templates/tasks/.agents/skills/agent-watchdog/SKILL.md +110 -0
- package/corpus/templates/tasks/.agents/skills/agent-watchdog/agents/openai.yaml +4 -0
- package/corpus/templates/tasks/.agents/skills/capture-learnings/SKILL.md +89 -0
- package/corpus/templates/tasks/.agents/skills/change-summary/SKILL.md +83 -0
- package/corpus/templates/tasks/.agents/skills/create-skill/SKILL.md +221 -0
- package/corpus/templates/tasks/.agents/skills/delegate-to-agent/SKILL.md +263 -0
- package/corpus/templates/tasks/.agents/skills/efficient-fable/README.md +75 -0
- package/corpus/templates/tasks/.agents/skills/efficient-fable/SKILL.md +95 -0
- package/corpus/templates/tasks/.agents/skills/efficient-frontier/README.md +53 -0
- package/corpus/templates/tasks/.agents/skills/efficient-frontier/SKILL.md +73 -0
- package/corpus/templates/tasks/.agents/skills/frontend-design/SKILL.md +112 -0
- package/corpus/templates/tasks/.agents/skills/plan-arbiter/README.md +41 -0
- package/corpus/templates/tasks/.agents/skills/plan-arbiter/SKILL.md +114 -0
- package/corpus/templates/tasks/.agents/skills/plan-arbiter/agents/openai.yaml +4 -0
- package/corpus/templates/tasks/.agents/skills/plow-ahead/README.md +42 -0
- package/corpus/templates/tasks/.agents/skills/plow-ahead/SKILL.md +104 -0
- package/corpus/templates/tasks/.agents/skills/plow-ahead/agents/openai.yaml +4 -0
- package/corpus/templates/tasks/.agents/skills/quick-recap/README.md +55 -0
- package/corpus/templates/tasks/.agents/skills/quick-recap/SKILL.md +54 -0
- package/corpus/templates/tasks/.agents/skills/read-the-damn-docs/README.md +54 -0
- package/corpus/templates/tasks/.agents/skills/read-the-damn-docs/SKILL.md +126 -0
- package/corpus/templates/tasks/.agents/skills/read-the-damn-docs/agents/openai.yaml +4 -0
- package/corpus/templates/tasks/.agents/skills/real-time-sync/SKILL.md +232 -0
- package/corpus/templates/tasks/.agents/skills/security/SKILL.md +280 -0
- package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +106 -0
- package/corpus/templates/tasks/.agents/skills/shadcn-ui/SKILL.md +95 -0
- package/corpus/templates/tasks/.agents/skills/stay-within-limits/README.md +61 -0
- package/corpus/templates/tasks/.agents/skills/stay-within-limits/SKILL.md +83 -0
- package/corpus/templates/tasks/.agents/skills/upgrade-agent-native/SKILL.md +87 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/SKILL.md +547 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/agent-native-skill.json +12 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/references/canvas.md +121 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/references/document-quality.md +178 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/references/exemplar.md +62 -0
- package/corpus/templates/tasks/.agents/skills/visual-plan/references/wireframe.md +264 -0
- package/corpus/templates/tasks/.agents/skills/visual-recap/SKILL.md +634 -0
- package/corpus/templates/tasks/.agents/skills/visual-recap/agent-native-skill.json +12 -0
- package/corpus/templates/tasks/.agents/skills/visual-recap/references/wireframe.md +264 -0
- package/corpus/templates/tasks/.claude/commands/visual-plan.md +9 -0
- package/corpus/templates/tasks/.claude/commands/visual-recap.md +8 -0
- package/corpus/templates/tasks/.env.example +5 -0
- package/corpus/templates/tasks/.ignore +0 -0
- package/corpus/templates/tasks/.prettierrc +5 -0
- package/corpus/templates/tasks/AGENTS.md +158 -0
- package/corpus/templates/tasks/DEVELOPING.md +185 -0
- package/corpus/templates/tasks/README.md +16 -0
- package/corpus/templates/tasks/actions/bulk-delete-inbox-items.ts +24 -0
- package/corpus/templates/tasks/actions/bulk-delete-tasks.ts +21 -0
- package/corpus/templates/tasks/actions/bulk-mark-inbox-items-ready.ts +27 -0
- package/corpus/templates/tasks/actions/bulk-update-tasks.ts +35 -0
- package/corpus/templates/tasks/actions/create-custom-field.ts +22 -0
- package/corpus/templates/tasks/actions/create-inbox-item.ts +30 -0
- package/corpus/templates/tasks/actions/create-task.ts +33 -0
- package/corpus/templates/tasks/actions/delete-custom-field.ts +19 -0
- package/corpus/templates/tasks/actions/delete-inbox-item.ts +17 -0
- package/corpus/templates/tasks/actions/delete-task.ts +17 -0
- package/corpus/templates/tasks/actions/lib/boolean-query-param.ts +30 -0
- package/corpus/templates/tasks/actions/list-custom-fields.ts +18 -0
- package/corpus/templates/tasks/actions/list-inbox-items.ts +16 -0
- package/corpus/templates/tasks/actions/list-tasks.ts +52 -0
- package/corpus/templates/tasks/actions/list-visible-task-fields.ts +18 -0
- package/corpus/templates/tasks/actions/mark-inbox-item-ready.ts +31 -0
- package/corpus/templates/tasks/actions/navigate.ts +51 -0
- package/corpus/templates/tasks/actions/reorder-custom-fields.ts +27 -0
- package/corpus/templates/tasks/actions/reorder-inbox-items.ts +24 -0
- package/corpus/templates/tasks/actions/reorder-tasks.ts +29 -0
- package/corpus/templates/tasks/actions/run.ts +2 -0
- package/corpus/templates/tasks/actions/update-custom-field.ts +33 -0
- package/corpus/templates/tasks/actions/update-inbox-item.ts +24 -0
- package/corpus/templates/tasks/actions/update-task.ts +68 -0
- package/corpus/templates/tasks/actions/update-visible-task-fields.ts +27 -0
- package/corpus/templates/tasks/actions/view-screen-helpers.ts +68 -0
- package/corpus/templates/tasks/actions/view-screen.ts +207 -0
- package/corpus/templates/tasks/app/components/custom-fields/FieldCreateBar.tsx +121 -0
- package/corpus/templates/tasks/app/components/custom-fields/FieldListRow.tsx +116 -0
- package/corpus/templates/tasks/app/components/custom-fields/FieldsList.tsx +225 -0
- package/corpus/templates/tasks/app/components/custom-fields/FieldsListSkeleton.tsx +18 -0
- package/corpus/templates/tasks/app/components/custom-fields/FieldsPage.tsx +42 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/FieldEditorSidebar.tsx +69 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/FieldTitleSection.tsx +32 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/CurrencyConfigControl.tsx +49 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/FieldConfigControl.tsx +56 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/NumberConfigControl.tsx +52 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/PercentConfigControl.tsx +30 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/SelectConfigControl.tsx +135 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/select-colors.ts +23 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/config/utils.ts +52 -0
- package/corpus/templates/tasks/app/components/custom-fields/editor/types.ts +7 -0
- package/corpus/templates/tasks/app/components/dnd/SortableItem.tsx +72 -0
- package/corpus/templates/tasks/app/components/dnd/SortableList.tsx +136 -0
- package/corpus/templates/tasks/app/components/dnd/reorder-moving-items.ts +160 -0
- package/corpus/templates/tasks/app/components/dnd/sortable-drag-props.ts +60 -0
- package/corpus/templates/tasks/app/components/inbox/InboxList.tsx +222 -0
- package/corpus/templates/tasks/app/components/inbox/InboxListPage.tsx +39 -0
- package/corpus/templates/tasks/app/components/inbox/InboxListRow.tsx +122 -0
- package/corpus/templates/tasks/app/components/layout/Header.tsx +55 -0
- package/corpus/templates/tasks/app/components/layout/HeaderActions.tsx +84 -0
- package/corpus/templates/tasks/app/components/layout/Layout.tsx +134 -0
- package/corpus/templates/tasks/app/components/layout/Sidebar.tsx +211 -0
- package/corpus/templates/tasks/app/components/shared/AddListItemInput.tsx +57 -0
- package/corpus/templates/tasks/app/components/shared/AlertDialog.tsx +53 -0
- package/corpus/templates/tasks/app/components/shared/BulkDeleteDialog.tsx +76 -0
- package/corpus/templates/tasks/app/components/shared/ChipSelect.tsx +240 -0
- package/corpus/templates/tasks/app/components/shared/DeleteItemDialog.tsx +40 -0
- package/corpus/templates/tasks/app/components/shared/InlineEditable.tsx +166 -0
- package/corpus/templates/tasks/app/components/shared/ListEmptyState.tsx +13 -0
- package/corpus/templates/tasks/app/components/shared/ListErrorMessage.tsx +15 -0
- package/corpus/templates/tasks/app/components/shared/ListViewHeader.tsx +75 -0
- package/corpus/templates/tasks/app/components/shared/PageHeader.tsx +25 -0
- package/corpus/templates/tasks/app/components/shared/RowActionsMenu.tsx +42 -0
- package/corpus/templates/tasks/app/components/shared/SidePanel.tsx +99 -0
- package/corpus/templates/tasks/app/components/shared/dnd/ListRowPreview.tsx +37 -0
- package/corpus/templates/tasks/app/components/shared/list/List.tsx +63 -0
- package/corpus/templates/tasks/app/components/shared/list/ListRow.tsx +159 -0
- package/corpus/templates/tasks/app/components/shared/list/ListRowDragHandle.tsx +52 -0
- package/corpus/templates/tasks/app/components/shared/list/ListSkeletonRows.tsx +11 -0
- package/corpus/templates/tasks/app/components/shared/list/SortableListItemShell.tsx +32 -0
- package/corpus/templates/tasks/app/components/shared/list/types.ts +1 -0
- package/corpus/templates/tasks/app/components/shared/selection/ListSelectionBar.tsx +158 -0
- package/corpus/templates/tasks/app/components/shared/selection/ListSelectionHeaderToggle.tsx +28 -0
- package/corpus/templates/tasks/app/components/shared/selection/ListSelectionToolbar.tsx +81 -0
- package/corpus/templates/tasks/app/components/shared/selection/get-list-row-selection-ui.ts +41 -0
- package/corpus/templates/tasks/app/components/shared/selection/use-list-selection.ts +196 -0
- package/corpus/templates/tasks/app/components/tasks/TaskList.tsx +333 -0
- package/corpus/templates/tasks/app/components/tasks/TaskListHeaderRow.tsx +46 -0
- package/corpus/templates/tasks/app/components/tasks/TaskListPage.tsx +115 -0
- package/corpus/templates/tasks/app/components/tasks/TaskListRow.css +49 -0
- package/corpus/templates/tasks/app/components/tasks/TaskListRow.tsx +307 -0
- package/corpus/templates/tasks/app/components/tasks/fields/TaskFieldsSidebar.tsx +102 -0
- package/corpus/templates/tasks/app/components/tasks/fields/TaskTitleSection.tsx +27 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/DateValueControl.tsx +21 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/FieldValueControl.tsx +76 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/MultiSelectValueControl.tsx +52 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/NumberValueControl.tsx +56 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/RichTextValueControl.tsx +115 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/SingleSelectValueControl.tsx +61 -0
- package/corpus/templates/tasks/app/components/tasks/fields/controls/TextValueControl.tsx +20 -0
- package/corpus/templates/tasks/app/components/tasks/use-task-row-completion-animation.ts +181 -0
- package/corpus/templates/tasks/app/components/ui/accordion.tsx +56 -0
- package/corpus/templates/tasks/app/components/ui/alert-dialog.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/alert.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/aspect-ratio.tsx +5 -0
- package/corpus/templates/tasks/app/components/ui/avatar.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/badge.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/breadcrumb.tsx +115 -0
- package/corpus/templates/tasks/app/components/ui/button.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/calendar.tsx +70 -0
- package/corpus/templates/tasks/app/components/ui/card.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/carousel.tsx +260 -0
- package/corpus/templates/tasks/app/components/ui/chart.tsx +379 -0
- package/corpus/templates/tasks/app/components/ui/checkbox.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/collapsible.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/command.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/context-menu.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/dialog.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/drawer.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/dropdown-menu.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/form.tsx +177 -0
- package/corpus/templates/tasks/app/components/ui/hover-card.tsx +27 -0
- package/corpus/templates/tasks/app/components/ui/input-otp.tsx +69 -0
- package/corpus/templates/tasks/app/components/ui/input.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/label.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/menubar.tsx +254 -0
- package/corpus/templates/tasks/app/components/ui/navigation-menu.tsx +128 -0
- package/corpus/templates/tasks/app/components/ui/pagination.tsx +121 -0
- package/corpus/templates/tasks/app/components/ui/popover.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/progress.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/radio-group.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/resizable.tsx +43 -0
- package/corpus/templates/tasks/app/components/ui/scroll-area.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/select.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/separator.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/sheet.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/sidebar.tsx +782 -0
- package/corpus/templates/tasks/app/components/ui/skeleton.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/slider.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/sonner.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/spinner.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/switch.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/table.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/tabs.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/textarea.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/toast.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/toaster.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/toggle-group.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/toggle.tsx +43 -0
- package/corpus/templates/tasks/app/components/ui/tooltip.tsx +1 -0
- package/corpus/templates/tasks/app/components/ui/use-toast.ts +3 -0
- package/corpus/templates/tasks/app/entry.client.tsx +19 -0
- package/corpus/templates/tasks/app/entry.server.tsx +10 -0
- package/corpus/templates/tasks/app/global.css +93 -0
- package/corpus/templates/tasks/app/hooks/cache.ts +31 -0
- package/corpus/templates/tasks/app/hooks/use-custom-fields.ts +93 -0
- package/corpus/templates/tasks/app/hooks/use-inbox-items.ts +196 -0
- package/corpus/templates/tasks/app/hooks/use-mobile.tsx +21 -0
- package/corpus/templates/tasks/app/hooks/use-navigation-state.ts +40 -0
- package/corpus/templates/tasks/app/hooks/use-tasks.ts +276 -0
- package/corpus/templates/tasks/app/hooks/use-toast.ts +188 -0
- package/corpus/templates/tasks/app/hooks/use-visible-task-fields.ts +140 -0
- package/corpus/templates/tasks/app/lib/app-config.ts +11 -0
- package/corpus/templates/tasks/app/lib/tab-id.ts +1 -0
- package/corpus/templates/tasks/app/lib/utils.ts +1 -0
- package/corpus/templates/tasks/app/root.tsx +130 -0
- package/corpus/templates/tasks/app/routes/_index.tsx +22 -0
- package/corpus/templates/tasks/app/routes/extensions.$id.$slug.tsx +2 -0
- package/corpus/templates/tasks/app/routes/extensions.$id.tsx +11 -0
- package/corpus/templates/tasks/app/routes/extensions._index.tsx +11 -0
- package/corpus/templates/tasks/app/routes/extensions.tsx +5 -0
- package/corpus/templates/tasks/app/routes/fields.tsx +16 -0
- package/corpus/templates/tasks/app/routes/inbox.tsx +16 -0
- package/corpus/templates/tasks/app/routes/tasks.tsx +17 -0
- package/corpus/templates/tasks/app/routes/team.tsx +17 -0
- package/corpus/templates/tasks/app/routes.ts +4 -0
- package/corpus/templates/tasks/app/vite-env.d.ts +6 -0
- package/corpus/templates/tasks/components.json +20 -0
- package/corpus/templates/tasks/data/sync-config.json +1 -0
- package/corpus/templates/tasks/docs/features/README.md +81 -0
- package/corpus/templates/tasks/docs/features/f1-tasks.mdx +67 -0
- package/corpus/templates/tasks/docs/features/f2-custom-fields.mdx +68 -0
- package/corpus/templates/tasks/docs/features/f3-projects.mdx +33 -0
- package/corpus/templates/tasks/docs/features/f4-inbox.mdx +55 -0
- package/corpus/templates/tasks/docs/features/f5-views.mdx +65 -0
- package/corpus/templates/tasks/docs/features/f6-search.mdx +43 -0
- package/corpus/templates/tasks/docs/features/f7-first-run.mdx +66 -0
- package/corpus/templates/tasks/docs/features/f8-chat.mdx +120 -0
- package/corpus/templates/tasks/e2e/global-setup.ts +42 -0
- package/corpus/templates/tasks/e2e/helpers/inbox.ts +71 -0
- package/corpus/templates/tasks/e2e/helpers/tasks.ts +99 -0
- package/corpus/templates/tasks/learnings.defaults.md +5 -0
- package/corpus/templates/tasks/netlify.toml +10 -0
- package/corpus/templates/tasks/package.json +104 -0
- package/corpus/templates/tasks/playwright.config.ts +34 -0
- package/corpus/templates/tasks/public/agent-native-icon-dark.svg +10 -0
- package/corpus/templates/tasks/public/agent-native-icon-light.svg +10 -0
- package/corpus/templates/tasks/public/agent-native-logo-dark.svg +21 -0
- package/corpus/templates/tasks/public/agent-native-logo-light.svg +21 -0
- package/corpus/templates/tasks/public/favicon.svg +1 -0
- package/corpus/templates/tasks/public/icon-180.svg +1 -0
- package/corpus/templates/tasks/public/icon-192.svg +1 -0
- package/corpus/templates/tasks/public/icon-512.svg +1 -0
- package/corpus/templates/tasks/public/manifest.json +21 -0
- package/corpus/templates/tasks/react-router.config.ts +7 -0
- package/corpus/templates/tasks/server/custom-fields/normalize.ts +163 -0
- package/corpus/templates/tasks/server/custom-fields/parse.ts +146 -0
- package/corpus/templates/tasks/server/custom-fields/schema.ts +147 -0
- package/corpus/templates/tasks/server/custom-fields/store.ts +425 -0
- package/corpus/templates/tasks/server/custom-fields/task-fields.ts +104 -0
- package/corpus/templates/tasks/server/custom-fields/types.ts +98 -0
- package/corpus/templates/tasks/server/custom-fields/validate.ts +210 -0
- package/corpus/templates/tasks/server/custom-fields/values/store.ts +386 -0
- package/corpus/templates/tasks/server/db/bulk-write.ts +30 -0
- package/corpus/templates/tasks/server/db/index.ts +5 -0
- package/corpus/templates/tasks/server/db/record-utils.ts +7 -0
- package/corpus/templates/tasks/server/db/schema.ts +67 -0
- package/corpus/templates/tasks/server/db/test-tasks-table.ts +76 -0
- package/corpus/templates/tasks/server/db/transaction.ts +6 -0
- package/corpus/templates/tasks/server/errors.ts +31 -0
- package/corpus/templates/tasks/server/inbox/store.ts +216 -0
- package/corpus/templates/tasks/server/middleware/auth.ts +15 -0
- package/corpus/templates/tasks/server/plugins/agent-chat.ts +46 -0
- package/corpus/templates/tasks/server/plugins/auth.ts +15 -0
- package/corpus/templates/tasks/server/plugins/db.ts +90 -0
- package/corpus/templates/tasks/server/routes/[...page].get.ts +5 -0
- package/corpus/templates/tasks/server/stored-items/store.ts +548 -0
- package/corpus/templates/tasks/server/tasks/store.ts +306 -0
- package/corpus/templates/tasks/server/user-config/store.ts +138 -0
- package/corpus/templates/tasks/shared/app-state-tabs.ts +15 -0
- package/corpus/templates/tasks/shared/boolean-param.ts +22 -0
- package/corpus/templates/tasks/shared/bulk-limits.ts +7 -0
- package/corpus/templates/tasks/shared/list-screen-snapshot.ts +90 -0
- package/corpus/templates/tasks/shared/navigation.ts +104 -0
- package/corpus/templates/tasks/shared/visible-task-fields.ts +2 -0
- package/corpus/templates/tasks/ssr-entry.ts +15 -0
- package/corpus/templates/tasks/tsconfig.json +24 -0
- package/corpus/templates/tasks/vite.config.ts +19 -0
- package/corpus/templates/tasks/vitest.config.ts +8 -0
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +13 -0
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/client/agent-page/AgentTabsPage.js +1 -1
- package/dist/client/agent-page/AgentTabsPage.js.map +1 -1
- package/dist/client/org/OrgSwitcher.d.ts.map +1 -1
- package/dist/client/org/OrgSwitcher.js +2 -1
- package/dist/client/org/OrgSwitcher.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +5 -5
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { and, asc, eq, inArray, max } from "drizzle-orm";
|
|
2
|
+
|
|
3
|
+
import { caseById, chunk } from "../db/bulk-write.js";
|
|
4
|
+
import { getDb } from "../db/index.js";
|
|
5
|
+
import { createRecordId, timestamp } from "../db/record-utils.js";
|
|
6
|
+
import { customFields } from "../db/schema.js";
|
|
7
|
+
import type { DbHandle } from "../db/transaction.js";
|
|
8
|
+
import { NotFoundError, UserInputError } from "../errors.js";
|
|
9
|
+
import { requireUserEmail } from "../stored-items/store.js";
|
|
10
|
+
import { removeTaskCardFieldId } from "../user-config/store.js";
|
|
11
|
+
import {
|
|
12
|
+
canonicalizeFieldConfig,
|
|
13
|
+
isEmptyFieldValue,
|
|
14
|
+
normalizeFieldConfigInput,
|
|
15
|
+
normalizeFieldTitle,
|
|
16
|
+
} from "./normalize.js";
|
|
17
|
+
import {
|
|
18
|
+
parseFieldType,
|
|
19
|
+
parseFieldConfigShape,
|
|
20
|
+
parseField,
|
|
21
|
+
parseFieldValueShape,
|
|
22
|
+
} from "./parse.js";
|
|
23
|
+
import type {
|
|
24
|
+
FieldConfigInput,
|
|
25
|
+
FieldDefinition,
|
|
26
|
+
FieldType,
|
|
27
|
+
FieldValue,
|
|
28
|
+
} from "./types.js";
|
|
29
|
+
import { validateFieldConfig, validateFieldTitle } from "./validate.js";
|
|
30
|
+
import {
|
|
31
|
+
deleteCustomFieldValues,
|
|
32
|
+
deleteCustomFieldValuesByFieldIds,
|
|
33
|
+
listCustomFieldValues,
|
|
34
|
+
updateCustomFieldValues,
|
|
35
|
+
} from "./values/store.js";
|
|
36
|
+
|
|
37
|
+
export { requireUserEmail };
|
|
38
|
+
export type {
|
|
39
|
+
FieldConfig,
|
|
40
|
+
FieldDefinition,
|
|
41
|
+
FieldType,
|
|
42
|
+
FieldValue,
|
|
43
|
+
FieldValueInput,
|
|
44
|
+
SelectColorToken,
|
|
45
|
+
SelectOption,
|
|
46
|
+
} from "./types.js";
|
|
47
|
+
export type {
|
|
48
|
+
CurrencyConfigInput,
|
|
49
|
+
EmptyConfigInput,
|
|
50
|
+
FieldConfigInput,
|
|
51
|
+
NumericConfigInput,
|
|
52
|
+
PercentConfigInput,
|
|
53
|
+
SelectConfigInput,
|
|
54
|
+
SelectOptionInput,
|
|
55
|
+
} from "./types.js";
|
|
56
|
+
export { FIELD_TYPES, SELECT_COLOR_TOKENS } from "./types.js";
|
|
57
|
+
export {
|
|
58
|
+
createCustomFieldActionSchema,
|
|
59
|
+
fieldConfigShapeSchema,
|
|
60
|
+
fieldValueInputSchema,
|
|
61
|
+
updateCustomFieldConfigActionSchema,
|
|
62
|
+
} from "./schema.js";
|
|
63
|
+
|
|
64
|
+
const SORT_GAP = 1000;
|
|
65
|
+
|
|
66
|
+
export async function createCustomField(
|
|
67
|
+
input: {
|
|
68
|
+
ownerEmail: string;
|
|
69
|
+
title: string;
|
|
70
|
+
type: FieldType;
|
|
71
|
+
config?: unknown;
|
|
72
|
+
now?: string;
|
|
73
|
+
},
|
|
74
|
+
db: DbHandle = getDb(),
|
|
75
|
+
): Promise<FieldDefinition> {
|
|
76
|
+
const createdAt = timestamp(input.now);
|
|
77
|
+
const type = parseFieldType(input.type);
|
|
78
|
+
validateFieldTitle(input.title);
|
|
79
|
+
const field = {
|
|
80
|
+
id: createRecordId("fld"),
|
|
81
|
+
title: normalizeFieldTitle(input.title),
|
|
82
|
+
type,
|
|
83
|
+
configJson: serializeFieldConfig(type, input.config),
|
|
84
|
+
sortOrder: await nextSortOrder(input.ownerEmail),
|
|
85
|
+
ownerEmail: input.ownerEmail,
|
|
86
|
+
createdAt,
|
|
87
|
+
updatedAt: createdAt,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
await db.insert(customFields).values(field);
|
|
91
|
+
const created = await getCustomField({
|
|
92
|
+
ownerEmail: input.ownerEmail,
|
|
93
|
+
fieldId: field.id,
|
|
94
|
+
});
|
|
95
|
+
if (!created) throw new Error("Failed to create custom field.");
|
|
96
|
+
return created;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function getCustomField(
|
|
100
|
+
input: {
|
|
101
|
+
ownerEmail: string;
|
|
102
|
+
fieldId: string;
|
|
103
|
+
},
|
|
104
|
+
db: DbHandle = getDb(),
|
|
105
|
+
): Promise<FieldDefinition | null> {
|
|
106
|
+
const [row] = await db
|
|
107
|
+
.select()
|
|
108
|
+
.from(customFields)
|
|
109
|
+
.where(
|
|
110
|
+
and(
|
|
111
|
+
eq(customFields.ownerEmail, input.ownerEmail),
|
|
112
|
+
eq(customFields.id, input.fieldId),
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
.limit(1);
|
|
116
|
+
return row ? parseField(row) : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function listCustomFields(
|
|
120
|
+
input: {
|
|
121
|
+
ownerEmail: string;
|
|
122
|
+
fieldIds?: string[];
|
|
123
|
+
},
|
|
124
|
+
db: DbHandle = getDb(),
|
|
125
|
+
): Promise<{ fields: FieldDefinition[] }> {
|
|
126
|
+
const fieldIds = input.fieldIds ? [...new Set(input.fieldIds)] : undefined;
|
|
127
|
+
if (fieldIds?.length === 0) return { fields: [] };
|
|
128
|
+
|
|
129
|
+
const conditions = [eq(customFields.ownerEmail, input.ownerEmail)];
|
|
130
|
+
if (fieldIds) conditions.push(inArray(customFields.id, fieldIds));
|
|
131
|
+
|
|
132
|
+
const rows = await db
|
|
133
|
+
.select()
|
|
134
|
+
.from(customFields)
|
|
135
|
+
.where(and(...conditions))
|
|
136
|
+
.orderBy(asc(customFields.sortOrder), asc(customFields.createdAt));
|
|
137
|
+
return { fields: rows.map(parseField) };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Title and config are per-field, so the bulk form takes one entry per field
|
|
142
|
+
* rather than a single patch applied across ids.
|
|
143
|
+
*/
|
|
144
|
+
export async function updateCustomFields(
|
|
145
|
+
input: {
|
|
146
|
+
ownerEmail: string;
|
|
147
|
+
entries: Array<{ fieldId: string; title?: string; config?: unknown }>;
|
|
148
|
+
now?: string;
|
|
149
|
+
},
|
|
150
|
+
db: DbHandle = getDb(),
|
|
151
|
+
): Promise<FieldDefinition[]> {
|
|
152
|
+
if (input.entries.length === 0) return [];
|
|
153
|
+
|
|
154
|
+
const { fields: existing } = await listCustomFields(
|
|
155
|
+
{
|
|
156
|
+
ownerEmail: input.ownerEmail,
|
|
157
|
+
fieldIds: input.entries.map((entry) => entry.fieldId),
|
|
158
|
+
},
|
|
159
|
+
db,
|
|
160
|
+
);
|
|
161
|
+
const existingById = new Map(existing.map((field) => [field.id, field]));
|
|
162
|
+
|
|
163
|
+
const patches = input.entries.map((entry) => {
|
|
164
|
+
const field = existingById.get(entry.fieldId);
|
|
165
|
+
if (!field) throw new NotFoundError("Custom field not found.");
|
|
166
|
+
|
|
167
|
+
if (entry.title === undefined && entry.config === undefined) {
|
|
168
|
+
return { field, patch: null };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const patch: Partial<typeof customFields.$inferInsert> = {
|
|
172
|
+
updatedAt: timestamp(input.now),
|
|
173
|
+
};
|
|
174
|
+
if (entry.title !== undefined) {
|
|
175
|
+
validateFieldTitle(entry.title);
|
|
176
|
+
patch.title = normalizeFieldTitle(entry.title);
|
|
177
|
+
}
|
|
178
|
+
if (entry.config !== undefined) {
|
|
179
|
+
patch.configJson = serializeFieldConfig(field.type, entry.config);
|
|
180
|
+
}
|
|
181
|
+
return { field, patch, cleanup: entry.config !== undefined };
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return db.transaction(async (tx) => {
|
|
185
|
+
const updated: FieldDefinition[] = [];
|
|
186
|
+
|
|
187
|
+
for (const { field, patch, cleanup } of patches) {
|
|
188
|
+
if (!patch) {
|
|
189
|
+
updated.push(field);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await tx
|
|
194
|
+
.update(customFields)
|
|
195
|
+
.set(patch)
|
|
196
|
+
.where(
|
|
197
|
+
and(
|
|
198
|
+
eq(customFields.ownerEmail, input.ownerEmail),
|
|
199
|
+
eq(customFields.id, field.id),
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const [updatedRow] = await tx
|
|
204
|
+
.select()
|
|
205
|
+
.from(customFields)
|
|
206
|
+
.where(
|
|
207
|
+
and(
|
|
208
|
+
eq(customFields.ownerEmail, input.ownerEmail),
|
|
209
|
+
eq(customFields.id, field.id),
|
|
210
|
+
),
|
|
211
|
+
)
|
|
212
|
+
.limit(1);
|
|
213
|
+
if (!updatedRow) throw new NotFoundError("Custom field not found.");
|
|
214
|
+
|
|
215
|
+
const parsed = parseField(updatedRow);
|
|
216
|
+
if (cleanup) {
|
|
217
|
+
await cleanupValuesAfterConfigChange(parsed, tx);
|
|
218
|
+
}
|
|
219
|
+
updated.push(parsed);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return updated;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function updateCustomField(
|
|
227
|
+
input: {
|
|
228
|
+
ownerEmail: string;
|
|
229
|
+
fieldId: string;
|
|
230
|
+
title?: string;
|
|
231
|
+
config?: unknown;
|
|
232
|
+
now?: string;
|
|
233
|
+
},
|
|
234
|
+
db: DbHandle = getDb(),
|
|
235
|
+
): Promise<FieldDefinition> {
|
|
236
|
+
const [field] = await updateCustomFields(
|
|
237
|
+
{
|
|
238
|
+
ownerEmail: input.ownerEmail,
|
|
239
|
+
entries: [
|
|
240
|
+
{ fieldId: input.fieldId, title: input.title, config: input.config },
|
|
241
|
+
],
|
|
242
|
+
now: input.now,
|
|
243
|
+
},
|
|
244
|
+
db,
|
|
245
|
+
);
|
|
246
|
+
if (!field) throw new NotFoundError("Custom field not found.");
|
|
247
|
+
return field;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function cleanupValuesAfterConfigChange(
|
|
251
|
+
field: FieldDefinition,
|
|
252
|
+
db: DbHandle,
|
|
253
|
+
): Promise<void> {
|
|
254
|
+
if (field.type !== "single_select" && field.type !== "multi_select") return;
|
|
255
|
+
const allowed = new Set(selectOptionIds(field));
|
|
256
|
+
const rows = await listCustomFieldValues(
|
|
257
|
+
{ ownerEmail: field.ownerEmail, fieldIds: [field.id] },
|
|
258
|
+
db,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const staleIds: string[] = [];
|
|
262
|
+
const trimmed: Array<{ id: string; value: FieldValue }> = [];
|
|
263
|
+
|
|
264
|
+
for (const row of rows) {
|
|
265
|
+
// Read the raw shape rather than `parseStoredValue`: that validates against
|
|
266
|
+
// the new config and throws on exactly the removed options this cleans up.
|
|
267
|
+
const value = parseFieldValueShape(JSON.parse(row.valueJson));
|
|
268
|
+
if (isEmptyFieldValue(value)) {
|
|
269
|
+
staleIds.push(row.id);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (field.type === "single_select") {
|
|
273
|
+
if (typeof value !== "string" || !allowed.has(value)) {
|
|
274
|
+
staleIds.push(row.id);
|
|
275
|
+
}
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const nextValue = Array.isArray(value)
|
|
280
|
+
? value.filter(
|
|
281
|
+
(optionId): optionId is string =>
|
|
282
|
+
typeof optionId === "string" && allowed.has(optionId),
|
|
283
|
+
)
|
|
284
|
+
: [];
|
|
285
|
+
if (nextValue.length === 0) {
|
|
286
|
+
staleIds.push(row.id);
|
|
287
|
+
} else if (!Array.isArray(value) || nextValue.length !== value.length) {
|
|
288
|
+
trimmed.push({ id: row.id, value: nextValue });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
await deleteCustomFieldValues(
|
|
293
|
+
{ ownerEmail: field.ownerEmail, ids: staleIds },
|
|
294
|
+
db,
|
|
295
|
+
);
|
|
296
|
+
await updateCustomFieldValues(
|
|
297
|
+
{ ownerEmail: field.ownerEmail, entries: trimmed },
|
|
298
|
+
db,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function selectOptionIds(field: FieldDefinition) {
|
|
303
|
+
return field.type === "single_select" || field.type === "multi_select"
|
|
304
|
+
? field.config.options.map((option) => option.id)
|
|
305
|
+
: [];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export async function deleteCustomFields(
|
|
309
|
+
input: {
|
|
310
|
+
ownerEmail: string;
|
|
311
|
+
fieldIds: string[];
|
|
312
|
+
},
|
|
313
|
+
db: DbHandle = getDb(),
|
|
314
|
+
): Promise<{ ok: true; deletedValues: number }> {
|
|
315
|
+
const fieldIds = [...new Set(input.fieldIds)];
|
|
316
|
+
if (fieldIds.length === 0) return { ok: true, deletedValues: 0 };
|
|
317
|
+
|
|
318
|
+
const { fields: existing } = await listCustomFields(
|
|
319
|
+
{ ownerEmail: input.ownerEmail, fieldIds },
|
|
320
|
+
db,
|
|
321
|
+
);
|
|
322
|
+
if (existing.length !== fieldIds.length) {
|
|
323
|
+
throw new NotFoundError("Custom field not found.");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const { deletedValues } = await db.transaction(async (tx) => {
|
|
327
|
+
const result = await deleteCustomFieldValuesByFieldIds(
|
|
328
|
+
{ ownerEmail: input.ownerEmail, fieldIds },
|
|
329
|
+
tx,
|
|
330
|
+
);
|
|
331
|
+
await tx
|
|
332
|
+
.delete(customFields)
|
|
333
|
+
.where(
|
|
334
|
+
and(
|
|
335
|
+
eq(customFields.ownerEmail, input.ownerEmail),
|
|
336
|
+
inArray(customFields.id, fieldIds),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
return result;
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
for (const fieldId of fieldIds) {
|
|
343
|
+
await removeTaskCardFieldId({ ownerEmail: input.ownerEmail, fieldId });
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return { ok: true, deletedValues };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export async function deleteCustomField(
|
|
350
|
+
input: {
|
|
351
|
+
ownerEmail: string;
|
|
352
|
+
fieldId: string;
|
|
353
|
+
},
|
|
354
|
+
db: DbHandle = getDb(),
|
|
355
|
+
): Promise<{ ok: true; deletedValues: number }> {
|
|
356
|
+
return deleteCustomFields(
|
|
357
|
+
{ ownerEmail: input.ownerEmail, fieldIds: [input.fieldId] },
|
|
358
|
+
db,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export async function reorderCustomFields(
|
|
363
|
+
input: {
|
|
364
|
+
ownerEmail: string;
|
|
365
|
+
fieldIds: string[];
|
|
366
|
+
},
|
|
367
|
+
db: DbHandle = getDb(),
|
|
368
|
+
): Promise<{ fields: FieldDefinition[] }> {
|
|
369
|
+
const { fields: existing } = await listCustomFields({
|
|
370
|
+
ownerEmail: input.ownerEmail,
|
|
371
|
+
});
|
|
372
|
+
const existingIds = new Set(existing.map((field) => field.id));
|
|
373
|
+
|
|
374
|
+
if (new Set(input.fieldIds).size !== input.fieldIds.length) {
|
|
375
|
+
throw new UserInputError("fieldIds must not contain duplicates.");
|
|
376
|
+
}
|
|
377
|
+
if (input.fieldIds.length !== existingIds.size) {
|
|
378
|
+
throw new UserInputError("fieldIds must include every field exactly once.");
|
|
379
|
+
}
|
|
380
|
+
if (!input.fieldIds.every((fieldId) => existingIds.has(fieldId))) {
|
|
381
|
+
throw new UserInputError("fieldIds must match the current field list.");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const updatedAt = timestamp();
|
|
385
|
+
const entries = input.fieldIds.map((fieldId, index) => ({
|
|
386
|
+
id: fieldId,
|
|
387
|
+
value: index * SORT_GAP,
|
|
388
|
+
}));
|
|
389
|
+
|
|
390
|
+
await db.transaction(async (tx) => {
|
|
391
|
+
for (const group of chunk(entries)) {
|
|
392
|
+
await tx
|
|
393
|
+
.update(customFields)
|
|
394
|
+
.set({ sortOrder: caseById(customFields.id, group), updatedAt })
|
|
395
|
+
.where(
|
|
396
|
+
and(
|
|
397
|
+
eq(customFields.ownerEmail, input.ownerEmail),
|
|
398
|
+
inArray(
|
|
399
|
+
customFields.id,
|
|
400
|
+
group.map((entry) => entry.id),
|
|
401
|
+
),
|
|
402
|
+
),
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
return listCustomFields({ ownerEmail: input.ownerEmail });
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function serializeFieldConfig<T extends FieldType>(type: T, config?: unknown) {
|
|
411
|
+
const shaped = parseFieldConfigShape(type, config ?? {});
|
|
412
|
+
validateFieldConfig(type, shaped);
|
|
413
|
+
return JSON.stringify(
|
|
414
|
+
canonicalizeFieldConfig(type, normalizeFieldConfigInput(type, shaped)),
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function nextSortOrder(ownerEmail: string) {
|
|
419
|
+
const db = getDb();
|
|
420
|
+
const [row] = await db
|
|
421
|
+
.select({ maxSortOrder: max(customFields.sortOrder) })
|
|
422
|
+
.from(customFields)
|
|
423
|
+
.where(eq(customFields.ownerEmail, ownerEmail));
|
|
424
|
+
return (row?.maxSortOrder ?? -SORT_GAP) + SORT_GAP;
|
|
425
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { StoredCustomFieldValue } from "../db/schema.js";
|
|
2
|
+
import { NotFoundError } from "../errors.js";
|
|
3
|
+
import { getTask, type Task } from "../tasks/store.js";
|
|
4
|
+
import { parseStoredValue } from "./parse.js";
|
|
5
|
+
import { listCustomFields } from "./store.js";
|
|
6
|
+
import type { FieldDefinition, FieldValue } from "./types.js";
|
|
7
|
+
import { listCustomFieldValues } from "./values/store.js";
|
|
8
|
+
|
|
9
|
+
export type TaskFieldValue = FieldDefinition & {
|
|
10
|
+
value: FieldValue | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type TaskWithFields = Task & { fields: TaskFieldValue[] };
|
|
14
|
+
|
|
15
|
+
function fieldsById(fields: FieldDefinition[]) {
|
|
16
|
+
return new Map(fields.map((field) => [field.id, field]));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function valuesByFieldId(
|
|
20
|
+
rows: StoredCustomFieldValue[],
|
|
21
|
+
fieldsByIdMap: Map<string, FieldDefinition>,
|
|
22
|
+
): Map<string, FieldValue | null> {
|
|
23
|
+
return new Map(
|
|
24
|
+
rows.map((row) => {
|
|
25
|
+
const field = fieldsByIdMap.get(row.fieldId);
|
|
26
|
+
if (!field) throw new Error("Custom field not found.");
|
|
27
|
+
return [row.fieldId, parseStoredValue(field, row)] as const;
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function valuesByTaskId(
|
|
33
|
+
rows: StoredCustomFieldValue[],
|
|
34
|
+
fieldsByIdMap: Map<string, FieldDefinition>,
|
|
35
|
+
): Map<string, Map<string, FieldValue | null>> {
|
|
36
|
+
const result = new Map<string, Map<string, FieldValue | null>>();
|
|
37
|
+
for (const row of rows) {
|
|
38
|
+
let values = result.get(row.taskId);
|
|
39
|
+
if (!values) {
|
|
40
|
+
values = new Map();
|
|
41
|
+
result.set(row.taskId, values);
|
|
42
|
+
}
|
|
43
|
+
const field = fieldsByIdMap.get(row.fieldId);
|
|
44
|
+
if (!field) throw new Error("Custom field not found.");
|
|
45
|
+
values.set(row.fieldId, parseStoredValue(field, row));
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function buildTaskFieldValues(
|
|
51
|
+
fields: FieldDefinition[],
|
|
52
|
+
valuesByFieldIdMap: Map<string, FieldValue | null>,
|
|
53
|
+
): TaskFieldValue[] {
|
|
54
|
+
return fields.map((field) => ({
|
|
55
|
+
...field,
|
|
56
|
+
value: valuesByFieldIdMap.get(field.id) ?? null,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function listTaskFieldValues(input: {
|
|
61
|
+
ownerEmail: string;
|
|
62
|
+
taskId: string;
|
|
63
|
+
}): Promise<TaskFieldValue[]> {
|
|
64
|
+
const task = await getTask({
|
|
65
|
+
ownerEmail: input.ownerEmail,
|
|
66
|
+
id: input.taskId,
|
|
67
|
+
});
|
|
68
|
+
if (!task) throw new NotFoundError("Task not found.");
|
|
69
|
+
|
|
70
|
+
const [{ fields }, rows] = await Promise.all([
|
|
71
|
+
listCustomFields({ ownerEmail: input.ownerEmail }),
|
|
72
|
+
listCustomFieldValues({
|
|
73
|
+
ownerEmail: input.ownerEmail,
|
|
74
|
+
taskIds: [input.taskId],
|
|
75
|
+
}),
|
|
76
|
+
]);
|
|
77
|
+
const fieldsByIdMap = fieldsById(fields);
|
|
78
|
+
return buildTaskFieldValues(fields, valuesByFieldId(rows, fieldsByIdMap));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function attachFieldsToTasks(
|
|
82
|
+
ownerEmail: string,
|
|
83
|
+
tasks: Task[],
|
|
84
|
+
): Promise<TaskWithFields[]> {
|
|
85
|
+
if (tasks.length === 0) return [];
|
|
86
|
+
|
|
87
|
+
const [{ fields }, rows] = await Promise.all([
|
|
88
|
+
listCustomFields({ ownerEmail }),
|
|
89
|
+
listCustomFieldValues({
|
|
90
|
+
ownerEmail,
|
|
91
|
+
taskIds: tasks.map((task) => task.id),
|
|
92
|
+
}),
|
|
93
|
+
]);
|
|
94
|
+
const fieldsByIdMap = fieldsById(fields);
|
|
95
|
+
const valuesByTaskIdMap = valuesByTaskId(rows, fieldsByIdMap);
|
|
96
|
+
|
|
97
|
+
return tasks.map((task) => ({
|
|
98
|
+
...task,
|
|
99
|
+
fields: buildTaskFieldValues(
|
|
100
|
+
fields,
|
|
101
|
+
valuesByTaskIdMap.get(task.id) ?? new Map(),
|
|
102
|
+
),
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export type FieldDefinitionBase = {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
sortOrder: number;
|
|
5
|
+
ownerEmail: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/* Configs: */
|
|
11
|
+
|
|
12
|
+
export type NumericFieldConfig = {
|
|
13
|
+
precision?: number;
|
|
14
|
+
positiveOnly?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type CurrencyFieldConfig = { symbol: string; precision?: number };
|
|
17
|
+
|
|
18
|
+
export const SELECT_COLOR_TOKENS = [
|
|
19
|
+
"red",
|
|
20
|
+
"orange",
|
|
21
|
+
"yellow",
|
|
22
|
+
"green",
|
|
23
|
+
"blue",
|
|
24
|
+
"purple",
|
|
25
|
+
"pink",
|
|
26
|
+
"gray",
|
|
27
|
+
] as const;
|
|
28
|
+
export type SelectColorToken = (typeof SELECT_COLOR_TOKENS)[number];
|
|
29
|
+
|
|
30
|
+
export type SelectOption = {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
color?: SelectColorToken;
|
|
34
|
+
sortOrder: number;
|
|
35
|
+
};
|
|
36
|
+
export type SelectFieldConfig = { options: SelectOption[] };
|
|
37
|
+
|
|
38
|
+
export type EmptyFieldConfig = Record<string, never>;
|
|
39
|
+
|
|
40
|
+
export const FIELD_TYPES = [
|
|
41
|
+
"text",
|
|
42
|
+
"rich_text",
|
|
43
|
+
"number",
|
|
44
|
+
"percent",
|
|
45
|
+
"currency",
|
|
46
|
+
"single_select",
|
|
47
|
+
"multi_select",
|
|
48
|
+
"date",
|
|
49
|
+
] as const;
|
|
50
|
+
export type FieldType = (typeof FIELD_TYPES)[number];
|
|
51
|
+
|
|
52
|
+
export type EmptyConfigInput = EmptyFieldConfig;
|
|
53
|
+
export type SelectOptionInput = {
|
|
54
|
+
id?: string;
|
|
55
|
+
name: string;
|
|
56
|
+
color?: SelectColorToken;
|
|
57
|
+
sortOrder?: number;
|
|
58
|
+
};
|
|
59
|
+
export type SelectConfigInput = { options: SelectOptionInput[] };
|
|
60
|
+
export type NumericConfigInput = NumericFieldConfig;
|
|
61
|
+
export type PercentConfigInput = { precision?: number };
|
|
62
|
+
export type CurrencyConfigInput = {
|
|
63
|
+
symbol?: string;
|
|
64
|
+
precision?: number;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type FieldConfigInputMap = {
|
|
68
|
+
text: EmptyFieldConfig;
|
|
69
|
+
rich_text: EmptyFieldConfig;
|
|
70
|
+
date: EmptyFieldConfig;
|
|
71
|
+
number: NumericConfigInput;
|
|
72
|
+
percent: PercentConfigInput;
|
|
73
|
+
currency: CurrencyConfigInput;
|
|
74
|
+
single_select: SelectConfigInput;
|
|
75
|
+
multi_select: SelectConfigInput;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type FieldConfigInput<T extends FieldType = FieldType> =
|
|
79
|
+
FieldConfigInputMap[T];
|
|
80
|
+
|
|
81
|
+
/* Field Definition: */
|
|
82
|
+
|
|
83
|
+
export type FieldDefinition = FieldDefinitionBase &
|
|
84
|
+
(
|
|
85
|
+
| { type: "text"; config: EmptyFieldConfig }
|
|
86
|
+
| { type: "rich_text"; config: EmptyFieldConfig }
|
|
87
|
+
| { type: "date"; config: EmptyFieldConfig }
|
|
88
|
+
| { type: "number"; config: NumericFieldConfig }
|
|
89
|
+
| { type: "percent"; config: NumericFieldConfig }
|
|
90
|
+
| { type: "currency"; config: CurrencyFieldConfig }
|
|
91
|
+
| { type: "single_select"; config: SelectFieldConfig }
|
|
92
|
+
| { type: "multi_select"; config: SelectFieldConfig }
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export type FieldConfig = FieldDefinition["config"];
|
|
96
|
+
|
|
97
|
+
export type FieldValue = string | number | string[];
|
|
98
|
+
export type FieldValueInput = FieldValue | null;
|