@redaksjon/protokoll-engine 0.1.7 → 0.1.8-dev.20260220204442.6592aed

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/index33.js CHANGED
@@ -1,6 +1,6 @@
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 './index53.js';
3
+ import { create as create$2 } from './index59.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';
package/dist/index34.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getLogger } from './index47.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 './index54.js';
5
- import { stringifyJSON } from './index55.js';
4
+ import { transcribeAudio } from './index53.js';
5
+ import { stringifyJSON } from './index54.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
1
  import { getLogger } from './index47.js';
2
2
  import { create as create$1 } from './index13.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 { stringifyJSON } from './index55.js';
3
+ import { create as create$2 } from './index55.js';
4
+ import { create as create$3 } from './index56.js';
5
+ import { create as create$4 } from './index57.js';
6
+ import { stringifyJSON } from './index54.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
1
  import { getLogger } from './index47.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 './index59.js';
4
+ import { create as create$2 } from './index58.js';
5
5
  import { DEFAULT_INTERMEDIATE_DIRECTORY } from './index18.js';
6
6
  import path__default from 'node:path';
7
7
 
package/dist/index53.js CHANGED
@@ -1,8 +1,51 @@
1
- import { create as create$1 } from './index60.js';
1
+ import { OpenAI } from 'openai';
2
+ import { create } from './index13.js';
3
+ import { getLogger } from './index47.js';
4
+ import { DEFAULT_TRANSCRIPTION_MODEL } from './index18.js';
2
5
 
3
- const create = (config) => {
4
- return create$1(config);
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");
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
+ }
6
49
 
7
- export { create };
50
+ export { OpenAIError, transcribeAudio };
8
51
  //# sourceMappingURL=index53.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index53.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;;;;"}
