@trayai/helix-sdk 0.78.0 → 0.80.0

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/CHANGELOG.md CHANGED
@@ -9,6 +9,13 @@ general availability, minor versions may include breaking changes.
9
9
  The SDK and [`@trayai/helix-cli`](https://www.npmjs.com/package/@trayai/helix-cli) are
10
10
  released together and share a version — install matching versions.
11
11
 
12
+ ## 0.80.0
13
+
14
+ ### Changed
15
+
16
+ - Internal configuration additions supporting the Helix CLI's new browser sign-in
17
+ (`helix login`). No changes to the SDK's public API.
18
+
12
19
  ## 0.72.0
13
20
 
14
21
  ### Added
@@ -1 +1 @@
1
- import{a as n,b as s,c as i,d as a}from"../chunk-5XNPF4RA.js";import"../chunk-ATJUJXR7.js";import p from"ky";var d=6e4;async function l(e){let u=n({authenticationId:e.authenticationId,method:e.method,url:e.url,body:e.body,headers:e.headers,query:e.query}),k=s(e.env),r=await p.post(`${k}/broker/http/dev`,{json:u,headers:{Authorization:`Bearer ${e.devToken}`,Accept:"application/json"},throwHttpErrors:!1,timeout:e.timeoutMs??d}),t;if((r.headers.get("content-type")??"").includes("application/json")?t=await r.json():t=await r.text(),r.status<200||r.status>=300)return{kind:"brokerError",brokerStatus:r.status,body:t};let o=i.safeParse(t);return o.success?{kind:"upstream",upstream:a(o.data)}:{kind:"brokerError",brokerStatus:r.status,body:t}}export{l as callBrokerDev};
1
+ import{a as n,b as s,c as i,d as a}from"../chunk-R56ARJY5.js";import"../chunk-7MAMPE72.js";import p from"ky";var d=6e4;async function l(e){let u=n({authenticationId:e.authenticationId,method:e.method,url:e.url,body:e.body,headers:e.headers,query:e.query}),k=s(e.env),r=await p.post(`${k}/broker/http/dev`,{json:u,headers:{Authorization:`Bearer ${e.devToken}`,Accept:"application/json"},throwHttpErrors:!1,timeout:e.timeoutMs??d}),t;if((r.headers.get("content-type")??"").includes("application/json")?t=await r.json():t=await r.text(),r.status<200||r.status>=300)return{kind:"brokerError",brokerStatus:r.status,body:t};let o=i.safeParse(t);return o.success?{kind:"upstream",upstream:a(o.data)}:{kind:"brokerError",brokerStatus:r.status,body:t}}export{l as callBrokerDev};
@@ -0,0 +1 @@
1
+ var g=new Set(["production"]),i=new Map,o={name:"production",exposedName:"us1",displayName:"production",hosts:{api:"https://api.tray.io",broker:"https://api.tray.io/private/v1/code",ingest:"https://api.tray.io/private/v1/helix/otlp",weaver:"https://weaver.tray.io",app:"https://app.tray.io",projectHost:"helix-app.ai",dashboard:"https://helix.tray.io",auth:"https://auth.tray.io"},login:{storePrefix:"PROD",appUrl:"https://app.tray.io",cookieName:"prod_tray_lid",cookieDomain:"tray.io"}};i.set(o.name,o);var l=["api","broker","ingest","weaver","app","projectHost","dashboard"],d=["auth"],u=["storePrefix","appUrl","cookieName","cookieDomain"];function m(e){if(!e.name||typeof e.name!="string")throw new Error("EnvironmentProfile.name must be a non-empty string");if(!e.exposedName||typeof e.exposedName!="string")throw new Error("EnvironmentProfile.exposedName must be a non-empty string");if(!e.displayName||typeof e.displayName!="string")throw new Error("EnvironmentProfile.displayName must be a non-empty string");if(!e.hosts||typeof e.hosts!="object")throw new Error("EnvironmentProfile.hosts must be an object");if(!e.login||typeof e.login!="object")throw new Error("EnvironmentProfile.login must be an object");for(let n of l)if(typeof e.hosts[n]!="string"||!e.hosts[n])throw new Error(`EnvironmentProfile.hosts.${n} must be a non-empty string`);for(let n of d){let r=e.hosts[n];if(r!==void 0&&(typeof r!="string"||!r))throw new Error(`EnvironmentProfile.hosts.${n} must be a non-empty string when set`)}for(let n of u)if(typeof e.login[n]!="string"||!e.login[n])throw new Error(`EnvironmentProfile.login.${n} must be a non-empty string`)}function v(e,n){return e.name===n.name&&e.exposedName===n.exposedName&&e.displayName===n.displayName&&l.every(r=>e.hosts[r]===n.hosts[r])&&d.every(r=>e.hosts[r]===n.hosts[r])&&u.every(r=>e.login[r]===n.login[r])}function _(e){m(e);let n=i.get(e.name);if(n){if(v(n,e))return;throw new Error(`EnvironmentProfile.name "${e.name}" is already registered with different values`)}for(let r of i.values())if(r.exposedName===e.exposedName)throw new Error(`EnvironmentProfile.exposedName "${e.exposedName}" is already used by "${r.name}"`);i.set(e.name,e)}function c(e){return i.has(e)}function y(e){return i.get(e)}function E(e){let n=i.get(e);if(!n)throw new Error(`Unknown environment: ${e}`);return n}function h(){return[...i.keys()]}function b(){return[...i.values()].map(e=>e.exposedName)}function f(e){for(let n of i.values())if(n.exposedName===e)return n.name}var s=Symbol.for("@trayai/helix-sdk.forcedEnvironment");function p(e){let n=globalThis;if(e===void 0||e.trim()===""){delete n[s];return}let r=e.trim(),t=f(r);if(t){n[s]=t;return}if(c(r)){n[s]=r;return}throw new Error(`Unknown environment: ${r}`)}function w(){return globalThis[s]}function x(){return[...i.values()].filter(e=>!g.has(e.name))}function S(){p(void 0),i.clear(),i.set(o.name,{...o,hosts:{...o.hosts},login:{...o.login}})}var a=class e extends Error{detail;constructor(n){super(k(n)),this.name="SdkError",this.detail=n}get kind(){return this.detail.kind}static unknownAlias(n,r){return new e({kind:"unknown_alias",alias:n,available:r})}static inputValidationFailed(n){return new e({kind:"input_validation_failed",fields:n})}static outputValidationFailed(n){return new e({kind:"output_validation_failed",fields:n})}static configLoadFailed(n){return new e({kind:"config_load_failed",cause:n})}static brokerError(n,r,t){return new e({kind:"broker_error",status:n,message:r,body:t})}static unsupportedBodyType(n){return new e({kind:"unsupported_body_type",actualType:n})}static unsupportedScheme(n){return new e({kind:"unsupported_scheme",scheme:n})}static missingExecutionCredentials(){return new e({kind:"missing_execution_credentials"})}static missingTrayToken(){return new e({kind:"missing_tray_token"})}static dbCallFailed(n,r){return new e({kind:"db_call_failed",message:n,cause:r})}static dbQueryFailed(n){return new e({kind:"db_query_failed",message:n})}static dbInvalidParameters(n){return new e({kind:"db_invalid_parameters",message:n})}static kvKeyInvalid(n){return new e({kind:"kv_key_invalid",message:n})}static kvValueInvalid(n){return new e({kind:"kv_value_invalid",message:n})}static kvValueTooLarge(n,r){return new e({kind:"kv_value_too_large",message:n,maxBytes:r})}static kvNotAvailable(){return new e({kind:"kv_not_available"})}static kvCallFailed(n,r,t){return new e({kind:"kv_call_failed",status:n,message:r,body:t})}static kvRequiresProvisioning(){return new e({kind:"kv_requires_provisioning"})}static filesPathInvalid(n){return new e({kind:"files_path_invalid",message:n})}static filesValueInvalid(n){return new e({kind:"files_value_invalid",message:n})}static filesValueTooLarge(n,r){return new e({kind:"files_value_too_large",message:n,maxBytes:r})}static filesNotAvailable(){return new e({kind:"files_not_available"})}static filesCallFailed(n,r,t){return new e({kind:"files_call_failed",status:n,message:r,body:t})}static filesRequiresProvisioning(){return new e({kind:"files_requires_provisioning"})}};function N(e){return e instanceof a}function k(e){switch(e.kind){case"unknown_alias":return`Unknown auth alias "${e.alias}". Available: ${e.available.join(", ")||"(none)"}`;case"input_validation_failed":return`Input validation failed for fields: ${e.fields.join(", ")}`;case"output_validation_failed":return`Output validation failed for fields: ${e.fields.join(", ")}`;case"config_load_failed":return`Config load failed: ${e.cause}`;case"broker_error":return`broker error: ${e.status} ${e.message}`;case"unsupported_body_type":return`unsupported body type: ${e.actualType}`;case"unsupported_scheme":return`unsupported scheme: ${e.scheme} (only https supported)`;case"missing_execution_credentials":return"missing execution credentials: at least one of internalJwt / helixExecutionJwt must be set before an authed broker/KV call";case"missing_tray_token":return"Not logged in. Run `helix login` to authenticate before making authed HTTP calls in dev.";case"db_call_failed":return`Database call failed: ${e.message}`;case"db_query_failed":return`Database query failed: ${e.message}`;case"db_invalid_parameters":return`Invalid database parameters: ${e.message}`;case"kv_key_invalid":return`Invalid KV key: ${e.message}`;case"kv_value_invalid":return e.message;case"kv_value_too_large":return e.message;case"kv_not_available":return"Key-value store is not available in this environment";case"kv_call_failed":return`KV platform error: ${e.status} ${e.message}`;case"kv_requires_provisioning":return"Key-value store requires a provisioned project (run helix project set)";case"files_path_invalid":return`Invalid file path: ${e.message}`;case"files_value_invalid":return e.message;case"files_value_too_large":return e.message;case"files_not_available":return"File storage is not available in this environment";case"files_call_failed":return`Files platform error: ${e.status} ${e.message}`;case"files_requires_provisioning":return"File storage requires a provisioned project (run helix project set)"}}export{_ as a,c as b,y as c,E as d,h as e,b as f,f as g,p as h,w as i,x as j,S as k,a as l,N as m};
@@ -1 +1 @@
1
- import{d as m,l as p}from"./chunk-ATJUJXR7.js";var l=new Set(["proxy-authorization","x-tray-token"]);function k(e){let t=e.toLowerCase();return l.has(t)||t.startsWith("x-tray-internal-")}function g(e){let t;return e instanceof Headers?t=Array.from(e.entries()):Array.isArray(e)?t=e:t=Object.entries(e),t.filter(([o])=>!k(o)).map(([o,i])=>({name:o,value:i}))}function B(e){return typeof e=="string"?"string":e instanceof Blob?"Blob":e instanceof FormData?"FormData":e instanceof ArrayBuffer?"ArrayBuffer":e instanceof Uint8Array?"Uint8Array":typeof ReadableStream<"u"&&e instanceof ReadableStream?"ReadableStream":null}function q(e){let t=new URL(e.url);if(t.protocol!=="https:")throw p.unsupportedScheme(t.protocol.replace(/:$/,""));let o=e.body!==void 0&&e.body!==null?B(e.body):null;if(o!==null)throw p.unsupportedBodyType(o);let i=t.host,s=t.pathname,n=[];for(let[d,a]of t.searchParams.entries())n.push({name:d,value:a});if(e.query!==void 0)if(e.query instanceof URLSearchParams)for(let[d,a]of e.query.entries())n.push({name:d,value:a});else for(let[d,a]of Object.entries(e.query))if(Array.isArray(a))for(let h of a)n.push({name:d,value:h});else n.push({name:d,value:a});let u=e.headers!==void 0?g(e.headers):[],c=e.body!==void 0&&e.body!==null?{host:i,method:e.method,path:s,body:e.body,headers:u,queryParams:n}:{host:i,method:e.method,path:s,headers:u,queryParams:n};return{authenticationId:e.authenticationId,httpRequest:c}}function A(e){return m(e).hosts.broker}import{z as r}from"zod";var y=r.object({name:r.string(),value:r.string()}),R=r.object({host:r.string(),method:r.string(),path:r.string().startsWith("/"),body:r.record(r.unknown()).optional(),headers:r.array(y),queryParams:r.array(y)}),w=r.object({authenticationId:r.string().uuid(),httpRequest:R}),j=r.object({httpResponse:r.object({status:r.number(),body:r.unknown().optional(),headers:r.array(y)})});function D(e){let{status:t,body:o,headers:i}=e.httpResponse,s={};for(let{name:n,value:u}of i){let f=n.toLowerCase(),c=s[f];c===void 0?s[f]=u:Array.isArray(c)?c.push(u):s[f]=[c,u]}return{status:t,body:o,headers:s}}export{q as a,A as b,j as c,D as d};
1
+ import{d as m,l as p}from"./chunk-7MAMPE72.js";var l=new Set(["proxy-authorization","x-tray-token"]);function k(e){let t=e.toLowerCase();return l.has(t)||t.startsWith("x-tray-internal-")}function g(e){let t;return e instanceof Headers?t=Array.from(e.entries()):Array.isArray(e)?t=e:t=Object.entries(e),t.filter(([o])=>!k(o)).map(([o,i])=>({name:o,value:i}))}function B(e){return typeof e=="string"?"string":e instanceof Blob?"Blob":e instanceof FormData?"FormData":e instanceof ArrayBuffer?"ArrayBuffer":e instanceof Uint8Array?"Uint8Array":typeof ReadableStream<"u"&&e instanceof ReadableStream?"ReadableStream":null}function q(e){let t=new URL(e.url);if(t.protocol!=="https:")throw p.unsupportedScheme(t.protocol.replace(/:$/,""));let o=e.body!==void 0&&e.body!==null?B(e.body):null;if(o!==null)throw p.unsupportedBodyType(o);let i=t.host,s=t.pathname,n=[];for(let[d,a]of t.searchParams.entries())n.push({name:d,value:a});if(e.query!==void 0)if(e.query instanceof URLSearchParams)for(let[d,a]of e.query.entries())n.push({name:d,value:a});else for(let[d,a]of Object.entries(e.query))if(Array.isArray(a))for(let h of a)n.push({name:d,value:h});else n.push({name:d,value:a});let u=e.headers!==void 0?g(e.headers):[],c=e.body!==void 0&&e.body!==null?{host:i,method:e.method,path:s,body:e.body,headers:u,queryParams:n}:{host:i,method:e.method,path:s,headers:u,queryParams:n};return{authenticationId:e.authenticationId,httpRequest:c}}function A(e){return m(e).hosts.broker}import{z as r}from"zod";var y=r.object({name:r.string(),value:r.string()}),R=r.object({host:r.string(),method:r.string(),path:r.string().startsWith("/"),body:r.record(r.unknown()).optional(),headers:r.array(y),queryParams:r.array(y)}),w=r.object({authenticationId:r.string().uuid(),httpRequest:R}),j=r.object({httpResponse:r.object({status:r.number(),body:r.unknown().optional(),headers:r.array(y)})});function D(e){let{status:t,body:o,headers:i}=e.httpResponse,s={};for(let{name:n,value:u}of i){let f=n.toLowerCase(),c=s[f];c===void 0?s[f]=u:Array.isArray(c)?c.push(u):s[f]=[c,u]}return{status:t,body:o,headers:s}}export{q as a,A as b,j as c,D as d};
@@ -1 +1 @@
1
- import{l as n}from"./chunk-ATJUJXR7.js";var R="X-Helix-Project-Execution-Token",b="X-Tray-Token",h={mode:"dev",deploymentId:null},u={...h},i={};function B(t){let{internalJwt:e,helixExecutionJwt:r,devToken:o,...s}=t;"internalJwt"in t&&(i.internalJwt=e),"helixExecutionJwt"in t&&(i.helixExecutionJwt=r),"devToken"in t&&(i.devToken=o),u={...u,...s}}function D(){return u}function L(){return i.internalJwt}function F(){return i.helixExecutionJwt}function N(){return i.devToken}var J="tray-config-bridge",c=null;function M(t){c=t}function O(){if(!c)throw new Error("Active tray config not seeded. Worker boot must call setActiveConfig() before handlers run.");return c}function U(){c=null}var E=1024,a=100*1024*1024,x=250,T=3600,S=T*1e3,m=new TextEncoder,_=/(^|\/)\.\.(\/|$)/,p=/[?#]/;function v(t){for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);if(r<=31||r===127)return!0}return!1}function $(t,e=E){if(t.length===0)throw n.filesPathInvalid("Path must be a non-empty string");A(t,e)}function G(t){return t.endsWith("/")?t.slice(0,-1):t}function A(t,e=E){if(t.length===0)return;if(_.test(t))throw n.filesPathInvalid("Path contains path traversal segment");if(p.test(t)||v(t))throw n.filesPathInvalid("Path contains illegal characters");let r=t.split("/");if(t.startsWith("/")||t.endsWith("/")||r.some(s=>s===""))throw n.filesPathInvalid("Path must not contain empty path segments");for(let s of r){let d=m.encode(s).length;if(d>x)throw n.filesPathInvalid(`Path segment exceeds ${x} UTF-8 bytes (got ${d})`)}let o=m.encode(t).length;if(o<1||o>e)throw n.filesPathInvalid(`Path must be between 1 and ${e} UTF-8 bytes (got ${o})`)}function V(t){if(t>a)throw n.filesValueTooLarge(`File exceeds maximum size of ${a} bytes (got ${t})`,a)}function W(t){let e=t!==void 0?t*1e3:S;return new Date(Date.now()+e)}import{join as f}from"path";var C="files",I="files-meta",P=1023,w=1,k=5;function K(t){let e=Math.max(Buffer.byteLength(l(t),"utf8"),Buffer.byteLength(g(t),"utf8"));return Math.max(0,P-e-w-k)}function l(t){return f(t,".helix",C)}function g(t){return f(t,".helix",I)}function y(t,e){return f(l(t),...e.split("/"))}function q(t,e){return f(g(t),...e.split("/"))+".json"}function Q(t,e){return e.length===0?l(t):y(t,e)}function Z(t,e){return e.length===0?g(t):f(g(t),...e.split("/"))}export{R as a,b,B as c,D as d,L as e,F as f,N as g,J as h,M as i,O as j,U as k,a as l,$ as m,G as n,A as o,V as p,W as q,K as r,y as s,q as t,Q as u,Z as v};
1
+ import{l as n}from"./chunk-7MAMPE72.js";var R="X-Helix-Project-Execution-Token",b="X-Tray-Token",h={mode:"dev",deploymentId:null},u={...h},i={};function B(t){let{internalJwt:e,helixExecutionJwt:r,devToken:o,...s}=t;"internalJwt"in t&&(i.internalJwt=e),"helixExecutionJwt"in t&&(i.helixExecutionJwt=r),"devToken"in t&&(i.devToken=o),u={...u,...s}}function D(){return u}function L(){return i.internalJwt}function F(){return i.helixExecutionJwt}function N(){return i.devToken}var J="tray-config-bridge",c=null;function M(t){c=t}function O(){if(!c)throw new Error("Active tray config not seeded. Worker boot must call setActiveConfig() before handlers run.");return c}function U(){c=null}var E=1024,a=100*1024*1024,x=250,T=3600,S=T*1e3,m=new TextEncoder,_=/(^|\/)\.\.(\/|$)/,p=/[?#]/;function v(t){for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);if(r<=31||r===127)return!0}return!1}function $(t,e=E){if(t.length===0)throw n.filesPathInvalid("Path must be a non-empty string");A(t,e)}function G(t){return t.endsWith("/")?t.slice(0,-1):t}function A(t,e=E){if(t.length===0)return;if(_.test(t))throw n.filesPathInvalid("Path contains path traversal segment");if(p.test(t)||v(t))throw n.filesPathInvalid("Path contains illegal characters");let r=t.split("/");if(t.startsWith("/")||t.endsWith("/")||r.some(s=>s===""))throw n.filesPathInvalid("Path must not contain empty path segments");for(let s of r){let d=m.encode(s).length;if(d>x)throw n.filesPathInvalid(`Path segment exceeds ${x} UTF-8 bytes (got ${d})`)}let o=m.encode(t).length;if(o<1||o>e)throw n.filesPathInvalid(`Path must be between 1 and ${e} UTF-8 bytes (got ${o})`)}function V(t){if(t>a)throw n.filesValueTooLarge(`File exceeds maximum size of ${a} bytes (got ${t})`,a)}function W(t){let e=t!==void 0?t*1e3:S;return new Date(Date.now()+e)}import{join as f}from"path";var C="files",I="files-meta",P=1023,w=1,k=5;function K(t){let e=Math.max(Buffer.byteLength(l(t),"utf8"),Buffer.byteLength(g(t),"utf8"));return Math.max(0,P-e-w-k)}function l(t){return f(t,".helix",C)}function g(t){return f(t,".helix",I)}function y(t,e){return f(l(t),...e.split("/"))}function q(t,e){return f(g(t),...e.split("/"))+".json"}function Q(t,e){return e.length===0?l(t):y(t,e)}function Z(t,e){return e.length===0?g(t):f(g(t),...e.split("/"))}export{R as a,b,B as c,D as d,L as e,F as f,N as g,J as h,M as i,O as j,U as k,a as l,$ as m,G as n,A as o,V as p,W as q,K as r,y as s,q as t,Q as u,Z as v};
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as wt,b as Yr}from"./chunk-L6J5L3JQ.js";import{a as k,b as D,d as y,e as O,f as T,g as pt,j as b,l as V,m as I,n as Ie,o as Ae,p as St,q as L,r as xt,s as ie,t as ae,u as ce,v as Ct}from"./chunk-KURGNIK4.js";import{a as q,b as se,c as bt,d as Et}from"./chunk-5XNPF4RA.js";import{b as gt,d as F,e as yt,i as ht,l as c,m as vt}from"./chunk-ATJUJXR7.js";import{randomUUID as $o}from"crypto";import{SpanStatusCode as Br,SpanKind as Ho}from"@opentelemetry/api";import{AsyncLocalStorage as qt}from"async_hooks";import{trace as dn,SpanKind as ln,SpanStatusCode as Oe}from"@opentelemetry/api";import{ExportResultCode as fn,W3CTraceContextPropagator as mn}from"@opentelemetry/core";import{NodeTracerProvider as pn,SimpleSpanProcessor as gn,BatchSpanProcessor as yn}from"@opentelemetry/sdk-trace-node";import{OTLPTraceExporter as Gr}from"@opentelemetry/exporter-trace-otlp-proto";import{OTLPLogExporter as Xr}from"@opentelemetry/exporter-logs-otlp-proto";function _e(e){return F(e).hosts.ingest}function Zr(){return T()??""}function Rt(){return{[k]:Zr()}}function kt(){let e=_e(b().env);return new Gr({url:`${e}/v1/traces`,headers:()=>Promise.resolve(Rt())})}function Tt(){let e=_e(b().env);return new Xr({url:`${e}/v1/logs`,headers:()=>Promise.resolve(Rt())})}import{logs as At,SeverityNumber as ue}from"@opentelemetry/api-logs";import{LoggerProvider as tn,BatchLogRecordProcessor as rn}from"@opentelemetry/sdk-logs";function W(e){try{return JSON.stringify(e)}catch(t){return JSON.stringify({_serialization_error:t instanceof Error?t.message:String(t)})}}function Qr(e){return new TextEncoder().encode(e).length}var Pt="\u2026[truncated]",en=Qr(Pt),z=4096;function A(e,t=z){let r=new TextEncoder().encode(e);if(r.length<=t)return e;let n=r.subarray(0,t-en);return new TextDecoder("utf-8").decode(n).replace(/�$/,"")+Pt}function h(e,t=z){return A(W(e),t)}var nn="@trayai/helix-sdk",J,It={debug:{number:ue.DEBUG,text:"DEBUG"},info:{number:ue.INFO,text:"INFO"},warn:{number:ue.WARN,text:"WARN"},error:{number:ue.ERROR,text:"ERROR"}};function on(){return y().mode==="lambda"?[new rn({exporter:Tt()})]:[]}function _t(){if(J!==void 0)return;let e=on();e.length!==0&&(J=new tn({processors:e}),At.setGlobalLoggerProvider(J))}function sn(e,t,r){let n=It[e]??It.info;return{severityNumber:n.number,severityText:n.text,body:t,...r?{attributes:{"tray.log.meta":h(r)}}:{}}}function Dt(e,t,r){At.getLogger(nn).emit(sn(e,t,r))}async function Ot(e=2e3){if(J===void 0)return;let t;try{await Promise.race([J.forceFlush(),new Promise(r=>{t=setTimeout(r,e)})])}catch(r){process.stderr.write(`[helix-sdk] otel log flush failed: ${r instanceof Error?r.message:String(r)}
1
+ import{a as wt,b as Yr}from"./chunk-L6J5L3JQ.js";import{a as k,b as D,d as y,e as O,f as T,g as pt,j as b,l as V,m as I,n as Ie,o as Ae,p as St,q as L,r as xt,s as ie,t as ae,u as ce,v as Ct}from"./chunk-W32AX5BI.js";import{a as q,b as se,c as bt,d as Et}from"./chunk-R56ARJY5.js";import{b as gt,d as F,e as yt,i as ht,l as c,m as vt}from"./chunk-7MAMPE72.js";import{randomUUID as $o}from"crypto";import{SpanStatusCode as Br,SpanKind as Ho}from"@opentelemetry/api";import{AsyncLocalStorage as qt}from"async_hooks";import{trace as dn,SpanKind as ln,SpanStatusCode as Oe}from"@opentelemetry/api";import{ExportResultCode as fn,W3CTraceContextPropagator as mn}from"@opentelemetry/core";import{NodeTracerProvider as pn,SimpleSpanProcessor as gn,BatchSpanProcessor as yn}from"@opentelemetry/sdk-trace-node";import{OTLPTraceExporter as Gr}from"@opentelemetry/exporter-trace-otlp-proto";import{OTLPLogExporter as Xr}from"@opentelemetry/exporter-logs-otlp-proto";function _e(e){return F(e).hosts.ingest}function Zr(){return T()??""}function Rt(){return{[k]:Zr()}}function kt(){let e=_e(b().env);return new Gr({url:`${e}/v1/traces`,headers:()=>Promise.resolve(Rt())})}function Tt(){let e=_e(b().env);return new Xr({url:`${e}/v1/logs`,headers:()=>Promise.resolve(Rt())})}import{logs as At,SeverityNumber as ue}from"@opentelemetry/api-logs";import{LoggerProvider as tn,BatchLogRecordProcessor as rn}from"@opentelemetry/sdk-logs";function W(e){try{return JSON.stringify(e)}catch(t){return JSON.stringify({_serialization_error:t instanceof Error?t.message:String(t)})}}function Qr(e){return new TextEncoder().encode(e).length}var Pt="\u2026[truncated]",en=Qr(Pt),z=4096;function A(e,t=z){let r=new TextEncoder().encode(e);if(r.length<=t)return e;let n=r.subarray(0,t-en);return new TextDecoder("utf-8").decode(n).replace(/�$/,"")+Pt}function h(e,t=z){return A(W(e),t)}var nn="@trayai/helix-sdk",J,It={debug:{number:ue.DEBUG,text:"DEBUG"},info:{number:ue.INFO,text:"INFO"},warn:{number:ue.WARN,text:"WARN"},error:{number:ue.ERROR,text:"ERROR"}};function on(){return y().mode==="lambda"?[new rn({exporter:Tt()})]:[]}function _t(){if(J!==void 0)return;let e=on();e.length!==0&&(J=new tn({processors:e}),At.setGlobalLoggerProvider(J))}function sn(e,t,r){let n=It[e]??It.info;return{severityNumber:n.number,severityText:n.text,body:t,...r?{attributes:{"tray.log.meta":h(r)}}:{}}}function Dt(e,t,r){At.getLogger(nn).emit(sn(e,t,r))}async function Ot(e=2e3){if(J===void 0)return;let t;try{await Promise.race([J.forceFlush(),new Promise(r=>{t=setTimeout(r,e)})])}catch(r){process.stderr.write(`[helix-sdk] otel log flush failed: ${r instanceof Error?r.message:String(r)}
2
2
  `)}finally{t!==void 0&&clearTimeout(t)}}function De(){let e=process.env.TRAY_PRETTY_LOGS;return e==="1"||e==="true"}function an(){if(process.env.NO_COLOR!==void 0)return!1;let e=process.env.FORCE_COLOR;return e!==void 0&&e!=="0"&&e!=="false"?!0:!!process.stdout.isTTY&&process.env.TERM!=="dumb"}function R(e,t){return an()?`\x1B[${e}m${t}\x1B[0m`:t}var cn=5,un={FN:"1;35",INFO:"34",AUTH:"35",API:"36",WARN:"33",ERROR:"31",DEBUG:"90"},Ft="32",Lt="31",de="2",jt="1";function le(e){return R(un[e]??"0",e.padEnd(cn))}function Nt(e,t){return`${le("FN")} ${R(jt,`${e} ${t}`.trim())}`}function Bt(e,t,r,n){let o=e.toUpperCase(),i=`${n?`${R(de,n)} `:""}${le(o)} ${t}`;return r&&Object.keys(r).length>0&&(i+=` ${R(de,W(r))}`),i}function Ut(e){return new Date(e[0]*1e3).toTimeString().slice(0,8)}function Mt(e){return`${le("AUTH")} ${e}`}function $t(e,t,r,n,o){let s=r===void 0?"ERR":String(r),i=R(o==="error"?Lt:Ft,s);return`${le("API")} ${e} ${t} \u2192 ${i} ${R(de,`${n}ms`)}`}function Ht(e,t,r){let n=t?Lt:Ft,o=R(n,"\u25CF"),s=R(n,t?"error":"success");return`${o} ${R(jt,e)} ${s} ${R(de,`${r}ms`)}`}function j(e){try{process.stdout.write(e+`
3
3
  `)}catch{}}var fe=new qt,me=new qt;function x(e){let t=me.getStore();t&&(t[e]=!0)}var hn=/^[0-9a-f]{32}$/;function wn(e){let t=e.replace(/-/g,"").toLowerCase();return hn.test(t)?t:null}var vn={0:"STATUS_CODE_UNSET",1:"STATUS_CODE_OK",2:"STATUS_CODE_ERROR"},N=new Map;function Vt(e,t,r){let n=N.get(e);n?n[t]=r:N.set(e,{[t]:r})}function S(e,t,r){e.setAttribute(t,h(r))}var Y;function Kt(e){return`${e[0]}${String(e[1]).padStart(9,"0")}`}function bn(e){return Math.round(e[0]*1e3+e[1]/1e6)}function Wt(e){try{process.stdout.write(W(e)+`
4
4
  `)}catch{}}var Fe=class{export(t,r){for(let n of t){let o=n.spanContext().spanId,s=N.get(o),i={...n.attributes};if(s!==void 0){for(let[d,f]of Object.entries(s))typeof f=="string"?i[d]=A(f):typeof f=="object"&&f!==null?i[d]=h(f):i[d]=f;N.delete(o)}let a=fe.getStore(),u=a?wn(a):null;Wt({_otel:"span",traceId:u??n.spanContext().traceId,spanId:o,parentSpanId:n.parentSpanContext?.spanId??"",name:n.name,kind:n.kind,startTimeUnixNano:Kt(n.startTime),endTimeUnixNano:Kt(n.endTime),attributes:i,status:{code:vn[n.status.code]??"STATUS_CODE_UNSET",...n.status.message?{message:A(n.status.message)}:{}}})}r({code:fn.SUCCESS})}forceFlush(){return Promise.resolve()}shutdown(){return Promise.resolve()}},Le=class{onStart(t,r){}onEnd(t){N.delete(t.spanContext().spanId)}forceFlush(){return Promise.resolve()}shutdown(){return Promise.resolve()}},je=class{onStart(t){let r=t;(r.name==="function"||r.name==="App")&&j(`
@@ -133,6 +133,7 @@ interface EnvironmentHosts {
133
133
  app: string;
134
134
  projectHost: string;
135
135
  dashboard: string;
136
+ auth?: string;
136
137
  }
137
138
  interface EnvironmentLoginInfo {
138
139
  storePrefix: string;
@@ -1 +1 @@
1
- import{c as e,h as n,i as o,j as r,k as t,m as x,s as P,t as C}from"../chunk-KURGNIK4.js";import{a as i,b as s,c as m,d as f,e as v,f as E,g,h as p,i as l,j as a,k as d,m as c}from"../chunk-ATJUJXR7.js";export{n as CONFIG_BRIDGE_CHANNEL,x as assertValidPath,t as clearActiveConfig,P as contentFilePath,r as getActiveConfig,a as getAdditionalEnvironmentProfiles,m as getEnvironmentProfile,s as isKnownEnvironment,c as isSdkError,v as listEnvironmentNames,E as listExposedEnvNames,C as metaFilePath,g as parseExposedEnvironment,i as registerEnvironmentProfile,f as requireEnvironmentProfile,d as resetEnvironmentRegistryForTests,l as resolveForcedEnvironment,o as setActiveConfig,p as setForcedEnvironment,e as setSdkConfig};
1
+ import{c as e,h as n,i as o,j as r,k as t,m as x,s as P,t as C}from"../chunk-W32AX5BI.js";import{a as i,b as s,c as m,d as f,e as v,f as E,g,h as p,i as l,j as a,k as d,m as c}from"../chunk-7MAMPE72.js";export{n as CONFIG_BRIDGE_CHANNEL,x as assertValidPath,t as clearActiveConfig,P as contentFilePath,r as getActiveConfig,a as getAdditionalEnvironmentProfiles,m as getEnvironmentProfile,s as isKnownEnvironment,c as isSdkError,v as listEnvironmentNames,E as listExposedEnvNames,C as metaFilePath,g as parseExposedEnvironment,i as registerEnvironmentProfile,f as requireEnvironmentProfile,d as resetEnvironmentRegistryForTests,l as resolveForcedEnvironment,o as setActiveConfig,p as setForcedEnvironment,e as setSdkConfig};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayai/helix-sdk",
3
- "version": "0.78.0",
3
+ "version": "0.80.0",
4
4
  "description": "Helix SDK runtime — defineFunction, ctx, defineConfig, authed HTTP",
5
5
  "license": "Apache-2.0",
6
6
  "author": "trayio",
@@ -1 +0,0 @@
1
- var u=new Set(["production"]),i=new Map,o={name:"production",exposedName:"us1",displayName:"production",hosts:{api:"https://api.tray.io",broker:"https://api.tray.io/private/v1/code",ingest:"https://api.tray.io/private/v1/helix/otlp",weaver:"https://weaver.tray.io",app:"https://app.tray.io",projectHost:"helix-app.ai",dashboard:"https://helix.tray.io"},login:{storePrefix:"PROD",appUrl:"https://app.tray.io",cookieName:"prod_tray_lid",cookieDomain:"tray.io"}};i.set(o.name,o);var l=["api","broker","ingest","weaver","app","projectHost","dashboard"],d=["storePrefix","appUrl","cookieName","cookieDomain"];function g(e){if(!e.name||typeof e.name!="string")throw new Error("EnvironmentProfile.name must be a non-empty string");if(!e.exposedName||typeof e.exposedName!="string")throw new Error("EnvironmentProfile.exposedName must be a non-empty string");if(!e.displayName||typeof e.displayName!="string")throw new Error("EnvironmentProfile.displayName must be a non-empty string");if(!e.hosts||typeof e.hosts!="object")throw new Error("EnvironmentProfile.hosts must be an object");if(!e.login||typeof e.login!="object")throw new Error("EnvironmentProfile.login must be an object");for(let n of l)if(typeof e.hosts[n]!="string"||!e.hosts[n])throw new Error(`EnvironmentProfile.hosts.${n} must be a non-empty string`);for(let n of d)if(typeof e.login[n]!="string"||!e.login[n])throw new Error(`EnvironmentProfile.login.${n} must be a non-empty string`)}function m(e,n){return e.name===n.name&&e.exposedName===n.exposedName&&e.displayName===n.displayName&&l.every(r=>e.hosts[r]===n.hosts[r])&&d.every(r=>e.login[r]===n.login[r])}function k(e){g(e);let n=i.get(e.name);if(n){if(m(n,e))return;throw new Error(`EnvironmentProfile.name "${e.name}" is already registered with different values`)}for(let r of i.values())if(r.exposedName===e.exposedName)throw new Error(`EnvironmentProfile.exposedName "${e.exposedName}" is already used by "${r.name}"`);i.set(e.name,e)}function v(e){return i.has(e)}function _(e){return i.get(e)}function y(e){let n=i.get(e);if(!n)throw new Error(`Unknown environment: ${e}`);return n}function E(){return[...i.keys()]}function b(){return[...i.values()].map(e=>e.exposedName)}function c(e){for(let n of i.values())if(n.exposedName===e)return n.name}var s=Symbol.for("@trayai/helix-sdk.forcedEnvironment");function f(e){let n=globalThis;if(e===void 0||e.trim()===""){delete n[s];return}let r=e.trim(),t=c(r);if(t){n[s]=t;return}if(v(r)){n[s]=r;return}throw new Error(`Unknown environment: ${r}`)}function h(){return globalThis[s]}function w(){return[...i.values()].filter(e=>!u.has(e.name))}function x(){f(void 0),i.clear(),i.set(o.name,{...o,hosts:{...o.hosts},login:{...o.login}})}var a=class e extends Error{detail;constructor(n){super(p(n)),this.name="SdkError",this.detail=n}get kind(){return this.detail.kind}static unknownAlias(n,r){return new e({kind:"unknown_alias",alias:n,available:r})}static inputValidationFailed(n){return new e({kind:"input_validation_failed",fields:n})}static outputValidationFailed(n){return new e({kind:"output_validation_failed",fields:n})}static configLoadFailed(n){return new e({kind:"config_load_failed",cause:n})}static brokerError(n,r,t){return new e({kind:"broker_error",status:n,message:r,body:t})}static unsupportedBodyType(n){return new e({kind:"unsupported_body_type",actualType:n})}static unsupportedScheme(n){return new e({kind:"unsupported_scheme",scheme:n})}static missingExecutionCredentials(){return new e({kind:"missing_execution_credentials"})}static missingTrayToken(){return new e({kind:"missing_tray_token"})}static dbCallFailed(n,r){return new e({kind:"db_call_failed",message:n,cause:r})}static dbQueryFailed(n){return new e({kind:"db_query_failed",message:n})}static dbInvalidParameters(n){return new e({kind:"db_invalid_parameters",message:n})}static kvKeyInvalid(n){return new e({kind:"kv_key_invalid",message:n})}static kvValueInvalid(n){return new e({kind:"kv_value_invalid",message:n})}static kvValueTooLarge(n,r){return new e({kind:"kv_value_too_large",message:n,maxBytes:r})}static kvNotAvailable(){return new e({kind:"kv_not_available"})}static kvCallFailed(n,r,t){return new e({kind:"kv_call_failed",status:n,message:r,body:t})}static kvRequiresProvisioning(){return new e({kind:"kv_requires_provisioning"})}static filesPathInvalid(n){return new e({kind:"files_path_invalid",message:n})}static filesValueInvalid(n){return new e({kind:"files_value_invalid",message:n})}static filesValueTooLarge(n,r){return new e({kind:"files_value_too_large",message:n,maxBytes:r})}static filesNotAvailable(){return new e({kind:"files_not_available"})}static filesCallFailed(n,r,t){return new e({kind:"files_call_failed",status:n,message:r,body:t})}static filesRequiresProvisioning(){return new e({kind:"files_requires_provisioning"})}};function N(e){return e instanceof a}function p(e){switch(e.kind){case"unknown_alias":return`Unknown auth alias "${e.alias}". Available: ${e.available.join(", ")||"(none)"}`;case"input_validation_failed":return`Input validation failed for fields: ${e.fields.join(", ")}`;case"output_validation_failed":return`Output validation failed for fields: ${e.fields.join(", ")}`;case"config_load_failed":return`Config load failed: ${e.cause}`;case"broker_error":return`broker error: ${e.status} ${e.message}`;case"unsupported_body_type":return`unsupported body type: ${e.actualType}`;case"unsupported_scheme":return`unsupported scheme: ${e.scheme} (only https supported)`;case"missing_execution_credentials":return"missing execution credentials: at least one of internalJwt / helixExecutionJwt must be set before an authed broker/KV call";case"missing_tray_token":return"Not logged in. Run `helix login` to authenticate before making authed HTTP calls in dev.";case"db_call_failed":return`Database call failed: ${e.message}`;case"db_query_failed":return`Database query failed: ${e.message}`;case"db_invalid_parameters":return`Invalid database parameters: ${e.message}`;case"kv_key_invalid":return`Invalid KV key: ${e.message}`;case"kv_value_invalid":return e.message;case"kv_value_too_large":return e.message;case"kv_not_available":return"Key-value store is not available in this environment";case"kv_call_failed":return`KV platform error: ${e.status} ${e.message}`;case"kv_requires_provisioning":return"Key-value store requires a provisioned project (run helix project set)";case"files_path_invalid":return`Invalid file path: ${e.message}`;case"files_value_invalid":return e.message;case"files_value_too_large":return e.message;case"files_not_available":return"File storage is not available in this environment";case"files_call_failed":return`Files platform error: ${e.status} ${e.message}`;case"files_requires_provisioning":return"File storage requires a provisioned project (run helix project set)"}}export{k as a,v as b,_ as c,y as d,E as e,b as f,c as g,f as h,h as i,w as j,x as k,a as l,N as m};