@agentmem/sdk 0.6.0

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 ADDED
@@ -0,0 +1,42 @@
1
+ # @agentmem/sdk
2
+
3
+ TypeScript SDK for [AgentMem](https://agentmem.dev) — the memory API for AI agents.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @agentmem/sdk
9
+ # or
10
+ pnpm add @agentmem/sdk
11
+ # or
12
+ yarn add @agentmem/sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { MemoryStore } from '@agentmem/sdk'
19
+
20
+ const mem = new MemoryStore({
21
+ apiKey: process.env.AGENTMEM_API_KEY!,
22
+ // baseUrl: 'https://your-self-hosted.example.com/functions/v1/api', // optional
23
+ })
24
+
25
+ await mem.write({
26
+ content: 'user prefers dark mode',
27
+ agentId: 'agent-1',
28
+ scope: 'user',
29
+ })
30
+
31
+ const hits = await mem.search({
32
+ query: 'theme preference',
33
+ agentId: 'agent-1',
34
+ topK: 5,
35
+ })
36
+ ```
37
+
38
+ See [`src/types.ts`](./src/types.ts) for the full type surface (writes, search, conflicts, scratch, API keys, teams, policies, webhooks, retention, usage, batch).
39
+
40
+ ## License
41
+
42
+ [Apache-2.0](../LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,178 @@
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
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AgentMemError: () => AgentMemError,
24
+ DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
25
+ MemoryStore: () => MemoryStore
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/client.ts
30
+ var DEFAULT_BASE_URL = "https://lwbwcuuzoituanwhekyo.supabase.co/functions/v1/api";
31
+ var MemoryStore = class {
32
+ constructor(opts) {
33
+ this.apiKey = opts.apiKey;
34
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
35
+ }
36
+ async req(method, path, body) {
37
+ const r = await fetch(`${this.baseUrl}${path}`, {
38
+ method,
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ "Authorization": `Bearer ${this.apiKey}`
42
+ },
43
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
44
+ });
45
+ if (r.status === 204) return null;
46
+ const json = await r.json();
47
+ if (!r.ok) {
48
+ throw new AgentMemError(json?.error ?? `HTTP ${r.status}`, r.status);
49
+ }
50
+ return json;
51
+ }
52
+ // ── Memory ────────────────────────────────────────────────────────────────
53
+ async write(params) {
54
+ return this.req("POST", "/v1/memory/write", params);
55
+ }
56
+ async search(params) {
57
+ return this.req("POST", "/v1/memory/search", params);
58
+ }
59
+ async get(id) {
60
+ return this.req("GET", `/v1/memory/${id}`);
61
+ }
62
+ async delete(id) {
63
+ return this.req("DELETE", `/v1/memory/${id}`);
64
+ }
65
+ async checkConflicts(params) {
66
+ return this.req("POST", "/v1/memory/conflicts", params);
67
+ }
68
+ // ── Batch ─────────────────────────────────────────────────────────────────
69
+ async batchWrite(writes) {
70
+ return this.req("POST", "/v1/memory/batch/write", { writes });
71
+ }
72
+ async batchSearch(searches) {
73
+ return this.req("POST", "/v1/memory/batch/search", { searches });
74
+ }
75
+ // ── Scratch ───────────────────────────────────────────────────────────────
76
+ async scratchSet(params) {
77
+ const { ttlSecs, ...rest } = params;
78
+ return this.req("POST", "/v1/scratch/set", { ...rest, ttl: ttlSecs });
79
+ }
80
+ async scratchGet(workflowId, key) {
81
+ const r = await this.req("POST", "/v1/scratch/get", { workflowId, key });
82
+ return r.value;
83
+ }
84
+ async scratchDel(workflowId, key) {
85
+ return this.req("POST", "/v1/scratch/del", { workflowId, key });
86
+ }
87
+ // ── Workflows ─────────────────────────────────────────────────────────────
88
+ async summarize(workflowId, agentId) {
89
+ const r = await this.req("POST", `/v1/workflows/${workflowId}/summarize`, { agentId });
90
+ return r.summary;
91
+ }
92
+ async workflowMemories(workflowId) {
93
+ return this.req("GET", `/v1/workflows/${workflowId}/memories`);
94
+ }
95
+ // ── API Keys ──────────────────────────────────────────────────────────────
96
+ async listKeys() {
97
+ const r = await this.req("GET", "/v1/keys");
98
+ return r.keys;
99
+ }
100
+ async createKey(params) {
101
+ return this.req("POST", "/v1/keys", params);
102
+ }
103
+ async revokeKey(id) {
104
+ return this.req("DELETE", `/v1/keys/${id}`);
105
+ }
106
+ // ── Teams ─────────────────────────────────────────────────────────────────
107
+ async listTeams() {
108
+ const r = await this.req("GET", "/v1/teams");
109
+ return r.teams;
110
+ }
111
+ async createTeam(name) {
112
+ return this.req("POST", "/v1/teams", { name });
113
+ }
114
+ async deleteTeam(id) {
115
+ return this.req("DELETE", `/v1/teams/${id}`);
116
+ }
117
+ // ── Conflict policies ─────────────────────────────────────────────────────
118
+ async listPolicies() {
119
+ const r = await this.req("GET", "/v1/policies");
120
+ return r.policies;
121
+ }
122
+ async setPolicy(params) {
123
+ return this.req("PUT", "/v1/policies", params);
124
+ }
125
+ async deletePolicy(id) {
126
+ return this.req("DELETE", `/v1/policies/${id}`);
127
+ }
128
+ // ── Webhooks ──────────────────────────────────────────────────────────────
129
+ async listWebhooks() {
130
+ const r = await this.req("GET", "/v1/webhooks");
131
+ return r.webhooks;
132
+ }
133
+ async createWebhook(params) {
134
+ return this.req("POST", "/v1/webhooks", params);
135
+ }
136
+ async enableWebhook(id) {
137
+ return this.req("PATCH", `/v1/webhooks/${id}`, { active: true });
138
+ }
139
+ async disableWebhook(id) {
140
+ return this.req("PATCH", `/v1/webhooks/${id}`, { active: false });
141
+ }
142
+ async deleteWebhook(id) {
143
+ return this.req("DELETE", `/v1/webhooks/${id}`);
144
+ }
145
+ // ── Org settings ──────────────────────────────────────────────────────────
146
+ async registerByok(customerKey) {
147
+ return this.req("POST", "/v1/org/byok", { customerKey });
148
+ }
149
+ async removeByok() {
150
+ return this.req("DELETE", "/v1/org/byok");
151
+ }
152
+ async getRetention() {
153
+ return this.req("GET", "/v1/org/retention");
154
+ }
155
+ async setRetention(params) {
156
+ return this.req("PUT", "/v1/org/retention", params);
157
+ }
158
+ async getWorkflowUsage(days = 30) {
159
+ const r = await this.req(
160
+ "GET",
161
+ `/v1/org/usage/workflows?days=${days}`
162
+ );
163
+ return r.workflows;
164
+ }
165
+ };
166
+ var AgentMemError = class extends Error {
167
+ constructor(message, status) {
168
+ super(message);
169
+ this.status = status;
170
+ this.name = "AgentMemError";
171
+ }
172
+ };
173
+ // Annotate the CommonJS export names for ESM import in node:
174
+ 0 && (module.exports = {
175
+ AgentMemError,
176
+ DEFAULT_BASE_URL,
177
+ MemoryStore
178
+ });
@@ -0,0 +1,197 @@
1
+ interface ClientOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ type Scope = 'private' | 'team' | 'global';
6
+ type Role = 'planner' | 'executor' | 'observer';
7
+ type ConflictPolicy = 'ignore' | 'planner_wins' | 'timestamp_wins' | 'human_in_loop';
8
+ type WebhookEvent = 'memory.written' | 'memory.deleted' | 'memory.conflict_blocked' | 'memory.superseded';
9
+ interface WriteParams {
10
+ content: string;
11
+ agentId: string;
12
+ scope?: Scope;
13
+ role?: Role;
14
+ workflowId?: string;
15
+ expiresAt?: string;
16
+ }
17
+ interface WriteResult {
18
+ writeId: string;
19
+ duplicate?: boolean;
20
+ }
21
+ interface SearchParams {
22
+ query: string;
23
+ agentId: string;
24
+ workflowId?: string;
25
+ topK?: number;
26
+ scope?: Scope;
27
+ atTime?: string;
28
+ }
29
+ interface MemoryHit {
30
+ id: string;
31
+ content: string;
32
+ agent_id: string;
33
+ scope: string;
34
+ role: string | null;
35
+ workflow_id: string | null;
36
+ created_at: string;
37
+ score: number;
38
+ vector_clock?: Record<string, number>;
39
+ }
40
+ interface Memory {
41
+ id: string;
42
+ content: string;
43
+ agent_id: string;
44
+ scope: string;
45
+ role: string | null;
46
+ workflow_id: string | null;
47
+ created_at: string;
48
+ expires_at: string | null;
49
+ extracted: boolean;
50
+ encrypted: boolean;
51
+ vector_clock?: Record<string, number>;
52
+ }
53
+ interface Conflict {
54
+ memoryId: string;
55
+ severity: 'high' | 'low';
56
+ description: string;
57
+ }
58
+ interface ConflictResult {
59
+ conflicts: Conflict[];
60
+ }
61
+ interface ScratchSetParams {
62
+ workflowId: string;
63
+ key: string;
64
+ value: string;
65
+ ttlSecs?: number;
66
+ }
67
+ interface ApiKey {
68
+ id: string;
69
+ name: string;
70
+ key_prefix: string;
71
+ tier: string;
72
+ scoped_agent: string | null;
73
+ scoped_scope: string | null;
74
+ created_at: string;
75
+ last_used_at: string | null;
76
+ revoked_at: string | null;
77
+ }
78
+ interface CreateKeyParams {
79
+ name: string;
80
+ tier?: string;
81
+ scopedAgent?: string;
82
+ scopedScope?: string;
83
+ }
84
+ interface CreateKeyResult {
85
+ key: string;
86
+ id: string;
87
+ }
88
+ interface Team {
89
+ id: string;
90
+ name: string;
91
+ created_at: string;
92
+ }
93
+ interface Policy {
94
+ id: string;
95
+ workflow_id: string | null;
96
+ policy: ConflictPolicy;
97
+ webhook_url: string | null;
98
+ created_at: string;
99
+ }
100
+ interface SetPolicyParams {
101
+ policy: ConflictPolicy;
102
+ workflowId?: string;
103
+ webhookUrl?: string | null;
104
+ }
105
+ interface Webhook {
106
+ id: string;
107
+ url: string;
108
+ events: WebhookEvent[];
109
+ active: boolean;
110
+ created_at: string;
111
+ secret?: string;
112
+ }
113
+ interface CreateWebhookParams {
114
+ url: string;
115
+ events: WebhookEvent[];
116
+ }
117
+ interface Retention {
118
+ memoriesDays: number | null;
119
+ auditDays: number;
120
+ scratchDays: number;
121
+ }
122
+ interface WorkflowUsage {
123
+ writes: number;
124
+ searches: number;
125
+ }
126
+ interface BatchWriteResult {
127
+ results: Array<{
128
+ writeId?: string;
129
+ duplicate?: boolean;
130
+ error?: string;
131
+ }>;
132
+ }
133
+ interface BatchSearchResult {
134
+ results: Array<MemoryHit[] | {
135
+ error: string;
136
+ }>;
137
+ }
138
+
139
+ declare const DEFAULT_BASE_URL = "https://lwbwcuuzoituanwhekyo.supabase.co/functions/v1/api";
140
+ declare class MemoryStore {
141
+ private readonly apiKey;
142
+ private readonly baseUrl;
143
+ constructor(opts: ClientOptions);
144
+ private req;
145
+ write(params: WriteParams): Promise<WriteResult>;
146
+ search(params: SearchParams): Promise<MemoryHit[]>;
147
+ get(id: string): Promise<Memory>;
148
+ delete(id: string): Promise<void>;
149
+ checkConflicts(params: {
150
+ content: string;
151
+ agentId: string;
152
+ workflowId?: string;
153
+ scope?: string;
154
+ }): Promise<ConflictResult>;
155
+ batchWrite(writes: WriteParams[]): Promise<BatchWriteResult>;
156
+ batchSearch(searches: SearchParams[]): Promise<BatchSearchResult>;
157
+ scratchSet(params: ScratchSetParams): Promise<void>;
158
+ scratchGet(workflowId: string, key: string): Promise<string | null>;
159
+ scratchDel(workflowId: string, key: string): Promise<void>;
160
+ summarize(workflowId: string, agentId: string): Promise<string>;
161
+ workflowMemories(workflowId: string): Promise<MemoryHit[]>;
162
+ listKeys(): Promise<ApiKey[]>;
163
+ createKey(params: CreateKeyParams): Promise<CreateKeyResult>;
164
+ revokeKey(id: string): Promise<void>;
165
+ listTeams(): Promise<Team[]>;
166
+ createTeam(name: string): Promise<Team>;
167
+ deleteTeam(id: string): Promise<void>;
168
+ listPolicies(): Promise<Policy[]>;
169
+ setPolicy(params: SetPolicyParams): Promise<Policy>;
170
+ deletePolicy(id: string): Promise<void>;
171
+ listWebhooks(): Promise<Webhook[]>;
172
+ createWebhook(params: CreateWebhookParams): Promise<Webhook & {
173
+ secret: string;
174
+ }>;
175
+ enableWebhook(id: string): Promise<Webhook>;
176
+ disableWebhook(id: string): Promise<Webhook>;
177
+ deleteWebhook(id: string): Promise<void>;
178
+ registerByok(customerKey: string): Promise<{
179
+ ok: boolean;
180
+ message: string;
181
+ }>;
182
+ removeByok(): Promise<{
183
+ ok: boolean;
184
+ warning: string;
185
+ }>;
186
+ getRetention(): Promise<Retention>;
187
+ setRetention(params: Retention): Promise<{
188
+ ok: boolean;
189
+ }>;
190
+ getWorkflowUsage(days?: number): Promise<Record<string, WorkflowUsage>>;
191
+ }
192
+ declare class AgentMemError extends Error {
193
+ readonly status: number;
194
+ constructor(message: string, status: number);
195
+ }
196
+
197
+ export { AgentMemError, type ApiKey, type BatchSearchResult, type BatchWriteResult, type ClientOptions, type Conflict, type ConflictPolicy, type ConflictResult, type CreateKeyParams, type CreateKeyResult, type CreateWebhookParams, DEFAULT_BASE_URL, type Memory, type MemoryHit, MemoryStore, type Policy, type Retention, type Role, type Scope, type ScratchSetParams, type SearchParams, type SetPolicyParams, type Team, type Webhook, type WebhookEvent, type WorkflowUsage, type WriteParams, type WriteResult };
@@ -0,0 +1,197 @@
1
+ interface ClientOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ type Scope = 'private' | 'team' | 'global';
6
+ type Role = 'planner' | 'executor' | 'observer';
7
+ type ConflictPolicy = 'ignore' | 'planner_wins' | 'timestamp_wins' | 'human_in_loop';
8
+ type WebhookEvent = 'memory.written' | 'memory.deleted' | 'memory.conflict_blocked' | 'memory.superseded';
9
+ interface WriteParams {
10
+ content: string;
11
+ agentId: string;
12
+ scope?: Scope;
13
+ role?: Role;
14
+ workflowId?: string;
15
+ expiresAt?: string;
16
+ }
17
+ interface WriteResult {
18
+ writeId: string;
19
+ duplicate?: boolean;
20
+ }
21
+ interface SearchParams {
22
+ query: string;
23
+ agentId: string;
24
+ workflowId?: string;
25
+ topK?: number;
26
+ scope?: Scope;
27
+ atTime?: string;
28
+ }
29
+ interface MemoryHit {
30
+ id: string;
31
+ content: string;
32
+ agent_id: string;
33
+ scope: string;
34
+ role: string | null;
35
+ workflow_id: string | null;
36
+ created_at: string;
37
+ score: number;
38
+ vector_clock?: Record<string, number>;
39
+ }
40
+ interface Memory {
41
+ id: string;
42
+ content: string;
43
+ agent_id: string;
44
+ scope: string;
45
+ role: string | null;
46
+ workflow_id: string | null;
47
+ created_at: string;
48
+ expires_at: string | null;
49
+ extracted: boolean;
50
+ encrypted: boolean;
51
+ vector_clock?: Record<string, number>;
52
+ }
53
+ interface Conflict {
54
+ memoryId: string;
55
+ severity: 'high' | 'low';
56
+ description: string;
57
+ }
58
+ interface ConflictResult {
59
+ conflicts: Conflict[];
60
+ }
61
+ interface ScratchSetParams {
62
+ workflowId: string;
63
+ key: string;
64
+ value: string;
65
+ ttlSecs?: number;
66
+ }
67
+ interface ApiKey {
68
+ id: string;
69
+ name: string;
70
+ key_prefix: string;
71
+ tier: string;
72
+ scoped_agent: string | null;
73
+ scoped_scope: string | null;
74
+ created_at: string;
75
+ last_used_at: string | null;
76
+ revoked_at: string | null;
77
+ }
78
+ interface CreateKeyParams {
79
+ name: string;
80
+ tier?: string;
81
+ scopedAgent?: string;
82
+ scopedScope?: string;
83
+ }
84
+ interface CreateKeyResult {
85
+ key: string;
86
+ id: string;
87
+ }
88
+ interface Team {
89
+ id: string;
90
+ name: string;
91
+ created_at: string;
92
+ }
93
+ interface Policy {
94
+ id: string;
95
+ workflow_id: string | null;
96
+ policy: ConflictPolicy;
97
+ webhook_url: string | null;
98
+ created_at: string;
99
+ }
100
+ interface SetPolicyParams {
101
+ policy: ConflictPolicy;
102
+ workflowId?: string;
103
+ webhookUrl?: string | null;
104
+ }
105
+ interface Webhook {
106
+ id: string;
107
+ url: string;
108
+ events: WebhookEvent[];
109
+ active: boolean;
110
+ created_at: string;
111
+ secret?: string;
112
+ }
113
+ interface CreateWebhookParams {
114
+ url: string;
115
+ events: WebhookEvent[];
116
+ }
117
+ interface Retention {
118
+ memoriesDays: number | null;
119
+ auditDays: number;
120
+ scratchDays: number;
121
+ }
122
+ interface WorkflowUsage {
123
+ writes: number;
124
+ searches: number;
125
+ }
126
+ interface BatchWriteResult {
127
+ results: Array<{
128
+ writeId?: string;
129
+ duplicate?: boolean;
130
+ error?: string;
131
+ }>;
132
+ }
133
+ interface BatchSearchResult {
134
+ results: Array<MemoryHit[] | {
135
+ error: string;
136
+ }>;
137
+ }
138
+
139
+ declare const DEFAULT_BASE_URL = "https://lwbwcuuzoituanwhekyo.supabase.co/functions/v1/api";
140
+ declare class MemoryStore {
141
+ private readonly apiKey;
142
+ private readonly baseUrl;
143
+ constructor(opts: ClientOptions);
144
+ private req;
145
+ write(params: WriteParams): Promise<WriteResult>;
146
+ search(params: SearchParams): Promise<MemoryHit[]>;
147
+ get(id: string): Promise<Memory>;
148
+ delete(id: string): Promise<void>;
149
+ checkConflicts(params: {
150
+ content: string;
151
+ agentId: string;
152
+ workflowId?: string;
153
+ scope?: string;
154
+ }): Promise<ConflictResult>;
155
+ batchWrite(writes: WriteParams[]): Promise<BatchWriteResult>;
156
+ batchSearch(searches: SearchParams[]): Promise<BatchSearchResult>;
157
+ scratchSet(params: ScratchSetParams): Promise<void>;
158
+ scratchGet(workflowId: string, key: string): Promise<string | null>;
159
+ scratchDel(workflowId: string, key: string): Promise<void>;
160
+ summarize(workflowId: string, agentId: string): Promise<string>;
161
+ workflowMemories(workflowId: string): Promise<MemoryHit[]>;
162
+ listKeys(): Promise<ApiKey[]>;
163
+ createKey(params: CreateKeyParams): Promise<CreateKeyResult>;
164
+ revokeKey(id: string): Promise<void>;
165
+ listTeams(): Promise<Team[]>;
166
+ createTeam(name: string): Promise<Team>;
167
+ deleteTeam(id: string): Promise<void>;
168
+ listPolicies(): Promise<Policy[]>;
169
+ setPolicy(params: SetPolicyParams): Promise<Policy>;
170
+ deletePolicy(id: string): Promise<void>;
171
+ listWebhooks(): Promise<Webhook[]>;
172
+ createWebhook(params: CreateWebhookParams): Promise<Webhook & {
173
+ secret: string;
174
+ }>;
175
+ enableWebhook(id: string): Promise<Webhook>;
176
+ disableWebhook(id: string): Promise<Webhook>;
177
+ deleteWebhook(id: string): Promise<void>;
178
+ registerByok(customerKey: string): Promise<{
179
+ ok: boolean;
180
+ message: string;
181
+ }>;
182
+ removeByok(): Promise<{
183
+ ok: boolean;
184
+ warning: string;
185
+ }>;
186
+ getRetention(): Promise<Retention>;
187
+ setRetention(params: Retention): Promise<{
188
+ ok: boolean;
189
+ }>;
190
+ getWorkflowUsage(days?: number): Promise<Record<string, WorkflowUsage>>;
191
+ }
192
+ declare class AgentMemError extends Error {
193
+ readonly status: number;
194
+ constructor(message: string, status: number);
195
+ }
196
+
197
+ export { AgentMemError, type ApiKey, type BatchSearchResult, type BatchWriteResult, type ClientOptions, type Conflict, type ConflictPolicy, type ConflictResult, type CreateKeyParams, type CreateKeyResult, type CreateWebhookParams, DEFAULT_BASE_URL, type Memory, type MemoryHit, MemoryStore, type Policy, type Retention, type Role, type Scope, type ScratchSetParams, type SearchParams, type SetPolicyParams, type Team, type Webhook, type WebhookEvent, type WorkflowUsage, type WriteParams, type WriteResult };
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ // src/client.ts
2
+ var DEFAULT_BASE_URL = "https://lwbwcuuzoituanwhekyo.supabase.co/functions/v1/api";
3
+ var MemoryStore = class {
4
+ constructor(opts) {
5
+ this.apiKey = opts.apiKey;
6
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
7
+ }
8
+ async req(method, path, body) {
9
+ const r = await fetch(`${this.baseUrl}${path}`, {
10
+ method,
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ "Authorization": `Bearer ${this.apiKey}`
14
+ },
15
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
16
+ });
17
+ if (r.status === 204) return null;
18
+ const json = await r.json();
19
+ if (!r.ok) {
20
+ throw new AgentMemError(json?.error ?? `HTTP ${r.status}`, r.status);
21
+ }
22
+ return json;
23
+ }
24
+ // ── Memory ────────────────────────────────────────────────────────────────
25
+ async write(params) {
26
+ return this.req("POST", "/v1/memory/write", params);
27
+ }
28
+ async search(params) {
29
+ return this.req("POST", "/v1/memory/search", params);
30
+ }
31
+ async get(id) {
32
+ return this.req("GET", `/v1/memory/${id}`);
33
+ }
34
+ async delete(id) {
35
+ return this.req("DELETE", `/v1/memory/${id}`);
36
+ }
37
+ async checkConflicts(params) {
38
+ return this.req("POST", "/v1/memory/conflicts", params);
39
+ }
40
+ // ── Batch ─────────────────────────────────────────────────────────────────
41
+ async batchWrite(writes) {
42
+ return this.req("POST", "/v1/memory/batch/write", { writes });
43
+ }
44
+ async batchSearch(searches) {
45
+ return this.req("POST", "/v1/memory/batch/search", { searches });
46
+ }
47
+ // ── Scratch ───────────────────────────────────────────────────────────────
48
+ async scratchSet(params) {
49
+ const { ttlSecs, ...rest } = params;
50
+ return this.req("POST", "/v1/scratch/set", { ...rest, ttl: ttlSecs });
51
+ }
52
+ async scratchGet(workflowId, key) {
53
+ const r = await this.req("POST", "/v1/scratch/get", { workflowId, key });
54
+ return r.value;
55
+ }
56
+ async scratchDel(workflowId, key) {
57
+ return this.req("POST", "/v1/scratch/del", { workflowId, key });
58
+ }
59
+ // ── Workflows ─────────────────────────────────────────────────────────────
60
+ async summarize(workflowId, agentId) {
61
+ const r = await this.req("POST", `/v1/workflows/${workflowId}/summarize`, { agentId });
62
+ return r.summary;
63
+ }
64
+ async workflowMemories(workflowId) {
65
+ return this.req("GET", `/v1/workflows/${workflowId}/memories`);
66
+ }
67
+ // ── API Keys ──────────────────────────────────────────────────────────────
68
+ async listKeys() {
69
+ const r = await this.req("GET", "/v1/keys");
70
+ return r.keys;
71
+ }
72
+ async createKey(params) {
73
+ return this.req("POST", "/v1/keys", params);
74
+ }
75
+ async revokeKey(id) {
76
+ return this.req("DELETE", `/v1/keys/${id}`);
77
+ }
78
+ // ── Teams ─────────────────────────────────────────────────────────────────
79
+ async listTeams() {
80
+ const r = await this.req("GET", "/v1/teams");
81
+ return r.teams;
82
+ }
83
+ async createTeam(name) {
84
+ return this.req("POST", "/v1/teams", { name });
85
+ }
86
+ async deleteTeam(id) {
87
+ return this.req("DELETE", `/v1/teams/${id}`);
88
+ }
89
+ // ── Conflict policies ─────────────────────────────────────────────────────
90
+ async listPolicies() {
91
+ const r = await this.req("GET", "/v1/policies");
92
+ return r.policies;
93
+ }
94
+ async setPolicy(params) {
95
+ return this.req("PUT", "/v1/policies", params);
96
+ }
97
+ async deletePolicy(id) {
98
+ return this.req("DELETE", `/v1/policies/${id}`);
99
+ }
100
+ // ── Webhooks ──────────────────────────────────────────────────────────────
101
+ async listWebhooks() {
102
+ const r = await this.req("GET", "/v1/webhooks");
103
+ return r.webhooks;
104
+ }
105
+ async createWebhook(params) {
106
+ return this.req("POST", "/v1/webhooks", params);
107
+ }
108
+ async enableWebhook(id) {
109
+ return this.req("PATCH", `/v1/webhooks/${id}`, { active: true });
110
+ }
111
+ async disableWebhook(id) {
112
+ return this.req("PATCH", `/v1/webhooks/${id}`, { active: false });
113
+ }
114
+ async deleteWebhook(id) {
115
+ return this.req("DELETE", `/v1/webhooks/${id}`);
116
+ }
117
+ // ── Org settings ──────────────────────────────────────────────────────────
118
+ async registerByok(customerKey) {
119
+ return this.req("POST", "/v1/org/byok", { customerKey });
120
+ }
121
+ async removeByok() {
122
+ return this.req("DELETE", "/v1/org/byok");
123
+ }
124
+ async getRetention() {
125
+ return this.req("GET", "/v1/org/retention");
126
+ }
127
+ async setRetention(params) {
128
+ return this.req("PUT", "/v1/org/retention", params);
129
+ }
130
+ async getWorkflowUsage(days = 30) {
131
+ const r = await this.req(
132
+ "GET",
133
+ `/v1/org/usage/workflows?days=${days}`
134
+ );
135
+ return r.workflows;
136
+ }
137
+ };
138
+ var AgentMemError = class extends Error {
139
+ constructor(message, status) {
140
+ super(message);
141
+ this.status = status;
142
+ this.name = "AgentMemError";
143
+ }
144
+ };
145
+ export {
146
+ AgentMemError,
147
+ DEFAULT_BASE_URL,
148
+ MemoryStore
149
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@agentmem/sdk",
3
+ "version": "0.6.0",
4
+ "description": "TypeScript SDK for AgentMem — the memory API for AI agents",
5
+ "license": "Apache-2.0",
6
+ "author": "rooney011 <bvsa2020@gmail.com>",
7
+ "homepage": "https://agentmem.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/rooney011/agentmem-sdk.git",
11
+ "directory": "typescript"
12
+ },
13
+ "bugs": { "url": "https://github.com/rooney011/agentmem-sdk/issues" },
14
+ "keywords": ["ai", "agents", "memory", "llm", "rag", "vector", "sdk"],
15
+ "type": "module",
16
+ "main": "./dist/index.cjs",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "files": ["dist", "README.md", "LICENSE"],
27
+ "scripts": {
28
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "devDependencies": {
32
+ "tsup": "8.3.5",
33
+ "typescript": "5.8.3"
34
+ },
35
+ "engines": { "node": ">=18" }
36
+ }