@infolang/sdk 0.2.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.
@@ -0,0 +1,353 @@
1
+ /**
2
+ * Authentication providers for the InfoLang SDK.
3
+ *
4
+ * A provider returns the headers to attach to each request. `headers()` is
5
+ * called before every request so providers can refresh short-lived tokens.
6
+ */
7
+ declare const DEFAULT_SESSION_PATH: string;
8
+ interface AuthProvider {
9
+ headers(): Promise<Record<string, string>>;
10
+ }
11
+ /** Bearer authentication with an InfoLang API key (`il_live_...`). */
12
+ declare class ApiKeyAuth implements AuthProvider {
13
+ private readonly apiKey;
14
+ constructor(apiKey: string);
15
+ headers(): Promise<Record<string, string>>;
16
+ }
17
+ /** Self-hosted dev key in `key:namespace` form (matches INFOLANG_API_KEYS). */
18
+ declare class DevKeyAuth implements AuthProvider {
19
+ readonly namespace: string;
20
+ private readonly token;
21
+ constructor(devKey: string);
22
+ headers(): Promise<Record<string, string>>;
23
+ }
24
+ /**
25
+ * OAuth bearer token read from the cursor-setup session file (default
26
+ * `~/.config/infolang/session.json`, written by `npx @infolang/cursor-setup`).
27
+ * Refreshes transparently when the file carries a `refresh_token` + `token_url`.
28
+ */
29
+ declare class SessionFileAuth implements AuthProvider {
30
+ private readonly path;
31
+ private cache?;
32
+ constructor(path?: string);
33
+ private load;
34
+ headers(): Promise<Record<string, string>>;
35
+ private isExpired;
36
+ private refresh;
37
+ }
38
+ /** Worker-to-origin shared secret. For internal integrators only. */
39
+ declare class OriginAuth implements AuthProvider {
40
+ private readonly workspace;
41
+ private readonly secret;
42
+ constructor(workspace: string, secret: string);
43
+ headers(): Promise<Record<string, string>>;
44
+ }
45
+
46
+ /**
47
+ * Request and response types mirroring the il-runtime REST contract
48
+ * (`openapi/il-runtime.yaml`). The runtime emits compact keys (`i`, `s`, `t`,
49
+ * `g`); the SDK normalizes them into readable fields.
50
+ */
51
+ /** A single recalled memory chunk (normalized from the compact wire shape). */
52
+ interface Chunk {
53
+ /** Memory id (wire: `i`). */
54
+ id: string;
55
+ /** Similarity score (wire: `s`). */
56
+ score?: number;
57
+ /** Chunk text (wire: `t`). */
58
+ text: string;
59
+ /** Tags (wire: `g`). */
60
+ tags?: string;
61
+ }
62
+ /** Usage metadata parsed from managed-cloud response headers. */
63
+ interface MeteringMeta {
64
+ tokensSaved?: number;
65
+ chunksUsed?: number;
66
+ repoCoverage?: number;
67
+ requestId?: string;
68
+ }
69
+ /** Result of a `recall` / `investigate` call. */
70
+ interface RecallResult {
71
+ chunks: Chunk[];
72
+ namespace?: string;
73
+ metering?: MeteringMeta;
74
+ /** True when the top match scores below the 0.85 confidence floor. */
75
+ weak: boolean;
76
+ }
77
+ /** Result of a `remember` / `memorize` call. */
78
+ interface RememberResult {
79
+ memoryId?: string;
80
+ namespace?: string;
81
+ }
82
+ /** Result of a `contextPack` call: a token-budgeted context string. */
83
+ interface ContextPack {
84
+ pack: string;
85
+ tokensEstimated?: number;
86
+ namespace?: string;
87
+ metering?: MeteringMeta;
88
+ }
89
+ /** A memory bank descriptor. */
90
+ interface Bank {
91
+ namespace: string;
92
+ count?: number;
93
+ }
94
+ interface RecallOptions {
95
+ namespace?: string;
96
+ topK?: number;
97
+ filters?: Record<string, unknown>;
98
+ verbose?: boolean;
99
+ }
100
+ interface InvestigateOptions {
101
+ namespaceHint?: string;
102
+ topK?: number;
103
+ }
104
+ interface RememberOptions {
105
+ namespace?: string;
106
+ source?: string;
107
+ tags?: string;
108
+ }
109
+ interface ContextPackOptions {
110
+ namespace?: string;
111
+ maxTokens?: number;
112
+ repoRoot?: string;
113
+ }
114
+ interface ListRecentOptions {
115
+ namespace?: string;
116
+ n?: number;
117
+ }
118
+
119
+ /**
120
+ * fetch-native HTTP transport.
121
+ *
122
+ * Works on Node 18+, Bun, Deno, Cloudflare Workers and browsers without
123
+ * polyfills. Adds the resilience defaults expected of a modern SDK: targeted
124
+ * retries (429 + 5xx) with exponential backoff and full jitter, an explicit
125
+ * timeout budget via AbortController, and typed error mapping.
126
+ */
127
+
128
+ type FetchLike = typeof fetch;
129
+ interface TransportOptions {
130
+ baseUrl: string;
131
+ auth: AuthProvider;
132
+ fetch?: FetchLike;
133
+ timeoutMs?: number;
134
+ maxRetries?: number;
135
+ backoffBaseMs?: number;
136
+ backoffCapMs?: number;
137
+ userAgent: string;
138
+ /** When set, sent as X-InfoLang-Workspace-Id on every request. */
139
+ workspaceId?: string;
140
+ }
141
+ interface RequestOptions {
142
+ method: string;
143
+ path: string;
144
+ body?: unknown;
145
+ headers?: Record<string, string>;
146
+ }
147
+ interface TransportResult<T> {
148
+ data: T;
149
+ metering: MeteringMeta;
150
+ }
151
+ declare class Transport {
152
+ private readonly baseUrl;
153
+ private readonly auth;
154
+ private readonly fetchImpl;
155
+ private readonly timeoutMs;
156
+ private readonly maxRetries;
157
+ private readonly backoffBaseMs;
158
+ private readonly backoffCapMs;
159
+ private readonly userAgent;
160
+ private readonly workspaceId?;
161
+ constructor(options: TransportOptions);
162
+ private delay;
163
+ request<T>(options: RequestOptions): Promise<TransportResult<T>>;
164
+ private finish;
165
+ }
166
+
167
+ /** Context resource: context-pack, repo ingest, and batch execute. */
168
+
169
+ declare class ContextResource {
170
+ private readonly transport;
171
+ private readonly defaultNamespace?;
172
+ constructor(transport: Transport, defaultNamespace?: string | undefined);
173
+ contextPack(query: string, options?: ContextPackOptions): Promise<ContextPack>;
174
+ ingestRepo(namespace: string, options: {
175
+ repoRoot: string;
176
+ ref?: string;
177
+ }): Promise<Record<string, unknown>>;
178
+ execute(operations: Record<string, unknown>[]): Promise<Record<string, unknown>>;
179
+ }
180
+
181
+ /** Health resource: liveness/readiness checks against the runtime. */
182
+
183
+ declare class HealthResource {
184
+ private readonly transport;
185
+ constructor(transport: Transport);
186
+ check(): Promise<Record<string, unknown>>;
187
+ }
188
+
189
+ /** Memory resource: recall, remember, forget, and agent-friendly aliases. */
190
+
191
+ declare class MemoryResource {
192
+ private readonly transport;
193
+ private readonly defaultNamespace?;
194
+ constructor(transport: Transport, defaultNamespace?: string | undefined);
195
+ recall(query: string, options?: RecallOptions): Promise<RecallResult>;
196
+ /** Agent-style recall with a sensible default `topK` of 5. */
197
+ investigate(query: string, options?: InvestigateOptions): Promise<RecallResult>;
198
+ remember(text: string, options?: RememberOptions): Promise<RememberResult>;
199
+ /** Alias for `remember` matching the `auto_memorize` tool. */
200
+ memorize(content: string, options?: RememberOptions): Promise<RememberResult>;
201
+ forget(memoryId: string, options?: {
202
+ namespace?: string;
203
+ }): Promise<void>;
204
+ listBanks(): Promise<Bank[]>;
205
+ listRecent(options?: ListRecentOptions): Promise<unknown[]>;
206
+ /** Recall with tag-inclusion ordering over a candidate pool (client-side). */
207
+ recallHybrid(query: string, options?: {
208
+ namespace?: string;
209
+ topK?: number;
210
+ tagFilter?: string[];
211
+ candidatePool?: number;
212
+ useHybrid?: boolean;
213
+ }): Promise<RecallResult>;
214
+ /** Store many memories via POST /v1/execute remember_batch. */
215
+ rememberBatch(items: Array<string | {
216
+ text: string;
217
+ tags?: string | string[];
218
+ source?: string;
219
+ }>, options?: {
220
+ namespace?: string;
221
+ source?: string;
222
+ }): Promise<RememberResult[]>;
223
+ /** Best-effort bulk clear (list + forget loop). */
224
+ resetNamespace(namespace?: string, options?: {
225
+ batch?: number;
226
+ }): Promise<number>;
227
+ }
228
+
229
+ /**
230
+ * The InfoLang client: one-line construction over the il-runtime REST API.
231
+ *
232
+ * Exposes grouped resources (`client.memory`, `client.context`,
233
+ * `client.health`) plus the common operations as top-level aliases so the
234
+ * first call is a one-liner.
235
+ */
236
+
237
+ declare const CLOUD_BASE_URL = "https://api.infolang.ai";
238
+ declare const DIRECT_BASE_URL = "http://127.0.0.1:8766";
239
+ interface InfoLangOptions {
240
+ /** Managed-cloud API key (`il_live_...`). Defaults to the cloud base URL. */
241
+ apiKey?: string;
242
+ /** Self-hosted dev key in `key:namespace` form. Defaults to the direct base URL. */
243
+ devKey?: string;
244
+ /** An explicit auth provider (e.g. `new SessionFileAuth()`). */
245
+ auth?: AuthProvider;
246
+ baseUrl?: string;
247
+ namespace?: string;
248
+ /**
249
+ * Account workspace to target. Sent as `X-InfoLang-Workspace-Id`.
250
+ * Must be in the API key's allowlist (or a membership for JWT auth).
251
+ * Also reads `INFOLANG_WORKSPACE` / `INFOLANG_WORKSPACE_ID`.
252
+ */
253
+ workspace?: string;
254
+ timeoutMs?: number;
255
+ maxRetries?: number;
256
+ /** Custom fetch (for Workers, mocks, or a TLS-configured agent). */
257
+ fetch?: FetchLike;
258
+ }
259
+ declare class InfoLang {
260
+ readonly namespace?: string;
261
+ readonly workspace?: string;
262
+ readonly baseUrl: string;
263
+ readonly memory: MemoryResource;
264
+ readonly context: ContextResource;
265
+ readonly health: HealthResource;
266
+ constructor(options?: InfoLangOptions);
267
+ static fromApiKey(apiKey: string, options?: Omit<InfoLangOptions, "apiKey">): InfoLang;
268
+ static fromDevKey(devKey: string, options?: Omit<InfoLangOptions, "devKey">): InfoLang;
269
+ static fromSessionFile(path?: string, options?: Omit<InfoLangOptions, "auth">): InfoLang;
270
+ recall(query: string, options?: RecallOptions): Promise<RecallResult>;
271
+ investigate(query: string, options?: InvestigateOptions): Promise<RecallResult>;
272
+ remember(text: string, options?: RememberOptions): Promise<RememberResult>;
273
+ memorize(content: string, options?: RememberOptions): Promise<RememberResult>;
274
+ forget(memoryId: string, options?: {
275
+ namespace?: string;
276
+ }): Promise<void>;
277
+ listBanks(): Promise<Bank[]>;
278
+ listRecent(options?: ListRecentOptions): Promise<unknown[]>;
279
+ recallHybrid(query: string, options?: {
280
+ namespace?: string;
281
+ topK?: number;
282
+ tagFilter?: string[];
283
+ candidatePool?: number;
284
+ useHybrid?: boolean;
285
+ }): Promise<RecallResult>;
286
+ rememberBatch(items: Array<string | {
287
+ text: string;
288
+ tags?: string | string[];
289
+ source?: string;
290
+ }>, options?: {
291
+ namespace?: string;
292
+ source?: string;
293
+ }): Promise<RememberResult[]>;
294
+ resetNamespace(namespace?: string, options?: {
295
+ batch?: number;
296
+ }): Promise<number>;
297
+ contextPack(query: string, options?: ContextPackOptions): Promise<ContextPack>;
298
+ ingestRepo(namespace: string, options: {
299
+ repoRoot: string;
300
+ ref?: string;
301
+ }): Promise<Record<string, unknown>>;
302
+ execute(operations: Record<string, unknown>[]): Promise<Record<string, unknown>>;
303
+ }
304
+
305
+ /**
306
+ * Typed error hierarchy for the InfoLang SDK.
307
+ *
308
+ * Catch these instead of inspecting raw responses. Every API error carries the
309
+ * originating `requestId` (from the `x-request-id` header) when available.
310
+ */
311
+ declare class InfoLangError extends Error {
312
+ constructor(message: string);
313
+ }
314
+ /** Client misconfiguration (missing credentials, bad base URL). */
315
+ declare class InfoLangConfigError extends InfoLangError {
316
+ }
317
+ /** The runtime could not be reached, or the request timed out. */
318
+ declare class InfoLangConnectionError extends InfoLangError {
319
+ }
320
+ interface APIErrorOptions {
321
+ status: number;
322
+ body?: unknown;
323
+ requestId?: string;
324
+ retryAfter?: number;
325
+ }
326
+ /** A non-2xx response from the runtime. */
327
+ declare class InfoLangAPIError extends InfoLangError {
328
+ readonly status: number;
329
+ readonly body: unknown;
330
+ readonly requestId?: string;
331
+ constructor(message: string, options: APIErrorOptions);
332
+ }
333
+ /** 401/403 — credential missing, invalid, or lacking permission. */
334
+ declare class AuthenticationError extends InfoLangAPIError {
335
+ }
336
+ /** 404 — namespace, bank, or memory id does not exist. */
337
+ declare class NotFoundError extends InfoLangAPIError {
338
+ }
339
+ /** 400/422 — the request payload was rejected. */
340
+ declare class ValidationError extends InfoLangAPIError {
341
+ }
342
+ /** 429 — quota exceeded. `retryAfter` is seconds when the server sets it. */
343
+ declare class RateLimitError extends InfoLangAPIError {
344
+ readonly retryAfter?: number;
345
+ constructor(message: string, options: APIErrorOptions);
346
+ }
347
+ /** 5xx — the runtime failed to process the request. */
348
+ declare class ServerError extends InfoLangAPIError {
349
+ }
350
+
351
+ declare const version = "0.2.0";
352
+
353
+ export { ApiKeyAuth, type AuthProvider, AuthenticationError, type Bank, CLOUD_BASE_URL, type Chunk, type ContextPack, type ContextPackOptions, DEFAULT_SESSION_PATH, DIRECT_BASE_URL, DevKeyAuth, InfoLang, InfoLangAPIError, InfoLangConfigError, InfoLangConnectionError, InfoLangError, type InfoLangOptions, type InvestigateOptions, type ListRecentOptions, type MeteringMeta, NotFoundError, OriginAuth, RateLimitError, type RecallOptions, type RecallResult, type RememberOptions, type RememberResult, ServerError, SessionFileAuth, ValidationError, version };