@land-catalyst/batch-data-sdk 1.2.1 → 1.2.2

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.
@@ -26,6 +26,16 @@ export interface SearchCriteriaDomain {
26
26
  * All available SearchCriteria domains with their descriptions
27
27
  */
28
28
  export declare const SEARCH_CRITERIA_DOMAINS: SearchCriteriaDomain[];
29
+ /**
30
+ * Array of all valid SearchCriteria domain names (for autocomplete)
31
+ * Using `as const` preserves literal types for better IDE autocomplete
32
+ */
33
+ export declare const SEARCH_CRITERIA_DOMAIN_NAMES: readonly ["query", "address", "assessment", "building", "lot", "owner", "sale", "tax", "valuation", "listing", "openLien", "foreclosure", "quickList"];
34
+ /**
35
+ * Type representing valid SearchCriteria domain names
36
+ * This union type provides better autocomplete in IDEs
37
+ */
38
+ export type SearchCriteriaDomainName = (typeof SEARCH_CRITERIA_DOMAIN_NAMES)[number];
29
39
  /**
30
40
  * Options for building AI context
31
41
  */
@@ -41,17 +51,51 @@ export interface SearchCriteriaAIContextOptions {
41
51
  */
42
52
  maxExamplesPerField?: number;
43
53
  }
54
+ /**
55
+ * Build domain context documentation for specified domains
56
+ * @param domains Array of domain names to include (e.g., ["address", "building", "assessment"])
57
+ * If undefined or empty array, includes all domains (default)
58
+ * Type-safe: only valid domain names from SEARCH_CRITERIA_DOMAINS are allowed
59
+ * @param options Options for customizing the context (applies to all specified domains)
60
+ * @returns Formatted domain documentation string
61
+ * @example
62
+ * ```typescript
63
+ * // Get context for all domains (default)
64
+ * const allContext = buildSearchCriteriaContext();
65
+ *
66
+ * // Get context for specific domains
67
+ * const context = buildSearchCriteriaContext(["address", "building", "assessment"]);
68
+ *
69
+ * // Get context for all domains with options
70
+ * const allContextWithOptions = buildSearchCriteriaContext(undefined, { maxFieldsPerDomain: 5 });
71
+ *
72
+ * // Get context for specific domains with options
73
+ * const selectiveContext = buildSearchCriteriaContext(["address", "building"], { maxFieldsPerDomain: 5 });
74
+ * ```
75
+ */
76
+ export declare function buildSearchCriteriaContext(domains?: SearchCriteriaDomainName[], options?: SearchCriteriaAIContextOptions): string;
44
77
  /**
45
78
  * Build complete system prompt for AI to generate SearchCriteria from natural language
46
- * @param options Options for customizing the context
79
+ * @param domains Optional domain names to include. If not specified, includes all domains.
80
+ * Only domains that exist in SEARCH_CRITERIA_DOMAINS are allowed
81
+ * @param options Options for customizing the context (applies to all specified domains)
47
82
  * @returns Complete system prompt string
48
83
  * @example
49
84
  * ```typescript
85
+ * // Full context with all domains
50
86
  * const systemPrompt = buildSearchCriteriaSystemPrompt();
51
- * const aiService = createAIService(systemPrompt);
87
+ *
88
+ * // Selective context for specific domains
89
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(["address", "building", "assessment"]);
90
+ *
91
+ * // All domains with options
92
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(undefined, { maxFieldsPerDomain: 5 });
93
+ *
94
+ * // Specific domains with options
95
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(["address", "building"], { maxFieldsPerDomain: 5 });
52
96
  * ```
53
97
  */
54
- export declare function buildSearchCriteriaSystemPrompt(options?: SearchCriteriaAIContextOptions): string;
98
+ export declare function buildSearchCriteriaSystemPrompt(domains?: SearchCriteriaDomainName[], options?: SearchCriteriaAIContextOptions): string;
55
99
  /**
56
100
  * Get context documentation for a specific domain
57
101
  * @param domainName The domain name (e.g., "address", "building", "assessment")
@@ -6,7 +6,8 @@
6
6
  * This includes all domain documentation, filter types, examples, and rules.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SEARCH_CRITERIA_DOMAINS = void 0;
9
+ exports.SEARCH_CRITERIA_DOMAIN_NAMES = exports.SEARCH_CRITERIA_DOMAINS = void 0;
10
+ exports.buildSearchCriteriaContext = buildSearchCriteriaContext;
10
11
  exports.buildSearchCriteriaSystemPrompt = buildSearchCriteriaSystemPrompt;
11
12
  exports.getDomainContext = getDomainContext;
12
13
  exports.buildSearchCriteriaUserPrompt = buildSearchCriteriaUserPrompt;
@@ -80,20 +81,84 @@ exports.SEARCH_CRITERIA_DOMAINS = [
80
81
  description: "Pre-defined quick filters (owner-occupied, vacant, absentee-owner, high-equity, low-equity, free-and-clear, active-listing, recently-sold, preforeclosure, tax-default, etc.). Can be negated with 'not-' prefix.",
81
82
  },
82
83
  ];
84
+ /**
85
+ * Array of all valid SearchCriteria domain names (for autocomplete)
86
+ * Using `as const` preserves literal types for better IDE autocomplete
87
+ */
88
+ exports.SEARCH_CRITERIA_DOMAIN_NAMES = [
89
+ "query",
90
+ "address",
91
+ "assessment",
92
+ "building",
93
+ "lot",
94
+ "owner",
95
+ "sale",
96
+ "tax",
97
+ "valuation",
98
+ "listing",
99
+ "openLien",
100
+ "foreclosure",
101
+ "quickList",
102
+ ];
103
+ /**
104
+ * Build domain context documentation for specified domains
105
+ * @param domains Array of domain names to include (e.g., ["address", "building", "assessment"])
106
+ * If undefined or empty array, includes all domains (default)
107
+ * Type-safe: only valid domain names from SEARCH_CRITERIA_DOMAINS are allowed
108
+ * @param options Options for customizing the context (applies to all specified domains)
109
+ * @returns Formatted domain documentation string
110
+ * @example
111
+ * ```typescript
112
+ * // Get context for all domains (default)
113
+ * const allContext = buildSearchCriteriaContext();
114
+ *
115
+ * // Get context for specific domains
116
+ * const context = buildSearchCriteriaContext(["address", "building", "assessment"]);
117
+ *
118
+ * // Get context for all domains with options
119
+ * const allContextWithOptions = buildSearchCriteriaContext(undefined, { maxFieldsPerDomain: 5 });
120
+ *
121
+ * // Get context for specific domains with options
122
+ * const selectiveContext = buildSearchCriteriaContext(["address", "building"], { maxFieldsPerDomain: 5 });
123
+ * ```
124
+ */
125
+ function buildSearchCriteriaContext(domains, options) {
126
+ // Default to all domains if undefined or empty array
127
+ const selectedDomains = !domains || domains.length === 0
128
+ ? exports.SEARCH_CRITERIA_DOMAINS.map((d) => d.name)
129
+ : domains;
130
+ // Validate that all specified domains exist
131
+ const validDomainNames = new Set(exports.SEARCH_CRITERIA_DOMAINS.map((d) => d.name));
132
+ const invalidDomains = selectedDomains.filter((d) => !validDomainNames.has(d));
133
+ if (invalidDomains.length > 0) {
134
+ throw new Error(`Invalid domain(s): ${invalidDomains.join(", ")}. Valid domains are: ${Array.from(validDomainNames).join(", ")}`);
135
+ }
136
+ return buildDomainDocumentation(selectedDomains, options || {});
137
+ }
83
138
  /**
84
139
  * Build complete system prompt for AI to generate SearchCriteria from natural language
85
- * @param options Options for customizing the context
140
+ * @param domains Optional domain names to include. If not specified, includes all domains.
141
+ * Only domains that exist in SEARCH_CRITERIA_DOMAINS are allowed
142
+ * @param options Options for customizing the context (applies to all specified domains)
86
143
  * @returns Complete system prompt string
87
144
  * @example
88
145
  * ```typescript
146
+ * // Full context with all domains
89
147
  * const systemPrompt = buildSearchCriteriaSystemPrompt();
90
- * const aiService = createAIService(systemPrompt);
148
+ *
149
+ * // Selective context for specific domains
150
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(["address", "building", "assessment"]);
151
+ *
152
+ * // All domains with options
153
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(undefined, { maxFieldsPerDomain: 5 });
154
+ *
155
+ * // Specific domains with options
156
+ * const systemPrompt = buildSearchCriteriaSystemPrompt(["address", "building"], { maxFieldsPerDomain: 5 });
91
157
  * ```
92
158
  */
93
- function buildSearchCriteriaSystemPrompt(options = {}) {
94
- const { maxFieldsPerDomain, maxExamplesPerField } = options;
95
- // Build domain documentation
96
- const domainDocs = buildDomainDocumentation(maxFieldsPerDomain, maxExamplesPerField);
159
+ function buildSearchCriteriaSystemPrompt(domains, options) {
160
+ // Build domain documentation using the unified function
161
+ const domainDocs = buildSearchCriteriaContext(domains, options);
97
162
  return `You are an expert at creating property search criteria for real estate professionals. Your task is to convert natural language requests into structured BatchData.io search criteria.
98
163
 
99
164
  ${domainDocs}
@@ -182,10 +247,21 @@ function getDomainContext(domainName, options = {}) {
182
247
  return doc;
183
248
  }
184
249
  /**
185
- * Build domain documentation string for all domains
250
+ * Build domain documentation string for specified domains
251
+ * @param domainNames Array of domain names to include
252
+ * @param options Options for customizing the context
186
253
  */
187
- function buildDomainDocumentation(maxFieldsPerDomain, maxExamplesPerField) {
188
- const domains = exports.SEARCH_CRITERIA_DOMAINS.map((domain) => ({
254
+ function buildDomainDocumentation(domainNames, options = {}) {
255
+ const { maxFieldsPerDomain, maxExamplesPerField } = options;
256
+ // Filter domains to only include specified ones
257
+ const selectedDomains = exports.SEARCH_CRITERIA_DOMAINS.filter((domain) => domainNames.includes(domain.name));
258
+ // Ensure query is always first if included
259
+ const queryDomain = selectedDomains.find((d) => d.name === "query");
260
+ const otherDomains = selectedDomains.filter((d) => d.name !== "query");
261
+ const orderedDomains = queryDomain
262
+ ? [queryDomain, ...otherDomains]
263
+ : otherDomains;
264
+ const domains = orderedDomains.map((domain) => ({
189
265
  ...domain,
190
266
  fields: [],
191
267
  }));
@@ -211,10 +287,20 @@ function buildDomainDocumentation(maxFieldsPerDomain, maxExamplesPerField) {
211
287
  }
212
288
  }
213
289
  // Build the documentation string
214
- let doc = "REQUIRED:\n";
215
- doc += `- query: ${domains[0].description}\n\n`;
216
- doc += "OPTIONAL DOMAINS:\n";
217
- for (const domain of domains.slice(1)) {
290
+ let doc = "";
291
+ const queryDomainItem = domains.find((d) => d.name === "query");
292
+ const optionalDomains = domains.filter((d) => d.name !== "query");
293
+ if (queryDomainItem) {
294
+ doc += "REQUIRED:\n";
295
+ doc += `- query: ${queryDomainItem.description}\n`;
296
+ if (optionalDomains.length > 0) {
297
+ doc += "\nOPTIONAL DOMAINS:\n";
298
+ }
299
+ }
300
+ else if (optionalDomains.length > 0) {
301
+ doc += "OPTIONAL DOMAINS:\n";
302
+ }
303
+ for (const domain of optionalDomains) {
218
304
  doc += `\n- ${domain.name}: ${domain.description}`;
219
305
  if (domain.fields.length > 0) {
220
306
  doc += "\n Available fields:\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@land-catalyst/batch-data-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript SDK for BatchData.io Property API - Types, Builders, and Utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",