1
+ {"version":3,"file":"index53.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,I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O,UAAU,aAAA,CAAc,IAAA,EAAM,UAAU,CAAC,CAAA;AAElF,IAAA,IAAI,OAAA,CAAQ,KAAA,IAAS,OAAA,CAAQ,SAAA,EAAW;AACpC,MAAA,MAAMA,SAAA,CAAQ,SAAA,CAAU,OAAA,CAAQ,SAAA,EAAW,IAAA,CAAK,UAAU,aAAA,EAAe,IAAA,EAAM,CAAC,CAAA,EAAG,MAAM,CAAA;AACzF,MAAA,MAAA,CAAO,KAAA,CAAM,wBAAA,EAA0B,OAAA,CAAQ,SAAS,CAAA;AAAA,IAC5D;AAEA,IAAA,MAAA,CAAO,KAAA,CAAM,0CAA0C,aAAa,CAAA;AACpE,IAAA,OAAO,aAAA;AAAA,EAEX,SAAS,KAAA,EAAY;AACjB,IAAA,MAAA,CAAO,KAAA,CAAM,sCAAA,EAAwC,KAAA,CAAM,OAAA,EAAS,MAAM,KAAK,CAAA;AAC/E,IAAA,MAAM,IAAI,WAAA,CAAY,CAAA,4BAAA,EAA+B,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,EACxE;AACJ;;;;"}
package/dist/index54.js CHANGED
@@ -1,51 +1,39 @@
1
- import { OpenAI } from 'openai';
2
- import { create } from './index13.js';
3
- import { getLogger } from './index47.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");
1
+ const stringifyJSON = function(obj) {
2
+ const arrOfKeyVals = [];
3
+ const arrVals = [];
4
+ let objKeys = [];
5
+ if (typeof obj === "number" || typeof obj === "boolean" || obj === null)
6
+ return "" + obj;
7
+ else if (typeof obj === "string")
8
+ return '"' + obj + '"';
9
+ else if (Array.isArray(obj)) {
10
+ if (obj[0] === void 0)
11
+ return "[]";
12
+ else {
13
+ obj.forEach(function(el) {
14
+ arrVals.push(stringifyJSON(el));
15
+ });
16
+ return "[" + arrVals + "]";
19
17
  }
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"
18
+ } else if (obj instanceof Object) {
19
+ objKeys = Object.keys(obj);
20
+ objKeys.forEach(function(key) {
21
+ const keyOut = '"' + key + '":';
22
+ const keyValOut = obj[key];
23
+ if (keyValOut instanceof Function || keyValOut === void 0)
24
+ arrOfKeyVals.push("");
25
+ else if (typeof keyValOut === "string")
26
+ arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
27
+ else if (typeof keyValOut === "boolean" || typeof keyValOut === "number" || keyValOut === null)
28
+ arrOfKeyVals.push(keyOut + keyValOut);
29
+ else if (keyValOut instanceof Object) {
30
+ arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut));
31
+ }
32
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}`);
33
+ return "{" + arrOfKeyVals + "}";
47
34
  }
48
- }
35
+ return "";
36
+ };
49
37
 
50
- export { OpenAIError, transcribeAudio };
38
+ export { stringifyJSON };
51
39
  //# sourceMappingURL=index54.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index54.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,CAAM,eAAe,MAAA,CAAO;AAAA,MAC3D,KAAA;AAAA,MACA,IAAA,EAAM,WAAA;AAAA,MACN,eAAA,EAAiB;AAAA,KACpB,CAAA;AAED,IAAA,IAAI,CAAC,aAAA,EAAe;AAChB,MAAA,MAAM,IAAI,YAAY,uCAAuC,CAAA;AAAA,IACjE;AAEA,IAAA,MAAM,aAAa,IAAA,CAAK,GAAA,KAAQ,SAAA,IAAa,GAAA,EAAM,QAAQ,CAAC,CAAA;AAC5D,IAAA,MAAA,CAAO,KAAK,oBAAA,EAAsB,KAAA,EAAO,UAAU,aAAA,CAAc,IAAA,EAAM,UAAU,CAAC,CAAA;AAElF,IAAA,IAAI,OAAA,CAAQ,KAAA,IAAS,OAAA,CAAQ,SAAA,EAAW;AACpC,MAAA,MAAMA,SAAA,CAAQ,SAAA,CAAU,OAAA,CAAQ,SAAA,EAAW,IAAA,CAAK,UAAU,aAAA,EAAe,IAAA,EAAM,CAAC,CAAA,EAAG,MAAM,CAAA;AACzF,MAAA,MAAA,CAAO,KAAA,CAAM,wBAAA,EAA0B,OAAA,CAAQ,SAAS,CAAA;AAAA,IAC5D;AAEA,IAAA,MAAA,CAAO,KAAA,CAAM,0CAA0C,aAAa,CAAA;AACpE,IAAA,OAAO,aAAA;AAAA,EAEX,SAAS,KAAA,EAAY;AACjB,IAAA,MAAA,CAAO,KAAA,CAAM,sCAAA,EAAwC,KAAA,CAAM,OAAA,EAAS,MAAM,KAAK,CAAA;AAC/E,IAAA,MAAM,IAAI,WAAA,CAAY,CAAA,4BAAA,EAA+B,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,EACxE;AACJ;;;;"}
1
+ {"version":3,"file":"index54.js","sources":["../src/util/general.ts"],"sourcesContent":["// Utility function for deep merging two objects.\nexport function deepMerge(target: any, source: any): any {\n for (const key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n // Block prototype-polluting keys\n if (key === '__proto__' || key === 'constructor') {\n continue;\n }\n if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {\n if (!target[key]) {\n target[key] = {};\n }\n deepMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n }\n return target;\n}\n\n//Recursive implementation of jSON.stringify;\nexport const stringifyJSON = function (obj: any): string {\n\n const arrOfKeyVals: string[] = [];\n const arrVals: string[] = [];\n let objKeys: string[] = [];\n\n /*********CHECK FOR PRIMITIVE TYPES**********/\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)\n return '' + obj;\n else if (typeof obj === 'string')\n return '\"' + obj + '\"';\n\n /*********CHECK FOR ARRAY**********/\n else if (Array.isArray(obj)) {\n //check for empty array\n if (obj[0] === undefined)\n return '[]';\n else {\n obj.forEach(function (el) {\n arrVals.push(stringifyJSON(el));\n });\n return '[' + arrVals + ']';\n }\n }\n /*********CHECK FOR OBJECT**********/\n else if (obj instanceof Object) {\n //get object keys\n objKeys = Object.keys(obj);\n //set key output;\n objKeys.forEach(function (key) {\n const keyOut = '\"' + key + '\":';\n const keyValOut = obj[key];\n //skip functions and undefined properties\n if (keyValOut instanceof Function || keyValOut === undefined)\n arrOfKeyVals.push('');\n else if (typeof keyValOut === 'string')\n arrOfKeyVals.push(keyOut + '\"' + keyValOut + '\"');\n else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)\n arrOfKeyVals.push(keyOut + keyValOut);\n //check for nested objects, call recursively until no more objects\n else if (keyValOut instanceof Object) {\n arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut));\n }\n });\n return '{' + arrOfKeyVals + '}';\n }\n return '';\n};"],"names":[],"mappings":"AAsBO,MAAM,aAAA,GAAgB,SAAU,GAAA,EAAkB;AAErD,EAAA,MAAM,eAAyB,EAAC;AAChC,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,UAAoB,EAAC;AAGzB,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,OAAO,GAAA,KAAQ,aAAa,GAAA,KAAQ,IAAA;AAC/D,IAAA,OA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ACJ,CAAC,CAAA;AACD,IAAA,OAAO,MAAM,YAAA,GAAe,GAAA;AAAA,EAChC;AACA,EAAA,OAAO,EAAA;AACX;;;;"}
package/dist/index55.js CHANGED
@@ -1,39 +1,284 @@
1
- const stringifyJSON = function(obj) {
2
- const arrOfKeyVals = [];
3
- const arrVals = [];
4
- let objKeys = [];
5
- if (typeof obj === "number" || typeof obj === "boolean" || obj === null)
6
- return "" + obj;
7
- else if (typeof obj === "string")
8
- return '"' + obj + '"';
9
- else if (Array.isArray(obj)) {
10
- if (obj[0] === void 0)
11
- return "[]";
12
- else {
13
- obj.forEach(function(el) {
14
- arrVals.push(stringifyJSON(el));
15
- });
16
- return "[" + arrVals + "]";
17
- }
18
- } else if (obj instanceof Object) {
19
- objKeys = Object.keys(obj);
20
- objKeys.forEach(function(key) {
21
- const keyOut = '"' + key + '":';
22
- const keyValOut = obj[key];
23
- if (keyValOut instanceof Function || keyValOut === void 0)
24
- arrOfKeyVals.push("");
25
- else if (typeof keyValOut === "string")
26
- arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
27
- else if (typeof keyValOut === "boolean" || typeof keyValOut === "number" || keyValOut === null)
28
- arrOfKeyVals.push(keyOut + keyValOut);
29
- else if (keyValOut instanceof Object) {
30
- arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut));
1
+ import { getLogger } from './index47.js';
2
+ import * as yaml from 'js-yaml';
3
+ import * as fs from 'fs/promises';
4
+ import * as path from 'node:path';
5
+ import * as os from 'node:os';
6
+
7
+ const create = (config) => {
8
+ const logger = getLogger();
9
+ const database = {
10
+ mappings: [],
11
+ tier1: [],
12
+ tier2: /* @__PURE__ */ new Map(),
13
+ tier3: [],
14
+ collisions: /* @__PURE__ */ new Map(),
15
+ commonTerms: new Set(config?.commonTerms ?? DEFAULT_COMMON_TERMS),
16
+ genericTerms: new Set(config?.genericTerms ?? DEFAULT_GENERIC_TERMS)
17
+ };
18
+ const findProtokolDirectories = async () => {
19
+ if (config?.protokollContextPaths) {
20
+ return config.protokollContextPaths;
21
+ }
22
+ const homeDir = os.homedir();
23
+ const primaryPath = path.join(homeDir, ".protokoll", "context");
24
+ const dirs = [];
25
+ try {
26
+ await fs.access(primaryPath);
27
+ dirs.push(primaryPath);
28
+ logger.debug(`Found protokoll context at: ${primaryPath}`);
29
+ } catch {
30
+ logger.debug(`No protokoll context found at: ${primaryPath}`);
31
+ }
32
+ return dirs;
33
+ };
34
+ const loadProjectsFromProtokoll = async () => {
35
+ logger.debug("Loading projects from protokoll context");
36
+ const contextDirs = await findProtokolDirectories();
37
+ if (contextDirs.length === 0) {
38
+ logger.warn("No protokoll context directories found");
39
+ return [];
40
+ }
41
+ const mappings = [];
42
+ for (const contextDir of contextDirs) {
43
+ const projectsDir = path.join(contextDir, "projects");
44
+ try {
45
+ const files = await fs.readdir(projectsDir);
46
+ for (const file of files) {
47
+ if (!file.endsWith(".yaml") && !file.endsWith(".yml")) continue;
48
+ try {
49
+ const content = await fs.readFile(path.join(projectsDir, file), "utf-8");
50
+ const parsed = yaml.load(content);
51
+ if (!parsed || !parsed.id || !parsed.name) {
52
+ logger.debug(`Skipping invalid project file: ${file}`);
53
+ continue;
54
+ }
55
+ if (parsed.active === false) {
56
+ logger.debug(`Skipping inactive project: ${parsed.id}`);
57
+ continue;
58
+ }
59
+ if (parsed.sounds_like && parsed.sounds_like.length > 0) {
60
+ for (const soundsLike of parsed.sounds_like) {
61
+ mappings.push({
62
+ soundsLike: soundsLike.toLowerCase(),
63
+ correctText: parsed.name,
64
+ entityType: "project",
65
+ entityId: parsed.id,
66
+ scopedToProjects: null,
67
+ // Will be determined by collision detection
68
+ collisionRisk: "none",
69
+ // Will be determined by collision detection
70
+ tier: 1
71
+ // Will be determined by collision detection
72
+ });
73
+ }
74
+ logger.debug(`Loaded ${parsed.sounds_like.length} sounds_like entries for project: ${parsed.id}`);
75
+ }
76
+ } catch (error) {
77
+ logger.warn(`Failed to parse project file ${file}: ${error.message}`);
78
+ }
79
+ }
80
+ } catch (error) {
81
+ logger.debug(`Could not read projects directory ${projectsDir}: ${error.message}`);
82
+ }
83
+ }
84
+ logger.info(`Loaded ${mappings.length} sounds_like mappings from protokoll projects`);
85
+ return mappings;
86
+ };
87
+ const detectCollisions = (mappings) => {
88
+ const collisionMap = /* @__PURE__ */ new Map();
89
+ for (const mapping of mappings) {
90
+ const key = mapping.soundsLike.toLowerCase();
91
+ if (!collisionMap.has(key)) {
92
+ collisionMap.set(key, []);
93
+ }
94
+ collisionMap.get(key).push(mapping);
95
+ }
96
+ const collisions = /* @__PURE__ */ new Map();
97
+ for (const [soundsLike, conflictMappings] of collisionMap) {
98
+ if (conflictMappings.length > 1) {
99
+ collisions.set(soundsLike, {
100
+ soundsLike,
101
+ mappings: conflictMappings,
102
+ count: conflictMappings.length
103
+ });
104
+ logger.debug(`Collision detected for "${soundsLike}": ${conflictMappings.length} mappings`);
105
+ }
106
+ }
107
+ logger.info(`Detected ${collisions.size} collisions in sounds_like mappings`);
108
+ return collisions;
109
+ };
110
+ const classifyTier = (mapping) => {
111
+ if (!mapping.soundsLike) {
112
+ return 3;
113
+ }
114
+ const soundsLikeLower = mapping.soundsLike.toLowerCase();
115
+ if (database.genericTerms.has(soundsLikeLower)) {
116
+ return 3;
117
+ }
118
+ if (database.commonTerms.has(soundsLikeLower)) {
119
+ return 2;
120
+ }
121
+ if (database.collisions.has(soundsLikeLower)) {
122
+ return 2;
123
+ }
124
+ return 1;
125
+ };
126
+ const assignTiersAndCollisions = (mappings) => {
127
+ for (const mapping of mappings) {
128
+ mapping.tier = classifyTier(mapping);
129
+ if (database.collisions.has(mapping.soundsLike.toLowerCase())) {
130
+ mapping.collisionRisk = "high";
131
+ } else if (database.commonTerms.has(mapping.soundsLike.toLowerCase())) {
132
+ mapping.collisionRisk = "medium";
133
+ } else if (mapping.tier === 2) {
134
+ mapping.collisionRisk = "low";
135
+ } else {
136
+ mapping.collisionRisk = "none";
137
+ }
138
+ if (mapping.tier === 2 && mapping.entityType === "project") {
139
+ mapping.scopedToProjects = [mapping.entityId];
140
+ mapping.minConfidence = config?.tier2Confidence ?? 0.6;
141
+ }
142
+ logger.debug(
143
+ `Classified "${mapping.soundsLike}" → "${mapping.correctText}" (${mapping.entityType}:${mapping.entityId}) as Tier ${mapping.tier} (risk: ${mapping.collisionRisk})`
144
+ );
145
+ }
146
+ };
147
+ const organizeMappingsByTier = (mappings) => {
148
+ database.tier1 = [];
149
+ database.tier2 = /* @__PURE__ */ new Map();
150
+ database.tier3 = [];
151
+ for (const mapping of mappings) {
152
+ if (mapping.tier === 1) {
153
+ database.tier1.push(mapping);
154
+ } else if (mapping.tier === 2) {
155
+ if (mapping.entityType === "project") {
156
+ if (!database.tier2.has(mapping.entityId)) {
157
+ database.tier2.set(mapping.entityId, []);
158
+ }
159
+ database.tier2.get(mapping.entityId).push(mapping);
160
+ } else {
161
+ if (!database.tier2.has("_generic")) {
162
+ database.tier2.set("_generic", []);
163
+ }
164
+ database.tier2.get("_generic").push(mapping);
165
+ }
166
+ } else {
167
+ database.tier3.push(mapping);
168
+ }
169
+ }
170
+ logger.info(
171
+ `Organized mappings: Tier 1=${database.tier1.length}, Tier 2=${Array.from(database.tier2.values()).reduce((sum, arr) => sum + arr.length, 0)}, Tier 3=${database.tier3.length}`
172
+ );
173
+ };
174
+ const loadEntitiesFromContext = (ctx) => {
175
+ const mappings = [];
176
+ const addMappings = (name, entityId, entityType, soundsLike, active) => {
177
+ if (active === false) return;
178
+ const seen = /* @__PURE__ */ new Set();
179
+ const push = (raw) => {
180
+ const key = raw.toLowerCase().trim();
181
+ if (!key || seen.has(key)) return;
182
+ seen.add(key);
183
+ mappings.push({
184
+ soundsLike: key,
185
+ correctText: name,
186
+ entityType,
187
+ entityId,
188
+ scopedToProjects: null,
189
+ collisionRisk: "none",
190
+ tier: 1
191
+ });
192
+ };
193
+ push(name);
194
+ for (const sl of soundsLike) {
195
+ push(sl);
31
196
  }
32
- });
33
- return "{" + arrOfKeyVals + "}";
34
- }
35
- return "";
197
+ };
198
+ for (const project of ctx.getAllProjects()) {
199
+ addMappings(project.name, project.id, "project", project.sounds_like ?? [], project.active);
200
+ }
201
+ for (const person of ctx.getAllPeople()) {
202
+ addMappings(person.name, person.id, "person", person.sounds_like ?? []);
203
+ }
204
+ for (const term of ctx.getAllTerms()) {
205
+ addMappings(term.name, term.id, "term", term.sounds_like ?? []);
206
+ }
207
+ const projectCount = ctx.getAllProjects().filter((p) => p.active !== false).length;
208
+ const peopleCount = ctx.getAllPeople().length;
209
+ const termCount = ctx.getAllTerms().length;
210
+ logger.info(
211
+ `Loaded ${mappings.length} sounds_like mappings from context instance (${projectCount} projects, ${peopleCount} people, ${termCount} terms)`
212
+ );
213
+ return mappings;
214
+ };
215
+ const load = async () => {
216
+ logger.info("Loading sounds_like database");
217
+ let allMappings;
218
+ if (config?.contextInstance) {
219
+ allMappings = loadEntitiesFromContext(config.contextInstance);
220
+ } else {
221
+ const projectMappings = await loadProjectsFromProtokoll();
222
+ allMappings = projectMappings;
223
+ }
224
+ database.mappings = allMappings;
225
+ if (config?.detectCollisions !== false) {
226
+ database.collisions = detectCollisions(allMappings);
227
+ }
228
+ assignTiersAndCollisions(allMappings);
229
+ organizeMappingsByTier(allMappings);
230
+ logger.info(`Sounds_like database loaded: ${allMappings.length} total mappings`);
231
+ return database;
232
+ };
233
+ const getTier1Mappings = () => {
234
+ return database.tier1;
235
+ };
236
+ const getTier2MappingsForProject = (projectId) => {
237
+ const projectMappings = database.tier2.get(projectId) ?? [];
238
+ const genericMappings = database.tier2.get("_generic") ?? [];
239
+ return [...projectMappings, ...genericMappings];
240
+ };
241
+ const hasCollision = (soundsLike) => {
242
+ return database.collisions.has(soundsLike.toLowerCase());
243
+ };
244
+ const getCollision = (soundsLike) => {
245
+ return database.collisions.get(soundsLike.toLowerCase());
246
+ };
247
+ const getAllCollisions = () => {
248
+ return Array.from(database.collisions.values());
249
+ };
250
+ return {
251
+ load,
252
+ getTier1Mappings,
253
+ getTier2MappingsForProject,
254
+ hasCollision,
255
+ getCollision,
256
+ getAllCollisions,
257
+ classifyTier
258
+ };
36
259
  };
260
+ const DEFAULT_COMMON_TERMS = [
261
+ "protocol",
262
+ "observation",
263
+ "composition",
264
+ "gateway",
265
+ "service",
266
+ "system",
267
+ "platform"
268
+ ];
269
+ const DEFAULT_GENERIC_TERMS = [
270
+ "meeting",
271
+ "update",
272
+ "work",
273
+ "project",
274
+ "task",
275
+ "issue",
276
+ "discussion",
277
+ "review",
278
+ "the",
279
+ "a",
280
+ "an"
281
+ ];
37
282
 
38
- export { stringifyJSON };
283
+ export { create };
39
284
  //# sourceMappingURL=index55.js.map