@memberjunction/ai-agents 6.2.0-edge.2 → 6.2.0-edge.4

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.
Files changed (148) hide show
  1. package/README.md +6 -0
  2. package/dist/AgentDecisionService.d.ts +8 -1
  3. package/dist/AgentDecisionService.d.ts.map +1 -1
  4. package/dist/AgentDecisionService.js +4 -0
  5. package/dist/AgentDecisionService.js.map +1 -1
  6. package/dist/AgentRunner.d.ts +51 -2
  7. package/dist/AgentRunner.d.ts.map +1 -1
  8. package/dist/AgentRunner.js +121 -23
  9. package/dist/AgentRunner.js.map +1 -1
  10. package/dist/ConversationCompactionManager.d.ts +9 -1
  11. package/dist/ConversationCompactionManager.d.ts.map +1 -1
  12. package/dist/ConversationCompactionManager.js +6 -3
  13. package/dist/ConversationCompactionManager.js.map +1 -1
  14. package/dist/ConversationToolManager.d.ts +13 -2
  15. package/dist/ConversationToolManager.d.ts.map +1 -1
  16. package/dist/ConversationToolManager.js +19 -3
  17. package/dist/ConversationToolManager.js.map +1 -1
  18. package/dist/KnowledgeAgent.d.ts.map +1 -1
  19. package/dist/KnowledgeAgent.js +6 -1
  20. package/dist/KnowledgeAgent.js.map +1 -1
  21. package/dist/MJAIAgentRequestEntityServer.d.ts +6 -0
  22. package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
  23. package/dist/MJAIAgentRequestEntityServer.js +26 -1
  24. package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
  25. package/dist/PayloadFeedbackManager.d.ts +3 -0
  26. package/dist/PayloadFeedbackManager.d.ts.map +1 -1
  27. package/dist/PayloadFeedbackManager.js +2 -1
  28. package/dist/PayloadFeedbackManager.js.map +1 -1
  29. package/dist/agent-run-watchdog.d.ts +65 -5
  30. package/dist/agent-run-watchdog.d.ts.map +1 -1
  31. package/dist/agent-run-watchdog.js +143 -28
  32. package/dist/agent-run-watchdog.js.map +1 -1
  33. package/dist/agent-types/loop-agent-prompt-params.d.ts +7 -0
  34. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  35. package/dist/agent-types/loop-agent-prompt-params.js +1 -0
  36. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  37. package/dist/agent-types/loop-agent-type.d.ts +20 -0
  38. package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
  39. package/dist/agent-types/loop-agent-type.js +73 -2
  40. package/dist/agent-types/loop-agent-type.js.map +1 -1
  41. package/dist/artifact-tools/SearchResultSetToolLibrary.js +4 -4
  42. package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
  43. package/dist/base-agent.d.ts +310 -26
  44. package/dist/base-agent.d.ts.map +1 -1
  45. package/dist/base-agent.js +867 -244
  46. package/dist/base-agent.js.map +1 -1
  47. package/dist/client-tool-results.d.ts +45 -0
  48. package/dist/client-tool-results.d.ts.map +1 -0
  49. package/dist/client-tool-results.js +94 -0
  50. package/dist/client-tool-results.js.map +1 -0
  51. package/dist/index.d.ts +9 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +9 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/native-tools/action-tool-builder.d.ts +14 -0
  56. package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
  57. package/dist/native-tools/action-tool-builder.js +62 -7
  58. package/dist/native-tools/action-tool-builder.js.map +1 -1
  59. package/dist/native-tools/control-tools.d.ts +17 -1
  60. package/dist/native-tools/control-tools.d.ts.map +1 -1
  61. package/dist/native-tools/control-tools.js +40 -3
  62. package/dist/native-tools/control-tools.js.map +1 -1
  63. package/dist/prior-turn-tool-result-cache.d.ts +31 -12
  64. package/dist/prior-turn-tool-result-cache.d.ts.map +1 -1
  65. package/dist/prior-turn-tool-result-cache.js +59 -16
  66. package/dist/prior-turn-tool-result-cache.js.map +1 -1
  67. package/dist/realtime/bridge-host-params.d.ts +22 -0
  68. package/dist/realtime/bridge-host-params.d.ts.map +1 -0
  69. package/dist/realtime/bridge-host-params.js +53 -0
  70. package/dist/realtime/bridge-host-params.js.map +1 -0
  71. package/dist/realtime/bridge-realtime-session-factory.d.ts +63 -3
  72. package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
  73. package/dist/realtime/bridge-realtime-session-factory.js +83 -22
  74. package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
  75. package/dist/realtime/bridge-realtime-usage-recorder.d.ts +81 -0
  76. package/dist/realtime/bridge-realtime-usage-recorder.d.ts.map +1 -0
  77. package/dist/realtime/bridge-realtime-usage-recorder.js +194 -0
  78. package/dist/realtime/bridge-realtime-usage-recorder.js.map +1 -0
  79. package/dist/realtime/bridge-session-transcript-sink.d.ts +37 -0
  80. package/dist/realtime/bridge-session-transcript-sink.d.ts.map +1 -0
  81. package/dist/realtime/bridge-session-transcript-sink.js +58 -0
  82. package/dist/realtime/bridge-session-transcript-sink.js.map +1 -0
  83. package/dist/realtime/client-only-channel-server.d.ts +83 -0
  84. package/dist/realtime/client-only-channel-server.d.ts.map +1 -0
  85. package/dist/realtime/client-only-channel-server.js +107 -0
  86. package/dist/realtime/client-only-channel-server.js.map +1 -0
  87. package/dist/realtime/identity-verification-channel-server.d.ts +50 -0
  88. package/dist/realtime/identity-verification-channel-server.d.ts.map +1 -0
  89. package/dist/realtime/identity-verification-channel-server.js +66 -0
  90. package/dist/realtime/identity-verification-channel-server.js.map +1 -0
  91. package/dist/realtime/interactive-component-channel-server.d.ts +39 -0
  92. package/dist/realtime/interactive-component-channel-server.d.ts.map +1 -0
  93. package/dist/realtime/interactive-component-channel-server.js +55 -0
  94. package/dist/realtime/interactive-component-channel-server.js.map +1 -0
  95. package/dist/realtime/realtime-avatar-resolution.d.ts +194 -0
  96. package/dist/realtime/realtime-avatar-resolution.d.ts.map +1 -0
  97. package/dist/realtime/realtime-avatar-resolution.js +208 -0
  98. package/dist/realtime/realtime-avatar-resolution.js.map +1 -0
  99. package/dist/realtime/realtime-channel-policy.d.ts +81 -0
  100. package/dist/realtime/realtime-channel-policy.d.ts.map +1 -0
  101. package/dist/realtime/realtime-channel-policy.js +91 -0
  102. package/dist/realtime/realtime-channel-policy.js.map +1 -0
  103. package/dist/realtime/realtime-channel-server-host.d.ts +14 -0
  104. package/dist/realtime/realtime-channel-server-host.d.ts.map +1 -1
  105. package/dist/realtime/realtime-channel-server-host.js +35 -0
  106. package/dist/realtime/realtime-channel-server-host.js.map +1 -1
  107. package/dist/realtime/realtime-client-session-service.d.ts +493 -30
  108. package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
  109. package/dist/realtime/realtime-client-session-service.js +825 -98
  110. package/dist/realtime/realtime-client-session-service.js.map +1 -1
  111. package/dist/realtime/realtime-coagent-config.d.ts +94 -15
  112. package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
  113. package/dist/realtime/realtime-coagent-config.js +109 -4
  114. package/dist/realtime/realtime-coagent-config.js.map +1 -1
  115. package/dist/realtime/realtime-coagent-resolution.d.ts +90 -0
  116. package/dist/realtime/realtime-coagent-resolution.d.ts.map +1 -0
  117. package/dist/realtime/realtime-coagent-resolution.js +186 -0
  118. package/dist/realtime/realtime-coagent-resolution.js.map +1 -0
  119. package/dist/realtime/realtime-delegation-narrator.d.ts +97 -0
  120. package/dist/realtime/realtime-delegation-narrator.d.ts.map +1 -0
  121. package/dist/realtime/realtime-delegation-narrator.js +162 -0
  122. package/dist/realtime/realtime-delegation-narrator.js.map +1 -0
  123. package/dist/realtime/realtime-recording-store.d.ts +136 -16
  124. package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
  125. package/dist/realtime/realtime-recording-store.js +505 -39
  126. package/dist/realtime/realtime-recording-store.js.map +1 -1
  127. package/dist/realtime/realtime-session-runner.d.ts +2 -82
  128. package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
  129. package/dist/realtime/realtime-session-runner.js +16 -191
  130. package/dist/realtime/realtime-session-runner.js.map +1 -1
  131. package/dist/realtime/realtime-vendor-resolution.d.ts +9 -0
  132. package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
  133. package/dist/realtime/realtime-vendor-resolution.js +16 -5
  134. package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
  135. package/dist/realtime/realtime-video-output-gate.d.ts +83 -0
  136. package/dist/realtime/realtime-video-output-gate.d.ts.map +1 -0
  137. package/dist/realtime/realtime-video-output-gate.js +79 -0
  138. package/dist/realtime/realtime-video-output-gate.js.map +1 -0
  139. package/dist/rubric-evaluation-agent-runner.js +17 -8
  140. package/dist/rubric-evaluation-agent-runner.js.map +1 -1
  141. package/dist/self-check.d.ts +6 -3
  142. package/dist/self-check.d.ts.map +1 -1
  143. package/dist/self-check.js +3 -3
  144. package/dist/self-check.js.map +1 -1
  145. package/dist/tool-result-format.d.ts +14 -0
  146. package/dist/tool-result-format.d.ts.map +1 -1
  147. package/dist/tool-result-format.js.map +1 -1
  148. package/package.json +19 -19
