@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,193 @@
1
+ # scaffold-connector
2
+
3
+ A TypeScript scaffold for building API connector CLIs with multi-profile support.
4
+
5
+ ## Features
6
+
7
+ - Multi-profile configuration (switch between different API keys/accounts)
8
+ - Bearer token authentication (easily customizable)
9
+ - Clean CLI structure with Commander.js
10
+ - Pretty and JSON output formats
11
+ - TypeScript with strict mode
12
+
13
+ ## Quick Start
14
+
15
+ ### 1. Clone and Rename
16
+
17
+ ```bash
18
+ # Clone for your connector
19
+ git clone https://github.com/hasna/scaffold-connector.git connect-yourapi
20
+ cd connect-yourapi
21
+
22
+ # Update package.json name
23
+ # Change "@hasna/scaffold-connector" to "@hasna/connect-yourapi"
24
+ ```
25
+
26
+ ### 2. Update Configuration
27
+
28
+ Search for `TODO` comments throughout the codebase and update:
29
+
30
+ - `src/cli/index.ts` - Update `CONNECTOR_NAME` and description
31
+ - `src/utils/config.ts` - Update `CONNECTOR_NAME` and env var names
32
+ - `src/api/client.ts` - Update `DEFAULT_BASE_URL` and authentication method
33
+ - `src/api/index.ts` - Rename `Connector` class to your API name
34
+ - `src/types/index.ts` - Add your API's type definitions
35
+ - `package.json` - Update name, description, bin command
36
+ - `.env.example` - Update environment variable names
37
+
38
+ ### 3. Install and Test
39
+
40
+ ```bash
41
+ # Install dependencies
42
+ bun install
43
+
44
+ # Run CLI
45
+ bun run dev
46
+
47
+ # Or run specific commands
48
+ bun run dev profile list
49
+ bun run dev config show
50
+ ```
51
+
52
+ ## CLI Structure
53
+
54
+ ```bash
55
+ connector [options] [command]
56
+
57
+ Options:
58
+ -k, --api-key <key> API key (overrides config)
59
+ -f, --format <format> Output format (json, pretty)
60
+ -p, --profile <profile> Use a specific profile
61
+
62
+ Commands:
63
+ profile list List all profiles
64
+ profile use <name> Switch to a profile
65
+ profile create <name> Create a new profile
66
+ profile delete <name> Delete a profile
67
+ profile show [name] Show profile configuration
68
+
69
+ config set-key <key> Set API key for active profile
70
+ config show Show current configuration
71
+ config clear Clear configuration
72
+
73
+ example list Example API command (replace)
74
+ example get <id> Example API command (replace)
75
+ example create Example API command (replace)
76
+ ```
77
+
78
+ ## Project Structure
79
+
80
+ ```
81
+ src/
82
+ ├── api/
83
+ │ ├── client.ts # HTTP client with authentication
84
+ │ ├── example.ts # Example API module (replace with your API)
85
+ │ └── index.ts # Main connector class
86
+ ├── cli/
87
+ │ └── index.ts # CLI commands
88
+ ├── types/
89
+ │ └── index.ts # Type definitions
90
+ ├── utils/
91
+ │ ├── config.ts # Multi-profile configuration
92
+ │ └── output.ts # CLI output formatting
93
+ └── index.ts # Library exports
94
+ ```
95
+
96
+ ## Multi-Profile Configuration
97
+
98
+ Profiles are stored in `~/.connect/{connector-name}/profiles/`:
99
+
100
+ ```
101
+ ~/.connect/connector/
102
+ ├── current_profile # Name of active profile
103
+ └── profiles/
104
+ ├── default.json # Default profile
105
+ ├── work.json # Named profile
106
+ └── personal.json # Named profile
107
+ ```
108
+
109
+ ### Profile Commands
110
+
111
+ ```bash
112
+ # Create profiles
113
+ connector profile create work --api-key sk-xxx --use
114
+ connector profile create personal --api-key sk-yyy
115
+
116
+ # Switch profiles
117
+ connector profile use work
118
+
119
+ # Use profile for single command
120
+ connector -p personal example list
121
+
122
+ # List profiles
123
+ connector profile list
124
+ ```
125
+
126
+ ## Customizing Authentication
127
+
128
+ Edit `src/api/client.ts` to change authentication:
129
+
130
+ ```typescript
131
+ // Bearer token (default)
132
+ 'Authorization': `Bearer ${this.apiKey}`,
133
+
134
+ // API Key header
135
+ 'X-API-Key': this.apiKey,
136
+
137
+ // Basic auth
138
+ 'Authorization': `Basic ${Buffer.from(`${this.apiKey}:${this.apiSecret}`).toString('base64')}`,
139
+ ```
140
+
141
+ ## Adding API Endpoints
142
+
143
+ 1. Create a new file in `src/api/` (e.g., `users.ts`)
144
+ 2. Export it from `src/api/index.ts`
145
+ 3. Add types in `src/types/index.ts`
146
+ 4. Add CLI commands in `src/cli/index.ts`
147
+
148
+ Example API module:
149
+
150
+ ```typescript
151
+ // src/api/users.ts
152
+ import type { ConnectorClient } from './client';
153
+
154
+ export class UsersApi {
155
+ constructor(private readonly client: ConnectorClient) {}
156
+
157
+ async list(options?: { limit?: number }) {
158
+ return this.client.get('/users', { limit: options?.limit });
159
+ }
160
+
161
+ async get(id: string) {
162
+ return this.client.get(`/users/${id}`);
163
+ }
164
+ }
165
+ ```
166
+
167
+ ## Environment Variables
168
+
169
+ | Variable | Description |
170
+ |----------|-------------|
171
+ | `CONNECTOR_API_KEY` | API key (overrides profile config) |
172
+ | `CONNECTOR_API_SECRET` | API secret (optional) |
173
+ | `CONNECTOR_BASE_URL` | Override base URL (optional) |
174
+
175
+ ## Development
176
+
177
+ ```bash
178
+ # Install dependencies
179
+ bun install
180
+
181
+ # Run CLI in development
182
+ bun run dev
183
+
184
+ # Build for distribution
185
+ bun run build
186
+
187
+ # Type check
188
+ bun run typecheck
189
+ ```
190
+
191
+ ## License
192
+
193
+ MIT
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@hasna/connect-deepseek",
3
+ "version": "0.0.1",
4
+ "description": "DeepSeek AI connector CLI - Advanced reasoning models with multi-profile support",
5
+ "type": "module",
6
+ "bin": {
7
+ "connect-deepseek": "./bin/index.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "scripts": {
18
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun && bun build ./src/cli/index.ts --outdir ./bin --target bun",
19
+ "dev": "bun run ./src/cli/index.ts",
20
+ "typecheck": "tsc --noEmit",
21
+ "prepublishOnly": "bun run build"
22
+ },
23
+ "keywords": [
24
+ "deepseek",
25
+ "ai",
26
+ "api",
27
+ "connector",
28
+ "cli",
29
+ "typescript",
30
+ "bun",
31
+ "llm",
32
+ "reasoning"
33
+ ],
34
+ "author": "Hasna",
35
+ "license": "Apache-2.0",
36
+ "devDependencies": {
37
+ "@types/bun": "latest",
38
+ "typescript": "^5"
39
+ },
40
+ "dependencies": {
41
+ "commander": "^12.1.0",
42
+ "chalk": "^5.3.0"
43
+ },
44
+ "engines": {
45
+ "bun": ">=1.0.0"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/hasna/open-connectors.git"
50
+ }
51
+ }
@@ -0,0 +1,108 @@
1
+ import type { DeepSeekConfig } from '../types';
2
+ import { DeepSeekApiError } from '../types';
3
+
4
+ const DEFAULT_BASE_URL = 'https://api.deepseek.com/v1';
5
+
6
+ export interface RequestOptions {
7
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
8
+ params?: Record<string, string | number | boolean | undefined>;
9
+ body?: Record<string, unknown> | unknown[] | string;
10
+ headers?: Record<string, string>;
11
+ }
12
+
13
+ export class DeepSeekClient {
14
+ private readonly apiKey: string;
15
+ private readonly baseUrl: string;
16
+
17
+ constructor(config: DeepSeekConfig) {
18
+ if (!config.apiKey) {
19
+ throw new Error('API key is required');
20
+ }
21
+ this.apiKey = config.apiKey;
22
+ this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
23
+ }
24
+
25
+ private buildUrl(path: string, params?: Record<string, string | number | boolean | undefined>): string {
26
+ const url = new URL(`${this.baseUrl}${path}`);
27
+ if (params) {
28
+ Object.entries(params).forEach(([key, value]) => {
29
+ if (value !== undefined && value !== null && value !== '') {
30
+ url.searchParams.append(key, String(value));
31
+ }
32
+ });
33
+ }
34
+ return url.toString();
35
+ }
36
+
37
+ async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
38
+ const { method = 'GET', params, body, headers = {} } = options;
39
+ const url = this.buildUrl(path, params);
40
+
41
+ const requestHeaders: Record<string, string> = {
42
+ 'Authorization': `Bearer ${this.apiKey}`,
43
+ 'Accept': 'application/json',
44
+ ...headers,
45
+ };
46
+
47
+ if (body && ['POST', 'PUT', 'PATCH'].includes(method)) {
48
+ requestHeaders['Content-Type'] = 'application/json';
49
+ }
50
+
51
+ const fetchOptions: RequestInit = {
52
+ method,
53
+ headers: requestHeaders,
54
+ };
55
+
56
+ if (body && ['POST', 'PUT', 'PATCH'].includes(method)) {
57
+ fetchOptions.body = typeof body === 'string' ? body : JSON.stringify(body);
58
+ }
59
+
60
+ const response = await fetch(url, fetchOptions);
61
+
62
+ if (response.status === 204) {
63
+ return {} as T;
64
+ }
65
+
66
+ let data: unknown;
67
+ const contentType = response.headers.get('content-type') || '';
68
+
69
+ if (contentType.includes('application/json')) {
70
+ const text = await response.text();
71
+ if (text) {
72
+ try {
73
+ data = JSON.parse(text);
74
+ } catch {
75
+ data = text;
76
+ }
77
+ }
78
+ } else {
79
+ data = await response.text();
80
+ }
81
+
82
+ if (!response.ok) {
83
+ let errorMessage = String(data || response.statusText);
84
+ if (typeof data === 'object' && data !== null) {
85
+ const errorObj = data as { error?: { message?: string }; message?: string };
86
+ errorMessage = errorObj.error?.message || errorObj.message || JSON.stringify(data);
87
+ }
88
+ throw new DeepSeekApiError(errorMessage, response.status);
89
+ }
90
+
91
+ return data as T;
92
+ }
93
+
94
+ async get<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
95
+ return this.request<T>(path, { method: 'GET', params });
96
+ }
97
+
98
+ async post<T>(path: string, body?: Record<string, unknown> | unknown[] | string | object): Promise<T> {
99
+ return this.request<T>(path, { method: 'POST', body: body as Record<string, unknown> });
100
+ }
101
+
102
+ getApiKeyPreview(): string {
103
+ if (this.apiKey.length > 10) {
104
+ return `${this.apiKey.substring(0, 6)}...${this.apiKey.substring(this.apiKey.length - 4)}`;
105
+ }
106
+ return '***';
107
+ }
108
+ }
@@ -0,0 +1,36 @@
1
+ import type { DeepSeekConfig, ChatRequest, ChatResponse, ModelsResponse } from '../types';
2
+ import { DeepSeekClient } from './client';
3
+
4
+ export class DeepSeek {
5
+ private readonly client: DeepSeekClient;
6
+
7
+ constructor(config: DeepSeekConfig) {
8
+ this.client = new DeepSeekClient(config);
9
+ }
10
+
11
+ static fromEnv(): DeepSeek {
12
+ const apiKey = process.env.DEEPSEEK_API_KEY;
13
+ if (!apiKey) {
14
+ throw new Error('DEEPSEEK_API_KEY environment variable is required');
15
+ }
16
+ return new DeepSeek({ apiKey });
17
+ }
18
+
19
+ getApiKeyPreview(): string {
20
+ return this.client.getApiKeyPreview();
21
+ }
22
+
23
+ async chat(request: ChatRequest): Promise<ChatResponse> {
24
+ return this.client.post<ChatResponse>('/chat/completions', request);
25
+ }
26
+
27
+ async listModels(): Promise<ModelsResponse> {
28
+ return this.client.get<ModelsResponse>('/models');
29
+ }
30
+
31
+ getClient(): DeepSeekClient {
32
+ return this.client;
33
+ }
34
+ }
35
+
36
+ export { DeepSeekClient } from './client';
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env bun
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { DeepSeek } 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-deepseek';
14
+ const VERSION = '0.0.1';
15
+
16
+ const program = new Command();
17
+
18
+ program
19
+ .name(CONNECTOR_NAME)
20
+ .description('DeepSeek AI connector CLI - Advanced reasoning models')
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(): DeepSeek {
41
+ const apiKey = getApiKey();
42
+ if (!apiKey) {
43
+ error(`No API key configured. Run "${CONNECTOR_NAME} config set-key <key>" or set DEEPSEEK_API_KEY`);
44
+ process.exit(1);
45
+ }
46
+ return new DeepSeek({ 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: deepseek-chat)', 'deepseek-chat')
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
+ }
139
+ }
140
+ } catch (err) {
141
+ error(String(err));
142
+ process.exit(1);
143
+ }
144
+ });
145
+
146
+ // Models Command
147
+ program.command('models')
148
+ .description('List available models')
149
+ .action(async () => {
150
+ try {
151
+ const client = getClient();
152
+ const result = await client.listModels();
153
+ if (getFormat(program) === 'json') {
154
+ print(result.data, 'json');
155
+ } else {
156
+ result.data.forEach(m => {
157
+ console.log(chalk.cyan(`\n${m.id}`));
158
+ if (m.owned_by) console.log(` Owner: ${m.owned_by}`);
159
+ });
160
+ }
161
+ } catch (err) {
162
+ error(String(err));
163
+ process.exit(1);
164
+ }
165
+ });
166
+
167
+ program.parse();
@@ -0,0 +1,19 @@
1
+ // DeepSeek Connector
2
+ // TypeScript wrapper for DeepSeek AI API
3
+
4
+ export { DeepSeek } from './api';
5
+ export * from './types';
6
+ export { DeepSeekClient } 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,72 @@
1
+ // DeepSeek API Types
2
+
3
+ export interface DeepSeekConfig {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ }
7
+
8
+ // Chat Types
9
+ export interface ChatMessage {
10
+ role: 'system' | 'user' | 'assistant';
11
+ content: string;
12
+ }
13
+
14
+ export interface ChatRequest {
15
+ model: string;
16
+ messages: ChatMessage[];
17
+ temperature?: number;
18
+ max_tokens?: number;
19
+ top_p?: number;
20
+ frequency_penalty?: number;
21
+ presence_penalty?: number;
22
+ stop?: string | string[];
23
+ stream?: boolean;
24
+ }
25
+
26
+ export interface ChatChoice {
27
+ index: number;
28
+ message: ChatMessage;
29
+ finish_reason: string;
30
+ }
31
+
32
+ export interface ChatUsage {
33
+ prompt_tokens: number;
34
+ completion_tokens: number;
35
+ total_tokens: number;
36
+ prompt_cache_hit_tokens?: number;
37
+ prompt_cache_miss_tokens?: number;
38
+ }
39
+
40
+ export interface ChatResponse {
41
+ id: string;
42
+ object: string;
43
+ created: number;
44
+ model: string;
45
+ choices: ChatChoice[];
46
+ usage?: ChatUsage;
47
+ }
48
+
49
+ // Models Types
50
+ export interface DeepSeekModel {
51
+ id: string;
52
+ object: string;
53
+ created?: number;
54
+ owned_by?: string;
55
+ }
56
+
57
+ export interface ModelsResponse {
58
+ object: string;
59
+ data: DeepSeekModel[];
60
+ }
61
+
62
+ // Error Types
63
+ export class DeepSeekApiError extends Error {
64
+ constructor(
65
+ message: string,
66
+ public readonly status: number,
67
+ public readonly code?: string
68
+ ) {
69
+ super(message);
70
+ this.name = 'DeepSeekApiError';
71
+ }
72
+ }