openmates 0.11.0-alpha.28 → 0.11.0-alpha.29

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.
@@ -1144,9 +1144,10 @@ var OpenMatesWsClient = class {
1144
1144
  });
1145
1145
  };
1146
1146
  const handleSubChatEvent = (type, p) => {
1147
- const eventChatId = typeof p.chat_id === "string" ? p.chat_id : typeof p.parent_id === "string" ? p.parent_id : null;
1147
+ const eventPayload = p.payload && typeof p.payload === "object" && !Array.isArray(p.payload) ? p.payload : p;
1148
+ const eventChatId = typeof eventPayload.chat_id === "string" ? eventPayload.chat_id : typeof eventPayload.parent_id === "string" ? eventPayload.parent_id : null;
1148
1149
  if (eventChatId && eventChatId !== chatId) return;
1149
- const event = { type, payload: p };
1150
+ const event = { type, payload: eventPayload };
1150
1151
  subChatEvents.push(event);
1151
1152
  if (type === "awaiting_sub_chats_completion") {
1152
1153
  awaitingSubChatsCompletion = true;
@@ -1748,11 +1749,12 @@ function toonEncodeContent(data) {
1748
1749
  function generateEmbedId() {
1749
1750
  return randomUUID();
1750
1751
  }
1751
- function createEmbedReferenceBlock(type, embedId, url) {
1752
- const data = { type, embed_id: embedId };
1753
- if (url) data.url = url;
1754
- const ref = JSON.stringify(data, null, 2);
1755
- return "```json\n" + ref + "\n```";
1752
+ function createEmbedRef(type, source) {
1753
+ const prefix = source.toLowerCase().replace(/^https?:\/\//, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || type;
1754
+ return `${prefix}-${computeSHA256(`${type}:${source}`).slice(0, 6)}`;
1755
+ }
1756
+ function createEmbedReferenceBlock(embedRef) {
1757
+ return `[!](embed:${embedRef})`;
1756
1758
  }
1757
1759
  async function encryptEmbed(embed, masterKey, chatKey, chatId, messageId, userId) {
1758
1760
  try {
@@ -1931,6 +1933,10 @@ function normalizeUnixSeconds(value, fallback) {
1931
1933
  }
1932
1934
  return value > 1e10 ? Math.floor(value / 1e3) : Math.floor(value);
1933
1935
  }
1936
+ function getClientMessagesVersionForSync(cached) {
1937
+ if (cached.messages.length === 0) return 0;
1938
+ return typeof cached.details.messages_v === "number" ? cached.details.messages_v : 0;
1939
+ }
1934
1940
  function buildSubChatConfirmationPayload(params) {
1935
1941
  return {
1936
1942
  chat_id: params.chatId,
@@ -4825,7 +4831,7 @@ Required: ${schema.required.join(", ")}`
4825
4831
  if (!id) continue;
4826
4832
  clientChatIds.push(id);
4827
4833
  clientChatVersions[id] = {
4828
- messages_v: typeof chat.details.messages_v === "number" ? chat.details.messages_v : 0,
4834
+ messages_v: getClientMessagesVersionForSync(chat),
4829
4835
  title_v: typeof chat.details.title_v === "number" ? chat.details.title_v : 0,
4830
4836
  draft_v: typeof chat.details.draft_v === "number" ? chat.details.draft_v : 0
4831
4837
  };
@@ -6114,19 +6120,22 @@ function processCodeFile(filePath, filename, redactor) {
6114
6120
  }
6115
6121
  const language = detectLanguage(filename);
6116
6122
  const lineCount = content.split("\n").length;
6123
+ const embedId = generateEmbedId();
6124
+ const embedRef = createEmbedRef("code", `${filename}:${embedId}`);
6117
6125
  const embedContent = toonEncodeContent({
6118
6126
  type: "code",
6119
6127
  language,
6120
6128
  code: content,
6121
6129
  filename,
6130
+ embed_ref: embedRef,
6122
6131
  status: "finished",
6123
6132
  line_count: lineCount
6124
6133
  });
6125
- const embedId = generateEmbedId();
6126
6134
  const textPreview = `${filename} (${language}, ${lineCount} lines)`;
6127
6135
  const contentHash = createHash4("sha256").update(content).digest("hex");
6128
6136
  const embed = {
6129
6137
  embedId,
6138
+ embedRef,
6130
6139
  type: "code-code",
6131
6140
  content: embedContent,
6132
6141
  textPreview,
@@ -6137,7 +6146,7 @@ function processCodeFile(filePath, filename, redactor) {
6137
6146
  };
6138
6147
  return {
6139
6148
  embed,
6140
- referenceBlock: createEmbedReferenceBlock("code", embedId),
6149
+ referenceBlock: createEmbedReferenceBlock(embedRef),
6141
6150
  displayName: filename,
6142
6151
  secretsRedacted,
6143
6152
  zeroKnowledge,
@@ -6154,15 +6163,18 @@ function processCodeFile(filePath, filename, redactor) {
6154
6163
  function processImageFile(filePath, filename) {
6155
6164
  try {
6156
6165
  const embedId = generateEmbedId();
6166
+ const embedRef = createEmbedRef("image", `${filename}:${embedId}`);
6157
6167
  const embedContent = toonEncodeContent({
6158
6168
  type: "image",
6159
6169
  app_id: "images",
6160
6170
  skill_id: "upload",
6161
6171
  status: "uploading",
6162
- filename
6172
+ filename,
6173
+ embed_ref: embedRef
6163
6174
  });
6164
6175
  const embed = {
6165
6176
  embedId,
6177
+ embedRef,
6166
6178
  type: "image",
6167
6179
  content: embedContent,
6168
6180
  textPreview: filename,
@@ -6171,7 +6183,7 @@ function processImageFile(filePath, filename) {
6171
6183
  };
6172
6184
  return {
6173
6185
  embed,
6174
- referenceBlock: createEmbedReferenceBlock("image", embedId),
6186
+ referenceBlock: createEmbedReferenceBlock(embedRef),
6175
6187
  displayName: filename,
6176
6188
  secretsRedacted: false,
6177
6189
  zeroKnowledge: false,
@@ -6189,13 +6201,16 @@ function processImageFile(filePath, filename) {
6189
6201
  function processPDFFile(filePath, filename) {
6190
6202
  try {
6191
6203
  const embedId = generateEmbedId();
6204
+ const embedRef = createEmbedRef("pdf", `${filename}:${embedId}`);
6192
6205
  const embedContent = toonEncodeContent({
6193
6206
  type: "pdf",
6194
6207
  status: "uploading",
6195
- filename
6208
+ filename,
6209
+ embed_ref: embedRef
6196
6210
  });
6197
6211
  const embed = {
6198
6212
  embedId,
6213
+ embedRef,
6199
6214
  type: "pdf",
6200
6215
  content: embedContent,
6201
6216
  textPreview: filename,
@@ -6204,7 +6219,7 @@ function processPDFFile(filePath, filename) {
6204
6219
  };
6205
6220
  return {
6206
6221
  embed,
6207
- referenceBlock: createEmbedReferenceBlock("pdf", embedId),
6222
+ referenceBlock: createEmbedReferenceBlock(embedRef),
6208
6223
  displayName: filename,
6209
6224
  secretsRedacted: false,
6210
6225
  zeroKnowledge: false,
@@ -6222,15 +6237,18 @@ function processPDFFile(filePath, filename) {
6222
6237
  function processAudioFile(filePath, filename) {
6223
6238
  try {
6224
6239
  const embedId = generateEmbedId();
6240
+ const embedRef = createEmbedRef("audio-recording", `${filename}:${embedId}`);
6225
6241
  const embedContent = toonEncodeContent({
6226
6242
  app_id: "audio",
6227
6243
  skill_id: "transcribe",
6228
6244
  type: "audio-recording",
6229
6245
  status: "uploading",
6230
- filename
6246
+ filename,
6247
+ embed_ref: embedRef
6231
6248
  });
6232
6249
  const embed = {
6233
6250
  embedId,
6251
+ embedRef,
6234
6252
  type: "audio-recording",
6235
6253
  content: embedContent,
6236
6254
  textPreview: filename,
@@ -6238,7 +6256,7 @@ function processAudioFile(filePath, filename) {
6238
6256
  };
6239
6257
  return {
6240
6258
  embed,
6241
- referenceBlock: createEmbedReferenceBlock("audio-recording", embedId),
6259
+ referenceBlock: createEmbedReferenceBlock(embedRef),
6242
6260
  displayName: filename,
6243
6261
  secretsRedacted: false,
6244
6262
  zeroKnowledge: false,
@@ -6281,8 +6299,10 @@ function trimTrailingUrlPunctuation(rawUrl) {
6281
6299
  }
6282
6300
  function createWebsiteEmbed(url) {
6283
6301
  const embedId = generateEmbedId();
6302
+ const embedRef = createEmbedRef("website", `${url}:${embedId}`);
6284
6303
  const content = toonEncodeContent({
6285
6304
  url,
6305
+ embed_ref: embedRef,
6286
6306
  title: null,
6287
6307
  description: null,
6288
6308
  favicon: null,
@@ -6292,6 +6312,7 @@ function createWebsiteEmbed(url) {
6292
6312
  });
6293
6313
  return {
6294
6314
  embedId,
6315
+ embedRef,
6295
6316
  type: "web-website",
6296
6317
  content,
6297
6318
  textPreview: url,
@@ -6309,7 +6330,7 @@ function replaceUrlsInText(text, embeds) {
6309
6330
  }
6310
6331
  const embed = createWebsiteEmbed(url);
6311
6332
  embeds.push(embed);
6312
- return `${createEmbedReferenceBlock("website", embed.embedId, url)}${suffix}`;
6333
+ return `${createEmbedReferenceBlock(embed.embedRef ?? embed.embedId)}${suffix}`;
6313
6334
  });
6314
6335
  }
6315
6336
  function prepareUrlEmbeds(message) {
@@ -11286,12 +11307,15 @@ async function sendMessageStreaming(client, params, redactor) {
11286
11307
  session,
11287
11308
  { chatId: params.chatId, requestId: uploadResult.embed_id }
11288
11309
  ) : null;
11310
+ const embedRef = fe.embed.embedRef ?? createEmbedRef(embedType, uploadResult.embed_id);
11311
+ fe.embed.embedRef = embedRef;
11289
11312
  const uploadedContent = embedType === "audio-recording" ? {
11290
11313
  app_id: "audio",
11291
11314
  skill_id: "transcribe",
11292
11315
  type: "audio-recording",
11293
11316
  status: "finished",
11294
11317
  filename: fe.displayName,
11318
+ embed_ref: embedRef,
11295
11319
  mime_type: uploadResult.content_type,
11296
11320
  transcript: audioTranscription?.transcript ?? null,
11297
11321
  transcript_original: audioTranscription?.transcript_original ?? null,
@@ -11308,6 +11332,7 @@ async function sendMessageStreaming(client, params, redactor) {
11308
11332
  type: "pdf",
11309
11333
  status: "processing",
11310
11334
  filename: fe.displayName,
11335
+ embed_ref: embedRef,
11311
11336
  page_count: uploadResult.page_count ?? null,
11312
11337
  content_hash: uploadResult.content_hash,
11313
11338
  s3_base_url: uploadResult.s3_base_url,
@@ -11321,6 +11346,7 @@ async function sendMessageStreaming(client, params, redactor) {
11321
11346
  skill_id: "upload",
11322
11347
  status: "finished",
11323
11348
  filename: fe.displayName,
11349
+ embed_ref: embedRef,
11324
11350
  content_hash: uploadResult.content_hash,
11325
11351
  s3_base_url: uploadResult.s3_base_url,
11326
11352
  files: uploadResult.files,
@@ -11333,10 +11359,7 @@ async function sendMessageStreaming(client, params, redactor) {
11333
11359
  fe.embed.status = embedType === "pdf" ? "processing" : "finished";
11334
11360
  fe.embed.contentHash = uploadResult.content_hash;
11335
11361
  fe.embed.embedId = uploadResult.embed_id;
11336
- fe.referenceBlock = createEmbedReferenceBlock(
11337
- embedType,
11338
- uploadResult.embed_id
11339
- );
11362
+ fe.referenceBlock = createEmbedReferenceBlock(embedRef);
11340
11363
  if (!params.json) {
11341
11364
  process.stderr.write(
11342
11365
  `\x1B[32m \u2713\x1B[0m \x1B[2m${fe.displayName} uploaded\x1B[0m
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  getExtForLang,
4
4
  serializeToYaml
5
- } from "./chunk-HR7MPMQP.js";
5
+ } from "./chunk-BCUTLV5E.js";
6
6
  import "./chunk-AXNRPVLE.js";
7
7
  export {
8
8
  getExtForLang,
package/dist/index.d.ts CHANGED
@@ -152,6 +152,7 @@ interface MentionContext {
152
152
  /** A prepared embed ready for encryption and sending */
153
153
  interface PreparedEmbed {
154
154
  embedId: string;
155
+ embedRef?: string;
155
156
  type: string;
156
157
  content: string;
157
158
  textPreview: string;
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  getExtForLang,
8
8
  parseNewChatSuggestionText,
9
9
  serializeToYaml
10
- } from "./chunk-HR7MPMQP.js";
10
+ } from "./chunk-BCUTLV5E.js";
11
11
  import "./chunk-AXNRPVLE.js";
12
12
  export {
13
13
  MATE_NAMES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmates",
3
- "version": "0.11.0-alpha.28",
3
+ "version": "0.11.0-alpha.29",
4
4
  "description": "OpenMates CLI and SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",