risicare 0.1.5 → 0.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.
Files changed (93) hide show
  1. package/dist/frameworks/instructor.cjs +178 -0
  2. package/dist/frameworks/instructor.cjs.map +1 -0
  3. package/dist/frameworks/instructor.d.cts +28 -0
  4. package/dist/frameworks/instructor.d.ts +28 -0
  5. package/dist/frameworks/instructor.js +151 -0
  6. package/dist/frameworks/instructor.js.map +1 -0
  7. package/dist/frameworks/langchain.cjs +262 -0
  8. package/dist/frameworks/langchain.cjs.map +1 -0
  9. package/dist/frameworks/langchain.d.cts +45 -0
  10. package/dist/frameworks/langchain.d.ts +45 -0
  11. package/dist/frameworks/langchain.js +235 -0
  12. package/dist/frameworks/langchain.js.map +1 -0
  13. package/dist/frameworks/langgraph.cjs +296 -0
  14. package/dist/frameworks/langgraph.cjs.map +1 -0
  15. package/dist/frameworks/langgraph.d.cts +28 -0
  16. package/dist/frameworks/langgraph.d.ts +28 -0
  17. package/dist/frameworks/langgraph.js +269 -0
  18. package/dist/frameworks/langgraph.js.map +1 -0
  19. package/dist/frameworks/llamaindex.cjs +239 -0
  20. package/dist/frameworks/llamaindex.cjs.map +1 -0
  21. package/dist/frameworks/llamaindex.d.cts +55 -0
  22. package/dist/frameworks/llamaindex.d.ts +55 -0
  23. package/dist/frameworks/llamaindex.js +212 -0
  24. package/dist/frameworks/llamaindex.js.map +1 -0
  25. package/dist/index.cjs +407 -4
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +96 -6
  28. package/dist/index.d.ts +96 -6
  29. package/dist/index.js +400 -4
  30. package/dist/index.js.map +1 -1
  31. package/dist/providers/anthropic/index.cjs +22 -0
  32. package/dist/providers/anthropic/index.cjs.map +1 -1
  33. package/dist/providers/anthropic/index.js +22 -0
  34. package/dist/providers/anthropic/index.js.map +1 -1
  35. package/dist/providers/bedrock/index.cjs +334 -0
  36. package/dist/providers/bedrock/index.cjs.map +1 -0
  37. package/dist/providers/bedrock/index.d.cts +37 -0
  38. package/dist/providers/bedrock/index.d.ts +37 -0
  39. package/dist/providers/bedrock/index.js +307 -0
  40. package/dist/providers/bedrock/index.js.map +1 -0
  41. package/dist/providers/cerebras/index.cjs +282 -0
  42. package/dist/providers/cerebras/index.cjs.map +1 -0
  43. package/dist/providers/cerebras/index.d.cts +24 -0
  44. package/dist/providers/cerebras/index.d.ts +24 -0
  45. package/dist/providers/cerebras/index.js +255 -0
  46. package/dist/providers/cerebras/index.js.map +1 -0
  47. package/dist/providers/cohere/index.cjs +347 -0
  48. package/dist/providers/cohere/index.cjs.map +1 -0
  49. package/dist/providers/cohere/index.d.cts +24 -0
  50. package/dist/providers/cohere/index.d.ts +24 -0
  51. package/dist/providers/cohere/index.js +320 -0
  52. package/dist/providers/cohere/index.js.map +1 -0
  53. package/dist/providers/google/index.cjs +337 -0
  54. package/dist/providers/google/index.cjs.map +1 -0
  55. package/dist/providers/google/index.d.cts +25 -0
  56. package/dist/providers/google/index.d.ts +25 -0
  57. package/dist/providers/google/index.js +310 -0
  58. package/dist/providers/google/index.js.map +1 -0
  59. package/dist/providers/groq/index.cjs +282 -0
  60. package/dist/providers/groq/index.cjs.map +1 -0
  61. package/dist/providers/groq/index.d.cts +23 -0
  62. package/dist/providers/groq/index.d.ts +23 -0
  63. package/dist/providers/groq/index.js +255 -0
  64. package/dist/providers/groq/index.js.map +1 -0
  65. package/dist/providers/huggingface/index.cjs +289 -0
  66. package/dist/providers/huggingface/index.cjs.map +1 -0
  67. package/dist/providers/huggingface/index.d.cts +24 -0
  68. package/dist/providers/huggingface/index.d.ts +24 -0
  69. package/dist/providers/huggingface/index.js +262 -0
  70. package/dist/providers/huggingface/index.js.map +1 -0
  71. package/dist/providers/mistral/index.cjs +336 -0
  72. package/dist/providers/mistral/index.cjs.map +1 -0
  73. package/dist/providers/mistral/index.d.cts +24 -0
  74. package/dist/providers/mistral/index.d.ts +24 -0
  75. package/dist/providers/mistral/index.js +309 -0
  76. package/dist/providers/mistral/index.js.map +1 -0
  77. package/dist/providers/ollama/index.cjs +376 -0
  78. package/dist/providers/ollama/index.cjs.map +1 -0
  79. package/dist/providers/ollama/index.d.cts +28 -0
  80. package/dist/providers/ollama/index.d.ts +28 -0
  81. package/dist/providers/ollama/index.js +349 -0
  82. package/dist/providers/ollama/index.js.map +1 -0
  83. package/dist/providers/openai/index.cjs +31 -1
  84. package/dist/providers/openai/index.cjs.map +1 -1
  85. package/dist/providers/openai/index.js +31 -1
  86. package/dist/providers/openai/index.js.map +1 -1
  87. package/dist/providers/together/index.cjs +275 -0
  88. package/dist/providers/together/index.cjs.map +1 -0
  89. package/dist/providers/together/index.d.cts +24 -0
  90. package/dist/providers/together/index.d.ts +24 -0
  91. package/dist/providers/together/index.js +248 -0
  92. package/dist/providers/together/index.js.map +1 -0
  93. package/package.json +124 -2
