conare 0.7.3 → 0.8.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.
Files changed (4) hide show
  1. package/README.md +182 -0
  2. package/dist/index.d.ts +186 -0
  3. package/dist/index.js +283 -6693
  4. package/package.json +21 -28
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # conare
2
+
3
+ TypeScript client for [Conare](https://conare.ai): add documents, query them, connect apps.
4
+ No dependencies. Works on Node 18+, Bun, Deno and edge runtimes.
5
+
6
+ ## Quickstart
7
+
8
+ ```bash
9
+ npm install conare
10
+ export CONARE_API_KEY=sk-conare-... # conare.ai/console/keys
11
+ ```
12
+
13
+ ```ts
14
+ import { Conare } from "conare";
15
+
16
+ const conare = new Conare();
17
+ const docs = conare.namespace("docs");
18
+
19
+ await docs.add({ id: "refunds", text: "Refunds are available for 30 days.", metadata: { team: "support" } });
20
+
21
+ const results = await docs.query("how do refunds work?", { topK: 5 });
22
+ // [{ id: "refunds", text: "Refunds are available for 30 days.", score: 0.91, metadata: { team: "support" } }]
23
+ ```
24
+
25
+ A namespace is created by its first write. Writing the same id again replaces the document.
26
+
27
+ ## Reference
28
+
29
+ ### Client
30
+
31
+ ```ts
32
+ new Conare() // CONARE_API_KEY from the environment
33
+ new Conare({ apiKey, baseURL, timeout: 60_000, maxRetries: 2 })
34
+ ```
35
+
36
+ Every method also takes `{ signal, timeout }` as its last option.
37
+
38
+ ### Namespaces and documents
39
+
40
+ ```ts
41
+ const docs = conare.namespace("docs");
42
+
43
+ await docs.add({ id, text, metadata }); // one document
44
+ await docs.add([...]); // or many; sent 100 at a time. Returns the ids.
45
+ await docs.get("refunds"); // { id, text, metadata, updatedAt } or null
46
+ for await (const doc of docs.list()) {} // every document, page by page ({ limit } per page: 1-100, default 50)
47
+ await docs.delete("refunds"); // 404 document_not_found if it does not exist
48
+ await docs.drop(); // delete the namespace and its documents (404 namespace_not_found if empty)
49
+
50
+ await conare.namespaces(); // [{ name, documents }]
51
+ ```
52
+
53
+ Namespace names: 1-64 characters of `a-z 0-9 _ -`. Ids: up to 256 characters of
54
+ `A-Z a-z 0-9 . _ : -`. Metadata values are strings, numbers, booleans or arrays of strings.
55
+
56
+ ### Query
57
+
58
+ ```ts
59
+ await docs.query("how do refunds work?", {
60
+ topK: 10, // 1-100, default 10
61
+ filter: { team: "support" }, // optional metadata filter
62
+ rerank: true, // default true
63
+ });
64
+ ```
65
+
66
+ Hybrid search (vector and keyword), reranked. One result per document: its best passage.
67
+
68
+ Filters: `{ key: value }` means equals. Operators: `$eq $ne $gt $gte $lt $lte $in $nin`.
69
+ Combine with `$and` and `$or`:
70
+
71
+ ```ts
72
+ { $or: [{ team: "support" }, { year: { $gte: 2024 } }] }
73
+ { $and: [{ lang: { $in: ["en", "de"] } }, { draft: { $ne: true } }] }
74
+ ```
75
+
76
+ ### Embed and rerank
77
+
78
+ ```ts
79
+ await conare.embed(["some text"], { type: "query" }); // number[][]; type defaults to "document"
80
+ await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }]
81
+ ```
82
+
83
+ ### Sources
84
+
85
+ Connect an app such as HubSpot or Gmail. It keeps syncing into one namespace, and each record
86
+ becomes a document. `sources.types()` lists the apps you can connect.
87
+
88
+ ```ts
89
+ const { source, connectUrl } = await conare.sources.connect({
90
+ type: "hubspot",
91
+ namespace: "crm",
92
+ redirectUrl: "https://yourapp.com/settings",
93
+ });
94
+ // Send the app owner to connectUrl. They sign in and come back to redirectUrl.
95
+
96
+ await conare.sources.types(); // [{ type, name, logoUrl }]
97
+ await conare.sources.list(); // [Source]
98
+ await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
99
+ await conare.sources.sync(source.id); // sync now
100
+ await conare.sources.delete(source.id, { deleteDocuments: true });
101
+ ```
102
+
103
+ `status` is `connecting`, `syncing`, `ready` or `error`.
104
+
105
+ ### Errors
106
+
107
+ Every failure is a `ConareError` with `status`, `code`, `message` and `requestId`
108
+ (`status` is 0 when no response arrived: `timeout`, `connection_error`). 429, 5xx and network
109
+ errors are retried twice with backoff, honouring `Retry-After`. `sources.connect()` is retried only
110
+ on 429 and 503, and `add()` gives every document without an id one of its own first, so a retry
111
+ never creates anything twice.
112
+
113
+ ```ts
114
+ import { ConareError } from "conare";
115
+
116
+ try {
117
+ await docs.add({ text: "" });
118
+ } catch (err) {
119
+ if (err instanceof ConareError) console.log(err.status, err.code, err.requestId);
120
+ }
121
+ ```
122
+
123
+ ## One namespace per user
124
+
125
+ To give each user of your app their own searchable data, use one namespace per user and connect
126
+ their apps into it:
127
+
128
+ ```ts
129
+ const user = conare.namespace(`user-${userId}`);
130
+ await user.add({ id: "note-1", text: "Prefers email over phone." });
131
+
132
+ const { connectUrl } = await conare.sources.connect({
133
+ type: "gmail",
134
+ namespace: `user-${userId}`,
135
+ redirectUrl: "https://yourapp.com/settings/connections",
136
+ });
137
+ // Redirect the user to connectUrl. Their mail syncs into their namespace only.
138
+
139
+ const context = await user.query("how should we contact them?");
140
+ ```
141
+
142
+ Keep the API key on your server. It can read and write every namespace in your organization.
143
+
144
+ ## MCP
145
+
146
+ Conare is also an MCP server at `https://api.conare.ai/mcp`, with tools to search, fetch, save
147
+ and delete documents and list namespaces.
148
+
149
+ Claude Code:
150
+
151
+ ```bash
152
+ claude mcp add --transport http conare https://api.conare.ai/mcp \
153
+ --header "Authorization: Bearer $CONARE_API_KEY"
154
+ ```
155
+
156
+ Cursor (`~/.cursor/mcp.json`):
157
+
158
+ ```json
159
+ {
160
+ "mcpServers": {
161
+ "conare": {
162
+ "url": "https://api.conare.ai/mcp",
163
+ "headers": { "Authorization": "Bearer sk-conare-..." }
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ ## Development
170
+
171
+ ```bash
172
+ bun install
173
+ bun run build
174
+ bun test # local fake API
175
+ CONARE_API_KEY=sk-conare-... bun test # also runs test/live.test.ts against the real API
176
+ ```
177
+
178
+ Releases: push a tag `sdk-v<version>` matching `package.json`; CI tests and publishes to npm.
179
+
180
+ ## Versions
181
+
182
+ 0.8.0 is the first release of this client. Versions of `conare` before it (0.7.x and older) were the retired memory CLI.
@@ -0,0 +1,186 @@
1
+ export declare const VERSION = "0.8.0";
2
+ /** A metadata value: string, number, boolean or an array of strings. */
3
+ export type MetadataValue = string | number | boolean | string[];
4
+ export type Metadata = Record<string, MetadataValue>;
5
+ type Scalar = string | number | boolean;
6
+ /** Comparison operators for one metadata key. */
7
+ export interface FilterOperators {
8
+ $eq?: Scalar;
9
+ $ne?: Scalar;
10
+ $gt?: number | string;
11
+ $gte?: number | string;
12
+ $lt?: number | string;
13
+ $lte?: number | string;
14
+ $in?: Scalar[];
15
+ $nin?: Scalar[];
16
+ }
17
+ /**
18
+ * A metadata filter. `{ team: "support" }` means equals; use operators for the rest
19
+ * and `$and` / `$or` to combine: `{ $or: [{ team: "support" }, { year: { $gte: 2024 } }] }`.
20
+ */
21
+ export interface Filter {
22
+ $and?: Filter[];
23
+ $or?: Filter[];
24
+ [key: string]: Scalar | FilterOperators | Filter[] | undefined;
25
+ }
26
+ export interface DocumentInput {
27
+ /** 1-256 characters of [A-Za-z0-9._:-]. Omit to let Conare generate one. Same id replaces. */
28
+ id?: string;
29
+ text: string;
30
+ metadata?: Metadata;
31
+ }
32
+ export interface Document {
33
+ id: string;
34
+ text: string;
35
+ metadata: Metadata;
36
+ updatedAt: Date;
37
+ }
38
+ export interface DocumentSummary {
39
+ id: string;
40
+ metadata: Metadata;
41
+ updatedAt: Date;
42
+ }
43
+ export interface QueryResult {
44
+ id: string;
45
+ /** The best matching passage of the document. */
46
+ text: string;
47
+ score: number;
48
+ metadata: Metadata;
49
+ }
50
+ export interface NamespaceInfo {
51
+ name: string;
52
+ documents: number;
53
+ }
54
+ export interface RerankResult {
55
+ index: number;
56
+ score: number;
57
+ document: string;
58
+ }
59
+ export type SourceStatus = "connecting" | "syncing" | "ready" | "error";
60
+ export interface Source {
61
+ id: string;
62
+ type: string;
63
+ name: string;
64
+ namespace: string;
65
+ status: SourceStatus;
66
+ error: string | null;
67
+ documents: number;
68
+ lastSyncedAt: Date | null;
69
+ createdAt: Date;
70
+ }
71
+ export interface SourceType {
72
+ type: string;
73
+ name: string;
74
+ logoUrl: string;
75
+ }
76
+ export interface ConareOptions {
77
+ /** Defaults to the CONARE_API_KEY environment variable. */
78
+ apiKey?: string;
79
+ /** Defaults to CONARE_BASE_URL, then https://api.conare.ai. */
80
+ baseURL?: string;
81
+ /** Per-request timeout in milliseconds. Default 60000. */
82
+ timeout?: number;
83
+ /** Retries on 429, 5xx and network errors (a request that could create something twice only on 429 and 503). Default 2. */
84
+ maxRetries?: number;
85
+ /** Custom fetch, e.g. for proxies or tests. */
86
+ fetch?: (url: string, init: RequestInit) => Promise<Response>;
87
+ }
88
+ export interface RequestOptions {
89
+ signal?: AbortSignal;
90
+ /** Overrides the client timeout for this call, in milliseconds. */
91
+ timeout?: number;
92
+ }
93
+ /** Every failure the SDK throws. `status` is 0 when no response arrived. */
94
+ export declare class ConareError extends Error {
95
+ readonly status: number;
96
+ readonly code: string;
97
+ readonly requestId: string | null;
98
+ constructor(status: number, code: string, message: string, requestId?: string | null);
99
+ }
100
+ /**
101
+ * The Conare client.
102
+ *
103
+ * const conare = new Conare() // reads CONARE_API_KEY
104
+ * const docs = conare.namespace("docs")
105
+ */
106
+ export declare class Conare {
107
+ readonly baseURL: string;
108
+ readonly sources: Sources;
109
+ private readonly apiKey;
110
+ private readonly timeout;
111
+ private readonly maxRetries;
112
+ private readonly fetchFn;
113
+ constructor(options?: ConareOptions);
114
+ /** A handle to one namespace. Nothing is sent until you call a method; the first write creates it. */
115
+ namespace(name: string): Namespace;
116
+ /** Every namespace in the organization with its document count. */
117
+ namespaces(options?: RequestOptions): Promise<NamespaceInfo[]>;
118
+ /** Embed texts. Use type "query" for search queries and "document" (default) for stored text. */
119
+ embed(input: string | string[], options?: RequestOptions & {
120
+ type?: "document" | "query";
121
+ }): Promise<number[][]>;
122
+ /** Rerank documents against a query, best first. */
123
+ rerank(query: string, documents: string[], options?: RequestOptions & {
124
+ topK?: number;
125
+ }): Promise<RerankResult[]>;
126
+ private send;
127
+ }
128
+ /** One namespace: a named set of documents, e.g. "docs" or "user-42". */
129
+ export declare class Namespace {
130
+ private readonly client;
131
+ readonly name: string;
132
+ constructor(client: Conare, name: string);
133
+ private path;
134
+ /**
135
+ * Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
136
+ * A document without an id gets one here, so a retried batch replaces instead of duplicating.
137
+ */
138
+ add(documents: DocumentInput | DocumentInput[], options?: RequestOptions): Promise<string[]>;
139
+ /** Hybrid search, reranked. One result per document: its best passage. */
140
+ query(query: string, options?: RequestOptions & {
141
+ topK?: number;
142
+ filter?: Filter;
143
+ rerank?: boolean;
144
+ }): Promise<QueryResult[]>;
145
+ /** One document by id, or null if it does not exist. */
146
+ get(id: string, options?: RequestOptions): Promise<Document | null>;
147
+ /** Every document (id, metadata, updatedAt), fetched page by page as you iterate. `limit` is the page size: 1-100, default 50. */
148
+ list(options?: RequestOptions & {
149
+ limit?: number;
150
+ }): AsyncGenerator<DocumentSummary>;
151
+ /** Delete one document. Throws a ConareError with status 404 (`document_not_found`) if it does not exist. */
152
+ delete(id: string, options?: RequestOptions): Promise<void>;
153
+ /** Delete the namespace and every document in it. Throws 404 (`namespace_not_found`) if it holds no documents. */
154
+ drop(options?: RequestOptions): Promise<void>;
155
+ }
156
+ /** Apps connected through Conare that keep syncing into a namespace. */
157
+ export declare class Sources {
158
+ private readonly client;
159
+ constructor(client: Conare);
160
+ /**
161
+ * Start connecting an app. Send the app owner to `connectUrl`; they come back to `redirectUrl`.
162
+ * For your own users, connect each one into their own namespace, e.g. "user-42".
163
+ */
164
+ connect(params: {
165
+ type: string;
166
+ namespace: string;
167
+ name?: string;
168
+ redirectUrl?: string;
169
+ }, options?: RequestOptions): Promise<{
170
+ source: Source;
171
+ connectUrl: string;
172
+ }>;
173
+ /** Every connected source. */
174
+ list(options?: RequestOptions): Promise<Source[]>;
175
+ /** One source by id. */
176
+ get(id: string, options?: RequestOptions): Promise<Source>;
177
+ /** Start a sync now. */
178
+ sync(id: string, options?: RequestOptions): Promise<Source>;
179
+ /** Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced. */
180
+ delete(id: string, options?: RequestOptions & {
181
+ deleteDocuments?: boolean;
182
+ }): Promise<void>;
183
+ /** The apps you can connect. */
184
+ types(options?: RequestOptions): Promise<SourceType[]>;
185
+ }
186
+ export {};