@memberjunction/core-actions 5.50.0 → 6.1.0-edge.0

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 (36) hide show
  1. package/LICENSE +7 -0
  2. package/dist/custom/ai/base-find-actions.action.d.ts +22 -0
  3. package/dist/custom/ai/base-find-actions.action.d.ts.map +1 -0
  4. package/dist/custom/ai/base-find-actions.action.js +118 -0
  5. package/dist/custom/ai/base-find-actions.action.js.map +1 -0
  6. package/dist/custom/ai/base-find-agents.action.d.ts +40 -0
  7. package/dist/custom/ai/base-find-agents.action.d.ts.map +1 -0
  8. package/dist/custom/ai/base-find-agents.action.js +139 -0
  9. package/dist/custom/ai/base-find-agents.action.js.map +1 -0
  10. package/dist/custom/ai/find-best-action.action.d.ts +12 -37
  11. package/dist/custom/ai/find-best-action.action.d.ts.map +1 -1
  12. package/dist/custom/ai/find-best-action.action.js +12 -177
  13. package/dist/custom/ai/find-best-action.action.js.map +1 -1
  14. package/dist/custom/ai/find-best-agent.action.d.ts +13 -37
  15. package/dist/custom/ai/find-best-agent.action.d.ts.map +1 -1
  16. package/dist/custom/ai/find-best-agent.action.js +14 -162
  17. package/dist/custom/ai/find-best-agent.action.js.map +1 -1
  18. package/dist/custom/ai/find-candidate-actions.action.d.ts +11 -37
  19. package/dist/custom/ai/find-candidate-actions.action.d.ts.map +1 -1
  20. package/dist/custom/ai/find-candidate-actions.action.js +11 -177
  21. package/dist/custom/ai/find-candidate-actions.action.js.map +1 -1
  22. package/dist/custom/ai/find-candidate-agents.action.d.ts +17 -38
  23. package/dist/custom/ai/find-candidate-agents.action.d.ts.map +1 -1
  24. package/dist/custom/ai/find-candidate-agents.action.js +22 -190
  25. package/dist/custom/ai/find-candidate-agents.action.js.map +1 -1
  26. package/dist/custom/ai/semantic-entity-search.helper.d.ts +48 -0
  27. package/dist/custom/ai/semantic-entity-search.helper.d.ts.map +1 -0
  28. package/dist/custom/ai/semantic-entity-search.helper.js +60 -0
  29. package/dist/custom/ai/semantic-entity-search.helper.js.map +1 -0
  30. package/dist/custom/data/search-query-catalog.action.d.ts +6 -3
  31. package/dist/custom/data/search-query-catalog.action.d.ts.map +1 -1
  32. package/dist/custom/data/search-query-catalog.action.js +45 -35
  33. package/dist/custom/data/search-query-catalog.action.js.map +1 -1
  34. package/dist/custom/search/scoped-search.action.js +2 -2
  35. package/dist/custom/search/scoped-search.action.js.map +1 -1
  36. package/package.json +46 -46
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023 MemberJunction
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,22 @@
1
+ import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
2
+ import { BaseAction } from "@memberjunction/actions";
3
+ /**
4
+ * Shared base for the "Find Best Action" / "Find Candidate Actions" wrappers.
5
+ *
6
+ * Both rank actions for a task description via the unified
7
+ * {@link IRunViewProvider.SearchEntity} pipeline (semantic mode, backed by the
8
+ * daily-synced "Actions Search" EntityDocument) and then hydrate action metadata
9
+ * + parameters from AIEngine's cache to preserve the legacy
10
+ * `MatchedActions` / `MatchCount` output shape.
11
+ *
12
+ * This base intentionally carries **no** `@RegisterClass` decorator so importing
13
+ * it from a concrete subclass does not register an extra action.
14
+ */
15
+ export declare abstract class BaseFindActionsAction extends BaseAction {
16
+ /** Entity searched by this action. */
17
+ protected get entityName(): string;
18
+ /** Verb used in error messages (e.g. "find best action"). */
19
+ protected abstract get actionLabel(): string;
20
+ protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
21
+ }
22
+ //# sourceMappingURL=base-find-actions.action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-find-actions.action.d.ts","sourceRoot":"","sources":["../../../src/custom/ai/base-find-actions.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAMrD;;;;;;;;;;;GAWG;AACH,8BAAsB,qBAAsB,SAAQ,UAAU;IAC1D,sCAAsC;IACtC,SAAS,KAAK,UAAU,IAAI,MAAM,CAA0B;IAC5D,6DAA6D;IAC7D,SAAS,CAAC,QAAQ,KAAK,WAAW,IAAI,MAAM,CAAC;cAE7B,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA2G1F"}
@@ -0,0 +1,118 @@
1
+ import { NormalizeUUID } from "@memberjunction/global";
2
+ import { BaseAction } from "@memberjunction/actions";
3
+ import { AIEngine } from "@memberjunction/aiengine";
4
+ import { RunView } from "@memberjunction/core";
5
+ import { runSemanticEntitySearch, getActionParamValue, getActionBooleanParam } from "./semantic-entity-search.helper.js";
6
+ /**
7
+ * Shared base for the "Find Best Action" / "Find Candidate Actions" wrappers.
8
+ *
9
+ * Both rank actions for a task description via the unified
10
+ * {@link IRunViewProvider.SearchEntity} pipeline (semantic mode, backed by the
11
+ * daily-synced "Actions Search" EntityDocument) and then hydrate action metadata
12
+ * + parameters from AIEngine's cache to preserve the legacy
13
+ * `MatchedActions` / `MatchCount` output shape.
14
+ *
15
+ * This base intentionally carries **no** `@RegisterClass` decorator so importing
16
+ * it from a concrete subclass does not register an extra action.
17
+ */
18
+ export class BaseFindActionsAction extends BaseAction {
19
+ /** Entity searched by this action. */
20
+ get entityName() { return 'MJ: Actions'; }
21
+ async InternalRunAction(params) {
22
+ try {
23
+ const taskDescription = getActionParamValue(params, 'taskdescription');
24
+ const maxResults = parseInt(String(getActionParamValue(params, 'maxresults') ?? '10'));
25
+ const minimumSimilarityScore = parseFloat(String(getActionParamValue(params, 'minimumsimilarityscore') ?? '0.5'));
26
+ const excludeAgentManagement = getActionBooleanParam(params, 'excludeagentmanagement', true);
27
+ if (!taskDescription || taskDescription.trim().length === 0) {
28
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'TaskDescription parameter is required and cannot be empty' };
29
+ }
30
+ if (maxResults < 1 || maxResults > 50) {
31
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'MaxResults must be between 1 and 50' };
32
+ }
33
+ if (minimumSimilarityScore < 0 || minimumSimilarityScore > 1) {
34
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'MinimumSimilarityScore must be between 0 and 1' };
35
+ }
36
+ if (!params.ContextUser) {
37
+ return { Success: false, ResultCode: 'MISSING_USER_CONTEXT', Message: 'User context required' };
38
+ }
39
+ // Rank via the unified SearchEntity pipeline (over-fetch to allow post-filtering)
40
+ const search = await runSemanticEntitySearch(params, this.entityName, taskDescription, maxResults * 2, minimumSimilarityScore);
41
+ if (!search.ok) {
42
+ return { Success: false, ResultCode: search.resultCode ?? 'SEARCH_FAILED', Message: search.message ?? 'Semantic search failed' };
43
+ }
44
+ // Hydrate action metadata from AIEngine's cached actions (no DB round trip)
45
+ await AIEngine.Instance.Config(false, params.ContextUser);
46
+ const actionsById = new Map();
47
+ for (const a of AIEngine.Instance.SystemActions) {
48
+ actionsById.set(NormalizeUUID(a.ID), a);
49
+ }
50
+ let matched = search.results
51
+ .map(r => ({ action: actionsById.get(NormalizeUUID(r.recordId)), score: r.score }))
52
+ .filter((m) => m.action != null);
53
+ if (excludeAgentManagement) {
54
+ matched = matched.filter(m => m.action.Category !== 'Agent Management');
55
+ }
56
+ matched = matched.slice(0, maxResults);
57
+ if (matched.length === 0) {
58
+ return {
59
+ Success: false,
60
+ ResultCode: 'NO_ACTIONS_FOUND',
61
+ Message: `No actions found matching the criteria (minimum similarity: ${minimumSimilarityScore}).`
62
+ };
63
+ }
64
+ // Load action parameters for all matched actions
65
+ const actionIds = matched.map(m => m.action.ID);
66
+ const rv = new RunView();
67
+ const paramsResult = await rv.RunView({
68
+ EntityName: 'MJ: Action Params',
69
+ ExtraFilter: `ActionID IN ('${actionIds.join("','")}')`,
70
+ OrderBy: 'ActionID, Name',
71
+ ResultType: 'entity_object'
72
+ }, params.ContextUser);
73
+ const paramsByActionId = new Map();
74
+ if (paramsResult.Success && paramsResult.Results) {
75
+ for (const param of paramsResult.Results) {
76
+ const list = paramsByActionId.get(param.ActionID) ?? [];
77
+ list.push(param);
78
+ paramsByActionId.set(param.ActionID, list);
79
+ }
80
+ }
81
+ const actionsWithParams = matched.map(m => ({
82
+ actionId: m.action.ID,
83
+ actionName: m.action.Name,
84
+ similarityScore: Math.round(m.score * 100) / 100,
85
+ description: m.action.Description,
86
+ categoryName: m.action.Category,
87
+ status: m.action.Status,
88
+ driverClass: m.action.DriverClass,
89
+ parameters: (paramsByActionId.get(m.action.ID) || []).map(p => ({
90
+ name: p.Name,
91
+ type: p.Type,
92
+ valueType: p.ValueType,
93
+ isArray: p.IsArray,
94
+ description: p.Description,
95
+ isRequired: p.IsRequired,
96
+ defaultValue: p.DefaultValue
97
+ }))
98
+ }));
99
+ params.Params.push({ Name: 'MatchedActions', Type: 'Output', Value: actionsWithParams });
100
+ params.Params.push({ Name: 'MatchCount', Type: 'Output', Value: actionsWithParams.length });
101
+ const responseData = {
102
+ message: `Found ${actionsWithParams.length} relevant action(s)`,
103
+ taskDescription,
104
+ matchCount: actionsWithParams.length,
105
+ allMatches: actionsWithParams
106
+ };
107
+ return { Success: true, ResultCode: 'SUCCESS', Message: JSON.stringify(responseData, null, 2) };
108
+ }
109
+ catch (error) {
110
+ return {
111
+ Success: false,
112
+ ResultCode: 'EXECUTION_ERROR',
113
+ Message: `Failed to ${this.actionLabel}: ${error instanceof Error ? error.message : String(error)}`
114
+ };
115
+ }
116
+ }
117
+ }
118
+ //# sourceMappingURL=base-find-actions.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-find-actions.action.js","sourceRoot":"","sources":["../../../src/custom/ai/base-find-actions.action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAEtH;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,qBAAsB,SAAQ,UAAU;IAC1D,sCAAsC;IACtC,IAAc,UAAU,KAAa,OAAO,aAAa,CAAC,CAAC,CAAC;IAIlD,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,CAAuB,CAAC;YAC7F,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;YACvF,MAAM,sBAAsB,GAAG,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,wBAAwB,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YAClH,MAAM,sBAAsB,GAAG,qBAAqB,CAAC,MAAM,EAAE,wBAAwB,EAAE,IAAI,CAAC,CAAC;YAE7F,IAAI,CAAC,eAAe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junction/actions";
3
+ import { MJAIAgentEntityExtended } from "@memberjunction/ai-core-plus";
4
+ /**
5
+ * Shared base for the "Find Best Agent" / "Find Candidate Agents" wrappers.
6
+ *
7
+ * Both rank agents for a task description via the unified
8
+ * {@link IRunViewProvider.SearchEntity} pipeline (semantic mode, backed by the
9
+ * daily-synced "AI Agents Search" EntityDocument), then permission-filter to
10
+ * agents the user can run, drop Sub-Agents, and hydrate agent metadata from
11
+ * AIEngine's cache. Subclasses tune the invocation filter and whether sub-agent
12
+ * details are included in the output.
13
+ *
14
+ * Carries **no** `@RegisterClass` decorator so importing it does not register an
15
+ * extra action.
16
+ */
17
+ export declare abstract class BaseFindAgentsAction extends BaseAction {
18
+ /** Entity searched by this action. */
19
+ protected get entityName(): string;
20
+ /** Verb used in error messages. */
21
+ protected abstract get actionLabel(): string;
22
+ /** Whether each result includes sub-agent details + default artifact type (candidate variant). */
23
+ protected get includeSubAgentDetails(): boolean;
24
+ /**
25
+ * Variant-specific invocation/parent filtering. Default excludes agents whose
26
+ * invocation mode is 'Sub-Agent' (they're meant to be called by other agents).
27
+ */
28
+ protected applyInvocationFilter(agents: MJAIAgentEntityExtended[], _params: RunActionParams): MJAIAgentEntityExtended[];
29
+ protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
30
+ /** Action names available to the given agent. */
31
+ protected getAgentActionNames(agentId: string): string[];
32
+ /** Sub-agents (direct children + relationship-linked) for the given agent. */
33
+ protected getSubAgents(agentId: string): Array<{
34
+ name: string;
35
+ description: string;
36
+ }>;
37
+ /** Builds the per-agent result object, including sub-agent details for the candidate variant. */
38
+ protected buildAgentResult(agent: MJAIAgentEntityExtended, score: number): Record<string, unknown>;
39
+ }
40
+ //# sourceMappingURL=base-find-agents.action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-find-agents.action.d.ts","sourceRoot":"","sources":["../../../src/custom/ai/base-find-agents.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGvE;;;;;;;;;;;;GAYG;AACH,8BAAsB,oBAAqB,SAAQ,UAAU;IACzD,sCAAsC;IACtC,SAAS,KAAK,UAAU,IAAI,MAAM,CAA4B;IAC9D,mCAAmC;IACnC,SAAS,CAAC,QAAQ,KAAK,WAAW,IAAI,MAAM,CAAC;IAC7C,kGAAkG;IAClG,SAAS,KAAK,sBAAsB,IAAI,OAAO,CAAkB;IAEjE;;;OAGG;IACH,SAAS,CAAC,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,uBAAuB,EAAE;cAIvG,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoFvF,iDAAiD;IACjD,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAMxD,8EAA8E;IAC9E,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAoBrF,iGAAiG;IACjG,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAcrG"}
@@ -0,0 +1,139 @@
1
+ import { UUIDsEqual, NormalizeUUID } from "@memberjunction/global";
2
+ import { BaseAction } from "@memberjunction/actions";
3
+ import { AIEngine } from "@memberjunction/aiengine";
4
+ import { AIAgentPermissionHelper } from "@memberjunction/ai-engine-base";
5
+ import { runSemanticEntitySearch, getActionParamValue, getActionBooleanParam } from "./semantic-entity-search.helper.js";
6
+ /**
7
+ * Shared base for the "Find Best Agent" / "Find Candidate Agents" wrappers.
8
+ *
9
+ * Both rank agents for a task description via the unified
10
+ * {@link IRunViewProvider.SearchEntity} pipeline (semantic mode, backed by the
11
+ * daily-synced "AI Agents Search" EntityDocument), then permission-filter to
12
+ * agents the user can run, drop Sub-Agents, and hydrate agent metadata from
13
+ * AIEngine's cache. Subclasses tune the invocation filter and whether sub-agent
14
+ * details are included in the output.
15
+ *
16
+ * Carries **no** `@RegisterClass` decorator so importing it does not register an
17
+ * extra action.
18
+ */
19
+ export class BaseFindAgentsAction extends BaseAction {
20
+ /** Entity searched by this action. */
21
+ get entityName() { return 'MJ: AI Agents'; }
22
+ /** Whether each result includes sub-agent details + default artifact type (candidate variant). */
23
+ get includeSubAgentDetails() { return false; }
24
+ /**
25
+ * Variant-specific invocation/parent filtering. Default excludes agents whose
26
+ * invocation mode is 'Sub-Agent' (they're meant to be called by other agents).
27
+ */
28
+ applyInvocationFilter(agents, _params) {
29
+ return agents.filter(a => a.InvocationMode !== 'Sub-Agent');
30
+ }
31
+ async InternalRunAction(params) {
32
+ try {
33
+ const taskDescription = getActionParamValue(params, 'taskdescription');
34
+ const maxResults = parseInt(String(getActionParamValue(params, 'maxresults') ?? '5'));
35
+ const minimumSimilarityScore = parseFloat(String(getActionParamValue(params, 'minimumsimilarityscore') ?? '0.5'));
36
+ const includeInactive = getActionBooleanParam(params, 'includeinactive', false);
37
+ if (!taskDescription || taskDescription.trim().length === 0) {
38
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'TaskDescription parameter is required and cannot be empty' };
39
+ }
40
+ if (maxResults < 1 || maxResults > 20) {
41
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'MaxResults must be between 1 and 20' };
42
+ }
43
+ if (minimumSimilarityScore < 0 || minimumSimilarityScore > 1) {
44
+ return { Success: false, ResultCode: 'INVALID_INPUT', Message: 'MinimumSimilarityScore must be between 0 and 1' };
45
+ }
46
+ if (!params.ContextUser) {
47
+ return { Success: false, ResultCode: 'MISSING_USER_CONTEXT', Message: 'User context required for permission filtering' };
48
+ }
49
+ // Rank via the unified SearchEntity pipeline (over-fetch 3x for post-filtering)
50
+ const search = await runSemanticEntitySearch(params, this.entityName, taskDescription, maxResults * 3, minimumSimilarityScore);
51
+ if (!search.ok) {
52
+ return { Success: false, ResultCode: search.resultCode ?? 'SEARCH_FAILED', Message: search.message ?? 'Semantic search failed' };
53
+ }
54
+ // Hydrate agent metadata from AIEngine's cache (no DB round trip)
55
+ await AIEngine.Instance.Config(false, params.ContextUser);
56
+ const agentsById = new Map();
57
+ for (const a of AIEngine.Instance.Agents) {
58
+ agentsById.set(NormalizeUUID(a.ID), a);
59
+ }
60
+ const scoreById = new Map();
61
+ let matched = [];
62
+ for (const r of search.results) {
63
+ const agent = agentsById.get(NormalizeUUID(r.recordId));
64
+ if (agent) {
65
+ matched.push(agent);
66
+ scoreById.set(NormalizeUUID(agent.ID), r.score);
67
+ }
68
+ }
69
+ // Permission-filter to agents the user can 'run'
70
+ const accessibleAgents = await AIAgentPermissionHelper.GetAccessibleAgents(params.ContextUser, 'run');
71
+ const accessibleAgentIds = new Set(accessibleAgents.map(a => NormalizeUUID(a.ID)));
72
+ matched = matched.filter(a => accessibleAgentIds.has(NormalizeUUID(a.ID)));
73
+ if (!includeInactive) {
74
+ matched = matched.filter(a => a.Status === 'Active');
75
+ }
76
+ matched = this.applyInvocationFilter(matched, params).slice(0, maxResults);
77
+ if (matched.length === 0) {
78
+ return {
79
+ Success: false,
80
+ ResultCode: 'NO_AGENTS_FOUND',
81
+ Message: `No accessible agents found matching the criteria (minimum similarity: ${minimumSimilarityScore}). You may not have permission to run the matching agents.`
82
+ };
83
+ }
84
+ const allMatches = matched.map(a => this.buildAgentResult(a, scoreById.get(NormalizeUUID(a.ID)) ?? 0));
85
+ params.Params.push({ Name: 'MatchedAgents', Type: 'Output', Value: allMatches });
86
+ params.Params.push({ Name: 'MatchCount', Type: 'Output', Value: allMatches.length });
87
+ const responseData = {
88
+ message: `Found ${allMatches.length} accessible agent(s)`,
89
+ taskDescription,
90
+ matchCount: allMatches.length,
91
+ allMatches
92
+ };
93
+ return { Success: true, ResultCode: 'SUCCESS', Message: JSON.stringify(responseData, null, 2) };
94
+ }
95
+ catch (error) {
96
+ return {
97
+ Success: false,
98
+ ResultCode: 'EXECUTION_ERROR',
99
+ Message: `Failed to ${this.actionLabel}: ${error instanceof Error ? error.message : String(error)}`
100
+ };
101
+ }
102
+ }
103
+ /** Action names available to the given agent. */
104
+ getAgentActionNames(agentId) {
105
+ return AIEngine.Instance.AgentActions
106
+ .filter(aa => UUIDsEqual(aa.AgentID, agentId) && aa.Status === 'Active')
107
+ .map(aa => aa.Action);
108
+ }
109
+ /** Sub-agents (direct children + relationship-linked) for the given agent. */
110
+ getSubAgents(agentId) {
111
+ const subAgents = [];
112
+ const childAgents = AIEngine.Instance.Agents.filter(a => UUIDsEqual(a.ParentID, agentId) && a.Status === 'Active');
113
+ subAgents.push(...childAgents.map(a => ({ name: a.Name, description: a.Description || '' })));
114
+ const relationships = AIEngine.Instance.AgentRelationships.filter(r => UUIDsEqual(r.AgentID, agentId) && r.Status === 'Active');
115
+ for (const rel of relationships) {
116
+ const relatedAgent = AIEngine.Instance.Agents.find(a => UUIDsEqual(a.ID, rel.SubAgentID));
117
+ if (relatedAgent && relatedAgent.Status === 'Active') {
118
+ subAgents.push({ name: relatedAgent.Name, description: relatedAgent.Description || '' });
119
+ }
120
+ }
121
+ return subAgents;
122
+ }
123
+ /** Builds the per-agent result object, including sub-agent details for the candidate variant. */
124
+ buildAgentResult(agent, score) {
125
+ const base = {
126
+ agentId: agent.ID,
127
+ agentName: agent.Name,
128
+ similarityScore: Math.round(score * 100) / 100,
129
+ description: agent.Description,
130
+ actions: this.getAgentActionNames(agent.ID)
131
+ };
132
+ if (this.includeSubAgentDetails) {
133
+ base.subAgents = this.getSubAgents(agent.ID);
134
+ base.defaultArtifactType = agent.DefaultArtifactType || null;
135
+ }
136
+ return base;
137
+ }
138
+ }
139
+ //# sourceMappingURL=base-find-agents.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-find-agents.action.js","sourceRoot":"","sources":["../../../src/custom/ai/base-find-agents.action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAEtH;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,oBAAqB,SAAQ,UAAU;IACzD,sCAAsC;IACtC,IAAc,UAAU,KAAa,OAAO,eAAe,CAAC,CAAC,CAAC;IAG9D,kGAAkG;IAClG,IAAc,sBAAsB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAEjE;;;OAGG;IACO,qBAAqB,CAAC,MAAiC,EAAE,OAAwB;QACvF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,KAAK,WAAW,CAAC,CAAC;IAChE,CAAC;IAES,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,CAAuB,CAAC;YAC7F,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YACtF,MAAM,sBAAsB,GAAG,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,wBAAwB,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YAClH,MAAM,eAAe,GAAG,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,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,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;YAC1F,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACnD,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7F,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,iGAAiG;IACvF,gBAAgB,CAAC,KAA8B,EAAE,KAAa;QACpE,MAAM,IAAI,GAA4B;YAClC,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,SAAS,EAAE,KAAK,CAAC,IAAI;YACrB,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG;YAC9C,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;SAC9C,CAAC;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC7C,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,IAAI,IAAI,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -1,49 +1,24 @@
1
- import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
2
- import { BaseAction } from "@memberjunction/actions";
1
+ import { BaseFindActionsAction } from "./base-find-actions.action.js";
3
2
  /**
4
- * Action that finds the best-matching actions for a given task using embedding-based semantic search.
3
+ * Finds the best-matching actions for a given task using semantic search.
5
4
  *
6
- * This action uses local embeddings to perform fast similarity search across all available actions,
7
- * returning the most relevant actions based on their descriptions and capabilities.
5
+ * @deprecated Prefer the generic **Search Entity** action
6
+ * (`SearchEntity({ entityName: 'MJ: Actions', searchText, options })`). This action
7
+ * is retained as a thin, backward-compatible wrapper around `Provider.SearchEntity`
8
+ * (semantic mode, backed by the daily-synced "Actions Search" EntityDocument).
9
+ *
10
+ * Inputs: `TaskDescription` (required), `MaxResults` (default 10), `MinimumSimilarityScore`
11
+ * (cosine 0-1, default 0.5), `ExcludeAgentManagement` (default true).
8
12
  *
9
13
  * @example
10
14
  * ```typescript
11
- * // Find actions for a web search task
12
15
  * await runAction({
13
16
  * ActionName: 'Find Best Action',
14
- * Params: [{
15
- * Name: 'TaskDescription',
16
- * Value: 'Search the internet for information on a topic'
17
- * }, {
18
- * Name: 'MaxResults',
19
- * Value: 5
20
- * }, {
21
- * Name: 'MinimumSimilarityScore',
22
- * Value: 0.6
23
- * }]
17
+ * Params: [{ Name: 'TaskDescription', Value: 'Search the internet for information' }]
24
18
  * });
25
19
  * ```
26
20
  */
