Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - zep #15616

Merged
merged 7 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/brillium/brillium.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
55 changes: 55 additions & 0 deletions components/zep/actions/add-memory/add-memory.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import zep from "../../zep.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "zep-add-memory",
name: "Add Memory to Session",
description: "Adds memory to an existing session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/add)",
version: "0.0.1",
type: "action",
props: {
zep,
sessionId: {
propDefinition: [
zep,
"sessionId",
],
},
messages: {
type: "string[]",
label: "Messages",
description: "An array of message objects, where each message contains a role (`norole`, `system`, `assistant`, `user`, `function`, or `tool`) and content. Example: `[{ \"content\": \"content\", \"role_type\": \"norole\" }]` [See the documentation](https://help.getzep.com/api-reference/memory/add) for more information",
},
factInstruction: {
type: "string",
label: "Fact Instruction",
description: "Additional instruction for generating the facts",
optional: true,
},
returnContext: {
type: "boolean",
label: "Return Context",
description: "Optionally return memory context relevant to the most recent messages",
optional: true,
},
summaryInstruction: {
type: "string",
label: "Summary Instructions",
description: "Additional instruction for generating the summary",
optional: true,
},
},
async run({ $ }) {
const response = await this.zep.addMemoryToSession({
sessionId: this.sessionId,
data: {
messages: utils.parseArray(this.messages),
factInstruction: this.factInstruction,
returnContext: this.returnContext,
summaryInstruction: this.summaryInstruction,
},
});
$.export("$summary", `Added memory to session ${this.sessionId}`);
return response;
},
};
64 changes: 64 additions & 0 deletions components/zep/actions/add-user/add-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import zep from "../../zep.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "zep-add-user",
name: "Add User",
description: "Adds a user in Zep. [See the documentation](https://help.getzep.com/api-reference/user/add)",
version: "0.0.1",
type: "action",
props: {
zep,
userId: {
type: "string",
label: "User ID",
description: "The unique identifier of the new user",
},
email: {
type: "string",
label: "Email",
description: "Email address of the user",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "First name of the new user",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the new user",
optional: true,
},
factRatingInstructions: {
propDefinition: [
zep,
"factRatingInstructions",
],
},
metadata: {
propDefinition: [
zep,
"metadata",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.zep.createUser({
$,
data: {
email: this.email,
first_name: this.firstName,
last_name: this.lastName,
fact_rating_instructions: utils.parseObject(this.factRatingInstructions),
metadata: utils.parseObject(this.metadata),
user_id: this.userId,
},
});
$.export("$summary", `Successfully added user with ID: ${response.id}`);
return response;
},
};
50 changes: 50 additions & 0 deletions components/zep/actions/create-session/create-session.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import zep from "../../zep.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "zep-create-session",
name: "Create Session",
description: "Creates a new session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/add-session)",
version: "0.0.1",
type: "action",
props: {
zep,
sessionId: {
type: "string",
label: "Session ID",
description: "The unique identifier of the session",
},
userId: {
propDefinition: [
zep,
"userId",
],
},
factRatingInstructions: {
propDefinition: [
zep,
"factRatingInstructions",
],
},
metadata: {
propDefinition: [
zep,
"metadata",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.zep.createSession({
$,
data: {
session_id: this.sessionId,
user_id: this.userId,
fact_rating_instructions: utils.parseObject(this.factRatingInstructions),
metadata: utils.parseObject(this.metadata),
},
});
$.export("$summary", `Created session with ID ${this.sessionId}`);
return response;
},
};
44 changes: 44 additions & 0 deletions components/zep/actions/update-session/update-session.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import zep from "../../zep.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "zep-update-session",
name: "Update Session",
description: "Updates an existing session in Zep. [See the documentation](https://help.getzep.com/api-reference/memory/update-session)",
version: "0.0.1",
type: "action",
props: {
zep,
sessionId: {
propDefinition: [
zep,
"sessionId",
],
},
metadata: {
propDefinition: [
zep,
"metadata",
],
description: "An object of key/value pairs representing the metadata to add to the session",
},
factRatingInstructions: {
propDefinition: [
zep,
"factRatingInstructions",
],
},
},
async run({ $ }) {
const response = await this.zep.updateSession({
$,
sessionId: this.sessionId,
data: {
fact_rating_instructions: utils.parseObject(this.factRatingInstructions),
metadata: utils.parseObject(this.metadata),
},
});
$.export("$summary", `Successfully updated ssession with ID ${this.sessionId}`);
return response;
},
};
30 changes: 30 additions & 0 deletions components/zep/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function parseObject(obj) {
if (!obj) {
return undefined;
}

return typeof obj === "string"
? JSON.parse(obj)
: obj;
}

function parseArray(arr) {
if (!arr) {
return undefined;
}

if (typeof arr === "string") {
return JSON.parse(arr);
}

if (Array.isArray(arr)) {
return arr.map((item) => parseObject(item));
}

return arr;
}

export default {
parseObject,
parseArray,
};
5 changes: 4 additions & 1 deletion components/zep/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zep",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Zep Components",
"main": "zep.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
80 changes: 80 additions & 0 deletions components/zep/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import zep from "../../zep.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
zep,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
async processEvent(max) {
const lastTs = this._getLastTs();
const results = await this.getNewResults(lastTs, max);
results.forEach((item) => this.emitEvent(item));
},
async getSessions({
lastTs, orderBy, max, updateLastTs = true,
}) {
const params = {
page_size: max || 1000,
order_by: orderBy,
asc: false,
};

const { sessions: results } = await this.zep.listSessions({
params,
});

const sessions = [];
for (const session of results) {
const ts = Date.parse(session[orderBy]);
if (ts >= lastTs) {
sessions.push(session);
} else {
break;
}
if (max && sessions.length >= max) {
break;
}
}

if (!sessions.length) {
return [];
}
if (updateLastTs) {
this._setLastTs(Date.parse(sessions[0][orderBy]));
}
return sessions.reverse();
},
emitEvent(item) {
const meta = this.generateMeta(item);
this.$emit(item, meta);
},
getNewResults() {
throw new Error("getNewResults is not implemented");
},
generateMeta() {
throw new Error("generateMeta is not implemented");
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
async run() {
await this.processEvent();
},
};
Loading
Loading