@aglit-ai/sdk 0.1.9

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,101 @@
1
+ const fs = require('fs');
2
+ const os = require('os');
3
+ const path = require('path');
4
+ // Shared example utilities for @aglit-ai/sdk
5
+ const { executeTool, createChat } = require('..');
6
+
7
+ const baseUrl =
8
+ process.env.AGLIT_DESKTOP_BASE_URL ??
9
+ `http://localhost:${process.env.SERVER_PORT ?? process.env.PORT ?? '49117'}`;
10
+
11
+ const agentId = process.env.AGLIT_AGENT_ID ?? 'root-agent';
12
+
13
+ function makeSessionId(name) {
14
+ return `sdk-example-${name}-${Date.now().toString(36)}`;
15
+ }
16
+
17
+ async function enableAutoApproveTools(sessionId, agent = agentId, base = baseUrl) {
18
+ // Best effort: write session-config on disk so the server picks up agent mode immediately
19
+ const userDataRoots = [];
20
+ if (process.env.AGLIT_USER_DATA_PATH) {
21
+ const override = process.env.AGLIT_USER_DATA_PATH;
22
+ userDataRoots.push(
23
+ override.startsWith('~/') || override.startsWith('~')
24
+ ? path.join(os.homedir(), override.replace(/^~\//, '').replace(/^~/, ''))
25
+ : override
26
+ );
27
+ }
28
+ // Use platform-standard paths (matches Electron's app.getPath('userData'))
29
+ if (process.platform === 'darwin') {
30
+ userDataRoots.push(path.join(os.homedir(), 'Library', 'Application Support', 'Aglit AI (Dev)'));
31
+ userDataRoots.push(path.join(os.homedir(), 'Library', 'Application Support', 'Aglit AI'));
32
+ } else if (process.platform === 'win32') {
33
+ const appData = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
34
+ userDataRoots.push(path.join(appData, 'Aglit AI (Dev)'));
35
+ userDataRoots.push(path.join(appData, 'Aglit AI'));
36
+ } else {
37
+ userDataRoots.push(path.join(os.homedir(), '.config', 'Aglit AI (Dev)'));
38
+ userDataRoots.push(path.join(os.homedir(), '.config', 'Aglit AI'));
39
+ }
40
+
41
+ for (const root of userDataRoots) {
42
+ try {
43
+ const sessionDir = path.join(root, 'agents', agent, 'sessions', sessionId);
44
+ fs.mkdirSync(sessionDir, { recursive: true });
45
+ const configPath = path.join(sessionDir, 'session-config.json');
46
+ let existing = {};
47
+ if (fs.existsSync(configPath)) {
48
+ try {
49
+ existing = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
50
+ } catch (err) {
51
+ console.warn('[shared] failed to parse existing session-config', configPath, err);
52
+ }
53
+ }
54
+ const now = new Date().toISOString();
55
+ const updated = {
56
+ ...existing,
57
+ autoApproveTools: true,
58
+ updatedAt: now,
59
+ createdAt: existing.createdAt || now,
60
+ };
61
+ fs.writeFileSync(configPath, JSON.stringify(updated, null, 2), 'utf-8');
62
+ } catch (err) {
63
+ console.warn('[shared] failed to write session-config', root, err);
64
+ }
65
+ }
66
+
67
+ try {
68
+ const url = `${base}/chats/${encodeURIComponent(sessionId)}/agent-mode?agentId=${encodeURIComponent(agent)}`;
69
+ const res = await fetch(url, {
70
+ method: 'PATCH',
71
+ headers: { 'content-type': 'application/json' },
72
+ body: JSON.stringify({ autoApproveTools: true }),
73
+ });
74
+
75
+ if (!res.ok) {
76
+ const text = await res.text();
77
+ console.warn('[shared] auto-approve request failed', res.status, res.statusText, text);
78
+ }
79
+ } catch (err) {
80
+ console.warn('[shared] auto-approve request error', err);
81
+ }
82
+ }
83
+
84
+ function unwrapResult(toolResponse) {
85
+ const result = toolResponse?.data?.result || null;
86
+ if (!result) return null;
87
+
88
+ // Newer tool responses carry structured metadata under `_meta`; surface key fields for examples.
89
+ if (result._meta) return { ...result, ...result._meta };
90
+ return result;
91
+ }
92
+
93
+ module.exports = {
94
+ executeTool,
95
+ createChat,
96
+ baseUrl,
97
+ agentId,
98
+ makeSessionId,
99
+ enableAutoApproveTools,
100
+ unwrapResult,
101
+ };
@@ -0,0 +1,74 @@
1
+ const {
2
+ executeTool,
3
+ baseUrl,
4
+ agentId,
5
+ makeSessionId,
6
+ enableAutoApproveTools,
7
+ unwrapResult,
8
+ } = require('./shared');
9
+
10
+ async function runTerminalExample() {
11
+ const sessionId = makeSessionId('terminal');
12
+ await enableAutoApproveTools(sessionId);
13
+
14
+ const open = await executeTool({
15
+ baseUrl,
16
+ agentId,
17
+ request: {
18
+ jsonrpc: '2.0',
19
+ id: `open-${sessionId}`,
20
+ params: {
21
+ name: 'p1_terminal',
22
+ arguments: {
23
+ action: 'open',
24
+ x_aglit_ai_tool_reason: 'SDK example: open terminal',
25
+ },
26
+ },
27
+ context: { sessionId, agentId },
28
+ },
29
+ });
30
+
31
+ const openResult = unwrapResult(open);
32
+ const windowId = openResult?.windowId;
33
+ if (!windowId) {
34
+ throw new Error('Failed to open terminal session');
35
+ }
36
+
37
+ const type = await executeTool({
38
+ baseUrl,
39
+ agentId,
40
+ request: {
41
+ jsonrpc: '2.0',
42
+ id: `type-${sessionId}`,
43
+ params: {
44
+ name: 'p1_terminal',
45
+ arguments: {
46
+ action: 'type',
47
+ windowId,
48
+ text: 'echo hello-from-sdk',
49
+ submit_command: true,
50
+ x_aglit_ai_tool_reason: 'SDK example: run echo in terminal',
51
+ },
52
+ },
53
+ context: { sessionId, agentId },
54
+ },
55
+ });
56
+
57
+ const typeResult = unwrapResult(type);
58
+ const output = typeResult?.output ?? typeResult?.content ?? '';
59
+
60
+ return { windowId, output };
61
+ }
62
+
63
+ if (require.main === module) {
64
+ runTerminalExample()
65
+ .then(res => {
66
+ console.log('[terminal] success', res);
67
+ })
68
+ .catch(err => {
69
+ console.error('[terminal] failed', err);
70
+ process.exitCode = 1;
71
+ });
72
+ }
73
+
74
+ module.exports = { runTerminalExample };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@aglit-ai/sdk",
3
+ "version": "0.1.9",
4
+ "private": false,
5
+ "description": "Aglit AI SDK helpers + OpenAPI-driven client generation entrypoints",
6
+ "author": "Aglit AI <support@aglit.ai>",
7
+ "license": "Aglit AI Commercial License",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "type": "commonjs",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE",
15
+ "examples"
16
+ ],
17
+ "scripts": {
18
+ "build": "node scripts/build-production.js",
19
+ "build:dev": "tsc",
20
+ "dev": "tsc --watch",
21
+ "type-check": "tsc --noEmit",
22
+ "clean": "rm -rf dist",
23
+ "test": "npm run test:examples",
24
+ "generate:clients": "node scripts/generate-openapi-client.js",
25
+ "generate:all": "node scripts/generate-all-clients.js",
26
+ "generate:languages": "node scripts/generate-clients.js",
27
+ "test:examples": "SERVER_PORT=49217 node examples/run-all.js",
28
+ "deploy": "node scripts/deploy.js",
29
+ "publish:go": "node scripts/publish-go.js"
30
+ },
31
+ "dependencies": {
32
+ "@aglit-ai/types": "workspace:*"
33
+ },
34
+ "devDependencies": {
35
+ "@openapitools/openapi-generator-cli": "^2.25.2",
36
+ "@types/uuid": "^11.0.0",
37
+ "esbuild": "^0.23.0",
38
+ "javascript-obfuscator": "^4.1.1",
39
+ "openai": "^4.104.0",
40
+ "prettier": "^3.6.2",
41
+ "typescript": "^5.5.4"
42
+ },
43
+ "keywords": [
44
+ "aglit-ai",
45
+ "sdk",
46
+ "tool-builder",
47
+ "automation"
48
+ ],
49
+ "homepage": "https://github.com/Aglit-AI/monorepo/tree/main/packages/sdk",
50
+ "bugs": {
51
+ "url": "https://github.com/Aglit-AI/monorepo/issues"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/Aglit-AI/monorepo"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }