@testgorilla/tgo-ui 11.19.0 → 11.19.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/mcp/server.mjs CHANGED
@@ -15172,17 +15172,33 @@ function normalizeObjectSchema(schema) {
15172
15172
  }
15173
15173
  return void 0;
15174
15174
  }
15175
+ function getDotPath(path3) {
15176
+ if (path3.length === 0) {
15177
+ return "object root";
15178
+ }
15179
+ return path3.reduce((acc, seg, index) => {
15180
+ if (index === 0) {
15181
+ return String(seg);
15182
+ }
15183
+ if (typeof seg === "number") {
15184
+ return `${acc}[${seg}]`;
15185
+ }
15186
+ return `${acc}.${seg}`;
15187
+ }, "");
15188
+ }
15175
15189
  function getParseErrorMessage(error2) {
15176
15190
  if (error2 && typeof error2 === "object") {
15191
+ if ("issues" in error2 && Array.isArray(error2.issues) && error2.issues.length > 0) {
15192
+ return error2.issues.map((i) => {
15193
+ if (!i.path?.length) {
15194
+ return i.message;
15195
+ }
15196
+ return `${i.message} at ${getDotPath(i.path)}`;
15197
+ }).join("\n");
15198
+ }
15177
15199
  if ("message" in error2 && typeof error2.message === "string") {
15178
15200
  return error2.message;
15179
15201
  }
15180
- if ("issues" in error2 && Array.isArray(error2.issues) && error2.issues.length > 0) {
15181
- const firstIssue = error2.issues[0];
15182
- if (firstIssue && typeof firstIssue === "object" && "message" in firstIssue) {
15183
- return String(firstIssue.message);
15184
- }
15185
- }
15186
15202
  try {
15187
15203
  return JSON.stringify(error2);
15188
15204
  } catch {
@@ -15937,10 +15953,9 @@ var ProgressTokenSchema = union([string2(), number2().int()]);
15937
15953
  var CursorSchema = string2();
15938
15954
  var TaskCreationParamsSchema = looseObject({
15939
15955
  /**
15940
- * Time in milliseconds to keep task results available after completion.
15941
- * If null, the task has unlimited lifetime until manually cleaned up.
15956
+ * Requested duration in milliseconds to retain task from creation.
15942
15957
  */
15943
- ttl: union([number2(), _null3()]).optional(),
15958
+ ttl: number2().optional(),
15944
15959
  /**
15945
15960
  * Time in milliseconds to wait between task status requests.
15946
15961
  */
@@ -16240,7 +16255,11 @@ var ClientCapabilitiesSchema = object2({
16240
16255
  /**
16241
16256
  * Present if the client supports task creation.
16242
16257
  */
16243
- tasks: ClientTasksCapabilitySchema.optional()
16258
+ tasks: ClientTasksCapabilitySchema.optional(),
16259
+ /**
16260
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
16261
+ */
16262
+ extensions: record(string2(), AssertObjectSchema).optional()
16244
16263
  });
16245
16264
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
16246
16265
  /**
@@ -16301,7 +16320,11 @@ var ServerCapabilitiesSchema = object2({
16301
16320
  /**
16302
16321
  * Present if the server supports task creation.
16303
16322
  */
16304
- tasks: ServerTasksCapabilitySchema.optional()
16323
+ tasks: ServerTasksCapabilitySchema.optional(),
16324
+ /**
16325
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
16326
+ */
16327
+ extensions: record(string2(), AssertObjectSchema).optional()
16305
16328
  });
16306
16329
  var InitializeResultSchema = ResultSchema.extend({
16307
16330
  /**
@@ -16493,6 +16516,12 @@ var ResourceSchema = object2({
16493
16516
  * The MIME type of this resource, if known.
16494
16517
  */
16495
16518
  mimeType: optional(string2()),
16519
+ /**
16520
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
16521
+ *
16522
+ * This can be used by Hosts to display file sizes and estimate context window usage.
16523
+ */
16524
+ size: optional(number2()),
16496
16525
  /**
16497
16526
  * Optional annotations for the client.
16498
16527
  */
@@ -18817,6 +18846,9 @@ var Protocol = class {
18817
18846
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
18818
18847
  const handleTaskResult = async () => {
18819
18848
  const taskId = request.params.taskId;
18849
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
18850
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
18851
+ }
18820
18852
  if (this._taskMessageQueue) {
18821
18853
  let queuedMessage;
18822
18854
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -18847,12 +18879,12 @@ var Protocol = class {
18847
18879
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
18848
18880
  }
18849
18881
  if (!isTerminal(task.status)) {
18850
- await this._waitForTaskUpdate(taskId, extra.signal);
18882
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
18851
18883
  return await handleTaskResult();
18852
18884
  }
18853
18885
  if (isTerminal(task.status)) {
18854
18886
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
18855
- this._clearTaskQueue(taskId);
18887
+ this._clearTaskQueue(taskId, extra.sessionId);
18856
18888
  return {
18857
18889
  ...result,
18858
18890
  _meta: {
@@ -18889,7 +18921,7 @@ var Protocol = class {
18889
18921
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
18890
18922
  }
18891
18923
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
18892
- this._clearTaskQueue(request.params.taskId);
18924
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
18893
18925
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
18894
18926
  if (!cancelledTask) {
18895
18927
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -18988,6 +19020,10 @@ var Protocol = class {
18988
19020
  this._progressHandlers.clear();
18989
19021
  this._taskProgressTokens.clear();
18990
19022
  this._pendingDebouncedNotifications.clear();
19023
+ for (const info of this._timeoutInfo.values()) {
19024
+ clearTimeout(info.timeoutId);
19025
+ }
19026
+ this._timeoutInfo.clear();
18991
19027
  for (const controller of this._requestHandlerAbortControllers.values()) {
18992
19028
  controller.abort();
18993
19029
  }
@@ -19013,6 +19049,19 @@ var Protocol = class {
19013
19049
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
19014
19050
  const capturedTransport = this._transport;
19015
19051
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
19052
+ const sessionId = capturedTransport?.sessionId;
19053
+ const store = this._taskStore;
19054
+ let relatedTaskFound = true;
19055
+ let relatedTaskLookup;
19056
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
19057
+ relatedTaskFound = false;
19058
+ relatedTaskLookup = (async () => {
19059
+ if (!await store.getTask(relatedTaskId, sessionId)) {
19060
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
19061
+ }
19062
+ relatedTaskFound = true;
19063
+ })();
19064
+ }
19016
19065
  if (handler === void 0) {
19017
19066
  const errorResponse = {
19018
19067
  jsonrpc: "2.0",
@@ -19022,7 +19071,10 @@ var Protocol = class {
19022
19071
  message: "Method not found"
19023
19072
  }
19024
19073
  };
19025
- if (relatedTaskId && this._taskMessageQueue) {
19074
+ if (relatedTaskId && relatedTaskLookup) {
19075
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
19076
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
19077
+ } else if (relatedTaskId && this._taskMessageQueue) {
19026
19078
  this._enqueueTaskMessage(relatedTaskId, {
19027
19079
  type: "error",
19028
19080
  message: errorResponse,
@@ -19073,7 +19125,10 @@ var Protocol = class {
19073
19125
  closeSSEStream: extra?.closeSSEStream,
19074
19126
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
19075
19127
  };
19076
- Promise.resolve().then(() => {
19128
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
19129
+ if (relatedTaskLookup && abortController.signal.aborted) {
19130
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
19131
+ }
19077
19132
  if (taskCreationParams) {
19078
19133
  this.assertTaskHandlerCapability(request.method);
19079
19134
  }
@@ -19108,7 +19163,7 @@ var Protocol = class {
19108
19163
  ...error2["data"] !== void 0 && { data: error2["data"] }
19109
19164
  }
19110
19165
  };
19111
- if (relatedTaskId && this._taskMessageQueue) {
19166
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
19112
19167
  await this._enqueueTaskMessage(relatedTaskId, {
19113
19168
  type: "error",
19114
19169
  message: errorResponse,
@@ -19118,7 +19173,9 @@ var Protocol = class {
19118
19173
  await capturedTransport?.send(errorResponse);
19119
19174
  }
19120
19175
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
19121
- this._requestHandlerAbortControllers.delete(request.id);
19176
+ if (this._requestHandlerAbortControllers.get(request.id) === abortController) {
19177
+ this._requestHandlerAbortControllers.delete(request.id);
19178
+ }
19122
19179
  });
19123
19180
  }
19124
19181
  _onprogress(notification) {
@@ -19586,7 +19643,7 @@ var Protocol = class {
19586
19643
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
19587
19644
  }
19588
19645
  const maxQueueSize = this._options?.maxTaskQueueSize;
19589
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
19646
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
19590
19647
  }
19591
19648
  /**
19592
19649
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -19615,12 +19672,13 @@ var Protocol = class {
19615
19672
  * Uses polling to check for updates at the task's configured poll interval.
19616
19673
  * @param taskId The task ID to wait for
19617
19674
  * @param signal Abort signal to cancel the wait
19675
+ * @param sessionId Session of the request that waits, passed to the task store
19618
19676
  * @returns Promise that resolves when an update occurs or rejects if aborted
19619
19677
  */
19620
- async _waitForTaskUpdate(taskId, signal) {
19678
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
19621
19679
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
19622
19680
  try {
19623
- const task = await this._taskStore?.getTask(taskId);
19681
+ const task = await this._taskStore?.getTask(taskId, sessionId);
19624
19682
  if (task?.pollInterval) {
19625
19683
  interval = task.pollInterval;
19626
19684
  }
@@ -20106,16 +20164,7 @@ var Server = class extends Protocol {
20106
20164
  if (!methodSchema) {
20107
20165
  throw new Error("Schema is missing a method literal");
20108
20166
  }
20109
- let methodValue;
20110
- if (isZ4Schema(methodSchema)) {
20111
- const v4Schema = methodSchema;
20112
- const v4Def = v4Schema._zod?.def;
20113
- methodValue = v4Def?.value ?? v4Schema.value;
20114
- } else {
20115
- const v3Schema = methodSchema;
20116
- const legacyDef = v3Schema._def;
20117
- methodValue = legacyDef?.value ?? v3Schema.value;
20118
- }
20167
+ const methodValue = getLiteralValue(methodSchema);
20119
20168
  if (typeof methodValue !== "string") {
20120
20169
  throw new Error("Schema method literal must be a string");
20121
20170
  }
@@ -20508,6 +20557,42 @@ var ExperimentalMcpServerTasks = class {
20508
20557
  };
20509
20558
 
20510
20559
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
20560
+ function toolInputElementCount(value, max) {
20561
+ let count = 0;
20562
+ const stack = [value];
20563
+ while (stack.length > 0) {
20564
+ const node = stack.pop();
20565
+ if (node === null || typeof node !== "object")
20566
+ continue;
20567
+ if (Array.isArray(node)) {
20568
+ for (const child of node) {
20569
+ if (++count > max)
20570
+ return count;
20571
+ if (child !== null && typeof child === "object")
20572
+ stack.push(child);
20573
+ }
20574
+ } else {
20575
+ for (const key in node) {
20576
+ if (!Object.prototype.hasOwnProperty.call(node, key))
20577
+ continue;
20578
+ if (++count > max)
20579
+ return count;
20580
+ const child = node[key];
20581
+ if (child !== null && typeof child === "object")
20582
+ stack.push(child);
20583
+ }
20584
+ }
20585
+ }
20586
+ return count;
20587
+ }
20588
+ function resolveMaxToolInputElements(value) {
20589
+ if (value === void 0 || value === Infinity)
20590
+ return void 0;
20591
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
20592
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
20593
+ }
20594
+ return value;
20595
+ }
20511
20596
  var McpServer = class {
20512
20597
  constructor(serverInfo, options) {
20513
20598
  this._registeredResources = {};
@@ -20519,6 +20604,7 @@ var McpServer = class {
20519
20604
  this._resourceHandlersInitialized = false;
20520
20605
  this._promptHandlersInitialized = false;
20521
20606
  this.server = new Server(serverInfo, options);
20607
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
20522
20608
  }
20523
20609
  /**
20524
20610
  * Access experimental features.
@@ -20649,12 +20735,15 @@ var McpServer = class {
20649
20735
  * Validates tool input arguments against the tool's input schema.
20650
20736
  */
20651
20737
  async validateToolInput(tool, args, toolName) {
20738
+ if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
20739
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
20740
+ }
20652
20741
  if (!tool.inputSchema) {
20653
20742
  return void 0;
20654
20743
  }
20655
20744
  const inputObj = normalizeObjectSchema(tool.inputSchema);
20656
20745
  const schemaToParse = inputObj ?? tool.inputSchema;
20657
- const parseResult = await safeParseAsync2(schemaToParse, args);
20746
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
20658
20747
  if (!parseResult.success) {
20659
20748
  const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
20660
20749
  const errorMessage = getParseErrorMessage(error2);
@@ -20892,7 +20981,7 @@ var McpServer = class {
20892
20981
  }
20893
20982
  if (prompt.argsSchema) {
20894
20983
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
20895
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
20984
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
20896
20985
  if (!parseResult.success) {
20897
20986
  const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
20898
20987
  const errorMessage = getParseErrorMessage(error2);
@@ -21131,6 +21220,9 @@ var McpServer = class {
21131
21220
  annotations = rest.shift();
21132
21221
  }
21133
21222
  } else if (typeof firstArg === "object" && firstArg !== null) {
21223
+ if (Object.values(firstArg).some((v) => typeof v === "object" && v !== null)) {
21224
+ throw new Error(`Tool ${name} expected a Zod schema or ToolAnnotations, but received an unrecognized object`);
21225
+ }
21134
21226
  annotations = rest.shift();
21135
21227
  }
21136
21228
  }
@@ -21249,6 +21341,9 @@ function getZodSchemaObject(schema) {
21249
21341
  if (isZodRawShapeCompat(schema)) {
21250
21342
  return objectFromShape(schema);
21251
21343
  }
21344
+ if (!isZodSchemaInstance(schema)) {
21345
+ throw new Error("inputSchema must be a Zod schema or raw shape, received an unrecognized object");
21346
+ }
21252
21347
  return schema;
21253
21348
  }
21254
21349
  function promptArgumentsFromSchema(schema) {
@@ -21297,8 +21392,17 @@ var EMPTY_COMPLETION_RESULT = {
21297
21392
  import process2 from "node:process";
21298
21393
 
21299
21394
  // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
21395
+ var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
21300
21396
  var ReadBuffer = class {
21397
+ constructor(options) {
21398
+ this._maxBufferSize = options?.maxBufferSize ?? STDIO_DEFAULT_MAX_BUFFER_SIZE;
21399
+ }
21301
21400
  append(chunk) {
21401
+ const newSize = (this._buffer?.length ?? 0) + chunk.length;
21402
+ if (newSize > this._maxBufferSize) {
21403
+ this.clear();
21404
+ throw new Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);
21405
+ }
21302
21406
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
21303
21407
  }
21304
21408
  readMessage() {
@@ -21326,18 +21430,24 @@ function serializeMessage(message) {
21326
21430
 
21327
21431
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
21328
21432
  var StdioServerTransport = class {
21329
- constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
21433
+ constructor(_stdin = process2.stdin, _stdout = process2.stdout, options) {
21330
21434
  this._stdin = _stdin;
21331
21435
  this._stdout = _stdout;
21332
- this._readBuffer = new ReadBuffer();
21333
21436
  this._started = false;
21334
21437
  this._ondata = (chunk) => {
21335
- this._readBuffer.append(chunk);
21336
- this.processReadBuffer();
21438
+ try {
21439
+ this._readBuffer.append(chunk);
21440
+ this.processReadBuffer();
21441
+ } catch (error2) {
21442
+ this.onerror?.(error2);
21443
+ this.close().catch(() => {
21444
+ });
21445
+ }
21337
21446
  };
21338
21447
  this._onerror = (error2) => {
21339
21448
  this.onerror?.(error2);
21340
21449
  };
21450
+ this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
21341
21451
  }
21342
21452
  /**
21343
21453
  * Starts listening for messages on stdin.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testgorilla/tgo-ui",
3
- "version": "11.19.0",
3
+ "version": "11.19.1",
4
4
  "license": "proprietary-license",
5
5
  "lint-staged": {
6
6
  "{projects,components}/**/*.ts": [