@agentuity/keyvalue 1.0.54
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/AGENTS.md +39 -0
- package/README.md +78 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +125 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Agent Guidelines for @agentuity/keyvalue
|
|
2
|
+
|
|
3
|
+
## Package Overview
|
|
4
|
+
|
|
5
|
+
Standalone package for the Agentuity Key-Value storage service. Provides a simple, ergonomic client for storing and retrieving key-value data.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- **Build**: `bun run build`
|
|
10
|
+
- **Typecheck**: `bun run typecheck`
|
|
11
|
+
- **Clean**: `rm -rf dist`
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
- **Runtime**: Node.js and Bun compatible
|
|
16
|
+
- **Exports**: KeyValueClient and all types from @agentuity/core/keyvalue
|
|
17
|
+
- **Dependencies**: @agentuity/core, zod
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { KeyValueClient } from '@agentuity/keyvalue';
|
|
23
|
+
|
|
24
|
+
const client = new KeyValueClient();
|
|
25
|
+
|
|
26
|
+
// Set a value
|
|
27
|
+
await client.set('my-namespace', 'my-key', { foo: 'bar' });
|
|
28
|
+
|
|
29
|
+
// Get a value
|
|
30
|
+
const result = await client.get('my-namespace', 'my-key');
|
|
31
|
+
if (result.exists) {
|
|
32
|
+
console.log(result.data);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Publishing
|
|
37
|
+
|
|
38
|
+
1. Run `bun run build`
|
|
39
|
+
2. Must publish **after** @agentuity/core
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @agentuity/keyvalue
|
|
2
|
+
|
|
3
|
+
A standalone package for the Agentuity Key-Value storage service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agentuity/keyvalue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { KeyValueClient } from '@agentuity/keyvalue';
|
|
15
|
+
|
|
16
|
+
const client = new KeyValueClient();
|
|
17
|
+
|
|
18
|
+
// Set a value with optional TTL
|
|
19
|
+
await client.set('my-namespace', 'user:123', { name: 'John', email: 'john@example.com' }, {
|
|
20
|
+
ttl: 3600 // expires in 1 hour
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Get a value
|
|
24
|
+
const result = await client.get('my-namespace', 'user:123');
|
|
25
|
+
if (result.exists) {
|
|
26
|
+
console.log('Found:', result.data);
|
|
27
|
+
console.log('Content-Type:', result.contentType);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Delete a value
|
|
31
|
+
await client.delete('my-namespace', 'user:123');
|
|
32
|
+
|
|
33
|
+
// Get namespace statistics
|
|
34
|
+
const stats = await client.getStats('my-namespace');
|
|
35
|
+
console.log(`${stats.count} keys, ${stats.sum} bytes`);
|
|
36
|
+
|
|
37
|
+
// Search for keys
|
|
38
|
+
const results = await client.search('my-namespace', 'user');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
The client can be configured with options:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const client = new KeyValueClient({
|
|
47
|
+
apiKey: 'your-api-key', // or set AGENTUITY_SDK_KEY
|
|
48
|
+
url: 'https://api.agentuity.com', // or set AGENTUITY_KV_URL
|
|
49
|
+
logger: customLogger, // optional custom logger
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Environment Variables
|
|
54
|
+
|
|
55
|
+
| Variable | Description | Default |
|
|
56
|
+
|----------|-------------|---------|
|
|
57
|
+
| `AGENTUITY_SDK_KEY` | API key for authentication | Required |
|
|
58
|
+
| `AGENTUITY_REGION` | Region for API endpoints | `usc` |
|
|
59
|
+
| `AGENTUITY_KV_URL` | Override KV API URL | Auto-detected |
|
|
60
|
+
|
|
61
|
+
## TTL (Time-to-Live)
|
|
62
|
+
|
|
63
|
+
Keys can have an optional TTL:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Key expires in 1 hour
|
|
67
|
+
await client.set('ns', 'key', value, { ttl: 3600 });
|
|
68
|
+
|
|
69
|
+
// Key never expires
|
|
70
|
+
await client.set('ns', 'key', value, { ttl: null });
|
|
71
|
+
|
|
72
|
+
// Key uses namespace default TTL
|
|
73
|
+
await client.set('ns', 'key', value);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export { KeyValueStorageService, KeyValueStorage, type KeyValueStats, type KeyValueStatsPaginated, type KeyValueItemWithMetadata, type DataResult, type DataResultFound, type DataResultNotFound, type KeyValueStorageSetParams, type CreateNamespaceParams, type GetAllStatsParams, type KVSortField, KV_MIN_TTL_SECONDS, KV_MAX_TTL_SECONDS, KV_DEFAULT_TTL_SECONDS, DataResultFoundSchema, DataResultNotFoundSchema, DataResultSchema, KeyValueStorageSetParamsSchema, CreateNamespaceParamsSchema, GetAllStatsParamsSchema, KeyValueStatsSchema, KeyValueStatsPaginatedSchema, KeyValueItemWithMetadataSchema, KVSortFieldSchema, } from '@agentuity/core/keyvalue';
|
|
2
|
+
import { KeyValueStorageService, type KeyValueStorageSetParams, type DataResult } from '@agentuity/core/keyvalue';
|
|
3
|
+
import { type Logger } from '@agentuity/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const KeyValueClientOptionsSchema: z.ZodObject<{
|
|
6
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
orgId: z.ZodOptional<z.ZodString>;
|
|
9
|
+
logger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type KeyValueClientOptions = z.infer<typeof KeyValueClientOptionsSchema>;
|
|
12
|
+
export declare class KeyValueClient {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options?: KeyValueClientOptions);
|
|
15
|
+
get<T>(name: string, key: string): Promise<DataResult<T>>;
|
|
16
|
+
set<T = unknown>(name: string, key: string, value: T, params?: KeyValueStorageSetParams): Promise<void>;
|
|
17
|
+
delete(name: string, key: string): Promise<void>;
|
|
18
|
+
getStats(name: string): Promise<{
|
|
19
|
+
sum: number;
|
|
20
|
+
count: number;
|
|
21
|
+
createdAt?: number | undefined;
|
|
22
|
+
lastUsedAt?: number | undefined;
|
|
23
|
+
internal?: boolean | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
getAllStats(params?: Parameters<KeyValueStorageService['getAllStats']>[0]): Promise<Record<string, {
|
|
26
|
+
sum: number;
|
|
27
|
+
count: number;
|
|
28
|
+
createdAt?: number | undefined;
|
|
29
|
+
lastUsedAt?: number | undefined;
|
|
30
|
+
internal?: boolean | undefined;
|
|
31
|
+
}> | {
|
|
32
|
+
namespaces: Record<string, {
|
|
33
|
+
sum: number;
|
|
34
|
+
count: number;
|
|
35
|
+
createdAt?: number | undefined;
|
|
36
|
+
lastUsedAt?: number | undefined;
|
|
37
|
+
internal?: boolean | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
total: number;
|
|
40
|
+
limit: number;
|
|
41
|
+
offset: number;
|
|
42
|
+
hasMore: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
getNamespaces(): Promise<string[]>;
|
|
45
|
+
search<T = unknown>(name: string, keyword: string): Promise<Record<string, import("@agentuity/core").KeyValueItemWithMetadata<T>>>;
|
|
46
|
+
getKeys(name: string): Promise<string[]>;
|
|
47
|
+
deleteNamespace(name: string): Promise<void>;
|
|
48
|
+
createNamespace(name: string, params?: Parameters<KeyValueStorageService['createNamespace']>[1]): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,EAC9B,2BAA2B,EAC3B,uBAAuB,EACvB,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACN,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAgD,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,2BAA2B;;;;;iBAKtC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,qBAAa,cAAc;;gBAGd,OAAO,GAAE,qBAA0B;IAoBzC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAIzD,GAAG,CAAC,CAAC,GAAG,OAAO,EACpB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,wBAAwB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAIV,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,QAAQ,CAAC,IAAI,EAAE,MAAM;;;;;;;IAIrB,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;IAIzE,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIlC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAIjD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIxC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,UAAU,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/D,OAAO,CAAC,IAAI,CAAC;CAGhB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { KeyValueStorageService, KV_MIN_TTL_SECONDS, KV_MAX_TTL_SECONDS, KV_DEFAULT_TTL_SECONDS, DataResultFoundSchema, DataResultNotFoundSchema, DataResultSchema, KeyValueStorageSetParamsSchema, CreateNamespaceParamsSchema, GetAllStatsParamsSchema, KeyValueStatsSchema, KeyValueStatsPaginatedSchema, KeyValueItemWithMetadataSchema, KVSortFieldSchema, } from '@agentuity/core/keyvalue';
|
|
2
|
+
import { KeyValueStorageService, } from '@agentuity/core/keyvalue';
|
|
3
|
+
import { createServerFetchAdapter, buildClientHeaders } from '@agentuity/server';
|
|
4
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
5
|
+
import { getEnv } from '@agentuity/core';
|
|
6
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
const isLogger = (val) => typeof val === 'object' &&
|
|
9
|
+
val !== null &&
|
|
10
|
+
['info', 'warn', 'error', 'debug', 'trace'].every((m) => typeof val[m] === 'function');
|
|
11
|
+
export const KeyValueClientOptionsSchema = z.object({
|
|
12
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
13
|
+
url: z.string().optional().describe('Base URL for the KV API'),
|
|
14
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
15
|
+
logger: z.custom(isLogger).optional().describe('Custom logger instance'),
|
|
16
|
+
});
|
|
17
|
+
export class KeyValueClient {
|
|
18
|
+
#service;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
const validatedOptions = KeyValueClientOptionsSchema.parse(options);
|
|
21
|
+
const apiKey = validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
22
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
23
|
+
const serviceUrls = getServiceUrls(region);
|
|
24
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_KEYVALUE_URL') || serviceUrls.keyvalue;
|
|
25
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
26
|
+
const headers = buildClientHeaders({
|
|
27
|
+
apiKey,
|
|
28
|
+
orgId: validatedOptions.orgId,
|
|
29
|
+
});
|
|
30
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
31
|
+
this.#service = new KeyValueStorageService(url, adapter);
|
|
32
|
+
}
|
|
33
|
+
async get(name, key) {
|
|
34
|
+
return this.#service.get(name, key);
|
|
35
|
+
}
|
|
36
|
+
async set(name, key, value, params) {
|
|
37
|
+
return this.#service.set(name, key, value, params);
|
|
38
|
+
}
|
|
39
|
+
async delete(name, key) {
|
|
40
|
+
return this.#service.delete(name, key);
|
|
41
|
+
}
|
|
42
|
+
async getStats(name) {
|
|
43
|
+
return this.#service.getStats(name);
|
|
44
|
+
}
|
|
45
|
+
async getAllStats(params) {
|
|
46
|
+
return this.#service.getAllStats(params);
|
|
47
|
+
}
|
|
48
|
+
async getNamespaces() {
|
|
49
|
+
return this.#service.getNamespaces();
|
|
50
|
+
}
|
|
51
|
+
async search(name, keyword) {
|
|
52
|
+
return this.#service.search(name, keyword);
|
|
53
|
+
}
|
|
54
|
+
async getKeys(name) {
|
|
55
|
+
return this.#service.getKeys(name);
|
|
56
|
+
}
|
|
57
|
+
async deleteNamespace(name) {
|
|
58
|
+
return this.#service.deleteNamespace(name);
|
|
59
|
+
}
|
|
60
|
+
async createNamespace(name, params) {
|
|
61
|
+
return this.#service.createNamespace(name, params);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EAYtB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,EAC9B,2BAA2B,EAC3B,uBAAuB,EACvB,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACN,sBAAsB,GAGtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAe,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iB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AQ,CAAC,aAAa,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,MAAM,CAAc,IAAY,EAAE,OAAe;QACtD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAI,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,eAAe,CACpB,IAAY,EACZ,MAAiE;QAEjE,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentuity/keyvalue",
|
|
3
|
+
"version": "1.0.54",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": "Agentuity employees and contributors",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"AGENTS.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"src",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
23
|
+
"build": "bunx tsc --build --force",
|
|
24
|
+
"typecheck": "bunx tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "bun run clean && bun run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@agentuity/core": "1.0.54",
|
|
29
|
+
"@agentuity/server": "1.0.54",
|
|
30
|
+
"zod": "^4.3.5"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"bun-types": "latest",
|
|
36
|
+
"typescript": "^5.9.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export {
|
|
2
|
+
KeyValueStorageService,
|
|
3
|
+
KeyValueStorage,
|
|
4
|
+
type KeyValueStats,
|
|
5
|
+
type KeyValueStatsPaginated,
|
|
6
|
+
type KeyValueItemWithMetadata,
|
|
7
|
+
type DataResult,
|
|
8
|
+
type DataResultFound,
|
|
9
|
+
type DataResultNotFound,
|
|
10
|
+
type KeyValueStorageSetParams,
|
|
11
|
+
type CreateNamespaceParams,
|
|
12
|
+
type GetAllStatsParams,
|
|
13
|
+
type KVSortField,
|
|
14
|
+
KV_MIN_TTL_SECONDS,
|
|
15
|
+
KV_MAX_TTL_SECONDS,
|
|
16
|
+
KV_DEFAULT_TTL_SECONDS,
|
|
17
|
+
DataResultFoundSchema,
|
|
18
|
+
DataResultNotFoundSchema,
|
|
19
|
+
DataResultSchema,
|
|
20
|
+
KeyValueStorageSetParamsSchema,
|
|
21
|
+
CreateNamespaceParamsSchema,
|
|
22
|
+
GetAllStatsParamsSchema,
|
|
23
|
+
KeyValueStatsSchema,
|
|
24
|
+
KeyValueStatsPaginatedSchema,
|
|
25
|
+
KeyValueItemWithMetadataSchema,
|
|
26
|
+
KVSortFieldSchema,
|
|
27
|
+
} from '@agentuity/core/keyvalue';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
KeyValueStorageService,
|
|
31
|
+
type KeyValueStorageSetParams,
|
|
32
|
+
type DataResult,
|
|
33
|
+
} from '@agentuity/core/keyvalue';
|
|
34
|
+
import { createServerFetchAdapter, buildClientHeaders, type Logger } from '@agentuity/server';
|
|
35
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
36
|
+
import { getEnv } from '@agentuity/core';
|
|
37
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
38
|
+
import { z } from 'zod';
|
|
39
|
+
|
|
40
|
+
const isLogger = (val: unknown): val is Logger =>
|
|
41
|
+
typeof val === 'object' &&
|
|
42
|
+
val !== null &&
|
|
43
|
+
['info', 'warn', 'error', 'debug', 'trace'].every(
|
|
44
|
+
(m) => typeof (val as Record<string, unknown>)[m] === 'function'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const KeyValueClientOptionsSchema = z.object({
|
|
48
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
49
|
+
url: z.string().optional().describe('Base URL for the KV API'),
|
|
50
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
51
|
+
logger: z.custom<Logger>(isLogger).optional().describe('Custom logger instance'),
|
|
52
|
+
});
|
|
53
|
+
export type KeyValueClientOptions = z.infer<typeof KeyValueClientOptionsSchema>;
|
|
54
|
+
|
|
55
|
+
export class KeyValueClient {
|
|
56
|
+
readonly #service: KeyValueStorageService;
|
|
57
|
+
|
|
58
|
+
constructor(options: KeyValueClientOptions = {}) {
|
|
59
|
+
const validatedOptions = KeyValueClientOptionsSchema.parse(options);
|
|
60
|
+
const apiKey =
|
|
61
|
+
validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
62
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
63
|
+
const serviceUrls = getServiceUrls(region);
|
|
64
|
+
|
|
65
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_KEYVALUE_URL') || serviceUrls.keyvalue;
|
|
66
|
+
|
|
67
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
68
|
+
|
|
69
|
+
const headers = buildClientHeaders({
|
|
70
|
+
apiKey,
|
|
71
|
+
orgId: validatedOptions.orgId,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
75
|
+
this.#service = new KeyValueStorageService(url, adapter);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async get<T>(name: string, key: string): Promise<DataResult<T>> {
|
|
79
|
+
return this.#service.get(name, key);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async set<T = unknown>(
|
|
83
|
+
name: string,
|
|
84
|
+
key: string,
|
|
85
|
+
value: T,
|
|
86
|
+
params?: KeyValueStorageSetParams
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
return this.#service.set(name, key, value, params);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async delete(name: string, key: string): Promise<void> {
|
|
92
|
+
return this.#service.delete(name, key);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getStats(name: string) {
|
|
96
|
+
return this.#service.getStats(name);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getAllStats(params?: Parameters<KeyValueStorageService['getAllStats']>[0]) {
|
|
100
|
+
return this.#service.getAllStats(params);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async getNamespaces(): Promise<string[]> {
|
|
104
|
+
return this.#service.getNamespaces();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async search<T = unknown>(name: string, keyword: string) {
|
|
108
|
+
return this.#service.search<T>(name, keyword);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getKeys(name: string): Promise<string[]> {
|
|
112
|
+
return this.#service.getKeys(name);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async deleteNamespace(name: string): Promise<void> {
|
|
116
|
+
return this.#service.deleteNamespace(name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async createNamespace(
|
|
120
|
+
name: string,
|
|
121
|
+
params?: Parameters<KeyValueStorageService['createNamespace']>[1]
|
|
122
|
+
): Promise<void> {
|
|
123
|
+
return this.#service.createNamespace(name, params);
|
|
124
|
+
}
|
|
125
|
+
}
|