@mgamadeus/ddd-agents 0.12.0 → 0.13.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/dist/admin.js CHANGED
@@ -1355,7 +1355,8 @@ const buildAgentSkillCatalogRequests = (apiPrefix) => {
1355
1355
  tool: ({ toolName }) => ({ url: `${prefix}/tools/${encodeURIComponent(toolName)}` }),
1356
1356
  sharedBlocks: () => ({ url: `${prefix}/sharedBlocks` }),
1357
1357
  purposes: (arg = {}) => ({ url: `${prefix}/purposes${toQueryString({ from: arg.from, to: arg.to })}` }),
1358
- skillLoadCounts: (arg = {}) => ({ url: `${prefix}/skillLoadCounts${toQueryString({ from: arg.from, to: arg.to })}` })
1358
+ skillLoadCounts: (arg = {}) => ({ url: `${prefix}/skillLoadCounts${toQueryString({ from: arg.from, to: arg.to })}` }),
1359
+ skillLoadSources: (arg = {}) => ({ url: `${prefix}/skillLoadSources${toQueryString({ from: arg.from, to: arg.to })}` })
1359
1360
  };
1360
1361
  };
1361
1362
  const CATALOG = { type: AGENT_SKILL_CATALOG_TAG, id: "CATALOG" };
@@ -1363,6 +1364,7 @@ const TOOL = { type: AGENT_SKILL_CATALOG_TAG, id: "TOOL" };
1363
1364
  const SHARED_BLOCKS = { type: AGENT_SKILL_CATALOG_TAG, id: "SHARED_BLOCKS" };
1364
1365
  const PURPOSES = { type: AGENT_SKILL_CATALOG_TAG, id: "PURPOSES" };
1365
1366
  const LOAD_COUNTS = { type: AGENT_SKILL_CATALOG_TAG, id: "LOAD_COUNTS" };
1367
+ const LOAD_SOURCES = { type: AGENT_SKILL_CATALOG_TAG, id: "LOAD_SOURCES" };
1366
1368
  const agentSkillCatalogEndpointDefinitions = (apiPrefix) => {
1367
1369
  const requests = buildAgentSkillCatalogRequests(apiPrefix);
1368
1370
  return {
@@ -1370,7 +1372,8 @@ const agentSkillCatalogEndpointDefinitions = (apiPrefix) => {
1370
1372
  adminUiAgentSkillToolDocumentation: { kind: "query", request: requests.tool, providesTags: [TOOL] },
1371
1373
  adminUiAgentSkillSharedBlocks: { kind: "query", request: requests.sharedBlocks, providesTags: [SHARED_BLOCKS] },
1372
1374
  adminUiAgentSkillPurposes: { kind: "query", request: requests.purposes, providesTags: [PURPOSES] },
1373
- adminUiAgentSkillLoadCounts: { kind: "query", request: requests.skillLoadCounts, providesTags: [LOAD_COUNTS] }
1375
+ adminUiAgentSkillLoadCounts: { kind: "query", request: requests.skillLoadCounts, providesTags: [LOAD_COUNTS] },
1376
+ adminUiAgentSkillLoadSources: { kind: "query", request: requests.skillLoadSources, providesTags: [LOAD_SOURCES] }
1374
1377
  };
1375
1378
  };
1376
1379
  const createAgentSkillCatalogApi = ({ baseApi, apiPrefix }) => injectEndpointsOnce(
@@ -1383,7 +1386,8 @@ const createAgentSkillCatalogApi = ({ baseApi, apiPrefix }) => injectEndpointsOn
1383
1386
  useSkillToolDocumentationQuery: hookOf("adminUiAgentSkillToolDocumentation"),
1384
1387
  useSkillSharedBlocksQuery: hookOf("adminUiAgentSkillSharedBlocks"),
1385
1388
  useSkillPurposesQuery: hookOf("adminUiAgentSkillPurposes"),
1386
- useSkillLoadCountsQuery: hookOf("adminUiAgentSkillLoadCounts")
1389
+ useSkillLoadCountsQuery: hookOf("adminUiAgentSkillLoadCounts"),
1390
+ useSkillLoadSourcesQuery: hookOf("adminUiAgentSkillLoadSources")
1387
1391
  })
1388
1392
  );
