@hasna/connectors 1.3.45 → 1.3.46
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/README.md +25 -0
- package/bin/index.js +792 -130
- package/bin/mcp.js +438 -52
- package/bin/serve.js +438 -52
- package/connectors/cloudflare-workers/.env.example +5 -0
- package/connectors/cloudflare-workers/AGENTS.md +11 -0
- package/connectors/cloudflare-workers/CLAUDE.md +11 -0
- package/connectors/cloudflare-workers/README.md +45 -0
- package/connectors/cloudflare-workers/package.json +47 -0
- package/connectors/cloudflare-workers/src/api/client.test.ts +144 -0
- package/connectors/cloudflare-workers/src/api/client.ts +386 -0
- package/connectors/cloudflare-workers/src/api/index.ts +1 -0
- package/connectors/cloudflare-workers/src/cli/index.ts +206 -0
- package/connectors/cloudflare-workers/src/index.ts +16 -0
- package/connectors/cloudflare-workers/src/types/index.ts +53 -0
- package/connectors/cloudflare-workers/src/utils/config.ts +61 -0
- package/connectors/cloudflare-workers/src/utils/output.ts +26 -0
- package/connectors/cloudflare-workers/tsconfig.build.json +4 -0
- package/connectors/cloudflare-workers/tsconfig.json +14 -0
- package/connectors/tidio/.env.example +3 -2
- package/connectors/tidio/CLAUDE.md +21 -96
- package/connectors/tidio/README.md +22 -18
- package/connectors/tidio/package.json +4 -2
- package/connectors/tidio/src/api/client.ts +26 -15
- package/connectors/tidio/src/api/index.ts +185 -128
- package/connectors/tidio/src/api/tidio.test.ts +175 -44
- package/connectors/tidio/src/cli/index.ts +154 -388
- package/connectors/tidio/src/index.ts +5 -3
- package/connectors/tidio/src/types/index.ts +135 -82
- package/connectors/tidio/src/utils/config.ts +90 -44
- package/connectors/wandb/.env.example +7 -0
- package/connectors/wandb/AGENTS.md +43 -0
- package/connectors/wandb/CLAUDE.md +67 -0
- package/connectors/wandb/README.md +65 -0
- package/connectors/wandb/package.json +52 -0
- package/connectors/wandb/src/api/client.test.ts +116 -0
- package/connectors/wandb/src/api/client.ts +83 -0
- package/connectors/wandb/src/api/graphql.ts +9 -0
- package/connectors/wandb/src/api/index.ts +36 -0
- package/connectors/wandb/src/api/projects.ts +36 -0
- package/connectors/wandb/src/api/viewer.ts +20 -0
- package/connectors/wandb/src/cli/index.ts +265 -0
- package/connectors/wandb/src/index.ts +22 -0
- package/connectors/wandb/src/types/index.ts +75 -0
- package/connectors/wandb/src/utils/config.ts +164 -0
- package/connectors/wandb/src/utils/output.ts +119 -0
- package/connectors/wandb/tsconfig.json +16 -0
- package/connectors/weights-biases/.env.example +7 -0
- package/connectors/weights-biases/CLAUDE.md +65 -0
- package/connectors/weights-biases/README.md +62 -0
- package/connectors/weights-biases/package.json +53 -0
- package/connectors/weights-biases/src/api/client.test.ts +46 -0
- package/connectors/weights-biases/src/api/client.ts +119 -0
- package/connectors/weights-biases/src/api/events.ts +18 -0
- package/connectors/weights-biases/src/api/index.ts +56 -0
- package/connectors/weights-biases/src/api/runs.ts +28 -0
- package/connectors/weights-biases/src/api/search.ts +10 -0
- package/connectors/weights-biases/src/cli/index.ts +289 -0
- package/connectors/weights-biases/src/index.ts +19 -0
- package/connectors/weights-biases/src/types/index.ts +92 -0
- package/connectors/weights-biases/src/utils/config.ts +168 -0
- package/connectors/weights-biases/src/utils/output.ts +116 -0
- package/connectors/weights-biases/tsconfig.json +16 -0
- package/connectors/zoominfo/.env.example +4 -0
- package/connectors/zoominfo/AGENTS.md +26 -0
- package/connectors/zoominfo/CLAUDE.md +20 -0
- package/connectors/zoominfo/README.md +69 -0
- package/connectors/zoominfo/package.json +52 -0
- package/connectors/zoominfo/src/api/client.test.ts +140 -0
- package/connectors/zoominfo/src/api/client.ts +228 -0
- package/connectors/zoominfo/src/api/index.ts +1 -0
- package/connectors/zoominfo/src/cli/index.ts +179 -0
- package/connectors/zoominfo/src/index.ts +3 -0
- package/connectors/zoominfo/src/types/index.ts +39 -0
- package/connectors/zoominfo/src/utils/config.ts +61 -0
- package/connectors/zoominfo/src/utils/output.ts +27 -0
- package/connectors/zoominfo/tsconfig.json +20 -0
- package/connectors/zotero/.env.example +7 -0
- package/connectors/zotero/.npmrc.example +2 -0
- package/connectors/zotero/AGENTS.md +40 -0
- package/connectors/zotero/CLAUDE.md +69 -0
- package/connectors/zotero/README.md +91 -0
- package/connectors/zotero/package.json +43 -0
- package/connectors/zotero/src/api/attachments.ts +130 -0
- package/connectors/zotero/src/api/client.test.ts +166 -0
- package/connectors/zotero/src/api/client.ts +169 -0
- package/connectors/zotero/src/api/collections.ts +26 -0
- package/connectors/zotero/src/api/index.ts +45 -0
- package/connectors/zotero/src/api/items.ts +64 -0
- package/connectors/zotero/src/cli/index.ts +386 -0
- package/connectors/zotero/src/index.ts +28 -0
- package/connectors/zotero/src/types/index.ts +129 -0
- package/connectors/zotero/src/utils/config.ts +245 -0
- package/connectors/zotero/src/utils/output.ts +119 -0
- package/connectors/zotero/tsconfig.json +16 -0
- package/connectors/zymbly/.env.example +2 -0
- package/connectors/zymbly/AGENTS.md +11 -0
- package/connectors/zymbly/CLAUDE.md +5 -0
- package/connectors/zymbly/README.md +35 -0
- package/connectors/zymbly/package.json +52 -0
- package/connectors/zymbly/src/api/client.test.ts +110 -0
- package/connectors/zymbly/src/api/client.ts +166 -0
- package/connectors/zymbly/src/api/index.ts +1 -0
- package/connectors/zymbly/src/cli/index.ts +156 -0
- package/connectors/zymbly/src/index.ts +12 -0
- package/connectors/zymbly/src/types/index.ts +34 -0
- package/connectors/zymbly/src/utils/config.ts +52 -0
- package/connectors/zymbly/src/utils/output.ts +17 -0
- package/connectors/zymbly/tsconfig.json +13 -0
- package/dist/index.js +45 -2
- package/dist/lib/compact-output.d.ts +40 -0
- package/dist/mcp/tools/jobs.d.ts +32 -0
- package/dist/mcp/tools/jobs.test.d.ts +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Wandb } from '../api';
|
|
5
|
+
import {
|
|
6
|
+
getApiKey,
|
|
7
|
+
getBaseUrl,
|
|
8
|
+
setApiKey,
|
|
9
|
+
setBaseUrl,
|
|
10
|
+
clearConfig,
|
|
11
|
+
getConfigDir,
|
|
12
|
+
setProfileOverride,
|
|
13
|
+
getCurrentProfile,
|
|
14
|
+
setCurrentProfile,
|
|
15
|
+
listProfiles,
|
|
16
|
+
createProfile,
|
|
17
|
+
deleteProfile,
|
|
18
|
+
profileExists,
|
|
19
|
+
loadProfile,
|
|
20
|
+
} from '../utils/config';
|
|
21
|
+
import type { OutputFormat } from '../utils/output';
|
|
22
|
+
import { success, error, info, print } from '../utils/output';
|
|
23
|
+
|
|
24
|
+
const CONNECTOR_NAME = 'wandb';
|
|
25
|
+
const VERSION = '0.1.0';
|
|
26
|
+
|
|
27
|
+
const program = new Command();
|
|
28
|
+
|
|
29
|
+
program
|
|
30
|
+
.name(CONNECTOR_NAME)
|
|
31
|
+
.description('Weights & Biases GraphQL API connector CLI')
|
|
32
|
+
.version(VERSION)
|
|
33
|
+
.option('-k, --api-key <key>', 'API key (overrides config)')
|
|
34
|
+
.option('-f, --format <format>', 'Output format (json, pretty, table)', 'pretty')
|
|
35
|
+
.option('-p, --profile <profile>', 'Use a specific profile')
|
|
36
|
+
.hook('preAction', (thisCommand) => {
|
|
37
|
+
const opts = thisCommand.opts();
|
|
38
|
+
if (opts.profile) {
|
|
39
|
+
if (!profileExists(opts.profile)) {
|
|
40
|
+
error(`Profile "${opts.profile}" does not exist. Create it with "${CONNECTOR_NAME} profile create ${opts.profile}"`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
setProfileOverride(opts.profile);
|
|
44
|
+
}
|
|
45
|
+
if (opts.apiKey) {
|
|
46
|
+
process.env.WANDB_API_KEY = opts.apiKey;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function getFormat(cmd: Command): OutputFormat {
|
|
51
|
+
const parent = cmd.parent;
|
|
52
|
+
return (parent?.opts().format || 'pretty') as OutputFormat;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getClient(): Wandb {
|
|
56
|
+
const apiKey = getApiKey();
|
|
57
|
+
if (!apiKey) {
|
|
58
|
+
error(`No API key configured. Run "${CONNECTOR_NAME} config set-key <key>" or set WANDB_API_KEY environment variable.`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const baseUrl = getBaseUrl();
|
|
62
|
+
return new Wandb({ apiKey, baseUrl });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const profileCmd = program
|
|
66
|
+
.command('profile')
|
|
67
|
+
.description('Manage configuration profiles');
|
|
68
|
+
|
|
69
|
+
profileCmd
|
|
70
|
+
.command('list')
|
|
71
|
+
.description('List all profiles')
|
|
72
|
+
.action(() => {
|
|
73
|
+
const profiles = listProfiles();
|
|
74
|
+
const current = getCurrentProfile();
|
|
75
|
+
|
|
76
|
+
if (profiles.length === 0) {
|
|
77
|
+
info('No profiles found. Use "profile create <name>" to create one.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
success('Profiles:');
|
|
82
|
+
profiles.forEach(p => {
|
|
83
|
+
const isActive = p === current ? chalk.green(' (active)') : '';
|
|
84
|
+
console.log(` ${p}${isActive}`);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
profileCmd
|
|
89
|
+
.command('use <name>')
|
|
90
|
+
.description('Switch to a profile')
|
|
91
|
+
.action((name: string) => {
|
|
92
|
+
if (!profileExists(name)) {
|
|
93
|
+
error(`Profile "${name}" does not exist. Create it with "profile create ${name}"`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
setCurrentProfile(name);
|
|
97
|
+
success(`Switched to profile: ${name}`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
profileCmd
|
|
101
|
+
.command('create <name>')
|
|
102
|
+
.description('Create a new profile')
|
|
103
|
+
.option('--api-key <key>', 'API key')
|
|
104
|
+
.option('--use', 'Switch to this profile after creation')
|
|
105
|
+
.action((name: string, opts) => {
|
|
106
|
+
if (profileExists(name)) {
|
|
107
|
+
error(`Profile "${name}" already exists`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
createProfile(name, { apiKey: opts.apiKey });
|
|
112
|
+
success(`Profile "${name}" created`);
|
|
113
|
+
|
|
114
|
+
if (opts.use) {
|
|
115
|
+
setCurrentProfile(name);
|
|
116
|
+
info(`Switched to profile: ${name}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
profileCmd
|
|
121
|
+
.command('delete <name>')
|
|
122
|
+
.description('Delete a profile')
|
|
123
|
+
.action((name: string) => {
|
|
124
|
+
if (name === 'default') {
|
|
125
|
+
error('Cannot delete the default profile');
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
if (deleteProfile(name)) {
|
|
129
|
+
success(`Profile "${name}" deleted`);
|
|
130
|
+
} else {
|
|
131
|
+
error(`Profile "${name}" not found`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
profileCmd
|
|
137
|
+
.command('show [name]')
|
|
138
|
+
.description('Show profile configuration')
|
|
139
|
+
.action((name?: string) => {
|
|
140
|
+
const profileName = name || getCurrentProfile();
|
|
141
|
+
const config = loadProfile(profileName);
|
|
142
|
+
const active = getCurrentProfile();
|
|
143
|
+
|
|
144
|
+
console.log(chalk.bold(`Profile: ${profileName}${profileName === active ? chalk.green(' (active)') : ''}`));
|
|
145
|
+
info(`API Key: ${config.apiKey ? `${config.apiKey.substring(0, 8)}...` : chalk.gray('not set')}`);
|
|
146
|
+
info(`Base URL: ${config.baseUrl || chalk.gray('default (https://api.wandb.ai/graphql)')}`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const configCmd = program
|
|
150
|
+
.command('config')
|
|
151
|
+
.description('Manage CLI configuration (for active profile)');
|
|
152
|
+
|
|
153
|
+
configCmd
|
|
154
|
+
.command('set-key <apiKey>')
|
|
155
|
+
.description('Set API key')
|
|
156
|
+
.action((apiKey: string) => {
|
|
157
|
+
setApiKey(apiKey);
|
|
158
|
+
success(`API key saved to profile: ${getCurrentProfile()}`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
configCmd
|
|
162
|
+
.command('set-base-url <url>')
|
|
163
|
+
.description('Set custom GraphQL base URL')
|
|
164
|
+
.action((url: string) => {
|
|
165
|
+
setBaseUrl(url);
|
|
166
|
+
success(`Base URL saved to profile: ${getCurrentProfile()}`);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
configCmd
|
|
170
|
+
.command('show')
|
|
171
|
+
.description('Show current configuration')
|
|
172
|
+
.action(() => {
|
|
173
|
+
const profileName = getCurrentProfile();
|
|
174
|
+
const apiKey = getApiKey();
|
|
175
|
+
const baseUrl = getBaseUrl();
|
|
176
|
+
|
|
177
|
+
console.log(chalk.bold(`Active Profile: ${profileName}`));
|
|
178
|
+
info(`Config directory: ${getConfigDir()}`);
|
|
179
|
+
info(`API Key: ${apiKey ? `${apiKey.substring(0, 8)}...` : chalk.gray('not set')}`);
|
|
180
|
+
info(`Base URL: ${baseUrl || chalk.gray('default (https://api.wandb.ai/graphql)')}`);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
configCmd
|
|
184
|
+
.command('clear')
|
|
185
|
+
.description('Clear configuration for active profile')
|
|
186
|
+
.action(() => {
|
|
187
|
+
clearConfig();
|
|
188
|
+
success(`Configuration cleared for profile: ${getCurrentProfile()}`);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
program
|
|
192
|
+
.command('viewer')
|
|
193
|
+
.description('Get the authenticated viewer (current user)')
|
|
194
|
+
.action(async () => {
|
|
195
|
+
try {
|
|
196
|
+
const client = getClient();
|
|
197
|
+
const result = await client.viewer.get();
|
|
198
|
+
print(result.viewer, getFormat(program));
|
|
199
|
+
} catch (err) {
|
|
200
|
+
error(String(err));
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
program
|
|
206
|
+
.command('project-runs')
|
|
207
|
+
.description('List runs for a project')
|
|
208
|
+
.requiredOption('--entity <entity>', 'Entity (username or team)')
|
|
209
|
+
.requiredOption('--project <project>', 'Project name')
|
|
210
|
+
.option('--first <n>', 'Max runs to fetch', '50')
|
|
211
|
+
.option('--order <order>', 'Sort order (e.g. -created_at)')
|
|
212
|
+
.option('--filters <json>', 'Run filters as JSON object')
|
|
213
|
+
.action(async (opts) => {
|
|
214
|
+
try {
|
|
215
|
+
const client = getClient();
|
|
216
|
+
const filters = opts.filters ? JSON.parse(opts.filters) : undefined;
|
|
217
|
+
const result = await client.projects.projectRuns({
|
|
218
|
+
entity: opts.entity,
|
|
219
|
+
project: opts.project,
|
|
220
|
+
first: parseInt(opts.first, 10),
|
|
221
|
+
order: opts.order,
|
|
222
|
+
filters,
|
|
223
|
+
});
|
|
224
|
+
const runs = result.project?.runs.edges.map(e => e.node) ?? [];
|
|
225
|
+
print(runs, getFormat(program));
|
|
226
|
+
} catch (err) {
|
|
227
|
+
error(String(err));
|
|
228
|
+
process.exit(1);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
program
|
|
233
|
+
.command('graphql')
|
|
234
|
+
.description('Execute an ad-hoc GraphQL query')
|
|
235
|
+
.requiredOption('--query <query>', 'GraphQL query string')
|
|
236
|
+
.option('--variables <json>', 'Query variables as JSON object')
|
|
237
|
+
.action(async (opts) => {
|
|
238
|
+
try {
|
|
239
|
+
const client = getClient();
|
|
240
|
+
const variables = opts.variables ? JSON.parse(opts.variables) : undefined;
|
|
241
|
+
const result = await client.graphql.execute(opts.query, variables);
|
|
242
|
+
print(result, getFormat(program));
|
|
243
|
+
} catch (err) {
|
|
244
|
+
error(String(err));
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
program
|
|
250
|
+
.command('raw')
|
|
251
|
+
.description('Send a raw JSON body to the GraphQL endpoint')
|
|
252
|
+
.requiredOption('--body <json>', 'Request body as JSON (query + variables)')
|
|
253
|
+
.action(async (opts) => {
|
|
254
|
+
try {
|
|
255
|
+
const client = getClient();
|
|
256
|
+
const body = JSON.parse(opts.body);
|
|
257
|
+
const result = await client.getClient().raw(body);
|
|
258
|
+
print(result, getFormat(program));
|
|
259
|
+
} catch (err) {
|
|
260
|
+
error(String(err));
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
program.parse();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Weights & Biases GraphQL API Connector
|
|
2
|
+
|
|
3
|
+
export { Wandb } from './api';
|
|
4
|
+
export * from './types';
|
|
5
|
+
|
|
6
|
+
export { WandbClient, DEFAULT_BASE_URL } from './api';
|
|
7
|
+
export { ViewerApi, ProjectsApi, GraphqlApi } from './api';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
getApiKey,
|
|
11
|
+
setApiKey,
|
|
12
|
+
getBaseUrl,
|
|
13
|
+
setBaseUrl,
|
|
14
|
+
getCurrentProfile,
|
|
15
|
+
setCurrentProfile,
|
|
16
|
+
listProfiles,
|
|
17
|
+
createProfile,
|
|
18
|
+
deleteProfile,
|
|
19
|
+
loadProfile,
|
|
20
|
+
saveProfile,
|
|
21
|
+
clearConfig,
|
|
22
|
+
} from './utils/config';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Weights & Biases GraphQL API types
|
|
2
|
+
|
|
3
|
+
export type OutputFormat = 'json' | 'table' | 'pretty';
|
|
4
|
+
|
|
5
|
+
export interface WandbConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ProfileConfig {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class WandbApiError extends Error {
|
|
16
|
+
constructor(
|
|
17
|
+
message: string,
|
|
18
|
+
public readonly code: string,
|
|
19
|
+
public readonly statusCode?: number
|
|
20
|
+
) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'WandbApiError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GraphQLResponse<T> {
|
|
27
|
+
data?: T;
|
|
28
|
+
errors?: Array<{
|
|
29
|
+
message: string;
|
|
30
|
+
locations?: Array<{ line: number; column: number }>;
|
|
31
|
+
path?: string[];
|
|
32
|
+
extensions?: Record<string, unknown>;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface WandbViewer {
|
|
37
|
+
id: string;
|
|
38
|
+
username: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
email?: string;
|
|
41
|
+
entity?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ViewerResponse {
|
|
45
|
+
viewer: WandbViewer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface WandbRun {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
displayName?: string;
|
|
52
|
+
state?: string;
|
|
53
|
+
createdAt?: string;
|
|
54
|
+
summaryMetrics?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ProjectRunsResponse {
|
|
58
|
+
project: {
|
|
59
|
+
runs: {
|
|
60
|
+
edges: Array<{ node: WandbRun }>;
|
|
61
|
+
pageInfo?: {
|
|
62
|
+
endCursor?: string;
|
|
63
|
+
hasNextPage?: boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
} | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ProjectRunsOptions {
|
|
70
|
+
entity: string;
|
|
71
|
+
project: string;
|
|
72
|
+
first?: number;
|
|
73
|
+
order?: string;
|
|
74
|
+
filters?: Record<string, unknown>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync } from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import type { ProfileConfig } from '../types';
|
|
5
|
+
|
|
6
|
+
const CONNECTOR_NAME = 'wandb';
|
|
7
|
+
const DEFAULT_PROFILE = 'default';
|
|
8
|
+
|
|
9
|
+
let profileOverride: string | undefined;
|
|
10
|
+
|
|
11
|
+
const CONFIG_DIR = join(homedir(), '.hasna', 'connectors', CONNECTOR_NAME);
|
|
12
|
+
const PROFILES_DIR = join(CONFIG_DIR, 'profiles');
|
|
13
|
+
const CURRENT_PROFILE_FILE = join(CONFIG_DIR, 'current_profile');
|
|
14
|
+
|
|
15
|
+
export function setProfileOverride(profile: string | undefined): void {
|
|
16
|
+
profileOverride = profile;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ensureConfigDir(): void {
|
|
20
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
21
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
if (!existsSync(PROFILES_DIR)) {
|
|
24
|
+
mkdirSync(PROFILES_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getProfilePath(profile: string): string {
|
|
29
|
+
return join(PROFILES_DIR, `${profile}.json`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getCurrentProfile(): string {
|
|
33
|
+
if (profileOverride) {
|
|
34
|
+
return profileOverride;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ensureConfigDir();
|
|
38
|
+
|
|
39
|
+
if (existsSync(CURRENT_PROFILE_FILE)) {
|
|
40
|
+
try {
|
|
41
|
+
const profile = readFileSync(CURRENT_PROFILE_FILE, 'utf-8').trim();
|
|
42
|
+
if (profile && profileExists(profile)) {
|
|
43
|
+
return profile;
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
// Fall through to default
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return DEFAULT_PROFILE;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function setCurrentProfile(profile: string): void {
|
|
54
|
+
ensureConfigDir();
|
|
55
|
+
|
|
56
|
+
if (!profileExists(profile) && profile !== DEFAULT_PROFILE) {
|
|
57
|
+
throw new Error(`Profile "${profile}" does not exist`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
writeFileSync(CURRENT_PROFILE_FILE, profile);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function profileExists(profile: string): boolean {
|
|
64
|
+
return existsSync(getProfilePath(profile));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function listProfiles(): string[] {
|
|
68
|
+
ensureConfigDir();
|
|
69
|
+
|
|
70
|
+
if (!existsSync(PROFILES_DIR)) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return readdirSync(PROFILES_DIR)
|
|
75
|
+
.filter(f => f.endsWith('.json'))
|
|
76
|
+
.map(f => f.replace('.json', ''))
|
|
77
|
+
.sort();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function createProfile(profile: string, config: ProfileConfig = {}): boolean {
|
|
81
|
+
ensureConfigDir();
|
|
82
|
+
|
|
83
|
+
if (profileExists(profile)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(profile)) {
|
|
88
|
+
throw new Error('Profile name can only contain letters, numbers, hyphens, and underscores');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
writeFileSync(getProfilePath(profile), JSON.stringify(config, null, 2));
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function deleteProfile(profile: string): boolean {
|
|
96
|
+
if (profile === DEFAULT_PROFILE) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!profileExists(profile)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (getCurrentProfile() === profile) {
|
|
105
|
+
setCurrentProfile(DEFAULT_PROFILE);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
rmSync(getProfilePath(profile));
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function loadProfile(profile?: string): ProfileConfig {
|
|
113
|
+
ensureConfigDir();
|
|
114
|
+
const profileName = profile || getCurrentProfile();
|
|
115
|
+
const profilePath = getProfilePath(profileName);
|
|
116
|
+
|
|
117
|
+
if (!existsSync(profilePath)) {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(readFileSync(profilePath, 'utf-8'));
|
|
123
|
+
} catch {
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function saveProfile(config: ProfileConfig, profile?: string): void {
|
|
129
|
+
ensureConfigDir();
|
|
130
|
+
const profileName = profile || getCurrentProfile();
|
|
131
|
+
writeFileSync(getProfilePath(profileName), JSON.stringify(config, null, 2));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getApiKey(): string | undefined {
|
|
135
|
+
return process.env.WANDB_API_KEY || loadProfile().apiKey;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function setApiKey(apiKey: string): void {
|
|
139
|
+
const config = loadProfile();
|
|
140
|
+
config.apiKey = apiKey;
|
|
141
|
+
saveProfile(config);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function getBaseUrl(): string | undefined {
|
|
145
|
+
return process.env.WANDB_BASE_URL || loadProfile().baseUrl;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function setBaseUrl(baseUrl: string): void {
|
|
149
|
+
const config = loadProfile();
|
|
150
|
+
config.baseUrl = baseUrl;
|
|
151
|
+
saveProfile(config);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function clearConfig(): void {
|
|
155
|
+
saveProfile({});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function getConfigDir(): string {
|
|
159
|
+
return CONFIG_DIR;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getActiveProfileName(): string {
|
|
163
|
+
return getCurrentProfile();
|
|
164
|
+
}
|
|
@@ -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
|
+
}
|