@signaliz/sdk 1.0.28 → 1.0.30

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
@@ -77,6 +77,9 @@ resumes long-running research through the same `/company-signals` endpoint;
77
77
  callers never need an internal Trigger.dev status URL. The SDK follows the
78
78
  server's adaptive polling hints by default and still honors `pollIntervalMs`
79
79
  when a caller explicitly overrides the cadence.
80
+ All four products are transported in 25-row REST chunks. Exact duplicate tasks
81
+ are single-flighted without changing input order or result cardinality, and
82
+ Signal to Copy also shares company research across copy recipients.
80
83
 
81
84
  Company Signal Enrichment defaults `online` and `enableDeepSearch` to `true`
82
85
  unless the caller explicitly disables them. Signal to Copy AI returns three
@@ -353,89 +353,51 @@ var Signaliz = class {
353
353
  this.client = new HttpClient(config);
354
354
  }
355
355
  async findEmail(params) {
356
- const data = await this.client.post("api/v1/find-email", compact({
357
- company_domain: params.companyDomain,
358
- full_name: params.fullName,
359
- first_name: params.firstName,
360
- last_name: params.lastName,
361
- linkedin_url: params.linkedinUrl,
362
- company_name: params.companyName,
363
- skip_cache: params.skipCache
364
- }));
365
- const email = typeof data.email === "string" && data.email.trim() ? data.email.trim() : null;
366
- const found = Boolean(email) && data.found !== false;
367
- const verificationStatus = data.verification_status ?? data.status ?? "unknown";
368
- const rawFreshness = String(data.verification_freshness ?? "").toLowerCase();
369
- const verificationFreshness = rawFreshness === "fresh" || rawFreshness === "stale" ? rawFreshness : "unknown";
370
- const needsReverification = data.needs_reverification === true || verificationFreshness === "stale";
371
- const explicitlyNotSendSafe = data.verified_for_sending === false || needsReverification;
372
- const verified = !explicitlyNotSendSafe && (data.email_verified === true || data.verified_for_sending === true || ["valid", "deliverable"].includes(String(verificationStatus).toLowerCase()));
373
- const verificationAgeDays = typeof data.verification_age_days === "number" && Number.isFinite(data.verification_age_days) ? data.verification_age_days : null;
374
- return {
375
- success: data.success !== false && found,
376
- found,
377
- email,
378
- firstName: data.first_name,
379
- lastName: data.last_name,
380
- confidence: data.confidence ?? data.confidence_score ?? (verified ? 1 : 0),
381
- verificationStatus,
382
- isVerified: verified,
383
- isVerifiedForSending: !needsReverification && data.verified_for_sending === true,
384
- isCatchAll: data.email_is_catch_all === true || data.is_catch_all === true,
385
- verificationFreshness,
386
- verificationAgeDays,
387
- verifiedAt: typeof data.verified_at === "string" ? data.verified_at : null,
388
- needsReverification,
389
- providerUsed: data.provider_used ?? data.provider ?? data.email_source ?? data.source ?? "unknown",
390
- error: found ? void 0 : data.error ?? "No verified email found",
391
- errorCode: found ? void 0 : data.error_code ?? "EMAIL_NOT_FOUND",
392
- raw: data
393
- };
356
+ const data = await this.client.post("api/v1/find-email", findEmailRequestBody(params));
357
+ return normalizeFindEmailResult(data);
394
358
  }
395
359
  async findEmails(params, options) {
396
- return runBatch(params, (item) => this.findEmail(item), options);
360
+ validateBatchSize(params);
361
+ const startedAt = Date.now();
362
+ const round = await this.runCoreBatchRound(
363
+ "api/v1/find-email",
364
+ params.map((item, index) => ({ index, request: findEmailRequestBody(item) })),
365
+ options
366
+ );
367
+ return finalizeCoreBatch(
368
+ params.length,
369
+ startedAt,
370
+ round,
371
+ (item) => normalizeFindEmailResult(item.raw)
372
+ );
397
373
  }
