ak-claude 0.0.5 → 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 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;