@saplingai/sapling-js 1.0.53 → 1.0.54

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.
@@ -24,10 +24,42 @@ export type ConstructorOptions = {
24
24
  timeout?: number,
25
25
  hostname?: string,
26
26
  pathname?: string,
27
- }
27
+ /**
28
+ * When true, every request carries the API's `return_usage: true` flag and
29
+ * every successful JSON-object response additionally reports the usage the
30
+ * request submitted for metering as a top-level `usage` field (see
31
+ * `ApiUsage`). Defaults to false.
32
+ */
33
+ returnUsage?: boolean,
34
+ }
35
+
36
+ /**
37
+ * Usage a request submitted for metering, reported when the client is
38
+ * constructed with `returnUsage: true`. `characters` is the count the request
39
+ * submitted for billing (one count per DISTINCT item of a batch request;
40
+ * 0 for unbilled requests). It is captured before the billing pipeline's
41
+ * dedup window applies, so it is an upper bound on the final charge.
42
+ */
43
+ export type ApiUsage = {
44
+ characters: number;
45
+ }
46
+
47
+ /**
48
+ * A top-level API response with the optional `usage` report attached
49
+ * (present only on successful responses when the client was constructed with
50
+ * `returnUsage: true`). Batch responses carry it on the wrapper object, not
51
+ * on the per-item results.
52
+ */
53
+ export type WithUsage<T> = T & { usage?: ApiUsage };
54
+
55
+ /** English varieties the API accepts for `variety`. `string & {}` keeps the
56
+ * literals as autocomplete hints while still accepting any string. */
57
+ export type EnglishVariety = 'us-variety' | 'gb-variety' | 'au-variety' | 'ca-variety'
58
+ | 's-variety' | 't-variety' | 'null-variety' | (string & {});
28
59
 
29
60
  export type EditOptions = {
30
- variety?: string,
61
+ /** English variety to enforce. The API rejects other values with a 400. */
62
+ variety?: EnglishVariety,
31
63
  autoApply?: boolean,
32
64
  lang?: string,
33
65
  medical?: boolean,
@@ -37,14 +69,112 @@ export type EditOptions = {
37
69
  includeErrorCategories?: boolean,
38
70
  }
39
71
 
72
+ /** One suggested edit. `start`/`end` are offsets into `sentence`; add
73
+ * `sentence_start` to get offsets into the submitted text. */
74
+ export type SpellcheckEdit = {
75
+ /** Opaque edit id; pass to acceptEdit()/rejectEdit(). */
76
+ id: string,
77
+ /** The unedited sentence containing the edit. */
78
+ sentence: string,
79
+ sentence_start: number,
80
+ start: number,
81
+ end: number,
82
+ replacement: string,
83
+ }
84
+
85
+ export type Edit = SpellcheckEdit & {
86
+ /** Error type (see the API's Error Categories page). Omitted when
87
+ * `includeErrorCategories` is false. */
88
+ error_type?: string,
89
+ general_error_type?: string,
90
+ /** Explanation for some edits; advanced edits carry their own (may be null). */
91
+ description?: string | null,
92
+ }
93
+
94
+ /** Why some sentences are missing model edits. */
95
+ export type DegradedReason = 'model_timeout' | 'model_unavailable' | 'model_error';
96
+
97
+ /**
98
+ * Present only on a partial result: a model stage could not process some
99
+ * sentences in time, so those sentences may be missing some or all of their
100
+ * edits. Counts only: the response does not say which sentences, so retry the
101
+ * whole request after a short backoff for a complete result. A total failure
102
+ * is an HTTP 503 with `Retry-After` instead.
103
+ */
104
+ export type Degraded = {
105
+ sentences_degraded: number,
106
+ sentences_total: number,
107
+ reason: DegradedReason,
108
+ }
109
+
110
+ /** A sentence the API skipped without checking. */
111
+ export type IgnoredSentence = {
112
+ sentence: string,
113
+ reason: 'SENTENCE_EXCEEDS_MAX_LENGTH' | 'UNRECOGNIZED_CHARACTER_SET' | 'INVALID_TOKENS_FOUND',
114
+ }
115
+
116
+ export type EditsResponse = {
117
+ /** Sorted by position in the text. */
118
+ edits: Edit[],
119
+ /** The detected language; only when `lang: 'auto'` was sent. */
120
+ lang?: string,
121
+ /** The text with every edit applied; only when `autoApply: true`. Advanced edits
122
+ * are never applied. */
123
+ applied_text?: string,
124
+ /** Set with `applied_text` when the text contains HTML tags, which auto-apply
125
+ * does not account for. */
126
+ warning?: string,
127
+ 'ignored-sentences'?: IgnoredSentence[],
128
+ degraded?: Degraded,
129
+ }
130
+
131
+ export type SpellcheckResponse = {
132
+ edits: SpellcheckEdit[],
133
+ /** The detected language; only when `lang: 'auto'` was sent. */
134
+ lang?: string,
135
+ /** Misspelled word -> ranked candidate corrections; only with `multipleEdits: true`
136
+ * (empty when the neural spellchecker served the request). */
137
+ candidates?: Record<string, string[]>,
138
+ /** Echo of the `userData` option, when sent. */
139
+ user_data?: unknown,
140
+ /** Only when `autoApply: true`. */
141
+ applied_text?: string,
142
+ warning?: string,
143
+ degraded?: Degraded,
144
+ }
145
+
40
146
  export type AIDetectOptions = {
41
147
  /** Include `sentence_scores` (server default true). */
42
148
  sent_scores?: boolean,
43
149
  /** Include `score_string`, an HTML heatmap of the scored text. */
44
150
  score_string?: boolean,
45
- /** Pin a detector model version (e.g. `'20251027'`); omitted = current default. */
151
+ /** Pin a detector model version (e.g. `'20251027'`, or `'ml20261009'` for the multilingual
152
+ * model); omitted = current default, with text detected as `es`/`pt`/`fr`/`de`/`it`/`nl`/`ja`
153
+ * routed to the multilingual model. A pin always wins over that routing and over `lang`. */
46
154
  version?: string,
47
- }
155
+ /** Language of the text: `'en'`, `'es'`, `'pt'`, `'fr'`, `'de'`, `'it'`, `'nl'` or `'ja'`
156
+ * (case-insensitive; region subtags such as `'pt-BR'` are accepted). Picks that language's
157
+ * model instead of relying on detection, which helps with short texts; omit it (or pass
158
+ * `'auto'`) to detect.
159
+ * Other languages are rejected with a 400. Applies to every item of a batch. */
160
+ lang?: string,
161
+ /** Keep no copy of the text: the result is still scored and billed (repeats within the
162
+ * deduplication window are still not billed twice), but it is not written to the shared
163
+ * result cache and usage is logged without the text. Default false; always on for teams with
164
+ * data retention disabled. Applies to every item of a batch. */
165
+ zero_retention?: boolean,
166
+ /** Also save the result as a shareable report and return its link in `report`. A single
167
+ * text only (not a batch). The report is saved to your AI detector history, where you can
168
+ * revoke the link; anyone with the link can view the text and its scores until it is
169
+ * revoked or expires 90 days after creation. Requires your private API key (OAuth access
170
+ * tokens and public API keys get a 400, as does combining it with `zero_retention`). When
171
+ * no report can be made, `report` is null and `report_skip_reason` says why; the request
172
+ * is still scored and billed. */
173
+ create_report?: boolean,
174
+ }
175
+
176
+ /** aidetect() batch options: `create_report` is single-text only. */
177
+ export type AIDetectBatchOptions = Omit<AIDetectOptions, 'create_report'>;
48
178
 
