@ai-ecoverse/slicc-agent 3.36.2 → 3.37.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/README.md +56 -2
- package/dist/client.js +3 -1
- package/dist/client.js.map +2 -2
- package/dist/control.js +3 -1
- package/dist/control.js.map +2 -2
- package/dist/host.js +14 -3
- package/dist/host.js.map +2 -2
- package/dist/kernel/groups.js +6 -0
- package/dist/kernel/groups.js.map +2 -2
- package/dist/main.js +7 -1
- package/dist/main.js.map +2 -2
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +2 -2
- package/dist/mcp/runtime.js +1 -0
- package/dist/mcp/runtime.js.map +2 -2
- package/dist/memory/format.js +8 -0
- package/dist/memory/format.js.map +2 -2
- package/dist/monitor/index.js +449 -0
- package/dist/monitor/index.js.map +7 -0
- package/dist/monitor/redact.js +25 -0
- package/dist/monitor/redact.js.map +7 -0
- package/dist/readonly.js +1 -1
- package/dist/readonly.js.map +2 -2
- package/dist/services.js.map +2 -2
- package/dist/spectrum/index.js +12 -1
- package/dist/spectrum/index.js.map +3 -3
- package/dist/spectrum/monitor-port.js +621 -0
- package/dist/spectrum/monitor-port.js.map +7 -0
- package/dist/spectrum/tray-port.js +0 -2
- package/dist/spectrum/tray-port.js.map +2 -2
- package/dist/types/client.d.ts +2 -1
- package/dist/types/control.d.ts +2 -1
- package/dist/types/host.d.ts +2 -0
- package/dist/types/kernel/groups.d.ts +1 -0
- package/dist/types/mcp/runtime.d.ts +1 -0
- package/dist/types/monitor/index.d.ts +67 -0
- package/dist/types/monitor/redact.d.ts +5 -0
- package/dist/types/services.d.ts +71 -0
- package/dist/types/spectrum/index.d.ts +7 -0
- package/dist/types/spectrum/monitor-port.d.ts +70 -0
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/spectrum/monitor-port.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n MonitorAlert,\n MonitorEvents,\n MonitorPort,\n MonitorRow,\n MonitorSection,\n MonitorSnapshot,\n MonitorStatus,\n MonitorVital,\n} from '@ai-ecoverse/slicc-spectrum/ui';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { AgentConnection } from '../client.ts';\nimport type {\n BudgetState,\n ModelChoice,\n MonitorAgent,\n MonitorFeed,\n MonitorProcess,\n MonitorTask,\n} from '../services.ts';\nimport { Emitter } from './emitter.ts';\n\nexport const RENEW_MS = 10000;\nexport const ROWS_MAX = 200;\nexport const HISTORY = 24;\nexport const BUDGET_WARN = 80;\nexport const BUDGET_ERROR = 95;\nexport const RETRY_WARN = 3;\nexport const RETRY_ERROR = 6;\nexport const RETRY_SLOW_MS = 120000;\nexport const FAILED_MS = 600000;\nexport const ABORT_MS = 30000;\nexport const ABORT_ROW_MS = 10000;\nexport const GROUP_MAX = 32;\nexport const TOTAL_MAX = 128;\nexport const ZOMBIE_MS = 60000;\nexport const STALE_MS = 1800000;\nexport const CONTEXT_WARN = 0.8;\nexport const DEPTH_MAX = 6;\nconst MINUTE = 60000;\nconst HOUR = 3600000;\n\nexport interface Sample {\n at: number;\n cost: number;\n tokens: number;\n active: number;\n}\n\nexport interface MonitorInput {\n feed: MonitorFeed | undefined;\n budget: BudgetState | null | undefined;\n models: readonly ModelChoice[];\n changes: readonly { path: string; status: string }[];\n sprinkles: readonly { name: string; title: string }[];\n extra: readonly MonitorSection[];\n history: readonly Sample[];\n now: number;\n}\n\nconst KINDS: Record<string, string> = {\n 'pi.generation': 'generating',\n 'pi.compaction': 'compacting',\n 'slicc.cron': 'cron',\n 'slicc.scoop-wait': 'agent wait',\n 'slicc.scoop-reporter': 'report',\n 'slicc.memory-extract': 'memory extraction',\n};\n\nexport function age(ms: number): string {\n const seconds = Math.max(0, Math.round(ms / 1000));\n if (seconds < 60) return `${seconds}s`;\n if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;\n return `${Math.floor(seconds / 3600)}h`;\n}\n\nexport function money(value: number): string {\n return `$${value.toFixed(2)}`;\n}\n\nexport function count(value: number): string {\n if (value < 1000) return String(value);\n if (value < 1000000) return `${(value / 1000).toFixed(1)}k`;\n return `${(value / 1000000).toFixed(1)}M`;\n}\n\nexport function bytes(value: number): string {\n if (value < 1024) return `${value} B`;\n const units = ['KiB', 'MiB', 'GiB', 'TiB'];\n let size = value / 1024;\n let unit = 0;\n while (size >= 1024 && unit < units.length - 1) {\n size /= 1024;\n unit++;\n }\n return `${size.toFixed(size < 10 ? 1 : 0)} ${units[unit]}`;\n}\n\nfunction memoryVital(processes: readonly MonitorProcess[]): MonitorVital[] {\n const measured = processes.filter((row) => typeof row.rss === 'number');\n if (!measured.length) return [];\n const total = measured.reduce((sum, row) => sum + (row.rss as number), 0);\n const agents = measured\n .filter((row) => row.agentId)\n .reduce((sum, row) => sum + (row.rss as number), 0);\n return [\n {\n id: 'memory',\n label: 'Process memory',\n value: bytes(total),\n unit: `${bytes(agents)} by agents`,\n },\n ];\n}\n\nexport function taskLabel(task: MonitorTask): string {\n if (task.kind === 'pi.tool') return task.detail ? `tool ${task.detail}` : 'tool';\n if (task.kind === 'slicc.scoop-anchor') return task.detail ? `scoop ${task.detail}` : 'scoop';\n return KINDS[task.kind] ?? task.kind;\n}\n\nfunction coneOf(agents: ReadonlyMap<string, MonitorAgent>, id: string | null): string | null {\n const visited = new Set<string>();\n let current = id === null ? undefined : agents.get(id);\n while (current?.parentId && !visited.has(current.id)) {\n visited.add(current.id);\n const parent = agents.get(current.parentId);\n if (!parent) break;\n current = parent;\n }\n return current ? current.id : null;\n}\n\nfunction ordered(feed: MonitorFeed): MonitorAgent[] {\n const byId = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out: MonitorAgent[] = [];\n for (const cone of feed.agents.filter((agent) => agent.kind === 'cone')) {\n out.push(cone);\n for (const agent of feed.agents)\n if (agent.kind === 'scoop' && coneOf(byId, agent.id) === cone.id) out.push(agent);\n }\n for (const agent of feed.agents) if (!out.includes(agent)) out.push(agent);\n return out;\n}\n\nexport function taskTree(feed: MonitorFeed): { task: MonitorTask; depth: number }[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const order = ordered(feed).map((agent) => agent.id);\n const rank = (task: MonitorTask) => {\n const at = task.agentId === null ? -1 : order.indexOf(task.agentId);\n return at < 0 ? order.length : at;\n };\n const groupOf = (task: MonitorTask) => coneOf(agents, task.agentId) ?? '';\n const byId = new Map(feed.tasks.map((task) => [task.id, task]));\n const children = new Map<string, MonitorTask[]>();\n const roots: MonitorTask[] = [];\n for (const task of feed.tasks) {\n const owner = task.owner === null ? undefined : byId.get(task.owner);\n if (owner && groupOf(owner) === groupOf(task)) {\n const list = children.get(owner.id) ?? [];\n list.push(task);\n children.set(owner.id, list);\n } else roots.push(task);\n }\n const sort = (list: MonitorTask[]) =>\n list.sort((a, b) => rank(a) - rank(b) || Number(a.id) - Number(b.id));\n const out: { task: MonitorTask; depth: number }[] = [];\n const visit = (task: MonitorTask, depth: number) => {\n out.push({ task, depth });\n for (const child of sort(children.get(task.id) ?? [])) visit(child, depth + 1);\n };\n for (const root of sort(roots)) visit(root, 0);\n return out;\n}\n\nfunction capped(rows: MonitorRow[]): MonitorRow[] {\n if (rows.length <= ROWS_MAX) return rows;\n const shown = rows.slice(0, ROWS_MAX - 1);\n return [\n ...shown,\n { id: 'more', name: `+${rows.length - shown.length} more`, meta: '', status: 'idle' },\n ];\n}\n\nfunction contextRatio(agent: MonitorAgent, models: readonly ModelChoice[]): number | null {\n const window = models.find((model) => model.id === agent.model)?.contextWindow;\n if (!agent.context || !window) return null;\n return Math.min(1, agent.context / window);\n}\n\nfunction rate(history: readonly Sample[], pick: (sample: Sample) => number): number | null {\n const first = history[0];\n const last = history.at(-1);\n if (!first || !last || last.at - first.at < MINUTE) return null;\n return ((pick(last) - pick(first)) / (last.at - first.at)) * HOUR;\n}\n\nfunction budgetVital(budget: BudgetState): MonitorVital {\n const resets = new Date(budget.resets);\n return {\n id: 'budget',\n label: `Budget (${budget.window})`,\n value: `${budget.percent}%`,\n ...(Number.isNaN(resets.getTime())\n ? {}\n : { unit: `resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC` }),\n ratio: Math.min(1, Math.max(0, budget.percent / 100)),\n };\n}\n\nfunction vitals(input: MonitorInput, feed: MonitorFeed): MonitorVital[] {\n const out: MonitorVital[] = [];\n if (feed.usage) {\n const free = feed.usage.free;\n const pick = (sample: Sample) => (free ? sample.tokens : sample.cost);\n const perHour = rate(input.history, pick);\n const series = input.history.map(pick);\n out.push({\n id: 'spend',\n label: free ? 'Tokens' : 'Spend',\n value: free ? count(feed.usage.tokens) : money(feed.usage.cost),\n unit: free ? 'tokens' : `${count(feed.usage.tokens)} tokens`,\n ...(perHour === null ? {} : { delta: `${free ? count(perHour) : money(perHour)}/h` }),\n ...(series.length > 1 ? { series } : {}),\n });\n }\n const active = feed.agents.filter((agent) => agent.running).length;\n const actives = input.history.map((sample) => sample.active);\n out.push({\n id: 'agents',\n label: 'Active agents',\n value: String(active),\n unit: `of ${feed.agents.length}`,\n ...(actives.length > 1 ? { series: actives } : {}),\n });\n const tools = feed.tasks.filter(\n (task) => task.kind === 'pi.tool' && task.status === 'running'\n ).length;\n out.push({\n id: 'tasks',\n label: 'Running',\n value: String(tools),\n unit: `${tools === 1 ? 'tool' : 'tools'} \u00B7 ${feed.tasks.length} ${feed.tasks.length === 1 ? 'task' : 'tasks'}`,\n });\n out.push(\n feed.processes\n ? {\n id: 'processes',\n label: 'Processes',\n value: String(feed.processes.length),\n unit: `${feed.processes.filter((row) => row.agentId).length} by agents`,\n }\n : { id: 'processes', label: 'Processes', value: '\u2014', unit: 'kernel not reachable' }\n );\n out.push(...memoryVital(feed.processes ?? []));\n const ratios = feed.agents\n .map((agent) => contextRatio(agent, input.models))\n .filter((ratio): ratio is number => ratio !== null);\n if (ratios.length) {\n const fullest = Math.max(...ratios);\n out.push({\n id: 'context',\n label: 'Fullest context',\n value: `${Math.round(fullest * 100)}%`,\n ratio: fullest,\n });\n }\n return out;\n}\n\nfunction stale(process: MonitorProcess, agents: ReadonlyMap<string, MonitorAgent>, now: number) {\n if (!process.agentId || process.state === 'Z' || !process.started) return false;\n if (agents.get(process.agentId)?.tool === 'bash') return false;\n return now - process.started > STALE_MS;\n}\n\nfunction groups(processes: readonly MonitorProcess[]): Map<number, MonitorProcess[]> {\n const out = new Map<number, MonitorProcess[]>();\n for (const process of processes) {\n if (!process.agentId) continue;\n const list = out.get(process.pgid) ?? [];\n list.push(process);\n out.set(process.pgid, list);\n }\n return out;\n}\n\ntype Names = (id: string | null) => string;\n\nfunction resetLine(budget: BudgetState): string {\n const resets = new Date(budget.resets);\n return Number.isNaN(resets.getTime())\n ? `The ${budget.window} budget is nearly used up.`\n : `Resets ${resets.toISOString().slice(0, 16).replace('T', ' ')} UTC.`;\n}\n\nfunction budgetAlerts(budget: BudgetState | null | undefined): MonitorAlert[] {\n if (!budget || budget.percent < BUDGET_WARN) return [];\n return [\n {\n id: 'budget',\n title: `Budget ${budget.percent}% used`,\n detail: resetLine(budget),\n severity: budget.percent >= BUDGET_ERROR ? 'error' : 'warn',\n },\n ];\n}\n\nfunction agentAlerts(input: MonitorInput, feed: MonitorFeed): MonitorAlert[] {\n const out: MonitorAlert[] = [];\n for (const agent of feed.agents) {\n const retry = agent.retry;\n if (retry && (retry.attempt >= RETRY_WARN || input.now - retry.since > RETRY_SLOW_MS))\n out.push({\n id: `retry-${agent.id}`,\n title: `${agent.name} is retrying (attempt ${retry.attempt})`,\n detail: retry.error,\n severity: retry.attempt >= RETRY_ERROR ? 'error' : 'warn',\n });\n if (agent.failed && !agent.running)\n out.push({\n id: `turn-${agent.id}`,\n title: `${agent.name}'s last turn failed`,\n detail: agent.failed,\n severity: 'error',\n });\n }\n return out;\n}\n\nfunction taskAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): MonitorAlert[] {\n const out: MonitorAlert[] = [];\n for (const problem of feed.problems)\n if (problem.kind === 'task' && input.now - problem.at < FAILED_MS)\n out.push({\n id: `failed-${problem.id}`,\n title: `A task of ${nameOf(problem.agentId)} failed`,\n detail: problem.message,\n severity: 'error',\n });\n for (const task of feed.tasks)\n if (task.aborting !== null && input.now - task.aborting > ABORT_MS)\n out.push({\n id: `abort-${task.id}`,\n title: `Stop is still waiting for ${taskLabel(task)}`,\n detail: `${nameOf(task.agentId)} asked it to stop ${age(input.now - task.aborting)} ago.`,\n severity: 'warn',\n });\n return out;\n}\n\nfunction crowdAlerts(processes: readonly MonitorProcess[], nameOf: Names): MonitorAlert[] {\n const out: MonitorAlert[] = [];\n for (const [pgid, members] of groups(processes))\n if (members.length > GROUP_MAX)\n out.push({\n id: `runaway-${pgid}`,\n title: `${nameOf((members[0] as MonitorProcess).agentId)} has ${members.length} processes`,\n detail: `Kill them with kill -- -${pgid}.`,\n severity: members.length > GROUP_MAX * 2 ? 'error' : 'warn',\n });\n if (processes.length > TOTAL_MAX)\n out.push({\n id: 'runaway-total',\n title: `The kernel has ${processes.length} processes`,\n detail: 'Something may be starting processes in a loop.',\n severity: processes.length > TOTAL_MAX * 2 ? 'error' : 'warn',\n });\n return out;\n}\n\nfunction processAlerts(input: MonitorInput, feed: MonitorFeed, nameOf: Names): MonitorAlert[] {\n const processes = feed.processes ?? [];\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const out = crowdAlerts(processes, nameOf);\n for (const process of processes) {\n if (process.zombie !== null && input.now - process.zombie > ZOMBIE_MS)\n out.push({\n id: `zombie-${process.pid}`,\n title: `Process ${process.pid} is a zombie`,\n detail: `Its parent ${process.ppid} hasn't reaped it.`,\n severity: 'warn',\n });\n if (stale(process, agents, input.now))\n out.push({\n id: `stale-${process.pid}`,\n title: `${process.command || `Process ${process.pid}`} has run for ${age(input.now - process.started)}`,\n detail: `${nameOf(process.agentId)} started it in the background. Kill it with kill ${process.pid}.`,\n severity: input.now - process.started > STALE_MS * 2 ? 'error' : 'warn',\n });\n }\n return out;\n}\n\nfunction contextAlerts(input: MonitorInput, feed: MonitorFeed): MonitorAlert[] {\n const out: MonitorAlert[] = [];\n for (const agent of feed.agents) {\n const ratio = contextRatio(agent, input.models);\n if (ratio !== null && ratio >= CONTEXT_WARN)\n out.push({\n id: `context-${agent.id}`,\n title: `${agent.name} is ${Math.round(ratio * 100)}% full`,\n detail: 'Compact it soon to keep replies fast.',\n severity: 'warn',\n });\n }\n if (feed.paused)\n out.push({\n id: 'scheduler',\n title: \"The agent isn't scheduling work\",\n detail: 'Its scheduler is paused.',\n severity: 'warn',\n });\n return out;\n}\n\nfunction alerts(input: MonitorInput, feed: MonitorFeed): MonitorAlert[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf: Names = (id) => (id ? (agents.get(id)?.name ?? id) : 'the session');\n return [\n ...budgetAlerts(input.budget),\n ...agentAlerts(input, feed),\n ...taskAlerts(input, feed, nameOf),\n ...processAlerts(input, feed, nameOf),\n ...contextAlerts(input, feed),\n ];\n}\n\nfunction agentRow(agent: MonitorAgent, depth: number, models: readonly ModelChoice[]): MonitorRow {\n const ratio = contextRatio(agent, models);\n const word = agent.retry\n ? 'retrying'\n : agent.running\n ? 'running'\n : agent.failed\n ? 'failed'\n : 'idle';\n const status: MonitorStatus = agent.retry\n ? 'warn'\n : agent.running\n ? 'active'\n : agent.failed\n ? 'error'\n : 'idle';\n const meta = [word, agent.model, ratio === null ? null : `${Math.round(ratio * 100)}% context`]\n .filter(Boolean)\n .join(' \u00B7 ');\n const badges = [\n ...(agent.queued ? [`${agent.queued} queued`] : []),\n ...(agent.tool ? [agent.tool] : []),\n ...(agent.retry ? [`retry ${agent.retry.attempt}`] : []),\n ];\n return {\n id: agent.id,\n name: agent.name,\n meta,\n status,\n depth,\n ...(badges.length ? { badges } : {}),\n };\n}\n\nfunction taskRow(\n task: MonitorTask,\n depth: number,\n nameOf: (id: string | null) => string,\n now: number\n): MonitorRow {\n const aborting = task.aborting !== null && now - task.aborting > ABORT_ROW_MS;\n const status: MonitorStatus = aborting\n ? 'warn'\n : task.status === 'running' || task.status === 'completing'\n ? 'active'\n : 'idle';\n const badges = [\n ...(task.background ? ['background'] : []),\n ...(task.aborting !== null ? ['aborting'] : []),\n ...(task.waits ? [`waits on ${task.waits}`] : []),\n ];\n return {\n id: task.id,\n name: taskLabel(task),\n depth: Math.min(depth, DEPTH_MAX),\n meta: [nameOf(task.agentId), task.phase, age(now - task.since)].filter(Boolean).join(' \u00B7 '),\n status,\n ...(badges.length ? { badges } : {}),\n };\n}\n\nfunction processRows(input: MonitorInput, feed: MonitorFeed): MonitorRow[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const crowded = new Set<number>();\n for (const [pgid, members] of groups(feed.processes ?? []))\n if (members.length > GROUP_MAX) crowded.add(pgid);\n return (feed.processes ?? []).map((process) => {\n const runaway = stale(process, agents, input.now) || crowded.has(process.pgid);\n const badges = [\n ...(process.agentId ? [agents.get(process.agentId)?.name ?? process.agentId] : []),\n ...(process.tty ? ['terminal'] : []),\n ];\n return {\n id: String(process.pid),\n name: process.command || `[${process.pid}]`,\n meta: [\n `pid ${process.pid}`,\n process.user,\n typeof process.rss === 'number' ? bytes(process.rss) : null,\n process.started ? age(input.now - process.started) : null,\n ]\n .filter(Boolean)\n .join(' \u00B7 '),\n status: runaway ? 'error' : process.state === 'Z' ? 'warn' : 'idle',\n ...(badges.length ? { badges } : {}),\n };\n });\n}\n\nconst PROBLEM_KINDS = { task: 'task failed', retry: 'retry', turn: 'turn failed' } as const;\n\nfunction depthOf(agents: ReadonlyMap<string, MonitorAgent>, agent: MonitorAgent): number {\n const visited = new Set<string>();\n let depth = 0;\n let current = agent;\n while (current.parentId && !visited.has(current.id)) {\n visited.add(current.id);\n const parent = agents.get(current.parentId);\n if (!parent) break;\n depth++;\n current = parent;\n }\n return depth;\n}\n\nfunction sections(input: MonitorInput, feed: MonitorFeed): MonitorSection[] {\n const agents = new Map(feed.agents.map((agent) => [agent.id, agent]));\n const nameOf = (id: string | null) => (id ? (agents.get(id)?.name ?? id) : 'session');\n return [\n {\n id: 'agents',\n label: 'Cones and scoops',\n rows: ordered(feed).map((agent) =>\n agentRow(agent, Math.min(depthOf(agents, agent), DEPTH_MAX), input.models)\n ),\n },\n {\n id: 'tasks',\n label: 'Tasks',\n rows: capped(\n taskTree(feed).map(({ task, depth }) => taskRow(task, depth, nameOf, input.now))\n ),\n },\n { id: 'processes', label: 'Processes', rows: capped(processRows(input, feed)) },\n {\n id: 'problems',\n label: 'Recent problems',\n rows: feed.problems.map((problem) => ({\n id: problem.id,\n name: `${nameOf(problem.agentId)} \u00B7 ${PROBLEM_KINDS[problem.kind]}`,\n meta: problem.message,\n status: problem.kind === 'retry' ? 'warn' : 'error',\n })),\n },\n ];\n}\n\nfunction pageSections(input: MonitorInput): MonitorSection[] {\n return [\n {\n id: 'changes',\n label: 'Pending changes',\n rows: input.changes.map((change) => ({\n id: change.path,\n name: change.path,\n meta: change.status,\n status: 'warn',\n })),\n },\n {\n id: 'sprinkles',\n label: 'Sprinkles',\n rows: input.sprinkles.map((sprinkle) => ({\n name: sprinkle.title,\n meta: sprinkle.name,\n status: 'idle',\n })),\n },\n ...input.extra,\n ];\n}\n\nexport function monitorSnapshot(input: MonitorInput): MonitorSnapshot {\n const budget = input.budget ? [budgetVital(input.budget)] : [];\n const feed = input.feed;\n if (!feed?.at)\n return {\n vitals: budget,\n alerts: [],\n sections: pageSections(input),\n updatedAt: input.now,\n };\n return {\n vitals: [...budget, ...vitals(input, feed)],\n alerts: alerts(input, feed),\n sections: [...sections(input, feed), ...pageSections(input)],\n updatedAt: feed.at,\n };\n}\n\nexport interface Intervals {\n every(run: () => void, ms: number): unknown;\n stop(handle: unknown): void;\n}\n\nexport const globalIntervals: Intervals = {\n every: (run, ms) => setInterval(run, ms),\n stop: (handle) => clearInterval(handle as ReturnType<typeof setInterval>),\n};\n\nexport interface MonitorAdapterOptions {\n extra?: () => readonly MonitorSection[];\n renewMs?: number;\n intervals?: Intervals;\n now?: () => number;\n}\n\ninterface Open {\n lease: Promise<string | null>;\n timer: unknown;\n}\n\nexport class MonitorAdapter implements MonitorPort {\n readonly #connection: AgentConnection;\n readonly #emitter = new Emitter<MonitorEvents>();\n readonly #extra: () => readonly MonitorSection[];\n readonly #renewMs: number;\n readonly #intervals: Intervals;\n readonly #now: () => number;\n #listeners = 0;\n #open: Open | undefined;\n #history: Sample[] = [];\n\n constructor(connection: AgentConnection, options: MonitorAdapterOptions = {}) {\n this.#connection = connection;\n this.#extra = options.extra ?? (() => []);\n this.#renewMs = options.renewMs ?? RENEW_MS;\n this.#intervals = options.intervals ?? globalIntervals;\n this.#now = options.now ?? Date.now;\n connection.monitor?.subscribe(() => this.#update());\n connection.settings.state.subscribe(() => this.#update());\n connection.changes?.subscribe(() => this.#update());\n connection.sprinkles?.subscribe(() => this.#update());\n }\n\n on<K extends keyof MonitorEvents>(\n type: K,\n listener: (detail: MonitorEvents[K]) => void\n ): () => void {\n const off = this.#emitter.on(type, listener);\n this.#listeners++;\n if (this.#listeners === 1) this.#start();\n let done = false;\n return () => {\n if (done) return;\n done = true;\n off();\n this.#listeners--;\n if (!this.#listeners) this.#stop();\n };\n }\n\n snapshot(): MonitorSnapshot {\n const settings = this.#connection.settings.state.value;\n return monitorSnapshot({\n feed: this.#connection.monitor?.value,\n budget: settings?.budget,\n models: settings?.models ?? [],\n changes: this.#connection.changes?.value?.changes ?? [],\n sprinkles: this.#connection.sprinkles?.value ?? [],\n extra: this.#extra(),\n history: this.#history,\n now: this.#now(),\n });\n }\n\n resync(): void {\n const open = this.#open;\n const control = this.#connection.control;\n if (open)\n void open.lease\n .then((lease) => (lease ? control.monitorOpen(lease, true, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#emitter.emit('snapshot', this.snapshot());\n }\n\n #start(): void {\n const control = this.#connection.control;\n this.#history = [];\n void control.changesOpen(BACKGROUND_CONTEXT).catch(() => undefined);\n const lease = control.monitorOpen(null, true, BACKGROUND_CONTEXT).then(\n (opened) => opened.lease || null,\n () => null\n );\n const renew = () =>\n void lease\n .then((held) => (held ? control.monitorOpen(held, false, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n this.#open = { lease, timer: this.#intervals.every(renew, this.#renewMs) };\n }\n\n #stop(): void {\n const open = this.#open;\n if (!open) return;\n this.#open = undefined;\n this.#intervals.stop(open.timer);\n const control = this.#connection.control;\n void open.lease\n .then((held) => (held ? control.monitorClose(held, BACKGROUND_CONTEXT) : undefined))\n .catch(() => undefined);\n }\n\n #sample(): void {\n const feed = this.#connection.monitor?.value;\n if (!feed?.open || !feed.usage || this.#history.at(-1)?.at === feed.at) return;\n this.#history.push({\n at: feed.at,\n cost: feed.usage.cost,\n tokens: feed.usage.tokens,\n active: feed.agents.filter((agent) => agent.running).length,\n });\n if (this.#history.length > HISTORY) this.#history.shift();\n }\n\n #update(): void {\n if (!this.#listeners) return;\n this.#sample();\n this.#emitter.emit('snapshot', this.snapshot());\n }\n}\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,0BAA0B;AAUnC,SAAS,eAAe;AAEjB,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,YAAY;AACzB,MAAM,SAAS;AACf,MAAM,OAAO;AAoBb,MAAM,QAAgC;AAAA,EACpC,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,wBAAwB;AAC1B;AAEO,SAAS,IAAI,IAAoB;AACtC,QAAM,UAAU,KAAK,IAAI,G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SAAK,KAAK,MACP,KAAK,CAAC,SAAU,OAAO,QAAQ,aAAa,MAAM,kBAAkB,IAAI,MAAU,EAClF,MAAM,MAAM,MAAS;AAAA,EAC1B;AAAA,EAEA,UAAgB;AACd,UAAM,OAAO,KAAK,YAAY,SAAS;AACvC,QAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,SAAS,KAAK,SAAS,GAAG,EAAE,GAAG,OAAO,KAAK,GAAI;AACxE,SAAK,SAAS,KAAK;AAAA,MACjB,IAAI,KAAK;AAAA,MACT,MAAM,KAAK,MAAM;AAAA,MACjB,QAAQ,KAAK,MAAM;AAAA,MACnB,QAAQ,KAAK,OAAO,OAAO,CAAC,UAAU,MAAM,OAAO,EAAE;AAAA,IACvD,CAAC;AACD,QAAI,KAAK,SAAS,SAAS,QAAS,MAAK,SAAS,MAAM;AAAA,EAC1D;AAAA,EAEA,UAAgB;AACd,QAAI,CAAC,KAAK,WAAY;AACtB,SAAK,QAAQ;AACb,SAAK,SAAS,KAAK,YAAY,KAAK,SAAS,CAAC;AAAA,EAChD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -14,8 +14,6 @@ class TrayAdapter extends Emitter {
|
|
|
14
14
|
connection: "offline",
|
|
15
15
|
role: "none",
|
|
16
16
|
followers: [],
|
|
17
|
-
spent: 0,
|
|
18
|
-
rate: 0,
|
|
19
17
|
budget: budget ? { percent: budget.percent, window: budget.window, resets: budget.resets } : { percent: 0, window: "weekly", resets: "" },
|
|
20
18
|
joinUrl: ""
|
|
21
19
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spectrum/tray-port.ts"],
|
|
4
|
-
"sourcesContent": ["import type { TrayEvents, TrayPort, TrayStatus } from '@ai-ecoverse/slicc-spectrum/ui';\nimport type { AgentSettings } from '../services.ts';\nimport { Emitter } from './emitter.ts';\n\nexport class TrayAdapter extends Emitter<TrayEvents> implements TrayPort {\n readonly #settings: AgentSettings;\n\n constructor(settings: AgentSettings) {\n super();\n this.#settings = settings;\n settings.state.subscribe(() => this.emit('status', this.status()));\n }\n\n status(): TrayStatus {\n const budget = this.#settings.state.value?.budget;\n return {\n name: 'slicc',\n kind: 'hosted',\n connection: 'offline',\n role: 'none',\n followers: [],\n
|
|
5
|
-
"mappings": "AAEA,SAAS,eAAe;AAEjB,MAAM,oBAAoB,QAAwC;AAAA,EAC9D;AAAA,EAET,YAAY,UAAyB;AACnC,UAAM;AACN,SAAK,YAAY;AACjB,aAAS,MAAM,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,OAAO,CAAC,CAAC;AAAA,EACnE;AAAA,EAEA,SAAqB;AACnB,UAAM,SAAS,KAAK,UAAU,MAAM,OAAO;AAC3C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,WAAW,CAAC;AAAA,MACZ,
|
|
4
|
+
"sourcesContent": ["import type { TrayEvents, TrayPort, TrayStatus } from '@ai-ecoverse/slicc-spectrum/ui';\nimport type { AgentSettings } from '../services.ts';\nimport { Emitter } from './emitter.ts';\n\nexport class TrayAdapter extends Emitter<TrayEvents> implements TrayPort {\n readonly #settings: AgentSettings;\n\n constructor(settings: AgentSettings) {\n super();\n this.#settings = settings;\n settings.state.subscribe(() => this.emit('status', this.status()));\n }\n\n status(): TrayStatus {\n const budget = this.#settings.state.value?.budget;\n return {\n name: 'slicc',\n kind: 'hosted',\n connection: 'offline',\n role: 'none',\n followers: [],\n budget: budget\n ? { percent: budget.percent, window: budget.window, resets: budget.resets }\n : { percent: 0, window: 'weekly', resets: '' },\n joinUrl: '',\n };\n }\n\n reconnect(): void {}\n\n disconnect(): void {}\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,eAAe;AAEjB,MAAM,oBAAoB,QAAwC;AAAA,EAC9D;AAAA,EAET,YAAY,UAAyB;AACnC,UAAM;AACN,SAAK,YAAY;AACjB,aAAS,MAAM,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,OAAO,CAAC,CAAC;AAAA,EACnE;AAAA,EAEA,SAAqB;AACnB,UAAM,SAAS,KAAK,UAAU,MAAM,OAAO;AAC3C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,WAAW,CAAC;AAAA,MACZ,QAAQ,SACJ,EAAE,SAAS,OAAO,SAAS,QAAQ,OAAO,QAAQ,QAAQ,OAAO,OAAO,IACxE,EAAE,SAAS,GAAG,QAAQ,UAAU,QAAQ,GAAG;AAAA,MAC/C,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EAEA,YAAkB;AAAA,EAAC;AAAA,EAEnB,aAAmB;AAAA,EAAC;AACtB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/types/client.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ChangesView } from './changes/git.ts';
|
|
|
4
4
|
import type { FrozenCone } from './freezer/index.ts';
|
|
5
5
|
import type { MemoryEntry, MemoryScope } from './memory/format.ts';
|
|
6
6
|
import type { AgentRemote } from './remote/host.ts';
|
|
7
|
-
import { AgentControl, AgentSettings, type AgentsSummary, type Command, type Delivered, type SendMode } from './services.ts';
|
|
7
|
+
import { AgentControl, AgentSettings, type AgentsSummary, type Command, type Delivered, type MonitorFeed, type SendMode } from './services.ts';
|
|
8
8
|
import type { Sprinkle } from './sprinkles/kind.ts';
|
|
9
9
|
import { type PortEndpoint } from './wire.ts';
|
|
10
10
|
export interface AgentConnection {
|
|
@@ -20,6 +20,7 @@ export interface AgentConnection {
|
|
|
20
20
|
readonly memoryScopes?: ReplicatedState<MemoryScope[]>;
|
|
21
21
|
readonly frozen?: ReplicatedState<FrozenCone[]>;
|
|
22
22
|
readonly changes?: ReplicatedState<ChangesView>;
|
|
23
|
+
readonly monitor?: ReplicatedState<MonitorFeed>;
|
|
23
24
|
readonly settings: AgentSettings;
|
|
24
25
|
readonly remote?: AgentRemote;
|
|
25
26
|
readonly closed: Promise<Error | undefined>;
|
package/dist/types/control.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Deliveries } from './deliveries.ts';
|
|
|
5
5
|
import type { FreezerRuntime } from './freezer/index.ts';
|
|
6
6
|
import type { LickSources, Licks } from './licks/index.ts';
|
|
7
7
|
import type { MemoryRuntime } from './memory/index.ts';
|
|
8
|
+
import type { Monitor } from './monitor/index.ts';
|
|
8
9
|
import type { Scoops, ScoopsRuntime } from './scoops/index.ts';
|
|
9
10
|
import type { AgentControl } from './services.ts';
|
|
10
11
|
import type { SkillsRuntime } from './skills/index.ts';
|
|
@@ -19,4 +20,4 @@ export interface HostScoops {
|
|
|
19
20
|
}
|
|
20
21
|
export declare function readable(out: string): string;
|
|
21
22
|
export declare function submissionId(value: string): SubmissionId | undefined;
|
|
22
|
-
export declare function createAgentControl(harness: Harness, target: Conversation | Cones, deliveries?: Deliveries, licks?: HostLicks, scoops?: HostScoops, skills?: Pick<SkillsRuntime, 'expand'>, sprinkles?: Pick<SprinklesRuntime, 'send' | 'call'>, memory?: Pick<MemoryRuntime, 'save' | 'remove'>, freezer?: Pick<FreezerRuntime, 'freeze' | 'newChat' | 'thaw' | 'discard'>, changes?: Pick<ChangesRuntime, 'open' | 'accept' | 'revert'>): AgentControl;
|
|
23
|
+
export declare function createAgentControl(harness: Harness, target: Conversation | Cones, deliveries?: Deliveries, licks?: HostLicks, scoops?: HostScoops, skills?: Pick<SkillsRuntime, 'expand'>, sprinkles?: Pick<SprinklesRuntime, 'send' | 'call'>, memory?: Pick<MemoryRuntime, 'save' | 'remove'>, freezer?: Pick<FreezerRuntime, 'freeze' | 'newChat' | 'thaw' | 'discard'>, changes?: Pick<ChangesRuntime, 'open' | 'accept' | 'revert'>, monitor?: Pick<Monitor, 'open' | 'close'>): AgentControl;
|
package/dist/types/host.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { FreezerRuntime } from './freezer/index.ts';
|
|
|
6
6
|
import type { UserClients } from './kernel/users.ts';
|
|
7
7
|
import type { McpRuntime } from './mcp/index.ts';
|
|
8
8
|
import type { MemoryRuntime } from './memory/index.ts';
|
|
9
|
+
import { type MonitorOptions } from './monitor/index.ts';
|
|
9
10
|
import { AgentSettings } from './services.ts';
|
|
10
11
|
import type { SkillsRuntime } from './skills/index.ts';
|
|
11
12
|
import type { SprinklesRuntime } from './sprinkles/index.ts';
|
|
@@ -32,4 +33,5 @@ export declare function hostAgent(agent: Agent, options?: {
|
|
|
32
33
|
changes?: ChangesRuntime;
|
|
33
34
|
mcp?: Pick<McpRuntime, 'close'>;
|
|
34
35
|
users?: UserClients;
|
|
36
|
+
monitor?: Pick<MonitorOptions, 'kernel' | 'groups' | 'users' | 'secrets'>;
|
|
35
37
|
}): Promise<AgentHost>;
|
|
@@ -3,6 +3,7 @@ export declare const REFUSED: Set<string>;
|
|
|
3
3
|
export interface ProcessGroups {
|
|
4
4
|
track(owner: number, process: KernelProcess): void;
|
|
5
5
|
of(owner: number): number[];
|
|
6
|
+
owned(owner: number): number[];
|
|
6
7
|
shared(owner: number): number | undefined;
|
|
7
8
|
joins(): boolean;
|
|
8
9
|
pending(owner: number): Promise<void> | undefined;
|
|
@@ -31,6 +31,7 @@ export interface ServerStatus {
|
|
|
31
31
|
export type { McpAccounts } from './accounts.ts';
|
|
32
32
|
export interface McpRuntime extends McpAccounts {
|
|
33
33
|
status(): ServerStatus[];
|
|
34
|
+
secrets(): string[];
|
|
34
35
|
reload(context: Context): Promise<void>;
|
|
35
36
|
close(context: Context): Promise<void>;
|
|
36
37
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Context, type ReplicatedState } from '@earendil-works/chord';
|
|
2
|
+
import type { ConversationView, Harness, UsageState } from '@earendil-works/pi-durable';
|
|
3
|
+
import { type AgentsState } from '../agents.ts';
|
|
4
|
+
import type { MonitorFeed, MonitorLease } from '../services.ts';
|
|
5
|
+
export interface PsEntry {
|
|
6
|
+
pid: number;
|
|
7
|
+
ppid?: number;
|
|
8
|
+
pgid?: number;
|
|
9
|
+
argv?: readonly string[];
|
|
10
|
+
tty?: unknown;
|
|
11
|
+
started?: number;
|
|
12
|
+
state?: string;
|
|
13
|
+
uid?: number;
|
|
14
|
+
rss?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Timers {
|
|
17
|
+
set(run: () => void, ms: number): unknown;
|
|
18
|
+
clear(handle: unknown): void;
|
|
19
|
+
}
|
|
20
|
+
export interface MonitorOptions {
|
|
21
|
+
harness: Pick<Harness, 'watchTaskGraph' | 'usage' | 'subscribeCommits' | 'inspect'>;
|
|
22
|
+
agents: {
|
|
23
|
+
state(): Readonly<AgentsState>;
|
|
24
|
+
onChange(listener: () => void): () => void;
|
|
25
|
+
};
|
|
26
|
+
views: ReplicatedState<Record<string, ConversationView>>;
|
|
27
|
+
kernel?: {
|
|
28
|
+
ps?(): Promise<readonly PsEntry[]>;
|
|
29
|
+
};
|
|
30
|
+
groups?: {
|
|
31
|
+
owned(owner: number): number[];
|
|
32
|
+
};
|
|
33
|
+
users?: () => Promise<readonly {
|
|
34
|
+
name: string;
|
|
35
|
+
uid: number;
|
|
36
|
+
}[]>;
|
|
37
|
+
secrets?: () => readonly string[];
|
|
38
|
+
now?: () => number;
|
|
39
|
+
timers?: Timers;
|
|
40
|
+
ttlMs?: number;
|
|
41
|
+
psMs?: number;
|
|
42
|
+
throttleMs?: number;
|
|
43
|
+
usageMs?: number;
|
|
44
|
+
context?: Context;
|
|
45
|
+
}
|
|
46
|
+
export interface Monitor {
|
|
47
|
+
readonly state: ReplicatedState<MonitorFeed>;
|
|
48
|
+
readonly viewState: ReplicatedState<MonitorFeed>;
|
|
49
|
+
open(lease: string | null, resync: boolean, context: Context): Promise<MonitorLease>;
|
|
50
|
+
close(lease: string, context: Context): Promise<void>;
|
|
51
|
+
active(): boolean;
|
|
52
|
+
dispose(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export declare const TTL_MS = 30000;
|
|
55
|
+
export declare const PS_MS = 2000;
|
|
56
|
+
export declare const THROTTLE_MS = 1000;
|
|
57
|
+
export declare const USAGE_MS = 2000;
|
|
58
|
+
export declare const PROBLEMS_MAX = 50;
|
|
59
|
+
export declare const globalTimers: Timers;
|
|
60
|
+
export declare function emptyFeed(): MonitorFeed;
|
|
61
|
+
export declare function totals(usage: UsageState): {
|
|
62
|
+
tokens: number;
|
|
63
|
+
cost: number;
|
|
64
|
+
free: boolean;
|
|
65
|
+
};
|
|
66
|
+
export declare function narrowed(feed: MonitorFeed, programs: ReadonlyMap<number, string>): MonitorFeed;
|
|
67
|
+
export declare function createMonitor(options: MonitorOptions): Monitor;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const TEXT_MAX = 160;
|
|
2
|
+
export declare function cut(text: string, max?: number): string;
|
|
3
|
+
export declare function redacted(text: string, secrets: readonly string[]): string;
|
|
4
|
+
export declare function commandLine(argv: readonly string[], secrets: readonly string[]): string;
|
|
5
|
+
export declare function program(argv: readonly string[]): string;
|
package/dist/types/services.d.ts
CHANGED
|
@@ -79,6 +79,76 @@ export interface AgentControl {
|
|
|
79
79
|
changesOpen(context: Context): Promise<void>;
|
|
80
80
|
changeAccept(path: string, context: Context): Promise<Created>;
|
|
81
81
|
changeRevert(path: string, context: Context): Promise<Created>;
|
|
82
|
+
monitorOpen(lease: string | null, resync: boolean, context: Context): Promise<MonitorLease>;
|
|
83
|
+
monitorClose(lease: string, context: Context): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export interface MonitorLease {
|
|
86
|
+
lease: string;
|
|
87
|
+
ttlMs: number;
|
|
88
|
+
}
|
|
89
|
+
export interface MonitorAgent {
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
kind: 'cone' | 'scoop';
|
|
93
|
+
parentId: string | null;
|
|
94
|
+
model: string | null;
|
|
95
|
+
running: boolean;
|
|
96
|
+
queued: number;
|
|
97
|
+
tool: string | null;
|
|
98
|
+
retry: {
|
|
99
|
+
attempt: number;
|
|
100
|
+
since: number;
|
|
101
|
+
error: string;
|
|
102
|
+
} | null;
|
|
103
|
+
failed: string | null;
|
|
104
|
+
context: number | null;
|
|
105
|
+
}
|
|
106
|
+
export interface MonitorTask {
|
|
107
|
+
id: string;
|
|
108
|
+
kind: string;
|
|
109
|
+
detail: string | null;
|
|
110
|
+
agentId: string | null;
|
|
111
|
+
owner: string | null;
|
|
112
|
+
status: 'pending' | 'running' | 'waiting' | 'completing';
|
|
113
|
+
phase: string;
|
|
114
|
+
background: boolean;
|
|
115
|
+
aborting: number | null;
|
|
116
|
+
since: number;
|
|
117
|
+
waits: number;
|
|
118
|
+
}
|
|
119
|
+
export interface MonitorProcess {
|
|
120
|
+
pid: number;
|
|
121
|
+
ppid: number;
|
|
122
|
+
pgid: number;
|
|
123
|
+
user: string | null;
|
|
124
|
+
agentId: string | null;
|
|
125
|
+
command: string;
|
|
126
|
+
state: 'S' | 'Z';
|
|
127
|
+
started: number;
|
|
128
|
+
zombie: number | null;
|
|
129
|
+
tty: boolean;
|
|
130
|
+
rss: number | null;
|
|
131
|
+
}
|
|
132
|
+
export interface MonitorProblem {
|
|
133
|
+
id: string;
|
|
134
|
+
at: number;
|
|
135
|
+
agentId: string | null;
|
|
136
|
+
kind: 'task' | 'retry' | 'turn';
|
|
137
|
+
message: string;
|
|
138
|
+
}
|
|
139
|
+
export interface MonitorFeed {
|
|
140
|
+
open: boolean;
|
|
141
|
+
at: number;
|
|
142
|
+
usage: {
|
|
143
|
+
tokens: number;
|
|
144
|
+
cost: number;
|
|
145
|
+
free: boolean;
|
|
146
|
+
} | null;
|
|
147
|
+
agents: MonitorAgent[];
|
|
148
|
+
tasks: MonitorTask[];
|
|
149
|
+
processes: MonitorProcess[] | null;
|
|
150
|
+
problems: MonitorProblem[];
|
|
151
|
+
paused: boolean;
|
|
82
152
|
}
|
|
83
153
|
export interface MemoryDraft {
|
|
84
154
|
id: string | null;
|
|
@@ -150,6 +220,7 @@ export interface AgentTranscript {
|
|
|
150
220
|
readonly memoryScopes: ReplicatedState<MemoryScope[]>;
|
|
151
221
|
readonly frozen: ReplicatedState<FrozenCone[]>;
|
|
152
222
|
readonly changes: ReplicatedState<ChangesView>;
|
|
223
|
+
readonly monitor: ReplicatedState<MonitorFeed>;
|
|
153
224
|
}
|
|
154
225
|
export interface Command {
|
|
155
226
|
name: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { MonitorSection } from '@ai-ecoverse/slicc-spectrum/ui';
|
|
1
2
|
import type { AgentConnection } from '../client.ts';
|
|
2
3
|
import { AgentAdapter } from './agent-port.ts';
|
|
3
4
|
import { ChangesAdapter } from './changes-port.ts';
|
|
4
5
|
import { MemoryAdapter } from './memory-port.ts';
|
|
6
|
+
import { MonitorAdapter } from './monitor-port.ts';
|
|
5
7
|
import { type Login, SettingsAdapter } from './settings-port.ts';
|
|
6
8
|
import { SprinkleAdapter } from './sprinkle-port.ts';
|
|
7
9
|
import { TrayAdapter } from './tray-port.ts';
|
|
@@ -9,12 +11,16 @@ export { AgentAdapter, CONE } from './agent-port.ts';
|
|
|
9
11
|
export { ChangesAdapter, type ChangesEvents } from './changes-port.ts';
|
|
10
12
|
export { MemoryAdapter } from './memory-port.ts';
|
|
11
13
|
export { assistant, errorAction, errorPart, isBusy, queued, textOf, toMessages, } from './messages.ts';
|
|
14
|
+
export { MonitorAdapter, type MonitorAdapterOptions, type MonitorInput, monitorSnapshot, } from './monitor-port.ts';
|
|
12
15
|
export { type Login, SETTINGS_KEY, SettingsAdapter } from './settings-port.ts';
|
|
13
16
|
export { SprinkleAdapter } from './sprinkle-port.ts';
|
|
14
17
|
export { TrayAdapter } from './tray-port.ts';
|
|
15
18
|
export declare function createAgentModel(connection: AgentConnection, options?: {
|
|
16
19
|
storage?: Pick<Storage, 'getItem' | 'setItem'> | null;
|
|
17
20
|
login?: Login;
|
|
21
|
+
monitor?: {
|
|
22
|
+
extra?: () => readonly MonitorSection[];
|
|
23
|
+
};
|
|
18
24
|
}): {
|
|
19
25
|
agent: AgentAdapter;
|
|
20
26
|
settings: SettingsAdapter;
|
|
@@ -22,4 +28,5 @@ export declare function createAgentModel(connection: AgentConnection, options?:
|
|
|
22
28
|
sprinkles: SprinkleAdapter;
|
|
23
29
|
memory: MemoryAdapter;
|
|
24
30
|
changes: ChangesAdapter;
|
|
31
|
+
monitor: MonitorAdapter;
|
|
25
32
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { MonitorEvents, MonitorPort, MonitorSection, MonitorSnapshot } from '@ai-ecoverse/slicc-spectrum/ui';
|
|
2
|
+
import type { AgentConnection } from '../client.ts';
|
|
3
|
+
import type { BudgetState, ModelChoice, MonitorFeed, MonitorTask } from '../services.ts';
|
|
4
|
+
export declare const RENEW_MS = 10000;
|
|
5
|
+
export declare const ROWS_MAX = 200;
|
|
6
|
+
export declare const HISTORY = 24;
|
|
7
|
+
export declare const BUDGET_WARN = 80;
|
|
8
|
+
export declare const BUDGET_ERROR = 95;
|
|
9
|
+
export declare const RETRY_WARN = 3;
|
|
10
|
+
export declare const RETRY_ERROR = 6;
|
|
11
|
+
export declare const RETRY_SLOW_MS = 120000;
|
|
12
|
+
export declare const FAILED_MS = 600000;
|
|
13
|
+
export declare const ABORT_MS = 30000;
|
|
14
|
+
export declare const ABORT_ROW_MS = 10000;
|
|
15
|
+
export declare const GROUP_MAX = 32;
|
|
16
|
+
export declare const TOTAL_MAX = 128;
|
|
17
|
+
export declare const ZOMBIE_MS = 60000;
|
|
18
|
+
export declare const STALE_MS = 1800000;
|
|
19
|
+
export declare const CONTEXT_WARN = 0.8;
|
|
20
|
+
export declare const DEPTH_MAX = 6;
|
|
21
|
+
export interface Sample {
|
|
22
|
+
at: number;
|
|
23
|
+
cost: number;
|
|
24
|
+
tokens: number;
|
|
25
|
+
active: number;
|
|
26
|
+
}
|
|
27
|
+
export interface MonitorInput {
|
|
28
|
+
feed: MonitorFeed | undefined;
|
|
29
|
+
budget: BudgetState | null | undefined;
|
|
30
|
+
models: readonly ModelChoice[];
|
|
31
|
+
changes: readonly {
|
|
32
|
+
path: string;
|
|
33
|
+
status: string;
|
|
34
|
+
}[];
|
|
35
|
+
sprinkles: readonly {
|
|
36
|
+
name: string;
|
|
37
|
+
title: string;
|
|
38
|
+
}[];
|
|
39
|
+
extra: readonly MonitorSection[];
|
|
40
|
+
history: readonly Sample[];
|
|
41
|
+
now: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function age(ms: number): string;
|
|
44
|
+
export declare function money(value: number): string;
|
|
45
|
+
export declare function count(value: number): string;
|
|
46
|
+
export declare function bytes(value: number): string;
|
|
47
|
+
export declare function taskLabel(task: MonitorTask): string;
|
|
48
|
+
export declare function taskTree(feed: MonitorFeed): {
|
|
49
|
+
task: MonitorTask;
|
|
50
|
+
depth: number;
|
|
51
|
+
}[];
|
|
52
|
+
export declare function monitorSnapshot(input: MonitorInput): MonitorSnapshot;
|
|
53
|
+
export interface Intervals {
|
|
54
|
+
every(run: () => void, ms: number): unknown;
|
|
55
|
+
stop(handle: unknown): void;
|
|
56
|
+
}
|
|
57
|
+
export declare const globalIntervals: Intervals;
|
|
58
|
+
export interface MonitorAdapterOptions {
|
|
59
|
+
extra?: () => readonly MonitorSection[];
|
|
60
|
+
renewMs?: number;
|
|
61
|
+
intervals?: Intervals;
|
|
62
|
+
now?: () => number;
|
|
63
|
+
}
|
|
64
|
+
export declare class MonitorAdapter implements MonitorPort {
|
|
65
|
+
#private;
|
|
66
|
+
constructor(connection: AgentConnection, options?: MonitorAdapterOptions);
|
|
67
|
+
on<K extends keyof MonitorEvents>(type: K, listener: (detail: MonitorEvents[K]) => void): () => void;
|
|
68
|
+
snapshot(): MonitorSnapshot;
|
|
69
|
+
resync(): void;
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-agent",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.37.0",
|
|
4
4
|
"description": "SLICC's agent core on pi durable: an agent worker, session storage, remoting and pi extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@ai-ecoverse/slicc-kernel": "1.47.1",
|
|
65
|
-
"@ai-ecoverse/slicc-shared-web": "1.12.
|
|
66
|
-
"@ai-ecoverse/slicc-spectrum": "1.
|
|
65
|
+
"@ai-ecoverse/slicc-shared-web": "1.12.2",
|
|
66
|
+
"@ai-ecoverse/slicc-spectrum": "1.57.0",
|
|
67
67
|
"@ai-ecoverse/wasm-bash": "5.3.0-17",
|
|
68
68
|
"@ai-ecoverse/wasm-coreutils": "9.12.0-5",
|
|
69
69
|
"@ai-ecoverse/wasm-git": "2.55.0-15",
|