@burdenoff/microfe-botmanor 2026.1120.6 → 2026.1120.8
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/dist/botlit/components/AssistantChannelPanel.js +3 -3
- package/dist/botlit/components/AssistantChannelPanel.js.map +1 -1
- package/dist/botlit/components/ChannelRoutesPanel.d.ts +9 -0
- package/dist/botlit/components/ChannelRoutesPanel.js +275 -0
- package/dist/botlit/components/ChannelRoutesPanel.js.map +1 -0
- package/dist/botlit/components/CreateChannelRouteDialog.d.ts +13 -0
- package/dist/botlit/components/CreateChannelRouteDialog.js +188 -0
- package/dist/botlit/components/CreateChannelRouteDialog.js.map +1 -0
- package/dist/botlit/components/DashboardUsagePanel.d.ts +8 -0
- package/dist/botlit/components/DashboardUsagePanel.js +277 -0
- package/dist/botlit/components/DashboardUsagePanel.js.map +1 -0
- package/dist/botlit/components/LiveIndicator.d.ts +9 -0
- package/dist/botlit/components/LiveIndicator.js +21 -0
- package/dist/botlit/components/LiveIndicator.js.map +1 -0
- package/dist/botlit/components/RunStatsCard.d.ts +9 -0
- package/dist/botlit/components/RunStatsCard.js +138 -0
- package/dist/botlit/components/RunStatsCard.js.map +1 -0
- package/dist/botlit/hooks/index.d.ts +3 -3
- package/dist/botlit/hooks/index.js +19 -19
- package/dist/botlit/hooks/useBots.d.ts +5 -0
- package/dist/botlit/hooks/useBots.js +63 -50
- package/dist/botlit/hooks/useBots.js.map +1 -1
- package/dist/botlit/hooks/useChannels.d.ts +49 -23
- package/dist/botlit/hooks/useChannels.js +141 -135
- package/dist/botlit/hooks/useChannels.js.map +1 -1
- package/dist/botlit/hooks/useExecutionLiveUpdates.d.ts +29 -0
- package/dist/botlit/hooks/useExecutionLiveUpdates.js +124 -0
- package/dist/botlit/hooks/useExecutionLiveUpdates.js.map +1 -0
- package/dist/botlit/hooks/useUsageStats.d.ts +71 -0
- package/dist/botlit/hooks/useUsageStats.js +115 -0
- package/dist/botlit/hooks/useUsageStats.js.map +1 -0
- package/dist/botlit/pages/AgentDetailPage.js +48 -43
- package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
- package/dist/botlit/pages/BotChannelsTab.js +12 -3
- package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
- package/dist/botlit/pages/BotDetailPage.js +317 -309
- package/dist/botlit/pages/BotDetailPage.js.map +1 -1
- package/dist/botlit/pages/ChannelDetailPage.js +642 -776
- package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
- package/dist/botlit/pages/ChannelRoutesPage.js +22 -208
- package/dist/botlit/pages/ChannelRoutesPage.js.map +1 -1
- package/dist/botlit/pages/ChannelsPage.js +314 -251
- package/dist/botlit/pages/ChannelsPage.js.map +1 -1
- package/dist/botlit/pages/DashboardPage.js +155 -153
- package/dist/botlit/pages/DashboardPage.js.map +1 -1
- package/dist/botlit/pages/ExecutionDetailPage.js +142 -132
- package/dist/botlit/pages/ExecutionDetailPage.js.map +1 -1
- package/dist/botlit/pages/ExecutionsPage.js +150 -141
- package/dist/botlit/pages/ExecutionsPage.js.map +1 -1
- package/dist/botlit/pages/PromptStudioPage.js +172 -172
- package/dist/botlit/pages/PromptStudioPage.js.map +1 -1
- package/dist/botlit/permissions/botmanorPermissions.d.ts +1 -0
- package/dist/botlit/permissions/botmanorPermissions.js +1 -0
- package/dist/botlit/permissions/botmanorPermissions.js.map +1 -1
- package/dist/botlit/utils/channelConnectors.d.ts +13 -0
- package/dist/botlit/utils/channelConnectors.js +21 -1
- package/dist/botlit/utils/channelConnectors.js.map +1 -1
- package/dist/botlit/utils/errors.d.ts +8 -0
- package/dist/botlit/utils/errors.js +21 -1
- package/dist/botlit/utils/errors.js.map +1 -1
- package/dist/botlit/utils/formatters.js +6 -2
- package/dist/botlit/utils/formatters.js.map +1 -1
- package/dist/generated/wspace-operations.d.ts +321 -12
- package/dist/generated/wspace-operations.js +188 -91
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +130 -0
- package/dist/generated/wspace-types.js +8 -4
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExecutionLiveUpdates.js","names":["OPEN_STATUSES","LIVE_FALLBACK_POLL_MS","isOpenStatus","status","useWorkspaceSubscription","client","useWorkspaceClient","variablesKey","variables","stream","setStream","useState","onDataRef","useRef","onData","streamKey","operationKey","query","useEffect","enabled","closed","report","subscription","errors","result","definition","document","useLiveExecutionList","workspaceId","useWorkspaceId","updates","setUpdates","options","live","BotmanorExecutionUpdatedDocument","update","data","next","current","rowsKey","rows","row","seenRowsKey","setSeenRowsKey","loaded","kept","id","hasOpenRun","pollRef","timer","useMemo","patched","stripNulls","fresh","b","a","value","useLiveExecution","open","executionId","refetchRef","refetch","AgentExecutionUpdatedDocument"],"sources":["../../../src/botlit/hooks/useExecutionLiveUpdates.ts"],"sourcesContent":["/**\n * Live execution updates (BOFF-15360 package E)\n * @module botlit/hooks\n *\n * The service publishes every execution status change (created, running,\n * finished) on two subscriptions:\n *\n * - `botmanorExecutionUpdated` — every run of the request workspace. The\n * executions list opens ONE stream for it rather than one per visible row:\n * the gateway caps live streams per user.\n * - `agentExecutionUpdated(executionId)` — one run. The detail page uses it\n * while the run it shows is still pending or running.\n *\n * Both go through the shell's workspace Apollo client (its subscription link).\n * When the stream cannot be opened or drops, the hooks fall back to polling,\n * so the page still converges without a manual refresh.\n */\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport {\n AgentExecutionUpdatedDocument,\n BotmanorExecutionUpdatedDocument,\n type AgentExecutionUpdatedSubscription,\n type BotmanorExecutionUpdatedSubscription,\n} from '../../generated/wspace-operations';\nimport type { ExecutionRecord } from './useExecutions';\nimport { useWorkspaceClient, useWorkspaceId } from './internal/workspaceGateway';\n\n/** Statuses that can still change. */\nconst OPEN_STATUSES = new Set(['PENDING', 'RUNNING']);\n\n/** Poll interval used only when the live stream is unavailable. */\nexport const LIVE_FALLBACK_POLL_MS = 15_000;\n\nexport type LiveState = 'live' | 'polling' | 'off';\n\nexport type ExecutionUpdate = Partial<ExecutionRecord> & { id: string; status: string };\n\nexport function isOpenStatus(status: string | null | undefined): boolean {\n return Boolean(status && OPEN_STATUSES.has(status));\n}\n\ninterface SubscribeOptions<TData> {\n query: typeof BotmanorExecutionUpdatedDocument | typeof AgentExecutionUpdatedDocument;\n variables?: Record<string, unknown>;\n enabled: boolean;\n onData: (data: TData) => void;\n}\n\n/** Open one subscription on the workspace client; report whether it is live. */\nfunction useWorkspaceSubscription<TData>({\n query,\n variables,\n enabled,\n onData,\n}: SubscribeOptions<TData>): LiveState {\n const client = useWorkspaceClient();\n const variablesKey = JSON.stringify(variables ?? {});\n // State is recorded per stream so a new stream starts live without a reset\n // inside the effect; only stream callbacks change it.\n const [stream, setStream] = useState<{ key: string; state: LiveState }>({\n key: '',\n state: 'live',\n });\n const onDataRef = useRef(onData);\n useEffect(() => {\n onDataRef.current = onData;\n }, [onData]);\n const operation = operationKey(query);\n const streamKey = `${operation}:${variablesKey}`;\n\n useEffect(() => {\n if (!enabled) return undefined;\n let closed = false;\n const report = (state: LiveState) => {\n if (!closed) setStream({ key: streamKey, state });\n };\n let subscription: { unsubscribe: () => void } | undefined;\n try {\n subscription = client\n .subscribe<TData>({\n query,\n variables: JSON.parse(variablesKey) as Record<string, unknown>,\n })\n .subscribe({\n next: (result) => {\n const errors = (result as { errors?: unknown }).errors;\n const error = (result as { error?: unknown }).error;\n if (error != null || (Array.isArray(errors) && errors.length > 0)) {\n report('polling');\n return;\n }\n report('live');\n if (!closed && result.data) onDataRef.current(result.data as TData);\n },\n error: () => report('polling'),\n complete: () => report('polling'),\n });\n } catch {\n // The client could not open a stream at all (no subscription link).\n // Report it after this effect, like any other stream failure.\n void Promise.resolve().then(() => report('polling'));\n }\n return () => {\n closed = true;\n subscription?.unsubscribe();\n };\n }, [client, query, variablesKey, enabled, streamKey]);\n\n if (!enabled) return 'off';\n return stream.key === streamKey ? stream.state : 'live';\n}\n\n/** Stable identity of a subscription document for keying its stream state. */\nfunction operationKey(document: SubscribeOptions<unknown>['query']): string {\n for (const definition of document.definitions) {\n if (definition.kind === 'OperationDefinition') return definition.name?.value ?? '';\n }\n return '';\n}\n\n/**\n * Overlay live updates on a loaded executions list. Rows already loaded take\n * the newest status, metrics and errors; runs created after the list loaded are\n * prepended when `includeNew` (no filter active) is true. When the stream is\n * unavailable `onFallbackPoll` runs every {@link LIVE_FALLBACK_POLL_MS} while a\n * loaded run is still open.\n */\nexport function useLiveExecutionList(\n rows: readonly ExecutionRecord[],\n options: { enabled: boolean; includeNew: boolean; onFallbackPoll: () => void }\n): { rows: ExecutionRecord[]; live: LiveState } {\n const workspaceId = useWorkspaceId();\n const [updates, setUpdates] = useState<Map<string, ExecutionUpdate>>(() => new Map());\n const enabled = options.enabled && Boolean(workspaceId);\n\n const live = useWorkspaceSubscription<BotmanorExecutionUpdatedSubscription>({\n query: BotmanorExecutionUpdatedDocument,\n enabled,\n onData: (data) => {\n const update = data.botmanorExecutionUpdated as ExecutionUpdate | undefined;\n if (\n !update?.id ||\n (workspaceId && update.workspaceId && update.workspaceId !== workspaceId)\n ) {\n return;\n }\n setUpdates((current) => {\n const next = new Map(current);\n next.set(update.id, { ...current.get(update.id), ...update });\n return next;\n });\n },\n });\n\n // A fresh list from the server supersedes the overlay for the rows it\n // carries (state derived from the previous render, not an effect).\n // Keyed by content, not identity, so a caller passing a fresh array with the\n // same rows does not re-trigger it.\n const rowsKey = rows.map((row) => `${row.id}:${row.status}`).join('|');\n const [seenRowsKey, setSeenRowsKey] = useState(rowsKey);\n if (seenRowsKey !== rowsKey) {\n setSeenRowsKey(rowsKey);\n if (updates.size > 0) {\n const loaded = new Set(rows.map((row) => row.id));\n const kept = new Map([...updates].filter(([id]) => !loaded.has(id)));\n if (kept.size !== updates.size) setUpdates(kept);\n }\n }\n\n const hasOpenRun = rows.some((row) => isOpenStatus(updates.get(row.id)?.status ?? row.status));\n const pollRef = useRef(options.onFallbackPoll);\n useEffect(() => {\n pollRef.current = options.onFallbackPoll;\n }, [options.onFallbackPoll]);\n useEffect(() => {\n if (live !== 'polling' || !hasOpenRun) return undefined;\n const timer = setInterval(() => pollRef.current(), LIVE_FALLBACK_POLL_MS);\n return () => clearInterval(timer);\n }, [live, hasOpenRun]);\n\n const merged = useMemo(() => {\n const loaded = new Set(rows.map((row) => row.id));\n const patched = rows.map((row) => {\n const update = updates.get(row.id);\n return update ? ({ ...row, ...stripNulls(update) } as ExecutionRecord) : row;\n });\n if (!options.includeNew) return patched;\n const fresh = [...updates.values()]\n .filter((update) => !loaded.has(update.id) && update.createdAt && update.input !== undefined)\n .map((update) => update as ExecutionRecord)\n .sort((a, b) => b.createdAt.localeCompare(a.createdAt));\n return fresh.length > 0 ? [...fresh, ...patched] : patched;\n }, [rows, updates, options.includeNew]);\n\n return { rows: merged, live };\n}\n\n/** Keep loaded values when the live payload leaves a field out. */\nfunction stripNulls(update: ExecutionUpdate): ExecutionUpdate {\n return Object.fromEntries(\n Object.entries(update).filter(([, value]) => value !== undefined)\n ) as ExecutionUpdate;\n}\n\n/**\n * Refresh one execution while it is still open: on every live update, or every\n * {@link LIVE_FALLBACK_POLL_MS} when the stream is unavailable.\n */\nexport function useLiveExecution(\n executionId: string | undefined,\n status: string | null | undefined,\n refetch: () => void\n): LiveState {\n const open = Boolean(executionId) && isOpenStatus(status);\n const refetchRef = useRef(refetch);\n useEffect(() => {\n refetchRef.current = refetch;\n }, [refetch]);\n\n const variables = useMemo(() => ({ executionId: executionId ?? '' }), [executionId]);\n const live = useWorkspaceSubscription<AgentExecutionUpdatedSubscription>({\n query: AgentExecutionUpdatedDocument,\n variables,\n enabled: open,\n onData: () => refetchRef.current(),\n });\n\n useEffect(() => {\n if (!open || live !== 'polling') return undefined;\n const timer = setInterval(() => refetchRef.current(), LIVE_FALLBACK_POLL_MS);\n return () => clearInterval(timer);\n }, [open, live]);\n\n return live;\n}\n"],"mappings":";;;;AA6BA,IAAM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Aa/C,EAAOgD,CAAO;CACjC,QAAgB;EACd,EAAW,UAAUA;CACvB,GAAG,CAACA,CAAO,CAAC;CAEZ,IAAMrD,IAAY0C,SAAe,EAAE,aAAaS,KAAe,GAAG,IAAI,CAACA,CAAW,CAAC,GAC7E1B,IAAO7B,EAA4D;EACvE,OAAO0D;EACP;EACA,SAASJ;EACT,cAAcE,EAAW,QAAQ;CACnC,CAAC;CAQD,OANA1C,QAAgB;EACd,IAAI,CAACwC,KAAQzB,MAAS,WAAW;EACjC,IAAMgB,IAAQ,kBAAkBW,EAAW,QAAQ,GAAG3D,CAAqB;EAC3E,aAAa,cAAcgD,CAAK;CAClC,GAAG,CAACS,GAAMzB,CAAI,CAAC,GAERA;AACT"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DailyUsageDimension, DailyUsageInterval } from '../../generated/wspace-types';
|
|
2
|
+
import { QueryResult } from './internal/workspaceGateway';
|
|
3
|
+
export interface RunStatsRecord {
|
|
4
|
+
totalExecutions: number;
|
|
5
|
+
successfulExecutions: number;
|
|
6
|
+
failedExecutions: number;
|
|
7
|
+
inProgressExecutions: number;
|
|
8
|
+
/** 0..1 over finished runs; null when none finished. */
|
|
9
|
+
successRate: number | null;
|
|
10
|
+
avgDurationMs: number | null;
|
|
11
|
+
totalCost: number;
|
|
12
|
+
pricedExecutions: number;
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
lastExecutedAt: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface DailyUsageRecord {
|
|
17
|
+
date: string;
|
|
18
|
+
agentId: string | null;
|
|
19
|
+
agentName: string | null;
|
|
20
|
+
appId: string | null;
|
|
21
|
+
appName: string | null;
|
|
22
|
+
executionCount: number;
|
|
23
|
+
successCount: number;
|
|
24
|
+
failureCount: number;
|
|
25
|
+
inProgressCount: number;
|
|
26
|
+
successRate: number | null;
|
|
27
|
+
totalTokens: number;
|
|
28
|
+
totalCost: number | null;
|
|
29
|
+
pricedRuns: number;
|
|
30
|
+
avgDurationMs: number | null;
|
|
31
|
+
lastExecutedAt: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** `null` = whole history; a number = trailing window of that many days. */
|
|
34
|
+
export type StatsRange = number | null;
|
|
35
|
+
/**
|
|
36
|
+
* A trailing window as ISO strings. The end is rounded up to the next minute so
|
|
37
|
+
* the variables stay stable across re-renders within that minute.
|
|
38
|
+
*/
|
|
39
|
+
export declare function trailingWindow(days: number, now?: number): {
|
|
40
|
+
startDate: string;
|
|
41
|
+
endDate: string;
|
|
42
|
+
};
|
|
43
|
+
/** Run totals of one agent over the range. */
|
|
44
|
+
export declare function useAgentRunStats(agentId: string | undefined, range: StatsRange): QueryResult<RunStatsRecord | null>;
|
|
45
|
+
/** Run totals of one bot over the range. */
|
|
46
|
+
export declare function useBotRunStats(botAppId: string | undefined, range: StatsRange): QueryResult<RunStatsRecord | null>;
|
|
47
|
+
export interface DailyUsageOptions {
|
|
48
|
+
days: number;
|
|
49
|
+
dimension?: DailyUsageDimension;
|
|
50
|
+
interval?: DailyUsageInterval;
|
|
51
|
+
agentId?: string;
|
|
52
|
+
appId?: string;
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** Daily (or per-window) run statistics for the workspace. */
|
|
56
|
+
export declare function useDailyUsageStats(options: DailyUsageOptions): QueryResult<DailyUsageRecord[]>;
|
|
57
|
+
export interface UsageTotals {
|
|
58
|
+
executionCount: number;
|
|
59
|
+
successCount: number;
|
|
60
|
+
failureCount: number;
|
|
61
|
+
inProgressCount: number;
|
|
62
|
+
successRate: number | null;
|
|
63
|
+
totalTokens: number;
|
|
64
|
+
totalCost: number | null;
|
|
65
|
+
avgDurationMs: number | null;
|
|
66
|
+
}
|
|
67
|
+
/** Fold daily rows into window totals; latency is weighted by run count. */
|
|
68
|
+
export declare function sumUsage(rows: readonly DailyUsageRecord[]): UsageTotals;
|
|
69
|
+
/** Every UTC day of the trailing window, oldest first, as `YYYY-MM-DD`. */
|
|
70
|
+
export declare function windowDays(days: number, now?: number): string[];
|
|
71
|
+
export { DailyUsageDimension, DailyUsageInterval };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { GetAgentRunStatsDocument as e, GetBotRunStatsDocument as t, GetDailyUsageStatsDocument as n } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { useWorkspaceId as r, useWorkspaceQuery as i } from "./internal/workspaceGateway.js";
|
|
3
|
+
import { DailyUsageDimension as a, DailyUsageInterval as o } from "../../generated/wspace-types.js";
|
|
4
|
+
import { useMemo as s } from "react";
|
|
5
|
+
// src/botlit/hooks/useUsageStats.ts
|
|
6
|
+
var c = 864e5;
|
|
7
|
+
function l(e, t = Date.now()) {
|
|
8
|
+
let n = Math.ceil(t / 6e4) * 6e4;
|
|
9
|
+
return {
|
|
10
|
+
startDate: (/* @__PURE__ */ new Date(n - e * c)).toISOString(),
|
|
11
|
+
endDate: new Date(n).toISOString()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function u(e) {
|
|
15
|
+
return e ? {
|
|
16
|
+
totalExecutions: e.totalExecutions,
|
|
17
|
+
successfulExecutions: e.successfulExecutions,
|
|
18
|
+
failedExecutions: e.failedExecutions,
|
|
19
|
+
inProgressExecutions: e.inProgressExecutions,
|
|
20
|
+
successRate: e.successRate ?? null,
|
|
21
|
+
avgDurationMs: e.avgDurationMs ?? null,
|
|
22
|
+
totalCost: e.totalCost,
|
|
23
|
+
pricedExecutions: e.pricedExecutions,
|
|
24
|
+
totalTokens: e.totalTokens,
|
|
25
|
+
lastExecutedAt: e.lastExecutedAt ?? null
|
|
26
|
+
} : null;
|
|
27
|
+
}
|
|
28
|
+
function d(e) {
|
|
29
|
+
return s(() => e === null ? {} : l(e), [e]);
|
|
30
|
+
}
|
|
31
|
+
function f(t, n) {
|
|
32
|
+
let r = d(n), a = s(() => ({
|
|
33
|
+
agentId: t ?? "",
|
|
34
|
+
...r
|
|
35
|
+
}), [t, r]);
|
|
36
|
+
return i({
|
|
37
|
+
document: e,
|
|
38
|
+
variables: a,
|
|
39
|
+
select: (e) => u(e?.getAgentStats),
|
|
40
|
+
fallback: null,
|
|
41
|
+
enabled: !!t,
|
|
42
|
+
errorMessage: "Failed to load agent stats"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function p(e, n) {
|
|
46
|
+
let r = d(n), a = s(() => ({
|
|
47
|
+
botAppId: e ?? "",
|
|
48
|
+
...r
|
|
49
|
+
}), [e, r]);
|
|
50
|
+
return i({
|
|
51
|
+
document: t,
|
|
52
|
+
variables: a,
|
|
53
|
+
select: (e) => u(e?.getBotAppStats),
|
|
54
|
+
fallback: null,
|
|
55
|
+
enabled: !!e,
|
|
56
|
+
errorMessage: "Failed to load bot stats"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
var m = [];
|
|
60
|
+
function h(e) {
|
|
61
|
+
let t = r(), { days: a, dimension: o, interval: c, agentId: l, appId: u, enabled: f = !0 } = e, p = d(a), h = s(() => ({ filter: {
|
|
62
|
+
...p,
|
|
63
|
+
dimension: o,
|
|
64
|
+
interval: c,
|
|
65
|
+
agentId: l,
|
|
66
|
+
appId: u
|
|
67
|
+
} }), [
|
|
68
|
+
p,
|
|
69
|
+
o,
|
|
70
|
+
c,
|
|
71
|
+
l,
|
|
72
|
+
u
|
|
73
|
+
]);
|
|
74
|
+
return i({
|
|
75
|
+
document: n,
|
|
76
|
+
variables: h,
|
|
77
|
+
select: (e) => (e?.getDailyUsageStats ?? m).map((e) => ({
|
|
78
|
+
...e,
|
|
79
|
+
agentId: e.agentId ?? null,
|
|
80
|
+
agentName: e.agentName ?? null,
|
|
81
|
+
appId: e.appId ?? null,
|
|
82
|
+
appName: e.appName ?? null,
|
|
83
|
+
successRate: e.successRate ?? null,
|
|
84
|
+
totalCost: e.totalCost ?? null,
|
|
85
|
+
avgDurationMs: e.avgDurationMs ?? null,
|
|
86
|
+
lastExecutedAt: e.lastExecutedAt ?? null
|
|
87
|
+
})),
|
|
88
|
+
fallback: m,
|
|
89
|
+
enabled: !!t && f,
|
|
90
|
+
errorMessage: "Failed to load usage statistics"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function g(e) {
|
|
94
|
+
let t = 0, n = 0, r = 0, i = 0, a = 0, o = 0, s = 0, c = 0, l = 0;
|
|
95
|
+
for (let u of e) t += u.executionCount, n += u.successCount, r += u.failureCount, i += u.inProgressCount, a += u.totalTokens, u.totalCost !== null && (o += u.totalCost, s += u.pricedRuns), u.avgDurationMs !== null && (l += u.avgDurationMs * u.executionCount, c += u.executionCount);
|
|
96
|
+
let u = n + r;
|
|
97
|
+
return {
|
|
98
|
+
executionCount: t,
|
|
99
|
+
successCount: n,
|
|
100
|
+
failureCount: r,
|
|
101
|
+
inProgressCount: i,
|
|
102
|
+
successRate: u > 0 ? n / u : null,
|
|
103
|
+
totalTokens: a,
|
|
104
|
+
totalCost: s > 0 ? o : null,
|
|
105
|
+
avgDurationMs: c > 0 ? l / c : null
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function _(e, t = Date.now()) {
|
|
109
|
+
let n = new Date(t), r = [];
|
|
110
|
+
for (let t = e - 1; t >= 0; --t) r.push((/* @__PURE__ */ new Date(n.getTime() - t * c)).toISOString().slice(0, 10));
|
|
111
|
+
return r;
|
|
112
|
+
}
|
|
113
|
+
export { a as DailyUsageDimension, o as DailyUsageInterval, g as sumUsage, l as trailingWindow, f as useAgentRunStats, p as useBotRunStats, h as useDailyUsageStats, _ as windowDays };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=useUsageStats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUsageStats.js","names":["DAY_MS","trailingWindow","end","now","days","toRunStats","raw","useRangeVariables","useMemo","range","useAgentRunStats","window","variables","agentId","useWorkspaceQuery","GetAgentRunStatsDocument","data","useBotRunStats","botAppId","GetBotRunStatsDocument","NO_USAGE","useDailyUsageStats","workspaceId","useWorkspaceId","options","dimension","interval","appId","GetDailyUsageStatsDocument","row","enabled","sumUsage","executionCount","successCount","failureCount","inProgressCount","totalTokens","cost","pricedRuns","durationWeight","durationSum","rows","finished","windowDays","out","i","DailyUsageDimension","DailyUsageInterval"],"sources":["../../../src/botlit/hooks/useUsageStats.ts"],"sourcesContent":["/**\n * Run statistics hooks (BOFF-15360 package E)\n * @module botlit/hooks\n *\n * Backed by `getAgentStats` / `getBotAppStats` (per agent or bot) and\n * `getDailyUsageStats` (workspace, per agent or per bot, per day or per window)\n * on wspace-botmanor-svc. Every number is counted by the service over the\n * whole window — nothing here sums rows the browser happened to load.\n */\n\nimport { useMemo } from 'react';\nimport {\n GetAgentRunStatsDocument,\n GetBotRunStatsDocument,\n GetDailyUsageStatsDocument,\n type GetAgentRunStatsQuery,\n type GetBotRunStatsQuery,\n type GetDailyUsageStatsQuery,\n} from '../../generated/wspace-operations';\nimport { DailyUsageDimension, DailyUsageInterval } from '../../generated/wspace-types';\nimport { useWorkspaceId, useWorkspaceQuery, type QueryResult } from './internal/workspaceGateway';\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\nexport interface RunStatsRecord {\n totalExecutions: number;\n successfulExecutions: number;\n failedExecutions: number;\n inProgressExecutions: number;\n /** 0..1 over finished runs; null when none finished. */\n successRate: number | null;\n avgDurationMs: number | null;\n totalCost: number;\n pricedExecutions: number;\n totalTokens: number;\n lastExecutedAt: string | null;\n}\n\nexport interface DailyUsageRecord {\n date: string;\n agentId: string | null;\n agentName: string | null;\n appId: string | null;\n appName: string | null;\n executionCount: number;\n successCount: number;\n failureCount: number;\n inProgressCount: number;\n successRate: number | null;\n totalTokens: number;\n totalCost: number | null;\n pricedRuns: number;\n avgDurationMs: number | null;\n lastExecutedAt: string | null;\n}\n\n/** `null` = whole history; a number = trailing window of that many days. */\nexport type StatsRange = number | null;\n\n/**\n * A trailing window as ISO strings. The end is rounded up to the next minute so\n * the variables stay stable across re-renders within that minute.\n */\nexport function trailingWindow(\n days: number,\n now: number = Date.now()\n): { startDate: string; endDate: string } {\n const end = Math.ceil(now / 60_000) * 60_000;\n return {\n startDate: new Date(end - days * DAY_MS).toISOString(),\n endDate: new Date(end).toISOString(),\n };\n}\n\n/** Fields shared by `AgentStats` and `BotAppStats`. */\ntype RawRunStats = Omit<NonNullable<GetAgentRunStatsQuery['getAgentStats']>, 'agentId'>;\n\nfunction toRunStats(raw: RawRunStats | null | undefined): RunStatsRecord | null {\n if (!raw) return null;\n return {\n totalExecutions: raw.totalExecutions,\n successfulExecutions: raw.successfulExecutions,\n failedExecutions: raw.failedExecutions,\n inProgressExecutions: raw.inProgressExecutions,\n successRate: raw.successRate ?? null,\n avgDurationMs: raw.avgDurationMs ?? null,\n totalCost: raw.totalCost,\n pricedExecutions: raw.pricedExecutions,\n totalTokens: raw.totalTokens,\n lastExecutedAt: (raw.lastExecutedAt as string | null | undefined) ?? null,\n };\n}\n\nfunction useRangeVariables(range: StatsRange) {\n return useMemo(() => (range === null ? {} : trailingWindow(range)), [range]);\n}\n\n/** Run totals of one agent over the range. */\nexport function useAgentRunStats(\n agentId: string | undefined,\n range: StatsRange\n): QueryResult<RunStatsRecord | null> {\n const window = useRangeVariables(range);\n const variables = useMemo(() => ({ agentId: agentId ?? '', ...window }), [agentId, window]);\n return useWorkspaceQuery<GetAgentRunStatsQuery, RunStatsRecord | null>({\n document: GetAgentRunStatsDocument,\n variables,\n select: (data) => toRunStats(data?.getAgentStats),\n fallback: null,\n enabled: Boolean(agentId),\n errorMessage: 'Failed to load agent stats',\n });\n}\n\n/** Run totals of one bot over the range. */\nexport function useBotRunStats(\n botAppId: string | undefined,\n range: StatsRange\n): QueryResult<RunStatsRecord | null> {\n const window = useRangeVariables(range);\n const variables = useMemo(() => ({ botAppId: botAppId ?? '', ...window }), [botAppId, window]);\n return useWorkspaceQuery<GetBotRunStatsQuery, RunStatsRecord | null>({\n document: GetBotRunStatsDocument,\n variables,\n select: (data) => toRunStats(data?.getBotAppStats),\n fallback: null,\n enabled: Boolean(botAppId),\n errorMessage: 'Failed to load bot stats',\n });\n}\n\nconst NO_USAGE: DailyUsageRecord[] = [];\n\nexport interface DailyUsageOptions {\n days: number;\n dimension?: DailyUsageDimension;\n interval?: DailyUsageInterval;\n agentId?: string;\n appId?: string;\n enabled?: boolean;\n}\n\n/** Daily (or per-window) run statistics for the workspace. */\nexport function useDailyUsageStats(options: DailyUsageOptions): QueryResult<DailyUsageRecord[]> {\n const workspaceId = useWorkspaceId();\n const { days, dimension, interval, agentId, appId, enabled = true } = options;\n const window = useRangeVariables(days);\n const variables = useMemo(\n () => ({ filter: { ...window, dimension, interval, agentId, appId } }),\n [window, dimension, interval, agentId, appId]\n );\n return useWorkspaceQuery<GetDailyUsageStatsQuery, DailyUsageRecord[]>({\n document: GetDailyUsageStatsDocument,\n variables,\n select: (data) =>\n (data?.getDailyUsageStats ?? NO_USAGE).map((row) => ({\n ...row,\n agentId: row.agentId ?? null,\n agentName: row.agentName ?? null,\n appId: row.appId ?? null,\n appName: row.appName ?? null,\n successRate: row.successRate ?? null,\n totalCost: row.totalCost ?? null,\n avgDurationMs: row.avgDurationMs ?? null,\n lastExecutedAt: (row.lastExecutedAt as string | null | undefined) ?? null,\n })),\n fallback: NO_USAGE,\n enabled: Boolean(workspaceId) && enabled,\n errorMessage: 'Failed to load usage statistics',\n });\n}\n\nexport interface UsageTotals {\n executionCount: number;\n successCount: number;\n failureCount: number;\n inProgressCount: number;\n successRate: number | null;\n totalTokens: number;\n totalCost: number | null;\n avgDurationMs: number | null;\n}\n\n/** Fold daily rows into window totals; latency is weighted by run count. */\nexport function sumUsage(rows: readonly DailyUsageRecord[]): UsageTotals {\n let executionCount = 0;\n let successCount = 0;\n let failureCount = 0;\n let inProgressCount = 0;\n let totalTokens = 0;\n let cost = 0;\n let pricedRuns = 0;\n let durationWeight = 0;\n let durationSum = 0;\n for (const row of rows) {\n executionCount += row.executionCount;\n successCount += row.successCount;\n failureCount += row.failureCount;\n inProgressCount += row.inProgressCount;\n totalTokens += row.totalTokens;\n if (row.totalCost !== null) {\n cost += row.totalCost;\n pricedRuns += row.pricedRuns;\n }\n if (row.avgDurationMs !== null) {\n durationSum += row.avgDurationMs * row.executionCount;\n durationWeight += row.executionCount;\n }\n }\n const finished = successCount + failureCount;\n return {\n executionCount,\n successCount,\n failureCount,\n inProgressCount,\n successRate: finished > 0 ? successCount / finished : null,\n totalTokens,\n totalCost: pricedRuns > 0 ? cost : null,\n avgDurationMs: durationWeight > 0 ? durationSum / durationWeight : null,\n };\n}\n\n/** Every UTC day of the trailing window, oldest first, as `YYYY-MM-DD`. */\nexport function windowDays(days: number, now: number = Date.now()): string[] {\n const end = new Date(now);\n const out: string[] = [];\n for (let i = days - 1; i >= 0; i -= 1) {\n out.push(new Date(end.getTime() - i * DAY_MS).toISOString().slice(0, 10));\n }\n return out;\n}\n\nexport { DailyUsageDimension, DailyUsageInterval };\n"],"mappings":";;;;;AAsBA,IAAMA,IAAS;AAyCf,SAAgBC,EACd,GACA,IAAc,KAAK,IAAI,GACiB;CACxC,IAAMC,IAAM,KAAK,KAAKC,IAAM,GAAM,IAAI;CACtC,OAAO;EACL,4BAAW,IAAI,KAAKD,IAAME,IAAOJ,CAAM,EAAA,CAAE,YAAY;EACrD,SAAS,IAAI,KAAKE,CAAG,CAAC,CAAC,YAAY;CACrC;AACF;AAKA,SAASG,EAAW,GAA4D;CAE9E,OADKC,IACE;EACL,iBAAiBA,EAAI;EACrB,sBAAsBA,EAAI;EAC1B,kBAAkBA,EAAI;EACtB,sBAAsBA,EAAI;EAC1B,aAAaA,EAAI,eAAe;EAChC,eAAeA,EAAI,iBAAiB;EACpC,WAAWA,EAAI;EACf,kBAAkBA,EAAI;EACtB,aAAaA,EAAI;EACjB,gBAAiBA,EAAI,kBAAgD;CACvE,IAZiB;AAanB;AAEA,SAASC,EAAkB,GAAmB;CAC5C,OAAOC,QAAeC,MAAU,OAAO,CAAC,IAAIR,EAAeQ,CAAK,GAAI,CAACA,CAAK,CAAC;AAC7E;AAGA,SAAgBC,EACd,GACA,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EACjC,cAAc;CAChB,CAAC;AACH;AAcA,SAAgBC,EAAS,GAAgD;CACvE,IAAIC,IAAiB,GACjBC,IAAe,GACfC,IAAe,GACfC,IAAkB,GAClBC,IAAc,GACdC,IAAO,GACPC,IAAa,GACbC,IAAiB,GACjBC,IAAc;CAClB,KAAK,IAAMX,KAAOY,GAUhB,AATA,KAAkBZ,EAAI,gBACtB,KAAgBA,EAAI,cACpB,KAAgBA,EAAI,cACpB,KAAmBA,EAAI,iBACvB,KAAeA,EAAI,aACfA,EAAI,cAAc,SACpB,KAAQA,EAAI,WACZ,KAAcA,EAAI,aAEhBA,EAAI,kBAAkB,SACxB,KAAeA,EAAI,gBAAgBA,EAAI,gBACvC,KAAkBA,EAAI;CAG1B,IAAMa,IAAWT,IAAeC;CAChC,OAAO;EACL;EACA;EACA;EACA;EACA,aAAaQ,IAAW,IAAIT,IAAeS,IAAW;EACtD;EACA,WAAWJ,IAAa,IAAID,IAAO;EACnC,eAAeE,IAAiB,IAAIC,IAAcD,IAAiB;CACrE;AACF;AAGA,SAAgBI,EAAW,GAAc,IAAc,KAAK,IAAI,GAAa;CAC3E,IAAMzC,IAAM,IAAI,KAAKC,CAAG,GAClByC,IAAgB,CAAC;CACvB,KAAK,IAAIC,IAAIzC,IAAO,GAAGyC,KAAK,GAAG,KAC7B,EAAI,sBAAK,IAAI,KAAK3C,EAAI,QAAQ,IAAI2C,IAAI7C,CAAM,EAAA,CAAE,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC;CAE1E,OAAO4C;AACT"}
|
|
@@ -28,15 +28,16 @@ import { formatRelativeTime as p } from "../utils/formatters.js";
|
|
|
28
28
|
import { cn as Ce } from "../utils/cn.js";
|
|
29
29
|
import { agentDeleteMessage as we } from "../utils/agentDelete.js";
|
|
30
30
|
import { confirmAction as m } from "../utils/confirmAction.js";
|
|
31
|
+
import { RunStatsCard as Te } from "../components/RunStatsCard.js";
|
|
31
32
|
import "../permissions/index.js";
|
|
32
|
-
import { useState as
|
|
33
|
-
import { GlassCard as
|
|
33
|
+
import { useState as Ee } from "react";
|
|
34
|
+
import { GlassCard as De, NextSteps as Oe, PagePurpose as ke } from "@burdenoff/fe-libs/ui";
|
|
34
35
|
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
35
|
-
import { useParams as
|
|
36
|
-
import { ArrowLeft as
|
|
36
|
+
import { useParams as Ae, useSearchParams as je } from "react-router";
|
|
37
|
+
import { ArrowLeft as Me, BarChart3 as Ne, BookOpen as v, Brain as y, Edit as Pe, FileText as b, Headset as Fe, History as Ie, MessageSquare as Le, Play as x, Settings as S, Share2 as C, Shield as Re, ShieldCheck as ze, Trash2 as Be, Wrench as w } from "lucide-react";
|
|
37
38
|
import { toast as T } from "sonner";
|
|
38
39
|
// src/botlit/pages/AgentDetailPage.tsx
|
|
39
|
-
var
|
|
40
|
+
var Ve = "🤖", He = [
|
|
40
41
|
"overview",
|
|
41
42
|
"prompt",
|
|
42
43
|
"llm",
|
|
@@ -68,7 +69,7 @@ var Be = "🤖", Ve = [
|
|
|
68
69
|
to: "ARCHIVED",
|
|
69
70
|
variant: "outline",
|
|
70
71
|
confirm: !0
|
|
71
|
-
},
|
|
72
|
+
}, Ue = {
|
|
72
73
|
DRAFT: [E, k],
|
|
73
74
|
ACTIVE: [O, k],
|
|
74
75
|
PAUSED: [D, k],
|
|
@@ -80,8 +81,8 @@ var Be = "🤖", Ve = [
|
|
|
80
81
|
confirm: !1
|
|
81
82
|
}]
|
|
82
83
|
}, A = () => {
|
|
83
|
-
let E = e(), { agentId: D, botId: O } =
|
|
84
|
-
if (
|
|
84
|
+
let E = e(), { agentId: D, botId: O } = Ae(), { navigateTo: k } = Se(), A = ne(), { data: j, loading: We, error: M, refetch: N } = ue(D), [P, Ge] = me(), [Ke, qe] = fe(), Je = pe(), [Ye] = je(), [F, I] = Ee(() => He.find((e) => e === Ye.get("tab")) ?? "overview"), L = ge(), R = he(), Xe = L.data, z = R.data, Ze = ae(), Qe = _e(), $e = de(), B = O ? `bots/${O}/agents` : "agents";
|
|
85
|
+
if (We) return /* @__PURE__ */ g(t, {
|
|
85
86
|
title: E("botlit.common.loading", "Loading..."),
|
|
86
87
|
children: /* @__PURE__ */ g("div", {
|
|
87
88
|
role: "status",
|
|
@@ -110,7 +111,7 @@ var Be = "🤖", Ve = [
|
|
|
110
111
|
})
|
|
111
112
|
})
|
|
112
113
|
});
|
|
113
|
-
let V = j.systemPrompt || "", H = j.llmModelId || "", U = (
|
|
114
|
+
let V = j.systemPrompt || "", H = j.llmModelId || "", U = (Qe.data ?? []).find((e) => e.id === H), W = U ? `${U.name} (${U.modelId})` : H || "Not configured", et = j.temperature, tt = j.maxTokens, G = j.mcpConnectionIds ?? [], K = j.knowledgeBaseIds ?? [], q = j.workflowIds ?? [], J = j.capabilities ?? [], Y = j.maxConcurrentExecutions || 10, X = !!Ze.data?.requireActivationApproval && (j.status === "DRAFT" || j.status === "ARCHIVED") && !j.currentVersionId, Z = new Map(Xe.map((e) => [e.id, e.name])), Q = new Map(z.map((e) => [e.id, e.name])), nt = J.includes("RAG") && !R.loading && !R.error ? K.flatMap((e) => {
|
|
114
115
|
let t = z.find((t) => t.id === e);
|
|
115
116
|
return t ? t.indexStatus === "READY" ? [] : [{
|
|
116
117
|
id: e,
|
|
@@ -121,7 +122,7 @@ var Be = "🤖", Ve = [
|
|
|
121
122
|
name: null,
|
|
122
123
|
status: "MISSING"
|
|
123
124
|
}];
|
|
124
|
-
}) : [],
|
|
125
|
+
}) : [], rt = (e, t, n, r) => t.get(e) ?? (n.loading ? E("botlit.agentDetail.resourceLoading", "Loading…") : n.error ? E("botlit.agentDetail.resourceUnnamed", "Name unavailable") : E(r, "No longer available")), it = (() => {
|
|
125
126
|
switch (j.status) {
|
|
126
127
|
case "ACTIVE": return null;
|
|
127
128
|
case "DRAFT": return X ? E("botlit.agentDetail.reason.pendingApproval", "This agent is a draft. This workspace needs a reviewer to approve it before it goes live: use Request activation.") : j.currentVersionId ? E("botlit.agentDetail.reason.deactivated", "This agent was taken out of service and is a draft again. Activate it to put it back live.") : E("botlit.agentDetail.reason.neverPublished", "This agent is a draft that was never published, so it does not answer bots yet. Activate it to publish it.");
|
|
@@ -162,7 +163,7 @@ var Be = "🤖", Ve = [
|
|
|
162
163
|
error: E("botlit.agentDetail.restore.error", "Failed to restore agent")
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
|
-
},
|
|
166
|
+
}, at = async (e) => {
|
|
166
167
|
if (!D) return;
|
|
167
168
|
let t = $(e.key, j.name);
|
|
168
169
|
if (!(e.confirm && t.confirmTitle && t.confirmMessage && !await m({
|
|
@@ -178,16 +179,16 @@ var Be = "🤖", Ve = [
|
|
|
178
179
|
} catch (e) {
|
|
179
180
|
T.error(e instanceof Error ? e.message : t.error);
|
|
180
181
|
}
|
|
181
|
-
},
|
|
182
|
+
}, ot = async () => {
|
|
182
183
|
if (!D) return;
|
|
183
|
-
let e = await
|
|
184
|
+
let e = await Je(D).catch(() => null), t = we(E, j.name, e);
|
|
184
185
|
if (await m({
|
|
185
186
|
title: E("botlit.agentsList.delete.title", "Delete agent?"),
|
|
186
187
|
message: t,
|
|
187
188
|
confirmLabel: E("botlit.agentsList.delete.okButton", "Delete"),
|
|
188
189
|
cancelLabel: E("botlit.agentsList.delete.cancelButton", "Cancel")
|
|
189
190
|
})) try {
|
|
190
|
-
if (!await
|
|
191
|
+
if (!await Ke(D)) {
|
|
191
192
|
T.error(E("botlit.agentDetail.delete.error", "Failed to delete agent"));
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
@@ -195,7 +196,7 @@ var Be = "🤖", Ve = [
|
|
|
195
196
|
} catch (e) {
|
|
196
197
|
T.error(e instanceof Error ? e.message : E("botlit.agentDetail.delete.error", "Failed to delete agent"));
|
|
197
198
|
}
|
|
198
|
-
},
|
|
199
|
+
}, st = [
|
|
199
200
|
{
|
|
200
201
|
id: "assistant",
|
|
201
202
|
label: "Assistant setup",
|
|
@@ -204,7 +205,7 @@ var Be = "🤖", Ve = [
|
|
|
204
205
|
{
|
|
205
206
|
id: "overview",
|
|
206
207
|
label: E("botlit.agentDetail.tabs.overview", "Overview"),
|
|
207
|
-
icon: /* @__PURE__ */ g(
|
|
208
|
+
icon: /* @__PURE__ */ g(Ne, { size: 16 })
|
|
208
209
|
},
|
|
209
210
|
{
|
|
210
211
|
id: "prompt",
|
|
@@ -229,17 +230,17 @@ var Be = "🤖", Ve = [
|
|
|
229
230
|
{
|
|
230
231
|
id: "guardrails",
|
|
231
232
|
label: E("botlit.agentDetail.tabs.guardrails", "Guardrails"),
|
|
232
|
-
icon: /* @__PURE__ */ g(
|
|
233
|
+
icon: /* @__PURE__ */ g(Re, { size: 16 })
|
|
233
234
|
},
|
|
234
235
|
{
|
|
235
236
|
id: "handoff",
|
|
236
237
|
label: E("botlit.agentDetail.tabs.handoff", "Handoff"),
|
|
237
|
-
icon: /* @__PURE__ */ g(
|
|
238
|
+
icon: /* @__PURE__ */ g(Fe, { size: 16 })
|
|
238
239
|
},
|
|
239
240
|
{
|
|
240
241
|
id: "aiOperations",
|
|
241
242
|
label: E("botlit.agentDetail.tabs.aiOperations", "AI Operations"),
|
|
242
|
-
icon: /* @__PURE__ */ g(
|
|
243
|
+
icon: /* @__PURE__ */ g(ze, { size: 16 })
|
|
243
244
|
},
|
|
244
245
|
{
|
|
245
246
|
id: "a2a",
|
|
@@ -249,7 +250,7 @@ var Be = "🤖", Ve = [
|
|
|
249
250
|
{
|
|
250
251
|
id: "versions",
|
|
251
252
|
label: E("botlit.agentDetail.tabs.versions", "Versions"),
|
|
252
|
-
icon: /* @__PURE__ */ g(
|
|
253
|
+
icon: /* @__PURE__ */ g(Ie, { size: 16 })
|
|
253
254
|
}
|
|
254
255
|
];
|
|
255
256
|
return /* @__PURE__ */ _(t, {
|
|
@@ -259,14 +260,14 @@ var Be = "🤖", Ve = [
|
|
|
259
260
|
size: "icon",
|
|
260
261
|
"aria-label": E("botlit.agentDetail.back", "Back to agents"),
|
|
261
262
|
onClick: () => k(B),
|
|
262
|
-
children: /* @__PURE__ */ g(
|
|
263
|
+
children: /* @__PURE__ */ g(Me, {
|
|
263
264
|
size: 20,
|
|
264
265
|
"aria-hidden": "true"
|
|
265
266
|
})
|
|
266
267
|
}), /* @__PURE__ */ g("span", {
|
|
267
268
|
className: "text-3xl",
|
|
268
269
|
"aria-hidden": "true",
|
|
269
|
-
children: j.avatar ||
|
|
270
|
+
children: j.avatar || Ve
|
|
270
271
|
})] }),
|
|
271
272
|
meta: /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(u, { status: j.status }), /* @__PURE__ */ g(l, {
|
|
272
273
|
variant: "outline",
|
|
@@ -287,10 +288,10 @@ var Be = "🤖", Ve = [
|
|
|
287
288
|
}));
|
|
288
289
|
},
|
|
289
290
|
children: E("botlit.agentApproval.requestAction", "Request activation")
|
|
290
|
-
}) : (
|
|
291
|
+
}) : (Ue[j.status] ?? []).map((e) => /* @__PURE__ */ g(c, {
|
|
291
292
|
variant: e.variant,
|
|
292
|
-
isLoading:
|
|
293
|
-
onClick: () => void
|
|
293
|
+
isLoading: Ge.loading,
|
|
294
|
+
onClick: () => void at(e),
|
|
294
295
|
children: $(e.key, j.name).label
|
|
295
296
|
}, e.key))
|
|
296
297
|
}),
|
|
@@ -298,7 +299,7 @@ var Be = "🤖", Ve = [
|
|
|
298
299
|
permission: d.AGENT_UPDATE,
|
|
299
300
|
children: /* @__PURE__ */ g(c, {
|
|
300
301
|
variant: "outline",
|
|
301
|
-
leftIcon: /* @__PURE__ */ g(
|
|
302
|
+
leftIcon: /* @__PURE__ */ g(Pe, { size: 16 }),
|
|
302
303
|
onClick: () => k(O ? `bots/${O}/agents/${D}/edit` : `agents/${D}/edit`),
|
|
303
304
|
children: E("botlit.agentDetail.actions.editAgent", "Edit Agent")
|
|
304
305
|
})
|
|
@@ -315,22 +316,22 @@ var Be = "🤖", Ve = [
|
|
|
315
316
|
permission: d.AGENT_DELETE,
|
|
316
317
|
children: /* @__PURE__ */ g(c, {
|
|
317
318
|
variant: "destructive",
|
|
318
|
-
leftIcon: /* @__PURE__ */ g(
|
|
319
|
-
isLoading:
|
|
320
|
-
onClick: () => void
|
|
319
|
+
leftIcon: /* @__PURE__ */ g(Be, { size: 16 }),
|
|
320
|
+
isLoading: qe.loading,
|
|
321
|
+
onClick: () => void ot(),
|
|
321
322
|
children: E("botlit.common.delete", "Delete")
|
|
322
323
|
})
|
|
323
324
|
})
|
|
324
325
|
]
|
|
325
326
|
}),
|
|
326
327
|
children: [
|
|
327
|
-
|
|
328
|
+
it && /* @__PURE__ */ g("div", {
|
|
328
329
|
role: "status",
|
|
329
330
|
"data-testid": "agent-status-reason",
|
|
330
331
|
className: "mb-4 rounded-lg border border-status-warning-border bg-status-warning-bg-subtle p-3 text-sm text-text-primary",
|
|
331
|
-
children:
|
|
332
|
+
children: it
|
|
332
333
|
}),
|
|
333
|
-
|
|
334
|
+
nt.length > 0 && /* @__PURE__ */ _("div", {
|
|
334
335
|
role: "status",
|
|
335
336
|
"data-testid": "agent-knowledge-warning",
|
|
336
337
|
className: "mb-4 rounded-lg border border-status-warning-border bg-status-warning-bg-subtle p-3 text-sm text-text-primary",
|
|
@@ -339,7 +340,7 @@ var Be = "🤖", Ve = [
|
|
|
339
340
|
children: E("botlit.agentDetail.knowledgeWarning.title", "This agent cannot answer right now: a knowledge base it uses cannot be searched.")
|
|
340
341
|
}), /* @__PURE__ */ g("ul", {
|
|
341
342
|
className: "mt-1 list-disc pl-5",
|
|
342
|
-
children:
|
|
343
|
+
children: nt.map((e) => /* @__PURE__ */ g("li", { children: e.name === null ? E("botlit.agentDetail.knowledgeWarning.missing", "A knowledge base that no longer exists ({{id}}). Remove it from the agent.", { id: e.id }) : E("botlit.agentDetail.knowledgeWarning.notReady", "\"{{name}}\" is {{status}}.", {
|
|
343
344
|
name: e.name,
|
|
344
345
|
status: E(`botlit.status.${e.status.toLowerCase()}`, e.status.toLowerCase())
|
|
345
346
|
}) }, e.id))
|
|
@@ -366,13 +367,13 @@ var Be = "🤖", Ve = [
|
|
|
366
367
|
})
|
|
367
368
|
]
|
|
368
369
|
}),
|
|
369
|
-
/* @__PURE__ */ g(
|
|
370
|
+
/* @__PURE__ */ g(ke, {
|
|
370
371
|
icon: /* @__PURE__ */ g(y, { size: 18 }),
|
|
371
372
|
children: E("botlit.agentDetail.purpose", "This is the full configuration for a single agent — its prompt, model settings, the tools and knowledge it can use, its guardrails and how it talks to other agents. Use the tabs to inspect or change any part, and test the agent in chat to confirm it behaves the way you expect before going live.")
|
|
372
373
|
}),
|
|
373
374
|
/* @__PURE__ */ g("div", {
|
|
374
375
|
className: "flex gap-1 border-b border-border-subtle overflow-x-auto",
|
|
375
|
-
children:
|
|
376
|
+
children: st.map((e) => /* @__PURE__ */ _("button", {
|
|
376
377
|
onClick: () => I(e.id),
|
|
377
378
|
className: Ce("flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap", F === e.id ? "border-primary text-primary" : "border-transparent text-text-secondary hover:text-text-primary"),
|
|
378
379
|
children: [e.icon, e.label]
|
|
@@ -381,7 +382,7 @@ var Be = "🤖", Ve = [
|
|
|
381
382
|
F === "overview" && /* @__PURE__ */ _("div", {
|
|
382
383
|
className: "space-y-6",
|
|
383
384
|
children: [
|
|
384
|
-
/* @__PURE__ */ g(
|
|
385
|
+
/* @__PURE__ */ g(Oe, {
|
|
385
386
|
storageKey: `botlit-agent-${D}`,
|
|
386
387
|
steps: [
|
|
387
388
|
{
|
|
@@ -420,6 +421,10 @@ var Be = "🤖", Ve = [
|
|
|
420
421
|
agentStatus: j.status,
|
|
421
422
|
onChanged: () => void N()
|
|
422
423
|
}),
|
|
424
|
+
/* @__PURE__ */ g(Te, {
|
|
425
|
+
kind: "agent",
|
|
426
|
+
id: D
|
|
427
|
+
}),
|
|
423
428
|
/* @__PURE__ */ _("div", {
|
|
424
429
|
className: "grid grid-cols-1 lg:grid-cols-3 gap-6",
|
|
425
430
|
children: [
|
|
@@ -498,7 +503,7 @@ var Be = "🤖", Ve = [
|
|
|
498
503
|
]
|
|
499
504
|
})]
|
|
500
505
|
}),
|
|
501
|
-
/* @__PURE__ */ _(
|
|
506
|
+
/* @__PURE__ */ _(De, {
|
|
502
507
|
treatment: "glass",
|
|
503
508
|
glow: !0,
|
|
504
509
|
className: "lg:col-span-2 p-6",
|
|
@@ -577,19 +582,19 @@ var Be = "🤖", Ve = [
|
|
|
577
582
|
children: "Temperature"
|
|
578
583
|
}), /* @__PURE__ */ g("p", {
|
|
579
584
|
className: "font-medium",
|
|
580
|
-
children:
|
|
585
|
+
children: et ?? "Default"
|
|
581
586
|
})] }),
|
|
582
587
|
/* @__PURE__ */ _("div", { children: [/* @__PURE__ */ g("p", {
|
|
583
588
|
className: "text-sm text-text-secondary",
|
|
584
589
|
children: "Max Tokens"
|
|
585
590
|
}), /* @__PURE__ */ g("p", {
|
|
586
591
|
className: "font-medium",
|
|
587
|
-
children:
|
|
592
|
+
children: tt ?? "Default"
|
|
588
593
|
})] })
|
|
589
594
|
]
|
|
590
595
|
})] }), /* @__PURE__ */ _(r, { children: [/* @__PURE__ */ g(o, { children: /* @__PURE__ */ _(s, {
|
|
591
596
|
className: "flex items-center gap-2",
|
|
592
|
-
children: [/* @__PURE__ */ g(
|
|
597
|
+
children: [/* @__PURE__ */ g(Le, { size: 18 }), E("botlit.agentDetail.executionLimits.title", "Execution Limits")]
|
|
593
598
|
}) }), /* @__PURE__ */ _(i, {
|
|
594
599
|
className: "space-y-4",
|
|
595
600
|
children: [
|
|
@@ -634,7 +639,7 @@ var Be = "🤖", Ve = [
|
|
|
634
639
|
})
|
|
635
640
|
}), /* @__PURE__ */ _("div", { children: [/* @__PURE__ */ g("p", {
|
|
636
641
|
className: "font-medium",
|
|
637
|
-
children:
|
|
642
|
+
children: rt(e, Z, L, "botlit.agentDetail.tools.unavailable")
|
|
638
643
|
}), !Z.has(e) && /* @__PURE__ */ g("p", {
|
|
639
644
|
className: "text-sm text-text-secondary font-mono",
|
|
640
645
|
children: e
|
|
@@ -668,7 +673,7 @@ var Be = "🤖", Ve = [
|
|
|
668
673
|
className: "flex items-center justify-between",
|
|
669
674
|
children: [/* @__PURE__ */ g("p", {
|
|
670
675
|
className: "font-medium",
|
|
671
|
-
children:
|
|
676
|
+
children: rt(e, Q, R, "botlit.agentDetail.knowledge.unavailable")
|
|
672
677
|
}), /* @__PURE__ */ _(l, {
|
|
673
678
|
variant: "outline",
|
|
674
679
|
children: ["#", t + 1]
|
|
@@ -698,7 +703,7 @@ var Be = "🤖", Ve = [
|
|
|
698
703
|
agentId: D,
|
|
699
704
|
agentName: j.name,
|
|
700
705
|
delegationEnabled: J.includes("A2A"),
|
|
701
|
-
agents:
|
|
706
|
+
agents: $e.data ?? []
|
|
702
707
|
}),
|
|
703
708
|
F === "versions" && D && /* @__PURE__ */ g(re, {
|
|
704
709
|
agentId: D,
|