Class AiToolContext

java.lang.Object
com.kingsrook.qqq.backend.core.actions.ai.tools.AiToolContext

public class AiToolContext extends Object
Per-call context for an AI tool: the kernel's instance, settings, exposure policy and redactor, the result being built - and the shared checks and output shaping every tool uses (so no tool can forget one): - visibility (the meta-data customizer, and DENY_HIDE) and exposure checks, - the table READ permission check (recorded in the result's permissionCheck), - action-input preparation (input source USER, omit hidden fields, mask passwords, and the core-enforcement hook), - value shaping: exposure post-filter, masking, redaction and truncation. Created by the kernel, inside the requesting user's QContext.
  • Field Details

  • Constructor Details

  • Method Details

    • getDataGateway

      public AiDataGateway getDataGateway()
      How the data tools read data: the settings' gateway (the assistant's UI API gateway), else the core actions.
    • requireReadableTable

      public QTableMetaData requireReadableTable(String tableName) throws AiToolException
      The table, if this session may read it through the assistant: it exists, is visible to the session (not DENY_HIDE, allowed by any meta-data action customizer), is exposed (not NONE), and the session has READ on it. Otherwise a DENIED exception - with the same message in every case, so a caller can't tell a missing table from a forbidden one.
      Throws:
      AiToolException
    • tableNotAvailable

      public static AiToolException tableNotAvailable(String tableName)
      The DENIED exception for a table that is missing, invisible, unexposed or not readable.
    • canReadTable

      public boolean canReadTable(QTableMetaData table)
      Whether the session may read a table through the assistant (same checks as requireReadableTable, without recording or throwing).
    • hasTablePermission

      public boolean hasTablePermission(QTableMetaData table, TablePermissionSubType permissionSubType)
      Whether the session has a (non-READ) permission on a table.
    • isVisible

      public boolean isVisible(MetaDataWithPermissionRules object)
      Whether a meta-data object (table, process, report, widget, app) is visible to the session - the same rule as MetaDataAction: allowed by any meta-data action customizer, and its permission check is not DENY_HIDE.
    • isAllowed

      public boolean isAllowed(MetaDataWithPermissionRules object)
      Whether a meta-data object is visible to the session AND its permission check fully allows it (not DENY_HIDE, not DENY_DISABLE).
    • personalize

      public QTableMetaData personalize(QTableMetaData table) throws QException
      The table as personalized for this session (fields the session may not see removed by any table personalizer).
      Throws:
      QException
    • getNameableFields

      public Map<String,QFieldMetaData> getNameableFields(QTableMetaData personalizedTable)
      The fields of a (personalized) table the assistant may name - in filters, sorts and field lists - that is, those whose exposure is not NONE.
    • getDefaultValueFields

      public List<QFieldMetaData> getDefaultValueFields(QTableMetaData personalizedTable)
      The fields whose values may be sent to the model by default: exposure MASKED or VALUES, and not heavy or binary.
    • getFieldExposure

      @Deprecated public AiExposure getFieldExposure(QTableMetaData table, QFieldMetaData field)
      Deprecated.
      use FieldAccessHelper.getDecision for access decisions.
      Compatibility projection of the core decision. Metadata-only still omits values from model output, so retain that channel policy reason.
    • getFieldAccessReason

      public String getFieldAccessReason(QTableMetaData table, QFieldMetaData field)
      The reason from the single core decision, used by access reports.
    • getTableExposure

      public AiExposure getTableExposure(QTableMetaData table)
      The effective exposure of a table.
    • prepareInput

      public void prepareInput(AbstractActionInput input)
      Prepare an action input the kernel will run: input source USER (for table, search and widget inputs) and, for query and get, omit hidden fields and mask passwords - then the core permission-enforcement hook.
    • sanitize

      public String sanitize(String value)
      Redact, then truncate, a string for the model (or the UI).
    • wouldTruncate

      public boolean wouldTruncate(String value)
      Whether sanitize would truncate a value.
    • mask

      public String mask(QTableMetaData table, QFieldMetaData field, String value)
      Mask a value of a MASKED field (noting the masking in the redactions).
    • displayValue

      public String displayValue(QTableMetaData table, QFieldMetaData field, QRecord record)
      The value of one field of a record, shaped for its exposure: - NONE / METADATA_ONLY: null (and nothing should be output), - MASKED: the masked display (or raw) value, - VALUES: the display value (or raw value), redacted and truncated.
    • putModelValue

      public void putModelValue(Map<String,Object> values, QTableMetaData table, QFieldMetaData field, QRecord record)
      Add the value of one field of a record to a map for the model: for VALUES fields, the raw value (numbers and booleans as-is, others redacted and truncated) - plus, when it differs, the display value as {field}__display; for MASKED fields, only the masked value; for others, nothing.
    • recordLabel

      public String recordLabel(QTableMetaData personalizedTable, QRecord record)
      A label for a record that is safe to send: the record's label if every field in the table's record label is exposed with VALUES - else the table label and the record's id.
    • recordRef

      public AiRecordRef recordRef(QTableMetaData personalizedTable, QRecord record)
      A record reference (for a record chip) - with a safe label.
    • stringify

      public static String stringify(Serializable value)
      A value as a string (temporal values in ISO form, decimals plain).
    • getQInstance

      public QInstance getQInstance()
      Getter for qInstance
    • getSettings

      public AiToolKernelSettings getSettings()
      Getter for settings
    • getMaxRowsToModel

      public int getMaxRowsToModel()
      The maximum rows to send to the model.
    • getResult

      public AiToolResult getResult()
      Getter for result
    • getRedactions

      public List<String> getRedactions()
      The redactions made so far (sorted, distinct).