@jini-ai/agentic 0.4.3 → 0.4.5
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/CHANGELOG.md +4 -0
- package/dist/core/a2ui/json-pointer.js +94 -73
- package/dist/core/a2ui/resolve.js +45 -23
- package/dist/core/a2ui/tree.js +8 -5
- package/dist/core/capability.js +21 -12
- package/dist/core/dom/dom-page-driver.js +89 -74
- package/dist/core/gen-ui/encoder.js +31 -31
- package/dist/core/guards.js +13 -6
- package/dist/core/handle.d.ts +13 -0
- package/dist/core/handle.js +19 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +2 -1
- package/dist/core/mcp-ui-apps.js +12 -6
- package/dist/core/page-executor.js +131 -111
- package/dist/core/site-guide/index.d.ts +4 -0
- package/dist/core/site-guide/index.js +4 -0
- package/dist/core/site-guide/site-guide.d.ts +18 -0
- package/dist/core/site-guide/site-guide.js +162 -0
- package/dist/core/site-guide/topic-schema.d.ts +16 -0
- package/dist/core/site-guide/topic-schema.js +68 -0
- package/dist/core/site-guide/types.d.ts +83 -0
- package/dist/core/site-guide/types.js +2 -0
- package/dist/skills/install/archive.js +42 -30
- package/dist/skills/install/github.js +102 -63
- package/dist/skills/install/index.d.ts +1 -0
- package/dist/skills/install/index.js +1 -0
- package/dist/skills/install/install-service.d.ts +20 -1
- package/dist/skills/install/install-service.js +23 -11
- package/dist/skills/install/layout.d.ts +8 -0
- package/dist/skills/install/layout.js +26 -1
- package/dist/skills/install/live-registration.js +1 -0
- package/dist/skills/install/node-filesystem.js +3 -1
- package/dist/skills/install/state.js +18 -7
- package/dist/skills/install/validation.d.ts +5 -1
- package/dist/skills/install/validation.js +85 -52
- package/dist/skills/install/yauzl-archive-reader.d.ts +29 -0
- package/dist/skills/install/yauzl-archive-reader.js +31 -0
- package/package.json +4 -4
- package/dist/a2ui/agent-to-renderer.d.ts +0 -613
- package/dist/a2ui/agent-to-renderer.js +0 -191
- package/dist/a2ui/catalog.d.ts +0 -73
- package/dist/a2ui/catalog.js +0 -304
- package/dist/a2ui/common-types.d.ts +0 -401
- package/dist/a2ui/common-types.js +0 -130
- package/dist/a2ui/index.d.ts +0 -16
- package/dist/a2ui/index.js +0 -16
- package/dist/a2ui/interpreter.d.ts +0 -71
- package/dist/a2ui/interpreter.js +0 -337
- package/dist/a2ui/json-pointer.d.ts +0 -48
- package/dist/a2ui/json-pointer.js +0 -174
- package/dist/a2ui/renderer-to-agent.d.ts +0 -342
- package/dist/a2ui/renderer-to-agent.js +0 -111
- package/dist/a2ui/resolve.d.ts +0 -28
- package/dist/a2ui/resolve.js +0 -144
- package/dist/a2ui/tree.d.ts +0 -66
- package/dist/a2ui/tree.js +0 -74
- package/dist/ag-ui.d.ts +0 -82
- package/dist/ag-ui.js +0 -85
- package/dist/agui/encoder.d.ts +0 -50
- package/dist/agui/encoder.js +0 -97
- package/dist/agui/events.d.ts +0 -59
- package/dist/agui/events.js +0 -15
- package/dist/capability.d.ts +0 -81
- package/dist/capability.js +0 -79
- package/dist/dom/dom-page-driver.d.ts +0 -36
- package/dist/dom/dom-page-driver.js +0 -601
- package/dist/dom/index.d.ts +0 -17
- package/dist/dom/index.js +0 -17
- package/dist/dom/model-context.d.ts +0 -69
- package/dist/dom/model-context.js +0 -44
- package/dist/element-handles.d.ts +0 -120
- package/dist/element-handles.js +0 -39
- package/dist/gen-ui/encoder.d.ts +0 -50
- package/dist/gen-ui/encoder.js +0 -97
- package/dist/gen-ui/events.d.ts +0 -59
- package/dist/gen-ui/events.js +0 -15
- package/dist/gen-ui/index.d.ts +0 -18
- package/dist/gen-ui/index.js +0 -17
- package/dist/guards.d.ts +0 -96
- package/dist/guards.js +0 -186
- package/dist/handle.d.ts +0 -41
- package/dist/handle.js +0 -41
- package/dist/mcp-ui-apps.d.ts +0 -223
- package/dist/mcp-ui-apps.js +0 -252
- package/dist/mcp-ui.d.ts +0 -133
- package/dist/mcp-ui.js +0 -134
- package/dist/page-capabilities.d.ts +0 -14
- package/dist/page-capabilities.js +0 -129
- package/dist/page-driver.d.ts +0 -120
- package/dist/page-driver.js +0 -2
- package/dist/page-executor.d.ts +0 -94
- package/dist/page-executor.js +0 -320
- package/dist/webmcp.d.ts +0 -202
- package/dist/webmcp.js +0 -173
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SkillUploadFile } from "./validation.js";
|
|
1
|
+
import { validateSkillFiles, type SkillUploadFile } from "./validation.js";
|
|
2
2
|
import { type GitHubSkillSource } from "./github.js";
|
|
3
3
|
import type { SkillInstallDeps } from "./ports.js";
|
|
4
4
|
export interface ManagedSkill {
|
|
@@ -17,7 +17,26 @@ export type SkillInstallInput = {
|
|
|
17
17
|
} | {
|
|
18
18
|
readonly archiveBase64: string;
|
|
19
19
|
});
|
|
20
|
+
/** A fetched and fully validated skill package, not yet written. Holding the validated bytes (not
|
|
21
|
+
* the source) means commitSkillInstall writes exactly what was validated, with no second fetch. */
|
|
22
|
+
export interface PreparedSkillInstall {
|
|
23
|
+
readonly toolId: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly description: string;
|
|
26
|
+
readonly source: ManagedSkill["source"];
|
|
27
|
+
readonly files: ReturnType<typeof validateSkillFiles>["files"];
|
|
28
|
+
}
|
|
29
|
+
/** Fetch/decode and validate before asking for mutation approval. No filesystem writes. */
|
|
30
|
+
export declare function prepareSkillInstall(required: {
|
|
31
|
+
input: SkillInstallInput;
|
|
32
|
+
deps: Pick<SkillInstallDeps, "fetch" | "archiveReader" | "yamlReader" | "toolId">;
|
|
33
|
+
}, _optional?: {}): Promise<PreparedSkillInstall>;
|
|
20
34
|
export interface SkillInstaller {
|
|
35
|
+
prepareSkillInstall(required: SkillInstallInput): Promise<PreparedSkillInstall>;
|
|
36
|
+
commitSkillInstall(required: {
|
|
37
|
+
workspaceId: string;
|
|
38
|
+
prepared: PreparedSkillInstall;
|
|
39
|
+
}): Promise<ManagedSkill>;
|
|
21
40
|
installSkill(required: SkillInstallInput): Promise<ManagedSkill>;
|
|
22
41
|
listManagedSkills(required: {
|
|
23
42
|
workspaceId: string;
|
|
@@ -3,6 +3,20 @@ import { SkillInputError, validateSkillFiles } from "./validation.js";
|
|
|
3
3
|
import { readSkillArchive } from "./archive.js";
|
|
4
4
|
import { fetchGitHubSkill } from "./github.js";
|
|
5
5
|
import { readSkillState } from "./state.js";
|
|
6
|
+
/** Fetch/decode and validate before asking for mutation approval. No filesystem writes. */
|
|
7
|
+
export async function prepareSkillInstall(required, _optional = {}) {
|
|
8
|
+
const { input, deps } = required;
|
|
9
|
+
let upload;
|
|
10
|
+
let source = "uploaded";
|
|
11
|
+
if ("githubUrl" in input)
|
|
12
|
+
({ files: upload, source } = await fetchGitHubSkill({ githubUrl: input.githubUrl, fetch: deps.fetch }));
|
|
13
|
+
else if ("archiveBase64" in input)
|
|
14
|
+
upload = await readSkillArchive({ base64: input.archiveBase64, archiveReader: deps.archiveReader });
|
|
15
|
+
else
|
|
16
|
+
upload = input.files;
|
|
17
|
+
const validated = validateSkillFiles({ files: upload, yamlReader: deps.yamlReader });
|
|
18
|
+
return { ...validated, toolId: deps.toolId({ name: validated.name }), source };
|
|
19
|
+
}
|
|
6
20
|
/** Validate before writes; publish via rename, with instance-local queues keyed by resolved root.
|
|
7
21
|
* Cross-process exclusivity remains the host filesystem/layout adapter's responsibility.
|
|
8
22
|
*/
|
|
@@ -16,6 +30,7 @@ export function createSkillInstaller(deps, optional = {}) {
|
|
|
16
30
|
throw new SkillInputError({ message: "Invalid skill state file name." });
|
|
17
31
|
return layout;
|
|
18
32
|
};
|
|
33
|
+
/** Serializes mutations in this server without leaving persistent locks after a crash. */
|
|
19
34
|
async function locked(workspaceId, work) {
|
|
20
35
|
const key = layoutFor(workspaceId).workspaceRoot;
|
|
21
36
|
const result = (queues.get(key) ?? Promise.resolve()).catch(() => { }).then(work);
|
|
@@ -47,19 +62,15 @@ export function createSkillInstaller(deps, optional = {}) {
|
|
|
47
62
|
return directory;
|
|
48
63
|
}
|
|
49
64
|
const changed = async (workspaceId, toolId) => { await optional.onChanged?.({ workspaceId, toolId }); };
|
|
50
|
-
|
|
65
|
+
const installer = {
|
|
51
66
|
listManagedSkills,
|
|
67
|
+
prepareSkillInstall: input => prepareSkillInstall({ input, deps }),
|
|
52
68
|
async installSkill(input) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
upload = await readSkillArchive({ base64: input.archiveBase64, archiveReader: deps.archiveReader });
|
|
59
|
-
else
|
|
60
|
-
upload = input.files;
|
|
61
|
-
const validated = validateSkillFiles({ files: upload, yamlReader: deps.yamlReader });
|
|
62
|
-
const toolId = deps.toolId({ name: validated.name });
|
|
69
|
+
return installer.commitSkillInstall({ workspaceId: input.workspaceId, prepared: await prepareSkillInstall({ input, deps }) });
|
|
70
|
+
},
|
|
71
|
+
async commitSkillInstall(input) {
|
|
72
|
+
const validated = input.prepared;
|
|
73
|
+
const { toolId, source } = validated;
|
|
63
74
|
const layout = layoutFor(input.workspaceId);
|
|
64
75
|
return locked(input.workspaceId, async () => {
|
|
65
76
|
if ((await listManagedSkills(input)).some(skill => skill.toolId === toolId))
|
|
@@ -112,6 +123,7 @@ export function createSkillInstaller(deps, optional = {}) {
|
|
|
112
123
|
});
|
|
113
124
|
},
|
|
114
125
|
};
|
|
126
|
+
return installer;
|
|
115
127
|
}
|
|
116
128
|
function containedDirectory(root, directory) {
|
|
117
129
|
if (!directory || directory === "." || directory === ".." || /[/\\\x00]/.test(directory))
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { SkillLayoutPort } from './ports.js';
|
|
2
|
+
/**
|
|
3
|
+
* Deliberately does NOT import anything from `src/features/agent-plugins/` — Agent Skills and Agent
|
|
4
|
+
* Plugins are different things with their own directories (owner decision, above), and this file's
|
|
5
|
+
* small id-segment guard is duplicated rather than shared, for the same reason
|
|
6
|
+
* `capability-projection.ts`/`capability-source.ts` already duplicate their own `humanize` helper
|
|
7
|
+
* between themselves: a private guard belonging to one small module, not a promise to keep two
|
|
8
|
+
* independent features' internals in sync.
|
|
9
|
+
*/
|
|
2
10
|
/** Every storage location is host-owned; this adapter has no product or cwd defaults.
|
|
3
11
|
* Layout resolves the same required root/stagingRoot/workspaceDirectory/stateFileName
|
|
4
12
|
* contract used by the installer. No site, environment or cwd defaults are allowed: separate
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* One safe, indivisible path segment: lowercase alphanumerics in `-`/`.`-separated runs, with no
|
|
4
|
+
* leading, trailing, or doubled separator. Mirrors `agent-plugins/layout.ts`'s own
|
|
5
|
+
* `SAFE_ID_SEGMENT_PATTERN` — duplicated rather than imported (see this file's header) — and accepts
|
|
6
|
+
* this instance's real workspace id (`workspace-local`, per `<site>/uploads/ws/workspace-local/`) as
|
|
7
|
+
* well as every UUID.
|
|
8
|
+
*/
|
|
9
|
+
const SAFE_ID_SEGMENT_PATTERN = /^[a-z0-9]+(?:[-.][a-z0-9]+)*$/;
|
|
10
|
+
/** Bounds the segment so a caller cannot drive a pathological path length. */
|
|
11
|
+
const MAX_ID_SEGMENT_LENGTH = 64;
|
|
12
|
+
// The segment grammar above moved from host features/skills/layout.ts; the sibling path in its
|
|
13
|
+
// historical rationale refers to host features/agent-plugins/layout.ts.
|
|
14
|
+
/**
|
|
15
|
+
* Deliberately does NOT import anything from `src/features/agent-plugins/` — Agent Skills and Agent
|
|
16
|
+
* Plugins are different things with their own directories (owner decision, above), and this file's
|
|
17
|
+
* small id-segment guard is duplicated rather than shared, for the same reason
|
|
18
|
+
* `capability-projection.ts`/`capability-source.ts` already duplicate their own `humanize` helper
|
|
19
|
+
* between themselves: a private guard belonging to one small module, not a promise to keep two
|
|
20
|
+
* independent features' internals in sync.
|
|
21
|
+
*/
|
|
22
|
+
// This paragraph records the original host module boundary; the private segment guard now
|
|
23
|
+
// belongs to this Jini layout owner, and the host keeps only the site-directory adapter.
|
|
2
24
|
/** Every storage location is host-owned; this adapter has no product or cwd defaults.
|
|
3
25
|
* Layout resolves the same required root/stagingRoot/workspaceDirectory/stateFileName
|
|
4
26
|
* contract used by the installer. No site, environment or cwd defaults are allowed: separate
|
|
@@ -13,8 +35,11 @@ export function createSkillLayout(required, _optional = {}) {
|
|
|
13
35
|
if (!stateFileName || /[/\\\x00]/.test(stateFileName) || ['.', '..', 'SKILL.md', 'README.md', 'LICENSE', 'references', 'scripts', 'assets'].includes(stateFileName))
|
|
14
36
|
throw new Error('Invalid skill state file name.');
|
|
15
37
|
return Object.freeze({ resolve({ workspaceId }) {
|
|
38
|
+
// Normalize BEFORE validating, not after — see `agent-plugins/layout.ts`'s own comment at the
|
|
39
|
+
// identical line: the pattern is deliberately lowercase-only, and the normalized value is the
|
|
40
|
+
// one that actually becomes the path segment, so it is the only value worth asserting about.
|
|
16
41
|
const normalized = workspaceId.toLowerCase();
|
|
17
|
-
if (normalized.length >
|
|
42
|
+
if (normalized.length > MAX_ID_SEGMENT_LENGTH || !SAFE_ID_SEGMENT_PATTERN.test(normalized))
|
|
18
43
|
throw new Error(`resolve: '${workspaceId}' is not a valid workspace id`);
|
|
19
44
|
return { workspaceRoot: path.join(root, workspaceDirectory, normalized), stagingRoot: path.resolve(stagingRoot), stateFileName };
|
|
20
45
|
} });
|
|
@@ -8,6 +8,7 @@ export function createLiveSkillRegistration(required, _optional = {}) {
|
|
|
8
8
|
registry.has = input => slots.has(input.id) ? active.has(input.id) : has(input);
|
|
9
9
|
let fingerprint = '';
|
|
10
10
|
return ({ tools }) => {
|
|
11
|
+
// Discovery changes invalidate the search snapshot; handlers always use current guidance.
|
|
11
12
|
const nextFingerprint = JSON.stringify(tools.map(t => t.descriptor));
|
|
12
13
|
const next = new Map(tools.map(t => [t.descriptor.id, t]));
|
|
13
14
|
if (next.size !== tools.length)
|
|
@@ -33,7 +33,9 @@ export function createNodeSkillFilesystem(_required, _optional = {}) {
|
|
|
33
33
|
await handle.close();
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
// The port types `exclusive` as the literal `true`: skill files and state temporaries are only
|
|
37
|
+
// ever created, never overwritten in place, so the flag is always exclusive-create.
|
|
38
|
+
writeFile: ({ path, bytes, mode }) => writeFile(path, bytes, { flag: 'wx', mode }),
|
|
37
39
|
rename: ({ from, to }) => rename(from, to),
|
|
38
40
|
remove: ({ path }, options = {}) => rm(path, options),
|
|
39
41
|
};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
const MAX_STATE_BYTES = 8192;
|
|
3
|
+
const INVALID_STATE = "Invalid skill installation record.";
|
|
2
4
|
/** Missing legacy records default to enabled; malformed records and symlinks fail closed. */
|
|
3
5
|
export async function readSkillState(required, _optional = {}) {
|
|
4
6
|
const statePath = path.join(required.directory, required.stateFileName);
|
|
5
7
|
try {
|
|
6
8
|
const info = await required.filesystem.lstat({ path: statePath });
|
|
7
|
-
if (info.kind !== "file" || info.size >
|
|
8
|
-
throw new Error(
|
|
9
|
-
const bytes = await required.filesystem.readFile({ path: statePath, maxBytes:
|
|
10
|
-
if (bytes.length >
|
|
11
|
-
throw new Error(
|
|
9
|
+
if (info.kind !== "file" || info.size > MAX_STATE_BYTES)
|
|
10
|
+
throw new Error(INVALID_STATE);
|
|
11
|
+
const bytes = await required.filesystem.readFile({ path: statePath, maxBytes: MAX_STATE_BYTES });
|
|
12
|
+
if (bytes.length > MAX_STATE_BYTES)
|
|
13
|
+
throw new Error(INVALID_STATE);
|
|
12
14
|
const state = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
13
|
-
if (!
|
|
14
|
-
throw new Error(
|
|
15
|
+
if (!isSkillState(state))
|
|
16
|
+
throw new Error(INVALID_STATE);
|
|
15
17
|
return state;
|
|
16
18
|
}
|
|
17
19
|
catch (error) {
|
|
@@ -20,4 +22,13 @@ export async function readSkillState(required, _optional = {}) {
|
|
|
20
22
|
throw error;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
25
|
+
/** A boolean `enabled` plus either "uploaded" or a GitHub source pinned to a 40-hex commit. */
|
|
26
|
+
function isSkillState(value) {
|
|
27
|
+
const state = value;
|
|
28
|
+
if (!state || typeof state.enabled !== "boolean")
|
|
29
|
+
return false;
|
|
30
|
+
if (state.source === "uploaded")
|
|
31
|
+
return true;
|
|
32
|
+
return !!state.source && typeof state.source.githubUrl === "string" && /^[a-f0-9]{40}$/.test(state.source.commit);
|
|
33
|
+
}
|
|
23
34
|
//# sourceMappingURL=state.js.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { YamlReaderPort } from "./ports.js";
|
|
2
2
|
export type SkillYamlPort = YamlReaderPort;
|
|
3
3
|
export declare class SkillInputError extends Error {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(required: {
|
|
5
5
|
message: string;
|
|
6
6
|
}, optional?: {
|
|
7
7
|
cause?: unknown;
|
|
8
8
|
});
|
|
9
|
+
/** Published host adapters may still use the native Error call shape during migration. */
|
|
10
|
+
constructor(message: string, optional?: {
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
});
|
|
9
13
|
}
|
|
10
14
|
export interface SkillUploadFile {
|
|
11
15
|
readonly path: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Bounded skill-bundle validation; scripts are stored as data and never executed. */
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
export class SkillInputError extends Error {
|
|
4
|
-
constructor(
|
|
5
|
-
super(message, optional);
|
|
4
|
+
constructor(required, optional = {}) {
|
|
5
|
+
super(typeof required === "string" ? required : required.message, optional);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
export const MAX_SKILL_BYTES = 8 * 1024 * 1024;
|
|
@@ -10,6 +10,10 @@ export const MAX_SKILL_FILES = 256;
|
|
|
10
10
|
export const MAX_SKILL_FILE_BYTES = 1024 * 1024;
|
|
11
11
|
const TEXT_EXTENSIONS = new Set([".md", ".txt", ".json", ".yaml", ".yml", ".csv", ".svg", ".sh", ".py", ".js", ".ts", ".mjs"]);
|
|
12
12
|
const ASSET_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
13
|
+
const ROOT_FILES = new Set(["SKILL.md", "README.md", "LICENSE"]);
|
|
14
|
+
const SKILL_FOLDERS = new Set(["references", "scripts", "assets"]);
|
|
15
|
+
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
16
|
+
const MISSING_FRONTMATTER = "SKILL.md must have YAML frontmatter with a name and description.";
|
|
13
17
|
/** Decodes bounded canonical base64; malformed encodings never silently turn into empty files. */
|
|
14
18
|
export function decodeSkillBase64({ value }, { maxBytes = MAX_SKILL_BYTES } = {}) {
|
|
15
19
|
if (typeof value !== "string" || value.length > Math.ceil(maxBytes / 3) * 4)
|
|
@@ -27,24 +31,28 @@ export function validateSkillPath({ filePath }, _optional = {}) {
|
|
|
27
31
|
}
|
|
28
32
|
/** Strict frontmatter for new installs; the legacy disk loader remains backwards compatible. */
|
|
29
33
|
export function validateSkillMarkdown({ markdown, yamlReader }, _optional = {}) {
|
|
34
|
+
const { name, description } = readFrontmatterFields({ markdown, yamlReader });
|
|
35
|
+
if (typeof name !== "string" || typeof description !== "string" || !description.trim())
|
|
36
|
+
throw new SkillInputError({ message: MISSING_FRONTMATTER });
|
|
37
|
+
if (name.length > 64 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))
|
|
38
|
+
throw new SkillInputError({ message: "Skill name must use lowercase letters, digits and single hyphens (1–64 characters)." });
|
|
39
|
+
if (description.length > 1024)
|
|
40
|
+
throw new SkillInputError({ message: "Skill description exceeds 1024 characters." });
|
|
41
|
+
return { name, description: description.replace(/\s+/g, " ").trim() };
|
|
42
|
+
}
|
|
43
|
+
/** Parses the leading `---` block through the host YAML port; a non-object result has no fields. */
|
|
44
|
+
function readFrontmatterFields({ markdown, yamlReader }) {
|
|
30
45
|
const frontmatter = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
31
46
|
if (!frontmatter)
|
|
32
|
-
throw new SkillInputError({ message:
|
|
47
|
+
throw new SkillInputError({ message: MISSING_FRONTMATTER });
|
|
33
48
|
let fields;
|
|
34
49
|
try {
|
|
35
50
|
fields = yamlReader.read({ yaml: frontmatter[1] });
|
|
36
51
|
}
|
|
37
|
-
catch {
|
|
38
|
-
throw new SkillInputError({ message: "SKILL.md must have valid YAML frontmatter." });
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new SkillInputError({ message: "SKILL.md must have valid YAML frontmatter." }, { cause: error });
|
|
39
54
|
}
|
|
40
|
-
|
|
41
|
-
if (typeof name !== "string" || typeof description !== "string" || !description.trim())
|
|
42
|
-
throw new SkillInputError({ message: "SKILL.md must have YAML frontmatter with a name and description." });
|
|
43
|
-
if (name.length > 64 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))
|
|
44
|
-
throw new SkillInputError({ message: "Skill name must use lowercase letters, digits and single hyphens (1–64 characters)." });
|
|
45
|
-
if (description.length > 1024)
|
|
46
|
-
throw new SkillInputError({ message: "Skill description exceeds 1024 characters." });
|
|
47
|
-
return { name, description: description.replace(/\s+/g, " ").trim() };
|
|
55
|
+
return (fields && typeof fields === "object" ? fields : {});
|
|
48
56
|
}
|
|
49
57
|
/** Validates the whole package before writes, including cross-file collisions and combined limits.
|
|
50
58
|
* @complexity O(total bytes + files × path length), bounded to 8 MiB / 256 files.
|
|
@@ -54,51 +62,76 @@ export function validateSkillFiles({ files: upload, yamlReader }, _optional = {}
|
|
|
54
62
|
throw new SkillInputError({ message: "A skill must contain 1–256 files." });
|
|
55
63
|
for (const file of upload)
|
|
56
64
|
validateSkillPath({ filePath: file.path });
|
|
65
|
+
const prefix = selectSkillFolder({ upload });
|
|
66
|
+
const files = new Map();
|
|
67
|
+
const budget = { total: 0 };
|
|
68
|
+
for (const file of upload) {
|
|
69
|
+
const { relative, bytes } = validateBundleFile({ file, prefix, seen: files, budget });
|
|
70
|
+
files.set(relative, bytes);
|
|
71
|
+
}
|
|
72
|
+
return { ...validateSkillMarkdown({ markdown: files.get("SKILL.md").toString("utf8"), yamlReader }), files };
|
|
73
|
+
}
|
|
74
|
+
/** The folder holding the bundle's only SKILL.md (empty string at the root). */
|
|
75
|
+
function selectSkillFolder({ upload }) {
|
|
57
76
|
const skillFiles = upload.filter(f => f.path === "SKILL.md" || f.path.endsWith("/SKILL.md"));
|
|
58
77
|
if (skillFiles.length !== 1) {
|
|
59
78
|
if (skillFiles.length > 1 && new Set(skillFiles.map(f => f.path)).size === 1)
|
|
60
79
|
throw new SkillInputError({ message: `Duplicate skill file path: ${skillFiles[0].path}` });
|
|
61
80
|
throw new SkillInputError({ message: "Choose one skill folder containing a single SKILL.md." });
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
return skillFiles[0].path.slice(0, -"SKILL.md".length);
|
|
83
|
+
}
|
|
84
|
+
/** Checks one upload's folder, path, location, type, sizes and content; returns its folder-relative key. */
|
|
85
|
+
function validateBundleFile({ file, prefix, seen, budget }) {
|
|
86
|
+
if (!file.path.startsWith(prefix))
|
|
87
|
+
throw new SkillInputError({ message: "All files must belong to the selected skill folder." });
|
|
88
|
+
const relative = file.path.slice(prefix.length);
|
|
89
|
+
validateSkillPath({ filePath: relative });
|
|
90
|
+
if (seen.has(relative))
|
|
91
|
+
throw new SkillInputError({ message: `Duplicate skill file path: ${relative}` });
|
|
92
|
+
const { extension, isText } = classifySkillFile({ relative });
|
|
93
|
+
const bytes = decodeSkillBase64({ value: file.contentBase64 }, { maxBytes: MAX_SKILL_FILE_BYTES });
|
|
94
|
+
if (relative === "SKILL.md" && bytes.length > 128 * 1024)
|
|
95
|
+
throw new SkillInputError({ message: "SKILL.md exceeds 128 KiB." });
|
|
96
|
+
budget.total += bytes.length;
|
|
97
|
+
if (budget.total > MAX_SKILL_BYTES)
|
|
98
|
+
throw new SkillInputError({ message: "Skill files exceed 8 MiB combined." });
|
|
99
|
+
if (isText)
|
|
100
|
+
assertTextContent({ relative, bytes });
|
|
101
|
+
else if (!matchesAssetSignature({ extension, bytes }))
|
|
102
|
+
throw new SkillInputError({ message: `Skill asset content does not match its file type: ${relative}` });
|
|
103
|
+
return { relative, bytes };
|
|
104
|
+
}
|
|
105
|
+
/** Allowed locations are SKILL.md, README.md, LICENSE and the references/scripts/assets folders;
|
|
106
|
+
* text extensions anywhere there, image extensions only under assets/. */
|
|
107
|
+
function classifySkillFile({ relative }) {
|
|
108
|
+
const extension = path.posix.extname(relative).toLowerCase();
|
|
109
|
+
const top = relative.split("/")[0];
|
|
110
|
+
if (!ROOT_FILES.has(relative) && !SKILL_FOLDERS.has(top))
|
|
111
|
+
throw new SkillInputError({ message: `Unsupported skill file location: ${relative}` });
|
|
112
|
+
const isText = relative === "LICENSE" || TEXT_EXTENSIONS.has(extension);
|
|
113
|
+
if (!isText && !(top === "assets" && ASSET_EXTENSIONS.has(extension)))
|
|
114
|
+
throw new SkillInputError({ message: `Unsupported skill file type: ${relative}` });
|
|
115
|
+
return { extension, isText };
|
|
116
|
+
}
|
|
117
|
+
/** Text files must be strict UTF-8 with no NUL bytes. */
|
|
118
|
+
function assertTextContent({ relative, bytes }) {
|
|
119
|
+
const message = `Skill text file must be valid UTF-8 without null bytes: ${relative}`;
|
|
120
|
+
try {
|
|
121
|
+
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
101
122
|
}
|
|
102
|
-
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new SkillInputError({ message }, { cause: error });
|
|
125
|
+
}
|
|
126
|
+
if (bytes.includes(0))
|
|
127
|
+
throw new SkillInputError({ message });
|
|
128
|
+
}
|
|
129
|
+
/** Magic-byte sniffing for the allowed image types (.png, .webp, otherwise JPEG). */
|
|
130
|
+
function matchesAssetSignature({ extension, bytes }) {
|
|
131
|
+
if (extension === ".png")
|
|
132
|
+
return bytes.subarray(0, 8).equals(PNG_SIGNATURE);
|
|
133
|
+
if (extension === ".webp")
|
|
134
|
+
return bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP";
|
|
135
|
+
return bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
|
|
103
136
|
}
|
|
104
137
|
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ArchiveReaderPort } from "./ports.js";
|
|
2
|
+
interface ZipEntry {
|
|
3
|
+
fileName: string;
|
|
4
|
+
uncompressedSize: number;
|
|
5
|
+
externalFileAttributes: number;
|
|
6
|
+
}
|
|
7
|
+
interface ZipFile {
|
|
8
|
+
eachEntry(): AsyncIterable<ZipEntry>;
|
|
9
|
+
openReadStreamPromise(entry: ZipEntry): Promise<AsyncIterable<Uint8Array> & {
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}>;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
|
14
|
+
export interface SkillZipSdkPort {
|
|
15
|
+
fromBufferPromise(bytes: Buffer, options: {
|
|
16
|
+
lazyEntries: boolean;
|
|
17
|
+
strictFileNames: boolean;
|
|
18
|
+
validateEntrySizes: boolean;
|
|
19
|
+
}): Promise<ZipFile>;
|
|
20
|
+
}
|
|
21
|
+
/** Bind the installed ZIP library, preserving strict filenames and regular-file-only semantics.
|
|
22
|
+
* Unlike executable plugin archives, skill scripts are inert data and every non-regular mode is
|
|
23
|
+
* refused regardless of the ZIP producer's platform marker.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createYauzlSkillArchiveReader({ yauzl }: {
|
|
26
|
+
yauzl: SkillZipSdkPort;
|
|
27
|
+
}, _optional?: {}): ArchiveReaderPort;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=yauzl-archive-reader.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Bind the installed ZIP library, preserving strict filenames and regular-file-only semantics.
|
|
2
|
+
* Unlike executable plugin archives, skill scripts are inert data and every non-regular mode is
|
|
3
|
+
* refused regardless of the ZIP producer's platform marker.
|
|
4
|
+
*/
|
|
5
|
+
export function createYauzlSkillArchiveReader({ yauzl }, _optional = {}) {
|
|
6
|
+
return { async open({ bytes }) {
|
|
7
|
+
const zip = await yauzl.fromBufferPromise(Buffer.from(bytes), { lazyEntries: true, strictFileNames: true, validateEntrySizes: true });
|
|
8
|
+
return {
|
|
9
|
+
entries: (async function* () {
|
|
10
|
+
for await (const entry of zip.eachEntry()) {
|
|
11
|
+
const type = (entry.externalFileAttributes >>> 16) & 0xf000;
|
|
12
|
+
const kind = type && type !== 0x8000 && type !== 0x4000 ? "other" : entry.fileName.endsWith("/") ? "directory" : "file";
|
|
13
|
+
yield { path: entry.fileName, size: entry.uncompressedSize, kind,
|
|
14
|
+
async *read() {
|
|
15
|
+
const stream = await zip.openReadStreamPromise(entry);
|
|
16
|
+
try {
|
|
17
|
+
for await (const chunk of stream)
|
|
18
|
+
yield chunk;
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
stream.destroy();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
})(),
|
|
27
|
+
close: () => zip.close(),
|
|
28
|
+
};
|
|
29
|
+
} };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=yauzl-archive-reader.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/agentic",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Framework-free agent-control layer: page-capability vocabulary and manifests, the data-agent-* markup convention, AG-UI projection, generative-UI streams, and A2UI.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"jsdom": "^25.0.1",
|
|
78
78
|
"zod": "^3.25.76",
|
|
79
79
|
"@jini-ai/core": "^0.4.0",
|
|
80
|
-
"@jini-ai/protocol": "^0.4.
|
|
80
|
+
"@jini-ai/protocol": "^0.4.5"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@jini-ai/protocol": "^0.4.
|
|
83
|
+
"@jini-ai/protocol": "^0.4.4",
|
|
84
84
|
"zod": "^3.25.76",
|
|
85
|
-
"@jini-ai/core": "^0.4.
|
|
85
|
+
"@jini-ai/core": "^0.4.3"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|
|
88
88
|
"@jini-ai/protocol": {
|