398
374
  async verifyEmail(email, options) {
399
375
  const data = await this.client.post("api/v1/verify-email", {
400
376
  email,
401
377
  skip_cache: options?.skipCache
402
378
  });
403
- const verificationStatus = String(data.verification_status ?? "").toLowerCase();
404
- const verified = data.email_verified === true || ["valid", "deliverable"].includes(verificationStatus);
405
- return {
406
- email: data.email ?? email,
407
- isValid: data.is_valid ?? data.valid ?? verified,
408
- isDeliverable: data.is_deliverable ?? data.deliverable ?? verified,
409
- isCatchAll: data.is_catch_all ?? data.catch_all ?? data.diagnostics?.is_catch_all ?? false,
410
- confidenceScore: data.confidence_score ?? data.confidence ?? data.diagnostics?.confidence_score ?? (verified ? 1 : 0),
411
- provider: data.provider,
412
- verificationSource: data.verification_source,
413
- raw: data
414
- };
379
+ return normalizeVerifyEmailResult(email, data);
415
380
  }
416
381
  async verifyEmails(emails, options) {
417
- return runBatch(emails, (email) => this.verifyEmail(email, { skipCache: options?.skipCache }), options);
382
+ validateBatchSize(emails);
383
+ const startedAt = Date.now();
384
+ const round = await this.runCoreBatchRound(
385
+ "api/v1/verify-email",
386
+ emails.map((email, index) => ({
387
+ index,
388
+ request: { email, skip_cache: options?.skipCache }
389
+ })),
390
+ options
391
+ );
392
+ return finalizeCoreBatch(
393
+ emails.length,
394
+ startedAt,
395
+ round,
396
+ (item) => normalizeVerifyEmailResult(emails[item.index], item.raw)
397
+ );
418
398
  }
419
399
  async enrichCompanySignals(params) {
420
- const online = params.online ?? true;
421
- const request = compact({
422
- signal_run_id: params.signalRunId,
423
- company_domain: params.companyDomain,
424
- company_name: params.companyName,
425
- research_prompt: params.researchPrompt,
426
- signal_types: params.signalTypes,
427
- target_signal_count: params.targetSignalCount,
428
- lookback_days: params.lookbackDays,
429
- online,
430
- enable_deep_search: params.enableDeepSearch ?? online,
431
- enable_outreach_intelligence: params.enableOutreachIntelligence,
432
- enable_predictive_intelligence: params.enablePredictiveIntelligence,
433
- skip_cache: params.skipCache,
434
- // REST always returns a resumable run instead of holding the connection;
435
- // waitForResult controls this SDK's polling loop below.
436
- wait_for_result: false,
437
- max_wait_ms: params.maxWaitMs
438
- });
400
+ const request = companySignalRequestBody(params);
439
401
  let data = await this.client.post("api/v1/company-signals", request);
440
402
  if (params.waitForResult !== false && data.run_id && isPendingSignalResponse(data)) {
441
403
  const maxWaitMs = Math.max(1e3, params.maxWaitMs ?? 20 * 6e4);
@@ -463,59 +425,71 @@ var Signaliz = class {
463
425
  throw new Error(`Company signal enrichment ${data.run_id} did not complete within ${maxWaitMs}ms`);
464
426
  }
465
427
  }
466
- return {
467
- success: data.success ?? true,
468
- status: data.status,
469
- signalRunId: data.signal_run_id ?? data.run_id,
470
- company: {
471
- name: data.company?.name ?? params.companyName ?? null,
472
- domain: data.company?.domain ?? params.companyDomain ?? null
473
- },
474
- signals: (data.signals ?? []).map((signal) => {
475
- const metadata = signal.metadata && typeof signal.metadata === "object" && !Array.isArray(signal.metadata) ? signal.metadata : void 0;
476
- return {
477
- id: signal.id,
478
- title: signal.title ?? "",
479
- type: signal.type ?? signal.signal_type ?? "unknown",
480
- content: signal.content ?? signal.description ?? "",
481
- date: signal.date ?? signal.detected_at ?? null,
482
- datePrecision: signal.date_precision,
483
- sourceUrl: signal.source_url ?? signal.url ?? null,
484
- sourceType: signal.source_type,
485
- sourceProvenance: signal.source_provenance,
486
- confidence: signal.confidence ?? signal.confidence_score ?? null,
487
- entityConfidence: signal.entity_confidence ?? metadata?.entity_confidence ?? null,
488
- signalFamily: signal.signal_family,
489
- eventType: signal.signal_event_type,
490
- eventLabel: signal.signal_event_label,
491
- classification: signal.signal_classification ?? null,
492
- derived: signal.derived === true,
493
- evidencePublishedDate: signal.evidence_published_date ?? metadata?.evidence_published_date ?? null,
494
- signalFeedSource: signal.signal_feed_source ?? metadata?.signal_feed_source,
495
- metadata
496
- };
497
- }),
498
- signalCount: data.signal_count ?? data.total_signals ?? data.signals?.length ?? 0,
499
- intelligence: data.intelligence ?? null,
500
- credits: data.credits,
501
- metadata: data.metadata,
502
- raw: data
503
- };
428
+ return normalizeCompanySignalResult(params, data);
504
429
  }
