@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.
Files changed (205) hide show
  1. package/bin/index.js +113 -1
  2. package/bin/mcp.js +113 -1
  3. package/bin/serve.js +112 -0
  4. package/connectors/connect-assemblyai/.env.example +11 -0
  5. package/connectors/connect-assemblyai/CLAUDE.md +128 -0
  6. package/connectors/connect-assemblyai/README.md +193 -0
  7. package/connectors/connect-assemblyai/package.json +50 -0
  8. package/connectors/connect-assemblyai/src/api/client.ts +192 -0
  9. package/connectors/connect-assemblyai/src/api/index.ts +71 -0
  10. package/connectors/connect-assemblyai/src/cli/index.ts +384 -0
  11. package/connectors/connect-assemblyai/src/index.ts +19 -0
  12. package/connectors/connect-assemblyai/src/types/index.ts +277 -0
  13. package/connectors/connect-assemblyai/src/utils/config.ts +103 -0
  14. package/connectors/connect-assemblyai/src/utils/output.ts +119 -0
  15. package/connectors/connect-assemblyai/tsconfig.json +16 -0
  16. package/connectors/connect-baseten/.env.example +11 -0
  17. package/connectors/connect-baseten/CLAUDE.md +128 -0
  18. package/connectors/connect-baseten/README.md +193 -0
  19. package/connectors/connect-baseten/package.json +51 -0
  20. package/connectors/connect-baseten/src/api/client.ts +71 -0
  21. package/connectors/connect-baseten/src/api/index.ts +40 -0
  22. package/connectors/connect-baseten/src/cli/index.ts +244 -0
  23. package/connectors/connect-baseten/src/index.ts +19 -0
  24. package/connectors/connect-baseten/src/types/index.ts +55 -0
  25. package/connectors/connect-baseten/src/utils/config.ts +103 -0
  26. package/connectors/connect-baseten/src/utils/output.ts +119 -0
  27. package/connectors/connect-baseten/tsconfig.json +16 -0
  28. package/connectors/connect-cerebras/.env.example +11 -0
  29. package/connectors/connect-cerebras/CLAUDE.md +128 -0
  30. package/connectors/connect-cerebras/README.md +193 -0
  31. package/connectors/connect-cerebras/package.json +51 -0
  32. package/connectors/connect-cerebras/src/api/client.ts +64 -0
  33. package/connectors/connect-cerebras/src/api/index.ts +32 -0
  34. package/connectors/connect-cerebras/src/cli/index.ts +244 -0
  35. package/connectors/connect-cerebras/src/index.ts +19 -0
  36. package/connectors/connect-cerebras/src/types/index.ts +65 -0
  37. package/connectors/connect-cerebras/src/utils/config.ts +103 -0
  38. package/connectors/connect-cerebras/src/utils/output.ts +119 -0
  39. package/connectors/connect-cerebras/tsconfig.json +16 -0
  40. package/connectors/connect-cohere/.env.example +11 -0
  41. package/connectors/connect-cohere/CLAUDE.md +128 -0
  42. package/connectors/connect-cohere/README.md +193 -0
  43. package/connectors/connect-cohere/package.json +53 -0
  44. package/connectors/connect-cohere/src/api/client.ts +109 -0
  45. package/connectors/connect-cohere/src/api/index.ts +59 -0
  46. package/connectors/connect-cohere/src/cli/index.ts +255 -0
  47. package/connectors/connect-cohere/src/index.ts +19 -0
  48. package/connectors/connect-cohere/src/types/index.ts +132 -0
  49. package/connectors/connect-cohere/src/utils/config.ts +197 -0
  50. package/connectors/connect-cohere/src/utils/output.ts +119 -0
  51. package/connectors/connect-cohere/tsconfig.json +16 -0
  52. package/connectors/connect-deepgram/.env.example +11 -0
  53. package/connectors/connect-deepgram/CLAUDE.md +128 -0
  54. package/connectors/connect-deepgram/README.md +193 -0
  55. package/connectors/connect-deepgram/package.json +51 -0
  56. package/connectors/connect-deepgram/src/api/client.ts +235 -0
  57. package/connectors/connect-deepgram/src/api/index.ts +57 -0
  58. package/connectors/connect-deepgram/src/cli/index.ts +339 -0
  59. package/connectors/connect-deepgram/src/index.ts +19 -0
  60. package/connectors/connect-deepgram/src/types/index.ts +232 -0
  61. package/connectors/connect-deepgram/src/utils/config.ts +103 -0
  62. package/connectors/connect-deepgram/src/utils/output.ts +119 -0
  63. package/connectors/connect-deepgram/tsconfig.json +16 -0
  64. package/connectors/connect-deepseek/.env.example +11 -0
  65. package/connectors/connect-deepseek/CLAUDE.md +128 -0
  66. package/connectors/connect-deepseek/README.md +193 -0
  67. package/connectors/connect-deepseek/package.json +51 -0
  68. package/connectors/connect-deepseek/src/api/client.ts +108 -0
  69. package/connectors/connect-deepseek/src/api/index.ts +36 -0
  70. package/connectors/connect-deepseek/src/cli/index.ts +167 -0
  71. package/connectors/connect-deepseek/src/index.ts +19 -0
  72. package/connectors/connect-deepseek/src/types/index.ts +72 -0
  73. package/connectors/connect-deepseek/src/utils/config.ts +103 -0
  74. package/connectors/connect-deepseek/src/utils/output.ts +119 -0
  75. package/connectors/connect-deepseek/tsconfig.json +16 -0
  76. package/connectors/connect-fal/.env.example +11 -0
  77. package/connectors/connect-fal/CLAUDE.md +128 -0
  78. package/connectors/connect-fal/README.md +193 -0
  79. package/connectors/connect-fal/package.json +51 -0
  80. package/connectors/connect-fal/src/api/client.ts +172 -0
  81. package/connectors/connect-fal/src/api/index.ts +55 -0
  82. package/connectors/connect-fal/src/cli/index.ts +341 -0
  83. package/connectors/connect-fal/src/index.ts +19 -0
  84. package/connectors/connect-fal/src/types/index.ts +135 -0
  85. package/connectors/connect-fal/src/utils/config.ts +103 -0
  86. package/connectors/connect-fal/src/utils/output.ts +119 -0
  87. package/connectors/connect-fal/tsconfig.json +16 -0
  88. package/connectors/connect-fireworks/.env.example +11 -0
  89. package/connectors/connect-fireworks/CLAUDE.md +128 -0
  90. package/connectors/connect-fireworks/README.md +193 -0
  91. package/connectors/connect-fireworks/package.json +51 -0
  92. package/connectors/connect-fireworks/src/api/client.ts +63 -0
  93. package/connectors/connect-fireworks/src/api/index.ts +36 -0
  94. package/connectors/connect-fireworks/src/cli/index.ts +244 -0
  95. package/connectors/connect-fireworks/src/index.ts +19 -0
  96. package/connectors/connect-fireworks/src/types/index.ts +70 -0
  97. package/connectors/connect-fireworks/src/utils/config.ts +103 -0
  98. package/connectors/connect-fireworks/src/utils/output.ts +119 -0
  99. package/connectors/connect-fireworks/tsconfig.json +16 -0
  100. package/connectors/connect-groq/.env.example +11 -0
  101. package/connectors/connect-groq/CLAUDE.md +128 -0
  102. package/connectors/connect-groq/README.md +193 -0
  103. package/connectors/connect-groq/package.json +52 -0
  104. package/connectors/connect-groq/src/api/client.ts +108 -0
  105. package/connectors/connect-groq/src/api/index.ts +36 -0
  106. package/connectors/connect-groq/src/cli/index.ts +171 -0
  107. package/connectors/connect-groq/src/index.ts +19 -0
  108. package/connectors/connect-groq/src/types/index.ts +69 -0
  109. package/connectors/connect-groq/src/utils/config.ts +103 -0
  110. package/connectors/connect-groq/src/utils/output.ts +119 -0
  111. package/connectors/connect-groq/tsconfig.json +16 -0
  112. package/connectors/connect-luma/.env.example +11 -0
  113. package/connectors/connect-luma/CLAUDE.md +128 -0
  114. package/connectors/connect-luma/README.md +193 -0
  115. package/connectors/connect-luma/package.json +53 -0
  116. package/connectors/connect-luma/src/api/client.ts +85 -0
  117. package/connectors/connect-luma/src/api/index.ts +44 -0
  118. package/connectors/connect-luma/src/cli/index.ts +300 -0
  119. package/connectors/connect-luma/src/index.ts +19 -0
  120. package/connectors/connect-luma/src/types/index.ts +60 -0
  121. package/connectors/connect-luma/src/utils/config.ts +103 -0
  122. package/connectors/connect-luma/src/utils/output.ts +119 -0
  123. package/connectors/connect-luma/tsconfig.json +16 -0
  124. package/connectors/connect-modal/.env.example +11 -0
  125. package/connectors/connect-modal/CLAUDE.md +128 -0
  126. package/connectors/connect-modal/README.md +193 -0
  127. package/connectors/connect-modal/package.json +51 -0
  128. package/connectors/connect-modal/src/api/client.ts +119 -0
  129. package/connectors/connect-modal/src/api/index.ts +69 -0
  130. package/connectors/connect-modal/src/cli/index.ts +224 -0
  131. package/connectors/connect-modal/src/index.ts +21 -0
  132. package/connectors/connect-modal/src/types/index.ts +60 -0
  133. package/connectors/connect-modal/src/utils/config.ts +114 -0
  134. package/connectors/connect-modal/src/utils/output.ts +119 -0
  135. package/connectors/connect-modal/tsconfig.json +16 -0
  136. package/connectors/connect-perplexity/.env.example +4 -0
  137. package/connectors/connect-perplexity/CLAUDE.md +156 -0
  138. package/connectors/connect-perplexity/README.md +184 -0
  139. package/connectors/connect-perplexity/package.json +58 -0
  140. package/connectors/connect-perplexity/scripts/publish.ts +210 -0
  141. package/connectors/connect-perplexity/src/api/client.ts +119 -0
  142. package/connectors/connect-perplexity/src/api/example.ts +118 -0
  143. package/connectors/connect-perplexity/src/api/index.ts +48 -0
  144. package/connectors/connect-perplexity/src/cli/index.ts +421 -0
  145. package/connectors/connect-perplexity/src/index.ts +24 -0
  146. package/connectors/connect-perplexity/src/types/index.ts +140 -0
  147. package/connectors/connect-perplexity/src/utils/config.ts +208 -0
  148. package/connectors/connect-perplexity/src/utils/output.ts +119 -0
  149. package/connectors/connect-perplexity/tsconfig.json +16 -0
  150. package/connectors/connect-replicate/.env.example +11 -0
  151. package/connectors/connect-replicate/CLAUDE.md +128 -0
  152. package/connectors/connect-replicate/README.md +193 -0
  153. package/connectors/connect-replicate/package.json +51 -0
  154. package/connectors/connect-replicate/src/api/client.ts +109 -0
  155. package/connectors/connect-replicate/src/api/index.ts +71 -0
  156. package/connectors/connect-replicate/src/cli/index.ts +250 -0
  157. package/connectors/connect-replicate/src/index.ts +19 -0
  158. package/connectors/connect-replicate/src/types/index.ts +85 -0
  159. package/connectors/connect-replicate/src/utils/config.ts +103 -0
  160. package/connectors/connect-replicate/src/utils/output.ts +119 -0
  161. package/connectors/connect-replicate/tsconfig.json +16 -0
  162. package/connectors/connect-roboflow/.env.example +11 -0
  163. package/connectors/connect-roboflow/CLAUDE.md +272 -0
  164. package/connectors/connect-roboflow/README.md +193 -0
  165. package/connectors/connect-roboflow/package.json +51 -0
  166. package/connectors/connect-roboflow/scripts/release.ts +179 -0
  167. package/connectors/connect-roboflow/src/api/client.ts +213 -0
  168. package/connectors/connect-roboflow/src/api/example.ts +48 -0
  169. package/connectors/connect-roboflow/src/api/index.ts +51 -0
  170. package/connectors/connect-roboflow/src/cli/index.ts +254 -0
  171. package/connectors/connect-roboflow/src/index.ts +103 -0
  172. package/connectors/connect-roboflow/src/types/index.ts +237 -0
  173. package/connectors/connect-roboflow/src/utils/auth.ts +274 -0
  174. package/connectors/connect-roboflow/src/utils/bulk.ts +212 -0
  175. package/connectors/connect-roboflow/src/utils/config.ts +326 -0
  176. package/connectors/connect-roboflow/src/utils/output.ts +175 -0
  177. package/connectors/connect-roboflow/src/utils/settings.ts +114 -0
  178. package/connectors/connect-roboflow/src/utils/storage.ts +198 -0
  179. package/connectors/connect-roboflow/tsconfig.json +16 -0
  180. package/connectors/connect-runway/.env.example +11 -0
  181. package/connectors/connect-runway/CLAUDE.md +128 -0
  182. package/connectors/connect-runway/README.md +193 -0
  183. package/connectors/connect-runway/package.json +52 -0
  184. package/connectors/connect-runway/src/api/client.ts +78 -0
  185. package/connectors/connect-runway/src/api/index.ts +40 -0
  186. package/connectors/connect-runway/src/cli/index.ts +283 -0
  187. package/connectors/connect-runway/src/index.ts +19 -0
  188. package/connectors/connect-runway/src/types/index.ts +52 -0
  189. package/connectors/connect-runway/src/utils/config.ts +103 -0
  190. package/connectors/connect-runway/src/utils/output.ts +119 -0
  191. package/connectors/connect-runway/tsconfig.json +16 -0
  192. package/connectors/connect-together/.env.example +11 -0
  193. package/connectors/connect-together/CLAUDE.md +128 -0
  194. package/connectors/connect-together/README.md +193 -0
  195. package/connectors/connect-together/package.json +52 -0
  196. package/connectors/connect-together/src/api/client.ts +106 -0
  197. package/connectors/connect-together/src/api/index.ts +47 -0
  198. package/connectors/connect-together/src/cli/index.ts +228 -0
  199. package/connectors/connect-together/src/index.ts +19 -0
  200. package/connectors/connect-together/src/types/index.ts +91 -0
  201. package/connectors/connect-together/src/utils/config.ts +142 -0
  202. package/connectors/connect-together/src/utils/output.ts +119 -0
  203. package/connectors/connect-together/tsconfig.json +16 -0
  204. package/dist/index.js +112 -0
  205. package/package.json +1 -1
