diff --git a/bun.lock b/bun.lock index 719082aa..3549fdf9 100644 --- a/bun.lock +++ b/bun.lock @@ -248,6 +248,7 @@ "sonner": "2.0.7", "tailwind-merge": "2.6.1", "tailwindcss-animate": "1.0.7", + "ulid": "3.0.2", "use-image": "1.1.4", "vaul": "1.1.2", "video.js": "8.23.7", @@ -280,6 +281,7 @@ "@temporalio/client": "1.17.2", "@temporalio/worker": "1.17.2", "@temporalio/workflow": "1.17.2", + "ulid": "3.0.2", }, }, }, diff --git a/packages/webui/components/fields-manager.tsx b/packages/webui/components/fields-manager.tsx index 901751c2..acded80d 100644 --- a/packages/webui/components/fields-manager.tsx +++ b/packages/webui/components/fields-manager.tsx @@ -1,9 +1,15 @@ -import { FieldType, type FieldInfo, type FieldInfo as MetadataFieldInfo } from '@shumai/dtos' +import { + FieldType, + type FieldInfo, + type FieldInfo as MetadataFieldInfo, + type SelectOption, +} from '@shumai/dtos' +import { ulid } from 'ulid' import { client } from '@/ui/api/client' import { useFieldStore } from '@/ui/stores/fields' import { DragDropProvider, KeyboardSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/react' import { useSortable } from '@dnd-kit/react/sortable' -import { useMutation } from '@tanstack/react-query' +import { useMutation, useQueryClient } from '@tanstack/react-query' import { InferRequestType, InferResponseType } from 'hono/client' import { Button } from '@/ui/components/ui/button' @@ -13,13 +19,86 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from '@/ui/components/ui/dropdown-menu' +import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' import { Switch } from '@/ui/components/ui/switch' import { arrayMove } from '@/ui/lib/dnd-utils' import { PointerActivationConstraints } from '@dnd-kit/dom' -import { ChevronDown, GripVertical, Plus, Search, Settings, Sparkles } from 'lucide-react' -import { useMemo, useState } from 'react' + +export const PREDEFINED_COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'gray'] + +export const COLOR_MAP: Record = { + red: { bg: 'rgba(239, 68, 68, 0.15)', text: '#ef4444', hex: '#ef4444' }, + orange: { bg: 'rgba(249, 115, 22, 0.15)', text: '#f97316', hex: '#f97316' }, + yellow: { bg: 'rgba(234, 179, 8, 0.15)', text: '#ca8a04', hex: '#eab308' }, + green: { bg: 'rgba(34, 197, 94, 0.15)', text: '#16a34a', hex: '#22c55e' }, + blue: { bg: 'rgba(59, 130, 246, 0.15)', text: '#2563eb', hex: '#3b82f6' }, + purple: { bg: 'rgba(168, 85, 247, 0.15)', text: '#9333ea', hex: '#a855f7' }, + gray: { bg: 'rgba(128, 128, 128, 0.15)', text: '#4b5563', hex: '#808080' }, + system: { bg: 'rgba(128, 128, 128, 0.1)', text: '#6b7280', hex: '#808080' }, +} + +export function getOptionStyle(color?: string) { + if (!color) { + return { + backgroundColor: 'rgba(128, 128, 128, 0.1)', + color: '#6b7280', + } + } + + const normalized = color.toLowerCase() + const mapped = COLOR_MAP[normalized] + if (mapped) { + return { + backgroundColor: mapped.bg, + color: mapped.text, + } + } + + // Support hex colors (e.g. for existing custom fields) + if (color.startsWith('#')) { + return { + backgroundColor: `${color}33`, + color: color, + } + } + + // Fallback + return { + backgroundColor: 'rgba(128, 128, 128, 0.1)', + color: color, + } +} +import { + AlignLeft, + Calendar, + ChevronDown, + GripVertical, + Hash, + List, + Plus, + Search, + Settings, + Sparkles, + Star, + Tags, + ToggleLeft, + Type, + X, +} from 'lucide-react' +import { useMemo, useState, useEffect } from 'react' + +export const FIELD_TYPE_ICONS: Record> = { + [FieldType.text]: Type, + [FieldType.longText]: AlignLeft, + [FieldType.select]: List, + [FieldType.selectMulti]: Tags, + [FieldType.rating]: Star, + [FieldType.number]: Hash, + [FieldType.toggle]: ToggleLeft, + [FieldType.date]: Calendar, +} type SortableFieldItemProps = { field: FieldInfo @@ -33,14 +112,17 @@ function SortableFieldItem({ field, index, onVisibilityChange }: SortableFieldIt index, }) + const Icon = field.config?.type ? FIELD_TYPE_ICONS[field.config.type as FieldType] : null + return (
- {field.aiAutofill && } - {field.config?.name} + {Icon && } + {field.aiAutofill && } + {field.config?.name}
('') const [newAiAutofill, setNewAiAutofill] = useState(false) const [newDescription, setNewDescription] = useState('') + const [newOptions, setNewOptions] = useState([]) + + const queryClient = useQueryClient() + useEffect(() => { + queryClient.invalidateQueries({ queryKey: ['fields', projectId] }) + }, [projectId, queryClient]) const $patchOrder = client.api.projects[':projectId'].fields.order.$patch const { mutate: updateFieldsOrder } = useMutation< @@ -96,6 +184,7 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag const newFieldsList = [...fields, newField] updateFields(newFieldsList) setNewFieldName('') + setNewOptions([]) updateFieldsOrder({ param: { projectId: projectId }, @@ -147,12 +236,19 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag const handleCreateField = () => { if (!newFieldName || !newFieldType) return + const typeConfig = + newFieldType === FieldType.select + ? { select: { options: newOptions } } + : newFieldType === FieldType.selectMulti + ? { selectMulti: { options: newOptions } } + : {} createField({ param: { projectId: projectId }, json: { config: { name: newFieldName, type: newFieldType, + ...typeConfig, }, label: newFieldName, aiAutofill: newAiAutofill, @@ -195,7 +291,10 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag {Object.values(FieldType).map((type) => ( setNewFieldType(type)} + onClick={() => { + setNewFieldType(type) + setNewOptions([]) + }} className="capitalize" > {type.replace(/_/g, ' ')} @@ -220,6 +319,84 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
+ {(newFieldType === FieldType.select || newFieldType === FieldType.selectMulti) && ( +
+
+ + +
+
+ {newOptions.map((opt, idx) => ( +
+ { + const updated = [...newOptions] + updated[idx] = { ...opt, displayName: e.target.value } + setNewOptions(updated) + }} + placeholder="Option name" + className="h-8 flex-1" + /> + + +
+ + + +
+ ))} +
+ + )} +
+ + )} + + {selectedGroup === SCOPE_GROUPS.PROJECT && ( + + )}
- {fields.map((field, index) => ( + {filteredFields.map((field, index) => ( ))} - {fields.length === 0 && ( + {filteredFields.length === 0 && (
No fields found
@@ -585,7 +649,7 @@ export function ManageFieldsDialog({ projectId, open, onOpenChange }: ManageFiel
{/* Right Column: Config */} -
+
{renderConfigEditor()}
{(isCreating || (selectedField && !selectedField.readOnly)) && (
diff --git a/packages/webui/package.json b/packages/webui/package.json index b42e095f..cb5a4da9 100644 --- a/packages/webui/package.json +++ b/packages/webui/package.json @@ -82,7 +82,8 @@ "zod": "4.4.3", "date-fns": "4.4.0", "hono": "4.12.23", - "@shumai/dtos": "workspace:*" + "@shumai/dtos": "workspace:*", + "ulid": "3.0.2" }, "devDependencies": { "@tailwindcss/postcss": "4.3.0", diff --git a/packages/workflow-core/package.json b/packages/workflow-core/package.json index 7a0db689..f8844396 100644 --- a/packages/workflow-core/package.json +++ b/packages/workflow-core/package.json @@ -11,6 +11,7 @@ "@shumai/core": "workspace:*", "@temporalio/client": "1.17.2", "@temporalio/workflow": "1.17.2", - "@temporalio/worker": "1.17.2" + "@temporalio/worker": "1.17.2", + "ulid": "3.0.2" } } diff --git a/packages/workflow-core/src/workflow.ts b/packages/workflow-core/src/workflow.ts index 24881516..f437d72e 100644 --- a/packages/workflow-core/src/workflow.ts +++ b/packages/workflow-core/src/workflow.ts @@ -1,5 +1,6 @@ import { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db' import path from 'path' +import { ulid } from 'ulid' import * as taskActivities from './activities/task' import { Executor } from './executor' import { LocalExecutor } from './local-executor' @@ -73,8 +74,7 @@ export class WorkflowService { const activities = (globalThis as any).__localActivities // For agent_queue and transcode_queue, use worker-specific unique queues - const crypto = await import('crypto') - const workerId = crypto.randomUUID() + const workerId = ulid() const workerSpecificQueue = `${queue}-${workerId}` console.log(`Starting Temporal workers for domain: ${queue}`)