@runtypelabs/sdk 9.7.0 → 9.9.0

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.mjs CHANGED
@@ -4717,6 +4717,7 @@ var SkillsNamespace = class {
4717
4717
 
4718
4718
  // src/agents-namespace.ts
4719
4719
  var AGENT_CONFIG_KEYS = [
4720
+ "contextManagement",
4720
4721
  "model",
4721
4722
  "systemPrompt",
4722
4723
  "temperature",
@@ -5716,27 +5717,6 @@ var SurfacesNamespace = class {
5716
5717
  }
5717
5718
  };
5718
5719
 
5719
- // src/transform.ts
5720
- function transformResponse(data) {
5721
- return data;
5722
- }
5723
- function transformRequest(data) {
5724
- return data;
5725
- }
5726
- function transformQueryParams(params) {
5727
- const result = {};
5728
- for (const [key, value] of Object.entries(params)) {
5729
- if (value !== void 0 && value !== null) {
5730
- if (Array.isArray(value)) {
5731
- result[key] = value.join(",");
5732
- } else {
5733
- result[key] = String(value);
5734
- }
5735
- }
5736
- }
5737
- return result;
5738
- }
5739
-
5740
5720
  // src/types.ts
5741
5721
  function isCatalogClientToolRef(entry) {
5742
5722
  return entry.catalog === "runtype-mcp";
@@ -5819,7 +5799,7 @@ var RuntypeClient = class {
5819
5799
  method: "GET",
5820
5800
  headers: this.headers
5821
5801
  });
5822
- return this.transformResponse(response);
5802
+ return response;
5823
5803
  }
5824
5804
  /**
5825
5805
  * Generic POST request
@@ -5831,7 +5811,7 @@ var RuntypeClient = class {
5831
5811
  headers: { ...this.headers, ...extraHeaders },
5832
5812
  body: data ? JSON.stringify(data) : void 0
5833
5813
  });
5834
- return this.transformResponse(response);
5814
+ return response;
5835
5815
  }
5836
5816
  /**
5837
5817
  * Generic PUT request
@@ -5843,7 +5823,7 @@ var RuntypeClient = class {
5843
5823
  headers: this.headers,
5844
5824
  body: data ? JSON.stringify(data) : void 0
5845
5825
  });
5846
- return this.transformResponse(response);
5826
+ return response;
5847
5827
  }
5848
5828
  /**
5849
5829
  * Generic PATCH request
@@ -5855,7 +5835,7 @@ var RuntypeClient = class {
5855
5835
  headers: this.headers,
5856
5836
  body: data ? JSON.stringify(data) : void 0
5857
5837
  });
5858
- return this.transformResponse(response);
5838
+ return response;
5859
5839
  }
5860
5840
  /**
5861
5841
  * Generic DELETE request
@@ -5866,7 +5846,7 @@ var RuntypeClient = class {
5866
5846
  method: "DELETE",
5867
5847
  headers: this.headers
5868
5848
  });
5869
- return this.transformResponse(response);
5849
+ return response;
5870
5850
  }
5871
5851
  /**
5872
5852
  * Generic request that returns raw Response for streaming
@@ -5892,13 +5872,13 @@ var RuntypeClient = class {
5892
5872
  */
