@lelemon-ai/trace 0.0.0-stage → 0.12.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/LICENSE +21 -0
- package/README.md +1183 -2
- package/dist/anthropic.d.mts +25 -0
- package/dist/anthropic.d.ts +25 -0
- package/dist/anthropic.js +4 -0
- package/dist/anthropic.mjs +4 -0
- package/dist/bedrock.d.mts +25 -0
- package/dist/bedrock.d.ts +25 -0
- package/dist/bedrock.js +4 -0
- package/dist/bedrock.mjs +4 -0
- package/dist/capture-CC6pIfa4.d.mts +354 -0
- package/dist/capture-CC6pIfa4.d.ts +354 -0
- package/dist/express-BrfMWEVl.d.mts +67 -0
- package/dist/express-BrfMWEVl.d.ts +67 -0
- package/dist/express.d.mts +1 -0
- package/dist/express.d.ts +1 -0
- package/dist/express.js +3 -0
- package/dist/express.mjs +3 -0
- package/dist/gemini.d.mts +28 -0
- package/dist/gemini.d.ts +28 -0
- package/dist/gemini.js +4 -0
- package/dist/gemini.mjs +4 -0
- package/dist/google-genai.d.mts +31 -0
- package/dist/google-genai.d.ts +31 -0
- package/dist/google-genai.js +4 -0
- package/dist/google-genai.mjs +4 -0
- package/dist/hono-MTDbviM5.d.mts +80 -0
- package/dist/hono-MTDbviM5.d.ts +80 -0
- package/dist/hono.d.mts +1 -0
- package/dist/hono.d.ts +1 -0
- package/dist/hono.js +3 -0
- package/dist/hono.mjs +3 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +4 -0
- package/dist/index.mjs +4 -0
- package/dist/integrations.d.mts +4 -0
- package/dist/integrations.d.ts +4 -0
- package/dist/integrations.js +3 -0
- package/dist/integrations.mjs +3 -0
- package/dist/lambda-Drx54kXf.d.mts +79 -0
- package/dist/lambda-Drx54kXf.d.ts +79 -0
- package/dist/lambda.d.mts +1 -0
- package/dist/lambda.d.ts +1 -0
- package/dist/lambda.js +3 -0
- package/dist/lambda.mjs +3 -0
- package/dist/next-DONwf0f5.d.mts +100 -0
- package/dist/next-DONwf0f5.d.ts +100 -0
- package/dist/next.d.mts +1 -0
- package/dist/next.d.ts +1 -0
- package/dist/next.js +3 -0
- package/dist/next.mjs +3 -0
- package/dist/openai.d.mts +25 -0
- package/dist/openai.d.ts +25 -0
- package/dist/openai.js +4 -0
- package/dist/openai.mjs +4 -0
- package/dist/openrouter.d.mts +33 -0
- package/dist/openrouter.d.ts +33 -0
- package/dist/openrouter.js +4 -0
- package/dist/openrouter.mjs +4 -0
- package/package.json +173 -4
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hono Integration
|
|
3
|
+
*
|
|
4
|
+
* Middleware for Hono framework (Cloudflare Workers, Deno, Bun, Node.js).
|
|
5
|
+
* Uses executionCtx.waitUntil() when available for non-blocking flush.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { Hono } from 'hono';
|
|
9
|
+
* import { createMiddleware } from '@lelemon-ai/trace/hono';
|
|
10
|
+
*
|
|
11
|
+
* const app = new Hono();
|
|
12
|
+
* app.use(createMiddleware());
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Execution context for edge runtimes (Cloudflare Workers, Deno Deploy)
|
|
16
|
+
*/
|
|
17
|
+
interface ExecutionContext {
|
|
18
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
19
|
+
passThroughOnException(): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Minimal Hono context type (avoids requiring hono as dependency)
|
|
23
|
+
*/
|
|
24
|
+
interface HonoContext {
|
|
25
|
+
req: {
|
|
26
|
+
raw: Request;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
res: Response | undefined;
|
|
30
|
+
executionCtx?: ExecutionContext;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hono next function type
|
|
35
|
+
*/
|
|
36
|
+
type HonoNextFunction = () => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Hono middleware function type
|
|
39
|
+
*
|
|
40
|
+
* @param c - Hono context object
|
|
41
|
+
* @param next - Next function to continue middleware chain
|
|
42
|
+
*/
|
|
43
|
+
type HonoMiddleware = (c: HonoContext, next: HonoNextFunction) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Create Hono middleware for automatic trace flushing
|
|
46
|
+
*
|
|
47
|
+
* On Cloudflare Workers/Deno Deploy: uses executionCtx.waitUntil() for non-blocking flush
|
|
48
|
+
* On Node.js/Bun: flushes after response (fire-and-forget)
|
|
49
|
+
*
|
|
50
|
+
* @returns Hono middleware function
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* import { Hono } from 'hono';
|
|
54
|
+
* import { createMiddleware } from '@lelemon-ai/trace/hono';
|
|
55
|
+
*
|
|
56
|
+
* const app = new Hono();
|
|
57
|
+
*
|
|
58
|
+
* // Global middleware
|
|
59
|
+
* app.use(createMiddleware());
|
|
60
|
+
*
|
|
61
|
+
* app.post('/chat', async (c) => {
|
|
62
|
+
* const openai = observe(new OpenAI());
|
|
63
|
+
* const result = await openai.chat.completions.create({...});
|
|
64
|
+
* return c.json(result);
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* export default app;
|
|
68
|
+
*/
|
|
69
|
+
declare function createMiddleware(): HonoMiddleware;
|
|
70
|
+
|
|
71
|
+
type hono_ExecutionContext = ExecutionContext;
|
|
72
|
+
type hono_HonoContext = HonoContext;
|
|
73
|
+
type hono_HonoMiddleware = HonoMiddleware;
|
|
74
|
+
type hono_HonoNextFunction = HonoNextFunction;
|
|
75
|
+
declare const hono_createMiddleware: typeof createMiddleware;
|
|
76
|
+
declare namespace hono {
|
|
77
|
+
export { type hono_ExecutionContext as ExecutionContext, type hono_HonoContext as HonoContext, type hono_HonoMiddleware as HonoMiddleware, type hono_HonoNextFunction as HonoNextFunction, hono_createMiddleware as createMiddleware };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { type ExecutionContext as E, type HonoContext as H, type HonoNextFunction as a, type HonoMiddleware as b, createMiddleware as c, hono as h };
|
package/dist/hono.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { E as ExecutionContext, H as HonoContext, b as HonoMiddleware, a as HonoNextFunction, c as createMiddleware } from './hono-MTDbviM5.mjs';
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { E as ExecutionContext, H as HonoContext, b as HonoMiddleware, a as HonoNextFunction, c as createMiddleware } from './hono-MTDbviM5.js';
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
async function e(){}function s(){return async(t,i)=>{await i(),t.executionCtx?.waitUntil?t.executionCtx.waitUntil(e()):e().catch(()=>{});}}exports.createMiddleware=s;//# sourceMappingURL=hono.js.map
|
|
3
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/hono.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
async function e(){}function l(){return async(t,i)=>{await i(),t.executionCtx?.waitUntil?t.executionCtx.waitUntil(e()):e().catch(()=>{});}}export{l as createMiddleware};//# sourceMappingURL=hono.mjs.map
|
|
3
|
+
//# sourceMappingURL=hono.mjs.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { O as ObserveOptions } from './capture-CC6pIfa4.mjs';
|
|
2
|
+
export { C as CaptureSpanOptions, L as LelemonConfig, P as ProviderName, b as SDKTelemetry, S as ServiceConfig, h as SpanOptions, d as SpanType, j as StyleOptions, T as TraceContext, e as TraceOptions, c as captureSpan, f as flush, g as getTraceContext, i as init, a as isEnabled, s as span, t as trace } from './capture-CC6pIfa4.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Observe Function
|
|
6
|
+
*
|
|
7
|
+
* Main entry point for wrapping LLM clients with automatic tracing.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wrap an LLM client with automatic tracing
|
|
12
|
+
*
|
|
13
|
+
* @param client - OpenAI, Anthropic, or Bedrock client instance
|
|
14
|
+
* @param options - Optional context (sessionId, userId, etc.)
|
|
15
|
+
* @returns The wrapped client with the same type
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { observe } from '@lelemon-ai/trace';
|
|
19
|
+
* import OpenAI from 'openai';
|
|
20
|
+
*
|
|
21
|
+
* const openai = observe(new OpenAI());
|
|
22
|
+
*
|
|
23
|
+
* // All calls are now automatically traced
|
|
24
|
+
* const response = await openai.chat.completions.create({...});
|
|
25
|
+
*/
|
|
26
|
+
declare function observe<T>(client: T, options?: ObserveOptions): T;
|
|
27
|
+
/**
|
|
28
|
+
* Create a scoped observe function with preset context
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const observeWithSession = createObserve({
|
|
32
|
+
* sessionId: 'session-123',
|
|
33
|
+
* userId: 'user-456',
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const openai = observeWithSession(new OpenAI());
|
|
37
|
+
*/
|
|
38
|
+
declare function createObserve(defaultOptions: ObserveOptions): <T>(client: T, options?: ObserveOptions) => T;
|
|
39
|
+
|
|
40
|
+
export { ObserveOptions, createObserve, observe };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { O as ObserveOptions } from './capture-CC6pIfa4.js';
|
|
2
|
+
export { C as CaptureSpanOptions, L as LelemonConfig, P as ProviderName, b as SDKTelemetry, S as ServiceConfig, h as SpanOptions, d as SpanType, j as StyleOptions, T as TraceContext, e as TraceOptions, c as captureSpan, f as flush, g as getTraceContext, i as init, a as isEnabled, s as span, t as trace } from './capture-CC6pIfa4.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Observe Function
|
|
6
|
+
*
|
|
7
|
+
* Main entry point for wrapping LLM clients with automatic tracing.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wrap an LLM client with automatic tracing
|
|
12
|
+
*
|
|
13
|
+
* @param client - OpenAI, Anthropic, or Bedrock client instance
|
|
14
|
+
* @param options - Optional context (sessionId, userId, etc.)
|
|
15
|
+
* @returns The wrapped client with the same type
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { observe } from '@lelemon-ai/trace';
|
|
19
|
+
* import OpenAI from 'openai';
|
|
20
|
+
*
|
|
21
|
+
* const openai = observe(new OpenAI());
|
|
22
|
+
*
|
|
23
|
+
* // All calls are now automatically traced
|
|
24
|
+
* const response = await openai.chat.completions.create({...});
|
|
25
|
+
*/
|
|
26
|
+
declare function observe<T>(client: T, options?: ObserveOptions): T;
|
|
27
|
+
/**
|
|
28
|
+
* Create a scoped observe function with preset context
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const observeWithSession = createObserve({
|
|
32
|
+
* sessionId: 'session-123',
|
|
33
|
+
* userId: 'user-456',
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const openai = observeWithSession(new OpenAI());
|
|
37
|
+
*/
|
|
38
|
+
declare function createObserve(defaultOptions: ObserveOptions): <T>(client: T, options?: ObserveOptions) => T;
|
|
39
|
+
|
|
40
|
+
export { ObserveOptions, createObserve, observe };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var async_hooks=require('async_hooks');/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
var Z=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,t)=>(typeof require<"u"?require:n)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Fe=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var se=Fe((Ot,Ye)=>{Ye.exports={name:"@lelemon-ai/trace",version:"0.12.0",description:"Automatic LLM observability. Wrap your client, everything is traced.",author:"Lelemon <info@lelemon.dev>",license:"MIT",repository:{type:"git",url:"git+https://github.com/Lelemon-studio/lelemondev-sdk.git"},homepage:"https://lelemon.dev",bugs:{url:"https://github.com/Lelemon-studio/lelemondev-sdk/issues"},keywords:["llm","observability","tracing","openai","anthropic","nextjs","lambda","express","hono","claude","gpt","ai","monitoring","serverless"],main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.js"},"./openai":{types:"./dist/openai.d.ts",import:"./dist/openai.mjs",require:"./dist/openai.js"},"./anthropic":{types:"./dist/anthropic.d.ts",import:"./dist/anthropic.mjs",require:"./dist/anthropic.js"},"./bedrock":{types:"./dist/bedrock.d.ts",import:"./dist/bedrock.mjs",require:"./dist/bedrock.js"},"./gemini":{types:"./dist/gemini.d.ts",import:"./dist/gemini.mjs",require:"./dist/gemini.js"},"./google-genai":{types:"./dist/google-genai.d.ts",import:"./dist/google-genai.mjs",require:"./dist/google-genai.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.mjs",require:"./dist/openrouter.js"},"./next":{types:"./dist/next.d.ts",import:"./dist/next.mjs",require:"./dist/next.js"},"./lambda":{types:"./dist/lambda.d.ts",import:"./dist/lambda.mjs",require:"./dist/lambda.js"},"./express":{types:"./dist/express.d.ts",import:"./dist/express.mjs",require:"./dist/express.js"},"./hono":{types:"./dist/hono.d.ts",import:"./dist/hono.mjs",require:"./dist/hono.js"},"./integrations":{types:"./dist/integrations.d.ts",import:"./dist/integrations.mjs",require:"./dist/integrations.js"},"./package.json":"./package.json"},typesVersions:{"*":{openai:["./dist/openai.d.ts"],anthropic:["./dist/anthropic.d.ts"],bedrock:["./dist/bedrock.d.ts"],gemini:["./dist/gemini.d.ts"],"google-genai":["./dist/google-genai.d.ts"],openrouter:["./dist/openrouter.d.ts"],next:["./dist/next.d.ts"],lambda:["./dist/lambda.d.ts"],express:["./dist/express.d.ts"],hono:["./dist/hono.d.ts"],integrations:["./dist/integrations.d.ts"],"*":["./dist/index.d.ts"]}},files:["dist/**/*.js","dist/**/*.mjs","dist/**/*.d.ts","dist/**/*.d.mts","README.md"],sideEffects:false,engines:{node:">=18.0.0"},scripts:{build:"tsup",dev:"tsup --watch",docs:"typedoc && node scripts/generate-llms-txt.mjs",prepublishOnly:"npm run build",lint:"eslint src/",test:"vitest","test:run":"vitest run","test:coverage":"vitest run --coverage","test:e2e":"vitest run tests/e2e",typecheck:"tsc --noEmit"},devDependencies:{"@anthropic-ai/sdk":"^0.82.0","@aws-sdk/client-bedrock-runtime":"^3.962.0","@google/genai":"^1.0.0","@google/generative-ai":"^0.24.1","@types/node":"^22.0.0","@vitest/coverage-v8":"^4.0.0",dotenv:"^17.2.3",openai:"^6.15.0",tsup:"^8.5.1",typedoc:"^0.28.18",typescript:"^6.0.0",vite:"^6.0.0",vitest:"^4.0.0"}};});var X=false;function Q(e){X=e;}function I(){return X?true:ze("LELEMON_DEBUG")==="true"}var C="[Lelemon]";function k(e,n){I()&&J("debug",e,n);}function L(e,n){I()&&J("info",e,n);}function G(e,n){J("warn",e,n);}function K(e,n,t,o){I()&&console.log(`${C} Captured trace: provider=${e} model=${n} duration=${t}ms status=${o}`);}function N(e,n){console.error(`${C} Failed to capture trace: provider=${e} error=${n.message}`);}function O(e){I()&&console.log(`${C} Wrapped client: provider=${e}`);}function ee(e,n){I()&&console.log(`${C} Sending batch: count=${e} endpoint=${n}`);}function ne(e,n){I()&&console.log(`${C} Batch sent successfully: count=${e} duration=${n}ms`);}function te(e,n){let t=n instanceof Error?n.message:String(n);console.error(`${C} Batch send failed: count=${e} error=${t}`);}function re(e,n,t){I()&&console.log(`${C} Request: ${e} ${n} (${t} bytes)`);}function oe(e,n){I()&&console.log(`${C} Response: status=${e} duration=${n}ms`);}function J(e,n,t){let o=e==="error"?console.error:e==="warn"?console.warn:console.log;t!==void 0?o(`${C} ${n}`,t):o(`${C} ${n}`);}function ze(e){if(typeof process<"u"&&process.env)return process.env[e]}var Ve=10,He=1e3,We=1e4,j=class{config;queue=[];flushPromise=null;flushTimer=null;constructor(n){this.config={apiKey:n.apiKey,endpoint:n.endpoint,debug:n.debug,disabled:n.disabled,batchSize:n.batchSize??Ve,flushIntervalMs:n.flushIntervalMs??He,requestTimeoutMs:n.requestTimeoutMs??We};}isEnabled(){return !this.config.disabled&&!!this.config.apiKey}enqueue(n){this.config.disabled||(this.queue.push(n),this.queue.length>=this.config.batchSize?this.flush():this.scheduleFlush());}async flush(){if(this.flushPromise)return this.flushPromise;if(this.queue.length===0)return;this.cancelScheduledFlush();let n=this.queue;return this.queue=[],this.flushPromise=this.sendBatch(n).finally(()=>{this.flushPromise=null;}),this.flushPromise}getPendingCount(){return this.queue.length}scheduleFlush(){this.flushTimer===null&&(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush();},this.config.flushIntervalMs));}cancelScheduledFlush(){this.flushTimer!==null&&(clearTimeout(this.flushTimer),this.flushTimer=null);}async sendBatch(n){if(n.length===0)return;let t=Date.now();ee(n.length,`${this.config.endpoint}/api/v1/ingest`);try{await this.request("POST","/api/v1/ingest",{events:n}),ne(n.length,Date.now()-t);}catch(o){te(n.length,o);}}async request(n,t,o){let s=`${this.config.endpoint}${t}`,r=new AbortController,a=o?JSON.stringify(o):void 0;re(n,s,a?.length??0);let i=setTimeout(()=>{r.abort();},this.config.requestTimeoutMs),d=Date.now();try{let c=await fetch(s,{method:n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:a,signal:r.signal});if(clearTimeout(i),oe(c.status,Date.now()-d),!c.ok){let l=await c.text().catch(()=>"Unknown error");throw new Error(`HTTP ${c.status}: ${l}`)}let u=await c.text();return u?JSON.parse(u):{}}catch(c){throw clearTimeout(i),c instanceof Error&&c.name==="AbortError"?new Error(`Request timeout after ${this.config.requestTimeoutMs}ms`):c}}};var Ze="@lelemon-ai/trace",Xe="nodejs";function Qe(){return typeof process<"u"&&process.versions?.node?{name:"nodejs",version:process.versions.node}:typeof Deno<"u"?{name:"deno",version:Deno.version?.deno??"unknown"}:typeof Bun<"u"?{name:"bun",version:Bun.version??"unknown"}:typeof window<"u"&&typeof navigator<"u"?{name:"browser",version:navigator.userAgent}:null}function en(){if(typeof process<"u"&&process.platform){let e=process.platform;switch(e){case "darwin":return "darwin";case "win32":return "windows";case "linux":return "linux";default:return e}}if(typeof navigator<"u"){let e=navigator.userAgent.toLowerCase();if(e.includes("mac"))return "darwin";if(e.includes("win"))return "windows";if(e.includes("linux"))return "linux"}return null}function nn(){try{if(typeof Z<"u")return se().version??"unknown"}catch{}return "unknown"}var x=null;function ie(e){if(!x){let t=Qe(),o=en();x={"telemetry.sdk.name":Ze,"telemetry.sdk.version":nn(),"telemetry.sdk.language":Xe},t&&(x["process.runtime.name"]=t.name,x["process.runtime.version"]=t.version),o&&(x["os.type"]=o);}let n={...x};return e?.name&&(n["service.name"]=e.name),e?.version&&(n["service.version"]=e.version),e?.environment&&(n["deployment.environment"]=e.environment),n}var z={},M=null,F=null,ue="https://api.lelemon.dev";function rn(e={}){z=e,e.debug&&Q(true),F=ie(e.service),L("Initializing SDK",{endpoint:e.endpoint??ue,debug:e.debug??false,disabled:e.disabled??false,telemetry:F}),M=ce(e),M.isEnabled()?L("SDK initialized - tracing enabled"):k("SDK initialized - tracing disabled (no API key or explicitly disabled)");}function B(){return z}function U(){return F}function on(){return E().isEnabled()}function E(){return M||(M=ce(z)),M}async function sn(){M&&await M.flush();}function ce(e){let n=e.apiKey??an("LELEMON_API_KEY");return !n&&!e.disabled&&G("No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled."),new j({apiKey:n??"",endpoint:e.endpoint??ue,debug:e.debug??false,disabled:e.disabled??!n,batchSize:e.batchSize,flushIntervalMs:e.flushIntervalMs,requestTimeoutMs:e.requestTimeoutMs})}function an(e){if(typeof process<"u"&&process.env)return process.env[e]}function g(e){try{let n=E();if(!n.isEnabled()){k("Transport disabled, skipping trace capture");return}let t=e.context??{},o=v(),s=P(),r=U(),a={provider:e.provider,model:e.model,input:H(e.input),rawResponse:e.rawResponse?A(e.rawResponse,0):void 0,durationMs:e.durationMs,status:e.status,streaming:e.streaming,firstTokenMs:e.firstTokenMs,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:o?.traceId,spanId:s,parentSpanId:o?.currentSpanId,metadata:{...t.metadata,...e.metadata,...o?{_traceName:o.name}:{},...r?{_telemetry:r}:{}},tags:t.tags??o?.tags,spanType:e.spanType,name:e.name};return K(e.provider,e.model,e.durationMs,e.status),n.enqueue(a),s}catch(n){N(e.provider,n instanceof Error?n:new Error(String(n)));return}}function m(e){try{let n=E();if(!n.isEnabled()){k("Transport disabled, skipping error capture");return}let t=e.context??{},o=v(),s=U(),r={provider:e.provider,model:e.model,input:H(e.input),durationMs:e.durationMs,status:"error",errorMessage:e.error.message,streaming:e.streaming,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:o?.traceId,spanId:P(),parentSpanId:o?.currentSpanId,metadata:{...t.metadata,...e.metadata,...o?{_traceName:o.name}:{},...s?{_telemetry:s}:{}},tags:t.tags??o?.tags};K(e.provider,e.model,e.durationMs,"error"),k("Error details",{message:e.error.message,stack:e.error.stack}),n.enqueue(r);}catch(n){N(e.provider,n instanceof Error?n:new Error(String(n)));}}function V(e){try{let n=E();if(!n.isEnabled()){k("Transport disabled, skipping span capture");return}let t=e.context??{},o=v(),s=e.metadata?._traceId,r=e.metadata?._parentSpanId,a=U(),i={...t.metadata,...e.metadata,...a?{_telemetry:a}:{}};delete i._traceId,delete i._parentSpanId;let d={spanType:e.type,name:e.name,provider:"unknown",model:e.name,input:H(e.input),output:A(e.output,0),durationMs:e.durationMs,status:e.status||"success",errorMessage:e.errorMessage,streaming:!1,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:s??o?.traceId,spanId:P(),parentSpanId:r??o?.currentSpanId,toolCallId:e.toolCallId,metadata:i,tags:t.tags??o?.tags};k(`Span captured: ${e.type}/${e.name}`,{durationMs:e.durationMs}),n.enqueue(d);}catch(n){N("unknown",n instanceof Error?n:new Error(String(n)));}}var de=1e5,un=["api_key","apikey","password","secret","authorization"],cn=["access_token","auth_token","bearer_token","refresh_token","id_token","session_token"],dn=["inputtokens","outputtokens","totaltokens","prompttokens","completiontokens","cachereadtokens","cachewritetokens","cachereadinputtokens","cachewriteinputtokens","reasoningtokens"],le={emails:/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,phones:/\b\d{9,}\b/g};function pe(){return B().redaction??{}}function ln(e){let n=e.toLowerCase();return dn.includes(n)?false:!!(un.some(o=>n.includes(o))||cn.some(o=>n.includes(o))||(pe().keys??[]).some(o=>n.includes(o.toLowerCase())))}function pn(e){let n=pe(),t=e;for(let o of n.patterns??[])o.lastIndex=0,t=t.replace(o,"[REDACTED]");return n.emails&&(t=t.replace(le.emails,"[EMAIL]")),n.phones&&(t=t.replace(le.phones,"[PHONE]")),t}function H(e){return A(e,0)}function A(e,n){if(n>10)return "[max depth exceeded]";if(e==null)return e;if(typeof e=="string"){let t=pn(e);return t.length>de&&(t=t.slice(0,de)+"...[truncated]"),t}if(typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(t=>A(t,n+1));if(typeof e=="object"){let t={};for(let[o,s]of Object.entries(e))ln(o)?t[o]="[REDACTED]":t[o]=A(s,n+1);return t}return String(e)}var W=Symbol.for("@lelemondev/sdk:traceStorage");function mn(){let e=globalThis;return e[W]||(e[W]=new async_hooks.AsyncLocalStorage),e[W]}var fe=mn();function P(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}`}function v(){return fe.getStore()}function w(e,n){let t=v();if(t)for(let o of e)t.pendingToolCalls.set(o,n),k(`Registered tool call ${o} \u2192 LLM span ${n}`);}function gn(e){let n=v();if(n)return e&&n.pendingToolCalls.has(e)?n.pendingToolCalls.get(e):n.currentSpanId}function wn(e){let n=v();n&&n.pendingToolCalls.delete(e);}async function yn(e,n){let t=typeof e=="string"?{name:e}:e,o=v(),s=o?.traceId??P(),r=P(),a={traceId:s,rootSpanId:r,currentSpanId:r,parentSpanId:o?.currentSpanId,name:t.name,startTime:Date.now(),input:t.input,metadata:t.metadata,tags:t.tags,outputKey:t.outputKey,outputTransform:t.outputTransform,sessionId:t.sessionId,userId:t.userId,style:t.style,pendingToolCalls:new Map};return fe.run(a,async()=>{let i,d;try{return i=await n(),i}catch(c){throw d=c instanceof Error?c:new Error(String(c)),c}finally{bn(a,d?void 0:i,d);}})}var kn=["text","content","message","output","response","result","answer"];function hn(e,n,t){if(t)try{return t(e)}catch{return e}if(n===false)return e;if(typeof n=="string"&&e&&typeof e=="object"){let s=e;return n in s?s[n]:e}if(e==null||typeof e!="object"||Array.isArray(e))return e;let o=e;for(let s of kn)if(s in o&&typeof o[s]=="string")return o[s];return e}function bn(e,n,t){let o=E();if(!o.isEnabled()){k("Transport disabled, skipping root span");return}let s=Date.now()-e.startTime,r=t?null:hn(n,e.outputKey,e.outputTransform),a={spanType:"agent",name:e.name,provider:"agent",model:e.name,traceId:e.traceId,spanId:e.rootSpanId,parentSpanId:e.parentSpanId,input:e.input,output:r,inputTokens:0,outputTokens:0,durationMs:s,status:t?"error":"success",errorMessage:t?.message,streaming:false,sessionId:e.sessionId,userId:e.userId,metadata:{...e.metadata,...e.style?{_style:e.style}:{}},tags:e.tags};k(`Sending root span: ${e.name}`,{durationMs:s,hasError:!!t}),o.enqueue(a);}function Cn(e){let n=v();if(!n){process.env.NODE_ENV!=="production"&&console.warn("[Lelemon] span() called outside of trace() - span will not be captured");return}let t=gn(e.toolCallId);V({type:e.type,name:e.name,input:e.input,output:e.output,durationMs:e.durationMs??0,status:e.status??"success",errorMessage:e.errorMessage,toolCallId:e.toolCallId,metadata:{...e.metadata,_traceId:n.traceId,_parentSpanId:t,...e.style?{_style:e.style}:{}}}),e.toolCallId&&wn(e.toolCallId);}var b="openai";function me(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="OpenAI")return true;let t=e;return !!(t.chat&&t.completions)||!!t.responses}function ge(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&we(i))return vn(i,r,s,n);let d=Date.now()-s,c=i,u=g({provider:b,model:r.model||c.model||"unknown",input:r.messages,rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n});if(u){let l=be(c);l.length>0&&w(l,u);}return i}catch(i){let d=Date.now()-s;throw m({provider:b,model:r.model||"unknown",input:r.messages,error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function we(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}async function*vn(e,n,t,o){let s={choices:[{message:{content:"",tool_calls:[]},finish_reason:""}],usage:{prompt_tokens:0,completion_tokens:0}},r=null,a,i=false,d=new Map;try{for await(let c of e){let u=c,l=u?.choices?.[0]?.delta?.content;l&&(i||(i=!0,a=Date.now()-t),s.choices[0].message.content+=l);let p=u?.choices?.[0]?.delta?.tool_calls;if(p)for(let y of p){d.has(y.index)||d.set(y.index,{id:"",function:{name:"",arguments:""}});let $=d.get(y.index);y.id&&($.id=y.id),y.function?.name&&($.function.name=y.function.name),y.function?.arguments&&($.function.arguments+=y.function.arguments);}let f=u?.choices?.[0]?.finish_reason;f&&(s.choices[0].finish_reason=f),u?.usage&&(s.usage=u.usage),yield c;}}catch(c){throw r=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-t;if(d.size>0&&(s.choices[0].message.tool_calls=Array.from(d.entries()).sort((u,l)=>u[0]-l[0]).map(([,u])=>u)),r)m({provider:b,model:n.model||"unknown",input:n.messages,error:r,durationMs:c,streaming:true,context:o});else {let u=g({provider:b,model:n.model||"unknown",input:n.messages,rawResponse:s,durationMs:c,status:"success",streaming:true,firstTokenMs:a,context:o});if(u){let l=be(s);l.length>0&&w(l,u);}}}}function ye(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&we(i))return Sn(i,r,s,n);let d=Date.now()-s;return g({provider:b,model:r.model||"unknown",input:{instructions:r.instructions,input:r.input},rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n}),i}catch(i){let d=Date.now()-s;throw m({provider:b,model:r.model||"unknown",input:{instructions:r.instructions,input:r.input},error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}async function*Sn(e,n,t,o){let s=[],r=null,a=null;try{for await(let i of e){s.push(i);let d=i;d.type==="response.done"&&d.response&&(r=d.response),yield i;}}catch(i){throw a=i instanceof Error?i:new Error(String(i)),i}finally{let i=Date.now()-t;a?m({provider:b,model:n.model||"unknown",input:{instructions:n.instructions,input:n.input},error:a,durationMs:i,streaming:true,context:o}):g({provider:b,model:n.model||"unknown",input:{instructions:n.instructions,input:n.input},rawResponse:r||{streamEvents:s},durationMs:i,status:"success",streaming:true,context:o});}}function ke(e,n){return async function(...o){let s=Date.now(),r=o[0]||{};try{let a=await e(...o),i=Date.now()-s;return g({provider:b,model:r.model||"unknown",input:r.prompt,rawResponse:a,durationMs:i,status:"success",streaming:!1,context:n}),a}catch(a){let i=Date.now()-s;throw m({provider:b,model:r.model||"unknown",input:r.prompt,error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:false,context:n}),a}}}function he(e,n){return async function(...o){let s=Date.now(),r=o[0]||{};try{let a=await e(...o),i=Date.now()-s;return g({provider:b,model:r.model||"unknown",input:r.input,rawResponse:a,durationMs:i,status:"success",streaming:!1,spanType:"embedding",context:n}),a}catch(a){let i=Date.now()-s;throw m({provider:b,model:r.model||"unknown",input:r.input,error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:false,context:n}),a}}}function be(e){let n=[],t=e.choices?.[0]?.message?.tool_calls;if(Array.isArray(t))for(let o of t)o.id&&n.push(o.id);return n}var _="anthropic";function Ce(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="Anthropic")return true;let t=e;return !!(t.messages&&typeof t.messages=="object")}function ve(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&Rn(i))return On(i,r,s,n);let d=Date.now()-s,c=i,u=g({provider:_,model:r.model||c.model||"unknown",input:{system:r.system,messages:r.messages},rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n});if(u&&c.content){let l=Y(c.content);l.length>0&&w(l,u);}return i}catch(i){let d=Date.now()-s;throw m({provider:_,model:r.model||"unknown",input:{system:r.system,messages:r.messages},error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function Se(e,n){return function(...o){let s=Date.now(),r=o[0]||{};try{let a=e(...o);return a&&typeof a=="object"?Tn(a,r,s,n):a}catch(a){let i=Date.now()-s;throw m({provider:_,model:r.model||"unknown",input:{system:r.system,messages:r.messages},error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:true,context:n}),a}}}function Rn(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function Tn(e,n,t,o){let s=e;if(!s[Symbol.asyncIterator])return e;let r={content:[],usage:{input_tokens:0,output_tokens:0}},a=false,i,d=false,c=null,u=[],l=async function*(){try{for await(let p of s){if(p.type==="message_start"&&p.message&&(r.model=p.message.model,r.id=p.message.id,r.role=p.message.role,p.message.usage&&(r.usage={...p.message.usage})),p.type==="content_block_start"&&p.content_block&&(c=p.index??u.length,u[c]={...p.content_block},p.content_block.type==="text"&&(u[c].text=""),p.content_block.type==="thinking"&&(u[c].thinking="")),p.type==="content_block_delta"&&p.delta&&c!==null){let f=u[c];f&&(p.delta.text&&(d||(d=!0,i=Date.now()-t),f.type==="thinking"?f.thinking=(f.thinking||"")+p.delta.text:f.type==="text"&&(f.text=(f.text||"")+p.delta.text)),p.delta.partial_json&&f.type==="tool_use"&&(f._inputJson=(f._inputJson||"")+p.delta.partial_json));}if(p.type==="content_block_stop"&&c!==null){let f=u[c];if(f&&f.type==="tool_use"){let y=f._inputJson;if(y){try{f.input=JSON.parse(y);}catch{}delete f._inputJson;}}c=null;}p.type==="message_delta"&&(p.usage?.output_tokens&&(r.usage.output_tokens=p.usage.output_tokens),p.delta?.stop_reason&&(r.stop_reason=p.delta.stop_reason)),yield p;}}catch(p){if(!a){a=true;let f=Date.now()-t;m({provider:_,model:r.model||n.model||"unknown",input:{system:n.system,messages:n.messages},error:p instanceof Error?p:new Error(String(p)),durationMs:f,streaming:true,context:o});}throw p}finally{if(!a){a=true;let p=Date.now()-t;r.content=u.filter(Boolean);let f=g({provider:_,model:r.model||n.model||"unknown",input:{system:n.system,messages:n.messages},rawResponse:r,durationMs:p,status:"success",streaming:true,firstTokenMs:i,context:o});if(f&&r.content){let y=Y(r.content);y.length>0&&w(y,f);}}}};return new Proxy(e,{get(p,f,y){return f===Symbol.asyncIterator?()=>l()[Symbol.asyncIterator]():Reflect.get(p,f,y)}})}async function*On(e,n,t,o){let s={content:[],usage:{input_tokens:0,output_tokens:0}},r=null,a,i=false,d=null,c=[];try{for await(let u of e){if(u.type==="message_start"&&u.message&&(s.model=u.message.model,s.id=u.message.id,s.role=u.message.role,u.message.usage&&(s.usage={...u.message.usage})),u.type==="content_block_start"&&u.content_block&&(d=u.index??c.length,c[d]={...u.content_block},u.content_block.type==="text"&&(c[d].text=""),u.content_block.type==="thinking"&&(c[d].thinking="")),u.type==="content_block_delta"&&u.delta&&d!==null){let l=c[d];l&&(u.delta.text&&(i||(i=!0,a=Date.now()-t),l.type==="thinking"?l.thinking=(l.thinking||"")+u.delta.text:l.type==="text"&&(l.text=(l.text||"")+u.delta.text)),u.delta.partial_json&&l.type==="tool_use"&&(l._inputJson=(l._inputJson||"")+u.delta.partial_json));}if(u.type==="content_block_stop"&&d!==null){let l=c[d];if(l&&l.type==="tool_use"){let p=l._inputJson;if(p){try{l.input=JSON.parse(p);}catch{}delete l._inputJson;}}d=null;}u.type==="message_delta"&&(u.usage?.output_tokens&&(s.usage.output_tokens=u.usage.output_tokens),u.delta?.stop_reason&&(s.stop_reason=u.delta.stop_reason)),yield u;}}catch(u){throw r=u instanceof Error?u:new Error(String(u)),u}finally{let u=Date.now()-t;if(s.content=c.filter(Boolean),r)m({provider:_,model:s.model||n.model||"unknown",input:{system:n.system,messages:n.messages},error:r,durationMs:u,streaming:true,context:o});else {let l=g({provider:_,model:s.model||n.model||"unknown",input:{system:n.system,messages:n.messages},rawResponse:s,durationMs:u,status:"success",streaming:true,firstTokenMs:a,context:o});if(l&&s.content){let p=Y(s.content);p.length>0&&w(p,l);}}}}function Y(e){let n=[];for(let t of e)t.type==="tool_use"&&t.id&&n.push(t.id);return n}var S="bedrock";function Ie(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="BedrockRuntimeClient")return true;let t=e;return typeof t.send!="function"||!t.config||typeof t.config!="object"?false:"region"in t.config}function Re(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="send"&&typeof a=="function"?En(a.bind(o),n):a}})}function En(e,n){return async function(o){switch(o.constructor?.name||""){case "ConverseCommand":return _n(e,o,n);case "ConverseStreamCommand":return xn(e,o,n);case "InvokeModelCommand":return An(e,o,n);case "InvokeModelWithResponseStreamCommand":return Dn(e,o,n);default:return e(o)}}}async function _n(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n),a=Date.now()-o,i=g({provider:S,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},rawResponse:Te(r),durationMs:a,status:"success",streaming:!1,context:t});if(i){let d=Oe(r);d.length>0&&w(d,i);}return r}catch(r){throw m({provider:S,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:false,context:t}),r}}async function xn(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n);return r.stream?{...r,stream:Pn(r.stream,s,o,t)}:r}catch(r){throw m({provider:S,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:true,context:t}),r}}async function*Pn(e,n,t,o){let s={output:{message:{role:"assistant",content:[]}},usage:{inputTokens:0,outputTokens:0}},r=null,a,i=false,d=new Map,c=new Map;try{for await(let u of e){if(u.contentBlockStart){let l=u.contentBlockStart.contentBlockIndex;if(u.contentBlockStart.start?.toolUse){let p=u.contentBlockStart.start.toolUse;d.set(l,{toolUse:{toolUseId:p.toolUseId,name:p.name,input:{}}}),c.set(l,"");}else d.set(l,{text:""});}if(u.contentBlockDelta){let l=u.contentBlockDelta.contentBlockIndex,p=d.get(l);if(p&&u.contentBlockDelta.delta?.text&&(i||(i=!0,a=Date.now()-t),p.text=(p.text||"")+u.contentBlockDelta.delta.text),p?.toolUse&&u.contentBlockDelta.delta?.toolUse?.input){let f=c.get(l)||"";c.set(l,f+u.contentBlockDelta.delta.toolUse.input);}}if(u.contentBlockStop){let l=u.contentBlockStop.contentBlockIndex,p=d.get(l),f=c.get(l);if(p?.toolUse&&f)try{p.toolUse.input=JSON.parse(f);}catch{}}u.messageStop?.stopReason&&(s.stopReason=u.messageStop.stopReason),u.metadata?.usage&&(s.usage={inputTokens:u.metadata.usage.inputTokens||0,outputTokens:u.metadata.usage.outputTokens||0}),yield u;}}catch(u){throw r=u instanceof Error?u:new Error(String(u)),u}finally{let u=Date.now()-t,l=Array.from(d.entries()).sort((p,f)=>p[0]-f[0]).map(([,p])=>p);if(s.output.message.content=l,r)m({provider:S,model:n.modelId||"unknown",input:{system:n.system,messages:n.messages},error:r,durationMs:u,streaming:true,context:o});else {let p=g({provider:S,model:n.modelId||"unknown",input:{system:n.system,messages:n.messages},rawResponse:Te(s),durationMs:u,status:"success",streaming:true,firstTokenMs:a,context:o});if(p){let f=Oe(s);f.length>0&&w(f,p);}}}}async function An(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n),a=Date.now()-o,i=Nn(r.body);return g({provider:S,model:s.modelId||"unknown",input:D(s.body),rawResponse:i,durationMs:a,status:"success",streaming:!1,context:t}),r}catch(r){throw m({provider:S,model:s.modelId||"unknown",input:D(s.body),error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:false,context:t}),r}}async function Dn(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n);return r.body?{...r,body:Gn(r.body,s,o,t)}:r}catch(r){throw m({provider:S,model:s.modelId||"unknown",input:D(s.body),error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:true,context:t}),r}}async function*Gn(e,n,t,o){let s=[],r=null;try{for await(let a of e){if(a.chunk?.bytes){let i=jn(a.chunk.bytes);i&&s.push(i);}yield a;}}catch(a){throw r=a instanceof Error?a:new Error(String(a)),a}finally{let a=Date.now()-t;r?m({provider:S,model:n.modelId||"unknown",input:D(n.body),error:r,durationMs:a,streaming:true,context:o}):g({provider:S,model:n.modelId||"unknown",input:D(n.body),rawResponse:{streamEvents:s},durationMs:a,status:"success",streaming:true,context:o});}}function Te(e){try{return JSON.parse(JSON.stringify(e))}catch{return e}}function Oe(e){let n=[],t=e.output?.message?.content;if(Array.isArray(t))for(let o of t)o.toolUse?.toolUseId&&n.push(o.toolUse.toolUseId);return n}function D(e){try{let n=typeof e=="string"?e:new TextDecoder().decode(e);return JSON.parse(n)}catch{return e}}function Nn(e){try{let n=new TextDecoder().decode(e);return JSON.parse(n)}catch{return null}}function jn(e){try{let n=new TextDecoder().decode(e);return JSON.parse(n)}catch{return null}}var R="gemini";function Me(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="GoogleGenAI")return true;let t=e;return !!(t.models&&typeof t.models=="object"&&typeof t.models.generateContent=="function"&&t.chats&&typeof t.chats=="object")}function Ee(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="models"&&a&&typeof a=="object"?Un(a,n):s==="chats"&&a&&typeof a=="object"?Ln(a,n):a}})}function Un(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="generateContent"&&typeof r=="function"?qn(r.bind(t),n):o==="generateContentStream"&&typeof r=="function"?$n(r.bind(t),n):r}})}function qn(e,n){return async function(o){let s=Date.now(),r=o.model,a=xe(o);try{let i=await e(o),d=Date.now()-s,c=Pe(i),u=g({provider:R,model:r,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:n});if(u){let l=Ae(i);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:R,model:r,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-s,streaming:false,context:n}),i}}}function $n(e,n){return async function(o){let s=Date.now(),r=o.model,a=xe(o);try{let i=await e(o);return _e(i,r,a,s,n)}catch(i){throw m({provider:R,model:r,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-s,streaming:true,context:n}),i}}}async function*_e(e,n,t,o,s){let r={candidates:[{content:{parts:[]}}]},a=null,i,d=false;try{for await(let c of e){let u=c.text;if(u){d||(d=!0,i=Date.now()-o);let l=r.candidates[0].content?.parts||[],p=l[l.length-1];p?.text!==void 0?p.text+=u:l.push({text:u});}if(c.candidates?.[0]?.content?.parts)for(let l of c.candidates[0].content.parts)l.functionCall&&r.candidates[0].content?.parts?.push(l);c.usageMetadata&&(r.usageMetadata=c.usageMetadata),c.candidates?.[0]?.finishReason&&(r.candidates[0].finishReason=c.candidates[0].finishReason),yield c;}}catch(c){throw a=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-o;if(a)m({provider:R,model:n,input:t,error:a,durationMs:c,streaming:true,context:s});else {let u=g({provider:R,model:n,input:t,rawResponse:r,durationMs:c,status:"success",streaming:true,firstTokenMs:i,context:s});if(u){let l=Vn(r.candidates);l.length>0&&w(l,u);}}}}function Ln(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?Kn(r.bind(t),n):r}})}function Kn(e,n){return function(o){let s=e(o);return Jn(s,o.model,n)}}function Jn(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="sendMessage"&&typeof a=="function"?Fn(a.bind(o),n,t):s==="sendMessageStream"&&typeof a=="function"?zn(a.bind(o),n,t):a}})}function Fn(e,n,t){return async function(s){let r=Date.now(),a=s.message;try{let i=await e(s),d=Date.now()-r,c=Pe(i),u=g({provider:R,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=Ae(i);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function zn(e,n,t){return async function(s){let r=Date.now(),a=s.message;try{let i=await e(s);return _e(i,n,a,r,t)}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}function xe(e){return e.contents}function Pe(e){return {candidates:e.candidates,usageMetadata:e.usageMetadata,modelVersion:e.modelVersion}}function Ae(e){let n=[],t=e.candidates?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}function Vn(e){let n=[],t=e?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}var T="gemini";function De(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="GenerativeModel")return true;let t=e;return typeof t.generateContent=="function"&&typeof t.generateContentStream=="function"&&typeof t.model=="string"}function Ge(e){return !e||typeof e!="object"?false:!!(e.constructor?.name==="GoogleGenerativeAI"||typeof e.getGenerativeModel=="function"||De(e))}function Ne(e,n){if(De(e)){let o=e;return je(o,o.model,n)}let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="getGenerativeModel"&&typeof a=="function"?Wn(a.bind(o),n):a}})}function Wn(e,n){return function(o){let s=e(o);return je(s,o.model,n)}}function je(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="generateContent"&&typeof a=="function"?Yn(a.bind(o),n,t):s==="generateContentStream"&&typeof a=="function"?Zn(a.bind(o),n,t):s==="startChat"&&typeof a=="function"?Xn(a.bind(o),n,t):a}})}function Yn(e,n,t){return async function(s){let r=Date.now(),a=Ue(s);try{let i=await e(s),d=Date.now()-r,c=qe(i.response),u=g({provider:T,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=$e(i.response);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:T,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function Zn(e,n,t){return async function(s){let r=Date.now(),a=Ue(s);try{let i=await e(s),d=Be(i.stream,n,a,r,t);return {...i,stream:d}}catch(i){throw m({provider:T,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}async function*Be(e,n,t,o,s){let r={candidates:[{content:{parts:[]}}]},a=null,i,d=false;try{for await(let c of e){try{let u=c.text();if(u){d||(d=!0,i=Date.now()-o);let l=r.candidates[0].content?.parts||[],p=l[l.length-1];p?.text!==void 0?p.text+=u:l.push({text:u});}}catch{}if(c.candidates?.[0]?.content?.parts)for(let u of c.candidates[0].content.parts)u.functionCall&&r.candidates[0].content?.parts?.push(u);c.usageMetadata&&(r.usageMetadata=c.usageMetadata),c.candidates?.[0]?.finishReason&&(r.candidates[0].finishReason=c.candidates[0].finishReason),yield c;}}catch(c){throw a=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-o;if(a)m({provider:T,model:n,input:t,error:a,durationMs:c,streaming:true,context:s});else {let u=g({provider:T,model:n,input:t,rawResponse:r,durationMs:c,status:"success",streaming:true,firstTokenMs:i,context:s});if(u){let l=tt(r.candidates);l.length>0&&w(l,u);}}}}function Xn(e,n,t){return function(s){let r=e(s);return Qn(r,n,t)}}function Qn(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="sendMessage"&&typeof a=="function"?et(a.bind(o),n,t):s==="sendMessageStream"&&typeof a=="function"?nt(a.bind(o),n,t):a}})}function et(e,n,t){return async function(s){let r=Date.now(),a=s;try{let i=await e(s),d=Date.now()-r,c=qe(i.response),u=g({provider:T,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=$e(i.response);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:T,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function nt(e,n,t){return async function(s){let r=Date.now(),a=s;try{let i=await e(s),d=Be(i.stream,n,a,r,t);return {...i,stream:d}}catch(i){throw m({provider:T,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}function Ue(e){return typeof e=="string"?e:e.contents?e.contents:e}function qe(e){return {candidates:e.candidates,usageMetadata:e.usageMetadata}}function $e(e){let n=[],t=e.candidates?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}function tt(e){let n=[],t=e?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}var ot="openrouter.ai",q="openrouter";function Le(e){if(!e||typeof e!="object")return false;let n=e;return n.chat?.completions?.create?(n.baseURL||"").includes(ot):false}function Ke(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="chat"&&a&&typeof a=="object"?st(a,n):a}})}function st(e,n){return e&&new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="completions"&&r&&typeof r=="object"?at(r,n):r}})}function at(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?it(r.bind(t),n):r}})}function it(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&ut(i))return ct(i,r,s,n);let d=Date.now()-s,c=i;return g({provider:q,model:r.model||c.model||"unknown",input:r.messages,rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n}),i}catch(i){let d=Date.now()-s;throw m({provider:q,model:r.model||"unknown",input:r.messages,error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function ut(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}async function*ct(e,n,t,o){let s={choices:[{message:{content:"",role:"assistant"},finish_reason:""}],usage:{prompt_tokens:0,completion_tokens:0}},r=null,a,i=false;try{for await(let d of e){let c=d;!s.id&&c.id&&(s.id=c.id);let u=c.choices?.[0]?.delta?.content;u&&(i||(i=!0,a=Date.now()-t),s.choices[0].message.content+=u);let l=c.choices?.[0]?.finish_reason;l&&(s.choices[0].finish_reason=l),c.usage&&(s.usage=c.usage),yield d;}}catch(d){throw r=d instanceof Error?d:new Error(String(d)),d}finally{let d=Date.now()-t;r?m({provider:q,model:n.model||"unknown",input:n.messages,error:r,durationMs:d,streaming:true,context:o}):g({provider:q,model:n.model||"unknown",input:n.messages,rawResponse:s,durationMs:d,status:"success",streaming:true,firstTokenMs:a,context:o});}}function Je(e,n){return B().disabled?(k("Tracing disabled, returning unwrapped client"),e):Le(e)?(O("openrouter"),Ke(e,n)):me(e)?(O("openai"),lt(e,n)):Ce(e)?(O("anthropic"),yt(e,n)):Ie(e)?(O("bedrock"),Re(e,n)):Me(e)?(O("gemini"),Ee(e,n)):Ge(e)?(O("gemini"),Ne(e,n)):(G("Unknown client type. Tracing not enabled. Supported: OpenAI, OpenRouter, Anthropic, Bedrock, Gemini"),e)}function lt(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="chat"&&a&&typeof a=="object"?pt(a,n):s==="responses"&&a&&typeof a=="object"?mt(a,n):s==="completions"&&a&&typeof a=="object"?gt(a,n):s==="embeddings"&&a&&typeof a=="object"?wt(a,n):a}})}function pt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="completions"&&r&&typeof r=="object"?ft(r,n):r}})}function ft(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ge(r.bind(t),n):r}})}function mt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ye(r.bind(t),n):r}})}function gt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ke(r.bind(t),n):r}})}function wt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?he(r.bind(t),n):r}})}function yt(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="messages"&&a&&typeof a=="object"?kt(a,n):a}})}function kt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ve(r.bind(t),n):o==="stream"&&typeof r=="function"?Se(r.bind(t),n):r}})}function ht(e){return function(t,o){return Je(t,{...e,...o})}}
|
|
3
|
+
exports.captureSpan=V;exports.createObserve=ht;exports.flush=sn;exports.getTraceContext=v;exports.init=rn;exports.isEnabled=on;exports.observe=Je;exports.span=Cn;exports.trace=yn;//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {AsyncLocalStorage}from'async_hooks';/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
var Y=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,t)=>(typeof require<"u"?require:n)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Je=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var oe=Je((It,We)=>{We.exports={name:"@lelemon-ai/trace",version:"0.12.0",description:"Automatic LLM observability. Wrap your client, everything is traced.",author:"Lelemon <info@lelemon.dev>",license:"MIT",repository:{type:"git",url:"git+https://github.com/Lelemon-studio/lelemondev-sdk.git"},homepage:"https://lelemon.dev",bugs:{url:"https://github.com/Lelemon-studio/lelemondev-sdk/issues"},keywords:["llm","observability","tracing","openai","anthropic","nextjs","lambda","express","hono","claude","gpt","ai","monitoring","serverless"],main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.js"},"./openai":{types:"./dist/openai.d.ts",import:"./dist/openai.mjs",require:"./dist/openai.js"},"./anthropic":{types:"./dist/anthropic.d.ts",import:"./dist/anthropic.mjs",require:"./dist/anthropic.js"},"./bedrock":{types:"./dist/bedrock.d.ts",import:"./dist/bedrock.mjs",require:"./dist/bedrock.js"},"./gemini":{types:"./dist/gemini.d.ts",import:"./dist/gemini.mjs",require:"./dist/gemini.js"},"./google-genai":{types:"./dist/google-genai.d.ts",import:"./dist/google-genai.mjs",require:"./dist/google-genai.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.mjs",require:"./dist/openrouter.js"},"./next":{types:"./dist/next.d.ts",import:"./dist/next.mjs",require:"./dist/next.js"},"./lambda":{types:"./dist/lambda.d.ts",import:"./dist/lambda.mjs",require:"./dist/lambda.js"},"./express":{types:"./dist/express.d.ts",import:"./dist/express.mjs",require:"./dist/express.js"},"./hono":{types:"./dist/hono.d.ts",import:"./dist/hono.mjs",require:"./dist/hono.js"},"./integrations":{types:"./dist/integrations.d.ts",import:"./dist/integrations.mjs",require:"./dist/integrations.js"},"./package.json":"./package.json"},typesVersions:{"*":{openai:["./dist/openai.d.ts"],anthropic:["./dist/anthropic.d.ts"],bedrock:["./dist/bedrock.d.ts"],gemini:["./dist/gemini.d.ts"],"google-genai":["./dist/google-genai.d.ts"],openrouter:["./dist/openrouter.d.ts"],next:["./dist/next.d.ts"],lambda:["./dist/lambda.d.ts"],express:["./dist/express.d.ts"],hono:["./dist/hono.d.ts"],integrations:["./dist/integrations.d.ts"],"*":["./dist/index.d.ts"]}},files:["dist/**/*.js","dist/**/*.mjs","dist/**/*.d.ts","dist/**/*.d.mts","README.md"],sideEffects:false,engines:{node:">=18.0.0"},scripts:{build:"tsup",dev:"tsup --watch",docs:"typedoc && node scripts/generate-llms-txt.mjs",prepublishOnly:"npm run build",lint:"eslint src/",test:"vitest","test:run":"vitest run","test:coverage":"vitest run --coverage","test:e2e":"vitest run tests/e2e",typecheck:"tsc --noEmit"},devDependencies:{"@anthropic-ai/sdk":"^0.82.0","@aws-sdk/client-bedrock-runtime":"^3.962.0","@google/genai":"^1.0.0","@google/generative-ai":"^0.24.1","@types/node":"^22.0.0","@vitest/coverage-v8":"^4.0.0",dotenv:"^17.2.3",openai:"^6.15.0",tsup:"^8.5.1",typedoc:"^0.28.18",typescript:"^6.0.0",vite:"^6.0.0",vitest:"^4.0.0"}};});var Z=false;function X(e){Z=e;}function S(){return Z?true:Fe("LELEMON_DEBUG")==="true"}var b="[Lelemon]";function k(e,n){S()&&K("debug",e,n);}function $(e,n){S()&&K("info",e,n);}function D(e,n){K("warn",e,n);}function L(e,n,t,o){S()&&console.log(`${b} Captured trace: provider=${e} model=${n} duration=${t}ms status=${o}`);}function G(e,n){console.error(`${b} Failed to capture trace: provider=${e} error=${n.message}`);}function T(e){S()&&console.log(`${b} Wrapped client: provider=${e}`);}function Q(e,n){S()&&console.log(`${b} Sending batch: count=${e} endpoint=${n}`);}function ee(e,n){S()&&console.log(`${b} Batch sent successfully: count=${e} duration=${n}ms`);}function ne(e,n){let t=n instanceof Error?n.message:String(n);console.error(`${b} Batch send failed: count=${e} error=${t}`);}function te(e,n,t){S()&&console.log(`${b} Request: ${e} ${n} (${t} bytes)`);}function re(e,n){S()&&console.log(`${b} Response: status=${e} duration=${n}ms`);}function K(e,n,t){let o=e==="error"?console.error:e==="warn"?console.warn:console.log;t!==void 0?o(`${b} ${n}`,t):o(`${b} ${n}`);}function Fe(e){if(typeof process<"u"&&process.env)return process.env[e]}var ze=10,Ve=1e3,He=1e4,N=class{config;queue=[];flushPromise=null;flushTimer=null;constructor(n){this.config={apiKey:n.apiKey,endpoint:n.endpoint,debug:n.debug,disabled:n.disabled,batchSize:n.batchSize??ze,flushIntervalMs:n.flushIntervalMs??Ve,requestTimeoutMs:n.requestTimeoutMs??He};}isEnabled(){return !this.config.disabled&&!!this.config.apiKey}enqueue(n){this.config.disabled||(this.queue.push(n),this.queue.length>=this.config.batchSize?this.flush():this.scheduleFlush());}async flush(){if(this.flushPromise)return this.flushPromise;if(this.queue.length===0)return;this.cancelScheduledFlush();let n=this.queue;return this.queue=[],this.flushPromise=this.sendBatch(n).finally(()=>{this.flushPromise=null;}),this.flushPromise}getPendingCount(){return this.queue.length}scheduleFlush(){this.flushTimer===null&&(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush();},this.config.flushIntervalMs));}cancelScheduledFlush(){this.flushTimer!==null&&(clearTimeout(this.flushTimer),this.flushTimer=null);}async sendBatch(n){if(n.length===0)return;let t=Date.now();Q(n.length,`${this.config.endpoint}/api/v1/ingest`);try{await this.request("POST","/api/v1/ingest",{events:n}),ee(n.length,Date.now()-t);}catch(o){ne(n.length,o);}}async request(n,t,o){let s=`${this.config.endpoint}${t}`,r=new AbortController,a=o?JSON.stringify(o):void 0;te(n,s,a?.length??0);let i=setTimeout(()=>{r.abort();},this.config.requestTimeoutMs),d=Date.now();try{let c=await fetch(s,{method:n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:a,signal:r.signal});if(clearTimeout(i),re(c.status,Date.now()-d),!c.ok){let l=await c.text().catch(()=>"Unknown error");throw new Error(`HTTP ${c.status}: ${l}`)}let u=await c.text();return u?JSON.parse(u):{}}catch(c){throw clearTimeout(i),c instanceof Error&&c.name==="AbortError"?new Error(`Request timeout after ${this.config.requestTimeoutMs}ms`):c}}};var Ye="@lelemon-ai/trace",Ze="nodejs";function Xe(){return typeof process<"u"&&process.versions?.node?{name:"nodejs",version:process.versions.node}:typeof Deno<"u"?{name:"deno",version:Deno.version?.deno??"unknown"}:typeof Bun<"u"?{name:"bun",version:Bun.version??"unknown"}:typeof window<"u"&&typeof navigator<"u"?{name:"browser",version:navigator.userAgent}:null}function Qe(){if(typeof process<"u"&&process.platform){let e=process.platform;switch(e){case "darwin":return "darwin";case "win32":return "windows";case "linux":return "linux";default:return e}}if(typeof navigator<"u"){let e=navigator.userAgent.toLowerCase();if(e.includes("mac"))return "darwin";if(e.includes("win"))return "windows";if(e.includes("linux"))return "linux"}return null}function en(){try{if(typeof Y<"u")return oe().version??"unknown"}catch{}return "unknown"}var _=null;function ae(e){if(!_){let t=Xe(),o=Qe();_={"telemetry.sdk.name":Ye,"telemetry.sdk.version":en(),"telemetry.sdk.language":Ze},t&&(_["process.runtime.name"]=t.name,_["process.runtime.version"]=t.version),o&&(_["os.type"]=o);}let n={..._};return e?.name&&(n["service.name"]=e.name),e?.version&&(n["service.version"]=e.version),e?.environment&&(n["deployment.environment"]=e.environment),n}var F={},O=null,J=null,ie="https://api.lelemon.dev";function tn(e={}){F=e,e.debug&&X(true),J=ae(e.service),$("Initializing SDK",{endpoint:e.endpoint??ie,debug:e.debug??false,disabled:e.disabled??false,telemetry:J}),O=ue(e),O.isEnabled()?$("SDK initialized - tracing enabled"):k("SDK initialized - tracing disabled (no API key or explicitly disabled)");}function j(){return F}function B(){return J}function rn(){return M().isEnabled()}function M(){return O||(O=ue(F)),O}async function on(){O&&await O.flush();}function ue(e){let n=e.apiKey??sn("LELEMON_API_KEY");return !n&&!e.disabled&&D("No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled."),new N({apiKey:n??"",endpoint:e.endpoint??ie,debug:e.debug??false,disabled:e.disabled??!n,batchSize:e.batchSize,flushIntervalMs:e.flushIntervalMs,requestTimeoutMs:e.requestTimeoutMs})}function sn(e){if(typeof process<"u"&&process.env)return process.env[e]}function g(e){try{let n=M();if(!n.isEnabled()){k("Transport disabled, skipping trace capture");return}let t=e.context??{},o=C(),s=x(),r=B(),a={provider:e.provider,model:e.model,input:V(e.input),rawResponse:e.rawResponse?P(e.rawResponse,0):void 0,durationMs:e.durationMs,status:e.status,streaming:e.streaming,firstTokenMs:e.firstTokenMs,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:o?.traceId,spanId:s,parentSpanId:o?.currentSpanId,metadata:{...t.metadata,...e.metadata,...o?{_traceName:o.name}:{},...r?{_telemetry:r}:{}},tags:t.tags??o?.tags,spanType:e.spanType,name:e.name};return L(e.provider,e.model,e.durationMs,e.status),n.enqueue(a),s}catch(n){G(e.provider,n instanceof Error?n:new Error(String(n)));return}}function m(e){try{let n=M();if(!n.isEnabled()){k("Transport disabled, skipping error capture");return}let t=e.context??{},o=C(),s=B(),r={provider:e.provider,model:e.model,input:V(e.input),durationMs:e.durationMs,status:"error",errorMessage:e.error.message,streaming:e.streaming,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:o?.traceId,spanId:x(),parentSpanId:o?.currentSpanId,metadata:{...t.metadata,...e.metadata,...o?{_traceName:o.name}:{},...s?{_telemetry:s}:{}},tags:t.tags??o?.tags};L(e.provider,e.model,e.durationMs,"error"),k("Error details",{message:e.error.message,stack:e.error.stack}),n.enqueue(r);}catch(n){G(e.provider,n instanceof Error?n:new Error(String(n)));}}function z(e){try{let n=M();if(!n.isEnabled()){k("Transport disabled, skipping span capture");return}let t=e.context??{},o=C(),s=e.metadata?._traceId,r=e.metadata?._parentSpanId,a=B(),i={...t.metadata,...e.metadata,...a?{_telemetry:a}:{}};delete i._traceId,delete i._parentSpanId;let d={spanType:e.type,name:e.name,provider:"unknown",model:e.name,input:V(e.input),output:P(e.output,0),durationMs:e.durationMs,status:e.status||"success",errorMessage:e.errorMessage,streaming:!1,sessionId:o?.sessionId??t.sessionId,userId:o?.userId??t.userId,traceId:s??o?.traceId,spanId:x(),parentSpanId:r??o?.currentSpanId,toolCallId:e.toolCallId,metadata:i,tags:t.tags??o?.tags};k(`Span captured: ${e.type}/${e.name}`,{durationMs:e.durationMs}),n.enqueue(d);}catch(n){G("unknown",n instanceof Error?n:new Error(String(n)));}}var ce=1e5,an=["api_key","apikey","password","secret","authorization"],un=["access_token","auth_token","bearer_token","refresh_token","id_token","session_token"],cn=["inputtokens","outputtokens","totaltokens","prompttokens","completiontokens","cachereadtokens","cachewritetokens","cachereadinputtokens","cachewriteinputtokens","reasoningtokens"],de={emails:/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,phones:/\b\d{9,}\b/g};function le(){return j().redaction??{}}function dn(e){let n=e.toLowerCase();return cn.includes(n)?false:!!(an.some(o=>n.includes(o))||un.some(o=>n.includes(o))||(le().keys??[]).some(o=>n.includes(o.toLowerCase())))}function ln(e){let n=le(),t=e;for(let o of n.patterns??[])o.lastIndex=0,t=t.replace(o,"[REDACTED]");return n.emails&&(t=t.replace(de.emails,"[EMAIL]")),n.phones&&(t=t.replace(de.phones,"[PHONE]")),t}function V(e){return P(e,0)}function P(e,n){if(n>10)return "[max depth exceeded]";if(e==null)return e;if(typeof e=="string"){let t=ln(e);return t.length>ce&&(t=t.slice(0,ce)+"...[truncated]"),t}if(typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(t=>P(t,n+1));if(typeof e=="object"){let t={};for(let[o,s]of Object.entries(e))dn(o)?t[o]="[REDACTED]":t[o]=P(s,n+1);return t}return String(e)}var H=Symbol.for("@lelemondev/sdk:traceStorage");function fn(){let e=globalThis;return e[H]||(e[H]=new AsyncLocalStorage),e[H]}var pe=fn();function x(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}`}function C(){return pe.getStore()}function w(e,n){let t=C();if(t)for(let o of e)t.pendingToolCalls.set(o,n),k(`Registered tool call ${o} \u2192 LLM span ${n}`);}function mn(e){let n=C();if(n)return e&&n.pendingToolCalls.has(e)?n.pendingToolCalls.get(e):n.currentSpanId}function gn(e){let n=C();n&&n.pendingToolCalls.delete(e);}async function wn(e,n){let t=typeof e=="string"?{name:e}:e,o=C(),s=o?.traceId??x(),r=x(),a={traceId:s,rootSpanId:r,currentSpanId:r,parentSpanId:o?.currentSpanId,name:t.name,startTime:Date.now(),input:t.input,metadata:t.metadata,tags:t.tags,outputKey:t.outputKey,outputTransform:t.outputTransform,sessionId:t.sessionId,userId:t.userId,style:t.style,pendingToolCalls:new Map};return pe.run(a,async()=>{let i,d;try{return i=await n(),i}catch(c){throw d=c instanceof Error?c:new Error(String(c)),c}finally{hn(a,d?void 0:i,d);}})}var yn=["text","content","message","output","response","result","answer"];function kn(e,n,t){if(t)try{return t(e)}catch{return e}if(n===false)return e;if(typeof n=="string"&&e&&typeof e=="object"){let s=e;return n in s?s[n]:e}if(e==null||typeof e!="object"||Array.isArray(e))return e;let o=e;for(let s of yn)if(s in o&&typeof o[s]=="string")return o[s];return e}function hn(e,n,t){let o=M();if(!o.isEnabled()){k("Transport disabled, skipping root span");return}let s=Date.now()-e.startTime,r=t?null:kn(n,e.outputKey,e.outputTransform),a={spanType:"agent",name:e.name,provider:"agent",model:e.name,traceId:e.traceId,spanId:e.rootSpanId,parentSpanId:e.parentSpanId,input:e.input,output:r,inputTokens:0,outputTokens:0,durationMs:s,status:t?"error":"success",errorMessage:t?.message,streaming:false,sessionId:e.sessionId,userId:e.userId,metadata:{...e.metadata,...e.style?{_style:e.style}:{}},tags:e.tags};k(`Sending root span: ${e.name}`,{durationMs:s,hasError:!!t}),o.enqueue(a);}function bn(e){let n=C();if(!n){process.env.NODE_ENV!=="production"&&console.warn("[Lelemon] span() called outside of trace() - span will not be captured");return}let t=mn(e.toolCallId);z({type:e.type,name:e.name,input:e.input,output:e.output,durationMs:e.durationMs??0,status:e.status??"success",errorMessage:e.errorMessage,toolCallId:e.toolCallId,metadata:{...e.metadata,_traceId:n.traceId,_parentSpanId:t,...e.style?{_style:e.style}:{}}}),e.toolCallId&&gn(e.toolCallId);}var h="openai";function fe(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="OpenAI")return true;let t=e;return !!(t.chat&&t.completions)||!!t.responses}function me(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&ge(i))return Cn(i,r,s,n);let d=Date.now()-s,c=i,u=g({provider:h,model:r.model||c.model||"unknown",input:r.messages,rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n});if(u){let l=he(c);l.length>0&&w(l,u);}return i}catch(i){let d=Date.now()-s;throw m({provider:h,model:r.model||"unknown",input:r.messages,error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function ge(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}async function*Cn(e,n,t,o){let s={choices:[{message:{content:"",tool_calls:[]},finish_reason:""}],usage:{prompt_tokens:0,completion_tokens:0}},r=null,a,i=false,d=new Map;try{for await(let c of e){let u=c,l=u?.choices?.[0]?.delta?.content;l&&(i||(i=!0,a=Date.now()-t),s.choices[0].message.content+=l);let p=u?.choices?.[0]?.delta?.tool_calls;if(p)for(let y of p){d.has(y.index)||d.set(y.index,{id:"",function:{name:"",arguments:""}});let q=d.get(y.index);y.id&&(q.id=y.id),y.function?.name&&(q.function.name=y.function.name),y.function?.arguments&&(q.function.arguments+=y.function.arguments);}let f=u?.choices?.[0]?.finish_reason;f&&(s.choices[0].finish_reason=f),u?.usage&&(s.usage=u.usage),yield c;}}catch(c){throw r=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-t;if(d.size>0&&(s.choices[0].message.tool_calls=Array.from(d.entries()).sort((u,l)=>u[0]-l[0]).map(([,u])=>u)),r)m({provider:h,model:n.model||"unknown",input:n.messages,error:r,durationMs:c,streaming:true,context:o});else {let u=g({provider:h,model:n.model||"unknown",input:n.messages,rawResponse:s,durationMs:c,status:"success",streaming:true,firstTokenMs:a,context:o});if(u){let l=he(s);l.length>0&&w(l,u);}}}}function we(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&ge(i))return vn(i,r,s,n);let d=Date.now()-s;return g({provider:h,model:r.model||"unknown",input:{instructions:r.instructions,input:r.input},rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n}),i}catch(i){let d=Date.now()-s;throw m({provider:h,model:r.model||"unknown",input:{instructions:r.instructions,input:r.input},error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}async function*vn(e,n,t,o){let s=[],r=null,a=null;try{for await(let i of e){s.push(i);let d=i;d.type==="response.done"&&d.response&&(r=d.response),yield i;}}catch(i){throw a=i instanceof Error?i:new Error(String(i)),i}finally{let i=Date.now()-t;a?m({provider:h,model:n.model||"unknown",input:{instructions:n.instructions,input:n.input},error:a,durationMs:i,streaming:true,context:o}):g({provider:h,model:n.model||"unknown",input:{instructions:n.instructions,input:n.input},rawResponse:r||{streamEvents:s},durationMs:i,status:"success",streaming:true,context:o});}}function ye(e,n){return async function(...o){let s=Date.now(),r=o[0]||{};try{let a=await e(...o),i=Date.now()-s;return g({provider:h,model:r.model||"unknown",input:r.prompt,rawResponse:a,durationMs:i,status:"success",streaming:!1,context:n}),a}catch(a){let i=Date.now()-s;throw m({provider:h,model:r.model||"unknown",input:r.prompt,error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:false,context:n}),a}}}function ke(e,n){return async function(...o){let s=Date.now(),r=o[0]||{};try{let a=await e(...o),i=Date.now()-s;return g({provider:h,model:r.model||"unknown",input:r.input,rawResponse:a,durationMs:i,status:"success",streaming:!1,spanType:"embedding",context:n}),a}catch(a){let i=Date.now()-s;throw m({provider:h,model:r.model||"unknown",input:r.input,error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:false,context:n}),a}}}function he(e){let n=[],t=e.choices?.[0]?.message?.tool_calls;if(Array.isArray(t))for(let o of t)o.id&&n.push(o.id);return n}var E="anthropic";function be(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="Anthropic")return true;let t=e;return !!(t.messages&&typeof t.messages=="object")}function Ce(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&In(i))return Tn(i,r,s,n);let d=Date.now()-s,c=i,u=g({provider:E,model:r.model||c.model||"unknown",input:{system:r.system,messages:r.messages},rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n});if(u&&c.content){let l=W(c.content);l.length>0&&w(l,u);}return i}catch(i){let d=Date.now()-s;throw m({provider:E,model:r.model||"unknown",input:{system:r.system,messages:r.messages},error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function ve(e,n){return function(...o){let s=Date.now(),r=o[0]||{};try{let a=e(...o);return a&&typeof a=="object"?Rn(a,r,s,n):a}catch(a){let i=Date.now()-s;throw m({provider:E,model:r.model||"unknown",input:{system:r.system,messages:r.messages},error:a instanceof Error?a:new Error(String(a)),durationMs:i,streaming:true,context:n}),a}}}function In(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function Rn(e,n,t,o){let s=e;if(!s[Symbol.asyncIterator])return e;let r={content:[],usage:{input_tokens:0,output_tokens:0}},a=false,i,d=false,c=null,u=[],l=async function*(){try{for await(let p of s){if(p.type==="message_start"&&p.message&&(r.model=p.message.model,r.id=p.message.id,r.role=p.message.role,p.message.usage&&(r.usage={...p.message.usage})),p.type==="content_block_start"&&p.content_block&&(c=p.index??u.length,u[c]={...p.content_block},p.content_block.type==="text"&&(u[c].text=""),p.content_block.type==="thinking"&&(u[c].thinking="")),p.type==="content_block_delta"&&p.delta&&c!==null){let f=u[c];f&&(p.delta.text&&(d||(d=!0,i=Date.now()-t),f.type==="thinking"?f.thinking=(f.thinking||"")+p.delta.text:f.type==="text"&&(f.text=(f.text||"")+p.delta.text)),p.delta.partial_json&&f.type==="tool_use"&&(f._inputJson=(f._inputJson||"")+p.delta.partial_json));}if(p.type==="content_block_stop"&&c!==null){let f=u[c];if(f&&f.type==="tool_use"){let y=f._inputJson;if(y){try{f.input=JSON.parse(y);}catch{}delete f._inputJson;}}c=null;}p.type==="message_delta"&&(p.usage?.output_tokens&&(r.usage.output_tokens=p.usage.output_tokens),p.delta?.stop_reason&&(r.stop_reason=p.delta.stop_reason)),yield p;}}catch(p){if(!a){a=true;let f=Date.now()-t;m({provider:E,model:r.model||n.model||"unknown",input:{system:n.system,messages:n.messages},error:p instanceof Error?p:new Error(String(p)),durationMs:f,streaming:true,context:o});}throw p}finally{if(!a){a=true;let p=Date.now()-t;r.content=u.filter(Boolean);let f=g({provider:E,model:r.model||n.model||"unknown",input:{system:n.system,messages:n.messages},rawResponse:r,durationMs:p,status:"success",streaming:true,firstTokenMs:i,context:o});if(f&&r.content){let y=W(r.content);y.length>0&&w(y,f);}}}};return new Proxy(e,{get(p,f,y){return f===Symbol.asyncIterator?()=>l()[Symbol.asyncIterator]():Reflect.get(p,f,y)}})}async function*Tn(e,n,t,o){let s={content:[],usage:{input_tokens:0,output_tokens:0}},r=null,a,i=false,d=null,c=[];try{for await(let u of e){if(u.type==="message_start"&&u.message&&(s.model=u.message.model,s.id=u.message.id,s.role=u.message.role,u.message.usage&&(s.usage={...u.message.usage})),u.type==="content_block_start"&&u.content_block&&(d=u.index??c.length,c[d]={...u.content_block},u.content_block.type==="text"&&(c[d].text=""),u.content_block.type==="thinking"&&(c[d].thinking="")),u.type==="content_block_delta"&&u.delta&&d!==null){let l=c[d];l&&(u.delta.text&&(i||(i=!0,a=Date.now()-t),l.type==="thinking"?l.thinking=(l.thinking||"")+u.delta.text:l.type==="text"&&(l.text=(l.text||"")+u.delta.text)),u.delta.partial_json&&l.type==="tool_use"&&(l._inputJson=(l._inputJson||"")+u.delta.partial_json));}if(u.type==="content_block_stop"&&d!==null){let l=c[d];if(l&&l.type==="tool_use"){let p=l._inputJson;if(p){try{l.input=JSON.parse(p);}catch{}delete l._inputJson;}}d=null;}u.type==="message_delta"&&(u.usage?.output_tokens&&(s.usage.output_tokens=u.usage.output_tokens),u.delta?.stop_reason&&(s.stop_reason=u.delta.stop_reason)),yield u;}}catch(u){throw r=u instanceof Error?u:new Error(String(u)),u}finally{let u=Date.now()-t;if(s.content=c.filter(Boolean),r)m({provider:E,model:s.model||n.model||"unknown",input:{system:n.system,messages:n.messages},error:r,durationMs:u,streaming:true,context:o});else {let l=g({provider:E,model:s.model||n.model||"unknown",input:{system:n.system,messages:n.messages},rawResponse:s,durationMs:u,status:"success",streaming:true,firstTokenMs:a,context:o});if(l&&s.content){let p=W(s.content);p.length>0&&w(p,l);}}}}function W(e){let n=[];for(let t of e)t.type==="tool_use"&&t.id&&n.push(t.id);return n}var v="bedrock";function Se(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="BedrockRuntimeClient")return true;let t=e;return typeof t.send!="function"||!t.config||typeof t.config!="object"?false:"region"in t.config}function Ie(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="send"&&typeof a=="function"?Mn(a.bind(o),n):a}})}function Mn(e,n){return async function(o){switch(o.constructor?.name||""){case "ConverseCommand":return En(e,o,n);case "ConverseStreamCommand":return _n(e,o,n);case "InvokeModelCommand":return Pn(e,o,n);case "InvokeModelWithResponseStreamCommand":return An(e,o,n);default:return e(o)}}}async function En(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n),a=Date.now()-o,i=g({provider:v,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},rawResponse:Re(r),durationMs:a,status:"success",streaming:!1,context:t});if(i){let d=Te(r);d.length>0&&w(d,i);}return r}catch(r){throw m({provider:v,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:false,context:t}),r}}async function _n(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n);return r.stream?{...r,stream:xn(r.stream,s,o,t)}:r}catch(r){throw m({provider:v,model:s.modelId||"unknown",input:{system:s.system,messages:s.messages},error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:true,context:t}),r}}async function*xn(e,n,t,o){let s={output:{message:{role:"assistant",content:[]}},usage:{inputTokens:0,outputTokens:0}},r=null,a,i=false,d=new Map,c=new Map;try{for await(let u of e){if(u.contentBlockStart){let l=u.contentBlockStart.contentBlockIndex;if(u.contentBlockStart.start?.toolUse){let p=u.contentBlockStart.start.toolUse;d.set(l,{toolUse:{toolUseId:p.toolUseId,name:p.name,input:{}}}),c.set(l,"");}else d.set(l,{text:""});}if(u.contentBlockDelta){let l=u.contentBlockDelta.contentBlockIndex,p=d.get(l);if(p&&u.contentBlockDelta.delta?.text&&(i||(i=!0,a=Date.now()-t),p.text=(p.text||"")+u.contentBlockDelta.delta.text),p?.toolUse&&u.contentBlockDelta.delta?.toolUse?.input){let f=c.get(l)||"";c.set(l,f+u.contentBlockDelta.delta.toolUse.input);}}if(u.contentBlockStop){let l=u.contentBlockStop.contentBlockIndex,p=d.get(l),f=c.get(l);if(p?.toolUse&&f)try{p.toolUse.input=JSON.parse(f);}catch{}}u.messageStop?.stopReason&&(s.stopReason=u.messageStop.stopReason),u.metadata?.usage&&(s.usage={inputTokens:u.metadata.usage.inputTokens||0,outputTokens:u.metadata.usage.outputTokens||0}),yield u;}}catch(u){throw r=u instanceof Error?u:new Error(String(u)),u}finally{let u=Date.now()-t,l=Array.from(d.entries()).sort((p,f)=>p[0]-f[0]).map(([,p])=>p);if(s.output.message.content=l,r)m({provider:v,model:n.modelId||"unknown",input:{system:n.system,messages:n.messages},error:r,durationMs:u,streaming:true,context:o});else {let p=g({provider:v,model:n.modelId||"unknown",input:{system:n.system,messages:n.messages},rawResponse:Re(s),durationMs:u,status:"success",streaming:true,firstTokenMs:a,context:o});if(p){let f=Te(s);f.length>0&&w(f,p);}}}}async function Pn(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n),a=Date.now()-o,i=Gn(r.body);return g({provider:v,model:s.modelId||"unknown",input:A(s.body),rawResponse:i,durationMs:a,status:"success",streaming:!1,context:t}),r}catch(r){throw m({provider:v,model:s.modelId||"unknown",input:A(s.body),error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:false,context:t}),r}}async function An(e,n,t){let o=Date.now(),s=n.input;try{let r=await e(n);return r.body?{...r,body:Dn(r.body,s,o,t)}:r}catch(r){throw m({provider:v,model:s.modelId||"unknown",input:A(s.body),error:r instanceof Error?r:new Error(String(r)),durationMs:Date.now()-o,streaming:true,context:t}),r}}async function*Dn(e,n,t,o){let s=[],r=null;try{for await(let a of e){if(a.chunk?.bytes){let i=Nn(a.chunk.bytes);i&&s.push(i);}yield a;}}catch(a){throw r=a instanceof Error?a:new Error(String(a)),a}finally{let a=Date.now()-t;r?m({provider:v,model:n.modelId||"unknown",input:A(n.body),error:r,durationMs:a,streaming:true,context:o}):g({provider:v,model:n.modelId||"unknown",input:A(n.body),rawResponse:{streamEvents:s},durationMs:a,status:"success",streaming:true,context:o});}}function Re(e){try{return JSON.parse(JSON.stringify(e))}catch{return e}}function Te(e){let n=[],t=e.output?.message?.content;if(Array.isArray(t))for(let o of t)o.toolUse?.toolUseId&&n.push(o.toolUse.toolUseId);return n}function A(e){try{let n=typeof e=="string"?e:new TextDecoder().decode(e);return JSON.parse(n)}catch{return e}}function Gn(e){try{let n=new TextDecoder().decode(e);return JSON.parse(n)}catch{return null}}function Nn(e){try{let n=new TextDecoder().decode(e);return JSON.parse(n)}catch{return null}}var I="gemini";function Oe(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="GoogleGenAI")return true;let t=e;return !!(t.models&&typeof t.models=="object"&&typeof t.models.generateContent=="function"&&t.chats&&typeof t.chats=="object")}function Me(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="models"&&a&&typeof a=="object"?Bn(a,n):s==="chats"&&a&&typeof a=="object"?$n(a,n):a}})}function Bn(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="generateContent"&&typeof r=="function"?Un(r.bind(t),n):o==="generateContentStream"&&typeof r=="function"?qn(r.bind(t),n):r}})}function Un(e,n){return async function(o){let s=Date.now(),r=o.model,a=_e(o);try{let i=await e(o),d=Date.now()-s,c=xe(i),u=g({provider:I,model:r,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:n});if(u){let l=Pe(i);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:I,model:r,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-s,streaming:false,context:n}),i}}}function qn(e,n){return async function(o){let s=Date.now(),r=o.model,a=_e(o);try{let i=await e(o);return Ee(i,r,a,s,n)}catch(i){throw m({provider:I,model:r,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-s,streaming:true,context:n}),i}}}async function*Ee(e,n,t,o,s){let r={candidates:[{content:{parts:[]}}]},a=null,i,d=false;try{for await(let c of e){let u=c.text;if(u){d||(d=!0,i=Date.now()-o);let l=r.candidates[0].content?.parts||[],p=l[l.length-1];p?.text!==void 0?p.text+=u:l.push({text:u});}if(c.candidates?.[0]?.content?.parts)for(let l of c.candidates[0].content.parts)l.functionCall&&r.candidates[0].content?.parts?.push(l);c.usageMetadata&&(r.usageMetadata=c.usageMetadata),c.candidates?.[0]?.finishReason&&(r.candidates[0].finishReason=c.candidates[0].finishReason),yield c;}}catch(c){throw a=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-o;if(a)m({provider:I,model:n,input:t,error:a,durationMs:c,streaming:true,context:s});else {let u=g({provider:I,model:n,input:t,rawResponse:r,durationMs:c,status:"success",streaming:true,firstTokenMs:i,context:s});if(u){let l=zn(r.candidates);l.length>0&&w(l,u);}}}}function $n(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?Ln(r.bind(t),n):r}})}function Ln(e,n){return function(o){let s=e(o);return Kn(s,o.model,n)}}function Kn(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="sendMessage"&&typeof a=="function"?Jn(a.bind(o),n,t):s==="sendMessageStream"&&typeof a=="function"?Fn(a.bind(o),n,t):a}})}function Jn(e,n,t){return async function(s){let r=Date.now(),a=s.message;try{let i=await e(s),d=Date.now()-r,c=xe(i),u=g({provider:I,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=Pe(i);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:I,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function Fn(e,n,t){return async function(s){let r=Date.now(),a=s.message;try{let i=await e(s);return Ee(i,n,a,r,t)}catch(i){throw m({provider:I,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}function _e(e){return e.contents}function xe(e){return {candidates:e.candidates,usageMetadata:e.usageMetadata,modelVersion:e.modelVersion}}function Pe(e){let n=[],t=e.candidates?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}function zn(e){let n=[],t=e?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}var R="gemini";function Ae(e){if(!e||typeof e!="object")return false;if(e.constructor?.name==="GenerativeModel")return true;let t=e;return typeof t.generateContent=="function"&&typeof t.generateContentStream=="function"&&typeof t.model=="string"}function De(e){return !e||typeof e!="object"?false:!!(e.constructor?.name==="GoogleGenerativeAI"||typeof e.getGenerativeModel=="function"||Ae(e))}function Ge(e,n){if(Ae(e)){let o=e;return Ne(o,o.model,n)}let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="getGenerativeModel"&&typeof a=="function"?Hn(a.bind(o),n):a}})}function Hn(e,n){return function(o){let s=e(o);return Ne(s,o.model,n)}}function Ne(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="generateContent"&&typeof a=="function"?Wn(a.bind(o),n,t):s==="generateContentStream"&&typeof a=="function"?Yn(a.bind(o),n,t):s==="startChat"&&typeof a=="function"?Zn(a.bind(o),n,t):a}})}function Wn(e,n,t){return async function(s){let r=Date.now(),a=Be(s);try{let i=await e(s),d=Date.now()-r,c=Ue(i.response),u=g({provider:R,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=qe(i.response);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function Yn(e,n,t){return async function(s){let r=Date.now(),a=Be(s);try{let i=await e(s),d=je(i.stream,n,a,r,t);return {...i,stream:d}}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}async function*je(e,n,t,o,s){let r={candidates:[{content:{parts:[]}}]},a=null,i,d=false;try{for await(let c of e){try{let u=c.text();if(u){d||(d=!0,i=Date.now()-o);let l=r.candidates[0].content?.parts||[],p=l[l.length-1];p?.text!==void 0?p.text+=u:l.push({text:u});}}catch{}if(c.candidates?.[0]?.content?.parts)for(let u of c.candidates[0].content.parts)u.functionCall&&r.candidates[0].content?.parts?.push(u);c.usageMetadata&&(r.usageMetadata=c.usageMetadata),c.candidates?.[0]?.finishReason&&(r.candidates[0].finishReason=c.candidates[0].finishReason),yield c;}}catch(c){throw a=c instanceof Error?c:new Error(String(c)),c}finally{let c=Date.now()-o;if(a)m({provider:R,model:n,input:t,error:a,durationMs:c,streaming:true,context:s});else {let u=g({provider:R,model:n,input:t,rawResponse:r,durationMs:c,status:"success",streaming:true,firstTokenMs:i,context:s});if(u){let l=nt(r.candidates);l.length>0&&w(l,u);}}}}function Zn(e,n,t){return function(s){let r=e(s);return Xn(r,n,t)}}function Xn(e,n,t){return new Proxy(e,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="sendMessage"&&typeof a=="function"?Qn(a.bind(o),n,t):s==="sendMessageStream"&&typeof a=="function"?et(a.bind(o),n,t):a}})}function Qn(e,n,t){return async function(s){let r=Date.now(),a=s;try{let i=await e(s),d=Date.now()-r,c=Ue(i.response),u=g({provider:R,model:n,input:a,rawResponse:c,durationMs:d,status:"success",streaming:!1,context:t});if(u){let l=qe(i.response);l.length>0&&w(l,u);}return i}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:false,context:t}),i}}}function et(e,n,t){return async function(s){let r=Date.now(),a=s;try{let i=await e(s),d=je(i.stream,n,a,r,t);return {...i,stream:d}}catch(i){throw m({provider:R,model:n,input:a,error:i instanceof Error?i:new Error(String(i)),durationMs:Date.now()-r,streaming:true,context:t}),i}}}function Be(e){return typeof e=="string"?e:e.contents?e.contents:e}function Ue(e){return {candidates:e.candidates,usageMetadata:e.usageMetadata}}function qe(e){let n=[],t=e.candidates?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}function nt(e){let n=[],t=e?.[0]?.content?.parts;return t&&t.forEach((o,s)=>{o.functionCall?.name&&n.push(`gemini-fc-${o.functionCall.name}-${s}`);}),n}var rt="openrouter.ai",U="openrouter";function $e(e){if(!e||typeof e!="object")return false;let n=e;return n.chat?.completions?.create?(n.baseURL||"").includes(rt):false}function Le(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="chat"&&a&&typeof a=="object"?ot(a,n):a}})}function ot(e,n){return e&&new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="completions"&&r&&typeof r=="object"?st(r,n):r}})}function st(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?at(r.bind(t),n):r}})}function at(e,n){return async function(...o){let s=Date.now(),r=o[0]||{},a=r.stream===true;try{let i=await e(...o);if(a&&it(i))return ut(i,r,s,n);let d=Date.now()-s,c=i;return g({provider:U,model:r.model||c.model||"unknown",input:r.messages,rawResponse:i,durationMs:d,status:"success",streaming:!1,context:n}),i}catch(i){let d=Date.now()-s;throw m({provider:U,model:r.model||"unknown",input:r.messages,error:i instanceof Error?i:new Error(String(i)),durationMs:d,streaming:a,context:n}),i}}}function it(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}async function*ut(e,n,t,o){let s={choices:[{message:{content:"",role:"assistant"},finish_reason:""}],usage:{prompt_tokens:0,completion_tokens:0}},r=null,a,i=false;try{for await(let d of e){let c=d;!s.id&&c.id&&(s.id=c.id);let u=c.choices?.[0]?.delta?.content;u&&(i||(i=!0,a=Date.now()-t),s.choices[0].message.content+=u);let l=c.choices?.[0]?.finish_reason;l&&(s.choices[0].finish_reason=l),c.usage&&(s.usage=c.usage),yield d;}}catch(d){throw r=d instanceof Error?d:new Error(String(d)),d}finally{let d=Date.now()-t;r?m({provider:U,model:n.model||"unknown",input:n.messages,error:r,durationMs:d,streaming:true,context:o}):g({provider:U,model:n.model||"unknown",input:n.messages,rawResponse:s,durationMs:d,status:"success",streaming:true,firstTokenMs:a,context:o});}}function Ke(e,n){return j().disabled?(k("Tracing disabled, returning unwrapped client"),e):$e(e)?(T("openrouter"),Le(e,n)):fe(e)?(T("openai"),dt(e,n)):be(e)?(T("anthropic"),wt(e,n)):Se(e)?(T("bedrock"),Ie(e,n)):Oe(e)?(T("gemini"),Me(e,n)):De(e)?(T("gemini"),Ge(e,n)):(D("Unknown client type. Tracing not enabled. Supported: OpenAI, OpenRouter, Anthropic, Bedrock, Gemini"),e)}function dt(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="chat"&&a&&typeof a=="object"?lt(a,n):s==="responses"&&a&&typeof a=="object"?ft(a,n):s==="completions"&&a&&typeof a=="object"?mt(a,n):s==="embeddings"&&a&&typeof a=="object"?gt(a,n):a}})}function lt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="completions"&&r&&typeof r=="object"?pt(r,n):r}})}function pt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?me(r.bind(t),n):r}})}function ft(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?we(r.bind(t),n):r}})}function mt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ye(r.bind(t),n):r}})}function gt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?ke(r.bind(t),n):r}})}function wt(e,n){let t=e;return new Proxy(t,{get(o,s,r){let a=Reflect.get(o,s,r);return s==="messages"&&a&&typeof a=="object"?yt(a,n):a}})}function yt(e,n){return new Proxy(e,{get(t,o,s){let r=Reflect.get(t,o,s);return o==="create"&&typeof r=="function"?Ce(r.bind(t),n):o==="stream"&&typeof r=="function"?ve(r.bind(t),n):r}})}function kt(e){return function(t,o){return Ke(t,{...e,...o})}}
|
|
3
|
+
export{z as captureSpan,kt as createObserve,on as flush,C as getTraceContext,tn as init,rn as isEnabled,Ke as observe,bn as span,wn as trace};//# sourceMappingURL=index.mjs.map
|
|
4
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
var m=Object.defineProperty;var i=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:true});};var l={};i(l,{createWrapper:()=>f,withObserve:()=>a});async function n(){}function a(t,e){return async(r,x)=>{try{return await t(r,x)}finally{e?.after?e.after(()=>n()):e?.waitUntil?e.waitUntil(n()):await n();}}}function f(t){return function(e,r){return a(e,{...t,...r})}}var u={};i(u,{withObserve:()=>c});function c(t){return async(e,r)=>{try{return await t(e,r)}finally{await n();}}}var p={};i(p,{createMiddleware:()=>b});function b(){return (t,e,r)=>{e.on("finish",()=>{n().catch(()=>{});}),r();}}var d={};i(d,{createMiddleware:()=>T});function T(){return async(t,e)=>{await e(),t.executionCtx?.waitUntil?t.executionCtx.waitUntil(n()):n().catch(()=>{});}}exports.express=p;exports.hono=d;exports.lambda=u;exports.next=l;//# sourceMappingURL=integrations.js.map
|
|
3
|
+
//# sourceMappingURL=integrations.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @lelemon-ai/trace - LLM Observability */
|
|
2
|
+
var x=Object.defineProperty;var o=(t,e)=>{for(var r in e)x(t,r,{get:e[r],enumerable:true});};var a={};o(a,{createWrapper:()=>m,withObserve:()=>s});async function n(){}function s(t,e){return async(r,d)=>{try{return await t(r,d)}finally{e?.after?e.after(()=>n()):e?.waitUntil?e.waitUntil(n()):await n();}}}function m(t){return function(e,r){return s(e,{...t,...r})}}var l={};o(l,{withObserve:()=>f});function f(t){return async(e,r)=>{try{return await t(e,r)}finally{await n();}}}var u={};o(u,{createMiddleware:()=>c});function c(){return (t,e,r)=>{e.on("finish",()=>{n().catch(()=>{});}),r();}}var p={};o(p,{createMiddleware:()=>b});function b(){return async(t,e)=>{await e(),t.executionCtx?.waitUntil?t.executionCtx.waitUntil(n()):n().catch(()=>{});}}export{u as express,p as hono,l as lambda,a as next};//# sourceMappingURL=integrations.mjs.map
|
|
3
|
+
//# sourceMappingURL=integrations.mjs.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Lambda Integration
|
|
3
|
+
*
|
|
4
|
+
* Wraps Lambda handlers to automatically flush traces before the function exits.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { withObserve } from '@lelemon-ai/trace/lambda';
|
|
8
|
+
*
|
|
9
|
+
* export const handler = withObserve(async (event) => {
|
|
10
|
+
* const openai = observe(new OpenAI());
|
|
11
|
+
* const result = await openai.chat.completions.create({...});
|
|
12
|
+
* return { statusCode: 200, body: JSON.stringify(result) };
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* AWS Lambda Context object
|
|
17
|
+
*/
|
|
18
|
+
interface LambdaContext {
|
|
19
|
+
functionName: string;
|
|
20
|
+
functionVersion: string;
|
|
21
|
+
invokedFunctionArn: string;
|
|
22
|
+
memoryLimitInMB: string;
|
|
23
|
+
awsRequestId: string;
|
|
24
|
+
logGroupName: string;
|
|
25
|
+
logStreamName: string;
|
|
26
|
+
getRemainingTimeInMillis(): number;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generic AWS Lambda handler type
|
|
31
|
+
*
|
|
32
|
+
* @typeParam TEvent - The event type (e.g., APIGatewayProxyEvent)
|
|
33
|
+
* @typeParam TResult - The result type (e.g., APIGatewayProxyResult)
|
|
34
|
+
*/
|
|
35
|
+
type LambdaHandler<TEvent = unknown, TResult = unknown> = (event: TEvent, context: LambdaContext) => Promise<TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Wrap an AWS Lambda handler with automatic trace flushing
|
|
38
|
+
*
|
|
39
|
+
* Always flushes before returning - Lambda freezes the container
|
|
40
|
+
* immediately after the handler returns, so this is required.
|
|
41
|
+
*
|
|
42
|
+
* @param handler - Your Lambda handler function
|
|
43
|
+
* @returns Wrapped handler that auto-flushes traces
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // API Gateway event
|
|
47
|
+
* export const handler = withObserve(async (event) => {
|
|
48
|
+
* const body = JSON.parse(event.body);
|
|
49
|
+
* const openai = observe(new OpenAI());
|
|
50
|
+
* const result = await openai.chat.completions.create({
|
|
51
|
+
* model: 'gpt-4',
|
|
52
|
+
* messages: [{ role: 'user', content: body.message }],
|
|
53
|
+
* });
|
|
54
|
+
* return {
|
|
55
|
+
* statusCode: 200,
|
|
56
|
+
* body: JSON.stringify(result.choices[0].message),
|
|
57
|
+
* };
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // With typed events
|
|
62
|
+
* import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
63
|
+
*
|
|
64
|
+
* export const handler = withObserve<APIGatewayProxyEvent, APIGatewayProxyResult>(
|
|
65
|
+
* async (event, context) => {
|
|
66
|
+
* return { statusCode: 200, body: 'OK' };
|
|
67
|
+
* }
|
|
68
|
+
* );
|
|
69
|
+
*/
|
|
70
|
+
declare function withObserve<TEvent = unknown, TResult = unknown>(handler: LambdaHandler<TEvent, TResult>): LambdaHandler<TEvent, TResult>;
|
|
71
|
+
|
|
72
|
+
type lambda_LambdaContext = LambdaContext;
|
|
73
|
+
type lambda_LambdaHandler<TEvent = unknown, TResult = unknown> = LambdaHandler<TEvent, TResult>;
|
|
74
|
+
declare const lambda_withObserve: typeof withObserve;
|
|
75
|
+
declare namespace lambda {
|
|
76
|
+
export { type lambda_LambdaContext as LambdaContext, type lambda_LambdaHandler as LambdaHandler, lambda_withObserve as withObserve };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { type LambdaContext as L, type LambdaHandler as a, lambda as l, withObserve as w };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Lambda Integration
|
|
3
|
+
*
|
|
4
|
+
* Wraps Lambda handlers to automatically flush traces before the function exits.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { withObserve } from '@lelemon-ai/trace/lambda';
|
|
8
|
+
*
|
|
9
|
+
* export const handler = withObserve(async (event) => {
|
|
10
|
+
* const openai = observe(new OpenAI());
|
|
11
|
+
* const result = await openai.chat.completions.create({...});
|
|
12
|
+
* return { statusCode: 200, body: JSON.stringify(result) };
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* AWS Lambda Context object
|
|
17
|
+
*/
|
|
18
|
+
interface LambdaContext {
|
|
19
|
+
functionName: string;
|
|
20
|
+
functionVersion: string;
|
|
21
|
+
invokedFunctionArn: string;
|
|
22
|
+
memoryLimitInMB: string;
|
|
23
|
+
awsRequestId: string;
|
|
24
|
+
logGroupName: string;
|
|
25
|
+
logStreamName: string;
|
|
26
|
+
getRemainingTimeInMillis(): number;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generic AWS Lambda handler type
|
|
31
|
+
*
|
|
32
|
+
* @typeParam TEvent - The event type (e.g., APIGatewayProxyEvent)
|
|
33
|
+
* @typeParam TResult - The result type (e.g., APIGatewayProxyResult)
|
|
34
|
+
*/
|
|
35
|
+
type LambdaHandler<TEvent = unknown, TResult = unknown> = (event: TEvent, context: LambdaContext) => Promise<TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Wrap an AWS Lambda handler with automatic trace flushing
|
|
38
|
+
*
|
|
39
|
+
* Always flushes before returning - Lambda freezes the container
|
|
40
|
+
* immediately after the handler returns, so this is required.
|
|
41
|
+
*
|
|
42
|
+
* @param handler - Your Lambda handler function
|
|
43
|
+
* @returns Wrapped handler that auto-flushes traces
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // API Gateway event
|
|
47
|
+
* export const handler = withObserve(async (event) => {
|
|
48
|
+
* const body = JSON.parse(event.body);
|
|
49
|
+
* const openai = observe(new OpenAI());
|
|
50
|
+
* const result = await openai.chat.completions.create({
|
|
51
|
+
* model: 'gpt-4',
|
|
52
|
+
* messages: [{ role: 'user', content: body.message }],
|
|
53
|
+
* });
|
|
54
|
+
* return {
|
|
55
|
+
* statusCode: 200,
|
|
56
|
+
* body: JSON.stringify(result.choices[0].message),
|
|
57
|
+
* };
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // With typed events
|
|
62
|
+
* import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
63
|
+
*
|
|
64
|
+
* export const handler = withObserve<APIGatewayProxyEvent, APIGatewayProxyResult>(
|
|
65
|
+
* async (event, context) => {
|
|
66
|
+
* return { statusCode: 200, body: 'OK' };
|
|
67
|
+
* }
|
|
68
|
+
* );
|
|
69
|
+
*/
|
|
70
|
+
declare function withObserve<TEvent = unknown, TResult = unknown>(handler: LambdaHandler<TEvent, TResult>): LambdaHandler<TEvent, TResult>;
|
|
71
|
+
|
|
72
|
+
type lambda_LambdaContext = LambdaContext;
|
|
73
|
+
type lambda_LambdaHandler<TEvent = unknown, TResult = unknown> = LambdaHandler<TEvent, TResult>;
|
|
74
|
+
declare const lambda_withObserve: typeof withObserve;
|
|
75
|
+
declare namespace lambda {
|
|
76
|
+
export { type lambda_LambdaContext as LambdaContext, type lambda_LambdaHandler as LambdaHandler, lambda_withObserve as withObserve };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { type LambdaContext as L, type LambdaHandler as a, lambda as l, withObserve as w };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { L as LambdaContext, a as LambdaHandler, w as withObserve } from './lambda-Drx54kXf.mjs';
|
package/dist/lambda.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { L as LambdaContext, a as LambdaHandler, w as withObserve } from './lambda-Drx54kXf.js';
|
package/dist/lambda.js
ADDED
package/dist/lambda.mjs
ADDED