openloops 0.7.5 → 0.8.0

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +53 -11
  2. package/dist/clients/llm/llm-error.d.ts +1 -1
  3. package/dist/clients/llm/llm-error.js +12 -0
  4. package/dist/clients/llm/llm-error.mjs +12 -0
  5. package/dist/common/helpers/index.d.ts +1 -0
  6. package/dist/common/helpers/index.js +3 -1
  7. package/dist/common/helpers/index.mjs +1 -0
  8. package/dist/common/helpers/sanitize-string.js +5 -15
  9. package/dist/common/helpers/sanitize-string.mjs +5 -5
  10. package/dist/common/helpers/strip-blocks.d.ts +1 -0
  11. package/dist/common/helpers/strip-blocks.js +45 -0
  12. package/dist/common/helpers/strip-blocks.mjs +21 -0
  13. package/dist/common/logger/pino.js +12 -3
  14. package/dist/common/logger/pino.mjs +12 -3
  15. package/dist/db/index.d.ts +1 -0
  16. package/dist/db/index.js +3 -1
  17. package/dist/db/index.mjs +1 -0
  18. package/dist/db/migrations/chat-titles.d.ts +10 -0
  19. package/dist/db/migrations/chat-titles.js +55 -0
  20. package/dist/db/migrations/chat-titles.mjs +31 -0
  21. package/dist/harness/agent-state.d.ts +0 -1
  22. package/dist/loops/agi/loop.js +4 -2
  23. package/dist/loops/agi/loop.mjs +4 -2
  24. package/dist/loops/shared/skills/fast-responder.d.ts +1 -0
  25. package/dist/loops/shared/skills/fast-responder.js +4 -2
  26. package/dist/loops/shared/skills/fast-responder.mjs +4 -2
  27. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +2 -1
  28. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +2 -2
  29. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +2 -2
  30. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +1 -0
  31. package/dist/services/automations/use-cases/sync-automation-run.use-case.js +6 -2
  32. package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +5 -2
  33. package/dist/services/chats/entities/chat.entity.d.ts +3 -0
  34. package/dist/services/chats/entities/chat.entity.js +8 -0
  35. package/dist/services/chats/entities/chat.entity.mjs +8 -0
  36. package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +1 -5
  37. package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +1 -5
  38. package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +2 -1
  39. package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +3 -2
  40. package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +3 -2
  41. package/dist/services/chats/utils/title.d.ts +2 -0
  42. package/dist/services/chats/utils/title.js +35 -0
  43. package/dist/services/chats/utils/title.mjs +10 -0
  44. package/dist/tools/core/fetch-url/fetch-url.tool.js +1 -1
  45. package/dist/tools/core/fetch-url/fetch-url.tool.mjs +1 -1
  46. package/dist/tools/core/fetch-url/html-to-text.js +3 -20
  47. package/dist/tools/core/fetch-url/html-to-text.mjs +3 -20
  48. package/docs/README.md +1 -1
  49. package/docs/agent.md +18 -3
  50. package/docs/automations.md +3 -3
  51. package/docs/chats.md +41 -8
  52. package/docs/configuration.md +1 -1
  53. package/docs/integration-guide.md +2 -2
  54. package/docs/llms.txt +1 -1
  55. package/docs/loops.md +1 -1
  56. package/docs/tools.md +1 -0
  57. package/examples/chats/search-chats.ts +30 -0
  58. package/package.json +7 -8
  59. package/dist/services/chats/utils/deprecated-activity.d.ts +0 -1
  60. package/dist/services/chats/utils/deprecated-activity.js +0 -60
  61. package/dist/services/chats/utils/deprecated-activity.mjs +0 -36
