UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

93 lines • 5.92 kB
import type { DataProvider, ExtensionContext, TelescopeEntryLike } from './telescope-sdk.js'; /** * The agent "Agent" dashboard data providers. Every provider here is ENTRY-BACKED: it aggregates the * `agora:agent:*` lifecycle events that `@adonis-agora/agent` emits through `@adonis-agora/diagnostics` * (via `src/diagnostics.ts`'s `publishAgent`) and that `@adonis-agora/telescope`'s generic diagnostics * watcher records — one entry per publish, stored as `type: 'diagnostic'`, `tag: 'lib:agent'`, with the * agent payload preserved verbatim under `content.payload`. * * No agent-specific watcher is contributed: capture is entirely handled by the generic bridge, so the * extension only has to SURFACE the recorded history. This mirrors `@adonis-agora/media/telescope`'s * entry-backed providers, and needs zero coupling to the agent container internals — no NestJS-style * DI/read-model resolution. */ /** * Newest-first cap on how many recorded agent entries a provider scans. Shared by every * `lib:agent` consumer of `fetchEntries` — including `rag-data-providers.ts`, since retrieval * events are recorded on this SAME generic slice (Adonis's diagnostics bridge has no per-event * entry type to give RAG its own window; see that file's header for what this implies). */ export declare const ENTRY_LIMIT = 5000; /** Default rollup window: 24h. */ export declare const DAY_MS: number; /** Epoch millis of an entry's `createdAt`, or `0` when absent. Exported for `rag-data-providers.ts`. */ export declare const atOf: (e: TelescopeEntryLike) => number; /** Fetch captured `agora:agent:*` entries from Telescope storage (newest-first). */ export declare function fetchEntries(ctx: ExtensionContext, limit?: number): Promise<TelescopeEntryLike[]>; /** * Build N equal-width time buckets spanning from the oldest entry to now, each starting empty. * Exported so `rag-data-providers.ts` buckets retrieval entries the same way the agent providers * bucket everything else, instead of a second, drifting bucketing scheme. */ export declare function timeBuckets<TRow extends Record<string, number>>(entries: TelescopeEntryLike[], count: number, emptyRow: () => TRow): { rows: Array<{ label: string; } & TRow>; minTime: number; bucketSize: number; }; /** Which of `timeBuckets`'s N buckets `e` falls into, clamped to `[0, count-1]`. */ export declare function bucketIndexFor(e: TelescopeEntryLike, minTime: number, bucketSize: number, count: number): number; /** * Net in-flight runs = `run.started` − every ending (`run.finished`, `run.failed`, `run.cancelled`) * over the window (default 24h; `windowMs: 0` = all-time). Floored at 0. A cheap "how many agent runs * are live right now" stat derived purely from the captured event stream — no live run store is * consulted. */ export declare function agentActiveRunsProvider(): DataProvider; /** * Token usage = total (input + output) tokens summed from `run.finished` over the window (default 24h), * with `delta` vs the prior window and an 8-point spark. The entry-backed proxy for "spend/usage" — no * pricing read-model is joined (that would need host DI, which this extension deliberately avoids). */ export declare function agentTokenUsageProvider(): DataProvider; /** * Tool-call success rate = executed / (executed + rejected + failed) over the window; 1 when no data. * `rejected` counts an approval that was denied — a first-class governance signal, not a crash. */ export declare function agentToolCallSuccessRateProvider(): DataProvider; /** Runs over time — `run.started` (started) vs `run.finished` (finished) per bucket. */ export declare function agentRunsOverTimeProvider(): DataProvider; /** Token throughput over time — input/output tokens per bucket, summed from `run.finished`. */ export declare function agentTokensOverTimeProvider(): DataProvider; /** Recent finished runs (newest first) as table rows: time, run, thread, steps, tokens. */ export declare function agentRecentRunsProvider(): DataProvider; /** * Turn latency as a distribution, from `run.finished` over the window (default 24h; `windowMs: 0` = * all-time): `query.metric` `'ttft'` (default — turn start → first text frame; a turn that streamed * no text has no sample) or `'duration'` (the whole turn). A delegation's child run is left out: it is * part of its parent's turn, the same rule the read-model's `RunReliability.latency` follows. * Percentiles are nearest-rank and omitted when there are no samples. */ export declare function agentLatencyDistributionProvider(): DataProvider; /** * Failed runs by the stable code their stream `error` frame carried, from `run.failed` over the * window (default 24h; `windowMs: 0` = all-time), most frequent first. An entry without a code is * `unknown`. */ export declare function agentFailuresByCodeProvider(): DataProvider; /** Tool calls over time — executed/rejected/failed per bucket (the `tool-call` event). */ export declare function agentToolCallsOverTimeProvider(): DataProvider; /** Recent tool calls (newest first) as table rows: time, run, tool, type, status. */ export declare function agentRecentToolCallsProvider(): DataProvider; /** * Recent approval decisions (newest first): the `action`-type tool calls — the ones that pass through * the human-approval gate — surfaced with their outcome (`executed` = approved/auto, `rejected` = * denied). Read-type tool calls never require approval and are excluded. */ export declare function agentRecentApprovalsProvider(): DataProvider; /** Sub-agent delegations over time — the `delegated` event per bucket. */ export declare function agentDelegationsOverTimeProvider(): DataProvider; /** Recent delegations (newest first) as table rows: time, run, from, to. */ export declare function agentRecentDelegationsProvider(): DataProvider; //# sourceMappingURL=data-providers.d.ts.map