@pixerate/editor 0.260.0 → 0.262.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/agent/index.cjs +19 -3
- package/dist/agent/index.js +21 -5
- package/dist/bridge/cli.cjs +4 -3
- package/dist/bridge/cli.js +3 -2
- package/dist/bridge/index.cjs +4 -3
- package/dist/bridge/index.js +3 -2
- package/dist/{chunk-KBNCEZZB.cjs → chunk-5NRD76T7.cjs} +9 -7
- package/dist/{chunk-SPPDMY7T.js → chunk-6LWEL5DO.js} +4 -2
- package/dist/{chunk-RTPBM46F.cjs → chunk-7TD63DZP.cjs} +1 -294
- package/dist/{chunk-ABHOYBZD.js → chunk-K4BGRCSH.js} +1 -294
- package/dist/chunk-SYEOA5MS.js +301 -0
- package/dist/{chunk-5DLCOQOQ.cjs → chunk-YBC3RKT2.cjs} +177 -16
- package/dist/chunk-ZEKI6EPI.cjs +301 -0
- package/dist/{chunk-UCYW4M66.js → chunk-ZQI3WUPP.js} +163 -2
- package/dist/paint-editor/contract.d.cts +11 -0
- package/dist/paint-editor/contract.d.ts +11 -0
- package/dist/paint-editor/controller.d.cts +17 -0
- package/dist/paint-editor/controller.d.ts +17 -0
- package/dist/paint-editor/index.cjs +245 -84
- package/dist/paint-editor/index.d.cts +2 -1
- package/dist/paint-editor/index.d.ts +2 -1
- package/dist/paint-editor/index.js +163 -2
- package/dist/paint-editor/path-samples.d.cts +19 -0
- package/dist/paint-editor/path-samples.d.ts +19 -0
- package/dist/paint-editor/ui.d.cts +6 -0
- package/dist/paint-editor/ui.d.ts +6 -0
- package/dist/tools/conformance.d.cts +138 -0
- package/dist/tools/conformance.d.ts +138 -0
- package/dist/tools/index.cjs +19 -3
- package/dist/tools/index.d.cts +1 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +21 -5
- package/package.json +1 -1
- package/skills/pixerate-paint-editor/SKILL.md +2 -0
- package/skills/pixerate-paint-sketch-to-finish/SKILL.md +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk7TD63DZPcjs = require('./chunk-7TD63DZP.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk3SLBXKAWcjs = require('./chunk-3SLBXKAW.cjs');
|
|
@@ -39,7 +39,7 @@ function imageEvalFixturePixels(f) {
|
|
|
39
39
|
}
|
|
40
40
|
async function callEvalTool(callTool, { tool, args = {} }) {
|
|
41
41
|
const res = await callTool(tool, await resolve(callTool, args));
|
|
42
|
-
if (res.isError) throw new Error(`${tool}: ${_nullishCoalesce(_optionalChain([res, 'access',
|
|
42
|
+
if (res.isError) throw new Error(`${tool}: ${_nullishCoalesce(_optionalChain([res, 'access', _2 => _2.content, 'optionalAccess', _3 => _3[0], 'optionalAccess', _4 => _4.text]), () => ( "tool error"))}`);
|
|
43
43
|
return res.structuredContent;
|
|
44
44
|
}
|
|
45
45
|
async function resolve(callTool, v) {
|
|
@@ -127,7 +127,7 @@ async function failedEvalChecks(callTool, checks) {
|
|
|
127
127
|
function toolResultValue(result) {
|
|
128
128
|
if (result.structuredContent) return result.structuredContent;
|
|
129
129
|
const text = result.content.find((b) => b.type === "text");
|
|
130
|
-
if (!_optionalChain([text, 'optionalAccess',
|
|
130
|
+
if (!_optionalChain([text, 'optionalAccess', _5 => _5.text])) return void 0;
|
|
131
131
|
try {
|
|
132
132
|
return JSON.parse(text.text);
|
|
133
133
|
} catch (e3) {
|
|
@@ -136,7 +136,7 @@ function toolResultValue(result) {
|
|
|
136
136
|
}
|
|
137
137
|
function toolResultError(result) {
|
|
138
138
|
const text = result.content.find((b) => b.type === "text");
|
|
139
|
-
return _nullishCoalesce(_optionalChain([text, 'optionalAccess',
|
|
139
|
+
return _nullishCoalesce(_optionalChain([text, 'optionalAccess', _6 => _6.text]), () => ( "The tool failed."));
|
|
140
140
|
}
|
|
141
141
|
var realWait = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
142
142
|
async function runToolScript(source, script, options = {}) {
|
|
@@ -147,7 +147,7 @@ async function runToolScript(source, script, options = {}) {
|
|
|
147
147
|
})));
|
|
148
148
|
const ctx = { results: {}, last: void 0 };
|
|
149
149
|
const finish = (ok) => {
|
|
150
|
-
if (control.stopped) _optionalChain([options, 'access',
|
|
150
|
+
if (control.stopped) _optionalChain([options, 'access', _7 => _7.playback, 'optionalAccess', _8 => _8.stop, 'call', _9 => _9()]);
|
|
151
151
|
emit({ type: "done", ok, stopped: control.stopped });
|
|
152
152
|
return { ok, ctx };
|
|
153
153
|
};
|
|
@@ -156,7 +156,7 @@ async function runToolScript(source, script, options = {}) {
|
|
|
156
156
|
const step = script.steps[i];
|
|
157
157
|
if (step.say) {
|
|
158
158
|
emit({ type: "say", step: i, text: step.say });
|
|
159
|
-
_optionalChain([options, 'access',
|
|
159
|
+
_optionalChain([options, 'access', _10 => _10.playback, 'optionalAccess', _11 => _11.say, 'call', _12 => _12(step.say, options.actor ? { actor: options.actor } : {})]);
|
|
160
160
|
await pause(_chunk3SLBXKAWcjs.readingTime.call(void 0, step.say));
|
|
161
161
|
}
|
|
162
162
|
if (!step.tool) continue;
|
|
@@ -187,7 +187,7 @@ var STYLE_SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
|
187
187
|
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
188
188
|
function parseStyleDomains(markdown) {
|
|
189
189
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(markdown);
|
|
190
|
-
const line = _optionalChain([match, 'optionalAccess',
|
|
190
|
+
const line = _optionalChain([match, 'optionalAccess', _13 => _13[1], 'access', _14 => _14.split, 'call', _15 => _15(/\r?\n/), 'access', _16 => _16.find, 'call', _17 => _17((l) => /^domains:/.test(l))]);
|
|
191
191
|
if (!line) return void 0;
|
|
192
192
|
const raw = line.slice("domains:".length).trim().replace(/^\[|\]$/g, "");
|
|
193
193
|
return raw.split(",").map((d) => d.trim().replace(/^(['"])(.*)\1$/, "$2")).filter(Boolean);
|
|
@@ -205,8 +205,8 @@ function memoryStyleStore(initial = {}, state = {}) {
|
|
|
205
205
|
}
|
|
206
206
|
return {
|
|
207
207
|
list: () => [.../* @__PURE__ */ new Set([...files.keys(), ...states.keys()])].sort().map((name) => ({ name, ...states.get(name) })),
|
|
208
|
-
read: (name, file) => _optionalChain([files, 'access',
|
|
209
|
-
files: (name) => [..._nullishCoalesce(_optionalChain([files, 'access',
|
|
208
|
+
read: (name, file) => _optionalChain([files, 'access', _18 => _18.get, 'call', _19 => _19(name), 'optionalAccess', _20 => _20.get, 'call', _21 => _21(file)]),
|
|
209
|
+
files: (name) => [..._nullishCoalesce(_optionalChain([files, 'access', _22 => _22.get, 'call', _23 => _23(name), 'optionalAccess', _24 => _24.keys, 'call', _25 => _25()]), () => ( []))].sort(),
|
|
210
210
|
subscribe(listener) {
|
|
211
211
|
listeners.add(listener);
|
|
212
212
|
return () => listeners.delete(listener);
|
|
@@ -344,7 +344,7 @@ function createStyleResolver(options) {
|
|
|
344
344
|
}
|
|
345
345
|
enabled = entry.enabled;
|
|
346
346
|
}
|
|
347
|
-
const { description = "", body } =
|
|
347
|
+
const { description = "", body } = _chunk7TD63DZPcjs.parseSkillFrontmatter.call(void 0, winner.text);
|
|
348
348
|
const named = parseStyleDomains(winner.text);
|
|
349
349
|
const applies = /* @__PURE__ */ new Set();
|
|
350
350
|
for (const d of _nullishCoalesce(named, () => ( domainIds))) {
|
|
@@ -449,8 +449,8 @@ function createStyleResolver(options) {
|
|
|
449
449
|
return { ...runStyleChecks(domain, state, style), style };
|
|
450
450
|
},
|
|
451
451
|
subscribe(listener) {
|
|
452
|
-
const offs = [...layers.map((l) => _optionalChain([l, 'access',
|
|
453
|
-
return () => offs.forEach((off) => _optionalChain([off, 'optionalCall',
|
|
452
|
+
const offs = [...layers.map((l) => _optionalChain([l, 'access', _26 => _26.store, 'access', _27 => _27.subscribe, 'optionalCall', _28 => _28(listener)])), _optionalChain([options, 'access', _29 => _29.tokens, 'optionalAccess', _30 => _30.subscribe, 'optionalCall', _31 => _31(listener)])];
|
|
453
|
+
return () => offs.forEach((off) => _optionalChain([off, 'optionalCall', _32 => _32()]));
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
456
|
}
|
|
@@ -586,16 +586,177 @@ function createStyleToolProvider(styles, options = {}) {
|
|
|
586
586
|
function createOriginMiddleware(options) {
|
|
587
587
|
const fallback = _nullishCoalesce(options.fallbackOrigin, () => ( "agent:anonymous"));
|
|
588
588
|
return (call, next) => {
|
|
589
|
-
if (_optionalChain([call, 'access',
|
|
589
|
+
if (_optionalChain([call, 'access', _33 => _33.tool, 'access', _34 => _34.annotations, 'optionalAccess', _35 => _35.readOnlyHint]) === true) return next();
|
|
590
590
|
const found = typeof options.histories === "function" ? options.histories(call) : options.histories;
|
|
591
591
|
const targets = !found ? [] : Array.isArray(found) ? found : [found];
|
|
592
592
|
if (!targets.length) return next();
|
|
593
|
-
const origin = _optionalChain([call, 'access',
|
|
593
|
+
const origin = _optionalChain([call, 'access', _36 => _36.context, 'access', _37 => _37.actor, 'optionalAccess', _38 => _38.id]) ? `agent:${call.context.actor.id}` : fallback;
|
|
594
594
|
const run = targets.reduceRight((inner, target) => () => target.withOrigin(origin, inner), next);
|
|
595
595
|
return run();
|
|
596
596
|
};
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
+
// src/tools/conformance.ts
|
|
600
|
+
var ConformanceIds = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
|
|
601
|
+
__init() {this.toPlaceholder = /* @__PURE__ */ new Map()}
|
|
602
|
+
__init2() {this.fromPlaceholder = /* @__PURE__ */ new Map()}
|
|
603
|
+
/** The placeholder for `id`, assigning the next one when it is new. */
|
|
604
|
+
add(id) {
|
|
605
|
+
let placeholder = this.toPlaceholder.get(id);
|
|
606
|
+
if (!placeholder) {
|
|
607
|
+
placeholder = `@${this.toPlaceholder.size + 1}`;
|
|
608
|
+
this.toPlaceholder.set(id, placeholder);
|
|
609
|
+
this.fromPlaceholder.set(placeholder, id);
|
|
610
|
+
}
|
|
611
|
+
return placeholder;
|
|
612
|
+
}
|
|
613
|
+
placeholder(id) {
|
|
614
|
+
return this.toPlaceholder.get(id);
|
|
615
|
+
}
|
|
616
|
+
/** `text` with every known id in it replaced by its placeholder (longest ids first). */
|
|
617
|
+
replaceWithin(text) {
|
|
618
|
+
const exact = this.toPlaceholder.get(text);
|
|
619
|
+
if (exact) return exact;
|
|
620
|
+
let out = text;
|
|
621
|
+
for (const id of [...this.toPlaceholder.keys()].sort((a, b) => b.length - a.length)) {
|
|
622
|
+
if (out.includes(id)) out = out.split(id).join(this.toPlaceholder.get(id));
|
|
623
|
+
}
|
|
624
|
+
return out;
|
|
625
|
+
}
|
|
626
|
+
/** The real id a placeholder stands for. */
|
|
627
|
+
resolve(placeholder) {
|
|
628
|
+
return this.fromPlaceholder.get(placeholder);
|
|
629
|
+
}
|
|
630
|
+
}, _class);
|
|
631
|
+
var PLACEHOLDER = /^@[1-9][0-9]*$/;
|
|
632
|
+
var TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
633
|
+
var BASE64 = /^[A-Za-z0-9+/=_-]+$/;
|
|
634
|
+
var CONFORMANCE_BINARY_MIN_LENGTH = 200;
|
|
635
|
+
function isBinary(value) {
|
|
636
|
+
return value.startsWith("data:") || value.length >= CONFORMANCE_BINARY_MIN_LENGTH && BASE64.test(value);
|
|
637
|
+
}
|
|
638
|
+
function sortedKeys(value) {
|
|
639
|
+
return Object.keys(value).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
640
|
+
}
|
|
641
|
+
function collectIds(value, ids, isId) {
|
|
642
|
+
if (typeof value === "string") {
|
|
643
|
+
if (isId(value)) ids.add(value);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (Array.isArray(value)) {
|
|
647
|
+
for (const item of value) collectIds(item, ids, isId);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (value && typeof value === "object") {
|
|
651
|
+
for (const k of sortedKeys(value)) {
|
|
652
|
+
if (isId(k)) ids.add(k);
|
|
653
|
+
collectIds(value[k], ids, isId);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function replaceIds(value, ids) {
|
|
658
|
+
if (typeof value === "string") return isBinary(value) ? "<binary>" : TIMESTAMP.test(value) ? "<time>" : ids.replaceWithin(value);
|
|
659
|
+
if (Array.isArray(value)) return value.map((item) => replaceIds(item, ids));
|
|
660
|
+
if (value && typeof value === "object") {
|
|
661
|
+
const out = {};
|
|
662
|
+
for (const k of sortedKeys(value)) out[ids.replaceWithin(k)] = replaceIds(value[k], ids);
|
|
663
|
+
return out;
|
|
664
|
+
}
|
|
665
|
+
return value;
|
|
666
|
+
}
|
|
667
|
+
function normalizeConformanceValue(value, ids, isGeneratedId = () => false) {
|
|
668
|
+
const json = value === void 0 ? null : JSON.parse(JSON.stringify(value));
|
|
669
|
+
collectIds(json, ids, (v) => !PLACEHOLDER.test(v) && isGeneratedId(v));
|
|
670
|
+
return replaceIds(json, ids);
|
|
671
|
+
}
|
|
672
|
+
function omitConformancePaths(value, paths) {
|
|
673
|
+
let out = value === void 0 ? null : JSON.parse(JSON.stringify(value));
|
|
674
|
+
for (const path of paths) out = omitPath(out, path.split("/").slice(1));
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
function omitPath(value, parts) {
|
|
678
|
+
if (!value || typeof value !== "object" || parts.length === 0) return value;
|
|
679
|
+
const [head, ...rest] = parts;
|
|
680
|
+
if (Array.isArray(value)) {
|
|
681
|
+
if (head === "*") return value.map((item) => omitPath(item, rest));
|
|
682
|
+
const i = Number(head);
|
|
683
|
+
if (!Number.isInteger(i) || i < 0 || i >= value.length) return value;
|
|
684
|
+
if (rest.length === 0) return value.filter((_, j) => j !== i);
|
|
685
|
+
return value.map((item, j) => j === i ? omitPath(item, rest) : item);
|
|
686
|
+
}
|
|
687
|
+
const object = value;
|
|
688
|
+
const keys = head === "*" ? Object.keys(object) : head in object ? [head] : [];
|
|
689
|
+
for (const key of keys) {
|
|
690
|
+
if (rest.length === 0) delete object[key];
|
|
691
|
+
else object[key] = omitPath(object[key], rest);
|
|
692
|
+
}
|
|
693
|
+
return object;
|
|
694
|
+
}
|
|
695
|
+
function resolveConformanceArguments(value, ids) {
|
|
696
|
+
if (typeof value === "string" && PLACEHOLDER.test(value)) {
|
|
697
|
+
const id = ids.resolve(value);
|
|
698
|
+
if (id === void 0) throw new Error(`Placeholder ${value} is used before any result returned that id.`);
|
|
699
|
+
return id;
|
|
700
|
+
}
|
|
701
|
+
if (Array.isArray(value)) return value.map((item) => resolveConformanceArguments(item, ids));
|
|
702
|
+
if (value && typeof value === "object") {
|
|
703
|
+
const out = {};
|
|
704
|
+
for (const [k, v] of Object.entries(value)) out[k] = resolveConformanceArguments(v, ids);
|
|
705
|
+
return out;
|
|
706
|
+
}
|
|
707
|
+
return value;
|
|
708
|
+
}
|
|
709
|
+
function conformanceResult(result) {
|
|
710
|
+
if (result.isError) {
|
|
711
|
+
const error = _nullishCoalesce(_optionalChain([result, 'access', _39 => _39.structuredContent, 'optionalAccess', _40 => _40.error]), () => ( {}));
|
|
712
|
+
const value = { code: _nullishCoalesce(error.code, () => ( "tool_failed")), message: _nullishCoalesce(_nullishCoalesce(error.message, () => ( resultText(result))), () => ( "")), ...error.details !== void 0 ? { details: error.details } : {} };
|
|
713
|
+
return { value: { error: value }, isError: true };
|
|
714
|
+
}
|
|
715
|
+
if (result.structuredContent !== void 0) return { value: result.structuredContent, isError: false };
|
|
716
|
+
const text = resultText(result);
|
|
717
|
+
if (text === void 0) return { value: null, isError: false };
|
|
718
|
+
try {
|
|
719
|
+
return { value: JSON.parse(text), isError: false };
|
|
720
|
+
} catch (e4) {
|
|
721
|
+
return { value: text, isError: false };
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function resultText(result) {
|
|
725
|
+
for (const content of result.content) {
|
|
726
|
+
if (content.type === "text" && "text" in content && typeof content.text === "string") return content.text;
|
|
727
|
+
}
|
|
728
|
+
return void 0;
|
|
729
|
+
}
|
|
730
|
+
async function runConformanceScenario(scenario, host) {
|
|
731
|
+
const ids = new ConformanceIds();
|
|
732
|
+
const isId = _optionalChain([host, 'access', _41 => _41.isGeneratedId, 'optionalAccess', _42 => _42.bind, 'call', _43 => _43(host)]);
|
|
733
|
+
const outputs = [];
|
|
734
|
+
try {
|
|
735
|
+
for (const step of scenario.steps) {
|
|
736
|
+
const args = resolveConformanceArguments(_nullishCoalesce(step.arguments, () => ( {})), ids);
|
|
737
|
+
const { value, isError } = conformanceResult(await host.callTool(step.tool, args));
|
|
738
|
+
const result = normalizeConformanceValue(value, ids, isId);
|
|
739
|
+
const output = { result: step.ignore ? omitConformancePaths(result, step.ignore) : result, isError };
|
|
740
|
+
if (step.document) output.document = normalizeConformanceValue(host.document(), ids, isId);
|
|
741
|
+
if (step.pixels) {
|
|
742
|
+
const image = host.pixels({ paper: typeof step.pixels === "object" ? step.pixels.paper : void 0 });
|
|
743
|
+
output.pixels = { width: image.width, height: image.height, data: new Uint8Array(image.data.buffer, image.data.byteOffset, image.data.byteLength) };
|
|
744
|
+
}
|
|
745
|
+
outputs.push(output);
|
|
746
|
+
}
|
|
747
|
+
} finally {
|
|
748
|
+
_optionalChain([host, 'access', _44 => _44.dispose, 'optionalCall', _45 => _45()]);
|
|
749
|
+
}
|
|
750
|
+
return outputs;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
599
760
|
|
|
600
761
|
|
|
601
762
|
|
|
@@ -612,4 +773,4 @@ function createOriginMiddleware(options) {
|
|
|
612
773
|
|
|
613
774
|
|
|
614
775
|
|
|
615
|
-
exports.listSkillEvals = listSkillEvals; exports.imageEvalFixturePixels = imageEvalFixturePixels; exports.callEvalTool = callEvalTool; exports.matchesEvalExpectation = matchesEvalExpectation; exports.failedEvalChecks = failedEvalChecks; exports.toolResultValue = toolResultValue; exports.toolResultError = toolResultError; exports.runToolScript = runToolScript; exports.parseStyleDomains = parseStyleDomains; exports.memoryStyleStore = memoryStyleStore; exports.createStyleResolver = createStyleResolver; exports.runStyleChecks = runStyleChecks; exports.renderStyle = renderStyle; exports.createStyleToolProvider = createStyleToolProvider; exports.createOriginMiddleware = createOriginMiddleware;
|
|
776
|
+
exports.listSkillEvals = listSkillEvals; exports.imageEvalFixturePixels = imageEvalFixturePixels; exports.callEvalTool = callEvalTool; exports.matchesEvalExpectation = matchesEvalExpectation; exports.failedEvalChecks = failedEvalChecks; exports.toolResultValue = toolResultValue; exports.toolResultError = toolResultError; exports.runToolScript = runToolScript; exports.parseStyleDomains = parseStyleDomains; exports.memoryStyleStore = memoryStyleStore; exports.createStyleResolver = createStyleResolver; exports.runStyleChecks = runStyleChecks; exports.renderStyle = renderStyle; exports.createStyleToolProvider = createStyleToolProvider; exports.createOriginMiddleware = createOriginMiddleware; exports.ConformanceIds = ConformanceIds; exports.CONFORMANCE_BINARY_MIN_LENGTH = CONFORMANCE_BINARY_MIN_LENGTH; exports.normalizeConformanceValue = normalizeConformanceValue; exports.omitConformancePaths = omitConformancePaths; exports.resolveConformanceArguments = resolveConformanceArguments; exports.conformanceResult = conformanceResult; exports.runConformanceScenario = runConformanceScenario;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk7TD63DZPcjs = require('./chunk-7TD63DZP.cjs');
|
|
6
|
+
|
|
7
|
+
// src/tools/mcp-server.ts
|
|
8
|
+
var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
9
|
+
var JSON_RPC_ERRORS = {
|
|
10
|
+
parseError: -32700,
|
|
11
|
+
invalidRequest: -32600,
|
|
12
|
+
methodNotFound: -32601,
|
|
13
|
+
invalidParams: -32602,
|
|
14
|
+
internalError: -32603
|
|
15
|
+
};
|
|
16
|
+
var errorResponse = (id, code, message, data) => ({
|
|
17
|
+
jsonrpc: "2.0",
|
|
18
|
+
id,
|
|
19
|
+
error: { code, message, ...data !== void 0 ? { data } : {} }
|
|
20
|
+
});
|
|
21
|
+
function toolsetInstructions(source) {
|
|
22
|
+
const sets = source.toolsets();
|
|
23
|
+
const discovery = source.hasTool("list_toolsets") && source.hasTool("search_tools");
|
|
24
|
+
const lines = [
|
|
25
|
+
"Tools are grouped into toolsets, one per open editor or feature, and named `<toolset>__<tool>`." + (discovery ? " Only some are listed at first: call list_toolsets to see them all, search_tools to find a tool for a task, and enable_tools to add what you need." : "")
|
|
26
|
+
];
|
|
27
|
+
if (sets.length > 0) {
|
|
28
|
+
lines.push("", "Toolsets:");
|
|
29
|
+
for (const set of sets) {
|
|
30
|
+
const about = [set.title, _chunk7TD63DZPcjs.summarize.call(void 0, set.description)].filter(Boolean).join(": ");
|
|
31
|
+
const skill = set.skill ? ` (skill: ${set.skill})` : "";
|
|
32
|
+
lines.push(`- ${set.name}${about ? ` - ${about}` : ""}${skill}, ${set.tools.length} tools`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (sets.some((s) => s.skill)) {
|
|
36
|
+
lines.push(
|
|
37
|
+
"",
|
|
38
|
+
"Read the skill a toolset names before using it" + (source.hasTool("get_skill") ? " (get_skill)." : " (an MCP resource or prompt when the server offers skills).")
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
var skillUri = (path) => `skill://${path}`;
|
|
44
|
+
function createMcpServer(registry, options) {
|
|
45
|
+
const skillFiles = _nullishCoalesce(options.skills, () => ( null));
|
|
46
|
+
const skills = skillFiles ? _chunk7TD63DZPcjs.listSkills.call(void 0, skillFiles) : [];
|
|
47
|
+
const capabilities = {
|
|
48
|
+
...registry.capabilities,
|
|
49
|
+
...skills.length > 0 ? { resources: {}, prompts: {} } : {}
|
|
50
|
+
};
|
|
51
|
+
const readSkillPath = (path) => _nullishCoalesce(_optionalChain([skillFiles, 'optionalAccess', _ => _[path]]), () => ( _optionalChain([skillFiles, 'optionalAccess', _2 => _2[`./${path}`]])));
|
|
52
|
+
let initialized = false;
|
|
53
|
+
let actor;
|
|
54
|
+
let unsubscribe = null;
|
|
55
|
+
const running = /* @__PURE__ */ new Map();
|
|
56
|
+
const startNotifications = () => {
|
|
57
|
+
if (unsubscribe || !options.send) return;
|
|
58
|
+
const send = options.send;
|
|
59
|
+
unsubscribe = registry.onListChanged(() => send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" }));
|
|
60
|
+
};
|
|
61
|
+
async function dispatch(request) {
|
|
62
|
+
const id = _nullishCoalesce(request.id, () => ( null));
|
|
63
|
+
const isNotification = request.id === void 0 || request.id === null;
|
|
64
|
+
const params = _nullishCoalesce(request.params, () => ( {}));
|
|
65
|
+
switch (request.method) {
|
|
66
|
+
case "initialize": {
|
|
67
|
+
const client = params.clientInfo;
|
|
68
|
+
if (client && typeof client.name === "string" && client.name) {
|
|
69
|
+
actor = { id: `mcp:${client.name}`, name: typeof client.title === "string" && client.title ? client.title : client.name };
|
|
70
|
+
}
|
|
71
|
+
const instructions = typeof options.instructions === "function" ? options.instructions(registry) : options.instructions;
|
|
72
|
+
const requested = String(_nullishCoalesce(params.protocolVersion, () => ( "")));
|
|
73
|
+
const protocolVersion = MCP_PROTOCOL_VERSIONS.includes(requested) ? requested : MCP_PROTOCOL_VERSIONS[0];
|
|
74
|
+
return {
|
|
75
|
+
jsonrpc: "2.0",
|
|
76
|
+
id,
|
|
77
|
+
result: {
|
|
78
|
+
protocolVersion,
|
|
79
|
+
capabilities,
|
|
80
|
+
serverInfo: { name: options.name, version: options.version, ...options.title ? { title: options.title } : {} },
|
|
81
|
+
...instructions ? { instructions } : {}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
case "notifications/initialized":
|
|
86
|
+
initialized = true;
|
|
87
|
+
startNotifications();
|
|
88
|
+
return null;
|
|
89
|
+
case "notifications/cancelled": {
|
|
90
|
+
const requestId = params.requestId;
|
|
91
|
+
if (requestId !== void 0) _optionalChain([running, 'access', _3 => _3.get, 'call', _4 => _4(requestId), 'optionalAccess', _5 => _5.abort, 'call', _6 => _6(params.reason)]);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
case "ping":
|
|
95
|
+
return { jsonrpc: "2.0", id, result: {} };
|
|
96
|
+
case "tools/list":
|
|
97
|
+
return { jsonrpc: "2.0", id, result: registry.listTools() };
|
|
98
|
+
case "tools/call": {
|
|
99
|
+
const name = params.name;
|
|
100
|
+
if (typeof name !== "string") {
|
|
101
|
+
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, 'tools/call needs a string "name".');
|
|
102
|
+
}
|
|
103
|
+
if (!registry.hasTool(name)) {
|
|
104
|
+
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, `Unknown tool: ${name}`);
|
|
105
|
+
}
|
|
106
|
+
const args = params.arguments;
|
|
107
|
+
if (args !== void 0 && (typeof args !== "object" || args === null || Array.isArray(args))) {
|
|
108
|
+
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, '"arguments" must be an object.');
|
|
109
|
+
}
|
|
110
|
+
const controller = new AbortController();
|
|
111
|
+
if (!isNotification) running.set(id, controller);
|
|
112
|
+
try {
|
|
113
|
+
const result = await registry.callTool(name, _nullishCoalesce(args, () => ( {})), { signal: controller.signal, ...actor ? { actor } : {} });
|
|
114
|
+
if (controller.signal.aborted) return null;
|
|
115
|
+
return { jsonrpc: "2.0", id, result };
|
|
116
|
+
} finally {
|
|
117
|
+
if (!isNotification) running.delete(id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
case "resources/list":
|
|
121
|
+
case "prompts/list":
|
|
122
|
+
case "resources/read":
|
|
123
|
+
case "prompts/get": {
|
|
124
|
+
if (skills.length === 0) break;
|
|
125
|
+
if (request.method === "resources/list") {
|
|
126
|
+
const resources = skills.flatMap(
|
|
127
|
+
(skill2) => ["SKILL.md", ...skill2.references].map((file) => ({
|
|
128
|
+
uri: skillUri(`${skill2.name}/${file}`),
|
|
129
|
+
name: file === "SKILL.md" ? skill2.name : `${skill2.name}/${file}`,
|
|
130
|
+
...file === "SKILL.md" ? { description: skill2.description } : {},
|
|
131
|
+
mimeType: "text/markdown"
|
|
132
|
+
}))
|
|
133
|
+
);
|
|
134
|
+
return { jsonrpc: "2.0", id, result: { resources } };
|
|
135
|
+
}
|
|
136
|
+
if (request.method === "resources/read") {
|
|
137
|
+
const uri = String(_nullishCoalesce(params.uri, () => ( "")));
|
|
138
|
+
const text2 = uri.startsWith("skill://") ? readSkillPath(uri.slice("skill://".length)) : void 0;
|
|
139
|
+
if (text2 === void 0) return errorResponse(id, JSON_RPC_ERRORS.invalidParams, `Unknown resource: ${uri}`, { uri });
|
|
140
|
+
return { jsonrpc: "2.0", id, result: { contents: [{ uri, mimeType: "text/markdown", text: text2 }] } };
|
|
141
|
+
}
|
|
142
|
+
if (request.method === "prompts/list") {
|
|
143
|
+
return { jsonrpc: "2.0", id, result: { prompts: skills.map((s) => ({ name: s.name, description: s.description })) } };
|
|
144
|
+
}
|
|
145
|
+
const skill = skills.find((s) => s.name === params.name);
|
|
146
|
+
const text = skill ? readSkillPath(`${skill.name}/SKILL.md`) : void 0;
|
|
147
|
+
if (!skill || text === void 0) return errorResponse(id, JSON_RPC_ERRORS.invalidParams, `Unknown prompt: ${String(params.name)}`);
|
|
148
|
+
return {
|
|
149
|
+
jsonrpc: "2.0",
|
|
150
|
+
id,
|
|
151
|
+
result: {
|
|
152
|
+
description: skill.description,
|
|
153
|
+
messages: [{ role: "user", content: { type: "text", text: _chunk7TD63DZPcjs.parseSkillFrontmatter.call(void 0, text).body.trim() } }]
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (isNotification) return null;
|
|
159
|
+
return errorResponse(id, JSON_RPC_ERRORS.methodNotFound, `Method not found: ${request.method}`);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
get initialized() {
|
|
163
|
+
return initialized;
|
|
164
|
+
},
|
|
165
|
+
async handle(message) {
|
|
166
|
+
let request;
|
|
167
|
+
if (typeof message === "string") {
|
|
168
|
+
try {
|
|
169
|
+
request = JSON.parse(message);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
return errorResponse(null, JSON_RPC_ERRORS.parseError, "Parse error.");
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
request = message;
|
|
175
|
+
}
|
|
176
|
+
if (!request || typeof request !== "object" || Array.isArray(request) || request.jsonrpc !== "2.0" || typeof request.method !== "string") {
|
|
177
|
+
const id = request && typeof request === "object" && !Array.isArray(request) ? _nullishCoalesce(request.id, () => ( null)) : null;
|
|
178
|
+
return errorResponse(id, JSON_RPC_ERRORS.invalidRequest, "Invalid JSON-RPC 2.0 request.");
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
return await dispatch(request);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (request.id === void 0 || request.id === null) return null;
|
|
184
|
+
return errorResponse(
|
|
185
|
+
request.id,
|
|
186
|
+
JSON_RPC_ERRORS.internalError,
|
|
187
|
+
error instanceof Error ? error.message : String(error)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
close() {
|
|
192
|
+
_optionalChain([unsubscribe, 'optionalCall', _7 => _7()]);
|
|
193
|
+
unsubscribe = null;
|
|
194
|
+
for (const controller of running.values()) controller.abort("Server closed.");
|
|
195
|
+
running.clear();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/tools/bridge-client.ts
|
|
201
|
+
var TOOL_BRIDGE_PROTOCOL = 1;
|
|
202
|
+
var TOOL_BRIDGE_DEFAULT_PORT = 4477;
|
|
203
|
+
function connectToolBridge(registry, options) {
|
|
204
|
+
const Ctor = _nullishCoalesce(options.WebSocket, () => ( globalThis.WebSocket));
|
|
205
|
+
if (!Ctor) throw new Error("No WebSocket implementation: pass options.WebSocket.");
|
|
206
|
+
const base = _nullishCoalesce(options.url, () => ( `ws://127.0.0.1:${TOOL_BRIDGE_DEFAULT_PORT}`));
|
|
207
|
+
const url = options.token ? `${base}${base.includes("?") ? "&" : "?"}token=${encodeURIComponent(options.token)}` : base;
|
|
208
|
+
let status = "connecting";
|
|
209
|
+
let editorId = null;
|
|
210
|
+
let socket = null;
|
|
211
|
+
let closed = false;
|
|
212
|
+
let delay = 500;
|
|
213
|
+
let retry = null;
|
|
214
|
+
const running = /* @__PURE__ */ new Map();
|
|
215
|
+
const setStatus = (next, detail) => {
|
|
216
|
+
if (next === status && !detail) return;
|
|
217
|
+
status = next;
|
|
218
|
+
_optionalChain([options, 'access', _8 => _8.onStatus, 'optionalCall', _9 => _9(next, detail)]);
|
|
219
|
+
};
|
|
220
|
+
const send = (message) => {
|
|
221
|
+
if (socket && socket.readyState === 1) socket.send(JSON.stringify(message));
|
|
222
|
+
};
|
|
223
|
+
const unsubscribe = registry.onListChanged((tools) => send({ t: "tools", tools }));
|
|
224
|
+
const open = () => {
|
|
225
|
+
if (closed) return;
|
|
226
|
+
setStatus("connecting");
|
|
227
|
+
const ws = new Ctor(url);
|
|
228
|
+
socket = ws;
|
|
229
|
+
ws.addEventListener("open", () => {
|
|
230
|
+
delay = 500;
|
|
231
|
+
send({ t: "hello", v: TOOL_BRIDGE_PROTOCOL, name: options.name, ...options.kind ? { kind: options.kind } : {}, tools: registry.listTools().tools });
|
|
232
|
+
});
|
|
233
|
+
ws.addEventListener("message", (event) => {
|
|
234
|
+
let message;
|
|
235
|
+
try {
|
|
236
|
+
message = JSON.parse(String(event.data));
|
|
237
|
+
} catch (e2) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (message.t === "welcome") {
|
|
241
|
+
editorId = message.id;
|
|
242
|
+
setStatus("connected");
|
|
243
|
+
} else if (message.t === "call") {
|
|
244
|
+
const controller = new AbortController();
|
|
245
|
+
running.set(message.id, controller);
|
|
246
|
+
void registry.callTool(message.name, _nullishCoalesce(message.arguments, () => ( {})), { signal: controller.signal }).then((result) => {
|
|
247
|
+
running.delete(message.id);
|
|
248
|
+
if (!controller.signal.aborted) send({ t: "result", id: message.id, result });
|
|
249
|
+
});
|
|
250
|
+
} else if (message.t === "cancel") {
|
|
251
|
+
_optionalChain([running, 'access', _10 => _10.get, 'call', _11 => _11(message.id), 'optionalAccess', _12 => _12.abort, 'call', _13 => _13(_nullishCoalesce(message.reason, () => ( "Cancelled by the agent.")))]);
|
|
252
|
+
running.delete(message.id);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
ws.addEventListener("close", (event) => {
|
|
256
|
+
if (socket !== ws) return;
|
|
257
|
+
socket = null;
|
|
258
|
+
editorId = null;
|
|
259
|
+
for (const controller of running.values()) controller.abort("The bridge disconnected.");
|
|
260
|
+
running.clear();
|
|
261
|
+
if (closed) return setStatus("closed");
|
|
262
|
+
setStatus("disconnected", event.reason || void 0);
|
|
263
|
+
if (options.reconnect === false) return;
|
|
264
|
+
retry = setTimeout(open, delay);
|
|
265
|
+
delay = Math.min(1e4, delay * 2);
|
|
266
|
+
});
|
|
267
|
+
ws.addEventListener("error", () => {
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
open();
|
|
271
|
+
return {
|
|
272
|
+
get status() {
|
|
273
|
+
return status;
|
|
274
|
+
},
|
|
275
|
+
get editorId() {
|
|
276
|
+
return editorId;
|
|
277
|
+
},
|
|
278
|
+
close() {
|
|
279
|
+
if (closed) return;
|
|
280
|
+
closed = true;
|
|
281
|
+
if (retry) clearTimeout(retry);
|
|
282
|
+
unsubscribe();
|
|
283
|
+
for (const controller of running.values()) controller.abort("The editor disconnected.");
|
|
284
|
+
running.clear();
|
|
285
|
+
const ws = socket;
|
|
286
|
+
socket = null;
|
|
287
|
+
_optionalChain([ws, 'optionalAccess', _14 => _14.close, 'call', _15 => _15(1e3, "Editor closed.")]);
|
|
288
|
+
setStatus("closed");
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
exports.MCP_PROTOCOL_VERSIONS = MCP_PROTOCOL_VERSIONS; exports.JSON_RPC_ERRORS = JSON_RPC_ERRORS; exports.toolsetInstructions = toolsetInstructions; exports.createMcpServer = createMcpServer; exports.TOOL_BRIDGE_PROTOCOL = TOOL_BRIDGE_PROTOCOL; exports.TOOL_BRIDGE_DEFAULT_PORT = TOOL_BRIDGE_DEFAULT_PORT; exports.connectToolBridge = connectToolBridge;
|