@flowtasks/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.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Flow SDK for JavaScript / TypeScript
2
+
3
+ Official client for the [Flow Intelligence Engine](https://flowtasks.io) API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flowtasks/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { FlowClient } from "@flowtasks/sdk";
15
+
16
+ const client = new FlowClient({
17
+ baseUrl: "https://flowtasks.io",
18
+ apiKey: "YOUR_API_KEY",
19
+ organizationId: "YOUR_ORG_ID",
20
+ });
21
+
22
+ // Chat with your documents
23
+ const answer = await client.chat("What are the termination conditions?");
24
+ console.log(answer);
25
+
26
+ // Search the knowledge graph
27
+ const results = await client.searchGraph("termination clause");
28
+ console.log(results);
29
+
30
+ // Ask the knowledge graph (LLM-powered)
31
+ const response = await client.askGraph("Which contracts allow termination without cause?");
32
+ console.log(response.answer);
33
+
34
+ // Legal analysis
35
+ const clauses = await client.legalQuery("indemnity clauses", { mode: "deterministic" });
36
+ console.log(clauses);
37
+ ```
38
+
39
+ ## Available Methods
40
+
41
+ ### Documents
42
+ - `listDocuments()` -- List all documents
43
+ - `getDocument(id)` -- Get document metadata
44
+ - `deleteDocument(id)` -- Delete a document
45
+
46
+ ### Chat / RAG
47
+ - `chat(message, options?)` -- AI-powered query with source citations
48
+
49
+ ### Knowledge Graph
50
+ - `searchGraph(query)` -- Search entities and relationships
51
+ - `getGraphStats()` -- Node and edge counts
52
+ - `askGraph(question)` -- Natural-language graph query (LLM)
53
+ - `reasonGraph(question, options?)` -- Intent-aware reasoning
54
+ - `getGraphVisualization(limit?)` -- Full graph data for rendering
55
+ - `getEntityNeighbors(name, depth?)` -- Explore entity connections
56
+
57
+ ### Legal Analysis
58
+ - `legalClauseTypes()` -- Available clause types
59
+ - `legalClauses(docId)` -- Extract clauses from a document
60
+ - `legalDiff(docA, docB)` -- Compare clauses between documents
61
+ - `legalQuery(query, options?)` -- Query across all clauses
62
+
63
+ ### Ontology
64
+ - `listDomains()` -- Built-in domain ontologies
65
+ - `createOntology(params)` -- Create custom ontology
66
+ - `listCustomOntologies()` -- List custom ontologies
67
+ - `getResolvedOntology(domain)` -- Merged core + custom ontology
68
+
69
+ ### Agent
70
+ - `agentRun(params?)` -- Trigger an agent run
71
+ - `listAgentRuns()` -- Past agent runs
72
+ - `listRiskSignals()` -- Detected risk signals
73
+
74
+ ### Workflows
75
+ - `listWorkflows()` / `createWorkflow(params)` / `runWorkflow(id)`
76
+
77
+ ### Compliance
78
+ - `listComplianceChecks()` / `runComplianceScan(params?)`
79
+
80
+ ### Webhooks
81
+ - `listWebhooks()` / `createWebhook(params)`
82
+
83
+ ### Usage
84
+ - `getUsage()` -- Current usage and quota
85
+
86
+ ## Error Handling
87
+
88
+ ```typescript
89
+ import { FlowClient, FlowAPIError } from "@flowtasks/sdk";
90
+
91
+ try {
92
+ const result = await client.chat("Summarize the agreement");
93
+ } catch (err) {
94
+ if (err instanceof FlowAPIError) {
95
+ console.error(`API error ${err.statusCode}: ${err.detail}`);
96
+ }
97
+ }
98
+ ```
99
+
100
+ ## Links
101
+
102
+ - [Interactive API Docs](https://flowtasks.io/docs)
103
+ - [OpenAPI Schema](https://flowtasks.io/openapi.json)
104
+
105
+ ## License
106
+
107
+ MIT
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Flow SDK — JavaScript/TypeScript client for the Flowtasks Intelligence Engine API.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { FlowClient } from "@flowtasks/sdk";
7
+ *
8
+ * const client = new FlowClient({
9
+ * baseUrl: "https://api.flowtasks.io",
10
+ * apiKey: "your-api-key",
11
+ * organizationId: "org-123",
12
+ * });
13
+ *
14
+ * const answer = await client.chat("What are the key contract terms?");
15
+ * const clauses = await client.legalQuery("termination clauses", { mode: "deterministic" });
16
+ * ```
17
+ */
18
+ export interface FlowClientConfig {
19
+ baseUrl: string;
20
+ apiKey: string;
21
+ organizationId?: string;
22
+ timeout?: number;
23
+ }
24
+ export declare class FlowAPIError extends Error {
25
+ statusCode: number;
26
+ detail: string;
27
+ constructor(statusCode: number, detail: string);
28
+ }
29
+ export declare class FlowClient {
30
+ private baseUrl;
31
+ private apiKey;
32
+ private organizationId?;
33
+ private timeout;
34
+ constructor(config: FlowClientConfig);
35
+ private request;
36
+ health(): Promise<any>;
37
+ listDocuments(params?: {
38
+ skip?: number;
39
+ limit?: number;
40
+ organizationId?: string;
41
+ }): Promise<any>;
42
+ getDocument(documentId: string): Promise<any>;
43
+ deleteDocument(documentId: string): Promise<void>;
44
+ chat(message: string, options?: {
45
+ sessionId?: string;
46
+ organizationId?: string;
47
+ useMultiAgent?: boolean;
48
+ }): Promise<any>;
49
+ searchGraph(query: string, organizationId?: string): Promise<any>;
50
+ getGraphStats(organizationId?: string): Promise<any>;
51
+ askGraph(question: string): Promise<any>;
52
+ reasonGraph(question: string, options?: {
53
+ category?: string;
54
+ }): Promise<any>;
55
+ getGraphVisualization(limit?: number): Promise<any>;
56
+ getEntityNeighbors(entityName: string, depth?: number): Promise<any>;
57
+ agentRun(params?: {
58
+ query?: string;
59
+ triggerType?: string;
60
+ context?: Record<string, any>;
61
+ }): Promise<any>;
62
+ listAgentRuns(skip?: number, limit?: number): Promise<any>;
63
+ listRiskSignals(skip?: number, limit?: number): Promise<any>;
64
+ listDomains(): Promise<any>;
65
+ getDomain(domain: string): Promise<any>;
66
+ createOntology(params: {
67
+ name: string;
68
+ description?: string;
69
+ entityTypes?: string[];
70
+ relationshipTypes?: string[];
71
+ relationRules?: Array<{
72
+ relationship_type: string;
73
+ allowed_source_types: string[];
74
+ allowed_target_types: string[];
75
+ symmetric?: boolean;
76
+ }>;
77
+ }): Promise<any>;
78
+ listCustomOntologies(): Promise<any>;
79
+ getCustomOntology(ontologyId: string): Promise<any>;
80
+ updateOntology(ontologyId: string, fields: Record<string, any>): Promise<any>;
81
+ deleteOntology(ontologyId: string): Promise<void>;
82
+ getResolvedOntology(domain: string): Promise<any>;
83
+ legalClauseTypes(): Promise<any>;
84
+ legalClauses(documentId: string): Promise<any>;
85
+ legalDiff(docA: string, docB: string): Promise<any>;
86
+ legalQuery(query: string, options?: {
87
+ mode?: "auto" | "deterministic" | "hybrid";
88
+ clauseTypes?: string[];
89
+ conditionFilters?: Record<string, string>;
90
+ hasObligations?: boolean;
91
+ }): Promise<any>;
92
+ listWorkflows(): Promise<any>;
93
+ createWorkflow(params: {
94
+ name: string;
95
+ description?: string;
96
+ steps: Array<Record<string, any>>;
97
+ isActive?: boolean;
98
+ }): Promise<any>;
99
+ runWorkflow(workflowId: string, inputData?: Record<string, any>): Promise<any>;
100
+ listComplianceChecks(): Promise<any>;
101
+ runComplianceScan(params?: {
102
+ documentId?: string;
103
+ framework?: string;
104
+ }): Promise<any>;
105
+ listWebhooks(): Promise<any>;
106
+ createWebhook(params: {
107
+ url: string;
108
+ events: string[];
109
+ name?: string;
110
+ }): Promise<any>;
111
+ getUsage(organizationId?: string): Promise<any>;
112
+ }
package/dist/client.js ADDED
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ /**
3
+ * Flow SDK — JavaScript/TypeScript client for the Flowtasks Intelligence Engine API.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { FlowClient } from "@flowtasks/sdk";
8
+ *
9
+ * const client = new FlowClient({
10
+ * baseUrl: "https://api.flowtasks.io",
11
+ * apiKey: "your-api-key",
12
+ * organizationId: "org-123",
13
+ * });
14
+ *
15
+ * const answer = await client.chat("What are the key contract terms?");
16
+ * const clauses = await client.legalQuery("termination clauses", { mode: "deterministic" });
17
+ * ```
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.FlowClient = exports.FlowAPIError = void 0;
21
+ class FlowAPIError extends Error {
22
+ constructor(statusCode, detail) {
23
+ super(`HTTP ${statusCode}: ${detail}`);
24
+ this.statusCode = statusCode;
25
+ this.detail = detail;
26
+ this.name = "FlowAPIError";
27
+ }
28
+ }
29
+ exports.FlowAPIError = FlowAPIError;
30
+ class FlowClient {
31
+ constructor(config) {
32
+ this.baseUrl = config.baseUrl.replace(/\/+$/, "") + "/api/v1";
33
+ this.apiKey = config.apiKey;
34
+ this.organizationId = config.organizationId;
35
+ this.timeout = config.timeout ?? 60000;
36
+ }
37
+ async request(method, path, options) {
38
+ let url = `${this.baseUrl}${path}`;
39
+ if (options?.params) {
40
+ const qs = new URLSearchParams();
41
+ for (const [k, v] of Object.entries(options.params)) {
42
+ if (v !== undefined && v !== null)
43
+ qs.set(k, String(v));
44
+ }
45
+ const qsStr = qs.toString();
46
+ if (qsStr)
47
+ url += `?${qsStr}`;
48
+ }
49
+ const controller = new AbortController();
50
+ const timer = setTimeout(() => controller.abort(), this.timeout);
51
+ const headers = {
52
+ "X-API-Key": this.apiKey,
53
+ "Content-Type": "application/json",
54
+ };
55
+ if (this.organizationId) {
56
+ headers["X-Organization-ID"] = this.organizationId;
57
+ }
58
+ try {
59
+ const resp = await fetch(url, {
60
+ method,
61
+ headers,
62
+ body: options?.body ? JSON.stringify(options.body) : undefined,
63
+ signal: controller.signal,
64
+ });
65
+ if (!resp.ok) {
66
+ let detail;
67
+ try {
68
+ const json = await resp.json();
69
+ detail = json.detail ?? resp.statusText;
70
+ }
71
+ catch {
72
+ detail = resp.statusText;
73
+ }
74
+ throw new FlowAPIError(resp.status, detail);
75
+ }
76
+ if (resp.status === 204)
77
+ return undefined;
78
+ return (await resp.json());
79
+ }
80
+ finally {
81
+ clearTimeout(timer);
82
+ }
83
+ }
84
+ // ── Health ──────────────────────────────────────────────────────────
85
+ async health() {
86
+ return this.request("GET", "/health");
87
+ }
88
+ // ── Documents ──────────────────────────────────────────────────────
89
+ async listDocuments(params) {
90
+ return this.request("GET", "/documents", {
91
+ params: {
92
+ skip: params?.skip ?? 0,
93
+ limit: params?.limit ?? 50,
94
+ ...(params?.organizationId && { organization_id: params.organizationId }),
95
+ },
96
+ });
97
+ }
98
+ async getDocument(documentId) {
99
+ return this.request("GET", `/documents/${documentId}`);
100
+ }
101
+ async deleteDocument(documentId) {
102
+ await this.request("DELETE", `/documents/${documentId}`);
103
+ }
104
+ // ── Chat / RAG ─────────────────────────────────────────────────────
105
+ async chat(message, options) {
106
+ return this.request("POST", "/chat", {
107
+ body: {
108
+ message,
109
+ ...(options?.sessionId && { session_id: options.sessionId }),
110
+ ...(options?.organizationId && { organization_id: options.organizationId }),
111
+ ...(options?.useMultiAgent && { use_multi_agent: true }),
112
+ },
113
+ });
114
+ }
115
+ // ── Knowledge Graph ────────────────────────────────────────────────
116
+ async searchGraph(query, organizationId) {
117
+ return this.request("GET", "/knowledge-graph/search", {
118
+ params: { q: query, ...(organizationId && { organization_id: organizationId }) },
119
+ });
120
+ }
121
+ async getGraphStats(organizationId) {
122
+ return this.request("GET", "/knowledge-graph/stats", {
123
+ params: organizationId ? { organization_id: organizationId } : {},
124
+ });
125
+ }
126
+ async askGraph(question) {
127
+ return this.request("POST", "/knowledge-graph/ask", {
128
+ body: { question },
129
+ });
130
+ }
131
+ async reasonGraph(question, options) {
132
+ return this.request("POST", "/knowledge-graph/reason", {
133
+ body: { question, ...(options?.category && { category: options.category }) },
134
+ });
135
+ }
136
+ async getGraphVisualization(limit = 500) {
137
+ return this.request("GET", "/knowledge-graph/visualization", {
138
+ params: { limit },
139
+ });
140
+ }
141
+ async getEntityNeighbors(entityName, depth = 1) {
142
+ return this.request("GET", `/knowledge-graph/neighbors/${encodeURIComponent(entityName)}`, {
143
+ params: { depth },
144
+ });
145
+ }
146
+ // ── Agent ──────────────────────────────────────────────────────────
147
+ async agentRun(params) {
148
+ return this.request("POST", "/agent/run", {
149
+ body: {
150
+ trigger_type: params?.triggerType ?? "manual",
151
+ ...(params?.query && { query: params.query }),
152
+ ...(params?.context && { context: params.context }),
153
+ },
154
+ });
155
+ }
156
+ async listAgentRuns(skip = 0, limit = 50) {
157
+ return this.request("GET", "/agent/runs", { params: { skip, limit } });
158
+ }
159
+ async listRiskSignals(skip = 0, limit = 50) {
160
+ return this.request("GET", "/agent/risk-signals", { params: { skip, limit } });
161
+ }
162
+ // ── Ontology ───────────────────────────────────────────────────────
163
+ async listDomains() {
164
+ return this.request("GET", "/ontology/domains");
165
+ }
166
+ async getDomain(domain) {
167
+ return this.request("GET", `/ontology/domains/${domain}`);
168
+ }
169
+ async createOntology(params) {
170
+ return this.request("POST", "/ontology/custom", {
171
+ body: {
172
+ name: params.name,
173
+ description: params.description ?? "",
174
+ entity_types: (params.entityTypes ?? []).map((name) => ({ name })),
175
+ relationship_types: params.relationshipTypes ?? [],
176
+ relation_rules: params.relationRules ?? [],
177
+ },
178
+ });
179
+ }
180
+ async listCustomOntologies() {
181
+ return this.request("GET", "/ontology/custom");
182
+ }
183
+ async getCustomOntology(ontologyId) {
184
+ return this.request("GET", `/ontology/custom/${ontologyId}`);
185
+ }
186
+ async updateOntology(ontologyId, fields) {
187
+ return this.request("PUT", `/ontology/custom/${ontologyId}`, { body: fields });
188
+ }
189
+ async deleteOntology(ontologyId) {
190
+ await this.request("DELETE", `/ontology/custom/${ontologyId}`);
191
+ }
192
+ async getResolvedOntology(domain) {
193
+ return this.request("GET", `/ontology/resolved/${domain}`);
194
+ }
195
+ // ── Legal Analysis ─────────────────────────────────────────────────
196
+ async legalClauseTypes() {
197
+ return this.request("GET", "/legal/clause-types");
198
+ }
199
+ async legalClauses(documentId) {
200
+ return this.request("GET", `/legal/clauses/${documentId}`);
201
+ }
202
+ async legalDiff(docA, docB) {
203
+ return this.request("GET", "/legal/diff", { params: { doc_a: docA, doc_b: docB } });
204
+ }
205
+ async legalQuery(query, options) {
206
+ return this.request("POST", "/legal/query", {
207
+ body: {
208
+ query,
209
+ mode: options?.mode ?? "auto",
210
+ ...(options?.clauseTypes && { clause_types: options.clauseTypes }),
211
+ ...(options?.conditionFilters && { condition_filters: options.conditionFilters }),
212
+ ...(options?.hasObligations !== undefined && { has_obligations: options.hasObligations }),
213
+ },
214
+ });
215
+ }
216
+ // ── Workflows ──────────────────────────────────────────────────────
217
+ async listWorkflows() {
218
+ return this.request("GET", "/workflows");
219
+ }
220
+ async createWorkflow(params) {
221
+ return this.request("POST", "/workflows", {
222
+ body: {
223
+ name: params.name,
224
+ description: params.description ?? "",
225
+ steps_json: params.steps,
226
+ is_active: params.isActive ?? true,
227
+ },
228
+ });
229
+ }
230
+ async runWorkflow(workflowId, inputData) {
231
+ return this.request("POST", `/workflows/${workflowId}/run`, {
232
+ body: inputData ? { input_data: inputData } : {},
233
+ });
234
+ }
235
+ // ── Compliance ─────────────────────────────────────────────────────
236
+ async listComplianceChecks() {
237
+ return this.request("GET", "/compliance/checks");
238
+ }
239
+ async runComplianceScan(params) {
240
+ return this.request("POST", "/compliance/scan", {
241
+ body: {
242
+ framework: params?.framework ?? "general",
243
+ ...(params?.documentId && { document_id: params.documentId }),
244
+ },
245
+ });
246
+ }
247
+ // ── Webhooks ───────────────────────────────────────────────────────
248
+ async listWebhooks() {
249
+ return this.request("GET", "/webhooks");
250
+ }
251
+ async createWebhook(params) {
252
+ return this.request("POST", "/webhooks", {
253
+ body: { url: params.url, events: params.events, name: params.name ?? "" },
254
+ });
255
+ }
256
+ // ── Usage ──────────────────────────────────────────────────────────
257
+ async getUsage(organizationId) {
258
+ return this.request("GET", "/usage", {
259
+ params: organizationId ? { organization_id: organizationId } : {},
260
+ });
261
+ }
262
+ }
263
+ exports.FlowClient = FlowClient;
@@ -0,0 +1,2 @@
1
+ export { FlowClient, FlowClientConfig } from "./client";
2
+ export { FlowAPIError } from "./client";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowAPIError = exports.FlowClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "FlowClient", { enumerable: true, get: function () { return client_1.FlowClient; } });
6
+ var client_2 = require("./client");
7
+ Object.defineProperty(exports, "FlowAPIError", { enumerable: true, get: function () { return client_2.FlowAPIError; } });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@flowtasks/sdk",
3
+ "version": "0.2.0",
4
+ "description": "JavaScript/TypeScript SDK for the Flowtasks Intelligence Engine API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "dependencies": {},
15
+ "devDependencies": {
16
+ "typescript": "^5.4.0"
17
+ },
18
+ "author": "Flow Tasks <dev@flowtasks.io>",
19
+ "license": "MIT",
20
+ "homepage": "https://flowtasks.io",
21
+ "keywords": ["rag", "ai", "knowledge-graph", "legal", "compliance", "api", "flowtasks"]
22
+ }