@mochabug/adapt-sdk 0.4.7 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var b=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var A=(e,n)=>{for(var r in n)b(e,r,{get:n[r],enumerable:!0})},N=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of P(n))!E.call(e,i)&&i!==r&&b(e,i,{get:()=>n[i],enumerable:!(s=C(n,i))||s.enumerable});return e};var F=e=>N(b({},"__esModule",{value:!0}),e);var z={};A(z,{GeminiConversion:()=>J,convertSignalToGeminiSchema:()=>X,convertToGeminiSchema:()=>K});module.exports=F(z);var S=require("jtd");var G=new Set(["int8","uint8","int16","uint16","int32","uint32"]);function M(e){return e.length===0?"/":e.map(n=>/^\d+$/.test(n)?`[${n}]`:`.${n}`).join("")}function w(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 I(e,n){let r=e;for(let s of n)if(r&&typeof r=="object")r=r[s];else return;return r}function U(e,n,r){let{instancePath:s,schemaPath:i}=e,t=M(s),o=i[i.length-1];if(o==="type"){let c=w(n,i)?.type;return c==="boolean"?`${t}: expected boolean`:c==="string"?`${t}: expected string`:c==="timestamp"?`${t}: expected timestamp string`:G.has(c)?`${t}: expected integer`:`${t}: expected number`}if(o==="enum"){let c=w(n,i)?.enum;return`${t}: expected one of [${c.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 a=I(r,s);return`${t}: unknown variant "${a}"`}return i.length===0?`${t}: unexpected property`:`${t}: validation error at /${i.join("/")}`}function k(e,n,r){let s=r??e.definitions,i=s?{...e,definitions:s}:e;return(0,S.isValidSchema)(i)?(0,S.validate)(i,n,{maxDepth:q,maxErrors:_}).map(o=>U(o,i,n)):e.ref?[`/: unknown ref "${e.ref}"`]:["/: invalid schema"]}var q=32,_=100;var g=32,v={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}},h={minimum:-34028235e31,maximum:34028235e31};function p(e,n){return n?[e,"null"]:e}function T(e,n,r){let s=e.definitions,i=r(n,e,s,0),t=k(e,i,s);return t.length>0?{success:!1,errors:t}:{success:!0,kind:"json",data:i}}function B(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 j(e,n,r){return e.mimeType?B(e.mimeType,n):e.jtdSchema?T(e.jtdSchema,n,r):{success:!1,errors:["Signal format has neither jtdSchema nor mimeType"]}}function D(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 j(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 a=`format_${o}`;if(i[a]!==void 0&&i[a]!==null)return j(s[o],i[a],r)}if(e.optional)return{success:!0,kind:"json",data:null};let t=s.map((o,a)=>`format_${a}`);return{success:!1,errors:[`Signal '${e.name??"unnamed"}' is required but no format was provided. Set exactly one of: ${t.join(", ")}.`]}}function $(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 a=s[o.name];if(a==null)continue;let c=D(o,a,r);if(c.success)c.kind==="binary"?i[o.name]={data:c.data,mimeType:c.mimeType,filename:c.filename}:c.kind==="json"&&(i[o.name]=c.data);else for(let u of c.errors)t.push(`/${o.name}${u.startsWith("/")?"":": "}${u}`)}return t.length>0?{success:!1,errors:t}:{success:!0,kind:"signals",signals:i}}function m(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 ${m(e.elements)}`:e.values?`map of ${m(e.values)}`:e.properties||e.optionalProperties?"object":e.discriminator?`union on '${e.discriminator}'`:"any"}function x(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} (${m(o)})`);if(n.optionalProperties)for(let[t,o]of Object.entries(n.optionalProperties))i.push(`${t} (${m(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 ${m(n.elements)}.`),n.values&&r.push(`Map with values of type ${m(n.values)}.`),r.join(" ")}var V=new Set(["title","label","name","description"]);function f(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))V.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 R(e,n,r){if(r>g)throw new Error(`Circular or excessively deep ref chain (exceeded ${g} levels)`);if(!e.ref)return e;let s=n?.[e.ref];if(!s)throw new Error(`Unresolved ref "${e.ref}"`);return R(s,n,r+1)}function d(e,n,r,s){if(r>g)throw new Error(`Schema nesting exceeded ${g} 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],y={description:u?x(e.ref,u):`Recursive reference to ${e.ref}. Accepts any valid JSON matching the ${e.ref} structure.`};return f(y,e),y}o.add(e.ref);let a=R(e,n,0),c=d(a,n,r+1,o);if(o.delete(e.ref),f(c,e),e.nullable){let u=c.type;c.type=Array.isArray(u)?[...u,"null"]:u?[u,"null"]:["null"]}return c}let i=e.nullable===!0,t={};if(e.type){let o=v[e.type];if(o)t.type=p("integer",i),t.minimum=o.minimum,t.maximum=o.maximum;else switch(e.type){case"boolean":t.type=p("boolean",i);break;case"string":t.type=p("string",i);break;case"timestamp":t.type=p("string",i),t.format="date-time";break;case"float32":t.type=p("number",i),t.minimum=h.minimum,t.maximum=h.maximum;break;case"float64":t.type=p("number",i);break;default:throw new Error(`Unknown JTD type "${e.type}"`)}return f(t,e),t}if(e.enum)return t.type=p("string",i),t.enum=i?[...e.enum,null]:e.enum,f(t,e),t;if(e.elements)return t.type=p("array",i),t.items=d(e.elements,n,r+1,s),f(t,e),t;if(e.properties||e.optionalProperties){t.type=p("object",i),t.properties={};let o=[];if(e.properties)for(let[a,c]of Object.entries(e.properties))t.properties[a]=d(c,n,r+1,s),o.push(a);if(e.optionalProperties)for(let[a,c]of Object.entries(e.optionalProperties))t.properties[a]=d(c,n,r+1,s);return o.length>0&&(t.required=o),e.additionalProperties!==!0&&(t.additionalProperties=!1),f(t,e),t}if(e.values)return t.type=p("object",i),t.additionalProperties=d(e.values,n,r+1,s),f(t,e),t;if(e.discriminator&&e.mapping){let o=Object.keys(e.mapping);t.type=p("object",i),t.description=`Tagged union: set '${e.discriminator}' to one of [${o.join(", ")}], then populate ONLY the property whose name matches the chosen '${e.discriminator}' value. Leave all other variant properties empty.`,t.properties={[e.discriminator]:{type:"string",enum:[...o],description:`Selects which variant to use. MUST match exactly one of: ${o.join(", ")}.`}},t.required=[e.discriminator],t.additionalProperties=!1;for(let[a,c]of Object.entries(e.mapping)){let u=d(c,n,r+1,s),y=`Populate ONLY when ${e.discriminator}='${a}'.`;u.description=u.description?`${u.description} \u2014 ${y}`:y,t.properties[a]=u}return f(t,e),t}return t.description="Any JSON value",f(t,e),t}var L=new Set(Object.keys(v));function l(e,n,r,s){if(s>g||e==null)return e;if(n.ref){let i=r?.[n.ref];return i?l(e,i,r,s+1):e}if(n.type&&L.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=>l(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]=l(i[t],o,r,s+1));if(n.optionalProperties)for(let[t,o]of Object.entries(n.optionalProperties))t in i&&(i[t]=l(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]=l(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||typeof i[t]!="object"||i[t]===null)return e;let a=l(i[t],o,r,s+1);return{[n.discriminator]:t,...a}}return e}var J=class e{schema;jtdSchema;descriptor;descriptors;static fromJTD(n){let r=d(n,n.definitions,0);return new e(r,n,void 0)}static fromSignal(n){let r=Y(n);return new e(r,void 0,n)}static fromSignals(n,r,s){let i={},t=[];for(let a of n){if(!a.name)continue;let c=e.fromSignal(a);i[a.name]=c.schema,a.optional||t.push(a.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?$(this.descriptors,n,l):this.jtdSchema?T(this.jtdSchema,n,l):this.descriptor?D(this.descriptor,n,l):{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 Y(e){let n=e.formats;if(!n||n.length===0)throw new Error("Signal descriptor has no formats");if(n.length===1){let[a]=n,c=O(a);return e.label&&(c.title=e.label),e.description&&(c.description=e.description),c}let r={};for(let[a,c]of n.entries()){let u=O(c);c.jtdSchema&&(u.description=u.description?`Structured JSON data. ${u.description}`:"Structured JSON data."),r[`format_${a}`]=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 O(e){if(e.jtdSchema)return d(e.jtdSchema,e.jtdSchema.definitions,0);if(e.mimeType)return H(e.mimeType);throw new Error("Signal format has neither jtdSchema nor mimeType")}function H(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 K(e){return J.fromJTD(e)}function X(e){return J.fromSignal(e)}0&&(module.exports={GeminiConversion,convertSignalToGeminiSchema,convertToGeminiSchema});
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});
2
2
  //# sourceMappingURL=gemini.cjs.map