@hasna/assistants 1.1.16 → 1.1.17
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 +586 -503
- package/dist/index.js.map +13 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25784,60 +25784,6 @@ var init_executor3 = __esm(async () => {
|
|
|
25784
25784
|
MAX_SHELL_OUTPUT_LENGTH = 64 * 1024;
|
|
25785
25785
|
});
|
|
25786
25786
|
|
|
25787
|
-
// packages/core/src/channels/mentions.ts
|
|
25788
|
-
function parseMentions(content) {
|
|
25789
|
-
const mentions = [];
|
|
25790
|
-
const quotedRegex = /@"([^"]+)"/g;
|
|
25791
|
-
let match;
|
|
25792
|
-
while ((match = quotedRegex.exec(content)) !== null) {
|
|
25793
|
-
const name = match[1].trim();
|
|
25794
|
-
if (name && !mentions.includes(name)) {
|
|
25795
|
-
mentions.push(name);
|
|
25796
|
-
}
|
|
25797
|
-
}
|
|
25798
|
-
const simpleRegex = /@([a-zA-Z0-9_-]+)/g;
|
|
25799
|
-
while ((match = simpleRegex.exec(content)) !== null) {
|
|
25800
|
-
const name = match[1];
|
|
25801
|
-
if (!mentions.includes(name)) {
|
|
25802
|
-
mentions.push(name);
|
|
25803
|
-
}
|
|
25804
|
-
}
|
|
25805
|
-
return mentions;
|
|
25806
|
-
}
|
|
25807
|
-
function resolveNameToKnown(mentionName, knownNames) {
|
|
25808
|
-
const lower = mentionName.toLowerCase();
|
|
25809
|
-
const exact = knownNames.find((k) => k.name.toLowerCase() === lower);
|
|
25810
|
-
if (exact)
|
|
25811
|
-
return exact;
|
|
25812
|
-
const prefix = knownNames.find((k) => k.name.toLowerCase().startsWith(lower));
|
|
25813
|
-
if (prefix)
|
|
25814
|
-
return prefix;
|
|
25815
|
-
const word = knownNames.find((k) => k.name.toLowerCase().split(/\s+/).some((w) => w === lower));
|
|
25816
|
-
if (word)
|
|
25817
|
-
return word;
|
|
25818
|
-
return null;
|
|
25819
|
-
}
|
|
25820
|
-
function resolveMentions(names, members) {
|
|
25821
|
-
const resolved = [];
|
|
25822
|
-
for (const name of names) {
|
|
25823
|
-
const lower = name.toLowerCase();
|
|
25824
|
-
const member = members.find((m) => m.assistantName.toLowerCase() === lower);
|
|
25825
|
-
if (member) {
|
|
25826
|
-
resolved.push({
|
|
25827
|
-
name,
|
|
25828
|
-
memberId: member.assistantId,
|
|
25829
|
-
memberType: member.memberType
|
|
25830
|
-
});
|
|
25831
|
-
}
|
|
25832
|
-
}
|
|
25833
|
-
return resolved;
|
|
25834
|
-
}
|
|
25835
|
-
function getMentionedMemberIds(content, members) {
|
|
25836
|
-
const names = parseMentions(content);
|
|
25837
|
-
const resolved = resolveMentions(names, members);
|
|
25838
|
-
return resolved.map((r) => r.memberId);
|
|
25839
|
-
}
|
|
25840
|
-
|
|
25841
25787
|
// packages/core/src/scheduler/format.ts
|
|
25842
25788
|
function formatRelativeTime(timestamp, now2 = Date.now()) {
|
|
25843
25789
|
if (!timestamp)
|
|
@@ -74513,24 +74459,15 @@ Configure the external source with the URL and secret above.
|
|
|
74513
74459
|
`);
|
|
74514
74460
|
context.emit("done");
|
|
74515
74461
|
if (activePerson && result.success) {
|
|
74516
|
-
const
|
|
74517
|
-
|
|
74518
|
-
if (
|
|
74519
|
-
const
|
|
74520
|
-
|
|
74521
|
-
const assistants = assistantManager.listAssistants?.() || [];
|
|
74522
|
-
const knownNames = assistants.map((a) => ({ id: a.id, name: a.name }));
|
|
74523
|
-
const resolved = mentions.map((m) => resolveNameToKnown(m, knownNames)).filter(Boolean);
|
|
74524
|
-
if (resolved.length > 0) {
|
|
74525
|
-
mentionContext = `
|
|
74526
|
-
|
|
74527
|
-
Note: ${activePerson.name} mentioned ${resolved.map((r) => r.name).join(", ")}. Respond as the mentioned assistant.`;
|
|
74528
|
-
}
|
|
74529
|
-
}
|
|
74462
|
+
const agentPool = context.getChannelAgentPool?.();
|
|
74463
|
+
const members = manager.getMembers(channel);
|
|
74464
|
+
if (agentPool && members.length > 0) {
|
|
74465
|
+
const currentAssistantId = context.getAssistantManager?.()?.getActive?.()?.id;
|
|
74466
|
+
agentPool.triggerResponses(channel, activePerson.name, message, members, currentAssistantId || undefined);
|
|
74530
74467
|
}
|
|
74531
74468
|
return {
|
|
74532
74469
|
handled: false,
|
|
74533
|
-
prompt: `[Channel Message] ${activePerson.name} posted in #${channel}: "${message}"
|
|
74470
|
+
prompt: `[Channel Message] ${activePerson.name} posted in #${channel}: "${message}"
|
|
74534
74471
|
|
|
74535
74472
|
Respond in #${channel} using channel_send. Be helpful and conversational.`
|
|
74536
74473
|
};
|
|
@@ -79387,7 +79324,7 @@ ${repoUrl}/issues/new
|
|
|
79387
79324
|
context.setProjectContext(projectContext);
|
|
79388
79325
|
}
|
|
79389
79326
|
}
|
|
79390
|
-
var VERSION = "1.1.
|
|
79327
|
+
var VERSION = "1.1.17";
|
|
79391
79328
|
var init_builtin = __esm(async () => {
|
|
79392
79329
|
init_src2();
|
|
79393
79330
|
init_store();
|
|
@@ -172760,7 +172697,7 @@ class ChannelStore {
|
|
|
172760
172697
|
params.push(options.status);
|
|
172761
172698
|
}
|
|
172762
172699
|
}
|
|
172763
|
-
query += " ORDER BY last_message_at
|
|
172700
|
+
query += " ORDER BY (last_message_at IS NULL) ASC, last_message_at DESC, c.created_at DESC";
|
|
172764
172701
|
const stmt = this.db.prepare(query);
|
|
172765
172702
|
const rows = stmt.all(...params);
|
|
172766
172703
|
return rows.map((row) => ({
|
|
@@ -173166,6 +173103,550 @@ var init_manager6 = __esm(async () => {
|
|
|
173166
173103
|
await init_store7();
|
|
173167
173104
|
});
|
|
173168
173105
|
|
|
173106
|
+
// packages/core/src/client.ts
|
|
173107
|
+
class EmbeddedClient {
|
|
173108
|
+
assistantLoop;
|
|
173109
|
+
chunkCallbacks = [];
|
|
173110
|
+
errorCallbacks = [];
|
|
173111
|
+
initialized = false;
|
|
173112
|
+
logger;
|
|
173113
|
+
session;
|
|
173114
|
+
messages = [];
|
|
173115
|
+
messageIds = new Set;
|
|
173116
|
+
cwd;
|
|
173117
|
+
startedAt;
|
|
173118
|
+
initialMessages = null;
|
|
173119
|
+
assistantId = null;
|
|
173120
|
+
messageQueue = [];
|
|
173121
|
+
processingQueue = false;
|
|
173122
|
+
sawErrorChunk = false;
|
|
173123
|
+
constructor(cwd, options) {
|
|
173124
|
+
initAssistantsDir();
|
|
173125
|
+
const sessionId = options?.sessionId || generateId();
|
|
173126
|
+
this.logger = new Logger(sessionId);
|
|
173127
|
+
this.session = new SessionStorage(sessionId);
|
|
173128
|
+
this.cwd = cwd || process.cwd();
|
|
173129
|
+
this.startedAt = options?.startedAt || new Date().toISOString();
|
|
173130
|
+
this.initialMessages = options?.initialMessages || null;
|
|
173131
|
+
this.logger.info("Session started", { cwd: this.cwd });
|
|
173132
|
+
const createAssistant = options?.assistantFactory ?? ((opts) => new AssistantLoop(opts));
|
|
173133
|
+
this.assistantLoop = createAssistant({
|
|
173134
|
+
cwd: this.cwd,
|
|
173135
|
+
sessionId,
|
|
173136
|
+
assistantId: options?.assistantId,
|
|
173137
|
+
allowedTools: options?.allowedTools,
|
|
173138
|
+
extraSystemPrompt: options?.systemPrompt,
|
|
173139
|
+
model: options?.model,
|
|
173140
|
+
onChunk: (chunk) => {
|
|
173141
|
+
for (const callback of this.chunkCallbacks) {
|
|
173142
|
+
callback(chunk);
|
|
173143
|
+
}
|
|
173144
|
+
if (chunk.type === "error") {
|
|
173145
|
+
this.sawErrorChunk = true;
|
|
173146
|
+
}
|
|
173147
|
+
if (chunk.type === "done" || chunk.type === "error" || chunk.type === "stopped") {
|
|
173148
|
+
queueMicrotask(() => {
|
|
173149
|
+
this.drainQueue();
|
|
173150
|
+
});
|
|
173151
|
+
}
|
|
173152
|
+
},
|
|
173153
|
+
onToolStart: (toolCall) => {
|
|
173154
|
+
this.logger.info("Tool started", { tool: toolCall.name, input: toolCall.input });
|
|
173155
|
+
},
|
|
173156
|
+
onToolEnd: (toolCall, result) => {
|
|
173157
|
+
this.logger.info("Tool completed", {
|
|
173158
|
+
tool: toolCall.name,
|
|
173159
|
+
success: !result.isError,
|
|
173160
|
+
resultLength: result.content.length
|
|
173161
|
+
});
|
|
173162
|
+
}
|
|
173163
|
+
});
|
|
173164
|
+
}
|
|
173165
|
+
async initialize() {
|
|
173166
|
+
if (this.initialized)
|
|
173167
|
+
return;
|
|
173168
|
+
this.logger.info("Initializing assistant");
|
|
173169
|
+
await this.assistantLoop.initialize();
|
|
173170
|
+
if (typeof this.assistantLoop.getAssistantId === "function") {
|
|
173171
|
+
this.assistantId = this.assistantLoop.getAssistantId();
|
|
173172
|
+
if (this.assistantId) {
|
|
173173
|
+
this.session = new SessionStorage(this.session.getSessionId(), undefined, this.assistantId);
|
|
173174
|
+
}
|
|
173175
|
+
}
|
|
173176
|
+
if (this.initialMessages && this.initialMessages.length > 0) {
|
|
173177
|
+
const contextSeed = this.selectContextSeed(this.initialMessages);
|
|
173178
|
+
if (typeof this.assistantLoop.importContext === "function") {
|
|
173179
|
+
this.assistantLoop.importContext(contextSeed);
|
|
173180
|
+
} else {
|
|
173181
|
+
this.assistantLoop.getContext().import(contextSeed);
|
|
173182
|
+
}
|
|
173183
|
+
this.messages = [...this.initialMessages];
|
|
173184
|
+
this.messageIds = new Set(this.initialMessages.map((msg) => msg.id));
|
|
173185
|
+
}
|
|
173186
|
+
this.initialized = true;
|
|
173187
|
+
this.logger.info("Assistant initialized", {
|
|
173188
|
+
tools: this.assistantLoop.getTools().length,
|
|
173189
|
+
skills: this.assistantLoop.getSkills().length
|
|
173190
|
+
});
|
|
173191
|
+
}
|
|
173192
|
+
async send(message) {
|
|
173193
|
+
if (!this.initialized) {
|
|
173194
|
+
await this.initialize();
|
|
173195
|
+
}
|
|
173196
|
+
if (!message.trim()) {
|
|
173197
|
+
return;
|
|
173198
|
+
}
|
|
173199
|
+
this.messageQueue.push(message);
|
|
173200
|
+
if (this.assistantLoop.isProcessing() || this.processingQueue) {
|
|
173201
|
+
this.logger.info("Queuing message (assistant busy)", { message, queueLength: this.messageQueue.length });
|
|
173202
|
+
return;
|
|
173203
|
+
}
|
|
173204
|
+
await this.drainQueue();
|
|
173205
|
+
}
|
|
173206
|
+
async processMessage(message) {
|
|
173207
|
+
this.logger.info("User message", { message });
|
|
173208
|
+
this.sawErrorChunk = false;
|
|
173209
|
+
try {
|
|
173210
|
+
await this.assistantLoop.process(message);
|
|
173211
|
+
const context = this.assistantLoop.getContext();
|
|
173212
|
+
const contextMessages = context.getMessages();
|
|
173213
|
+
if (contextMessages.length > 0) {
|
|
173214
|
+
this.mergeMessages(contextMessages);
|
|
173215
|
+
const lastMessage = contextMessages.slice(-1)[0];
|
|
173216
|
+
if (lastMessage?.role === "assistant") {
|
|
173217
|
+
this.logger.info("Assistant response", {
|
|
173218
|
+
length: lastMessage.content.length,
|
|
173219
|
+
hasToolCalls: !!lastMessage.toolCalls?.length
|
|
173220
|
+
});
|
|
173221
|
+
}
|
|
173222
|
+
}
|
|
173223
|
+
this.saveSession();
|
|
173224
|
+
} catch (error3) {
|
|
173225
|
+
if (this.sawErrorChunk) {
|
|
173226
|
+
return;
|
|
173227
|
+
}
|
|
173228
|
+
const err = error3 instanceof Error ? error3 : new Error(String(error3));
|
|
173229
|
+
this.logger.error("Error processing message", { error: err.message });
|
|
173230
|
+
for (const callback of this.errorCallbacks) {
|
|
173231
|
+
callback(err);
|
|
173232
|
+
}
|
|
173233
|
+
}
|
|
173234
|
+
}
|
|
173235
|
+
async drainQueue() {
|
|
173236
|
+
if (this.processingQueue)
|
|
173237
|
+
return;
|
|
173238
|
+
this.processingQueue = true;
|
|
173239
|
+
try {
|
|
173240
|
+
while (this.messageQueue.length > 0 && !this.assistantLoop.isProcessing()) {
|
|
173241
|
+
const nextMessage = this.messageQueue.shift();
|
|
173242
|
+
if (nextMessage) {
|
|
173243
|
+
await this.processMessage(nextMessage);
|
|
173244
|
+
}
|
|
173245
|
+
}
|
|
173246
|
+
} finally {
|
|
173247
|
+
this.processingQueue = false;
|
|
173248
|
+
}
|
|
173249
|
+
}
|
|
173250
|
+
saveSession() {
|
|
173251
|
+
this.session.save({
|
|
173252
|
+
messages: this.messages,
|
|
173253
|
+
startedAt: this.startedAt,
|
|
173254
|
+
updatedAt: new Date().toISOString(),
|
|
173255
|
+
cwd: this.cwd
|
|
173256
|
+
});
|
|
173257
|
+
}
|
|
173258
|
+
onChunk(callback) {
|
|
173259
|
+
this.chunkCallbacks.push(callback);
|
|
173260
|
+
return () => {
|
|
173261
|
+
const index = this.chunkCallbacks.indexOf(callback);
|
|
173262
|
+
if (index !== -1)
|
|
173263
|
+
this.chunkCallbacks.splice(index, 1);
|
|
173264
|
+
};
|
|
173265
|
+
}
|
|
173266
|
+
onError(callback) {
|
|
173267
|
+
this.errorCallbacks.push(callback);
|
|
173268
|
+
return () => {
|
|
173269
|
+
const index = this.errorCallbacks.indexOf(callback);
|
|
173270
|
+
if (index !== -1)
|
|
173271
|
+
this.errorCallbacks.splice(index, 1);
|
|
173272
|
+
};
|
|
173273
|
+
}
|
|
173274
|
+
setAskUserHandler(handler) {
|
|
173275
|
+
if (typeof this.assistantLoop.setAskUserHandler === "function") {
|
|
173276
|
+
this.assistantLoop.setAskUserHandler(handler);
|
|
173277
|
+
}
|
|
173278
|
+
}
|
|
173279
|
+
async getTools() {
|
|
173280
|
+
if (!this.initialized) {
|
|
173281
|
+
await this.initialize();
|
|
173282
|
+
}
|
|
173283
|
+
return this.assistantLoop.getTools();
|
|
173284
|
+
}
|
|
173285
|
+
async getSkills() {
|
|
173286
|
+
if (!this.initialized) {
|
|
173287
|
+
await this.initialize();
|
|
173288
|
+
}
|
|
173289
|
+
return this.assistantLoop.getSkills();
|
|
173290
|
+
}
|
|
173291
|
+
async refreshSkills() {
|
|
173292
|
+
if (!this.initialized) {
|
|
173293
|
+
await this.initialize();
|
|
173294
|
+
}
|
|
173295
|
+
if (typeof this.assistantLoop.refreshSkills === "function") {
|
|
173296
|
+
await this.assistantLoop.refreshSkills();
|
|
173297
|
+
}
|
|
173298
|
+
return this.assistantLoop.getSkills();
|
|
173299
|
+
}
|
|
173300
|
+
getSkillLoader() {
|
|
173301
|
+
if (typeof this.assistantLoop.getSkillLoader === "function") {
|
|
173302
|
+
return this.assistantLoop.getSkillLoader();
|
|
173303
|
+
}
|
|
173304
|
+
return null;
|
|
173305
|
+
}
|
|
173306
|
+
stop() {
|
|
173307
|
+
this.logger.info("Processing stopped by user");
|
|
173308
|
+
this.assistantLoop.stop();
|
|
173309
|
+
}
|
|
173310
|
+
disconnect() {
|
|
173311
|
+
this.logger.info("Session ended");
|
|
173312
|
+
if (typeof this.assistantLoop.shutdown === "function") {
|
|
173313
|
+
this.assistantLoop.shutdown();
|
|
173314
|
+
}
|
|
173315
|
+
this.saveSession();
|
|
173316
|
+
this.chunkCallbacks.length = 0;
|
|
173317
|
+
this.errorCallbacks.length = 0;
|
|
173318
|
+
}
|
|
173319
|
+
isProcessing() {
|
|
173320
|
+
return this.assistantLoop.isProcessing();
|
|
173321
|
+
}
|
|
173322
|
+
getSessionId() {
|
|
173323
|
+
return this.session.getSessionId();
|
|
173324
|
+
}
|
|
173325
|
+
async getCommands() {
|
|
173326
|
+
if (!this.initialized) {
|
|
173327
|
+
await this.initialize();
|
|
173328
|
+
}
|
|
173329
|
+
return this.assistantLoop.getCommands();
|
|
173330
|
+
}
|
|
173331
|
+
getTokenUsage() {
|
|
173332
|
+
return this.assistantLoop.getTokenUsage();
|
|
173333
|
+
}
|
|
173334
|
+
getEnergyState() {
|
|
173335
|
+
if (typeof this.assistantLoop.getEnergyState === "function") {
|
|
173336
|
+
return this.assistantLoop.getEnergyState();
|
|
173337
|
+
}
|
|
173338
|
+
return null;
|
|
173339
|
+
}
|
|
173340
|
+
getVoiceState() {
|
|
173341
|
+
if (typeof this.assistantLoop.getVoiceState === "function") {
|
|
173342
|
+
return this.assistantLoop.getVoiceState();
|
|
173343
|
+
}
|
|
173344
|
+
return null;
|
|
173345
|
+
}
|
|
173346
|
+
getHeartbeatState() {
|
|
173347
|
+
if (typeof this.assistantLoop.getHeartbeatState === "function") {
|
|
173348
|
+
return this.assistantLoop.getHeartbeatState();
|
|
173349
|
+
}
|
|
173350
|
+
return null;
|
|
173351
|
+
}
|
|
173352
|
+
getIdentityInfo() {
|
|
173353
|
+
if (typeof this.assistantLoop.getIdentityInfo === "function") {
|
|
173354
|
+
return this.assistantLoop.getIdentityInfo();
|
|
173355
|
+
}
|
|
173356
|
+
return null;
|
|
173357
|
+
}
|
|
173358
|
+
getModel() {
|
|
173359
|
+
if (typeof this.assistantLoop.getModel === "function") {
|
|
173360
|
+
return this.assistantLoop.getModel();
|
|
173361
|
+
}
|
|
173362
|
+
return null;
|
|
173363
|
+
}
|
|
173364
|
+
getAssistantManager() {
|
|
173365
|
+
if (typeof this.assistantLoop.getAssistantManager === "function") {
|
|
173366
|
+
return this.assistantLoop.getAssistantManager();
|
|
173367
|
+
}
|
|
173368
|
+
return null;
|
|
173369
|
+
}
|
|
173370
|
+
getIdentityManager() {
|
|
173371
|
+
if (typeof this.assistantLoop.getIdentityManager === "function") {
|
|
173372
|
+
return this.assistantLoop.getIdentityManager();
|
|
173373
|
+
}
|
|
173374
|
+
return null;
|
|
173375
|
+
}
|
|
173376
|
+
getMemoryManager() {
|
|
173377
|
+
if (typeof this.assistantLoop.getMemoryManager === "function") {
|
|
173378
|
+
return this.assistantLoop.getMemoryManager();
|
|
173379
|
+
}
|
|
173380
|
+
return null;
|
|
173381
|
+
}
|
|
173382
|
+
async refreshIdentityContext() {
|
|
173383
|
+
if (typeof this.assistantLoop.refreshIdentityContext === "function") {
|
|
173384
|
+
await this.assistantLoop.refreshIdentityContext();
|
|
173385
|
+
}
|
|
173386
|
+
}
|
|
173387
|
+
getMessagesManager() {
|
|
173388
|
+
if (typeof this.assistantLoop.getMessagesManager === "function") {
|
|
173389
|
+
return this.assistantLoop.getMessagesManager();
|
|
173390
|
+
}
|
|
173391
|
+
return null;
|
|
173392
|
+
}
|
|
173393
|
+
getWebhooksManager() {
|
|
173394
|
+
if (typeof this.assistantLoop.getWebhooksManager === "function") {
|
|
173395
|
+
return this.assistantLoop.getWebhooksManager();
|
|
173396
|
+
}
|
|
173397
|
+
return null;
|
|
173398
|
+
}
|
|
173399
|
+
getChannelsManager() {
|
|
173400
|
+
if (typeof this.assistantLoop.getChannelsManager === "function") {
|
|
173401
|
+
return this.assistantLoop.getChannelsManager();
|
|
173402
|
+
}
|
|
173403
|
+
return null;
|
|
173404
|
+
}
|
|
173405
|
+
getChannelAgentPool() {
|
|
173406
|
+
if (typeof this.assistantLoop.getChannelAgentPool === "function") {
|
|
173407
|
+
return this.assistantLoop.getChannelAgentPool();
|
|
173408
|
+
}
|
|
173409
|
+
return null;
|
|
173410
|
+
}
|
|
173411
|
+
getPeopleManager() {
|
|
173412
|
+
if (typeof this.assistantLoop.getPeopleManager === "function") {
|
|
173413
|
+
return this.assistantLoop.getPeopleManager();
|
|
173414
|
+
}
|
|
173415
|
+
return null;
|
|
173416
|
+
}
|
|
173417
|
+
getTelephonyManager() {
|
|
173418
|
+
if (typeof this.assistantLoop.getTelephonyManager === "function") {
|
|
173419
|
+
return this.assistantLoop.getTelephonyManager();
|
|
173420
|
+
}
|
|
173421
|
+
return null;
|
|
173422
|
+
}
|
|
173423
|
+
getWalletManager() {
|
|
173424
|
+
if (typeof this.assistantLoop.getWalletManager === "function") {
|
|
173425
|
+
return this.assistantLoop.getWalletManager();
|
|
173426
|
+
}
|
|
173427
|
+
return null;
|
|
173428
|
+
}
|
|
173429
|
+
getSecretsManager() {
|
|
173430
|
+
if (typeof this.assistantLoop.getSecretsManager === "function") {
|
|
173431
|
+
return this.assistantLoop.getSecretsManager();
|
|
173432
|
+
}
|
|
173433
|
+
return null;
|
|
173434
|
+
}
|
|
173435
|
+
getInboxManager() {
|
|
173436
|
+
if (typeof this.assistantLoop.getInboxManager === "function") {
|
|
173437
|
+
return this.assistantLoop.getInboxManager();
|
|
173438
|
+
}
|
|
173439
|
+
return null;
|
|
173440
|
+
}
|
|
173441
|
+
getActiveProjectId() {
|
|
173442
|
+
if (typeof this.assistantLoop.getActiveProjectId === "function") {
|
|
173443
|
+
return this.assistantLoop.getActiveProjectId();
|
|
173444
|
+
}
|
|
173445
|
+
return null;
|
|
173446
|
+
}
|
|
173447
|
+
setActiveProjectId(projectId) {
|
|
173448
|
+
if (typeof this.assistantLoop.setActiveProjectId === "function") {
|
|
173449
|
+
this.assistantLoop.setActiveProjectId(projectId);
|
|
173450
|
+
}
|
|
173451
|
+
}
|
|
173452
|
+
getSwarmCoordinator() {
|
|
173453
|
+
if (typeof this.assistantLoop.getOrCreateSwarmCoordinator === "function") {
|
|
173454
|
+
return this.assistantLoop.getOrCreateSwarmCoordinator();
|
|
173455
|
+
}
|
|
173456
|
+
return null;
|
|
173457
|
+
}
|
|
173458
|
+
getAssistantLoop() {
|
|
173459
|
+
return this.assistantLoop;
|
|
173460
|
+
}
|
|
173461
|
+
addSystemMessage(content) {
|
|
173462
|
+
if (typeof this.assistantLoop.addSystemMessage === "function") {
|
|
173463
|
+
this.assistantLoop.addSystemMessage(content);
|
|
173464
|
+
} else {
|
|
173465
|
+
const context = this.assistantLoop.getContext();
|
|
173466
|
+
if (typeof context.addSystemMessage === "function") {
|
|
173467
|
+
context.addSystemMessage(content);
|
|
173468
|
+
}
|
|
173469
|
+
}
|
|
173470
|
+
}
|
|
173471
|
+
clearConversation() {
|
|
173472
|
+
this.assistantLoop.clearConversation();
|
|
173473
|
+
this.messages = [];
|
|
173474
|
+
this.messageIds.clear();
|
|
173475
|
+
this.logger.info("Conversation cleared");
|
|
173476
|
+
}
|
|
173477
|
+
getCwd() {
|
|
173478
|
+
return this.cwd;
|
|
173479
|
+
}
|
|
173480
|
+
getStartedAt() {
|
|
173481
|
+
return this.startedAt;
|
|
173482
|
+
}
|
|
173483
|
+
getMessages() {
|
|
173484
|
+
return [...this.messages];
|
|
173485
|
+
}
|
|
173486
|
+
getQueueLength() {
|
|
173487
|
+
return this.messageQueue.length;
|
|
173488
|
+
}
|
|
173489
|
+
clearQueue() {
|
|
173490
|
+
this.messageQueue = [];
|
|
173491
|
+
this.logger.info("Message queue cleared");
|
|
173492
|
+
}
|
|
173493
|
+
mergeMessages(contextMessages) {
|
|
173494
|
+
if (contextMessages.length === 0)
|
|
173495
|
+
return;
|
|
173496
|
+
if (this.messages.length === 0 && this.messageIds.size === 0) {
|
|
173497
|
+
this.messages = [...contextMessages];
|
|
173498
|
+
this.messageIds = new Set(contextMessages.map((msg) => msg.id));
|
|
173499
|
+
return;
|
|
173500
|
+
}
|
|
173501
|
+
for (const msg of contextMessages) {
|
|
173502
|
+
if (!this.messageIds.has(msg.id)) {
|
|
173503
|
+
this.messages.push(msg);
|
|
173504
|
+
this.messageIds.add(msg.id);
|
|
173505
|
+
}
|
|
173506
|
+
}
|
|
173507
|
+
}
|
|
173508
|
+
selectContextSeed(messages) {
|
|
173509
|
+
if (messages.length === 0)
|
|
173510
|
+
return [];
|
|
173511
|
+
const contextInfo = typeof this.assistantLoop.getContextInfo === "function" ? this.assistantLoop.getContextInfo() : null;
|
|
173512
|
+
const maxMessages = contextInfo?.config?.maxMessages ?? 100;
|
|
173513
|
+
if (messages.length <= maxMessages)
|
|
173514
|
+
return messages;
|
|
173515
|
+
let startIndex = messages.length - maxMessages;
|
|
173516
|
+
if (startIndex > 0 && messages[startIndex]?.toolResults && messages[startIndex - 1]) {
|
|
173517
|
+
startIndex -= 1;
|
|
173518
|
+
}
|
|
173519
|
+
return messages.slice(Math.max(0, startIndex));
|
|
173520
|
+
}
|
|
173521
|
+
}
|
|
173522
|
+
var init_client4 = __esm(async () => {
|
|
173523
|
+
init_src2();
|
|
173524
|
+
await __promiseAll([
|
|
173525
|
+
init_loop(),
|
|
173526
|
+
init_logger2()
|
|
173527
|
+
]);
|
|
173528
|
+
});
|
|
173529
|
+
|
|
173530
|
+
// packages/core/src/channels/mentions.ts
|
|
173531
|
+
function parseMentions(content) {
|
|
173532
|
+
const mentions = [];
|
|
173533
|
+
const quotedRegex = /@"([^"]+)"/g;
|
|
173534
|
+
let match;
|
|
173535
|
+
while ((match = quotedRegex.exec(content)) !== null) {
|
|
173536
|
+
const name2 = match[1].trim();
|
|
173537
|
+
if (name2 && !mentions.includes(name2)) {
|
|
173538
|
+
mentions.push(name2);
|
|
173539
|
+
}
|
|
173540
|
+
}
|
|
173541
|
+
const simpleRegex = /@([a-zA-Z0-9_-]+)/g;
|
|
173542
|
+
while ((match = simpleRegex.exec(content)) !== null) {
|
|
173543
|
+
const name2 = match[1];
|
|
173544
|
+
if (!mentions.includes(name2)) {
|
|
173545
|
+
mentions.push(name2);
|
|
173546
|
+
}
|
|
173547
|
+
}
|
|
173548
|
+
return mentions;
|
|
173549
|
+
}
|
|
173550
|
+
function resolveNameToKnown(mentionName, knownNames) {
|
|
173551
|
+
const lower = mentionName.toLowerCase();
|
|
173552
|
+
const exact = knownNames.find((k7) => k7.name.toLowerCase() === lower);
|
|
173553
|
+
if (exact)
|
|
173554
|
+
return exact;
|
|
173555
|
+
const prefix2 = knownNames.find((k7) => k7.name.toLowerCase().startsWith(lower));
|
|
173556
|
+
if (prefix2)
|
|
173557
|
+
return prefix2;
|
|
173558
|
+
const word = knownNames.find((k7) => k7.name.toLowerCase().split(/\s+/).some((w6) => w6 === lower));
|
|
173559
|
+
if (word)
|
|
173560
|
+
return word;
|
|
173561
|
+
return null;
|
|
173562
|
+
}
|
|
173563
|
+
function resolveMentions(names, members) {
|
|
173564
|
+
const resolved = [];
|
|
173565
|
+
for (const name2 of names) {
|
|
173566
|
+
const lower = name2.toLowerCase();
|
|
173567
|
+
const member = members.find((m5) => m5.assistantName.toLowerCase() === lower);
|
|
173568
|
+
if (member) {
|
|
173569
|
+
resolved.push({
|
|
173570
|
+
name: name2,
|
|
173571
|
+
memberId: member.assistantId,
|
|
173572
|
+
memberType: member.memberType
|
|
173573
|
+
});
|
|
173574
|
+
}
|
|
173575
|
+
}
|
|
173576
|
+
return resolved;
|
|
173577
|
+
}
|
|
173578
|
+
function getMentionedMemberIds(content, members) {
|
|
173579
|
+
const names = parseMentions(content);
|
|
173580
|
+
const resolved = resolveMentions(names, members);
|
|
173581
|
+
return resolved.map((r6) => r6.memberId);
|
|
173582
|
+
}
|
|
173583
|
+
|
|
173584
|
+
// packages/core/src/channels/agent-pool.ts
|
|
173585
|
+
class ChannelAgentPool {
|
|
173586
|
+
agents = new Map;
|
|
173587
|
+
cwd;
|
|
173588
|
+
constructor(cwd) {
|
|
173589
|
+
this.cwd = cwd;
|
|
173590
|
+
}
|
|
173591
|
+
async triggerResponses(channelName, personName, message, channelMembers, excludeAssistantId) {
|
|
173592
|
+
const assistantMembers = channelMembers.filter((m5) => m5.memberType === "assistant");
|
|
173593
|
+
if (assistantMembers.length === 0)
|
|
173594
|
+
return;
|
|
173595
|
+
let targetMembers = assistantMembers;
|
|
173596
|
+
const mentions = parseMentions(message);
|
|
173597
|
+
if (mentions.length > 0) {
|
|
173598
|
+
const knownNames = assistantMembers.map((m5) => ({
|
|
173599
|
+
id: m5.assistantId,
|
|
173600
|
+
name: m5.assistantName
|
|
173601
|
+
}));
|
|
173602
|
+
const resolved = mentions.map((m5) => resolveNameToKnown(m5, knownNames)).filter(Boolean);
|
|
173603
|
+
if (resolved.length > 0) {
|
|
173604
|
+
const resolvedIds = new Set(resolved.map((r6) => r6.id));
|
|
173605
|
+
targetMembers = assistantMembers.filter((m5) => resolvedIds.has(m5.assistantId));
|
|
173606
|
+
}
|
|
173607
|
+
}
|
|
173608
|
+
if (excludeAssistantId) {
|
|
173609
|
+
targetMembers = targetMembers.filter((m5) => m5.assistantId !== excludeAssistantId);
|
|
173610
|
+
}
|
|
173611
|
+
if (targetMembers.length === 0)
|
|
173612
|
+
return;
|
|
173613
|
+
const prompt = `[Channel Message] ${personName} posted in #${channelName}: "${message}"
|
|
173614
|
+
|
|
173615
|
+
Respond in #${channelName} using channel_send. Be helpful and conversational.`;
|
|
173616
|
+
const sends = targetMembers.map(async (member) => {
|
|
173617
|
+
try {
|
|
173618
|
+
const client = await this.getOrCreateClient(member.assistantId);
|
|
173619
|
+
await client.send(prompt);
|
|
173620
|
+
} catch (error3) {
|
|
173621
|
+
console.error(`ChannelAgentPool: Failed to trigger response for ${member.assistantName}:`, error3);
|
|
173622
|
+
}
|
|
173623
|
+
});
|
|
173624
|
+
await Promise.allSettled(sends);
|
|
173625
|
+
}
|
|
173626
|
+
async getOrCreateClient(assistantId) {
|
|
173627
|
+
const existing = this.agents.get(assistantId);
|
|
173628
|
+
if (existing)
|
|
173629
|
+
return existing;
|
|
173630
|
+
const client = new EmbeddedClient(this.cwd, {
|
|
173631
|
+
assistantId
|
|
173632
|
+
});
|
|
173633
|
+
await client.initialize();
|
|
173634
|
+
this.agents.set(assistantId, client);
|
|
173635
|
+
return client;
|
|
173636
|
+
}
|
|
173637
|
+
shutdown() {
|
|
173638
|
+
for (const [, client] of this.agents) {
|
|
173639
|
+
try {
|
|
173640
|
+
client.disconnect();
|
|
173641
|
+
} catch {}
|
|
173642
|
+
}
|
|
173643
|
+
this.agents.clear();
|
|
173644
|
+
}
|
|
173645
|
+
}
|
|
173646
|
+
var init_agent_pool = __esm(async () => {
|
|
173647
|
+
await init_client4();
|
|
173648
|
+
});
|
|
173649
|
+
|
|
173169
173650
|
// packages/core/src/channels/tools.ts
|
|
173170
173651
|
function createChannelToolExecutors(getChannelsManager) {
|
|
173171
173652
|
return {
|
|
@@ -173459,6 +173940,7 @@ var init_channels = __esm(async () => {
|
|
|
173459
173940
|
init_tools10();
|
|
173460
173941
|
await __promiseAll([
|
|
173461
173942
|
init_manager6(),
|
|
173943
|
+
init_agent_pool(),
|
|
173462
173944
|
init_store7()
|
|
173463
173945
|
]);
|
|
173464
173946
|
});
|
|
@@ -175529,424 +176011,6 @@ class SessionStore {
|
|
|
175529
176011
|
}
|
|
175530
176012
|
var init_store10 = () => {};
|
|
175531
176013
|
|
|
175532
|
-
// packages/core/src/client.ts
|
|
175533
|
-
class EmbeddedClient {
|
|
175534
|
-
assistantLoop;
|
|
175535
|
-
chunkCallbacks = [];
|
|
175536
|
-
errorCallbacks = [];
|
|
175537
|
-
initialized = false;
|
|
175538
|
-
logger;
|
|
175539
|
-
session;
|
|
175540
|
-
messages = [];
|
|
175541
|
-
messageIds = new Set;
|
|
175542
|
-
cwd;
|
|
175543
|
-
startedAt;
|
|
175544
|
-
initialMessages = null;
|
|
175545
|
-
assistantId = null;
|
|
175546
|
-
messageQueue = [];
|
|
175547
|
-
processingQueue = false;
|
|
175548
|
-
sawErrorChunk = false;
|
|
175549
|
-
constructor(cwd, options) {
|
|
175550
|
-
initAssistantsDir();
|
|
175551
|
-
const sessionId = options?.sessionId || generateId();
|
|
175552
|
-
this.logger = new Logger(sessionId);
|
|
175553
|
-
this.session = new SessionStorage(sessionId);
|
|
175554
|
-
this.cwd = cwd || process.cwd();
|
|
175555
|
-
this.startedAt = options?.startedAt || new Date().toISOString();
|
|
175556
|
-
this.initialMessages = options?.initialMessages || null;
|
|
175557
|
-
this.logger.info("Session started", { cwd: this.cwd });
|
|
175558
|
-
const createAssistant = options?.assistantFactory ?? ((opts) => new AssistantLoop(opts));
|
|
175559
|
-
this.assistantLoop = createAssistant({
|
|
175560
|
-
cwd: this.cwd,
|
|
175561
|
-
sessionId,
|
|
175562
|
-
assistantId: options?.assistantId,
|
|
175563
|
-
allowedTools: options?.allowedTools,
|
|
175564
|
-
extraSystemPrompt: options?.systemPrompt,
|
|
175565
|
-
model: options?.model,
|
|
175566
|
-
onChunk: (chunk) => {
|
|
175567
|
-
for (const callback of this.chunkCallbacks) {
|
|
175568
|
-
callback(chunk);
|
|
175569
|
-
}
|
|
175570
|
-
if (chunk.type === "error") {
|
|
175571
|
-
this.sawErrorChunk = true;
|
|
175572
|
-
}
|
|
175573
|
-
if (chunk.type === "done" || chunk.type === "error" || chunk.type === "stopped") {
|
|
175574
|
-
queueMicrotask(() => {
|
|
175575
|
-
this.drainQueue();
|
|
175576
|
-
});
|
|
175577
|
-
}
|
|
175578
|
-
},
|
|
175579
|
-
onToolStart: (toolCall) => {
|
|
175580
|
-
this.logger.info("Tool started", { tool: toolCall.name, input: toolCall.input });
|
|
175581
|
-
},
|
|
175582
|
-
onToolEnd: (toolCall, result) => {
|
|
175583
|
-
this.logger.info("Tool completed", {
|
|
175584
|
-
tool: toolCall.name,
|
|
175585
|
-
success: !result.isError,
|
|
175586
|
-
resultLength: result.content.length
|
|
175587
|
-
});
|
|
175588
|
-
}
|
|
175589
|
-
});
|
|
175590
|
-
}
|
|
175591
|
-
async initialize() {
|
|
175592
|
-
if (this.initialized)
|
|
175593
|
-
return;
|
|
175594
|
-
this.logger.info("Initializing assistant");
|
|
175595
|
-
await this.assistantLoop.initialize();
|
|
175596
|
-
if (typeof this.assistantLoop.getAssistantId === "function") {
|
|
175597
|
-
this.assistantId = this.assistantLoop.getAssistantId();
|
|
175598
|
-
if (this.assistantId) {
|
|
175599
|
-
this.session = new SessionStorage(this.session.getSessionId(), undefined, this.assistantId);
|
|
175600
|
-
}
|
|
175601
|
-
}
|
|
175602
|
-
if (this.initialMessages && this.initialMessages.length > 0) {
|
|
175603
|
-
const contextSeed = this.selectContextSeed(this.initialMessages);
|
|
175604
|
-
if (typeof this.assistantLoop.importContext === "function") {
|
|
175605
|
-
this.assistantLoop.importContext(contextSeed);
|
|
175606
|
-
} else {
|
|
175607
|
-
this.assistantLoop.getContext().import(contextSeed);
|
|
175608
|
-
}
|
|
175609
|
-
this.messages = [...this.initialMessages];
|
|
175610
|
-
this.messageIds = new Set(this.initialMessages.map((msg) => msg.id));
|
|
175611
|
-
}
|
|
175612
|
-
this.initialized = true;
|
|
175613
|
-
this.logger.info("Assistant initialized", {
|
|
175614
|
-
tools: this.assistantLoop.getTools().length,
|
|
175615
|
-
skills: this.assistantLoop.getSkills().length
|
|
175616
|
-
});
|
|
175617
|
-
}
|
|
175618
|
-
async send(message) {
|
|
175619
|
-
if (!this.initialized) {
|
|
175620
|
-
await this.initialize();
|
|
175621
|
-
}
|
|
175622
|
-
if (!message.trim()) {
|
|
175623
|
-
return;
|
|
175624
|
-
}
|
|
175625
|
-
this.messageQueue.push(message);
|
|
175626
|
-
if (this.assistantLoop.isProcessing() || this.processingQueue) {
|
|
175627
|
-
this.logger.info("Queuing message (assistant busy)", { message, queueLength: this.messageQueue.length });
|
|
175628
|
-
return;
|
|
175629
|
-
}
|
|
175630
|
-
await this.drainQueue();
|
|
175631
|
-
}
|
|
175632
|
-
async processMessage(message) {
|
|
175633
|
-
this.logger.info("User message", { message });
|
|
175634
|
-
this.sawErrorChunk = false;
|
|
175635
|
-
try {
|
|
175636
|
-
await this.assistantLoop.process(message);
|
|
175637
|
-
const context = this.assistantLoop.getContext();
|
|
175638
|
-
const contextMessages = context.getMessages();
|
|
175639
|
-
if (contextMessages.length > 0) {
|
|
175640
|
-
this.mergeMessages(contextMessages);
|
|
175641
|
-
const lastMessage = contextMessages.slice(-1)[0];
|
|
175642
|
-
if (lastMessage?.role === "assistant") {
|
|
175643
|
-
this.logger.info("Assistant response", {
|
|
175644
|
-
length: lastMessage.content.length,
|
|
175645
|
-
hasToolCalls: !!lastMessage.toolCalls?.length
|
|
175646
|
-
});
|
|
175647
|
-
}
|
|
175648
|
-
}
|
|
175649
|
-
this.saveSession();
|
|
175650
|
-
} catch (error3) {
|
|
175651
|
-
if (this.sawErrorChunk) {
|
|
175652
|
-
return;
|
|
175653
|
-
}
|
|
175654
|
-
const err = error3 instanceof Error ? error3 : new Error(String(error3));
|
|
175655
|
-
this.logger.error("Error processing message", { error: err.message });
|
|
175656
|
-
for (const callback of this.errorCallbacks) {
|
|
175657
|
-
callback(err);
|
|
175658
|
-
}
|
|
175659
|
-
}
|
|
175660
|
-
}
|
|
175661
|
-
async drainQueue() {
|
|
175662
|
-
if (this.processingQueue)
|
|
175663
|
-
return;
|
|
175664
|
-
this.processingQueue = true;
|
|
175665
|
-
try {
|
|
175666
|
-
while (this.messageQueue.length > 0 && !this.assistantLoop.isProcessing()) {
|
|
175667
|
-
const nextMessage = this.messageQueue.shift();
|
|
175668
|
-
if (nextMessage) {
|
|
175669
|
-
await this.processMessage(nextMessage);
|
|
175670
|
-
}
|
|
175671
|
-
}
|
|
175672
|
-
} finally {
|
|
175673
|
-
this.processingQueue = false;
|
|
175674
|
-
}
|
|
175675
|
-
}
|
|
175676
|
-
saveSession() {
|
|
175677
|
-
this.session.save({
|
|
175678
|
-
messages: this.messages,
|
|
175679
|
-
startedAt: this.startedAt,
|
|
175680
|
-
updatedAt: new Date().toISOString(),
|
|
175681
|
-
cwd: this.cwd
|
|
175682
|
-
});
|
|
175683
|
-
}
|
|
175684
|
-
onChunk(callback) {
|
|
175685
|
-
this.chunkCallbacks.push(callback);
|
|
175686
|
-
return () => {
|
|
175687
|
-
const index = this.chunkCallbacks.indexOf(callback);
|
|
175688
|
-
if (index !== -1)
|
|
175689
|
-
this.chunkCallbacks.splice(index, 1);
|
|
175690
|
-
};
|
|
175691
|
-
}
|
|
175692
|
-
onError(callback) {
|
|
175693
|
-
this.errorCallbacks.push(callback);
|
|
175694
|
-
return () => {
|
|
175695
|
-
const index = this.errorCallbacks.indexOf(callback);
|
|
175696
|
-
if (index !== -1)
|
|
175697
|
-
this.errorCallbacks.splice(index, 1);
|
|
175698
|
-
};
|
|
175699
|
-
}
|
|
175700
|
-
setAskUserHandler(handler) {
|
|
175701
|
-
if (typeof this.assistantLoop.setAskUserHandler === "function") {
|
|
175702
|
-
this.assistantLoop.setAskUserHandler(handler);
|
|
175703
|
-
}
|
|
175704
|
-
}
|
|
175705
|
-
async getTools() {
|
|
175706
|
-
if (!this.initialized) {
|
|
175707
|
-
await this.initialize();
|
|
175708
|
-
}
|
|
175709
|
-
return this.assistantLoop.getTools();
|
|
175710
|
-
}
|
|
175711
|
-
async getSkills() {
|
|
175712
|
-
if (!this.initialized) {
|
|
175713
|
-
await this.initialize();
|
|
175714
|
-
}
|
|
175715
|
-
return this.assistantLoop.getSkills();
|
|
175716
|
-
}
|
|
175717
|
-
async refreshSkills() {
|
|
175718
|
-
if (!this.initialized) {
|
|
175719
|
-
await this.initialize();
|
|
175720
|
-
}
|
|
175721
|
-
if (typeof this.assistantLoop.refreshSkills === "function") {
|
|
175722
|
-
await this.assistantLoop.refreshSkills();
|
|
175723
|
-
}
|
|
175724
|
-
return this.assistantLoop.getSkills();
|
|
175725
|
-
}
|
|
175726
|
-
getSkillLoader() {
|
|
175727
|
-
if (typeof this.assistantLoop.getSkillLoader === "function") {
|
|
175728
|
-
return this.assistantLoop.getSkillLoader();
|
|
175729
|
-
}
|
|
175730
|
-
return null;
|
|
175731
|
-
}
|
|
175732
|
-
stop() {
|
|
175733
|
-
this.logger.info("Processing stopped by user");
|
|
175734
|
-
this.assistantLoop.stop();
|
|
175735
|
-
}
|
|
175736
|
-
disconnect() {
|
|
175737
|
-
this.logger.info("Session ended");
|
|
175738
|
-
if (typeof this.assistantLoop.shutdown === "function") {
|
|
175739
|
-
this.assistantLoop.shutdown();
|
|
175740
|
-
}
|
|
175741
|
-
this.saveSession();
|
|
175742
|
-
this.chunkCallbacks.length = 0;
|
|
175743
|
-
this.errorCallbacks.length = 0;
|
|
175744
|
-
}
|
|
175745
|
-
isProcessing() {
|
|
175746
|
-
return this.assistantLoop.isProcessing();
|
|
175747
|
-
}
|
|
175748
|
-
getSessionId() {
|
|
175749
|
-
return this.session.getSessionId();
|
|
175750
|
-
}
|
|
175751
|
-
async getCommands() {
|
|
175752
|
-
if (!this.initialized) {
|
|
175753
|
-
await this.initialize();
|
|
175754
|
-
}
|
|
175755
|
-
return this.assistantLoop.getCommands();
|
|
175756
|
-
}
|
|
175757
|
-
getTokenUsage() {
|
|
175758
|
-
return this.assistantLoop.getTokenUsage();
|
|
175759
|
-
}
|
|
175760
|
-
getEnergyState() {
|
|
175761
|
-
if (typeof this.assistantLoop.getEnergyState === "function") {
|
|
175762
|
-
return this.assistantLoop.getEnergyState();
|
|
175763
|
-
}
|
|
175764
|
-
return null;
|
|
175765
|
-
}
|
|
175766
|
-
getVoiceState() {
|
|
175767
|
-
if (typeof this.assistantLoop.getVoiceState === "function") {
|
|
175768
|
-
return this.assistantLoop.getVoiceState();
|
|
175769
|
-
}
|
|
175770
|
-
return null;
|
|
175771
|
-
}
|
|
175772
|
-
getHeartbeatState() {
|
|
175773
|
-
if (typeof this.assistantLoop.getHeartbeatState === "function") {
|
|
175774
|
-
return this.assistantLoop.getHeartbeatState();
|
|
175775
|
-
}
|
|
175776
|
-
return null;
|
|
175777
|
-
}
|
|
175778
|
-
getIdentityInfo() {
|
|
175779
|
-
if (typeof this.assistantLoop.getIdentityInfo === "function") {
|
|
175780
|
-
return this.assistantLoop.getIdentityInfo();
|
|
175781
|
-
}
|
|
175782
|
-
return null;
|
|
175783
|
-
}
|
|
175784
|
-
getModel() {
|
|
175785
|
-
if (typeof this.assistantLoop.getModel === "function") {
|
|
175786
|
-
return this.assistantLoop.getModel();
|
|
175787
|
-
}
|
|
175788
|
-
return null;
|
|
175789
|
-
}
|
|
175790
|
-
getAssistantManager() {
|
|
175791
|
-
if (typeof this.assistantLoop.getAssistantManager === "function") {
|
|
175792
|
-
return this.assistantLoop.getAssistantManager();
|
|
175793
|
-
}
|
|
175794
|
-
return null;
|
|
175795
|
-
}
|
|
175796
|
-
getIdentityManager() {
|
|
175797
|
-
if (typeof this.assistantLoop.getIdentityManager === "function") {
|
|
175798
|
-
return this.assistantLoop.getIdentityManager();
|
|
175799
|
-
}
|
|
175800
|
-
return null;
|
|
175801
|
-
}
|
|
175802
|
-
getMemoryManager() {
|
|
175803
|
-
if (typeof this.assistantLoop.getMemoryManager === "function") {
|
|
175804
|
-
return this.assistantLoop.getMemoryManager();
|
|
175805
|
-
}
|
|
175806
|
-
return null;
|
|
175807
|
-
}
|
|
175808
|
-
async refreshIdentityContext() {
|
|
175809
|
-
if (typeof this.assistantLoop.refreshIdentityContext === "function") {
|
|
175810
|
-
await this.assistantLoop.refreshIdentityContext();
|
|
175811
|
-
}
|
|
175812
|
-
}
|
|
175813
|
-
getMessagesManager() {
|
|
175814
|
-
if (typeof this.assistantLoop.getMessagesManager === "function") {
|
|
175815
|
-
return this.assistantLoop.getMessagesManager();
|
|
175816
|
-
}
|
|
175817
|
-
return null;
|
|
175818
|
-
}
|
|
175819
|
-
getWebhooksManager() {
|
|
175820
|
-
if (typeof this.assistantLoop.getWebhooksManager === "function") {
|
|
175821
|
-
return this.assistantLoop.getWebhooksManager();
|
|
175822
|
-
}
|
|
175823
|
-
return null;
|
|
175824
|
-
}
|
|
175825
|
-
getChannelsManager() {
|
|
175826
|
-
if (typeof this.assistantLoop.getChannelsManager === "function") {
|
|
175827
|
-
return this.assistantLoop.getChannelsManager();
|
|
175828
|
-
}
|
|
175829
|
-
return null;
|
|
175830
|
-
}
|
|
175831
|
-
getPeopleManager() {
|
|
175832
|
-
if (typeof this.assistantLoop.getPeopleManager === "function") {
|
|
175833
|
-
return this.assistantLoop.getPeopleManager();
|
|
175834
|
-
}
|
|
175835
|
-
return null;
|
|
175836
|
-
}
|
|
175837
|
-
getTelephonyManager() {
|
|
175838
|
-
if (typeof this.assistantLoop.getTelephonyManager === "function") {
|
|
175839
|
-
return this.assistantLoop.getTelephonyManager();
|
|
175840
|
-
}
|
|
175841
|
-
return null;
|
|
175842
|
-
}
|
|
175843
|
-
getWalletManager() {
|
|
175844
|
-
if (typeof this.assistantLoop.getWalletManager === "function") {
|
|
175845
|
-
return this.assistantLoop.getWalletManager();
|
|
175846
|
-
}
|
|
175847
|
-
return null;
|
|
175848
|
-
}
|
|
175849
|
-
getSecretsManager() {
|
|
175850
|
-
if (typeof this.assistantLoop.getSecretsManager === "function") {
|
|
175851
|
-
return this.assistantLoop.getSecretsManager();
|
|
175852
|
-
}
|
|
175853
|
-
return null;
|
|
175854
|
-
}
|
|
175855
|
-
getInboxManager() {
|
|
175856
|
-
if (typeof this.assistantLoop.getInboxManager === "function") {
|
|
175857
|
-
return this.assistantLoop.getInboxManager();
|
|
175858
|
-
}
|
|
175859
|
-
return null;
|
|
175860
|
-
}
|
|
175861
|
-
getActiveProjectId() {
|
|
175862
|
-
if (typeof this.assistantLoop.getActiveProjectId === "function") {
|
|
175863
|
-
return this.assistantLoop.getActiveProjectId();
|
|
175864
|
-
}
|
|
175865
|
-
return null;
|
|
175866
|
-
}
|
|
175867
|
-
setActiveProjectId(projectId) {
|
|
175868
|
-
if (typeof this.assistantLoop.setActiveProjectId === "function") {
|
|
175869
|
-
this.assistantLoop.setActiveProjectId(projectId);
|
|
175870
|
-
}
|
|
175871
|
-
}
|
|
175872
|
-
getSwarmCoordinator() {
|
|
175873
|
-
if (typeof this.assistantLoop.getOrCreateSwarmCoordinator === "function") {
|
|
175874
|
-
return this.assistantLoop.getOrCreateSwarmCoordinator();
|
|
175875
|
-
}
|
|
175876
|
-
return null;
|
|
175877
|
-
}
|
|
175878
|
-
getAssistantLoop() {
|
|
175879
|
-
return this.assistantLoop;
|
|
175880
|
-
}
|
|
175881
|
-
addSystemMessage(content) {
|
|
175882
|
-
if (typeof this.assistantLoop.addSystemMessage === "function") {
|
|
175883
|
-
this.assistantLoop.addSystemMessage(content);
|
|
175884
|
-
} else {
|
|
175885
|
-
const context = this.assistantLoop.getContext();
|
|
175886
|
-
if (typeof context.addSystemMessage === "function") {
|
|
175887
|
-
context.addSystemMessage(content);
|
|
175888
|
-
}
|
|
175889
|
-
}
|
|
175890
|
-
}
|
|
175891
|
-
clearConversation() {
|
|
175892
|
-
this.assistantLoop.clearConversation();
|
|
175893
|
-
this.messages = [];
|
|
175894
|
-
this.messageIds.clear();
|
|
175895
|
-
this.logger.info("Conversation cleared");
|
|
175896
|
-
}
|
|
175897
|
-
getCwd() {
|
|
175898
|
-
return this.cwd;
|
|
175899
|
-
}
|
|
175900
|
-
getStartedAt() {
|
|
175901
|
-
return this.startedAt;
|
|
175902
|
-
}
|
|
175903
|
-
getMessages() {
|
|
175904
|
-
return [...this.messages];
|
|
175905
|
-
}
|
|
175906
|
-
getQueueLength() {
|
|
175907
|
-
return this.messageQueue.length;
|
|
175908
|
-
}
|
|
175909
|
-
clearQueue() {
|
|
175910
|
-
this.messageQueue = [];
|
|
175911
|
-
this.logger.info("Message queue cleared");
|
|
175912
|
-
}
|
|
175913
|
-
mergeMessages(contextMessages) {
|
|
175914
|
-
if (contextMessages.length === 0)
|
|
175915
|
-
return;
|
|
175916
|
-
if (this.messages.length === 0 && this.messageIds.size === 0) {
|
|
175917
|
-
this.messages = [...contextMessages];
|
|
175918
|
-
this.messageIds = new Set(contextMessages.map((msg) => msg.id));
|
|
175919
|
-
return;
|
|
175920
|
-
}
|
|
175921
|
-
for (const msg of contextMessages) {
|
|
175922
|
-
if (!this.messageIds.has(msg.id)) {
|
|
175923
|
-
this.messages.push(msg);
|
|
175924
|
-
this.messageIds.add(msg.id);
|
|
175925
|
-
}
|
|
175926
|
-
}
|
|
175927
|
-
}
|
|
175928
|
-
selectContextSeed(messages) {
|
|
175929
|
-
if (messages.length === 0)
|
|
175930
|
-
return [];
|
|
175931
|
-
const contextInfo = typeof this.assistantLoop.getContextInfo === "function" ? this.assistantLoop.getContextInfo() : null;
|
|
175932
|
-
const maxMessages = contextInfo?.config?.maxMessages ?? 100;
|
|
175933
|
-
if (messages.length <= maxMessages)
|
|
175934
|
-
return messages;
|
|
175935
|
-
let startIndex = messages.length - maxMessages;
|
|
175936
|
-
if (startIndex > 0 && messages[startIndex]?.toolResults && messages[startIndex - 1]) {
|
|
175937
|
-
startIndex -= 1;
|
|
175938
|
-
}
|
|
175939
|
-
return messages.slice(Math.max(0, startIndex));
|
|
175940
|
-
}
|
|
175941
|
-
}
|
|
175942
|
-
var init_client4 = __esm(async () => {
|
|
175943
|
-
init_src2();
|
|
175944
|
-
await __promiseAll([
|
|
175945
|
-
init_loop(),
|
|
175946
|
-
init_logger2()
|
|
175947
|
-
]);
|
|
175948
|
-
});
|
|
175949
|
-
|
|
175950
176014
|
// packages/core/src/sessions/registry.ts
|
|
175951
176015
|
class SessionRegistry {
|
|
175952
176016
|
sessions = new Map;
|
|
@@ -180810,7 +180874,7 @@ class GlobalMemoryManager {
|
|
|
180810
180874
|
const result = this.db.prepare(`
|
|
180811
180875
|
DELETE FROM memories WHERE id IN (
|
|
180812
180876
|
SELECT id FROM memories
|
|
180813
|
-
ORDER BY importance ASC, accessed_at ASC
|
|
180877
|
+
ORDER BY importance ASC, (accessed_at IS NOT NULL) ASC, accessed_at ASC, created_at ASC
|
|
180814
180878
|
LIMIT ?
|
|
180815
180879
|
)
|
|
180816
180880
|
`).run(toRemove);
|
|
@@ -182598,6 +182662,7 @@ class AssistantLoop {
|
|
|
182598
182662
|
messagesManager = null;
|
|
182599
182663
|
webhooksManager = null;
|
|
182600
182664
|
channelsManager = null;
|
|
182665
|
+
channelAgentPool = null;
|
|
182601
182666
|
peopleManager = null;
|
|
182602
182667
|
telephonyManager = null;
|
|
182603
182668
|
memoryManager = null;
|
|
@@ -182842,6 +182907,7 @@ class AssistantLoop {
|
|
|
182842
182907
|
const assistantName = assistant?.name || "assistant";
|
|
182843
182908
|
this.channelsManager = createChannelsManager(assistantId, assistantName, this.config.channels);
|
|
182844
182909
|
registerChannelTools(this.toolRegistry, () => this.channelsManager);
|
|
182910
|
+
this.channelAgentPool = new ChannelAgentPool(this.cwd);
|
|
182845
182911
|
}
|
|
182846
182912
|
try {
|
|
182847
182913
|
this.peopleManager = await createPeopleManager();
|
|
@@ -183925,6 +183991,7 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
183925
183991
|
getMessagesManager: () => this.messagesManager,
|
|
183926
183992
|
getWebhooksManager: () => this.webhooksManager,
|
|
183927
183993
|
getChannelsManager: () => this.channelsManager,
|
|
183994
|
+
getChannelAgentPool: () => this.channelAgentPool,
|
|
183928
183995
|
getPeopleManager: () => this.peopleManager,
|
|
183929
183996
|
getTelephonyManager: () => this.telephonyManager,
|
|
183930
183997
|
getMemoryManager: () => this.memoryManager,
|
|
@@ -184175,6 +184242,8 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
184175
184242
|
this.voiceManager?.stopListening();
|
|
184176
184243
|
this.messagesManager?.stopWatching();
|
|
184177
184244
|
this.webhooksManager?.stopWatching();
|
|
184245
|
+
this.channelAgentPool?.shutdown();
|
|
184246
|
+
this.channelAgentPool = null;
|
|
184178
184247
|
this.channelsManager?.close();
|
|
184179
184248
|
this.channelsManager = null;
|
|
184180
184249
|
this.telephonyManager?.close();
|
|
@@ -184256,6 +184325,9 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
184256
184325
|
getChannelsManager() {
|
|
184257
184326
|
return this.channelsManager;
|
|
184258
184327
|
}
|
|
184328
|
+
getChannelAgentPool() {
|
|
184329
|
+
return this.channelAgentPool;
|
|
184330
|
+
}
|
|
184259
184331
|
getPeopleManager() {
|
|
184260
184332
|
return this.peopleManager;
|
|
184261
184333
|
}
|
|
@@ -186932,6 +187004,7 @@ __export(exports_src2, {
|
|
|
186932
187004
|
CommandExecutor: () => CommandExecutor,
|
|
186933
187005
|
ChannelsManager: () => ChannelsManager,
|
|
186934
187006
|
ChannelStore: () => ChannelStore,
|
|
187007
|
+
ChannelAgentPool: () => ChannelAgentPool,
|
|
186935
187008
|
CapabilityStorage: () => CapabilityStorage,
|
|
186936
187009
|
CapabilityEnforcer: () => CapabilityEnforcer,
|
|
186937
187010
|
CallManager: () => CallManager,
|
|
@@ -206319,6 +206392,7 @@ var COMMANDS = [
|
|
|
206319
206392
|
{ name: "/memory", description: "show what AI remembers" },
|
|
206320
206393
|
{ name: "/context", description: "manage injected project context" },
|
|
206321
206394
|
{ name: "/hooks", description: "manage hooks (list, add, remove, test)" },
|
|
206395
|
+
{ name: "/onboarding", description: "rerun onboarding setup" },
|
|
206322
206396
|
{ name: "/projects", description: "manage projects in this folder" },
|
|
206323
206397
|
{ name: "/plans", description: "manage project plans" },
|
|
206324
206398
|
{ name: "/schedules", description: "manage scheduled commands" },
|
|
@@ -232120,6 +232194,10 @@ function App2({ cwd: cwd2, version: version3 }) {
|
|
|
232120
232194
|
setShowIdentityPanel(true);
|
|
232121
232195
|
return;
|
|
232122
232196
|
}
|
|
232197
|
+
if (cmdName === "onboarding" && !cmdArgs) {
|
|
232198
|
+
setShowOnboardingPanel(true);
|
|
232199
|
+
return;
|
|
232200
|
+
}
|
|
232123
232201
|
if (cmdName === "memory" && !cmdArgs) {
|
|
232124
232202
|
setMemoryError(null);
|
|
232125
232203
|
setShowMemoryPanel(true);
|
|
@@ -233613,23 +233691,28 @@ When done, report the result.`);
|
|
|
233613
233691
|
activePersonName: activeSession?.client.getPeopleManager?.()?.getActivePerson?.()?.name || undefined,
|
|
233614
233692
|
onPersonMessage: (channelName, personName, message) => {
|
|
233615
233693
|
const members = channelsManager.getMembers(channelName);
|
|
233616
|
-
const
|
|
233694
|
+
const agentPool = activeSession?.client.getChannelAgentPool?.();
|
|
233695
|
+
if (agentPool) {
|
|
233696
|
+
agentPool.triggerResponses(channelName, personName, message, members, activeSession?.assistantId || undefined);
|
|
233697
|
+
}
|
|
233698
|
+
const activeAssistantId = activeSession?.assistantId;
|
|
233699
|
+
const isActiveMember = activeAssistantId && members.some((m5) => m5.assistantId === activeAssistantId && m5.memberType === "assistant");
|
|
233617
233700
|
const mentions = parseMentions(message);
|
|
233618
|
-
let
|
|
233619
|
-
if (mentions.length > 0) {
|
|
233620
|
-
const
|
|
233621
|
-
const
|
|
233701
|
+
let activeAssistantTargeted = true;
|
|
233702
|
+
if (mentions.length > 0 && isActiveMember) {
|
|
233703
|
+
const assistantMembers = members.filter((m5) => m5.memberType === "assistant");
|
|
233704
|
+
const knownNames = assistantMembers.map((m5) => ({ id: m5.assistantId, name: m5.assistantName }));
|
|
233705
|
+
const resolved = mentions.map((m5) => resolveNameToKnown(m5, knownNames)).filter(Boolean);
|
|
233622
233706
|
if (resolved.length > 0) {
|
|
233623
|
-
|
|
233707
|
+
activeAssistantTargeted = resolved.some((r6) => r6.id === activeAssistantId);
|
|
233624
233708
|
}
|
|
233625
233709
|
}
|
|
233626
|
-
|
|
233627
|
-
|
|
233628
|
-
|
|
233629
|
-
${assistantList}
|
|
233710
|
+
if (isActiveMember && activeAssistantTargeted) {
|
|
233711
|
+
const prompt = `[Channel Message] ${personName} posted in #${channelName}: "${message}"
|
|
233630
233712
|
|
|
233631
233713
|
Respond in #${channelName} using channel_send. Be helpful and conversational.`;
|
|
233632
|
-
|
|
233714
|
+
activeSession?.client.send(prompt);
|
|
233715
|
+
}
|
|
233633
233716
|
}
|
|
233634
233717
|
}, undefined, false, undefined, this);
|
|
233635
233718
|
}
|
|
@@ -234421,7 +234504,7 @@ Interactive Mode:
|
|
|
234421
234504
|
// packages/terminal/src/index.tsx
|
|
234422
234505
|
var jsx_dev_runtime44 = __toESM(require_jsx_dev_runtime(), 1);
|
|
234423
234506
|
setRuntime(bunRuntime);
|
|
234424
|
-
var VERSION4 = "1.1.
|
|
234507
|
+
var VERSION4 = "1.1.17";
|
|
234425
234508
|
var SYNC_START = "\x1B[?2026h";
|
|
234426
234509
|
var SYNC_END = "\x1B[?2026l";
|
|
234427
234510
|
function enableSynchronizedOutput() {
|
|
@@ -234561,4 +234644,4 @@ export {
|
|
|
234561
234644
|
main
|
|
234562
234645
|
};
|
|
234563
234646
|
|
|
234564
|
-
//# debugId=
|
|
234647
|
+
//# debugId=06504F1621F0D4C464756E2164756E21
|