@lobu/core 2.8.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/dist/__tests__/encryption.test.d.ts +2 -0
- package/dist/__tests__/encryption.test.d.ts.map +1 -0
- package/dist/__tests__/encryption.test.js +88 -0
- package/dist/__tests__/encryption.test.js.map +1 -0
- package/dist/__tests__/fixtures/factories.d.ts +30 -0
- package/dist/__tests__/fixtures/factories.d.ts.map +1 -0
- package/dist/__tests__/fixtures/factories.js +53 -0
- package/dist/__tests__/fixtures/factories.js.map +1 -0
- package/dist/__tests__/fixtures/index.d.ts +5 -0
- package/dist/__tests__/fixtures/index.d.ts.map +1 -0
- package/dist/__tests__/fixtures/index.js +14 -0
- package/dist/__tests__/fixtures/index.js.map +1 -0
- package/dist/__tests__/fixtures/mock-fetch.d.ts +13 -0
- package/dist/__tests__/fixtures/mock-fetch.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mock-fetch.js +29 -0
- package/dist/__tests__/fixtures/mock-fetch.js.map +1 -0
- package/dist/__tests__/fixtures/mock-queue.d.ts +19 -0
- package/dist/__tests__/fixtures/mock-queue.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mock-queue.js +45 -0
- package/dist/__tests__/fixtures/mock-queue.js.map +1 -0
- package/dist/__tests__/fixtures/mock-redis.d.ts +54 -0
- package/dist/__tests__/fixtures/mock-redis.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mock-redis.js +267 -0
- package/dist/__tests__/fixtures/mock-redis.js.map +1 -0
- package/dist/__tests__/retry.test.d.ts +2 -0
- package/dist/__tests__/retry.test.d.ts.map +1 -0
- package/dist/__tests__/retry.test.js +114 -0
- package/dist/__tests__/retry.test.js.map +1 -0
- package/dist/__tests__/sanitize.test.d.ts +2 -0
- package/dist/__tests__/sanitize.test.d.ts.map +1 -0
- package/dist/__tests__/sanitize.test.js +129 -0
- package/dist/__tests__/sanitize.test.js.map +1 -0
- package/dist/agent-policy.d.ts +21 -0
- package/dist/agent-policy.d.ts.map +1 -0
- package/dist/agent-policy.js +181 -0
- package/dist/agent-policy.js.map +1 -0
- package/dist/agent-store.d.ts +140 -0
- package/dist/agent-store.d.ts.map +1 -0
- package/dist/agent-store.js +27 -0
- package/dist/agent-store.js.map +1 -0
- package/dist/api-types.d.ts +213 -0
- package/dist/api-types.d.ts.map +1 -0
- package/dist/api-types.js +7 -0
- package/dist/api-types.js.map +1 -0
- package/dist/command-registry.d.ts +41 -0
- package/dist/command-registry.d.ts.map +1 -0
- package/dist/command-registry.js +43 -0
- package/dist/command-registry.js.map +1 -0
- package/dist/constants.d.ts +54 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +60 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +97 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +182 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/integration-types.d.ts +22 -0
- package/dist/integration-types.d.ts.map +1 -0
- package/dist/integration-types.js +9 -0
- package/dist/integration-types.js.map +1 -0
- package/dist/logger.d.ts +15 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +223 -0
- package/dist/logger.js.map +1 -0
- package/dist/modules.d.ts +96 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +140 -0
- package/dist/modules.js.map +1 -0
- package/dist/otel.d.ts +107 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +251 -0
- package/dist/otel.js.map +1 -0
- package/dist/plugin-types.d.ts +42 -0
- package/dist/plugin-types.d.ts.map +1 -0
- package/dist/plugin-types.js +8 -0
- package/dist/plugin-types.js.map +1 -0
- package/dist/provider-config-types.d.ts +53 -0
- package/dist/provider-config-types.d.ts.map +1 -0
- package/dist/provider-config-types.js +7 -0
- package/dist/provider-config-types.js.map +1 -0
- package/dist/redis/base-store.d.ts +73 -0
- package/dist/redis/base-store.d.ts.map +1 -0
- package/dist/redis/base-store.js +174 -0
- package/dist/redis/base-store.js.map +1 -0
- package/dist/sentry.d.ts +12 -0
- package/dist/sentry.d.ts.map +1 -0
- package/dist/sentry.js +82 -0
- package/dist/sentry.js.map +1 -0
- package/dist/trace.d.ts +25 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +32 -0
- package/dist/trace.js.map +1 -0
- package/dist/types.d.ts +373 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/encryption.d.ts +9 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +107 -0
- package/dist/utils/encryption.js.map +1 -0
- package/dist/utils/env.d.ts +20 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +50 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/json.d.ts +11 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +38 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lock.d.ts +34 -0
- package/dist/utils/lock.d.ts.map +1 -0
- package/dist/utils/lock.js +66 -0
- package/dist/utils/lock.js.map +1 -0
- package/dist/utils/mcp-tool-instructions.d.ts +6 -0
- package/dist/utils/mcp-tool-instructions.d.ts.map +1 -0
- package/dist/utils/mcp-tool-instructions.js +3 -0
- package/dist/utils/mcp-tool-instructions.js.map +1 -0
- package/dist/utils/retry.d.ts +40 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +67 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/sanitize.d.ts +55 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/sanitize.js +111 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/dist/worker/auth.d.ts +34 -0
- package/dist/worker/auth.d.ts.map +1 -0
- package/dist/worker/auth.js +63 -0
- package/dist/worker/auth.js.map +1 -0
- package/dist/worker/transport.d.ts +86 -0
- package/dist/worker/transport.d.ts.map +1 -0
- package/dist/worker/transport.js +13 -0
- package/dist/worker/transport.js.map +1 -0
- package/package.json +40 -0
package/dist/otel.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenTelemetry tracing setup for distributed tracing with Grafana Tempo.
|
|
4
|
+
* Provides Chrome DevTools-style waterfall visualization in Grafana.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SpanStatusCode = exports.SpanKind = void 0;
|
|
8
|
+
exports.initTracing = initTracing;
|
|
9
|
+
exports.getTracer = getTracer;
|
|
10
|
+
exports.shutdownTracing = shutdownTracing;
|
|
11
|
+
exports.flushTracing = flushTracing;
|
|
12
|
+
exports.createSpan = createSpan;
|
|
13
|
+
exports.withSpan = withSpan;
|
|
14
|
+
exports.getCurrentSpan = getCurrentSpan;
|
|
15
|
+
exports.runInSpanContext = runInSpanContext;
|
|
16
|
+
exports.createRootSpan = createRootSpan;
|
|
17
|
+
exports.createChildSpan = createChildSpan;
|
|
18
|
+
exports.withChildSpan = withChildSpan;
|
|
19
|
+
exports.getTraceparent = getTraceparent;
|
|
20
|
+
const api_1 = require("@opentelemetry/api");
|
|
21
|
+
Object.defineProperty(exports, "SpanKind", { enumerable: true, get: function () { return api_1.SpanKind; } });
|
|
22
|
+
Object.defineProperty(exports, "SpanStatusCode", { enumerable: true, get: function () { return api_1.SpanStatusCode; } });
|
|
23
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
24
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
25
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
26
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
27
|
+
const logger_1 = require("./logger");
|
|
28
|
+
const logger = (0, logger_1.createLogger)("otel");
|
|
29
|
+
let provider = null;
|
|
30
|
+
let tracer = null;
|
|
31
|
+
/**
|
|
32
|
+
* Initialize OpenTelemetry tracing.
|
|
33
|
+
* Call this once at application startup.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* initTracing({
|
|
37
|
+
* serviceName: "lobu-gateway",
|
|
38
|
+
* tempoEndpoint: "http://lobu-tempo:4318/v1/traces",
|
|
39
|
+
* });
|
|
40
|
+
*/
|
|
41
|
+
function initTracing(config) {
|
|
42
|
+
if (provider) {
|
|
43
|
+
return; // Already initialized
|
|
44
|
+
}
|
|
45
|
+
const enabled = config.enabled ?? !!config.tempoEndpoint;
|
|
46
|
+
if (!enabled) {
|
|
47
|
+
logger.debug("Tracing disabled (no TEMPO_ENDPOINT configured)");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const resource = new resources_1.Resource({
|
|
51
|
+
[semantic_conventions_1.ATTR_SERVICE_NAME]: config.serviceName,
|
|
52
|
+
[semantic_conventions_1.ATTR_SERVICE_VERSION]: config.serviceVersion || "1.0.0",
|
|
53
|
+
});
|
|
54
|
+
provider = new sdk_trace_node_1.NodeTracerProvider({ resource });
|
|
55
|
+
// Configure OTLP exporter to send traces to Tempo
|
|
56
|
+
const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
|
|
57
|
+
url: config.tempoEndpoint,
|
|
58
|
+
timeoutMillis: 30000, // 30 second timeout for reliability
|
|
59
|
+
});
|
|
60
|
+
// Use SimpleSpanProcessor for immediate export (better for short-lived workers)
|
|
61
|
+
provider.addSpanProcessor(new sdk_trace_node_1.SimpleSpanProcessor(exporter));
|
|
62
|
+
provider.register();
|
|
63
|
+
tracer = api_1.trace.getTracer(config.serviceName, config.serviceVersion);
|
|
64
|
+
logger.info(`Tracing initialized: ${config.serviceName} -> ${config.tempoEndpoint}`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the configured tracer. Returns null if not initialized.
|
|
68
|
+
*/
|
|
69
|
+
function getTracer() {
|
|
70
|
+
return tracer;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Shutdown tracing gracefully.
|
|
74
|
+
*/
|
|
75
|
+
async function shutdownTracing() {
|
|
76
|
+
if (provider) {
|
|
77
|
+
await provider.shutdown();
|
|
78
|
+
provider = null;
|
|
79
|
+
tracer = null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Force flush all pending spans to the exporter.
|
|
84
|
+
* Call this after processing a message to ensure spans are exported promptly.
|
|
85
|
+
*/
|
|
86
|
+
async function flushTracing() {
|
|
87
|
+
if (provider) {
|
|
88
|
+
await provider.forceFlush();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a new span for tracing.
|
|
93
|
+
* If tracing is not initialized, returns a no-op span.
|
|
94
|
+
*
|
|
95
|
+
* @param name Span name (e.g., "queue_processing", "agent_execution")
|
|
96
|
+
* @param attributes Optional attributes to add to the span
|
|
97
|
+
* @param parentContext Optional parent context for trace correlation
|
|
98
|
+
*/
|
|
99
|
+
function createSpan(name, attributes, kind = api_1.SpanKind.INTERNAL) {
|
|
100
|
+
if (!tracer) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const span = tracer.startSpan(name, {
|
|
104
|
+
kind,
|
|
105
|
+
attributes,
|
|
106
|
+
});
|
|
107
|
+
return span;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Execute a function within a span context.
|
|
111
|
+
* Automatically handles span lifecycle (start, end, error recording).
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const result = await withSpan("process_message", async (span) => {
|
|
115
|
+
* span?.setAttribute("messageId", messageId);
|
|
116
|
+
* return await processMessage();
|
|
117
|
+
* });
|
|
118
|
+
*/
|
|
119
|
+
async function withSpan(name, fn, attributes) {
|
|
120
|
+
const span = createSpan(name, attributes);
|
|
121
|
+
try {
|
|
122
|
+
const result = await fn(span);
|
|
123
|
+
span?.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (span) {
|
|
128
|
+
span.setStatus({
|
|
129
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
130
|
+
message: error instanceof Error ? error.message : String(error),
|
|
131
|
+
});
|
|
132
|
+
span.recordException(error);
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
span?.end();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get current active span from context.
|
|
142
|
+
*/
|
|
143
|
+
function getCurrentSpan() {
|
|
144
|
+
return api_1.trace.getActiveSpan();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Run a function within a span context, propagating the span.
|
|
148
|
+
*/
|
|
149
|
+
function runInSpanContext(span, fn) {
|
|
150
|
+
const ctx = api_1.trace.setSpan(api_1.context.active(), span);
|
|
151
|
+
return api_1.context.with(ctx, fn);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a root span and return traceparent header for propagation.
|
|
155
|
+
* Use this at the entry point (message ingestion) to start a trace.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const { span, traceparent } = createRootSpan("message_received", { messageId });
|
|
159
|
+
* // Store traceparent in message metadata for downstream propagation
|
|
160
|
+
* await queueProducer.enqueueMessage({ ...data, platformMetadata: { traceparent } });
|
|
161
|
+
* span.end();
|
|
162
|
+
*/
|
|
163
|
+
function createRootSpan(name, attributes) {
|
|
164
|
+
if (!tracer) {
|
|
165
|
+
return { span: null, traceparent: null };
|
|
166
|
+
}
|
|
167
|
+
const span = tracer.startSpan(name, {
|
|
168
|
+
kind: api_1.SpanKind.SERVER,
|
|
169
|
+
attributes,
|
|
170
|
+
});
|
|
171
|
+
// Extract W3C traceparent header from span context
|
|
172
|
+
const spanContext = span.spanContext();
|
|
173
|
+
const traceparent = `00-${spanContext.traceId}-${spanContext.spanId}-01`;
|
|
174
|
+
return { span, traceparent };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Create a child span from a traceparent header.
|
|
178
|
+
* Use this to continue a trace in downstream services (queue consumer, worker).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const traceparent = data.platformMetadata?.traceparent;
|
|
182
|
+
* const span = createChildSpan("queue_processing", traceparent, { jobId });
|
|
183
|
+
* // ... do work ...
|
|
184
|
+
* span?.end();
|
|
185
|
+
*/
|
|
186
|
+
function createChildSpan(name, traceparent, attributes) {
|
|
187
|
+
if (!tracer) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
if (!traceparent) {
|
|
191
|
+
// No parent context - create independent span
|
|
192
|
+
return createSpan(name, attributes);
|
|
193
|
+
}
|
|
194
|
+
// Parse W3C traceparent: 00-traceId-parentSpanId-flags
|
|
195
|
+
const parts = traceparent.split("-");
|
|
196
|
+
if (parts.length !== 4) {
|
|
197
|
+
return createSpan(name, attributes);
|
|
198
|
+
}
|
|
199
|
+
const traceId = parts[1];
|
|
200
|
+
const parentSpanId = parts[2];
|
|
201
|
+
// Create span context from traceparent
|
|
202
|
+
const parentContext = api_1.trace.setSpanContext(api_1.context.active(), {
|
|
203
|
+
traceId,
|
|
204
|
+
spanId: parentSpanId,
|
|
205
|
+
traceFlags: 1, // sampled
|
|
206
|
+
isRemote: true,
|
|
207
|
+
});
|
|
208
|
+
// Start span as child of the propagated context
|
|
209
|
+
return tracer.startSpan(name, { kind: api_1.SpanKind.INTERNAL, attributes }, parentContext);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Run a function within a child span context.
|
|
213
|
+
* Automatically handles span lifecycle and error recording.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* const result = await withChildSpan("process_job", traceparent, async (span) => {
|
|
217
|
+
* span?.setAttribute("jobId", jobId);
|
|
218
|
+
* return await processJob();
|
|
219
|
+
* });
|
|
220
|
+
*/
|
|
221
|
+
async function withChildSpan(name, traceparent, fn, attributes) {
|
|
222
|
+
const span = createChildSpan(name, traceparent, attributes);
|
|
223
|
+
try {
|
|
224
|
+
const result = await fn(span);
|
|
225
|
+
span?.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (span) {
|
|
230
|
+
span.setStatus({
|
|
231
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
232
|
+
message: error instanceof Error ? error.message : String(error),
|
|
233
|
+
});
|
|
234
|
+
span.recordException(error);
|
|
235
|
+
}
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
span?.end();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Extract traceparent from span for propagation to downstream services.
|
|
244
|
+
*/
|
|
245
|
+
function getTraceparent(span) {
|
|
246
|
+
if (!span)
|
|
247
|
+
return null;
|
|
248
|
+
const ctx = span.spanContext();
|
|
249
|
+
return `00-${ctx.traceId}-${ctx.spanId}-01`;
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=otel.js.map
|
package/dist/otel.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../src/otel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAsCH,kCAiCC;AAKD,8BAEC;AAKD,0CAMC;AAMD,oCAIC;AAUD,gCAeC;AAYD,4BAuBC;AAKD,wCAEC;AAKD,4CAGC;AAYD,wCAkBC;AAYD,0CAqCC;AAYD,sCAwBC;AAKD,wCAIC;AAvSD,4CAA8E;AA0SrE,yFA1SS,cAAQ,OA0ST;AAAE,+FA1SS,oBAAc,OA0ST;AAzSjC,sFAA4E;AAC5E,wDAAoD;AACpD,kEAGuC;AACvC,8EAG6C;AAC7C,qCAAwC;AAExC,MAAM,MAA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AAK;gBAC1B,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;YACH,IAAI,CAAC,eAAe,CAAC,KAAc,CAAC,CAAC;QACvC,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,IAAI,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,IAAiB;IAC9C,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC/B,OAAO,MAAM,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw plugin types for Lobu.
|
|
3
|
+
*
|
|
4
|
+
* Supports loading existing OpenClaw community plugins.
|
|
5
|
+
*/
|
|
6
|
+
/** Supported plugin slots */
|
|
7
|
+
export type PluginSlot = "tool" | "provider" | "memory";
|
|
8
|
+
/** Configuration for a single plugin */
|
|
9
|
+
export interface PluginConfig {
|
|
10
|
+
/** npm package name or local path (e.g., "@openclaw/voice-call", "./my-plugin") */
|
|
11
|
+
source: string;
|
|
12
|
+
/** Which slot this plugin fills */
|
|
13
|
+
slot: PluginSlot;
|
|
14
|
+
/** Whether this plugin is enabled (default: true) */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/** Plugin-specific configuration passed through to the plugin runtime */
|
|
17
|
+
config?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/** Top-level plugins configuration stored in agent settings */
|
|
20
|
+
export interface PluginsConfig {
|
|
21
|
+
plugins: PluginConfig[];
|
|
22
|
+
}
|
|
23
|
+
/** Metadata about a loaded plugin */
|
|
24
|
+
export interface PluginManifest {
|
|
25
|
+
/** Source identifier (package name or path) */
|
|
26
|
+
source: string;
|
|
27
|
+
/** Plugin slot */
|
|
28
|
+
slot: PluginSlot;
|
|
29
|
+
/** Display name (from package or source) */
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A provider registration captured from pi.registerProvider().
|
|
34
|
+
* The config is opaque here — it's passed directly to ModelRegistry.registerProvider().
|
|
35
|
+
*/
|
|
36
|
+
export interface ProviderRegistration {
|
|
37
|
+
/** Provider name (e.g., "corporate-ai", "my-proxy") */
|
|
38
|
+
name: string;
|
|
39
|
+
/** Provider config (ProviderConfigInput from pi-coding-agent) */
|
|
40
|
+
config: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=plugin-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-types.d.ts","sourceRoot":"","sources":["../src/plugin-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6BAA6B;AAC7B,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;AAExD,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,qDAAqD;IACrD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-types.js","sourceRoot":"","sources":["../src/plugin-types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for config-driven LLM providers.
|
|
3
|
+
* Loaded from the `providers` section of system skills config.
|
|
4
|
+
*/
|
|
5
|
+
export interface ProviderConfigEntry {
|
|
6
|
+
/** Display name in settings page (e.g. "Groq") */
|
|
7
|
+
displayName: string;
|
|
8
|
+
/** Provider icon URL */
|
|
9
|
+
iconUrl: string;
|
|
10
|
+
/** Env var name for API key (e.g. "GROQ_API_KEY") */
|
|
11
|
+
envVarName: string;
|
|
12
|
+
/** Provider's API base URL (e.g. "https://api.groq.com/openai") */
|
|
13
|
+
upstreamBaseUrl: string;
|
|
14
|
+
/** HTML help text for the settings page API key input */
|
|
15
|
+
apiKeyInstructions: string;
|
|
16
|
+
/** Placeholder text for the API key input */
|
|
17
|
+
apiKeyPlaceholder: string;
|
|
18
|
+
/** SDK compatibility hint — "openai" means OpenAI-compatible API format */
|
|
19
|
+
sdkCompat?: "openai";
|
|
20
|
+
/** Default model ID when none is configured */
|
|
21
|
+
defaultModel?: string;
|
|
22
|
+
/** Relative path to fetch model list (e.g. "/v1/models") */
|
|
23
|
+
modelsEndpoint?: string;
|
|
24
|
+
/** Override provider name for model registry lookup */
|
|
25
|
+
registryAlias?: string;
|
|
26
|
+
/** Whether to show in "Add Provider" catalog (default: true) */
|
|
27
|
+
catalogVisible?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Optional speech-to-text configuration.
|
|
30
|
+
* If omitted and sdkCompat is "openai", STT is enabled with default endpoint/model.
|
|
31
|
+
* Use this block to override endpoint/model or disable STT for a provider.
|
|
32
|
+
*/
|
|
33
|
+
stt?: {
|
|
34
|
+
/** Set false to disable STT even when this block exists. */
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
/** STT protocol compatibility; currently only OpenAI-compatible is supported here. */
|
|
37
|
+
sdkCompat?: "openai";
|
|
38
|
+
/** Optional upstream base URL override for STT requests. */
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/** Relative or absolute transcription endpoint path/URL. */
|
|
41
|
+
transcriptionPath?: string;
|
|
42
|
+
/** STT model ID (for OpenAI-compatible endpoints). */
|
|
43
|
+
model?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Metadata passed from gateway to worker for config-driven providers. */
|
|
47
|
+
export interface ConfigProviderMeta {
|
|
48
|
+
sdkCompat?: "openai";
|
|
49
|
+
defaultModel?: string;
|
|
50
|
+
registryAlias?: string;
|
|
51
|
+
baseUrlEnvVar: string;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=provider-config-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-config-types.d.ts","sourceRoot":"","sources":["../src/provider-config-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,eAAe,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6CAA6C;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,GAAG,CAAC,EAAE;QACJ,4DAA4D;QAC5D,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,sFAAsF;QACtF,SAAS,CAAC,EAAE,QAAQ,CAAC;QACrB,4DAA4D;QAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,4DAA4D;QAC5D,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,sDAAsD;QACtD,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-config-types.js","sourceRoot":"","sources":["../src/provider-config-types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type Redis from "ioredis";
|
|
2
|
+
import { type Logger } from "../logger";
|
|
3
|
+
export interface RedisStoreConfig {
|
|
4
|
+
redis: Redis;
|
|
5
|
+
keyPrefix: string;
|
|
6
|
+
loggerName: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Base class for all Redis-backed stores
|
|
10
|
+
* Provides common CRUD operations with JSON serialization
|
|
11
|
+
*
|
|
12
|
+
* Consolidates:
|
|
13
|
+
* - packages/gateway/src/auth/credential-store.ts (BaseCredentialStore)
|
|
14
|
+
* - packages/gateway/src/infrastructure/redis/store.ts (BaseRedisStore)
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class BaseRedisStore<T> {
|
|
17
|
+
protected logger: Logger;
|
|
18
|
+
protected redis: Redis;
|
|
19
|
+
protected keyPrefix: string;
|
|
20
|
+
constructor(config: RedisStoreConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Build Redis key from parts
|
|
23
|
+
*/
|
|
24
|
+
protected buildKey(...parts: string[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get value from Redis
|
|
27
|
+
* Returns null if not found or validation fails
|
|
28
|
+
*/
|
|
29
|
+
protected get(key: string): Promise<T | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Set value in Redis
|
|
32
|
+
*/
|
|
33
|
+
protected set(key: string, value: T, ttlSeconds?: number): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete value from Redis
|
|
36
|
+
*/
|
|
37
|
+
protected delete(key: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Scan for all keys matching a prefix (cursor-based, production-safe).
|
|
40
|
+
* Returns full key strings matching `{prefix}*`.
|
|
41
|
+
*/
|
|
42
|
+
protected scanByPrefix(prefix: string): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Check if key exists in Redis
|
|
45
|
+
*/
|
|
46
|
+
protected exists(key: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Serialize value to string
|
|
49
|
+
* Override for custom serialization
|
|
50
|
+
*/
|
|
51
|
+
protected serialize(value: T): string;
|
|
52
|
+
/**
|
|
53
|
+
* Deserialize string to value
|
|
54
|
+
* Override for custom deserialization
|
|
55
|
+
*/
|
|
56
|
+
protected deserialize(data: string): T;
|
|
57
|
+
/**
|
|
58
|
+
* Validate value after deserialization
|
|
59
|
+
* Override to add custom validation logic
|
|
60
|
+
* Return false to reject invalid data
|
|
61
|
+
*/
|
|
62
|
+
protected validate(_value: T): boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Specialized base for credential stores
|
|
66
|
+
* Validates that accessToken field exists
|
|
67
|
+
*/
|
|
68
|
+
export declare abstract class BaseCredentialStore<T extends {
|
|
69
|
+
accessToken: string;
|
|
70
|
+
}> extends BaseRedisStore<T> {
|
|
71
|
+
protected validate(value: T): boolean;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=base-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-store.d.ts","sourceRoot":"","sources":["../../src/redis/base-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAOtD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,8BAAsB,cAAc,CAAC,CAAC;IACpC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEhB,MAAM,EAAE,gBAAgB;IAMpC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAI9C;;;OAGG;cACa,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAyBnD;;OAEG;cACa,GAAG,CACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,EACR,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IAiBhB;;OAEG;cACa,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWlD;;;OAGG;cACa,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAwB/D;;OAEG;cACa,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAarD;;;OAGG;IACH,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;IAQrC;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC;IAQtC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO;CAGvC;AAED;;;GAGG;AACH,8BAAsB,mBAAmB,CACvC,CAAC,SAAS;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CACjC,SAAQ,cAAc,CAAC,CAAC,CAAC;cACN,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;CAO/C"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCredentialStore = exports.BaseRedisStore = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const json_1 = require("../utils/json");
|
|
6
|
+
function errMsg(error) {
|
|
7
|
+
return error instanceof Error ? error.message : String(error);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all Redis-backed stores
|
|
11
|
+
* Provides common CRUD operations with JSON serialization
|
|
12
|
+
*
|
|
13
|
+
* Consolidates:
|
|
14
|
+
* - packages/gateway/src/auth/credential-store.ts (BaseCredentialStore)
|
|
15
|
+
* - packages/gateway/src/infrastructure/redis/store.ts (BaseRedisStore)
|
|
16
|
+
*/
|
|
17
|
+
class BaseRedisStore {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.redis = config.redis;
|
|
20
|
+
this.keyPrefix = config.keyPrefix;
|
|
21
|
+
this.logger = (0, logger_1.createLogger)(config.loggerName);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build Redis key from parts
|
|
25
|
+
*/
|
|
26
|
+
buildKey(...parts) {
|
|
27
|
+
return [this.keyPrefix, ...parts].join(":");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get value from Redis
|
|
31
|
+
* Returns null if not found or validation fails
|
|
32
|
+
*/
|
|
33
|
+
async get(key) {
|
|
34
|
+
try {
|
|
35
|
+
const data = await this.redis.get(key);
|
|
36
|
+
if (!data) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const value = this.deserialize(data);
|
|
40
|
+
// Validate after deserialization
|
|
41
|
+
if (!this.validate(value)) {
|
|
42
|
+
this.logger.warn("Invalid data after deserialization", { key });
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.logger.error("Failed to get from Redis", {
|
|
49
|
+
error: errMsg(error),
|
|
50
|
+
key,
|
|
51
|
+
});
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set value in Redis
|
|
57
|
+
*/
|
|
58
|
+
async set(key, value, ttlSeconds) {
|
|
59
|
+
try {
|
|
60
|
+
const data = this.serialize(value);
|
|
61
|
+
if (ttlSeconds) {
|
|
62
|
+
await this.redis.setex(key, ttlSeconds, data);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
await this.redis.set(key, data);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
this.logger.error("Failed to set in Redis", {
|
|
70
|
+
error: errMsg(error),
|
|
71
|
+
key,
|
|
72
|
+
});
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Delete value from Redis
|
|
78
|
+
*/
|
|
79
|
+
async delete(key) {
|
|
80
|
+
try {
|
|
81
|
+
await this.redis.del(key);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
this.logger.error("Failed to delete from Redis", {
|
|
85
|
+
error: errMsg(error),
|
|
86
|
+
key,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Scan for all keys matching a prefix (cursor-based, production-safe).
|
|
92
|
+
* Returns full key strings matching `{prefix}*`.
|
|
93
|
+
*/
|
|
94
|
+
async scanByPrefix(prefix) {
|
|
95
|
+
const results = [];
|
|
96
|
+
let cursor = "0";
|
|
97
|
+
try {
|
|
98
|
+
do {
|
|
99
|
+
const [nextCursor, keys] = await this.redis.scan(cursor, "MATCH", `${prefix}*`, "COUNT", 100);
|
|
100
|
+
cursor = nextCursor;
|
|
101
|
+
results.push(...keys);
|
|
102
|
+
} while (cursor !== "0");
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.logger.error("Failed to scan by prefix", {
|
|
106
|
+
error: errMsg(error),
|
|
107
|
+
prefix,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if key exists in Redis
|
|
114
|
+
*/
|
|
115
|
+
async exists(key) {
|
|
116
|
+
try {
|
|
117
|
+
const result = await this.redis.exists(key);
|
|
118
|
+
return result === 1;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.logger.error("Failed to check existence in Redis", {
|
|
122
|
+
error: errMsg(error),
|
|
123
|
+
key,
|
|
124
|
+
});
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serialize value to string
|
|
130
|
+
* Override for custom serialization
|
|
131
|
+
*/
|
|
132
|
+
serialize(value) {
|
|
133
|
+
const result = (0, json_1.safeJsonStringify)(value);
|
|
134
|
+
if (result === null) {
|
|
135
|
+
throw new Error("Failed to serialize value to JSON");
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Deserialize string to value
|
|
141
|
+
* Override for custom deserialization
|
|
142
|
+
*/
|
|
143
|
+
deserialize(data) {
|
|
144
|
+
const result = (0, json_1.safeJsonParse)(data);
|
|
145
|
+
if (result === null) {
|
|
146
|
+
throw new Error("Failed to deserialize JSON data");
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Validate value after deserialization
|
|
152
|
+
* Override to add custom validation logic
|
|
153
|
+
* Return false to reject invalid data
|
|
154
|
+
*/
|
|
155
|
+
validate(_value) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.BaseRedisStore = BaseRedisStore;
|
|
160
|
+
/**
|
|
161
|
+
* Specialized base for credential stores
|
|
162
|
+
* Validates that accessToken field exists
|
|
163
|
+
*/
|
|
164
|
+
class BaseCredentialStore extends BaseRedisStore {
|
|
165
|
+
validate(value) {
|
|
166
|
+
if (!value.accessToken) {
|
|
167
|
+
this.logger.warn("Invalid credentials: missing accessToken");
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.BaseCredentialStore = BaseCredentialStore;
|
|
174
|
+
//# sourceMappingURL=base-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-store.js","sourceRoot":"","sources":["../../src/redis/base-store.ts"],"names":[],"mappings":";;;AACA,sCAAsD;AACtD,wCAAiE;AAEjE,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAQD;;;;;;;GAOG;AACH,MAAsB,cAAc;IAKlC,YAAY,MAAwB;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,IAAA,qBAAY,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG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ACd,CAAC;CACF;AAVD,kDAUC"}
|
package/dist/sentry.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize Sentry with configuration from environment variables
|
|
3
|
+
* Falls back to hardcoded DSN if SENTRY_DSN is not provided
|
|
4
|
+
* Uses dynamic import to avoid module resolution issues in dev mode
|
|
5
|
+
*/
|
|
6
|
+
export declare function initSentry(): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Get the initialized Sentry instance
|
|
9
|
+
* @returns Sentry instance or null if not initialized
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSentry(): typeof import("@sentry/node") | null;
|
|
12
|
+
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../src/sentry.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,wBAAsB,UAAU,kBA2B/B;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,cAAc,cAAc,CAAC,GAAG,IAAI,CAEhE"}
|