package/README.md CHANGED
@@ -240,6 +240,12 @@ Key pieces in this package:
240
240
  - **`MediaChannelServer`** (`src/realtime/media-channel-server.ts`, key `'MediaChannelServer'`) — the server channel plugin for the **Media** surface. Like the Whiteboard it canonicalizes the channel's persisted media state, and additionally resolves the agent's **media kit** at session start: it implements `IRealtimeChannelServerDataAware` to receive the session `contextUser`+`provider`, reads a per-session `mediaCollectionID` override out of `RealtimeChannelServerContext.AgentSessionConfig` (the persisted `AIAgentSession.Config_`), and feeds the model a manifest via `SendContextNote`. The kit-resolution logic is the pure, unit-tested `agent-media-library.ts` (`buildAgentMediaContextNote` / `resolveAgentMediaManifest` / `formatAgentMediaManifest`); precedence is `runtime override > AIAgent.DefaultMediaCollectionID > none`. The agent then surfaces items with the existing `Media_ShowMedia` client tool — no new client tool. `LoadMediaChannelServer()` is invoked from MJServer's `agentSessions` module. See the [Real-Time Co-Agents Guide](../../../guides/REALTIME_CO_AGENTS_GUIDE.md).
241
241
  - **`AgentMemoryContextBuilder`** (`src/agent-memory-context-builder.ts`) — the memory/RAG injection orchestration extracted out of `BaseAgent` so the co-agent assembles the **same** notes/examples/context a loop agent does, with no duplicated logic.
