@whoz-oss/coday-web 0.18.4 → 0.18.6
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/package.json +1 -1
- package/server/server.js +78 -21
- package/server/server.js.map +2 -2
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -69230,7 +69230,21 @@ var AiThread = class _AiThread {
|
|
|
69230
69230
|
const cleanedMessages2 = this.cleanToolRequestResponseConsistency([...this.messages]);
|
|
69231
69231
|
return { messages: cleanedMessages2, compacted: false };
|
|
69232
69232
|
}
|
|
69233
|
-
|
|
69233
|
+
const maxSingleMessageSize = Math.floor(maxChars * 0.5);
|
|
69234
|
+
const filteredMessages = this.messages.map((msg) => {
|
|
69235
|
+
if (msg instanceof ToolResponseEvent && msg.length > maxSingleMessageSize) {
|
|
69236
|
+
const truncateAt = Math.floor(maxChars * 0.15);
|
|
69237
|
+
const output = msg.getTextOutput();
|
|
69238
|
+
const truncated = `[... truncated ${msg.length - truncateAt} chars]
|
|
69239
|
+
` + output.slice(-truncateAt);
|
|
69240
|
+
return new ToolResponseEvent({
|
|
69241
|
+
...msg,
|
|
69242
|
+
output: truncated
|
|
69243
|
+
});
|
|
69244
|
+
}
|
|
69245
|
+
return msg;
|
|
69246
|
+
});
|
|
69247
|
+
let { messages, overflow } = partition(filteredMessages.toReversed(), maxChars);
|
|
69234
69248
|
messages = this.cleanToolRequestResponseConsistency(messages.toReversed());
|
|
69235
69249
|
overflow = this.cleanToolRequestResponseConsistency(overflow.toReversed());
|
|
69236
69250
|
if (!compactor) {
|
|
@@ -69238,10 +69252,15 @@ var AiThread = class _AiThread {
|
|
|
69238
69252
|
return { messages: this.messages, compacted: true };
|
|
69239
69253
|
}
|
|
69240
69254
|
let summary;
|
|
69241
|
-
|
|
69242
|
-
|
|
69243
|
-
|
|
69244
|
-
|
|
69255
|
+
try {
|
|
69256
|
+
while (overflow.length) {
|
|
69257
|
+
const overflowPartition = partition(overflow, maxChars);
|
|
69258
|
+
summary = await compactor(overflowPartition.messages);
|
|
69259
|
+
overflow = overflowPartition.overflow.length ? [summary, ...overflowPartition.overflow] : [];
|
|
69260
|
+
}
|
|
69261
|
+
} catch (error) {
|
|
69262
|
+
console.error("[AiThread] Compaction failed, keeping recent messages only:", error);
|
|
69263
|
+
summary = void 0;
|
|
69245
69264
|
}
|
|
69246
69265
|
const cleanedMessages = this.cleanToolRequestResponseConsistency(messages);
|
|
69247
69266
|
this.messages = summary ? [summary, ...cleanedMessages] : cleanedMessages;
|
|
@@ -69567,6 +69586,7 @@ var AiThreadService = class {
|
|
|
69567
69586
|
this.username = userService.username;
|
|
69568
69587
|
}
|
|
69569
69588
|
activeThread$ = new import_rxjs2.BehaviorSubject(null);
|
|
69589
|
+
isKilled = false;
|
|
69570
69590
|
/**
|
|
69571
69591
|
* Observable of the currently active thread.
|
|
69572
69592
|
* Emits whenever the active thread changes.
|
|
@@ -69574,6 +69594,7 @@ var AiThreadService = class {
|
|
|
69574
69594
|
activeThread = this.activeThread$.asObservable();
|
|
69575
69595
|
username;
|
|
69576
69596
|
async kill() {
|
|
69597
|
+
this.isKilled = true;
|
|
69577
69598
|
this.activeThread$.complete();
|
|
69578
69599
|
}
|
|
69579
69600
|
/**
|
|
@@ -69664,16 +69685,24 @@ var AiThreadService = class {
|
|
|
69664
69685
|
this.activeThread$.next(saved);
|
|
69665
69686
|
}
|
|
69666
69687
|
async autoSave(newName) {
|
|
69688
|
+
if (this.isKilled) {
|
|
69689
|
+
console.log("Autosave skipped: service has been killed");
|
|
69690
|
+
return;
|
|
69691
|
+
}
|
|
69667
69692
|
const thread = this.activeThread$.value;
|
|
69668
69693
|
if (!thread || thread.messagesLength == 0) {
|
|
69669
|
-
console.
|
|
69694
|
+
console.log(`Autosave of an empty or falsy thread aborted, threadId: ${thread?.id}`);
|
|
69670
69695
|
return;
|
|
69671
69696
|
}
|
|
69672
|
-
|
|
69673
|
-
|
|
69697
|
+
try {
|
|
69698
|
+
if (newName) {
|
|
69699
|
+
thread.name = newName;
|
|
69700
|
+
}
|
|
69701
|
+
const repository = await this.getRepository();
|
|
69702
|
+
await repository.save(thread);
|
|
69703
|
+
} catch (error) {
|
|
69704
|
+
console.log("Autosave failed (service may have been killed):", error instanceof Error ? error.message : error);
|
|
69674
69705
|
}
|
|
69675
|
-
const repository = await this.getRepository();
|
|
69676
|
-
await repository.save(thread);
|
|
69677
69706
|
}
|
|
69678
69707
|
/**
|
|
69679
69708
|
* Truncate the current thread at a specific user message
|
|
@@ -97819,7 +97848,9 @@ var OpenaiClient = class _OpenaiClient extends AiClient {
|
|
|
97819
97848
|
}
|
|
97820
97849
|
const outputSubject = new import_rxjs9.Subject();
|
|
97821
97850
|
const thinking = setInterval(() => this.interactor.thinking(), this.thinkingInterval);
|
|
97822
|
-
this.processThread(openai, agent, model, thread, outputSubject).
|
|
97851
|
+
this.processThread(openai, agent, model, thread, outputSubject).catch((reason) => {
|
|
97852
|
+
outputSubject.next(new ErrorEvent({ error: reason }));
|
|
97853
|
+
}).finally(() => {
|
|
97823
97854
|
clearInterval(thinking);
|
|
97824
97855
|
this.showAgentAndUsage(agent, this.aiProviderConfig.name, model.name, thread);
|
|
97825
97856
|
const cost = thread.usage?.price || 0;
|
|
@@ -102146,7 +102177,9 @@ var AnthropicClient = class extends AiClient {
|
|
|
102146
102177
|
thread.resetUsageForRun();
|
|
102147
102178
|
const outputSubject = new import_rxjs10.Subject();
|
|
102148
102179
|
const thinking = setInterval(() => this.interactor.thinking(), this.thinkingInterval);
|
|
102149
|
-
this.processThread(anthropic, agent, model, thread, outputSubject).
|
|
102180
|
+
this.processThread(anthropic, agent, model, thread, outputSubject).catch((reason) => {
|
|
102181
|
+
outputSubject.next(new ErrorEvent({ error: reason }));
|
|
102182
|
+
}).finally(() => {
|
|
102150
102183
|
clearInterval(thinking);
|
|
102151
102184
|
this.showAgentAndUsage(agent, "Anthropic", model.name, thread);
|
|
102152
102185
|
const cost = thread.usage?.price || 0;
|
|
@@ -114313,7 +114346,7 @@ function isElectron() {
|
|
|
114313
114346
|
|
|
114314
114347
|
// libs/integration/mcp/mcp-tools-factory.ts
|
|
114315
114348
|
var import_child_process4 = require("child_process");
|
|
114316
|
-
var MCP_CONNECT_TIMEOUT =
|
|
114349
|
+
var MCP_CONNECT_TIMEOUT = 15e3;
|
|
114317
114350
|
var McpToolsFactory = class extends AssistantToolFactory {
|
|
114318
114351
|
constructor(interactor, serverConfig) {
|
|
114319
114352
|
super(interactor);
|
|
@@ -116489,9 +116522,12 @@ var ServerClient = class _ServerClient {
|
|
|
116489
116522
|
// Filter out falsy values and type guard
|
|
116490
116523
|
(0, import_rxjs14.first)(),
|
|
116491
116524
|
// Take the first truthy value and complete
|
|
116492
|
-
(0, import_rxjs14.timeout)(
|
|
116493
|
-
//
|
|
116494
|
-
(0, import_rxjs14.catchError)(() =>
|
|
116525
|
+
(0, import_rxjs14.timeout)(1e4),
|
|
116526
|
+
// Increased timeout to 10 seconds for slower operations
|
|
116527
|
+
(0, import_rxjs14.catchError)((error) => {
|
|
116528
|
+
debugLog("CLIENT", `getThreadId timeout or error for client ${this.clientId}:`, error.message);
|
|
116529
|
+
return (0, import_rxjs14.of)(void 0);
|
|
116530
|
+
})
|
|
116495
116531
|
// Return undefined on timeout or error
|
|
116496
116532
|
);
|
|
116497
116533
|
}
|
|
@@ -122173,22 +122209,32 @@ app.post("/api/webhook/:uuid", async (req, res) => {
|
|
|
122173
122209
|
clientId
|
|
122174
122210
|
});
|
|
122175
122211
|
console.error("Error waiting for webhook completion:", error);
|
|
122176
|
-
res.
|
|
122212
|
+
if (!res.headersSent) {
|
|
122213
|
+
res.status(500).send({ error: "Webhook processing failed" });
|
|
122214
|
+
}
|
|
122177
122215
|
});
|
|
122178
122216
|
} else {
|
|
122179
122217
|
(0, import_rxjs16.firstValueFrom)(
|
|
122180
122218
|
threadIdSource.pipe(
|
|
122181
|
-
(0, import_rxjs16.timeout)(
|
|
122219
|
+
(0, import_rxjs16.timeout)(1e4),
|
|
122220
|
+
// Increased timeout to 10 seconds
|
|
122182
122221
|
(0, import_rxjs16.catchError)((error) => {
|
|
122183
122222
|
if (error.message === "no elements in sequence" || error.constructor?.name === "EmptyErrorImpl") {
|
|
122184
122223
|
console.log("Thread ID Observable empty during system sleep - webhook will continue");
|
|
122185
122224
|
return (0, import_rxjs16.of)("unknown");
|
|
122186
122225
|
}
|
|
122187
|
-
|
|
122226
|
+
if (error.name === "TimeoutError") {
|
|
122227
|
+
console.log("Thread ID timeout - webhook will continue with unknown ID");
|
|
122228
|
+
return (0, import_rxjs16.of)("unknown");
|
|
122229
|
+
}
|
|
122230
|
+
console.error("Error in thread ID observable:", error);
|
|
122231
|
+
return (0, import_rxjs16.of)("unknown");
|
|
122188
122232
|
})
|
|
122189
122233
|
)
|
|
122190
122234
|
).then((threadId) => {
|
|
122191
|
-
res.
|
|
122235
|
+
if (!res.headersSent) {
|
|
122236
|
+
res.status(201).send({ threadId });
|
|
122237
|
+
}
|
|
122192
122238
|
}).catch((error) => {
|
|
122193
122239
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
122194
122240
|
logger.logWebhookError({
|
|
@@ -122198,7 +122244,9 @@ app.post("/api/webhook/:uuid", async (req, res) => {
|
|
|
122198
122244
|
clientId
|
|
122199
122245
|
});
|
|
122200
122246
|
console.error("Error getting thread ID for webhook:", error);
|
|
122201
|
-
res.
|
|
122247
|
+
if (!res.headersSent) {
|
|
122248
|
+
res.status(500).send({ error: "Failed to initialize webhook processing" });
|
|
122249
|
+
}
|
|
122202
122250
|
});
|
|
122203
122251
|
}
|
|
122204
122252
|
} catch (error) {
|
|
@@ -122496,7 +122544,16 @@ process.on("unhandledRejection", (reason, promise) => {
|
|
|
122496
122544
|
console.log("Detected RxJS EmptyError rejection during system sleep - this is expected behavior");
|
|
122497
122545
|
return;
|
|
122498
122546
|
}
|
|
122547
|
+
if (error.name === "TimeoutError" || error.message?.includes("timeout")) {
|
|
122548
|
+
console.log("Detected timeout error - handling gracefully without shutdown");
|
|
122549
|
+
return;
|
|
122550
|
+
}
|
|
122551
|
+
if (error.name === "AbortError" || error.message?.includes("aborted")) {
|
|
122552
|
+
console.log("Detected abort error - handling gracefully without shutdown");
|
|
122553
|
+
return;
|
|
122554
|
+
}
|
|
122499
122555
|
}
|
|
122556
|
+
console.error("Critical unhandled rejection detected");
|
|
122500
122557
|
if (!isShuttingDown) {
|
|
122501
122558
|
gracefulShutdown("unhandledRejection");
|
|
122502
122559
|
}
|