@probelabs/probe 0.6.0-rc134 → 0.6.0-rc136

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/index.d.ts CHANGED
@@ -560,5 +560,160 @@ export interface ProbeAgentEvents {
560
560
  removeAllListeners(event?: 'toolCall'): this;
561
561
  }
562
562
 
563
+ /**
564
+ * Simple telemetry configuration (no OpenTelemetry dependencies)
565
+ */
566
+ export interface SimpleTelemetryOptions {
567
+ /** Enable console logging */
568
+ enableConsole?: boolean;
569
+ /** Enable file logging */
570
+ enableFile?: boolean;
571
+ /** File path for logs */
572
+ filePath?: string;
573
+ }
574
+
575
+ /**
576
+ * Simple telemetry class for basic tracing without OpenTelemetry
577
+ */
578
+ export declare class SimpleTelemetry {
579
+ constructor(options?: SimpleTelemetryOptions);
580
+ log(message: string, data?: any): void;
581
+ flush(): Promise<void>;
582
+ shutdown(): Promise<void>;
583
+ }
584
+
585
+ /**
586
+ * Simple application tracer for basic operations
587
+ */
588
+ export declare class SimpleAppTracer {
589
+ constructor(telemetry?: SimpleTelemetry, sessionId?: string);
590
+ isEnabled(): boolean;
591
+ log(operation: string, data?: any): void;
592
+ flush(): Promise<void>;
593
+ shutdown(): Promise<void>;
594
+ }
595
+
596
+ /**
597
+ * Initialize simple telemetry from options
598
+ */
599
+ export declare function initializeSimpleTelemetryFromOptions(options: any): SimpleTelemetry;
600
+
601
+ /**
602
+ * Full OpenTelemetry configuration options
603
+ */
604
+ export interface TelemetryConfigOptions {
605
+ /** Service name for tracing */
606
+ serviceName?: string;
607
+ /** Service version */
608
+ serviceVersion?: string;
609
+ /** Enable file export */
610
+ enableFile?: boolean;
611
+ /** Enable remote OTLP export */
612
+ enableRemote?: boolean;
613
+ /** Enable console export */
614
+ enableConsole?: boolean;
615
+ /** File path for trace export */
616
+ filePath?: string;
617
+ /** Remote OTLP endpoint URL */
618
+ remoteEndpoint?: string;
619
+ }
620
+
621
+ /**
622
+ * Full OpenTelemetry configuration class
623
+ */
624
+ export declare class TelemetryConfig {
625
+ constructor(options?: TelemetryConfigOptions);
626
+
627
+ /** Initialize the OpenTelemetry SDK */
628
+ initialize(): void;
629
+
630
+ /** Get the tracer instance */
631
+ getTracer(): any;
632
+
633
+ /** Create a span with attributes */
634
+ createSpan(name: string, attributes?: Record<string, any>): any;
635
+
636
+ /** Wrap a function with automatic span creation */
637
+ wrapFunction(name: string, fn: Function, attributes?: Record<string, any>): Function;
638
+
639
+ /** Force flush all pending spans */
640
+ forceFlush(): Promise<void>;
641
+
642
+ /** Shutdown telemetry */
643
+ shutdown(): Promise<void>;
644
+ }
645
+
646
+ /**
647
+ * Application-specific tracing layer for AI operations
648
+ */
649
+ export declare class AppTracer {
650
+ constructor(telemetryConfig?: TelemetryConfig, sessionId?: string);
651
+
652
+ /** Check if tracing is enabled */
653
+ isEnabled(): boolean;
654
+
655
+ /** Create a root span for the agent session */
656
+ createSessionSpan(attributes?: Record<string, any>): any;
657
+
658
+ /** Create a span for AI model requests */
659
+ createAISpan(modelName: string, provider: string, attributes?: Record<string, any>): any;
660
+
661
+ /** Create a span for tool calls */
662
+ createToolSpan(toolName: string, attributes?: Record<string, any>): any;
663
+
664
+ /** Create a span for code search operations */
665
+ createSearchSpan(query: string, attributes?: Record<string, any>): any;
666
+
667
+ /** Create a span for code extraction operations */
668
+ createExtractSpan(files: string | string[], attributes?: Record<string, any>): any;
669
+
670
+ /** Create a span for agent iterations */
671
+ createIterationSpan(iteration: number, attributes?: Record<string, any>): any;
672
+
673
+ /** Create a span for delegation operations */
674
+ createDelegationSpan(task: string, attributes?: Record<string, any>): any;
675
+
676
+ /** Create a span for JSON validation operations */
677
+ createJsonValidationSpan(responseLength: number, attributes?: Record<string, any>): any;
678
+
679
+ /** Create a span for Mermaid validation operations */
680
+ createMermaidValidationSpan(diagramCount: number, attributes?: Record<string, any>): any;
681
+
682
+ /** Create a span for schema processing operations */
683
+ createSchemaProcessingSpan(schemaType: string, attributes?: Record<string, any>): any;
684
+
685
+ /** Record delegation events */
686
+ recordDelegationEvent(eventType: string, data?: Record<string, any>): void;
687
+
688
+ /** Record JSON validation events */
689
+ recordJsonValidationEvent(eventType: string, data?: Record<string, any>): void;
690
+
691
+ /** Record Mermaid validation events */
692
+ recordMermaidValidationEvent(eventType: string, data?: Record<string, any>): void;
693
+
694
+ /** Add an event to the current span */
695
+ addEvent(name: string, attributes?: Record<string, any>): void;
696
+
697
+ /** Set attributes on the current span */
698
+ setAttributes(attributes: Record<string, any>): void;
699
+
700
+ /** Wrap a function with automatic span creation */
701
+ wrapFunction(spanName: string, fn: Function, attributes?: Record<string, any>): Function;
702
+
703
+ /** Execute a function within a span context */
704
+ withSpan(spanName: string, fn: Function, attributes?: Record<string, any>): Promise<any>;
705
+
706
+ /** Force flush all pending spans */
707
+ flush(): Promise<void>;
708
+
709
+ /** Shutdown tracing */
710
+ shutdown(): Promise<void>;
711
+ }
712
+
713
+ /**
714
+ * Initialize full OpenTelemetry telemetry from options
715
+ */
716
+ export declare function initializeTelemetryFromOptions(options: any): TelemetryConfig;
717
+
563
718
  // Default export for ES modules
