mneme-sdk 0.3.0 → 0.4.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,31 @@ 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
+ /**
161
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
162
+ * distribute scoped keys to end-users who don't have wallets.
163
+ *
164
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
165
+ */
166
+ serviceKeys = {
167
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
168
+ create: (args) => this.request("POST", "/v1/service/keys", args),
169
+ /** List all keys you've created (no raw values — only metadata). */
170
+ list: () => this.request("GET", "/v1/service/keys"),
171
+ /** Revoke a key by id. */
172
+ revoke: (id) => this.request("DELETE", `/v1/service/keys/${id}`)
173
+ };
143
174
  /**
144
175
  * Run raw SQL against your project's Postgres schema.
145
176
  *
@@ -206,7 +237,9 @@ var Mneme = class {
206
237
  async request(method, path, body) {
207
238
  const bodyText = body === void 0 ? "" : JSON.stringify(body);
208
239
  const headers = { "Content-Type": "application/json" };
209
- if ("accessToken" in this.auth && this.auth.accessToken) {
240
+ if ("apiKey" in this.auth && this.auth.apiKey) {
241
+ headers["Authorization"] = `ApiKey ${this.auth.apiKey}`;
242
+ } else if ("accessToken" in this.auth && this.auth.accessToken) {
210
243
  headers["Authorization"] = `Bearer ${this.auth.accessToken}`;
211
244
  } else if ("account" in this.auth && this.auth.account) {
212
245
  const signed = await signRequest({
@@ -220,7 +253,7 @@ var Mneme = class {
220
253
  });
221
254
  Object.assign(headers, signed);
222
255
  } else {
223
- throw new Error("Mneme: either { account } or { accessToken } is required");
256
+ throw new Error("Mneme: one of { account }, { accessToken }, or { apiKey } is required");
224
257
  }
225
258
  const res = await fetch(`${this.gatewayUrl}${path}`, {
226
259
  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,63 @@ 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
+ /**
136
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
137
+ * distribute scoped keys to end-users who don't have wallets.
138
+ *
139
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
140
+ */
141
+ readonly serviceKeys: {
142
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
143
+ create: (args: {
144
+ scope: string;
145
+ label?: string;
146
+ rpm_limit?: number;
147
+ }) => Promise<{
148
+ ok: true;
149
+ id: number;
150
+ key: string;
151
+ key_prefix: string;
152
+ scope: string;
153
+ label: string | null;
154
+ rpm_limit: number;
155
+ created_at: string;
156
+ warning: string;
157
+ }>;
158
+ /** List all keys you've created (no raw values — only metadata). */
159
+ list: () => Promise<{
160
+ keys: Array<{
161
+ id: number;
162
+ key_prefix: string;
163
+ scope: string;
164
+ label: string | null;
165
+ rpm_limit: number;
166
+ revoked: boolean;
167
+ revoked_at: string | null;
168
+ last_used_at: string | null;
169
+ created_at: string;
170
+ }>;
171
+ }>;
172
+ /** Revoke a key by id. */
173
+ revoke: (id: number) => Promise<{
174
+ ok: true;
175
+ id: number;
176
+ }>;
177
+ };
115
178
  /**
116
179
  * Run raw SQL against your project's Postgres schema.
117
180
  *
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,63 @@ 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
+ /**
136
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
137
+ * distribute scoped keys to end-users who don't have wallets.
138
+ *
139
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
140
+ */
141
+ readonly serviceKeys: {
142
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
143
+ create: (args: {
144
+ scope: string;
145
+ label?: string;
146
+ rpm_limit?: number;
147
+ }) => Promise<{
148
+ ok: true;
149
+ id: number;
150
+ key: string;
151
+ key_prefix: string;
152
+ scope: string;
153
+ label: string | null;
154
+ rpm_limit: number;
155
+ created_at: string;
156
+ warning: string;
157
+ }>;
158
+ /** List all keys you've created (no raw values — only metadata). */
159
+ list: () => Promise<{
160
+ keys: Array<{
161
+ id: number;
162
+ key_prefix: string;
163
+ scope: string;
164
+ label: string | null;
165
+ rpm_limit: number;
166
+ revoked: boolean;
167
+ revoked_at: string | null;
168
+ last_used_at: string | null;
169
+ created_at: string;
170
+ }>;
171
+ }>;
172
+ /** Revoke a key by id. */
173
+ revoke: (id: number) => Promise<{
174
+ ok: true;
175
+ id: number;
176
+ }>;
177
+ };
115
178
  /**
116
179
  * Run raw SQL against your project's Postgres schema.
117
180
  *
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,31 @@ 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
+ /**
129
+ * Service-account API keys — for B2B2C integrators (e.g. Gitlawb) that
130
+ * distribute scoped keys to end-users who don't have wallets.
131
+ *
132
+ * Only callable by wallet-authed clients (keys cannot mint more keys).
133
+ */
134
+ serviceKeys = {
135
+ /** Mint a new scoped key. Returns the raw key value ONCE. */
136
+ create: (args) => this.request("POST", "/v1/service/keys", args),
137
+ /** List all keys you've created (no raw values — only metadata). */
138
+ list: () => this.request("GET", "/v1/service/keys"),
139
+ /** Revoke a key by id. */
140
+ revoke: (id) => this.request("DELETE", `/v1/service/keys/${id}`)
141
+ };
111
142
  /**
112
143
  * Run raw SQL against your project's Postgres schema.
113
144
  *
@@ -174,7 +205,9 @@ var Mneme = class {
174
205
  async request(method, path, body) {
175
206
  const bodyText = body === void 0 ? "" : JSON.stringify(body);
176
207
  const headers = { "Content-Type": "application/json" };
177
- if ("accessToken" in this.auth && this.auth.accessToken) {
208
+ if ("apiKey" in this.auth && this.auth.apiKey) {
209
+ headers["Authorization"] = `ApiKey ${this.auth.apiKey}`;
210
+ } else if ("accessToken" in this.auth && this.auth.accessToken) {
178
211
  headers["Authorization"] = `Bearer ${this.auth.accessToken}`;
179
212
  } else if ("account" in this.auth && this.auth.account) {
180
213
  const signed = await signRequest({
@@ -188,7 +221,7 @@ var Mneme = class {
188
221
  });
189
222
  Object.assign(headers, signed);
190
223
  } else {
191
- throw new Error("Mneme: either { account } or { accessToken } is required");
224
+ throw new Error("Mneme: one of { account }, { accessToken }, or { apiKey } is required");
192
225
  }
193
226
  const res = await fetch(`${this.gatewayUrl}${path}`, {
194
227
  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.4.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",