@lelemondev/sdk 0.3.0 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +536 -93
  2. package/dist/express-Dt5wT6_n.d.mts +67 -0
  3. package/dist/express-Dt5wT6_n.d.ts +67 -0
  4. package/dist/express.d.mts +1 -0
  5. package/dist/express.d.ts +1 -0
  6. package/dist/express.js +21 -0
  7. package/dist/express.js.map +1 -0
  8. package/dist/express.mjs +19 -0
  9. package/dist/express.mjs.map +1 -0
  10. package/dist/hono-Dzmu77iW.d.mts +80 -0
  11. package/dist/hono-Dzmu77iW.d.ts +80 -0
  12. package/dist/hono.d.mts +1 -0
  13. package/dist/hono.d.ts +1 -0
  14. package/dist/hono.js +23 -0
  15. package/dist/hono.js.map +1 -0
  16. package/dist/hono.mjs +21 -0
  17. package/dist/hono.mjs.map +1 -0
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +949 -3
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +949 -3
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/integrations.d.mts +4 -0
  25. package/dist/integrations.d.ts +4 -0
  26. package/dist/integrations.js +93 -0
  27. package/dist/integrations.js.map +1 -0
  28. package/dist/integrations.mjs +88 -0
  29. package/dist/integrations.mjs.map +1 -0
  30. package/dist/lambda-CAuiF9dH.d.mts +79 -0
  31. package/dist/lambda-CAuiF9dH.d.ts +79 -0
  32. package/dist/lambda.d.mts +1 -0
  33. package/dist/lambda.d.ts +1 -0
  34. package/dist/lambda.js +21 -0
  35. package/dist/lambda.js.map +1 -0
  36. package/dist/lambda.mjs +19 -0
  37. package/dist/lambda.mjs.map +1 -0
  38. package/dist/next-BC9PmEho.d.mts +100 -0
  39. package/dist/next-BC9PmEho.d.ts +100 -0
  40. package/dist/next.d.mts +1 -0
  41. package/dist/next.d.ts +1 -0
  42. package/dist/next.js +33 -0
  43. package/dist/next.js.map +1 -0
  44. package/dist/next.mjs +30 -0
  45. package/dist/next.mjs.map +1 -0
  46. package/package.json +59 -11
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Express Integration
3
+ *
4
+ * Middleware that automatically flushes traces when response finishes.
5
+ *
6
+ * @example
7
+ * import express from 'express';
8
+ * import { createMiddleware } from '@lelemondev/sdk/express';
9
+ *
10
+ * const app = express();
11
+ * app.use(createMiddleware());
12
+ */
13
+ /**
14
+ * Minimal Express request type (avoids requiring express as dependency)
15
+ */
16
+ interface ExpressRequest {
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Minimal Express response type (avoids requiring express as dependency)
21
+ */
22
+ interface ExpressResponse {
23
+ on(event: 'finish' | 'close' | 'error', listener: () => void): this;
24
+ [key: string]: unknown;
25
+ }
26
+ /**
27
+ * Express next function type
28
+ */
29
+ type ExpressNextFunction = (error?: unknown) => void;
30
+ /**
31
+ * Express middleware function type
32
+ *
33
+ * @param req - Express request object
34
+ * @param res - Express response object
35
+ * @param next - Next function to pass control
36
+ */
37
+ type ExpressMiddleware = (req: ExpressRequest, res: ExpressResponse, next: ExpressNextFunction) => void;
38
+ /**
39
+ * Create Express middleware for automatic trace flushing
40
+ *
41
+ * Flushes traces when the response finishes (after res.send/res.json).
42
+ * This is fire-and-forget and doesn't block the response.
43
+ *
44
+ * @returns Express middleware function
45
+ *
46
+ * @example
47
+ * // Global middleware
48
+ * app.use(createMiddleware());
49
+ *
50
+ * @example
51
+ * // Per-route middleware
52
+ * app.post('/chat', createMiddleware(), async (req, res) => {
53
+ * res.json({ ok: true });
54
+ * });
55
+ */
56
+ declare function createMiddleware(): ExpressMiddleware;
57
+
58
+ type express_ExpressMiddleware = ExpressMiddleware;
59
+ type express_ExpressNextFunction = ExpressNextFunction;
60
+ type express_ExpressRequest = ExpressRequest;
61
+ type express_ExpressResponse = ExpressResponse;
62
+ declare const express_createMiddleware: typeof createMiddleware;
63
+ declare namespace express {
64
+ export { type express_ExpressMiddleware as ExpressMiddleware, type express_ExpressNextFunction as ExpressNextFunction, type express_ExpressRequest as ExpressRequest, type express_ExpressResponse as ExpressResponse, express_createMiddleware as createMiddleware };
65
+ }
66
+
67
+ export { type ExpressRequest as E, type ExpressResponse as a, type ExpressNextFunction as b, type ExpressMiddleware as c, createMiddleware as d, express as e };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Express Integration
3
+ *
4
+ * Middleware that automatically flushes traces when response finishes.
5
+ *
6
+ * @example
7
+ * import express from 'express';
8
+ * import { createMiddleware } from '@lelemondev/sdk/express';
9
+ *
10
+ * const app = express();
11
+ * app.use(createMiddleware());
12
+ */
13
+ /**
14
+ * Minimal Express request type (avoids requiring express as dependency)
15
+ */
16
+ interface ExpressRequest {
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Minimal Express response type (avoids requiring express as dependency)
21
+ */
22
+ interface ExpressResponse {
23
+ on(event: 'finish' | 'close' | 'error', listener: () => void): this;
24
+ [key: string]: unknown;
25
+ }
26
+ /**
27
+ * Express next function type
28
+ */
29
+ type ExpressNextFunction = (error?: unknown) => void;
30
+ /**
31
+ * Express middleware function type
32
+ *
33
+ * @param req - Express request object
34
+ * @param res - Express response object
35
+ * @param next - Next function to pass control
36
+ */
37
+ type ExpressMiddleware = (req: ExpressRequest, res: ExpressResponse, next: ExpressNextFunction) => void;
38
+ /**
39
+ * Create Express middleware for automatic trace flushing
40
+ *
41
+ * Flushes traces when the response finishes (after res.send/res.json).
42
+ * This is fire-and-forget and doesn't block the response.
43
+ *
44
+ * @returns Express middleware function
45
+ *
46
+ * @example
47
+ * // Global middleware
48
+ * app.use(createMiddleware());
49
+ *
50
+ * @example
51
+ * // Per-route middleware
52
+ * app.post('/chat', createMiddleware(), async (req, res) => {
53
+ * res.json({ ok: true });
54
+ * });
55
+ */
56
+ declare function createMiddleware(): ExpressMiddleware;
57
+
58
+ type express_ExpressMiddleware = ExpressMiddleware;
59
+ type express_ExpressNextFunction = ExpressNextFunction;
60
+ type express_ExpressRequest = ExpressRequest;
61
+ type express_ExpressResponse = ExpressResponse;
62
+ declare const express_createMiddleware: typeof createMiddleware;
63
+ declare namespace express {
64
+ export { type express_ExpressMiddleware as ExpressMiddleware, type express_ExpressNextFunction as ExpressNextFunction, type express_ExpressRequest as ExpressRequest, type express_ExpressResponse as ExpressResponse, express_createMiddleware as createMiddleware };
65
+ }
66
+
67
+ export { type ExpressRequest as E, type ExpressResponse as a, type ExpressNextFunction as b, type ExpressMiddleware as c, createMiddleware as d, express as e };
@@ -0,0 +1 @@
1
+ export { c as ExpressMiddleware, b as ExpressNextFunction, E as ExpressRequest, a as ExpressResponse, d as createMiddleware } from './express-Dt5wT6_n.mjs';
@@ -0,0 +1 @@
1
+ export { c as ExpressMiddleware, b as ExpressNextFunction, E as ExpressRequest, a as ExpressResponse, d as createMiddleware } from './express-Dt5wT6_n.js';
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ /* @lelemondev/sdk - LLM Observability */
4
+
5
+ async function flush() {
6
+ }
7
+
8
+ // src/integrations/express.ts
9
+ function createMiddleware() {
10
+ return (_req, res, next) => {
11
+ res.on("finish", () => {
12
+ flush().catch(() => {
13
+ });
14
+ });
15
+ next();
16
+ };
17
+ }
18
+
19
+ exports.createMiddleware = createMiddleware;
20
+ //# sourceMappingURL=express.js.map
21
+ //# sourceMappingURL=express.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/config.ts","../src/integrations/express.ts"],"names":[],"mappings":";;;;AAuEA,eAAsB,KAAA,GAAuB;AAI7C;;;ACDO,SAAS,gBAAA,GAAsC;AACpD,EAAA,OAAO,CAAC,IAAA,EAAM,GAAA,EAAK,IAAA,KAAS;AAE1B,IAAA,GAAA,CAAI,EAAA,CAAG,UAAU,MAAM;AACrB,MAAA,KAAA,EAAM,CAAE,MAAM,MAAM;AAAA,MAEpB,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,IAAA,EAAK;AAAA,EACP,CAAA;AACF","file":"express.js","sourcesContent":["/**\n * Global Configuration\n *\n * Manages SDK configuration and transport instance.\n */\n\nimport type { LelemonConfig } from './types';\nimport { Transport } from './transport';\n\n// ─────────────────────────────────────────────────────────────\n// Global State\n// ─────────────────────────────────────────────────────────────\n\nlet globalConfig: LelemonConfig = {};\nlet globalTransport: Transport | null = null;\nlet initialized = false;\n\n// ─────────────────────────────────────────────────────────────\n// Configuration\n// ─────────────────────────────────────────────────────────────\n\nconst DEFAULT_ENDPOINT = 'https://api.lelemon.dev';\n\n/**\n * Initialize the SDK\n * Call once at app startup\n */\nexport function init(config: LelemonConfig = {}): void {\n globalConfig = config;\n globalTransport = createTransport(config);\n initialized = true;\n}\n\n/**\n * Get current config\n */\nexport function getConfig(): LelemonConfig {\n return globalConfig;\n}\n\n/**\n * Check if SDK is initialized\n */\nexport function isInitialized(): boolean {\n return initialized;\n}\n\n/**\n * Check if SDK is enabled\n */\nexport function isEnabled(): boolean {\n return getTransport().isEnabled();\n}\n\n// ─────────────────────────────────────────────────────────────\n// Transport\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Get or create transport instance\n */\nexport function getTransport(): Transport {\n if (!globalTransport) {\n globalTransport = createTransport(globalConfig);\n }\n return globalTransport;\n}\n\n/**\n * Flush all pending traces\n */\nexport async function flush(): Promise<void> {\n if (globalTransport) {\n await globalTransport.flush();\n }\n}\n\n/**\n * Create transport instance\n */\nfunction createTransport(config: LelemonConfig): Transport {\n const apiKey = config.apiKey ?? getEnvVar('LELEMON_API_KEY');\n\n if (!apiKey && !config.disabled) {\n console.warn(\n '[Lelemon] No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled.'\n );\n }\n\n return new Transport({\n apiKey: apiKey ?? '',\n endpoint: config.endpoint ?? DEFAULT_ENDPOINT,\n debug: config.debug ?? false,\n disabled: config.disabled ?? !apiKey,\n batchSize: config.batchSize,\n flushIntervalMs: config.flushIntervalMs,\n requestTimeoutMs: config.requestTimeoutMs,\n });\n}\n\n/**\n * Get environment variable (works in Node and edge)\n */\nfunction getEnvVar(name: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[name];\n }\n return undefined;\n}\n","/**\n * Express Integration\n *\n * Middleware that automatically flushes traces when response finishes.\n *\n * @example\n * import express from 'express';\n * import { createMiddleware } from '@lelemondev/sdk/express';\n *\n * const app = express();\n * app.use(createMiddleware());\n */\n\nimport { flush } from '../core/config';\n\n// ─────────────────────────────────────────────────────────────\n// Types (minimal to avoid requiring express as dependency)\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Minimal Express request type (avoids requiring express as dependency)\n */\nexport interface ExpressRequest {\n [key: string]: unknown;\n}\n\n/**\n * Minimal Express response type (avoids requiring express as dependency)\n */\nexport interface ExpressResponse {\n on(event: 'finish' | 'close' | 'error', listener: () => void): this;\n [key: string]: unknown;\n}\n\n/**\n * Express next function type\n */\nexport type ExpressNextFunction = (error?: unknown) => void;\n\n/**\n * Express middleware function type\n *\n * @param req - Express request object\n * @param res - Express response object\n * @param next - Next function to pass control\n */\nexport type ExpressMiddleware = (\n req: ExpressRequest,\n res: ExpressResponse,\n next: ExpressNextFunction\n) => void;\n\n// ─────────────────────────────────────────────────────────────\n// Middleware\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Create Express middleware for automatic trace flushing\n *\n * Flushes traces when the response finishes (after res.send/res.json).\n * This is fire-and-forget and doesn't block the response.\n *\n * @returns Express middleware function\n *\n * @example\n * // Global middleware\n * app.use(createMiddleware());\n *\n * @example\n * // Per-route middleware\n * app.post('/chat', createMiddleware(), async (req, res) => {\n * res.json({ ok: true });\n * });\n */\nexport function createMiddleware(): ExpressMiddleware {\n return (_req, res, next) => {\n // Flush when response is finished (after headers + body sent)\n res.on('finish', () => {\n flush().catch(() => {\n // Silently ignore flush errors - fire and forget\n });\n });\n\n next();\n };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /* @lelemondev/sdk - LLM Observability */
2
+
3
+ async function flush() {
4
+ }
5
+
6
+ // src/integrations/express.ts
7
+ function createMiddleware() {
8
+ return (_req, res, next) => {
9
+ res.on("finish", () => {
10
+ flush().catch(() => {
11
+ });
12
+ });
13
+ next();
14
+ };
15
+ }
16
+
17
+ export { createMiddleware };
18
+ //# sourceMappingURL=express.mjs.map
19
+ //# sourceMappingURL=express.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/config.ts","../src/integrations/express.ts"],"names":[],"mappings":";;AAuEA,eAAsB,KAAA,GAAuB;AAI7C;;;ACDO,SAAS,gBAAA,GAAsC;AACpD,EAAA,OAAO,CAAC,IAAA,EAAM,GAAA,EAAK,IAAA,KAAS;AAE1B,IAAA,GAAA,CAAI,EAAA,CAAG,UAAU,MAAM;AACrB,MAAA,KAAA,EAAM,CAAE,MAAM,MAAM;AAAA,MAEpB,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,IAAA,EAAK;AAAA,EACP,CAAA;AACF","file":"express.mjs","sourcesContent":["/**\n * Global Configuration\n *\n * Manages SDK configuration and transport instance.\n */\n\nimport type { LelemonConfig } from './types';\nimport { Transport } from './transport';\n\n// ─────────────────────────────────────────────────────────────\n// Global State\n// ─────────────────────────────────────────────────────────────\n\nlet globalConfig: LelemonConfig = {};\nlet globalTransport: Transport | null = null;\nlet initialized = false;\n\n// ─────────────────────────────────────────────────────────────\n// Configuration\n// ─────────────────────────────────────────────────────────────\n\nconst DEFAULT_ENDPOINT = 'https://api.lelemon.dev';\n\n/**\n * Initialize the SDK\n * Call once at app startup\n */\nexport function init(config: LelemonConfig = {}): void {\n globalConfig = config;\n globalTransport = createTransport(config);\n initialized = true;\n}\n\n/**\n * Get current config\n */\nexport function getConfig(): LelemonConfig {\n return globalConfig;\n}\n\n/**\n * Check if SDK is initialized\n */\nexport function isInitialized(): boolean {\n return initialized;\n}\n\n/**\n * Check if SDK is enabled\n */\nexport function isEnabled(): boolean {\n return getTransport().isEnabled();\n}\n\n// ─────────────────────────────────────────────────────────────\n// Transport\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Get or create transport instance\n */\nexport function getTransport(): Transport {\n if (!globalTransport) {\n globalTransport = createTransport(globalConfig);\n }\n return globalTransport;\n}\n\n/**\n * Flush all pending traces\n */\nexport async function flush(): Promise<void> {\n if (globalTransport) {\n await globalTransport.flush();\n }\n}\n\n/**\n * Create transport instance\n */\nfunction createTransport(config: LelemonConfig): Transport {\n const apiKey = config.apiKey ?? getEnvVar('LELEMON_API_KEY');\n\n if (!apiKey && !config.disabled) {\n console.warn(\n '[Lelemon] No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled.'\n );\n }\n\n return new Transport({\n apiKey: apiKey ?? '',\n endpoint: config.endpoint ?? DEFAULT_ENDPOINT,\n debug: config.debug ?? false,\n disabled: config.disabled ?? !apiKey,\n batchSize: config.batchSize,\n flushIntervalMs: config.flushIntervalMs,\n requestTimeoutMs: config.requestTimeoutMs,\n });\n}\n\n/**\n * Get environment variable (works in Node and edge)\n */\nfunction getEnvVar(name: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[name];\n }\n return undefined;\n}\n","/**\n * Express Integration\n *\n * Middleware that automatically flushes traces when response finishes.\n *\n * @example\n * import express from 'express';\n * import { createMiddleware } from '@lelemondev/sdk/express';\n *\n * const app = express();\n * app.use(createMiddleware());\n */\n\nimport { flush } from '../core/config';\n\n// ─────────────────────────────────────────────────────────────\n// Types (minimal to avoid requiring express as dependency)\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Minimal Express request type (avoids requiring express as dependency)\n */\nexport interface ExpressRequest {\n [key: string]: unknown;\n}\n\n/**\n * Minimal Express response type (avoids requiring express as dependency)\n */\nexport interface ExpressResponse {\n on(event: 'finish' | 'close' | 'error', listener: () => void): this;\n [key: string]: unknown;\n}\n\n/**\n * Express next function type\n */\nexport type ExpressNextFunction = (error?: unknown) => void;\n\n/**\n * Express middleware function type\n *\n * @param req - Express request object\n * @param res - Express response object\n * @param next - Next function to pass control\n */\nexport type ExpressMiddleware = (\n req: ExpressRequest,\n res: ExpressResponse,\n next: ExpressNextFunction\n) => void;\n\n// ─────────────────────────────────────────────────────────────\n// Middleware\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Create Express middleware for automatic trace flushing\n *\n * Flushes traces when the response finishes (after res.send/res.json).\n * This is fire-and-forget and doesn't block the response.\n *\n * @returns Express middleware function\n *\n * @example\n * // Global middleware\n * app.use(createMiddleware());\n *\n * @example\n * // Per-route middleware\n * app.post('/chat', createMiddleware(), async (req, res) => {\n * res.json({ ok: true });\n * });\n */\nexport function createMiddleware(): ExpressMiddleware {\n return (_req, res, next) => {\n // Flush when response is finished (after headers + body sent)\n res.on('finish', () => {\n flush().catch(() => {\n // Silently ignore flush errors - fire and forget\n });\n });\n\n next();\n };\n}\n"]}
@@ -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 '@lelemondev/sdk/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 '@lelemondev/sdk/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 };
@@ -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 '@lelemondev/sdk/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 '@lelemondev/sdk/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 };
@@ -0,0 +1 @@
1
+ export { E as ExecutionContext, H as HonoContext, b as HonoMiddleware, a as HonoNextFunction, c as createMiddleware } from './hono-Dzmu77iW.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-Dzmu77iW.js';
package/dist/hono.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ /* @lelemondev/sdk - LLM Observability */
4
+
5
+ async function flush() {
6
+ }
7
+
8
+ // src/integrations/hono.ts
9
+ function createMiddleware() {
10
+ return async (c, next) => {
11
+ await next();
12
+ if (c.executionCtx?.waitUntil) {
13
+ c.executionCtx.waitUntil(flush());
14
+ } else {
15
+ flush().catch(() => {
16
+ });
17
+ }
18
+ };
19
+ }
20
+
21
+ exports.createMiddleware = createMiddleware;
22
+ //# sourceMappingURL=hono.js.map
23
+ //# sourceMappingURL=hono.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/config.ts","../src/integrations/hono.ts"],"names":[],"mappings":";;;;AAuEA,eAAsB,KAAA,GAAuB;AAI7C;;;ACQO,SAAS,gBAAA,GAAmC;AACjD,EAAA,OAAO,OAAO,GAAG,IAAA,KAAS;AACxB,IAAA,MAAM,IAAA,EAAK;AAGX,IAAA,IAAI,CAAA,CAAE,cAAc,SAAA,EAAW;AAC7B,MAAA,CAAA,CAAE,YAAA,CAAa,SAAA,CAAU,KAAA,EAAO,CAAA;AAAA,IAClC,CAAA,MAAO;AAEL,MAAA,KAAA,EAAM,CAAE,MAAM,MAAM;AAAA,MAAC,CAAC,CAAA;AAAA,IACxB;AAAA,EACF,CAAA;AACF","file":"hono.js","sourcesContent":["/**\n * Global Configuration\n *\n * Manages SDK configuration and transport instance.\n */\n\nimport type { LelemonConfig } from './types';\nimport { Transport } from './transport';\n\n// ─────────────────────────────────────────────────────────────\n// Global State\n// ─────────────────────────────────────────────────────────────\n\nlet globalConfig: LelemonConfig = {};\nlet globalTransport: Transport | null = null;\nlet initialized = false;\n\n// ─────────────────────────────────────────────────────────────\n// Configuration\n// ─────────────────────────────────────────────────────────────\n\nconst DEFAULT_ENDPOINT = 'https://api.lelemon.dev';\n\n/**\n * Initialize the SDK\n * Call once at app startup\n */\nexport function init(config: LelemonConfig = {}): void {\n globalConfig = config;\n globalTransport = createTransport(config);\n initialized = true;\n}\n\n/**\n * Get current config\n */\nexport function getConfig(): LelemonConfig {\n return globalConfig;\n}\n\n/**\n * Check if SDK is initialized\n */\nexport function isInitialized(): boolean {\n return initialized;\n}\n\n/**\n * Check if SDK is enabled\n */\nexport function isEnabled(): boolean {\n return getTransport().isEnabled();\n}\n\n// ─────────────────────────────────────────────────────────────\n// Transport\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Get or create transport instance\n */\nexport function getTransport(): Transport {\n if (!globalTransport) {\n globalTransport = createTransport(globalConfig);\n }\n return globalTransport;\n}\n\n/**\n * Flush all pending traces\n */\nexport async function flush(): Promise<void> {\n if (globalTransport) {\n await globalTransport.flush();\n }\n}\n\n/**\n * Create transport instance\n */\nfunction createTransport(config: LelemonConfig): Transport {\n const apiKey = config.apiKey ?? getEnvVar('LELEMON_API_KEY');\n\n if (!apiKey && !config.disabled) {\n console.warn(\n '[Lelemon] No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled.'\n );\n }\n\n return new Transport({\n apiKey: apiKey ?? '',\n endpoint: config.endpoint ?? DEFAULT_ENDPOINT,\n debug: config.debug ?? false,\n disabled: config.disabled ?? !apiKey,\n batchSize: config.batchSize,\n flushIntervalMs: config.flushIntervalMs,\n requestTimeoutMs: config.requestTimeoutMs,\n });\n}\n\n/**\n * Get environment variable (works in Node and edge)\n */\nfunction getEnvVar(name: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[name];\n }\n return undefined;\n}\n","/**\n * Hono Integration\n *\n * Middleware for Hono framework (Cloudflare Workers, Deno, Bun, Node.js).\n * Uses executionCtx.waitUntil() when available for non-blocking flush.\n *\n * @example\n * import { Hono } from 'hono';\n * import { createMiddleware } from '@lelemondev/sdk/hono';\n *\n * const app = new Hono();\n * app.use(createMiddleware());\n */\n\nimport { flush } from '../core/config';\n\n// ─────────────────────────────────────────────────────────────\n// Types (minimal to avoid requiring hono as dependency)\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Execution context for edge runtimes (Cloudflare Workers, Deno Deploy)\n */\nexport interface ExecutionContext {\n waitUntil(promise: Promise<unknown>): void;\n passThroughOnException(): void;\n}\n\n/**\n * Minimal Hono context type (avoids requiring hono as dependency)\n */\nexport interface HonoContext {\n req: {\n raw: Request;\n [key: string]: unknown;\n };\n res: Response | undefined;\n executionCtx?: ExecutionContext;\n [key: string]: unknown;\n}\n\n/**\n * Hono next function type\n */\nexport type HonoNextFunction = () => Promise<void>;\n\n/**\n * Hono middleware function type\n *\n * @param c - Hono context object\n * @param next - Next function to continue middleware chain\n */\nexport type HonoMiddleware = (c: HonoContext, next: HonoNextFunction) => Promise<void>;\n\n// ─────────────────────────────────────────────────────────────\n// Middleware\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Create Hono middleware for automatic trace flushing\n *\n * On Cloudflare Workers/Deno Deploy: uses executionCtx.waitUntil() for non-blocking flush\n * On Node.js/Bun: flushes after response (fire-and-forget)\n *\n * @returns Hono middleware function\n *\n * @example\n * import { Hono } from 'hono';\n * import { createMiddleware } from '@lelemondev/sdk/hono';\n *\n * const app = new Hono();\n *\n * // Global middleware\n * app.use(createMiddleware());\n *\n * app.post('/chat', async (c) => {\n * const openai = observe(new OpenAI());\n * const result = await openai.chat.completions.create({...});\n * return c.json(result);\n * });\n *\n * export default app;\n */\nexport function createMiddleware(): HonoMiddleware {\n return async (c, next) => {\n await next();\n\n // Use waitUntil if available (Cloudflare Workers, Deno Deploy)\n if (c.executionCtx?.waitUntil) {\n c.executionCtx.waitUntil(flush());\n } else {\n // Fire-and-forget for Node.js/Bun\n flush().catch(() => {});\n }\n };\n}\n"]}
package/dist/hono.mjs ADDED
@@ -0,0 +1,21 @@
1
+ /* @lelemondev/sdk - LLM Observability */
2
+
3
+ async function flush() {
4
+ }
5
+
6
+ // src/integrations/hono.ts
7
+ function createMiddleware() {
8
+ return async (c, next) => {
9
+ await next();
10
+ if (c.executionCtx?.waitUntil) {
11
+ c.executionCtx.waitUntil(flush());
12
+ } else {
13
+ flush().catch(() => {
14
+ });
15
+ }
16
+ };
17
+ }
18
+
19
+ export { createMiddleware };
20
+ //# sourceMappingURL=hono.mjs.map
21
+ //# sourceMappingURL=hono.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/config.ts","../src/integrations/hono.ts"],"names":[],"mappings":";;AAuEA,eAAsB,KAAA,GAAuB;AAI7C;;;ACQO,SAAS,gBAAA,GAAmC;AACjD,EAAA,OAAO,OAAO,GAAG,IAAA,KAAS;AACxB,IAAA,MAAM,IAAA,EAAK;AAGX,IAAA,IAAI,CAAA,CAAE,cAAc,SAAA,EAAW;AAC7B,MAAA,CAAA,CAAE,YAAA,CAAa,SAAA,CAAU,KAAA,EAAO,CAAA;AAAA,IAClC,CAAA,MAAO;AAEL,MAAA,KAAA,EAAM,CAAE,MAAM,MAAM;AAAA,MAAC,CAAC,CAAA;AAAA,IACxB;AAAA,EACF,CAAA;AACF","file":"hono.mjs","sourcesContent":["/**\n * Global Configuration\n *\n * Manages SDK configuration and transport instance.\n */\n\nimport type { LelemonConfig } from './types';\nimport { Transport } from './transport';\n\n// ─────────────────────────────────────────────────────────────\n// Global State\n// ─────────────────────────────────────────────────────────────\n\nlet globalConfig: LelemonConfig = {};\nlet globalTransport: Transport | null = null;\nlet initialized = false;\n\n// ─────────────────────────────────────────────────────────────\n// Configuration\n// ─────────────────────────────────────────────────────────────\n\nconst DEFAULT_ENDPOINT = 'https://api.lelemon.dev';\n\n/**\n * Initialize the SDK\n * Call once at app startup\n */\nexport function init(config: LelemonConfig = {}): void {\n globalConfig = config;\n globalTransport = createTransport(config);\n initialized = true;\n}\n\n/**\n * Get current config\n */\nexport function getConfig(): LelemonConfig {\n return globalConfig;\n}\n\n/**\n * Check if SDK is initialized\n */\nexport function isInitialized(): boolean {\n return initialized;\n}\n\n/**\n * Check if SDK is enabled\n */\nexport function isEnabled(): boolean {\n return getTransport().isEnabled();\n}\n\n// ─────────────────────────────────────────────────────────────\n// Transport\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Get or create transport instance\n */\nexport function getTransport(): Transport {\n if (!globalTransport) {\n globalTransport = createTransport(globalConfig);\n }\n return globalTransport;\n}\n\n/**\n * Flush all pending traces\n */\nexport async function flush(): Promise<void> {\n if (globalTransport) {\n await globalTransport.flush();\n }\n}\n\n/**\n * Create transport instance\n */\nfunction createTransport(config: LelemonConfig): Transport {\n const apiKey = config.apiKey ?? getEnvVar('LELEMON_API_KEY');\n\n if (!apiKey && !config.disabled) {\n console.warn(\n '[Lelemon] No API key provided. Set apiKey in init() or LELEMON_API_KEY env var. Tracing disabled.'\n );\n }\n\n return new Transport({\n apiKey: apiKey ?? '',\n endpoint: config.endpoint ?? DEFAULT_ENDPOINT,\n debug: config.debug ?? false,\n disabled: config.disabled ?? !apiKey,\n batchSize: config.batchSize,\n flushIntervalMs: config.flushIntervalMs,\n requestTimeoutMs: config.requestTimeoutMs,\n });\n}\n\n/**\n * Get environment variable (works in Node and edge)\n */\nfunction getEnvVar(name: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[name];\n }\n return undefined;\n}\n","/**\n * Hono Integration\n *\n * Middleware for Hono framework (Cloudflare Workers, Deno, Bun, Node.js).\n * Uses executionCtx.waitUntil() when available for non-blocking flush.\n *\n * @example\n * import { Hono } from 'hono';\n * import { createMiddleware } from '@lelemondev/sdk/hono';\n *\n * const app = new Hono();\n * app.use(createMiddleware());\n */\n\nimport { flush } from '../core/config';\n\n// ─────────────────────────────────────────────────────────────\n// Types (minimal to avoid requiring hono as dependency)\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Execution context for edge runtimes (Cloudflare Workers, Deno Deploy)\n */\nexport interface ExecutionContext {\n waitUntil(promise: Promise<unknown>): void;\n passThroughOnException(): void;\n}\n\n/**\n * Minimal Hono context type (avoids requiring hono as dependency)\n */\nexport interface HonoContext {\n req: {\n raw: Request;\n [key: string]: unknown;\n };\n res: Response | undefined;\n executionCtx?: ExecutionContext;\n [key: string]: unknown;\n}\n\n/**\n * Hono next function type\n */\nexport type HonoNextFunction = () => Promise<void>;\n\n/**\n * Hono middleware function type\n *\n * @param c - Hono context object\n * @param next - Next function to continue middleware chain\n */\nexport type HonoMiddleware = (c: HonoContext, next: HonoNextFunction) => Promise<void>;\n\n// ─────────────────────────────────────────────────────────────\n// Middleware\n// ─────────────────────────────────────────────────────────────\n\n/**\n * Create Hono middleware for automatic trace flushing\n *\n * On Cloudflare Workers/Deno Deploy: uses executionCtx.waitUntil() for non-blocking flush\n * On Node.js/Bun: flushes after response (fire-and-forget)\n *\n * @returns Hono middleware function\n *\n * @example\n * import { Hono } from 'hono';\n * import { createMiddleware } from '@lelemondev/sdk/hono';\n *\n * const app = new Hono();\n *\n * // Global middleware\n * app.use(createMiddleware());\n *\n * app.post('/chat', async (c) => {\n * const openai = observe(new OpenAI());\n * const result = await openai.chat.completions.create({...});\n * return c.json(result);\n * });\n *\n * export default app;\n */\nexport function createMiddleware(): HonoMiddleware {\n return async (c, next) => {\n await next();\n\n // Use waitUntil if available (Cloudflare Workers, Deno Deploy)\n if (c.executionCtx?.waitUntil) {\n c.executionCtx.waitUntil(flush());\n } else {\n // Fire-and-forget for Node.js/Bun\n flush().catch(() => {});\n }\n };\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -17,7 +17,7 @@ interface LelemonConfig {
17
17
  /** Request timeout in ms (default: 10000) */
