@chat-ads/chatads-sdk 0.1.12 → 0.1.14
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/README.md +9 -0
- package/dist/client.js +4 -10
- package/dist/index.d.ts +1 -1
- package/dist/models.d.ts +24 -10
- package/dist/models.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,15 @@ const result = await client.analyzeMessage("Need scheduling ideas", {
|
|
|
44
44
|
});
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
### Image search
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const result = await client.analyze({
|
|
51
|
+
message: "https://example.com/product-image.jpg",
|
|
52
|
+
input_type: "image_url",
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
47
56
|
- Reserved payload keys (like `message`, `country`, etc.) cannot be overwritten inside `extraFields`; the client throws if it detects a collision.
|
|
48
57
|
- Pass `raiseOnFailure: true` to throw `ChatAdsAPIError` when the API returns an error with HTTP 200 responses.
|
|
49
58
|
- Retries honor `Retry-After` headers and exponential backoff (`maxRetries` + `retryBackoffFactorMs`).
|
package/dist/client.js
CHANGED
|
@@ -4,14 +4,6 @@ const DEFAULT_ENDPOINT = "/v1/chatads/messages";
|
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 10000;
|
|
5
5
|
const DEFAULT_BACKOFF_FACTOR = 500; // ms
|
|
6
6
|
const DEFAULT_RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
7
|
-
/**
|
|
8
|
-
* Field aliases for normalizing optional field names.
|
|
9
|
-
* Only includes the 3 optional fields from the OpenAPI spec.
|
|
10
|
-
*/
|
|
11
|
-
const FIELD_ALIASES = {
|
|
12
|
-
fillpriority: "quality",
|
|
13
|
-
quality: "quality",
|
|
14
|
-
};
|
|
15
7
|
export class ChatAdsClient {
|
|
16
8
|
constructor(options) {
|
|
17
9
|
if (!options?.apiKey) {
|
|
@@ -167,8 +159,7 @@ function normalizeOptionalFields(data) {
|
|
|
167
159
|
if (key === "extraFields") {
|
|
168
160
|
continue;
|
|
169
161
|
}
|
|
170
|
-
|
|
171
|
-
normalized[aliasKey] = value;
|
|
162
|
+
normalized[key] = value;
|
|
172
163
|
}
|
|
173
164
|
return normalized;
|
|
174
165
|
}
|
|
@@ -179,14 +170,17 @@ async function parseResponse(response) {
|
|
|
179
170
|
// Normalize null/undefined to empty defaults so devs don't need null checks
|
|
180
171
|
const data = raw.data ?? { offers: [], requested: 0, returned: 0 };
|
|
181
172
|
return {
|
|
173
|
+
...raw,
|
|
182
174
|
data: {
|
|
183
175
|
status: data.status,
|
|
184
176
|
offers: data.offers ?? [],
|
|
185
177
|
requested: data.requested ?? 0,
|
|
186
178
|
returned: data.returned ?? 0,
|
|
179
|
+
billed: data.billed ?? false,
|
|
187
180
|
extraction_source: data.extraction_source,
|
|
188
181
|
extraction_debug: data.extraction_debug,
|
|
189
182
|
resolution_debug: data.resolution_debug,
|
|
183
|
+
input_type: data.input_type,
|
|
190
184
|
},
|
|
191
185
|
error: raw.error,
|
|
192
186
|
meta: raw.meta ?? { request_id: "unknown" },
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ChatAdsClient } from "./client.js";
|
|
2
2
|
export { ChatAdsAPIError, ChatAdsSDKError } from "./errors.js";
|
|
3
3
|
export type { ChatAdsClientOptions, AnalyzeOptions, AnalyzeMessageOptions, } from "./client.js";
|
|
4
|
-
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields,
|
|
4
|
+
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields, ResponseStatus, } from "./models.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ExtractionMode = "none" | "fast" | "standard";
|
|
2
|
+
export type ResolutionMode = "none" | "fast" | "standard";
|
|
2
3
|
/** Top-level response status indicating the outcome of the request */
|
|
3
|
-
export type ResponseStatus = "filled" | "partial_fill" | "
|
|
4
|
+
export type ResponseStatus = "filled" | "partial_fill" | "no_offer" | "message_too_short" | "message_too_long" | "country_not_allowed" | "blocked_keyword" | "language_not_allowed" | "ip_country_not_allowed";
|
|
4
5
|
/**
|
|
5
6
|
* Optional fields for ChatAds API requests.
|
|
6
|
-
* Only these 3 optional fields are supported (plus required `message`).
|
|
7
7
|
*/
|
|
8
8
|
export type FunctionItemOptionalFields = {
|
|
9
9
|
/** Client IP address for geo-detection (max 45 characters) */
|
|
10
10
|
ip?: string;
|
|
11
11
|
/** ISO 3166-1 alpha-2 country code for geo-targeting */
|
|
12
12
|
country?: string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** Content type of the input message. Default: "text" */
|
|
14
|
+
input_type?: "text" | "image_url" | "image_file";
|
|
15
|
+
/** Extraction control: "none" (bring your own product), "fast" (NLP only), "standard" (default). Default: "standard" */
|
|
16
|
+
extraction_mode?: ExtractionMode;
|
|
17
|
+
/** Resolution control: "none" (extraction only), "fast" (vector only), "standard" (default). Default: "standard" */
|
|
18
|
+
resolution_mode?: ResolutionMode;
|
|
19
|
+
/** Filter image search results by title keyword (image input_type only) */
|
|
20
|
+
image_title_filter?: string;
|
|
15
21
|
};
|
|
16
22
|
export type FunctionItemPayload = {
|
|
17
23
|
message: string;
|
|
@@ -29,10 +35,12 @@ export interface Product {
|
|
|
29
35
|
stars?: number;
|
|
30
36
|
/** Number of product reviews */
|
|
31
37
|
reviews?: number;
|
|
38
|
+
/** Product image URL (image input_type only) */
|
|
39
|
+
image?: string;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Single affiliate offer returned by the API.
|
|
35
|
-
*
|
|
43
|
+
* URL is populated for resolved offers but may be empty in extraction-only mode (resolution_mode=none).
|
|
36
44
|
*/
|
|
37
45
|
export interface Offer {
|
|
38
46
|
/** Text to use for the affiliate link */
|
|
@@ -43,12 +51,14 @@ export interface Offer {
|
|
|
43
51
|
confidence_score?: number | null;
|
|
44
52
|
/** Confidence level classification (verbose mode only) */
|
|
45
53
|
confidence_level?: string;
|
|
46
|
-
/** Affiliate URL
|
|
47
|
-
url
|
|
54
|
+
/** Affiliate URL — empty when resolution_mode=none */
|
|
55
|
+
url?: string;
|
|
48
56
|
/** Source of the URL resolution (e.g., amazon, serper, vector) (verbose mode only) */
|
|
49
57
|
resolution_source?: string;
|
|
50
58
|
/** Product metadata from resolution */
|
|
51
59
|
product?: Product;
|
|
60
|
+
/** Source retailer name (image input_type only) */
|
|
61
|
+
offer_source?: string;
|
|
52
62
|
}
|
|
53
63
|
/**
|
|
54
64
|
* Response data containing affiliate offers.
|
|
@@ -56,18 +66,22 @@ export interface Offer {
|
|
|
56
66
|
export interface AnalyzeData {
|
|
57
67
|
/** Status of the request - single source of truth for outcome */
|
|
58
68
|
status: ResponseStatus;
|
|
59
|
-
/** Array of affiliate offers (
|
|
69
|
+
/** Array of affiliate offers (URL may be absent in extraction-only mode, never null) */
|
|
60
70
|
offers: Offer[];
|
|
61
71
|
/** Number of offers requested */
|
|
62
72
|
requested: number;
|
|
63
73
|
/** Number of offers returned (equals len(Offers)) */
|
|
64
74
|
returned: number;
|
|
75
|
+
/** Whether this request was billed */
|
|
76
|
+
billed: boolean;
|
|
65
77
|
/** Extraction source ("nlp", "groq_vector", "groq_resolved") (verbose mode only) */
|
|
66
78
|
extraction_source?: string;
|
|
67
79
|
/** Extraction debug information (verbose mode only) */
|
|
68
80
|
extraction_debug?: unknown[];
|
|
69
81
|
/** Resolution debug information (verbose mode only) */
|
|
70
82
|
resolution_debug?: unknown[];
|
|
83
|
+
/** Request input type (verbose mode only) */
|
|
84
|
+
input_type?: string;
|
|
71
85
|
}
|
|
72
86
|
export interface ChatAdsError {
|
|
73
87
|
code: string;
|
|
@@ -99,6 +113,6 @@ export interface ChatAdsResponseEnvelope {
|
|
|
99
113
|
}
|
|
100
114
|
/**
|
|
101
115
|
* Reserved payload keys that cannot be used in extraFields.
|
|
102
|
-
* These are the
|
|
116
|
+
* These are the allowed request fields per the OpenAPI spec.
|
|
103
117
|
*/
|
|
104
118
|
export declare const RESERVED_PAYLOAD_KEYS: ReadonlySet<string>;
|
package/dist/models.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reserved payload keys that cannot be used in extraFields.
|
|
3
|
-
* These are the
|
|
3
|
+
* These are the allowed request fields per the OpenAPI spec.
|
|
4
4
|
*/
|
|
5
5
|
export const RESERVED_PAYLOAD_KEYS = new Set([
|
|
6
6
|
"message",
|
|
7
7
|
"ip",
|
|
8
8
|
"country",
|
|
9
|
-
"
|
|
9
|
+
"input_type",
|
|
10
|
+
"extraction_mode",
|
|
11
|
+
"resolution_mode",
|
|
12
|
+
"image_title_filter",
|
|
10
13
|
]);
|