@fgv/ts-extras 5.0.2 → 5.1.0-0
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 +6 -2
- package/dist/index.js +5 -1
- package/dist/packlets/ai-assist/apiClient.js +484 -0
- package/dist/packlets/ai-assist/converters.js +121 -0
- package/dist/packlets/ai-assist/index.js +10 -0
- package/dist/packlets/ai-assist/model.js +90 -0
- package/dist/packlets/ai-assist/registry.js +145 -0
- package/dist/packlets/ai-assist/toolFormats.js +160 -0
- package/dist/packlets/crypto-utils/constants.js +48 -0
- package/dist/packlets/crypto-utils/converters.js +155 -0
- package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
- package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
- package/dist/packlets/crypto-utils/index.browser.js +41 -0
- package/dist/packlets/crypto-utils/index.js +41 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
- package/dist/packlets/crypto-utils/keystore/index.js +31 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
- package/dist/packlets/crypto-utils/keystore/model.js +64 -0
- package/dist/packlets/crypto-utils/model.js +39 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
- package/dist/packlets/experimental/formatter.js +1 -1
- package/dist/packlets/mustache/index.js +23 -0
- package/dist/packlets/mustache/interfaces.js +25 -0
- package/dist/packlets/mustache/mustacheTemplate.js +242 -0
- package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
- package/dist/packlets/yaml/converters.js +46 -0
- package/dist/packlets/yaml/index.js +23 -0
- package/dist/packlets/zip-file-tree/index.js +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +43 -2
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
- package/dist/ts-extras.d.ts +1990 -112
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +3 -1
- package/lib/index.browser.js +6 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -1
- package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
- package/lib/packlets/ai-assist/apiClient.js +488 -0
- package/lib/packlets/ai-assist/converters.d.ts +55 -0
- package/lib/packlets/ai-assist/converters.js +124 -0
- package/lib/packlets/ai-assist/index.d.ts +10 -0
- package/lib/packlets/ai-assist/index.js +33 -0
- package/lib/packlets/ai-assist/model.d.ts +222 -0
- package/lib/packlets/ai-assist/model.js +95 -0
- package/lib/packlets/ai-assist/registry.d.ts +25 -0
- package/lib/packlets/ai-assist/registry.js +150 -0
- package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
- package/lib/packlets/ai-assist/toolFormats.js +166 -0
- package/lib/packlets/crypto-utils/constants.d.ts +26 -0
- package/lib/packlets/crypto-utils/constants.js +51 -0
- package/lib/packlets/crypto-utils/converters.d.ts +58 -0
- package/lib/packlets/crypto-utils/converters.js +192 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
- package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
- package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
- package/lib/packlets/crypto-utils/index.browser.js +91 -0
- package/lib/packlets/crypto-utils/index.d.ts +15 -0
- package/lib/packlets/crypto-utils/index.js +88 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
- package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
- package/lib/packlets/crypto-utils/keystore/index.js +71 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
- package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
- package/lib/packlets/crypto-utils/keystore/model.js +68 -0
- package/lib/packlets/crypto-utils/model.d.ts +236 -0
- package/lib/packlets/crypto-utils/model.js +76 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
- package/lib/packlets/experimental/formatter.d.ts +1 -1
- package/lib/packlets/experimental/formatter.js +1 -1
- package/lib/packlets/mustache/index.d.ts +3 -0
- package/lib/packlets/mustache/index.js +27 -0
- package/lib/packlets/mustache/interfaces.d.ts +97 -0
- package/lib/packlets/mustache/interfaces.js +26 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
- package/lib/packlets/mustache/mustacheTemplate.js +249 -0
- package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
- package/lib/packlets/yaml/converters.d.ts +9 -0
- package/lib/packlets/yaml/converters.js +82 -0
- package/lib/packlets/yaml/index.d.ts +2 -0
- package/lib/packlets/yaml/index.js +39 -0
- package/lib/packlets/zip-file-tree/index.d.ts +1 -0
- package/lib/packlets/zip-file-tree/index.js +15 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +31 -2
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +42 -1
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
- package/package.json +37 -18
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Erik Fortune
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.allProviderIds = void 0;
|
|
23
|
+
exports.getProviderDescriptors = getProviderDescriptors;
|
|
24
|
+
exports.getProviderDescriptor = getProviderDescriptor;
|
|
25
|
+
/**
|
|
26
|
+
* Centralized provider registry — single source of truth for all AI provider metadata.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Built-in providers
|
|
32
|
+
// ============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* All known AI provider descriptors. Copy-paste first, then alphabetical.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
const BUILTIN_PROVIDERS = [
|
|
38
|
+
{
|
|
39
|
+
id: 'copy-paste',
|
|
40
|
+
label: 'Copy / Paste',
|
|
41
|
+
buttonLabel: 'AI Assist | Copy',
|
|
42
|
+
needsSecret: false,
|
|
43
|
+
apiFormat: 'openai',
|
|
44
|
+
baseUrl: '',
|
|
45
|
+
defaultModel: '',
|
|
46
|
+
supportedTools: [],
|
|
47
|
+
corsRestricted: false
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'anthropic',
|
|
51
|
+
label: 'Anthropic Claude',
|
|
52
|
+
buttonLabel: 'AI Assist | Claude',
|
|
53
|
+
needsSecret: true,
|
|
54
|
+
apiFormat: 'anthropic',
|
|
55
|
+
baseUrl: 'https://api.anthropic.com/v1',
|
|
56
|
+
defaultModel: 'claude-sonnet-4-5-20250929',
|
|
57
|
+
supportedTools: ['web_search'],
|
|
58
|
+
corsRestricted: false
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'google-gemini',
|
|
62
|
+
label: 'Google Gemini',
|
|
63
|
+
buttonLabel: 'AI Assist | Gemini',
|
|
64
|
+
needsSecret: true,
|
|
65
|
+
apiFormat: 'gemini',
|
|
66
|
+
baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
|
|
67
|
+
defaultModel: 'gemini-2.5-flash',
|
|
68
|
+
supportedTools: ['web_search'],
|
|
69
|
+
corsRestricted: false
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'groq',
|
|
73
|
+
label: 'Groq',
|
|
74
|
+
buttonLabel: 'AI Assist | Groq',
|
|
75
|
+
needsSecret: true,
|
|
76
|
+
apiFormat: 'openai',
|
|
77
|
+
baseUrl: 'https://api.groq.com/openai/v1',
|
|
78
|
+
defaultModel: 'llama-3.3-70b-versatile',
|
|
79
|
+
supportedTools: [],
|
|
80
|
+
corsRestricted: false
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'mistral',
|
|
84
|
+
label: 'Mistral',
|
|
85
|
+
buttonLabel: 'AI Assist | Mistral',
|
|
86
|
+
needsSecret: true,
|
|
87
|
+
apiFormat: 'openai',
|
|
88
|
+
baseUrl: 'https://api.mistral.ai/v1',
|
|
89
|
+
defaultModel: 'mistral-large-latest',
|
|
90
|
+
supportedTools: [],
|
|
91
|
+
corsRestricted: false
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'openai',
|
|
95
|
+
label: 'OpenAI',
|
|
96
|
+
buttonLabel: 'AI Assist | OpenAI',
|
|
97
|
+
needsSecret: true,
|
|
98
|
+
apiFormat: 'openai',
|
|
99
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
100
|
+
defaultModel: 'gpt-4o',
|
|
101
|
+
supportedTools: ['web_search'],
|
|
102
|
+
corsRestricted: false
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'xai-grok',
|
|
106
|
+
label: 'xAI Grok',
|
|
107
|
+
buttonLabel: 'AI Assist | Grok',
|
|
108
|
+
needsSecret: true,
|
|
109
|
+
apiFormat: 'openai',
|
|
110
|
+
baseUrl: 'https://api.x.ai/v1',
|
|
111
|
+
defaultModel: { base: 'grok-4-1-fast', tools: 'grok-4-1-fast-reasoning' },
|
|
112
|
+
supportedTools: ['web_search'],
|
|
113
|
+
corsRestricted: true
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
/**
|
|
117
|
+
* Index for O(1) lookup by id.
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
const PROVIDER_BY_ID = new Map(BUILTIN_PROVIDERS.map((d) => [d.id, d]));
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Public API
|
|
123
|
+
// ============================================================================
|
|
124
|
+
/**
|
|
125
|
+
* All valid provider ID values, in the same order as the registry.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
exports.allProviderIds = BUILTIN_PROVIDERS.map((d) => d.id);
|
|
129
|
+
/**
|
|
130
|
+
* Get all known provider descriptors. Copy-paste first, then alphabetical.
|
|
131
|
+
* @returns All built-in provider descriptors
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
function getProviderDescriptors() {
|
|
135
|
+
return BUILTIN_PROVIDERS;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get a provider descriptor by id.
|
|
139
|
+
* @param id - The provider identifier
|
|
140
|
+
* @returns The descriptor, or a failure if the provider is unknown
|
|
141
|
+
* @public
|
|
142
|
+
*/
|
|
143
|
+
function getProviderDescriptor(id) {
|
|
144
|
+
const descriptor = PROVIDER_BY_ID.get(id);
|
|
145
|
+
if (!descriptor) {
|
|
146
|
+
return (0, ts_utils_1.fail)(`unknown AI provider: ${id}`);
|
|
147
|
+
}
|
|
148
|
+
return (0, ts_utils_1.succeed)(descriptor);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific tool format translation and tool resolution logic.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import { type JsonObject } from '@fgv/ts-json-base';
|
|
6
|
+
import { type AiServerToolConfig, type IAiProviderDescriptor, type IAiToolEnablement } from './model';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the effective tools for a completion call.
|
|
9
|
+
*
|
|
10
|
+
* - If per-call tools are provided, they override settings-level tools entirely.
|
|
11
|
+
* - Otherwise, settings-level enabled tools are used.
|
|
12
|
+
* - Only tools supported by the provider are included.
|
|
13
|
+
* - Returns an empty array if no tools are enabled (= no tools sent).
|
|
14
|
+
*
|
|
15
|
+
* @param descriptor - The provider descriptor (used to filter by supported tools)
|
|
16
|
+
* @param settingsTools - Tool enablement from provider settings (optional)
|
|
17
|
+
* @param perCallTools - Per-call tool override (optional)
|
|
18
|
+
* @returns The resolved list of tool configs to include in the request
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveEffectiveTools(descriptor: IAiProviderDescriptor, settingsTools?: ReadonlyArray<IAiToolEnablement>, perCallTools?: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<AiServerToolConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* Formats tool configs for the xAI/OpenAI Responses API.
|
|
24
|
+
* @param tools - The resolved tool configs
|
|
25
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function toResponsesApiTools(tools: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<JsonObject>;
|
|
29
|
+
/**
|
|
30
|
+
* Formats tool configs for the Anthropic Messages API.
|
|
31
|
+
* @param tools - The resolved tool configs
|
|
32
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare function toAnthropicTools(tools: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<JsonObject>;
|
|
36
|
+
/**
|
|
37
|
+
* Formats tool configs for the Gemini generateContent API.
|
|
38
|
+
* Gemini uses `google_search` for search grounding — no per-tool config options.
|
|
39
|
+
* @param tools - The resolved tool configs
|
|
40
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export declare function toGeminiTools(tools: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<JsonObject>;
|
|
44
|
+
//# sourceMappingURL=toolFormats.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Erik Fortune
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.resolveEffectiveTools = resolveEffectiveTools;
|
|
23
|
+
exports.toResponsesApiTools = toResponsesApiTools;
|
|
24
|
+
exports.toAnthropicTools = toAnthropicTools;
|
|
25
|
+
exports.toGeminiTools = toGeminiTools;
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Tool resolution
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the effective tools for a completion call.
|
|
31
|
+
*
|
|
32
|
+
* - If per-call tools are provided, they override settings-level tools entirely.
|
|
33
|
+
* - Otherwise, settings-level enabled tools are used.
|
|
34
|
+
* - Only tools supported by the provider are included.
|
|
35
|
+
* - Returns an empty array if no tools are enabled (= no tools sent).
|
|
36
|
+
*
|
|
37
|
+
* @param descriptor - The provider descriptor (used to filter by supported tools)
|
|
38
|
+
* @param settingsTools - Tool enablement from provider settings (optional)
|
|
39
|
+
* @param perCallTools - Per-call tool override (optional)
|
|
40
|
+
* @returns The resolved list of tool configs to include in the request
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
function resolveEffectiveTools(descriptor, settingsTools, perCallTools) {
|
|
44
|
+
const supported = new Set(descriptor.supportedTools);
|
|
45
|
+
if (perCallTools !== undefined) {
|
|
46
|
+
return perCallTools.filter((t) => supported.has(t.type));
|
|
47
|
+
}
|
|
48
|
+
if (settingsTools === undefined) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return settingsTools
|
|
52
|
+
.filter((e) => e.enabled && supported.has(e.type))
|
|
53
|
+
.map((e) => { var _a; return (_a = e.config) !== null && _a !== void 0 ? _a : { type: e.type }; });
|
|
54
|
+
}
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// OpenAI / xAI Responses API format
|
|
57
|
+
// ============================================================================
|
|
58
|
+
/**
|
|
59
|
+
* Formats a web search tool config for the xAI/OpenAI Responses API.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
function webSearchToResponsesApi(config) {
|
|
63
|
+
const tool = { type: 'web_search' };
|
|
64
|
+
if (config.allowedDomains || config.blockedDomains) {
|
|
65
|
+
const filters = {};
|
|
66
|
+
if (config.allowedDomains) {
|
|
67
|
+
filters.allowed_domains = [...config.allowedDomains];
|
|
68
|
+
}
|
|
69
|
+
if (config.blockedDomains) {
|
|
70
|
+
filters.excluded_domains = [...config.blockedDomains];
|
|
71
|
+
}
|
|
72
|
+
tool.filters = filters;
|
|
73
|
+
}
|
|
74
|
+
if (config.enableImageUnderstanding) {
|
|
75
|
+
tool.enable_image_understanding = true;
|
|
76
|
+
}
|
|
77
|
+
return tool;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Formats tool configs for the xAI/OpenAI Responses API.
|
|
81
|
+
* @param tools - The resolved tool configs
|
|
82
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
function toResponsesApiTools(tools) {
|
|
86
|
+
return tools.map((t) => {
|
|
87
|
+
switch (t.type) {
|
|
88
|
+
case 'web_search':
|
|
89
|
+
return webSearchToResponsesApi(t);
|
|
90
|
+
/* c8 ignore next 4 - defensive coding: exhaustive switch guaranteed by TypeScript */
|
|
91
|
+
default: {
|
|
92
|
+
const _exhaustive = t.type;
|
|
93
|
+
return { type: String(_exhaustive) };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// ============================================================================
|
|
99
|
+
// Anthropic Messages API format
|
|
100
|
+
// ============================================================================
|
|
101
|
+
/**
|
|
102
|
+
* Formats a web search tool config for the Anthropic Messages API.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
function webSearchToAnthropic(config) {
|
|
106
|
+
const tool = {
|
|
107
|
+
type: 'web_search_20250305',
|
|
108
|
+
name: 'web_search'
|
|
109
|
+
};
|
|
110
|
+
if (config.maxUses !== undefined) {
|
|
111
|
+
tool.max_uses = config.maxUses;
|
|
112
|
+
}
|
|
113
|
+
if (config.allowedDomains) {
|
|
114
|
+
tool.allowed_domains = [...config.allowedDomains];
|
|
115
|
+
}
|
|
116
|
+
if (config.blockedDomains) {
|
|
117
|
+
tool.blocked_domains = [...config.blockedDomains];
|
|
118
|
+
}
|
|
119
|
+
return tool;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Formats tool configs for the Anthropic Messages API.
|
|
123
|
+
* @param tools - The resolved tool configs
|
|
124
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
function toAnthropicTools(tools) {
|
|
128
|
+
return tools.map((t) => {
|
|
129
|
+
switch (t.type) {
|
|
130
|
+
case 'web_search':
|
|
131
|
+
return webSearchToAnthropic(t);
|
|
132
|
+
/* c8 ignore next 4 - defensive coding: exhaustive switch guaranteed by TypeScript */
|
|
133
|
+
default: {
|
|
134
|
+
const _exhaustive = t.type;
|
|
135
|
+
return { type: String(_exhaustive) };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Gemini generateContent API format
|
|
142
|
+
// ============================================================================
|
|
143
|
+
/**
|
|
144
|
+
* Formats tool configs for the Gemini generateContent API.
|
|
145
|
+
* Gemini uses `google_search` for search grounding — no per-tool config options.
|
|
146
|
+
* @param tools - The resolved tool configs
|
|
147
|
+
* @returns Provider-native tool objects for the `tools` request field
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
function toGeminiTools(tools) {
|
|
151
|
+
const result = [];
|
|
152
|
+
for (const t of tools) {
|
|
153
|
+
switch (t.type) {
|
|
154
|
+
case 'web_search':
|
|
155
|
+
result.push({ google_search: {} });
|
|
156
|
+
break;
|
|
157
|
+
/* c8 ignore next 4 - defensive coding: exhaustive switch guaranteed by TypeScript */
|
|
158
|
+
default: {
|
|
159
|
+
const _exhaustive = t.type;
|
|
160
|
+
result.push({ type: String(_exhaustive) });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=toolFormats.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current format version for encrypted files.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare const ENCRYPTED_FILE_FORMAT: "encrypted-collection-v1";
|
|
6
|
+
/**
|
|
7
|
+
* Default encryption algorithm.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_ALGORITHM: "AES-256-GCM";
|
|
11
|
+
/**
|
|
12
|
+
* Key size in bytes for AES-256.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare const AES_256_KEY_SIZE: number;
|
|
16
|
+
/**
|
|
17
|
+
* IV size in bytes for GCM mode.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare const GCM_IV_SIZE: number;
|
|
21
|
+
/**
|
|
22
|
+
* Auth tag size in bytes for GCM mode.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const GCM_AUTH_TAG_SIZE: number;
|
|
26
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2024 Erik Fortune
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.GCM_AUTH_TAG_SIZE = exports.GCM_IV_SIZE = exports.AES_256_KEY_SIZE = exports.DEFAULT_ALGORITHM = exports.ENCRYPTED_FILE_FORMAT = void 0;
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Constants
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Current format version for encrypted files.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
exports.ENCRYPTED_FILE_FORMAT = 'encrypted-collection-v1';
|
|
31
|
+
/**
|
|
32
|
+
* Default encryption algorithm.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
exports.DEFAULT_ALGORITHM = 'AES-256-GCM';
|
|
36
|
+
/**
|
|
37
|
+
* Key size in bytes for AES-256.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
exports.AES_256_KEY_SIZE = 32;
|
|
41
|
+
/**
|
|
42
|
+
* IV size in bytes for GCM mode.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
exports.GCM_IV_SIZE = 12;
|
|
46
|
+
/**
|
|
47
|
+
* Auth tag size in bytes for GCM mode.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
exports.GCM_AUTH_TAG_SIZE = 16;
|
|
51
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { Converter } from '@fgv/ts-utils';
|
|
3
|
+
import { EncryptedFileErrorMode, EncryptedFileFormat, EncryptionAlgorithm, IEncryptedFile, IKeyDerivationParams, INamedSecret, KeyDerivationFunction } from './model';
|
|
4
|
+
/**
|
|
5
|
+
* Converter for {@link CryptoUtils.EncryptionAlgorithm | encryption algorithm} values.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const encryptionAlgorithm: Converter<EncryptionAlgorithm>;
|
|
9
|
+
/**
|
|
10
|
+
* Converter for {@link CryptoUtils.EncryptedFileFormat | encrypted file format} version.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare const encryptedFileFormat: Converter<EncryptedFileFormat>;
|
|
14
|
+
/**
|
|
15
|
+
* Converter for {@link CryptoUtils.EncryptedFileErrorMode | encrypted file error mode}.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare const encryptedFileErrorMode: Converter<EncryptedFileErrorMode>;
|
|
19
|
+
/**
|
|
20
|
+
* Converter for {@link CryptoUtils.KeyDerivationFunction | key derivation function} type.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const keyDerivationFunction: Converter<KeyDerivationFunction>;
|
|
24
|
+
/**
|
|
25
|
+
* Converter for {@link CryptoUtils.IKeyDerivationParams | key derivation parameters}.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const keyDerivationParams: Converter<IKeyDerivationParams>;
|
|
29
|
+
/**
|
|
30
|
+
* Converter for base64 strings (validates format).
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare const base64String: Converter<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Converter which converts a base64 string to a Uint8Array.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare const uint8ArrayFromBase64: Converter<Uint8Array>;
|
|
39
|
+
/**
|
|
40
|
+
* Converter for {@link CryptoUtils.INamedSecret | named secret} from JSON representation.
|
|
41
|
+
* Expects key as base64 string in JSON, converts to Uint8Array.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare const namedSecret: Converter<INamedSecret>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a converter for {@link CryptoUtils.IEncryptedFile | encrypted files} with optional typed metadata.
|
|
47
|
+
* @typeParam TMetadata - Type of optional unencrypted metadata
|
|
48
|
+
* @param metadataConverter - Optional converter for validating metadata field
|
|
49
|
+
* @returns A converter that validates and converts encrypted file structures
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare function createEncryptedFileConverter<TMetadata = JsonValue>(metadataConverter?: Converter<TMetadata>): Converter<IEncryptedFile<TMetadata>>;
|
|
53
|
+
/**
|
|
54
|
+
* Default converter for encrypted files without typed metadata.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare const encryptedFile: Converter<IEncryptedFile>;
|
|
58
|
+
//# sourceMappingURL=converters.d.ts.map
|