@cilow/sdk 0.2.0 → 0.3.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/LICENSE +201 -21
- package/README.md +109 -279
- package/dist/abstain.d.ts +43 -0
- package/dist/abstain.d.ts.map +1 -0
- package/dist/abstain.js +42 -0
- package/dist/abstain.js.map +1 -0
- package/dist/adapters/anthropic.d.ts +57 -0
- package/dist/adapters/anthropic.d.ts.map +1 -0
- package/dist/adapters/anthropic.js +57 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/index.d.ts +16 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +16 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/langchain.d.ts +62 -0
- package/dist/adapters/langchain.d.ts.map +1 -0
- package/dist/adapters/langchain.js +68 -0
- package/dist/adapters/langchain.js.map +1 -0
- package/dist/adapters/memory.d.ts +105 -0
- package/dist/adapters/memory.d.ts.map +1 -0
- package/dist/adapters/memory.js +105 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/openai.d.ts +56 -0
- package/dist/adapters/openai.d.ts.map +1 -0
- package/dist/adapters/openai.js +64 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/adapters/remaining.d.ts +52 -0
- package/dist/adapters/remaining.d.ts.map +1 -0
- package/dist/adapters/remaining.js +67 -0
- package/dist/adapters/remaining.js.map +1 -0
- package/dist/client.d.ts +563 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +653 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -0
- package/dist/hash.d.ts +13 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +92 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +17 -404
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -482
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +817 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +32 -46
- package/dist/index.d.mts +0 -407
- package/dist/index.mjs +0 -449
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
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 Generalized Labs
|
|
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
CHANGED
|
@@ -1,322 +1,152 @@
|
|
|
1
|
-
# @cilow/sdk
|
|
1
|
+
# @cilow/sdk — TypeScript
|
|
2
2
|
|
|
3
|
-
TypeScript
|
|
3
|
+
The TypeScript client for **Cilow**, the verifiable context layer for AI agents. Point it at
|
|
4
|
+
a running [`cilow-serve`](../../docs/user_guide/mcp_server.md) and call **four core verbs** —
|
|
5
|
+
`ingest`, `contextPack`, `forget`, `explain` — the same four the MCP core profile advertises.
|
|
6
|
+
The headline feature is **calibrated deferral**: every read tells you when the engine
|
|
7
|
+
*doesn't know* instead of fabricating an answer.
|
|
4
8
|
|
|
5
|
-
##
|
|
9
|
+
## Install
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **Knowledge Graph** - Entity extraction and relationship mapping
|
|
12
|
-
- **Multi-tenant Support** - User isolation for secure multi-user apps
|
|
13
|
-
- **TypeScript First** - Full type safety with comprehensive types
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @cilow/sdk
|
|
19
|
-
# or
|
|
20
|
-
yarn add @cilow/sdk
|
|
21
|
-
# or
|
|
22
|
-
pnpm add @cilow/sdk
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Quick Start
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { CilowClient } from '@cilow/sdk';
|
|
29
|
-
|
|
30
|
-
// Initialize with API key
|
|
31
|
-
const client = new CilowClient({
|
|
32
|
-
apiKey: 'cilow_your_api_key',
|
|
33
|
-
baseUrl: 'https://api.cilow.ai', // or your self-hosted URL
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Add a memory
|
|
37
|
-
const { memoryId } = await client.addMemory({
|
|
38
|
-
content: 'User prefers TypeScript over JavaScript for backend development',
|
|
39
|
-
tags: ['preference', 'programming', 'backend'],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Search memories semantically
|
|
43
|
-
const results = await client.searchMemories({
|
|
44
|
-
query: 'What programming languages does the user prefer?',
|
|
45
|
-
limit: 5,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
console.log(results);
|
|
49
|
-
// [
|
|
50
|
-
// {
|
|
51
|
-
// memoryId: 'mem_xxx',
|
|
52
|
-
// content: 'User prefers TypeScript over JavaScript...',
|
|
53
|
-
// similarity: 0.92,
|
|
54
|
-
// score: 0.18,
|
|
55
|
-
// tags: ['preference', 'programming', 'backend']
|
|
56
|
-
// }
|
|
57
|
-
// ]
|
|
11
|
+
```sh
|
|
12
|
+
# From this repo (no registry publish yet):
|
|
13
|
+
cd sdk/typescript && npm install && npm run build
|
|
14
|
+
# In your app, depend on the built package or vendor `dist/`.
|
|
58
15
|
```
|
|
59
16
|
|
|
60
|
-
|
|
17
|
+
Node 18+ (uses the global `fetch`). Zero runtime dependencies.
|
|
61
18
|
|
|
62
|
-
|
|
19
|
+
## Point it at a server
|
|
63
20
|
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
21
|
+
```sh
|
|
22
|
+
cargo build --profile fast --features serve --bin cilow-serve
|
|
23
|
+
CILOW_DB=/tmp/cilow.log CILOW_TOKENS="demo:1:1" ./target/fast/cilow-serve
|
|
24
|
+
# listening on http://0.0.0.0:8080 · bearer token "demo"
|
|
68
25
|
```
|
|
69
26
|
|
|
70
|
-
|
|
27
|
+
The token maps to a tenant scope that the server **stamps** onto every request — a client can
|
|
28
|
+
never read another tenant's memory, and a client-supplied `scope` is ignored over HTTP.
|
|
71
29
|
|
|
72
|
-
|
|
73
|
-
const client = new CilowClient({
|
|
74
|
-
baseUrl: 'https://api.cilow.ai',
|
|
75
|
-
});
|
|
30
|
+
## Five lines
|
|
76
31
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.log(`Logged in as: ${auth.user.email}`);
|
|
32
|
+
```ts
|
|
33
|
+
import { CilowClient, isGrounded } from "@cilow/sdk";
|
|
80
34
|
|
|
81
|
-
|
|
35
|
+
const cilow = new CilowClient({ baseUrl: "http://localhost:8080", token: "demo" });
|
|
36
|
+
await cilow.ingest({ facts: [{ subject: "Maya", predicate: "employer", object: "Acme" }] });
|
|
37
|
+
const r = await cilow.contextPack("where does Maya work", { anchor: "Maya", attribute: "employer" });
|
|
38
|
+
console.log(r.abstained ? `don't know: ${r.reason}` : r.pack); // the injectible pack; citations on r.citations
|
|
39
|
+
console.log(isGrounded(await cilow.explain(r.trace_id!))); // why it surfaced, vs the tenant threshold
|
|
82
40
|
```
|
|
83
41
|
|
|
84
|
-
##
|
|
85
|
-
|
|
86
|
-
### Add Memory
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
const { memoryId } = await client.addMemory({
|
|
90
|
-
content: 'Meeting notes: Q4 planning discussed roadmap priorities',
|
|
91
|
-
tags: ['meeting', 'planning', 'q4'],
|
|
92
|
-
metadata: {
|
|
93
|
-
source: 'meeting-notes',
|
|
94
|
-
date: '2024-01-15',
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Search Memories
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
// Semantic search
|
|
103
|
-
const results = await client.searchMemories({
|
|
104
|
-
query: 'What were the Q4 priorities?',
|
|
105
|
-
limit: 10,
|
|
106
|
-
minScore: 0.5,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Search with tag filtering
|
|
110
|
-
const taggedResults = await client.searchMemories({
|
|
111
|
-
query: 'planning discussions',
|
|
112
|
-
tags: ['meeting', 'planning'],
|
|
113
|
-
tagMode: 'all', // 'all' = AND, 'any' = OR
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Update Memory
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
await client.updateMemory(memoryId, {
|
|
121
|
-
content: 'Updated content with new information',
|
|
122
|
-
tags: ['updated', 'important'],
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Delete Memory
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
await client.deleteMemory(memoryId);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### List Memories
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
// List all memories
|
|
136
|
-
const memories = await client.listMemories();
|
|
137
|
-
|
|
138
|
-
// Filter by tier
|
|
139
|
-
const hotMemories = await client.listMemories({
|
|
140
|
-
tier: 'hot',
|
|
141
|
-
limit: 50,
|
|
142
|
-
offset: 0,
|
|
143
|
-
});
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Get Statistics
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
const stats = await client.getMemoryStats();
|
|
150
|
-
console.log(stats);
|
|
151
|
-
// {
|
|
152
|
-
// totalMemories: 1500,
|
|
153
|
-
// hotTier: 200,
|
|
154
|
-
// warmTier: 800,
|
|
155
|
-
// coldTier: 500,
|
|
156
|
-
// totalTokens: 45000,
|
|
157
|
-
// avgSalience: 0.65
|
|
158
|
-
// }
|
|
159
|
-
```
|
|
42
|
+
## The four core verbs
|
|
160
43
|
|
|
161
|
-
|
|
44
|
+
| Verb | Signature | Returns | What it does |
|
|
45
|
+
|------|-----------|---------|--------------|
|
|
46
|
+
| `ingest` | `ingest({ facts } \| { text } \| { url } \| { contentBase64, mime? }, opts?)` | `IngestResponse` | The **one write door**. Never rejects: known kinds extract, unknown kinds are retained and recallable. A new value for an exclusive attribute *supersedes* the old one (history stays queryable). |
|
|
47
|
+
| `contextPack` | `contextPack(query: string, opts?)` | `ContextPackResponse` | The **product read**: a ready-to-inject `pack`, structured `citations` / `claims` with `is_current`, and the faithfulness fields `abstained` / `reason_code` / `grounding` / `pack_sufficient` / `as_of` / `trace_id`. No free-form synthesis. |
|
|
48
|
+
| `forget` | `forget(entity: string, opts?)` | `ForgetResponse` | **Withdraw**, not erase history: recall stops returning it; as-of-T reads before `at` still see it. `{ erase: true }` (or `erase()`) is the destructive right-to-be-forgotten path. |
|
|
49
|
+
| `explain` | `explain(traceId: number, opts?)` | `ExplainResponse` | **Why** a pack/recall surfaced what it surfaced: the cited claims (labels resolved, inclusion probability each), `best_nonconformity` vs the tenant threshold `q_hat`, and `isGrounded(r)`. `found: false` + `error` is in-band. |
|
|
162
50
|
|
|
163
|
-
|
|
164
|
-
// Add tags to a memory
|
|
165
|
-
await client.addTags(memoryId, ['important', 'follow-up']);
|
|
51
|
+
Plus `health()` (liveness probe, no auth).
|
|
166
52
|
|
|
167
|
-
|
|
168
|
-
await client.removeTags(memoryId, ['follow-up']);
|
|
53
|
+
### Options
|
|
169
54
|
|
|
170
|
-
|
|
171
|
-
|
|
55
|
+
- `ingest`: `{ scope?, sourceId?, observedAt?, source?, rawContext?, branch?, subjectHint?, metadata? }` —
|
|
56
|
+
`source` / `rawContext` / `branch` apply to the facts form; `subjectHint` / `metadata` to text / url / bytes.
|
|
57
|
+
- `contextPack`: `{ scope?, now?, asOf?, anchor?, attribute? }`
|
|
58
|
+
- `forget`: `{ scope?, attribute?, value?, erase?, at? }`
|
|
59
|
+
- `explain`: `{ scope? }`
|
|
172
60
|
|
|
173
|
-
|
|
174
|
-
|
|
61
|
+
`ingest` takes **exactly one** content form. `sourceId` (the idempotency key the wire requires)
|
|
62
|
+
defaults to a **content hash** — `ingestSourceId(content)` — so re-sending the same payload is a
|
|
63
|
+
no-op; the key actually sent is echoed on `source_id`. `kind` tells you which server path ran
|
|
64
|
+
(`"facts"` → the `remember` receipt on `remember`; `"content"` → the raw-durable receipt on
|
|
65
|
+
`content` with `blob_id` / `detected` / `reader_error`).
|
|
175
66
|
|
|
176
|
-
|
|
177
|
-
|
|
67
|
+
`anchor` (an entity surface form like `"Maya"`) + `attribute` (a predicate like `"employer"`)
|
|
68
|
+
take the exact-key **fast path**. Omit them for free-text semantic reads — same response shape.
|
|
178
69
|
|
|
179
|
-
|
|
180
|
-
const tagStats = await client.getTagStats();
|
|
181
|
-
```
|
|
70
|
+
### Full profile / legacy aliases
|
|
182
71
|
|
|
183
|
-
|
|
72
|
+
The engine's full tool profile (`CILOW_MCP_PROFILE=full`) also advertises the older verbs, and
|
|
73
|
+
the client keeps them as aliases with their original receipts:
|
|
184
74
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
})
|
|
75
|
+
| Alias | Signature | Returns |
|
|
76
|
+
|-------|-----------|---------|
|
|
77
|
+
| `remember` | `remember(facts: Fact[], { scope?, source?, sourceId?, observedAt?, rawContext?, branch? })` | `RememberResponse` (write receipt) |
|
|
78
|
+
| `recall` | `recall(query: string, { scope?, asOf?, now?, anchor?, attribute?, branch? })` | `RecallResponse` (`abstained`, `claims`, `receipt`) |
|
|
79
|
+
| `answer` | `answer(query: string, { scope?, now?, anchor?, attribute?, branch? })` | `AnswerResponse` (`abstained`, `text`, `citations`) |
|
|
80
|
+
| `timeline` | `timeline(entity: string, { scope?, at?, from?, to? })` | `TimelineEntry[]` (bitemporal history) |
|
|
81
|
+
| `trackEntity` | `trackEntity(name: string, { scope?, at? })` | `TrackEntityResponse` (canonical id + alias class) |
|
|
192
82
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
});
|
|
83
|
+
Also available: `rememberText`, `ingestImage` / `ingestAudio` / `ingestPdf` / `ingestStructured`,
|
|
84
|
+
`save` / `ingestAny`, `feedback`, `consolidate`, `fork` / `branchList`, `blobGet` / `blobMeta` /
|
|
85
|
+
`blobList`, and the `cilow.memories.*` id-based REST surface (also exposed to frameworks via
|
|
86
|
+
`@cilow/sdk/adapters`).
|
|
198
87
|
|
|
199
|
-
|
|
200
|
-
const agent = await client.getAgent(agentId);
|
|
88
|
+
### Time is in microseconds
|
|
201
89
|
|
|
202
|
-
|
|
203
|
-
|
|
90
|
+
Every time field (`observedAt`, `asOf`, `now`, `at`, `from`, `to`, and the `valid_from` /
|
|
91
|
+
`valid_until` on timeline entries) is **epoch microseconds (µs)**, matching the engine. They all
|
|
92
|
+
default to "now" (`Date.now() * 1000`). Use the exported `nowMicros()` helper if you need it:
|
|
204
93
|
|
|
205
|
-
|
|
206
|
-
|
|
94
|
+
```ts
|
|
95
|
+
import { nowMicros } from "@cilow/sdk";
|
|
96
|
+
const t = nowMicros();
|
|
97
|
+
await cilow.remember(facts, { observedAt: t });
|
|
98
|
+
const past = await cilow.recall("...", { asOf: t - 86_400_000_000, now: t }); // a day ago
|
|
207
99
|
```
|
|
208
100
|
|
|
209
|
-
##
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
// Create a new API key
|
|
213
|
-
const apiKey = await client.createApiKey({
|
|
214
|
-
name: 'Production API Key',
|
|
215
|
-
expiresAt: new Date('2025-01-01'),
|
|
216
|
-
});
|
|
101
|
+
## The deferral contract
|
|
217
102
|
|
|
218
|
-
|
|
219
|
-
|
|
103
|
+
`contextPack` (and the `recall` / `answer` aliases) **never throw** for a deferral — they return
|
|
104
|
+
a normal response with a boolean flag. When `abstained` is `true`, the pack / claims / citations
|
|
105
|
+
are empty and `reason_code` says why: `below_threshold` / `no_candidates` are a *calibrated*
|
|
106
|
+
abstain (memory genuinely lacks grounded context — do not fabricate past it), while
|
|
107
|
+
`provider_unavailable` is an *infrastructure* abstain (retry when the provider recovers). Branch
|
|
108
|
+
with `isCalibratedAbstain(r)` / `isInfrastructureAbstain(r)` rather than matching strings.
|
|
220
109
|
|
|
221
|
-
|
|
222
|
-
|
|
110
|
+
On `answer` / `contextPack` an abstain also names **which layer stopped it** — `r.terminal_layer`
|
|
111
|
+
(`structural` | `gate` | `provider` | `reader` | `verifier`; `stoppedAt(r)` is the same thing gated on
|
|
112
|
+
`abstained`). Only `provider` is retryable. Both surfaces also carry `r.evidence`: the claim, span,
|
|
113
|
+
and verbatim lanes collapsed into one list ordered by fused cross-lane rank (`Evidence.origins`
|
|
114
|
+
says which lanes agreed; `Evidence.structure` is present when a typed claim backs the unit). It is
|
|
115
|
+
present on abstains too — the raw lanes have no standing at the gate, but you may still read them.
|
|
223
116
|
|
|
224
|
-
|
|
225
|
-
await
|
|
117
|
+
```ts
|
|
118
|
+
const r = await cilow.contextPack("what is Maya's salary", { anchor: "Maya", attribute: "salary" });
|
|
119
|
+
if (r.abstained) {
|
|
120
|
+
// r.pack is empty; r.reason explains the configured gate decision.
|
|
121
|
+
return `I don't have that in memory (${r.reason}).`;
|
|
122
|
+
}
|
|
123
|
+
return r.pack;
|
|
226
124
|
```
|
|
227
125
|
|
|
228
|
-
|
|
126
|
+
Every read carries a `trace_id`. Hand it to `explain` for the audit trail — the cited claims,
|
|
127
|
+
the tenant's conformal threshold `q_hat`, the best candidate's `best_nonconformity` (grounded iff
|
|
128
|
+
`n ≤ q̂`, see `isGrounded`) — or to `feedback` so memory learns from the outcome. This is the
|
|
129
|
+
difference between "I don't know" and a confident wrong answer.
|
|
229
130
|
|
|
230
|
-
|
|
231
|
-
// List active sessions
|
|
232
|
-
const sessions = await client.listSessions();
|
|
131
|
+
## Errors
|
|
233
132
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// Revoke all other sessions
|
|
238
|
-
await client.revokeOtherSessions();
|
|
239
|
-
|
|
240
|
-
// Revoke all sessions (logout everywhere)
|
|
241
|
-
await client.revokeAllSessions();
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
## Error Handling
|
|
245
|
-
|
|
246
|
-
```typescript
|
|
247
|
-
import {
|
|
248
|
-
CilowError,
|
|
249
|
-
AuthenticationError,
|
|
250
|
-
NotFoundError,
|
|
251
|
-
RateLimitError
|
|
252
|
-
} from '@cilow/sdk';
|
|
133
|
+
`CilowError` is thrown for genuine failures — auth (`401` / JSON-RPC `-32001`), bad params,
|
|
134
|
+
transport errors, malformed responses. A deferral is not an error.
|
|
253
135
|
|
|
136
|
+
```ts
|
|
137
|
+
import { CilowError } from "@cilow/sdk";
|
|
254
138
|
try {
|
|
255
|
-
await
|
|
256
|
-
} catch (
|
|
257
|
-
if (
|
|
258
|
-
console.error('Invalid API key');
|
|
259
|
-
} else if (error instanceof NotFoundError) {
|
|
260
|
-
console.error('Resource not found');
|
|
261
|
-
} else if (error instanceof RateLimitError) {
|
|
262
|
-
console.error('Rate limited, retry later');
|
|
263
|
-
} else if (error instanceof CilowError) {
|
|
264
|
-
console.error(`API error: ${error.message}`);
|
|
265
|
-
}
|
|
139
|
+
await cilow.recall("...");
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (e instanceof CilowError && e.isUnauthorized) { /* bad/expired token */ }
|
|
266
142
|
}
|
|
267
143
|
```
|
|
268
144
|
|
|
269
|
-
##
|
|
270
|
-
|
|
271
|
-
```typescript
|
|
272
|
-
const client = new CilowClient({
|
|
273
|
-
// API base URL (default: http://localhost:8080)
|
|
274
|
-
baseUrl: 'https://api.cilow.ai',
|
|
275
|
-
|
|
276
|
-
// API key for authentication
|
|
277
|
-
apiKey: 'cilow_your_api_key',
|
|
278
|
-
|
|
279
|
-
// JWT access token (alternative to API key)
|
|
280
|
-
accessToken: 'eyJhbGc...',
|
|
145
|
+
## Develop
|
|
281
146
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
147
|
+
```sh
|
|
148
|
+
npm install
|
|
149
|
+
npm run build # tsc → dist/
|
|
150
|
+
npm test # node:test — client + adapters suites, mocks the HTTP layer (no server needed)
|
|
151
|
+
npm run example # runs examples/quickstart.ts against a live server
|
|
285
152
|
```
|
|
286
|
-
|
|
287
|
-
## Types
|
|
288
|
-
|
|
289
|
-
All types are fully exported for TypeScript users:
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
import type {
|
|
293
|
-
Memory,
|
|
294
|
-
MemoryStats,
|
|
295
|
-
SearchResult,
|
|
296
|
-
Agent,
|
|
297
|
-
User,
|
|
298
|
-
ApiKey,
|
|
299
|
-
AddMemoryOptions,
|
|
300
|
-
SearchMemoriesOptions,
|
|
301
|
-
} from '@cilow/sdk';
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
## Self-Hosting
|
|
305
|
-
|
|
306
|
-
Cilow can be self-hosted. Point the SDK to your instance:
|
|
307
|
-
|
|
308
|
-
```typescript
|
|
309
|
-
const client = new CilowClient({
|
|
310
|
-
baseUrl: 'http://localhost:8080',
|
|
311
|
-
apiKey: 'your-local-api-key',
|
|
312
|
-
});
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
## Requirements
|
|
316
|
-
|
|
317
|
-
- Node.js >= 18.0.0
|
|
318
|
-
- ES2020+ or modern browser with fetch support
|
|
319
|
-
|
|
320
|
-
## License
|
|
321
|
-
|
|
322
|
-
MIT
|