@dealcrawl/sdk 2.3.0 → 2.4.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.mts CHANGED
@@ -839,6 +839,19 @@ interface AgentStatusResponse extends JobStatusResponse {
839
839
  /** Final result when completed */
840
840
  result?: AgentResultResponse;
841
841
  }
842
+ /** Schema generation response from /v1/agent/schema */
843
+ interface SchemaGenerationResponse {
844
+ /** Generated JSON Schema for data extraction */
845
+ schema: Record<string, unknown>;
846
+ /** Refined prompt optimized for agent execution */
847
+ refinedPrompt: string;
848
+ /** Human-readable description of the schema */
849
+ schemaDescription: string;
850
+ /** Suggested follow-up questions if prompt was ambiguous */
851
+ suggestedQuestions?: string[];
852
+ /** Confidence score (0-1) in the generated schema */
853
+ confidence: number;
854
+ }
842
855
 
843
856
  /**
844
857
  * Polling Utilities
@@ -1418,6 +1431,26 @@ interface AgentOptions {
1418
1431
  headers?: Record<string, string>;
1419
1432
  };
1420
1433
  }
1434
+ /** Context for schema generation from conversation */
1435
+ interface SchemaGenerationContext {
1436
+ /** Specific domains/topics mentioned (e.g., ['marketing', 'web development']) */
1437
+ domains?: string[];
1438
+ /** Types of data to extract (e.g., ['free courses', 'discounts']) */
1439
+ dataTypes?: string[];
1440
+ /** Preferred output format */
1441
+ format?: "json" | "csv" | "table";
1442
+ /** Additional clarifications from user */
1443
+ clarifications?: string[];
1444
+ }
1445
+ /** Options for generating a JSON Schema from natural language */
1446
+ interface SchemaGenerationOptions {
1447
+ /** Natural language description of what data to extract (required, 5-2000 chars) */
1448
+ prompt: string;
1449
+ /** Optional context from conversation to refine the schema */
1450
+ context?: SchemaGenerationContext;
1451
+ /** LLM provider for generation (default: openai) */
1452
+ model?: AgentModel;
1453
+ }
1421
1454
 
1422
1455
  /**
1423
1456
  * Account Resource
@@ -1713,6 +1746,53 @@ declare class AgentResource {
1713
1746
  * ```
1714
1747
  */
1715
1748
  withClaude(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "model">): Promise<AgentJobResponse>;
1749
+ /**
1750
+ * Generate a JSON Schema from a natural language prompt
1751
+ *
1752
+ * This is useful for building extraction schemas without manual JSON writing.
1753
+ * The generated schema can be used with the main agent.create() method.
1754
+ *
1755
+ * @param options - Schema generation options
1756
+ * @returns Generated schema with refined prompt and confidence score
1757
+ *
1758
+ * @example Basic usage:
1759
+ * ```ts
1760
+ * const result = await client.agent.generateSchema({
1761
+ * prompt: "Find the best student deals on Coursera for marketing courses"
1762
+ * });
1763
+ *
1764
+ * console.log(result.schema);
1765
+ * // { type: "object", properties: { courses: { ... } } }
1766
+ *
1767
+ * console.log(result.refinedPrompt);
1768
+ * // "Extract student offers for marketing courses..."
1769
+ *
1770
+ * // Use the generated schema with an agent
1771
+ * const job = await client.agent.create({
1772
+ * url: "https://coursera.org",
1773
+ * prompt: result.refinedPrompt,
1774
+ * schema: result.schema
1775
+ * });
1776
+ * ```
1777
+ *
1778
+ * @example With context from conversation:
1779
+ * ```ts
1780
+ * const result = await client.agent.generateSchema({
1781
+ * prompt: "Find student deals on online courses",
1782
+ * context: {
1783
+ * domains: ["marketing", "web development"],
1784
+ * dataTypes: ["free courses", "discounts"],
1785
+ * format: "json"
1786
+ * }
1787
+ * });
1788
+ *
1789
+ * if (result.confidence < 0.7 && result.suggestedQuestions) {
1790
+ * // Ask user for clarification
1791
+ * console.log("Please clarify:", result.suggestedQuestions);
1792
+ * }
1793
+ * ```
1794
+ */
1795
+ generateSchema(options: SchemaGenerationOptions): Promise<SchemaGenerationResponse>;
1716
1796
  }
1717
1797
 
1718
1798
  /**
package/dist/index.d.ts CHANGED
@@ -839,6 +839,19 @@ interface AgentStatusResponse extends JobStatusResponse {
839
839
  /** Final result when completed */
840
840
  result?: AgentResultResponse;
841
841
  }
842
+ /** Schema generation response from /v1/agent/schema */
843
+ interface SchemaGenerationResponse {
844
+ /** Generated JSON Schema for data extraction */
845
+ schema: Record<string, unknown>;
846
+ /** Refined prompt optimized for agent execution */
847
+ refinedPrompt: string;
848
+ /** Human-readable description of the schema */
849
+ schemaDescription: string;
850
+ /** Suggested follow-up questions if prompt was ambiguous */
851
+ suggestedQuestions?: string[];
852
+ /** Confidence score (0-1) in the generated schema */
853
+ confidence: number;
854
+ }
842
855
 