5893
5873
  async dispatch(config) {
5894
5874
  const normalized = normalizeDispatchRequest(config);
5895
- const request6 = transformRequest({
5875
+ const request6 = {
5896
5876
  ...normalized,
5897
5877
  options: {
5898
5878
  ...normalized.options,
5899
5879
  streamResponse: true
5900
5880
  }
5901
- });
5881
+ };
5902
5882
  return this.requestStream("/dispatch", {
5903
5883
  method: "POST",
5904
5884
  body: JSON.stringify(request6)
@@ -5957,35 +5937,15 @@ var RuntypeClient = class {
5957
5937
  * Make HTTP request with timeout and error handling
5958
5938
  */
5959
5939
  async makeRequest(url, options) {
5960
- const controller = new AbortController();
5961
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
5962
- try {
5963
- const response = await fetch(url, {
5964
- ...options,
5965
- signal: controller.signal
5966
- });
5967
- clearTimeout(timeoutId);
5968
- if (!response.ok) {
5969
- const errorText = await response.text();
5970
- throw new Error(
5971
- `API request failed: ${response.status} ${response.statusText} - ${errorText}`
5972
- );
5973
- }
5974
- if (response.status === 204) {
5975
- return null;
5976
- }
5977
- const contentType = response.headers.get("content-type");
5978
- if (contentType?.includes("application/json")) {
5979
- return response.json();
5980
- }
5981
- return response.text();
5982
- } catch (error) {
5983
- clearTimeout(timeoutId);
5984
- if (error instanceof Error && error.name === "AbortError") {
5985
- throw new Error(`Request timeout after ${this.timeout}ms`, { cause: error });
5986
- }
5987
- throw error;
5940
+ const response = await this.makeRawRequest(url, options);
5941
+ if (response.status === 204) {
5942
+ return null;
5943
+ }
5944
+ const contentType = response.headers.get("content-type");
5945
+ if (contentType?.includes("application/json")) {
5946
+ return response.json();
5988
5947
  }
5948
+ return response.text();
5989
5949
  }
5990
5950
  /**
5991
5951
  * Make HTTP request that returns raw Response (for streaming)
@@ -6014,12 +5974,6 @@ var RuntypeClient = class {
6014
5974
  throw error;
6015
5975
  }
6016
5976
  }
6017
- /**
6018
- * Transform response (placeholder for snake_case to camelCase)
6019
- */
6020
- transformResponse(response) {
6021
- return response;
6022
- }
6023
5977
  };
6024
5978
  var Runtype = class {
6025
5979
  /**
@@ -6298,9 +6252,24 @@ var Runtype = class {
6298
6252
  }
6299
6253
  };
6300
6254
 
6255
+ // src/transform.ts
6256
+ function transformQueryParams(params) {
6257
+ const result = {};
6258
+ for (const [key, value] of Object.entries(params)) {
6259
+ if (value !== void 0 && value !== null) {
6260
+ if (Array.isArray(value)) {
6261
+ result[key] = value.join(",");
6262
+ } else {
6263
+ result[key] = String(value);
6264
+ }
6265
+ }
6266
+ }
6267
+ return result;
6268
+ }
6269
+
6301
6270
  // src/version.ts
6302
6271
  var FALLBACK_VERSION = "0.0.0";
6303
- var SDK_VERSION = "9.7.0".length > 0 ? "9.7.0" : FALLBACK_VERSION;
6272
+ var SDK_VERSION = "9.9.0".length > 0 ? "9.9.0" : FALLBACK_VERSION;
6304
6273
  var RUNTYPE_CLIENT_KIND = "sdk";
6305
6274
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6306
6275
 
@@ -6734,6 +6703,7 @@ function applyGeneratedRuntimeToolProposalToDispatchRequest(request6, proposal,
6734
6703
 
6735
6704
  // src/offload-markers.ts
6736
6705
  var LEDGER_ARTIFACT_LINE_PREFIX = "Ledger artifact: ";
6706
+ var SPILL_MARKER_PATTERN = /\[Output saved to (art_[A-Za-z0-9_-]+) \(([\d,]+) chars?\); read_offloaded_output to view\]/;
6737
6707
  function formatChars(charLength) {
6738
6708
  return charLength.toLocaleString("en-US");
6739
6709
  }
@@ -6749,9 +6719,13 @@ function buildLedgerOffloadReference(details) {
6749
6719
  `Use read_offloaded_output with id "${details.outputId}" to retrieve the full output if needed.`
6750
6720
  ].join("\n");
6751
6721
  }
6722
+ function buildObservationMaskMarker(details) {
6723
+ return `[Output from ${details.toolName} masked \u2014 re-run the tool if needed]`;
6724
+ }
6752
6725
  var DECLARED_CHARS_PATTERNS = [
6753
6726
  /—\s*([\d,]+)\s+chars?\s+(?:stored|saved)/i,
6754
- /\(([\d,]+)\s+chars?\)\s+saved/i
6727
+ /\(([\d,]+)\s+chars?\)\s+saved/i,
6728
+ /\(([\d,]+)\s+chars?\);\s*read_offloaded_output/i
6755
6729
  ];
6756
6730
  function extractDeclaredToolResultChars(value) {
6757
6731
  if (typeof value !== "string") return void 0;
@@ -6763,13 +6737,82 @@ function extractDeclaredToolResultChars(value) {
6763
6737
  }
6764
6738
  return void 0;
6765
6739
  }
6740
+ function parseSpillMarkerArtifactId(value) {
6741
+ if (typeof value !== "string") return void 0;
6742
+ const match = SPILL_MARKER_PATTERN.exec(value);
6743
+ if (!match?.[1] || !match[2]) return void 0;
6744
+ const charLength = Number.parseInt(match[2].replace(/,/g, ""), 10);
6745
+ if (!Number.isFinite(charLength) || charLength <= 0) return void 0;
6746
+ return match[1];
6747
+ }
6766
6748
  function parseOffloadedOutputId(value) {
6767
- return /\bread_offloaded_output\s+with\s+id\s+"([^"]+)"/i.exec(value)?.[1] || /\[Output offloaded as\s+([a-zA-Z0-9_-]+)/i.exec(value)?.[1] || void 0;
6749
+ return /\bread_offloaded_output\s+with\s+id\s+"([^"]+)"/i.exec(value)?.[1] || /\[Output offloaded as\s+([a-zA-Z0-9_-]+)/i.exec(value)?.[1] || parseSpillMarkerArtifactId(value) || void 0;
6768
6750
  }
6769
6751
  function parseLedgerArtifactRelativePath(value) {
6770
6752
  return value.split("\n").find((line) => line.startsWith(LEDGER_ARTIFACT_LINE_PREFIX))?.slice(LEDGER_ARTIFACT_LINE_PREFIX.length).trim();
6771
6753
  }
6772
6754
 
6755
+ // src/context-budget.ts
6756
+ var DEFAULT_CHARS_PER_TOKEN = 4;
6757
+ var MESSAGE_OVERHEAD_TOKENS = 6;
6758
+ var TOOL_ENTRY_OVERHEAD_TOKENS = 12;
6759
+ var CONTENT_PART_OVERHEAD_TOKENS = 4;
6760
+ var IMAGE_PART_TOKENS = 85;
6761
+ var MAX_DATA_PART_TOKENS = 200;
6762
+ function estimateTokensByChars(text) {
6763
+ if (!text) return 0;
6764
+ return Math.ceil(text.length / DEFAULT_CHARS_PER_TOKEN);
6765
+ }
6766
+ function estimateUnknownValueTokens(value, estimate = estimateTokensByChars) {
6767
+ if (typeof value === "string") return estimate(value);
6768
+ try {
6769
+ return estimate(JSON.stringify(value) ?? "");
6770
+ } catch {
6771
+ return 0;
6772
+ }
6773
+ }
6774
+ function estimateContentTokens(content, estimate = estimateTokensByChars) {
6775
+ if (typeof content === "string") return estimate(content);
6776
+ if (!Array.isArray(content)) return 0;
6777
+ return content.reduce((total, part) => {
6778
+ let partTotal = CONTENT_PART_OVERHEAD_TOKENS;
6779
+ if (typeof part.text === "string") partTotal += estimate(part.text);
6780
+ if (typeof part.image === "string") partTotal += IMAGE_PART_TOKENS;
6781
+ if (typeof part.data === "string") {
6782
+ partTotal += Math.min(MAX_DATA_PART_TOKENS, estimate(part.data));
6783
+ }
6784
+ return total + partTotal;
6785
+ }, 0);
6786
+ }
6787
+ function estimateToolCallTokens(toolCalls, estimate = estimateTokensByChars) {
6788
+ if (!toolCalls || toolCalls.length === 0) return 0;
6789
+ return toolCalls.reduce(
6790
+ (sum, toolCall) => sum + TOOL_ENTRY_OVERHEAD_TOKENS + estimate(toolCall.toolName) + estimateUnknownValueTokens(toolCall.args, estimate),
6791
+ 0
6792
+ );
6793
+ }
6794
+ function estimateToolResultTokens(toolResults, options) {
6795
+ if (!toolResults || toolResults.length === 0) return 0;
6796
+ const estimate = options?.estimate ?? estimateTokensByChars;
6797
+ return toolResults.reduce((sum, toolResult) => {
6798
+ const resultTokens = estimateUnknownValueTokens(toolResult.result, estimate);
6799
+ const declaredChars = options?.useDeclaredSize ? extractDeclaredToolResultChars(toolResult.result) : void 0;
6800
+ const declaredTokens = typeof declaredChars === "number" ? Math.ceil(declaredChars / DEFAULT_CHARS_PER_TOKEN) : 0;
6801
+ return sum + TOOL_ENTRY_OVERHEAD_TOKENS + estimate(toolResult.toolName) + Math.max(resultTokens, declaredTokens);
6802
+ }, 0);
6803
+ }
6804
+ function estimateMessageTokens(message, options) {
6805
+ const estimate = options?.estimate ?? estimateTokensByChars;
6806
+ return MESSAGE_OVERHEAD_TOKENS + estimateContentTokens(message.content, estimate) + estimateToolCallTokens(message.toolCalls, estimate) + estimateToolResultTokens(message.toolResults, {
6807
+ ...options?.useDeclaredToolResultSizes ? { useDeclaredSize: true } : {},
6808
+ estimate
6809
+ });
6810
+ }
6811
+ function modelIdSupportsProviderNativeCompaction(modelId) {
6812
+ const normalized = modelId?.trim().toLowerCase() ?? "";
6813
+ return normalized.includes("claude") || normalized.includes("anthropic");
6814
+ }
6815
+
6773
6816
  // src/workflow-utils.ts
6774
6817
  function normalizeCandidatePath(candidatePath) {
6775
6818
  return candidatePath.trim().replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+/g, "/");
@@ -10762,7 +10805,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10762
10805
  )
10763
10806
  };
10764
10807
  }
10765
- return { ...tr, result: `[Output from ${tr.toolName} masked \u2014 re-run the tool if needed]` };
10808
+ return { ...tr, result: buildObservationMaskMarker({ toolName: tr.toolName }) };
10766
10809
  }
10767
10810
  isMarathonArtifactPath(candidatePath) {
10768
10811
  const normalized = this.normalizeCandidatePath(candidatePath).toLowerCase();
@@ -11845,57 +11888,29 @@ var _AgentsEndpoint = class _AgentsEndpoint {
11845
11888
  if (strategy === "summary_fallback") {
11846
11889
  return "summary_fallback";
11847
11890
  }
11848
- const normalizedModelId = modelId?.trim().toLowerCase() ?? "";
11849
- const supportsAnthropicNativeCompaction = normalizedModelId.includes("claude") || normalizedModelId.includes("anthropic");
11891
+ const supportsAnthropicNativeCompaction = modelIdSupportsProviderNativeCompaction(modelId);
11850
11892
  if (strategy === "provider_native") {
11851
11893
  return supportsAnthropicNativeCompaction ? "provider_native" : "summary_fallback";
11852
11894
  }
11853
11895
  return supportsAnthropicNativeCompaction ? "provider_native" : "summary_fallback";
11854
11896
  }
11855
11897
  estimateTextTokens(text) {
11856
- if (!text) return 0;
11857
- return Math.ceil(text.length / 4);
11858
- }
11859
- estimateUnknownTokens(value) {
11860
- if (typeof value === "string") return this.estimateTextTokens(value);
11861
- try {
11862
- return this.estimateTextTokens(JSON.stringify(value));
11863
- } catch {
11864
- return 0;
11865
- }
11898
+ return estimateTokensByChars(text);
11866
11899
  }
11867
11900
  extractDeclaredToolResultChars(value) {
11868
11901
  return extractDeclaredToolResultChars(value);
11869
11902
  }
11870
11903
  estimateMessageContentTokens(content) {
11871
- if (typeof content === "string") return this.estimateTextTokens(content);
11872
- return content.reduce((total, part) => {
11873
- if (typeof part.text === "string") total += this.estimateTextTokens(part.text);
11874
- if (typeof part.image === "string") total += 85;
11875
- if (typeof part.data === "string") {
11876
- total += Math.min(200, this.estimateTextTokens(part.data));
11877
- }
11878
- return total + 4;
11879
- }, 0);
11904
+ return estimateContentTokens(content);
11880
11905
  }
11881
11906
  estimateToolCallTokens(toolCalls) {
11882
- if (!toolCalls || toolCalls.length === 0) return 0;
11883
- return toolCalls.reduce(
11884
- (sum, toolCall) => sum + 12 + this.estimateTextTokens(toolCall.toolName) + this.estimateUnknownTokens(toolCall.args),
11885
- 0
11886
- );
11907
+ return estimateToolCallTokens(toolCalls);
11887
11908
  }
11888
11909
  estimateToolResultTokens(toolResults, options) {
11889
- if (!toolResults || toolResults.length === 0) return 0;
11890
- return toolResults.reduce((sum, toolResult) => {
11891
- const resultTokens = this.estimateUnknownTokens(toolResult.result);
11892
- const declaredChars = options?.useDeclaredSize ? this.extractDeclaredToolResultChars(toolResult.result) : void 0;
11893
- const declaredTokens = typeof declaredChars === "number" ? Math.ceil(declaredChars / 4) : 0;
11894
- return sum + 12 + this.estimateTextTokens(toolResult.toolName) + Math.max(resultTokens, declaredTokens);
11895
- }, 0);
11910
+ return estimateToolResultTokens(toolResults, options);
11896
11911
  }
11897
11912
  estimateMessageTokens(message) {
11898
- return 6 + this.estimateMessageContentTokens(message.content) + this.estimateToolCallTokens(message.toolCalls) + this.estimateToolResultTokens(message.toolResults);
11913
+ return estimateMessageTokens(message);
11899
11914
  }
11900
11915
  estimateConversationTokens(messages) {
11901
11916
  return messages.reduce((sum, message) => sum + this.estimateMessageTokens(message), 0);
@@ -11931,7 +11946,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
11931
11946
  }));
11932
11947
  const payload = [...localToolDefinitions, ...builtinToolSchemas];
11933
11948
  if (payload.length === 0) return 0;
11934
- return this.estimateUnknownTokens(payload);
11949
+ return estimateUnknownValueTokens(payload);
11935
11950
  }
11936
11951
  async loadBuiltinToolSchemas(toolIds) {
11937
11952
  if (!toolIds || toolIds.length === 0) return [];
@@ -13409,7 +13424,7 @@ var RuntypeClient2 = class {
13409
13424
  method: "GET",
13410
13425
  headers: this.headers
13411
13426
  });
13412
- return transformResponse(response);
13427
+ return response;
13413
13428
  }
13414
13429
  /**
13415
13430
  * Conditional GET (`ETag` / `If-None-Match`).
@@ -13432,7 +13447,7 @@ var RuntypeClient2 = class {
13432
13447
  if (!response.ok) {
13433
13448
  throw await this.createApiError(response);
13434
13449
  }
13435
- const data = transformResponse(await response.json());
13450
+ const data = await response.json();
13436
13451
  return { notModified: false, etag, data };
13437
13452
  }
13438
13453
  /**
@@ -13443,9 +13458,9 @@ var RuntypeClient2 = class {
13443
13458
  const response = await this.makeRequest(url, {
13444
13459
  method: "POST",
13445
13460
  headers: { ...this.headers, ...extraHeaders },
13446
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13461
+ body: data ? JSON.stringify(data) : void 0
13447
13462
  });
13448
- return transformResponse(response);
13463
+ return response;
13449
13464
  }
13450
13465
  /**
13451
13466
  * POST request with FormData support for file uploads
@@ -13459,7 +13474,7 @@ var RuntypeClient2 = class {
13459
13474
  headers,
13460
13475
  body: formData
13461
13476
  });
13462
- return transformResponse(response);
13477
+ return response;
13463
13478
  }
13464
13479
  /**
13465
13480
  * POST request with a raw binary body (e.g. application/zip bundle uploads).
@@ -13473,7 +13488,7 @@ var RuntypeClient2 = class {
13473
13488
  // WORKAROUND(docs/why/packages/client/src.md#ts-5-7-types-uint8array-over-arraybufferlike-whi): TS 5.7 types Uint8Array over ArrayBufferLike, which no longer overlaps DOM BodyInit, though the
13474
13489
  body
13475
13490
  });
13476
- return transformResponse(response);
13491
+ return response;
13477
13492
  }
13478
13493
  /**
13479
13494
  * Generic request that returns raw Response for streaming
@@ -13484,18 +13499,9 @@ var RuntypeClient2 = class {
13484
13499
  ...this.headers,
13485
13500
  ...options.headers
13486
13501
  };
13487
- let body = options.body;
13488
- if (body && typeof body === "string" && headers["Content-Type"]?.includes("application/json")) {
13489
- try {
13490
- const parsed = JSON.parse(body);
13491
- body = JSON.stringify(transformRequest(parsed));
13492
- } catch {
13493
- }
13494
- }
13495
13502
  return this.makeRawRequest(url, {
13496
13503
  ...options,
13497
- headers,
13498
- body
13504
+ headers
13499
13505
  });
13500
13506
  }
13501
13507
  /**
@@ -13506,9 +13512,9 @@ var RuntypeClient2 = class {
13506
13512
  const response = await this.makeRequest(url, {
13507
13513
  method: "PUT",
13508
13514
  headers: this.headers,
13509
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13515
+ body: data ? JSON.stringify(data) : void 0
13510
13516
  });
13511
- return transformResponse(response);
13517
+ return response;
13512
13518
  }
13513
13519
  /**
13514
13520
  * Generic PATCH request
@@ -13518,9 +13524,9 @@ var RuntypeClient2 = class {
13518
13524
  const response = await this.makeRequest(url, {
13519
13525
  method: "PATCH",
13520
13526
  headers: this.headers,
13521
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13527
+ body: data ? JSON.stringify(data) : void 0
13522
13528
  });
13523
- return transformResponse(response);
13529
+ return response;
13524
13530
  }
13525
13531
  /**
13526
13532
  * Generic DELETE request
@@ -13530,9 +13536,9 @@ var RuntypeClient2 = class {
13530
13536
  const response = await this.makeRequest(url, {
13531
13537
  method: "DELETE",
13532
13538
  headers: this.headers,
13533
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13539
+ body: data ? JSON.stringify(data) : void 0
13534
13540
  });
13535
- return transformResponse(response);
13541
+ return response;
13536
13542
  }
13537
13543
  /**
13538
13544
  * Build full URL with query parameters
@@ -14472,6 +14478,7 @@ export {
14472
14478
  buildEmptySessionNudge,
14473
14479
  buildGeneratedRuntimeToolGateOutput,
14474
14480
  buildLedgerOffloadReference,
14481
+ buildObservationMaskMarker,
14475
14482
  buildPolicyGuidance,
14476
14483
  buildSendViewOffloadMarker,
14477
14484
  calledTool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "9.7.0",
3
+ "version": "9.9.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Runtype API with fluent methods. Use it to quickly realize AI products, agents, and workflows.",
6
6
  "main": "dist/index.cjs",
@@ -24,6 +24,7 @@
24
24
  ],
25
25
  "dependencies": {},
26
26
  "devDependencies": {
27
+ "@runtypelabs/shared": "3.43.0",
27
28
  "openapi-typescript": "^7.13.0",
28
29
  "tsup": "^8.0.2",
29
30
  "typescript": "^6.0.3",