@tacone/prosey 0.2.6 → 0.4.0

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/src/summarize.ts CHANGED
@@ -7,7 +7,13 @@ export interface SummarizeOptions {
7
7
  cwd?: string;
8
8
  }
9
9
 
10
- function executeCommand(command: string, input: string, cwd?: string): Promise<string> {
10
+ export type ExecuteCommand = (command: string, input: string, cwd?: string) => Promise<string>;
11
+
12
+ export const defaultExecuteCommand: ExecuteCommand = (
13
+ command: string,
14
+ input: string,
15
+ cwd?: string,
16
+ ) => {
11
17
  return new Promise((resolve, reject) => {
12
18
  const proc = spawn(command, [], { shell: true, stdio: "pipe", cwd });
13
19
 
@@ -32,12 +38,20 @@ function executeCommand(command: string, input: string, cwd?: string): Promise<s
32
38
  proc.stdin!.write(input);
33
39
  proc.stdin!.end();
34
40
  });
35
- }
41
+ };
36
42
 
37
- export async function summarize(options: SummarizeOptions): Promise<string> {
43
+ export async function summarize(
44
+ options: SummarizeOptions,
45
+ execCommand: ExecuteCommand = defaultExecuteCommand,
46
+ ): Promise<string> {
38
47
  const { prompt, command, transcript, cwd } = options;
48
+
49
+ if (!prompt) {
50
+ throw new Error("No prompt configured. A prompt is required in the config.");
51
+ }
52
+
39
53
  const fullPrompt = `${prompt}\n\n${transcript}`;
40
- const output = await executeCommand(command, fullPrompt, cwd);
54
+ const output = await execCommand(command, fullPrompt, cwd);
41
55
 
42
56
  const cleaned = output.startsWith(fullPrompt)
43
57
  ? output.slice(fullPrompt.length).replace(/\n+$/, "")