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

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paperclip AI
4
+ Copyright (c) 2026 Microvac contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/lib/client.js ADDED
@@ -0,0 +1,263 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@microvac/plugin-task-routing",
3
+ factory: (require) => {
4
+ require("@microvac/ui").requireVersion("^1.2.0", "@microvac/plugin-task-routing");
5
+ const module = { exports: {} };
6
+ const exports = module.exports;
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name2 in all)
14
+ __defProp(target, name2, { get: all[name2], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/client.tsx
27
+ var client_exports = {};
28
+ __export(client_exports, {
29
+ PLUGIN_SETTINGS_SLOT: () => PLUGIN_SETTINGS_SLOT,
30
+ SettingsOccupant: () => SettingsOccupant,
31
+ apply: () => apply,
32
+ inject: () => inject,
33
+ name: () => name
34
+ });
35
+ module.exports = __toCommonJS(client_exports);
36
+
37
+ // src/settings-panel.tsx
38
+ var import_react = require("react");
39
+
40
+ // src/settings-model.ts
41
+ function settingsPath(companyId) {
42
+ return `/companies/${companyId}/microvac/task-routing`;
43
+ }
44
+ function cleanSettings(draft) {
45
+ return {
46
+ ...draft,
47
+ fallbackAgentId: draft.hesitation === "fallback-agent" ? draft.fallbackAgentId : null,
48
+ allowlist: draft.allowlist.map((entry) => ({
49
+ model: entry.model.trim(),
50
+ effort: entry.effort?.trim() ? entry.effort.trim() : null,
51
+ ...entry.whenToUse?.trim() ? { whenToUse: entry.whenToUse.trim() } : {}
52
+ })).filter((entry) => entry.model)
53
+ };
54
+ }
55
+
56
+ // src/settings-panel.tsx
57
+ var import_ui = require("@microvac/ui");
58
+ var import_jsx_runtime = require("react/jsx-runtime");
59
+ var SELECT_CLASS = "h-9 rounded-md border border-input bg-background px-2 text-sm text-foreground";
60
+ function TaskRoutingSettingsPanel() {
61
+ const { companyId } = (0, import_ui.useSelectedCompany)();
62
+ const queryClient = (0, import_ui.useQueryClient)();
63
+ const toast = (0, import_ui.useToast)();
64
+ const query = (0, import_ui.useQuery)({
65
+ queryKey: ["microvac", "task-routing", companyId],
66
+ queryFn: () => import_ui.api.get(settingsPath(companyId)),
67
+ enabled: Boolean(companyId)
68
+ });
69
+ const agentsQuery = (0, import_ui.useQuery)({
70
+ queryKey: ["microvac", "task-routing", "agents", companyId],
71
+ queryFn: () => import_ui.api.get(`/companies/${companyId}/agents`),
72
+ enabled: Boolean(companyId)
73
+ });
74
+ const [draft, setDraft] = (0, import_react.useState)(null);
75
+ const [saving, setSaving] = (0, import_react.useState)(false);
76
+ (0, import_react.useEffect)(() => {
77
+ if (query.data) setDraft(query.data.settings);
78
+ }, [query.data]);
79
+ if (!companyId) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "Select a company to set up task routing." });
80
+ if (query.error) {
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", className: "text-sm text-destructive", children: [
82
+ "Task routing settings could not be loaded: ",
83
+ String(query.error.message ?? query.error)
84
+ ] });
85
+ }
86
+ if (!draft || !query.data) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "Loading task routing settings\u2026" });
87
+ const readOnly = !query.data.canManage;
88
+ const update = (patch) => setDraft({ ...draft, ...patch });
89
+ const updateEntry = (index, patch) => update({ allowlist: draft.allowlist.map((entry, at) => at === index ? { ...entry, ...patch } : entry) });
90
+ const save = async () => {
91
+ setSaving(true);
92
+ try {
93
+ await import_ui.api.put(settingsPath(companyId), cleanSettings(draft));
94
+ await queryClient.invalidateQueries({ queryKey: ["microvac", "task-routing", companyId] });
95
+ toast({ title: "Task routing settings saved", tone: "success" });
96
+ } catch (error) {
97
+ toast({ title: "Task routing settings not saved", body: String(error.message ?? error), tone: "error" });
98
+ } finally {
99
+ setSaving(false);
100
+ }
101
+ };
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "flex flex-col gap-4", "aria-label": "Task routing", children: [
103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1", children: [
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: "text-sm font-medium", children: "Task routing for this company" }),
105
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "Assigns todo tasks created without assignee to an agent from their routing cards (the agent's capabilities), with a project and run settings. Uses this company's decision model." }),
106
+ readOnly ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "You need the right to manage AI connections to change these settings." }) : null
107
+ ] }),
108
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex items-center gap-2", children: [
109
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Checkbox, { checked: draft.enabled, disabled: readOnly, onCheckedChange: (value) => update({ enabled: value === true }) }),
110
+ "Route unassigned tasks"
111
+ ] }),
112
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex items-center gap-2", children: [
113
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ import_ui.Checkbox,
115
+ {
116
+ checked: draft.projectRouting,
117
+ disabled: readOnly,
118
+ onCheckedChange: (value) => update({ projectRouting: value === true })
119
+ }
120
+ ),
121
+ "Also choose a project for root tasks without one"
122
+ ] }),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap gap-4", children: [
124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex flex-col gap-1", children: [
125
+ "Minimum confidence",
126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
127
+ import_ui.Input,
128
+ {
129
+ type: "number",
130
+ min: 0,
131
+ max: 1,
132
+ step: 0.05,
133
+ value: draft.minProbability,
134
+ disabled: readOnly,
135
+ onChange: (event) => update({ minProbability: Number(event.target.value) })
136
+ }
137
+ )
138
+ ] }),
139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex flex-col gap-1", children: [
140
+ "Minimum margin over the next agent",
141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
142
+ import_ui.Input,
143
+ {
144
+ type: "number",
145
+ min: 0,
146
+ max: 1,
147
+ step: 0.05,
148
+ value: draft.minMargin,
149
+ disabled: readOnly,
150
+ onChange: (event) => update({ minMargin: Number(event.target.value) })
151
+ }
152
+ )
153
+ ] })
154
+ ] }),
155
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-end gap-4", children: [
156
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex flex-col gap-1", children: [
157
+ "When routing hesitates",
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
159
+ "select",
160
+ {
161
+ className: SELECT_CLASS,
162
+ value: draft.hesitation,
163
+ disabled: readOnly,
164
+ onChange: (event) => update({ hesitation: event.target.value }),
165
+ children: [
166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "decision-card", children: "Ask on the task (top 3 agents)" }),
167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "fallback-agent", children: "Assign a fallback agent" })
168
+ ]
169
+ }
170
+ )
171
+ ] }),
172
+ draft.hesitation === "fallback-agent" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Label, { className: "flex flex-col gap-1", children: [
173
+ "Fallback agent",
174
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
175
+ "select",
176
+ {
177
+ className: SELECT_CLASS,
178
+ value: draft.fallbackAgentId ?? "",
179
+ disabled: readOnly,
180
+ onChange: (event) => update({ fallbackAgentId: event.target.value || null }),
181
+ children: [
182
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "Choose an agent" }),
183
+ (agentsQuery.data ?? []).filter((agent) => agent.status !== "terminated").map((agent) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: agent.id, children: agent.name }, agent.id))
184
+ ]
185
+ }
186
+ )
187
+ ] }) : null
188
+ ] }),
189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { className: "text-sm font-medium", children: "Model allowlist" }),
191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "Models and efforts routing may pick, and the only ones agents may set on a task. Empty: routing keeps each agent's model and agents are not limited." }),
192
+ draft.allowlist.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-center gap-2", "data-testid": "allowlist-row", children: [
193
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
194
+ import_ui.Input,
195
+ {
196
+ "aria-label": "Model",
197
+ placeholder: "Model",
198
+ value: entry.model,
199
+ disabled: readOnly,
200
+ onChange: (event) => updateEntry(index, { model: event.target.value })
201
+ }
202
+ ),
203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
204
+ import_ui.Input,
205
+ {
206
+ "aria-label": "Effort",
207
+ placeholder: "Effort (optional)",
208
+ value: entry.effort ?? "",
209
+ disabled: readOnly,
210
+ onChange: (event) => updateEntry(index, { effort: event.target.value })
211
+ }
212
+ ),
213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
214
+ import_ui.Input,
215
+ {
216
+ "aria-label": "When to use",
217
+ placeholder: "When to use",
218
+ value: entry.whenToUse ?? "",
219
+ disabled: readOnly,
220
+ onChange: (event) => updateEntry(index, { whenToUse: event.target.value })
221
+ }
222
+ ),
223
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
+ import_ui.Button,
225
+ {
226
+ variant: "ghost",
227
+ size: "sm",
228
+ disabled: readOnly,
229
+ onClick: () => update({ allowlist: draft.allowlist.filter((_, at) => at !== index) }),
230
+ children: "Remove"
231
+ }
232
+ )
233
+ ] }, index)),
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
235
+ import_ui.Button,
236
+ {
237
+ variant: "outline",
238
+ size: "sm",
239
+ disabled: readOnly,
240
+ onClick: () => update({ allowlist: [...draft.allowlist, { model: "", effort: null }] }),
241
+ children: "Add a model"
242
+ }
243
+ ) })
244
+ ] }),
245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center justify-end gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { disabled: readOnly || saving, onClick: () => void save(), children: saving ? "Saving\u2026" : "Save task routing" }) })
246
+ ] });
247
+ }
248
+
249
+ // src/client.tsx
250
+ var import_jsx_runtime2 = require("react/jsx-runtime");
251
+ var name = "@microvac/plugin-task-routing";
252
+ var inject = ["slots"];
253
+ var PLUGIN_SETTINGS_SLOT = "microvac.plugin-settings";
254
+ function SettingsOccupant(props) {
255
+ return props.owner?.context?.pluginName === name ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TaskRoutingSettingsPanel, {}) : null;
256
+ }
257
+ function apply(ctx) {
258
+ ctx.effect(() => ctx.slots.register({ name: PLUGIN_SETTINGS_SLOT }, SettingsOccupant), "task-routing: settings panel");
259
+ }
260
+
261
+ return module.exports;
262
+ },
263
+ });
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@microvac/plugin-task-routing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-rc.31",
4
+ "license": "MIT",
5
+ "description": "Microvac plugin: routes tasks created without assignee to an agent, a project and run settings.",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "lib"
15
+ ],
16
+ "microvac": {
17
+ "ui": "^1.2.0"
18
+ },
19
+ "dsh": {
20
+ "client": {
21
+ "platform": "web",
22
+ "inject": [
23
+ "slots"
24
+ ],
25
+ "external": [
26
+ "@microvac/ui"
27
+ ],
28
+ "immediately": true
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "@deepseek-ai/schemastery": "3.20.0-alpha.2"
33
+ },
34
+ "scripts": {
35
+ "build:client": "node ../../scripts/microvac/build-client-plugin.mjs .",
36
+ "typecheck": "tsc --noEmit"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/microvac-ai/microvac"
41
+ }
42
+ }
@@ -0,0 +1,43 @@
1
+ // @ts-check
2
+ /**
3
+ * The model allowlist check behind the `issue.runSettings.check` hook point:
4
+ * run settings an agent sets on a task must match an allowlist entry.
5
+ */
6
+ import { allowlistLabel, normalizeSettings } from "./routing.js";
7
+
8
+ /**
9
+ * @typedef {{ model: string | null, effort: string | null }} RunSettingsChoice
10
+ * @typedef {{ status: "allowed" } | { status: "rejected", message: string, allowed: import("./routing.js").AllowlistEntry[] }} Verdict
11
+ */
12
+
13
+ /**
14
+ * Whether a choice is in the allowlist. A model must match an entry with the
15
+ * same effort (an entry without effort accepts any). With no model (the
16
+ * agent's own model), an effort must be one some entry uses.
17
+ * @param {RunSettingsChoice} choice
18
+ * @param {import("./routing.js").AllowlistEntry[]} allowlist
19
+ */
20
+ export function isAllowed(choice, allowlist) {
21
+ if (!choice.model) return !choice.effort || allowlist.some((entry) => entry.effort === choice.effort);
22
+ return allowlist.some((entry) => entry.model === choice.model && (entry.effort === null || entry.effort === choice.effort));
23
+ }
24
+
25
+ /**
26
+ * The hook handler. Companies without routing enabled, or without an
27
+ * allowlist, are not limited.
28
+ * @param {Verdict} value
29
+ * @param {{ companyId: string, runSettings: RunSettingsChoice }} context
30
+ * @param {(companyId: string) => Promise<unknown>} readSettings
31
+ * @returns {Promise<Verdict>}
32
+ */
33
+ export async function checkRunSettings(value, context, readSettings) {
34
+ if (value.status === "rejected") return value;
35
+ const settings = normalizeSettings(await readSettings(context.companyId));
36
+ if (!settings.enabled || settings.allowlist.length === 0) return value;
37
+ if (isAllowed(context.runSettings, settings.allowlist)) return value;
38
+ return {
39
+ status: "rejected",
40
+ message: `Run settings outside the company's model allowlist. Allowed: ${settings.allowlist.map(allowlistLabel).join(", ")}, or keep the agent's model.`,
41
+ allowed: settings.allowlist,
42
+ };
43
+ }
package/src/client.tsx ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Client face of the `task-routing` plugin (`docs/microvac/task-routing.md`):
3
+ * the per-company settings panel under the plugin's entry in
4
+ * Settings › Plugins (`microvac.plugin-settings` slot). The build checks the
5
+ * Microvac UI range (`microvac.ui` in `package.json`).
6
+ */
7
+ import { TaskRoutingSettingsPanel } from "./settings-panel.js";
8
+
9
+ export const name = "@microvac/plugin-task-routing";
10
+ export const inject = ["slots"];
11
+
12
+ /** `MICROVAC_PLUGIN_SETTINGS_SLOT` in `@paperclipai/shared`. */
13
+ export const PLUGIN_SETTINGS_SLOT = "microvac.plugin-settings";
14
+
15
+ interface SlotOwner {
16
+ owner?: { context?: { pluginName?: string } };
17
+ }
18
+
19
+ interface TaskRoutingContext {
20
+ slots: {
21
+ register(options: { name: string; id: string }, component: (props: SlotOwner) => unknown): () => void;
22
+ };
23
+ effect(start: () => () => void, label?: string): unknown;
24
+ }
25
+
26
+ /** Renders the panel only under this plugin's own entry. */
27
+ export function SettingsOccupant(props: SlotOwner) {
28
+ return props.owner?.context?.pluginName === name ? <TaskRoutingSettingsPanel /> : null;
29
+ }
30
+
31
+ /** The settings slot is a list: each occupant needs its own id. */
32
+ export function apply(ctx: TaskRoutingContext) {
33
+ ctx.effect(() => ctx.slots.register({ name: PLUGIN_SETTINGS_SLOT, id: name }, SettingsOccupant), "task-routing: settings panel");
34
+ }
package/src/index.js ADDED
@@ -0,0 +1,79 @@
1
+ // @ts-check
2
+ /**
3
+ * Host face of the `task-routing` plugin (ADR 0016, `docs/microvac/task-routing.md`):
4
+ * routes `todo` tasks created without assignee to an agent, a project and run
5
+ * settings, through the server's task routing port (`taskRoutingPort`).
6
+ * Triggers: company live events, plus a sweep every `sweepMinutes`. It also
7
+ * fills the `issue.runSettings.check` hook point with each company's model
8
+ * allowlist. Per-company settings live in the plugin's panel
9
+ * (Settings › Plugins › Task routing); the client face (`src/client.tsx`,
10
+ * built into `lib/client.js`) draws it.
11
+ *
12
+ * # microvac.yml
13
+ * - id: task-routing
14
+ * name: "@microvac/plugin-task-routing"
15
+ */
16
+ import z from "@deepseek-ai/schemastery";
17
+ import { checkRunSettings } from "./allowlist.js";
18
+ import { TaskRouter } from "./router.js";
19
+
20
+ export const name = "@microvac/plugin-task-routing";
21
+
22
+ export const inject = ["hooks", "taskRoutingPort"];
23
+
24
+ export const Config = z.object({
25
+ sweepMinutes: z
26
+ .natural()
27
+ .default(10)
28
+ .description("Minutes between two sweeps for tasks the event path missed. 0: no sweep."),
29
+ });
30
+
31
+ /**
32
+ * @typedef {import("./router.js").TaskRoutingPort & {
33
+ * subscribe(listener: (event: { companyId: string, type: string, payload: Record<string, unknown> }) => void): () => void,
34
+ * whenAttached(start: () => void): () => void,
35
+ * }} HostPort
36
+ * @typedef {{
37
+ * hooks: { register(name: string, handler: (value: any, context: any) => any): unknown },
38
+ * taskRoutingPort: HostPort,
39
+ * effect(start: () => () => void, label?: string): unknown,
40
+ * }} TaskRoutingContext
41
+ */
42
+
43
+ /**
44
+ * @param {TaskRoutingContext} ctx
45
+ * @param {{ sweepMinutes?: number }} [config]
46
+ */
47
+ export function apply(ctx, config = {}) {
48
+ const port = ctx.taskRoutingPort;
49
+ ctx.hooks.register("issue.runSettings.check", (value, context) =>
50
+ checkRunSettings(value, context, (companyId) => port.settings(companyId)),
51
+ );
52
+ ctx.effect(() => {
53
+ // The router reads the database, so it waits until the server attaches one.
54
+ /** @type {(() => void) | null} */
55
+ let stopRouter = null;
56
+ const detach = port.whenAttached(() => {
57
+ if (stopRouter) return;
58
+ const router = new TaskRouter(port);
59
+ const unsubscribe = port.subscribe((event) => router.handleEvent(event));
60
+ const minutes = config.sweepMinutes ?? 10;
61
+ const timer = minutes > 0 ? setInterval(() => void router.sweep(), minutes * 60_000) : undefined;
62
+ timer?.unref?.();
63
+ // A first sweep shortly after start picks up what arrived while the server was down.
64
+ const first = setTimeout(() => void router.sweep(), 30_000);
65
+ first.unref?.();
66
+ stopRouter = () => {
67
+ clearTimeout(first);
68
+ if (timer) clearInterval(timer);
69
+ unsubscribe();
70
+ router.stop();
71
+ };
72
+ });
73
+ return () => {
74
+ detach();
75
+ stopRouter?.();
76
+ stopRouter = null;
77
+ };
78
+ }, "task-routing/router");
79
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The part of Microvac UI (`ui/src/microvac/ui-module`) this plugin uses; the
3
+ * page provides the module at run time. `tsconfig.json` maps `@microvac/ui`
4
+ * here for type checking; the build keeps it external.
5
+ */
6
+ import type { ComponentType } from "react";
7
+
8
+ type AnyComponent = ComponentType<any>;
9
+
10
+ export declare const version: string;
11
+ export declare function requireVersion(range: string, plugin?: string): void;
12
+
13
+ export declare function useQuery<T>(options: {
14
+ queryKey: readonly unknown[];
15
+ queryFn: () => Promise<T>;
16
+ enabled?: boolean;
17
+ }): { data?: T; error: unknown; isPending: boolean; refetch(): Promise<unknown> };
18
+ export declare function useQueryClient(): { invalidateQueries(filters: { queryKey: readonly unknown[] }): Promise<void> };
19
+ export declare function useSelectedCompany(): { companyId: string | null; company: unknown };
20
+ export declare function useToast(): (input: { title: string; body?: string; tone?: "info" | "success" | "warn" | "error" }) => void;
21
+
22
+ export declare const api: {
23
+ get<T>(path: string): Promise<T>;
24
+ put<T>(path: string, body: unknown): Promise<T>;
25
+ };
26
+
27
+ export declare const Button: AnyComponent;
28
+ export declare const Input: AnyComponent;
29
+ export declare const Checkbox: AnyComponent;
30
+ export declare const Label: AnyComponent;
31
+ export declare function cn(...classes: unknown[]): string;