poe-code 3.0.273 → 3.0.275
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/index.js +51 -6
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/agent-mcp-config/dist/apply.js +36 -3
- package/packages/memory/dist/index.js +50 -5
- package/packages/memory/dist/index.js.map +3 -3
- package/packages/tokenfill/dist/cli.js +13 -4
- package/packages/tokenfill/dist/tokenizer.js +20 -3
package/package.json
CHANGED
|
@@ -15,6 +15,32 @@ export class UnsupportedAgentError extends Error {
|
|
|
15
15
|
function isConfigObject(value) {
|
|
16
16
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
17
17
|
}
|
|
18
|
+
function assertNonEmptyString(value, message) {
|
|
19
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
20
|
+
throw new Error(message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function assertHttpUrl(value) {
|
|
24
|
+
assertNonEmptyString(value, "MCP HTTP URL must be a valid http or https URL.");
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = new URL(value);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new Error("MCP HTTP URL must be a valid http or https URL.");
|
|
31
|
+
}
|
|
32
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
33
|
+
throw new Error("MCP HTTP URL must be a valid http or https URL.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function validateServerEntry(server) {
|
|
37
|
+
assertNonEmptyString(server.name, "MCP server name must be a non-empty string.");
|
|
38
|
+
if (server.config.transport === "stdio") {
|
|
39
|
+
assertNonEmptyString(server.config.command, "MCP stdio command must be a non-empty string.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
assertHttpUrl(server.config.url);
|
|
43
|
+
}
|
|
18
44
|
function resolveServerMap(document, configKey) {
|
|
19
45
|
const value = document[configKey];
|
|
20
46
|
if (value === undefined) {
|
|
@@ -32,12 +58,15 @@ export async function configure(agentId, server, options) {
|
|
|
32
58
|
if (!isSupported(agentId)) {
|
|
33
59
|
throw new UnsupportedAgentError(agentId);
|
|
34
60
|
}
|
|
61
|
+
validateServerEntry(server);
|
|
35
62
|
const config = getAgentConfig(agentId);
|
|
36
63
|
const configPath = resolveConfigPath(config, options.platform);
|
|
37
64
|
const shapeTransformer = getShapeTransformer(config.shape);
|
|
38
65
|
const shaped = shapeTransformer(server);
|
|
66
|
+
const enabledServer = { ...server, enabled: true };
|
|
67
|
+
const enabledShaped = shapeTransformer(enabledServer);
|
|
39
68
|
if (shaped === undefined) {
|
|
40
|
-
await unconfigure(agentId,
|
|
69
|
+
await unconfigure(agentId, enabledServer, options);
|
|
41
70
|
return;
|
|
42
71
|
}
|
|
43
72
|
const configDir = getConfigDirectory(configPath);
|
|
@@ -57,10 +86,13 @@ export async function configure(agentId, server, options) {
|
|
|
57
86
|
? servers[server.name]
|
|
58
87
|
: undefined;
|
|
59
88
|
const shapedServer = shaped;
|
|
89
|
+
const enabledShapedServer = enabledShaped;
|
|
60
90
|
if (existingServer !== undefined && isDeepStrictEqual(existingServer, shapedServer)) {
|
|
61
91
|
return { changed: false, content: document };
|
|
62
92
|
}
|
|
63
|
-
if (existingServer !== undefined &&
|
|
93
|
+
if (existingServer !== undefined &&
|
|
94
|
+
(enabledShapedServer === undefined ||
|
|
95
|
+
!isDeepStrictEqual(existingServer, enabledShapedServer))) {
|
|
64
96
|
throw new Error(`MCP server "${server.name}" already exists with different configuration in ${configPath}.`);
|
|
65
97
|
}
|
|
66
98
|
const newServers = {
|
|
@@ -98,7 +130,8 @@ export async function unconfigure(agentId, server, options) {
|
|
|
98
130
|
if (!Object.hasOwn(servers, serverName)) {
|
|
99
131
|
return { changed: false, content: document };
|
|
100
132
|
}
|
|
101
|
-
if (expectedServer !== undefined &&
|
|
133
|
+
if (expectedServer !== undefined &&
|
|
134
|
+
!isDeepStrictEqual(servers[serverName], expectedServer)) {
|
|
102
135
|
return { changed: false, content: document };
|
|
103
136
|
}
|
|
104
137
|
const newServers = { ...servers };
|
|
@@ -14185,12 +14185,28 @@ var DEFAULT_ENCODING = "cl100k_base";
|
|
|
14185
14185
|
function createTokenizer(options = {}) {
|
|
14186
14186
|
const encoding = options.encoding ?? DEFAULT_ENCODING;
|
|
14187
14187
|
const tokenizer = get_encoding(encoding);
|
|
14188
|
-
const utf8Decoder = new TextDecoder();
|
|
14189
14188
|
const strictUtf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
14190
14189
|
const encode = (text4) => tokenizer.encode(text4);
|
|
14190
|
+
const normalizeDecodeTokens = (tokens) => {
|
|
14191
|
+
if (tokens instanceof Uint32Array) {
|
|
14192
|
+
return tokens;
|
|
14193
|
+
}
|
|
14194
|
+
const tokenArray = new Uint32Array(tokens.length);
|
|
14195
|
+
tokens.forEach((token, index) => {
|
|
14196
|
+
if (!Number.isFinite(token) || !Number.isInteger(token) || token < 0 || token > 4294967295) {
|
|
14197
|
+
throw new TypeError(`token id at index ${index} must be a finite non-negative integer.`);
|
|
14198
|
+
}
|
|
14199
|
+
tokenArray[index] = token;
|
|
14200
|
+
});
|
|
14201
|
+
return tokenArray;
|
|
14202
|
+
};
|
|
14191
14203
|
const decode = (tokens) => {
|
|
14192
|
-
const tokenArray =
|
|
14193
|
-
|
|
14204
|
+
const tokenArray = normalizeDecodeTokens(tokens);
|
|
14205
|
+
try {
|
|
14206
|
+
return strictUtf8Decoder.decode(tokenizer.decode(tokenArray));
|
|
14207
|
+
} catch {
|
|
14208
|
+
throw new Error("Cannot decode tokens without corrupting UTF-8 text.");
|
|
14209
|
+
}
|
|
14194
14210
|
};
|
|
14195
14211
|
const count = (text4) => encode(text4).length;
|
|
14196
14212
|
const truncate2 = (text4, tokenCount) => {
|
|
@@ -16121,6 +16137,31 @@ var UnsupportedAgentError2 = class extends Error {
|
|
|
16121
16137
|
function isConfigObject6(value) {
|
|
16122
16138
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
16123
16139
|
}
|
|
16140
|
+
function assertNonEmptyString(value, message2) {
|
|
16141
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
16142
|
+
throw new Error(message2);
|
|
16143
|
+
}
|
|
16144
|
+
}
|
|
16145
|
+
function assertHttpUrl(value) {
|
|
16146
|
+
assertNonEmptyString(value, "MCP HTTP URL must be a valid http or https URL.");
|
|
16147
|
+
let parsed;
|
|
16148
|
+
try {
|
|
16149
|
+
parsed = new URL(value);
|
|
16150
|
+
} catch {
|
|
16151
|
+
throw new Error("MCP HTTP URL must be a valid http or https URL.");
|
|
16152
|
+
}
|
|
16153
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
16154
|
+
throw new Error("MCP HTTP URL must be a valid http or https URL.");
|
|
16155
|
+
}
|
|
16156
|
+
}
|
|
16157
|
+
function validateServerEntry(server) {
|
|
16158
|
+
assertNonEmptyString(server.name, "MCP server name must be a non-empty string.");
|
|
16159
|
+
if (server.config.transport === "stdio") {
|
|
16160
|
+
assertNonEmptyString(server.config.command, "MCP stdio command must be a non-empty string.");
|
|
16161
|
+
return;
|
|
16162
|
+
}
|
|
16163
|
+
assertHttpUrl(server.config.url);
|
|
16164
|
+
}
|
|
16124
16165
|
function resolveServerMap(document, configKey) {
|
|
16125
16166
|
const value = document[configKey];
|
|
16126
16167
|
if (value === void 0) {
|
|
@@ -16138,12 +16179,15 @@ async function configure2(agentId, server, options) {
|
|
|
16138
16179
|
if (!isSupported(agentId)) {
|
|
16139
16180
|
throw new UnsupportedAgentError2(agentId);
|
|
16140
16181
|
}
|
|
16182
|
+
validateServerEntry(server);
|
|
16141
16183
|
const config2 = getAgentConfig3(agentId);
|
|
16142
16184
|
const configPath = resolveConfigPath2(config2, options.platform);
|
|
16143
16185
|
const shapeTransformer = getShapeTransformer(config2.shape);
|
|
16144
16186
|
const shaped = shapeTransformer(server);
|
|
16187
|
+
const enabledServer = { ...server, enabled: true };
|
|
16188
|
+
const enabledShaped = shapeTransformer(enabledServer);
|
|
16145
16189
|
if (shaped === void 0) {
|
|
16146
|
-
await unconfigure2(agentId,
|
|
16190
|
+
await unconfigure2(agentId, enabledServer, options);
|
|
16147
16191
|
return;
|
|
16148
16192
|
}
|
|
16149
16193
|
const configDir = getConfigDirectory(configPath);
|
|
@@ -16162,10 +16206,11 @@ async function configure2(agentId, server, options) {
|
|
|
16162
16206
|
const servers = resolveServerMap(document, config2.configKey);
|
|
16163
16207
|
const existingServer = Object.hasOwn(servers, server.name) ? servers[server.name] : void 0;
|
|
16164
16208
|
const shapedServer = shaped;
|
|
16209
|
+
const enabledShapedServer = enabledShaped;
|
|
16165
16210
|
if (existingServer !== void 0 && isDeepStrictEqual(existingServer, shapedServer)) {
|
|
16166
16211
|
return { changed: false, content: document };
|
|
16167
16212
|
}
|
|
16168
|
-
if (existingServer !== void 0 &&
|
|
16213
|
+
if (existingServer !== void 0 && (enabledShapedServer === void 0 || !isDeepStrictEqual(existingServer, enabledShapedServer))) {
|
|
16169
16214
|
throw new Error(
|
|
16170
16215
|
`MCP server "${server.name}" already exists with different configuration in ${configPath}.`
|
|
16171
16216
|
);
|