@microvac/plugin-task-routing 0.0.0-stage → 0.1.0-rc.30

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.
@@ -0,0 +1,37 @@
1
+ /** Shapes and pure helpers of the task routing settings panel. */
2
+
3
+ export interface AllowlistEntry {
4
+ model: string;
5
+ effort: string | null;
6
+ whenToUse?: string;
7
+ }
8
+
9
+ export interface TaskRoutingSettings {
10
+ enabled: boolean;
11
+ minProbability: number;
12
+ minMargin: number;
13
+ hesitation: "decision-card" | "fallback-agent";
14
+ fallbackAgentId: string | null;
15
+ allowlist: AllowlistEntry[];
16
+ projectRouting: boolean;
17
+ }
18
+
19
+ export function settingsPath(companyId: string) {
20
+ return `/companies/${companyId}/microvac/task-routing`;
21
+ }
22
+
23
+ /** Cleans a draft before saving: blank allowlist rows dropped, efforts and notes trimmed. */
24
+ export function cleanSettings(draft: TaskRoutingSettings): TaskRoutingSettings {
25
+ return {
26
+ ...draft,
27
+ fallbackAgentId: draft.hesitation === "fallback-agent" ? draft.fallbackAgentId : null,
28
+ allowlist: draft.allowlist
29
+ .map((entry) => ({
30
+ model: entry.model.trim(),
31
+ effort: entry.effort?.trim() ? entry.effort.trim() : null,
32
+ ...(entry.whenToUse?.trim() ? { whenToUse: entry.whenToUse.trim() } : {}),
33
+ }))
34
+ .filter((entry) => entry.model),
35
+ };
36
+ }
37
+
@@ -0,0 +1,209 @@
1
+ /**
2
+ * The per-company task routing settings (`GET/PUT
3
+ * /companies/:companyId/microvac/task-routing`): on/off, thresholds, what to
4
+ * do on hesitation, project routing and the model allowlist.
5
+ */
6
+ import { useEffect, useState } from "react";
7
+ import { cleanSettings, settingsPath, type AllowlistEntry, type TaskRoutingSettings } from "./settings-model.js";
8
+ import { api, Button, Checkbox, Input, Label, useQuery, useQueryClient, useSelectedCompany, useToast } from "@microvac/ui";
9
+
10
+ interface SettingsResponse {
11
+ settings: TaskRoutingSettings;
12
+ canManage: boolean;
13
+ }
14
+
15
+ interface AgentRow {
16
+ id: string;
17
+ name: string;
18
+ status: string;
19
+ }
20
+
21
+ const SELECT_CLASS = "h-9 rounded-md border border-input bg-background px-2 text-sm text-foreground";
22
+
23
+ export function TaskRoutingSettingsPanel() {
24
+ const { companyId } = useSelectedCompany();
25
+ const queryClient = useQueryClient();
26
+ const toast = useToast();
27
+ const query = useQuery<SettingsResponse>({
28
+ queryKey: ["microvac", "task-routing", companyId],
29
+ queryFn: () => api.get<SettingsResponse>(settingsPath(companyId!)),
30
+ enabled: Boolean(companyId),
31
+ });
32
+ const agentsQuery = useQuery<AgentRow[]>({
33
+ queryKey: ["microvac", "task-routing", "agents", companyId],
34
+ queryFn: () => api.get<AgentRow[]>(`/companies/${companyId}/agents`),
35
+ enabled: Boolean(companyId),
36
+ });
37
+ const [draft, setDraft] = useState<TaskRoutingSettings | null>(null);
38
+ const [saving, setSaving] = useState(false);
39
+ useEffect(() => {
40
+ if (query.data) setDraft(query.data.settings);
41
+ }, [query.data]);
42
+
43
+ if (!companyId) return <p className="text-sm text-muted-foreground">Select a company to set up task routing.</p>;
44
+ if (query.error) {
45
+ return (
46
+ <p role="alert" className="text-sm text-destructive">
47
+ Task routing settings could not be loaded: {String((query.error as Error).message ?? query.error)}
48
+ </p>
49
+ );
50
+ }
51
+ if (!draft || !query.data) return <p className="text-sm text-muted-foreground">Loading task routing settings…</p>;
52
+ const readOnly = !query.data.canManage;
53
+ const update = (patch: Partial<TaskRoutingSettings>) => setDraft({ ...draft, ...patch });
54
+ const updateEntry = (index: number, patch: Partial<AllowlistEntry>) =>
55
+ update({ allowlist: draft.allowlist.map((entry, at) => (at === index ? { ...entry, ...patch } : entry)) });
56
+
57
+ const save = async () => {
58
+ setSaving(true);
59
+ try {
60
+ await api.put(settingsPath(companyId), cleanSettings(draft));
61
+ await queryClient.invalidateQueries({ queryKey: ["microvac", "task-routing", companyId] });
62
+ toast({ title: "Task routing settings saved", tone: "success" });
63
+ } catch (error) {
64
+ toast({ title: "Task routing settings not saved", body: String((error as Error).message ?? error), tone: "error" });
65
+ } finally {
66
+ setSaving(false);
67
+ }
68
+ };
69
+
70
+ return (
71
+ <section className="flex flex-col gap-4" aria-label="Task routing">
72
+ <div className="flex flex-col gap-1">
73
+ <h3 className="text-sm font-medium">Task routing for this company</h3>
74
+ <p className="text-sm text-muted-foreground">
75
+ Assigns todo tasks created without assignee to an agent from their routing cards (the agent's capabilities),
76
+ with a project and run settings. Uses this company's decision model.
77
+ </p>
78
+ {readOnly ? <p className="text-sm text-muted-foreground">You need the right to manage AI connections to change these settings.</p> : null}
79
+ </div>
80
+ <Label className="flex items-center gap-2">
81
+ <Checkbox checked={draft.enabled} disabled={readOnly} onCheckedChange={(value: boolean) => update({ enabled: value === true })} />
82
+ Route unassigned tasks
83
+ </Label>
84
+ <Label className="flex items-center gap-2">
85
+ <Checkbox
86
+ checked={draft.projectRouting}
87
+ disabled={readOnly}
88
+ onCheckedChange={(value: boolean) => update({ projectRouting: value === true })}
89
+ />
90
+ Also choose a project for root tasks without one
91
+ </Label>
92
+ <div className="flex flex-wrap gap-4">
93
+ <Label className="flex flex-col gap-1">
94
+ Minimum confidence
95
+ <Input
96
+ type="number"
97
+ min={0}
98
+ max={1}
99
+ step={0.05}
100
+ value={draft.minProbability}
101
+ disabled={readOnly}
102
+ onChange={(event: { target: { value: string } }) => update({ minProbability: Number(event.target.value) })}
103
+ />
104
+ </Label>
105
+ <Label className="flex flex-col gap-1">
106
+ Minimum margin over the next agent
107
+ <Input
108
+ type="number"
109
+ min={0}
110
+ max={1}
111
+ step={0.05}
112
+ value={draft.minMargin}
113
+ disabled={readOnly}
114
+ onChange={(event: { target: { value: string } }) => update({ minMargin: Number(event.target.value) })}
115
+ />
116
+ </Label>
117
+ </div>
118
+ <div className="flex flex-wrap items-end gap-4">
119
+ <Label className="flex flex-col gap-1">
120
+ When routing hesitates
121
+ <select
122
+ className={SELECT_CLASS}
123
+ value={draft.hesitation}
124
+ disabled={readOnly}
125
+ onChange={(event) => update({ hesitation: event.target.value as TaskRoutingSettings["hesitation"] })}
126
+ >
127
+ <option value="decision-card">Ask on the task (top 3 agents)</option>
128
+ <option value="fallback-agent">Assign a fallback agent</option>
129
+ </select>
130
+ </Label>
131
+ {draft.hesitation === "fallback-agent" ? (
132
+ <Label className="flex flex-col gap-1">
133
+ Fallback agent
134
+ <select
135
+ className={SELECT_CLASS}
136
+ value={draft.fallbackAgentId ?? ""}
137
+ disabled={readOnly}
138
+ onChange={(event) => update({ fallbackAgentId: event.target.value || null })}
139
+ >
140
+ <option value="">Choose an agent</option>
141
+ {(agentsQuery.data ?? [])
142
+ .filter((agent) => agent.status !== "terminated")
143
+ .map((agent) => (
144
+ <option key={agent.id} value={agent.id}>
145
+ {agent.name}
146
+ </option>
147
+ ))}
148
+ </select>
149
+ </Label>
150
+ ) : null}
151
+ </div>
152
+ <div className="flex flex-col gap-2">
153
+ <h4 className="text-sm font-medium">Model allowlist</h4>
154
+ <p className="text-sm text-muted-foreground">
155
+ Models and efforts routing may pick, and the only ones agents may set on a task. Empty: routing keeps each
156
+ agent's model and agents are not limited.
157
+ </p>
158
+ {draft.allowlist.map((entry, index) => (
159
+ <div key={index} className="flex flex-wrap items-center gap-2" data-testid="allowlist-row">
160
+ <Input
161
+ aria-label="Model"
162
+ placeholder="Model"
163
+ value={entry.model}
164
+ disabled={readOnly}
165
+ onChange={(event: { target: { value: string } }) => updateEntry(index, { model: event.target.value })}
166
+ />
167
+ <Input
168
+ aria-label="Effort"
169
+ placeholder="Effort (optional)"
170
+ value={entry.effort ?? ""}
171
+ disabled={readOnly}
172
+ onChange={(event: { target: { value: string } }) => updateEntry(index, { effort: event.target.value })}
173
+ />
174
+ <Input
175
+ aria-label="When to use"
176
+ placeholder="When to use"
177
+ value={entry.whenToUse ?? ""}
178
+ disabled={readOnly}
179
+ onChange={(event: { target: { value: string } }) => updateEntry(index, { whenToUse: event.target.value })}
180
+ />
181
+ <Button
182
+ variant="ghost"
183
+ size="sm"
184
+ disabled={readOnly}
185
+ onClick={() => update({ allowlist: draft.allowlist.filter((_, at) => at !== index) })}
186
+ >
187
+ Remove
188
+ </Button>
189
+ </div>
190
+ ))}
191
+ <div>
192
+ <Button
193
+ variant="outline"
194
+ size="sm"
195
+ disabled={readOnly}
196
+ onClick={() => update({ allowlist: [...draft.allowlist, { model: "", effort: null }] })}
197
+ >
198
+ Add a model
199
+ </Button>
200
+ </div>
201
+ </div>
202
+ <div className="flex items-center justify-end gap-2">
203
+ <Button disabled={readOnly || saving} onClick={() => void save()}>
204
+ {saving ? "Saving…" : "Save task routing"}
205
+ </Button>
206
+ </div>
207
+ </section>
208
+ );
209
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.