diff --git a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/home/AssistantAccessWidget.java b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/home/AssistantAccessWidget.java index 11a8034..5ceb752 100644 --- a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/home/AssistantAccessWidget.java +++ b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/home/AssistantAccessWidget.java @@ -17,6 +17,7 @@ package com.kingsrook.qbits.assistant.home; +import java.util.ArrayList; import java.util.List; import com.kingsrook.qbits.assistant.AssistantRuntime; import com.kingsrook.qbits.assistant.access.AccessExplainer; @@ -28,7 +29,7 @@ import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput; import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput; -import com.kingsrook.qqq.backend.core.model.dashboard.widgets.RawHTML; +import com.kingsrook.qqq.backend.core.model.dashboard.widgets.MultiStatisticsData; import com.kingsrook.qqq.backend.core.model.dashboard.widgets.WidgetType; import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference; import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData; @@ -36,23 +37,19 @@ import com.kingsrook.qqq.backend.core.utils.StringUtils; /******************************************************************************* - ** "Explain access" on the Assistant home: for the viewing user, each table's - ** assistant data access, the user's own UI permissions (from GET - ** /qqq/v1/metaData made with their session) and which tool operations the - ** assistant could call or would be denied, with the reason. Optional widget - ** inputs `table` and `prompt` narrow it. Flow layout only (no tables, no - ** inner scroll), inherited colors for light and dark. + ** "Explain access" on the Assistant home: for the viewing user, a summary of + ** the assistant's data access, with one group per access level (how many + ** tables are at that level, and how many of their tool operations the + ** assistant could call or would be denied, given the user's own UI permissions + ** from GET /qqq/v1/metaData made with their session). The summary has a fixed + ** size however many tables the instance has, and links to the Data Access table, + ** where each table's setting is edited. Optional widget inputs `table` and + ** `prompt` narrow it. *******************************************************************************/ public final class AssistantAccessWidget { public static final String WIDGET_NAME = "assistantAccess"; - private static final String ROOT = "display:grid;gap:.75rem;min-width:0;"; - private static final String CARD = "border:1px solid rgba(127,127,127,.3);border-radius:8px;padding:.75rem 1rem;min-width:0;overflow-wrap:anywhere;"; - private static final String CHIPS = "display:flex;flex-wrap:wrap;gap:.35rem;margin:.5rem 0 0;padding:0;list-style:none;"; - private static final String CHIP = "display:inline-flex;align-items:center;gap:.35rem;padding:.05rem .6rem;border-radius:999px;border:1px solid rgba(127,127,127,.4);font-size:.8rem;"; - private static final String MUTED = "opacity:.75;font-size:.85rem;"; - /******************************************************************************* @@ -72,7 +69,7 @@ public final class AssistantAccessWidget return (new QWidgetMetaData() .withName(WIDGET_NAME) .withLabel("Data access: what the assistant can do for you") - .withType(WidgetType.HTML.getType()) + .withType(WidgetType.MULTI_STATISTICS.getType()) .withCodeReference(new QCodeReference(Renderer.class)) .withGridColumns(12) .withIsCard(true) @@ -82,61 +79,54 @@ public final class AssistantAccessWidget /******************************************************************************* - ** HTML for an explanation. + ** The summary of an explanation: counts per access level, never a block per + ** table. Tables that are not visible to the user and have no assistant access + ** are not counted. *******************************************************************************/ - public static String render(List tables, String userLabel, String prefix) + public static MultiStatisticsData render(List tables, String userLabel, String prefix) { - StringBuilder html = new StringBuilder("
"); - html.append("

Computed for ").append(AssistantHomeView.esc(userLabel)) - .append(" from the UI API (GET /qqq/v1/metaData with your session) and the assistant's data access settings. Every call is still checked by the UI API itself.

"); - if(tables.isEmpty()) + String dataAccessUrl = prefix + "/" + AssistantDataAccess.TABLE_NAME; + List groups = new ArrayList<>(); + List counted = tables.stream().filter(table -> table.uiVisible() || table.mode() != DataAccessMode.NONE).toList(); + + groups.add(new MultiStatisticsData.StatisticsGroupData().withIcon("admin_panel_settings").withHeader("Computed for " + userLabel) + .withSubheader(counted.isEmpty() ? "No table matches." + : "From the UI API (GET /qqq/v1/metaData with your session) and the assistant's data access settings. Every call is still checked by the UI API itself.") + .withStatisticList(List.of(new MultiStatisticsData.StatisticsGroupData.Statistic("Tables (change the data access)", counted.size(), dataAccessUrl)))); + + for(DataAccessMode mode : List.of(DataAccessMode.READ_WRITE, DataAccessMode.READ, DataAccessMode.NONE)) { - html.append("

No table matches.

"); + List atLevel = counted.stream().filter(table -> table.mode() == mode).toList(); + int allowed = 0; + int denied = 0; + for(AccessExplainer.TableAccess table : atLevel) + { + long ok = table.operations().stream().filter(AccessExplainer.OperationCheck::allowed).count(); + allowed += (int) ok; + denied += table.operations().size() - (int) ok; + } + groups.add(new MultiStatisticsData.StatisticsGroupData() + .withIcon(mode == DataAccessMode.NONE ? "block" : mode == DataAccessMode.READ ? "visibility" : "edit") + .withHeader(mode.getLabel()) + .withSubheader("Assistant access: " + mode.getLabel().toLowerCase()) + .withStatisticList(List.of( + new MultiStatisticsData.StatisticsGroupData.Statistic("Tables", atLevel.size(), dataAccessUrl), + new MultiStatisticsData.StatisticsGroupData.Statistic("Tools allowed", allowed, null), + new MultiStatisticsData.StatisticsGroupData.Statistic("Tools denied", denied, null)))); } - for(AccessExplainer.TableAccess table : tables) - { - long allowed = table.operations().stream().filter(AccessExplainer.OperationCheck::allowed).count(); - if(!table.uiVisible() && table.mode() == DataAccessMode.NONE) - { - continue; - } - html.append("
"); - html.append("
").append(AssistantHomeView.esc(table.label())) - .append(" ").append(AssistantHomeView.esc(table.table())).append("") - .append("Assistant access: ").append(table.mode().getLabel()).append(" (") - .append(AssistantHomeView.esc(table.modeSource())).append(")
"); - html.append("

Your UI permissions: ") - .append(table.uiVisible() ? (yes(table.uiRead(), "read") + ", " + yes(table.uiInsert(), "create") + ", " + yes(table.uiEdit(), "edit") + ", " + yes(table.uiDelete(), "delete")) : "not visible to you") - .append(". ").append(allowed).append(" of ").append(table.operations().size()).append(" tools allowed.

"); - html.append("
    "); - for(AccessExplainer.OperationCheck check : table.operations()) - { - html.append("
  • ") - .append("").append(check.allowed() ? "✓" : "✕").append("") - .append(AssistantHomeView.esc(check.tool())).append(": ") - .append(AssistantHomeView.esc(check.reason())).append("
  • "); - } - html.append("
"); - String denied = table.operations().stream().filter(c -> !c.allowed()).map(AccessExplainer.OperationCheck::reason).distinct().findFirst().orElse(null); - if(denied != null) - { - html.append("

Why not: ").append(AssistantHomeView.esc(denied)).append("

"); - } - html.append("
"); - } - html.append("

Change the assistant's data access

"); - return (html.append("
").toString()); + return (new MultiStatisticsData().withStatisticsGroupData(groups)); } /******************************************************************************* - ** + ** A statistics widget that only says something (the assistant is not running, + ** or access cannot be computed). *******************************************************************************/ - private static String yes(boolean value, String word) + private static MultiStatisticsData message(String header, String subheader) { - return ((value ? "" : "no ") + word); + return (new MultiStatisticsData().withStatisticsGroupData(List.of(new MultiStatisticsData.StatisticsGroupData().withIcon("info") + .withHeader(header).withSubheader(subheader).withStatisticList(List.of())))); } @@ -155,7 +145,7 @@ public final class AssistantAccessWidget AssistantRuntime runtime = AssistantRuntime.of(QContext.getQInstance()); if(runtime == null) { - return (new RenderWidgetOutput(new RawHTML(null, "

The assistant is not running on this server.

"))); + return (new RenderWidgetOutput(message("The assistant is not running on this server.", ""))); } String table = input.getQueryParams() == null ? null : input.getQueryParams().get("table"); String prompt = input.getQueryParams() == null ? null : input.getQueryParams().get("prompt"); @@ -170,12 +160,12 @@ public final class AssistantAccessWidget // the UI API is not reachable (no assistant request has told the // // server its port yet, or the call failed): say so, don't guess // //////////////////////////////////////////////////////////////////// - return (new RenderWidgetOutput(new RawHTML(null, "

Access could not be computed from the UI API right now (" - + AssistantHomeView.esc(e.getMessage()) + "). Open the assistant panel once, or set uiApiBaseUrl, then refresh.

"))); + return (new RenderWidgetOutput(message("Access could not be computed from the UI API right now", + e.getMessage() + ". Open the assistant panel once, or set uiApiBaseUrl, then refresh."))); } String user = QContext.getQSession().getUser() == null ? "you" : StringUtils.hasContent(QContext.getQSession().getUser().getFullName()) ? QContext.getQSession().getUser().getFullName() : QContext.getQSession().getUser().getIdReference(); - return (new RenderWidgetOutput(new RawHTML(null, AssistantAccessWidget.render(tables, user, runtime.getConfig().getTablePathPrefix())))); + return (new RenderWidgetOutput(AssistantAccessWidget.render(tables, user, runtime.getConfig().getTablePathPrefix()))); } } diff --git a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/metadata/AssistantMetaDataBuilder.java b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/metadata/AssistantMetaDataBuilder.java index ea9eb25..d32e872 100644 --- a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/metadata/AssistantMetaDataBuilder.java +++ b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/metadata/AssistantMetaDataBuilder.java @@ -62,6 +62,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData; import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType; import com.kingsrook.qqq.backend.core.model.metadata.fields.ValueTooLongBehavior; import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData; +import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppSection; import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon; import com.kingsrook.qqq.backend.core.model.metadata.permissions.DenyBehavior; import com.kingsrook.qqq.backend.core.model.metadata.permissions.PermissionLevel; @@ -120,7 +121,18 @@ public class AssistantMetaDataBuilder ** calls on a conversation; model calls on a provider) or reached from the ** home. Processes are table and record actions, never nav entries. *******************************************************************************/ - public static final List NAV_TABLES = List.of(AssistantScheduledTask.TABLE_NAME, AssistantRagSource.TABLE_NAME, AssistantBudget.TABLE_NAME, AssistantProvider.TABLE_NAME, AssistantProfile.TABLE_NAME, AssistantSkill.TABLE_NAME, AssistantDataAccess.TABLE_NAME, AssistantConversation.TABLE_NAME, AssistantClientError.TABLE_NAME, AssistantModelPrice.TABLE_NAME, AssistantPolicy.TABLE_NAME); + public static final List PRIMARY_NAV_TABLES = List.of(AssistantConversation.TABLE_NAME, AssistantScheduledTask.TABLE_NAME, AssistantRagSource.TABLE_NAME, + AssistantClientError.TABLE_NAME); + + /** The nav's Setup section: who and what the assistant can use. */ + public static final List SETUP_NAV_TABLES = List.of(AssistantProvider.TABLE_NAME, AssistantProfile.TABLE_NAME, AssistantSkill.TABLE_NAME, AssistantDataAccess.TABLE_NAME, + AssistantBudget.TABLE_NAME); + + /** The nav's Settings section. */ + public static final List SETTINGS_NAV_TABLES = List.of(AssistantModelPrice.TABLE_NAME, AssistantPolicy.TABLE_NAME); + + /** Every table in the nav, in nav order (Conversations first). */ + public static final List NAV_TABLES = java.util.stream.Stream.of(PRIMARY_NAV_TABLES, SETUP_NAV_TABLES, SETTINGS_NAV_TABLES).flatMap(List::stream).toList(); private final AssistantQBitConfig config; @@ -171,7 +183,7 @@ public class AssistantMetaDataBuilder QCodeReference insertOnlyDates = new QCodeReference(AssistantInsertOnlyDatesCustomizer.class); QCodeReference conversationCustomizer = new QCodeReference(AssistantConversationCustomizer.class); - tables.add(owned(base(AssistantConversation.TABLE_NAME, "Assistant Conversation", "forum", AssistantConversation.class), false) + tables.add(owned(base(AssistantConversation.TABLE_NAME, "Conversations", "forum", AssistantConversation.class), false) .withRecordLabelFormat("%s") .withRecordLabelFields("title") .withoutCapabilities(Capability.TABLE_INSERT) @@ -181,34 +193,34 @@ public class AssistantMetaDataBuilder .withCustomizer(TableCustomizers.POST_DELETE_RECORD, conversationCustomizer)); text(tables.get(0), "contextJson"); - tables.add(text(readOnly(owned(base(AssistantMessage.TABLE_NAME, "Assistant Message", "chat", AssistantMessage.class), false)), "partsJson") + tables.add(text(readOnly(owned(base(AssistantMessage.TABLE_NAME, "Messages", "chat", AssistantMessage.class), false)), "partsJson") .withRecordLabelFormat("%s #%s").withRecordLabelFields("role", "id")); - tables.add(text(readOnly(owned(base(AssistantTurn.TABLE_NAME, "Assistant Turn", "sync_alt", AssistantTurn.class), false)), "providerRequestIds") + tables.add(text(readOnly(owned(base(AssistantTurn.TABLE_NAME, "Turns", "sync_alt", AssistantTurn.class), false)), "providerRequestIds") .withRecordLabelFormat("Turn #%s").withRecordLabelFields("id")); - tables.add(text(readOnly(owned(base(AssistantTurnEvent.TABLE_NAME, "Assistant Turn Event", "stream", AssistantTurnEvent.class), false)), "dataJson") + tables.add(text(readOnly(owned(base(AssistantTurnEvent.TABLE_NAME, "Turn Events", "stream", AssistantTurnEvent.class), false)), "dataJson") .withRecordLabelFormat("%s #%s").withRecordLabelFields("eventType", "seq")); - tables.add(text(readOnly(owned(base(AssistantToolCall.TABLE_NAME, "Assistant Tool Call", "build", AssistantToolCall.class), false)), "inputJson", "resultJson", "redactionsJson") + tables.add(text(readOnly(owned(base(AssistantToolCall.TABLE_NAME, "Tool Calls", "build", AssistantToolCall.class), false)), "inputJson", "resultJson", "redactionsJson") .withRecordLabelFormat("%s #%s").withRecordLabelFields("toolName", "id")); - tables.add(text(readOnly(owned(base(AssistantFeedback.TABLE_NAME, "Assistant Feedback", "thumbs_up_down", AssistantFeedback.class), false)), "comment")); + tables.add(text(readOnly(owned(base(AssistantFeedback.TABLE_NAME, "Feedback", "thumbs_up_down", AssistantFeedback.class), false)), "comment")); - tables.add(text(readOnly(owned(base(AssistantClientError.TABLE_NAME, "Assistant Client Error", "bug_report", AssistantClientError.class), false)), "message", "stack", "componentStack") + tables.add(text(readOnly(owned(base(AssistantClientError.TABLE_NAME, "Client Errors", "bug_report", AssistantClientError.class), false)), "message", "stack", "componentStack") .withRecordLabelFormat("%s #%s").withRecordLabelFields("scope", "id")); QCodeReference personSave = new QCodeReference(AssistantPersonSaveCustomizer.class); - tables.add(base(AssistantPolicy.TABLE_NAME, "Assistant Policy", "policy", AssistantPolicy.class) + tables.add(base(AssistantPolicy.TABLE_NAME, "Policies", "policy", AssistantPolicy.class) .withRecordLabelFormat("%s").withRecordLabelFields("name") .withCustomizer(TableCustomizers.PRE_INSERT_RECORD, personSave) .withCustomizer(TableCustomizers.PRE_UPDATE_RECORD, personSave)); - tables.add(readOnly(owned(base(AssistantUsageDaily.TABLE_NAME, "Assistant Usage (Daily)", "query_stats", AssistantUsageDaily.class), true)) + tables.add(readOnly(owned(base(AssistantUsageDaily.TABLE_NAME, "Daily Usage", "query_stats", AssistantUsageDaily.class), true)) .withUniqueKey(new UniqueKey("scope", "userId", "usageDate")) .withRecordLabelFormat("%s %s").withRecordLabelFields("scope", "usageDate")); - tables.add(settings(base(AssistantProvider.TABLE_NAME, "Assistant Provider", "settings_input_component", AssistantProvider.class)) + tables.add(settings(base(AssistantProvider.TABLE_NAME, "Providers", "settings_input_component", AssistantProvider.class)) .withUniqueKey(new UniqueKey("name")) .withRecordLabelFormat("%s").withRecordLabelFields("name")); @@ -231,36 +243,36 @@ public class AssistantMetaDataBuilder .withCustomizer(TableCustomizers.POST_INSERT_RECORD, ragCustomizer).withCustomizer(TableCustomizers.POST_UPDATE_RECORD, ragCustomizer) .withCustomizer(TableCustomizers.POST_DELETE_RECORD, ragCustomizer)); - tables.add(settings(base(AssistantModel.TABLE_NAME, "Assistant Model", "memory", AssistantModel.class)) + tables.add(settings(base(AssistantModel.TABLE_NAME, "Models", "memory", AssistantModel.class)) .withUniqueKey(new UniqueKey("providerId", "modelId")) .withRecordLabelFormat("%s").withRecordLabelFields("modelId")); - tables.add(settings(base(AssistantModelPrice.TABLE_NAME, "Assistant Model Price", "sell", AssistantModelPrice.class)) + tables.add(settings(base(AssistantModelPrice.TABLE_NAME, "Model Prices", "sell", AssistantModelPrice.class)) .withUniqueKey(new UniqueKey("providerType", "model")) .withRecordLabelFormat("%s").withRecordLabelFields("model")); - tables.add(readOnly(owned(base(AssistantUsage.TABLE_NAME, "Assistant Model Call", "receipt_long", AssistantUsage.class), false)) + tables.add(readOnly(owned(base(AssistantUsage.TABLE_NAME, "Model Calls", "receipt_long", AssistantUsage.class), false)) .withRecordLabelFormat("%s #%s").withRecordLabelFields("purpose", "id")); - tables.add(dataAccess(base(AssistantDataAccess.TABLE_NAME, "Assistant Data Access", "admin_panel_settings", AssistantDataAccess.class)) + tables.add(dataAccess(base(AssistantDataAccess.TABLE_NAME, "Data Access", "admin_panel_settings", AssistantDataAccess.class)) .withUniqueKey(new UniqueKey("objectType", "objectName")) .withRecordLabelFormat("%s %s").withRecordLabelFields("objectType", "objectName")); - tables.add(profiles(base(AssistantProfile.TABLE_NAME, "Assistant Profile", "face", AssistantProfile.class)) + tables.add(profiles(base(AssistantProfile.TABLE_NAME, "Profiles", "face", AssistantProfile.class)) .withUniqueKey(new UniqueKey("name")) .withRecordLabelFormat("%s").withRecordLabelFields("displayName")); text(tables.get(tables.size() - 1), "personality", "starterPrompts"); - tables.add(profiles(base(AssistantSkill.TABLE_NAME, "Assistant Skill", "school", AssistantSkill.class)) + tables.add(profiles(base(AssistantSkill.TABLE_NAME, "Skills", "school", AssistantSkill.class)) .withUniqueKey(new UniqueKey("name")) .withRecordLabelFormat("%s").withRecordLabelFields("name")); text(tables.get(tables.size() - 1), "instructions"); - tables.add(profiles(base(AssistantProfileSkill.TABLE_NAME, "Assistant Profile Skill", "link", AssistantProfileSkill.class)) + tables.add(profiles(base(AssistantProfileSkill.TABLE_NAME, "Profile Skills", "link", AssistantProfileSkill.class)) .withUniqueKey(new UniqueKey("profileId", "skillId")) .withRecordLabelFormat("%s · %s").withRecordLabelFields("profileId", "skillId")); - tables.add(readOnly(owned(base(AssistantPendingAction.TABLE_NAME, "Assistant Pending Action", "pending_actions", AssistantPendingAction.class), false)) + tables.add(readOnly(owned(base(AssistantPendingAction.TABLE_NAME, "Pending Actions", "pending_actions", AssistantPendingAction.class), false)) .withRecordLabelFormat("%s #%s").withRecordLabelFields("toolName", "id")); text(tables.get(tables.size() - 1), "paramsJson", "beforeJson"); @@ -268,12 +280,12 @@ public class AssistantMetaDataBuilder // the one decision of a pending action: its unique key is what lets // // exactly one request confirm or cancel an action // /////////////////////////////////////////////////////////////////////// - tables.add(readOnly(owned(base(AssistantPendingActionClaim.TABLE_NAME, "Assistant Pending Action Claim", "task_alt", AssistantPendingActionClaim.class), false)) + tables.add(readOnly(owned(base(AssistantPendingActionClaim.TABLE_NAME, "Pending Action Claims", "task_alt", AssistantPendingActionClaim.class), false)) .withUniqueKey(new UniqueKey("pendingActionId")) .withCustomizer(TableCustomizers.PRE_INSERT_RECORD, insertOnlyDates) .withRecordLabelFormat("%s #%s").withRecordLabelFields("decision", "pendingActionId")); - tables.add(readOnly(owned(base(AssistantDataAudit.TABLE_NAME, "Assistant Data Audit", "shield", AssistantDataAudit.class), false)) + tables.add(readOnly(owned(base(AssistantDataAudit.TABLE_NAME, "Data Audit", "shield", AssistantDataAudit.class), false)) .withoutCapabilities(Capability.TABLE_DELETE) .withRecordLabelFormat("%s #%s").withRecordLabelFields("decision", "id")); for(QTableMetaData table : tables) @@ -431,6 +443,9 @@ public class AssistantMetaDataBuilder { tables.stream().filter(t -> t.getName().equals(name)).findFirst().ifPresent(app::withChild); } + app.withSection(new QAppSection().withName("assistant").withLabel("Assistant").withIcon(new QIcon("smart_toy")).withTables(new ArrayList<>(PRIMARY_NAV_TABLES))) + .withSection(new QAppSection().withName("setup").withLabel("Setup").withIcon(new QIcon("tune")).withTables(new ArrayList<>(SETUP_NAV_TABLES))) + .withSection(new QAppSection().withName("settings").withLabel("Settings").withIcon(new QIcon("settings")).withTables(new ArrayList<>(SETTINGS_NAV_TABLES))); return (app); } diff --git a/qbit-assistant/src/main/resources/help/qbit-assistant.yaml b/qbit-assistant/src/main/resources/help/qbit-assistant.yaml index 42f92d0..ce01518 100644 --- a/qbit-assistant/src/main/resources/help/qbit-assistant.yaml +++ b/qbit-assistant/src/main/resources/help/qbit-assistant.yaml @@ -331,7 +331,7 @@ entries: - key: table:assistant_tool_call;field:permissionCheck summary: A short note of the permission check made for the lookup on the asking user's behalf. - key: table:assistant_tool_call;field:rowCount - summary: How many rows the lookup returned to the model, capped by the row limit in Assistant Policy. + summary: How many rows the lookup returned to the model, capped by the row limit in Policies. - key: table:assistant_tool_call;field:widgetName summary: The dashboard widget the lookup rendered, when it was about showing a widget. - key: table:assistant_feedback;slot:help diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/AssistantQBitProducerTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/AssistantQBitProducerTest.java index d998fe4..c41e8df 100644 --- a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/AssistantQBitProducerTest.java +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/AssistantQBitProducerTest.java @@ -93,7 +93,7 @@ class AssistantQBitProducerTest extends BaseAssistantTest // the nav: the home plus the main tables; processes are actions // ////////////////////////////////////////////////////////////////////// assertThat(qInstance.getApp(AssistantMetaDataBuilder.APP_NAME).getChildren()).extracting(c -> c.getName()) - .containsExactly("assistant_scheduled_task", "assistant_rag_source", "assistant_budget", "assistant_provider", "assistant_profile", "assistant_skill", "assistant_data_access", "assistant_conversation", "assistant_client_error", "assistant_model_price", "assistant_policy"); + .containsExactly("assistant_conversation", "assistant_scheduled_task", "assistant_rag_source", "assistant_client_error", "assistant_provider", "assistant_profile", "assistant_skill", "assistant_data_access", "assistant_budget", "assistant_model_price", "assistant_policy"); assertThat(qInstance.getApp(AssistantMetaDataBuilder.APP_NAME).getWidgets()).containsExactly("assistantHealth", "assistantHome", "assistantAccess"); assertThat(qInstance.getProcess(AssistantMetaDataBuilder.RETENTION_PROCESS_NAME).getTableName()).isEqualTo("assistant_conversation"); assertThat(qInstance.getProcess(AssistantMetaDataBuilder.RETENTION_PROCESS_NAME)).isNotNull(); diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/access/ProfilesSkillsAndAccessTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/access/ProfilesSkillsAndAccessTest.java index 65607d4..e3f72d3 100644 --- a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/access/ProfilesSkillsAndAccessTest.java +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/access/ProfilesSkillsAndAccessTest.java @@ -188,9 +188,15 @@ class ProfilesSkillsAndAccessTest extends BaseAssistantTest QContext.init(qInstance, AssistantTestFixture.sessionFor(AssistantTestFixture.ADMIN)); Map adminPage = only(new AssistantApi(config.getRuntime(), QContext.getQSession()).access("page", null)); assertThat(verdict(adminPage, "create_record")).containsEntry("allowed", true); - String html = AssistantAccessWidget.render(config.getRuntime().getAccessExplainer().explain(RuntimeInternals.gateway(config.getRuntime()), AssistantTestFixture.ADMIN, + var summary = AssistantAccessWidget.render(config.getRuntime().getAccessExplainer().explain(RuntimeInternals.gateway(config.getRuntime()), AssistantTestFixture.ADMIN, config.getRuntime().getPolicyService().current(false).tools(), null, null), "Admin", "/app"); - assertThat(html).contains("Page").contains("create_record").contains("Read and write").doesNotContain(" group.getHeader()).contains("Computed for Admin", "Read and write", "Read", "None"); + assertThat(summary.getStatisticsGroupData()).as("a fixed-size summary, not a block per table").hasSize(4); + var readWrite = summary.getStatisticsGroupData().stream().filter(group -> "Read and write".equals(group.getHeader())).findFirst().orElseThrow(); + assertThat(readWrite.getStatisticList()).extracting(statistic -> statistic.getLabel()).containsExactly("Tables", "Tools allowed", "Tools denied"); + assertThat(readWrite.getStatisticList().get(0).getValue()).isPositive(); + assertThat(readWrite.getStatisticList().get(0).getUrl()).isEqualTo("/app/assistant_data_access"); + assertThat(AssistantAccessWidget.widget().getType()).isEqualTo(com.kingsrook.qqq.backend.core.model.dashboard.widgets.WidgetType.MULTI_STATISTICS.getType()); QContext.clear(); } diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AdminAppLayoutTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AdminAppLayoutTest.java new file mode 100644 index 0000000..d57e13b --- /dev/null +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AdminAppLayoutTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2026 Kingsrook, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.kingsrook.qbits.assistant.metadata; + + +import java.util.List; +import com.kingsrook.qbits.assistant.AssistantQBitConfig; +import com.kingsrook.qbits.assistant.model.AssistantConversation; +import com.kingsrook.qbits.assistant.model.AssistantDataAccess; +import com.kingsrook.qbits.assistant.model.AssistantModelPrice; +import com.kingsrook.qbits.assistant.model.AssistantPolicy; +import com.kingsrook.qbits.assistant.model.AssistantProvider; +import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData; +import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + + +/******************************************************************************* + ** The admin app layout: plural labels that do not repeat the app name, and a + ** nav that starts with Conversations and keeps prices and policies under Settings. + *******************************************************************************/ +class AdminAppLayoutTest +{ + /******************************************************************************* + ** Labels are plural and unprefixed, and the nav is in three sections. + *******************************************************************************/ + @Test + void labelsAreUnprefixedAndTheNavIsSectioned() throws Exception + { + AssistantMetaDataBuilder builder = new AssistantMetaDataBuilder(new AssistantQBitConfig()); + List tables = builder.buildTables(); + + assertThat(tables).extracting(QTableMetaData::getLabel).noneMatch(label -> label.startsWith("Assistant ")); + assertThat(label(tables, AssistantConversation.TABLE_NAME)).isEqualTo("Conversations"); + assertThat(label(tables, AssistantProvider.TABLE_NAME)).isEqualTo("Providers"); + assertThat(label(tables, AssistantModelPrice.TABLE_NAME)).isEqualTo("Model Prices"); + assertThat(label(tables, AssistantPolicy.TABLE_NAME)).isEqualTo("Policies"); + assertThat(label(tables, AssistantDataAccess.TABLE_NAME)).isEqualTo("Data Access"); + + QAppMetaData app = builder.buildAdminApp(tables); + assertThat(app.getSections()).extracting(section -> section.getLabel()).containsExactly("Assistant", "Setup", "Settings"); + assertThat(app.getSections().get(0).getTables().get(0)).as("Conversations comes first").isEqualTo(AssistantConversation.TABLE_NAME); + assertThat(app.getSections().get(2).getTables()).containsExactly(AssistantModelPrice.TABLE_NAME, AssistantPolicy.TABLE_NAME); + assertThat(AssistantMetaDataBuilder.NAV_TABLES.get(0)).isEqualTo(AssistantConversation.TABLE_NAME); + } + + + + /******************************************************************************* + ** The label of a table. + *******************************************************************************/ + private static String label(List tables, String name) + { + return (tables.stream().filter(table -> table.getName().equals(name)).findFirst().orElseThrow().getLabel()); + } +} diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AssistantTableWritesTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AssistantTableWritesTest.java index c28b512..356ce1d 100644 --- a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AssistantTableWritesTest.java +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/AssistantTableWritesTest.java @@ -115,7 +115,7 @@ class AssistantTableWritesTest extends BaseAssistantTest new ReplaceInput(), new ConditionalUpdateInput(toolCalls.getName()))) { assertThatThrownBy(() -> new AssistantAdminPermissionChecker().checkPermissionsThrowing(input, toolCalls)).as(input.getClass().getSimpleName()) - .isInstanceOf(QPermissionDeniedException.class).hasMessageContaining("Rows of Assistant Tool Call are written by the assistant; they cannot be"); + .isInstanceOf(QPermissionDeniedException.class).hasMessageContaining("Rows of Tool Calls are written by the assistant; they cannot be"); assertThatThrownBy(() -> new AssistantWrittenByTheAssistantPermissionChecker().checkPermissionsThrowing(input, toolCalls)).isInstanceOf(QPermissionDeniedException.class); } new AssistantAdminPermissionChecker().checkPermissionsThrowing(new QueryInput(toolCalls.getName()), toolCalls); @@ -124,7 +124,7 @@ class AssistantTableWritesTest extends BaseAssistantTest new AssistantAccessPermissionChecker().checkPermissionsThrowing(new UpdateInput(conversations.getName()), conversations); new AssistantAccessPermissionChecker().checkPermissionsThrowing(new DeleteInput(conversations.getName()), conversations); assertThatThrownBy(() -> new AssistantAccessPermissionChecker().checkPermissionsThrowing(new InsertInput(conversations.getName()), conversations)) - .hasMessage("Rows of Assistant Conversation are written by the assistant; they cannot be added."); + .hasMessage("Rows of Conversations are written by the assistant; they cannot be added."); assertThatThrownBy(() -> new AssistantAccessPermissionChecker().checkPermissionsThrowing(new ReplaceInput(), conversations)) .hasMessageContaining("cannot be added"); diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/TablesWrittenByTheAssistantTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/TablesWrittenByTheAssistantTest.java index 2ff3a25..e7e78bf 100644 --- a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/TablesWrittenByTheAssistantTest.java +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/metadata/TablesWrittenByTheAssistantTest.java @@ -174,7 +174,7 @@ class TablesWrittenByTheAssistantTest extends BaseAssistantTest UiApiResult added = screen.create(AssistantConversation.TABLE_NAME, Map.of("title", "Mine", "userId", EDITOR)); assertThat(added.status()).as(added.body()).isEqualTo(403); - assertThat(added.body()).contains("Rows of Assistant Conversation are written by the assistant; they cannot be added."); + assertThat(added.body()).contains("Rows of Conversations are written by the assistant; they cannot be added."); assertThat(store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class)).hasSize(1); AssistantConversation asked = store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class).get(0);