Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([extract-requiretoolkit-pattern-to-runner-js]): typed AI_TOOLKIT_NOT_INITIALIZED across runner + promptService
[._.]/ Adam Eivya785505eaa4a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 66d1070a0b..0b306ea13b 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -12,6 +12,8 @@- **`isPlainObject` promoted to a named export of `server/lib/objects.js`.** The `(v && typeof v === 'object' && !Array.isArray(v))` check was previously inlined at 16 sites across `server/lib/`, `server/services/`, and `server/routes/`. The helper is now a named export of `objects.js` (surfaces through the `server/lib/index.js` barrel automatically) and all 16 sites import it. Pure refactor — no behavioral changes; the helper retains the "non-null, non-array `object`" semantics that match every existing call site (Date / Map / class instances still return true).+- **AI Toolkit "not initialized" errors now carry a typed code + 503 status across runner + promptService.** `server/services/runner.js` (13 sites) and `server/services/promptService.js` (12 sites) previously each inlined `if (!aiToolkitInstance) throw new Error(…)` checks that surfaced as untyped 500s with string-matched messages. Both now go through a private `requireToolkit()` helper that throws `ServerError('AI Toolkit not initialized', { status: 503, code: 'AI_TOOLKIT_NOT_INITIALIZED' })` — the same shape `providers.js` already throws. Callers (e.g. `visionTest.js`) can gate on `err.code === 'AI_TOOLKIT_NOT_INITIALIZED'` uniformly regardless of which service raised, and routes that hit any of the three services during toolkit warm-up now return 503 (service-unavailable) rather than a generic 500. No behavior change for the warmed path.+- **Universe Builder cast preview now matches Media History exactly.** Clicking a cast/canon image used to open a stripped-down modal: only Refine Prompt / Add to Collection / Download, no negative prompt, no notes, and the "prompt" field showed the character description rather than the actual prompt that produced the image. The canon section's local `<MediaPreview>` is gone — canon clicks now bubble up to the page-level lightbox, which hydrates from the gallery sidecar (real prompt, negative prompt, model, seed, resolution, …) and exposes the full action set (Refine Prompt, Remix, Send to Video, Clean, Add to Collection, Download, notes, favorite). The descriptor string is kept as a fallback label only when no sidecar exists (legacy canon renders). Character reference sheets still route through `/data/image-refs/` via a `canon-sheet:<filename>` key so a basename collision with a gallery image can't misroute the preview.- **First-run no longer silently flips :5555 from HTTP to self-signed HTTPS.** `scripts/setup-cert.js` ran on every `npm start` and, when Tailscale was unavailable, auto-generated a self-signed cert — breaking the documented `http://localhost:5555` URL and forcing a browser click-through. It now only auto-generates a self-signed cert when (a) the user explicitly passes `--self-signed`, or (b) a self-signed cert is already present (renewal path). Fresh installs without Tailscale stay HTTP-only on :5555 so the URL in the README and in `setup.sh`'s final banner just works. `setup.sh`'s "Access at:" banner is now cert-aware — when HTTPS got provisioned it prints the loopback HTTP mirror (`http://localhost:5553`) and the Tailscale hostname instead of the broken `http://localhost:5555`.diff --git a/DONE.md b/DONE.mdindex 8839532e4f..ffdb60fd62 100644--- a/DONE.md+++ b/DONE.md@@ -10,6 +10,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./### 2026-05-19+- **[extract-requiretoolkit-pattern-to-runner-js] Extend `requireToolkit()` pattern to `server/services/runner.js` + `promptService.js`.** The 13 inlined `if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized')` sites in `runner.js` (across `createRun`, `finalizeRunRecord`, `executeCliRun`, `executeApiRun`, `registerActiveRun`, `stopRun`, `getRun`, `getRunOutput`, `getRunPrompt`, `listRuns`, `deleteRun`, `deleteFailedRuns`, `isRunActive`) plus 12 sibling sites in `promptService.js` (across `loadPrompts`, `getStages`, `getStage`, `getStageTemplate`, `updateStageTemplate`, `updateStageConfig`, `getVariables`, `getVariable`, `updateVariable`, `createVariable`, `deleteVariable`, `buildPrompt`) now go through a private `requireToolkit()` helper that throws `new ServerError('AI Toolkit not initialized', { status: 503, code: 'AI_TOOLKIT_NOT_INITIALIZED' })` — mirroring the helper `providers.js` already exports. Promoting `promptService.js` to the typed-error shape too was a /simplify finding from this PR — leaving prompt-service failures on the untyped string-throw while runner + providers were typed would have left callers (e.g. `visionTest.js`'s `err.code === 'AI_TOOLKIT_NOT_INITIALIZED'` gate) unable to discriminate by source. In runner.js, multi-use callsites (`finalizeRunRecord`, `executeCliRun`, `stopRun`, `registerActiveRun`) hoist `const toolkit = requireToolkit()` once so the `aiToolkitInstance.services.X` chains collapse to `toolkit.services.X` without re-checking. `unregisterActiveRun` is unchanged — its optional-chained `.delete` is deliberately best-effort cleanup that runs from child-process teardown callbacks and must not throw. Error message string preserved verbatim so `server/lib/promptRunner.test.js`'s `rejects.toThrow(/AI Toolkit not initialized/)` regex still matches. Follow-up deferred to PLAN.md as `[extract-shared-requiretoolkit-helper]` — three copies of the 8-line helper now exist; extract to `server/lib/aiToolkitState.js` when a 4th caller appears or somebody wants to consolidate. All 5832 server tests pass.- **[move-usenextevalcountdown-to-hooks] Move `useNextEvalCountdown` from `components/cos/` to `client/src/hooks/`.** Relocated `client/src/components/cos/useNextEvalCountdown.js` (1s-tick countdown to the next CoS evaluation) to `client/src/hooks/useNextEvalCountdown.js` to conform to the CLAUDE.md "Module Organization" rule that `useX` hooks live exclusively under `client/src/hooks/`. Dropped the re-export from `components/cos/index.js`, added the catalog row to `client/src/hooks/README.md` (Apps / Sessions / Domain), and added the barrel re-export to `client/src/hooks/index.js`. Only consumer (`client/src/pages/ChiefOfStaff.jsx`) now imports the hook directly from `../hooks/useNextEvalCountdown`, matching the existing direct-import pattern it already uses for `useSocket` and `useLocalStorageBool`. Pure relocation — no behavioral changes. All 154 client tests pass (the `hooks/index.test.js` barrel-shape invariant test confirms the move is correctly wired).- **[sharing-annotationssync-cache-bucket-asset-keys] Cache `listBucketAssetKeys` per (bucket, manifests-dir mtime).** `server/services/sharing/annotationsSync.js#listBucketAssetKeys` previously re-scanned every manifest in every auto-merge bucket on every 2s-debounced annotation flush. Manifests are the only source of truth post-v2 (content-addressed `assets/blobs/<hash>` paths don't carry filenames), so per-flush fan-out scaled O(buckets × manifests). The function now stats `<bucket>/manifests/` on each call and reuses the previously-parsed `Set<assetKey>` whenever the directory mtime matches — every manifest write/archive goes through `atomicWrite` (temp + rename) or `rename`, both of which bump the dir mtime, so the mtime is a complete invalidation signal. The legacy v1 `assets/{images,videos}/` dir scan stays uncached (small + rare fall-through). The annotation manifest emitted by `exportAnnotationsToBucket` rolls the cached mtime forward so the post-write bump doesn't immediately invalidate the same bucket's cache on the next flush. New `__resetBucketAssetKeysCache` test hook + 7 new vitest cases in `annotationsSync.test.js` covering hit, mtime-advance miss, per-bucket isolation, legacy-dir-scan-still-runs, ENOENT-on-manifests-dir as a stable cache key, non-ENOENT stat error bypasses caching, and post-write mtime-roll-forward keeps the next flush hot.- **[export-isplainobject-helper-from-server-lib-objects] Export `isPlainObject` from `server/lib/objects.js`.** Promoted the previously-private `isPlainObject(v) = !!v && typeof v === 'object' && !Array.isArray(v)` helper to a named export of `server/lib/objects.js` (surfaces automatically through the `server/lib/index.js` barrel) and migrated 18 inline call sites onto it — every site that exactly matched the 3-part check pattern. Sites: the previously-private declarations in `server/lib/objects.js` + `server/lib/mediaModels.js` (which now imports from objects.js), the 12 sites enumerated in PLAN (`services/calendarAccounts.js`, `messageAccounts.js`, `messagePlaywrightSync.js`, `loras.js`, `mortalLoomStore.js`, `updateChecker.js`, `meatspacePost.js`, `dataSync.js`, `featureAgents.js`, `taskSchedule.js` — also dropped its single-use local `const isPlainObject`, `pipeline/issues.js`, `sharing/exporter.js`), and 4 additional matching sites that landed between when the PLAN entry was authored and now (`routes/loras.js#DELETE /auth/civitai`, `services/universeBuilderExpand.js#sanitizeCategory`, `server/scripts/moltbook-probe.mjs`, and `scripts/check-themes.js` ×2 — the last two caught by codex review after the initial grep missed `.mjs` files and the top-level `scripts/` dir). Sites with a partial-shape second predicate (`mortalLoomStore.js`'s `current[k] && typeof current[k] === 'object'` and the symmetric block in `featureAgents.js`) kept their second predicate intact — only the full 3-part check was migrated, keeping the PR a pure refactor. Helper retains the loose "non-null, non-array `object`" semantics that match every call site's behavior (Date / Map / class instances still return true — documented in the JSDoc and locked in by 3 new vitest cases). `server/lib/README.md` row updated to name both `deepMerge` and `isPlainObject`. No behavioral changes. All 5832 server tests + 154 client tests pass.diff --git a/PLAN.md b/PLAN.mdindex 294bedf53e..7916c565fe 100644--- a/PLAN.md+++ b/PLAN.md@@ -66,7 +66,7 @@ _Nothing currently parked — pick the next item from the Backlog._### Better-audit residue- [ ] [high-tests-add-coverage-for-server-services-shell] **[HIGH][TESTS]** Add coverage for `server/services/shell.js` and `server/services/feeds.js` — both have exported functions but no sibling test. Shell drives all terminal sessions; feeds manages subscriptions. (New — surfaced 2026-05-16 replan.)-- [ ] [extract-requiretoolkit-pattern-to-runner-js] **[MEDIUM][CODE]** Extend the `requireToolkit()` pattern from `server/services/providers.js` to `server/services/runner.js` — 13 sites of `if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized')` still inlined there (lines 27, 144, 218, 332, 343 + others). Surfaced by /simplify during the better-audit residue refactor bundle; left out of that PR to keep scope tight. Should reuse the same `ServerError({ status: 503, code: 'AI_TOOLKIT_NOT_INITIALIZED' })` shape providers.js now throws.+- [ ] [extract-shared-requiretoolkit-helper] **[LOW][CODE]** Three services now carry an identical private `requireToolkit()` helper that throws `ServerError('AI Toolkit not initialized', { status: 503, code: 'AI_TOOLKIT_NOT_INITIALIZED' })` — `server/services/providers.js`, `server/services/runner.js`, `server/services/promptService.js`. Three module-level `let aiToolkitInstance = null` declarations all receive the same toolkit object from `server/index.js` via per-service `setAIToolkit(toolkit)` setters. Candidate consolidation: extract to `server/lib/aiToolkitState.js` exporting `setAIToolkitInstance(toolkit)` + `requireToolkit()` so all three services import the same module-level state. Includes barrel + README row per `server/lib/` maintenance rule. Deferred from `[extract-requiretoolkit-pattern-to-runner-js]` — three callers crosses the threshold but the 8-line helper × 3 sites is low-maintenance enough that this can wait for a fourth caller or somebody actually wanting to consolidate.### Pipeline — deferreddiff --git a/server/services/promptService.js b/server/services/promptService.jsindex 0e81744833..2c7c2c969b 100644--- a/server/services/promptService.js+++ b/server/services/promptService.js@@ -14,6 +14,7 @@ import { join } from 'path';import { applyTemplate } from '../lib/promptTemplate.js';import { expandPartials } from '../lib/promptPartials.js';import { PATHS } from '../lib/fileUtils.js';+import { ServerError } from '../lib/errorHandler.js';// This will be initialized by server/index.js and set via setAIToolkit()let aiToolkitInstance = null;@@ -22,64 +23,63 @@ export function setAIToolkit(toolkit) {aiToolkitInstance = toolkit;}+// Mirrors the helper in `server/services/providers.js` + `runner.js` so callers+// can gate on `err.code === 'AI_TOOLKIT_NOT_INITIALIZED'` instead of string-+// matching the message; status 503 because the toolkit warms at boot.+function requireToolkit() {+ if (aiToolkitInstance) return aiToolkitInstance;+ throw new ServerError('AI Toolkit not initialized', {+ status: 503,+ code: 'AI_TOOLKIT_NOT_INITIALIZED',+ });+}+export async function loadPrompts() {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.init();+ return requireToolkit().services.prompts.init();}export function getStages() {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.getStages();+ return requireToolkit().services.prompts.getStages();}export function getStage(stageName) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.getStage(stageName);+ return requireToolkit().services.prompts.getStage(stageName);}export async function getStageTemplate(stageName) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.getStageTemplate(stageName);+ return requireToolkit().services.prompts.getStageTemplate(stageName);}export async function updateStageTemplate(stageName, content) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.updateStageTemplate(stageName, content);+ return requireToolkit().services.prompts.updateStageTemplate(stageName, content);}export async function updateStageConfig(stageName, config) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.updateStageConfig(stageName, config);+ return requireToolkit().services.prompts.updateStageConfig(stageName, config);}export function getVariables() {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.getVariables();+ return requireToolkit().services.prompts.getVariables();}export function getVariable(key) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.getVariable(key);+ return requireToolkit().services.prompts.getVariable(key);}export async function updateVariable(key, data) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.updateVariable(key, data);+ return requireToolkit().services.prompts.updateVariable(key, data);}export async function createVariable(key, data) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.createVariable(key, data);+ return requireToolkit().services.prompts.createVariable(key, data);}export async function deleteVariable(key) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.prompts.deleteVariable(key);+ return requireToolkit().services.prompts.deleteVariable(key);}export async function buildPrompt(stageName, data = {}) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- const prompts = aiToolkitInstance.services.prompts;+ const prompts = requireToolkit().services.prompts;const stage = prompts.getStage(stageName);if (!stage) throw new Error(`Stage ${stageName} not found`);const rawTemplate = await prompts.getStageTemplate(stageName);diff --git a/server/services/runner.js b/server/services/runner.jsindex 3748dced29..274c510beb 100644--- a/server/services/runner.js+++ b/server/services/runner.js@@ -7,6 +7,7 @@ import { writeFile, readFile } from 'fs/promises';import { join } from 'path';import { ensureDir, tryReadFile } from '../lib/fileUtils.js';import { resolveCliModel, hasModelFlag, extractBakedModel } from '../lib/providerModels.js';+import { ServerError } from '../lib/errorHandler.js';// Re-exported so `server/lib/promptRunner.js` can import via the runner// (its existing dependency boundary). The canonical home is now@@ -23,11 +24,22 @@ export function setAIToolkit(toolkit, config = {}) {runnerConfig = { dataDir: config.dataDir || './data', hooks: config.hooks || {} };}+// Mirrors the helper in `server/services/providers.js` so callers can gate on+// `err.code === 'AI_TOOLKIT_NOT_INITIALIZED'` instead of string-matching the+// message; status 503 (service-unavailable) because the toolkit warms at boot+// and a not-initialized state means the service hasn't finished starting.+function requireToolkit() {+ if (aiToolkitInstance) return aiToolkitInstance;+ throw new ServerError('AI Toolkit not initialized', {+ status: 503,+ code: 'AI_TOOLKIT_NOT_INITIALIZED',+ });+}+export async function createRun(options) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');// The toolkit's runner emits its own "🤖 AI run [source]: provider/model"// line — don't duplicate it here.- return aiToolkitInstance.services.runner.createRun(options);+ return requireToolkit().services.runner.createRun(options);}/**@@ -141,7 +153,7 @@ export function getRunsPath() {* @returns the merged metadata object (also written to disk).*/export async function finalizeRunRecord({ runId, output, exitCode, success, error, startTime, extras }) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');+ const toolkit = requireToolkit();const runDir = join(getRunsPath(), runId);const outputPath = join(runDir, 'output.txt');const metadataPath = join(runDir, 'metadata.json');@@ -159,8 +171,8 @@ export async function finalizeRunRecord({ runId, output, exitCode, success, erroif (error) metadata.error = error;if (extras && typeof extras === 'object') Object.assign(metadata, extras);- if (!success && aiToolkitInstance.services.errorDetection) {- const errorAnalysis = aiToolkitInstance.services.errorDetection.analyzeError(output, exitCode);+ if (!success && toolkit.services.errorDetection) {+ const errorAnalysis = toolkit.services.errorDetection.analyzeError(output, exitCode);metadata.error = metadata.error || errorAnalysis.message || `Process exited with code ${exitCode}`;metadata.errorCategory = errorAnalysis.category;metadata.errorAnalysis = errorAnalysis;@@ -215,7 +227,7 @@ export async function patchRunMetadata(runId, patch) {* This removes 'shell: true' which causes DEP0190 warning and potential security issues*/export async function executeCliRun(runId, provider, prompt, workspacePath, onData, onComplete, timeout) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');+ const toolkit = requireToolkit();const runsPath = join(runnerConfig.dataDir, 'runs');const runDir = join(runsPath, runId);@@ -241,10 +253,10 @@ export async function executeCliRun(runId, provider, prompt, workspacePath, onDachildProcess.stdin.end();// Track active run (store on the runner service itself for stopRun to access)- if (!aiToolkitInstance.services.runner._portosActiveRuns) {- aiToolkitInstance.services.runner._portosActiveRuns = new Map();+ if (!toolkit.services.runner._portosActiveRuns) {+ toolkit.services.runner._portosActiveRuns = new Map();}- aiToolkitInstance.services.runner._portosActiveRuns.set(runId, childProcess);+ toolkit.services.runner._portosActiveRuns.set(runId, childProcess);// Call hooksrunnerConfig.hooks?.onRunStarted?.({ runId, provider: provider.name, model: provider.defaultModel });@@ -272,7 +284,7 @@ export async function executeCliRun(runId, provider, prompt, workspacePath, onDachildProcess.on('error', async (err) => {if (timeoutHandle) clearTimeout(timeoutHandle);- aiToolkitInstance.services.runner._portosActiveRuns?.delete(runId);+ toolkit.services.runner._portosActiveRuns?.delete(runId);console.error(`❌ Run ${runId} spawn error: ${err.message}`);const metadata = {@@ -293,7 +305,7 @@ export async function executeCliRun(runId, provider, prompt, workspacePath, onDachildProcess.on('close', async (code) => {if (timeoutHandle) clearTimeout(timeoutHandle);- aiToolkitInstance.services.runner._portosActiveRuns?.delete(runId);+ toolkit.services.runner._portosActiveRuns?.delete(runId);await writeFile(outputPath, output);@@ -307,8 +319,8 @@ export async function executeCliRun(runId, provider, prompt, workspacePath, onDametadata.outputSize = Buffer.byteLength(output);// Analyze errors if the run failed (delegate to toolkit's error detection)- if (!metadata.success && aiToolkitInstance.services.errorDetection) {- const errorAnalysis = aiToolkitInstance.services.errorDetection.analyzeError(output, code);+ if (!metadata.success && toolkit.services.errorDetection) {+ const errorAnalysis = toolkit.services.errorDetection.analyzeError(output, code);metadata.error = errorAnalysis.message || `Process exited with code ${code}`;metadata.errorCategory = errorAnalysis.category;metadata.errorAnalysis = errorAnalysis;@@ -329,8 +341,7 @@ export async function executeCliRun(runId, provider, prompt, workspacePath, onDa}export async function executeApiRun(runId, provider, model, prompt, workspacePath, screenshots, onData, onComplete) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.executeApiRun(runId, provider, model, prompt, workspacePath, screenshots, onData, onComplete);+ return requireToolkit().services.runner.executeApiRun(runId, provider, model, prompt, workspacePath, screenshots, onData, onComplete);}/**@@ -340,11 +351,11 @@ export async function executeApiRun(runId, provider, model, prompt, workspacePat* CLI runs can. Both ChildProcess and node-pty IPty expose `.kill(signal?)`.*/export function registerActiveRun(runId, killable) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- if (!aiToolkitInstance.services.runner._portosActiveRuns) {- aiToolkitInstance.services.runner._portosActiveRuns = new Map();+ const toolkit = requireToolkit();+ if (!toolkit.services.runner._portosActiveRuns) {+ toolkit.services.runner._portosActiveRuns = new Map();}- aiToolkitInstance.services.runner._portosActiveRuns.set(runId, killable);+ toolkit.services.runner._portosActiveRuns.set(runId, killable);}export function unregisterActiveRun(runId) {@@ -352,48 +363,41 @@ export function unregisterActiveRun(runId) {}export async function stopRun(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');+ const toolkit = requireToolkit();// Check local active runs first (CLI runs spawned by this override)- const localProcess = aiToolkitInstance.services.runner._portosActiveRuns?.get(runId);+ const localProcess = toolkit.services.runner._portosActiveRuns?.get(runId);if (localProcess && !localProcess.killed) {localProcess.kill('SIGTERM');- aiToolkitInstance.services.runner._portosActiveRuns.delete(runId);+ toolkit.services.runner._portosActiveRuns.delete(runId);return { stopped: true, runId };}- return aiToolkitInstance.services.runner.stopRun(runId);+ return toolkit.services.runner.stopRun(runId);}export async function getRun(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.getRun(runId);+ return requireToolkit().services.runner.getRun(runId);}export async function getRunOutput(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.getRunOutput(runId);+ return requireToolkit().services.runner.getRunOutput(runId);}export async function getRunPrompt(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.getRunPrompt(runId);+ return requireToolkit().services.runner.getRunPrompt(runId);}export async function listRuns(limit, offset, source) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.listRuns(limit, offset, source);+ return requireToolkit().services.runner.listRuns(limit, offset, source);}export async function deleteRun(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.deleteRun(runId);+ return requireToolkit().services.runner.deleteRun(runId);}export async function deleteFailedRuns() {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.deleteFailedRuns();+ return requireToolkit().services.runner.deleteFailedRuns();}export async function isRunActive(runId) {- if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.isRunActive(runId);+ return requireToolkit().services.runner.isRunActive(runId);}