242
242
 
243
+ - **`realtime-channel-policy.ts`** (`BuildSessionChannelPolicy`) — the **server half of channel scoping** for client-direct sessions, pure and unit-tested. At mint the browser reports its channel candidates (`channelCandidatesJson`); `RealtimeClientSessionService` matches each to its `MJ: AI Agent Channels` row *from the server's own registry* (the client's view is never trusted), folds the cascade's `realtime.channels` section (agent layers plus `Application.AgentSettings.Realtime.Channels`) through `ResolveRealtimeChannelScope`, and returns the resolved `RealtimeSessionClientPolicy` (`PrepareClientSession` → `ClientPolicy`; the resolver returns it as `ClientPolicyJson` and persists the in-scope channel keys on the session). The tools the model is told about are narrowed to match: a vetoed channel's native tools never reach the provider, an included `'opt-in'` channel's are added by name, an `'on-demand'` channel declares none (it is opened through `ContextTool`), and tools no candidate owns (the host's own) pass through. Server plugins start before the scope is known, so `RealtimeChannelServerHost.PruneSessionChannels` drops the excluded channels' server halves afterwards. Absent candidates (a client that predates scoping, or a host that mints through its own proxy) ⇒ tools used exactly as declared and no policy.
244
+ - **`ClientOnlyChannelServer`** (`src/realtime/client-only-channel-server.ts`, key `'ClientOnlyChannelServer'`) — the generic server half for any channel that runs entirely in the browser. `MJ: AI Agent Channels.ServerPluginClass` is `NOT NULL`, so a client-only channel (an Open App's form or game channel) sets its row's `ServerPluginClass` to this key instead of writing an empty plugin. It takes its channel name from the registry row it was resolved for (`BindChannelName`, called by `RealtimeChannelServerHost`), contributes no server tools and does not interpret or rewrite saves. It does not decide scope (resolved before any plugin exists) and cannot stop a save (the host persists whatever the client submits when a plugin returns `null`), so persistence is controlled by the client plugin's `SerializeState()`. `LoadClientOnlyChannelServer()` is invoked from MJServer's `agentSessions` module.
245
+ - **`InteractiveComponentChannelServer`** (`src/realtime/interactive-component-channel-server.ts`, key `'InteractiveComponentChannelServer'`) — the deliberately thin server half of the **Interactive Component** channel (`MJ: AI Agent Channels` row `InteractiveComponent`), a `ClientOnlyChannelServer` subclass that keeps its existing registry key: no server tools, and the client plugin saves no state of record, because the channel's actions are derived from the open component's spec and run in the browser. `LoadInteractiveComponentChannelServer()` is invoked from MJServer's `agentSessions` module.
246
+ - **Channel exposure and zero data retention.** `BuildSessionChannelPolicy` also resolves each channel's **exposure** (`min(channel ceiling, agent cap, zero-data-retention ceiling)`; the user's own choice is applied by the browser). The agent cap is `realtime.channels.config.<Key>.maxExposure`; `requireZeroDataRetentionFor: ['state' | 'pixels']` (in the realtime configuration cascade and in `Application.AgentSettings.Realtime.Channels.RequireZeroDataRetentionFor`) lowers exposure when the session model's effective configuration (`AIEngine.GetEffectiveModelConfiguration`) does not declare `Privacy.ZeroDataRetention: true`; a failed model lookup fails closed. The resolved exposure and the reasons for any downgrade ride back in `ClientPolicyJson`. Also in the realtime session tuning section: `session.unverifiedMaxSeconds` / `session.verifiedMaxSeconds` (positive integers, carried through the cascade for the session-deadline logic; never forwarded to the provider driver).
247
+ - **App client tools and the unified resolver.** `Application.AgentSettings.ClientTools` is now actually read by the realtime path: resolved against the tool-definition catalog and layered, through `ResolveClientTools` (`override → session → app → static`), beneath the live surface's manifest in the app-context snapshot the companion prompt renders. The agent's static `MJ: AI Agent Client Tools` junction tools ride the returned policy (so the browser can describe them) but are deliberately not added to the voice prompt — voice prompts are token-sensitive and a tool with no browser handler is noise. The app's `AgentSettings` column is parsed with `ParseAgentSettings` rather than the generated accessor.
248
+
243
249
  Delegated runs link to the co-agent's run via `ParentRunID` and share the session's `AgentSessionID`, so the whole episode — session, co-agent run (with its prompt run + Timeline step), delegated runs, transcript (`ConversationDetail` rows), channel state, usage telemetry (checkpointed server-side, or relayed from the browser via `RelayRealtimeUsage`) — groups under one session record with full standard observability.
