@outputai/llm 0.7.1-next.ae5bab4.0 → 0.7.1-next.bd6bd49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/llm",
3
- "version": "0.7.1-next.ae5bab4.0",
3
+ "version": "0.7.1-next.bd6bd49.0",
4
4
  "description": "Framework abstraction to interact with LLM models",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -13,7 +13,7 @@
13
13
  "gray-matter": "4.0.3",
14
14
  "liquidjs": "10.25.7",
15
15
  "undici": "8.1.0",
16
- "@outputai/core": "0.7.1-next.ae5bab4.0"
16
+ "@outputai/core": "0.7.1-next.bd6bd49.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "ai": "6.0.168",
package/src/agent.js CHANGED
@@ -5,7 +5,7 @@ import { loadAiSdkTextOptions } from './ai_sdk_options.js';
5
5
  import { prepareTextPrompt } from './prompt/prepare_text.js';
6
6
  import { startTrace, endTraceWithError } from './utils/trace.js';
7
7
  import { wrapTextResponse, wrapStreamOnFinishResponse } from './utils/response_wrappers.js';
8
- import { ROLE, isRole, getContent } from './utils/message.js';
8
+ import { ROLE, isRole } from './utils/message.js';
9
9
  export { skill } from './prompt/skill.js';
10
10
 
