@camelai/tldr 0.1.0

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/bin/tldr.js +239 -0
  4. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QAML AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # tldr
2
+
3
+ A tiny CLI that summarizes text using OpenAI, Anthropic, or OpenRouter.
4
+
5
+ ## Install
6
+
7
+ ### Run locally
8
+
9
+ ```bash
10
+ npm install
11
+ node ./bin/tldr.js --help
12
+ ```
13
+
14
+ ### Install globally from npm
15
+
16
+ ```bash
17
+ npm install -g @camelai/tldr
18
+ ```
19
+
20
+ ### Install from this repo
21
+
22
+ ```bash
23
+ npm install -g github:qaml-ai/tldr
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Summarize a prompt:
29
+
30
+ ```bash
31
+ tldr "Summarize the key points from this meeting note..."
32
+ ```
33
+
34
+ Summarize stdin:
35
+
36
+ ```bash
37
+ cat notes.txt | tldr
38
+ ```
39
+
40
+ Choose a provider explicitly:
41
+
42
+ ```bash
43
+ tldr --provider openai "text"
44
+ tldr --provider anthropic "text"
45
+ tldr --provider openrouter "text"
46
+ ```
47
+
48
+ Override the model:
49
+
50
+ ```bash
51
+ tldr --provider openai --model gpt-5.4-nano "text"
52
+ tldr --provider anthropic --model claude-4-haiku-20250305 "text"
53
+ tldr --provider openrouter --model google/gemini-3.1-flash-lite-preview "text"
54
+ ```
55
+
56
+ Override the system prompt:
57
+
58
+ ```bash
59
+ tldr --system "Summarize in 3 bullet points." "text"
60
+ ```
61
+
62
+ ## Options
63
+
64
+ - `-p, --provider <name>`: `openai`, `anthropic`, or `openrouter`
65
+ - `-m, --model <model>`: override the model
66
+ - `-s, --system <prompt>`: override the summarization system prompt
67
+ - `-h, --help`: show help
68
+
69
+ ## Environment variables
70
+
71
+ API keys:
72
+
73
+ - `OPENAI_API_KEY`
74
+ - `ANTHROPIC_API_KEY`
75
+ - `OPENROUTER_API_KEY`
76
+
77
+ Defaults:
78
+
79
+ - `TLDR_SYSTEM_PROMPT`
80
+ - `TLDR_OPENAI_MODEL` default: `gpt-5.4-nano`
81
+ - `TLDR_ANTHROPIC_MODEL` default: `claude-4-haiku-20250305`
82
+ - `TLDR_OPENROUTER_MODEL` default: `google/gemini-3.1-flash-lite-preview`
83
+
84
+ Legacy env vars are also supported:
85
+
86
+ - `SUMMARIZE_SYSTEM_PROMPT`
87
+ - `SUMMARIZE_OPENAI_MODEL`
88
+ - `SUMMARIZE_ANTHROPIC_MODEL`
89
+ - `SUMMARIZE_OPENROUTER_MODEL`
90
+
91
+ ## Default model selection
92
+
93
+ If `--provider` is omitted, `tldr` picks the first available provider in this order:
94
+
95
+ 1. `OPENAI_API_KEY`
96
+ 2. `ANTHROPIC_API_KEY`
97
+ 3. `OPENROUTER_API_KEY`
98
+
99
+ ## Publish to npm
100
+
101
+ When you're ready:
102
+
103
+ ```bash
104
+ npm publish
105
+ ```
106
+
107
+ Because `publishConfig.access` is set to `public`, this package is ready for public npm publishing.
108
+
109
+ ## License
110
+
111
+ MIT
package/bin/tldr.js ADDED
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+
3
+ import process from 'node:process';
4
+
5
+ const DEFAULT_SYSTEM_PROMPT = process.env.TLDR_SYSTEM_PROMPT || process.env.SUMMARIZE_SYSTEM_PROMPT || [
6
+ 'You are a concise, accurate summarization assistant.',
7
+ 'Summarize the user input clearly and faithfully.',
8
+ 'Preserve the key facts, decisions, dates, numbers, and action items.',
9
+ 'Use short paragraphs or bullet points when that improves clarity.',
10
+ 'Do not invent details.'
11
+ ].join(' ');
12
+
13
+ function printHelp() {
14
+ console.log(`tldr - summarize text from stdin or a prompt\n\nUsage:\n tldr [options] [prompt...]\n echo "long text" | tldr [options]\n\nOptions:\n -p, --provider <name> Provider: openai | anthropic | openrouter\n -s, --system <prompt> Override the system prompt\n -m, --model <model> Override the default model for the selected provider\n -h, --help Show this help\n\nEnvironment variables:\n OPENAI_API_KEY API key for OpenAI\n ANTHROPIC_API_KEY API key for Anthropic\n OPENROUTER_API_KEY API key for OpenRouter\n TLDR_SYSTEM_PROMPT Default system prompt\n TLDR_OPENAI_MODEL Default OpenAI model (default: gpt-5.4-nano)\n TLDR_ANTHROPIC_MODEL Default Anthropic model (default: claude-4-haiku-20250305)\n TLDR_OPENROUTER_MODEL Default OpenRouter model (default: google/gemini-3.1-flash-lite-preview)\n\nLegacy env vars still supported:\n SUMMARIZE_SYSTEM_PROMPT\n SUMMARIZE_OPENAI_MODEL\n SUMMARIZE_ANTHROPIC_MODEL\n SUMMARIZE_OPENROUTER_MODEL\n`);
15
+ }
16
+
17
+ function fail(message, code = 1) {
18
+ console.error(message);
19
+ process.exit(code);
20
+ }
21
+
22
+ function parseArgs(argv) {
23
+ const args = [...argv];
24
+ let provider;
25
+ let system;
26
+ let model;
27
+ const promptParts = [];
28
+
29
+ while (args.length > 0) {
30
+ const arg = args.shift();
31
+
32
+ if (arg === '-h' || arg === '--help') {
33
+ printHelp();
34
+ process.exit(0);
35
+ }
36
+
37
+ if (arg === '-p' || arg === '--provider') {
38
+ provider = args.shift();
39
+ if (!provider) fail('Missing value for --provider');
40
+ continue;
41
+ }
42
+
43
+ if (arg.startsWith('--provider=')) {
44
+ provider = arg.split('=').slice(1).join('=');
45
+ continue;
46
+ }
47
+
48
+ if (arg === '-s' || arg === '--system') {
49
+ system = args.shift();
50
+ if (!system) fail('Missing value for --system');
51
+ continue;
52
+ }
53
+
54
+ if (arg.startsWith('--system=')) {
55
+ system = arg.split('=').slice(1).join('=');
56
+ continue;
57
+ }
58
+
59
+ if (arg === '-m' || arg === '--model') {
60
+ model = args.shift();
61
+ if (!model) fail('Missing value for --model');
62
+ continue;
63
+ }
64
+
65
+ if (arg.startsWith('--model=')) {
66
+ model = arg.split('=').slice(1).join('=');
67
+ continue;
68
+ }
69
+
70
+ promptParts.push(arg);
71
+ }
72
+
73
+ return {
74
+ provider,
75
+ system: system || DEFAULT_SYSTEM_PROMPT,
76
+ model,
77
+ prompt: promptParts.join(' ').trim()
78
+ };
79
+ }
80
+
81
+ function detectProvider(explicitProvider) {
82
+ if (explicitProvider) {
83
+ const normalized = explicitProvider.toLowerCase();
84
+ if (!['openai', 'anthropic', 'openrouter'].includes(normalized)) {
85
+ fail(`Unsupported provider: ${explicitProvider}`);
86
+ }
87
+ return normalized;
88
+ }
89
+
90
+ if (process.env.OPENAI_API_KEY) return 'openai';
91
+ if (process.env.ANTHROPIC_API_KEY) return 'anthropic';
92
+ if (process.env.OPENROUTER_API_KEY) return 'openrouter';
93
+
94
+ fail('No provider specified and no API key found in OPENAI_API_KEY, ANTHROPIC_API_KEY, or OPENROUTER_API_KEY.');
95
+ }
96
+
97
+ async function readStdinIfNeeded(prompt) {
98
+ if (prompt) return prompt;
99
+ if (process.stdin.isTTY) {
100
+ fail('No input provided. Pass a prompt argument or pipe text into stdin.');
101
+ }
102
+
103
+ const chunks = [];
104
+ for await (const chunk of process.stdin) {
105
+ chunks.push(chunk);
106
+ }
107
+
108
+ const input = Buffer.concat(chunks.map(chunk => Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))).toString('utf8').trim();
109
+ if (!input) fail('Received empty stdin input.');
110
+ return input;
111
+ }
112
+
113
+ function getModel(provider, explicitModel) {
114
+ if (explicitModel) return explicitModel;
115
+
116
+ switch (provider) {
117
+ case 'openai':
118
+ return process.env.TLDR_OPENAI_MODEL || process.env.SUMMARIZE_OPENAI_MODEL || 'gpt-5.4-nano';
119
+ case 'anthropic':
120
+ return process.env.TLDR_ANTHROPIC_MODEL || process.env.SUMMARIZE_ANTHROPIC_MODEL || 'claude-4-haiku-20250305';
121
+ case 'openrouter':
122
+ return process.env.TLDR_OPENROUTER_MODEL || process.env.SUMMARIZE_OPENROUTER_MODEL || 'google/gemini-3.1-flash-lite-preview';
123
+ default:
124
+ fail(`Unsupported provider: ${provider}`);
125
+ }
126
+ }
127
+
128
+ async function summarizeWithOpenAI({ apiKey, model, system, input }) {
129
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
130
+ method: 'POST',
131
+ headers: {
132
+ 'content-type': 'application/json',
133
+ authorization: `Bearer ${apiKey}`
134
+ },
135
+ body: JSON.stringify({
136
+ model,
137
+ messages: [
138
+ { role: 'system', content: system },
139
+ { role: 'user', content: input }
140
+ ]
141
+ })
142
+ });
143
+
144
+ const data = await response.json();
145
+ if (!response.ok) {
146
+ throw new Error(data?.error?.message || `OpenAI request failed with status ${response.status}`);
147
+ }
148
+
149
+ return data?.choices?.[0]?.message?.content?.trim() || '';
150
+ }
151
+
152
+ async function summarizeWithOpenRouter({ apiKey, model, system, input }) {
153
+ const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
154
+ method: 'POST',
155
+ headers: {
156
+ 'content-type': 'application/json',
157
+ authorization: `Bearer ${apiKey}`
158
+ },
159
+ body: JSON.stringify({
160
+ model,
161
+ messages: [
162
+ { role: 'system', content: system },
163
+ { role: 'user', content: input }
164
+ ]
165
+ })
166
+ });
167
+
168
+ const data = await response.json();
169
+ if (!response.ok) {
170
+ throw new Error(data?.error?.message || `OpenRouter request failed with status ${response.status}`);
171
+ }
172
+
173
+ return data?.choices?.[0]?.message?.content?.trim() || '';
174
+ }
175
+
176
+ async function summarizeWithAnthropic({ apiKey, model, system, input }) {
177
+ const response = await fetch('https://api.anthropic.com/v1/messages', {
178
+ method: 'POST',
179
+ headers: {
180
+ 'content-type': 'application/json',
181
+ 'x-api-key': apiKey,
182
+ 'anthropic-version': '2023-06-01'
183
+ },
184
+ body: JSON.stringify({
185
+ model,
186
+ system,
187
+ max_tokens: 1024,
188
+ messages: [
189
+ { role: 'user', content: input }
190
+ ]
191
+ })
192
+ });
193
+
194
+ const data = await response.json();
195
+ if (!response.ok) {
196
+ throw new Error(data?.error?.message || `Anthropic request failed with status ${response.status}`);
197
+ }
198
+
199
+ return (data?.content || [])
200
+ .filter(item => item?.type === 'text')
201
+ .map(item => item.text)
202
+ .join('\n')
203
+ .trim();
204
+ }
205
+
206
+ async function main() {
207
+ const { provider: explicitProvider, system, model: explicitModel, prompt } = parseArgs(process.argv.slice(2));
208
+ const provider = detectProvider(explicitProvider);
209
+ const input = await readStdinIfNeeded(prompt);
210
+ const model = getModel(provider, explicitModel);
211
+
212
+ let summary = '';
213
+
214
+ if (provider === 'openai') {
215
+ const apiKey = process.env.OPENAI_API_KEY;
216
+ if (!apiKey) fail('OPENAI_API_KEY is not set.');
217
+ summary = await summarizeWithOpenAI({ apiKey, model, system, input });
218
+ } else if (provider === 'anthropic') {
219
+ const apiKey = process.env.ANTHROPIC_API_KEY;
220
+ if (!apiKey) fail('ANTHROPIC_API_KEY is not set.');
221
+ summary = await summarizeWithAnthropic({ apiKey, model, system, input });
222
+ } else if (provider === 'openrouter') {
223
+ const apiKey = process.env.OPENROUTER_API_KEY;
224
+ if (!apiKey) fail('OPENROUTER_API_KEY is not set.');
225
+ summary = await summarizeWithOpenRouter({ apiKey, model, system, input });
226
+ } else {
227
+ fail(`Unsupported provider: ${provider}`);
228
+ }
229
+
230
+ if (!summary) {
231
+ fail('The provider returned an empty summary.');
232
+ }
233
+
234
+ process.stdout.write(summary.endsWith('\n') ? summary : `${summary}\n`);
235
+ }
236
+
237
+ main().catch(error => {
238
+ fail(error instanceof Error ? error.message : String(error));
239
+ });
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@camelai/tldr",
3
+ "version": "0.1.0",
4
+ "description": "CLI to summarize text with OpenAI, Anthropic, or OpenRouter",
5
+ "type": "module",
6
+ "bin": {
7
+ "tldr": "./bin/tldr.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node ./bin/tldr.js"
11
+ },
12
+ "keywords": [
13
+ "cli",
14
+ "summary",
15
+ "tldr",
16
+ "openai",
17
+ "anthropic",
18
+ "openrouter"
19
+ ],
20
+ "author": "QAML AI",
21
+ "license": "MIT",
22
+ "files": [
23
+ "bin",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/qaml-ai/tldr.git"
33
+ },
34
+ "homepage": "https://github.com/qaml-ai/tldr#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/qaml-ai/tldr/issues"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ }
41
+ }