Skip to content

refactor(ai): move Ask AI domain logic out of the provider adapter - #666

Open
Reversean wants to merge 1 commit into
chore/bump-types-nodefrom
refactor/ai-service-layering
Open

refactor(ai): move Ask AI domain logic out of the provider adapter#666
Reversean wants to merge 1 commit into
chore/bump-types-nodefrom
refactor/ai-service-layering

Conversation

@Reversean

@Reversean Reversean commented Jul 29, 2026

Copy link
Copy Markdown
Member

src/integrations/ holds adapters to external services. The Ask AI prompt assembly, the
model 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 reduce VercelAIApi to a transport that
takes a system/prompt pair and returns text:

complete({ system, prompt }: CompletionParams): Promise<string>

Orchestration moves to AIService, which already owns the event lookup.
instructions/cto.ts and inputs/eventSolving.ts are 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.generateSuggestion keeps its signature and its only caller,
src/resolvers/event.js, is untouched.

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
Reversean force-pushed the refactor/ai-service-layering branch from 71629b8 to 16fd7a6 Compare July 29, 2026 17:21
@neSpecc
neSpecc requested a review from Copilot July 30, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 updated AIService.generateSuggestion to 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.generateSuggestion orchestration 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
}

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.

3 participants