openloops 0.2.3 → 0.2.5
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/README.md +6 -1
- package/dist/clients/slack/index.d.ts +1 -0
- package/dist/clients/slack/index.js +22 -0
- package/dist/clients/slack/index.mjs +1 -0
- package/dist/clients/slack/slack-client.d.ts +11 -0
- package/dist/clients/slack/slack-client.js +50 -0
- package/dist/clients/slack/slack-client.mjs +27 -0
- package/dist/tools/core/index.d.ts +1 -0
- package/dist/tools/core/index.js +3 -1
- package/dist/tools/core/index.mjs +1 -0
- package/dist/tools/core/slack/index.d.ts +1 -0
- package/dist/tools/core/slack/index.js +22 -0
- package/dist/tools/core/slack/index.mjs +1 -0
- package/dist/tools/core/slack/send-slack-message.tool.d.ts +2 -0
- package/dist/tools/core/slack/send-slack-message.tool.js +54 -0
- package/dist/tools/core/slack/send-slack-message.tool.mjs +31 -0
- package/docs/configuration.md +1 -0
- package/docs/tools.md +12 -0
- package/examples/run-agent/run-agent-with-slack.ts +32 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -228,8 +228,9 @@ LANGFUSE_SECRET_KEY=
|
|
|
228
228
|
LANGFUSE_PUBLIC_KEY=
|
|
229
229
|
LANGFUSE_BASE_URL=
|
|
230
230
|
|
|
231
|
-
# Optional, see "Web search" below
|
|
231
|
+
# Optional, see "Web search" and "Slack" below
|
|
232
232
|
SERPER_API_KEY=
|
|
233
|
+
SLACK_BOT_TOKEN=
|
|
233
234
|
```
|
|
234
235
|
|
|
235
236
|
Every variable is described in [`docs/configuration.md`](docs/configuration.md).
|
|
@@ -242,6 +243,10 @@ By default, `openloops` uses a database named `openloops` if `OPENLOOPS_DB_NAME`
|
|
|
242
243
|
|
|
243
244
|
The built-in `webSearchTool` uses [Serper](https://serper.dev). Create a free API key there and set `SERPER_API_KEY` in your `.env`. See [`docs/tools.md`](docs/tools.md).
|
|
244
245
|
|
|
246
|
+
### Slack
|
|
247
|
+
|
|
248
|
+
The built-in `sendSlackMessageTool` posts a message to a channel. Create a Slack app with the `chat:write` scope, install it in your workspace, invite the bot to the channel and set `SLACK_BOT_TOKEN` in your `.env`. See [`docs/tools.md`](docs/tools.md).
|
|
249
|
+
|
|
245
250
|
### Observability
|
|
246
251
|
|
|
247
252
|
- **Sentry**: set `SENTRY_DSN` and error tracking turns on automatically.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slack-client';
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var slack_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(slack_exports);
|
|
18
|
+
__reExport(slack_exports, require("./slack-client"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./slack-client")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./slack-client";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface SlackMessage {
|
|
2
|
+
channel: string;
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SlackSentMessage {
|
|
6
|
+
channel: string;
|
|
7
|
+
ts: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class SlackClient {
|
|
10
|
+
sendMessage({ channel, text }: SlackMessage): Promise<SlackSentMessage>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 slack_client_exports = {};
|
|
20
|
+
__export(slack_client_exports, {
|
|
21
|
+
SlackClient: () => SlackClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(slack_client_exports);
|
|
24
|
+
var import_secret_manager = require("../../common/utils/secret-manager.js");
|
|
25
|
+
class SlackClient {
|
|
26
|
+
async sendMessage({ channel, text }) {
|
|
27
|
+
const token = import_secret_manager.secretManager.get("SLACK_BOT_TOKEN");
|
|
28
|
+
if (!token) throw new Error("[Slack Client] SLACK_BOT_TOKEN is not set");
|
|
29
|
+
const response = await fetch("https://slack.com/api/chat.postMessage", {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ channel, text, mrkdwn: true, unfurl_links: true, unfurl_media: true })
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(`[Slack Client] Slack responded with status ${response.status}`);
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
if (!data.ok) {
|
|
42
|
+
throw new Error(`[Slack Client] ${data.error ?? "unknown_error"}`);
|
|
43
|
+
}
|
|
44
|
+
return { channel: data.channel, ts: data.ts };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
SlackClient
|
|
50
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { secretManager } from "../../common/utils/secret-manager.js";
|
|
3
|
+
class SlackClient {
|
|
4
|
+
async sendMessage({ channel, text }) {
|
|
5
|
+
const token = secretManager.get("SLACK_BOT_TOKEN");
|
|
6
|
+
if (!token) throw new Error("[Slack Client] SLACK_BOT_TOKEN is not set");
|
|
7
|
+
const response = await fetch("https://slack.com/api/chat.postMessage", {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Bearer ${token}`,
|
|
11
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
12
|
+
},
|
|
13
|
+
body: JSON.stringify({ channel, text, mrkdwn: true, unfurl_links: true, unfurl_media: true })
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(`[Slack Client] Slack responded with status ${response.status}`);
|
|
17
|
+
}
|
|
18
|
+
const data = await response.json();
|
|
19
|
+
if (!data.ok) {
|
|
20
|
+
throw new Error(`[Slack Client] ${data.error ?? "unknown_error"}`);
|
|
21
|
+
}
|
|
22
|
+
return { channel: data.channel, ts: data.ts };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
SlackClient
|
|
27
|
+
};
|
package/dist/tools/core/index.js
CHANGED
|
@@ -17,8 +17,10 @@ var core_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(core_exports);
|
|
18
18
|
__reExport(core_exports, require("./web-search"), module.exports);
|
|
19
19
|
__reExport(core_exports, require("./call-ai"), module.exports);
|
|
20
|
+
__reExport(core_exports, require("./slack"), module.exports);
|
|
20
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
22
|
0 && (module.exports = {
|
|
22
23
|
...require("./web-search"),
|
|
23
|
-
...require("./call-ai")
|
|
24
|
+
...require("./call-ai"),
|
|
25
|
+
...require("./slack")
|
|
24
26
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './send-slack-message.tool';
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var slack_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(slack_exports);
|
|
18
|
+
__reExport(slack_exports, require("./send-slack-message.tool"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./send-slack-message.tool")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./send-slack-message.tool";
|
|
@@ -0,0 +1,54 @@
|
|
|
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 send_slack_message_tool_exports = {};
|
|
20
|
+
__export(send_slack_message_tool_exports, {
|
|
21
|
+
sendSlackMessageTool: () => sendSlackMessageTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(send_slack_message_tool_exports);
|
|
24
|
+
var import_tool = require("../../tool");
|
|
25
|
+
var import_slack_client = require("../../../clients/slack/slack-client.js");
|
|
26
|
+
const sendSlackMessageTool = new import_tool.Tool({
|
|
27
|
+
name: "send_slack_message",
|
|
28
|
+
description: "Send a message to a Slack channel",
|
|
29
|
+
destructive: false,
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
channel: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "channel id (C0123456789) or name (#general) to send the message to"
|
|
36
|
+
},
|
|
37
|
+
text: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: 'content of the message. Use Slack mrkdwn when it helps readability: *bold*, _italic_, ~strike~, `code`, <https://url|label> for links and "- " for lists. Do not use standard Markdown (no **bold**, no # headings, no [label](url))'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
required: ["channel", "text"]
|
|
43
|
+
},
|
|
44
|
+
handler: async (params) => {
|
|
45
|
+
if (!params) throw new Error("[send_slack_message] params is required");
|
|
46
|
+
const { channel, text } = params;
|
|
47
|
+
const sent = await new import_slack_client.SlackClient().sendMessage({ channel, text });
|
|
48
|
+
return { data: sent };
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
sendSlackMessageTool
|
|
54
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { Tool } from "../../tool";
|
|
3
|
+
import { SlackClient } from "../../../clients/slack/slack-client.js";
|
|
4
|
+
const sendSlackMessageTool = new Tool({
|
|
5
|
+
name: "send_slack_message",
|
|
6
|
+
description: "Send a message to a Slack channel",
|
|
7
|
+
destructive: false,
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
channel: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "channel id (C0123456789) or name (#general) to send the message to"
|
|
14
|
+
},
|
|
15
|
+
text: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: 'content of the message. Use Slack mrkdwn when it helps readability: *bold*, _italic_, ~strike~, `code`, <https://url|label> for links and "- " for lists. Do not use standard Markdown (no **bold**, no # headings, no [label](url))'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
required: ["channel", "text"]
|
|
21
|
+
},
|
|
22
|
+
handler: async (params) => {
|
|
23
|
+
if (!params) throw new Error("[send_slack_message] params is required");
|
|
24
|
+
const { channel, text } = params;
|
|
25
|
+
const sent = await new SlackClient().sendMessage({ channel, text });
|
|
26
|
+
return { data: sent };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
export {
|
|
30
|
+
sendSlackMessageTool
|
|
31
|
+
};
|
package/docs/configuration.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
| `OPENAI_API_KEY`, `GEMINI_API_KEY` | for those providers | API keys of the other providers you choose per chat. |
|
|
12
12
|
| `JWT_SECRET` | for `login` | Secret that signs the tokens. See [authentication](authentication.md). |
|
|
13
13
|
| `SERPER_API_KEY` | for `webSearchTool` | See [tools](tools.md#built-in-tools). |
|
|
14
|
+
| `SLACK_BOT_TOKEN` | for `sendSlackMessageTool` | See [tools](tools.md#built-in-tools). |
|
|
14
15
|
| `AGENTIC_JOBS_POLL_INTERVAL_MS` | no | How often the runner of [agentic jobs](agentic-jobs.md) checks what is due, in milliseconds. Defaults to `60000`. |
|
|
15
16
|
| `AGENTIC_JOBS_LEASE_MS` | no | How long a job stays locked while it runs, in milliseconds. Defaults to `600000`. |
|
|
16
17
|
| `LLM_FALLBACK_PROVIDER`, `LLM_FALLBACK_MODEL` | no | The model to use when nothing else chooses one, for the whole deployment. Set both or neither. See [Which model a chat uses](#which-model-a-chat-uses). |
|
package/docs/tools.md
CHANGED
|
@@ -75,6 +75,18 @@ agent.addTool(webSearchTool)
|
|
|
75
75
|
|
|
76
76
|
Requires a [Serper](https://serper.dev) API key. Set `SERPER_API_KEY` in your `.env`.
|
|
77
77
|
|
|
78
|
+
### `sendSlackMessageTool`
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { sendSlackMessageTool } from 'openloops/tools'
|
|
82
|
+
|
|
83
|
+
agent.addTool(sendSlackMessageTool)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Sends a message to a Slack channel. The model gives a `channel` (an id such as `C0123456789`, or a name such as `#general`) and the `text`. It returns the `channel` id and the `ts` of the message in `data`.
|
|
87
|
+
|
|
88
|
+
Requires a Slack app with the `chat:write` scope, installed in your workspace and invited to the channel. Set its bot token in `SLACK_BOT_TOKEN`. The token belongs to the deployment, so every agent can write to any channel where the bot is.
|
|
89
|
+
|
|
78
90
|
### `callAiTool`
|
|
79
91
|
|
|
80
92
|
An LLM-backed tool for ad-hoc analysis, summarization, extraction or transformation. It is useful as a fallback when no other tool fits a step.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Agent } from 'openloops/core'
|
|
2
|
+
import { Logger } from 'openloops/common'
|
|
3
|
+
import { CurrentUser } from 'openloops/base'
|
|
4
|
+
import { AgiLoop } from 'openloops/loops'
|
|
5
|
+
import { webSearchTool, sendSlackMessageTool } from 'openloops/tools'
|
|
6
|
+
|
|
7
|
+
async function runAgentWithSlack () {
|
|
8
|
+
const logger = new Logger()
|
|
9
|
+
const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
|
|
10
|
+
|
|
11
|
+
if (!currentUser) throw new Error('[Demo] current user is not defined')
|
|
12
|
+
|
|
13
|
+
const loop = new AgiLoop()
|
|
14
|
+
const agent = new Agent({ loop })
|
|
15
|
+
agent.addTool(webSearchTool) // requires a serper api key (add SERPER_API_KEY to your .env file)
|
|
16
|
+
agent.addTool(sendSlackMessageTool) // requires a slack bot token (add SLACK_BOT_TOKEN to your .env file) and the bot invited to the channel
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const result = await agent.run({
|
|
20
|
+
input: {
|
|
21
|
+
message: 'search the price of the bitcoin and send it to the #general channel on slack',
|
|
22
|
+
},
|
|
23
|
+
currentUser,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
logger.debug(result, '[Demo] Result')
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
logger.error(error, '[Demo] Error')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
runAgentWithSlack()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openloops",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Open source harness for AI agents: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous jobs, where the loop is pluggable",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jose Barcos",
|