@renanlido/tia-openness-mcp 1.13.1 → 1.13.2

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28629,7 +28629,7 @@ function isControlResult(value) {
28629
28629
  // src/jobRunner.ts
28630
28630
  var SOFT_DEADLINE_CAP_MS = 25e3;
28631
28631
  function parsePositiveInt(raw, fallback) {
28632
- if (raw === void 0 || !/^\d+$/.test(raw)) return fallback;
28632
+ if (!/^\d+$/.test(String(raw))) return fallback;
28633
28633
  const n = Number(raw);
28634
28634
  if (!Number.isSafeInteger(n) || n <= 0 || n > 2147483647) return fallback;
28635
28635
  return n;
@@ -28646,8 +28646,7 @@ function toolResult(payload, isError) {
28646
28646
  }
28647
28647
  function describeError(e) {
28648
28648
  try {
28649
- if (e instanceof Error) return e.message;
28650
- return String(e);
28649
+ return String(e instanceof Error ? e.message : e);
28651
28650
  } catch {
28652
28651
  return "non-Error rejection";
28653
28652
  }
@@ -28681,7 +28680,9 @@ function stableStringifyPlain(value) {
28681
28680
  }
28682
28681
  const obj = value;
28683
28682
  const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
28684
- return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`).join(",")}}`;
28683
+ const members2 = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`);
28684
+ const canonical = members2.join(",");
28685
+ return `{${canonical}}`;
28685
28686
  }
28686
28687
  function dedupeKey(tool, args) {
28687
28688
  const canonical = `${tool}:${stableStringify(args ?? {})}`;
@@ -28745,6 +28746,7 @@ var JobRunner = class {
28745
28746
  result: null,
28746
28747
  runningHint: options.runningHint ?? null,
28747
28748
  retain: false,
28749
+ // Stryker disable next-line BooleanLiteral: a placeholder, replaced synchronously below
28748
28750
  done: Promise.resolve(toolResult({}, false))
28749
28751
  // placeholder; substituído já a seguir, síncrono
28750
28752
  };
@@ -28760,13 +28762,12 @@ var JobRunner = class {
28760
28762
  return settled;
28761
28763
  }
28762
28764
  ).finally(() => {
28763
- this.finish(job, settled ?? internalError("non-Error rejection"));
28765
+ this.finish(job, settled);
28764
28766
  });
28765
28767
  const deadline = wait(this.softDeadlineMs);
28766
- const first = await Promise.race([job.done, deadline.promise]);
28768
+ await Promise.race([job.done, deadline.promise]);
28767
28769
  deadline.cancel();
28768
- if (first) return first;
28769
- if (job.finishedAt !== null && job.result) return job.result;
28770
+ if (job.finishedAt !== null) return job.result;
28770
28771
  return this.running(job, false);
28771
28772
  }
28772
28773
  async status(jobId, waitMs) {
@@ -28783,11 +28784,9 @@ var JobRunner = class {
28783
28784
  true
28784
28785
  );
28785
28786
  }
28786
- if (job.finishedAt === null) {
28787
- const w = wait(Math.min(Math.max(waitMs, 0), MAX_STATUS_WAIT_MS));
28788
- await Promise.race([job.done, w.promise]);
28789
- w.cancel();
28790
- }
28787
+ const w = wait(Math.min(Math.max(waitMs, 0), MAX_STATUS_WAIT_MS));
28788
+ await Promise.race([job.done, w.promise]);
28789
+ w.cancel();
28791
28790
  return job.finishedAt !== null ? this.withJob(job) : this.running(job, false);
28792
28791
  }
28793
28792
  /** Só para testes: esquece jobs (não cancela trabalho em andamento). */
@@ -28802,9 +28801,7 @@ var JobRunner = class {
28802
28801
  if (!job.retain) return;
28803
28802
  this.finished.set(job.id, job);
28804
28803
  while (this.finished.size > KEEP_FINISHED) {
28805
- const oldest = this.finished.keys().next().value;
28806
- if (oldest === void 0) break;
28807
- this.finished.delete(oldest);
28804
+ this.finished.delete(this.finished.keys().next().value);
28808
28805
  }
28809
28806
  }
28810
28807
  running(job, deduplicated) {
@@ -28996,7 +28993,7 @@ async function tiaFetch(path, init = {}, opts = {}) {
28996
28993
  }
28997
28994
  }
28998
28995
  if (!res.ok) {
28999
- const env = body && typeof body === "object" ? body : {};
28996
+ const env = body instanceof Object ? body : {};
29000
28997
  const license = env.license;
29001
28998
  const message = typeof env.error === "string" ? env.error : `HTTP ${res.status} ${res.statusText}`;
29002
28999
  throw new TiaApiError(message, {
@@ -29013,7 +29010,7 @@ async function tiaFetch(path, init = {}, opts = {}) {
29013
29010
  }
29014
29011
  var INSTALLING_HINT = "The serve host is installing a TIAOpenness app update: this call was refused BEFORE any operation ran (nothing changed). Wait until the update finishes, then retry the same call (GET /status stays available while draining \u2014 retry once it reports draining:false).";
29015
29012
  var AUDIT_UNAVAILABLE_HINT = "The serve could not write its local audit log, so it refused this call BEFORE running anything: nothing was sent to the PLC and nothing changed (there is no background job for this call). A human must fix the audit log on the serve host (disk full or no write permission on %LOCALAPPDATA%\\TIAOpenness\\audit, or on the folder TIAOPENNESS_AUDIT_DIR points to); only after that, retry.";
29016
- var UNSAVED_OPERATIONS = ["connect", "project_close", "disconnect", "project_create"];
29013
+ var UNSAVED_OPERATIONS = /* @__PURE__ */ new Set(["connect", "project_close", "disconnect", "project_create"]);
29017
29014
  var BINDING_REASONS = {
29018
29015
  project_closed: "the project was closed in TIA, so nothing is open in it now",
29019
29016
  other_project: "another project is open in it now (a different project was opened, or the project was saved under another name or place with Save As)",
@@ -29043,7 +29040,7 @@ function unsavedChangesHint(details) {
29043
29040
  const projects = (Array.isArray(d.projects) ? d.projects : []).map(describeProject).filter((p) => p !== null);
29044
29041
  const stateUnknown = d.reason === "state_unknown";
29045
29042
  if (d.operation === "show_ui") return showUiRefusalHint(projects, stateUnknown);
29046
- const tool = typeof d.operation === "string" && UNSAVED_OPERATIONS.includes(d.operation) ? `tia_${d.operation}` : null;
29043
+ const tool = UNSAVED_OPERATIONS.has(d.operation) ? `tia_${d.operation}` : null;
29047
29044
  const named = stateUnknown ? projects.length > 0 ? `Whether they have unsaved changes could not be read. Projects whose unsaved state could not be verified: ${projects.join("; ")}. ` : "Whether a project has unsaved changes could not be read (the TIA Portal did not answer). " : projects.length > 0 ? `Projects with unsaved changes that this call would close: ${projects.join("; ")}. ` : "A project with unsaved changes would be closed by this call. ";
29048
29045
  const untouched = stateUnknown ? "nothing was closed, disconnected or opened (a save you asked for may already have run for some projects: saved projects stay saved). " : "nothing was saved, closed, disconnected or opened. ";
29049
29046
  return `serve REFUSED ${tool ?? "this call"} before changing anything: ${untouched}` + named + "ASK the human whether to keep that work or throw it away; do not decide for them. To keep it, repeat the SAME call with saveUnsavedChanges:true (recommended: serve saves each modified project, then goes on). Pass discardUnsavedChanges:true ONLY if the human explicitly decides the unsaved work may be lost for good (data loss, cannot be undone), never just to get past this error. The two flags cannot both be true.";
@@ -39393,7 +39390,7 @@ function registerLifecycleTools(server) {
39393
39390
  description: "Opens/attaches a TIA project (.ap*) on the serve host. Class M-off. Idempotent for the ALREADY-OPEN project (response `alreadyOpen:true`, no-op) and reuses a running TIA instance for a DIFFERENT project (`reusedPortal:true`). In an instance serve started, the open project and any foreign project are closed to make room (or the instance is restarted): if one has unsaved changes the call is REFUSED with 409 `unsaved_changes` and nothing is changed, unless it carries `saveUnsavedChanges:true` (saves each modified project first; recommended) or `discardUnsavedChanges:true` (closes WITHOUT saving: DATA LOSS, only on an explicit human decision, never to get past the refusal; the client asks the human to confirm first). `closedForeign` lists the foreign projects that were closed, `savedProjects`/`discardedProjects` the ones saved or discarded; an instance you had open yourself is never closed (serve only detaches). The response carries `boundProjectPath` (the project this session is bound to) and `modified` (unsaved changes); a later operation answers 409 `binding_conflict` if the project open in the bound TIA changed meanwhile (call tia_connect again to rebind). `withUserInterface` only applies when a NEW instance is started (ignored when reusing one \u2014 see tia_show_ui to change an existing instance's visibility). WARNING: the 1st connection per `serve` process can BLOCK on the trust GATE (G1) \u2014 if the dialog hasn't been confirmed, this tool does NOT retry-storm: it returns a `requires_human_action` envelope (gate trust_dialog, with resumeToken) asking a human to confirm the dialog on the host. Proactive flow: tia_start \u2192 tia_show_ui \u2192 (human confirms) \u2192 tia_connect. UMAC (umacUser/umacPassword) is GATE G6: provide it ONLY if a human gave the credentials \u2014 NEVER make them up. Maps to POST /connect. " + LONG_OPERATION_NOTE,
39394
39391
  inputSchema: {
39395
39392
  projectPath: external_exports.string().describe("path to the project file (.ap*) on the serve host (required)"),
39396
- tiaVersion: external_exports.string().optional().describe("Optional TIA host major: '21', 'V21' or '21.0'. Without it the project .apNN hint applies, otherwise V21 is preferred. This application ships only the V21 layer; legacy selections are refused before startup with 409 feature_unsupported_in_version. Restart serve to change its selected host/API tuple."),
39393
+ tiaVersion: external_exports.string().optional().describe("Optional TIA host: the line '21' or 'V21', or an exact release '21.0' or '21.1'. Without it the project target applies (.ap21 is V21, .ap21_1 is V21.1), otherwise the lowest installed V21 release (V21 before V21.1). A project opens only in its own release: TIA V21.1 would save a .ap21 project as .ap21_1, so that is refused with 409 tia_version_conflict. This application ships only the V21 layer, which serves V21 and V21.1; legacy selections are refused before startup with 409 feature_unsupported_in_version. Restart serve to change its selected host/API tuple."),
39397
39394
  withUserInterface: external_exports.boolean().optional().describe("open with the TIA UI visible (default true)"),
39398
39395
  umacUser: external_exports.string().optional().describe("UMAC user (GATE G6; only if a human provided it \u2014 never make it up)"),
39399
39396
  umacPassword: external_exports.string().optional().describe("UMAC password (GATE G6; only if a human provided it \u2014 never make it up)"),
@@ -45251,7 +45248,6 @@ var PlanStore = class {
45251
45248
  return entry;
45252
45249
  }
45253
45250
  check(token, plan) {
45254
- if (!token) return { ok: false, reason: "unknown" };
45255
45251
  if (this.consumed.has(token)) return { ok: false, reason: "consumed" };
45256
45252
  const entry = this.issued.get(token);
45257
45253
  if (!entry) return { ok: false, reason: "unknown" };
@@ -45365,8 +45361,8 @@ async function planDownload(args, plan, store) {
45365
45361
  )
45366
45362
  );
45367
45363
  }
45368
- const serveToken = typeof data.approvalToken === "string" && data.approvalToken.trim() ? data.approvalToken.trim() : void 0;
45369
- const issued = store.issue(plan, fingerprint, serveToken);
45364
+ const issuedToken = typeof data.approvalToken === "string" ? data.approvalToken.trim() : "";
45365
+ const issued = store.issue(plan, fingerprint, issuedToken);
45370
45366
  return markControl(
45371
45367
  textResult(
45372
45368
  {
@@ -45560,7 +45556,7 @@ function uploadBodyFromApprovedPlan(issued, password) {
45560
45556
  ip: plan.ip
45561
45557
  }),
45562
45558
  expectedProjectPath: issued.fingerprint,
45563
- ...password !== void 0 ? { password } : {}
45559
+ password
45564
45560
  };
45565
45561
  }
45566
45562
  function modesToProbe(args, data, blockers) {
@@ -45709,7 +45705,7 @@ async function planUpload(args, plan, store) {
45709
45705
  devices,
45710
45706
  connection: data.connection ?? null,
45711
45707
  ...auditWarningOf(raw),
45712
- ...warning !== void 0 ? { warning } : {}
45708
+ warning
45713
45709
  }
45714
45710
  });
45715
45711
  }
@@ -45830,6 +45826,7 @@ async function uploadFlow(args, store = uploadPlanStore) {
45830
45826
  uploadedStation: typeof data.uploadedStation === "string" ? data.uploadedStation : null,
45831
45827
  createdDevices,
45832
45828
  configurations: data.configurations ?? null,
45829
+ // Stryker disable next-line StringLiteral: the separator between warning texts is wording, each text is tested
45833
45830
  ...warnings.length > 0 ? { warning: warnings.join(" ") } : {},
45834
45831
  ...auditWarningOf(raw),
45835
45832
  nextSteps: [
@@ -46467,7 +46464,7 @@ function buildServer(mode, version2, budget = resolveBudget()) {
46467
46464
  }
46468
46465
 
46469
46466
  // src/index.ts
46470
- var VERSION = "1.13.1";
46467
+ var VERSION = "1.13.2";
46471
46468
  async function main() {
46472
46469
  if (process.argv.slice(2).some((a) => a === "--version" || a === "-v")) {
46473
46470
  console.log(VERSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renanlido/tia-openness-mcp",
3
- "version": "1.13.1",
3
+ "version": "1.13.2",
4
4
  "description": "MCP server (stdio) — thin HTTP client over the TIA Openness `serve` API. Zero Openness/net48 references.",
5
5
  "mcpName": "io.github.renanlido/tia-openness",
6
6
  "keywords": [