@outputai/llm 0.8.2-next.42a0ddf.0 → 0.8.2-next.ad732b1.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 +2 -2
- package/src/agent.js +3 -3
- package/src/agent.spec.js +4 -2
- package/src/cost/index.js +1 -1
- package/src/cost/index.spec.js +2 -2
- package/src/prompt/load_content.js +2 -2
- package/src/prompt/load_content.spec.js +5 -3
- package/src/utils/trace.js +2 -2
- package/src/utils/trace.spec.js +8 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outputai/llm",
|
|
3
|
-
"version": "0.8.2-next.
|
|
3
|
+
"version": "0.8.2-next.ad732b1.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.8.2-next.
|
|
16
|
+
"@outputai/core": "0.8.2-next.ad732b1.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"ai": "6.0.168",
|
package/src/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidationError } from '@outputai/core';
|
|
2
|
-
import {
|
|
2
|
+
import { Path } from '@outputai/core/sdk/helpers';
|
|
3
3
|
import { ToolLoopAgent as AIToolLoopAgent, stepCountIs } from 'ai';
|
|
4
4
|
import { loadAiSdkTextOptions } from './ai_sdk_options.js';
|
|
5
5
|
import { prepareTextPrompt } from './prompt/prepare_text.js';
|
|
@@ -38,8 +38,8 @@ export class Agent extends AIToolLoopAgent {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Must be captured synchronously — Temporal async activity execution
|
|
41
|
-
// breaks the call stack, so resolveInvocationDir() fails if called lazily.
|
|
42
|
-
const resolvedPromptDir = promptDir ?? resolveInvocationDir();
|
|
41
|
+
// breaks the call stack, so Path.resolveInvocationDir() fails if called lazily.
|
|
42
|
+
const resolvedPromptDir = promptDir ?? Path.resolveInvocationDir();
|
|
43
43
|
|
|
44
44
|
const { loadedPrompt, tools } = prepareTextPrompt( { prompt, variables, promptDir: resolvedPromptDir, skills, tools: toolsArg } );
|
|
45
45
|
|
package/src/agent.spec.js
CHANGED
|
@@ -46,8 +46,10 @@ vi.mock( '@outputai/core', () => ( {
|
|
|
46
46
|
ValidationError: coreMocks.ValidationError
|
|
47
47
|
} ) );
|
|
48
48
|
|
|
49
|
-
vi.mock( '@outputai/core/
|
|
50
|
-
|
|
49
|
+
vi.mock( '@outputai/core/sdk/helpers', () => ( {
|
|
50
|
+
Path: {
|
|
51
|
+
resolveInvocationDir: () => state.invocationDir
|
|
52
|
+
}
|
|
51
53
|
} ) );
|
|
52
54
|
|
|
53
55
|
vi.mock( 'ai', () => {
|
package/src/cost/index.js
CHANGED
package/src/cost/index.spec.js
CHANGED
|
@@ -6,7 +6,7 @@ vi.mock( './fetch_models_pricing.js', () => ( {
|
|
|
6
6
|
fetchModelsPricing: ( ...args ) => mockFetchModelsPricing( ...args )
|
|
7
7
|
} ) );
|
|
8
8
|
|
|
9
|
-
vi.mock( '@outputai/core/
|
|
9
|
+
vi.mock( '@outputai/core/sdk/runtime', () => {
|
|
10
10
|
class LLMUsage {
|
|
11
11
|
static TYPE = 'llm:usage';
|
|
12
12
|
type = LLMUsage.TYPE;
|
|
@@ -44,7 +44,7 @@ vi.mock( '@outputai/core/sdk_activity_integration', () => {
|
|
|
44
44
|
};
|
|
45
45
|
} );
|
|
46
46
|
|
|
47
|
-
import { Tracing } from '@outputai/core/
|
|
47
|
+
import { Tracing } from '@outputai/core/sdk/runtime';
|
|
48
48
|
import { calculateLLMCallCost } from './index.js';
|
|
49
49
|
|
|
50
50
|
const expectLLMUsage = ( result, { modelId, usage, total, tokensUsed } ) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import { Path } from '@outputai/core/sdk/helpers';
|
|
4
4
|
import { FatalError } from '@outputai/core';
|
|
5
5
|
|
|
6
6
|
const scanDir = dir => {
|
|
@@ -41,5 +41,5 @@ const findContent = ( name, dir ) => {
|
|
|
41
41
|
* @param {string} [dir] - Directory to search, defaults to invocation directory
|
|
42
42
|
* @returns {{ content: string, dir: string } | null}
|
|
43
43
|
*/
|
|
44
|
-
export const loadContent = ( name, dir = resolveInvocationDir() ) =>
|
|
44
|
+
export const loadContent = ( name, dir = Path.resolveInvocationDir() ) =>
|
|
45
45
|
findContent( name, dir ) ?? null;
|
|
@@ -6,9 +6,11 @@ import { tmpdir } from 'node:os';
|
|
|
6
6
|
// Hoisted state so mocks can read dynamic values set in tests
|
|
7
7
|
const state = vi.hoisted( () => ( { dir: '', entries: {} } ) );
|
|
8
8
|
|
|
9
|
-
// Mock
|
|
10
|
-
vi.mock( '@outputai/core/
|
|
11
|
-
|
|
9
|
+
// Mock SDK helpers to control resolveInvocationDir
|
|
10
|
+
vi.mock( '@outputai/core/sdk/helpers', () => ( {
|
|
11
|
+
Path: {
|
|
12
|
+
resolveInvocationDir: () => state.dir
|
|
13
|
+
}
|
|
12
14
|
} ) );
|
|
13
15
|
|
|
14
16
|
// Mock node:fs.readFileSync for directory scans while delegating file reads
|
package/src/utils/trace.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tracing,
|
|
1
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
2
2
|
|
|
3
3
|
export const startTrace = ( { name, ...details } ) => {
|
|
4
4
|
const traceId = `${name}-${Date.now()}`;
|
|
@@ -13,7 +13,7 @@ export const endTraceWithError = ( { traceId, error } ) => {
|
|
|
13
13
|
export const endTraceWithSuccess = ( { traceId, result, cost, ...extra } ) => {
|
|
14
14
|
if ( cost ) {
|
|
15
15
|
Tracing.addEventAttribute( { eventId: traceId, attribute: cost } );
|
|
16
|
-
|
|
16
|
+
Event.emit( 'cost:llm:request', cost );
|
|
17
17
|
}
|
|
18
18
|
Tracing.addEventEnd( { id: traceId, details: { result, ...extra } } );
|
|
19
19
|
};
|
package/src/utils/trace.spec.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
|
|
3
|
-
vi.mock( '@outputai/core/
|
|
3
|
+
vi.mock( '@outputai/core/sdk/runtime', () => ( {
|
|
4
4
|
Tracing: {
|
|
5
5
|
addEventStart: vi.fn(),
|
|
6
6
|
addEventError: vi.fn(),
|
|
7
7
|
addEventAttribute: vi.fn(),
|
|
8
8
|
addEventEnd: vi.fn()
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
Event: {
|
|
11
|
+
emit: vi.fn()
|
|
12
|
+
}
|
|
11
13
|
} ) );
|
|
12
14
|
|
|
13
|
-
import { Tracing,
|
|
15
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
14
16
|
import { startTrace, endTraceWithError, endTraceWithSuccess } from './trace.js';
|
|
15
17
|
|
|
16
18
|
const tracing = vi.mocked( Tracing, true );
|
|
19
|
+
const event = vi.mocked( Event, true );
|
|
17
20
|
|
|
18
21
|
describe( 'trace utils', () => {
|
|
19
22
|
beforeEach( () => {
|
|
@@ -69,7 +72,7 @@ describe( 'trace utils', () => {
|
|
|
69
72
|
eventId: 'trace-a',
|
|
70
73
|
attribute: cost
|
|
71
74
|
} );
|
|
72
|
-
expect(
|
|
75
|
+
expect( event.emit ).toHaveBeenCalledWith( 'cost:llm:request', cost );
|
|
73
76
|
expect( tracing.addEventEnd ).toHaveBeenCalledWith( {
|
|
74
77
|
id: 'trace-a',
|
|
75
78
|
details: {
|
|
@@ -94,7 +97,7 @@ describe( 'trace utils', () => {
|
|
|
94
97
|
} );
|
|
95
98
|
|
|
96
99
|
expect( tracing.addEventAttribute ).not.toHaveBeenCalled();
|
|
97
|
-
expect(
|
|
100
|
+
expect( event.emit ).not.toHaveBeenCalled();
|
|
98
101
|
expect( tracing.addEventEnd ).toHaveBeenCalledWith( {
|
|
99
102
|
id: 'trace-no-cost',
|
|
100
103
|
details: {
|