@automagik/omni 2.260615.1 → 2.260616.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.260616.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.260616.1",
225249
225249
  type: "module",
225250
225250
  exports: {
225251
225251
  ".": {
@@ -366506,6 +366506,80 @@ 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 normalizeSimplifiedWebhook(p2) {
366528
+ const phone = p2.sender.id;
366529
+ const text = p2.message?.text;
366530
+ const tsSeconds = toUnixSeconds(p2.message?.timestamp);
366531
+ const id = p2.message?.id ?? `gs-simplified-${phone}-${tsSeconds}-${text ? text.length : 0}`;
366532
+ return {
366533
+ source: "gupshup-hv-entry-flow-simplified",
366534
+ sender: phone,
366535
+ channel: "whatsapp",
366536
+ destination: "",
366537
+ botname: "",
366538
+ event_type: "user_input",
366539
+ message: text,
366540
+ postbackText: null,
366541
+ senderobj: { channelid: phone, display: p2.sender.name, channeltype: "whatsapp" },
366542
+ messageobj: {
366543
+ id,
366544
+ type: "text",
366545
+ from: phone,
366546
+ timestamp: tsSeconds,
366547
+ text,
366548
+ raw: { sender: { name: p2.sender.name } }
366549
+ },
366550
+ messageHeader: { event_type: "user_input", project_id: p2.event?.project_id }
366551
+ };
366552
+ }
366553
+ function parseSimplifiedWebhook(parsed) {
366554
+ const r = GupshupSimplifiedWebhookSchema.safeParse(parsed);
366555
+ return r.success ? normalizeSimplifiedWebhook(r.data) : null;
366556
+ }
366557
+ function resolveInboundWebhook(parsed, instanceId, logger5) {
366558
+ const result = GupshupNativeWebhookSchema.safeParse(parsed);
366559
+ if (result.success) {
366560
+ return result.data;
366561
+ }
366562
+ const simplified = parseSimplifiedWebhook(parsed);
366563
+ if (simplified) {
366564
+ logger5.info("[gupshup] simplified Entry-Flow payload normalized", {
366565
+ instanceId,
366566
+ sender: simplified.sender
366567
+ });
366568
+ return simplified;
366569
+ }
366570
+ logger5.warn("[gupshup] webhook payload unrecognized shape (acking anyway)", {
366571
+ instanceId,
366572
+ errors: result.error.issues,
366573
+ parsed
366574
+ });
366575
+ const parsedEventType = parsed !== null && typeof parsed === "object" && "event_type" in parsed ? String(parsed.event_type ?? "unparsed") : "unparsed";
366576
+ recordGupshupWebhookReceived(logger5, {
366577
+ instanceId,
366578
+ event_type: parsedEventType,
366579
+ handled: "dropped_unrecognized_shape"
366580
+ });
366581
+ return null;
366582
+ }
366509
366583
  var KNOWN_MESSAGE_EVENT_TYPES = new Set([
366510
366584
  "user_input",
366511
366585
  "async_response",
@@ -366609,22 +366683,10 @@ async function handleGupshupWebhook(request, plugin3, instanceId, webhookVerifyT
366609
366683
  });
366610
366684
  return new Response("OK", { status: 200 });
366611
366685
  }
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
- });
366686
+ const webhook = resolveInboundWebhook(parsed, instanceId, logger5);
366687
+ if (!webhook) {
366625
366688
  return new Response("OK", { status: 200 });
366626
366689
  }
366627
- const webhook = result.data;
366628
366690
  if (seenEventTypes.markIfFirst(webhook.event_type)) {
366629
366691
  logger5.warn("[gupshup] first time seeing this event_type", {
366630
366692
  instanceId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260615.1",
3
+ "version": "2.260616.1",
4
4
  "description": "LLM-optimized CLI for Omni",
5
5
  "type": "module",
6
6
  "bin": {