@pixerate/editor 0.139.1 → 0.140.1
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/README.md +25 -4
- package/dist/agent/formatTools.d.cts +15 -0
- package/dist/agent/formatTools.d.ts +15 -0
- package/dist/agent/index.cjs +408 -49
- package/dist/agent/index.js +375 -16
- package/dist/agent/providers.d.cts +5 -3
- package/dist/agent/providers.d.ts +5 -3
- package/dist/animation-editor/effect-tools.d.cts +1 -1
- package/dist/animation-editor/effect-tools.d.ts +1 -1
- package/dist/animation-editor/index.cjs +250 -116
- package/dist/animation-editor/index.js +228 -94
- package/dist/animation-editor/instructions.d.cts +1 -1
- package/dist/animation-editor/instructions.d.ts +1 -1
- package/dist/animation-editor/parse.d.cts +3 -1
- package/dist/animation-editor/parse.d.ts +3 -1
- package/dist/animation-editor/tools.d.cts +8 -3
- package/dist/animation-editor/tools.d.ts +8 -3
- package/dist/bridge/cli.cjs +4 -3
- package/dist/bridge/cli.js +3 -2
- package/dist/bridge/index.cjs +8 -3
- package/dist/bridge/index.d.cts +7 -0
- package/dist/bridge/index.d.ts +7 -0
- package/dist/bridge/index.js +9 -4
- package/dist/bridge/skills.d.cts +9 -0
- package/dist/bridge/skills.d.ts +9 -0
- package/dist/canvas/effect-tools.d.cts +1 -1
- package/dist/canvas/effect-tools.d.ts +1 -1
- package/dist/canvas/index.cjs +22 -17
- package/dist/canvas/index.js +8 -3
- package/dist/chart/file-tools.d.cts +1 -1
- package/dist/chart/file-tools.d.ts +1 -1
- package/dist/chart/index.cjs +7 -1
- package/dist/chart/index.js +7 -1
- package/dist/chart/tools.d.cts +1 -1
- package/dist/chart/tools.d.ts +1 -1
- package/dist/chunk-2BSBFBOA.cjs +46 -0
- package/dist/{chunk-SWZTQWY7.js → chunk-2INPJDNY.js} +1 -1
- package/dist/{chunk-CCKP4XAN.cjs → chunk-34RQAGWI.cjs} +27 -7
- package/dist/{chunk-HXCBQ7A6.cjs → chunk-3AJMR7EG.cjs} +7 -4
- package/dist/{chunk-BKMU3V6K.js → chunk-5ED73EC6.js} +8 -1
- package/dist/{chunk-NKBUVQJW.cjs → chunk-5WOY52O6.cjs} +15 -15
- package/dist/{chunk-VRIR53SW.js → chunk-6GAYGQDC.js} +10 -8
- package/dist/{chunk-HZZXBTLB.js → chunk-6IN474P4.js} +25 -5
- package/dist/{chunk-KHMVB3SJ.js → chunk-7KWJEYIK.js} +4 -1
- package/dist/{chunk-R47NQICB.cjs → chunk-AGCD3EHB.cjs} +47 -10
- package/dist/{chunk-6I63VZ45.js → chunk-CXXKJBQZ.js} +5 -1
- package/dist/{chunk-6NXVDJDR.cjs → chunk-G43MNQ4C.cjs} +5 -5
- package/dist/chunk-HDK3T2QS.cjs +1159 -0
- package/dist/chunk-HF5QZS7Z.js +46 -0
- package/dist/{chunk-S7I3RI5Z.cjs → chunk-HMGWFXEC.cjs} +27 -24
- package/dist/{chunk-6NCBFBXA.js → chunk-IQ6KKXOU.js} +1 -1
- package/dist/{chunk-T6Y5FV7G.cjs → chunk-L434J57V.cjs} +10 -8
- package/dist/{chunk-UCRL6JEV.cjs → chunk-L5OWG2NA.cjs} +8 -3
- package/dist/{chunk-CZRWP6IW.cjs → chunk-N2FGYZ4Q.cjs} +8 -1
- package/dist/{chunk-GUPQ5BNA.cjs → chunk-PUR6BZFA.cjs} +112 -111
- package/dist/chunk-RB62U6MS.js +1159 -0
- package/dist/{chunk-3V746PF4.cjs → chunk-RUZQMYXH.cjs} +4 -1
- package/dist/{chunk-HGHXGCKG.cjs → chunk-SVFEVKLF.cjs} +1 -1
- package/dist/{chunk-PCNCT4ZY.js → chunk-UMS6YFA6.js} +40 -3
- package/dist/{chunk-4LGWAJDI.js → chunk-V5OOP74P.js} +5 -2
- package/dist/{chunk-BWT4IWLK.cjs → chunk-VKF3PWKR.cjs} +7 -7
- package/dist/{chunk-PQMADRCI.js → chunk-WBJ6BG4R.js} +23 -22
- package/dist/{chunk-WIYAOZZU.js → chunk-WHKNYFM2.js} +7 -2
- package/dist/{chunk-TBSPPVTT.js → chunk-XCK7QK5D.js} +1 -1
- package/dist/{chunk-F652BKMS.cjs → chunk-YN6JKAUE.cjs} +6 -2
- package/dist/{chunk-YTGF4TJR.js → chunk-ZLZKGHSZ.js} +5 -2
- package/dist/{chunk-USU2FL3N.js → chunk-ZNHB5RG6.js} +1 -1
- package/dist/commands/agentTools.d.cts +1 -1
- package/dist/commands/agentTools.d.ts +1 -1
- package/dist/commands/index.cjs +3 -0
- package/dist/commands/index.js +3 -0
- package/dist/compare/index.cjs +4 -3
- package/dist/compare/index.js +3 -2
- package/dist/diagram/index.cjs +3 -0
- package/dist/diagram/index.js +3 -0
- package/dist/diagram/tools.d.cts +1 -1
- package/dist/diagram/tools.d.ts +1 -1
- package/dist/effects/index.cjs +32 -32
- package/dist/effects/index.js +1 -1
- package/dist/effects/tools.d.cts +5 -1
- package/dist/effects/tools.d.ts +5 -1
- package/dist/export/index.cjs +4 -3
- package/dist/export/index.js +3 -2
- package/dist/extensions/index.cjs +11 -8
- package/dist/extensions/index.d.cts +1 -0
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +10 -7
- package/dist/extensions/safe-merge-attributes.d.cts +10 -0
- package/dist/extensions/safe-merge-attributes.d.ts +10 -0
- package/dist/generation/index.cjs +7 -1
- package/dist/generation/index.js +7 -1
- package/dist/image-editor/index.cjs +25 -18
- package/dist/image-editor/index.js +10 -3
- package/dist/image-editor/provider-effect-tools.d.cts +1 -1
- package/dist/image-editor/provider-effect-tools.d.ts +1 -1
- package/dist/image-editor/tools.d.cts +1 -1
- package/dist/image-editor/tools.d.ts +1 -1
- package/dist/index.cjs +42 -29
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -9
- package/dist/paint-editor/effect-tools.d.cts +1 -1
- package/dist/paint-editor/effect-tools.d.ts +1 -1
- package/dist/paint-editor/index.cjs +18 -8
- package/dist/paint-editor/index.js +13 -3
- package/dist/paint-editor/tools.d.cts +1 -1
- package/dist/paint-editor/tools.d.ts +1 -1
- package/dist/persistence/index.cjs +3 -2
- package/dist/persistence/index.js +2 -1
- package/dist/serializers/index.cjs +5 -4
- package/dist/serializers/index.js +4 -3
- package/dist/tools/bridge-client.d.cts +3 -3
- package/dist/tools/bridge-client.d.ts +3 -3
- package/dist/tools/capture.d.cts +5 -1
- package/dist/tools/capture.d.ts +5 -1
- package/dist/tools/definitions.d.cts +2 -2
- package/dist/tools/definitions.d.ts +2 -2
- package/dist/tools/index.cjs +39 -5
- package/dist/tools/index.d.cts +4 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +39 -5
- package/dist/tools/mcp-server.d.cts +24 -6
- package/dist/tools/mcp-server.d.ts +24 -6
- package/dist/tools/registry.d.cts +81 -6
- package/dist/tools/registry.d.ts +81 -6
- package/dist/tools/safe-json.d.cts +27 -0
- package/dist/tools/safe-json.d.ts +27 -0
- package/dist/tools/search.d.cts +30 -0
- package/dist/tools/search.d.ts +30 -0
- package/dist/tools/skills.d.cts +26 -0
- package/dist/tools/skills.d.ts +26 -0
- package/dist/tools/view.d.cts +95 -0
- package/dist/tools/view.d.ts +95 -0
- package/dist/vector/effect-tools.d.cts +1 -1
- package/dist/vector/effect-tools.d.ts +1 -1
- package/dist/vector/index.cjs +13 -7
- package/dist/vector/index.js +8 -2
- package/dist/video-editor/effect-tools.d.cts +1 -1
- package/dist/video-editor/effect-tools.d.ts +1 -1
- package/dist/video-editor/index.cjs +275 -269
- package/dist/video-editor/index.js +8 -2
- package/dist/video-editor/tools.d.cts +1 -1
- package/dist/video-editor/tools.d.ts +1 -1
- package/package.json +31 -29
- package/skills/README.md +8 -3
- package/skills/pixerate-agent-tools/SKILL.md +33 -7
- package/skills/pixerate-animation-editor/SKILL.md +7 -0
- package/skills/pixerate-rich-text/SKILL.md +18 -4
- package/dist/chunk-5RRYDFU2.js +0 -466
- package/dist/chunk-SPVIXXIB.cjs +0 -466
- /package/dist/{chunk-SMJK5HBJ.js → chunk-K73HMKQP.js} +0 -0
- /package/dist/{chunk-DDF6WQ62.cjs → chunk-LACYURUW.cjs} +0 -0
package/dist/chunk-SPVIXXIB.cjs
DELETED
|
@@ -1,466 +0,0 @@
|
|
|
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
|
-
|
|
3
|
-
var _chunkWOFXZ3XUcjs = require('./chunk-WOFXZ3XU.cjs');
|
|
4
|
-
|
|
5
|
-
// src/tools/registry.ts
|
|
6
|
-
var ToolRegistryError = class extends Error {
|
|
7
|
-
|
|
8
|
-
constructor(code, message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = "ToolRegistryError";
|
|
11
|
-
this.code = code;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var TOOL_NAMESPACE_SEPARATOR = "__";
|
|
15
|
-
var TOOL_NAME_REGEX = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
16
|
-
var sanitizeNamespace = (id) => id.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
17
|
-
function readTools(provider) {
|
|
18
|
-
return typeof provider.tools === "function" ? provider.tools() : provider.tools;
|
|
19
|
-
}
|
|
20
|
-
function toDefinition(name, tool) {
|
|
21
|
-
const { handler: _handler, name: _name, ...rest } = tool;
|
|
22
|
-
return { name, ...rest };
|
|
23
|
-
}
|
|
24
|
-
function errorResult(error) {
|
|
25
|
-
const details = _optionalChain([error, 'access', _ => _.details, 'optionalAccess', _2 => _2.length]) ? "\n" + error.details.map((d) => `- ${d.path}: ${d.message}`).join("\n") : "";
|
|
26
|
-
return {
|
|
27
|
-
isError: true,
|
|
28
|
-
content: [{ type: "text", text: `${error.message}${details}` }],
|
|
29
|
-
structuredContent: { error }
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function toToolResult(value) {
|
|
33
|
-
if (value && typeof value === "object" && Array.isArray(value.content)) {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
if (value === void 0) return { content: [] };
|
|
37
|
-
if (typeof value === "string") return { content: [{ type: "text", text: value }] };
|
|
38
|
-
const text = JSON.stringify(value);
|
|
39
|
-
const isPlainObject = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
-
return {
|
|
41
|
-
content: [{ type: "text", text: _nullishCoalesce(text, () => ( String(value))) }],
|
|
42
|
-
...isPlainObject ? { structuredContent: value } : {}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
var ToolRegistry = (_class = class {
|
|
46
|
-
/** MCP server capabilities this registry supports. */
|
|
47
|
-
__init() {this.capabilities = { tools: { listChanged: true } }}
|
|
48
|
-
__init2() {this.entries = []}
|
|
49
|
-
__init3() {this.listeners = /* @__PURE__ */ new Set()}
|
|
50
|
-
|
|
51
|
-
__init4() {this.timer = null}
|
|
52
|
-
|
|
53
|
-
constructor(options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
|
|
54
|
-
this.options = {
|
|
55
|
-
onCollision: _nullishCoalesce(options.onCollision, () => ( "namespace")),
|
|
56
|
-
listChangedDelayMs: _nullishCoalesce(options.listChangedDelayMs, () => ( 0)),
|
|
57
|
-
validateArguments: _nullishCoalesce(options.validateArguments, () => ( true))
|
|
58
|
-
};
|
|
59
|
-
this.lastSignature = this.signature();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Registers a provider and returns a function that unregisters it.
|
|
63
|
-
* Throws a {@link ToolRegistryError} for a duplicate provider id, an invalid
|
|
64
|
-
* tool name, or (with `onCollision: 'error'`) a tool name collision.
|
|
65
|
-
*/
|
|
66
|
-
register(provider) {
|
|
67
|
-
if (this.entries.some((e) => e.provider.id === provider.id)) {
|
|
68
|
-
throw new ToolRegistryError("duplicate_provider", `Tool provider "${provider.id}" is already registered.`);
|
|
69
|
-
}
|
|
70
|
-
for (const tool of readTools(provider)) {
|
|
71
|
-
if (!TOOL_NAME_REGEX.test(tool.name)) {
|
|
72
|
-
throw new ToolRegistryError("invalid_tool", `Invalid tool name "${tool.name}" from provider "${provider.id}".`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const entry = { provider };
|
|
76
|
-
this.entries.push(entry);
|
|
77
|
-
try {
|
|
78
|
-
const names = this.resolve(this.options.onCollision === "error").map((t) => t.name);
|
|
79
|
-
const duplicate = names.find((name, i) => names.indexOf(name) !== i);
|
|
80
|
-
if (duplicate) {
|
|
81
|
-
throw new ToolRegistryError("name_collision", `Tool name "${duplicate}" is exposed more than once.`);
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {
|
|
84
|
-
this.entries.pop();
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
if (provider.subscribe) {
|
|
88
|
-
entry.unsubscribe = provider.subscribe(() => this.notifyListChanged());
|
|
89
|
-
}
|
|
90
|
-
this.notifyListChanged();
|
|
91
|
-
let registered = true;
|
|
92
|
-
return () => {
|
|
93
|
-
if (!registered) return;
|
|
94
|
-
registered = false;
|
|
95
|
-
this.unregister(provider);
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/** Removes a provider by id or instance. Returns whether it was registered. */
|
|
99
|
-
unregister(providerOrId) {
|
|
100
|
-
const index = this.entries.findIndex(
|
|
101
|
-
(e) => typeof providerOrId === "string" ? e.provider.id === providerOrId : e.provider === providerOrId
|
|
102
|
-
);
|
|
103
|
-
if (index === -1) return false;
|
|
104
|
-
const [entry] = this.entries.splice(index, 1);
|
|
105
|
-
_optionalChain([entry, 'access', _3 => _3.unsubscribe, 'optionalCall', _4 => _4()]);
|
|
106
|
-
this.notifyListChanged();
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
/** Registered provider ids in registration order. */
|
|
110
|
-
providerIds() {
|
|
111
|
-
return this.entries.map((e) => e.provider.id);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Resolves exposed names. Tools are ordered by provider registration, then
|
|
115
|
-
* by their order within the provider.
|
|
116
|
-
*/
|
|
117
|
-
resolve(throwOnCollision = false) {
|
|
118
|
-
const all = [];
|
|
119
|
-
const counts = /* @__PURE__ */ new Map();
|
|
120
|
-
for (const { provider } of this.entries) {
|
|
121
|
-
for (const tool of readTools(provider)) {
|
|
122
|
-
all.push({ name: tool.name, tool, provider });
|
|
123
|
-
if (!provider.namespace) counts.set(tool.name, (_nullishCoalesce(counts.get(tool.name), () => ( 0))) + 1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
for (const item of all) {
|
|
127
|
-
const prefix = _nullishCoalesce(item.provider.namespace, () => ( ((_nullishCoalesce(counts.get(item.name), () => ( 0))) > 1 ? item.provider.id : void 0)));
|
|
128
|
-
if (prefix !== void 0) {
|
|
129
|
-
if (throwOnCollision && !item.provider.namespace) {
|
|
130
|
-
throw new ToolRegistryError(
|
|
131
|
-
"name_collision",
|
|
132
|
-
`Tool "${item.name}" from provider "${item.provider.id}" collides with another provider's tool.`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
item.name = `${sanitizeNamespace(prefix)}${TOOL_NAMESPACE_SEPARATOR}${item.name}`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return all;
|
|
139
|
-
}
|
|
140
|
-
/** MCP `tools/list` result for the current providers. */
|
|
141
|
-
listTools() {
|
|
142
|
-
return { tools: this.resolve().map(({ name, tool }) => toDefinition(name, tool)) };
|
|
143
|
-
}
|
|
144
|
-
/** Whether a tool with this exposed name exists. */
|
|
145
|
-
hasTool(name) {
|
|
146
|
-
return this.resolve().some((t) => t.name === name);
|
|
147
|
-
}
|
|
148
|
-
/** Looks up a tool definition by exposed name. */
|
|
149
|
-
getTool(name) {
|
|
150
|
-
const found = this.resolve().find((t) => t.name === name);
|
|
151
|
-
return found ? toDefinition(found.name, found.tool) : void 0;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Calls a tool by exposed name and returns an MCP `tools/call` result.
|
|
155
|
-
* Never rejects: unknown tools, invalid arguments and handler errors come
|
|
156
|
-
* back as `isError: true` results with a {@link ToolCallError} in
|
|
157
|
-
* `structuredContent.error` (MCP transports may map `unknown_tool` to a
|
|
158
|
-
* JSON-RPC `-32602` error instead).
|
|
159
|
-
*/
|
|
160
|
-
async callTool(name, args = {}, options = {}) {
|
|
161
|
-
const found = this.resolve().find((t) => t.name === name);
|
|
162
|
-
if (!found) {
|
|
163
|
-
return errorResult({ code: "unknown_tool", message: `Unknown tool "${name}".`, tool: name });
|
|
164
|
-
}
|
|
165
|
-
const input = _nullishCoalesce(args, () => ( {}));
|
|
166
|
-
if (this.options.validateArguments) {
|
|
167
|
-
const details = _chunkWOFXZ3XUcjs.validateJsonSchema.call(void 0, input, found.tool.inputSchema);
|
|
168
|
-
if (details.length > 0) {
|
|
169
|
-
return errorResult({
|
|
170
|
-
code: "invalid_arguments",
|
|
171
|
-
message: `Invalid arguments for tool "${name}".`,
|
|
172
|
-
tool: name,
|
|
173
|
-
details
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const value = await found.tool.handler(input, {
|
|
179
|
-
name,
|
|
180
|
-
providerId: found.provider.id,
|
|
181
|
-
signal: options.signal
|
|
182
|
-
});
|
|
183
|
-
return toToolResult(value);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
return errorResult({
|
|
186
|
-
code: "tool_failed",
|
|
187
|
-
message: error instanceof Error ? error.message : String(error),
|
|
188
|
-
tool: name
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Subscribes to tool-list changes. Notifications are coalesced: many
|
|
194
|
-
* registrations or provider signals within the delay window produce one
|
|
195
|
-
* call, and none if the exposed list ends up unchanged (e.g. a provider
|
|
196
|
-
* unmounted and remounted). Returns an unsubscribe function.
|
|
197
|
-
*/
|
|
198
|
-
onListChanged(listener) {
|
|
199
|
-
this.listeners.add(listener);
|
|
200
|
-
return () => {
|
|
201
|
-
this.listeners.delete(listener);
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/** Schedules a coalesced `listChanged` check; providers may call it directly. */
|
|
205
|
-
notifyListChanged() {
|
|
206
|
-
if (this.timer !== null) return;
|
|
207
|
-
this.timer = setTimeout(() => this.flush(), this.options.listChangedDelayMs);
|
|
208
|
-
}
|
|
209
|
-
/** Runs a pending `listChanged` check immediately. */
|
|
210
|
-
flush() {
|
|
211
|
-
if (this.timer !== null) {
|
|
212
|
-
clearTimeout(this.timer);
|
|
213
|
-
this.timer = null;
|
|
214
|
-
}
|
|
215
|
-
const signature = this.signature();
|
|
216
|
-
if (signature === this.lastSignature) return;
|
|
217
|
-
this.lastSignature = signature;
|
|
218
|
-
const { tools } = this.listTools();
|
|
219
|
-
for (const listener of Array.from(this.listeners)) listener(tools);
|
|
220
|
-
}
|
|
221
|
-
signature() {
|
|
222
|
-
try {
|
|
223
|
-
return JSON.stringify(this.listTools().tools);
|
|
224
|
-
} catch (e2) {
|
|
225
|
-
return String(Math.random());
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/** Unregisters every provider and listener and cancels pending notifications. */
|
|
229
|
-
dispose() {
|
|
230
|
-
if (this.timer !== null) clearTimeout(this.timer);
|
|
231
|
-
this.timer = null;
|
|
232
|
-
for (const entry of this.entries.splice(0)) _optionalChain([entry, 'access', _5 => _5.unsubscribe, 'optionalCall', _6 => _6()]);
|
|
233
|
-
this.listeners.clear();
|
|
234
|
-
}
|
|
235
|
-
}, _class);
|
|
236
|
-
function createToolRegistry(options) {
|
|
237
|
-
return new ToolRegistry(options);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// src/tools/mcp-server.ts
|
|
241
|
-
var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
242
|
-
var JSON_RPC_ERRORS = {
|
|
243
|
-
parseError: -32700,
|
|
244
|
-
invalidRequest: -32600,
|
|
245
|
-
methodNotFound: -32601,
|
|
246
|
-
invalidParams: -32602,
|
|
247
|
-
internalError: -32603
|
|
248
|
-
};
|
|
249
|
-
var errorResponse = (id, code, message, data) => ({
|
|
250
|
-
jsonrpc: "2.0",
|
|
251
|
-
id,
|
|
252
|
-
error: { code, message, ...data !== void 0 ? { data } : {} }
|
|
253
|
-
});
|
|
254
|
-
function createMcpServer(registry, options) {
|
|
255
|
-
let initialized = false;
|
|
256
|
-
let unsubscribe = null;
|
|
257
|
-
const running = /* @__PURE__ */ new Map();
|
|
258
|
-
const startNotifications = () => {
|
|
259
|
-
if (unsubscribe || !options.send) return;
|
|
260
|
-
const send = options.send;
|
|
261
|
-
unsubscribe = registry.onListChanged(() => send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" }));
|
|
262
|
-
};
|
|
263
|
-
async function dispatch(request) {
|
|
264
|
-
const id = _nullishCoalesce(request.id, () => ( null));
|
|
265
|
-
const isNotification = request.id === void 0 || request.id === null;
|
|
266
|
-
const params = _nullishCoalesce(request.params, () => ( {}));
|
|
267
|
-
switch (request.method) {
|
|
268
|
-
case "initialize": {
|
|
269
|
-
const requested = String(_nullishCoalesce(params.protocolVersion, () => ( "")));
|
|
270
|
-
const protocolVersion = MCP_PROTOCOL_VERSIONS.includes(requested) ? requested : MCP_PROTOCOL_VERSIONS[0];
|
|
271
|
-
return {
|
|
272
|
-
jsonrpc: "2.0",
|
|
273
|
-
id,
|
|
274
|
-
result: {
|
|
275
|
-
protocolVersion,
|
|
276
|
-
capabilities: registry.capabilities,
|
|
277
|
-
serverInfo: { name: options.name, version: options.version, ...options.title ? { title: options.title } : {} },
|
|
278
|
-
...options.instructions ? { instructions: options.instructions } : {}
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
case "notifications/initialized":
|
|
283
|
-
initialized = true;
|
|
284
|
-
startNotifications();
|
|
285
|
-
return null;
|
|
286
|
-
case "notifications/cancelled": {
|
|
287
|
-
const requestId = params.requestId;
|
|
288
|
-
if (requestId !== void 0) _optionalChain([running, 'access', _7 => _7.get, 'call', _8 => _8(requestId), 'optionalAccess', _9 => _9.abort, 'call', _10 => _10(params.reason)]);
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
case "ping":
|
|
292
|
-
return { jsonrpc: "2.0", id, result: {} };
|
|
293
|
-
case "tools/list":
|
|
294
|
-
return { jsonrpc: "2.0", id, result: registry.listTools() };
|
|
295
|
-
case "tools/call": {
|
|
296
|
-
const name = params.name;
|
|
297
|
-
if (typeof name !== "string") {
|
|
298
|
-
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, 'tools/call needs a string "name".');
|
|
299
|
-
}
|
|
300
|
-
if (!registry.hasTool(name)) {
|
|
301
|
-
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, `Unknown tool: ${name}`);
|
|
302
|
-
}
|
|
303
|
-
const args = params.arguments;
|
|
304
|
-
if (args !== void 0 && (typeof args !== "object" || args === null || Array.isArray(args))) {
|
|
305
|
-
return errorResponse(id, JSON_RPC_ERRORS.invalidParams, '"arguments" must be an object.');
|
|
306
|
-
}
|
|
307
|
-
const controller = new AbortController();
|
|
308
|
-
if (!isNotification) running.set(id, controller);
|
|
309
|
-
try {
|
|
310
|
-
const result = await registry.callTool(name, _nullishCoalesce(args, () => ( {})), { signal: controller.signal });
|
|
311
|
-
if (controller.signal.aborted) return null;
|
|
312
|
-
return { jsonrpc: "2.0", id, result };
|
|
313
|
-
} finally {
|
|
314
|
-
if (!isNotification) running.delete(id);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
default:
|
|
318
|
-
if (isNotification) return null;
|
|
319
|
-
return errorResponse(id, JSON_RPC_ERRORS.methodNotFound, `Method not found: ${request.method}`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return {
|
|
323
|
-
get initialized() {
|
|
324
|
-
return initialized;
|
|
325
|
-
},
|
|
326
|
-
async handle(message) {
|
|
327
|
-
let request;
|
|
328
|
-
if (typeof message === "string") {
|
|
329
|
-
try {
|
|
330
|
-
request = JSON.parse(message);
|
|
331
|
-
} catch (e3) {
|
|
332
|
-
return errorResponse(null, JSON_RPC_ERRORS.parseError, "Parse error.");
|
|
333
|
-
}
|
|
334
|
-
} else {
|
|
335
|
-
request = message;
|
|
336
|
-
}
|
|
337
|
-
if (!request || typeof request !== "object" || Array.isArray(request) || request.jsonrpc !== "2.0" || typeof request.method !== "string") {
|
|
338
|
-
const id = request && typeof request === "object" && !Array.isArray(request) ? _nullishCoalesce(request.id, () => ( null)) : null;
|
|
339
|
-
return errorResponse(id, JSON_RPC_ERRORS.invalidRequest, "Invalid JSON-RPC 2.0 request.");
|
|
340
|
-
}
|
|
341
|
-
try {
|
|
342
|
-
return await dispatch(request);
|
|
343
|
-
} catch (error) {
|
|
344
|
-
if (request.id === void 0 || request.id === null) return null;
|
|
345
|
-
return errorResponse(
|
|
346
|
-
request.id,
|
|
347
|
-
JSON_RPC_ERRORS.internalError,
|
|
348
|
-
error instanceof Error ? error.message : String(error)
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
close() {
|
|
353
|
-
_optionalChain([unsubscribe, 'optionalCall', _11 => _11()]);
|
|
354
|
-
unsubscribe = null;
|
|
355
|
-
for (const controller of running.values()) controller.abort("Server closed.");
|
|
356
|
-
running.clear();
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// src/tools/bridge-client.ts
|
|
362
|
-
var TOOL_BRIDGE_PROTOCOL = 1;
|
|
363
|
-
var TOOL_BRIDGE_DEFAULT_PORT = 4477;
|
|
364
|
-
function connectToolBridge(registry, options) {
|
|
365
|
-
const Ctor = _nullishCoalesce(options.WebSocket, () => ( globalThis.WebSocket));
|
|
366
|
-
if (!Ctor) throw new Error("No WebSocket implementation: pass options.WebSocket.");
|
|
367
|
-
const base = _nullishCoalesce(options.url, () => ( `ws://127.0.0.1:${TOOL_BRIDGE_DEFAULT_PORT}`));
|
|
368
|
-
const url = options.token ? `${base}${base.includes("?") ? "&" : "?"}token=${encodeURIComponent(options.token)}` : base;
|
|
369
|
-
let status = "connecting";
|
|
370
|
-
let editorId = null;
|
|
371
|
-
let socket = null;
|
|
372
|
-
let closed = false;
|
|
373
|
-
let delay = 500;
|
|
374
|
-
let retry = null;
|
|
375
|
-
const running = /* @__PURE__ */ new Map();
|
|
376
|
-
const setStatus = (next, detail) => {
|
|
377
|
-
if (next === status && !detail) return;
|
|
378
|
-
status = next;
|
|
379
|
-
_optionalChain([options, 'access', _12 => _12.onStatus, 'optionalCall', _13 => _13(next, detail)]);
|
|
380
|
-
};
|
|
381
|
-
const send = (message) => {
|
|
382
|
-
if (socket && socket.readyState === 1) socket.send(JSON.stringify(message));
|
|
383
|
-
};
|
|
384
|
-
const unsubscribe = registry.onListChanged((tools) => send({ t: "tools", tools }));
|
|
385
|
-
const open = () => {
|
|
386
|
-
if (closed) return;
|
|
387
|
-
setStatus("connecting");
|
|
388
|
-
const ws = new Ctor(url);
|
|
389
|
-
socket = ws;
|
|
390
|
-
ws.addEventListener("open", () => {
|
|
391
|
-
delay = 500;
|
|
392
|
-
send({ t: "hello", v: TOOL_BRIDGE_PROTOCOL, name: options.name, ...options.kind ? { kind: options.kind } : {}, tools: registry.listTools().tools });
|
|
393
|
-
});
|
|
394
|
-
ws.addEventListener("message", (event) => {
|
|
395
|
-
let message;
|
|
396
|
-
try {
|
|
397
|
-
message = JSON.parse(String(event.data));
|
|
398
|
-
} catch (e4) {
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
if (message.t === "welcome") {
|
|
402
|
-
editorId = message.id;
|
|
403
|
-
setStatus("connected");
|
|
404
|
-
} else if (message.t === "call") {
|
|
405
|
-
const controller = new AbortController();
|
|
406
|
-
running.set(message.id, controller);
|
|
407
|
-
void registry.callTool(message.name, _nullishCoalesce(message.arguments, () => ( {})), { signal: controller.signal }).then((result) => {
|
|
408
|
-
running.delete(message.id);
|
|
409
|
-
if (!controller.signal.aborted) send({ t: "result", id: message.id, result });
|
|
410
|
-
});
|
|
411
|
-
} else if (message.t === "cancel") {
|
|
412
|
-
_optionalChain([running, 'access', _14 => _14.get, 'call', _15 => _15(message.id), 'optionalAccess', _16 => _16.abort, 'call', _17 => _17(_nullishCoalesce(message.reason, () => ( "Cancelled by the agent.")))]);
|
|
413
|
-
running.delete(message.id);
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
ws.addEventListener("close", (event) => {
|
|
417
|
-
if (socket !== ws) return;
|
|
418
|
-
socket = null;
|
|
419
|
-
editorId = null;
|
|
420
|
-
for (const controller of running.values()) controller.abort("The bridge disconnected.");
|
|
421
|
-
running.clear();
|
|
422
|
-
if (closed) return setStatus("closed");
|
|
423
|
-
setStatus("disconnected", event.reason || void 0);
|
|
424
|
-
if (options.reconnect === false) return;
|
|
425
|
-
retry = setTimeout(open, delay);
|
|
426
|
-
delay = Math.min(1e4, delay * 2);
|
|
427
|
-
});
|
|
428
|
-
ws.addEventListener("error", () => {
|
|
429
|
-
});
|
|
430
|
-
};
|
|
431
|
-
open();
|
|
432
|
-
return {
|
|
433
|
-
get status() {
|
|
434
|
-
return status;
|
|
435
|
-
},
|
|
436
|
-
get editorId() {
|
|
437
|
-
return editorId;
|
|
438
|
-
},
|
|
439
|
-
close() {
|
|
440
|
-
if (closed) return;
|
|
441
|
-
closed = true;
|
|
442
|
-
if (retry) clearTimeout(retry);
|
|
443
|
-
unsubscribe();
|
|
444
|
-
for (const controller of running.values()) controller.abort("The editor disconnected.");
|
|
445
|
-
running.clear();
|
|
446
|
-
const ws = socket;
|
|
447
|
-
socket = null;
|
|
448
|
-
_optionalChain([ws, 'optionalAccess', _18 => _18.close, 'call', _19 => _19(1e3, "Editor closed.")]);
|
|
449
|
-
setStatus("closed");
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
exports.ToolRegistryError = ToolRegistryError; exports.TOOL_NAMESPACE_SEPARATOR = TOOL_NAMESPACE_SEPARATOR; exports.toToolResult = toToolResult; exports.ToolRegistry = ToolRegistry; exports.createToolRegistry = createToolRegistry; exports.MCP_PROTOCOL_VERSIONS = MCP_PROTOCOL_VERSIONS; exports.JSON_RPC_ERRORS = JSON_RPC_ERRORS; exports.createMcpServer = createMcpServer; exports.TOOL_BRIDGE_PROTOCOL = TOOL_BRIDGE_PROTOCOL; exports.TOOL_BRIDGE_DEFAULT_PORT = TOOL_BRIDGE_DEFAULT_PORT; exports.connectToolBridge = connectToolBridge;
|
|
File without changes
|
|
File without changes
|