@fgv/ts-extras 5.1.0-16 → 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/zip-file-tree/zipFileTreeAccessors.js +2 -2
- package/dist/ts-extras.d.ts +512 -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/zip-file-tree/zipFileTreeAccessors.d.ts +2 -2
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Logging, Result } from '@fgv/ts-utils';
|
|
2
|
-
import { AiPrompt, type AiServerToolConfig, type IAiCompletionResponse, type IAiProviderDescriptor, type IChatMessage, type ModelSpec } from './model';
|
|
2
|
+
import { AiPrompt, type AiModelCapability, type AiServerToolConfig, type IAiCompletionResponse, type IAiImageGenerationParams, type IAiImageGenerationResponse, type IAiModelCapabilityConfig, type IAiModelInfo, type IAiProviderDescriptor, type IChatMessage, type ModelSpec } from './model';
|
|
3
3
|
/**
|
|
4
4
|
* Parameters for a provider completion request.
|
|
5
5
|
* @public
|
|
@@ -24,6 +24,8 @@ export interface IProviderCompletionParams {
|
|
|
24
24
|
readonly logger?: Logging.ILogger;
|
|
25
25
|
/** Server-side tools to include in the request. Overrides settings-level tool config when provided. */
|
|
26
26
|
readonly tools?: ReadonlyArray<AiServerToolConfig>;
|
|
27
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Calls the appropriate chat completion API for a given provider.
|
|
@@ -43,6 +45,86 @@ export interface IProviderCompletionParams {
|
|
|
43
45
|
* @public
|
|
44
46
|
*/
|
|
45
47
|
export declare function callProviderCompletion(params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for an image-generation request.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface IProviderImageGenerationParams {
|
|
53
|
+
/** The provider descriptor */
|
|
54
|
+
readonly descriptor: IAiProviderDescriptor;
|
|
55
|
+
/** API key for authentication */
|
|
56
|
+
readonly apiKey: string;
|
|
57
|
+
/** The image-generation request */
|
|
58
|
+
readonly params: IAiImageGenerationParams;
|
|
59
|
+
/** Optional model override — string or context-aware map (uses descriptor.defaultModel.image otherwise) */
|
|
60
|
+
readonly modelOverride?: ModelSpec;
|
|
61
|
+
/** Optional logger for request/response observability. */
|
|
62
|
+
readonly logger?: Logging.ILogger;
|
|
63
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
64
|
+
readonly signal?: AbortSignal;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calls the appropriate image-generation API for a given provider.
|
|
68
|
+
*
|
|
69
|
+
* Routes based on `descriptor.imageApiFormat`:
|
|
70
|
+
* - `'openai-images'` for OpenAI (DALL-E, gpt-image-1)
|
|
71
|
+
* - `'xai-images'` for xAI Grok image models
|
|
72
|
+
* - `'gemini-imagen'` for Google Imagen
|
|
73
|
+
*
|
|
74
|
+
* Image-model selection reuses the existing `'image'` {@link ModelSpecKey}.
|
|
75
|
+
*
|
|
76
|
+
* @param params - Request parameters including descriptor, API key, and prompt
|
|
77
|
+
* @returns The generated images, or a failure
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare function callProviderImageGeneration(params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
|
|
81
|
+
/**
|
|
82
|
+
* Parameters for a list-models request.
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export interface IProviderListModelsParams {
|
|
86
|
+
/** The provider descriptor */
|
|
87
|
+
readonly descriptor: IAiProviderDescriptor;
|
|
88
|
+
/** API key for authentication */
|
|
89
|
+
readonly apiKey: string;
|
|
90
|
+
/** Optional capability filter; when set, only models declaring this capability are returned. */
|
|
91
|
+
readonly capability?: AiModelCapability;
|
|
92
|
+
/** Optional capability config override (defaults to {@link DEFAULT_MODEL_CAPABILITY_CONFIG}). */
|
|
93
|
+
readonly capabilityConfig?: IAiModelCapabilityConfig;
|
|
94
|
+
/** Optional logger for request/response observability. */
|
|
95
|
+
readonly logger?: Logging.ILogger;
|
|
96
|
+
/** Optional abort signal for cancelling the in-flight request. */
|
|
97
|
+
readonly signal?: AbortSignal;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Lists models available from a provider, with capabilities resolved from
|
|
101
|
+
* native provider info (where supplied) and a configurable rule set.
|
|
102
|
+
*
|
|
103
|
+
* Routes based on `descriptor.apiFormat` — listing reuses the existing
|
|
104
|
+
* format dispatch and does not require a separate descriptor field.
|
|
105
|
+
*
|
|
106
|
+
* @param params - Request parameters including descriptor, API key, and optional capability filter
|
|
107
|
+
* @returns The resolved model list, or a failure
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
export declare function callProviderListModels(params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
|
|
111
|
+
/**
|
|
112
|
+
* Calls the model-listing endpoint on a proxy server.
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* Proxy contract:
|
|
116
|
+
* - Endpoint: `POST ${proxyUrl}/api/ai/list-models`
|
|
117
|
+
* - Request body: `{providerId, apiKey, capability?}`. Capability config is
|
|
118
|
+
* not forwarded — the proxy applies its own (typically the same default
|
|
119
|
+
* the library ships).
|
|
120
|
+
* - Success response body: an `IAiModelInfo[]` (under key `models`) where
|
|
121
|
+
* `capabilities` is serialized as a string array (not Set, which doesn't
|
|
122
|
+
* round-trip through JSON).
|
|
123
|
+
* - Error response body: `{error: string}`, surfaced as `proxy: ${error}`.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export declare function callProxiedListModels(proxyUrl: string, params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
|
|
46
128
|
/**
|
|
47
129
|
* Calls the AI completion endpoint on a proxy server instead of calling
|
|
48
130
|
* the provider API directly from the browser.
|
|
@@ -57,4 +139,24 @@ export declare function callProviderCompletion(params: IProviderCompletionParams
|
|
|
57
139
|
* @public
|
|
58
140
|
*/
|
|
59
141
|
export declare function callProxiedCompletion(proxyUrl: string, params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
|
|
142
|
+
/**
|
|
143
|
+
* Calls the image-generation endpoint on a proxy server instead of calling
|
|
144
|
+
* the provider API directly from the browser.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* The proxy contract:
|
|
148
|
+
* - Endpoint: `POST ${proxyUrl}/api/ai/image-generation`
|
|
149
|
+
* - Request body: `{providerId, apiKey, params, modelOverride?}`
|
|
150
|
+
* - Success response body: an {@link IAiImageGenerationResponse}
|
|
151
|
+
* - Error response body: `{error: string}` (surfaced as `proxy: ${error}`)
|
|
152
|
+
*
|
|
153
|
+
* The proxy server is responsible for descriptor lookup, model resolution,
|
|
154
|
+
* provider dispatch, and response normalization.
|
|
155
|
+
*
|
|
156
|
+
* @param proxyUrl - Base URL of the proxy server (e.g. `http://localhost:3001`)
|
|
157
|
+
* @param params - Same parameters as {@link callProviderImageGeneration}
|
|
158
|
+
* @returns The generated images, or a failure
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export declare function callProxiedImageGeneration(proxyUrl: string, params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
|
|
60
162
|
//# sourceMappingURL=apiClient.d.ts.map
|