@hasna/assistants 1.1.15 → 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 +564 -428
- package/dist/index.js.map +13 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74459,11 +74459,17 @@ Configure the external source with the URL and secret above.
|
|
|
74459
74459
|
`);
|
|
74460
74460
|
context.emit("done");
|
|
74461
74461
|
if (activePerson && result.success) {
|
|
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);
|
|
74467
|
+
}
|
|
74462
74468
|
return {
|
|
74463
74469
|
handled: false,
|
|
74464
74470
|
prompt: `[Channel Message] ${activePerson.name} posted in #${channel}: "${message}"
|
|
74465
74471
|
|
|
74466
|
-
|
|
74472
|
+
Respond in #${channel} using channel_send. Be helpful and conversational.`
|
|
74467
74473
|
};
|
|
74468
74474
|
}
|
|
74469
74475
|
return { handled: true };
|
|
@@ -79318,7 +79324,7 @@ ${repoUrl}/issues/new
|
|
|
79318
79324
|
context.setProjectContext(projectContext);
|
|
79319
79325
|
}
|
|
79320
79326
|
}
|
|
79321
|
-
var VERSION = "1.1.
|
|
79327
|
+
var VERSION = "1.1.17";
|
|
79322
79328
|
var init_builtin = __esm(async () => {
|
|
79323
79329
|
init_src2();
|
|
79324
79330
|
init_store();
|
|
@@ -172691,7 +172697,7 @@ class ChannelStore {
|
|
|
172691
172697
|
params.push(options.status);
|
|
172692
172698
|
}
|
|
172693
172699
|
}
|
|
172694
|
-
query += " ORDER BY last_message_at
|
|
172700
|
+
query += " ORDER BY (last_message_at IS NULL) ASC, last_message_at DESC, c.created_at DESC";
|
|
172695
172701
|
const stmt = this.db.prepare(query);
|
|
172696
172702
|
const rows = stmt.all(...params);
|
|
172697
172703
|
return rows.map((row) => ({
|
|
@@ -173097,12 +173103,443 @@ var init_manager6 = __esm(async () => {
|
|
|
173097
173103
|
await init_store7();
|
|
173098
173104
|
});
|
|
173099
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
|
+
|
|
173100
173530
|
// packages/core/src/channels/mentions.ts
|
|
173101
173531
|
function parseMentions(content) {
|
|
173102
|
-
const regex = /@([a-zA-Z0-9_-]+)/g;
|
|
173103
173532
|
const mentions = [];
|
|
173533
|
+
const quotedRegex = /@"([^"]+)"/g;
|
|
173104
173534
|
let match;
|
|
173105
|
-
while ((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) {
|
|
173106
173543
|
const name2 = match[1];
|
|
173107
173544
|
if (!mentions.includes(name2)) {
|
|
173108
173545
|
mentions.push(name2);
|
|
@@ -173110,6 +173547,19 @@ function parseMentions(content) {
|
|
|
173110
173547
|
}
|
|
173111
173548
|
return mentions;
|
|
173112
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
|
+
}
|
|
173113
173563
|
function resolveMentions(names, members) {
|
|
173114
173564
|
const resolved = [];
|
|
173115
173565
|
for (const name2 of names) {
|
|
@@ -173131,6 +173581,72 @@ function getMentionedMemberIds(content, members) {
|
|
|
173131
173581
|
return resolved.map((r6) => r6.memberId);
|
|
173132
173582
|
}
|
|
173133
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
|
+
|
|
173134
173650
|
// packages/core/src/channels/tools.ts
|
|
173135
173651
|
function createChannelToolExecutors(getChannelsManager) {
|
|
173136
173652
|
return {
|
|
@@ -173424,6 +173940,7 @@ var init_channels = __esm(async () => {
|
|
|
173424
173940
|
init_tools10();
|
|
173425
173941
|
await __promiseAll([
|
|
173426
173942
|
init_manager6(),
|
|
173943
|
+
init_agent_pool(),
|
|
173427
173944
|
init_store7()
|
|
173428
173945
|
]);
|
|
173429
173946
|
});
|
|
@@ -175494,424 +176011,6 @@ class SessionStore {
|
|
|
175494
176011
|
}
|
|
175495
176012
|
var init_store10 = () => {};
|
|
175496
176013
|
|
|
175497
|
-
// packages/core/src/client.ts
|
|
175498
|
-
class EmbeddedClient {
|
|
175499
|
-
assistantLoop;
|
|
175500
|
-
chunkCallbacks = [];
|
|
175501
|
-
errorCallbacks = [];
|
|
175502
|
-
initialized = false;
|
|
175503
|
-
logger;
|
|
175504
|
-
session;
|
|
175505
|
-
messages = [];
|
|
175506
|
-
messageIds = new Set;
|
|
175507
|
-
cwd;
|
|
175508
|
-
startedAt;
|
|
175509
|
-
initialMessages = null;
|
|
175510
|
-
assistantId = null;
|
|
175511
|
-
messageQueue = [];
|
|
175512
|
-
processingQueue = false;
|
|
175513
|
-
sawErrorChunk = false;
|
|
175514
|
-
constructor(cwd, options) {
|
|
175515
|
-
initAssistantsDir();
|
|
175516
|
-
const sessionId = options?.sessionId || generateId();
|
|
175517
|
-
this.logger = new Logger(sessionId);
|
|
175518
|
-
this.session = new SessionStorage(sessionId);
|
|
175519
|
-
this.cwd = cwd || process.cwd();
|
|
175520
|
-
this.startedAt = options?.startedAt || new Date().toISOString();
|
|
175521
|
-
this.initialMessages = options?.initialMessages || null;
|
|
175522
|
-
this.logger.info("Session started", { cwd: this.cwd });
|
|
175523
|
-
const createAssistant = options?.assistantFactory ?? ((opts) => new AssistantLoop(opts));
|
|
175524
|
-
this.assistantLoop = createAssistant({
|
|
175525
|
-
cwd: this.cwd,
|
|
175526
|
-
sessionId,
|
|
175527
|
-
assistantId: options?.assistantId,
|
|
175528
|
-
allowedTools: options?.allowedTools,
|
|
175529
|
-
extraSystemPrompt: options?.systemPrompt,
|
|
175530
|
-
model: options?.model,
|
|
175531
|
-
onChunk: (chunk) => {
|
|
175532
|
-
for (const callback of this.chunkCallbacks) {
|
|
175533
|
-
callback(chunk);
|
|
175534
|
-
}
|
|
175535
|
-
if (chunk.type === "error") {
|
|
175536
|
-
this.sawErrorChunk = true;
|
|
175537
|
-
}
|
|
175538
|
-
if (chunk.type === "done" || chunk.type === "error" || chunk.type === "stopped") {
|
|
175539
|
-
queueMicrotask(() => {
|
|
175540
|
-
this.drainQueue();
|
|
175541
|
-
});
|
|
175542
|
-
}
|
|
175543
|
-
},
|
|
175544
|
-
onToolStart: (toolCall) => {
|
|
175545
|
-
this.logger.info("Tool started", { tool: toolCall.name, input: toolCall.input });
|
|
175546
|
-
},
|
|
175547
|
-
onToolEnd: (toolCall, result) => {
|
|
175548
|
-
this.logger.info("Tool completed", {
|
|
175549
|
-
tool: toolCall.name,
|
|
175550
|
-
success: !result.isError,
|
|
175551
|
-
resultLength: result.content.length
|
|
175552
|
-
});
|
|
175553
|
-
}
|
|
175554
|
-
});
|
|
175555
|
-
}
|
|
175556
|
-
async initialize() {
|
|
175557
|
-
if (this.initialized)
|
|
175558
|
-
return;
|
|
175559
|
-
this.logger.info("Initializing assistant");
|
|
175560
|
-
await this.assistantLoop.initialize();
|
|
175561
|
-
if (typeof this.assistantLoop.getAssistantId === "function") {
|
|
175562
|
-
this.assistantId = this.assistantLoop.getAssistantId();
|
|
175563
|
-
if (this.assistantId) {
|
|
175564
|
-
this.session = new SessionStorage(this.session.getSessionId(), undefined, this.assistantId);
|
|
175565
|
-
}
|
|
175566
|
-
}
|
|
175567
|
-
if (this.initialMessages && this.initialMessages.length > 0) {
|
|
175568
|
-
const contextSeed = this.selectContextSeed(this.initialMessages);
|
|
175569
|
-
if (typeof this.assistantLoop.importContext === "function") {
|
|
175570
|
-
this.assistantLoop.importContext(contextSeed);
|
|
175571
|
-
} else {
|
|
175572
|
-
this.assistantLoop.getContext().import(contextSeed);
|
|
175573
|
-
}
|
|
175574
|
-
this.messages = [...this.initialMessages];
|
|
175575
|
-
this.messageIds = new Set(this.initialMessages.map((msg) => msg.id));
|
|
175576
|
-
}
|
|
175577
|
-
this.initialized = true;
|
|
175578
|
-
this.logger.info("Assistant initialized", {
|
|
175579
|
-
tools: this.assistantLoop.getTools().length,
|
|
175580
|
-
skills: this.assistantLoop.getSkills().length
|
|
175581
|
-
});
|
|
175582
|
-
}
|
|
175583
|
-
async send(message) {
|
|
175584
|
-
if (!this.initialized) {
|
|
175585
|
-
await this.initialize();
|
|
175586
|
-
}
|
|
175587
|
-
if (!message.trim()) {
|
|
175588
|
-
return;
|
|
175589
|
-
}
|
|
175590
|
-
this.messageQueue.push(message);
|
|
175591
|
-
if (this.assistantLoop.isProcessing() || this.processingQueue) {
|
|
175592
|
-
this.logger.info("Queuing message (assistant busy)", { message, queueLength: this.messageQueue.length });
|
|
175593
|
-
return;
|
|
175594
|
-
}
|
|
175595
|
-
await this.drainQueue();
|
|
175596
|
-
}
|
|
175597
|
-
async processMessage(message) {
|
|
175598
|
-
this.logger.info("User message", { message });
|
|
175599
|
-
this.sawErrorChunk = false;
|
|
175600
|
-
try {
|
|
175601
|
-
await this.assistantLoop.process(message);
|
|
175602
|
-
const context = this.assistantLoop.getContext();
|
|
175603
|
-
const contextMessages = context.getMessages();
|
|
175604
|
-
if (contextMessages.length > 0) {
|
|
175605
|
-
this.mergeMessages(contextMessages);
|
|
175606
|
-
const lastMessage = contextMessages.slice(-1)[0];
|
|
175607
|
-
if (lastMessage?.role === "assistant") {
|
|
175608
|
-
this.logger.info("Assistant response", {
|
|
175609
|
-
length: lastMessage.content.length,
|
|
175610
|
-
hasToolCalls: !!lastMessage.toolCalls?.length
|
|
175611
|
-
});
|
|
175612
|
-
}
|
|
175613
|
-
}
|
|
175614
|
-
this.saveSession();
|
|
175615
|
-
} catch (error3) {
|
|
175616
|
-
if (this.sawErrorChunk) {
|
|
175617
|
-
return;
|
|
175618
|
-
}
|
|
175619
|
-
const err = error3 instanceof Error ? error3 : new Error(String(error3));
|
|
175620
|
-
this.logger.error("Error processing message", { error: err.message });
|
|
175621
|
-
for (const callback of this.errorCallbacks) {
|
|
175622
|
-
callback(err);
|
|
175623
|
-
}
|
|
175624
|
-
}
|
|
175625
|
-
}
|
|
175626
|
-
async drainQueue() {
|
|
175627
|
-
if (this.processingQueue)
|
|
175628
|
-
return;
|
|
175629
|
-
this.processingQueue = true;
|
|
175630
|
-
try {
|
|
175631
|
-
while (this.messageQueue.length > 0 && !this.assistantLoop.isProcessing()) {
|
|
175632
|
-
const nextMessage = this.messageQueue.shift();
|
|
175633
|
-
if (nextMessage) {
|
|
175634
|
-
await this.processMessage(nextMessage);
|
|
175635
|
-
}
|
|
175636
|
-
}
|
|
175637
|
-
} finally {
|
|
175638
|
-
this.processingQueue = false;
|
|
175639
|
-
}
|
|
175640
|
-
}
|
|
175641
|
-
saveSession() {
|
|
175642
|
-
this.session.save({
|
|
175643
|
-
messages: this.messages,
|
|
175644
|
-
startedAt: this.startedAt,
|
|
175645
|
-
updatedAt: new Date().toISOString(),
|
|
175646
|
-
cwd: this.cwd
|
|
175647
|
-
});
|
|
175648
|
-
}
|
|
175649
|
-
onChunk(callback) {
|
|
175650
|
-
this.chunkCallbacks.push(callback);
|
|
175651
|
-
return () => {
|
|
175652
|
-
const index = this.chunkCallbacks.indexOf(callback);
|
|
175653
|
-
if (index !== -1)
|
|
175654
|
-
this.chunkCallbacks.splice(index, 1);
|
|
175655
|
-
};
|
|
175656
|
-
}
|
|
175657
|
-
onError(callback) {
|
|
175658
|
-
this.errorCallbacks.push(callback);
|
|
175659
|
-
return () => {
|
|
175660
|
-
const index = this.errorCallbacks.indexOf(callback);
|
|
175661
|
-
if (index !== -1)
|
|
175662
|
-
this.errorCallbacks.splice(index, 1);
|
|
175663
|
-
};
|
|
175664
|
-
}
|
|
175665
|
-
setAskUserHandler(handler) {
|
|
175666
|
-
if (typeof this.assistantLoop.setAskUserHandler === "function") {
|
|
175667
|
-
this.assistantLoop.setAskUserHandler(handler);
|
|
175668
|
-
}
|
|
175669
|
-
}
|
|
175670
|
-
async getTools() {
|
|
175671
|
-
if (!this.initialized) {
|
|
175672
|
-
await this.initialize();
|
|
175673
|
-
}
|
|
175674
|
-
return this.assistantLoop.getTools();
|
|
175675
|
-
}
|
|
175676
|
-
async getSkills() {
|
|
175677
|
-
if (!this.initialized) {
|
|
175678
|
-
await this.initialize();
|
|
175679
|
-
}
|
|
175680
|
-
return this.assistantLoop.getSkills();
|
|
175681
|
-
}
|
|
175682
|
-
async refreshSkills() {
|
|
175683
|
-
if (!this.initialized) {
|
|
175684
|
-
await this.initialize();
|
|
175685
|
-
}
|
|
175686
|
-
if (typeof this.assistantLoop.refreshSkills === "function") {
|
|
175687
|
-
await this.assistantLoop.refreshSkills();
|
|
175688
|
-
}
|
|
175689
|
-
return this.assistantLoop.getSkills();
|
|
175690
|
-
}
|
|
175691
|
-
getSkillLoader() {
|
|
175692
|
-
if (typeof this.assistantLoop.getSkillLoader === "function") {
|
|
175693
|
-
return this.assistantLoop.getSkillLoader();
|
|
175694
|
-
}
|
|
175695
|
-
return null;
|
|
175696
|
-
}
|
|
175697
|
-
stop() {
|
|
175698
|
-
this.logger.info("Processing stopped by user");
|
|
175699
|
-
this.assistantLoop.stop();
|
|
175700
|
-
}
|
|
175701
|
-
disconnect() {
|
|
175702
|
-
this.logger.info("Session ended");
|
|
175703
|
-
if (typeof this.assistantLoop.shutdown === "function") {
|
|
175704
|
-
this.assistantLoop.shutdown();
|
|
175705
|
-
}
|
|
175706
|
-
this.saveSession();
|
|
175707
|
-
this.chunkCallbacks.length = 0;
|
|
175708
|
-
this.errorCallbacks.length = 0;
|
|
175709
|
-
}
|
|
175710
|
-
isProcessing() {
|
|
175711
|
-
return this.assistantLoop.isProcessing();
|
|
175712
|
-
}
|
|
175713
|
-
getSessionId() {
|
|
175714
|
-
return this.session.getSessionId();
|
|
175715
|
-
}
|
|
175716
|
-
async getCommands() {
|
|
175717
|
-
if (!this.initialized) {
|
|
175718
|
-
await this.initialize();
|
|
175719
|
-
}
|
|
175720
|
-
return this.assistantLoop.getCommands();
|
|
175721
|
-
}
|
|
175722
|
-
getTokenUsage() {
|
|
175723
|
-
return this.assistantLoop.getTokenUsage();
|
|
175724
|
-
}
|
|
175725
|
-
getEnergyState() {
|
|
175726
|
-
if (typeof this.assistantLoop.getEnergyState === "function") {
|
|
175727
|
-
return this.assistantLoop.getEnergyState();
|
|
175728
|
-
}
|
|
175729
|
-
return null;
|
|
175730
|
-
}
|
|
175731
|
-
getVoiceState() {
|
|
175732
|
-
if (typeof this.assistantLoop.getVoiceState === "function") {
|
|
175733
|
-
return this.assistantLoop.getVoiceState();
|
|
175734
|
-
}
|
|
175735
|
-
return null;
|
|
175736
|
-
}
|
|
175737
|
-
getHeartbeatState() {
|
|
175738
|
-
if (typeof this.assistantLoop.getHeartbeatState === "function") {
|
|
175739
|
-
return this.assistantLoop.getHeartbeatState();
|
|
175740
|
-
}
|
|
175741
|
-
return null;
|
|
175742
|
-
}
|
|
175743
|
-
getIdentityInfo() {
|
|
175744
|
-
if (typeof this.assistantLoop.getIdentityInfo === "function") {
|
|
175745
|
-
return this.assistantLoop.getIdentityInfo();
|
|
175746
|
-
}
|
|
175747
|
-
return null;
|
|
175748
|
-
}
|
|
175749
|
-
getModel() {
|
|
175750
|
-
if (typeof this.assistantLoop.getModel === "function") {
|
|
175751
|
-
return this.assistantLoop.getModel();
|
|
175752
|
-
}
|
|
175753
|
-
return null;
|
|
175754
|
-
}
|
|
175755
|
-
getAssistantManager() {
|
|
175756
|
-
if (typeof this.assistantLoop.getAssistantManager === "function") {
|
|
175757
|
-
return this.assistantLoop.getAssistantManager();
|
|
175758
|
-
}
|
|
175759
|
-
return null;
|
|
175760
|
-
}
|
|
175761
|
-
getIdentityManager() {
|
|
175762
|
-
if (typeof this.assistantLoop.getIdentityManager === "function") {
|
|
175763
|
-
return this.assistantLoop.getIdentityManager();
|
|
175764
|
-
}
|
|
175765
|
-
return null;
|
|
175766
|
-
}
|
|
175767
|
-
getMemoryManager() {
|
|
175768
|
-
if (typeof this.assistantLoop.getMemoryManager === "function") {
|
|
175769
|
-
return this.assistantLoop.getMemoryManager();
|
|
175770
|
-
}
|
|
175771
|
-
return null;
|
|
175772
|
-
}
|
|
175773
|
-
async refreshIdentityContext() {
|
|
175774
|
-
if (typeof this.assistantLoop.refreshIdentityContext === "function") {
|
|
175775
|
-
await this.assistantLoop.refreshIdentityContext();
|
|
175776
|
-
}
|
|
175777
|
-
}
|
|
175778
|
-
getMessagesManager() {
|
|
175779
|
-
if (typeof this.assistantLoop.getMessagesManager === "function") {
|
|
175780
|
-
return this.assistantLoop.getMessagesManager();
|
|
175781
|
-
}
|
|
175782
|
-
return null;
|
|
175783
|
-
}
|
|
175784
|
-
getWebhooksManager() {
|
|
175785
|
-
if (typeof this.assistantLoop.getWebhooksManager === "function") {
|
|
175786
|
-
return this.assistantLoop.getWebhooksManager();
|
|
175787
|
-
}
|
|
175788
|
-
return null;
|
|
175789
|
-
}
|
|
175790
|
-
getChannelsManager() {
|
|
175791
|
-
if (typeof this.assistantLoop.getChannelsManager === "function") {
|
|
175792
|
-
return this.assistantLoop.getChannelsManager();
|
|
175793
|
-
}
|
|
175794
|
-
return null;
|
|
175795
|
-
}
|
|
175796
|
-
getPeopleManager() {
|
|
175797
|
-
if (typeof this.assistantLoop.getPeopleManager === "function") {
|
|
175798
|
-
return this.assistantLoop.getPeopleManager();
|
|
175799
|
-
}
|
|
175800
|
-
return null;
|
|
175801
|
-
}
|
|
175802
|
-
getTelephonyManager() {
|
|
175803
|
-
if (typeof this.assistantLoop.getTelephonyManager === "function") {
|
|
175804
|
-
return this.assistantLoop.getTelephonyManager();
|
|
175805
|
-
}
|
|
175806
|
-
return null;
|
|
175807
|
-
}
|
|
175808
|
-
getWalletManager() {
|
|
175809
|
-
if (typeof this.assistantLoop.getWalletManager === "function") {
|
|
175810
|
-
return this.assistantLoop.getWalletManager();
|
|
175811
|
-
}
|
|
175812
|
-
return null;
|
|
175813
|
-
}
|
|
175814
|
-
getSecretsManager() {
|
|
175815
|
-
if (typeof this.assistantLoop.getSecretsManager === "function") {
|
|
175816
|
-
return this.assistantLoop.getSecretsManager();
|
|
175817
|
-
}
|
|
175818
|
-
return null;
|
|
175819
|
-
}
|
|
175820
|
-
getInboxManager() {
|
|
175821
|
-
if (typeof this.assistantLoop.getInboxManager === "function") {
|
|
175822
|
-
return this.assistantLoop.getInboxManager();
|
|
175823
|
-
}
|
|
175824
|
-
return null;
|
|
175825
|
-
}
|
|
175826
|
-
getActiveProjectId() {
|
|
175827
|
-
if (typeof this.assistantLoop.getActiveProjectId === "function") {
|
|
175828
|
-
return this.assistantLoop.getActiveProjectId();
|
|
175829
|
-
}
|
|
175830
|
-
return null;
|
|
175831
|
-
}
|
|
175832
|
-
setActiveProjectId(projectId) {
|
|
175833
|
-
if (typeof this.assistantLoop.setActiveProjectId === "function") {
|
|
175834
|
-
this.assistantLoop.setActiveProjectId(projectId);
|
|
175835
|
-
}
|
|
175836
|
-
}
|
|
175837
|
-
getSwarmCoordinator() {
|
|
175838
|
-
if (typeof this.assistantLoop.getOrCreateSwarmCoordinator === "function") {
|
|
175839
|
-
return this.assistantLoop.getOrCreateSwarmCoordinator();
|
|
175840
|
-
}
|
|
175841
|
-
return null;
|
|
175842
|
-
}
|
|
175843
|
-
getAssistantLoop() {
|
|
175844
|
-
return this.assistantLoop;
|
|
175845
|
-
}
|
|
175846
|
-
addSystemMessage(content) {
|
|
175847
|
-
if (typeof this.assistantLoop.addSystemMessage === "function") {
|
|
175848
|
-
this.assistantLoop.addSystemMessage(content);
|
|
175849
|
-
} else {
|
|
175850
|
-
const context = this.assistantLoop.getContext();
|
|
175851
|
-
if (typeof context.addSystemMessage === "function") {
|
|
175852
|
-
context.addSystemMessage(content);
|
|
175853
|
-
}
|
|
175854
|
-
}
|
|
175855
|
-
}
|
|
175856
|
-
clearConversation() {
|
|
175857
|
-
this.assistantLoop.clearConversation();
|
|
175858
|
-
this.messages = [];
|
|
175859
|
-
this.messageIds.clear();
|
|
175860
|
-
this.logger.info("Conversation cleared");
|
|
175861
|
-
}
|
|
175862
|
-
getCwd() {
|
|
175863
|
-
return this.cwd;
|
|
175864
|
-
}
|
|
175865
|
-
getStartedAt() {
|
|
175866
|
-
return this.startedAt;
|
|
175867
|
-
}
|
|
175868
|
-
getMessages() {
|
|
175869
|
-
return [...this.messages];
|
|
175870
|
-
}
|
|
175871
|
-
getQueueLength() {
|
|
175872
|
-
return this.messageQueue.length;
|
|
175873
|
-
}
|
|
175874
|
-
clearQueue() {
|
|
175875
|
-
this.messageQueue = [];
|
|
175876
|
-
this.logger.info("Message queue cleared");
|
|
175877
|
-
}
|
|
175878
|
-
mergeMessages(contextMessages) {
|
|
175879
|
-
if (contextMessages.length === 0)
|
|
175880
|
-
return;
|
|
175881
|
-
if (this.messages.length === 0 && this.messageIds.size === 0) {
|
|
175882
|
-
this.messages = [...contextMessages];
|
|
175883
|
-
this.messageIds = new Set(contextMessages.map((msg) => msg.id));
|
|
175884
|
-
return;
|
|
175885
|
-
}
|
|
175886
|
-
for (const msg of contextMessages) {
|
|
175887
|
-
if (!this.messageIds.has(msg.id)) {
|
|
175888
|
-
this.messages.push(msg);
|
|
175889
|
-
this.messageIds.add(msg.id);
|
|
175890
|
-
}
|
|
175891
|
-
}
|
|
175892
|
-
}
|
|
175893
|
-
selectContextSeed(messages) {
|
|
175894
|
-
if (messages.length === 0)
|
|
175895
|
-
return [];
|
|
175896
|
-
const contextInfo = typeof this.assistantLoop.getContextInfo === "function" ? this.assistantLoop.getContextInfo() : null;
|
|
175897
|
-
const maxMessages = contextInfo?.config?.maxMessages ?? 100;
|
|
175898
|
-
if (messages.length <= maxMessages)
|
|
175899
|
-
return messages;
|
|
175900
|
-
let startIndex = messages.length - maxMessages;
|
|
175901
|
-
if (startIndex > 0 && messages[startIndex]?.toolResults && messages[startIndex - 1]) {
|
|
175902
|
-
startIndex -= 1;
|
|
175903
|
-
}
|
|
175904
|
-
return messages.slice(Math.max(0, startIndex));
|
|
175905
|
-
}
|
|
175906
|
-
}
|
|
175907
|
-
var init_client4 = __esm(async () => {
|
|
175908
|
-
init_src2();
|
|
175909
|
-
await __promiseAll([
|
|
175910
|
-
init_loop(),
|
|
175911
|
-
init_logger2()
|
|
175912
|
-
]);
|
|
175913
|
-
});
|
|
175914
|
-
|
|
175915
176014
|
// packages/core/src/sessions/registry.ts
|
|
175916
176015
|
class SessionRegistry {
|
|
175917
176016
|
sessions = new Map;
|
|
@@ -180775,7 +180874,7 @@ class GlobalMemoryManager {
|
|
|
180775
180874
|
const result = this.db.prepare(`
|
|
180776
180875
|
DELETE FROM memories WHERE id IN (
|
|
180777
180876
|
SELECT id FROM memories
|
|
180778
|
-
ORDER BY importance ASC, accessed_at ASC
|
|
180877
|
+
ORDER BY importance ASC, (accessed_at IS NOT NULL) ASC, accessed_at ASC, created_at ASC
|
|
180779
180878
|
LIMIT ?
|
|
180780
180879
|
)
|
|
180781
180880
|
`).run(toRemove);
|
|
@@ -182563,6 +182662,7 @@ class AssistantLoop {
|
|
|
182563
182662
|
messagesManager = null;
|
|
182564
182663
|
webhooksManager = null;
|
|
182565
182664
|
channelsManager = null;
|
|
182665
|
+
channelAgentPool = null;
|
|
182566
182666
|
peopleManager = null;
|
|
182567
182667
|
telephonyManager = null;
|
|
182568
182668
|
memoryManager = null;
|
|
@@ -182807,6 +182907,7 @@ class AssistantLoop {
|
|
|
182807
182907
|
const assistantName = assistant?.name || "assistant";
|
|
182808
182908
|
this.channelsManager = createChannelsManager(assistantId, assistantName, this.config.channels);
|
|
182809
182909
|
registerChannelTools(this.toolRegistry, () => this.channelsManager);
|
|
182910
|
+
this.channelAgentPool = new ChannelAgentPool(this.cwd);
|
|
182810
182911
|
}
|
|
182811
182912
|
try {
|
|
182812
182913
|
this.peopleManager = await createPeopleManager();
|
|
@@ -183890,6 +183991,7 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
183890
183991
|
getMessagesManager: () => this.messagesManager,
|
|
183891
183992
|
getWebhooksManager: () => this.webhooksManager,
|
|
183892
183993
|
getChannelsManager: () => this.channelsManager,
|
|
183994
|
+
getChannelAgentPool: () => this.channelAgentPool,
|
|
183893
183995
|
getPeopleManager: () => this.peopleManager,
|
|
183894
183996
|
getTelephonyManager: () => this.telephonyManager,
|
|
183895
183997
|
getMemoryManager: () => this.memoryManager,
|
|
@@ -184140,6 +184242,8 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
184140
184242
|
this.voiceManager?.stopListening();
|
|
184141
184243
|
this.messagesManager?.stopWatching();
|
|
184142
184244
|
this.webhooksManager?.stopWatching();
|
|
184245
|
+
this.channelAgentPool?.shutdown();
|
|
184246
|
+
this.channelAgentPool = null;
|
|
184143
184247
|
this.channelsManager?.close();
|
|
184144
184248
|
this.channelsManager = null;
|
|
184145
184249
|
this.telephonyManager?.close();
|
|
@@ -184221,6 +184325,9 @@ You are running in **autonomous mode**. You manage your own wakeup schedule.
|
|
|
184221
184325
|
getChannelsManager() {
|
|
184222
184326
|
return this.channelsManager;
|
|
184223
184327
|
}
|
|
184328
|
+
getChannelAgentPool() {
|
|
184329
|
+
return this.channelAgentPool;
|
|
184330
|
+
}
|
|
184224
184331
|
getPeopleManager() {
|
|
184225
184332
|
return this.peopleManager;
|
|
184226
184333
|
}
|
|
@@ -186469,6 +186576,7 @@ __export(exports_src2, {
|
|
|
186469
186576
|
saveHistory: () => saveHistory,
|
|
186470
186577
|
resourceLimitsTool: () => resourceLimitsTool,
|
|
186471
186578
|
resolveTaskId: () => resolveTaskId,
|
|
186579
|
+
resolveNameToKnown: () => resolveNameToKnown,
|
|
186472
186580
|
resolveMentions: () => resolveMentions,
|
|
186473
186581
|
resolveHeartbeatPersistPath: () => resolveHeartbeatPersistPath,
|
|
186474
186582
|
resolveHeartbeatHistoryPath: () => resolveHeartbeatHistoryPath,
|
|
@@ -186896,6 +187004,7 @@ __export(exports_src2, {
|
|
|
186896
187004
|
CommandExecutor: () => CommandExecutor,
|
|
186897
187005
|
ChannelsManager: () => ChannelsManager,
|
|
186898
187006
|
ChannelStore: () => ChannelStore,
|
|
187007
|
+
ChannelAgentPool: () => ChannelAgentPool,
|
|
186899
187008
|
CapabilityStorage: () => CapabilityStorage,
|
|
186900
187009
|
CapabilityEnforcer: () => CapabilityEnforcer,
|
|
186901
187010
|
CallManager: () => CallManager,
|
|
@@ -206283,6 +206392,7 @@ var COMMANDS = [
|
|
|
206283
206392
|
{ name: "/memory", description: "show what AI remembers" },
|
|
206284
206393
|
{ name: "/context", description: "manage injected project context" },
|
|
206285
206394
|
{ name: "/hooks", description: "manage hooks (list, add, remove, test)" },
|
|
206395
|
+
{ name: "/onboarding", description: "rerun onboarding setup" },
|
|
206286
206396
|
{ name: "/projects", description: "manage projects in this folder" },
|
|
206287
206397
|
{ name: "/plans", description: "manage project plans" },
|
|
206288
206398
|
{ name: "/schedules", description: "manage scheduled commands" },
|
|
@@ -219649,6 +219759,9 @@ function ChannelsPanel({ manager, onClose, activePersonId, activePersonName, onP
|
|
|
219649
219759
|
}, undefined, true, undefined, this);
|
|
219650
219760
|
}
|
|
219651
219761
|
|
|
219762
|
+
// packages/terminal/src/components/App.tsx
|
|
219763
|
+
await init_src3();
|
|
219764
|
+
|
|
219652
219765
|
// packages/terminal/src/components/PeoplePanel.tsx
|
|
219653
219766
|
var import_react47 = __toESM(require_react(), 1);
|
|
219654
219767
|
var jsx_dev_runtime24 = __toESM(require_jsx_dev_runtime(), 1);
|
|
@@ -232081,6 +232194,10 @@ function App2({ cwd: cwd2, version: version3 }) {
|
|
|
232081
232194
|
setShowIdentityPanel(true);
|
|
232082
232195
|
return;
|
|
232083
232196
|
}
|
|
232197
|
+
if (cmdName === "onboarding" && !cmdArgs) {
|
|
232198
|
+
setShowOnboardingPanel(true);
|
|
232199
|
+
return;
|
|
232200
|
+
}
|
|
232084
232201
|
if (cmdName === "memory" && !cmdArgs) {
|
|
232085
232202
|
setMemoryError(null);
|
|
232086
232203
|
setShowMemoryPanel(true);
|
|
@@ -233573,10 +233690,29 @@ When done, report the result.`);
|
|
|
233573
233690
|
activePersonId: activeSession?.client.getPeopleManager?.()?.getActivePersonId?.() || undefined,
|
|
233574
233691
|
activePersonName: activeSession?.client.getPeopleManager?.()?.getActivePerson?.()?.name || undefined,
|
|
233575
233692
|
onPersonMessage: (channelName, personName, message) => {
|
|
233576
|
-
const
|
|
233693
|
+
const members = channelsManager.getMembers(channelName);
|
|
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");
|
|
233700
|
+
const mentions = parseMentions(message);
|
|
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);
|
|
233706
|
+
if (resolved.length > 0) {
|
|
233707
|
+
activeAssistantTargeted = resolved.some((r6) => r6.id === activeAssistantId);
|
|
233708
|
+
}
|
|
233709
|
+
}
|
|
233710
|
+
if (isActiveMember && activeAssistantTargeted) {
|
|
233711
|
+
const prompt = `[Channel Message] ${personName} posted in #${channelName}: "${message}"
|
|
233577
233712
|
|
|
233578
233713
|
Respond in #${channelName} using channel_send. Be helpful and conversational.`;
|
|
233579
|
-
|
|
233714
|
+
activeSession?.client.send(prompt);
|
|
233715
|
+
}
|
|
233580
233716
|
}
|
|
233581
233717
|
}, undefined, false, undefined, this);
|
|
233582
233718
|
}
|
|
@@ -234368,7 +234504,7 @@ Interactive Mode:
|
|
|
234368
234504
|
// packages/terminal/src/index.tsx
|
|
234369
234505
|
var jsx_dev_runtime44 = __toESM(require_jsx_dev_runtime(), 1);
|
|
234370
234506
|
setRuntime(bunRuntime);
|
|
234371
|
-
var VERSION4 = "1.1.
|
|
234507
|
+
var VERSION4 = "1.1.17";
|
|
234372
234508
|
var SYNC_START = "\x1B[?2026h";
|
|
234373
234509
|
var SYNC_END = "\x1B[?2026l";
|
|
234374
234510
|
function enableSynchronizedOutput() {
|
|
@@ -234508,4 +234644,4 @@ export {
|
|
|
234508
234644
|
main
|
|
234509
234645
|
};
|
|
234510
234646
|
|
|
234511
|
-
//# debugId=
|
|
234647
|
+
//# debugId=06504F1621F0D4C464756E2164756E21
|