openloops 0.4.2 → 0.4.3

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to `openloops` are written here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com) and the versions follow [semantic versioning](https://semver.org), where a minor version can still break the API while the package is in beta. Changes before 0.4.0 are not recorded here, see the commits and the tags.
4
4
 
5
+ ## 0.4.3
6
+
7
+ ### Added
8
+
9
+ - `search` in `listChatsByUser`: returns only the chats with a message whose content contains the text, ignoring case. The text is escaped, so it is matched literally and not as a regular expression.
10
+ - `escapeRegex` helper in `src/common/helpers`, now used by `listChatsByUser`, `searchWorkspaceItems` and the tool ranking instead of three copies of the same escape.
11
+
5
12
  ## 0.4.2
6
13
 
7
14
  ### Added
@@ -0,0 +1 @@
1
+ export declare function escapeRegex(input?: string): string;
@@ -0,0 +1,30 @@
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 escape_regex_exports = {};
20
+ __export(escape_regex_exports, {
21
+ escapeRegex: () => escapeRegex
22
+ });
23
+ module.exports = __toCommonJS(escape_regex_exports);
24
+ function escapeRegex(input = "") {
25
+ return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ escapeRegex
30
+ });
@@ -0,0 +1,7 @@
1
+ import "../../chunk-CF3WOMB3.mjs";
2
+ function escapeRegex(input = "") {
3
+ return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ }
5
+ export {
6
+ escapeRegex
7
+ };
@@ -1,2 +1,3 @@
1
+ export * from './escape-regex';
1
2
  export * from './extract-json-from-text';
2
3
  export * from './sanitize-string';
@@ -15,10 +15,12 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var helpers_exports = {};
17
17
  module.exports = __toCommonJS(helpers_exports);
18
+ __reExport(helpers_exports, require("./escape-regex"), module.exports);
18
19
  __reExport(helpers_exports, require("./extract-json-from-text"), module.exports);
19
20
  __reExport(helpers_exports, require("./sanitize-string"), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
23
+ ...require("./escape-regex"),
22
24
  ...require("./extract-json-from-text"),
23
25
  ...require("./sanitize-string")
24
26
  });
@@ -1,2 +1,3 @@
1
+ export * from "./escape-regex";
1
2
  export * from "./extract-json-from-text";
2
3
  export * from "./sanitize-string";
@@ -21,9 +21,7 @@ __export(rank_tools_by_keywords_exports, {
21
21
  rankToolsByKeywords: () => rankToolsByKeywords
22
22
  });
23
23
  module.exports = __toCommonJS(rank_tools_by_keywords_exports);