27
- export declare class FindBestActionAction extends BaseAction {
28
- /**
29
- * Executes the Find Best Action action.
30
- *
31
- * @param params - The action parameters containing:
32
- * - TaskDescription: Description of the task to find actions for (required)
33
- * - MaxResults: Maximum number of actions to return (optional, default: 10)
34
- * - MinimumSimilarityScore: Minimum similarity score 0-1 (optional, default: 0.5)
35
- * - ExcludeAgentManagement: Exclude Agent Management actions (optional, default: true)
36
- *
37
- * @returns Action result with matched actions
38
- */
39
- protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
40
- /**
41
- * Get boolean parameter with default
42
- */
43
- private getBooleanParam;
44
- /**
45
- * Get parameter value by name (case-insensitive)
46
- */
47
- private getParamValue;
21
+ export declare class FindBestActionAction extends BaseFindActionsAction {
22
+ protected get actionLabel(): string;
48
23
  }
49
24
  //# sourceMappingURL=find-best-action.action.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-best-action.action.d.ts","sourceRoot":"","sources":["../../../src/custom/ai/find-best-action.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBACa,oBAAqB,SAAQ,UAAU;IAChD;;;;;;;;;;OAUG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsJvF;;OAEG;IACH,OAAO,CAAC,eAAe;IAUvB;;OAEG;IACH,OAAO,CAAC,aAAa;CAIxB"}
1
+ {"version":3,"file":"find-best-action.action.d.ts","sourceRoot":"","sources":["../../../src/custom/ai/find-best-action.action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBACa,oBAAqB,SAAQ,qBAAqB;IAC3D,SAAS,KAAK,WAAW,IAAI,MAAM,CAA+B;CACrE"}
@@ -6,193 +6,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { RegisterClass } from "@memberjunction/global";
8
8
  import { BaseAction } from "@memberjunction/actions";
9
- import { AIEngine } from "@memberjunction/aiengine";
10
- import { RunView } from "@memberjunction/core";
9
+ import { BaseFindActionsAction } from "./base-find-actions.action.js";
11
10
  /**
12
- * Action that finds the best-matching actions for a given task using embedding-based semantic search.
11
+ * Finds the best-matching actions for a given task using semantic search.
13
12
  *
14
- * This action uses local embeddings to perform fast similarity search across all available actions,
15
- * returning the most relevant actions based on their descriptions and capabilities.
13
+ * @deprecated Prefer the generic **Search Entity** action
14
+ * (`SearchEntity({ entityName: 'MJ: Actions', searchText, options })`). This action
15
+ * is retained as a thin, backward-compatible wrapper around `Provider.SearchEntity`
16
+ * (semantic mode, backed by the daily-synced "Actions Search" EntityDocument).
17
+ *
18
+ * Inputs: `TaskDescription` (required), `MaxResults` (default 10), `MinimumSimilarityScore`
19
+ * (cosine 0-1, default 0.5), `ExcludeAgentManagement` (default true).
16
20
  *
17
21
  * @example
18
22
  * ```typescript
19
- * // Find actions for a web search task
20
23
  * await runAction({
21
24
  * ActionName: 'Find Best Action',
22
- * Params: [{
23
- * Name: 'TaskDescription',
24
- * Value: 'Search the internet for information on a topic'
25
- * }, {
26
- * Name: 'MaxResults',
27
- * Value: 5
28
- * }, {
29
- * Name: 'MinimumSimilarityScore',
30
- * Value: 0.6
31
- * }]
25
+ * Params: [{ Name: 'TaskDescription', Value: 'Search the internet for information' }]
32
26
  * });
33
27
  * ```
34
28
  */
35
- let FindBestActionAction = class FindBestActionAction extends BaseAction {
36
- /**
37
- * Executes the Find Best Action action.
38
- *
39
- * @param params - The action parameters containing:
40
- * - TaskDescription: Description of the task to find actions for (required)
41
- * - MaxResults: Maximum number of actions to return (optional, default: 10)
42
- * - MinimumSimilarityScore: Minimum similarity score 0-1 (optional, default: 0.5)
43
- * - ExcludeAgentManagement: Exclude Agent Management actions (optional, default: true)
44
- *
45
- * @returns Action result with matched actions
46
- */
47
- async InternalRunAction(params) {
48
- try {
49
- // Extract and validate input parameters
50
- const taskDescription = this.getParamValue(params, 'taskdescription');
51
- const maxResults = parseInt(this.getParamValue(params, 'maxresults') || '10');
52
- const minimumSimilarityScore = parseFloat(this.getParamValue(params, 'minimumsimilarityscore') || '0.5');
53
- const excludeAgentManagement = this.getBooleanParam(params, 'excludeagentmanagement', true);
54
- // Validate required input
55
- if (!taskDescription || taskDescription.trim().length === 0) {
56
- return {
57
- Success: false,
58
- ResultCode: 'INVALID_INPUT',
59
- Message: 'TaskDescription parameter is required and cannot be empty'
60
- };
61
- }
62
- // Validate numeric ranges
63
- if (maxResults < 1 || maxResults > 50) {
64
- return {
65
- Success: false,
66
- ResultCode: 'INVALID_INPUT',
67
- Message: 'MaxResults must be between 1 and 50'
68
- };
69
- }
70
- if (minimumSimilarityScore < 0 || minimumSimilarityScore > 1) {
71
- return {
72
- Success: false,
73
- ResultCode: 'INVALID_INPUT',
74
- Message: 'MinimumSimilarityScore must be between 0 and 1'
75
- };
76
- }
77
- // Validate contextUser is provided
78
- if (!params.ContextUser) {
79
- return {
80
- Success: false,
81
- ResultCode: 'MISSING_USER_CONTEXT',
82
- Message: 'User context required'
83
- };
84
- }
85
- // Ensure AIEngine is loaded (embeddings computed during initialization)
86
- await AIEngine.Instance.Config(false, params.ContextUser);
87
- // Find similar actions using AIEngine's built-in method - no database round trip!
88
- const matchedActions = await AIEngine.Instance.FindSimilarActions(taskDescription, maxResults * 2, // Get 2x results to account for filtering
89
- minimumSimilarityScore);
90
- // Filter out Agent Management actions if requested
91
- let filteredActions = matchedActions;
92
- if (excludeAgentManagement) {
93
- filteredActions = matchedActions.filter(a => a.categoryName !== 'Agent Management');
94
- }
95
- // Limit to maxResults after filtering
96
- filteredActions = filteredActions.slice(0, maxResults);
97
- if (filteredActions.length === 0) {
98
- return {
99
- Success: false,
100
- ResultCode: 'NO_ACTIONS_FOUND',
101
- Message: `No actions found matching the criteria (minimum similarity: ${minimumSimilarityScore}).`
102
- };
103
- }
104
- // Load action parameters for all matched actions
105
- const actionIds = filteredActions.map(a => a.actionId);
106
- const rv = new RunView();
107
- const paramsResult = await rv.RunView({
108
- EntityName: 'MJ: Action Params',
109
- ExtraFilter: `ActionID IN ('${actionIds.join("','")}')`,
110
- OrderBy: 'ActionID, Name',
111
- ResultType: 'entity_object'
112
- }, params.ContextUser);
113
- // Group parameters by action ID
114
- const paramsByActionId = new Map();
115
- if (paramsResult.Success && paramsResult.Results) {
116
- for (const param of paramsResult.Results) {
117
- const actionId = param.ActionID;
118
- if (!paramsByActionId.has(actionId)) {
119
- paramsByActionId.set(actionId, []);
120
- }
121
- paramsByActionId.get(actionId).push(param);
122
- }
123
- }
124
- // Build response with parameters included
125
- const actionsWithParams = filteredActions.map(a => ({
126
- actionId: a.actionId,
127
- actionName: a.actionName,
128
- similarityScore: Math.round(a.similarityScore * 100) / 100,
129
- description: a.description,
130
- categoryName: a.categoryName,
131
- status: a.status,
132
- driverClass: a.driverClass,
133
- parameters: (paramsByActionId.get(a.actionId) || []).map(p => ({
134
- name: p.Name,
135
- type: p.Type, // Input/Output
136
- valueType: p.ValueType,
137
- isArray: p.IsArray,
138
- description: p.Description,
139
- isRequired: p.IsRequired,
140
- defaultValue: p.DefaultValue
141
- }))
142
- }));
143
- // Add output parameters
144
- params.Params.push({
145
- Name: 'MatchedActions',
146
- Type: 'Output',
147
- Value: actionsWithParams
148
- });
149
- params.Params.push({
150
- Name: 'MatchCount',
151
- Type: 'Output',
152
- Value: filteredActions.length
153
- });
154
- // Build response message with full descriptions and parameters
155
- const responseData = {
156
- message: `Found ${filteredActions.length} relevant action(s)`,
157
- taskDescription: taskDescription,
158
- matchCount: filteredActions.length,
159
- allMatches: actionsWithParams
160
- };
161
- return {
162
- Success: true,
163
- ResultCode: 'SUCCESS',
164
- Message: JSON.stringify(responseData, null, 2)
165
- };
166
- }
167
- catch (error) {
168
- return {
169
- Success: false,
170
- ResultCode: 'EXECUTION_ERROR',
171
- Message: `Failed to find best action: ${error instanceof Error ? error.message : String(error)}`
172
- };
173
- }
174
- }
175
- /**
176
- * Get boolean parameter with default
177
- */
178
- getBooleanParam(params, name, defaultValue) {
179
- const value = this.getParamValue(params, name);
180
- if (value === undefined || value === null)
181
- return defaultValue;
182
- if (typeof value === 'boolean')
183
- return value;
184
- if (typeof value === 'string') {
185
- return value.toLowerCase() === 'true';
186
- }
187
- return defaultValue;
188
- }
189
- /**
190
- * Get parameter value by name (case-insensitive)
191
- */
192
- getParamValue(params, name) {
193
- const param = params.Params.find(p => p.Name.toLowerCase() === name.toLowerCase());
194
- return param?.Value;
195
- }
29
+ let FindBestActionAction = class FindBestActionAction extends BaseFindActionsAction {
30
+ get actionLabel() { return 'find best action'; }
196
31
  };
197
32
  FindBestActionAction = __decorate([
198
33
  RegisterClass(BaseAction, "Find Best Action")