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