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