49
179
  export type AIDetectSentenceScore = {
50
180
  sentence: string;
@@ -63,27 +193,109 @@ export type AIDetectLanguage = {
63
193
  confidence: number;
64
194
  }
65
195
 
196
+ /** A run of consecutive sentences scoring >= 0.5. */
197
+ export type AIDetectSegment = {
198
+ /** Offsets into the response `text` (`end` exclusive), in Unicode code points like
199
+ * `AIDetectSentenceScore`. */
200
+ start: number;
201
+ end: number;
202
+ /** Mean score of the run's sentences, weighted by their length. */
203
+ score: number;
204
+ }
205
+
206
+ /** `short_text`: under 500 characters. `list_format`: mostly bullet or numbered lines. */
207
+ export type AIDetectLowConfidenceReason = 'short_text' | 'list_format';
208
+
66
209
  export type AIDetectResponse = {
67
210
  /** 0 (likely human-written) to 1 (likely AI-generated). */
68
211
  score: number;
69
212
  /** Share of the text in sentences scoring >= 0.5 (flags partially
70
213
  * AI-written documents); null when nothing could be scored. */
71
214
  ai_fraction: number | null;
215
+ /** Plain-language summary of `score` and `ai_fraction`: `'ai'` when `ai_fraction` >= 0.8
216
+ * and `score` >= 0.5; otherwise `'mixed'` when `ai_fraction` >= 0.2 or `score` >= 0.5;
217
+ * otherwise `'human'` (with a null `ai_fraction`, `'ai'` or `'human'` by `score` alone).
218
+ * Omitted when the text could not be scored. */
219
+ verdict?: 'human' | 'mixed' | 'ai';
220
+ /** The AI-scored passages, in text order; empty when no sentence scores >= 0.5. Also sent
221
+ * with `sent_scores: false`; omitted when sentence offsets are unavailable. */
222
+ segments?: AIDetectSegment[];
223
+ /** True when the input is of a kind with a higher false-positive rate (see
224
+ * `low_confidence_reasons`), so hedge the result rather than show a bare score. */
225
+ low_confidence: boolean;
226
+ /** Empty when `low_confidence` is false. */
227
+ low_confidence_reasons: AIDetectLowConfidenceReason[];
72
228
  text: string;
73
229
  tokens: string[];
74
230
  token_probs: number[];
75
- /** The pinned `version` when one was requested, otherwise an opaque
76
- * identifier of the default model — log it, don't parse it. */
231
+ /** The pinned `version` when one was requested; `'ml20261009'` when unpinned text was
232
+ * detected as (or `lang` named) `es`/`pt`/`fr`/`de`/`it`/`nl`/`ja` and scored by the
233
+ * multilingual model; otherwise an opaque identifier of the default model — log it, don't
234
+ * parse it. */
77
235
  version: string;
78
236
  /** Present unless `sent_scores: false`. */
79
237
  sentence_scores?: AIDetectSentenceScore[];
80
238
  /** Present when `score_string: true`. */
81
239
  score_string?: string;
82
- /** Advisory detected language; omitted unless detection is high-confidence.
83
- * The detector is trained on English. */
240
+ /** Advisory detected language; omitted unless detection is high-confidence. Always the
241
+ * detected language, even when `lang` was sent, so a mismatch is visible.
242
+ * English plus `es`, `pt`, `fr`, `de`, `it`, `nl` and `ja` (routed to the multilingual
243
+ * model) are supported; other languages are scored by the English model and are less
244
+ * reliable. */
84
245
  language?: AIDetectLanguage;
85
246
  }
86
247
 
248
+ /** The public report link minted by `create_report: true`. */
249
+ export type AIDetectReport = {
250
+ /** AI detector history entry id (the report is listed in your dashboard history). */
251
+ id: string;
252
+ /** Public report link. */
253
+ url: string;
254
+ /** ISO 8601 timestamp. */
255
+ shared_at: string;
256
+ /** ISO 8601 timestamp: when the link stops resolving unless revoked or deleted sooner. */
257
+ expires_at: string;
258
+ }
259
+
260
+ /** Why `report` is null: `nonpersist` (team keeps no data), `disabled` (AI detector history
261
+ * off), `text_not_retained` (history keeps no text), `unconfirmed_email`, `quota` (history
262
+ * full), `unscorable`, `error`. */
263
+ export type AIDetectReportSkipReason = 'nonpersist' | 'disabled' | 'text_not_retained'
264
+ | 'unconfirmed_email' | 'quota' | 'unscorable' | 'error';
265
+
266
+ /** Added to single-text responses only when `create_report: true` was sent. */
267
+ export type AIDetectReportFields = {
268
+ /** null when no report was made (see `report_skip_reason`). */
269
+ report?: AIDetectReport | null;
270
+ /** Present only when `report` is null. */
271
+ report_skip_reason?: AIDetectReportSkipReason;
272
+ }
273
+
274
+ /** fileAidetect() always scores with sentence scores and score_string enabled. */
275
+ export type FileAIDetectResponse = AIDetectResponse
276
+ & Required<Pick<AIDetectResponse, 'sentence_scores' | 'score_string'>>
277
+ & AIDetectReportFields;
278
+
279
+ export type URLAIDetectSource = {
280
+ /** Final URL after redirects. */
281
+ url: string;
282
+ /** The page's og:title, <title> or first <h1> (a linked document's file name); empty
283
+ * when there is none. */
284
+ title: string;
285
+ /** The response's media type, e.g. `'text/html'` or `'application/pdf'`. */
286
+ content_type: string;
287
+ /** Characters scored (and billed). */
288
+ characters: number;
289
+ /** True when the page (2MB of HTML), document (15MB) or text (200,000 characters) was cut
290
+ * off, so only a prefix was scored. */
291
+ truncated: boolean;
292
+ }
293
+
294
+ /** urlAidetect(): the aidetect() response plus where the scored text came from. */
295
+ export type URLAIDetectResponse = AIDetectResponse & AIDetectReportFields & {
296
+ source: URLAIDetectSource;
297
+ }
298
+
87
299
  export type AIDetectBatchResponse = {
88
300
  results: AIDetectResponse[];
89
301
  }
@@ -183,6 +395,85 @@ export type AccountStatusResponse = {
183
395
  };
184
396
  }
