@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,228 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Together } from '../api';
|
|
5
|
+
import {
|
|
6
|
+
getApiKey,
|
|
7
|
+
setApiKey,
|
|
8
|
+
clearConfig,
|
|
9
|
+
getConfigDir,
|
|
10
|
+
setProfileOverride,
|
|
11
|
+
getCurrentProfile,
|
|
12
|
+
setCurrentProfile,
|
|
13
|
+
listProfiles,
|
|
14
|
+
createProfile,
|
|
15
|
+
deleteProfile,
|
|
16
|
+
profileExists,
|
|
17
|
+
loadProfile,
|
|
18
|
+
} from '../utils/config';
|
|
19
|
+
import type { OutputFormat } from '../utils/output';
|
|
20
|
+
import { success, error, info, print } from '../utils/output';
|
|
21
|
+
|
|
22
|
+
const CONNECTOR_NAME = 'connect-together';
|
|
23
|
+
const VERSION = '0.0.1';
|
|
24
|
+
|
|
25
|
+
const program = new Command();
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.name(CONNECTOR_NAME)
|
|
29
|
+
.description('Together AI connector CLI - Chat completions and embeddings')
|
|
30
|
+
.version(VERSION)
|
|
31
|
+
.option('-f, --format <format>', 'Output format (json, pretty)', 'pretty')
|
|
32
|
+
.option('-p, --profile <profile>', 'Use a specific profile')
|
|
33
|
+
.hook('preAction', (thisCommand) => {
|
|
34
|
+
const opts = thisCommand.opts();
|
|
35
|
+
if (opts.profile) {
|
|
36
|
+
if (!profileExists(opts.profile)) {
|
|
37
|
+
error(`Profile "${opts.profile}" does not exist`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
setProfileOverride(opts.profile);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function getFormat(cmd: Command): OutputFormat {
|
|
45
|
+
const parent = cmd.parent;
|
|
46
|
+
return (parent?.opts().format || 'pretty') as OutputFormat;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getClient(): Together {
|
|
50
|
+
const apiKey = getApiKey();
|
|
51
|
+
if (!apiKey) {
|
|
52
|
+
error(`No API key configured. Run "${CONNECTOR_NAME} config set-key <key>" or set TOGETHER_API_KEY`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
return new Together({ apiKey });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Profile Commands
|
|
59
|
+
const profileCmd = program.command('profile').description('Manage profiles');
|
|
60
|
+
|
|
61
|
+
profileCmd.command('list').description('List profiles').action(() => {
|
|
62
|
+
const profiles = listProfiles();
|
|
63
|
+
const current = getCurrentProfile();
|
|
64
|
+
if (profiles.length === 0) {
|
|
65
|
+
info('No profiles found');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
profiles.forEach(p => {
|
|
69
|
+
const marker = p === current ? chalk.green(' (active)') : '';
|
|
70
|
+
console.log(` ${p}${marker}`);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
profileCmd.command('use <name>').description('Switch profile').action((name: string) => {
|
|
75
|
+
if (!profileExists(name)) {
|
|
76
|
+
error(`Profile "${name}" does not exist`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
setCurrentProfile(name);
|
|
80
|
+
success(`Switched to profile: ${name}`);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
profileCmd.command('create <name>').description('Create profile')
|
|
84
|
+
.option('--api-key <key>', 'API key')
|
|
85
|
+
.option('--use', 'Switch to this profile')
|
|
86
|
+
.action((name: string, opts) => {
|
|
87
|
+
if (profileExists(name)) {
|
|
88
|
+
error(`Profile "${name}" already exists`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
createProfile(name, { apiKey: opts.apiKey });
|
|
92
|
+
success(`Profile "${name}" created`);
|
|
93
|
+
if (opts.use) {
|
|
94
|
+
setCurrentProfile(name);
|
|
95
|
+
info(`Switched to profile: ${name}`);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
profileCmd.command('delete <name>').description('Delete profile').action((name: string) => {
|
|
100
|
+
if (name === 'default') {
|
|
101
|
+
error('Cannot delete default profile');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
if (deleteProfile(name)) {
|
|
105
|
+
success(`Profile "${name}" deleted`);
|
|
106
|
+
} else {
|
|
107
|
+
error(`Profile "${name}" not found`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
profileCmd.command('show [name]').description('Show profile').action((name?: string) => {
|
|
113
|
+
const profileName = name || getCurrentProfile();
|
|
114
|
+
const config = loadProfile(profileName);
|
|
115
|
+
console.log(chalk.bold(`Profile: ${profileName}`));
|
|
116
|
+
info(`API Key: ${config.apiKey ? config.apiKey.substring(0, 8) + '...' : chalk.gray('not set')}`);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Config Commands
|
|
120
|
+
const configCmd = program.command('config').description('Manage configuration');
|
|
121
|
+
|
|
122
|
+
configCmd.command('set-key <apiKey>').description('Set API key').action((apiKey: string) => {
|
|
123
|
+
setApiKey(apiKey);
|
|
124
|
+
success(`API key saved`);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
configCmd.command('show').description('Show config').action(() => {
|
|
128
|
+
console.log(chalk.bold(`Profile: ${getCurrentProfile()}`));
|
|
129
|
+
info(`Config dir: ${getConfigDir()}`);
|
|
130
|
+
const apiKey = getApiKey();
|
|
131
|
+
info(`API Key: ${apiKey ? apiKey.substring(0, 8) + '...' : chalk.gray('not set')}`);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
configCmd.command('clear').description('Clear config').action(() => {
|
|
135
|
+
clearConfig();
|
|
136
|
+
success('Config cleared');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Chat Command
|
|
140
|
+
program.command('chat <message>')
|
|
141
|
+
.description('Send a chat message')
|
|
142
|
+
.requiredOption('-m, --model <model>', 'Model (e.g., meta-llama/Llama-3-70b-chat-hf)')
|
|
143
|
+
.option('-t, --temperature <temp>', 'Temperature')
|
|
144
|
+
.option('--max-tokens <n>', 'Max tokens')
|
|
145
|
+
.option('-s, --system <prompt>', 'System prompt')
|
|
146
|
+
.action(async (message: string, opts) => {
|
|
147
|
+
try {
|
|
148
|
+
const client = getClient();
|
|
149
|
+
const messages: { role: 'system' | 'user'; content: string }[] = [];
|
|
150
|
+
|
|
151
|
+
if (opts.system) {
|
|
152
|
+
messages.push({ role: 'system', content: opts.system });
|
|
153
|
+
}
|
|
154
|
+
messages.push({ role: 'user', content: message });
|
|
155
|
+
|
|
156
|
+
const result = await client.chat({
|
|
157
|
+
model: opts.model,
|
|
158
|
+
messages,
|
|
159
|
+
temperature: opts.temperature ? parseFloat(opts.temperature) : undefined,
|
|
160
|
+
max_tokens: opts.maxTokens ? parseInt(opts.maxTokens) : undefined,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
if (getFormat(program) === 'json') {
|
|
164
|
+
print(result, 'json');
|
|
165
|
+
} else {
|
|
166
|
+
console.log(chalk.green('\nResponse:'));
|
|
167
|
+
console.log(result.choices[0]?.message?.content || '');
|
|
168
|
+
if (result.usage) {
|
|
169
|
+
info(`\nTokens: ${result.usage.prompt_tokens} in, ${result.usage.completion_tokens} out`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
error(String(err));
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Embed Command
|
|
179
|
+
program.command('embed <texts...>')
|
|
180
|
+
.description('Generate embeddings')
|
|
181
|
+
.requiredOption('-m, --model <model>', 'Model (e.g., togethercomputer/m2-bert-80M-8k-retrieval)')
|
|
182
|
+
.action(async (texts: string[], opts) => {
|
|
183
|
+
try {
|
|
184
|
+
const client = getClient();
|
|
185
|
+
const result = await client.embed({
|
|
186
|
+
model: opts.model,
|
|
187
|
+
input: texts,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (getFormat(program) === 'json') {
|
|
191
|
+
print(result, 'json');
|
|
192
|
+
} else {
|
|
193
|
+
result.data.forEach((d, i) => {
|
|
194
|
+
console.log(chalk.cyan(`\n[${i + 1}] "${texts[i]?.substring(0, 40)}${(texts[i]?.length || 0) > 40 ? '...' : ''}"`));
|
|
195
|
+
console.log(`Dimension: ${d.embedding.length}`);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
error(String(err));
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Models Command
|
|
205
|
+
program.command('models')
|
|
206
|
+
.description('List available models')
|
|
207
|
+
.action(async () => {
|
|
208
|
+
try {
|
|
209
|
+
const client = getClient();
|
|
210
|
+
const result = await client.listModels();
|
|
211
|
+
|
|
212
|
+
if (getFormat(program) === 'json') {
|
|
213
|
+
print(result.data, 'json');
|
|
214
|
+
} else {
|
|
215
|
+
result.data.forEach(m => {
|
|
216
|
+
console.log(chalk.cyan(`\n${m.id}`));
|
|
217
|
+
if (m.display_name) console.log(` Name: ${m.display_name}`);
|
|
218
|
+
if (m.type) console.log(` Type: ${m.type}`);
|
|
219
|
+
if (m.context_length) console.log(` Context: ${m.context_length}`);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
} catch (err) {
|
|
223
|
+
error(String(err));
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
program.parse();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Together AI Connector
|
|
2
|
+
// TypeScript wrapper for Together AI API
|
|
3
|
+
|
|
4
|
+
export { Together } from './api';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { TogetherClient } 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,91 @@
|
|
|
1
|
+
// Together AI Connector Types
|
|
2
|
+
|
|
3
|
+
export interface TogetherConfig {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type OutputFormat = 'json' | 'pretty';
|
|
9
|
+
|
|
10
|
+
// Chat Types
|
|
11
|
+
export interface ChatMessage {
|
|
12
|
+
role: 'system' | 'user' | 'assistant';
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ChatRequest {
|
|
17
|
+
model: string;
|
|
18
|
+
messages: ChatMessage[];
|
|
19
|
+
max_tokens?: number;
|
|
20
|
+
temperature?: number;
|
|
21
|
+
top_p?: number;
|
|
22
|
+
top_k?: number;
|
|
23
|
+
stop?: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ChatChoice {
|
|
27
|
+
index: number;
|
|
28
|
+
message: ChatMessage;
|
|
29
|
+
finish_reason: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ChatResponse {
|
|
33
|
+
id: string;
|
|
34
|
+
object: string;
|
|
35
|
+
created: number;
|
|
36
|
+
model: string;
|
|
37
|
+
choices: ChatChoice[];
|
|
38
|
+
usage?: {
|
|
39
|
+
prompt_tokens: number;
|
|
40
|
+
completion_tokens: number;
|
|
41
|
+
total_tokens: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Embeddings Types
|
|
46
|
+
export interface EmbeddingRequest {
|
|
47
|
+
model: string;
|
|
48
|
+
input: string | string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface EmbeddingData {
|
|
52
|
+
object: string;
|
|
53
|
+
embedding: number[];
|
|
54
|
+
index: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface EmbeddingResponse {
|
|
58
|
+
object: string;
|
|
59
|
+
data: EmbeddingData[];
|
|
60
|
+
model: string;
|
|
61
|
+
usage?: {
|
|
62
|
+
prompt_tokens: number;
|
|
63
|
+
total_tokens: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Models Types
|
|
68
|
+
export interface TogetherModel {
|
|
69
|
+
id: string;
|
|
70
|
+
object: string;
|
|
71
|
+
created: number;
|
|
72
|
+
type: string;
|
|
73
|
+
display_name?: string;
|
|
74
|
+
context_length?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ModelsResponse {
|
|
78
|
+
object: string;
|
|
79
|
+
data: TogetherModel[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// API Error
|
|
83
|
+
export class TogetherApiError extends Error {
|
|
84
|
+
public readonly statusCode: number;
|
|
85
|
+
|
|
86
|
+
constructor(message: string, statusCode: number) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.name = 'TogetherApiError';
|
|
89
|
+
this.statusCode = statusCode;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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-together';
|
|
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)) {
|
|
24
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
if (!existsSync(PROFILES_DIR)) {
|
|
27
|
+
mkdirSync(PROFILES_DIR, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getProfilePath(profile: string): string {
|
|
32
|
+
return join(PROFILES_DIR, `${profile}.json`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getCurrentProfile(): string {
|
|
36
|
+
if (profileOverride) {
|
|
37
|
+
return profileOverride;
|
|
38
|
+
}
|
|
39
|
+
ensureConfigDir();
|
|
40
|
+
if (existsSync(CURRENT_PROFILE_FILE)) {
|
|
41
|
+
try {
|
|
42
|
+
const profile = readFileSync(CURRENT_PROFILE_FILE, 'utf-8').trim();
|
|
43
|
+
if (profile && profileExists(profile)) {
|
|
44
|
+
return profile;
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// Fall through to default
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return DEFAULT_PROFILE;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function setCurrentProfile(profile: string): void {
|
|
54
|
+
ensureConfigDir();
|
|
55
|
+
if (!profileExists(profile) && profile !== DEFAULT_PROFILE) {
|
|
56
|
+
throw new Error(`Profile "${profile}" does not exist`);
|
|
57
|
+
}
|
|
58
|
+
writeFileSync(CURRENT_PROFILE_FILE, profile);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function profileExists(profile: string): boolean {
|
|
62
|
+
return existsSync(getProfilePath(profile));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function listProfiles(): string[] {
|
|
66
|
+
ensureConfigDir();
|
|
67
|
+
if (!existsSync(PROFILES_DIR)) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return readdirSync(PROFILES_DIR)
|
|
71
|
+
.filter(f => f.endsWith('.json'))
|
|
72
|
+
.map(f => f.replace('.json', ''))
|
|
73
|
+
.sort();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function createProfile(profile: string, config: ProfileConfig = {}): boolean {
|
|
77
|
+
ensureConfigDir();
|
|
78
|
+
if (profileExists(profile)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(profile)) {
|
|
82
|
+
throw new Error('Profile name can only contain letters, numbers, hyphens, and underscores');
|
|
83
|
+
}
|
|
84
|
+
writeFileSync(getProfilePath(profile), JSON.stringify(config, null, 2));
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function deleteProfile(profile: string): boolean {
|
|
89
|
+
if (profile === DEFAULT_PROFILE) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (!profileExists(profile)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (getCurrentProfile() === profile) {
|
|
96
|
+
setCurrentProfile(DEFAULT_PROFILE);
|
|
97
|
+
}
|
|
98
|
+
rmSync(getProfilePath(profile));
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function loadProfile(profile?: string): ProfileConfig {
|
|
103
|
+
ensureConfigDir();
|
|
104
|
+
const profileName = profile || getCurrentProfile();
|
|
105
|
+
const profilePath = getProfilePath(profileName);
|
|
106
|
+
if (!existsSync(profilePath)) {
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(readFileSync(profilePath, 'utf-8'));
|
|
111
|
+
} catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function saveProfile(config: ProfileConfig, profile?: string): void {
|
|
117
|
+
ensureConfigDir();
|
|
118
|
+
const profileName = profile || getCurrentProfile();
|
|
119
|
+
writeFileSync(getProfilePath(profileName), JSON.stringify(config, null, 2));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function getApiKey(): string | undefined {
|
|
123
|
+
return process.env.TOGETHER_API_KEY || loadProfile().apiKey;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function setApiKey(apiKey: string): void {
|
|
127
|
+
const config = loadProfile();
|
|
128
|
+
config.apiKey = apiKey;
|
|
129
|
+
saveProfile(config);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function clearConfig(): void {
|
|
133
|
+
saveProfile({});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function getConfigDir(): string {
|
|
137
|
+
return CONFIG_DIR;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function getActiveProfileName(): string {
|
|
141
|
+
return getCurrentProfile();
|
|
142
|
+
}
|
|
@@ -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
|
+
}
|