@automagik/omni 2.260603.6 → 2.260609.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.
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.260603.6",
124974
+ version: "2.260609.2",
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.260603.6",
225248
+ version: "2.260609.2",
225249
225249
  type: "module",
225250
225250
  exports: {
225251
225251
  ".": {
@@ -335731,6 +335731,23 @@ class MessageService {
335731
335731
  const [result] = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.externalId, externalId))).limit(1);
335732
335732
  return result ?? null;
335733
335733
  }
335734
+ async findByProviderAlias(chatId, aliases) {
335735
+ const candidates = [
335736
+ ...new Set(aliases.filter((alias3) => typeof alias3 === "string" && alias3.length > 0).map((alias3) => alias3.slice(0, 255)))
335737
+ ].slice(0, 8);
335738
+ if (candidates.length === 0)
335739
+ return null;
335740
+ const aliasConditions = candidates.flatMap((alias3) => [
335741
+ eq(messages2.externalId, alias3),
335742
+ sql`${messages2.rawPayload}->'gupshupResponse'->>'messageId' = ${alias3}`,
335743
+ sql`${messages2.rawPayload}->'gupshupResponse'->>'gsId' = ${alias3}`,
335744
+ sql`${messages2.rawPayload}->'gupshupResponse'->>'id' = ${alias3}`,
335745
+ sql`${messages2.rawPayload}->'gupshupResponse'->'messageIds' @> ${JSON.stringify([alias3])}::jsonb`,
335746
+ sql`${messages2.rawPayload}->'gupshupProviderAliases' @> ${JSON.stringify([alias3])}::jsonb`
335747
+ ]);
335748
+ const [result] = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.isFromMe, true), or2(...aliasConditions))).orderBy(desc(messages2.platformTimestamp)).limit(1);
335749
+ return result ?? null;
335750
+ }
335734
335751
  async getByExternalIds(chatId, externalIds) {
335735
335752
  if (externalIds.length === 0)
335736
335753
  return [];
@@ -338434,12 +338451,35 @@ function getMessageContentText(msg) {
338434
338451
  return msg.textContent;
338435
338452
  }
338436
338453
  }
338437
- async function resolveQuotedMessage(services, instanceId, chatId, replyToId) {
338454
+ function uniqueNonEmpty(values2) {
338455
+ return [...new Set(values2.filter((value) => typeof value === "string" && value.length > 0))];
338456
+ }
338457
+ async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
338458
+ const quoted = await messages4.getByExternalId(chatDbId, replyToId);
338459
+ if (quoted)
338460
+ return quoted;
338461
+ const candidates = uniqueNonEmpty([replyToId, ...aliases]);
338462
+ const aliasLookup = messages4;
338463
+ if (aliasLookup.findByProviderAlias && candidates.length > 0) {
338464
+ const byAlias = await aliasLookup.findByProviderAlias(chatDbId, candidates);
338465
+ if (byAlias)
338466
+ return byAlias;
338467
+ }
338468
+ for (const candidate of candidates) {
338469
+ if (candidate === replyToId)
338470
+ continue;
338471
+ const byExternalId = await messages4.getByExternalId(chatDbId, candidate);
338472
+ if (byExternalId)
338473
+ return byExternalId;
338474
+ }
338475
+ return null;
338476
+ }
338477
+ async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = []) {
338438
338478
  try {
338439
338479
  const chat2 = await services.chats.findByExternalIdSmart(instanceId, chatId);
338440
338480
  if (!chat2)
338441
338481
  return null;
338442
- const quoted = await services.messages.getByExternalId(chat2.id, replyToId);
338482
+ const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases);
338443
338483
  if (!quoted)
338444
338484
  return null;
338445
338485
  const sender = quoted.senderDisplayName ?? quoted.senderPlatformUserId ?? (quoted.isFromMe ? "You" : "unknown");
@@ -338504,12 +338544,29 @@ async function collectProcessedMedia(services, instance4, messages4) {
338504
338544
  }
338505
338545
  return results;
338506
338546
  }
