ak-gemini 2.0.9 → 2.1.3
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 +29 -0
- package/code-agent.js +435 -173
- package/index.cjs +431 -121
- package/package.json +1 -1
- package/types.d.ts +52 -23
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
|
/**
|
|
@@ -82,6 +83,34 @@ class Chat extends BaseGemini {
|
|
|
82
83
|
usage: this.getLastUsage()
|
|
83
84
|
};
|
|
84
85
|
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Send a message and stream the response as events.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} message - The user's message
|
|
91
|
+
* @param {Object} [opts={}] - Per-message options
|
|
92
|
+
* @yields {ChatStreamEvent}
|
|
93
|
+
*/
|
|
94
|
+
async *stream(message, opts = {}) {
|
|
95
|
+
if (!this.chatSession) await this.init();
|
|
96
|
+
|
|
97
|
+
let fullText = '';
|
|
98
|
+
const streamResponse = await this._withRetry(() => this.chatSession.sendMessageStream({ message }));
|
|
99
|
+
|
|
100
|
+
for await (const chunk of streamResponse) {
|
|
101
|
+
if (chunk.candidates?.[0]?.content?.parts?.[0]?.text) {
|
|
102
|
+
const text = chunk.candidates[0].content.parts[0].text;
|
|
103
|
+
fullText += text;
|
|
104
|
+
yield { type: 'text', text };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
yield {
|
|
109
|
+
type: 'done',
|
|
110
|
+
fullText,
|
|
111
|
+
usage: this.getLastUsage()
|
|
112
|
+
};
|
|
113
|
+
}
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
export default Chat;
|