@automagik/omni 2.260902.5 → 2.260903.2

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.
@@ -68655,7 +68655,7 @@ var require_ClientVoiceManager = __commonJS((exports, module) => {
68655
68655
 
68656
68656
  // ../../node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist/index.js
68657
68657
  var require_dist9 = __commonJS((exports, module) => {
68658
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist";
68658
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist";
68659
68659
  var __create2 = Object.create;
68660
68660
  var __defProp2 = Object.defineProperty;
68661
68661
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -132634,12 +132634,12 @@ var require_minimal = __commonJS((exports) => {
132634
132634
  util3.newError = newError;
132635
132635
  util3.ProtocolError = newError("ProtocolError");
132636
132636
  util3.oneOfGetter = function getOneOf(fieldNames) {
132637
- var fieldMap = {};
132637
+ var fieldMap2 = {};
132638
132638
  for (var i = 0;i < fieldNames.length; ++i)
132639
- fieldMap[fieldNames[i]] = 1;
132639
+ fieldMap2[fieldNames[i]] = 1;
132640
132640
  return function() {
132641
132641
  for (var keys = Object.keys(this), i2 = keys.length - 1;i2 > -1; --i2)
132642
- if (fieldMap[keys[i2]] === 1 && this[keys[i2]] !== undefined && this[keys[i2]] !== null)
132642
+ if (fieldMap2[keys[i2]] === 1 && this[keys[i2]] !== undefined && this[keys[i2]] !== null)
132643
132643
  return keys[i2];
132644
132644
  };
132645
132645
  };
@@ -135823,12 +135823,12 @@ var require_minimal2 = __commonJS((exports) => {
135823
135823
  util3.newError = newError;
135824
135824
  util3.ProtocolError = newError("ProtocolError");
135825
135825
  util3.oneOfGetter = function getOneOf(fieldNames) {
135826
- var fieldMap = {};
135826
+ var fieldMap2 = {};
135827
135827
  for (var i = 0;i < fieldNames.length; ++i)
135828
- fieldMap[fieldNames[i]] = 1;
135828
+ fieldMap2[fieldNames[i]] = 1;
135829
135829
  return function() {
135830
135830
  for (var keys = Object.keys(this), i2 = keys.length - 1;i2 > -1; --i2)
135831
- if (fieldMap[keys[i2]] === 1 && this[keys[i2]] !== undefined && this[keys[i2]] !== null)
135831
+ if (fieldMap2[keys[i2]] === 1 && this[keys[i2]] !== undefined && this[keys[i2]] !== null)
135832
135832
  return keys[i2];
135833
135833
  };
135834
135834
  };
@@ -153935,7 +153935,7 @@ var require_indexes = __commonJS((exports, module) => {
153935
153935
 
153936
153936
  // ../../node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream/index.js
153937
153937
  var require_thread_stream = __commonJS((exports, module) => {
153938
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream";
153938
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream";
153939
153939
  var { version } = require_package5();
153940
153940
  var { EventEmitter: EventEmitter3 } = __require("events");
153941
153941
  var { Worker } = __require("worker_threads");
@@ -154356,7 +154356,7 @@ var require_thread_stream = __commonJS((exports, module) => {
154356
154356
 
154357
154357
  // ../../node_modules/.bun/pino@9.14.0/node_modules/pino/lib/transport.js
154358
154358
  var require_transport2 = __commonJS((exports, module) => {
154359
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/pino@9.14.0/node_modules/pino/lib";
154359
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/pino@9.14.0/node_modules/pino/lib";
154360
154360
  var { createRequire: createRequire2 } = __require("module");
154361
154361
  var getCallers = require_caller();
154362
154362
  var { join: join7, isAbsolute, sep: sep2 } = __require("path");
@@ -164744,6 +164744,7 @@ var init_schema2 = __esm(() => {
164744
164744
  gupshupAuthToken: text("gupshup_auth_token"),
164745
164745
  gupshupEventId: varchar("gupshup_event_id", { length: 255 }),
164746
164746
  webhookVerifyToken: text("webhook_verify_token"),
164747
+ gupshupHandoffOptions: jsonb("gupshup_handoff_options").$type(),
164747
164748
  twilioAccountSid: varchar("twilio_account_sid", { length: 34 }),
164748
164749
  twilioAuthToken: text("twilio_auth_token"),
164749
164750
  twilioFrom: varchar("twilio_from", { length: 64 }),
@@ -235675,7 +235676,7 @@ var require_client3 = __commonJS((exports) => {
235675
235676
 
235676
235677
  // ../../node_modules/.bun/@sentry+node-core@10.52.0+6488de8736d8e524/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js
235677
235678
  var require_esmLoader = __commonJS((exports) => {
235678
- var __filename = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@sentry+node-core@10.52.0+6488de8736d8e524/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js";
235679
+ var __filename = "/home/runner/work/omni/omni/node_modules/.bun/@sentry+node-core@10.52.0+6488de8736d8e524/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js";
235679
235680
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
235680
235681
  var core3 = require_cjs6();
235681
235682
  var importInTheMiddle = require_import_in_the_middle();
@@ -242901,7 +242902,7 @@ var init_sentry_scrub = __esm(() => {
242901
242902
  var require_package7 = __commonJS((exports, module) => {
242902
242903
  module.exports = {
242903
242904
  name: "@omni/api",
242904
- version: "2.260902.5",
242905
+ version: "2.260903.2",
242905
242906
  type: "module",
242906
242907
  exports: {
242907
242908
  ".": {
@@ -278656,7 +278657,7 @@ var require_src52 = __commonJS((exports) => {
278656
278657
 
278657
278658
  // ../../node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src/channelz.js
278658
278659
  var require_channelz = __commonJS((exports) => {
278659
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
278660
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
278660
278661
  Object.defineProperty(exports, "__esModule", { value: true });
278661
278662
  exports.registerChannelzSocket = exports.registerChannelzServer = exports.registerChannelzSubchannel = exports.registerChannelzChannel = exports.ChannelzCallTrackerStub = exports.ChannelzCallTracker = exports.ChannelzChildrenTrackerStub = exports.ChannelzChildrenTracker = exports.ChannelzTrace = exports.ChannelzTraceStub = undefined;
278662
278663
  exports.unregisterChannelzRef = unregisterChannelzRef;
@@ -284059,7 +284060,7 @@ var require_duration = __commonJS((exports) => {
284059
284060
 
284060
284061
  // ../../node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src/orca.js
284061
284062
  var require_orca = __commonJS((exports) => {
284062
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
284063
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
284063
284064
  Object.defineProperty(exports, "__esModule", { value: true });
284064
284065
  exports.OrcaOobMetricsSubchannelWrapper = exports.GRPC_METRICS_HEADER = exports.ServerMetricRecorder = exports.PerRequestMetricRecorder = undefined;
284065
284066
  exports.createOrcaClient = createOrcaClient;
@@ -304265,8 +304266,8 @@ class GenerateContentResponse {
304265
304266
  let anyTextPartText = false;
304266
304267
  const nonTextParts = [];
304267
304268
  for (const part of (_h = (_g = (_f = (_e = this.candidates) === null || _e === undefined ? undefined : _e[0]) === null || _f === undefined ? undefined : _f.content) === null || _g === undefined ? undefined : _g.parts) !== null && _h !== undefined ? _h : []) {
304268
- for (const [fieldName, fieldValue] of Object.entries(part)) {
304269
- if (fieldName !== "text" && fieldName !== "thought" && fieldName !== "thoughtSignature" && (fieldValue !== null || fieldValue !== undefined)) {
304269
+ for (const [fieldName, fieldValue2] of Object.entries(part)) {
304270
+ if (fieldName !== "text" && fieldName !== "thought" && fieldName !== "thoughtSignature" && (fieldValue2 !== null || fieldValue2 !== undefined)) {
304270
304271
  nonTextParts.push(fieldName);
304271
304272
  }
304272
304273
  }
@@ -304294,8 +304295,8 @@ class GenerateContentResponse {
304294
304295
  let data = "";
304295
304296
  const nonDataParts = [];
304296
304297
  for (const part of (_h = (_g = (_f = (_e = this.candidates) === null || _e === undefined ? undefined : _e[0]) === null || _f === undefined ? undefined : _f.content) === null || _g === undefined ? undefined : _g.parts) !== null && _h !== undefined ? _h : []) {
304297
- for (const [fieldName, fieldValue] of Object.entries(part)) {
304298
- if (fieldName !== "inlineData" && (fieldValue !== null || fieldValue !== undefined)) {
304298
+ for (const [fieldName, fieldValue2] of Object.entries(part)) {
304299
+ if (fieldName !== "inlineData" && (fieldValue2 !== null || fieldValue2 !== undefined)) {
304299
304300
  nonDataParts.push(fieldName);
304300
304301
  }
304301
304302
  }
@@ -304450,8 +304451,8 @@ class LiveServerMessage {
304450
304451
  let anyTextPartFound = false;
304451
304452
  const nonTextParts = [];
304452
304453
  for (const part of (_c = (_b = (_a2 = this.serverContent) === null || _a2 === undefined ? undefined : _a2.modelTurn) === null || _b === undefined ? undefined : _b.parts) !== null && _c !== undefined ? _c : []) {
304453
- for (const [fieldName, fieldValue] of Object.entries(part)) {
304454
- if (fieldName !== "text" && fieldName !== "thought" && fieldValue !== null) {
304454
+ for (const [fieldName, fieldValue2] of Object.entries(part)) {
304455
+ if (fieldName !== "text" && fieldName !== "thought" && fieldValue2 !== null) {
304455
304456
  nonTextParts.push(fieldName);
304456
304457
  }
304457
304458
  }
@@ -304473,8 +304474,8 @@ class LiveServerMessage {
304473
304474
  let data = "";
304474
304475
  const nonDataParts = [];
304475
304476
  for (const part of (_c = (_b = (_a2 = this.serverContent) === null || _a2 === undefined ? undefined : _a2.modelTurn) === null || _b === undefined ? undefined : _b.parts) !== null && _c !== undefined ? _c : []) {
304476
- for (const [fieldName, fieldValue] of Object.entries(part)) {
304477
- if (fieldName !== "inlineData" && fieldValue !== null) {
304477
+ for (const [fieldName, fieldValue2] of Object.entries(part)) {
304478
+ if (fieldName !== "inlineData" && fieldValue2 !== null) {
304478
304479
  nonDataParts.push(fieldName);
304479
304480
  }
304480
304481
  }
@@ -304705,23 +304706,23 @@ function processJsonSchema(_jsonSchema) {
304705
304706
  if (_jsonSchema["type"] instanceof Array) {
304706
304707
  flattenTypeArrayToAnyOf(_jsonSchema["type"], genAISchema);
304707
304708
  }
304708
- for (const [fieldName, fieldValue] of Object.entries(_jsonSchema)) {
304709
- if (fieldValue == null) {
304709
+ for (const [fieldName, fieldValue2] of Object.entries(_jsonSchema)) {
304710
+ if (fieldValue2 == null) {
304710
304711
  continue;
304711
304712
  }
304712
304713
  if (fieldName == "type") {
304713
- if (fieldValue === "null") {
304714
+ if (fieldValue2 === "null") {
304714
304715
  throw new Error("type: null can not be the only possible type for the field.");
304715
304716
  }
304716
- if (fieldValue instanceof Array) {
304717
+ if (fieldValue2 instanceof Array) {
304717
304718
  continue;
304718
304719
  }
304719
- genAISchema["type"] = Object.values(Type).includes(fieldValue.toUpperCase()) ? fieldValue.toUpperCase() : Type.TYPE_UNSPECIFIED;
304720
+ genAISchema["type"] = Object.values(Type).includes(fieldValue2.toUpperCase()) ? fieldValue2.toUpperCase() : Type.TYPE_UNSPECIFIED;
304720
304721
  } else if (schemaFieldNames.includes(fieldName)) {
304721
- genAISchema[fieldName] = processJsonSchema(fieldValue);
304722
+ genAISchema[fieldName] = processJsonSchema(fieldValue2);
304722
304723
  } else if (listSchemaFieldNames.includes(fieldName)) {
304723
304724
  const listSchemaFieldValue = [];
304724
- for (const item of fieldValue) {
304725
+ for (const item of fieldValue2) {
304725
304726
  if (item["type"] == "null") {
304726
304727
  genAISchema["nullable"] = true;
304727
304728
  continue;
@@ -304731,7 +304732,7 @@ function processJsonSchema(_jsonSchema) {
304731
304732
  genAISchema[fieldName] = listSchemaFieldValue;
304732
304733
  } else if (dictSchemaFieldNames.includes(fieldName)) {
304733
304734
  const dictSchemaFieldValue = {};
304734
- for (const [key, value] of Object.entries(fieldValue)) {
304735
+ for (const [key, value] of Object.entries(fieldValue2)) {
304735
304736
  dictSchemaFieldValue[key] = processJsonSchema(value);
304736
304737
  }
304737
304738
  genAISchema[fieldName] = dictSchemaFieldValue;
@@ -304739,7 +304740,7 @@ function processJsonSchema(_jsonSchema) {
304739
304740
  if (fieldName === "additionalProperties") {
304740
304741
  continue;
304741
304742
  }
304742
- genAISchema[fieldName] = fieldValue;
304743
+ genAISchema[fieldName] = fieldValue2;
304743
304744
  }
304744
304745
  }
304745
304746
  return genAISchema;
@@ -359867,7 +359868,7 @@ function registerInstanceSchemas(registry4) {
359867
359868
  }
359868
359869
  });
359869
359870
  }
359870
- var InstanceSchema2, CreateInstanceSchema2, InstanceStatusSchema2, QrCodeSchema, PairingCodeRequestSchema, PairingCodeSchema, ConnectInstanceSchema, ConnectResponseSchema, UserProfileSchema, ContactSchema, GroupSchema, SupportedChannelSchema;
359871
+ var InstanceSchema2, gupshupHandoffFieldValue, gupshupHandoffFieldKey, gupshupHandoffFields, GupshupHandoffOptionsSchema, CreateInstanceSchema2, InstanceStatusSchema2, QrCodeSchema, PairingCodeRequestSchema, PairingCodeSchema, ConnectInstanceSchema, ConnectResponseSchema, UserProfileSchema, ContactSchema, GroupSchema, SupportedChannelSchema;
359871
359872
  var init_instances2 = __esm(() => {
359872
359873
  init_src();
359873
359874
  init_zod_openapi();
@@ -359891,6 +359892,40 @@ var init_instances2 = __esm(() => {
359891
359892
  createdAt: exports_external.string().datetime().openapi({ description: "Creation timestamp" }),
359892
359893
  updatedAt: exports_external.string().datetime().openapi({ description: "Last update timestamp" })
359893
359894
  });
359895
+ gupshupHandoffFieldValue = exports_external.string().max(2048);
359896
+ gupshupHandoffFieldKey = exports_external.string().min(1).max(128);
359897
+ gupshupHandoffFields = exports_external.record(gupshupHandoffFieldKey, gupshupHandoffFieldValue);
359898
+ GupshupHandoffOptionsSchema = exports_external.object({
359899
+ defaultFields: gupshupHandoffFields.optional().openapi({
359900
+ description: "Routing fields merged under whatever the emitter sent; explicit handoff fields always win, so system-initiated handoffs (dispatch error, silence watchdog) still land in a queue",
359901
+ example: { queue: "SALES" }
359902
+ }),
359903
+ fieldsByPhonePrefix: exports_external.array(exports_external.object({
359904
+ prefixes: exports_external.array(exports_external.string().min(1).max(15).regex(/^\d+$/)).min(1).max(256).openapi({
359905
+ description: "Digit-only phone prefixes (country code first, no +)",
359906
+ example: ["5511", "5521"]
359907
+ }),
359908
+ fields: gupshupHandoffFields.openapi({
359909
+ description: "Routing fields applied when the customer phone starts with one of the prefixes",
359910
+ example: { queue: "SALES-SOUTHEAST" }
359911
+ })
359912
+ })).max(64).optional().openapi({ description: "Prefix rules layered over defaultFields; the first matching rule wins" }),
359913
+ customerFields: exports_external.array(exports_external.object({
359914
+ apiKey: gupshupHandoffFieldKey.openapi({ description: "customerFields apiKey your Gupshup Journey reads" }),
359915
+ value: gupshupHandoffFieldValue.optional().openapi({ description: "Literal value to send; mutually exclusive with `from`" }),
359916
+ from: gupshupHandoffFieldKey.optional().openapi({
359917
+ description: "Resolved handoff field to copy the value from; mutually exclusive with `value`"
359918
+ })
359919
+ }).refine((entry) => entry.value === undefined !== (entry.from === undefined), {
359920
+ message: "each customerFields entry needs exactly one of `value` or `from`"
359921
+ })).max(64).optional().openapi({
359922
+ description: "Ordered template for the Custom Integration customerFields array. Entries whose source resolves empty are dropped; the array is only sent when non-empty",
359923
+ example: [
359924
+ { apiKey: "Queue", from: "queue" },
359925
+ { apiKey: "Handled By", value: "assistant" }
359926
+ ]
359927
+ })
359928
+ }).strict();
359894
359929
  CreateInstanceSchema2 = exports_external.object({
359895
359930
  name: exports_external.string().min(1).max(255).openapi({ description: "Unique name for the instance" }),
359896
359931
  channel: ChannelTypeSchema.openapi({ description: "Channel type" }),
@@ -359901,7 +359936,18 @@ var init_instances2 = __esm(() => {
359901
359936
  }),
359902
359937
  agentStreamMode: exports_external.boolean().default(false).openapi({ description: "Enable streaming responses" }),
359903
359938
  isDefault: exports_external.boolean().default(false).openapi({ description: "Set as default instance for channel" }),
359904
- token: exports_external.string().optional().openapi({ description: "Bot token for Discord instances" })
359939
+ token: exports_external.string().optional().openapi({ description: "Bot token for Discord instances" }),
359940
+ gupshupHandoffOptions: GupshupHandoffOptionsSchema.nullable().optional().openapi({
359941
+ description: "Gupshup HANDOFF routing defaults and customerFields template (gupshup instances only). Read by the plugin at connect: restart the instance after changing it. null clears it",
359942
+ example: {
359943
+ defaultFields: { queue: "SALES" },
359944
+ fieldsByPhonePrefix: [{ prefixes: ["5511", "5521"], fields: { queue: "SALES-SOUTHEAST" } }],
359945
+ customerFields: [
359946
+ { apiKey: "Queue", from: "queue" },
359947
+ { apiKey: "Handled By", value: "assistant" }
359948
+ ]
359949
+ }
359950
+ })
359905
359951
  });
359906
359952
  InstanceStatusSchema2 = exports_external.object({
359907
359953
  instanceId: exports_external.string().uuid().openapi({ description: "Instance UUID" }),
@@ -366744,6 +366790,8 @@ function applyGupshupConnectionOptions(options, input) {
366744
366790
  options.gupshupAuthToken = input.gupshupAuthToken;
366745
366791
  if (input.gupshupEventId)
366746
366792
  options.gupshupEventId = input.gupshupEventId;
366793
+ if (input.gupshupHandoffOptions)
366794
+ options.gupshupHandoffOptions = input.gupshupHandoffOptions;
366747
366795
  if (input.webhookVerifyToken)
366748
366796
  options.webhookVerifyToken = input.webhookVerifyToken;
366749
366797
  }
@@ -366927,6 +366975,7 @@ function buildConnectConnectionOptions(instance4, body, forceNewQr) {
366927
366975
  gupshupCallbackUrl: instance4.gupshupCallbackUrl,
366928
366976
  gupshupAuthToken: instance4.gupshupAuthToken,
366929
366977
  gupshupEventId: instance4.gupshupEventId,
366978
+ gupshupHandoffOptions: instance4.gupshupHandoffOptions,
366930
366979
  webhookVerifyToken: instance4.webhookVerifyToken,
366931
366980
  twilioAccountSid: body.twilioAccountSid ?? instance4.twilioAccountSid,
366932
366981
  twilioAuthToken: body.twilioAuthToken ?? body.token ?? instance4.twilioAuthToken,
@@ -367100,6 +367149,7 @@ var init_instances3 = __esm(() => {
367100
367149
  init_auth();
367101
367150
  init_agent_dispatcher();
367102
367151
  init_qr_store();
367152
+ init_instances2();
367103
367153
  init_access();
367104
367154
  init_agent_replay();
367105
367155
  log117 = createLogger("api:instances");
@@ -367165,6 +367215,7 @@ var init_instances3 = __esm(() => {
367165
367215
  gupshupCallbackUrl: exports_external.string().optional().nullable().describe("Gupshup Custom Integration callback URL"),
367166
367216
  gupshupAuthToken: exports_external.string().optional().nullable().describe("Gupshup Custom Integration auth token"),
367167
367217
  gupshupEventId: exports_external.string().optional().nullable().describe("Gupshup event ID (default: nx_omni_agent_reply)"),
367218
+ gupshupHandoffOptions: GupshupHandoffOptionsSchema.optional().nullable().describe("Gupshup HANDOFF routing defaults and customerFields template"),
367168
367219
  webhookVerifyToken: exports_external.string().optional().nullable().describe("Gupshup webhook verify token"),
367169
367220
  twilioAccountSid: exports_external.string().optional().nullable().describe("Twilio Account SID"),
367170
367221
  twilioAuthToken: exports_external.string().optional().nullable().describe("Twilio Auth Token"),
@@ -367204,6 +367255,7 @@ var init_instances3 = __esm(() => {
367204
367255
  gupshupCallbackUrl: exports_external.string().nullable().optional(),
367205
367256
  gupshupAuthToken: exports_external.string().nullable().optional(),
367206
367257
  gupshupEventId: exports_external.string().nullable().optional(),
367258
+ gupshupHandoffOptions: GupshupHandoffOptionsSchema.nullable().optional(),
367207
367259
  webhookVerifyToken: exports_external.string().nullable().optional(),
367208
367260
  twilioAccountSid: exports_external.string().nullable().optional(),
367209
367261
  twilioAuthToken: exports_external.string().nullable().optional(),
@@ -367334,6 +367386,7 @@ var init_instances3 = __esm(() => {
367334
367386
  gupshupCallbackUrl: instance4.gupshupCallbackUrl,
367335
367387
  gupshupAuthToken: instance4.gupshupAuthToken,
367336
367388
  gupshupEventId: instance4.gupshupEventId,
367389
+ gupshupHandoffOptions: instance4.gupshupHandoffOptions,
367337
367390
  webhookVerifyToken: instance4.webhookVerifyToken,
367338
367391
  twilioAccountSid: instance4.twilioAccountSid,
367339
367392
  twilioAuthToken: instance4.twilioAuthToken,
@@ -367686,6 +367739,9 @@ var init_instances3 = __esm(() => {
367686
367739
  if (instance4.channel === "hermes") {
367687
367740
  applyHermesConnectionOptions(restartOptions, instance4);
367688
367741
  }
367742
+ if (instance4.channel === "gupshup") {
367743
+ applyGupshupConnectionOptions(restartOptions, instance4);
367744
+ }
367689
367745
  if (instance4.channel === "whatsapp-business") {
367690
367746
  applyWhatsAppBusinessConnectionOptions(restartOptions, instance4);
367691
367747
  }
@@ -377712,6 +377768,8 @@ function applyGupshupOptions(options, instance4) {
377712
377768
  options.gupshupAuthToken = instance4.gupshupAuthToken;
377713
377769
  if (instance4.gupshupEventId)
377714
377770
  options.gupshupEventId = instance4.gupshupEventId;
377771
+ if (instance4.gupshupHandoffOptions)
377772
+ options.gupshupHandoffOptions = instance4.gupshupHandoffOptions;
377715
377773
  if (instance4.gupshupApiKey)
377716
377774
  options.gupshupApiKey = instance4.gupshupApiKey;
377717
377775
  if (instance4.gupshupAppName)
@@ -383228,6 +383286,7 @@ var src_default = plugin2;
383228
383286
 
383229
383287
  // ../channel-gupshup/src/plugin.ts
383230
383288
  init_src2();
383289
+ init_zod();
383231
383290
 
383232
383291
  // ../channel-gupshup/src/capabilities.ts
383233
383292
  init_src2();
@@ -383350,6 +383409,8 @@ class GupshupClient {
383350
383409
  payload.motivo_handoff = msg.motivo_handoff;
383351
383410
  if (msg.handoff_fields)
383352
383411
  payload.handoff_fields = msg.handoff_fields;
383412
+ if (msg.customer_fields && msg.customer_fields.length > 0)
383413
+ payload.customerFields = msg.customer_fields;
383353
383414
  const res = await fetch(this.callbackUrl, {
383354
383415
  method: "POST",
383355
383416
  headers: { "Content-Type": "application/json", Authorization: this.authToken },
@@ -383866,6 +383927,67 @@ function extractContent2(msg) {
383866
383927
  return null;
383867
383928
  }
383868
383929
 
383930
+ // ../channel-gupshup/src/handoff-options.ts
383931
+ init_zod();
383932
+ var fieldValue = exports_external.string().max(2048);
383933
+ var fieldKey = exports_external.string().min(1).max(128);
383934
+ var fieldMap = exports_external.record(fieldKey, fieldValue);
383935
+ var gupshupHandoffOptionsSchema = exports_external.object({
383936
+ defaultFields: fieldMap.optional(),
383937
+ fieldsByPhonePrefix: exports_external.array(exports_external.object({
383938
+ prefixes: exports_external.array(exports_external.string().min(1).max(15).regex(/^\d+$/, "prefixes must be digits only")).min(1).max(256),
383939
+ fields: fieldMap
383940
+ })).max(64).optional(),
383941
+ customerFields: exports_external.array(exports_external.object({
383942
+ apiKey: fieldKey,
383943
+ value: fieldValue.optional(),
383944
+ from: fieldKey.optional()
383945
+ }).refine((entry) => entry.value === undefined !== (entry.from === undefined), {
383946
+ message: "each customerFields entry needs exactly one of `value` or `from`"
383947
+ })).max(64).optional()
383948
+ }).strict();
383949
+ var EMPTY_SENTINELS = new Set(["", "undefined", "null"]);
383950
+ function cleanValue(value) {
383951
+ const text = String(value ?? "").trim();
383952
+ return EMPTY_SENTINELS.has(text.toLowerCase()) ? "" : text;
383953
+ }
383954
+ function parseHandoffOptions(raw) {
383955
+ if (raw === undefined || raw === null)
383956
+ return;
383957
+ return gupshupHandoffOptionsSchema.parse(raw);
383958
+ }
383959
+ function resolveHandoffFields(phone, explicit, options) {
383960
+ if (!options)
383961
+ return explicit;
383962
+ const defaults = { ...options.defaultFields ?? {} };
383963
+ const digits = String(phone ?? "").replace(/\D/g, "");
383964
+ if (digits && options.fieldsByPhonePrefix) {
383965
+ const rule = options.fieldsByPhonePrefix.find((r) => r.prefixes.some((p2) => digits.startsWith(p2)));
383966
+ if (rule)
383967
+ Object.assign(defaults, rule.fields);
383968
+ }
383969
+ if (Object.keys(defaults).length === 0)
383970
+ return explicit;
383971
+ const out = { ...explicit ?? {} };
383972
+ for (const [key, value] of Object.entries(defaults)) {
383973
+ if (cleanValue(out[key]) === "")
383974
+ out[key] = value;
383975
+ }
383976
+ return out;
383977
+ }
383978
+ function buildCustomerFields(handoffFields, template) {
383979
+ if (!template || template.length === 0)
383980
+ return;
383981
+ const out = [];
383982
+ for (const entry of template) {
383983
+ const value = entry.value !== undefined ? cleanValue(entry.value) : cleanValue(handoffFields?.[entry.from]);
383984
+ if (value === "")
383985
+ continue;
383986
+ out.push({ apiKey: entry.apiKey, value });
383987
+ }
383988
+ return out.length > 0 ? out : undefined;
383989
+ }
383990
+
383869
383991
  // ../channel-gupshup/src/senders/close-contact.ts
383870
383992
  var GUPSHUP_CLOSE_MSG_TYPE = "CLOSING";
383871
383993
  async function sendCloseContact(client, to, text, closeReason, closeOutcome, closeFields) {
@@ -383879,13 +384001,14 @@ async function sendCloseContact(client, to, text, closeReason, closeOutcome, clo
383879
384001
  }
383880
384002
 
383881
384003
  // ../channel-gupshup/src/senders/handoff.ts
383882
- async function sendHandoff(client, to, text, dadosLead, motivoHandoff, handoffFields) {
384004
+ async function sendHandoff(client, to, text, dadosLead, motivoHandoff, handoffFields, customerFields) {
383883
384005
  return client.send(to, {
383884
384006
  type: "HANDOFF",
383885
384007
  text,
383886
384008
  dados_lead: dadosLead,
383887
384009
  motivo_handoff: motivoHandoff,
383888
- handoff_fields: handoffFields
384010
+ handoff_fields: handoffFields,
384011
+ ...customerFields ? { customer_fields: customerFields } : {}
383889
384012
  });
383890
384013
  }
383891
384014
 
@@ -383941,15 +384064,17 @@ function toGupshupPhone(phone) {
383941
384064
  }
383942
384065
 
383943
384066
  // ../channel-gupshup/src/plugin.ts
383944
- async function dispatchContent(client, dest, message2) {
384067
+ async function dispatchContent(client, dest, message2, handoffOptions) {
383945
384068
  const { content } = message2;
383946
384069
  const meta = message2.metadata;
383947
384070
  const mediaTypes = new Set(["image", "audio", "video", "document", "sticker"]);
383948
384071
  if (meta?.isHandoff === true) {
383949
384072
  const dadosLead = meta.dadosLead;
383950
384073
  const motivoHandoff = meta.motivoHandoff;
383951
- const handoffFields = meta.handoffFields;
383952
- return sendHandoff(client, dest, content.text ?? "", dadosLead, motivoHandoff, handoffFields);
384074
+ const explicitFields = meta.handoffFields;
384075
+ const handoffFields = resolveHandoffFields(dest, explicitFields, handoffOptions);
384076
+ const customerFields = buildCustomerFields(handoffFields, handoffOptions?.customerFields);
384077
+ return sendHandoff(client, dest, content.text ?? "", dadosLead, motivoHandoff, handoffFields, customerFields);
383953
384078
  }
383954
384079
  if (meta?.isCloseContact === true) {
383955
384080
  const closeReason = meta.closeReason;
@@ -384021,6 +384146,13 @@ class GupshupPlugin extends BaseChannelPlugin {
384021
384146
  const authToken = creds.gupshupAuthToken ?? opts.gupshupAuthToken;
384022
384147
  const eventId = creds.gupshupEventId ?? opts.gupshupEventId ?? "nx_omni_agent_reply";
384023
384148
  const webhookVerifyToken = creds.webhookVerifyToken ?? opts.webhookVerifyToken;
384149
+ let handoffOptions;
384150
+ try {
384151
+ handoffOptions = parseHandoffOptions(creds.gupshupHandoffOptions ?? opts.gupshupHandoffOptions);
384152
+ } catch (err2) {
384153
+ const detail = err2 instanceof ZodError ? err2.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ") : String(err2);
384154
+ throw new GupshupError(GupshupErrorCode.BAD_REQUEST, `gupshupHandoffOptions is invalid \u2014 ${detail}`);
384155
+ }
384024
384156
  if (!callbackUrl)
384025
384157
  throw new GupshupError(GupshupErrorCode.AUTH_FAILED, "gupshupCallbackUrl is required");
384026
384158
  if (!authToken)
@@ -384035,7 +384167,8 @@ class GupshupPlugin extends BaseChannelPlugin {
384035
384167
  gupshupCallbackUrl: callbackUrl,
384036
384168
  gupshupAuthToken: authToken,
384037
384169
  gupshupEventId: eventId,
384038
- webhookVerifyToken
384170
+ webhookVerifyToken,
384171
+ handoffOptions
384039
384172
  };
384040
384173
  const dedupeCache = createInboundDedupeCache();
384041
384174
  this.gupshupInstances.set(instanceId, { client, config: gupshupConfig, dedupeCache });
@@ -384076,7 +384209,7 @@ class GupshupPlugin extends BaseChannelPlugin {
384076
384209
  if (correlationId)
384077
384210
  this.captureT10(correlationId);
384078
384211
  try {
384079
- const response = await dispatchContent(client, dest, message2);
384212
+ const response = await dispatchContent(client, dest, message2, state.config.handoffOptions);
384080
384213
  const providerAliases = extractGupshupProviderAliases(response);
384081
384214
  const messageId = extractResponseString(response, "messageId") ?? crypto.randomUUID();
384082
384215
  if (correlationId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260902.5",
3
+ "version": "2.260903.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/automagik-dev/omni.git",