contiss-ai 1.0.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 (3) hide show
  1. package/index.d.ts +208 -0
  2. package/index.js +255 -0
  3. package/package.json +13 -0
package/index.d.ts ADDED
@@ -0,0 +1,208 @@
1
+ export type MemoryType = "fact" | "decision" | "plan" | "summary" | "note";
2
+ export type SearchMode = "semantic" | "fulltext" | "hybrid";
3
+ export type AgentStatus = "active" | "idle" | "offline";
4
+ export type Namespace = "shared" | "private";
5
+
6
+ export interface ContissOptions {
7
+ apiKey?: string;
8
+ baseUrl?: string;
9
+ }
10
+
11
+ export interface MemoryWriteParams {
12
+ orgId: string;
13
+ projectId: string;
14
+ content: string;
15
+ type?: MemoryType;
16
+ title?: string;
17
+ tags?: string[];
18
+ sources?: string[];
19
+ confidence?: number;
20
+ requiresReview?: boolean;
21
+ supersedesId?: string;
22
+ agentId?: string;
23
+ namespace?: Namespace;
24
+ }
25
+
26
+ export interface MemoryWriteResult {
27
+ id: string;
28
+ root_id: string;
29
+ version: number;
30
+ is_current: boolean;
31
+ requires_review: boolean;
32
+ type: string;
33
+ consolidated: boolean;
34
+ duplicates_found: boolean;
35
+ }
36
+
37
+ export interface MemorySearchParams {
38
+ orgId: string;
39
+ projectId: string;
40
+ query: string;
41
+ limit?: number;
42
+ types?: MemoryType[];
43
+ tags?: string[];
44
+ searchMode?: SearchMode;
45
+ agentId?: string;
46
+ namespace?: Namespace;
47
+ }
48
+
49
+ export interface MemorySearchResult {
50
+ items: any[];
51
+ total: number;
52
+ query: string;
53
+ search_mode: string;
54
+ }
55
+
56
+ export interface MemoryBundleParams {
57
+ orgId: string;
58
+ projectId: string;
59
+ task: string;
60
+ maxItems?: number;
61
+ maxChars?: number;
62
+ types?: string[];
63
+ tags?: string[];
64
+ }
65
+
66
+ export interface MemoryBundleResult {
67
+ bundle_version: string;
68
+ project_id: string;
69
+ generated_at: string;
70
+ high_confidence_facts: any[];
71
+ relevant_decisions: any[];
72
+ active_plans: any[];
73
+ recent_summaries: any[];
74
+ warnings: string[];
75
+ }
76
+
77
+ export interface MemoryBatchItem {
78
+ orgId: string;
79
+ projectId: string;
80
+ content: string;
81
+ type?: MemoryType;
82
+ title?: string;
83
+ tags?: string[];
84
+ sources?: string[];
85
+ confidence?: number;
86
+ requiresReview?: boolean;
87
+ supersedesId?: string;
88
+ agentId?: string;
89
+ namespace?: Namespace;
90
+ }
91
+
92
+ export interface MemoryBatchResult {
93
+ results: MemoryWriteResult[];
94
+ }
95
+
96
+ export interface ProjectCreateParams {
97
+ name: string;
98
+ description?: string;
99
+ }
100
+
101
+ export interface Project {
102
+ id: string;
103
+ name: string;
104
+ description: string | null;
105
+ created_at: string;
106
+ updated_at: string;
107
+ stats?: { memories: number; agents: number; documents: number };
108
+ }
109
+
110
+ export interface ProjectResponse {
111
+ project: Project;
112
+ }
113
+
114
+ export interface ProjectListResponse {
115
+ projects: Project[];
116
+ }
117
+
118
+ export interface ProjectUpdateParams {
119
+ name?: string;
120
+ description?: string;
121
+ }
122
+
123
+ export interface AgentRegisterParams {
124
+ projectId: string;
125
+ agentId: string;
126
+ name: string;
127
+ role?: string;
128
+ capabilities?: string[];
129
+ metadata?: Record<string, any>;
130
+ }
131
+
132
+ export interface Agent {
133
+ id: string;
134
+ project_id: string;
135
+ agent_id: string;
136
+ name: string;
137
+ role?: string;
138
+ capabilities: string[];
139
+ metadata: Record<string, any>;
140
+ status: string;
141
+ last_active_at?: string;
142
+ created_at: string;
143
+ updated_at: string;
144
+ }
145
+
146
+ export interface AgentRegisterResponse {
147
+ agent: Agent;
148
+ message: string;
149
+ }
150
+
151
+ export interface AgentListResponse {
152
+ agents: Agent[];
153
+ }
154
+
155
+ export interface AgentGetResponse {
156
+ agent: Agent;
157
+ }
158
+
159
+ export interface AgentStatsResponse {
160
+ memory_count: number;
161
+ [key: string]: any;
162
+ }
163
+
164
+ export interface HealthResponse {
165
+ ok: boolean;
166
+ [key: string]: any;
167
+ }
168
+
169
+ export class ContissAPIError extends Error {
170
+ readonly error: string;
171
+ readonly statusCode: number;
172
+ constructor(statusCode: number, error: string, message: string);
173
+ }
174
+
175
+ declare class MemoryResource {
176
+ write(params: MemoryWriteParams): Promise<MemoryWriteResult>;
177
+ search(params: MemorySearchParams): Promise<MemorySearchResult>;
178
+ bundle(params: MemoryBundleParams): Promise<MemoryBundleResult>;
179
+ writeBatch(memories: MemoryBatchItem[]): Promise<MemoryBatchResult>;
180
+ }
181
+
182
+ declare class ProjectsResource {
183
+ list(): Promise<ProjectListResponse>;
184
+ create(params: ProjectCreateParams): Promise<ProjectResponse>;
185
+ get(projectId: string): Promise<ProjectResponse>;
186
+ update(projectId: string, params: ProjectUpdateParams): Promise<ProjectResponse>;
187
+ delete(projectId: string): Promise<void>;
188
+ }
189
+
190
+ declare class AgentsResource {
191
+ register(params: AgentRegisterParams): Promise<AgentRegisterResponse>;
192
+ list(projectId: string): Promise<AgentListResponse>;
193
+ get(projectId: string, agentId: string): Promise<AgentGetResponse>;
194
+ updateStatus(projectId: string, agentId: string, status: AgentStatus): Promise<void>;
195
+ touch(projectId: string, agentId: string): Promise<void>;
196
+ stats(projectId: string, agentId: string): Promise<AgentStatsResponse>;
197
+ delete(projectId: string, agentId: string): Promise<void>;
198
+ }
199
+
200
+ export class Contiss {
201
+ readonly memory: MemoryResource;
202
+ readonly projects: ProjectsResource;
203
+ readonly agents: AgentsResource;
204
+ constructor(opts?: ContissOptions);
205
+ health(): Promise<HealthResponse>;
206
+ }
207
+
208
+ export default Contiss;
package/index.js ADDED
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Contiss AI SDK — Persistent memory for AI agents.
5
+ *
6
+ * Works with both CommonJS (require) and ESM (import).
7
+ * Zero dependencies — uses native fetch (Node 18+).
8
+ *
9
+ * @example
10
+ * const { Contiss } = require('contiss');
11
+ * const client = new Contiss({ apiKey: 'sk_live_...' });
12
+ *
13
+ * await client.memory.write({
14
+ * orgId: '...', projectId: '...',
15
+ * content: 'User prefers dark mode',
16
+ * type: 'fact',
17
+ * });
18
+ */
19
+
20
+ const DEFAULT_URL =
21
+ "https://main-backend-963363632208.europe-west1.run.app";
22
+
23
+ // ── Error ──
24
+
25
+ class ContissAPIError extends Error {
26
+ constructor(statusCode, error, message) {
27
+ super(`${error}: ${message}`);
28
+ this.name = "ContissAPIError";
29
+ this.error = error;
30
+ this.statusCode = statusCode;
31
+ }
32
+ }
33
+
34
+ // ── HTTP client ──
35
+
36
+ class HttpClient {
37
+ constructor(baseUrl, apiKey) {
38
+ this.baseUrl = baseUrl.replace(/\/+$/, "");
39
+ this.apiKey = apiKey;
40
+ }
41
+
42
+ async request(method, path, body) {
43
+ const url = `${this.baseUrl}${path}`;
44
+ const headers = {
45
+ "X-API-Key": this.apiKey,
46
+ "Content-Type": "application/json",
47
+ };
48
+
49
+ const res = await fetch(url, {
50
+ method,
51
+ headers,
52
+ body: body ? JSON.stringify(body) : undefined,
53
+ });
54
+
55
+ if (res.status === 204) return undefined;
56
+
57
+ const data = await res.json();
58
+
59
+ if (!res.ok) {
60
+ throw new ContissAPIError(
61
+ res.status,
62
+ data.error || "api_error",
63
+ data.message || res.statusText,
64
+ );
65
+ }
66
+
67
+ return data;
68
+ }
69
+ }
70
+
71
+ // ── Helpers ──
72
+
73
+ function buildWriteBody(p) {
74
+ const body = {
75
+ org_id: p.orgId,
76
+ project_id: p.projectId,
77
+ content: p.content,
78
+ type: p.type || "note",
79
+ confidence: p.confidence ?? 0.6,
80
+ requires_review: p.requiresReview ?? false,
81
+ namespace: p.namespace || "shared",
82
+ };
83
+ if (p.title) body.title = p.title;
84
+ if (p.tags) body.tags = p.tags;
85
+ if (p.sources) body.sources = p.sources;
86
+ if (p.supersedesId) body.supersedes_id = p.supersedesId;
87
+ if (p.agentId) body.agent_id = p.agentId;
88
+ return body;
89
+ }
90
+
91
+ // ── Resources ──
92
+
93
+ class MemoryResource {
94
+ constructor(http) {
95
+ this._http = http;
96
+ }
97
+
98
+ async write(params) {
99
+ return this._http.request("POST", "/memory/write", buildWriteBody(params));
100
+ }
101
+
102
+ async search(params) {
103
+ const body = {
104
+ org_id: params.orgId,
105
+ project_id: params.projectId,
106
+ query: params.query,
107
+ limit: params.limit ?? 20,
108
+ searchMode: params.searchMode || "hybrid",
109
+ };
110
+ if (params.types) body.types = params.types;
111
+ if (params.tags) body.tags = params.tags;
112
+ if (params.agentId) body.agent_id = params.agentId;
113
+ if (params.namespace) body.namespace = params.namespace;
114
+ return this._http.request("POST", "/memory/search", body);
115
+ }
116
+
117
+ async bundle(params) {
118
+ return this._http.request("POST", "/memory/bundle", {
119
+ org_id: params.orgId,
120
+ project_id: params.projectId,
121
+ task: params.task,
122
+ limits: {
123
+ max_items: params.maxItems ?? 12,
124
+ max_chars: params.maxChars ?? 6000,
125
+ },
126
+ filters: {
127
+ types: params.types || ["fact", "decision", "plan", "summary"],
128
+ tags: params.tags || [],
129
+ },
130
+ });
131
+ }
132
+
133
+ async writeBatch(memories) {
134
+ return this._http.request("POST", "/memory/batch", {
135
+ memories: memories.map(buildWriteBody),
136
+ });
137
+ }
138
+ }
139
+
140
+ class ProjectsResource {
141
+ constructor(http) {
142
+ this._http = http;
143
+ }
144
+
145
+ async list() {
146
+ return this._http.request("GET", "/projects/");
147
+ }
148
+
149
+ async create(params) {
150
+ return this._http.request("POST", "/projects/", params);
151
+ }
152
+
153
+ async get(projectId) {
154
+ return this._http.request("GET", `/projects/${projectId}/`);
155
+ }
156
+
157
+ async update(projectId, params) {
158
+ return this._http.request("PUT", `/projects/${projectId}/`, params);
159
+ }
160
+
161
+ async delete(projectId) {
162
+ return this._http.request("DELETE", `/projects/${projectId}/`);
163
+ }
164
+ }
165
+
166
+ class AgentsResource {
167
+ constructor(http) {
168
+ this._http = http;
169
+ }
170
+
171
+ async register(params) {
172
+ return this._http.request("POST", "/agents/register", {
173
+ project_id: params.projectId,
174
+ agent_id: params.agentId,
175
+ name: params.name,
176
+ role: params.role,
177
+ capabilities: params.capabilities,
178
+ metadata: params.metadata,
179
+ });
180
+ }
181
+
182
+ async list(projectId) {
183
+ return this._http.request("POST", "/agents/list", {
184
+ project_id: projectId,
185
+ });
186
+ }
187
+
188
+ async get(projectId, agentId) {
189
+ const data = await this._http.request(
190
+ "GET",
191
+ `/agents/${projectId}/${agentId}`,
192
+ );
193
+ if (data && data.agent_id) return { agent: data };
194
+ return data;
195
+ }
196
+
197
+ async updateStatus(projectId, agentId, status) {
198
+ return this._http.request(
199
+ "PUT",
200
+ `/agents/${projectId}/${agentId}/status`,
201
+ { status },
202
+ );
203
+ }
204
+
205
+ async touch(projectId, agentId) {
206
+ return this._http.request(
207
+ "POST",
208
+ `/agents/${projectId}/${agentId}/touch`,
209
+ );
210
+ }
211
+
212
+ async stats(projectId, agentId) {
213
+ return this._http.request(
214
+ "GET",
215
+ `/agents/${projectId}/${agentId}/stats`,
216
+ );
217
+ }
218
+
219
+ async delete(projectId, agentId) {
220
+ return this._http.request(
221
+ "DELETE",
222
+ `/agents/${projectId}/${agentId}`,
223
+ );
224
+ }
225
+ }
226
+
227
+ // ── Main client ──
228
+
229
+ class Contiss {
230
+ constructor(opts = {}) {
231
+ const apiKey = opts.apiKey || process.env.CONTISS_API_KEY;
232
+ if (!apiKey) {
233
+ throw new Error(
234
+ "API key required. Pass apiKey or set CONTISS_API_KEY env var. " +
235
+ "Create one at https://contiss.ai/dashboard/keys",
236
+ );
237
+ }
238
+
239
+ const baseUrl = opts.baseUrl || process.env.CONTISS_BASE_URL || DEFAULT_URL;
240
+ this._http = new HttpClient(baseUrl, apiKey);
241
+
242
+ this.memory = new MemoryResource(this._http);
243
+ this.projects = new ProjectsResource(this._http);
244
+ this.agents = new AgentsResource(this._http);
245
+ }
246
+
247
+ async health() {
248
+ return this._http.request("GET", "/health");
249
+ }
250
+ }
251
+
252
+ // ── Exports ──
253
+
254
+ module.exports = { Contiss, ContissAPIError };
255
+ module.exports.default = Contiss;
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "contiss-ai",
3
+ "version": "1.0.0",
4
+ "description": "Contiss AI SDK — Persistent memory for AI agents",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": ["index.js", "index.d.ts"],
8
+ "keywords": ["contiss", "ai", "memory", "agents", "sdk"],
9
+ "license": "MIT",
10
+ "engines": {
11
+ "node": ">=18.0.0"
12
+ }
13
+ }