@tpmjs/tools-sprites-sessions 0.1.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/dist/index.d.ts +24 -0
- package/dist/index.js +92 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sprites Sessions Tool for TPMJS
|
|
5
|
+
* Lists active execution sessions for a sprite.
|
|
6
|
+
*
|
|
7
|
+
* @requires SPRITES_TOKEN environment variable
|
|
8
|
+
*/
|
|
9
|
+
interface ExecSession {
|
|
10
|
+
id: string;
|
|
11
|
+
status: 'active' | 'completed' | 'terminated';
|
|
12
|
+
startedAt: string;
|
|
13
|
+
command?: string;
|
|
14
|
+
}
|
|
15
|
+
interface SpritesSessionsResult {
|
|
16
|
+
sessions: ExecSession[];
|
|
17
|
+
count: number;
|
|
18
|
+
}
|
|
19
|
+
type SpritesSessionsInput = {
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
declare const spritesSessionsTool: ai.Tool<SpritesSessionsInput, SpritesSessionsResult>;
|
|
23
|
+
|
|
24
|
+
export { type ExecSession, type SpritesSessionsResult, spritesSessionsTool as default, spritesSessionsTool };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { tool, jsonSchema } from 'ai';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var SPRITES_API_BASE = "https://api.sprites.dev/v1";
|
|
5
|
+
function getSpritesToken() {
|
|
6
|
+
const token = process.env.SPRITES_TOKEN;
|
|
7
|
+
if (!token) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"SPRITES_TOKEN environment variable is required. Get your token from https://sprites.dev"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return token;
|
|
13
|
+
}
|
|
14
|
+
var spritesSessionsTool = tool({
|
|
15
|
+
description: "List active execution sessions for a sprite. Useful for monitoring running commands or attaching to existing sessions.",
|
|
16
|
+
inputSchema: jsonSchema({
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
name: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Name of the sprite to list sessions for"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ["name"],
|
|
25
|
+
additionalProperties: false
|
|
26
|
+
}),
|
|
27
|
+
async execute({ name }) {
|
|
28
|
+
if (!name || typeof name !== "string") {
|
|
29
|
+
throw new Error("Sprite name is required and must be a string");
|
|
30
|
+
}
|
|
31
|
+
const token = getSpritesToken();
|
|
32
|
+
let response;
|
|
33
|
+
try {
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const timeoutId = setTimeout(() => controller.abort(), 3e4);
|
|
36
|
+
response = await fetch(
|
|
37
|
+
`${SPRITES_API_BASE}/sprites/${encodeURIComponent(name)}/exec/sessions`,
|
|
38
|
+
{
|
|
39
|
+
method: "GET",
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${token}`,
|
|
42
|
+
"User-Agent": "TPMJS/1.0"
|
|
43
|
+
},
|
|
44
|
+
signal: controller.signal
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
clearTimeout(timeoutId);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
if (error.name === "AbortError") {
|
|
51
|
+
throw new Error(`Request to list sessions for sprite "${name}" timed out`);
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Failed to list sessions for sprite "${name}": ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`Failed to list sessions for sprite "${name}": Unknown network error`);
|
|
56
|
+
}
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
if (response.status === 404) {
|
|
59
|
+
throw new Error(`Sprite "${name}" not found`);
|
|
60
|
+
}
|
|
61
|
+
if (response.status === 401) {
|
|
62
|
+
throw new Error("Invalid SPRITES_TOKEN. Check your API token at https://sprites.dev");
|
|
63
|
+
}
|
|
64
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Failed to list sessions for sprite "${name}": HTTP ${response.status} - ${errorText}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
let data;
|
|
70
|
+
try {
|
|
71
|
+
data = await response.json();
|
|
72
|
+
} catch {
|
|
73
|
+
throw new Error("Failed to parse response from Sprites API");
|
|
74
|
+
}
|
|
75
|
+
const sessionsArray = Array.isArray(data) ? data : data.sessions;
|
|
76
|
+
const sessions = (Array.isArray(sessionsArray) ? sessionsArray : []).map(
|
|
77
|
+
(s) => ({
|
|
78
|
+
id: s.id,
|
|
79
|
+
status: s.status || "active",
|
|
80
|
+
startedAt: s.startedAt || s.started_at || "",
|
|
81
|
+
command: s.command
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
sessions,
|
|
86
|
+
count: sessions.length
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
var index_default = spritesSessionsTool;
|
|
91
|
+
|
|
92
|
+
export { index_default as default, spritesSessionsTool };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tpmjs/tools-sprites-sessions",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "List active execution sessions for a sprite",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": ["tpmjs", "sprites", "sandbox", "code-execution", "ai"],
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"type-check": "tsc --noEmit",
|
|
18
|
+
"clean": "rm -rf dist .turbo"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tpmjs/tsconfig": "workspace:*",
|
|
22
|
+
"tsup": "^8.5.1",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": { "access": "public" },
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/anthropics/tpmjs.git",
|
|
29
|
+
"directory": "packages/tools/official/sprites-sessions"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://tpmjs.com",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"tpmjs": {
|
|
34
|
+
"category": "sandbox",
|
|
35
|
+
"frameworks": ["vercel-ai"],
|
|
36
|
+
"tools": [{
|
|
37
|
+
"name": "spritesSessionsTool",
|
|
38
|
+
"description": "List active execution sessions for a sprite",
|
|
39
|
+
"parameters": [{
|
|
40
|
+
"name": "name",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "Name of the sprite to list sessions for",
|
|
43
|
+
"required": true
|
|
44
|
+
}],
|
|
45
|
+
"returns": {
|
|
46
|
+
"type": "{ sessions: ExecSession[], count: number }",
|
|
47
|
+
"description": "Array of active execution sessions with count"
|
|
48
|
+
}
|
|
49
|
+
}]
|
|
50
|
+
},
|
|
51
|
+
"dependencies": { "ai": "6.0.23" }
|
|
52
|
+
}
|