@fgv/ts-extras 5.1.0-15 → 5.1.0-17
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.browser.js +2 -1
- package/dist/packlets/ai-assist/apiClient.js +570 -58
- package/dist/packlets/ai-assist/chatRequestBuilders.js +180 -0
- package/dist/packlets/ai-assist/index.js +4 -3
- package/dist/packlets/ai-assist/model.js +20 -3
- package/dist/packlets/ai-assist/registry.js +66 -10
- package/dist/packlets/ai-assist/sseParser.js +122 -0
- package/dist/packlets/ai-assist/streamingAdapters/anthropic.js +192 -0
- package/dist/packlets/ai-assist/streamingAdapters/common.js +77 -0
- package/dist/packlets/ai-assist/streamingAdapters/gemini.js +160 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js +149 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js +163 -0
- package/dist/packlets/ai-assist/streamingAdapters/proxy.js +157 -0
- package/dist/packlets/ai-assist/streamingClient.js +88 -0
- package/dist/packlets/conversion/converters.js +1 -1
- package/dist/packlets/crypto-utils/keystore/keyStore.js +74 -42
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
- package/dist/ts-extras.d.ts +531 -5
- package/lib/index.browser.d.ts +2 -1
- package/lib/index.browser.js +3 -1
- package/lib/packlets/ai-assist/apiClient.d.ts +103 -1
- package/lib/packlets/ai-assist/apiClient.js +574 -58
- package/lib/packlets/ai-assist/chatRequestBuilders.d.ts +89 -0
- package/lib/packlets/ai-assist/chatRequestBuilders.js +189 -0
- package/lib/packlets/ai-assist/index.d.ts +4 -3
- package/lib/packlets/ai-assist/index.js +10 -1
- package/lib/packlets/ai-assist/model.d.ts +271 -2
- package/lib/packlets/ai-assist/model.js +21 -3
- package/lib/packlets/ai-assist/registry.d.ts +10 -1
- package/lib/packlets/ai-assist/registry.js +67 -11
- package/lib/packlets/ai-assist/sseParser.d.ts +45 -0
- package/lib/packlets/ai-assist/sseParser.js +127 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts +18 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.js +195 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.d.ts +71 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.js +81 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts +19 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.js +163 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts +18 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js +152 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts +19 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js +166 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts +34 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.js +160 -0
- package/lib/packlets/ai-assist/streamingClient.d.ts +33 -0
- package/lib/packlets/ai-assist/streamingClient.js +93 -0
- package/lib/packlets/conversion/converters.d.ts +1 -1
- package/lib/packlets/conversion/converters.js +1 -1
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +19 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +74 -42
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +2 -2
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
- package/package.json +7 -7
package/dist/ts-extras.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare type AiApiFormat = 'openai' | 'anthropic' | 'gemini';
|
|
|
23
23
|
declare namespace AiAssist {
|
|
24
24
|
export {
|
|
25
25
|
AiPrompt,
|
|
26
|
+
AiModelCapability,
|
|
26
27
|
AiProviderId,
|
|
27
28
|
AiServerToolType,
|
|
28
29
|
AiServerToolConfig,
|
|
@@ -31,23 +32,49 @@ declare namespace AiAssist {
|
|
|
31
32
|
IAiCompletionResponse,
|
|
32
33
|
IChatMessage,
|
|
33
34
|
AiApiFormat,
|
|
35
|
+
AiImageApiFormat,
|
|
34
36
|
IAiProviderDescriptor,
|
|
35
37
|
IAiAssistProviderConfig,
|
|
36
38
|
IAiAssistSettings,
|
|
37
39
|
DEFAULT_AI_ASSIST,
|
|
38
40
|
IAiAssistKeyStore,
|
|
41
|
+
IAiImageAttachment,
|
|
42
|
+
IAiImageData,
|
|
43
|
+
IAiImageGenerationOptions,
|
|
44
|
+
IAiImageGenerationParams,
|
|
45
|
+
IAiGeneratedImage,
|
|
46
|
+
IAiImageGenerationResponse,
|
|
47
|
+
IAiModelCapabilityRule,
|
|
48
|
+
IAiModelCapabilityConfig,
|
|
49
|
+
IAiModelInfo,
|
|
50
|
+
IAiStreamEvent,
|
|
51
|
+
IAiStreamTextDelta,
|
|
52
|
+
IAiStreamToolEvent,
|
|
53
|
+
IAiStreamDone,
|
|
54
|
+
IAiStreamError,
|
|
39
55
|
ModelSpec,
|
|
40
56
|
ModelSpecKey,
|
|
41
57
|
IModelSpecMap,
|
|
42
58
|
allModelSpecKeys,
|
|
43
59
|
MODEL_SPEC_BASE_KEY,
|
|
44
60
|
resolveModel,
|
|
61
|
+
toDataUrl,
|
|
45
62
|
allProviderIds,
|
|
46
63
|
getProviderDescriptors,
|
|
47
64
|
getProviderDescriptor,
|
|
65
|
+
DEFAULT_MODEL_CAPABILITY_CONFIG,
|
|
48
66
|
callProviderCompletion,
|
|
49
67
|
callProxiedCompletion,
|
|
68
|
+
callProviderImageGeneration,
|
|
69
|
+
callProxiedImageGeneration,
|
|
70
|
+
callProviderListModels,
|
|
71
|
+
callProxiedListModels,
|
|
50
72
|
IProviderCompletionParams,
|
|
73
|
+
IProviderImageGenerationParams,
|
|
74
|
+
IProviderListModelsParams,
|
|
75
|
+
callProviderCompletionStream,
|
|
76
|
+
callProxiedCompletionStream,
|
|
77
|
+
IProviderCompletionStreamParams,
|
|
51
78
|
aiProviderId,
|
|
52
79
|
aiServerToolType,
|
|
53
80
|
aiWebSearchToolConfig,
|
|
@@ -74,6 +101,25 @@ declare const aiAssistProviderConfig: Converter<IAiAssistProviderConfig>;
|
|
|
74
101
|
*/
|
|
75
102
|
declare const aiAssistSettings: Converter<IAiAssistSettings>;
|
|
76
103
|
|
|
104
|
+
/**
|
|
105
|
+
* API format categories for image-generation provider routing.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images';
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Capability vocabulary used to describe what a model can do. Used as both
|
|
112
|
+
* a filter and as a tag in {@link AiAssist.IAiModelInfo.capabilities}.
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* Adding a new capability is cheap; adding the *first* one after consumers
|
|
116
|
+
* already exist forces churn. The initial vocabulary is intentionally broad
|
|
117
|
+
* even though only `image-generation` is fully exercised today.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
declare type AiModelCapability = 'chat' | 'tools' | 'vision' | 'image-generation';
|
|
122
|
+
|
|
77
123
|
/**
|
|
78
124
|
* A structured AI prompt with system/user split for direct API calls,
|
|
79
125
|
* and a lazily-constructed combined version for copy/paste workflows.
|
|
@@ -84,8 +130,18 @@ declare class AiPrompt {
|
|
|
84
130
|
readonly system: string;
|
|
85
131
|
/** User request: the specific entity generation request. */
|
|
86
132
|
readonly user: string;
|
|
87
|
-
|
|
88
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Optional image attachments. When present, vision-capable providers will
|
|
135
|
+
* include them in the user message; non-vision providers will reject the
|
|
136
|
+
* call up front (see {@link AiAssist.IAiProviderDescriptor.acceptsImageInput}).
|
|
137
|
+
*/
|
|
138
|
+
readonly attachments: ReadonlyArray<IAiImageAttachment>;
|
|
139
|
+
constructor(user: string, system: string, attachments?: ReadonlyArray<IAiImageAttachment>);
|
|
140
|
+
/**
|
|
141
|
+
* Combined single-string version (user + system joined) for copy/paste.
|
|
142
|
+
* When attachments are present, includes a sentinel noting they aren't
|
|
143
|
+
* part of the copied text.
|
|
144
|
+
*/
|
|
89
145
|
get combined(): string;
|
|
90
146
|
}
|
|
91
147
|
|
|
@@ -180,6 +236,55 @@ declare const base64String: Converter<string>;
|
|
|
180
236
|
*/
|
|
181
237
|
declare function callProviderCompletion(params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
|
|
182
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Calls the appropriate streaming chat completion API for a given provider.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* Pre-flight rejection: when `descriptor.streamingCorsRestricted === true`
|
|
244
|
+
* and the call isn't being routed through a proxy, this returns
|
|
245
|
+
* `Result.fail` before fetch is invoked. Callers should route through
|
|
246
|
+
* {@link AiAssist.callProxiedCompletionStream} or surface the failure to the user.
|
|
247
|
+
*
|
|
248
|
+
* Connection-time failures (auth, network, non-2xx) surface as the outer
|
|
249
|
+
* `Result.fail`. Once iteration begins, errors mid-stream surface as a
|
|
250
|
+
* terminal error event ({@link AiAssist.IAiStreamError}) followed by the iterable
|
|
251
|
+
* ending. The final successful event is {@link AiAssist.IAiStreamDone}.
|
|
252
|
+
*
|
|
253
|
+
* @param params - Request parameters including descriptor, API key, prompt, and optional tools
|
|
254
|
+
* @returns A streaming iterable of unified events, or a Result.fail
|
|
255
|
+
* @public
|
|
256
|
+
*/
|
|
257
|
+
declare function callProviderCompletionStream(params: IProviderCompletionStreamParams): Promise<Result<AsyncIterable<IAiStreamEvent>>>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Calls the appropriate image-generation API for a given provider.
|
|
261
|
+
*
|
|
262
|
+
* Routes based on `descriptor.imageApiFormat`:
|
|
263
|
+
* - `'openai-images'` for OpenAI (DALL-E, gpt-image-1)
|
|
264
|
+
* - `'xai-images'` for xAI Grok image models
|
|
265
|
+
* - `'gemini-imagen'` for Google Imagen
|
|
266
|
+
*
|
|
267
|
+
* Image-model selection reuses the existing `'image'` {@link ModelSpecKey}.
|
|
268
|
+
*
|
|
269
|
+
* @param params - Request parameters including descriptor, API key, and prompt
|
|
270
|
+
* @returns The generated images, or a failure
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
declare function callProviderImageGeneration(params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Lists models available from a provider, with capabilities resolved from
|
|
277
|
+
* native provider info (where supplied) and a configurable rule set.
|
|
278
|
+
*
|
|
279
|
+
* Routes based on `descriptor.apiFormat` — listing reuses the existing
|
|
280
|
+
* format dispatch and does not require a separate descriptor field.
|
|
281
|
+
*
|
|
282
|
+
* @param params - Request parameters including descriptor, API key, and optional capability filter
|
|
283
|
+
* @returns The resolved model list, or a failure
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
declare function callProviderListModels(params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
|
|
287
|
+
|
|
183
288
|
/**
|
|
184
289
|
* Calls the AI completion endpoint on a proxy server instead of calling
|
|
185
290
|
* the provider API directly from the browser.
|
|
@@ -195,6 +300,68 @@ declare function callProviderCompletion(params: IProviderCompletionParams): Prom
|
|
|
195
300
|
*/
|
|
196
301
|
declare function callProxiedCompletion(proxyUrl: string, params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
|
|
197
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Calls the streaming chat endpoint on a proxy server instead of calling
|
|
305
|
+
* the provider directly from the browser.
|
|
306
|
+
*
|
|
307
|
+
* @remarks
|
|
308
|
+
* Proxy contract:
|
|
309
|
+
* - Endpoint: `POST ${proxyUrl}/api/ai/completion-stream`
|
|
310
|
+
* - Request body: same JSON as `/api/ai/completion` plus `"stream": true`
|
|
311
|
+
* - Response: `Content-Type: text/event-stream`; body is the unified
|
|
312
|
+
* {@link AiAssist.IAiStreamEvent} JSON-serialized one event per SSE `data:` line
|
|
313
|
+
* (no `event:` line needed since the type discriminator is in the JSON).
|
|
314
|
+
* - Error response (when the proxy can't even start): JSON `{error: string}`
|
|
315
|
+
* with a non-2xx status, surfaced as `proxy: ${error}`.
|
|
316
|
+
*
|
|
317
|
+
* The proxy server is responsible for opening the upstream SSE connection,
|
|
318
|
+
* translating provider-native events to the unified vocabulary, and
|
|
319
|
+
* forwarding events as they arrive (no buffering). The library does not
|
|
320
|
+
* ship a proxy implementation.
|
|
321
|
+
*
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
declare function callProxiedCompletionStream(proxyUrl: string, params: IProviderCompletionStreamParams): Promise<Result<AsyncIterable<IAiStreamEvent>>>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Calls the image-generation endpoint on a proxy server instead of calling
|
|
328
|
+
* the provider API directly from the browser.
|
|
329
|
+
*
|
|
330
|
+
* @remarks
|
|
331
|
+
* The proxy contract:
|
|
332
|
+
* - Endpoint: `POST ${proxyUrl}/api/ai/image-generation`
|
|
333
|
+
* - Request body: `{providerId, apiKey, params, modelOverride?}`
|
|
334
|
+
* - Success response body: an {@link IAiImageGenerationResponse}
|
|
335
|
+
* - Error response body: `{error: string}` (surfaced as `proxy: ${error}`)
|
|
336
|
+
*
|
|
337
|
+
* The proxy server is responsible for descriptor lookup, model resolution,
|
|
338
|
+
* provider dispatch, and response normalization.
|
|
339
|
+
*
|
|
340
|
+
* @param proxyUrl - Base URL of the proxy server (e.g. `http://localhost:3001`)
|
|
341
|
+
* @param params - Same parameters as {@link callProviderImageGeneration}
|
|
342
|
+
* @returns The generated images, or a failure
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
declare function callProxiedImageGeneration(proxyUrl: string, params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Calls the model-listing endpoint on a proxy server.
|
|
349
|
+
*
|
|
350
|
+
* @remarks
|
|
351
|
+
* Proxy contract:
|
|
352
|
+
* - Endpoint: `POST ${proxyUrl}/api/ai/list-models`
|
|
353
|
+
* - Request body: `{providerId, apiKey, capability?}`. Capability config is
|
|
354
|
+
* not forwarded — the proxy applies its own (typically the same default
|
|
355
|
+
* the library ships).
|
|
356
|
+
* - Success response body: an `IAiModelInfo[]` (under key `models`) where
|
|
357
|
+
* `capabilities` is serialized as a string array (not Set, which doesn't
|
|
358
|
+
* round-trip through JSON).
|
|
359
|
+
* - Error response body: `{error: string}`, surfaced as `proxy: ${error}`.
|
|
360
|
+
*
|
|
361
|
+
* @public
|
|
362
|
+
*/
|
|
363
|
+
declare function callProxiedListModels(proxyUrl: string, params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
|
|
364
|
+
|
|
198
365
|
declare namespace Constants {
|
|
199
366
|
export {
|
|
200
367
|
ENCRYPTED_FILE_FORMAT,
|
|
@@ -347,6 +514,16 @@ declare const DEFAULT_ALGORITHM: "AES-256-GCM";
|
|
|
347
514
|
*/
|
|
348
515
|
declare const DEFAULT_KEYSTORE_ITERATIONS: number;
|
|
349
516
|
|
|
517
|
+
/**
|
|
518
|
+
* Default capability config used by `callProviderListModels` when callers
|
|
519
|
+
* don't supply their own. Patterns are intentionally narrow — false
|
|
520
|
+
* positives are worse than missing a model. Caller can override per call
|
|
521
|
+
* via {@link IProviderListModelsParams.capabilityConfig}.
|
|
522
|
+
*
|
|
523
|
+
* @public
|
|
524
|
+
*/
|
|
525
|
+
declare const DEFAULT_MODEL_CAPABILITY_CONFIG: IAiModelCapabilityConfig;
|
|
526
|
+
|
|
350
527
|
/**
|
|
351
528
|
* Default {@link Experimental.RangeOfFormats | formats} to use for both
|
|
352
529
|
* open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.
|
|
@@ -534,7 +711,7 @@ declare class ExtendedArray<T> extends Array<T> {
|
|
|
534
711
|
* If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
|
|
535
712
|
* be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
|
|
536
713
|
* @param converter - `Converter` used to convert each item in the array
|
|
537
|
-
* @param
|
|
714
|
+
* @param onError - Specifies treatment of unconvertible elements
|
|
538
715
|
* @beta
|
|
539
716
|
*/
|
|
540
717
|
declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: Conversion.OnError): Converter<ExtendedArray<T>, TC>;
|
|
@@ -764,6 +941,162 @@ declare interface IAiCompletionResponse {
|
|
|
764
941
|
readonly truncated: boolean;
|
|
765
942
|
}
|
|
766
943
|
|
|
944
|
+
/**
|
|
945
|
+
* A single generated image.
|
|
946
|
+
* @public
|
|
947
|
+
*/
|
|
948
|
+
declare interface IAiGeneratedImage extends IAiImageData {
|
|
949
|
+
/**
|
|
950
|
+
* The prompt as rewritten by the provider, if any. OpenAI's image models
|
|
951
|
+
* commonly rewrite prompts; other providers do not.
|
|
952
|
+
*/
|
|
953
|
+
readonly revisedPrompt?: string;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Image attachment for a vision (image-input) prompt.
|
|
958
|
+
*
|
|
959
|
+
* @remarks
|
|
960
|
+
* Extends {@link IAiImageData} with an OpenAI-specific `detail` hint that is
|
|
961
|
+
* silently ignored by Anthropic, Gemini, and other providers.
|
|
962
|
+
*
|
|
963
|
+
* @public
|
|
964
|
+
*/
|
|
965
|
+
declare interface IAiImageAttachment extends IAiImageData {
|
|
966
|
+
/**
|
|
967
|
+
* OpenAI vision detail hint:
|
|
968
|
+
* - `'low'`: faster, cheaper, lower fidelity
|
|
969
|
+
* - `'high'`: slower, more expensive, higher fidelity
|
|
970
|
+
* - `'auto'` (default): provider chooses
|
|
971
|
+
*
|
|
972
|
+
* Ignored by providers other than OpenAI.
|
|
973
|
+
*/
|
|
974
|
+
readonly detail?: 'low' | 'high' | 'auto';
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Universal image representation used for both image input (vision prompts)
|
|
979
|
+
* and image output (generation responses).
|
|
980
|
+
*
|
|
981
|
+
* @remarks
|
|
982
|
+
* The base64 string is raw — no `data:` URL prefix. Use {@link AiAssist.toDataUrl} to
|
|
983
|
+
* format it for browser-display contexts.
|
|
984
|
+
*
|
|
985
|
+
* @public
|
|
986
|
+
*/
|
|
987
|
+
declare interface IAiImageData {
|
|
988
|
+
/** MIME type, e.g. `'image/png'`, `'image/jpeg'`, `'image/webp'`. */
|
|
989
|
+
readonly mimeType: string;
|
|
990
|
+
/** Base64-encoded image bytes (no `data:` prefix). */
|
|
991
|
+
readonly base64: string;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Options for image generation requests.
|
|
996
|
+
*
|
|
997
|
+
* @remarks
|
|
998
|
+
* Provider compatibility is documented per field. The library does not
|
|
999
|
+
* pre-validate against per-model constraints (e.g. `dall-e-3` rejects
|
|
1000
|
+
* `count > 1`); provider 400 errors surface through the failure path.
|
|
1001
|
+
*
|
|
1002
|
+
* @public
|
|
1003
|
+
*/
|
|
1004
|
+
declare interface IAiImageGenerationOptions {
|
|
1005
|
+
/**
|
|
1006
|
+
* Image dimensions. Used by openai-format providers (mapped to the
|
|
1007
|
+
* provider's `size` field). Ignored by Imagen — use
|
|
1008
|
+
* {@link IAiImageGenerationOptions.imagen} `aspectRatio` instead.
|
|
1009
|
+
*
|
|
1010
|
+
* Note: each model has its own accepted set; `dall-e-3` only accepts the
|
|
1011
|
+
* values listed here.
|
|
1012
|
+
*/
|
|
1013
|
+
readonly size?: '1024x1024' | '1024x1792' | '1792x1024' | 'auto';
|
|
1014
|
+
/**
|
|
1015
|
+
* Number of images to generate. Default 1.
|
|
1016
|
+
*
|
|
1017
|
+
* Note: `dall-e-3` rejects `count > 1`.
|
|
1018
|
+
*/
|
|
1019
|
+
readonly count?: number;
|
|
1020
|
+
/** Generation quality hint where supported. */
|
|
1021
|
+
readonly quality?: 'standard' | 'high';
|
|
1022
|
+
/** Random seed for reproducibility, where supported. */
|
|
1023
|
+
readonly seed?: number;
|
|
1024
|
+
/**
|
|
1025
|
+
* Imagen-specific options. Ignored by other providers.
|
|
1026
|
+
*/
|
|
1027
|
+
readonly imagen?: {
|
|
1028
|
+
readonly negativePrompt?: string;
|
|
1029
|
+
readonly aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Parameters for an image-generation request.
|
|
1035
|
+
* @public
|
|
1036
|
+
*/
|
|
1037
|
+
declare interface IAiImageGenerationParams {
|
|
1038
|
+
/** The text prompt describing the desired image. */
|
|
1039
|
+
readonly prompt: string;
|
|
1040
|
+
/** Optional generation options. */
|
|
1041
|
+
readonly options?: IAiImageGenerationOptions;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Result of an image-generation call.
|
|
1046
|
+
* @public
|
|
1047
|
+
*/
|
|
1048
|
+
declare interface IAiImageGenerationResponse {
|
|
1049
|
+
/** The generated images, in provider-returned order. */
|
|
1050
|
+
readonly images: ReadonlyArray<IAiGeneratedImage>;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Configuration that maps model id patterns to capabilities. Used to
|
|
1055
|
+
* augment (or, where the provider supplies no capability info, fully
|
|
1056
|
+
* derive) the capability set for each listed model.
|
|
1057
|
+
* @public
|
|
1058
|
+
*/
|
|
1059
|
+
declare interface IAiModelCapabilityConfig {
|
|
1060
|
+
/** Per-provider rules. Tried before {@link AiAssist.IAiModelCapabilityConfig.global}. */
|
|
1061
|
+
readonly perProvider?: {
|
|
1062
|
+
readonly [P in AiProviderId]?: ReadonlyArray<IAiModelCapabilityRule>;
|
|
1063
|
+
};
|
|
1064
|
+
/** Cross-provider fallback rules. */
|
|
1065
|
+
readonly global?: ReadonlyArray<IAiModelCapabilityRule>;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* One rule in an {@link IAiModelCapabilityConfig}. Multiple rules can match
|
|
1070
|
+
* a single model — their capability arrays are unioned.
|
|
1071
|
+
* @public
|
|
1072
|
+
*/
|
|
1073
|
+
declare interface IAiModelCapabilityRule {
|
|
1074
|
+
/** RegExp tested against the model id (using `.test`). */
|
|
1075
|
+
readonly idPattern: RegExp;
|
|
1076
|
+
/** Capabilities this rule attributes to matching models. */
|
|
1077
|
+
readonly capabilities: ReadonlyArray<AiModelCapability>;
|
|
1078
|
+
/**
|
|
1079
|
+
* Friendly display-name override for matching models. The function form
|
|
1080
|
+
* lets one rule format many ids (e.g. `(id) => id.toUpperCase()`).
|
|
1081
|
+
* If multiple matching rules supply `displayName`, the first match wins.
|
|
1082
|
+
*/
|
|
1083
|
+
readonly displayName?: string | ((id: string) => string);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Information about a single model returned by a provider's list endpoint,
|
|
1088
|
+
* with capabilities already resolved (native + config rules).
|
|
1089
|
+
* @public
|
|
1090
|
+
*/
|
|
1091
|
+
declare interface IAiModelInfo {
|
|
1092
|
+
/** Provider-native model identifier. */
|
|
1093
|
+
readonly id: string;
|
|
1094
|
+
/** Resolved capability set — union of native declarations and config rules. */
|
|
1095
|
+
readonly capabilities: ReadonlySet<AiModelCapability>;
|
|
1096
|
+
/** Friendly name for display, when known. */
|
|
1097
|
+
readonly displayName?: string;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
767
1100
|
/**
|
|
768
1101
|
* Describes a single AI provider — single source of truth for all metadata.
|
|
769
1102
|
* @public
|
|
@@ -787,6 +1120,99 @@ declare interface IAiProviderDescriptor {
|
|
|
787
1120
|
readonly supportedTools: ReadonlyArray<AiServerToolType>;
|
|
788
1121
|
/** Whether this provider's API enforces CORS restrictions that prevent direct browser calls. */
|
|
789
1122
|
readonly corsRestricted: boolean;
|
|
1123
|
+
/**
|
|
1124
|
+
* Whether this provider's streaming completion endpoint requires a proxy
|
|
1125
|
+
* for direct browser calls. Some providers gate streaming separately from
|
|
1126
|
+
* non-streaming (rare), so this is tracked independently from
|
|
1127
|
+
* {@link IAiProviderDescriptor.corsRestricted}.
|
|
1128
|
+
*
|
|
1129
|
+
* @remarks
|
|
1130
|
+
* When `true`, `callProviderCompletionStream` rejects up front unless the
|
|
1131
|
+
* call is being routed through a proxy.
|
|
1132
|
+
*/
|
|
1133
|
+
readonly streamingCorsRestricted: boolean;
|
|
1134
|
+
/**
|
|
1135
|
+
* Whether this provider's chat completions API accepts image input
|
|
1136
|
+
* (i.e. supports vision prompts). When false, calls with
|
|
1137
|
+
* `prompt.attachments` are rejected up front.
|
|
1138
|
+
*/
|
|
1139
|
+
readonly acceptsImageInput: boolean;
|
|
1140
|
+
/**
|
|
1141
|
+
* Which image-generation API format this provider uses, or undefined if it
|
|
1142
|
+
* does not support image generation.
|
|
1143
|
+
*
|
|
1144
|
+
* @remarks
|
|
1145
|
+
* Image-model selection reuses the existing `image` {@link ModelSpecKey}.
|
|
1146
|
+
* Providers with `imageApiFormat` set should declare a model in
|
|
1147
|
+
* `defaultModel.image`, e.g. `{ base: 'gpt-4o', image: 'dall-e-3' }`.
|
|
1148
|
+
*/
|
|
1149
|
+
readonly imageApiFormat?: AiImageApiFormat;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Terminal success event for a streaming completion. Carries the aggregated
|
|
1154
|
+
* full text and truncation status for callers that want both the progressive
|
|
1155
|
+
* UI and the complete result.
|
|
1156
|
+
* @public
|
|
1157
|
+
*/
|
|
1158
|
+
declare interface IAiStreamDone {
|
|
1159
|
+
readonly type: 'done';
|
|
1160
|
+
/** Whether the response was truncated due to token limits. */
|
|
1161
|
+
readonly truncated: boolean;
|
|
1162
|
+
/** The full concatenated text from all `text-delta` events. */
|
|
1163
|
+
readonly fullText: string;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Terminal failure event for a streaming completion. After this event no
|
|
1168
|
+
* further events are emitted.
|
|
1169
|
+
*
|
|
1170
|
+
* @remarks
|
|
1171
|
+
* Connection-time failures (auth, network, pre-flight CORS rejection) are
|
|
1172
|
+
* surfaced via the outer `Result.fail` returned by
|
|
1173
|
+
* `callProviderCompletionStream` rather than as an `error` event, so callers
|
|
1174
|
+
* can distinguish "didn't start" from "started but errored mid-stream."
|
|
1175
|
+
*
|
|
1176
|
+
* @public
|
|
1177
|
+
*/
|
|
1178
|
+
declare interface IAiStreamError {
|
|
1179
|
+
readonly type: 'error';
|
|
1180
|
+
readonly message: string;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* Discriminated union of events emitted by a streaming completion.
|
|
1185
|
+
* @public
|
|
1186
|
+
*/
|
|
1187
|
+
declare type IAiStreamEvent = IAiStreamTextDelta | IAiStreamToolEvent | IAiStreamDone | IAiStreamError;
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* A text-content delta arriving during a streaming completion.
|
|
1191
|
+
* @public
|
|
1192
|
+
*/
|
|
1193
|
+
declare interface IAiStreamTextDelta {
|
|
1194
|
+
readonly type: 'text-delta';
|
|
1195
|
+
/** The newly arrived text fragment. */
|
|
1196
|
+
readonly delta: string;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* A server-side tool progress event arriving during a streaming completion.
|
|
1201
|
+
* Surfaced for providers that emit explicit tool-progress markers (OpenAI
|
|
1202
|
+
* Responses API, Anthropic). Gemini's grounding doesn't emit these.
|
|
1203
|
+
* @public
|
|
1204
|
+
*/
|
|
1205
|
+
declare interface IAiStreamToolEvent {
|
|
1206
|
+
readonly type: 'tool-event';
|
|
1207
|
+
/** Which server-side tool this event describes. */
|
|
1208
|
+
readonly toolType: AiServerToolType;
|
|
1209
|
+
/** Tool lifecycle phase. */
|
|
1210
|
+
readonly phase: 'started' | 'completed';
|
|
1211
|
+
/**
|
|
1212
|
+
* Optional provider-specific detail. For web_search this is typically the
|
|
1213
|
+
* search query when available; format varies by provider.
|
|
1214
|
+
*/
|
|
1215
|
+
readonly detail?: string;
|
|
790
1216
|
}
|
|
791
1217
|
|
|
792
1218
|
/**
|
|
@@ -1383,6 +1809,79 @@ declare interface IProviderCompletionParams {
|
|
|
1383
1809
|
readonly logger?: Logging.ILogger;
|
|
1384
1810
|
/** Server-side tools to include in the request. Overrides settings-level tool config when provided. */
|
|
1385
1811
|
readonly tools?: ReadonlyArray<AiServerToolConfig>;
|
|
1812
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
1813
|
+
readonly signal?: AbortSignal;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/**
|
|
1817
|
+
* Parameters for a streaming completion request. Structurally identical to
|
|
1818
|
+
* the non-streaming `IProviderCompletionParams`; kept as its own interface
|
|
1819
|
+
* so callers can be explicit about which path they're invoking.
|
|
1820
|
+
*
|
|
1821
|
+
* @public
|
|
1822
|
+
*/
|
|
1823
|
+
declare interface IProviderCompletionStreamParams {
|
|
1824
|
+
/** The provider descriptor */
|
|
1825
|
+
readonly descriptor: IAiProviderDescriptor;
|
|
1826
|
+
/** API key for authentication */
|
|
1827
|
+
readonly apiKey: string;
|
|
1828
|
+
/** The structured prompt to send */
|
|
1829
|
+
readonly prompt: AiPrompt;
|
|
1830
|
+
/**
|
|
1831
|
+
* Prior conversation history to insert between the system prompt and the
|
|
1832
|
+
* prompt's user message. The new user turn (carried by `prompt.user`) is
|
|
1833
|
+
* always sent last, so the wire shape becomes
|
|
1834
|
+
* `[system, ...messagesBefore, user=prompt.user]`.
|
|
1835
|
+
*/
|
|
1836
|
+
readonly messagesBefore?: ReadonlyArray<IChatMessage>;
|
|
1837
|
+
/** Sampling temperature (default: 0.7) */
|
|
1838
|
+
readonly temperature?: number;
|
|
1839
|
+
/** Optional model override — string or context-aware map. */
|
|
1840
|
+
readonly modelOverride?: ModelSpec;
|
|
1841
|
+
/** Optional logger for request/response observability. */
|
|
1842
|
+
readonly logger?: Logging.ILogger;
|
|
1843
|
+
/** Server-side tools to include in the request. */
|
|
1844
|
+
readonly tools?: ReadonlyArray<AiServerToolConfig>;
|
|
1845
|
+
/** Optional abort signal for cancelling the in-flight stream. */
|
|
1846
|
+
readonly signal?: AbortSignal;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* Parameters for an image-generation request.
|
|
1851
|
+
* @public
|
|
1852
|
+
*/
|
|
1853
|
+
declare interface IProviderImageGenerationParams {
|
|
1854
|
+
/** The provider descriptor */
|
|
1855
|
+
readonly descriptor: IAiProviderDescriptor;
|
|
1856
|
+
/** API key for authentication */
|
|
1857
|
+
readonly apiKey: string;
|
|
1858
|
+
/** The image-generation request */
|
|
1859
|
+
readonly params: IAiImageGenerationParams;
|
|
1860
|
+
/** Optional model override — string or context-aware map (uses descriptor.defaultModel.image otherwise) */
|
|
1861
|
+
readonly modelOverride?: ModelSpec;
|
|
1862
|
+
/** Optional logger for request/response observability. */
|
|
1863
|
+
readonly logger?: Logging.ILogger;
|
|
1864
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
1865
|
+
readonly signal?: AbortSignal;
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/**
|
|
1869
|
+
* Parameters for a list-models request.
|
|
1870
|
+
* @public
|
|
1871
|
+
*/
|
|
1872
|
+
declare interface IProviderListModelsParams {
|
|
1873
|
+
/** The provider descriptor */
|
|
1874
|
+
readonly descriptor: IAiProviderDescriptor;
|
|
1875
|
+
/** API key for authentication */
|
|
1876
|
+
readonly apiKey: string;
|
|
1877
|
+
/** Optional capability filter; when set, only models declaring this capability are returned. */
|
|
1878
|
+
readonly capability?: AiModelCapability;
|
|
1879
|
+
/** Optional capability config override (defaults to {@link DEFAULT_MODEL_CAPABILITY_CONFIG}). */
|
|
1880
|
+
readonly capabilityConfig?: IAiModelCapabilityConfig;
|
|
1881
|
+
/** Optional logger for request/response observability. */
|
|
1882
|
+
readonly logger?: Logging.ILogger;
|
|
1883
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
1884
|
+
readonly signal?: AbortSignal;
|
|
1386
1885
|
}
|
|
1387
1886
|
|
|
1388
1887
|
/**
|
|
@@ -1792,6 +2291,20 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
1792
2291
|
* @public
|
|
1793
2292
|
*/
|
|
1794
2293
|
save(password: string): Promise<Result<IKeyStoreFile>>;
|
|
2294
|
+
/**
|
|
2295
|
+
* Saves the key store using a pre-derived key, bypassing PBKDF2 key
|
|
2296
|
+
* derivation. Use this when the derived key has been stored externally
|
|
2297
|
+
* (e.g., in another key store) and the original password is no longer
|
|
2298
|
+
* available.
|
|
2299
|
+
*
|
|
2300
|
+
* The supplied key must be the same key that was (or would be) derived
|
|
2301
|
+
* from the master password using the key store's PBKDF2 parameters.
|
|
2302
|
+
*
|
|
2303
|
+
* @param derivedKey - The pre-derived master key (32 bytes for AES-256)
|
|
2304
|
+
* @returns Success with IKeyStoreFile, Failure if locked or key invalid
|
|
2305
|
+
* @public
|
|
2306
|
+
*/
|
|
2307
|
+
saveWithKey(derivedKey: Uint8Array): Promise<Result<IKeyStoreFile>>;
|
|
1795
2308
|
/**
|
|
1796
2309
|
* Changes the master password.
|
|
1797
2310
|
* Re-encrypts the vault with the new password-derived key.
|
|
@@ -1816,6 +2329,11 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
1816
2329
|
* @public
|
|
1817
2330
|
*/
|
|
1818
2331
|
getEncryptionConfig(): Result<Pick<IEncryptionConfig, 'secretProvider' | 'cryptoProvider'>>;
|
|
2332
|
+
/**
|
|
2333
|
+
* Encrypts the vault with a derived key and returns the key store file.
|
|
2334
|
+
* Shared by `save()` and `saveWithKey()`.
|
|
2335
|
+
*/
|
|
2336
|
+
private _encryptVault;
|
|
1819
2337
|
/**
|
|
1820
2338
|
* Decrypts the vault with a derived key and loads secrets into memory.
|
|
1821
2339
|
* Shared by `unlock()` and `unlockWithKey()`.
|
|
@@ -2358,6 +2876,14 @@ declare function templateString(defaultContext?: unknown): Conversion.StringConv
|
|
|
2358
2876
|
*/
|
|
2359
2877
|
declare function toBase64(bytes: Uint8Array): string;
|
|
2360
2878
|
|
|
2879
|
+
/**
|
|
2880
|
+
* Formats an {@link IAiImageData} as a `data:` URL suitable for browser display.
|
|
2881
|
+
* @param image - The image to format
|
|
2882
|
+
* @returns A `data:<mime>;base64,<data>` URL string
|
|
2883
|
+
* @public
|
|
2884
|
+
*/
|
|
2885
|
+
declare function toDataUrl(image: IAiImageData): string;
|
|
2886
|
+
|
|
2361
2887
|
/**
|
|
2362
2888
|
* Attempts to parse and decrypt a JSON object as an {@link CryptoUtils.IEncryptedFile | encrypted file}.
|
|
2363
2889
|
* @typeParam TPayload - Expected type of decrypted content
|
|
@@ -2557,8 +3083,8 @@ declare class ZipFileTreeAccessors<TCT extends string = string> implements FileT
|
|
|
2557
3083
|
private constructor();
|
|
2558
3084
|
/**
|
|
2559
3085
|
* Default function to infer the content type of a file.
|
|
2560
|
-
* @param
|
|
2561
|
-
* @param
|
|
3086
|
+
* @param __filePath - The path of the file.
|
|
3087
|
+
* @param __provided - Optional supplied content type.
|
|
2562
3088
|
* @returns `Success` with the content type of the file if successful, or
|
|
2563
3089
|
* `Failure` with an error message otherwise.
|
|
2564
3090
|
* @remarks This default implementation always returns `Success` with `undefined`.
|
package/lib/index.browser.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as AiAssist from './packlets/ai-assist';
|
|
1
2
|
import * as Crypto from './packlets/crypto-utils/index.browser';
|
|
2
3
|
import * as Csv from './packlets/csv/index.browser';
|
|
3
4
|
import * as Experimental from './packlets/experimental';
|
|
@@ -6,5 +7,5 @@ import * as Mustache from './packlets/mustache';
|
|
|
6
7
|
import * as RecordJar from './packlets/record-jar/index.browser';
|
|
7
8
|
import * as ZipFileTree from './packlets/zip-file-tree';
|
|
8
9
|
import { Converters } from './packlets/conversion';
|
|
9
|
-
export { Converters, Crypto, Csv, Experimental, Hash, Mustache, RecordJar, ZipFileTree };
|
|
10
|
+
export { AiAssist, Converters, Crypto, Csv, Experimental, Hash, Mustache, RecordJar, ZipFileTree };
|
|
10
11
|
//# sourceMappingURL=index.browser.d.ts.map
|
package/lib/index.browser.js
CHANGED
|
@@ -54,8 +54,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
54
54
|
};
|
|
55
55
|
})();
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.ZipFileTree = exports.RecordJar = exports.Mustache = exports.Hash = exports.Experimental = exports.Csv = exports.Crypto = exports.Converters = void 0;
|
|
57
|
+
exports.ZipFileTree = exports.RecordJar = exports.Mustache = exports.Hash = exports.Experimental = exports.Csv = exports.Crypto = exports.Converters = exports.AiAssist = void 0;
|
|
58
58
|
/* c8 ignore start - Browser-specific export used conditionally in package.json */
|
|
59
|
+
const AiAssist = __importStar(require("./packlets/ai-assist"));
|
|
60
|
+
exports.AiAssist = AiAssist;
|
|
59
61
|
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
60
62
|
const Crypto = __importStar(require("./packlets/crypto-utils/index.browser"));
|
|
61
63
|
exports.Crypto = Crypto;
|