@mochabug/adapt-sdk 0.4.14 → 0.4.15
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/anthropic/index.d.ts.map +1 -1
- package/dist/cjs/anthropic.cjs +1 -1
- package/dist/cjs/anthropic.cjs.map +3 -3
- package/dist/cjs/gemini.cjs +1 -1
- package/dist/cjs/gemini.cjs.map +3 -3
- package/dist/cjs/openai.cjs +1 -1
- package/dist/cjs/openai.cjs.map +3 -3
- package/dist/cjs/react.cjs +1 -1
- package/dist/cjs/react.cjs.map +3 -3
- package/dist/esm/anthropic.mjs +1 -1
- package/dist/esm/anthropic.mjs.map +3 -3
- package/dist/esm/gemini.mjs +1 -1
- package/dist/esm/gemini.mjs.map +3 -3
- package/dist/esm/openai.mjs +1 -1
- package/dist/esm/openai.mjs.map +3 -3
- package/dist/esm/react.mjs +1 -1
- package/dist/esm/react.mjs.map +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/openai/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/anthropic/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAErB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAiBL,KAAK,cAAc,EAEnB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AAMzB;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,oBAAoB,CAAC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BAAgB,8BAA8B,CAC5C,UAAU,EAAE,oBAAoB,GAC/B,mBAAmB,CAAC,kBAAkB,GAAG,oBAAoB,CAAC,CAEhE"}
|
package/dist/cjs/anthropic.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)x(e,n,{get:t[n],enumerable:!0})},Q=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of z(t))!X.call(e,r)&&r!==n&&x(e,r,{get:()=>t[r],enumerable:!(i=Y(t,r))||i.enumerable});return e};var ee=e=>Q(x({},"__esModule",{value:!0}),e);var Se={};Z(Se,{AnthropicConversion:()=>O,convertSignalToAnthropicSchema:()=>ye,convertToAnthropicSchema:()=>ge});module.exports=ee(Se);var w=require("jtd");var te=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function ne(e){return e.length===0?"/":e.map(t=>/^\d+$/.test(t)?`[${t}]`:`.${t}`).join("")}function I(e,t){let n=e;for(let i=0;i<t.length-1&&(n&&typeof n=="object"&&t[i]in n);i++)n=n[t[i]];return n}function re(e,t){let n=e;for(let i of t)if(n&&typeof n=="object")n=n[i];else return;return n}function ie(e,t,n){let{instancePath:i,schemaPath:r}=e,o=ne(i),s=r[r.length-1];if(s==="type"){let c=I(t,r)?.type;return c==="boolean"?`${o}: expected boolean`:c==="string"?`${o}: expected string`:c==="timestamp"?`${o}: expected timestamp string`:te.has(c)?`${o}: expected integer`:`${o}: expected number`}if(s==="enum"){let c=I(t,r)?.enum;return`${o}: expected one of [${c.join(", ")}]`}if(r.length>=2&&r[r.length-2]==="properties"&&s)return`${o==="/"?"":o}.${s}: missing required property`;if(s==="elements")return`${o}: expected array`;if(s==="properties"||s==="optionalProperties"||s==="values")return`${o}: expected object`;if(s==="discriminator")return`${o}: expected string discriminator`;if(s==="mapping"){let a=re(n,i);return`${o}: unknown variant "${a}"`}return r.length===0?`${o}: unexpected property`:`${o}: validation error at /${r.join("/")}`}function q(e,t,n){let i=n??e.definitions,r=i?{...e,definitions:i}:e;return(0,w.isValidSchema)(r)?(0,w.validate)(r,t,{maxDepth:oe,maxErrors:se}).map(s=>ie(s,r,t)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var oe=32,se=100;var v=32,C={int8:{minimum:-128,maximum:127},uint8:{minimum:0,maximum:255},int16:{minimum:-32768,maximum:32767},uint16:{minimum:0,maximum:65535},int32:{minimum:-2147483648,maximum:2147483647},uint32:{minimum:0,maximum:4294967295}},E={minimum:-34028235e31,maximum:34028235e31},$=`Must be a valid JSON value encoded as a string. For objects: '{"key": "value"}', for arrays: '[1, 2]', for primitives: '"hello"' or '42' or 'true' or 'null'.`,V=`The variant data encoded as a valid JSON string (e.g. '{"key": "value"}').`,B="Array of key-value entries representing a map/dictionary. Each entry has a string 'key' (the property name) and a 'value' (the property value).";function m(e,t){return t?[e,"null"]:e}function R(e,t){if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!="object")return!1;if(Array.isArray(e))return Array.isArray(t)&&e.length===t.length&&e.every((o,s)=>R(o,t[s]));if(Array.isArray(t))return!1;let n=e,i=t,r=Object.keys(n);if(r.length!==Object.keys(i).length)return!1;for(let o of r)if(!(o in i)||!R(n[o],i[o]))return!1;return!0}function j(e){return!e||typeof e!="object"?!0:e.type||e.enum||e.elements||e.values||e.discriminator||e.ref||e.properties&&Object.keys(e.properties).length>0||e.optionalProperties&&Object.keys(e.optionalProperties).length>0?!1:(e.properties!==void 0||e.optionalProperties!==void 0)&&e.additionalProperties===!0?!0:!(e.properties!==void 0||e.optionalProperties!==void 0)}function P(e,t){let n=e,i=0;for(;n.ref&&i<v;){let r=t?.[n.ref];if(!r)return!1;n=r,i++}return i>=v?!1:j(n)}function A(e,t){let n=new Set,i=[...e];for(;i.length>0;){let r=i.pop();if(!(!r||typeof r!="object")){if(r.ref){!n.has(r.ref)&&t[r.ref]&&(n.add(r.ref),i.push(t[r.ref]));continue}if(r.elements&&i.push(r.elements),r.values&&i.push(r.values),r.properties)for(let o of Object.values(r.properties))i.push(o);if(r.optionalProperties)for(let o of Object.values(r.optionalProperties))i.push(o);if(r.mapping)for(let o of Object.values(r.mapping))i.push(o)}}return n}function N(e,t,n){let i=e.definitions,r=n(t,e,i,0),o=q(e,r,i);return o.length>0?{success:!1,errors:o}:{success:!0,kind:"json",data:r}}function L(e,t,n){let i=t?`${t}. `:"",r={type:"object",properties:{kind:{type:"string",enum:["value"]},data:e},required:["kind","data"],description:`${i}Inline value.`},o={type:"object",properties:{kind:{type:"string",enum:["reference"]},ref:{type:"string",description:'A file reference. The referenced file MUST contain data that conforms to the same format described in the "value" variant.'}},required:["kind","ref"],description:`${i}Reference to a file instead of inline data.`};return n!==!1&&(r.additionalProperties=!1,o.additionalProperties=!1),{anyOf:[r,o]}}function ae(e,t){let n=e.trim().toLowerCase(),i=t.trim().toLowerCase();return i==="*/*"?!0:i.endsWith("/*")?n.startsWith(i.slice(0,i.indexOf("/")+1)):n===i}function ce(e,t){if(typeof t!="object"||t===null)return{success:!1,errors:[`/: expected object with data and mimeType fields, got ${typeof t}`]};let n=t;if(typeof n.mimeType!="string"||!n.mimeType.includes("/"))return{success:!1,errors:['/mimeType: required concrete MIME type (e.g. "image/png", "application/pdf")']};if(!ae(n.mimeType,e))return{success:!1,errors:[`/mimeType: "${n.mimeType}" does not match accepted type "${e}"`]};let i;if(n.data instanceof Uint8Array)i=n.data;else if(typeof n.data=="string")i=new Uint8Array(Buffer.from(n.data,"base64"));else return{success:!1,errors:[`/data: expected base64 string or Uint8Array, got ${typeof n.data}`]};let r={success:!0,kind:"binary",mimeType:n.mimeType,data:i};return typeof n.filename=="string"&&n.filename&&(r.filename=n.filename),r}function _(e,t,n){return e.mimeType?ce(e.mimeType,t):e.jtdSchema?N(e.jtdSchema,t,n):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function F(e,t,n){let i=e.formats;if(!i||i.length===0)return{success:!1,errors:["Signal descriptor has no formats"]};if(i.length===1)return _(i[0],t,n);let r=[];for(let o of i){let s=_(o,t,n);if(s.success)return s;r.push(...s.errors)}return{success:!1,errors:[`No format matched for signal '${e.name??"unnamed"}'. Errors: ${r.join("; ")}`]}}function G(e,t,n){if(typeof t!="object"||t===null)return{success:!1,errors:["/: expected object with signal properties, got "+typeof t]};let i=t,r={},o=[];for(let s of e){if(!s.name)continue;let a=i[s.name];if(a==null)continue;let c=F(s,a,n);if(c.success)c.kind==="binary"?r[s.name]={data:c.data,mimeType:c.mimeType,filename:c.filename}:c.kind==="json"&&(r[s.name]=c.data);else for(let f of c.errors)o.push(`/${s.name}${f.startsWith("/")?"":": "}${f}`)}return o.length>0?{success:!1,errors:o}:{success:!0,kind:"signals",signals:r}}function J(e,t){if(!e||typeof e!="object")return e;let n={...e};return n.ref&&t.has(n.ref)&&(n.ref=t.get(n.ref)),n.properties&&(n.properties=Object.fromEntries(Object.entries(n.properties).map(([i,r])=>[i,J(r,t)]))),n.optionalProperties&&(n.optionalProperties=Object.fromEntries(Object.entries(n.optionalProperties).map(([i,r])=>[i,J(r,t)]))),n.elements&&(n.elements=J(n.elements,t)),n.values&&(n.values=J(n.values,t)),n.mapping&&(n.mapping=Object.fromEntries(Object.entries(n.mapping).map(([i,r])=>[i,J(r,t)]))),n.definitions&&delete n.definitions,n}function H(e){let t={},n=new Map;for(let s=0;s<e.length;s++){let a=e[s].formats;if(a)for(let c=0;c<a.length;c++){let f=a[c].jtdSchema?.definitions;if(!f||Object.keys(f).length===0)continue;let p=new Map,l=!1;for(let[u,d]of Object.entries(f)){let h=t[u];if(h&&!R(h,d)){l=!0;break}}if(l)for(let[u,d]of Object.entries(f)){let h=t[u];if(!(h&&R(h,d)))if(h){let b=1;for(;t[`${u}_${b}`];)b++;let U=`${u}_${b}`;p.set(u,U),t[U]=d}else t[u]=d}else for(let[u,d]of Object.entries(f))t[u]||(t[u]=d);p.size>0&&n.set(`${s}:${c}`,p)}}for(let[,s]of n)for(let[,a]of s)t[a]=J(t[a],s);let i=e.map((s,a)=>{let c=s.formats;if(!c)return s;let f=!1,p=c.map((l,u)=>{if(!l.jtdSchema)return l;let d=n.get(`${a}:${u}`),h=l.jtdSchema.definitions&&Object.keys(l.jtdSchema.definitions).length>0;if(!d&&!h)return l;f=!0;let b=d?J(l.jtdSchema,d):{...l.jtdSchema};return delete b.definitions,{...l,jtdSchema:b}});return f?{...s,formats:p}:s}),r=i.flatMap(s=>(s.formats??[]).filter(a=>a.jtdSchema).map(a=>a.jtdSchema)),o=A(r,t);for(let s of Object.keys(t))o.has(s)||delete t[s];return{mergedDefs:t,signalsCopy:i}}function T(e){return!e||typeof e!="object"?"any":e.ref?e.ref:e.type?e.type:e.enum?`one of: ${e.enum.join(", ")}`:e.elements?`array of ${T(e.elements)}`:e.values?`map of ${T(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function K(e,t){let n=["Recursive nesting. This field accepts the same object structure as its parent with the following shape:"],i=[],r=[];if(t.properties)for(let[o,s]of Object.entries(t.properties))i.push(`${o} (${T(s)})`);if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))r.push(`${o} (${T(s)})`);if(i.length>0&&n.push(`Required: ${i.join(", ")}.`),r.length>0){let o=r.slice(0,8),s=r.length>8?`, and ${r.length-8} more`:"";n.push(`Optional: ${o.join(", ")}${s}.`)}return t.elements&&n.push(`Array of ${T(t.elements)}.`),t.values&&n.push(`Map with values of type ${T(t.values)}.`),n.join(" ")}function D(e){let t=[];if(!e||typeof e!="object")return t;if(e.ref&&t.push(e.ref),e.properties)for(let n of Object.values(e.properties))t.push(...D(n));if(e.optionalProperties)for(let n of Object.values(e.optionalProperties))t.push(...D(n));if(e.elements&&t.push(...D(e.elements)),e.values&&t.push(...D(e.values)),e.mapping)for(let n of Object.values(e.mapping))t.push(...D(n));return t}function fe(e){let r=new Map,o=new Set;for(let a of Object.keys(e))r.set(a,0);function s(a,c){r.set(a,1),c.push(a);let f=e[a];if(f){for(let p of D(f))if(r.has(p))if(r.get(p)===1){let l=c.indexOf(p);for(let u=l;u<c.length;u++)o.add(c[u])}else r.get(p)===0&&s(p,c)}c.pop(),r.set(a,2)}for(let a of Object.keys(e))r.get(a)===0&&s(a,[]);return o}function k(e,t,n){if(!e||typeof e!="object")return e;if(e.ref&&t.has(e.ref)){let r=n[e.ref];return{metadata:{description:r?K(e.ref,r):`Recursive reference to ${e.ref}.`}}}let i={...e};return i.properties&&(i.properties=Object.fromEntries(Object.entries(i.properties).map(([r,o])=>[r,k(o,t,n)]))),i.optionalProperties&&(i.optionalProperties=Object.fromEntries(Object.entries(i.optionalProperties).map(([r,o])=>[r,k(o,t,n)]))),i.elements&&(i.elements=k(i.elements,t,n)),i.values&&(i.values=k(i.values,t,n)),i.mapping&&(i.mapping=Object.fromEntries(Object.entries(i.mapping).map(([r,o])=>[r,k(o,t,n)]))),i}function M(e){let t=fe(e);if(t.size===0)return e;let n={};for(let[i,r]of Object.entries(e))t.has(i)?n[i]=k(r,t,e):n[i]=r;return n}function pe(e,t){e.description=e.description?`${e.description} ${t}`:t}var ue=new Set(["title","label","name","description"]);function g(e,t){let n=t.metadata;if(!n)return;let i=[],r=typeof n.title=="string"&&n.title.trim()||typeof n.label=="string"&&n.label.trim()||typeof n.name=="string"&&n.name.trim(),o=typeof n.description=="string"?n.description.trim():"";r&&o?i.push(`${r}. ${o}`):r?i.push(r):o&&i.push(o);let s=[];for(let[a,c]of Object.entries(n))ue.has(a)||(typeof c=="string"&&c.trim()?s.push(`[${a}: ${c.trim()}]`):(typeof c=="number"||typeof c=="boolean")&&s.push(`[${a}: ${c}]`));if(s.length>0&&i.push(s.join(" ")),i.length>0){let a=i.join(" ");e.description=e.description?`${e.description} ${a}`:a}}function S(e,t,n){if(n>v)throw new Error(`Schema nesting exceeded ${v} levels`);if(!e||typeof e!="object")return{type:"string",description:$};if(j(e)){let r={type:m("string",e.nullable===!0),description:$};return g(r,e),r}let i=e.nullable===!0;if(e.ref){let r=e.ref;if(!t?.[r])throw new Error(`Unresolved ref "${r}"`);if(i){let o={anyOf:[{$ref:`#/$defs/${r}`},{type:"null"}]};return g(o,e),o}return{$ref:`#/$defs/${r}`}}if(e.type){let r={},o,s=C[e.type];if(s)r.type=m("integer",i),o=`Value range: [${s.minimum}, ${s.maximum}].`;else switch(e.type){case"boolean":r.type=m("boolean",i);break;case"string":r.type=m("string",i);break;case"timestamp":r.type=m("string",i),r.format="date-time";break;case"float32":r.type=m("number",i),o=`Value range: [${E.minimum}, ${E.maximum}].`;break;case"float64":r.type=m("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return g(r,e),o&&pe(r,o),r}if(e.enum){let r={type:m("string",i),enum:i?[...e.enum,null]:e.enum};return g(r,e),r}if(e.elements){let r={type:m("array",i),items:S(e.elements,t,n+1)};return g(r,e),r}if(e.properties||e.optionalProperties){let r={},o=[];if(e.properties)for(let[a,c]of Object.entries(e.properties))r[a]=S(c,t,n+1),o.push(a);if(e.optionalProperties)for(let[a,c]of Object.entries(e.optionalProperties))r[a]=S(c,t,n+1);let s={type:m("object",i),properties:r,additionalProperties:!1};return o.length>0&&(s.required=o),g(s,e),s}if(e.values){let r=S(e.values,t,n+1),o={type:m("array",i),description:B,items:{type:"object",properties:{key:{type:"string",description:"The property name."},value:r},required:["key","value"],additionalProperties:!1}};return g(o,e),o}if(e.discriminator&&e.mapping){let r=e.discriminator,o=e.mapping,s=[];for(let[c,f]of Object.entries(o)){let p;j(f)?p={type:"object",properties:{[r]:{const:c},_data:{type:"string",description:V}},required:[r,"_data"],additionalProperties:!1}:(p=S(f,t,n+1),p.properties[r]={const:c},(p.required??=[]).unshift(r),p.additionalProperties=!1),g(p,f),s.push(p)}i&&s.push({type:"null"});let a={anyOf:s};return g(a,e),a}return{type:"string",description:$}}var le=new Set(Object.keys(C));function y(e,t,n,i){if(i>v||e==null)return e;if(t.ref){let r=n?.[t.ref];return r?y(e,r,n,i+1):e}if(j(t)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(t.type&&le.has(t.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(t.elements&&Array.isArray(e)){let r=t.elements;return e.map(o=>y(o,r,n,i+1))}if((t.properties||t.optionalProperties)&&typeof e=="object"&&e!==null){let r={...e};if(t.properties)for(let[o,s]of Object.entries(t.properties))o in r&&(r[o]=y(r[o],s,n,i+1));if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))o in r&&(r[o]=y(r[o],s,n,i+1));return r}if(t.values&&Array.isArray(e)){let r={};for(let o of e)if(typeof o=="object"&&o!==null){let s=o,a=s.key;r[a]=y(s.value,t.values,n,i+1)}return r}if(t.discriminator&&t.mapping&&typeof e=="object"&&e!==null){let r=e,o=t.discriminator,s=r[o];if(typeof s!="string")return e;let a=t.mapping[s];if(!a)return e;if(j(a)){let f=r._data;if(typeof f=="string")try{let p=JSON.parse(f);if(typeof p=="object"&&p!==null)return{[o]:s,...p}}catch{}return{[o]:s}}let c={[o]:s};if(a.properties)for(let[f,p]of Object.entries(a.properties))f in r&&(c[f]=y(r[f],p,n,i+1));if(a.optionalProperties)for(let[f,p]of Object.entries(a.optionalProperties))f in r&&(c[f]=y(r[f],p,n,i+1));return c}return e}function de(e){return{type:"object",description:`Binary content (accepted MIME type: ${e}).`,properties:{data:{type:"string",description:"The base64-encoded binary content."},filename:{type:"string",description:'Filename for the content (e.g. "report.pdf", "image.png").'},mimeType:{type:"string",description:`The concrete MIME type of the content. Must match: ${e}.`}},required:["data","mimeType","filename"],additionalProperties:!1}}var O=class e{schema;strict;jtdSchema;descriptor;descriptors;referenceMode;static fromJTD(t){let n=t.definitions,i=n&&Object.keys(n).length>0?M(n):n,r=!P(t,i),o;if(r){if(o=S(t,i,0),i&&Object.keys(i).length>0){let s=A([t],n??i);o.$defs=Object.fromEntries(Object.entries(i).filter(([a])=>s.has(a)).map(([a,c])=>[a,S(c,i,0)]))}}else o={},g(o,t);return new e(o,r,t,void 0)}static fromSignal(t,n,i){let{schema:r,strict:o}=me(t,n);if(i){let s=L(r,t.description);return new e(s,o,void 0,t)}return new e(r,o,void 0,t)}static fromSignals(t,n,i,r){let{mergedDefs:o,signalsCopy:s}=H(t),a=Object.keys(o).length>0?M(o):o,c={},f=[],p=!0;for(let u of s){if(!u.name)continue;let d=e.fromSignal(u,a,r);d.strict||(p=!1),c[u.name]=d.schema,u.optional||f.push(u.name)}let l={type:"object",properties:c,required:f.length>0?f:void 0,additionalProperties:!1};return Object.keys(a).length>0&&(l.$defs=Object.fromEntries(Object.entries(a).map(([u,d])=>[u,S(d,a,0)]))),i&&n?l.description=`${i}. ${n}`:i?l.description=i:n&&(l.description=n),new e(l,p,void 0,void 0,t,r)}static fromJSON(t){let n=typeof t=="string"?JSON.parse(t):t;if(n.descriptors)return e.fromSignals(n.descriptors,n.description,n.label,n.referenceMode);if(n.descriptor)return e.fromSignal(n.descriptor);if(n.jtdSchema)return e.fromJTD(n.jtdSchema);throw new Error("Cannot deserialize: missing jtdSchema, descriptor, or descriptors")}constructor(t,n,i,r,o,s){this.schema=t,this.strict=n,this.jtdSchema=i,this.descriptor=r,this.descriptors=o,this.referenceMode=s??!1}convert=t=>this.descriptors?G(this.descriptors,t,y):this.jtdSchema?N(this.jtdSchema,t,y):this.descriptor?F(this.descriptor,t,y):{success:!1,errors:["No source schema available"]};toJSON(){if(this.descriptors){let t={schema:this.schema,strict:this.strict,descriptors:this.descriptors};return this.schema.description&&(t.description=this.schema.description),this.referenceMode&&(t.referenceMode=!0),t}return this.descriptor?{schema:this.schema,strict:this.strict,descriptor:this.descriptor}:{schema:this.schema,strict:this.strict,jtdSchema:this.jtdSchema}}};function me(e,t){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[a]=n,{schema:c,strict:f}=W(a,t);if(e.label||e.description){let p=[];e.label&&p.push(e.label),e.description&&p.push(e.description);let l=p.join(". ");c.description=c.description?`${l} ${c.description}`:l}return{schema:c,strict:f}}let i=[],r=!0;for(let a of n){let{schema:c,strict:f}=W(a,t);f||(r=!1),a.jtdSchema&&(c.description=c.description?`Structured JSON data. ${c.description}`:"Structured JSON data."),i.push(c)}let o=e.description??"";return{schema:{anyOf:i,description:o||void 0},strict:r}}function W(e,t){if(e.jtdSchema){let n=t??e.jtdSchema.definitions,i=n&&Object.keys(n).length>0?M(n):n,r=!P(e.jtdSchema,i),o;if(r){if(o=S(e.jtdSchema,i,0),!t&&i&&Object.keys(i).length>0){let s=A([e.jtdSchema],i);o.$defs=Object.fromEntries(Object.entries(i).filter(([a])=>s.has(a)).map(([a,c])=>[a,S(c,i,0)]))}}else o={},g(o,e.jtdSchema);return{schema:o,strict:r}}if(e.mimeType)return{schema:de(e.mimeType),strict:!0};throw new Error("Signal format has neither jtdSchema nor mimeType")}function ge(e){return O.fromJTD(e)}function ye(e){return O.fromSignal(e)}0&&(module.exports={AnthropicConversion,convertSignalToAnthropicSchema,convertToAnthropicSchema});
|
|
1
|
+
"use strict";var x=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)x(e,n,{get:t[n],enumerable:!0})},Q=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of z(t))!X.call(e,r)&&r!==n&&x(e,r,{get:()=>t[r],enumerable:!(i=Y(t,r))||i.enumerable});return e};var ee=e=>Q(x({},"__esModule",{value:!0}),e);var Se={};Z(Se,{AnthropicConversion:()=>O,convertSignalToAnthropicSchema:()=>ye,convertToAnthropicSchema:()=>ge});module.exports=ee(Se);var w=require("jtd");var te=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function ne(e){return e.length===0?"/":e.map(t=>/^\d+$/.test(t)?`[${t}]`:`.${t}`).join("")}function I(e,t){let n=e;for(let i=0;i<t.length-1&&(n&&typeof n=="object"&&t[i]in n);i++)n=n[t[i]];return n}function re(e,t){let n=e;for(let i of t)if(n&&typeof n=="object")n=n[i];else return;return n}function ie(e,t,n){let{instancePath:i,schemaPath:r}=e,o=ne(i),s=r[r.length-1];if(s==="type"){let c=I(t,r)?.type;return c==="boolean"?`${o}: expected boolean`:c==="string"?`${o}: expected string`:c==="timestamp"?`${o}: expected timestamp string`:te.has(c)?`${o}: expected integer`:`${o}: expected number`}if(s==="enum"){let c=I(t,r)?.enum;return`${o}: expected one of [${c.join(", ")}]`}if(r.length>=2&&r[r.length-2]==="properties"&&s)return`${o==="/"?"":o}.${s}: missing required property`;if(s==="elements")return`${o}: expected array`;if(s==="properties"||s==="optionalProperties"||s==="values")return`${o}: expected object`;if(s==="discriminator")return`${o}: expected string discriminator`;if(s==="mapping"){let a=re(n,i);return`${o}: unknown variant "${a}"`}return r.length===0?`${o}: unexpected property`:`${o}: validation error at /${r.join("/")}`}function q(e,t,n){let i=n??e.definitions,r=i?{...e,definitions:i}:e;return(0,w.isValidSchema)(r)?(0,w.validate)(r,t,{maxDepth:oe,maxErrors:se}).map(s=>ie(s,r,t)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var oe=32,se=100;var v=32,C={int8:{minimum:-128,maximum:127},uint8:{minimum:0,maximum:255},int16:{minimum:-32768,maximum:32767},uint16:{minimum:0,maximum:65535},int32:{minimum:-2147483648,maximum:2147483647},uint32:{minimum:0,maximum:4294967295}},E={minimum:-34028235e31,maximum:34028235e31},$=`Must be a valid JSON value encoded as a string. For objects: '{"key": "value"}', for arrays: '[1, 2]', for primitives: '"hello"' or '42' or 'true' or 'null'.`,V=`The variant data encoded as a valid JSON string (e.g. '{"key": "value"}').`,B="Array of key-value entries representing a map/dictionary. Each entry has a string 'key' (the property name) and a 'value' (the property value).";function m(e,t){return t?[e,"null"]:e}function R(e,t){if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!="object")return!1;if(Array.isArray(e))return Array.isArray(t)&&e.length===t.length&&e.every((o,s)=>R(o,t[s]));if(Array.isArray(t))return!1;let n=e,i=t,r=Object.keys(n);if(r.length!==Object.keys(i).length)return!1;for(let o of r)if(!(o in i)||!R(n[o],i[o]))return!1;return!0}function j(e){return!e||typeof e!="object"?!0:e.type||e.enum||e.elements||e.values||e.discriminator||e.ref||e.properties&&Object.keys(e.properties).length>0||e.optionalProperties&&Object.keys(e.optionalProperties).length>0?!1:(e.properties!==void 0||e.optionalProperties!==void 0)&&e.additionalProperties===!0?!0:!(e.properties!==void 0||e.optionalProperties!==void 0)}function P(e,t){let n=e,i=0;for(;n.ref&&i<v;){let r=t?.[n.ref];if(!r)return!1;n=r,i++}return i>=v?!1:j(n)}function A(e,t){let n=new Set,i=[...e];for(;i.length>0;){let r=i.pop();if(!(!r||typeof r!="object")){if(r.ref){!n.has(r.ref)&&t[r.ref]&&(n.add(r.ref),i.push(t[r.ref]));continue}if(r.elements&&i.push(r.elements),r.values&&i.push(r.values),r.properties)for(let o of Object.values(r.properties))i.push(o);if(r.optionalProperties)for(let o of Object.values(r.optionalProperties))i.push(o);if(r.mapping)for(let o of Object.values(r.mapping))i.push(o)}}return n}function N(e,t,n){let i=e.definitions,r=n(t,e,i,0),o=q(e,r,i);return o.length>0?{success:!1,errors:o}:{success:!0,kind:"json",data:r}}function L(e,t,n){let i=t?`${t}. `:"",r={type:"object",properties:{kind:{type:"string",enum:["value"]},data:e},required:["kind","data"],description:`${i}Inline value.`},o={type:"object",properties:{kind:{type:"string",enum:["reference"]},ref:{type:"string",description:'A file reference. The referenced file MUST contain data that conforms to the same format described in the "value" variant.'}},required:["kind","ref"],description:`${i}Reference to a file instead of inline data.`};return n!==!1&&(r.additionalProperties=!1,o.additionalProperties=!1),{anyOf:[r,o]}}function ae(e,t){let n=e.trim().toLowerCase(),i=t.trim().toLowerCase();return i==="*/*"?!0:i.endsWith("/*")?n.startsWith(i.slice(0,i.indexOf("/")+1)):n===i}function ce(e,t){if(typeof t!="object"||t===null)return{success:!1,errors:[`/: expected object with data and mimeType fields, got ${typeof t}`]};let n=t;if(typeof n.mimeType!="string"||!n.mimeType.includes("/"))return{success:!1,errors:['/mimeType: required concrete MIME type (e.g. "image/png", "application/pdf")']};if(!ae(n.mimeType,e))return{success:!1,errors:[`/mimeType: "${n.mimeType}" does not match accepted type "${e}"`]};let i;if(n.data instanceof Uint8Array)i=n.data;else if(typeof n.data=="string")i=new Uint8Array(Buffer.from(n.data,"base64"));else return{success:!1,errors:[`/data: expected base64 string or Uint8Array, got ${typeof n.data}`]};let r={success:!0,kind:"binary",mimeType:n.mimeType,data:i};return typeof n.filename=="string"&&n.filename&&(r.filename=n.filename),r}function _(e,t,n){return e.mimeType?ce(e.mimeType,t):e.jtdSchema?N(e.jtdSchema,t,n):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function F(e,t,n){let i=e.formats;if(!i||i.length===0)return{success:!1,errors:["Signal descriptor has no formats"]};if(i.length===1)return _(i[0],t,n);let r=[];for(let o of i){let s=_(o,t,n);if(s.success)return s;r.push(...s.errors)}return{success:!1,errors:[`No format matched for signal '${e.name??"unnamed"}'. Errors: ${r.join("; ")}`]}}function G(e,t,n){if(typeof t!="object"||t===null)return{success:!1,errors:["/: expected object with signal properties, got "+typeof t]};let i=t,r={},o=[];for(let s of e){if(!s.name)continue;let a=i[s.name];if(a==null)continue;let c=F(s,a,n);if(c.success)c.kind==="binary"?r[s.name]={data:c.data,mimeType:c.mimeType,filename:c.filename}:c.kind==="json"&&(r[s.name]=c.data);else for(let p of c.errors)o.push(`/${s.name}${p.startsWith("/")?"":": "}${p}`)}return o.length>0?{success:!1,errors:o}:{success:!0,kind:"signals",signals:r}}function J(e,t){if(!e||typeof e!="object")return e;let n={...e};return n.ref&&t.has(n.ref)&&(n.ref=t.get(n.ref)),n.properties&&(n.properties=Object.fromEntries(Object.entries(n.properties).map(([i,r])=>[i,J(r,t)]))),n.optionalProperties&&(n.optionalProperties=Object.fromEntries(Object.entries(n.optionalProperties).map(([i,r])=>[i,J(r,t)]))),n.elements&&(n.elements=J(n.elements,t)),n.values&&(n.values=J(n.values,t)),n.mapping&&(n.mapping=Object.fromEntries(Object.entries(n.mapping).map(([i,r])=>[i,J(r,t)]))),n.definitions&&delete n.definitions,n}function H(e){let t={},n=new Map;for(let s=0;s<e.length;s++){let a=e[s].formats;if(a)for(let c=0;c<a.length;c++){let p=a[c].jtdSchema?.definitions;if(!p||Object.keys(p).length===0)continue;let f=new Map,l=!1;for(let[u,d]of Object.entries(p)){let h=t[u];if(h&&!R(h,d)){l=!0;break}}if(l)for(let[u,d]of Object.entries(p)){let h=t[u];if(!(h&&R(h,d)))if(h){let b=1;for(;t[`${u}_${b}`];)b++;let U=`${u}_${b}`;f.set(u,U),t[U]=d}else t[u]=d}else for(let[u,d]of Object.entries(p))t[u]||(t[u]=d);f.size>0&&n.set(`${s}:${c}`,f)}}for(let[,s]of n)for(let[,a]of s)t[a]=J(t[a],s);let i=e.map((s,a)=>{let c=s.formats;if(!c)return s;let p=!1,f=c.map((l,u)=>{if(!l.jtdSchema)return l;let d=n.get(`${a}:${u}`),h=l.jtdSchema.definitions&&Object.keys(l.jtdSchema.definitions).length>0;if(!d&&!h)return l;p=!0;let b=d?J(l.jtdSchema,d):{...l.jtdSchema};return delete b.definitions,{...l,jtdSchema:b}});return p?{...s,formats:f}:s}),r=i.flatMap(s=>(s.formats??[]).filter(a=>a.jtdSchema).map(a=>a.jtdSchema)),o=A(r,t);for(let s of Object.keys(t))o.has(s)||delete t[s];return{mergedDefs:t,signalsCopy:i}}function T(e){return!e||typeof e!="object"?"any":e.ref?e.ref:e.type?e.type:e.enum?`one of: ${e.enum.join(", ")}`:e.elements?`array of ${T(e.elements)}`:e.values?`map of ${T(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function K(e,t){let n=["Recursive nesting. This field accepts the same object structure as its parent with the following shape:"],i=[],r=[];if(t.properties)for(let[o,s]of Object.entries(t.properties))i.push(`${o} (${T(s)})`);if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))r.push(`${o} (${T(s)})`);if(i.length>0&&n.push(`Required: ${i.join(", ")}.`),r.length>0){let o=r.slice(0,8),s=r.length>8?`, and ${r.length-8} more`:"";n.push(`Optional: ${o.join(", ")}${s}.`)}return t.elements&&n.push(`Array of ${T(t.elements)}.`),t.values&&n.push(`Map with values of type ${T(t.values)}.`),n.join(" ")}function D(e){let t=[];if(!e||typeof e!="object")return t;if(e.ref&&t.push(e.ref),e.properties)for(let n of Object.values(e.properties))t.push(...D(n));if(e.optionalProperties)for(let n of Object.values(e.optionalProperties))t.push(...D(n));if(e.elements&&t.push(...D(e.elements)),e.values&&t.push(...D(e.values)),e.mapping)for(let n of Object.values(e.mapping))t.push(...D(n));return t}function pe(e){let r=new Map,o=new Set;for(let a of Object.keys(e))r.set(a,0);function s(a,c){r.set(a,1),c.push(a);let p=e[a];if(p){for(let f of D(p))if(r.has(f))if(r.get(f)===1){let l=c.indexOf(f);for(let u=l;u<c.length;u++)o.add(c[u])}else r.get(f)===0&&s(f,c)}c.pop(),r.set(a,2)}for(let a of Object.keys(e))r.get(a)===0&&s(a,[]);return o}function k(e,t,n){if(!e||typeof e!="object")return e;if(e.ref&&t.has(e.ref)){let r=n[e.ref];return{metadata:{description:r?K(e.ref,r):`Recursive reference to ${e.ref}.`}}}let i={...e};return i.properties&&(i.properties=Object.fromEntries(Object.entries(i.properties).map(([r,o])=>[r,k(o,t,n)]))),i.optionalProperties&&(i.optionalProperties=Object.fromEntries(Object.entries(i.optionalProperties).map(([r,o])=>[r,k(o,t,n)]))),i.elements&&(i.elements=k(i.elements,t,n)),i.values&&(i.values=k(i.values,t,n)),i.mapping&&(i.mapping=Object.fromEntries(Object.entries(i.mapping).map(([r,o])=>[r,k(o,t,n)]))),i}function M(e){let t=pe(e);if(t.size===0)return e;let n={};for(let[i,r]of Object.entries(e))t.has(i)?n[i]=k(r,t,e):n[i]=r;return n}function fe(e,t){e.description=e.description?`${e.description} ${t}`:t}var ue=new Set(["title","label","name","description"]);function g(e,t){let n=t.metadata;if(!n)return;let i=[],r=typeof n.title=="string"&&n.title.trim()||typeof n.label=="string"&&n.label.trim()||typeof n.name=="string"&&n.name.trim(),o=typeof n.description=="string"?n.description.trim():"";r&&o?i.push(`${r}. ${o}`):r?i.push(r):o&&i.push(o);let s=[];for(let[a,c]of Object.entries(n))ue.has(a)||(typeof c=="string"&&c.trim()?s.push(`[${a}: ${c.trim()}]`):(typeof c=="number"||typeof c=="boolean")&&s.push(`[${a}: ${c}]`));if(s.length>0&&i.push(s.join(" ")),i.length>0){let a=i.join(" ");e.description=e.description?`${e.description} ${a}`:a}}function S(e,t,n){if(n>v)throw new Error(`Schema nesting exceeded ${v} levels`);if(!e||typeof e!="object")return{type:"string",description:$};if(j(e)){let r={type:m("string",e.nullable===!0),description:$};return g(r,e),r}let i=e.nullable===!0;if(e.ref){let r=e.ref;if(!t?.[r])throw new Error(`Unresolved ref "${r}"`);if(i){let o={anyOf:[{$ref:`#/$defs/${r}`},{type:"null"}]};return g(o,e),o}return{$ref:`#/$defs/${r}`}}if(e.type){let r={},o,s=C[e.type];if(s)r.type=m("integer",i),o=`Value range: [${s.minimum}, ${s.maximum}].`;else switch(e.type){case"boolean":r.type=m("boolean",i);break;case"string":r.type=m("string",i);break;case"timestamp":r.type=m("string",i),r.format="date-time";break;case"float32":r.type=m("number",i),o=`Value range: [${E.minimum}, ${E.maximum}].`;break;case"float64":r.type=m("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return g(r,e),o&&fe(r,o),r}if(e.enum){let r={type:m("string",i),enum:i?[...e.enum,null]:e.enum};return g(r,e),r}if(e.elements){let r={type:m("array",i),items:S(e.elements,t,n+1)};return g(r,e),r}if(e.properties||e.optionalProperties){let r={},o=[];if(e.properties)for(let[a,c]of Object.entries(e.properties))r[a]=S(c,t,n+1),o.push(a);if(e.optionalProperties)for(let[a,c]of Object.entries(e.optionalProperties))r[a]=S(c,t,n+1);let s={type:m("object",i),properties:r,additionalProperties:!1};return o.length>0&&(s.required=o),g(s,e),s}if(e.values){let r=S(e.values,t,n+1),o={type:m("array",i),description:B,items:{type:"object",properties:{key:{type:"string",description:"The property name."},value:r},required:["key","value"],additionalProperties:!1}};return g(o,e),o}if(e.discriminator&&e.mapping){let r=e.discriminator,o=e.mapping,s=[];for(let[c,p]of Object.entries(o)){let f;j(p)?f={type:"object",properties:{[r]:{const:c},_data:{type:"string",description:V}},required:[r,"_data"],additionalProperties:!1}:(f=S(p,t,n+1),f.properties[r]={const:c},(f.required??=[]).unshift(r),f.additionalProperties=!1),g(f,p),s.push(f)}i&&s.push({type:"null"});let a={anyOf:s};return g(a,e),a}return{type:"string",description:$}}var le=new Set(Object.keys(C));function y(e,t,n,i){if(i>v||e==null)return e;if(t.ref){let r=n?.[t.ref];return r?y(e,r,n,i+1):e}if(j(t)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(t.type&&le.has(t.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(t.elements&&Array.isArray(e)){let r=t.elements;return e.map(o=>y(o,r,n,i+1))}if((t.properties||t.optionalProperties)&&typeof e=="object"&&e!==null){let r={...e};if(t.properties)for(let[o,s]of Object.entries(t.properties))o in r&&(r[o]=y(r[o],s,n,i+1));if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))o in r&&(r[o]=y(r[o],s,n,i+1));return r}if(t.values&&Array.isArray(e)){let r={};for(let o of e)if(typeof o=="object"&&o!==null){let s=o,a=s.key;r[a]=y(s.value,t.values,n,i+1)}return r}if(t.discriminator&&t.mapping&&typeof e=="object"&&e!==null){let r=e,o=t.discriminator,s=r[o];if(typeof s!="string")return e;let a=t.mapping[s];if(!a)return e;if(j(a)){let p=r._data;if(typeof p=="string")try{let f=JSON.parse(p);if(typeof f=="object"&&f!==null)return{[o]:s,...f}}catch{}return{[o]:s}}let c={[o]:s};if(a.properties)for(let[p,f]of Object.entries(a.properties))p in r&&(c[p]=y(r[p],f,n,i+1));if(a.optionalProperties)for(let[p,f]of Object.entries(a.optionalProperties))p in r&&(c[p]=y(r[p],f,n,i+1));return c}return e}function de(e){return{type:"object",description:`Binary content (accepted MIME type: ${e}).`,properties:{data:{type:"string",description:"The base64-encoded binary content."},filename:{type:"string",description:'Filename for the content (e.g. "report.pdf", "image.png").'},mimeType:{type:"string",description:`The concrete MIME type of the content. Must match: ${e}.`}},required:["data","mimeType","filename"],additionalProperties:!1}}var O=class e{schema;strict;jtdSchema;descriptor;descriptors;referenceMode;static fromJTD(t){let n=t.definitions,i=n&&Object.keys(n).length>0?M(n):n,r=!P(t,i),o;if(r){if(o=S(t,i,0),i&&Object.keys(i).length>0){let s=A([t],n??i);o.$defs=Object.fromEntries(Object.entries(i).filter(([a])=>s.has(a)).map(([a,c])=>[a,S(c,i,0)]))}if(t.discriminator&&t.mapping){let s=o;o={type:"object",properties:{input:s},required:["input"],additionalProperties:!1},s.$defs&&(o.$defs=s.$defs,delete s.$defs)}}else o={},g(o,t);return new e(o,r,t,void 0)}static fromSignal(t,n,i){let{schema:r,strict:o}=me(t,n);if(i){let s=L(r,t.description);return new e(s,o,void 0,t)}return new e(r,o,void 0,t)}static fromSignals(t,n,i,r){let{mergedDefs:o,signalsCopy:s}=H(t),a=Object.keys(o).length>0?M(o):o,c={},p=[],f=!0;for(let u of s){if(!u.name)continue;let d=e.fromSignal(u,a,r);d.strict||(f=!1),c[u.name]=d.schema,u.optional||p.push(u.name)}let l={type:"object",properties:c,required:p.length>0?p:void 0,additionalProperties:!1};return Object.keys(a).length>0&&(l.$defs=Object.fromEntries(Object.entries(a).map(([u,d])=>[u,S(d,a,0)]))),i&&n?l.description=`${i}. ${n}`:i?l.description=i:n&&(l.description=n),new e(l,f,void 0,void 0,t,r)}static fromJSON(t){let n=typeof t=="string"?JSON.parse(t):t;if(n.descriptors)return e.fromSignals(n.descriptors,n.description,n.label,n.referenceMode);if(n.descriptor)return e.fromSignal(n.descriptor);if(n.jtdSchema)return e.fromJTD(n.jtdSchema);throw new Error("Cannot deserialize: missing jtdSchema, descriptor, or descriptors")}constructor(t,n,i,r,o,s){this.schema=t,this.strict=n,this.jtdSchema=i,this.descriptor=r,this.descriptors=o,this.referenceMode=s??!1}convert=t=>{if(this.descriptors)return G(this.descriptors,t,y);if(this.jtdSchema){let n=t;return this.jtdSchema.discriminator&&this.jtdSchema.mapping&&typeof n=="object"&&n!==null&&"input"in n&&(n=n.input),N(this.jtdSchema,n,y)}return this.descriptor?F(this.descriptor,t,y):{success:!1,errors:["No source schema available"]}};toJSON(){if(this.descriptors){let t={schema:this.schema,strict:this.strict,descriptors:this.descriptors};return this.schema.description&&(t.description=this.schema.description),this.referenceMode&&(t.referenceMode=!0),t}return this.descriptor?{schema:this.schema,strict:this.strict,descriptor:this.descriptor}:{schema:this.schema,strict:this.strict,jtdSchema:this.jtdSchema}}};function me(e,t){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[a]=n,{schema:c,strict:p}=W(a,t);if(e.label||e.description){let f=[];e.label&&f.push(e.label),e.description&&f.push(e.description);let l=f.join(". ");c.description=c.description?`${l} ${c.description}`:l}return{schema:c,strict:p}}let i=[],r=!0;for(let a of n){let{schema:c,strict:p}=W(a,t);p||(r=!1),a.jtdSchema&&(c.description=c.description?`Structured JSON data. ${c.description}`:"Structured JSON data."),i.push(c)}let o=e.description??"";return{schema:{anyOf:i,description:o||void 0},strict:r}}function W(e,t){if(e.jtdSchema){let n=t??e.jtdSchema.definitions,i=n&&Object.keys(n).length>0?M(n):n,r=!P(e.jtdSchema,i),o;if(r){if(o=S(e.jtdSchema,i,0),!t&&i&&Object.keys(i).length>0){let s=A([e.jtdSchema],i);o.$defs=Object.fromEntries(Object.entries(i).filter(([a])=>s.has(a)).map(([a,c])=>[a,S(c,i,0)]))}}else o={},g(o,e.jtdSchema);return{schema:o,strict:r}}if(e.mimeType)return{schema:de(e.mimeType),strict:!0};throw new Error("Signal format has neither jtdSchema nor mimeType")}function ge(e){return O.fromJTD(e)}function ye(e){return O.fromSignal(e)}0&&(module.exports={AnthropicConversion,convertSignalToAnthropicSchema,convertToAnthropicSchema});
|
|
2
2
|
//# sourceMappingURL=anthropic.cjs.map
|