@outputai/llm 0.11.1-next.da26845.0 → 0.12.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.
Files changed (47) hide show
  1. package/package.json +7 -3
  2. package/src/agent.js +7 -2
  3. package/src/generate.js +1 -0
  4. package/src/index.d.ts +14 -6
  5. package/src/utils/wrap.js +35 -2
  6. package/src/agent.spec.js +0 -595
  7. package/src/ai_provider.spec.js +0 -217
  8. package/src/ai_sdk_options.spec.js +0 -390
  9. package/src/fixtures/image_response_v7_google_vertex.js +0 -72
  10. package/src/fixtures/image_response_v7_openai.js +0 -77
  11. package/src/fixtures/models_api_light.json +0 -675
  12. package/src/fixtures/models_api_v7_subset.json +0 -259
  13. package/src/fixtures/stream_response_v7_anthropic.js +0 -389
  14. package/src/fixtures/stream_response_v7_google_vertex.js +0 -462
  15. package/src/fixtures/stream_response_v7_openai.js +0 -353
  16. package/src/fixtures/stream_response_v7_perplexity.js +0 -671
  17. package/src/fixtures/text_response_v7_anthropic.js +0 -359
  18. package/src/fixtures/text_response_v7_anthropic_cache.js +0 -719
  19. package/src/fixtures/text_response_v7_google_vertex.js +0 -435
  20. package/src/fixtures/text_response_v7_openai.js +0 -347
  21. package/src/fixtures/text_response_v7_perplexity.js +0 -764
  22. package/src/generate.spec.js +0 -525
  23. package/src/prompt/content.spec.js +0 -208
  24. package/src/prompt/interpolations.spec.js +0 -109
  25. package/src/prompt/loader.full.spec.js +0 -309
  26. package/src/prompt/loader.spec.js +0 -258
  27. package/src/prompt/markup/attributes.spec.js +0 -132
  28. package/src/prompt/markup/nodes.spec.js +0 -333
  29. package/src/prompt/markup/tokenizer.spec.js +0 -149
  30. package/src/prompt/markup/tokens.spec.js +0 -250
  31. package/src/prompt/validations.spec.js +0 -812
  32. package/src/utils/cost.full.spec.js +0 -272
  33. package/src/utils/cost.spec.js +0 -290
  34. package/src/utils/error_handler.spec.js +0 -230
  35. package/src/utils/file.spec.js +0 -89
  36. package/src/utils/image.spec.js +0 -20
  37. package/src/utils/legacy_cost_attribute.spec.js +0 -278
  38. package/src/utils/models.spec.js +0 -119
  39. package/src/utils/models_pricing.spec.js +0 -162
  40. package/src/utils/skills.spec.js +0 -168
  41. package/src/utils/sources.spec.js +0 -122
  42. package/src/utils/stream.spec.js +0 -55
  43. package/src/utils/tools.spec.js +0 -167
  44. package/src/utils/usage.full.spec.js +0 -215
  45. package/src/utils/usage.spec.js +0 -246
  46. package/src/utils/wrap.spec.js +0 -467
  47. package/src/validations.spec.js +0 -631
