@eworkbase/plugin-ai-rules 0.4.2 → 0.4.3
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/plugin.mjs +141 -10
- package/dist/ui/main.js +147 -38
- package/dist/ui/style.css +707 -177
- package/package.json +5 -3
package/dist/plugin.mjs
CHANGED
|
@@ -2261,6 +2261,70 @@ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
|
|
|
2261
2261
|
});
|
|
2262
2262
|
};
|
|
2263
2263
|
});
|
|
2264
|
+
function discriminatorMap(def) {
|
|
2265
|
+
const map = /* @__PURE__ */ new Map();
|
|
2266
|
+
for (const option of def.options) {
|
|
2267
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
2268
|
+
if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2269
|
+
for (const value of values) if (map.has(value)) {
|
|
2270
|
+
if (value !== void 0) throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
2271
|
+
map.set(value, null);
|
|
2272
|
+
} else map.set(value, option);
|
|
2273
|
+
}
|
|
2274
|
+
return map;
|
|
2275
|
+
}
|
|
2276
|
+
const $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
2277
|
+
def.inclusive = false;
|
|
2278
|
+
$ZodUnion.init(inst, def);
|
|
2279
|
+
const _super = inst._zod.parse;
|
|
2280
|
+
defineLazyInternal(inst, "propValues", (zod) => {
|
|
2281
|
+
const propValues = {};
|
|
2282
|
+
let undefinedCount = 0;
|
|
2283
|
+
for (const option of zod.def.options) {
|
|
2284
|
+
const pv = option._zod.propValues;
|
|
2285
|
+
if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
2286
|
+
if (pv[zod.def.discriminator]?.has(void 0)) undefinedCount++;
|
|
2287
|
+
for (const [k, v] of Object.entries(pv)) {
|
|
2288
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, k)) assignProp(propValues, k, /* @__PURE__ */ new Set());
|
|
2289
|
+
for (const val of v) propValues[k].add(val);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(void 0);
|
|
2293
|
+
return propValues;
|
|
2294
|
+
});
|
|
2295
|
+
def.options.forEach((option, i) => {
|
|
2296
|
+
const propShape = rawShape(option._zod.def);
|
|
2297
|
+
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
2298
|
+
});
|
|
2299
|
+
const disc = cached(() => discriminatorMap(def));
|
|
2300
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2301
|
+
const input = payload.value;
|
|
2302
|
+
if (!isObject$1(input)) {
|
|
2303
|
+
payload.issues.push({
|
|
2304
|
+
code: "invalid_type",
|
|
2305
|
+
expected: "object",
|
|
2306
|
+
input,
|
|
2307
|
+
inst
|
|
2308
|
+
});
|
|
2309
|
+
return payload;
|
|
2310
|
+
}
|
|
2311
|
+
const value = input?.[def.discriminator];
|
|
2312
|
+
const opt = disc.value.get(value);
|
|
2313
|
+
if (opt && (value !== void 0 || ctx.direction !== "backward")) return opt._zod.run(payload, ctx);
|
|
2314
|
+
if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
|
|
2315
|
+
payload.issues.push({
|
|
2316
|
+
code: "invalid_union",
|
|
2317
|
+
errors: [],
|
|
2318
|
+
note: "No matching discriminator",
|
|
2319
|
+
discriminator: def.discriminator,
|
|
2320
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
2321
|
+
input,
|
|
2322
|
+
path: [def.discriminator],
|
|
2323
|
+
inst
|
|
2324
|
+
});
|
|
2325
|
+
return payload;
|
|
2326
|
+
};
|
|
2327
|
+
});
|
|
2264
2328
|
const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
|
|
2265
2329
|
$ZodType.init(inst, def);
|
|
2266
2330
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -5462,6 +5526,18 @@ function union(options, params) {
|
|
|
5462
5526
|
...normalizeParams(params)
|
|
5463
5527
|
});
|
|
5464
5528
|
}
|
|
5529
|
+
const ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
5530
|
+
ZodUnion.init(inst, def);
|
|
5531
|
+
$ZodDiscriminatedUnion.init(inst, def);
|
|
5532
|
+
});
|
|
5533
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
5534
|
+
return new ZodDiscriminatedUnion({
|
|
5535
|
+
type: "union",
|
|
5536
|
+
options,
|
|
5537
|
+
discriminator,
|
|
5538
|
+
...normalizeParams(params)
|
|
5539
|
+
});
|
|
5540
|
+
}
|
|
5465
5541
|
const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
|
|
5466
5542
|
$ZodIntersection.init(inst, def);
|
|
5467
5543
|
ZodType.init(inst, def);
|
|
@@ -5814,6 +5890,11 @@ let PluginCommandTransaction = /* @__PURE__ */ function(PluginCommandTransaction
|
|
|
5814
5890
|
PluginCommandTransaction["ProjectMutation"] = "projectMutation";
|
|
5815
5891
|
return PluginCommandTransaction;
|
|
5816
5892
|
}({});
|
|
5893
|
+
let PluginViewLayout = /* @__PURE__ */ function(PluginViewLayout) {
|
|
5894
|
+
PluginViewLayout["Content"] = "content";
|
|
5895
|
+
PluginViewLayout["Fill"] = "fill";
|
|
5896
|
+
return PluginViewLayout;
|
|
5897
|
+
}({});
|
|
5817
5898
|
let PluginProcessOutputMode = /* @__PURE__ */ function(PluginProcessOutputMode) {
|
|
5818
5899
|
PluginProcessOutputMode["Log"] = "log";
|
|
5819
5900
|
PluginProcessOutputMode["Content"] = "content";
|
|
@@ -5989,6 +6070,30 @@ object({
|
|
|
5989
6070
|
execution: executionIdentitySchema.nullish(),
|
|
5990
6071
|
context: executionContextSchema.optional()
|
|
5991
6072
|
});
|
|
6073
|
+
/** Serializable opt-in for workflow nodes and the result fields a condition may read. */
|
|
6074
|
+
const name = string().trim().min(1).max(120);
|
|
6075
|
+
const fieldKey = string().regex(/^[A-Za-z][A-Za-z0-9_]{0,63}$/).refine((key) => ![
|
|
6076
|
+
"constructor",
|
|
6077
|
+
"prototype",
|
|
6078
|
+
"__proto__"
|
|
6079
|
+
].includes(key));
|
|
6080
|
+
const outputField = discriminatedUnion("type", [
|
|
6081
|
+
object({
|
|
6082
|
+
type: literal("boolean"),
|
|
6083
|
+
label: name
|
|
6084
|
+
}).strict(),
|
|
6085
|
+
object({
|
|
6086
|
+
type: literal("number"),
|
|
6087
|
+
label: name,
|
|
6088
|
+
unit: name.optional()
|
|
6089
|
+
}).strict(),
|
|
6090
|
+
object({
|
|
6091
|
+
type: literal("enum"),
|
|
6092
|
+
label: name,
|
|
6093
|
+
values: array(name).min(1).max(64)
|
|
6094
|
+
}).strict()
|
|
6095
|
+
]);
|
|
6096
|
+
union([literal(true), object({ outputs: record(fieldKey, outputField).refine((fields) => Object.keys(fields).length <= 32) }).strict()]);
|
|
5992
6097
|
//#endregion
|
|
5993
6098
|
//#region ../plugin-sdk/dist/markdown-link-C-qw7xuN.js
|
|
5994
6099
|
const MAXIMUM_LINK_LENGTH = 4096;
|
|
@@ -16065,6 +16170,10 @@ function resourceDocuments(root) {
|
|
|
16065
16170
|
});
|
|
16066
16171
|
return documents.sort((left, right) => `${left.kind}/${left.id}`.localeCompare(`${right.kind}/${right.id}`));
|
|
16067
16172
|
}
|
|
16173
|
+
/** 与资源目录共用规则条目标识,概览只枚举文件。 */
|
|
16174
|
+
function countProjectRules(root) {
|
|
16175
|
+
return directoryEntries(root, "rules").filter(({ entry }) => entry.isFile()).length;
|
|
16176
|
+
}
|
|
16068
16177
|
async function resourceGitOutput(invocation, options) {
|
|
16069
16178
|
const result = await invocation.process.run({
|
|
16070
16179
|
...options,
|
|
@@ -16226,16 +16335,7 @@ function importSkill(context, directory) {
|
|
|
16226
16335
|
}
|
|
16227
16336
|
function directoryResources(root, kind) {
|
|
16228
16337
|
const documents = [];
|
|
16229
|
-
const
|
|
16230
|
-
if (!existsSync(directory)) return [];
|
|
16231
|
-
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
16232
|
-
const id = kind === "skills" ? entry.name : entry.name.replace(/\.md$/, "");
|
|
16233
|
-
if (!resourceIdentitySchema.safeParse({
|
|
16234
|
-
kind,
|
|
16235
|
-
id
|
|
16236
|
-
}).success) continue;
|
|
16237
|
-
if (kind !== "skills" && !entry.name.endsWith(".md")) continue;
|
|
16238
|
-
const source = `rules/.rulesync/${kind}/${entry.name}`;
|
|
16338
|
+
for (const { entry, id, source } of directoryEntries(root, kind)) {
|
|
16239
16339
|
const target = safeFilePath(root, source);
|
|
16240
16340
|
const contents = kind === "skills" && entry.isDirectory() ? new Map([...readOutputFiles(target)].map(([file, content]) => [`${source}/${file}`, content])) : /* @__PURE__ */ new Map([[source, readSafeFile(root, source)]]);
|
|
16241
16341
|
if (kind === "skills" && !contents.has(`${source}/SKILL.md`)) continue;
|
|
@@ -16246,6 +16346,23 @@ function directoryResources(root, kind) {
|
|
|
16246
16346
|
}
|
|
16247
16347
|
return documents;
|
|
16248
16348
|
}
|
|
16349
|
+
function directoryEntries(root, kind) {
|
|
16350
|
+
const prefix = `rules/.rulesync/${kind}`;
|
|
16351
|
+
const directory = safeFilePath(root, prefix);
|
|
16352
|
+
if (!existsSync(directory)) return [];
|
|
16353
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
16354
|
+
if (kind !== "skills" && !entry.name.endsWith(".md")) return [];
|
|
16355
|
+
const id = kind === "skills" ? entry.name : entry.name.slice(0, -3);
|
|
16356
|
+
return resourceIdentitySchema.safeParse({
|
|
16357
|
+
kind,
|
|
16358
|
+
id
|
|
16359
|
+
}).success ? [{
|
|
16360
|
+
entry,
|
|
16361
|
+
id,
|
|
16362
|
+
source: `${prefix}/${entry.name}`
|
|
16363
|
+
}] : [];
|
|
16364
|
+
});
|
|
16365
|
+
}
|
|
16249
16366
|
//#endregion
|
|
16250
16367
|
//#region src/rulesync.ts
|
|
16251
16368
|
/** Rulesync generation, preview, synchronization and result normalization. */
|
|
@@ -16968,7 +17085,21 @@ var plugin_default = definePlugin({
|
|
|
16968
17085
|
description: "诊断、预览并同步当前 Workspace 的 AI 客户端上下文。",
|
|
16969
17086
|
entry: "dist/ui/index.html",
|
|
16970
17087
|
id: "workspace",
|
|
17088
|
+
overviewCard: {
|
|
17089
|
+
icon: "list-checks",
|
|
17090
|
+
order: 30,
|
|
17091
|
+
tone: "yellow",
|
|
17092
|
+
resolve: () => {
|
|
17093
|
+
const configured = isConfigured(paths);
|
|
17094
|
+
return {
|
|
17095
|
+
status: configured ? "ready" : "warning",
|
|
17096
|
+
value: `${countProjectRules(context.project.root)} 条规则`,
|
|
17097
|
+
...!configured && { detail: "待配置" }
|
|
17098
|
+
};
|
|
17099
|
+
}
|
|
17100
|
+
},
|
|
16971
17101
|
slot: "workspace.tab",
|
|
17102
|
+
layout: PluginViewLayout.Fill,
|
|
16972
17103
|
handlers: createMarkdownHandlers({ root: rulesRoot })
|
|
16973
17104
|
});
|
|
16974
17105
|
}
|