@metorial/sdk 1.2.0 → 2.0.1

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/index.js CHANGED
@@ -1,439 +1,189 @@
1
- import { createMetorialCoreSDK } from '@metorial/core';
2
- import { MetorialMcpSession } from '@metorial/mcp-session';
3
- import { metorialOpenAI } from '@metorial/openai';
4
- import { metorialAnthropic } from '@metorial/anthropic';
5
- import { metorialDeepseek } from '@metorial/deepseek';
6
- import { metorialGoogle } from '@metorial/google';
7
- import { metorialMistral } from '@metorial/mistral';
8
- import { metorialXai } from '@metorial/xai';
9
- import { metorialTogetherAi } from '@metorial/togetherai';
1
+ import { createMetorialPulsarCoreSDK, createMetorialMagnetarCoreSDK } from '@metorial/core';
2
+ import { MetorialMcpSession, MetorialMagnetarMcpSession } from '@metorial/mcp-session';
10
3
 
11
4
  // src/metorial.ts
12
- var runWithOpenAI = async (config) => {
13
- let {
14
- message,
15
- serverDeployments,
16
- client,
17
- model,
18
- maxSteps = 25,
19
- tools: requestedTools,
20
- withProviderSession,
21
- ...openaiOptions
22
- } = config;
23
- return withProviderSession(
24
- metorialOpenAI.chatCompletions,
25
- {
26
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
27
- },
28
- async (session) => {
29
- let tools = requestedTools ? session.tools.filter((t) => requestedTools.includes(t.name)) : session.tools;
30
- let messages = [
31
- { role: "user", content: message }
32
- ];
33
- for (let step = 0; step < maxSteps; step++) {
34
- let response = await client.chat.completions.create({
35
- model,
36
- messages,
37
- tools,
38
- ...openaiOptions
39
- });
40
- let choice = response.choices[0];
41
- if (!choice.message.tool_calls) {
42
- return {
43
- text: choice.message.content || "",
44
- steps: step + 1
45
- };
46
- }
47
- let toolResponses = await session.callTools(choice.message.tool_calls);
48
- messages.push(
49
- { role: "assistant", tool_calls: choice.message.tool_calls },
50
- ...toolResponses
51
- );
52
- }
53
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
54
- }
55
- );
56
- };
57
- var runWithAnthropic = async (config) => {
58
- let {
59
- message,
60
- serverDeployments,
61
- client,
62
- model,
63
- maxSteps = 25,
64
- tools: requestedTools,
65
- withProviderSession,
66
- max_tokens = 4096,
67
- ...anthropicOptions
68
- } = config;
69
- return withProviderSession(
70
- metorialAnthropic,
71
- {
72
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
73
- },
74
- async (session) => {
75
- let tools = requestedTools ? session.tools.filter((t) => requestedTools.includes(t.name)) : session.tools;
76
- let messages = [
77
- { role: "user", content: message }
78
- ];
79
- let uniqueTools = Array.from(new Map(tools.map((t) => [t.name, t])).values());
80
- for (let step = 0; step < maxSteps; step++) {
81
- let response = await client.messages.create({
82
- model,
83
- max_tokens,
84
- messages,
85
- tools: uniqueTools,
86
- ...anthropicOptions
87
- });
88
- if (response.stop_reason !== "tool_use") {
89
- let textContent = response.content.find(
90
- (block) => block.type === "text"
91
- );
92
- return {
93
- text: (textContent == null ? void 0 : textContent.text) || "",
94
- steps: step + 1
95
- };
96
- }
97
- let toolUseBlocks = response.content.filter(
98
- (block) => block.type === "tool_use"
99
- );
100
- let toolResponse = await session.callTools(toolUseBlocks);
101
- let toolResponseMessage = {
102
- role: "user",
103
- content: toolResponse.content.map((block) => ({
104
- type: "tool_result",
105
- tool_use_id: block.tool_use_id,
106
- content: block.content
107
- }))
108
- };
109
- messages.push(
110
- { role: "assistant", content: response.content },
111
- toolResponseMessage
112
- );
113
- }
114
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
115
- }
116
- );
117
- };
118
- var runWithDeepSeek = async (config) => {
119
- let {
120
- message,
121
- serverDeployments,
122
- client,
123
- model,
124
- maxSteps = 25,
125
- tools: requestedTools,
126
- withProviderSession,
127
- ...deepseekOptions
128
- } = config;
129
- return withProviderSession(
130
- metorialDeepseek,
131
- {
132
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
133
- },
134
- async (session) => {
135
- let tools = requestedTools ? session.tools.filter((t) => {
136
- var _a;
137
- return requestedTools.includes(((_a = t.function) == null ? void 0 : _a.name) || t.name);
138
- }) : session.tools;
139
- let uniqueTools = Array.from(
140
- new Map(tools.map((t) => {
141
- var _a;
142
- return [((_a = t.function) == null ? void 0 : _a.name) || t.name, t];
143
- })).values()
144
- );
145
- let messages = [
146
- { role: "user", content: message }
147
- ];
148
- for (let step = 0; step < maxSteps; step++) {
149
- let response = await client.chat.completions.create({
150
- model,
151
- messages,
152
- tools: uniqueTools,
153
- ...deepseekOptions
154
- });
155
- let choice = response.choices[0];
156
- if (!choice.message.tool_calls || choice.message.tool_calls.length === 0) {
157
- return {
158
- text: choice.message.content || "",
159
- steps: step + 1
160
- };
161
- }
162
- let toolResponses = await session.callTools(choice.message.tool_calls);
163
- messages.push(
164
- { role: "assistant", tool_calls: choice.message.tool_calls },
165
- ...toolResponses
166
- );
167
- }
168
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
169
- }
170
- );
171
- };
172
- var runWithGoogle = async (config) => {
173
- let {
174
- message,
175
- serverDeployments,
176
- client,
177
- model,
178
- maxSteps = 25,
179
- tools: requestedTools,
180
- withProviderSession,
181
- ...googleOptions
182
- } = config;
183
- return withProviderSession(
184
- metorialGoogle,
185
- {
186
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
187
- },
188
- async (session) => {
189
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
190
- let tools = requestedTools ? session.tools.filter((t) => requestedTools.includes(t.name)) : session.tools;
191
- let response = await client.models.generateContent({
192
- model,
193
- contents: [
194
- {
195
- role: "user",
196
- parts: [{ text: message }]
197
- }
198
- ],
199
- config: {
200
- tools,
201
- ...googleOptions
202
- }
203
- });
204
- let text = (_e = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0]) == null ? void 0 : _e.text;
205
- let functionCalls = (_i = (_h = (_g = (_f = response.candidates) == null ? void 0 : _f[0]) == null ? void 0 : _g.content) == null ? void 0 : _h.parts) == null ? void 0 : _i.filter((part) => part.functionCall).map((part) => part.functionCall);
206
- if (functionCalls && functionCalls.length > 0) {
207
- let toolResponses = await session.callTools(functionCalls);
208
- return {
209
- text: text || "",
210
- toolResponses,
211
- steps: 1
212
- };
213
- }
214
- return {
215
- text: text || "",
216
- steps: 1
217
- };
5
+ var Metorial = class {
6
+ constructor(init) {
7
+ let apiHost = init.apiHost;
8
+ let mcpHost = init.mcpHost;
9
+ if (mcpHost && !apiHost) {
10
+ apiHost = mcpHost.replace("://connect.", "://api.");
218
11
  }
219
- );
220
- };
221
- var extractTextFromContent = (content) => {
222
- if (typeof content === "string") {
223
- return content;
12
+ this.pulsarSdk = createMetorialPulsarCoreSDK({ ...init, apiHost });
13
+ this.magnetarSdk = createMetorialMagnetarCoreSDK({ ...init, apiHost, mcpHost });
224
14
  }
225
- if (Array.isArray(content)) {
226
- return content.filter((chunk) => chunk && typeof chunk === "object").map((chunk) => chunk.text || chunk.content || JSON.stringify(chunk)).join("");
15
+ // ── Magnetar (default) ───────────────────────────────────────────
16
+ get providers() {
17
+ return this.magnetarSdk.providers;
227
18
  }
228
- return "";
229
- };
230
- var runWithMistral = async (config) => {
231
- let {
232
- message,
233
- serverDeployments,
234
- client,
235
- model,
236
- maxSteps = 25,
237
- tools: requestedTools,
238
- withProviderSession,
239
- ...mistralOptions
240
- } = config;
241
- return withProviderSession(
242
- metorialMistral,
243
- {
244
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
245
- },
246
- async (session) => {
247
- let tools = requestedTools ? session.tools.filter((t) => {
248
- var _a;
249
- return requestedTools.includes(((_a = t.function) == null ? void 0 : _a.name) || t.name);
250
- }) : session.tools;
251
- let fixedTools = tools.map((tool) => {
252
- var _a;
253
- if ((_a = tool.function) == null ? void 0 : _a.parameters) {
254
- let fixedParams = { ...tool.function.parameters };
255
- fixedParams.additionalProperties = false;
256
- if (fixedParams.properties) {
257
- Object.values(fixedParams.properties).forEach((prop) => {
258
- if (prop && typeof prop === "object" && prop.type === "object") {
259
- prop.additionalProperties = false;
260
- }
261
- });
262
- }
263
- return {
264
- ...tool,
265
- function: {
266
- ...tool.function,
267
- parameters: fixedParams
268
- }
269
- };
270
- }
271
- return tool;
272
- });
273
- let messages = [
274
- { role: "user", content: message }
275
- ];
276
- for (let step = 0; step < maxSteps; step++) {
277
- let response = await client.chat.complete({
278
- model,
279
- messages,
280
- tools: fixedTools,
281
- ...mistralOptions
282
- });
283
- let choice = response.choices[0];
284
- let toolCalls = choice.message.toolCalls;
285
- if (!toolCalls || toolCalls.length === 0) {
286
- return {
287
- text: extractTextFromContent(choice.message.content),
288
- steps: step + 1
289
- };
290
- }
291
- let toolResponses = await session.callTools(toolCalls);
292
- messages.push(
293
- { role: "assistant", toolCalls },
294
- ...toolResponses
295
- );
296
- }
297
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
298
- }
299
- );
300
- };
301
- var runWithXAI = async (config) => {
302
- let {
303
- message,
304
- serverDeployments,
305
- client,
306
- model,
307
- maxSteps = 25,
308
- tools: requestedTools,
309
- withProviderSession,
310
- ...xaiOptions
311
- } = config;
312
- return withProviderSession(
313
- metorialXai,
314
- {
315
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
316
- },
317
- async (session) => {
318
- let tools = requestedTools ? session.tools.filter((t) => {
319
- var _a;
320
- return requestedTools.includes(((_a = t.function) == null ? void 0 : _a.name) || t.name);
321
- }) : session.tools;
322
- let uniqueTools = Array.from(
323
- new Map(tools.map((t) => [t.function.name, t])).values()
324
- );
325
- let messages = [
326
- { role: "user", content: message }
327
- ];
328
- for (let step = 0; step < maxSteps; step++) {
329
- let response = await client.chat.completions.create({
330
- model,
331
- messages,
332
- tools: uniqueTools,
333
- ...xaiOptions
334
- });
335
- let choice = response.choices[0];
336
- if (!choice.message.tool_calls || choice.message.tool_calls.length === 0) {
337
- return {
338
- text: choice.message.content || "",
339
- steps: step + 1
340
- };
341
- }
342
- let toolResponses = await session.callTools(choice.message.tool_calls);
343
- messages.push(
344
- { role: "assistant", tool_calls: choice.message.tool_calls },
345
- ...toolResponses
346
- );
347
- }
348
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
349
- }
350
- );
351
- };
352
- var runWithTogetherAI = async (config) => {
353
- let {
354
- message,
355
- serverDeployments,
356
- client,
357
- model,
358
- maxSteps = 25,
359
- tools: requestedTools,
360
- withProviderSession,
361
- ...togetheraiOptions
362
- } = config;
363
- return withProviderSession(
364
- metorialTogetherAi,
365
- {
366
- serverDeployments: Array.isArray(serverDeployments) ? serverDeployments : [serverDeployments]
367
- },
368
- async (session) => {
369
- let tools = requestedTools ? session.tools.filter((t) => {
370
- var _a;
371
- return requestedTools.includes(((_a = t.function) == null ? void 0 : _a.name) || t.name);
372
- }) : session.tools;
373
- let messages = [
374
- { role: "user", content: message }
375
- ];
376
- for (let step = 0; step < maxSteps; step++) {
377
- let response = await client.chat.completions.create({
378
- model,
379
- messages,
380
- tools,
381
- ...togetheraiOptions
382
- });
383
- let choice = response.choices[0];
384
- if (!choice.message.tool_calls || choice.message.tool_calls.length === 0) {
385
- return {
386
- text: choice.message.content || "",
387
- steps: step + 1
388
- };
389
- }
390
- let toolResponses = await session.callTools(choice.message.tool_calls);
391
- messages.push(
392
- { role: "assistant", tool_calls: choice.message.tool_calls },
393
- ...toolResponses
394
- );
395
- }
396
- throw new Error(`Max steps (${maxSteps}) reached without final response`);
397
- }
398
- );
399
- };
400
-
401
- // src/metorial.ts
402
- var Metorial = class {
403
- constructor(init) {
404
- this.sdk = createMetorialCoreSDK(init);
19
+ get providerDeployments() {
20
+ let deployments = this.magnetarSdk.providerDeployments;
21
+ Object.assign(deployments.setupSessions, {
22
+ waitForCompletion: this.waitForSetupSession.bind(this)
23
+ });
24
+ return deployments;
25
+ }
26
+ get sessions() {
27
+ return this.magnetarSdk.sessions;
28
+ }
29
+ get sessionTemplates() {
30
+ return this.magnetarSdk.sessionTemplates;
31
+ }
32
+ get providerRuns() {
33
+ return this.magnetarSdk.providerRuns;
405
34
  }
406
35
  get instance() {
407
- return this.sdk.instance;
36
+ return this.magnetarSdk.instance;
408
37
  }
409
- get secrets() {
410
- return this.sdk.secrets;
38
+ get publishers() {
39
+ return this.magnetarSdk.publishers;
40
+ }
41
+ get providerCategories() {
42
+ return this.magnetarSdk.providerCategories;
43
+ }
44
+ get providerCollections() {
45
+ return this.magnetarSdk.providerCollections;
46
+ }
47
+ get providerGroups() {
48
+ return this.magnetarSdk.providerGroups;
411
49
  }
50
+ get providerListings() {
51
+ return this.magnetarSdk.providerListings;
52
+ }
53
+ get providerSetupSessions() {
54
+ return this.magnetarSdk.providerSetupSessions;
55
+ }
56
+ get toolCalls() {
57
+ return this.magnetarSdk.toolCalls;
58
+ }
59
+ get customProviders() {
60
+ return this.magnetarSdk.customProviders;
61
+ }
62
+ // ── Backward compat (Pulsar endpoints at top level) ──────────────
412
63
  get servers() {
413
- return this.sdk.servers;
64
+ return this.pulsarSdk.servers;
414
65
  }
415
- get sessions() {
416
- return this.sdk.sessions;
66
+ get secrets() {
67
+ return this.pulsarSdk.secrets;
417
68
  }
418
69
  get oauth() {
419
70
  return {
420
- ...this.sdk.oauth,
71
+ ...this.pulsarSdk.oauth,
421
72
  waitForCompletion: this.waitForOAuthCompletion.bind(this)
422
73
  };
423
74
  }
424
75
  get _config() {
425
- return this.sdk._config;
76
+ return this.pulsarSdk._config;
77
+ }
78
+ // ── v1 namespace (legacy Pulsar) ─────────────────────────────────
79
+ get v1() {
80
+ let pulsarSdk = this.pulsarSdk;
81
+ let self = this;
82
+ return {
83
+ get instance() {
84
+ return pulsarSdk.instance;
85
+ },
86
+ get secrets() {
87
+ return pulsarSdk.secrets;
88
+ },
89
+ get servers() {
90
+ return pulsarSdk.servers;
91
+ },
92
+ get sessions() {
93
+ return pulsarSdk.sessions;
94
+ },
95
+ get oauth() {
96
+ return self.oauth;
97
+ },
98
+ get _config() {
99
+ return pulsarSdk._config;
100
+ },
101
+ mcp: {
102
+ createSession: (init) => new MetorialMcpSession(pulsarSdk, init),
103
+ withSession: self._pulsarWithSession.bind(self),
104
+ withProviderSession: self._pulsarWithProviderSession.bind(self),
105
+ createConnection: self._pulsarCreateMcpConnection.bind(self)
106
+ },
107
+ withSession: self._pulsarWithSession.bind(self),
108
+ withProviderSession: self._pulsarWithProviderSession.bind(self),
109
+ createMcpConnection: self._pulsarCreateMcpConnection.bind(self)
110
+ };
426
111
  }
112
+ // ── MCP (Magnetar default) ───────────────────────────────────────
427
113
  get mcp() {
428
114
  return {
429
- createSession: (init) => new MetorialMcpSession(this.sdk, init),
115
+ createSession: (init) => new MetorialMagnetarMcpSession(this.magnetarSdk, init),
430
116
  withSession: this.withSession.bind(this),
431
117
  withProviderSession: this.withProviderSession.bind(this),
432
118
  createConnection: this.createMcpConnection.bind(this)
433
119
  };
434
120
  }
121
+ session(init) {
122
+ return new MetorialMagnetarMcpSession(this.magnetarSdk, init);
123
+ }
435
124
  async createMcpConnection(init) {
436
- let session = new MetorialMcpSession(this.sdk, {
125
+ let session = new MetorialMagnetarMcpSession(this.magnetarSdk, init);
126
+ return await session.getClient();
127
+ }
128
+ async withSession(init, action) {
129
+ let session = new MetorialMagnetarMcpSession(this.magnetarSdk, init);
130
+ try {
131
+ return await action(session);
132
+ } finally {
133
+ await session.close();
134
+ }
135
+ }
136
+ async withProviderSession(provider, init, action) {
137
+ if (init.streaming) {
138
+ return this.withMagnetarStreamingSession(provider, init, action);
139
+ }
140
+ return this.withSession(init, async (session) => {
141
+ let providerData = await provider(session);
142
+ return action({
143
+ ...providerData,
144
+ session,
145
+ getSession: session.getSession.bind(session),
146
+ getCapabilities: session.getCapabilities.bind(session),
147
+ getToolManager: session.getToolManager.bind(session),
148
+ closeSession: async () => {
149
+ }
150
+ });
151
+ });
152
+ }
153
+ async withMagnetarStreamingSession(provider, init, action) {
154
+ let session = new MetorialMagnetarMcpSession(this.magnetarSdk, init);
155
+ let sessionClosed = false;
156
+ const closeSession = async () => {
157
+ if (!sessionClosed) {
158
+ sessionClosed = true;
159
+ await session.close();
160
+ }
161
+ };
162
+ try {
163
+ let providerData = await provider(session);
164
+ let result = await action({
165
+ ...providerData,
166
+ session,
167
+ getSession: session.getSession.bind(session),
168
+ getCapabilities: session.getCapabilities.bind(session),
169
+ getToolManager: session.getToolManager.bind(session),
170
+ closeSession
171
+ });
172
+ let timeout = setTimeout(async () => {
173
+ if (!sessionClosed) {
174
+ await closeSession();
175
+ }
176
+ }, 6e4);
177
+ timeout.unref();
178
+ return result;
179
+ } catch (error) {
180
+ await closeSession();
181
+ throw error;
182
+ }
183
+ }
184
+ // ── Pulsar MCP helpers (used by v1) ──────────────────────────────
185
+ async _pulsarCreateMcpConnection(init) {
186
+ let session = new MetorialMcpSession(this.pulsarSdk, {
437
187
  serverDeployments: [init]
438
188
  });
439
189
  let deployments = await session.getServerDeployments();
@@ -441,19 +191,19 @@ var Metorial = class {
441
191
  deploymentId: deployments[0].id
442
192
  });
443
193
  }
444
- async withSession(init, action) {
445
- let session = new MetorialMcpSession(this.sdk, init);
194
+ async _pulsarWithSession(init, action) {
195
+ let session = new MetorialMcpSession(this.pulsarSdk, init);
446
196
  try {
447
197
  return await action(session);
448
198
  } finally {
449
199
  await session.close();
450
200
  }
451
201
  }
452
- async withProviderSession(provider, init, action) {
202
+ async _pulsarWithProviderSession(provider, init, action) {
453
203
  if (init.streaming) {
454
204
  return this.withStreamingSession(provider, init, action);
455
205
  }
456
- return this.withSession(init, async (session) => {
206
+ return this._pulsarWithSession(init, async (session) => {
457
207
  let providerData = await provider(session);
458
208
  return action({
459
209
  ...providerData,
@@ -467,12 +217,11 @@ var Metorial = class {
467
217
  });
468
218
  }
469
219
  async withStreamingSession(provider, init, action) {
470
- let session = new MetorialMcpSession(this.sdk, init);
220
+ let session = new MetorialMcpSession(this.pulsarSdk, init);
471
221
  let sessionClosed = false;
472
222
  const closeSession = async () => {
473
223
  if (!sessionClosed) {
474
224
  sessionClosed = true;
475
- console.log("[Metorial] Closing streaming session");
476
225
  await session.close();
477
226
  }
478
227
  };
@@ -488,42 +237,51 @@ var Metorial = class {
488
237
  getToolManager: session.getToolManager.bind(session),
489
238
  closeSession
490
239
  });
491
- setTimeout(async () => {
240
+ let timeout = setTimeout(async () => {
492
241
  if (!sessionClosed) {
493
- console.log("[Metorial] Streaming timeout reached - auto-closing session");
494
242
  await closeSession();
495
243
  }
496
244
  }, 6e4);
245
+ timeout.unref();
497
246
  return result;
498
247
  } catch (error) {
499
248
  await closeSession();
500
249
  throw error;
501
250
  }
502
251
  }
503
- inferProvider(model) {
504
- let modelLower = model.toLowerCase();
505
- if (modelLower.startsWith("claude-")) {
506
- return "anthropic";
507
- }
508
- if (modelLower.startsWith("gpt-") || modelLower.startsWith("o1-")) {
509
- return "openai";
510
- }
511
- if (modelLower.includes("deepseek")) {
512
- return "deepseek";
513
- }
514
- if (modelLower.startsWith("gemini-") || modelLower.includes("google")) {
515
- return "google";
516
- }
517
- if (modelLower.startsWith("mistral-") || modelLower.includes("mistral")) {
518
- return "mistral";
519
- }
520
- if (modelLower.startsWith("x-") || modelLower === "grok-beta") {
521
- return "xai";
252
+ async waitForSetupSession(sessions, options) {
253
+ var _a, _b;
254
+ let sessionList = Array.isArray(sessions) ? sessions : [sessions];
255
+ let pollInterval = Math.max((_a = options == null ? void 0 : options.pollInterval) != null ? _a : 5e3, 2e3);
256
+ let timeout = (_b = options == null ? void 0 : options.timeout) != null ? _b : 6e5;
257
+ let startTime = Date.now();
258
+ if (sessionList.length === 0) {
259
+ return [];
522
260
  }
523
- if (modelLower.includes("together") || modelLower.includes("llama") || modelLower.includes("mixtral") || modelLower.includes("qwen") || modelLower.includes("/")) {
524
- return "togetherai";
261
+ while (true) {
262
+ if (Date.now() - startTime > timeout) {
263
+ throw new Error(`Setup session timed out after ${timeout / 1e3} seconds`);
264
+ }
265
+ try {
266
+ let statuses = await Promise.all(
267
+ sessionList.map((s) => this.magnetarSdk.providerDeployments.setupSessions.get(s.id))
268
+ );
269
+ let failed = statuses.filter((s) => s.status === "failed");
270
+ if (failed.length > 0) {
271
+ throw new Error(`${failed.length} setup session(s) failed`);
272
+ }
273
+ let allCompleted = statuses.every((s) => s.status === "completed");
274
+ if (allCompleted) {
275
+ return statuses;
276
+ }
277
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
278
+ } catch (error) {
279
+ if (error instanceof Error && (error.message.includes("setup session") && (error.message.includes("failed") || error.message.includes("timed out")))) {
280
+ throw error;
281
+ }
282
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
283
+ }
525
284
  }
526
- throw new Error(`Unable to infer provider from model "${model}".`);
527
285
  }
528
286
  async waitForOAuthCompletion(sessions, options) {
529
287
  var _a, _b;
@@ -560,55 +318,6 @@ var Metorial = class {
560
318
  }
561
319
  }
562
320
  }
563
- async run(config) {
564
- let provider = this.inferProvider(config.model);
565
- switch (provider) {
566
- case "openai":
567
- return runWithOpenAI({
568
- ...config,
569
- client: config.client,
570
- withProviderSession: this.withProviderSession.bind(this)
571
- });
572
- case "anthropic":
573
- return runWithAnthropic({
574
- ...config,
575
- client: config.client,
576
- withProviderSession: this.withProviderSession.bind(this)
577
- });
578
- case "deepseek":
579
- return runWithDeepSeek({
580
- ...config,
581
- client: config.client,
582
- withProviderSession: this.withProviderSession.bind(this)
583
- });
584
- case "google":
585
- return runWithGoogle({
586
- ...config,
587
- client: config.client,
588
- withProviderSession: this.withProviderSession.bind(this)
589
- });
590
- case "mistral":
591
- return runWithMistral({
592
- ...config,
593
- client: config.client,
594
- withProviderSession: this.withProviderSession.bind(this)
595
- });
596
- case "xai":
597
- return runWithXAI({
598
- ...config,
599
- client: config.client,
600
- withProviderSession: this.withProviderSession.bind(this)
601
- });
602
- case "togetherai":
603
- return runWithTogetherAI({
604
- ...config,
605
- client: config.client,
606
- withProviderSession: this.withProviderSession.bind(this)
607
- });
608
- default:
609
- throw new Error(`Unsupported provider: ${provider}`);
610
- }
611
- }
612
321
  };
613
322
 
614
323
  export { Metorial };