@urun-sh/openai 0.6.19 → 0.6.21

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,7 +1,7 @@
1
1
  import { Server } from 'node:http';
2
2
  import * as _prometheus_io_client from '@prometheus-io/client';
3
3
  import { Registry } from '@prometheus-io/client';
4
- import { c as LedgerOutcome, I as InferenceRecord, S as SessionGoneError, P as ProxyClients, M as ModelRouter, i as UsageRowReporter, b as InferenceUsageRecord, e as LedgerWrite, d as LedgerRecorded, L as LedgerFailure } from '../responses-turn-B91w2YKn.cjs';
4
+ import { c as LedgerOutcome, I as InferenceRecord, S as SessionGoneError, P as ProxyClients, M as ModelRouter, i as UsageRowReporter, b as InferenceUsageRecord, e as LedgerWrite, d as LedgerRecorded, L as LedgerFailure } from '../responses-turn-Cb1qQBA7.cjs';
5
5
  import { createClientToken } from '@urun-sh/core';
6
6
  import { U as UrunResponses } from '../ResponsesClient-_OZERUjH.cjs';
7
7
  import { b as UrunSessionLike } from '../types-CHPtJx6d.cjs';
@@ -419,12 +419,13 @@ type PoolEntry = {
419
419
  * 1. Nothing here is authoritative. A replica's tenant map is a CACHE of
420
420
  * backhauls it happens to have open; a cold replica rebuilds it from the
421
421
  * caller's key on the first request. Losing it changes no answer.
422
- * 2. Replicas converge on the platform's OWN dedupe rather than on a
423
- * registry of ours: client tokens are minted with a STABLE `subject`
424
- * derived from the key, and the platform dedupes sessions per
425
- * (org, actor, app, function) — so replica A and replica B dialing the
426
- * same (key, app) coalesce onto ONE platform session. That is the
427
- * library's own mechanism doing the sharding.
422
+ * 2. Every pool entry mints the SDK default credential — a fresh random
423
+ * subject per token — so a dial is a FRESH platform session owned by
424
+ * that dial alone. There is nothing to coalesce across replicas, and
425
+ * no pinned name for one replica's actor to collide with another's
426
+ * (`session_name_not_yours`, owner ruling 2026-10-01). The pool's
427
+ * bounded/reuse semantics live per process; cross-replica coalescing
428
+ * is NOT a pool property.
428
429
  * The yjs/valkey state plane in urun-infra#1490 §7 is therefore NOT built
429
430
  * here, and is not silently missing either — it is unnecessary for this
430
431
  * phase's correctness and is called out as such in the PR.
@@ -458,24 +459,6 @@ interface TenantRegistryOptions {
458
459
  apiUrl: string;
459
460
  /** The model-catalog oracle for routing rule 5, or null. */
460
461
  catalog: CatalogConfig | null;
461
- /**
462
- * THE STATELESS DIRECT PATH (urun-ts #497): present ⇒ every tenant's
463
- * clients carry a per-caller decision dial — discovery over the CALLER'S
464
- * own key (`GET {apiUrl}/runtimes`), tokens minted with the caller's
465
- * org/app/fn, the flat body POSTed to the ready runtime's `:8099/v1/decision`.
466
- * `shared` (the shared org's API key, when mounted) extends the same dial
467
- * to SHARED-catalog models: discovery under the shared key, the token's
468
- * `tenant` stays the caller and `provider` names the pod org from the
469
- * block's `shared_org_id` (the intake's provider-aware org gate). Absent
470
- * ⇒ shared models keep the session dial. Absent ⇒ no dial exists and every
471
- * decision rides the session lane byte-for-byte.
472
- */
473
- decisionIntake?: {
474
- secret: string;
475
- shared?: {
476
- apiKey: string;
477
- };
478
- };
479
462
  /** Injected in tests; production builds real uRun backhauls. */
480
463
  build?: (caller: CallerIdentity) => {
481
464
  router: ModelRouter<PoolEntry>;
@@ -921,39 +904,6 @@ interface HostedConfig {
921
904
  apiUrl: string;
922
905
  /** The `model_catalog` oracle for routing rule 5, or null when unconfigured. */
923
906
  catalog: CatalogConfig | null;
924
- /**
925
- * THE STATELESS DIRECT PATH's credential (URUN_SESSION_TOKEN_SECRET) — the
926
- * runtime scoped-token signing secret the decision intake verifies
927
- * (urun-python decision_intake). A SECRET input, not a behavior knob: it is
928
- * the mandate's allowed env class, and it is the SAME predicate the local
929
- * lane enables on (cli.ts statelessDialEnabled), so the two lanes can never
930
- * disagree. Absent ('') the stateless lane does not exist and every
931
- * decision rides the session lane byte-for-byte. Present, decisions for
932
- * CALLER-ORG serves="openai" apps dispatch straight to a ready runtime's
933
- * `:8099/v1/decision`: discovery rides the CALLER'S OWN key
934
- * (`GET {apiUrl}/runtimes`), and the per-decision token is minted with the
935
- * caller's org/app/fn identity. Shared-catalog models keep the session
936
- * dial — the v1 boundary #497 declares (the dial's own targetFor refuses
937
- * them).
938
- *
939
- * OPTIONAL on this bag because legacy constructors may omit it
940
- * (resolveHostedConfig always supplies it — '' when the env is absent);
941
- * consumers read it as `?? ''`.
942
- */
943
- decisionSecret?: string;
944
- /**
945
- * THE SHARED LANE'S credential (URUN_SHARED_ORG_API_KEY): the shared org's
946
- * API key, so the decision dial can discover — and its tokens can name via
947
- * the block's `shared_org_id` — the SHARED org's pods. Optional: absent ⇒
948
- * shared models keep the session dial (the stateless boundary narrows to
949
- * "no shared credential mounted"). URUN_SHARED_ORG_ID must ride WITH it
950
- * (both-or-neither, loud) purely as the identity statement of the key —
951
- * the dial never re-spells the pod org; it reads `shared_org_id` from the
952
- * block that resolved the lane, so key and pod org cannot drift.
953
- */
954
- sharedOrgKey?: string;
955
- /** Identity statement accompanying `sharedOrgKey` (URUN_SHARED_ORG_ID). */
956
- sharedOrgId?: string;
957
907
  }
958
908
  /**
959
909
  * Read and VALIDATE the deployment's external inputs. Every failure is loud
@@ -1092,9 +1042,9 @@ declare function createHostedProxy(options: HostedProxyOptions): {
1092
1042
  */
1093
1043
  edgeIdentityServer: Server;
1094
1044
  /**
1095
- * The tenant registry this proxy built (production wiring). Tests assert
1096
- * the per-caller stateless dial through it; production code goes through
1097
- * `callerOf`, never here.
1045
+ * The tenant registry this proxy built (production wiring). Also the ops
1046
+ * surface for the tenant count. Production code goes through `callerOf`,
1047
+ * never here.
1098
1048
  */
1099
1049
  registry: TenantRegistry;
1100
1050
  closeAll: () => Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { Server } from 'node:http';
2
2
  import * as _prometheus_io_client from '@prometheus-io/client';
3
3
  import { Registry } from '@prometheus-io/client';
4
- import { c as LedgerOutcome, I as InferenceRecord, S as SessionGoneError, P as ProxyClients, M as ModelRouter, i as UsageRowReporter, b as InferenceUsageRecord, e as LedgerWrite, d as LedgerRecorded, L as LedgerFailure } from '../responses-turn-FcEDaymF.js';
4
+ import { c as LedgerOutcome, I as InferenceRecord, S as SessionGoneError, P as ProxyClients, M as ModelRouter, i as UsageRowReporter, b as InferenceUsageRecord, e as LedgerWrite, d as LedgerRecorded, L as LedgerFailure } from '../responses-turn-DmzWIpmO.js';
5
5
  import { createClientToken } from '@urun-sh/core';
6
6
  import { U as UrunResponses } from '../ResponsesClient-CSSrOYD8.js';
7
7
  import { b as UrunSessionLike } from '../types-CHPtJx6d.js';
@@ -152,13 +152,6 @@ interface TenantRegistryOptions {
152
152
 
153
153
  catalog: CatalogConfig | null;
154
154
 
155
- decisionIntake?: {
156
- secret: string;
157
- shared?: {
158
- apiKey: string;
159
- };
160
- };
161
-
162
155
  build?: (caller: CallerIdentity) => {
163
156
  router: ModelRouter<PoolEntry>;
164
157
  clients: ProxyClients;
@@ -300,12 +293,6 @@ interface HostedConfig {
300
293
  apiUrl: string;
301
294
 
302
295
  catalog: CatalogConfig | null;
303
-
304
- decisionSecret?: string;
305
-
306
- sharedOrgKey?: string;
307
-
308
- sharedOrgId?: string;
309
296
  }
310
297
 
311
298
  declare function resolveHostedConfig(env?: NodeJS.ProcessEnv): HostedConfig;
@@ -1 +1 @@
1
- import{A as x,B as v,C as m,D as y,E as B,F as H,G as P,H as u,I as G,J as U,K as F,L as X,M as Y,N as b,O as h,P as k,Q as K,R as V,S as j,T as W,U as q,a as r,b as o,c as t,d as E,e as n,f as _,g as a,h as T,i as O,j as i,k as s,l as I,m as p,n as A,o as R,p as S,q as N,r as C,s as D,t as L,u as M,v as d,w as f,x as l,y as c,z as g}from"../chunk-DR2ANRFC.js";import"../chunk-MLJ66LPI.js";import"../chunk-K23AZPI4.js";import"../chunk-7TOD3ORT.js";import"../chunk-76BZLCGT.js";import"../chunk-NYSZ3RGB.js";import"../chunk-3JWYIKHM.js";import"../chunk-6M5JK4YC.js";import"../chunk-7V2JKPIG.js";import{c as e}from"../chunk-YSFSRI3D.js";e();export{N as ANONYMOUS_KEY_ID,y as BIND_HOST,R as BUCKET_DOMAIN,O as BoundedLabel,f as ControlPlaneUnavailableError,X as ConversationBackhauls,F as ConversationCapacityError,v as DEFAULT_PORT,I as EDGE_IDENTITY_PORT,A as EDGE_KEY_FINGERPRINT_HEADER,p as EDGE_KEY_ID_HEADER,i as InferenceMetrics,Y as LEDGER_FUNCTION_PATH,b as LEDGER_WRITE_TIMEOUT_MS,V as LedgerClient,h as LedgerDuplicateError,k as LedgerSurfaceError,g as MAX_CACHED_KEYS,G as MAX_CONVERSATIONS,U as MAX_CONVERSATION_HANDLES,n as MAX_MODEL_LABELS,_ as MAX_ORG_LABELS,H as MAX_TENANTS,o as METRICS_PATH,r as METRICS_PORT,E as NO_MODEL_LABEL,c as ORG_BINDING_TTL_MS,t as OTHER_LABEL,x as OrgResolver,d as ProxyAuthError,W as READINESS_TIMEOUT_MS,j as READINESS_TTL_MS,m as SERVE_FUNCTION,S as TIER_DOMAIN,u as TenantRegistry,l as bearerFrom,L as bearerTokenOf,M as createEdgeIdentityServer,q as createHostedProxy,s as createMetricsServer,C as edgeBucketId,D as edgeTierFingerprint,a as laneOf,K as parseLedgerRecorded,B as resolveHostedConfig,T as statusClassOf,P as tenantSubject};
1
+ import{A as x,B as v,C as m,D as y,E as B,F as H,G as P,H as u,I as G,J as U,K as F,L as X,M as Y,N as b,O as h,P as k,Q as K,R as V,S as j,T as W,U as q,a as r,b as o,c as t,d as E,e as n,f as _,g as a,h as T,i as O,j as i,k as s,l as I,m as p,n as A,o as R,p as S,q as N,r as C,s as D,t as L,u as M,v as d,w as f,x as l,y as c,z as g}from"../chunk-CL3LVMNL.js";import"../chunk-7ZH2UHK6.js";import"../chunk-K23AZPI4.js";import"../chunk-5SBYFTBD.js";import"../chunk-76BZLCGT.js";import"../chunk-BAKPG5S3.js";import"../chunk-3JWYIKHM.js";import"../chunk-6M5JK4YC.js";import"../chunk-7V2JKPIG.js";import{c as e}from"../chunk-YSFSRI3D.js";e();export{N as ANONYMOUS_KEY_ID,y as BIND_HOST,R as BUCKET_DOMAIN,O as BoundedLabel,f as ControlPlaneUnavailableError,X as ConversationBackhauls,F as ConversationCapacityError,v as DEFAULT_PORT,I as EDGE_IDENTITY_PORT,A as EDGE_KEY_FINGERPRINT_HEADER,p as EDGE_KEY_ID_HEADER,i as InferenceMetrics,Y as LEDGER_FUNCTION_PATH,b as LEDGER_WRITE_TIMEOUT_MS,V as LedgerClient,h as LedgerDuplicateError,k as LedgerSurfaceError,g as MAX_CACHED_KEYS,G as MAX_CONVERSATIONS,U as MAX_CONVERSATION_HANDLES,n as MAX_MODEL_LABELS,_ as MAX_ORG_LABELS,H as MAX_TENANTS,o as METRICS_PATH,r as METRICS_PORT,E as NO_MODEL_LABEL,c as ORG_BINDING_TTL_MS,t as OTHER_LABEL,x as OrgResolver,d as ProxyAuthError,W as READINESS_TIMEOUT_MS,j as READINESS_TTL_MS,m as SERVE_FUNCTION,S as TIER_DOMAIN,u as TenantRegistry,l as bearerFrom,L as bearerTokenOf,M as createEdgeIdentityServer,q as createHostedProxy,s as createMetricsServer,C as edgeBucketId,D as edgeTierFingerprint,a as laneOf,K as parseLedgerRecorded,B as resolveHostedConfig,T as statusClassOf,P as tenantSubject};
@@ -1,4 +1,4 @@
1
- import{a as z}from"../chunk-76BZLCGT.js";import{e as W,h as Q}from"../chunk-NYSZ3RGB.js";import"../chunk-7V2JKPIG.js";import{c as C}from"../chunk-YSFSRI3D.js";C();import{createAssistantMessageEventStream as he}from"@earendil-works/pi-ai";import{mkdirSync as we,openSync as _e,writeSync as ke}from"fs";import{dirname as ve}from"path";C();import{appendFileSync as de,mkdirSync as pe}from"fs";import fe from"os";import{dirname as ge,join as me}from"path";import{format as ye}from"util";function J(t=fe.homedir()){return me(t,".urun","logs","pi-extension.log")}var V=!1;function te(t,e){let n=J();try{pe(ge(n),{recursive:!0}),de(n,`${new Date().toISOString()} [console.${t}] [urun] ${ye(...e)}
1
+ import{a as z}from"../chunk-76BZLCGT.js";import{e as W,h as Q}from"../chunk-BAKPG5S3.js";import"../chunk-7V2JKPIG.js";import{c as C}from"../chunk-YSFSRI3D.js";C();import{createAssistantMessageEventStream as he}from"@earendil-works/pi-ai";import{mkdirSync as we,openSync as _e,writeSync as ke}from"fs";import{dirname as ve}from"path";C();import{appendFileSync as de,mkdirSync as pe}from"fs";import fe from"os";import{dirname as ge,join as me}from"path";import{format as ye}from"util";function J(t=fe.homedir()){return me(t,".urun","logs","pi-extension.log")}var V=!1;function te(t,e){let n=J();try{pe(ge(n),{recursive:!0}),de(n,`${new Date().toISOString()} [console.${t}] [urun] ${ye(...e)}
2
2
  `)}catch(o){if(!V){V=!0;try{process.stderr.write(`[urun] pi-extension quiet console: cannot write ${n} (${String(o)}); further urun-side console output will be dropped
3
3
  `)}catch{}}}}var f=t=>(...e)=>te(t,e),j={log:f("log"),info:f("info"),warn:f("warn"),error:f("error"),debug:f("debug"),trace:f("trace"),dir:f("dir"),table:f("table"),group:f("group"),groupCollapsed:f("groupCollapsed"),groupEnd:f("groupEnd"),count:f("count"),countReset:f("countReset"),time:f("time"),timeLog:f("timeLog"),timeEnd:f("timeEnd"),assert:(t,...e)=>{t||te("assert",e.length>0?e:["Assertion failed"])}};function q(t){try{process.stderr.write(t)}catch{}}C();async function ne(t){let e=await Q(t),n=e.filter(o=>o.function_name===t.fnName&&o.deployment_status==="active").map(o=>o.app_slug);if(n.length===0)throw new Error(`urun pi extension: the org has no active deployed app exposing "${t.fnName}" (GET ${t.apiUrl}/apps returned ${e.length} app(s), none servable) \u2014 deploy one with \`urun serve <model>\` first`);return n.sort()}var ae="urun-serve",xe="serve",Re=131072,be=16384,oe=3,Te=42e4,Ee=6e4,re=2,Se=15e3;function Ae(t){let e=(t.URUN_API_KEY??"").trim();if(!e)throw new Error("urun pi extension: URUN_API_KEY is required \u2014 model discovery lists the org's deployed serve apps via the org API (URUN_JWT alone cannot list apps)");return{apiKey:e,apiUrl:(t.URUN_API_URL??"").trim()||W,fnName:(t.URUN_FUNCTION??"").trim()||xe}}function Ue(t){let e=(t.URUN_BASE_URL??"").trim(),n=(t.URUN_ORG_ID??"").trim();if(!e)throw new Error("urun pi extension: URUN_BASE_URL is required to open a session");if(/\/v1\/*$/.test(new URL(e).pathname))throw new Error(`urun pi extension: URUN_BASE_URL must be the session-gateway base (e.g. https://api.urun.sh), got ${e} \u2014 a trailing /v1 is the org API form (URUN_API_URL); session allocation 404s against it. Drop the /v1.`);if(!n)throw new Error("urun pi extension: URUN_ORG_ID is required to open a session");let o=(t.URUN_JWT??"").trim();if(o)return{baseUrl:e,orgId:n,auth:{lane:"jwt",jwt:o}};let s=(t.URUN_API_KEY??"").trim();if(!s)throw new Error("urun pi extension: URUN_JWT or URUN_API_KEY is required to open a session");let l=(t.URUN_GATEWAY_URL??"").trim()||void 0;return{baseUrl:e,orgId:n,auth:{lane:"api-key",apiKey:s,gatewayUrl:l}}}function Ie(t){let e=null;return n=>{e===null&&(we(ve(t),{recursive:!0}),e=_e(t,"a"));let o=n.detail?` ${JSON.stringify(n.detail)}`:"";ke(e,`${new Date().toISOString()} [${n.level}] [urun] ${n.message}${o}
4
4
  `)}}function Pe(t){let e=Ie(J());return async(n,o,s)=>{let{baseUrl:l,orgId:i,auth:p}=Ue(n),{App:k,createClientToken:a}=await t(),m=(p.lane==="jwt"?k(o,{baseUrl:l,orgId:i,jwt:p.jwt,diagnosticSink:e}):k(o,{baseUrl:l,orgId:i,diagnosticSink:e,getAccessToken:async()=>(await a(p.apiKey,{baseUrl:p.gatewayUrl,expiresIn:300,allowedFunctions:[`${o}/${s}`]})).token}))[s];if(typeof m!="function")throw new Error(`urun pi extension: app "${o}" has no function "${s}"`);let h=m();if(typeof h.end!="function")throw new Error(`urun pi extension: app "${o}" function "${s}" returned a session without end()`);let A=h.connect;return typeof A=="function"&&await A.call(h),h}}var Ce=Pe(async()=>{let{createRequire:t}=await import("module"),e=t(import.meta.url);if(typeof globalThis.RTCPeerConnection>"u")try{e.resolve("werift")}catch{throw new Error('urun pi extension: token streams require a WebRTC data channel, and this Node runtime has no RTCPeerConnection and no "werift" backend installed (@urun-sh/core\'s optional Node WebRTC backend \u2014 it was probably stripped by a --no-optional install). Install werift (`npm i werift`) and retry.')}return e("@urun-sh/core")});function Ne(t,e){try{return Promise.resolve(t.end()).then(()=>{},n=>e(n))}catch(n){return e(n),Promise.resolve()}}function $e(t){if(t?.hasUI===!1)return!0;if(t?.hasUI===!0)return!1;let e=process.argv.slice(2);if(e.includes("-p")||e.includes("--print"))return!0;let n=e.indexOf("--mode");return n!==-1&&(e[n+1]==="json"||e[n+1]==="rpc")?!0:!process.stdin.isTTY||!process.stdout.isTTY}function le(t,e){return`uRun: releasing the pooled "${t}" session failed \u2014 the backend session may stay allocated until the platform reclaims it: ${e instanceof Error?e.message:String(e)}`}var H=class{constructor(e,n,o,s=(l,i)=>j.warn(le(l,i))){this.open=e;this.env=n;this.fnName=o;this.onReleaseError=s}open;env;fnName;onReleaseError;pool=new Map;releasing=new Set;acquire(e){let n=this.pool.get(e);if(!n){let o=Promise.resolve(this.open(this.env,e,this.fnName)).then(s=>({session:s,responses:new z(s)}));n=o,this.pool.set(e,o),o.catch(()=>{this.pool.get(e)===o&&this.pool.delete(e)})}return n}evict(e){let n=this.pool.get(e);if(!n)return Promise.resolve();this.pool.delete(e);let o=n.then(s=>Ne(s.session,l=>this.onReleaseError(e,l)),()=>{});return this.releasing.add(o),o.then(()=>this.releasing.delete(o)),o}closeAll(){let e=[...this.pool.keys()].map(n=>this.evict(n));return Promise.all([...e,...this.releasing]).then(()=>{})}};function Le(t){let e=[];t.systemPrompt&&e.push({role:"system",content:t.systemPrompt});for(let n of t.messages){if(n.role==="toolResult"){e.push({type:"function_call_output",call_id:n.toolCallId,output:De(n.content)});continue}if(n.role==="assistant"&&Array.isArray(n.content)){let s="",l=()=>{s&&(e.push({role:"assistant",content:s}),s="")};for(let i of n.content)if(i.type==="text")s+=String(i.text??"");else if(i.type==="toolCall")l(),e.push({type:"function_call",call_id:String(i.id??""),name:String(i.name??""),arguments:JSON.stringify(i.arguments??{})});else{if(i.type==="thinking")continue;throw new Error(`urun pi extension: unsupported assistant content part "${String(i.type)}"`)}l();continue}let o=n.role==="assistant"?"assistant":"user";e.push({role:o,content:Me(n.content)})}return Oe(e)}function Oe(t){let e=[];for(let n of t){let o=e[e.length-1];o&&"role"in o&&"role"in n&&o.role===n.role?o.content=[o.content,n.content].filter(s=>s.length>0).join(`