@z3rno/sdk 0.0.1
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/LICENSE +201 -0
- package/README.md +75 -0
- package/dist/index.cjs +292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +396 -0
- package/dist/index.d.ts +396 -0
- package/dist/index.js +276 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The AI Project Co.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @z3rno/sdk (TypeScript)
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
|
+
[](https://github.com/the-ai-project-co/z3rno-sdk-typescript/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/@z3rno/sdk)
|
|
6
|
+
|
|
7
|
+
TypeScript SDK for Z3rno -- native fetch client with Zod validation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @z3rno/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quickstart
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Z3rnoClient } from "@z3rno/sdk";
|
|
19
|
+
|
|
20
|
+
const client = new Z3rnoClient({ baseUrl: "https://api.z3rno.dev", apiKey: "z3rno_sk_..." });
|
|
21
|
+
const memory = await client.store({ agentId: "agent-1", content: "User prefers dark mode", memoryType: "semantic" });
|
|
22
|
+
const results = await client.recall({ agentId: "agent-1", query: "What does the user prefer?", topK: 5 });
|
|
23
|
+
await client.forget({ agentId: "agent-1", memoryId: memory.id });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## CJS + ESM Support
|
|
27
|
+
|
|
28
|
+
The SDK ships as a dual build via tsup. Both CommonJS and ES module entry points are provided:
|
|
29
|
+
|
|
30
|
+
```jsonc
|
|
31
|
+
// package.json exports
|
|
32
|
+
{
|
|
33
|
+
"import": "./dist/index.js", // ESM
|
|
34
|
+
"require": "./dist/index.cjs" // CJS
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Works in Node.js 18+, Bun, Deno, and browsers.
|
|
39
|
+
|
|
40
|
+
## Methods
|
|
41
|
+
|
|
42
|
+
| Method | Description |
|
|
43
|
+
|--------|-------------|
|
|
44
|
+
| `store(request)` | Store a new memory with optional type, metadata, relationships, TTL, and importance |
|
|
45
|
+
| `recall(params)` | Recall memories by semantic similarity query |
|
|
46
|
+
| `forget(params)` | Soft-delete a memory by ID |
|
|
47
|
+
| `audit(params?)` | Query the audit trail with optional filters and pagination |
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Zero runtime dependencies** -- only `zod` for request/response validation. No `axios`, no database drivers.
|
|
52
|
+
- **Native fetch** -- works in every modern JavaScript runtime without polyfills.
|
|
53
|
+
- **Runtime-validated responses** -- every API response is parsed through a Zod schema, giving both compile-time and runtime type safety.
|
|
54
|
+
- **Typed errors** -- `Z3rnoAuthenticationError`, `Z3rnoRateLimitError` (with `retryAfter`), `Z3rnoValidationError`.
|
|
55
|
+
- **Tree-shakeable** -- ESM build with clean exports for optimal bundling.
|
|
56
|
+
|
|
57
|
+
## API Documentation
|
|
58
|
+
|
|
59
|
+
Full API reference: [docs.z3rno.dev/sdk/typescript](https://docs.z3rno.dev/sdk/typescript)
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install
|
|
65
|
+
npm run typecheck
|
|
66
|
+
npm run format:check
|
|
67
|
+
npm test
|
|
68
|
+
npm run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
Apache 2.0 -- see [LICENSE](LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var Z3rnoError = class extends Error {
|
|
7
|
+
statusCode;
|
|
8
|
+
constructor(message, statusCode) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "Z3rnoError";
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var AuthenticationError = class extends Z3rnoError {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message, 401);
|
|
17
|
+
this.name = "AuthenticationError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var RateLimitError = class extends Z3rnoError {
|
|
21
|
+
retryAfter;
|
|
22
|
+
constructor(message, retryAfter = 60) {
|
|
23
|
+
super(message, 429);
|
|
24
|
+
this.name = "RateLimitError";
|
|
25
|
+
this.retryAfter = retryAfter;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var ValidationError = class extends Z3rnoError {
|
|
29
|
+
constructor(message, statusCode = 400) {
|
|
30
|
+
super(message, statusCode);
|
|
31
|
+
this.name = "ValidationError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var NotFoundError = class extends Z3rnoError {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message, 404);
|
|
37
|
+
this.name = "NotFoundError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ServerError = class extends Z3rnoError {
|
|
41
|
+
constructor(message, statusCode = 500) {
|
|
42
|
+
super(message, statusCode);
|
|
43
|
+
this.name = "ServerError";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var MemoryType = zod.z.enum([
|
|
47
|
+
"working",
|
|
48
|
+
"episodic",
|
|
49
|
+
"semantic",
|
|
50
|
+
"procedural"
|
|
51
|
+
]);
|
|
52
|
+
var RelationshipType = zod.z.enum([
|
|
53
|
+
"derived_from",
|
|
54
|
+
"contradicts",
|
|
55
|
+
"supports",
|
|
56
|
+
"supersedes",
|
|
57
|
+
"related_to",
|
|
58
|
+
"caused_by"
|
|
59
|
+
]);
|
|
60
|
+
zod.z.object({
|
|
61
|
+
agentId: zod.z.string().uuid(),
|
|
62
|
+
content: zod.z.string().min(1).max(1e5),
|
|
63
|
+
memoryType: MemoryType.default("episodic"),
|
|
64
|
+
userId: zod.z.string().uuid().optional(),
|
|
65
|
+
metadata: zod.z.record(zod.z.unknown()).default({}),
|
|
66
|
+
relationships: zod.z.array(
|
|
67
|
+
zod.z.object({
|
|
68
|
+
targetMemoryId: zod.z.string().uuid(),
|
|
69
|
+
relationshipType: RelationshipType,
|
|
70
|
+
weight: zod.z.number().min(0).max(1).default(1),
|
|
71
|
+
metadata: zod.z.record(zod.z.unknown()).default({})
|
|
72
|
+
})
|
|
73
|
+
).default([]),
|
|
74
|
+
ttlSeconds: zod.z.number().int().positive().optional(),
|
|
75
|
+
importance: zod.z.number().min(0).max(1).optional()
|
|
76
|
+
});
|
|
77
|
+
zod.z.object({
|
|
78
|
+
agentId: zod.z.string().uuid(),
|
|
79
|
+
query: zod.z.string().optional(),
|
|
80
|
+
memoryType: zod.z.string().optional(),
|
|
81
|
+
filters: zod.z.record(zod.z.unknown()).optional(),
|
|
82
|
+
topK: zod.z.number().int().min(1).max(100).default(10),
|
|
83
|
+
similarityThreshold: zod.z.number().min(0).max(1).default(0),
|
|
84
|
+
asOf: zod.z.string().datetime().optional(),
|
|
85
|
+
includeDeleted: zod.z.boolean().default(false)
|
|
86
|
+
});
|
|
87
|
+
zod.z.object({
|
|
88
|
+
agentId: zod.z.string().uuid(),
|
|
89
|
+
memoryId: zod.z.string().uuid().optional(),
|
|
90
|
+
memoryIds: zod.z.array(zod.z.string().uuid()).optional(),
|
|
91
|
+
hardDelete: zod.z.boolean().default(false),
|
|
92
|
+
cascade: zod.z.boolean().default(false),
|
|
93
|
+
reason: zod.z.string().optional()
|
|
94
|
+
});
|
|
95
|
+
var MemoryResponse = zod.z.object({
|
|
96
|
+
id: zod.z.string(),
|
|
97
|
+
agent_id: zod.z.string(),
|
|
98
|
+
content: zod.z.string(),
|
|
99
|
+
memory_type: zod.z.string(),
|
|
100
|
+
importance_score: zod.z.number(),
|
|
101
|
+
recall_count: zod.z.number(),
|
|
102
|
+
embedding_model: zod.z.string().nullable().optional(),
|
|
103
|
+
created_at: zod.z.string(),
|
|
104
|
+
metadata: zod.z.record(zod.z.unknown()).default({})
|
|
105
|
+
});
|
|
106
|
+
var RecallResultItem = zod.z.object({
|
|
107
|
+
memory_id: zod.z.string(),
|
|
108
|
+
content: zod.z.string(),
|
|
109
|
+
summary: zod.z.string().nullable().optional(),
|
|
110
|
+
memory_type: zod.z.string(),
|
|
111
|
+
similarity_score: zod.z.number(),
|
|
112
|
+
importance_score: zod.z.number(),
|
|
113
|
+
relevance_score: zod.z.number(),
|
|
114
|
+
recall_count: zod.z.number(),
|
|
115
|
+
created_at: zod.z.string(),
|
|
116
|
+
metadata: zod.z.record(zod.z.unknown()).default({})
|
|
117
|
+
});
|
|
118
|
+
var RecallResponse = zod.z.object({
|
|
119
|
+
results: zod.z.array(RecallResultItem),
|
|
120
|
+
total: zod.z.number(),
|
|
121
|
+
query: zod.z.string().nullable().optional()
|
|
122
|
+
});
|
|
123
|
+
var ForgetResponse = zod.z.object({
|
|
124
|
+
deleted_count: zod.z.number(),
|
|
125
|
+
hard_deleted: zod.z.boolean(),
|
|
126
|
+
cascade_count: zod.z.number(),
|
|
127
|
+
memory_ids: zod.z.array(zod.z.string())
|
|
128
|
+
});
|
|
129
|
+
var AuditEntry = zod.z.object({
|
|
130
|
+
id: zod.z.number(),
|
|
131
|
+
agent_id: zod.z.string().nullable().optional(),
|
|
132
|
+
user_id: zod.z.string().nullable().optional(),
|
|
133
|
+
operation: zod.z.string(),
|
|
134
|
+
memory_id: zod.z.string().nullable().optional(),
|
|
135
|
+
memory_type: zod.z.string().nullable().optional(),
|
|
136
|
+
details: zod.z.record(zod.z.unknown()).default({}),
|
|
137
|
+
ip_address: zod.z.string().nullable().optional(),
|
|
138
|
+
created_at: zod.z.string()
|
|
139
|
+
});
|
|
140
|
+
var AuditPageResponse = zod.z.object({
|
|
141
|
+
entries: zod.z.array(AuditEntry),
|
|
142
|
+
total: zod.z.number(),
|
|
143
|
+
page: zod.z.number(),
|
|
144
|
+
page_size: zod.z.number(),
|
|
145
|
+
has_next: zod.z.boolean()
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// src/client.ts
|
|
149
|
+
var Z3rnoClient = class {
|
|
150
|
+
baseUrl;
|
|
151
|
+
apiKey;
|
|
152
|
+
timeout;
|
|
153
|
+
constructor(config) {
|
|
154
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
155
|
+
this.apiKey = config.apiKey;
|
|
156
|
+
this.timeout = config.timeout ?? 3e4;
|
|
157
|
+
}
|
|
158
|
+
// --- Store ---
|
|
159
|
+
async store(request) {
|
|
160
|
+
const body = {
|
|
161
|
+
agent_id: request.agentId,
|
|
162
|
+
content: request.content,
|
|
163
|
+
memory_type: request.memoryType,
|
|
164
|
+
user_id: request.userId,
|
|
165
|
+
metadata: request.metadata,
|
|
166
|
+
relationships: request.relationships?.map((r) => ({
|
|
167
|
+
target_memory_id: r.targetMemoryId,
|
|
168
|
+
relationship_type: r.relationshipType,
|
|
169
|
+
weight: r.weight,
|
|
170
|
+
metadata: r.metadata
|
|
171
|
+
})),
|
|
172
|
+
ttl_seconds: request.ttlSeconds,
|
|
173
|
+
importance: request.importance
|
|
174
|
+
};
|
|
175
|
+
const resp = await this.request("POST", "/v1/memories", body);
|
|
176
|
+
return MemoryResponse.parse(resp);
|
|
177
|
+
}
|
|
178
|
+
// --- Recall ---
|
|
179
|
+
async recall(params) {
|
|
180
|
+
const body = {
|
|
181
|
+
agent_id: params.agentId,
|
|
182
|
+
query: params.query,
|
|
183
|
+
memory_type: params.memoryType,
|
|
184
|
+
filters: params.filters,
|
|
185
|
+
top_k: params.topK ?? 10,
|
|
186
|
+
similarity_threshold: params.similarityThreshold ?? 0
|
|
187
|
+
};
|
|
188
|
+
const resp = await this.request("POST", "/v1/memories/recall", body);
|
|
189
|
+
return RecallResponse.parse(resp);
|
|
190
|
+
}
|
|
191
|
+
// --- Forget ---
|
|
192
|
+
async forget(params) {
|
|
193
|
+
const body = {
|
|
194
|
+
agent_id: params.agentId,
|
|
195
|
+
memory_id: params.memoryId,
|
|
196
|
+
memory_ids: params.memoryIds,
|
|
197
|
+
hard_delete: params.hardDelete ?? false,
|
|
198
|
+
cascade: params.cascade ?? false,
|
|
199
|
+
reason: params.reason
|
|
200
|
+
};
|
|
201
|
+
const resp = await this.request("POST", "/v1/memories/forget", body);
|
|
202
|
+
return ForgetResponse.parse(resp);
|
|
203
|
+
}
|
|
204
|
+
// --- Audit ---
|
|
205
|
+
async audit(params) {
|
|
206
|
+
const searchParams = new URLSearchParams();
|
|
207
|
+
if (params?.agentId) searchParams.set("agent_id", params.agentId);
|
|
208
|
+
if (params?.page) searchParams.set("page", String(params.page));
|
|
209
|
+
if (params?.pageSize)
|
|
210
|
+
searchParams.set("page_size", String(params.pageSize));
|
|
211
|
+
const query = searchParams.toString();
|
|
212
|
+
const path = query ? `/v1/audit?${query}` : "/v1/audit";
|
|
213
|
+
const resp = await this.request("GET", path);
|
|
214
|
+
return AuditPageResponse.parse(resp);
|
|
215
|
+
}
|
|
216
|
+
// --- HTTP layer ---
|
|
217
|
+
async request(method, path, body) {
|
|
218
|
+
const controller = new AbortController();
|
|
219
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
220
|
+
try {
|
|
221
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
222
|
+
method,
|
|
223
|
+
headers: {
|
|
224
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
225
|
+
"Content-Type": "application/json",
|
|
226
|
+
"User-Agent": "@z3rno/sdk/0.0.1"
|
|
227
|
+
},
|
|
228
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
229
|
+
signal: controller.signal
|
|
230
|
+
});
|
|
231
|
+
clearTimeout(timeoutId);
|
|
232
|
+
return this.handleResponse(response);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
clearTimeout(timeoutId);
|
|
235
|
+
if (error instanceof Z3rnoError) throw error;
|
|
236
|
+
throw new Z3rnoError(`Request failed: ${String(error)}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async handleResponse(resp) {
|
|
240
|
+
if (resp.ok) {
|
|
241
|
+
return resp.json();
|
|
242
|
+
}
|
|
243
|
+
let detail = resp.statusText;
|
|
244
|
+
try {
|
|
245
|
+
const body = await resp.json();
|
|
246
|
+
detail = String(body.detail ?? body.error ?? resp.statusText);
|
|
247
|
+
} catch {
|
|
248
|
+
}
|
|
249
|
+
switch (resp.status) {
|
|
250
|
+
case 401:
|
|
251
|
+
throw new AuthenticationError(`Authentication failed: ${detail}`);
|
|
252
|
+
case 404:
|
|
253
|
+
throw new NotFoundError(`Not found: ${detail}`);
|
|
254
|
+
case 429: {
|
|
255
|
+
const retryAfter = parseInt(
|
|
256
|
+
resp.headers.get("Retry-After") ?? "60",
|
|
257
|
+
10
|
|
258
|
+
);
|
|
259
|
+
throw new RateLimitError(`Rate limit exceeded: ${detail}`, retryAfter);
|
|
260
|
+
}
|
|
261
|
+
case 400:
|
|
262
|
+
case 422:
|
|
263
|
+
throw new ValidationError(detail, resp.status);
|
|
264
|
+
default:
|
|
265
|
+
if (resp.status >= 500) {
|
|
266
|
+
throw new ServerError(`Server error: ${detail}`, resp.status);
|
|
267
|
+
}
|
|
268
|
+
throw new Z3rnoError(
|
|
269
|
+
`Unexpected error (${resp.status}): ${detail}`,
|
|
270
|
+
resp.status
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
exports.AuditEntry = AuditEntry;
|
|
277
|
+
exports.AuditPageResponse = AuditPageResponse;
|
|
278
|
+
exports.AuthenticationError = AuthenticationError;
|
|
279
|
+
exports.ForgetResponse = ForgetResponse;
|
|
280
|
+
exports.MemoryResponse = MemoryResponse;
|
|
281
|
+
exports.MemoryType = MemoryType;
|
|
282
|
+
exports.NotFoundError = NotFoundError;
|
|
283
|
+
exports.RateLimitError = RateLimitError;
|
|
284
|
+
exports.RecallResponse = RecallResponse;
|
|
285
|
+
exports.RecallResultItem = RecallResultItem;
|
|
286
|
+
exports.RelationshipType = RelationshipType;
|
|
287
|
+
exports.ServerError = ServerError;
|
|
288
|
+
exports.ValidationError = ValidationError;
|
|
289
|
+
exports.Z3rnoClient = Z3rnoClient;
|
|
290
|
+
exports.Z3rnoError = Z3rnoError;
|
|
291
|
+
//# sourceMappingURL=index.cjs.map
|
|
292
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/models.ts","../src/client.ts"],"names":["z"],"mappings":";;;;;AAIO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,UAAA;AAAA,EAEA,WAAA,CAAY,SAAiB,UAAA,EAAqB;AAChD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACpB;AACF;AAEO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAW;AAAA,EAClD,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,SAAS,GAAG,CAAA;AAClB,IAAA,IAAA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cesContent":["/**\n * Z3rno SDK error hierarchy.\n */\n\nexport class Z3rnoError extends Error {\n statusCode?: number;\n\n constructor(message: string, statusCode?: number) {\n super(message);\n this.name = \"Z3rnoError\";\n this.statusCode = statusCode;\n }\n}\n\nexport class AuthenticationError extends Z3rnoError {\n constructor(message: string) {\n super(message, 401);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends Z3rnoError {\n retryAfter: number;\n\n constructor(message: string, retryAfter: number = 60) {\n super(message, 429);\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class ValidationError extends Z3rnoError {\n constructor(message: string, statusCode: number = 400) {\n super(message, statusCode);\n this.name = \"ValidationError\";\n }\n}\n\nexport class NotFoundError extends Z3rnoError {\n constructor(message: string) {\n super(message, 404);\n this.name = \"NotFoundError\";\n }\n}\n\nexport class ServerError extends Z3rnoError {\n constructor(message: string, statusCode: number = 500) {\n super(message, statusCode);\n this.name = \"ServerError\";\n }\n}\n","/**\n * Zod schemas and inferred TypeScript types for the Z3rno API.\n */\n\nimport { z } from \"zod\";\n\n// --- Enums ---\n\nexport const MemoryType = z.enum([\n \"working\",\n \"episodic\",\n \"semantic\",\n \"procedural\",\n]);\nexport type MemoryType = z.infer<typeof MemoryType>;\n\nexport const RelationshipType = z.enum([\n \"derived_from\",\n \"contradicts\",\n \"supports\",\n \"supersedes\",\n \"related_to\",\n \"caused_by\",\n]);\nexport type RelationshipType = z.infer<typeof RelationshipType>;\n\n// --- Request schemas ---\n\nexport const StoreMemoryRequest = z.object({\n agentId: z.string().uuid(),\n content: z.string().min(1).max(100000),\n memoryType: MemoryType.default(\"episodic\"),\n userId: z.string().uuid().optional(),\n metadata: z.record(z.unknown()).default({}),\n relationships: z\n .array(\n z.object({\n targetMemoryId: z.string().uuid(),\n relationshipType: RelationshipType,\n weight: z.number().min(0).max(1).default(1.0),\n metadata: z.record(z.unknown()).default({}),\n }),\n )\n .default([]),\n ttlSeconds: z.number().int().positive().optional(),\n importance: z.number().min(0).max(1).optional(),\n});\nexport type StoreMemoryRequest = z.infer<typeof StoreMemoryRequest>;\n\nexport const RecallRequest = z.object({\n agentId: z.string().uuid(),\n query: z.string().optional(),\n memoryType: z.string().optional(),\n filters: z.record(z.unknown()).optional(),\n topK: z.number().int().min(1).max(100).default(10),\n similarityThreshold: z.number().min(0).max(1).default(0),\n asOf: z.string().datetime().optional(),\n includeDeleted: z.boolean().default(false),\n});\nexport type RecallRequest = z.infer<typeof RecallRequest>;\n\nexport const ForgetRequest = z.object({\n agentId: z.string().uuid(),\n memoryId: z.string().uuid().optional(),\n memoryIds: z.array(z.string().uuid()).optional(),\n hardDelete: z.boolean().default(false),\n cascade: z.boolean().default(false),\n reason: z.string().optional(),\n});\nexport type ForgetRequest = z.infer<typeof ForgetRequest>;\n\n// --- Response schemas ---\n\nexport const MemoryResponse = z.object({\n id: z.string(),\n agent_id: z.string(),\n content: z.string(),\n memory_type: z.string(),\n importance_score: z.number(),\n recall_count: z.number(),\n embedding_model: z.string().nullable().optional(),\n created_at: z.string(),\n metadata: z.record(z.unknown()).default({}),\n});\nexport type MemoryResponse = z.infer<typeof MemoryResponse>;\n\nexport const RecallResultItem = z.object({\n memory_id: z.string(),\n content: z.string(),\n summary: z.string().nullable().optional(),\n memory_type: z.string(),\n similarity_score: z.number(),\n importance_score: z.number(),\n relevance_score: z.number(),\n recall_count: z.number(),\n created_at: z.string(),\n metadata: z.record(z.unknown()).default({}),\n});\nexport type RecallResultItem = z.infer<typeof RecallResultItem>;\n\nexport const RecallResponse = z.object({\n results: z.array(RecallResultItem),\n total: z.number(),\n query: z.string().nullable().optional(),\n});\nexport type RecallResponse = z.infer<typeof RecallResponse>;\n\nexport const ForgetResponse = z.object({\n deleted_count: z.number(),\n hard_deleted: z.boolean(),\n cascade_count: z.number(),\n memory_ids: z.array(z.string()),\n});\nexport type ForgetResponse = z.infer<typeof ForgetResponse>;\n\nexport const AuditEntry = z.object({\n id: z.number(),\n agent_id: z.string().nullable().optional(),\n user_id: z.string().nullable().optional(),\n operation: z.string(),\n memory_id: z.string().nullable().optional(),\n memory_type: z.string().nullable().optional(),\n details: z.record(z.unknown()).default({}),\n ip_address: z.string().nullable().optional(),\n created_at: z.string(),\n});\nexport type AuditEntry = z.infer<typeof AuditEntry>;\n\nexport const AuditPageResponse = z.object({\n entries: z.array(AuditEntry),\n total: z.number(),\n page: z.number(),\n page_size: z.number(),\n has_next: z.boolean(),\n});\nexport type AuditPageResponse = z.infer<typeof AuditPageResponse>;\n","/**\n * Z3rno TypeScript SDK client.\n *\n * Thin fetch wrapper — no database drivers, no embedding providers.\n *\n * @example\n * ```ts\n * const client = new Z3rnoClient({ baseUrl: \"http://localhost:8000\", apiKey: \"z3rno_sk_...\" });\n * const memory = await client.store({ agentId: \"agent-1\", content: \"User prefers dark mode\" });\n * const results = await client.recall({ agentId: \"agent-1\", query: \"user preferences\" });\n * await client.forget({ agentId: \"agent-1\", memoryId: memory.id });\n * ```\n */\n\nimport {\n AuthenticationError,\n NotFoundError,\n RateLimitError,\n ServerError,\n ValidationError,\n Z3rnoError,\n} from \"./errors.js\";\nimport type {\n AuditPageResponse,\n ForgetResponse,\n MemoryResponse,\n RecallResponse,\n StoreMemoryRequest,\n} from \"./models.js\";\nimport {\n AuditPageResponse as AuditPageSchema,\n ForgetResponse as ForgetSchema,\n MemoryResponse as MemorySchema,\n RecallResponse as RecallSchema,\n} from \"./models.js\";\n\nexport interface Z3rnoClientConfig {\n baseUrl: string;\n apiKey: string;\n timeout?: number;\n maxRetries?: number;\n}\n\nexport class Z3rnoClient {\n private baseUrl: string;\n private apiKey: string;\n private timeout: number;\n\n constructor(config: Z3rnoClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n this.apiKey = config.apiKey;\n this.timeout = config.timeout ?? 30000;\n }\n\n // --- Store ---\n\n async store(request: StoreMemoryRequest): Promise<MemoryResponse> {\n const body = {\n agent_id: request.agentId,\n content: request.content,\n memory_type: request.memoryType,\n user_id: request.userId,\n metadata: request.metadata,\n relationships: request.relationships?.map((r) => ({\n target_memory_id: r.targetMemoryId,\n relationship_type: r.relationshipType,\n weight: r.weight,\n metadata: r.metadata,\n })),\n ttl_seconds: request.ttlSeconds,\n importance: request.importance,\n };\n\n const resp = await this.request(\"POST\", \"/v1/memories\", body);\n return MemorySchema.parse(resp);\n }\n\n // --- Recall ---\n\n async recall(params: {\n agentId: string;\n query?: string;\n memoryType?: string;\n filters?: Record<string, unknown>;\n topK?: number;\n similarityThreshold?: number;\n }): Promise<RecallResponse> {\n const body = {\n agent_id: params.agentId,\n query: params.query,\n memory_type: params.memoryType,\n filters: params.filters,\n top_k: params.topK ?? 10,\n similarity_threshold: params.similarityThreshold ?? 0,\n };\n\n const resp = await this.request(\"POST\", \"/v1/memories/recall\", body);\n return RecallSchema.parse(resp);\n }\n\n // --- Forget ---\n\n async forget(params: {\n agentId: string;\n memoryId?: string;\n memoryIds?: string[];\n hardDelete?: boolean;\n cascade?: boolean;\n reason?: string;\n }): Promise<ForgetResponse> {\n const body = {\n agent_id: params.agentId,\n memory_id: params.memoryId,\n memory_ids: params.memoryIds,\n hard_delete: params.hardDelete ?? false,\n cascade: params.cascade ?? false,\n reason: params.reason,\n };\n\n const resp = await this.request(\"POST\", \"/v1/memories/forget\", body);\n return ForgetSchema.parse(resp);\n }\n\n // --- Audit ---\n\n async audit(params?: {\n agentId?: string;\n page?: number;\n pageSize?: number;\n }): Promise<AuditPageResponse> {\n const searchParams = new URLSearchParams();\n if (params?.agentId) searchParams.set(\"agent_id\", params.agentId);\n if (params?.page) searchParams.set(\"page\", String(params.page));\n if (params?.pageSize)\n searchParams.set(\"page_size\", String(params.pageSize));\n\n const query = searchParams.toString();\n const path = query ? `/v1/audit?${query}` : \"/v1/audit\";\n const resp = await this.request(\"GET\", path);\n return AuditPageSchema.parse(resp);\n }\n\n // --- HTTP layer ---\n\n private async request(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<unknown> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": \"@z3rno/sdk/0.0.1\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n return this.handleResponse(response);\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof Z3rnoError) throw error;\n throw new Z3rnoError(`Request failed: ${String(error)}`);\n }\n }\n\n private async handleResponse(resp: Response): Promise<unknown> {\n if (resp.ok) {\n return resp.json();\n }\n\n let detail = resp.statusText;\n try {\n const body = (await resp.json()) as Record<string, unknown>;\n detail = String(body.detail ?? body.error ?? resp.statusText);\n } catch {\n // Not JSON\n }\n\n switch (resp.status) {\n case 401:\n throw new AuthenticationError(`Authentication failed: ${detail}`);\n case 404:\n throw new NotFoundError(`Not found: ${detail}`);\n case 429: {\n const retryAfter = parseInt(\n resp.headers.get(\"Retry-After\") ?? \"60\",\n 10,\n );\n throw new RateLimitError(`Rate limit exceeded: ${detail}`, retryAfter);\n }\n case 400:\n case 422:\n throw new ValidationError(detail, resp.status);\n default:\n if (resp.status >= 500) {\n throw new ServerError(`Server error: ${detail}`, resp.status);\n }\n throw new Z3rnoError(\n `Unexpected error (${resp.status}): ${detail}`,\n resp.status,\n );\n }\n }\n}\n"]}
|