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 CHANGED
@@ -94861,6 +94861,31 @@ function getConfigDirectory(configPath) {
94861
94861
  function isConfigObject6(value) {
94862
94862
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
94863
94863
  }
94864
+ function assertNonEmptyString(value, message2) {
94865
+ if (typeof value !== "string" || value.trim().length === 0) {
94866
+ throw new Error(message2);
94867
+ }
94868
+ }
94869
+ function assertHttpUrl(value) {
94870
+ assertNonEmptyString(value, "MCP HTTP URL must be a valid http or https URL.");
94871
+ let parsed;
94872
+ try {
94873
+ parsed = new URL(value);
94874
+ } catch {
94875
+ throw new Error("MCP HTTP URL must be a valid http or https URL.");
94876
+ }
94877
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
94878
+ throw new Error("MCP HTTP URL must be a valid http or https URL.");
94879
+ }
94880
+ }
94881
+ function validateServerEntry(server) {
94882
+ assertNonEmptyString(server.name, "MCP server name must be a non-empty string.");
94883
+ if (server.config.transport === "stdio") {
94884
+ assertNonEmptyString(server.config.command, "MCP stdio command must be a non-empty string.");
94885
+ return;
94886
+ }
94887
+ assertHttpUrl(server.config.url);
94888
+ }
94864
94889
  function resolveServerMap(document, configKey) {
94865
94890
  const value = document[configKey];
94866
94891
  if (value === void 0) {
@@ -94878,12 +94903,15 @@ async function configure2(agentId, server, options) {
94878
94903
  if (!isSupported(agentId)) {
94879
94904
  throw new UnsupportedAgentError2(agentId);
94880
94905
  }
94906
+ validateServerEntry(server);
94881
94907
  const config2 = getAgentConfig3(agentId);
94882
94908
  const configPath = resolveConfigPath2(config2, options.platform);
94883
94909
  const shapeTransformer = getShapeTransformer(config2.shape);
94884
94910
  const shaped = shapeTransformer(server);
94911
+ const enabledServer = { ...server, enabled: true };
94912
+ const enabledShaped = shapeTransformer(enabledServer);
94885
94913
  if (shaped === void 0) {
94886
- await unconfigure2(agentId, server.name, options);
94914
+ await unconfigure2(agentId, enabledServer, options);
94887
94915
  return;
94888
94916
  }
94889
94917
  const configDir = getConfigDirectory(configPath);
@@ -94902,10 +94930,11 @@ async function configure2(agentId, server, options) {
94902
94930
  const servers = resolveServerMap(document, config2.configKey);
94903
94931
  const existingServer = Object.hasOwn(servers, server.name) ? servers[server.name] : void 0;
94904
94932
  const shapedServer = shaped;
94933
+ const enabledShapedServer = enabledShaped;
94905
94934
  if (existingServer !== void 0 && isDeepStrictEqual(existingServer, shapedServer)) {
94906
94935
  return { changed: false, content: document };
94907
94936
  }
94908
- if (existingServer !== void 0 && server.enabled !== false) {
94937
+ if (existingServer !== void 0 && (enabledShapedServer === void 0 || !isDeepStrictEqual(existingServer, enabledShapedServer))) {
94909
94938
  throw new Error(
94910
94939
  `MCP server "${server.name}" already exists with different configuration in ${configPath}.`
94911
94940
  );
@@ -100916,12 +100945,28 @@ import { get_encoding } from "tiktoken";
100916
100945
  function createTokenizer(options = {}) {
100917
100946
  const encoding = options.encoding ?? DEFAULT_ENCODING;
100918
100947
  const tokenizer = get_encoding(encoding);
100919
- const utf8Decoder = new TextDecoder();
100920
100948
  const strictUtf8Decoder = new TextDecoder("utf-8", { fatal: true });
100921
100949
  const encode = (text5) => tokenizer.encode(text5);
100950
+ const normalizeDecodeTokens = (tokens) => {
100951
+ if (tokens instanceof Uint32Array) {
100952
+ return tokens;
100953
+ }
100954
+ const tokenArray = new Uint32Array(tokens.length);
100955
+ tokens.forEach((token, index) => {
100956
+ if (!Number.isFinite(token) || !Number.isInteger(token) || token < 0 || token > 4294967295) {
100957
+ throw new TypeError(`token id at index ${index} must be a finite non-negative integer.`);
100958
+ }
100959
+ tokenArray[index] = token;
100960
+ });
100961
+ return tokenArray;
100962
+ };
100922
100963
  const decode = (tokens) => {
100923
- const tokenArray = tokens instanceof Uint32Array ? tokens : Uint32Array.from(tokens);
100924
- return utf8Decoder.decode(tokenizer.decode(tokenArray));
100964
+ const tokenArray = normalizeDecodeTokens(tokens);
100965
+ try {
100966
+ return strictUtf8Decoder.decode(tokenizer.decode(tokenArray));
100967
+ } catch {
100968
+ throw new Error("Cannot decode tokens without corrupting UTF-8 text.");
100969
+ }
100925
100970
  };
100926
100971
  const count = (text5) => encode(text5).length;
100927
100972
  const truncate4 = (text5, tokenCount) => {
@@ -136445,7 +136490,7 @@ var init_package2 = __esm({
136445
136490
  "package.json"() {
136446
136491
  package_default2 = {
136447
136492
  name: "poe-code",
136448
- version: "3.0.273",
136493
+ version: "3.0.275",
136449
136494
  description: "CLI tool to configure Poe API for developer workflows.",
136450
136495
  type: "module",
136451
136496
  main: "./dist/index.js",