@fastino-ai/pioneer-cli 0.2.7 → 0.2.8
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/README.md +51 -71
- package/package.json +1 -1
- package/src/api.ts +670 -228
- package/src/client/WebSocketClient.ts +25 -7
- package/src/config.ts +8 -1
- package/src/index.tsx +2267 -1120
|
@@ -42,7 +42,7 @@ export interface WebSocketClientCallbacks {
|
|
|
42
42
|
onToolCall?: (call: ToolCallRequest) => Promise<string>;
|
|
43
43
|
onAssistantMessage?: (content: string) => void;
|
|
44
44
|
onError?: (error: Error) => void;
|
|
45
|
-
onDone?: (messages?: HistoryMessage[]) => void;
|
|
45
|
+
onDone?: (messages?: HistoryMessage[], sessionId?: string) => void;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface ChatOptions {
|
|
@@ -98,9 +98,10 @@ export class WebSocketClient {
|
|
|
98
98
|
|
|
99
99
|
this.ws.on("open", () => {
|
|
100
100
|
this.state = "connected";
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
101
|
+
// Send auth explicitly as a defensive fallback when header auth is not
|
|
102
|
+
// propagated by proxy layers (some environments only support
|
|
103
|
+
// first-message auth for WS).
|
|
104
|
+
if (this.apiKey) {
|
|
104
105
|
this.ws?.send(JSON.stringify({ type: "auth", api_key: this.apiKey }));
|
|
105
106
|
}
|
|
106
107
|
resolve();
|
|
@@ -122,7 +123,7 @@ export class WebSocketClient {
|
|
|
122
123
|
// Only call onDone if not already called (prevents duplicate)
|
|
123
124
|
if (!this.doneCalled) {
|
|
124
125
|
this.doneCalled = true;
|
|
125
|
-
this.callbacks.onDone?.();
|
|
126
|
+
this.callbacks.onDone?.(undefined, undefined);
|
|
126
127
|
}
|
|
127
128
|
if (this.doneResolver) {
|
|
128
129
|
this.doneResolver();
|
|
@@ -143,6 +144,15 @@ export class WebSocketClient {
|
|
|
143
144
|
|
|
144
145
|
private async handleMessage(message: WebSocketMessage): Promise<void> {
|
|
145
146
|
switch (message.type) {
|
|
147
|
+
case "auth_required":
|
|
148
|
+
if (this.apiKey) {
|
|
149
|
+
this.send({ type: "auth", api_key: this.apiKey });
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
case "auth_success":
|
|
154
|
+
break;
|
|
155
|
+
|
|
146
156
|
case "stream":
|
|
147
157
|
this.callbacks.onStream?.(message.content as string);
|
|
148
158
|
break;
|
|
@@ -211,8 +221,16 @@ export class WebSocketClient {
|
|
|
211
221
|
this.doneCalled = true;
|
|
212
222
|
// Pass the message history if provided by the backend
|
|
213
223
|
const messages = message.messages as HistoryMessage[] | undefined;
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
const sessionId = typeof message.session_id === "string" ? message.session_id : undefined;
|
|
225
|
+
console.log(
|
|
226
|
+
"[DEBUG] Done event received, messages:",
|
|
227
|
+
messages?.length,
|
|
228
|
+
"roles:",
|
|
229
|
+
messages?.map((m) => m.role),
|
|
230
|
+
"sessionId:",
|
|
231
|
+
sessionId
|
|
232
|
+
);
|
|
233
|
+
this.callbacks.onDone?.(messages, sessionId);
|
|
216
234
|
}
|
|
217
235
|
if (this.doneResolver) {
|
|
218
236
|
this.doneResolver();
|
package/src/config.ts
CHANGED
|
@@ -36,7 +36,8 @@ export const DEFAULT_BASE_URL = process.env.PIONEER_API_URL || "https://api.pion
|
|
|
36
36
|
// WebSocket URL environments
|
|
37
37
|
const WS_URLS: Record<string, string> = {
|
|
38
38
|
local: "ws://localhost:5001/mle-agent/ws",
|
|
39
|
-
dev: "wss://
|
|
39
|
+
dev: "wss://api-dev.pioneer.ai/mle-agent/ws",
|
|
40
|
+
stg: "wss://api-stg.pioneer.ai/mle-agent/ws",
|
|
40
41
|
prod: "wss://api.pioneer.ai/mle-agent/ws",
|
|
41
42
|
};
|
|
42
43
|
|
|
@@ -65,6 +66,12 @@ export function getWsUrl(): string {
|
|
|
65
66
|
// Dev API Gateway detected - use dev WebSocket URL
|
|
66
67
|
return WS_URLS.dev;
|
|
67
68
|
}
|
|
69
|
+
if (baseUrl.includes("api-dev.pioneer.ai")) {
|
|
70
|
+
return WS_URLS.dev;
|
|
71
|
+
}
|
|
72
|
+
if (baseUrl.includes("api-stg.pioneer.ai")) {
|
|
73
|
+
return WS_URLS.stg;
|
|
74
|
+
}
|
|
68
75
|
if (baseUrl === "https://api.pioneer.ai" || baseUrl === "https://api.pioneer.ai/") {
|
|
69
76
|
// Production detected
|
|
70
77
|
return WS_URLS.prod;
|