505
430
  async enrichCompanies(companies, options) {
506
- return runBatch(companies, (company) => this.enrichCompanySignals(company), options);
431
+ validateBatchSize(companies);
432
+ const startedAt = Date.now();
433
+ const results = new Array(companies.length);
434
+ let pending = companies.map((params, index) => ({
435
+ index,
436
+ request: companySignalRequestBody(params)
437
+ }));
438
+ while (pending.length > 0) {
439
+ const round = await this.runCoreBatchRound("api/v1/company-signals", pending, options);
440
+ const taskByIndex = new Map(pending.map((task) => [task.index, task]));
441
+ const nextPending = [];
442
+ let nextDelayMs = 6e4;
443
+ for (const item of round) {
444
+ const params = companies[item.index];
445
+ const task = taskByIndex.get(item.index);
446
+ if (!item.success || !item.raw) {
447
+ results[item.index] = { index: item.index, success: false, error: item.error || "Company Signal batch request failed" };
448
+ continue;
449
+ }
450
+ if (!isPendingSignalResponse(item.raw) || params.waitForResult === false) {
451
+ results[item.index] = { index: item.index, success: true, data: normalizeCompanySignalResult(params, item.raw) };
452
+ continue;
453
+ }
454
+ const maxWaitMs = Math.max(1e3, params.maxWaitMs ?? 20 * 6e4);
455
+ if (Date.now() - startedAt >= maxWaitMs) {
456
+ results[item.index] = {
457
+ index: item.index,
458
+ success: false,
459
+ error: `Company signal enrichment ${item.raw.signal_run_id || item.raw.run_id || ""} did not complete within ${maxWaitMs}ms`
460
+ };
461
+ continue;
462
+ }
463
+ const signalRunId = item.raw.signal_run_id || item.raw.run_id;
464
+ if (!signalRunId) {
465
+ results[item.index] = { index: item.index, success: false, error: "Company signal enrichment is processing without a signal_run_id" };
466
+ continue;
467
+ }
468
+ nextDelayMs = Math.min(
469
+ nextDelayMs,
470
+ signalPollDelayMs(item.raw, params.pollIntervalMs),
471
+ maxWaitMs - (Date.now() - startedAt)
472
+ );
473
+ nextPending.push({
474
+ ...task,
475
+ request: { ...task.request, signal_run_id: signalRunId }
476
+ });
477
+ }
478
+ if (nextPending.length === 0) break;
479
+ await sleep2(Math.max(1, nextDelayMs));
480
+ pending = nextPending;
481
+ }
482
+ const succeeded = results.filter((item) => item.success).length;
483
+ return {
484
+ total: companies.length,
485
+ succeeded,
486
+ failed: companies.length - succeeded,
487
+ durationMs: Date.now() - startedAt,
488
+ results
489
+ };
507
490
  }
