enzostvs HF Staff commited on
Commit
b3e1908
·
1 Parent(s): 8cc084b

run format

Browse files
src/lib/chat/triggerAiCall.ts CHANGED
@@ -89,80 +89,80 @@ export async function triggerAiCall(ctx: TriggerAiCallContext): Promise<void> {
89
  }
90
  if (!response.body) throw new Error('No response body');
91
 
92
- let content = '';
93
- let reasoning = '';
94
- let usage: TokenUsage | null = null;
95
- let inThink = false;
96
- let buffer = '';
97
- const reader = response.body.getReader();
98
- const decoder = new TextDecoder();
99
 
100
- while (true) {
101
- const { done, value } = await reader.read();
102
- if (done) {
103
- if (content.includes('__ERROR__')) {
104
- const errMsg = content.split('__ERROR__').pop() ?? 'Unknown error';
105
- throw new Error(errMsg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
107
- if (content.includes('__USAGE__')) {
108
- const usageParts = content.split('__USAGE__');
109
- const usageJson = usageParts.pop() ?? '';
110
- content = usageParts.join('').trimEnd();
111
- try {
112
- usage = JSON.parse(usageJson) as TokenUsage;
113
- } catch {
114
- // ignore malformed usage JSON
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
  }
117
- const end = Date.now();
118
  updateNodeData(
119
  node.id,
120
- {
121
- ...node.data,
122
- content,
123
- reasoning,
124
- timestamp: end - start,
125
- loading: false,
126
- messages,
127
- usage
128
- } as Record<string, unknown>,
129
  { replace: true }
130
  );
131
- return { [model]: { content, timestamp: String(end - start) } };
132
  }
133
- buffer += decoder.decode(value, { stream: true });
134
-
135
- // Process buffer chunk by chunk, splitting on think tags
136
- while (true) {
137
- if (inThink) {
138
- const closeIdx = buffer.indexOf('</think>');
139
- if (closeIdx === -1) {
140
- reasoning += buffer;
141
- buffer = '';
142
- break;
143
- }
144
- reasoning += buffer.slice(0, closeIdx);
145
- buffer = buffer.slice(closeIdx + '</think>'.length);
146
- inThink = false;
147
- } else {
148
- const openIdx = buffer.indexOf('<think>');
149
- if (openIdx === -1) {
150
- content += buffer;
151
- buffer = '';
152
- break;
153
- }
154
- content += buffer.slice(0, openIdx);
155
- buffer = buffer.slice(openIdx + '<think>'.length);
156
- inThink = true;
157
- }
158
- }
159
-
160
- updateNodeData(
161
- node.id,
162
- { ...node.data, content, reasoning, loading: false } as Record<string, unknown>,
163
- { replace: true }
164
- );
165
- }
166
  } catch (error) {
167
  const msg = error instanceof Error ? error.message : 'An unknown error occurred';
168
  failedNodeIds.add(node.id);
 
89
  }
90
  if (!response.body) throw new Error('No response body');
91
 
92
+ let content = '';
93
+ let reasoning = '';
94
+ let usage: TokenUsage | null = null;
95
+ let inThink = false;
96
+ let buffer = '';
97
+ const reader = response.body.getReader();
98
+ const decoder = new TextDecoder();
99
 
100
+ while (true) {
101
+ const { done, value } = await reader.read();
102
+ if (done) {
103
+ if (content.includes('__ERROR__')) {
104
+ const errMsg = content.split('__ERROR__').pop() ?? 'Unknown error';
105
+ throw new Error(errMsg);
106
+ }
107
+ if (content.includes('__USAGE__')) {
108
+ const usageParts = content.split('__USAGE__');
109
+ const usageJson = usageParts.pop() ?? '';
110
+ content = usageParts.join('').trimEnd();
111
+ try {
112
+ usage = JSON.parse(usageJson) as TokenUsage;
113
+ } catch {
114
+ // ignore malformed usage JSON
115
+ }
116
+ }
117
+ const end = Date.now();
118
+ updateNodeData(
119
+ node.id,
120
+ {
121
+ ...node.data,
122
+ content,
123
+ reasoning,
124
+ timestamp: end - start,
125
+ loading: false,
126
+ messages,
127
+ usage
128
+ } as Record<string, unknown>,
129
+ { replace: true }
130
+ );
131
+ return { [model]: { content, timestamp: String(end - start) } };
132
  }
133
+ buffer += decoder.decode(value, { stream: true });
134
+
135
+ // Process buffer chunk by chunk, splitting on think tags
136
+ while (true) {
137
+ if (inThink) {
138
+ const closeIdx = buffer.indexOf('</think>');
139
+ if (closeIdx === -1) {
140
+ reasoning += buffer;
141
+ buffer = '';
142
+ break;
143
+ }
144
+ reasoning += buffer.slice(0, closeIdx);
145
+ buffer = buffer.slice(closeIdx + '</think>'.length);
146
+ inThink = false;
147
+ } else {
148
+ const openIdx = buffer.indexOf('<think>');
149
+ if (openIdx === -1) {
150
+ content += buffer;
151
+ buffer = '';
152
+ break;
153
+ }
154
+ content += buffer.slice(0, openIdx);
155
+ buffer = buffer.slice(openIdx + '<think>'.length);
156
+ inThink = true;
157
  }
158
  }
159
+
160
  updateNodeData(
161
  node.id,
162
+ { ...node.data, content, reasoning, loading: false } as Record<string, unknown>,
 
 
 
 
 
 
 
 
163
  { replace: true }
164
  );
 
165
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  } catch (error) {
167
  const msg = error instanceof Error ? error.message : 'An unknown error occurred';
168
  failedNodeIds.add(node.id);
src/lib/components/chat/markdown/think/Blockquote.svelte CHANGED
@@ -3,6 +3,8 @@
3
  let { children }: { children?: Snippet } = $props();
4
  </script>
5
 
6
- <blockquote class="my-2 border-l-2 border-muted-foreground/25 pl-2.5 text-muted-foreground/80 italic">
 
 
7
  {@render children?.()}
8
  </blockquote>
 
3
  let { children }: { children?: Snippet } = $props();
4
  </script>
5
 
6
+ <blockquote
7
+ class="my-2 border-l-2 border-muted-foreground/25 pl-2.5 text-muted-foreground/80 italic"
8
+ >
9
  {@render children?.()}
10
  </blockquote>
src/lib/components/ui/switch/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import Root from "./switch.svelte";
2
 
3
  export {
4
  Root,
5
  //
6
- Root as Switch,
7
  };
 
1
+ import Root from './switch.svelte';
2
 
3
  export {
4
  Root,
5
  //
6
+ Root as Switch
7
  };