mneme-sdk 0.3.0 → 0.5.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/dist/index.cjs CHANGED
@@ -112,7 +112,13 @@ var Mneme = class {
112
112
  events;
113
113
  kvs;
114
114
  constructor(opts) {
115
- this.auth = "accessToken" in opts && opts.accessToken ? { accessToken: opts.accessToken } : { account: opts.account };
115
+ if ("apiKey" in opts && opts.apiKey) {
116
+ this.auth = { apiKey: opts.apiKey };
117
+ } else if ("accessToken" in opts && opts.accessToken) {
118
+ this.auth = { accessToken: opts.accessToken };
119
+ } else {
120
+ this.auth = { account: opts.account };
121
+ }
116
122
  this.gatewayUrl = opts.gatewayUrl.replace(/\/$/, "");
117
123
  this.chainId = opts.chainId ?? 8453;
118
124
  this.domainName = opts.domainName ?? "Mneme";
@@ -140,6 +146,41 @@ var Mneme = class {
140
146
  from(table) {
141
147
  return new Collection(this, table);
142
148
  }
149
+ /**
150
+ * Natural-language → SQL via the gateway's LLM proxy.
151
+ * Use the returned SQL with `m.sql(...)` to execute it.
152
+ */
153
+ llm = {
154
+ sql: (args) => this.request(
155
+ "POST",
156
+ "/v1/llm/sql",
157
+ args
158
+ ),
159
+ /**
160
+ * Free-form chat with the Mneme assistant. Server-side LLM is told
161
+ * about your schema and Base ecosystem — useful for "what does this
162
+ * SQL do", "how do I do vector search", "what's pgvector", etc.
163
+ */
164
+ chat: (args) => this.request(
165
+ "POST",
166
+ "/v1/llm/chat",
167
+ args
168
+ )
169
+ };
170
+ /**
171
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
172
+ * distribute scoped keys to end-users who don't have wallets.
173
+ *
174
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
175
+ */
176
+ serviceKeys = {
177
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
178
+ create: (args) => this.request("POST", "/v1/service/keys", args),
179
+ /** List all keys you've created (no raw values — only metadata). */
180
+ list: () => this.request("GET", "/v1/service/keys"),
181
+ /** Revoke a key by id. */
182
+ revoke: (id) => this.request("DELETE", `/v1/service/keys/${id}`)
183
+ };
143
184
  /**
144
185
  * Run raw SQL against your project's Postgres schema.
145
186
  *
@@ -206,7 +247,9 @@ var Mneme = class {
206
247
  async request(method, path, body) {
207
248
  const bodyText = body === void 0 ? "" : JSON.stringify(body);
208
249
  const headers = { "Content-Type": "application/json" };
209
- if ("accessToken" in this.auth && this.auth.accessToken) {
250
+ if ("apiKey" in this.auth && this.auth.apiKey) {
251
+ headers["Authorization"] = `ApiKey ${this.auth.apiKey}`;
252
+ } else if ("accessToken" in this.auth && this.auth.accessToken) {
210
253
  headers["Authorization"] = `Bearer ${this.auth.accessToken}`;
211
254
  } else if ("account" in this.auth && this.auth.account) {
212
255
  const signed = await signRequest({
@@ -220,7 +263,7 @@ var Mneme = class {
220
263
  });
221
264
  Object.assign(headers, signed);
222
265
  } else {
223
- throw new Error("Mneme: either { account } or { accessToken } is required");
266
+ throw new Error("Mneme: one of { account }, { accessToken }, or { apiKey } is required");
224
267
  }
225
268
  const res = await fetch(`${this.gatewayUrl}${path}`, {
226
269
  method,
package/dist/index.d.cts CHANGED
@@ -64,9 +64,15 @@ interface KvRow {
64
64
  type MnemeAuth = {
65
65
  account: Account;
66
66
  accessToken?: never;
67
+ apiKey?: never;
67
68
  } | {
68
69
  accessToken: string;
69
70
  account?: never;
71
+ apiKey?: never;
72
+ } | {
73
+ apiKey: string;
74
+ account?: never;
75
+ accessToken?: never;
70
76
  };
71
77
  type MnemeOptions = MnemeAuth & {
72
78
  gatewayUrl: string;
@@ -112,6 +118,79 @@ declare class Mneme {
112
118
  }>;
113
119
  stats(): Promise<StatsResponse>;
114
120
  from<T = unknown>(table: string): Collection<T>;
121
+ /**
122
+ * Natural-language → SQL via the gateway's LLM proxy.
123
+ * Use the returned SQL with `m.sql(...)` to execute it.
124
+ */
125
+ llm: {
126
+ sql: (args: {
127
+ prompt: string;
128
+ schema?: string;
129
+ }) => Promise<{
130
+ sql: string;
131
+ model: string;
132
+ elapsed_ms: number;
133
+ }>;
134
+ /**
135
+ * Free-form chat with the Mneme assistant. Server-side LLM is told
136
+ * about your schema and Base ecosystem — useful for "what does this
137
+ * SQL do", "how do I do vector search", "what's pgvector", etc.
138
+ */
139
+ chat: (args: {
140
+ prompt: string;
141
+ history?: Array<{
142
+ role: "user" | "assistant";
143
+ content: string;
144
+ }>;
145
+ }) => Promise<{
146
+ reply: string;
147
+ model: string;
148
+ elapsed_ms: number;
149
+ }>;
150
+ };
151
+ /**
152
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
153
+ * distribute scoped keys to end-users who don't have wallets.
154
+ *
155
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
156
+ */
157
+ readonly serviceKeys: {
158
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
159
+ create: (args: {
160
+ scope: string;
161
+ label?: string;
162
+ rpm_limit?: number;
163
+ }) => Promise<{
164
+ ok: true;
165
+ id: number;
166
+ key: string;
167
+ key_prefix: string;
168
+ scope: string;
169
+ label: string | null;
170
+ rpm_limit: number;
171
+ created_at: string;
172
+ warning: string;
173
+ }>;
174
+ /** List all keys you've created (no raw values — only metadata). */
175
+ list: () => Promise<{
176
+ keys: Array<{
177
+ id: number;
178
+ key_prefix: string;
179
+ scope: string;
180
+ label: string | null;
181
+ rpm_limit: number;
182
+ revoked: boolean;
183
+ revoked_at: string | null;
184
+ last_used_at: string | null;
185
+ created_at: string;
186
+ }>;
187
+ }>;
188
+ /** Revoke a key by id. */
189
+ revoke: (id: number) => Promise<{
190
+ ok: true;
191
+ id: number;
192
+ }>;
193
+ };
115
194
  /**
116
195
  * Run raw SQL against your project's Postgres schema.
117
196
  *
package/dist/index.d.ts CHANGED
@@ -64,9 +64,15 @@ interface KvRow {
64
64
  type MnemeAuth = {
65
65
  account: Account;
66
66
  accessToken?: never;
67
+ apiKey?: never;
67
68
  } | {
68
69
  accessToken: string;
69
70
  account?: never;
71
+ apiKey?: never;
72
+ } | {
73
+ apiKey: string;
74
+ account?: never;
75
+ accessToken?: never;
70
76
  };
71
77
  type MnemeOptions = MnemeAuth & {
72
78
  gatewayUrl: string;
@@ -112,6 +118,79 @@ declare class Mneme {
112
118
  }>;
113
119
  stats(): Promise<StatsResponse>;
114
120
  from<T = unknown>(table: string): Collection<T>;
121
+ /**
122
+ * Natural-language → SQL via the gateway's LLM proxy.
123
+ * Use the returned SQL with `m.sql(...)` to execute it.
124
+ */
125
+ llm: {
126
+ sql: (args: {
127
+ prompt: string;
128
+ schema?: string;
129
+ }) => Promise<{
130
+ sql: string;
131
+ model: string;
132
+ elapsed_ms: number;
133
+ }>;
134
+ /**
135
+ * Free-form chat with the Mneme assistant. Server-side LLM is told
136
+ * about your schema and Base ecosystem — useful for "what does this
137
+ * SQL do", "how do I do vector search", "what's pgvector", etc.
138
+ */
139
+ chat: (args: {
140
+ prompt: string;
141
+ history?: Array<{
142
+ role: "user" | "assistant";
143
+ content: string;
144
+ }>;
145
+ }) => Promise<{
146
+ reply: string;
147
+ model: string;
148
+ elapsed_ms: number;
149
+ }>;
150
+ };
151
+ /**
152
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
153
+ * distribute scoped keys to end-users who don't have wallets.
154
+ *
155
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
156
+ */
157
+ readonly serviceKeys: {
158
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
159
+ create: (args: {
160
+ scope: string;
161
+ label?: string;
162
+ rpm_limit?: number;
163
+ }) => Promise<{
164
+ ok: true;
165
+ id: number;
166
+ key: string;
167
+ key_prefix: string;
168
+ scope: string;
169
+ label: string | null;
170
+ rpm_limit: number;
171
+ created_at: string;
172
+ warning: string;
173
+ }>;
174
+ /** List all keys you've created (no raw values — only metadata). */
175
+ list: () => Promise<{
176
+ keys: Array<{
177
+ id: number;
178
+ key_prefix: string;
179
+ scope: string;
180
+ label: string | null;
181
+ rpm_limit: number;
182
+ revoked: boolean;
183
+ revoked_at: string | null;
184
+ last_used_at: string | null;
185
+ created_at: string;
186
+ }>;
187
+ }>;
188
+ /** Revoke a key by id. */
189
+ revoke: (id: number) => Promise<{
190
+ ok: true;
191
+ id: number;
192
+ }>;
193
+ };
115
194
  /**
116
195
  * Run raw SQL against your project's Postgres schema.
117
196
  *
package/dist/index.js CHANGED
@@ -80,7 +80,13 @@ var Mneme = class {
80
80
  events;
81
81
  kvs;
82
82
  constructor(opts) {
83
- this.auth = "accessToken" in opts && opts.accessToken ? { accessToken: opts.accessToken } : { account: opts.account };
83
+ if ("apiKey" in opts && opts.apiKey) {
84
+ this.auth = { apiKey: opts.apiKey };
85
+ } else if ("accessToken" in opts && opts.accessToken) {
86
+ this.auth = { accessToken: opts.accessToken };
87
+ } else {
88
+ this.auth = { account: opts.account };
89
+ }
84
90
  this.gatewayUrl = opts.gatewayUrl.replace(/\/$/, "");
85
91
  this.chainId = opts.chainId ?? 8453;
86
92
  this.domainName = opts.domainName ?? "Mneme";
@@ -108,6 +114,41 @@ var Mneme = class {
108
114
  from(table) {
109
115
  return new Collection(this, table);
110
116
  }
117
+ /**
118
+ * Natural-language → SQL via the gateway's LLM proxy.
119
+ * Use the returned SQL with `m.sql(...)` to execute it.
120
+ */
121
+ llm = {
122
+ sql: (args) => this.request(
123
+ "POST",
124
+ "/v1/llm/sql",
125
+ args
126
+ ),
127
+ /**
128
+ * Free-form chat with the Mneme assistant. Server-side LLM is told
129
+ * about your schema and Base ecosystem — useful for "what does this
130
+ * SQL do", "how do I do vector search", "what's pgvector", etc.
131
+ */
132
+ chat: (args) => this.request(
133
+ "POST",
134
+ "/v1/llm/chat",
135
+ args
136
+ )
137
+ };
138
+ /**
139
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
140
+ * distribute scoped keys to end-users who don't have wallets.
141
+ *
142
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
143
+ */
144
+ serviceKeys = {
145
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
146
+ create: (args) => this.request("POST", "/v1/service/keys", args),
147
+ /** List all keys you've created (no raw values — only metadata). */
148
+ list: () => this.request("GET", "/v1/service/keys"),
149
+ /** Revoke a key by id. */
150
+ revoke: (id) => this.request("DELETE", `/v1/service/keys/${id}`)
151
+ };
111
152
  /**
112
153
  * Run raw SQL against your project's Postgres schema.
113
154
  *
@@ -174,7 +215,9 @@ var Mneme = class {
174
215
  async request(method, path, body) {
175
216
  const bodyText = body === void 0 ? "" : JSON.stringify(body);
176
217
  const headers = { "Content-Type": "application/json" };
177
- if ("accessToken" in this.auth && this.auth.accessToken) {
218
+ if ("apiKey" in this.auth && this.auth.apiKey) {
219
+ headers["Authorization"] = `ApiKey ${this.auth.apiKey}`;
220
+ } else if ("accessToken" in this.auth && this.auth.accessToken) {
178
221
  headers["Authorization"] = `Bearer ${this.auth.accessToken}`;
179
222
  } else if ("account" in this.auth && this.auth.account) {
180
223
  const signed = await signRequest({
@@ -188,7 +231,7 @@ var Mneme = class {
188
231
  });
189
232
  Object.assign(headers, signed);
190
233
  } else {
191
- throw new Error("Mneme: either { account } or { accessToken } is required");
234
+ throw new Error("Mneme: one of { account }, { accessToken }, or { apiKey } is required");
192
235
  }
193
236
  const res = await fetch(`${this.gatewayUrl}${path}`, {
194
237
  method,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mneme-sdk",
3
- "version": "0.3.0",
4
- "description": "TypeScript SDK for Mneme — agent-native Postgres + R2 storage on Base. Wallet-auth, runtime DDL, full CRUD with WHERE filters, raw SQL, pgvector, wallet-bound files with $MNEME burn quota.",
3
+ "version": "0.5.0",
4
+ "description": "TypeScript SDK for Mneme — agent-native Postgres + R2 storage on Base. Wallet-auth, runtime DDL, full CRUD with WHERE filters, raw SQL, pgvector, service-account API keys for B2B2C integrations, wallet-bound files with $MNEME burn quota.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",