@probelabs/probe 0.6.0-rc233 → 0.6.0-rc234

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.
@@ -771,6 +771,78 @@ export function isJsonSchemaDefinition(jsonString, options = {}) {
771
771
  }
772
772
  }
773
773
 
774
+ /**
775
+ * Check if schema is a simple text wrapper (e.g., {text: string} or {response: string})
776
+ * These schemas can be auto-wrapped without re-invoking the AI
777
+ * @param {string} schema - The schema string
778
+ * @returns {Object|null} - Object with field name if simple wrapper, null otherwise
779
+ */
780
+ export function isSimpleTextWrapperSchema(schema) {
781
+ if (!schema || typeof schema !== 'string') {
782
+ return null;
783
+ }
784
+
785
+ const trimmed = schema.trim();
786
+
787
+ // Match patterns like: {text: string}, {"text": "string"}, {response: string}, etc.
788
+ // These are simple wrappers that just need a single text field
789
+ const simplePatterns = [
790
+ /^\{\s*["']?(\w+)["']?\s*:\s*["']?string["']?\s*\}$/i,
791
+ /^\{\s*["']?type["']?\s*:\s*["']?object["']?\s*,\s*["']?properties["']?\s*:\s*\{\s*["']?(\w+)["']?\s*:\s*\{\s*["']?type["']?\s*:\s*["']?string["']?\s*\}\s*\}\s*\}$/i
792
+ ];
793
+
794
+ for (const pattern of simplePatterns) {
795
+ const match = trimmed.match(pattern);
796
+ if (match) {
797
+ return { fieldName: match[1] };
798
+ }
799
+ }
800
+
801
+ return null;
802
+ }
803
+
804
+ /**
805
+ * Try to auto-wrap plain text for simple wrapper schemas
806
+ * Returns wrapped JSON if successful, null if not applicable
807
+ * @param {string} response - The response to wrap
808
+ * @param {string} schema - The schema string
809
+ * @param {Object} options - Options
810
+ * @param {boolean} [options.debug=false] - Enable debug logging
811
+ * @returns {string|null} - Wrapped JSON string or null
812
+ */
813
+ export function tryAutoWrapForSimpleSchema(response, schema, options = {}) {
814
+ const { debug = false } = options;
815
+
816
+ const wrapperInfo = isSimpleTextWrapperSchema(schema);
817
+ if (!wrapperInfo) {
818
+ if (debug) {
819
+ console.log(`[DEBUG] Auto-wrap: Schema is not a simple text wrapper`);
820
+ }
821
+ return null;
822
+ }
823
+
824
+ // Check if response is already valid JSON
825
+ try {
826
+ JSON.parse(response);
827
+ // Already valid JSON, don't wrap
828
+ if (debug) {
829
+ console.log(`[DEBUG] Auto-wrap: Response is already valid JSON, skipping`);
830
+ }
831
+ return null;
832
+ } catch {
833
+ // Not valid JSON, proceed with wrapping
834
+ }
835
+
836
+ // Wrap the plain text in the schema structure
837
+ const wrapped = JSON.stringify({ [wrapperInfo.fieldName]: response });
838
+
839
+ if (debug) {
840
+ console.log(`[DEBUG] Auto-wrap: Wrapped plain text in {"${wrapperInfo.fieldName}": ...} (${response.length} chars)`);
841
+ }
842
+
843
+ return wrapped;
844
+ }
845
+
774
846
  /**
775
847
  * Create a correction prompt for invalid JSON
776
848
  * @param {string} invalidResponse - The invalid JSON response
@@ -817,9 +889,10 @@ export function createJsonCorrectionPrompt(invalidResponse, schema, errorOrValid
817
889
  const level = Math.min(retryCount, strengthLevels.length - 1);
818
890
  const currentLevel = strengthLevels[level];
819
891
 
892
+ // Include full response - truncating loses context the AI needs to fix the issue
820
893
  let prompt = `${currentLevel.prefix} Your previous response is not valid JSON and cannot be parsed. Here's what you returned:
821
894
 
822
- ${invalidResponse.substring(0, 500)}${invalidResponse.length > 500 ? '...' : ''}
895
+ ${invalidResponse}
823
896
 
824
897
  Error: ${enhancedError}
825
898
 
@@ -42,7 +42,7 @@ Manage tasks for tracking progress during code exploration and problem-solving.
42
42
 
43
43
  Parameters:
44
44
  - action: (required) The action to perform: create, update, complete, delete, list
45
- - tasks: (optional) JSON array for batch operations - alternative to single-task params
45
+ - tasks: (optional) Array of task objects for batch operations. Place raw JSON array directly between tags.
46
46
  - id: (optional) Task ID for single operations (e.g., "task-1")
47
47
  - title: (optional) Task title for create/update
48
48
  - description: (optional) Task description for create/update
@@ -51,6 +51,11 @@ Parameters:
51
51
  - dependencies: (optional) JSON array of task IDs that must be completed first
52
52
  - after: (optional) Task ID to insert the new task after (for ordering). By default, new tasks are appended to the end
53
53
 
54
+ IMPORTANT - JSON Format:
55
+ Place raw JSON arrays directly between tags without quotes or escaping:
56
+ CORRECT: <tasks>[{"title": "Do X"}]</tasks>
57
+ INCORRECT: <tasks>"[{\"title\": \"Do X\"}]"</tasks>
58
+
54
59
  Usage Examples:
55
60
 
56
61
  Creating a single task: