@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.cjs CHANGED
@@ -102,6 +102,7 @@ __export(index_exports, {
102
102
  buildEmptySessionNudge: () => buildEmptySessionNudge,
103
103
  buildGeneratedRuntimeToolGateOutput: () => buildGeneratedRuntimeToolGateOutput,
104
104
  buildLedgerOffloadReference: () => buildLedgerOffloadReference,
105
+ buildObservationMaskMarker: () => buildObservationMaskMarker,
105
106
  buildPolicyGuidance: () => buildPolicyGuidance,
106
107
  buildSendViewOffloadMarker: () => buildSendViewOffloadMarker,
107
108
  calledTool: () => calledTool,
@@ -4912,6 +4913,7 @@ var SkillsNamespace = class {
4912
4913
 
4913
4914
  // src/agents-namespace.ts
4914
4915
  var AGENT_CONFIG_KEYS = [
4916
+ "contextManagement",
4915
4917
  "model",
4916
4918
  "systemPrompt",
4917
4919
  "temperature",
@@ -5911,27 +5913,6 @@ var SurfacesNamespace = class {
5911
5913
  }
5912
5914
  };
5913
5915
 
5914
- // src/transform.ts
5915
- function transformResponse(data) {
5916
- return data;
5917
- }
5918
- function transformRequest(data) {
5919
- return data;
5920
- }
5921
- function transformQueryParams(params) {
5922
- const result = {};
5923
- for (const [key, value] of Object.entries(params)) {
5924
- if (value !== void 0 && value !== null) {
5925
- if (Array.isArray(value)) {
5926
- result[key] = value.join(",");
5927
- } else {
5928
- result[key] = String(value);
5929
- }
5930
- }
5931
- }
5932
- return result;
5933
- }
5934
-
5935
5916
  // src/types.ts
5936
5917
  function isCatalogClientToolRef(entry) {
5937
5918
  return entry.catalog === "runtype-mcp";
@@ -6014,7 +5995,7 @@ var RuntypeClient = class {
6014
5995
  method: "GET",
6015
5996
  headers: this.headers
6016
5997
  });
6017
- return this.transformResponse(response);
5998
+ return response;
6018
5999
  }
6019
6000
  /**
6020
6001
  * Generic POST request
@@ -6026,7 +6007,7 @@ var RuntypeClient = class {
6026
6007
  headers: { ...this.headers, ...extraHeaders },
6027
6008
  body: data ? JSON.stringify(data) : void 0
6028
6009
  });
6029
- return this.transformResponse(response);
6010
+ return response;
6030
6011
  }
6031
6012
  /**
6032
6013
  * Generic PUT request
@@ -6038,7 +6019,7 @@ var RuntypeClient = class {
6038
6019
  headers: this.headers,
6039
6020
  body: data ? JSON.stringify(data) : void 0
6040
6021
  });
6041
- return this.transformResponse(response);
6022
+ return response;
6042
6023
  }
6043
6024
  /**
6044
6025
  * Generic PATCH request
@@ -6050,7 +6031,7 @@ var RuntypeClient = class {
6050
6031
  headers: this.headers,
6051
6032
  body: data ? JSON.stringify(data) : void 0
6052
6033
  });
6053
- return this.transformResponse(response);
6034
+ return response;
6054
6035
  }
6055
6036
  /**
6056
6037
  * Generic DELETE request
@@ -6061,7 +6042,7 @@ var RuntypeClient = class {
6061
6042
  method: "DELETE",
6062
6043
  headers: this.headers
6063
6044
  });
6064
- return this.transformResponse(response);
6045
+ return response;
6065
6046
  }
6066
6047
  /**
6067
6048
  * Generic request that returns raw Response for streaming
@@ -6087,13 +6068,13 @@ var RuntypeClient = class {
6087
6068
  */
6088
6069
  async dispatch(config) {
6089
6070
  const normalized = normalizeDispatchRequest(config);
6090
- const request6 = transformRequest({
6071
+ const request6 = {
6091
6072
  ...normalized,
6092
6073
  options: {
6093
6074
  ...normalized.options,
6094
6075
  streamResponse: true
6095
6076
  }
6096
- });
6077
+ };
6097
6078
  return this.requestStream("/dispatch", {
6098
6079
  method: "POST",
6099
6080
  body: JSON.stringify(request6)
@@ -6152,35 +6133,15 @@ var RuntypeClient = class {
6152
6133
  * Make HTTP request with timeout and error handling
6153
6134
  */
6154
6135
  async makeRequest(url, options) {
6155
- const controller = new AbortController();
6156
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
6157
- try {
6158
- const response = await fetch(url, {
6159
- ...options,
6160
- signal: controller.signal
6161
- });
6162
- clearTimeout(timeoutId);
6163
- if (!response.ok) {
6164
- const errorText = await response.text();
6165
- throw new Error(
6166
- `API request failed: ${response.status} ${response.statusText} - ${errorText}`
6167
- );
6168
- }
6169
- if (response.status === 204) {
6170
- return null;
6171
- }
6172
- const contentType = response.headers.get("content-type");
6173
- if (contentType?.includes("application/json")) {
6174
- return response.json();
6175
- }
6176
- return response.text();
6177
- } catch (error) {
6178
- clearTimeout(timeoutId);
6179
- if (error instanceof Error && error.name === "AbortError") {
6180
- throw new Error(`Request timeout after ${this.timeout}ms`, { cause: error });
6181
- }
6182
- throw error;
6136
+ const response = await this.makeRawRequest(url, options);
6137
+ if (response.status === 204) {
6138
+ return null;
6139
+ }
6140
+ const contentType = response.headers.get("content-type");
6141
+ if (contentType?.includes("application/json")) {
6142
+ return response.json();
6183
6143
  }
6144
+ return response.text();
6184
6145
  }
6185
6146
  /**
6186
6147
  * Make HTTP request that returns raw Response (for streaming)
@@ -6209,12 +6170,6 @@ var RuntypeClient = class {
6209
6170
  throw error;
6210
6171
  }
6211
6172
  }
6212
- /**
6213
- * Transform response (placeholder for snake_case to camelCase)
6214
- */
6215
- transformResponse(response) {
6216
- return response;
6217
- }
6218
6173
  };
6219
6174
  var Runtype = class {
6220
6175
  /**
@@ -6493,9 +6448,24 @@ var Runtype = class {
6493
6448
  }
6494
6449
  };
6495
6450
 
6451
+ // src/transform.ts
6452
+ function transformQueryParams(params) {
6453
+ const result = {};
6454
+ for (const [key, value] of Object.entries(params)) {
6455
+ if (value !== void 0 && value !== null) {
6456
+ if (Array.isArray(value)) {
6457
+ result[key] = value.join(",");
6458
+ } else {
6459
+ result[key] = String(value);
6460
+ }
6461
+ }
6462
+ }
6463
+ return result;
6464
+ }
6465
+
6496
6466
  // src/version.ts
6497
6467
  var FALLBACK_VERSION = "0.0.0";
6498
- var SDK_VERSION = "9.7.0".length > 0 ? "9.7.0" : FALLBACK_VERSION;
6468
+ var SDK_VERSION = "9.9.0".length > 0 ? "9.9.0" : FALLBACK_VERSION;
6499
6469
  var RUNTYPE_CLIENT_KIND = "sdk";
6500
6470
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6501
6471
 
@@ -6929,6 +6899,7 @@ function applyGeneratedRuntimeToolProposalToDispatchRequest(request6, proposal,
6929
6899
 
6930
6900
  // src/offload-markers.ts
6931
6901
  var LEDGER_ARTIFACT_LINE_PREFIX = "Ledger artifact: ";
6902
+ var SPILL_MARKER_PATTERN = /\[Output saved to (art_[A-Za-z0-9_-]+) \(([\d,]+) chars?\); read_offloaded_output to view\]/;
6932
6903
  function formatChars(charLength) {
6933
6904
  return charLength.toLocaleString("en-US");
6934
6905
  }
@@ -6944,9 +6915,13 @@ function buildLedgerOffloadReference(details) {
6944
6915
  `Use read_offloaded_output with id "${details.outputId}" to retrieve the full output if needed.`
6945
6916
  ].join("\n");
6946
6917
  }
6918
+ function buildObservationMaskMarker(details) {
6919
+ return `[Output from ${details.toolName} masked \u2014 re-run the tool if needed]`;
6920
+ }
6947
6921
  var DECLARED_CHARS_PATTERNS = [
6948
6922
  /—\s*([\d,]+)\s+chars?\s+(?:stored|saved)/i,
6949
- /\(([\d,]+)\s+chars?\)\s+saved/i
6923
+ /\(([\d,]+)\s+chars?\)\s+saved/i,
6924
+ /\(([\d,]+)\s+chars?\);\s*read_offloaded_output/i
6950
6925
  ];
6951
6926
  function extractDeclaredToolResultChars(value) {
6952
6927
  if (typeof value !== "string") return void 0;
@@ -6958,13 +6933,82 @@ function extractDeclaredToolResultChars(value) {
6958
6933
  }
6959
6934
  return void 0;
6960
6935
  }
6936
+ function parseSpillMarkerArtifactId(value) {
6937
+ if (typeof value !== "string") return void 0;
6938
+ const match = SPILL_MARKER_PATTERN.exec(value);
6939
+ if (!match?.[1] || !match[2]) return void 0;
6940
+ const charLength = Number.parseInt(match[2].replace(/,/g, ""), 10);
6941
+ if (!Number.isFinite(charLength) || charLength <= 0) return void 0;
6942
+ return match[1];
6943
+ }
6961
6944
  function parseOffloadedOutputId(value) {
6962
- 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;
6945
+ 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;
6963
6946
  }
6964
6947
  function parseLedgerArtifactRelativePath(value) {
6965
6948
  return value.split("\n").find((line) => line.startsWith(LEDGER_ARTIFACT_LINE_PREFIX))?.slice(LEDGER_ARTIFACT_LINE_PREFIX.length).trim();
6966
6949
  }
6967
6950
 
6951
+ // src/context-budget.ts
6952
+ var DEFAULT_CHARS_PER_TOKEN = 4;
6953
+ var MESSAGE_OVERHEAD_TOKENS = 6;
6954
+ var TOOL_ENTRY_OVERHEAD_TOKENS = 12;
6955
+ var CONTENT_PART_OVERHEAD_TOKENS = 4;
6956
+ var IMAGE_PART_TOKENS = 85;
6957
+ var MAX_DATA_PART_TOKENS = 200;
6958
+ function estimateTokensByChars(text) {
6959
+ if (!text) return 0;
6960
+ return Math.ceil(text.length / DEFAULT_CHARS_PER_TOKEN);
6961
+ }
6962
+ function estimateUnknownValueTokens(value, estimate = estimateTokensByChars) {
6963
+ if (typeof value === "string") return estimate(value);
6964
+ try {
6965
+ return estimate(JSON.stringify(value) ?? "");
6966
+ } catch {
6967
+ return 0;
6968
+ }
6969
+ }
6970
+ function estimateContentTokens(content, estimate = estimateTokensByChars) {
6971
+ if (typeof content === "string") return estimate(content);
6972
+ if (!Array.isArray(content)) return 0;
6973
+ return content.reduce((total, part) => {
6974
+ let partTotal = CONTENT_PART_OVERHEAD_TOKENS;
6975
+ if (typeof part.text === "string") partTotal += estimate(part.text);
6976
+ if (typeof part.image === "string") partTotal += IMAGE_PART_TOKENS;
6977
+ if (typeof part.data === "string") {
6978
+ partTotal += Math.min(MAX_DATA_PART_TOKENS, estimate(part.data));
6979
+ }
6980
+ return total + partTotal;
6981
+ }, 0);
6982
+ }
6983
+ function estimateToolCallTokens(toolCalls, estimate = estimateTokensByChars) {
6984
+ if (!toolCalls || toolCalls.length === 0) return 0;
6985
+ return toolCalls.reduce(
6986
+ (sum, toolCall) => sum + TOOL_ENTRY_OVERHEAD_TOKENS + estimate(toolCall.toolName) + estimateUnknownValueTokens(toolCall.args, estimate),
6987
+ 0
6988
+ );
6989
+ }
6990
+ function estimateToolResultTokens(toolResults, options) {
6991
+ if (!toolResults || toolResults.length === 0) return 0;
6992
+ const estimate = options?.estimate ?? estimateTokensByChars;
6993
+ return toolResults.reduce((sum, toolResult) => {
6994
+ const resultTokens = estimateUnknownValueTokens(toolResult.result, estimate);
6995
+ const declaredChars = options?.useDeclaredSize ? extractDeclaredToolResultChars(toolResult.result) : void 0;
6996
+ const declaredTokens = typeof declaredChars === "number" ? Math.ceil(declaredChars / DEFAULT_CHARS_PER_TOKEN) : 0;
6997
+ return sum + TOOL_ENTRY_OVERHEAD_TOKENS + estimate(toolResult.toolName) + Math.max(resultTokens, declaredTokens);
6998
+ }, 0);
6999
+ }
7000
+ function estimateMessageTokens(message, options) {
7001
+ const estimate = options?.estimate ?? estimateTokensByChars;
7002
+ return MESSAGE_OVERHEAD_TOKENS + estimateContentTokens(message.content, estimate) + estimateToolCallTokens(message.toolCalls, estimate) + estimateToolResultTokens(message.toolResults, {
7003
+ ...options?.useDeclaredToolResultSizes ? { useDeclaredSize: true } : {},
7004
+ estimate
7005
+ });
7006
+ }
7007
+ function modelIdSupportsProviderNativeCompaction(modelId) {
7008
+ const normalized = modelId?.trim().toLowerCase() ?? "";
7009
+ return normalized.includes("claude") || normalized.includes("anthropic");
7010
+ }
7011
+
6968
7012
  // src/workflow-utils.ts
6969
7013
  function normalizeCandidatePath(candidatePath) {
6970
7014
  return candidatePath.trim().replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+/g, "/");
@@ -10957,7 +11001,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10957
11001
  )
10958
11002
  };
10959
11003
  }
10960
- return { ...tr, result: `[Output from ${tr.toolName} masked \u2014 re-run the tool if needed]` };
11004
+ return { ...tr, result: buildObservationMaskMarker({ toolName: tr.toolName }) };
10961
11005
  }
10962
11006
  isMarathonArtifactPath(candidatePath) {
10963
11007
  const normalized = this.normalizeCandidatePath(candidatePath).toLowerCase();
@@ -12040,57 +12084,29 @@ var _AgentsEndpoint = class _AgentsEndpoint {
12040
12084
  if (strategy === "summary_fallback") {
12041
12085
  return "summary_fallback";
12042
12086
  }
12043
- const normalizedModelId = modelId?.trim().toLowerCase() ?? "";
12044
- const supportsAnthropicNativeCompaction = normalizedModelId.includes("claude") || normalizedModelId.includes("anthropic");
12087
+ const supportsAnthropicNativeCompaction = modelIdSupportsProviderNativeCompaction(modelId);
12045
12088
  if (strategy === "provider_native") {
12046
12089
  return supportsAnthropicNativeCompaction ? "provider_native" : "summary_fallback";
12047
12090
  }
12048
12091
  return supportsAnthropicNativeCompaction ? "provider_native" : "summary_fallback";
12049
12092
  }
12050
12093
  estimateTextTokens(text) {
12051
- if (!text) return 0;
12052
- return Math.ceil(text.length / 4);
12053
- }
12054
- estimateUnknownTokens(value) {
12055
- if (typeof value === "string") return this.estimateTextTokens(value);
12056
- try {
12057
- return this.estimateTextTokens(JSON.stringify(value));
12058
- } catch {
12059
- return 0;
12060
- }
12094
+ return estimateTokensByChars(text);
12061
12095
  }
12062
12096
  extractDeclaredToolResultChars(value) {
12063
12097
  return extractDeclaredToolResultChars(value);
12064
12098
  }
12065
12099
  estimateMessageContentTokens(content) {
12066
- if (typeof content === "string") return this.estimateTextTokens(content);
12067
- return content.reduce((total, part) => {
12068
- if (typeof part.text === "string") total += this.estimateTextTokens(part.text);
12069
- if (typeof part.image === "string") total += 85;
12070
- if (typeof part.data === "string") {
12071
- total += Math.min(200, this.estimateTextTokens(part.data));
12072
- }
12073
- return total + 4;
12074
- }, 0);
12100
+ return estimateContentTokens(content);
12075
12101
  }
12076
12102
  estimateToolCallTokens(toolCalls) {
12077
- if (!toolCalls || toolCalls.length === 0) return 0;
12078
- return toolCalls.reduce(
12079
- (sum, toolCall) => sum + 12 + this.estimateTextTokens(toolCall.toolName) + this.estimateUnknownTokens(toolCall.args),
12080
- 0
12081
- );
12103
+ return estimateToolCallTokens(toolCalls);
12082
12104
  }
12083
12105
  estimateToolResultTokens(toolResults, options) {
12084
- if (!toolResults || toolResults.length === 0) return 0;
12085
- return toolResults.reduce((sum, toolResult) => {
12086
- const resultTokens = this.estimateUnknownTokens(toolResult.result);
12087
- const declaredChars = options?.useDeclaredSize ? this.extractDeclaredToolResultChars(toolResult.result) : void 0;
12088
- const declaredTokens = typeof declaredChars === "number" ? Math.ceil(declaredChars / 4) : 0;
12089
- return sum + 12 + this.estimateTextTokens(toolResult.toolName) + Math.max(resultTokens, declaredTokens);
12090
- }, 0);
12106
+ return estimateToolResultTokens(toolResults, options);
12091
12107
  }
12092
12108
  estimateMessageTokens(message) {
12093
- return 6 + this.estimateMessageContentTokens(message.content) + this.estimateToolCallTokens(message.toolCalls) + this.estimateToolResultTokens(message.toolResults);
12109
+ return estimateMessageTokens(message);
12094
12110
  }
12095
12111
  estimateConversationTokens(messages) {
12096
12112
  return messages.reduce((sum, message) => sum + this.estimateMessageTokens(message), 0);
@@ -12126,7 +12142,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
12126
12142
  }));
12127
12143
  const payload = [...localToolDefinitions, ...builtinToolSchemas];
12128
12144
  if (payload.length === 0) return 0;
12129
- return this.estimateUnknownTokens(payload);
12145
+ return estimateUnknownValueTokens(payload);
12130
12146
  }
12131
12147
  async loadBuiltinToolSchemas(toolIds) {
12132
12148
  if (!toolIds || toolIds.length === 0) return [];
@@ -13604,7 +13620,7 @@ var RuntypeClient2 = class {
13604
13620
  method: "GET",
13605
13621
  headers: this.headers
13606
13622
  });
13607
- return transformResponse(response);
13623
+ return response;
13608
13624
  }
13609
13625
  /**
13610
13626
  * Conditional GET (`ETag` / `If-None-Match`).
@@ -13627,7 +13643,7 @@ var RuntypeClient2 = class {
13627
13643
  if (!response.ok) {
13628
13644
  throw await this.createApiError(response);
13629
13645
  }
13630
- const data = transformResponse(await response.json());
13646
+ const data = await response.json();
13631
13647
  return { notModified: false, etag, data };
13632
13648
  }
13633
13649
  /**
@@ -13638,9 +13654,9 @@ var RuntypeClient2 = class {
13638
13654
  const response = await this.makeRequest(url, {
13639
13655
  method: "POST",
13640
13656
  headers: { ...this.headers, ...extraHeaders },
13641
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13657
+ body: data ? JSON.stringify(data) : void 0
13642
13658
  });
13643
- return transformResponse(response);
13659
+ return response;
13644
13660
  }
13645
13661
  /**
13646
13662
  * POST request with FormData support for file uploads
@@ -13654,7 +13670,7 @@ var RuntypeClient2 = class {
13654
13670
  headers,
13655
13671
  body: formData
13656
13672
  });
13657
- return transformResponse(response);
13673
+ return response;
13658
13674
  }
13659
13675
  /**
13660
13676
  * POST request with a raw binary body (e.g. application/zip bundle uploads).
@@ -13668,7 +13684,7 @@ var RuntypeClient2 = class {
13668
13684
  // 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
13669
13685
  body
13670
13686
  });
13671
- return transformResponse(response);
13687
+ return response;
13672
13688
  }
13673
13689
  /**
13674
13690
  * Generic request that returns raw Response for streaming
@@ -13679,18 +13695,9 @@ var RuntypeClient2 = class {
13679
13695
  ...this.headers,
13680
13696
  ...options.headers
13681
13697
  };
13682
- let body = options.body;
13683
- if (body && typeof body === "string" && headers["Content-Type"]?.includes("application/json")) {
13684
- try {
13685
- const parsed = JSON.parse(body);
13686
- body = JSON.stringify(transformRequest(parsed));
13687
- } catch {
13688
- }
13689
- }
13690
13698
  return this.makeRawRequest(url, {
13691
13699
  ...options,
13692
- headers,
13693
- body
13700
+ headers
13694
13701
  });
13695
13702
  }
13696
13703
  /**
@@ -13701,9 +13708,9 @@ var RuntypeClient2 = class {
13701
13708
  const response = await this.makeRequest(url, {
13702
13709
  method: "PUT",
13703
13710
  headers: this.headers,
13704
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13711
+ body: data ? JSON.stringify(data) : void 0
13705
13712
  });
13706
- return transformResponse(response);
13713
+ return response;
13707
13714
  }
13708
13715
  /**
13709
13716
  * Generic PATCH request
@@ -13713,9 +13720,9 @@ var RuntypeClient2 = class {
13713
13720
  const response = await this.makeRequest(url, {
13714
13721
  method: "PATCH",
13715
13722
  headers: this.headers,
13716
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13723
+ body: data ? JSON.stringify(data) : void 0
13717
13724
  });
13718
- return transformResponse(response);
13725
+ return response;
13719
13726
  }
13720
13727
  /**
13721
13728
  * Generic DELETE request
@@ -13725,9 +13732,9 @@ var RuntypeClient2 = class {
13725
13732
  const response = await this.makeRequest(url, {
13726
13733
  method: "DELETE",
13727
13734
  headers: this.headers,
13728
- body: data ? JSON.stringify(transformRequest(data)) : void 0
13735
+ body: data ? JSON.stringify(data) : void 0
13729
13736
  });
13730
- return transformResponse(response);
13737
+ return response;
13731
13738
  }
13732
13739
  /**
13733
13740
  * Build full URL with query parameters
@@ -14668,6 +14675,7 @@ var STEP_TYPE_TO_METHOD = {
14668
14675
  buildEmptySessionNudge,
14669
14676
  buildGeneratedRuntimeToolGateOutput,
14670
14677
  buildLedgerOffloadReference,
14678
+ buildObservationMaskMarker,
14671
14679
  buildPolicyGuidance,
14672
14680
  buildSendViewOffloadMarker,
14673
14681
  calledTool,