refactor(ai): move Ask AI domain logic out of the provider adapter - #666
Open
Reversean wants to merge 1 commit into
Open
refactor(ai): move Ask AI domain logic out of the provider adapter#666Reversean wants to merge 1 commit into
Reversean wants to merge 1 commit into
Conversation
This was referenced Jul 29, 2026
The Ask AI prompt assembly, the model instruction and the event serialisation lived in src/integrations/vercel-ai/, a directory meant for adapters to external services, even though none of them referenced the provider. Replacing the provider therefore dragged the domain along, and anything applied around the model call could only be reused by importing from another adapter's internals. The domain now lives in src/services/askAi/ and VercelAIApi is reduced to a transport taking a system/prompt pair. Orchestration sits in AIService, which already owned the event lookup. Anything applied to the model's input or output can now sit above the transport, where a provider swap cannot silently drop it. Behaviour is unchanged: AIService.generateSuggestion keeps its signature and its only caller is untouched.
Reversean
force-pushed
the
refactor/ai-service-layering
branch
from
July 29, 2026 17:21
71629b8 to
16fd7a6
Compare
neSpecc
approved these changes
Jul 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the “Ask AI” feature by moving prompt/instruction assembly out of the Vercel AI integration adapter and into a dedicated domain area under src/services/askAi/, leaving src/integrations/vercel-ai/ as a thin transport layer.
Changes:
- Moved Ask AI domain prompt/instruction modules into
src/services/askAi/and updatedAIService.generateSuggestionto assemble{ system, prompt }there. - Simplified the Vercel adapter API to
complete({ system, prompt }): Promise<string>and added unit coverage for it. - Added unit tests to validate
AIService.generateSuggestionorchestration and the Vercel transport behavior; bumped package version.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/services/ai.ts |
Moves orchestration into AIService and calls the adapter via complete({ system, prompt }). |
src/integrations/vercel-ai/index.ts |
Refactors the adapter to a transport-style complete method that forwards to generateText. |
src/services/askAi/instructions/cto.ts |
Adds the CTO system instruction in the new domain location. |
src/services/askAi/inputs/eventSolving.ts |
Adds event prompt serialization in the new domain location. |
test/services/askAi.test.ts |
Adds unit tests asserting AIService.generateSuggestion calls the transport with the assembled system/prompt. |
test/integrations/vercel-ai.test.ts |
Adds unit tests asserting adapter forwards to generateText and returns text. |
package.json |
Bumps version to 1.5.10. |
Comments suppressed due to low confidence (1)
src/integrations/vercel-ai/index.ts:39
- Continuation of the indentation issue: this docblock/method body is indented differently from the surrounding codebase (2-space blocks). Reformatting here will keep the file consistent and avoid noisy diffs from auto-formatting.
* Send a system/prompt pair to the model and return the generated text
*
* @param {CompletionParams} params - system instruction and prompt to complete
* @returns {Promise<string>} text generated by the model
* @todo add defence against invalid prompt injection
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+50
| const result = await aiService.generateSuggestion(eventsFactoryWithPayload(), testEventId, testOriginalEventId); | ||
|
|
||
| expect(vercelAIApi.complete).toHaveBeenCalledWith({ | ||
| system: ctoInstruction, | ||
| prompt: eventSolvingInput(testPayload), |
Comment on lines
32
to
33
| } | ||
|
|
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.
src/integrations/holds adapters to external services. The Ask AI prompt assembly, themodel instruction and the event serialisation live there today, inside the Vercel adapter,
even though none of them import anything from the provider. They are domain code that ended
up in an adapter directory.
This has two consequences. Replacing the provider drags the domain along with it, and any
policy applied around the model call can only be reused by importing from another adapter's
internals.
Move the domain modules to
src/services/askAi/and reduceVercelAIApito a transport thattakes a system/prompt pair and returns text:
Orchestration moves to
AIService, which already owns the event lookup.instructions/cto.tsandinputs/eventSolving.tsare moved unchanged.This also places anything applied to the model's input or output above the transport, so
swapping the provider cannot silently drop it.
No behaviour change:
AIService.generateSuggestionkeeps its signature and its only caller,src/resolvers/event.js, is untouched.