@automagik/omni 2.260615.1 → 2.260617.1

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
@@ -124971,7 +124971,7 @@ import { fileURLToPath } from "url";
124971
124971
  // package.json
124972
124972
  var package_default = {
124973
124973
  name: "@automagik/omni",
124974
- version: "2.260615.1",
124974
+ version: "2.260617.1",
124975
124975
  description: "LLM-optimized CLI for Omni",
124976
124976
  type: "module",
124977
124977
  bin: {
@@ -225245,7 +225245,7 @@ var init_sentry_scrub = __esm(() => {
225245
225245
  var require_package7 = __commonJS((exports, module) => {
225246
225246
  module.exports = {
225247
225247
  name: "@omni/api",
225248
- version: "2.260615.1",
225248
+ version: "2.260617.1",
225249
225249
  type: "module",
225250
225250
  exports: {
225251
225251
  ".": {
@@ -366506,6 +366506,90 @@ var GupshupNativeWebhookSchema = exports_external.object({
366506
366506
  }).passthrough().optional(),
366507
366507
  source: exports_external.string().max(64).optional()
366508
366508
  }).passthrough();
366509
+ var GupshupSimplifiedWebhookSchema = exports_external.object({
366510
+ sender: exports_external.object({
366511
+ id: exports_external.string().min(1).max(32),
366512
+ name: exports_external.string().max(256).optional()
366513
+ }),
366514
+ message: exports_external.object({
366515
+ id: exports_external.string().max(512).optional(),
366516
+ text: exports_external.string().max(65536).optional(),
366517
+ timestamp: exports_external.union([exports_external.string(), exports_external.number()]).optional()
366518
+ }),
366519
+ event: exports_external.object({ project_id: exports_external.string().max(64).optional() }).passthrough().optional()
366520
+ }).passthrough();
366521
+ function toUnixSeconds(ts) {
366522
+ const n2 = typeof ts === "number" ? ts : Number.parseInt(String(ts ?? ""), 10);
366523
+ if (!Number.isFinite(n2) || n2 <= 0)
366524
+ return Math.floor(Date.now() / 1000);
366525
+ return Math.floor(n2 > 1000000000000 ? n2 / 1000 : n2);
366526
+ }
366527
+ function textDigest(text) {
366528
+ let h2 = 2166136261;
366529
+ for (let i = 0;i < text.length; i++) {
366530
+ h2 ^= text.charCodeAt(i);
366531
+ h2 = Math.imul(h2, 16777619);
366532
+ }
366533
+ return (h2 >>> 0).toString(36);
366534
+ }
366535
+ function normalizeSimplifiedWebhook(p2) {
366536
+ const phone = p2.sender.id;
366537
+ const text = p2.message?.text;
366538
+ if (!text)
366539
+ return null;
366540
+ const tsSeconds = toUnixSeconds(p2.message?.timestamp);
366541
+ const id = p2.message?.id ?? `gs-simplified-${phone}-${tsSeconds}-${textDigest(text)}`;
366542
+ return {
366543
+ source: "gupshup-hv-entry-flow-simplified",
366544
+ sender: phone,
366545
+ channel: "whatsapp",
366546
+ destination: "",
366547
+ botname: "",
366548
+ event_type: "user_input",
366549
+ message: text,
366550
+ postbackText: null,
366551
+ senderobj: { channelid: phone, display: p2.sender.name, channeltype: "whatsapp" },
366552
+ messageobj: {
366553
+ id,
366554
+ type: "text",
366555
+ from: phone,
366556
+ timestamp: tsSeconds,
366557
+ text,
366558
+ raw: { sender: { name: p2.sender.name } }
366559
+ },
366560
+ messageHeader: { event_type: "user_input", project_id: p2.event?.project_id }
366561
+ };
366562
+ }
366563
+ function parseSimplifiedWebhook(parsed) {
366564
+ const r = GupshupSimplifiedWebhookSchema.safeParse(parsed);
366565
+ return r.success ? normalizeSimplifiedWebhook(r.data) : null;
366566
+ }
366567
+ function resolveInboundWebhook(parsed, instanceId, logger5) {
366568
+ const result = GupshupNativeWebhookSchema.safeParse(parsed);
366569
+ if (result.success) {
366570
+ return result.data;
366571
+ }
366572
+ const simplified = parseSimplifiedWebhook(parsed);
366573
+ if (simplified) {
366574
+ logger5.info("[gupshup] simplified Entry-Flow payload normalized", {
366575
+ instanceId,
366576
+ sender: simplified.sender
366577
+ });
366578
+ return simplified;
366579
+ }
366580
+ logger5.warn("[gupshup] webhook payload unrecognized shape (acking anyway)", {
366581
+ instanceId,
366582
+ errors: result.error.issues,
366583
+ parsed
366584
+ });
366585
+ const parsedEventType = parsed !== null && typeof parsed === "object" && "event_type" in parsed ? String(parsed.event_type ?? "unparsed") : "unparsed";
366586
+ recordGupshupWebhookReceived(logger5, {
366587
+ instanceId,
366588
+ event_type: parsedEventType,
366589
+ handled: "dropped_unrecognized_shape"
366590
+ });
366591
+ return null;
366592
+ }
366509
366593
  var KNOWN_MESSAGE_EVENT_TYPES = new Set([
366510
366594
  "user_input",
366511
366595
  "async_response",
@@ -366609,22 +366693,10 @@ async function handleGupshupWebhook(request, plugin3, instanceId, webhookVerifyT
366609
366693
  });
366610
366694
  return new Response("OK", { status: 200 });
366611
366695
  }
366612
- const result = GupshupNativeWebhookSchema.safeParse(parsed);
366613
- if (!result.success) {
366614
- logger5.warn("[gupshup] webhook payload unrecognized shape (acking anyway)", {
366615
- instanceId,
366616
- errors: result.error.issues,
366617
- parsed
366618
- });
366619
- const parsedEventType = parsed !== null && typeof parsed === "object" && "event_type" in parsed ? String(parsed.event_type ?? "unparsed") : "unparsed";
366620
- recordGupshupWebhookReceived(logger5, {
366621
- instanceId,
366622
- event_type: parsedEventType,
366623
- handled: "dropped_unrecognized_shape"
366624
- });
366696
+ const webhook = resolveInboundWebhook(parsed, instanceId, logger5);
366697
+ if (!webhook) {
366625
366698
  return new Response("OK", { status: 200 });
366626
366699
  }
366627
- const webhook = result.data;
366628
366700
  if (seenEventTypes.markIfFirst(webhook.event_type)) {
366629
366701
  logger5.warn("[gupshup] first time seeing this event_type", {
366630
366702
  instanceId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260615.1",
3
+ "version": "2.260617.1",
4
4
  "description": "LLM-optimized CLI for Omni",
5
5
  "type": "module",
6
6
  "bin": {