843
856
  /**
844
857
  * Polling Utilities
@@ -1418,6 +1431,26 @@ interface AgentOptions {
1418
1431
  headers?: Record<string, string>;
1419
1432
  };
1420
1433
  }
1434
+ /** Context for schema generation from conversation */
1435
+ interface SchemaGenerationContext {
1436
+ /** Specific domains/topics mentioned (e.g., ['marketing', 'web development']) */
1437
+ domains?: string[];
1438
+ /** Types of data to extract (e.g., ['free courses', 'discounts']) */
1439
+ dataTypes?: string[];
1440
+ /** Preferred output format */
1441
+ format?: "json" | "csv" | "table";
1442
+ /** Additional clarifications from user */
1443
+ clarifications?: string[];
1444
+ }
1445
+ /** Options for generating a JSON Schema from natural language */
1446
+ interface SchemaGenerationOptions {
1447
+ /** Natural language description of what data to extract (required, 5-2000 chars) */
1448
+ prompt: string;
1449
+ /** Optional context from conversation to refine the schema */
1450
+ context?: SchemaGenerationContext;
1451
+ /** LLM provider for generation (default: openai) */
1452
+ model?: AgentModel;
1453
+ }
1421
1454
 
1422
1455
  /**
1423
1456
  * Account Resource
@@ -1713,6 +1746,53 @@ declare class AgentResource {
1713
1746
  * ```
1714
1747
  */
1715
1748
  withClaude(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "model">): Promise<AgentJobResponse>;
1749
+ /**
1750
+ * Generate a JSON Schema from a natural language prompt
1751
+ *
1752
+ * This is useful for building extraction schemas without manual JSON writing.
1753
+ * The generated schema can be used with the main agent.create() method.
1754
+ *
1755
+ * @param options - Schema generation options
1756
+ * @returns Generated schema with refined prompt and confidence score
1757
+ *
1758
+ * @example Basic usage:
1759
+ * ```ts
1760
+ * const result = await client.agent.generateSchema({
1761
+ * prompt: "Find the best student deals on Coursera for marketing courses"
1762
+ * });
1763
+ *
1764
+ * console.log(result.schema);
1765
+ * // { type: "object", properties: { courses: { ... } } }
1766
+ *
1767
+ * console.log(result.refinedPrompt);
1768
+ * // "Extract student offers for marketing courses..."
1769
+ *
1770
+ * // Use the generated schema with an agent
1771
+ * const job = await client.agent.create({
1772
+ * url: "https://coursera.org",
1773
+ * prompt: result.refinedPrompt,
1774
+ * schema: result.schema
1775
+ * });
1776
+ * ```
1777
+ *
1778
+ * @example With context from conversation:
1779
+ * ```ts
1780
+ * const result = await client.agent.generateSchema({
1781
+ * prompt: "Find student deals on online courses",
1782
+ * context: {
1783
+ * domains: ["marketing", "web development"],
1784
+ * dataTypes: ["free courses", "discounts"],
1785
+ * format: "json"
1786
+ * }
1787
+ * });
1788
+ *
1789
+ * if (result.confidence < 0.7 && result.suggestedQuestions) {
1790
+ * // Ask user for clarification
1791
+ * console.log("Please clarify:", result.suggestedQuestions);
1792
+ * }
1793
+ * ```
1794
+ */
1795
+ generateSchema(options: SchemaGenerationOptions): Promise<SchemaGenerationResponse>;
1716
1796
  }
1717
1797
 
1718
1798
  /**
package/dist/index.js CHANGED
@@ -784,6 +784,65 @@ var AgentResource = class {
784
784
  ...options
785
785
  });
786
786
  }
787
+ /**
788
+ * Generate a JSON Schema from a natural language prompt
789
+ *
790
+ * This is useful for building extraction schemas without manual JSON writing.
791
+ * The generated schema can be used with the main agent.create() method.
792
+ *
793
+ * @param options - Schema generation options
794
+ * @returns Generated schema with refined prompt and confidence score
795
+ *
796
+ * @example Basic usage:
797
+ * ```ts
798
+ * const result = await client.agent.generateSchema({
799
+ * prompt: "Find the best student deals on Coursera for marketing courses"
800
+ * });
801
+ *
802
+ * console.log(result.schema);
803
+ * // { type: "object", properties: { courses: { ... } } }
804
+ *
805
+ * console.log(result.refinedPrompt);
806
+ * // "Extract student offers for marketing courses..."
807
+ *
808
+ * // Use the generated schema with an agent
809
+ * const job = await client.agent.create({
810
+ * url: "https://coursera.org",
811
+ * prompt: result.refinedPrompt,
812
+ * schema: result.schema
813
+ * });
814
+ * ```
815
+ *
816
+ * @example With context from conversation:
817
+ * ```ts
818
+ * const result = await client.agent.generateSchema({
819
+ * prompt: "Find student deals on online courses",
820
+ * context: {
821
+ * domains: ["marketing", "web development"],
822
+ * dataTypes: ["free courses", "discounts"],
823
+ * format: "json"
824
+ * }
825
+ * });
826
+ *
827
+ * if (result.confidence < 0.7 && result.suggestedQuestions) {
828
+ * // Ask user for clarification
829
+ * console.log("Please clarify:", result.suggestedQuestions);
830
+ * }
831
+ * ```
832
+ */
833
+ async generateSchema(options) {
834
+ const body = {
835
+ prompt: options.prompt,
836
+ context: options.context,
837
+ model: options.model ?? "openai"
838
+ };
839
+ const result = await post(
840
+ this.ctx,
841
+ "/v1/agent/schema",
842
+ body
843
+ );
844
+ return result.data;
845
+ }
787
846
  };
788
847
 
789
848
  // src/resources/crawl.ts