@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,548 @@
|
|
|
1
|
+
import { and, asc, eq, inArray, min } from "drizzle-orm";
|
|
2
|
+
|
|
3
|
+
import { caseById, chunk } from "../db/bulk-write.js";
|
|
4
|
+
import { getDb } from "../db/index.js";
|
|
5
|
+
import { tasks, type StoredItem } from "../db/schema.js";
|
|
6
|
+
import type { DbHandle } from "../db/transaction.js";
|
|
7
|
+
import { AuthError, NotFoundError, UserInputError } from "../errors.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Storage layer on the unified `tasks` table.
|
|
11
|
+
* All methods take `promotedToTask`; there is no inbox/task split at this layer.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type { StoredItem };
|
|
15
|
+
|
|
16
|
+
const SORT_GAP = 1000;
|
|
17
|
+
|
|
18
|
+
export function requireUserEmail(email: string | undefined): string {
|
|
19
|
+
if (!email) {
|
|
20
|
+
throw new AuthError("Authentication required.");
|
|
21
|
+
}
|
|
22
|
+
return email;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function createStoredItem(
|
|
26
|
+
input: {
|
|
27
|
+
ownerEmail: string;
|
|
28
|
+
title: string;
|
|
29
|
+
id: string;
|
|
30
|
+
now: string;
|
|
31
|
+
promotedToTask: boolean;
|
|
32
|
+
},
|
|
33
|
+
db: DbHandle = getDb(),
|
|
34
|
+
): Promise<StoredItem> {
|
|
35
|
+
const title = assertNonEmptyTitle(input.title, "Title is required.");
|
|
36
|
+
const sortOrder = await nextSortOrderForNewItem(
|
|
37
|
+
input.ownerEmail,
|
|
38
|
+
input.promotedToTask,
|
|
39
|
+
db,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
await db.insert(tasks).values({
|
|
43
|
+
id: input.id,
|
|
44
|
+
title,
|
|
45
|
+
done: false,
|
|
46
|
+
promotedToTask: input.promotedToTask,
|
|
47
|
+
sortOrder,
|
|
48
|
+
ownerEmail: input.ownerEmail,
|
|
49
|
+
createdAt: input.now,
|
|
50
|
+
updatedAt: input.now,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const item = await getStoredItem(
|
|
54
|
+
{
|
|
55
|
+
ownerEmail: input.ownerEmail,
|
|
56
|
+
id: input.id,
|
|
57
|
+
promotedToTask: input.promotedToTask,
|
|
58
|
+
},
|
|
59
|
+
db,
|
|
60
|
+
);
|
|
61
|
+
if (!item) {
|
|
62
|
+
throw new Error("Failed to create stored item.");
|
|
63
|
+
}
|
|
64
|
+
return item;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function getStoredItem(
|
|
68
|
+
input: {
|
|
69
|
+
ownerEmail: string;
|
|
70
|
+
id: string;
|
|
71
|
+
promotedToTask?: boolean;
|
|
72
|
+
},
|
|
73
|
+
db: DbHandle = getDb(),
|
|
74
|
+
): Promise<StoredItem | null> {
|
|
75
|
+
const conditions = [
|
|
76
|
+
eq(tasks.id, input.id),
|
|
77
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
78
|
+
];
|
|
79
|
+
if (input.promotedToTask !== undefined) {
|
|
80
|
+
conditions.push(eq(tasks.promotedToTask, input.promotedToTask));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const [row] = await db
|
|
84
|
+
.select()
|
|
85
|
+
.from(tasks)
|
|
86
|
+
.where(and(...conditions))
|
|
87
|
+
.limit(1);
|
|
88
|
+
return row ?? null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function hasCompletedStoredItems(
|
|
92
|
+
input: {
|
|
93
|
+
ownerEmail: string;
|
|
94
|
+
promotedToTask: boolean;
|
|
95
|
+
},
|
|
96
|
+
db: DbHandle = getDb(),
|
|
97
|
+
): Promise<boolean> {
|
|
98
|
+
if (!input.promotedToTask) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const [row] = await db
|
|
103
|
+
.select({ id: tasks.id })
|
|
104
|
+
.from(tasks)
|
|
105
|
+
.where(
|
|
106
|
+
and(
|
|
107
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
108
|
+
eq(tasks.promotedToTask, true),
|
|
109
|
+
eq(tasks.done, true),
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
.limit(1);
|
|
113
|
+
return row !== undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function listStoredItems(
|
|
117
|
+
input: {
|
|
118
|
+
ownerEmail: string;
|
|
119
|
+
promotedToTask: boolean;
|
|
120
|
+
ids?: string[];
|
|
121
|
+
includeDone?: boolean;
|
|
122
|
+
notFoundMessage?: string;
|
|
123
|
+
},
|
|
124
|
+
db: DbHandle = getDb(),
|
|
125
|
+
): Promise<StoredItem[]> {
|
|
126
|
+
const ids = input.ids ? [...new Set(input.ids)] : undefined;
|
|
127
|
+
if (ids?.length === 0) return [];
|
|
128
|
+
|
|
129
|
+
const filters = [
|
|
130
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
131
|
+
eq(tasks.promotedToTask, input.promotedToTask),
|
|
132
|
+
];
|
|
133
|
+
if (ids) {
|
|
134
|
+
filters.push(inArray(tasks.id, ids));
|
|
135
|
+
} else if (input.promotedToTask && !input.includeDone) {
|
|
136
|
+
filters.push(eq(tasks.done, false));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const rows = await db
|
|
140
|
+
.select()
|
|
141
|
+
.from(tasks)
|
|
142
|
+
.where(and(...filters))
|
|
143
|
+
.orderBy(asc(tasks.sortOrder), asc(tasks.createdAt));
|
|
144
|
+
|
|
145
|
+
if (!ids) return rows;
|
|
146
|
+
|
|
147
|
+
const rowsById = new Map(rows.map((row) => [row.id, row]));
|
|
148
|
+
return ids.map((id) => {
|
|
149
|
+
const row = rowsById.get(id);
|
|
150
|
+
if (!row) {
|
|
151
|
+
throw new NotFoundError(
|
|
152
|
+
input.notFoundMessage ?? "Stored item not found.",
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return row;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function updateStoredItems(
|
|
160
|
+
input: {
|
|
161
|
+
ownerEmail: string;
|
|
162
|
+
ids: string[];
|
|
163
|
+
promotedToTask: boolean;
|
|
164
|
+
title?: string;
|
|
165
|
+
done?: boolean;
|
|
166
|
+
now?: string;
|
|
167
|
+
notFoundMessage?: string;
|
|
168
|
+
},
|
|
169
|
+
db: DbHandle = getDb(),
|
|
170
|
+
): Promise<StoredItem[]> {
|
|
171
|
+
const ids = [...new Set(input.ids)];
|
|
172
|
+
if (ids.length === 0) return [];
|
|
173
|
+
|
|
174
|
+
const read = {
|
|
175
|
+
ownerEmail: input.ownerEmail,
|
|
176
|
+
ids,
|
|
177
|
+
promotedToTask: input.promotedToTask,
|
|
178
|
+
notFoundMessage: input.notFoundMessage,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const hasTitle = input.title !== undefined;
|
|
182
|
+
const hasDone = input.promotedToTask && input.done !== undefined;
|
|
183
|
+
if (!hasTitle && !hasDone) {
|
|
184
|
+
return listStoredItems(read, db);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
await assertStoredItemsExist(read, db);
|
|
188
|
+
|
|
189
|
+
const patch: Partial<typeof tasks.$inferInsert> = {
|
|
190
|
+
updatedAt: input.now ?? new Date().toISOString(),
|
|
191
|
+
};
|
|
192
|
+
if (hasTitle) {
|
|
193
|
+
patch.title = assertNonEmptyTitle(input.title!, "Title cannot be empty.");
|
|
194
|
+
}
|
|
195
|
+
if (hasDone) {
|
|
196
|
+
patch.done = input.done;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await db
|
|
200
|
+
.update(tasks)
|
|
201
|
+
.set(patch)
|
|
202
|
+
.where(
|
|
203
|
+
and(
|
|
204
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
205
|
+
eq(tasks.promotedToTask, input.promotedToTask),
|
|
206
|
+
inArray(tasks.id, ids),
|
|
207
|
+
),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
return listStoredItems(read, db);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function updateStoredItem(
|
|
214
|
+
input: {
|
|
215
|
+
ownerEmail: string;
|
|
216
|
+
id: string;
|
|
217
|
+
promotedToTask: boolean;
|
|
218
|
+
title?: string;
|
|
219
|
+
done?: boolean;
|
|
220
|
+
now?: string;
|
|
221
|
+
notFoundMessage?: string;
|
|
222
|
+
},
|
|
223
|
+
db: DbHandle = getDb(),
|
|
224
|
+
): Promise<StoredItem> {
|
|
225
|
+
const [item] = await updateStoredItems({ ...input, ids: [input.id] }, db);
|
|
226
|
+
if (!item) {
|
|
227
|
+
throw new NotFoundError(input.notFoundMessage ?? "Stored item not found.");
|
|
228
|
+
}
|
|
229
|
+
return item;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Deletes without checking existence first; callers assert when they need to. */
|
|
233
|
+
export async function deleteStoredItems(
|
|
234
|
+
input: {
|
|
235
|
+
ownerEmail: string;
|
|
236
|
+
ids: string[];
|
|
237
|
+
promotedToTask: boolean;
|
|
238
|
+
},
|
|
239
|
+
db: DbHandle = getDb(),
|
|
240
|
+
): Promise<void> {
|
|
241
|
+
const ids = [...new Set(input.ids)];
|
|
242
|
+
if (ids.length === 0) return;
|
|
243
|
+
|
|
244
|
+
await db
|
|
245
|
+
.delete(tasks)
|
|
246
|
+
.where(
|
|
247
|
+
and(
|
|
248
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
249
|
+
eq(tasks.promotedToTask, input.promotedToTask),
|
|
250
|
+
inArray(tasks.id, ids),
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export async function deleteStoredItem(
|
|
256
|
+
input: {
|
|
257
|
+
ownerEmail: string;
|
|
258
|
+
id: string;
|
|
259
|
+
promotedToTask: boolean;
|
|
260
|
+
},
|
|
261
|
+
db: DbHandle = getDb(),
|
|
262
|
+
): Promise<void> {
|
|
263
|
+
await deleteStoredItems({ ...input, ids: [input.id] }, db);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export async function assertStoredItemsExist(
|
|
267
|
+
input: {
|
|
268
|
+
ownerEmail: string;
|
|
269
|
+
ids: string[];
|
|
270
|
+
promotedToTask: boolean;
|
|
271
|
+
notFoundMessage?: string;
|
|
272
|
+
},
|
|
273
|
+
db: DbHandle = getDb(),
|
|
274
|
+
): Promise<void> {
|
|
275
|
+
const ids = [...new Set(input.ids)];
|
|
276
|
+
if (ids.length === 0) return;
|
|
277
|
+
|
|
278
|
+
const found = await db
|
|
279
|
+
.select({ id: tasks.id })
|
|
280
|
+
.from(tasks)
|
|
281
|
+
.where(
|
|
282
|
+
and(
|
|
283
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
284
|
+
eq(tasks.promotedToTask, input.promotedToTask),
|
|
285
|
+
inArray(tasks.id, ids),
|
|
286
|
+
),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
if (found.length !== ids.length) {
|
|
290
|
+
throw new NotFoundError(input.notFoundMessage ?? "Stored item not found.");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export async function reorderStoredItems(
|
|
295
|
+
input: {
|
|
296
|
+
ownerEmail: string;
|
|
297
|
+
promotedToTask: boolean;
|
|
298
|
+
orderedIds: string[];
|
|
299
|
+
includeDone?: boolean;
|
|
300
|
+
idLabel?: string;
|
|
301
|
+
},
|
|
302
|
+
db: DbHandle = getDb(),
|
|
303
|
+
): Promise<void> {
|
|
304
|
+
const idLabel =
|
|
305
|
+
input.idLabel ?? (input.promotedToTask ? "taskIds" : "inboxItemIds");
|
|
306
|
+
const visibleItems = await listStoredItems(
|
|
307
|
+
{
|
|
308
|
+
ownerEmail: input.ownerEmail,
|
|
309
|
+
promotedToTask: input.promotedToTask,
|
|
310
|
+
includeDone: input.includeDone,
|
|
311
|
+
},
|
|
312
|
+
db,
|
|
313
|
+
);
|
|
314
|
+
const visibleIds = new Set(visibleItems.map((item) => item.id));
|
|
315
|
+
validateVisibleReorder(input.orderedIds, visibleIds, idLabel);
|
|
316
|
+
|
|
317
|
+
if (!input.promotedToTask) {
|
|
318
|
+
await applySortOrderUpdates(input, db);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const allPromotedItems = await db
|
|
323
|
+
.select()
|
|
324
|
+
.from(tasks)
|
|
325
|
+
.where(
|
|
326
|
+
and(
|
|
327
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
328
|
+
eq(tasks.promotedToTask, true),
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
.orderBy(asc(tasks.sortOrder), asc(tasks.createdAt));
|
|
332
|
+
|
|
333
|
+
const itemsById = new Map(allPromotedItems.map((item) => [item.id, item]));
|
|
334
|
+
const visibleQueue = [...input.orderedIds];
|
|
335
|
+
const merged = allPromotedItems.map((item) => {
|
|
336
|
+
if (!visibleIds.has(item.id)) return item;
|
|
337
|
+
const nextId = visibleQueue.shift();
|
|
338
|
+
if (!nextId) {
|
|
339
|
+
throw new UserInputError(
|
|
340
|
+
`${idLabel} must include every visible item exactly once.`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
const nextItem = itemsById.get(nextId);
|
|
344
|
+
if (!nextItem) {
|
|
345
|
+
throw new NotFoundError("Stored item not found.");
|
|
346
|
+
}
|
|
347
|
+
return nextItem;
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const timestamp = new Date().toISOString();
|
|
351
|
+
const entries = merged.map((item, index) => ({
|
|
352
|
+
id: item.id,
|
|
353
|
+
value: index * SORT_GAP,
|
|
354
|
+
}));
|
|
355
|
+
|
|
356
|
+
await db.transaction(async (tx) => {
|
|
357
|
+
for (const group of chunk(entries)) {
|
|
358
|
+
await tx
|
|
359
|
+
.update(tasks)
|
|
360
|
+
.set({ sortOrder: caseById(tasks.id, group), updatedAt: timestamp })
|
|
361
|
+
.where(
|
|
362
|
+
and(
|
|
363
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
364
|
+
eq(tasks.promotedToTask, true),
|
|
365
|
+
inArray(
|
|
366
|
+
tasks.id,
|
|
367
|
+
group.map((entry) => entry.id),
|
|
368
|
+
),
|
|
369
|
+
),
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function validateVisibleReorder(
|
|
376
|
+
orderedIds: string[],
|
|
377
|
+
visibleIds: Set<string>,
|
|
378
|
+
idLabel: string,
|
|
379
|
+
): void {
|
|
380
|
+
if (orderedIds.length !== visibleIds.size) {
|
|
381
|
+
throw new UserInputError(
|
|
382
|
+
`${idLabel} must include every visible item exactly once.`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (!orderedIds.every((id) => visibleIds.has(id))) {
|
|
387
|
+
throw new UserInputError(`${idLabel} must match the current visible list.`);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (new Set(orderedIds).size !== orderedIds.length) {
|
|
391
|
+
throw new UserInputError(`${idLabel} must not contain duplicates.`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function applySortOrderUpdates(
|
|
396
|
+
input: {
|
|
397
|
+
ownerEmail: string;
|
|
398
|
+
promotedToTask: boolean;
|
|
399
|
+
orderedIds: string[];
|
|
400
|
+
},
|
|
401
|
+
db: DbHandle = getDb(),
|
|
402
|
+
): Promise<void> {
|
|
403
|
+
const timestamp = new Date().toISOString();
|
|
404
|
+
const entries = input.orderedIds.map((id, index) => ({
|
|
405
|
+
id,
|
|
406
|
+
value: index * SORT_GAP,
|
|
407
|
+
}));
|
|
408
|
+
|
|
409
|
+
await db.transaction(async (tx) => {
|
|
410
|
+
for (const group of chunk(entries)) {
|
|
411
|
+
await tx
|
|
412
|
+
.update(tasks)
|
|
413
|
+
.set({ sortOrder: caseById(tasks.id, group), updatedAt: timestamp })
|
|
414
|
+
.where(
|
|
415
|
+
and(
|
|
416
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
417
|
+
eq(tasks.promotedToTask, input.promotedToTask),
|
|
418
|
+
inArray(
|
|
419
|
+
tasks.id,
|
|
420
|
+
group.map((entry) => entry.id),
|
|
421
|
+
),
|
|
422
|
+
),
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** Set `promotedToTask` from false → true on existing stored items (same ids). */
|
|
429
|
+
export async function promoteStoredItemsToTasks(
|
|
430
|
+
input: {
|
|
431
|
+
ownerEmail: string;
|
|
432
|
+
ids: string[];
|
|
433
|
+
now?: string;
|
|
434
|
+
},
|
|
435
|
+
db: DbHandle = getDb(),
|
|
436
|
+
): Promise<StoredItem[]> {
|
|
437
|
+
const ids = [...new Set(input.ids)];
|
|
438
|
+
if (ids.length === 0) {
|
|
439
|
+
throw new UserInputError("Provide at least one inbox item id.");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
await assertStoredItemsExist(
|
|
443
|
+
{
|
|
444
|
+
ownerEmail: input.ownerEmail,
|
|
445
|
+
ids,
|
|
446
|
+
promotedToTask: false,
|
|
447
|
+
notFoundMessage: "Stored item not found.",
|
|
448
|
+
},
|
|
449
|
+
db,
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
const timestamp = input.now ?? new Date().toISOString();
|
|
453
|
+
const topSortOrder = await nextSortOrderForNewItem(
|
|
454
|
+
input.ownerEmail,
|
|
455
|
+
true,
|
|
456
|
+
db,
|
|
457
|
+
);
|
|
458
|
+
const entries = ids.map((id, index) => ({
|
|
459
|
+
id,
|
|
460
|
+
value: topSortOrder - index * SORT_GAP,
|
|
461
|
+
}));
|
|
462
|
+
|
|
463
|
+
await db.transaction(async (tx) => {
|
|
464
|
+
for (const group of chunk(entries)) {
|
|
465
|
+
await tx
|
|
466
|
+
.update(tasks)
|
|
467
|
+
.set({
|
|
468
|
+
promotedToTask: true,
|
|
469
|
+
done: false,
|
|
470
|
+
sortOrder: caseById(tasks.id, group),
|
|
471
|
+
updatedAt: timestamp,
|
|
472
|
+
})
|
|
473
|
+
.where(
|
|
474
|
+
and(
|
|
475
|
+
eq(tasks.ownerEmail, input.ownerEmail),
|
|
476
|
+
eq(tasks.promotedToTask, false),
|
|
477
|
+
inArray(
|
|
478
|
+
tasks.id,
|
|
479
|
+
group.map((entry) => entry.id),
|
|
480
|
+
),
|
|
481
|
+
),
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
return listStoredItems(
|
|
487
|
+
{
|
|
488
|
+
ownerEmail: input.ownerEmail,
|
|
489
|
+
ids,
|
|
490
|
+
promotedToTask: true,
|
|
491
|
+
},
|
|
492
|
+
db,
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export async function promoteStoredItemToTask(
|
|
497
|
+
input: {
|
|
498
|
+
ownerEmail: string;
|
|
499
|
+
id: string;
|
|
500
|
+
now?: string;
|
|
501
|
+
},
|
|
502
|
+
db: DbHandle = getDb(),
|
|
503
|
+
): Promise<StoredItem> {
|
|
504
|
+
const [item] = await promoteStoredItemsToTasks(
|
|
505
|
+
{ ownerEmail: input.ownerEmail, ids: [input.id], now: input.now },
|
|
506
|
+
db,
|
|
507
|
+
);
|
|
508
|
+
if (!item) {
|
|
509
|
+
throw new NotFoundError("Stored item not found.");
|
|
510
|
+
}
|
|
511
|
+
return item;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function assertNonEmptyTitle(title: string, emptyMessage: string): string {
|
|
515
|
+
const trimmed = title.trim();
|
|
516
|
+
if (!trimmed) {
|
|
517
|
+
throw new UserInputError(emptyMessage);
|
|
518
|
+
}
|
|
519
|
+
return trimmed;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function nextSortOrderForNewItem(
|
|
523
|
+
ownerEmail: string,
|
|
524
|
+
promotedToTask: boolean,
|
|
525
|
+
db: DbHandle = getDb(),
|
|
526
|
+
): Promise<number> {
|
|
527
|
+
const minSort = await minSortOrderForOwner(ownerEmail, promotedToTask, db);
|
|
528
|
+
if (minSort == null) return 0;
|
|
529
|
+
return minSort - SORT_GAP;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async function minSortOrderForOwner(
|
|
533
|
+
ownerEmail: string,
|
|
534
|
+
promotedToTask: boolean,
|
|
535
|
+
db: DbHandle = getDb(),
|
|
536
|
+
): Promise<number | null> {
|
|
537
|
+
const [row] = await db
|
|
538
|
+
.select({ minSort: min(tasks.sortOrder) })
|
|
539
|
+
.from(tasks)
|
|
540
|
+
.where(
|
|
541
|
+
and(
|
|
542
|
+
eq(tasks.ownerEmail, ownerEmail),
|
|
543
|
+
eq(tasks.promotedToTask, promotedToTask),
|
|
544
|
+
),
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
return row?.minSort ?? null;
|
|
548
|
+
}
|