@signaliz/sdk 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -38,6 +38,8 @@ __export(index_exports, {
38
38
  createCampaignBuilderAgentPlan: () => createCampaignBuilderAgentPlan,
39
39
  createCampaignBuilderAgentRequestTemplate: () => createCampaignBuilderAgentRequestTemplate,
40
40
  createCampaignBuilderApproval: () => createCampaignBuilderApproval,
41
+ createCampaignBuilderProofReceipt: () => createCampaignBuilderProofReceipt,
42
+ createCampaignBuilderReadiness: () => createCampaignBuilderReadiness,
41
43
  createCampaignBuilderToolRoute: () => createCampaignBuilderToolRoute,
42
44
  getCampaignBuilderOperatingPlaybook: () => getCampaignBuilderOperatingPlaybook,
43
45
  getCampaignBuilderOperatingPlaybooksForRequest: () => getCampaignBuilderOperatingPlaybooksForRequest,
@@ -1240,6 +1242,13 @@ var DEFAULT_CAMPAIGN_BUILDER_BUILT_INS = [
1240
1242
  "email_verification",
1241
1243
  "signals"
1242
1244
  ];
1245
+ var CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS = {
1246
+ lead_generation: "signaliz-lead-generation",
1247
+ local_leads: "signaliz-local-leads",
1248
+ email_finding: "signaliz-email-finding",
1249
+ email_verification: "signaliz-email-verification",
1250
+ signals: "signaliz-signals"
1251
+ };
1243
1252
  var DEFAULT_CAMPAIGN_BUILDER_APPROVAL_TYPES = [
1244
1253
  "memory_retrieval",
1245
1254
  "spend",
@@ -1736,6 +1745,17 @@ var CampaignBuilderAgent = class {
1736
1745
  }
1737
1746
  return plan;
1738
1747
  }
1748
+ async readiness(request, options = {}) {
1749
+ const plan = await this.createPlan(request, options);
1750
+ return createCampaignBuilderReadiness(plan);
1751
+ }
1752
+ async proof(request, options = {}) {
1753
+ const plan = await this.createPlan(request, options);
1754
+ const result = await this.dryRunPlan(plan, {
1755
+ idempotencyKey: options.idempotencyKey
1756
+ });
1757
+ return createCampaignBuilderProofReceipt(plan, result);
1758
+ }
1739
1759
  async commitPlan(plan, options = {}) {
1740
1760
  const writeMode = options.confirm === true && options.dryRun === false;
1741
1761
  if (writeMode && !options.approvedBy) {
@@ -2096,6 +2116,157 @@ function createCampaignBuilderAgentPlan(request, context = {}) {
2096
2116
  warnings: context.warnings ?? []
2097
2117
  };
2098
2118
  }
2119
+ function createCampaignBuilderReadiness(plan) {
2120
+ const lanes = plan.routes.map((route) => createCampaignBuilderReadinessLane(route, plan));
2121
+ const builtInLanes = lanes.filter((lane) => lane.builtIn);
2122
+ const customRoutes = lanes.filter((lane) => lane.customRoute);
2123
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
2124
+ const deliveryRisk = asRecord(plan.buildRequest.deliveryRisk);
2125
+ const deliveryRiskBlockers = arrayOfStrings(deliveryRisk.blockers) ?? [];
2126
+ const deliveryRiskValue = asRecord(deliveryRisk.risk);
2127
+ const deliveryRiskLevel = stringValue(deliveryRiskValue.risk_level ?? deliveryRiskValue.riskLevel);
2128
+ const memoryReady = !plan.strategyMemoryStatus || strategyMemory.ready !== false;
2129
+ const kernelPlanReady = Object.keys(asRecord(plan.kernelPlan)).length > 0;
2130
+ const deliveryRiskReady = !plan.buildRequest.deliveryRisk || deliveryRiskBlockers.length === 0 && !["high", "critical", "blocked"].includes(String(deliveryRiskLevel ?? "").toLowerCase());
2131
+ const builtInsReady = builtInLanes.length > 0 && builtInLanes.every((lane) => lane.ready);
2132
+ const customRoutesReady = customRoutes.every((lane) => lane.ready);
2133
+ const approvalGatesReady = plan.approvals.length > 0;
2134
+ const gates = [
2135
+ {
2136
+ id: "campaign_plan_created",
2137
+ label: "Campaign plan created",
2138
+ passed: Boolean(plan.planId && plan.mcpFlow.length > 0),
2139
+ detail: plan.planId ? `Plan ${plan.planId} has ${plan.mcpFlow.length} MCP step(s).` : "No campaign-builder plan was created."
2140
+ },
2141
+ {
2142
+ id: "built_in_lanes_ready",
2143
+ label: "Built-in lanes ready",
2144
+ passed: builtInsReady,
2145
+ detail: `${builtInLanes.filter((lane) => lane.ready).length}/${builtInLanes.length} Signaliz built-in lane(s) are present.`
2146
+ },
2147
+ {
2148
+ id: "strategy_memory_ready",
2149
+ label: "Strategy memory ready",
2150
+ passed: memoryReady,
2151
+ detail: plan.strategyMemoryStatus ? "Strategy memory readiness was checked." : "Strategy memory readiness was not requested."
2152
+ },
2153
+ {
2154
+ id: "kernel_plan_attached",
2155
+ label: "Kernel plan attached",
2156
+ passed: kernelPlanReady,
2157
+ detail: kernelPlanReady ? "Kernel planner evidence is attached." : "Kernel planner evidence is not attached."
2158
+ },
2159
+ {
2160
+ id: "delivery_risk_clear",
2161
+ label: "Delivery risk clear",
2162
+ passed: deliveryRiskReady,
2163
+ detail: plan.buildRequest.deliveryRisk ? `Delivery risk is ${deliveryRiskLevel || "available"} with ${deliveryRiskBlockers.length} blocker(s).` : "Delivery risk preflight was not requested."
2164
+ },
2165
+ {
2166
+ id: "custom_routes_prepared",
2167
+ label: "Custom routes prepared",
2168
+ passed: customRoutesReady,
2169
+ detail: customRoutes.length === 0 ? "No BYO routes were requested." : `${customRoutes.filter((lane) => lane.ready).length}/${customRoutes.length} BYO route(s) have read-only setup steps.`
2170
+ },
2171
+ {
2172
+ id: "approval_gates_present",
2173
+ label: "Approval gates present",
2174
+ passed: approvalGatesReady,
2175
+ detail: approvalGatesReady ? `${plan.approvals.length} approval gate(s) are attached.` : "No approval gates are attached."
2176
+ }
2177
+ ];
2178
+ const blockers = [
2179
+ ...gates.filter((gate) => !gate.passed).map((gate) => gate.detail),
2180
+ ...lanes.flatMap((lane) => lane.blockers)
2181
+ ];
2182
+ const score = gates.length === 0 ? 0 : Math.round(gates.filter((gate) => gate.passed).length / gates.length * 100);
2183
+ const ready = blockers.length === 0;
2184
+ return {
2185
+ plan,
2186
+ lanes,
2187
+ gates,
2188
+ summary: {
2189
+ ready,
2190
+ score,
2191
+ targetCount: plan.targetCount,
2192
+ estimatedCredits: plan.estimatedCredits,
2193
+ builtInLanesReady: builtInLanes.filter((lane) => lane.ready).length,
2194
+ builtInLanesTotal: builtInLanes.length,
2195
+ customRoutesReady: customRoutes.filter((lane) => lane.ready).length,
2196
+ customRoutesTotal: customRoutes.length,
2197
+ approvalGateCount: plan.approvals.length,
2198
+ blockers,
2199
+ warnings: plan.warnings
2200
+ },
2201
+ nextActions: campaignReadinessNextActions(plan, ready, customRoutes.length)
2202
+ };
2203
+ }
2204
+ function createCampaignBuilderProofReceipt(plan, result) {
2205
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
2206
+ const dryRunResult = asRecord(result);
2207
+ const memoryReady = plan.strategyMemoryStatus ? strategyMemory.ready !== false : false;
2208
+ const dryRunCompleted = dryRunResult.dryRun === true || dryRunResult.dry_run === true || dryRunResult.status === "dry_run";
2209
+ const noLaunch = dryRunCompleted && !dryRunResult.campaignBuildId && !dryRunResult.campaign_build_id;
2210
+ const gates = [
2211
+ {
2212
+ id: "strategy_memory_ready",
2213
+ passed: memoryReady,
2214
+ ready: strategyMemory.ready ?? null,
2215
+ blocker_count: Array.isArray(strategyMemory.blockers) ? strategyMemory.blockers.length : 0
2216
+ },
2217
+ {
2218
+ id: "campaign_plan_ready",
2219
+ passed: Boolean(plan.planId && plan.mcpFlow.length > 0),
2220
+ plan_id: plan.planId,
2221
+ flow_steps: plan.mcpFlow.length
2222
+ },
2223
+ {
2224
+ id: "approval_gates_present",
2225
+ passed: plan.approvals.length > 0,
2226
+ approval_types: plan.approvals.map((approval) => approval.type)
2227
+ },
2228
+ {
2229
+ id: "dry_run_completed",
2230
+ passed: dryRunCompleted,
2231
+ status: dryRunResult.status ?? null,
2232
+ current_phase: dryRunResult.currentPhase ?? dryRunResult.current_phase ?? null
2233
+ },
2234
+ {
2235
+ id: "no_spendful_launch",
2236
+ passed: noLaunch,
2237
+ campaign_build_id: dryRunResult.campaignBuildId ?? dryRunResult.campaign_build_id ?? null
2238
+ }
2239
+ ];
2240
+ return {
2241
+ receipt_version: "campaign-agent-proof.v1",
2242
+ source: "signaliz.campaignBuilderAgent.proof",
2243
+ success: gates.every((gate) => gate.passed),
2244
+ safety: {
2245
+ spendful_tools_called: false,
2246
+ external_writes_called: false,
2247
+ sender_loads_called: false,
2248
+ email_sends_called: false,
2249
+ dry_run_only: true
2250
+ },
2251
+ campaign: {
2252
+ plan_id: plan.planId,
2253
+ campaign_name: plan.campaignName,
2254
+ strategy_template: campaignBuilderProofStrategyTemplate(plan),
2255
+ target_count: plan.targetCount,
2256
+ estimated_credits: plan.estimatedCredits,
2257
+ operating_playbooks: plan.operatingPlaybooks.map((playbook) => playbook.slug)
2258
+ },
2259
+ gates,
2260
+ strategy_memory_status: summarizeCampaignBuilderProofStrategyMemory(strategyMemory),
2261
+ dry_run_result: summarizeCampaignBuilderProofDryRun(dryRunResult),
2262
+ recommended_next_actions: [
2263
+ "Review the plan, approvals, and dry-run result.",
2264
+ "Use campaign-agent commit-plan --confirm-write only after review.",
2265
+ "Use campaign-agent build-approved only with --confirm-launch, approval identity, approval types, and spend limit.",
2266
+ "When an approved build reaches pending_approval, review rows and approve delivery through the Campaigns SDK."
2267
+ ]
2268
+ };
2269
+ }
2099
2270
  function getMissingCampaignBuilderApprovals(plan, approval) {
2100
2271
  if (approval.planId !== plan.planId) {
2101
2272
  return plan.approvals;
@@ -3473,6 +3644,137 @@ function campaignReviewRowHasCopy(row) {
3473
3644
  stringValue(data.subject) || stringValue(data.subject_line) || stringValue(data.subjectLine) || stringValue(data.opener) || stringValue(data.body) || stringValue(data.cta) || stringValue(copy.subject) || stringValue(copy.body) || stringValue(rawCopy.subject) || stringValue(rawCopy.body)
3474
3645
  );
3475
3646
  }
3647
+ function createCampaignBuilderReadinessLane(route, plan) {
3648
+ const builtIn = campaignBuilderBuiltInForRoute(route);
3649
+ const customRoute = route.provider !== "signaliz" && route.provider !== "csv" && builtIn === void 0;
3650
+ const prepareStep = plan.mcpFlow.find(
3651
+ (step) => step.tool === "gtm_provider_recipe_prepare" && step.arguments.provider_id === route.provider
3652
+ );
3653
+ const activateStep = plan.mcpFlow.find(
3654
+ (step) => step.tool === "gtm_provider_route_activate" && step.arguments.provider_id === route.provider
3655
+ );
3656
+ const readOnlySetup = !customRoute || prepareStep?.readOnly === true && activateStep?.readOnly === true && activateStep.arguments.dry_run === true && activateStep.arguments.confirm === false;
3657
+ const blockers = [
3658
+ customRoute && !prepareStep ? `${route.label ?? route.provider} is missing provider recipe setup.` : void 0,
3659
+ customRoute && !activateStep ? `${route.label ?? route.provider} is missing provider route dry-run setup.` : void 0,
3660
+ customRoute && !readOnlySetup ? `${route.label ?? route.provider} route setup must stay read-only before approval.` : void 0,
3661
+ route.mode === "required" && !route.toolName && customRoute ? `${route.label ?? route.provider} is required but has no tool name.` : void 0
3662
+ ].filter((item) => Boolean(item));
3663
+ return {
3664
+ id: route.id ?? `${route.provider}-${route.layer}`,
3665
+ label: route.label ?? readinessLaneLabel(route, builtIn),
3666
+ layer: route.layer,
3667
+ gtmLayers: gtmLayersForRoute(route),
3668
+ provider: route.provider,
3669
+ toolName: route.toolName,
3670
+ mode: route.mode ?? "if_available",
3671
+ builtIn,
3672
+ approvalRequired: route.approvalRequired === true || plan.approvals.some((approval) => approval.routeId === route.id),
3673
+ customRoute,
3674
+ readOnlySetup,
3675
+ ready: blockers.length === 0,
3676
+ blockers,
3677
+ nextAction: customRoute ? `Review ${route.provider} route setup before launch approval.` : void 0
3678
+ };
3679
+ }
3680
+ function campaignBuilderBuiltInForRoute(route) {
3681
+ return Object.entries(CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS).find(([, routeId]) => route.id === routeId)?.[0];
3682
+ }
3683
+ function readinessLaneLabel(route, builtIn) {
3684
+ if (builtIn) {
3685
+ const labels = {
3686
+ lead_generation: "Signaliz lead generation",
3687
+ local_leads: "Signaliz local leads",
3688
+ email_finding: "Signaliz email finding",
3689
+ email_verification: "Signaliz email verification",
3690
+ signals: "Signaliz signals"
3691
+ };
3692
+ return labels[builtIn];
3693
+ }
3694
+ return `${route.provider} ${route.layer}`;
3695
+ }
3696
+ function campaignReadinessNextActions(plan, ready, customRouteCount) {
3697
+ const requestHint = "--request-file campaign-request.json";
3698
+ if (ready) {
3699
+ return [
3700
+ `signaliz campaign-agent proof ${requestHint} --json`,
3701
+ `signaliz campaign-agent commit-plan ${requestHint} --json`,
3702
+ `signaliz campaign-agent build-approved ${requestHint} --confirm-launch --approve-all --approved-by operator@example.com --spend-limit ${plan.estimatedCredits}`
3703
+ ];
3704
+ }
3705
+ const actions = [
3706
+ plan.strategyMemoryStatus && asRecord(plan.strategyMemoryStatus).ready === false ? "signaliz gtm strategy-memory --strategy-template <strategy_template> --include-samples --json" : void 0,
3707
+ customRouteCount > 0 ? "Review BYO provider recipe and route dry-run steps in the readiness packet." : void 0,
3708
+ `signaliz campaign-agent plan ${requestHint} --json`
3709
+ ];
3710
+ return actions.filter((item) => Boolean(item));
3711
+ }
3712
+ function campaignBuilderProofStrategyTemplate(plan) {
3713
+ const buildRequest = asRecord(plan.buildRequest);
3714
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
3715
+ const statusTemplate = strategyMemory.strategy_template ?? strategyMemory.strategyTemplate;
3716
+ const statusTemplateRecord = asRecord(statusTemplate);
3717
+ const flowTemplate = plan.mcpFlow.map((step) => asRecord(step.arguments).strategy_template ?? asRecord(step.arguments).strategyTemplate).find((value) => typeof value === "string" && value.trim());
3718
+ return firstNonEmptyString(
3719
+ buildRequest.strategyTemplate,
3720
+ buildRequest.strategy_template,
3721
+ statusTemplate,
3722
+ statusTemplateRecord.slug,
3723
+ statusTemplateRecord.id,
3724
+ flowTemplate
3725
+ );
3726
+ }
3727
+ function summarizeCampaignBuilderProofStrategyMemory(strategyMemory) {
3728
+ if (Object.keys(strategyMemory).length === 0) return { ready: false };
3729
+ const template = strategyMemory.strategy_template ?? strategyMemory.strategyTemplate;
3730
+ const templateRecord = asRecord(template);
3731
+ const coverage = asRecord(strategyMemory.coverage);
3732
+ const rawSourceGroups = Array.isArray(strategyMemory.source_groups) ? strategyMemory.source_groups : Array.isArray(strategyMemory.sourceGroups) ? strategyMemory.sourceGroups : [];
3733
+ const sourceGroups = rawSourceGroups.map((group) => {
3734
+ const sourceGroup = asRecord(group);
3735
+ return {
3736
+ id: sourceGroup.id ?? null,
3737
+ required: sourceGroup.required ?? null,
3738
+ ready: sourceGroup.ready ?? null,
3739
+ counts: asRecord(sourceGroup.counts)
3740
+ };
3741
+ });
3742
+ return {
3743
+ ready: strategyMemory.ready ?? null,
3744
+ read_only: strategyMemory.read_only ?? strategyMemory.readOnly ?? null,
3745
+ source_tool: firstNonEmptyString(strategyMemory.source_tool, strategyMemory.sourceTool),
3746
+ strategy_template: {
3747
+ slug: firstNonEmptyString(template, templateRecord.slug, templateRecord.id),
3748
+ label: firstNonEmptyString(templateRecord.label)
3749
+ },
3750
+ coverage: {
3751
+ required_groups_ready: coverage.required_groups_ready ?? coverage.requiredGroupsReady ?? null,
3752
+ required_groups_total: coverage.required_groups_total ?? coverage.requiredGroupsTotal ?? null,
3753
+ source_groups_ready: coverage.source_groups_ready ?? coverage.sourceGroupsReady ?? null,
3754
+ source_groups_total: coverage.source_groups_total ?? coverage.sourceGroupsTotal ?? null,
3755
+ knowledge_docs: coverage.knowledge_docs ?? coverage.knowledgeDocs ?? null,
3756
+ memories: coverage.memories ?? null
3757
+ },
3758
+ source_groups: sourceGroups,
3759
+ blocker_count: Array.isArray(strategyMemory.blockers) ? strategyMemory.blockers.length : 0,
3760
+ warning_count: Array.isArray(strategyMemory.warnings) ? strategyMemory.warnings.length : 0
3761
+ };
3762
+ }
3763
+ function summarizeCampaignBuilderProofDryRun(dryRunResult) {
3764
+ return {
3765
+ dryRun: dryRunResult.dryRun ?? dryRunResult.dry_run ?? null,
3766
+ status: dryRunResult.status ?? null,
3767
+ currentPhase: dryRunResult.currentPhase ?? dryRunResult.current_phase ?? null,
3768
+ campaignBuildId: dryRunResult.campaignBuildId ?? dryRunResult.campaign_build_id ?? null,
3769
+ plannedTargetCount: dryRunResult.plannedTargetCount ?? dryRunResult.planned_target_count ?? null
3770
+ };
3771
+ }
3772
+ function firstNonEmptyString(...values) {
3773
+ for (const value of values) {
3774
+ if (typeof value === "string" && value.trim()) return value;
3775
+ }
3776
+ return null;
3777
+ }
3476
3778
  function diagnosticMessages2(value) {
3477
3779
  if (!Array.isArray(value)) return [];
3478
3780
  return value.map((item) => {
@@ -6492,6 +6794,8 @@ var Signaliz = class {
6492
6794
  createCampaignBuilderAgentPlan,
6493
6795
  createCampaignBuilderAgentRequestTemplate,
6494
6796
  createCampaignBuilderApproval,
6797
+ createCampaignBuilderProofReceipt,
6798
+ createCampaignBuilderReadiness,
6495
6799
  createCampaignBuilderToolRoute,
6496
6800
  getCampaignBuilderOperatingPlaybook,
6497
6801
  getCampaignBuilderOperatingPlaybooksForRequest,
package/dist/index.mjs CHANGED
@@ -17,13 +17,15 @@ import {
17
17
  createCampaignBuilderAgentPlan,
18
18
  createCampaignBuilderAgentRequestTemplate,
19
19
  createCampaignBuilderApproval,
20
+ createCampaignBuilderProofReceipt,
21
+ createCampaignBuilderReadiness,
20
22
  createCampaignBuilderToolRoute,
21
23
  getCampaignBuilderOperatingPlaybook,
22
24
  getCampaignBuilderOperatingPlaybooksForRequest,
23
25
  getCampaignBuilderStrategyTemplate,
24
26
  getMissingCampaignBuilderApprovals,
25
27
  normalizeExecutionReference
26
- } from "./chunk-XJQ6KGNQ.mjs";
28
+ } from "./chunk-EVFQETTN.mjs";
27
29
  export {
28
30
  Ai,
29
31
  CAMPAIGN_BUILDER_OPERATING_PLAYBOOKS,
@@ -43,6 +45,8 @@ export {
43
45
  createCampaignBuilderAgentPlan,
44
46
  createCampaignBuilderAgentRequestTemplate,
45
47
  createCampaignBuilderApproval,
48
+ createCampaignBuilderProofReceipt,
49
+ createCampaignBuilderReadiness,
46
50
  createCampaignBuilderToolRoute,
47
51
  getCampaignBuilderOperatingPlaybook,
48
52
  getCampaignBuilderOperatingPlaybooksForRequest,