@tpmjs/tools-sprites-url-set 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 +21 -0
- package/dist/index.js +95 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sprites URL Set Tool for TPMJS
|
|
5
|
+
* Sets the access settings for a sprite URL (public or private).
|
|
6
|
+
*
|
|
7
|
+
* @requires SPRITES_TOKEN environment variable
|
|
8
|
+
*/
|
|
9
|
+
interface SpriteUrlResult {
|
|
10
|
+
url: string;
|
|
11
|
+
auth: 'sprite' | 'public';
|
|
12
|
+
name: string;
|
|
13
|
+
updated: boolean;
|
|
14
|
+
}
|
|
15
|
+
type SpritesUrlSetInput = {
|
|
16
|
+
name: string;
|
|
17
|
+
auth: 'sprite' | 'public';
|
|
18
|
+
};
|
|
19
|
+
declare const spritesUrlSetTool: ai.Tool<SpritesUrlSetInput, SpriteUrlResult>;
|
|
20
|
+
|
|
21
|
+
export { type SpriteUrlResult, spritesUrlSetTool as default, spritesUrlSetTool };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
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 spritesUrlSetTool = tool({
|
|
15
|
+
description: "Set the access settings for a sprite URL. Use 'public' to allow anyone to access the sprite URL (for web servers, APIs, webhooks), or 'sprite' to require authentication. The sprite must have a server listening on port 8080 for the URL to work.",
|
|
16
|
+
inputSchema: jsonSchema({
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
name: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Name of the sprite to update"
|
|
22
|
+
},
|
|
23
|
+
auth: {
|
|
24
|
+
type: "string",
|
|
25
|
+
enum: ["sprite", "public"],
|
|
26
|
+
description: "Access mode - 'public' for public access, 'sprite' for authenticated access only"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
required: ["name", "auth"],
|
|
30
|
+
additionalProperties: false
|
|
31
|
+
}),
|
|
32
|
+
async execute({ name, auth }) {
|
|
33
|
+
if (!name || typeof name !== "string") {
|
|
34
|
+
throw new Error("Sprite name is required and must be a string");
|
|
35
|
+
}
|
|
36
|
+
if (auth !== "sprite" && auth !== "public") {
|
|
37
|
+
throw new Error("Auth must be 'sprite' or 'public'");
|
|
38
|
+
}
|
|
39
|
+
const token = getSpritesToken();
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const timeoutId = setTimeout(() => controller.abort(), 3e4);
|
|
44
|
+
response = await fetch(`${SPRITES_API_BASE}/sprites/${encodeURIComponent(name)}`, {
|
|
45
|
+
method: "PUT",
|
|
46
|
+
headers: {
|
|
47
|
+
Authorization: `Bearer ${token}`,
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
"User-Agent": "TPMJS/1.0"
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
url_settings: { auth }
|
|
53
|
+
}),
|
|
54
|
+
signal: controller.signal
|
|
55
|
+
});
|
|
56
|
+
clearTimeout(timeoutId);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
if (error.name === "AbortError") {
|
|
60
|
+
throw new Error(`Request to set URL auth for sprite "${name}" timed out`);
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`Failed to set URL auth for sprite "${name}": ${error.message}`);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Failed to set URL auth for sprite "${name}": Unknown network error`);
|
|
65
|
+
}
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
if (response.status === 404) {
|
|
68
|
+
throw new Error(`Sprite "${name}" not found`);
|
|
69
|
+
}
|
|
70
|
+
if (response.status === 401) {
|
|
71
|
+
throw new Error("Invalid SPRITES_TOKEN. Check your API token at https://sprites.dev");
|
|
72
|
+
}
|
|
73
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Failed to set URL auth for sprite "${name}": HTTP ${response.status} - ${errorText}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
let data;
|
|
79
|
+
try {
|
|
80
|
+
data = await response.json();
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error("Failed to parse response from Sprites API");
|
|
83
|
+
}
|
|
84
|
+
const urlSettings = data.url_settings;
|
|
85
|
+
return {
|
|
86
|
+
url: data.url || "",
|
|
87
|
+
auth: urlSettings?.auth || auth,
|
|
88
|
+
name: data.name || name,
|
|
89
|
+
updated: true
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
var index_default = spritesUrlSetTool;
|
|
94
|
+
|
|
95
|
+
export { index_default as default, spritesUrlSetTool };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tpmjs/tools-sprites-url-set",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Set the access settings for a sprite URL (public or private)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tpmjs",
|
|
8
|
+
"sprites",
|
|
9
|
+
"sandbox",
|
|
10
|
+
"code-execution",
|
|
11
|
+
"ai"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"type-check": "tsc --noEmit",
|
|
26
|
+
"clean": "rm -rf dist .turbo"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@tpmjs/tsconfig": "workspace:*",
|
|
30
|
+
"tsup": "^8.5.1",
|
|
31
|
+
"typescript": "^5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/anthropics/tpmjs.git",
|
|
39
|
+
"directory": "packages/tools/official/sprites-url-set"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://tpmjs.com",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"tpmjs": {
|
|
44
|
+
"category": "sandbox",
|
|
45
|
+
"frameworks": [
|
|
46
|
+
"vercel-ai"
|
|
47
|
+
],
|
|
48
|
+
"tools": [
|
|
49
|
+
{
|
|
50
|
+
"name": "spritesUrlSetTool",
|
|
51
|
+
"description": "Set the access settings for a sprite URL. Use 'public' to allow anyone to access the sprite URL, or 'sprite' to require authentication.",
|
|
52
|
+
"parameters": [
|
|
53
|
+
{
|
|
54
|
+
"name": "name",
|
|
55
|
+
"type": "string",
|
|
56
|
+
"description": "Name of the sprite to update",
|
|
57
|
+
"required": true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "auth",
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Access mode - 'public' for public access, 'sprite' for authenticated access only",
|
|
63
|
+
"required": true
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"returns": {
|
|
67
|
+
"type": "SpriteUrlResult",
|
|
68
|
+
"description": "Updated sprite URL and settings"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"ai": "6.0.23"
|
|
75
|
+
}
|
|
76
|
+
}
|