hai-api 1.1.3 → 1.1.5
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/index.d.ts +9 -5
- package/dist/index.js +10 -4
- package/package.json +2 -2
- package/src/index.ts +16 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface HAIResponse {
|
|
2
2
|
text: string;
|
|
3
3
|
thinking_text: string;
|
|
4
4
|
search_text: string;
|
|
@@ -50,7 +50,7 @@ export interface ChatOptions {
|
|
|
50
50
|
/** Model to use (e.g., 'deepseek', 'gemini-nano-banana'). */
|
|
51
51
|
model?: string;
|
|
52
52
|
/** Callback function called once streaming is complete. */
|
|
53
|
-
onDone?: (response:
|
|
53
|
+
onDone?: (response: HAIResponse) => void;
|
|
54
54
|
}
|
|
55
55
|
interface SessionData {
|
|
56
56
|
chatSessionId: string | null;
|
|
@@ -70,21 +70,25 @@ interface SessionData {
|
|
|
70
70
|
* console.log(res.text);
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
|
-
export declare class
|
|
73
|
+
export declare class HAIClient {
|
|
74
74
|
private apiKey;
|
|
75
75
|
private baseUrl;
|
|
76
76
|
private memory;
|
|
77
77
|
constructor(apiKey?: string, baseUrl?: string);
|
|
78
|
+
/**
|
|
79
|
+
* Create a client pre-configured for local development (http://localhost:5000).
|
|
80
|
+
*/
|
|
81
|
+
static local(apiKey?: string): HAIClient;
|
|
78
82
|
private buildPayload;
|
|
79
83
|
private createResponse;
|
|
80
84
|
/**
|
|
81
85
|
* Stream a response in real-time, yielding chunks as they arrive.
|
|
82
86
|
*/
|
|
83
|
-
streamChat(prompt: string, options?: ChatOptions): AsyncGenerator<
|
|
87
|
+
streamChat(prompt: string, options?: ChatOptions): AsyncGenerator<HAIResponse, void, unknown>;
|
|
84
88
|
/**
|
|
85
89
|
* Send a message and get the full response at once (non-streaming).
|
|
86
90
|
*/
|
|
87
|
-
chat(prompt: string, options?: ChatOptions): Promise<
|
|
91
|
+
chat(prompt: string, options?: ChatOptions): Promise<HAIResponse>;
|
|
88
92
|
/**
|
|
89
93
|
* Export the full conversation history for a session.
|
|
90
94
|
*/
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.HAIClient = void 0;
|
|
37
37
|
const dotenv = __importStar(require("dotenv"));
|
|
38
38
|
dotenv.config();
|
|
39
39
|
// ========================
|
|
@@ -100,7 +100,7 @@ async function fetchYouTubeTranscript(videoId) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
// ========================
|
|
103
|
-
// Main
|
|
103
|
+
// Main HAIClient
|
|
104
104
|
// ========================
|
|
105
105
|
/**
|
|
106
106
|
* HSeekClient — The official client for the hAI private AI.
|
|
@@ -112,7 +112,7 @@ async function fetchYouTubeTranscript(videoId) {
|
|
|
112
112
|
* console.log(res.text);
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
|
-
class
|
|
115
|
+
class HAIClient {
|
|
116
116
|
apiKey;
|
|
117
117
|
baseUrl;
|
|
118
118
|
memory;
|
|
@@ -124,6 +124,12 @@ class HSeekClient {
|
|
|
124
124
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
125
125
|
this.memory = new MemoryStore();
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a client pre-configured for local development (http://localhost:5000).
|
|
129
|
+
*/
|
|
130
|
+
static local(apiKey) {
|
|
131
|
+
return new HAIClient(apiKey, "http://localhost:5000");
|
|
132
|
+
}
|
|
127
133
|
buildPayload(prompt, options) {
|
|
128
134
|
const { sessionId, thinking = false, search = false, chatSessionId, parentMessageId, system, temperature, maxTokens, jsonMode, translate, codeMode, verify, summarize, includeThought, image, memoryDepth = 10, } = options;
|
|
129
135
|
// Build messages array
|
|
@@ -327,4 +333,4 @@ class HSeekClient {
|
|
|
327
333
|
this.memory.clear(sessionId);
|
|
328
334
|
}
|
|
329
335
|
}
|
|
330
|
-
exports.
|
|
336
|
+
exports.HAIClient = HAIClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hai-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "The official Node.js SDK for hAI Private AI.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"dotenv": "^16.4.5",
|
|
15
|
-
"
|
|
15
|
+
"hai-api": "^1.1.3"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "^20.12.7",
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ dotenv.config();
|
|
|
6
6
|
// Types & Interfaces
|
|
7
7
|
// ========================
|
|
8
8
|
|
|
9
|
-
export interface
|
|
9
|
+
export interface HAIResponse {
|
|
10
10
|
text: string;
|
|
11
11
|
thinking_text: string;
|
|
12
12
|
search_text: string;
|
|
@@ -59,7 +59,7 @@ export interface ChatOptions {
|
|
|
59
59
|
/** Model to use (e.g., 'deepseek', 'gemini-nano-banana'). */
|
|
60
60
|
model?: string;
|
|
61
61
|
/** Callback function called once streaming is complete. */
|
|
62
|
-
onDone?: (response:
|
|
62
|
+
onDone?: (response: HAIResponse) => void;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
interface SessionData {
|
|
@@ -135,7 +135,7 @@ async function fetchYouTubeTranscript(videoId: string): Promise<string> {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// ========================
|
|
138
|
-
// Main
|
|
138
|
+
// Main HAIClient
|
|
139
139
|
// ========================
|
|
140
140
|
|
|
141
141
|
/**
|
|
@@ -148,7 +148,7 @@ async function fetchYouTubeTranscript(videoId: string): Promise<string> {
|
|
|
148
148
|
* console.log(res.text);
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
|
-
export class
|
|
151
|
+
export class HAIClient {
|
|
152
152
|
private apiKey: string;
|
|
153
153
|
private baseUrl: string;
|
|
154
154
|
private memory: MemoryStore;
|
|
@@ -162,6 +162,13 @@ export class HSeekClient {
|
|
|
162
162
|
this.memory = new MemoryStore();
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Create a client pre-configured for local development (http://localhost:5000).
|
|
167
|
+
*/
|
|
168
|
+
static local(apiKey?: string): HAIClient {
|
|
169
|
+
return new HAIClient(apiKey, "http://localhost:5000");
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
private buildPayload(prompt: string, options: ChatOptions): Record<string, unknown> {
|
|
166
173
|
const {
|
|
167
174
|
sessionId, thinking = false, search = false,
|
|
@@ -215,8 +222,8 @@ export class HSeekClient {
|
|
|
215
222
|
return payload;
|
|
216
223
|
}
|
|
217
224
|
|
|
218
|
-
private createResponse():
|
|
219
|
-
const r:
|
|
225
|
+
private createResponse(): HAIResponse {
|
|
226
|
+
const r: HAIResponse = {
|
|
220
227
|
text: "",
|
|
221
228
|
thinking_text: "",
|
|
222
229
|
search_text: "",
|
|
@@ -250,7 +257,7 @@ export class HSeekClient {
|
|
|
250
257
|
/**
|
|
251
258
|
* Stream a response in real-time, yielding chunks as they arrive.
|
|
252
259
|
*/
|
|
253
|
-
async *streamChat(prompt: string, options: ChatOptions = {}): AsyncGenerator<
|
|
260
|
+
async *streamChat(prompt: string, options: ChatOptions = {}): AsyncGenerator<HAIResponse, void, unknown> {
|
|
254
261
|
const { sessionId, youtube, retries = 3, onDone } = options;
|
|
255
262
|
|
|
256
263
|
// Handle YouTube
|
|
@@ -345,8 +352,8 @@ export class HSeekClient {
|
|
|
345
352
|
/**
|
|
346
353
|
* Send a message and get the full response at once (non-streaming).
|
|
347
354
|
*/
|
|
348
|
-
async chat(prompt: string, options: ChatOptions = {}): Promise<
|
|
349
|
-
let finalResponse:
|
|
355
|
+
async chat(prompt: string, options: ChatOptions = {}): Promise<HAIResponse> {
|
|
356
|
+
let finalResponse: HAIResponse | null = null;
|
|
350
357
|
for await (const chunk of this.streamChat(prompt, options)) {
|
|
351
358
|
finalResponse = chunk;
|
|
352
359
|
}
|