@memberjunction/ai-agents 6.2.0-edge.6 → 6.2.0-edge.8
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/README.md +44 -2
- package/dist/AgentRunner.d.ts +96 -3
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +438 -34
- package/dist/AgentRunner.js.map +1 -1
- package/dist/AgentWakeTriggerService.d.ts.map +1 -1
- package/dist/AgentWakeTriggerService.js +8 -1
- package/dist/AgentWakeTriggerService.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +15 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +43 -3
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/MemoryWriteManager.d.ts +12 -0
- package/dist/MemoryWriteManager.d.ts.map +1 -1
- package/dist/MemoryWriteManager.js +18 -3
- package/dist/MemoryWriteManager.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +1 -0
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +51 -13
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +89 -21
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +6 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +70 -6
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +46 -3
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +9 -4
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +35 -4
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +27 -4
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +121 -18
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +390 -37
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +2046 -433
- package/dist/base-agent.js.map +1 -1
- package/dist/catalog-narrowing.d.ts.map +1 -1
- package/dist/catalog-narrowing.js +6 -3
- package/dist/catalog-narrowing.js.map +1 -1
- package/dist/client-tool-results.d.ts +12 -0
- package/dist/client-tool-results.d.ts.map +1 -1
- package/dist/client-tool-results.js +21 -0
- package/dist/client-tool-results.js.map +1 -1
- package/dist/handoff-target.d.ts +80 -0
- package/dist/handoff-target.d.ts.map +1 -0
- package/dist/handoff-target.js +158 -0
- package/dist/handoff-target.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +2 -0
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-tool-builder.d.ts +6 -0
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +21 -5
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/control-tools.d.ts +15 -4
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +31 -14
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/pipeline/pipeline-registry.d.ts +5 -12
- package/dist/pipeline/pipeline-registry.d.ts.map +1 -1
- package/dist/pipeline/pipeline-registry.js +28 -2
- package/dist/pipeline/pipeline-registry.js.map +1 -1
- package/dist/pipeline/providers/serialize.d.ts +7 -3
- package/dist/pipeline/providers/serialize.d.ts.map +1 -1
- package/dist/pipeline/providers/serialize.js +9 -5
- package/dist/pipeline/providers/serialize.js.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.d.ts +3 -3
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +12 -6
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +2 -0
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +72 -25
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +154 -54
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +2 -28
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-platform-credentials.d.ts +65 -0
- package/dist/realtime/realtime-platform-credentials.d.ts.map +1 -0
- package/dist/realtime/realtime-platform-credentials.js +148 -0
- package/dist/realtime/realtime-platform-credentials.js.map +1 -0
- package/dist/realtime/realtime-recording-capture.d.ts +1 -0
- package/dist/realtime/realtime-recording-capture.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-capture.js +17 -3
- package/dist/realtime/realtime-recording-capture.js.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.js +9 -4
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -1
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +5 -7
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +1 -0
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.d.ts +41 -2
- package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.js +86 -4
- package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
- package/dist/rubric-evaluation-agent-runner.js +1 -0
- package/dist/rubric-evaluation-agent-runner.js.map +1 -1
- package/dist/runtime-state-fragment.d.ts.map +1 -1
- package/dist/runtime-state-fragment.js +3 -0
- package/dist/runtime-state-fragment.js.map +1 -1
- package/dist/sub-agent-consult.d.ts +75 -0
- package/dist/sub-agent-consult.d.ts.map +1 -0
- package/dist/sub-agent-consult.js +193 -0
- package/dist/sub-agent-consult.js.map +1 -0
- package/dist/volatile-child-prompt.d.ts +7 -0
- package/dist/volatile-child-prompt.d.ts.map +1 -1
- package/dist/volatile-child-prompt.js +8 -0
- package/dist/volatile-child-prompt.js.map +1 -1
- package/package.json +20 -20
|
@@ -47,7 +47,8 @@ import { BridgeRealtimeUsageRecorder } from './bridge-realtime-usage-recorder.js
|
|
|
47
47
|
import { RealtimeToolBroker, INVOKE_TARGET_AGENT_TOOL_NAME, INVOKE_TARGET_AGENT_DESCRIPTION, BuildRealtimeAgentFraming } from './realtime-tool-broker.js';
|
|
48
48
|
import { NARRATION_PROMPT_NAME, LEGACY_NARRATION_PROMPT_NAME, ResolveNarrationInstructionsTemplate } from './realtime-narration.js';
|
|
49
49
|
import { BuildVoiceMannerSection, BuildAppRealtimeOverridesJson, DeepMergeConfigs, FindDeprecatedRealtimeVideoKeys, GetModelCatalogSessionSettings, GetDisclosureForTarget, GetNarrationPaceMs, GetProviderVoiceSettings, GetSessionTuningSettings, GetWatchesMeetingVideo, ResolveEffectiveRealtimeConfig, MatchProviderVoiceSettings, GetDirectActionsConfig, IsActionAllowedForDirectInvocation } from './realtime-coagent-config.js';
|
|
50
|
-
import { ListRealtimeVendorsForModel, SelectRealtimeVendorForModel } from './realtime-vendor-resolution.js';
|
|
50
|
+
import { ListRealtimeVendorsForModel, SelectRealtimeVendorForModel, RealtimeKeyFixHint } from './realtime-vendor-resolution.js';
|
|
51
|
+
import { RealtimePlatformCredentials, ResolveRealtimePlatformCredentials } from './realtime-platform-credentials.js';
|
|
51
52
|
import { AIEngineBase, MergeRealtimeUsageRecord } from '@memberjunction/ai-engine-base';
|
|
52
53
|
import { BuildSessionChannelPolicy } from './realtime-channel-policy.js';
|
|
53
54
|
/**
|
|
@@ -340,6 +341,7 @@ export class RealtimeClientSessionService {
|
|
|
340
341
|
// failure here never fails the prepare — we just omit the ids.
|
|
341
342
|
const promptID = this.resolveCoAgentSystemPrompt(coAgent).PromptID;
|
|
342
343
|
const obs = await this.createCoAgentObservabilityRun(coAgent, promptID, resolution.ModelID, resolution.VendorID, input.UserID || contextUser?.ID, input.AgentSessionID, contextUser, provider, input.ConversationID);
|
|
344
|
+
this.logMissingCoAgentObservability(coAgent, promptID, obs, input.AgentSessionID, 'PrepareClientSession');
|
|
343
345
|
return {
|
|
344
346
|
Success: true,
|
|
345
347
|
ClientConfig: clientConfig,
|
|
@@ -430,6 +432,7 @@ export class RealtimeClientSessionService {
|
|
|
430
432
|
let localToolHandler;
|
|
431
433
|
const promptID = this.resolveCoAgentSystemPrompt(coAgent).PromptID;
|
|
432
434
|
const obs = await this.createCoAgentObservabilityRun(coAgent, promptID, resolution.ModelID, resolution.VendorID, input.UserID || contextUser?.ID, input.AgentSessionID, contextUser, provider, input.ConversationID);
|
|
435
|
+
this.logMissingCoAgentObservability(coAgent, promptID, obs, input.AgentSessionID, 'WireBridgeRealtimeSession');
|
|
433
436
|
const usage = this.wireBridgeUsage(session, obs?.PromptRunID, contextUser, provider);
|
|
434
437
|
const finalize = this.createBridgeFinalizer(obs, usage, contextUser, provider);
|
|
435
438
|
this.wireBridgeToolCalls(session, {
|
|
@@ -619,9 +622,9 @@ export class RealtimeClientSessionService {
|
|
|
619
622
|
const appSettingsJson = await this.resolveAppRealtimeOverrides(input.ApplicationID, contextUser, provider);
|
|
620
623
|
const effectiveConfig = this.resolveEffectiveConfig(coAgent, input.ConfigOverridesJson, targetAgent, appSettingsJson);
|
|
621
624
|
this.logDeprecatedVideoKeys(effectiveConfig, coAgent, targetAgent);
|
|
622
|
-
const outcome = await this.resolveModelForSession(input, coAgent, effectiveConfig);
|
|
625
|
+
const outcome = await this.resolveModelForSession(input, coAgent, effectiveConfig, contextUser);
|
|
623
626
|
if (!outcome.Resolution) {
|
|
624
|
-
return { Success: false, ErrorMessage: outcome.ErrorMessage ?? this.noModelMessage() };
|
|
627
|
+
return { Success: false, ErrorMessage: outcome.ErrorMessage ?? this.noModelMessage(input.CredentialScope) };
|
|
625
628
|
}
|
|
626
629
|
const resolution = outcome.Resolution;
|
|
627
630
|
let hostTools = input.HostTools;
|
|
@@ -858,6 +861,7 @@ export class RealtimeClientSessionService {
|
|
|
858
861
|
EntityName: 'MJ: Applications',
|
|
859
862
|
ExtraFilter: `ID='${EscapeSQLString(appId)}'`,
|
|
860
863
|
MaxRows: 1,
|
|
864
|
+
SkipTotalRowCount: true,
|
|
861
865
|
ResultType: 'entity_object',
|
|
862
866
|
}, contextUser);
|
|
863
867
|
if (!result.Success || !result.Results || result.Results.length === 0) {
|
|
@@ -915,6 +919,34 @@ export class RealtimeClientSessionService {
|
|
|
915
919
|
const runStepID = await this.createCoAgentRunStep(coAgentRunID, promptID, promptRunID, contextUser, provider);
|
|
916
920
|
return { CoAgentRunID: coAgentRunID, PromptRunID: promptRunID ?? undefined, CoAgentRunStepID: runStepID ?? undefined };
|
|
917
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
* Logs once, when a session is prepared, why it has no co-agent prompt run: without one, the session's usage
|
|
924
|
+
* and cost are not recorded. Two causes: the co-agent has no Active `MJ: AI Agent Prompts` row (so no prompt run
|
|
925
|
+
* is created), or a run save failed (its own error was logged just before this line). Silent when both ids exist.
|
|
926
|
+
*
|
|
927
|
+
* @param coAgent The resolved co-agent.
|
|
928
|
+
* @param promptID The co-agent's system prompt id, or `null` when it has none.
|
|
929
|
+
* @param obs The observability ids, or `null` when the co-agent run save failed.
|
|
930
|
+
* @param agentSessionID The session the ids belong to.
|
|
931
|
+
* @param caller The prepare path, for the log prefix.
|
|
932
|
+
*/
|
|
933
|
+
logMissingCoAgentObservability(coAgent, promptID, obs, agentSessionID, caller) {
|
|
934
|
+
if (obs?.PromptRunID) {
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
const agent = `co-agent '${coAgent.Name}' (${coAgent.ID})`;
|
|
938
|
+
const consequence = `session ${agentSessionID || '(none)'} has no co-agent prompt run, so its usage and cost are not recorded`;
|
|
939
|
+
if (!obs) {
|
|
940
|
+
LogError(`${caller}: the co-agent run for ${agent} could not be saved (see the error above) — ${consequence}.`);
|
|
941
|
+
}
|
|
942
|
+
else if (!promptID) {
|
|
943
|
+
LogError(`${caller}: ${agent} has no Active 'MJ: AI Agent Prompts' row, so no prompt run was created — ${consequence}. ` +
|
|
944
|
+
'Give the co-agent an active system prompt to record usage.');
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
LogError(`${caller}: the prompt run for ${agent} (prompt ${promptID}) could not be saved (see the error above) — ${consequence}.`);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
918
950
|
/**
|
|
919
951
|
* Creates the co-agent `AIAgentRun` row (Status `Running`). Returns its id, or `null` (logging
|
|
920
952
|
* `CompleteMessage`) when the save fails.
|
|
@@ -1562,39 +1594,65 @@ export class RealtimeClientSessionService {
|
|
|
1562
1594
|
* @param input The prepare-session input (carries the optional preferred model id).
|
|
1563
1595
|
* @param coAgent The resolved co-agent (threaded to the default-resolution seam).
|
|
1564
1596
|
* @param effectiveConfig The resolved effective configuration (carries `modelPreference` and the video setting).
|
|
1597
|
+
* @param contextUser The calling user, as whom the platform's MJ Credentials are read.
|
|
1565
1598
|
* @returns The resolution outcome (resolution or failure reason).
|
|
1566
1599
|
*/
|
|
1567
|
-
async resolveModelForSession(input, coAgent, effectiveConfig) {
|
|
1600
|
+
async resolveModelForSession(input, coAgent, effectiveConfig, contextUser) {
|
|
1568
1601
|
// One resolver for every branch below, built here rather than per branch so the requested-model,
|
|
1569
1602
|
// configured-preference and default paths cannot disagree about which credentials the session
|
|
1570
|
-
// may use. It answers with the session's RUN keys only: resolveVendorAndInstantiate layers
|
|
1571
|
-
//
|
|
1572
|
-
//
|
|
1573
|
-
//
|
|
1603
|
+
// may use. It answers with the session's RUN keys only: resolveVendorAndInstantiate layers the
|
|
1604
|
+
// platform's MJ Credentials over it and this service's getAPIKeyForDriver seam under it, giving
|
|
1605
|
+
// platform credential → run key → seam → (the seam's default) env. A resolver that fell back to
|
|
1606
|
+
// the environment itself would answer before the seam, so a subclass that overrides the seam
|
|
1607
|
+
// would lose to AI_VENDOR_API_KEY__<driver>.
|
|
1574
1608
|
const resolveRunKey = this.buildRunKeyResolver(input.APIKeys);
|
|
1575
1609
|
const scope = input.CredentialScope ?? 'Any';
|
|
1610
|
+
// MJ Credential resolution is async and vendor selection is not, so every candidate vendor's
|
|
1611
|
+
// credential is resolved here, once, before any branch selects.
|
|
1612
|
+
const platform = await this.resolvePlatformCredentials(input.CredentialScope, coAgent, input.PreferredModelID, contextUser);
|
|
1576
1613
|
const preferAvatar = effectiveConfig?.realtime?.video?.enabled === true && RealtimeSessionCanShowAvatar(input);
|
|
1577
1614
|
if (input.PreferredModelID) {
|
|
1578
|
-
return this.resolvePreferredRealtimeModel(input.PreferredModelID, resolveRunKey, scope, preferAvatar);
|
|
1615
|
+
return this.resolvePreferredRealtimeModel(input.PreferredModelID, resolveRunKey, scope, preferAvatar, platform);
|
|
1579
1616
|
}
|
|
1580
|
-
const fromConfig = this.resolveConfiguredModelPreference(effectiveConfig, resolveRunKey, scope, preferAvatar);
|
|
1617
|
+
const fromConfig = this.resolveConfiguredModelPreference(effectiveConfig, resolveRunKey, scope, preferAvatar, platform);
|
|
1581
1618
|
if (fromConfig) {
|
|
1582
1619
|
return { Resolution: fromConfig };
|
|
1583
1620
|
}
|
|
1584
|
-
const resolution = await this.resolveDefaultRealtimeModel(coAgent, preferAvatar, resolveRunKey, scope);
|
|
1585
|
-
return resolution ? { Resolution: resolution } : { ErrorMessage: this.noModelMessage() };
|
|
1621
|
+
const resolution = await this.resolveDefaultRealtimeModel(coAgent, preferAvatar, resolveRunKey, scope, platform);
|
|
1622
|
+
return resolution ? { Resolution: resolution } : { ErrorMessage: this.noModelMessage(scope) };
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* The platform MJ Credentials of every vendor this session might select: the Active Realtime
|
|
1626
|
+
* models' vendors, plus an explicitly requested model's. **Overridable seam** (tests substitute
|
|
1627
|
+
* credentials without a credential store). `'RuntimeOnly'` resolves none.
|
|
1628
|
+
*
|
|
1629
|
+
* @param credentialScope The session's credential scope.
|
|
1630
|
+
* @param coAgent The co-agent (its candidate models are the default walk's).
|
|
1631
|
+
* @param preferredModelID An explicitly requested model, which may sit outside the default walk.
|
|
1632
|
+
* @param contextUser The user the credentials are read as.
|
|
1633
|
+
* @returns The resolved credentials.
|
|
1634
|
+
*/
|
|
1635
|
+
async resolvePlatformCredentials(credentialScope, coAgent, preferredModelID, contextUser) {
|
|
1636
|
+
if (!CredentialScopeAllows(credentialScope, 'PlatformCredential')) {
|
|
1637
|
+
return RealtimePlatformCredentials.None;
|
|
1638
|
+
}
|
|
1639
|
+
const modelIDs = this.selectRealtimeModelCandidates(coAgent).map(m => m.ID);
|
|
1640
|
+
if (preferredModelID && !modelIDs.some(id => UUIDsEqual(id, preferredModelID))) {
|
|
1641
|
+
modelIDs.unshift(preferredModelID);
|
|
1642
|
+
}
|
|
1643
|
+
return ResolveRealtimePlatformCredentials(modelIDs, contextUser, credentialScope);
|
|
1586
1644
|
}
|
|
1587
1645
|
/**
|
|
1588
1646
|
* The default walk. With `preferAvatar` (the co-agent's video setting is on and the session could show an avatar),
|
|
1589
1647
|
* it takes the first candidate that shows one ({@link ResolveAvatarRealtimeModel}). When none does, or without it, it
|
|
1590
1648
|
* takes {@link resolveRealtimeModel}'s choice; when one was preferred, one log line says the call stays audio only.
|
|
1591
1649
|
*/
|
|
1592
|
-
async resolveDefaultRealtimeModel(coAgent, preferAvatar, resolve, credentialScope) {
|
|
1593
|
-
const withAvatar = preferAvatar ? this.ResolveAvatarRealtimeModel(coAgent, resolve, credentialScope) : null;
|
|
1650
|
+
async resolveDefaultRealtimeModel(coAgent, preferAvatar, resolve, credentialScope, platform) {
|
|
1651
|
+
const withAvatar = preferAvatar ? this.ResolveAvatarRealtimeModel(coAgent, resolve, credentialScope, platform) : null;
|
|
1594
1652
|
if (withAvatar) {
|
|
1595
1653
|
return withAvatar;
|
|
1596
1654
|
}
|
|
1597
|
-
const resolution = await this.resolveRealtimeModel(coAgent, resolve, credentialScope, preferAvatar);
|
|
1655
|
+
const resolution = await this.resolveRealtimeModel(coAgent, resolve, credentialScope, preferAvatar, platform);
|
|
1598
1656
|
if (preferAvatar && resolution) {
|
|
1599
1657
|
LogStatus('[RealtimeCoAgent] Video is on, but no realtime model with a usable key shows an avatar (its Video/Output row ' +
|
|
1600
1658
|
`and its endpoint): using '${resolution.ModelName ?? resolution.APIName}' on ${resolution.DriverClass ?? 'its driver'}, audio only.`);
|
|
@@ -1611,14 +1669,15 @@ export class RealtimeClientSessionService {
|
|
|
1611
1669
|
* @param coAgent The co-agent (reserved for future per-agent model preference).
|
|
1612
1670
|
* @param resolve The session's run-scoped key resolver (run keys only; see {@link resolveVendorAndInstantiate}).
|
|
1613
1671
|
* @param credentialScope The session's credential scope; see {@link resolveVendorAndInstantiate}.
|
|
1672
|
+
* @param platform The platform MJ Credentials resolved for the session; see {@link resolveVendorAndInstantiate}.
|
|
1614
1673
|
* @returns The resolution, or `null` when no candidate shows an avatar.
|
|
1615
1674
|
*/
|
|
1616
|
-
ResolveAvatarRealtimeModel(coAgent, resolve, credentialScope = 'Any') {
|
|
1617
|
-
const resolveKey = this.buildKeyChain(resolve, credentialScope);
|
|
1675
|
+
ResolveAvatarRealtimeModel(coAgent, resolve, credentialScope = 'Any', platform = RealtimePlatformCredentials.None) {
|
|
1618
1676
|
for (const model of this.selectRealtimeModelCandidates(coAgent)) {
|
|
1619
1677
|
if (ReadRealtimeVideoOutputRow(model.ID, AIEngine.Instance) === 'unsupported') {
|
|
1620
1678
|
continue;
|
|
1621
1679
|
}
|
|
1680
|
+
const resolveKey = this.buildKeyChain(resolve, credentialScope, platform, model.ID);
|
|
1622
1681
|
for (const vendor of ListRealtimeVendorsForModel(model.ID)) {
|
|
1623
1682
|
const resolution = this.instantiateRealtimeVendor(model, vendor, resolveKey);
|
|
1624
1683
|
if (resolution?.Model.SupportsClientDirect && RealtimeModelShowsAvatar(resolution, AIEngine.Instance)) {
|
|
@@ -1651,9 +1710,10 @@ export class RealtimeClientSessionService {
|
|
|
1651
1710
|
* @param resolve The session's run-scoped key resolver (run keys only; see {@link resolveVendorAndInstantiate}).
|
|
1652
1711
|
* @param credentialScope The session's credential scope; see {@link resolveVendorAndInstantiate}.
|
|
1653
1712
|
* @param showsAvatar Whether the session will show an avatar; see {@link resolveVendorAndInstantiate}.
|
|
1713
|
+
* @param platform The platform MJ Credentials resolved for the session; see {@link resolveVendorAndInstantiate}.
|
|
1654
1714
|
* @returns The resolution, or `null` when no preference is configured or it can't be satisfied.
|
|
1655
1715
|
*/
|
|
1656
|
-
resolveConfiguredModelPreference(effectiveConfig, resolve, credentialScope = 'Any', showsAvatar = false) {
|
|
1716
|
+
resolveConfiguredModelPreference(effectiveConfig, resolve, credentialScope = 'Any', showsAvatar = false, platform = RealtimePlatformCredentials.None) {
|
|
1657
1717
|
const preference = effectiveConfig?.realtime?.modelPreference;
|
|
1658
1718
|
if (!preference) {
|
|
1659
1719
|
return null;
|
|
@@ -1669,7 +1729,7 @@ export class RealtimeClientSessionService {
|
|
|
1669
1729
|
`'${model.Name}' but it is not an Active Realtime model — falling through to default resolution.`);
|
|
1670
1730
|
return null;
|
|
1671
1731
|
}
|
|
1672
|
-
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar);
|
|
1732
|
+
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar, platform);
|
|
1673
1733
|
if (!resolution) {
|
|
1674
1734
|
LogError(`RealtimeClientSessionService: configured realtime model preference '${model.Name}' has no usable ` +
|
|
1675
1735
|
'vendor DriverClass/API key — falling through to default resolution.');
|
|
@@ -1704,9 +1764,10 @@ export class RealtimeClientSessionService {
|
|
|
1704
1764
|
* @param resolve The session's run-scoped key resolver (run keys only; see {@link resolveVendorAndInstantiate}).
|
|
1705
1765
|
* @param credentialScope The session's credential scope; see {@link resolveVendorAndInstantiate}.
|
|
1706
1766
|
* @param showsAvatar Whether the session will show an avatar; see {@link resolveVendorAndInstantiate}.
|
|
1767
|
+
* @param platform The platform MJ Credentials resolved for the session; see {@link resolveVendorAndInstantiate}.
|
|
1707
1768
|
* @returns The resolution outcome (resolution or a specific failure reason).
|
|
1708
1769
|
*/
|
|
1709
|
-
resolvePreferredRealtimeModel(preferredModelID, resolve, credentialScope = 'Any', showsAvatar = false) {
|
|
1770
|
+
resolvePreferredRealtimeModel(preferredModelID, resolve, credentialScope = 'Any', showsAvatar = false, platform = RealtimePlatformCredentials.None) {
|
|
1710
1771
|
const model = this.findModelByID(preferredModelID);
|
|
1711
1772
|
if (!model) {
|
|
1712
1773
|
return { ErrorMessage: `The requested realtime model (id '${preferredModelID}') was not found in AI model metadata.` };
|
|
@@ -1717,11 +1778,11 @@ export class RealtimeClientSessionService {
|
|
|
1717
1778
|
if (!this.isRealtimeModel(model)) {
|
|
1718
1779
|
return { ErrorMessage: `The requested model '${model.Name}' is not a Realtime model (its type is '${model.AIModelType}').` };
|
|
1719
1780
|
}
|
|
1720
|
-
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar);
|
|
1781
|
+
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar, platform);
|
|
1721
1782
|
if (!resolution) {
|
|
1722
1783
|
return {
|
|
1723
|
-
ErrorMessage: `The requested model '${model.Name}' has no active vendor with a usable DriverClass/API key ` +
|
|
1724
|
-
|
|
1784
|
+
ErrorMessage: `The requested model '${model.Name}' has no active vendor with a usable DriverClass/API key, so the ` +
|
|
1785
|
+
`voice session could not be started with it. ${RealtimeKeyFixHint(credentialScope)}`
|
|
1725
1786
|
};
|
|
1726
1787
|
}
|
|
1727
1788
|
return { Resolution: resolution };
|
|
@@ -1752,9 +1813,10 @@ export class RealtimeClientSessionService {
|
|
|
1752
1813
|
* @param resolve The session's run-scoped key resolver (run keys only; see {@link resolveVendorAndInstantiate}).
|
|
1753
1814
|
* @param credentialScope The session's credential scope; see {@link resolveVendorAndInstantiate}.
|
|
1754
1815
|
* @param showsAvatar Whether the session will show an avatar; see {@link resolveVendorAndInstantiate}.
|
|
1816
|
+
* @param platform The platform MJ Credentials resolved for the session; see {@link resolveVendorAndInstantiate}.
|
|
1755
1817
|
* @returns The resolved model + identifiers, or `null`.
|
|
1756
1818
|
*/
|
|
1757
|
-
async resolveRealtimeModel(coAgent, resolve, credentialScope = 'Any', showsAvatar = false) {
|
|
1819
|
+
async resolveRealtimeModel(coAgent, resolve, credentialScope = 'Any', showsAvatar = false, platform = RealtimePlatformCredentials.None) {
|
|
1758
1820
|
// Walk candidates in descending PowerRank, returning the FIRST that fully resolves to a usable
|
|
1759
1821
|
// client-direct driver (active vendor + API key + ClassFactory driver + SupportsClientDirect).
|
|
1760
1822
|
// Single-pick dead-ended whenever the highest-power model lacked a key or client-direct support
|
|
@@ -1762,7 +1824,7 @@ export class RealtimeClientSessionService {
|
|
|
1762
1824
|
// surfaced "No usable Realtime model" instead of falling through to a model that works.
|
|
1763
1825
|
const candidates = this.selectRealtimeModelCandidates(coAgent);
|
|
1764
1826
|
for (const model of candidates) {
|
|
1765
|
-
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar);
|
|
1827
|
+
const resolution = this.resolveVendorAndInstantiate(model, resolve, credentialScope, showsAvatar, platform);
|
|
1766
1828
|
if (resolution && resolution.Model.SupportsClientDirect) {
|
|
1767
1829
|
return resolution;
|
|
1768
1830
|
}
|
|
@@ -1773,9 +1835,11 @@ export class RealtimeClientSessionService {
|
|
|
1773
1835
|
* Shared tail of model resolution: picks the vendor (with a usable API key) for an
|
|
1774
1836
|
* already-chosen model entity and instantiates its realtime driver.
|
|
1775
1837
|
*
|
|
1776
|
-
* Key precedence, per driver class:
|
|
1777
|
-
*
|
|
1778
|
-
*
|
|
1838
|
+
* Key precedence, per driver class: the platform's MJ Credential for the model's vendor
|
|
1839
|
+
* (`platform`), then `resolve` (the session's run keys), then this service's
|
|
1840
|
+
* {@link getAPIKeyForDriver} seam, whose default is the environment key — the order a prompt
|
|
1841
|
+
* resolves its key in. Vendor selection and the mint use that one chain, so a session is never
|
|
1842
|
+
* routed to a vendor it cannot then be minted on, nor minted on a different key than selection saw.
|
|
1779
1843
|
*
|
|
1780
1844
|
* @param model The chosen model entity.
|
|
1781
1845
|
* @param resolve The session's run-scoped key resolver. Expected to answer with run keys only:
|
|
@@ -1789,11 +1853,13 @@ export class RealtimeClientSessionService {
|
|
|
1789
1853
|
* other keyed vendor that does is taken, when there is one. So a vendor that renders avatars (Vertex AI for Gemini
|
|
1790
1854
|
* 3.8 Live, with its own billing and limits) takes a session only when it will show an avatar, or when it is the
|
|
1791
1855
|
* only keyed vendor; and a session that will show one goes to such a vendor whatever the Priority order.
|
|
1856
|
+
* @param platform The platform MJ Credentials resolved for the session before selection
|
|
1857
|
+
* ({@link resolvePlatformCredentials}); `None` leaves the run keys and the seam.
|
|
1792
1858
|
* @returns The full resolution, or `null` when no vendor/key/driver can be satisfied.
|
|
1793
1859
|
*/
|
|
1794
|
-
resolveVendorAndInstantiate(model, resolve, credentialScope = 'Any', showsAvatar = false) {
|
|
1795
|
-
const resolveKey = this.buildKeyChain(resolve, credentialScope);
|
|
1796
|
-
const vendor = this.selectRealtimeVendor(model.ID, resolveKey);
|
|
1860
|
+
resolveVendorAndInstantiate(model, resolve, credentialScope = 'Any', showsAvatar = false, platform = RealtimePlatformCredentials.None) {
|
|
1861
|
+
const resolveKey = this.buildKeyChain(resolve, credentialScope, platform, model.ID);
|
|
1862
|
+
const vendor = this.selectRealtimeVendor(model.ID, resolveKey, credentialScope);
|
|
1797
1863
|
const first = vendor ? this.instantiateRealtimeVendor(model, vendor, resolveKey) : null;
|
|
1798
1864
|
if (!vendor || !first) {
|
|
1799
1865
|
return first;
|
|
@@ -1806,15 +1872,18 @@ export class RealtimeClientSessionService {
|
|
|
1806
1872
|
});
|
|
1807
1873
|
}
|
|
1808
1874
|
/**
|
|
1809
|
-
* The session's complete key chain for vendor selection and
|
|
1810
|
-
*
|
|
1811
|
-
*
|
|
1812
|
-
* step: the seam's default is the platform key.
|
|
1875
|
+
* The session's complete key chain for one model's vendor selection and mint (see
|
|
1876
|
+
* {@link resolveVendorAndInstantiate}): the platform's MJ Credential for the model's vendor, then the run's keys, then
|
|
1877
|
+
* this service's own seam (which subclasses and tests override). A scope that rules out the platform's credentials
|
|
1878
|
+
* has no first step, and one that rules out the environment has no last: the seam's default is the platform key.
|
|
1813
1879
|
*/
|
|
1814
|
-
buildKeyChain(resolve, credentialScope) {
|
|
1815
|
-
|
|
1880
|
+
buildKeyChain(resolve, credentialScope, platform = RealtimePlatformCredentials.None, modelID) {
|
|
1881
|
+
const runThenSeam = CredentialScopeAllows(credentialScope, 'Environment')
|
|
1816
1882
|
? (driverClass) => resolve?.(driverClass) ?? this.getAPIKeyForDriver(driverClass)
|
|
1817
1883
|
: (driverClass) => resolve?.(driverClass);
|
|
1884
|
+
return modelID && CredentialScopeAllows(credentialScope, 'PlatformCredential')
|
|
1885
|
+
? platform.ResolverFor(modelID, runThenSeam)
|
|
1886
|
+
: runThenSeam;
|
|
1818
1887
|
}
|
|
1819
1888
|
/** Instantiates a vendor's realtime driver with its key from the chain; `null` when the key or the driver is missing. */
|
|
1820
1889
|
instantiateRealtimeVendor(model, vendor, resolveKey) {
|
|
@@ -1883,10 +1952,11 @@ export class RealtimeClientSessionService {
|
|
|
1883
1952
|
*
|
|
1884
1953
|
* @param modelID The chosen model's id.
|
|
1885
1954
|
* @param resolve The complete key chain to select against; defaults to {@link getAPIKeyForDriver}.
|
|
1955
|
+
* @param credentialScope The session's credential scope (words the log line when no vendor qualifies).
|
|
1886
1956
|
* @returns The vendor driver/api identifiers, or `null` when none has a usable key.
|
|
1887
1957
|
*/
|
|
1888
|
-
selectRealtimeVendor(modelID, resolve) {
|
|
1889
|
-
return SelectRealtimeVendorForModel(modelID, resolve ?? ((driverClass) => this.getAPIKeyForDriver(driverClass)));
|
|
1958
|
+
selectRealtimeVendor(modelID, resolve, credentialScope) {
|
|
1959
|
+
return SelectRealtimeVendorForModel(modelID, resolve ?? ((driverClass) => this.getAPIKeyForDriver(driverClass)), credentialScope);
|
|
1890
1960
|
}
|
|
1891
1961
|
/**
|
|
1892
1962
|
* Resolves the DB-driven progress-narration instruction template: the Active `MJ: AI Prompts`
|
|
@@ -1921,8 +1991,8 @@ export class RealtimeClientSessionService {
|
|
|
1921
1991
|
async buildSessionParams(input, coAgent, modelApiName, contextUser, provider, effectiveConfig, driverClass, modelID, modelVendorID, resolvedAvatar) {
|
|
1922
1992
|
const directTools = this.projectDirectActions(input, effectiveConfig, driverClass);
|
|
1923
1993
|
const hasDirectTools = directTools.length > 0 || (input.ExtraTools != null && input.ExtraTools.length > 0);
|
|
1924
|
-
const systemPrompt = await this.buildCompanionSystemPrompt(input, coAgent, contextUser, provider, effectiveConfig, hasDirectTools);
|
|
1925
1994
|
const memoryContext = await this.assembleMemoryContext(input, coAgent, contextUser, provider);
|
|
1995
|
+
const systemPrompt = await this.buildCompanionSystemPrompt(input, coAgent, contextUser, provider, effectiveConfig, hasDirectTools, memoryContext);
|
|
1926
1996
|
const combinedExtra = directTools.length > 0
|
|
1927
1997
|
? [...(input.ExtraTools ?? []), ...directTools]
|
|
1928
1998
|
: input.ExtraTools;
|
|
@@ -2063,9 +2133,13 @@ export class RealtimeClientSessionService {
|
|
|
2063
2133
|
* @param contextUser The calling user.
|
|
2064
2134
|
* @param provider The request-scoped metadata provider.
|
|
2065
2135
|
* @param effectiveConfig The resolved effective configuration (voice persona source).
|
|
2136
|
+
* @param hasDirectTools Whether direct action/channel tools are projected onto the session.
|
|
2137
|
+
* @param memoryContext The memory/context block when the caller already assembled it (as
|
|
2138
|
+
* {@link buildSessionParams} does); omitted, it is assembled here. Last and optional so overrides
|
|
2139
|
+
* written against the earlier signature (bizapps-caliber's persona seam) keep working.
|
|
2066
2140
|
* @returns The concatenated system prompt (never empty — the framing is always present).
|
|
2067
2141
|
*/
|
|
2068
|
-
async buildCompanionSystemPrompt(input, coAgent, contextUser, provider, effectiveConfig, hasDirectTools = false) {
|
|
2142
|
+
async buildCompanionSystemPrompt(input, coAgent, contextUser, provider, effectiveConfig, hasDirectTools = false, memoryContext) {
|
|
2069
2143
|
const target = this.resolveTargetAgent(input.TargetAgentID);
|
|
2070
2144
|
const targetName = target?.Name ?? 'the configured target agent';
|
|
2071
2145
|
// Identity framing comes from the ONE shared producer (see BuildRealtimeAgentFraming) so the agent
|
|
@@ -2082,8 +2156,8 @@ export class RealtimeClientSessionService {
|
|
|
2082
2156
|
const appContextSection = this.buildAppContextSection(input.AppContext);
|
|
2083
2157
|
const priorTranscript = this.formatPriorTranscript(input.PriorTranscript);
|
|
2084
2158
|
const history = this.formatConversationHistory(input.ConversationMessages);
|
|
2085
|
-
const
|
|
2086
|
-
return [framing, meetingFraming, hostFraming, coAgentPrompt, voiceManner, targetIdentity, appContextSection, priorTranscript, history,
|
|
2159
|
+
const memory = memoryContext ?? await this.assembleMemoryContext(input, coAgent, contextUser, provider);
|
|
2160
|
+
return [framing, meetingFraming, hostFraming, coAgentPrompt, voiceManner, targetIdentity, appContextSection, priorTranscript, history, memory]
|
|
2087
2161
|
.filter(part => part && part.trim().length > 0)
|
|
2088
2162
|
.join('\n\n');
|
|
2089
2163
|
}
|
|
@@ -2733,8 +2807,16 @@ export class RealtimeClientSessionService {
|
|
|
2733
2807
|
* @returns The active action entities assigned to the agent.
|
|
2734
2808
|
*/
|
|
2735
2809
|
getTargetAgentActions(targetAgentID) {
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2810
|
+
const activeActionIds = new Set();
|
|
2811
|
+
for (const aa of AIEngine.Instance.AgentActions ?? []) {
|
|
2812
|
+
if (aa.Status === 'Active' && UUIDsEqual(aa.AgentID, targetAgentID) && aa.ActionID) {
|
|
2813
|
+
activeActionIds.add(NormalizeUUID(aa.ActionID));
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
if (activeActionIds.size === 0) {
|
|
2817
|
+
return [];
|
|
2818
|
+
}
|
|
2819
|
+
return (ActionEngineServer.Instance.Actions ?? []).filter(a => a.Status === 'Active' && activeActionIds.has(NormalizeUUID(a.ID)));
|
|
2738
2820
|
}
|
|
2739
2821
|
/**
|
|
2740
2822
|
* The session's direct-action tools. When the input excludes direct actions, none, and the empty
|
|
@@ -2876,8 +2958,8 @@ export class RealtimeClientSessionService {
|
|
|
2876
2958
|
};
|
|
2877
2959
|
}
|
|
2878
2960
|
const projection = input?.AgentSessionID ? this.sessionWireActionMaps.Get(input.AgentSessionID) : undefined;
|
|
2879
|
-
const
|
|
2880
|
-
|
|
2961
|
+
const action = this.findWireAction(projection, call.ToolName)
|
|
2962
|
+
?? this.findWireAction(this.BuildWireActionMap(this.getTargetAgentActions(target.ID)), call.ToolName);
|
|
2881
2963
|
if (!action) {
|
|
2882
2964
|
return {
|
|
2883
2965
|
CallID: call.CallID,
|
|
@@ -2957,15 +3039,32 @@ export class RealtimeClientSessionService {
|
|
|
2957
3039
|
if (!wireMap) {
|
|
2958
3040
|
return undefined;
|
|
2959
3041
|
}
|
|
3042
|
+
const exact = wireMap.get(toolName);
|
|
3043
|
+
if (exact) {
|
|
3044
|
+
return exact;
|
|
3045
|
+
}
|
|
2960
3046
|
const wanted = toolName.trim().toLowerCase();
|
|
2961
|
-
|
|
3047
|
+
for (const [wireName, action] of wireMap.entries()) {
|
|
3048
|
+
if (wireName.toLowerCase() === wanted) {
|
|
3049
|
+
return action;
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
return undefined;
|
|
2962
3053
|
}
|
|
2963
3054
|
/**
|
|
2964
3055
|
* True when the action is in the session's start-time projection, or when this service holds no
|
|
2965
3056
|
* projection for the session (see {@link executeNonTargetTool} for when that happens).
|
|
2966
3057
|
*/
|
|
2967
3058
|
isInProjection(projection, action) {
|
|
2968
|
-
|
|
3059
|
+
if (!projection) {
|
|
3060
|
+
return true;
|
|
3061
|
+
}
|
|
3062
|
+
for (const projected of projection.values()) {
|
|
3063
|
+
if (UUIDsEqual(projected.ID, action.ID)) {
|
|
3064
|
+
return true;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
return false;
|
|
2969
3068
|
}
|
|
2970
3069
|
/**
|
|
2971
3070
|
* Parses JSON arguments string into a key-value record of parameters.
|
|
@@ -3040,14 +3139,15 @@ export class RealtimeClientSessionService {
|
|
|
3040
3139
|
return { Signal: controller.signal, Dispose: dispose };
|
|
3041
3140
|
}
|
|
3042
3141
|
/**
|
|
3043
|
-
* The
|
|
3142
|
+
* The message returned when no usable Realtime model can be resolved: what is missing and how to
|
|
3143
|
+
* supply it. The server log carries a line per skipped model naming each vendor and what it needed.
|
|
3044
3144
|
*
|
|
3145
|
+
* @param credentialScope The session's credential scope (which key sources could have answered).
|
|
3045
3146
|
* @returns The failure message.
|
|
3046
3147
|
*/
|
|
3047
|
-
noModelMessage() {
|
|
3048
|
-
return ('No usable Realtime model could be resolved for the Realtime Co-Agent
|
|
3049
|
-
|
|
3050
|
-
'(e.g. AI_VENDOR_API_KEY__<driver>).');
|
|
3148
|
+
noModelMessage(credentialScope) {
|
|
3149
|
+
return ('No usable Realtime model could be resolved for the Realtime Co-Agent: no active vendor of an active ' +
|
|
3150
|
+
`model of AIModelType 'Realtime' has a usable key. ${RealtimeKeyFixHint(credentialScope)}`);
|
|
3051
3151
|
}
|
|
3052
3152
|
}
|
|
3053
3153
|
//# sourceMappingURL=realtime-client-session-service.js.map
|