stagent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +399 -0
- package/components.json +21 -0
- package/dist/cli.js +171 -0
- package/drizzle.config.ts +12 -0
- package/next.config.mjs +15 -0
- package/package.json +114 -0
- package/postcss.config.mjs +8 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +13 -0
- package/public/readme/home-workspace.png +0 -0
- package/public/readme/inbox-approvals.png +0 -0
- package/public/readme/workflow-blueprints.png +0 -0
- package/public/stagent-s-128.png +0 -0
- package/public/stagent-s-64.png +0 -0
- package/src/app/api/blueprints/[id]/instantiate/route.ts +27 -0
- package/src/app/api/blueprints/[id]/route.ts +39 -0
- package/src/app/api/blueprints/import/route.ts +68 -0
- package/src/app/api/blueprints/route.ts +29 -0
- package/src/app/api/command-palette/recent/route.ts +31 -0
- package/src/app/api/data/clear/route.ts +22 -0
- package/src/app/api/data/seed/route.ts +22 -0
- package/src/app/api/documents/[id]/file/route.ts +44 -0
- package/src/app/api/documents/[id]/route.ts +123 -0
- package/src/app/api/documents/route.ts +59 -0
- package/src/app/api/logs/stream/route.ts +101 -0
- package/src/app/api/notifications/[id]/route.ts +36 -0
- package/src/app/api/notifications/mark-all-read/route.ts +13 -0
- package/src/app/api/notifications/pending-approvals/route.ts +10 -0
- package/src/app/api/notifications/pending-approvals/stream/route.ts +101 -0
- package/src/app/api/notifications/route.ts +34 -0
- package/src/app/api/permissions/route.ts +46 -0
- package/src/app/api/profiles/[id]/route.ts +79 -0
- package/src/app/api/profiles/[id]/test/route.ts +42 -0
- package/src/app/api/profiles/import/route.ts +108 -0
- package/src/app/api/profiles/route.ts +50 -0
- package/src/app/api/projects/[id]/route.ts +72 -0
- package/src/app/api/projects/route.ts +53 -0
- package/src/app/api/schedules/[id]/route.ts +185 -0
- package/src/app/api/schedules/route.ts +117 -0
- package/src/app/api/settings/budgets/route.ts +24 -0
- package/src/app/api/settings/openai/route.ts +24 -0
- package/src/app/api/settings/route.ts +21 -0
- package/src/app/api/settings/test/route.ts +26 -0
- package/src/app/api/tasks/[id]/cancel/route.ts +21 -0
- package/src/app/api/tasks/[id]/execute/route.ts +90 -0
- package/src/app/api/tasks/[id]/logs/route.ts +95 -0
- package/src/app/api/tasks/[id]/output/route.ts +47 -0
- package/src/app/api/tasks/[id]/respond/route.ts +64 -0
- package/src/app/api/tasks/[id]/resume/route.ts +76 -0
- package/src/app/api/tasks/[id]/route.ts +77 -0
- package/src/app/api/tasks/assist/route.ts +35 -0
- package/src/app/api/tasks/route.ts +82 -0
- package/src/app/api/uploads/[id]/route.ts +81 -0
- package/src/app/api/uploads/cleanup/route.ts +7 -0
- package/src/app/api/uploads/route.ts +66 -0
- package/src/app/api/workflows/[id]/execute/route.ts +82 -0
- package/src/app/api/workflows/[id]/route.ts +133 -0
- package/src/app/api/workflows/[id]/status/route.ts +54 -0
- package/src/app/api/workflows/[id]/steps/[stepId]/retry/route.ts +22 -0
- package/src/app/api/workflows/route.ts +61 -0
- package/src/app/apple-icon.tsx +31 -0
- package/src/app/costs/page.tsx +256 -0
- package/src/app/dashboard/page.tsx +44 -0
- package/src/app/documents/[id]/page.tsx +46 -0
- package/src/app/documents/page.tsx +45 -0
- package/src/app/error.tsx +26 -0
- package/src/app/global-error.tsx +23 -0
- package/src/app/globals.css +733 -0
- package/src/app/icon.tsx +30 -0
- package/src/app/inbox/loading.tsx +15 -0
- package/src/app/inbox/page.tsx +35 -0
- package/src/app/layout.tsx +78 -0
- package/src/app/manifest.ts +32 -0
- package/src/app/monitor/page.tsx +37 -0
- package/src/app/page.tsx +162 -0
- package/src/app/profiles/[id]/edit/page.tsx +39 -0
- package/src/app/profiles/[id]/page.tsx +33 -0
- package/src/app/profiles/new/page.tsx +22 -0
- package/src/app/profiles/page.tsx +19 -0
- package/src/app/projects/[id]/page.tsx +134 -0
- package/src/app/projects/loading.tsx +17 -0
- package/src/app/projects/page.tsx +32 -0
- package/src/app/schedules/[id]/page.tsx +47 -0
- package/src/app/schedules/page.tsx +18 -0
- package/src/app/settings/loading.tsx +24 -0
- package/src/app/settings/page.tsx +27 -0
- package/src/app/tasks/[id]/page.tsx +45 -0
- package/src/app/tasks/new/page.tsx +27 -0
- package/src/app/workflows/[id]/edit/page.tsx +66 -0
- package/src/app/workflows/[id]/page.tsx +37 -0
- package/src/app/workflows/blueprints/[id]/page.tsx +40 -0
- package/src/app/workflows/blueprints/new/page.tsx +20 -0
- package/src/app/workflows/blueprints/page.tsx +11 -0
- package/src/app/workflows/new/page.tsx +36 -0
- package/src/app/workflows/page.tsx +18 -0
- package/src/components/charts/donut-ring.tsx +64 -0
- package/src/components/charts/mini-bar.tsx +75 -0
- package/src/components/charts/sparkline.tsx +107 -0
- package/src/components/costs/cost-dashboard.tsx +877 -0
- package/src/components/costs/cost-filters.tsx +179 -0
- package/src/components/dashboard/activity-feed.tsx +95 -0
- package/src/components/dashboard/greeting.tsx +30 -0
- package/src/components/dashboard/priority-queue.tsx +79 -0
- package/src/components/dashboard/quick-actions.tsx +62 -0
- package/src/components/dashboard/recent-projects.tsx +79 -0
- package/src/components/dashboard/stats-cards.tsx +114 -0
- package/src/components/documents/document-browser.tsx +235 -0
- package/src/components/documents/document-detail-view.tsx +367 -0
- package/src/components/documents/document-grid.tsx +78 -0
- package/src/components/documents/document-preview.tsx +68 -0
- package/src/components/documents/document-table.tsx +119 -0
- package/src/components/documents/document-upload-dialog.tsx +153 -0
- package/src/components/documents/types.ts +6 -0
- package/src/components/documents/utils.ts +57 -0
- package/src/components/monitoring/connection-indicator.tsx +14 -0
- package/src/components/monitoring/log-entry.tsx +79 -0
- package/src/components/monitoring/log-filters.tsx +57 -0
- package/src/components/monitoring/log-stream.tsx +144 -0
- package/src/components/monitoring/monitor-overview-wrapper.tsx +64 -0
- package/src/components/monitoring/monitor-overview.tsx +119 -0
- package/src/components/notifications/failure-action.tsx +38 -0
- package/src/components/notifications/inbox-list.tsx +165 -0
- package/src/components/notifications/message-response.tsx +196 -0
- package/src/components/notifications/notification-item.tsx +250 -0
- package/src/components/notifications/pending-approval-host.tsx +478 -0
- package/src/components/notifications/permission-action.tsx +37 -0
- package/src/components/notifications/permission-response-actions.tsx +126 -0
- package/src/components/notifications/unread-badge.tsx +35 -0
- package/src/components/profiles/profile-browser.tsx +117 -0
- package/src/components/profiles/profile-card.tsx +78 -0
- package/src/components/profiles/profile-detail-view.tsx +564 -0
- package/src/components/profiles/profile-form-view.tsx +480 -0
- package/src/components/profiles/profile-import-dialog.tsx +113 -0
- package/src/components/projects/project-card.tsx +58 -0
- package/src/components/projects/project-create-dialog.tsx +140 -0
- package/src/components/projects/project-detail.tsx +68 -0
- package/src/components/projects/project-edit-dialog.tsx +219 -0
- package/src/components/projects/project-list.tsx +108 -0
- package/src/components/schedules/schedule-create-dialog.tsx +403 -0
- package/src/components/schedules/schedule-detail-view.tsx +274 -0
- package/src/components/schedules/schedule-list.tsx +242 -0
- package/src/components/schedules/schedule-status-badge.tsx +16 -0
- package/src/components/settings/api-key-form.tsx +141 -0
- package/src/components/settings/auth-config-section.tsx +141 -0
- package/src/components/settings/auth-method-selector.tsx +67 -0
- package/src/components/settings/auth-status-badge.tsx +40 -0
- package/src/components/settings/auth-status-dot.tsx +59 -0
- package/src/components/settings/budget-guardrails-section.tsx +842 -0
- package/src/components/settings/data-management-section.tsx +141 -0
- package/src/components/settings/openai-runtime-section.tsx +104 -0
- package/src/components/settings/permissions-section.tsx +91 -0
- package/src/components/shared/app-sidebar.tsx +123 -0
- package/src/components/shared/card-skeleton.tsx +42 -0
- package/src/components/shared/command-palette.tsx +250 -0
- package/src/components/shared/confirm-dialog.tsx +52 -0
- package/src/components/shared/empty-state.tsx +24 -0
- package/src/components/shared/error-state.tsx +32 -0
- package/src/components/shared/form-section-card.tsx +33 -0
- package/src/components/shared/section-heading.tsx +14 -0
- package/src/components/shared/stagent-logo.tsx +21 -0
- package/src/components/shared/theme-toggle.tsx +46 -0
- package/src/components/tasks/ai-assist-panel.tsx +210 -0
- package/src/components/tasks/content-preview.tsx +89 -0
- package/src/components/tasks/empty-board.tsx +12 -0
- package/src/components/tasks/file-upload.tsx +120 -0
- package/src/components/tasks/kanban-board.tsx +275 -0
- package/src/components/tasks/kanban-column.tsx +75 -0
- package/src/components/tasks/skeleton-board.tsx +21 -0
- package/src/components/tasks/task-attachments.tsx +114 -0
- package/src/components/tasks/task-card.tsx +101 -0
- package/src/components/tasks/task-create-panel.tsx +360 -0
- package/src/components/tasks/task-detail-view.tsx +356 -0
- package/src/components/ui/alert-dialog.tsx +196 -0
- package/src/components/ui/badge.tsx +50 -0
- package/src/components/ui/button.tsx +71 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/command.tsx +184 -0
- package/src/components/ui/dialog.tsx +158 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/form.tsx +167 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/popover.tsx +89 -0
- package/src/components/ui/progress.tsx +31 -0
- package/src/components/ui/radio-group.tsx +45 -0
- package/src/components/ui/scroll-area.tsx +58 -0
- package/src/components/ui/select.tsx +190 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/sheet.tsx +143 -0
- package/src/components/ui/sidebar.tsx +726 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +63 -0
- package/src/components/ui/sonner.tsx +36 -0
- package/src/components/ui/switch.tsx +35 -0
- package/src/components/ui/table.tsx +116 -0
- package/src/components/ui/tabs.tsx +91 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +57 -0
- package/src/components/workflows/blueprint-editor.tsx +109 -0
- package/src/components/workflows/blueprint-gallery.tsx +155 -0
- package/src/components/workflows/blueprint-preview.tsx +240 -0
- package/src/components/workflows/loop-status-view.tsx +272 -0
- package/src/components/workflows/swarm-dashboard.tsx +185 -0
- package/src/components/workflows/workflow-form-view.tsx +1376 -0
- package/src/components/workflows/workflow-list.tsx +230 -0
- package/src/components/workflows/workflow-status-view.tsx +477 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/instrumentation.ts +7 -0
- package/src/lib/agents/claude-agent.ts +737 -0
- package/src/lib/agents/execution-manager.ts +27 -0
- package/src/lib/agents/profiles/assignment-validation.ts +75 -0
- package/src/lib/agents/profiles/builtins/code-reviewer/SKILL.md +21 -0
- package/src/lib/agents/profiles/builtins/code-reviewer/profile.yaml +28 -0
- package/src/lib/agents/profiles/builtins/data-analyst/SKILL.md +25 -0
- package/src/lib/agents/profiles/builtins/data-analyst/profile.yaml +27 -0
- package/src/lib/agents/profiles/builtins/devops-engineer/SKILL.md +34 -0
- package/src/lib/agents/profiles/builtins/devops-engineer/profile.yaml +27 -0
- package/src/lib/agents/profiles/builtins/document-writer/SKILL.md +16 -0
- package/src/lib/agents/profiles/builtins/document-writer/profile.yaml +27 -0
- package/src/lib/agents/profiles/builtins/general/SKILL.md +13 -0
- package/src/lib/agents/profiles/builtins/general/profile.yaml +18 -0
- package/src/lib/agents/profiles/builtins/health-fitness-coach/SKILL.md +34 -0
- package/src/lib/agents/profiles/builtins/health-fitness-coach/profile.yaml +26 -0
- package/src/lib/agents/profiles/builtins/learning-coach/SKILL.md +35 -0
- package/src/lib/agents/profiles/builtins/learning-coach/profile.yaml +26 -0
- package/src/lib/agents/profiles/builtins/project-manager/SKILL.md +26 -0
- package/src/lib/agents/profiles/builtins/project-manager/profile.yaml +26 -0
- package/src/lib/agents/profiles/builtins/researcher/SKILL.md +15 -0
- package/src/lib/agents/profiles/builtins/researcher/profile.yaml +27 -0
- package/src/lib/agents/profiles/builtins/shopping-assistant/SKILL.md +34 -0
- package/src/lib/agents/profiles/builtins/shopping-assistant/profile.yaml +26 -0
- package/src/lib/agents/profiles/builtins/technical-writer/SKILL.md +31 -0
- package/src/lib/agents/profiles/builtins/technical-writer/profile.yaml +29 -0
- package/src/lib/agents/profiles/builtins/travel-planner/SKILL.md +23 -0
- package/src/lib/agents/profiles/builtins/travel-planner/profile.yaml +26 -0
- package/src/lib/agents/profiles/builtins/wealth-manager/SKILL.md +24 -0
- package/src/lib/agents/profiles/builtins/wealth-manager/profile.yaml +26 -0
- package/src/lib/agents/profiles/compatibility.ts +109 -0
- package/src/lib/agents/profiles/registry.ts +293 -0
- package/src/lib/agents/profiles/test-runner.ts +18 -0
- package/src/lib/agents/profiles/test-types.ts +20 -0
- package/src/lib/agents/profiles/types.ts +43 -0
- package/src/lib/agents/router.ts +56 -0
- package/src/lib/agents/runtime/catalog.ts +85 -0
- package/src/lib/agents/runtime/claude-sdk.ts +12 -0
- package/src/lib/agents/runtime/claude.ts +370 -0
- package/src/lib/agents/runtime/codex-app-server-client.ts +289 -0
- package/src/lib/agents/runtime/index.ts +167 -0
- package/src/lib/agents/runtime/openai-codex.ts +1089 -0
- package/src/lib/agents/runtime/task-assist-types.ts +8 -0
- package/src/lib/agents/runtime/types.ts +30 -0
- package/src/lib/constants/settings.ts +13 -0
- package/src/lib/constants/status-colors.ts +44 -0
- package/src/lib/constants/task-status.ts +49 -0
- package/src/lib/data/clear.ts +63 -0
- package/src/lib/data/seed-data/documents.ts +715 -0
- package/src/lib/data/seed-data/logs.ts +195 -0
- package/src/lib/data/seed-data/notifications.ts +141 -0
- package/src/lib/data/seed-data/profiles.ts +175 -0
- package/src/lib/data/seed-data/projects.ts +61 -0
- package/src/lib/data/seed-data/schedules.ts +108 -0
- package/src/lib/data/seed-data/tasks.ts +341 -0
- package/src/lib/data/seed-data/usage-ledger.ts +130 -0
- package/src/lib/data/seed-data/workflows.ts +213 -0
- package/src/lib/data/seed.ts +129 -0
- package/src/lib/db/index.ts +221 -0
- package/src/lib/db/migrations/0000_aromatic_gargoyle.sql +59 -0
- package/src/lib/db/migrations/0001_first_iron_patriot.sql +6 -0
- package/src/lib/db/migrations/0002_add_resume_count.sql +1 -0
- package/src/lib/db/migrations/0003_add_settings.sql +5 -0
- package/src/lib/db/migrations/0004_add_documents.sql +20 -0
- package/src/lib/db/migrations/0005_add_document_preprocessing.sql +4 -0
- package/src/lib/db/migrations/0006_add_agent_profile.sql +2 -0
- package/src/lib/db/migrations/0007_add_usage_metering_ledger.sql +30 -0
- package/src/lib/db/migrations/0008_add_document_version.sql +1 -0
- package/src/lib/db/migrations/meta/0000_snapshot.json +416 -0
- package/src/lib/db/migrations/meta/0001_snapshot.json +461 -0
- package/src/lib/db/migrations/meta/0002_snapshot.json +469 -0
- package/src/lib/db/migrations/meta/_journal.json +27 -0
- package/src/lib/db/schema.ts +227 -0
- package/src/lib/documents/cleanup.ts +50 -0
- package/src/lib/documents/context-builder.ts +75 -0
- package/src/lib/documents/output-scanner.ts +166 -0
- package/src/lib/documents/processor.ts +120 -0
- package/src/lib/documents/processors/image.ts +21 -0
- package/src/lib/documents/processors/office.ts +36 -0
- package/src/lib/documents/processors/pdf.ts +12 -0
- package/src/lib/documents/processors/spreadsheet.ts +18 -0
- package/src/lib/documents/processors/text.ts +8 -0
- package/src/lib/documents/registry.ts +25 -0
- package/src/lib/notifications/actionable.ts +108 -0
- package/src/lib/notifications/permissions.ts +169 -0
- package/src/lib/queries/chart-data.ts +184 -0
- package/src/lib/schedules/interval-parser.ts +110 -0
- package/src/lib/schedules/scheduler.ts +220 -0
- package/src/lib/settings/auth.ts +98 -0
- package/src/lib/settings/budget-guardrails.ts +590 -0
- package/src/lib/settings/helpers.ts +23 -0
- package/src/lib/settings/openai-auth.ts +80 -0
- package/src/lib/settings/permissions.ts +102 -0
- package/src/lib/usage/ledger.ts +489 -0
- package/src/lib/usage/pricing.ts +68 -0
- package/src/lib/utils/crypto.ts +90 -0
- package/src/lib/utils/format-timestamp.ts +46 -0
- package/src/lib/utils/session-cleanup.ts +26 -0
- package/src/lib/utils/stagent-paths.ts +18 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validators/blueprint.ts +43 -0
- package/src/lib/validators/profile.ts +64 -0
- package/src/lib/validators/project.ts +17 -0
- package/src/lib/validators/settings.ts +57 -0
- package/src/lib/validators/task.ts +30 -0
- package/src/lib/workflows/blueprints/builtins/code-review-pipeline.yaml +72 -0
- package/src/lib/workflows/blueprints/builtins/documentation-generation.yaml +62 -0
- package/src/lib/workflows/blueprints/builtins/investment-research.yaml +81 -0
- package/src/lib/workflows/blueprints/builtins/meal-planning.yaml +73 -0
- package/src/lib/workflows/blueprints/builtins/product-research.yaml +72 -0
- package/src/lib/workflows/blueprints/builtins/research-report.yaml +77 -0
- package/src/lib/workflows/blueprints/builtins/sprint-planning.yaml +77 -0
- package/src/lib/workflows/blueprints/builtins/travel-planning.yaml +80 -0
- package/src/lib/workflows/blueprints/instantiator.ts +131 -0
- package/src/lib/workflows/blueprints/registry.ts +128 -0
- package/src/lib/workflows/blueprints/template.ts +58 -0
- package/src/lib/workflows/blueprints/types.ts +38 -0
- package/src/lib/workflows/definition-validation.ts +121 -0
- package/src/lib/workflows/engine.ts +1113 -0
- package/src/lib/workflows/loop-executor.ts +270 -0
- package/src/lib/workflows/parallel.ts +55 -0
- package/src/lib/workflows/swarm.ts +97 -0
- package/src/lib/workflows/types.ts +112 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import { Input } from "@/components/ui/input";
|
|
6
|
+
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
|
7
|
+
import { Label } from "@/components/ui/label";
|
|
8
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
9
|
+
import { Send } from "lucide-react";
|
|
10
|
+
|
|
11
|
+
export interface Question {
|
|
12
|
+
id?: string;
|
|
13
|
+
question: string;
|
|
14
|
+
header: string;
|
|
15
|
+
options?: { label: string; description: string }[];
|
|
16
|
+
multiSelect?: boolean;
|
|
17
|
+
isSecret?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface MessageResponseProps {
|
|
21
|
+
taskId: string;
|
|
22
|
+
notificationId: string;
|
|
23
|
+
toolInput: { questions: Question[] };
|
|
24
|
+
responded: boolean;
|
|
25
|
+
response: string | null;
|
|
26
|
+
onResponded: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function MessageResponse({
|
|
30
|
+
taskId,
|
|
31
|
+
notificationId,
|
|
32
|
+
toolInput,
|
|
33
|
+
responded,
|
|
34
|
+
response,
|
|
35
|
+
onResponded,
|
|
36
|
+
}: MessageResponseProps) {
|
|
37
|
+
const [answers, setAnswers] = useState<Record<string, string>>({});
|
|
38
|
+
const [otherTexts, setOtherTexts] = useState<Record<string, string>>({});
|
|
39
|
+
const [loading, setLoading] = useState(false);
|
|
40
|
+
|
|
41
|
+
if (responded && response) {
|
|
42
|
+
return (
|
|
43
|
+
<span className="text-xs text-muted-foreground">Response sent</span>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const questions = toolInput?.questions ?? [];
|
|
48
|
+
|
|
49
|
+
function getAnswerKey(question: Question) {
|
|
50
|
+
return question.id ?? question.question;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function handleSingleSelect(questionKey: string, label: string) {
|
|
54
|
+
setAnswers((prev) => ({ ...prev, [questionKey]: label }));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleMultiSelect(
|
|
58
|
+
questionKey: string,
|
|
59
|
+
label: string,
|
|
60
|
+
checked: boolean
|
|
61
|
+
) {
|
|
62
|
+
setAnswers((prev) => {
|
|
63
|
+
const current = prev[questionKey] ? prev[questionKey].split(", ") : [];
|
|
64
|
+
const next = checked
|
|
65
|
+
? [...current, label]
|
|
66
|
+
: current.filter((l) => l !== label);
|
|
67
|
+
return { ...prev, [questionKey]: next.join(", ") };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function handleSend() {
|
|
72
|
+
setLoading(true);
|
|
73
|
+
// Merge in "Other" text where applicable
|
|
74
|
+
const finalAnswers: Record<string, string> = {};
|
|
75
|
+
for (const q of questions) {
|
|
76
|
+
const questionKey = getAnswerKey(q);
|
|
77
|
+
const answer = answers[questionKey] ?? "";
|
|
78
|
+
if (answer === "__other__") {
|
|
79
|
+
finalAnswers[questionKey] = otherTexts[questionKey] ?? "";
|
|
80
|
+
} else {
|
|
81
|
+
finalAnswers[questionKey] = answer;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await fetch(`/api/tasks/${taskId}/respond`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "Content-Type": "application/json" },
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
notificationId,
|
|
91
|
+
behavior: "allow",
|
|
92
|
+
updatedInput: {
|
|
93
|
+
questions: toolInput.questions,
|
|
94
|
+
answers: finalAnswers,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
onResponded();
|
|
99
|
+
} finally {
|
|
100
|
+
setLoading(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div className="space-y-4 mt-2">
|
|
106
|
+
{questions.map((q) => (
|
|
107
|
+
<div key={getAnswerKey(q)} className="space-y-2">
|
|
108
|
+
<p className="text-sm font-medium">{q.question}</p>
|
|
109
|
+
{(q.multiSelect ?? false) ? (
|
|
110
|
+
<div className="space-y-2">
|
|
111
|
+
{(q.options ?? []).map((opt) => (
|
|
112
|
+
<div key={opt.label} className="flex items-center gap-2">
|
|
113
|
+
<Checkbox
|
|
114
|
+
id={`${getAnswerKey(q)}-${opt.label}`}
|
|
115
|
+
onCheckedChange={(checked) =>
|
|
116
|
+
handleMultiSelect(getAnswerKey(q), opt.label, checked as boolean)
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
119
|
+
<Label
|
|
120
|
+
htmlFor={`${getAnswerKey(q)}-${opt.label}`}
|
|
121
|
+
className="text-sm"
|
|
122
|
+
>
|
|
123
|
+
{opt.label}
|
|
124
|
+
<span className="text-muted-foreground ml-1">
|
|
125
|
+
— {opt.description}
|
|
126
|
+
</span>
|
|
127
|
+
</Label>
|
|
128
|
+
</div>
|
|
129
|
+
))}
|
|
130
|
+
</div>
|
|
131
|
+
) : (q.options ?? []).length === 0 ? (
|
|
132
|
+
<Input
|
|
133
|
+
type={q.isSecret ? "password" : "text"}
|
|
134
|
+
value={answers[getAnswerKey(q)] ?? ""}
|
|
135
|
+
onChange={(e) =>
|
|
136
|
+
setAnswers((prev) => ({
|
|
137
|
+
...prev,
|
|
138
|
+
[getAnswerKey(q)]: e.target.value,
|
|
139
|
+
}))
|
|
140
|
+
}
|
|
141
|
+
placeholder="Type your answer"
|
|
142
|
+
className="h-8 text-sm"
|
|
143
|
+
/>
|
|
144
|
+
) : (
|
|
145
|
+
<RadioGroup
|
|
146
|
+
value={answers[getAnswerKey(q)] ?? ""}
|
|
147
|
+
onValueChange={(val) => handleSingleSelect(getAnswerKey(q), val)}
|
|
148
|
+
>
|
|
149
|
+
{(q.options ?? []).map((opt) => (
|
|
150
|
+
<div key={opt.label} className="flex items-center gap-2">
|
|
151
|
+
<RadioGroupItem
|
|
152
|
+
value={opt.label}
|
|
153
|
+
id={`${getAnswerKey(q)}-${opt.label}`}
|
|
154
|
+
/>
|
|
155
|
+
<Label
|
|
156
|
+
htmlFor={`${getAnswerKey(q)}-${opt.label}`}
|
|
157
|
+
className="text-sm"
|
|
158
|
+
>
|
|
159
|
+
{opt.label}
|
|
160
|
+
<span className="text-muted-foreground ml-1">
|
|
161
|
+
— {opt.description}
|
|
162
|
+
</span>
|
|
163
|
+
</Label>
|
|
164
|
+
</div>
|
|
165
|
+
))}
|
|
166
|
+
<div className="flex items-center gap-2">
|
|
167
|
+
<RadioGroupItem value="__other__" id={`${getAnswerKey(q)}-other`} />
|
|
168
|
+
<Label htmlFor={`${getAnswerKey(q)}-other`} className="text-sm">
|
|
169
|
+
Other
|
|
170
|
+
</Label>
|
|
171
|
+
{answers[getAnswerKey(q)] === "__other__" && (
|
|
172
|
+
<Input
|
|
173
|
+
type={q.isSecret ? "password" : "text"}
|
|
174
|
+
value={otherTexts[getAnswerKey(q)] ?? ""}
|
|
175
|
+
onChange={(e) =>
|
|
176
|
+
setOtherTexts((prev) => ({
|
|
177
|
+
...prev,
|
|
178
|
+
[getAnswerKey(q)]: e.target.value,
|
|
179
|
+
}))
|
|
180
|
+
}
|
|
181
|
+
placeholder="Type your answer"
|
|
182
|
+
className="h-7 text-sm"
|
|
183
|
+
/>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
</RadioGroup>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
))}
|
|
190
|
+
<Button size="sm" onClick={handleSend} disabled={loading}>
|
|
191
|
+
<Send className="h-3.5 w-3.5 mr-1" />
|
|
192
|
+
Send
|
|
193
|
+
</Button>
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Badge } from "@/components/ui/badge";
|
|
4
|
+
import { Card } from "@/components/ui/card";
|
|
5
|
+
import { Shield, MessageCircle, CheckCircle, XCircle, Eye, EyeOff, Trash2, Wallet } from "lucide-react";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { PermissionAction } from "./permission-action";
|
|
9
|
+
import { MessageResponse, type Question } from "./message-response";
|
|
10
|
+
import { FailureAction } from "./failure-action";
|
|
11
|
+
import { formatTimestamp } from "@/lib/utils/format-timestamp";
|
|
12
|
+
import {
|
|
13
|
+
buildPermissionSummary,
|
|
14
|
+
parseNotificationToolInput,
|
|
15
|
+
type PermissionToolInput,
|
|
16
|
+
} from "@/lib/notifications/permissions";
|
|
17
|
+
|
|
18
|
+
interface Notification {
|
|
19
|
+
id: string;
|
|
20
|
+
taskId: string | null;
|
|
21
|
+
type: string;
|
|
22
|
+
title: string;
|
|
23
|
+
body: string | null;
|
|
24
|
+
read: boolean;
|
|
25
|
+
toolName: string | null;
|
|
26
|
+
toolInput: string | null;
|
|
27
|
+
response: string | null;
|
|
28
|
+
respondedAt: string | null;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface NotificationItemProps {
|
|
33
|
+
notification: Notification;
|
|
34
|
+
onUpdated: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const typeIcons: Record<string, React.ReactNode> = {
|
|
38
|
+
permission_required: <Shield className="h-4 w-4 text-chart-5" aria-hidden="true" />,
|
|
39
|
+
agent_message: <MessageCircle className="h-4 w-4 text-primary" aria-hidden="true" />,
|
|
40
|
+
task_completed: <CheckCircle className="h-4 w-4 text-chart-2" aria-hidden="true" />,
|
|
41
|
+
task_failed: <XCircle className="h-4 w-4 text-destructive" aria-hidden="true" />,
|
|
42
|
+
budget_alert: <Wallet className="h-4 w-4 text-status-warning" aria-hidden="true" />,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const typeLabels: Record<string, string> = {
|
|
46
|
+
permission_required: "Permission required",
|
|
47
|
+
agent_message: "Agent message",
|
|
48
|
+
task_completed: "Task completed",
|
|
49
|
+
task_failed: "Task failed",
|
|
50
|
+
budget_alert: "Budget alert",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function formatToolInput(
|
|
54
|
+
toolName: string | null,
|
|
55
|
+
input: PermissionToolInput
|
|
56
|
+
): React.ReactNode {
|
|
57
|
+
// AskUserQuestion — show the question text directly
|
|
58
|
+
if (toolName === "AskUserQuestion" || toolName === "ask_user_question") {
|
|
59
|
+
const question = input.question ?? input.text ?? input.message;
|
|
60
|
+
if (typeof question === "string") {
|
|
61
|
+
return <p>{question}</p>;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Bash/shell — show the command
|
|
66
|
+
if (toolName === "Bash" || toolName === "bash") {
|
|
67
|
+
const cmd = input.command ?? input.cmd;
|
|
68
|
+
if (typeof cmd === "string") {
|
|
69
|
+
return <code className="text-xs font-mono break-all">{cmd}</code>;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Read/Write — show the file path
|
|
74
|
+
if (toolName === "Read" || toolName === "Write" || toolName === "Edit") {
|
|
75
|
+
const path = input.file_path ?? input.path;
|
|
76
|
+
if (typeof path === "string") {
|
|
77
|
+
return <span>File: <code className="text-xs font-mono">{path}</code></span>;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Fallback: show key-value pairs in a readable format
|
|
82
|
+
const entries = Object.entries(input).slice(0, 4);
|
|
83
|
+
if (entries.length === 0) return null;
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<dl className="text-xs space-y-0.5">
|
|
87
|
+
{entries.map(([key, val]) => (
|
|
88
|
+
<div key={key} className="flex gap-2">
|
|
89
|
+
<dt className="font-medium shrink-0">{key}:</dt>
|
|
90
|
+
<dd className="truncate">{typeof val === "string" ? val : JSON.stringify(val)}</dd>
|
|
91
|
+
</div>
|
|
92
|
+
))}
|
|
93
|
+
</dl>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function NotificationItem({ notification, onUpdated }: NotificationItemProps) {
|
|
98
|
+
const [toggling, setToggling] = useState(false);
|
|
99
|
+
const [dismissing, setDismissing] = useState(false);
|
|
100
|
+
const isUnread = !notification.read;
|
|
101
|
+
const hasResponse = !!notification.response;
|
|
102
|
+
const parsedToolInput = parseNotificationToolInput(notification.toolInput);
|
|
103
|
+
|
|
104
|
+
async function toggleRead() {
|
|
105
|
+
setToggling(true);
|
|
106
|
+
try {
|
|
107
|
+
await fetch(`/api/notifications/${notification.id}`, {
|
|
108
|
+
method: "PATCH",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: JSON.stringify({ read: !notification.read }),
|
|
111
|
+
});
|
|
112
|
+
onUpdated();
|
|
113
|
+
} finally {
|
|
114
|
+
setToggling(false);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function dismiss() {
|
|
119
|
+
setDismissing(true);
|
|
120
|
+
try {
|
|
121
|
+
await fetch(`/api/notifications/${notification.id}`, {
|
|
122
|
+
method: "DELETE",
|
|
123
|
+
});
|
|
124
|
+
onUpdated();
|
|
125
|
+
} finally {
|
|
126
|
+
setDismissing(false);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<Card
|
|
132
|
+
className={`p-4 ${
|
|
133
|
+
isUnread
|
|
134
|
+
? "surface-card border-l-4 border-l-primary"
|
|
135
|
+
: "surface-card-muted"
|
|
136
|
+
}`}
|
|
137
|
+
role="article"
|
|
138
|
+
aria-label={`${typeLabels[notification.type] ?? "Notification"}: ${notification.title}${isUnread ? " (unread)" : ""}`}
|
|
139
|
+
>
|
|
140
|
+
<div className="flex items-start gap-3">
|
|
141
|
+
<div className="mt-0.5">{typeIcons[notification.type]}</div>
|
|
142
|
+
<div className="flex-1 min-w-0">
|
|
143
|
+
<div className="flex items-center gap-2 mb-1">
|
|
144
|
+
<h4
|
|
145
|
+
className={`text-sm ${isUnread ? "font-semibold" : "font-normal"}`}
|
|
146
|
+
>
|
|
147
|
+
{notification.title}
|
|
148
|
+
</h4>
|
|
149
|
+
{hasResponse && (
|
|
150
|
+
<Badge variant="secondary" className="text-xs">
|
|
151
|
+
Responded
|
|
152
|
+
</Badge>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
{/* Tool name for permission requests */}
|
|
157
|
+
{notification.type === "permission_required" && notification.toolName && (
|
|
158
|
+
<div className="mb-2">
|
|
159
|
+
<Badge variant="outline" className="text-xs font-mono">
|
|
160
|
+
{notification.toolName}
|
|
161
|
+
</Badge>
|
|
162
|
+
{parsedToolInput && (
|
|
163
|
+
<div className="text-sm text-muted-foreground bg-muted/60 p-2 rounded mt-1">
|
|
164
|
+
<p className="mb-1 font-medium text-foreground">
|
|
165
|
+
{buildPermissionSummary(notification.toolName, parsedToolInput)}
|
|
166
|
+
</p>
|
|
167
|
+
{formatToolInput(notification.toolName, parsedToolInput)}
|
|
168
|
+
</div>
|
|
169
|
+
)}
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
|
|
173
|
+
{/* Body for non-tool notifications */}
|
|
174
|
+
{notification.body &&
|
|
175
|
+
notification.type !== "permission_required" &&
|
|
176
|
+
notification.type !== "agent_message" && (
|
|
177
|
+
<p className="text-sm text-muted-foreground line-clamp-3">
|
|
178
|
+
{notification.body}
|
|
179
|
+
</p>
|
|
180
|
+
)}
|
|
181
|
+
|
|
182
|
+
{/* Actions based on type */}
|
|
183
|
+
{notification.type === "permission_required" &&
|
|
184
|
+
notification.taskId &&
|
|
185
|
+
parsedToolInput && (
|
|
186
|
+
<PermissionAction
|
|
187
|
+
taskId={notification.taskId}
|
|
188
|
+
notificationId={notification.id}
|
|
189
|
+
toolName={notification.toolName ?? ""}
|
|
190
|
+
toolInput={parsedToolInput}
|
|
191
|
+
responded={hasResponse}
|
|
192
|
+
response={notification.response}
|
|
193
|
+
onResponded={onUpdated}
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
|
|
197
|
+
{notification.type === "agent_message" &&
|
|
198
|
+
notification.taskId &&
|
|
199
|
+
parsedToolInput && (
|
|
200
|
+
<MessageResponse
|
|
201
|
+
taskId={notification.taskId}
|
|
202
|
+
notificationId={notification.id}
|
|
203
|
+
toolInput={parsedToolInput as { questions: Question[] }}
|
|
204
|
+
responded={hasResponse}
|
|
205
|
+
response={notification.response}
|
|
206
|
+
onResponded={onUpdated}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
209
|
+
|
|
210
|
+
{notification.type === "task_failed" && notification.taskId && (
|
|
211
|
+
<FailureAction taskId={notification.taskId} onRetried={onUpdated} />
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
<p className="text-xs text-muted-foreground mt-2">
|
|
215
|
+
{formatTimestamp(notification.createdAt)}
|
|
216
|
+
{notification.respondedAt && (
|
|
217
|
+
<span>
|
|
218
|
+
{" "}
|
|
219
|
+
· Responded{" "}
|
|
220
|
+
{formatTimestamp(notification.respondedAt)}
|
|
221
|
+
</span>
|
|
222
|
+
)}
|
|
223
|
+
</p>
|
|
224
|
+
</div>
|
|
225
|
+
<div className="flex flex-col gap-1 shrink-0">
|
|
226
|
+
<Button
|
|
227
|
+
variant="ghost"
|
|
228
|
+
size="icon"
|
|
229
|
+
className="h-8 w-8"
|
|
230
|
+
onClick={toggleRead}
|
|
231
|
+
disabled={toggling}
|
|
232
|
+
aria-label={isUnread ? "Mark as read" : "Mark as unread"}
|
|
233
|
+
>
|
|
234
|
+
{isUnread ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
|
235
|
+
</Button>
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="icon"
|
|
239
|
+
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
|
240
|
+
onClick={dismiss}
|
|
241
|
+
disabled={dismissing}
|
|
242
|
+
aria-label="Dismiss notification"
|
|
243
|
+
>
|
|
244
|
+
<Trash2 className="h-4 w-4" />
|
|
245
|
+
</Button>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
</Card>
|
|
249
|
+
);
|
|
250
|
+
}
|