openloops 0.7.6 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -11
- package/README.md +5 -8
- package/dist/clients/llm/llm-error.d.ts +1 -1
- package/dist/clients/llm/llm-error.js +12 -0
- package/dist/clients/llm/llm-error.mjs +12 -0
- package/dist/common/error/error-reporter.d.ts +11 -0
- package/dist/common/error/error-reporter.js +36 -0
- package/dist/common/error/error-reporter.mjs +11 -0
- package/dist/common/error/index.d.ts +1 -0
- package/dist/common/error/index.js +3 -1
- package/dist/common/error/index.mjs +1 -0
- package/dist/common/error/reportError.js +10 -0
- package/dist/common/error/reportError.mjs +10 -0
- package/dist/common/error/sentry-client.d.ts +2 -2
- package/dist/common/error/sentry-client.js +19 -24
- package/dist/common/error/sentry-client.mjs +19 -14
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +3 -1
- package/dist/common/helpers/index.mjs +1 -0
- package/dist/common/helpers/sanitize-string.js +5 -15
- package/dist/common/helpers/sanitize-string.mjs +5 -5
- package/dist/common/helpers/strip-blocks.d.ts +1 -0
- package/dist/common/helpers/strip-blocks.js +45 -0
- package/dist/common/helpers/strip-blocks.mjs +21 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +9 -0
- package/dist/common/index.mjs +4 -0
- package/dist/common/logger/pino.js +12 -3
- package/dist/common/logger/pino.mjs +12 -3
- package/dist/common/repositories/mongo-db.client.js +1 -1
- package/dist/common/repositories/mongo-db.client.mjs +1 -1
- package/dist/common/repositories/mongo-db.repository.js +1 -1
- package/dist/common/repositories/mongo-db.repository.mjs +1 -1
- package/dist/common/utils/secret-manager.js +1 -1
- package/dist/common/utils/secret-manager.mjs +1 -1
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +3 -1
- package/dist/db/index.mjs +1 -0
- package/dist/db/migrations/chat-titles.d.ts +10 -0
- package/dist/db/migrations/chat-titles.js +55 -0
- package/dist/db/migrations/chat-titles.mjs +31 -0
- package/dist/harness/agent-state.d.ts +0 -1
- package/dist/harness/agent.d.ts +1 -0
- package/dist/harness/agent.js +9 -0
- package/dist/harness/agent.mjs +9 -0
- package/dist/loops/agi/loop.js +4 -2
- package/dist/loops/agi/loop.mjs +4 -2
- package/dist/loops/shared/skills/fast-responder.d.ts +1 -0
- package/dist/loops/shared/skills/fast-responder.js +4 -2
- package/dist/loops/shared/skills/fast-responder.mjs +4 -2
- package/dist/services/automations/runner/automation-runner.js +6 -1
- package/dist/services/automations/runner/automation-runner.mjs +6 -1
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +2 -1
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +2 -2
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +2 -2
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +1 -0
- package/dist/services/automations/use-cases/sync-automation-run.use-case.js +6 -2
- package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +5 -2
- package/dist/services/chats/entities/chat.entity.d.ts +3 -0
- package/dist/services/chats/entities/chat.entity.js +8 -0
- package/dist/services/chats/entities/chat.entity.mjs +8 -0
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +1 -5
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +1 -5
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +2 -1
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +3 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +3 -2
- package/dist/services/chats/utils/title.d.ts +2 -0
- package/dist/services/chats/utils/title.js +37 -0
- package/dist/services/chats/utils/title.mjs +12 -0
- package/dist/tools/core/fetch-url/html-to-text.js +3 -20
- package/dist/tools/core/fetch-url/html-to-text.mjs +3 -20
- package/docs/README.md +2 -1
- package/docs/agent.md +20 -3
- package/docs/automations.md +3 -3
- package/docs/chats.md +41 -8
- package/docs/configuration.md +6 -2
- package/docs/error-reporting.md +219 -0
- package/docs/integration-guide.md +6 -2
- package/docs/llms.txt +2 -1
- package/docs/loops.md +1 -1
- package/examples/chats/search-chats.ts +30 -0
- package/examples/errors/error-reporting.ts +75 -0
- package/package.json +23 -12
- package/dist/services/chats/utils/deprecated-activity.d.ts +0 -1
- package/dist/services/chats/utils/deprecated-activity.js +0 -60
- package/dist/services/chats/utils/deprecated-activity.mjs +0 -36
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var strip_blocks_exports = {};
|
|
20
|
+
__export(strip_blocks_exports, {
|
|
21
|
+
stripBlocks: () => stripBlocks
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(strip_blocks_exports);
|
|
24
|
+
function asciiLower(text) {
|
|
25
|
+
return text.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
|
|
26
|
+
}
|
|
27
|
+
function stripBlocks(html, open, close, end, isElement) {
|
|
28
|
+
const lower = asciiLower(html);
|
|
29
|
+
let result = "";
|
|
30
|
+
let cursor = 0;
|
|
31
|
+
while (cursor < html.length) {
|
|
32
|
+
let start = lower.indexOf(open, cursor);
|
|
33
|
+
while (isElement && start !== -1 && /[a-z0-9]/.test(lower.charAt(start + open.length))) start = lower.indexOf(open, start + 1);
|
|
34
|
+
if (start === -1) break;
|
|
35
|
+
result += html.slice(cursor, start);
|
|
36
|
+
const closing = lower.indexOf(close, start + open.length);
|
|
37
|
+
const stop = closing === -1 ? -1 : lower.indexOf(end, closing);
|
|
38
|
+
cursor = stop === -1 ? html.length : stop + end.length;
|
|
39
|
+
}
|
|
40
|
+
return result + html.slice(cursor);
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
stripBlocks
|
|
45
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function asciiLower(text) {
|
|
2
|
+
return text.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
|
|
3
|
+
}
|
|
4
|
+
function stripBlocks(html, open, close, end, isElement) {
|
|
5
|
+
const lower = asciiLower(html);
|
|
6
|
+
let result = "";
|
|
7
|
+
let cursor = 0;
|
|
8
|
+
while (cursor < html.length) {
|
|
9
|
+
let start = lower.indexOf(open, cursor);
|
|
10
|
+
while (isElement && start !== -1 && /[a-z0-9]/.test(lower.charAt(start + open.length))) start = lower.indexOf(open, start + 1);
|
|
11
|
+
if (start === -1) break;
|
|
12
|
+
result += html.slice(cursor, start);
|
|
13
|
+
const closing = lower.indexOf(close, start + open.length);
|
|
14
|
+
const stop = closing === -1 ? -1 : lower.indexOf(end, closing);
|
|
15
|
+
cursor = stop === -1 ? html.length : stop + end.length;
|
|
16
|
+
}
|
|
17
|
+
return result + html.slice(cursor);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
stripBlocks
|
|
21
|
+
};
|
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,9 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
20
|
var common_exports = {};
|
|
21
|
+
__export(common_exports, {
|
|
22
|
+
setErrorReporter: () => import_error_reporter.setErrorReporter
|
|
23
|
+
});
|
|
17
24
|
module.exports = __toCommonJS(common_exports);
|
|
18
25
|
__reExport(common_exports, require("./logger"), module.exports);
|
|
26
|
+
var import_error_reporter = require("./error/error-reporter");
|
|
19
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
28
|
0 && (module.exports = {
|
|
29
|
+
setErrorReporter,
|
|
21
30
|
...require("./logger")
|
|
22
31
|
});
|
package/dist/common/index.mjs
CHANGED
|
@@ -34,11 +34,20 @@ __export(pino_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(pino_exports);
|
|
35
35
|
var import_config = require("dotenv/config");
|
|
36
36
|
var import_pino = __toESM(require("pino"));
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let prettyStream;
|
|
38
|
+
function localStream() {
|
|
39
|
+
if (prettyStream === void 0) {
|
|
40
|
+
try {
|
|
41
|
+
prettyStream = require("pino-pretty")({ colorize: true });
|
|
42
|
+
} catch {
|
|
43
|
+
prettyStream = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return prettyStream ?? void 0;
|
|
47
|
+
}
|
|
39
48
|
class Logger {
|
|
40
49
|
IS_LOCAL = process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development";
|
|
41
|
-
logger = this.IS_LOCAL ? (0, import_pino.default)({ level: "debug" },
|
|
50
|
+
logger = this.IS_LOCAL ? (0, import_pino.default)({ level: "debug" }, localStream()) : (0, import_pino.default)({ level: "info" });
|
|
42
51
|
log(level, obj, msg) {
|
|
43
52
|
if (typeof obj === "string") {
|
|
44
53
|
msg = obj;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import pino from "pino";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
let prettyStream;
|
|
4
|
+
function localStream() {
|
|
5
|
+
if (prettyStream === void 0) {
|
|
6
|
+
try {
|
|
7
|
+
prettyStream = require("pino-pretty")({ colorize: true });
|
|
8
|
+
} catch {
|
|
9
|
+
prettyStream = null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return prettyStream ?? void 0;
|
|
13
|
+
}
|
|
5
14
|
class Logger {
|
|
6
15
|
IS_LOCAL = process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development";
|
|
7
|
-
logger = this.IS_LOCAL ? pino({ level: "debug" },
|
|
16
|
+
logger = this.IS_LOCAL ? pino({ level: "debug" }, localStream()) : pino({ level: "info" });
|
|
8
17
|
log(level, obj, msg) {
|
|
9
18
|
if (typeof obj === "string") {
|
|
10
19
|
msg = obj;
|
|
@@ -59,7 +59,7 @@ class MongoClient {
|
|
|
59
59
|
await this.connect();
|
|
60
60
|
} catch (error) {
|
|
61
61
|
this.logger.error("[Mongo Client]: Error connecting to MongoDB");
|
|
62
|
-
await (0, import_error.reportError)(`Error connecting to MongoDB: ${error.message}`, { error });
|
|
62
|
+
await (0, import_error.reportError)(`Error connecting to MongoDB: ${error.message}`, { source: "mongo", error });
|
|
63
63
|
throw error;
|
|
64
64
|
}
|
|
65
65
|
return this.client.db(dbName, options);
|
|
@@ -37,7 +37,7 @@ class MongoClient {
|
|
|
37
37
|
await this.connect();
|
|
38
38
|
} catch (error) {
|
|
39
39
|
this.logger.error("[Mongo Client]: Error connecting to MongoDB");
|
|
40
|
-
await reportError(`Error connecting to MongoDB: ${error.message}`, { error });
|
|
40
|
+
await reportError(`Error connecting to MongoDB: ${error.message}`, { source: "mongo", error });
|
|
41
41
|
throw error;
|
|
42
42
|
}
|
|
43
43
|
return this.client.db(dbName, options);
|
|
@@ -44,7 +44,7 @@ class MongoRepository {
|
|
|
44
44
|
scoped;
|
|
45
45
|
ownerField;
|
|
46
46
|
protectedFields;
|
|
47
|
-
report = import_error.reportError;
|
|
47
|
+
report = (error) => (0, import_error.reportError)(error, { source: "mongo", collection: this.collection });
|
|
48
48
|
constructor(props) {
|
|
49
49
|
const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
|
|
50
50
|
if (!database) throw new Error("[Mongo Repository] Database name is required");
|
|
@@ -20,7 +20,7 @@ class MongoRepository {
|
|
|
20
20
|
scoped;
|
|
21
21
|
ownerField;
|
|
22
22
|
protectedFields;
|
|
23
|
-
report = reportError;
|
|
23
|
+
report = (error) => reportError(error, { source: "mongo", collection: this.collection });
|
|
24
24
|
constructor(props) {
|
|
25
25
|
const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
|
|
26
26
|
if (!database) throw new Error("[Mongo Repository] Database name is required");
|
|
@@ -52,7 +52,7 @@ class SecretManager {
|
|
|
52
52
|
constructor() {
|
|
53
53
|
const secretKey = process.env.SECRET_MANAGER_KEY;
|
|
54
54
|
if (!secretKey) {
|
|
55
|
-
throw new Error("[Secret manager]
|
|
55
|
+
throw new Error("[Secret manager] SECRET_MANAGER_KEY environment variable is not set");
|
|
56
56
|
}
|
|
57
57
|
this.cryptr = new import_cryptr.default(secretKey, {
|
|
58
58
|
pbkdf2Iterations: 1e3,
|
|
@@ -18,7 +18,7 @@ class SecretManager {
|
|
|
18
18
|
constructor() {
|
|
19
19
|
const secretKey = process.env.SECRET_MANAGER_KEY;
|
|
20
20
|
if (!secretKey) {
|
|
21
|
-
throw new Error("[Secret manager]
|
|
21
|
+
throw new Error("[Secret manager] SECRET_MANAGER_KEY environment variable is not set");
|
|
22
22
|
}
|
|
23
23
|
this.cryptr = new Cryptr(secretKey, {
|
|
24
24
|
pbkdf2Iterations: 1e3,
|
package/dist/db/index.d.ts
CHANGED
package/dist/db/index.js
CHANGED
|
@@ -17,8 +17,10 @@ var db_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(db_exports);
|
|
18
18
|
__reExport(db_exports, require("./indexes"), module.exports);
|
|
19
19
|
__reExport(db_exports, require("./migrations/automations"), module.exports);
|
|
20
|
+
__reExport(db_exports, require("./migrations/chat-titles"), module.exports);
|
|
20
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
22
|
0 && (module.exports = {
|
|
22
23
|
...require("./indexes"),
|
|
23
|
-
...require("./migrations/automations")
|
|
24
|
+
...require("./migrations/automations"),
|
|
25
|
+
...require("./migrations/chat-titles")
|
|
24
26
|
});
|
package/dist/db/index.mjs
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
export interface ChatTitlesMigrationOptions {
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ChatTitlesMigrationReport {
|
|
6
|
+
dryRun: boolean;
|
|
7
|
+
titled: number;
|
|
8
|
+
skipped: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function migrateChatTitles(db: Db, options?: ChatTitlesMigrationOptions): Promise<ChatTitlesMigrationReport>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var chat_titles_exports = {};
|
|
20
|
+
__export(chat_titles_exports, {
|
|
21
|
+
migrateChatTitles: () => migrateChatTitles
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chat_titles_exports);
|
|
24
|
+
var import_title = require("../../services/chats/utils/title");
|
|
25
|
+
const BATCH_SIZE = 500;
|
|
26
|
+
const withoutTitle = { $or: [{ title: { $exists: false } }, { title: null }, { title: "" }] };
|
|
27
|
+
const firstUserMessage = { role: "user", source: { $ne: "harness" }, excludeFromContext: { $ne: true } };
|
|
28
|
+
async function migrateChatTitles(db, options = {}) {
|
|
29
|
+
const dryRun = Boolean(options.dryRun);
|
|
30
|
+
const report = { dryRun, titled: 0, skipped: 0 };
|
|
31
|
+
const chats = db.collection("chats");
|
|
32
|
+
let operations = [];
|
|
33
|
+
const flush = async () => {
|
|
34
|
+
if (!operations.length) return;
|
|
35
|
+
if (!dryRun) await chats.bulkWrite(operations, { ordered: false });
|
|
36
|
+
operations = [];
|
|
37
|
+
};
|
|
38
|
+
const cursor = chats.find({ ...withoutTitle, deletedAt: null }, { projection: { messages: { $elemMatch: firstUserMessage } } });
|
|
39
|
+
for await (const chat of cursor) {
|
|
40
|
+
const title = (0, import_title.normalizeTitle)(chat.messages?.[0]?.content);
|
|
41
|
+
if (!title) {
|
|
42
|
+
report.skipped++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
report.titled++;
|
|
46
|
+
operations.push({ updateOne: { filter: { _id: chat._id, ...withoutTitle }, update: { $set: { title } } } });
|
|
47
|
+
if (operations.length >= BATCH_SIZE) await flush();
|
|
48
|
+
}
|
|
49
|
+
await flush();
|
|
50
|
+
return report;
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
migrateChatTitles
|
|
55
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { normalizeTitle } from "../../services/chats/utils/title";
|
|
2
|
+
const BATCH_SIZE = 500;
|
|
3
|
+
const withoutTitle = { $or: [{ title: { $exists: false } }, { title: null }, { title: "" }] };
|
|
4
|
+
const firstUserMessage = { role: "user", source: { $ne: "harness" }, excludeFromContext: { $ne: true } };
|
|
5
|
+
async function migrateChatTitles(db, options = {}) {
|
|
6
|
+
const dryRun = Boolean(options.dryRun);
|
|
7
|
+
const report = { dryRun, titled: 0, skipped: 0 };
|
|
8
|
+
const chats = db.collection("chats");
|
|
9
|
+
let operations = [];
|
|
10
|
+
const flush = async () => {
|
|
11
|
+
if (!operations.length) return;
|
|
12
|
+
if (!dryRun) await chats.bulkWrite(operations, { ordered: false });
|
|
13
|
+
operations = [];
|
|
14
|
+
};
|
|
15
|
+
const cursor = chats.find({ ...withoutTitle, deletedAt: null }, { projection: { messages: { $elemMatch: firstUserMessage } } });
|
|
16
|
+
for await (const chat of cursor) {
|
|
17
|
+
const title = normalizeTitle(chat.messages?.[0]?.content);
|
|
18
|
+
if (!title) {
|
|
19
|
+
report.skipped++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
report.titled++;
|
|
23
|
+
operations.push({ updateOne: { filter: { _id: chat._id, ...withoutTitle }, update: { $set: { title } } } });
|
|
24
|
+
if (operations.length >= BATCH_SIZE) await flush();
|
|
25
|
+
}
|
|
26
|
+
await flush();
|
|
27
|
+
return report;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
migrateChatTitles
|
|
31
|
+
};
|
package/dist/harness/agent.d.ts
CHANGED
package/dist/harness/agent.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(agent_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(agent_exports);
|
|
25
25
|
var import_mongodb = require("mongodb");
|
|
26
26
|
var import_logger = require("../common/logger/index.js");
|
|
27
|
+
var import_error = require("../common/error/index.js");
|
|
27
28
|
var import_entities = require("../services/mcp-servers/entities/index.js");
|
|
28
29
|
var import_chats = require("../services/chats/index.js");
|
|
29
30
|
var import_chat = require("../services/chats/entities/chat.entity.js");
|
|
@@ -191,6 +192,7 @@ class Agent {
|
|
|
191
192
|
const llmError = error instanceof import_llm_error.LLMError ? error : void 0;
|
|
192
193
|
const reported = llmError?.userMessage ?? message;
|
|
193
194
|
await this.failRun(reported, llmError);
|
|
195
|
+
await this.reportFailure(error, llmError ? { code: llmError.code } : {});
|
|
194
196
|
return { data: this.currentChat?._id ? this.currentChat : void 0, error: reported };
|
|
195
197
|
}
|
|
196
198
|
}
|
|
@@ -221,6 +223,7 @@ class Agent {
|
|
|
221
223
|
listener(activity);
|
|
222
224
|
} catch (error) {
|
|
223
225
|
this.logger.warn({ error: error?.message ?? error }, "[AGENT] An activity listener failed");
|
|
226
|
+
void this.reportFailure(error, { listener: "activity" });
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
}
|
|
@@ -294,6 +297,7 @@ class Agent {
|
|
|
294
297
|
result = await guard.run(context);
|
|
295
298
|
} catch (error) {
|
|
296
299
|
this.logger.error({ error: error?.message ?? error, guard: guard.name }, "[AGENT] Guard failed");
|
|
300
|
+
await this.reportFailure(error, { stage: "guard", guard: guard.name });
|
|
297
301
|
failed = true;
|
|
298
302
|
result = { passed: false, reason: `Guard failed: ${error?.message ?? error}` };
|
|
299
303
|
}
|
|
@@ -378,6 +382,9 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
378
382
|
await this.persist();
|
|
379
383
|
await this.disconnectMcpServers();
|
|
380
384
|
}
|
|
385
|
+
async reportFailure(error, details = {}) {
|
|
386
|
+
await (0, import_error.reportError)(error, { source: "agent", chatId: this.currentChat?._id?.toString(), userId: this.currentUser?.userId, ...details });
|
|
387
|
+
}
|
|
381
388
|
async failRun(message, llmError) {
|
|
382
389
|
try {
|
|
383
390
|
this.currentChat.state?.setStatus(import_agent_state.AgentStatus.FAILED);
|
|
@@ -387,6 +394,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
387
394
|
await this.persist();
|
|
388
395
|
} catch (saveError) {
|
|
389
396
|
this.logger.error({ error: saveError?.message ?? saveError }, "[AGENT] Failed to persist failed run state");
|
|
397
|
+
await this.reportFailure(saveError, { stage: "persist" });
|
|
390
398
|
} finally {
|
|
391
399
|
await this.disconnectMcpServers();
|
|
392
400
|
}
|
|
@@ -474,6 +482,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
474
482
|
});
|
|
475
483
|
} catch (error) {
|
|
476
484
|
this.logger.error({ error: error?.message ?? error }, "[AGENT] Failed to persist traces");
|
|
485
|
+
await this.reportFailure(error, { stage: "traces" });
|
|
477
486
|
}
|
|
478
487
|
}
|
|
479
488
|
async persist(props) {
|
package/dist/harness/agent.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ObjectId } from "mongodb";
|
|
2
2
|
import { Logger } from "../common/logger/index.js";
|
|
3
|
+
import { reportError } from "../common/error/index.js";
|
|
3
4
|
import { McpServer, needsUserReview } from "../services/mcp-servers/entities/index.js";
|
|
4
5
|
import { createChat, updateChat, getChatById } from "../services/chats/index.js";
|
|
5
6
|
import { Chat } from "../services/chats/entities/chat.entity.js";
|
|
@@ -175,6 +176,7 @@ class Agent {
|
|
|
175
176
|
const llmError = error instanceof LLMError ? error : void 0;
|
|
176
177
|
const reported = llmError?.userMessage ?? message;
|
|
177
178
|
await this.failRun(reported, llmError);
|
|
179
|
+
await this.reportFailure(error, llmError ? { code: llmError.code } : {});
|
|
178
180
|
return { data: this.currentChat?._id ? this.currentChat : void 0, error: reported };
|
|
179
181
|
}
|
|
180
182
|
}
|
|
@@ -205,6 +207,7 @@ class Agent {
|
|
|
205
207
|
listener(activity);
|
|
206
208
|
} catch (error) {
|
|
207
209
|
this.logger.warn({ error: error?.message ?? error }, "[AGENT] An activity listener failed");
|
|
210
|
+
void this.reportFailure(error, { listener: "activity" });
|
|
208
211
|
}
|
|
209
212
|
}
|
|
210
213
|
}
|
|
@@ -278,6 +281,7 @@ class Agent {
|
|
|
278
281
|
result = await guard.run(context);
|
|
279
282
|
} catch (error) {
|
|
280
283
|
this.logger.error({ error: error?.message ?? error, guard: guard.name }, "[AGENT] Guard failed");
|
|
284
|
+
await this.reportFailure(error, { stage: "guard", guard: guard.name });
|
|
281
285
|
failed = true;
|
|
282
286
|
result = { passed: false, reason: `Guard failed: ${error?.message ?? error}` };
|
|
283
287
|
}
|
|
@@ -362,6 +366,9 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
362
366
|
await this.persist();
|
|
363
367
|
await this.disconnectMcpServers();
|
|
364
368
|
}
|
|
369
|
+
async reportFailure(error, details = {}) {
|
|
370
|
+
await reportError(error, { source: "agent", chatId: this.currentChat?._id?.toString(), userId: this.currentUser?.userId, ...details });
|
|
371
|
+
}
|
|
365
372
|
async failRun(message, llmError) {
|
|
366
373
|
try {
|
|
367
374
|
this.currentChat.state?.setStatus(AgentStatus.FAILED);
|
|
@@ -371,6 +378,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
371
378
|
await this.persist();
|
|
372
379
|
} catch (saveError) {
|
|
373
380
|
this.logger.error({ error: saveError?.message ?? saveError }, "[AGENT] Failed to persist failed run state");
|
|
381
|
+
await this.reportFailure(saveError, { stage: "persist" });
|
|
374
382
|
} finally {
|
|
375
383
|
await this.disconnectMcpServers();
|
|
376
384
|
}
|
|
@@ -458,6 +466,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
|
|
|
458
466
|
});
|
|
459
467
|
} catch (error) {
|
|
460
468
|
this.logger.error({ error: error?.message ?? error }, "[AGENT] Failed to persist traces");
|
|
469
|
+
await this.reportFailure(error, { stage: "traces" });
|
|
461
470
|
}
|
|
462
471
|
}
|
|
463
472
|
async persist(props) {
|
package/dist/loops/agi/loop.js
CHANGED
|
@@ -50,7 +50,7 @@ class AgiLoop extends import_harness.AgentLoop {
|
|
|
50
50
|
return "agi";
|
|
51
51
|
}
|
|
52
52
|
get version() {
|
|
53
|
-
return "1.
|
|
53
|
+
return "1.10.0";
|
|
54
54
|
}
|
|
55
55
|
get author() {
|
|
56
56
|
return {
|
|
@@ -78,10 +78,12 @@ class AgiLoop extends import_harness.AgentLoop {
|
|
|
78
78
|
...ctx.skillParams,
|
|
79
79
|
contextInjection: {
|
|
80
80
|
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
81
|
-
...chat_history?.length ? { chat_history } : {}
|
|
81
|
+
...chat_history?.length ? { chat_history } : {},
|
|
82
|
+
...ctx.chat.title ? {} : { needs_title: true }
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
85
|
ctx.chat.state?.setLanguage(result.detected_language);
|
|
86
|
+
ctx.chat.setTitle(result.title);
|
|
85
87
|
if (!result.can_answer) {
|
|
86
88
|
const activity = (0, import_activity.cleanActivity)(result.activity);
|
|
87
89
|
if (activity) ctx.chat.state?.setCurrentActivity(activity);
|
package/dist/loops/agi/loop.mjs
CHANGED
|
@@ -27,7 +27,7 @@ class AgiLoop extends AgentLoop {
|
|
|
27
27
|
return "agi";
|
|
28
28
|
}
|
|
29
29
|
get version() {
|
|
30
|
-
return "1.
|
|
30
|
+
return "1.10.0";
|
|
31
31
|
}
|
|
32
32
|
get author() {
|
|
33
33
|
return {
|
|
@@ -55,10 +55,12 @@ class AgiLoop extends AgentLoop {
|
|
|
55
55
|
...ctx.skillParams,
|
|
56
56
|
contextInjection: {
|
|
57
57
|
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
58
|
-
...chat_history?.length ? { chat_history } : {}
|
|
58
|
+
...chat_history?.length ? { chat_history } : {},
|
|
59
|
+
...ctx.chat.title ? {} : { needs_title: true }
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
ctx.chat.state?.setLanguage(result.detected_language);
|
|
63
|
+
ctx.chat.setTitle(result.title);
|
|
62
64
|
if (!result.can_answer) {
|
|
63
65
|
const activity = cleanActivity(result.activity);
|
|
64
66
|
if (activity) ctx.chat.state?.setCurrentActivity(activity);
|
|
@@ -25,7 +25,7 @@ var import_skill = require("../../../skills/skill.js");
|
|
|
25
25
|
var import_shared_rules = require("../../../skills/shared/shared-rules.js");
|
|
26
26
|
const fastResponder = new import_skill.Skill({
|
|
27
27
|
name: "fast_responder",
|
|
28
|
-
version: "2.
|
|
28
|
+
version: "2.5.0",
|
|
29
29
|
description: "Handles general conversations and multipurpose user assistance.",
|
|
30
30
|
temperature: 0.7,
|
|
31
31
|
thinking: "low",
|
|
@@ -43,6 +43,7 @@ const fastResponder = new import_skill.Skill({
|
|
|
43
43
|
"MEMORY_AND_PERSONAL_DATA_CHECK: Do NOT assume, pretend, or hallucinate remembering past events, meetings, notes, or specific user context. If the user asks about something mentioned in the past (e.g., 'recuerdas la reuni\xF3n...?', 'qu\xE9 te dije de...?'), set 'can_answer' to false UNLESS the exact details are explicitly provided inside 'context_injection'. Never fake memory.",
|
|
44
44
|
"CAPABILITY_CHECK: Set 'can_answer' to false if: 1) The query involves creating, registering, updating, or deleting data or non-text resources (e.g., expenses, records, reminders, calendar entries), 2) The query refers to personal memory, past events, meetings, or stored notes not present in 'context_injection', 3) The query requires specialized skills or tools (e.g., searching databases, calendar lookup, external integrations), 4) The query requires live internet access (news, weather, live data), 5) The query is a correction, rejection, or negative feedback regarding a previously executed task or tool response (e.g., 'no era esa fecha', 'te equivocaste', 'busca otra opci\xF3n', 'eso no sirvi\xF3'). When 'can_answer' is false, leave 'answer' minimal or empty for the fallback engine.",
|
|
45
45
|
"ACTIVITY: When 'can_answer' is false, always write in 'activity' one short sentence of at most 60 characters: a verb in the present or progressive form followed by what you will look up or do, taken from the user's request. It must be in 'detected_language' and match the language of the message of the user, never the language of these instructions. Never mention tool names or technical terms, never include personal data, and do not promise a result. Leave it empty when 'can_answer' is true.",
|
|
46
|
+
"TITLE: Only when 'context_injection.needs_title' is true, write in 'title' a short title for this conversation, of at most 50 characters, taken from the topic of INPUT.user_message, in 'detected_language', as a noun phrase with no quotes, no final period and no personal data. Write it whether 'can_answer' is true or false. Leave it empty when 'context_injection.needs_title' is not present.",
|
|
46
47
|
"REASONING: Always generate the 'reasoning' field with a short explanation in English of the decision-making process, regardless of whether 'can_answer' is true or false.",
|
|
47
48
|
import_shared_rules.FORMATTING,
|
|
48
49
|
import_shared_rules.LATEX_FORMATTING,
|
|
@@ -57,7 +58,8 @@ const fastResponder = new import_skill.Skill({
|
|
|
57
58
|
answer: "string",
|
|
58
59
|
reasoning: "string",
|
|
59
60
|
detected_language: "string",
|
|
60
|
-
activity: "string"
|
|
61
|
+
activity: "string",
|
|
62
|
+
title: "string"
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -2,7 +2,7 @@ import { Skill } from "../../../skills/skill.js";
|
|
|
2
2
|
import { FORMATTING, LATEX_FORMATTING, CITATION_FORMATTING, POLICY_RESTRICTIONS } from "../../../skills/shared/shared-rules.js";
|
|
3
3
|
const fastResponder = new Skill({
|
|
4
4
|
name: "fast_responder",
|
|
5
|
-
version: "2.
|
|
5
|
+
version: "2.5.0",
|
|
6
6
|
description: "Handles general conversations and multipurpose user assistance.",
|
|
7
7
|
temperature: 0.7,
|
|
8
8
|
thinking: "low",
|
|
@@ -20,6 +20,7 @@ const fastResponder = new Skill({
|
|
|
20
20
|
"MEMORY_AND_PERSONAL_DATA_CHECK: Do NOT assume, pretend, or hallucinate remembering past events, meetings, notes, or specific user context. If the user asks about something mentioned in the past (e.g., 'recuerdas la reuni\xF3n...?', 'qu\xE9 te dije de...?'), set 'can_answer' to false UNLESS the exact details are explicitly provided inside 'context_injection'. Never fake memory.",
|
|
21
21
|
"CAPABILITY_CHECK: Set 'can_answer' to false if: 1) The query involves creating, registering, updating, or deleting data or non-text resources (e.g., expenses, records, reminders, calendar entries), 2) The query refers to personal memory, past events, meetings, or stored notes not present in 'context_injection', 3) The query requires specialized skills or tools (e.g., searching databases, calendar lookup, external integrations), 4) The query requires live internet access (news, weather, live data), 5) The query is a correction, rejection, or negative feedback regarding a previously executed task or tool response (e.g., 'no era esa fecha', 'te equivocaste', 'busca otra opci\xF3n', 'eso no sirvi\xF3'). When 'can_answer' is false, leave 'answer' minimal or empty for the fallback engine.",
|
|
22
22
|
"ACTIVITY: When 'can_answer' is false, always write in 'activity' one short sentence of at most 60 characters: a verb in the present or progressive form followed by what you will look up or do, taken from the user's request. It must be in 'detected_language' and match the language of the message of the user, never the language of these instructions. Never mention tool names or technical terms, never include personal data, and do not promise a result. Leave it empty when 'can_answer' is true.",
|
|
23
|
+
"TITLE: Only when 'context_injection.needs_title' is true, write in 'title' a short title for this conversation, of at most 50 characters, taken from the topic of INPUT.user_message, in 'detected_language', as a noun phrase with no quotes, no final period and no personal data. Write it whether 'can_answer' is true or false. Leave it empty when 'context_injection.needs_title' is not present.",
|
|
23
24
|
"REASONING: Always generate the 'reasoning' field with a short explanation in English of the decision-making process, regardless of whether 'can_answer' is true or false.",
|
|
24
25
|
FORMATTING,
|
|
25
26
|
LATEX_FORMATTING,
|
|
@@ -34,7 +35,8 @@ const fastResponder = new Skill({
|
|
|
34
35
|
answer: "string",
|
|
35
36
|
reasoning: "string",
|
|
36
37
|
detected_language: "string",
|
|
37
|
-
activity: "string"
|
|
38
|
+
activity: "string",
|
|
39
|
+
title: "string"
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(automation_runner_exports);
|
|
|
25
25
|
var import_node_crypto = require("node:crypto");
|
|
26
26
|
var import_node_os = require("node:os");
|
|
27
27
|
var import_logger = require("../../../common/logger/index.js");
|
|
28
|
+
var import_error = require("../../../common/error/index.js");
|
|
28
29
|
var import_base = require("../../../common/base/index.js");
|
|
29
30
|
var import_agent = require("../../../harness/agent.js");
|
|
30
31
|
var import_loop = require("../../../loops/agi/loop.js");
|
|
@@ -83,6 +84,7 @@ class AutomationRunner {
|
|
|
83
84
|
await new import_sync_automation_runs.SyncAutomationRunsUseCase().execute({});
|
|
84
85
|
} catch (error) {
|
|
85
86
|
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] Failed to sync the open runs");
|
|
87
|
+
await (0, import_error.reportError)(error, { source: "automations", stage: "sync" });
|
|
86
88
|
}
|
|
87
89
|
if (capacity <= 0) return;
|
|
88
90
|
const data = await new import_claim_due_automations.ClaimDueAutomationsUseCase().execute({ workerId: this.workerId, limit: capacity, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
@@ -101,8 +103,9 @@ class AutomationRunner {
|
|
|
101
103
|
}
|
|
102
104
|
async loop() {
|
|
103
105
|
while (this.running) {
|
|
104
|
-
this.ticking = this.tick().catch((error) => {
|
|
106
|
+
this.ticking = this.tick().catch(async (error) => {
|
|
105
107
|
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The worker failed to check the due automations");
|
|
108
|
+
await (0, import_error.reportError)(error, { source: "automations", stage: "tick" });
|
|
106
109
|
});
|
|
107
110
|
await this.ticking;
|
|
108
111
|
if (!this.running) break;
|
|
@@ -136,6 +139,7 @@ class AutomationRunner {
|
|
|
136
139
|
} catch (failure) {
|
|
137
140
|
error = { code: failure?.code ?? "RUNNER_ERROR", message: failure?.message ?? String(failure) };
|
|
138
141
|
this.logger.error({ error: error.message, automationId, runId }, "[AUTOMATIONS] A run failed");
|
|
142
|
+
await (0, import_error.reportError)(failure, { source: "automations", stage: "run", automationId, runId });
|
|
139
143
|
} finally {
|
|
140
144
|
clearInterval(heartbeat);
|
|
141
145
|
}
|
|
@@ -177,6 +181,7 @@ class AutomationRunner {
|
|
|
177
181
|
await this.options.onRunFinished(event);
|
|
178
182
|
} catch (error) {
|
|
179
183
|
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The onRunFinished callback failed");
|
|
184
|
+
await (0, import_error.reportError)(error, { source: "automations", stage: "onRunFinished" });
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
}
|