185
397
 
398
+ export type ReportingWindowOptions = {
399
+ /** Days before today the window starts (non-negative integer). */
400
+ start_days_back?: number,
401
+ /** Days before today the window ends (non-negative integer). Defaults to 0. */
402
+ end_days_back?: number,
403
+ }
404
+
405
+ export type ApiUsageKeySummary = {
406
+ /** Masked id, `****<last4>-<hash8>`; the raw key is never returned. */
407
+ api_key: string;
408
+ tag: string;
409
+ /** Characters in the window. */
410
+ characters: number;
411
+ /** Monthly character limit; -1 for none. */
412
+ monthly_limit: number | null;
413
+ /** Characters this calendar month. */
414
+ monthly_usage: number;
415
+ /** null when there is no limit. */
416
+ remaining_quota: number | null;
417
+ quota_exceeded: boolean;
418
+ }
419
+
420
+ export type ApiUsageResponse = {
421
+ /** Inclusive ISO dates of the resolved window. */
422
+ start_date: string;
423
+ end_date: string;
424
+ total_characters: number;
425
+ /** At list prices, per (endpoint, month). */
426
+ total_cost_usd: number;
427
+ currency: string;
428
+ /** Keyed by masked key id. */
429
+ by_api_key: Record<string, ApiUsageKeySummary>;
430
+ /** Keyed by endpoint name, e.g. `EDIT`. */
431
+ by_endpoint: Record<string, { characters: number; cost_usd: number }>;
432
+ /** Masked key id → `YYYY-MM-DD` → characters. */
433
+ daily_usage: Record<string, Record<string, number>>;
434
+ /** Masked key id → `YYYY-MM` → characters. */
435
+ monthly_usage: Record<string, Record<string, number>>;
436
+ /** ISO timestamp of the latest usage row in the window, or null. */
437
+ last_updated: string | null;
438
+ /** Omitted for team-scoped keys. Same object as accountStatus()'s `credits`. */
439
+ credit_balance_data?: AccountCreditSummary;
440
+ }
441
+
442
+ export type ApiEndpointUsageInterval = 'Daily' | 'Weekly' | 'Monthly';
443
+
444
+ export type ApiEndpointUsageOptions = ReportingWindowOptions & {
445
+ /** Defaults to 'Daily'. */
446
+ interval?: ApiEndpointUsageInterval,
447
+ }
448
+
449
+ export type ApiEndpointUsageResponse = {
450
+ /** Endpoint name → bucket start (days before today, as a string key) → characters. */
451
+ data: Record<string, Record<string, number>>;
452
+ last_updated: string | null;
453
+ }
454
+
455
+ export type ApiQuotaUsageResponse = {
456
+ /** Monthly character limit; -1 for none. */
457
+ quota: number;
458
+ /** Characters in the window. */
459
+ usage: number;
460
+ /** Suggestions accepted / ignored via acceptEdit()/rejectEdit() since the first of the month. */
461
+ accepts: number;
462
+ ignores: number;
463
+ /** Unix epoch seconds. */
464
+ last_updated: number;
465
+ }
466
+
467
+ export type ApiUserActivityResponse = {
468
+ edits_shown: number;
469
+ edits_accepted: number;
470
+ edits_ignored: number;
471
+ active_users: {
472
+ logged_in: number;
473
+ anonymous: number;
474
+ };
475
+ }
476
+
186
477
  export type SimplifyReadingLevel = 'plain' | 'elementary' | 'middle_school' | 'high_school';
