thebird 1.2.16 → 1.2.18
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 +7 -0
- package/CLAUDE.md +8 -0
- package/deno.json +6 -0
- package/package.json +1 -1
- package/wasi/cli.ts +47 -0
package/CHANGELOG.md
ADDED
package/CLAUDE.md
CHANGED
|
@@ -119,3 +119,11 @@ Run examples against real Gemini API to validate message translation.
|
|
|
119
119
|
- `index.js`: Main entry point, streaming and generation wrappers
|
|
120
120
|
- `index.d.ts`: TypeScript type definitions
|
|
121
121
|
- `examples/`: Working examples using Anthropic SDK format
|
|
122
|
+
- `wasi/cli.ts`: Deno streaming CLI — `deno run --allow-net --allow-env wasi/cli.ts [--model M] [--system S] <prompt>`
|
|
123
|
+
- `deno.json`: tasks `cli` (run) and `cli:compile` (→ `dist/thebird` binary)
|
|
124
|
+
|
|
125
|
+
## Environment Notes
|
|
126
|
+
|
|
127
|
+
- Repo remote: `https://github.com/AnEntrypoint/thebird.git` (capital A)
|
|
128
|
+
- Deno 2.1.3 available; `exec:bash` uses PowerShell — use `exec:cmd` with `set KEY=val && cmd` syntax for env vars
|
|
129
|
+
- Windows `KEY=val cmd` inline env syntax fails in PowerShell
|
package/deno.json
ADDED
package/package.json
CHANGED
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'));
|