@mochabug/adapt-sdk 0.4.9 → 0.4.11
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 +10 -4
- 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/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/gemini/index.d.ts +12 -8
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/openai/index.d.ts +12 -6
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/schema-utils.d.ts +78 -4
- package/dist/schema-utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -105,6 +105,12 @@ export declare class AnthropicConversion<T extends ConvertSuccess = ConvertSucce
|
|
|
105
105
|
* Set when created via {@link fromSignals}; `undefined` otherwise.
|
|
106
106
|
*/
|
|
107
107
|
readonly descriptors?: SignalDescriptorJson[];
|
|
108
|
+
/**
|
|
109
|
+
* When true, MIME-format signals expect blob reference strings instead of
|
|
110
|
+
* base64-encoded data objects. Mixed signals (JTD + MIME) use a discriminated
|
|
111
|
+
* anyOf with `kind: "value" | "reference"`.
|
|
112
|
+
*/
|
|
113
|
+
readonly referenceMode: boolean;
|
|
108
114
|
/**
|
|
109
115
|
* Build a conversion from a JTD schema.
|
|
110
116
|
*
|
|
@@ -136,7 +142,7 @@ export declare class AnthropicConversion<T extends ConvertSuccess = ConvertSucce
|
|
|
136
142
|
* @throws If the descriptor has no formats, or a format has neither
|
|
137
143
|
* `jtdSchema` nor `mimeType`.
|
|
138
144
|
*/
|
|
139
|
-
static fromSignal(descriptor: SignalDescriptorJson, sharedDefs?: Record<string, JTDSchemaJson
|
|
145
|
+
static fromSignal(descriptor: SignalDescriptorJson, sharedDefs?: Record<string, JTDSchemaJson>, referenceMode?: boolean): AnthropicConversion<ConvertSuccessJson | ConvertSuccessBinary>;
|
|
140
146
|
/**
|
|
141
147
|
* Build a conversion from multiple signal descriptors.
|
|
142
148
|
*
|
|
@@ -162,7 +168,7 @@ export declare class AnthropicConversion<T extends ConvertSuccess = ConvertSucce
|
|
|
162
168
|
* @returns A new {@link AnthropicConversion} with `descriptors` set.
|
|
163
169
|
* @throws If any signal has no formats or an invalid format.
|
|
164
170
|
*/
|
|
165
|
-
static fromSignals(signals: SignalDescriptorJson[], description?: string, label?: string): AnthropicConversion<ConvertSuccessSignals>;
|
|
171
|
+
static fromSignals(signals: SignalDescriptorJson[], description?: string, label?: string, referenceMode?: boolean): AnthropicConversion<ConvertSuccessSignals>;
|
|
166
172
|
/**
|
|
167
173
|
* Restore an {@link AnthropicConversion} from its serialized form.
|
|
168
174
|
*
|
|
@@ -198,10 +204,10 @@ export declare class AnthropicConversion<T extends ConvertSuccess = ConvertSucce
|
|
|
198
204
|
* For multi-format signals, the first non-null `format_N` property is
|
|
199
205
|
* selected and converted individually.
|
|
200
206
|
*
|
|
201
|
-
* @param
|
|
207
|
+
* @param value - The value to convert. JSON for JTD, or `{ data, mimeType, filename }` for MIME.
|
|
202
208
|
* @returns A {@link ConvertResult} indicating success or failure with errors.
|
|
203
209
|
*/
|
|
204
|
-
convert: (
|
|
210
|
+
convert: (value: unknown) => T | ConvertFailure;
|
|
205
211
|
/**
|
|
206
212
|
* Produce a JSON-serializable representation of this conversion.
|
|
207
213
|
*
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/anthropic/index.ts"],"names":[],"mappings":"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"}
|
package/dist/cjs/anthropic.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var r in t)O(e,r,{get:t[r],enumerable:!0})},W=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of K(t))!L.call(e,n)&&n!==r&&O(e,n,{get:()=>t[n],enumerable:!(i=H(t,n))||i.enumerable});return e};var z=e=>W(O({},"__esModule",{value:!0}),e);var le={};Y(le,{AnthropicConversion:()=>k,convertSignalToAnthropicSchema:()=>fe,convertToAnthropicSchema:()=>ue});module.exports=z(le);var j=require("jtd");var X=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function Z(e){return e.length===0?"/":e.map(t=>/^\d+$/.test(t)?`[${t}]`:`.${t}`).join("")}function N(e,t){let r=e;for(let i=0;i<t.length-1&&(r&&typeof r=="object"&&t[i]in r);i++)r=r[t[i]];return r}function Q(e,t){let r=e;for(let i of t)if(r&&typeof r=="object")r=r[i];else return;return r}function ee(e,t,r){let{instancePath:i,schemaPath:n}=e,o=Z(i),s=n[n.length-1];if(s==="type"){let c=N(t,n)?.type;return c==="boolean"?`${o}: expected boolean`:c==="string"?`${o}: expected string`:c==="timestamp"?`${o}: expected timestamp string`:X.has(c)?`${o}: expected integer`:`${o}: expected number`}if(s==="enum"){let c=N(t,n)?.enum;return`${o}: expected one of [${c.join(", ")}]`}if(n.length>=2&&n[n.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=Q(r,i);return`${o}: unknown variant "${a}"`}return n.length===0?`${o}: unexpected property`:`${o}: validation error at /${n.join("/")}`}function F(e,t,r){let i=r??e.definitions,n=i?{...e,definitions:i}:e;return(0,j.isValidSchema)(n)?(0,j.validate)(n,t,{maxDepth:te,maxErrors:ne}).map(s=>ee(s,n,t)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var te=32,ne=100;var b=32,R={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}},A={minimum:-34028235e31,maximum:34028235e31},w=`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'.`,I=`The variant data encoded as a valid JSON string (e.g. '{"key": "value"}').`,U="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 d(e,t){return t?[e,"null"]:e}function $(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)=>$(o,t[s]));if(Array.isArray(t))return!1;let r=e,i=t,n=Object.keys(r);if(n.length!==Object.keys(i).length)return!1;for(let o of n)if(!(o in i)||!$(r[o],i[o]))return!1;return!0}function v(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 x(e,t){let r=e,i=0;for(;r.ref&&i<b;){let n=t?.[r.ref];if(!n)return!1;r=n,i++}return i>=b?!1:v(r)}function C(e,t,r){let i=e.definitions,n=r(t,e,i,0),o=F(e,n,i);return o.length>0?{success:!1,errors:o}:{success:!0,kind:"json",data:n}}function re(e,t){if(typeof t!="object"||t===null)return{success:!1,errors:[`/: expected object with 'data' field for MIME type ${e}, got ${typeof t}`]};let r=t;if(typeof r.data!="string")return{success:!1,errors:[`/data: expected base64 string for MIME type ${e}, got ${typeof r.data}`]};let i={success:!0,kind:"binary",mimeType:e,data:new Uint8Array(Buffer.from(r.data,"base64"))};return typeof r.filename=="string"&&r.filename&&(i.filename=r.filename),i}function M(e,t,r){return e.mimeType?re(e.mimeType,t):e.jtdSchema?C(e.jtdSchema,t,r):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function E(e,t,r){let i=e.formats;if(!i||i.length===0)return{success:!1,errors:["Signal descriptor has no formats"]};if(i.length===1)return M(i[0],t,r);if(typeof t!="object"||t===null)return{success:!1,errors:[`/: expected object with format properties, got ${typeof t}`]};let n=t;for(let s=0;s<i.length;s++){let a=`format_${s}`;if(n[a]!==void 0&&n[a]!==null)return M(i[s],n[a],r)}if(e.optional)return{success:!0,kind:"json",data:null};let o=i.map((s,a)=>`format_${a}`);return{success:!1,errors:[`Signal '${e.name??"unnamed"}' is required but no format was provided. Set exactly one of: ${o.join(", ")}.`]}}function _(e,t,r){if(typeof t!="object"||t===null)return{success:!1,errors:["/: expected object with signal properties, got "+typeof t]};let i=t,n={},o=[];for(let s of e){if(!s.name)continue;let a=i[s.name];if(a==null)continue;let c=E(s,a,r);if(c.success)c.kind==="binary"?n[s.name]={data:c.data,mimeType:c.mimeType,filename:c.filename}:c.kind==="json"&&(n[s.name]=c.data);else for(let u of c.errors)o.push(`/${s.name}${u.startsWith("/")?"":": "}${u}`)}return o.length>0?{success:!1,errors:o}:{success:!0,kind:"signals",signals:n}}function S(e,t){if(!e||typeof e!="object")return e;let r={...e};return r.ref&&t.has(r.ref)&&(r.ref=t.get(r.ref)),r.properties&&(r.properties=Object.fromEntries(Object.entries(r.properties).map(([i,n])=>[i,S(n,t)]))),r.optionalProperties&&(r.optionalProperties=Object.fromEntries(Object.entries(r.optionalProperties).map(([i,n])=>[i,S(n,t)]))),r.elements&&(r.elements=S(r.elements,t)),r.values&&(r.values=S(r.values,t)),r.mapping&&(r.mapping=Object.fromEntries(Object.entries(r.mapping).map(([i,n])=>[i,S(n,t)]))),r.definitions&&delete r.definitions,r}function q(e){let t={},r=new Map;for(let n=0;n<e.length;n++){let o=e[n].formats;if(o)for(let s=0;s<o.length;s++){let a=o[s].jtdSchema?.definitions;if(!a||Object.keys(a).length===0)continue;let c=new Map,u=!1;for(let[p,f]of Object.entries(a)){let l=t[p];if(l&&!$(l,f)){u=!0;break}}if(u)for(let[p,f]of Object.entries(a)){let l=t[p];if(!(l&&$(l,f)))if(l){let h=1;for(;t[`${p}_${h}`];)h++;let P=`${p}_${h}`;c.set(p,P),t[P]=f}else t[p]=f}else for(let[p,f]of Object.entries(a))t[p]||(t[p]=f);c.size>0&&r.set(`${n}:${s}`,c)}}for(let[,n]of r)for(let[,o]of n)t[o]=S(t[o],n);let i=e.map((n,o)=>{let s=n.formats;if(!s)return n;let a=!1,c=s.map((u,p)=>{if(!u.jtdSchema)return u;let f=r.get(`${o}:${p}`),l=u.jtdSchema.definitions&&Object.keys(u.jtdSchema.definitions).length>0;if(!f&&!l)return u;a=!0;let h=f?S(u.jtdSchema,f):{...u.jtdSchema};return delete h.definitions,{...u,jtdSchema:h}});return a?{...n,formats:c}:n});return{mergedDefs:t,signalsCopy:i}}function J(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 ${J(e.elements)}`:e.values?`map of ${J(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function B(e,t){let r=["Recursive nesting. This field accepts the same object structure as its parent with the following shape:"],i=[],n=[];if(t.properties)for(let[o,s]of Object.entries(t.properties))i.push(`${o} (${J(s)})`);if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))n.push(`${o} (${J(s)})`);if(i.length>0&&r.push(`Required: ${i.join(", ")}.`),n.length>0){let o=n.slice(0,8),s=n.length>8?`, and ${n.length-8} more`:"";r.push(`Optional: ${o.join(", ")}${s}.`)}return t.elements&&r.push(`Array of ${J(t.elements)}.`),t.values&&r.push(`Map with values of type ${J(t.values)}.`),r.join(" ")}function T(e){let t=[];if(!e||typeof e!="object")return t;if(e.ref&&t.push(e.ref),e.properties)for(let r of Object.values(e.properties))t.push(...T(r));if(e.optionalProperties)for(let r of Object.values(e.optionalProperties))t.push(...T(r));if(e.elements&&t.push(...T(e.elements)),e.values&&t.push(...T(e.values)),e.mapping)for(let r of Object.values(e.mapping))t.push(...T(r));return t}function ie(e){let n=new Map,o=new Set;for(let a of Object.keys(e))n.set(a,0);function s(a,c){n.set(a,1),c.push(a);let u=e[a];if(u){for(let p of T(u))if(n.has(p))if(n.get(p)===1){let f=c.indexOf(p);for(let l=f;l<c.length;l++)o.add(c[l])}else n.get(p)===0&&s(p,c)}c.pop(),n.set(a,2)}for(let a of Object.keys(e))n.get(a)===0&&s(a,[]);return o}function D(e,t,r){if(!e||typeof e!="object")return e;if(e.ref&&t.has(e.ref)){let n=r[e.ref];return{metadata:{description:n?B(e.ref,n):`Recursive reference to ${e.ref}.`}}}let i={...e};return i.properties&&(i.properties=Object.fromEntries(Object.entries(i.properties).map(([n,o])=>[n,D(o,t,r)]))),i.optionalProperties&&(i.optionalProperties=Object.fromEntries(Object.entries(i.optionalProperties).map(([n,o])=>[n,D(o,t,r)]))),i.elements&&(i.elements=D(i.elements,t,r)),i.values&&(i.values=D(i.values,t,r)),i.mapping&&(i.mapping=Object.fromEntries(Object.entries(i.mapping).map(([n,o])=>[n,D(o,t,r)]))),i}function G(e){let t=ie(e);if(t.size===0)return e;let r={};for(let[i,n]of Object.entries(e))t.has(i)?r[i]=D(n,t,e):r[i]=n;return r}function oe(e,t){e.description=e.description?`${e.description} ${t}`:t}var se=new Set(["title","label","name","description"]);function m(e,t){let r=t.metadata;if(!r)return;let i=[],n=typeof r.title=="string"&&r.title.trim()||typeof r.label=="string"&&r.label.trim()||typeof r.name=="string"&&r.name.trim(),o=typeof r.description=="string"?r.description.trim():"";n&&o?i.push(`${n}. ${o}`):n?i.push(n):o&&i.push(o);let s=[];for(let[a,c]of Object.entries(r))se.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 y(e,t,r){if(r>b)throw new Error(`Schema nesting exceeded ${b} levels`);if(!e||typeof e!="object")return{type:"string",description:w};if(v(e)){let n={type:d("string",e.nullable===!0),description:w};return m(n,e),n}let i=e.nullable===!0;if(e.ref){let n=e.ref;if(!t?.[n])throw new Error(`Unresolved ref "${n}"`);if(i){let o={anyOf:[{$ref:`#/$defs/${n}`},{type:"null"}]};return m(o,e),o}return{$ref:`#/$defs/${n}`}}if(e.type){let n={},o,s=R[e.type];if(s)n.type=d("integer",i),o=`Value range: [${s.minimum}, ${s.maximum}].`;else switch(e.type){case"boolean":n.type=d("boolean",i);break;case"string":n.type=d("string",i);break;case"timestamp":n.type=d("string",i),n.format="date-time";break;case"float32":n.type=d("number",i),o=`Value range: [${A.minimum}, ${A.maximum}].`;break;case"float64":n.type=d("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return m(n,e),o&&oe(n,o),n}if(e.enum){let n={type:d("string",i),enum:i?[...e.enum,null]:e.enum};return m(n,e),n}if(e.elements){let n={type:d("array",i),items:y(e.elements,t,r+1)};return m(n,e),n}if(e.properties||e.optionalProperties){let n={},o=[];if(e.properties)for(let[a,c]of Object.entries(e.properties))n[a]=y(c,t,r+1),o.push(a);if(e.optionalProperties)for(let[a,c]of Object.entries(e.optionalProperties))n[a]=y(c,t,r+1);let s={type:d("object",i),properties:n,additionalProperties:!1};return o.length>0&&(s.required=o),m(s,e),s}if(e.values){let n=y(e.values,t,r+1),o={type:d("array",i),description:U,items:{type:"object",properties:{key:{type:"string",description:"The property name."},value:n},required:["key","value"],additionalProperties:!1}};return m(o,e),o}if(e.discriminator&&e.mapping){let n=e.discriminator,o=e.mapping,s=[];for(let[c,u]of Object.entries(o)){let p;v(u)?p={type:"object",properties:{[n]:{const:c},_data:{type:"string",description:I}},required:[n,"_data"],additionalProperties:!1}:(p=y(u,t,r+1),p.properties[n]={const:c},(p.required??=[]).unshift(n),p.additionalProperties=!1),m(p,u),s.push(p)}i&&s.push({type:"null"});let a={anyOf:s};return m(a,e),a}return{type:"string",description:w}}var ae=new Set(Object.keys(R));function g(e,t,r,i){if(i>b||e==null)return e;if(t.ref){let n=r?.[t.ref];return n?g(e,n,r,i+1):e}if(v(t)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(t.type&&ae.has(t.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(t.elements&&Array.isArray(e)){let n=t.elements;return e.map(o=>g(o,n,r,i+1))}if((t.properties||t.optionalProperties)&&typeof e=="object"&&e!==null){let n={...e};if(t.properties)for(let[o,s]of Object.entries(t.properties))o in n&&(n[o]=g(n[o],s,r,i+1));if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))o in n&&(n[o]=g(n[o],s,r,i+1));return n}if(t.values&&Array.isArray(e)){let n={};for(let o of e)if(typeof o=="object"&&o!==null){let s=o,a=s.key;n[a]=g(s.value,t.values,r,i+1)}return n}if(t.discriminator&&t.mapping&&typeof e=="object"&&e!==null){let n=e,o=t.discriminator,s=n[o];if(typeof s!="string")return e;let a=t.mapping[s];if(!a)return e;if(v(a)){let u=n._data;if(typeof u=="string")try{let p=JSON.parse(u);if(typeof p=="object"&&p!==null)return{[o]:s,...p}}catch{}return{[o]:s}}let c={[o]:s};if(a.properties)for(let[u,p]of Object.entries(a.properties))u in n&&(c[u]=g(n[u],p,r,i+1));if(a.optionalProperties)for(let[u,p]of Object.entries(a.optionalProperties))u in n&&(c[u]=g(n[u],p,r,i+1));return c}return e}function ce(e){return{type:"object",description:`Binary content (MIME type: ${e}).`,properties:{data:{type:"string",description:`The base64-encoded binary content (MIME type: ${e}).`},filename:{type:"string",description:'Optional filename for the binary content (e.g. "report.pdf", "image.png").'}},required:["data"],additionalProperties:!1}}var k=class e{schema;strict;jtdSchema;descriptor;descriptors;static fromJTD(t){let r=t.definitions,i=r&&Object.keys(r).length>0?G(r):r,n=!x(t,i),o;return n?(o=y(t,i,0),i&&Object.keys(i).length>0&&(o.$defs=Object.fromEntries(Object.entries(i).map(([s,a])=>[s,y(a,i,0)])))):(o={},m(o,t)),new e(o,n,t,void 0)}static fromSignal(t,r){let{schema:i,strict:n}=pe(t,r);return new e(i,n,void 0,t)}static fromSignals(t,r,i){let{mergedDefs:n,signalsCopy:o}=q(t),s={},a=[],c=!0;for(let p of o){if(!p.name)continue;let f=e.fromSignal(p,n);f.strict||(c=!1),s[p.name]=f.schema,p.optional||a.push(p.name)}let u={type:"object",properties:s,required:a.length>0?a:void 0,additionalProperties:!1};return Object.keys(n).length>0&&(u.$defs=Object.fromEntries(Object.entries(n).map(([p,f])=>[p,y(f,n,0)]))),i&&r?u.description=`${i}. ${r}`:i?u.description=i:r&&(u.description=r),new e(u,c,void 0,void 0,t)}static fromJSON(t){let r=typeof t=="string"?JSON.parse(t):t;if(r.descriptors)return e.fromSignals(r.descriptors,r.description,r.label);if(r.descriptor)return e.fromSignal(r.descriptor);if(r.jtdSchema)return e.fromJTD(r.jtdSchema);throw new Error("Cannot deserialize: missing jtdSchema, descriptor, or descriptors")}constructor(t,r,i,n,o){this.schema=t,this.strict=r,this.jtdSchema=i,this.descriptor=n,this.descriptors=o}convert=t=>this.descriptors?_(this.descriptors,t,g):this.jtdSchema?C(this.jtdSchema,t,g):this.descriptor?E(this.descriptor,t,g):{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),t}return this.descriptor?{schema:this.schema,strict:this.strict,descriptor:this.descriptor}:{schema:this.schema,strict:this.strict,jtdSchema:this.jtdSchema}}};function pe(e,t){let r=e.formats;if(!r||r.length===0)throw new Error("Signal descriptor has no formats");if(r.length===1){let[c]=r,{schema:u,strict:p}=V(c,t);if(e.label||e.description){let f=[];e.label&&f.push(e.label),e.description&&f.push(e.description);let l=f.join(". ");u.description=u.description?`${l} ${u.description}`:l}return{schema:u,strict:p}}let i={};for(let[c,u]of r.entries()){let{schema:p}=V(u,t);u.jtdSchema&&(p.description=p.description?`Structured JSON data. ${p.description}`:"Structured JSON data."),i[`format_${c}`]=p}let n=Object.keys(i),o=e.description??"",s=e.optional?"Provide at most ONE of the following format properties. All are optional.":`You MUST provide exactly ONE of the following format properties: ${n.join(", ")}.`;return{schema:{type:"object",description:o?`${o} ${s}`:s,properties:i,additionalProperties:!1},strict:!0}}function V(e,t){if(e.jtdSchema){let r=t??e.jtdSchema.definitions,i=r&&Object.keys(r).length>0?G(r):r,n=!x(e.jtdSchema,i),o;return n?(o=y(e.jtdSchema,i,0),!t&&i&&Object.keys(i).length>0&&(o.$defs=Object.fromEntries(Object.entries(i).map(([s,a])=>[s,y(a,i,0)])))):(o={},m(o,e.jtdSchema)),{schema:o,strict:n}}if(e.mimeType)return{schema:ce(e.mimeType),strict:!0};throw new Error("Signal format has neither jtdSchema nor mimeType")}function ue(e){return k.fromJTD(e)}function fe(e){return k.fromSignal(e)}0&&(module.exports={AnthropicConversion,convertSignalToAnthropicSchema,convertToAnthropicSchema});
|
|
1
|
+
"use strict";var R=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},z=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of K(t))!W.call(e,r)&&r!==n&&R(e,r,{get:()=>t[r],enumerable:!(i=H(t,r))||i.enumerable});return e};var X=e=>z(R({},"__esModule",{value:!0}),e);var me={};Y(me,{AnthropicConversion:()=>k,convertSignalToAnthropicSchema:()=>de,convertToAnthropicSchema:()=>le});module.exports=X(me);var D=require("jtd");var Z=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function Q(e){return e.length===0?"/":e.map(t=>/^\d+$/.test(t)?`[${t}]`:`.${t}`).join("")}function F(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 ee(e,t){let n=e;for(let i of t)if(n&&typeof n=="object")n=n[i];else return;return n}function te(e,t,n){let{instancePath:i,schemaPath:r}=e,o=Q(i),s=r[r.length-1];if(s==="type"){let c=F(t,r)?.type;return c==="boolean"?`${o}: expected boolean`:c==="string"?`${o}: expected string`:c==="timestamp"?`${o}: expected timestamp string`:Z.has(c)?`${o}: expected integer`:`${o}: expected number`}if(s==="enum"){let c=F(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=ee(n,i);return`${o}: unknown variant "${a}"`}return r.length===0?`${o}: unexpected property`:`${o}: validation error at /${r.join("/")}`}function M(e,t,n){let i=n??e.definitions,r=i?{...e,definitions:i}:e;return(0,D.isValidSchema)(r)?(0,D.validate)(r,t,{maxDepth:ne,maxErrors:re}).map(s=>te(s,r,t)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var ne=32,re=100;var b=32,$={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}},A={minimum:-34028235e31,maximum:34028235e31},O=`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'.`,I=`The variant data encoded as a valid JSON string (e.g. '{"key": "value"}').`,q="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 d(e,t){return t?[e,"null"]:e}function w(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)=>w(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)||!w(n[o],i[o]))return!1;return!0}function T(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 x(e,t){let n=e,i=0;for(;n.ref&&i<b;){let r=t?.[n.ref];if(!r)return!1;n=r,i++}return i>=b?!1:T(n)}function C(e,t,n){let i=e.definitions,r=n(t,e,i,0),o=M(e,r,i);return o.length>0?{success:!1,errors:o}:{success:!0,kind:"json",data:r}}function _(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 ie(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 oe(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(!ie(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 U(e,t,n){return e.mimeType?oe(e.mimeType,t):e.jtdSchema?C(e.jtdSchema,t,n):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function E(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 U(i[0],t,n);let r=[];for(let o of i){let s=U(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 V(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=E(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 h(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,h(r,t)]))),n.optionalProperties&&(n.optionalProperties=Object.fromEntries(Object.entries(n.optionalProperties).map(([i,r])=>[i,h(r,t)]))),n.elements&&(n.elements=h(n.elements,t)),n.values&&(n.values=h(n.values,t)),n.mapping&&(n.mapping=Object.fromEntries(Object.entries(n.mapping).map(([i,r])=>[i,h(r,t)]))),n.definitions&&delete n.definitions,n}function B(e){let t={},n=new Map;for(let r=0;r<e.length;r++){let o=e[r].formats;if(o)for(let s=0;s<o.length;s++){let a=o[s].jtdSchema?.definitions;if(!a||Object.keys(a).length===0)continue;let c=new Map,f=!1;for(let[p,u]of Object.entries(a)){let l=t[p];if(l&&!w(l,u)){f=!0;break}}if(f)for(let[p,u]of Object.entries(a)){let l=t[p];if(!(l&&w(l,u)))if(l){let m=1;for(;t[`${p}_${m}`];)m++;let N=`${p}_${m}`;c.set(p,N),t[N]=u}else t[p]=u}else for(let[p,u]of Object.entries(a))t[p]||(t[p]=u);c.size>0&&n.set(`${r}:${s}`,c)}}for(let[,r]of n)for(let[,o]of r)t[o]=h(t[o],r);let i=e.map((r,o)=>{let s=r.formats;if(!s)return r;let a=!1,c=s.map((f,p)=>{if(!f.jtdSchema)return f;let u=n.get(`${o}:${p}`),l=f.jtdSchema.definitions&&Object.keys(f.jtdSchema.definitions).length>0;if(!u&&!l)return f;a=!0;let m=u?h(f.jtdSchema,u):{...f.jtdSchema};return delete m.definitions,{...f,jtdSchema:m}});return a?{...r,formats:c}:r});return{mergedDefs:t,signalsCopy:i}}function J(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 ${J(e.elements)}`:e.values?`map of ${J(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function L(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} (${J(s)})`);if(t.optionalProperties)for(let[o,s]of Object.entries(t.optionalProperties))r.push(`${o} (${J(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 ${J(t.elements)}.`),t.values&&n.push(`Map with values of type ${J(t.values)}.`),n.join(" ")}function v(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(...v(n));if(e.optionalProperties)for(let n of Object.values(e.optionalProperties))t.push(...v(n));if(e.elements&&t.push(...v(e.elements)),e.values&&t.push(...v(e.values)),e.mapping)for(let n of Object.values(e.mapping))t.push(...v(n));return t}function se(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 v(f))if(r.has(p))if(r.get(p)===1){let u=c.indexOf(p);for(let l=u;l<c.length;l++)o.add(c[l])}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 j(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?L(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,j(o,t,n)]))),i.optionalProperties&&(i.optionalProperties=Object.fromEntries(Object.entries(i.optionalProperties).map(([r,o])=>[r,j(o,t,n)]))),i.elements&&(i.elements=j(i.elements,t,n)),i.values&&(i.values=j(i.values,t,n)),i.mapping&&(i.mapping=Object.fromEntries(Object.entries(i.mapping).map(([r,o])=>[r,j(o,t,n)]))),i}function P(e){let t=se(e);if(t.size===0)return e;let n={};for(let[i,r]of Object.entries(e))t.has(i)?n[i]=j(r,t,e):n[i]=r;return n}function ae(e,t){e.description=e.description?`${e.description} ${t}`:t}var ce=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))ce.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>b)throw new Error(`Schema nesting exceeded ${b} levels`);if(!e||typeof e!="object")return{type:"string",description:O};if(T(e)){let r={type:d("string",e.nullable===!0),description:O};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=$[e.type];if(s)r.type=d("integer",i),o=`Value range: [${s.minimum}, ${s.maximum}].`;else switch(e.type){case"boolean":r.type=d("boolean",i);break;case"string":r.type=d("string",i);break;case"timestamp":r.type=d("string",i),r.format="date-time";break;case"float32":r.type=d("number",i),o=`Value range: [${A.minimum}, ${A.maximum}].`;break;case"float64":r.type=d("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return g(r,e),o&&ae(r,o),r}if(e.enum){let r={type:d("string",i),enum:i?[...e.enum,null]:e.enum};return g(r,e),r}if(e.elements){let r={type:d("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:d("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:d("array",i),description:q,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;T(f)?p={type:"object",properties:{[r]:{const:c},_data:{type:"string",description:I}},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:O}}var pe=new Set(Object.keys($));function y(e,t,n,i){if(i>b||e==null)return e;if(t.ref){let r=n?.[t.ref];return r?y(e,r,n,i+1):e}if(T(t)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(t.type&&pe.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(T(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 fe(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"],additionalProperties:!1}}var k=class e{schema;strict;jtdSchema;descriptor;descriptors;referenceMode;static fromJTD(t){let n=t.definitions,i=n&&Object.keys(n).length>0?P(n):n,r=!x(t,i),o;return r?(o=S(t,i,0),i&&Object.keys(i).length>0&&(o.$defs=Object.fromEntries(Object.entries(i).map(([s,a])=>[s,S(a,i,0)])))):(o={},g(o,t)),new e(o,r,t,void 0)}static fromSignal(t,n,i){let{schema:r,strict:o}=ue(t,n);if(i){let s=_(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}=B(t),a=Object.keys(o).length>0?P(o):o,c={},f=[],p=!0;for(let l of s){if(!l.name)continue;let m=e.fromSignal(l,a,r);m.strict||(p=!1),c[l.name]=m.schema,l.optional||f.push(l.name)}let u={type:"object",properties:c,required:f.length>0?f:void 0,additionalProperties:!1};return Object.keys(a).length>0&&(u.$defs=Object.fromEntries(Object.entries(a).map(([l,m])=>[l,S(m,a,0)]))),i&&n?u.description=`${i}. ${n}`:i?u.description=i:n&&(u.description=n),new e(u,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?V(this.descriptors,t,y):this.jtdSchema?C(this.jtdSchema,t,y):this.descriptor?E(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 ue(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}=G(a,t);if(e.label||e.description){let p=[];e.label&&p.push(e.label),e.description&&p.push(e.description);let u=p.join(". ");c.description=c.description?`${u} ${c.description}`:u}return{schema:c,strict:f}}let i=[],r=!0;for(let a of n){let{schema:c,strict:f}=G(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 G(e,t){if(e.jtdSchema){let n=t??e.jtdSchema.definitions,i=n&&Object.keys(n).length>0?P(n):n,r=!x(e.jtdSchema,i),o;return r?(o=S(e.jtdSchema,i,0),!t&&i&&Object.keys(i).length>0&&(o.$defs=Object.fromEntries(Object.entries(i).map(([s,a])=>[s,S(a,i,0)])))):(o={},g(o,e.jtdSchema)),{schema:o,strict:r}}if(e.mimeType)return{schema:fe(e.mimeType),strict:!0};throw new Error("Signal format has neither jtdSchema nor mimeType")}function le(e){return k.fromJTD(e)}function de(e){return k.fromSignal(e)}0&&(module.exports={AnthropicConversion,convertSignalToAnthropicSchema,convertToAnthropicSchema});
|
|
2
2
|
//# sourceMappingURL=anthropic.cjs.map
|