thebird 1.2.16 → 1.2.17

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+ - `wasi/cli.ts`: Deno CLI — Anthropic-format prompt → Gemini streaming via REST, flags: `--model`, `--system`
7
+ - `deno.json`: tasks `cli` (run) and `cli:compile` (single binary)
package/deno.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "tasks": {
3
+ "cli": "deno run --allow-net --allow-env wasi/cli.ts",
4
+ "cli:compile": "deno compile --allow-net --allow-env --output dist/thebird wasi/cli.ts"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thebird",
3
- "version": "1.2.16",
3
+ "version": "1.2.17",
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",
package/wasi/cli.ts ADDED
@@ -0,0 +1,47 @@
1
+ const BASE = 'https://generativelanguage.googleapis.com/v1beta';
2
+
3
+ const args = Deno.args.slice();
4
+ const modelIdx = args.indexOf('--model');
5
+ const model = modelIdx >= 0 ? args.splice(modelIdx, 2)[1] : 'gemini-2.5-flash';
6
+ const sysIdx = args.indexOf('--system');
7
+ const system = sysIdx >= 0 ? args.splice(sysIdx, 2)[1] : undefined;
8
+ const prompt = args.join(' ').trim();
9
+
10
+ const apiKey = Deno.env.get('GEMINI_API_KEY');
11
+ if (!apiKey) throw new Error('GEMINI_API_KEY env var required');
12
+ if (!prompt) throw new Error('Usage: deno run --allow-net --allow-env wasi/cli.ts [--model MODEL] [--system SYSTEM] <prompt>');
13
+
14
+ const contents = [{ role: 'user', parts: [{ text: prompt }] }];
15
+ const body = { contents, generationConfig: { maxOutputTokens: 8192, temperature: 0.7 } };
16
+ if (system) body.systemInstruction = { parts: [{ text: system }] };
17
+
18
+ const res = await fetch(BASE + '/models/' + model + ':streamGenerateContent?alt=sse&key=' + apiKey, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify(body),
22
+ });
23
+ if (!res.ok) throw new Error('Gemini API ' + res.status + ': ' + await res.text());
24
+
25
+ const reader = res.body.getReader();
26
+ const dec = new TextDecoder();
27
+ const enc = new TextEncoder();
28
+ let buf = '';
29
+ while (true) {
30
+ const { done, value } = await reader.read();
31
+ if (done) break;
32
+ buf += dec.decode(value, { stream: true });
33
+ const lines = buf.split('\n');
34
+ buf = lines.pop();
35
+ for (const line of lines) {
36
+ if (!line.startsWith('data: ')) continue;
37
+ const json = line.slice(6).trim();
38
+ if (!json || json === '[DONE]') continue;
39
+ try {
40
+ const chunk = JSON.parse(json);
41
+ for (const c of (chunk.candidates || []))
42
+ for (const p of (c.content?.parts || []))
43
+ if (p.text && !p.thought) await Deno.stdout.write(enc.encode(p.text));
44
+ } catch {}
45
+ }
46
+ }
47
+ await Deno.stdout.write(enc.encode('\n'));