Compare commits

..
Author SHA1 Message Date
james.maesandClaude Fable 5.2 dc054b34e7 fix(tables): the tables the assistant writes are written by nobody else; a person's save sets no field the server decides
maven / build (push) Successful in 10m16s
build / maven (push) Successful in 10m16s
Every table of the assistant has a decision about who writes it, by
operation (AssistantTableWrites); a table without one is not built. The
settings are edited by an administrator on a record screen. A conversation
is renamed, archived and deleted by its owner, and started only by the
assistant. Everything else (what was said and done, and what was spent) is
written by the assistant only.

The assistant enforces the decision itself, on any QQQ version: a table has
no capability for what a person may not do to it, so a screen is offered no
button and QQQ defines no bulk action; and the permission checker of every
table refuses the insert, update or delete a table route is about to make,
for every person, with 403 and a message that says why. The assistant's own
writes go through AssistantStore, in code, and are unchanged.

A person's save of a settings table sets no field that is not editable (the
id, the create date, who granted an override, health and test results, index
counters, a scheduled task's approval and run fields): StoredRecords.ofSave,
used by every settings customizer, takes them out of a USER save before a
rule sees them. A client that sends a whole record back keeps working.

Tests go through the real table routes against the fixture application.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 22:30:22 -06:00
CI 86e649e165 Bump version to 0.1.0-RC.34 [skip ci] 2026-11-21 04:08:00 +00:00
james.maes 33c358a90f Merge pull request 'fix(settings): a setting saved from its record screen is stored, and is held to its rules as it will be stored (release/0.1)' (#121) from fix/budget-edit-over-http-0.1 into release/0.1
maven / build (push) Successful in 11m46s
build / maven (push) Successful in 11m46s
2026-11-21 03:56:18 +00:00
james.maesandClaude Fable 5.2 fae89fff2f test(settings): no customizer pairs a record with its stored row itself; StoredRecords for integer, long and text keys
maven / build (push) Successful in 10m50s
build / maven (push) Successful in 10m50s
ArchitectureTest refuses a call of oldRecordListToMap anywhere in the
assistant: the map is keyed by the stored key, and the key of a record saved
from a screen is text. StoredRecordsTest pairs a record with its stored row
for an integer, a long and a text key, with the key as text and as a number,
and covers the merged record, refusals and comparisons.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 19:29:38 -06:00
james.maesandClaude Fable 5.2 47eb69edef fix(settings): a setting saved from its record screen is stored, and is held to its rules as it will be stored
A record screen saves through the UI API's table update route: only the
fields that were changed, with the version that was read. The record's key
comes from the request's path, so it reaches a table customizer as text.

AssistantBudgetCustomizer paired the record with its stored row by comparing
that text with the stored integer key, did not find the row, and judged the
one changed field as if it were a whole new budget: 400, nothing stored. The
same pairing was in every settings customizer: budget overrides, data access
rows, providers, knowledge sources and scheduled tasks were refused the same
way; a profile and a skill were stored with the defaults of a new row written
over what the save had not sent.

StoredRecords now does the pairing for all of them: the key of the record
and of each stored row are read as the type of the table's key field before
they are compared, the values being saved are laid over the stored row each
as the type of its field, and a change is found by comparing values of the
same type. A value that cannot be read as the type of its field is refused.

The rules (the host's ceiling on a cost limit, required fields, allowed
periods and scopes, an override's rules) are judged on the record as it will
be stored, for a save of one field exactly as for a save of all of them.

Tests go through the real route against the fixture application; fourteen of
the sixteen fail without the fix.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 19:15:37 -06:00
CI ea072700e8 Bump version to 0.1.0-RC.33 [skip ci] 2026-11-20 16:13:15 +00:00
james.maes bfdf9e7792 Merge pull request 'feat(schema): every table has a create date and a modify date (release 0.1)' (#119) from feat/table-standard-dates-0.1 into release/0.1
maven / build (push) Successful in 14m58s
build / maven (push) Successful in 14m58s
2026-11-20 15:58:19 +00:00
james.maesandClaude Fable 5.2 7f1db4cae1 fix(schema): a row written once has modifyDate equal to createDate exactly
maven / build (push) Successful in 10m40s
build / maven (push) Successful in 10m40s
QQQ's createDate and modifyDate behaviors each read the clock, so the two
values of one insert differ by a few microseconds on a clock finer than the
machine this was first run on. The decision claim and the budget event are
written once and never change; an insert customizer on those two tables makes
modifyDate the same instant as createDate. The test of the other tables no
longer asserts equality they cannot give (they are rewritten when a
transcript is redacted).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 09:13:39 -06:00
james.maesandClaude Fable 5.2 09a176dae6 feat(schema): every table has a create date and a modify date
maven / build (push) Failing after 10m50s
build / maven (push) Failing after 10m50s
Nine tables lacked a standard date: eight had createDate but no modifyDate
(turn events, tool calls, feedback, model calls, data audit, budget events,
client errors, pending action claims) and the budget accounting table had
neither. All nine now declare both, date-time, not editable, set by QQQ.

Every write the QBit makes goes through QQQ's own insert and update actions,
so an insert sets both and an update (an incremented daily usage counter, a
decided pending action, a cleared tool result, a scheduled run that ends, the
accounting row that follows a usage row) moves modifyDate. A table that is
only inserted has modifyDate equal to createDate.

The reference DDL gets an additive block (nullable columns defaulting to the
time of the write, so the previous release keeps working; existing rows get
the table's own creation time). Tests iterate the declared tables, exercise
the store's insert and update paths, and check the DDL creates the columns.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 08:46:00 -06:00
CI 3a6fd1b809 Bump version to 0.1.0-RC.32 [skip ci] 2026-11-18 17:36:52 +00:00
james.maes d8a1168210 Merge pull request 'release: merge develop into release/0.1 (one confirmation for a set, compact answers, file reading, links)' (#117) from rc/develop-into-release-0.1-one-card-files into release/0.1
maven / build (push) Successful in 11m15s
build / maven (push) Successful in 11m15s
2026-11-18 17:25:42 +00:00
james.maesandClaude Fable 5.2 55bcf1a509 release: merge develop into release/0.1 (one confirmation for a set, compact answers, no silent stop at the output ceiling, widgets follow data access, file reading where a host turns it on, links the application gave)
maven / build (push) Successful in 9m18s
build / maven (push) Successful in 9m18s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 11:15:05 -06:00
CI b4bda50ae2 Bump version to 0.1.0-RC.31 [skip ci] 2026-11-14 14:37:13 +00:00
james.maes a4b2b01612 Merge pull request 'release: merge develop into release/0.1 (one tool registry, tool-call service, signed-in writes, spending limit, process confirmation)' (#111) from rc/develop-into-release-0.1-registry into release/0.1
maven / build (push) Successful in 8m54s
build / maven (push) Successful in 8m54s
2026-11-14 14:28:28 +00:00
james.maesandClaude Fable 5.2 a51fd12799 release: merge develop into release/0.1 (one tool registry, tool-call service, signed-in writes, spending limit, process confirmation)
maven / build (push) Successful in 8m7s
build / maven (push) Successful in 8m7s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 07:17:14 -06:00
CI 88aec4afec Bump version to 0.1.0-RC.30 [skip ci] 2026-11-11 17:22:56 +00:00
james.maes ceb31a71b3 Merge pull request 'release: merge develop into release/0.1 (the store as trusted code, a person's own budget)' (#103) from rc/develop-into-release-0.1-everyone into release/0.1
maven / build (push) Successful in 5m33s
build / maven (push) Successful in 5m33s
2026-11-11 17:17:32 +00:00
james.maesandClaude Fable 5.2 e3f68bf7ee Merge develop into release/0.1 for the next 0.1.0 RC (the store as trusted code, a person's own budget)
maven / build (push) Successful in 6m4s
build / maven (push) Successful in 6m5s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 11:10:47 -06:00
CI e37602b71e Bump version to 0.1.0-RC.29 [skip ci] 2026-11-11 16:21:20 +00:00
james.maes cd1cdaa1c0 Merge pull request 'release: merge develop into release/0.1 (weekly budgets, refusal sentence, limit ceiling)' (#101) from rc/develop-into-release-0.1-weekly into release/0.1
maven / build (push) Successful in 5m34s
build / maven (push) Successful in 5m34s
2026-11-11 16:15:55 +00:00
james.maesandClaude Fable 5.2 1ae7bb9cfa Merge develop into release/0.1 for the next 0.1.0 RC (weekly budgets, refusal sentence, limit ceiling)
maven / build (push) Successful in 5m16s
build / maven (push) Successful in 5m16s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 10:08:23 -06:00
CI 6d66deabc9 Bump version to 0.1.0-RC.28 [skip ci] 2026-11-11 14:03:10 +00:00
james.maes 08c8264f23 Merge pull request 'release: merge develop into release/0.1 (save_analysis, decided actions, ask before guessing)' (#99) from rc/develop-into-release-0.1-save into release/0.1
maven / build (push) Successful in 5m55s
build / maven (push) Successful in 5m55s
2026-11-11 13:57:25 +00:00
james.maesandClaude Fable 5.2 07b06f2070 Merge develop into release/0.1 for the next 0.1.0 RC (save_analysis, decided actions, ask before guessing)
maven / build (push) Successful in 5m13s
build / maven (push) Successful in 5m13s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 07:51:36 -06:00
CI 61fca48424 Bump version to 0.1.0-RC.27 [skip ci] 2026-11-11 13:51:22 +00:00
james.maes d761bd4a7d Merge pull request 'release: merge develop into release/0.1 (analyze_records)' (#97) from rc/develop-into-release-0.1-analyze into release/0.1
maven / build (push) Successful in 6m16s
build / maven (push) Successful in 6m16s
2026-11-11 13:45:08 +00:00
james.maes f1634b0911 Merge develop into release/0.1 for the next 0.1.0 RC (analyze_records)
maven / build (push) Successful in 6m27s
build / maven (push) Successful in 6m27s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

# Conflicts:
#	CHANGELOG.md
#	pom.xml
2026-11-11 07:34:30 -06:00
CI feab4caf17 Bump version to 0.1.0-RC.26 [skip ci] 2026-11-09 15:59:36 +00:00
james.maes ba21b72188 Merge pull request 'fix(engine): a stalled database can no longer hang a turn on 'Thinking'' (#94) from fix/turn-watchdog-never-hangs into release/0.1
maven / build (push) Successful in 5m5s
build / maven (push) Successful in 5m5s
2026-11-09 15:54:38 +00:00
james.maesandClaude Sonnet 5.5 0a65702dab fix(engine): a stalled database can no longer hang a turn on 'Thinking'
maven / build (push) Successful in 5m3s
build / maven (push) Successful in 5m3s
The watchdog ran the deadline logic after two database reads and heartbeat() was synchronized on the monitor that finish() needs, so one blocked database call stopped the deadline, the force-finalize and the final message.end. The deadline now runs first with no database access, housekeeping runs on a bounded abandonable worker, finish() has a guard that ends the stream with an error event, and every phase logs at INFO.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 09:48:47 -06:00
CI 739ca6981f Bump version to 0.1.0-RC.25 [skip ci] 2026-11-07 17:28:54 +00:00
james.maes b51dd4dad1 Merge pull request 'release: merge develop into release/0.1 (Gitea-aligned RC)' (#92) from align/develop-into-release-0.1 into release/0.1
maven / build (push) Successful in 8m11s
build / maven (push) Successful in 8m11s
2026-11-07 17:20:44 +00:00
james.maesandClaude Opus 5.5 c3a03b8d84 Merge develop into release/0.1 (Gitea-aligned RC)
maven / build (push) Canceled after 37s
build / maven (push) Canceled after 43s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 11:19:04 -06:00
james.maes 2d25f0b769 Merge pull request 'fix(assistant): store the transcript before message.end so the panel shows the answer' (#85) from fix/transcript-stored-before-message-end into release/0.1
QRun-IO/ci-policy: ci / fork-guard (push) Skipped
QRun-IO/ci-policy: ci / head-profile (push) Skipped
QRun-IO/ci-policy: ci / application-template-0 (push) Skipped
QRun-IO/ci-policy: ci / gradle-1 (push) Skipped
QRun-IO/ci-policy: ci / java-docker-4 (push) Skipped
QRun-IO/ci-policy: ci / java-frontend-browser-5 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6 (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7 (push) Skipped
QRun-IO/ci-policy: ci / node-8 (push) Skipped
QRun-IO/ci-policy: ci / node-9 (push) Skipped
QRun-IO/ci-policy: ci / node-10 (push) Skipped
QRun-IO/ci-policy: ci / node-playwright-11 (push) Skipped
QRun-IO/ci-policy: ci / repository-policy-12 (push) Skipped
QRun-IO/ci-policy: ci / source-config-13 (push) Skipped
QRun-IO/ci-policy: ci / source-config-14 (push) Skipped
QRun-IO/ci-policy: ci / android-0 (push) Skipped
QRun-IO/ci-policy: ci / original-business (push) Skipped
QRun-IO/ci-policy: ci / original-mcp (push) Skipped
QRun-IO/ci-policy: ci / original-voyage (push) Skipped
QRun-IO/ci-policy: ci / original-cli (push) Skipped
QRun-IO/ci-policy: ci / not-enrolled (push) Skipped
QRun-IO/ci-policy: native / fork-deny (push) Skipped
QRun-IO/ci-policy: native / dotnet-0 (push) Skipped
QRun-IO/ci-policy: native / native-result (push) Successful in 7s
QRun-IO/ci-policy: Shared Java Maven CI with Docker / secrets (push) Successful in 29s
QRun-IO/ci-policy: ci / repository-policy (push) Skipped
QRun-IO/ci-policy: ci / java-core-2-head (push) Skipped
QRun-IO/ci-policy: ci / java-docker-3-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-6-head (push) Skipped
QRun-IO/ci-policy: ci / java-maven-7-head (push) Skipped
QRun-IO/ci-policy: Shared Java Maven CI with Docker / verify (push) Successful in 5m57s
QRun-IO/ci-policy: Shared Java Maven CI with Docker / gate (push) Successful in 16s
QRun-IO/ci-policy: ci / java-docker-3 (push) Successful in 24m15s
QRun-IO/ci-policy: ci / ci-result (push) Successful in 8s
2026-11-05 10:17:10 +00:00
james.maesandClaude Sonnet 5.5 c5125f9788 fix(assistant): store the transcript before message.end so the panel shows the answer
QRun-IO/ci-policy: ci / fork-guard (pull_request) Skipped
QRun-IO/ci-policy: ci / head-profile (pull_request) Skipped
QRun-IO/ci-policy: ci / application-template-0 (pull_request) Skipped
QRun-IO/ci-policy: ci / gradle-1 (pull_request) Skipped
QRun-IO/ci-policy: ci / java-maven-6 (pull_request) Skipped
QRun-IO/ci-policy: ci / java-docker-4 (pull_request) Skipped
QRun-IO/ci-policy: ci / java-frontend-browser-5 (pull_request) Skipped
QRun-IO/ci-policy: ci / java-maven-7 (pull_request) Skipped
QRun-IO/ci-policy: ci / node-8 (pull_request) Skipped
QRun-IO/ci-policy: ci / node-9 (pull_request) Skipped
QRun-IO/ci-policy: ci / node-10 (pull_request) Skipped
QRun-IO/ci-policy: ci / node-playwright-11 (pull_request) Skipped
QRun-IO/ci-policy: ci / repository-policy-12 (pull_request) Skipped
QRun-IO/ci-policy: ci / source-config-13 (pull_request) Skipped
QRun-IO/ci-policy: ci / source-config-14 (pull_request) Skipped
QRun-IO/ci-policy: ci / android-0 (pull_request) Skipped
QRun-IO/ci-policy: ci / original-business (pull_request) Skipped
QRun-IO/ci-policy: ci / original-mcp (pull_request) Skipped
QRun-IO/ci-policy: ci / original-voyage (pull_request) Skipped
QRun-IO/ci-policy: ci / original-cli (pull_request) Skipped
QRun-IO/ci-policy: ci / not-enrolled (pull_request) Skipped
QRun-IO/ci-policy: native / fork-deny (pull_request) Skipped
QRun-IO/ci-policy: native / dotnet-0 (pull_request) Skipped
QRun-IO/ci-policy: native / native-result (pull_request) Successful in 11s
QRun-IO/ci-policy: Shared Java Maven CI with Docker / secrets (pull_request) Successful in 36s
QRun-IO/ci-policy: ci / repository-policy (pull_request) Skipped
QRun-IO/ci-policy: ci / java-core-2-head (pull_request) Skipped
QRun-IO/ci-policy: ci / java-docker-3-head (pull_request) Skipped
QRun-IO/ci-policy: ci / java-maven-6-head (pull_request) Skipped
QRun-IO/ci-policy: ci / java-maven-7-head (pull_request) Skipped
QRun-IO/ci-policy: Shared Java Maven CI with Docker / verify (pull_request) Successful in 7m8s
QRun-IO/ci-policy: Shared Java Maven CI with Docker / gate (pull_request) Successful in 23s
QRun-IO/ci-policy: ci / java-docker-3 (pull_request) Successful in 12m50s
QRun-IO/ci-policy: ci / ci-result (pull_request) Successful in 10s
The panel reloads the conversation the moment the stream ends. The
redacted transcript (message parts, pending actions, stored events) was
flushed only after message.end was sent, so that reload read the "[]"
placeholders and showed the newest question and answer as empty bubbles
until the panel was closed and reopened. Persist and flush first, then
emit message.end.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-04 19:15:44 -06:00
james.maesandCodex 3de664e0fd ci: centralize release branch verification and workflows (#75)
Co-authored-by: Codex <noreply@openai.com>
2026-10-21 12:38:46 -05:00
CircleCI 2caa634044 Bump version to 0.1.0-RC.24 [skip ci] 2026-10-16 17:08:39 +00:00
james.maesandClaude Opus 5.5 c77e5b0123 Merge develop into release/0.1 for 0.1.0-RC.24 (#62 optional unreachable providers report DEGRADED)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 11:59:08 -05:00
CircleCI f46735b1c0 Bump version to 0.1.0-RC.23 [skip ci] 2026-10-16 16:04:25 +00:00
github-actions[bot] 86563c64d2 Merge develop into release/0.1 for the next 0.1.0 RC 2026-10-16 15:58:52 +00:00
CircleCI 82febe0f19 Bump version to 0.1.0-RC.22 [skip ci] 2026-10-16 02:27:26 +00:00
james.maesandClaude Opus 5.5 1ea23dfc49 Merge develop into release/0.1 for 0.1.0-RC.22 (#60 fail-soft assistant server)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 21:17:28 -05:00
CircleCI 9d31de46a6 Bump version to 0.1.0-RC.21 [skip ci] 2026-10-16 01:13:38 +00:00
james.maesandClaude Opus 5.5 24b0b3b14a Merge develop into release/0.1 for 0.1.0-RC.21 (#59 records render always carries rows and columns)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 20:04:06 -05:00
CircleCI 1c33e97664 Bump version to 0.1.0-RC.20 [skip ci] 2026-10-15 21:41:12 +00:00
james.maesandClaude Opus 5.5 fcaf2ded7e Merge develop into release/0.1 for 0.1.0-RC.20 (#56 UI API 1.6.0 extension, QQQ RC.15)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 16:30:07 -05:00
CircleCI 2cea8ffd44 Bump version to 0.1.0-RC.19 [skip ci] 2026-10-15 21:12:25 +00:00
james.maesandClaude Opus 5.5 6b98d5216b Merge develop into release/0.1 for 0.1.0-RC.19 (#57 shutdown hook holds the runtime weakly)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 16:04:27 -05:00
CircleCI 6adf390bf8 Bump version to 0.1.0-RC.18 [skip ci] 2026-10-15 03:36:35 +00:00
james.maesandClaude Opus 5.5 bc92c89665 Merge develop into release/0.1 for 0.1.0-RC.18 (#45 health checks)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 22:29:33 -05:00
CircleCI d43402e262 Bump version to 0.1.0-RC.17 [skip ci] 2026-10-15 02:40:56 +00:00
james.maesandClaude Opus 5.5 fe725ac8ff Merge develop into release/0.1 for 0.1.0-RC.17 (#54 assistant answers in the Jobs tray, QQQ RC.8)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 21:32:46 -05:00
CircleCI dfb05d8935 Bump version to 0.1.0-RC.16 [skip ci] 2026-10-15 02:20:24 +00:00
james.maesandClaude Opus 5.5 523fd0128a Merge develop into release/0.1 for 0.1.0-RC.16 (#53 help bundle)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 21:11:51 -05:00
CircleCI 47115fe359 Bump version to 0.1.0-RC.15 [skip ci] 2026-10-15 00:18:50 +00:00
james.maesandClaude Opus 5.5 f2d2b50459 Merge develop into release/0.1 for 0.1.0-RC.15 (#44 transcript redaction)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 19:10:35 -05:00
CircleCI 8c33db9fcf Bump version to 0.1.0-RC.14 [skip ci] 2026-10-14 23:13:46 +00:00
james.maesandClaude Opus 5.5 75a5dedf7f Merge develop into release/0.1 for 0.1.0-RC.14 (#46, #47 indexes and FKs)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 18:07:05 -05:00
CircleCI c1cceaf4c3 Bump version to 0.1.0-RC.13 [skip ci] 2026-10-14 22:27:30 +00:00
james.maesandClaude Opus 5.5 f8a114bbb8 Merge develop into release/0.1 for 0.1.0-RC.13 (#48 seeds and Setup card, #49 durable turns, #50 seed fixes, #52 rollback)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 17:20:45 -05:00
CircleCI 3a7ff1c659 Bump version to 0.1.0-RC.12 [skip ci] 2026-10-14 16:03:00 +00:00
james.maesandClaude Opus 5.5 ea81166454 Merge develop into release/0.1 for 0.1.0-RC.12 (#19 #39 #40 #42 #43)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 10:56:16 -05:00
CircleCI cfcc044055 Bump version to 0.1.0-RC.11 [skip ci] 2026-10-14 12:57:45 +00:00
james.maesandClaude Opus 5.5 620dee488d Merge develop into release/0.1 for 0.1.0-RC.11 (#36 scheduled tasks, #37 provider-api module)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 07:51:34 -05:00
CircleCI e23206f1e8 Bump version to 0.1.0-RC.10 [skip ci] 2026-10-14 12:12:23 +00:00
james.maesandClaude Opus 5.5 c6bae3bcf2 Merge develop into release/0.1 for 0.1.0-RC.10 (#38 bulk-load tools)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 07:09:32 -05:00
CircleCI 2d8459bb24 Bump version to 0.1.0-RC.9 [skip ci] 2026-10-14 01:42:57 +00:00
james.maesandClaude Opus 5.5 ac06a96787 Merge develop into release/0.1 for 0.1.0-RC.9 (presentation #32, RAG and contingent PVs #33, demo #34, P-d/P-e)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 20:39:02 -05:00
CircleCI d4a1f64480 Bump version to 0.1.0-RC.8 [skip ci] 2026-10-14 00:55:57 +00:00
james.maesandClaude Opus 5.5 c28e782075 Merge develop into release/0.1 for 0.1.0-RC.8 (core alerts #31, budgets #26, routing #27)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 19:52:20 -05:00
CircleCI 5c76a13245 Bump version to 0.1.0-RC.7 [skip ci] 2026-10-13 23:31:30 +00:00
james.maesandClaude Opus 5.5 8d1348888d Merge develop into release/0.1 for 0.1.0-RC.7
Provider/model registry and OpenAI-compatible adapter (#22), Bedrock and
Vertex (#23), data classification, PHI routing and HIPAA mode (#24).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 18:28:10 -05:00
CircleCI 47cc572c36 Bump version to 0.1.0-RC.6 [skip ci] 2026-10-13 19:51:20 +00:00
james.maesandClaude Opus 5.5 8099f64bf2 Merge develop into release/0.1 for 0.1.0-RC.6
Tools via /qqq/v1 with a loopback stand-in (#14); profiles, skills,
explain access, denials, ArchUnit and the denial matrix (#15); #16; the
demo pending-action card (#18).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 14:49:14 -05:00
CircleCI ac6ec75deb Bump version to 0.1.0-RC.5 [skip ci] 2026-10-13 18:44:09 +00:00
james.maesandClaude Opus 5.5 1f48a370e3 Merge develop into release/0.1 for 0.1.0-RC.5
Tools are no longer all sent as strict, so Anthropic no longer rejects
every turn with "compiled grammar is too large" (#13).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:40:36 -05:00
CircleCI d0ad2aa0fa Bump version to 0.1.0-RC.4 [skip ci] 2026-10-13 15:24:59 +00:00
james.maesandClaude Opus 5.5 16c8500f59 Merge develop into release/0.1 for 0.1.0-RC.4
App home, provider settings with Test connection, per-call usage and
model prices (#12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 10:23:04 -05:00
CircleCI a8c5f586ee Bump version to 0.1.0-RC.3 [skip ci] 2026-10-12 21:22:35 +00:00
james.maesandClaude Opus 5.5 3dfa775b21 Merge develop into release/0.1 for 0.1.0-RC.3
Assistant Admin record screens (#6), deterministic RobustnessTest (#9)
and the GA-only tag filter (#8), on top of the snake_case rename (#3).
0.1.0-RC.2 on Central is an accidental republish of RC.1, so this
candidate is RC.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:20:10 -05:00
james.maesandClaude Opus 5.5 67f78fd660 ci: fix the GA tag filter YAML (no brackets in the flow sequence) [skip ci]
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:01:54 -05:00
james.maesandClaude Opus 5.5 ff67c6f7cc Set version to 0.1.0-RC.2 and publish only GA tags [skip ci]
0.1.0-RC.2 is already on Maven Central (an RC tag build republished the previous code), so the next release-branch build must publish the following RC. RC tags no longer trigger a publish (/^v[0-9]+\.[0-9]+\.[0-9]+$/ only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:56:59 -05:00
james.maesandClaude Opus 5.5 19551ac2af Merge develop into release/0.1 for 0.1.0-RC.2
Brings the snake_case assistant_ table and key names (#3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:18:00 -05:00
james.maesandClaude Opus 5.5 7263ac627d Bump version to 0.1.0-RC.1 [skip ci]
The orb published 0.1.0-RC.1 but could not push this commit (the
CircleCI deploy key is read only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 12:49:33 -05:00
28 changed files with 1321 additions and 15 deletions

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ Always use the wrapper: Maven 3.10 cannot read the parent POM. The committed def
- Parallel tool results go back in ONE user message, in call order.
- Errors (DENIED, NOT_FOUND, INVALID_INPUT, ERROR) are `is_error` results.
- Unknown tools and over-limit calls also get error results.
- **Who writes a table:** every `assistant_*` table has a decision in `metadata/AssistantTableWrites` (a table without one is not built). A table the assistant writes (messages, turns, tool calls, usage and budget accounting, pending actions, scheduled runs and the like) has no insert, update or delete capability, and the permission checker of every table refuses a write a person may not make through a table route; only `AssistantStore` writes them. A person's save of a settings table sets no field that is not editable: every pre-save customizer starts with `StoredRecords.ofSave`, which takes such fields out of a `USER` save. Never pair a record with its stored row or compare a saved value with a stored one except through `StoredRecords`.
- **Keys:** never stored in a table. `assistant_provider.apiKeyEnvName` holds only an allowed environment variable NAME; `apiKeyStatus` is computed on read (last 4 at most) and stripped on save.
- **Logging:** never log message content, prompts, tool results or keys. Structured end-of-turn log only.
- **Thinking:** thinking is never streamed or stored. The Anthropic adapter keeps the raw assistant message (with signatures) only in memory, as `providerState`, for the tool loop.
+14
View File
@@ -1,5 +1,19 @@
# Changelog
## Unreleased - The tables the assistant writes are written by nobody else; a person's save sets no field the server decides
**A host changes nothing, unless it wrote rows of these tables through a table route, or replaced the permission rules of the assistant's tables (see `UPGRADE.md`).**
- **Every table of the assistant has a decision about who writes it** (`AssistantTableWrites`), by operation. A table without a decision cannot be built, so a new table is decided when it is added.
- *Settings, edited by an administrator on a record screen (insert, update, delete):* `assistant_policy`, `assistant_provider`, `assistant_model`, `assistant_model_price`, `assistant_profile`, `assistant_skill`, `assistant_profile_skill`, `assistant_data_access`, `assistant_rag_source`, `assistant_scheduled_task`, `assistant_budget`, `assistant_budget_override`.
- *A conversation* (`assistant_conversation`) is started by the assistant, through its own API. Its owner renames, pins, archives and deletes it, also through the table routes (update, delete); it is never added there.
- *Written by the assistant only:* what was said and done (`assistant_message`, `assistant_turn`, `assistant_turn_event`, `assistant_tool_call`, `assistant_pending_action`, `assistant_pending_action_claim`, `assistant_feedback`, `assistant_client_error`, `assistant_data_audit`, `assistant_scheduled_run`) and what was spent (`assistant_usage`, `assistant_usage_daily`, `assistant_budget_usage`, `assistant_budget_event`). A rating and a client error are sent to the assistant's own API, which writes them.
- **The assistant enforces the decision itself, on any QQQ version.** A table has no capability (insert, update, delete) for what a person may not do to it, so the metadata a screen reads offers no button for it and QQQ defines no bulk action for it. And the permission checker of every table of the assistant refuses the insert, update or delete a table route is about to make, for every person, with 403 and a message that says why: "Rows of Assistant Tool Call are written by the assistant; they cannot be changed." (`AssistantAdminPermissionChecker`, `AssistantAccessPermissionChecker`, and the new `AssistantWrittenByTheAssistantPermissionChecker` for `assistant_scheduled_run`, which needs no permission to read).
- **The assistant's own writes are unchanged.** They are made by `AssistantStore`, in code, never through a table route: an answer, a tool call, the accounting of a model call, a proposed change and its decision, a scheduled run, retention. Deleting a conversation still deletes what belongs to it.
- **Changed for administrators:** rows of `assistant_message`, `assistant_turn`, `assistant_turn_event`, `assistant_tool_call`, `assistant_feedback`, `assistant_client_error`, `assistant_usage`, `assistant_usage_daily`, `assistant_pending_action` and `assistant_pending_action_claim` had a Delete button on their record screens. They no longer have one. History is removed by the retention process, and a conversation with everything that belongs to it by deleting the conversation.
- **A person's save of a settings table sets no field the server decides.** A field that is not editable (the id, the date a row was created, who granted an override, a provider's health and test results, a model's test result, what a knowledge source indexed, a scheduled task's approval, next run and last run) is taken out of a save whose input source is `USER`, which every table route sets, before a rule sees it or it is stored (`StoredRecords.ofSave`, used by every settings customizer; `assistant_policy`, which has no rules of its own, gets `AssistantPersonSaveCustomizer` for it). It is taken out, not refused: a client that sends a whole record back keeps working, and what it sent for such a field changes nothing. The primary key of an update stays (the route takes it from the path), and so do the dates QQQ itself sets on the save. The assistant's own saves set these fields as before.
- Tests, through the real routes against the fixture application: `TablesWrittenByTheAssistantTest` (for each of the fourteen tables, the administrator of the assistant and an ordinary user are each refused an insert, an update, an update that changes nothing, an update of the modify date and a delete, with 403, and every row is exactly what it was; the metadata offers no write and no bulk action; a conversation is renamed and deleted by its owner and not added; the assistant's own work still writes its tables), `AssistantTableWritesTest` (every table has a decision and is built to it; the checkers refuse every kind of write and nothing else; every table a person edits takes the server's fields out of a person's save and leaves them in the assistant's own), and server-decided fields in `BudgetEditOverHttpTest`, `RecordEditsOverHttpTest`, `AssistantSettingsTest`, `RagTest` and `ScheduledTasksTest`.
## Unreleased - Fixed: a setting saved from its record screen is stored, and is held to its rules as it will be stored
**Nothing for a host to change.**
+1
View File
@@ -107,6 +107,7 @@ Always use the wrapper: Maven 3.10 cannot read the parent POM. The committed def
- A turn goes on by itself after such a reply at most `maxOutputContinuations` times, each a model call under every limit of any other; then it ends `INCOMPLETE`, never `COMPLETE`, with a notice of what was done and what was not. An `INCOMPLETE` answer stays in the conversation's history.
- The output ceiling of one reply is the code's (`models.mainMaxOutputTokens`); a provider row lowers it only down to `minOutputTokensPerRequest` (`TurnEngine.outputCeiling`).
- One answer shows a record once and at most `maxRecordCardsPerTurn` record cards and `maxRecordChipsPerTurn` record links (`TurnEngine.recordToolResult`); a confirmation card is never left out. The caps are presentation only: every call still runs and has its row.
- **Who writes a table:** every `assistant_*` table has a decision in `metadata/AssistantTableWrites` (a table without one is not built). A table the assistant writes (messages, turns, tool calls, usage and budget accounting, pending actions, scheduled runs and the like) has no insert, update or delete capability, and the permission checker of every table refuses a write a person may not make through a table route; only `AssistantStore` writes them. A person's save of a settings table sets no field that is not editable: every pre-save customizer starts with `StoredRecords.ofSave`, which takes such fields out of a `USER` save. Never pair a record with its stored row or compare a saved value with a stored one except through `StoredRecords`.
- **Keys:** never stored in a table. `assistant_provider.apiKeyEnvName` holds only an allowed environment variable NAME; `apiKeyStatus` is computed on read (last 4 at most) and stripped on save.
- Scheduled task `credentialEnvName` is a separately allow-listed environment variable NAME. Tokens never enter rows, model context or logs. `credentialStatus` is computed and stripped on save.
- Scheduled write approval is invalidated by changes to prompt, run-as user, credential reference, profile or write request. Scheduled writes always require the designated user's panel confirmation.
+19
View File
@@ -1,5 +1,24 @@
# Upgrading qbit-assistant
## The tables the assistant writes are written by nobody else (Unreleased)
No schema change and no configuration change. Check three things:
- **Code of the host that writes a row of a table the assistant writes** (`assistant_message`, `assistant_turn`, `assistant_turn_event`,
`assistant_tool_call`, `assistant_pending_action`, `assistant_pending_action_claim`, `assistant_feedback`, `assistant_client_error`,
`assistant_data_audit`, `assistant_scheduled_run`, `assistant_usage`, `assistant_usage_daily`, `assistant_budget_usage`,
`assistant_budget_event`) **through a table route or the application API, as a person:** it is answered with 403 now. Nothing of the
assistant does this. A seed or a migration that writes these tables in code, as the system, is not affected.
- **An administrator's habit of deleting single rows of history on a record screen:** the Delete button is gone from those tables. Use
the retention process, or delete the conversation.
- **A host that replaces the permission rules of the assistant's tables** (through `withTableMetaDataCustomizer`): the refusal is made by
the assistant's permission checkers (`AssistantAdminPermissionChecker`, `AssistantAccessPermissionChecker`,
`AssistantWrittenByTheAssistantPermissionChecker`). Keep them, or call them from the host's own checker.
A person's save of a settings table no longer sets a field that is not editable (the id, `createDate`, `grantedBy`, test and health
results, index counters, a scheduled task's approval and run fields). A client that sent such a field gets no error; the value is not
stored.
## Every table has create and modify dates (Unreleased)
Nine tables gain columns: `modify_date` on `assistant_turn_event`, `assistant_tool_call`,
+1 -1
View File
@@ -20,7 +20,7 @@
<!-- Multi-module build. The qqq-orb sets the revision here; the modules -->
<!-- inherit it, and the flatten plugin resolves it in the published POMs. -->
<properties>
<revision>0.4.0-SNAPSHOT</revision>
<revision>0.1.0-RC.34</revision>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -46,6 +46,11 @@ public class AssistantAccessPermissionChecker implements CustomPermissionChecker
{
throw (new QPermissionDeniedException("Not authorized to use the assistant."));
}
///////////////////////////////////////////////////////////////////////////
// whoever asks: a table the assistant writes is not written by a person //
///////////////////////////////////////////////////////////////////////////
AssistantTableWrites.refuseWhatAPersonMayNotWrite(actionInput, metaDataWithPermissionRules);
}
}
@@ -45,6 +45,11 @@ public class AssistantAdminPermissionChecker implements CustomPermissionChecker
{
throw (new QPermissionDeniedException("Not authorized to access the assistant admin data."));
}
///////////////////////////////////////////////////////////////////////////
// whoever asks: a table the assistant writes is not written by a person //
///////////////////////////////////////////////////////////////////////////
AssistantTableWrites.refuseWhatAPersonMayNotWrite(actionInput, metaDataWithPermissionRules);
}
}
@@ -50,7 +50,7 @@ public class AssistantBudgetCustomizer implements TableCustomizerInterface
@Override
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
StoredRecords stored = StoredRecords.of(input, oldRecordList);
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
for(QRecord record : records)
{
QRecord merged = stored.merged(record);
@@ -51,7 +51,7 @@ public class AssistantDataAccessCustomizer implements TableCustomizerInterface
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
QInstance qInstance = QContext.getQInstance();
StoredRecords stored = StoredRecords.of(input, oldRecordList);
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
for(QRecord record : records)
{
QRecord merged = stored.merged(record);
@@ -198,8 +198,11 @@ public class AssistantMetaDataBuilder
tables.add(text(readOnly(owned(base(AssistantClientError.TABLE_NAME, "Assistant Client Error", "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)
.withRecordLabelFormat("%s").withRecordLabelFields("name"));
.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))
.withUniqueKey(new UniqueKey("scope", "userId", "usageDate"))
@@ -216,7 +219,8 @@ public class AssistantMetaDataBuilder
.withCustomizer(TableCustomizers.POST_QUERY_RECORD, scheduledCustomizer));
tables.add(readOnly(owned(base(AssistantScheduledRun.TABLE_NAME, "Scheduled runs", "history", AssistantScheduledRun.class), false))
.withoutCapabilities(Capability.TABLE_DELETE)
.withPermissionRules(new QPermissionRules().withLevel(PermissionLevel.NOT_PROTECTED))
.withPermissionRules(new QPermissionRules().withLevel(PermissionLevel.NOT_PROTECTED)
.withCustomPermissionChecker(new QCodeReference(AssistantWrittenByTheAssistantPermissionChecker.class)))
.withUniqueKey(new UniqueKey("taskId", "scheduledFor"))
.withRecordLabelFormat("Run #%s").withRecordLabelFields("id"));
@@ -310,6 +314,15 @@ public class AssistantMetaDataBuilder
.withCustomizer(TableCustomizers.PRE_INSERT_RECORD, insertOnlyDates)
.withUniqueKey(new UniqueKey("budgetId", "scopeKey", "periodStart", "state")));
tables.forEach(AssistantRecordScreens::apply);
/////////////////////////////////////////////////////////////////////////////////
// who writes each table: a table the assistant writes offers a person no //
// insert, update or delete (and a table nobody decided about is not built) //
/////////////////////////////////////////////////////////////////////////////////
for(QTableMetaData table : tables)
{
AssistantTableWrites.apply(table);
}
return (tables);
}
@@ -498,7 +511,8 @@ public class AssistantMetaDataBuilder
/*******************************************************************************
** Only the qbit writes these (admins may still delete rows).
** Only the qbit writes these. AssistantTableWrites is where that is decided
** for every table, and enforced (it also takes the delete capability away).
*******************************************************************************/
private static QTableMetaData readOnly(QTableMetaData table)
{
@@ -0,0 +1,46 @@
/*
* 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 com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import java.util.List;
import java.util.Optional;
/*******************************************************************************
** For a settings table that has no rules of its own to check: a person's save
** sets only what a person decides. The fields the server decides (the id, the
** dates, every field that is not editable) are taken out of it, as they are
** for every other settings table by its own customizer. See
** {@link StoredRecords#ofSave}.
*******************************************************************************/
public class AssistantPersonSaveCustomizer implements TableCustomizerInterface
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
StoredRecords.ofSave(input, records, oldRecordList);
return (records);
}
}
@@ -55,7 +55,7 @@ public class AssistantProfileCustomizer implements TableCustomizerInterface
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
String table = tableName(input);
StoredRecords stored = StoredRecords.of(input, oldRecordList);
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
for(QRecord record : records)
{
QRecord merged = stored.merged(record);
@@ -48,7 +48,7 @@ public class AssistantRagSourceCustomizer implements TableCustomizerInterface
@Override
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
StoredRecords stored = StoredRecords.of(input, oldRecordList);
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
AssistantRuntime runtime = AssistantRuntime.of(QContext.getQInstance());
for(QRecord record : records)
{
@@ -50,7 +50,7 @@ public class AssistantScheduledTaskCustomizer implements TableCustomizerInterfac
@Override
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
StoredRecords stored = StoredRecords.of(input, oldRecordList);
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
AssistantRuntime runtime = AssistantRuntime.of(QContext.getQInstance());
for(QRecord record : records)
{
@@ -79,6 +79,7 @@ public class AssistantSettingsCustomizer implements TableCustomizerInterface
public List<QRecord> preInsertOrUpdate(AbstractActionInput input, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
ProviderService service = service();
StoredRecords stored = StoredRecords.ofSave(input, records, oldRecordList);
if(AssistantModel.TABLE_NAME.equals(tableName(input)))
{
for(QRecord record : records)
@@ -115,7 +116,6 @@ public class AssistantSettingsCustomizer implements TableCustomizerInterface
return (records);
}
StoredRecords stored = StoredRecords.of(input, oldRecordList);
for(QRecord record : records)
{
record.removeValue(ProviderService.KEY_STATUS_FIELD);
@@ -0,0 +1,294 @@
/*
* 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 com.kingsrook.qbits.assistant.model.AssistantBudget;
import com.kingsrook.qbits.assistant.model.AssistantBudgetEvent;
import com.kingsrook.qbits.assistant.model.AssistantBudgetOverride;
import com.kingsrook.qbits.assistant.model.AssistantBudgetUsage;
import com.kingsrook.qbits.assistant.model.AssistantClientError;
import com.kingsrook.qbits.assistant.model.AssistantConversation;
import com.kingsrook.qbits.assistant.model.AssistantDataAccess;
import com.kingsrook.qbits.assistant.model.AssistantDataAudit;
import com.kingsrook.qbits.assistant.model.AssistantFeedback;
import com.kingsrook.qbits.assistant.model.AssistantMessage;
import com.kingsrook.qbits.assistant.model.AssistantModel;
import com.kingsrook.qbits.assistant.model.AssistantModelPrice;
import com.kingsrook.qbits.assistant.model.AssistantPendingAction;
import com.kingsrook.qbits.assistant.model.AssistantPendingActionClaim;
import com.kingsrook.qbits.assistant.model.AssistantPolicy;
import com.kingsrook.qbits.assistant.model.AssistantProfile;
import com.kingsrook.qbits.assistant.model.AssistantProfileSkill;
import com.kingsrook.qbits.assistant.model.AssistantProvider;
import com.kingsrook.qbits.assistant.model.AssistantRagSource;
import com.kingsrook.qbits.assistant.model.AssistantScheduledRun;
import com.kingsrook.qbits.assistant.model.AssistantScheduledTask;
import com.kingsrook.qbits.assistant.model.AssistantSkill;
import com.kingsrook.qbits.assistant.model.AssistantToolCall;
import com.kingsrook.qbits.assistant.model.AssistantTurn;
import com.kingsrook.qbits.assistant.model.AssistantTurnEvent;
import com.kingsrook.qbits.assistant.model.AssistantUsage;
import com.kingsrook.qbits.assistant.model.AssistantUsageDaily;
import com.kingsrook.qbits.assistant.persistence.AssistantStore;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QPermissionDeniedException;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.replace.ReplaceInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.ConditionalUpdateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.metadata.permissions.MetaDataWithPermissionRules;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
/*******************************************************************************
** Who writes each table of the assistant.
**
** Some tables are settings a person edits on a record screen: budgets,
** providers, profiles. The others are written by the assistant itself as it
** works: what was asked and answered, what a tool did, what a model call
** cost. Those are the record of what happened, and the spending limit is
** counted from them: a person changes none of them through a table route,
** whoever the person is. An administrator who could edit or delete a row of
** the accounting could give themselves any spending limit.
**
** Every table has a decision here, by operation. A table without one cannot
** be built ({@link #apply}), so a new table is decided when it is added. The
** decision is enforced by the assistant itself, in two ways that need nothing
** of the QQQ version underneath:
**
** - the table does not have the capability (insert, update, delete) a person
** may not use, so the metadata a screen reads offers no button for it and
** QQQ defines no bulk action for it;
** - the permission checker of every table refuses the write
** ({@link #refuseWhatAPersonMayNotWrite}): a table route asks it before it
** does anything, with the insert, update or delete it is about to make.
**
** The assistant's own writes are not asked: they are made by
** {@link AssistantStore}, in code, never through a table route.
*******************************************************************************/
public final class AssistantTableWrites
{
/*******************************************************************************
** What a table route can do to a row.
*******************************************************************************/
public enum Operation
{
INSERT(Capability.TABLE_INSERT, "added"),
UPDATE(Capability.TABLE_UPDATE, "changed"),
DELETE(Capability.TABLE_DELETE, "deleted");
private final Capability capability;
private final String done;
/*******************************************************************************
**
*******************************************************************************/
Operation(Capability capability, String done)
{
this.capability = capability;
this.done = done;
}
}
private static final Set<Operation> EVERYTHING = Set.copyOf(EnumSet.allOf(Operation.class));
private static final Set<Operation> NOTHING = Set.of();
/////////////////////////////////////////////////////////////////////////////////////////
// what a person does to each table through a table route. everything else is done by //
// the assistant (AssistantStore), in code. //
/////////////////////////////////////////////////////////////////////////////////////////
private static final Map<String, Set<Operation>> BY_A_PERSON = Map.ofEntries(
////////////////////////////////////////////////////////
// settings: an administrator's, on its record screen //
////////////////////////////////////////////////////////
Map.entry(AssistantPolicy.TABLE_NAME, EVERYTHING),
Map.entry(AssistantProvider.TABLE_NAME, EVERYTHING),
Map.entry(AssistantModel.TABLE_NAME, EVERYTHING),
Map.entry(AssistantModelPrice.TABLE_NAME, EVERYTHING),
Map.entry(AssistantProfile.TABLE_NAME, EVERYTHING),
Map.entry(AssistantSkill.TABLE_NAME, EVERYTHING),
Map.entry(AssistantProfileSkill.TABLE_NAME, EVERYTHING),
Map.entry(AssistantDataAccess.TABLE_NAME, EVERYTHING),
Map.entry(AssistantRagSource.TABLE_NAME, EVERYTHING),
Map.entry(AssistantScheduledTask.TABLE_NAME, EVERYTHING),
Map.entry(AssistantBudget.TABLE_NAME, EVERYTHING),
Map.entry(AssistantBudgetOverride.TABLE_NAME, EVERYTHING),
/////////////////////////////////////////////////////////////////////////////////////
// a conversation is started by the assistant (a question is asked through its own //
// API); its owner renames, pins, archives and deletes it, also on a record screen //
// (AssistantConversationCustomizer says which fields, and deletes what belongs to //
// a deleted conversation) //
/////////////////////////////////////////////////////////////////////////////////////
Map.entry(AssistantConversation.TABLE_NAME, Set.of(Operation.UPDATE, Operation.DELETE)),
///////////////////////////////////////////////////////////////////////////////////
// what was said and done: written through the assistant's own API and its turn //
// engine. a rating and a client error are sent to the assistant's API too, not //
// to a table route. //
///////////////////////////////////////////////////////////////////////////////////
Map.entry(AssistantMessage.TABLE_NAME, NOTHING),
Map.entry(AssistantTurn.TABLE_NAME, NOTHING),
Map.entry(AssistantTurnEvent.TABLE_NAME, NOTHING),
Map.entry(AssistantToolCall.TABLE_NAME, NOTHING),
Map.entry(AssistantPendingAction.TABLE_NAME, NOTHING),
Map.entry(AssistantPendingActionClaim.TABLE_NAME, NOTHING),
Map.entry(AssistantFeedback.TABLE_NAME, NOTHING),
Map.entry(AssistantClientError.TABLE_NAME, NOTHING),
Map.entry(AssistantDataAudit.TABLE_NAME, NOTHING),
Map.entry(AssistantScheduledRun.TABLE_NAME, NOTHING),
//////////////////////////////////////////////////////////////////
// what was spent: the spending limits are counted from these //
//////////////////////////////////////////////////////////////////
Map.entry(AssistantUsage.TABLE_NAME, NOTHING),
Map.entry(AssistantUsageDaily.TABLE_NAME, NOTHING),
Map.entry(AssistantBudgetUsage.TABLE_NAME, NOTHING),
Map.entry(AssistantBudgetEvent.TABLE_NAME, NOTHING));
/*******************************************************************************
** Utility class - no instances.
*******************************************************************************/
private AssistantTableWrites()
{
}
/*******************************************************************************
** What a person may do to a table through a table route; null for a table
** that is not the assistant's.
*******************************************************************************/
public static Set<Operation> byAPerson(String tableName)
{
return (BY_A_PERSON.get(tableName));
}
/*******************************************************************************
** Whether a person edits this table on a record screen (anything at all).
*******************************************************************************/
public static boolean isEditedByAPerson(String tableName)
{
Set<Operation> operations = byAPerson(tableName);
return (operations != null && !operations.isEmpty());
}
/*******************************************************************************
** Take from a table every capability a person may not use on it. A table
** nobody decided about is not built.
*******************************************************************************/
static QTableMetaData apply(QTableMetaData table) throws QException
{
Set<Operation> byAPerson = byAPerson(table.getName());
if(byAPerson == null)
{
throw (new QException("The table " + table.getName() + " has no decision in AssistantTableWrites: say who writes it, a person on a record screen or the assistant."));
}
for(Operation operation : Operation.values())
{
if(!byAPerson.contains(operation))
{
table.withoutCapability(operation.capability);
}
}
return (table);
}
/*******************************************************************************
** Refuse an insert, update or delete of a table of the assistant that a
** person may not make. Called by the permission checkers of the assistant's
** tables, which a table route asks before it does anything. Anything else
** (a read, another kind of object, a table that is not the assistant's,
** the assistant's own write) is not refused here.
*******************************************************************************/
static void refuseWhatAPersonMayNotWrite(AbstractActionInput input, MetaDataWithPermissionRules metaData) throws QPermissionDeniedException
{
Set<Operation> asked = operations(input);
if(asked.isEmpty() || !(metaData instanceof QTableMetaData table) || AssistantStore.isOwnWrite(input))
{
return;
}
Set<Operation> byAPerson = byAPerson(table.getName());
if(byAPerson == null)
{
return;
}
for(Operation operation : Operation.values())
{
if(asked.contains(operation) && !byAPerson.contains(operation))
{
throw (new QPermissionDeniedException("Rows of " + label(table) + " are written by the assistant; they cannot be " + operation.done + "."));
}
}
}
/*******************************************************************************
** The operations an action input is about to make; none for a read.
*******************************************************************************/
private static Set<Operation> operations(AbstractActionInput input)
{
if(input instanceof InsertInput)
{
return (Set.of(Operation.INSERT));
}
if(input instanceof UpdateInput || input instanceof ConditionalUpdateInput)
{
return (Set.of(Operation.UPDATE));
}
if(input instanceof DeleteInput)
{
return (Set.of(Operation.DELETE));
}
if(input instanceof ReplaceInput)
{
return (EVERYTHING);
}
return (NOTHING);
}
/*******************************************************************************
**
*******************************************************************************/
private static String label(QTableMetaData table)
{
return (table.getLabel() == null ? table.getName() : table.getLabel());
}
}
@@ -0,0 +1,41 @@
/*
* 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 com.kingsrook.qqq.backend.core.actions.permissions.CustomPermissionChecker;
import com.kingsrook.qqq.backend.core.exceptions.QPermissionDeniedException;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.metadata.permissions.MetaDataWithPermissionRules;
/*******************************************************************************
** For a table of the assistant that needs no permission to read (which rows a
** person sees is decided by the owner record lock): anybody reads, and nobody
** writes what the assistant writes. See {@link AssistantTableWrites}.
*******************************************************************************/
public class AssistantWrittenByTheAssistantPermissionChecker implements CustomPermissionChecker
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public void checkPermissionsThrowing(AbstractActionInput actionInput, MetaDataWithPermissionRules metaDataWithPermissionRules) throws QPermissionDeniedException
{
AssistantTableWrites.refuseWhatAPersonMayNotWrite(actionInput, metaDataWithPermissionRules);
}
}
@@ -19,7 +19,10 @@ package com.kingsrook.qbits.assistant.metadata;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.statusmessages.BadInputStatusMessage;
@@ -87,6 +90,62 @@ final class StoredRecords
/*******************************************************************************
** The stored rows of a save that is about to be made, after taking out of
** a person's records what a person does not decide.
**
** A field that is not editable is the server's: an id, a date, who granted
** an override, a test result, a counter. QQQ's record screens do not offer
** such a field, but a request can carry any field, and QQQ stores what a
** request carries. So for a save made by a person (its input source is
** USER, which every table route sets) every value of a field that is not
** editable is taken out of the record before a rule sees it or it is
** stored: the stored value stays. A client that sends a whole record back
** keeps working, and what it sent for such a field changes nothing.
**
** Left in: the primary key of an update (it names the row; the route takes
** it from the path), and the dates QQQ itself has just set on this save
** (the modify date; on an insert the create date too). The assistant's own
** saves are not touched: they set these fields.
*******************************************************************************/
static StoredRecords ofSave(AbstractActionInput input, List<QRecord> records, Optional<List<QRecord>> oldRecordList)
{
StoredRecords stored = of(input, oldRecordList);
if(stored.table != null && input instanceof AbstractTableActionInput tableInput && tableInput.getInputSource() == QInputSource.USER)
{
boolean update = input instanceof UpdateInput;
for(QRecord record : records)
{
for(String fieldName : new ArrayList<>(record.getValues().keySet()))
{
if(stored.isTheServers(fieldName, update))
{
record.removeValue(fieldName);
}
}
}
}
return (stored);
}
/*******************************************************************************
** Whether a person's save may not set this field.
*******************************************************************************/
private boolean isTheServers(String fieldName, boolean update)
{
QFieldMetaData field = table.getFields().get(fieldName);
if(field == null || field.getIsEditable() || (update && fieldName.equals(keyField)))
{
return (false);
}
DynamicDefaultValueBehavior setByQqq = field.getBehaviorOnlyIfSet(DynamicDefaultValueBehavior.class);
return (!(setByQqq == DynamicDefaultValueBehavior.MODIFY_DATE || (!update && setByQqq == DynamicDefaultValueBehavior.CREATE_DATE)));
}
/*******************************************************************************
** The stored row of a record being saved, or null: for an insert, and for
** a key that is no row QQQ read.
@@ -162,6 +162,17 @@ public class AssistantStore
/*******************************************************************************
** Whether an action input is one this store made (it carries the store's
** own reason). A request cannot make one: the reason is set in code, here.
*******************************************************************************/
public static boolean isOwnWrite(AbstractActionInput input)
{
return (input != null && TRUSTED_REASON.equals(input.getPermissionBypassReason()));
}
/*******************************************************************************
** The store only ever touches the QBit's own tables (assistant_*): the
** user's application data is reached only through the UI API.
@@ -0,0 +1,239 @@
/*
* 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.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import com.kingsrook.qbits.assistant.api.AssistantConversationCustomizer;
import com.kingsrook.qbits.assistant.metadata.AssistantTableWrites.Operation;
import com.kingsrook.qbits.assistant.model.AssistantBudget;
import com.kingsrook.qbits.assistant.model.AssistantConversation;
import com.kingsrook.qbits.assistant.model.AssistantToolCall;
import com.kingsrook.qbits.assistant.testing.AssistantTestFixture;
import com.kingsrook.qbits.assistant.testing.BaseAssistantTest;
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizers;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QPermissionDeniedException;
import com.kingsrook.qqq.backend.core.model.actions.tables.QInputSource;
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.replace.ReplaceInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.ConditionalUpdateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/*******************************************************************************
** Every table of the assistant has a decision about who writes it, and the
** table as it is built follows the decision. A table that is added without a
** decision fails here, and cannot be built at all.
*******************************************************************************/
class AssistantTableWritesTest extends BaseAssistantTest
{
private static final Set<Class<?>> CHECKERS = Set.of(AssistantAdminPermissionChecker.class, AssistantAccessPermissionChecker.class, AssistantWrittenByTheAssistantPermissionChecker.class);
/*******************************************************************************
** Every table has a decision; a table without one is not built.
*******************************************************************************/
@Test
void everyTableHasADecisionAndIsBuiltToIt() throws Exception
{
List<QTableMetaData> tables = assistantTables();
assertThat(tables).hasSizeGreaterThanOrEqualTo(27);
for(QTableMetaData table : tables)
{
Set<Operation> byAPerson = AssistantTableWrites.byAPerson(table.getName());
assertThat(byAPerson).as(table.getName() + " has a decision in AssistantTableWrites").isNotNull();
assertThat(table.isCapabilityEnabled(qInstance.getBackend(table.getBackendName()), Capability.TABLE_INSERT)).as(table.getName() + " insert").isEqualTo(byAPerson.contains(Operation.INSERT));
assertThat(table.isCapabilityEnabled(qInstance.getBackend(table.getBackendName()), Capability.TABLE_UPDATE)).as(table.getName() + " update").isEqualTo(byAPerson.contains(Operation.UPDATE));
assertThat(table.isCapabilityEnabled(qInstance.getBackend(table.getBackendName()), Capability.TABLE_DELETE)).as(table.getName() + " delete").isEqualTo(byAPerson.contains(Operation.DELETE));
QCodeReference checker = table.getPermissionRules().getCustomPermissionChecker();
assertThat(checker).as(table.getName() + " has a permission checker that refuses what a person may not write").isNotNull();
assertThat(CHECKERS).as(table.getName()).anySatisfy(type -> assertThat(type.getName()).isEqualTo(checker.getName()));
}
assertThatThrownBy(() -> AssistantTableWrites.apply(new QTableMetaData().withName("assistant_added_tomorrow")))
.isInstanceOf(QException.class).hasMessageContaining("assistant_added_tomorrow has no decision");
assertThat(AssistantTableWrites.byAPerson("page")).as("not a table of the assistant").isNull();
assertThat(AssistantTableWrites.isEditedByAPerson("page")).isFalse();
assertThat(AssistantTableWrites.isEditedByAPerson(AssistantBudget.TABLE_NAME)).isTrue();
assertThat(AssistantTableWrites.isEditedByAPerson(AssistantToolCall.TABLE_NAME)).isFalse();
}
/*******************************************************************************
** The checkers refuse every kind of write a table route can ask for, and
** nothing else: a read, a table that is not the assistant's and the
** assistant's own write are not refused.
*******************************************************************************/
@Test
void theCheckersRefuseEveryKindOfWriteAndNothingElse() throws Exception
{
QContext.init(qInstance, AssistantTestFixture.ownerSession(AssistantTestFixture.ADMIN, config));
QTableMetaData toolCalls = qInstance.getTable(AssistantToolCall.TABLE_NAME);
QTableMetaData conversations = qInstance.getTable(AssistantConversation.TABLE_NAME);
QTableMetaData budgets = qInstance.getTable(AssistantBudget.TABLE_NAME);
for(var input : List.of(new InsertInput(toolCalls.getName()), new UpdateInput(toolCalls.getName()), new DeleteInput(toolCalls.getName()),
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");
assertThatThrownBy(() -> new AssistantWrittenByTheAssistantPermissionChecker().checkPermissionsThrowing(input, toolCalls)).isInstanceOf(QPermissionDeniedException.class);
}
new AssistantAdminPermissionChecker().checkPermissionsThrowing(new QueryInput(toolCalls.getName()), toolCalls);
new AssistantAdminPermissionChecker().checkPermissionsThrowing(null, toolCalls);
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.");
assertThatThrownBy(() -> new AssistantAccessPermissionChecker().checkPermissionsThrowing(new ReplaceInput(), conversations))
.hasMessageContaining("cannot be added");
for(var input : List.of(new InsertInput(budgets.getName()), new UpdateInput(budgets.getName()), new DeleteInput(budgets.getName()), new ReplaceInput()))
{
new AssistantAdminPermissionChecker().checkPermissionsThrowing(input, budgets);
}
QTableMetaData pages = qInstance.getTable("page");
new AssistantWrittenByTheAssistantPermissionChecker().checkPermissionsThrowing(new DeleteInput("page"), pages);
new AssistantWrittenByTheAssistantPermissionChecker().checkPermissionsThrowing(new DeleteInput(toolCalls.getName()), qInstance.getProcesses().values().iterator().next());
}
/*******************************************************************************
** Every table a person edits has a customizer before an insert and before
** an update that takes the fields the server decides out of a person's
** save: sent with a value for every field that is not editable, the record
** it is handed keeps none of them but its key. The assistant's own save
** keeps them.
*******************************************************************************/
@Test
void aPersonsSaveOfASettingsTableKeepsNoFieldTheServerDecides() throws Exception
{
QContext.init(qInstance, AssistantTestFixture.ownerSession(AssistantTestFixture.ADMIN, config));
Integer tablesChecked = 0;
for(QTableMetaData table : assistantTables())
{
Set<Operation> byAPerson = AssistantTableWrites.byAPerson(table.getName());
if(!byAPerson.contains(Operation.UPDATE))
{
continue;
}
tablesChecked++;
Optional<TableCustomizerInterface> beforeUpdate = QCodeLoader.getTableCustomizer(table, TableCustomizers.PRE_UPDATE_RECORD.getRole());
assertThat(beforeUpdate).as(table.getName() + " has a customizer before an update").isPresent();
if(byAPerson.contains(Operation.INSERT))
{
assertThat(QCodeLoader.getTableCustomizer(table, TableCustomizers.PRE_INSERT_RECORD.getRole())).as(table.getName() + " has a customizer before an insert").isPresent();
}
Set<String> theServers = new TreeSet<>();
for(QFieldMetaData field : table.getFields().values())
{
if(!field.getIsEditable() && !field.getName().equals(table.getPrimaryKeyField())
&& field.getBehaviorOnlyIfSet(DynamicDefaultValueBehavior.class) != DynamicDefaultValueBehavior.MODIFY_DATE)
{
theServers.add(field.getName());
}
}
assertThat(theServers).as(table.getName() + " has fields the server decides").contains("createDate");
if(table.getName().equals(AssistantConversation.TABLE_NAME))
{
///////////////////////////////////////////////////////////////////////////////
// its own customizer says what its owner changes on a screen, by name //
///////////////////////////////////////////////////////////////////////////////
theServers.removeAll(AssistantConversationCustomizer.USER_EDITABLE_FIELDS);
}
for(QInputSource source : QInputSource.values())
{
QRecord stored = new QRecord().withValue("id", 41);
QRecord saved = new QRecord().withValue("id", "41");
for(QFieldMetaData field : table.getFields().values())
{
if(!field.getName().equals("id"))
{
stored.setValue(field.getName(), TableRows.value(field, 1));
}
}
for(String fieldName : theServers)
{
saved.setValue(fieldName, (Serializable) TableRows.value(table.getField(fieldName), 2));
}
UpdateInput input = new UpdateInput(table.getName()).withInputSource(source);
input.setRecords(new ArrayList<>(List.of(saved)));
try
{
beforeUpdate.get().preUpdate(input, input.getRecords(), false, Optional.of(List.of(stored)));
}
catch(QException e)
{
///////////////////////////////////////////////////////////////////////////////////
// a rule of the table may refuse the made-up row; what was taken out stays out //
///////////////////////////////////////////////////////////////////////////////////
assertThat(e).hasMessageNotContaining("NullPointer");
}
if(source == QInputSource.USER)
{
assertThat(saved.getValues().keySet()).as(table.getName() + ": a person's save keeps no field the server decides").doesNotContainAnyElementsOf(theServers).contains("id");
}
else if(!table.getName().equals(AssistantConversation.TABLE_NAME))
{
assertThat(saved.getValues().keySet()).as(table.getName() + ": the assistant's own save sets them").contains("createDate");
}
}
}
assertThat(tablesChecked).as("the settings tables and the conversation table").isGreaterThanOrEqualTo(13);
}
/*******************************************************************************
**
*******************************************************************************/
private List<QTableMetaData> assistantTables()
{
return (qInstance.getTables().values().stream().filter(table -> table.getName().startsWith("assistant_")).toList());
}
}
@@ -275,8 +275,9 @@ class BudgetEditOverHttpTest extends BaseAssistantTest
/*******************************************************************************
** What the server decides stays the server's: a save cannot name another
** record in its body, set the version it is saved as, or say who granted
** an override.
** record in its body, set the date a budget was created or the version it
** is saved as, or say who granted an override. A field that is not editable
** is taken out of a person's save, whatever QQQ does with it.
*******************************************************************************/
@Test
void aSaveSetsNothingTheServerDecides() throws Exception
@@ -288,6 +289,7 @@ class BudgetEditOverHttpTest extends BaseAssistantTest
Map<String, String> changed = new LinkedHashMap<>();
changed.put("id", String.valueOf(other.getId()));
changed.put("createDate", "2001-01-01T00:00:00Z");
changed.put("modifyDate", "2001-01-01T00:00:00Z");
changed.put("notes", "Mine.");
UiApiResult saved = screen.change(BUDGET, budget.getId(), changed);
@@ -295,7 +297,7 @@ class BudgetEditOverHttpTest extends BaseAssistantTest
Map<String, Object> after = screen.read(BUDGET, budget.getId());
assertThat(after.get("notes")).isEqualTo("Mine.");
assertThat(after.get("createDate")).isEqualTo(before.get("createDate"));
assertThat(after.get("createDate")).as("the create date is the server's").isEqualTo(before.get("createDate"));
assertThat(Instant.parse(String.valueOf(after.get("modifyDate")))).as("the modify date is the server's").isAfterOrEqualTo(Instant.parse(String.valueOf(before.get("modifyDate"))));
assertThat(store().budget(other.getId()).getNotes()).as("the record of the path is the one saved").isNull();
@@ -306,6 +308,13 @@ class BudgetEditOverHttpTest extends BaseAssistantTest
AssistantBudgetOverride override = store().query(OVERRIDE, new QQueryFilter(), AssistantBudgetOverride.class).get(0);
assertThat(override.getGrantedBy()).as("who granted it is the session's").isEqualTo(ADMIN);
UiApiResult created = screen.create(BUDGET, Map.of("id", "987654", "createDate", "2001-01-01T00:00:00Z", "name", "New", "scopeType", "USER", "scopeValue", "someone",
"period", "DAY", "metric", "COST_USD", "limitValue", "5"));
assertThat(created.status()).as(created.body()).isEqualTo(200);
AssistantBudget fresh = store().query(BUDGET, new QQueryFilter().withCriteria("name", QCriteriaOperator.EQUALS, "New"), AssistantBudget.class).get(0);
assertThat(fresh.getId()).as("a new budget gets its id from the server").isNotEqualTo(987654);
assertThat(fresh.getCreateDate()).isAfter(Instant.parse("2020-01-01T00:00:00Z"));
UiApiResult edited = screen.change(OVERRIDE, override.getId(), Map.of("reason", "Quarter end, extended", "grantedBy", "somebody-else"));
assertThat(edited.status()).as(edited.body()).isEqualTo(200);
AssistantBudgetOverride stored = store().query(OVERRIDE, new QQueryFilter(), AssistantBudgetOverride.class).get(0);
@@ -20,6 +20,7 @@ package com.kingsrook.qbits.assistant.metadata;
import java.util.Map;
import com.kingsrook.qbits.assistant.access.DataAccessMode;
import com.kingsrook.qbits.assistant.model.AssistantDataAccess;
import com.kingsrook.qbits.assistant.model.AssistantPolicy;
import com.kingsrook.qbits.assistant.model.AssistantProfile;
import com.kingsrook.qbits.assistant.model.AssistantSkill;
import com.kingsrook.qbits.assistant.persistence.AssistantStore;
@@ -163,6 +164,66 @@ class RecordEditsOverHttpTest extends BaseAssistantTest
/*******************************************************************************
** The date a row was created is the server's on every settings table: a
** save that carries one, with nothing else or with a real change, leaves it
** as it is. A policy has no rules of its own, and is held to this like the
** others.
*******************************************************************************/
@Test
void aSaveSetsNoFieldTheServerDecides() throws Exception
{
AssistantPolicy policy = store().insert(new AssistantPolicy().withName("default").withKillSwitch(false));
AssistantProfile profile = store().insert(new AssistantProfile().withName("analyst").withDisplayName("Analyst").withEnabled(true).withIsDefault(false));
AssistantSkill skill = store().insert(new AssistantSkill().withName("summaries").withInstructions("Summarize in three lines.").withEnabled(true));
AssistantDataAccess access = store().insert(new AssistantDataAccess().withObjectType(AssistantDataAccess.TYPE_TABLE).withObjectName("page").withMode(DataAccessMode.READ.name()));
Map<String, Object> rows = new java.util.LinkedHashMap<>();
rows.put(AssistantPolicy.TABLE_NAME, policy.getId());
rows.put(AssistantProfile.TABLE_NAME, profile.getId());
rows.put(AssistantSkill.TABLE_NAME, skill.getId());
rows.put(AssistantDataAccess.TABLE_NAME, access.getId());
for(Map.Entry<String, Object> row : rows.entrySet())
{
Map<String, Object> before = screen.read(row.getKey(), row.getValue());
UiApiResult alone = screen.saveJson(row.getKey(), row.getValue(), "{\"createDate\":\"2001-01-01T00:00:00Z\",\"id\":987654}");
assertThat(alone.status()).as(row.getKey() + ": " + alone.body()).isEqualTo(200);
assertThat(screen.read(row.getKey(), row.getValue()).get("createDate")).as(row.getKey() + ": the create date is the server's").isEqualTo(before.get("createDate"));
UiApiResult withAChange = screen.change(row.getKey(), row.getValue(), Map.of("createDate", "2001-01-01T00:00:00Z", textField(row.getKey()), "changed"));
assertThat(withAChange.status()).as(row.getKey() + ": " + withAChange.body()).isEqualTo(200);
Map<String, Object> after = screen.read(row.getKey(), row.getValue());
assertThat(after.get(textField(row.getKey()))).as(row.getKey() + ": the change is stored").isEqualTo("changed");
assertThat(after.get("createDate")).as(row.getKey()).isEqualTo(before.get("createDate"));
assertThat(after.get("id")).isEqualTo(before.get("id"));
}
UiApiResult created = screen.createJson(AssistantPolicy.TABLE_NAME, "{\"name\":\"second\",\"id\":987654,\"createDate\":\"2001-01-01T00:00:00Z\"}");
assertThat(created.status()).as(created.body()).isEqualTo(200);
AssistantPolicy second = store().query(AssistantPolicy.TABLE_NAME, new QQueryFilter().withCriteria("name", QCriteriaOperator.EQUALS, "second"), AssistantPolicy.class).get(0);
assertThat(second.getId()).as("a new row gets its id from the server").isNotEqualTo(987654);
assertThat(second.getCreateDate()).isAfter(java.time.Instant.parse("2020-01-01T00:00:00Z"));
}
/*******************************************************************************
** A text field of a settings table that a person edits freely.
*******************************************************************************/
private static String textField(String tableName)
{
return (switch(tableName)
{
case AssistantDataAccess.TABLE_NAME -> "notes";
case AssistantProfile.TABLE_NAME -> "greeting";
case AssistantSkill.TABLE_NAME -> "description";
default -> "killSwitchReason";
});
}
/*******************************************************************************
**
*******************************************************************************/
@@ -114,6 +114,48 @@ public final class RecordScreen
/*******************************************************************************
** Save with a JSON body, as a client other than the record screen may
** ("{}" is an update that changes nothing).
*******************************************************************************/
public UiApiResult saveJson(String tableName, Object id, String json) throws Exception
{
return (send("PATCH", "/table/" + tableName + "/" + id, "application/json", json));
}
/*******************************************************************************
** Create a record from a JSON body.
*******************************************************************************/
public UiApiResult createJson(String tableName, String json) throws Exception
{
return (send("POST", "/table/" + tableName, "application/json", json));
}
/*******************************************************************************
** Delete a record.
*******************************************************************************/
public UiApiResult delete(String tableName, Object id) throws Exception
{
return (send("DELETE", "/table/" + tableName + "/" + id, null, null));
}
/*******************************************************************************
** What the application tells a screen about a table: the capabilities are
** what the screen offers buttons for.
*******************************************************************************/
public UiApiResult tableMetaData(String tableName) throws Exception
{
return (send("GET", "/metaData/table/" + tableName, null, null));
}
/*******************************************************************************
**
*******************************************************************************/
@@ -0,0 +1,118 @@
/*
* 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.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
/*******************************************************************************
** Rows of the fixture's memory backend, put there and read back without any
** action of QQQ: no permission, no customizer, no validation. A test of what
** a table route refuses needs a row that is there whatever the routes allow,
** and needs to see afterwards exactly what is stored.
*******************************************************************************/
public final class TableRows
{
public static final Instant LONG_AGO = Instant.parse("2020-02-02T02:02:02Z");
/*******************************************************************************
** Utility class - no instances.
*******************************************************************************/
private TableRows()
{
}
/*******************************************************************************
** Store one row with a value in every field (the owner in userId, dates
** long ago), and return it as stored (with its id).
*******************************************************************************/
public static QRecord seed(QTableMetaData table, String ownerUserId) throws QException
{
QRecord record = new QRecord();
for(QFieldMetaData field : table.getFields().values())
{
if(!field.getName().equals(table.getPrimaryKeyField()))
{
record.setValue(field.getName(), field.getName().equals("userId") ? ownerUserId : value(field, 1));
}
}
InsertInput input = new InsertInput(table.getName()).withRecords(new ArrayList<>(List.of(record)));
input.setTableMetaData(table);
return (MemoryRecordStore.getInstance().insert(input, true).get(0));
}
/*******************************************************************************
** A value of the type of a field; a different one for each variant.
*******************************************************************************/
public static Serializable value(QFieldMetaData field, int variant)
{
return (switch(field.getType())
{
case STRING, TEXT, HTML, PASSWORD -> "value " + variant;
case INTEGER -> 40 + variant;
case LONG -> 4000L + variant;
case DECIMAL -> new BigDecimal(variant + ".5");
case BOOLEAN -> variant % 2 == 1;
case DATE -> LocalDate.of(2020, 2, variant);
case TIME -> LocalTime.of(variant, 0);
case DATE_TIME -> LONG_AGO.plusSeconds(variant);
case BLOB -> ("blob " + variant).getBytes(java.nio.charset.StandardCharsets.UTF_8);
});
}
/*******************************************************************************
** Every row of a table, as stored.
*******************************************************************************/
public static List<QRecord> all(QTableMetaData table) throws QException
{
QueryInput input = new QueryInput(table.getName());
input.setTableMetaData(table);
return (MemoryRecordStore.getInstance().query(input));
}
/*******************************************************************************
** The values of every row of a table, as text: to see that nothing moved.
*******************************************************************************/
public static List<String> snapshot(QTableMetaData table) throws QException
{
return (all(table).stream().map(row -> new java.util.TreeMap<>(row.getValues()).toString()).sorted().toList());
}
}
@@ -0,0 +1,310 @@
/*
* 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.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.kingsrook.qbits.assistant.api.AssistantApi;
import com.kingsrook.qbits.assistant.metadata.AssistantTableWrites.Operation;
import com.kingsrook.qbits.assistant.model.AssistantBudgetUsage;
import com.kingsrook.qbits.assistant.model.AssistantClientError;
import com.kingsrook.qbits.assistant.model.AssistantConversation;
import com.kingsrook.qbits.assistant.model.AssistantFeedback;
import com.kingsrook.qbits.assistant.model.AssistantMessage;
import com.kingsrook.qbits.assistant.model.AssistantPendingAction;
import com.kingsrook.qbits.assistant.model.AssistantPendingActionClaim;
import com.kingsrook.qbits.assistant.model.AssistantScheduledRun;
import com.kingsrook.qbits.assistant.model.AssistantToolCall;
import com.kingsrook.qbits.assistant.model.AssistantTurn;
import com.kingsrook.qbits.assistant.model.AssistantTurnEvent;
import com.kingsrook.qbits.assistant.model.AssistantUsage;
import com.kingsrook.qbits.assistant.persistence.AssistantStore;
import com.kingsrook.qbits.assistant.testing.AssistantTestFixture;
import com.kingsrook.qbits.assistant.testing.BaseAssistantTest;
import com.kingsrook.qbits.assistant.testing.TurnRunner;
import com.kingsrook.qbits.assistant.testing.UiApiTestServer;
import com.kingsrook.qbits.assistant.uiapi.UiApiResult;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
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.tables.QTableMetaData;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/*******************************************************************************
** The tables the assistant writes as it works (what was said and done, and
** what it cost) are written by nobody else. Through the real table routes, a
** person - the administrator of the assistant and an ordinary user alike -
** cannot add a row, change one (not even with an update that changes
** nothing), or delete one; nothing is stored and nothing moves. The
** assistant's own work still writes them.
*******************************************************************************/
class TablesWrittenByTheAssistantTest extends BaseAssistantTest
{
private static final String ADMIN = AssistantTestFixture.ADMIN;
private static final String EDITOR = AssistantTestFixture.EDITOR;
private static final String AUTHOR = AssistantTestFixture.AUTHOR;
private String base;
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
void serve()
{
base = UiApiTestServer.serve(qInstance, config);
QContext.init(qInstance, AssistantTestFixture.ownerSession(ADMIN, config));
}
/*******************************************************************************
** Every table the assistant writes, with a row of the administrator's own
** and a row of the ordinary user's own in it: each of them is refused an
** insert, an update, an update that changes nothing and a delete, for
** either row, and afterwards every row is exactly what it was.
*******************************************************************************/
@Test
void aPersonWritesNoRowOfATableTheAssistantWrites() throws Exception
{
List<String> tables = systemWritten();
assertThat(tables).as("the accounting the spending limits are counted from is among them")
.contains(AssistantUsage.TABLE_NAME, AssistantBudgetUsage.TABLE_NAME, AssistantToolCall.TABLE_NAME, AssistantScheduledRun.TABLE_NAME);
for(String tableName : tables)
{
QTableMetaData table = qInstance.getTable(tableName);
QRecord ofTheAdmin = TableRows.seed(table, ADMIN);
QRecord ofTheEditor = TableRows.seed(table, EDITOR);
List<String> before = TableRows.snapshot(table);
for(String person : List.of(ADMIN, EDITOR))
{
RecordScreen screen = new RecordScreen(base, person);
for(QRecord row : List.of(ofTheAdmin, ofTheEditor))
{
Object id = row.getValue("id");
String what = tableName + ", as " + person + ", row " + id;
Map<String, String> changed = changedValues(table);
refused(screen.save(tableName, id, changed, null), what + ": update", person, table, "changed");
refused(screen.saveJson(tableName, id, "{}"), what + ": update that changes nothing", person, table, "changed");
refused(screen.saveJson(tableName, id, "{\"modifyDate\":\"2031-01-01T00:00:00Z\"}"), what + ": update of the modify date", person, table, "changed");
refused(screen.delete(tableName, id), what + ": delete", person, table, "deleted");
}
refused(screen.create(tableName, changedValues(table)), tableName + ", as " + person + ": insert", person, table, "added");
refused(screen.createJson(tableName, "{}"), tableName + ", as " + person + ": empty insert", person, table, "added");
}
assertThat(TableRows.snapshot(table)).as(tableName + ": every row is what it was, and there is no new one").isEqualTo(before);
}
}
/*******************************************************************************
** What the application tells a screen: a table the assistant writes has no
** capability to insert, update or delete, so a screen offers no button for
** it, and QQQ defines no bulk action for it.
*******************************************************************************/
@Test
void aScreenIsOfferedNoWriteOfATableTheAssistantWrites() throws Exception
{
RecordScreen screen = new RecordScreen(base, ADMIN);
for(String tableName : systemWritten())
{
UiApiResult metaData = screen.tableMetaData(tableName);
assertThat(metaData.status()).as(tableName + ": " + metaData.body()).isEqualTo(200);
assertThat(metaData.body()).as(tableName).contains("TABLE_QUERY").doesNotContain("TABLE_INSERT").doesNotContain("TABLE_UPDATE").doesNotContain("TABLE_DELETE");
for(String bulk : List.of(".bulkInsert", ".bulkEdit", ".bulkEditWithFile", ".bulkDelete"))
{
assertThat(qInstance.getProcess(tableName + bulk)).as(tableName + bulk).isNull();
}
}
UiApiResult settings = screen.tableMetaData("assistant_budget");
assertThat(settings.body()).as("a settings table keeps its buttons").contains("TABLE_INSERT").contains("TABLE_UPDATE").contains("TABLE_DELETE");
}
/*******************************************************************************
** A conversation is started by the assistant, never added on a screen. Its
** owner still renames it and deletes it through the table routes, and what
** belongs to a deleted conversation goes with it.
*******************************************************************************/
@Test
void aConversationIsRenamedAndDeletedByItsOwnerButNotAdded() throws Exception
{
provider.thenText("Four posts are published.");
TurnRunner.Outcome outcome = runner.run(EDITOR, "How many posts are published?");
QContext.init(qInstance, AssistantTestFixture.ownerSession(ADMIN, config));
/////////////////////////////////////////////////////////////////////////////////////
// the owner key of a person, as a host sign-in sets it on the session of a screen //
/////////////////////////////////////////////////////////////////////////////////////
AssistantTestFixture.giveKey(EDITOR, config.getOwnerSecurityKeyType(), EDITOR);
RecordScreen screen = new RecordScreen(base, EDITOR);
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(store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class)).hasSize(1);
AssistantConversation asked = store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class).get(0);
UiApiResult renamed = screen.saveJson(AssistantConversation.TABLE_NAME, outcome.conversationId(), "{\"title\":\"Published posts\",\"totalCostMicros\":0,\"unreadCount\":99}");
assertThat(renamed.status()).as(renamed.body()).isEqualTo(200);
AssistantConversation conversation = store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class).get(0);
assertThat(conversation.getTitle()).isEqualTo("Published posts");
assertThat(conversation.getTotalCostMicros()).as("what it cost is not something a save sets").isEqualTo(asked.getTotalCostMicros());
assertThat(conversation.getUnreadCount()).isEqualTo(asked.getUnreadCount());
UiApiResult givenAway = screen.saveJson(AssistantConversation.TABLE_NAME, outcome.conversationId(), "{\"title\":\"Somebody's\",\"userId\":\"somebody-else\"}");
assertThat(givenAway.status()).as("nor its owner: " + givenAway.body()).isGreaterThanOrEqualTo(400);
assertThat(store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class).get(0).getUserId()).isEqualTo(EDITOR);
assertThat(store().query(AssistantMessage.TABLE_NAME, new QQueryFilter(), AssistantMessage.class)).isNotEmpty();
UiApiResult deleted = screen.delete(AssistantConversation.TABLE_NAME, outcome.conversationId());
assertThat(deleted.status()).as(deleted.body()).isEqualTo(200);
assertThat(store().query(AssistantConversation.TABLE_NAME, new QQueryFilter(), AssistantConversation.class)).isEmpty();
assertThat(store().query(AssistantMessage.TABLE_NAME, new QQueryFilter(), AssistantMessage.class)).as("its messages went with it").isEmpty();
assertThat(store().query(AssistantTurn.TABLE_NAME, new QQueryFilter(), AssistantTurn.class)).isEmpty();
}
/*******************************************************************************
** The assistant's own work still writes its tables: an answer with a tool
** call and a change that is proposed and confirmed, a rating and a client
** error sent to the assistant's own API. (Scheduled runs and budget events
** are written in ScheduledTasksTest and BudgetServiceTest.)
*******************************************************************************/
@Test
void theAssistantsOwnWorkStillWritesItsTables() throws Exception
{
provider.thenToolUse("update_record", input("table", "page", "id", "12", "values", Map.of("title", "About us"))).thenText("Please confirm.");
TurnRunner.Outcome outcome = runner.run(AUTHOR, "Rename page 12 to About us");
Integer pending = outcome.toolCalls().get(0).getPendingActionId();
assertThat(pending).as("the change was proposed").isNotNull();
AssistantApi api = new AssistantApi(config.getRuntime(), AssistantTestFixture.ownerSession(AUTHOR, config));
Map<String, Object> confirmed = api.confirmAction(pending);
assertThat(confirmed.get("status")).isEqualTo(AssistantPendingAction.STATUS_EXECUTED);
QContext.init(qInstance, AssistantTestFixture.ownerSession(ADMIN, config));
AssistantMessage answer = store().query(AssistantMessage.TABLE_NAME, new QQueryFilter().withCriteria("role", QCriteriaOperator.EQUALS, "ASSISTANT"), AssistantMessage.class).get(0);
QContext.init(qInstance, AssistantTestFixture.ownerSession(AUTHOR, config));
api.feedback(answer.getId(), Map.of("rating", 1));
assertThat(api.reportClientError(Map.of("scope", "panel", "message", "It did not draw."))).containsEntry("accepted", true);
QContext.init(qInstance, AssistantTestFixture.ownerSession(ADMIN, config));
Map<String, Integer> rows = new LinkedHashMap<>();
for(String tableName : List.of(AssistantConversation.TABLE_NAME, AssistantMessage.TABLE_NAME, AssistantTurn.TABLE_NAME, AssistantTurnEvent.TABLE_NAME,
AssistantToolCall.TABLE_NAME, AssistantPendingAction.TABLE_NAME, AssistantPendingActionClaim.TABLE_NAME, AssistantUsage.TABLE_NAME, AssistantBudgetUsage.TABLE_NAME,
AssistantFeedback.TABLE_NAME, AssistantClientError.TABLE_NAME))
{
rows.put(tableName, TableRows.all(qInstance.getTable(tableName)).size());
}
assertThat(rows).allSatisfy((tableName, count) -> assertThat(count).as("rows written to " + tableName).isPositive());
assertThat(rows.get(AssistantBudgetUsage.TABLE_NAME)).as("one accounting row for every model call").isEqualTo(rows.get(AssistantUsage.TABLE_NAME));
}
/*******************************************************************************
** The tables a person writes nothing of.
*******************************************************************************/
private List<String> systemWritten()
{
List<String> tables = new ArrayList<>();
for(QTableMetaData table : qInstance.getTables().values())
{
Set<Operation> byAPerson = AssistantTableWrites.byAPerson(table.getName());
if(byAPerson != null && byAPerson.isEmpty())
{
tables.add(table.getName());
}
}
assertThat(tables).hasSizeGreaterThanOrEqualTo(14);
return (tables);
}
/*******************************************************************************
** A value for every text field of a table (other than its key and owner):
** what a request that tried to change a row would carry.
*******************************************************************************/
private static Map<String, String> changedValues(QTableMetaData table)
{
Map<String, String> values = new LinkedHashMap<>();
for(QFieldMetaData field : table.getFields().values())
{
if(!field.getName().equals("id") && !field.getName().equals("userId") && (field.getType() == QFieldType.STRING || field.getType() == QFieldType.TEXT))
{
values.put(field.getName(), "changed");
}
else if(field.getType() == QFieldType.INTEGER && !field.getName().equals("id"))
{
values.put(field.getName(), "0");
}
else if(field.getType() == QFieldType.LONG)
{
values.put(field.getName(), "0");
}
}
assertThat(values).as("something to change in " + table.getName()).isNotEmpty();
return (values);
}
/*******************************************************************************
** A request was refused with 403. The administrator, who may do everything
** a person may do to the assistant, is told why.
*******************************************************************************/
private static void refused(UiApiResult result, String what, String person, QTableMetaData table, String done)
{
assertThat(result.status()).as(what + ": " + result.body()).isEqualTo(403);
if(person.equals(ADMIN))
{
assertThat(result.body()).as(what).contains("Rows of " + table.getLabel() + " are written by the assistant; they cannot be " + done + ".");
}
}
/*******************************************************************************
**
*******************************************************************************/
private AssistantStore store()
{
return (config.getRuntime().getStore());
}
}
@@ -254,6 +254,12 @@ class RagTest extends BaseAssistantTest
assertThat(after).as("only the name changed").isEqualTo(expected);
assertThat(vectors.count(source.getId())).as("a new name leaves the vectors").isEqualTo(indexed);
UiApiResult status = screen.saveJson(AssistantRagSource.TABLE_NAME, source.getId(), "{\"indexedChunkCount\":0,\"lastIndexStatus\":\"FAILED\",\"createDate\":\"2001-01-01T00:00:00Z\"}");
assertThat(status.status()).as(status.body()).isEqualTo(200);
Map<String, Object> afterStatus = screen.read(AssistantRagSource.TABLE_NAME, source.getId());
after.put("modifyDate", afterStatus.get("modifyDate"));
assertThat(afterStatus).as("what was indexed and when it was created are the server's").isEqualTo(after);
UiApiResult same = screen.change(AssistantRagSource.TABLE_NAME, source.getId(), Map.of("chunkChars", "1500"));
assertThat(same.status()).as(same.body()).isEqualTo(200);
assertThat(vectors.count(source.getId())).as("the chunk size it already has, sent as text, is no change").isEqualTo(indexed);
@@ -651,8 +651,13 @@ class ScheduledTasksTest extends BaseAssistantTest
assertThat(prompt.status()).as(prompt.body()).isEqualTo(200);
assertThat(runtime.getStore().scheduledTask(task.getId()).getWriteModeApprovedAt()).as("a changed prompt was not approved").isNull();
UiApiResult approval = screen.change(AssistantScheduledTask.TABLE_NAME, task.getId(), Map.of("writeModeApprovedBy", "somebody", "writeModeApprovedAt", NOW.toString(), "name", "Mine"));
assertThat(runtime.getStore().scheduledTask(task.getId()).getWriteModeApprovedBy()).as("an approval is not something a save sets: " + approval.body()).isNull();
Instant created = runtime.getStore().scheduledTask(task.getId()).getCreateDate();
UiApiResult approval = screen.change(AssistantScheduledTask.TABLE_NAME, task.getId(), Map.of("writeModeApprovedBy", "somebody", "writeModeApprovedAt", NOW.toString(), "name", "Mine",
"lastRunStatus", "OK", "createDate", "2001-01-01T00:00:00Z"));
AssistantScheduledTask afterwards = runtime.getStore().scheduledTask(task.getId());
assertThat(afterwards.getWriteModeApprovedBy()).as("an approval is not something a save sets: " + approval.body()).isNull();
assertThat(afterwards.getLastRunStatus()).as("nor how its last run ended").isNull();
assertThat(afterwards.getCreateDate()).as("nor when it was created").isEqualTo(created);
}
@@ -680,6 +680,12 @@ class AssistantSettingsTest extends BaseAssistantTest
expected.put("modifyDate", after.get("modifyDate"));
assertThat(after).as("only the name changed").isEqualTo(expected);
UiApiResult status = screen.saveJson(AssistantProvider.TABLE_NAME, id, "{\"healthState\":\"DOWN\",\"lastTestStatus\":\"FAILED\",\"downUntil\":\"2099-01-01T00:00:00Z\",\"createDate\":\"2001-01-01T00:00:00Z\"}");
assertThat(status.status()).as(status.body()).isEqualTo(200);
Map<String, Object> afterStatus = screen.read(AssistantProvider.TABLE_NAME, id);
after.put("modifyDate", afterStatus.get("modifyDate"));
assertThat(afterStatus).as("its health, its test result and its dates are the server's").isEqualTo(after);
UiApiResult unknownType = screen.change(AssistantProvider.TABLE_NAME, id, Map.of("providerType", "nope"));
assertThat(unknownType.status()).isEqualTo(400);
assertThat(unknownType.body()).contains("not installed");