@redaksjon/protokoll-engine 0.1.19 → 0.2.0-dev.20260521201150.7ae20f9

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/index51.js CHANGED
@@ -1,45 +1,163 @@
1
- const create = (ctx) => ({
2
- name: "route_note",
3
- description: "Determine the destination for this note based on content analysis.",
4
- parameters: {
5
- type: "object",
6
- properties: {
7
- projectHint: {
8
- type: "string",
9
- description: "The detected project name or hint"
10
- },
11
- contentSummary: {
12
- type: "string",
13
- description: "Brief summary of what the note is about"
1
+ import { getLogger } from './index47.js';
2
+
3
+ const create = (config) => {
4
+ const logger = getLogger();
5
+ const tier2MinConfidence = config?.tier2MinConfidence;
6
+ const useCapitalizationHints = config?.useCapitalizationHints ?? true;
7
+ const shouldApplyTier2 = (mapping, classification) => {
8
+ if (mapping.tier !== 2) {
9
+ return false;
10
+ }
11
+ const confidence = classification.confidence ?? 0;
12
+ const minConfidence = mapping.minConfidence ?? tier2MinConfidence;
13
+ if (confidence < minConfidence) {
14
+ logger.debug(
15
+ `Skipping Tier 2 replacement for "${mapping.soundsLike}": confidence ${confidence} < ${minConfidence}`
16
+ );
17
+ return false;
18
+ }
19
+ if (mapping.scopedToProjects && mapping.scopedToProjects.length > 0) {
20
+ const classifiedProject = classification.project;
21
+ if (!classifiedProject) {
22
+ logger.debug(
23
+ `Skipping Tier 2 replacement for "${mapping.soundsLike}": no project in classification`
24
+ );
25
+ return false;
26
+ }
27
+ if (!mapping.scopedToProjects.includes(classifiedProject)) {
28
+ logger.debug(
29
+ `Skipping Tier 2 replacement for "${mapping.soundsLike}": project "${classifiedProject}" not in scope [${mapping.scopedToProjects.join(", ")}]`
30
+ );
31
+ return false;
14
32
  }
15
33
  }
16
- },
17
- execute: async (args) => {
18
- const routing = ctx.routingInstance;
19
- const routingContext = {
20
- transcriptText: ctx.transcriptText,
21
- audioDate: ctx.audioDate,
22
- sourceFile: ctx.sourceFile
23
- };
24
- const decision = routing.route(routingContext);
25
- const outputPath = routing.buildOutputPath(decision, routingContext);
26
- return {
27
- success: true,
28
- data: {
29
- projectId: decision.projectId,
30
- // Return the routing decision (base path + structure), NOT the built output path
31
- // The orchestrator will call buildOutputPath() later
32
- routingDecision: decision,
33
- // Also include the built path for informational purposes
34
- outputPath,
35
- confidence: decision.confidence,
36
- reasoning: decision.reasoning,
37
- projectHint: args.projectHint,
38
- contentSummary: args.contentSummary
34
+ logger.debug(
35
+ `Applying Tier 2 replacement for "${mapping.soundsLike}" → "${mapping.correctText}" (project: ${classification.project}, confidence: ${confidence})`
36
+ );
37
+ return true;
38
+ };
39
+ const resolveCollision = (collision, classification) => {
40
+ const { soundsLike, mappings } = collision;
41
+ logger.debug(`Resolving collision for "${soundsLike}" (${mappings.length} candidates)`);
42
+ const tier1Mappings = mappings.filter((m) => m.tier === 1);
43
+ const tier2Mappings = mappings.filter((m) => m.tier === 2 && shouldApplyTier2(m, classification));
44
+ if (tier1Mappings.length === 1) {
45
+ logger.debug(`Resolved collision: using Tier 1 mapping "${tier1Mappings[0].correctText}"`);
46
+ return tier1Mappings[0];
47
+ }
48
+ if (tier1Mappings.length > 1) {
49
+ logger.warn(`Multiple Tier 1 mappings for "${soundsLike}", skipping replacement`);
50
+ return null;
51
+ }
52
+ if (tier2Mappings.length === 1) {
53
+ logger.debug(`Resolved collision: using Tier 2 mapping "${tier2Mappings[0].correctText}"`);
54
+ return tier2Mappings[0];
55
+ }
56
+ if (tier2Mappings.length > 1) {
57
+ logger.debug(`Multiple Tier 2 mappings match for "${soundsLike}", skipping replacement`);
58
+ return null;
59
+ }
60
+ logger.debug(`No applicable mappings for collision "${soundsLike}"`);
61
+ return null;
62
+ };
63
+ const detectCapitalizationHint = (soundsLike, surroundingText) => {
64
+ if (!useCapitalizationHints || !surroundingText) {
65
+ return "unknown";
66
+ }
67
+ const regex = new RegExp(`\\b${soundsLike}\\b`, "i");
68
+ const match = surroundingText.match(regex);
69
+ if (!match) {
70
+ return "unknown";
71
+ }
72
+ const matchedText = match[0];
73
+ const isCapitalized = matchedText[0] === matchedText[0].toUpperCase();
74
+ if (!isCapitalized) {
75
+ return "common-term";
76
+ }
77
+ const indexInText = surroundingText.indexOf(matchedText);
78
+ const beforeText = surroundingText.substring(0, indexInText).trimEnd();
79
+ const isAtSentenceStart = beforeText.length === 0 || /[.!?]\s*$/.test(beforeText);
80
+ if (isAtSentenceStart) {
81
+ return "unknown";
82
+ }
83
+ return "proper-noun";
84
+ };
85
+ const decideReplacement = (context) => {
86
+ const { classification, soundsLike, availableMappings, surroundingText } = context;
87
+ if (availableMappings.length === 0) {
88
+ return {
89
+ shouldReplace: false,
90
+ reason: "No mappings available",
91
+ confidence: 1
92
+ };
93
+ }
94
+ if (availableMappings.length === 1) {
95
+ const mapping = availableMappings[0];
96
+ if (mapping.tier === 1) {
97
+ return {
98
+ shouldReplace: true,
99
+ mapping,
100
+ reason: "Tier 1 mapping (always safe)",
101
+ confidence: 1
102
+ };
103
+ }
104
+ if (mapping.tier === 2) {
105
+ if (shouldApplyTier2(mapping, classification)) {
106
+ return {
107
+ shouldReplace: true,
108
+ mapping,
109
+ reason: `Tier 2 mapping (project: ${classification.project}, confidence: ${classification.confidence})`,
110
+ confidence: classification.confidence ?? 0.5
111
+ };
112
+ } else {
113
+ return {
114
+ shouldReplace: false,
115
+ reason: "Tier 2 conditions not met",
116
+ confidence: 0.5
117
+ };
118
+ }
39
119
  }
120
+ return {
121
+ shouldReplace: false,
122
+ reason: "Tier 3 mapping (too ambiguous)",
123
+ confidence: 1
124
+ };
125
+ }
126
+ const resolvedMapping = resolveCollision(
127
+ { soundsLike, mappings: availableMappings, count: availableMappings.length },
128
+ classification
129
+ );
130
+ if (resolvedMapping) {
131
+ return {
132
+ shouldReplace: true,
133
+ mapping: resolvedMapping,
134
+ reason: `Collision resolved (${availableMappings.length} candidates)`,
135
+ confidence: classification.confidence ?? 0.5
136
+ };
137
+ }
138
+ if (surroundingText && useCapitalizationHints) {
139
+ const hint = detectCapitalizationHint(soundsLike, surroundingText);
140
+ if (hint === "common-term") {
141
+ return {
142
+ shouldReplace: false,
143
+ reason: "Capitalization hint suggests common term",
144
+ confidence: 0.7
145
+ };
146
+ }
147
+ }
148
+ return {
149
+ shouldReplace: false,
150
+ reason: "Collision could not be resolved",
151
+ confidence: 0.5
40
152
  };
41
- }
42
- });
153
+ };
154
+ return {
155
+ decideReplacement,
156
+ shouldApplyTier2,
157
+ resolveCollision,
158
+ detectCapitalizationHint
159
+ };
160
+ };
43
161
 
44
162
  export { create };
45
163
  //# sourceMappingURL=index51.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index51.js","sources":["../src/agentic/tools/route-note.ts"],"sourcesContent":["/**\n * Route Note Tool\n * \n * Determines the destination for a note based on content analysis.\n */\n\nimport { TranscriptionTool, ToolContext, ToolResult } from '../types';\n\nexport const create = (ctx: ToolContext): TranscriptionTool => ({\n name: 'route_note',\n description: 'Determine the destination for this note based on content analysis.',\n parameters: {\n type: 'object',\n properties: {\n projectHint: {\n type: 'string',\n description: 'The detected project name or hint',\n },\n contentSummary: {\n type: 'string',\n description: 'Brief summary of what the note is about',\n },\n },\n },\n execute: async (args: { projectHint?: string; contentSummary?: string }): Promise<ToolResult> => {\n const routing = ctx.routingInstance;\n \n const routingContext = {\n transcriptText: ctx.transcriptText,\n audioDate: ctx.audioDate,\n sourceFile: ctx.sourceFile,\n };\n \n const decision = routing.route(routingContext);\n const outputPath = routing.buildOutputPath(decision, routingContext);\n \n return {\n success: true,\n data: {\n projectId: decision.projectId,\n // Return the routing decision (base path + structure), NOT the built output path\n // The orchestrator will call buildOutputPath() later\n routingDecision: decision,\n // Also include the built path for informational purposes\n outputPath: outputPath,\n confidence: decision.confidence,\n reasoning: decision.reasoning,\n projectHint: args.projectHint,\n contentSummary: args.contentSummary,\n },\n };\n },\n});\n\n"],"names":[],"mappings":"AAQO,MAAM,MAAA,GAAS,CAAC,GAAA,MAAyC;AAAA,EAC5D,IAAA,EAAM,YAAA;AAAA,EACN,WAAA,EAAa,oEAAA;AAAA,EACb,UAAA,EAAY;AAAA,IACR,IAAA,EAAM,QAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACR,WAAA,EAAa;AAAA,QACT,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACjB;AAAA,MACA,cAAA,EAAgB;AAAA,QACZ,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA;AACjB;AACJ,GACJ;AAAA,EACA,OAAA,EAAS,OAAO,IAAA,KAAiF;AAC7F,IAAA,MAAM,UAAU,GAAA,CAAI,eAAA;AAEpB,IAAA,MAAM,cAAA,GAAiB;AAAA,MACnB,gBAAgB,GAAA,CAAI,cAAA;AAAA,MACpB,WAAW,GAAA,CAAI,SAAA;AAAA,MACf,YAAY,GAAA,CAAI;AAAA,KACpB;AAEA,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,KAAA,CAAM,cAAc,CAAA;AAC7C,IAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,eAAA,CAAgB,QAAA,EAAU,cAAc,CAAA;AAEnE,IAAA,OAAO;AAAA,MACH,OAAA,EAAS,IAAA;AAAA,MACT,IAAA,EAAM;AAAA,QACF,WAAW,QAAA,CAAS,SAAA;AAAA;AAAA;AAAA,QAGpB,eAAA,EAAiB,QAAA;AAAA;AAAA,QAEjB,UAAA;AAAA,QACA,YAAY,QAAA,CAAS,UAAA;AAAA,QACrB,WAAW,QAAA,CAAS,SAAA;AAAA,QACpB,aAAa,IAAA,CAAK,WAAA;AAAA,QAClB,gBAAgB,IAAA,CAAK;AAAA;AACzB,KACJ;AAAA,EACJ;AACJ,CAAA;;;;"}
1
+ {"version":3,"file":"index51.js","sources":["../src/util/collision-detector.ts"],"sourcesContent":["/**\n * Collision Detector\n *\n * Provides utilities for detecting and resolving collisions in sounds_like mappings.\n * Helps determine when it's safe to apply a replacement and when context is needed.\n *\n * Part of the simple-replace optimization (Phase 1).\n */\n\nimport * as Logging from '@/logging';\nimport { SoundsLikeMapping, Collision } from './sounds-like-database';\n\n/**\n * Classification result for an entity\n */\nexport interface Classification {\n /** Identified project ID */\n project?: string;\n\n /** Classification confidence (0-1) */\n confidence?: number;\n\n /** Additional classification metadata */\n [key: string]: any;\n}\n\n/**\n * Replacement decision\n */\nexport interface ReplacementDecision {\n /** Whether to apply the replacement */\n shouldReplace: boolean;\n\n /** The mapping to use (if shouldReplace is true) */\n mapping?: SoundsLikeMapping;\n\n /** Reason for the decision */\n reason: string;\n\n /** Confidence in this decision (0-1) */\n confidence: number;\n}\n\n/**\n * Context for collision resolution\n */\nexport interface CollisionContext {\n /** Classification of the transcription */\n classification: Classification;\n\n /** The sounds_like value being considered */\n soundsLike: string;\n\n /** Available mappings for this sounds_like */\n availableMappings: SoundsLikeMapping[];\n\n /** Surrounding text context (optional) */\n surroundingText?: string;\n}\n\n/**\n * Instance interface for collision detector\n */\nexport interface Instance {\n /**\n * Decide whether to apply a replacement given a collision context\n */\n decideReplacement(context: CollisionContext): ReplacementDecision;\n\n /**\n * Check if a Tier 2 mapping should be applied given classification\n */\n shouldApplyTier2(mapping: SoundsLikeMapping, classification: Classification): boolean;\n\n /**\n * Resolve a collision by selecting the best mapping\n */\n resolveCollision(collision: Collision, classification: Classification): SoundsLikeMapping | null;\n\n /**\n * Detect capitalization hints in context\n */\n detectCapitalizationHint(soundsLike: string, surroundingText: string): 'proper-noun' | 'common-term' | 'unknown';\n}\n\n/**\n * Configuration for collision detector\n */\nexport interface CollisionDetectorConfig {\n /** Minimum confidence for Tier 2 replacements (default: 0.6) */\n tier2MinConfidence?: number;\n\n /** High confidence threshold for aggressive replacement (default: 0.8) */\n tier2HighConfidence?: number;\n\n /** Enable capitalization hints (default: true) */\n useCapitalizationHints?: boolean;\n\n /** Enable surrounding text analysis (default: false, future feature) */\n useSurroundingText?: boolean;\n}\n\n/**\n * Create a collision detector instance\n */\nexport const create = (config?: CollisionDetectorConfig): Instance => {\n const logger = Logging.getLogger();\n\n const tier2MinConfidence = config?.tier2MinConfidence ?? 0.6;\n // const tier2HighConfidence = config?.tier2HighConfidence ?? 0.8; // Reserved for future use\n const useCapitalizationHints = config?.useCapitalizationHints ?? true;\n\n /**\n * Check if a Tier 2 mapping should be applied\n */\n const shouldApplyTier2 = (\n mapping: SoundsLikeMapping,\n classification: Classification\n ): boolean => {\n // Must be Tier 2\n if (mapping.tier !== 2) {\n return false;\n }\n\n // Check confidence threshold\n const confidence = classification.confidence ?? 0;\n const minConfidence = mapping.minConfidence ?? tier2MinConfidence;\n\n if (confidence < minConfidence) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `confidence ${confidence} < ${minConfidence}`\n );\n return false;\n }\n\n // For project-scoped mappings, check if project matches\n if (mapping.scopedToProjects && mapping.scopedToProjects.length > 0) {\n const classifiedProject = classification.project;\n\n if (!classifiedProject) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `no project in classification`\n );\n return false;\n }\n\n if (!mapping.scopedToProjects.includes(classifiedProject)) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `project \"${classifiedProject}\" not in scope [${mapping.scopedToProjects.join(', ')}]`\n );\n return false;\n }\n }\n\n logger.debug(\n `Applying Tier 2 replacement for \"${mapping.soundsLike}\" → \"${mapping.correctText}\" ` +\n `(project: ${classification.project}, confidence: ${confidence})`\n );\n return true;\n };\n\n /**\n * Resolve a collision by selecting the best mapping\n */\n const resolveCollision = (\n collision: Collision,\n classification: Classification\n ): SoundsLikeMapping | null => {\n const { soundsLike, mappings } = collision;\n\n logger.debug(`Resolving collision for \"${soundsLike}\" (${mappings.length} candidates)`);\n\n // Filter to Tier 1 and applicable Tier 2 mappings\n const tier1Mappings = mappings.filter(m => m.tier === 1);\n const tier2Mappings = mappings.filter(m => m.tier === 2 && shouldApplyTier2(m, classification));\n\n // Prefer Tier 1 if available (always safe)\n if (tier1Mappings.length === 1) {\n logger.debug(`Resolved collision: using Tier 1 mapping \"${tier1Mappings[0].correctText}\"`);\n return tier1Mappings[0];\n }\n\n // If multiple Tier 1 mappings, this is ambiguous (shouldn't happen in practice)\n if (tier1Mappings.length > 1) {\n logger.warn(`Multiple Tier 1 mappings for \"${soundsLike}\", skipping replacement`);\n return null;\n }\n\n // Try Tier 2 mappings that match classification\n if (tier2Mappings.length === 1) {\n logger.debug(`Resolved collision: using Tier 2 mapping \"${tier2Mappings[0].correctText}\"`);\n return tier2Mappings[0];\n }\n\n // If multiple Tier 2 mappings match, this is ambiguous\n if (tier2Mappings.length > 1) {\n logger.debug(`Multiple Tier 2 mappings match for \"${soundsLike}\", skipping replacement`);\n return null;\n }\n\n // No applicable mappings\n logger.debug(`No applicable mappings for collision \"${soundsLike}\"`);\n return null;\n };\n\n /**\n * Detect capitalization hints in surrounding text\n */\n const detectCapitalizationHint = (\n soundsLike: string,\n surroundingText: string\n ): 'proper-noun' | 'common-term' | 'unknown' => {\n if (!useCapitalizationHints || !surroundingText) {\n return 'unknown';\n }\n\n // Find the sounds_like in the surrounding text\n const regex = new RegExp(`\\\\b${soundsLike}\\\\b`, 'i');\n const match = surroundingText.match(regex);\n\n if (!match) {\n return 'unknown';\n }\n\n const matchedText = match[0];\n\n // Check if it's capitalized\n const isCapitalized = matchedText[0] === matchedText[0].toUpperCase();\n\n if (!isCapitalized) {\n // Lowercase in text → likely common term\n return 'common-term';\n }\n\n // Capitalized - check if it's at sentence start\n const indexInText = surroundingText.indexOf(matchedText);\n\n // Look back for sentence boundaries\n const beforeText = surroundingText.substring(0, indexInText).trimEnd();\n const isAtSentenceStart = beforeText.length === 0 || /[.!?]\\s*$/.test(beforeText);\n\n if (isAtSentenceStart) {\n // Capitalized at sentence start → ambiguous\n return 'unknown';\n }\n\n // Capitalized mid-sentence → likely proper noun\n return 'proper-noun';\n };\n\n /**\n * Decide whether to apply a replacement\n */\n const decideReplacement = (context: CollisionContext): ReplacementDecision => {\n const { classification, soundsLike, availableMappings, surroundingText } = context;\n\n // No mappings available\n if (availableMappings.length === 0) {\n return {\n shouldReplace: false,\n reason: 'No mappings available',\n confidence: 1.0,\n };\n }\n\n // Single mapping - straightforward\n if (availableMappings.length === 1) {\n const mapping = availableMappings[0];\n\n // Tier 1: Always apply\n if (mapping.tier === 1) {\n return {\n shouldReplace: true,\n mapping,\n reason: 'Tier 1 mapping (always safe)',\n confidence: 1.0,\n };\n }\n\n // Tier 2: Check conditions\n if (mapping.tier === 2) {\n if (shouldApplyTier2(mapping, classification)) {\n return {\n shouldReplace: true,\n mapping,\n reason: `Tier 2 mapping (project: ${classification.project}, confidence: ${classification.confidence})`,\n confidence: classification.confidence ?? 0.5,\n };\n } else {\n return {\n shouldReplace: false,\n reason: 'Tier 2 conditions not met',\n confidence: 0.5,\n };\n }\n }\n\n // Tier 3: Skip\n return {\n shouldReplace: false,\n reason: 'Tier 3 mapping (too ambiguous)',\n confidence: 1.0,\n };\n }\n\n // Multiple mappings - collision scenario\n const resolvedMapping = resolveCollision(\n { soundsLike, mappings: availableMappings, count: availableMappings.length },\n classification\n );\n\n if (resolvedMapping) {\n return {\n shouldReplace: true,\n mapping: resolvedMapping,\n reason: `Collision resolved (${availableMappings.length} candidates)`,\n confidence: classification.confidence ?? 0.5,\n };\n }\n\n // Use capitalization hint as fallback (future enhancement)\n if (surroundingText && useCapitalizationHints) {\n const hint = detectCapitalizationHint(soundsLike, surroundingText);\n\n if (hint === 'common-term') {\n return {\n shouldReplace: false,\n reason: 'Capitalization hint suggests common term',\n confidence: 0.7,\n };\n }\n }\n\n // Could not resolve collision\n return {\n shouldReplace: false,\n reason: 'Collision could not be resolved',\n confidence: 0.5,\n };\n };\n\n return {\n decideReplacement,\n shouldApplyTier2,\n resolveCollision,\n detectCapitalizationHint,\n };\n};\n"],"names":["Logging.getLogger"],"mappings":";;AAyGO,MAAM,MAAA,GAAS,CAAC,MAAA,KAA+C;AAClE,EAAA,MAAM,MAAA,GAASA,SAAQ,EAAU;AAEjC,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A,QACf,MAAA,EAAQ,gCAAA;AAAA,QACR,UAAA,EAAY;AAAA,OAChB;AAAA,IACJ;AAGA,IAAA,MAAM,eAAA,GAAkB,gBAAA;AAAA,MACpB,EAAE,UAAA,EAAY,QAAA,EAAU,iBAAA,EAAmB,KAAA,EAAO,kBAAkB,MAAA,EAAO;AAAA,MAC3E;AAAA,KACJ;AAEA,IAAA,IAAI,eAAA,EAAiB;AACjB,MAAA,OAAO;AAAA,QACH,aAAA,EAAe,IAAA;AAAA,QACf,OAAA,EAAS,eAAA;AAAA,QACT,MAAA,EAAQ,CAAA,oBAAA,EAAuB,iBAAA,CAAkB,MAAM,CAAA,YAAA,CAAA;AAAA,QACvD,UAAA,EAAY,eAAe,UAAA,IAAc;AAAA,OAC7C;AAAA,IACJ;AAGA,IAAA,IAAI,mBAAmB,sBAAA,EAAwB;AAC3C,MAAA,MAAM,IAAA,GAAO,wBAAA,CAAyB,UAAA,EAAY,eAAe,CAAA;AAEjE,MAAA,IAAI,SAAS,aAAA,EAAe;AACxB,QAAA,OAAO;AAAA,UACH,aAAA,EAAe,KAAA;AAAA,UACf,MAAA,EAAQ,0CAAA;AAAA,UACR,UAAA,EAAY;AAAA,SAChB;AAAA,MACJ;AAAA,IACJ;AAGA,IAAA,OAAO;AAAA,MACH,aAAA,EAAe,KAAA;AAAA,MACf,MAAA,EAAQ,iCAAA;AAAA,MACR,UAAA,EAAY;AAAA,KAChB;AAAA,EACJ,CAAA;AAEA,EAAA,OAAO;AAAA,IACH,iBAAA;AAAA,IACA,gBAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACJ;AACJ;;;;"}
package/dist/index52.js CHANGED
@@ -1,37 +1,81 @@
1
- const create = (_ctx) => ({
2
- name: "store_context",
3
- description: "Store new context information for future use. Use when you learn something new that should be remembered.",
4
- parameters: {
5
- type: "object",
6
- properties: {
7
- entityType: {
8
- type: "string",
9
- enum: ["person", "project", "company", "term"],
10
- description: "Type of entity to store"
11
- },
12
- name: {
13
- type: "string",
14
- description: "Name of the entity"
15
- },
16
- details: {
17
- type: "object",
18
- description: "Additional details about the entity"
19
- }
20
- },
21
- required: ["entityType", "name"]
22
- },
23
- execute: async (args) => {
1
+ import { getLogger } from './index47.js';
2
+
3
+ const create = (config) => {
4
+ const logger = getLogger();
5
+ const createPattern = (soundsLike) => {
6
+ const escaped = soundsLike.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7
+ const pattern = `\\b${escaped}\\b` ;
8
+ const flags = "gi" ;
9
+ return new RegExp(pattern, flags);
10
+ };
11
+ const applySingleReplacement = (text, mapping) => {
12
+ const pattern = createPattern(mapping.soundsLike);
13
+ const occurrences = [];
14
+ let count = 0;
15
+ const replacements = [];
16
+ let match;
17
+ while ((match = pattern.exec(text)) !== null) {
18
+ const original = match[0];
19
+ let replacement = mapping.correctText;
20
+ replacements.push({
21
+ index: match.index,
22
+ length: original.length,
23
+ replacement
24
+ });
25
+ occurrences.push({
26
+ original,
27
+ replacement,
28
+ position: match.index,
29
+ mapping
30
+ });
31
+ count++;
32
+ }
33
+ let resultText = text;
34
+ for (let i = replacements.length - 1; i >= 0; i--) {
35
+ const { index, length, replacement } = replacements[i];
36
+ resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);
37
+ }
38
+ if (count > 0) {
39
+ logger.debug(
40
+ `Replaced "${mapping.soundsLike}" → "${mapping.correctText}" (${count} occurrence${count === 1 ? "" : "s"})`
41
+ );
42
+ }
24
43
  return {
25
- success: true,
26
- data: {
27
- stored: false,
28
- message: "Context storage requires --self-update flag. Information noted but not persisted.",
29
- entityType: args.entityType,
30
- name: args.name
44
+ text: resultText,
45
+ count,
46
+ occurrences,
47
+ appliedMappings: count > 0 ? [mapping] : []
48
+ };
49
+ };
50
+ const applyReplacements = (text, mappings) => {
51
+ let resultText = text;
52
+ let totalCount = 0;
53
+ const allOccurrences = [];
54
+ const appliedMappings = [];
55
+ for (const mapping of mappings) {
56
+ const result = applySingleReplacement(resultText, mapping);
57
+ if (result.count > 0) {
58
+ resultText = result.text;
59
+ totalCount += result.count;
60
+ allOccurrences.push(...result.occurrences);
61
+ appliedMappings.push(mapping);
31
62
  }
63
+ }
64
+ logger.debug(
65
+ `Applied ${mappings.length} mappings, made ${totalCount} replacements (${appliedMappings.length} mappings had matches)`
66
+ );
67
+ return {
68
+ text: resultText,
69
+ count: totalCount,
70
+ occurrences: allOccurrences,
71
+ appliedMappings
32
72
  };
33
- }
34
- });
73
+ };
74
+ return {
75
+ applyReplacements,
76
+ applySingleReplacement
77
+ };
78
+ };
35
79
 
36
80
  export { create };
37
81
  //# sourceMappingURL=index52.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index52.js","sources":["../src/agentic/tools/store-context.ts"],"sourcesContent":["/**\n * Store Context Tool\n * \n * Stores new context information for future use.\n */\n\nimport { TranscriptionTool, ToolContext, ToolResult } from '../types';\n\nexport const create = (_ctx: ToolContext): TranscriptionTool => ({\n name: 'store_context',\n description: 'Store new context information for future use. Use when you learn something new that should be remembered.',\n parameters: {\n type: 'object',\n properties: {\n entityType: {\n type: 'string',\n enum: ['person', 'project', 'company', 'term'],\n description: 'Type of entity to store',\n },\n name: {\n type: 'string',\n description: 'Name of the entity',\n },\n details: {\n type: 'object',\n description: 'Additional details about the entity',\n },\n },\n required: ['entityType', 'name'],\n },\n \n execute: async (args: { entityType: string; name: string; details?: any }): Promise<ToolResult> => {\n // This tool requires --self-update flag to actually persist\n // Otherwise it just acknowledges without saving\n \n return {\n success: true,\n data: {\n stored: false,\n message: 'Context storage requires --self-update flag. Information noted but not persisted.',\n entityType: args.entityType,\n name: args.name,\n },\n };\n },\n});\n\n"],"names":[],"mappings":"AAQO,MAAM,MAAA,GAAS,CAAC,IAAA,MAA0C;AAAA,EAC7D,IAAA,EAAM,eAAA;AAAA,EACN,WAAA,EAAa,2GAAA;AAAA,EACb,UAAA,EAAY;AAAA,IACR,IAAA,EAAM,QAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACR,UAAA,EAAY;AAAA,QACR,IAAA,EAAM,QAAA;AAAA,QACN,IAAA,EAAM,CAAC,QAAA,EAAU,SAAA,EAAW,WAAW,MAAM,CAAA;AAAA,QAC7C,WAAA,EAAa;AAAA,OACjB;AAAA,MACA,IAAA,EAAM;AAAA,QACF,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACjB;AAAA,MACA,OAAA,EAAS;AAAA,QACL,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA;AACjB,KACJ;AAAA,IACA,QAAA,EAAU,CAAC,YAAA,EAAc,MAAM;AAAA,GACnC;AAAA,EAEA,OAAA,EAAS,OAAO,IAAA,KAAmF;AAI/F,IAAA,OAAO;AAAA,MACH,OAAA,EAAS,IAAA;AAAA,MACT,IAAA,EAAM;AAAA,QACF,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS,mFAAA;AAAA,QACT,YAAY,IAAA,CAAK,UAAA;AAAA,QACjB,MAAM,IAAA,CAAK;AAAA;AACf,KACJ;AAAA,EACJ;AACJ,CAAA;;;;"}
1
+ {"version":3,"file":"index52.js","sources":["../src/util/text-replacer.ts"],"sourcesContent":["/**\n * Text Replacer\n *\n * Performs intelligent text replacements with case preservation and word boundary matching.\n * Core utility for the simple-replace phase.\n *\n * Part of the simple-replace optimization (Phase 2).\n */\n\nimport * as Logging from '@/logging';\nimport { SoundsLikeMapping } from './sounds-like-database';\n\n/**\n * Replacement result for a single occurrence\n */\nexport interface ReplacementOccurrence {\n /** Original text that was replaced */\n original: string;\n\n /** Replacement text */\n replacement: string;\n\n /** Position in the text where replacement occurred */\n position: number;\n\n /** The mapping that was used */\n mapping: SoundsLikeMapping;\n}\n\n/**\n * Result of applying replacements to text\n */\nexport interface ReplacementResult {\n /** The text after replacements */\n text: string;\n\n /** Number of replacements made */\n count: number;\n\n /** Detailed information about each replacement */\n occurrences: ReplacementOccurrence[];\n\n /** Mappings that were applied */\n appliedMappings: SoundsLikeMapping[];\n}\n\n/**\n * Configuration for text replacer\n */\nexport interface TextReplacerConfig {\n /** Preserve case of original text when replacing (default: true) */\n preserveCase?: boolean;\n\n /** Use word boundaries for matching (default: true) */\n useWordBoundaries?: boolean;\n\n /** Case-insensitive matching (default: true) */\n caseInsensitive?: boolean;\n}\n\n/**\n * Instance interface for text replacer\n */\nexport interface Instance {\n /**\n * Apply a set of replacements to text\n */\n applyReplacements(text: string, mappings: SoundsLikeMapping[]): ReplacementResult;\n\n /**\n * Apply a single replacement to text\n */\n applySingleReplacement(text: string, mapping: SoundsLikeMapping): ReplacementResult;\n}\n\n/**\n * Create a text replacer instance\n */\nexport const create = (config?: TextReplacerConfig): Instance => {\n const logger = Logging.getLogger();\n\n const preserveCase = config?.preserveCase ?? true;\n const useWordBoundaries = config?.useWordBoundaries ?? true;\n const caseInsensitive = config?.caseInsensitive ?? true;\n\n /**\n * Determine the case style of a string\n */\n const getCaseStyle = (text: string): 'upper' | 'lower' | 'title' | 'mixed' => {\n // Check for all uppercase first (includes single chars)\n if (text.length > 0 && text === text.toUpperCase() && text.toUpperCase() !== text.toLowerCase()) {\n return 'upper';\n }\n // Check for all lowercase\n if (text === text.toLowerCase()) {\n return 'lower';\n }\n // Check for title case (first char upper, or mixed case starting with upper)\n if (text[0] === text[0].toUpperCase()) {\n return 'title';\n }\n return 'mixed';\n };\n\n /**\n * Apply case style from original to replacement\n *\n * Case preservation means: make the replacement match the case pattern of the original\n * - \"protocol\" (lowercase) → \"protokoll\" (lowercase)\n * - \"Protocol\" (title) → \"Protokoll\" (title)\n * - \"PROTOCOL\" (upper) → \"PROTOKOLL\" (upper)\n */\n const applyCaseStyle = (replacement: string, originalCase: 'upper' | 'lower' | 'title' | 'mixed'): string => {\n switch (originalCase) {\n case 'upper':\n // ALL CAPS in original → ALL CAPS in replacement\n return replacement.toUpperCase();\n case 'lower':\n // all lowercase in original → all lowercase in replacement\n return replacement.toLowerCase();\n case 'title':\n // Title Case in original → Title Case in replacement (first char upper, rest as-is)\n return replacement.charAt(0).toUpperCase() + replacement.slice(1);\n case 'mixed':\n default:\n // Mixed case → preserve replacement's original case\n return replacement;\n }\n };\n\n /**\n * Create a regex pattern for matching\n */\n const createPattern = (soundsLike: string): RegExp => {\n // Escape special regex characters\n const escaped = soundsLike.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n // Add word boundaries if enabled\n const pattern = useWordBoundaries ? `\\\\b${escaped}\\\\b` : escaped;\n\n // Create regex with appropriate flags\n const flags = caseInsensitive ? 'gi' : 'g';\n return new RegExp(pattern, flags);\n };\n\n /**\n * Apply a single replacement to text\n */\n const applySingleReplacement = (text: string, mapping: SoundsLikeMapping): ReplacementResult => {\n const pattern = createPattern(mapping.soundsLike);\n const occurrences: ReplacementOccurrence[] = [];\n let count = 0;\n\n // Track positions to avoid double-replacement issues\n const replacements: { index: number; length: number; replacement: string }[] = [];\n\n // Find all matches\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(text)) !== null) {\n const original = match[0];\n let replacement = mapping.correctText;\n\n // Preserve case if enabled\n if (preserveCase) {\n const caseStyle = getCaseStyle(original);\n replacement = applyCaseStyle(replacement, caseStyle);\n }\n\n replacements.push({\n index: match.index,\n length: original.length,\n replacement,\n });\n\n occurrences.push({\n original,\n replacement,\n position: match.index,\n mapping,\n });\n\n count++;\n }\n\n // Apply replacements in reverse order to preserve positions\n let resultText = text;\n for (let i = replacements.length - 1; i >= 0; i--) {\n const { index, length, replacement } = replacements[i];\n resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);\n }\n\n if (count > 0) {\n logger.debug(\n `Replaced \"${mapping.soundsLike}\" → \"${mapping.correctText}\" ` +\n `(${count} occurrence${count === 1 ? '' : 's'})`\n );\n }\n\n return {\n text: resultText,\n count,\n occurrences,\n appliedMappings: count > 0 ? [mapping] : [],\n };\n };\n\n /**\n * Apply multiple replacements to text\n */\n const applyReplacements = (text: string, mappings: SoundsLikeMapping[]): ReplacementResult => {\n let resultText = text;\n let totalCount = 0;\n const allOccurrences: ReplacementOccurrence[] = [];\n const appliedMappings: SoundsLikeMapping[] = [];\n\n // Apply each mapping sequentially\n for (const mapping of mappings) {\n const result = applySingleReplacement(resultText, mapping);\n\n if (result.count > 0) {\n resultText = result.text;\n totalCount += result.count;\n allOccurrences.push(...result.occurrences);\n appliedMappings.push(mapping);\n }\n }\n\n logger.debug(\n `Applied ${mappings.length} mappings, made ${totalCount} replacements ` +\n `(${appliedMappings.length} mappings had matches)`\n );\n\n return {\n text: resultText,\n count: totalCount,\n occurrences: allOccurrences,\n appliedMappings,\n };\n };\n\n return {\n applyReplacements,\n applySingleReplacement,\n };\n};\n"],"names":["Logging.getLogger"],"mappings":";;AA8EO,MAAM,MAAA,GAAS,CAAC,MAAA,KAA0C;AAC7D,EAAA,MAAM,MAAA,GAASA,SAAQ,EAAU;AAsDjC,EAAA,MAAM,aAAA,GAAgB,CAAC,UAAA,KAA+B;AAElD,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,OAAA,CAAQ,qBAAA,EAAuB,MAAM,CAAA;AAGhE,IAAA,MAAM,OAAA,GAA8B,CAAA,GAAA,EAAM,OAAO,CAAA,GAAA,CAAA,CAAQ;AAGzD,IAAA,MAAM,KAAA,GAA0B,IAAA,CAAO;AACvC,IAAA,OAAO,IAAI,MAAA,CAAO,OAAA,EAAS,KAAK,CAAA;AAAA,EACpC,CAAA;AAKA,EAAA,MAAM,sBAAA,GAAyB,CAAC,IAAA,EAAc,OAAA,KAAkD;AAC5F,IAAA,MAAM,OAAA,GAAU,aAAA,CAAc,OAAA,CAAQ,UAAU,CAAA;AAChD,IAAA,MAAM,cAAuC,EAAC;AAC9C,IAAA,IAAI,KAAA,GAAQ,CAAA;AAGZ,IAAA,MAAM,eAAyE,EAAC;AAGhF,IAAA,IAAI,KAAA;AACJ,IAAA,OAAA,CAAQ,KAAA,GAAQ,OAAA,CAAQ,IAAA,CAAK,IAAI,OAAO,IAAA,EAAM;AAC1C,MAAA,MAAM,QAAA,GAAW,MAAM,CAAC,CAA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1F,IAAA,IAAI,UAAA,GAAa,IAAA;AACjB,IAAA,IAAI,UAAA,GAAa,CAAA;AACjB,IAAA,MAAM,iBAA0C,EAAC;AACjD,IAAA,MAAM,kBAAuC,EAAC;AAG9C,IAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC5B,MAAA,MAAM,MAAA,GAAS,sBAAA,CAAuB,UAAA,EAAY,OAAO,CAAA;AAEzD,MAAA,IAAI,MAAA,CAAO,QAAQ,CAAA,EAAG;AAClB,QAAA,UAAA,GAAa,MAAA,CAAO,IAAA;AACpB,QAAA,UAAA,IAAc,MAAA,CAAO,KAAA;AACrB,QAAA,cAAA,CAAe,IAAA,CAAK,GAAG,MAAA,CAAO,WAAW,CAAA;AACzC,QAAA,eAAA,CAAgB,KAAK,OAAO,CAAA;AAAA,MAChC;AAAA,IACJ;AAEA,IAAA,MAAA,CAAO,KAAA;AAAA,MACH,WAAW,QAAA,CAAS,MAAM,mBAAmB,UAAU,CAAA,eAAA,EACnD,gBAAgB,MAAM,CAAA,sBAAA;AAAA,KAC9B;AAEA,IAAA,OAAO;AAAA,MACH,IAAA,EAAM,UAAA;AAAA,MACN,KAAA,EAAO,UAAA;AAAA,MACP,WAAA,EAAa,cAAA;AAAA,MACb;AAAA,KACJ;AAAA,EACJ,CAAA;AAEA,EAAA,OAAO;AAAA,IACH,iBAAA;AAAA,IACA;AAAA,GACJ;AACJ;;;;"}
package/dist/index53.js CHANGED
@@ -1,51 +1,78 @@
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';
1
+ import dayjs from 'dayjs';
2
+ import timezone from './index60.js';
3
+ import utc from './index61.js';
4
+ import 'moment-timezone';
5
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");
6
+ dayjs.extend(utc);
7
+ dayjs.extend(timezone);
8
+ const create = (parameters) => {
9
+ const { timezone: timezone2 } = parameters;
10
+ const now = () => {
11
+ return date(void 0);
12
+ };
13
+ const date = (date2) => {
14
+ let value;
15
+ try {
16
+ if (date2) {
17
+ value = dayjs.tz(date2, timezone2);
18
+ } else {
19
+ value = dayjs().tz(timezone2);
20
+ }
21
+ } catch (error) {
22
+ throw new Error(`Invalid date: ${date2}, error: ${error.message}`);
19
23
  }
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");
24
+ return value.toDate();
25
+ };
26
+ const parse = (date2, format2) => {
27
+ let value;
28
+ try {
29
+ value = dayjs.tz(date2, format2, timezone2);
30
+ } catch (error) {
31
+ throw new Error(`Invalid date: ${date2}, expected format: ${format2}, error: ${error.message}`);
35
32
  }
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
- }
33
+ return value.toDate();
34
+ };
35
+ const addDays = (date2, days) => {
36
+ return dayjs.tz(date2, timezone2).add(days, "day").toDate();
37
+ };
38
+ const addMonths = (date2, months) => {
39
+ return dayjs.tz(date2, timezone2).add(months, "month").toDate();
40
+ };
41
+ const addYears = (date2, years) => {
42
+ return dayjs.tz(date2, timezone2).add(years, "year").toDate();
43
+ };
44
+ const format = (date2, format2) => {
45
+ return dayjs.tz(date2, timezone2).format(format2);
46
+ };
47
+ const subDays = (date2, days) => {
48
+ return dayjs.tz(date2, timezone2).subtract(days, "day").toDate();
49
+ };
50
+ const subMonths = (date2, months) => {
51
+ return dayjs.tz(date2, timezone2).subtract(months, "month").toDate();
52
+ };
53
+ const subYears = (date2, years) => {
54
+ return dayjs.tz(date2, timezone2).subtract(years, "year").toDate();
55
+ };
56
+ const startOfMonth = (date2) => {
57
+ return dayjs.tz(date2, timezone2).startOf("month").toDate();
58
+ };
59
+ const endOfMonth = (date2) => {
60
+ return dayjs.tz(date2, timezone2).endOf("month").toDate();
61
+ };
62
+ const startOfYear = (date2) => {
63
+ return dayjs.tz(date2, timezone2).startOf("year").toDate();
64
+ };
65
+ const endOfYear = (date2) => {
66
+ return dayjs.tz(date2, timezone2).endOf("year").toDate();
67
+ };
68
+ const isBefore = (date2, other) => {
69
+ return dayjs.tz(date2, timezone2).isBefore(dayjs.tz(other, timezone2));
70
+ };
71
+ const isAfter = (date2, other) => {
72
+ return dayjs.tz(date2, timezone2).isAfter(dayjs.tz(other, timezone2));
73
+ };
74
+ return { now, date, parse, addDays, addMonths, addYears, format, subDays, subMonths, subYears, startOfMonth, endOfMonth, startOfYear, endOfYear, isBefore, isAfter };
75
+ };
49
76
 
50
- export { OpenAIError, transcribeAudio };
77
+ export { create };
51
78
  //# sourceMappingURL=index53.js.map
@@ -1 +1 @@
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":";;;;;AAU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A,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":"index53.js","sources":["../src/util/dates.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n// eslint-disable-next-line no-restricted-imports\nimport moment from 'moment-timezone';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\n/**\n * Yes, wrapping dayjs is a bit annoying and might seem overly paranoid. However, I feel strongly\n * about not letting Dayjs instances leak into the rest of the codebase. Having Dayjs objects\n * floating around the application leads to inconsistent timezone handling, makes testing more\n * difficult, and creates subtle bugs that are hard to track down.\n * \n * By wrapping dayjs completely and only exposing plain JavaScript Date objects, we get several\n * key benefits:\n * 1. Consistent timezone handling through a single configuration point\n * 2. Simpler testing since we only need to mock this one library\n * 3. Type safety - the rest of the codebase only deals with standard Date objects\n * 4. No risk of dayjs method chains creating unexpected timezone shifts\n * \n * The Library interface gives us full control over all date operations while keeping the messy\n * details of timezone manipulation contained in one place. Yes it's more code, but the peace of\n * mind is worth it.\n */\nexport interface Utility {\n now: () => Date;\n date: (date: string | number | Date | null | undefined) => Date;\n parse: (date: string | number | Date | null | undefined, format: string) => Date;\n addDays: (date: Date, days: number) => Date;\n addMonths: (date: Date, months: number) => Date;\n addYears: (date: Date, years: number) => Date;\n format: (date: Date, format: string) => string;\n subDays: (date: Date, days: number) => Date;\n subMonths: (date: Date, months: number) => Date;\n subYears: (date: Date, years: number) => Date;\n startOfMonth: (date: Date) => Date;\n endOfMonth: (date: Date) => Date;\n startOfYear: (date: Date) => Date;\n endOfYear: (date: Date) => Date;\n isBefore: (date: Date, other: Date) => boolean;\n isAfter: (date: Date, other: Date) => boolean;\n}\n\nexport const create = (parameters: { timezone: string }) => {\n const { timezone } = parameters;\n const now = () => {\n return date(undefined);\n }\n\n const date = (date: string | number | Date | null | undefined) => {\n let value: dayjs.Dayjs;\n try {\n if (date) {\n value = dayjs.tz(date, timezone);\n } else {\n value = dayjs().tz(timezone);\n }\n } catch (error: any) {\n throw new Error(`Invalid date: ${date}, error: ${error.message}`);\n }\n\n return value.toDate();\n }\n\n const parse = (date: string | number | Date | null | undefined, format: string) => {\n let value: dayjs.Dayjs;\n try {\n value = dayjs.tz(date, format, timezone);\n } catch (error: any) {\n throw new Error(`Invalid date: ${date}, expected format: ${format}, error: ${error.message}`);\n }\n\n return value.toDate();\n }\n\n const addDays = (date: Date, days: number) => {\n return dayjs.tz(date, timezone).add(days, 'day').toDate();\n }\n\n const addMonths = (date: Date, months: number) => {\n return dayjs.tz(date, timezone).add(months, 'month').toDate();\n }\n\n const addYears = (date: Date, years: number) => {\n return dayjs.tz(date, timezone).add(years, 'year').toDate();\n }\n\n const format = (date: Date, format: string) => {\n return dayjs.tz(date, timezone).format(format);\n }\n\n const subDays = (date: Date, days: number) => {\n return dayjs.tz(date, timezone).subtract(days, 'day').toDate();\n }\n\n const subMonths = (date: Date, months: number) => {\n return dayjs.tz(date, timezone).subtract(months, 'month').toDate();\n }\n\n const subYears = (date: Date, years: number) => {\n return dayjs.tz(date, timezone).subtract(years, 'year').toDate();\n }\n\n const startOfMonth = (date: Date) => {\n return dayjs.tz(date, timezone).startOf('month').toDate();\n }\n\n const endOfMonth = (date: Date) => {\n return dayjs.tz(date, timezone).endOf('month').toDate();\n }\n\n const startOfYear = (date: Date) => {\n return dayjs.tz(date, timezone).startOf('year').toDate();\n }\n\n const endOfYear = (date: Date) => {\n return dayjs.tz(date, timezone).endOf('year').toDate();\n }\n\n const isBefore = (date: Date, other: Date) => {\n return dayjs.tz(date, timezone).isBefore(dayjs.tz(other, timezone));\n }\n\n const isAfter = (date: Date, other: Date) => {\n return dayjs.tz(date, timezone).isAfter(dayjs.tz(other, timezone));\n }\n\n return { now, date, parse, addDays, addMonths, addYears, format, subDays, subMonths, subYears, startOfMonth, endOfMonth, startOfYear, endOfYear, isBefore, isAfter };\n}\n\nexport const validTimezones = () => {\n return moment.tz.names();\n}\n"],"names":["timezone","date","format"],"mappings":";;;;;AAOA,KAAA,CAAM,OAAO,GAAG,CAAA;AAChB,KAAA,CAAM,OAAO,QAAQ,CAAA;AAsCd,MAAM,MAAA,GAAS,CAAC,UAAA,KAAqC;AACxD,EAAA,MAAM,EAAE,QAAA,EAAAA,SAAAA,EAAS,GAAI,UAAA;AACrB,EAAA,MAAM,MAAM,MAAM;AACd,IAAA,OAAO,KAAK,MAAS,CAAA;AAAA,EACzB,CAAA;AAEA,EAAA,MAAM,IAAA,GAAO,CAACC,KAAAA,KAAoD;AAC9D,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AACA,MAAA,IAAIA,KAAAA,EAAM;AACN,QAAA,KAAA,GAAQ,KAAA,CAAM,EAAA,CAAGA,KAAAA,EAAM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