@output.ai/core 0.1.8-dev.pr156.696d4dd → 0.1.8-dev.pr156.ac53caf

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": "@output.ai/core",
3
- "version": "0.1.8-dev.pr156.696d4dd",
3
+ "version": "0.1.8-dev.pr156.ac53caf",
4
4
  "description": "The core module of the output framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,11 +1,12 @@
1
1
  import { appendFileSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
- import { join } from 'node:path';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'url';
3
4
  import buildTraceTree from '../../tools/build_trace_tree.js';
4
5
  import { EOL } from 'node:os';
5
6
 
6
7
  const oneWeekInMS = 1000 * 60 * 60 * 24 * 7;
7
- // Use local working directory for temp files, not module-relative path
8
- const tempDir = join( process.cwd(), 'logs', 'temp', 'traces' );
8
+ const __dirname = dirname( fileURLToPath( import.meta.url ) );
9
+ const tempDir = join( __dirname, 'temp', 'traces' );
9
10
 
10
11
  const accumulate = ( { entry, executionContext: { workflowId, startTime } } ) => {
11
12
  const path = join( tempDir, `${startTime}_${workflowId}.trace` );
@@ -27,23 +28,31 @@ export const init = () => {
27
28
  };
28
29
 
29
30
  /**
30
- * Get the local file system path for ALL file I/O operations (read/write)
31
- * Always uses the container's local working directory
32
- * @param {string} workflowName - The name of the workflow
33
- * @returns {string} The local filesystem path for file operations
31
+ * Get the container base path for writing trace files
32
+ * Always writes to the local working directory, regardless of HOST_TRACE_PATH
33
+ * @returns {string} The base path where traces should be written in the container
34
+ */
35
+ const getContainerBasePath = () => {
36
+ return join( process.cwd(), 'logs' );
37
+ };
38
+
39
+ /**
40
+ * Get the base path for reporting trace file locations
41
+ * Uses HOST_TRACE_PATH if set (for reporting to host), otherwise uses local path
42
+ * @returns {string} The base path where traces can be accessed from the host
34
43
  */
35
- const getLocalOutputDir = workflowName => {
36
- return join( process.cwd(), 'logs', 'runs', workflowName );
44
+ const getBasePath = () => {
45
+ return process.env.HOST_TRACE_PATH || join( process.cwd(), 'logs' );
37
46
  };
38
47
 
39
48
  /**
40
- * Get the host path for reporting trace file locations to users
41
- * Uses HOST_TRACE_PATH if set (for Docker), otherwise uses local path
49
+ * Get the output directory for trace files
42
50
  * @param {string} workflowName - The name of the workflow
43
- * @returns {string} The path to report to users/API
51
+ * @param {boolean} useContainerPath - If true, uses container path for writing; otherwise uses host path for reporting
52
+ * @returns {string} The output directory path
44
53
  */
45
- const getReportOutputDir = workflowName => {
46
- const basePath = process.env.HOST_TRACE_PATH || join( process.cwd(), 'logs' );
54
+ const getOutputDir = ( workflowName, useContainerPath = false ) => {
55
+ const basePath = useContainerPath ? getContainerBasePath() : getBasePath();
47
56
  return join( basePath, 'runs', workflowName );
48
57
  };
49
58
 
@@ -66,8 +75,8 @@ export const exec = ( { entry, executionContext } ) => {
66
75
  const { workflowId, workflowName, startTime } = executionContext;
67
76
  const content = buildTraceTree( accumulate( { entry, executionContext } ) );
68
77
 
69
- // Always use local path for writing files
70
- const dir = getLocalOutputDir( workflowName );
78
+ // Use container path for writing files (true flag)
79
+ const dir = getOutputDir( workflowName, true );
71
80
  const path = join( dir, buildOutputFileName( { startTime, workflowId } ) );
72
81
 
73
82
  mkdirSync( dir, { recursive: true } );
@@ -83,6 +92,5 @@ export const exec = ( { entry, executionContext } ) => {
83
92
  * @returns {string} The absolute path where the trace will be saved
84
93
  */
85
94
  export const getDestination = ( { startTime, workflowId, workflowName } ) => {
86
- // Use report path for reporting to users/API
87
- return join( getReportOutputDir( workflowName ), buildOutputFileName( { workflowId, startTime } ) );
95
+ return join( getOutputDir( workflowName ), buildOutputFileName( { workflowId, startTime } ) );
88
96
  };
@@ -40,8 +40,7 @@ describe( 'tracing/processors/local', () => {
40
40
 
41
41
  init();
42
42
 
43
- // Should create temp dir under process.cwd()/logs, not module-relative
44
- expect( mkdirSyncMock ).toHaveBeenCalledWith( expect.stringMatching( /logs\/temp\/traces$/ ), { recursive: true } );
43
+ expect( mkdirSyncMock ).toHaveBeenCalledWith( expect.stringMatching( /temp\/traces$/ ), { recursive: true } );
45
44
  expect( rmSyncMock ).toHaveBeenCalledTimes( 1 );
46
45
  } );
47
46