508
491
  async signalToCopy(params) {
509
- const request = compact({
510
- company_domain: params.companyDomain,
511
- person_name: params.personName,
512
- title: params.title,
513
- campaign_offer: params.campaignOffer,
514
- research_prompt: params.researchPrompt,
515
- signal_run_id: params.signalRunId,
516
- skip_cache: params.skipCache,
517
- enable_deep_search: params.enableDeepSearch
518
- });
492
+ const request = signalToCopyRequestBody(params);
519
493
  let data = await this.client.post("api/v1/signal-to-copy", request);
520
494
  if (params.waitForResult !== false && data.run_id && isPendingSignalResponse(data)) {
521
495
  const maxWaitMs = Math.max(1e3, params.maxWaitMs ?? 20 * 6e4);
@@ -532,30 +506,152 @@ var Signaliz = class {
532
506
  throw new Error(`Signal Copy ${data.run_id} did not complete within ${maxWaitMs}ms`);
533
507
  }
534
508
  }
509
+ return normalizeSignalToCopyResult(data);
510
+ }
511
+ async createSignalCopyBatch(requests, options) {
512
+ validateBatchSize(requests);
513
+ const startedAt = Date.now();
514
+ const chunks = [];
515
+ for (let offset = 0; offset < requests.length; offset += 25) {
516
+ chunks.push({ offset, requests: requests.slice(offset, offset + 25) });
517
+ }
518
+ const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
519
+ const chunkBatch = await runBatch(
520
+ chunks,
521
+ (chunk) => this.runSignalCopyBatchChunk(chunk.requests, serverConcurrency),
522
+ { concurrency: chunkConcurrency }
523
+ );
524
+ const results = new Array(requests.length);
525
+ for (const chunkResult of chunkBatch.results) {
526
+ const chunk = chunks[chunkResult.index];
527
+ if (!chunkResult.success || !chunkResult.data) {
528
+ for (let index = 0; index < chunk.requests.length; index += 1) {
529
+ results[chunk.offset + index] = {
530
+ index: chunk.offset + index,
531
+ success: false,
532
+ error: chunkResult.error || "Signal to Copy batch request failed"
533
+ };
534
+ }
535
+ continue;
536
+ }
537
+ for (const item of chunkResult.data) {
538
+ results[chunk.offset + item.index] = { ...item, index: chunk.offset + item.index };
539
+ }
540
+ }
541
+ const succeeded = results.filter((item) => item.success).length;
535
542
  return {
536
- success: data.success ?? true,
537
- status: data.status,
538
- runId: data.run_id,
539
- strongestSignal: data.strongest_signal ?? "",
540
- whyNow: data.why_now ?? "",
541
- subjectLine: data.subject_line ?? "",
542
- openingLine: data.opening_line ?? "",
543
- confidence: data.confidence ?? 0,
544
- evidenceUrl: data.evidence_url ?? "",
545
- researchPrompt: data.research_prompt,
546
- variations: (data.variations ?? []).map((variation) => ({
547
- style: variation.style,
548
- subjectLine: variation.subject_line ?? "",
549
- openingLine: variation.opening_line ?? "",
550
- cta: variation.cta ?? "",
551
- prediction: variation.prediction,
552
- email: variation.email
553
- })),
554
- raw: data
543
+ total: requests.length,
544
+ succeeded,
545
+ failed: requests.length - succeeded,
546
+ durationMs: Date.now() - startedAt,
547
+ results
555
548
  };
556
549
  }
