Skip to content

feat(chat): add scheduled tasks as a viewable resource#5085

Open
waleedlatif1 wants to merge 4 commits into
stagingfrom
feat/scheduled-task-mship-resource
Open

feat(chat): add scheduled tasks as a viewable resource#5085
waleedlatif1 wants to merge 4 commits into
stagingfrom
feat/scheduled-task-mship-resource

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Add a new scheduledtask resource type so a scheduled task can be opened and viewed as a tab in Chat (we had no way to view one before)
  • Registry config: Calendar icon, label, tab + dropdown renderers
  • Add-resource dropdown now lists workspace scheduled tasks (jobs)
  • Embedded detail viewer: status, schedule cadence, next/last run, prompt, and recent runs, with a not-found state
  • "Open in scheduled tasks" tab action + React Query cache invalidation
  • Contract enum + route validation so the resource persists on the chat

Agent-side mention/OpenResource wiring is intentionally left as a follow-up.

Type of Change

  • New feature

Testing

Tested manually. tsc, check:api-validation, and check:react-query all pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Adds a new `scheduledtask` resource type so a scheduled task can be opened
and viewed as a tab in Chat:
- registry config (Calendar icon, label, tab/dropdown renderers)
- add-resource dropdown listing (workspace jobs)
- embedded detail viewer (status, schedule, next/last run, prompt, recent runs)
- "Open in scheduled tasks" action + query invalidation
- contract enum + route validation so the resource persists

Agent-side mention/OpenResource wiring is left as a follow-up.
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 16, 2026 2:55am

Request Review

@cursor

cursor Bot commented Jun 16, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Read-only UI and enum extensions following existing resource patterns; no auth or execution-path changes.

Overview
Introduces scheduledtask as a first-class mothership/chat resource so workspace job schedules can be opened as tabs in Chat.

End-to-end wiring: API contract and chat-resources route accept and persist the type; shared GENERIC_RESOURCE_TITLES (including “Scheduled Task”) replaces duplicated local sets for title merge/dedup. Registries, chip clipboard codec, ChatContext, and resource→context mapping all gain scheduledtask / scheduleId.

UI: Add-resource dropdown lists schedules (sourceType === 'job'); tabs use Calendar icons. EmbeddedScheduledTask shows status, cadence, next/last run, prompt, and recent runs (with loading/error/not-found). Tab action navigates to the scheduled-tasks page; schedule list queries invalidate when the resource is added.

Reviewed by Cursor Bugbot for commit 9c07fd9. Configure here.

Comment thread apps/sim/app/api/copilot/chat/resources/route.ts Outdated
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds scheduledtask as a first-class resource type in the Chat (mothership) UI, allowing users to open and view a standalone scheduled task as a tab — a resource that previously had no viewable representation.

  • Viewer component: EmbeddedScheduledTask renders status, schedule cadence, next/last run, prompt, and up to 5 recent runs; correctly handles loading, network-error, and not-found states using isLoading/isError from useWorkspaceSchedules.
  • Registry plumbing: scheduledtask is wired into the resource registry (display config + cache invalidation), context-kind registry, add-resource dropdown (filtered to sourceType === 'job'), clipboard codec, isChatContext type guard, Zod contract enum, and route VALID_RESOURCE_TYPES — consistent with how all other resource types are integrated.
  • Dedup refactor: The previously duplicated GENERIC_TITLES local sets in route.ts and persistence.ts are consolidated into the exported GENERIC_RESOURCE_TITLES constant in types.ts.

Confidence Score: 5/5

Safe to merge — purely additive feature wiring that follows the exact same pattern used by all other resource types, with no changes to shared execution paths.

