@hasna/connectors 0.4.2 → 0.5.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.
- package/bin/index.js +113 -1
- package/bin/mcp.js +113 -1
- package/bin/serve.js +112 -0
- package/connectors/connect-assemblyai/.env.example +11 -0
- package/connectors/connect-assemblyai/CLAUDE.md +128 -0
- package/connectors/connect-assemblyai/README.md +193 -0
- package/connectors/connect-assemblyai/package.json +50 -0
- package/connectors/connect-assemblyai/src/api/client.ts +192 -0
- package/connectors/connect-assemblyai/src/api/index.ts +71 -0
- package/connectors/connect-assemblyai/src/cli/index.ts +384 -0
- package/connectors/connect-assemblyai/src/index.ts +19 -0
- package/connectors/connect-assemblyai/src/types/index.ts +277 -0
- package/connectors/connect-assemblyai/src/utils/config.ts +103 -0
- package/connectors/connect-assemblyai/src/utils/output.ts +119 -0
- package/connectors/connect-assemblyai/tsconfig.json +16 -0
- package/connectors/connect-baseten/.env.example +11 -0
- package/connectors/connect-baseten/CLAUDE.md +128 -0
- package/connectors/connect-baseten/README.md +193 -0
- package/connectors/connect-baseten/package.json +51 -0
- package/connectors/connect-baseten/src/api/client.ts +71 -0
- package/connectors/connect-baseten/src/api/index.ts +40 -0
- package/connectors/connect-baseten/src/cli/index.ts +244 -0
- package/connectors/connect-baseten/src/index.ts +19 -0
- package/connectors/connect-baseten/src/types/index.ts +55 -0
- package/connectors/connect-baseten/src/utils/config.ts +103 -0
- package/connectors/connect-baseten/src/utils/output.ts +119 -0
- package/connectors/connect-baseten/tsconfig.json +16 -0
- package/connectors/connect-cerebras/.env.example +11 -0
- package/connectors/connect-cerebras/CLAUDE.md +128 -0
- package/connectors/connect-cerebras/README.md +193 -0
- package/connectors/connect-cerebras/package.json +51 -0
- package/connectors/connect-cerebras/src/api/client.ts +64 -0
- package/connectors/connect-cerebras/src/api/index.ts +32 -0
- package/connectors/connect-cerebras/src/cli/index.ts +244 -0
- package/connectors/connect-cerebras/src/index.ts +19 -0
- package/connectors/connect-cerebras/src/types/index.ts +65 -0
- package/connectors/connect-cerebras/src/utils/config.ts +103 -0
- package/connectors/connect-cerebras/src/utils/output.ts +119 -0
- package/connectors/connect-cerebras/tsconfig.json +16 -0
- package/connectors/connect-cohere/.env.example +11 -0
- package/connectors/connect-cohere/CLAUDE.md +128 -0
- package/connectors/connect-cohere/README.md +193 -0
- package/connectors/connect-cohere/package.json +53 -0
- package/connectors/connect-cohere/src/api/client.ts +109 -0
- package/connectors/connect-cohere/src/api/index.ts +59 -0
- package/connectors/connect-cohere/src/cli/index.ts +255 -0
- package/connectors/connect-cohere/src/index.ts +19 -0
- package/connectors/connect-cohere/src/types/index.ts +132 -0
- package/connectors/connect-cohere/src/utils/config.ts +197 -0
- package/connectors/connect-cohere/src/utils/output.ts +119 -0
- package/connectors/connect-cohere/tsconfig.json +16 -0
- package/connectors/connect-deepgram/.env.example +11 -0
- package/connectors/connect-deepgram/CLAUDE.md +128 -0
- package/connectors/connect-deepgram/README.md +193 -0
- package/connectors/connect-deepgram/package.json +51 -0
- package/connectors/connect-deepgram/src/api/client.ts +235 -0
- package/connectors/connect-deepgram/src/api/index.ts +57 -0
- package/connectors/connect-deepgram/src/cli/index.ts +339 -0
- package/connectors/connect-deepgram/src/index.ts +19 -0
- package/connectors/connect-deepgram/src/types/index.ts +232 -0
- package/connectors/connect-deepgram/src/utils/config.ts +103 -0
- package/connectors/connect-deepgram/src/utils/output.ts +119 -0
- package/connectors/connect-deepgram/tsconfig.json +16 -0
- package/connectors/connect-deepseek/.env.example +11 -0
- package/connectors/connect-deepseek/CLAUDE.md +128 -0
- package/connectors/connect-deepseek/README.md +193 -0
- package/connectors/connect-deepseek/package.json +51 -0
- package/connectors/connect-deepseek/src/api/client.ts +108 -0
- package/connectors/connect-deepseek/src/api/index.ts +36 -0
- package/connectors/connect-deepseek/src/cli/index.ts +167 -0
- package/connectors/connect-deepseek/src/index.ts +19 -0
- package/connectors/connect-deepseek/src/types/index.ts +72 -0
- package/connectors/connect-deepseek/src/utils/config.ts +103 -0
- package/connectors/connect-deepseek/src/utils/output.ts +119 -0
- package/connectors/connect-deepseek/tsconfig.json +16 -0
- package/connectors/connect-fal/.env.example +11 -0
- package/connectors/connect-fal/CLAUDE.md +128 -0
- package/connectors/connect-fal/README.md +193 -0
- package/connectors/connect-fal/package.json +51 -0
- package/connectors/connect-fal/src/api/client.ts +172 -0
- package/connectors/connect-fal/src/api/index.ts +55 -0
- package/connectors/connect-fal/src/cli/index.ts +341 -0
- package/connectors/connect-fal/src/index.ts +19 -0
- package/connectors/connect-fal/src/types/index.ts +135 -0
- package/connectors/connect-fal/src/utils/config.ts +103 -0
- package/connectors/connect-fal/src/utils/output.ts +119 -0
- package/connectors/connect-fal/tsconfig.json +16 -0
- package/connectors/connect-fireworks/.env.example +11 -0
- package/connectors/connect-fireworks/CLAUDE.md +128 -0
- package/connectors/connect-fireworks/README.md +193 -0
- package/connectors/connect-fireworks/package.json +51 -0
- package/connectors/connect-fireworks/src/api/client.ts +63 -0
- package/connectors/connect-fireworks/src/api/index.ts +36 -0
- package/connectors/connect-fireworks/src/cli/index.ts +244 -0
- package/connectors/connect-fireworks/src/index.ts +19 -0
- package/connectors/connect-fireworks/src/types/index.ts +70 -0
- package/connectors/connect-fireworks/src/utils/config.ts +103 -0
- package/connectors/connect-fireworks/src/utils/output.ts +119 -0
- package/connectors/connect-fireworks/tsconfig.json +16 -0
- package/connectors/connect-groq/.env.example +11 -0
- package/connectors/connect-groq/CLAUDE.md +128 -0
- package/connectors/connect-groq/README.md +193 -0
- package/connectors/connect-groq/package.json +52 -0
- package/connectors/connect-groq/src/api/client.ts +108 -0
- package/connectors/connect-groq/src/api/index.ts +36 -0
- package/connectors/connect-groq/src/cli/index.ts +171 -0
- package/connectors/connect-groq/src/index.ts +19 -0
- package/connectors/connect-groq/src/types/index.ts +69 -0
- package/connectors/connect-groq/src/utils/config.ts +103 -0
- package/connectors/connect-groq/src/utils/output.ts +119 -0
- package/connectors/connect-groq/tsconfig.json +16 -0
- package/connectors/connect-luma/.env.example +11 -0
- package/connectors/connect-luma/CLAUDE.md +128 -0
- package/connectors/connect-luma/README.md +193 -0
- package/connectors/connect-luma/package.json +53 -0
- package/connectors/connect-luma/src/api/client.ts +85 -0
- package/connectors/connect-luma/src/api/index.ts +44 -0
- package/connectors/connect-luma/src/cli/index.ts +300 -0
- package/connectors/connect-luma/src/index.ts +19 -0
- package/connectors/connect-luma/src/types/index.ts +60 -0
- package/connectors/connect-luma/src/utils/config.ts +103 -0
- package/connectors/connect-luma/src/utils/output.ts +119 -0
- package/connectors/connect-luma/tsconfig.json +16 -0
- package/connectors/connect-modal/.env.example +11 -0
- package/connectors/connect-modal/CLAUDE.md +128 -0
- package/connectors/connect-modal/README.md +193 -0
- package/connectors/connect-modal/package.json +51 -0
- package/connectors/connect-modal/src/api/client.ts +119 -0
- package/connectors/connect-modal/src/api/index.ts +69 -0
- package/connectors/connect-modal/src/cli/index.ts +224 -0
- package/connectors/connect-modal/src/index.ts +21 -0
- package/connectors/connect-modal/src/types/index.ts +60 -0
- package/connectors/connect-modal/src/utils/config.ts +114 -0
- package/connectors/connect-modal/src/utils/output.ts +119 -0
- package/connectors/connect-modal/tsconfig.json +16 -0
- package/connectors/connect-perplexity/.env.example +4 -0
- package/connectors/connect-perplexity/CLAUDE.md +156 -0
- package/connectors/connect-perplexity/README.md +184 -0
- package/connectors/connect-perplexity/package.json +58 -0
- package/connectors/connect-perplexity/scripts/publish.ts +210 -0
- package/connectors/connect-perplexity/src/api/client.ts +119 -0
- package/connectors/connect-perplexity/src/api/example.ts +118 -0
- package/connectors/connect-perplexity/src/api/index.ts +48 -0
- package/connectors/connect-perplexity/src/cli/index.ts +421 -0
- package/connectors/connect-perplexity/src/index.ts +24 -0
- package/connectors/connect-perplexity/src/types/index.ts +140 -0
- package/connectors/connect-perplexity/src/utils/config.ts +208 -0
- package/connectors/connect-perplexity/src/utils/output.ts +119 -0
- package/connectors/connect-perplexity/tsconfig.json +16 -0
- package/connectors/connect-replicate/.env.example +11 -0
- package/connectors/connect-replicate/CLAUDE.md +128 -0
- package/connectors/connect-replicate/README.md +193 -0
- package/connectors/connect-replicate/package.json +51 -0
- package/connectors/connect-replicate/src/api/client.ts +109 -0
- package/connectors/connect-replicate/src/api/index.ts +71 -0
- package/connectors/connect-replicate/src/cli/index.ts +250 -0
- package/connectors/connect-replicate/src/index.ts +19 -0
- package/connectors/connect-replicate/src/types/index.ts +85 -0
- package/connectors/connect-replicate/src/utils/config.ts +103 -0
- package/connectors/connect-replicate/src/utils/output.ts +119 -0
- package/connectors/connect-replicate/tsconfig.json +16 -0
- package/connectors/connect-roboflow/.env.example +11 -0
- package/connectors/connect-roboflow/CLAUDE.md +272 -0
- package/connectors/connect-roboflow/README.md +193 -0
- package/connectors/connect-roboflow/package.json +51 -0
- package/connectors/connect-roboflow/scripts/release.ts +179 -0
- package/connectors/connect-roboflow/src/api/client.ts +213 -0
- package/connectors/connect-roboflow/src/api/example.ts +48 -0
- package/connectors/connect-roboflow/src/api/index.ts +51 -0
- package/connectors/connect-roboflow/src/cli/index.ts +254 -0
- package/connectors/connect-roboflow/src/index.ts +103 -0
- package/connectors/connect-roboflow/src/types/index.ts +237 -0
- package/connectors/connect-roboflow/src/utils/auth.ts +274 -0
- package/connectors/connect-roboflow/src/utils/bulk.ts +212 -0
- package/connectors/connect-roboflow/src/utils/config.ts +326 -0
- package/connectors/connect-roboflow/src/utils/output.ts +175 -0
- package/connectors/connect-roboflow/src/utils/settings.ts +114 -0
- package/connectors/connect-roboflow/src/utils/storage.ts +198 -0
- package/connectors/connect-roboflow/tsconfig.json +16 -0
- package/connectors/connect-runway/.env.example +11 -0
- package/connectors/connect-runway/CLAUDE.md +128 -0
- package/connectors/connect-runway/README.md +193 -0
- package/connectors/connect-runway/package.json +52 -0
- package/connectors/connect-runway/src/api/client.ts +78 -0
- package/connectors/connect-runway/src/api/index.ts +40 -0
- package/connectors/connect-runway/src/cli/index.ts +283 -0
- package/connectors/connect-runway/src/index.ts +19 -0
- package/connectors/connect-runway/src/types/index.ts +52 -0
- package/connectors/connect-runway/src/utils/config.ts +103 -0
- package/connectors/connect-runway/src/utils/output.ts +119 -0
- package/connectors/connect-runway/tsconfig.json +16 -0
- package/connectors/connect-together/.env.example +11 -0
- package/connectors/connect-together/CLAUDE.md +128 -0
- package/connectors/connect-together/README.md +193 -0
- package/connectors/connect-together/package.json +52 -0
- package/connectors/connect-together/src/api/client.ts +106 -0
- package/connectors/connect-together/src/api/index.ts +47 -0
- package/connectors/connect-together/src/cli/index.ts +228 -0
- package/connectors/connect-together/src/index.ts +19 -0
- package/connectors/connect-together/src/types/index.ts +91 -0
- package/connectors/connect-together/src/utils/config.ts +142 -0
- package/connectors/connect-together/src/utils/output.ts +119 -0
- package/connectors/connect-together/tsconfig.json +16 -0
- package/dist/index.js +112 -0
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Groq } from '../api';
|
|
5
|
+
import {
|
|
6
|
+
getApiKey, setApiKey, clearConfig, getConfigDir, setProfileOverride,
|
|
7
|
+
getCurrentProfile, setCurrentProfile, listProfiles, createProfile,
|
|
8
|
+
deleteProfile, profileExists, loadProfile,
|
|
9
|
+
} from '../utils/config';
|
|
10
|
+
import type { OutputFormat } from '../utils/output';
|
|
11
|
+
import { success, error, info, print } from '../utils/output';
|
|
12
|
+
|
|
13
|
+
const CONNECTOR_NAME = 'connect-groq';
|
|
14
|
+
const VERSION = '0.0.1';
|
|
15
|
+
|
|
16
|
+
const program = new Command();
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.name(CONNECTOR_NAME)
|
|
20
|
+
.description('Groq AI connector CLI - Ultra-fast LLM inference')
|
|
21
|
+
.version(VERSION)
|
|
22
|
+
.option('-f, --format <format>', 'Output format (json, pretty)', 'pretty')
|
|
23
|
+
.option('-p, --profile <profile>', 'Use a specific profile')
|
|
24
|
+
.hook('preAction', (thisCommand) => {
|
|
25
|
+
const opts = thisCommand.opts();
|
|
26
|
+
if (opts.profile) {
|
|
27
|
+
if (!profileExists(opts.profile)) {
|
|
28
|
+
error(`Profile "${opts.profile}" does not exist`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
setProfileOverride(opts.profile);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function getFormat(cmd: Command): OutputFormat {
|
|
36
|
+
const parent = cmd.parent;
|
|
37
|
+
return (parent?.opts().format || 'pretty') as OutputFormat;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getClient(): Groq {
|
|
41
|
+
const apiKey = getApiKey();
|
|
42
|
+
if (!apiKey) {
|
|
43
|
+
error(`No API key configured. Run "${CONNECTOR_NAME} config set-key <key>" or set GROQ_API_KEY`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
return new Groq({ apiKey });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Profile Commands
|
|
50
|
+
const profileCmd = program.command('profile').description('Manage profiles');
|
|
51
|
+
|
|
52
|
+
profileCmd.command('list').description('List profiles').action(() => {
|
|
53
|
+
const profiles = listProfiles();
|
|
54
|
+
const current = getCurrentProfile();
|
|
55
|
+
if (profiles.length === 0) { info('No profiles found'); return; }
|
|
56
|
+
profiles.forEach(p => {
|
|
57
|
+
console.log(` ${p}${p === current ? chalk.green(' (active)') : ''}`);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
profileCmd.command('use <name>').description('Switch profile').action((name: string) => {
|
|
62
|
+
if (!profileExists(name)) { error(`Profile "${name}" does not exist`); process.exit(1); }
|
|
63
|
+
setCurrentProfile(name);
|
|
64
|
+
success(`Switched to profile: ${name}`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
profileCmd.command('create <name>').description('Create profile')
|
|
68
|
+
.option('--api-key <key>', 'API key')
|
|
69
|
+
.option('--use', 'Switch to this profile')
|
|
70
|
+
.action((name: string, opts) => {
|
|
71
|
+
if (profileExists(name)) { error(`Profile "${name}" already exists`); process.exit(1); }
|
|
72
|
+
createProfile(name, { apiKey: opts.apiKey });
|
|
73
|
+
success(`Profile "${name}" created`);
|
|
74
|
+
if (opts.use) { setCurrentProfile(name); info(`Switched to profile: ${name}`); }
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
profileCmd.command('delete <name>').description('Delete profile').action((name: string) => {
|
|
78
|
+
if (name === 'default') { error('Cannot delete default profile'); process.exit(1); }
|
|
79
|
+
if (deleteProfile(name)) { success(`Profile "${name}" deleted`); }
|
|
80
|
+
else { error(`Profile "${name}" not found`); process.exit(1); }
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
profileCmd.command('show [name]').description('Show profile').action((name?: string) => {
|
|
84
|
+
const profileName = name || getCurrentProfile();
|
|
85
|
+
const config = loadProfile(profileName);
|
|
86
|
+
console.log(chalk.bold(`Profile: ${profileName}`));
|
|
87
|
+
info(`API Key: ${config.apiKey ? config.apiKey.substring(0, 8) + '...' : chalk.gray('not set')}`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Config Commands
|
|
91
|
+
const configCmd = program.command('config').description('Manage configuration');
|
|
92
|
+
|
|
93
|
+
configCmd.command('set-key <apiKey>').description('Set API key').action((apiKey: string) => {
|
|
94
|
+
setApiKey(apiKey);
|
|
95
|
+
success(`API key saved`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
configCmd.command('show').description('Show config').action(() => {
|
|
99
|
+
console.log(chalk.bold(`Profile: ${getCurrentProfile()}`));
|
|
100
|
+
info(`Config dir: ${getConfigDir()}`);
|
|
101
|
+
const apiKey = getApiKey();
|
|
102
|
+
info(`API Key: ${apiKey ? apiKey.substring(0, 8) + '...' : chalk.gray('not set')}`);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
configCmd.command('clear').description('Clear config').action(() => {
|
|
106
|
+
clearConfig();
|
|
107
|
+
success('Config cleared');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Chat Command
|
|
111
|
+
program.command('chat <message>')
|
|
112
|
+
.description('Send a chat message')
|
|
113
|
+
.option('-m, --model <model>', 'Model (default: llama3-8b-8192)', 'llama3-8b-8192')
|
|
114
|
+
.option('-t, --temperature <temp>', 'Temperature')
|
|
115
|
+
.option('--max-tokens <n>', 'Max tokens')
|
|
116
|
+
.option('-s, --system <prompt>', 'System prompt')
|
|
117
|
+
.action(async (message: string, opts) => {
|
|
118
|
+
try {
|
|
119
|
+
const client = getClient();
|
|
120
|
+
const messages: { role: 'system' | 'user'; content: string }[] = [];
|
|
121
|
+
if (opts.system) messages.push({ role: 'system', content: opts.system });
|
|
122
|
+
messages.push({ role: 'user', content: message });
|
|
123
|
+
|
|
124
|
+
const result = await client.chat({
|
|
125
|
+
model: opts.model,
|
|
126
|
+
messages,
|
|
127
|
+
temperature: opts.temperature ? parseFloat(opts.temperature) : undefined,
|
|
128
|
+
max_tokens: opts.maxTokens ? parseInt(opts.maxTokens) : undefined,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (getFormat(program) === 'json') {
|
|
132
|
+
print(result, 'json');
|
|
133
|
+
} else {
|
|
134
|
+
console.log(chalk.green('\nResponse:'));
|
|
135
|
+
console.log(result.choices[0]?.message?.content || '');
|
|
136
|
+
if (result.usage) {
|
|
137
|
+
info(`\nTokens: ${result.usage.prompt_tokens} in, ${result.usage.completion_tokens} out`);
|
|
138
|
+
if (result.usage.total_time) {
|
|
139
|
+
info(`Time: ${(result.usage.total_time * 1000).toFixed(0)}ms`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
error(String(err));
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Models Command
|
|
150
|
+
program.command('models')
|
|
151
|
+
.description('List available models')
|
|
152
|
+
.action(async () => {
|
|
153
|
+
try {
|
|
154
|
+
const client = getClient();
|
|
155
|
+
const result = await client.listModels();
|
|
156
|
+
if (getFormat(program) === 'json') {
|
|
157
|
+
print(result.data, 'json');
|
|
158
|
+
} else {
|
|
159
|
+
result.data.forEach(m => {
|
|
160
|
+
console.log(chalk.cyan(`\n${m.id}`));
|
|
161
|
+
if (m.owned_by) console.log(` Owner: ${m.owned_by}`);
|
|
162
|
+
if (m.context_window) console.log(` Context: ${m.context_window}`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
} catch (err) {
|
|
166
|
+
error(String(err));
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
program.parse();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Groq Connector
|
|
2
|
+
// TypeScript wrapper for Groq AI API
|
|
3
|
+
|
|
4
|
+
export { Groq } from './api';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { GroqClient } from './api';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
getApiKey,
|
|
10
|
+
setApiKey,
|
|
11
|
+
getCurrentProfile,
|
|
12
|
+
setCurrentProfile,
|
|
13
|
+
listProfiles,
|
|
14
|
+
createProfile,
|
|
15
|
+
deleteProfile,
|
|
16
|
+
loadProfile,
|
|
17
|
+
saveProfile,
|
|
18
|
+
clearConfig,
|
|
19
|
+
} from './utils/config';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Groq Connector Types
|
|
2
|
+
|
|
3
|
+
export interface GroqConfig {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type OutputFormat = 'json' | 'pretty';
|
|
9
|
+
|
|
10
|
+
export interface ChatMessage {
|
|
11
|
+
role: 'system' | 'user' | 'assistant';
|
|
12
|
+
content: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ChatRequest {
|
|
16
|
+
model: string;
|
|
17
|
+
messages: ChatMessage[];
|
|
18
|
+
max_tokens?: number;
|
|
19
|
+
temperature?: number;
|
|
20
|
+
top_p?: number;
|
|
21
|
+
stop?: string[];
|
|
22
|
+
stream?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ChatChoice {
|
|
26
|
+
index: number;
|
|
27
|
+
message: ChatMessage;
|
|
28
|
+
finish_reason: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ChatResponse {
|
|
32
|
+
id: string;
|
|
33
|
+
object: string;
|
|
34
|
+
created: number;
|
|
35
|
+
model: string;
|
|
36
|
+
choices: ChatChoice[];
|
|
37
|
+
usage?: {
|
|
38
|
+
prompt_tokens: number;
|
|
39
|
+
completion_tokens: number;
|
|
40
|
+
total_tokens: number;
|
|
41
|
+
queue_time?: number;
|
|
42
|
+
prompt_time?: number;
|
|
43
|
+
completion_time?: number;
|
|
44
|
+
total_time?: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GroqModel {
|
|
49
|
+
id: string;
|
|
50
|
+
object: string;
|
|
51
|
+
created: number;
|
|
52
|
+
owned_by: string;
|
|
53
|
+
context_window?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ModelsResponse {
|
|
57
|
+
object: string;
|
|
58
|
+
data: GroqModel[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class GroqApiError extends Error {
|
|
62
|
+
public readonly statusCode: number;
|
|
63
|
+
|
|
64
|
+
constructor(message: string, statusCode: number) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = 'GroqApiError';
|
|
67
|
+
this.statusCode = statusCode;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync } from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
const CONNECTOR_NAME = 'connect-groq';
|
|
6
|
+
const DEFAULT_PROFILE = 'default';
|
|
7
|
+
|
|
8
|
+
export interface ProfileConfig {
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let profileOverride: string | undefined;
|
|
13
|
+
|
|
14
|
+
const CONFIG_DIR = join(homedir(), '.connect', CONNECTOR_NAME);
|
|
15
|
+
const PROFILES_DIR = join(CONFIG_DIR, 'profiles');
|
|
16
|
+
const CURRENT_PROFILE_FILE = join(CONFIG_DIR, 'current_profile');
|
|
17
|
+
|
|
18
|
+
export function setProfileOverride(profile: string | undefined): void {
|
|
19
|
+
profileOverride = profile;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ensureConfigDir(): void {
|
|
23
|
+
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
24
|
+
if (!existsSync(PROFILES_DIR)) mkdirSync(PROFILES_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getProfilePath(profile: string): string {
|
|
28
|
+
return join(PROFILES_DIR, `${profile}.json`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getCurrentProfile(): string {
|
|
32
|
+
if (profileOverride) return profileOverride;
|
|
33
|
+
ensureConfigDir();
|
|
34
|
+
if (existsSync(CURRENT_PROFILE_FILE)) {
|
|
35
|
+
try {
|
|
36
|
+
const profile = readFileSync(CURRENT_PROFILE_FILE, 'utf-8').trim();
|
|
37
|
+
if (profile && profileExists(profile)) return profile;
|
|
38
|
+
} catch { /* fall through */ }
|
|
39
|
+
}
|
|
40
|
+
return DEFAULT_PROFILE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function setCurrentProfile(profile: string): void {
|
|
44
|
+
ensureConfigDir();
|
|
45
|
+
if (!profileExists(profile) && profile !== DEFAULT_PROFILE) {
|
|
46
|
+
throw new Error(`Profile "${profile}" does not exist`);
|
|
47
|
+
}
|
|
48
|
+
writeFileSync(CURRENT_PROFILE_FILE, profile);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function profileExists(profile: string): boolean {
|
|
52
|
+
return existsSync(getProfilePath(profile));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function listProfiles(): string[] {
|
|
56
|
+
ensureConfigDir();
|
|
57
|
+
if (!existsSync(PROFILES_DIR)) return [];
|
|
58
|
+
return readdirSync(PROFILES_DIR).filter(f => f.endsWith('.json')).map(f => f.replace('.json', '')).sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createProfile(profile: string, config: ProfileConfig = {}): boolean {
|
|
62
|
+
ensureConfigDir();
|
|
63
|
+
if (profileExists(profile)) return false;
|
|
64
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(profile)) {
|
|
65
|
+
throw new Error('Profile name can only contain letters, numbers, hyphens, and underscores');
|
|
66
|
+
}
|
|
67
|
+
writeFileSync(getProfilePath(profile), JSON.stringify(config, null, 2));
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function deleteProfile(profile: string): boolean {
|
|
72
|
+
if (profile === DEFAULT_PROFILE) return false;
|
|
73
|
+
if (!profileExists(profile)) return false;
|
|
74
|
+
if (getCurrentProfile() === profile) setCurrentProfile(DEFAULT_PROFILE);
|
|
75
|
+
rmSync(getProfilePath(profile));
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function loadProfile(profile?: string): ProfileConfig {
|
|
80
|
+
ensureConfigDir();
|
|
81
|
+
const profilePath = getProfilePath(profile || getCurrentProfile());
|
|
82
|
+
if (!existsSync(profilePath)) return {};
|
|
83
|
+
try { return JSON.parse(readFileSync(profilePath, 'utf-8')); } catch { return {}; }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function saveProfile(config: ProfileConfig, profile?: string): void {
|
|
87
|
+
ensureConfigDir();
|
|
88
|
+
writeFileSync(getProfilePath(profile || getCurrentProfile()), JSON.stringify(config, null, 2));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getApiKey(): string | undefined {
|
|
92
|
+
return process.env.GROQ_API_KEY || loadProfile().apiKey;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function setApiKey(apiKey: string): void {
|
|
96
|
+
const config = loadProfile();
|
|
97
|
+
config.apiKey = apiKey;
|
|
98
|
+
saveProfile(config);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function clearConfig(): void { saveProfile({}); }
|
|
102
|
+
export function getConfigDir(): string { return CONFIG_DIR; }
|
|
103
|
+
export function getActiveProfileName(): string { return getCurrentProfile(); }
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
export type OutputFormat = 'json' | 'table' | 'pretty';
|
|
4
|
+
|
|
5
|
+
export function formatOutput(data: unknown, format: OutputFormat = 'pretty'): string {
|
|
6
|
+
switch (format) {
|
|
7
|
+
case 'json':
|
|
8
|
+
return JSON.stringify(data, null, 2);
|
|
9
|
+
case 'table':
|
|
10
|
+
return formatAsTable(data);
|
|
11
|
+
case 'pretty':
|
|
12
|
+
default:
|
|
13
|
+
return formatPretty(data);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function formatAsTable(data: unknown): string {
|
|
18
|
+
if (!Array.isArray(data)) {
|
|
19
|
+
data = [data];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const items = data as Record<string, unknown>[];
|
|
23
|
+
if (items.length === 0) {
|
|
24
|
+
return 'No data';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const firstItem = items[0];
|
|
28
|
+
if (!firstItem || typeof firstItem !== 'object') {
|
|
29
|
+
return 'No data';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const keys = Object.keys(firstItem);
|
|
33
|
+
const colWidths = keys.map(key => {
|
|
34
|
+
const maxValue = Math.max(
|
|
35
|
+
key.length,
|
|
36
|
+
...items.map(item => String(item[key] ?? '').length)
|
|
37
|
+
);
|
|
38
|
+
return Math.min(maxValue, 40);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const header = keys.map((key, i) => key.padEnd(colWidths[i] ?? 10)).join(' | ');
|
|
42
|
+
const separator = colWidths.map(w => '-'.repeat(w)).join('-+-');
|
|
43
|
+
|
|
44
|
+
const rows = items.map(item =>
|
|
45
|
+
keys.map((key, i) => {
|
|
46
|
+
const value = String(item[key] ?? '');
|
|
47
|
+
const width = colWidths[i] ?? 10;
|
|
48
|
+
return value.length > width
|
|
49
|
+
? value.substring(0, width - 3) + '...'
|
|
50
|
+
: value.padEnd(width);
|
|
51
|
+
}).join(' | ')
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return [header, separator, ...rows].join('\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function formatPretty(data: unknown): string {
|
|
58
|
+
if (Array.isArray(data)) {
|
|
59
|
+
return data.map((item, i) => `${chalk.cyan(`[${i + 1}]`)} ${formatPrettyItem(item)}`).join('\n\n');
|
|
60
|
+
}
|
|
61
|
+
return formatPrettyItem(data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function formatPrettyItem(item: unknown, indent = 0): string {
|
|
65
|
+
if (item === null || item === undefined) {
|
|
66
|
+
return chalk.gray('null');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof item !== 'object') {
|
|
70
|
+
return String(item);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const spaces = ' '.repeat(indent);
|
|
74
|
+
const entries = Object.entries(item as Record<string, unknown>);
|
|
75
|
+
|
|
76
|
+
return entries
|
|
77
|
+
.map(([key, value]) => {
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
if (value.length === 0) {
|
|
80
|
+
return `${spaces}${chalk.blue(key)}: ${chalk.gray('[]')}`;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value[0] === 'object') {
|
|
83
|
+
return `${spaces}${chalk.blue(key)}:\n${value.map(v => formatPrettyItem(v, indent + 1)).join('\n')}`;
|
|
84
|
+
}
|
|
85
|
+
return `${spaces}${chalk.blue(key)}: ${value.join(', ')}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof value === 'object' && value !== null) {
|
|
89
|
+
return `${spaces}${chalk.blue(key)}:\n${formatPrettyItem(value, indent + 1)}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return `${spaces}${chalk.blue(key)}: ${chalk.white(String(value))}`;
|
|
93
|
+
})
|
|
94
|
+
.join('\n');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function success(message: string): void {
|
|
98
|
+
console.log(chalk.green('✓'), message);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function error(message: string): void {
|
|
102
|
+
console.error(chalk.red('✗'), message);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function warn(message: string): void {
|
|
106
|
+
console.warn(chalk.yellow('⚠'), message);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function info(message: string): void {
|
|
110
|
+
console.log(chalk.blue('ℹ'), message);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function heading(message: string): void {
|
|
114
|
+
console.log(chalk.bold.cyan(`\n${message}\n`));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function print(data: unknown, format: OutputFormat = 'pretty'): void {
|
|
118
|
+
console.log(formatOutput(data, format));
|
|
119
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"types": ["bun-types"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"],
|
|
15
|
+
"exclude": ["node_modules", "dist", "bin"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# API Credentials
|
|
2
|
+
# TODO: Update variable names and instructions for your API
|
|
3
|
+
# Example: PERPLEXITY_API_KEY, OPENAI_API_KEY, etc.
|
|
4
|
+
|
|
5
|
+
CONNECTOR_API_KEY=your-api-key-here
|
|
6
|
+
|
|
7
|
+
# Optional: API secret (if your API requires it)
|
|
8
|
+
# CONNECTOR_API_SECRET=your-api-secret-here
|
|
9
|
+
|
|
10
|
+
# Optional: Custom base URL (if needed)
|
|
11
|
+
# CONNECTOR_BASE_URL=https://api.example.com
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
scaffold-connector is a TypeScript template for building API connector CLIs. It provides multi-profile configuration, Bearer token authentication (customizable), and a clean CLI structure using Commander.js.
|
|
8
|
+
|
|
9
|
+
**This is a SCAFFOLD** - meant to be cloned and customized for specific APIs.
|
|
10
|
+
|
|
11
|
+
## Build & Run Commands
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Install dependencies
|
|
15
|
+
bun install
|
|
16
|
+
|
|
17
|
+
# Run CLI in development
|
|
18
|
+
bun run dev
|
|
19
|
+
|
|
20
|
+
# Build for distribution
|
|
21
|
+
bun run build
|
|
22
|
+
|
|
23
|
+
# Type check
|
|
24
|
+
bun run typecheck
|
|
25
|
+
|
|
26
|
+
# Run specific commands
|
|
27
|
+
bun run dev profile list
|
|
28
|
+
bun run dev config show
|
|
29
|
+
bun run dev example list
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Code Style
|
|
33
|
+
|
|
34
|
+
- TypeScript with strict mode
|
|
35
|
+
- ESM modules (type: module)
|
|
36
|
+
- Use async/await for all async operations
|
|
37
|
+
- Minimal dependencies: commander, chalk only
|
|
38
|
+
- Type annotations required everywhere
|
|
39
|
+
- Use interfaces for all API types
|
|
40
|
+
|
|
41
|
+
## Project Structure
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
src/
|
|
45
|
+
├── api/
|
|
46
|
+
│ ├── client.ts # HTTP client with authentication
|
|
47
|
+
│ ├── example.ts # Example API module (template)
|
|
48
|
+
│ └── index.ts # Main connector class
|
|
49
|
+
├── cli/
|
|
50
|
+
│ └── index.ts # CLI commands
|
|
51
|
+
├── types/
|
|
52
|
+
│ └── index.ts # Type definitions
|
|
53
|
+
├── utils/
|
|
54
|
+
│ ├── config.ts # Multi-profile configuration
|
|
55
|
+
│ └── output.ts # CLI output formatting
|
|
56
|
+
└── index.ts # Library exports
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Key Patterns
|
|
60
|
+
|
|
61
|
+
### Multi-Profile Configuration
|
|
62
|
+
|
|
63
|
+
Profiles stored in `~/.connect/{connector-name}/profiles/`:
|
|
64
|
+
- Each profile is a separate JSON file
|
|
65
|
+
- `current_profile` file tracks active profile
|
|
66
|
+
- `--profile` flag overrides for single command
|
|
67
|
+
- Environment variables override profile config
|
|
68
|
+
|
|
69
|
+
### Authentication
|
|
70
|
+
|
|
71
|
+
Default is Bearer token in `src/api/client.ts`:
|
|
72
|
+
```typescript
|
|
73
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Customize for different auth methods:
|
|
77
|
+
- API Key header: `'X-API-Key': this.apiKey`
|
|
78
|
+
- Basic auth: `'Authorization': 'Basic ' + base64(key:secret)`
|
|
79
|
+
- OAuth: Add token refresh logic
|
|
80
|
+
|
|
81
|
+
### Adding New API Modules
|
|
82
|
+
|
|
83
|
+
1. Create file in `src/api/` following `example.ts` pattern
|
|
84
|
+
2. Add to exports in `src/api/index.ts`
|
|
85
|
+
3. Add types in `src/types/index.ts`
|
|
86
|
+
4. Add CLI commands in `src/cli/index.ts`
|
|
87
|
+
|
|
88
|
+
## TODO Markers
|
|
89
|
+
|
|
90
|
+
When customizing this scaffold, search for `TODO` comments:
|
|
91
|
+
|
|
92
|
+
- `src/cli/index.ts:22-24` - CONNECTOR_NAME, VERSION, description
|
|
93
|
+
- `src/utils/config.ts:5-6` - CONNECTOR_NAME, env var prefix
|
|
94
|
+
- `src/api/client.ts:5` - DEFAULT_BASE_URL
|
|
95
|
+
- `src/api/client.ts:45-48` - Authentication method
|
|
96
|
+
- `src/api/index.ts:7` - Rename Connector class
|
|
97
|
+
- `src/types/index.ts` - Replace example types
|
|
98
|
+
|
|
99
|
+
## Environment Variables
|
|
100
|
+
|
|
101
|
+
| Variable | Description |
|
|
102
|
+
|----------|-------------|
|
|
103
|
+
| `CONNECTOR_API_KEY` | API key (overrides profile) |
|
|
104
|
+
| `CONNECTOR_API_SECRET` | API secret (optional) |
|
|
105
|
+
| `CONNECTOR_BASE_URL` | Override base URL |
|
|
106
|
+
|
|
107
|
+
## Data Storage
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
~/.connect/{connector-name}/
|
|
111
|
+
├── current_profile # Active profile name
|
|
112
|
+
└── profiles/
|
|
113
|
+
├── default.json # Default profile
|
|
114
|
+
└── {name}.json # Named profiles
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Profile JSON structure:
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"apiKey": "sk-xxx",
|
|
121
|
+
"apiSecret": "optional"
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Dependencies
|
|
126
|
+
|
|
127
|
+
- commander: CLI framework
|
|
128
|
+
- chalk: Terminal styling
|