1389
1393
  const createStaticAgentSkillCatalogApi = (data) => ({
@@ -1391,7 +1395,8 @@ const createStaticAgentSkillCatalogApi = (data) => ({
1391
1395
  useSkillToolDocumentationQuery: staticQueryHook((arg) => data.tool?.(arg)),
1392
1396
  useSkillSharedBlocksQuery: staticQueryHook(() => data.sharedBlocks?.()),
1393
1397
  useSkillPurposesQuery: staticQueryHook((arg) => data.purposes?.(arg ?? {})),
1394
- useSkillLoadCountsQuery: staticQueryHook((arg) => data.skillLoadCounts?.(arg ?? {}))
1398
+ useSkillLoadCountsQuery: staticQueryHook((arg) => data.skillLoadCounts?.(arg ?? {})),
1399
+ useSkillLoadSourcesQuery: staticQueryHook((arg) => data.skillLoadSources?.(arg ?? {}))
1395
1400
  });
1396
1401
  const ADMIN_PERIOD_PRESETS = [
1397
1402
  { id: "7d", days: 7 },
@@ -1964,6 +1969,94 @@ const wireNumberOf = (value) => {
1964
1969
  return null;
1965
1970
  };
1966
1971
  const wireCreatedTimeOf = (row) => row?.changeHistory?.createdTime ?? row?.created ?? null;
1972
+ const SKILL_LOAD_SOURCES_COLLAPSED_ROW_COUNT = 12;
1973
+ const isSkillPreloadCandidate = (loadSource) => (loadSource.modelLoadCount ?? 0) > 0 && (loadSource.preloadCount ?? 0) + (loadSource.subPassPreloadCount ?? 0) === 0;
1974
+ const CountCell = ({ value }) => /* @__PURE__ */ jsx(TableCell, { className: cn("px-3 py-2 text-right align-top tabular-nums", value === 0 && "text-muted-foreground"), children: formatUiNumber(value) });
1975
+ const SkillLoadSourcesPanel = ({ api, period, className }) => {
1976
+ const { t } = useTranslate();
1977
+ const locale = getUiLocale();
1978
+ const [isShowingAll, setIsShowingAll] = useState(false);
1979
+ const query = api.useSkillLoadSourcesQuery({ from: period.from, to: period.to });
1980
+ const response = query.data ?? null;
1981
+ const loadSources = response?.loadSources ?? null;
1982
+ const rows = loadSources === null ? null : wireElementsOf(loadSources);
1983
+ if (query.isLoading || rows === null && query.isFetching) return /* @__PURE__ */ jsx(Skeleton, { className: cn("h-48 w-full rounded-2xl", className) });
1984
+ if (query.isError || rows === null || loadSources === null) {
1985
+ return /* @__PURE__ */ jsx(
1986
+ StatusCallout,
1987
+ {
1988
+ tone: "destructive",
1989
+ title: t("The skill load sources could not be loaded."),
1990
+ description: query.isError ? normalizeDddError(query.error, "").message : void 0,
1991
+ className
1992
+ }
1993
+ );
1994
+ }
1995
+ const percent = new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 0 });
1996
+ const usedTurnCount = loadSources.preloadUsedTurnCount ?? 0;
1997
+ const unusedTurnCount = loadSources.preloadUnusedTurnCount ?? 0;
1998
+ const usedShare = typeof loadSources.preloadUsedShare === "number" ? Math.min(1, Math.max(0, loadSources.preloadUsedShare)) : null;
1999
+ const shownRows = isShowingAll ? rows : rows.slice(0, SKILL_LOAD_SOURCES_COLLAPSED_ROW_COUNT);
2000
+ const notes = [
2001
+ ...response?.isLoadSourceDataAvailable === false ? [{ id: "sourcesUnavailable", tone: "warning", text: t("The turn events cannot be read on this database: no load sources.") }] : [],
2002
+ ...loadSources.isModelLoadCountAvailable === false ? [{ id: "modelLoadsUnavailable", tone: "warning", text: t("The loads of the chat model cannot be counted on this database: only the preloads are shown.") }] : [],
2003
+ ...loadSources.isTruncated === true ? [{ id: "sourcesTruncated", tone: "warning", text: t("The period holds more rows than one read counts: the newest were counted.") }] : []
2004
+ ];
2005
+ return /* @__PURE__ */ jsx(Card, { "data-slot": "skill-load-sources-panel", className: cn("gap-0 py-0 transition-opacity motion-reduce:transition-none", query.isFetching && "opacity-80", className), children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 px-2 py-4", children: [
2006
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4 px-3", children: [
2007
+ /* @__PURE__ */ jsxs("div", { className: "max-w-2xl", children: [
2008
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold", children: t("Loads by source") }),
2009
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("How each skill came into the conversations: preloaded by the decision model (first pass, or the follow-up pass under a preloaded root) or loaded by the chat model itself with load_skills. A skill the model loads itself that no preload brought is a preload candidate.") })
2010
+ ] }),
2011
+ /* @__PURE__ */ jsxs("div", { "data-slot": "skill-preload-outcome", className: "w-60 shrink-0", children: [
2012
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("Preloads used") }),
2013
+ usedShare === null ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("no preloading turn") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2014
+ /* @__PURE__ */ jsxs("span", { className: "flex items-baseline justify-between gap-2 text-sm", children: [
2015
+ /* @__PURE__ */ jsx("span", { className: "font-semibold tabular-nums", children: percent.format(usedShare) }),
2016
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground tabular-nums", children: t("%used% used, %unused% unused", { replacements: { used: formatUiNumber(usedTurnCount), unused: formatUiNumber(unusedTurnCount) } }) })
2017
+ ] }),
2018
+ /* @__PURE__ */ jsx(
2019
+ "span",
2020
+ {
2021
+ role: "meter",
2022
+ "aria-label": t("Preloads used"),
2023
+ "aria-valuemin": 0,
2024
+ "aria-valuemax": 100,
2025
+ "aria-valuenow": Math.round(usedShare * 100),
2026
+ className: "mt-1 block h-1.5 overflow-hidden rounded-full bg-muted",
2027
+ children: /* @__PURE__ */ jsx("span", { className: "block h-full rounded-full bg-[color:var(--series-1,var(--brand))]", style: { width: `${usedShare * 100}%` } })
2028
+ }
2029
+ )
2030
+ ] })
2031
+ ] })
2032
+ ] }),
2033
+ notes.length > 0 && /* @__PURE__ */ jsx("div", { className: "px-3", children: /* @__PURE__ */ jsx(NoteList, { notes }) }),
2034
+ rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: "px-3 py-6 text-center text-sm text-muted-foreground", children: t("No skill was loaded in this period.") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2035
+ /* @__PURE__ */ jsxs(Table, { children: [
2036
+ /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { className: "hover:bg-transparent", children: [
2037
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-xs text-muted-foreground", children: t("Skill", { context: "skill-catalog" }) }),
2038
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-right text-xs text-muted-foreground", children: t("Preload", { context: "skill-load-source" }) }),
2039
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-right text-xs text-muted-foreground", children: t("Follow-up pass", { context: "skill-load-source" }) }),
2040
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-right text-xs text-muted-foreground", children: /* @__PURE__ */ jsx("span", { className: "font-mono", children: "load_skills" }) }),
2041
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-right text-xs text-muted-foreground", children: t("Preload used", { context: "skill-load-source" }) }),
2042
+ /* @__PURE__ */ jsx(TableHead, { className: "px-3 text-right text-xs text-muted-foreground", children: t("Preload unused", { context: "skill-load-source" }) })
2043
+ ] }) }),
2044
+ /* @__PURE__ */ jsx(TableBody, { children: shownRows.map((loadSource) => /* @__PURE__ */ jsxs(TableRow, { "data-slot": "skill-load-source", "data-skill": loadSource.skillName, className: "hover:bg-transparent", children: [
2045
+ /* @__PURE__ */ jsx(TableCell, { className: "px-3 py-2 align-top whitespace-normal", children: /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-2", children: [
2046
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-sm break-all", children: loadSource.skillName }),
2047
+ isSkillPreloadCandidate(loadSource) && /* @__PURE__ */ jsx(Badge, { variant: "warning", className: "text-[10px]", children: t("preload candidate") })
2048
+ ] }) }),
2049
+ /* @__PURE__ */ jsx(CountCell, { value: loadSource.preloadCount ?? 0 }),
2050
+ /* @__PURE__ */ jsx(CountCell, { value: loadSource.subPassPreloadCount ?? 0 }),
2051
+ /* @__PURE__ */ jsx(CountCell, { value: loadSource.modelLoadCount ?? 0 }),
2052
+ /* @__PURE__ */ jsx(CountCell, { value: loadSource.preloadUsedCount ?? 0 }),
2053
+ /* @__PURE__ */ jsx(CountCell, { value: loadSource.preloadUnusedCount ?? 0 })
2054
+ ] }, loadSource.skillName)) })
2055
+ ] }),
2056
+ rows.length > SKILL_LOAD_SOURCES_COLLAPSED_ROW_COUNT && /* @__PURE__ */ jsx("div", { className: "px-3", children: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", "data-slot": "skill-load-sources-toggle", onClick: () => setIsShowingAll((value) => !value), children: isShowingAll ? t("Show fewer skills") : t("{count, plural, one {Show all # skill} other {Show all # skills}}", { count: rows.length }) }) })
2057
+ ] })
2058
+ ] }) });
2059
+ };
1967
2060
  const SkillNames = ({ names }) => /* @__PURE__ */ jsx("span", { className: "flex flex-wrap gap-1", children: names.map((name) => /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "font-mono text-[11px]", children: name }, name)) });
