@mj-biz-apps/marketing-server 0.0.0 → 0.2.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.
- package/LICENSE +183 -0
- package/dist/agents/BaseMarketingAgent.d.ts +120 -0
- package/dist/agents/BaseMarketingAgent.d.ts.map +1 -0
- package/dist/agents/BaseMarketingAgent.js +323 -0
- package/dist/agents/BaseMarketingAgent.js.map +1 -0
- package/dist/agents/MarketingExperimentationAgent.d.ts +123 -0
- package/dist/agents/MarketingExperimentationAgent.d.ts.map +1 -0
- package/dist/agents/MarketingExperimentationAgent.js +371 -0
- package/dist/agents/MarketingExperimentationAgent.js.map +1 -0
- package/dist/agents/MarketingOperationsAgent.d.ts +24 -0
- package/dist/agents/MarketingOperationsAgent.d.ts.map +1 -0
- package/dist/agents/MarketingOperationsAgent.js +36 -0
- package/dist/agents/MarketingOperationsAgent.js.map +1 -0
- package/dist/agents/MarketingPodcastIngestionAgent.d.ts +21 -0
- package/dist/agents/MarketingPodcastIngestionAgent.d.ts.map +1 -0
- package/dist/agents/MarketingPodcastIngestionAgent.js +33 -0
- package/dist/agents/MarketingPodcastIngestionAgent.js.map +1 -0
- package/dist/agents/MarketingStrategyOnboardingAgent.d.ts +206 -0
- package/dist/agents/MarketingStrategyOnboardingAgent.d.ts.map +1 -0
- package/dist/agents/MarketingStrategyOnboardingAgent.js +1264 -0
- package/dist/agents/MarketingStrategyOnboardingAgent.js.map +1 -0
- package/dist/agents/index.d.ts +14 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +25 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -0
- package/dist/generated/class-registrations-manifest.d.ts +7 -0
- package/dist/generated/class-registrations-manifest.d.ts.map +1 -0
- package/dist/generated/class-registrations-manifest.js +7 -0
- package/dist/generated/class-registrations-manifest.js.map +1 -0
- package/dist/generated/generated.d.ts +7 -0
- package/dist/generated/generated.d.ts.map +1 -0
- package/dist/generated/generated.js +7 -0
- package/dist/generated/generated.js.map +1 -0
- package/dist/generated/graphql-schemas/__mj_BizAppsMarketing.d.ts +3522 -0
- package/dist/generated/graphql-schemas/__mj_BizAppsMarketing.d.ts.map +1 -0
- package/dist/generated/graphql-schemas/__mj_BizAppsMarketing.js +18854 -0
- package/dist/generated/graphql-schemas/__mj_BizAppsMarketing.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/programs/ContentPostProgramDriver.d.ts +44 -0
- package/dist/programs/ContentPostProgramDriver.d.ts.map +1 -0
- package/dist/programs/ContentPostProgramDriver.js +185 -0
- package/dist/programs/ContentPostProgramDriver.js.map +1 -0
- package/dist/programs/EmailProgramDriver.d.ts +56 -0
- package/dist/programs/EmailProgramDriver.d.ts.map +1 -0
- package/dist/programs/EmailProgramDriver.js +224 -0
- package/dist/programs/EmailProgramDriver.js.map +1 -0
- package/dist/programs/google/GoogleAdsClient.d.ts +93 -0
- package/dist/programs/google/GoogleAdsClient.d.ts.map +1 -0
- package/dist/programs/google/GoogleAdsClient.js +279 -0
- package/dist/programs/google/GoogleAdsClient.js.map +1 -0
- package/dist/programs/google/GoogleAdsProgramDriver.d.ts +56 -0
- package/dist/programs/google/GoogleAdsProgramDriver.d.ts.map +1 -0
- package/dist/programs/google/GoogleAdsProgramDriver.js +357 -0
- package/dist/programs/google/GoogleAdsProgramDriver.js.map +1 -0
- package/dist/programs/google/googleAdsExecutionContext.d.ts +47 -0
- package/dist/programs/google/googleAdsExecutionContext.d.ts.map +1 -0
- package/dist/programs/google/googleAdsExecutionContext.js +128 -0
- package/dist/programs/google/googleAdsExecutionContext.js.map +1 -0
- package/dist/programs/google/googleBrandAssets.d.ts +27 -0
- package/dist/programs/google/googleBrandAssets.d.ts.map +1 -0
- package/dist/programs/google/googleBrandAssets.js +81 -0
- package/dist/programs/google/googleBrandAssets.js.map +1 -0
- package/dist/programs/index.d.ts +18 -0
- package/dist/programs/index.d.ts.map +1 -0
- package/dist/programs/index.js +27 -0
- package/dist/programs/index.js.map +1 -0
- package/dist/programs/linkedin/LinkedInAdsClient.d.ts +145 -0
- package/dist/programs/linkedin/LinkedInAdsClient.d.ts.map +1 -0
- package/dist/programs/linkedin/LinkedInAdsClient.js +408 -0
- package/dist/programs/linkedin/LinkedInAdsClient.js.map +1 -0
- package/dist/programs/linkedin/LinkedInAdsProgramDriver.d.ts +94 -0
- package/dist/programs/linkedin/LinkedInAdsProgramDriver.d.ts.map +1 -0
- package/dist/programs/linkedin/LinkedInAdsProgramDriver.js +449 -0
- package/dist/programs/linkedin/LinkedInAdsProgramDriver.js.map +1 -0
- package/dist/programs/linkedin/linkedInExecutionContext.d.ts +42 -0
- package/dist/programs/linkedin/linkedInExecutionContext.d.ts.map +1 -0
- package/dist/programs/linkedin/linkedInExecutionContext.js +97 -0
- package/dist/programs/linkedin/linkedInExecutionContext.js.map +1 -0
- package/package.json +46 -7
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB plc.
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Blue Cypress, Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: MemberJunction.
|
|
13
|
+
The Licensed Work is (c) 2023-2026 Blue Cypress, Inc.
|
|
14
|
+
|
|
15
|
+
Additional Use Grant: Subject to the terms of this License, Licensor grants
|
|
16
|
+
you the following additional rights to make Production
|
|
17
|
+
Use of the Licensed Work.
|
|
18
|
+
|
|
19
|
+
1. Internal Use
|
|
20
|
+
|
|
21
|
+
You may make production use of the Licensed Work for
|
|
22
|
+
your own internal business or organizational operations.
|
|
23
|
+
|
|
24
|
+
2. Nonprofit Use
|
|
25
|
+
|
|
26
|
+
If you are a Nonprofit, you may make production use of
|
|
27
|
+
the Licensed Work for the operations and activities of
|
|
28
|
+
your Organizational Family.
|
|
29
|
+
|
|
30
|
+
3. MemberJunction Certified Program Use
|
|
31
|
+
|
|
32
|
+
If you are authorized by Licensor under the
|
|
33
|
+
MemberJunction Certified Program to provide professional
|
|
34
|
+
services using the Licensed Work, you may make
|
|
35
|
+
production use of the Licensed Work in providing such
|
|
36
|
+
professional services to a client, provided that:
|
|
37
|
+
|
|
38
|
+
(a) the Licensed Work is deployed in, and the applicable
|
|
39
|
+
production use occurs within, an environment owned,
|
|
40
|
+
leased, licensed, subscribed to, or otherwise controlled
|
|
41
|
+
by that client; and
|
|
42
|
+
|
|
43
|
+
(b) the production use is for that client's own internal
|
|
44
|
+
business or organizational operations or is otherwise
|
|
45
|
+
independently permitted to that client under this
|
|
46
|
+
Additional Use Grant.
|
|
47
|
+
|
|
48
|
+
4. Definitions Applicable to the Additional Use Grant
|
|
49
|
+
|
|
50
|
+
"Affiliate" means, with respect to a specified Person,
|
|
51
|
+
any other Person that directly or indirectly Controls,
|
|
52
|
+
is Controlled by, or is under common Control with such
|
|
53
|
+
specified Person.
|
|
54
|
+
|
|
55
|
+
"Control" (including the terms "Controls," "Controlled
|
|
56
|
+
by," and "under common Control with") means the direct
|
|
57
|
+
or indirect possession of the power to direct or cause
|
|
58
|
+
the direction of the management and policies of a
|
|
59
|
+
Person, whether through ownership of voting interests,
|
|
60
|
+
by contract, or otherwise.
|
|
61
|
+
|
|
62
|
+
"Organizational Family" means, with respect to a Person,
|
|
63
|
+
(a) such Person and its Affiliates, and (b) any
|
|
64
|
+
nonprofit organization, governmental entity, chapter,
|
|
65
|
+
division, local affiliate, regional affiliate, state
|
|
66
|
+
affiliate, national affiliate, or other entity that is
|
|
67
|
+
formally affiliated with such Person through governing
|
|
68
|
+
documents, a charter, bylaws, a membership agreement, or
|
|
69
|
+
another written organizational instrument, and is
|
|
70
|
+
recognized under such documents as part of the same
|
|
71
|
+
organizational structure.
|
|
72
|
+
|
|
73
|
+
"Nonprofit" means a Person recognized by the Internal
|
|
74
|
+
Revenue Service as exempt from federal income taxation
|
|
75
|
+
under Section 501(c)(3), 501(c)(4), 501(c)(5), or
|
|
76
|
+
501(c)(6) of the Internal Revenue Code, or a foreign
|
|
77
|
+
organization recognized under substantially equivalent
|
|
78
|
+
laws.
|
|
79
|
+
|
|
80
|
+
A Person claiming eligibility as a Nonprofit shall, upon
|
|
81
|
+
Licensor's reasonable request, provide documentation
|
|
82
|
+
reasonably sufficient to demonstrate that it qualifies
|
|
83
|
+
as a Nonprofit. If such Person materially misrepresents,
|
|
84
|
+
or is unable to demonstrate, its qualification as a
|
|
85
|
+
Nonprofit, the rights granted to such Person under
|
|
86
|
+
Section 2 of this Additional Use Grant shall terminate.
|
|
87
|
+
|
|
88
|
+
"MemberJunction Certified Program" means Licensor's
|
|
89
|
+
then-current program for certifying and authorizing a
|
|
90
|
+
Person to provide professional services using the
|
|
91
|
+
Licensed Work.
|
|
92
|
+
|
|
93
|
+
"Person" means any individual, corporation, limited
|
|
94
|
+
liability company, partnership, association, nonprofit
|
|
95
|
+
organization, governmental entity, or other legal or
|
|
96
|
+
organizational entity.
|
|
97
|
+
|
|
98
|
+
Change Date: Four (4) years from the date the Licensed Work is first
|
|
99
|
+
made available.
|
|
100
|
+
|
|
101
|
+
Change License: MIT License.
|
|
102
|
+
|
|
103
|
+
For information about alternative licensing arrangements for the Licensed
|
|
104
|
+
Work, please contact Blue Cypress, Inc.
|
|
105
|
+
|
|
106
|
+
-----------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
Terms
|
|
109
|
+
|
|
110
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
111
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
112
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
113
|
+
production use.
|
|
114
|
+
|
|
115
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
116
|
+
available distribution of a specific version of the Licensed Work under this
|
|
117
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
118
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
119
|
+
above terminate.
|
|
120
|
+
|
|
121
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
122
|
+
currently in effect as described in this License, you must purchase a
|
|
123
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
124
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
125
|
+
|
|
126
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
127
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
128
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
129
|
+
for each version of the Licensed Work released by Licensor.
|
|
130
|
+
|
|
131
|
+
You must conspicuously display this License on each original or modified copy
|
|
132
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
133
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
134
|
+
License apply to your use of that work.
|
|
135
|
+
|
|
136
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
137
|
+
terminate your rights under this License for the current and all other
|
|
138
|
+
versions of the Licensed Work.
|
|
139
|
+
|
|
140
|
+
This License does not grant you any right in any trademark or logo of
|
|
141
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
142
|
+
Licensor as expressly required by this License).
|
|
143
|
+
|
|
144
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
145
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
146
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
147
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
148
|
+
TITLE.
|
|
149
|
+
|
|
150
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
151
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
152
|
+
as long as you comply with the Covenants of Licensor below.
|
|
153
|
+
|
|
154
|
+
-----------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
Covenants of Licensor
|
|
157
|
+
|
|
158
|
+
In consideration of the right to use this License's text and the "Business
|
|
159
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
160
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
161
|
+
|
|
162
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
163
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
164
|
+
where "compatible" means that software provided under the Change License
|
|
165
|
+
can be included in a program with software provided under GPL Version 2.0
|
|
166
|
+
or a later version. Licensor may specify additional Change Licenses without
|
|
167
|
+
limitation.
|
|
168
|
+
|
|
169
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
170
|
+
impose any additional restriction on the right granted in this License, as
|
|
171
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
172
|
+
|
|
173
|
+
3. To specify a Change Date.
|
|
174
|
+
|
|
175
|
+
4. Not to modify this License in any other way.
|
|
176
|
+
|
|
177
|
+
-----------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
Notice
|
|
180
|
+
|
|
181
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
182
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
183
|
+
under an Open Source License, as stated in this License.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BaseAgent } from "@memberjunction/ai-agents";
|
|
2
|
+
import { ExecuteAgentParams, BaseAgentNextStep, AIPromptParams, AgentConfiguration } from "@memberjunction/ai-core-plus";
|
|
3
|
+
import { MJAIAgentRunEntityExtended, MJAIAgentRunStepEntityExtended } from "@memberjunction/ai-core-plus";
|
|
4
|
+
import { UserInfo } from "@memberjunction/core";
|
|
5
|
+
/**
|
|
6
|
+
* One brand the current user is authorized for (payload/prompt shape).
|
|
7
|
+
*
|
|
8
|
+
* `companyName` rides along because brand names are only unique WITHIN a
|
|
9
|
+
* company — a user who works across companies can hold grants on two brands
|
|
10
|
+
* both called "Skip", and the agent has to be able to ask "which Skip?".
|
|
11
|
+
*/
|
|
12
|
+
export interface AuthorizedBrandOption {
|
|
13
|
+
brandId: string;
|
|
14
|
+
/** Brand.BrandName */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Brand.Company — the parent company's name, for disambiguation only. */
|
|
17
|
+
companyName: string;
|
|
18
|
+
role: string | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Base class for all marketing agents.
|
|
22
|
+
*
|
|
23
|
+
* Centralizes three concerns every marketing Loop / Flow agent shares:
|
|
24
|
+
*
|
|
25
|
+
* 1. Brand self-resolution — brand, not company, is the unit of marketing
|
|
26
|
+
* scope and of authorization. When no `brandId` was passed in (e.g. the
|
|
27
|
+
* generic conversations UI, which sends no payload), resolve it from the
|
|
28
|
+
* caller's marketing grants (`resolveAuthorizedBrands`, which expands
|
|
29
|
+
* company-level grants to their brands): exactly one authorized brand
|
|
30
|
+
* adopts that brand; several surface `authorizedBrands` so the agent asks
|
|
31
|
+
* the user which brand to work on; zero leaves everything unset and the
|
|
32
|
+
* action gate denies any write. Mirrors MJ's server-side scope-resolution
|
|
33
|
+
* idiom (widget-guest dispatch, DefaultAgentResolver ladder). Transport is
|
|
34
|
+
* convenience — MarketingBaseAction re-validates BrandID against the
|
|
35
|
+
* caller's grants on every tool call regardless.
|
|
36
|
+
*
|
|
37
|
+
* 2. Payload bootstrap — load `brandName` (and the parent `companyId`, see
|
|
38
|
+
* below) from the Brand row when only `brandId` was passed in (e.g.
|
|
39
|
+
* scheduled-job StartingPayloads), and stamp `currentDate` so prompts can
|
|
40
|
+
* reference it.
|
|
41
|
+
*
|
|
42
|
+
* 3. Template-data plumbing — copy the top-level payload keys
|
|
43
|
+
* (brandId / brandName / companyId / currentDate / mode / instructions /
|
|
44
|
+
* authorizedBrands) into the prompt-render data so child templates that
|
|
45
|
+
* use `{{ brandId }}`, `{{ brandName }}`, etc. resolve.
|
|
46
|
+
*
|
|
47
|
+
* **Why `payload.companyId` survives the brand migration:** it is DERIVED from
|
|
48
|
+
* the resolved Brand's CompanyID and is never a scope of its own. Two
|
|
49
|
+
* downstreams genuinely need the parent company: (a) the
|
|
50
|
+
* `MarketingStrategySpec` contract in marketing-core still carries a required
|
|
51
|
+
* `companyId`, and (b) MJ-core `CompanyIntegration` lookups are company-level
|
|
52
|
+
* by definition. Nothing may use it to scope marketing-schema rows — those all
|
|
53
|
+
* carry BrandID.
|
|
54
|
+
*
|
|
55
|
+
* Subclasses can extend `initializeStartingPayload` for additional context
|
|
56
|
+
* loading (CMO does this for marketing-overview state).
|
|
57
|
+
*/
|
|
58
|
+
export declare class BaseMarketingAgent extends BaseAgent {
|
|
59
|
+
protected initializeStartingPayload<P = unknown>(params: ExecuteAgentParams<unknown, P>): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Loads the prior run's FinalPayload onto `params.payload` — the same restore core's
|
|
62
|
+
* initializeAgentRun performs, done early because this class must populate the payload
|
|
63
|
+
* before core gets the chance. A missing or unparseable payload leaves `params.payload`
|
|
64
|
+
* unset, and the normal empty-payload path takes over.
|
|
65
|
+
*/
|
|
66
|
+
private restoreLastRunPayload;
|
|
67
|
+
/**
|
|
68
|
+
* The brand the EMBEDDING APP says the user is looking at —
|
|
69
|
+
* `appContext.AdditionalContext.BrandID`, set by the marketing app's chat
|
|
70
|
+
* panel from its brand picker. Authoritative over grant-derivation (the
|
|
71
|
+
* user already chose), but still just client input: UUID-validated here and
|
|
72
|
+
* access-checked by every action's gate exactly like any other brandId.
|
|
73
|
+
*/
|
|
74
|
+
protected brandFromAppContext(params: ExecuteAgentParams): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Derive brand context from the caller's marketing grants.
|
|
77
|
+
*
|
|
78
|
+
* `resolveAuthorizedBrands` is THE source of truth for what a user may
|
|
79
|
+
* reach: it reads AuthorizedUser and expands company-level grants to every
|
|
80
|
+
* brand of that company, so a "Blue Cypress person" who oversees Sidecar,
|
|
81
|
+
* Izzy and Skip lands here with three brands, not one company.
|
|
82
|
+
*
|
|
83
|
+
* Failure is non-fatal: the agent simply runs without brand context and the
|
|
84
|
+
* prompt instructs it to say so.
|
|
85
|
+
*/
|
|
86
|
+
private resolveBrandFromGrants;
|
|
87
|
+
/**
|
|
88
|
+
* Fill brandName + the derived parent companyId for an already-known
|
|
89
|
+
* brandId. Protected because a subclass shell can resolve the brand LATER
|
|
90
|
+
* than initializeStartingPayload (the onboarding driver matches a brand
|
|
91
|
+
* name out of the conversation) and must be able to hydrate the rest of
|
|
92
|
+
* the context the same way. Clears `payload.brandId` when it doesn't
|
|
93
|
+
* resolve to an active Brand the caller can see.
|
|
94
|
+
*/
|
|
95
|
+
protected hydrateBrandContext(payload: Record<string, unknown>, contextUser: UserInfo): Promise<void>;
|
|
96
|
+
/** Load active Brand rows by id. Empty id list short-circuits (no query). */
|
|
97
|
+
private loadBrands;
|
|
98
|
+
/**
|
|
99
|
+
* Stamp the resolved brand onto the payload. `companyId` is the brand's
|
|
100
|
+
* PARENT company, derived here and only here — it exists for the
|
|
101
|
+
* MarketingStrategySpec contract and MJ-core CompanyIntegration lookups,
|
|
102
|
+
* never to scope marketing-schema rows (those are BrandID-scoped).
|
|
103
|
+
*/
|
|
104
|
+
private applyBrand;
|
|
105
|
+
private toBrandOptions;
|
|
106
|
+
/** One settle per run — preparePromptParams fires every turn. */
|
|
107
|
+
private answeredRequestsSettled;
|
|
108
|
+
/**
|
|
109
|
+
* A run that starts inside a conversation IS the user's answer to whatever this agent was
|
|
110
|
+
* waiting on there. Core only records that when the caller sends `lastRunId`, which the
|
|
111
|
+
* conversation UI never does — so this agent closes its own open Chat-step requests (and
|
|
112
|
+
* their "needs your input" notifications). Runs here, not in initializeStartingPayload,
|
|
113
|
+
* because the run row — whose id the request is linked to — does not exist until later.
|
|
114
|
+
*/
|
|
115
|
+
private settleAnsweredRequestsOnce;
|
|
116
|
+
protected preparePromptParams<P>(config: AgentConfiguration, payload: P, params: ExecuteAgentParams): Promise<AIPromptParams>;
|
|
117
|
+
protected validateSuccessNextStep<P>(params: ExecuteAgentParams, nextStep: BaseAgentNextStep<P>, currentPayload: P, agentRun: MJAIAgentRunEntityExtended, currentStep: MJAIAgentRunStepEntityExtended): Promise<BaseAgentNextStep<P>>;
|
|
118
|
+
}
|
|
119
|
+
export declare function LoadBaseMarketingAgent(): void;
|
|
120
|
+
//# sourceMappingURL=BaseMarketingAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseMarketingAgent.d.ts","sourceRoot":"","sources":["../../src/agents/BaseMarketingAgent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACzH,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAgC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG9E;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;cACpB,yBAAyB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA2DtH;;;;;OAKG;YACW,qBAAqB;IAmBnC;;;;;;OAMG;IACH,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI;IAYxE;;;;;;;;;;OAUG;YACW,sBAAsB;IA8CpC;;;;;;;OAOG;cACa,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAe3G,6EAA6E;YAC/D,UAAU;IAmBxB;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,cAAc;IAUtB,iEAAiE;IACjE,OAAO,CAAC,uBAAuB,CAAS;IAExC;;;;;;OAMG;YACW,0BAA0B;cAgBf,mBAAmB,CAAC,CAAC,EAC1C,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,kBAAkB,GAC3B,OAAO,CAAC,cAAc,CAAC;cA0BD,uBAAuB,CAAC,CAAC,EAC9C,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,cAAc,EAAE,CAAC,EACjB,QAAQ,EAAE,0BAA0B,EACpC,WAAW,EAAE,8BAA8B,GAC5C,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAgBnC;AAED,wBAAgB,sBAAsB,SAAK"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { EscapeSQLString, UUIDsEqual } from '@memberjunction/global';
|
|
2
|
+
import { BaseAgent } from "@memberjunction/ai-agents";
|
|
3
|
+
import { LogStatus, LogError, RunView } from "@memberjunction/core";
|
|
4
|
+
import { closeAnsweredFeedbackRequests, isUuid, resolveAuthorizedBrands, toMarketingEntityName } from "@mj-biz-apps/marketing-core";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all marketing agents.
|
|
7
|
+
*
|
|
8
|
+
* Centralizes three concerns every marketing Loop / Flow agent shares:
|
|
9
|
+
*
|
|
10
|
+
* 1. Brand self-resolution — brand, not company, is the unit of marketing
|
|
11
|
+
* scope and of authorization. When no `brandId` was passed in (e.g. the
|
|
12
|
+
* generic conversations UI, which sends no payload), resolve it from the
|
|
13
|
+
* caller's marketing grants (`resolveAuthorizedBrands`, which expands
|
|
14
|
+
* company-level grants to their brands): exactly one authorized brand
|
|
15
|
+
* adopts that brand; several surface `authorizedBrands` so the agent asks
|
|
16
|
+
* the user which brand to work on; zero leaves everything unset and the
|
|
17
|
+
* action gate denies any write. Mirrors MJ's server-side scope-resolution
|
|
18
|
+
* idiom (widget-guest dispatch, DefaultAgentResolver ladder). Transport is
|
|
19
|
+
* convenience — MarketingBaseAction re-validates BrandID against the
|
|
20
|
+
* caller's grants on every tool call regardless.
|
|
21
|
+
*
|
|
22
|
+
* 2. Payload bootstrap — load `brandName` (and the parent `companyId`, see
|
|
23
|
+
* below) from the Brand row when only `brandId` was passed in (e.g.
|
|
24
|
+
* scheduled-job StartingPayloads), and stamp `currentDate` so prompts can
|
|
25
|
+
* reference it.
|
|
26
|
+
*
|
|
27
|
+
* 3. Template-data plumbing — copy the top-level payload keys
|
|
28
|
+
* (brandId / brandName / companyId / currentDate / mode / instructions /
|
|
29
|
+
* authorizedBrands) into the prompt-render data so child templates that
|
|
30
|
+
* use `{{ brandId }}`, `{{ brandName }}`, etc. resolve.
|
|
31
|
+
*
|
|
32
|
+
* **Why `payload.companyId` survives the brand migration:** it is DERIVED from
|
|
33
|
+
* the resolved Brand's CompanyID and is never a scope of its own. Two
|
|
34
|
+
* downstreams genuinely need the parent company: (a) the
|
|
35
|
+
* `MarketingStrategySpec` contract in marketing-core still carries a required
|
|
36
|
+
* `companyId`, and (b) MJ-core `CompanyIntegration` lookups are company-level
|
|
37
|
+
* by definition. Nothing may use it to scope marketing-schema rows — those all
|
|
38
|
+
* carry BrandID.
|
|
39
|
+
*
|
|
40
|
+
* Subclasses can extend `initializeStartingPayload` for additional context
|
|
41
|
+
* loading (CMO does this for marketing-overview state).
|
|
42
|
+
*/
|
|
43
|
+
export class BaseMarketingAgent extends BaseAgent {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
/** One settle per run — preparePromptParams fires every turn. */
|
|
47
|
+
this.answeredRequestsSettled = false;
|
|
48
|
+
}
|
|
49
|
+
async initializeStartingPayload(params) {
|
|
50
|
+
await super.initializeStartingPayload(params);
|
|
51
|
+
// A RESUMED run (core's answer-a-request-then-resume path) arrives with no payload
|
|
52
|
+
// but with lastRunId + autoPopulateLastRunPayload, expecting the prior run's
|
|
53
|
+
// FinalPayload back. Core performs that restore in initializeAgentRun — AFTER this
|
|
54
|
+
// hook — and only `if (!params.payload)`. Creating the empty object below therefore
|
|
55
|
+
// silently cancelled the restore: the resumed run lost its brand, interview state
|
|
56
|
+
// and spec and asked "Which brand?" straight after a successful publish
|
|
57
|
+
// (2026-09-18). Restore it here, first, so everything below runs on the real payload.
|
|
58
|
+
if (!params.payload && params.lastRunId && params.autoPopulateLastRunPayload) {
|
|
59
|
+
await this.restoreLastRunPayload(params);
|
|
60
|
+
}
|
|
61
|
+
// The generic conversations flow passes no payload at all — create one
|
|
62
|
+
// so brand resolution and the date stamp have somewhere to live.
|
|
63
|
+
if (!params.payload) {
|
|
64
|
+
params.payload = {};
|
|
65
|
+
}
|
|
66
|
+
const payload = params.payload;
|
|
67
|
+
// Always stamp currentDate (idempotent — payload value wins if already set).
|
|
68
|
+
if (!payload.currentDate) {
|
|
69
|
+
payload.currentDate = new Date().toISOString().split('T')[0];
|
|
70
|
+
}
|
|
71
|
+
// Payload values can be LLM/client-influenced; a malformed id must never
|
|
72
|
+
// reach an ExtraFilter. Clear it and let the ladder below re-resolve —
|
|
73
|
+
// the action gate would reject it anyway.
|
|
74
|
+
if (payload.brandId !== undefined && !isUuid(payload.brandId)) {
|
|
75
|
+
LogError(`${this.constructor.name}: payload.brandId is not a UUID — clearing`);
|
|
76
|
+
delete payload.brandId;
|
|
77
|
+
}
|
|
78
|
+
// companyId is derived, never an input scope — a stale/hand-passed value
|
|
79
|
+
// is dropped so it can only ever come from the resolved Brand row.
|
|
80
|
+
if (payload.companyId !== undefined && !isUuid(payload.companyId)) {
|
|
81
|
+
delete payload.companyId;
|
|
82
|
+
}
|
|
83
|
+
if (!params.contextUser)
|
|
84
|
+
return;
|
|
85
|
+
// Brand self-resolution ladder: explicit payload.brandId wins (workspace
|
|
86
|
+
// brand switcher / scheduled jobs); otherwise resolve from the caller's
|
|
87
|
+
// grants — PREFERRING the brand the embedding app says the user is looking
|
|
88
|
+
// at (the in-app chat passes the brand already selected in the app chrome,
|
|
89
|
+
// so the agent must not re-ask; product ruling 2026-09-15) when, and only
|
|
90
|
+
// when, it is among those grants. appContext is client input: a brand id is
|
|
91
|
+
// a SCOPE, and taking it unverified would let a client widen its own access.
|
|
92
|
+
if (!payload.brandId) {
|
|
93
|
+
await this.resolveBrandFromGrants(payload, params.contextUser, this.brandFromAppContext(params));
|
|
94
|
+
}
|
|
95
|
+
// Hydrate brandName + the derived parent companyId for an explicitly
|
|
96
|
+
// passed brandId (the grant path already fills both).
|
|
97
|
+
if (payload.brandId && (!payload.brandName || !payload.companyId)) {
|
|
98
|
+
await this.hydrateBrandContext(payload, params.contextUser);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Loads the prior run's FinalPayload onto `params.payload` — the same restore core's
|
|
103
|
+
* initializeAgentRun performs, done early because this class must populate the payload
|
|
104
|
+
* before core gets the chance. A missing or unparseable payload leaves `params.payload`
|
|
105
|
+
* unset, and the normal empty-payload path takes over.
|
|
106
|
+
*/
|
|
107
|
+
async restoreLastRunPayload(params) {
|
|
108
|
+
try {
|
|
109
|
+
const rv = new RunView();
|
|
110
|
+
const res = await rv.RunView({
|
|
111
|
+
EntityName: 'MJ: AI Agent Runs',
|
|
112
|
+
ExtraFilter: `ID='${EscapeSQLString(params.lastRunId)}'`,
|
|
113
|
+
Fields: ['FinalPayload'],
|
|
114
|
+
MaxRows: 1,
|
|
115
|
+
ResultType: 'simple',
|
|
116
|
+
}, params.contextUser);
|
|
117
|
+
const raw = res.Success ? res.Results?.[0]?.FinalPayload : null;
|
|
118
|
+
if (!raw)
|
|
119
|
+
return;
|
|
120
|
+
params.payload = JSON.parse(raw);
|
|
121
|
+
LogStatus(`${this.constructor.name}: restored the payload of run ${params.lastRunId} for this resumed run`);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
LogError(`${this.constructor.name}: could not restore the payload of run ${params.lastRunId} — starting from an empty payload`, undefined, error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The brand the EMBEDDING APP says the user is looking at —
|
|
129
|
+
* `appContext.AdditionalContext.BrandID`, set by the marketing app's chat
|
|
130
|
+
* panel from its brand picker. Authoritative over grant-derivation (the
|
|
131
|
+
* user already chose), but still just client input: UUID-validated here and
|
|
132
|
+
* access-checked by every action's gate exactly like any other brandId.
|
|
133
|
+
*/
|
|
134
|
+
brandFromAppContext(params) {
|
|
135
|
+
const data = params.data;
|
|
136
|
+
const appContext = data?.appContext;
|
|
137
|
+
const brandId = appContext?.AdditionalContext?.BrandID;
|
|
138
|
+
if (brandId === undefined || brandId === null)
|
|
139
|
+
return null;
|
|
140
|
+
if (!isUuid(brandId)) {
|
|
141
|
+
LogError(`${this.constructor.name}: appContext BrandID is not a UUID — ignoring`);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return brandId;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Derive brand context from the caller's marketing grants.
|
|
148
|
+
*
|
|
149
|
+
* `resolveAuthorizedBrands` is THE source of truth for what a user may
|
|
150
|
+
* reach: it reads AuthorizedUser and expands company-level grants to every
|
|
151
|
+
* brand of that company, so a "Blue Cypress person" who oversees Sidecar,
|
|
152
|
+
* Izzy and Skip lands here with three brands, not one company.
|
|
153
|
+
*
|
|
154
|
+
* Failure is non-fatal: the agent simply runs without brand context and the
|
|
155
|
+
* prompt instructs it to say so.
|
|
156
|
+
*/
|
|
157
|
+
async resolveBrandFromGrants(payload, contextUser, preferredBrandId = null) {
|
|
158
|
+
const userId = contextUser.ID;
|
|
159
|
+
try {
|
|
160
|
+
const grants = await resolveAuthorizedBrands(contextUser);
|
|
161
|
+
if (grants.length === 0) {
|
|
162
|
+
LogStatus(`${this.constructor.name}: user ${userId} has no marketing brand grants — running without brand context`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const brands = await this.loadBrands(grants.map(g => g.BrandID), contextUser);
|
|
166
|
+
if (brands.length === 0) {
|
|
167
|
+
LogStatus(`${this.constructor.name}: user ${userId} holds ${grants.length} grant(s) but no matching active Brand rows — running without brand context`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// EVERY path publishes the full authorized set: subclass shells verify any
|
|
171
|
+
// claimed brandId against it (the onboarding shell refuses a brand it cannot
|
|
172
|
+
// find here — seen live when only brandId was set), and a multi-brand agent
|
|
173
|
+
// asks from it.
|
|
174
|
+
payload.authorizedBrands = this.toBrandOptions(brands, grants);
|
|
175
|
+
if (preferredBrandId) {
|
|
176
|
+
const preferred = brands.find(b => UUIDsEqual(b.ID, preferredBrandId));
|
|
177
|
+
if (preferred) {
|
|
178
|
+
this.applyBrand(payload, preferred);
|
|
179
|
+
LogStatus(`${this.constructor.name}: brandId=${preferred.ID} ("${preferred.BrandName}") taken from the embedding app's context for user ${userId}`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
LogError(`${this.constructor.name}: appContext BrandID ${preferredBrandId} is not among user ${userId}'s grants — ignoring it`);
|
|
183
|
+
}
|
|
184
|
+
if (brands.length === 1) {
|
|
185
|
+
this.applyBrand(payload, brands[0]);
|
|
186
|
+
LogStatus(`${this.constructor.name}: auto-resolved brandId=${brands[0].ID} ("${brands[0].BrandName}") — sole authorized brand for user ${userId}`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// Several brands: don't guess. The grounded options (brand name AND company
|
|
190
|
+
// name — brand names collide across companies) are already on the payload
|
|
191
|
+
// so the agent's first turn can ask which brand to work on.
|
|
192
|
+
LogStatus(`${this.constructor.name}: user ${userId} is authorized for ${brands.length} brands — leaving brandId unset for the agent to ask`);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
LogError(`${this.constructor.name}: brand grant resolution failed — running without brand context`, undefined, error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Fill brandName + the derived parent companyId for an already-known
|
|
200
|
+
* brandId. Protected because a subclass shell can resolve the brand LATER
|
|
201
|
+
* than initializeStartingPayload (the onboarding driver matches a brand
|
|
202
|
+
* name out of the conversation) and must be able to hydrate the rest of
|
|
203
|
+
* the context the same way. Clears `payload.brandId` when it doesn't
|
|
204
|
+
* resolve to an active Brand the caller can see.
|
|
205
|
+
*/
|
|
206
|
+
async hydrateBrandContext(payload, contextUser) {
|
|
207
|
+
const brandId = payload.brandId;
|
|
208
|
+
try {
|
|
209
|
+
const brands = await this.loadBrands([brandId], contextUser);
|
|
210
|
+
if (brands.length === 0) {
|
|
211
|
+
LogError(`${this.constructor.name}: brandId=${brandId} did not resolve to an active Brand row — clearing brand context`);
|
|
212
|
+
delete payload.brandId;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.applyBrand(payload, brands[0]);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
LogError(`${this.constructor.name}: brand hydration failed for brandId=${brandId}`, undefined, error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Load active Brand rows by id. Empty id list short-circuits (no query). */
|
|
222
|
+
async loadBrands(brandIds, contextUser) {
|
|
223
|
+
const safe = brandIds.filter(isUuid);
|
|
224
|
+
if (safe.length === 0)
|
|
225
|
+
return [];
|
|
226
|
+
const rv = new RunView();
|
|
227
|
+
const result = await rv.RunView({
|
|
228
|
+
EntityName: toMarketingEntityName('Brands'),
|
|
229
|
+
ExtraFilter: `ID IN (${safe.map(id => `'${id}'`).join(',')}) AND IsActive=1`,
|
|
230
|
+
ResultType: 'simple',
|
|
231
|
+
Fields: ['ID', 'BrandName', 'CompanyID', 'Company'],
|
|
232
|
+
OrderBy: 'BrandName',
|
|
233
|
+
MaxRows: 500,
|
|
234
|
+
}, contextUser);
|
|
235
|
+
if (!result.Success) {
|
|
236
|
+
LogError(`${this.constructor.name}: Brand lookup failed: ${result.ErrorMessage}`);
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
return result.Results ?? [];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Stamp the resolved brand onto the payload. `companyId` is the brand's
|
|
243
|
+
* PARENT company, derived here and only here — it exists for the
|
|
244
|
+
* MarketingStrategySpec contract and MJ-core CompanyIntegration lookups,
|
|
245
|
+
* never to scope marketing-schema rows (those are BrandID-scoped).
|
|
246
|
+
*/
|
|
247
|
+
applyBrand(payload, brand) {
|
|
248
|
+
payload.brandId = brand.ID;
|
|
249
|
+
payload.brandName = brand.BrandName;
|
|
250
|
+
payload.companyId = brand.CompanyID;
|
|
251
|
+
}
|
|
252
|
+
toBrandOptions(brands, grants) {
|
|
253
|
+
const roleByBrand = new Map(grants.map(g => [g.BrandID.toLowerCase(), g.Role]));
|
|
254
|
+
return brands.map(b => ({
|
|
255
|
+
brandId: b.ID,
|
|
256
|
+
name: b.BrandName,
|
|
257
|
+
companyName: b.Company,
|
|
258
|
+
role: roleByBrand.get(b.ID.toLowerCase()) ?? null,
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* A run that starts inside a conversation IS the user's answer to whatever this agent was
|
|
263
|
+
* waiting on there. Core only records that when the caller sends `lastRunId`, which the
|
|
264
|
+
* conversation UI never does — so this agent closes its own open Chat-step requests (and
|
|
265
|
+
* their "needs your input" notifications). Runs here, not in initializeStartingPayload,
|
|
266
|
+
* because the run row — whose id the request is linked to — does not exist until later.
|
|
267
|
+
*/
|
|
268
|
+
async settleAnsweredRequestsOnce(params) {
|
|
269
|
+
if (this.answeredRequestsSettled)
|
|
270
|
+
return;
|
|
271
|
+
const run = this.AgentRun;
|
|
272
|
+
if (!run?.ID || !run.ConversationID || !params.contextUser)
|
|
273
|
+
return;
|
|
274
|
+
this.answeredRequestsSettled = true;
|
|
275
|
+
const lastUser = [...(params.conversationMessages ?? [])].reverse().find(m => m.role === 'user');
|
|
276
|
+
await closeAnsweredFeedbackRequests({
|
|
277
|
+
runId: run.ID,
|
|
278
|
+
agentId: params.agent.ID,
|
|
279
|
+
conversationId: run.ConversationID,
|
|
280
|
+
userMessage: typeof lastUser?.content === 'string' ? lastUser.content : null,
|
|
281
|
+
contextUser: params.contextUser,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
async preparePromptParams(config, payload, params) {
|
|
285
|
+
const result = await super.preparePromptParams(config, payload, params);
|
|
286
|
+
await this.settleAnsweredRequestsOnce(params);
|
|
287
|
+
const p = payload;
|
|
288
|
+
if (!p || !result.data)
|
|
289
|
+
return result;
|
|
290
|
+
// companyId is exposed to templates only as the brand's parent company
|
|
291
|
+
// (CompanyIntegration-scoped tooling); brandId is the marketing scope.
|
|
292
|
+
for (const key of ['brandId', 'brandName', 'companyId', 'currentDate', 'mode', 'instructions', 'authorizedBrands', 'proposalMode']) {
|
|
293
|
+
if (p[key] !== undefined && p[key] !== null) {
|
|
294
|
+
result.data[key] = p[key];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Copy any guidance payload key (e.g. `guidanceProgramScoring`) into the
|
|
298
|
+
// prompt-render data so templates can inject deterministic decision-point
|
|
299
|
+
// guidance via `{{ guidanceProgramScoring }}`. Subclasses populate these
|
|
300
|
+
// in initializeStartingPayload (see ExperimentationAgent).
|
|
301
|
+
for (const key of Object.keys(p)) {
|
|
302
|
+
if (key.startsWith('guidance') && p[key] != null) {
|
|
303
|
+
result.data[key] = p[key];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
async validateSuccessNextStep(params, nextStep, currentPayload, agentRun, currentStep) {
|
|
309
|
+
const baseResult = await super.validateSuccessNextStep(params, nextStep, currentPayload, agentRun, currentStep);
|
|
310
|
+
if (baseResult.step === 'Retry') {
|
|
311
|
+
LogStatus(`${this.constructor.name}: Step requires retry - ${currentStep.ID}`);
|
|
312
|
+
return baseResult;
|
|
313
|
+
}
|
|
314
|
+
const payload = currentPayload;
|
|
315
|
+
if (payload && payload['_subAgentError']) {
|
|
316
|
+
const errorMsg = payload['_subAgentError'];
|
|
317
|
+
LogError(`${this.constructor.name}: Sub-agent failure detected: ${errorMsg}`);
|
|
318
|
+
}
|
|
319
|
+
return baseResult;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
export function LoadBaseMarketingAgent() { }
|
|
323
|
+
//# sourceMappingURL=BaseMarketingAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseMarketingAgent.js","sourceRoot":"","sources":["../../src/agents/BaseMarketingAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,EAAE,uBAAuB,EAAE,qBAAqB,EAAmB,MAAM,6BAA6B,CAAC;AA0BrJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAAjD;;QAkOI,iEAAiE;QACzD,4BAAuB,GAAG,KAAK,CAAC;IA6E5C,CAAC;IA/SsB,KAAK,CAAC,yBAAyB,CAAc,MAAsC;QAClG,MAAM,KAAK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