Skip to content

Ai tools scope public apis - #1150

Merged
realcodesiman merged 5 commits into
mainfrom
feat/ai-tools-scope-public-apis
Sep 12, 2026
Merged

Ai tools scope public apis#1150
realcodesiman merged 5 commits into
mainfrom
feat/ai-tools-scope-public-apis

Conversation

@realcodesiman

Copy link
Copy Markdown
Contributor

No description provided.

realcodesiman and others added 5 commits September 12, 2026 07:56
…ctions, ai-mcp-servers

Removes the ai-triggers feature end to end (schema, repository, relations,
service, UI, actions) since it has been superseded, and drops its
AITrigger/AITriggerToIntegrationOpenai tables via a new migration.

Adds workspace-token endpoints under existing scopes for AI files (create,
list, delete — including SSRF-checked URL ingestion), AI functions
(CRUD + duplicate), and AI MCP servers (CRUD), following the established
pattern: each handler delegates to the same packages/business service method
the private UI action already calls. Also adds Facebook/Instagram comment
moderation service methods (edit, delete, change-attributes) consumed by the
existing messages public API, and extracts ai-file/ai-function/ai-mcp-server
data access out of the app layer into new business services.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… scoping

Phase 1: fixes two of PR #1150's own failing tests — the SSRF test asserted
uploadFileFromUrl's callback was called directly instead of invoking the
captured validate callback, and ai-function's create test needed a name-free
mock now that create pre-checks isNameTaken. Adds coverage for the
isNameTaken skip-on-tx path.

Phase 2: fixes three defects in the URL-ingestion upload path — recorded size
now comes from the real streamed byte count (buffer.byteLength) instead of
the origin's self-reported content-length, which can under-report and send a
mismatched ContentLength to S3; infrastructure failures (storage outage,
network error) now surface as a generic 502 with server-side logging instead
of a 400 that echoed internal error text (e.g. connect ECONNREFUSED ...) and
the raw SSRF-guard message (which echoed the submitted URL) verbatim to any
automation-token holder; and the public create schema now rejects a payload
carrying both `file` and `url` instead of silently dropping one via z.union's
first-match resolution.

Phase 3: closes test gaps around properties that were already correct but
unguarded — MCP auth secret redaction through the real
publicAIMcpServerResource schema, upload.ts's byte-cap/redirect logic via a
mocked fetch, cross-workspace isolation for ai-mcp-server and ai-function
update/delete, and the create-ai-file action's noEmbeddingProvider
translation branch (lost when the old action test was deleted).

Phase 5 nit: aligns ai-function's update/delete to scope by
{workspaceId, id} instead of bare id, matching ai-mcp-server's pattern, for
defense in depth.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
apps/worker's bounded-download.ts and packages/filesystem's upload.ts each
carried a near-verbatim copy of the byte-limited body reader and the
manual-redirect-with-re-validation loop — the worker copy already had test
coverage, and the filesystem copy is what introduced the ContentLength bug
fixed in the previous commit. Extracts both into a shared
packages/filesystem/src/lib/bounded-fetch.ts, parameterized over the caller's
own error type (UploadValidationError vs ExpectedHeavyStepError) and fetch
implementation (platform fetch vs ky, so the worker keeps its abort-signal/
timeout support), so both call sites stay behaviorally identical without a
second implementation to drift.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…unded-fetch cap

Actions for ai-functions/ai-mcp-servers now call the service and catch
validationException instead of pre-checking name uniqueness, so create/update
race conditions surface as a proper conflict instead of a lost check. Service
methods drop the optional TranslationFn param and throw plain-English errors,
letting both the app layer and the public API share one error path. The MCP
server delete public API now checks the deleted-rows result and 404s when
nothing matched. readBodyWithLimit also enforces the byte cap when a response
has no body stream, closing a bypass in uploadFileFromUrl.
…gerIds column

listAIFunctions was missing the chatbot access check present on sibling
ai-* queries. aiTriggerIds became dead weight after ai-triggers retirement
in cddb767; drop the column and its schema-default-parity exception.
@realcodesiman
realcodesiman merged commit d2002eb into main Sep 12, 2026
4 checks passed
@realcodesiman
realcodesiman deleted the feat/ai-tools-scope-public-apis branch September 12, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant