@redaksjon/protokoll-engine 0.1.3 → 0.1.4-dev.20260216151443.e1454c9

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.
Files changed (163) hide show
  1. package/dist/agentic/executor.d.ts.map +1 -1
  2. package/dist/agentic/types.d.ts +4 -1
  3. package/dist/agentic/types.d.ts.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +8 -5
  7. package/dist/index.js.map +1 -1
  8. package/dist/index10.js +4 -3
  9. package/dist/index10.js.map +1 -1
  10. package/dist/index11.js +2 -2
  11. package/dist/index12.js +3 -124
  12. package/dist/index12.js.map +1 -1
  13. package/dist/index13.js +101 -100
  14. package/dist/index13.js.map +1 -1
  15. package/dist/index14.js +109 -281
  16. package/dist/index14.js.map +1 -1
  17. package/dist/index15.js +285 -89
  18. package/dist/index15.js.map +1 -1
  19. package/dist/index16.js +97 -104
  20. package/dist/index16.js.map +1 -1
  21. package/dist/index17.js +18 -179
  22. package/dist/index17.js.map +1 -1
  23. package/dist/index18.js +102 -48
  24. package/dist/index18.js.map +1 -1
  25. package/dist/index19.js +182 -16
  26. package/dist/index19.js.map +1 -1
  27. package/dist/index2.js +3 -3
  28. package/dist/index20.js +48 -100
  29. package/dist/index20.js.map +1 -1
  30. package/dist/index21.js +16 -23
  31. package/dist/index21.js.map +1 -1
  32. package/dist/index22.js +98 -42
  33. package/dist/index22.js.map +1 -1
  34. package/dist/index23.js +19 -112
  35. package/dist/index23.js.map +1 -1
  36. package/dist/index24.js +42 -323
  37. package/dist/index24.js.map +1 -1
  38. package/dist/index25.js +114 -52
  39. package/dist/index25.js.map +1 -1
  40. package/dist/index26.js +339 -37
  41. package/dist/index26.js.map +1 -1
  42. package/dist/index27.js +51 -121
  43. package/dist/index27.js.map +1 -1
  44. package/dist/index28.js +36 -155
  45. package/dist/index28.js.map +1 -1
  46. package/dist/index29.js +114 -150
  47. package/dist/index29.js.map +1 -1
  48. package/dist/index3.js +2 -2
  49. package/dist/index30.js +171 -161
  50. package/dist/index30.js.map +1 -1
  51. package/dist/index31.js +141 -401
  52. package/dist/index31.js.map +1 -1
  53. package/dist/index32.js +158 -146
  54. package/dist/index32.js.map +1 -1
  55. package/dist/index33.js +425 -130
  56. package/dist/index33.js.map +1 -1
  57. package/dist/index34.js +145 -40
  58. package/dist/index34.js.map +1 -1
  59. package/dist/index35.js +159 -83
  60. package/dist/index35.js.map +1 -1
  61. package/dist/index36.js +46 -439
  62. package/dist/index36.js.map +1 -1
  63. package/dist/index37.js +91 -419
  64. package/dist/index37.js.map +1 -1
  65. package/dist/index38.js +447 -66
  66. package/dist/index38.js.map +1 -1
  67. package/dist/index39.js +424 -115
  68. package/dist/index39.js.map +1 -1
  69. package/dist/index4.js +2 -2
  70. package/dist/index40.js +78 -290
  71. package/dist/index40.js.map +1 -1
  72. package/dist/index41.js +112 -44
  73. package/dist/index41.js.map +1 -1
  74. package/dist/index42.js +115 -44
  75. package/dist/index42.js.map +1 -1
  76. package/dist/index43.js +295 -35
  77. package/dist/index43.js.map +1 -1
  78. package/dist/index44.js +270 -218
  79. package/dist/index44.js.map +1 -1
  80. package/dist/index45.js +131 -150
  81. package/dist/index45.js.map +1 -1
  82. package/dist/index46.js +117 -73
  83. package/dist/index46.js.map +1 -1
  84. package/dist/index47.js +45 -74
  85. package/dist/index47.js.map +1 -1
  86. package/dist/index48.js +48 -5
  87. package/dist/index48.js.map +1 -1
  88. package/dist/index49.js +33 -145
  89. package/dist/index49.js.map +1 -1
  90. package/dist/index5.js +3 -3
  91. package/dist/index50.js +216 -203
  92. package/dist/index50.js.map +1 -1
  93. package/dist/index51.js +153 -39
  94. package/dist/index51.js.map +1 -1
  95. package/dist/index52.js +74 -38
  96. package/dist/index52.js.map +1 -1
  97. package/dist/index53.js +74 -33
  98. package/dist/index53.js.map +1 -1
  99. package/dist/index54.js +149 -6
  100. package/dist/index54.js.map +1 -1
  101. package/dist/index55.js +224 -6
  102. package/dist/index55.js.map +1 -1
  103. package/dist/index56.js +42 -143
  104. package/dist/index56.js.map +1 -1
  105. package/dist/index57.js +43 -15
  106. package/dist/index57.js.map +1 -1
  107. package/dist/index58.js +35 -2
  108. package/dist/index58.js.map +1 -1
  109. package/dist/index59.js +5 -14
  110. package/dist/index59.js.map +1 -1
  111. package/dist/index6.js +4 -4
  112. package/dist/index6.js.map +1 -1
  113. package/dist/index60.js +6 -2
  114. package/dist/index60.js.map +1 -1
  115. package/dist/index61.js +6 -4
  116. package/dist/index61.js.map +1 -1
  117. package/dist/index62.js +151 -0
  118. package/dist/index62.js.map +1 -0
  119. package/dist/index63.js +17 -0
  120. package/dist/index63.js.map +1 -0
  121. package/dist/index64.js +4 -0
  122. package/dist/index64.js.map +1 -0
  123. package/dist/index65.js +17 -0
  124. package/dist/index65.js.map +1 -0
  125. package/dist/index66.js +4 -0
  126. package/dist/index66.js.map +1 -0
  127. package/dist/index67.js +6 -0
  128. package/dist/index67.js.map +1 -0
  129. package/dist/index7.js +2 -2
  130. package/dist/index8.js +1 -1
  131. package/dist/index9.js +4 -4
  132. package/dist/phases/simple-replace.d.ts +2 -1
  133. package/dist/phases/simple-replace.d.ts.map +1 -1
  134. package/dist/pipeline/orchestrator.d.ts.map +1 -1
  135. package/dist/pipeline/types.d.ts +3 -0
  136. package/dist/pipeline/types.d.ts.map +1 -1
  137. package/dist/routing/classifier.d.ts +2 -1
  138. package/dist/routing/classifier.d.ts.map +1 -1
  139. package/dist/routing/index.d.ts +2 -1
  140. package/dist/routing/index.d.ts.map +1 -1
  141. package/dist/routing/types.d.ts +1 -1
  142. package/dist/routing/types.d.ts.map +1 -1
  143. package/dist/transcript/index.d.ts +1 -0
  144. package/dist/transcript/index.d.ts.map +1 -1
  145. package/dist/transcript/operations.d.ts +14 -1
  146. package/dist/transcript/operations.d.ts.map +1 -1
  147. package/dist/transcript/upload-utils.d.ts +80 -0
  148. package/dist/transcript/upload-utils.d.ts.map +1 -0
  149. package/dist/util/enhancement-logger.d.ts +19 -0
  150. package/dist/util/enhancement-logger.d.ts.map +1 -0
  151. package/dist/util/metadata.d.ts +1 -0
  152. package/dist/util/metadata.d.ts.map +1 -1
  153. package/dist/weighting/builder.d.ts +126 -0
  154. package/dist/weighting/builder.d.ts.map +1 -0
  155. package/dist/weighting/index.d.ts +12 -0
  156. package/dist/weighting/index.d.ts.map +1 -0
  157. package/dist/weighting/prepositioning.d.ts +55 -0
  158. package/dist/weighting/prepositioning.d.ts.map +1 -0
  159. package/dist/weighting/provider.d.ts +78 -0
  160. package/dist/weighting/provider.d.ts.map +1 -0
  161. package/dist/weighting/types.d.ts +119 -0
  162. package/dist/weighting/types.d.ts.map +1 -0
  163. package/package.json +2 -2
package/dist/index25.js CHANGED
@@ -1,57 +1,119 @@
1
- import { ToolRegistry } from '@kjerneverk/riotprompt';
2
- import { create as create$1 } from './index49.js';
3
- import { create as create$2 } from './index50.js';
4
- import { create as create$3 } from './index51.js';
5
- import { create as create$4 } from './index52.js';
6
- import { create as create$5 } from './index53.js';
1
+ import { registerTemplates, clearTemplates, getTemplates } from '@kjerneverk/riotprompt';
7
2
 
8
- const toRiotTool = (tool, category) => ({
9
- name: tool.name,
10
- description: tool.description,
11
- parameters: tool.parameters,
12
- category,
13
- cost: "cheap",
14
- execute: async (params) => {
15
- const result = await tool.execute(params);
16
- return result;
17
- }
18
- });
19
- const create = (ctx) => {
20
- const tools = [
21
- create$1(ctx),
22
- create$2(ctx),
23
- create$3(ctx),
24
- create$4(ctx),
25
- create$5()
26
- ];
27
- const toolMap = new Map(tools.map((t) => [t.name, t]));
28
- const riotRegistry = ToolRegistry.create();
29
- riotRegistry.register(toRiotTool(tools[0], "lookup"));
30
- riotRegistry.register(toRiotTool(tools[1], "lookup"));
31
- riotRegistry.register(toRiotTool(tools[2], "verification"));
32
- riotRegistry.register(toRiotTool(tools[3], "routing"));
33
- riotRegistry.register(toRiotTool(tools[4], "storage"));
34
- return {
35
- getTools: () => tools,
36
- // Use RiotPrompt's OpenAI format export
37
- getToolDefinitions: () => riotRegistry.toOpenAIFormat().map((t) => ({
38
- name: t.function.name,
39
- description: t.function.description,
40
- parameters: t.function.parameters
41
- })),
42
- executeTool: async (name, args) => {
43
- const tool = toolMap.get(name);
44
- if (!tool) {
45
- return {
46
- success: false,
47
- error: `Unknown tool: ${name}`
48
- };
49
- }
50
- return tool.execute(args);
3
+ const TEMPLATES = {
4
+ // Standard transcription template (default)
5
+ "transcription-standard": {
6
+ persona: {
7
+ content: "You are an expert transcription assistant specializing in correcting misheard names and technical terms while preserving all original content."
8
+ },
9
+ constraints: [
10
+ { content: "Preserve ALL original content - this is NOT a summary." },
11
+ { content: "Only correct obvious transcription errors (misheard names, technical terms)." },
12
+ { content: "Maintain the original structure, flow, and speaking style." },
13
+ { content: "Never add information that was not in the original transcript." }
14
+ ],
15
+ tone: [
16
+ { content: "Professional and accurate." },
17
+ { content: "When uncertain about a correction, preserve the original text." }
18
+ ]
19
+ },
20
+ // Meeting notes template
21
+ "transcription-meeting": {
22
+ persona: {
23
+ content: "You are an expert transcription assistant specializing in meeting notes and discussions."
24
+ },
25
+ constraints: [
26
+ { content: "Preserve ALL discussion points, decisions, and action items." },
27
+ { content: "Correct names of participants and companies." },
28
+ { content: "Maintain the chronological flow of the discussion." },
29
+ { content: "Format action items and decisions clearly." }
30
+ ],
31
+ tone: [
32
+ { content: "Professional and organized." },
33
+ { content: "Clear and structured for easy reference." }
34
+ ]
35
+ },
36
+ // Technical discussion template
37
+ "transcription-technical": {
38
+ persona: {
39
+ content: "You are an expert transcription assistant with deep technical knowledge across software, engineering, and technology domains."
40
+ },
41
+ constraints: [
42
+ { content: "Preserve technical details and specifications accurately." },
43
+ { content: "Correct technical term spellings (APIs, frameworks, tools, protocols)." },
44
+ { content: "Maintain code snippets, commands, and technical references exactly." },
45
+ { content: "Preserve technical jargon and domain-specific terminology." }
46
+ ],
47
+ tone: [
48
+ { content: "Precise and technically accurate." },
49
+ { content: "Maintain the technical depth of the original discussion." }
50
+ ]
51
+ },
52
+ // Quick notes template (brief voice memos)
53
+ "transcription-quick": {
54
+ persona: {
55
+ content: "You are a transcription assistant for quick voice notes and brief memos."
51
56
  },
52
- getRiotRegistry: () => riotRegistry
53
- };
57
+ constraints: [
58
+ { content: "Keep the original brevity and directness." },
59
+ { content: "Focus on capturing key information clearly." },
60
+ { content: "Correct obvious errors but maintain the informal style." }
61
+ ],
62
+ tone: [
63
+ { content: "Concise and direct." },
64
+ { content: "Preserve the informal, note-taking style." }
65
+ ]
66
+ },
67
+ // Interview template
68
+ "transcription-interview": {
69
+ persona: {
70
+ content: "You are an expert transcription assistant specializing in interviews and conversations."
71
+ },
72
+ constraints: [
73
+ { content: "Preserve ALL questions and answers completely." },
74
+ { content: "Maintain speaker attribution and conversational flow." },
75
+ { content: "Correct names and proper nouns mentioned." },
76
+ { content: "Keep the natural speaking patterns and emphasis." }
77
+ ],
78
+ tone: [
79
+ { content: "Accurate and respectful of the speakers' voices." },
80
+ { content: "Clear speaker identification throughout." }
81
+ ]
82
+ }
83
+ };
84
+ const initializeTemplates = () => {
85
+ registerTemplates(TEMPLATES);
86
+ };
87
+ const getTemplateNames = () => {
88
+ return Object.keys(getTemplates());
89
+ };
90
+ const clearAllTemplates = () => {
91
+ clearTemplates();
92
+ };
93
+ const selectTemplate = (transcriptText, hints) => {
94
+ if (hints?.isMeeting) return "transcription-meeting";
95
+ if (hints?.isTechnical) return "transcription-technical";
96
+ if (hints?.isQuick) return "transcription-quick";
97
+ if (hints?.isInterview) return "transcription-interview";
98
+ const lowerText = transcriptText.toLowerCase();
99
+ if (lowerText.includes("meeting") || lowerText.includes("agenda") || lowerText.includes("action item") || lowerText.includes("minutes") || lowerText.includes("attendees")) {
100
+ return "transcription-meeting";
101
+ }
102
+ if ((lowerText.match(/\binterviewer\b/g) || []).length > 1 || (lowerText.match(/\binterviewee\b/g) || []).length > 1 || (lowerText.match(/\bq:|question:/gi) || []).length > 2 || (lowerText.match(/\ba:|answer:/gi) || []).length > 2) {
103
+ return "transcription-interview";
104
+ }
105
+ if (lowerText.includes("code") || lowerText.includes("function") || lowerText.includes("api") || lowerText.includes("database") || lowerText.includes("server") || lowerText.includes("algorithm") || /\b(npm|git|docker|kubernetes|react|python|javascript|typescript)\b/i.test(transcriptText)) {
106
+ return "transcription-technical";
107
+ }
108
+ if (transcriptText.length < 300) {
109
+ return "transcription-quick";
110
+ }
111
+ return "transcription-standard";
112
+ };
113
+ const getTemplate = (name) => {
114
+ const templates = getTemplates();
115
+ return templates[name];
54
116
  };
55
117
 
56
- export { create };
118
+ export { TEMPLATES, clearAllTemplates, getTemplate, getTemplateNames, initializeTemplates, selectTemplate };
57
119
  //# sourceMappingURL=index25.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index25.js","sources":["../src/agentic/registry.ts"],"sourcesContent":["/**\n * Tool Registry\n * \n * Manages available tools for agentic transcription.\n * Uses RiotPrompt's ToolRegistry for format conversion while\n * preserving protokoll's custom ToolResult interface.\n */\n\nimport { ToolRegistry } from '@kjerneverk/riotprompt';\nimport type { Tool as RiotTool } from '@kjerneverk/riotprompt';\nimport { TranscriptionTool, ToolContext, ToolResult } from './types';\nimport * as LookupPerson from './tools/lookup-person';\nimport * as LookupProject from './tools/lookup-project';\nimport * as VerifySpelling from './tools/verify-spelling';\nimport * as RouteNote from './tools/route-note';\nimport * as StoreContext from './tools/store-context';\n\nexport interface RegistryInstance {\n getTools(): TranscriptionTool[];\n \n getToolDefinitions(): any[]; // For LLM API format (OpenAI compatible)\n \n executeTool(name: string, args: any): Promise<ToolResult>;\n \n /** Get the underlying RiotPrompt ToolRegistry */\n getRiotRegistry(): ToolRegistry;\n}\n\n/**\n * Convert a protokoll TranscriptionTool to a RiotPrompt Tool.\n * The execute function is adapted to work with both systems.\n */\nconst toRiotTool = (tool: TranscriptionTool, category?: string): RiotTool => ({\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters as RiotTool['parameters'],\n category,\n cost: 'cheap',\n execute: async (params: any) => {\n const result = await tool.execute(params);\n return result;\n },\n});\n\nexport const create = (ctx: ToolContext): RegistryInstance => {\n // Create protokoll tools\n const tools: TranscriptionTool[] = [\n LookupPerson.create(ctx),\n LookupProject.create(ctx),\n VerifySpelling.create(ctx),\n RouteNote.create(ctx),\n StoreContext.create(ctx),\n ];\n \n const toolMap = new Map(tools.map(t => [t.name, t]));\n \n // Create RiotPrompt ToolRegistry for format conversion\n const riotRegistry = ToolRegistry.create();\n \n // Register tools with categories\n riotRegistry.register(toRiotTool(tools[0], 'lookup')); // lookup_person\n riotRegistry.register(toRiotTool(tools[1], 'lookup')); // lookup_project\n riotRegistry.register(toRiotTool(tools[2], 'verification')); // verify_spelling\n riotRegistry.register(toRiotTool(tools[3], 'routing')); // route_note\n riotRegistry.register(toRiotTool(tools[4], 'storage')); // store_context\n \n return {\n getTools: () => tools,\n \n // Use RiotPrompt's OpenAI format export\n getToolDefinitions: () => riotRegistry.toOpenAIFormat().map(t => ({\n name: t.function.name,\n description: t.function.description,\n parameters: t.function.parameters,\n })),\n \n executeTool: async (name: string, args: any): Promise<ToolResult> => {\n const tool = toolMap.get(name);\n if (!tool) {\n return {\n success: false,\n error: `Unknown tool: ${name}`,\n };\n }\n return tool.execute(args);\n },\n \n getRiotRegistry: () => riotRegistry,\n };\n};\n\n"],"names":["LookupPerson.create","LookupProject.create","VerifySpelling.create","RouteNote.create","StoreContext.create"],"mappings":";;;;;;;AAgCA,MAAM,UAAA,GAAa,CAAC,IAAA,EAAyB,QAAA,MAAiC;AAAA,EAC1E,MAAM,IAAA,CAAK,IAAA;AAAA,EACX,aAAa,IAAA,CAAK,WAAA;AAAA,EAClB,YAAY,IAAA,CAAK,UAAA;AAAA,EACjB,QAAA;AAAA,EACA,IAAA,EAAM,OAAA;AAAA,EACN,OAAA,EAAS,OAAO,MAAA,KAAgB;AAC5B,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA;AACxC,IAA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;AAAA,IAEF,WAAA,EAAa,OAAO,IAAA,EAAc,IAAA,KAAmC;AACjE,MAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA;AAC7B,MAAA,IAAI,CAAC,IAAA,EAAM;AACP,QAAA,OAAO;AAAA,UACH,OAAA,EAAS,KAAA;AAAA,UACT,KAAA,EAAO,iBAAiB,IAAI,CAAA;AAAA,SAChC;AAAA,MACJ;AACA,MAAA,OAAO,IAAA,CAAK,QAAQ,IAAI,CAAA;AAAA,IAC5B,CAAA;AAAA,IAEA,iBAAiB,MAAM;AAAA,GAC3B;AACJ;;;;"}
1
+ {"version":3,"file":"index25.js","sources":["../src/prompt/templates.ts"],"sourcesContent":["/**\n * Transcription Prompt Templates\n * \n * Reusable templates for different transcription scenarios.\n * Uses RiotPrompt's template system for consistent prompt structure.\n */\n\nimport { registerTemplates, getTemplates, clearTemplates } from '@kjerneverk/riotprompt';\nimport type { TemplateConfig } from '@kjerneverk/riotprompt';\n\n/**\n * Available transcription templates\n */\nexport const TEMPLATES: Record<string, TemplateConfig> = {\n // Standard transcription template (default)\n 'transcription-standard': {\n persona: { \n content: 'You are an expert transcription assistant specializing in correcting misheard names and technical terms while preserving all original content.'\n },\n constraints: [\n { content: 'Preserve ALL original content - this is NOT a summary.' },\n { content: 'Only correct obvious transcription errors (misheard names, technical terms).' },\n { content: 'Maintain the original structure, flow, and speaking style.' },\n { content: 'Never add information that was not in the original transcript.' }\n ],\n tone: [\n { content: 'Professional and accurate.' },\n { content: 'When uncertain about a correction, preserve the original text.' }\n ]\n },\n \n // Meeting notes template\n 'transcription-meeting': {\n persona: { \n content: 'You are an expert transcription assistant specializing in meeting notes and discussions.'\n },\n constraints: [\n { content: 'Preserve ALL discussion points, decisions, and action items.' },\n { content: 'Correct names of participants and companies.' },\n { content: 'Maintain the chronological flow of the discussion.' },\n { content: 'Format action items and decisions clearly.' }\n ],\n tone: [\n { content: 'Professional and organized.' },\n { content: 'Clear and structured for easy reference.' }\n ]\n },\n \n // Technical discussion template\n 'transcription-technical': {\n persona: { \n content: 'You are an expert transcription assistant with deep technical knowledge across software, engineering, and technology domains.'\n },\n constraints: [\n { content: 'Preserve technical details and specifications accurately.' },\n { content: 'Correct technical term spellings (APIs, frameworks, tools, protocols).' },\n { content: 'Maintain code snippets, commands, and technical references exactly.' },\n { content: 'Preserve technical jargon and domain-specific terminology.' }\n ],\n tone: [\n { content: 'Precise and technically accurate.' },\n { content: 'Maintain the technical depth of the original discussion.' }\n ]\n },\n \n // Quick notes template (brief voice memos)\n 'transcription-quick': {\n persona: { \n content: 'You are a transcription assistant for quick voice notes and brief memos.'\n },\n constraints: [\n { content: 'Keep the original brevity and directness.' },\n { content: 'Focus on capturing key information clearly.' },\n { content: 'Correct obvious errors but maintain the informal style.' }\n ],\n tone: [\n { content: 'Concise and direct.' },\n { content: 'Preserve the informal, note-taking style.' }\n ]\n },\n \n // Interview template\n 'transcription-interview': {\n persona: {\n content: 'You are an expert transcription assistant specializing in interviews and conversations.'\n },\n constraints: [\n { content: 'Preserve ALL questions and answers completely.' },\n { content: 'Maintain speaker attribution and conversational flow.' },\n { content: 'Correct names and proper nouns mentioned.' },\n { content: 'Keep the natural speaking patterns and emphasis.' }\n ],\n tone: [\n { content: 'Accurate and respectful of the speakers\\' voices.' },\n { content: 'Clear speaker identification throughout.' }\n ]\n }\n};\n\n/**\n * Initialize templates by registering them with RiotPrompt\n * Should be called once at application startup\n */\nexport const initializeTemplates = (): void => {\n registerTemplates(TEMPLATES);\n};\n\n/**\n * Get list of available template names\n */\nexport const getTemplateNames = (): string[] => {\n return Object.keys(getTemplates());\n};\n\n/**\n * Clear all registered templates\n * Useful for testing or reinitialization\n */\nexport const clearAllTemplates = (): void => {\n clearTemplates();\n};\n\n/**\n * Auto-select appropriate template based on transcript content\n * \n * @param transcriptText - The transcript text to analyze\n * @param hints - Optional hints about the transcript type\n * @returns Template name to use\n */\nexport const selectTemplate = (\n transcriptText: string,\n hints?: { \n isMeeting?: boolean; \n isTechnical?: boolean; \n isQuick?: boolean;\n isInterview?: boolean;\n }\n): string => {\n // Check explicit hints first\n if (hints?.isMeeting) return 'transcription-meeting';\n if (hints?.isTechnical) return 'transcription-technical';\n if (hints?.isQuick) return 'transcription-quick';\n if (hints?.isInterview) return 'transcription-interview';\n \n // Auto-detect from content\n const lowerText = transcriptText.toLowerCase();\n \n // Meeting indicators\n if (lowerText.includes('meeting') || \n lowerText.includes('agenda') || \n lowerText.includes('action item') ||\n lowerText.includes('minutes') ||\n lowerText.includes('attendees')) {\n return 'transcription-meeting';\n }\n \n // Interview indicators (check before length-based quick detection)\n if ((lowerText.match(/\\binterviewer\\b/g) || []).length > 1 ||\n (lowerText.match(/\\binterviewee\\b/g) || []).length > 1 ||\n (lowerText.match(/\\bq:|question:/gi) || []).length > 2 ||\n (lowerText.match(/\\ba:|answer:/gi) || []).length > 2) {\n return 'transcription-interview';\n }\n \n // Technical indicators\n if (lowerText.includes('code') || \n lowerText.includes('function') || \n lowerText.includes('api') ||\n lowerText.includes('database') ||\n lowerText.includes('server') ||\n lowerText.includes('algorithm') ||\n /\\b(npm|git|docker|kubernetes|react|python|javascript|typescript)\\b/i.test(transcriptText)) {\n return 'transcription-technical';\n }\n \n // Quick note indicators (short length) - check last to avoid false positives\n // Use a more conservative threshold to avoid misclassifying short but substantial content\n if (transcriptText.length < 300) {\n return 'transcription-quick';\n }\n \n // Default to standard\n return 'transcription-standard';\n};\n\n/**\n * Get template configuration by name\n * \n * @param name - Template name\n * @returns Template configuration or undefined if not found\n */\nexport const getTemplate = (name: string): TemplateConfig | undefined => {\n const templates = getTemplates();\n return templates[name];\n};\n"],"names":[],"mappings":";;AAaO,MAAM,SAAA,GAA4C;AAAA;AAAA,EAErD,wBAAA,EAA0B;AAAA,IACtB,OAAA,EAAS;AAAA,MACL,OAAA,EAAS;AAAA,KACb;AAAA,IACA,WAAA,EAAa;AAAA,MACT,EAAE,SAAS,wDAAA,EAAyD;AAAA,MACpE,E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AAA,OAAO,uBAAA;AAAA,EACX;AAGA,EAAA,IAAA,CAAK,SAAA,CAAU,KAAA,CAAM,kBAAkB,CAAA,IAAK,EAAC,EAAG,MAAA,GAAS,CAAA,IAAA,CACpD,SAAA,CAAU,KAAA,CAAM,kBAAkB,CAAA,IAAK,EAAC,EAAG,MAAA,GAAS,CAAA,IAAA,CACpD,SAAA,CAAU,KAAA,CAAM,kBAAkB,CAAA,IAAK,IAAI,MAAA,GAAS,CAAA,IAAA,CACpD,SAAA,CAAU,KAAA,CAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,SAAS,CAAA,EAAG;AACtD,IAAA,OAAO,yBAAA;AAAA,EACX;AAGA,EAAA,IAAI,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA,IACzB,SAAA,CAAU,QAAA,CAAS,UAAU,CAAA,IAC7B,SAAA,CAAU,QAAA,CAAS,KAAK,CAAA,IACxB,SAAA,CAAU,QAAA,CAAS,UAAU,CAAA,IAC7B,SAAA,CAAU,QAAA,CAAS,QAAQ,CAAA,IAC3B,SAAA,CAAU,QAAA,CAAS,WAAW,CAAA,IAC9B,qEAAA,CAAsE,IAAA,CAAK,cAAc,CAAA,EAAG;AAC5F,IAAA,OAAO,yBAAA;AAAA,EACX;AAIA,EAAA,IAAI,cAAA,CAAe,SAAS,GAAA,EAAK;AAC7B,IAAA,OAAO,qBAAA;AAAA,EACX;AAGA,EAAA,OAAO,wBAAA;AACX;AAQO,MAAM,WAAA,GAAc,CAAC,IAAA,KAA6C;AACrE,EAAA,MAAM,YAAY,YAAA,EAAa;AAC/B,EAAA,OAAO,UAAU,IAAI,CAAA;AACzB;;;;"}
package/dist/index26.js CHANGED
@@ -1,38 +1,340 @@
1
- import { z } from 'zod';
2
-
3
- const CorrectedEntitySchema = z.object({
4
- original: z.string().describe("Original text from transcript"),
5
- corrected: z.string().describe("Corrected spelling/name"),
6
- type: z.enum(["person", "project", "term", "company"]).describe("Entity type"),
7
- confidence: z.number().min(0).max(1).describe("Confidence in correction")
8
- });
9
- const RoutingDecisionSchema = z.object({
10
- projectId: z.string().optional().describe("Matched project ID"),
11
- destination: z.object({
12
- path: z.string().describe("File destination path"),
13
- structure: z.enum(["none", "year", "month", "day"]).default("month")
14
- }),
15
- confidence: z.number().min(0).max(1).describe("Confidence in routing"),
16
- signals: z.array(z.object({
17
- type: z.enum(["explicit_phrase", "associated_person", "associated_company", "topic", "context_type"]),
18
- value: z.string(),
19
- weight: z.number()
20
- })).optional(),
21
- reasoning: z.string().optional().describe("Why this destination was chosen")
22
- });
23
- const ReferencedEntitiesSchema = z.object({
24
- people: z.array(z.string()).describe("IDs of people mentioned"),
25
- projects: z.array(z.string()).describe("IDs of projects mentioned"),
26
- terms: z.array(z.string()).describe("IDs of terms mentioned"),
27
- companies: z.array(z.string()).describe("IDs of companies mentioned")
28
- });
29
- const ToolResultSchema = z.object({
30
- success: z.boolean(),
31
- data: z.any().optional(),
32
- error: z.string().optional(),
33
- needsUserInput: z.boolean().optional(),
34
- userPrompt: z.string().optional()
35
- });
36
-
37
- export { CorrectedEntitySchema, ReferencedEntitiesSchema, RoutingDecisionSchema, ToolResultSchema };
1
+ import { create as create$1 } from './index27.js';
2
+ import { getLogger } from './index47.js';
3
+ import { ConversationBuilder } from '@kjerneverk/riotprompt';
4
+ import { EntityPrepositioner } from './index46.js';
5
+
6
+ const toRiotToolCalls = (toolCalls) => {
7
+ return toolCalls.map((tc) => ({
8
+ id: tc.id,
9
+ type: "function",
10
+ function: {
11
+ name: tc.name,
12
+ arguments: JSON.stringify(tc.arguments)
13
+ }
14
+ }));
15
+ };
16
+ const cleanResponseContent = (content) => {
17
+ let cleaned = content.replace(/^(?:Using tools?|Let me|I'll|I will|Now I'll|First,?\s*I(?:'ll| will)).*?[\r\n]+/gim, "");
18
+ cleaned = cleaned.replace(/\{"tool":\s*"[^"]+",\s*"(?:args|input)":\s*\{[^}]*\}\}/g, "");
19
+ cleaned = cleaned.replace(/\b\w+_\w+\(\{[^}]*\}\)/g, "");
20
+ cleaned = cleaned.replace(/^.*\s+to=\w+\.\w+.*$/gm, "");
21
+ const spamPattern = /^.*[\u4E00-\u9FFF].*(app|官网|彩票|中彩票).*$/gm;
22
+ cleaned = cleaned.replace(spamPattern, "");
23
+ const corruptionStartPattern = /^[\u0530-\u058F\u0E00-\u0E7F\u0A80-\u0AFF\u0C00-\u0C7F].*$/gm;
24
+ cleaned = cleaned.replace(corruptionStartPattern, "");
25
+ const lines = cleaned.split("\n");
26
+ let startIndex = 0;
27
+ for (let i = 0; i < lines.length; i++) {
28
+ const line = lines[i].trim();
29
+ if (line === "") continue;
30
+ const isCommentary = /^(checking|verifying|looking|searching|analyzing|processing|determining|using|calling|executing|I'm|I am|Let me)/i.test(line) || line.includes("tool") || line.includes('{"') || line.includes("reasoning") || line.includes("undefined");
31
+ if (!isCommentary) {
32
+ startIndex = i;
33
+ break;
34
+ }
35
+ }
36
+ if (startIndex > 0) {
37
+ cleaned = lines.slice(startIndex).join("\n");
38
+ }
39
+ cleaned = cleaned.replace(/\n{3,}/g, "\n\n");
40
+ return cleaned.trim();
41
+ };
42
+ const create = (reasoning, ctx) => {
43
+ const logger = getLogger();
44
+ const registry = create$1(ctx);
45
+ const process = async (transcriptText) => {
46
+ const state = {
47
+ originalText: transcriptText,
48
+ correctedText: transcriptText,
49
+ unknownEntities: [],
50
+ resolvedEntities: /* @__PURE__ */ new Map(),
51
+ referencedEntities: {
52
+ people: /* @__PURE__ */ new Set(),
53
+ projects: /* @__PURE__ */ new Set(),
54
+ terms: /* @__PURE__ */ new Set(),
55
+ companies: /* @__PURE__ */ new Set()
56
+ },
57
+ confidence: 0
58
+ };
59
+ ctx.resolvedEntities = state.resolvedEntities;
60
+ const toolsUsed = [];
61
+ const contextChanges = [];
62
+ let iterations = 0;
63
+ let totalTokens = 0;
64
+ const maxIterations = 15;
65
+ const conversation = ConversationBuilder.create({ model: "gpt-4o" }).withTokenBudget({
66
+ max: 1e5,
67
+ // 100k token context window
68
+ reserveForResponse: 4e3,
69
+ // Reserve 4k tokens for response
70
+ strategy: "summarize",
71
+ // Summarize old messages if budget exceeded
72
+ onBudgetExceeded: "compress",
73
+ // Automatically compress when exceeded
74
+ preserveSystem: true,
75
+ // Always keep system messages
76
+ preserveRecent: 5
77
+ // Keep last 5 messages
78
+ });
79
+ const prepositioner = ctx.weightModelProvider ? new EntityPrepositioner(ctx.weightModelProvider, ctx.contextInstance) : null;
80
+ const entityGuidance = prepositioner ? prepositioner.generateGuidance(void 0) : { guidance: "" };
81
+ let systemPrompt = `You are an intelligent transcription assistant. Your job is to:
82
+ 1. Analyze the transcript for names, projects, and companies
83
+ 2. Use the available tools to verify spellings and gather context
84
+ 3. Correct any misheard names or terms
85
+ 4. Determine the appropriate destination for this note
86
+ 5. Produce a clean, accurate Markdown transcript
87
+
88
+ CRITICAL RULES:
89
+ - This is NOT a summary. Preserve ALL content from the original transcript.
90
+ - Only fix obvious transcription errors like misheard names.
91
+ - When you have finished processing, output the COMPLETE corrected transcript as Markdown.
92
+ - Do NOT say you don't have the transcript - it's in the conversation history.
93
+
94
+ OUTPUT REQUIREMENTS - EXTREMELY IMPORTANT:
95
+ - Your final response MUST contain ONLY the corrected transcript text.
96
+ - DO NOT include any commentary like "Using tools to..." or "Let me verify...".
97
+ - DO NOT include any explanations about what you're doing or have done.
98
+ - DO NOT include any tool call information or JSON in your response.
99
+ - DO NOT include any reasoning or processing notes.
100
+ - Your output will be inserted directly into the user-facing document.
101
+ - If you need to use tools, use them silently - don't narrate what you're doing.
102
+
103
+ Available tools:
104
+ - lookup_person: Find information about people (use for any name that might be misspelled)
105
+ - lookup_project: Find project routing information
106
+ - verify_spelling: Ask user about unknown terms (if interactive mode)
107
+ - route_note: Determine where to file this note
108
+ - store_context: Remember new information for future use`;
109
+ if (entityGuidance.guidance) {
110
+ systemPrompt += `
111
+
112
+ ## Entity Guidance
113
+ ${entityGuidance.guidance}`;
114
+ systemPrompt += "\n\nUse this guidance to improve entity recognition, but verify entities exist in the context before referencing them.";
115
+ }
116
+ conversation.addSystemMessage(systemPrompt);
117
+ const initialPrompt = `Here is the raw transcript to process:
118
+
119
+ --- BEGIN TRANSCRIPT ---
120
+ ${transcriptText}
121
+ --- END TRANSCRIPT ---
122
+
123
+ Please:
124
+ 1. Identify any names, companies, or technical terms that might be misspelled
125
+ 2. Use the lookup_person tool to verify spelling of any names you find
126
+ 3. Use route_note to determine the destination
127
+ 4. Then output the COMPLETE corrected transcript as clean Markdown
128
+
129
+ CRITICAL: Your response must contain ONLY the transcript text - no commentary, no explanations, no tool information.
130
+ Remember: preserve ALL content, only fix transcription errors.`;
131
+ conversation.addUserMessage(initialPrompt);
132
+ try {
133
+ logger.debug("Starting agentic transcription - analyzing for names and routing...");
134
+ let response = await reasoning.complete({
135
+ systemPrompt,
136
+ prompt: initialPrompt,
137
+ tools: registry.getToolDefinitions(),
138
+ maxIterations
139
+ });
140
+ if (response.usage) {
141
+ totalTokens += response.usage.totalTokens;
142
+ }
143
+ if (response.toolCalls && response.toolCalls.length > 0) {
144
+ conversation.addAssistantWithToolCalls(
145
+ response.content,
146
+ toRiotToolCalls(response.toolCalls)
147
+ );
148
+ } else {
149
+ conversation.addAssistantMessage(response.content);
150
+ }
151
+ while (response.toolCalls && response.toolCalls.length > 0 && iterations < maxIterations) {
152
+ iterations++;
153
+ logger.debug("Iteration %d: Processing %d tool calls...", iterations, response.toolCalls.length);
154
+ const toolResults = [];
155
+ for (const toolCall of response.toolCalls) {
156
+ logger.debug("Executing tool: %s", toolCall.name);
157
+ toolsUsed.push(toolCall.name);
158
+ try {
159
+ const result = await registry.executeTool(toolCall.name, toolCall.arguments);
160
+ const resultStr = JSON.stringify(result.data || { success: result.success, message: result.error || "OK" });
161
+ toolResults.push({ id: toolCall.id, name: toolCall.name, result: resultStr });
162
+ logger.debug("Tool %s result: %s", toolCall.name, result.success ? "success" : "failed");
163
+ if (result.data?.person) {
164
+ state.resolvedEntities.set(result.data.person.name, result.data.suggestion);
165
+ state.referencedEntities.people.add(result.data.person.id);
166
+ }
167
+ if (result.data?.term) {
168
+ state.referencedEntities.terms.add(result.data.term.id);
169
+ }
170
+ if (result.data?.company) {
171
+ state.referencedEntities.companies.add(result.data.company.id);
172
+ }
173
+ if (result.data?.routingDecision?.destination) {
174
+ const routingDecision = result.data.routingDecision;
175
+ state.routeDecision = {
176
+ projectId: routingDecision.projectId,
177
+ destination: routingDecision.destination,
178
+ confidence: routingDecision.confidence || 1,
179
+ signals: routingDecision.signals,
180
+ reasoning: routingDecision.reasoning || "Determined by route_note tool"
181
+ };
182
+ if (routingDecision.projectId) {
183
+ state.referencedEntities.projects.add(routingDecision.projectId);
184
+ }
185
+ }
186
+ if (result.data?.found && result.data?.project?.routing?.destination) {
187
+ const project = result.data.project;
188
+ state.routeDecision = {
189
+ projectId: project.id,
190
+ destination: {
191
+ path: project.routing.destination,
192
+ structure: project.routing.structure || "month"
193
+ },
194
+ confidence: 1,
195
+ signals: [{ type: "explicit_phrase", value: project.name, weight: 1 }],
196
+ reasoning: `Matched project "${project.name}" with routing to ${project.routing.destination}`
197
+ };
198
+ logger.debug(
199
+ "Captured routing from project lookup: %s -> %s",
200
+ project.name,
201
+ project.routing.destination
202
+ );
203
+ state.referencedEntities.projects.add(project.id);
204
+ }
205
+ } catch (error) {
206
+ logger.error("Tool execution failed", { tool: toolCall.name, error });
207
+ toolResults.push({
208
+ id: toolCall.id,
209
+ name: toolCall.name,
210
+ result: JSON.stringify({ error: String(error) })
211
+ });
212
+ }
213
+ }
214
+ for (const tr of toolResults) {
215
+ conversation.addToolResult(tr.id, tr.result, tr.name);
216
+ }
217
+ const continuationPrompt = `Tool results received. Here's a reminder of your task:
218
+
219
+ ORIGINAL TRANSCRIPT (process this):
220
+ --- BEGIN TRANSCRIPT ---
221
+ ${transcriptText}
222
+ --- END TRANSCRIPT ---
223
+
224
+ Corrections made so far: ${state.resolvedEntities.size > 0 ? Array.from(state.resolvedEntities.entries()).map(([k, v]) => `${k} -> ${v}`).join(", ") : "none yet"}
225
+
226
+ Continue analyzing. If you need more information, use the tools.
227
+ When you're done with tool calls, output the COMPLETE corrected transcript as Markdown.
228
+ Do NOT summarize - include ALL original content with corrections applied.
229
+
230
+ CRITICAL REMINDER: Your response must contain ONLY the transcript text. Do NOT include any commentary, explanations, or processing notes - those will leak into the user-facing document.`;
231
+ conversation.addUserMessage(continuationPrompt);
232
+ response = await reasoning.complete({
233
+ systemPrompt,
234
+ prompt: continuationPrompt,
235
+ tools: registry.getToolDefinitions()
236
+ });
237
+ if (response.usage) {
238
+ totalTokens += response.usage.totalTokens;
239
+ }
240
+ if (response.toolCalls && response.toolCalls.length > 0) {
241
+ conversation.addAssistantWithToolCalls(
242
+ response.content,
243
+ toRiotToolCalls(response.toolCalls)
244
+ );
245
+ } else {
246
+ conversation.addAssistantMessage(response.content);
247
+ }
248
+ }
249
+ if (response.content && response.content.length > 50) {
250
+ const cleanedContent = cleanResponseContent(response.content);
251
+ if (cleanedContent !== response.content) {
252
+ const removedChars = response.content.length - cleanedContent.length;
253
+ logger.warn(
254
+ "Removed leaked internal processing from response (%d -> %d chars, removed %d chars)",
255
+ response.content.length,
256
+ cleanedContent.length,
257
+ removedChars
258
+ );
259
+ const corruptionRatio = removedChars / response.content.length;
260
+ const hasSuspiciousUnicode = /[\u0530-\u058F\u0E00-\u0E7F\u4E00-\u9FFF\u0A80-\u0AFF\u0C00-\u0C7F]/.test(response.content);
261
+ if (corruptionRatio > 0.1 || hasSuspiciousUnicode) {
262
+ logger.error(
263
+ "SEVERE CORRUPTION DETECTED in LLM response (%.1f%% removed, suspicious unicode: %s)",
264
+ corruptionRatio * 100,
265
+ hasSuspiciousUnicode
266
+ );
267
+ logger.error(
268
+ "Raw response preview (first 500 chars): %s",
269
+ response.content.substring(0, 500).replace(/\n/g, "\\n")
270
+ );
271
+ }
272
+ }
273
+ state.correctedText = cleanedContent;
274
+ state.confidence = 0.9;
275
+ logger.debug("Final transcript generated: %d characters", cleanedContent.length);
276
+ } else {
277
+ logger.debug("Model did not produce transcript, requesting explicitly...");
278
+ const finalRequest = `Please output the COMPLETE corrected transcript now.
279
+
280
+ ORIGINAL:
281
+ ${transcriptText}
282
+
283
+ CORRECTIONS TO APPLY:
284
+ ${state.resolvedEntities.size > 0 ? Array.from(state.resolvedEntities.entries()).map(([k, v]) => `- "${k}" should be "${v}"`).join("\n") : "None identified"}
285
+
286
+ Output the full transcript as clean Markdown. Do NOT summarize.
287
+
288
+ CRITICAL: Your response must contain ONLY the corrected transcript text - absolutely no commentary, tool information, or explanations.`;
289
+ const finalResponse = await reasoning.complete({
290
+ systemPrompt,
291
+ prompt: finalRequest
292
+ });
293
+ if (finalResponse.usage) {
294
+ totalTokens += finalResponse.usage.totalTokens;
295
+ }
296
+ const cleanedFinalContent = cleanResponseContent(finalResponse.content || transcriptText);
297
+ if (cleanedFinalContent !== finalResponse.content) {
298
+ const removedChars = (finalResponse.content?.length || 0) - cleanedFinalContent.length;
299
+ logger.warn(
300
+ "Removed leaked internal processing from final response (%d -> %d chars, removed %d chars)",
301
+ finalResponse.content?.length || 0,
302
+ cleanedFinalContent.length,
303
+ removedChars
304
+ );
305
+ const corruptionRatio = removedChars / (finalResponse.content?.length || 1);
306
+ const hasSuspiciousUnicode = /[\u0530-\u058F\u0E00-\u0E7F\u4E00-\u9FFF\u0A80-\u0AFF\u0C00-\u0C7F]/.test(finalResponse.content || "");
307
+ if (corruptionRatio > 0.1 || hasSuspiciousUnicode) {
308
+ logger.error(
309
+ "SEVERE CORRUPTION DETECTED in final LLM response (%.1f%% removed, suspicious unicode: %s)",
310
+ corruptionRatio * 100,
311
+ hasSuspiciousUnicode
312
+ );
313
+ logger.error(
314
+ "Raw response preview (first 500 chars): %s",
315
+ (finalResponse.content || "").substring(0, 500).replace(/\n/g, "\\n")
316
+ );
317
+ }
318
+ }
319
+ state.correctedText = cleanedFinalContent;
320
+ state.confidence = 0.8;
321
+ }
322
+ } catch (error) {
323
+ logger.error("Agentic processing failed", { error });
324
+ state.correctedText = transcriptText;
325
+ state.confidence = 0.5;
326
+ }
327
+ return {
328
+ enhancedText: state.correctedText,
329
+ state,
330
+ toolsUsed: [...new Set(toolsUsed)],
331
+ iterations,
332
+ totalTokens: totalTokens > 0 ? totalTokens : void 0,
333
+ contextChanges: contextChanges.length > 0 ? contextChanges : void 0
334
+ };
335
+ };
336
+ return { process };
337
+ };
338
+
339
+ export { create };
38
340
  //# sourceMappingURL=index26.js.map