@redaksjon/protokoll-engine 0.1.15 → 0.1.16-dev.20260316055955.5771fbb
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/dist/agentic/executor.d.ts.map +1 -1
- package/dist/index19.js +22 -2
- package/dist/index19.js.map +1 -1
- package/dist/index22.js +1 -1
- package/dist/index26.js +3 -2
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +5 -5
- package/dist/index31.js +1 -1
- package/dist/index32.js +1 -1
- package/dist/index33.js +2 -2
- package/dist/index34.js +3 -3
- package/dist/index35.js +5 -5
- package/dist/index36.js +2 -2
- package/dist/index37.js +1 -1
- package/dist/index39.js +1 -1
- package/dist/index42.js +1 -1
- package/dist/index43.js +1 -1
- package/dist/index47.js +4 -45
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +45 -47
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +46 -34
- package/dist/index49.js.map +1 -1
- package/dist/index50.js +35 -280
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +259 -138
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +143 -61
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +73 -70
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +72 -145
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +31 -106
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +198 -21
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +29 -25
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +26 -18
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +34 -5
- package/dist/index59.js.map +1 -1
- package/dist/index60.js +148 -5
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +4 -4
- package/dist/index62.js +5 -148
- package/dist/index62.js.map +1 -1
- package/dist/reasoning/client.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index27.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ToolRegistry } from '@kjerneverk/riotprompt';
|
|
2
|
-
import { create as create$1 } from './
|
|
3
|
-
import { create as create$2 } from './
|
|
4
|
-
import { create as create$3 } from './
|
|
5
|
-
import { create as create$4 } from './
|
|
6
|
-
import { create as create$5 } from './
|
|
2
|
+
import { create as create$1 } from './index55.js';
|
|
3
|
+
import { create as create$2 } from './index56.js';
|
|
4
|
+
import { create as create$3 } from './index57.js';
|
|
5
|
+
import { create as create$4 } from './index58.js';
|
|
6
|
+
import { create as create$5 } from './index59.js';
|
|
7
7
|
|
|
8
8
|
const toRiotTool = (tool, category) => ({
|
|
9
9
|
name: tool.name,
|
package/dist/index31.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as readline from 'readline';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
import { getLogger } from './
|
|
4
|
+
import { getLogger } from './index48.js';
|
|
5
5
|
|
|
6
6
|
const print = console.log;
|
|
7
7
|
const createReadlineInterface = () => {
|
package/dist/index32.js
CHANGED
package/dist/index33.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as Context from '@redaksjon/context';
|
|
2
2
|
import { create as create$1 } from './index6.js';
|
|
3
|
-
import { create as create$2 } from './
|
|
3
|
+
import { create as create$2 } from './index47.js';
|
|
4
4
|
import { create as create$3 } from './index11.js';
|
|
5
5
|
import { create as create$4 } from './index3.js';
|
|
6
6
|
import { create as create$5 } from './index2.js';
|
|
7
7
|
import { create as create$8 } from './index5.js';
|
|
8
8
|
import { create as create$7 } from './index37.js';
|
|
9
9
|
import { create as create$6 } from './index35.js';
|
|
10
|
-
import { getLogger } from './
|
|
10
|
+
import { getLogger } from './index48.js';
|
|
11
11
|
import { randomUUID } from 'node:crypto';
|
|
12
12
|
import * as path from 'node:path';
|
|
13
13
|
import { extractTagsFromSignals, createRoutingMetadata } from './index15.js';
|
package/dist/index34.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getLogger } from './
|
|
1
|
+
import { getLogger } from './index48.js';
|
|
2
2
|
import { create as create$1 } from './index13.js';
|
|
3
3
|
import { create as create$2 } from './index14.js';
|
|
4
|
-
import { transcribeAudio } from './
|
|
5
|
-
import { stringifyJSON } from './
|
|
4
|
+
import { transcribeAudio } from './index49.js';
|
|
5
|
+
import { stringifyJSON } from './index50.js';
|
|
6
6
|
import path__default from 'node:path';
|
|
7
7
|
import { create as create$4 } from './index5.js';
|
|
8
8
|
import { create as create$3 } from './index2.js';
|
package/dist/index35.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getLogger } from './
|
|
1
|
+
import { getLogger } from './index48.js';
|
|
2
2
|
import { create as create$1 } from './index13.js';
|
|
3
|
-
import { create as create$2 } from './
|
|
4
|
-
import { create as create$3 } from './
|
|
5
|
-
import { create as create$4 } from './
|
|
6
|
-
import { stringifyJSON } from './
|
|
3
|
+
import { create as create$2 } from './index51.js';
|
|
4
|
+
import { create as create$3 } from './index52.js';
|
|
5
|
+
import { create as create$4 } from './index53.js';
|
|
6
|
+
import { stringifyJSON } from './index50.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
|
|
9
9
|
const create = (config, contextInstance) => {
|
package/dist/index36.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getLogger } from './
|
|
1
|
+
import { getLogger } from './index48.js';
|
|
2
2
|
import { create as create$3 } from './index14.js';
|
|
3
3
|
import { create as create$1 } from './index13.js';
|
|
4
|
-
import { create as create$2 } from './
|
|
4
|
+
import { create as create$2 } from './index54.js';
|
|
5
5
|
import { DEFAULT_INTERMEDIATE_DIRECTORY } from './index18.js';
|
|
6
6
|
import path__default from 'node:path';
|
|
7
7
|
|
package/dist/index37.js
CHANGED
package/dist/index39.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { getLogger } from './
|
|
3
|
+
import { getLogger } from './index48.js';
|
|
4
4
|
import { extractTimestampFromFilename, slugifyTitle } from './index38.js';
|
|
5
5
|
import { PklTranscript } from '@redaksjon/protokoll-format';
|
|
6
6
|
import { ensurePklExtension } from './index40.js';
|
package/dist/index42.js
CHANGED
package/dist/index43.js
CHANGED
package/dist/index47.js
CHANGED
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS, PROGRAM_NAME } from './index18.js';
|
|
1
|
+
import { create as create$1 } from './index60.js';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
winston.format.timestamp({ format: DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS }),
|
|
7
|
-
winston.format.errors({ stack: true }),
|
|
8
|
-
winston.format.splat(),
|
|
9
|
-
winston.format.json()
|
|
10
|
-
);
|
|
11
|
-
let transports = [
|
|
12
|
-
new winston.transports.Console({
|
|
13
|
-
format: winston.format.combine(
|
|
14
|
-
winston.format.colorize(),
|
|
15
|
-
winston.format.printf(({ timestamp, level: level2, message, ...meta }) => {
|
|
16
|
-
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : "";
|
|
17
|
-
return `${timestamp} ${level2}: ${message}${metaStr}`;
|
|
18
|
-
})
|
|
19
|
-
)
|
|
20
|
-
})
|
|
21
|
-
];
|
|
22
|
-
if (level === "info") {
|
|
23
|
-
format = winston.format.combine(
|
|
24
|
-
winston.format.errors({ stack: true }),
|
|
25
|
-
winston.format.splat()
|
|
26
|
-
);
|
|
27
|
-
transports = [
|
|
28
|
-
new winston.transports.Console({
|
|
29
|
-
format: winston.format.combine(
|
|
30
|
-
winston.format.colorize(),
|
|
31
|
-
winston.format.printf(({ level: level2, message }) => {
|
|
32
|
-
return `${level2}: ${message}`;
|
|
33
|
-
})
|
|
34
|
-
)
|
|
35
|
-
})
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
return winston.createLogger({
|
|
39
|
-
level,
|
|
40
|
-
format,
|
|
41
|
-
defaultMeta: { service: PROGRAM_NAME },
|
|
42
|
-
transports
|
|
43
|
-
});
|
|
3
|
+
const create = (config) => {
|
|
4
|
+
return create$1(config);
|
|
44
5
|
};
|
|
45
|
-
let logger = createLogger();
|
|
46
|
-
const getLogger = () => logger;
|
|
47
6
|
|
|
48
|
-
export {
|
|
7
|
+
export { create };
|
|
49
8
|
//# sourceMappingURL=index47.js.map
|
package/dist/index47.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index47.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index47.js","sources":["../src/out/index.ts"],"sourcesContent":["/**\n * Output Management System\n *\n * Main entry point for the output management system. Handles intermediate\n * files and final output destinations.\n */\n\nimport { OutputConfig, OutputPaths, IntermediateFiles, RawTranscriptData } from './types';\nimport * as Manager from './manager';\nimport * as Metadata from '../util/metadata';\n\nexport interface OutputInstance {\n createOutputPaths(\n audioFile: string,\n routedDestination: string,\n hash: string,\n date: Date\n ): OutputPaths;\n ensureDirectories(paths: OutputPaths): Promise<void>;\n writeIntermediate(\n paths: OutputPaths,\n type: keyof IntermediateFiles,\n content: unknown\n ): Promise<string>;\n /**\n * Write the raw Whisper transcript to the .transcript/ directory alongside final output.\n * This enables compare and reanalyze workflows.\n */\n writeRawTranscript(paths: OutputPaths, data: RawTranscriptData): Promise<string>;\n writeTranscript(paths: OutputPaths, content: string, metadata?: Metadata.TranscriptMetadata): Promise<string>;\n /**\n * Read a previously stored raw transcript from the .transcript/ directory.\n * Returns null if no raw transcript exists.\n */\n readRawTranscript(finalOutputPath: string): Promise<RawTranscriptData | null>;\n cleanIntermediates(paths: OutputPaths): Promise<void>;\n}\n\nexport const create = (config: OutputConfig): OutputInstance => {\n return Manager.create(config);\n};\n\nexport const DEFAULT_OUTPUT_CONFIG: OutputConfig = {\n intermediateDir: './output/protokoll',\n keepIntermediates: true,\n timestampFormat: 'YYMMDD-HHmm',\n};\n\n// Re-export types\nexport * from './types';\n"],"names":["Manager.create"],"mappings":";;AAsCO,MAAM,MAAA,GAAS,CAAC,MAAA,KAAyC;AAC5D,EAAA,OAAOA,SAAe,MAAM,CAAA;AAChC;;;;"}
|
package/dist/index48.js
CHANGED
|
@@ -1,51 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { getLogger } from './index47.js';
|
|
4
|
-
import { DEFAULT_TRANSCRIPTION_MODEL } from './index18.js';
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import { DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS, PROGRAM_NAME } from './index18.js';
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const createLogger = (level = "info") => {
|
|
5
|
+
let format = winston.format.combine(
|
|
6
|
+
winston.format.timestamp({ format: DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS }),
|
|
7
|
+
winston.format.errors({ stack: true }),
|
|
8
|
+
winston.format.splat(),
|
|
9
|
+
winston.format.json()
|
|
10
|
+
);
|
|
11
|
+
let transports = [
|
|
12
|
+
new winston.transports.Console({
|
|
13
|
+
format: winston.format.combine(
|
|
14
|
+
winston.format.colorize(),
|
|
15
|
+
winston.format.printf(({ timestamp, level: level2, message, ...meta }) => {
|
|
16
|
+
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : "";
|
|
17
|
+
return `${timestamp} ${level2}: ${message}${metaStr}`;
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
];
|
|
22
|
+
if (level === "info") {
|
|
23
|
+
format = winston.format.combine(
|
|
24
|
+
winston.format.errors({ stack: true }),
|
|
25
|
+
winston.format.splat()
|
|
26
|
+
);
|
|
27
|
+
transports = [
|
|
28
|
+
new winston.transports.Console({
|
|
29
|
+
format: winston.format.combine(
|
|
30
|
+
winston.format.colorize(),
|
|
31
|
+
winston.format.printf(({ level: level2, message }) => {
|
|
32
|
+
return `${level2}: ${message}`;
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
];
|
|
10
37
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const openai = new OpenAI({
|
|
21
|
-
apiKey
|
|
22
|
-
});
|
|
23
|
-
const model = options.model || DEFAULT_TRANSCRIPTION_MODEL;
|
|
24
|
-
const fileName = filePath.split("/").pop() || filePath;
|
|
25
|
-
logger.debug("Transcribing: %s (full path: %s)", fileName, filePath);
|
|
26
|
-
const startTime = Date.now();
|
|
27
|
-
const audioStream = await storage$1.readStream(filePath);
|
|
28
|
-
const transcription = await openai.audio.transcriptions.create({
|
|
29
|
-
model,
|
|
30
|
-
file: audioStream,
|
|
31
|
-
response_format: "json"
|
|
32
|
-
});
|
|
33
|
-
if (!transcription) {
|
|
34
|
-
throw new OpenAIError("No transcription received from OpenAI");
|
|
35
|
-
}
|
|
36
|
-
const duration = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
37
|
-
logger.info("%s (%ss, %d chars)", model, duration, transcription.text?.length || 0);
|
|
38
|
-
if (options.debug && options.debugFile) {
|
|
39
|
-
await storage$1.writeFile(options.debugFile, JSON.stringify(transcription, null, 2), "utf8");
|
|
40
|
-
logger.debug("Wrote debug file to %s", options.debugFile);
|
|
41
|
-
}
|
|
42
|
-
logger.debug("Received transcription from OpenAI: %s", transcription);
|
|
43
|
-
return transcription;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error("Error transcribing audio file: %s %s", error.message, error.stack);
|
|
46
|
-
throw new OpenAIError(`Failed to transcribe audio: ${error.message}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
38
|
+
return winston.createLogger({
|
|
39
|
+
level,
|
|
40
|
+
format,
|
|
41
|
+
defaultMeta: { service: PROGRAM_NAME },
|
|
42
|
+
transports
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
let logger = createLogger();
|
|
46
|
+
const getLogger = () => logger;
|
|
49
47
|
|
|
50
|
-
export {
|
|
48
|
+
export { getLogger };
|
|
51
49
|
//# sourceMappingURL=index48.js.map
|
package/dist/index48.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index48.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index48.js","sources":["../src/logging.ts"],"sourcesContent":["import winston from 'winston';\nimport { DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS, PROGRAM_NAME } from './constants';\n\nexport interface LogContext {\n [key: string]: any;\n}\n\nconst createLogger = (level: string = 'info') => {\n\n let format = winston.format.combine(\n winston.format.timestamp({ format: DATE_FORMAT_YEAR_MONTH_DAY_HOURS_MINUTES_SECONDS }),\n winston.format.errors({ stack: true }),\n winston.format.splat(),\n winston.format.json()\n );\n\n let transports = [\n new winston.transports.Console({\n format: winston.format.combine(\n winston.format.colorize(),\n winston.format.printf(({ timestamp, level, message, ...meta }) => {\n const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : '';\n return `${timestamp} ${level}: ${message}${metaStr}`;\n })\n )\n })\n ];\n\n if (level === 'info') {\n format = winston.format.combine(\n winston.format.errors({ stack: true }),\n winston.format.splat(),\n );\n\n transports = [\n new winston.transports.Console({\n format: winston.format.combine(\n winston.format.colorize(),\n winston.format.printf(({ level, message }) => {\n return `${level}: ${message}`;\n })\n )\n })\n ];\n }\n\n return winston.createLogger({\n level,\n format,\n defaultMeta: { service: PROGRAM_NAME },\n transports,\n });\n};\n\nlet logger = createLogger();\n\nexport const setLogLevel = (level: string) => {\n logger = createLogger(level);\n};\n\nexport const getLogger = () => logger; "],"names":["level"],"mappings":";;;AAOA,MAAM,YAAA,GAAe,CAAC,KAAA,GAAgB,MAAA,KAAW;AAE7C,EAAA,IAAI,MAAA,GAAS,QA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A;AAAA,UACnB,OAAA,CAAQ,OAAO,QAAA,EAAS;AAAA,UACxB,OAAA,CAAQ,OAAO,MAAA,CAAO,CAAC,EAAE,KAAA,EAAAA,MAAAA,EAAO,SAAQ,KAAM;AAC1C,YAAA,OAAO,CAAA,EAAGA,MAAK,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,UAC/B,CAAC;AAAA;AACL,OACH;AAAA,KACL;AAAA,EACJ;AAEA,EAAA,OAAO,QAAQ,YAAA,CAAa;AAAA,IACxB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAA,EAAa,EAAE,OAAA,EAAS,YAAA,EAAa;AAAA,IACrC;AAAA,GACH,CAAA;AACL,CAAA;AAEA,IAAI,SAAS,YAAA,EAAa;AAMnB,MAAM,YAAY,MAAM;;;;"}
|
package/dist/index49.js
CHANGED
|
@@ -1,39 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { OpenAI } from 'openai';
|
|
2
|
+
import { create } from './index13.js';
|
|
3
|
+
import { getLogger } from './index48.js';
|
|
4
|
+
import { DEFAULT_TRANSCRIPTION_MODEL } from './index18.js';
|
|
5
|
+
|
|
6
|
+
class OpenAIError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "OpenAIError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function transcribeAudio(filePath, options = {}) {
|
|
13
|
+
const logger = getLogger();
|
|
14
|
+
const storage$1 = create({ log: logger.debug });
|
|
15
|
+
try {
|
|
16
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
throw new OpenAIError("OPENAI_API_KEY environment variable is not set");
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut));
|
|
31
|
-
}
|
|
20
|
+
const openai = new OpenAI({
|
|
21
|
+
apiKey
|
|
22
|
+
});
|
|
23
|
+
const model = options.model || DEFAULT_TRANSCRIPTION_MODEL;
|
|
24
|
+
const fileName = filePath.split("/").pop() || filePath;
|
|
25
|
+
logger.debug("Transcribing: %s (full path: %s)", fileName, filePath);
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
const audioStream = await storage$1.readStream(filePath);
|
|
28
|
+
const transcription = await openai.audio.transcriptions.create({
|
|
29
|
+
model,
|
|
30
|
+
file: audioStream,
|
|
31
|
+
response_format: "json"
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
if (!transcription) {
|
|
34
|
+
throw new OpenAIError("No transcription received from OpenAI");
|
|
35
|
+
}
|
|
36
|
+
const duration = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
37
|
+
logger.info("%s (%ss, %d chars)", model, duration, transcription.text?.length || 0);
|
|
38
|
+
if (options.debug && options.debugFile) {
|
|
39
|
+
await storage$1.writeFile(options.debugFile, JSON.stringify(transcription, null, 2), "utf8");
|
|
40
|
+
logger.debug("Wrote debug file to %s", options.debugFile);
|
|
41
|
+
}
|
|
42
|
+
logger.debug("Received transcription from OpenAI: %s", transcription);
|
|
43
|
+
return transcription;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error("Error transcribing audio file: %s %s", error.message, error.stack);
|
|
46
|
+
throw new OpenAIError(`Failed to transcribe audio: ${error.message}`);
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
};
|
|
48
|
+
}
|
|
37
49
|
|
|
38
|
-
export {
|
|
50
|
+
export { OpenAIError, transcribeAudio };
|
|
39
51
|
//# sourceMappingURL=index49.js.map
|
package/dist/index49.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index49.js","sources":["../src/util/
|
|
1
|
+
{"version":3,"file":"index49.js","sources":["../src/util/openai.ts"],"sourcesContent":["import { OpenAI } from 'openai';\nimport { ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam } from 'openai/resources/chat/completions';\nimport * as Storage from '@/util/storage';\nimport { getLogger } from '@/logging';\nimport { DEFAULT_MODEL, DEFAULT_TRANSCRIPTION_MODEL } from '@/constants';\n\nexport interface Transcription {\n text: string;\n}\n\nexport class OpenAIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'OpenAIError';\n }\n}\n\n\nexport async function createCompletion(messages: ChatCompletionMessageParam[], options: { responseFormat?: any, model?: string, reasoningLevel?: 'none' | 'low' | 'medium' | 'high', maxTokens?: number, debug?: boolean, debugFile?: string, reason?: string } = {}): Promise<string | any> {\n const logger = getLogger();\n const storage = Storage.create({ log: logger.debug });\n try {\n const apiKey = process.env.OPENAI_API_KEY;\n if (!apiKey) {\n throw new OpenAIError('OPENAI_API_KEY environment variable is not set');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n });\n\n const model = options.model || DEFAULT_MODEL;\n \n // Check if model supports reasoning_effort\n const supportsReasoning = model.includes('gpt-5') || \n model.includes('o1') || model.includes('o3');\n const isReasoningCall = supportsReasoning && options.reasoningLevel && options.reasoningLevel !== 'none';\n \n logger.debug('Sending prompt to OpenAI: %j', messages);\n\n const startTime = Date.now();\n \n const requestParams: Record<string, unknown> = {\n model,\n messages,\n max_completion_tokens: options.maxTokens || 10000,\n response_format: options.responseFormat,\n };\n \n if (isReasoningCall) {\n requestParams.reasoning_effort = options.reasoningLevel;\n logger.debug('Using reasoning_effort: %s', options.reasoningLevel);\n }\n \n const completion = await openai.chat.completions.create(\n requestParams as unknown as ChatCompletionCreateParamsNonStreaming\n );\n const duration = ((Date.now() - startTime) / 1000).toFixed(1);\n\n // Log token usage with reason if provided\n const usage = completion.usage;\n const reasonSuffix = options.reason ? ` - ${options.reason}` : '';\n if (usage) {\n logger.info('%s (%ss, %d→%d tokens)%s', \n model, duration, usage.prompt_tokens, usage.completion_tokens, reasonSuffix);\n } else {\n logger.info('%s (%ss)%s', model, duration, reasonSuffix);\n }\n\n if (options.debug && options.debugFile) {\n await storage.writeFile(options.debugFile, JSON.stringify(completion, null, 2), 'utf8');\n logger.debug('Wrote debug file to %s', options.debugFile);\n }\n\n const response = completion.choices[0]?.message?.content?.trim();\n if (!response) {\n // Log the full completion object to help debug\n logger.error('Empty response from OpenAI. Full completion object: %j', completion);\n throw new OpenAIError('No response received from OpenAI');\n }\n\n logger.debug('Received response from OpenAI: %s', response);\n if (options.responseFormat) {\n return JSON.parse(response);\n } else {\n return response;\n }\n\n } catch (error: any) {\n logger.error('Error calling OpenAI API: %s %s', error.message, error.stack);\n throw new OpenAIError(`Failed to create completion: ${error.message}`);\n }\n}\n\nexport async function transcribeAudio(filePath: string, options: { model?: string, debug?: boolean, debugFile?: string } = {}): Promise<Transcription> {\n const logger = getLogger();\n const storage = Storage.create({ log: logger.debug });\n try {\n const apiKey = process.env.OPENAI_API_KEY;\n if (!apiKey) {\n throw new OpenAIError('OPENAI_API_KEY environment variable is not set');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n });\n\n const model = options.model || DEFAULT_TRANSCRIPTION_MODEL;\n const fileName = filePath.split('/').pop() || filePath;\n logger.debug('Transcribing: %s (full path: %s)', fileName, filePath);\n\n const startTime = Date.now();\n const audioStream = await storage.readStream(filePath);\n const transcription = await openai.audio.transcriptions.create({\n model,\n file: audioStream,\n response_format: \"json\",\n });\n \n if (!transcription) {\n throw new OpenAIError('No transcription received from OpenAI');\n }\n \n const duration = ((Date.now() - startTime) / 1000).toFixed(1);\n logger.info('%s (%ss, %d chars)', model, duration, transcription.text?.length || 0);\n\n if (options.debug && options.debugFile) {\n await storage.writeFile(options.debugFile, JSON.stringify(transcription, null, 2), 'utf8');\n logger.debug('Wrote debug file to %s', options.debugFile);\n }\n\n logger.debug('Received transcription from OpenAI: %s', transcription);\n return transcription;\n\n } catch (error: any) {\n logger.error('Error transcribing audio file: %s %s', error.message, error.stack);\n throw new OpenAIError(`Failed to transcribe audio: ${error.message}`);\n }\n}\n"],"names":["storage","Storage.create"],"mappings":";;;;;AAUO,MAAM,oBAAoB,KAAA,CAAM;AAAA,EACnC,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EAChB;AACJ;AA+EA,eAAsB,eAAA,CAAgB,QAAA,EAAkB,OAAA,GAAmE,EAAC,EAA2B;AACnJ,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAMA,YAAUC,MAAQ,CAAO,EAAE,GAAA,EAAK,MAAA,CAAO,OAAO,CAAA;AACpD,EAAA,IAAI;AACA,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,cAAA;AAC3B,IAAA,IAAI,CAAC,MAAA,EAAQ;AACT,MAAA,MAAM,IAAI,YAAY,gDAAgD,CAAA;AAAA,IAC1E;AAEA,IAAA,MAAM,MAAA,GAAS,IAAI,MAAA,CAAO;AAAA,MACtB;AAAA,KACH,CAAA;AAED,IAAA,MAAM,KAAA,GAAQ,QAAQ,KAAA,IAAS,2BAAA;AAC/B,IAAA,MAAM,WAAW,QAAA,CAAS,KAAA,CAAM,GAAG,CAAA,CAAE,KAAI,IAAK,QAAA;AAC9C,IAAA,MAAA,CAAO,KAAA,CAAM,kCAAA,EAAoC,QAAA,EAAU,QAAQ,CAAA;AAEnE,IAAA,MAAM,SAAA,GAAY,KAAK,GAAA,EAAI;AAC3B,IAAA,MAAM,WAAA,GAAc,MAAMD,SAAA,CAAQ,UAAA,CAAW,QAAQ,CAAA;AACrD,IAAA,MAAM,aAAA,GAAgB,MAAM,MAAA,CAAO,KAAA,CA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