@ycodium-ai/plugin-im 0.2.3018 → 0.2.3024

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.
Files changed (2) hide show
  1. package/dist/index.js +99 -24
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -127224,6 +127224,9 @@ var makeChatQueue = (core) => {
127224
127224
  return { enqueueForChat };
127225
127225
  };
127226
127226
 
127227
+ // src/chatSetup.ts
127228
+ import { threadOrNull } from "@ycodium-ai/plugin-api";
127229
+
127227
127230
  // src/projectList.ts
127228
127231
  var PROJECT_LIST_MAX = 20;
127229
127232
  var projectLine = (row, position) => `${String(position)}. ${row.title.replace(/\s+/g, " ").trim()}${row.current ? " \u2605" : ""}`;
@@ -127365,7 +127368,7 @@ var makeChatSetup = (core, deps) => {
127365
127368
  }
127366
127369
  const threadId = chatOf(core.state, chatKey).threadId;
127367
127370
  if (threadId !== null) {
127368
- const thread = await host.projections.getThread(threadId).catch(() => null);
127371
+ const thread = await threadOrNull(host.threads, threadId).catch(() => null);
127369
127372
  if (isSessionRunning(thread?.session?.status)) {
127370
127373
  await deliver(binding, t("repo.busy"));
127371
127374
  return;
@@ -127410,6 +127413,9 @@ var makeChatSetup = (core, deps) => {
127410
127413
  return { promptProject, handleRepo, handleGroup };
127411
127414
  };
127412
127415
 
127416
+ // src/commands.ts
127417
+ import { threadOrNull as threadOrNull2 } from "@ycodium-ai/plugin-api";
127418
+
127413
127419
  // src/chatCommand.ts
127414
127420
  var teamArgument = (text3, chinese) => {
127415
127421
  const match = text3.match(/^\/team(?:\s+([\s\S]*))?$/i);
@@ -127720,7 +127726,7 @@ var makeCommands = (core, deps) => {
127720
127726
  );
127721
127727
  return true;
127722
127728
  }
127723
- const thread = await host.projections.getThread(threadId);
127729
+ const thread = await threadOrNull2(host.threads, threadId);
127724
127730
  const running = isSessionRunning(thread?.session?.status);
127725
127731
  await deliver(
127726
127732
  binding,
@@ -127772,7 +127778,7 @@ var makeCommands = (core, deps) => {
127772
127778
  await deliver(binding, t("command.stopNoSession"));
127773
127779
  return true;
127774
127780
  }
127775
- const thread = await host.projections.getThread(threadId);
127781
+ const thread = await threadOrNull2(host.threads, threadId);
127776
127782
  const activeTurnId = thread?.session?.activeTurnId ?? null;
127777
127783
  if (activeTurnId === null) {
127778
127784
  await deliver(binding, t("command.stopNoTurn"));
@@ -139036,13 +139042,14 @@ var makeLiveTranslate = (initial) => {
139036
139042
  };
139037
139043
 
139038
139044
  // src/modelPlan.ts
139045
+ import { threadOrNull as threadOrNull3 } from "@ycodium-ai/plugin-api";
139039
139046
  var makeModelPlan = (core, deps) => {
139040
139047
  const { host, t, commit, deliver } = core;
139041
139048
  const { threadStillUsable } = deps;
139042
139049
  const currentModelOf = async (binding) => {
139043
139050
  const chat = chatOf(core.state, chatKeyOf(binding));
139044
139051
  if (chat.threadId !== null) {
139045
- const thread = await host.projections.getThread(chat.threadId).catch(() => null);
139052
+ const thread = await threadOrNull3(host.threads, chat.threadId).catch(() => null);
139046
139053
  if (thread !== null) {
139047
139054
  return {
139048
139055
  instanceId: thread.modelSelection.instanceId,
@@ -139111,6 +139118,9 @@ var makeModelPlan = (core, deps) => {
139111
139118
  return { currentModelOf, handleModel, handlePlan };
139112
139119
  };
139113
139120
 
139121
+ // src/notifications.ts
139122
+ import { threadOrNull as threadOrNull4 } from "@ycodium-ai/plugin-api";
139123
+
139114
139124
  // src/notificationTargets.ts
139115
139125
  var notificationChatKeys = (state, threadId, projectId) => {
139116
139126
  const owner = chatOfThread(state, threadId);
@@ -139118,6 +139128,62 @@ var notificationChatKeys = (state, threadId, projectId) => {
139118
139128
  return projectId === null ? [] : chatsOnProject(state, projectId);
139119
139129
  };
139120
139130
 
139131
+ // src/threadMessages.ts
139132
+ import {
139133
+ isThreadNotFound
139134
+ } from "@ycodium-ai/plugin-api";
139135
+ var PAGE_SIZE = 20;
139136
+ async function* newestFirst(threads, threadId) {
139137
+ let cursor = null;
139138
+ do {
139139
+ let page;
139140
+ try {
139141
+ page = await threads.messages.list({ threadId, limit: PAGE_SIZE, cursor });
139142
+ } catch (error) {
139143
+ if (isThreadNotFound(error)) return;
139144
+ throw error;
139145
+ }
139146
+ yield* page.items;
139147
+ cursor = page.nextCursor;
139148
+ } while (cursor !== null);
139149
+ }
139150
+ async function attachmentsOf(threads, threadId, message) {
139151
+ const collected = [...message.attachments ?? []];
139152
+ const total = message.attachmentsTotal ?? collected.length;
139153
+ while (collected.length < total) {
139154
+ let page;
139155
+ try {
139156
+ page = await threads.messages.list({
139157
+ threadId,
139158
+ messageId: message.id,
139159
+ attachmentOffset: collected.length,
139160
+ textLimit: 2
139161
+ });
139162
+ } catch (error) {
139163
+ if (isThreadNotFound(error)) break;
139164
+ throw error;
139165
+ }
139166
+ const more = page.items[0]?.attachments ?? [];
139167
+ if (more.length === 0) break;
139168
+ collected.push(...more);
139169
+ }
139170
+ return collected;
139171
+ }
139172
+ async function latestMessage(threads, threadId, accept) {
139173
+ for await (const message of newestFirst(threads, threadId)) {
139174
+ if (accept(message)) return message;
139175
+ }
139176
+ return void 0;
139177
+ }
139178
+ async function messagesAfterLastUser(threads, threadId) {
139179
+ const after = [];
139180
+ for await (const message of newestFirst(threads, threadId)) {
139181
+ if (message.role === "user") break;
139182
+ after.push(message);
139183
+ }
139184
+ return after.toReversed();
139185
+ }
139186
+
139121
139187
  // src/turnOutcome.ts
139122
139188
  var outcomeOfSession = (status) => {
139123
139189
  if (status === "error") return "failed";
@@ -139137,7 +139203,7 @@ var makeNotifications = (core, deps) => {
139137
139203
  const projectOfThread = async (threadId) => {
139138
139204
  const known = projectByThread.get(threadId);
139139
139205
  if (known !== void 0) return known;
139140
- const thread = await host.projections.getThread(threadId);
139206
+ const thread = await threadOrNull4(host.threads, threadId);
139141
139207
  if (thread === null) return null;
139142
139208
  if (projectByThread.size >= THREAD_PROJECT_CACHE_LIMIT) {
139143
139209
  const oldest = projectByThread.keys().next().value;
@@ -139175,9 +139241,14 @@ var makeNotifications = (core, deps) => {
139175
139241
  const targets = targetsForProject(threadId, await projectOfThread(threadId));
139176
139242
  const reporters = said ? targets : [];
139177
139243
  if (reporters.length > 0) {
139178
- const thread = await host.projections.getThread(threadId);
139179
- const final = thread?.messages.toReversed().find((message) => message.role === "assistant" && message.text.trim() !== "");
139244
+ const thread = await threadOrNull4(host.threads, threadId);
139245
+ const final = thread === null ? void 0 : await latestMessage(
139246
+ host.threads,
139247
+ threadId,
139248
+ (message) => message.role === "assistant" && message.text.trim() !== ""
139249
+ );
139180
139250
  if (thread !== null && final !== void 0) {
139251
+ const attachments = await attachmentsOf(host.threads, threadId, final);
139181
139252
  for (const binding of reporters) {
139182
139253
  const text3 = streamsTo(binding, threadId) ? "" : `${thread.title}
139183
139254
 
@@ -139186,7 +139257,7 @@ ${final.text}`;
139186
139257
  await deliver(
139187
139258
  owns ? await anchors.anchored(binding, threadId, final.turnId) : binding,
139188
139259
  text3,
139189
- final.attachments
139260
+ attachments
139190
139261
  );
139191
139262
  }
139192
139263
  }
@@ -139207,7 +139278,7 @@ ${final.text}`;
139207
139278
  const drawingTurn = turnCards.drawingTurn(threadId);
139208
139279
  const notice = textTargets.length > 0 || drawingTurn !== null ? failures.forFailure(
139209
139280
  threadId,
139210
- (await host.projections.getThread(threadId).catch(() => null))?.session?.lastError
139281
+ (await threadOrNull4(host.threads, threadId).catch(() => null))?.session?.lastError
139211
139282
  ) : null;
139212
139283
  if (notice !== null && drawingTurn !== null)
139213
139284
  failures.holdForCard(threadId, drawingTurn, notice);
@@ -139858,6 +139929,7 @@ var makeFailureNotices = (core) => {
139858
139929
  // src/replyCards.ts
139859
139930
  import {
139860
139931
  readTurnProgress,
139932
+ threadOrNull as threadOrNull5,
139861
139933
  TURN_PROGRESS_TRIGGER_KIND
139862
139934
  } from "@ycodium-ai/plugin-api";
139863
139935
 
@@ -140166,15 +140238,18 @@ var makeReplyCards = (core, failures, anchors) => {
140166
140238
  },
140167
140239
  readText: async (messageId) => (await host.projections.getThreadMessage(messageId))?.text ?? null,
140168
140240
  titleOf: async (threadId) => {
140169
- const thread = await host.projections.getThread(threadId).catch(() => null);
140170
- const asked = thread?.messages.findLast(
140241
+ const asked = await latestMessage(
140242
+ host.threads,
140243
+ threadId,
140171
140244
  (message) => message.role === "user" && message.text.trim() !== ""
140172
- );
140173
- return turnTitleOf(asked?.text ?? thread?.title ?? "");
140245
+ ).catch(() => void 0);
140246
+ if (asked !== void 0) return turnTitleOf(asked.text);
140247
+ const thread = await threadOrNull5(host.threads, threadId).catch(() => null);
140248
+ return turnTitleOf(thread?.title ?? "");
140174
140249
  },
140175
140250
  endOf: async (threadId, turnId) => {
140176
140251
  const stopped = stopRequested.delete(threadId);
140177
- const thread = await host.projections.getThread(threadId).catch(() => null);
140252
+ const thread = await threadOrNull5(host.threads, threadId).catch(() => null);
140178
140253
  const session = thread?.session;
140179
140254
  const outcome = outcomeOfSession(session?.status);
140180
140255
  const errorText2 = failures.forCard(
@@ -140217,14 +140292,13 @@ var makeReplyCards = (core, failures, anchors) => {
140217
140292
  const cards = binding === void 0 ? void 0 : adapterFor(binding.platform)?.turnCards;
140218
140293
  if (binding !== void 0 && cards !== void 0) {
140219
140294
  try {
140220
- const thread = await host.projections.getThread(record2.threadId).catch(() => null);
140295
+ const messages = await messagesAfterLastUser(host.threads, record2.threadId).catch(
140296
+ () => []
140297
+ );
140221
140298
  await cards.update(
140222
140299
  binding,
140223
140300
  cardId,
140224
- interruptedView({
140225
- title: record2.title,
140226
- body: trailingReply(thread?.messages ?? [])
140227
- })
140301
+ interruptedView({ title: record2.title, body: trailingReply(messages) })
140228
140302
  );
140229
140303
  } catch (error) {
140230
140304
  host.log.warn("chat could not mark a stale card as interrupted", {
@@ -140414,9 +140488,10 @@ var makeSendFileTool = (deps) => ({
140414
140488
  });
140415
140489
 
140416
140490
  // src/sessions.ts
140491
+ import { threadOrNull as threadOrNull6 } from "@ycodium-ai/plugin-api";
140417
140492
  var WEB_LIST_PAGE = 100;
140418
140493
  var shellOf = (thread) => ({
140419
- threadId: thread.threadId,
140494
+ threadId: thread.id,
140420
140495
  title: thread.title,
140421
140496
  updatedAt: thread.updatedAt,
140422
140497
  archivedAt: thread.archivedAt,
@@ -140474,7 +140549,7 @@ var makeSessions = (core) => {
140474
140549
  });
140475
140550
  };
140476
140551
  const rowForThread = async (binding, chatKey, threadId) => {
140477
- const thread = await host.projections.getThread(threadId);
140552
+ const thread = await threadOrNull6(host.threads, threadId, { archived: "include" });
140478
140553
  if (thread === null || thread.projectId !== binding.projectId) return null;
140479
140554
  return rowFromThread(shellOf(thread), chatKey, originOf(threadId, binding.projectId));
140480
140555
  };
@@ -141517,7 +141592,7 @@ ${line}`
141517
141592
  };
141518
141593
 
141519
141594
  // src/turns.ts
141520
- import { projectOrNull as projectOrNull2 } from "@ycodium-ai/plugin-api";
141595
+ import { projectOrNull as projectOrNull2, threadOrNull as threadOrNull7 } from "@ycodium-ai/plugin-api";
141521
141596
  var TITLE_MAX_CHARS = 72;
141522
141597
  var titleFrom = (text3) => text3.replace(/\s+/g, " ").slice(0, TITLE_MAX_CHARS) || "Chat thread";
141523
141598
  var makeTurns = (core, deps) => {
@@ -141526,7 +141601,7 @@ var makeTurns = (core, deps) => {
141526
141601
  const { pendingByChat, pendingFor, collectResources } = deps.attachments;
141527
141602
  const threadStillUsable = async (binding, threadId) => {
141528
141603
  try {
141529
- const thread = await host.projections.getThread(threadId);
141604
+ const thread = await threadOrNull7(host.threads, threadId, { archived: "include" });
141530
141605
  return thread !== null && thread.archivedAt == null && thread.projectId === binding.projectId;
141531
141606
  } catch {
141532
141607
  return true;
@@ -143927,7 +144002,7 @@ var makeWecomAppAdapter = (deps) => {
143927
144002
  // src/index.ts
143928
144003
  var imPlugin = definePlugin({
143929
144004
  id: "im",
143930
- apiVersion: 8,
144005
+ apiVersion: 9,
143931
144006
  activate: async (ctx) => {
143932
144007
  const { t, setLanguage } = makeLiveTranslate(
143933
144008
  parseReplyLanguage(ctx.config[REPLY_LANGUAGE_FIELD])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/plugin-im",
3
- "version": "0.2.3018",
3
+ "version": "0.2.3024",
4
4
  "description": "Talk to your agents from Telegram, WeCom, Lark, or WeChat (experimental).",
5
5
  "keywords": [
6
6
  "im",
@@ -32,7 +32,7 @@
32
32
  "markdown-it": "^15.0.2",
33
33
  "react": "19.2.6",
34
34
  "vite-plus": "0.2.2",
35
- "@ycodium-ai/plugin-api": "0.2.3018"
35
+ "@ycodium-ai/plugin-api": "0.2.3024"
36
36
  },
37
37
  "ycodium": {
38
38
  "plugin": "./dist/index.js",