altalandi 0.6.1 → 0.6.3

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/client.d.ts CHANGED
@@ -1,122 +1,200 @@
1
- export type SourceLang = "auto" | "en" | "is";
2
- export type Domain = "general" | "marketing" | "data-analysis" | "childrens-fiction";
3
- export type Register = "formal" | "neutral" | "warm";
4
- export type WriterTier = "standard" | "max";
5
- export type ScoringTier = "none" | "fast" | "rigorous";
6
-
7
- export interface GlossaryTerm {
8
- en: string;
9
- is: string;
10
- note?: string;
11
- }
12
-
13
- export interface FetchResponseLike {
14
- ok: boolean;
15
- status: number;
16
- statusText?: string;
17
- /** Read for Retry-After on a 429. */
18
- headers?: { get(name: string): string | null };
19
- text(): Promise<string>;
20
- }
21
-
22
- export type FetchLike = (
23
- url: string,
24
- init: {
25
- method: string;
26
- headers: Record<string, string>;
27
- body: string;
28
- signal: any;
29
- },
30
- ) => Promise<FetchResponseLike>;
31
-
32
- export interface RefineOptions {
33
- sourceLang?: SourceLang;
34
- domain?: Domain;
35
- register?: Register;
36
- preserveMeaning?: boolean;
37
- scoreNativeness?: boolean;
38
- /** IS-refine: keep the original unless improvement is verified. */
39
- onlyImprove?: boolean;
40
- /** Optional EN→IS monolingual polish pass; false by default. */
41
- polishPass?: boolean;
42
- writer?: WriterTier;
43
- scoring?: ScoringTier;
44
- glossary?: GlossaryTerm[];
45
- returnDiffs?: boolean;
46
- /** Let Altalandi keep this text and its output to improve the service. Only with the person's consent; default false. */
47
- contribute?: boolean;
48
- /** Defaults to ALTALANDI_API_KEY. Never put a key in source control. */
49
- apiKey?: string;
50
- /** Defaults to https://altalandi.is/api. */
51
- baseUrl?: string;
52
- /** Per-request timeout in milliseconds; defaults to 300000. */
53
- timeoutMs?: number;
54
- /** Optional fetch-compatible implementation, useful for controlled runtimes and tests. */
55
- fetch?: FetchLike;
56
- }
57
-
58
- export interface RefineDiff {
59
- before: string;
60
- after: string;
61
- layer: "L1" | "L2" | "L3";
62
- reason: string;
63
- }
64
-
65
- export interface RefineQuality {
66
- nativenessScore: number | null;
67
- translationeseTells: string[];
68
- iceBertScore: number | null;
69
- morphologyOk: boolean | null;
70
- calqueFlags: string[];
71
- englishRemnants: string[];
72
- encodingArtifacts: string[];
73
- }
74
-
75
- export interface RefineResult {
76
- id: string;
77
- output: string;
78
- sourceLang: "en" | "is";
79
- diffs: RefineDiff[];
80
- quality: RefineQuality;
81
- /** Only strict true is a completed verification; null means skipped/unavailable. */
82
- meaningPreserved: boolean | null;
83
- meaningNotes: string;
84
- modelUsed: string;
85
- tier?: { writer: WriterTier; scoring: ScoringTier };
86
- billedTier?: { writer: WriterTier; scoring: ScoringTier };
87
- warnings: string[];
88
- /** true when a test key made the call: no model ran, nothing was charged, output = input. */
89
- test?: boolean | null;
90
- }
91
-
92
- export type VerifiedRefineResult = RefineResult & { meaningPreserved: true };
93
-
94
- export interface AltalandiErrorOptions {
95
- code?: string;
96
- status?: number;
97
- retryAfterMs?: number;
98
- }
99
-
100
- export class AltalandiError extends Error {
101
- readonly code: string;
102
- readonly status?: number;
103
- /** From the Retry-After header of an error response (429), when present. */
104
- readonly retryAfterMs?: number;
105
- constructor(message: string, options?: AltalandiErrorOptions);
106
- }
107
-
108
- export class MeaningVerificationError extends AltalandiError {
109
- readonly verdict: false | null;
110
- constructor(verdict: boolean | null | undefined);
111
- }
112
-
113
- /** Refine text and return the full hosted API response. */
114
- export function refine(text: string, options?: RefineOptions): Promise<RefineResult>;
115
-
116
- /** Refine text and throw unless meaningPreserved is strict true. */
117
- export function refineVerified(text: string, options?: RefineOptions): Promise<VerifiedRefineResult>;
118
-
119
- /** Narrow an existing result to one with a verified meaning verdict. */
120
- export function assertMeaningVerified(
121
- result: RefineResult,
122
- ): asserts result is VerifiedRefineResult;
1
+ export type SourceLang = "auto" | "en" | "is";
2
+ export type Domain = "general" | "marketing" | "data-analysis" | "childrens-fiction";
3
+ export type Register = "formal" | "neutral" | "warm";
4
+ export type WriterTier = "standard" | "max";
5
+ export type ScoringTier = "none" | "fast" | "rigorous";
6
+
7
+ export interface GlossaryTerm {
8
+ en: string;
9
+ is: string;
10
+ note?: string;
11
+ }
12
+
13
+ /** Groups calls into one job ("verk") on the account: a document sent in
14
+ * parts, a folder or a site. The first call that names an id creates the job. */
15
+ export interface JobRef {
16
+ /** `j_` and 8–64 of [A-Za-z0-9_-], chosen by the client. */
17
+ id: string;
18
+ /** The job's name (at most 120 characters); the first one sent is kept. */
19
+ title?: string;
20
+ /** This call's piece: a file path, a page URL, "Hluti 2 af 5" (at most 300 characters). */
21
+ part?: string;
22
+ }
23
+
24
+ export interface FetchResponseLike {
25
+ ok: boolean;
26
+ status: number;
27
+ statusText?: string;
28
+ /** Read for Retry-After on a 429. */
29
+ headers?: { get(name: string): string | null };
30
+ text(): Promise<string>;
31
+ }
32
+
33
+ export type FetchLike = (
34
+ url: string,
35
+ init: {
36
+ method: string;
37
+ headers: Record<string, string>;
38
+ body: string;
39
+ signal: any;
40
+ },
41
+ ) => Promise<FetchResponseLike>;
42
+
43
+ export interface RefineOptions {
44
+ sourceLang?: SourceLang;
45
+ domain?: Domain;
46
+ register?: Register;
47
+ preserveMeaning?: boolean;
48
+ scoreNativeness?: boolean;
49
+ /** IS-refine: keep the original unless improvement is verified. */
50
+ onlyImprove?: boolean;
51
+ /** Optional EN→IS monolingual polish pass; false by default. */
52
+ polishPass?: boolean;
53
+ writer?: WriterTier;
54
+ scoring?: ScoringTier;
55
+ glossary?: GlossaryTerm[];
56
+ returnDiffs?: boolean;
57
+ /** Let Altalandi keep this text and its output to improve the service. Only with the person's consent; default false. */
58
+ contribute?: boolean;
59
+ /** Make this call a part of a job. Ignored for anonymous calls. */
60
+ job?: JobRef;
61
+ /** Defaults to ALTALANDI_API_KEY. Never put a key in source control. */
62
+ apiKey?: string;
63
+ /** Defaults to https://altalandi.is/api. */
64
+ baseUrl?: string;
65
+ /** Per-request timeout in milliseconds; defaults to 300000. */
66
+ timeoutMs?: number;
67
+ /** Optional fetch-compatible implementation, useful for controlled runtimes and tests. */
68
+ fetch?: FetchLike;
69
+ }
70
+
71
+ export interface RefineDiff {
72
+ before: string;
73
+ after: string;
74
+ layer: "L1" | "L2" | "L3";
75
+ reason: string;
76
+ }
77
+
78
+ export interface RefineQuality {
79
+ nativenessScore: number | null;
80
+ translationeseTells: string[];
81
+ iceBertScore: number | null;
82
+ morphologyOk: boolean | null;
83
+ calqueFlags: string[];
84
+ englishRemnants: string[];
85
+ encodingArtifacts: string[];
86
+ }
87
+
88
+ export interface RefineResult {
89
+ id: string;
90
+ output: string;
91
+ sourceLang: "en" | "is";
92
+ diffs: RefineDiff[];
93
+ quality: RefineQuality;
94
+ /** Only strict true is a completed verification; null means skipped/unavailable. */
95
+ meaningPreserved: boolean | null;
96
+ meaningNotes: string;
97
+ modelUsed: string;
98
+ tier?: { writer: WriterTier; scoring: ScoringTier };
99
+ billedTier?: { writer: WriterTier; scoring: ScoringTier };
100
+ warnings: string[];
101
+ /** true when a test key made the call: no model ran, nothing was charged, output = input. */
102
+ test?: boolean | null;
103
+ /** Characters billed (= billing.characters); absent from engines before character billing. */
104
+ characters?: number;
105
+ /** /v1 only: what the call cost and what is left (characters, chargedIsk, balanceIsk, freeCharsLeftToday, …). */
106
+ billing?: Record<string, unknown> | null;
107
+ /** This call's own page. */
108
+ runUrl?: string | null;
109
+ /** When `job` was sent (and the engine knows jobs): the job's id and page. */
110
+ jobId?: string;
111
+ jobUrl?: string;
112
+ }
113
+
114
+ export type VerifiedRefineResult = RefineResult & { meaningPreserved: true };
115
+
116
+ export interface AltalandiErrorOptions {
117
+ code?: string;
118
+ status?: number;
119
+ retryAfterMs?: number;
120
+ }
121
+
122
+ export class AltalandiError extends Error {
123
+ readonly code: string;
124
+ readonly status?: number;
125
+ /** From the Retry-After header of an error response (429), when present. */
126
+ readonly retryAfterMs?: number;
127
+ constructor(message: string, options?: AltalandiErrorOptions);
128
+ }
129
+
130
+ export class MeaningVerificationError extends AltalandiError {
131
+ readonly verdict: false | null;
132
+ constructor(verdict: boolean | null | undefined);
133
+ }
134
+
135
+ /** Refine text and return the full hosted API response. */
136
+ export function refine(text: string, options?: RefineOptions): Promise<RefineResult>;
137
+
138
+ export interface BatchItem {
139
+ /** Your key for the string; defaults to its index, as a string. */
140
+ id?: string;
141
+ /** At most 2,000 characters. */
142
+ text: string;
143
+ }
144
+
145
+ export interface BatchOptions {
146
+ sourceLang?: SourceLang;
147
+ domain?: Domain;
148
+ register?: Register;
149
+ preserveMeaning?: boolean;
150
+ scoreNativeness?: boolean;
151
+ onlyImprove?: boolean;
152
+ glossary?: GlossaryTerm[];
153
+ autoTerminology?: boolean;
154
+ contribute?: boolean;
155
+ job?: JobRef;
156
+ apiKey?: string;
157
+ baseUrl?: string;
158
+ timeoutMs?: number;
159
+ fetch?: FetchLike;
160
+ }
161
+
162
+ export interface BatchItemResult {
163
+ id: string;
164
+ output: string;
165
+ sourceLang: "en" | "is";
166
+ diffs: RefineDiff[];
167
+ meaningCheck: "passed" | "changed" | "reverted" | "skipped" | "unavailable";
168
+ meaningPreserved: boolean | null;
169
+ warnings: string[];
170
+ /** true: refined in one model call with other strings, then checked on its own. */
171
+ packed: boolean;
172
+ /** Set when this string could not be refined: it came back unchanged and was not billed. */
173
+ error?: string | null;
174
+ }
175
+
176
+ export interface BatchResult {
177
+ id: string;
178
+ runUrl: string | null;
179
+ items: BatchItemResult[];
180
+ /** Characters billed for the whole batch (= billing.characters); absent from engines before character billing. */
181
+ characters?: number;
182
+ /** @deprecated The word equivalent of `characters` (= billing.units). */
183
+ units: number;
184
+ billing: Record<string, unknown> | null;
185
+ quality: RefineQuality;
186
+ warnings: string[];
187
+ jobId?: string;
188
+ jobUrl?: string;
189
+ }
190
+
191
+ /** Refine many short strings in one call (POST /v1/refine/batch). */
192
+ export function refineBatch(items: BatchItem[], options?: BatchOptions): Promise<BatchResult>;
193
+
194
+ /** Refine text and throw unless meaningPreserved is strict true. */
195
+ export function refineVerified(text: string, options?: RefineOptions): Promise<VerifiedRefineResult>;
196
+
197
+ /** Narrow an existing result to one with a verified meaning verdict. */
198
+ export function assertMeaningVerified(
199
+ result: RefineResult,
200
+ ): asserts result is VerifiedRefineResult;