557
- async createSignalCopyBatch(requests, options) {
558
- return runBatch(requests, (request) => this.signalToCopy(request), options);
550
+ async runSignalCopyBatchChunk(requests, concurrency) {
551
+ const startedAt = Date.now();
552
+ const results = new Array(requests.length);
553
+ let pending = requests.map((params, index) => ({
554
+ index,
555
+ params,
556
+ request: signalToCopyRequestBody(params)
557
+ }));
558
+ while (pending.length > 0) {
559
+ const data = await this.client.post("api/v1/signal-to-copy", {
560
+ requests: pending.map((item) => item.request),
561
+ concurrency
562
+ });
563
+ if (!Array.isArray(data.results) || data.results.length !== pending.length) {
564
+ throw new Error("Signal to Copy batch returned an invalid result count");
565
+ }
566
+ const nextPending = [];
567
+ let nextDelayMs = 6e4;
568
+ for (let index = 0; index < pending.length; index += 1) {
569
+ const task = pending[index];
570
+ const item = data.results[index];
571
+ if (item.success === false) {
572
+ results[task.index] = { index: task.index, success: false, error: item.error || item.message || "Signal to Copy failed" };
573
+ continue;
574
+ }
575
+ if (!isPendingSignalResponse(item)) {
576
+ results[task.index] = { index: task.index, success: true, data: normalizeSignalToCopyResult(item) };
577
+ continue;
578
+ }
579
+ if (task.params.waitForResult === false) {
580
+ results[task.index] = { index: task.index, success: true, data: normalizeSignalToCopyResult(item) };
581
+ continue;
582
+ }
583
+ const maxWaitMs = Math.max(1e3, task.params.maxWaitMs ?? 20 * 6e4);
584
+ if (Date.now() - startedAt >= maxWaitMs) {
585
+ results[task.index] = {
586
+ index: task.index,
587
+ success: false,
588
+ error: `Signal Copy ${item.signal_run_id || item.run_id || ""} did not complete within ${maxWaitMs}ms`
589
+ };
590
+ continue;
591
+ }
592
+ const signalRunId = item.signal_run_id || item.run_id;
593
+ if (!signalRunId) {
594
+ results[task.index] = { index: task.index, success: false, error: "Signal Copy is processing without a signal_run_id" };
595
+ continue;
596
+ }
597
+ nextDelayMs = Math.min(
598
+ nextDelayMs,
599
+ signalPollDelayMs(item, task.params.pollIntervalMs),
600
+ maxWaitMs - (Date.now() - startedAt)
601
+ );
602
+ nextPending.push({
603
+ ...task,
604
+ request: { ...task.request, signal_run_id: signalRunId }
605
+ });
606
+ }
607
+ pending = nextPending;
608
+ if (pending.length > 0) await sleep2(nextDelayMs);
609
+ }
610
+ return results;
611
+ }
612
+ async runCoreBatchRound(path, tasks, options) {
613
+ const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
614
+ const chunks = [];
615
+ for (let offset = 0; offset < tasks.length; offset += 25) {
616
+ chunks.push({ offset, tasks: tasks.slice(offset, offset + 25) });
617
+ }
618
+ const chunkBatch = await runBatch(chunks, async (chunk) => {
619
+ const data = await this.client.post(path, {
620
+ requests: chunk.tasks.map((task) => task.request),
621
+ concurrency: serverConcurrency
622
+ });
623
+ if (!Array.isArray(data.results) || data.results.length !== chunk.tasks.length) {
624
+ throw new Error(`${path} batch returned an invalid result count`);
625
+ }
626
+ if (data.results.some((row, index) => row.index !== index)) {
627
+ throw new Error(`${path} batch returned results out of order`);
628
+ }
629
+ return data.results;
630
+ }, { concurrency: chunkConcurrency });
631
+ const results = new Array(tasks.length);
632
+ for (const chunkResult of chunkBatch.results) {
633
+ const chunk = chunks[chunkResult.index];
634
+ if (!chunkResult.success || !chunkResult.data) {
635
+ for (let index = 0; index < chunk.tasks.length; index += 1) {
636
+ results[chunk.offset + index] = {
637
+ index: chunk.tasks[index].index,
638
+ success: false,
639
+ error: chunkResult.error || `${path} batch request failed`
640
+ };
641
+ }
642
+ continue;
643
+ }
644
+ for (let index = 0; index < chunkResult.data.length; index += 1) {
645
+ const raw = chunkResult.data[index];
646
+ results[chunk.offset + index] = {
647
+ index: chunk.tasks[index].index,
648
+ success: raw.success !== false,
649
+ raw,
650
+ error: raw.success === false ? raw.error || raw.message || raw.error_code || `${path} item failed` : void 0
651
+ };
652
+ }
653
+ }
654
+ return results;
559
655
  }
560
656
  async listTools() {
561
657
  const result = await this.client.mcp("tools/list");
@@ -572,6 +668,207 @@ var Signaliz = class {
572
668
  function compact(input) {
573
669
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
574
670
  }
671
+ function findEmailRequestBody(params) {
672
+ return compact({
673
+ company_domain: params.companyDomain,
674
+ full_name: params.fullName,
675
+ first_name: params.firstName,
676
+ last_name: params.lastName,
677
+ linkedin_url: params.linkedinUrl,
678
+ company_name: params.companyName,
679
+ skip_cache: params.skipCache
680
+ });
681
+ }
682
+ function normalizeFindEmailResult(data) {
683
+ const email = typeof data.email === "string" && data.email.trim() ? data.email.trim() : null;
684
+ const found = Boolean(email) && data.found !== false;
685
+ const verificationStatus = data.verification_status ?? data.status ?? "unknown";
686
+ const rawFreshness = String(data.verification_freshness ?? "").toLowerCase();
687
+ const verificationFreshness = rawFreshness === "fresh" || rawFreshness === "stale" ? rawFreshness : "unknown";
688
+ const needsReverification = data.needs_reverification === true || verificationFreshness === "stale";
689
+ const explicitlyNotSendSafe = data.verified_for_sending === false || needsReverification;
690
+ const verified = !explicitlyNotSendSafe && (data.email_verified === true || data.verified_for_sending === true || ["valid", "deliverable"].includes(String(verificationStatus).toLowerCase()));
691
+ const verificationAgeDays = typeof data.verification_age_days === "number" && Number.isFinite(data.verification_age_days) ? data.verification_age_days : null;
692
+ return {
693
+ success: data.success !== false && found,
694
+ found,
695
+ email,
696
+ firstName: data.first_name,
697
+ lastName: data.last_name,
698
+ confidence: data.confidence ?? data.confidence_score ?? (verified ? 1 : 0),
699
+ verificationStatus,
700
+ isVerified: verified,
701
+ isVerifiedForSending: !needsReverification && data.verified_for_sending === true,
702
+ isCatchAll: data.email_is_catch_all === true || data.is_catch_all === true,
703
+ verificationFreshness,
704
+ verificationAgeDays,
705
+ verifiedAt: typeof data.verified_at === "string" ? data.verified_at : null,
706
+ needsReverification,
707
+ providerUsed: data.provider_used ?? data.provider ?? data.email_source ?? data.source ?? "unknown",
708
+ error: found ? void 0 : data.error ?? "No verified email found",
709
+ errorCode: found ? void 0 : data.error_code ?? "EMAIL_NOT_FOUND",
710
+ raw: data
711
+ };
712
+ }
713
+ function normalizeVerifyEmailResult(email, data) {
714
+ const verificationStatus = String(data.verification_status ?? "").toLowerCase();
715
+ const verified = data.email_verified === true || ["valid", "deliverable"].includes(verificationStatus);
716
+ return {
717
+ email: data.email ?? email,
718
+ isValid: data.is_valid ?? data.valid ?? verified,
719
+ isDeliverable: data.is_deliverable ?? data.deliverable ?? verified,
720
+ isCatchAll: data.email_is_catch_all ?? data.is_catch_all ?? data.catch_all ?? data.diagnostics?.is_catch_all ?? false,
721
+ confidenceScore: data.confidence_score ?? data.confidence ?? data.diagnostics?.confidence_score ?? (verified ? 1 : 0),
722
+ provider: data.provider,
723
+ verificationSource: data.verification_source,
724
+ raw: data
725
+ };
726
+ }
727
+ function companySignalRequestBody(params) {
728
+ const online = params.online ?? true;
729
+ return compact({
730
+ signal_run_id: params.signalRunId,
731
+ company_domain: params.companyDomain,
732
+ company_name: params.companyName,
733
+ research_prompt: params.researchPrompt,
734
+ signal_types: params.signalTypes,
735
+ target_signal_count: params.targetSignalCount,
736
+ lookback_days: params.lookbackDays,
737
+ online,
738
+ enable_deep_search: params.enableDeepSearch ?? online,
739
+ enable_outreach_intelligence: params.enableOutreachIntelligence,
740
+ enable_predictive_intelligence: params.enablePredictiveIntelligence,
741
+ skip_cache: params.skipCache,
742
+ // REST always returns a resumable run instead of holding the connection;
743
+ // waitForResult controls the SDK polling loop.
744
+ wait_for_result: false,
745
+ max_wait_ms: params.maxWaitMs
746
+ });
747
+ }
748
+ function normalizeCompanySignalResult(params, data) {
749
+ return {
750
+ success: data.success ?? true,
751
+ status: data.status,
752
+ signalRunId: data.signal_run_id ?? data.run_id,
753
+ company: {
754
+ name: data.company?.name ?? params.companyName ?? null,
755
+ domain: data.company?.domain ?? params.companyDomain ?? null
756
+ },
757
+ signals: (data.signals ?? []).map((signal) => {
758
+ const metadata = signal.metadata && typeof signal.metadata === "object" && !Array.isArray(signal.metadata) ? signal.metadata : void 0;
759
+ return {
760
+ id: signal.id,
761
+ title: signal.title ?? "",
762
+ type: signal.type ?? signal.signal_type ?? "unknown",
763
+ content: signal.content ?? signal.description ?? "",
764
+ date: signal.date ?? signal.detected_at ?? null,
765
+ datePrecision: signal.date_precision,
766
+ sourceUrl: signal.source_url ?? signal.url ?? null,
767
+ sourceType: signal.source_type,
768
+ sourceProvenance: signal.source_provenance,
769
+ confidence: signal.confidence ?? signal.confidence_score ?? null,
770
+ entityConfidence: signal.entity_confidence ?? metadata?.entity_confidence ?? null,
771
+ signalFamily: signal.signal_family,
772
+ eventType: signal.signal_event_type,
773
+ eventLabel: signal.signal_event_label,
774
+ classification: signal.signal_classification ?? null,
775
+ derived: signal.derived === true,
776
+ evidencePublishedDate: signal.evidence_published_date ?? metadata?.evidence_published_date ?? null,
777
+ signalFeedSource: signal.signal_feed_source ?? metadata?.signal_feed_source,
778
+ metadata
779
+ };
780
+ }),
781
+ signalCount: data.signal_count ?? data.total_signals ?? data.signals?.length ?? 0,
782
+ intelligence: data.intelligence ?? null,
783
+ credits: data.credits,
784
+ metadata: data.metadata,
785
+ raw: data
786
+ };
787
+ }
788
+ function validateBatchSize(items) {
789
+ if (!Array.isArray(items) || items.length === 0) {
790
+ throw new Error("Signaliz batch requests require at least one item");
791
+ }
792
+ if (items.length > 5e3) {
793
+ throw new Error(`Signaliz batch requests support at most 5,000 items; received ${items.length}`);
794
+ }
795
+ }
796
+ function validatedBatchConcurrency(options) {
797
+ const concurrency = options?.concurrency ?? 10;
798
+ if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 50) {
799
+ throw new Error("Signaliz batch concurrency must be an integer between 1 and 50");
800
+ }
801
+ return concurrency;
802
+ }
803
+ function batchConcurrencyPlan(options) {
804
+ const concurrency = validatedBatchConcurrency(options);
805
+ const serverConcurrency = Math.min(10, concurrency);
806
+ return {
807
+ serverConcurrency,
808
+ chunkConcurrency: Math.max(1, Math.floor(concurrency / serverConcurrency))
809
+ };
810
+ }
811
+ function finalizeCoreBatch(total, startedAt, round, normalize) {
812
+ const results = new Array(total);
813
+ for (const item of round) {
814
+ if (!item.success || !item.raw) {
815
+ results[item.index] = { index: item.index, success: false, error: item.error || "Signaliz batch item failed" };
816
+ continue;
817
+ }
818
+ try {
819
+ results[item.index] = { index: item.index, success: true, data: normalize(item) };
820
+ } catch (error) {
821
+ results[item.index] = {
822
+ index: item.index,
823
+ success: false,
824
+ error: error instanceof Error ? error.message : String(error)
825
+ };
826
+ }
827
+ }
828
+ const succeeded = results.filter((item) => item.success).length;
829
+ return {
830
+ total,
831
+ succeeded,
832
+ failed: total - succeeded,
833
+ durationMs: Date.now() - startedAt,
834
+ results
835
+ };
836
+ }
837
+ function signalToCopyRequestBody(params) {
838
+ return compact({
839
+ company_domain: params.companyDomain,
840
+ person_name: params.personName,
841
+ title: params.title,
842
+ campaign_offer: params.campaignOffer,
843
+ research_prompt: params.researchPrompt,
844
+ signal_run_id: params.signalRunId,
845
+ skip_cache: params.skipCache,
846
+ enable_deep_search: params.enableDeepSearch
847
+ });
848
+ }
849
+ function normalizeSignalToCopyResult(data) {
850
+ return {
851
+ success: data.success ?? true,
852
+ status: data.status,
853
+ runId: data.signal_run_id ?? data.run_id,
854
+ strongestSignal: data.strongest_signal ?? "",
855
+ whyNow: data.why_now ?? "",
856
+ subjectLine: data.subject_line ?? "",
857
+ openingLine: data.opening_line ?? "",
858
+ confidence: data.confidence ?? 0,
859
+ evidenceUrl: data.evidence_url ?? "",
860
+ researchPrompt: data.research_prompt,
861
+ variations: (data.variations ?? []).map((variation) => ({
862
+ style: variation.style,
863
+ subjectLine: variation.subject_line ?? "",
864
+ openingLine: variation.opening_line ?? "",
865
+ cta: variation.cta ?? "",
866
+ prediction: variation.prediction,
867
+ email: variation.email
868
+ })),
869
+ raw: data
870
+ };
871
+ }
575
872
  function isPendingSignalResponse(data) {
576
873
  return ["triggered", "queued", "processing", "pending", "pending_version", "waiting_for_deploy"].includes(String(data.status || "").toLowerCase());
577
874
  }
@@ -598,16 +895,8 @@ function sleep2(ms) {
598
895
  return new Promise((resolve) => setTimeout(resolve, ms));
599
896
  }
600
897
  async function runBatch(items, execute, options) {
601
- if (!Array.isArray(items) || items.length === 0) {
602
- throw new Error("Signaliz batch requests require at least one item");
603
- }
604
- if (items.length > 5e3) {
605
- throw new Error(`Signaliz batch requests support at most 5,000 items; received ${items.length}`);
606
- }
607
- const concurrency = options?.concurrency ?? 10;
608
- if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 50) {
609
- throw new Error("Signaliz batch concurrency must be an integer between 1 and 50");
610
- }
898
+ validateBatchSize(items);
899
+ const concurrency = validatedBatchConcurrency(options);
611
900
  const startedAt = Date.now();
612
901
  const results = new Array(items.length);
613
902
  let nextIndex = 0;
package/dist/index.d.mts CHANGED
@@ -203,6 +203,8 @@ declare class Signaliz {
203
203
  enrichCompanies(companies: CompanySignalEnrichmentParams[], options?: BatchOptions): Promise<BatchResult<CompanySignalEnrichmentResult>>;
204
204
  signalToCopy(params: SignalToCopyParams): Promise<SignalToCopyResult>;
205
205
  createSignalCopyBatch(requests: SignalToCopyParams[], options?: BatchOptions): Promise<BatchResult<SignalToCopyResult>>;
206
+ private runSignalCopyBatchChunk;
207
+ private runCoreBatchRound;
206
208
  listTools(): Promise<MCPToolInfo[]>;
207
209
  health(): Promise<PlatformHealth>;
208
210
  }
package/dist/index.d.ts CHANGED
@@ -203,6 +203,8 @@ declare class Signaliz {
203
203
  enrichCompanies(companies: CompanySignalEnrichmentParams[], options?: BatchOptions): Promise<BatchResult<CompanySignalEnrichmentResult>>;
204
204
  signalToCopy(params: SignalToCopyParams): Promise<SignalToCopyResult>;
205
205
  createSignalCopyBatch(requests: SignalToCopyParams[], options?: BatchOptions): Promise<BatchResult<SignalToCopyResult>>;
206
+ private runSignalCopyBatchChunk;
207
+ private runCoreBatchRound;
206
208
  listTools(): Promise<MCPToolInfo[]>;
207
209
  health(): Promise<PlatformHealth>;
208
210
  }