@verbatra/sdk 0.2.1 → 0.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.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -41
- package/dist/index.d.ts +87 -41
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
import { AnthropicModel, OpenAiModel, GeminiModel, ProviderNotice, TranslationProvider } from '@verbatra/ai-providers';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import { ProviderNotice, TranslationProvider } from '@verbatra/ai-providers';
|
|
3
3
|
import { AdapterRegistry } from '@verbatra/format-adapters';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The provider section of the config: a discriminated union over the provider id,
|
|
7
|
+
* reusing each provider's own exported config schema. There is no key field anywhere
|
|
8
|
+
* in this union. The provider reads its API key from the environment at construction.
|
|
9
|
+
*
|
|
10
|
+
* This union and the factory table below are co-located on purpose: adding a provider
|
|
11
|
+
* is a single edit here (one union variant plus one table entry), and the mapped-type
|
|
12
|
+
* table makes the two sets provably identical at compile time.
|
|
13
|
+
*/
|
|
14
|
+
declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
id: z.ZodLiteral<"anthropic">;
|
|
16
|
+
options: z.ZodObject<{
|
|
17
|
+
model: z.ZodString;
|
|
18
|
+
maxTokens: z.ZodNumber;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
21
|
+
id: z.ZodLiteral<"openai">;
|
|
22
|
+
options: z.ZodObject<{
|
|
23
|
+
model: z.ZodString;
|
|
24
|
+
maxOutputTokens: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
id: z.ZodLiteral<"gemini">;
|
|
28
|
+
options: z.ZodObject<{
|
|
29
|
+
model: z.ZodString;
|
|
30
|
+
maxOutputTokens: z.ZodNumber;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
id: z.ZodLiteral<"deepl">;
|
|
34
|
+
options: z.ZodObject<{
|
|
35
|
+
glossaryId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
}, z.core.$strip>], "id">;
|
|
38
|
+
type ProviderConfig = z.infer<typeof providerConfigSchema>;
|
|
39
|
+
type ProviderId = ProviderConfig["id"];
|
|
40
|
+
|
|
5
41
|
/**
|
|
6
42
|
* The verbatra project configuration. Non-secret only: it carries no API key (the
|
|
7
43
|
* provider reads its key from the environment), and unknown top-level keys are rejected
|
|
@@ -53,12 +89,56 @@ declare const verbatraConfigSchema: z.ZodObject<{
|
|
|
53
89
|
}, z.core.$strict>;
|
|
54
90
|
type VerbatraConfig = z.infer<typeof verbatraConfigSchema>;
|
|
55
91
|
|
|
92
|
+
/**
|
|
93
|
+
* An open union over a provider's known model IDs: the suggested IDs plus any other
|
|
94
|
+
* non-empty string. The `string & {}` arm keeps the union from collapsing to plain
|
|
95
|
+
* `string` (so editors still surface the literals as completions) while accepting a
|
|
96
|
+
* brand-new model ID the tool has never heard of. This is a static authoring hint
|
|
97
|
+
* only; the runtime schema stays `z.string().min(1)` and validates nothing against
|
|
98
|
+
* these literals.
|
|
99
|
+
*/
|
|
100
|
+
type OpenModel<M extends string> = M | (string & {});
|
|
101
|
+
/**
|
|
102
|
+
* The authoring view of one provider variant: its runtime config with `options.model`
|
|
103
|
+
* narrowed to that provider's open model union. LLM providers (anthropic, openai,
|
|
104
|
+
* gemini) get suggestions; DeepL has no model field and is carried through unchanged.
|
|
105
|
+
*/
|
|
106
|
+
type AuthoringProviderConfig = AuthoringVariant<"anthropic", AnthropicModel> | AuthoringVariant<"openai", OpenAiModel> | AuthoringVariant<"gemini", GeminiModel> | Extract<ProviderConfig, {
|
|
107
|
+
id: "deepl";
|
|
108
|
+
}>;
|
|
109
|
+
type AuthoringVariant<Id extends ProviderConfig["id"], M extends string> = Extract<ProviderConfig, {
|
|
110
|
+
id: Id;
|
|
111
|
+
}> extends infer Variant ? Variant extends {
|
|
112
|
+
options: {
|
|
113
|
+
model: string;
|
|
114
|
+
};
|
|
115
|
+
} ? Omit<Variant, "options"> & {
|
|
116
|
+
options: Omit<Variant["options"], "model"> & {
|
|
117
|
+
model: OpenModel<M>;
|
|
118
|
+
};
|
|
119
|
+
} : never : never;
|
|
120
|
+
/**
|
|
121
|
+
* The authoring view of the whole config: identical to {@link VerbatraConfig} except
|
|
122
|
+
* that `provider` offers per-provider model completions. Every value assignable to
|
|
123
|
+
* this type is assignable to {@link VerbatraConfig}, because the open model union is a
|
|
124
|
+
* subtype of `string`; `defineConfig` returns the runtime {@link VerbatraConfig}.
|
|
125
|
+
*/
|
|
126
|
+
type AuthoringConfig = Omit<VerbatraConfig, "provider"> & {
|
|
127
|
+
provider: AuthoringProviderConfig;
|
|
128
|
+
};
|
|
129
|
+
|
|
56
130
|
/**
|
|
57
131
|
* Identity helper for authoring a code-defined verbatra.config.ts. It returns its
|
|
58
132
|
* argument unchanged; its only purpose is to give the author full type inference and
|
|
59
133
|
* editor autocomplete on the config object.
|
|
134
|
+
*
|
|
135
|
+
* The argument type is {@link AuthoringConfig}, which is structurally a
|
|
136
|
+
* {@link VerbatraConfig} whose `provider.options.model` offers the selected provider's
|
|
137
|
+
* known model IDs as completions while still accepting any other string. The return
|
|
138
|
+
* type is the runtime {@link VerbatraConfig}: the suggestions are a static authoring
|
|
139
|
+
* hint, not a runtime constraint, and `loadConfig` validates `model` exactly as before.
|
|
60
140
|
*/
|
|
61
|
-
declare function defineConfig(config:
|
|
141
|
+
declare function defineConfig(config: AuthoringConfig): VerbatraConfig;
|
|
62
142
|
|
|
63
143
|
interface LoadConfigOptions {
|
|
64
144
|
/** Directory to start the search from. Defaults to the current working directory. */
|
|
@@ -107,42 +187,6 @@ interface LoadConfigOptions {
|
|
|
107
187
|
*/
|
|
108
188
|
declare function loadConfig(options?: LoadConfigOptions): Promise<VerbatraConfig>;
|
|
109
189
|
|
|
110
|
-
/**
|
|
111
|
-
* The provider section of the config: a discriminated union over the provider id,
|
|
112
|
-
* reusing each provider's own exported config schema. There is no key field anywhere
|
|
113
|
-
* in this union. The provider reads its API key from the environment at construction.
|
|
114
|
-
*
|
|
115
|
-
* This union and the factory table below are co-located on purpose: adding a provider
|
|
116
|
-
* is a single edit here (one union variant plus one table entry), and the mapped-type
|
|
117
|
-
* table makes the two sets provably identical at compile time.
|
|
118
|
-
*/
|
|
119
|
-
declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
120
|
-
id: z.ZodLiteral<"anthropic">;
|
|
121
|
-
options: z.ZodObject<{
|
|
122
|
-
model: z.ZodString;
|
|
123
|
-
maxTokens: z.ZodNumber;
|
|
124
|
-
}, z.core.$strict>;
|
|
125
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
-
id: z.ZodLiteral<"openai">;
|
|
127
|
-
options: z.ZodObject<{
|
|
128
|
-
model: z.ZodString;
|
|
129
|
-
maxOutputTokens: z.ZodNumber;
|
|
130
|
-
}, z.core.$strict>;
|
|
131
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
132
|
-
id: z.ZodLiteral<"gemini">;
|
|
133
|
-
options: z.ZodObject<{
|
|
134
|
-
model: z.ZodString;
|
|
135
|
-
maxOutputTokens: z.ZodNumber;
|
|
136
|
-
}, z.core.$strict>;
|
|
137
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
-
id: z.ZodLiteral<"deepl">;
|
|
139
|
-
options: z.ZodObject<{
|
|
140
|
-
glossaryId: z.ZodOptional<z.ZodString>;
|
|
141
|
-
}, z.core.$strict>;
|
|
142
|
-
}, z.core.$strip>], "id">;
|
|
143
|
-
type ProviderConfig = z.infer<typeof providerConfigSchema>;
|
|
144
|
-
type ProviderId = ProviderConfig["id"];
|
|
145
|
-
|
|
146
190
|
/**
|
|
147
191
|
* Structured, secret-free error codes for the SDK boundaries. A key never appears in
|
|
148
192
|
* any message: provider/adapter/core errors are already secret-free, and the SDK never
|
|
@@ -236,9 +280,11 @@ type BoundedBytesRead = {
|
|
|
236
280
|
readonly kind: "too-large";
|
|
237
281
|
};
|
|
238
282
|
/**
|
|
239
|
-
* The minimal file-system surface the SDK needs
|
|
240
|
-
*
|
|
241
|
-
*
|
|
283
|
+
* The minimal file-system surface the SDK needs: existence checks, the lock-file read/write,
|
|
284
|
+
* and the untrusted workbook bytes read/write for the export/import flow. Reads are bounded
|
|
285
|
+
* (see {@link readFileBounded} / {@link readBytesBounded}) and writes are atomic. Injectable so
|
|
286
|
+
* tests stay deterministic; the format adapters do their own file IO and are not routed through
|
|
287
|
+
* this seam.
|
|
242
288
|
*/
|
|
243
289
|
interface SdkFs {
|
|
244
290
|
/** Whether a readable file exists at the path. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
import { AnthropicModel, OpenAiModel, GeminiModel, ProviderNotice, TranslationProvider } from '@verbatra/ai-providers';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import { ProviderNotice, TranslationProvider } from '@verbatra/ai-providers';
|
|
3
3
|
import { AdapterRegistry } from '@verbatra/format-adapters';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The provider section of the config: a discriminated union over the provider id,
|
|
7
|
+
* reusing each provider's own exported config schema. There is no key field anywhere
|
|
8
|
+
* in this union. The provider reads its API key from the environment at construction.
|
|
9
|
+
*
|
|
10
|
+
* This union and the factory table below are co-located on purpose: adding a provider
|
|
11
|
+
* is a single edit here (one union variant plus one table entry), and the mapped-type
|
|
12
|
+
* table makes the two sets provably identical at compile time.
|
|
13
|
+
*/
|
|
14
|
+
declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
id: z.ZodLiteral<"anthropic">;
|
|
16
|
+
options: z.ZodObject<{
|
|
17
|
+
model: z.ZodString;
|
|
18
|
+
maxTokens: z.ZodNumber;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
21
|
+
id: z.ZodLiteral<"openai">;
|
|
22
|
+
options: z.ZodObject<{
|
|
23
|
+
model: z.ZodString;
|
|
24
|
+
maxOutputTokens: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
id: z.ZodLiteral<"gemini">;
|
|
28
|
+
options: z.ZodObject<{
|
|
29
|
+
model: z.ZodString;
|
|
30
|
+
maxOutputTokens: z.ZodNumber;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
id: z.ZodLiteral<"deepl">;
|
|
34
|
+
options: z.ZodObject<{
|
|
35
|
+
glossaryId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
}, z.core.$strip>], "id">;
|
|
38
|
+
type ProviderConfig = z.infer<typeof providerConfigSchema>;
|
|
39
|
+
type ProviderId = ProviderConfig["id"];
|
|
40
|
+
|
|
5
41
|
/**
|
|
6
42
|
* The verbatra project configuration. Non-secret only: it carries no API key (the
|
|
7
43
|
* provider reads its key from the environment), and unknown top-level keys are rejected
|
|
@@ -53,12 +89,56 @@ declare const verbatraConfigSchema: z.ZodObject<{
|
|
|
53
89
|
}, z.core.$strict>;
|
|
54
90
|
type VerbatraConfig = z.infer<typeof verbatraConfigSchema>;
|
|
55
91
|
|
|
92
|
+
/**
|
|
93
|
+
* An open union over a provider's known model IDs: the suggested IDs plus any other
|
|
94
|
+
* non-empty string. The `string & {}` arm keeps the union from collapsing to plain
|
|
95
|
+
* `string` (so editors still surface the literals as completions) while accepting a
|
|
96
|
+
* brand-new model ID the tool has never heard of. This is a static authoring hint
|
|
97
|
+
* only; the runtime schema stays `z.string().min(1)` and validates nothing against
|
|
98
|
+
* these literals.
|
|
99
|
+
*/
|
|
100
|
+
type OpenModel<M extends string> = M | (string & {});
|
|
101
|
+
/**
|
|
102
|
+
* The authoring view of one provider variant: its runtime config with `options.model`
|
|
103
|
+
* narrowed to that provider's open model union. LLM providers (anthropic, openai,
|
|
104
|
+
* gemini) get suggestions; DeepL has no model field and is carried through unchanged.
|
|
105
|
+
*/
|
|
106
|
+
type AuthoringProviderConfig = AuthoringVariant<"anthropic", AnthropicModel> | AuthoringVariant<"openai", OpenAiModel> | AuthoringVariant<"gemini", GeminiModel> | Extract<ProviderConfig, {
|
|
107
|
+
id: "deepl";
|
|
108
|
+
}>;
|
|
109
|
+
type AuthoringVariant<Id extends ProviderConfig["id"], M extends string> = Extract<ProviderConfig, {
|
|
110
|
+
id: Id;
|
|
111
|
+
}> extends infer Variant ? Variant extends {
|
|
112
|
+
options: {
|
|
113
|
+
model: string;
|
|
114
|
+
};
|
|
115
|
+
} ? Omit<Variant, "options"> & {
|
|
116
|
+
options: Omit<Variant["options"], "model"> & {
|
|
117
|
+
model: OpenModel<M>;
|
|
118
|
+
};
|
|
119
|
+
} : never : never;
|
|
120
|
+
/**
|
|
121
|
+
* The authoring view of the whole config: identical to {@link VerbatraConfig} except
|
|
122
|
+
* that `provider` offers per-provider model completions. Every value assignable to
|
|
123
|
+
* this type is assignable to {@link VerbatraConfig}, because the open model union is a
|
|
124
|
+
* subtype of `string`; `defineConfig` returns the runtime {@link VerbatraConfig}.
|
|
125
|
+
*/
|
|
126
|
+
type AuthoringConfig = Omit<VerbatraConfig, "provider"> & {
|
|
127
|
+
provider: AuthoringProviderConfig;
|
|
128
|
+
};
|
|
129
|
+
|
|
56
130
|
/**
|
|
57
131
|
* Identity helper for authoring a code-defined verbatra.config.ts. It returns its
|
|
58
132
|
* argument unchanged; its only purpose is to give the author full type inference and
|
|
59
133
|
* editor autocomplete on the config object.
|
|
134
|
+
*
|
|
135
|
+
* The argument type is {@link AuthoringConfig}, which is structurally a
|
|
136
|
+
* {@link VerbatraConfig} whose `provider.options.model` offers the selected provider's
|
|
137
|
+
* known model IDs as completions while still accepting any other string. The return
|
|
138
|
+
* type is the runtime {@link VerbatraConfig}: the suggestions are a static authoring
|
|
139
|
+
* hint, not a runtime constraint, and `loadConfig` validates `model` exactly as before.
|
|
60
140
|
*/
|
|
61
|
-
declare function defineConfig(config:
|
|
141
|
+
declare function defineConfig(config: AuthoringConfig): VerbatraConfig;
|
|
62
142
|
|
|
63
143
|
interface LoadConfigOptions {
|
|
64
144
|
/** Directory to start the search from. Defaults to the current working directory. */
|
|
@@ -107,42 +187,6 @@ interface LoadConfigOptions {
|
|
|
107
187
|
*/
|
|
108
188
|
declare function loadConfig(options?: LoadConfigOptions): Promise<VerbatraConfig>;
|
|
109
189
|
|
|
110
|
-
/**
|
|
111
|
-
* The provider section of the config: a discriminated union over the provider id,
|
|
112
|
-
* reusing each provider's own exported config schema. There is no key field anywhere
|
|
113
|
-
* in this union. The provider reads its API key from the environment at construction.
|
|
114
|
-
*
|
|
115
|
-
* This union and the factory table below are co-located on purpose: adding a provider
|
|
116
|
-
* is a single edit here (one union variant plus one table entry), and the mapped-type
|
|
117
|
-
* table makes the two sets provably identical at compile time.
|
|
118
|
-
*/
|
|
119
|
-
declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
120
|
-
id: z.ZodLiteral<"anthropic">;
|
|
121
|
-
options: z.ZodObject<{
|
|
122
|
-
model: z.ZodString;
|
|
123
|
-
maxTokens: z.ZodNumber;
|
|
124
|
-
}, z.core.$strict>;
|
|
125
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
-
id: z.ZodLiteral<"openai">;
|
|
127
|
-
options: z.ZodObject<{
|
|
128
|
-
model: z.ZodString;
|
|
129
|
-
maxOutputTokens: z.ZodNumber;
|
|
130
|
-
}, z.core.$strict>;
|
|
131
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
132
|
-
id: z.ZodLiteral<"gemini">;
|
|
133
|
-
options: z.ZodObject<{
|
|
134
|
-
model: z.ZodString;
|
|
135
|
-
maxOutputTokens: z.ZodNumber;
|
|
136
|
-
}, z.core.$strict>;
|
|
137
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
-
id: z.ZodLiteral<"deepl">;
|
|
139
|
-
options: z.ZodObject<{
|
|
140
|
-
glossaryId: z.ZodOptional<z.ZodString>;
|
|
141
|
-
}, z.core.$strict>;
|
|
142
|
-
}, z.core.$strip>], "id">;
|
|
143
|
-
type ProviderConfig = z.infer<typeof providerConfigSchema>;
|
|
144
|
-
type ProviderId = ProviderConfig["id"];
|
|
145
|
-
|
|
146
190
|
/**
|
|
147
191
|
* Structured, secret-free error codes for the SDK boundaries. A key never appears in
|
|
148
192
|
* any message: provider/adapter/core errors are already secret-free, and the SDK never
|
|
@@ -236,9 +280,11 @@ type BoundedBytesRead = {
|
|
|
236
280
|
readonly kind: "too-large";
|
|
237
281
|
};
|
|
238
282
|
/**
|
|
239
|
-
* The minimal file-system surface the SDK needs
|
|
240
|
-
*
|
|
241
|
-
*
|
|
283
|
+
* The minimal file-system surface the SDK needs: existence checks, the lock-file read/write,
|
|
284
|
+
* and the untrusted workbook bytes read/write for the export/import flow. Reads are bounded
|
|
285
|
+
* (see {@link readFileBounded} / {@link readBytesBounded}) and writes are atomic. Injectable so
|
|
286
|
+
* tests stay deterministic; the format adapters do their own file IO and are not routed through
|
|
287
|
+
* this seam.
|
|
242
288
|
*/
|
|
243
289
|
interface SdkFs {
|
|
244
290
|
/** Whether a readable file exists at the path. */
|