poe-code 3.0.231 → 3.0.233
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.js +12 -7
- package/dist/agent.js.map +3 -3
- package/dist/index.js +536 -229
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -0
- package/dist/providers/poe-agent.js +424 -126
- package/dist/providers/poe-agent.js.map +4 -4
- package/package.json +6 -1
- package/packages/agent-skill-config/dist/index.d.ts +1 -0
- package/packages/agent-skill-config/dist/index.js +1 -0
- package/packages/memory/dist/explain.js +1 -1
- package/packages/memory/dist/index.js +315 -44
- package/packages/memory/dist/index.js.map +4 -4
- package/packages/memory/dist/query.js +1 -1
- package/packages/memory/dist/tokens.js +1 -1
- package/packages/superintendent/dist/mcp.js +41194 -151
- package/packages/superintendent/dist/mcp.js.map +7 -0
- package/packages/tiny-stdio-mcp-server/dist/index.d.ts +1 -1
- package/packages/tiny-stdio-mcp-server/dist/server.d.ts +12 -2
- package/packages/tiny-stdio-mcp-server/dist/server.js +310 -40
- package/packages/tiny-stdio-mcp-server/dist/types.d.ts +136 -9
- package/packages/tiny-stdio-mcp-server/dist/types.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poe-code",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.233",
|
|
4
4
|
"description": "CLI tool to configure Poe API for developer workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"check:semver": "node -e \"const semver=require('semver'); const pkg=require('./package.json'); if(!semver.valid(pkg.version)){console.error('Invalid semver version in package.json:', pkg.version); process.exit(1);}\"",
|
|
39
39
|
"lint": "npm run lint:eslint && npm run lint:types && npm run lint:workflows",
|
|
40
40
|
"lint:workflows": "(command -v actionlint > /dev/null || bash scripts/setup-actionlint.sh) && (command -v actionlint > /dev/null && actionlint || ./actionlint)",
|
|
41
|
+
"lint:packages": "poe-package-lint",
|
|
41
42
|
"lint:eslint": "eslint . --ext ts",
|
|
42
43
|
"lint:types": "tsc -p tsconfig.build.json --noEmit",
|
|
43
44
|
"labels:generate": "tsx scripts/generate-labels.ts",
|
|
@@ -111,6 +112,7 @@
|
|
|
111
112
|
"packageManager": "npm@10.9.2",
|
|
112
113
|
"dependencies": {
|
|
113
114
|
"@clack/prompts": "^1.0.0",
|
|
115
|
+
"ajv": "^8.20.0",
|
|
114
116
|
"chalk": "^5.6.2",
|
|
115
117
|
"commander": "^14.0.3",
|
|
116
118
|
"console-table-printer": "^2.15.0",
|
|
@@ -129,6 +131,8 @@
|
|
|
129
131
|
"smol-toml": "^1.6.0",
|
|
130
132
|
"tiktoken": "^1.0.22",
|
|
131
133
|
"turndown": "^7.2.4",
|
|
134
|
+
"uri-template": "^2.0.0",
|
|
135
|
+
"uri-template-lite": "^23.4.0",
|
|
132
136
|
"yaml": "^2.8.2"
|
|
133
137
|
},
|
|
134
138
|
"devDependencies": {
|
|
@@ -160,6 +164,7 @@
|
|
|
160
164
|
"@poe-code/maestro-tui": "*",
|
|
161
165
|
"@poe-code/markdown-reader": "*",
|
|
162
166
|
"@poe-code/memory": "*",
|
|
167
|
+
"@poe-code/package-lint": "*",
|
|
163
168
|
"@poe-code/pipeline": "*",
|
|
164
169
|
"@poe-code/plan-browser": "*",
|
|
165
170
|
"@poe-code/poe-acp-client": "*",
|
|
@@ -7,4 +7,5 @@ export { configure, unconfigure, installSkill, UnsupportedAgentError } from "./a
|
|
|
7
7
|
export type { InstallSkillOptions, InstallSkillResult } from "./apply.js";
|
|
8
8
|
export { resolveSkillReference } from "./resolve-skill-reference.js";
|
|
9
9
|
export { appendExcludeBlock, removeExcludeBlock } from "./git-exclude.js";
|
|
10
|
+
export { setGitDirRunnerForTest } from "./git-exclude.js";
|
|
10
11
|
export { bridgeActiveSkills, cleanupBridgedSkills } from "./bridge-active-skills.js";
|
|
@@ -2,4 +2,5 @@ export { supportedAgents, resolveAgentSupport, getAgentConfig, resolveSkillDir }
|
|
|
2
2
|
export { configure, unconfigure, installSkill, UnsupportedAgentError } from "./apply.js";
|
|
3
3
|
export { resolveSkillReference } from "./resolve-skill-reference.js";
|
|
4
4
|
export { appendExcludeBlock, removeExcludeBlock } from "./git-exclude.js";
|
|
5
|
+
export { setGitDirRunnerForTest } from "./git-exclude.js";
|
|
5
6
|
export { bridgeActiveSkills, cleanupBridgedSkills } from "./bridge-active-skills.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { countTokens } from "
|
|
3
|
+
import { countTokens } from "tokenfill";
|
|
4
4
|
import { spawn } from "@poe-code/agent-spawn";
|
|
5
5
|
import { resolveAgent } from "@poe-code/poe-code-config";
|
|
6
6
|
import { readPage } from "./pages.js";
|
|
@@ -12258,7 +12258,7 @@ import { mkdir as mkdir6, open as open2 } from "node:fs/promises";
|
|
|
12258
12258
|
import * as fs15 from "node:fs/promises";
|
|
12259
12259
|
import path52 from "node:path";
|
|
12260
12260
|
|
|
12261
|
-
// packages/tokenfill/
|
|
12261
|
+
// packages/tokenfill/src/tokenizer.ts
|
|
12262
12262
|
import { get_encoding } from "tiktoken";
|
|
12263
12263
|
var DEFAULT_ENCODING = "cl100k_base";
|
|
12264
12264
|
function createTokenizer(options = {}) {
|
|
@@ -12287,10 +12287,14 @@ function createTokenizer(options = {}) {
|
|
|
12287
12287
|
try {
|
|
12288
12288
|
truncated = strictUtf8Decoder.decode(tokenizer.decode(tokens.slice(0, tokenCount)));
|
|
12289
12289
|
} catch {
|
|
12290
|
-
throw new Error(
|
|
12290
|
+
throw new Error(
|
|
12291
|
+
`Cannot truncate text to exactly ${tokenCount} tokens without corrupting UTF-8 text.`
|
|
12292
|
+
);
|
|
12291
12293
|
}
|
|
12292
12294
|
if (count(truncated) !== tokenCount) {
|
|
12293
|
-
throw new Error(
|
|
12295
|
+
throw new Error(
|
|
12296
|
+
`Cannot truncate text to exactly ${tokenCount} tokens without changing token boundaries.`
|
|
12297
|
+
);
|
|
12294
12298
|
}
|
|
12295
12299
|
return truncated;
|
|
12296
12300
|
};
|
|
@@ -12309,7 +12313,7 @@ function countTokens(text5) {
|
|
|
12309
12313
|
return defaultTokenizer.count(text5);
|
|
12310
12314
|
}
|
|
12311
12315
|
|
|
12312
|
-
// packages/tokenfill/
|
|
12316
|
+
// packages/tokenfill/src/corpus.ts
|
|
12313
12317
|
import { readdirSync as readdirSync2, readFileSync as readFileSync8 } from "node:fs";
|
|
12314
12318
|
import { dirname, join as join2 } from "node:path";
|
|
12315
12319
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -12327,7 +12331,7 @@ function loadBuiltInCorpusArticles() {
|
|
|
12327
12331
|
}
|
|
12328
12332
|
var BUILT_IN_CORPUS_ARTICLES = loadBuiltInCorpusArticles();
|
|
12329
12333
|
|
|
12330
|
-
// packages/tokenfill/
|
|
12334
|
+
// packages/tokenfill/src/tokenfill.ts
|
|
12331
12335
|
var builtInCorpusText = BUILT_IN_CORPUS_ARTICLES.join(CORPUS_ARTICLE_SEPARATOR);
|
|
12332
12336
|
var builtInCorpusByteLength = Buffer.byteLength(builtInCorpusText, "utf8");
|
|
12333
12337
|
|
|
@@ -12564,6 +12568,9 @@ async function runWithTimeout(promise, timeoutMs, onTimeout) {
|
|
|
12564
12568
|
|
|
12565
12569
|
// packages/tiny-stdio-mcp-server/src/server.ts
|
|
12566
12570
|
import * as readline2 from "readline";
|
|
12571
|
+
import AjvModule from "ajv";
|
|
12572
|
+
import uriTemplateParser from "uri-template";
|
|
12573
|
+
import UriTemplate from "uri-template-lite";
|
|
12567
12574
|
|
|
12568
12575
|
// packages/tiny-stdio-mcp-server/src/types.ts
|
|
12569
12576
|
var JSON_RPC_ERROR_CODES = Object.freeze({
|
|
@@ -12571,7 +12578,8 @@ var JSON_RPC_ERROR_CODES = Object.freeze({
|
|
|
12571
12578
|
INVALID_REQUEST: -32600,
|
|
12572
12579
|
METHOD_NOT_FOUND: -32601,
|
|
12573
12580
|
INVALID_PARAMS: -32602,
|
|
12574
|
-
INTERNAL_ERROR: -32603
|
|
12581
|
+
INTERNAL_ERROR: -32603,
|
|
12582
|
+
RESOURCE_NOT_FOUND: -32002
|
|
12575
12583
|
});
|
|
12576
12584
|
var ToolError = class extends Error {
|
|
12577
12585
|
constructor(code, message2) {
|
|
@@ -13074,12 +13082,21 @@ var SUPPORTED_PROTOCOL_VERSIONS = /* @__PURE__ */ new Set([
|
|
|
13074
13082
|
PROTOCOL_VERSION
|
|
13075
13083
|
]);
|
|
13076
13084
|
function createServer(options) {
|
|
13085
|
+
const Ajv = "default" in AjvModule ? AjvModule.default : AjvModule;
|
|
13086
|
+
const jsonSchemaValidator = new Ajv({ strict: false });
|
|
13087
|
+
const supportNotifications = options.supportNotifications !== false;
|
|
13088
|
+
const supportResourceSubscriptions = options.supportResourceSubscriptions !== false;
|
|
13077
13089
|
const tools = /* @__PURE__ */ new Map();
|
|
13090
|
+
const prompts = /* @__PURE__ */ new Map();
|
|
13091
|
+
const resources = /* @__PURE__ */ new Map();
|
|
13092
|
+
const resourceTemplates = /* @__PURE__ */ new Map();
|
|
13078
13093
|
const notificationListeners = /* @__PURE__ */ new Set();
|
|
13079
13094
|
const connectionNotificationListeners = /* @__PURE__ */ new Map();
|
|
13080
13095
|
const defaultLifecycle = {
|
|
13081
13096
|
initialized: false,
|
|
13082
|
-
initializeAccepted: false
|
|
13097
|
+
initializeAccepted: false,
|
|
13098
|
+
notificationReady: false,
|
|
13099
|
+
resourceSubscriptions: /* @__PURE__ */ new Set()
|
|
13083
13100
|
};
|
|
13084
13101
|
const messageLifecycles = /* @__PURE__ */ new Set([defaultLifecycle]);
|
|
13085
13102
|
const handleMessageWithLifecycle = async (method, lifecycle, params) => {
|
|
@@ -13089,12 +13106,20 @@ function createServer(options) {
|
|
|
13089
13106
|
if (method === "initialize") {
|
|
13090
13107
|
lifecycle.initializeAccepted = true;
|
|
13091
13108
|
lifecycle.initialized = true;
|
|
13109
|
+
lifecycle.notificationReady = false;
|
|
13092
13110
|
const requestedProtocol = typeof params?.protocolVersion === "string" ? params.protocolVersion : void 0;
|
|
13093
13111
|
const result = {
|
|
13094
13112
|
protocolVersion: requestedProtocol !== void 0 && SUPPORTED_PROTOCOL_VERSIONS.has(requestedProtocol) ? requestedProtocol : PROTOCOL_VERSION,
|
|
13095
13113
|
capabilities: {
|
|
13096
13114
|
tools: {
|
|
13097
|
-
listChanged: true
|
|
13115
|
+
...supportNotifications ? { listChanged: true } : {}
|
|
13116
|
+
},
|
|
13117
|
+
prompts: {
|
|
13118
|
+
...supportNotifications ? { listChanged: true } : {}
|
|
13119
|
+
},
|
|
13120
|
+
resources: {
|
|
13121
|
+
...supportNotifications ? { listChanged: true } : {},
|
|
13122
|
+
...supportResourceSubscriptions ? { subscribe: true } : {}
|
|
13098
13123
|
}
|
|
13099
13124
|
},
|
|
13100
13125
|
serverInfo: {
|
|
@@ -13113,6 +13138,7 @@ function createServer(options) {
|
|
|
13113
13138
|
}
|
|
13114
13139
|
};
|
|
13115
13140
|
}
|
|
13141
|
+
lifecycle.notificationReady = true;
|
|
13116
13142
|
return { result: void 0 };
|
|
13117
13143
|
}
|
|
13118
13144
|
if (!lifecycle.initialized) {
|
|
@@ -13126,10 +13152,10 @@ function createServer(options) {
|
|
|
13126
13152
|
if (method === "tools/list") {
|
|
13127
13153
|
const toolList = [];
|
|
13128
13154
|
for (const tool of tools.values()) {
|
|
13155
|
+
const descriptor = { ...tool };
|
|
13156
|
+
delete descriptor.handler;
|
|
13129
13157
|
toolList.push({
|
|
13130
|
-
|
|
13131
|
-
description: tool.description,
|
|
13132
|
-
inputSchema: tool.inputSchema
|
|
13158
|
+
...descriptor
|
|
13133
13159
|
});
|
|
13134
13160
|
}
|
|
13135
13161
|
return { result: { tools: toolList } };
|
|
@@ -13154,7 +13180,7 @@ function createServer(options) {
|
|
|
13154
13180
|
};
|
|
13155
13181
|
}
|
|
13156
13182
|
const toolArgs = params?.arguments ?? {};
|
|
13157
|
-
if (options.validateToolArguments !== false && !
|
|
13183
|
+
if (options.validateToolArguments !== false && !jsonSchemaValidator.validate(tool.inputSchema, toolArgs)) {
|
|
13158
13184
|
return {
|
|
13159
13185
|
error: {
|
|
13160
13186
|
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
@@ -13168,6 +13194,9 @@ function createServer(options) {
|
|
|
13168
13194
|
throw new Error("Invalid tool result");
|
|
13169
13195
|
}
|
|
13170
13196
|
const result = isCallToolResult(handlerResult) ? handlerResult : { content: toContentBlocks(handlerResult) };
|
|
13197
|
+
if (tool.outputSchema !== void 0 && (result.structuredContent === void 0 || !jsonSchemaValidator.validate(tool.outputSchema, result.structuredContent))) {
|
|
13198
|
+
throw new Error("Invalid structured tool result");
|
|
13199
|
+
}
|
|
13171
13200
|
return { result };
|
|
13172
13201
|
} catch (err) {
|
|
13173
13202
|
if (err instanceof ToolError) {
|
|
@@ -13186,6 +13215,94 @@ function createServer(options) {
|
|
|
13186
13215
|
return { result };
|
|
13187
13216
|
}
|
|
13188
13217
|
}
|
|
13218
|
+
if (method === "prompts/list") {
|
|
13219
|
+
return {
|
|
13220
|
+
result: {
|
|
13221
|
+
prompts: [...prompts.values()].map(({ handler: _handler, ...prompt }) => prompt)
|
|
13222
|
+
}
|
|
13223
|
+
};
|
|
13224
|
+
}
|
|
13225
|
+
if (method === "prompts/get") {
|
|
13226
|
+
const promptName = typeof params?.name === "string" ? params.name : void 0;
|
|
13227
|
+
if (promptName === void 0) {
|
|
13228
|
+
return invalidParams("Prompt name required");
|
|
13229
|
+
}
|
|
13230
|
+
const prompt = prompts.get(promptName);
|
|
13231
|
+
if (prompt === void 0) {
|
|
13232
|
+
return invalidParams(`Prompt not found: ${promptName}`);
|
|
13233
|
+
}
|
|
13234
|
+
const args = toStringArguments(params?.arguments);
|
|
13235
|
+
if (args === void 0 || !hasRequiredPromptArguments(prompt, args)) {
|
|
13236
|
+
return invalidParams("Invalid prompt arguments");
|
|
13237
|
+
}
|
|
13238
|
+
try {
|
|
13239
|
+
const result = await prompt.handler(args);
|
|
13240
|
+
if (!isGetPromptResult(result)) {
|
|
13241
|
+
return internalError("Invalid prompt result");
|
|
13242
|
+
}
|
|
13243
|
+
return { result };
|
|
13244
|
+
} catch (error2) {
|
|
13245
|
+
return internalError(toErrorMessage(error2));
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
if (method === "resources/list") {
|
|
13249
|
+
return {
|
|
13250
|
+
result: {
|
|
13251
|
+
resources: [...resources.values()].map(({ handler: _handler, ...resource }) => resource)
|
|
13252
|
+
}
|
|
13253
|
+
};
|
|
13254
|
+
}
|
|
13255
|
+
if (method === "resources/templates/list") {
|
|
13256
|
+
return {
|
|
13257
|
+
result: {
|
|
13258
|
+
resourceTemplates: [...resourceTemplates.values()].map(
|
|
13259
|
+
({ handler: _handler, ...resourceTemplate }) => resourceTemplate
|
|
13260
|
+
)
|
|
13261
|
+
}
|
|
13262
|
+
};
|
|
13263
|
+
}
|
|
13264
|
+
if (method === "resources/read") {
|
|
13265
|
+
const uri = typeof params?.uri === "string" ? params.uri : void 0;
|
|
13266
|
+
if (uri === void 0 || !isValidUri(uri)) {
|
|
13267
|
+
return invalidParams("Resource URI required");
|
|
13268
|
+
}
|
|
13269
|
+
const resource = findReadableResource(uri, resources, resourceTemplates);
|
|
13270
|
+
if (resource === void 0) {
|
|
13271
|
+
return resourceNotFound(uri);
|
|
13272
|
+
}
|
|
13273
|
+
try {
|
|
13274
|
+
const result = await resource.handler(uri);
|
|
13275
|
+
if (!isReadResourceResult(result)) {
|
|
13276
|
+
return internalError("Invalid resource result");
|
|
13277
|
+
}
|
|
13278
|
+
return { result };
|
|
13279
|
+
} catch (error2) {
|
|
13280
|
+
return internalError(toErrorMessage(error2));
|
|
13281
|
+
}
|
|
13282
|
+
}
|
|
13283
|
+
if (method === "resources/subscribe" || method === "resources/unsubscribe") {
|
|
13284
|
+
if (!supportResourceSubscriptions) {
|
|
13285
|
+
return {
|
|
13286
|
+
error: {
|
|
13287
|
+
code: JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND,
|
|
13288
|
+
message: "Method not found"
|
|
13289
|
+
}
|
|
13290
|
+
};
|
|
13291
|
+
}
|
|
13292
|
+
const uri = typeof params?.uri === "string" ? params.uri : void 0;
|
|
13293
|
+
if (uri === void 0 || !isValidUri(uri)) {
|
|
13294
|
+
return invalidParams("Resource URI required");
|
|
13295
|
+
}
|
|
13296
|
+
if (method === "resources/subscribe" && findReadableResource(uri, resources, resourceTemplates) === void 0) {
|
|
13297
|
+
return resourceNotFound(uri);
|
|
13298
|
+
}
|
|
13299
|
+
if (method === "resources/subscribe") {
|
|
13300
|
+
lifecycle.resourceSubscriptions.add(uri);
|
|
13301
|
+
} else {
|
|
13302
|
+
lifecycle.resourceSubscriptions.delete(uri);
|
|
13303
|
+
}
|
|
13304
|
+
return { result: {} };
|
|
13305
|
+
}
|
|
13189
13306
|
return {
|
|
13190
13307
|
error: {
|
|
13191
13308
|
code: JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND,
|
|
@@ -13193,15 +13310,23 @@ function createServer(options) {
|
|
|
13193
13310
|
}
|
|
13194
13311
|
};
|
|
13195
13312
|
};
|
|
13196
|
-
const createMessageSession = () => {
|
|
13313
|
+
const createMessageSession = (listener) => {
|
|
13197
13314
|
const lifecycle = {
|
|
13198
13315
|
initialized: false,
|
|
13199
|
-
initializeAccepted: false
|
|
13316
|
+
initializeAccepted: false,
|
|
13317
|
+
notificationReady: false,
|
|
13318
|
+
resourceSubscriptions: /* @__PURE__ */ new Set()
|
|
13200
13319
|
};
|
|
13201
13320
|
messageLifecycles.add(lifecycle);
|
|
13321
|
+
if (listener !== void 0) {
|
|
13322
|
+
connectionNotificationListeners.set(listener, lifecycle);
|
|
13323
|
+
}
|
|
13202
13324
|
return {
|
|
13203
13325
|
handleMessage: (method, params) => handleMessageWithLifecycle(method, lifecycle, params),
|
|
13204
13326
|
close: () => {
|
|
13327
|
+
if (listener !== void 0) {
|
|
13328
|
+
connectionNotificationListeners.delete(listener);
|
|
13329
|
+
}
|
|
13205
13330
|
messageLifecycles.delete(lifecycle);
|
|
13206
13331
|
}
|
|
13207
13332
|
};
|
|
@@ -13236,17 +13361,18 @@ function createServer(options) {
|
|
|
13236
13361
|
write2(formatSuccessResponse(requestWithId.id, result) + "\n");
|
|
13237
13362
|
}
|
|
13238
13363
|
};
|
|
13239
|
-
const broadcastNotification = async (method) => {
|
|
13364
|
+
const broadcastNotification = async (method, params, canSend = () => true) => {
|
|
13240
13365
|
const notification = {
|
|
13241
13366
|
jsonrpc: "2.0",
|
|
13242
|
-
method
|
|
13367
|
+
method,
|
|
13368
|
+
...params === void 0 ? {} : { params }
|
|
13243
13369
|
};
|
|
13244
13370
|
for (const listener of notificationListeners) {
|
|
13245
13371
|
listener(notification);
|
|
13246
13372
|
}
|
|
13247
13373
|
await Promise.all(
|
|
13248
13374
|
[...connectionNotificationListeners].map(async ([listener, lifecycle]) => {
|
|
13249
|
-
if (lifecycle.
|
|
13375
|
+
if (lifecycle.notificationReady && canSend(lifecycle)) {
|
|
13250
13376
|
await listener(notification);
|
|
13251
13377
|
}
|
|
13252
13378
|
})
|
|
@@ -13262,6 +13388,30 @@ function createServer(options) {
|
|
|
13262
13388
|
});
|
|
13263
13389
|
return server;
|
|
13264
13390
|
},
|
|
13391
|
+
registerTool(definition, handler) {
|
|
13392
|
+
tools.set(definition.name, {
|
|
13393
|
+
...definition,
|
|
13394
|
+
handler
|
|
13395
|
+
});
|
|
13396
|
+
return server;
|
|
13397
|
+
},
|
|
13398
|
+
prompt(definition, handler) {
|
|
13399
|
+
prompts.set(definition.name, { ...definition, handler });
|
|
13400
|
+
return server;
|
|
13401
|
+
},
|
|
13402
|
+
resource(definition, handler) {
|
|
13403
|
+
if (!isValidUri(definition.uri)) {
|
|
13404
|
+
throw new Error(`Invalid resource URI: ${definition.uri}`);
|
|
13405
|
+
}
|
|
13406
|
+
resources.set(definition.uri, { ...definition, handler });
|
|
13407
|
+
return server;
|
|
13408
|
+
},
|
|
13409
|
+
resourceTemplate(definition, handler) {
|
|
13410
|
+
uriTemplateParser.parse(definition.uriTemplate);
|
|
13411
|
+
new UriTemplate(definition.uriTemplate);
|
|
13412
|
+
resourceTemplates.set(definition.uriTemplate, { ...definition, handler });
|
|
13413
|
+
return server;
|
|
13414
|
+
},
|
|
13265
13415
|
onNotification(listener) {
|
|
13266
13416
|
notificationListeners.add(listener);
|
|
13267
13417
|
return () => {
|
|
@@ -13271,11 +13421,40 @@ function createServer(options) {
|
|
|
13271
13421
|
removeTool(name) {
|
|
13272
13422
|
return tools.delete(name);
|
|
13273
13423
|
},
|
|
13424
|
+
removePrompt(name) {
|
|
13425
|
+
return prompts.delete(name);
|
|
13426
|
+
},
|
|
13427
|
+
removeResource(uri) {
|
|
13428
|
+
return resources.delete(uri);
|
|
13429
|
+
},
|
|
13430
|
+
removeResourceTemplate(uriTemplate) {
|
|
13431
|
+
return resourceTemplates.delete(uriTemplate);
|
|
13432
|
+
},
|
|
13274
13433
|
async notifyToolsChanged() {
|
|
13275
|
-
if ([...messageLifecycles].some((lifecycle) => lifecycle.
|
|
13434
|
+
if (supportNotifications && [...messageLifecycles].some((lifecycle) => lifecycle.notificationReady)) {
|
|
13276
13435
|
await broadcastNotification("notifications/tools/list_changed");
|
|
13277
13436
|
}
|
|
13278
13437
|
},
|
|
13438
|
+
async notifyPromptsChanged() {
|
|
13439
|
+
if (supportNotifications && [...messageLifecycles].some((lifecycle) => lifecycle.notificationReady)) {
|
|
13440
|
+
await broadcastNotification("notifications/prompts/list_changed");
|
|
13441
|
+
}
|
|
13442
|
+
},
|
|
13443
|
+
async notifyResourcesChanged() {
|
|
13444
|
+
if (supportNotifications && [...messageLifecycles].some((lifecycle) => lifecycle.notificationReady)) {
|
|
13445
|
+
await broadcastNotification("notifications/resources/list_changed");
|
|
13446
|
+
}
|
|
13447
|
+
},
|
|
13448
|
+
async notifyResourceUpdated(uri) {
|
|
13449
|
+
if (!supportResourceSubscriptions) {
|
|
13450
|
+
return;
|
|
13451
|
+
}
|
|
13452
|
+
await broadcastNotification(
|
|
13453
|
+
"notifications/resources/updated",
|
|
13454
|
+
{ uri },
|
|
13455
|
+
(lifecycle) => lifecycle.resourceSubscriptions.has(uri)
|
|
13456
|
+
);
|
|
13457
|
+
},
|
|
13279
13458
|
createMessageSession,
|
|
13280
13459
|
handleMessage,
|
|
13281
13460
|
async listen() {
|
|
@@ -13286,7 +13465,7 @@ function createServer(options) {
|
|
|
13286
13465
|
},
|
|
13287
13466
|
async connect(transport) {
|
|
13288
13467
|
return new Promise((resolve2) => {
|
|
13289
|
-
const lifecycle = { initialized: false, initializeAccepted: false };
|
|
13468
|
+
const lifecycle = { initialized: false, initializeAccepted: false, notificationReady: false, resourceSubscriptions: /* @__PURE__ */ new Set() };
|
|
13290
13469
|
const messageHandler = (method, params) => handleMessageWithLifecycle(method, lifecycle, params);
|
|
13291
13470
|
messageLifecycles.add(lifecycle);
|
|
13292
13471
|
const listener = (notification) => {
|
|
@@ -13316,7 +13495,7 @@ function createServer(options) {
|
|
|
13316
13495
|
},
|
|
13317
13496
|
async connectSDK(transport) {
|
|
13318
13497
|
return new Promise((resolve2, reject) => {
|
|
13319
|
-
const lifecycle = { initialized: false, initializeAccepted: false };
|
|
13498
|
+
const lifecycle = { initialized: false, initializeAccepted: false, notificationReady: false, resourceSubscriptions: /* @__PURE__ */ new Set() };
|
|
13320
13499
|
const messageHandler = (method, params) => handleMessageWithLifecycle(method, lifecycle, params);
|
|
13321
13500
|
messageLifecycles.add(lifecycle);
|
|
13322
13501
|
const listener = (notification) => transport.send(notification);
|
|
@@ -13376,35 +13555,99 @@ function createServer(options) {
|
|
|
13376
13555
|
};
|
|
13377
13556
|
return server;
|
|
13378
13557
|
}
|
|
13379
|
-
function
|
|
13380
|
-
return
|
|
13558
|
+
function invalidParams(message2) {
|
|
13559
|
+
return {
|
|
13560
|
+
error: {
|
|
13561
|
+
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
13562
|
+
message: message2
|
|
13563
|
+
}
|
|
13564
|
+
};
|
|
13381
13565
|
}
|
|
13382
|
-
function
|
|
13383
|
-
return
|
|
13566
|
+
function internalError(message2) {
|
|
13567
|
+
return {
|
|
13568
|
+
error: {
|
|
13569
|
+
code: JSON_RPC_ERROR_CODES.INTERNAL_ERROR,
|
|
13570
|
+
message: message2
|
|
13571
|
+
}
|
|
13572
|
+
};
|
|
13384
13573
|
}
|
|
13385
|
-
function
|
|
13386
|
-
|
|
13574
|
+
function resourceNotFound(uri) {
|
|
13575
|
+
return {
|
|
13576
|
+
error: {
|
|
13577
|
+
code: JSON_RPC_ERROR_CODES.RESOURCE_NOT_FOUND,
|
|
13578
|
+
message: `Resource not found: ${uri}`
|
|
13579
|
+
}
|
|
13580
|
+
};
|
|
13581
|
+
}
|
|
13582
|
+
function toErrorMessage(error2) {
|
|
13583
|
+
return error2 instanceof Error ? error2.message : String(error2);
|
|
13584
|
+
}
|
|
13585
|
+
function isValidUri(uri) {
|
|
13586
|
+
try {
|
|
13587
|
+
new URL(uri);
|
|
13588
|
+
return true;
|
|
13589
|
+
} catch {
|
|
13387
13590
|
return false;
|
|
13388
13591
|
}
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
}
|
|
13592
|
+
}
|
|
13593
|
+
function toStringArguments(value) {
|
|
13594
|
+
if (value === void 0) {
|
|
13595
|
+
return {};
|
|
13394
13596
|
}
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
if (argument
|
|
13401
|
-
|
|
13402
|
-
}
|
|
13403
|
-
if (property.type === "array" && !Array.isArray(argument) || property.type === "object" && (typeof argument !== "object" || argument === null || Array.isArray(argument)) || property.type === "integer" && !Number.isInteger(argument) || property.type !== "array" && property.type !== "object" && property.type !== "integer" && typeof argument !== property.type) {
|
|
13404
|
-
return false;
|
|
13597
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13598
|
+
return void 0;
|
|
13599
|
+
}
|
|
13600
|
+
const args = {};
|
|
13601
|
+
for (const [name, argument] of Object.entries(value)) {
|
|
13602
|
+
if (typeof argument !== "string") {
|
|
13603
|
+
return void 0;
|
|
13405
13604
|
}
|
|
13605
|
+
args[name] = argument;
|
|
13406
13606
|
}
|
|
13407
|
-
return
|
|
13607
|
+
return args;
|
|
13608
|
+
}
|
|
13609
|
+
function hasRequiredPromptArguments(prompt, args) {
|
|
13610
|
+
return (prompt.arguments ?? []).every(
|
|
13611
|
+
(argument) => argument.required !== true || args[argument.name] !== void 0
|
|
13612
|
+
);
|
|
13613
|
+
}
|
|
13614
|
+
function findReadableResource(uri, resources, resourceTemplates) {
|
|
13615
|
+
const resource = resources.get(uri);
|
|
13616
|
+
if (resource !== void 0) {
|
|
13617
|
+
return resource;
|
|
13618
|
+
}
|
|
13619
|
+
return [...resourceTemplates.values()].find(
|
|
13620
|
+
(template) => matchesUriTemplate(template.uriTemplate, uri)
|
|
13621
|
+
);
|
|
13622
|
+
}
|
|
13623
|
+
function matchesUriTemplate(template, uri) {
|
|
13624
|
+
try {
|
|
13625
|
+
return new UriTemplate(template).match(uri) !== null;
|
|
13626
|
+
} catch {
|
|
13627
|
+
return false;
|
|
13628
|
+
}
|
|
13629
|
+
}
|
|
13630
|
+
function isCallToolResult(value) {
|
|
13631
|
+
return hasContentArray(value) && value.content.every(isContentItem);
|
|
13632
|
+
}
|
|
13633
|
+
function isGetPromptResult(value) {
|
|
13634
|
+
if (typeof value !== "object" || value === null || !("messages" in value)) {
|
|
13635
|
+
return false;
|
|
13636
|
+
}
|
|
13637
|
+
return Array.isArray(value.messages) && value.messages.every(
|
|
13638
|
+
(message2) => typeof message2 === "object" && message2 !== null && "role" in message2 && (message2.role === "user" || message2.role === "assistant") && "content" in message2 && isPromptContentItem(message2.content)
|
|
13639
|
+
);
|
|
13640
|
+
}
|
|
13641
|
+
function isReadResourceResult(value) {
|
|
13642
|
+
if (typeof value !== "object" || value === null || !("contents" in value)) {
|
|
13643
|
+
return false;
|
|
13644
|
+
}
|
|
13645
|
+
return Array.isArray(value.contents) && value.contents.every(
|
|
13646
|
+
(content) => typeof content === "object" && content !== null && "uri" in content && typeof content.uri === "string" && isValidUri(content.uri) && ("text" in content && typeof content.text === "string" || "blob" in content && typeof content.blob === "string" && isBase64(content.blob))
|
|
13647
|
+
);
|
|
13648
|
+
}
|
|
13649
|
+
function hasContentArray(value) {
|
|
13650
|
+
return typeof value === "object" && value !== null && "content" in value && Array.isArray(value.content);
|
|
13408
13651
|
}
|
|
13409
13652
|
function isContentItem(value) {
|
|
13410
13653
|
if (typeof value !== "object" || value === null || !("type" in value)) {
|
|
@@ -13415,13 +13658,41 @@ function isContentItem(value) {
|
|
|
13415
13658
|
return typeof block.text === "string";
|
|
13416
13659
|
}
|
|
13417
13660
|
if (block.type === "image" || block.type === "audio") {
|
|
13418
|
-
return typeof block.data === "string" && typeof block.mimeType === "string";
|
|
13661
|
+
return typeof block.data === "string" && isBase64(block.data) && typeof block.mimeType === "string";
|
|
13662
|
+
}
|
|
13663
|
+
if (block.type === "resource_link") {
|
|
13664
|
+
return typeof block.uri === "string" && typeof block.name === "string";
|
|
13419
13665
|
}
|
|
13420
13666
|
if (block.type !== "resource" || typeof block.resource !== "object" || block.resource === null) {
|
|
13421
13667
|
return false;
|
|
13422
13668
|
}
|
|
13423
13669
|
const resource = block.resource;
|
|
13424
|
-
return typeof resource.uri === "string" && typeof resource.mimeType === "string" && (typeof resource.text === "string" || typeof resource.blob === "string");
|
|
13670
|
+
return typeof resource.uri === "string" && (resource.mimeType === void 0 || typeof resource.mimeType === "string") && (typeof resource.text === "string" || typeof resource.blob === "string" && isBase64(resource.blob));
|
|
13671
|
+
}
|
|
13672
|
+
function isBase64(value) {
|
|
13673
|
+
if (value.length === 0) {
|
|
13674
|
+
return true;
|
|
13675
|
+
}
|
|
13676
|
+
if (value.length % 4 !== 0) {
|
|
13677
|
+
return false;
|
|
13678
|
+
}
|
|
13679
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13680
|
+
const paddingStart = value.indexOf("=");
|
|
13681
|
+
const encoded = paddingStart === -1 ? value : value.slice(0, paddingStart);
|
|
13682
|
+
const padding = paddingStart === -1 ? "" : value.slice(paddingStart);
|
|
13683
|
+
if (padding.length > 2 || [...padding].some((character) => character !== "=")) {
|
|
13684
|
+
return false;
|
|
13685
|
+
}
|
|
13686
|
+
if ([...encoded].some((character) => !alphabet.includes(character))) {
|
|
13687
|
+
return false;
|
|
13688
|
+
}
|
|
13689
|
+
return Buffer.from(value, "base64").toString("base64") === value;
|
|
13690
|
+
}
|
|
13691
|
+
function isPromptContentItem(value) {
|
|
13692
|
+
if (!isContentItem(value)) {
|
|
13693
|
+
return false;
|
|
13694
|
+
}
|
|
13695
|
+
return !(typeof value === "object" && value !== null && "type" in value && value.type === "resource_link");
|
|
13425
13696
|
}
|
|
13426
13697
|
|
|
13427
13698
|
// packages/tiny-stdio-mcp-server/src/schema.ts
|