@mcoda/core 0.1.69 → 0.1.71
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/dist/api/AgentsApi.js +1 -1
- package/dist/api/MswarmApi.d.ts +61 -0
- package/dist/api/MswarmApi.d.ts.map +1 -1
- package/dist/api/MswarmApi.js +246 -5
- package/package.json +6 -6
package/dist/api/AgentsApi.js
CHANGED
|
@@ -8,7 +8,7 @@ const isManagedMswarmAgent = (agent) => {
|
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
const record = config;
|
|
11
|
-
return ["mswarmCloud", "mswarmSelfHosted"].some((key) => {
|
|
11
|
+
return ["mswarmCloud", "mswarmSelfHosted", "mswarmWorker"].some((key) => {
|
|
12
12
|
const managed = record[key];
|
|
13
13
|
return Boolean(managed &&
|
|
14
14
|
typeof managed === "object" &&
|
package/dist/api/MswarmApi.d.ts
CHANGED
|
@@ -33,6 +33,24 @@ export interface MswarmSelfHostedAgent extends MswarmCloudAgent {
|
|
|
33
33
|
source_agent_id?: string;
|
|
34
34
|
source_agent_slug?: string;
|
|
35
35
|
}
|
|
36
|
+
export interface MswarmWorkerAgent extends MswarmCloudAgent {
|
|
37
|
+
id?: string;
|
|
38
|
+
remote_slug?: string;
|
|
39
|
+
updated_at?: string;
|
|
40
|
+
adapter?: string;
|
|
41
|
+
source?: string;
|
|
42
|
+
worker?: {
|
|
43
|
+
installation_id?: string;
|
|
44
|
+
status?: string;
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
name?: string;
|
|
47
|
+
api_run_url?: string;
|
|
48
|
+
docdex_enabled?: boolean;
|
|
49
|
+
selected_agent?: Record<string, unknown> | null;
|
|
50
|
+
config_health?: Record<string, unknown>;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
36
54
|
export interface MswarmCloudAgentDetail extends MswarmCloudAgent {
|
|
37
55
|
pricing?: Record<string, unknown>;
|
|
38
56
|
supported_parameters?: string[];
|
|
@@ -42,6 +60,8 @@ export interface MswarmCloudAgentDetail extends MswarmCloudAgent {
|
|
|
42
60
|
}
|
|
43
61
|
export interface MswarmSelfHostedAgentDetail extends MswarmSelfHostedAgent, Omit<MswarmCloudAgentDetail, keyof MswarmCloudAgent> {
|
|
44
62
|
}
|
|
63
|
+
export interface MswarmWorkerAgentDetail extends MswarmWorkerAgent, Omit<MswarmCloudAgentDetail, keyof MswarmCloudAgent> {
|
|
64
|
+
}
|
|
45
65
|
export interface ListMswarmCloudAgentsOptions {
|
|
46
66
|
provider?: string;
|
|
47
67
|
limit?: number;
|
|
@@ -54,6 +74,17 @@ export interface ListMswarmCloudAgentsOptions {
|
|
|
54
74
|
export interface ListMswarmSelfHostedAgentsOptions extends ListMswarmCloudAgentsOptions {
|
|
55
75
|
includeUnreachable?: boolean;
|
|
56
76
|
}
|
|
77
|
+
export interface ListMswarmWorkerAgentsOptions extends ListMswarmCloudAgentsOptions {
|
|
78
|
+
includeDisabled?: boolean;
|
|
79
|
+
cursor?: string;
|
|
80
|
+
updatedAfter?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface MswarmWorkerCatalogPage {
|
|
83
|
+
workers: MswarmWorkerAgent[];
|
|
84
|
+
next_cursor: string | null;
|
|
85
|
+
generated_at?: string;
|
|
86
|
+
total?: number;
|
|
87
|
+
}
|
|
57
88
|
export interface MswarmApiOptions {
|
|
58
89
|
baseUrl?: string;
|
|
59
90
|
openAiBaseUrl?: string;
|
|
@@ -61,6 +92,7 @@ export interface MswarmApiOptions {
|
|
|
61
92
|
timeoutMs?: number;
|
|
62
93
|
agentSlugPrefix?: string;
|
|
63
94
|
selfHostedAgentSlugPrefix?: string;
|
|
95
|
+
workerAgentSlugPrefix?: string;
|
|
64
96
|
}
|
|
65
97
|
export interface MswarmConsentResponse {
|
|
66
98
|
consent_token: string;
|
|
@@ -101,6 +133,7 @@ interface ResolvedMswarmApiOptions {
|
|
|
101
133
|
timeoutMs: number;
|
|
102
134
|
agentSlugPrefix: string;
|
|
103
135
|
selfHostedAgentSlugPrefix: string;
|
|
136
|
+
workerAgentSlugPrefix: string;
|
|
104
137
|
}
|
|
105
138
|
export interface ManagedMswarmCloudConfig {
|
|
106
139
|
managed: true;
|
|
@@ -145,6 +178,25 @@ export interface ManagedMswarmSelfHostedAgentConfig extends Record<string, unkno
|
|
|
145
178
|
apiBaseUrl: string;
|
|
146
179
|
mswarmSelfHosted: ManagedMswarmSelfHostedConfig;
|
|
147
180
|
}
|
|
181
|
+
export interface ManagedMswarmWorkerConfig {
|
|
182
|
+
managed: true;
|
|
183
|
+
remoteSlug: string;
|
|
184
|
+
workerId: string;
|
|
185
|
+
provider: string;
|
|
186
|
+
modelId?: string;
|
|
187
|
+
displayName?: string;
|
|
188
|
+
description?: string;
|
|
189
|
+
catalogBaseUrl: string;
|
|
190
|
+
apiRunUrl?: string;
|
|
191
|
+
worker?: Record<string, unknown>;
|
|
192
|
+
sync?: Record<string, unknown>;
|
|
193
|
+
syncedAt: string;
|
|
194
|
+
}
|
|
195
|
+
export interface ManagedMswarmWorkerAgentConfig extends Record<string, unknown> {
|
|
196
|
+
baseUrl: string;
|
|
197
|
+
apiBaseUrl: string;
|
|
198
|
+
mswarmWorker: ManagedMswarmWorkerConfig;
|
|
199
|
+
}
|
|
148
200
|
export interface MswarmSyncRecord {
|
|
149
201
|
remoteSlug: string;
|
|
150
202
|
localSlug: string;
|
|
@@ -171,6 +223,7 @@ export declare class MswarmApi {
|
|
|
171
223
|
readonly baseUrl: string;
|
|
172
224
|
readonly agentSlugPrefix: string;
|
|
173
225
|
readonly selfHostedAgentSlugPrefix: string;
|
|
226
|
+
readonly workerAgentSlugPrefix: string;
|
|
174
227
|
constructor(repo: GlobalRepository, options: ResolvedMswarmApiOptions);
|
|
175
228
|
static create(options?: MswarmApiOptions): Promise<MswarmApi>;
|
|
176
229
|
static refreshManagedAgentAuth(apiKey: string): Promise<MswarmManagedAuthRefreshSummary>;
|
|
@@ -182,8 +235,16 @@ export declare class MswarmApi {
|
|
|
182
235
|
getCloudAgent(slug: string): Promise<MswarmCloudAgentDetail>;
|
|
183
236
|
listSelfHostedAgents(options?: ListMswarmSelfHostedAgentsOptions): Promise<MswarmSelfHostedAgent[]>;
|
|
184
237
|
getSelfHostedAgent(slug: string): Promise<MswarmSelfHostedAgentDetail>;
|
|
238
|
+
private listWorkerAgentPage;
|
|
239
|
+
listAllWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmWorkerAgent[]>;
|
|
240
|
+
listWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmWorkerCatalogPage>;
|
|
241
|
+
getWorker(slug: string): Promise<MswarmWorkerAgentDetail>;
|
|
242
|
+
runWorker(slug: string, payload: unknown, options?: {
|
|
243
|
+
idempotencyKey?: string;
|
|
244
|
+
}): Promise<Record<string, unknown>>;
|
|
185
245
|
syncCloudAgents(options?: ListMswarmCloudAgentsOptions): Promise<MswarmSyncSummary>;
|
|
186
246
|
syncSelfHostedAgents(options?: ListMswarmSelfHostedAgentsOptions): Promise<MswarmSyncSummary>;
|
|
247
|
+
syncWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmSyncSummary>;
|
|
187
248
|
issuePaidConsent(policyVersion?: string): Promise<MswarmConsentResponse>;
|
|
188
249
|
registerFreeMcodaClient(options: RegisterFreeMcodaClientOptions): Promise<MswarmConsentResponse>;
|
|
189
250
|
revokeConsent(consentToken: string, reason?: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MswarmApi.d.ts","sourceRoot":"","sources":["../../src/api/MswarmApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAY7C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,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AAa,SAAgC,GAC5C,OAAO,CAAC,qBAAqB,CAAC;IAoB3B,uBAAuB,CAC3B,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,qBAAqB,CAAC;IAmB3B,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAclD,mBAAmB,CACvB,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,0BAA0B,CAAC;CAgBvC"}
|
package/dist/api/MswarmApi.js
CHANGED
|
@@ -5,6 +5,7 @@ const DEFAULT_BASE_URL = 'https://api.mswarm.org/';
|
|
|
5
5
|
const DEFAULT_TIMEOUT_MS = 15000;
|
|
6
6
|
const DEFAULT_AGENT_SLUG_PREFIX = 'mswarm-cloud';
|
|
7
7
|
const DEFAULT_SELF_HOSTED_AGENT_SLUG_PREFIX = 'mswarm-self-hosted';
|
|
8
|
+
const DEFAULT_WORKER_AGENT_SLUG_PREFIX = 'mswarm-worker';
|
|
8
9
|
export const MSWARM_CONSENT_POLICY_VERSION = '2026-03-18';
|
|
9
10
|
export const MCODA_FREE_CLIENT_TYPE = 'free_mcoda_client';
|
|
10
11
|
const MCODA_PRODUCT_SLUG = 'mcoda';
|
|
@@ -74,11 +75,14 @@ const resolveOptions = async (options = {}) => {
|
|
|
74
75
|
const directAgentSlugPrefix = options.agentSlugPrefix ?? process.env.MCODA_MSWARM_AGENT_SLUG_PREFIX;
|
|
75
76
|
const directSelfHostedAgentSlugPrefix = options.selfHostedAgentSlugPrefix ??
|
|
76
77
|
process.env.MCODA_MSWARM_SELF_HOSTED_AGENT_SLUG_PREFIX;
|
|
78
|
+
const directWorkerAgentSlugPrefix = options.workerAgentSlugPrefix ??
|
|
79
|
+
process.env.MCODA_MSWARM_WORKER_AGENT_SLUG_PREFIX;
|
|
77
80
|
const needsStoredFallback = directBaseUrl === undefined ||
|
|
78
81
|
directApiKey === undefined ||
|
|
79
82
|
directTimeout === undefined ||
|
|
80
83
|
directAgentSlugPrefix === undefined ||
|
|
81
|
-
directSelfHostedAgentSlugPrefix === undefined
|
|
84
|
+
directSelfHostedAgentSlugPrefix === undefined ||
|
|
85
|
+
directWorkerAgentSlugPrefix === undefined;
|
|
82
86
|
const stored = needsStoredFallback
|
|
83
87
|
? await new MswarmConfigStore().readState()
|
|
84
88
|
: {};
|
|
@@ -93,6 +97,8 @@ const resolveOptions = async (options = {}) => {
|
|
|
93
97
|
DEFAULT_AGENT_SLUG_PREFIX,
|
|
94
98
|
selfHostedAgentSlugPrefix: resolveString(directSelfHostedAgentSlugPrefix) ??
|
|
95
99
|
DEFAULT_SELF_HOSTED_AGENT_SLUG_PREFIX,
|
|
100
|
+
workerAgentSlugPrefix: resolveString(directWorkerAgentSlugPrefix) ??
|
|
101
|
+
DEFAULT_WORKER_AGENT_SLUG_PREFIX,
|
|
96
102
|
};
|
|
97
103
|
};
|
|
98
104
|
const uniqueStrings = (values) => Array.from(new Set(values.filter((value) => value.trim().length > 0)));
|
|
@@ -188,6 +194,10 @@ const toManagedLocalSlug = (prefix, remoteSlug) => {
|
|
|
188
194
|
.replace(/^-+|-+$/g, '');
|
|
189
195
|
return `${prefix}-${normalized || 'agent'}`;
|
|
190
196
|
};
|
|
197
|
+
const toManagedWorkerLocalSlug = (prefix, agent) => {
|
|
198
|
+
const base = agent.slug.startsWith('worker_') ? agent.slug.slice('worker_'.length) : agent.slug;
|
|
199
|
+
return toManagedLocalSlug(prefix, base);
|
|
200
|
+
};
|
|
191
201
|
const toHealthStatus = (value) => {
|
|
192
202
|
const normalized = value?.trim().toLowerCase();
|
|
193
203
|
if (!normalized)
|
|
@@ -196,16 +206,21 @@ const toHealthStatus = (value) => {
|
|
|
196
206
|
return 'healthy';
|
|
197
207
|
if (normalized === 'degraded' ||
|
|
198
208
|
normalized === 'unknown' ||
|
|
199
|
-
normalized === 'limited'
|
|
209
|
+
normalized === 'limited' ||
|
|
210
|
+
normalized === 'stale' ||
|
|
211
|
+
normalized === 'misconfigured')
|
|
200
212
|
return 'degraded';
|
|
201
|
-
if (normalized === 'unreachable' ||
|
|
213
|
+
if (normalized === 'unreachable' ||
|
|
214
|
+
normalized === 'offline' ||
|
|
215
|
+
normalized === 'disabled')
|
|
202
216
|
return 'unreachable';
|
|
203
217
|
return undefined;
|
|
204
218
|
};
|
|
205
219
|
const isSyncManagedHealth = (health) => isRecord(health?.details) &&
|
|
206
220
|
(health.details.source === 'mswarm' ||
|
|
207
221
|
health.details.source === 'mswarm_catalog' ||
|
|
208
|
-
health.details.source === 'mswarm_self_hosted'
|
|
222
|
+
health.details.source === 'mswarm_self_hosted' ||
|
|
223
|
+
health.details.source === 'mswarm_worker');
|
|
209
224
|
const isAuthMissingManagedHealth = (health) => {
|
|
210
225
|
if (!isRecord(health?.details))
|
|
211
226
|
return false;
|
|
@@ -230,7 +245,16 @@ const isManagedMswarmSelfHostedConfig = (config) => {
|
|
|
230
245
|
return false;
|
|
231
246
|
return config.mswarmSelfHosted.managed === true;
|
|
232
247
|
};
|
|
233
|
-
const
|
|
248
|
+
const isManagedMswarmWorkerConfig = (config) => {
|
|
249
|
+
if (!isRecord(config))
|
|
250
|
+
return false;
|
|
251
|
+
if (!isRecord(config.mswarmWorker))
|
|
252
|
+
return false;
|
|
253
|
+
return config.mswarmWorker.managed === true;
|
|
254
|
+
};
|
|
255
|
+
const isManagedMswarmConfig = (config) => isManagedMswarmCloudConfig(config) ||
|
|
256
|
+
isManagedMswarmSelfHostedConfig(config) ||
|
|
257
|
+
isManagedMswarmWorkerConfig(config);
|
|
234
258
|
const toManagedConfig = (existingConfig, catalogBaseUrl, openAiBaseUrl, agent, syncedAt) => {
|
|
235
259
|
const nextConfig = {
|
|
236
260
|
...(existingConfig ?? {}),
|
|
@@ -281,6 +305,32 @@ const toManagedSelfHostedConfig = (existingConfig, catalogBaseUrl, openAiBaseUrl
|
|
|
281
305
|
};
|
|
282
306
|
return nextConfig;
|
|
283
307
|
};
|
|
308
|
+
const toManagedWorkerConfig = (existingConfig, catalogBaseUrl, agent, syncedAt) => {
|
|
309
|
+
const sync = isRecord(agent.sync) ? agent.sync : {};
|
|
310
|
+
const worker = isRecord(agent.worker) ? agent.worker : {};
|
|
311
|
+
const workerId = agent.id ?? agent.slug;
|
|
312
|
+
const apiRunUrl = resolveString(worker.api_run_url);
|
|
313
|
+
const nextConfig = {
|
|
314
|
+
...(existingConfig ?? {}),
|
|
315
|
+
baseUrl: catalogBaseUrl,
|
|
316
|
+
apiBaseUrl: catalogBaseUrl,
|
|
317
|
+
mswarmWorker: {
|
|
318
|
+
managed: true,
|
|
319
|
+
remoteSlug: agent.remote_slug ?? agent.slug,
|
|
320
|
+
workerId,
|
|
321
|
+
provider: agent.provider,
|
|
322
|
+
modelId: agent.model_id,
|
|
323
|
+
displayName: agent.display_name,
|
|
324
|
+
description: agent.description,
|
|
325
|
+
catalogBaseUrl,
|
|
326
|
+
apiRunUrl,
|
|
327
|
+
worker: Object.keys(worker).length > 0 ? worker : undefined,
|
|
328
|
+
sync: Object.keys(sync).length > 0 ? sync : undefined,
|
|
329
|
+
syncedAt,
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
return nextConfig;
|
|
333
|
+
};
|
|
284
334
|
const toManagedSyncRecord = (config, localSlug, defaultModel, action) => ({
|
|
285
335
|
remoteSlug: config.mswarmCloud.remoteSlug,
|
|
286
336
|
localSlug,
|
|
@@ -296,6 +346,13 @@ const toManagedSelfHostedSyncRecord = (config, localSlug, defaultModel, action)
|
|
|
296
346
|
provider: config.mswarmSelfHosted.provider,
|
|
297
347
|
defaultModel,
|
|
298
348
|
});
|
|
349
|
+
const toManagedWorkerSyncRecord = (config, localSlug, defaultModel, action) => ({
|
|
350
|
+
remoteSlug: config.mswarmWorker.remoteSlug,
|
|
351
|
+
localSlug,
|
|
352
|
+
action,
|
|
353
|
+
provider: config.mswarmWorker.provider,
|
|
354
|
+
defaultModel,
|
|
355
|
+
});
|
|
299
356
|
const toCloudAgent = (value) => {
|
|
300
357
|
if (!isRecord(value)) {
|
|
301
358
|
throw new Error('mswarm returned an invalid cloud-agent payload');
|
|
@@ -371,6 +428,31 @@ const toSelfHostedAgentDetail = (value) => {
|
|
|
371
428
|
mcoda_shape: isRecord(record.mcoda_shape) ? record.mcoda_shape : undefined,
|
|
372
429
|
};
|
|
373
430
|
};
|
|
431
|
+
const toWorkerAgent = (value) => {
|
|
432
|
+
const agent = toCloudAgent(value);
|
|
433
|
+
const record = isRecord(value) ? value : {};
|
|
434
|
+
return {
|
|
435
|
+
...agent,
|
|
436
|
+
id: resolveString(record.id),
|
|
437
|
+
remote_slug: resolveString(record.remote_slug),
|
|
438
|
+
updated_at: resolveTimestamp(record.updated_at),
|
|
439
|
+
adapter: resolveString(record.adapter),
|
|
440
|
+
source: resolveString(record.source),
|
|
441
|
+
worker: isRecord(record.worker) ? record.worker : undefined,
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
const toWorkerAgentDetail = (value) => {
|
|
445
|
+
const agent = toWorkerAgent(value);
|
|
446
|
+
const record = isRecord(value) ? value : {};
|
|
447
|
+
return {
|
|
448
|
+
...agent,
|
|
449
|
+
pricing: isRecord(record.pricing) ? record.pricing : undefined,
|
|
450
|
+
supported_parameters: resolveStringArray(record.supported_parameters),
|
|
451
|
+
status: resolveString(record.status),
|
|
452
|
+
moderation_status: resolveString(record.moderation_status),
|
|
453
|
+
mcoda_shape: isRecord(record.mcoda_shape) ? record.mcoda_shape : undefined,
|
|
454
|
+
};
|
|
455
|
+
};
|
|
374
456
|
const hasAdvancedCloudAgentSelection = (options) => options.maxCostPerMillion !== undefined ||
|
|
375
457
|
options.minContextWindow !== undefined ||
|
|
376
458
|
options.minReasoningRating !== undefined ||
|
|
@@ -428,6 +510,7 @@ export class MswarmApi {
|
|
|
428
510
|
this.baseUrl = options.baseUrl;
|
|
429
511
|
this.agentSlugPrefix = options.agentSlugPrefix;
|
|
430
512
|
this.selfHostedAgentSlugPrefix = options.selfHostedAgentSlugPrefix;
|
|
513
|
+
this.workerAgentSlugPrefix = options.workerAgentSlugPrefix;
|
|
431
514
|
}
|
|
432
515
|
static async create(options = {}) {
|
|
433
516
|
const repo = await GlobalRepository.create();
|
|
@@ -560,6 +643,78 @@ export class MswarmApi {
|
|
|
560
643
|
const payload = await this.requestJson(`/v1/swarm/self-hosted/agents/${encodeURIComponent(slug)}`);
|
|
561
644
|
return toSelfHostedAgentDetail(payload);
|
|
562
645
|
}
|
|
646
|
+
async listWorkerAgentPage(options = {}) {
|
|
647
|
+
const query = {
|
|
648
|
+
shape: 'mcoda',
|
|
649
|
+
limit: options.limit,
|
|
650
|
+
cursor: options.cursor,
|
|
651
|
+
updated_after: options.updatedAfter,
|
|
652
|
+
};
|
|
653
|
+
if (options.includeDisabled !== undefined) {
|
|
654
|
+
query.include_disabled = options.includeDisabled ? 'true' : 'false';
|
|
655
|
+
}
|
|
656
|
+
const payload = await this.requestJson('/v1/swarm/workers', query);
|
|
657
|
+
const values = Array.isArray(payload.agents)
|
|
658
|
+
? payload.agents
|
|
659
|
+
: Array.isArray(payload.workers)
|
|
660
|
+
? payload.workers
|
|
661
|
+
: [];
|
|
662
|
+
return {
|
|
663
|
+
workers: values.map(toWorkerAgent),
|
|
664
|
+
next_cursor: resolveString(payload.next_cursor) ?? null,
|
|
665
|
+
generated_at: resolveTimestamp(payload.generated_at),
|
|
666
|
+
total: resolveNumber(payload.total),
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
async listAllWorkers(options = {}) {
|
|
670
|
+
const requestedLimit = normalizeOptionalPositiveInt(options.limit, 'limit');
|
|
671
|
+
const pageLimit = requestedLimit !== undefined ? Math.min(requestedLimit, 250) : 250;
|
|
672
|
+
const collected = [];
|
|
673
|
+
let cursor;
|
|
674
|
+
do {
|
|
675
|
+
const page = await this.listWorkerAgentPage({
|
|
676
|
+
...options,
|
|
677
|
+
limit: pageLimit,
|
|
678
|
+
cursor,
|
|
679
|
+
});
|
|
680
|
+
collected.push(...page.workers);
|
|
681
|
+
cursor = page.next_cursor ?? undefined;
|
|
682
|
+
if (requestedLimit !== undefined && collected.length >= requestedLimit) {
|
|
683
|
+
return applyCloudAgentListOptions(collected.slice(0, requestedLimit), options);
|
|
684
|
+
}
|
|
685
|
+
} while (cursor);
|
|
686
|
+
return applyCloudAgentListOptions(collected, options);
|
|
687
|
+
}
|
|
688
|
+
async listWorkers(options = {}) {
|
|
689
|
+
const page = await this.listWorkerAgentPage(options);
|
|
690
|
+
let agents = page.workers;
|
|
691
|
+
if (options.provider) {
|
|
692
|
+
agents = agents.filter((agent) => agent.provider === options.provider);
|
|
693
|
+
}
|
|
694
|
+
return {
|
|
695
|
+
...page,
|
|
696
|
+
workers: applyCloudAgentListOptions(agents, options),
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
async getWorker(slug) {
|
|
700
|
+
if (!slug.trim()) {
|
|
701
|
+
throw new Error('Worker slug is required');
|
|
702
|
+
}
|
|
703
|
+
const payload = await this.requestJson(`/v1/swarm/workers/${encodeURIComponent(slug)}`);
|
|
704
|
+
return toWorkerAgentDetail(payload);
|
|
705
|
+
}
|
|
706
|
+
async runWorker(slug, payload, options = {}) {
|
|
707
|
+
if (!slug.trim()) {
|
|
708
|
+
throw new Error('Worker slug is required');
|
|
709
|
+
}
|
|
710
|
+
return this.requestJson(`/v1/swarm/workers/${encodeURIComponent(slug)}/run`, undefined, {
|
|
711
|
+
method: 'POST',
|
|
712
|
+
body: payload ?? {},
|
|
713
|
+
headers: options.idempotencyKey
|
|
714
|
+
? { 'idempotency-key': options.idempotencyKey }
|
|
715
|
+
: undefined,
|
|
716
|
+
});
|
|
717
|
+
}
|
|
563
718
|
async syncCloudAgents(options = {}) {
|
|
564
719
|
if (options.pruneMissing &&
|
|
565
720
|
(options.limit !== undefined || hasAdvancedCloudAgentSelection(options))) {
|
|
@@ -721,6 +876,92 @@ export class MswarmApi {
|
|
|
721
876
|
agents: records,
|
|
722
877
|
};
|
|
723
878
|
}
|
|
879
|
+
async syncWorkers(options = {}) {
|
|
880
|
+
if (options.pruneMissing &&
|
|
881
|
+
(options.limit !== undefined ||
|
|
882
|
+
options.cursor !== undefined ||
|
|
883
|
+
options.updatedAfter !== undefined ||
|
|
884
|
+
options.includeDisabled === false ||
|
|
885
|
+
hasAdvancedCloudAgentSelection(options))) {
|
|
886
|
+
throw new Error('pruneMissing cannot be combined with partial worker catalog filters');
|
|
887
|
+
}
|
|
888
|
+
const agents = await this.listAllWorkers(options);
|
|
889
|
+
const syncedAt = new Date().toISOString();
|
|
890
|
+
const encryptedApiKey = await CryptoHelper.encryptSecret(this.requireApiKey());
|
|
891
|
+
const records = [];
|
|
892
|
+
for (const agent of agents) {
|
|
893
|
+
const localSlug = toManagedWorkerLocalSlug(this.options.workerAgentSlugPrefix, agent);
|
|
894
|
+
const existing = await this.repo.getAgentBySlug(localSlug);
|
|
895
|
+
const remoteSlug = agent.remote_slug ?? agent.slug;
|
|
896
|
+
if (existing &&
|
|
897
|
+
(!isManagedMswarmWorkerConfig(existing.config) ||
|
|
898
|
+
existing.config.mswarmWorker.remoteSlug !== remoteSlug)) {
|
|
899
|
+
throw new Error(`Refusing to overwrite non-mswarm agent ${localSlug}`);
|
|
900
|
+
}
|
|
901
|
+
const existingConfig = existing && isRecord(existing.config)
|
|
902
|
+
? existing.config
|
|
903
|
+
: undefined;
|
|
904
|
+
const nextConfig = toManagedWorkerConfig(existingConfig, this.options.baseUrl, agent, syncedAt);
|
|
905
|
+
const createInput = {
|
|
906
|
+
...toSyncedAgentInput(existing, agent, localSlug, nextConfig, syncedAt),
|
|
907
|
+
adapter: 'mswarm-worker',
|
|
908
|
+
openaiCompatible: false,
|
|
909
|
+
};
|
|
910
|
+
const { slug: _ignoredSlug, ...updateInput } = createInput;
|
|
911
|
+
const stored = existing
|
|
912
|
+
? await this.repo.updateAgent(existing.id, updateInput)
|
|
913
|
+
: await this.repo.createAgent(createInput);
|
|
914
|
+
if (!stored) {
|
|
915
|
+
throw new Error(`Failed to persist synced worker ${localSlug}`);
|
|
916
|
+
}
|
|
917
|
+
await this.repo.setAgentModels(stored.id, toAgentModels(stored.id, agent));
|
|
918
|
+
await this.repo.setAgentAuth(stored.id, encryptedApiKey);
|
|
919
|
+
const existingHealth = existing
|
|
920
|
+
? await this.repo.getAgentHealth(existing.id)
|
|
921
|
+
: undefined;
|
|
922
|
+
const mappedHealth = toHealthStatus(agent.health_status);
|
|
923
|
+
if (mappedHealth && shouldReplaceManagedHealth(existingHealth)) {
|
|
924
|
+
const health = {
|
|
925
|
+
agentId: stored.id,
|
|
926
|
+
status: mappedHealth,
|
|
927
|
+
lastCheckedAt: syncedAt,
|
|
928
|
+
details: {
|
|
929
|
+
source: 'mswarm_worker',
|
|
930
|
+
remoteSlug,
|
|
931
|
+
workerId: agent.id ?? agent.slug,
|
|
932
|
+
remoteHealthStatus: agent.health_status,
|
|
933
|
+
},
|
|
934
|
+
};
|
|
935
|
+
await this.repo.setAgentHealth(health);
|
|
936
|
+
}
|
|
937
|
+
records.push(toManagedWorkerSyncRecord(nextConfig, localSlug, agent.default_model, existing ? 'updated' : 'created'));
|
|
938
|
+
}
|
|
939
|
+
if (options.pruneMissing) {
|
|
940
|
+
const remoteSlugs = new Set(agents.map((agent) => agent.remote_slug ?? agent.slug));
|
|
941
|
+
const localAgents = await this.repo.listAgents();
|
|
942
|
+
for (const localAgent of localAgents) {
|
|
943
|
+
const managedConfig = isManagedMswarmWorkerConfig(localAgent.config)
|
|
944
|
+
? localAgent.config
|
|
945
|
+
: undefined;
|
|
946
|
+
if (!managedConfig)
|
|
947
|
+
continue;
|
|
948
|
+
if (options.provider &&
|
|
949
|
+
managedConfig.mswarmWorker.provider !== options.provider) {
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (remoteSlugs.has(managedConfig.mswarmWorker.remoteSlug))
|
|
953
|
+
continue;
|
|
954
|
+
await this.repo.deleteAgent(localAgent.id);
|
|
955
|
+
records.push(toManagedWorkerSyncRecord(managedConfig, localAgent.slug, localAgent.defaultModel ?? managedConfig.mswarmWorker.modelId ?? '-', 'deleted'));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
created: records.filter((record) => record.action === 'created').length,
|
|
960
|
+
updated: records.filter((record) => record.action === 'updated').length,
|
|
961
|
+
deleted: records.filter((record) => record.action === 'deleted').length,
|
|
962
|
+
agents: records,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
724
965
|
async issuePaidConsent(policyVersion = MSWARM_CONSENT_POLICY_VERSION) {
|
|
725
966
|
const apiKey = this.requireApiKey();
|
|
726
967
|
return this.requestJson('/v1/swarm/consent/issue', undefined, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcoda/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "Core services and APIs for the mcoda CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
34
34
|
"yaml": "^2.4.2",
|
|
35
|
-
"@mcoda/shared": "0.1.
|
|
36
|
-
"@mcoda/db": "0.1.
|
|
37
|
-
"@mcoda/
|
|
38
|
-
"@mcoda/
|
|
39
|
-
"@mcoda/
|
|
35
|
+
"@mcoda/shared": "0.1.71",
|
|
36
|
+
"@mcoda/db": "0.1.71",
|
|
37
|
+
"@mcoda/generators": "0.1.71",
|
|
38
|
+
"@mcoda/agents": "0.1.71",
|
|
39
|
+
"@mcoda/integrations": "0.1.71"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsc -p tsconfig.json",
|