mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
The four SQL bodies behind the Agents integration were Jinja templates read
through lookup('template'), which meant the raw query: parameter and a
"# nocheck: database-query-raw" on all five call sites in
tasks/utils/ai_gateway.yml.
They now use the mechanism the database_query module already offers: static
.sql files under files/sql/, reached by query_file:, with the values supplied
as named_args and %(name)s placeholders. All five suppressions are gone.
Same move as 4e9d4b53db made for odoo, for the reason that commit gives: an
interpolation straight into SQL carries an injection surface that a bound
parameter does not. Postgres dollar-quoting was doing that job here; the
module's own escaping does it now, doubling single quotes per the _ENGINES
postgres entry.
The | to_json filters did not disappear, they moved to the call site.
MATTERMOST_LITELLM_SERVICE and MATTERMOST_LITELLM_BOT are dicts, and the
module raises TypeError on those, so pre-serialising is what it asks for.
set_ai/ became update/ai/ to match the select/ and update/ verbs the role's
existing files/sql already uses.
The api key inside MATTERMOST_LITELLM_SERVICE is now a named_args value, which
the module adds to no_log_values; as part of the query string it was not.
Verified statically only: the database-query-raw lint passes, the task file
still parses to the same 11 tasks in the same order, every placeholder has a
matching named_args entry, and no reference to the old paths survives. Nothing
ran against a database, and the adversarial review of this change had not
finished when it was committed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
SQL
38 lines
1.6 KiB
SQL
UPDATE agents_confighistory a
|
|
SET config = (
|
|
a.config::jsonb
|
|
|| jsonb_build_object(
|
|
'services',
|
|
coalesce((
|
|
SELECT jsonb_agg(s)
|
|
FROM jsonb_array_elements(
|
|
CASE WHEN jsonb_typeof(a.config::jsonb -> 'services') = 'array'
|
|
THEN a.config::jsonb -> 'services'
|
|
ELSE '[]'::jsonb END
|
|
) AS s
|
|
WHERE s ->> 'id' <> d.service ->> 'id'
|
|
), '[]'::jsonb) || jsonb_build_array(d.service)
|
|
)
|
|
|| jsonb_build_object(
|
|
'bots',
|
|
coalesce((
|
|
SELECT jsonb_agg(b)
|
|
FROM jsonb_array_elements(
|
|
CASE WHEN jsonb_typeof(a.config::jsonb -> 'bots') = 'array'
|
|
THEN a.config::jsonb -> 'bots'
|
|
ELSE '[]'::jsonb END
|
|
) AS b
|
|
WHERE b ->> 'id' <> d.bot ->> 'id'
|
|
), '[]'::jsonb) || CASE WHEN EXISTS (SELECT 1
|
|
FROM agents_useragents u
|
|
WHERE u.username = d.bot ->> 'name'
|
|
AND u.deleteat = 0)
|
|
THEN '[]'::jsonb
|
|
ELSE jsonb_build_array(d.bot) END
|
|
)
|
|
|| jsonb_build_object('defaultBotName', d.bot ->> 'name')
|
|
)::text
|
|
FROM (SELECT %(service)s::jsonb AS service,
|
|
%(bot)s::jsonb AS bot) AS d
|
|
WHERE a.active = true;
|