564
719
  export { ProbeAgent as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc134",
3
+ "version": "0.6.0-rc136",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -21,6 +21,10 @@
21
21
  "import": "./src/agent/simpleTelemetry.js",
22
22
  "require": "./cjs/agent/simpleTelemetry.cjs"
23
23
  },
24
+ "./telemetry/full": {
25
+ "import": "./src/agent/telemetry.js",
26
+ "require": "./cjs/agent/telemetry.cjs"
27
+ },
24
28
  "./agent/mcp": {
25
29
  "import": "./src/agent/mcp/index.js"
26
30
  }
@@ -1613,8 +1613,7 @@ When troubleshooting:
1613
1613
  // Build appropriate reminder message based on whether schema is provided
1614
1614
  let reminderContent;
1615
1615
  if (options.schema) { // Apply for ANY schema, not just JSON schemas
1616
- // When schema is provided, AI should either use tools OR provide natural response
1617
- // Schema formatting will happen automatically afterward
1616
+ // When schema is provided, AI must use attempt_completion to trigger schema formatting
1618
1617
  reminderContent = `Please use one of the available tools to help answer the question, or use attempt_completion if you have enough information to provide a final answer.
1619
1618
 
1620
1619
  Remember: Use proper XML format with BOTH opening and closing tags:
@@ -1623,16 +1622,14 @@ Remember: Use proper XML format with BOTH opening and closing tags:
1623
1622
  <parameter>value</parameter>
1624
1623
  </tool_name>
1625
1624
 
1626
- IMPORTANT: A schema was provided for the final output format. You have two options:
1625
+ IMPORTANT: A schema was provided for the final output format.
1627
1626
 
1628
- Option 1 - Use attempt_completion with your complete answer:
1627
+ You MUST use attempt_completion to provide your answer:
1629
1628
  <attempt_completion>
1630
- [Your complete answer here - will be automatically formatted to match the schema]
1629
+ [Your complete answer here - provide in natural language, it will be automatically formatted to match the schema]
1631
1630
  </attempt_completion>
1632
1631
 
1633
- Option 2 - Provide a natural response without any tool, and it will be automatically formatted.
1634
-
1635
- Do NOT try to format your response as JSON yourself - this will be done automatically.`;
1632
+ Your response will be automatically formatted to JSON. You can provide your answer in natural language or as JSON - either will work.`;
1636
1633
  } else {
1637
1634
  // Standard reminder without schema
1638
1635
  reminderContent = `Please use one of the available tools to help answer the question, or use attempt_completion if you have enough information to provide a final answer.
@@ -1928,8 +1925,9 @@ Convert your previous response content into actual JSON data that follows this s
1928
1925
  }
