@123toto/ai-app-assistant-server 0.1.1 → 0.2.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/README.md +14 -14
- package/dist/{ai-sdk-QImICd56.d.cts → ai-sdk-qU3KgNu-.d.cts} +2 -2
- package/dist/{ai-sdk-QImICd56.d.ts → ai-sdk-qU3KgNu-.d.ts} +2 -2
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/{chunk-OA7OXUK7.js → chunk-Z4IVCZ5M.js} +15 -15
- package/dist/chunk-Z4IVCZ5M.js.map +1 -0
- package/dist/express.cjs +8 -8
- package/dist/express.cjs.map +1 -1
- package/dist/express.d.cts +11 -11
- package/dist/express.d.ts +11 -11
- package/dist/express.js +7 -7
- package/dist/express.js.map +1 -1
- package/dist/index.cjs +167 -167
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -33
- package/dist/index.d.ts +33 -33
- package/dist/index.js +142 -142
- package/dist/index.js.map +1 -1
- package/dist/{managed-server-7iurKxF1.d.cts → managed-server-BGQ-1jkx.d.ts} +148 -148
- package/dist/{managed-server-CrZumvVU.d.ts → managed-server-CthTKEQ6.d.cts} +148 -148
- package/dist/nest.cjs +31 -31
- package/dist/nest.cjs.map +1 -1
- package/dist/nest.d.cts +12 -12
- package/dist/nest.d.ts +12 -12
- package/dist/nest.js +28 -28
- package/dist/nest.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-OA7OXUK7.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
1
|
+
import { a as AiAppAssistantOptions, d as AiSdkConnectionTestResult, e as AiSdkFailureCode, D as DocumentationSource, A as AnswerGenerator } from './ai-sdk-qU3KgNu-.js';
|
|
2
|
+
import { AiAppAssistantResponse, AiAppAssistantRequest, AiAppAssistantConnectionTestInput, AiAppAssistantConnectionResult, AiAppAssistantCredentials, AiAppAssistantConfigurationInput, AiAppAssistantManagedConfigurationView, TokenUsage } from '@123toto/ai-app-assistant-contracts';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type AiAppAssistantStreamEvent = {
|
|
5
5
|
type: "status";
|
|
6
6
|
phase: "preparing" | "generating";
|
|
7
7
|
} | {
|
|
@@ -14,17 +14,17 @@ type DocsAssistantStreamEvent = {
|
|
|
14
14
|
delayMs: number;
|
|
15
15
|
} | {
|
|
16
16
|
type: "complete";
|
|
17
|
-
response:
|
|
17
|
+
response: AiAppAssistantResponse;
|
|
18
18
|
};
|
|
19
19
|
/** Stateful facade whose static documentation is prepared only once. */
|
|
20
|
-
interface
|
|
21
|
-
answer(request:
|
|
20
|
+
interface AiAppAssistant {
|
|
21
|
+
answer(request: AiAppAssistantRequest, options?: {
|
|
22
22
|
signal?: AbortSignal;
|
|
23
|
-
}): Promise<
|
|
23
|
+
}): Promise<AiAppAssistantResponse>;
|
|
24
24
|
/** Streams provider-neutral progress and always ends with a complete event. */
|
|
25
|
-
stream(request:
|
|
25
|
+
stream(request: AiAppAssistantRequest, options?: {
|
|
26
26
|
signal?: AbortSignal;
|
|
27
|
-
}): AsyncGenerator<
|
|
27
|
+
}): AsyncGenerator<AiAppAssistantStreamEvent, AiAppAssistantResponse>;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Creates a provider-neutral documentation assistant.
|
|
@@ -34,7 +34,7 @@ interface DocsAssistant {
|
|
|
34
34
|
* element and the user's prompt. This keeps the public integration small and
|
|
35
35
|
* lets provider-side prompt caching reuse the stable document prefix.
|
|
36
36
|
*/
|
|
37
|
-
declare function
|
|
37
|
+
declare function createAiAppAssistant(options: AiAppAssistantOptions): AiAppAssistant;
|
|
38
38
|
|
|
39
39
|
/** Providers available without installing an additional AI SDK package. */
|
|
40
40
|
type BuiltInProvider = "anthropic" | "google" | "mistral" | "ollama" | "openai";
|
|
@@ -77,7 +77,7 @@ declare class AiModelDiscoveryError extends Error {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/** Generic access rule; host applications map their own roles and user IDs. */
|
|
80
|
-
type
|
|
80
|
+
type AiAppAssistantAccessRule = {
|
|
81
81
|
mode: "all";
|
|
82
82
|
} | {
|
|
83
83
|
mode: "roles";
|
|
@@ -87,55 +87,55 @@ type AiDocsAccessRule = {
|
|
|
87
87
|
userIds: string[];
|
|
88
88
|
};
|
|
89
89
|
/** Stable identity used for ownership and audit without coupling the library to a user directory. */
|
|
90
|
-
interface
|
|
90
|
+
interface AiAppAssistantConfigurationActor {
|
|
91
91
|
id: string;
|
|
92
92
|
label: string;
|
|
93
93
|
}
|
|
94
|
-
type
|
|
94
|
+
type AiAppAssistantConfigurationAuditField = "provider" | "apiKey" | "model" | "access" | "quota" | "conversation" | "modelChangePolicy";
|
|
95
95
|
/** One safe configuration change. API key values must never be placed in from/to. */
|
|
96
|
-
interface
|
|
97
|
-
field:
|
|
96
|
+
interface AiAppAssistantConfigurationAuditChange {
|
|
97
|
+
field: AiAppAssistantConfigurationAuditField;
|
|
98
98
|
from?: string;
|
|
99
99
|
to?: string;
|
|
100
100
|
}
|
|
101
|
-
interface
|
|
101
|
+
interface AiAppAssistantConfigurationAuditEntry {
|
|
102
102
|
id: string;
|
|
103
|
-
actor:
|
|
103
|
+
actor: AiAppAssistantConfigurationActor;
|
|
104
104
|
changedAt: string;
|
|
105
|
-
changes:
|
|
105
|
+
changes: AiAppAssistantConfigurationAuditChange[];
|
|
106
106
|
}
|
|
107
107
|
/** Ownership and persisted audit metadata managed by the host application's authenticated backend. */
|
|
108
|
-
interface
|
|
109
|
-
keyCreatedBy?:
|
|
108
|
+
interface AiAppAssistantConfigurationAdministration {
|
|
109
|
+
keyCreatedBy?: AiAppAssistantConfigurationActor;
|
|
110
110
|
keyCreatedAt?: string;
|
|
111
|
-
modelUpdatedBy?:
|
|
111
|
+
modelUpdatedBy?: AiAppAssistantConfigurationActor;
|
|
112
112
|
modelUpdatedAt?: string;
|
|
113
113
|
allowModelChangesByOthers: boolean;
|
|
114
|
-
history:
|
|
114
|
+
history: AiAppAssistantConfigurationAuditEntry[];
|
|
115
115
|
}
|
|
116
116
|
/** Provider configuration owned by the library and persisted by an adapter. */
|
|
117
|
-
interface
|
|
117
|
+
interface AiAppAssistantConfiguration {
|
|
118
118
|
provider: BuiltInProvider;
|
|
119
119
|
model: string;
|
|
120
120
|
/** Whether provider fields override deployment defaults or merely accompany stored policies. */
|
|
121
121
|
connectionSource?: "environment" | "override";
|
|
122
122
|
apiKey?: string;
|
|
123
123
|
baseURL?: string;
|
|
124
|
-
access:
|
|
124
|
+
access: AiAppAssistantAccessRule;
|
|
125
125
|
quota?: {
|
|
126
126
|
maxRequests: number;
|
|
127
127
|
windowSeconds: number;
|
|
128
128
|
};
|
|
129
129
|
/** Maximum number of user questions kept in one assistant conversation. */
|
|
130
130
|
maxConversationTurns?: number;
|
|
131
|
-
administration?:
|
|
131
|
+
administration?: AiAppAssistantConfigurationAdministration;
|
|
132
132
|
}
|
|
133
133
|
/** Safe representation returned to a frontend; it never contains the secret. */
|
|
134
|
-
type
|
|
134
|
+
type AiAppAssistantConfigurationView = Omit<AiAppAssistantConfiguration, "apiKey"> & {
|
|
135
135
|
apiKeyConfigured: boolean;
|
|
136
136
|
};
|
|
137
137
|
/** Minimal persistence contract supported by Redis, databases or secret stores. */
|
|
138
|
-
interface
|
|
138
|
+
interface AiAppAssistantKeyValueStore {
|
|
139
139
|
get(key: string): Promise<string | null | undefined>;
|
|
140
140
|
set(key: string, value: string): Promise<void>;
|
|
141
141
|
delete(key: string): Promise<void>;
|
|
@@ -143,180 +143,180 @@ interface AiDocsKeyValueStore {
|
|
|
143
143
|
compareAndSet?(key: string, expected: string | null, value: string): Promise<boolean>;
|
|
144
144
|
}
|
|
145
145
|
/** Secret protection is explicit so plaintext keys can never be persisted. */
|
|
146
|
-
interface
|
|
146
|
+
interface AiAppAssistantSecretProtector {
|
|
147
147
|
protect(secret: string): Promise<string> | string;
|
|
148
148
|
unprotect(protectedSecret: string): Promise<string> | string;
|
|
149
149
|
}
|
|
150
|
-
interface
|
|
151
|
-
load(): Promise<
|
|
152
|
-
loadView(): Promise<
|
|
153
|
-
save(configuration:
|
|
150
|
+
interface AiAppAssistantConfigurationRepository {
|
|
151
|
+
load(): Promise<AiAppAssistantConfiguration | undefined>;
|
|
152
|
+
loadView(): Promise<AiAppAssistantConfigurationView | undefined>;
|
|
153
|
+
save(configuration: AiAppAssistantConfiguration): Promise<AiAppAssistantConfigurationView>;
|
|
154
154
|
/** Atomic when the underlying key/value store supports compare-and-set. */
|
|
155
|
-
mutate?(update: (current:
|
|
155
|
+
mutate?(update: (current: AiAppAssistantConfiguration | undefined) => AiAppAssistantConfiguration | Promise<AiAppAssistantConfiguration>): Promise<AiAppAssistantConfigurationView>;
|
|
156
156
|
clear(): Promise<void>;
|
|
157
157
|
}
|
|
158
|
-
interface
|
|
159
|
-
store:
|
|
160
|
-
secretProtector:
|
|
158
|
+
interface CreateAiAppAssistantConfigurationRepositoryOptions {
|
|
159
|
+
store: AiAppAssistantKeyValueStore;
|
|
160
|
+
secretProtector: AiAppAssistantSecretProtector;
|
|
161
161
|
/** Allows several applications or environments to share one storage system. */
|
|
162
162
|
key?: string;
|
|
163
163
|
}
|
|
164
|
-
declare class
|
|
164
|
+
declare class AiAppAssistantConfigurationConflictError extends Error {
|
|
165
165
|
constructor();
|
|
166
166
|
}
|
|
167
167
|
/** Creates a repository that validates and encrypts configuration data. */
|
|
168
|
-
declare function
|
|
168
|
+
declare function createAiAppAssistantConfigurationRepository(options: CreateAiAppAssistantConfigurationRepositoryOptions): AiAppAssistantConfigurationRepository;
|
|
169
169
|
/**
|
|
170
170
|
* Tests the exact model configuration and persists it only after a successful
|
|
171
171
|
* structured-output response.
|
|
172
172
|
*/
|
|
173
|
-
declare function
|
|
173
|
+
declare function validateAndSaveAiAppAssistantConfiguration(repository: AiAppAssistantConfigurationRepository, configuration: AiAppAssistantConfiguration, options?: {
|
|
174
174
|
timeoutMs?: number;
|
|
175
175
|
}): Promise<{
|
|
176
176
|
saved: boolean;
|
|
177
177
|
connection: AiSdkConnectionTestResult;
|
|
178
|
-
configuration?:
|
|
178
|
+
configuration?: AiAppAssistantConfigurationView;
|
|
179
179
|
}>;
|
|
180
180
|
/**
|
|
181
181
|
* AES-256-GCM protector for applications that keep configuration outside a
|
|
182
182
|
* dedicated secret manager. The key must be a random 32-byte base64 value.
|
|
183
183
|
*/
|
|
184
|
-
declare function createAes256GcmSecretProtector(base64Key: string):
|
|
184
|
+
declare function createAes256GcmSecretProtector(base64Key: string): AiAppAssistantSecretProtector;
|
|
185
185
|
/**
|
|
186
186
|
* Allows environment-only configurations while failing closed if a caller
|
|
187
187
|
* attempts to persist a secret without configuring encryption.
|
|
188
188
|
*/
|
|
189
|
-
declare function createDisabledSecretProtector():
|
|
189
|
+
declare function createDisabledSecretProtector(): AiAppAssistantSecretProtector;
|
|
190
190
|
/** Lightweight local store useful for tests and single-process prototypes. */
|
|
191
|
-
declare function
|
|
191
|
+
declare function createMemoryAiAppAssistantStore(): AiAppAssistantKeyValueStore;
|
|
192
192
|
/** Minimal Redis shape; consumers can pass an existing ioredis-like client. */
|
|
193
|
-
interface
|
|
193
|
+
interface AiAppAssistantRedisClient {
|
|
194
194
|
get(key: string): Promise<string | null>;
|
|
195
195
|
set(key: string, value: string): Promise<unknown>;
|
|
196
196
|
del(key: string): Promise<number>;
|
|
197
197
|
eval?(script: string, numberOfKeys: number, ...args: string[]): Promise<unknown>;
|
|
198
198
|
}
|
|
199
199
|
/** Reuses the host application's Redis connection without adding a dependency. */
|
|
200
|
-
declare function
|
|
200
|
+
declare function createRedisAiAppAssistantStore(client: AiAppAssistantRedisClient, options?: {
|
|
201
201
|
prefix?: string;
|
|
202
|
-
}):
|
|
202
|
+
}): AiAppAssistantKeyValueStore;
|
|
203
203
|
|
|
204
|
-
interface
|
|
204
|
+
interface AiAppAssistantQuotaPolicy {
|
|
205
205
|
maxRequests: number;
|
|
206
206
|
windowSeconds: number;
|
|
207
207
|
}
|
|
208
|
-
interface
|
|
208
|
+
interface AiAppAssistantQuotaResult {
|
|
209
209
|
allowed: boolean;
|
|
210
210
|
remaining: number;
|
|
211
211
|
retryAfterSeconds: number;
|
|
212
212
|
resetAt: Date;
|
|
213
213
|
}
|
|
214
214
|
/** Atomic quota contract implemented by shared or local stores. */
|
|
215
|
-
interface
|
|
216
|
-
consume(subject: string, policy:
|
|
215
|
+
interface AiAppAssistantQuotaStore {
|
|
216
|
+
consume(subject: string, policy: AiAppAssistantQuotaPolicy): Promise<AiAppAssistantQuotaResult>;
|
|
217
217
|
}
|
|
218
218
|
/** Single-process implementation intended for tests and local development. */
|
|
219
|
-
declare function
|
|
219
|
+
declare function createMemoryAiAppAssistantQuotaStore(): AiAppAssistantQuotaStore;
|
|
220
220
|
/** Minimal ioredis-compatible shape needed for one atomic Lua operation. */
|
|
221
|
-
interface
|
|
221
|
+
interface AiAppAssistantRedisQuotaClient {
|
|
222
222
|
eval(script: string, numberOfKeys: number, ...args: Array<string | number>): Promise<unknown>;
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
225
225
|
* Redis quota with one atomic increment/expiry operation. Subject identifiers
|
|
226
226
|
* are SHA-256 fingerprints, never readable user IDs.
|
|
227
227
|
*/
|
|
228
|
-
declare function
|
|
228
|
+
declare function createRedisAiAppAssistantQuotaStore(client: AiAppAssistantRedisQuotaClient, options?: {
|
|
229
229
|
prefix?: string;
|
|
230
|
-
}):
|
|
230
|
+
}): AiAppAssistantQuotaStore;
|
|
231
231
|
|
|
232
232
|
/** Minimal identity understood by the generic access and audit policies. */
|
|
233
|
-
interface
|
|
233
|
+
interface AiAppAssistantRuntimeIdentity extends AiAppAssistantConfigurationActor {
|
|
234
234
|
roles?: readonly string[];
|
|
235
235
|
}
|
|
236
|
-
interface
|
|
236
|
+
interface AiAppAssistantConfigurationChangeEvent {
|
|
237
237
|
reason: "saved" | "revoked" | "connection-tested" | "remote-change";
|
|
238
238
|
reloadRequired: boolean;
|
|
239
239
|
/** A successful provider call already validated the current configuration. */
|
|
240
240
|
connectionValidated: boolean;
|
|
241
241
|
remote: boolean;
|
|
242
242
|
}
|
|
243
|
-
interface
|
|
244
|
-
start(onChange: (event:
|
|
245
|
-
publish(event:
|
|
243
|
+
interface AiAppAssistantConfigurationSynchronizer {
|
|
244
|
+
start(onChange: (event: AiAppAssistantConfigurationChangeEvent) => Promise<void> | void): Promise<() => void> | (() => void);
|
|
245
|
+
publish(event: AiAppAssistantConfigurationChangeEvent): Promise<void>;
|
|
246
246
|
}
|
|
247
|
-
interface
|
|
248
|
-
repository:
|
|
247
|
+
interface AiAppAssistantConfigurationManagerOptions {
|
|
248
|
+
repository: AiAppAssistantConfigurationRepository;
|
|
249
249
|
/** Defaults to the local in-memory quota implementation. */
|
|
250
|
-
quotaStore?:
|
|
250
|
+
quotaStore?: AiAppAssistantQuotaStore;
|
|
251
251
|
/** Environment or deployment defaults. They are never persisted automatically. */
|
|
252
|
-
defaultConfiguration?:
|
|
252
|
+
defaultConfiguration?: AiAppAssistantConfiguration | (() => AiAppAssistantConfiguration | undefined);
|
|
253
253
|
/** Resolves a secret supplied by the host environment or secret manager. */
|
|
254
|
-
resolveDefaultApiKey?: (provider:
|
|
254
|
+
resolveDefaultApiKey?: (provider: AiAppAssistantConfiguration["provider"]) => string | undefined;
|
|
255
255
|
apiKeyStorageAvailable?: boolean;
|
|
256
|
-
defaultQuota?:
|
|
256
|
+
defaultQuota?: AiAppAssistantQuotaPolicy;
|
|
257
257
|
connectionTimeoutMs?: number;
|
|
258
258
|
/** Minimum delay before retrying a disconnected provider on demand. */
|
|
259
259
|
reconnectIntervalMs?: number;
|
|
260
|
-
synchronizer?:
|
|
261
|
-
testConnection?: (input:
|
|
262
|
-
listModels?: (input:
|
|
260
|
+
synchronizer?: AiAppAssistantConfigurationSynchronizer;
|
|
261
|
+
testConnection?: (input: AiAppAssistantConnectionTestInput) => Promise<AiAppAssistantConnectionResult>;
|
|
262
|
+
listModels?: (input: AiAppAssistantCredentials) => Promise<AiModelInfo[]>;
|
|
263
263
|
now?: () => Date;
|
|
264
264
|
createId?: () => string;
|
|
265
265
|
logger?: Pick<Console, "info" | "warn">;
|
|
266
266
|
}
|
|
267
|
-
interface
|
|
267
|
+
interface AiAppAssistantConfigurationSaveResult {
|
|
268
268
|
saved: boolean;
|
|
269
|
-
connection:
|
|
270
|
-
configuration?:
|
|
269
|
+
connection: AiAppAssistantConnectionResult;
|
|
270
|
+
configuration?: AiAppAssistantManagedConfigurationView;
|
|
271
271
|
reloadRequired: boolean;
|
|
272
272
|
}
|
|
273
|
-
type
|
|
273
|
+
type AiAppAssistantManagementErrorCode = "unauthorized" | "forbidden" | "conflict" | "invalid_request" | "not_configured" | "quota_reached" | "secret_storage_unavailable";
|
|
274
274
|
/** Framework-neutral policy error that HTTP adapters can map safely. */
|
|
275
|
-
declare class
|
|
275
|
+
declare class AiAppAssistantManagementError extends Error {
|
|
276
276
|
readonly status: number;
|
|
277
|
-
readonly code:
|
|
277
|
+
readonly code: AiAppAssistantManagementErrorCode;
|
|
278
278
|
readonly details?: Record<string, unknown> | undefined;
|
|
279
|
-
constructor(status: number, code:
|
|
279
|
+
constructor(status: number, code: AiAppAssistantManagementErrorCode, message: string, details?: Record<string, unknown> | undefined);
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
282
|
* Owns provider configuration, access, quota, audit and runtime connection
|
|
283
283
|
* state. Hosts only supply identity mapping, storage and optional defaults.
|
|
284
284
|
*/
|
|
285
|
-
declare class
|
|
285
|
+
declare class AiAppAssistantConfigurationManager {
|
|
286
286
|
#private;
|
|
287
|
-
constructor(options:
|
|
287
|
+
constructor(options: AiAppAssistantConfigurationManagerOptions);
|
|
288
288
|
/** Returns the built-in provider catalogue; no credentials are exposed. */
|
|
289
289
|
listProviders(): AiProviderInfo[];
|
|
290
290
|
/** Discovers models with an explicit key or the currently configured secret. */
|
|
291
|
-
listModels(input:
|
|
291
|
+
listModels(input: AiAppAssistantCredentials): Promise<AiModelInfo[]>;
|
|
292
292
|
/** Notifies the runtime when a provider-affecting setting changes. */
|
|
293
|
-
subscribe(listener: (event:
|
|
293
|
+
subscribe(listener: (event: AiAppAssistantConfigurationChangeEvent) => Promise<void> | void): () => void;
|
|
294
294
|
/** Starts optional cross-instance invalidation. Calling it repeatedly is safe. */
|
|
295
295
|
startSynchronization(): Promise<void>;
|
|
296
296
|
dispose(): void;
|
|
297
297
|
/** Tests credentials and briefly caches a successful result for the next save. */
|
|
298
|
-
testConnection(input:
|
|
298
|
+
testConnection(input: AiAppAssistantConnectionTestInput): Promise<AiAppAssistantConnectionResult>;
|
|
299
299
|
/** Checks the effective stored/deployment connection used by live questions. */
|
|
300
300
|
validateRuntimeConnection(): Promise<boolean>;
|
|
301
301
|
/** Validates sensitive connection changes, persists safely and records their author. */
|
|
302
|
-
save(rawInput:
|
|
302
|
+
save(rawInput: AiAppAssistantConfigurationInput, actor: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantConfigurationSaveResult>;
|
|
303
303
|
/** Removes only the manual key, records the revocation and falls back to defaults. */
|
|
304
|
-
revokeApiKey(actor:
|
|
304
|
+
revokeApiKey(actor: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantManagedConfigurationView>;
|
|
305
305
|
/** Resolves persisted policy against deployment defaults, including the secret. */
|
|
306
|
-
getRuntimeConfiguration(): Promise<
|
|
306
|
+
getRuntimeConfiguration(): Promise<AiAppAssistantConfiguration | undefined>;
|
|
307
307
|
/** Returns the frontend-safe view: secret presence and permissions, never the key. */
|
|
308
|
-
getView(identity?:
|
|
308
|
+
getView(identity?: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantManagedConfigurationView>;
|
|
309
309
|
/** Minimal launcher state used by clients before rendering the assistant. */
|
|
310
|
-
getAccess(identity:
|
|
310
|
+
getAccess(identity: AiAppAssistantRuntimeIdentity): Promise<{
|
|
311
311
|
available: boolean;
|
|
312
312
|
maxConversationTurns: number;
|
|
313
313
|
}>;
|
|
314
314
|
/** Combines configuration, provider health and application access rules. */
|
|
315
|
-
canUse(identity:
|
|
315
|
+
canUse(identity: AiAppAssistantRuntimeIdentity): Promise<boolean>;
|
|
316
316
|
/** Atomically consumes one request from the user's active quota window. */
|
|
317
|
-
consumeQuota(identity:
|
|
317
|
+
consumeQuota(identity: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantQuotaResult>;
|
|
318
318
|
/** Enforces access and quota immediately before any model call. */
|
|
319
|
-
assertCanAsk(identity:
|
|
319
|
+
assertCanAsk(identity: AiAppAssistantRuntimeIdentity): Promise<void>;
|
|
320
320
|
/** Retries a failed provider lazily, with a shared backoff across requests. */
|
|
321
321
|
ensureRuntimeConnection(): Promise<boolean>;
|
|
322
322
|
private applyTestResultToActiveConfiguration;
|
|
@@ -336,24 +336,24 @@ declare class AiDocsConfigurationManager {
|
|
|
336
336
|
* Portable cross-instance invalidation using any key/value store. It avoids a
|
|
337
337
|
* Redis-specific dependency and gives every process an eventual reload.
|
|
338
338
|
*/
|
|
339
|
-
declare function
|
|
339
|
+
declare function createPollingAiAppAssistantConfigurationSynchronizer(store: AiAppAssistantKeyValueStore, options?: {
|
|
340
340
|
key?: string;
|
|
341
341
|
intervalMs?: number;
|
|
342
|
-
}):
|
|
342
|
+
}): AiAppAssistantConfigurationSynchronizer;
|
|
343
343
|
|
|
344
|
-
type
|
|
345
|
-
interface
|
|
344
|
+
type AiAppAssistantGenerationOperation = "answer" | "stream";
|
|
345
|
+
interface AiAppAssistantGenerationEventBase {
|
|
346
346
|
requestId: string;
|
|
347
|
-
operation:
|
|
347
|
+
operation: AiAppAssistantGenerationOperation;
|
|
348
348
|
model: string;
|
|
349
349
|
durationMs: number;
|
|
350
350
|
occurredAt: string;
|
|
351
351
|
}
|
|
352
352
|
/** Safe operational event. It deliberately excludes prompts, HTML, users and credentials. */
|
|
353
|
-
type
|
|
353
|
+
type AiAppAssistantGenerationEvent = (AiAppAssistantGenerationEventBase & {
|
|
354
354
|
outcome: "success";
|
|
355
355
|
usage?: TokenUsage;
|
|
356
|
-
}) | (
|
|
356
|
+
}) | (AiAppAssistantGenerationEventBase & {
|
|
357
357
|
outcome: "failure";
|
|
358
358
|
error: {
|
|
359
359
|
code: AiSdkFailureCode;
|
|
@@ -363,7 +363,7 @@ type AiDocsGenerationEvent = (AiDocsGenerationEventBase & {
|
|
|
363
363
|
providerStatus?: number;
|
|
364
364
|
};
|
|
365
365
|
});
|
|
366
|
-
interface
|
|
366
|
+
interface AiAppAssistantTelemetrySummary {
|
|
367
367
|
requests: number;
|
|
368
368
|
succeeded: number;
|
|
369
369
|
failed: number;
|
|
@@ -373,43 +373,43 @@ interface AiDocsTelemetrySummary {
|
|
|
373
373
|
totalTokens: number;
|
|
374
374
|
failuresByCode: Partial<Record<AiSdkFailureCode, number>>;
|
|
375
375
|
}
|
|
376
|
-
type
|
|
376
|
+
type AiAppAssistantRecentFailure = Extract<AiAppAssistantGenerationEvent, {
|
|
377
377
|
outcome: "failure";
|
|
378
378
|
}>;
|
|
379
379
|
/** Persistence contract used by the managed server and reusable by any host. */
|
|
380
|
-
interface
|
|
381
|
-
record(event:
|
|
382
|
-
summary(): Promise<
|
|
383
|
-
recentFailures(limit?: number): Promise<
|
|
380
|
+
interface AiAppAssistantTelemetryStore {
|
|
381
|
+
record(event: AiAppAssistantGenerationEvent): Promise<void>;
|
|
382
|
+
summary(): Promise<AiAppAssistantTelemetrySummary>;
|
|
383
|
+
recentFailures(limit?: number): Promise<AiAppAssistantRecentFailure[]>;
|
|
384
384
|
}
|
|
385
385
|
/** Single-process telemetry intended for tests and local development. */
|
|
386
|
-
declare function
|
|
386
|
+
declare function createMemoryAiAppAssistantTelemetryStore(options?: {
|
|
387
387
|
recentFailureLimit?: number;
|
|
388
|
-
}):
|
|
388
|
+
}): AiAppAssistantTelemetryStore;
|
|
389
389
|
/** Minimal Redis shape; compatible with ioredis without adding it as a dependency. */
|
|
390
|
-
interface
|
|
390
|
+
interface AiAppAssistantRedisTelemetryClient {
|
|
391
391
|
eval(script: string, numberOfKeys: number, ...args: Array<string | number>): Promise<unknown>;
|
|
392
392
|
}
|
|
393
393
|
/**
|
|
394
394
|
* Shared Redis telemetry. One Lua call atomically updates counters and keeps a
|
|
395
395
|
* bounded failure list, so several application instances can safely share it.
|
|
396
396
|
*/
|
|
397
|
-
declare function
|
|
397
|
+
declare function createRedisAiAppAssistantTelemetryStore(client: AiAppAssistantRedisTelemetryClient, options?: {
|
|
398
398
|
prefix?: string;
|
|
399
399
|
recentFailureLimit?: number;
|
|
400
|
-
}):
|
|
400
|
+
}): AiAppAssistantTelemetryStore;
|
|
401
401
|
/** Converts any generator error to the same safe public diagnostic. */
|
|
402
|
-
declare function
|
|
402
|
+
declare function createAiAppAssistantFailureEvent(input: {
|
|
403
403
|
error: unknown;
|
|
404
404
|
requestId: string;
|
|
405
|
-
operation:
|
|
405
|
+
operation: AiAppAssistantGenerationOperation;
|
|
406
406
|
model: string;
|
|
407
407
|
durationMs: number;
|
|
408
|
-
}):
|
|
408
|
+
}): AiAppAssistantRecentFailure;
|
|
409
409
|
|
|
410
|
-
type AssistantPolicies = NonNullable<
|
|
411
|
-
interface
|
|
412
|
-
configuration:
|
|
410
|
+
type AssistantPolicies = NonNullable<AiAppAssistantOptions["policies"]>;
|
|
411
|
+
interface CreateManagedAiAppAssistantRuntimeOptions<TIdentity extends AiAppAssistantRuntimeIdentity> {
|
|
412
|
+
configuration: AiAppAssistantConfigurationManager;
|
|
413
413
|
documents?: DocumentationSource[];
|
|
414
414
|
policies?: AssistantPolicies;
|
|
415
415
|
/** Overrides the built-in `provider:model` AI SDK generator. */
|
|
@@ -420,36 +420,36 @@ interface CreateManagedAiDocsRuntimeOptions<TIdentity extends AiDocsRuntimeIdent
|
|
|
420
420
|
}) => AnswerGenerator | Promise<AnswerGenerator>;
|
|
421
421
|
timeoutMs?: number;
|
|
422
422
|
maxRetries?: number;
|
|
423
|
-
transformRequest?: (input:
|
|
424
|
-
transformResponse?: (output:
|
|
425
|
-
transformStreamEvent?: (event:
|
|
423
|
+
transformRequest?: (input: AiAppAssistantRequest, identity: TIdentity) => AiAppAssistantRequest | Promise<AiAppAssistantRequest>;
|
|
424
|
+
transformResponse?: (output: AiAppAssistantResponse, identity: TIdentity) => AiAppAssistantResponse | Promise<AiAppAssistantResponse>;
|
|
425
|
+
transformStreamEvent?: (event: AiAppAssistantStreamEvent, identity: TIdentity) => AiAppAssistantStreamEvent | Promise<AiAppAssistantStreamEvent>;
|
|
426
426
|
authorize?: (identity: TIdentity) => Promise<void> | void;
|
|
427
427
|
/** Receives provider/runtime failures without exposing prompts or credentials. */
|
|
428
428
|
onGenerationError?: (error: unknown, operation: "answer" | "stream", identity: TIdentity) => Promise<void> | void;
|
|
429
429
|
/** Receives one safe success/failure event per user request. */
|
|
430
|
-
onGenerationEvent?: (event:
|
|
430
|
+
onGenerationEvent?: (event: AiAppAssistantGenerationEvent, identity: TIdentity) => Promise<void> | void;
|
|
431
431
|
/** Optional persistence used by the batteries-included managed server. */
|
|
432
|
-
telemetryStore?:
|
|
432
|
+
telemetryStore?: AiAppAssistantTelemetryStore;
|
|
433
433
|
}
|
|
434
|
-
interface
|
|
435
|
-
readonly configuration:
|
|
436
|
-
readonly telemetry?:
|
|
434
|
+
interface ManagedAiAppAssistantRuntime<TIdentity extends AiAppAssistantRuntimeIdentity> {
|
|
435
|
+
readonly configuration: AiAppAssistantConfigurationManager;
|
|
436
|
+
readonly telemetry?: AiAppAssistantTelemetryStore;
|
|
437
437
|
initialize(): Promise<void>;
|
|
438
438
|
dispose(): void;
|
|
439
439
|
reload(connectionAlreadyValidated?: boolean): Promise<void>;
|
|
440
440
|
/** Replaces the stable documentation without recreating the configuration manager. */
|
|
441
441
|
setDocuments(documents: DocumentationSource[]): Promise<void>;
|
|
442
|
-
answer(input:
|
|
443
|
-
stream(input:
|
|
442
|
+
answer(input: AiAppAssistantRequest, identity: TIdentity): Promise<AiAppAssistantResponse>;
|
|
443
|
+
stream(input: AiAppAssistantRequest, identity: TIdentity, signal?: AbortSignal): AsyncGenerator<AiAppAssistantStreamEvent, AiAppAssistantResponse>;
|
|
444
444
|
}
|
|
445
445
|
/**
|
|
446
|
-
* Optional batteries-included runtime. The minimal `
|
|
446
|
+
* Optional batteries-included runtime. The minimal `createAiAppAssistant` API
|
|
447
447
|
* remains available for applications that want to own the lifecycle.
|
|
448
448
|
*/
|
|
449
|
-
declare function
|
|
449
|
+
declare function createManagedAiAppAssistantRuntime<TIdentity extends AiAppAssistantRuntimeIdentity>(options: CreateManagedAiAppAssistantRuntimeOptions<TIdentity>): ManagedAiAppAssistantRuntime<TIdentity>;
|
|
450
450
|
|
|
451
|
-
interface
|
|
452
|
-
runtime:
|
|
451
|
+
interface ManagedAiAppAssistantFetchHandlerOptions<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
452
|
+
runtime: ManagedAiAppAssistantRuntime<TIdentity>;
|
|
453
453
|
/** Required by default so application endpoints fail closed. */
|
|
454
454
|
resolveIdentity?: (request: Request, nativeContext: TNativeContext | undefined) => TIdentity | Promise<TIdentity>;
|
|
455
455
|
/** Explicit opt-in for public prototypes. Never enable it on authenticated applications. */
|
|
@@ -472,51 +472,51 @@ interface ManagedAiDocsFetchHandlerOptions<TIdentity extends AiDocsRuntimeIdenti
|
|
|
472
472
|
maxBodyBytes?: number;
|
|
473
473
|
onError?: (error: unknown, request: Request, nativeContext: TNativeContext | undefined) => Response | Promise<Response>;
|
|
474
474
|
}
|
|
475
|
-
interface
|
|
475
|
+
interface ManagedAiAppAssistantFetchHandlers<TNativeContext = undefined> {
|
|
476
476
|
handle(request: Request, nativeContext?: TNativeContext): Promise<Response>;
|
|
477
477
|
}
|
|
478
478
|
/** Complete framework-neutral chat and administration API. */
|
|
479
|
-
declare function
|
|
479
|
+
declare function createManagedAiAppAssistantFetchHandlers<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined>(options: ManagedAiAppAssistantFetchHandlerOptions<TIdentity, TNativeContext>): ManagedAiAppAssistantFetchHandlers<TNativeContext>;
|
|
480
480
|
|
|
481
|
-
type
|
|
481
|
+
type AiAppAssistantManagedStorage = {
|
|
482
482
|
type: "memory";
|
|
483
483
|
} | {
|
|
484
484
|
type: "redis";
|
|
485
|
-
client:
|
|
486
|
-
/** Shared namespace. Defaults to `ai-
|
|
485
|
+
client: AiAppAssistantRedisClient & AiAppAssistantRedisQuotaClient;
|
|
486
|
+
/** Shared namespace. Defaults to `ai-app-assistant:`. */
|
|
487
487
|
prefix?: string;
|
|
488
488
|
synchronizationIntervalMs?: number;
|
|
489
489
|
};
|
|
490
|
-
interface
|
|
490
|
+
interface AiAppAssistantManagedConfigurationSetup extends Omit<AiAppAssistantConfigurationManagerOptions, "apiKeyStorageAvailable" | "quotaStore" | "repository" | "synchronizer"> {
|
|
491
491
|
/** Creates configuration, quota and synchronization adapters automatically. */
|
|
492
|
-
storage?:
|
|
492
|
+
storage?: AiAppAssistantManagedStorage;
|
|
493
493
|
/** AES-256-GCM key used to persist administrator-supplied API keys. */
|
|
494
494
|
encryptionKey?: string;
|
|
495
495
|
/** Alternative secret manager; takes precedence over encryptionKey. */
|
|
496
|
-
secretProtector?:
|
|
496
|
+
secretProtector?: AiAppAssistantSecretProtector;
|
|
497
497
|
repositoryKey?: string;
|
|
498
|
-
quotaStore?:
|
|
499
|
-
synchronizer?:
|
|
498
|
+
quotaStore?: AiAppAssistantQuotaStore;
|
|
499
|
+
synchronizer?: AiAppAssistantConfigurationManagerOptions["synchronizer"];
|
|
500
500
|
apiKeyStorageAvailable?: boolean;
|
|
501
501
|
}
|
|
502
|
-
interface
|
|
502
|
+
interface CreateManagedAiAppAssistantServerOptions<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
503
503
|
/** Pass an existing manager, or its construction options for the common case. */
|
|
504
|
-
configuration:
|
|
504
|
+
configuration: AiAppAssistantConfigurationManager | AiAppAssistantConfigurationManagerOptions | AiAppAssistantManagedConfigurationSetup;
|
|
505
505
|
/** Stable application documentation. It can also be supplied later with setDocuments(). */
|
|
506
506
|
documents?: DocumentationSource[];
|
|
507
|
-
runtime?: Omit<
|
|
508
|
-
http?: Omit<
|
|
507
|
+
runtime?: Omit<CreateManagedAiAppAssistantRuntimeOptions<TIdentity>, "configuration" | "documents">;
|
|
508
|
+
http?: Omit<ManagedAiAppAssistantFetchHandlerOptions<TIdentity, TNativeContext>, "runtime">;
|
|
509
509
|
/** Enabled by default; Redis configuration automatically makes it persistent. */
|
|
510
510
|
telemetry?: false | {
|
|
511
|
-
store?:
|
|
511
|
+
store?: AiAppAssistantTelemetryStore;
|
|
512
512
|
recentFailureLimit?: number;
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
|
-
interface
|
|
516
|
-
readonly configuration:
|
|
517
|
-
readonly runtime:
|
|
518
|
-
readonly fetch:
|
|
519
|
-
readonly telemetry?:
|
|
515
|
+
interface ManagedAiAppAssistantServer<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
516
|
+
readonly configuration: AiAppAssistantConfigurationManager;
|
|
517
|
+
readonly runtime: ManagedAiAppAssistantRuntime<TIdentity>;
|
|
518
|
+
readonly fetch: ManagedAiAppAssistantFetchHandlers<TNativeContext>;
|
|
519
|
+
readonly telemetry?: AiAppAssistantTelemetryStore;
|
|
520
520
|
initialize(): Promise<void>;
|
|
521
521
|
setDocuments(documents: DocumentationSource[]): Promise<void>;
|
|
522
522
|
dispose(): void;
|
|
@@ -528,6 +528,6 @@ interface ManagedAiDocsServer<TIdentity extends AiDocsRuntimeIdentity, TNativeCo
|
|
|
528
528
|
* Framework integrations only need to adapt their native request/response and
|
|
529
529
|
* pass the authenticated application identity through `http.resolveIdentity`.
|
|
530
530
|
*/
|
|
531
|
-
declare function
|
|
531
|
+
declare function createManagedAiAppAssistantServer<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined>(options: CreateManagedAiAppAssistantServerOptions<TIdentity, TNativeContext>): ManagedAiAppAssistantServer<TIdentity, TNativeContext>;
|
|
532
532
|
|
|
533
|
-
export {
|
|
533
|
+
export { createManagedAiAppAssistantRuntime as $, type AiAppAssistant as A, type BuiltInProvider as B, type AiAppAssistantRecentFailure as C, type AiAppAssistantRedisClient as D, type AiAppAssistantRedisQuotaClient as E, type AiAppAssistantRedisTelemetryClient as F, type AiAppAssistantRuntimeIdentity as G, type AiAppAssistantSecretProtector as H, type AiAppAssistantTelemetryStore as I, type AiAppAssistantTelemetrySummary as J, AiModelDiscoveryError as K, type AiModelInfo as L, type ManagedAiAppAssistantServer as M, type AiProviderInfo as N, type CreateAiAppAssistantConfigurationRepositoryOptions as O, type CreateManagedAiAppAssistantRuntimeOptions as P, type CreateManagedAiAppAssistantServerOptions as Q, type ListAiModelsOptions as R, type ManagedAiAppAssistantFetchHandlerOptions as S, type ManagedAiAppAssistantFetchHandlers as T, type ManagedAiAppAssistantRuntime as U, createAes256GcmSecretProtector as V, createAiAppAssistant as W, createAiAppAssistantConfigurationRepository as X, createAiAppAssistantFailureEvent as Y, createDisabledSecretProtector as Z, createManagedAiAppAssistantFetchHandlers as _, type AiAppAssistantStreamEvent as a, createManagedAiAppAssistantServer as a0, createMemoryAiAppAssistantQuotaStore as a1, createMemoryAiAppAssistantStore as a2, createMemoryAiAppAssistantTelemetryStore as a3, createPollingAiAppAssistantConfigurationSynchronizer as a4, createRedisAiAppAssistantQuotaStore as a5, createRedisAiAppAssistantStore as a6, createRedisAiAppAssistantTelemetryStore as a7, listAiModels as a8, listAiProviders as a9, validateAndSaveAiAppAssistantConfiguration as aa, type AiAppAssistantConfiguration as b, type AiAppAssistantAccessRule as c, type AiAppAssistantConfigurationActor as d, type AiAppAssistantConfigurationAdministration as e, type AiAppAssistantConfigurationAuditChange as f, type AiAppAssistantConfigurationAuditEntry as g, type AiAppAssistantConfigurationAuditField as h, type AiAppAssistantConfigurationChangeEvent as i, AiAppAssistantConfigurationConflictError as j, AiAppAssistantConfigurationManager as k, type AiAppAssistantConfigurationManagerOptions as l, type AiAppAssistantConfigurationRepository as m, type AiAppAssistantConfigurationSaveResult as n, type AiAppAssistantConfigurationSynchronizer as o, type AiAppAssistantConfigurationView as p, type AiAppAssistantGenerationEvent as q, type AiAppAssistantGenerationOperation as r, type AiAppAssistantKeyValueStore as s, type AiAppAssistantManagedConfigurationSetup as t, type AiAppAssistantManagedStorage as u, AiAppAssistantManagementError as v, type AiAppAssistantManagementErrorCode as w, type AiAppAssistantQuotaPolicy as x, type AiAppAssistantQuotaResult as y, type AiAppAssistantQuotaStore as z };
|