24
- function escapeRegExp(text) {
25
- return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26
- }
24
+ var import_helpers = require("../../common/helpers/index.js");
27
25
  function rankToolsByKeywords(keywords, tools, minScoreThreshold = 0.1) {
28
26
  const NAME_WEIGHT_MULTIPLIER = 2.5;
29
27
  const DESCRIPTION_WEIGHT_MULTIPLIER = 1;
@@ -36,7 +34,7 @@ function rankToolsByKeywords(keywords, tools, minScoreThreshold = 0.1) {
36
34
  for (const { keyword, weight } of keywords) {
37
35
  if (!keyword || weight <= 0) continue;
38
36
  const cleanKeyword = keyword.trim();
39
- const escapedKeyword = escapeRegExp(cleanKeyword);
37
+ const escapedKeyword = (0, import_helpers.escapeRegex)(cleanKeyword);
40
38
  const regex = new RegExp(`\\b${escapedKeyword}\\b`, "gi");
41
39
  const nameMatches = (normalizedName.match(regex) || []).length;
42
40
  const descMatches = (normalizedDescription.match(regex) || []).length;
@@ -1,7 +1,5 @@
1
1
  import "../../chunk-CF3WOMB3.mjs";
2
- function escapeRegExp(text) {
3
- return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
- }
2
+ import { escapeRegex } from "../../common/helpers/index.js";
5
3
  function rankToolsByKeywords(keywords, tools, minScoreThreshold = 0.1) {
6
4
  const NAME_WEIGHT_MULTIPLIER = 2.5;
7
5
  const DESCRIPTION_WEIGHT_MULTIPLIER = 1;
@@ -14,7 +12,7 @@ function rankToolsByKeywords(keywords, tools, minScoreThreshold = 0.1) {
14
12
  for (const { keyword, weight } of keywords) {
15
13
  if (!keyword || weight <= 0) continue;
16
14
  const cleanKeyword = keyword.trim();
17
- const escapedKeyword = escapeRegExp(cleanKeyword);
15
+ const escapedKeyword = escapeRegex(cleanKeyword);
18
16
  const regex = new RegExp(`\\b${escapedKeyword}\\b`, "gi");
19
17
  const nameMatches = (normalizedName.match(regex) || []).length;
20
18
  const descMatches = (normalizedDescription.match(regex) || []).length;
@@ -5,6 +5,7 @@ import { ChatProps, ExecutionMode } from '../entities';
5
5
  export interface Params extends BaseUseCaseParams {
6
6
  filters?: Partial<ChatProps>;
7
7
  executionMode?: ExecutionMode;
8
+ search?: string;
8
9
  options?: QueryOptions;
9
10
  }
10
11
  export interface Output extends BaseUseCaseOutput {
@@ -32,6 +32,7 @@ __export(list_chats_by_user_use_case_exports, {
32
32
  module.exports = __toCommonJS(list_chats_by_user_use_case_exports);
33
33
  var import_tsyringe = require("tsyringe");
34
34
  var import_mongodb = require("mongodb");
35
+ var import_helpers = require("../../../common/helpers/index.js");
35
36
  var import_base = require("../../../common/base/base.use-case.js");
36
37
  var import_repositories2 = require("../repositories");
37
38
  let ListChatsByUserUseCase = class extends import_base.BaseUseCase {
@@ -41,13 +42,15 @@ let ListChatsByUserUseCase = class extends import_base.BaseUseCase {
41
42
  }
42
43
  chatRepository;
43
44
  async execute(params) {
44
- const { options, executionMode, currentUser } = params;
45
+ const { options, executionMode, search, currentUser } = params;
45
46
  const { page = 1, limit: pageSize = 10 } = options || {};
47
+ const term = (0, import_helpers.escapeRegex)(search?.trim());
46
48
  const result = await this.chatRepository?._.findManyPaginated({
47
49
  where: {
48
50
  ownerId: new import_mongodb.ObjectId(currentUser?.userId),
49
51
  ...executionMode === "autonomous" ? { "settings.executionMode": "autonomous" } : {},
50
- ...executionMode === "interactive" ? { "settings.executionMode": { $ne: "autonomous" } } : {}
52
+ ...executionMode === "interactive" ? { "settings.executionMode": { $ne: "autonomous" } } : {},
53
+ ...term ? { "messages.content": { $regex: term, $options: "i" } } : {}
51
54
  },
52
55
  options: { page, limit: pageSize, sortBy: { updatedAt: -1 } }
53
56
  });
@@ -4,6 +4,7 @@ import {
4
4
  } from "../../../chunk-CF3WOMB3.mjs";
5
5
  import { autoInjectable, inject } from "tsyringe";
6
6
  import { ObjectId } from "mongodb";
7
+ import { escapeRegex } from "../../../common/helpers/index.js";
7
8
  import { BaseUseCase } from "../../../common/base/base.use-case.js";
8
9
  import { ChatRepository } from "../repositories";
9
10
  let ListChatsByUserUseCase = class extends BaseUseCase {
@@ -13,13 +14,15 @@ let ListChatsByUserUseCase = class extends BaseUseCase {
13
14
  }
14
15
  chatRepository;
15
16
  async execute(params) {
16
- const { options, executionMode, currentUser } = params;
17
+ const { options, executionMode, search, currentUser } = params;
17
18
  const { page = 1, limit: pageSize = 10 } = options || {};
19
+ const term = escapeRegex(search?.trim());
18
20
  const result = await this.chatRepository?._.findManyPaginated({
19
21
  where: {
20
22
  ownerId: new ObjectId(currentUser?.userId),
21
23
  ...executionMode === "autonomous" ? { "settings.executionMode": "autonomous" } : {},
22
- ...executionMode === "interactive" ? { "settings.executionMode": { $ne: "autonomous" } } : {}
24
+ ...executionMode === "interactive" ? { "settings.executionMode": { $ne: "autonomous" } } : {},
25
+ ...term ? { "messages.content": { $regex: term, $options: "i" } } : {}
23
26
  },
24
27
  options: { page, limit: pageSize, sortBy: { updatedAt: -1 } }
25
28
  });
@@ -31,6 +31,7 @@ __export(search_workspace_items_use_case_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(search_workspace_items_use_case_exports);
33
33
  var import_tsyringe = require("tsyringe");
34
+ var import_helpers = require("../../../common/helpers/index.js");
34
35
  var import_base = require("../../../common/base/base.use-case.js");
35
36
  var import_base2 = require("../../../common/base/base.entity.js");
36
37
  var import_repositories2 = require("../repositories");
@@ -46,8 +47,7 @@ let SearchWorkspaceItemsUseCase = class extends import_base.BaseUseCase {
46
47
  if (!chatId) throw new Error("chatId is required");
47
48
  if (!query?.trim()) throw new Error("query is required");
48
49
  if (!currentUser) this.throwError403();
49
- const escaped = query.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
50
- const pattern = { $regex: escaped, $options: "i" };
50
+ const pattern = { $regex: (0, import_helpers.escapeRegex)(query.trim()), $options: "i" };
51
51
  const where = {
52
52
  ownerId: import_base2.BaseEntity.toObjectId(currentUser?.userId),
53
53
  chatId: import_base2.BaseEntity.toObjectId(chatId),
@@ -3,6 +3,7 @@ import {
3
3
  __decorateParam
4
4
  } from "../../../chunk-CF3WOMB3.mjs";
5
5
  import { autoInjectable, inject } from "tsyringe";
6
+ import { escapeRegex } from "../../../common/helpers/index.js";
6
7
  import { BaseUseCase } from "../../../common/base/base.use-case.js";
7
8
  import { BaseEntity } from "../../../common/base/base.entity.js";
8
9
  import { WorkspaceItemRepository } from "../repositories";
@@ -18,8 +19,7 @@ let SearchWorkspaceItemsUseCase = class extends BaseUseCase {
18
19
  if (!chatId) throw new Error("chatId is required");
19
20
  if (!query?.trim()) throw new Error("query is required");
20
21
  if (!currentUser) this.throwError403();
21
- const escaped = query.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
22
- const pattern = { $regex: escaped, $options: "i" };
22
+ const pattern = { $regex: escapeRegex(query.trim()), $options: "i" };
23
23
  const where = {
24
24
  ownerId: BaseEntity.toObjectId(currentUser?.userId),
25
25
  chatId: BaseEntity.toObjectId(chatId),
package/docs/chats.md CHANGED
@@ -53,6 +53,12 @@ const interactive = await listChatsByUser({ executionMode: 'interactive', curren
53
53
 
54
54
  `executionMode` is optional. `autonomous` returns the chats that were created by an autonomous run and `interactive` returns the rest, including the chats saved before the mode existed. Combine it with `state.status` to show the autonomous runs that need attention: `awaiting_user_confirmation` or `awaiting_user_input` mean the run is paused until the user answers in the chat, and `failed` means it failed.
55
55
 
56
+ ```typescript
57
+ const found = await listChatsByUser({ search: 'netflix', currentUser })
58
+ ```
59
+
60
+ `search` is optional. It returns the chats with at least one message whose content contains the text, ignoring case, in the same order and with the same pagination. The text is matched literally, so characters such as `(` or `.` have no special meaning. It reads the messages without an index, which is fine for the chats of one user. An empty text is ignored.
61
+
56
62
  ## Getting one chat
57
63
 
58
64
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openloops",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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",