ak-claude 0.0.7 → 0.0.9
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/chat.js +32 -0
- package/index.cjs +26 -0
- package/package.json +1 -1
- package/types.d.ts +8 -0
package/chat.js
CHANGED
|
@@ -9,6 +9,7 @@ import log from './logger.js';
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {import('./types').ChatOptions} ChatOptions
|
|
11
11
|
* @typedef {import('./types').ChatResponse} ChatResponse
|
|
12
|
+
* @typedef {import('./types').ChatStreamEvent} ChatStreamEvent
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -71,6 +72,37 @@ class Chat extends BaseClaude {
|
|
|
71
72
|
usage: this.getLastUsage()
|
|
72
73
|
};
|
|
73
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Send a message and stream the response as events.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} message - The user's message
|
|
80
|
+
* @param {Object} [opts={}] - Per-message options
|
|
81
|
+
* @yields {ChatStreamEvent}
|
|
82
|
+
*/
|
|
83
|
+
async *stream(message, opts = {}) {
|
|
84
|
+
if (!this._initialized) await this.init();
|
|
85
|
+
|
|
86
|
+
let fullText = '';
|
|
87
|
+
const stream = await this._streamMessage(message, opts);
|
|
88
|
+
const finalMessage = await stream.finalMessage();
|
|
89
|
+
|
|
90
|
+
for (const block of finalMessage.content) {
|
|
91
|
+
if (block.type === 'text') {
|
|
92
|
+
fullText += block.text;
|
|
93
|
+
yield { type: 'text', text: block.text };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.history.push({ role: 'assistant', content: finalMessage.content });
|
|
98
|
+
this._captureMetadata(finalMessage);
|
|
99
|
+
|
|
100
|
+
yield {
|
|
101
|
+
type: 'done',
|
|
102
|
+
fullText,
|
|
103
|
+
usage: this.getLastUsage()
|
|
104
|
+
};
|
|
105
|
+
}
|
|
74
106
|
}
|
|
75
107
|
|
|
76
108
|
export default Chat;
|
package/index.cjs
CHANGED
|
@@ -1166,6 +1166,32 @@ var Chat = class extends base_default {
|
|
|
1166
1166
|
usage: this.getLastUsage()
|
|
1167
1167
|
};
|
|
1168
1168
|
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Send a message and stream the response as events.
|
|
1171
|
+
*
|
|
1172
|
+
* @param {string} message - The user's message
|
|
1173
|
+
* @param {Object} [opts={}] - Per-message options
|
|
1174
|
+
* @yields {ChatStreamEvent}
|
|
1175
|
+
*/
|
|
1176
|
+
async *stream(message, opts = {}) {
|
|
1177
|
+
if (!this._initialized) await this.init();
|
|
1178
|
+
let fullText = "";
|
|
1179
|
+
const stream = await this._streamMessage(message, opts);
|
|
1180
|
+
const finalMessage = await stream.finalMessage();
|
|
1181
|
+
for (const block of finalMessage.content) {
|
|
1182
|
+
if (block.type === "text") {
|
|
1183
|
+
fullText += block.text;
|
|
1184
|
+
yield { type: "text", text: block.text };
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
this.history.push({ role: "assistant", content: finalMessage.content });
|
|
1188
|
+
this._captureMetadata(finalMessage);
|
|
1189
|
+
yield {
|
|
1190
|
+
type: "done",
|
|
1191
|
+
fullText,
|
|
1192
|
+
usage: this.getLastUsage()
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1169
1195
|
};
|
|
1170
1196
|
var chat_default = Chat;
|
|
1171
1197
|
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -394,6 +394,13 @@ export interface ChatResponse {
|
|
|
394
394
|
usage: UsageData | null;
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
+
export interface ChatStreamEvent {
|
|
398
|
+
type: 'text' | 'done';
|
|
399
|
+
text?: string;
|
|
400
|
+
fullText?: string;
|
|
401
|
+
usage?: UsageData | null;
|
|
402
|
+
}
|
|
403
|
+
|
|
397
404
|
export interface MessageResponse {
|
|
398
405
|
text: string;
|
|
399
406
|
data?: any;
|
|
@@ -527,6 +534,7 @@ export declare class Chat extends BaseClaude {
|
|
|
527
534
|
constructor(options?: ChatOptions);
|
|
528
535
|
|
|
529
536
|
send(message: string, opts?: Record<string, any>): Promise<ChatResponse>;
|
|
537
|
+
stream(message: string, opts?: Record<string, any>): AsyncGenerator<ChatStreamEvent, void, unknown>;
|
|
530
538
|
}
|
|
531
539
|
|
|
532
540
|
export declare class Message extends BaseClaude {
|