18
18
  requestTimeoutMs?: number;
19
19
  }
20
- type ProviderName = 'openai' | 'anthropic' | 'google' | 'bedrock' | 'unknown';
20
+ type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'bedrock' | 'openrouter' | 'unknown';
21
21
  interface ObserveOptions {
22
22
  /** Session ID to group related calls */
23
23
  sessionId?: string;
@@ -58,7 +58,7 @@ declare function flush(): Promise<void>;
58
58
  /**
59
59
  * Wrap an LLM client with automatic tracing
60
60
  *
61
- * @param client - OpenAI or Anthropic client instance
61
+ * @param client - OpenAI, Anthropic, or Bedrock client instance
62
62
  * @param options - Optional context (sessionId, userId, etc.)
63
63
  * @returns The wrapped client with the same type
64
64
  *
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ interface LelemonConfig {
17
17
  /** Request timeout in ms (default: 10000) */
18
18
  requestTimeoutMs?: number;
19
19
  }
20
- type ProviderName = 'openai' | 'anthropic' | 'google' | 'bedrock' | 'unknown';
20
+ type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'bedrock' | 'openrouter' | 'unknown';
21
21
  interface ObserveOptions {
22
22
  /** Session ID to group related calls */
23
23
  sessionId?: string;
@@ -58,7 +58,7 @@ declare function flush(): Promise<void>;
58
58
  /**
59
59
  * Wrap an LLM client with automatic tracing
60
60
  *
61
- * @param client - OpenAI or Anthropic client instance
61
+ * @param client - OpenAI, Anthropic, or Bedrock client instance
62
62
  * @param options - Optional context (sessionId, userId, etc.)
63
63
  * @returns The wrapped client with the same type
64
64
  *