Every touchpoint — Zod contract, route allowlist, persistence dedup, type guard, clipboard codec, context registry, resource registry, and embedded viewer — is updated consistently. Error and loading states were addressed in a prior commit (e494b22). The shared GENERIC_RESOURCE_TITLES refactor is a strict equivalence substitution. No pre-existing paths are altered.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Adds EmbeddedScheduledTask viewer and EmbeddedScheduledTaskActions; error/loading/not-found states correctly handled; jobHistory null-check present; formatScheduleInstant guards against invalid dates.
apps/sim/lib/copilot/resources/types.ts Adds scheduledtask to MothershipResourceType enum and extracts the GENERIC_RESOURCE_TITLES set (previously duplicated inline in route and persistence); 'Scheduled Task' correctly added as a generic placeholder title.
apps/sim/lib/api/contracts/copilot.ts Adds scheduledtask to copilotResourceTypeSchema Zod enum, keeping the contract in sync with VALID_RESOURCE_TYPES; no regressions.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown/add-resource-dropdown.tsx Fetches workspace schedules, filters to sourceType === 'job' (correct – excludes workflow block schedules and legacy null rows), and maps to dropdown items with jobTitle or truncated prompt fallback.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry/resource-registry.tsx Adds scheduledtask to RESOURCE_REGISTRY (display config) and RESOURCE_INVALIDATORS (invalidates scheduleKeys.list on tab open); follows existing patterns correctly.
apps/sim/lib/copilot/resources/persistence.ts Removes the duplicated local GENERIC set and uses the shared GENERIC_RESOURCE_TITLES constant; logic unchanged.
apps/sim/stores/panel/types.ts Adds the scheduledtask discriminant to the ChatContext union with the correct scheduleId field; consistent with all call sites updated in this PR.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/chip-clipboard-codec.ts Adds scheduledtask to PORTABLE_KIND_TO_ID_FIELD and chipLinkToContext; field name scheduleId matches the ChatContext type definition.
apps/sim/app/workspace/[workspaceId]/home/components/chat-context-kind-registry/chat-context-kind-registry.tsx Registers the scheduledtask kind with Calendar icon and 'Scheduled task' label; required to satisfy the Record<ChatContextKind, ...> exhaustiveness check.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Adds the scheduledtask case to the isChatContext type guard, checking scheduleId is a string; matches the discriminant union.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/constants.ts Maps scheduledtask resource to a ChatContext with kind 'scheduledtask' and scheduleId; consistent with all other resource-to-context mappings.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User opens Add Resource dropdown] --> B[useWorkspaceSchedules]
    B --> C{Filter sourceType === 'job'}
    C --> D[Show scheduled tasks list]
    D --> E[User selects a scheduled task]
    E --> F[POST /api/copilot/chat/resources\ntype: 'scheduledtask']
    F --> G{copilotResourceTypeSchema\nvalidates 'scheduledtask'}
    G --> H{VALID_RESOURCE_TYPES\ncheck passes}
    H --> I[persistChatResources\nGENERIC_RESOURCE_TITLES dedup]
    I --> J[Resource stored in chat.resources]
    J --> K[Tab rendered via RESOURCE_REGISTRY]
    K --> L[EmbeddedScheduledTask]
    L --> M{useWorkspaceSchedules}
    M -->|isLoading + no data| N[Loading skeleton]
    M -->|isError| O[Error state — Try again]
    M -->|not found| P[Not found state]
    M -->|found| Q[Render status / schedule / runs]
    Q --> R[EmbeddedScheduledTaskActions]
    R --> S[router.push scheduled-tasks page]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User opens Add Resource dropdown] --> B[useWorkspaceSchedules]
    B --> C{Filter sourceType === 'job'}
    C --> D[Show scheduled tasks list]
    D --> E[User selects a scheduled task]
    E --> F[POST /api/copilot/chat/resources\ntype: 'scheduledtask']
    F --> G{copilotResourceTypeSchema\nvalidates 'scheduledtask'}
    G --> H{VALID_RESOURCE_TYPES\ncheck passes}
    H --> I[persistChatResources\nGENERIC_RESOURCE_TITLES dedup]
    I --> J[Resource stored in chat.resources]
    J --> K[Tab rendered via RESOURCE_REGISTRY]
    K --> L[EmbeddedScheduledTask]
    L --> M{useWorkspaceSchedules}
    M -->|isLoading + no data| N[Loading skeleton]
    M -->|isError| O[Error state — Try again]
    M -->|not found| P[Not found state]
    M -->|found| Q[Render status / schedule / runs]
    Q --> R[EmbeddedScheduledTaskActions]
    R --> S[router.push scheduled-tasks page]
Loading

Reviews (3): Last reviewed commit: "feat(chat): wire scheduledtask chat-cont..." | Re-trigger Greptile

…sistence

Dedupes the placeholder-title set that the chat-resource route and the
server-side persistence merge each defined separately. They had already
drifted ('Log' was missing from persistence); a single shared
GENERIC_RESOURCE_TITLES keeps title-upgrade behavior consistent, including
the new 'Scheduled Task' placeholder.
…task viewer

- Render a 'couldn't load' state when the schedules query errors, instead of
  falsely claiming the task was deleted (uses React Query isError)
- Use a stable composite key for jobHistory rows so same-second timestamps
  don't collide
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e494b22. Configure here.

Adds a first-class 'scheduledtask' ChatContext kind so a scheduled-task
resource maps to a real context (not a generic docs fallback), fixing the
exhaustive RESOURCE_TO_CONTEXT map that broke the build:
- ChatContext union + CHAT_CONTEXT_KIND_REGISTRY (Calendar chip)
- resource→context mapping, context validity check, clipboard portability

Agent-side consumption of the kind remains a follow-up.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9c07fd9. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant