netra-sdk 1.1.0-beta.1 → 1.2.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/index.d.cts CHANGED
@@ -1061,6 +1061,32 @@ interface DecoratorOptions {
1061
1061
  }
1062
1062
  type SpanCallback<T> = (span: SpanWrapper) => T;
1063
1063
 
1064
+ /**
1065
+ * Raw file metadata received from the backend.
1066
+ *
1067
+ * Contains a pre-signed download URL that the SDK uses to fetch the actual
1068
+ * file content. Instances are produced by parsing the `attachments` array
1069
+ * returned on each user message from the simulation API.
1070
+ */
1071
+ interface FileData {
1072
+ fileName: string;
1073
+ contentType: string;
1074
+ description?: string;
1075
+ downloadUrl: string;
1076
+ }
1077
+ /**
1078
+ * File after download and base64 encoding, delivered to the user task.
1079
+ *
1080
+ * The `data` field contains the raw file bytes encoded as a base64 ASCII
1081
+ * string. Consumers should decode with `Buffer.from(data, "base64")` before
1082
+ * passing to an LLM or other downstream system.
1083
+ */
1084
+ interface ProcessedFile {
1085
+ fileName: string;
1086
+ contentType: string;
1087
+ description?: string;
1088
+ data: string;
1089
+ }
1064
1090
  /**
1065
1091
  * Represents a single item in a simulation run.
1066
1092
  */
@@ -1068,6 +1094,7 @@ interface SimulationItem {
1068
1094
  runItemId: string;
1069
1095
  message: string;
1070
1096
  turnId: string;
1097
+ files?: FileData[];
1071
1098
  }
1072
1099
  /**
1073
1100
  * Response from the conversation trigger API.
@@ -1078,6 +1105,7 @@ interface ConversationResponse {
1078
1105
  nextTurnId?: string;
1079
1106
  nextUserMessage?: string;
1080
1107
  nextRunItemId?: string;
1108
+ nextFiles?: FileData[];
1081
1109
  }
1082
1110
  /**
1083
1111
  * Result returned from the user's task function.
@@ -1108,13 +1136,17 @@ interface SimulationResult {
1108
1136
 
1109
1137
  declare abstract class BaseTask {
1110
1138
  /**
1139
+ * Process a simulation turn and return the agent's response.
1140
+ *
1111
1141
  * @param message - The input message from the simulation.
1112
- * @param sessionId - The Session identifier.
1142
+ * @param sessionId - The session identifier.
1143
+ * @param files - Optional list of base64-encoded file attachments from the
1144
+ * dataset item. Will be `null` when no files are attached.
1113
1145
  * @returns The task result containing:
1114
1146
  * - message (string): The response message from the task.
1115
1147
  * - sessionId (string): The session identifier.
1116
1148
  */
1117
- abstract run(message: string, sessionId?: string | null): Promise<TaskResult> | TaskResult;
1149
+ abstract run(message: string, sessionId?: string | null, files?: ProcessedFile[] | null): Promise<TaskResult> | TaskResult;
1118
1150
  }
1119
1151
 
1120
1152
  /**
@@ -1206,13 +1238,12 @@ declare class NetraMistralAIInstrumentor {
1206
1238
  instrumentationDependencies(): string[];
1207
1239
  /**
1208
1240
  * Instrument MistralAI client methods (async version)
1209
- * Uses dynamic import() to ensure we get the same ES module instance
1210
- * that the application uses.
1241
+ * Tries both ESM and CJS resolution to cover dual-package setups.
1211
1242
  */
1212
1243
  instrumentAsync(options?: InstrumentorOptions$1): Promise<NetraMistralAIInstrumentor>;
1213
1244
  /**
1214
1245
  * Instrument MistralAI client methods (sync version - for backwards compatibility)
1215
- * Note: This uses a cached Mistral class. Call instrumentAsync() for proper initialization.
1246
+ * Note: This uses cached Mistral classes. Call instrumentAsync() for proper initialization.
1216
1247
  */
1217
1248
  instrument(options?: InstrumentorOptions$1): NetraMistralAIInstrumentor;
1218
1249
  /**
@@ -1390,6 +1421,82 @@ declare class TrialAwareOTLPExporter implements SpanExporter {
1390
1421
  shutdown(): Promise<void>;
1391
1422
  }
1392
1423
 
1424
+ /**
1425
+ * Public helpers for distributed tracing context propagation.
1426
+ *
1427
+ * These utilities let users extract incoming W3C Trace Context from HTTP
1428
+ * headers and run code within that context so that all child spans (LLM
1429
+ * calls, database queries, outgoing HTTP, etc.) are linked to the upstream
1430
+ * trace.
1431
+ *
1432
+ * When `@opentelemetry/instrumentation-http` + `@opentelemetry/instrumentation-express`
1433
+ * are installed and working, incoming context extraction happens automatically.
1434
+ * These helpers cover cases where auto-instrumentation is unavailable (e.g.
1435
+ * ESM module loading order issues, missing peer dependencies, or non-Express
1436
+ * frameworks).
1437
+ */
1438
+
1439
+ /**
1440
+ * Run a function within a context extracted from HTTP headers.
1441
+ *
1442
+ * All spans created inside `fn` will be children of the trace described by the
1443
+ * incoming `traceparent` / `tracestate` headers, enabling end-to-end
1444
+ * distributed tracing across service boundaries.
1445
+ *
1446
+ * @param headers - Incoming HTTP request headers (e.g. `req.headers`).
1447
+ * @param fn - The function to execute within the extracted context.
1448
+ * May be sync or async -- the return value is forwarded as-is.
1449
+ * @returns The return value of `fn`.
1450
+ *
1451
+ * @example
1452
+ * ```ts
1453
+ * import { runWithExtractedContext } from "netra";
1454
+ *
1455
+ * app.post("/api/chat", async (req, res) => {
1456
+ * await runWithExtractedContext(req.headers, async () => {
1457
+ * const result = await myAgent(req.body.message);
1458
+ * res.json(result);
1459
+ * });
1460
+ * });
1461
+ * ```
1462
+ */
1463
+ declare function runWithExtractedContext<T>(headers: Record<string, string | string[] | undefined>, fn: () => T): T;
1464
+ /**
1465
+ * Express/Connect-compatible middleware that extracts W3C Trace Context from
1466
+ * incoming request headers and runs all downstream handlers within the
1467
+ * extracted context.
1468
+ *
1469
+ * This is the recommended way to enable distributed tracing for Express
1470
+ * servers when `@opentelemetry/instrumentation-http` is not available or not
1471
+ * working (e.g. due to ESM module loading order with `tsx`). It is the
1472
+ * TypeScript equivalent of the Python SDK's `NetraFastAPIMiddleware`.
1473
+ *
1474
+ * **Note:** In Express 4.x, async errors thrown inside downstream handlers are
1475
+ * not automatically caught by the Express error handler. Wrap async route
1476
+ * handlers with your own try/catch or use Express 5 which supports async
1477
+ * error propagation natively.
1478
+ *
1479
+ * @returns An Express middleware function.
1480
+ *
1481
+ * @example
1482
+ * ```ts
1483
+ * import express from "express";
1484
+ * import { netraExpressMiddleware } from "netra-sdk";
1485
+ *
1486
+ * const app = express();
1487
+ * app.use(netraExpressMiddleware());
1488
+ *
1489
+ * app.post("/api/chat", async (req, res) => {
1490
+ * // Spans created here are children of the upstream trace
1491
+ * const result = await myAgent(req.body.message);
1492
+ * res.json(result);
1493
+ * });
1494
+ * ```
1495
+ */
1496
+ declare function netraExpressMiddleware(): (req: {
1497
+ headers: Record<string, string | string[] | undefined>;
1498
+ }, res: unknown, next: () => void) => void;
1499
+
1393
1500
  /**
1394
1501
  * Netra SDK - Main entry point
1395
1502
  * A comprehensive TypeScript/JavaScript SDK for AI application observability
@@ -1453,4 +1560,4 @@ declare class Netra {
1453
1560
  static withBlockedSpansLocal: typeof withBlockedSpansLocal;
1454
1561
  }
1455
1562
 
1456
- export { type ActionModel, Aggregation, BaseTask, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, type CreateRunResult, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, openaiAgentsInstrumentor, span, task, workflow };
1563
+ export { type ActionModel, Aggregation, BaseTask, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, type CreateRunResult, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, span, task, workflow };
package/dist/index.d.ts CHANGED
@@ -1061,6 +1061,32 @@ interface DecoratorOptions {
1061
1061
  }
1062
1062
  type SpanCallback<T> = (span: SpanWrapper) => T;
1063
1063
 
1064
+ /**
1065
+ * Raw file metadata received from the backend.
1066
+ *
1067
+ * Contains a pre-signed download URL that the SDK uses to fetch the actual
1068
+ * file content. Instances are produced by parsing the `attachments` array
1069
+ * returned on each user message from the simulation API.
1070
+ */
1071
+ interface FileData {
1072
+ fileName: string;
1073
+ contentType: string;
1074
+ description?: string;
1075
+ downloadUrl: string;
1076
+ }
1077
+ /**
1078
+ * File after download and base64 encoding, delivered to the user task.
1079
+ *
1080
+ * The `data` field contains the raw file bytes encoded as a base64 ASCII
1081
+ * string. Consumers should decode with `Buffer.from(data, "base64")` before
1082
+ * passing to an LLM or other downstream system.
1083
+ */
1084
+ interface ProcessedFile {
1085
+ fileName: string;
1086
+ contentType: string;
1087
+ description?: string;
1088
+ data: string;
1089
+ }
1064
1090
  /**
1065
1091
  * Represents a single item in a simulation run.
1066
1092
  */
@@ -1068,6 +1094,7 @@ interface SimulationItem {
1068
1094
  runItemId: string;
1069
1095
  message: string;
1070
1096
  turnId: string;
1097
+ files?: FileData[];
1071
1098
  }
1072
1099
  /**
1073
1100
  * Response from the conversation trigger API.
@@ -1078,6 +1105,7 @@ interface ConversationResponse {
1078
1105
  nextTurnId?: string;
1079
1106
  nextUserMessage?: string;
1080
1107
  nextRunItemId?: string;
1108
+ nextFiles?: FileData[];
1081
1109
  }
1082
1110
  /**
1083
1111
  * Result returned from the user's task function.
@@ -1108,13 +1136,17 @@ interface SimulationResult {
1108
1136
 
1109
1137
  declare abstract class BaseTask {
1110
1138
  /**
1139
+ * Process a simulation turn and return the agent's response.
1140
+ *
1111
1141
  * @param message - The input message from the simulation.
1112
- * @param sessionId - The Session identifier.
1142
+ * @param sessionId - The session identifier.
1143
+ * @param files - Optional list of base64-encoded file attachments from the
1144
+ * dataset item. Will be `null` when no files are attached.
1113
1145
  * @returns The task result containing:
1114
1146
  * - message (string): The response message from the task.
1115
1147
  * - sessionId (string): The session identifier.
1116
1148
  */
1117
- abstract run(message: string, sessionId?: string | null): Promise<TaskResult> | TaskResult;
1149
+ abstract run(message: string, sessionId?: string | null, files?: ProcessedFile[] | null): Promise<TaskResult> | TaskResult;
1118
1150
  }
1119
1151
 
1120
1152
  /**
@@ -1206,13 +1238,12 @@ declare class NetraMistralAIInstrumentor {
1206
1238
  instrumentationDependencies(): string[];
1207
1239
  /**
1208
1240
  * Instrument MistralAI client methods (async version)
1209
- * Uses dynamic import() to ensure we get the same ES module instance
1210
- * that the application uses.
1241
+ * Tries both ESM and CJS resolution to cover dual-package setups.
1211
1242
  */
1212
1243
  instrumentAsync(options?: InstrumentorOptions$1): Promise<NetraMistralAIInstrumentor>;
1213
1244
  /**
1214
1245
  * Instrument MistralAI client methods (sync version - for backwards compatibility)
1215
- * Note: This uses a cached Mistral class. Call instrumentAsync() for proper initialization.
1246
+ * Note: This uses cached Mistral classes. Call instrumentAsync() for proper initialization.
1216
1247
  */
1217
1248
  instrument(options?: InstrumentorOptions$1): NetraMistralAIInstrumentor;
1218
1249
  /**
@@ -1390,6 +1421,82 @@ declare class TrialAwareOTLPExporter implements SpanExporter {
1390
1421
  shutdown(): Promise<void>;
1391
1422
  }
1392
1423
 
1424
+ /**
1425
+ * Public helpers for distributed tracing context propagation.
1426
+ *
1427
+ * These utilities let users extract incoming W3C Trace Context from HTTP
1428
+ * headers and run code within that context so that all child spans (LLM
1429
+ * calls, database queries, outgoing HTTP, etc.) are linked to the upstream
1430
+ * trace.
1431
+ *
1432
+ * When `@opentelemetry/instrumentation-http` + `@opentelemetry/instrumentation-express`
1433
+ * are installed and working, incoming context extraction happens automatically.
1434
+ * These helpers cover cases where auto-instrumentation is unavailable (e.g.
1435
+ * ESM module loading order issues, missing peer dependencies, or non-Express
1436
+ * frameworks).
1437
+ */
1438
+
1439
+ /**
1440
+ * Run a function within a context extracted from HTTP headers.
1441
+ *
1442
+ * All spans created inside `fn` will be children of the trace described by the
1443
+ * incoming `traceparent` / `tracestate` headers, enabling end-to-end
1444
+ * distributed tracing across service boundaries.
1445
+ *
1446
+ * @param headers - Incoming HTTP request headers (e.g. `req.headers`).
1447
+ * @param fn - The function to execute within the extracted context.
1448
+ * May be sync or async -- the return value is forwarded as-is.
1449
+ * @returns The return value of `fn`.
1450
+ *
1451
+ * @example
1452
+ * ```ts
1453
+ * import { runWithExtractedContext } from "netra";
1454
+ *
1455
+ * app.post("/api/chat", async (req, res) => {
1456
+ * await runWithExtractedContext(req.headers, async () => {
1457
+ * const result = await myAgent(req.body.message);
1458
+ * res.json(result);
1459
+ * });
1460
+ * });
1461
+ * ```
1462
+ */
1463
+ declare function runWithExtractedContext<T>(headers: Record<string, string | string[] | undefined>, fn: () => T): T;
1464
+ /**
1465
+ * Express/Connect-compatible middleware that extracts W3C Trace Context from
1466
+ * incoming request headers and runs all downstream handlers within the
1467
+ * extracted context.
1468
+ *
1469
+ * This is the recommended way to enable distributed tracing for Express
1470
+ * servers when `@opentelemetry/instrumentation-http` is not available or not
1471
+ * working (e.g. due to ESM module loading order with `tsx`). It is the
1472
+ * TypeScript equivalent of the Python SDK's `NetraFastAPIMiddleware`.
1473
+ *
1474
+ * **Note:** In Express 4.x, async errors thrown inside downstream handlers are
1475
+ * not automatically caught by the Express error handler. Wrap async route
1476
+ * handlers with your own try/catch or use Express 5 which supports async
1477
+ * error propagation natively.
1478
+ *
1479
+ * @returns An Express middleware function.
1480
+ *
1481
+ * @example
1482
+ * ```ts
1483
+ * import express from "express";
1484
+ * import { netraExpressMiddleware } from "netra-sdk";
1485
+ *
1486
+ * const app = express();
1487
+ * app.use(netraExpressMiddleware());
1488
+ *
1489
+ * app.post("/api/chat", async (req, res) => {
1490
+ * // Spans created here are children of the upstream trace
1491
+ * const result = await myAgent(req.body.message);
1492
+ * res.json(result);
1493
+ * });
1494
+ * ```
1495
+ */
1496
+ declare function netraExpressMiddleware(): (req: {
1497
+ headers: Record<string, string | string[] | undefined>;
1498
+ }, res: unknown, next: () => void) => void;
1499
+
1393
1500
  /**
1394
1501
  * Netra SDK - Main entry point
1395
1502
  * A comprehensive TypeScript/JavaScript SDK for AI application observability
@@ -1453,4 +1560,4 @@ declare class Netra {
1453
1560
  static withBlockedSpansLocal: typeof withBlockedSpansLocal;
1454
1561
  }
1455
1562
 
1456
- export { type ActionModel, Aggregation, BaseTask, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, type CreateRunResult, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, openaiAgentsInstrumentor, span, task, workflow };
1563
+ export { type ActionModel, Aggregation, BaseTask, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, type CreateRunResult, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, span, task, workflow };