risicare 0.1.3 → 0.1.5
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/index.cjs +66 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.js +64 -3
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/index.cjs.map +1 -1
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/openai/index.cjs.map +1 -1
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/vercel-ai/index.cjs.map +1 -1
- package/dist/providers/vercel-ai/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,15 +5,19 @@
|
|
|
5
5
|
* RISICARE_API_KEY, RISICARE_ENDPOINT, RISICARE_PROJECT_ID, etc.
|
|
6
6
|
*/
|
|
7
7
|
interface RisicareConfig {
|
|
8
|
-
/** API key for authentication (format: "rsk-{random}") */
|
|
8
|
+
/** API key for authentication (format: "rsk-{random}"). Each key is scoped to one project. */
|
|
9
9
|
apiKey?: string;
|
|
10
10
|
/** Gateway endpoint URL */
|
|
11
11
|
endpoint?: string;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Project is determined by your API key. This field is ignored
|
|
14
|
+
* by the gateway and will be removed in v1.0. Use `serviceName` and
|
|
15
|
+
* `environment` for within-project organization.
|
|
16
|
+
*/
|
|
13
17
|
projectId?: string;
|
|
14
|
-
/** Environment name (production, staging, development) */
|
|
18
|
+
/** Environment name (production, staging, development). Used for within-project organization. */
|
|
15
19
|
environment?: string;
|
|
16
|
-
/** Service name for
|
|
20
|
+
/** Service name for within-project organization. */
|
|
17
21
|
serviceName?: string;
|
|
18
22
|
/** Service version */
|
|
19
23
|
serviceVersion?: string;
|
|
@@ -288,7 +292,7 @@ declare class Tracer {
|
|
|
288
292
|
*
|
|
289
293
|
* Usage:
|
|
290
294
|
* import { init, shutdown } from 'risicare';
|
|
291
|
-
* init({ apiKey: 'rsk-...'
|
|
295
|
+
* init({ apiKey: 'rsk-...' }); // API key determines project
|
|
292
296
|
* // ... instrument code ...
|
|
293
297
|
* await shutdown(); // flush remaining spans
|
|
294
298
|
*/
|
|
@@ -298,7 +302,7 @@ declare class Tracer {
|
|
|
298
302
|
*
|
|
299
303
|
* @example
|
|
300
304
|
* import { init } from 'risicare';
|
|
301
|
-
* init({ apiKey: 'rsk-...',
|
|
305
|
+
* init({ apiKey: 'rsk-...', serviceName: 'my-agent', environment: 'production' });
|
|
302
306
|
*/
|
|
303
307
|
declare function init(config?: Partial<RisicareConfig>): void;
|
|
304
308
|
/**
|
|
@@ -341,6 +345,34 @@ declare function getMetrics(): {
|
|
|
341
345
|
queueCapacity: number;
|
|
342
346
|
queueUtilization: number;
|
|
343
347
|
};
|
|
348
|
+
/**
|
|
349
|
+
* Report a caught exception to the self-healing pipeline.
|
|
350
|
+
*
|
|
351
|
+
* Creates an error span that triggers diagnosis and fix generation.
|
|
352
|
+
* This function never throws and is non-blocking.
|
|
353
|
+
*
|
|
354
|
+
* @param error - The caught exception (Error object or string)
|
|
355
|
+
* @param options - Optional attributes and context overrides
|
|
356
|
+
*/
|
|
357
|
+
declare function reportError(error: unknown, options?: {
|
|
358
|
+
name?: string;
|
|
359
|
+
attributes?: Record<string, unknown>;
|
|
360
|
+
}): void;
|
|
361
|
+
/**
|
|
362
|
+
* Record a custom evaluation score on a trace.
|
|
363
|
+
*
|
|
364
|
+
* Sends the score to the server in a fire-and-forget fashion.
|
|
365
|
+
* This function never throws and is non-blocking.
|
|
366
|
+
*
|
|
367
|
+
* @param traceId - The trace to score
|
|
368
|
+
* @param name - Score name (e.g., "accuracy", "user_satisfaction")
|
|
369
|
+
* @param value - Score value between 0.0 and 1.0 inclusive
|
|
370
|
+
* @param options - Optional span_id and comment
|
|
371
|
+
*/
|
|
372
|
+
declare function score(traceId: string, name: string, value: number, options?: {
|
|
373
|
+
spanId?: string;
|
|
374
|
+
comment?: string;
|
|
375
|
+
}): void;
|
|
344
376
|
|
|
345
377
|
/**
|
|
346
378
|
* Agent context — identifies which agent is executing.
|
|
@@ -586,4 +618,4 @@ declare function registerSpan(span: Span, ttlMs?: number): void;
|
|
|
586
618
|
declare function getSpanById(spanId: string): Span | undefined;
|
|
587
619
|
declare function unregisterSpan(spanId: string): void;
|
|
588
620
|
|
|
589
|
-
export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, registerSpan, session, shutdown, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, unregisterSpan, withAgent, withPhase, withSession };
|
|
621
|
+
export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, registerSpan, reportError, score, session, shutdown, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, unregisterSpan, withAgent, withPhase, withSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,15 +5,19 @@
|
|
|
5
5
|
* RISICARE_API_KEY, RISICARE_ENDPOINT, RISICARE_PROJECT_ID, etc.
|
|
6
6
|
*/
|
|
7
7
|
interface RisicareConfig {
|
|
8
|
-
/** API key for authentication (format: "rsk-{random}") */
|
|
8
|
+
/** API key for authentication (format: "rsk-{random}"). Each key is scoped to one project. */
|
|
9
9
|
apiKey?: string;
|
|
10
10
|
/** Gateway endpoint URL */
|
|
11
11
|
endpoint?: string;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Project is determined by your API key. This field is ignored
|
|
14
|
+
* by the gateway and will be removed in v1.0. Use `serviceName` and
|
|
15
|
+
* `environment` for within-project organization.
|
|
16
|
+
*/
|
|
13
17
|
projectId?: string;
|
|
14
|
-
/** Environment name (production, staging, development) */
|
|
18
|
+
/** Environment name (production, staging, development). Used for within-project organization. */
|
|
15
19
|
environment?: string;
|
|
16
|
-
/** Service name for
|
|
20
|
+
/** Service name for within-project organization. */
|
|
17
21
|
serviceName?: string;
|
|
18
22
|
/** Service version */
|
|
19
23
|
serviceVersion?: string;
|
|
@@ -288,7 +292,7 @@ declare class Tracer {
|
|
|
288
292
|
*
|
|
289
293
|
* Usage:
|
|
290
294
|
* import { init, shutdown } from 'risicare';
|
|
291
|
-
* init({ apiKey: 'rsk-...'
|
|
295
|
+
* init({ apiKey: 'rsk-...' }); // API key determines project
|
|
292
296
|
* // ... instrument code ...
|
|
293
297
|
* await shutdown(); // flush remaining spans
|
|
294
298
|
*/
|
|
@@ -298,7 +302,7 @@ declare class Tracer {
|
|
|
298
302
|
*
|
|
299
303
|
* @example
|
|
300
304
|
* import { init } from 'risicare';
|
|
301
|
-
* init({ apiKey: 'rsk-...',
|
|
305
|
+
* init({ apiKey: 'rsk-...', serviceName: 'my-agent', environment: 'production' });
|
|
302
306
|
*/
|
|
303
307
|
declare function init(config?: Partial<RisicareConfig>): void;
|
|
304
308
|
/**
|
|
@@ -341,6 +345,34 @@ declare function getMetrics(): {
|
|
|
341
345
|
queueCapacity: number;
|
|
342
346
|
queueUtilization: number;
|
|
343
347
|
};
|
|
348
|
+
/**
|
|
349
|
+
* Report a caught exception to the self-healing pipeline.
|
|
350
|
+
*
|
|
351
|
+
* Creates an error span that triggers diagnosis and fix generation.
|
|
352
|
+
* This function never throws and is non-blocking.
|
|
353
|
+
*
|
|
354
|
+
* @param error - The caught exception (Error object or string)
|
|
355
|
+
* @param options - Optional attributes and context overrides
|
|
356
|
+
*/
|
|
357
|
+
declare function reportError(error: unknown, options?: {
|
|
358
|
+
name?: string;
|
|
359
|
+
attributes?: Record<string, unknown>;
|
|
360
|
+
}): void;
|
|
361
|
+
/**
|
|
362
|
+
* Record a custom evaluation score on a trace.
|
|
363
|
+
*
|
|
364
|
+
* Sends the score to the server in a fire-and-forget fashion.
|
|
365
|
+
* This function never throws and is non-blocking.
|
|
366
|
+
*
|
|
367
|
+
* @param traceId - The trace to score
|
|
368
|
+
* @param name - Score name (e.g., "accuracy", "user_satisfaction")
|
|
369
|
+
* @param value - Score value between 0.0 and 1.0 inclusive
|
|
370
|
+
* @param options - Optional span_id and comment
|
|
371
|
+
*/
|
|
372
|
+
declare function score(traceId: string, name: string, value: number, options?: {
|
|
373
|
+
spanId?: string;
|
|
374
|
+
comment?: string;
|
|
375
|
+
}): void;
|
|
344
376
|
|
|
345
377
|
/**
|
|
346
378
|
* Agent context — identifies which agent is executing.
|
|
@@ -586,4 +618,4 @@ declare function registerSpan(span: Span, ttlMs?: number): void;
|
|
|
586
618
|
declare function getSpanById(spanId: string): Span | undefined;
|
|
587
619
|
declare function unregisterSpan(spanId: string): void;
|
|
588
620
|
|
|
589
|
-
export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, registerSpan, session, shutdown, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, unregisterSpan, withAgent, withPhase, withSession };
|
|
621
|
+
export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, registerSpan, reportError, score, session, shutdown, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, unregisterSpan, withAgent, withPhase, withSession };
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,11 @@ function resolveConfig(config) {
|
|
|
5
5
|
const apiKey = config?.apiKey ?? env.RISICARE_API_KEY;
|
|
6
6
|
const endpoint = config?.endpoint ?? env.RISICARE_ENDPOINT ?? DEFAULT_ENDPOINT;
|
|
7
7
|
const projectId = config?.projectId ?? env.RISICARE_PROJECT_ID;
|
|
8
|
+
if (config?.projectId || env.RISICARE_PROJECT_ID) {
|
|
9
|
+
console.warn(
|
|
10
|
+
"[risicare] projectId is deprecated and ignored by the gateway. Your API key determines the project. Use serviceName and environment for within-project organization. projectId will be removed in v1.0."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
8
13
|
const environment = config?.environment ?? env.RISICARE_ENVIRONMENT ?? "development";
|
|
9
14
|
const serviceName = config?.serviceName ?? env.RISICARE_SERVICE_NAME;
|
|
10
15
|
const serviceVersion = config?.serviceVersion ?? env.RISICARE_SERVICE_VERSION;
|
|
@@ -1038,10 +1043,66 @@ function getMetrics() {
|
|
|
1038
1043
|
queueUtilization: 0
|
|
1039
1044
|
};
|
|
1040
1045
|
}
|
|
1046
|
+
function reportError(error, options) {
|
|
1047
|
+
try {
|
|
1048
|
+
const tracer = getTracer2();
|
|
1049
|
+
if (!tracer) return;
|
|
1050
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1051
|
+
const spanName = options?.name ?? `error:${err.constructor.name}`;
|
|
1052
|
+
tracer.startSpan({ name: spanName, kind: "internal" /* INTERNAL */ }, (span) => {
|
|
1053
|
+
span.setStatus("error" /* ERROR */, err.message);
|
|
1054
|
+
span.setAttribute("error", true);
|
|
1055
|
+
span.setAttribute("error.type", err.constructor.name);
|
|
1056
|
+
span.setAttribute("error.message", err.message.slice(0, 2e3));
|
|
1057
|
+
if (err.stack) span.setAttribute("error.stack", err.stack.slice(0, 4e3));
|
|
1058
|
+
span.setAttribute("risicare.reported_error", true);
|
|
1059
|
+
if (options?.attributes) {
|
|
1060
|
+
for (const [k, v] of Object.entries(options.attributes)) {
|
|
1061
|
+
span.setAttribute(k, v);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
} catch {
|
|
1066
|
+
debug("reportError failed");
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
function score(traceId, name, value, options) {
|
|
1070
|
+
try {
|
|
1071
|
+
if (typeof value !== "number" || value < 0 || value > 1) {
|
|
1072
|
+
debug(`score: value must be in [0.0, 1.0], got ${value}. Score not sent.`);
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
if (!traceId || !name) {
|
|
1076
|
+
debug("score: traceId and name are required");
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
const client = getClient();
|
|
1080
|
+
if (!client?.enabled || !client.config.apiKey) return;
|
|
1081
|
+
const endpoint = client.config.endpoint.replace(/\/$/, "");
|
|
1082
|
+
const url = `${endpoint}/api/v1/scores`;
|
|
1083
|
+
const body = JSON.stringify({
|
|
1084
|
+
trace_id: traceId,
|
|
1085
|
+
name,
|
|
1086
|
+
score: value,
|
|
1087
|
+
source: "sdk",
|
|
1088
|
+
...options?.spanId && { span_id: options.spanId },
|
|
1089
|
+
...options?.comment && { comment: options.comment }
|
|
1090
|
+
});
|
|
1091
|
+
fetch(url, {
|
|
1092
|
+
method: "POST",
|
|
1093
|
+
headers: {
|
|
1094
|
+
"Content-Type": "application/json",
|
|
1095
|
+
"Authorization": `Bearer ${client.config.apiKey}`
|
|
1096
|
+
},
|
|
1097
|
+
body
|
|
1098
|
+
}).catch((err) => debug(`score: send failed: ${err}`));
|
|
1099
|
+
} catch {
|
|
1100
|
+
debug("score failed");
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1041
1103
|
|
|
1042
1104
|
// src/context/agent.ts
|
|
1043
1105
|
function withAgent(options, fn) {
|
|
1044
|
-
if (!isEnabled()) return fn();
|
|
1045
1106
|
const parent = getCurrentAgent();
|
|
1046
1107
|
const agentName = options.name ?? "agent";
|
|
1047
1108
|
const agent2 = {
|
|
@@ -1074,7 +1135,6 @@ function agent(options, fn) {
|
|
|
1074
1135
|
|
|
1075
1136
|
// src/context/session.ts
|
|
1076
1137
|
function withSession(options, fn) {
|
|
1077
|
-
if (!isEnabled()) return fn();
|
|
1078
1138
|
const session2 = {
|
|
1079
1139
|
sessionId: options.sessionId,
|
|
1080
1140
|
userId: options.userId,
|
|
@@ -1095,7 +1155,6 @@ function session(optionsOrResolver, fn) {
|
|
|
1095
1155
|
|
|
1096
1156
|
// src/context/phase.ts
|
|
1097
1157
|
function withPhase(phase, fn) {
|
|
1098
|
-
if (!isEnabled()) return fn();
|
|
1099
1158
|
return runWithContext({ phase }, fn);
|
|
1100
1159
|
}
|
|
1101
1160
|
|
|
@@ -1331,6 +1390,8 @@ export {
|
|
|
1331
1390
|
injectTraceContext,
|
|
1332
1391
|
isEnabled,
|
|
1333
1392
|
registerSpan,
|
|
1393
|
+
reportError,
|
|
1394
|
+
score,
|
|
1334
1395
|
session,
|
|
1335
1396
|
shutdown,
|
|
1336
1397
|
traceAct,
|