@veryfront/ext-llm-anthropic 0.1.1271-rc.23355 → 0.1.1271

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.
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-request-builder.d.ts","sourceRoot":"","sources":["../src/anthropic-request-builder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,uBAAuB,EAEvB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EACL,KAAK,iCAAiC,EAUvC,MAAM,+BAA+B,CAAC;AAEvC,KAAK,gBAAgB,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;AA2E9C,KAAK,0BAA0B,GAAG;IAChC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,MAAM,WAAW,+BAAgC,SAAQ,uBAAuB;IAC9E,YAAY,CAAC,EAAE,0BAA0B,CAAC;IAC1C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACjD;AAED,gGAAgG;AAChG,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAE/D,KAAK,gBAAgB,GAAG;IACtB,IAAI,CAAC,OAAO,EAAE;QACZ,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC;QACtC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI,CAAC;IACT,KAAK,IAAI,KAAK,CAAC;QACb,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC;QACtC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,C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OAAO,CAAC,CAAC,CAAC;CACzC,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IACpD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AA+vEF,wBAAgB,iDAAiD,CAC/D,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,+BAA+B,EACxC,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,gBAAgB,GACzB;IACD,IAAI,EAAE,0BAA0B,CAAC;IACjC,qBAAqB,EAAE,iCAAiC,CAAC;CAC1D,CA4KA;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,+BAA+B,EACxC,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,gBAAgB,GACzB,0BAA0B,CAQ5B"}
@@ -1,4 +1,4 @@
1
- import { canIdentifyProxyWithoutHooks, isProxyWithoutHooks, jsonValuesEqual, readProviderOptions, readRecord, snapshotProviderJsonValue, stringifyToolResultValue, unwrapToolInputSchema, } from "veryfront/provider/shared";
1
+ import { canIdentifyProxyWithoutHooks, closeSchemaForOutputConfig, isProxyWithoutHooks, jsonValuesEqual, readProviderOptions, readRecord, snapshotProviderJsonValue, stringifyToolResultValue, unwrapToolInputSchema, } from "veryfront/provider/shared";
2
2
  import { assertAnthropicMcpRequestContract, normalizeAnthropicMcpServers, normalizeAnthropicMcpToolsetArgs, } from "./anthropic-mcp-request.js";
3
3
  import { isAnthropicProviderToolResultBlockType, MAX_ANTHROPIC_RAW_ASSISTANT_BLOCKS, MAX_ANTHROPIC_REPLAY_ASSISTANT_MESSAGES, parseAnthropicProviderToolUse, parseAnthropicServerToolResult, snapshotAnthropicRawAssistantMetadata, validateAnthropicRawAssistantMessages, } from "./anthropic-native-content.js";
4
4
  const apply = Reflect.apply;
@@ -6,6 +6,8 @@ const NativeArray = Array;
6
6
  const ArrayIsArray = Array.isArray;
7
7
  const booleanValueOf = Boolean.prototype.valueOf;
8
8
  const NativeSet = Set;
9
+ const mathMin = Math.min;
10
+ const numberIsSafeInteger = Number.isSafeInteger;
9
11
  const numberValueOf = Number.prototype.valueOf;
10
12
  const objectAssign = Object.assign;
11
13
  const objectDefineProperty = Object.defineProperty;
@@ -1739,213 +1741,6 @@ function buildAnthropicOutputConfig(responseFormat, warnings) {
1739
1741
  },
1740
1742
  };
1741
1743
  }
