lightrace 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +14 -35
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +60 -84
- package/dist/client.js.map +1 -1
- package/dist/dev-server.d.ts +18 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/dev-server.js +95 -0
- package/dist/dev-server.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/_base.d.ts +70 -0
- package/dist/integrations/_base.d.ts.map +1 -0
- package/dist/integrations/_base.js +167 -0
- package/dist/integrations/_base.js.map +1 -0
- package/dist/integrations/anthropic.d.ts +15 -0
- package/dist/integrations/anthropic.d.ts.map +1 -0
- package/dist/integrations/anthropic.js +229 -0
- package/dist/integrations/anthropic.js.map +1 -0
- package/dist/integrations/llamaindex.d.ts +14 -0
- package/dist/integrations/llamaindex.d.ts.map +1 -0
- package/dist/integrations/llamaindex.js +222 -0
- package/dist/integrations/llamaindex.js.map +1 -0
- package/dist/integrations/openai.d.ts +17 -0
- package/dist/integrations/openai.d.ts.map +1 -0
- package/dist/integrations/openai.js +259 -0
- package/dist/integrations/openai.js.map +1 -0
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +2 -1
- package/dist/trace.js.map +1 -1
- package/dist/types.d.ts +2 -39
- package/dist/types.d.ts.map +1 -1
- package/package.json +31 -5
- package/dist/security.d.ts +0 -20
- package/dist/security.d.ts.map +0 -1
- package/dist/security.js +0 -46
- package/dist/security.js.map +0 -1
- package/dist/tool-client.d.ts +0 -46
- package/dist/tool-client.d.ts.map +0 -1
- package/dist/tool-client.js +0 -237
- package/dist/tool-client.js.map +0 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* Main Lightrace SDK client.
|
|
3
3
|
*/
|
|
4
4
|
import { LightraceOtelExporter } from "./otel-exporter.js";
|
|
5
|
+
import { DevServer } from "./dev-server.js";
|
|
5
6
|
import { Observation } from "./observation.js";
|
|
6
7
|
import type { UsageDetails } from "./types.js";
|
|
7
8
|
export interface LightraceOptions {
|
|
8
9
|
publicKey?: string;
|
|
9
10
|
secretKey?: string;
|
|
10
11
|
host?: string;
|
|
11
|
-
/** WebSocket host for tool connections (defaults to host if not set). */
|
|
12
|
-
wsHost?: string;
|
|
13
12
|
flushAt?: number;
|
|
14
13
|
flushInterval?: number;
|
|
15
14
|
timeout?: number;
|
|
@@ -18,48 +17,34 @@ export interface LightraceOptions {
|
|
|
18
17
|
userId?: string;
|
|
19
18
|
/** Default session ID for all traces. */
|
|
20
19
|
sessionId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Start the embedded dev server for tool invocation from the dashboard.
|
|
22
|
+
* Default: true. Set to false in production environments.
|
|
23
|
+
*/
|
|
24
|
+
devServer?: boolean;
|
|
25
|
+
/** Port for the dev server (0 = auto-discover free port). Default: 0. */
|
|
26
|
+
devServerPort?: number;
|
|
21
27
|
}
|
|
22
28
|
export declare class Lightrace {
|
|
23
29
|
private static instance;
|
|
24
30
|
private otelExporter;
|
|
25
|
-
private
|
|
26
|
-
private toolConnectTimer;
|
|
31
|
+
private _devServer;
|
|
27
32
|
private enabled;
|
|
28
33
|
private host;
|
|
29
|
-
private wsHost;
|
|
30
34
|
private publicKey;
|
|
31
35
|
private secretKey;
|
|
32
|
-
|
|
36
|
+
private devServerEnabled;
|
|
37
|
+
private devServerPort;
|
|
33
38
|
readonly userId: string | undefined;
|
|
34
|
-
/** Default session ID for all traces. */
|
|
35
39
|
readonly sessionId: string | undefined;
|
|
36
40
|
constructor(options?: LightraceOptions);
|
|
37
41
|
static getInstance(): Lightrace | null;
|
|
38
|
-
/** Get the OTel exporter (used by Observation). */
|
|
39
42
|
getOtelExporter(): LightraceOtelExporter | null;
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
* Explicitly start the tool WebSocket client.
|
|
44
|
-
* Call this after all tools have been registered (via trace() or registerTools).
|
|
45
|
-
* Cancels the deferred auto-connect timer if still pending.
|
|
46
|
-
*/
|
|
47
|
-
connectTools(): void;
|
|
48
|
-
/**
|
|
49
|
-
* Register tools for remote invocation.
|
|
50
|
-
*
|
|
51
|
-
* @param tools - Array of tool descriptors with name, fn, and optional inputSchema.
|
|
52
|
-
*/
|
|
53
|
-
registerTools(...tools: Array<{
|
|
54
|
-
name: string;
|
|
55
|
-
fn: (...args: unknown[]) => unknown;
|
|
56
|
-
inputSchema?: Record<string, unknown> | null;
|
|
57
|
-
}>): void;
|
|
43
|
+
getDevServer(): DevServer | null;
|
|
44
|
+
private startDevServer;
|
|
45
|
+
private registerToolsHttp;
|
|
58
46
|
flush(): void;
|
|
59
47
|
shutdown(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Create a span observation imperatively.
|
|
62
|
-
*/
|
|
63
48
|
span(opts: {
|
|
64
49
|
name: string;
|
|
65
50
|
input?: unknown;
|
|
@@ -67,9 +52,6 @@ export declare class Lightrace {
|
|
|
67
52
|
traceId?: string;
|
|
68
53
|
parentObservationId?: string;
|
|
69
54
|
}): Observation;
|
|
70
|
-
/**
|
|
71
|
-
* Create a generation observation imperatively.
|
|
72
|
-
*/
|
|
73
55
|
generation(opts: {
|
|
74
56
|
name: string;
|
|
75
57
|
input?: unknown;
|
|
@@ -79,9 +61,6 @@ export declare class Lightrace {
|
|
|
79
61
|
traceId?: string;
|
|
80
62
|
parentObservationId?: string;
|
|
81
63
|
}): Observation;
|
|
82
|
-
/**
|
|
83
|
-
* Create an event observation imperatively (auto-ended).
|
|
84
|
-
*/
|
|
85
64
|
event(opts: {
|
|
86
65
|
name: string;
|
|
87
66
|
input?: unknown;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],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2,34 +2,32 @@
|
|
|
2
2
|
* Main Lightrace SDK client.
|
|
3
3
|
*/
|
|
4
4
|
import { LightraceOtelExporter } from "./otel-exporter.js";
|
|
5
|
-
import
|
|
5
|
+
import { AS_ROOT, TRACE_NAME } from "./otel-exporter.js";
|
|
6
6
|
import { _setOtelExporter, _setClientDefaults, _getTraceContext, _getToolRegistry, } from "./trace.js";
|
|
7
|
-
import {
|
|
7
|
+
import { DevServer } from "./dev-server.js";
|
|
8
8
|
import { Observation } from "./observation.js";
|
|
9
9
|
import { generateId } from "./utils.js";
|
|
10
10
|
export class Lightrace {
|
|
11
11
|
static instance = null;
|
|
12
12
|
otelExporter = null;
|
|
13
|
-
|
|
14
|
-
toolConnectTimer = null;
|
|
13
|
+
_devServer = null;
|
|
15
14
|
enabled;
|
|
16
15
|
host;
|
|
17
|
-
wsHost;
|
|
18
16
|
publicKey;
|
|
19
17
|
secretKey;
|
|
20
|
-
|
|
18
|
+
devServerEnabled;
|
|
19
|
+
devServerPort;
|
|
21
20
|
userId;
|
|
22
|
-
/** Default session ID for all traces. */
|
|
23
21
|
sessionId;
|
|
24
22
|
constructor(options = {}) {
|
|
25
23
|
this.publicKey = options.publicKey ?? process.env.LIGHTRACE_PUBLIC_KEY ?? "";
|
|
26
24
|
this.secretKey = options.secretKey ?? process.env.LIGHTRACE_SECRET_KEY ?? "";
|
|
27
25
|
this.host = (options.host ?? process.env.LIGHTRACE_HOST ?? "http://localhost:3002").replace(/\/$/, "");
|
|
28
|
-
this.wsHost =
|
|
29
|
-
(options.wsHost ?? process.env.LIGHTRACE_WS_HOST ?? "").replace(/\/$/, "") || null;
|
|
30
26
|
this.enabled = options.enabled !== false;
|
|
31
27
|
this.userId = options.userId;
|
|
32
28
|
this.sessionId = options.sessionId;
|
|
29
|
+
this.devServerEnabled = options.devServer !== false;
|
|
30
|
+
this.devServerPort = options.devServerPort ?? 0;
|
|
33
31
|
if (!this.enabled)
|
|
34
32
|
return;
|
|
35
33
|
this.otelExporter = new LightraceOtelExporter({
|
|
@@ -42,106 +40,87 @@ export class Lightrace {
|
|
|
42
40
|
_setOtelExporter(this.otelExporter);
|
|
43
41
|
_setClientDefaults({ userId: this.userId, sessionId: this.sessionId });
|
|
44
42
|
Lightrace.instance = this;
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (this.devServerEnabled) {
|
|
44
|
+
this.startDevServer();
|
|
45
|
+
}
|
|
47
46
|
}
|
|
48
47
|
static getInstance() {
|
|
49
48
|
return Lightrace.instance;
|
|
50
49
|
}
|
|
51
|
-
/** Get the OTel exporter (used by Observation). */
|
|
52
50
|
getOtelExporter() {
|
|
53
51
|
return this.otelExporter;
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.toolConnectTimer = null;
|
|
58
|
-
if (!this.enabled || this.toolClient)
|
|
59
|
-
return;
|
|
60
|
-
const registry = _getToolRegistry();
|
|
61
|
-
if (registry.size === 0)
|
|
62
|
-
return;
|
|
63
|
-
this.startToolClient();
|
|
53
|
+
getDevServer() {
|
|
54
|
+
return this._devServer;
|
|
64
55
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
host: this.wsHost ?? this.host,
|
|
56
|
+
// -- Dev server + tool registration -----------------------------------------
|
|
57
|
+
startDevServer() {
|
|
58
|
+
this._devServer = new DevServer({
|
|
59
|
+
port: this.devServerPort,
|
|
70
60
|
publicKey: this.publicKey,
|
|
71
|
-
secretKey: this.secretKey,
|
|
72
61
|
});
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
clearTimeout(this.toolConnectTimer);
|
|
83
|
-
this.toolConnectTimer = null;
|
|
84
|
-
}
|
|
85
|
-
if (!this.enabled)
|
|
86
|
-
return;
|
|
87
|
-
this.startToolClient();
|
|
62
|
+
this._devServer
|
|
63
|
+
.start()
|
|
64
|
+
.then((port) => {
|
|
65
|
+
console.log(`[lightrace] Dev server listening on http://127.0.0.1:${port}`);
|
|
66
|
+
this.registerToolsHttp();
|
|
67
|
+
})
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error("[lightrace] Failed to start dev server:", err);
|
|
70
|
+
});
|
|
88
71
|
}
|
|
89
|
-
|
|
90
|
-
* Register tools for remote invocation.
|
|
91
|
-
*
|
|
92
|
-
* @param tools - Array of tool descriptors with name, fn, and optional inputSchema.
|
|
93
|
-
*/
|
|
94
|
-
registerTools(...tools) {
|
|
72
|
+
registerToolsHttp() {
|
|
95
73
|
const registry = _getToolRegistry();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
74
|
+
if (registry.size === 0)
|
|
75
|
+
return;
|
|
76
|
+
const callbackUrl = this._devServer?.getCallbackUrl();
|
|
77
|
+
if (!callbackUrl)
|
|
78
|
+
return;
|
|
79
|
+
const tools = Array.from(registry.entries()).map(([name, entry]) => ({
|
|
80
|
+
name,
|
|
81
|
+
inputSchema: entry.inputSchema,
|
|
82
|
+
description: entry.description ?? null,
|
|
83
|
+
}));
|
|
84
|
+
const auth = Buffer.from(`${this.publicKey}:${this.secretKey}`).toString("base64");
|
|
85
|
+
fetch(`${this.host}/api/public/tools/register`, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
Authorization: `Basic ${auth}`,
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify({ callbackUrl, tools }),
|
|
92
|
+
})
|
|
93
|
+
.then((res) => {
|
|
94
|
+
if (!res.ok)
|
|
95
|
+
console.warn(`[lightrace] Tool registration returned ${res.status}`);
|
|
96
|
+
})
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
console.error("[lightrace] Failed to register tools:", err.message);
|
|
99
|
+
});
|
|
109
100
|
}
|
|
110
101
|
// -- Flush / shutdown --------------------------------------------------------
|
|
111
102
|
flush() {
|
|
112
103
|
this.otelExporter?.flush();
|
|
113
104
|
}
|
|
114
105
|
async shutdown() {
|
|
115
|
-
if (this.
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
}
|
|
119
|
-
if (this.toolClient) {
|
|
120
|
-
this.toolClient.stop();
|
|
121
|
-
this.toolClient = null;
|
|
106
|
+
if (this._devServer) {
|
|
107
|
+
await this._devServer.stop();
|
|
108
|
+
this._devServer = null;
|
|
122
109
|
}
|
|
123
110
|
if (this.otelExporter) {
|
|
124
111
|
await this.otelExporter.shutdown();
|
|
112
|
+
this.otelExporter = null;
|
|
125
113
|
_setOtelExporter(null);
|
|
126
114
|
}
|
|
127
115
|
Lightrace.instance = null;
|
|
128
116
|
}
|
|
129
117
|
// -- Imperative observation API ----------------------------------------------
|
|
130
|
-
/**
|
|
131
|
-
* Create a span observation imperatively.
|
|
132
|
-
*/
|
|
133
118
|
span(opts) {
|
|
134
119
|
return this._createObservation("span", opts);
|
|
135
120
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Create a generation observation imperatively.
|
|
138
|
-
*/
|
|
139
121
|
generation(opts) {
|
|
140
122
|
return this._createObservation("generation", opts);
|
|
141
123
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Create an event observation imperatively (auto-ended).
|
|
144
|
-
*/
|
|
145
124
|
event(opts) {
|
|
146
125
|
const obs = this._createObservation("event", opts);
|
|
147
126
|
obs.end();
|
|
@@ -149,23 +128,21 @@ export class Lightrace {
|
|
|
149
128
|
}
|
|
150
129
|
_createObservation(type, opts) {
|
|
151
130
|
const otelExporter = this.otelExporter;
|
|
152
|
-
// Resolve trace context: explicit > OTel active span > create new root trace
|
|
153
131
|
const ctx = _getTraceContext();
|
|
154
132
|
let traceId = opts.traceId ?? ctx?.traceId;
|
|
155
|
-
const parentObservationId = opts.parentObservationId ?? ctx?.observationId
|
|
156
|
-
// If no trace context, create an implicit root trace via OTel span
|
|
133
|
+
const parentObservationId = opts.parentObservationId ?? ctx?.observationId;
|
|
157
134
|
if (!traceId && otelExporter) {
|
|
158
135
|
const tracer = otelExporter.tracer;
|
|
159
136
|
const rootSpan = tracer.startSpan(opts.name);
|
|
160
|
-
rootSpan.setAttribute(
|
|
161
|
-
rootSpan.setAttribute(
|
|
137
|
+
rootSpan.setAttribute(AS_ROOT, "true");
|
|
138
|
+
rootSpan.setAttribute(TRACE_NAME, opts.name);
|
|
162
139
|
traceId = rootSpan.spanContext().traceId;
|
|
163
140
|
rootSpan.end();
|
|
164
141
|
}
|
|
165
142
|
if (!traceId) {
|
|
166
143
|
traceId = generateId();
|
|
167
144
|
}
|
|
168
|
-
|
|
145
|
+
return new Observation({
|
|
169
146
|
traceId,
|
|
170
147
|
type,
|
|
171
148
|
name: opts.name,
|
|
@@ -176,7 +153,6 @@ export class Lightrace {
|
|
|
176
153
|
usage: opts.usage,
|
|
177
154
|
parentObservationId: parentObservationId ?? undefined,
|
|
178
155
|
});
|
|
179
|
-
return obs;
|
|
180
156
|
}
|
|
181
157
|
}
|
|
182
158
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,gBAAgB,EAEhB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAA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Aa,CAAC;QAE3E,IAAI,CAAC,OAAO,IAAI,YAAY,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;YACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACvC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC;YACzC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACjB,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,UAAU,EAAE,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,WAAW,CAAC;YACrB,OAAO;YACP,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY;YACZ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,mBAAmB,EAAE,mBAAmB,IAAI,SAAS;SACtD,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface DevServerOptions {
|
|
2
|
+
/** Port to bind (0 = auto-discover free port). Default: 0. */
|
|
3
|
+
port?: number;
|
|
4
|
+
/** Public key for request authentication. */
|
|
5
|
+
publicKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class DevServer {
|
|
8
|
+
private server;
|
|
9
|
+
private publicKey;
|
|
10
|
+
private assignedPort;
|
|
11
|
+
private requestedPort;
|
|
12
|
+
constructor(options?: DevServerOptions);
|
|
13
|
+
start(): Promise<number>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
getPort(): number | null;
|
|
16
|
+
getCallbackUrl(): string | null;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=dev-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,aAAa,CAAS;gBAElB,OAAO,GAAE,gBAAqB;IAKpC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAkExB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,OAAO,IAAI,MAAM,GAAG,IAAI;IAIxB,cAAc,IAAI,MAAM,GAAG,IAAI;CAIhC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { cors } from "hono/cors";
|
|
3
|
+
import { bodyLimit } from "hono/body-limit";
|
|
4
|
+
import { serve } from "@hono/node-server";
|
|
5
|
+
import { _getToolRegistry } from "./trace.js";
|
|
6
|
+
import { jsonSerializable } from "./utils.js";
|
|
7
|
+
function apiResponse(c, code, message, response = null) {
|
|
8
|
+
return c.json({ code, message, response }, code);
|
|
9
|
+
}
|
|
10
|
+
export class DevServer {
|
|
11
|
+
server = null;
|
|
12
|
+
publicKey;
|
|
13
|
+
assignedPort = null;
|
|
14
|
+
requestedPort;
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.requestedPort = options.port ?? 0;
|
|
17
|
+
this.publicKey = options.publicKey ?? "";
|
|
18
|
+
}
|
|
19
|
+
async start() {
|
|
20
|
+
if (this.server)
|
|
21
|
+
return this.assignedPort;
|
|
22
|
+
const app = new Hono();
|
|
23
|
+
const publicKey = this.publicKey;
|
|
24
|
+
app.use("*", cors());
|
|
25
|
+
app.use("/invoke", bodyLimit({ maxSize: 1024 * 1024 }));
|
|
26
|
+
app.get("/health", (c) => apiResponse(c, 200, "OK", { status: "ok" }));
|
|
27
|
+
app.post("/invoke", async (c) => {
|
|
28
|
+
if (publicKey && c.req.header("Authorization") !== `Bearer ${publicKey}`) {
|
|
29
|
+
return apiResponse(c, 401, "Unauthorized");
|
|
30
|
+
}
|
|
31
|
+
const body = await c.req.json().catch(() => null);
|
|
32
|
+
if (!body || typeof body !== "object") {
|
|
33
|
+
return apiResponse(c, 400, "Invalid JSON body");
|
|
34
|
+
}
|
|
35
|
+
const { tool, input } = body;
|
|
36
|
+
const registry = _getToolRegistry();
|
|
37
|
+
const entry = registry.get(tool);
|
|
38
|
+
if (!entry) {
|
|
39
|
+
return apiResponse(c, 404, `Tool not found: ${tool}`);
|
|
40
|
+
}
|
|
41
|
+
const start = performance.now();
|
|
42
|
+
try {
|
|
43
|
+
let result;
|
|
44
|
+
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
45
|
+
result = await entry.fn(input);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
result = input != null ? await entry.fn(input) : await entry.fn();
|
|
49
|
+
}
|
|
50
|
+
const durationMs = Math.round(performance.now() - start);
|
|
51
|
+
return apiResponse(c, 200, "OK", { output: jsonSerializable(result), durationMs });
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const durationMs = Math.round(performance.now() - start);
|
|
55
|
+
return apiResponse(c, 200, "OK", {
|
|
56
|
+
output: null,
|
|
57
|
+
error: err instanceof Error ? err.message : String(err),
|
|
58
|
+
durationMs,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
try {
|
|
64
|
+
const server = serve({ fetch: app.fetch, port: this.requestedPort, hostname: "127.0.0.1" }, (info) => {
|
|
65
|
+
this.assignedPort = info.port;
|
|
66
|
+
this.server = server;
|
|
67
|
+
resolve(info.port);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
reject(err);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async stop() {
|
|
76
|
+
if (!this.server)
|
|
77
|
+
return;
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
this.server.close(() => {
|
|
80
|
+
this.server = null;
|
|
81
|
+
this.assignedPort = null;
|
|
82
|
+
resolve();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getPort() {
|
|
87
|
+
return this.assignedPort;
|
|
88
|
+
}
|
|
89
|
+
getCallbackUrl() {
|
|
90
|
+
if (!this.assignedPort)
|
|
91
|
+
return null;
|
|
92
|
+
return `http://127.0.0.1:${this.assignedPort}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=dev-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,SAAS,WAAW,CAAC,CAAU,EAAE,IAAY,EAAE,OAAe,EAAE,WAAoB,IAAI;IACtF,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,IAA4B,CAAC,CAAC;AA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AO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,oBAAoB,IAAI,CAAC,YAAY,EAAE,CAAC;IACjD,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { LightraceOptions } from "./client.js";
|
|
|
3
3
|
export { trace } from "./trace.js";
|
|
4
4
|
export { Observation } from "./observation.js";
|
|
5
5
|
export { LightraceOtelExporter } from "./otel-exporter.js";
|
|
6
|
-
export {
|
|
6
|
+
export { DevServer } from "./dev-server.js";
|
|
7
7
|
export { registerContext, captureContext, restoreContext } from "./context.js";
|
|
8
8
|
export type { TraceOptions, ObservationType, UsageDetails } from "./types.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/E,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,6 @@ export { Lightrace } from "./client.js";
|
|
|
2
2
|
export { trace } from "./trace.js";
|
|
3
3
|
export { Observation } from "./observation.js";
|
|
4
4
|
export { LightraceOtelExporter } from "./otel-exporter.js";
|
|
5
|
-
export {
|
|
5
|
+
export { DevServer } from "./dev-server.js";
|
|
6
6
|
export { registerContext, captureContext, restoreContext } from "./context.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tracing infrastructure for framework integrations.
|
|
3
|
+
*
|
|
4
|
+
* Provides `TracingMixin` with `registerRun` / `endRun` to manage OTel spans
|
|
5
|
+
* with `lightrace.*` attributes, and `normalizeUsage` for multi-provider
|
|
6
|
+
* token usage extraction.
|
|
7
|
+
*/
|
|
8
|
+
import type { Span } from "@opentelemetry/api";
|
|
9
|
+
import type { LightraceOtelExporter } from "../otel-exporter.js";
|
|
10
|
+
import { Lightrace } from "../client.js";
|
|
11
|
+
/** State tracked for each in-flight observation. */
|
|
12
|
+
export interface ObsRunInfo {
|
|
13
|
+
observationId: string;
|
|
14
|
+
type: "span" | "generation" | "event" | "tool" | "chain";
|
|
15
|
+
name: string;
|
|
16
|
+
startTime: Date;
|
|
17
|
+
input: unknown;
|
|
18
|
+
parentRunId?: string;
|
|
19
|
+
model?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
modelParameters?: Record<string, unknown>;
|
|
22
|
+
span: Span;
|
|
23
|
+
}
|
|
24
|
+
export interface TracingMixinOptions {
|
|
25
|
+
/** User ID to attach to the root trace. */
|
|
26
|
+
userId?: string;
|
|
27
|
+
/** Session ID to attach to the root trace. */
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
/** Override name for the root trace. */
|
|
30
|
+
traceName?: string;
|
|
31
|
+
/** Additional metadata to attach to the root trace. */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
/** Provide a Lightrace client instance. If omitted, uses Lightrace.getInstance(). */
|
|
34
|
+
client?: Lightrace;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalize token usage from any provider format to a canonical form.
|
|
38
|
+
*
|
|
39
|
+
* Supports OpenAI (`prompt_tokens`/`completion_tokens`), Anthropic
|
|
40
|
+
* (`input_tokens`/`output_tokens`), and camelCase variants.
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeUsage(raw: Record<string, unknown>): Record<string, number> | null;
|
|
43
|
+
/**
|
|
44
|
+
* Base class providing shared OTel tracing infrastructure for framework
|
|
45
|
+
* integrations. Manages span lifecycle, run-state tracking, and
|
|
46
|
+
* `lightrace.*` attribute setting.
|
|
47
|
+
*/
|
|
48
|
+
export declare class TracingMixin {
|
|
49
|
+
protected runs: Map<string, ObsRunInfo>;
|
|
50
|
+
protected runParents: Map<string, string | undefined>;
|
|
51
|
+
protected completionStartTimes: Map<string, Date>;
|
|
52
|
+
protected rootRunId: string | null;
|
|
53
|
+
protected _traceId: string | null;
|
|
54
|
+
protected userId?: string;
|
|
55
|
+
protected sessionId?: string;
|
|
56
|
+
protected traceName?: string;
|
|
57
|
+
protected rootMetadata?: Record<string, unknown>;
|
|
58
|
+
protected otelExporter: LightraceOtelExporter | null;
|
|
59
|
+
/** Root span for the current trace. */
|
|
60
|
+
protected rootSpan: Span | null;
|
|
61
|
+
/** The trace ID from the most recently completed root run. */
|
|
62
|
+
lastTraceId: string | null;
|
|
63
|
+
constructor(opts?: TracingMixinOptions);
|
|
64
|
+
/** Get the current active trace ID (null if no run is active). */
|
|
65
|
+
get traceId(): string | null;
|
|
66
|
+
protected registerRun(runId: string, parentRunId: string | undefined, info: Omit<ObsRunInfo, "observationId" | "parentRunId" | "span">): ObsRunInfo;
|
|
67
|
+
protected endObservationSpan(run: ObsRunInfo, output: unknown, level: string, statusMessage: string | null, extra?: Record<string, unknown>): void;
|
|
68
|
+
endRun(runId: string, output: unknown, level?: string, statusMessage?: string | null, extra?: Record<string, unknown>): void;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=_base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_base.d.ts","sourceRoot":"","sources":["../../src/integrations/_base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,IAAI,EAAU,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,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