thebird 1.2.14 → 1.2.16

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.
Files changed (2) hide show
  1. package/docs/app.js +9 -7
  2. package/package.json +1 -1
package/docs/app.js CHANGED
@@ -14,7 +14,7 @@ async function fetchModels(apiKey) {
14
14
  .map(m => ({ id: m.name.replace('models/', ''), label: m.displayName || m.name }));
15
15
  }
16
16
 
17
- async function* streamGenerate(apiKey, model, contents) {
17
+ async function streamGenerate(apiKey, model, contents, onChunk) {
18
18
  const res = await fetch(`${BASE}/models/${model}:streamGenerateContent?alt=sse&key=${apiKey}`, {
19
19
  method: 'POST',
20
20
  headers: { 'Content-Type': 'application/json' },
@@ -38,7 +38,7 @@ async function* streamGenerate(apiKey, model, contents) {
38
38
  const chunk = JSON.parse(json);
39
39
  for (const c of (chunk.candidates || []))
40
40
  for (const p of (c.content?.parts || []))
41
- if (p.text && !p.thought) yield p.text;
41
+ if (p.text && !p.thought) onChunk(p.text);
42
42
  } catch {}
43
43
  }
44
44
  }
@@ -161,20 +161,22 @@ class BirdChat extends HTMLElement {
161
161
  const cursor = document.createElement('span');
162
162
  cursor.className = 'animate-pulse ml-1';
163
163
  cursor.textContent = '▋';
164
- const list = this.querySelector('#msg-list');
165
164
  const wrap = document.createElement('div');
166
165
  wrap.className = 'flex justify-start';
167
166
  wrap.appendChild(streamEl);
168
167
  wrap.appendChild(cursor);
168
+ const list = this.querySelector('#msg-list');
169
169
  if (list) list.appendChild(wrap);
170
- for await (const chunk of streamGenerate(apiKey, model, convertMessages(messages))) {
170
+ await streamGenerate(apiKey, model, convertMessages(messages), chunk => {
171
171
  full += chunk;
172
172
  streamEl.textContent = full;
173
- if (list) list.scrollTop = list.scrollHeight;
174
- }
173
+ const l = this.querySelector('#msg-list');
174
+ if (l) l.scrollTop = l.scrollHeight;
175
+ });
175
176
  wrap.remove();
176
177
  this.setState({ messages: [...messages, { role: 'assistant', content: full || '(empty)' }], streaming: false, streamingText: '' });
177
- if (list) list.scrollTop = list.scrollHeight;
178
+ const l2 = this.querySelector('#msg-list');
179
+ if (l2) l2.scrollTop = l2.scrollHeight;
178
180
  } catch (err) {
179
181
  this.setState({ streaming: false, streamingText: '', status: 'Error: ' + (err?.message || String(err)) });
180
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thebird",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "description": "Anthropic SDK to Gemini streaming bridge — drop-in proxy that translates Anthropic message format and tool calls to Google Gemini",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",