@geminixiang/mikan 1.0.0-beta.46 → 1.0.0-beta.48
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/CHANGELOG.md +32 -0
- package/dist/adapters/discord/bot.d.ts +3 -0
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +27 -5
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/github/bot.d.ts +6 -1
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +56 -21
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/shared.d.ts +12 -1
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +44 -1
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +3 -0
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +75 -28
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +3 -0
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +23 -7
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/agent/catalog.d.ts.map +1 -1
- package/dist/agent/catalog.js +5 -1
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +116 -46
- package/dist/agent/runner.js.map +1 -1
- package/dist/cli/boot.js +1 -1
- package/dist/cli/boot.js.map +1 -1
- package/dist/cli/sessions.d.ts.map +1 -1
- package/dist/cli/sessions.js +18 -13
- package/dist/cli/sessions.js.map +1 -1
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +17 -0
- package/dist/env-manifest.js.map +1 -1
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +2 -2
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session-store.d.ts +3 -45
- package/dist/harness/session-store.d.ts.map +1 -1
- package/dist/harness/session-store.js +296 -198
- package/dist/harness/session-store.js.map +1 -1
- package/dist/harness/types.d.ts +9 -5
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/main.js +74 -12
- package/dist/main.js.map +1 -1
- package/dist/mcp/catalog.d.ts.map +1 -1
- package/dist/mcp/catalog.js +21 -0
- package/dist/mcp/catalog.js.map +1 -1
- package/dist/mcp/loader.d.ts +3 -2
- package/dist/mcp/loader.d.ts.map +1 -1
- package/dist/mcp/loader.js +54 -20
- package/dist/mcp/loader.js.map +1 -1
- package/dist/mcp/open-connector.d.ts +14 -0
- package/dist/mcp/open-connector.d.ts.map +1 -0
- package/dist/mcp/open-connector.js +203 -0
- package/dist/mcp/open-connector.js.map +1 -0
- package/dist/mcp/types.d.ts +6 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/types.js.map +1 -1
- package/dist/packages/index.d.ts.map +1 -1
- package/dist/packages/index.js +20 -49
- package/dist/packages/index.js.map +1 -1
- package/dist/process-lifecycle.d.ts +19 -0
- package/dist/process-lifecycle.d.ts.map +1 -0
- package/dist/process-lifecycle.js +60 -0
- package/dist/process-lifecycle.js.map +1 -0
- package/dist/runtime/conversation-runtime.js +11 -4
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +3 -1
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js +22 -2
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +5 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sessions/migrate-pi-084.d.ts +8 -0
- package/dist/sessions/migrate-pi-084.d.ts.map +1 -0
- package/dist/sessions/migrate-pi-084.js +353 -0
- package/dist/sessions/migrate-pi-084.js.map +1 -0
- package/dist/sessions/migrate-v3.d.ts +0 -5
- package/dist/sessions/migrate-v3.d.ts.map +1 -1
- package/dist/sessions/migrate-v3.js +129 -51
- package/dist/sessions/migrate-v3.js.map +1 -1
- package/dist/sessions/types.d.ts +6 -1
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/types.d.ts +16 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/web/session-view/portal.js +0 -16
- package/dist/web/session-view/portal.js.map +1 -1
- package/package.json +3 -3
|
@@ -10,7 +10,7 @@ import { resolveConversationSettings } from "../../config.js";
|
|
|
10
10
|
import * as log from "../../log.js";
|
|
11
11
|
import { isRecord, readTextFileIfExists } from "../../utils/file-guards.js";
|
|
12
12
|
import { PRODUCT_NAME, formatForceStopped } from "../../platform-messages.js";
|
|
13
|
-
import { appendBotResponseLog, appendChannelLog, MessagingEventQueue, saveIncomingAttachments, withRetry, } from "../shared.js";
|
|
13
|
+
import { appendBotResponseLog, appendChannelLog, MessagingEventQueue, MessagingIntakeTracker, saveIncomingAttachments, withRetry, } from "../shared.js";
|
|
14
14
|
import { processMessageIntake } from "../intake.js";
|
|
15
15
|
import { recordPlatformChannelKind, } from "../../workspace-projection/index.js";
|
|
16
16
|
import { AssistantThreadRegistry, handleAgentContextChanged, handleAgentDmOpened, handleAssistantThreadStarted, titleAssistantThread, } from "./assistant.js";
|
|
@@ -139,7 +139,9 @@ export class SlackMessagingBot {
|
|
|
139
139
|
* instead of inheriting whatever ran before it.
|
|
140
140
|
*/
|
|
141
141
|
this.streamStarts = new StreamStartLimiter();
|
|
142
|
+
this.stopped = false;
|
|
142
143
|
this.queues = new Map();
|
|
144
|
+
this.intake = new MessagingIntakeTracker("Slack");
|
|
143
145
|
this.eventsWatcher = null;
|
|
144
146
|
this.handler = handler;
|
|
145
147
|
this.workspace = config.workspace;
|
|
@@ -159,11 +161,14 @@ export class SlackMessagingBot {
|
|
|
159
161
|
// Public API
|
|
160
162
|
// ==========================================================================
|
|
161
163
|
async start() {
|
|
164
|
+
this.stopped = false;
|
|
162
165
|
const auth = await this.webClient.auth.test();
|
|
163
166
|
this.botUserId = auth.user_id;
|
|
164
167
|
this.botId = typeof auth.bot_id === "string" ? auth.bot_id : null;
|
|
165
168
|
this.teamId = typeof auth.team_id === "string" ? auth.team_id : null;
|
|
166
169
|
await Promise.all([this.fetchUsers(), this.fetchChannels()]);
|
|
170
|
+
if (this.stopped)
|
|
171
|
+
return;
|
|
167
172
|
log.logInfo(`Loaded ${this.channels.size} channels, ${this.users.size} users`);
|
|
168
173
|
// Record startup time before opening the socket. Slack may replay older events;
|
|
169
174
|
// those should be logged but not processed. Backfill runs in the background up
|
|
@@ -176,6 +181,16 @@ export class SlackMessagingBot {
|
|
|
176
181
|
log.logWarning("Slack backfill failed", String(error));
|
|
177
182
|
});
|
|
178
183
|
}
|
|
184
|
+
async stop() {
|
|
185
|
+
this.stopped = true;
|
|
186
|
+
try {
|
|
187
|
+
await this.socketClient.disconnect();
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
await this.intake.close();
|
|
191
|
+
await Promise.all([...this.queues.values()].map((queue) => queue.close()));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
179
194
|
getUser(userId) {
|
|
180
195
|
return this.users.get(userId);
|
|
181
196
|
}
|
|
@@ -558,6 +573,7 @@ export class SlackMessagingBot {
|
|
|
558
573
|
getMessagingInfo() {
|
|
559
574
|
return {
|
|
560
575
|
name: "slack",
|
|
576
|
+
...(this.teamId ? { workspaceId: this.teamId } : {}),
|
|
561
577
|
trustModel: "membership",
|
|
562
578
|
formattingGuide: "## Slack Formatting\nWrite standard Markdown/GFM: **bold**, _italic_, ~~strike~~, `code`, fenced code blocks, [links](url), lists, and pipe tables (rendered as native Slack tables).\nDo NOT use Slack mrkdwn syntax like *single-asterisk bold* or <url|label> links.",
|
|
563
579
|
channels: this.getAllChannels().map((c) => ({ id: c.id, name: c.name })),
|
|
@@ -579,6 +595,8 @@ export class SlackMessagingBot {
|
|
|
579
595
|
* Returns true if enqueued, false if queue is full (max 5).
|
|
580
596
|
*/
|
|
581
597
|
enqueueEvent(event) {
|
|
598
|
+
if (this.stopped)
|
|
599
|
+
return false;
|
|
582
600
|
const conversationId = event.conversationId;
|
|
583
601
|
const queue = this.getQueue(conversationId);
|
|
584
602
|
if (queue.size() >= 5) {
|
|
@@ -586,7 +604,7 @@ export class SlackMessagingBot {
|
|
|
586
604
|
return false;
|
|
587
605
|
}
|
|
588
606
|
log.logInfo(`Enqueueing event for ${conversationId}: ${event.text.substring(0, 50)}`);
|
|
589
|
-
queue.enqueue(async () => {
|
|
607
|
+
return queue.enqueue(async () => {
|
|
590
608
|
let anchorTs;
|
|
591
609
|
if (!event.thread_ts) {
|
|
592
610
|
try {
|
|
@@ -621,7 +639,7 @@ export class SlackMessagingBot {
|
|
|
621
639
|
const runQueueKey = planSlackAdapterSession(eventForRun, {
|
|
622
640
|
initialMessageTs: eventPlan.initialMessageTs,
|
|
623
641
|
}).sessionKey;
|
|
624
|
-
|
|
642
|
+
const run = async () => {
|
|
625
643
|
const slackEvent = createConversationEvent({
|
|
626
644
|
platform: "slack",
|
|
627
645
|
address: eventForRun.address,
|
|
@@ -641,9 +659,13 @@ export class SlackMessagingBot {
|
|
|
641
659
|
replyMode: this.resolveReplyMode(eventForRun.address),
|
|
642
660
|
});
|
|
643
661
|
return this.handler.handleEvent(eventForRun, this, context);
|
|
644
|
-
}
|
|
662
|
+
};
|
|
663
|
+
const runQueue = this.getQueue(runQueueKey);
|
|
664
|
+
if (!runQueue.enqueue(run)) {
|
|
665
|
+
await runQueue.close();
|
|
666
|
+
await run();
|
|
667
|
+
}
|
|
645
668
|
});
|
|
646
|
-
return true;
|
|
647
669
|
}
|
|
648
670
|
// ==========================================================================
|
|
649
671
|
// Private - Event Handlers
|
|
@@ -652,6 +674,8 @@ export class SlackMessagingBot {
|
|
|
652
674
|
let queue = this.queues.get(channelId);
|
|
653
675
|
if (!queue) {
|
|
654
676
|
queue = new MessagingEventQueue("Slack");
|
|
677
|
+
if (this.stopped)
|
|
678
|
+
void queue.close();
|
|
655
679
|
this.queues.set(channelId, queue);
|
|
656
680
|
}
|
|
657
681
|
return queue;
|
|
@@ -711,7 +735,7 @@ export class SlackMessagingBot {
|
|
|
711
735
|
log.logWarning("Failed to log Slack message", String(err));
|
|
712
736
|
});
|
|
713
737
|
};
|
|
714
|
-
processMessageIntake({
|
|
738
|
+
return processMessageIntake({
|
|
715
739
|
eventBase: options.event,
|
|
716
740
|
office: this.workspace.office(options.event.address),
|
|
717
741
|
isAutoReplyCandidate: options.isAutoReplyCandidate,
|
|
@@ -992,21 +1016,39 @@ export class SlackMessagingBot {
|
|
|
992
1016
|
this.socketClient.on("unable_to_socket_mode_start", (err) => {
|
|
993
1017
|
log.logWarning("Slack socket unable_to_start", err ? String(err) : "");
|
|
994
1018
|
});
|
|
995
|
-
this.socketClient.on("app_mention", (payload) =>
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
this.socketClient.on("
|
|
1019
|
+
this.socketClient.on("app_mention", (payload) => {
|
|
1020
|
+
void this.intake.run(() => this.handleAppMention(payload));
|
|
1021
|
+
});
|
|
1022
|
+
this.socketClient.on("message", (payload) => {
|
|
1023
|
+
void this.intake.run(() => this.handleMessageEvent(payload));
|
|
1024
|
+
});
|
|
1025
|
+
this.socketClient.on("slash_commands", (payload) => {
|
|
1026
|
+
void this.intake.run(() => this.handleSlashCommand(payload));
|
|
1027
|
+
});
|
|
1028
|
+
this.socketClient.on("app_home_opened", (payload) => {
|
|
1029
|
+
void this.intake.run(() => this.handleAppHomeOpened(payload));
|
|
1030
|
+
});
|
|
999
1031
|
// The assistant surface's lifecycle. Both events were already subscribed
|
|
1000
1032
|
// in the app manifest and then dropped on the floor, which is why the pane
|
|
1001
1033
|
// opened empty and the sidebar filled with untitled conversations.
|
|
1002
|
-
this.socketClient.on("assistant_thread_started", (payload) =>
|
|
1003
|
-
|
|
1034
|
+
this.socketClient.on("assistant_thread_started", (payload) => {
|
|
1035
|
+
void this.intake.run(() => this.handleAssistantThreadStarted(payload));
|
|
1036
|
+
});
|
|
1037
|
+
this.socketClient.on("assistant_thread_context_changed", (payload) => {
|
|
1038
|
+
void this.intake.run(() => this.handleAgentContextChangedEvent(payload));
|
|
1039
|
+
});
|
|
1004
1040
|
// agent_view's spelling of the same signal.
|
|
1005
|
-
this.socketClient.on("app_context_changed", (payload) =>
|
|
1006
|
-
|
|
1007
|
-
|
|
1041
|
+
this.socketClient.on("app_context_changed", (payload) => {
|
|
1042
|
+
void this.intake.run(() => this.handleAgentContextChangedEvent(payload));
|
|
1043
|
+
});
|
|
1044
|
+
this.socketClient.on("block_actions", (payload) => {
|
|
1045
|
+
void this.intake.run(() => this.handleBlockAction(payload));
|
|
1046
|
+
});
|
|
1047
|
+
this.socketClient.on("interactive", (payload) => {
|
|
1048
|
+
void this.intake.run(() => this.handleBlockAction(payload));
|
|
1049
|
+
});
|
|
1008
1050
|
}
|
|
1009
|
-
handleAppMention({ event, ack }) {
|
|
1051
|
+
async handleAppMention({ event, ack, }) {
|
|
1010
1052
|
const e = event;
|
|
1011
1053
|
// Skip DMs (handled by message event)
|
|
1012
1054
|
if (e.channel.startsWith("D")) {
|
|
@@ -1040,7 +1082,7 @@ export class SlackMessagingBot {
|
|
|
1040
1082
|
ack();
|
|
1041
1083
|
return;
|
|
1042
1084
|
}
|
|
1043
|
-
this.processSlackMessageIntake({
|
|
1085
|
+
const intake = this.processSlackMessageIntake({
|
|
1044
1086
|
event: slackEvent,
|
|
1045
1087
|
attachmentsPromise,
|
|
1046
1088
|
queueKey: this.resolveQueueKey(e.channel, sessionKey),
|
|
@@ -1048,6 +1090,7 @@ export class SlackMessagingBot {
|
|
|
1048
1090
|
addressed: true,
|
|
1049
1091
|
});
|
|
1050
1092
|
ack();
|
|
1093
|
+
await intake;
|
|
1051
1094
|
}
|
|
1052
1095
|
admitHumanMessage(event, ack) {
|
|
1053
1096
|
const hasSlackContent = !!event.text ||
|
|
@@ -1083,7 +1126,7 @@ export class SlackMessagingBot {
|
|
|
1083
1126
|
ack();
|
|
1084
1127
|
return false;
|
|
1085
1128
|
}
|
|
1086
|
-
handleMessageEvent({ event, ack }) {
|
|
1129
|
+
async handleMessageEvent({ event, ack, }) {
|
|
1087
1130
|
const e = event;
|
|
1088
1131
|
if (!this.admitHumanMessage(e, ack))
|
|
1089
1132
|
return;
|
|
@@ -1144,7 +1187,7 @@ export class SlackMessagingBot {
|
|
|
1144
1187
|
// message ts as a thread session (`channel:ts`) instead of the persistent
|
|
1145
1188
|
// top-level channel session.
|
|
1146
1189
|
slackEvent.sessionKey = activeSessionKey;
|
|
1147
|
-
this.processSlackMessageIntake({
|
|
1190
|
+
const intake = this.processSlackMessageIntake({
|
|
1148
1191
|
event: slackEvent,
|
|
1149
1192
|
attachmentsPromise,
|
|
1150
1193
|
queueKey: this.resolveQueueKey(e.channel, activeSessionKey),
|
|
@@ -1152,6 +1195,7 @@ export class SlackMessagingBot {
|
|
|
1152
1195
|
addressed: isDM,
|
|
1153
1196
|
});
|
|
1154
1197
|
ack();
|
|
1198
|
+
await intake;
|
|
1155
1199
|
}
|
|
1156
1200
|
async handleSlashCommand({ body, ack, }) {
|
|
1157
1201
|
const payload = body;
|
|
@@ -1165,16 +1209,19 @@ export class SlackMessagingBot {
|
|
|
1165
1209
|
return;
|
|
1166
1210
|
if (!entry.slackRoute)
|
|
1167
1211
|
return;
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1212
|
+
try {
|
|
1213
|
+
await this.routeSlashCommand(entry.slackRoute, {
|
|
1214
|
+
command,
|
|
1215
|
+
text,
|
|
1216
|
+
channel_id,
|
|
1217
|
+
user_id,
|
|
1218
|
+
user_name,
|
|
1219
|
+
thread_ts,
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
catch (err) {
|
|
1176
1223
|
log.logWarning("Slack slash command error", err instanceof Error ? err.message : String(err));
|
|
1177
|
-
}
|
|
1224
|
+
}
|
|
1178
1225
|
}
|
|
1179
1226
|
handleAppHomeOpened({ event, ack }) {
|
|
1180
1227
|
const e = event;
|