338547
+ function extractQuotedProviderAliases(rawPayload) {
338548
+ if (!rawPayload)
338549
+ return [];
338550
+ const messageObj = isRecord(rawPayload.messageobj) ? rawPayload.messageobj : undefined;
338551
+ const replyContext = isRecord(messageObj?.replyContext) ? messageObj.replyContext : undefined;
338552
+ const rawMessage = isRecord(messageObj?.raw) ? messageObj.raw : undefined;
338553
+ const rawContext = isRecord(rawMessage?.context) ? rawMessage.context : undefined;
338554
+ const topContext = isRecord(rawPayload.context) ? rawPayload.context : undefined;
338555
+ return uniqueNonEmpty([
338556
+ replyContext?.internalId,
338557
+ rawContext?.gsId,
338558
+ rawContext?.id,
338559
+ topContext?.gsId,
338560
+ topContext?.id
338561
+ ]);
338562
+ }
338507
338563
  async function prependQuotedContext(services, instanceId, chatId, messages4, entries, messageKeyByIndex) {
338508
338564
  for (const [index2, m2] of messages4.entries()) {
338509
338565
  const replyToId = m2.payload.replyToId;
338510
338566
  if (!replyToId)
338511
338567
  continue;
338512
- const quotedText = await resolveQuotedMessage(services, instanceId, chatId, replyToId);
338568
+ const providerAliases = extractQuotedProviderAliases(m2.payload.rawPayload);
338569
+ const quotedText = await resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases);
338513
338570
  if (!quotedText)
338514
338571
  continue;
338515
338572
  const messageKey = messageKeyByIndex.get(index2);
@@ -353111,6 +353168,27 @@ async function enrichContactNames(contacts, services, instanceId) {
353111
353168
  contact.name = dbName;
353112
353169
  }
353113
353170
  }