@@ -1,167 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- const getProvider = vi.hoisted( () => vi.fn() );
4
-
5
- vi.mock( '../ai_provider.js', () => ( {
6
- getProvider
7
- } ) );
8
-
9
- vi.mock( 'ai', () => ( {
10
- tool: def => def
11
- } ) );
12
-
13
- import { buildLoadSkillTool, loadPromptTools } from './tools.js';
14
-
15
- const skills = [
16
- { name: 'writer', description: 'Writes copy', instructions: '# Writer\nDo it.' },
17
- { name: 'reviewer', description: 'Reviews drafts', instructions: 'Review carefully.' }
18
- ];
19
-
20
- describe( 'buildLoadSkillTool', () => {
21
- it( 'returns a tool that loads instructions by skill name', () => {
22
- const tool = buildLoadSkillTool( skills );
23
-
24
- expect( tool.description ).toBe( 'Get detailed instructions for a named skill' );
25
- expect( tool.execute( { name: 'writer' } ) ).toBe( '# Writer\nDo it.' );
26
- expect( tool.execute( { name: 'reviewer' } ) ).toBe( 'Review carefully.' );
27
- } );
28
-
29
- it( 'returns available skill names when the name is unknown', () => {
30
- const tool = buildLoadSkillTool( skills );
31
-
32
- expect( tool.execute( { name: 'missing' } ) ).toBe(
33
- 'Skill "missing" not found. Available: writer, reviewer'
34
- );
35
- } );
36
-
37
- it( 'lists no names when the catalog is empty', () => {
38
- const tool = buildLoadSkillTool( [] );
39
-
40
- expect( tool.execute( { name: 'writer' } ) ).toBe( 'Skill "writer" not found. Available: ' );
41
- } );
42
- } );
43
-
44
- describe( 'loadPromptTools', () => {
45
- it( 'returns null and does not load the provider when no tools are configured', () => {
46
- const result = loadPromptTools( {
47
- config: {
48
- provider: 'vertex',
49
- model: 'gemini-2.0-flash'
50
- }
51
- } );
52
-
53
- expect( result ).toBeNull();
54
- expect( getProvider ).not.toHaveBeenCalled();
55
- } );
56
-
57
- it( 'returns null and does not load the provider when tools config is empty', () => {
58
- const result = loadPromptTools( {
59
- config: {
60
- provider: 'vertex',
61
- tools: {}
62
- }
63
- } );
64
-
65
- expect( result ).toBeNull();
66
- expect( getProvider ).not.toHaveBeenCalled();
67
- } );
68
-
69
- it( 'throws when the provider has no tools object', () => {
70
- getProvider.mockReturnValue( vi.fn() );
71
-
72
- expect( () => loadPromptTools( {
73
- name: 'foo',
74
- config: {
75
- provider: 'azure',
76
- tools: {
77
- webSearch: {}
78
- }
79
- }
80
- } ) ).toThrow( 'Provider "azure" used by prompt "foo" does not support provider-specific tools.' );
81
- } );
82
-
83
- it( 'loads a single provider tool with config', () => {
84
- const googleSearch = vi.fn( config => ( { type: 'googleSearch', config } ) );
85
- const provider = {
86
- tools: {
87
- googleSearch
88
- }
89
- };
90
- getProvider.mockReturnValue( provider );
91
-
92
- const result = loadPromptTools( {
93
- config: {
94
- provider: 'vertex',
95
- tools: {
96
- googleSearch: {
97
- mode: 'MODE_DYNAMIC',
98
- dynamicThreshold: 0.8
99
- }
100
- }
101
- }
102
- } );
103
-
104
- expect( getProvider ).toHaveBeenCalledWith( 'vertex' );
105
- expect( googleSearch ).toHaveBeenCalledWith( {
106
- mode: 'MODE_DYNAMIC',
107
- dynamicThreshold: 0.8
108
- } );
109
- expect( result ).toEqual( {
110
- googleSearch: {
111
- type: 'googleSearch',
112
- config: {
113
- mode: 'MODE_DYNAMIC',
114
- dynamicThreshold: 0.8
115
- }
116
- }
117
- } );
118
- } );
119
-
120
- it( 'loads multiple provider tools', () => {
121
- const googleSearch = vi.fn( config => ( { type: 'googleSearch', config } ) );
122
- const urlContext = vi.fn( config => ( { type: 'urlContext', config } ) );
123
- getProvider.mockReturnValue( {
124
- tools: {
125
- googleSearch,
126
- urlContext
127
- }
128
- } );
129
-
130
- const result = loadPromptTools( {
131
- config: {
132
- provider: 'vertex',
133
- tools: {
134
- googleSearch: {
135
- mode: 'MODE_DYNAMIC'
136
- },
137
- urlContext: {}
138
- }
139
- }
140
- } );
141
-
142
- expect( Object.keys( result ) ).toEqual( [ 'googleSearch', 'urlContext' ] );
143
- expect( googleSearch ).toHaveBeenCalledWith( { mode: 'MODE_DYNAMIC' } );
144
- expect( urlContext ).toHaveBeenCalledWith( {} );
145
- expect( result.googleSearch.type ).toBe( 'googleSearch' );
146
- expect( result.urlContext.type ).toBe( 'urlContext' );
147
- } );
148
-
149
- it( 'throws when a configured tool is not supported by the provider', () => {
150
- getProvider.mockReturnValue( {
151
- tools: {
152
- googleSearch: vi.fn(),
153
- urlContext: vi.fn()
154
- }
155
- } );
156
-
157
- expect( () => loadPromptTools( {
158
- name: 'foo',
159
- config: {
160
- provider: 'vertex',
161
- tools: {
162
- unknownTool: {}
163
- }
164
- }
165
- } ) ).toThrow( 'Provider "vertex" used by prompt "foo" does not support these tools: unknownTool.' );
166
- } );
167
- } );
@@ -1,215 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { req1 as anthropicCacheSeed, req2 as anthropicCacheReadWrite } from '../fixtures/text_response_v7_anthropic_cache.js';
3
- import anthropicStream from '../fixtures/stream_response_v7_anthropic.js';
4
- import anthropicText from '../fixtures/text_response_v7_anthropic.js';
5
- import googleVertexImage from '../fixtures/image_response_v7_google_vertex.js';
6
- import googleVertexStream from '../fixtures/stream_response_v7_google_vertex.js';
7
- import googleVertexText from '../fixtures/text_response_v7_google_vertex.js';
8
- import openaiImage from '../fixtures/image_response_v7_openai.js';
9
- import openaiStream from '../fixtures/stream_response_v7_openai.js';
10
- import openaiText from '../fixtures/text_response_v7_openai.js';
11
- import perplexityStream from '../fixtures/stream_response_v7_perplexity.js';
12
- import perplexityText from '../fixtures/text_response_v7_perplexity.js';
13
- import { LLMGenerationUsage, LLMGenerationUsageItem, parseLLMUsage } from './usage.js';
14
-
15
- const INPUT = LLMGenerationUsageItem.Group.INPUT;
16
- const OUTPUT = LLMGenerationUsageItem.Group.OUTPUT;
17
-
18
- const cases = [
19
- {
20
- name: 'OpenAI text',
21
- fixture: openaiText,
22
- providerId: 'openai',
23
- modelId: 'gpt-4.1-mini',
24
- input: 1035,
25
- output: 396,
26
- items: [
27
- { group: INPUT, label: 'no_cache', amount: 1035 },
28
- { group: INPUT, label: 'cache_read', amount: 0 },
29
- { group: INPUT, label: 'cache_write', amount: 0 },
30
- { group: OUTPUT, label: 'text', amount: 396 },
31
- { group: OUTPUT, label: 'reasoning', amount: 0 }
32
- ]
33
- },
34
- {
35
- name: 'OpenAI stream',
36
- fixture: openaiStream,
37
- providerId: 'openai',
38
- modelId: 'gpt-4.1-mini',
39
- input: 1035,
40
- output: 386,
41
- items: [
42
- { group: INPUT, label: 'no_cache', amount: 1035 },
43
- { group: INPUT, label: 'cache_read', amount: 0 },
44
- { group: INPUT, label: 'cache_write', amount: 0 },
45
- { group: OUTPUT, label: 'text', amount: 386 },
46
- { group: OUTPUT, label: 'reasoning', amount: 0 }
47
- ]
48
- },
49
- {
50
- name: 'OpenAI image',
51
- fixture: openaiImage,
52
- providerId: 'openai',
53
- modelId: 'gpt-image-1',
54
- input: 151,
55
- output: 4160,
56
- items: [
57
- { group: INPUT, label: null, amount: 151 },
58
- { group: OUTPUT, label: null, amount: 4160 }
59
- ]
60
- },
61
- {
62
- name: 'Anthropic text',
63
- fixture: anthropicText,
64
- providerId: 'anthropic',
65
- modelId: 'claude-haiku-4-5',
66
- input: 1113,
67
- output: 845,
68
- items: [
69
- { group: INPUT, label: 'no_cache', amount: 1113 },
70
- { group: INPUT, label: 'cache_read', amount: 0 },
71
- { group: INPUT, label: 'cache_write', amount: 0 },
72
- { group: OUTPUT, label: null, amount: 845 }
73
- ]
74
- },
75
- {
76
- name: 'Anthropic stream',
77
- fixture: anthropicStream,
78
- providerId: 'anthropic',
79
- modelId: 'claude-haiku-4-5',
80
- input: 1113,
81
- output: 1047,
82
- items: [
83
- { group: INPUT, label: 'no_cache', amount: 1113 },
84
- { group: INPUT, label: 'cache_read', amount: 0 },
85
- { group: INPUT, label: 'cache_write', amount: 0 },
86
- { group: OUTPUT, label: null, amount: 1047 }
87
- ]
88
- },
89
- {
90
- name: 'Anthropic cache seed',
91
- fixture: anthropicCacheSeed,
92
- providerId: 'anthropic',
93
- modelId: 'claude-haiku-4-5',
94
- input: 15016,
95
- output: 5,
96
- items: [
97
- { group: INPUT, label: 'no_cache', amount: 15 },
98
- { group: INPUT, label: 'cache_read', amount: 0 },
99
- { group: INPUT, label: 'cache_write', amount: 15001 },
100
- { group: OUTPUT, label: null, amount: 5 }
101
- ]
102
- },
103
- {
104
- name: 'Anthropic cache read and write',
105
- fixture: anthropicCacheReadWrite,
106
- providerId: 'anthropic',
107
- modelId: 'claude-haiku-4-5',
108
- input: 19017,
109
- output: 4,
110
- items: [
111
- { group: INPUT, label: 'no_cache', amount: 14 },
112
- { group: INPUT, label: 'cache_read', amount: 15001 },
113
- { group: INPUT, label: 'cache_write', amount: 4002 },
114
- { group: OUTPUT, label: null, amount: 4 }
115
- ]
116
- },
117
- {
118
- name: 'Google Vertex text',
119
- fixture: googleVertexText,
120
- providerId: 'google-vertex',
121
- modelId: 'gemini-2.5-flash',
122
- input: 1032,
123
- output: 1381,
124
- items: [
125
- { group: INPUT, label: 'no_cache', amount: 1032 },
126
- { group: INPUT, label: 'cache_read', amount: 0 },
127
- { group: OUTPUT, label: 'text', amount: 793 },
128
- { group: OUTPUT, label: 'reasoning', amount: 588 }
129
- ]
130
- },
131
- {
132
- name: 'Google Vertex stream',
133
- fixture: googleVertexStream,
134
- providerId: 'google-vertex',
135
- modelId: 'gemini-2.5-flash',
136
- input: 1032,
137
- output: 1347,
138
- items: [
139
- { group: INPUT, label: 'no_cache', amount: 1032 },
140
- { group: INPUT, label: 'cache_read', amount: 0 },
141
- { group: OUTPUT, label: 'text', amount: 858 },
142
- { group: OUTPUT, label: 'reasoning', amount: 489 }
143
- ]
144
- },
145
- {
146
- name: 'Google Vertex image',
147
- fixture: googleVertexImage,
148
- providerId: 'google-vertex',
149
- modelId: 'gemini-2.5-flash-image',
150
- input: 157,
151
- output: 1290,
152
- items: [
153
- { group: INPUT, label: null, amount: 157 },
154
- { group: OUTPUT, label: null, amount: 1290 }
155
- ]
156
- },
157
- {
158
- name: 'Perplexity text',
159
- fixture: perplexityText,
160
- providerId: 'perplexity',
161
- modelId: 'sonar',
162
- input: 1025,
163
- output: 437,
164
- items: [
165
- { group: INPUT, label: 'no_cache', amount: 1025 },
166
- { group: OUTPUT, label: 'text', amount: 437 },
167
- { group: OUTPUT, label: 'reasoning', amount: 0 }
168
- ]
169
- },
170
- {
171
- name: 'Perplexity stream',
172
- fixture: perplexityStream,
173
- providerId: 'perplexity',
174
- modelId: 'sonar',
175
- input: 1025,
176
- output: 448,
177
- items: [
178
- { group: INPUT, label: 'no_cache', amount: 1025 },
179
- { group: OUTPUT, label: 'text', amount: 448 },
180
- { group: OUTPUT, label: 'reasoning', amount: 0 }
181
- ]
182
- }
183
- ];
184
-
185
- describe( 'parseLLMUsage with AI SDK response fixtures', () => {
186
- it.each( cases )( 'normalizes $name usage', ( {
187
- fixture,
188
- providerId,
189
- modelId,
190
- input,
191
- output,
192
- items
193
- } ) => {
194
- const result = parseLLMUsage( {
195
- prompt: {
196
- config: {
197
- provider: providerId,
198
- model: modelId
199
- }
200
- },
201
- usage: fixture.usage
202
- } );
203
-
204
- expect( JSON.parse( JSON.stringify( result ) ) ).toEqual( {
205
- type: LLMGenerationUsage.TYPE,
206
- providerId,
207
- modelId,
208
- status: LLMGenerationUsage.Status.COMPLETE,
209
- input,
210
- output,
211
- total: input + output,
212
- items
213
- } );
214
- } );
215
- } );
@@ -1,246 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { Tracing } from '@outputai/core/sdk/runtime';
3
- import { LLMGenerationUsage, LLMGenerationUsageItem, parseLLMUsage } from './usage.js';
4
-
5
- const prompt = {
6
- config: {
7
- provider: 'test-provider',
8
- model: 'test-model'
9
- }
10
- };
11
-
12
- const parse = usage => parseLLMUsage( { prompt, usage } );
13
- const serialize = value => JSON.parse( JSON.stringify( value ) );
14
-
15
- describe( 'LLMGenerationUsage', () => {
16
- it( 'aggregates usage items and produces serializable data', () => {
17
- const usage = new LLMGenerationUsage( 'test-model', 'test-provider', [
18
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, 'no_cache', 70 ),
19
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, 'cache_read', 30 ),
20
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, 'text', 40 ),
21
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, 'reasoning', 10 )
22
- ] );
23
-
24
- expect( usage ).toBeInstanceOf( Tracing.Attribute.BaseAttribute );
25
- expect( serialize( usage ) ).toEqual( {
26
- type: LLMGenerationUsage.TYPE,
27
- providerId: 'test-provider',
28
- modelId: 'test-model',
29
- status: LLMGenerationUsage.Status.COMPLETE,
30
- input: 100,
31
- output: 50,
32
- total: 150,
33
- items: [
34
- { group: LLMGenerationUsageItem.Group.INPUT, label: 'no_cache', amount: 70 },
35
- { group: LLMGenerationUsageItem.Group.INPUT, label: 'cache_read', amount: 30 },
36
- { group: LLMGenerationUsageItem.Group.OUTPUT, label: 'text', amount: 40 },
37
- { group: LLMGenerationUsageItem.Group.OUTPUT, label: 'reasoning', amount: 10 }
38
- ]
39
- } );
40
- } );
41
-
42
- it( 'keeps missing groups null and marks usage incomplete', () => {
43
- const usage = new LLMGenerationUsage( 'test-model', 'test-provider', [
44
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, null, 25 )
45
- ] );
46
-
47
- expect( usage ).toMatchObject( {
48
- status: LLMGenerationUsage.Status.INCOMPLETE,
49
- input: 25,
50
- output: null,
51
- total: 25
52
- } );
53
- } );
54
-
55
- it( 'represents empty items as incomplete usage without totals', () => {
56
- const usage = new LLMGenerationUsage( 'test-model', 'test-provider', [] );
57
-
58
- expect( usage ).toMatchObject( {
59
- status: LLMGenerationUsage.Status.INCOMPLETE,
60
- input: null,
61
- output: null,
62
- total: null,
63
- items: []
64
- } );
65
- } );
66
- } );
67
-
68
- describe( 'parseLLMUsage', () => {
69
- it( 'uses complete input and output breakdowns', () => {
70
- const result = parse( {
71
- inputTokens: 100,
72
- inputTokenDetails: {
73
- noCacheTokens: 70,
74
- cacheReadTokens: 20,
75
- cacheWriteTokens: 10
76
- },
77
- outputTokens: 50,
78
- outputTokenDetails: {
79
- textTokens: 40,
80
- reasoningTokens: 10
81
- }
82
- } );
83
-
84
- expect( serialize( result ) ).toEqual( {
85
- type: LLMGenerationUsage.TYPE,
86
- providerId: 'test-provider',
87
- modelId: 'test-model',
88
- status: LLMGenerationUsage.Status.COMPLETE,
89
- input: 100,
90
- output: 50,
91
- total: 150,
92
- items: [
93
- { group: LLMGenerationUsageItem.Group.INPUT, label: 'no_cache', amount: 70 },
94
- { group: LLMGenerationUsageItem.Group.INPUT, label: 'cache_read', amount: 20 },
95
- { group: LLMGenerationUsageItem.Group.INPUT, label: 'cache_write', amount: 10 },
96
- { group: LLMGenerationUsageItem.Group.OUTPUT, label: 'text', amount: 40 },
97
- { group: LLMGenerationUsageItem.Group.OUTPUT, label: 'reasoning', amount: 10 }
98
- ]
99
- } );
100
- } );
101
-
102
- it( 'uses sparse breakdowns when their reported values match the aggregates', () => {
103
- const result = parse( {
104
- inputTokens: 100,
105
- inputTokenDetails: {
106
- noCacheTokens: 80,
107
- cacheReadTokens: 20
108
- },
109
- outputTokens: 50,
110
- outputTokenDetails: {
111
- textTokens: 50
112
- }
113
- } );
114
-
115
- expect( result.items ).toEqual( [
116
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, 'no_cache', 80 ),
117
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, 'cache_read', 20 ),
118
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, 'text', 50 )
119
- ] );
120
- expect( result.status ).toBe( LLMGenerationUsage.Status.COMPLETE );
121
- } );
122
-
123
- it( 'uses aggregate items when no breakdown is reported', () => {
124
- const result = parse( {
125
- inputTokens: 100,
126
- outputTokens: 50
127
- } );
128
-
129
- expect( result.items ).toEqual( [
130
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, null, 100 ),
131
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, null, 50 )
132
- ] );
133
- expect( result ).toMatchObject( {
134
- status: LLMGenerationUsage.Status.COMPLETE,
135
- input: 100,
136
- output: 50,
137
- total: 150
138
- } );
139
- } );
140
-
141
- it( 'uses aggregate items when reported breakdowns do not match', () => {
142
- const result = parse( {
143
- inputTokens: 100,
144
- inputTokenDetails: {
145
- noCacheTokens: 90,
146
- cacheReadTokens: 5,
147
- cacheWriteTokens: 0
148
- },
149
- outputTokens: 50,
150
- outputTokenDetails: {
151
- textTokens: 40,
152
- reasoningTokens: 5
153
- }
154
- } );
155
-
156
- expect( result.items ).toEqual( [
157
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, null, 100 ),
158
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, null, 50 )
159
- ] );
160
- } );
161
-
162
- it( 'preserves known zero aggregates', () => {
163
- const result = parse( {
164
- inputTokens: 0,
165
- inputTokenDetails: {
166
- noCacheTokens: 0,
167
- cacheReadTokens: 0,
168
- cacheWriteTokens: 0
169
- },
170
- outputTokens: 0,
171
- outputTokenDetails: {
172
- textTokens: 0,
173
- reasoningTokens: 0
174
- }
175
- } );
176
-
177
- expect( result ).toMatchObject( {
178
- status: LLMGenerationUsage.Status.COMPLETE,
179
- input: 0,
180
- output: 0,
181
- total: 0
182
- } );
183
- expect( result.items ).toEqual( [
184
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, null, 0 ),
185
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, null, 0 )
186
- ] );
187
- } );
188
-
189
- it.each( [
190
- {
191
- name: 'input',
192
- usage: { inputTokens: 25 },
193
- expected: { input: 25, output: null, total: 25 },
194
- item: new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.INPUT, null, 25 )
195
- },
196
- {
197
- name: 'output',
198
- usage: { outputTokens: 15 },
199
- expected: { input: null, output: 15, total: 15 },
200
- item: new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, null, 15 )
201
- }
202
- ] )( 'marks $name-only usage incomplete', ( { usage, expected, item } ) => {
203
- const result = parse( usage );
204
-
205
- expect( result ).toMatchObject( {
206
- status: LLMGenerationUsage.Status.INCOMPLETE,
207
- ...expected
208
- } );
209
- expect( result.items ).toEqual( [ item ] );
210
- } );
211
-
212
- it.each( [
213
- Number.POSITIVE_INFINITY,
214
- -1,
215
- 1.5
216
- ] )( 'ignores invalid aggregate value %s', inputTokens => {
217
- const result = parse( {
218
- inputTokens,
219
- outputTokens: 15
220
- } );
221
-
222
- expect( result ).toMatchObject( {
223
- status: LLMGenerationUsage.Status.INCOMPLETE,
224
- input: null,
225
- output: 15,
226
- total: 15
227
- } );
228
- expect( result.items ).toEqual( [
229
- new LLMGenerationUsageItem( LLMGenerationUsageItem.Group.OUTPUT, null, 15 )
230
- ] );
231
- } );
232
-
233
- it( 'returns null when neither aggregate is reported', () => {
234
- const result = parse( {
235
- inputTokenDetails: {
236
- noCacheTokens: 10
237
- },
238
- outputTokenDetails: {
239
- textTokens: 5
240
- },
241
- totalTokens: 15
242
- } );
243
-
244
- expect( result ).toBeNull();
245
- } );
246
- } );