@agentstep/agent-sdk 0.5.5 → 0.5.6
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.
|
@@ -23,6 +23,32 @@ import {
|
|
|
23
23
|
|
|
24
24
|
// src/handlers/skills-write.ts
|
|
25
25
|
import { z } from "zod";
|
|
26
|
+
import { inflateRawSync } from "zlib";
|
|
27
|
+
function extractFromZip(buffer) {
|
|
28
|
+
const files = /* @__PURE__ */ new Map();
|
|
29
|
+
let offset = 0;
|
|
30
|
+
while (offset + 30 <= buffer.length) {
|
|
31
|
+
const sig = buffer.readUInt32LE(offset);
|
|
32
|
+
if (sig !== 67324752) break;
|
|
33
|
+
const compMethod = buffer.readUInt16LE(offset + 8);
|
|
34
|
+
const compSize = buffer.readUInt32LE(offset + 18);
|
|
35
|
+
const uncompSize = buffer.readUInt32LE(offset + 22);
|
|
36
|
+
const nameLen = buffer.readUInt16LE(offset + 26);
|
|
37
|
+
const extraLen = buffer.readUInt16LE(offset + 28);
|
|
38
|
+
const name = buffer.toString("utf8", offset + 30, offset + 30 + nameLen);
|
|
39
|
+
const dataStart = offset + 30 + nameLen + extraLen;
|
|
40
|
+
if (compMethod === 0) {
|
|
41
|
+
const content = buffer.toString("utf8", dataStart, dataStart + uncompSize);
|
|
42
|
+
files.set(name, content);
|
|
43
|
+
} else if (compMethod === 8) {
|
|
44
|
+
const compressed = buffer.subarray(dataStart, dataStart + compSize);
|
|
45
|
+
const content = inflateRawSync(compressed).toString("utf8");
|
|
46
|
+
files.set(name, content);
|
|
47
|
+
}
|
|
48
|
+
offset = dataStart + compSize;
|
|
49
|
+
}
|
|
50
|
+
return files;
|
|
51
|
+
}
|
|
26
52
|
var CreateSkillSchema = z.object({
|
|
27
53
|
name: z.string().min(1).max(256),
|
|
28
54
|
description: z.string().max(2048).optional(),
|
|
@@ -36,20 +62,46 @@ var CreateVersionSchema = z.object({
|
|
|
36
62
|
});
|
|
37
63
|
function handleCreateSkill(request) {
|
|
38
64
|
return routeWrap(request, async ({ auth }) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
66
|
+
let name;
|
|
67
|
+
let description;
|
|
68
|
+
let content;
|
|
69
|
+
let tenantId;
|
|
70
|
+
if (contentType.includes("multipart/form-data")) {
|
|
71
|
+
const formData = await request.formData();
|
|
72
|
+
name = (formData.get("display_title") ?? "").trim() || "untitled";
|
|
73
|
+
const file = formData.get("files[]") ?? formData.get("files") ?? formData.get("file");
|
|
74
|
+
if (!file || !(file instanceof File)) {
|
|
75
|
+
throw badRequest("Missing file in multipart upload");
|
|
76
|
+
}
|
|
77
|
+
const buffer = Buffer.from(await file.arrayBuffer());
|
|
78
|
+
if (file.name?.toLowerCase().endsWith(".zip")) {
|
|
79
|
+
const zipFiles = extractFromZip(buffer);
|
|
80
|
+
const skillEntry = [...zipFiles.entries()].find(
|
|
81
|
+
([k]) => k.endsWith("SKILL.md") || k.endsWith("skill.md")
|
|
82
|
+
);
|
|
83
|
+
if (!skillEntry) {
|
|
84
|
+
throw badRequest("No SKILL.md found in zip archive");
|
|
85
|
+
}
|
|
86
|
+
content = skillEntry[1];
|
|
87
|
+
} else {
|
|
88
|
+
content = buffer.toString("utf-8");
|
|
89
|
+
}
|
|
90
|
+
tenantId = resolveCreateTenant(auth, void 0);
|
|
91
|
+
} else {
|
|
92
|
+
const body = await request.json().catch(() => null);
|
|
93
|
+
const parsed = CreateSkillSchema.safeParse(body);
|
|
94
|
+
if (!parsed.success) {
|
|
95
|
+
throw badRequest(
|
|
96
|
+
`invalid body: ${parsed.error.issues.map((i) => i.message).join("; ")}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
name = parsed.data.name;
|
|
100
|
+
description = parsed.data.description;
|
|
101
|
+
content = parsed.data.content;
|
|
102
|
+
tenantId = resolveCreateTenant(auth, parsed.data.tenant_id);
|
|
45
103
|
}
|
|
46
|
-
const
|
|
47
|
-
const skill = createSkill({
|
|
48
|
-
name: parsed.data.name,
|
|
49
|
-
description: parsed.data.description,
|
|
50
|
-
content: parsed.data.content,
|
|
51
|
-
tenantId
|
|
52
|
-
});
|
|
104
|
+
const skill = createSkill({ name, description, content, tenantId });
|
|
53
105
|
return jsonOk(skill, 201);
|
|
54
106
|
});
|
|
55
107
|
}
|
package/dist/handlers/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"license": "Apache-2.0",
|
|
3
3
|
"name": "@agentstep/agent-sdk",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.6",
|
|
5
5
|
"description": "Core engine for AgentStep Gateway \u2014 backends, sandbox providers, session orchestration, and vault encryption.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"anthropic",
|