Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/.changeset/quiet-multi-turn-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@link-assistant/agent': patch
---

Eliminate AI SDK warnings from multi-turn OpenAI-compatible runs by passing
trusted system prompts through the dedicated `system` option and upgrading the
adapter to its AI SDK 6-compatible Language Model v3 release.
32 changes: 22 additions & 10 deletions js/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@ai-sdk/mcp": "^0.0.8",
"@ai-sdk/mistral": "^2.0.27",
"@ai-sdk/openai": "^2.0.89",
"@ai-sdk/openai-compatible": "^1.0.32",
"@ai-sdk/openai-compatible": "^2.0.62",
"@ai-sdk/xai": "^2.0.33",
"@clack/prompts": "^0.11.0",
"@hono/standard-validator": "^0.2.0",
Expand All @@ -82,7 +82,7 @@
"@standard-community/standard-json": "^0.3.5",
"@standard-community/standard-openapi": "^0.2.9",
"@zip.js/zip.js": "^2.8.10",
"ai": "^6.0.1",
"ai": "^6.0.235",
"chokidar": "^4.0.3",
"clipboardy": "^5.0.0",
"command-stream": "^0.7.1",
Expand Down
9 changes: 2 additions & 7 deletions js/src/session/compaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { streamText, wrapLanguageModel, type ModelMessage } from 'ai';
import { streamText, wrapLanguageModel } from 'ai';
import { Session } from '.';
import { Identifier } from '../id/id';
import { Instance } from '../project/instance';
Expand Down Expand Up @@ -384,13 +384,8 @@ export namespace SessionCompaction {
headers: model.info.headers,
abortSignal: input.abort,
tools: model.info.tool_call ? {} : undefined,
system: system.map((content) => ({ role: 'system', content })),
messages: [
...system.map(
(x): ModelMessage => ({
role: 'system',
content: x,
})
),
...safeModelMessages,
{
role: 'user',
Expand Down
22 changes: 6 additions & 16 deletions js/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Provider } from '../provider/provider';
import {
generateText,
streamText,
type ModelMessage,
type Tool as AITool,
tool,
wrapLanguageModel,
Expand Down Expand Up @@ -990,15 +989,8 @@ export namespace SessionPrompt {
stopWhen: stepCountIs(1),
temperature: params.temperature,
topP: params.topP,
messages: [
...system.map(
(x): ModelMessage => ({
role: 'system',
content: x,
})
),
...safeModelMessages,
],
system: system.map((content) => ({ role: 'system', content })),
messages: safeModelMessages,
tools: model.info?.tool_call === false ? undefined : tools,
model: wrapLanguageModel({
model: model.language,
Expand Down Expand Up @@ -1925,13 +1917,11 @@ export namespace SessionPrompt {
small.providerID,
options
),
system: safeTitleSystemMessages.map((content) => ({
role: 'system',
content,
})),
messages: [
...safeTitleSystemMessages.map(
(x): ModelMessage => ({
role: 'system',
content: x,
})
),
{
role: 'user' as const,
content: `
Expand Down
73 changes: 73 additions & 0 deletions js/tests/ai-sdk-warnings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { afterEach, describe, expect, mock, test } from 'bun:test';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';

const originalWarn = console.warn;

afterEach(() => {
console.warn = originalWarn;
});

function successfulChatCompletion() {
const chunks = [
{
id: 'chatcmpl-test',
object: 'chat.completion.chunk',
created: 0,
model: 'test-model',
choices: [
{
index: 0,
delta: { role: 'assistant', content: 'ok' },
finish_reason: null,
},
],
},
{
id: 'chatcmpl-test',
object: 'chat.completion.chunk',
created: 0,
model: 'test-model',
choices: [
{
index: 0,
delta: {},
finish_reason: 'stop',
},
],
},
];
const body =
chunks.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`).join('') +
'data: [DONE]\n\n';

return new Response(body, {
headers: { 'content-type': 'text/event-stream' },
});
}

describe('AI SDK warning-free multi-turn requests', () => {
test('OpenAI-compatible requests do not emit warnings', async () => {
const warnings: unknown[][] = [];
console.warn = mock((...args: unknown[]) => warnings.push(args));

const provider = createOpenAICompatible({
name: 'test-provider',
baseURL: 'https://example.invalid/v1',
apiKey: 'test-key',
fetch: async () => successfulChatCompletion(),
});
const model = provider('test-model');

for (let turn = 0; turn < 2; turn++) {
const result = streamText({
model,
system: 'You are a test assistant.',
messages: [{ role: 'user', content: `Turn ${turn + 1}` }],
});
expect(await result.text).toBe('ok');
}

expect(warnings).toEqual([]);
});
});