11
11
  export const createMemoryConversationStore = () => {
@@ -47,12 +47,13 @@ export class Agent extends AIToolLoopAgent {
47
47
 
48
48
  // Extract system messages as `instructions` for the ToolLoopAgent constructor
49
49
  // and keep user messages for generate() calls — avoids provider errors
50
- // with multiple system messages during multi-step tool loops
51
- const systemContent = allMessages.filter( isRole( ROLE.SYSTEM ) ).map( getContent ).join( '\n\n' );
50
+ // with multiple system messages during multi-step tool loops.
51
+ // Pass message objects (not a string) so per-message providerOptions are preserved.
52
+ const systemMessages = allMessages.filter( isRole( ROLE.SYSTEM ) );
52
53
 
53
54
  super( {
54
55
  ...constructorOptions,
55
- ...( systemContent ? { instructions: systemContent } : {} ),
56
+ ...( systemMessages.length > 0 ? { instructions: systemMessages } : {} ),
56
57
  ...( tools ? { tools } : {} ),
57
58
  stopWhen: stopWhen ?? stepCountIs( maxSteps ),
58
59
  ...rest
package/src/agent.spec.js CHANGED
@@ -86,7 +86,8 @@ vi.mock( './utils/trace.js', () => ( {
86
86
 
87
87
  vi.mock( './utils/response_wrappers.js', () => ( {
88
88
  wrapTextResponse: ( ...args ) => wrapMocks.wrapTextResponse( ...args ),
89
- wrapStreamOnFinishResponse: ( ...args ) => wrapMocks.wrapStreamOnFinishResponse( ...args )
89
+ wrapStreamOnFinishResponse: ( ...args ) =>
90
+ wrapMocks.wrapStreamOnFinishResponse( ...args )
90
91
  } ) );
91
92
 
92
93
  vi.mock( './prompt/skill.js', () => ( {
@@ -131,7 +132,9 @@ describe( 'Agent', () => {
131
132
  aiMocks.superConstructor.mockReset();
132
133
  aiMocks.superGenerate.mockReset().mockResolvedValue( aiResponse );
133
134
  aiMocks.superStream.mockReset().mockReturnValue( { textStream: 'stream' } );
134
- aiMocks.stepCountIs.mockReset().mockImplementation( count => ( { type: 'step-count', count } ) );
135
+ aiMocks.stepCountIs
136
+ .mockReset()
137
+ .mockImplementation( count => ( { type: 'step-count', count } ) );
135
138
 
136
139
  promptMocks.prepareTextPrompt.mockReset().mockReturnValue( {
137
140
  loadedPrompt,
@@ -143,7 +146,9 @@ describe( 'Agent', () => {
143
146
  traceMocks.startTrace.mockReset().mockReturnValue( 'trace-id' );
144
147
  traceMocks.endTraceWithError.mockReset();
145
148
 
146
- wrapMocks.wrapTextResponse.mockReset().mockImplementation( async ( { response } ) => response );
149
+ wrapMocks.wrapTextResponse
150
+ .mockReset()
151
+ .mockImplementation( async ( { response } ) => response );
147
152
  wrapMocks.wrapStreamOnFinishResponse.mockReset().mockReturnValue( {
148
153
  onFinish: vi.fn()
149
154
  } );
@@ -175,7 +180,9 @@ describe( 'Agent', () => {
175
180
 
176
181
  it( 'prepares the prompt using the resolved invocation dir', async () => {
177
182
  const { Agent } = await importSut();
178
- const skills = [ { name: 'style', description: 'Style', instructions: '# Style' } ];
183
+ const skills = [
184
+ { name: 'style', description: 'Style', instructions: '# Style' }
185
+ ];
179
186
  const tools = { search: { description: 'Search' } };
180
187
 
181
188
  new Agent( {
@@ -199,9 +206,11 @@ describe( 'Agent', () => {
199
206
 
200
207
  new Agent( { prompt: 'test@v1', promptDir: '/explicit/prompts' } );
201
208
 
202
- expect( promptMocks.prepareTextPrompt ).toHaveBeenCalledWith( expect.objectContaining( {
203
- promptDir: '/explicit/prompts'
204
- } ) );
209
+ expect( promptMocks.prepareTextPrompt ).toHaveBeenCalledWith(
210
+ expect.objectContaining( {
211
+ promptDir: '/explicit/prompts'
212
+ } )
213
+ );
205
214
  } );
206
215
 
207
216
  it( 'constructs ToolLoopAgent with text options, instructions, tools, and default stopWhen', async () => {
@@ -215,12 +224,33 @@ describe( 'Agent', () => {
215
224
  model,
216
225
  providerOptions: { test: true },
217
226
  temperature: 0.3,
218
- instructions: 'You are concise.',
227
+ instructions: [ { role: 'system', content: 'You are concise.' } ],
219
228
  tools: preparedTools,
220
229
  stopWhen: { type: 'step-count', count: 10 }
221
230
  } );
222
231
  } );
223
232
 
233
+ it( 'preserves per-message providerOptions on system messages passed as instructions', async () => {
234
+ const { Agent } = await importSut();
235
+ const systemMessage = {
236
+ role: 'system',
237
+ content: 'You are concise.',
238
+ providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }
239
+ };
240
+ optionMocks.loadAiSdkTextOptions.mockReturnValueOnce( {
241
+ model,
242
+ messages: [ systemMessage, { role: 'user', content: 'Hello' } ]
243
+ } );
244
+
245
+ new Agent( { prompt: 'test@v1' } );
246
+
247
+ expect( aiMocks.superConstructor ).toHaveBeenCalledWith(
248
+ expect.objectContaining( {
249
+ instructions: [ systemMessage ]
250
+ } )
251
+ );
252
+ } );
253
+
224
254
  it( 'omits tools when prompt preparation returns null tools', async () => {
225
255
  const { Agent } = await importSut();
226
256
  promptMocks.prepareTextPrompt.mockReturnValueOnce( {
@@ -234,7 +264,7 @@ describe( 'Agent', () => {
234
264
  model,
235
265
  providerOptions: { test: true },
236
266
  temperature: 0.3,
237
- instructions: 'You are concise.',
267
+ instructions: [ { role: 'system', content: 'You are concise.' } ],
238
268
  stopWhen: { type: 'step-count', count: 10 }
239
269
  } );
240
270
  } );
@@ -246,9 +276,11 @@ describe( 'Agent', () => {
246
276
  new Agent( { prompt: 'test@v1', stopWhen } );
247
277
 
248
278
  expect( aiMocks.stepCountIs ).not.toHaveBeenCalled();
249
- expect( aiMocks.superConstructor ).toHaveBeenCalledWith( expect.objectContaining( {
250
- stopWhen
251
- } ) );
279
+ expect( aiMocks.superConstructor ).toHaveBeenCalledWith(
280
+ expect.objectContaining( {
281
+ stopWhen
282
+ } )
283
+ );
252
284
  } );
253
285
 
254
286
  it( 'passes custom constructor options through', async () => {
@@ -256,10 +288,12 @@ describe( 'Agent', () => {
256
288
 
257
289
  new Agent( { prompt: 'test@v1', temperature: 0.8, seed: 42 } );
258
290
 
259
- expect( aiMocks.superConstructor ).toHaveBeenCalledWith( expect.objectContaining( {
260
- temperature: 0.8,
261
- seed: 42
262
- } ) );
291
+ expect( aiMocks.superConstructor ).toHaveBeenCalledWith(
292
+ expect.objectContaining( {
293
+ temperature: 0.8,
294
+ seed: 42
295
+ } )
296
+ );
263
297
  } );
264
298
 
265
299
  it( 'keeps only user prompt messages as initial generate messages', async () => {
@@ -275,7 +309,9 @@ describe( 'Agent', () => {
275
309
 
276
310
  it( 'combines initial, stored, and caller messages for generate', async () => {
277
311
  const store = {
278
- getMessages: vi.fn( () => [ { role: 'assistant', content: 'Stored reply' } ] ),
312
+ getMessages: vi.fn( () => [
313
+ { role: 'assistant', content: 'Stored reply' }
314
+ ] ),
279
315
  addMessages: vi.fn()
280
316
  };
281
317
  const callerMessage = { role: 'user', content: 'New question' };
@@ -336,7 +372,9 @@ describe( 'Agent', () => {
336
372
 
337
373
  it( 'streams with initial, stored, and caller messages', async () => {
338
374
  const store = {
339
- getMessages: vi.fn( () => [ { role: 'assistant', content: 'Stored reply' } ] ),
375
+ getMessages: vi.fn( () => [
376
+ { role: 'assistant', content: 'Stored reply' }
377
+ ] ),
340
378
  addMessages: vi.fn()
341
379
  };
342
380
  const onFinish = vi.fn();
@@ -345,7 +383,12 @@ describe( 'Agent', () => {
345
383
  const { Agent } = await importSut();
346
384
  const agent = new Agent( { prompt: 'test@v1', conversationStore: store } );
347
385
 
348
- const result = await agent.stream( { messages: [ callerMessage ], onFinish, onError, maxRetries: 1 } );
386
+ const result = await agent.stream( {
387
+ messages: [ callerMessage ],
388
+ onFinish,
389
+ onError,
390
+ maxRetries: 1
391
+ } );
349
392
 
350
393
  expect( traceMocks.startTrace ).toHaveBeenCalledWith( {
351
394
  name: 'Agent.stream',
package/src/index.d.ts CHANGED
@@ -62,7 +62,7 @@ export type PromptMessage = {
62
62
  * frontmatter `messageOptions` set names — which is resolved into per-message `providerOptions`
63
63
  * at call time and stripped before the request is sent. Authored as `<system options="set_a set_b">`.
64
64
  */
65
- attributes?: Record<string, string | boolean>;
65
+ attributes?: Record<string, string | true>;
66
66
  };
67
67
 
68
68
  /**