1929
1926
  } else if (reachedMaxIterations && options.schema && this.debug) {
1930
1927
  console.log('[DEBUG] Skipping schema formatting due to max iterations reached without completion');
1931
- } else if (completionAttempted && options.schema && !options._schemaFormatted) {
1928
+ } else if (completionAttempted && options.schema && !options._schemaFormatted && !options._skipValidation) {
1932
1929
  // For attempt_completion results with schema, still clean markdown if needed
1930
+ // Skip this validation if we're in a recursive correction call (_skipValidation flag)
1933
1931
  try {
1934
1932
  finalResult = cleanSchemaResponse(finalResult);
1935
1933
 
@@ -1995,9 +1993,10 @@ Convert your previous response content into actual JSON data that follows this s
1995
1993
  0
1996
1994
  );
1997
1995
 
1998
- finalResult = await this.answer(schemaDefinitionPrompt, [], {
1999
- ...options,
2000
- _schemaFormatted: true
1996
+ finalResult = await this.answer(schemaDefinitionPrompt, [], {
1997
+ ...options,
1998
+ _schemaFormatted: true,
1999
+ _skipValidation: true // Skip validation in recursive correction calls to prevent loops
2001
2000
  });
2002
2001
  finalResult = cleanSchemaResponse(finalResult);
2003
2002
  validation = validateJsonResponse(finalResult);
@@ -2040,9 +2039,10 @@ Convert your previous response content into actual JSON data that follows this s
2040
2039
  );
2041
2040
  }
2042
2041
 
2043
- finalResult = await this.answer(correctionPrompt, [], {
2044
- ...options,
2045
- _schemaFormatted: true
2042
+ finalResult = await this.answer(correctionPrompt, [], {
2043
+ ...options,
2044
+ _schemaFormatted: true,
2045
+ _skipValidation: true // Skip validation in recursive correction calls to prevent loops
2046
2046
  });
2047
2047
  finalResult = cleanSchemaResponse(finalResult);
2048
2048
 
@@ -765,6 +765,9 @@ Ensure all Mermaid diagrams are properly formatted within \`\`\`mermaid code blo
765
765
  return prompt;
766
766
  }
767
767
 
768
+ // Counter to ensure unique session IDs even when created in the same millisecond
769
+ let sessionIdCounter = 0;
770
+
768
771
  /**
769
772
  * Specialized JSON fixing agent
770
773
  * Uses a separate ProbeAgent instance optimized for JSON syntax correction
@@ -774,7 +777,7 @@ export class JsonFixingAgent {
774
777
  // Import ProbeAgent dynamically to avoid circular dependencies
775
778
  this.ProbeAgent = null;
776
779
  this.options = {
777
- sessionId: options.sessionId || `json-fixer-${Date.now()}`,
780
+ sessionId: options.sessionId || `json-fixer-${Date.now()}-${sessionIdCounter++}`,
778
781
  path: options.path || process.cwd(),
779
782
  provider: options.provider,
780
783
  model: options.model,
@@ -1001,7 +1004,7 @@ export class MermaidFixingAgent {
1001
1004
  // Import ProbeAgent dynamically to avoid circular dependencies
1002
1005
  this.ProbeAgent = null;
1003
1006
  this.options = {
1004
- sessionId: options.sessionId || `mermaid-fixer-${Date.now()}`,
1007
+ sessionId: options.sessionId || `mermaid-fixer-${Date.now()}-${sessionIdCounter++}`,
1005
1008
  path: options.path || process.cwd(),
1006
1009
  provider: options.provider,
1007
1010
  model: options.model,
@@ -1,6 +1,6 @@
1
1
  import nodeSDKPkg from '@opentelemetry/sdk-node';
2
2
  import resourcesPkg from '@opentelemetry/resources';
3
- import semanticConventionsPkg from '@opentelemetry/semantic-conventions';
3
+ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
4
4
  import { trace, context, SpanStatusCode } from '@opentelemetry/api';
5
5
  import otlpPkg from '@opentelemetry/exporter-trace-otlp-http';
6
6
  import spanPkg from '@opentelemetry/sdk-trace-base';
@@ -10,8 +10,7 @@ import { dirname } from 'path';
10
10
  import { FileSpanExporter } from './fileSpanExporter.js';
11
11
 
12
12
  const { NodeSDK } = nodeSDKPkg;
13
- const { resourceFromAttributes } = resourcesPkg;
14
- const { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } = semanticConventionsPkg;
13
+ const { Resource } = resourcesPkg;
15
14
  const { OTLPTraceExporter } = otlpPkg;
16
15
  const { BatchSpanProcessor, ConsoleSpanExporter } = spanPkg;
17
16
 
@@ -40,7 +39,7 @@ export class TelemetryConfig {
40
39
  return;
41
40
  }
42
41
 
43
- const resource = resourceFromAttributes({
42
+ const resource = new Resource({
44
43
  [ATTR_SERVICE_NAME]: this.serviceName,
45
44
  [ATTR_SERVICE_VERSION]: this.serviceVersion,
46
45
  });
package/src/index.js CHANGED
@@ -35,6 +35,8 @@ import { searchTool, queryTool, extractTool, delegateTool } from './tools/vercel
35
35
  import { bashTool } from './tools/bash.js';
36
36
  import { ProbeAgent } from './agent/ProbeAgent.js';
37
37
  import { SimpleTelemetry, SimpleAppTracer, initializeSimpleTelemetryFromOptions } from './agent/simpleTelemetry.js';
38
+ import { TelemetryConfig, initializeTelemetryFromOptions } from './agent/telemetry.js';
39
+ import { AppTracer } from './agent/appTracer.js';
38
40
  import { listFilesToolInstance, searchFilesToolInstance } from './agent/probeTool.js';
39
41
  import { StorageAdapter, InMemoryStorageAdapter } from './agent/storage/index.js';
40
42
  import { HookManager, HOOK_TYPES } from './agent/hooks/index.js';
@@ -58,10 +60,14 @@ export {
58
60
  // Export hooks
59
61
  HookManager,
60
62
  HOOK_TYPES,
61
- // Export telemetry classes
63
+ // Export simple telemetry classes (no OpenTelemetry dependencies)
62
64
  SimpleTelemetry,
63
65
  SimpleAppTracer,
64
66
  initializeSimpleTelemetryFromOptions,
67
+ // Export full OpenTelemetry telemetry classes
68
+ TelemetryConfig,
69
+ AppTracer,
70
+ initializeTelemetryFromOptions,
65
71
  // Export tool generators directly
66
72
  searchTool,
67
73
  queryTool,