@llmsafespaces/sdk 0.5.2
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 +113 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @llmsafespaces/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the LLMSafeSpaces API. Zero runtime dependencies — uses native `fetch`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @llmsafespaces/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { LLMSafeSpaces } from '@llmsafespaces/sdk';
|
|
15
|
+
|
|
16
|
+
const client = new LLMSafeSpaces({
|
|
17
|
+
baseUrl: 'https://llmsafespaces.example.com',
|
|
18
|
+
apiKey: 'lsp_your_api_key',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create a workspace and send a message
|
|
22
|
+
const workspace = await client.workspaces.create({ name: 'my-project', runtime: 'python:3.11', storageSize: '10Gi' });
|
|
23
|
+
const session = await client.sessions.ensure(workspace.id);
|
|
24
|
+
const response = await client.sessions.sendMessage(workspace.id, session.sessionId, 'Write hello world in Python');
|
|
25
|
+
console.log(response.content);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Authentication
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// API key (recommended for programmatic use)
|
|
32
|
+
const client = new LLMSafeSpaces({ baseUrl: '...', apiKey: 'lsp_...' });
|
|
33
|
+
|
|
34
|
+
// Email/password (auto-manages JWT, refreshes on 401)
|
|
35
|
+
const client = new LLMSafeSpaces({ baseUrl: '...', credentials: { email: '...', password: '...' } });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Important: `sendMessage` Timeout
|
|
39
|
+
|
|
40
|
+
`sendMessage` proxies to the LLM agent and blocks until it responds. This can take 30-120+ seconds. Default timeout is 120s. On timeout, a `TimeoutError` is thrown — the prompt may still be processing. Poll `getHistory` to check.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { TimeoutError } from '@llmsafespaces/sdk';
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const resp = await client.sessions.sendMessage(wsId, sessId, 'complex prompt...');
|
|
47
|
+
} catch (e) {
|
|
48
|
+
if (e instanceof TimeoutError) {
|
|
49
|
+
// Prompt may still be processing — check history later
|
|
50
|
+
const history = await client.sessions.getHistory(wsId, sessId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Error Handling
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { NotFoundError, AuthError, ConflictError, LLMSafeSpacesError } from '@llmsafespaces/sdk';
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
await client.workspaces.get('nonexistent');
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e instanceof NotFoundError) { /* 404 */ }
|
|
64
|
+
if (e instanceof AuthError) { /* 401/403 */ }
|
|
65
|
+
if (e instanceof ConflictError) { /* 409 - e.g. workspace not active */ }
|
|
66
|
+
if (e instanceof LLMSafeSpacesError) { /* any API error: e.status, e.message */ }
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API Reference
|
|
71
|
+
|
|
72
|
+
### `client.workspaces`
|
|
73
|
+
- `list(limit?, offset?)` — List workspaces
|
|
74
|
+
- `create(req)` — Create workspace
|
|
75
|
+
- `get(id)` — Get workspace
|
|
76
|
+
- `rename(id, name)` — Rename workspace
|
|
77
|
+
- `delete(id)` — Delete workspace
|
|
78
|
+
- `getStatus(id)` — Get workspace status
|
|
79
|
+
- `activate(id)` — Activate workspace (injects credentials, resumes from Suspended)
|
|
80
|
+
- `suspend(id)` — Suspend workspace
|
|
81
|
+
- `setBindings(id, secretIds)` — Set secret bindings
|
|
82
|
+
- `setEnv(id, env)` — Set environment variables
|
|
83
|
+
- `getEnv(id)` — Get environment variables
|
|
84
|
+
|
|
85
|
+
### `client.sessions`
|
|
86
|
+
- `ensure(workspaceId)` — Create session (activates workspace if needed)
|
|
87
|
+
- `list(workspaceId)` — List sessions
|
|
88
|
+
- `getActive(workspaceId)` — Get active sessions
|
|
89
|
+
- `rename(workspaceId, sessionId, title)` — Rename session
|
|
90
|
+
- `sendMessage(workspaceId, sessionId, content)` — Send message (sync, blocks)
|
|
91
|
+
- `getHistory(workspaceId, sessionId)` — Get message history
|
|
92
|
+
- `abort(workspaceId, sessionId)` — Abort current operation
|
|
93
|
+
|
|
94
|
+
### `client.auth`
|
|
95
|
+
- `me()` — Get current user
|
|
96
|
+
- `listApiKeys()` — List API keys
|
|
97
|
+
- `createApiKey(name)` — Create API key
|
|
98
|
+
- `deleteApiKey(id)` — Delete API key
|
|
99
|
+
|
|
100
|
+
### `client.secrets`
|
|
101
|
+
- `create(req)` — Create secret
|
|
102
|
+
- `list()` — List secrets
|
|
103
|
+
- `get(id)` — Get secret
|
|
104
|
+
- `delete(id)` — Delete secret
|
|
105
|
+
- `reveal(id)` — Reveal secret value (audited)
|
|
106
|
+
|
|
107
|
+
### `client.terminal`
|
|
108
|
+
- `getTicket(workspaceId)` — Get one-time WebSocket terminal ticket
|
|
109
|
+
|
|
110
|
+
## Requirements
|
|
111
|
+
|
|
112
|
+
- Node.js 18+ or modern browser (native `fetch` required)
|
|
113
|
+
- No runtime dependencies
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@llmsafespaces/sdk",
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "TypeScript SDK for LLMSafeSpaces API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"generate": "openapi-typescript ../../sdks/openapi.yaml -o src/generated/api.ts"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"openapi-typescript": "^7.6.1",
|
|
27
|
+
"tsup": "^8.3.5",
|
|
28
|
+
"typescript": "^5.7.2",
|
|
29
|
+
"vitest": "^3.0.4"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"license": "AGPL-3.0-or-later",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"node-fetch": "^2.7.0"
|
|
37
|
+
}
|
|
38
|
+
}
|