Skip to content

Commit 7189016

Browse files
committed
Added actions
1 parent 7fa4e07 commit 7189016

File tree

5 files changed

+159
-5
lines changed

5 files changed

+159
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import app from "../../langbase.app.mjs";
2+
3+
export default {
4+
key: "langbase-create-memory",
5+
name: "Create Memory",
6+
description: "Create a new organization memory by sending the memory data. [See the documentation](https://langbase.com/docs/api-reference/memory/create)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name"
15+
]
16+
},
17+
description: {
18+
propDefinition: [
19+
app,
20+
"description"
21+
]
22+
},
23+
},
24+
25+
async run({ $ }) {
26+
const response = await this.app.createMemory({
27+
$,
28+
data: {
29+
name: this.name,
30+
description: this.description
31+
}
32+
});
33+
34+
$.export("$summary", `Successfully created memory ${this.name}`);
35+
36+
return response;
37+
},
38+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import app from "../../langbase.app.mjs";
2+
3+
export default {
4+
key: "langbase-delete-memory",
5+
name: "Delete Memory",
6+
description: "Delete an existing memory on Langbase. [See the documentation](https://langbase.com/docs/api-reference/memory/delete)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
memoryName: {
12+
propDefinition: [
13+
app,
14+
"memoryName"
15+
]
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.deleteMemory({
21+
$,
22+
memoryName: this.memoryName,
23+
});
24+
25+
$.export("$summary", `Successfully deleted memory named ${this.memoryName}`);
26+
27+
return response;
28+
},
29+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import app from "../../langbase.app.mjs";
2+
3+
export default {
4+
key: "langbase-list-memories",
5+
name: "List Memories",
6+
description: "Get a list of memory sets on Langbase. [See the documentation](https://langbase.com/docs/api-reference/memory/list)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
13+
async run({ $ }) {
14+
const response = await this.app.listMemories({
15+
$,
16+
});
17+
18+
$.export("$summary", `Successfully retrieved ${response.memorySets.length} memorysets`);
19+
20+
return response;
21+
},
22+
};
Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,73 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "langbase",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
memoryName: {
8+
type: "string",
9+
label: "Memory Name",
10+
description: "The name of the memory",
11+
async options() {
12+
const response = await this.listMemories();
13+
const memoryNames = response.memorySets;
14+
return memoryNames.map(({ name, description }) => ({
15+
label: description,
16+
value: name,
17+
}));
18+
}
19+
},
20+
name: {
21+
type: "string",
22+
label: "Name",
23+
description: "Name of the memory",
24+
},
25+
description: {
26+
type: "string",
27+
label: "Description",
28+
description: "Short description of the memory",
29+
},
30+
},
531
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
32+
_baseUrl() {
33+
return "https://api.langbase.com/beta";
34+
},
35+
async _makeRequest(opts = {}) {
36+
const {
37+
$ = this,
38+
path,
39+
headers,
40+
...otherOpts
41+
} = opts;
42+
return axios($, {
43+
...otherOpts,
44+
url: this._baseUrl() + path,
45+
headers: {
46+
...headers,
47+
Authorization: `Bearer ${this.$auth.org_api_key}`,
48+
"Accept": `application/json`,
49+
},
50+
});
51+
},
52+
async createMemory(args = {}) {
53+
return this._makeRequest({
54+
path: `/org/${this.$auth.org}/memorysets`,
55+
method: "post",
56+
...args,
57+
});
58+
},
59+
async deleteMemory({ memoryName, ...args }) {
60+
return this._makeRequest({
61+
path: `/memorysets/sergio19733/${memoryName}`,
62+
method: "delete",
63+
...args,
64+
});
65+
},
66+
async listMemories(args = {}) {
67+
return this._makeRequest({
68+
path: `/org/${this.$auth.org}/memorysets`,
69+
...args,
70+
});
971
},
1072
},
1173
};

components/langbase/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)