@mcoda/core 0.1.70 → 0.1.72
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 +89 -0
- package/dist/api/MswarmApi.d.ts.map +1 -1
- package/dist/api/MswarmApi.js +289 -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;
|
|
@@ -163,6 +215,32 @@ export interface MswarmManagedAuthRefreshSummary {
|
|
|
163
215
|
updated: number;
|
|
164
216
|
agents: string[];
|
|
165
217
|
}
|
|
218
|
+
export interface MswarmRuntimeUsageBudget {
|
|
219
|
+
key: string;
|
|
220
|
+
meter_id?: string | null;
|
|
221
|
+
limit?: number | null;
|
|
222
|
+
used?: number | null;
|
|
223
|
+
remaining?: number | null;
|
|
224
|
+
reset_at?: string | null;
|
|
225
|
+
source?: string | null;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
export interface MswarmRuntimeUsageLimits {
|
|
229
|
+
product_slug: string | null;
|
|
230
|
+
tenant_id: string | null;
|
|
231
|
+
api_key_id: string | null;
|
|
232
|
+
subscription_id: string | null;
|
|
233
|
+
budgets: MswarmRuntimeUsageBudget[];
|
|
234
|
+
as_of: string | null;
|
|
235
|
+
}
|
|
236
|
+
export interface MswarmRuntimeIdentity {
|
|
237
|
+
tenantId: string | null;
|
|
238
|
+
productSlug: string | null;
|
|
239
|
+
apiKeyId: string | null;
|
|
240
|
+
subscriptionId: string | null;
|
|
241
|
+
asOf: string | null;
|
|
242
|
+
usageLimits: MswarmRuntimeUsageLimits;
|
|
243
|
+
}
|
|
166
244
|
export declare const MSWARM_CONSENT_POLICY_VERSION = "2026-03-18";
|
|
167
245
|
export declare const MCODA_FREE_CLIENT_TYPE = "free_mcoda_client";
|
|
168
246
|
export declare class MswarmApi {
|
|
@@ -171,19 +249,30 @@ export declare class MswarmApi {
|
|
|
171
249
|
readonly baseUrl: string;
|
|
172
250
|
readonly agentSlugPrefix: string;
|
|
173
251
|
readonly selfHostedAgentSlugPrefix: string;
|
|
252
|
+
readonly workerAgentSlugPrefix: string;
|
|
174
253
|
constructor(repo: GlobalRepository, options: ResolvedMswarmApiOptions);
|
|
175
254
|
static create(options?: MswarmApiOptions): Promise<MswarmApi>;
|
|
176
255
|
static refreshManagedAgentAuth(apiKey: string): Promise<MswarmManagedAuthRefreshSummary>;
|
|
177
256
|
close(): Promise<void>;
|
|
178
257
|
refreshManagedAgentAuth(): Promise<MswarmManagedAuthRefreshSummary>;
|
|
258
|
+
getRuntimeUsageLimits(): Promise<MswarmRuntimeUsageLimits>;
|
|
259
|
+
getRuntimeIdentity(): Promise<MswarmRuntimeIdentity>;
|
|
179
260
|
private requireApiKey;
|
|
180
261
|
private requestJson;
|
|
181
262
|
listCloudAgents(options?: ListMswarmCloudAgentsOptions): Promise<MswarmCloudAgent[]>;
|
|
182
263
|
getCloudAgent(slug: string): Promise<MswarmCloudAgentDetail>;
|
|
183
264
|
listSelfHostedAgents(options?: ListMswarmSelfHostedAgentsOptions): Promise<MswarmSelfHostedAgent[]>;
|
|
184
265
|
getSelfHostedAgent(slug: string): Promise<MswarmSelfHostedAgentDetail>;
|
|
266
|
+
private listWorkerAgentPage;
|
|
267
|
+
listAllWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmWorkerAgent[]>;
|
|
268
|
+
listWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmWorkerCatalogPage>;
|
|
269
|
+
getWorker(slug: string): Promise<MswarmWorkerAgentDetail>;
|
|
270
|
+
runWorker(slug: string, payload: unknown, options?: {
|
|
271
|
+
idempotencyKey?: string;
|
|
272
|
+
}): Promise<Record<string, unknown>>;
|
|
185
273
|
syncCloudAgents(options?: ListMswarmCloudAgentsOptions): Promise<MswarmSyncSummary>;
|
|
186
274
|
syncSelfHostedAgents(options?: ListMswarmSelfHostedAgentsOptions): Promise<MswarmSyncSummary>;
|
|
275
|
+
syncWorkers(options?: ListMswarmWorkerAgentsOptions): Promise<MswarmSyncSummary>;
|
|
187
276
|
issuePaidConsent(policyVersion?: string): Promise<MswarmConsentResponse>;
|
|
188
277
|
registerFreeMcodaClient(options: RegisterFreeMcodaClientOptions): Promise<MswarmConsentResponse>;
|
|
189
278
|
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,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC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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';
|
|
@@ -24,6 +25,7 @@ const resolveStringArray = (value) => {
|
|
|
24
25
|
return [];
|
|
25
26
|
return value.filter((entry) => typeof entry === 'string' && entry.trim().length > 0);
|
|
26
27
|
};
|
|
28
|
+
const resolveNullableString = (value) => resolveString(value) ?? null;
|
|
27
29
|
const normalizeBaseUrl = (value, label) => {
|
|
28
30
|
const trimmed = value?.trim();
|
|
29
31
|
if (!trimmed) {
|
|
@@ -74,11 +76,14 @@ const resolveOptions = async (options = {}) => {
|
|
|
74
76
|
const directAgentSlugPrefix = options.agentSlugPrefix ?? process.env.MCODA_MSWARM_AGENT_SLUG_PREFIX;
|
|
75
77
|
const directSelfHostedAgentSlugPrefix = options.selfHostedAgentSlugPrefix ??
|
|
76
78
|
process.env.MCODA_MSWARM_SELF_HOSTED_AGENT_SLUG_PREFIX;
|
|
79
|
+
const directWorkerAgentSlugPrefix = options.workerAgentSlugPrefix ??
|
|
80
|
+
process.env.MCODA_MSWARM_WORKER_AGENT_SLUG_PREFIX;
|
|
77
81
|
const needsStoredFallback = directBaseUrl === undefined ||
|
|
78
82
|
directApiKey === undefined ||
|
|
79
83
|
directTimeout === undefined ||
|
|
80
84
|
directAgentSlugPrefix === undefined ||
|
|
81
|
-
directSelfHostedAgentSlugPrefix === undefined
|
|
85
|
+
directSelfHostedAgentSlugPrefix === undefined ||
|
|
86
|
+
directWorkerAgentSlugPrefix === undefined;
|
|
82
87
|
const stored = needsStoredFallback
|
|
83
88
|
? await new MswarmConfigStore().readState()
|
|
84
89
|
: {};
|
|
@@ -93,6 +98,8 @@ const resolveOptions = async (options = {}) => {
|
|
|
93
98
|
DEFAULT_AGENT_SLUG_PREFIX,
|
|
94
99
|
selfHostedAgentSlugPrefix: resolveString(directSelfHostedAgentSlugPrefix) ??
|
|
95
100
|
DEFAULT_SELF_HOSTED_AGENT_SLUG_PREFIX,
|
|
101
|
+
workerAgentSlugPrefix: resolveString(directWorkerAgentSlugPrefix) ??
|
|
102
|
+
DEFAULT_WORKER_AGENT_SLUG_PREFIX,
|
|
96
103
|
};
|
|
97
104
|
};
|
|
98
105
|
const uniqueStrings = (values) => Array.from(new Set(values.filter((value) => value.trim().length > 0)));
|
|
@@ -118,6 +125,33 @@ const resolveStringArrayFromRecordOrShape = (record, keys) => {
|
|
|
118
125
|
const values = sources.flatMap((source) => keys.flatMap((key) => resolveStringArray(source[key])));
|
|
119
126
|
return uniqueStrings(values);
|
|
120
127
|
};
|
|
128
|
+
const toRuntimeUsageBudget = (value) => {
|
|
129
|
+
const record = isRecord(value) ? value : {};
|
|
130
|
+
const budget = {
|
|
131
|
+
...record,
|
|
132
|
+
key: resolveString(record.key) ?? resolveString(record.meter_id) ?? 'unknown',
|
|
133
|
+
meter_id: resolveNullableString(record.meter_id),
|
|
134
|
+
limit: resolveNumber(record.limit) ?? null,
|
|
135
|
+
used: resolveNumber(record.used) ?? null,
|
|
136
|
+
remaining: resolveNumber(record.remaining) ?? null,
|
|
137
|
+
reset_at: resolveNullableString(record.reset_at),
|
|
138
|
+
source: resolveNullableString(record.source),
|
|
139
|
+
};
|
|
140
|
+
return budget;
|
|
141
|
+
};
|
|
142
|
+
const toRuntimeUsageLimits = (value) => {
|
|
143
|
+
const record = isRecord(value) ? value : {};
|
|
144
|
+
return {
|
|
145
|
+
product_slug: resolveNullableString(record.product_slug ?? record.productSlug),
|
|
146
|
+
tenant_id: resolveNullableString(record.tenant_id ?? record.tenantId),
|
|
147
|
+
api_key_id: resolveNullableString(record.api_key_id ?? record.apiKeyId),
|
|
148
|
+
subscription_id: resolveNullableString(record.subscription_id ?? record.subscriptionId),
|
|
149
|
+
budgets: Array.isArray(record.budgets)
|
|
150
|
+
? record.budgets.map(toRuntimeUsageBudget)
|
|
151
|
+
: [],
|
|
152
|
+
as_of: resolveNullableString(record.as_of ?? record.asOf),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
121
155
|
const hasCapabilityFragment = (capabilities, fragments) => capabilities.some((capability) => fragments.some((fragment) => capability.includes(fragment)));
|
|
122
156
|
const inferCloudBestUsage = (agent) => {
|
|
123
157
|
const capabilities = agent.capabilities.map((capability) => capability.trim().toLowerCase());
|
|
@@ -188,6 +222,10 @@ const toManagedLocalSlug = (prefix, remoteSlug) => {
|
|
|
188
222
|
.replace(/^-+|-+$/g, '');
|
|
189
223
|
return `${prefix}-${normalized || 'agent'}`;
|
|
190
224
|
};
|
|
225
|
+
const toManagedWorkerLocalSlug = (prefix, agent) => {
|
|
226
|
+
const base = agent.slug.startsWith('worker_') ? agent.slug.slice('worker_'.length) : agent.slug;
|
|
227
|
+
return toManagedLocalSlug(prefix, base);
|
|
228
|
+
};
|
|
191
229
|
const toHealthStatus = (value) => {
|
|
192
230
|
const normalized = value?.trim().toLowerCase();
|
|
193
231
|
if (!normalized)
|
|
@@ -196,16 +234,21 @@ const toHealthStatus = (value) => {
|
|
|
196
234
|
return 'healthy';
|
|
197
235
|
if (normalized === 'degraded' ||
|
|
198
236
|
normalized === 'unknown' ||
|
|
199
|
-
normalized === 'limited'
|
|
237
|
+
normalized === 'limited' ||
|
|
238
|
+
normalized === 'stale' ||
|
|
239
|
+
normalized === 'misconfigured')
|
|
200
240
|
return 'degraded';
|
|
201
|
-
if (normalized === 'unreachable' ||
|
|
241
|
+
if (normalized === 'unreachable' ||
|
|
242
|
+
normalized === 'offline' ||
|
|
243
|
+
normalized === 'disabled')
|
|
202
244
|
return 'unreachable';
|
|
203
245
|
return undefined;
|
|
204
246
|
};
|
|
205
247
|
const isSyncManagedHealth = (health) => isRecord(health?.details) &&
|
|
206
248
|
(health.details.source === 'mswarm' ||
|
|
207
249
|
health.details.source === 'mswarm_catalog' ||
|
|
208
|
-
health.details.source === 'mswarm_self_hosted'
|
|
250
|
+
health.details.source === 'mswarm_self_hosted' ||
|
|
251
|
+
health.details.source === 'mswarm_worker');
|
|
209
252
|
const isAuthMissingManagedHealth = (health) => {
|
|
210
253
|
if (!isRecord(health?.details))
|
|
211
254
|
return false;
|
|
@@ -230,7 +273,16 @@ const isManagedMswarmSelfHostedConfig = (config) => {
|
|
|
230
273
|
return false;
|
|
231
274
|
return config.mswarmSelfHosted.managed === true;
|
|
232
275
|
};
|
|
233
|
-
const
|
|
276
|
+
const isManagedMswarmWorkerConfig = (config) => {
|
|
277
|
+
if (!isRecord(config))
|
|
278
|
+
return false;
|
|
279
|
+
if (!isRecord(config.mswarmWorker))
|
|
280
|
+
return false;
|
|
281
|
+
return config.mswarmWorker.managed === true;
|
|
282
|
+
};
|
|
283
|
+
const isManagedMswarmConfig = (config) => isManagedMswarmCloudConfig(config) ||
|
|
284
|
+
isManagedMswarmSelfHostedConfig(config) ||
|
|
285
|
+
isManagedMswarmWorkerConfig(config);
|
|
234
286
|
const toManagedConfig = (existingConfig, catalogBaseUrl, openAiBaseUrl, agent, syncedAt) => {
|
|
235
287
|
const nextConfig = {
|
|
236
288
|
...(existingConfig ?? {}),
|
|
@@ -281,6 +333,32 @@ const toManagedSelfHostedConfig = (existingConfig, catalogBaseUrl, openAiBaseUrl
|
|
|
281
333
|
};
|
|
282
334
|
return nextConfig;
|
|
283
335
|
};
|
|
336
|
+
const toManagedWorkerConfig = (existingConfig, catalogBaseUrl, agent, syncedAt) => {
|
|
337
|
+
const sync = isRecord(agent.sync) ? agent.sync : {};
|
|
338
|
+
const worker = isRecord(agent.worker) ? agent.worker : {};
|
|
339
|
+
const workerId = agent.id ?? agent.slug;
|
|
340
|
+
const apiRunUrl = resolveString(worker.api_run_url);
|
|
341
|
+
const nextConfig = {
|
|
342
|
+
...(existingConfig ?? {}),
|
|
343
|
+
baseUrl: catalogBaseUrl,
|
|
344
|
+
apiBaseUrl: catalogBaseUrl,
|
|
345
|
+
mswarmWorker: {
|
|
346
|
+
managed: true,
|
|
347
|
+
remoteSlug: agent.remote_slug ?? agent.slug,
|
|
348
|
+
workerId,
|
|
349
|
+
provider: agent.provider,
|
|
350
|
+
modelId: agent.model_id,
|
|
351
|
+
displayName: agent.display_name,
|
|
352
|
+
description: agent.description,
|
|
353
|
+
catalogBaseUrl,
|
|
354
|
+
apiRunUrl,
|
|
355
|
+
worker: Object.keys(worker).length > 0 ? worker : undefined,
|
|
356
|
+
sync: Object.keys(sync).length > 0 ? sync : undefined,
|
|
357
|
+
syncedAt,
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
return nextConfig;
|
|
361
|
+
};
|
|
284
362
|
const toManagedSyncRecord = (config, localSlug, defaultModel, action) => ({
|
|
285
363
|
remoteSlug: config.mswarmCloud.remoteSlug,
|
|
286
364
|
localSlug,
|
|
@@ -296,6 +374,13 @@ const toManagedSelfHostedSyncRecord = (config, localSlug, defaultModel, action)
|
|
|
296
374
|
provider: config.mswarmSelfHosted.provider,
|
|
297
375
|
defaultModel,
|
|
298
376
|
});
|
|
377
|
+
const toManagedWorkerSyncRecord = (config, localSlug, defaultModel, action) => ({
|
|
378
|
+
remoteSlug: config.mswarmWorker.remoteSlug,
|
|
379
|
+
localSlug,
|
|
380
|
+
action,
|
|
381
|
+
provider: config.mswarmWorker.provider,
|
|
382
|
+
defaultModel,
|
|
383
|
+
});
|
|
299
384
|
const toCloudAgent = (value) => {
|
|
300
385
|
if (!isRecord(value)) {
|
|
301
386
|
throw new Error('mswarm returned an invalid cloud-agent payload');
|
|
@@ -371,6 +456,31 @@ const toSelfHostedAgentDetail = (value) => {
|
|
|
371
456
|
mcoda_shape: isRecord(record.mcoda_shape) ? record.mcoda_shape : undefined,
|
|
372
457
|
};
|
|
373
458
|
};
|
|
459
|
+
const toWorkerAgent = (value) => {
|
|
460
|
+
const agent = toCloudAgent(value);
|
|
461
|
+
const record = isRecord(value) ? value : {};
|
|
462
|
+
return {
|
|
463
|
+
...agent,
|
|
464
|
+
id: resolveString(record.id),
|
|
465
|
+
remote_slug: resolveString(record.remote_slug),
|
|
466
|
+
updated_at: resolveTimestamp(record.updated_at),
|
|
467
|
+
adapter: resolveString(record.adapter),
|
|
468
|
+
source: resolveString(record.source),
|
|
469
|
+
worker: isRecord(record.worker) ? record.worker : undefined,
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
const toWorkerAgentDetail = (value) => {
|
|
473
|
+
const agent = toWorkerAgent(value);
|
|
474
|
+
const record = isRecord(value) ? value : {};
|
|
475
|
+
return {
|
|
476
|
+
...agent,
|
|
477
|
+
pricing: isRecord(record.pricing) ? record.pricing : undefined,
|
|
478
|
+
supported_parameters: resolveStringArray(record.supported_parameters),
|
|
479
|
+
status: resolveString(record.status),
|
|
480
|
+
moderation_status: resolveString(record.moderation_status),
|
|
481
|
+
mcoda_shape: isRecord(record.mcoda_shape) ? record.mcoda_shape : undefined,
|
|
482
|
+
};
|
|
483
|
+
};
|
|
374
484
|
const hasAdvancedCloudAgentSelection = (options) => options.maxCostPerMillion !== undefined ||
|
|
375
485
|
options.minContextWindow !== undefined ||
|
|
376
486
|
options.minReasoningRating !== undefined ||
|
|
@@ -428,6 +538,7 @@ export class MswarmApi {
|
|
|
428
538
|
this.baseUrl = options.baseUrl;
|
|
429
539
|
this.agentSlugPrefix = options.agentSlugPrefix;
|
|
430
540
|
this.selfHostedAgentSlugPrefix = options.selfHostedAgentSlugPrefix;
|
|
541
|
+
this.workerAgentSlugPrefix = options.workerAgentSlugPrefix;
|
|
431
542
|
}
|
|
432
543
|
static async create(options = {}) {
|
|
433
544
|
const repo = await GlobalRepository.create();
|
|
@@ -461,6 +572,21 @@ export class MswarmApi {
|
|
|
461
572
|
async refreshManagedAgentAuth() {
|
|
462
573
|
return MswarmApi.refreshManagedAgentAuth(this.requireApiKey());
|
|
463
574
|
}
|
|
575
|
+
async getRuntimeUsageLimits() {
|
|
576
|
+
const payload = await this.requestJson('/v1/swarm/runtime/usage-limits');
|
|
577
|
+
return toRuntimeUsageLimits(payload);
|
|
578
|
+
}
|
|
579
|
+
async getRuntimeIdentity() {
|
|
580
|
+
const usageLimits = await this.getRuntimeUsageLimits();
|
|
581
|
+
return {
|
|
582
|
+
tenantId: usageLimits.tenant_id,
|
|
583
|
+
productSlug: usageLimits.product_slug,
|
|
584
|
+
apiKeyId: usageLimits.api_key_id,
|
|
585
|
+
subscriptionId: usageLimits.subscription_id,
|
|
586
|
+
asOf: usageLimits.as_of,
|
|
587
|
+
usageLimits,
|
|
588
|
+
};
|
|
589
|
+
}
|
|
464
590
|
requireApiKey() {
|
|
465
591
|
if (!this.options.apiKey) {
|
|
466
592
|
throw new Error('MCODA_MSWARM_API_KEY is required');
|
|
@@ -560,6 +686,78 @@ export class MswarmApi {
|
|
|
560
686
|
const payload = await this.requestJson(`/v1/swarm/self-hosted/agents/${encodeURIComponent(slug)}`);
|
|
561
687
|
return toSelfHostedAgentDetail(payload);
|
|
562
688
|
}
|
|
689
|
+
async listWorkerAgentPage(options = {}) {
|
|
690
|
+
const query = {
|
|
691
|
+
shape: 'mcoda',
|
|
692
|
+
limit: options.limit,
|
|
693
|
+
cursor: options.cursor,
|
|
694
|
+
updated_after: options.updatedAfter,
|
|
695
|
+
};
|
|
696
|
+
if (options.includeDisabled !== undefined) {
|
|
697
|
+
query.include_disabled = options.includeDisabled ? 'true' : 'false';
|
|
698
|
+
}
|
|
699
|
+
const payload = await this.requestJson('/v1/swarm/workers', query);
|
|
700
|
+
const values = Array.isArray(payload.agents)
|
|
701
|
+
? payload.agents
|
|
702
|
+
: Array.isArray(payload.workers)
|
|
703
|
+
? payload.workers
|
|
704
|
+
: [];
|
|
705
|
+
return {
|
|
706
|
+
workers: values.map(toWorkerAgent),
|
|
707
|
+
next_cursor: resolveString(payload.next_cursor) ?? null,
|
|
708
|
+
generated_at: resolveTimestamp(payload.generated_at),
|
|
709
|
+
total: resolveNumber(payload.total),
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
async listAllWorkers(options = {}) {
|
|
713
|
+
const requestedLimit = normalizeOptionalPositiveInt(options.limit, 'limit');
|
|
714
|
+
const pageLimit = requestedLimit !== undefined ? Math.min(requestedLimit, 250) : 250;
|
|
715
|
+
const collected = [];
|
|
716
|
+
let cursor;
|
|
717
|
+
do {
|
|
718
|
+
const page = await this.listWorkerAgentPage({
|
|
719
|
+
...options,
|
|
720
|
+
limit: pageLimit,
|
|
721
|
+
cursor,
|
|
722
|
+
});
|
|
723
|
+
collected.push(...page.workers);
|
|
724
|
+
cursor = page.next_cursor ?? undefined;
|
|
725
|
+
if (requestedLimit !== undefined && collected.length >= requestedLimit) {
|
|
726
|
+
return applyCloudAgentListOptions(collected.slice(0, requestedLimit), options);
|
|
727
|
+
}
|
|
728
|
+
} while (cursor);
|
|
729
|
+
return applyCloudAgentListOptions(collected, options);
|
|
730
|
+
}
|
|
731
|
+
async listWorkers(options = {}) {
|
|
732
|
+
const page = await this.listWorkerAgentPage(options);
|
|
733
|
+
let agents = page.workers;
|
|
734
|
+
if (options.provider) {
|
|
735
|
+
agents = agents.filter((agent) => agent.provider === options.provider);
|
|
736
|
+
}
|
|
737
|
+
return {
|
|
738
|
+
...page,
|
|
739
|
+
workers: applyCloudAgentListOptions(agents, options),
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
async getWorker(slug) {
|
|
743
|
+
if (!slug.trim()) {
|
|
744
|
+
throw new Error('Worker slug is required');
|
|
745
|
+
}
|
|
746
|
+
const payload = await this.requestJson(`/v1/swarm/workers/${encodeURIComponent(slug)}`);
|
|
747
|
+
return toWorkerAgentDetail(payload);
|
|
748
|
+
}
|
|
749
|
+
async runWorker(slug, payload, options = {}) {
|
|
750
|
+
if (!slug.trim()) {
|
|
751
|
+
throw new Error('Worker slug is required');
|
|
752
|
+
}
|
|
753
|
+
return this.requestJson(`/v1/swarm/workers/${encodeURIComponent(slug)}/run`, undefined, {
|
|
754
|
+
method: 'POST',
|
|
755
|
+
body: payload ?? {},
|
|
756
|
+
headers: options.idempotencyKey
|
|
757
|
+
? { 'idempotency-key': options.idempotencyKey }
|
|
758
|
+
: undefined,
|
|
759
|
+
});
|
|
760
|
+
}
|
|
563
761
|
async syncCloudAgents(options = {}) {
|
|
564
762
|
if (options.pruneMissing &&
|
|
565
763
|
(options.limit !== undefined || hasAdvancedCloudAgentSelection(options))) {
|
|
@@ -721,6 +919,92 @@ export class MswarmApi {
|
|
|
721
919
|
agents: records,
|
|
722
920
|
};
|
|
723
921
|
}
|
|
922
|
+
async syncWorkers(options = {}) {
|
|
923
|
+
if (options.pruneMissing &&
|
|
924
|
+
(options.limit !== undefined ||
|
|
925
|
+
options.cursor !== undefined ||
|
|
926
|
+
options.updatedAfter !== undefined ||
|
|
927
|
+
options.includeDisabled === false ||
|
|
928
|
+
hasAdvancedCloudAgentSelection(options))) {
|
|
929
|
+
throw new Error('pruneMissing cannot be combined with partial worker catalog filters');
|
|
930
|
+
}
|
|
931
|
+
const agents = await this.listAllWorkers(options);
|
|
932
|
+
const syncedAt = new Date().toISOString();
|
|
933
|
+
const encryptedApiKey = await CryptoHelper.encryptSecret(this.requireApiKey());
|
|
934
|
+
const records = [];
|
|
935
|
+
for (const agent of agents) {
|
|
936
|
+
const localSlug = toManagedWorkerLocalSlug(this.options.workerAgentSlugPrefix, agent);
|
|
937
|
+
const existing = await this.repo.getAgentBySlug(localSlug);
|
|
938
|
+
const remoteSlug = agent.remote_slug ?? agent.slug;
|
|
939
|
+
if (existing &&
|
|
940
|
+
(!isManagedMswarmWorkerConfig(existing.config) ||
|
|
941
|
+
existing.config.mswarmWorker.remoteSlug !== remoteSlug)) {
|
|
942
|
+
throw new Error(`Refusing to overwrite non-mswarm agent ${localSlug}`);
|
|
943
|
+
}
|
|
944
|
+
const existingConfig = existing && isRecord(existing.config)
|
|
945
|
+
? existing.config
|
|
946
|
+
: undefined;
|
|
947
|
+
const nextConfig = toManagedWorkerConfig(existingConfig, this.options.baseUrl, agent, syncedAt);
|
|
948
|
+
const createInput = {
|
|
949
|
+
...toSyncedAgentInput(existing, agent, localSlug, nextConfig, syncedAt),
|
|
950
|
+
adapter: 'mswarm-worker',
|
|
951
|
+
openaiCompatible: false,
|
|
952
|
+
};
|
|
953
|
+
const { slug: _ignoredSlug, ...updateInput } = createInput;
|
|
954
|
+
const stored = existing
|
|
955
|
+
? await this.repo.updateAgent(existing.id, updateInput)
|
|
956
|
+
: await this.repo.createAgent(createInput);
|
|
957
|
+
if (!stored) {
|
|
958
|
+
throw new Error(`Failed to persist synced worker ${localSlug}`);
|
|
959
|
+
}
|
|
960
|
+
await this.repo.setAgentModels(stored.id, toAgentModels(stored.id, agent));
|
|
961
|
+
await this.repo.setAgentAuth(stored.id, encryptedApiKey);
|
|
962
|
+
const existingHealth = existing
|
|
963
|
+
? await this.repo.getAgentHealth(existing.id)
|
|
964
|
+
: undefined;
|
|
965
|
+
const mappedHealth = toHealthStatus(agent.health_status);
|
|
966
|
+
if (mappedHealth && shouldReplaceManagedHealth(existingHealth)) {
|
|
967
|
+
const health = {
|
|
968
|
+
agentId: stored.id,
|
|
969
|
+
status: mappedHealth,
|
|
970
|
+
lastCheckedAt: syncedAt,
|
|
971
|
+
details: {
|
|
972
|
+
source: 'mswarm_worker',
|
|
973
|
+
remoteSlug,
|
|
974
|
+
workerId: agent.id ?? agent.slug,
|
|
975
|
+
remoteHealthStatus: agent.health_status,
|
|
976
|
+
},
|
|
977
|
+
};
|
|
978
|
+
await this.repo.setAgentHealth(health);
|
|
979
|
+
}
|
|
980
|
+
records.push(toManagedWorkerSyncRecord(nextConfig, localSlug, agent.default_model, existing ? 'updated' : 'created'));
|
|
981
|
+
}
|
|
982
|
+
if (options.pruneMissing) {
|
|
983
|
+
const remoteSlugs = new Set(agents.map((agent) => agent.remote_slug ?? agent.slug));
|
|
984
|
+
const localAgents = await this.repo.listAgents();
|
|
985
|
+
for (const localAgent of localAgents) {
|
|
986
|
+
const managedConfig = isManagedMswarmWorkerConfig(localAgent.config)
|
|
987
|
+
? localAgent.config
|
|
988
|
+
: undefined;
|
|
989
|
+
if (!managedConfig)
|
|
990
|
+
continue;
|
|
991
|
+
if (options.provider &&
|
|
992
|
+
managedConfig.mswarmWorker.provider !== options.provider) {
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (remoteSlugs.has(managedConfig.mswarmWorker.remoteSlug))
|
|
996
|
+
continue;
|
|
997
|
+
await this.repo.deleteAgent(localAgent.id);
|
|
998
|
+
records.push(toManagedWorkerSyncRecord(managedConfig, localAgent.slug, localAgent.defaultModel ?? managedConfig.mswarmWorker.modelId ?? '-', 'deleted'));
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return {
|
|
1002
|
+
created: records.filter((record) => record.action === 'created').length,
|
|
1003
|
+
updated: records.filter((record) => record.action === 'updated').length,
|
|
1004
|
+
deleted: records.filter((record) => record.action === 'deleted').length,
|
|
1005
|
+
agents: records,
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
724
1008
|
async issuePaidConsent(policyVersion = MSWARM_CONSENT_POLICY_VERSION) {
|
|
725
1009
|
const apiKey = this.requireApiKey();
|
|
726
1010
|
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.72",
|
|
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/
|
|
37
|
-
"@mcoda/
|
|
38
|
-
"@mcoda/generators": "0.1.
|
|
39
|
-
"@mcoda/
|
|
35
|
+
"@mcoda/shared": "0.1.72",
|
|
36
|
+
"@mcoda/agents": "0.1.72",
|
|
37
|
+
"@mcoda/integrations": "0.1.72",
|
|
38
|
+
"@mcoda/generators": "0.1.72",
|
|
39
|
+
"@mcoda/db": "0.1.72"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsc -p tsconfig.json",
|