@cilow/sdk 0.2.1 → 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 -0
- package/README.md +109 -492
- 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 +512 -173
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +648 -504
- package/dist/client.js.map +1 -1
- 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 +18 -109
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -876
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +809 -486
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -17
- package/dist/types.js.map +1 -1
- package/package.json +30 -103
- package/dist/client.d.mts +0 -224
- package/dist/client.mjs +0 -505
- package/dist/client.mjs.map +0 -1
- package/dist/index.d.mts +0 -111
- package/dist/index.mjs +0 -863
- package/dist/index.mjs.map +0 -1
- package/dist/providers/langchain.js +0 -821
- package/dist/providers/langchain.js.map +0 -1
- package/dist/providers/langchain.mjs +0 -816
- package/dist/providers/langchain.mjs.map +0 -1
- package/dist/providers/openai.js +0 -737
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/openai.mjs +0 -732
- package/dist/providers/openai.mjs.map +0 -1
- package/dist/providers/vercel.js +0 -866
- package/dist/providers/vercel.js.map +0 -1
- package/dist/providers/vercel.mjs +0 -860
- package/dist/providers/vercel.mjs.map +0 -1
- package/dist/react/hooks.d.mts +0 -327
- package/dist/react/hooks.d.ts +0 -327
- package/dist/react/hooks.js +0 -1183
- package/dist/react/hooks.js.map +0 -1
- package/dist/react/hooks.mjs +0 -1172
- package/dist/react/hooks.mjs.map +0 -1
- package/dist/types.d.mts +0 -494
- package/dist/types.mjs +0 -14
- package/dist/types.mjs.map +0 -1
- package/dist/websocket.d.mts +0 -160
- package/dist/websocket.d.ts +0 -160
- package/dist/websocket.js +0 -342
- package/dist/websocket.js.map +0 -1
- package/dist/websocket.mjs +0 -339
- package/dist/websocket.mjs.map +0 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,224 +1,563 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { AnswerResponse, Branch, ConsolidateResponse, Fact, FeedbackResponse, ContextPackResponse, ExplainResponse, ForgetResponse, IngestResponse, BlobGetResponse, BlobMetaResponse, BlobListResponse, ForkResponse, IngestAudioResponse, IngestImageResponse, IngestPdfResponse, IngestAnyResponse, IngestStructuredResponse, Outcome, RecallResponse, RememberResponse, RememberTextResponse, Scope, Source, TimelineEntry, TrackEntityResponse, WorkspaceResponse, EvidenceResponse, InvestigateResponse, CompileContextResponse, TraceResponse, EpisodeResponse, MemoryResponse } from "./types.js";
|
|
2
|
+
/** Current wall clock as epoch MICROSECONDS — the unit every Cilow time field uses. */
|
|
3
|
+
export declare function nowMicros(): number;
|
|
4
|
+
/** The content forms `ingest` accepts — exactly one. `url` is sent as `text` (the wire's one text
|
|
5
|
+
* field is "raw text or a URL"; the server fetches + snapshots a bare URL). */
|
|
6
|
+
export type IngestContent = {
|
|
7
|
+
facts: Fact[];
|
|
8
|
+
} | {
|
|
9
|
+
text: string;
|
|
10
|
+
} | {
|
|
11
|
+
url: string;
|
|
12
|
+
} | {
|
|
13
|
+
contentBase64: string;
|
|
14
|
+
mime?: string;
|
|
15
|
+
};
|
|
3
16
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
17
|
+
* The idempotency key `ingest` sends when you pass no `sourceId`: a sha256 CONTENT HASH.
|
|
18
|
+
* The wire requires `source_id` (`RememberRequest.source_id` / `IngestAnyRequest.source_id` are
|
|
19
|
+
* non-optional) and a timestamp would make every retry a fresh write; hashing the content makes a
|
|
20
|
+
* retry of the same payload an idempotent no-op (the engine dedups under the tenant on this key).
|
|
21
|
+
* Pre-image: `"<form>:<content>"`, facts as canonical JSON (sorted keys, compact). The Python SDK's
|
|
22
|
+
* `ingest_source_id` computes the identical key.
|
|
8
23
|
*/
|
|
9
|
-
|
|
24
|
+
export declare function ingestSourceId(content: IngestContent): string;
|
|
25
|
+
/** Options for `new CilowClient(...)`. */
|
|
26
|
+
export interface CilowClientOptions {
|
|
27
|
+
/** Base URL of a running cilow-serve, e.g. `http://localhost:8080`. */
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
/** Bearer token (the `CILOW_TOKENS` entry). Required for `/rpc`; the server stamps its scope. */
|
|
30
|
+
token: string;
|
|
31
|
+
/**
|
|
32
|
+
* Default scope sent with every call. Over HTTP this is ignored (the server stamps it
|
|
33
|
+
* from the token), but it is honored by the stdio MCP transport, so it is kept for parity.
|
|
34
|
+
*/
|
|
35
|
+
scope?: Scope;
|
|
36
|
+
/** Optional `fetch` implementation (defaults to global `fetch`). */
|
|
37
|
+
fetch?: typeof fetch;
|
|
38
|
+
/** Per-request timeout in milliseconds (default 30000). */
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface RememberOptions {
|
|
42
|
+
scope?: Scope;
|
|
43
|
+
/** Provenance kind (default `operator`). */
|
|
44
|
+
source?: Source;
|
|
45
|
+
/** Idempotency / provenance id for this batch (dedup key). Defaults to a generated id. */
|
|
46
|
+
sourceId?: string;
|
|
47
|
+
/** Observation time in epoch µs — the claims' `valid_from` (default: now). */
|
|
48
|
+
observedAt?: number;
|
|
49
|
+
/**
|
|
50
|
+
* The RAW source text these facts were extracted from (recommended). Captured durably into the
|
|
51
|
+
* engine's verbatim lane and made searchable — the lossless backstop, so a detail the extractor
|
|
52
|
+
* dropped is still recallable from the raw text. Without it the engine stores only the lossy claims.
|
|
53
|
+
* Mirrors the engine's `RememberRequest.raw_context`.
|
|
54
|
+
*/
|
|
55
|
+
rawContext?: string;
|
|
56
|
+
/** Track A1: the git-style branch NAME to write to (default `"main"` = trunk). A fork's writes are
|
|
57
|
+
* isolated from main and other branches. */
|
|
58
|
+
branch?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface RecallOptions {
|
|
61
|
+
scope?: Scope;
|
|
62
|
+
/** The valid-time `T` to read as-of, in epoch µs (default: now). `< now` ⇒ a historical read. */
|
|
63
|
+
asOf?: number;
|
|
64
|
+
/** The present clock in epoch µs (default: now). */
|
|
65
|
+
now?: number;
|
|
66
|
+
/** Optional fast-path entity-surface hint, e.g. `"Maya"`. */
|
|
67
|
+
anchor?: string;
|
|
68
|
+
/** Optional fast-path predicate hint, e.g. `"employer"`. */
|
|
69
|
+
attribute?: string;
|
|
70
|
+
/** Track A1: the git-style branch NAME to read from (default `"main"` = trunk). An anchored read on a
|
|
71
|
+
* branch sees the branch's values, falling back to the base as-of the fork point for keys it never
|
|
72
|
+
* wrote. */
|
|
73
|
+
branch?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface AnswerOptions {
|
|
76
|
+
scope?: Scope;
|
|
77
|
+
/** The present clock in epoch µs (default: now). */
|
|
78
|
+
now?: number;
|
|
79
|
+
anchor?: string;
|
|
80
|
+
attribute?: string;
|
|
81
|
+
/** Track A1: the git-style branch NAME to answer from (default `"main"` = trunk). */
|
|
82
|
+
branch?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface ForkOptions {
|
|
85
|
+
scope?: Scope;
|
|
86
|
+
/** The base branch to fork from (default `"main"` = trunk). */
|
|
87
|
+
from?: string;
|
|
88
|
+
/** The fork instant in epoch µs — the valid-time cap the branch's read falls back under (default now). */
|
|
89
|
+
now?: number;
|
|
90
|
+
}
|
|
91
|
+
export interface TimelineOptions {
|
|
92
|
+
scope?: Scope;
|
|
93
|
+
/** The instant the `active` flag is computed against, in epoch µs (default: now). */
|
|
94
|
+
at?: number;
|
|
95
|
+
/** Optional window start (epoch µs). */
|
|
96
|
+
from?: number;
|
|
97
|
+
/** Optional window end (epoch µs). */
|
|
98
|
+
to?: number;
|
|
99
|
+
}
|
|
100
|
+
export interface TrackEntityOptions {
|
|
101
|
+
scope?: Scope;
|
|
102
|
+
/** The instant the alias class is resolved as-of, in epoch µs (default: now). */
|
|
103
|
+
at?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface FeedbackOptions {
|
|
106
|
+
scope?: Scope;
|
|
107
|
+
}
|
|
108
|
+
export interface ConsolidateOptions {
|
|
109
|
+
scope?: Scope;
|
|
110
|
+
/** The present clock in epoch µs the decay/recency pass reads against (default: now). */
|
|
111
|
+
now?: number;
|
|
112
|
+
}
|
|
113
|
+
export interface RememberTextOptions {
|
|
114
|
+
scope?: Scope;
|
|
115
|
+
/** Idempotency / provenance id (default: generated). */
|
|
116
|
+
sourceId?: string;
|
|
117
|
+
/** Observation time in epoch µs — the claims' `valid_from` (default: now). */
|
|
118
|
+
observedAt?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface IngestImageOptions {
|
|
121
|
+
scope?: Scope;
|
|
122
|
+
sourceId?: string;
|
|
123
|
+
observedAt?: number;
|
|
124
|
+
}
|
|
125
|
+
export interface IngestAudioOptions {
|
|
126
|
+
scope?: Scope;
|
|
127
|
+
sourceId?: string;
|
|
128
|
+
observedAt?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface IngestPdfOptions {
|
|
131
|
+
scope?: Scope;
|
|
132
|
+
sourceId?: string;
|
|
133
|
+
observedAt?: number;
|
|
134
|
+
}
|
|
135
|
+
export interface IngestStructuredOptions {
|
|
136
|
+
scope?: Scope;
|
|
137
|
+
/** The column/key whose value names the entity (omit ⇒ subjectHint + row index). */
|
|
138
|
+
subjectField?: string;
|
|
139
|
+
sourceId?: string;
|
|
140
|
+
observedAt?: number;
|
|
141
|
+
}
|
|
142
|
+
export interface IngestAnyOptions {
|
|
143
|
+
scope?: Scope;
|
|
144
|
+
/** Optional mime HINT (the sniff verifies; bytes win a contradiction). */
|
|
145
|
+
mime?: string;
|
|
146
|
+
/** The subject derived facts anchor to when the content names none (defaults to the document). */
|
|
147
|
+
subjectHint?: string;
|
|
148
|
+
/** Free-form provenance pairs — each becomes a claim on the document entity. */
|
|
149
|
+
metadata?: Record<string, string>;
|
|
150
|
+
sourceId?: string;
|
|
151
|
+
observedAt?: number;
|
|
152
|
+
}
|
|
153
|
+
export interface ForgetOptions {
|
|
154
|
+
scope?: Scope;
|
|
155
|
+
/** Scope the forget to one attribute (omit to forget the whole entity). */
|
|
156
|
+
attribute?: string;
|
|
157
|
+
/** Forget exactly this value (requires `attribute`). */
|
|
158
|
+
value?: string;
|
|
159
|
+
/**
|
|
160
|
+
* When true, destroy the entity (OF1): truth + verbatim + span/claim ANN + known embed-cache
|
|
161
|
+
* keys. Attribute/value are ignored. Not complete Art.17 (query-cache residual).
|
|
162
|
+
*/
|
|
163
|
+
erase?: boolean;
|
|
164
|
+
/** The instant the claims are retired as-of, in epoch µs (default: now). */
|
|
165
|
+
at?: number;
|
|
166
|
+
}
|
|
167
|
+
export interface IngestOptions {
|
|
168
|
+
scope?: Scope;
|
|
169
|
+
/** Idempotency / provenance key. Default: a content hash (see `ingestSourceId`) — retries dedup. */
|
|
170
|
+
sourceId?: string;
|
|
171
|
+
/** Observation time in epoch µs — the claims' `valid_from` (default: now). */
|
|
172
|
+
observedAt?: number;
|
|
173
|
+
/** Provenance kind (default `operator`). */
|
|
174
|
+
source?: Source;
|
|
175
|
+
/** The RAW source text the facts were extracted from — captured into the verbatim lane (lossless backstop). */
|
|
176
|
+
rawContext?: string;
|
|
177
|
+
/** Track A1: the git-style branch NAME to write to (default `"main"`). */
|
|
178
|
+
branch?: string;
|
|
179
|
+
/** The subject derived facts anchor to when the content names none (defaults to the document). */
|
|
180
|
+
subjectHint?: string;
|
|
181
|
+
/** Free-form provenance pairs — each becomes a claim on the document entity. */
|
|
182
|
+
metadata?: Record<string, string>;
|
|
183
|
+
}
|
|
184
|
+
export interface ContextPackOptions {
|
|
185
|
+
scope?: Scope;
|
|
186
|
+
/** Epoch µs — default now. */
|
|
187
|
+
now?: number;
|
|
188
|
+
/** Read truth as-of this instant (default: now). */
|
|
189
|
+
asOf?: number;
|
|
190
|
+
anchor?: string;
|
|
191
|
+
attribute?: string;
|
|
192
|
+
}
|
|
193
|
+
/** One claim minted by `memories.add`, with its opaque id. */
|
|
194
|
+
export interface AddedMemory {
|
|
195
|
+
id: string;
|
|
196
|
+
subject: string;
|
|
197
|
+
predicate: string;
|
|
198
|
+
object: string;
|
|
199
|
+
}
|
|
200
|
+
/** `memories.add` result — the episode echo handle + the per-claim memory ids. */
|
|
201
|
+
export interface MemoryAddResult {
|
|
202
|
+
id: string;
|
|
203
|
+
status: string;
|
|
204
|
+
count: number;
|
|
205
|
+
memories: AddedMemory[];
|
|
206
|
+
error?: string;
|
|
207
|
+
}
|
|
208
|
+
/** One search hit — `text` is a ready-to-inject line; the structured fields are kept alongside. */
|
|
209
|
+
export interface SearchHit {
|
|
210
|
+
id: string;
|
|
211
|
+
text: string;
|
|
212
|
+
entity: string;
|
|
213
|
+
subject?: string;
|
|
214
|
+
predicate?: string;
|
|
215
|
+
value: string;
|
|
216
|
+
score: number;
|
|
217
|
+
}
|
|
218
|
+
/** `memories.search` result — check `abstained` FIRST (when true, `results` is empty). */
|
|
219
|
+
export interface MemorySearchResult {
|
|
220
|
+
abstained: boolean;
|
|
221
|
+
trace_id: number;
|
|
222
|
+
results: SearchHit[];
|
|
223
|
+
reason?: string;
|
|
224
|
+
/** The MACHINE-readable abstain code (`below_threshold` | `no_candidates` | `provider_unavailable`). */
|
|
225
|
+
reason_code?: string;
|
|
226
|
+
/** The configured gate's confidence margin (q̂ − n). */
|
|
227
|
+
margin?: number;
|
|
228
|
+
/** Token-efficiency of the packed working set. */
|
|
229
|
+
packed_tokens?: number;
|
|
230
|
+
coverage_score?: number;
|
|
231
|
+
/** working_set: a ready-to-inject context block; answer: the synthesized prose answer. */
|
|
232
|
+
context_text?: string;
|
|
233
|
+
}
|
|
234
|
+
/** One memory as returned by `memories.get` / `memories.list`. */
|
|
235
|
+
export interface MemoryView {
|
|
236
|
+
id: string;
|
|
237
|
+
entity: string;
|
|
238
|
+
subject?: string;
|
|
239
|
+
predicate_id: number;
|
|
240
|
+
predicate?: string;
|
|
241
|
+
value: string;
|
|
242
|
+
confidence: number;
|
|
243
|
+
valid_from: number;
|
|
244
|
+
valid_until?: number;
|
|
245
|
+
active: boolean;
|
|
246
|
+
}
|
|
247
|
+
export interface MemoryListResult {
|
|
248
|
+
memories: MemoryView[];
|
|
249
|
+
total: number;
|
|
250
|
+
offset: number;
|
|
251
|
+
limit: number;
|
|
252
|
+
}
|
|
253
|
+
export interface MemoryUpdateResult {
|
|
254
|
+
ok: boolean;
|
|
255
|
+
id?: string;
|
|
256
|
+
previous_id?: string;
|
|
257
|
+
error?: string;
|
|
258
|
+
}
|
|
259
|
+
export interface MemoryDeleteResult {
|
|
260
|
+
ok: boolean;
|
|
261
|
+
deleted: number;
|
|
262
|
+
}
|
|
263
|
+
export interface AddMemoryOptions {
|
|
264
|
+
/** Base64 bytes of ANY type — routed through the never-reject ingest_any pipeline. */
|
|
265
|
+
contentBase64?: string;
|
|
266
|
+
/** Optional mime hint for `contentBase64` (the sniff verifies). */
|
|
267
|
+
mime?: string;
|
|
268
|
+
/** Default subject when the text names none (e.g. a user id). */
|
|
269
|
+
subjectHint?: string;
|
|
270
|
+
/** Dedup / idempotency key. */
|
|
271
|
+
customId?: string;
|
|
272
|
+
/** When the fact was observed, in epoch µs (default: server clock). */
|
|
273
|
+
observedAt?: number;
|
|
274
|
+
/** Reserved free-form metadata (accepted + echoed; not yet indexed). */
|
|
275
|
+
metadata?: Record<string, unknown>;
|
|
276
|
+
}
|
|
277
|
+
export interface SearchMemoryOptions {
|
|
278
|
+
/** Optional entity hint (exact fast-path lookup). */
|
|
279
|
+
anchor?: string;
|
|
280
|
+
/** Optional predicate hint (exact fast-path lookup). */
|
|
281
|
+
attribute?: string;
|
|
282
|
+
/** Result shape: "claims" (default) | "working_set" (adds a ready-to-inject context block) | "answer". */
|
|
283
|
+
mode?: "claims" | "working_set" | "answer";
|
|
284
|
+
}
|
|
285
|
+
export interface ListMemoryOptions {
|
|
286
|
+
offset?: number;
|
|
287
|
+
limit?: number;
|
|
288
|
+
/** When true, exclude retired/superseded history. */
|
|
289
|
+
activeOnly?: boolean;
|
|
290
|
+
}
|
|
10
291
|
/**
|
|
11
|
-
*
|
|
292
|
+
* The friendly id-based memories surface — the same six verbs as the HTTP API (`/v1/memories/*`) and
|
|
293
|
+
* the MCP tools. Reached via `client.memories`.
|
|
294
|
+
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* const m = await cilow.memories.add("Maya is a senior engineer at Acme", { subjectHint: "Maya" });
|
|
297
|
+
* const r = await cilow.memories.search("where does Maya work", { anchor: "Maya", attribute: "employer" });
|
|
298
|
+
* if (!r.abstained) await cilow.memories.delete(r.results[0].id);
|
|
299
|
+
* ```
|
|
12
300
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
301
|
+
export interface MemoriesApi {
|
|
302
|
+
add(content: string, opts?: AddMemoryOptions): Promise<MemoryAddResult>;
|
|
303
|
+
search(query: string, opts?: SearchMemoryOptions): Promise<MemorySearchResult>;
|
|
304
|
+
/** Fetch one memory by id; resolves to `null` if it doesn't exist (or isn't this tenant's). */
|
|
305
|
+
get(id: string): Promise<MemoryView | null>;
|
|
306
|
+
list(opts?: ListMemoryOptions): Promise<MemoryListResult>;
|
|
307
|
+
update(id: string, value: string, opts?: {
|
|
308
|
+
observedAt?: number;
|
|
309
|
+
}): Promise<MemoryUpdateResult>;
|
|
310
|
+
delete(id: string, opts?: {
|
|
311
|
+
at?: number;
|
|
312
|
+
}): Promise<MemoryDeleteResult>;
|
|
313
|
+
batchAdd(items: Array<{
|
|
314
|
+
content: string;
|
|
315
|
+
} & AddMemoryOptions>): Promise<{
|
|
316
|
+
count: number;
|
|
317
|
+
results: MemoryAddResult[];
|
|
318
|
+
}>;
|
|
18
319
|
}
|
|
19
320
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const client = new CilowClient({
|
|
25
|
-
* apiUrl: 'https://api.cilow.ai',
|
|
26
|
-
* apiKey: 'your-api-key'
|
|
27
|
-
* });
|
|
321
|
+
* A thin, typed client for a running cilow-serve. One instance, five verbs:
|
|
28
322
|
*
|
|
29
|
-
*
|
|
30
|
-
* const
|
|
31
|
-
*
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* //
|
|
35
|
-
* const results = await client.recall("user preferences");
|
|
36
|
-
*
|
|
37
|
-
* // Delete memories
|
|
38
|
-
* await client.forget({ tags: ["old"] });
|
|
323
|
+
* ```ts
|
|
324
|
+
* const cilow = new CilowClient({ baseUrl: "http://localhost:8080", token: "demo" });
|
|
325
|
+
* await cilow.remember([{ subject: "Maya", predicate: "employer", object: "Acme" }]);
|
|
326
|
+
* const r = await cilow.recall("where does Maya work", { anchor: "Maya", attribute: "employer" });
|
|
327
|
+
* if (r.abstained) console.log("engine doesn't know:", r.reason);
|
|
328
|
+
* else console.log(r.claims[0].value); // "Acme"
|
|
39
329
|
* ```
|
|
330
|
+
*
|
|
331
|
+
* Handles the JSON-RPC 2.0 envelope, bearer auth, and error mapping. The abstention
|
|
332
|
+
* contract is surfaced as a plain `abstained` boolean on `recall`/`answer` — never an
|
|
333
|
+
* exception. CilowError is thrown only for protocol / transport / auth failures.
|
|
40
334
|
*/
|
|
41
|
-
declare class CilowClient {
|
|
335
|
+
export declare class CilowClient {
|
|
42
336
|
private readonly baseUrl;
|
|
43
|
-
private readonly
|
|
44
|
-
private readonly
|
|
45
|
-
private readonly
|
|
46
|
-
private readonly
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
337
|
+
private readonly token;
|
|
338
|
+
private readonly scope;
|
|
339
|
+
private readonly fetchImpl;
|
|
340
|
+
private readonly timeoutMs;
|
|
341
|
+
/** The friendly id-based memories surface: `client.memories.add(...)` etc. */
|
|
342
|
+
readonly memories: MemoriesApi;
|
|
343
|
+
constructor(opts: CilowClientOptions);
|
|
344
|
+
/** Liveness probe — `GET /health`, no auth. Returns true iff the server is up. */
|
|
345
|
+
health(): Promise<boolean>;
|
|
346
|
+
/** Ingest `(subject, predicate, object)` facts as bitemporal claims. Returns the write receipt. */
|
|
347
|
+
remember(facts: Fact[], opts?: RememberOptions): Promise<RememberResponse>;
|
|
53
348
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param content - The content to remember
|
|
57
|
-
* @param options - Optional configuration
|
|
58
|
-
* @returns The created memory ID
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* await cilow.remember("User prefers dark mode", {
|
|
63
|
-
* tags: ["preference"],
|
|
64
|
-
* userId: "user-123"
|
|
65
|
-
* });
|
|
66
|
-
* ```
|
|
349
|
+
* Retrieve claims as-of a valid-time T, OR a calibrated abstain. Check `abstained`
|
|
350
|
+
* first. When true, `claims` is empty; use the caller's fallback or safe-deferral policy.
|
|
67
351
|
*/
|
|
68
|
-
|
|
352
|
+
recall(query: string, opts?: RecallOptions): Promise<RecallResponse>;
|
|
69
353
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @param query - Search query text
|
|
73
|
-
* @param options - Search options
|
|
74
|
-
* @returns Array of search results
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* const memories = await cilow.recall("user preferences", {
|
|
79
|
-
* limit: 10,
|
|
80
|
-
* tags: ["preference"]
|
|
81
|
-
* });
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
recall(query: string, options?: {
|
|
85
|
-
limit?: number;
|
|
86
|
-
minRelevance?: number;
|
|
87
|
-
tags?: string[];
|
|
88
|
-
userId?: string;
|
|
89
|
-
}): Promise<SearchResult[]>;
|
|
90
|
-
/**
|
|
91
|
-
* Delete memories (simple API)
|
|
92
|
-
*
|
|
93
|
-
* @param filter - Filter criteria for deletion
|
|
94
|
-
* @returns Number of memories deleted
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* // Delete by tags
|
|
99
|
-
* await cilow.forget({ tags: ["temporary"] });
|
|
100
|
-
*
|
|
101
|
-
* // Delete by user
|
|
102
|
-
* await cilow.forget({ userId: "user-123" });
|
|
103
|
-
*
|
|
104
|
-
* // Delete specific memory
|
|
105
|
-
* await cilow.forget({ memoryId: "mem-abc" });
|
|
106
|
-
* ```
|
|
354
|
+
* Present-time synthesized answer with citations, OR a calibrated abstain. When
|
|
355
|
+
* `abstained` is true, `text` is the honored abstain message and `citations` is empty.
|
|
107
356
|
*/
|
|
108
|
-
|
|
109
|
-
memoryId?: string;
|
|
110
|
-
tags?: string[];
|
|
111
|
-
userId?: string;
|
|
112
|
-
sessionId?: string;
|
|
113
|
-
olderThan?: string;
|
|
114
|
-
}): Promise<number>;
|
|
357
|
+
answer(query: string, opts?: AnswerOptions): Promise<AnswerResponse>;
|
|
115
358
|
/**
|
|
116
|
-
*
|
|
359
|
+
* Track A1 — create a git-style BRANCH of this tenant's memory (O(1), copies nothing). Write/
|
|
360
|
+
* supersede facts on the branch (`remember(facts, { branch: name })`) and they stay ISOLATED from
|
|
361
|
+
* `main` and other branches; an anchored `recall(q, { branch: name })` inherits main's value as of
|
|
362
|
+
* the fork for keys the branch never wrote. Check `ok`: false ⇒ rejected (see `error`).
|
|
117
363
|
*/
|
|
118
|
-
|
|
364
|
+
fork(name: string, opts?: ForkOptions): Promise<ForkResponse>;
|
|
365
|
+
/** Track A1 — list this tenant's git-style branches (`main` first, then forks in name order). */
|
|
366
|
+
branchList(opts?: {
|
|
367
|
+
scope?: Scope;
|
|
368
|
+
}): Promise<Branch[]>;
|
|
369
|
+
/** The as-of-T bitemporal history of an entity's claims, ascending by `valid_from`. */
|
|
370
|
+
timeline(entity: string, opts?: TimelineOptions): Promise<TimelineEntry[]>;
|
|
371
|
+
/** Register / resolve an entity name to its canonical id + alias class as-of `at`. */
|
|
372
|
+
trackEntity(name: string, opts?: TrackEntityOptions): Promise<TrackEntityResponse>;
|
|
119
373
|
/**
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* Delete a memory
|
|
129
|
-
*/
|
|
130
|
-
deleteMemory(memoryId: string): Promise<void>;
|
|
131
|
-
/**
|
|
132
|
-
* List memories with pagination
|
|
374
|
+
* Report the outcome of a prior `recall` (by its `traceId`) so memory LEARNS — the
|
|
375
|
+
* outcome-feedback loop. A `"positive"` outcome reinforces the cited claims; `"negative"`
|
|
376
|
+
* down-weights them; either way the calibrated abstain gate's q̂ self-tunes. This is
|
|
377
|
+
* in-context learning at the memory layer — no model retraining.
|
|
378
|
+
*
|
|
379
|
+
* Check `.applied`: when FALSE the feedback was rejected (`.error` is `"unknown_trace"` or
|
|
380
|
+
* `"cross_tenant"`) and nothing was mutated. A cross-tenant attempt does NOT consume the
|
|
381
|
+
* owner's trace.
|
|
133
382
|
*/
|
|
134
|
-
|
|
135
|
-
limit?: number;
|
|
136
|
-
offset?: number;
|
|
137
|
-
userId?: string;
|
|
138
|
-
sessionId?: string;
|
|
139
|
-
tags?: string[];
|
|
140
|
-
tier?: string;
|
|
141
|
-
}): Promise<PaginatedResponse<MemorySummary>>;
|
|
383
|
+
feedback(traceId: number, outcome: Outcome, opts?: FeedbackOptions): Promise<FeedbackResponse>;
|
|
142
384
|
/**
|
|
143
|
-
*
|
|
385
|
+
* Run the idle-time episodic→semantic pass for this tenant: promote corroborated claims,
|
|
386
|
+
* collapse supersession chains into queryable transitions, and decay stale never-recalled
|
|
387
|
+
* claims. Retire-not-delete — as-of-T history is preserved. Returns the counts.
|
|
144
388
|
*/
|
|
145
|
-
|
|
389
|
+
consolidate(opts?: ConsolidateOptions): Promise<ConsolidateResponse>;
|
|
146
390
|
/**
|
|
147
|
-
*
|
|
391
|
+
* "Just add text": ingest free PROSE. A language model extracts (subject, predicate, object) facts,
|
|
392
|
+
* written as calibrated bitemporal claims — no hand-structuring. `subjectHint` is the default subject
|
|
393
|
+
* for a fact the text does not name. Check `.ok`: false ⇒ the text couldn't be read (`.error` says why).
|
|
148
394
|
*/
|
|
149
|
-
|
|
395
|
+
rememberText(text: string, subjectHint: string, opts?: RememberTextOptions): Promise<RememberTextResponse>;
|
|
150
396
|
/**
|
|
151
|
-
*
|
|
397
|
+
* Make an image part of memory: a vision model reads it into a caption + facts, written as claims —
|
|
398
|
+
* so the image is recallable by an ordinary TEXT query. `imageBase64` is the raw base64 (no data: prefix).
|
|
399
|
+
* Check `.ok`: false ⇒ the image couldn't be read (`.error`).
|
|
152
400
|
*/
|
|
153
|
-
|
|
154
|
-
maxTokens?: number;
|
|
155
|
-
userId?: string;
|
|
156
|
-
tags?: string[];
|
|
157
|
-
}): Promise<ContextResult>;
|
|
401
|
+
ingestImage(imageBase64: string, mime: string, subjectHint: string, opts?: IngestImageOptions): Promise<IngestImageResponse>;
|
|
158
402
|
/**
|
|
159
|
-
*
|
|
403
|
+
* Make an audio clip part of memory: it's transcribed, then the transcript is written as a claim AND
|
|
404
|
+
* run through the same text→facts extraction prose uses — so the audio is recallable by an ordinary
|
|
405
|
+
* TEXT query. `audioBase64` is the raw base64 (no data: prefix). Check `.ok`: false ⇒ couldn't read (`.error`).
|
|
160
406
|
*/
|
|
161
|
-
|
|
162
|
-
userId: string;
|
|
163
|
-
}): Promise<string>;
|
|
407
|
+
ingestAudio(audioBase64: string, mime: string, subjectHint: string, opts?: IngestAudioOptions): Promise<IngestAudioResponse>;
|
|
164
408
|
/**
|
|
165
|
-
*
|
|
409
|
+
* Make a PDF part of memory via the hybrid path: the text layer is extracted AND each page is rendered
|
|
410
|
+
* to an image read by a VLM, both written as claims — so a document (text-based or scanned) is
|
|
411
|
+
* recallable by an ordinary TEXT query. `pdfBase64` is the raw base64 (no data: prefix). Check `.ok`.
|
|
166
412
|
*/
|
|
167
|
-
|
|
168
|
-
limit?: number;
|
|
169
|
-
offset?: number;
|
|
170
|
-
}): Promise<MemorySummary[]>;
|
|
413
|
+
ingestPdf(pdfBase64: string, subjectHint: string, opts?: IngestPdfOptions): Promise<IngestPdfResponse>;
|
|
171
414
|
/**
|
|
172
|
-
*
|
|
415
|
+
* Ingest clean CSV or JSON DIRECTLY into claims — no LLM, no hallucination, no token cost. Each row is
|
|
416
|
+
* an entity, each column/key a predicate, each value an object. `format` is "csv" or "json";
|
|
417
|
+
* `subjectField` names the column/key that is the entity (omit ⇒ subjectHint + row index).
|
|
173
418
|
*/
|
|
174
|
-
|
|
419
|
+
ingestStructured(data: string, format: "csv" | "json", subjectHint: string, opts?: IngestStructuredOptions): Promise<IngestStructuredResponse>;
|
|
175
420
|
/**
|
|
176
|
-
*
|
|
421
|
+
* Primary universal save API: hand Cilow literally any data. Pass exactly one of
|
|
422
|
+
* `contentBase64` (any bytes) or `text` (prose / CSV / JSON / a bare URL) in `content`. The data is
|
|
423
|
+
* sniffed, the ORIGINAL retained durably (`raw_id`/`blob_id`), a document entity + metadata claims
|
|
424
|
+
* written (so even unknown bytes are findable), and the matching typed reader runs when one exists.
|
|
425
|
+
* Reader/provider failures are surfaced in-band as `status: "degraded"` + `reader_error`, not as a
|
|
426
|
+
* calibrated "memory does not know" read abstain.
|
|
177
427
|
*/
|
|
178
|
-
|
|
428
|
+
save(content: {
|
|
429
|
+
contentBase64: string;
|
|
430
|
+
} | {
|
|
431
|
+
text: string;
|
|
432
|
+
}, opts?: IngestAnyOptions): Promise<IngestAnyResponse>;
|
|
179
433
|
/**
|
|
180
|
-
*
|
|
434
|
+
* Legacy alias for `save`: the universal NEVER-REJECT ingest. Pass exactly one of
|
|
435
|
+
* `contentBase64` (any bytes) or `text` (prose / CSV / JSON / a bare URL) in `content`. The data is
|
|
436
|
+
* sniffed, the ORIGINAL retained durably (`blob_id`), a document entity + metadata claims written
|
|
437
|
+
* (so even unknown bytes are findable), and the matching typed reader runs when one exists (a URL
|
|
438
|
+
* is fetched + snapshotted; replay never re-fetches). `ok` is false only for malformed ARGUMENTS;
|
|
439
|
+
* unknown types and reader failures are `ok: true` with `routed` absent + `reader_error` set.
|
|
181
440
|
*/
|
|
182
|
-
|
|
441
|
+
ingestAny(content: {
|
|
442
|
+
contentBase64: string;
|
|
443
|
+
} | {
|
|
444
|
+
text: string;
|
|
445
|
+
}, opts?: IngestAnyOptions): Promise<IngestAnyResponse>;
|
|
183
446
|
/**
|
|
184
|
-
*
|
|
447
|
+
* Retire memory (retire-not-delete), or destroy it when `erase: true` (OF1).
|
|
448
|
+
*
|
|
449
|
+
* Retire: omit `attribute` to forget the whole entity, set it to forget one attribute, add
|
|
450
|
+
* `value` to forget one value. As-of-T history before `at` is preserved.
|
|
451
|
+
*
|
|
452
|
+
* Erase: whole-entity destruction; counters on the receipt. Not complete Art.17.
|
|
185
453
|
*/
|
|
186
|
-
|
|
454
|
+
forget(entity: string, opts?: ForgetOptions): Promise<ForgetResponse>;
|
|
455
|
+
/** Destructive right-to-be-forgotten path — `forget(entity, { erase: true })`. */
|
|
456
|
+
erase(entity: string, opts?: {
|
|
457
|
+
scope?: Scope;
|
|
458
|
+
at?: number;
|
|
459
|
+
}): Promise<ForgetResponse>;
|
|
187
460
|
/**
|
|
188
|
-
*
|
|
461
|
+
* Curated injectible pack + citations + trunk/suffix — no free-form synthesis (D2).
|
|
462
|
+
* When session trunk is on and `session != 0`, `trunk` is the stable multi-turn prefix.
|
|
189
463
|
*/
|
|
190
|
-
|
|
464
|
+
contextPack(query: string, opts?: ContextPackOptions): Promise<ContextPackResponse>;
|
|
191
465
|
/**
|
|
192
|
-
*
|
|
466
|
+
* The ONE write door (core verb #1): store `{ facts }` | `{ text }` | `{ url }` | `{ contentBase64 }`.
|
|
467
|
+
*
|
|
468
|
+
* - `facts` — `[{ subject, predicate, object, multi? }]`. Rides the `remember` path. A new value for
|
|
469
|
+
* an exclusive attribute SUPERSEDES the old one (history stays queryable via `contextPack({ asOf })`);
|
|
470
|
+
* `multi: true` on a fact lets values coexist. `source` / `rawContext` / `branch` apply here.
|
|
471
|
+
* - `text` (prose / CSV / JSON), `url` (a bare URL — sent as `text`; the server fetches + snapshots
|
|
472
|
+
* it), `contentBase64` (+ `mime` hint) — ride the never-reject `ingest_any` path: the original is
|
|
473
|
+
* retained durably (`content.blob_id`), a document entity + `metadata` claims are written, and the
|
|
474
|
+
* matching typed reader runs when one exists. `subjectHint` / `metadata` apply here.
|
|
475
|
+
*
|
|
476
|
+
* `sourceId` defaults to a CONTENT HASH (`ingestSourceId`) so a retry of the same payload is an
|
|
477
|
+
* idempotent no-op; the key actually sent is echoed on `source_id`. Never throws for content —
|
|
478
|
+
* only for a transport / auth failure.
|
|
193
479
|
*/
|
|
194
|
-
|
|
480
|
+
ingest(content: IngestContent, opts?: IngestOptions): Promise<IngestResponse>;
|
|
195
481
|
/**
|
|
196
|
-
*
|
|
482
|
+
* Why did a pack / recall surface what it surfaced? (core verb #4) Pass the `trace_id` from a
|
|
483
|
+
* `contextPack` / `recall` response. The report carries the cited claims (labels resolved, each with
|
|
484
|
+
* its inclusion probability), the read's `best_nonconformity` vs the tenant's grounding threshold
|
|
485
|
+
* `q_hat`, and whether the read was grounded (`isGrounded(r)`) or a gap. Read-only: explaining never
|
|
486
|
+
* consumes the feedback trace. `found: false` + `error` (`unknown_trace` / `cross_tenant`) is in-band.
|
|
197
487
|
*/
|
|
198
|
-
|
|
488
|
+
explain(traceId: number, opts?: {
|
|
489
|
+
scope?: Scope;
|
|
490
|
+
}): Promise<ExplainResponse>;
|
|
199
491
|
/**
|
|
200
|
-
*
|
|
492
|
+
* Read a retained original back by its hex `blob_id` (from an ingest receipt or `blobList`).
|
|
493
|
+
* Full sha256-verified read by default; pass `offset`/`length` for a chunk-indexed RANGE read
|
|
494
|
+
* of a large blob (EOF-clamped; `total_len` in the response lets you paginate; `byte_len` is
|
|
495
|
+
* the returned window). `found:false` with no `error` is an ordinary miss; `error` in
|
|
496
|
+
* {invalid_id, invalid_range, storage, corrupt} means the range read FAILED — never treat it
|
|
497
|
+
* as absence. Bytes ride back in `data_base64`.
|
|
201
498
|
*/
|
|
202
|
-
|
|
499
|
+
blobGet(blobId: string, opts?: {
|
|
500
|
+
offset?: number;
|
|
501
|
+
length?: number;
|
|
502
|
+
scope?: Scope;
|
|
503
|
+
}): Promise<BlobGetResponse>;
|
|
203
504
|
/**
|
|
204
|
-
*
|
|
505
|
+
* One retained blob's METADATA (mime, byte length, provenance, metadata pairs, chunk count) by
|
|
506
|
+
* hex `blob_id` — no bytes. `found:false` ⇒ this tenant retains no such blob.
|
|
205
507
|
*/
|
|
206
|
-
|
|
508
|
+
blobMeta(blobId: string, scope?: Scope): Promise<BlobMetaResponse>;
|
|
509
|
+
/** Enumerate this tenant's retained original blobs with metadata (no bytes), deterministically ordered. */
|
|
510
|
+
blobList(scope?: Scope): Promise<BlobListResponse>;
|
|
511
|
+
createContextWorkspace(name: string, scope?: Scope): Promise<WorkspaceResponse>;
|
|
512
|
+
ingestEvidence(input: {
|
|
513
|
+
workspaceId: string;
|
|
514
|
+
sourceId: string;
|
|
515
|
+
sourceRevision: string;
|
|
516
|
+
text: string;
|
|
517
|
+
mime?: string;
|
|
518
|
+
metadata?: Record<string, string>;
|
|
519
|
+
coordinates?: Array<Record<string, unknown>>;
|
|
520
|
+
trust?: "untrusted" | "user_provided" | "tool_observed" | "operator_verified";
|
|
521
|
+
aclPrincipals?: string[];
|
|
522
|
+
scope?: Scope;
|
|
523
|
+
}): Promise<EvidenceResponse>;
|
|
524
|
+
investigate(workspaceId: string, query: string, opts?: {
|
|
525
|
+
tokenBudget?: number;
|
|
526
|
+
scope?: Scope;
|
|
527
|
+
}): Promise<InvestigateResponse>;
|
|
528
|
+
compileContext(workspaceId: string, query: string, opts: {
|
|
529
|
+
modelId: string;
|
|
530
|
+
tokenizerId: string;
|
|
531
|
+
modelContextTokenBudget?: number;
|
|
532
|
+
auditPayloadByteBudget?: number;
|
|
533
|
+
promptTemplateId?: string;
|
|
534
|
+
asOf?: number;
|
|
535
|
+
scope?: Scope;
|
|
536
|
+
}): Promise<CompileContextResponse>;
|
|
537
|
+
getCompiledContext(receiptId: string, scope?: Scope): Promise<CompileContextResponse>;
|
|
538
|
+
getContextTrace(traceId: string, scope?: Scope): Promise<TraceResponse>;
|
|
539
|
+
recordAgentEpisode(workspaceId: string, summary: string, evidenceIds: string[], scope?: Scope): Promise<EpisodeResponse>;
|
|
540
|
+
proposeMemory(input: {
|
|
541
|
+
workspaceId: string;
|
|
542
|
+
episodeId: string;
|
|
543
|
+
subject: string;
|
|
544
|
+
predicate: string;
|
|
545
|
+
value: string;
|
|
546
|
+
evidenceIds: string[];
|
|
547
|
+
scope?: Scope;
|
|
548
|
+
}): Promise<MemoryResponse>;
|
|
549
|
+
verifyMemory(proposalId: string, accept: boolean, reason: string, scope?: Scope): Promise<MemoryResponse>;
|
|
550
|
+
private mergeScope;
|
|
207
551
|
/**
|
|
208
|
-
*
|
|
552
|
+
* Issue one JSON-RPC `tools/call` and return the engine's `structuredContent`.
|
|
553
|
+
* Maps every failure mode (transport, HTTP, JSON-RPC error, malformed body) to a CilowError.
|
|
209
554
|
*/
|
|
210
|
-
|
|
211
|
-
content: string;
|
|
212
|
-
options?: CreateMemoryOptions;
|
|
213
|
-
}>): Promise<string[]>;
|
|
555
|
+
private call;
|
|
214
556
|
/**
|
|
215
|
-
*
|
|
557
|
+
* POST to `/v1/memories/<verb>` and return the parsed JSON body (plain REST, not JSON-RPC). With
|
|
558
|
+
* `allow404`, a 404 resolves to `null` (used by `memories.get`). Other 4xx/5xx throw a CilowError
|
|
559
|
+
* carrying the body's `error` string.
|
|
216
560
|
*/
|
|
217
|
-
|
|
561
|
+
private callRest;
|
|
218
562
|
}
|
|
219
|
-
|
|
220
|
-
* Create a Cilow client instance (convenience function)
|
|
221
|
-
*/
|
|
222
|
-
declare function createClient(config: CilowConfig): CilowClient;
|
|
223
|
-
|
|
224
|
-
export { CilowApiError, CilowClient, createClient };
|
|
563
|
+
//# sourceMappingURL=client.d.ts.map
|