package/dist/index.d.cts CHANGED
@@ -1,3 +1,8 @@
1
+ export { RisicareCallbackHandler } from './frameworks/langchain.cjs';
2
+ export { instrumentLangGraph } from './frameworks/langgraph.cjs';
3
+ export { patchInstructor } from './frameworks/instructor.cjs';
4
+ export { RisicareLlamaIndexHandler } from './frameworks/llamaindex.cjs';
5
+
1
6
  /**
2
7
  * SDK configuration with environment variable loading.
3
8
  *
@@ -83,18 +88,38 @@ declare enum SemanticPhase {
83
88
  declare enum AgentRole {
84
89
  ORCHESTRATOR = "orchestrator",
85
90
  WORKER = "worker",
86
- REVIEWER = "reviewer",
91
+ SUPERVISOR = "supervisor",
92
+ SPECIALIST = "specialist",
93
+ ROUTER = "router",
94
+ AGGREGATOR = "aggregator",
95
+ BROADCASTER = "broadcaster",
96
+ CRITIC = "critic",
87
97
  PLANNER = "planner",
88
98
  EXECUTOR = "executor",
89
- CRITIC = "critic",
99
+ RETRIEVER = "retriever",
100
+ VALIDATOR = "validator",
101
+ REVIEWER = "reviewer",
90
102
  CUSTOM = "custom"
91
103
  }
92
104
  declare enum MessageType {
93
- REQUEST = "request",
105
+ TASK = "task",
106
+ RESULT = "result",
107
+ STATUS = "status",
108
+ ERROR = "error",
109
+ QUERY = "query",
94
110
  RESPONSE = "response",
111
+ BROADCAST = "broadcast",
112
+ DIRECT = "direct",
113
+ PROPOSAL = "proposal",
114
+ VOTE = "vote",
115
+ CONSENSUS = "consensus",
116
+ CONFLICT = "conflict",
117
+ HEARTBEAT = "heartbeat",
118
+ SHUTDOWN = "shutdown",
119
+ HANDOFF = "handoff",
120
+ REQUEST = "request",
95
121
  DELEGATE = "delegate",
96
- COORDINATE = "coordinate",
97
- BROADCAST = "broadcast"
122
+ COORDINATE = "coordinate"
98
123
  }
99
124
  interface SpanEvent {
100
125
  name: string;
@@ -618,4 +643,69 @@ declare function registerSpan(span: Span, ttlMs?: number): void;
618
643
  declare function getSpanById(spanId: string): Span | undefined;
619
644
  declare function unregisterSpan(spanId: string): void;
620
645
 
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 };
646
+ /**
647
+ * tracedStream — Wrap an async iterable in a trace span.
648
+ *
649
+ * Creates a span that starts when iteration begins and ends when
650
+ * iteration completes (or errors). Chunks pass through UNCHANGED.
651
+ *
652
+ * This is the user-level streaming utility. For provider-level streaming
653
+ * enrichment (token counts, cost), see individual provider instrumentors.
654
+ *
655
+ * Usage:
656
+ * const stream = await openai.chat.completions.create({ stream: true, ... });
657
+ * for await (const chunk of tracedStream(stream, { name: 'llm-stream' })) {
658
+ * process(chunk);
659
+ * }
660
+ */
661
+
662
+ interface TracedStreamOptions {
663
+ /** Span name */
664
+ name: string;
665
+ /** Span kind (default: INTERNAL) */
666
+ kind?: SpanKind;
667
+ /** Additional span attributes */
668
+ attributes?: Record<string, unknown>;
669
+ }
670
+ /**
671
+ * Wrap an async iterable in a trace span.
672
+ *
673
+ * - Span starts on first iteration
674
+ * - chunk_count attribute set when iteration ends
675
+ * - On error: span records exception, error re-thrown to caller
676
+ * - On early break: span ended cleanly via finally
677
+ * - If SDK not initialized: chunks pass through without wrapping
678
+ */
679
+ declare function tracedStream<T>(source: AsyncIterable<T>, options: TracedStreamOptions | string): AsyncGenerator<T, void, undefined>;
680
+
681
+ /**
682
+ * Double-tracing prevention for framework integrations.
683
+ *
684
+ * When a framework integration (e.g., LlamaIndex handler) creates its own
685
+ * LLM span, the underlying provider proxy (e.g., patchOpenAI) would also
686
+ * create a duplicate span. This module provides suppression:
687
+ *
688
+ * - Framework integrations SET suppression via suppressProviderInstrumentation()
689
+ * - Provider proxies CHECK via isProviderInstrumentationSuppressed() and skip
690
+ *
691
+ * Scoped to AsyncLocalStorage — concurrent calls are independent.
692
+ */
693
+ /**
694
+ * Run a callback with provider instrumentation suppressed.
695
+ *
696
+ * During this callback, all provider instrumentors (patchOpenAI, etc.) will
697
+ * skip span creation. The framework is responsible for creating the span.
698
+ *
699
+ * @param fn - The function to run with suppression active
700
+ * @returns The function's return value
701
+ */
702
+ declare function suppressProviderInstrumentation<T>(fn: () => T): T;
703
+ /**
704
+ * Check if provider instrumentation should be suppressed.
705
+ *
706
+ * Called by provider instrumentors as an early-exit guard. When true,
707
+ * the provider calls the original method directly without creating a span.
708
+ */
709
+ declare function isProviderInstrumentationSuppressed(): boolean;
710
+
711
+ export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, withAgent, withPhase, withSession };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export { RisicareCallbackHandler } from './frameworks/langchain.js';
2
+ export { instrumentLangGraph } from './frameworks/langgraph.js';
3
+ export { patchInstructor } from './frameworks/instructor.js';
4
+ export { RisicareLlamaIndexHandler } from './frameworks/llamaindex.js';
5
+
1
6
  /**
2
7
  * SDK configuration with environment variable loading.
3
8
  *
@@ -83,18 +88,38 @@ declare enum SemanticPhase {
83
88
  declare enum AgentRole {
84
89
  ORCHESTRATOR = "orchestrator",
85
90
  WORKER = "worker",
86
- REVIEWER = "reviewer",
91
+ SUPERVISOR = "supervisor",
92
+ SPECIALIST = "specialist",
93
+ ROUTER = "router",
94
+ AGGREGATOR = "aggregator",
95
+ BROADCASTER = "broadcaster",
96
+ CRITIC = "critic",
87
97
  PLANNER = "planner",
88
98
  EXECUTOR = "executor",
89
- CRITIC = "critic",
99
+ RETRIEVER = "retriever",
100
+ VALIDATOR = "validator",
101
+ REVIEWER = "reviewer",
90
102
  CUSTOM = "custom"
91
103
  }
92
104
  declare enum MessageType {
93
- REQUEST = "request",
105
+ TASK = "task",
106
+ RESULT = "result",
107
+ STATUS = "status",
108
+ ERROR = "error",
109
+ QUERY = "query",
94
110
  RESPONSE = "response",
111
+ BROADCAST = "broadcast",
112
+ DIRECT = "direct",
113
+ PROPOSAL = "proposal",
114
+ VOTE = "vote",
115
+ CONSENSUS = "consensus",
116
+ CONFLICT = "conflict",
117
+ HEARTBEAT = "heartbeat",
118
+ SHUTDOWN = "shutdown",
119
+ HANDOFF = "handoff",
120
+ REQUEST = "request",
95
121
  DELEGATE = "delegate",
96
- COORDINATE = "coordinate",
97
- BROADCAST = "broadcast"
122
+ COORDINATE = "coordinate"
98
123
  }
99
124
  interface SpanEvent {
100
125
  name: string;
@@ -618,4 +643,69 @@ declare function registerSpan(span: Span, ttlMs?: number): void;
618
643
  declare function getSpanById(spanId: string): Span | undefined;
619
644
  declare function unregisterSpan(spanId: string): void;
620
645
 
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 };
646
+ /**
647
+ * tracedStream — Wrap an async iterable in a trace span.
648
+ *
649
+ * Creates a span that starts when iteration begins and ends when
650
+ * iteration completes (or errors). Chunks pass through UNCHANGED.
651
+ *
652
+ * This is the user-level streaming utility. For provider-level streaming
653
+ * enrichment (token counts, cost), see individual provider instrumentors.
654
+ *
655
+ * Usage:
656
+ * const stream = await openai.chat.completions.create({ stream: true, ... });
657
+ * for await (const chunk of tracedStream(stream, { name: 'llm-stream' })) {
658
+ * process(chunk);
659
+ * }
660
+ */
661
+
662
+ interface TracedStreamOptions {
663
+ /** Span name */
664
+ name: string;
665
+ /** Span kind (default: INTERNAL) */
666
+ kind?: SpanKind;
667
+ /** Additional span attributes */
668
+ attributes?: Record<string, unknown>;
669
+ }
670
+ /**
671
+ * Wrap an async iterable in a trace span.
672
+ *
673
+ * - Span starts on first iteration
674
+ * - chunk_count attribute set when iteration ends
675
+ * - On error: span records exception, error re-thrown to caller
676
+ * - On early break: span ended cleanly via finally
677
+ * - If SDK not initialized: chunks pass through without wrapping
678
+ */
679
+ declare function tracedStream<T>(source: AsyncIterable<T>, options: TracedStreamOptions | string): AsyncGenerator<T, void, undefined>;
680
+
681
+ /**
682
+ * Double-tracing prevention for framework integrations.
683
+ *
684
+ * When a framework integration (e.g., LlamaIndex handler) creates its own
685
+ * LLM span, the underlying provider proxy (e.g., patchOpenAI) would also
686
+ * create a duplicate span. This module provides suppression:
687
+ *
688
+ * - Framework integrations SET suppression via suppressProviderInstrumentation()
689
+ * - Provider proxies CHECK via isProviderInstrumentationSuppressed() and skip
690
+ *
691
+ * Scoped to AsyncLocalStorage — concurrent calls are independent.
692
+ */
693
+ /**
694
+ * Run a callback with provider instrumentation suppressed.
695
+ *
696
+ * During this callback, all provider instrumentors (patchOpenAI, etc.) will
697
+ * skip span creation. The framework is responsible for creating the span.
698
+ *
699
+ * @param fn - The function to run with suppression active
700
+ * @returns The function's return value
701
+ */
702
+ declare function suppressProviderInstrumentation<T>(fn: () => T): T;
703
+ /**
704
+ * Check if provider instrumentation should be suppressed.
705
+ *
706
+ * Called by provider instrumentors as an early-exit guard. When true,
707
+ * the provider calls the original method directly without creating a span.
708
+ */
709
+ declare function isProviderInstrumentationSuppressed(): boolean;
710
+
711
+ export { type AgentContext, type AgentOptions, AgentRole, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, withAgent, withPhase, withSession };