@memberjunction/ai-prompts 6.2.0-edge.6 → 6.2.0-edge.7
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/AIPromptRunner.d.ts.map +1 -1
- package/dist/AIPromptRunner.js +13 -49
- package/dist/AIPromptRunner.js.map +1 -1
- package/dist/BaseModelRunner.d.ts +79 -1
- package/dist/BaseModelRunner.d.ts.map +1 -1
- package/dist/BaseModelRunner.js +155 -24
- package/dist/BaseModelRunner.js.map +1 -1
- package/dist/PromptRunDataCapture.d.ts.map +1 -1
- package/dist/PromptRunDataCapture.js +7 -0
- package/dist/PromptRunDataCapture.js.map +1 -1
- package/dist/decision/AIDecisionRunner.d.ts +1 -3
- package/dist/decision/AIDecisionRunner.d.ts.map +1 -1
- package/dist/decision/AIDecisionRunner.js +6 -17
- package/dist/decision/AIDecisionRunner.js.map +1 -1
- package/dist/embedding/AIEmbeddingRunner.d.ts +0 -1
- package/dist/embedding/AIEmbeddingRunner.d.ts.map +1 -1
- package/dist/embedding/AIEmbeddingRunner.js +6 -14
- package/dist/embedding/AIEmbeddingRunner.js.map +1 -1
- package/dist/embedding/embedding-runner.types.d.ts +8 -0
- package/dist/embedding/embedding-runner.types.d.ts.map +1 -1
- package/dist/image/AIImageGenerationRunner.d.ts +1 -3
- package/dist/image/AIImageGenerationRunner.d.ts.map +1 -1
- package/dist/image/AIImageGenerationRunner.js +3 -15
- package/dist/image/AIImageGenerationRunner.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/media/BaseMediaRunner.d.ts +1 -3
- package/dist/media/BaseMediaRunner.d.ts.map +1 -1
- package/dist/media/BaseMediaRunner.js +3 -15
- package/dist/media/BaseMediaRunner.js.map +1 -1
- package/dist/video/AIVideoRunner.d.ts +39 -11
- package/dist/video/AIVideoRunner.d.ts.map +1 -1
- package/dist/video/AIVideoRunner.js +69 -10
- package/dist/video/AIVideoRunner.js.map +1 -1
- package/dist/video/VideoGenerationRunner.d.ts +40 -0
- package/dist/video/VideoGenerationRunner.d.ts.map +1 -0
- package/dist/video/VideoGenerationRunner.js +299 -0
- package/dist/video/VideoGenerationRunner.js.map +1 -0
- package/dist/video/video-runner.types.d.ts +45 -1
- package/dist/video/video-runner.types.d.ts.map +1 -1
- package/package.json +12 -12
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @author MemberJunction.com
|
|
13
13
|
*/
|
|
14
14
|
import { BaseEntitySaveQueue, Metadata, IMetadataProvider } from '@memberjunction/core';
|
|
15
|
-
import { MJAIModelVendorEntity } from '@memberjunction/core-entities';
|
|
15
|
+
import { MJAIPromptModelEntity, MJAIModelVendorEntity } from '@memberjunction/core-entities';
|
|
16
16
|
import { MJAIModelEntityExtended, MJAIPromptEntityExtended, MJAIPromptRunEntityExtended, AIPromptParams, AIModelSelectionInfo } from '@memberjunction/ai-core-plus';
|
|
17
17
|
import { BaseResult, AIErrorInfo, AIPromptConfiguration, ModelUsage } from '@memberjunction/ai';
|
|
18
18
|
/**
|
|
@@ -51,9 +51,30 @@ export interface ModelVendorCandidate {
|
|
|
51
51
|
*/
|
|
52
52
|
promptModelConfiguration?: AIPromptConfiguration | null;
|
|
53
53
|
isPreferredVendor: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* True when this candidate's vendor is the one its `AIPromptModel` row names. Selection runs it in
|
|
56
|
+
* place of the first credentialed candidate of the same model; see `PromptModelVendorIndex`.
|
|
57
|
+
*/
|
|
58
|
+
isPromptModelVendor?: boolean;
|
|
54
59
|
priority: number;
|
|
55
60
|
source: 'explicit' | 'prompt-model' | 'model-type' | 'power-rank' | 'power-match-fallback';
|
|
56
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A single candidate entry returned by {@link BaseModelRunner.PreviewModelSelection},
|
|
64
|
+
* reporting the model, vendor, driver class, and whether credentials are available.
|
|
65
|
+
*/
|
|
66
|
+
export interface ModelSelectionPreviewItem {
|
|
67
|
+
/** ID of the candidate AI model */
|
|
68
|
+
ModelID: string;
|
|
69
|
+
/** Display name of the candidate AI model */
|
|
70
|
+
ModelName: string;
|
|
71
|
+
/** Display name of the inference provider vendor, when available */
|
|
72
|
+
VendorName?: string;
|
|
73
|
+
/** Driver class used to invoke the model-vendor pair */
|
|
74
|
+
DriverClass: string;
|
|
75
|
+
/** Whether platform or environment credentials are available for this candidate */
|
|
76
|
+
HasCredentials: boolean;
|
|
77
|
+
}
|
|
57
78
|
/**
|
|
58
79
|
* Configuration for failover behavior when primary model fails.
|
|
59
80
|
*
|
|
@@ -299,6 +320,16 @@ export declare abstract class BaseModelRunner {
|
|
|
299
320
|
* @returns Ordered array of model-vendor candidates (highest priority first)
|
|
300
321
|
*/
|
|
301
322
|
protected BuildModelVendorCandidates(prompt: MJAIPromptEntityExtended, explicitModelId?: string, configurationId?: string, preferredVendorId?: string, verbose?: boolean): ModelVendorCandidate[];
|
|
323
|
+
/**
|
|
324
|
+
* Previews the ordered model-vendor candidate list for `prompt` (optionally scoped to
|
|
325
|
+
* `configurationId`) and checks whether credentials are available for each candidate.
|
|
326
|
+
* Performs no model call and records no prompt run.
|
|
327
|
+
*
|
|
328
|
+
* @param prompt - The AI prompt whose model selection should be previewed
|
|
329
|
+
* @param configurationId - Optional AI configuration ID for preset-scoped candidate ordering
|
|
330
|
+
* @returns Ordered array of candidate preview items with credential availability flags
|
|
331
|
+
*/
|
|
332
|
+
PreviewModelSelection(prompt: MJAIPromptEntityExtended, configurationId?: string): ModelSelectionPreviewItem[];
|
|
302
333
|
/**
|
|
303
334
|
* PHASE 1: Build candidates for explicitly specified model ID.
|
|
304
335
|
* Returns candidates for the single model if it's active. Throws if the model is of a different type
|
|
@@ -364,6 +395,10 @@ export declare abstract class BaseModelRunner {
|
|
|
364
395
|
* Helper: Create candidates for all vendors of a model, sorted by vendor priority.
|
|
365
396
|
*/
|
|
366
397
|
private createCandidatesForAllVendors;
|
|
398
|
+
/**
|
|
399
|
+
* Returns all AIPromptModel rows for a prompt via AIEngine's O(1) PromptModelsByPromptID index.
|
|
400
|
+
*/
|
|
401
|
+
protected getPromptModelsForPromptId(promptId: string): MJAIPromptModelEntity[];
|
|
367
402
|
/**
|
|
368
403
|
* Helper: true if this prompt has any AIPromptModel bindings at all, regardless of Status or
|
|
369
404
|
* ConfigurationID. Distinguishes "no bindings were ever configured" (general selection strategy
|
|
@@ -403,8 +438,42 @@ export declare abstract class BaseModelRunner {
|
|
|
403
438
|
private sortByPowerPreference;
|
|
404
439
|
/**
|
|
405
440
|
* Helper: Create candidates for a model with AIModelVendor priorities (legacy behavior).
|
|
441
|
+
* `preferredVendorId` is the caller's runtime vendor override and is boosted above its own model's
|
|
442
|
+
* other vendors. A prompt-model row's `VendorID` changes no priority: that vendor's candidate is
|
|
443
|
+
* flagged `isPromptModelVendor`, and selection runs it in place of the first credentialed candidate
|
|
444
|
+
* of its model (see {@link PromptModelVendorIndex}), so the row picks the vendor but never which
|
|
445
|
+
* model runs. The row's effort level and configuration go only to the candidates the row
|
|
446
|
+
* describes: its own vendor, or every vendor of the model when it names none.
|
|
406
447
|
*/
|
|
407
448
|
private createCandidatesForModel;
|
|
449
|
+
/**
|
|
450
|
+
* Where a candidate list runs the prompt-model row's vendor in place of `candidates[index]`.
|
|
451
|
+
*
|
|
452
|
+
* Call it when `candidates[index]` is the first credentialed candidate a walk reaches. If that
|
|
453
|
+
* candidate is neither the caller's runtime override nor a row vendor, and a later candidate of the
|
|
454
|
+
* same model is its prompt-model row's vendor with credentials, returns that candidate's index;
|
|
455
|
+
* otherwise -1. The caller moves it into `index`. So the ranked order still decides which model
|
|
456
|
+
* runs, credentials included, and the row only decides which of that model's vendors serves it.
|
|
457
|
+
*/
|
|
458
|
+
protected PromptModelVendorIndex(candidates: ModelVendorCandidate[], index: number, hasCredentials: (candidate: ModelVendorCandidate) => boolean): number;
|
|
459
|
+
/** The key credential probes are cached under: driver, model and vendor. */
|
|
460
|
+
protected CandidateKey(candidate: ModelVendorCandidate): string;
|
|
461
|
+
/**
|
|
462
|
+
* Picks the candidate a run uses: the first with credentials, or that model's prompt-model-row vendor
|
|
463
|
+
* when it has credentials too (see {@link PromptModelVendorIndex}). Every runner selects here, so the
|
|
464
|
+
* vendor is the same whether or not failover runs. Probing stops at the pick unless `probeAll` asks
|
|
465
|
+
* for every candidate (a selection report). Returns the probes made, keyed by {@link CandidateKey},
|
|
466
|
+
* for failover to reuse.
|
|
467
|
+
*
|
|
468
|
+
* Failover walks the same rule, so a model with two prompt-model rows naming two vendors has two
|
|
469
|
+
* row-vendor candidates and the whole call budget can land on that one model: better for a vendor
|
|
470
|
+
* outage, worse for a model-level failure (retired APIName, refusal, bad ModelConfiguration). Calls
|
|
471
|
+
* that span several driver classes also skip the last-resort cross-provider attempt.
|
|
472
|
+
*/
|
|
473
|
+
protected SelectCandidate(candidates: ModelVendorCandidate[], hasCredentials: (candidate: ModelVendorCandidate) => boolean, probeAll?: boolean): {
|
|
474
|
+
Candidate: ModelVendorCandidate | null;
|
|
475
|
+
CredentialAvailability: Map<string, boolean>;
|
|
476
|
+
};
|
|
408
477
|
/**
|
|
409
478
|
* Awaits all in-flight `MJAIPromptRunEntityExtended` INSERT and UPDATE operations queued on this
|
|
410
479
|
* runner's internal {@link BaseEntitySaveQueue} (`_promptRunQueue`) and clears the in-flight parent
|
|
@@ -561,6 +630,15 @@ export declare abstract class BaseModelRunner {
|
|
|
561
630
|
* RateLimit and `{ errorMessage: 'Invalid API key provided' }` stays an Authentication error.
|
|
562
631
|
*/
|
|
563
632
|
private asModelError;
|
|
633
|
+
/**
|
|
634
|
+
* The Error a failover attempt records for a failed result. A driver may put something other than
|
|
635
|
+
* an Error in `exception` (the Anthropic driver wraps the SDK error with the result it was building),
|
|
636
|
+
* and reading `.message` off that gave undefined, so both the run's error and its stored
|
|
637
|
+
* `FailoverErrors` said "Unknown error" instead of what the provider said. An Error is used as it
|
|
638
|
+
* is, and an Error inside such a wrapper is unwrapped; anything else becomes an Error carrying the
|
|
639
|
+
* result's own message, with the result's classification kept on it.
|
|
640
|
+
*/
|
|
641
|
+
private failedResultError;
|
|
564
642
|
/**
|
|
565
643
|
* Filters out all candidates from a vendor when a vendor-level error occurs.
|
|
566
644
|
* Vendor-level errors affect all models from that vendor:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseModelRunner.d.ts","sourceRoot":"","sources":["../src/BaseModelRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,mBAAmB,EAKnB,QAAQ,EACR,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,
|
|
1
|
+
{"version":3,"file":"BaseModelRunner.d.ts","sourceRoot":"","sources":["../src/BaseModelRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,mBAAmB,EAKnB,QAAQ,EACR,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EAGtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,cAAc,EACd,oBAAoB,EAErB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,UAAU,EAGV,WAAW,EAGX,qBAAqB,EACrB,UAAU,EAGX,MAAM,oBAAoB,CAAC;AAW5B;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC3B,kGAAkG;IAClG,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,qFAAqF;IACrF,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,M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AOG;IAIH;;;;;;;;;;OAUG;IACH,SAAS,CAAC,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,qBAAqB;IAU3F;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,qBAAqB,CAC7B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,qBAAqB,EAC7B,aAAa,EAAE,MAAM,GACpB,OAAO;IA6BV;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,sBAAsB,CAC9B,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,GACvB,MAAM;IAaT;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,wBAAwB,CAChC,YAAY,EAAE,uBAAuB,EACrC,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC,EAC3C,aAAa,EAAE,qBAAqB,CAAC,eAAe,CAAC,EACrD,aAAa,EAAE,oBAAoB,EAAE,EACrC,cAAc,EAAE,eAAe,EAAE,GAChC,oBAAoB,EAAE;IAgIzB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,kBAAkB,CAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,OAAO,GACjB,IAAI;CA6BR"}
|
package/dist/BaseModelRunner.js
CHANGED
|
@@ -209,7 +209,7 @@ export class BaseModelRunner {
|
|
|
209
209
|
await CredentialEngine.Instance.Config(false, params.contextUser);
|
|
210
210
|
// Priority 2: PromptModel bindings (most specific) - with failover
|
|
211
211
|
if (promptId && modelId) {
|
|
212
|
-
const promptModel =
|
|
212
|
+
const promptModel = this.getPromptModelsForPromptId(promptId).find(pm => UUIDsEqual(pm.ModelID, modelId));
|
|
213
213
|
if (promptModel) {
|
|
214
214
|
const bindings = AIEngine.Instance.GetCredentialBindingsForTarget('PromptModel', promptModel.ID);
|
|
215
215
|
const result = await this.tryCredentialBindingsWithFailover(bindings, 'AICredentialBinding(PromptModel)', params, verbose);
|
|
@@ -404,7 +404,7 @@ export class BaseModelRunner {
|
|
|
404
404
|
hasPlatformCredential(promptId, modelId, vendorId) {
|
|
405
405
|
// Priority 2: PromptModel bindings
|
|
406
406
|
if (promptId && modelId) {
|
|
407
|
-
const promptModel =
|
|
407
|
+
const promptModel = this.getPromptModelsForPromptId(promptId).find(pm => UUIDsEqual(pm.ModelID, modelId));
|
|
408
408
|
if (promptModel && AIEngine.Instance.HasCredentialBindings('PromptModel', promptModel.ID)) {
|
|
409
409
|
return true;
|
|
410
410
|
}
|
|
@@ -499,6 +499,25 @@ export class BaseModelRunner {
|
|
|
499
499
|
// (SelectionStrategy='Default' or 'ByPower')
|
|
500
500
|
return this.buildCandidatesForGeneralSelection(prompt, configurationId, preferredVendorId, verbose);
|
|
501
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* Previews the ordered model-vendor candidate list for `prompt` (optionally scoped to
|
|
504
|
+
* `configurationId`) and checks whether credentials are available for each candidate.
|
|
505
|
+
* Performs no model call and records no prompt run.
|
|
506
|
+
*
|
|
507
|
+
* @param prompt - The AI prompt whose model selection should be previewed
|
|
508
|
+
* @param configurationId - Optional AI configuration ID for preset-scoped candidate ordering
|
|
509
|
+
* @returns Ordered array of candidate preview items with credential availability flags
|
|
510
|
+
*/
|
|
511
|
+
PreviewModelSelection(prompt, configurationId) {
|
|
512
|
+
const candidates = this.BuildModelVendorCandidates(prompt, undefined, configurationId);
|
|
513
|
+
return candidates.map(candidate => ({
|
|
514
|
+
ModelID: candidate.model.ID,
|
|
515
|
+
ModelName: candidate.model.Name,
|
|
516
|
+
...(candidate.vendorName != null ? { VendorName: candidate.vendorName } : {}),
|
|
517
|
+
DriverClass: candidate.driverClass,
|
|
518
|
+
HasCredentials: this.HasCredentialsAvailable(candidate.driverClass, prompt.ID, candidate.model.ID, candidate.vendorId),
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
502
521
|
/**
|
|
503
522
|
* PHASE 1: Build candidates for explicitly specified model ID.
|
|
504
523
|
* Returns candidates for the single model if it's active. Throws if the model is of a different type
|
|
@@ -527,7 +546,7 @@ export class BaseModelRunner {
|
|
|
527
546
|
*/
|
|
528
547
|
buildCandidatesForSpecificStrategy(prompt, configurationId, verbose) {
|
|
529
548
|
// Get all active AIPromptModel records for this prompt
|
|
530
|
-
const allPromptModels =
|
|
549
|
+
const allPromptModels = this.getPromptModelsForPromptId(prompt.ID).filter(pm => pm.Status === 'Active' || pm.Status === 'Preview');
|
|
531
550
|
// Filter by configuration matching rules
|
|
532
551
|
const promptModels = this.filterPromptModelsByConfiguration(allPromptModels, configurationId);
|
|
533
552
|
// Sort: config-specific before universal, then by priority DESC within each group
|
|
@@ -796,13 +815,19 @@ export class BaseModelRunner {
|
|
|
796
815
|
}
|
|
797
816
|
return candidates;
|
|
798
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Returns all AIPromptModel rows for a prompt via AIEngine's O(1) PromptModelsByPromptID index.
|
|
820
|
+
*/
|
|
821
|
+
getPromptModelsForPromptId(promptId) {
|
|
822
|
+
return AIEngine.Instance.PromptModelsByPromptID.get(NormalizeUUID(promptId)) ?? [];
|
|
823
|
+
}
|
|
799
824
|
/**
|
|
800
825
|
* Helper: true if this prompt has any AIPromptModel bindings at all, regardless of Status or
|
|
801
826
|
* ConfigurationID. Distinguishes "no bindings were ever configured" (general selection strategy
|
|
802
827
|
* should apply) from "bindings exist but are all Inactive" (no model should be selected).
|
|
803
828
|
*/
|
|
804
829
|
hasAnyPromptModelBindings(prompt) {
|
|
805
|
-
return
|
|
830
|
+
return this.getPromptModelsForPromptId(prompt.ID).length > 0;
|
|
806
831
|
}
|
|
807
832
|
/**
|
|
808
833
|
* Helper: Get prompt models for configuration with inheritance chain fallback.
|
|
@@ -810,13 +835,13 @@ export class BaseModelRunner {
|
|
|
810
835
|
* Returns models from the first config in the chain that has any, or falls back to null-config.
|
|
811
836
|
*/
|
|
812
837
|
getPromptModelsForConfiguration(prompt, configurationId) {
|
|
838
|
+
const forPrompt = this.getPromptModelsForPromptId(prompt.ID);
|
|
813
839
|
if (configurationId) {
|
|
814
840
|
// Get the configuration inheritance chain (child -> parent -> grandparent -> ...)
|
|
815
841
|
const chain = AIEngine.Instance.GetConfigurationChain(configurationId);
|
|
816
842
|
// Walk the chain looking for prompt models
|
|
817
843
|
for (const config of chain) {
|
|
818
|
-
const promptModels =
|
|
819
|
-
(pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
844
|
+
const promptModels = forPrompt.filter(pm => (pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
820
845
|
UUIDsEqual(pm.ConfigurationID, config.ID));
|
|
821
846
|
if (promptModels.length > 0) {
|
|
822
847
|
return promptModels;
|
|
@@ -826,8 +851,7 @@ export class BaseModelRunner {
|
|
|
826
851
|
LogStatus(`No models found in configuration chain for "${configurationId}", falling back to default models`);
|
|
827
852
|
}
|
|
828
853
|
// Return null-config (universal) models
|
|
829
|
-
return
|
|
830
|
-
(pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
854
|
+
return forPrompt.filter(pm => (pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
831
855
|
!pm.ConfigurationID);
|
|
832
856
|
}
|
|
833
857
|
/**
|
|
@@ -843,7 +867,7 @@ export class BaseModelRunner {
|
|
|
843
867
|
LogStatus(`Skipping model "${model.Name}" for prompt "${prompt?.Name ?? pm.PromptID}": model type "${modelTypeName}" does not match runner required type "${this.RequiredModelType}"`);
|
|
844
868
|
continue;
|
|
845
869
|
}
|
|
846
|
-
const modelCandidates = this.createCandidatesForModel(model, 5000, 'prompt-model', preferredVendorId, pm
|
|
870
|
+
const modelCandidates = this.createCandidatesForModel(model, 5000, 'prompt-model', preferredVendorId, pm);
|
|
847
871
|
candidates.push(...modelCandidates);
|
|
848
872
|
}
|
|
849
873
|
}
|
|
@@ -855,11 +879,11 @@ export class BaseModelRunner {
|
|
|
855
879
|
addConfigurationFallbackCandidates(candidates, prompt, configurationId, preferredVendorId, verbose) {
|
|
856
880
|
const chain = AIEngine.Instance.GetConfigurationChain(configurationId);
|
|
857
881
|
const requiredTypeId = this.RequiredModelTypeID();
|
|
882
|
+
const forPrompt = this.getPromptModelsForPromptId(prompt.ID);
|
|
858
883
|
// Add models from parent configs (skip index 0 which is the direct config, already handled)
|
|
859
884
|
for (let i = 1; i < chain.length; i++) {
|
|
860
885
|
const parentConfig = chain[i];
|
|
861
|
-
const parentModels =
|
|
862
|
-
(pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
886
|
+
const parentModels = forPrompt.filter(pm => (pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
863
887
|
UUIDsEqual(pm.ConfigurationID, parentConfig.ID));
|
|
864
888
|
if (parentModels.length > 0 && verbose) {
|
|
865
889
|
LogStatus(`Adding ${parentModels.length} models from parent config "${parentConfig.Name}" as fallback`);
|
|
@@ -874,14 +898,13 @@ export class BaseModelRunner {
|
|
|
874
898
|
}
|
|
875
899
|
// Decrease base priority for each level up the chain (3000, 2500, 2000, etc.)
|
|
876
900
|
const basePriority = 3000 - (i * 500);
|
|
877
|
-
const modelCandidates = this.createCandidatesForModel(model, basePriority, 'prompt-model', preferredVendorId, pm
|
|
901
|
+
const modelCandidates = this.createCandidatesForModel(model, basePriority, 'prompt-model', preferredVendorId, pm);
|
|
878
902
|
candidates.push(...modelCandidates);
|
|
879
903
|
}
|
|
880
904
|
}
|
|
881
905
|
}
|
|
882
906
|
// Finally add NULL config models (universal fallback) with lowest priority
|
|
883
|
-
const nullConfigModels =
|
|
884
|
-
(pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
907
|
+
const nullConfigModels = forPrompt.filter(pm => (pm.Status === 'Active' || pm.Status === 'Preview') &&
|
|
885
908
|
!pm.ConfigurationID);
|
|
886
909
|
if (nullConfigModels.length > 0 && verbose) {
|
|
887
910
|
LogStatus(`Adding ${nullConfigModels.length} NULL configuration models as universal fallback`);
|
|
@@ -895,7 +918,7 @@ export class BaseModelRunner {
|
|
|
895
918
|
continue;
|
|
896
919
|
}
|
|
897
920
|
const modelCandidates = this.createCandidatesForModel(model, 1000, // Lowest priority tier
|
|
898
|
-
'prompt-model', preferredVendorId, pm
|
|
921
|
+
'prompt-model', preferredVendorId, pm);
|
|
899
922
|
candidates.push(...modelCandidates);
|
|
900
923
|
}
|
|
901
924
|
}
|
|
@@ -959,9 +982,24 @@ export class BaseModelRunner {
|
|
|
959
982
|
}
|
|
960
983
|
/**
|
|
961
984
|
* Helper: Create candidates for a model with AIModelVendor priorities (legacy behavior).
|
|
962
|
-
|
|
963
|
-
|
|
985
|
+
* `preferredVendorId` is the caller's runtime vendor override and is boosted above its own model's
|
|
986
|
+
* other vendors. A prompt-model row's `VendorID` changes no priority: that vendor's candidate is
|
|
987
|
+
* flagged `isPromptModelVendor`, and selection runs it in place of the first credentialed candidate
|
|
988
|
+
* of its model (see {@link PromptModelVendorIndex}), so the row picks the vendor but never which
|
|
989
|
+
* model runs. The row's effort level and configuration go only to the candidates the row
|
|
990
|
+
* describes: its own vendor, or every vendor of the model when it names none.
|
|
991
|
+
*/
|
|
992
|
+
createCandidatesForModel(model, basePriority, source, preferredVendorId, promptModel) {
|
|
964
993
|
const modelCandidates = [];
|
|
994
|
+
const rowFields = (vendorId) => {
|
|
995
|
+
const isRowVendor = !!promptModel?.VendorID && UUIDsEqual(vendorId, promptModel.VendorID);
|
|
996
|
+
const applies = !!promptModel && (!promptModel.VendorID || isRowVendor);
|
|
997
|
+
return {
|
|
998
|
+
effortLevel: applies ? promptModel?.EffortLevel ?? undefined : undefined,
|
|
999
|
+
promptModelConfiguration: applies ? promptModel?.PromptConfigurationObject : undefined,
|
|
1000
|
+
isPromptModelVendor: isRowVendor
|
|
1001
|
+
};
|
|
1002
|
+
};
|
|
965
1003
|
// Get all vendors for this model - filter for inference providers only.
|
|
966
1004
|
// Uses the model's precomputed ModelVendors (grouped at engine load) rather than scanning
|
|
967
1005
|
// the global ModelVendors array.
|
|
@@ -981,7 +1019,8 @@ export class BaseModelRunner {
|
|
|
981
1019
|
supportsEffortLevel: preferredVendor.SupportsEffortLevel ?? model.SupportsEffortLevel ?? false,
|
|
982
1020
|
isPreferredVendor: true,
|
|
983
1021
|
priority: basePriority + 1000, // Boost priority for preferred vendor
|
|
984
|
-
source
|
|
1022
|
+
source,
|
|
1023
|
+
...rowFields(preferredVendor.VendorID)
|
|
985
1024
|
});
|
|
986
1025
|
}
|
|
987
1026
|
}
|
|
@@ -997,7 +1036,8 @@ export class BaseModelRunner {
|
|
|
997
1036
|
supportsEffortLevel: vendor.SupportsEffortLevel ?? model.SupportsEffortLevel ?? false,
|
|
998
1037
|
isPreferredVendor: false,
|
|
999
1038
|
priority: basePriority + (vendor.Priority || 0),
|
|
1000
|
-
source
|
|
1039
|
+
source,
|
|
1040
|
+
...rowFields(vendor.VendorID)
|
|
1001
1041
|
});
|
|
1002
1042
|
}
|
|
1003
1043
|
}
|
|
@@ -1010,15 +1050,75 @@ export class BaseModelRunner {
|
|
|
1010
1050
|
supportsEffortLevel: model.SupportsEffortLevel ?? false,
|
|
1011
1051
|
isPreferredVendor: false,
|
|
1012
1052
|
priority: basePriority,
|
|
1013
|
-
source
|
|
1053
|
+
source,
|
|
1054
|
+
...rowFields(undefined)
|
|
1014
1055
|
});
|
|
1015
1056
|
}
|
|
1016
1057
|
// Apply prompt model priority if provided (legacy blended approach)
|
|
1017
|
-
if (
|
|
1018
|
-
modelCandidates.forEach(c => c.priority +=
|
|
1058
|
+
if (promptModel) {
|
|
1059
|
+
modelCandidates.forEach(c => c.priority += promptModel.Priority * 10);
|
|
1019
1060
|
}
|
|
1020
1061
|
return modelCandidates;
|
|
1021
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Where a candidate list runs the prompt-model row's vendor in place of `candidates[index]`.
|
|
1065
|
+
*
|
|
1066
|
+
* Call it when `candidates[index]` is the first credentialed candidate a walk reaches. If that
|
|
1067
|
+
* candidate is neither the caller's runtime override nor a row vendor, and a later candidate of the
|
|
1068
|
+
* same model is its prompt-model row's vendor with credentials, returns that candidate's index;
|
|
1069
|
+
* otherwise -1. The caller moves it into `index`. So the ranked order still decides which model
|
|
1070
|
+
* runs, credentials included, and the row only decides which of that model's vendors serves it.
|
|
1071
|
+
*/
|
|
1072
|
+
PromptModelVendorIndex(candidates, index, hasCredentials) {
|
|
1073
|
+
const current = candidates[index];
|
|
1074
|
+
if (!current || current.isPreferredVendor || current.isPromptModelVendor) {
|
|
1075
|
+
return -1;
|
|
1076
|
+
}
|
|
1077
|
+
for (let j = index + 1; j < candidates.length; j++) {
|
|
1078
|
+
const candidate = candidates[j];
|
|
1079
|
+
if (candidate.isPromptModelVendor && UUIDsEqual(candidate.model.ID, current.model.ID) && hasCredentials(candidate)) {
|
|
1080
|
+
return j;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return -1;
|
|
1084
|
+
}
|
|
1085
|
+
/** The key credential probes are cached under: driver, model and vendor. */
|
|
1086
|
+
CandidateKey(candidate) {
|
|
1087
|
+
return `${candidate.driverClass}:${candidate.model.ID}:${candidate.vendorId || 'default'}`;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Picks the candidate a run uses: the first with credentials, or that model's prompt-model-row vendor
|
|
1091
|
+
* when it has credentials too (see {@link PromptModelVendorIndex}). Every runner selects here, so the
|
|
1092
|
+
* vendor is the same whether or not failover runs. Probing stops at the pick unless `probeAll` asks
|
|
1093
|
+
* for every candidate (a selection report). Returns the probes made, keyed by {@link CandidateKey},
|
|
1094
|
+
* for failover to reuse.
|
|
1095
|
+
*
|
|
1096
|
+
* Failover walks the same rule, so a model with two prompt-model rows naming two vendors has two
|
|
1097
|
+
* row-vendor candidates and the whole call budget can land on that one model: better for a vendor
|
|
1098
|
+
* outage, worse for a model-level failure (retired APIName, refusal, bad ModelConfiguration). Calls
|
|
1099
|
+
* that span several driver classes also skip the last-resort cross-provider attempt.
|
|
1100
|
+
*/
|
|
1101
|
+
SelectCandidate(candidates, hasCredentials, probeAll = false) {
|
|
1102
|
+
const availability = new Map();
|
|
1103
|
+
const probe = (candidate) => {
|
|
1104
|
+
const key = this.CandidateKey(candidate);
|
|
1105
|
+
let available = availability.get(key);
|
|
1106
|
+
if (available === undefined) {
|
|
1107
|
+
available = hasCredentials(candidate);
|
|
1108
|
+
availability.set(key, available);
|
|
1109
|
+
}
|
|
1110
|
+
return available;
|
|
1111
|
+
};
|
|
1112
|
+
const first = candidates.findIndex(probe);
|
|
1113
|
+
const rowVendor = first < 0 ? -1 : this.PromptModelVendorIndex(candidates, first, probe);
|
|
1114
|
+
if (probeAll) {
|
|
1115
|
+
candidates.forEach(probe);
|
|
1116
|
+
}
|
|
1117
|
+
return {
|
|
1118
|
+
Candidate: first < 0 ? null : candidates[rowVendor >= 0 ? rowVendor : first],
|
|
1119
|
+
CredentialAvailability: availability
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1022
1122
|
/**
|
|
1023
1123
|
* Awaits all in-flight `MJAIPromptRunEntityExtended` INSERT and UPDATE operations queued on this
|
|
1024
1124
|
* runner's internal {@link BaseEntitySaveQueue} (`_promptRunQueue`) and clears the in-flight parent
|
|
@@ -1268,7 +1368,7 @@ export class BaseModelRunner {
|
|
|
1268
1368
|
? new Map(credentialAvailability)
|
|
1269
1369
|
: new Map();
|
|
1270
1370
|
const candidateHasCredentials = (c) => {
|
|
1271
|
-
const key =
|
|
1371
|
+
const key = this.CandidateKey(c);
|
|
1272
1372
|
let has = failoverCredentialCache.get(key);
|
|
1273
1373
|
if (has === undefined) {
|
|
1274
1374
|
has = this.HasCredentialsAvailable(c.driverClass, prompt.ID, c.model.ID, c.vendorId, params);
|
|
@@ -1319,6 +1419,15 @@ export class BaseModelRunner {
|
|
|
1319
1419
|
skippedForCredentials++;
|
|
1320
1420
|
continue;
|
|
1321
1421
|
}
|
|
1422
|
+
// The model is decided; its prompt-model row's vendor serves it when that vendor has credentials.
|
|
1423
|
+
// Move it into this slot (on a copy) and re-run the index, so the displaced candidate follows it.
|
|
1424
|
+
const rowVendorIndex = this.PromptModelVendorIndex(allCandidates, i, candidateHasCredentials);
|
|
1425
|
+
if (rowVendorIndex > i) {
|
|
1426
|
+
allCandidates = [...allCandidates];
|
|
1427
|
+
allCandidates.splice(i, 0, ...allCandidates.splice(rowVendorIndex, 1));
|
|
1428
|
+
i--;
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1322
1431
|
// Budget check AFTER the credential skip and BEFORE the call, so a keyless tail costs
|
|
1323
1432
|
// nothing and the cap counts only calls a provider actually saw. Stopping here leaves
|
|
1324
1433
|
// `lastError` holding the most recent real failure, which is what the caller needs to see —
|
|
@@ -1406,7 +1515,7 @@ export class BaseModelRunner {
|
|
|
1406
1515
|
// Provider drivers (GeminiLLM, OpenAILLM, etc.) catch errors internally and return ChatResult{success: false}
|
|
1407
1516
|
// instead of throwing, so we must check result.success here.
|
|
1408
1517
|
if (!result.success && result.errorInfo?.canFailover) {
|
|
1409
|
-
lastError =
|
|
1518
|
+
lastError = this.failedResultError(result);
|
|
1410
1519
|
// Use shared failover error handling logic
|
|
1411
1520
|
const decision = await this.processFailoverError(lastError, result.errorInfo, candidate, attemptStartTime, i, allCandidates, failoverAttempts, prompt, failoverConfig);
|
|
1412
1521
|
// Update candidates list (may have been filtered)
|
|
@@ -1707,6 +1816,28 @@ export class BaseModelRunner {
|
|
|
1707
1816
|
wrapped.errorInfo = caught?.errorInfo ?? ErrorAnalyzer.analyzeError({ ...caught, message: caught?.errorMessage });
|
|
1708
1817
|
return wrapped;
|
|
1709
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* The Error a failover attempt records for a failed result. A driver may put something other than
|
|
1821
|
+
* an Error in `exception` (the Anthropic driver wraps the SDK error with the result it was building),
|
|
1822
|
+
* and reading `.message` off that gave undefined, so both the run's error and its stored
|
|
1823
|
+
* `FailoverErrors` said "Unknown error" instead of what the provider said. An Error is used as it
|
|
1824
|
+
* is, and an Error inside such a wrapper is unwrapped; anything else becomes an Error carrying the
|
|
1825
|
+
* result's own message, with the result's classification kept on it.
|
|
1826
|
+
*/
|
|
1827
|
+
failedResultError(result) {
|
|
1828
|
+
const exception = result.exception;
|
|
1829
|
+
if (exception instanceof Error) {
|
|
1830
|
+
return exception;
|
|
1831
|
+
}
|
|
1832
|
+
if (exception && typeof exception === 'object' && exception.exception instanceof Error) {
|
|
1833
|
+
return exception.exception;
|
|
1834
|
+
}
|
|
1835
|
+
const wrapped = new Error(result.errorMessage || 'Model execution failed');
|
|
1836
|
+
if (result.errorInfo) {
|
|
1837
|
+
wrapped.errorInfo = result.errorInfo;
|
|
1838
|
+
}
|
|
1839
|
+
return wrapped;
|
|
1840
|
+
}
|
|
1710
1841
|
/**
|
|
1711
1842
|
* Filters out all candidates from a vendor when a vendor-level error occurs.
|
|
1712
1843
|
* Vendor-level errors affect all models from that vendor:
|