nsarrazin HF Staff commited on
Commit
ae65508
·
unverified ·
1 Parent(s): ed74852

fix(tools): show errors properly with new stream

Browse files
Files changed (1) hide show
  1. src/lib/server/tools/utils.ts +16 -8
src/lib/server/tools/utils.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
  MessageUpdateType,
8
  type MessageToolUpdate,
9
  } from "$lib/types/MessageUpdate";
10
-
11
  export async function* callSpace<TInput extends unknown[], TOutput extends unknown[]>(
12
  name: string,
13
  func: string,
@@ -34,16 +34,24 @@ export async function* callSpace<TInput extends unknown[], TOutput extends unkno
34
 
35
  let data;
36
  for await (const output of job) {
 
 
37
  if (output.type === "data") {
38
  data = output.data as TOutput;
39
  }
40
- if (output.type === "status" && output.eta) {
41
- yield {
42
- type: MessageUpdateType.Tool,
43
- subtype: MessageToolUpdateType.ETA,
44
- eta: output.eta,
45
- uuid,
46
- };
 
 
 
 
 
 
47
  }
48
  }
49
 
 
7
  MessageUpdateType,
8
  type MessageToolUpdate,
9
  } from "$lib/types/MessageUpdate";
10
+ import { logger } from "$lib/server/logger";
11
  export async function* callSpace<TInput extends unknown[], TOutput extends unknown[]>(
12
  name: string,
13
  func: string,
 
34
 
35
  let data;
36
  for await (const output of job) {
37
+ console.log(JSON.stringify(output));
38
+
39
  if (output.type === "data") {
40
  data = output.data as TOutput;
41
  }
42
+ if (output.type === "status") {
43
+ if (output.stage === "error") {
44
+ logger.error(output.message);
45
+ throw new Error(output.message);
46
+ }
47
+ if (output.eta) {
48
+ yield {
49
+ type: MessageUpdateType.Tool,
50
+ subtype: MessageToolUpdateType.ETA,
51
+ eta: output.eta,
52
+ uuid,
53
+ };
54
+ }
55
  }
56
  }
57