353171
+ async function resolveInstancePlugin(services, channelRegistry2, instanceId) {
353172
+ const instance4 = await services.instances.getById(instanceId);
353173
+ if (!channelRegistry2) {
353174
+ return { ok: false, status: 503, error: { code: "NO_REGISTRY", message: "Channel registry not available" } };
353175
+ }
353176
+ const plugin7 = channelRegistry2.get(instance4.channel);
353177
+ if (!plugin7) {
353178
+ return {
353179
+ ok: false,
353180
+ status: 400,
353181
+ error: { code: "PLUGIN_NOT_FOUND", message: `No plugin for channel: ${instance4.channel}` }
353182
+ };
353183
+ }
353184
+ return { ok: true, plugin: plugin7 };
353185
+ }
353186
+ function participantUpdateResponse(result) {
353187
+ return {
353188
+ ...result,
353189
+ changedCount: result.participants.length
353190
+ };
353191
+ }
353114
353192
  function parseDuration(duration) {
353115
353193
  const match2 = duration.match(/^(\d+)(s|m|h|d)$/);
353116
353194
  if (!match2?.[1] || !match2[2])
@@ -353150,7 +353228,7 @@ function getCacheKey(instanceId, guildId) {
353150
353228
  function invalidateGuildCache(instanceId, guildId) {
353151
353229
  guildConfigCache.delete(getCacheKey(instanceId, guildId));
353152
353230
  }
353153
- var log108, instancesRoutes, instanceAccess2, listQuerySchema12, agentReplyFilterSchema, createInstanceSchema, updateInstanceSchema, DEFAULT_AGENT_REPLY_FILTER, SENSITIVE_INSTANCE_FIELDS, pairingCodeSchema, connectInstanceSchema, syncRequestSchema, listContactsQuerySchema, listGroupsQuerySchema, checkNumberSchema, updateBioSchema, blockContactSchema, resyncSchema, replaySchema, pairingActionSchema, guildConfigOverrideSchema, guildConfigCache, GUILD_CONFIG_TTL, presenceSchema;
353231
+ var log108, instancesRoutes, instanceAccess2, listQuerySchema12, agentReplyFilterSchema, createInstanceSchema, updateInstanceSchema, DEFAULT_AGENT_REPLY_FILTER, SENSITIVE_INSTANCE_FIELDS, pairingCodeSchema, connectInstanceSchema, syncRequestSchema, listContactsQuerySchema, listGroupsQuerySchema, checkNumberSchema, updateBioSchema, blockContactSchema, groupParticipantActionSchema, groupSettingSchema, groupParticipantsSchema, groupParticipantsPatchSchema, updateGroupSubjectSchema, updateGroupDescriptionSchema, updateGroupSettingsSchema, patchGroupSchema, resyncSchema, replaySchema, pairingActionSchema, guildConfigOverrideSchema, guildConfigCache, GUILD_CONFIG_TTL, presenceSchema;
353154
353232
  var init_instances3 = __esm(() => {
353155
353233
  init_dist6();
353156
353234
  init_src();
@@ -354252,6 +354330,30 @@ var init_instances3 = __esm(() => {
354252
354330
  return c.json({ error: { code: "REMOVE_FAILED", message: message2 } }, 500);
354253
354331
  }
354254
354332
  });
354333
+ groupParticipantActionSchema = exports_external.enum(["add", "remove", "promote", "demote"]);
354334
+ groupSettingSchema = exports_external.enum(["announcement", "not_announcement", "locked", "unlocked"]);
354335
+ groupParticipantsSchema = exports_external.object({
354336
+ participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to mutate")
354337
+ });
354338
+ groupParticipantsPatchSchema = groupParticipantsSchema.extend({
354339
+ action: groupParticipantActionSchema.describe("Participant mutation action")
354340
+ });
354341
+ updateGroupSubjectSchema = exports_external.object({
354342
+ subject: exports_external.string().min(1).max(100).describe("New group name/subject")
354343
+ });
354344
+ updateGroupDescriptionSchema = exports_external.object({
354345
+ description: exports_external.string().max(2048).describe("New group description. Empty string clears the description.")
354346
+ });
354347
+ updateGroupSettingsSchema = exports_external.object({
354348
+ setting: groupSettingSchema.describe("Group setting to apply")
354349
+ });
354350
+ patchGroupSchema = exports_external.object({
354351
+ subject: exports_external.string().min(1).max(100).optional(),
354352
+ description: exports_external.string().max(2048).optional(),
354353
+ setting: groupSettingSchema.optional()
354354
+ }).refine((value) => value.subject !== undefined || value.description !== undefined || value.setting !== undefined, {
354355
+ message: "At least one of subject, description, or setting is required"
354356
+ });
354255
354357
  instancesRoutes.post("/:id/groups", instanceAccess2, zValidator("json", exports_external.object({
354256
354358
  subject: exports_external.string().min(1).max(100).describe("Group name/subject"),
354257
354359
  participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to add")
@@ -354271,6 +354373,218 @@ var init_instances3 = __esm(() => {
354271
354373
  const result = await plugin7.groupCreate(id, subject, participants);
354272
354374
  return c.json({ data: result }, 201);
354273
354375
  });
354376
+ instancesRoutes.post("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
354377
+ const id = c.req.param("id");
354378
+ const groupJid = c.req.param("groupJid");
354379
+ const { participants } = c.req.valid("json");
354380
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354381
+ if (!resolved.ok)
354382
+ return c.json({ error: resolved.error }, resolved.status);
354383
+ if (typeof resolved.plugin.updateGroupParticipants !== "function") {
354384
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
354385
+ }
354386
+ try {
354387
+ const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, "add");
354388
+ return c.json({ success: true, data: participantUpdateResponse(result) });
354389
+ } catch (error3) {
354390
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354391
+ return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
354392
+ }
354393
+ });
354394
+ instancesRoutes.post("/:id/groups/:groupJid/participants/:action", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
354395
+ const id = c.req.param("id");
354396
+ const groupJid = c.req.param("groupJid");
354397
+ const parsedAction = groupParticipantActionSchema.safeParse(c.req.param("action"));
354398
+ const { participants } = c.req.valid("json");
354399
+ if (!parsedAction.success) {
354400
+ return c.json({
354401
+ error: {
354402
+ code: "VALIDATION_ERROR",
354403
+ message: "Invalid group participant action. Expected add, remove, promote, or demote."
354404
+ }
354405
+ }, 400);
354406
+ }
354407
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354408
+ if (!resolved.ok)
354409
+ return c.json({ error: resolved.error }, resolved.status);
354410
+ if (typeof resolved.plugin.updateGroupParticipants !== "function") {
354411
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
354412
+ }
354413
+ try {
354414
+ const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, parsedAction.data);
354415
+ return c.json({ success: true, data: participantUpdateResponse(result) });
354416
+ } catch (error3) {
354417
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354418
+ return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
354419
+ }
354420
+ });
354421
+ instancesRoutes.patch("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsPatchSchema), async (c) => {
354422
+ const id = c.req.param("id");
354423
+ const groupJid = c.req.param("groupJid");
354424
+ const { action, participants } = c.req.valid("json");
354425
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354426
+ if (!resolved.ok)
354427
+ return c.json({ error: resolved.error }, resolved.status);
354428
+ if (typeof resolved.plugin.updateGroupParticipants !== "function") {
354429
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
354430
+ }
354431
+ try {
354432
+ const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, action);
354433
+ return c.json({ success: true, data: participantUpdateResponse(result) });
354434
+ } catch (error3) {
354435
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354436
+ return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
354437
+ }
354438
+ });
354439
+ instancesRoutes.patch("/:id/groups/:groupJid", instanceAccess2, zValidator("json", patchGroupSchema), async (c) => {
354440
+ const id = c.req.param("id");
354441
+ const groupJid = c.req.param("groupJid");
354442
+ const body = c.req.valid("json");
354443
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354444
+ if (!resolved.ok)
354445
+ return c.json({ error: resolved.error }, resolved.status);
354446
+ if (body.subject !== undefined && typeof resolved.plugin.updateGroupSubject !== "function") {
354447
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
354448
+ }
354449
+ if (body.description !== undefined && typeof resolved.plugin.updateGroupDescription !== "function") {
354450
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
354451
+ }
354452
+ if (body.setting !== undefined && typeof resolved.plugin.updateGroupSettings !== "function") {
354453
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
354454
+ }
354455
+ try {
354456
+ const updated = [];
354457
+ if (body.subject !== undefined) {
354458
+ await resolved.plugin.updateGroupSubject?.(id, groupJid, body.subject);
354459
+ updated.push("subject");
354460
+ }
354461
+ if (body.description !== undefined) {
354462
+ await resolved.plugin.updateGroupDescription?.(id, groupJid, body.description);
354463
+ updated.push("description");
354464
+ }
354465
+ if (body.setting !== undefined) {
354466
+ await resolved.plugin.updateGroupSettings?.(id, groupJid, body.setting);
354467
+ updated.push("settings");
354468
+ }
354469
+ return c.json({ success: true, data: { instanceId: id, groupJid, updated, ...body } });
354470
+ } catch (error3) {
354471
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354472
+ return c.json({ error: { code: "GROUP_UPDATE_FAILED", message: message2 } }, 500);
354473
+ }
354474
+ });
354475
+ instancesRoutes.put("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
354476
+ const id = c.req.param("id");
354477
+ const groupJid = c.req.param("groupJid");
354478
+ const { subject } = c.req.valid("json");
354479
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354480
+ if (!resolved.ok)
354481
+ return c.json({ error: resolved.error }, resolved.status);
354482
+ if (typeof resolved.plugin.updateGroupSubject !== "function") {
354483
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
354484
+ }
354485
+ try {
354486
+ await resolved.plugin.updateGroupSubject(id, groupJid, subject);
354487
+ return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
354488
+ } catch (error3) {
354489
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354490
+ return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
354491
+ }
354492
+ });
354493
+ instancesRoutes.post("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
354494
+ const id = c.req.param("id");
354495
+ const groupJid = c.req.param("groupJid");
354496
+ const { subject } = c.req.valid("json");
354497
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354498
+ if (!resolved.ok)
354499
+ return c.json({ error: resolved.error }, resolved.status);
354500
+ if (typeof resolved.plugin.updateGroupSubject !== "function") {
354501
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
354502
+ }
354503
+ try {
354504
+ await resolved.plugin.updateGroupSubject(id, groupJid, subject);
354505
+ return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
354506
+ } catch (error3) {
354507
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354508
+ return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
354509
+ }
354510
+ });
354511
+ instancesRoutes.put("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
354512
+ const id = c.req.param("id");
354513
+ const groupJid = c.req.param("groupJid");
354514
+ const { description } = c.req.valid("json");
354515
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354516
+ if (!resolved.ok)
354517
+ return c.json({ error: resolved.error }, resolved.status);
354518
+ if (typeof resolved.plugin.updateGroupDescription !== "function") {
354519
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
354520
+ }
354521
+ try {
354522
+ await resolved.plugin.updateGroupDescription(id, groupJid, description);
354523
+ return c.json({
354524
+ success: true,
354525
+ data: { instanceId: id, groupJid, description, action: "group_description_updated" }
354526
+ });
354527
+ } catch (error3) {
354528
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354529
+ return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
354530
+ }
354531
+ });
354532
+ instancesRoutes.post("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
354533
+ const id = c.req.param("id");
354534
+ const groupJid = c.req.param("groupJid");
354535
+ const { description } = c.req.valid("json");
354536
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354537
+ if (!resolved.ok)
354538
+ return c.json({ error: resolved.error }, resolved.status);
354539
+ if (typeof resolved.plugin.updateGroupDescription !== "function") {
354540
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
354541
+ }
354542
+ try {
354543
+ await resolved.plugin.updateGroupDescription(id, groupJid, description);
354544
+ return c.json({
354545
+ success: true,
354546
+ data: { instanceId: id, groupJid, description, action: "group_description_updated" }
354547
+ });
354548
+ } catch (error3) {
354549
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354550
+ return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
354551
+ }
354552
+ });
354553
+ instancesRoutes.post("/:id/groups/:groupJid/settings", instanceAccess2, zValidator("json", updateGroupSettingsSchema), async (c) => {
354554
+ const id = c.req.param("id");
354555
+ const groupJid = c.req.param("groupJid");
354556
+ const { setting } = c.req.valid("json");
354557
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354558
+ if (!resolved.ok)
354559
+ return c.json({ error: resolved.error }, resolved.status);
354560
+ if (typeof resolved.plugin.updateGroupSettings !== "function") {
354561
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
354562
+ }
354563
+ try {
354564
+ await resolved.plugin.updateGroupSettings(id, groupJid, setting);
354565
+ return c.json({ success: true, data: { instanceId: id, groupJid, setting, action: "group_settings_updated" } });
354566
+ } catch (error3) {
354567
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354568
+ return c.json({ error: { code: "GROUP_SETTINGS_FAILED", message: message2 } }, 500);
354569
+ }
354570
+ });
354571
+ instancesRoutes.post("/:id/groups/:groupJid/leave", instanceAccess2, async (c) => {
354572
+ const id = c.req.param("id");
354573
+ const groupJid = c.req.param("groupJid");
354574
+ const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
354575
+ if (!resolved.ok)
354576
+ return c.json({ error: resolved.error }, resolved.status);
354577
+ if (typeof resolved.plugin.leaveGroup !== "function") {
354578
+ return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support leaving groups" } }, 400);
354579
+ }
354580
+ try {
354581
+ await resolved.plugin.leaveGroup(id, groupJid);
354582
+ return c.json({ success: true, data: { instanceId: id, groupJid, left: true } });
354583
+ } catch (error3) {
354584
+ const message2 = error3 instanceof Error ? error3.message : "Unknown error";
354585
+ return c.json({ error: { code: "GROUP_LEAVE_FAILED", message: message2 } }, 500);
354586
+ }
354587
+ });
354274
354588
  instancesRoutes.get("/:id/chats/:chatId/invite", instanceAccess2, async (c) => {
354275
354589
  const id = c.req.param("id");
354276
354590
  const chatId = c.req.param("chatId");
@@ -366513,6 +366827,34 @@ async function dispatchContent(client, dest, message2) {
366513
366827
  }
366514
366828
  return sendText(client, dest, content.text ?? "[Unsupported content]");
366515
366829
  }
366830
+ function extractResponseString(response, key) {
366831
+ const value = response[key];
366832
+ if (typeof value !== "string" || value.length === 0)
366833
+ return;
366834
+ return value.slice(0, 255);
366835
+ }
366836
+ function extractGupshupMessageIds(response) {
366837
+ if (!Array.isArray(response.messageIds))
366838
+ return [];
366839
+ return response.messageIds.filter((value) => typeof value === "string" && value.length > 0).map((value) => value.slice(0, 255));
366840
+ }
366841
+ function extractGupshupProviderAliases(response) {
366842
+ return [
366843
+ extractResponseString(response, "messageId"),
366844
+ extractResponseString(response, "gsId"),
366845
+ extractResponseString(response, "id"),
366846
+ ...extractGupshupMessageIds(response)
366847
+ ].filter((value, index, values) => typeof value === "string" && values.indexOf(value) === index);
366848
+ }
366849
+ function buildGupshupResponseMetadata(response) {
366850
+ return {
366851
+ status: extractResponseString(response, "status"),
366852
+ messageId: extractResponseString(response, "messageId"),
366853
+ gsId: extractResponseString(response, "gsId"),
366854
+ id: extractResponseString(response, "id"),
366855
+ messageIds: extractGupshupMessageIds(response)
366856
+ };
366857
+ }
366516
366858
 
366517
366859
  class GupshupPlugin extends BaseChannelPlugin {
366518
366860
  id = "gupshup";
@@ -366593,7 +366935,8 @@ class GupshupPlugin extends BaseChannelPlugin {
366593
366935
  this.captureT10(correlationId);
366594
366936
  try {
366595
366937
  const response = await dispatchContent(client, dest, message2);
366596
- const messageId = typeof response.messageId === "string" ? response.messageId : crypto.randomUUID();
366938
+ const providerAliases = extractGupshupProviderAliases(response);
366939
+ const messageId = extractResponseString(response, "messageId") ?? crypto.randomUUID();
366597
366940
  if (correlationId)
366598
366941
  this.captureT11(correlationId);
366599
366942
  await this.emitMessageSent({
@@ -366607,6 +366950,10 @@ class GupshupPlugin extends BaseChannelPlugin {
366607
366950
  mediaUrl: content.mediaUrl
366608
366951
  },
366609
366952
  replyToId: message2.replyTo,
366953
+ rawPayload: {
366954
+ gupshupResponse: buildGupshupResponseMetadata(response),
366955
+ gupshupProviderAliases: providerAliases
366956
+ },
366610
366957
  senderAgentId: message2.metadata?.senderAgentId
366611
366958
  });
366612
366959
  return { success: true, messageId, timestamp: Date.now() };
@@ -482714,6 +483061,12 @@ function toJid(identifier, lidCache) {
482714
483061
  }
482715
483062
  return phoneJid;
482716
483063
  }
483064
+ function toGroupJid(groupId) {
483065
+ if (groupId.endsWith(JID_SUFFIX.GROUP)) {
483066
+ return groupId;
483067
+ }
483068
+ return `${groupId}${JID_SUFFIX.GROUP}`;
483069
+ }
482717
483070
  function fromJid(jid) {
482718
483071
  const isGroup = jid.endsWith(JID_SUFFIX.GROUP);
482719
483072
  const isBroadcast = jid.endsWith(JID_SUFFIX.BROADCAST);
@@ -486329,6 +486682,85 @@ class WhatsAppPlugin extends BaseChannelPlugin {
486329
486682
  throw waError;
486330
486683
  }
486331
486684
  }
486685
+ async updateGroupParticipants(instanceId, groupJid, participants, action) {
486686
+ await this.humanDelay(instanceId);
486687
+ const sock = this.getSocket(instanceId);
486688
+ const jid = toGroupJid(groupJid);
486689
+ const participantJids = participants.map((participant) => toJid(participant));
486690
+ try {
486691
+ const result = await sock.groupParticipantsUpdate(jid, participantJids, action);
486692
+ this.invalidateGroupMetadataCache(instanceId, jid);
486693
+ this.logger.info("Group participants updated", {
486694
+ instanceId,
486695
+ groupJid: jid,
486696
+ action,
486697
+ participantCount: participantJids.length
486698
+ });
486699
+ return {
486700
+ groupJid: jid,
486701
+ action,
486702
+ participants: result.map((participant) => ({
486703
+ jid: participant.jid,
486704
+ status: participant.status
486705
+ }))
486706
+ };
486707
+ } catch (error) {
486708
+ const waError = mapBaileysError(error);
486709
+ throw waError;
486710
+ }
486711
+ }
486712
+ async updateGroupSubject(instanceId, groupJid, subject) {
486713
+ await this.humanDelay(instanceId);
486714
+ const sock = this.getSocket(instanceId);
486715
+ const jid = toGroupJid(groupJid);
486716
+ try {
486717
+ await sock.groupUpdateSubject(jid, subject);
486718
+ this.invalidateGroupMetadataCache(instanceId, jid);
486719
+ this.logger.info("Group subject updated", { instanceId, groupJid: jid });
486720
+ } catch (error) {
486721
+ const waError = mapBaileysError(error);
486722
+ throw waError;
486723
+ }
486724
+ }
486725
+ async updateGroupDescription(instanceId, groupJid, description) {
486726
+ await this.humanDelay(instanceId);
486727
+ const sock = this.getSocket(instanceId);
486728
+ const jid = toGroupJid(groupJid);
486729
+ try {
486730
+ await sock.groupUpdateDescription(jid, description);
486731
+ this.invalidateGroupMetadataCache(instanceId, jid);
486732
+ this.logger.info("Group description updated", { instanceId, groupJid: jid, cleared: !description });
486733
+ } catch (error) {
486734
+ const waError = mapBaileysError(error);
486735
+ throw waError;
486736
+ }
486737
+ }
486738
+ async updateGroupSettings(instanceId, groupJid, setting) {
486739
+ await this.humanDelay(instanceId);
486740
+ const sock = this.getSocket(instanceId);
486741
+ const jid = toGroupJid(groupJid);
486742
+ try {
486743
+ await sock.groupSettingUpdate(jid, setting);
486744
+ this.invalidateGroupMetadataCache(instanceId, jid);
486745
+ this.logger.info("Group settings updated", { instanceId, groupJid: jid, setting });
486746
+ } catch (error) {
486747
+ const waError = mapBaileysError(error);
486748
+ throw waError;
486749
+ }
486750
+ }
486751
+ async leaveGroup(instanceId, groupJid) {
486752
+ await this.humanDelay(instanceId);
486753
+ const sock = this.getSocket(instanceId);
486754
+ const jid = toGroupJid(groupJid);
486755
+ try {
486756
+ await sock.groupLeave(jid);
486757
+ this.invalidateGroupMetadataCache(instanceId, jid);
486758
+ this.logger.info("Left group", { instanceId, groupJid: jid });
486759
+ } catch (error) {
486760
+ const waError = mapBaileysError(error);
486761
+ throw waError;
486762
+ }
486763
+ }
486332
486764
  async handleQrCode(instanceId, qrCode, expiresAt) {
486333
486765
  await this.emitQrCode(instanceId, qrCode, expiresAt);
486334
486766
  const config2 = this.instances.get(instanceId)?.config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260603.6",
3
+ "version": "2.260609.2",
4
4
  "description": "LLM-optimized CLI for Omni",
5
5
  "type": "module",
6
6
  "bin": {