@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.
Files changed (92) hide show
  1. package/dist/index.browser.js +6 -2
  2. package/dist/index.js +5 -1
  3. package/dist/packlets/ai-assist/apiClient.js +484 -0
  4. package/dist/packlets/ai-assist/converters.js +121 -0
  5. package/dist/packlets/ai-assist/index.js +10 -0
  6. package/dist/packlets/ai-assist/model.js +90 -0
  7. package/dist/packlets/ai-assist/registry.js +145 -0
  8. package/dist/packlets/ai-assist/toolFormats.js +160 -0
  9. package/dist/packlets/crypto-utils/constants.js +48 -0
  10. package/dist/packlets/crypto-utils/converters.js +155 -0
  11. package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
  12. package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
  13. package/dist/packlets/crypto-utils/index.browser.js +41 -0
  14. package/dist/packlets/crypto-utils/index.js +41 -0
  15. package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
  16. package/dist/packlets/crypto-utils/keystore/index.js +31 -0
  17. package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
  18. package/dist/packlets/crypto-utils/keystore/model.js +64 -0
  19. package/dist/packlets/crypto-utils/model.js +39 -0
  20. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
  21. package/dist/packlets/experimental/formatter.js +1 -1
  22. package/dist/packlets/mustache/index.js +23 -0
  23. package/dist/packlets/mustache/interfaces.js +25 -0
  24. package/dist/packlets/mustache/mustacheTemplate.js +242 -0
  25. package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
  26. package/dist/packlets/yaml/converters.js +46 -0
  27. package/dist/packlets/yaml/index.js +23 -0
  28. package/dist/packlets/zip-file-tree/index.js +1 -0
  29. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +43 -2
  30. package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
  31. package/dist/ts-extras.d.ts +1990 -112
  32. package/dist/tsdoc-metadata.json +1 -1
  33. package/lib/index.browser.d.ts +3 -1
  34. package/lib/index.browser.js +6 -1
  35. package/lib/index.d.ts +5 -1
  36. package/lib/index.js +9 -1
  37. package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
  38. package/lib/packlets/ai-assist/apiClient.js +488 -0
  39. package/lib/packlets/ai-assist/converters.d.ts +55 -0
  40. package/lib/packlets/ai-assist/converters.js +124 -0
  41. package/lib/packlets/ai-assist/index.d.ts +10 -0
  42. package/lib/packlets/ai-assist/index.js +33 -0
  43. package/lib/packlets/ai-assist/model.d.ts +222 -0
  44. package/lib/packlets/ai-assist/model.js +95 -0
  45. package/lib/packlets/ai-assist/registry.d.ts +25 -0
  46. package/lib/packlets/ai-assist/registry.js +150 -0
  47. package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
  48. package/lib/packlets/ai-assist/toolFormats.js +166 -0
  49. package/lib/packlets/crypto-utils/constants.d.ts +26 -0
  50. package/lib/packlets/crypto-utils/constants.js +51 -0
  51. package/lib/packlets/crypto-utils/converters.d.ts +58 -0
  52. package/lib/packlets/crypto-utils/converters.js +192 -0
  53. package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
  54. package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
  55. package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
  56. package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
  57. package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
  58. package/lib/packlets/crypto-utils/index.browser.js +91 -0
  59. package/lib/packlets/crypto-utils/index.d.ts +15 -0
  60. package/lib/packlets/crypto-utils/index.js +88 -0
  61. package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
  62. package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
  63. package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
  64. package/lib/packlets/crypto-utils/keystore/index.js +71 -0
  65. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
  66. package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
  67. package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
  68. package/lib/packlets/crypto-utils/keystore/model.js +68 -0
  69. package/lib/packlets/crypto-utils/model.d.ts +236 -0
  70. package/lib/packlets/crypto-utils/model.js +76 -0
  71. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
  72. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
  73. package/lib/packlets/experimental/formatter.d.ts +1 -1
  74. package/lib/packlets/experimental/formatter.js +1 -1
  75. package/lib/packlets/mustache/index.d.ts +3 -0
  76. package/lib/packlets/mustache/index.js +27 -0
  77. package/lib/packlets/mustache/interfaces.d.ts +97 -0
  78. package/lib/packlets/mustache/interfaces.js +26 -0
  79. package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
  80. package/lib/packlets/mustache/mustacheTemplate.js +249 -0
  81. package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
  82. package/lib/packlets/yaml/converters.d.ts +9 -0
  83. package/lib/packlets/yaml/converters.js +82 -0
  84. package/lib/packlets/yaml/index.d.ts +2 -0
  85. package/lib/packlets/yaml/index.js +39 -0
  86. package/lib/packlets/zip-file-tree/index.d.ts +1 -0
  87. package/lib/packlets/zip-file-tree/index.js +15 -0
  88. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +31 -2
  89. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +42 -1
  90. package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
  91. package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
  92. package/package.json +37 -18
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Converters for AI assist settings types.
3
+ * @packageDocumentation
4
+ */
5
+ import { type Converter } from '@fgv/ts-utils';
6
+ import { type AiProviderId, type AiServerToolConfig, type AiServerToolType, type IAiAssistProviderConfig, type IAiAssistSettings, type IAiToolEnablement, type IAiWebSearchToolConfig, type ModelSpec, type ModelSpecKey } from './model';
7
+ /**
8
+ * Converter for {@link AiProviderId}.
9
+ * @public
10
+ */
11
+ export declare const aiProviderId: Converter<AiProviderId>;
12
+ /**
13
+ * Converter for {@link AiServerToolType}.
14
+ * @public
15
+ */
16
+ export declare const aiServerToolType: Converter<AiServerToolType>;
17
+ /**
18
+ * Converter for {@link IAiWebSearchToolConfig}.
19
+ * @public
20
+ */
21
+ export declare const aiWebSearchToolConfig: Converter<IAiWebSearchToolConfig>;
22
+ /**
23
+ * Converter for {@link AiServerToolConfig} (discriminated union on `type`).
24
+ * @public
25
+ */
26
+ export declare const aiServerToolConfig: Converter<AiServerToolConfig>;
27
+ /**
28
+ * Converter for {@link IAiToolEnablement}.
29
+ * @public
30
+ */
31
+ export declare const aiToolEnablement: Converter<IAiToolEnablement>;
32
+ /**
33
+ * Converter for {@link ModelSpecKey}.
34
+ * @public
35
+ */
36
+ export declare const modelSpecKey: Converter<ModelSpecKey>;
37
+ /**
38
+ * Recursive converter for {@link ModelSpec}.
39
+ * Accepts a string or an object whose values are themselves ModelSpec values,
40
+ * with keys constrained to known {@link ModelSpecKey} values.
41
+ * Uses the `self` parameter from `Converters.generic` for recursion.
42
+ * @public
43
+ */
44
+ export declare const modelSpec: Converter<ModelSpec>;
45
+ /**
46
+ * Converter for {@link IAiAssistProviderConfig}.
47
+ * @public
48
+ */
49
+ export declare const aiAssistProviderConfig: Converter<IAiAssistProviderConfig>;
50
+ /**
51
+ * Converter for {@link IAiAssistSettings}.
52
+ * @public
53
+ */
54
+ export declare const aiAssistSettings: Converter<IAiAssistSettings>;
55
+ //# sourceMappingURL=converters.d.ts.map
@@ -0,0 +1,124 @@
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.aiAssistSettings = exports.aiAssistProviderConfig = exports.modelSpec = exports.modelSpecKey = exports.aiToolEnablement = exports.aiServerToolConfig = exports.aiWebSearchToolConfig = exports.aiServerToolType = exports.aiProviderId = void 0;
23
+ /**
24
+ * Converters for AI assist settings types.
25
+ * @packageDocumentation
26
+ */
27
+ const ts_utils_1 = require("@fgv/ts-utils");
28
+ const model_1 = require("./model");
29
+ const registry_1 = require("./registry");
30
+ // ============================================================================
31
+ // Provider ID
32
+ // ============================================================================
33
+ /**
34
+ * Converter for {@link AiProviderId}.
35
+ * @public
36
+ */
37
+ exports.aiProviderId = ts_utils_1.Converters.enumeratedValue(registry_1.allProviderIds);
38
+ // ============================================================================
39
+ // Server-Side Tool Converters
40
+ // ============================================================================
41
+ /**
42
+ * All known server-side tool type values.
43
+ * @internal
44
+ */
45
+ const allServerToolTypes = ['web_search'];
46
+ /**
47
+ * Converter for {@link AiServerToolType}.
48
+ * @public
49
+ */
50
+ exports.aiServerToolType = ts_utils_1.Converters.enumeratedValue(allServerToolTypes);
51
+ /**
52
+ * Converter for {@link IAiWebSearchToolConfig}.
53
+ * @public
54
+ */
55
+ exports.aiWebSearchToolConfig = ts_utils_1.Converters.strictObject({
56
+ type: ts_utils_1.Converters.enumeratedValue(['web_search']),
57
+ allowedDomains: ts_utils_1.Converters.arrayOf(ts_utils_1.Converters.string).optional(),
58
+ blockedDomains: ts_utils_1.Converters.arrayOf(ts_utils_1.Converters.string).optional(),
59
+ maxUses: ts_utils_1.Converters.number.optional(),
60
+ enableImageUnderstanding: ts_utils_1.Converters.boolean.optional()
61
+ });
62
+ /**
63
+ * Converter for {@link AiServerToolConfig} (discriminated union on `type`).
64
+ * @public
65
+ */
66
+ exports.aiServerToolConfig = ts_utils_1.Converters.discriminatedObject('type', {
67
+ web_search: exports.aiWebSearchToolConfig
68
+ });
69
+ /**
70
+ * Converter for {@link IAiToolEnablement}.
71
+ * @public
72
+ */
73
+ exports.aiToolEnablement = ts_utils_1.Converters.strictObject({
74
+ type: exports.aiServerToolType,
75
+ enabled: ts_utils_1.Converters.boolean,
76
+ config: exports.aiServerToolConfig.optional()
77
+ });
78
+ // ============================================================================
79
+ // Model Specification
80
+ // ============================================================================
81
+ /**
82
+ * Converter for {@link ModelSpecKey}.
83
+ * @public
84
+ */
85
+ exports.modelSpecKey = ts_utils_1.Converters.enumeratedValue(model_1.allModelSpecKeys);
86
+ /**
87
+ * Recursive converter for {@link ModelSpec}.
88
+ * Accepts a string or an object whose values are themselves ModelSpec values,
89
+ * with keys constrained to known {@link ModelSpecKey} values.
90
+ * Uses the `self` parameter from `Converters.generic` for recursion.
91
+ * @public
92
+ */
93
+ exports.modelSpec = ts_utils_1.Converters.generic((from, self) => {
94
+ return ts_utils_1.Converters.oneOf([
95
+ ts_utils_1.Converters.string,
96
+ ts_utils_1.Converters.recordOf(self, { keyConverter: exports.modelSpecKey })
97
+ ])
98
+ .withFormattedError(() => 'expected model spec (string or object with keys: base, tools, image)')
99
+ .convert(from);
100
+ });
101
+ // ============================================================================
102
+ // Provider Config & Settings
103
+ // ============================================================================
104
+ /**
105
+ * Converter for {@link IAiAssistProviderConfig}.
106
+ * @public
107
+ */
108
+ exports.aiAssistProviderConfig = ts_utils_1.Converters.strictObject({
109
+ provider: exports.aiProviderId,
110
+ secretName: ts_utils_1.Converters.string.optional(),
111
+ model: exports.modelSpec.optional(),
112
+ tools: ts_utils_1.Converters.arrayOf(exports.aiToolEnablement).optional()
113
+ });
114
+ /**
115
+ * Converter for {@link IAiAssistSettings}.
116
+ * @public
117
+ */
118
+ exports.aiAssistSettings = ts_utils_1.Converters.strictObject({
119
+ providers: ts_utils_1.Converters.arrayOf(exports.aiAssistProviderConfig),
120
+ defaultProvider: exports.aiProviderId.optional(),
121
+ proxyUrl: ts_utils_1.Converters.string.optional(),
122
+ proxyAllProviders: ts_utils_1.Converters.boolean.optional()
123
+ });
124
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * AI assist packlet - provider registry, prompt class, settings, and API client.
3
+ * @packageDocumentation
4
+ */
5
+ export { AiPrompt, type AiProviderId, type AiServerToolType, type AiServerToolConfig, type IAiWebSearchToolConfig, type IAiToolEnablement, type IAiCompletionResponse, type IChatMessage, type AiApiFormat, type IAiProviderDescriptor, type IAiAssistProviderConfig, type IAiAssistSettings, DEFAULT_AI_ASSIST, type IAiAssistKeyStore, type ModelSpec, type ModelSpecKey, type IModelSpecMap, allModelSpecKeys, MODEL_SPEC_BASE_KEY, resolveModel } from './model';
6
+ export { allProviderIds, getProviderDescriptors, getProviderDescriptor } from './registry';
7
+ export { callProviderCompletion, callProxiedCompletion, type IProviderCompletionParams } from './apiClient';
8
+ export { aiProviderId, aiServerToolType, aiWebSearchToolConfig, aiServerToolConfig, aiToolEnablement, aiAssistProviderConfig, aiAssistSettings, modelSpecKey, modelSpec } from './converters';
9
+ export { resolveEffectiveTools } from './toolFormats';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * AI assist packlet - provider registry, prompt class, settings, and API client.
4
+ * @packageDocumentation
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.resolveEffectiveTools = exports.modelSpec = exports.modelSpecKey = exports.aiAssistSettings = exports.aiAssistProviderConfig = exports.aiToolEnablement = exports.aiServerToolConfig = exports.aiWebSearchToolConfig = exports.aiServerToolType = exports.aiProviderId = exports.callProxiedCompletion = exports.callProviderCompletion = exports.getProviderDescriptor = exports.getProviderDescriptors = exports.allProviderIds = exports.resolveModel = exports.MODEL_SPEC_BASE_KEY = exports.allModelSpecKeys = exports.DEFAULT_AI_ASSIST = exports.AiPrompt = void 0;
8
+ var model_1 = require("./model");
9
+ Object.defineProperty(exports, "AiPrompt", { enumerable: true, get: function () { return model_1.AiPrompt; } });
10
+ Object.defineProperty(exports, "DEFAULT_AI_ASSIST", { enumerable: true, get: function () { return model_1.DEFAULT_AI_ASSIST; } });
11
+ Object.defineProperty(exports, "allModelSpecKeys", { enumerable: true, get: function () { return model_1.allModelSpecKeys; } });
12
+ Object.defineProperty(exports, "MODEL_SPEC_BASE_KEY", { enumerable: true, get: function () { return model_1.MODEL_SPEC_BASE_KEY; } });
13
+ Object.defineProperty(exports, "resolveModel", { enumerable: true, get: function () { return model_1.resolveModel; } });
14
+ var registry_1 = require("./registry");
15
+ Object.defineProperty(exports, "allProviderIds", { enumerable: true, get: function () { return registry_1.allProviderIds; } });
16
+ Object.defineProperty(exports, "getProviderDescriptors", { enumerable: true, get: function () { return registry_1.getProviderDescriptors; } });
17
+ Object.defineProperty(exports, "getProviderDescriptor", { enumerable: true, get: function () { return registry_1.getProviderDescriptor; } });
18
+ var apiClient_1 = require("./apiClient");
19
+ Object.defineProperty(exports, "callProviderCompletion", { enumerable: true, get: function () { return apiClient_1.callProviderCompletion; } });
20
+ Object.defineProperty(exports, "callProxiedCompletion", { enumerable: true, get: function () { return apiClient_1.callProxiedCompletion; } });
21
+ var converters_1 = require("./converters");
22
+ Object.defineProperty(exports, "aiProviderId", { enumerable: true, get: function () { return converters_1.aiProviderId; } });
23
+ Object.defineProperty(exports, "aiServerToolType", { enumerable: true, get: function () { return converters_1.aiServerToolType; } });
24
+ Object.defineProperty(exports, "aiWebSearchToolConfig", { enumerable: true, get: function () { return converters_1.aiWebSearchToolConfig; } });
25
+ Object.defineProperty(exports, "aiServerToolConfig", { enumerable: true, get: function () { return converters_1.aiServerToolConfig; } });
26
+ Object.defineProperty(exports, "aiToolEnablement", { enumerable: true, get: function () { return converters_1.aiToolEnablement; } });
27
+ Object.defineProperty(exports, "aiAssistProviderConfig", { enumerable: true, get: function () { return converters_1.aiAssistProviderConfig; } });
28
+ Object.defineProperty(exports, "aiAssistSettings", { enumerable: true, get: function () { return converters_1.aiAssistSettings; } });
29
+ Object.defineProperty(exports, "modelSpecKey", { enumerable: true, get: function () { return converters_1.modelSpecKey; } });
30
+ Object.defineProperty(exports, "modelSpec", { enumerable: true, get: function () { return converters_1.modelSpec; } });
31
+ var toolFormats_1 = require("./toolFormats");
32
+ Object.defineProperty(exports, "resolveEffectiveTools", { enumerable: true, get: function () { return toolFormats_1.resolveEffectiveTools; } });
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Core types for AI assist: prompt class, provider descriptors, settings, and chat messages.
3
+ * @packageDocumentation
4
+ */
5
+ import { type Result } from '@fgv/ts-utils';
6
+ /**
7
+ * A structured AI prompt with system/user split for direct API calls,
8
+ * and a lazily-constructed combined version for copy/paste workflows.
9
+ * @public
10
+ */
11
+ export declare class AiPrompt {
12
+ /** System instructions: schema documentation, format rules, general guidance. */
13
+ readonly system: string;
14
+ /** User request: the specific entity generation request. */
15
+ readonly user: string;
16
+ constructor(user: string, system: string);
17
+ /** Combined single-string version (user + system joined) for copy/paste. */
18
+ get combined(): string;
19
+ }
20
+ /**
21
+ * A single chat message in OpenAI format.
22
+ * @public
23
+ */
24
+ export interface IChatMessage {
25
+ /** Message role */
26
+ readonly role: 'system' | 'user' | 'assistant';
27
+ /** Message content */
28
+ readonly content: string;
29
+ }
30
+ /**
31
+ * Built-in server-side tool types supported across providers.
32
+ * @public
33
+ */
34
+ export type AiServerToolType = 'web_search';
35
+ /**
36
+ * Configuration specific to web search tools.
37
+ * @public
38
+ */
39
+ export interface IAiWebSearchToolConfig {
40
+ readonly type: 'web_search';
41
+ /** Optional: restrict search to these domains. */
42
+ readonly allowedDomains?: ReadonlyArray<string>;
43
+ /** Optional: exclude these domains from search. */
44
+ readonly blockedDomains?: ReadonlyArray<string>;
45
+ /** Optional: max number of searches per request. */
46
+ readonly maxUses?: number;
47
+ /**
48
+ * Optional: enable image understanding during web search.
49
+ * When true, the model can view and analyze images found during search.
50
+ * Currently supported by xAI only; ignored by other providers.
51
+ */
52
+ readonly enableImageUnderstanding?: boolean;
53
+ }
54
+ /**
55
+ * Union of all server-side tool configurations. Discriminated on `type`.
56
+ * @public
57
+ */
58
+ export type AiServerToolConfig = IAiWebSearchToolConfig;
59
+ /**
60
+ * Declares a tool as enabled/disabled in provider settings.
61
+ * Tools are disabled by default — consuming apps must opt in explicitly.
62
+ * @public
63
+ */
64
+ export interface IAiToolEnablement {
65
+ /** Which tool type. */
66
+ readonly type: AiServerToolType;
67
+ /** Whether this tool is enabled by default for this provider. */
68
+ readonly enabled: boolean;
69
+ /** Optional tool-specific configuration. */
70
+ readonly config?: AiServerToolConfig;
71
+ }
72
+ /**
73
+ * Known context keys for model specification maps.
74
+ * @public
75
+ */
76
+ export type ModelSpecKey = 'base' | 'tools' | 'image';
77
+ /**
78
+ * All valid {@link ModelSpecKey} values.
79
+ * @public
80
+ */
81
+ export declare const allModelSpecKeys: ReadonlyArray<ModelSpecKey>;
82
+ /**
83
+ * Default context key used as fallback when resolving a {@link ModelSpec}.
84
+ * @public
85
+ */
86
+ export declare const MODEL_SPEC_BASE_KEY: ModelSpecKey;
87
+ /**
88
+ * A model specification: either a simple model string or a record mapping
89
+ * context keys to nested model specs.
90
+ *
91
+ * @remarks
92
+ * A bare string is equivalent to `{ base: string }`. This keeps the simple
93
+ * case simple while allowing context-aware model selection (e.g. different
94
+ * models for tool-augmented vs. base completions).
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Simple — same model for all contexts:
99
+ * const simple: ModelSpec = 'grok-4-1-fast';
100
+ *
101
+ * // Context-aware — reasoning model when tools are active:
102
+ * const split: ModelSpec = { base: 'grok-4-1-fast', tools: 'grok-4-1-fast-reasoning' };
103
+ *
104
+ * // Future nested — per-tool model selection:
105
+ * const nested: ModelSpec = { base: 'grok-fast', tools: { base: 'grok-r', image: 'grok-v' } };
106
+ * ```
107
+ * @public
108
+ */
109
+ export interface IModelSpecMap {
110
+ readonly [key: string]: ModelSpec;
111
+ }
112
+ /**
113
+ * @public
114
+ */
115
+ export type ModelSpec = string | IModelSpecMap;
116
+ /**
117
+ * Resolves a {@link ModelSpec} to a concrete model string given an optional context key.
118
+ *
119
+ * @remarks
120
+ * Resolution rules:
121
+ * 1. If the spec is a string, return it directly (context is irrelevant).
122
+ * 2. If the spec is an object and the context key exists, recurse into that branch.
123
+ * 3. Otherwise, fall back to the {@link MODEL_SPEC_BASE_KEY | 'base'} key.
124
+ * 4. If neither context nor `'base'` exists, use the first available value.
125
+ *
126
+ * @param spec - The model specification to resolve
127
+ * @param context - Optional context key (e.g. `'tools'`)
128
+ * @returns The resolved model string
129
+ * @public
130
+ */
131
+ export declare function resolveModel(spec: ModelSpec, context?: string): string;
132
+ /**
133
+ * All known AI provider identifiers.
134
+ * @public
135
+ */
136
+ export type AiProviderId = 'copy-paste' | 'xai-grok' | 'openai' | 'anthropic' | 'google-gemini' | 'groq' | 'mistral';
137
+ /**
138
+ * API format categories for provider routing.
139
+ * @public
140
+ */
141
+ export type AiApiFormat = 'openai' | 'anthropic' | 'gemini';
142
+ /**
143
+ * Result of an AI provider completion call.
144
+ * @public
145
+ */
146
+ export interface IAiCompletionResponse {
147
+ /** The generated text content */
148
+ readonly content: string;
149
+ /** Whether the response was truncated due to token limits */
150
+ readonly truncated: boolean;
151
+ }
152
+ /**
153
+ * Describes a single AI provider — single source of truth for all metadata.
154
+ * @public
155
+ */
156
+ export interface IAiProviderDescriptor {
157
+ /** Provider identifier (e.g. 'xai-grok', 'anthropic') */
158
+ readonly id: AiProviderId;
159
+ /** Human-readable label (e.g. "xAI Grok") */
160
+ readonly label: string;
161
+ /** Button label for action buttons (e.g. "AI Assist | Grok") */
162
+ readonly buttonLabel: string;
163
+ /** Whether this provider requires an API key secret */
164
+ readonly needsSecret: boolean;
165
+ /** Which API adapter format to use */
166
+ readonly apiFormat: AiApiFormat;
167
+ /** Base URL for the API (e.g. 'https://api.x.ai/v1') */
168
+ readonly baseUrl: string;
169
+ /** Default model specification — string or context-aware map. */
170
+ readonly defaultModel: ModelSpec;
171
+ /** Which server-side tools this provider supports (empty = none). */
172
+ readonly supportedTools: ReadonlyArray<AiServerToolType>;
173
+ /** Whether this provider's API enforces CORS restrictions that prevent direct browser calls. */
174
+ readonly corsRestricted: boolean;
175
+ }
176
+ /**
177
+ * Configuration for a single AI assist provider.
178
+ * @public
179
+ */
180
+ export interface IAiAssistProviderConfig {
181
+ /** Which provider this configures */
182
+ readonly provider: AiProviderId;
183
+ /** For API-based providers: the keystore secret name holding the API key */
184
+ readonly secretName?: string;
185
+ /** Optional model override — string or context-aware map. */
186
+ readonly model?: ModelSpec;
187
+ /** Tool enablement/configuration. Tools are disabled unless explicitly enabled. */
188
+ readonly tools?: ReadonlyArray<IAiToolEnablement>;
189
+ }
190
+ /**
191
+ * AI assist settings — which providers are enabled and their configuration.
192
+ * @public
193
+ */
194
+ export interface IAiAssistSettings {
195
+ /** Enabled providers and their configuration. */
196
+ readonly providers: ReadonlyArray<IAiAssistProviderConfig>;
197
+ /** Which enabled provider is the default for the main button. Falls back to first in list. */
198
+ readonly defaultProvider?: AiProviderId;
199
+ /** Optional proxy URL for routing API requests through a backend server (e.g. `http://localhost:3002`). */
200
+ readonly proxyUrl?: string;
201
+ /** When true, route all providers through the proxy. When false (default), only CORS-restricted providers use the proxy. */
202
+ readonly proxyAllProviders?: boolean;
203
+ }
204
+ /**
205
+ * Default AI assist settings (copy-paste only).
206
+ * @public
207
+ */
208
+ export declare const DEFAULT_AI_ASSIST: IAiAssistSettings;
209
+ /**
210
+ * Minimal keystore interface for AI assist API key resolution.
211
+ * Satisfied structurally by the concrete `KeyStore` class from `@fgv/ts-extras`.
212
+ * @public
213
+ */
214
+ export interface IAiAssistKeyStore {
215
+ /** Whether the keystore is currently unlocked */
216
+ readonly isUnlocked: boolean;
217
+ /** Check if a named secret exists */
218
+ hasSecret(name: string): Result<boolean>;
219
+ /** Get an API key by secret name */
220
+ getApiKey(name: string): Result<string>;
221
+ }
222
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1,95 @@
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.DEFAULT_AI_ASSIST = exports.MODEL_SPEC_BASE_KEY = exports.allModelSpecKeys = exports.AiPrompt = void 0;
23
+ exports.resolveModel = resolveModel;
24
+ // ============================================================================
25
+ // AiPrompt
26
+ // ============================================================================
27
+ /**
28
+ * A structured AI prompt with system/user split for direct API calls,
29
+ * and a lazily-constructed combined version for copy/paste workflows.
30
+ * @public
31
+ */
32
+ class AiPrompt {
33
+ constructor(user, system) {
34
+ this.system = system;
35
+ this.user = user;
36
+ }
37
+ /** Combined single-string version (user + system joined) for copy/paste. */
38
+ get combined() {
39
+ return `${this.user}\n\n${this.system}`;
40
+ }
41
+ }
42
+ exports.AiPrompt = AiPrompt;
43
+ /**
44
+ * All valid {@link ModelSpecKey} values.
45
+ * @public
46
+ */
47
+ exports.allModelSpecKeys = ['base', 'tools', 'image'];
48
+ /**
49
+ * Default context key used as fallback when resolving a {@link ModelSpec}.
50
+ * @public
51
+ */
52
+ exports.MODEL_SPEC_BASE_KEY = 'base';
53
+ /**
54
+ * Resolves a {@link ModelSpec} to a concrete model string given an optional context key.
55
+ *
56
+ * @remarks
57
+ * Resolution rules:
58
+ * 1. If the spec is a string, return it directly (context is irrelevant).
59
+ * 2. If the spec is an object and the context key exists, recurse into that branch.
60
+ * 3. Otherwise, fall back to the {@link MODEL_SPEC_BASE_KEY | 'base'} key.
61
+ * 4. If neither context nor `'base'` exists, use the first available value.
62
+ *
63
+ * @param spec - The model specification to resolve
64
+ * @param context - Optional context key (e.g. `'tools'`)
65
+ * @returns The resolved model string
66
+ * @public
67
+ */
68
+ function resolveModel(spec, context) {
69
+ if (typeof spec === 'string') {
70
+ return spec;
71
+ }
72
+ // Try the requested context key first
73
+ if (context !== undefined && context in spec) {
74
+ return resolveModel(spec[context]);
75
+ }
76
+ // Fall back to 'base'
77
+ if (exports.MODEL_SPEC_BASE_KEY in spec) {
78
+ return resolveModel(spec[exports.MODEL_SPEC_BASE_KEY]);
79
+ }
80
+ // Last resort: first value in the record
81
+ const first = Object.values(spec)[0];
82
+ /* c8 ignore next 3 - defensive: only reachable with empty object (prevented by converter) */
83
+ if (first === undefined) {
84
+ return '';
85
+ }
86
+ return resolveModel(first);
87
+ }
88
+ /**
89
+ * Default AI assist settings (copy-paste only).
90
+ * @public
91
+ */
92
+ exports.DEFAULT_AI_ASSIST = {
93
+ providers: [{ provider: 'copy-paste' }]
94
+ };
95
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Centralized provider registry — single source of truth for all AI provider metadata.
3
+ * @packageDocumentation
4
+ */
5
+ import { Result } from '@fgv/ts-utils';
6
+ import { type AiProviderId, type IAiProviderDescriptor } from './model';
7
+ /**
8
+ * All valid provider ID values, in the same order as the registry.
9
+ * @public
10
+ */
11
+ export declare const allProviderIds: ReadonlyArray<AiProviderId>;
12
+ /**
13
+ * Get all known provider descriptors. Copy-paste first, then alphabetical.
14
+ * @returns All built-in provider descriptors
15
+ * @public
16
+ */
17
+ export declare function getProviderDescriptors(): ReadonlyArray<IAiProviderDescriptor>;
18
+ /**
19
+ * Get a provider descriptor by id.
20
+ * @param id - The provider identifier
21
+ * @returns The descriptor, or a failure if the provider is unknown
22
+ * @public
23
+ */
24
+ export declare function getProviderDescriptor(id: string): Result<IAiProviderDescriptor>;
25
+ //# sourceMappingURL=registry.d.ts.map