Skip to content

Commit 7ed9fba

Browse files
committed
Added actions
1 parent defec58 commit 7ed9fba

File tree

11 files changed

+169
-102
lines changed

11 files changed

+169
-102
lines changed

components/zep/actions/get-session-memory/get-session-memory.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/zep/actions/get-session-messages/get-session-messages.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/zep/actions/get-session/get-session.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/zep/actions/get-sessions/get-sessions.mjs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import zep from "../../zep.app.mjs";
2+
3+
export default {
4+
key: "zep-get-thread-messages",
5+
name: "Get Thread Messages",
6+
description: "Returns messages for the thread with the specified ID. [See the documentation](https://help.getzep.com/sdk-reference/thread/get)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
zep,
11+
threadId: {
12+
propDefinition: [
13+
zep,
14+
"threadId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const allMessages = [];
20+
let cursor = 0;
21+
const limit = 100; // Tamanho da página
22+
23+
while (true) {
24+
const response = await this.zep.getThreadMessages({
25+
$,
26+
threadId: this.threadId,
27+
params: {
28+
limit,
29+
cursor,
30+
},
31+
});
32+
33+
if (!response.messages || response.messages.length === 0) {
34+
break;
35+
}
36+
37+
allMessages.push(...response.messages);
38+
39+
// Se recebemos menos mensagens que o limite, chegamos ao fim
40+
if (response.messages.length < limit) {
41+
break;
42+
}
43+
44+
cursor += limit;
45+
}
46+
47+
$.export("$summary", `Successfully retrieved ${allMessages.length} messages for the thread with ID: ${this.threadId}`);
48+
49+
return allMessages;
50+
},
51+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import zep from "../../zep.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "zep-get-threads",
6+
name: "Get Threads",
7+
description: "Returns a paginated list of threads. [See the documentation](https://help.getzep.com/sdk-reference/thread/list-all)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
zep,
12+
order_by: {
13+
type: "string",
14+
label: "Order By",
15+
description: "Field to order by (e.g., updated_at).",
16+
optional: true,
17+
options: constants.SORT_OPTIONS,
18+
},
19+
asc: {
20+
type: "boolean",
21+
label: "Ascending",
22+
description: "If true, results are returned in ascending order.",
23+
optional: true,
24+
},
25+
maxResults: {
26+
type: "integer",
27+
label: "Max Results",
28+
description: "Maximum number of threads to return across pages.",
29+
optional: true,
30+
default: 50,
31+
},
32+
},
33+
async run({ $ }) {
34+
const max = this.maxResults ?? 50;
35+
const threads = [];
36+
37+
let page = 1;
38+
while (threads.length < max) {
39+
const pageSize = Math.min(1000, max - threads.length);
40+
const params = {
41+
page_number: page,
42+
page_size: pageSize,
43+
};
44+
45+
if (this.order_by) {
46+
params.order_by = this.order_by;
47+
}
48+
if (typeof this.asc === "boolean") {
49+
params.asc = this.asc;
50+
}
51+
52+
const response = await this.zep.getThreads({
53+
$,
54+
params,
55+
});
56+
57+
const pageThreads = response?.threads || [];
58+
if (!Array.isArray(pageThreads) || pageThreads.length === 0) {
59+
break;
60+
}
61+
62+
threads.push(...pageThreads);
63+
if (pageThreads.length < pageSize) {
64+
break;
65+
}
66+
67+
page += 1;
68+
}
69+
70+
const plural = threads.length === 1
71+
? ""
72+
: "s";
73+
$.export("$summary", `Successfully retrieved ${threads.length} thread${plural}`);
74+
return threads;
75+
},
76+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
SORT_OPTIONS: [
3+
"created_at",
4+
"updated_at",
5+
"user_id",
6+
"thread_id",
7+
],
8+
};

components/zep/sources/new-message/new-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "zep-new-message",
66
name: "New Message in Session",
77
description: "Emit new event when a message is added to a session. [See the documentation](https://help.getzep.com/api-reference/memory/get-session-messages)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

components/zep/sources/new-session/new-session.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "zep-new-session",
66
name: "New Session Created",
77
description: "Emit new event when a new session is created in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/list-sessions)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

components/zep/sources/session-updated/session-updated.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import common from "../common/base.mjs";
33
export default {
44
...common,
55
key: "zep-session-updated",
6-
name: "Session Updated",
6+
name: "New Session Updated",
77
description: "Emit new event when an existing session is updated. [See the documentation](https://help.getzep.com/api-reference/memory/list-sessions)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

0 commit comments

Comments
 (0)