@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.mjs CHANGED
@@ -780,6 +780,65 @@ var AgentResource = class {
780
780
  ...options
781
781
  });
782
782
  }
783
+ /**
784
+ * Generate a JSON Schema from a natural language prompt
785
+ *
786
+ * This is useful for building extraction schemas without manual JSON writing.
787
+ * The generated schema can be used with the main agent.create() method.
788
+ *
789
+ * @param options - Schema generation options
790
+ * @returns Generated schema with refined prompt and confidence score
791
+ *
792
+ * @example Basic usage:
793
+ * ```ts
794
+ * const result = await client.agent.generateSchema({
795
+ * prompt: "Find the best student deals on Coursera for marketing courses"
796
+ * });
797
+ *
798
+ * console.log(result.schema);
799
+ * // { type: "object", properties: { courses: { ... } } }
800
+ *
801
+ * console.log(result.refinedPrompt);
802
+ * // "Extract student offers for marketing courses..."
803
+ *
804
+ * // Use the generated schema with an agent
805
+ * const job = await client.agent.create({
806
+ * url: "https://coursera.org",
807
+ * prompt: result.refinedPrompt,
808
+ * schema: result.schema
809
+ * });
810
+ * ```
811
+ *
812
+ * @example With context from conversation:
813
+ * ```ts
814
+ * const result = await client.agent.generateSchema({
815
+ * prompt: "Find student deals on online courses",
816
+ * context: {
817
+ * domains: ["marketing", "web development"],
818
+ * dataTypes: ["free courses", "discounts"],
819
+ * format: "json"
820
+ * }
821
+ * });
822
+ *
823
+ * if (result.confidence < 0.7 && result.suggestedQuestions) {
824
+ * // Ask user for clarification
825
+ * console.log("Please clarify:", result.suggestedQuestions);
826
+ * }
827
+ * ```
828
+ */
829
+ async generateSchema(options) {
830
+ const body = {
831
+ prompt: options.prompt,
832
+ context: options.context,
833
+ model: options.model ?? "openai"
834
+ };
835
+ const result = await post(
836
+ this.ctx,
837
+ "/v1/agent/schema",
838
+ body
839
+ );
840
+ return result.data;
841
+ }
783
842
  };
784
843
 
785
844
  // src/resources/crawl.ts