@memoy-dev/sdk 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +2 -5
  2. package/readme.md +39 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memoy-dev/sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Run your memoy agents from any JavaScript runtime.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,10 +15,7 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "files": [
19
- "dist/index.js",
20
- "dist/index.d.ts"
21
- ],
18
+ "files": ["dist/index.js", "dist/index.d.ts"],
22
19
  "scripts": {
23
20
  "build": "rm -rf dist && bun build ./index.ts --outdir dist --target browser --dts",
24
21
  "typecheck": "bun check",
package/readme.md CHANGED
@@ -6,11 +6,49 @@ Run your memoy agents from any JavaScript runtime (Node, Bun, Deno, edge, browse
6
6
  npm install @memoy-dev/sdk
7
7
  ```
8
8
 
9
+ ## Example
10
+
11
+ ```ts
12
+ import { Memoy, MemoyError } from "@memoy-dev/sdk"
13
+
14
+ const memoy = new Memoy({ apiKey: "memoy_live_..." })
15
+
16
+ // With a key, the agent remembers this user across conversations
17
+ const reply = await memoy.run({
18
+ agent: "support",
19
+ key: "user-42",
20
+ input: "Hi, I prefer to be contacted by email.",
21
+ })
22
+ console.log(reply.content)
23
+
24
+ // What the agent learned about the user
25
+ const memories = await memoy.memories.search({ agent: "support", key: "user-42" })
26
+
27
+ // The conversation history, newest first
28
+ const { messages, total } = await memoy.messages.list({ agent: "support", key: "user-42" })
29
+
30
+ // A human takes over and replies: stored without running the agent nor spending credits
31
+ await memoy.messages.record({
32
+ agent: "support",
33
+ key: "user-42",
34
+ messages: [{ role: "agent", content: "Hi, this is Ana from support." }],
35
+ })
36
+
37
+ // API errors throw a MemoyError
38
+ try {
39
+ await memoy.run({ agent: "missing-agent", input: "Hi" })
40
+ } catch (error) {
41
+ if (error instanceof MemoyError) console.log(error.status, error.message)
42
+ }
43
+ ```
44
+
45
+ ## Usage
46
+
9
47
  ```ts
10
48
  import { Memoy, MemoyError } from "@memoy-dev/sdk"
11
49
 
12
50
  // apiKey defaults to process.env.MEMOY_API_KEY
13
- const memoy = new Memoy({ apiKey: "db_live_..." })
51
+ const memoy = new Memoy({ apiKey: "memoy_live_..." })
14
52
 
15
53
  // Runs on the agent's own model.
16
54
  const reply = await memoy.run({ agent: "your-agent-slug", input: "Hi!" })