@bicharts/shape-core 0.6.3 → 0.6.4
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/chunk-TBMKT74S.mjs +4 -0
- package/dist/index.mjs +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/wire.d.ts +14 -10
- package/package.json +2 -1
- package/dist/chunk-ANY34FNP.mjs +0 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
+
import{d as c}from"./chunk-FUTSF2X5.mjs";import{gzip as h}from"pako";var w=e=>h(e);function P(e){return x(w(JSON.stringify(e))).replace(/\//g,".")}function x(e){let t="";for(let r=0;r<e.length;r+=32768)t+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(t)}function T(e){if(typeof e!="string"||e==="")throw new TypeError("keyedSigner needs the host's signing key");return{sign:t=>String(c(t+e))}}function W(e,t){let n=t.sign(e);if(typeof n!="string"||n.trim()==="")throw new TypeError("the host's signer returned a blank signature");return n}function u(e,t){if(e==null||typeof e!="object")return;let n=e,r=n[t];return r??n[t.charAt(0).toUpperCase()+t.slice(1)]}function m(e){return String(e??"").toLowerCase().includes("ndjson")}function C(e){let t=null;try{t=e.headers?.get?.("content-type")??null}catch{t=null}return{status:typeof e.status=="number"?e.status:0,contentType:t,body:e.body??null,text:()=>e.text()}}function S(e,t,n){let r=e.trim();if(!r)return{result:null,typed:!1,parsed:!1};let i;try{i=JSON.parse(r)}catch{return{result:null,typed:!1,parsed:!1}}return f(i,t,n)}function f(e,t,n){if(!e||typeof e!="object"||Array.isArray(e))return{result:null,typed:!1,parsed:!0};let r=u(e,"type");if(r!=null){if(r==="progress"){let s=String(u(e,"stage")??"").trim();return s&&t?.(s),{result:null,typed:!0,parsed:!0}}if(r==="result"){let s=u(e,"result");return{result:s&&typeof s=="object"?s:null,typed:!0,parsed:!0}}return{result:null,typed:!0,parsed:!0}}return n?{result:u(e,"code")!==void 0||u(e,"errorMessage")!==void 0?e:null,typed:!1,parsed:!0}:{result:e,typed:!1,parsed:!0}}var a=class{constructor(t){this.onStage=t}onStage;result=null;anyParsed=!1;take(t){let n=S(t,this.onStage,!0);n.parsed&&(this.anyParsed=!0),n.result&&(n.typed||this.result===null)&&(this.result=n.result)}};function d(){return new Error("the generate response ended without a result")}async function R(e,t){let n=e.body;if(!n||typeof n.getReader!="function")return p(await e.text(),t,null);let r=n.getReader(),i=new TextDecoder,s=new a(t),o="";try{for(;;){let{done:y,value:g}=await r.read();if(y)break;o+=i.decode(g,{stream:!0});let l;for(;(l=o.indexOf(`
|
|
3
|
+
`))>=0;)s.take(o.slice(0,l)),o=o.slice(l+1)}}finally{try{r.releaseLock?.()}catch{}}if(o+=i.decode(),s.take(o),!s.result)throw d();return s.result}function p(e,t,n){let r=new a(t);for(let i of e.split(`
|
|
4
|
+
`))r.take(i);if(r.result)return r.result;throw!r.anyParsed&&n?n:d()}async function b(e,t){let n=await e.text(),r;try{r=JSON.parse(n)}catch(s){return p(n,t,s)}if(!r||typeof r!="object"||Array.isArray(r))throw new SyntaxError("the generate response was JSON but not a result object");let i=f(r,t,!1);if(i.result)return i.result;throw d()}async function N(e,t){return m(e.contentType)?R(e,t):b(e,t)}export{w as a,P as b,T as c,W as d,u as e,m as f,C as g,N as h};
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{a as dt,b as gt}from"./chunk-UQU75XXR.mjs";import{a as yt,b as Ct,c as ht,d as xt,e as Pt,f as St,g as Rt}from"./chunk-
|
|
2
|
+
import{a as dt,b as gt}from"./chunk-UQU75XXR.mjs";import{a as yt,b as Ct,c as ht,d as xt,e as Pt,f as St,g as Rt,h as Tt}from"./chunk-TBMKT74S.mjs";import{a as mt,b as pt}from"./chunk-IJXTU62R.mjs";import{A as it,B as rt,C as st,D as at,E as lt,F as ut,G as ct,I as ft,a as De,b as _e,c as we,d as Fe,e as Ne,f as Ee,g as Oe,h as ze,i as $e,j as Be,k as He,l as Ke,m as We,n as Ue,o as Ve,p as je,q as qe,r as Ze,s as Xe,t as Ye,u as Je,v as Qe,w as et,x as tt,y as nt,z as ot}from"./chunk-TDTXRIHS.mjs";import{a as Le}from"./chunk-QEH7WTLB.mjs";import{a as ke,b as Ge}from"./chunk-2LR73DNS.mjs";import{a as W,b as U,c as be,d as Me,e as ve,f as Ie}from"./chunk-OZEOA6ZE.mjs";import{a as b,f as M,g as C,h as v,i as L,j as ge,k as ye,l as K,m as d,n as Ce,o as he,p as xe,q as I,r as Pe,s as Se,t as Re,u as Te,v as k,w as Ae}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as me,b as pe,c as de}from"./chunk-DMLWYEQ2.mjs";import{a as ee,b as te,d as ne,e as oe,f as ie,g as re,h as se,i as ae,j as le,k as ue,l as ce,m as fe}from"./chunk-FUTSF2X5.mjs";var G=2,q=400;function E(i){return!!M(i)}function S(i){let n=new Set;for(let t of i){if(t==null)continue;let r=b(String(t));if(!v(r)&&!n.has(r)&&(n.add(r),n.size>=q))break}return Array.from(n)}function P(i){let n=S(i);if(n.length===0||O(i)<95)return!1;let t=n.filter(c=>E(c)&&!d(c)).length,r=n.filter(c=>!E(c)&&!!d(c)).length;return t>=1&&t>=r}function V(i,n){if(!d(i))return!1;let t=M(i);return t?n==="world"?!0:K.has(t):!1}function O(i){let n=S(i);if(n.length===0)return 0;let t=0;for(let r of n)E(r)&&t++;return Math.round(t/n.length*1e3)/10}function D(i){let n=S(i);if(n.length===0)return 0;let t=0;for(let r of n)d(r)&&t++;return Math.round(t/n.length*1e3)/10}function $(i){let n=new Set;for(let t of i){if(t==null)continue;let r=String(t).trim();if(!v(b(r))&&!n.has(r)&&(n.add(r),n.size>=q))break}return Array.from(n)}function z(i){let n=$(i);if(n.length===0)return 0;let t=0;for(let r of n)I(r).length>0&&t++;return Math.round(t/n.length*1e3)/10}function j(i,n){return U(n,W)?!0:$(i).some(t=>/^\d{5}(-\d{4})?$/.test(t.replace(/\.0+$/,"")))}function At(i,n){let t=S(i);if(t.length===0)return 0;let r=0;for(let c of t)k(c,n)&&r++;return Math.round(r/t.length*1e3)/10}function N(i,n){let t=0;for(let r of S(i))n(r)&&t++;return t}function bt(i,n){let t=0;for(let r of $(i))n(r)&&t++;return t}function Mt(i,n,t,r,c){let l=[],a=[],o={},R={},h=new Set(i),f=e=>n.map(s=>s[e]);for(let e of["city","country"]){let s=t?.[e];s&&h.has(s)&&(o[e]=s)}let Y=new Set(c??i);for(let e of["lat","lon"]){let s=t?.[e];s&&Y.has(s)&&(o[e]=s)}let g=t?.zip;if(g&&h.has(g)){let e=f(g),s=z(e);s<95?a.push(`zip=${g} (only ${s}% of values read as ZIPs)`):j(e,g)?o.zip=g:a.push(`zip=${g} (all values are 3-4 digits with nothing to say they are postal)`)}let p=t?.state;if(p&&h.has(p)){let e=f(p),s=S(e);s.length>0&&s.every(u=>V(u,r))?a.push(`state=${p} (every value is "CA", which is both Canada and California)`):P(e)?(a.push(`state=${p} (every value is a country, not a state)`),o.country||(o.country=p)):D(e)<95?a.push(`state=${p} (only ${D(e)}% of values are states/provinces)`):o.state=p}let y=new Set(Object.values(o).filter(Boolean)),T=i.filter(e=>!y.has(e)&&!e.startsWith("__"));if(!o.state){let e=null;for(let s of T){let u=f(s);if(P(u))continue;let m=D(u);if(m<95)continue;let F=N(u,A=>!!d(A)),Q=N(u,A=>!!d(A)&&!V(A,r));F<G&&Q<1||(!e||m>e.pct)&&(e={name:s,pct:m})}e&&(o.state=e.name,y.add(e.name),l.push(`state=${e.name} (${e.pct}% states/provinces)`))}if(!o.zip)for(let e of T){if(y.has(e))continue;let s=f(e),u=z(s);if(!(u<95)&&j(s,e)&&!(bt(s,m=>I(m).length>0)<G)){o.zip=e,y.add(e),l.push(`zip=${e} (${u}% ZIP codes)`);break}}let x=o.country;if(!x||!P(f(x))){let e=null;for(let s of T){if(y.has(s)||!P(f(s)))continue;let u=O(f(s));(!e||u>e.pct)&&(e={name:s,pct:u})}e&&(x&&(a.push(`country=${x} (only ${O(f(x))}% of values are country identifiers; using ${e.name} instead)`),R.country=x),o.country=e.name,y.add(e.name),l.push(`country=${e.name}`))}if(!o.city){let e=null;for(let s of T){if(y.has(s))continue;let u=f(s),m=At(u,r);m<L||N(u,F=>k(F,r))<G||(!e||m>e.pct)&&(e={name:s,pct:m})}e&&(o.city=e.name,l.push(`city=${e.name} (${e.pct}% known cities)`))}let B=o.country?f(o.country):[],_=!!o.country&&P(B),J=_?new Set(B.map(e=>M(e==null?null:String(e))).filter(Boolean)).size:0,H=_&&J>=2,w=!!(o.lat&&o.lon)&&n.some(e=>{let s=+String(e[o.lat]??"").trim(),u=+String(e[o.lon]??"").trim();return isFinite(s)&&isFinite(u)&&s>=-90&&s<=90&&u>=-180&&u<=180&&String(e[o.lat]??"").trim()!==""&&String(e[o.lon]??"").trim()!==""});return o.lat&&o.lon&&!w&&a.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!H&&!(o.city||o.state||o.zip||w)&&a.push(_?`country=${o.country} (every row resolves to the same country - nothing to place apart)`:`country=${o.country} (values are not country identifiers)`),{bind:!!(o.city||o.state||o.zip||H||w)?o:null,backfilled:l,refused:a,...Object.keys(R).length?{labelFallback:R}:{}}}function Z(i,n){let t=n?.freemiumMaxShapeColumns;return typeof t!="number"||!isFinite(t)||t<1?null:!isFinite(i)||i<=t?0:Math.round(i-t)}function vt(i,n,t){let r=Z(i,n);if(r===null||r<=0)return null;let c=typeof n?.freemiumColumnCapPivot=="number"?n.freemiumColumnCapPivot:4,l=r>c?n?.freemiumColumnCapMessageMany:n?.freemiumColumnCapMessageFew;if(typeof l!="string"||l.trim().length===0)return null;let a=l.split("{n}").join(String(r)).split("{fields}").join(r===1?"field":"fields"),o=X(t);return o.length===0?a:a+" "+o.join(" ")}function X(i){if(!i||i.length===0)return[];let n=[],t=new Map,r=new Map;for(let l of i){let a=typeof l?.dateGroupId=="string"?l.dateGroupId.trim():"";if(a!==""&&(t.has(a)||(n.push(a),t.set(a,0)),l.isDatePart===!0&&t.set(a,t.get(a)+1),l.isReassembledDate===!0&&!r.has(a))){let o=typeof l.sourceField=="string"?l.sourceField.trim():"",R=typeof l.name=="string"?l.name.trim():"",h=o!==""?o:R;h!==""&&r.set(a,h)}}let c=[];for(let l of n){let a=r.get(l),o=t.get(l)??0;!a||o===0||c.push(`'${a}' is a date hierarchy and counts as ${o+1} fields - bind the date itself instead of its hierarchy.`)}return c}export{L as CITY_ROLE_MATCH_PCT,tt as DEFAULT_GAP_FACTOR,re as DEFAULT_TEMPERATURE,oe as GET_RANDOM,Ee as INTENSIVE_SUFFIX_TOKENS,Ne as INTENSIVE_WORD_TOKENS,ft as IndexedText,nt as MAX_RUN_BOUNDS,ze as POSITIONAL_SUFFIX_TOKENS,Oe as POSITIONAL_WORD_TOKENS,dt as PREVIEW_OMITTED_FIELDS,C as ROLE_MATCH_PCT,ne as SIMPLE_STRING_HASH,te as STR,D as admin1MatchPct,qe as allowedAggregations,Ie as buildGeoIsoColumn,Re as buildGeoPointColumns,Ae as cityMatchPct,Te as cityTagsFor,ut as classifyAdditivity,je as classifyForAggregation,ct as classifyNumericValueNature,at as classifyTemporal,Ke as codeNeedsLegacyAggNames,Je as codeReadsColumn,Qe as codeReadsColumnsByRoleOrPosition,He as collapseRepeatedAggPrefix,et as columnsTheCodeReads,we as countryRegion,Ze as defaultAggregation,Le as detectFormatSignature,be as detectGeo,de as detectOrdinalDomain,st as detectTextDatePattern,Ct as encodePayload,mt as engineTypeForSqlType,We as englishImplicitAggNames,vt as freemiumColumnCapRefusal,Z as freemiumColumnsOverCap,X as freemiumDateHierarchyClauses,yt as gzipWireText,Be as hasDefaultAggPrefix,lt as hostAggHint,pt as ingest,Xe as isAggregationAllowed,v as isBlankLike,ye as isCityTableLoaded,ie as isDeterministicRefusal,Pe as isGeoPointAmbiguity,rt as isIdentifierName,ve as isJoinGeoKind,St as isNdjsonContentType,me as isOrdinalFriendlyName,ht as keyedSigner,ce as localMidnightDateColumns,ue as localMidnightToUtcDay,P as looksLikeCountryColumn,it as measureCadence,xt as messageSignature,Ge as monthLookupFor,Ve as nameLooksIntensiveRate,Ue as nameLooksPositional,ee as nameWords,Ce as normalizeCountry,fe as normalizeLocalMidnightDates,ke as normalizeMonthKey,b as normalizePlaceName,xe as normalizeZip5,se as parseDateStable,ot as parseTemporalPoint,gt as payloadPreview,Tt as readGenerateStream,Pt as readWireField,ge as registerCityTable,_e as registerIso3Regions,d as resolveAdmin1,Se as resolveGeoPoint,Mt as resolvePointRoles,pe as safeDistinctValuesToShip,Ye as shareOfTotalIsHonest,$e as stripHostAggPrefix,Fe as summarizeCountryRegions,De as summarizeGeoExtent,Me as toGeoIso,ae as wholeDayFrame,le as wholeDayIso,Rt as wireResponseFromFetch,z as zipMatchPct,I as zipPrefixCandidates,he as zipToPrefix3};
|
package/dist/testing.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{
|
|
2
|
+
import{f as y,h}from"./chunk-TBMKT74S.mjs";import"./chunk-FUTSF2X5.mjs";var p=class extends Error{contract;failures;constructor(e,r){super(`${e} conformance failed:
|
|
3
3
|
- ${r.join(`
|
|
4
4
|
- `)}`),this.name="ConformanceError",this.contract=e,this.failures=r}},u=class{constructor(e){this.contract=e}contract;failures=[];check(e,r){e||this.failures.push(r)}fail(e){this.failures.push(e)}throwIfFailed(){if(this.failures.length)throw new p(this.contract,this.failures.slice())}},f="H4sIAAAAAAAAA6tWyk0tSs5ITUxRslIqS8wpTVWqBQBL0RbkEwAAAA==",l="H4sIAAAAAAAAA6tWSkksSVSyUsrMyyrKz1OqBQBVrD9YEAAAAA==";function d(s){return s instanceof Error?`${s.name}: ${s.message}`:String(s)}function w(s){let e=new u("WireSigner");(!s||typeof s.sign!="function")&&(e.fail("the signer has no sign() method"),e.throwIfFailed());let r,a,i;try{r=s.sign(f),a=s.sign(f),i=s.sign(l)}catch(t){e.fail(`sign() threw on an ordinary encoded body: ${d(t)}`),e.throwIfFailed()}e.check(typeof r=="string",`sign() returned ${typeof r}, not a string`),e.check(typeof r!="string"||r.trim()!=="","sign() returned a blank signature"),e.check(r===a,"sign() is not deterministic: the same body signed twice gave two signatures"),e.check(r!==i,"sign() gave two different bodies the same signature"),e.throwIfFailed()}async function A(s){let e=new u("WireResponse"),r=new TextEncoder,a=[`{"type":"progress","stage":"Reading your data"}
|
|
5
5
|
`,`{"type":"result","result":{"code":"x","version":2}}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,6 +31,6 @@ export { codeReadsColumn, codeReadsColumnsByRoleOrPosition, columnsTheCodeReads
|
|
|
31
31
|
export { freemiumColumnsOverCap, freemiumColumnCapRefusal, freemiumDateHierarchyClauses } from "./freemiumCaps";
|
|
32
32
|
export type { FreemiumColumnCapStatus, FreemiumDateGroupColumn } from "./freemiumCaps";
|
|
33
33
|
export type { WireSigner, WireTransport, WireResponse, CredentialTriple, CredentialSource, ViewportSource, Clock, DiagnosticEntry, DiagnosticsSink, RendererId, WireServices, } from "./host/services";
|
|
34
|
-
export { encodePayload, keyedSigner, messageSignature, readWireField } from "./wire";
|
|
34
|
+
export { encodePayload, gzipWireText, keyedSigner, messageSignature, readWireField } from "./wire";
|
|
35
35
|
export type { GzipText } from "./wire";
|
|
36
36
|
export { readGenerateStream, isNdjsonContentType, wireResponseFromFetch } from "./wireStream";
|
package/dist/types/wire.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import type { WireSigner } from "./host/services";
|
|
2
|
+
/** Gzip one string (the request's JSON) to bytes. */
|
|
3
|
+
export type GzipText = (text: string) => Uint8Array;
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* byte-identical to what it sent before this function existed only if it keeps its own. The
|
|
7
|
-
* server inflates any valid gzip.
|
|
5
|
+
* The envelope's compressor: pako's gzip at its default level (6), from the exact pako version
|
|
6
|
+
* this package pins. Exported so a host's test can derive a known answer from the same
|
|
7
|
+
* function the envelope uses; a host never needs to call it.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export declare const gzipWireText: GzipText;
|
|
10
|
+
/**
|
|
11
|
+
* JSON -> gzip -> base64 -> '/' to '.'. The body every signed request sends, compressed with
|
|
12
|
+
* `gzipWireText`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function encodePayload(payload: unknown): string;
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* the server and read as a network fault.
|
|
16
|
+
* @deprecated The compressor is no longer the host's: every envelope is compressed with this
|
|
17
|
+
* package's pinned pako (`gzipWireText`), and a second argument is IGNORED. The overload is
|
|
18
|
+
* kept only so a caller written against 0.6.1-0.6.3 still compiles; drop the argument.
|
|
15
19
|
*/
|
|
16
20
|
export declare function encodePayload(payload: unknown, gzip: GzipText): string;
|
|
17
21
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bicharts/shape-core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Host-agnostic data-shape profiler: ingest a dataset's rows through IValueCollection.addRow and read back the measured shape as an LLMColumnWithValue[] payload — types, cardinality, temporal/ordinal detection, geographic region and point resolution, cross-column signals. MEASUREMENT only: the policy that decides what a measured shape means for chart selection lives server-side.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"directory": "packages/shape-core"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
+
"pako": "3.0.2",
|
|
94
95
|
"papaparse": "^5.4.1"
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
package/dist/chunk-ANY34FNP.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
-
import{d as f}from"./chunk-FUTSF2X5.mjs";function b(e,t){if(typeof t!="function")throw new TypeError("encodePayload needs the host's gzip function");return h(t(JSON.stringify(e))).replace(/\//g,".")}function h(e){let t="";for(let r=0;r<e.length;r+=32768)t+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(t)}function k(e){if(typeof e!="string"||e==="")throw new TypeError("keyedSigner needs the host's signing key");return{sign:t=>String(f(t+e))}}function v(e,t){let n=t.sign(e);if(typeof n!="string"||n.trim()==="")throw new TypeError("the host's signer returned a blank signature");return n}function u(e,t){if(e==null||typeof e!="object")return;let n=e,r=n[t];return r??n[t.charAt(0).toUpperCase()+t.slice(1)]}function w(e){return String(e??"").toLowerCase().includes("ndjson")}function W(e){let t=null;try{t=e.headers?.get?.("content-type")??null}catch{t=null}return{status:typeof e.status=="number"?e.status:0,contentType:t,body:e.body??null,text:()=>e.text()}}function m(e,t,n){let r=e.trim();if(!r)return{result:null,typed:!1,parsed:!1};let i;try{i=JSON.parse(r)}catch{return{result:null,typed:!1,parsed:!1}}return c(i,t,n)}function c(e,t,n){if(!e||typeof e!="object"||Array.isArray(e))return{result:null,typed:!1,parsed:!0};let r=u(e,"type");if(r!=null){if(r==="progress"){let s=String(u(e,"stage")??"").trim();return s&&t?.(s),{result:null,typed:!0,parsed:!0}}if(r==="result"){let s=u(e,"result");return{result:s&&typeof s=="object"?s:null,typed:!0,parsed:!0}}return{result:null,typed:!0,parsed:!0}}return n?{result:u(e,"code")!==void 0||u(e,"errorMessage")!==void 0?e:null,typed:!1,parsed:!0}:{result:e,typed:!1,parsed:!0}}var l=class{constructor(t){this.onStage=t}onStage;result=null;anyParsed=!1;take(t){let n=m(t,this.onStage,!0);n.parsed&&(this.anyParsed=!0),n.result&&(n.typed||this.result===null)&&(this.result=n.result)}};function d(){return new Error("the generate response ended without a result")}async function x(e,t){let n=e.body;if(!n||typeof n.getReader!="function")return y(await e.text(),t,null);let r=n.getReader(),i=new TextDecoder,s=new l(t),o="";try{for(;;){let{done:p,value:g}=await r.read();if(p)break;o+=i.decode(g,{stream:!0});let a;for(;(a=o.indexOf(`
|
|
3
|
-
`))>=0;)s.take(o.slice(0,a)),o=o.slice(a+1)}}finally{try{r.releaseLock?.()}catch{}}if(o+=i.decode(),s.take(o),!s.result)throw d();return s.result}function y(e,t,n){let r=new l(t);for(let i of e.split(`
|
|
4
|
-
`))r.take(i);if(r.result)return r.result;throw!r.anyParsed&&n?n:d()}async function S(e,t){let n=await e.text(),r;try{r=JSON.parse(n)}catch(s){return y(n,t,s)}if(!r||typeof r!="object"||Array.isArray(r))throw new SyntaxError("the generate response was JSON but not a result object");let i=c(r,t,!1);if(i.result)return i.result;throw d()}async function A(e,t){return w(e.contentType)?x(e,t):S(e,t)}export{b as a,k as b,v as c,u as d,w as e,W as f,A as g};
|