@eng-ai/sdk 2.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/README.md +32 -0
  2. package/package.json +33 -0
  3. package/src/client.js +46 -0
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @eng-ai/sdk
2
+
3
+ Official JavaScript SDK for ENG-AI External API v2.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @eng-ai/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { EngAIClient } from "@eng-ai/sdk";
15
+
16
+ const client = new EngAIClient(process.env.ENG_AI_API_KEY, "https://your-domain/api/v2");
17
+
18
+ const response = await client.invokeAgent("general", {
19
+ message: "Explique o conceito de talude",
20
+ normativeMode: true,
21
+ normId: "auto"
22
+ });
23
+
24
+ console.log(response.result.content);
25
+ console.log(response.normative?.citations ?? []);
26
+ ```
27
+
28
+ ## Security Notes
29
+
30
+ - Use your ENG-AI API key only in trusted server environments.
31
+ - Do not ship secrets in frontend bundles.
32
+ - Keep idempotency enabled for mutation-heavy integrations.
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@eng-ai/sdk",
3
+ "version": "2.0.0",
4
+ "description": "Official JavaScript SDK for ENG-AI External API v2",
5
+ "type": "module",
6
+ "main": "./src/client.js",
7
+ "exports": {
8
+ ".": "./src/client.js"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "check:pack": "NPM_CONFIG_CACHE=${NPM_CONFIG_CACHE:-/tmp/engai-npm-cache} npm pack --dry-run"
16
+ },
17
+ "keywords": [
18
+ "eng-ai",
19
+ "sdk",
20
+ "mcp",
21
+ "agent",
22
+ "ai"
23
+ ],
24
+ "author": "ENG-AI",
25
+ "license": "UNLICENSED",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "sideEffects": false,
30
+ "engines": {
31
+ "node": ">=18"
32
+ }
33
+ }
package/src/client.js ADDED
@@ -0,0 +1,46 @@
1
+ export class EngAIClient {
2
+ constructor(apiKey, baseUrl = "http://localhost:8000/api/v2") {
3
+ this.apiKey = apiKey;
4
+ this.baseUrl = baseUrl;
5
+ this.headers = {
6
+ "X-API-Key": this.apiKey,
7
+ "Content-Type": "application/json",
8
+ };
9
+ }
10
+
11
+ async invokeAgent(agentId, payload) {
12
+ const body =
13
+ typeof payload === "string"
14
+ ? { message: payload }
15
+ : {
16
+ message: payload?.message,
17
+ project_id: payload?.projectId ?? payload?.project_id,
18
+ session_id: payload?.sessionId ?? payload?.session_id,
19
+ context_digest: payload?.contextDigest ?? payload?.context_digest,
20
+ normative_mode:
21
+ (payload?.normativeMode ?? payload?.normative_mode) ||
22
+ (payload?.normId ?? payload?.norm_id)
23
+ ? true
24
+ : undefined,
25
+ norm_id: payload?.normId ?? payload?.norm_id,
26
+ };
27
+
28
+ const headers = { ...this.headers };
29
+ const idempotencyKey = payload?.idempotencyKey ?? payload?.idempotency_key;
30
+ if (idempotencyKey) {
31
+ headers["Idempotency-Key"] = idempotencyKey;
32
+ }
33
+
34
+ const response = await fetch(`${this.baseUrl}/sdk/agents/${agentId}/invoke`, {
35
+ method: "POST",
36
+ headers,
37
+ body: JSON.stringify(body),
38
+ });
39
+
40
+ if (!response.ok) {
41
+ throw new Error(`Error: ${response.statusText}`);
42
+ }
43
+
44
+ return await response.json();
45
+ }
46
+ }