@@ -0,0 +1,255 @@
1
+ #!/usr/bin/env bun
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { Cohere } 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-cohere';
23
+ const VERSION = '0.0.1';
24
+
25
+ const program = new Command();
26
+
27
+ program
28
+ .name(CONNECTOR_NAME)
29
+ .description('Cohere AI connector CLI - Chat, embeddings, rerank, and classify')
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(): Cohere {
50
+ const apiKey = getApiKey();
51
+ if (!apiKey) {
52
+ error(`No API key configured. Run "${CONNECTOR_NAME} config set-key <key>" or set COHERE_API_KEY`);
53
+ process.exit(1);
54
+ }
55
+ return new Cohere({ 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
+ .option('-m, --model <model>', 'Model (default: command)')
143
+ .option('-t, --temperature <temp>', 'Temperature')
144
+ .option('--max-tokens <n>', 'Max tokens')
145
+ .action(async (message: string, opts) => {
146
+ try {
147
+ const client = getClient();
148
+ const result = await client.chat({
149
+ message,
150
+ model: opts.model,
151
+ temperature: opts.temperature ? parseFloat(opts.temperature) : undefined,
152
+ max_tokens: opts.maxTokens ? parseInt(opts.maxTokens) : undefined,
153
+ });
154
+ if (getFormat(program) === 'json') {
155
+ print(result, 'json');
156
+ } else {
157
+ console.log(chalk.green('\nResponse:'));
158
+ console.log(result.text);
159
+ if (result.meta?.billed_units) {
160
+ info(`\nTokens: ${result.meta.billed_units.input_tokens || 0} in, ${result.meta.billed_units.output_tokens || 0} out`);
161
+ }
162
+ }
163
+ } catch (err) {
164
+ error(String(err));
165
+ process.exit(1);
166
+ }
167
+ });
168
+
169
+ // Embed Command
170
+ program.command('embed <texts...>')
171
+ .description('Generate embeddings')
172
+ .option('-m, --model <model>', 'Model (default: embed-english-v3.0)')
173
+ .option('-t, --input-type <type>', 'Input type: search_document, search_query, classification, clustering')
174
+ .action(async (texts: string[], opts) => {
175
+ try {
176
+ const client = getClient();
177
+ const result = await client.embed({
178
+ texts,
179
+ model: opts.model,
180
+ input_type: opts.inputType,
181
+ });
182
+ if (getFormat(program) === 'json') {
183
+ print(result, 'json');
184
+ } else {
185
+ texts.forEach((text, i) => {
186
+ console.log(chalk.cyan(`\n[${i + 1}] "${text.substring(0, 40)}${text.length > 40 ? '...' : ''}"`));
187
+ console.log(`Dimension: ${result.embeddings[i]?.length || 0}`);
188
+ });
189
+ }
190
+ } catch (err) {
191
+ error(String(err));
192
+ process.exit(1);
193
+ }
194
+ });
195
+
196
+ // Rerank Command
197
+ program.command('rerank <query>')
198
+ .description('Rerank documents')
199
+ .option('-d, --documents <docs...>', 'Documents to rerank')
200
+ .option('-m, --model <model>', 'Model (default: rerank-english-v3.0)')
201
+ .option('-n, --top-n <n>', 'Top N results')
202
+ .action(async (query: string, opts) => {
203
+ try {
204
+ if (!opts.documents || opts.documents.length === 0) {
205
+ error('No documents provided. Use -d option.');
206
+ process.exit(1);
207
+ }
208
+ const client = getClient();
209
+ const result = await client.rerank({
210
+ query,
211
+ documents: opts.documents,
212
+ model: opts.model,
213
+ top_n: opts.topN ? parseInt(opts.topN) : undefined,
214
+ return_documents: true,
215
+ });
216
+ if (getFormat(program) === 'json') {
217
+ print(result, 'json');
218
+ } else {
219
+ console.log(chalk.cyan(`\nQuery: "${query}"\n`));
220
+ result.results.forEach((r, i) => {
221
+ console.log(`${chalk.yellow(`#${i + 1}`)} Score: ${chalk.green(r.relevance_score.toFixed(4))}`);
222
+ if (r.document) {
223
+ console.log(` ${r.document.text.substring(0, 60)}${r.document.text.length > 60 ? '...' : ''}`);
224
+ }
225
+ });
226
+ }
227
+ } catch (err) {
228
+ error(String(err));
229
+ process.exit(1);
230
+ }
231
+ });
232
+
233
+ // Models Command
234
+ program.command('models')
235
+ .description('List available models')
236
+ .action(async () => {
237
+ try {
238
+ const client = getClient();
239
+ const result = await client.listModels();
240
+ if (getFormat(program) === 'json') {
241
+ print(result.models, 'json');
242
+ } else {
243
+ result.models.forEach(m => {
244
+ console.log(chalk.cyan(`\n${m.name}`));
245
+ if (m.endpoints) console.log(` Endpoints: ${m.endpoints.join(', ')}`);
246
+ if (m.context_length) console.log(` Context: ${m.context_length}`);
247
+ });
248
+ }
249
+ } catch (err) {
250
+ error(String(err));
251
+ process.exit(1);
252
+ }
253
+ });
254
+
255
+ program.parse();
@@ -0,0 +1,19 @@
1
+ // Cohere Connector
2
+ // TypeScript wrapper for Cohere AI API
3
+
4
+ export { Cohere } from './api';
5
+ export * from './types';
6
+ export { CohereClient } 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,132 @@
1
+ // Cohere Connector Types
2
+
3
+ export interface CohereConfig {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ }
7
+
8
+ export type OutputFormat = 'json' | 'pretty';
9
+
10
+ // Chat Types
11
+ export interface ChatMessage {
12
+ role: 'USER' | 'CHATBOT' | 'SYSTEM';
13
+ message: string;
14
+ }
15
+
16
+ export interface ChatRequest {
17
+ model?: string;
18
+ message: string;
19
+ chat_history?: ChatMessage[];
20
+ preamble?: string;
21
+ temperature?: number;
22
+ max_tokens?: number;
23
+ k?: number;
24
+ p?: number;
25
+ stop_sequences?: string[];
26
+ }
27
+
28
+ export interface ChatResponse {
29
+ text: string;
30
+ generation_id?: string;
31
+ chat_history?: ChatMessage[];
32
+ finish_reason?: string;
33
+ meta?: {
34
+ api_version?: { version: string };
35
+ billed_units?: { input_tokens?: number; output_tokens?: number };
36
+ };
37
+ }
38
+
39
+ // Embed Types
40
+ export type EmbedInputType = 'search_document' | 'search_query' | 'classification' | 'clustering';
41
+
42
+ export interface EmbedRequest {
43
+ model?: string;
44
+ texts: string[];
45
+ input_type?: EmbedInputType;
46
+ truncate?: 'NONE' | 'START' | 'END';
47
+ }
48
+
49
+ export interface EmbedResponse {
50
+ id: string;
51
+ embeddings: number[][];
52
+ texts: string[];
53
+ meta?: {
54
+ api_version?: { version: string };
55
+ billed_units?: { input_tokens?: number };
56
+ };
57
+ }
58
+
59
+ // Rerank Types
60
+ export interface RerankRequest {
61
+ model?: string;
62
+ query: string;
63
+ documents: (string | { text: string })[];
64
+ top_n?: number;
65
+ return_documents?: boolean;
66
+ }
67
+
68
+ export interface RerankResult {
69
+ index: number;
70
+ relevance_score: number;
71
+ document?: { text: string };
72
+ }
73
+
74
+ export interface RerankResponse {
75
+ id: string;
76
+ results: RerankResult[];
77
+ meta?: {
78
+ api_version?: { version: string };
79
+ billed_units?: { search_units?: number };
80
+ };
81
+ }
82
+
83
+ // Classify Types
84
+ export interface ClassifyExample {
85
+ text: string;
86
+ label: string;
87
+ }
88
+
89
+ export interface ClassifyRequest {
90
+ model?: string;
91
+ inputs: string[];
92
+ examples: ClassifyExample[];
93
+ }
94
+
95
+ export interface Classification {
96
+ id: string;
97
+ input: string;
98
+ prediction: string;
99
+ confidence: number;
100
+ labels: Record<string, { confidence: number }>;
101
+ }
102
+
103
+ export interface ClassifyResponse {
104
+ id: string;
105
+ classifications: Classification[];
106
+ meta?: {
107
+ api_version?: { version: string };
108
+ };
109
+ }
110
+
111
+ // Models Types
112
+ export interface CohereModel {
113
+ name: string;
114
+ endpoints?: string[];
115
+ finetuned?: boolean;
116
+ context_length?: number;
117
+ }
118
+
119
+ export interface ModelsResponse {
120
+ models: CohereModel[];
121
+ }
122
+
123
+ // API Error
124
+ export class CohereApiError extends Error {
125
+ public readonly statusCode: number;
126
+
127
+ constructor(message: string, statusCode: number) {
128
+ super(message);
129
+ this.name = 'CohereApiError';
130
+ this.statusCode = statusCode;
131
+ }
132
+ }
@@ -0,0 +1,197 @@
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-cohere';
6
+ const DEFAULT_PROFILE = 'default';
7
+
8
+ export interface ProfileConfig {
9
+ apiKey?: string;
10
+ }
11
+
12
+ // Store for --profile flag override (set by CLI before commands run)
13
+ let profileOverride: string | undefined;
14
+
15
+ // Config directory: ~/.connect/{connector-name}/
16
+ const CONFIG_DIR = join(homedir(), '.connect', CONNECTOR_NAME);
17
+ const PROFILES_DIR = join(CONFIG_DIR, 'profiles');
18
+ const CURRENT_PROFILE_FILE = join(CONFIG_DIR, 'current_profile');
19
+
20
+ // ============================================
21
+ // Profile Management
22
+ // ============================================
23
+
24
+ export function setProfileOverride(profile: string | undefined): void {
25
+ profileOverride = profile;
26
+ }
27
+
28
+ export function ensureConfigDir(): void {
29
+ if (!existsSync(CONFIG_DIR)) {
30
+ mkdirSync(CONFIG_DIR, { recursive: true });
31
+ }
32
+ if (!existsSync(PROFILES_DIR)) {
33
+ mkdirSync(PROFILES_DIR, { recursive: true });
34
+ }
35
+ }
36
+
37
+ function getProfilePath(profile: string): string {
38
+ return join(PROFILES_DIR, `${profile}.json`);
39
+ }
40
+
41
+ /**
42
+ * Get the current active profile name
43
+ */
44
+ export function getCurrentProfile(): string {
45
+ if (profileOverride) {
46
+ return profileOverride;
47
+ }
48
+
49
+ ensureConfigDir();
50
+
51
+ if (existsSync(CURRENT_PROFILE_FILE)) {
52
+ try {
53
+ const profile = readFileSync(CURRENT_PROFILE_FILE, 'utf-8').trim();
54
+ if (profile && profileExists(profile)) {
55
+ return profile;
56
+ }
57
+ } catch {
58
+ // Fall through to default
59
+ }
60
+ }
61
+
62
+ return DEFAULT_PROFILE;
63
+ }
64
+
65
+ /**
66
+ * Set the current active profile
67
+ */
68
+ export function setCurrentProfile(profile: string): void {
69
+ ensureConfigDir();
70
+
71
+ if (!profileExists(profile) && profile !== DEFAULT_PROFILE) {
72
+ throw new Error(`Profile "${profile}" does not exist`);
73
+ }
74
+
75
+ writeFileSync(CURRENT_PROFILE_FILE, profile);
76
+ }
77
+
78
+ /**
79
+ * Check if a profile exists
80
+ */
81
+ export function profileExists(profile: string): boolean {
82
+ return existsSync(getProfilePath(profile));
83
+ }
84
+
85
+ /**
86
+ * List all available profiles
87
+ */
88
+ export function listProfiles(): string[] {
89
+ ensureConfigDir();
90
+
91
+ if (!existsSync(PROFILES_DIR)) {
92
+ return [];
93
+ }
94
+
95
+ return readdirSync(PROFILES_DIR)
96
+ .filter(f => f.endsWith('.json'))
97
+ .map(f => f.replace('.json', ''))
98
+ .sort();
99
+ }
100
+
101
+ /**
102
+ * Create a new profile
103
+ */
104
+ export function createProfile(profile: string, config: ProfileConfig = {}): boolean {
105
+ ensureConfigDir();
106
+
107
+ if (profileExists(profile)) {
108
+ return false;
109
+ }
110
+
111
+ // Validate profile name
112
+ if (!/^[a-zA-Z0-9_-]+$/.test(profile)) {
113
+ throw new Error('Profile name can only contain letters, numbers, hyphens, and underscores');
114
+ }
115
+
116
+ writeFileSync(getProfilePath(profile), JSON.stringify(config, null, 2));
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Delete a profile
122
+ */
123
+ export function deleteProfile(profile: string): boolean {
124
+ if (profile === DEFAULT_PROFILE) {
125
+ return false;
126
+ }
127
+
128
+ if (!profileExists(profile)) {
129
+ return false;
130
+ }
131
+
132
+ // Switch to default if deleting current profile
133
+ if (getCurrentProfile() === profile) {
134
+ setCurrentProfile(DEFAULT_PROFILE);
135
+ }
136
+
137
+ rmSync(getProfilePath(profile));
138
+ return true;
139
+ }
140
+
141
+ /**
142
+ * Load profile config
143
+ */
144
+ export function loadProfile(profile?: string): ProfileConfig {
145
+ ensureConfigDir();
146
+ const profileName = profile || getCurrentProfile();
147
+ const profilePath = getProfilePath(profileName);
148
+
149
+ if (!existsSync(profilePath)) {
150
+ return {};
151
+ }
152
+
153
+ try {
154
+ return JSON.parse(readFileSync(profilePath, 'utf-8'));
155
+ } catch {
156
+ return {};
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Save profile config
162
+ */
163
+ export function saveProfile(config: ProfileConfig, profile?: string): void {
164
+ ensureConfigDir();
165
+ const profileName = profile || getCurrentProfile();
166
+ writeFileSync(getProfilePath(profileName), JSON.stringify(config, null, 2));
167
+ }
168
+
169
+ // ============================================
170
+ // API Key Management
171
+ // ============================================
172
+
173
+ export function getApiKey(): string | undefined {
174
+ return process.env.COHERE_API_KEY || loadProfile().apiKey;
175
+ }
176
+
177
+ export function setApiKey(apiKey: string): void {
178
+ const config = loadProfile();
179
+ config.apiKey = apiKey;
180
+ saveProfile(config);
181
+ }
182
+
183
+ // ============================================
184
+ // Utility Functions
185
+ // ============================================
186
+
187
+ export function clearConfig(): void {
188
+ saveProfile({});
189
+ }
190
+
191
+ export function getConfigDir(): string {
192
+ return CONFIG_DIR;
193
+ }
194
+
195
+ export function getActiveProfileName(): string {
196
+ return getCurrentProfile();
197
+ }