refactor(builder): move ai feature data access into business services - #1096
Open
realcodesiman wants to merge 1 commit into
Open
refactor(builder): move ai feature data access into business services#1096realcodesiman wants to merge 1 commit into
realcodesiman wants to merge 1 commit into
Conversation
Removes direct db usage from the builder AI surface (Claude, DeepSeek, Gemini, OpenAI connect actions and queries, ai-files, ai-functions, ai-mcp-servers, ai-triggers, personas) per .agents/rules/data-access.md. - add connect() to the four LLM provider services (mirrors openrouter) - add aiFileService (create/delete/listWithEmbeddingStatus) and aiTriggerService (list/create/duplicate) - add aiFunctionService.list and integrationMessengerRepository.listPersonasByWorkspaceId - actions/queries become thin wrappers; cache invalidation stays in the builder because business must not import @chatbotx.io/ai - OpenAI connect audits via dispatchAuditRecord with an explicit workspaceId (authActionClient has no workspace in the audit context)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
db.*call from the builder AI surface (Claude/DeepSeek/Gemini/OpenAI connect actions and queries, ai-files, ai-functions, ai-mcp-servers, ai-triggers, personas) per.agents/rules/data-access.md, so the logic is reusable from the worker and public APIs and mockable at one boundary.mainand only append to the shared barrels.Changes
packages/business/src/integration-{claude,deepseek,gemini,openai}/service.ts: newconnect()mirroringintegrationOpenRouterService.connect(audit stays unconditional as before; OpenAI records audit with an explicitworkspaceIdbecauseauthActionClienthas no workspace in the audit context).packages/business/src/ai-file/(create,delete,listWithEmbeddingStatus) andpackages/business/src/ai-trigger/(list,create,duplicate);aiFunctionService.list;integrationMessengerRepository.listPersonasByWorkspaceId.@chatbotx.io/ai.packages/business/__tests__/{integration-llm-connect,ai-file,ai-trigger}.service.test.ts,apps/builder/__tests__/{integration-llm-connect-actions,ai-triggers-actions}.test.ts).Notes for reviewers
connect()update paths now run the UPDATE outside a transaction (the insert path is still transactional); the old action wrapped the read+update in one transaction. Idempotent byexisting.id, so no data-loss window, but flagging the shape change.aiFileService.deletedeletes embeddings byaiEmbeddingModel.idinstead ofaiFileId(harmless via FK cascade).integration-*/actions/update.action.tsandai-triggers/actions/{update,delete}.action.tsstill usedb;connectOpenAIActionusesauthActionClientand does not verify workspace membership.Test plan
pnpm --filter @chatbotx.io/database check-types && testpnpm --filter @chatbotx.io/business check-types && test(only the pre-existingads-conversion-rule.service.test.tsfailures remain, also red onmain)pnpm --filter builder check-types && testpnpm lint