@mochabug/adapt-sdk 0.4.10 → 0.4.12
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 +2 -2
package/dist/cjs/gemini.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var Y=(e,n)=>{for(var r in n)x(e,r,{get:n[r],enumerable:!0})},z=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of K(n))!L.call(e,i)&&i!==r&&x(e,i,{get:()=>n[i],enumerable:!(s=V(n,i))||s.enumerable});return e};var H=e=>z(x({},"__esModule",{value:!0}),e);var pe={};Y(pe,{GeminiConversion:()=>k,GeminiFunctionCallingConversion:()=>$,GeminiStructuredOutputConversion:()=>k,convertSignalToGeminiSchema:()=>ce,convertToGeminiFCSchema:()=>ue,convertToGeminiSchema:()=>ae});module.exports=H(pe);var T=require("jtd");var X=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function Z(e){return e.length===0?"/":e.map(n=>/^\d+$/.test(n)?`[${n}]`:`.${n}`).join("")}function N(e,n){let r=e;for(let s=0;s<n.length-1&&(r&&typeof r=="object"&&n[s]in r);s++)r=r[n[s]];return r}function W(e,n){let r=e;for(let s of n)if(r&&typeof r=="object")r=r[s];else return;return r}function Q(e,n,r){let{instancePath:s,schemaPath:i}=e,t=Z(s),o=i[i.length-1];if(o==="type"){let a=N(n,i)?.type;return a==="boolean"?`${t}: expected boolean`:a==="string"?`${t}: expected string`:a==="timestamp"?`${t}: expected timestamp string`:X.has(a)?`${t}: expected integer`:`${t}: expected number`}if(o==="enum"){let a=N(n,i)?.enum;return`${t}: expected one of [${a.join(", ")}]`}if(i.length>=2&&i[i.length-2]==="properties"&&o)return`${t==="/"?"":t}.${o}: missing required property`;if(o==="elements")return`${t}: expected array`;if(o==="properties"||o==="optionalProperties"||o==="values")return`${t}: expected object`;if(o==="discriminator")return`${t}: expected string discriminator`;if(o==="mapping"){let c=W(r,s);return`${t}: unknown variant "${c}"`}return i.length===0?`${t}: unexpected property`:`${t}: validation error at /${i.join("/")}`}function A(e,n,r){let s=r??e.definitions,i=s?{...e,definitions:s}:e;return(0,T.isValidSchema)(i)?(0,T.validate)(i,n,{maxDepth:ee,maxErrors:ne}).map(o=>Q(o,i,n)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var ee=32,ne=100;var f=32,w={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}},D={minimum:-34028235e31,maximum:34028235e31},j=`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'.`;var M="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 l(e,n){return n?[e,"null"]:e}function R(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 I(e,n){let r=e,s=0;for(;r.ref&&s<f;){let i=n?.[r.ref];if(!i)return!1;r=i,s++}return s>=f?!1:R(r)}function C(e,n,r){let s=e.definitions,i=r(n,e,s,0),t=A(e,i,s);return t.length>0?{success:!1,errors:t}:{success:!0,kind:"json",data:i}}function te(e,n){if(typeof n!="object"||n===null)return{success:!1,errors:[`/: expected object with 'data' field for MIME type ${e}, got ${typeof n}`]};let r=n;if(typeof r.data!="string")return{success:!1,errors:[`/data: expected base64 string for MIME type ${e}, got ${typeof r.data}`]};let s={success:!0,kind:"binary",mimeType:e,data:new Uint8Array(Buffer.from(r.data,"base64"))};return typeof r.filename=="string"&&r.filename&&(s.filename=r.filename),s}function G(e,n,r){return e.mimeType?te(e.mimeType,n):e.jtdSchema?C(e.jtdSchema,n,r):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function O(e,n,r){let s=e.formats;if(!s||s.length===0)return{success:!1,errors:["Signal descriptor has no formats"]};if(s.length===1)return G(s[0],n,r);if(typeof n!="object"||n===null)return{success:!1,errors:[`/: expected object with format properties, got ${typeof n}`]};let i=n;for(let o=0;o<s.length;o++){let c=`format_${o}`;if(i[c]!==void 0&&i[c]!==null)return G(s[o],i[c],r)}if(e.optional)return{success:!0,kind:"json",data:null};let t=s.map((o,c)=>`format_${c}`);return{success:!1,errors:[`Signal '${e.name??"unnamed"}' is required but no format was provided. Set exactly one of: ${t.join(", ")}.`]}}function F(e,n,r){if(typeof n!="object"||n===null)return{success:!1,errors:["/: expected object with signal properties, got "+typeof n]};let s=n,i={},t=[];for(let o of e){if(!o.name)continue;let c=s[o.name];if(c==null)continue;let a=O(o,c,r);if(a.success)a.kind==="binary"?i[o.name]={data:a.data,mimeType:a.mimeType,filename:a.filename}:a.kind==="json"&&(i[o.name]=a.data);else for(let u of a.errors)t.push(`/${o.name}${u.startsWith("/")?"":": "}${u}`)}return t.length>0?{success:!1,errors:t}:{success:!0,kind:"signals",signals:i}}function h(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 ${h(e.elements)}`:e.values?`map of ${h(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function E(e,n){let r=["Recursive nesting. This field accepts the same object structure as its parent with the following shape:"],s=[],i=[];if(n.properties)for(let[t,o]of Object.entries(n.properties))s.push(`${t} (${h(o)})`);if(n.optionalProperties)for(let[t,o]of Object.entries(n.optionalProperties))i.push(`${t} (${h(o)})`);if(s.length>0&&r.push(`Required: ${s.join(", ")}.`),i.length>0){let t=i.slice(0,8),o=i.length>8?`, and ${i.length-8} more`:"";r.push(`Optional: ${t.join(", ")}${o}.`)}return n.elements&&r.push(`Array of ${h(n.elements)}.`),n.values&&r.push(`Map with values of type ${h(n.values)}.`),r.join(" ")}var B=new Set(["title","label","name","description"]);function g(e,n){let r=n.metadata;if(!r)return;typeof r.description=="string"&&r.description.trim()&&(e.description=r.description.trim());let s=typeof r.title=="string"&&r.title.trim()||typeof r.label=="string"&&r.label.trim()||typeof r.name=="string"&&r.name.trim();s&&(e.title=s);let i=[];for(let[t,o]of Object.entries(r))B.has(t)||(typeof o=="string"&&o.trim()?i.push(`[${t}: ${o.trim()}]`):(typeof o=="number"||typeof o=="boolean")&&i.push(`[${t}: ${o}]`));if(i.length>0){let t=i.join(" ");e.description=e.description?`${e.description} ${t}`:t}}function P(e,n,r){if(r>f)throw new Error(`Circular or excessively deep ref chain (exceeded ${f} levels)`);if(!e.ref)return e;let s=n?.[e.ref];if(!s)throw new Error(`Unresolved ref "${e.ref}"`);return P(s,n,r+1)}function J(e,n,r,s){if(r>f)throw new Error(`Schema nesting exceeded ${f} levels`);if(!e||typeof e!="object")return{description:"Any JSON value"};if(e.ref){let o=s??new Set;if(o.has(e.ref)){let u=n?.[e.ref],p={description:u?E(e.ref,u):`Recursive reference to ${e.ref}. Accepts any valid JSON matching the ${e.ref} structure.`};return g(p,e),p}o.add(e.ref);let c=P(e,n,0),a=J(c,n,r+1,o);if(o.delete(e.ref),g(a,e),e.nullable){let u=a.type;a.type=Array.isArray(u)?[...u,"null"]:u?[u,"null"]:["null"]}return a}let i=e.nullable===!0,t={};if(e.type){let o=w[e.type];if(o)t.type=l("integer",i),t.minimum=o.minimum,t.maximum=o.maximum;else switch(e.type){case"boolean":t.type=l("boolean",i);break;case"string":t.type=l("string",i);break;case"timestamp":t.type=l("string",i),t.format="date-time";break;case"float32":t.type=l("number",i),t.minimum=D.minimum,t.maximum=D.maximum;break;case"float64":t.type=l("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return g(t,e),t}if(e.enum)return t.type=l("string",i),t.enum=i?[...e.enum,null]:e.enum,g(t,e),t;if(e.elements)return t.type=l("array",i),t.items=J(e.elements,n,r+1,s),g(t,e),t;if(e.properties||e.optionalProperties){t.type=l("object",i),t.properties={};let o=[];if(e.properties)for(let[c,a]of Object.entries(e.properties))t.properties[c]=J(a,n,r+1,s),o.push(c);if(e.optionalProperties)for(let[c,a]of Object.entries(e.optionalProperties))t.properties[c]=J(a,n,r+1,s);return o.length>0&&(t.required=o),e.additionalProperties!==!0&&(t.additionalProperties=!1),g(t,e),t}if(e.values)return t.type=l("object",i),t.additionalProperties=J(e.values,n,r+1,s),g(t,e),t;if(e.discriminator&&e.mapping){let o=e.discriminator,a=Object.keys(e.mapping).map(u=>{let p=e.mapping[u],d=J(p,n,r+1,s);return d.type="object",d.properties={[o]:{type:"string",enum:[u],description:`Must be '${u}'.`},...d.properties??{}},d.required=[o,...d.required??[]],d.additionalProperties=!1,d});if(i&&a.push({type:"null"}),a.length===1){let u=a[0];return g(u,e),u}return t.anyOf=a,g(t,e),t}return t.description="Any JSON value",g(t,e),t}function m(e,n){let r=n.metadata;if(!r)return;typeof r.description=="string"&&r.description.trim()&&(e.description=r.description.trim());let s=typeof r.title=="string"&&r.title.trim()||typeof r.label=="string"&&r.label.trim()||typeof r.name=="string"&&r.name.trim();s&&(e.title=s);let i=[];for(let[t,o]of Object.entries(r))B.has(t)||(typeof o=="string"&&o.trim()?i.push(`[${t}: ${o.trim()}]`):(typeof o=="number"||typeof o=="boolean")&&i.push(`[${t}: ${o}]`));if(i.length>0){let t=i.join(" ");e.description=e.description?`${e.description} ${t}`:t}}function b(e,n,r,s){if(r>f)throw new Error(`Schema nesting exceeded ${f} levels`);if(!e||typeof e!="object")return{type:"string",description:j};if(I(e,n)){let o={type:"string",description:j};return e.nullable&&(o.nullable=!0),m(o,e),o}if(e.ref){let o=s??new Set;if(o.has(e.ref)){let u=n?.[e.ref],p={description:u?E(e.ref,u):`Recursive reference to ${e.ref}. Accepts any valid JSON matching the ${e.ref} structure.`};return m(p,e),p}o.add(e.ref);let c=P(e,n,0),a=b(c,n,r+1,o);return o.delete(e.ref),m(a,e),e.nullable&&(a.nullable=!0),a}let i=e.nullable===!0,t={};if(e.type){let o=w[e.type];if(o)t.type="integer",t.minimum=o.minimum,t.maximum=o.maximum;else switch(e.type){case"boolean":t.type="boolean";break;case"string":t.type="string";break;case"timestamp":t.type="string",t.format="date-time";break;case"float32":t.type="number",t.minimum=D.minimum,t.maximum=D.maximum;break;case"float64":t.type="number";break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return i&&(t.nullable=!0),m(t,e),t}if(e.enum)return t.type="string",t.enum=[...e.enum],i&&(t.nullable=!0),m(t,e),t;if(e.elements)return t.type="array",t.items=b(e.elements,n,r+1,s),i&&(t.nullable=!0),m(t,e),t;if(e.properties||e.optionalProperties){t.type="object",t.properties={};let o=[];if(e.properties)for(let[c,a]of Object.entries(e.properties))t.properties[c]=b(a,n,r+1,s),o.push(c);if(e.optionalProperties)for(let[c,a]of Object.entries(e.optionalProperties))t.properties[c]=b(a,n,r+1,s);return o.length>0&&(t.required=o),i&&(t.nullable=!0),m(t,e),t}if(e.values){let o=b(e.values,n,r+1,s);return t.type="array",t.description=M,t.items={type:"object",properties:{key:{type:"string",description:"The property name."},value:o},required:["key","value"]},i&&(t.nullable=!0),m(t,e),t}if(e.discriminator&&e.mapping){let o=e.discriminator,c=e.mapping,a=[];for(let[p,d]of Object.entries(c)){let v=b(d,n,r+1,s);v.properties??={},v.properties[o]={type:"string",enum:[p]},(v.required??=[]).unshift(o),m(v,d),a.push(v)}i&&a.push({type:"string",nullable:!0});let u={anyOf:a};return m(u,e),u}return t.type="string",t.description=j,i&&(t.nullable=!0),m(t,e),t}var _=new Set(Object.keys(w));function S(e,n,r,s){if(s>f||e==null)return e;if(n.ref){let i=r?.[n.ref];return i?S(e,i,r,s+1):e}if(n.type&&_.has(n.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(n.elements&&Array.isArray(e)){let i=n.elements;return e.map(t=>S(t,i,r,s+1))}if((n.properties||n.optionalProperties)&&typeof e=="object"&&e!==null){let i={...e};if(n.properties)for(let[t,o]of Object.entries(n.properties))t in i&&(i[t]=S(i[t],o,r,s+1));if(n.optionalProperties)for(let[t,o]of Object.entries(n.optionalProperties))t in i&&(i[t]=S(i[t],o,r,s+1));return i}if(n.values&&typeof e=="object"&&e!==null){let i={};for(let[t,o]of Object.entries(e))i[t]=S(o,n.values,r,s+1);return i}if(n.discriminator&&n.mapping&&typeof e=="object"&&e!==null){let i=e,t=i[n.discriminator];if(typeof t!="string")return e;let o=n.mapping[t];if(!o)return e;let c=S(i,o,r,s+1);return c[n.discriminator]=t,c}return e}function y(e,n,r,s){if(s>f||e==null)return e;if(n.ref){let i=r?.[n.ref];return i?y(e,i,r,s+1):e}if(R(n)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(n.type&&_.has(n.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(n.elements&&Array.isArray(e)){let i=n.elements;return e.map(t=>y(t,i,r,s+1))}if((n.properties||n.optionalProperties)&&typeof e=="object"&&e!==null){let i={...e};if(n.properties)for(let[t,o]of Object.entries(n.properties))t in i&&(i[t]=y(i[t],o,r,s+1));if(n.optionalProperties)for(let[t,o]of Object.entries(n.optionalProperties))t in i&&(i[t]=y(i[t],o,r,s+1));return i}if(n.values&&Array.isArray(e)){let i={};for(let t of e)if(typeof t=="object"&&t!==null){let o=t,c=o.key;i[c]=y(o.value,n.values,r,s+1)}return i}if(n.discriminator&&n.mapping&&typeof e=="object"&&e!==null){let i=e,t=n.discriminator,o=i[t];if(typeof o!="string")return e;let c=n.mapping[o];if(!c)return e;let a={[t]:o};if(c.properties)for(let[u,p]of Object.entries(c.properties))u in i&&(a[u]=y(i[u],p,r,s+1));if(c.optionalProperties)for(let[u,p]of Object.entries(c.optionalProperties))u in i&&(a[u]=y(i[u],p,r,s+1));return a}return e}var k=class e{schema;jtdSchema;descriptor;descriptors;static fromJTD(n){let r=J(n,n.definitions,0);return new e(r,n,void 0)}static fromSignal(n){let r=re(n);return new e(r,void 0,n)}static fromSignals(n,r,s){let i={},t=[];for(let c of n){if(!c.name)continue;let a=e.fromSignal(c);i[c.name]=a.schema,c.optional||t.push(c.name)}let o={type:"object",properties:i,required:t.length>0?t:void 0,additionalProperties:!1};return r&&(o.description=r),s&&(o.title=s),new e(o,void 0,void 0,n)}static fromJSON(n){let r=typeof n=="string"?JSON.parse(n):n;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(n,r,s,i){this.schema=n,this.jtdSchema=r,this.descriptor=s,this.descriptors=i}convert=n=>this.descriptors?F(this.descriptors,n,S):this.jtdSchema?C(this.jtdSchema,n,S):this.descriptor?O(this.descriptor,n,S):{success:!1,errors:["No source schema available"]};toJSON(){if(this.descriptors){let n={schema:this.schema,descriptors:this.descriptors};return this.schema.description&&(n.description=this.schema.description),this.schema.title&&(n.label=this.schema.title),n}return this.descriptor?{schema:this.schema,descriptor:this.descriptor}:{schema:this.schema,jtdSchema:this.jtdSchema}}};function re(e){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[c]=n,a=U(c);return e.label&&(a.title=e.label),e.description&&(a.description=e.description),a}let r={};for(let[c,a]of n.entries()){let u=U(a);a.jtdSchema&&(u.description=u.description?`Structured JSON data. ${u.description}`:"Structured JSON data."),r[`format_${c}`]=u}let s=Object.keys(r),i=e.description??"",t=e.optional?"Provide at most ONE of the following format properties. All are optional.":`You MUST provide exactly ONE of the following format properties: ${s.join(", ")}.`,o={type:"object",description:i?`${i} ${t}`:t,properties:r,additionalProperties:!1};return e.label&&(o.title=e.label),o}function U(e){if(e.jtdSchema)return J(e.jtdSchema,e.jtdSchema.definitions,0);if(e.mimeType)return ie(e.mimeType);throw new Error("Signal format has neither jtdSchema nor mimeType")}function ie(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}}function oe(e){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[c]=n,a=q(c);return e.label&&(a.title=e.label),e.description&&(a.description=e.description),a}let r={};for(let[c,a]of n.entries()){let u=q(a);a.jtdSchema&&(u.description=u.description?`Structured JSON data. ${u.description}`:"Structured JSON data."),r[`format_${c}`]=u}let s=Object.keys(r),i=e.description??"",t=e.optional?"Provide at most ONE of the following format properties. All are optional.":`You MUST provide exactly ONE of the following format properties: ${s.join(", ")}.`,o={type:"object",description:i?`${i} ${t}`:t,properties:r};return e.label&&(o.title=e.label),o}function q(e){if(e.jtdSchema)return b(e.jtdSchema,e.jtdSchema.definitions,0);if(e.mimeType)return se(e.mimeType);throw new Error("Signal format has neither jtdSchema nor mimeType")}function se(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"]}}var $=class e{schema;jtdSchema;descriptor;descriptors;static fromJTD(n){let r=b(n,n.definitions,0);return new e(r,n,void 0)}static fromSignal(n){let r=oe(n);return new e(r,void 0,n)}static fromSignals(n,r,s){let i={},t=[];for(let c of n){if(!c.name)continue;let a=e.fromSignal(c);i[c.name]=a.schema,c.optional||t.push(c.name)}let o={type:"object",properties:i,required:t.length>0?t:void 0};return r&&(o.description=r),s&&(o.title=s),new e(o,void 0,void 0,n)}static fromJSON(n){let r=typeof n=="string"?JSON.parse(n):n;if(r.mode!=="fc")throw new Error('Cannot deserialize as GeminiFunctionCallingConversion: mode is not "fc"');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(n,r,s,i){this.schema=n,this.jtdSchema=r,this.descriptor=s,this.descriptors=i}convert=n=>this.descriptors?F(this.descriptors,n,y):this.jtdSchema?C(this.jtdSchema,n,y):this.descriptor?O(this.descriptor,n,y):{success:!1,errors:["No source schema available"]};toJSON(){if(this.descriptors){let n={mode:"fc",schema:this.schema,descriptors:this.descriptors};return this.schema.description&&(n.description=this.schema.description),this.schema.title&&(n.label=this.schema.title),n}return this.descriptor?{mode:"fc",schema:this.schema,descriptor:this.descriptor}:{mode:"fc",schema:this.schema,jtdSchema:this.jtdSchema}}};function ae(e){return k.fromJTD(e)}function ce(e){return k.fromSignal(e)}function ue(e){return $.fromJTD(e)}0&&(module.exports={GeminiConversion,GeminiFunctionCallingConversion,GeminiStructuredOutputConversion,convertSignalToGeminiSchema,convertToGeminiFCSchema,convertToGeminiSchema});
|
|
1
|
+
"use strict";var $=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var H=(e,n)=>{for(var t in n)$(e,t,{get:n[t],enumerable:!0})},X=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of K(n))!z.call(e,i)&&i!==t&&$(e,i,{get:()=>n[i],enumerable:!(s=L(n,i))||s.enumerable});return e};var Y=e=>X($({},"__esModule",{value:!0}),e);var le={};H(le,{GeminiConversion:()=>k,GeminiFunctionCallingConversion:()=>x,GeminiStructuredOutputConversion:()=>k,convertSignalToGeminiSchema:()=>fe,convertToGeminiFCSchema:()=>pe,convertToGeminiSchema:()=>ue});module.exports=Y(le);var v=require("jtd");var W=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function Z(e){return e.length===0?"/":e.map(n=>/^\d+$/.test(n)?`[${n}]`:`.${n}`).join("")}function G(e,n){let t=e;for(let s=0;s<n.length-1&&(t&&typeof t=="object"&&n[s]in t);s++)t=t[n[s]];return t}function Q(e,n){let t=e;for(let s of n)if(t&&typeof t=="object")t=t[s];else return;return t}function ee(e,n,t){let{instancePath:s,schemaPath:i}=e,r=Z(s),o=i[i.length-1];if(o==="type"){let a=G(n,i)?.type;return a==="boolean"?`${r}: expected boolean`:a==="string"?`${r}: expected string`:a==="timestamp"?`${r}: expected timestamp string`:W.has(a)?`${r}: expected integer`:`${r}: expected number`}if(o==="enum"){let a=G(n,i)?.enum;return`${r}: expected one of [${a.join(", ")}]`}if(i.length>=2&&i[i.length-2]==="properties"&&o)return`${r==="/"?"":r}.${o}: missing required property`;if(o==="elements")return`${r}: expected array`;if(o==="properties"||o==="optionalProperties"||o==="values")return`${r}: expected object`;if(o==="discriminator")return`${r}: expected string discriminator`;if(o==="mapping"){let c=Q(t,s);return`${r}: unknown variant "${c}"`}return i.length===0?`${r}: unexpected property`:`${r}: validation error at /${i.join("/")}`}function N(e,n,t){let s=t??e.definitions,i=s?{...e,definitions:s}:e;return(0,v.isValidSchema)(i)?(0,v.validate)(i,n,{maxDepth:ne,maxErrors:re}).map(o=>ee(o,i,n)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var ne=32,re=100;var p=32,j={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}},D={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'.`;var 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 l(e,n){return n?[e,"null"]:e}function R(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 q(e,n){let t=e,s=0;for(;t.ref&&s<p;){let i=n?.[t.ref];if(!i)return!1;t=i,s++}return s>=p?!1:R(t)}function C(e,n,t){let s=e.definitions,i=t(n,e,s,0),r=N(e,i,s);return r.length>0?{success:!1,errors:r}:{success:!0,kind:"json",data:i}}function F(e,n,t){let s=n?`${n}. `:"",i={type:"object",properties:{kind:{type:"string",enum:["value"]},data:e},required:["kind","data"],description:`${s}Inline value.`},r={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:`${s}Reference to a file instead of inline data.`};return t!==!1&&(i.additionalProperties=!1,r.additionalProperties=!1),{anyOf:[i,r]}}function te(e,n){let t=e.trim().toLowerCase(),s=n.trim().toLowerCase();return s==="*/*"?!0:s.endsWith("/*")?t.startsWith(s.slice(0,s.indexOf("/")+1)):t===s}function ie(e,n){if(typeof n!="object"||n===null)return{success:!1,errors:[`/: expected object with data and mimeType fields, got ${typeof n}`]};let t=n;if(typeof t.mimeType!="string"||!t.mimeType.includes("/"))return{success:!1,errors:['/mimeType: required concrete MIME type (e.g. "image/png", "application/pdf")']};if(!te(t.mimeType,e))return{success:!1,errors:[`/mimeType: "${t.mimeType}" does not match accepted type "${e}"`]};let s;if(t.data instanceof Uint8Array)s=t.data;else if(typeof t.data=="string")s=new Uint8Array(Buffer.from(t.data,"base64"));else return{success:!1,errors:[`/data: expected base64 string or Uint8Array, got ${typeof t.data}`]};let i={success:!0,kind:"binary",mimeType:t.mimeType,data:s};return typeof t.filename=="string"&&t.filename&&(i.filename=t.filename),i}function M(e,n,t){return e.mimeType?ie(e.mimeType,n):e.jtdSchema?C(e.jtdSchema,n,t):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function O(e,n,t){let s=e.formats;if(!s||s.length===0)return{success:!1,errors:["Signal descriptor has no formats"]};if(s.length===1)return M(s[0],n,t);let i=[];for(let r of s){let o=M(r,n,t);if(o.success)return o;i.push(...o.errors)}return{success:!1,errors:[`No format matched for signal '${e.name??"unnamed"}'. Errors: ${i.join("; ")}`]}}function E(e,n,t){if(typeof n!="object"||n===null)return{success:!1,errors:["/: expected object with signal properties, got "+typeof n]};let s=n,i={},r=[];for(let o of e){if(!o.name)continue;let c=s[o.name];if(c==null)continue;let a=O(o,c,t);if(a.success)a.kind==="binary"?i[o.name]={data:a.data,mimeType:a.mimeType,filename:a.filename}:a.kind==="json"&&(i[o.name]=a.data);else for(let u of a.errors)r.push(`/${o.name}${u.startsWith("/")?"":": "}${u}`)}return r.length>0?{success:!1,errors:r}:{success:!0,kind:"signals",signals:i}}function h(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 ${h(e.elements)}`:e.values?`map of ${h(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function A(e,n){let t=["Recursive nesting. This field accepts the same object structure as its parent with the following shape:"],s=[],i=[];if(n.properties)for(let[r,o]of Object.entries(n.properties))s.push(`${r} (${h(o)})`);if(n.optionalProperties)for(let[r,o]of Object.entries(n.optionalProperties))i.push(`${r} (${h(o)})`);if(s.length>0&&t.push(`Required: ${s.join(", ")}.`),i.length>0){let r=i.slice(0,8),o=i.length>8?`, and ${i.length-8} more`:"";t.push(`Optional: ${r.join(", ")}${o}.`)}return n.elements&&t.push(`Array of ${h(n.elements)}.`),n.values&&t.push(`Map with values of type ${h(n.values)}.`),t.join(" ")}var V=new Set(["title","label","name","description"]);function g(e,n){let t=n.metadata;if(!t)return;typeof t.description=="string"&&t.description.trim()&&(e.description=t.description.trim());let s=typeof t.title=="string"&&t.title.trim()||typeof t.label=="string"&&t.label.trim()||typeof t.name=="string"&&t.name.trim();s&&(e.title=s);let i=[];for(let[r,o]of Object.entries(t))V.has(r)||(typeof o=="string"&&o.trim()?i.push(`[${r}: ${o.trim()}]`):(typeof o=="number"||typeof o=="boolean")&&i.push(`[${r}: ${o}]`));if(i.length>0){let r=i.join(" ");e.description=e.description?`${e.description} ${r}`:r}}function P(e,n,t){if(t>p)throw new Error(`Circular or excessively deep ref chain (exceeded ${p} levels)`);if(!e.ref)return e;let s=n?.[e.ref];if(!s)throw new Error(`Unresolved ref "${e.ref}"`);return P(s,n,t+1)}function b(e,n,t,s){if(t>p)throw new Error(`Schema nesting exceeded ${p} levels`);if(!e||typeof e!="object")return{description:"Any JSON value"};if(e.ref){let o=s??new Set;if(o.has(e.ref)){let u=n?.[e.ref],f={description:u?A(e.ref,u):`Recursive reference to ${e.ref}. Accepts any valid JSON matching the ${e.ref} structure.`};return g(f,e),f}o.add(e.ref);let c=P(e,n,0),a=b(c,n,t+1,o);if(o.delete(e.ref),g(a,e),e.nullable){let u=a.type;a.type=Array.isArray(u)?[...u,"null"]:u?[u,"null"]:["null"]}return a}let i=e.nullable===!0,r={};if(e.type){let o=j[e.type];if(o)r.type=l("integer",i),r.minimum=o.minimum,r.maximum=o.maximum;else switch(e.type){case"boolean":r.type=l("boolean",i);break;case"string":r.type=l("string",i);break;case"timestamp":r.type=l("string",i),r.format="date-time";break;case"float32":r.type=l("number",i),r.minimum=D.minimum,r.maximum=D.maximum;break;case"float64":r.type=l("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return g(r,e),r}if(e.enum)return r.type=l("string",i),r.enum=i?[...e.enum,null]:e.enum,g(r,e),r;if(e.elements)return r.type=l("array",i),r.items=b(e.elements,n,t+1,s),g(r,e),r;if(e.properties||e.optionalProperties){r.type=l("object",i),r.properties={};let o=[];if(e.properties)for(let[c,a]of Object.entries(e.properties))r.properties[c]=b(a,n,t+1,s),o.push(c);if(e.optionalProperties)for(let[c,a]of Object.entries(e.optionalProperties))r.properties[c]=b(a,n,t+1,s);return o.length>0&&(r.required=o),e.additionalProperties!==!0&&(r.additionalProperties=!1),g(r,e),r}if(e.values)return r.type=l("object",i),r.additionalProperties=b(e.values,n,t+1,s),g(r,e),r;if(e.discriminator&&e.mapping){let o=e.discriminator,a=Object.keys(e.mapping).map(u=>{let f=e.mapping[u],d=b(f,n,t+1,s);return d.type="object",d.properties={[o]:{type:"string",enum:[u],description:`Must be '${u}'.`},...d.properties??{}},d.required=[o,...d.required??[]],d.additionalProperties=!1,d});if(i&&a.push({type:"null"}),a.length===1){let u=a[0];return g(u,e),u}return r.anyOf=a,g(r,e),r}return r.description="Any JSON value",g(r,e),r}function m(e,n){let t=n.metadata;if(!t)return;typeof t.description=="string"&&t.description.trim()&&(e.description=t.description.trim());let s=typeof t.title=="string"&&t.title.trim()||typeof t.label=="string"&&t.label.trim()||typeof t.name=="string"&&t.name.trim();s&&(e.title=s);let i=[];for(let[r,o]of Object.entries(t))V.has(r)||(typeof o=="string"&&o.trim()?i.push(`[${r}: ${o.trim()}]`):(typeof o=="number"||typeof o=="boolean")&&i.push(`[${r}: ${o}]`));if(i.length>0){let r=i.join(" ");e.description=e.description?`${e.description} ${r}`:r}}function J(e,n,t,s){if(t>p)throw new Error(`Schema nesting exceeded ${p} levels`);if(!e||typeof e!="object")return{type:"string",description:w};if(q(e,n)){let o={type:"string",description:w};return e.nullable&&(o.nullable=!0),m(o,e),o}if(e.ref){let o=s??new Set;if(o.has(e.ref)){let u=n?.[e.ref],f={description:u?A(e.ref,u):`Recursive reference to ${e.ref}. Accepts any valid JSON matching the ${e.ref} structure.`};return m(f,e),f}o.add(e.ref);let c=P(e,n,0),a=J(c,n,t+1,o);return o.delete(e.ref),m(a,e),e.nullable&&(a.nullable=!0),a}let i=e.nullable===!0,r={};if(e.type){let o=j[e.type];if(o)r.type="integer",r.minimum=o.minimum,r.maximum=o.maximum;else switch(e.type){case"boolean":r.type="boolean";break;case"string":r.type="string";break;case"timestamp":r.type="string",r.format="date-time";break;case"float32":r.type="number",r.minimum=D.minimum,r.maximum=D.maximum;break;case"float64":r.type="number";break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return i&&(r.nullable=!0),m(r,e),r}if(e.enum)return r.type="string",r.enum=[...e.enum],i&&(r.nullable=!0),m(r,e),r;if(e.elements)return r.type="array",r.items=J(e.elements,n,t+1,s),i&&(r.nullable=!0),m(r,e),r;if(e.properties||e.optionalProperties){r.type="object",r.properties={};let o=[];if(e.properties)for(let[c,a]of Object.entries(e.properties))r.properties[c]=J(a,n,t+1,s),o.push(c);if(e.optionalProperties)for(let[c,a]of Object.entries(e.optionalProperties))r.properties[c]=J(a,n,t+1,s);return o.length>0&&(r.required=o),i&&(r.nullable=!0),m(r,e),r}if(e.values){let o=J(e.values,n,t+1,s);return r.type="array",r.description=U,r.items={type:"object",properties:{key:{type:"string",description:"The property name."},value:o},required:["key","value"]},i&&(r.nullable=!0),m(r,e),r}if(e.discriminator&&e.mapping){let o=e.discriminator,c=e.mapping,a=[];for(let[f,d]of Object.entries(c)){let T=J(d,n,t+1,s);T.properties??={},T.properties[o]={type:"string",enum:[f]},(T.required??=[]).unshift(o),m(T,d),a.push(T)}i&&a.push({type:"string",nullable:!0});let u={anyOf:a};return m(u,e),u}return r.type="string",r.description=w,i&&(r.nullable=!0),m(r,e),r}var _=new Set(Object.keys(j));function S(e,n,t,s){if(s>p||e==null)return e;if(n.ref){let i=t?.[n.ref];return i?S(e,i,t,s+1):e}if(n.type&&_.has(n.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(n.elements&&Array.isArray(e)){let i=n.elements;return e.map(r=>S(r,i,t,s+1))}if((n.properties||n.optionalProperties)&&typeof e=="object"&&e!==null){let i={...e};if(n.properties)for(let[r,o]of Object.entries(n.properties))r in i&&(i[r]=S(i[r],o,t,s+1));if(n.optionalProperties)for(let[r,o]of Object.entries(n.optionalProperties))r in i&&(i[r]=S(i[r],o,t,s+1));return i}if(n.values&&typeof e=="object"&&e!==null){let i={};for(let[r,o]of Object.entries(e))i[r]=S(o,n.values,t,s+1);return i}if(n.discriminator&&n.mapping&&typeof e=="object"&&e!==null){let i=e,r=i[n.discriminator];if(typeof r!="string")return e;let o=n.mapping[r];if(!o)return e;let c=S(i,o,t,s+1);return c[n.discriminator]=r,c}return e}function y(e,n,t,s){if(s>p||e==null)return e;if(n.ref){let i=t?.[n.ref];return i?y(e,i,t,s+1):e}if(R(n)){if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}if(n.type&&_.has(n.type))return typeof e=="number"&&!Number.isInteger(e)?Math.round(e):e;if(n.elements&&Array.isArray(e)){let i=n.elements;return e.map(r=>y(r,i,t,s+1))}if((n.properties||n.optionalProperties)&&typeof e=="object"&&e!==null){let i={...e};if(n.properties)for(let[r,o]of Object.entries(n.properties))r in i&&(i[r]=y(i[r],o,t,s+1));if(n.optionalProperties)for(let[r,o]of Object.entries(n.optionalProperties))r in i&&(i[r]=y(i[r],o,t,s+1));return i}if(n.values&&Array.isArray(e)){let i={};for(let r of e)if(typeof r=="object"&&r!==null){let o=r,c=o.key;i[c]=y(o.value,n.values,t,s+1)}return i}if(n.discriminator&&n.mapping&&typeof e=="object"&&e!==null){let i=e,r=n.discriminator,o=i[r];if(typeof o!="string")return e;let c=n.mapping[o];if(!c)return e;let a={[r]:o};if(c.properties)for(let[u,f]of Object.entries(c.properties))u in i&&(a[u]=y(i[u],f,t,s+1));if(c.optionalProperties)for(let[u,f]of Object.entries(c.optionalProperties))u in i&&(a[u]=y(i[u],f,t,s+1));return a}return e}var k=class e{schema;jtdSchema;descriptor;descriptors;referenceMode;static fromJTD(n){let t=b(n,n.definitions,0);return new e(t,n,void 0)}static fromSignal(n,t){let s=oe(n);if(t){let i=F(s,n.description);return new e(i,void 0,n)}return new e(s,void 0,n)}static fromSignals(n,t,s,i){let r={},o=[];for(let a of n){if(!a.name)continue;let u=e.fromSignal(a,i);r[a.name]=u.schema,a.optional||o.push(a.name)}let c={type:"object",properties:r,required:o.length>0?o:void 0,additionalProperties:!1};return t&&(c.description=t),s&&(c.title=s),new e(c,void 0,void 0,n,i)}static fromJSON(n){let t=typeof n=="string"?JSON.parse(n):n;if(t.descriptors)return e.fromSignals(t.descriptors,t.description,t.label,t.referenceMode);if(t.descriptor)return e.fromSignal(t.descriptor);if(t.jtdSchema)return e.fromJTD(t.jtdSchema);throw new Error("Cannot deserialize: missing jtdSchema, descriptor, or descriptors")}constructor(n,t,s,i,r){this.schema=n,this.jtdSchema=t,this.descriptor=s,this.descriptors=i,this.referenceMode=r??!1}convert=n=>this.descriptors?E(this.descriptors,n,S):this.jtdSchema?C(this.jtdSchema,n,S):this.descriptor?O(this.descriptor,n,S):{success:!1,errors:["No source schema available"]};toJSON(){if(this.descriptors){let n={schema:this.schema,descriptors:this.descriptors};return this.schema.description&&(n.description=this.schema.description),this.schema.title&&(n.label=this.schema.title),this.referenceMode&&(n.referenceMode=!0),n}return this.descriptor?{schema:this.schema,descriptor:this.descriptor}:{schema:this.schema,jtdSchema:this.jtdSchema}}};function oe(e){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[r]=n,o=I(r);return e.label&&(o.title=e.label),e.description&&(o.description=e.description),o}let t=[];for(let r of n){let o=I(r);r.jtdSchema&&(o.description=o.description?`Structured JSON data. ${o.description}`:"Structured JSON data."),t.push(o)}let s=e.description??"";return{anyOf:t,description:s||void 0}}function I(e){if(e.jtdSchema)return b(e.jtdSchema,e.jtdSchema.definitions,0);if(e.mimeType)return se(e.mimeType);throw new Error("Signal format has neither jtdSchema nor mimeType")}function se(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}}function ae(e){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[r]=n,o=B(r);return e.label&&(o.title=e.label),e.description&&(o.description=e.description),o}let t=[];for(let r of n){let o=B(r);r.jtdSchema&&(o.description=o.description?`Structured JSON data. ${o.description}`:"Structured JSON data."),t.push(o)}let s=e.description??"";return{anyOf:t,description:s||void 0}}function B(e){if(e.jtdSchema)return J(e.jtdSchema,e.jtdSchema.definitions,0);if(e.mimeType)return ce(e.mimeType);throw new Error("Signal format has neither jtdSchema nor mimeType")}function ce(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"]}}var x=class e{schema;jtdSchema;descriptor;descriptors;referenceMode;static fromJTD(n){let t=J(n,n.definitions,0);return new e(t,n,void 0)}static fromSignal(n,t){let s=ae(n);if(t){let i=F(s,n.description,!1);return new e(i,void 0,n)}return new e(s,void 0,n)}static fromSignals(n,t,s,i){let r={},o=[];for(let a of n){if(!a.name)continue;let u=e.fromSignal(a,i);r[a.name]=u.schema,a.optional||o.push(a.name)}let c={type:"object",properties:r,required:o.length>0?o:void 0};return t&&(c.description=t),s&&(c.title=s),new e(c,void 0,void 0,n,i)}static fromJSON(n){let t=typeof n=="string"?JSON.parse(n):n;if(t.mode!=="fc")throw new Error('Cannot deserialize as GeminiFunctionCallingConversion: mode is not "fc"');if(t.descriptors)return e.fromSignals(t.descriptors,t.description,t.label,t.referenceMode);if(t.descriptor)return e.fromSignal(t.descriptor);if(t.jtdSchema)return e.fromJTD(t.jtdSchema);throw new Error("Cannot deserialize: missing jtdSchema, descriptor, or descriptors")}constructor(n,t,s,i,r){this.schema=n,this.jtdSchema=t,this.descriptor=s,this.descriptors=i,this.referenceMode=r??!1}convert=n=>this.descriptors?E(this.descriptors,n,y):this.jtdSchema?C(this.jtdSchema,n,y):this.descriptor?O(this.descriptor,n,y):{success:!1,errors:["No source schema available"]};toJSON(){if(this.descriptors){let n={mode:"fc",schema:this.schema,descriptors:this.descriptors};return this.schema.description&&(n.description=this.schema.description),this.schema.title&&(n.label=this.schema.title),this.referenceMode&&(n.referenceMode=!0),n}return this.descriptor?{mode:"fc",schema:this.schema,descriptor:this.descriptor}:{mode:"fc",schema:this.schema,jtdSchema:this.jtdSchema}}};function ue(e){return k.fromJTD(e)}function fe(e){return k.fromSignal(e)}function pe(e){return x.fromJTD(e)}0&&(module.exports={GeminiConversion,GeminiFunctionCallingConversion,GeminiStructuredOutputConversion,convertSignalToGeminiSchema,convertToGeminiFCSchema,convertToGeminiSchema});
|
|
2
2
|
//# sourceMappingURL=gemini.cjs.map
|