244
250
 
245
251
  The browser-side driver layer lives in [`@memberjunction/ai-realtime-client`](../RealtimeClient/README.md); the model primitive (`BaseRealtimeModel` / `IRealtimeSession`) lives in `@memberjunction/ai`; the Angular UX (call overlay, interactive channels, the live whiteboard) lives in `@memberjunction/ng-conversations`. **The flagship guide — concept, triple-registry plugin architecture, topologies, session lifecycle, channels, narration, security — is [guides/REALTIME_CO_AGENTS_GUIDE.md](../../../guides/REALTIME_CO_AGENTS_GUIDE.md).**
@@ -10,7 +10,7 @@
10
10
  import { UserInfo } from '@memberjunction/core';
11
11
  import { DecisionQuestion, DecisionAnswer } from '@memberjunction/ai';
12
12
  import { AIDecisionRunResult } from '@memberjunction/ai-prompts';
13
- import { AgentDecisionAnswerSummary } from '@memberjunction/ai-core-plus';
13
+ import { AgentDecisionAnswerSummary, type AIPromptExecutionScope } from '@memberjunction/ai-core-plus';
14
14
  /**
15
15
  * Parameters for the AgentDecisionService.Ask method.
16
16
  */
@@ -35,6 +35,13 @@ export interface AgentDecisionAskParams {
35
35
  * Optional prompt name to resolve from AIEngine. Defaults to 'Default Decision'.
36
36
  */
37
37
  PromptName?: string;
38
+ /**
39
+ * The asking run's execution scope — its configuration, runtime API keys and credential scope.
40
+ * Without it a decision resolves no run key and, under the default scope, answers on the
41
+ * platform's keys inside a customer's run; under `'RuntimeOnly'` that is exactly what must not
42
+ * happen. `ContextUser` still names the user.
43
+ */
44
+ ExecutionScope?: AIPromptExecutionScope;
38
45
  /**
39
46
  * Optional cancellation token to abort execution.
40
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AgentDecisionService.d.ts","sourceRoot":"","sources":["../src/AgentDecisionService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAsC,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAExC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gB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EAAE,0BAA0B,CAAC;CAyBtH"}
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { AIEngine } from '@memberjunction/aiengine';
11
11
  import { AIDecisionRunner, AIDecisionParams } from '@memberjunction/ai-prompts';
12
+ import { PickPromptExecutionScope } from '@memberjunction/ai-core-plus';
12
13
  /** A plain object, as opposed to null, an array or a primitive. */
13
14
  function isPlainObject(value) {
14
15
  return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -49,6 +50,9 @@ export class AgentDecisionService {
49
50
  };
50
51
  }
51
52
  const params = new AIDecisionParams();
53
+ if (args.ExecutionScope) {
54
+ Object.assign(params, PickPromptExecutionScope(args.ExecutionScope));
55
+ }
52
56
  params.prompt = prompt;
53
57
  params.contextUser = args.ContextUser;
54
58
  params.State = args.State;
@@ -1 +1 @@
1
- {"version":3,"file":"AgentDecisionService.js","sourceRoot":"","sources":["../src/AgentDecisionService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAuB,MAAM,4BAA4B,CAAC;AAkDrG,mEAAmE;AACnE,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,gDAAgD;AAChD,SAAS,SAAS,CAAI,KAAc,EAAE,KAAmC;IACrE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC5B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AAED,+DAA+D;AAC/D,SAAS,cAAc,CAAC,KAAc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ryArtifact(fileArtifacts: readonly CreatedArt
51
51
  * ```
52
52
  */
53
53
  export declare class AgentRunner {
54
+ /**
55
+ * The status and message the agent's reply detail ends with, from the run's result.
56
+ *
57
+ * A run the user stopped is not an error: its reply is marked Complete with a short "stopped"
58
+ * message, so the chat shows a quiet end rather than a red failure, and the run row (Cancelled,
59
+ * with its reason and the payload as it stood) carries the detail. Every other outcome keeps the
60
+ * long-standing mapping: the run's message when it wrote one, else Completed or the error.
61
+ */
62
+ static ResolveFinalDetailState(agentResult: ExecuteAgentResult): {
63
+ Status: 'Complete' | 'Error';
64
+ Message: string;
65
+ };
54
66
  /**
55
67
  * Why a conversation-detail `Save()` returned false, for an error or log line. The owner gate in
56
68
  * `MJConversationDetailEntityExtended` refuses a non-owner's write (e.g. the elevated System user
@@ -202,6 +214,34 @@ export declare class AgentRunner {
202
214
  versionId: string;
203
215
  versionNumber: number;
204
216
  }>;
217
+ /**
218
+ * Gives the current reply an existing artifact version whose content equals the new payload.
219
+ * The reply gets an `Output` link to that version (unless it already has one), which makes the
220
+ * version visible on the reply's branch path, and the result is the same tuple the normal
221
+ * version-creation path returns. When the link-exists read fails, no link is written and the
222
+ * result is `undefined`, so a failed read never adds a second link for the same pair.
223
+ *
224
+ * @param versionId - The existing version with identical content
225
+ * @param conversationDetailId - The reply row to link the version to
226
+ * @param artifactId - The parent artifact ID
227
+ * @param versionNumber - The existing version's number
228
+ * @param contextUser - User context for the read and the save
229
+ * @param provider - Metadata provider for the read and the save
230
+ * @returns The standard artifact result tuple for the existing version, or `undefined` when
231
+ * the link-exists read failed
232
+ */
233
+ private reuseVersionForReply;
234
+ /**
235
+ * Checks whether a conversation detail already has an `Output` link to an artifact version.
236
+ * A failed read is logged and returns `null`.
237
+ *
238
+ * @param conversationDetailId - The conversation detail to check
239
+ * @param versionId - The artifact version to look for
240
+ * @param contextUser - User context for the read
241
+ * @param provider - Metadata provider for the read
242
+ * @returns `true` when the link exists, `false` when it does not, `null` when the read failed
243
+ */
244
+ private hasOutputLink;
205
245
  /**
206
246
  * Finds the most recent artifact for a conversation detail to determine versioning.
207
247
  * Queries the junction table to locate artifacts linked to a specific conversation message.
@@ -240,6 +280,11 @@ export declare class AgentRunner {
240
280
  * 3. If previous artifact exists, creates new version of it
241
281
  * 4. If no previous artifact, creates entirely new artifact
242
282
  *
283
+ * When the payload equals the version a new one would follow, no version is created. Inside a
284
+ * conversation that existing version is linked to the reply (an `Output` link, unless one
285
+ * exists) and returned; if the link-exists read fails, nothing is written and the method returns
286
+ * `undefined`. Outside a conversation the method returns `undefined`.
287
+ *
243
288
  * Respects the agent's ArtifactCreationMode configuration:
244
289
  * - "Never": Skips artifact creation entirely
245
290
  * - "System Only": Creates artifact with Visibility='System Only'
@@ -402,6 +447,8 @@ export declare class AgentRunner {
402
447
  *
403
448
  * @param userMessage - The first user message to base the name on
404
449
  * @param contextUser - User context for prompt execution
450
+ * @param credentials - The run's configuration, runtime keys and credential scope, so naming runs
451
+ * on the same credentials as the agent run it names
405
452
  * @returns Generated conversation name and description, or null if generation failed
406
453
  * @private
407
454
  */
@@ -578,12 +625,14 @@ export declare class AgentRunner {
578
625
  */
579
626
  private resolveConversationId;
580
627
  /**
581
- * Gathers all artifacts from a conversation (both artifact-system records and
582
- * uploaded file attachments) so the ArtifactToolManager can make them available
628
+ * Gathers the artifacts on the run's branch path of a conversation (both artifact-system
629
+ * records and uploaded file attachments) so the ArtifactToolManager can make them available
583
630
  * to the agent as input artifacts.
584
631
  *
585
632
  * @param historyFrom The run's history floor (`ExecuteAgentParams.ConversationHistoryFrom`).
586
633
  * When set, only artifacts attached to messages written at or after it are gathered.
634
+ * @param branchId The run's branch; only artifacts of messages on its path that no rerun
635
+ * replaced are gathered.
587
636
  */
588
637
  private gatherConversationArtifacts;
589
638
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AgentRunner.d.ts","sourceRoot":"","sources":["../src/AgentRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAA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yC5C"}
@@ -53,6 +53,28 @@ export function selectPrimaryArtifact(fileArtifacts, payloadArtifact) {
53
53
  * ```
54
54
  */
55
55
  export class AgentRunner {
56
+ /**
57
+ * The status and message the agent's reply detail ends with, from the run's result.
58
+ *
59
+ * A run the user stopped is not an error: its reply is marked Complete with a short "stopped"
60
+ * message, so the chat shows a quiet end rather than a red failure, and the run row (Cancelled,
61
+ * with its reason and the payload as it stood) carries the detail. Every other outcome keeps the
62
+ * long-standing mapping: the run's message when it wrote one, else Completed or the error.
63
+ */
64
+ static ResolveFinalDetailState(agentResult) {
65
+ const run = agentResult.agentRun;
66
+ if (run?.Status === 'Cancelled') {
67
+ const byUser = run.CancellationReason === 'User Request';
68
+ return {
69
+ Status: 'Complete',
70
+ Message: byUser ? 'Stopped by user' : `Stopped: ${run.ErrorMessage || 'the run was cancelled'}`,
71
+ };
72
+ }
73
+ return {
74
+ Status: agentResult.success ? 'Complete' : 'Error',
75
+ Message: run?.Message || (agentResult.success ? '✅ Completed' : run?.ErrorMessage || '❌ Failed'),
76
+ };
77
+ }
56
78
  /**
57
79
  * Why a conversation-detail `Save()` returned false, for an error or log line. The owner gate in
58
80
  * `MJConversationDetailEntityExtended` refuses a non-owner's write (e.g. the elevated System user
@@ -225,7 +247,7 @@ export class AgentRunner {
225
247
  let conversationDescription = null;
226
248
  if (!conversationName && options.userMessage) {
227
249
  // Try to generate a name using the "Name Conversation" prompt (same as UI)
228
- const nameResult = await this.generateConversationName(options.userMessage, contextUser, md);
250
+ const nameResult = await this.generateConversationName(options.userMessage, contextUser, md, params);
229
251
  if (nameResult) {
230
252
  conversationName = nameResult.name;
231
253
  conversationDescription = nameResult.description;
@@ -257,6 +279,7 @@ export class AgentRunner {
257
279
  userMessageDetail.Role = 'User';
258
280
  userMessageDetail.UserID = contextUser.ID;
259
281
  userMessageDetail.HiddenToUser = false;
282
+ userMessageDetail.BranchID = params.ConversationBranchID ?? null;
260
283
  // Link to test run if provided (for test execution traceability)
261
284
  if (options.testRunId) {
262
285
  userMessageDetail.TestRunID = options.testRunId;
@@ -275,6 +298,7 @@ export class AgentRunner {
275
298
  agentResponseDetail.Status = 'In-Progress';
276
299
  agentResponseDetail.HiddenToUser = false;
277
300
  agentResponseDetail.AgentID = params.agent.ID;
301
+ agentResponseDetail.BranchID = params.ConversationBranchID ?? null;
278
302
  // Link to test run if provided (for test execution traceability)
279
303
  if (options.testRunId) {
280
304
  agentResponseDetail.TestRunID = options.testRunId;
@@ -317,12 +341,14 @@ export class AgentRunner {
317
341
  }
318
342
  }
319
343
  : originalOnProgress;
320
- // Gather all artifacts from this conversation for the ArtifactToolManager.
344
+ // The run reads the branch the caller named, else the branch its reply row carries. Undefined is Main.
345
+ const runBranchId = params.ConversationBranchID ?? agentResponseDetail?.BranchID ?? undefined;
346
+ // Gather all artifacts on the run's branch path of this conversation for the ArtifactToolManager.
321
347
  // Per design doc Section 8.8: in the in-conversation flow, "the agent continues
322
348
  // the conversation with the artifact already available." This means ALL artifacts
323
- // in the conversation (both agent-produced Output and user-attached Input) should
349
+ // on that path (both agent-produced Output and user-attached Input) should
324
350
  // be available to the agent via artifact tools.
325
- const inputArtifacts = await this.gatherConversationArtifacts(conversationId, contextUser, params.ConversationHistoryFrom);
351
+ const inputArtifacts = await this.gatherConversationArtifacts(conversationId, contextUser, params.ConversationHistoryFrom, runBranchId);
326
352
  const modifiedParams = {
327
353
  ...params,
328
354
  // First-class conversationId gates the cross-turn context features
@@ -339,6 +365,7 @@ export class AgentRunner {
339
365
  // (BaseAgent tests `inputArtifacts?.length`, so [] and undefined behave identically there.)
340
366
  inputArtifacts,
341
367
  conversationDetailId: agentResponseDetailId,
368
+ ...(runBranchId !== undefined ? { ConversationBranchID: runBranchId } : {}),
342
369
  onProgress: wrappedOnProgress
343
370
  };
344
371
  // Returning-visitor memory (RV3): for a public web-widget guest with remembering on, derive the
@@ -379,11 +406,9 @@ export class AgentRunner {
379
406
  if (!loaded) {
380
407
  LogError(`Failed to reload agent response detail ${agentResponseDetailId}`);
381
408
  }
382
- agentResponseDetail.Message = agentResult.agentRun?.Message ||
383
- (agentResult.success
384
- ? '✅ Completed'
385
- : agentResult.agentRun?.ErrorMessage || '❌ Failed');
386
- agentResponseDetail.Status = agentResult.success ? 'Complete' : 'Error';
409
+ const finalState = AgentRunner.ResolveFinalDetailState(agentResult);
410
+ agentResponseDetail.Message = finalState.Message;
411
+ agentResponseDetail.Status = finalState.Status;
387
412
  // Set response form and command fields
388
413
  if (agentResult.responseForm) {
389
414
  agentResponseDetail.ResponseForm = JSON.stringify(agentResult.responseForm);
@@ -536,6 +561,7 @@ export class AgentRunner {
536
561
  async GetMaxVersionForArtifact(artifactId, contextUser, provider) {
537
562
  try {
538
563
  const rv = RunView.FromMetadataProvider(provider || this._provider);
564
+ // conversation-scope: artifact-wide read; version numbers are unique per artifact across every path
539
565
  const result = await rv.RunView({
540
566
  EntityName: 'MJ: Artifact Versions',
541
567
  ExtraFilter: `ArtifactID='${AgentRunner.filterId(artifactId, 'GetMaxVersionForArtifact artifactId')}'`,
@@ -582,6 +608,7 @@ export class AgentRunner {
582
608
  return null;
583
609
  }
584
610
  const rv = RunView.FromMetadataProvider(provider || this._provider);
611
+ // conversation-scope: artifact-wide read; compares with the artifact's latest version number, which is global
585
612
  const result = await rv.RunView({
586
613
  EntityName: 'MJ: Artifact Versions',
587
614
  ExtraFilter: `ArtifactID='${AgentRunner.filterId(artifactId, 'CheckForDuplicateVersion artifactId')}' AND VersionNumber=${latestVersion}`,
@@ -620,6 +647,60 @@ export class AgentRunner {
620
647
  LogStatus(`Linked artifact to conversation detail ${conversationDetailId}`);
621
648
  return { artifactId, versionId, versionNumber };
622
649
  }
650
+ /**
651
+ * Gives the current reply an existing artifact version whose content equals the new payload.
652
+ * The reply gets an `Output` link to that version (unless it already has one), which makes the
653
+ * version visible on the reply's branch path, and the result is the same tuple the normal
654
+ * version-creation path returns. When the link-exists read fails, no link is written and the
655
+ * result is `undefined`, so a failed read never adds a second link for the same pair.
656
+ *
657
+ * @param versionId - The existing version with identical content
658
+ * @param conversationDetailId - The reply row to link the version to
659
+ * @param artifactId - The parent artifact ID
660
+ * @param versionNumber - The existing version's number
661
+ * @param contextUser - User context for the read and the save
662
+ * @param provider - Metadata provider for the read and the save
663
+ * @returns The standard artifact result tuple for the existing version, or `undefined` when
664
+ * the link-exists read failed
665
+ */
666
+ async reuseVersionForReply(versionId, conversationDetailId, artifactId, versionNumber, contextUser, provider) {
667
+ LogStatus(`Reusing version ${versionNumber} of artifact ${artifactId} for this reply (identical content)`);
668
+ const linkExists = await this.hasOutputLink(conversationDetailId, versionId, contextUser, provider);
669
+ if (linkExists === null) {
670
+ return undefined;
671
+ }
672
+ if (linkExists) {
673
+ return { artifactId, versionId, versionNumber };
674
+ }
675
+ return this.LinkArtifactToConversationDetail(versionId, conversationDetailId, artifactId, versionNumber, contextUser, provider);
676
+ }
677
+ /**
678
+ * Checks whether a conversation detail already has an `Output` link to an artifact version.
679
+ * A failed read is logged and returns `null`.
680
+ *
681
+ * @param conversationDetailId - The conversation detail to check
682
+ * @param versionId - The artifact version to look for
683
+ * @param contextUser - User context for the read
684
+ * @param provider - Metadata provider for the read
685
+ * @returns `true` when the link exists, `false` when it does not, `null` when the read failed
686
+ */
687
+ async hasOutputLink(conversationDetailId, versionId, contextUser, provider) {
688
+ const rv = RunView.FromMetadataProvider(provider);
689
+ const result = await rv.RunView({
690
+ EntityName: 'MJ: Conversation Detail Artifacts',
691
+ ExtraFilter: `ConversationDetailID='${AgentRunner.filterId(conversationDetailId, 'hasOutputLink conversationDetailId')}' ` +
692
+ `AND ArtifactVersionID='${AgentRunner.filterId(versionId, 'hasOutputLink versionId')}' AND Direction='Output'`,
693
+ Fields: ['ID'],
694
+ MaxRows: 1,
695
+ ResultType: 'simple'
696
+ }, contextUser);
697
+ if (!result.Success) {
698
+ LogError(`Could not check for an existing artifact link on conversation detail ${conversationDetailId} ` +
699
+ `(no link written): ${result.ErrorMessage}`);
700
+ return null;
701
+ }
702
+ return result.Results.length > 0;
703
+ }
623
704
  /**
624
705
  * Finds the most recent artifact for a conversation detail to determine versioning.
625
706
  * Queries the junction table to locate artifacts linked to a specific conversation message.
@@ -683,6 +764,11 @@ export class AgentRunner {
683
764
  * 3. If previous artifact exists, creates new version of it
684
765
  * 4. If no previous artifact, creates entirely new artifact
685
766
  *
767
+ * When the payload equals the version a new one would follow, no version is created. Inside a
768
+ * conversation that existing version is linked to the reply (an `Output` link, unless one
769
+ * exists) and returned; if the link-exists read fails, nothing is written and the method returns
770
+ * `undefined`. Outside a conversation the method returns `undefined`.
771
+ *
686
772
  * Respects the agent's ArtifactCreationMode configuration:
687
773
  * - "Never": Skips artifact creation entirely
688
774
  * - "System Only": Creates artifact with Visibility='System Only'
@@ -809,12 +895,17 @@ export class AgentRunner {
809
895
  }
810
896
  // Serialize the payload once — used for both dedup check and version creation
811
897
  const serializedContent = JSON.stringify(payload, null, 2);
812
- // Skip version creation if content is identical to the latest version
898
+ // Identical content creates no new version. Inside a conversation the existing version
899
+ // is linked to this reply instead; outside one there is nothing to link.
813
900
  if (!isNewArtifact && newVersionNumber > 1) {
814
- const existingVersionId = await this.CheckForDuplicateVersion(artifactId, serializedContent, newVersionNumber - 1, contextUser, provider);
901
+ const latestVersionNumber = newVersionNumber - 1;
902
+ const existingVersionId = await this.CheckForDuplicateVersion(artifactId, serializedContent, latestVersionNumber, contextUser, provider);
815
903
  if (existingVersionId) {
816
- console.debug(`Skipping duplicate artifact version — content identical to version ${newVersionNumber - 1}`);
817
- return undefined;
904
+ if (!conversationDetailId) {
905
+ console.debug(`Skipping duplicate artifact version — content identical to version ${latestVersionNumber}`);
906
+ return undefined;
907
+ }
908
+ return await this.reuseVersionForReply(existingVersionId, conversationDetailId, artifactId, latestVersionNumber, contextUser, md);
818
909
  }
819
910
  }
820
911
  // Create artifact version with content
@@ -1086,10 +1177,12 @@ export class AgentRunner {
1086
1177
  *
1087
1178
  * @param userMessage - The first user message to base the name on
1088
1179
  * @param contextUser - User context for prompt execution
1180
+ * @param credentials - The run's configuration, runtime keys and credential scope, so naming runs
1181
+ * on the same credentials as the agent run it names
1089
1182
  * @returns Generated conversation name and description, or null if generation failed
1090
1183
  * @private
1091
1184
  */
1092
- async generateConversationName(userMessage, contextUser, provider) {
1185
+ async generateConversationName(userMessage, contextUser, provider, credentials) {
1093
1186
  try {
1094
1187
  // Import AIPromptRunner, AIPromptParams, and AIEngine
1095
1188
  const { AIPromptRunner } = await import('@memberjunction/ai-prompts');
@@ -1110,6 +1203,9 @@ export class AgentRunner {
1110
1203
  promptParams.UserID = ResolvePromptRunUserID({ ContextUser: contextUser }) ?? undefined;
1111
1204
  promptParams.conversationMessages = [{ role: 'user', content: userMessage }];
1112
1205
  promptParams.provider = provider || this._provider;
1206
+ promptParams.configurationId = credentials?.configurationId;
1207
+ promptParams.apiKeys = credentials?.apiKeys;
1208
+ promptParams.CredentialScope = credentials?.CredentialScope;
1113
1209
  const runner = new AIPromptRunner();
1114
1210
  const result = await runner.ExecutePrompt(promptParams);
1115
1211
  if (result && result.success && result.result) {
@@ -1660,7 +1756,7 @@ export class AgentRunner {
1660
1756
  if (!conversationId) {
1661
1757
  return params;
1662
1758
  }
1663
- const inputArtifacts = await this.gatherConversationArtifacts(conversationId, params.contextUser, params.ConversationHistoryFrom);
1759
+ const inputArtifacts = await this.gatherConversationArtifacts(conversationId, params.contextUser, params.ConversationHistoryFrom, params.ConversationBranchID);
1664
1760
  return inputArtifacts.length > 0 ? { ...params, inputArtifacts } : params;
1665
1761
  }
1666
1762
  /**
@@ -1679,23 +1775,25 @@ export class AgentRunner {
1679
1775
  return (await detail.Load(params.conversationDetailId)) ? detail.ConversationID : undefined;
1680
1776
  }
1681
1777
  /**
1682
- * Gathers all artifacts from a conversation (both artifact-system records and
1683
- * uploaded file attachments) so the ArtifactToolManager can make them available
1778
+ * Gathers the artifacts on the run's branch path of a conversation (both artifact-system
1779
+ * records and uploaded file attachments) so the ArtifactToolManager can make them available
1684
1780
  * to the agent as input artifacts.
1685
1781
  *
1686
1782
  * @param historyFrom The run's history floor (`ExecuteAgentParams.ConversationHistoryFrom`).
1687
1783
  * When set, only artifacts attached to messages written at or after it are gathered.
1784
+ * @param branchId The run's branch; only artifacts of messages on its path that no rerun
1785
+ * replaced are gathered.
1688
1786
  */
1689
- async gatherConversationArtifacts(conversationId, contextUser, historyFrom) {
1787
+ async gatherConversationArtifacts(conversationId, contextUser, historyFrom, branchId) {
1690
1788
  try {
1691
1789
  const rv = new RunView();
1692
- const conversationFilter = `ConversationID='${conversationId}'`;
1693
- // Get all conversation detail IDs for this conversation (from its floor, if the run has one)
1790
+ const pathFilter = await ConversationEngine.BranchPathFilterFresh(conversationId, branchId, contextUser);
1791
+ // Get the IDs of the live conversation details on the run's branch path (from its floor, if the run has one)
1694
1792
  const details = await rv.RunView({
1695
1793
  EntityName: 'MJ: Conversation Details',
1696
- ExtraFilter: historyFrom
1697
- ? `${conversationFilter} AND ${ConversationEngine.HistoryFromFilter(historyFrom)}`
1698
- : conversationFilter,
1794
+ ExtraFilter: ConversationEngine.LiveRowsFilter(historyFrom
1795
+ ? `${pathFilter} AND ${ConversationEngine.HistoryFromFilter(historyFrom)}`
1796
+ : pathFilter),
1699
1797
  Fields: ['ID'],
1700
1798
  ResultType: 'simple',
1701
1799
  }, contextUser);