187
478
 
188
479
  export type SimplifyOptions = {
@@ -215,6 +506,43 @@ export type LangdetectOptions = {
215
506
  segments?: boolean,
216
507
  }
217
508
 
509
+ export type LangdetectCandidate = {
510
+ lang: string;
511
+ conf: number;
512
+ name: string | null;
513
+ }
514
+
515
+ export type LangdetectResult = {
516
+ /** ISO 639-1 code of the most likely language. */
517
+ lang: string;
518
+ conf: number;
519
+ name: string | null;
520
+ /** The recommended trust bar: true only when the confidence is high and the text has enough
521
+ * letters. Short inputs like "OK" or "Hola" are never reliable. */
522
+ reliable: boolean;
523
+ /** Dominant writing system as an ISO 15924 code (`Latn`, `Cyrl`, `Arab`, `Hani`, `Jpan`,
524
+ * `Hang`, ...). `Zzzz` when the letters are in an unmapped script; null when the text has no
525
+ * letters. */
526
+ script: string | null;
527
+ /** The top_k most likely languages, best first. */
528
+ candidates: LangdetectCandidate[];
529
+ }
530
+
531
+ export type LangdetectSegment = LangdetectResult & {
532
+ start: number;
533
+ end: number;
534
+ text: string;
535
+ }
536
+
537
+ export type LangdetectResponse = LangdetectResult & {
538
+ /** Present only when the request sent segments: true. */
539
+ segments?: LangdetectSegment[];
540
+ }
541
+
542
+ export type LangdetectBatchResponse = {
543
+ results: LangdetectResponse[];
544
+ }
545
+
218
546
  export type ClassifyLabel = string | { name: string; description?: string };
219
547
 
220
548
  export type ClassifyOptions = {
@@ -371,6 +699,35 @@ export type NERBatchResponse = {
371
699
  results: NERResponse[];
372
700
  }
373
701
 
702
+ export type InclusiveCategory = 'gender' | 'race_ethnicity' | 'disability' | 'age' |
703
+ 'lgbtq' | 'religion' | 'socioeconomic' | 'appearance';
704
+
705
+ export type InclusiveSeverity = 'low' | 'medium' | 'high';
706
+
707
+ export type InclusiveOptions = {
708
+ categories?: InclusiveCategory[],
709
+ }
710
+
711
+ export type InclusiveIssue = {
712
+ category: InclusiveCategory;
713
+ severity: InclusiveSeverity;
714
+ text: string;
715
+ start: number | null;
716
+ end: number | null;
717
+ note: string;
718
+ suggestion: string;
719
+ }
720
+
721
+ export type InclusiveResponse = {
722
+ issues: InclusiveIssue[];
723
+ categories: InclusiveCategory[];
724
+ inclusive: boolean;
725
+ }
726
+
727
+ export type InclusiveBatchResponse = {
728
+ results: InclusiveResponse[];
729
+ }
730
+
374
731
  export type SafetyCategory = 'toxicity' | 'profanity' | 'harassment' | 'hate_speech' |
375
732
  'self_harm' | 'sexual' | 'violence';
376
733
 
@@ -404,7 +761,9 @@ export type SpellcheckOptions = {
404
761
  multipleEdits?: boolean,
405
762
  lang?: string,
406
763
  autoApply?: boolean,
407
- variety?: string,
764
+ /** English variety to enforce. The API rejects other values with a 400. */
765
+ variety?: EnglishVariety,
766
+ /** Arbitrary JSON echoed back as `user_data` on the response. */
408
767
  userData?: any,
409
768
  }
410
769
 
@@ -441,6 +800,36 @@ export type ExtractBatchResponse = {
441
800
  results: ExtractResponse[];
442
801
  }
443
802
 
803
+ /** A document for fileAidetect()/fileExtract()/fileSummarize(): a Blob/File, or the file's bytes (Buffer,
804
+ * Uint8Array, ArrayBuffer). The API picks the format by file extension (.pdf, .docx, .pptx,
805
+ * .odt, .txt, .md, .html, .htm; up to 30MB), so bytes need `options.filename`. */
806
+ export type UploadFile = Blob | ArrayBuffer | ArrayBufferView;
807
+
808
+ export type FileUploadOptions = {
809
+ /** Required unless `file` is a File (whose own name is used otherwise), e.g. 'report.pdf'. */
810
+ filename?: string,
811
+ }
812
+
813
+ export type FileExtractOptions = ExtractOptions & FileUploadOptions;
814
+
815
+ export type FileAIDetectOptions = FileUploadOptions & Pick<AIDetectOptions, 'zero_retention' | 'create_report'>;
816
+
817
+ export type FileExtractDocument = {
818
+ /** The extension the document was read as, e.g. 'pdf'. */
819
+ file_type: string,
820
+ /** Characters of text extracted from the file. */
821
+ characters: number,
822
+ /** Characters read for extraction (at most 10,000) and billed. */
823
+ characters_used: number,
824
+ /** True when the text was cut to its first 10,000 characters; fields stated only
825
+ * later in the document are reported missing. */
826
+ truncated: boolean,
827
+ }
828
+
829
+ export type FileExtractResponse = ExtractResponse & {
830
+ document: FileExtractDocument,
831
+ }
832
+
444
833
  export type TranslateOptions = {
445
834
  source_lang?: string,
446
835
  formality?: 'formal' | 'informal',
@@ -474,6 +863,24 @@ export type SummarizeBatchResponse = {
474
863
  results: SummarizeResponse[];
475
864
  }
476
865
 
866
+ export type FileSummarizeOptions = SummarizeOptions & FileUploadOptions;
867
+
868
+ export type FileSummarizeDocument = {
869
+ /** The extension the document was read as, e.g. 'pdf'. */
870
+ file_type: string,
871
+ /** Characters of text extracted from the file. */
872
+ characters: number,
873
+ /** Characters summarized (at most 20,000) and billed. */
874
+ characters_used: number,
875
+ /** True when the text was cut to its first 20,000 characters; the summary covers
876
+ * only that part of the document. */
877
+ truncated: boolean,
878
+ }
879
+
880
+ export type FileSummarizeResponse = SummarizeResponse & {
881
+ document: FileSummarizeDocument,
882
+ }
883
+
477
884
  export type RephraseMapping =
478
885
  'paraphrase' | 'passive_to_active' | 'active_to_passive' | 'informal_to_formal' |
479
886
  'formal_to_informal' | 'sentence_split' | 'reword' | 'generate_title' | 'generate_acronym' |
@@ -513,6 +920,31 @@ export type RephraseResponse = {
513
920
  results: RephraseResult[],
514
921
  }
515
922
 
923
+ export type CompleteResponse = {
924
+ /** The predicted continuation of `query`. */
925
+ output: string,
926
+ /** The part of the sent query the prediction continues: the API keeps only the text
927
+ * after the last run of three spaces. */
928
+ query: string,
929
+ /** Pass to acceptComplete() as `completeUUID`, with this `query` and `output`. */
930
+ hash: string,
931
+ }
932
+
933
+ export type AcceptCompleteResponse = {
934
+ result: 'success',
935
+ }
936
+
937
+ /** [probability, tone name, emoji] triples, e.g. [1.0, 'neutral', '😐']. */
938
+ export type ToneScores = Array<[number, string, string]>;
939
+
940
+ export type ToneResponse = {
941
+ /** Up to 3 tones for the whole text, most likely first; the probabilities sum to 1. */
942
+ overall: ToneScores,
943
+ /** One entry per sentence, aligned with `sents`. */
944
+ results: ToneScores[],
945
+ sents: string[],
946
+ }
947
+
516
948
  export type SentimentLabel = 'POSITIVE' | 'NEUTRAL' | 'NEGATIVE';
517
949
 
518
950
  /** [probability, label] pairs, most likely first. */
@@ -573,6 +1005,54 @@ export type AddDictionaryEntryOptions = {
573
1005
  case_sensitive?: boolean,
574
1006
  }
575
1007
 
1008
+ export type CustomMapping = {
1009
+ id: string,
1010
+ /** The text to match; `^` / `$` anchor to a sentence's start / end, `#` matches a number. */
1011
+ entry: string,
1012
+ /** The replacement suggested; a `#` substitutes the matched number back in. */
1013
+ mapping: string,
1014
+ /** Shown with the suggestion; empty string or null (older rules) when none was set. */
1015
+ description: string | null,
1016
+ case_sensitive: boolean,
1017
+ /** RFC 1123 timestamp, e.g. "Wed, 07 Oct 2020 21:15:47 GMT". */
1018
+ created_at: string,
1019
+ updated_at: string,
1020
+ }
1021
+
1022
+ export type CustomMappingsResponse = {
1023
+ /** Sorted by entry. */
1024
+ custom_mappings: CustomMapping[],
1025
+ }
1026
+
1027
+ export type AddCustomMappingOptions = {
1028
+ /** Shown to the end user with the suggestion; a mapping with a description cannot be ignored. */
1029
+ description?: string,
1030
+ /** Defaults to true. */
1031
+ case_sensitive?: boolean,
1032
+ }
1033
+
1034
+ export type CustomFilter = {
1035
+ id: string,
1036
+ /** The original text of the suppressed edits; empty string is a wildcard. */
1037
+ input: string,
1038
+ /** The replacement text of the suppressed edits; empty string is a wildcard. */
1039
+ output: string,
1040
+ case_sensitive: boolean,
1041
+ /** RFC 1123 timestamp, e.g. "Wed, 07 Oct 2020 21:15:47 GMT". */
1042
+ created_at: string,
1043
+ updated_at: string,
1044
+ }
1045
+
1046
+ export type CustomFiltersResponse = {
1047
+ /** Sorted by input. */
1048
+ custom_filters: CustomFilter[],
1049
+ }
1050
+
1051
+ export type AddCustomFilterOptions = {
1052
+ /** Defaults to true. */
1053
+ case_sensitive?: boolean,
1054
+ }
1055
+
576
1056
  export type UserDetails = {
577
1057
  userId?: string,
578
1058
  anonUser?: boolean,
@@ -581,63 +1061,91 @@ export type UserDetails = {
581
1061
  export declare class Client {
582
1062
  constructor(apiKey: string, options?: ConstructorOptions);
583
1063
 
584
- edits(text: string, sessionId?: string, options?: EditOptions, userDetails?: UserDetails): Promise<AxiosResponse>;
1064
+ edits(text: string, sessionId?: string, options?: EditOptions, userDetails?: UserDetails): Promise<AxiosResponse<WithUsage<EditsResponse>>>;
585
1065
  acceptEdit(editUUID: string, sessionId?: string, userId?: string): Promise<AxiosResponse>;
586
1066
  rejectEdit(editUUID: string, sessionId?: string, userId?: string): Promise<AxiosResponse>;
587
1067
 
588
- spellcheck(text: string, sessionId?: string, options?: SpellcheckOptions, userDetails?: UserDetails): Promise<AxiosResponse>;
589
-
590
- complete(query: string, sessionId?: string): Promise<AxiosResponse>;
591
- acceptComplete(completeUUID: string, query: string, completion: string, sessionId?: string): Promise<AxiosResponse>;
592
- tone(text: string): Promise<AxiosResponse>;
593
- rephrase(text: string, options?: RephraseOptions): Promise<AxiosResponse<RephraseResponse>>;
1068
+ spellcheck(text: string, sessionId?: string, options?: SpellcheckOptions, userDetails?: UserDetails): Promise<AxiosResponse<WithUsage<SpellcheckResponse>>>;
1069
+
1070
+ /** `data` is `[]` when no completion is available (the prediction failed or was too
1071
+ * short). Check `Array.isArray(data)` before reading fields. */
1072
+ complete(query: string, sessionId?: string): Promise<AxiosResponse<WithUsage<CompleteResponse> | never[]>>;
1073
+ /** Pass the `hash`, `query` and `output` that complete() returned. A changed `query` or
1074
+ * `completion` gets a 400 ("Arguments do not match hash."). */
1075
+ acceptComplete(completeUUID: string, query: string, completion: string, sessionId?: string): Promise<AxiosResponse<WithUsage<AcceptCompleteResponse>>>;
1076
+ /** `data` is `[]` when the API cannot split the text into sentences. Check
1077
+ * `Array.isArray(data)` before reading fields. */
1078
+ tone(text: string): Promise<AxiosResponse<WithUsage<ToneResponse> | never[]>>;
1079
+ rephrase(text: string, options?: RephraseOptions): Promise<AxiosResponse<WithUsage<RephraseResponse>>>;
594
1080
  /** A text with no sentences (e.g. markup or punctuation only) gets a 204 with an empty
595
1081
  * body, so `data` is `''` then; a text the API cannot split into sentences gets a 200
596
1082
  * with `[]`. Check `Array.isArray(data) || !data` before reading fields. */
597
- sentiment(text: string): Promise<AxiosResponse<SentimentResponse | '' | never[]>>;
598
- statistics(text: string, options?: StatisticsOptions): Promise<AxiosResponse<StatisticsResponse>>;
599
- similarTerms(query: string): Promise<AxiosResponse<SimilarTermsResponse>>;
600
- profanity(text: string): Promise<AxiosResponse<ProfanityResponse>>;
1083
+ sentiment(text: string): Promise<AxiosResponse<WithUsage<SentimentResponse> | '' | never[]>>;
1084
+ statistics(text: string, options?: StatisticsOptions): Promise<AxiosResponse<WithUsage<StatisticsResponse>>>;
1085
+ similarTerms(query: string): Promise<AxiosResponse<WithUsage<SimilarTermsResponse>>>;
1086
+ profanity(text: string): Promise<AxiosResponse<WithUsage<ProfanityResponse>>>;
601
1087
  dictionaryEntries(): Promise<AxiosResponse<DictionaryEntry[]>>;
602
- addDictionaryEntry(entry: string, options?: AddDictionaryEntryOptions): Promise<AxiosResponse<DictionaryEntry>>;
1088
+ addDictionaryEntry(entry: string, options?: AddDictionaryEntryOptions): Promise<AxiosResponse<WithUsage<DictionaryEntry>>>;
603
1089
  /** Answers 204 with an empty body. */
604
1090
  deleteDictionaryEntry(entryId: string): Promise<AxiosResponse<''>>;
605
- extract(text: string, fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse>>;
606
- extract(texts: string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractBatchResponse>>;
607
- extract(text: string | string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse | ExtractBatchResponse>>;
608
- translate(text: string, targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse>>;
609
- translate(texts: string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateBatchResponse>>;
610
- translate(text: string | string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse | TranslateBatchResponse>>;
611
- summarize(text: string, options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse>>;
612
- summarize(texts: string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeBatchResponse>>;
613
- summarize(text: string | string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse | SummarizeBatchResponse>>;
614
-
615
- aidetect(text: string, options?: AIDetectOptions): Promise<AxiosResponse<AIDetectResponse>>;
616
- aidetect(texts: string[], options?: AIDetectOptions): Promise<AxiosResponse<AIDetectBatchResponse>>;
617
- aidetect(text: string | string[], options?: AIDetectOptions): Promise<AxiosResponse<AIDetectResponse | AIDetectBatchResponse>>;
618
- styleguide(text: string, rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse>>;
619
- styleguide(texts: string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideBatchResponse>>;
620
- styleguide(text: string | string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse | StyleguideBatchResponse>>;
621
- styleguideRulesets(): Promise<AxiosResponse<StyleguideRulesetsResponse>>;
622
- saveStyleguideRuleset(name: string, rules: StyleguideRule[]): Promise<AxiosResponse<SaveStyleguideRulesetResponse>>;
623
- deleteStyleguideRuleset(name: string): Promise<AxiosResponse<DeleteStyleguideRulesetResponse>>;
624
- simplify(text: string, options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse>>;
625
- simplify(texts: string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyBatchResponse>>;
626
- simplify(text: string | string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse | SimplifyBatchResponse>>;
627
- langdetect(text: string | string[], options?: LangdetectOptions): Promise<AxiosResponse>;
628
- quality(text: string, options?: QualityOptions): Promise<AxiosResponse<QualityResponse>>;
629
- quality(texts: string[], options?: QualityOptions): Promise<AxiosResponse<QualityBatchResponse>>;
630
- quality(text: string | string[], options?: QualityOptions): Promise<AxiosResponse<QualityResponse | QualityBatchResponse>>;
631
- pii(text: string, options?: PIIOptions): Promise<AxiosResponse<PIIResponse>>;
632
- ner(text: string, options?: NEROptions): Promise<AxiosResponse<NERResponse>>;
633
- ner(texts: string[], options?: NEROptions): Promise<AxiosResponse<NERBatchResponse>>;
634
- ner(text: string | string[], options?: NEROptions): Promise<AxiosResponse<NERResponse | NERBatchResponse>>;
635
- safety(text: string, options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse>>;
636
- safety(texts: string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyBatchResponse>>;
637
- safety(text: string | string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse | SafetyBatchResponse>>;
638
- classify(text: string, labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse>>;
639
- classify(texts: string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyBatchResponse>>;
640
- classify(text: string | string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse | ClassifyBatchResponse>>;
641
- seo(text: string, options?: SeoOptions): Promise<AxiosResponse<SeoResponse>>;
1091
+ customMappings(): Promise<AxiosResponse<WithUsage<CustomMappingsResponse>>>;
1092
+ addCustomMapping(entry: string, mapping: string, options?: AddCustomMappingOptions): Promise<AxiosResponse<WithUsage<CustomMapping>>>;
1093
+ /** Answers 204 with an empty body. */
1094
+ deleteCustomMapping(mappingId: string): Promise<AxiosResponse<''>>;
1095
+ customFilters(): Promise<AxiosResponse<WithUsage<CustomFiltersResponse>>>;
1096
+ addCustomFilter(input: string, output: string, options?: AddCustomFilterOptions): Promise<AxiosResponse<WithUsage<CustomFilter>>>;
1097
+ /** Answers 204 with an empty body. */
1098
+ deleteCustomFilter(filterId: string): Promise<AxiosResponse<''>>;
1099
+ extract(text: string, fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractResponse>>>;
1100
+ extract(texts: string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractBatchResponse>>>;
1101
+ extract(text: string | string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractResponse | ExtractBatchResponse>>>;
1102
+ fileExtract(file: UploadFile, fields: ExtractField[], options?: FileExtractOptions): Promise<AxiosResponse<WithUsage<FileExtractResponse>>>;
1103
+ translate(text: string, targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateResponse>>>;
1104
+ translate(texts: string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateBatchResponse>>>;
1105
+ translate(text: string | string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateResponse | TranslateBatchResponse>>>;
1106
+ summarize(text: string, options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeResponse>>>;
1107
+ summarize(texts: string[], options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeBatchResponse>>>;
1108
+ summarize(text: string | string[], options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeResponse | SummarizeBatchResponse>>>;
1109
+ fileSummarize(file: UploadFile, options?: FileSummarizeOptions): Promise<AxiosResponse<WithUsage<FileSummarizeResponse>>>;
1110
+
1111
+ aidetect(text: string, options?: AIDetectOptions): Promise<AxiosResponse<WithUsage<AIDetectResponse & AIDetectReportFields>>>;
1112
+ aidetect(texts: string[], options?: AIDetectBatchOptions): Promise<AxiosResponse<WithUsage<AIDetectBatchResponse>>>;
1113
+ aidetect(text: string | string[], options?: AIDetectBatchOptions): Promise<AxiosResponse<WithUsage<AIDetectResponse | AIDetectBatchResponse>>>;
1114
+ fileAidetect(file: UploadFile, options?: FileAIDetectOptions): Promise<AxiosResponse<WithUsage<FileAIDetectResponse>>>;
1115
+ urlAidetect(url: string, options?: AIDetectOptions): Promise<AxiosResponse<WithUsage<URLAIDetectResponse>>>;
1116
+ styleguide(text: string, rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideResponse>>>;
1117
+ styleguide(texts: string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideBatchResponse>>>;
1118
+ styleguide(text: string | string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideResponse | StyleguideBatchResponse>>>;
1119
+ styleguideRulesets(): Promise<AxiosResponse<WithUsage<StyleguideRulesetsResponse>>>;
1120
+ saveStyleguideRuleset(name: string, rules: StyleguideRule[]): Promise<AxiosResponse<WithUsage<SaveStyleguideRulesetResponse>>>;
1121
+ deleteStyleguideRuleset(name: string): Promise<AxiosResponse<WithUsage<DeleteStyleguideRulesetResponse>>>;
1122
+ simplify(text: string, options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyResponse>>>;
1123
+ simplify(texts: string[], options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyBatchResponse>>>;
1124
+ simplify(text: string | string[], options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyResponse | SimplifyBatchResponse>>>;
1125
+ langdetect(text: string, options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectResponse>>>;
1126
+ langdetect(texts: string[], options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectBatchResponse>>>;
1127
+ langdetect(text: string | string[], options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectResponse | LangdetectBatchResponse>>>;
1128
+ quality(text: string, options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityResponse>>>;
1129
+ quality(texts: string[], options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityBatchResponse>>>;
1130
+ quality(text: string | string[], options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityResponse | QualityBatchResponse>>>;
1131
+ pii(text: string, options?: PIIOptions): Promise<AxiosResponse<WithUsage<PIIResponse>>>;
1132
+ ner(text: string, options?: NEROptions): Promise<AxiosResponse<WithUsage<NERResponse>>>;
1133
+ ner(texts: string[], options?: NEROptions): Promise<AxiosResponse<WithUsage<NERBatchResponse>>>;
1134
+ ner(text: string | string[], options?: NEROptions): Promise<AxiosResponse<WithUsage<NERResponse | NERBatchResponse>>>;
1135
+ inclusive(text: string, options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveResponse>>>;
1136
+ inclusive(texts: string[], options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveBatchResponse>>>;
1137
+ inclusive(text: string | string[], options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveResponse | InclusiveBatchResponse>>>;
1138
+ safety(text: string, options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyResponse>>>;
1139
+ safety(texts: string[], options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyBatchResponse>>>;
1140
+ safety(text: string | string[], options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyResponse | SafetyBatchResponse>>>;
1141
+ classify(text: string, labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyResponse>>>;
1142
+ classify(texts: string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyBatchResponse>>>;
1143
+ classify(text: string | string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyResponse | ClassifyBatchResponse>>>;
1144
+ seo(text: string, options?: SeoOptions): Promise<AxiosResponse<WithUsage<SeoResponse>>>;
642
1145
  accountStatus(): Promise<AxiosResponse<AccountStatusResponse>>;
1146
+ apiUsage(options?: ReportingWindowOptions): Promise<AxiosResponse<WithUsage<ApiUsageResponse>>>;
1147
+ apiEndpointUsage(options?: ApiEndpointUsageOptions): Promise<AxiosResponse<WithUsage<ApiEndpointUsageResponse>>>;
1148
+ /** Not WithUsage<>: the response's own `usage` is an integer and return_usage is not sent. */
1149
+ apiQuotaUsage(options?: ReportingWindowOptions): Promise<AxiosResponse<ApiQuotaUsageResponse>>;
1150
+ apiUserActivity(options?: ReportingWindowOptions): Promise<AxiosResponse<WithUsage<ApiUserActivityResponse>>>;
643
1151
  }