@cydm/pie 1.0.23 → 1.0.24

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.
@@ -1560,12 +1560,12 @@ function Iterator(items, options) {
1560
1560
  function RequiredArray(properties) {
1561
1561
  return globalThis.Object.keys(properties).filter((key) => !IsOptional(properties[key]));
1562
1562
  }
1563
- function _Object(properties, options) {
1563
+ function _Object_(properties, options) {
1564
1564
  const required = RequiredArray(properties);
1565
1565
  const schema = required.length > 0 ? { [Kind]: "Object", type: "object", required, properties } : { [Kind]: "Object", type: "object", properties };
1566
1566
  return CreateType(schema, options);
1567
1567
  }
1568
- var Object2 = _Object;
1568
+ var Object2 = _Object_;
1569
1569
 
1570
1570
  // ../../node_modules/@sinclair/typebox/build/esm/type/promise/promise.mjs
1571
1571
  function Promise2(item, options) {
@@ -5634,6 +5634,36 @@ import Anthropic from "@anthropic-ai/sdk";
5634
5634
  function sanitizeSurrogates(text) {
5635
5635
  return text.replace(/[\uD800-\uDFFF]/g, "");
5636
5636
  }
5637
+ var ANTHROPIC_PROVIDER_HEADERS = {
5638
+ accept: "application/json",
5639
+ "anthropic-dangerous-direct-browser-access": "true",
5640
+ "anthropic-version": "2023-06-01"
5641
+ };
5642
+ function buildAnthropicHeaders(modelHeaders, runtimeHeaders, includeLongCacheBeta) {
5643
+ const merged = /* @__PURE__ */ new Map();
5644
+ for (const layer of [ANTHROPIC_PROVIDER_HEADERS, modelHeaders, runtimeHeaders]) {
5645
+ for (const [key, value] of Object.entries(layer ?? {})) {
5646
+ const normalizedKey = key.toLowerCase();
5647
+ if (normalizedKey && normalizedKey !== "anthropic-beta") {
5648
+ merged.set(normalizedKey, value);
5649
+ }
5650
+ }
5651
+ }
5652
+ const betaFeatures = includeLongCacheBeta ? ["extended-cache-ttl-2025-04-11"] : [];
5653
+ for (const layer of [modelHeaders, runtimeHeaders]) {
5654
+ for (const [key, value] of Object.entries(layer ?? {})) {
5655
+ if (key.toLowerCase() !== "anthropic-beta") continue;
5656
+ for (const feature of value.split(",")) {
5657
+ const trimmed = feature.trim();
5658
+ if (trimmed) betaFeatures.push(trimmed);
5659
+ }
5660
+ }
5661
+ }
5662
+ if (betaFeatures.length > 0) {
5663
+ merged.set("anthropic-beta", [...new Set(betaFeatures)].join(","));
5664
+ }
5665
+ return Object.fromEntries(merged);
5666
+ }
5637
5667
  function normalizeToolCallId(id) {
5638
5668
  return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
5639
5669
  }
@@ -5838,31 +5868,18 @@ var streamAnthropic = (model, context, options) => {
5838
5868
  };
5839
5869
  try {
5840
5870
  const apiKey = options?.apiKey ?? getEnvApiKey(model.provider, model.apiKeyEnv) ?? "";
5841
- const modelHeaders = model.headers || {};
5842
- const otherModelHeaders = {};
5843
- let modelBetaValue;
5844
- for (const [key, value] of Object.entries(modelHeaders)) {
5845
- if (key.toLowerCase() === "anthropic-beta") {
5846
- modelBetaValue = value;
5847
- } else {
5848
- otherModelHeaders[key] = value;
5849
- }
5850
- }
5851
- const betaFlags = [
5852
- ...options?.cacheRetention === "long" ? ["extended-cache-ttl-2025-04-11"] : [],
5853
- ...modelBetaValue?.split(",") ?? []
5854
- ].map((flag) => flag.trim()).filter(Boolean);
5871
+ const cacheCapability = getModelCacheCapability(model);
5872
+ const promptCacheSupported = cacheCapability.supported && isPromptCacheCapability(cacheCapability);
5873
+ const headers = buildAnthropicHeaders(
5874
+ model.headers,
5875
+ options?.headers,
5876
+ promptCacheSupported && options?.cacheRetention === "long"
5877
+ );
5855
5878
  const client = new Anthropic({
5856
5879
  apiKey,
5857
5880
  baseURL: model.baseUrl,
5858
5881
  dangerouslyAllowBrowser: true,
5859
- defaultHeaders: {
5860
- accept: "application/json",
5861
- "anthropic-dangerous-direct-browser-access": "true",
5862
- "anthropic-version": "2023-06-01",
5863
- ...otherModelHeaders,
5864
- ...betaFlags.length > 0 ? { "anthropic-beta": [...new Set(betaFlags)].join(",") } : {}
5865
- }
5882
+ defaultHeaders: headers
5866
5883
  });
5867
5884
  const params = {
5868
5885
  model: model.id,
@@ -5870,7 +5887,6 @@ var streamAnthropic = (model, context, options) => {
5870
5887
  max_tokens: options?.maxTokens || Math.floor(model.maxTokens / 3) || 1024,
5871
5888
  stream: true
5872
5889
  };
5873
- const cacheCapability = model.cacheCapability ?? getModelCacheCapability(model) ?? ANTHROPIC_PROMPT_CACHE_CAPABILITY;
5874
5890
  if (context.systemPrompt) {
5875
5891
  params.system = [{ type: "text", text: sanitizeSurrogates(context.systemPrompt) }];
5876
5892
  }
@@ -5893,7 +5909,7 @@ var streamAnthropic = (model, context, options) => {
5893
5909
  params.tool_choice = options.toolChoice;
5894
5910
  }
5895
5911
  }
5896
- if (isPromptCacheCapability(cacheCapability)) {
5912
+ if (promptCacheSupported) {
5897
5913
  applyCacheBreakpoints(params, options?.cacheRetention);
5898
5914
  }
5899
5915
  options?.onPayload?.(params);