1968
2061
  const SkillPurposesPanel = ({ api, period, describeSkillPurpose, className }) => {
1969
2062
  const { t } = useTranslate();
@@ -2504,6 +2597,7 @@ const AgentSkillCatalogScreen = ({
2504
2597
  /* @__PURE__ */ jsx(NoteList, { notes: loadNotes })
2505
2598
  ] }),
2506
2599
  catalog.totals && /* @__PURE__ */ jsx(SkillCatalogTotalsCard, { totals: catalog.totals }),
2600
+ /* @__PURE__ */ jsx(SkillLoadSourcesPanel, { api, period }),
2507
2601
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
2508
2602
  /* @__PURE__ */ jsx(
2509
2603
  SearchField,
@@ -10290,11 +10384,19 @@ const buildAgentConnectionDriveSearch = ({ connectionId, driveRootId }) => {
10290
10384
  return parameters.toString();
10291
10385
  };
10292
10386
  const readAgentConnectionDriveSelection = (parameters) => {
10387
+ if (parameters.get("reconnect") === "1") return null;
10293
10388
  const connection = parameters.get("connection");
10294
10389
  if (connection === null || !/^\d+$/.test(connection)) return null;
10295
10390
  const driveRoot = parameters.get("driveRoot");
10296
10391
  return { connectionId: Number(connection), driveRootId: driveRoot !== null && /^\d+$/.test(driveRoot) ? Number(driveRoot) : null };
10297
10392
  };
10393
+ const AGENT_CONNECTION_RECONNECT_LINK_PARAMETERS = ["connection", "reconnect"];
10394
+ const buildAgentConnectionReconnectSearch = ({ connectionId }) => new URLSearchParams({ connection: String(connectionId), reconnect: "1" }).toString();
10395
+ const readAgentConnectionReconnectRequest = (parameters) => {
10396
+ if (parameters.get("reconnect") !== "1") return null;
10397
+ const connection = parameters.get("connection");
10398
+ return connection !== null && /^\d+$/.test(connection) ? { connectionId: Number(connection) } : null;
10399
+ };
10298
10400
  const agentConnectionDriveRootDomId = (connectionId, driveRootId) => `connection-${connectionId}-drive-root-${driveRootId}`;
10299
10401
  const AGENT_CONNECTION_DRIVE_CONTEXT = "agent-connection-drive";
10300
10402
  const AGENT_CONNECTION_DRIVE_ROOT_STATUS = defineStatusMap(
@@ -12933,6 +13035,8 @@ const PanelContent = ({
12933
13035
  tableView = true,
12934
13036
  levelsRequest: hostLevelsRequest = null,
12935
13037
  onLevelsRequestHandled,
13038
+ reconnectRequest = null,
13039
+ onReconnectRequestHandled,
12936
13040
  driveRoots = true,
12937
13041
  selectedDrive: hostSelectedDrive,
12938
13042
  onSelectedDriveChange,
@@ -13038,6 +13142,23 @@ const PanelContent = ({
13038
13142
  notify.submitError(toFormSubmitError(error, t("Google could not be connected")));
13039
13143
  }
13040
13144
  };
13145
+ const startedReconnectOf = useRef(null);
13146
+ useEffect(() => {
13147
+ if (!isSuccess || reconnectRequest === null || startedReconnectOf.current === reconnectRequest.connectionId) return;
13148
+ startedReconnectOf.current = reconnectRequest.connectionId;
13149
+ onReconnectRequestHandled?.();
13150
+ const connection = connections.find((candidate) => candidate.connectionId === reconnectRequest.connectionId) ?? null;
13151
+ if (connection === null) {
13152
+ notify.error(t("This connection is not in your list."));
13153
+ return;
13154
+ }
13155
+ if (typeof document !== "undefined") document.querySelector(`[data-connection-id="${connection.connectionId}"]`)?.scrollIntoView?.({ block: "center", behavior: "smooth" });
13156
+ if (!writesAllowed || !canManageAgentConnection(connection, viewer) || connection.provider !== "GOOGLE" || !isOAuthAvailable) {
13157
+ notify.error(t("This connection cannot be reconnected here."));
13158
+ return;
13159
+ }
13160
+ void handleReconnect(connection);
13161
+ }, [isSuccess, reconnectRequest, connections, onReconnectRequestHandled, writesAllowed, viewer, isOAuthAvailable, t]);
13041
13162
  const handlersFor = (connection) => ({
13042
13163
  onChangeLevels: () => setLevelsId(connection.connectionId),
13043
13164
  onChangeSharing: () => setSharingId(connection.connectionId),
@@ -13342,6 +13463,7 @@ export {
13342
13463
  AGENT_CONNECTION_LEVEL_HELP,
13343
13464
  AGENT_CONNECTION_LEVEL_HELP_CONTEXT,
13344
13465
  AGENT_CONNECTION_LEVEL_LABEL,
13466
+ AGENT_CONNECTION_RECONNECT_LINK_PARAMETERS,
13345
13467
  AGENT_CONNECTION_STATUS,
13346
13468
  AGENT_CONNECTION_STATUS_GROUPS,
13347
13469
  AGENT_CONNECTION_STATUS_GROUP_LABEL,
@@ -13436,6 +13558,7 @@ export {
13436
13558
  ProportionBar,
13437
13559
  SERIES_FILL_CLASS_NAMES,
13438
13560
  SKILL_INSTRUCTIONS_FILL_CLASS_NAME,
13561
+ SKILL_LOAD_SOURCES_COLLAPSED_ROW_COUNT,
13439
13562
  SKILL_ROW_GRID_CLASS_NAME,
13440
13563
  SKILL_ROW_WITH_LOADS_GRID_CLASS_NAME,
13441
13564
  SKILL_TOOL_DEFINITIONS_FILL_CLASS_NAME,
@@ -13444,6 +13567,7 @@ export {
13444
13567
  SentPayloadPanel,
13445
13568
  SettingsTab,
13446
13569
  SharedBlocksPanel,
13570
+ SkillLoadSourcesPanel,
13447
13571
  SkillPurposesPanel,
13448
13572
  SkillTreeRowView,
13449
13573
  SlackLogo,
@@ -13510,6 +13634,7 @@ export {
13510
13634
  budgetMeterLevelOf,
13511
13635
  buildAgentConnectionDriveSearch,
13512
13636
  buildAgentConnectionLevelsSearch,
13637
+ buildAgentConnectionReconnectSearch,
13513
13638
  buildAgentConnectionsRequests,
13514
13639
  buildAgentContextCompositionEntries,
13515
13640
  buildAgentContextEntrySegmentViews,
@@ -13628,6 +13753,7 @@ export {
13628
13753
  isRuntimeSettingName,
13629
13754
  isRuntimeSettingSwitch,
13630
13755
  isRuntimeSettingText,
13756
+ isSkillPreloadCandidate,
13631
13757
  jsonChildCountOf,
13632
13758
  jsonChildEntriesOf,
13633
13759
  jsonValueKindOf,
@@ -13659,6 +13785,7 @@ export {
13659
13785
  readAgentConnectReturnParameters,
13660
13786
  readAgentConnectionDriveSelection,
13661
13787
  readAgentConnectionLevelsRequest,
13788
+ readAgentConnectionReconnectRequest,
13662
13789
  readAgentConversationListCost,
13663
13790
  readAgentConversationListIds,
13664
13791
  readAgentConversationListPage,