@engenty/wizards-runtime 0.12.1 → 0.13.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/apps/runtime/dist/agents/studio-assistant.js +42 -5
- package/apps/runtime/dist/app.js +15 -4
- package/apps/runtime/dist/credits/estimate.js +3 -3
- package/apps/runtime/dist/db/live-triggers.js +13 -3
- package/apps/runtime/dist/db/migrations/tenant/0027_space_skill.sql +48 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +4120 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +31 -0
- package/apps/runtime/dist/docs/dev/skills.md +116 -0
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +20 -2
- package/apps/runtime/dist/docs/user-guide/models.md +105 -30
- package/apps/runtime/dist/docs/user-guide/skills.md +85 -0
- package/apps/runtime/dist/docs/user-guide/together.md +15 -2
- package/apps/runtime/dist/engine/decide.js +1 -1
- package/apps/runtime/dist/engine/requirements.js +139 -11
- package/apps/runtime/dist/engine/runner.js +47 -5
- package/apps/runtime/dist/engine/steps.js +23 -6
- package/apps/runtime/dist/engine/template.js +17 -0
- package/apps/runtime/dist/harness/model.js +4 -0
- package/apps/runtime/dist/link-preview.js +9 -0
- package/apps/runtime/dist/live/views.js +2 -0
- package/apps/runtime/dist/manage.js +25 -0
- package/apps/runtime/dist/mcp/handler.js +55 -1
- package/apps/runtime/dist/mcp/seen.js +47 -0
- package/apps/runtime/dist/models.js +206 -11
- package/apps/runtime/dist/motion-graphics/step.js +2 -2
- package/apps/runtime/dist/prompts/goose.md +15 -7
- package/apps/runtime/dist/prompts/safety.md +18 -0
- package/apps/runtime/dist/prompts/step.md +20 -2
- package/apps/runtime/dist/prompts/tools.md +33 -0
- package/apps/runtime/dist/routes/marketplace.js +3 -3
- package/apps/runtime/dist/routes/runs.js +5 -0
- package/apps/runtime/dist/routes/skills.js +84 -0
- package/apps/runtime/dist/routes/studio.js +103 -4
- package/apps/runtime/dist/safety.js +60 -18
- package/apps/runtime/dist/services/manage-reports.js +3 -0
- package/apps/runtime/dist/services/marketplace.js +7 -31
- package/apps/runtime/dist/services/pages.js +6 -2
- package/apps/runtime/dist/services/shares.js +5 -0
- package/apps/runtime/dist/services/skills-registry.js +209 -0
- package/apps/runtime/dist/services/skills.js +478 -0
- package/apps/runtime/dist/services/spaces.js +15 -1
- package/apps/runtime/dist/sync/records.js +81 -1
- package/apps/runtime/dist/texts.js +45 -0
- package/apps/runtime/dist/tools/index.js +7 -4
- package/apps/runtime/dist/tools/net-guard.js +8 -4
- package/apps/runtime/dist/tools/skills.js +197 -0
- package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-BWaEdlt3.js → ChangelogDialog-SwyId00t.js} +1 -1
- package/apps/web/dist/assets/CodeEditor-BwZsk5Al.js +2 -0
- package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DXpzFBRj.js → FlowPreview-DtSpjVTl.js} +1 -1
- package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-B5wuTm7J.js → NewWizardChannels-Tgoexgj4.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-B24AF482.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +1 -0
- package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +10 -0
- package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +10 -0
- package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-Cap_e5ke.js → ReadOnly-BXjv-MSv.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +2 -0
- package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +1 -0
- package/apps/web/dist/assets/{SharePage-DEeVGatD.js → SharePage-DXGzJSnR.js} +1 -1
- package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +1 -0
- package/apps/web/dist/assets/changelog-BLdS-0Bj.js +1 -0
- package/apps/web/dist/assets/code-xml-TwKzzMtA.js +1 -0
- package/apps/web/dist/assets/{dist-BwhPmMDu.js → dist-BdDd1FxP.js} +1 -1
- package/apps/web/dist/assets/dist-EBVTpvRr.js +10 -0
- package/apps/web/dist/assets/dist-GlRRx9Xl.js +1 -0
- package/apps/web/dist/assets/dist-H1UN89OA.js +1 -0
- package/apps/web/dist/assets/eye-Brd-xPUJ.js +1 -0
- package/apps/web/dist/assets/i18n-8-Sw11tB.js +55 -0
- package/apps/web/dist/assets/index-OsdQFHmh.js +49 -0
- package/apps/web/dist/assets/index-QPipX5Fi.css +1 -0
- package/apps/web/dist/assets/json-CEsfHdlZ.js +1 -0
- package/apps/web/dist/assets/{lock-D-CjMpqn.js → lock-C0uxcOlq.js} +1 -1
- package/apps/web/dist/assets/markdown-5-I9_izp.js +29 -0
- package/apps/web/dist/assets/{oss-credits-CUpVhKSr.js → oss-credits-DpRWUPjD.js} +1 -1
- package/apps/web/dist/assets/{phone-CXSrxw3H.js → phone-DhkHteoJ.js} +1 -1
- package/apps/web/dist/assets/{runners-D71NjXtA.js → runners-G-XYaDgR.js} +1 -1
- package/apps/web/dist/assets/{session-B2LtqeDq.js → session-BWI-KENJ.js} +1 -1
- package/apps/web/dist/assets/theme-D7krsx0_.js +11 -0
- package/apps/web/dist/assets/ui-DSXG3f49.js +83 -0
- package/apps/web/dist/assets/{upload-hLkuT3Q6.js → upload-BYZTwJTD.js} +1 -1
- package/apps/web/dist/assets/{useMutation-C3XBoSVf.js → useMutation-D0QP_k2-.js} +1 -1
- package/apps/web/dist/assets/{volume-2-DIxdTlaA.js → volume-2-CVHoxdGM.js} +1 -1
- package/apps/web/dist/index.html +9 -8
- package/apps/web/dist/mcp/flow.html +66 -66
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +3 -2
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +1 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +5 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +107 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.js +67 -4
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +18 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +18 -0
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +0 -5
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +62 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +52 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +165 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.js +346 -0
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +4 -2
- package/node_modules/@engenty/wizards-shared/dist/sync.js +2 -1
- package/node_modules/@engenty/wizards-shared/dist/tiers.d.ts +195 -0
- package/node_modules/@engenty/wizards-shared/dist/tiers.js +98 -0
- package/package.json +7 -7
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/AboutDialog-uGYGy2R2.js +0 -1
- package/apps/web/dist/assets/CodeEditor-B5hV1IvK.js +0 -2
- package/apps/web/dist/assets/EditorPage-j9BOx5-V.js +0 -3
- package/apps/web/dist/assets/Marketplace-DSo6uZF6.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-Ci1ZsTJk.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-QkdluEZk.js +0 -1
- package/apps/web/dist/assets/PreviewPane-swAH89un.js +0 -10
- package/apps/web/dist/assets/ProjectPage-Djv5EOYU.js +0 -1
- package/apps/web/dist/assets/PublicRunner-Bt8gMxit.js +0 -1
- package/apps/web/dist/assets/SettingsPage-C2rmXm_Q.js +0 -2
- package/apps/web/dist/assets/SetupPage-CbqGgFPZ.js +0 -1
- package/apps/web/dist/assets/changelog-DAY6ZEyy.js +0 -1
- package/apps/web/dist/assets/dist-DVpDdhG9.js +0 -1
- package/apps/web/dist/assets/dist-DzdNG7Sf.js +0 -10
- package/apps/web/dist/assets/i18n-B3J2ypKu.js +0 -55
- package/apps/web/dist/assets/index-Dxwbli0m.css +0 -1
- package/apps/web/dist/assets/index-WY5lJ_-h.js +0 -49
- package/apps/web/dist/assets/json-D2GVvTXK.js +0 -1
- package/apps/web/dist/assets/markdown-DwdMW7q0.js +0 -29
- package/apps/web/dist/assets/theme-Dab079EV.js +0 -11
- package/apps/web/dist/assets/ui-DQX_CQ7c.js +0 -83
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { featureOn } from "@engenty/wizards-shared/features";
|
|
3
|
+
import { byteLength, officialSkill, parseSkillMd, SKILL_LIMITS, SKILL_NAME, SkillMdError, skillMd, skillPathOk, skillTextPath, } from "@engenty/wizards-shared/skills";
|
|
4
|
+
import { and, asc, count, eq, ne } from "drizzle-orm";
|
|
5
|
+
import { unzipSync, zipSync } from "fflate";
|
|
6
|
+
import { nanoid } from "nanoid";
|
|
7
|
+
import { db, schema } from "../db/client.js";
|
|
8
|
+
import { currentFeatures } from "../features.js";
|
|
9
|
+
import { getBlob, putBlob } from "../files/blobs.js";
|
|
10
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
11
|
+
import { projectWritable, requireWritableProject } from "./access.js";
|
|
12
|
+
import { notFound, ServiceError } from "./errors.js";
|
|
13
|
+
import { ownedProject } from "./projects.js";
|
|
14
|
+
const refuse = (server, params) => new ServiceError("invalid", { server, params });
|
|
15
|
+
export async function skillsOn() {
|
|
16
|
+
return featureOn(await currentFeatures(), "skills");
|
|
17
|
+
}
|
|
18
|
+
/** Skills are behind their switch: while it is off, they are not there. */
|
|
19
|
+
export async function requireSkills() {
|
|
20
|
+
if (!(await skillsOn())) {
|
|
21
|
+
throw notFound();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// --- checks ---------------------------------------------------------------------------------
|
|
25
|
+
const MD_ERRORS = {
|
|
26
|
+
frontmatter: "skillMdFrontmatter",
|
|
27
|
+
name: "skillMdName",
|
|
28
|
+
description: "skillMdDescription",
|
|
29
|
+
};
|
|
30
|
+
/** A `SKILL.md` read, its failure said in the person's words. */
|
|
31
|
+
export function readSkillMd(text) {
|
|
32
|
+
try {
|
|
33
|
+
return parseSkillMd(text);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof SkillMdError) {
|
|
37
|
+
throw refuse(MD_ERRORS[err.problem]);
|
|
38
|
+
}
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The bytes of a skill's text: its `SKILL.md` and its text files. */
|
|
43
|
+
export function skillBytes(c) {
|
|
44
|
+
return byteLength(skillMd(c)) + c.files.reduce((n, f) => n + byteLength(f.text), 0);
|
|
45
|
+
}
|
|
46
|
+
/** The bytes of a skill's files for scripts. */
|
|
47
|
+
export const blobBytes = (files) => files.reduce((n, f) => n + f.bytes, 0);
|
|
48
|
+
/** What a skill may be: a name of the format, a description, files within the limits. */
|
|
49
|
+
export function checkContent(c) {
|
|
50
|
+
const name = c.name.trim();
|
|
51
|
+
const description = c.description.replace(/\s+/g, " ").trim();
|
|
52
|
+
if (name.length > SKILL_LIMITS.name || !SKILL_NAME.test(name)) {
|
|
53
|
+
throw refuse("skillName");
|
|
54
|
+
}
|
|
55
|
+
if (!description || description.length > SKILL_LIMITS.description) {
|
|
56
|
+
throw refuse("skillDescription");
|
|
57
|
+
}
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
for (const f of c.files) {
|
|
60
|
+
if (!skillPathOk(f.path) || f.path === "SKILL.md" || seen.has(f.path)) {
|
|
61
|
+
throw refuse("skillFilePath", { path: f.path.slice(0, 120) });
|
|
62
|
+
}
|
|
63
|
+
if (!skillTextPath(f.path)) {
|
|
64
|
+
throw refuse("skillFileText", { path: f.path });
|
|
65
|
+
}
|
|
66
|
+
seen.add(f.path);
|
|
67
|
+
}
|
|
68
|
+
for (const f of c.blobFiles) {
|
|
69
|
+
if (!skillPathOk(f.path) || f.path === "SKILL.md" || seen.has(f.path)) {
|
|
70
|
+
throw refuse("skillFilePath", { path: f.path.slice(0, 120) });
|
|
71
|
+
}
|
|
72
|
+
seen.add(f.path);
|
|
73
|
+
}
|
|
74
|
+
const out = { ...c, name, description };
|
|
75
|
+
if (byteLength(skillMd(out)) > SKILL_LIMITS.skillMd ||
|
|
76
|
+
c.files.length > SKILL_LIMITS.files ||
|
|
77
|
+
c.files.some((f) => byteLength(f.text) > SKILL_LIMITS.file) ||
|
|
78
|
+
skillBytes(out) > SKILL_LIMITS.total ||
|
|
79
|
+
c.blobFiles.length > SKILL_LIMITS.blobFiles ||
|
|
80
|
+
c.blobFiles.some((f) => f.bytes > SKILL_LIMITS.blobFile) ||
|
|
81
|
+
blobBytes(c.blobFiles) > SKILL_LIMITS.blobTotal) {
|
|
82
|
+
throw refuse("skillTooLarge");
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
async function nameTaken(projectId, name, except) {
|
|
87
|
+
const row = await db.query.spaceSkill.findFirst({
|
|
88
|
+
where: and(eq(schema.spaceSkill.projectId, projectId), eq(schema.spaceSkill.name, name), ...(except ? [ne(schema.spaceSkill.id, except)] : [])),
|
|
89
|
+
columns: { id: true },
|
|
90
|
+
});
|
|
91
|
+
return Boolean(row);
|
|
92
|
+
}
|
|
93
|
+
/** A name not yet taken in the space: the name itself, else with `-2`, `-3` … */
|
|
94
|
+
async function freeName(projectId, name) {
|
|
95
|
+
if (!(await nameTaken(projectId, name))) {
|
|
96
|
+
return name;
|
|
97
|
+
}
|
|
98
|
+
for (let n = 2; n < 1000; n++) {
|
|
99
|
+
const suffix = `-${n}`;
|
|
100
|
+
const next = `${name.slice(0, SKILL_LIMITS.name - suffix.length).replace(/-+$/, "")}${suffix}`;
|
|
101
|
+
if (!(await nameTaken(projectId, next))) {
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return `${name.slice(0, SKILL_LIMITS.name - 9)}-${nanoid(8)
|
|
106
|
+
.toLowerCase()
|
|
107
|
+
.replace(/[^a-z0-9]/g, "x")}`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* At most five skills always on, their instructions 20,000 characters together: each of them
|
|
111
|
+
* is in every AI step of the space.
|
|
112
|
+
*/
|
|
113
|
+
export async function checkAlways(projectId, id, mode, body) {
|
|
114
|
+
if (mode !== "always") {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const others = await db
|
|
118
|
+
.select({ id: schema.spaceSkill.id, body: schema.spaceSkill.body })
|
|
119
|
+
.from(schema.spaceSkill)
|
|
120
|
+
.where(and(eq(schema.spaceSkill.projectId, projectId), eq(schema.spaceSkill.mode, "always")));
|
|
121
|
+
const rest = others.filter((o) => o.id !== id);
|
|
122
|
+
if (rest.length + 1 > SKILL_LIMITS.always) {
|
|
123
|
+
throw refuse("skillsAlwaysCount");
|
|
124
|
+
}
|
|
125
|
+
const chars = rest.reduce((n, o) => n + o.body.length, 0) + body.length;
|
|
126
|
+
if (chars > SKILL_LIMITS.alwaysChars) {
|
|
127
|
+
throw refuse("skillsAlwaysChars", { n: chars.toLocaleString("en") });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// --- views ----------------------------------------------------------------------------------
|
|
131
|
+
function summaryOf(row) {
|
|
132
|
+
return {
|
|
133
|
+
id: row.id,
|
|
134
|
+
name: row.name,
|
|
135
|
+
description: row.description,
|
|
136
|
+
mode: row.mode,
|
|
137
|
+
source: row.source,
|
|
138
|
+
origin: row.origin,
|
|
139
|
+
official: row.source === "skills.sh" && officialSkill(row.origin),
|
|
140
|
+
runScripts: row.runScripts,
|
|
141
|
+
files: row.files.length + row.blobFiles.length,
|
|
142
|
+
chars: row.body.length,
|
|
143
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export async function skillRow(id) {
|
|
147
|
+
const row = await db.query.spaceSkill.findFirst({
|
|
148
|
+
where: and(eq(schema.spaceSkill.id, id), eq(schema.spaceSkill.tenantId, currentTenant())),
|
|
149
|
+
});
|
|
150
|
+
if (!row) {
|
|
151
|
+
throw notFound();
|
|
152
|
+
}
|
|
153
|
+
return row;
|
|
154
|
+
}
|
|
155
|
+
export async function listSkills(userId, projectId) {
|
|
156
|
+
await requireSkills();
|
|
157
|
+
const project = await ownedProject(userId, projectId);
|
|
158
|
+
const rows = await db.query.spaceSkill.findMany({
|
|
159
|
+
where: eq(schema.spaceSkill.projectId, project.id),
|
|
160
|
+
orderBy: [asc(schema.spaceSkill.name)],
|
|
161
|
+
});
|
|
162
|
+
return { skills: rows.map(summaryOf), readOnly: !(await projectWritable(project)) };
|
|
163
|
+
}
|
|
164
|
+
export async function getSkill(userId, id) {
|
|
165
|
+
await requireSkills();
|
|
166
|
+
const row = await skillRow(id);
|
|
167
|
+
const project = await ownedProject(userId, row.projectId);
|
|
168
|
+
return {
|
|
169
|
+
...summaryOf(row),
|
|
170
|
+
projectId: row.projectId,
|
|
171
|
+
body: row.body,
|
|
172
|
+
meta: row.meta,
|
|
173
|
+
fileList: row.files,
|
|
174
|
+
blobList: row.blobFiles,
|
|
175
|
+
originHash: row.originHash,
|
|
176
|
+
readOnly: !(await projectWritable(project)),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// --- writes ---------------------------------------------------------------------------------
|
|
180
|
+
/** The hash of a skill's content, as skills.sh had it: an update is offered when it differs. */
|
|
181
|
+
export function contentHash(c) {
|
|
182
|
+
const files = [...c.files].sort((a, b) => a.path.localeCompare(b.path));
|
|
183
|
+
const blobs = [...c.blobFiles].sort((a, b) => a.path.localeCompare(b.path));
|
|
184
|
+
return createHash("sha256")
|
|
185
|
+
.update(JSON.stringify([
|
|
186
|
+
skillMd(c),
|
|
187
|
+
files.map((f) => [f.path, f.text]),
|
|
188
|
+
...(blobs.length ? [blobs.map((f) => [f.path, f.hash])] : []),
|
|
189
|
+
]))
|
|
190
|
+
.digest("hex");
|
|
191
|
+
}
|
|
192
|
+
/** Keeps the bytes of a skill's files for scripts, before the skill that names them is written. */
|
|
193
|
+
export async function keepBlobs(blobs) {
|
|
194
|
+
for (const data of blobs) {
|
|
195
|
+
await putBlob(data);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** Puts a new skill into the space; its name is the one given, or the next free one. */
|
|
199
|
+
export async function insertSkill(projectId, content, options) {
|
|
200
|
+
const checked = checkContent(content);
|
|
201
|
+
const [{ n }] = await db
|
|
202
|
+
.select({ n: count() })
|
|
203
|
+
.from(schema.spaceSkill)
|
|
204
|
+
.where(eq(schema.spaceSkill.projectId, projectId));
|
|
205
|
+
if (n >= SKILL_LIMITS.perSpace) {
|
|
206
|
+
throw refuse("skillsTooMany");
|
|
207
|
+
}
|
|
208
|
+
const name = options.rename ? await freeName(projectId, checked.name) : checked.name;
|
|
209
|
+
if (!options.rename && (await nameTaken(projectId, name))) {
|
|
210
|
+
throw refuse("skillNameTaken", { name });
|
|
211
|
+
}
|
|
212
|
+
const mode = options.mode ?? "demand";
|
|
213
|
+
await checkAlways(projectId, null, mode, checked.body);
|
|
214
|
+
const id = nanoid(12);
|
|
215
|
+
await db.insert(schema.spaceSkill).values({
|
|
216
|
+
id,
|
|
217
|
+
tenantId: currentTenant(),
|
|
218
|
+
projectId,
|
|
219
|
+
name,
|
|
220
|
+
description: checked.description,
|
|
221
|
+
body: checked.body,
|
|
222
|
+
meta: checked.meta,
|
|
223
|
+
files: checked.files,
|
|
224
|
+
blobFiles: checked.blobFiles,
|
|
225
|
+
mode,
|
|
226
|
+
source: options.source,
|
|
227
|
+
origin: options.origin ?? null,
|
|
228
|
+
originHash: options.originHash ?? null,
|
|
229
|
+
});
|
|
230
|
+
return { id, name };
|
|
231
|
+
}
|
|
232
|
+
/** A skill written in the studio: a name, a description and a first heading. */
|
|
233
|
+
export async function createSkill(userId, projectId, input) {
|
|
234
|
+
await requireSkills();
|
|
235
|
+
const project = await ownedProject(userId, projectId);
|
|
236
|
+
await requireWritableProject(project.id);
|
|
237
|
+
return insertSkill(project.id, {
|
|
238
|
+
name: input.name,
|
|
239
|
+
description: input.description,
|
|
240
|
+
body: input.body ?? "",
|
|
241
|
+
meta: {},
|
|
242
|
+
files: [],
|
|
243
|
+
blobFiles: [],
|
|
244
|
+
}, { source: "own", mode: input.mode, rename: true });
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Changes a skill: when it counts and whether its scripts run, always; its content only when it
|
|
248
|
+
* is the space's own, since one from skills.sh stays as it came (an update replaces it whole).
|
|
249
|
+
*/
|
|
250
|
+
export async function updateSkill(userId, id, patch) {
|
|
251
|
+
await requireSkills();
|
|
252
|
+
const row = await skillRow(id);
|
|
253
|
+
await ownedProject(userId, row.projectId);
|
|
254
|
+
await requireWritableProject(row.projectId);
|
|
255
|
+
const content = { ...patch };
|
|
256
|
+
if (patch.skillMd !== undefined) {
|
|
257
|
+
Object.assign(content, readSkillMd(patch.skillMd));
|
|
258
|
+
}
|
|
259
|
+
const touches = ["name", "description", "body", "meta", "files"].some((k) => content[k] !== undefined);
|
|
260
|
+
if (touches && row.source === "skills.sh") {
|
|
261
|
+
throw refuse("skillReadOnly");
|
|
262
|
+
}
|
|
263
|
+
const next = checkContent({
|
|
264
|
+
name: content.name ?? row.name,
|
|
265
|
+
description: content.description ?? row.description,
|
|
266
|
+
body: content.body ?? row.body,
|
|
267
|
+
meta: content.meta ?? row.meta,
|
|
268
|
+
files: content.files ?? row.files,
|
|
269
|
+
blobFiles: row.blobFiles,
|
|
270
|
+
});
|
|
271
|
+
if (next.name !== row.name && (await nameTaken(row.projectId, next.name, row.id))) {
|
|
272
|
+
throw refuse("skillNameTaken", { name: next.name });
|
|
273
|
+
}
|
|
274
|
+
const mode = patch.mode ?? row.mode;
|
|
275
|
+
await checkAlways(row.projectId, row.id, mode, next.body);
|
|
276
|
+
await db
|
|
277
|
+
.update(schema.spaceSkill)
|
|
278
|
+
.set({ ...next, mode, runScripts: patch.runScripts ?? row.runScripts, updatedAt: new Date() })
|
|
279
|
+
.where(eq(schema.spaceSkill.id, row.id));
|
|
280
|
+
return { updatedAt: new Date().toISOString() };
|
|
281
|
+
}
|
|
282
|
+
export async function deleteSkill(userId, id) {
|
|
283
|
+
await requireSkills();
|
|
284
|
+
const row = await skillRow(id);
|
|
285
|
+
await ownedProject(userId, row.projectId);
|
|
286
|
+
await requireWritableProject(row.projectId);
|
|
287
|
+
await db.delete(schema.spaceSkill).where(eq(schema.spaceSkill.id, row.id));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A skill as the space's own: a copy to change, on demand until someone switches it on, its
|
|
291
|
+
* scripts off until someone switches them on for the copy.
|
|
292
|
+
*/
|
|
293
|
+
export async function copySkill(userId, id) {
|
|
294
|
+
await requireSkills();
|
|
295
|
+
const row = await skillRow(id);
|
|
296
|
+
await ownedProject(userId, row.projectId);
|
|
297
|
+
await requireWritableProject(row.projectId);
|
|
298
|
+
return insertSkill(row.projectId, {
|
|
299
|
+
name: row.name,
|
|
300
|
+
description: row.description,
|
|
301
|
+
body: row.body,
|
|
302
|
+
meta: row.meta,
|
|
303
|
+
files: row.files,
|
|
304
|
+
blobFiles: row.blobFiles,
|
|
305
|
+
}, { source: "own", mode: row.mode === "always" ? "demand" : row.mode, rename: true });
|
|
306
|
+
}
|
|
307
|
+
// --- files: a SKILL.md, a zip ---------------------------------------------------------------
|
|
308
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
309
|
+
/** Bytes as text, or null when they are not text: not UTF-8, or a NUL among them. */
|
|
310
|
+
export function asText(data) {
|
|
311
|
+
try {
|
|
312
|
+
const text = utf8.decode(data);
|
|
313
|
+
return text.includes("\u0000") ? null : text.replace(/^/, "");
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* The files of a skill's folder as the space keeps them: its `SKILL.md` read; text a model reads
|
|
321
|
+
* in the skill's row while it fits; any other file, and text beyond what fits, as a file for
|
|
322
|
+
* scripts (bytes for the blob store); the rest named as left out.
|
|
323
|
+
*/
|
|
324
|
+
export function contentOf(entries) {
|
|
325
|
+
const md = entries.find((e) => e.path === "SKILL.md");
|
|
326
|
+
if (!md || md.text === null) {
|
|
327
|
+
throw refuse("skillNoSkillMd");
|
|
328
|
+
}
|
|
329
|
+
const parsed = readSkillMd(md.text);
|
|
330
|
+
const files = [];
|
|
331
|
+
const blobFiles = [];
|
|
332
|
+
const blobs = [];
|
|
333
|
+
const skipped = [];
|
|
334
|
+
let textBytes = byteLength(skillMd(parsed));
|
|
335
|
+
let blobTotal = 0;
|
|
336
|
+
for (const e of entries) {
|
|
337
|
+
if (e.path === "SKILL.md") {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const bytes = e.data?.length ?? 0;
|
|
341
|
+
if (!skillPathOk(e.path)) {
|
|
342
|
+
skipped.push({ path: e.path, reason: "path" });
|
|
343
|
+
}
|
|
344
|
+
else if (e.text !== null &&
|
|
345
|
+
skillTextPath(e.path) &&
|
|
346
|
+
bytes <= SKILL_LIMITS.file &&
|
|
347
|
+
files.length < SKILL_LIMITS.files &&
|
|
348
|
+
textBytes + bytes <= SKILL_LIMITS.total) {
|
|
349
|
+
files.push({ path: e.path, text: e.text });
|
|
350
|
+
textBytes += bytes;
|
|
351
|
+
}
|
|
352
|
+
else if (e.data === null) {
|
|
353
|
+
skipped.push({ path: e.path, reason: "binary" });
|
|
354
|
+
}
|
|
355
|
+
else if (bytes > SKILL_LIMITS.blobFile || blobTotal + bytes > SKILL_LIMITS.blobTotal) {
|
|
356
|
+
skipped.push({ path: e.path, reason: "size" });
|
|
357
|
+
}
|
|
358
|
+
else if (blobFiles.length >= SKILL_LIMITS.blobFiles) {
|
|
359
|
+
skipped.push({ path: e.path, reason: "count" });
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
blobFiles.push({
|
|
363
|
+
path: e.path,
|
|
364
|
+
hash: createHash("sha256").update(e.data).digest("hex"),
|
|
365
|
+
bytes,
|
|
366
|
+
});
|
|
367
|
+
blobs.push(e.data);
|
|
368
|
+
blobTotal += bytes;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
372
|
+
blobFiles.sort((a, b) => a.path.localeCompare(b.path));
|
|
373
|
+
return { content: { ...parsed, files, blobFiles }, skipped, blobs };
|
|
374
|
+
}
|
|
375
|
+
/** Never unpacked: more than this many entries, or an entry larger than a file for scripts. */
|
|
376
|
+
const ZIP_ENTRIES = 500;
|
|
377
|
+
/**
|
|
378
|
+
* A skill from an uploaded zip (a `.skill` is one too): the folder of its shallowest `SKILL.md`,
|
|
379
|
+
* paths taken relative to it. Hidden files and the Mac's resource forks stay out.
|
|
380
|
+
*/
|
|
381
|
+
export function unpackSkill(data) {
|
|
382
|
+
let seen = 0;
|
|
383
|
+
let entries;
|
|
384
|
+
try {
|
|
385
|
+
entries = unzipSync(data, {
|
|
386
|
+
filter: (f) => {
|
|
387
|
+
seen++;
|
|
388
|
+
return (seen <= ZIP_ENTRIES && f.originalSize <= SKILL_LIMITS.blobFile && !f.name.endsWith("/"));
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
throw refuse("skillUploadKind");
|
|
394
|
+
}
|
|
395
|
+
const paths = Object.keys(entries).filter((p) => !p.split("/").some((part) => part.startsWith(".") || part === "__MACOSX"));
|
|
396
|
+
const md = paths
|
|
397
|
+
.filter((p) => p === "SKILL.md" || p.endsWith("/SKILL.md"))
|
|
398
|
+
.sort((a, b) => a.split("/").length - b.split("/").length)[0];
|
|
399
|
+
if (!md) {
|
|
400
|
+
throw refuse("skillNoSkillMd");
|
|
401
|
+
}
|
|
402
|
+
const root = md.slice(0, -"SKILL.md".length);
|
|
403
|
+
return contentOf(paths
|
|
404
|
+
.filter((p) => p.startsWith(root))
|
|
405
|
+
.map((p) => ({
|
|
406
|
+
path: p.slice(root.length),
|
|
407
|
+
text: asText(entries[p]),
|
|
408
|
+
data: entries[p],
|
|
409
|
+
})));
|
|
410
|
+
}
|
|
411
|
+
/** An uploaded `SKILL.md`, `.zip` or `.skill`, as a skill of the space. */
|
|
412
|
+
export async function uploadSkill(userId, projectId, file) {
|
|
413
|
+
await requireSkills();
|
|
414
|
+
const project = await ownedProject(userId, projectId);
|
|
415
|
+
await requireWritableProject(project.id);
|
|
416
|
+
const lower = file.name.toLowerCase();
|
|
417
|
+
let read;
|
|
418
|
+
if (lower.endsWith(".zip") || lower.endsWith(".skill")) {
|
|
419
|
+
read = unpackSkill(file.data);
|
|
420
|
+
}
|
|
421
|
+
else if (lower.endsWith(".md")) {
|
|
422
|
+
const text = asText(file.data);
|
|
423
|
+
if (text === null) {
|
|
424
|
+
throw refuse("skillUploadKind");
|
|
425
|
+
}
|
|
426
|
+
read = { content: { ...readSkillMd(text), files: [], blobFiles: [] }, skipped: [], blobs: [] };
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
throw refuse("skillUploadKind");
|
|
430
|
+
}
|
|
431
|
+
await keepBlobs(read.blobs);
|
|
432
|
+
const made = await insertSkill(project.id, read.content, { source: "upload", rename: true });
|
|
433
|
+
return { ...made, skipped: read.skipped };
|
|
434
|
+
}
|
|
435
|
+
/** A skill as a zip: its folder, named by the skill, as other tools take it. */
|
|
436
|
+
export async function skillZip(userId, id) {
|
|
437
|
+
await requireSkills();
|
|
438
|
+
const row = await skillRow(id);
|
|
439
|
+
await ownedProject(userId, row.projectId);
|
|
440
|
+
const enc = new TextEncoder();
|
|
441
|
+
const files = {
|
|
442
|
+
[`${row.name}/SKILL.md`]: enc.encode(skillMd(row)),
|
|
443
|
+
};
|
|
444
|
+
for (const f of row.files) {
|
|
445
|
+
files[`${row.name}/${f.path}`] = enc.encode(f.text);
|
|
446
|
+
}
|
|
447
|
+
for (const f of row.blobFiles) {
|
|
448
|
+
files[`${row.name}/${f.path}`] = new Uint8Array(await getBlob(f.hash));
|
|
449
|
+
}
|
|
450
|
+
return { name: `${row.name}.zip`, data: zipSync(files, { level: 6 }) };
|
|
451
|
+
}
|
|
452
|
+
// --- for steps and Goose ----------------------------------------------------------------------
|
|
453
|
+
/** Every skill of the space, off ones too, by name: what Goose is told the space has. */
|
|
454
|
+
export async function skillList(projectId) {
|
|
455
|
+
return db
|
|
456
|
+
.select({
|
|
457
|
+
name: schema.spaceSkill.name,
|
|
458
|
+
description: schema.spaceSkill.description,
|
|
459
|
+
mode: schema.spaceSkill.mode,
|
|
460
|
+
})
|
|
461
|
+
.from(schema.spaceSkill)
|
|
462
|
+
.where(eq(schema.spaceSkill.projectId, projectId))
|
|
463
|
+
.orderBy(asc(schema.spaceSkill.name));
|
|
464
|
+
}
|
|
465
|
+
/** The space's skills that count, by mode: none while the switch is off. */
|
|
466
|
+
export async function activeSkills(projectId) {
|
|
467
|
+
if (!(await skillsOn())) {
|
|
468
|
+
return { always: [], demand: [] };
|
|
469
|
+
}
|
|
470
|
+
const rows = await db.query.spaceSkill.findMany({
|
|
471
|
+
where: and(eq(schema.spaceSkill.projectId, projectId), ne(schema.spaceSkill.mode, "off")),
|
|
472
|
+
orderBy: [asc(schema.spaceSkill.name)],
|
|
473
|
+
});
|
|
474
|
+
return {
|
|
475
|
+
always: rows.filter((r) => r.mode === "always"),
|
|
476
|
+
demand: rows.filter((r) => r.mode === "demand").slice(0, SKILL_LIMITS.listed),
|
|
477
|
+
};
|
|
478
|
+
}
|
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { tableColumnsSchema } from "@engenty/wizards-shared/engenty/data-tables";
|
|
3
3
|
import { CATEGORY_TYPES } from "@engenty/wizards-shared/knowledge";
|
|
4
4
|
import { PROJECT_LIMITS } from "@engenty/wizards-shared/projects";
|
|
5
|
-
import { note } from "@engenty/wizards-shared/run";
|
|
5
|
+
import { note, noteText } from "@engenty/wizards-shared/run";
|
|
6
6
|
import { SPACE_DATA_LIMITS } from "@engenty/wizards-shared/space-data";
|
|
7
7
|
import { MAX_WIZARD_THEMES, themeSchema } from "@engenty/wizards-shared/theme";
|
|
8
8
|
import { WORKSPACE_LIMITS } from "@engenty/wizards-shared/workspace";
|
|
@@ -12,6 +12,7 @@ import { z } from "zod";
|
|
|
12
12
|
import { db, inTransaction, schema } from "../db/client.js";
|
|
13
13
|
import { missingModels } from "../engine/requirements.js";
|
|
14
14
|
import { env } from "../env.js";
|
|
15
|
+
import { currentTier } from "../models.js";
|
|
15
16
|
import { spaceChanged } from "../plugins/events.js";
|
|
16
17
|
import { sandboxEngine } from "../sandbox/index.js";
|
|
17
18
|
import { codeOf, putLink } from "../tenants/control.js";
|
|
@@ -102,6 +103,19 @@ export async function serverProblems(def, issues) {
|
|
|
102
103
|
detail: `${missing.cls}: ${missing.problem}`,
|
|
103
104
|
});
|
|
104
105
|
}
|
|
106
|
+
// The organization's tier may allow no web search: steps that search run without it.
|
|
107
|
+
const tier = await currentTier();
|
|
108
|
+
if (tier && !tier.rules.search) {
|
|
109
|
+
const steps = stepsWith(def, (s) => s.type === "agent" && s.tools.includes("web_search"));
|
|
110
|
+
if (steps.length) {
|
|
111
|
+
problems.push({
|
|
112
|
+
code: "model",
|
|
113
|
+
blocking: false,
|
|
114
|
+
steps,
|
|
115
|
+
detail: `web_search: ${noteText(note("tierNoSearch", { tier: tier.name }), "en")}`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
105
119
|
if (!sandboxEngine()) {
|
|
106
120
|
const steps = stepsWith(def, (s) => s.type === "agent" && s.tools.includes("sandbox"));
|
|
107
121
|
if (steps.length) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validateWizard } from "@engenty/wizards-shared/definition";
|
|
2
2
|
import { tableColumnsSchema } from "@engenty/wizards-shared/engenty/data-tables";
|
|
3
|
+
import { SKILL_MODES, SKILL_SOURCES, } from "@engenty/wizards-shared/skills";
|
|
3
4
|
import { themeSchema } from "@engenty/wizards-shared/theme";
|
|
4
5
|
import { and, asc, eq, inArray, isNull, ne, sql } from "drizzle-orm";
|
|
5
6
|
import { nanoid } from "nanoid";
|
|
@@ -883,6 +884,83 @@ const connector = {
|
|
|
883
884
|
},
|
|
884
885
|
title: (r, item) => str(obj(r?.record).name) ?? splitTwo(item)[1],
|
|
885
886
|
};
|
|
887
|
+
const skill = {
|
|
888
|
+
async read(id) {
|
|
889
|
+
const k = await db.query.spaceSkill.findFirst({
|
|
890
|
+
where: and(eq(schema.spaceSkill.id, id), eq(schema.spaceSkill.tenantId, currentTenant())),
|
|
891
|
+
});
|
|
892
|
+
if (!k) {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
return {
|
|
896
|
+
projectId: k.projectId,
|
|
897
|
+
record: {
|
|
898
|
+
projectId: k.projectId,
|
|
899
|
+
name: k.name,
|
|
900
|
+
description: k.description,
|
|
901
|
+
body: k.body,
|
|
902
|
+
meta: k.meta,
|
|
903
|
+
files: k.files,
|
|
904
|
+
blobFiles: k.blobFiles,
|
|
905
|
+
mode: k.mode,
|
|
906
|
+
runScripts: k.runScripts,
|
|
907
|
+
source: k.source,
|
|
908
|
+
origin: k.origin,
|
|
909
|
+
originHash: k.originHash,
|
|
910
|
+
},
|
|
911
|
+
};
|
|
912
|
+
},
|
|
913
|
+
async write(projectId, id, r) {
|
|
914
|
+
const mode = SKILL_MODES.find((m) => m === r.mode) ?? "demand";
|
|
915
|
+
const source = SKILL_SOURCES.find((m) => m === r.source) ?? "own";
|
|
916
|
+
const values = {
|
|
917
|
+
projectId,
|
|
918
|
+
name: str(r.name) ?? id.toLowerCase(),
|
|
919
|
+
description: str(r.description) ?? "",
|
|
920
|
+
body: str(r.body) ?? "",
|
|
921
|
+
meta: obj(r.meta),
|
|
922
|
+
files: arr(r.files).filter((f) => typeof f?.path === "string" && typeof f?.text === "string"),
|
|
923
|
+
blobFiles: arr(r.blobFiles).filter((f) => typeof f?.path === "string" &&
|
|
924
|
+
/^[a-f0-9]{64}$/.test(String(f?.hash)) &&
|
|
925
|
+
typeof f?.bytes === "number"),
|
|
926
|
+
mode,
|
|
927
|
+
runScripts: r.runScripts === true,
|
|
928
|
+
source,
|
|
929
|
+
origin: str(r.origin),
|
|
930
|
+
originHash: str(r.originHash),
|
|
931
|
+
};
|
|
932
|
+
// Two sides named a skill alike: the one arriving takes the name with its id behind it.
|
|
933
|
+
const clash = await db.query.spaceSkill.findFirst({
|
|
934
|
+
where: and(eq(schema.spaceSkill.projectId, projectId), eq(schema.spaceSkill.name, values.name), ne(schema.spaceSkill.id, id)),
|
|
935
|
+
columns: { id: true },
|
|
936
|
+
});
|
|
937
|
+
if (clash) {
|
|
938
|
+
values.name =
|
|
939
|
+
`${values.name.slice(0, 50)}-${id.toLowerCase().replace(/[^a-z0-9]/g, "")}`.slice(0, 64);
|
|
940
|
+
}
|
|
941
|
+
await db
|
|
942
|
+
.insert(schema.spaceSkill)
|
|
943
|
+
.values({ id, tenantId: currentTenant(), ...values })
|
|
944
|
+
.onConflictDoUpdate({
|
|
945
|
+
target: schema.spaceSkill.id,
|
|
946
|
+
set: { ...values, updatedAt: new Date() },
|
|
947
|
+
});
|
|
948
|
+
return undefined;
|
|
949
|
+
},
|
|
950
|
+
async remove(_projectId, id) {
|
|
951
|
+
await db.delete(schema.spaceSkill).where(eq(schema.spaceSkill.id, id));
|
|
952
|
+
return undefined;
|
|
953
|
+
},
|
|
954
|
+
async list(projectId) {
|
|
955
|
+
const rows = await db
|
|
956
|
+
.select({ id: schema.spaceSkill.id })
|
|
957
|
+
.from(schema.spaceSkill)
|
|
958
|
+
.where(eq(schema.spaceSkill.projectId, projectId));
|
|
959
|
+
return rows.map((r) => r.id);
|
|
960
|
+
},
|
|
961
|
+
title: (r, item) => str(r?.name) ?? item,
|
|
962
|
+
blobs: (r) => arr(r.blobFiles).map((f) => String(f.hash)),
|
|
963
|
+
};
|
|
886
964
|
export const KINDS = {
|
|
887
965
|
space,
|
|
888
966
|
wizard,
|
|
@@ -894,10 +972,11 @@ export const KINDS = {
|
|
|
894
972
|
category,
|
|
895
973
|
file,
|
|
896
974
|
connector,
|
|
975
|
+
skill,
|
|
897
976
|
};
|
|
898
977
|
/**
|
|
899
978
|
* The order items are written in, so what one points to is there first: the space, its files,
|
|
900
|
-
* tables and categories, then rows, pages, connectors, wizards and what belongs to them.
|
|
979
|
+
* tables and categories, then rows, pages, connectors, skills, wizards and what belongs to them.
|
|
901
980
|
*/
|
|
902
981
|
export const KIND_ORDER = [
|
|
903
982
|
"space",
|
|
@@ -907,6 +986,7 @@ export const KIND_ORDER = [
|
|
|
907
986
|
"row",
|
|
908
987
|
"page",
|
|
909
988
|
"connector",
|
|
989
|
+
"skill",
|
|
910
990
|
"wizard",
|
|
911
991
|
"translation",
|
|
912
992
|
"message",
|