@octavus/docs 0.0.3 → 0.0.4
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/content/02-server-sdk/04-streaming.md +0 -42
- package/dist/chunk-EPDM2NIJ.js +421 -0
- package/dist/chunk-EPDM2NIJ.js.map +1 -0
- package/dist/chunk-MDMRCS4W.mjs +421 -0
- package/dist/chunk-MDMRCS4W.mjs.map +1 -0
- package/dist/content.js +1 -1
- package/dist/content.mjs +17 -0
- package/dist/content.mjs.map +1 -0
- package/dist/docs.json +3 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -0
- package/dist/search-index.json +1 -1
- package/dist/search.js +1 -1
- package/dist/search.js.map +1 -1
- package/dist/search.mjs +30 -0
- package/dist/search.mjs.map +1 -0
- package/dist/sections.json +3 -3
- package/package.json +1 -1
|
@@ -173,48 +173,6 @@ type StreamEvent =
|
|
|
173
173
|
| ToolRequestEvent;
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
## Handling Streams Manually
|
|
177
|
-
|
|
178
|
-
If you need to process the stream server-side:
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
import { safeParseStreamEvent } from '@octavus/core';
|
|
182
|
-
|
|
183
|
-
const { stream } = session.trigger('user-message', { USER_MESSAGE: 'Hello' });
|
|
184
|
-
|
|
185
|
-
const reader = stream.getReader();
|
|
186
|
-
const decoder = new TextDecoder();
|
|
187
|
-
|
|
188
|
-
let buffer = '';
|
|
189
|
-
|
|
190
|
-
while (true) {
|
|
191
|
-
const { done, value } = await reader.read();
|
|
192
|
-
if (done) break;
|
|
193
|
-
|
|
194
|
-
buffer += decoder.decode(value, { stream: true });
|
|
195
|
-
const lines = buffer.split('\n');
|
|
196
|
-
buffer = lines.pop() ?? '';
|
|
197
|
-
|
|
198
|
-
for (const line of lines) {
|
|
199
|
-
if (line.startsWith('data: ') && line !== 'data: [DONE]') {
|
|
200
|
-
const parsed = safeParseStreamEvent(JSON.parse(line.slice(6)));
|
|
201
|
-
if (parsed.success) {
|
|
202
|
-
const event = parsed.data;
|
|
203
|
-
|
|
204
|
-
switch (event.type) {
|
|
205
|
-
case 'text-delta':
|
|
206
|
-
process.stdout.write(event.delta);
|
|
207
|
-
break;
|
|
208
|
-
case 'finish':
|
|
209
|
-
console.log('\nDone:', event.finishReason);
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
176
|
## Error Recovery
|
|
219
177
|
|
|
220
178
|
The SDK handles common error scenarios:
|