@signaliz/sdk 1.0.11 → 1.0.13

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/README.md CHANGED
@@ -93,19 +93,30 @@ const plan = await signaliz.campaignBuilderAgent.createPlan({
93
93
  });
94
94
 
95
95
  const dryRun = await signaliz.campaignBuilderAgent.dryRunPlan(plan);
96
+ const readiness = await signaliz.campaignBuilderAgent.readiness({
97
+ goal: 'Build a strategy-template campaign for mature local operators',
98
+ strategyTemplate: 'non-medical-home-care',
99
+ targetCount: 500,
100
+ builtIns: ['lead_generation', 'local_leads', 'email_finding', 'email_verification', 'signals'],
101
+ });
96
102
 
97
103
  console.log(plan.strategyMemoryStatus?.ready);
104
+ console.log(readiness.summary.ready);
98
105
  console.log(plan.mcpFlow.filter((step) =>
99
106
  ['gtm_provider_recipe_prepare', 'gtm_provider_route_activate'].includes(step.tool)
100
107
  ));
101
108
 
102
109
  // After an approved launch, keep review and delivery in the agent surface.
110
+ const review = await signaliz.campaignBuilderAgent.reviewBuild('campaign_build_id', {
111
+ limit: 100,
112
+ });
103
113
  const finalStatus = await signaliz.campaignBuilderAgent.getBuildStatus('campaign_build_id');
104
114
  const reviewRows = await signaliz.campaignBuilderAgent.getBuildRows('campaign_build_id', {
105
115
  limit: 100,
106
116
  qualified: true,
107
117
  });
108
118
  const artifacts = await signaliz.campaignBuilderAgent.listBuildArtifacts('campaign_build_id');
119
+ console.log(review.summary.readyForDeliveryApproval);
109
120
  ```
110
121
 
111
122
  The CLI can run the same request shape from a reusable JSON file, with flags
@@ -124,7 +135,12 @@ npx @signaliz/sdk campaign-agent plan \
124
135
  --target-count 250 \
125
136
  --json
126
137
 
138
+ npx @signaliz/sdk campaign-agent doctor \
139
+ --request-file campaign-request.json \
140
+ --json
141
+
127
142
  npx @signaliz/sdk campaign-agent status campaign_build_id --json
143
+ npx @signaliz/sdk campaign-agent review campaign_build_id --limit 100 --json
128
144
  npx @signaliz/sdk campaign-agent rows campaign_build_id --limit 100 --json
129
145
  ```
130
146
 
@@ -1191,6 +1191,13 @@ var DEFAULT_CAMPAIGN_BUILDER_BUILT_INS = [
1191
1191
  "email_verification",
1192
1192
  "signals"
1193
1193
  ];
1194
+ var CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS = {
1195
+ lead_generation: "signaliz-lead-generation",
1196
+ local_leads: "signaliz-local-leads",
1197
+ email_finding: "signaliz-email-finding",
1198
+ email_verification: "signaliz-email-verification",
1199
+ signals: "signaliz-signals"
1200
+ };
1194
1201
  var DEFAULT_CAMPAIGN_BUILDER_APPROVAL_TYPES = [
1195
1202
  "memory_retrieval",
1196
1203
  "spend",
@@ -1687,6 +1694,10 @@ var CampaignBuilderAgent = class {
1687
1694
  }
1688
1695
  return plan;
1689
1696
  }
