@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.
@@ -1222,6 +1222,13 @@ var DEFAULT_CAMPAIGN_BUILDER_BUILT_INS = [
1222
1222
  "email_verification",
1223
1223
  "signals"
1224
1224
  ];
1225
+ var CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS = {
1226
+ lead_generation: "signaliz-lead-generation",
1227
+ local_leads: "signaliz-local-leads",
1228
+ email_finding: "signaliz-email-finding",
1229
+ email_verification: "signaliz-email-verification",
1230
+ signals: "signaliz-signals"
1231
+ };
1225
1232
  var CAMPAIGN_BUILDER_OPERATING_PLAYBOOKS = [
1226
1233
  {
1227
1234
  slug: "cache-first-large-list",
@@ -1710,6 +1717,17 @@ var CampaignBuilderAgent = class {
1710
1717
  }
1711
1718
  return plan;
1712
1719
  }
1720
+ async readiness(request, options = {}) {
1721
+ const plan = await this.createPlan(request, options);
1722
+ return createCampaignBuilderReadiness(plan);
1723
+ }
1724
+ async proof(request, options = {}) {
1725
+ const plan = await this.createPlan(request, options);
1726
+ const result = await this.dryRunPlan(plan, {
1727
+ idempotencyKey: options.idempotencyKey
1728
+ });
1729
+ return createCampaignBuilderProofReceipt(plan, result);
1730
+ }
1713
1731
  async commitPlan(plan, options = {}) {
1714
1732
  const writeMode = options.confirm === true && options.dryRun === false;
1715
1733
  if (writeMode && !options.approvedBy) {
@@ -2070,6 +2088,157 @@ function createCampaignBuilderAgentPlan(request, context = {}) {
2070
2088
  warnings: context.warnings ?? []
2071
2089
  };
2072
2090
  }
2091
+ function createCampaignBuilderReadiness(plan) {
2092
+ const lanes = plan.routes.map((route) => createCampaignBuilderReadinessLane(route, plan));
2093
+ const builtInLanes = lanes.filter((lane) => lane.builtIn);
2094
+ const customRoutes = lanes.filter((lane) => lane.customRoute);
2095
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
2096
+ const deliveryRisk = asRecord(plan.buildRequest.deliveryRisk);
2097
+ const deliveryRiskBlockers = arrayOfStrings(deliveryRisk.blockers) ?? [];
2098
+ const deliveryRiskValue = asRecord(deliveryRisk.risk);
2099
+ const deliveryRiskLevel = stringValue(deliveryRiskValue.risk_level ?? deliveryRiskValue.riskLevel);
2100
+ const memoryReady = !plan.strategyMemoryStatus || strategyMemory.ready !== false;
2101
+ const kernelPlanReady = Object.keys(asRecord(plan.kernelPlan)).length > 0;
2102
+ const deliveryRiskReady = !plan.buildRequest.deliveryRisk || deliveryRiskBlockers.length === 0 && !["high", "critical", "blocked"].includes(String(deliveryRiskLevel ?? "").toLowerCase());
2103
+ const builtInsReady = builtInLanes.length > 0 && builtInLanes.every((lane) => lane.ready);
2104
+ const customRoutesReady = customRoutes.every((lane) => lane.ready);
2105
+ const approvalGatesReady = plan.approvals.length > 0;
2106
+ const gates = [
2107
+ {
2108
+ id: "campaign_plan_created",
2109
+ label: "Campaign plan created",
2110
+ passed: Boolean(plan.planId && plan.mcpFlow.length > 0),
2111
+ detail: plan.planId ? `Plan ${plan.planId} has ${plan.mcpFlow.length} MCP step(s).` : "No campaign-builder plan was created."
2112
+ },
2113
+ {
2114
+ id: "built_in_lanes_ready",
2115
+ label: "Built-in lanes ready",
2116
+ passed: builtInsReady,
2117
+ detail: `${builtInLanes.filter((lane) => lane.ready).length}/${builtInLanes.length} Signaliz built-in lane(s) are present.`
2118
+ },
2119
+ {
2120
+ id: "strategy_memory_ready",
2121
+ label: "Strategy memory ready",
2122
+ passed: memoryReady,
2123
+ detail: plan.strategyMemoryStatus ? "Strategy memory readiness was checked." : "Strategy memory readiness was not requested."
2124
+ },
2125
+ {
2126
+ id: "kernel_plan_attached",
2127
+ label: "Kernel plan attached",
2128
+ passed: kernelPlanReady,
2129
+ detail: kernelPlanReady ? "Kernel planner evidence is attached." : "Kernel planner evidence is not attached."
2130
+ },
2131
+ {
2132
+ id: "delivery_risk_clear",
2133
+ label: "Delivery risk clear",
2134
+ passed: deliveryRiskReady,
2135
+ detail: plan.buildRequest.deliveryRisk ? `Delivery risk is ${deliveryRiskLevel || "available"} with ${deliveryRiskBlockers.length} blocker(s).` : "Delivery risk preflight was not requested."
2136
+ },
2137
+ {
2138
+ id: "custom_routes_prepared",
2139
+ label: "Custom routes prepared",
2140
+ passed: customRoutesReady,
2141
+ 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.`
2142
+ },
2143
+ {
2144
+ id: "approval_gates_present",
2145
+ label: "Approval gates present",
2146
+ passed: approvalGatesReady,
2147
+ detail: approvalGatesReady ? `${plan.approvals.length} approval gate(s) are attached.` : "No approval gates are attached."
2148
+ }
2149
+ ];
2150
+ const blockers = [
2151
+ ...gates.filter((gate) => !gate.passed).map((gate) => gate.detail),
2152
+ ...lanes.flatMap((lane) => lane.blockers)
2153
+ ];
2154
+ const score = gates.length === 0 ? 0 : Math.round(gates.filter((gate) => gate.passed).length / gates.length * 100);
2155
+ const ready = blockers.length === 0;
2156
+ return {
2157
+ plan,
2158
+ lanes,
2159
+ gates,
2160
+ summary: {
2161
+ ready,
2162
+ score,
2163
+ targetCount: plan.targetCount,
2164
+ estimatedCredits: plan.estimatedCredits,
2165
+ builtInLanesReady: builtInLanes.filter((lane) => lane.ready).length,
2166
+ builtInLanesTotal: builtInLanes.length,
2167
+ customRoutesReady: customRoutes.filter((lane) => lane.ready).length,
2168
+ customRoutesTotal: customRoutes.length,
2169
+ approvalGateCount: plan.approvals.length,
2170
+ blockers,
2171
+ warnings: plan.warnings
2172
+ },
2173
+ nextActions: campaignReadinessNextActions(plan, ready, customRoutes.length)
2174
+ };
2175
+ }
2176
+ function createCampaignBuilderProofReceipt(plan, result) {
2177
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
2178
+ const dryRunResult = asRecord(result);
2179
+ const memoryReady = plan.strategyMemoryStatus ? strategyMemory.ready !== false : false;
2180
+ const dryRunCompleted = dryRunResult.dryRun === true || dryRunResult.dry_run === true || dryRunResult.status === "dry_run";
2181
+ const noLaunch = dryRunCompleted && !dryRunResult.campaignBuildId && !dryRunResult.campaign_build_id;
2182
+ const gates = [
2183
+ {
2184
+ id: "strategy_memory_ready",
2185
+ passed: memoryReady,
2186
+ ready: strategyMemory.ready ?? null,
2187
+ blocker_count: Array.isArray(strategyMemory.blockers) ? strategyMemory.blockers.length : 0
2188
+ },
2189
+ {
2190
+ id: "campaign_plan_ready",
2191
+ passed: Boolean(plan.planId && plan.mcpFlow.length > 0),
2192
+ plan_id: plan.planId,
2193
+ flow_steps: plan.mcpFlow.length
2194
+ },
2195
+ {
2196
+ id: "approval_gates_present",
2197
+ passed: plan.approvals.length > 0,
2198
+ approval_types: plan.approvals.map((approval) => approval.type)
2199
+ },
2200
+ {
2201
+ id: "dry_run_completed",
2202
+ passed: dryRunCompleted,
2203
+ status: dryRunResult.status ?? null,
2204
+ current_phase: dryRunResult.currentPhase ?? dryRunResult.current_phase ?? null
2205
+ },
2206
+ {
2207
+ id: "no_spendful_launch",
2208
+ passed: noLaunch,
2209
+ campaign_build_id: dryRunResult.campaignBuildId ?? dryRunResult.campaign_build_id ?? null
2210
+ }
2211
+ ];
2212
+ return {
2213
+ receipt_version: "campaign-agent-proof.v1",
2214
+ source: "signaliz.campaignBuilderAgent.proof",
2215
+ success: gates.every((gate) => gate.passed),
2216
+ safety: {
2217
+ spendful_tools_called: false,
2218
+ external_writes_called: false,
2219
+ sender_loads_called: false,
2220
+ email_sends_called: false,
2221
+ dry_run_only: true
2222
+ },
2223
+ campaign: {
2224
+ plan_id: plan.planId,
2225
+ campaign_name: plan.campaignName,
2226
+ strategy_template: campaignBuilderProofStrategyTemplate(plan),
2227
+ target_count: plan.targetCount,
2228
+ estimated_credits: plan.estimatedCredits,
2229
+ operating_playbooks: plan.operatingPlaybooks.map((playbook) => playbook.slug)
2230
+ },
2231
+ gates,
2232
+ strategy_memory_status: summarizeCampaignBuilderProofStrategyMemory(strategyMemory),
2233
+ dry_run_result: summarizeCampaignBuilderProofDryRun(dryRunResult),
2234
+ recommended_next_actions: [
2235
+ "Review the plan, approvals, and dry-run result.",
2236
+ "Use campaign-agent commit-plan --confirm-write only after review.",
2237
+ "Use campaign-agent build-approved only with --confirm-launch, approval identity, approval types, and spend limit.",
2238
+ "When an approved build reaches pending_approval, review rows and approve delivery through the Campaigns SDK."
2239
+ ]
2240
+ };
2241
+ }
2073
2242
  function getMissingCampaignBuilderApprovals(plan, approval) {
2074
2243
  if (approval.planId !== plan.planId) {
2075
2244
  return plan.approvals;
@@ -3346,6 +3515,137 @@ function campaignReviewRowHasCopy(row) {
3346
3515
  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)
3347
3516
  );
3348
3517
  }
3518
+ function createCampaignBuilderReadinessLane(route, plan) {
3519
+ const builtIn = campaignBuilderBuiltInForRoute(route);
3520
+ const customRoute = route.provider !== "signaliz" && route.provider !== "csv" && builtIn === void 0;
3521
+ const prepareStep = plan.mcpFlow.find(
3522
+ (step) => step.tool === "gtm_provider_recipe_prepare" && step.arguments.provider_id === route.provider
3523
+ );
3524
+ const activateStep = plan.mcpFlow.find(
3525
+ (step) => step.tool === "gtm_provider_route_activate" && step.arguments.provider_id === route.provider
3526
+ );
3527
+ const readOnlySetup = !customRoute || prepareStep?.readOnly === true && activateStep?.readOnly === true && activateStep.arguments.dry_run === true && activateStep.arguments.confirm === false;
3528
+ const blockers = [
3529
+ customRoute && !prepareStep ? `${route.label ?? route.provider} is missing provider recipe setup.` : void 0,
3530
+ customRoute && !activateStep ? `${route.label ?? route.provider} is missing provider route dry-run setup.` : void 0,
3531
+ customRoute && !readOnlySetup ? `${route.label ?? route.provider} route setup must stay read-only before approval.` : void 0,
3532
+ route.mode === "required" && !route.toolName && customRoute ? `${route.label ?? route.provider} is required but has no tool name.` : void 0
3533
+ ].filter((item) => Boolean(item));
3534
+ return {
3535
+ id: route.id ?? `${route.provider}-${route.layer}`,
3536
+ label: route.label ?? readinessLaneLabel(route, builtIn),
3537
+ layer: route.layer,
3538
+ gtmLayers: gtmLayersForRoute(route),
3539
+ provider: route.provider,
3540
+ toolName: route.toolName,
3541
+ mode: route.mode ?? "if_available",
3542
+ builtIn,
3543
+ approvalRequired: route.approvalRequired === true || plan.approvals.some((approval) => approval.routeId === route.id),
3544
+ customRoute,
3545
+ readOnlySetup,
3546
+ ready: blockers.length === 0,
3547
+ blockers,
3548
+ nextAction: customRoute ? `Review ${route.provider} route setup before launch approval.` : void 0
3549
+ };
3550
+ }
3551
+ function campaignBuilderBuiltInForRoute(route) {
3552
+ return Object.entries(CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS).find(([, routeId]) => route.id === routeId)?.[0];
3553
+ }
3554
+ function readinessLaneLabel(route, builtIn) {
3555
+ if (builtIn) {
3556
+ const labels = {
3557
+ lead_generation: "Signaliz lead generation",
3558
+ local_leads: "Signaliz local leads",
3559
+ email_finding: "Signaliz email finding",
3560
+ email_verification: "Signaliz email verification",
3561
+ signals: "Signaliz signals"
3562
+ };
3563
+ return labels[builtIn];
3564
+ }
3565
+ return `${route.provider} ${route.layer}`;
3566
+ }
3567
+ function campaignReadinessNextActions(plan, ready, customRouteCount) {
3568
+ const requestHint = "--request-file campaign-request.json";
3569
+ if (ready) {
3570
+ return [
3571
+ `signaliz campaign-agent proof ${requestHint} --json`,
3572
+ `signaliz campaign-agent commit-plan ${requestHint} --json`,
3573
+ `signaliz campaign-agent build-approved ${requestHint} --confirm-launch --approve-all --approved-by operator@example.com --spend-limit ${plan.estimatedCredits}`
3574
+ ];
3575
+ }
3576
+ const actions = [
3577
+ plan.strategyMemoryStatus && asRecord(plan.strategyMemoryStatus).ready === false ? "signaliz gtm strategy-memory --strategy-template <strategy_template> --include-samples --json" : void 0,
3578
+ customRouteCount > 0 ? "Review BYO provider recipe and route dry-run steps in the readiness packet." : void 0,
3579
+ `signaliz campaign-agent plan ${requestHint} --json`
3580
+ ];
3581
+ return actions.filter((item) => Boolean(item));
3582
+ }
3583
+ function campaignBuilderProofStrategyTemplate(plan) {
3584
+ const buildRequest = asRecord(plan.buildRequest);
3585
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
3586
+ const statusTemplate = strategyMemory.strategy_template ?? strategyMemory.strategyTemplate;
3587
+ const statusTemplateRecord = asRecord(statusTemplate);
3588
+ const flowTemplate = plan.mcpFlow.map((step) => asRecord(step.arguments).strategy_template ?? asRecord(step.arguments).strategyTemplate).find((value) => typeof value === "string" && value.trim());
3589
+ return firstNonEmptyString(
3590
+ buildRequest.strategyTemplate,
3591
+ buildRequest.strategy_template,
3592
+ statusTemplate,
3593
+ statusTemplateRecord.slug,
3594
+ statusTemplateRecord.id,
3595
+ flowTemplate
3596
+ );
3597
+ }
3598
+ function summarizeCampaignBuilderProofStrategyMemory(strategyMemory) {
3599
+ if (Object.keys(strategyMemory).length === 0) return { ready: false };
3600
+ const template = strategyMemory.strategy_template ?? strategyMemory.strategyTemplate;
3601
+ const templateRecord = asRecord(template);
3602
+ const coverage = asRecord(strategyMemory.coverage);
3603
+ const rawSourceGroups = Array.isArray(strategyMemory.source_groups) ? strategyMemory.source_groups : Array.isArray(strategyMemory.sourceGroups) ? strategyMemory.sourceGroups : [];
3604
+ const sourceGroups = rawSourceGroups.map((group) => {
3605
+ const sourceGroup = asRecord(group);
3606
+ return {
3607
+ id: sourceGroup.id ?? null,
3608
+ required: sourceGroup.required ?? null,
3609
+ ready: sourceGroup.ready ?? null,
3610
+ counts: asRecord(sourceGroup.counts)
3611
+ };
3612
+ });
3613
+ return {
3614
+ ready: strategyMemory.ready ?? null,
3615
+ read_only: strategyMemory.read_only ?? strategyMemory.readOnly ?? null,
3616
+ source_tool: firstNonEmptyString(strategyMemory.source_tool, strategyMemory.sourceTool),
3617
+ strategy_template: {
3618
+ slug: firstNonEmptyString(template, templateRecord.slug, templateRecord.id),
3619
+ label: firstNonEmptyString(templateRecord.label)
3620
+ },
3621
+ coverage: {
3622
+ required_groups_ready: coverage.required_groups_ready ?? coverage.requiredGroupsReady ?? null,
3623
+ required_groups_total: coverage.required_groups_total ?? coverage.requiredGroupsTotal ?? null,
3624
+ source_groups_ready: coverage.source_groups_ready ?? coverage.sourceGroupsReady ?? null,
3625
+ source_groups_total: coverage.source_groups_total ?? coverage.sourceGroupsTotal ?? null,
3626
+ knowledge_docs: coverage.knowledge_docs ?? coverage.knowledgeDocs ?? null,
3627
+ memories: coverage.memories ?? null
3628
+ },
3629
+ source_groups: sourceGroups,
3630
+ blocker_count: Array.isArray(strategyMemory.blockers) ? strategyMemory.blockers.length : 0,
3631
+ warning_count: Array.isArray(strategyMemory.warnings) ? strategyMemory.warnings.length : 0
3632
+ };
3633
+ }
3634
+ function summarizeCampaignBuilderProofDryRun(dryRunResult) {
3635
+ return {
3636
+ dryRun: dryRunResult.dryRun ?? dryRunResult.dry_run ?? null,
3637
+ status: dryRunResult.status ?? null,
3638
+ currentPhase: dryRunResult.currentPhase ?? dryRunResult.current_phase ?? null,
3639
+ campaignBuildId: dryRunResult.campaignBuildId ?? dryRunResult.campaign_build_id ?? null,
3640
+ plannedTargetCount: dryRunResult.plannedTargetCount ?? dryRunResult.planned_target_count ?? null
3641
+ };
3642
+ }
3643
+ function firstNonEmptyString(...values) {
3644
+ for (const value of values) {
3645
+ if (typeof value === "string" && value.trim()) return value;
3646
+ }
3647
+ return null;
3648
+ }
3349
3649
  function diagnosticMessages2(value) {
3350
3650
  if (!Array.isArray(value)) return [];
3351
3651
  return value.map((item) => {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  Signaliz
4
- } from "./chunk-XJQ6KGNQ.mjs";
4
+ } from "./chunk-EVFQETTN.mjs";
5
5
 
6
6
  // src/mcp-config.ts
7
7
  import * as fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaliz/sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Signaliz SDK — GTM Kernel, Nango routes, MCP, and enrichment for AI agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",