@123toto/ai-app-assistant-server 0.1.1 → 0.2.1
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 +18 -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 +200 -168
- 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 +175 -143
- package/dist/index.js.map +1 -1
- package/dist/{managed-server-7iurKxF1.d.cts → managed-server-CGmvVYsF.d.ts} +153 -148
- package/dist/{managed-server-CrZumvVU.d.ts → managed-server-CQb-RK-i.d.cts} +153 -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-.cjs';
|
|
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,184 @@ 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
|
+
/** Global kill switch. When false, no provider operation is allowed. */
|
|
250
|
+
enabled?: boolean | (() => boolean);
|
|
249
251
|
/** Defaults to the local in-memory quota implementation. */
|
|
250
|
-
quotaStore?:
|
|
252
|
+
quotaStore?: AiAppAssistantQuotaStore;
|
|
251
253
|
/** Environment or deployment defaults. They are never persisted automatically. */
|
|
252
|
-
defaultConfiguration?:
|
|
254
|
+
defaultConfiguration?: AiAppAssistantConfiguration | (() => AiAppAssistantConfiguration | undefined);
|
|
253
255
|
/** Resolves a secret supplied by the host environment or secret manager. */
|
|
254
|
-
resolveDefaultApiKey?: (provider:
|
|
256
|
+
resolveDefaultApiKey?: (provider: AiAppAssistantConfiguration["provider"]) => string | undefined;
|
|
255
257
|
apiKeyStorageAvailable?: boolean;
|
|
256
|
-
defaultQuota?:
|
|
258
|
+
defaultQuota?: AiAppAssistantQuotaPolicy;
|
|
257
259
|
connectionTimeoutMs?: number;
|
|
258
260
|
/** Minimum delay before retrying a disconnected provider on demand. */
|
|
259
261
|
reconnectIntervalMs?: number;
|
|
260
|
-
synchronizer?:
|
|
261
|
-
testConnection?: (input:
|
|
262
|
-
listModels?: (input:
|
|
262
|
+
synchronizer?: AiAppAssistantConfigurationSynchronizer;
|
|
263
|
+
testConnection?: (input: AiAppAssistantConnectionTestInput) => Promise<AiAppAssistantConnectionResult>;
|
|
264
|
+
listModels?: (input: AiAppAssistantCredentials) => Promise<AiModelInfo[]>;
|
|
263
265
|
now?: () => Date;
|
|
264
266
|
createId?: () => string;
|
|
265
267
|
logger?: Pick<Console, "info" | "warn">;
|
|
266
268
|
}
|
|
267
|
-
interface
|
|
269
|
+
interface AiAppAssistantConfigurationSaveResult {
|
|
268
270
|
saved: boolean;
|
|
269
|
-
connection:
|
|
270
|
-
configuration?:
|
|
271
|
+
connection: AiAppAssistantConnectionResult;
|
|
272
|
+
configuration?: AiAppAssistantManagedConfigurationView;
|
|
271
273
|
reloadRequired: boolean;
|
|
272
274
|
}
|
|
273
|
-
type
|
|
275
|
+
type AiAppAssistantManagementErrorCode = "unauthorized" | "forbidden" | "conflict" | "invalid_request" | "not_configured" | "assistant_disabled" | "quota_reached" | "secret_storage_unavailable";
|
|
274
276
|
/** Framework-neutral policy error that HTTP adapters can map safely. */
|
|
275
|
-
declare class
|
|
277
|
+
declare class AiAppAssistantManagementError extends Error {
|
|
276
278
|
readonly status: number;
|
|
277
|
-
readonly code:
|
|
279
|
+
readonly code: AiAppAssistantManagementErrorCode;
|
|
278
280
|
readonly details?: Record<string, unknown> | undefined;
|
|
279
|
-
constructor(status: number, code:
|
|
281
|
+
constructor(status: number, code: AiAppAssistantManagementErrorCode, message: string, details?: Record<string, unknown> | undefined);
|
|
280
282
|
}
|
|
281
283
|
/**
|
|
282
284
|
* Owns provider configuration, access, quota, audit and runtime connection
|
|
283
285
|
* state. Hosts only supply identity mapping, storage and optional defaults.
|
|
284
286
|
*/
|
|
285
|
-
declare class
|
|
287
|
+
declare class AiAppAssistantConfigurationManager {
|
|
286
288
|
#private;
|
|
287
|
-
constructor(options:
|
|
289
|
+
constructor(options: AiAppAssistantConfigurationManagerOptions);
|
|
290
|
+
/** Returns the current state of the host-controlled global kill switch. */
|
|
291
|
+
isEnabled(): boolean;
|
|
288
292
|
/** Returns the built-in provider catalogue; no credentials are exposed. */
|
|
289
293
|
listProviders(): AiProviderInfo[];
|
|
290
294
|
/** Discovers models with an explicit key or the currently configured secret. */
|
|
291
|
-
listModels(input:
|
|
295
|
+
listModels(input: AiAppAssistantCredentials): Promise<AiModelInfo[]>;
|
|
292
296
|
/** Notifies the runtime when a provider-affecting setting changes. */
|
|
293
|
-
subscribe(listener: (event:
|
|
297
|
+
subscribe(listener: (event: AiAppAssistantConfigurationChangeEvent) => Promise<void> | void): () => void;
|
|
294
298
|
/** Starts optional cross-instance invalidation. Calling it repeatedly is safe. */
|
|
295
299
|
startSynchronization(): Promise<void>;
|
|
296
300
|
dispose(): void;
|
|
297
301
|
/** Tests credentials and briefly caches a successful result for the next save. */
|
|
298
|
-
testConnection(input:
|
|
302
|
+
testConnection(input: AiAppAssistantConnectionTestInput): Promise<AiAppAssistantConnectionResult>;
|
|
299
303
|
/** Checks the effective stored/deployment connection used by live questions. */
|
|
300
304
|
validateRuntimeConnection(): Promise<boolean>;
|
|
301
305
|
/** Validates sensitive connection changes, persists safely and records their author. */
|
|
302
|
-
save(rawInput:
|
|
306
|
+
save(rawInput: AiAppAssistantConfigurationInput, actor: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantConfigurationSaveResult>;
|
|
303
307
|
/** Removes only the manual key, records the revocation and falls back to defaults. */
|
|
304
|
-
revokeApiKey(actor:
|
|
308
|
+
revokeApiKey(actor: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantManagedConfigurationView>;
|
|
305
309
|
/** Resolves persisted policy against deployment defaults, including the secret. */
|
|
306
|
-
getRuntimeConfiguration(): Promise<
|
|
310
|
+
getRuntimeConfiguration(): Promise<AiAppAssistantConfiguration | undefined>;
|
|
307
311
|
/** Returns the frontend-safe view: secret presence and permissions, never the key. */
|
|
308
|
-
getView(identity?:
|
|
312
|
+
getView(identity?: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantManagedConfigurationView>;
|
|
309
313
|
/** Minimal launcher state used by clients before rendering the assistant. */
|
|
310
|
-
getAccess(identity:
|
|
314
|
+
getAccess(identity: AiAppAssistantRuntimeIdentity): Promise<{
|
|
311
315
|
available: boolean;
|
|
312
316
|
maxConversationTurns: number;
|
|
313
317
|
}>;
|
|
314
318
|
/** Combines configuration, provider health and application access rules. */
|
|
315
|
-
canUse(identity:
|
|
319
|
+
canUse(identity: AiAppAssistantRuntimeIdentity): Promise<boolean>;
|
|
316
320
|
/** Atomically consumes one request from the user's active quota window. */
|
|
317
|
-
consumeQuota(identity:
|
|
321
|
+
consumeQuota(identity: AiAppAssistantRuntimeIdentity): Promise<AiAppAssistantQuotaResult>;
|
|
318
322
|
/** Enforces access and quota immediately before any model call. */
|
|
319
|
-
assertCanAsk(identity:
|
|
323
|
+
assertCanAsk(identity: AiAppAssistantRuntimeIdentity): Promise<void>;
|
|
320
324
|
/** Retries a failed provider lazily, with a shared backoff across requests. */
|
|
321
325
|
ensureRuntimeConnection(): Promise<boolean>;
|
|
322
326
|
private applyTestResultToActiveConfiguration;
|
|
@@ -329,6 +333,7 @@ declare class AiDocsConfigurationManager {
|
|
|
329
333
|
private connectionSignature;
|
|
330
334
|
private lastKnownConnection;
|
|
331
335
|
private now;
|
|
336
|
+
private assertEnabled;
|
|
332
337
|
private publishAndEmit;
|
|
333
338
|
private emit;
|
|
334
339
|
}
|
|
@@ -336,24 +341,24 @@ declare class AiDocsConfigurationManager {
|
|
|
336
341
|
* Portable cross-instance invalidation using any key/value store. It avoids a
|
|
337
342
|
* Redis-specific dependency and gives every process an eventual reload.
|
|
338
343
|
*/
|
|
339
|
-
declare function
|
|
344
|
+
declare function createPollingAiAppAssistantConfigurationSynchronizer(store: AiAppAssistantKeyValueStore, options?: {
|
|
340
345
|
key?: string;
|
|
341
346
|
intervalMs?: number;
|
|
342
|
-
}):
|
|
347
|
+
}): AiAppAssistantConfigurationSynchronizer;
|
|
343
348
|
|
|
344
|
-
type
|
|
345
|
-
interface
|
|
349
|
+
type AiAppAssistantGenerationOperation = "answer" | "stream";
|
|
350
|
+
interface AiAppAssistantGenerationEventBase {
|
|
346
351
|
requestId: string;
|
|
347
|
-
operation:
|
|
352
|
+
operation: AiAppAssistantGenerationOperation;
|
|
348
353
|
model: string;
|
|
349
354
|
durationMs: number;
|
|
350
355
|
occurredAt: string;
|
|
351
356
|
}
|
|
352
357
|
/** Safe operational event. It deliberately excludes prompts, HTML, users and credentials. */
|
|
353
|
-
type
|
|
358
|
+
type AiAppAssistantGenerationEvent = (AiAppAssistantGenerationEventBase & {
|
|
354
359
|
outcome: "success";
|
|
355
360
|
usage?: TokenUsage;
|
|
356
|
-
}) | (
|
|
361
|
+
}) | (AiAppAssistantGenerationEventBase & {
|
|
357
362
|
outcome: "failure";
|
|
358
363
|
error: {
|
|
359
364
|
code: AiSdkFailureCode;
|
|
@@ -363,7 +368,7 @@ type AiDocsGenerationEvent = (AiDocsGenerationEventBase & {
|
|
|
363
368
|
providerStatus?: number;
|
|
364
369
|
};
|
|
365
370
|
});
|
|
366
|
-
interface
|
|
371
|
+
interface AiAppAssistantTelemetrySummary {
|
|
367
372
|
requests: number;
|
|
368
373
|
succeeded: number;
|
|
369
374
|
failed: number;
|
|
@@ -373,43 +378,43 @@ interface AiDocsTelemetrySummary {
|
|
|
373
378
|
totalTokens: number;
|
|
374
379
|
failuresByCode: Partial<Record<AiSdkFailureCode, number>>;
|
|
375
380
|
}
|
|
376
|
-
type
|
|
381
|
+
type AiAppAssistantRecentFailure = Extract<AiAppAssistantGenerationEvent, {
|
|
377
382
|
outcome: "failure";
|
|
378
383
|
}>;
|
|
379
384
|
/** 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<
|
|
385
|
+
interface AiAppAssistantTelemetryStore {
|
|
386
|
+
record(event: AiAppAssistantGenerationEvent): Promise<void>;
|
|
387
|
+
summary(): Promise<AiAppAssistantTelemetrySummary>;
|
|
388
|
+
recentFailures(limit?: number): Promise<AiAppAssistantRecentFailure[]>;
|
|
384
389
|
}
|
|
385
390
|
/** Single-process telemetry intended for tests and local development. */
|
|
386
|
-
declare function
|
|
391
|
+
declare function createMemoryAiAppAssistantTelemetryStore(options?: {
|
|
387
392
|
recentFailureLimit?: number;
|
|
388
|
-
}):
|
|
393
|
+
}): AiAppAssistantTelemetryStore;
|
|
389
394
|
/** Minimal Redis shape; compatible with ioredis without adding it as a dependency. */
|
|
390
|
-
interface
|
|
395
|
+
interface AiAppAssistantRedisTelemetryClient {
|
|
391
396
|
eval(script: string, numberOfKeys: number, ...args: Array<string | number>): Promise<unknown>;
|
|
392
397
|
}
|
|
393
398
|
/**
|
|
394
399
|
* Shared Redis telemetry. One Lua call atomically updates counters and keeps a
|
|
395
400
|
* bounded failure list, so several application instances can safely share it.
|
|
396
401
|
*/
|
|
397
|
-
declare function
|
|
402
|
+
declare function createRedisAiAppAssistantTelemetryStore(client: AiAppAssistantRedisTelemetryClient, options?: {
|
|
398
403
|
prefix?: string;
|
|
399
404
|
recentFailureLimit?: number;
|
|
400
|
-
}):
|
|
405
|
+
}): AiAppAssistantTelemetryStore;
|
|
401
406
|
/** Converts any generator error to the same safe public diagnostic. */
|
|
402
|
-
declare function
|
|
407
|
+
declare function createAiAppAssistantFailureEvent(input: {
|
|
403
408
|
error: unknown;
|
|
404
409
|
requestId: string;
|
|
405
|
-
operation:
|
|
410
|
+
operation: AiAppAssistantGenerationOperation;
|
|
406
411
|
model: string;
|
|
407
412
|
durationMs: number;
|
|
408
|
-
}):
|
|
413
|
+
}): AiAppAssistantRecentFailure;
|
|
409
414
|
|
|
410
|
-
type AssistantPolicies = NonNullable<
|
|
411
|
-
interface
|
|
412
|
-
configuration:
|
|
415
|
+
type AssistantPolicies = NonNullable<AiAppAssistantOptions["policies"]>;
|
|
416
|
+
interface CreateManagedAiAppAssistantRuntimeOptions<TIdentity extends AiAppAssistantRuntimeIdentity> {
|
|
417
|
+
configuration: AiAppAssistantConfigurationManager;
|
|
413
418
|
documents?: DocumentationSource[];
|
|
414
419
|
policies?: AssistantPolicies;
|
|
415
420
|
/** Overrides the built-in `provider:model` AI SDK generator. */
|
|
@@ -420,36 +425,36 @@ interface CreateManagedAiDocsRuntimeOptions<TIdentity extends AiDocsRuntimeIdent
|
|
|
420
425
|
}) => AnswerGenerator | Promise<AnswerGenerator>;
|
|
421
426
|
timeoutMs?: number;
|
|
422
427
|
maxRetries?: number;
|
|
423
|
-
transformRequest?: (input:
|
|
424
|
-
transformResponse?: (output:
|
|
425
|
-
transformStreamEvent?: (event:
|
|
428
|
+
transformRequest?: (input: AiAppAssistantRequest, identity: TIdentity) => AiAppAssistantRequest | Promise<AiAppAssistantRequest>;
|
|
429
|
+
transformResponse?: (output: AiAppAssistantResponse, identity: TIdentity) => AiAppAssistantResponse | Promise<AiAppAssistantResponse>;
|
|
430
|
+
transformStreamEvent?: (event: AiAppAssistantStreamEvent, identity: TIdentity) => AiAppAssistantStreamEvent | Promise<AiAppAssistantStreamEvent>;
|
|
426
431
|
authorize?: (identity: TIdentity) => Promise<void> | void;
|
|
427
432
|
/** Receives provider/runtime failures without exposing prompts or credentials. */
|
|
428
433
|
onGenerationError?: (error: unknown, operation: "answer" | "stream", identity: TIdentity) => Promise<void> | void;
|
|
429
434
|
/** Receives one safe success/failure event per user request. */
|
|
430
|
-
onGenerationEvent?: (event:
|
|
435
|
+
onGenerationEvent?: (event: AiAppAssistantGenerationEvent, identity: TIdentity) => Promise<void> | void;
|
|
431
436
|
/** Optional persistence used by the batteries-included managed server. */
|
|
432
|
-
telemetryStore?:
|
|
437
|
+
telemetryStore?: AiAppAssistantTelemetryStore;
|
|
433
438
|
}
|
|
434
|
-
interface
|
|
435
|
-
readonly configuration:
|
|
436
|
-
readonly telemetry?:
|
|
439
|
+
interface ManagedAiAppAssistantRuntime<TIdentity extends AiAppAssistantRuntimeIdentity> {
|
|
440
|
+
readonly configuration: AiAppAssistantConfigurationManager;
|
|
441
|
+
readonly telemetry?: AiAppAssistantTelemetryStore;
|
|
437
442
|
initialize(): Promise<void>;
|
|
438
443
|
dispose(): void;
|
|
439
444
|
reload(connectionAlreadyValidated?: boolean): Promise<void>;
|
|
440
445
|
/** Replaces the stable documentation without recreating the configuration manager. */
|
|
441
446
|
setDocuments(documents: DocumentationSource[]): Promise<void>;
|
|
442
|
-
answer(input:
|
|
443
|
-
stream(input:
|
|
447
|
+
answer(input: AiAppAssistantRequest, identity: TIdentity): Promise<AiAppAssistantResponse>;
|
|
448
|
+
stream(input: AiAppAssistantRequest, identity: TIdentity, signal?: AbortSignal): AsyncGenerator<AiAppAssistantStreamEvent, AiAppAssistantResponse>;
|
|
444
449
|
}
|
|
445
450
|
/**
|
|
446
|
-
* Optional batteries-included runtime. The minimal `
|
|
451
|
+
* Optional batteries-included runtime. The minimal `createAiAppAssistant` API
|
|
447
452
|
* remains available for applications that want to own the lifecycle.
|
|
448
453
|
*/
|
|
449
|
-
declare function
|
|
454
|
+
declare function createManagedAiAppAssistantRuntime<TIdentity extends AiAppAssistantRuntimeIdentity>(options: CreateManagedAiAppAssistantRuntimeOptions<TIdentity>): ManagedAiAppAssistantRuntime<TIdentity>;
|
|
450
455
|
|
|
451
|
-
interface
|
|
452
|
-
runtime:
|
|
456
|
+
interface ManagedAiAppAssistantFetchHandlerOptions<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
457
|
+
runtime: ManagedAiAppAssistantRuntime<TIdentity>;
|
|
453
458
|
/** Required by default so application endpoints fail closed. */
|
|
454
459
|
resolveIdentity?: (request: Request, nativeContext: TNativeContext | undefined) => TIdentity | Promise<TIdentity>;
|
|
455
460
|
/** Explicit opt-in for public prototypes. Never enable it on authenticated applications. */
|
|
@@ -472,51 +477,51 @@ interface ManagedAiDocsFetchHandlerOptions<TIdentity extends AiDocsRuntimeIdenti
|
|
|
472
477
|
maxBodyBytes?: number;
|
|
473
478
|
onError?: (error: unknown, request: Request, nativeContext: TNativeContext | undefined) => Response | Promise<Response>;
|
|
474
479
|
}
|
|
475
|
-
interface
|
|
480
|
+
interface ManagedAiAppAssistantFetchHandlers<TNativeContext = undefined> {
|
|
476
481
|
handle(request: Request, nativeContext?: TNativeContext): Promise<Response>;
|
|
477
482
|
}
|
|
478
483
|
/** Complete framework-neutral chat and administration API. */
|
|
479
|
-
declare function
|
|
484
|
+
declare function createManagedAiAppAssistantFetchHandlers<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined>(options: ManagedAiAppAssistantFetchHandlerOptions<TIdentity, TNativeContext>): ManagedAiAppAssistantFetchHandlers<TNativeContext>;
|
|
480
485
|
|
|
481
|
-
type
|
|
486
|
+
type AiAppAssistantManagedStorage = {
|
|
482
487
|
type: "memory";
|
|
483
488
|
} | {
|
|
484
489
|
type: "redis";
|
|
485
|
-
client:
|
|
486
|
-
/** Shared namespace. Defaults to `ai-
|
|
490
|
+
client: AiAppAssistantRedisClient & AiAppAssistantRedisQuotaClient;
|
|
491
|
+
/** Shared namespace. Defaults to `ai-app-assistant:`. */
|
|
487
492
|
prefix?: string;
|
|
488
493
|
synchronizationIntervalMs?: number;
|
|
489
494
|
};
|
|
490
|
-
interface
|
|
495
|
+
interface AiAppAssistantManagedConfigurationSetup extends Omit<AiAppAssistantConfigurationManagerOptions, "apiKeyStorageAvailable" | "quotaStore" | "repository" | "synchronizer"> {
|
|
491
496
|
/** Creates configuration, quota and synchronization adapters automatically. */
|
|
492
|
-
storage?:
|
|
497
|
+
storage?: AiAppAssistantManagedStorage;
|
|
493
498
|
/** AES-256-GCM key used to persist administrator-supplied API keys. */
|
|
494
499
|
encryptionKey?: string;
|
|
495
500
|
/** Alternative secret manager; takes precedence over encryptionKey. */
|
|
496
|
-
secretProtector?:
|
|
501
|
+
secretProtector?: AiAppAssistantSecretProtector;
|
|
497
502
|
repositoryKey?: string;
|
|
498
|
-
quotaStore?:
|
|
499
|
-
synchronizer?:
|
|
503
|
+
quotaStore?: AiAppAssistantQuotaStore;
|
|
504
|
+
synchronizer?: AiAppAssistantConfigurationManagerOptions["synchronizer"];
|
|
500
505
|
apiKeyStorageAvailable?: boolean;
|
|
501
506
|
}
|
|
502
|
-
interface
|
|
507
|
+
interface CreateManagedAiAppAssistantServerOptions<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
503
508
|
/** Pass an existing manager, or its construction options for the common case. */
|
|
504
|
-
configuration:
|
|
509
|
+
configuration: AiAppAssistantConfigurationManager | AiAppAssistantConfigurationManagerOptions | AiAppAssistantManagedConfigurationSetup;
|
|
505
510
|
/** Stable application documentation. It can also be supplied later with setDocuments(). */
|
|
506
511
|
documents?: DocumentationSource[];
|
|
507
|
-
runtime?: Omit<
|
|
508
|
-
http?: Omit<
|
|
512
|
+
runtime?: Omit<CreateManagedAiAppAssistantRuntimeOptions<TIdentity>, "configuration" | "documents">;
|
|
513
|
+
http?: Omit<ManagedAiAppAssistantFetchHandlerOptions<TIdentity, TNativeContext>, "runtime">;
|
|
509
514
|
/** Enabled by default; Redis configuration automatically makes it persistent. */
|
|
510
515
|
telemetry?: false | {
|
|
511
|
-
store?:
|
|
516
|
+
store?: AiAppAssistantTelemetryStore;
|
|
512
517
|
recentFailureLimit?: number;
|
|
513
518
|
};
|
|
514
519
|
}
|
|
515
|
-
interface
|
|
516
|
-
readonly configuration:
|
|
517
|
-
readonly runtime:
|
|
518
|
-
readonly fetch:
|
|
519
|
-
readonly telemetry?:
|
|
520
|
+
interface ManagedAiAppAssistantServer<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined> {
|
|
521
|
+
readonly configuration: AiAppAssistantConfigurationManager;
|
|
522
|
+
readonly runtime: ManagedAiAppAssistantRuntime<TIdentity>;
|
|
523
|
+
readonly fetch: ManagedAiAppAssistantFetchHandlers<TNativeContext>;
|
|
524
|
+
readonly telemetry?: AiAppAssistantTelemetryStore;
|
|
520
525
|
initialize(): Promise<void>;
|
|
521
526
|
setDocuments(documents: DocumentationSource[]): Promise<void>;
|
|
522
527
|
dispose(): void;
|
|
@@ -528,6 +533,6 @@ interface ManagedAiDocsServer<TIdentity extends AiDocsRuntimeIdentity, TNativeCo
|
|
|
528
533
|
* Framework integrations only need to adapt their native request/response and
|
|
529
534
|
* pass the authenticated application identity through `http.resolveIdentity`.
|
|
530
535
|
*/
|
|
531
|
-
declare function
|
|
536
|
+
declare function createManagedAiAppAssistantServer<TIdentity extends AiAppAssistantRuntimeIdentity, TNativeContext = undefined>(options: CreateManagedAiAppAssistantServerOptions<TIdentity, TNativeContext>): ManagedAiAppAssistantServer<TIdentity, TNativeContext>;
|
|
532
537
|
|
|
533
|
-
export {
|
|
538
|
+
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 };
|