1697
+ async readiness(request, options = {}) {
1698
+ const plan = await this.createPlan(request, options);
1699
+ return createCampaignBuilderReadiness(plan);
1700
+ }
1690
1701
  async commitPlan(plan, options = {}) {
1691
1702
  const writeMode = options.confirm === true && options.dryRun === false;
1692
1703
  if (writeMode && !options.approvedBy) {
@@ -1874,6 +1885,15 @@ var CampaignBuilderAgent = class {
1874
1885
  async approveDelivery(campaignBuildId, destinationType, options) {
1875
1886
  return this.approveCampaignDelivery(campaignBuildId, destinationType, options);
1876
1887
  }
1888
+ async reviewBuild(campaignBuildId, options = {}) {
1889
+ const status = await this.getBuildStatus(campaignBuildId);
1890
+ const rows = await this.getBuildRows(campaignBuildId, {
1891
+ ...options,
1892
+ limit: options.limit ?? 100
1893
+ });
1894
+ const artifacts = await this.listBuildArtifacts(campaignBuildId);
1895
+ return createCampaignBuilderBuildReview(status, rows, artifacts);
1896
+ }
1877
1897
  async getCampaignBuildStatus(campaignBuildId) {
1878
1898
  const data = await this.callMcp("get_campaign_build_status", {
1879
1899
  campaign_build_id: campaignBuildId
@@ -2038,6 +2058,91 @@ function createCampaignBuilderAgentPlan(request, context = {}) {
2038
2058
  warnings: context.warnings ?? []
2039
2059
  };
2040
2060
  }
2061
+ function createCampaignBuilderReadiness(plan) {
2062
+ const lanes = plan.routes.map((route) => createCampaignBuilderReadinessLane(route, plan));
2063
+ const builtInLanes = lanes.filter((lane) => lane.builtIn);
2064
+ const customRoutes = lanes.filter((lane) => lane.customRoute);
2065
+ const strategyMemory = asRecord(plan.strategyMemoryStatus);
2066
+ const deliveryRisk = asRecord(plan.buildRequest.deliveryRisk);
2067
+ const deliveryRiskBlockers = arrayOfStrings(deliveryRisk.blockers) ?? [];
2068
+ const deliveryRiskValue = asRecord(deliveryRisk.risk);
2069
+ const deliveryRiskLevel = stringValue(deliveryRiskValue.risk_level ?? deliveryRiskValue.riskLevel);
2070
+ const memoryReady = !plan.strategyMemoryStatus || strategyMemory.ready !== false;
2071
+ const kernelPlanReady = Object.keys(asRecord(plan.kernelPlan)).length > 0;
2072
+ const deliveryRiskReady = !plan.buildRequest.deliveryRisk || deliveryRiskBlockers.length === 0 && !["high", "critical", "blocked"].includes(String(deliveryRiskLevel ?? "").toLowerCase());
2073
+ const builtInsReady = builtInLanes.length > 0 && builtInLanes.every((lane) => lane.ready);
2074
+ const customRoutesReady = customRoutes.every((lane) => lane.ready);
2075
+ const approvalGatesReady = plan.approvals.length > 0;
2076
+ const gates = [
2077
+ {
2078
+ id: "campaign_plan_created",
2079
+ label: "Campaign plan created",
2080
+ passed: Boolean(plan.planId && plan.mcpFlow.length > 0),
2081
+ detail: plan.planId ? `Plan ${plan.planId} has ${plan.mcpFlow.length} MCP step(s).` : "No campaign-builder plan was created."
2082
+ },
2083
+ {
2084
+ id: "built_in_lanes_ready",
2085
+ label: "Built-in lanes ready",
2086
+ passed: builtInsReady,
2087
+ detail: `${builtInLanes.filter((lane) => lane.ready).length}/${builtInLanes.length} Signaliz built-in lane(s) are present.`
2088
+ },
2089
+ {
2090
+ id: "strategy_memory_ready",
2091
+ label: "Strategy memory ready",
2092
+ passed: memoryReady,
2093
+ detail: plan.strategyMemoryStatus ? "Strategy memory readiness was checked." : "Strategy memory readiness was not requested."
2094
+ },
2095
+ {
2096
+ id: "kernel_plan_attached",
2097
+ label: "Kernel plan attached",
2098
+ passed: kernelPlanReady,
2099
+ detail: kernelPlanReady ? "Kernel planner evidence is attached." : "Kernel planner evidence is not attached."
2100
+ },
2101
+ {
2102
+ id: "delivery_risk_clear",
2103
+ label: "Delivery risk clear",
2104
+ passed: deliveryRiskReady,
2105
+ detail: plan.buildRequest.deliveryRisk ? `Delivery risk is ${deliveryRiskLevel || "available"} with ${deliveryRiskBlockers.length} blocker(s).` : "Delivery risk preflight was not requested."
2106
+ },
2107
+ {
2108
+ id: "custom_routes_prepared",
2109
+ label: "Custom routes prepared",
2110
+ passed: customRoutesReady,
2111
+ 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.`
2112
+ },
2113
+ {
2114
+ id: "approval_gates_present",
2115
+ label: "Approval gates present",
2116
+ passed: approvalGatesReady,
2117
+ detail: approvalGatesReady ? `${plan.approvals.length} approval gate(s) are attached.` : "No approval gates are attached."
2118
+ }
2119
+ ];
2120
+ const blockers = [
2121
+ ...gates.filter((gate) => !gate.passed).map((gate) => gate.detail),
2122
+ ...lanes.flatMap((lane) => lane.blockers)
2123
+ ];
2124
+ const score = gates.length === 0 ? 0 : Math.round(gates.filter((gate) => gate.passed).length / gates.length * 100);
2125
+ const ready = blockers.length === 0;
2126
+ return {
2127
+ plan,
2128
+ lanes,
2129
+ gates,
2130
+ summary: {
2131
+ ready,
2132
+ score,
2133
+ targetCount: plan.targetCount,
2134
+ estimatedCredits: plan.estimatedCredits,
2135
+ builtInLanesReady: builtInLanes.filter((lane) => lane.ready).length,
2136
+ builtInLanesTotal: builtInLanes.length,
2137
+ customRoutesReady: customRoutes.filter((lane) => lane.ready).length,
2138
+ customRoutesTotal: customRoutes.length,
2139
+ approvalGateCount: plan.approvals.length,
2140
+ blockers,
2141
+ warnings: plan.warnings
2142
+ },
2143
+ nextActions: campaignReadinessNextActions(plan, ready, customRoutes.length)
2144
+ };
2145
+ }
2041
2146
  function getMissingCampaignBuilderApprovals(plan, approval) {
2042
2147
  if (approval.planId !== plan.planId) {
2043
2148
  return plan.approvals;
@@ -3301,6 +3406,185 @@ function mapAgentCampaignArtifact(data) {
3301
3406
  createdAt: stringValue(data.created_at) ?? ""
3302
3407
  };
3303
3408
  }
3409
+ function createCampaignBuilderBuildReview(status, rows, artifacts) {
3410
+ const sampledRows = rows.rows.length;
3411
+ const availableRows = rows.count || sampledRows;
3412
+ const qualifiedRows = rows.rows.filter((row) => row.qualified !== false).length;
3413
+ const rowsWithEmail = rows.rows.filter(campaignReviewRowHasEmail).length;
3414
+ const copyReadyRows = rows.rows.filter(campaignReviewRowHasCopy).length;
3415
+ const artifactCount = artifacts.length || status.artifactCount || 0;
3416
+ const gates = [
3417
+ {
3418
+ id: "build_completed",
3419
+ label: "Build completed",
3420
+ passed: status.status === "completed",
3421
+ detail: status.status === "completed" ? "The campaign build is completed." : `The campaign build is ${status.status}; review again after completion.`
3422
+ },
3423
+ {
3424
+ id: "rows_available",
3425
+ label: "Rows available",
3426
+ passed: sampledRows > 0,
3427
+ detail: sampledRows > 0 ? `${sampledRows} sampled row(s) are available for review.` : "No rows were returned for review."
3428
+ },
3429
+ {
3430
+ id: "qualified_sample",
3431
+ label: "Sample rows qualified",
3432
+ passed: sampledRows > 0 && qualifiedRows === sampledRows,
3433
+ detail: sampledRows > 0 ? `${qualifiedRows}/${sampledRows} sampled row(s) are marked qualified.` : "Qualification could not be checked without sampled rows."
3434
+ },
3435
+ {
3436
+ id: "email_coverage",
3437
+ label: "Email coverage",
3438
+ passed: sampledRows > 0 && rowsWithEmail === sampledRows,
3439
+ detail: sampledRows > 0 ? `${rowsWithEmail}/${sampledRows} sampled row(s) include an email.` : "Email coverage could not be checked without sampled rows."
3440
+ },
3441
+ {
3442
+ id: "artifact_available",
3443
+ label: "Artifact available",
3444
+ passed: artifactCount > 0,
3445
+ detail: artifactCount > 0 ? `${artifactCount} artifact(s) are available.` : "No delivery artifact is available yet."
3446
+ },
3447
+ {
3448
+ id: "no_failed_rows",
3449
+ label: "No failed rows",
3450
+ passed: status.recordsFailed === 0,
3451
+ detail: status.recordsFailed === 0 ? "The build reports zero failed rows." : `${status.recordsFailed} row(s) failed during the build.`
3452
+ }
3453
+ ];
3454
+ const blockedReasons = gates.filter((gate) => !gate.passed).map((gate) => gate.detail);
3455
+ const warnings = [
3456
+ rows.hasMore ? "This review is based on a row sample; page through remaining rows before final approval." : void 0,
3457
+ sampledRows > 0 && copyReadyRows < sampledRows ? `${copyReadyRows}/${sampledRows} sampled row(s) include generated copy.` : void 0,
3458
+ ...status.warnings
3459
+ ].filter((item) => Boolean(item));
3460
+ const readyForDeliveryApproval = blockedReasons.length === 0;
3461
+ return {
3462
+ campaignBuildId: status.campaignBuildId || rows.campaignBuildId,
3463
+ status,
3464
+ rows,
3465
+ artifacts,
3466
+ gates,
3467
+ summary: {
3468
+ status: status.status,
3469
+ phase: status.currentPhase,
3470
+ sampledRows,
3471
+ availableRows,
3472
+ qualifiedRows,
3473
+ rowsWithEmail,
3474
+ copyReadyRows,
3475
+ artifactCount,
3476
+ readyForDeliveryApproval,
3477
+ blockedReasons,
3478
+ warnings
3479
+ },
3480
+ nextActions: campaignReviewNextActions(status, readyForDeliveryApproval)
3481
+ };
3482
+ }
3483
+ function campaignReviewNextActions(status, readyForDeliveryApproval) {
3484
+ const buildId = status.campaignBuildId;
3485
+ if (!buildId) return [];
3486
+ if (status.status === "completed" && readyForDeliveryApproval) {
3487
+ return [
3488
+ `signaliz campaign-agent approve ${buildId} --destination-type json`,
3489
+ `signaliz campaign-agent artifacts ${buildId}`
3490
+ ];
3491
+ }
3492
+ if (status.status === "completed") {
3493
+ return [
3494
+ `signaliz campaign-agent rows ${buildId} --limit 100`,
3495
+ `signaliz campaign-agent artifacts ${buildId}`
3496
+ ];
3497
+ }
3498
+ if (status.status === "pending_approval") {
3499
+ return [
3500
+ `signaliz campaign-agent rows ${buildId} --limit 100`,
3501
+ `signaliz campaign-agent approve ${buildId} --destination-type json`
3502
+ ];
3503
+ }
3504
+ if ((status.status === "queued" || status.status === "running") && status.triggerRunId) {
3505
+ return [`signaliz ops run-status ${status.triggerRunId} --watch`];
3506
+ }
3507
+ return [`signaliz campaign-agent status ${buildId}`];
3508
+ }
3509
+ function campaignReviewRowHasEmail(row) {
3510
+ const data = asRecord(row.data);
3511
+ return Boolean(
3512
+ stringValue(data.email) || stringValue(data.work_email) || stringValue(data.workEmail)
3513
+ );
3514
+ }
3515
+ function campaignReviewRowHasCopy(row) {
3516
+ const data = asRecord(row.data);
3517
+ const copy = asRecord(data.copy);
3518
+ const rawCopy = asRecord(data.raw_copy ?? data.rawCopy);
3519
+ return row.status === "copy_ready" || data.copy_ready === true || Boolean(
3520
+ 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)
3521
+ );
3522
+ }
3523
+ function createCampaignBuilderReadinessLane(route, plan) {
3524
+ const builtIn = campaignBuilderBuiltInForRoute(route);
3525
+ const customRoute = route.provider !== "signaliz" && route.provider !== "csv" && builtIn === void 0;
3526
+ const prepareStep = plan.mcpFlow.find(
3527
+ (step) => step.tool === "gtm_provider_recipe_prepare" && step.arguments.provider_id === route.provider
3528
+ );
3529
+ const activateStep = plan.mcpFlow.find(
3530
+ (step) => step.tool === "gtm_provider_route_activate" && step.arguments.provider_id === route.provider
3531
+ );
3532
+ const readOnlySetup = !customRoute || prepareStep?.readOnly === true && activateStep?.readOnly === true && activateStep.arguments.dry_run === true && activateStep.arguments.confirm === false;
3533
+ const blockers = [
3534
+ customRoute && !prepareStep ? `${route.label ?? route.provider} is missing provider recipe setup.` : void 0,
3535
+ customRoute && !activateStep ? `${route.label ?? route.provider} is missing provider route dry-run setup.` : void 0,
3536
+ customRoute && !readOnlySetup ? `${route.label ?? route.provider} route setup must stay read-only before approval.` : void 0,
3537
+ route.mode === "required" && !route.toolName && customRoute ? `${route.label ?? route.provider} is required but has no tool name.` : void 0
3538
+ ].filter((item) => Boolean(item));
3539
+ return {
3540
+ id: route.id ?? `${route.provider}-${route.layer}`,
3541
+ label: route.label ?? readinessLaneLabel(route, builtIn),
3542
+ layer: route.layer,
3543
+ gtmLayers: gtmLayersForRoute(route),
3544
+ provider: route.provider,
3545
+ toolName: route.toolName,
3546
+ mode: route.mode ?? "if_available",
3547
+ builtIn,
3548
+ approvalRequired: route.approvalRequired === true || plan.approvals.some((approval) => approval.routeId === route.id),
3549
+ customRoute,
3550
+ readOnlySetup,
3551
+ ready: blockers.length === 0,
3552
+ blockers,
3553
+ nextAction: customRoute ? `Review ${route.provider} route setup before launch approval.` : void 0
3554
+ };
3555
+ }
3556
+ function campaignBuilderBuiltInForRoute(route) {
3557
+ return Object.entries(CAMPAIGN_BUILDER_BUILT_IN_ROUTE_IDS).find(([, routeId]) => route.id === routeId)?.[0];
3558
+ }
3559
+ function readinessLaneLabel(route, builtIn) {
3560
+ if (builtIn) {
3561
+ const labels = {
3562
+ lead_generation: "Signaliz lead generation",
3563
+ local_leads: "Signaliz local leads",
3564
+ email_finding: "Signaliz email finding",
3565
+ email_verification: "Signaliz email verification",
3566
+ signals: "Signaliz signals"
3567
+ };
3568
+ return labels[builtIn];
3569
+ }
3570
+ return `${route.provider} ${route.layer}`;
3571
+ }
3572
+ function campaignReadinessNextActions(plan, ready, customRouteCount) {
3573
+ const requestHint = "--request-file campaign-request.json";
3574
+ if (ready) {
3575
+ return [
3576
+ `signaliz campaign-agent proof ${requestHint} --json`,
3577
+ `signaliz campaign-agent commit-plan ${requestHint} --json`,
3578
+ `signaliz campaign-agent build-approved ${requestHint} --confirm-launch --approve-all --approved-by operator@example.com --spend-limit ${plan.estimatedCredits}`
3579
+ ];
3580
+ }
3581
+ const actions = [
3582
+ plan.strategyMemoryStatus && asRecord(plan.strategyMemoryStatus).ready === false ? "signaliz gtm strategy-memory --strategy-template <strategy_template> --include-samples --json" : void 0,
3583
+ customRouteCount > 0 ? "Review BYO provider recipe and route dry-run steps in the readiness packet." : void 0,
3584
+ `signaliz campaign-agent plan ${requestHint} --json`
3585
+ ];
3586
+ return actions.filter((item) => Boolean(item));
3587
+ }
3304
3588
  function diagnosticMessages2(value) {
3305
3589
  if (!Array.isArray(value)) return [];
3306
3590
  return value.map((item) => {
@@ -6311,6 +6595,7 @@ export {
6311
6595
  CAMPAIGN_BUILDER_STRATEGY_TEMPLATES,
6312
6596
  CampaignBuilderAgent,
6313
6597
  createCampaignBuilderAgentPlan,
6598
+ createCampaignBuilderReadiness,
6314
6599
  getMissingCampaignBuilderApprovals,
6315
6600
  createCampaignBuilderApproval,
6316
6601
  getCampaignBuilderStrategyTemplate,