locdotech-ai 1.0.65 → 1.0.66
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/api/streaming.d.ts +1 -1
- package/dist/api/streaming.d.ts.map +1 -1
- package/dist/api/streaming.js +23 -116
- package/dist/api/streaming.js.map +1 -1
- package/dist/ui/App.js +1 -1
- package/package.json +1 -1
package/dist/api/streaming.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface StreamEvent {
|
|
|
9
9
|
export declare class StreamingHandler extends EventEmitter {
|
|
10
10
|
private abortController;
|
|
11
11
|
stream(request: ChatRequest): Promise<Message>;
|
|
12
|
-
private
|
|
12
|
+
private executeNonStreaming;
|
|
13
13
|
abort(): void;
|
|
14
14
|
}
|
|
15
15
|
export declare const streamingHandler: StreamingHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,OAAO,EAAU,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAWrE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,eAAe,CAAgC;IAEjD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;YAQtC,mBAAmB;IAuCjC,KAAK,IAAI,IAAI;CAKd;AAED,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
|
package/dist/api/streaming.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { appendFileSync } from 'fs';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as path from 'path';
|
|
3
5
|
import { client } from './client.js';
|
|
4
|
-
const DEBUG_FILE = '
|
|
6
|
+
const DEBUG_FILE = path.join(os.homedir(), '.ai-router', 'debug.log');
|
|
5
7
|
function debugLog(msg) {
|
|
6
8
|
try {
|
|
7
9
|
appendFileSync(DEBUG_FILE, `${new Date().toISOString()} ${msg}\n`);
|
|
@@ -14,95 +16,29 @@ export class StreamingHandler extends EventEmitter {
|
|
|
14
16
|
abortController = null;
|
|
15
17
|
async stream(request) {
|
|
16
18
|
this.abortController = new AbortController();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// Use non-streaming for reliability (server streaming has issues)
|
|
20
|
+
debugLog('=== Using non-streaming mode ===');
|
|
21
|
+
return await this.executeNonStreaming(request);
|
|
22
|
+
}
|
|
23
|
+
async executeNonStreaming(request) {
|
|
24
|
+
debugLog('Calling API (non-streaming)...');
|
|
20
25
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
continue;
|
|
29
|
-
const delta = choice.delta;
|
|
30
|
-
// Debug log the raw delta
|
|
31
|
-
if (delta.tool_calls) {
|
|
32
|
-
debugLog(`TOOL_CALLS: ${JSON.stringify(delta.tool_calls)}`);
|
|
33
|
-
}
|
|
34
|
-
if (choice.finish_reason) {
|
|
35
|
-
debugLog(`FINISH: ${choice.finish_reason}`);
|
|
36
|
-
}
|
|
37
|
-
// Handle content
|
|
38
|
-
if (delta.content) {
|
|
39
|
-
fullContent += delta.content;
|
|
40
|
-
this.emit('content', delta.content);
|
|
41
|
-
}
|
|
42
|
-
// Handle tool calls
|
|
43
|
-
if (delta.tool_calls) {
|
|
44
|
-
for (const tc of delta.tool_calls) {
|
|
45
|
-
if (tc.id) {
|
|
46
|
-
// New tool call
|
|
47
|
-
if (currentToolCall && currentToolCall.id) {
|
|
48
|
-
toolCalls.push(currentToolCall);
|
|
49
|
-
}
|
|
50
|
-
currentToolCall = {
|
|
51
|
-
id: tc.id,
|
|
52
|
-
type: 'function',
|
|
53
|
-
function: {
|
|
54
|
-
name: tc.function?.name || '',
|
|
55
|
-
arguments: tc.function?.arguments || '',
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
else if (currentToolCall && tc.function) {
|
|
60
|
-
// Continue building current tool call
|
|
61
|
-
if (tc.function.name) {
|
|
62
|
-
currentToolCall.function.name += tc.function.name;
|
|
63
|
-
}
|
|
64
|
-
if (tc.function.arguments) {
|
|
65
|
-
currentToolCall.function.arguments += tc.function.arguments;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Check for finish - emit any pending tool calls
|
|
71
|
-
if (choice.finish_reason) {
|
|
72
|
-
// Push any remaining tool call being built
|
|
73
|
-
if (currentToolCall && currentToolCall.id) {
|
|
74
|
-
toolCalls.push(currentToolCall);
|
|
75
|
-
currentToolCall = null;
|
|
76
|
-
}
|
|
77
|
-
// Emit all tool calls when stream finishes
|
|
78
|
-
if (toolCalls.length > 0) {
|
|
79
|
-
for (const tc of toolCalls) {
|
|
80
|
-
this.emit('tool_call', tc);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
this.emit('finish', choice.finish_reason);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Handle any remaining tool call that wasn't finalized
|
|
87
|
-
if (currentToolCall && currentToolCall.id) {
|
|
88
|
-
toolCalls.push(currentToolCall);
|
|
89
|
-
for (const tc of toolCalls) {
|
|
90
|
-
this.emit('tool_call', tc);
|
|
91
|
-
}
|
|
26
|
+
const response = await client.chat({ ...request, stream: false });
|
|
27
|
+
const content = response.choices[0]?.message?.content || '';
|
|
28
|
+
const toolCalls = response.choices[0]?.message?.tool_calls || [];
|
|
29
|
+
debugLog(`Response: ${content.slice(0, 100)}... (${toolCalls.length} tool calls)`);
|
|
30
|
+
// Emit content as single chunk
|
|
31
|
+
if (content) {
|
|
32
|
+
this.emit('content', content);
|
|
92
33
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
// Fallback to non-streaming if streaming returned empty content
|
|
98
|
-
if (!fullContent && toolCalls.length === 0) {
|
|
99
|
-
debugLog('Streaming returned empty, falling back to non-streaming');
|
|
100
|
-
return await this.fallbackToNonStreaming(request);
|
|
34
|
+
// Emit tool calls
|
|
35
|
+
for (const tc of toolCalls) {
|
|
36
|
+
this.emit('tool_call', tc);
|
|
101
37
|
}
|
|
102
38
|
this.emit('done');
|
|
103
39
|
const message = {
|
|
104
40
|
role: 'assistant',
|
|
105
|
-
content
|
|
41
|
+
content,
|
|
106
42
|
};
|
|
107
43
|
if (toolCalls.length > 0) {
|
|
108
44
|
message.tool_calls = toolCalls;
|
|
@@ -110,39 +46,10 @@ export class StreamingHandler extends EventEmitter {
|
|
|
110
46
|
return message;
|
|
111
47
|
}
|
|
112
48
|
catch (error) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return await this.fallbackToNonStreaming(request);
|
|
117
|
-
}
|
|
118
|
-
catch (fallbackError) {
|
|
119
|
-
this.emit('error', fallbackError);
|
|
120
|
-
throw fallbackError;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async fallbackToNonStreaming(request) {
|
|
125
|
-
debugLog('Using non-streaming fallback');
|
|
126
|
-
const response = await client.chat({ ...request, stream: false });
|
|
127
|
-
const content = response.choices[0]?.message?.content || '';
|
|
128
|
-
const toolCalls = response.choices[0]?.message?.tool_calls || [];
|
|
129
|
-
// Emit content as single chunk
|
|
130
|
-
if (content) {
|
|
131
|
-
this.emit('content', content);
|
|
132
|
-
}
|
|
133
|
-
// Emit tool calls
|
|
134
|
-
for (const tc of toolCalls) {
|
|
135
|
-
this.emit('tool_call', tc);
|
|
136
|
-
}
|
|
137
|
-
this.emit('done');
|
|
138
|
-
const message = {
|
|
139
|
-
role: 'assistant',
|
|
140
|
-
content,
|
|
141
|
-
};
|
|
142
|
-
if (toolCalls.length > 0) {
|
|
143
|
-
message.tool_calls = toolCalls;
|
|
49
|
+
debugLog(`API Error: ${error}`);
|
|
50
|
+
this.emit('error', error);
|
|
51
|
+
throw error;
|
|
144
52
|
}
|
|
145
|
-
return message;
|
|
146
53
|
}
|
|
147
54
|
abort() {
|
|
148
55
|
if (this.abortController) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,MAAM,EAAkC,MAAM,aAAa,CAAC;AAErE,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAkC,MAAM,aAAa,CAAC;AAErE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AACtE,SAAS,QAAQ,CAAC,GAAW;IAC3B,IAAI,CAAC;QACH,cAAc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YAC7B,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAElB,MAAM,OAAO,GAAY;gBACvB,IAAI,EAAE,WAAW;gBACjB,OAAO;aACR,CAAC;YAEF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;YACjC,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,cAAc,KAAK,EAAE,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC1B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/ui/App.js
CHANGED
|
@@ -15,7 +15,7 @@ import { useHistory } from './hooks/useHistory.js';
|
|
|
15
15
|
import { useServicesEffect, useToolCallsEffect, useKeyboardShortcuts } from './hooks/useAppEffects.js';
|
|
16
16
|
import { loadSettings, saveSettings } from '../config/index.js';
|
|
17
17
|
import { commandRegistry } from '../commands/index.js';
|
|
18
|
-
const VERSION = '1.0.
|
|
18
|
+
const VERSION = '1.0.66';
|
|
19
19
|
export function App({ initialPrompt }) {
|
|
20
20
|
const { exit } = useApp();
|
|
21
21
|
const settings = loadSettings();
|