1742
- /**
1743
- * JSON Schema keywords whose value is itself a schema, a list of schemas, or a
1744
- * map of schemas. Recursion is restricted to these so that keywords holding
1745
- * literal values -- `default`, `const`, `enum`, `examples` -- are copied
1746
- * through untouched instead of being rewritten when they happen to look like a
1747
- * schema.
1748
- */
1749
- const SCHEMA_MAP_KEYWORDS = new Set([
1750
- "properties",
1751
- "patternProperties",
1752
- "$defs",
1753
- "definitions",
1754
- "dependentSchemas",
1755
- // Draft-07 `dependencies` holds either a schema or an array of property
1756
- // names per key. The array form contains strings, which the walk returns
1757
- // unchanged, so both spellings can share this branch.
1758
- "dependencies",
1759
- ]);
1760
- const SCHEMA_LIST_KEYWORDS = new Set(["anyOf", "oneOf", "prefixItems"]);
1761
- /**
1762
- * `allOf` branches describe one instance together, not alternatives, and
1763
- * `additionalProperties` only ever sees the `properties` of the schema object
1764
- * carrying it. Closing branches that each declare part of the object therefore
1765
- * makes every one of them reject the others' properties, and the composition
1766
- * accepts nothing at all:
1767
- *
1768
- * allOf: [ { properties: { a }, additionalProperties: false },
1769
- * { properties: { b }, additionalProperties: false } ]
1770
- *
1771
- * `{ a, b }` fails the first branch on `b` and the second on `a`.
1772
- *
1773
- * So branches are walked for objects nested deeper inside them, but are not
1774
- * closed themselves. An `allOf` of open objects is still rejected by Anthropic
1775
- * -- which is the correct outcome, and a legible one, rather than a schema that
1776
- * validates nothing the model can produce.
1777
- */
1778
- const COMPOSITION_LIST_KEYWORDS = new Set(["allOf"]);
1779
- const SCHEMA_VALUE_KEYWORDS = new Set([
1780
- "items",
1781
- "additionalItems",
1782
- "contains",
1783
- "additionalProperties",
1784
- "propertyNames",
1785
- "not",
1786
- "if",
1787
- "then",
1788
- "else",
1789
- "unevaluatedProperties",
1790
- "unevaluatedItems",
1791
- "contentSchema",
1792
- ]);
1793
- /**
1794
- * Set `additionalProperties: false` on every object-typed subschema that left
1795
- * it unset.
1796
- *
1797
- * Anthropic's `output_config.format` rejects an object schema without it with a
1798
- * 400 -- "For 'object' type, 'additionalProperties' must be explicitly set to
1799
- * false" -- unconditionally, and independently of the framework's own `strict`
1800
- * flag. A plain `v.object({...})` with every field required therefore fails
1801
- * even though it already satisfies the rest of strict structured output, so the
1802
- * requirement is satisfied here rather than pushed onto every caller.
1803
- *
1804
- * An explicitly declared `additionalProperties` is preserved: rewriting it
1805
- * would silently narrow a contract the caller deliberately opened, and
1806
- * Anthropic surfaces its own error for that case. An explicit `undefined`
1807
- * is not a declaration -- JSON drops it before the provider ever sees it.
1808
- *
1809
- * The result is a copy. The schema object belongs to the agent and is reused
1810
- * across providers and calls, so closing it for Anthropic must not mutate it.
1811
- */
1812
- function closeObjectSchemas(schema, closeSelf = true, pointer = "#", openTargets = EMPTY_POINTER_SET) {
1813
- if (ArrayIsArray(schema)) {
1814
- const entries = [];
1815
- for (let index = 0; index < schema.length; index += 1) {
1816
- entries[index] = closeObjectSchemas(schema[index], closeSelf, `${pointer}/${index}`, openTargets);
1817
- }
1818
- return entries;
1819
- }
1820
- if (typeof schema !== "object" || schema === null)
1821
- return schema;
1822
- const source = schema;
1823
- const result = {};
1824
- for (const key of objectKeys(source)) {
1825
- const value = source[key];
1826
- const keyPointer = `${pointer}/${encodePointerToken(key)}`;
1827
- if (hasSetValue(SCHEMA_MAP_KEYWORDS, key)) {
1828
- result[key] = closeSchemaMap(value, keyPointer, openTargets);
1829
- continue;
1830
- }
1831
- if (hasSetValue(COMPOSITION_LIST_KEYWORDS, key)) {
1832
- result[key] = closeObjectSchemas(value, false, keyPointer, openTargets);
1833
- continue;
1834
- }
1835
- if (hasSetValue(SCHEMA_LIST_KEYWORDS, key) || hasSetValue(SCHEMA_VALUE_KEYWORDS, key)) {
1836
- result[key] = closeObjectSchemas(value, true, keyPointer, openTargets);
1837
- continue;
1838
- }
1839
- result[key] = value;
1840
- }
1841
- // `undefined` counts as unset, not as a declaration. The key survives the
1842
- // walk when a caller writes it explicitly as `undefined`, but JSON drops it
1843
- // on the way to the provider -- so honoring its presence would emit exactly
1844
- // the open schema Anthropic rejects.
1845
- //
1846
- // A `$ref` holder is skipped: `additionalProperties` only ever sees the
1847
- // `properties` of the schema object carrying it, and a `$ref` declares none
1848
- // of its own, so closing it rejects every property the target defines.
1849
- if (closeSelf && isObjectTyped(source.type) &&
1850
- source.additionalProperties === undefined &&
1851
- source.$ref === undefined) {
1852
- result.additionalProperties = false;
1853
- }
1854
- return result;
1855
- }
1856
- /**
1857
- * Walk a keyword whose value maps names to subschemas.
1858
- *
1859
- * A definition reached by a `$ref` that sits directly under `allOf` stays open,
1860
- * for the reason spelled out on `COMPOSITION_LIST_KEYWORDS`: the branches of an
1861
- * `allOf` describe one instance together, so closing each of them makes every
1862
- * branch reject the properties the others declare.
1863
- */
1864
- function closeSchemaMap(value, pointer, openTargets) {
1865
- if (typeof value !== "object" || value === null || ArrayIsArray(value))
1866
- return value;
1867
- const source = value;
1868
- const result = {};
1869
- for (const name of objectKeys(source)) {
1870
- const namePointer = `${pointer}/${encodePointerToken(name)}`;
1871
- result[name] = closeObjectSchemas(source[name], !hasSetValue(openTargets, namePointer), namePointer, openTargets);
1872
- }
1873
- return result;
1874
- }
1875
- /** Shared empty set, so the common walk allocates nothing extra. */
1876
- const EMPTY_POINTER_SET = new Set();
1877
- /** Escape a JSON pointer token, per RFC 6901. */
1878
- function encodePointerToken(token) {
1879
- let escaped = "";
1880
- for (const char of token) {
1881
- if (char === "~")
1882
- escaped += "~0";
1883
- else if (char === "/")
1884
- escaped += "~1";
1885
- else
1886
- escaped += char;
1887
- }
1888
- return escaped;
1889
- }
1890
- /**
1891
- * Close every object in a schema bound for `output_config`.
1892
- *
1893
- * Runs a pre-pass first, because a `$ref` used as an `allOf` branch carries the
1894
- * composition's meaning at its target rather than at the branch itself. The
1895
- * branch object is left open by the walk, but its target lives under `$defs` or
1896
- * `definitions`, which the walk would otherwise close. Collecting those
1897
- * pointers up front lets the walk leave exactly those definitions open.
1898
- *
1899
- * A definition referenced from an `allOf` branch and used somewhere else too
1900
- * stays open in both places. Opening is the safe direction: Anthropic rejects
1901
- * an open object with a named 400, whereas an over-closed `allOf` is accepted
1902
- * and then matches nothing, which surfaces as an empty generation.
1903
- */
1904
- function closeSchemaForOutputConfig(schema) {
1905
- const openTargets = new Set();
1906
- collectAllOfRefTargets(schema, openTargets);
1907
- return closeObjectSchemas(schema, true, "#", openTargets);
1908
- }
1909
- /**
1910
- * Collect the pointers named by `$ref` branches sitting directly under an
1911
- * `allOf`, anywhere in the schema. Only local pointers are collected, since a
1912
- * remote `$ref` names nothing this walk can open.
1913
- */
1914
- function collectAllOfRefTargets(schema, out) {
1915
- if (ArrayIsArray(schema)) {
1916
- for (const entry of schema)
1917
- collectAllOfRefTargets(entry, out);
1918
- return;
1919
- }
1920
- if (typeof schema !== "object" || schema === null)
1921
- return;
1922
- const source = schema;
1923
- for (const key of objectKeys(source)) {
1924
- const value = source[key];
1925
- if (hasSetValue(COMPOSITION_LIST_KEYWORDS, key)) {
1926
- const branches = ArrayIsArray(value) ? value : [value];
1927
- for (const branch of branches) {
1928
- if (typeof branch !== "object" || branch === null)
1929
- continue;
1930
- const ref = branch.$ref;
1931
- if (typeof ref === "string" && ref.startsWith("#/"))
1932
- out.add(ref);
1933
- }
1934
- }
1935
- collectAllOfRefTargets(value, out);
1936
- }
1937
- }
1938
- /**
1939
- * Whether a schema declares the object type.
1940
- *
1941
- * `JsonSchema.type` accepts an array as well as a single name, and the array
1942
- * form is how a nullable object is written by hand:
1943
- * `{ type: ["object", "null"], properties: {...} }`. Matching only the exact
1944
- * string would leave that branch open and let Anthropic reject it.
1945
- */
1946
- function isObjectTyped(type) {
1947
- return type === "object" || (Array.isArray(type) && type.includes("object"));
1948
- }
1949
1744
  function resolveAnthropicMaxTokens(modelId, callerMaxOutputTokens) {
1950
1745
  const { maxOutputTokens: modelMax, isKnownModel } = getAnthropicModelCapabilities(modelId);
1951
1746
  const requested = callerMaxOutputTokens ?? modelMax;
@@ -1959,7 +1754,7 @@ function resolveAnthropicThinkingBudget(option) {
1959
1754
  return undefined;
1960
1755
  }
1961
1756
  if (option.budgetTokens !== undefined) {
1962
- if (!Number.isSafeInteger(option.budgetTokens) || option.budgetTokens < 1024) {
1757
+ if (!numberIsSafeInteger(option.budgetTokens) || option.budgetTokens < 1024) {
1963
1758
  throw new TypeError("Anthropic reasoning budgetTokens must be a safe integer of at least 1024");
1964
1759
  }
1965
1760
  return option.budgetTokens;
@@ -1999,7 +1794,7 @@ function resolveAnthropicProviderThinkingBudget(options) {
1999
1794
  }
2000
1795
  const budgetTokens = budgetTokensProperty.present ? budgetTokensProperty.value : undefined;
2001
1796
  if (budgetTokens !== undefined &&
2002
- (!Number.isSafeInteger(budgetTokens) || budgetTokens < 1024)) {
1797
+ (!numberIsSafeInteger(budgetTokens) || budgetTokens < 1024)) {
2003
1798
  throw new TypeError("Anthropic provider thinking.budget_tokens must be a safe integer of at least 1024");
2004
1799
  }
2005
1800
  if (type.value !== "enabled") {
@@ -2090,7 +1885,7 @@ export function buildAnthropicMessagesRequestWithCorrelationState(modelId, provi
2090
1885
  const outputConfig = buildAnthropicOutputConfig(options.responseFormat, warnings);
2091
1886
  const baseMaxTokens = resolveAnthropicMaxTokens(modelId, options.maxOutputTokens);
2092
1887
  const maxTokens = thinkingEnabled
2093
- ? Math.min(baseMaxTokens + (effectiveThinkingBudget ?? 0), getAnthropicModelCapabilities(modelId).maxOutputTokens)
1888
+ ? mathMin(baseMaxTokens + (effectiveThinkingBudget ?? 0), getAnthropicModelCapabilities(modelId).maxOutputTokens)
2094
1889
  : baseMaxTokens;
2095
1890
  const body = {
2096
1891
  model: modelId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfront/ext-llm-anthropic",
3
- "version": "0.1.1271-rc.23355",
3
+ "version": "0.1.1271",
4
4
  "description": "Veryfront first-party extension package for ext-llm-anthropic",
5
5
  "keywords": [
6
6
  "veryfront",
@@ -45,7 +45,7 @@
45
45
  "capabilities": []
46
46
  },
47
47
  "peerDependencies": {
48
- "veryfront": "^0.1.1271-rc.23355"
48
+ "veryfront": "^0.1.1271"
49
49
  },
50
50
  "type": "module",
51
51
  "types": "./esm/index.d.ts",
@@ -55,5 +55,5 @@
55
55
  "NOTICE",
56
56
  "README.md"
57
57
  ],
58
- "gitHead": "da5cc33d9fb1f26dd3ce530670c155d37ce3526b"
58
+ "gitHead": "48e040987859350ca028ed696b8774ca092d1846"
59
59
  }