@@ -21,7 +21,7 @@
21
21
  | `MCP_TOOL_TIMEOUT_MS` | no | Longest time to wait for a tool of an MCP server, in milliseconds. Defaults to `60000`. See [Timeouts](#timeouts). |
22
22
  | `SENTRY_DSN` | no | Errors are reported to Sentry when set, unless `IS_LOCAL` is `true` or `NODE_ENV` is `development`. |
23
23
  | `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL` | no | Traces every LLM call in Langfuse when all three are set. |
24
- | `IS_LOCAL`, `NODE_ENV` | no | Local development switches. |
24
+ | `IS_LOCAL`, `NODE_ENV` | no | Local development switches. With `IS_LOCAL` set to `true`, or `NODE_ENV` set to `development`, the logger prints colored logs if `pino-pretty` is installed in your project (it is a dev dependency of this package, so install it yourself: `yarn add -D pino-pretty`), and plain JSON otherwise. |
25
25
 
26
26
  Any value can be stored encrypted by prefixing it with `ENC:`. It is decrypted with `SECRET_MANAGER_KEY` when it is read.
27
27
 
@@ -33,7 +33,7 @@ The use cases check who owns every record, in the repository, with the `currentU
33
33
  | --- | --- |
34
34
  | Send a message | `new Agent({ loop, tools, guards }).run({ input: { message, chatId? }, currentUser })` |
35
35
  | Stop a running message | `Agent.interruptExecution(chatId, currentUser)` |
36
- | List, read, delete chats | `listChatsByUser` (with `executionMode` to separate interactive from autonomous), `getChatById`, `deleteChat` |
36
+ | List, read, delete chats | `listChatsByUser` (with `executionMode` to separate interactive from autonomous, `search` for the title and the messages, and `select` for a light history list), `getChatById`, `updateChat` to rename a chat with `title`, `deleteChat` |
37
37
  | Poll the state of a chat | `getChatById({ id, select: { state: 1 } })` |
38
38
  | Manage MCP servers | `createMcpServer`, `listMcpServersByUser`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `verifyMcpServerConnection` |
39
39
  | Approve or block an MCP server from a screen | `decideMcpServerTrust` |
@@ -84,7 +84,7 @@ Show `data.messages`, and look at `data.state.status`:
84
84
  | `processing` | A run is in progress. Show a loading state and offer to stop it. |
85
85
  | `awaiting_user_input` | The agent asked a question. The answer is sent as a normal message in the same chat. |
86
86
  | `awaiting_user_confirmation` | The agent needs an approval, for a destructive tool or for an MCP server. The question is the last message, and the answer is sent as a normal message in the same chat. |
87
- | `failed` | Show `data.state.lastError.message` and let the user try again. |
87
+ | `failed` | Show `data.state.lastError.message` and let the user try again, unless `lastError.isRetryable` is `false`. `lastError.code` says what failed, see [error handling](agent.md#error-handling). |
88
88
 
89
89
  Messages have a `source` (`user`, `model` or `harness`) and some have `excludeFromContext`. Messages with `source: 'harness'` are written by the system, for example a guardrail reply or an approval question, and you may want to style them differently. See [chats](chats.md).
90
90
 
package/docs/llms.txt CHANGED
@@ -14,7 +14,7 @@ Start with the integration guide, then read only the pages you need. All pages a
14
14
 
15
15
  - [The Agent](agent.md): options, running a turn, statuses, confirmations, autonomous mode
16
16
  - [Configuration](configuration.md): environment variables, default model, timeouts
17
- - [Chats](chats.md): the chat record, message source, listing and deleting
17
+ - [Chats](chats.md): the chat record, its title, message source, listing, searching and deleting, and the migration to 0.8.0
18
18
 
19
19
  ## Shape the agent
20
20
 
package/docs/loops.md CHANGED
@@ -13,7 +13,7 @@ import { AgiLoop } from 'openloops/loops'
13
13
 
14
14
  | Node | What it does |
15
15
  | --- | --- |
16
- | `fast_responder` | Initial node. Answers directly when no tools or memory are needed, and when it cannot, says in one sentence what the agent will do. It is skipped in an autonomous run. |
16
+ | `fast_responder` | Initial node. Answers directly when no tools or memory are needed, and when it cannot, says in one sentence what the agent will do. It also writes the [title](chats.md#the-title) of a chat that has none. It is skipped in an autonomous run. |
17
17
  | `reasoning_engine` | Reads the situation or the results of the last actions, rewrites its working state, decides the next actions, reports the language of the conversation and says in one sentence what is happening until its next answer. |
18
18
  | `action_engine` | Runs the actions the reasoning engine asked for, asks the user for confirmation when needed, delivers the final answer. |
19
19
 
package/docs/tools.md CHANGED
@@ -98,6 +98,7 @@ What it does:
98
98
  - It never reaches a private network. Loopback, private ranges, link-local (cloud metadata included) and IPv6 equivalents are refused, for the first URL and for each redirect, and the check runs on the address the connection really uses.
99
99
  - The limits are fixed: 15 seconds, 10 MB of body and 50000 characters of text. When a limit cuts the content, `truncated` is `true`.
100
100
  - The tool has a `notice`, because the content of a page is untrusted.
101
+ - The description tells the model to prefer a source that returns plain text or JSON and needs no key, such as a public API it knows, over a regular web page, which is long and noisy, and to search when it does not know one instead of guessing a URL.
101
102
 
102
103
  What it does not do:
103
104
 
@@ -0,0 +1,30 @@
1
+ import { Logger } from 'openloops/common'
2
+ import { CurrentUser } from 'openloops/base'
3
+ import { getChatById, listChatsByUser } from 'openloops/chats'
4
+
5
+ /**
6
+ * Searches the history of the user. `search` looks in the title and in the messages, and `select` returns only what a list needs,
7
+ * so the messages do not travel. Once the user picks a chat, it is loaded complete.
8
+ */
9
+ async function searchChats () {
10
+ const logger = new Logger()
11
+ const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
12
+
13
+ const history = await listChatsByUser({
14
+ search: 'netflix',
15
+ select: { title: 1, updatedAt: 1 },
16
+ options: { page: 1, limit: 10 },
17
+ currentUser,
18
+ })
19
+
20
+ logger.info(history.items.map(chat => ({ id: chat._id, title: chat.title ?? 'Untitled', updatedAt: chat.updatedAt })), '[Demo] History')
21
+
22
+ const picked = history.items[0]?._id
23
+ if (!picked) return
24
+
25
+ const chat = await getChatById({ id: String(picked), currentUser })
26
+
27
+ logger.info(chat?.messages, '[Demo] Messages')
28
+ }
29
+
30
+ searchChats()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openloops",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "description": "Open source harness for AI agents: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous automations, where the loop is pluggable",
5
5
  "author": {
6
6
  "name": "Jose Barcos",
@@ -96,6 +96,7 @@
96
96
  "test:watch": "jest --watch",
97
97
  "test:coverage": "jest --coverage",
98
98
  "migrate:automations": "ts-node scripts/migrate-automations.ts",
99
+ "migrate:chat-titles": "ts-node scripts/migrate-chat-titles.ts",
99
100
  "eval": "ts-node --project evals/tsconfig.json evals/run.ts",
100
101
  "eval:models": "ts-node --project evals/tsconfig.json evals/run.ts models",
101
102
  "eval:skills": "ts-node --project evals/tsconfig.json evals/run.ts skills",
@@ -106,9 +107,9 @@
106
107
  "eval:list": "ts-node --project evals/tsconfig.json evals/run.ts list"
107
108
  },
108
109
  "dependencies": {
109
- "@earendil-works/pi-ai": "^1.4.0",
110
+ "@earendil-works/pi-ai": "^1.5.0",
110
111
  "@modelcontextprotocol/sdk": "^1.32.2",
111
- "@sentry/node": "^11.10.0",
112
+ "@sentry/node": "^11.11.0",
112
113
  "bcryptjs": "^3.0.3",
113
114
  "croner": "^11.0.0",
114
115
  "cryptr": "^6.4.0",
@@ -117,17 +118,15 @@
117
118
  "jsonwebtoken": "^9.0.3",
118
119
  "langfuse": "^3.39.2",
119
120
  "mongodb": "^7.8.0",
120
- "pino": "^10.4.0",
121
- "pino-pretty": "^13.2.0",
122
- "sanitize-html": "^2.18.1"
121
+ "pino": "^10.4.0"
123
122
  },
124
123
  "devDependencies": {
125
124
  "@types/jest": "^30.0.0",
126
125
  "@types/node": "^26.6.6",
127
- "@types/sanitize-html": "^2.16.2",
128
126
  "jest": "^30.5.2",
127
+ "pino-pretty": "^13.2.0",
129
128
  "ts-jest": "^29.4.15",
130
- "tsc-alias": "^1.9.9",
129
+ "tsc-alias": "^1.9.10",
131
130
  "tsconfig-paths": "^4.2.0",
132
131
  "tsup": "^9.0.0",
133
132
  "typescript": "^6.0.3"
@@ -1 +0,0 @@
1
- export declare function deprecatedActivity(chatId: string, now?: number): string;
@@ -1,60 +0,0 @@
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 deprecated_activity_exports = {};
20
- __export(deprecated_activity_exports, {
21
- deprecatedActivity: () => deprecatedActivity
22
- });
23
- module.exports = __toCommonJS(deprecated_activity_exports);
24
- const WORDS = [
25
- "Thinking",
26
- "Computing",
27
- "Pondering",
28
- "Analyzing",
29
- "Crunching",
30
- "Reviewing",
31
- "Checking",
32
- "Working on it",
33
- "Reasoning",
34
- "Digging in",
35
- "Gathering",
36
- "Sorting",
37
- "Calculating",
38
- "Connecting the dots",
39
- "Exploring",
40
- "Piecing it together",
41
- "Figuring it out",
42
- "Untangling",
43
- "Weighing options",
44
- "Cooking"
45
- ];
46
- const WINDOW_IN_MS = 4e3;
47
- function hash(text) {
48
- let value = 5381;
49
- for (const character of text) value = (value << 5) + value + character.charCodeAt(0) >>> 0;
50
- return value;
51
- }
52
- function deprecatedActivity(chatId, now = Date.now()) {
53
- const window = Math.floor(now / WINDOW_IN_MS);
54
- const index = hash(`${chatId}:${window}`) % WORDS.length;
55
- return `${WORDS[index]}...`;
56
- }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- deprecatedActivity
60
- });
@@ -1,36 +0,0 @@
1
- const WORDS = [
2
- "Thinking",
3
- "Computing",
4
- "Pondering",
5
- "Analyzing",
6
- "Crunching",
7
- "Reviewing",
8
- "Checking",
9
- "Working on it",
10
- "Reasoning",
11
- "Digging in",
12
- "Gathering",
13
- "Sorting",
14
- "Calculating",
15
- "Connecting the dots",
16
- "Exploring",
17
- "Piecing it together",
18
- "Figuring it out",
19
- "Untangling",
20
- "Weighing options",
21
- "Cooking"
22
- ];
23
- const WINDOW_IN_MS = 4e3;
24
- function hash(text) {
25
- let value = 5381;
26
- for (const character of text) value = (value << 5) + value + character.charCodeAt(0) >>> 0;
27
- return value;
28
- }
29
- function deprecatedActivity(chatId, now = Date.now()) {
30
- const window = Math.floor(now / WINDOW_IN_MS);
31
- const index = hash(`${chatId}:${window}`) % WORDS.length;
32
- return `${WORDS[index]}...`;
33
- }
34
- export {
35
- deprecatedActivity
36
- };