@aglit-ai/sdk 0.1.10 → 0.1.11

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.
@@ -1,63 +0,0 @@
1
- const { runTerminalExample } = require('./terminal');
2
- const { runBrowserExample } = require('./browser');
3
- const { runAppExample } = require('./app');
4
- const { runChatExample } = require('./chat');
5
- const { runOpenAIExample } = require('./openai-sdk');
6
- const { runMcpExample } = require('./mcp');
7
- const { baseUrl, agentId } = require('./shared');
8
-
9
- async function checkServerAvailable() {
10
- try {
11
- const res = await fetch(`${baseUrl}/health`, { signal: AbortSignal.timeout(10000) });
12
- return res.ok;
13
- } catch {
14
- return false;
15
- }
16
- }
17
-
18
- async function run() {
19
- console.log('Using baseUrl:', baseUrl, 'agentId:', agentId);
20
-
21
- // Check if server is available before running examples
22
- const serverAvailable = await checkServerAvailable();
23
- if (!serverAvailable) {
24
- console.log('[run-all] Server not available at', baseUrl, '- skipping SDK examples');
25
- console.log('[run-all] To run these tests, start the dev server: pnpm run dev');
26
- return;
27
- }
28
-
29
- const terminal = await runTerminalExample();
30
- console.log('[run-all] terminal ok', terminal);
31
-
32
- const browser = await runBrowserExample();
33
- console.log('[run-all] browser ok', browser);
34
-
35
- const app = await runAppExample();
36
- console.log('[run-all] app ok', app);
37
-
38
- const openai = await runOpenAIExample();
39
- if (openai?.skipped) {
40
- console.log('[run-all] openai skipped', openai.reason ?? '');
41
- } else {
42
- console.log('[run-all] openai ok', openai);
43
- }
44
-
45
- const mcp = await runMcpExample();
46
- if (mcp?.skipped) {
47
- console.log('[run-all] mcp skipped', mcp.reason ?? '');
48
- } else {
49
- console.log('[run-all] mcp ok', mcp);
50
- }
51
-
52
- const chat = await runChatExample();
53
- console.log('[run-all] chat ok', chat);
54
- }
55
-
56
- if (require.main === module) {
57
- run().catch(err => {
58
- console.error('[run-all] failed', err);
59
- process.exitCode = 1;
60
- });
61
- }
62
-
63
- module.exports = { run };
@@ -1,101 +0,0 @@
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
- };
@@ -1,74 +0,0 @@
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 };