@contractspec/lib.ai-providers 3.0.0 → 3.1.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/browser/factory.js +58 -84
- package/dist/browser/index.js +227 -84
- package/dist/browser/legacy.js +58 -84
- package/dist/browser/selector-types.js +0 -0
- package/dist/browser/selector.js +693 -0
- package/dist/browser/validation.js +58 -84
- package/dist/factory.js +58 -84
- package/dist/index.d.ts +3 -0
- package/dist/index.js +227 -84
- package/dist/legacy.js +58 -84
- package/dist/node/factory.js +58 -84
- package/dist/node/index.js +227 -84
- package/dist/node/legacy.js +58 -84
- package/dist/node/selector-types.js +0 -0
- package/dist/node/selector.js +693 -0
- package/dist/node/validation.js +58 -84
- package/dist/selector-types.d.ts +50 -0
- package/dist/selector-types.js +1 -0
- package/dist/selector.d.ts +16 -0
- package/dist/selector.js +694 -0
- package/dist/types.d.ts +12 -0
- package/dist/validation.js +58 -84
- package/package.json +37 -8
package/dist/node/legacy.js
CHANGED
|
@@ -288,22 +288,30 @@ function getDefaultModel(provider) {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
// src/factory.ts
|
|
291
|
-
import {
|
|
292
|
-
import {
|
|
293
|
-
import {
|
|
294
|
-
import {
|
|
295
|
-
import {
|
|
291
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
292
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
293
|
+
import { createMistral } from "@ai-sdk/mistral";
|
|
294
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
295
|
+
import { createOllama } from "ollama-ai-provider";
|
|
296
296
|
class BaseProvider {
|
|
297
297
|
name;
|
|
298
298
|
model;
|
|
299
299
|
mode;
|
|
300
300
|
config;
|
|
301
|
+
transport;
|
|
302
|
+
authMethod;
|
|
303
|
+
apiVersion;
|
|
304
|
+
customHeaders;
|
|
301
305
|
cachedModel = null;
|
|
302
306
|
constructor(config) {
|
|
303
307
|
this.name = config.provider;
|
|
304
308
|
this.model = config.model ?? DEFAULT_MODELS[config.provider];
|
|
305
309
|
this.mode = this.determineMode(config);
|
|
306
310
|
this.config = config;
|
|
311
|
+
this.transport = config.transport;
|
|
312
|
+
this.authMethod = config.authMethod;
|
|
313
|
+
this.apiVersion = config.apiVersion;
|
|
314
|
+
this.customHeaders = config.customHeaders;
|
|
307
315
|
}
|
|
308
316
|
getModel() {
|
|
309
317
|
if (!this.cachedModel) {
|
|
@@ -343,81 +351,33 @@ class BaseProvider {
|
|
|
343
351
|
return "managed";
|
|
344
352
|
}
|
|
345
353
|
createModel() {
|
|
346
|
-
const { baseUrl, proxyUrl } = this.config;
|
|
354
|
+
const { baseUrl, proxyUrl, apiKey } = this.config;
|
|
355
|
+
const headers = this.customHeaders;
|
|
356
|
+
if (this.name === "ollama") {
|
|
357
|
+
const provider = createOllama({ baseURL: baseUrl, headers });
|
|
358
|
+
return provider(this.model);
|
|
359
|
+
}
|
|
360
|
+
if (this.mode === "managed" && proxyUrl) {
|
|
361
|
+
const provider = createOpenAI({ baseURL: proxyUrl, apiKey, headers });
|
|
362
|
+
return provider(this.model);
|
|
363
|
+
}
|
|
347
364
|
switch (this.name) {
|
|
348
|
-
case "
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
case "openai": {
|
|
366
|
+
const provider = createOpenAI({ apiKey, headers });
|
|
367
|
+
return provider(this.model);
|
|
368
|
+
}
|
|
369
|
+
case "anthropic": {
|
|
370
|
+
const provider = createAnthropic({ apiKey, headers });
|
|
371
|
+
return provider(this.model);
|
|
372
|
+
}
|
|
373
|
+
case "mistral": {
|
|
374
|
+
const provider = createMistral({ apiKey, headers });
|
|
375
|
+
return provider(this.model);
|
|
376
|
+
}
|
|
377
|
+
case "gemini": {
|
|
378
|
+
const provider = createGoogleGenerativeAI({ apiKey, headers });
|
|
379
|
+
return provider(this.model);
|
|
360
380
|
}
|
|
361
|
-
case "openai":
|
|
362
|
-
if (this.mode === "managed") {
|
|
363
|
-
const originalBaseUrl = process.env.OPENAI_BASE_URL;
|
|
364
|
-
if (proxyUrl) {
|
|
365
|
-
process.env.OPENAI_BASE_URL = proxyUrl;
|
|
366
|
-
}
|
|
367
|
-
const model = openai(this.model);
|
|
368
|
-
if (originalBaseUrl !== undefined) {
|
|
369
|
-
process.env.OPENAI_BASE_URL = originalBaseUrl;
|
|
370
|
-
} else if (proxyUrl) {
|
|
371
|
-
delete process.env.OPENAI_BASE_URL;
|
|
372
|
-
}
|
|
373
|
-
return model;
|
|
374
|
-
}
|
|
375
|
-
return openai(this.model);
|
|
376
|
-
case "anthropic":
|
|
377
|
-
if (this.mode === "managed") {
|
|
378
|
-
const originalBaseUrl = process.env.OPENAI_BASE_URL;
|
|
379
|
-
if (proxyUrl) {
|
|
380
|
-
process.env.OPENAI_BASE_URL = proxyUrl;
|
|
381
|
-
}
|
|
382
|
-
const model = openai(this.model);
|
|
383
|
-
if (originalBaseUrl !== undefined) {
|
|
384
|
-
process.env.OPENAI_BASE_URL = originalBaseUrl;
|
|
385
|
-
} else if (proxyUrl) {
|
|
386
|
-
delete process.env.OPENAI_BASE_URL;
|
|
387
|
-
}
|
|
388
|
-
return model;
|
|
389
|
-
}
|
|
390
|
-
return anthropic(this.model);
|
|
391
|
-
case "mistral":
|
|
392
|
-
if (this.mode === "managed") {
|
|
393
|
-
const originalBaseUrl = process.env.OPENAI_BASE_URL;
|
|
394
|
-
if (proxyUrl) {
|
|
395
|
-
process.env.OPENAI_BASE_URL = proxyUrl;
|
|
396
|
-
}
|
|
397
|
-
const model = openai(this.model);
|
|
398
|
-
if (originalBaseUrl !== undefined) {
|
|
399
|
-
process.env.OPENAI_BASE_URL = originalBaseUrl;
|
|
400
|
-
} else if (proxyUrl) {
|
|
401
|
-
delete process.env.OPENAI_BASE_URL;
|
|
402
|
-
}
|
|
403
|
-
return model;
|
|
404
|
-
}
|
|
405
|
-
return mistral(this.model);
|
|
406
|
-
case "gemini":
|
|
407
|
-
if (this.mode === "managed") {
|
|
408
|
-
const originalBaseUrl = process.env.OPENAI_BASE_URL;
|
|
409
|
-
if (proxyUrl) {
|
|
410
|
-
process.env.OPENAI_BASE_URL = proxyUrl;
|
|
411
|
-
}
|
|
412
|
-
const model = openai(this.model);
|
|
413
|
-
if (originalBaseUrl !== undefined) {
|
|
414
|
-
process.env.OPENAI_BASE_URL = originalBaseUrl;
|
|
415
|
-
} else if (proxyUrl) {
|
|
416
|
-
delete process.env.OPENAI_BASE_URL;
|
|
417
|
-
}
|
|
418
|
-
return model;
|
|
419
|
-
}
|
|
420
|
-
return google(this.model);
|
|
421
381
|
default:
|
|
422
382
|
throw new Error(`Unknown provider: ${this.name}`);
|
|
423
383
|
}
|
|
@@ -499,13 +459,17 @@ function createProviderFromEnv() {
|
|
|
499
459
|
case "ollama":
|
|
500
460
|
break;
|
|
501
461
|
}
|
|
462
|
+
const transport = process.env.CONTRACTSPEC_AI_TRANSPORT;
|
|
463
|
+
const apiVersion = process.env.CONTRACTSPEC_AI_API_VERSION;
|
|
502
464
|
return createProvider({
|
|
503
465
|
provider,
|
|
504
466
|
model,
|
|
505
467
|
apiKey,
|
|
506
468
|
baseUrl: process.env.OLLAMA_BASE_URL,
|
|
507
469
|
proxyUrl: process.env.CONTRACTSPEC_AI_PROXY_URL,
|
|
508
|
-
organizationId: process.env.CONTRACTSPEC_ORG_ID
|
|
470
|
+
organizationId: process.env.CONTRACTSPEC_ORG_ID,
|
|
471
|
+
transport,
|
|
472
|
+
apiVersion
|
|
509
473
|
});
|
|
510
474
|
}
|
|
511
475
|
function getAvailableProviders() {
|
|
@@ -513,35 +477,45 @@ function getAvailableProviders() {
|
|
|
513
477
|
providers.push({
|
|
514
478
|
provider: "ollama",
|
|
515
479
|
available: true,
|
|
516
|
-
mode: "local"
|
|
480
|
+
mode: "local",
|
|
481
|
+
transports: ["rest", "sdk"],
|
|
482
|
+
authMethods: []
|
|
517
483
|
});
|
|
518
484
|
const openaiKey = process.env.OPENAI_API_KEY;
|
|
519
485
|
providers.push({
|
|
520
486
|
provider: "openai",
|
|
521
487
|
available: Boolean(openaiKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
|
|
522
488
|
mode: openaiKey ? "byok" : "managed",
|
|
523
|
-
reason: !openaiKey ? "Set OPENAI_API_KEY for BYOK mode" : undefined
|
|
489
|
+
reason: !openaiKey ? "Set OPENAI_API_KEY for BYOK mode" : undefined,
|
|
490
|
+
transports: ["rest", "sdk"],
|
|
491
|
+
authMethods: ["api-key"]
|
|
524
492
|
});
|
|
525
493
|
const anthropicKey = process.env.ANTHROPIC_API_KEY;
|
|
526
494
|
providers.push({
|
|
527
495
|
provider: "anthropic",
|
|
528
496
|
available: Boolean(anthropicKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
|
|
529
497
|
mode: anthropicKey ? "byok" : "managed",
|
|
530
|
-
reason: !anthropicKey ? "Set ANTHROPIC_API_KEY for BYOK mode" : undefined
|
|
498
|
+
reason: !anthropicKey ? "Set ANTHROPIC_API_KEY for BYOK mode" : undefined,
|
|
499
|
+
transports: ["rest", "sdk"],
|
|
500
|
+
authMethods: ["api-key"]
|
|
531
501
|
});
|
|
532
502
|
const mistralKey = process.env.MISTRAL_API_KEY;
|
|
533
503
|
providers.push({
|
|
534
504
|
provider: "mistral",
|
|
535
505
|
available: Boolean(mistralKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
|
|
536
506
|
mode: mistralKey ? "byok" : "managed",
|
|
537
|
-
reason: !mistralKey ? "Set MISTRAL_API_KEY for BYOK mode" : undefined
|
|
507
|
+
reason: !mistralKey ? "Set MISTRAL_API_KEY for BYOK mode" : undefined,
|
|
508
|
+
transports: ["rest", "sdk"],
|
|
509
|
+
authMethods: ["api-key"]
|
|
538
510
|
});
|
|
539
511
|
const geminiKey = process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
|
|
540
512
|
providers.push({
|
|
541
513
|
provider: "gemini",
|
|
542
514
|
available: Boolean(geminiKey) || Boolean(process.env.CONTRACTSPEC_AI_PROXY_URL),
|
|
543
515
|
mode: geminiKey ? "byok" : "managed",
|
|
544
|
-
reason: !geminiKey ? "Set GOOGLE_API_KEY for BYOK mode" : undefined
|
|
516
|
+
reason: !geminiKey ? "Set GOOGLE_API_KEY for BYOK mode" : undefined,
|
|
517
|
+
transports: ["rest", "sdk"],
|
|
518
|
+
authMethods: ["api-key"]
|
|
545
519
|
});
|
|
546
520
|
return providers;
|
|
547
521
|
}
|
|
File without changes
|