@123toto/ai-app-assistant-server 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ai-sdk-qU3KgNu-.d.cts → ai-sdk-Ipf8hBLm.d.cts} +3 -2
- package/dist/{ai-sdk-qU3KgNu-.d.ts → ai-sdk-Ipf8hBLm.d.ts} +3 -2
- package/dist/ai-sdk.cjs +5 -12
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/ai-sdk.js +1 -1
- package/dist/{chunk-NIF6AW6I.js → chunk-GVTOAUU3.js} +6 -13
- package/dist/chunk-GVTOAUU3.js.map +1 -0
- package/dist/express.d.cts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/index.cjs +64 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +27 -22
- package/dist/index.js.map +1 -1
- package/dist/{managed-server-CusQWWBB.d.ts → managed-server-B9146OrJ.d.ts} +1 -1
- package/dist/{managed-server-wXfu_9rp.d.cts → managed-server-DrglkZqp.d.cts} +1 -1
- package/dist/nest.d.cts +2 -2
- package/dist/nest.d.ts +2 -2
- package/package.json +2 -2
- package/dist/chunk-NIF6AW6I.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -573,7 +573,6 @@ async function writeResponse(response, webResponse) {
|
|
|
573
573
|
|
|
574
574
|
// src/ai-sdk.ts
|
|
575
575
|
var import_ai = require("ai");
|
|
576
|
-
var import_zod2 = require("zod");
|
|
577
576
|
var import_anthropic = require("@ai-sdk/anthropic");
|
|
578
577
|
var import_google = require("@ai-sdk/google");
|
|
579
578
|
var import_mistral = require("@ai-sdk/mistral");
|
|
@@ -701,20 +700,14 @@ async function testAiSdkConnection(options) {
|
|
|
701
700
|
const displayModel = typeof options.model === "string" ? options.model.trim() : `ai-sdk:${options.model.provider}:${options.model.modelId}`;
|
|
702
701
|
try {
|
|
703
702
|
const resolved = resolveModel(options);
|
|
704
|
-
|
|
703
|
+
await (0, import_ai.generateText)({
|
|
705
704
|
model: resolved.model,
|
|
706
705
|
maxRetries: 0,
|
|
707
|
-
maxOutputTokens:
|
|
708
|
-
timeout: clampInteger2(options.timeoutMs ?? 15e3, 1e3,
|
|
709
|
-
system: "
|
|
710
|
-
prompt: "
|
|
711
|
-
output: import_ai.Output.object({
|
|
712
|
-
schema: import_zod2.z.object({ status: import_zod2.z.literal("ok") })
|
|
713
|
-
})
|
|
706
|
+
maxOutputTokens: 8,
|
|
707
|
+
timeout: clampInteger2(options.timeoutMs ?? 15e3, 1e3, 12e4),
|
|
708
|
+
system: "This is a connectivity check. Reply briefly.",
|
|
709
|
+
prompt: "Reply with OK."
|
|
714
710
|
});
|
|
715
|
-
if (result.output.status !== "ok") {
|
|
716
|
-
throw new Error("The model returned an invalid connectivity result");
|
|
717
|
-
}
|
|
718
711
|
return {
|
|
719
712
|
success: true,
|
|
720
713
|
model: displayModel,
|
|
@@ -1130,52 +1123,52 @@ var import_node_crypto3 = require("crypto");
|
|
|
1130
1123
|
|
|
1131
1124
|
// src/configuration.ts
|
|
1132
1125
|
var import_node_crypto = require("crypto");
|
|
1133
|
-
var
|
|
1126
|
+
var import_zod2 = require("zod");
|
|
1134
1127
|
var AiAppAssistantConfigurationConflictError = class extends Error {
|
|
1135
1128
|
constructor() {
|
|
1136
1129
|
super("AI App Assistant configuration changed concurrently; retry the operation");
|
|
1137
1130
|
this.name = "AiAppAssistantConfigurationConflictError";
|
|
1138
1131
|
}
|
|
1139
1132
|
};
|
|
1140
|
-
var accessRuleSchema =
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1133
|
+
var accessRuleSchema = import_zod2.z.discriminatedUnion("mode", [
|
|
1134
|
+
import_zod2.z.object({ mode: import_zod2.z.literal("all") }),
|
|
1135
|
+
import_zod2.z.object({ mode: import_zod2.z.literal("roles"), roles: import_zod2.z.array(import_zod2.z.string().min(1)).min(1) }),
|
|
1136
|
+
import_zod2.z.object({ mode: import_zod2.z.literal("users"), userIds: import_zod2.z.array(import_zod2.z.string().min(1)).min(1) })
|
|
1144
1137
|
]);
|
|
1145
|
-
var actorSchema =
|
|
1146
|
-
id:
|
|
1147
|
-
label:
|
|
1138
|
+
var actorSchema = import_zod2.z.object({
|
|
1139
|
+
id: import_zod2.z.string().min(1),
|
|
1140
|
+
label: import_zod2.z.string().min(1)
|
|
1148
1141
|
});
|
|
1149
|
-
var administrationSchema =
|
|
1142
|
+
var administrationSchema = import_zod2.z.object({
|
|
1150
1143
|
keyCreatedBy: actorSchema.optional(),
|
|
1151
|
-
keyCreatedAt:
|
|
1144
|
+
keyCreatedAt: import_zod2.z.string().datetime().optional(),
|
|
1152
1145
|
modelUpdatedBy: actorSchema.optional(),
|
|
1153
|
-
modelUpdatedAt:
|
|
1154
|
-
allowModelChangesByOthers:
|
|
1155
|
-
history:
|
|
1156
|
-
id:
|
|
1146
|
+
modelUpdatedAt: import_zod2.z.string().datetime().optional(),
|
|
1147
|
+
allowModelChangesByOthers: import_zod2.z.boolean(),
|
|
1148
|
+
history: import_zod2.z.array(import_zod2.z.object({
|
|
1149
|
+
id: import_zod2.z.string().min(1),
|
|
1157
1150
|
actor: actorSchema,
|
|
1158
|
-
changedAt:
|
|
1159
|
-
changes:
|
|
1160
|
-
field:
|
|
1161
|
-
from:
|
|
1162
|
-
to:
|
|
1151
|
+
changedAt: import_zod2.z.string().datetime(),
|
|
1152
|
+
changes: import_zod2.z.array(import_zod2.z.object({
|
|
1153
|
+
field: import_zod2.z.enum(["provider", "apiKey", "model", "access", "quota", "conversation", "modelChangePolicy"]),
|
|
1154
|
+
from: import_zod2.z.string().optional(),
|
|
1155
|
+
to: import_zod2.z.string().optional()
|
|
1163
1156
|
})).min(1)
|
|
1164
1157
|
})).max(200)
|
|
1165
1158
|
});
|
|
1166
|
-
var persistedConfigurationSchema =
|
|
1167
|
-
version:
|
|
1168
|
-
provider:
|
|
1169
|
-
model:
|
|
1170
|
-
connectionSource:
|
|
1171
|
-
protectedApiKey:
|
|
1172
|
-
baseURL:
|
|
1159
|
+
var persistedConfigurationSchema = import_zod2.z.object({
|
|
1160
|
+
version: import_zod2.z.literal(1),
|
|
1161
|
+
provider: import_zod2.z.enum(["anthropic", "google", "mistral", "ollama", "openai"]),
|
|
1162
|
+
model: import_zod2.z.string().min(1),
|
|
1163
|
+
connectionSource: import_zod2.z.enum(["environment", "override"]).optional(),
|
|
1164
|
+
protectedApiKey: import_zod2.z.string().min(1).optional(),
|
|
1165
|
+
baseURL: import_zod2.z.string().url().optional(),
|
|
1173
1166
|
access: accessRuleSchema,
|
|
1174
|
-
quota:
|
|
1175
|
-
maxRequests:
|
|
1176
|
-
windowSeconds:
|
|
1167
|
+
quota: import_zod2.z.object({
|
|
1168
|
+
maxRequests: import_zod2.z.number().int().positive(),
|
|
1169
|
+
windowSeconds: import_zod2.z.number().int().positive()
|
|
1177
1170
|
}).optional(),
|
|
1178
|
-
maxConversationTurns:
|
|
1171
|
+
maxConversationTurns: import_zod2.z.number().int().min(1).max(10).optional(),
|
|
1179
1172
|
administration: administrationSchema.optional()
|
|
1180
1173
|
});
|
|
1181
1174
|
function createAiAppAssistantConfigurationRepository(options) {
|
|
@@ -1335,7 +1328,7 @@ function createRedisAiAppAssistantStore(client, options) {
|
|
|
1335
1328
|
}
|
|
1336
1329
|
function normalizeConfiguration(configuration) {
|
|
1337
1330
|
const parsed = persistedConfigurationSchema.omit({ version: true, protectedApiKey: true }).extend({
|
|
1338
|
-
apiKey:
|
|
1331
|
+
apiKey: import_zod2.z.string().min(1).optional()
|
|
1339
1332
|
}).parse({
|
|
1340
1333
|
...configuration,
|
|
1341
1334
|
model: configuration.model.trim(),
|
|
@@ -1686,7 +1679,7 @@ var AiAppAssistantConfigurationManager = class {
|
|
|
1686
1679
|
model: `${input.provider}:${input.model}`,
|
|
1687
1680
|
...apiKey ? { apiKey } : {},
|
|
1688
1681
|
...input.baseURL ? { baseURL: input.baseURL } : {},
|
|
1689
|
-
timeoutMs:
|
|
1682
|
+
timeoutMs: this.#options.connectionTimeoutMs ?? 15e3
|
|
1690
1683
|
});
|
|
1691
1684
|
if (connection.success) {
|
|
1692
1685
|
this.#recentConnectionValidation = {
|
|
@@ -1731,14 +1724,18 @@ var AiAppAssistantConfigurationManager = class {
|
|
|
1731
1724
|
model: `${configuration.provider}:${configuration.model}`,
|
|
1732
1725
|
...configuration.apiKey ? { apiKey: configuration.apiKey } : {},
|
|
1733
1726
|
...configuration.baseURL ? { baseURL: configuration.baseURL } : {},
|
|
1734
|
-
timeoutMs:
|
|
1727
|
+
timeoutMs: this.#options.connectionTimeoutMs ?? 15e3
|
|
1735
1728
|
}));
|
|
1736
1729
|
this.#runtimeConnection = {
|
|
1737
1730
|
status: result.success ? "connected" : "disconnected",
|
|
1738
1731
|
checkedAt: this.now(),
|
|
1739
1732
|
model: result.model
|
|
1740
1733
|
};
|
|
1741
|
-
if (!result.success)
|
|
1734
|
+
if (!result.success) {
|
|
1735
|
+
this.#options.logger?.warn(
|
|
1736
|
+
`AI assistant connection failed: ${result.error.code}: ${result.error.message}`
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1742
1739
|
return result.success;
|
|
1743
1740
|
}
|
|
1744
1741
|
/** Validates sensitive connection changes, persists safely and records their author. */
|
|
@@ -2021,23 +2018,22 @@ var AiAppAssistantConfigurationManager = class {
|
|
|
2021
2018
|
async ensureRuntimeConnection() {
|
|
2022
2019
|
if (!this.isEnabled()) return false;
|
|
2023
2020
|
if (this.#runtimeConnection.status === "connected") return true;
|
|
2021
|
+
if (this.#reconnectPromise) return this.#reconnectPromise;
|
|
2024
2022
|
const intervalMs = Math.max(1e3, this.#options.reconnectIntervalMs ?? 3e4);
|
|
2025
2023
|
if (Date.now() - this.#lastReconnectAttempt < intervalMs) return false;
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
});
|
|
2040
|
-
}
|
|
2024
|
+
this.#reconnectPromise = this.validateRuntimeConnection().then(async (connected) => {
|
|
2025
|
+
if (connected) {
|
|
2026
|
+
await this.publishAndEmit({
|
|
2027
|
+
reason: "connection-tested",
|
|
2028
|
+
reloadRequired: true,
|
|
2029
|
+
connectionValidated: true,
|
|
2030
|
+
remote: false
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
return connected;
|
|
2034
|
+
}).finally(() => {
|
|
2035
|
+
this.#reconnectPromise = void 0;
|
|
2036
|
+
});
|
|
2041
2037
|
return this.#reconnectPromise;
|
|
2042
2038
|
}
|
|
2043
2039
|
async applyTestResultToActiveConfiguration(input, result, apiKey) {
|
|
@@ -2473,13 +2469,15 @@ function createManagedAiAppAssistantRuntime(options) {
|
|
|
2473
2469
|
return {
|
|
2474
2470
|
configuration: options.configuration,
|
|
2475
2471
|
...options.telemetryStore ? { telemetry: options.telemetryStore } : {},
|
|
2476
|
-
/**
|
|
2472
|
+
/**
|
|
2473
|
+
* Starts synchronization immediately, then validates the optional provider
|
|
2474
|
+
* in the background so an unavailable LLM never delays the host bootstrap.
|
|
2475
|
+
*/
|
|
2477
2476
|
async initialize() {
|
|
2478
2477
|
if (initialized) return;
|
|
2479
2478
|
initialized = true;
|
|
2480
2479
|
await options.configuration.startSynchronization();
|
|
2481
|
-
|
|
2482
|
-
await rebuild({ connectionValidated: connected });
|
|
2480
|
+
void options.configuration.ensureRuntimeConnection().catch(() => void 0);
|
|
2483
2481
|
},
|
|
2484
2482
|
dispose() {
|
|
2485
2483
|
initialized = false;
|
|
@@ -2586,7 +2584,7 @@ function unavailable() {
|
|
|
2586
2584
|
|
|
2587
2585
|
// src/managed-http.ts
|
|
2588
2586
|
var import_ai_app_assistant_contracts4 = require("@123toto/ai-app-assistant-contracts");
|
|
2589
|
-
var
|
|
2587
|
+
var import_zod3 = require("zod");
|
|
2590
2588
|
function createManagedAiAppAssistantFetchHandlers(options) {
|
|
2591
2589
|
const identity = async (request, nativeContext) => {
|
|
2592
2590
|
if (options.resolveIdentity) return options.resolveIdentity(request, nativeContext);
|
|
@@ -2727,7 +2725,7 @@ function mapError2(error) {
|
|
|
2727
2725
|
if (error instanceof AiAppAssistantManagementError) {
|
|
2728
2726
|
return json({ error: error.code, message: error.message, ...error.details }, error.status);
|
|
2729
2727
|
}
|
|
2730
|
-
if (error instanceof
|
|
2728
|
+
if (error instanceof import_zod3.ZodError || error instanceof SyntaxError) {
|
|
2731
2729
|
return json({ error: "invalid_request", message: "The assistant request is invalid." }, 400);
|
|
2732
2730
|
}
|
|
2733
2731
|
return json({ error: "assistant_error", message: "The assistant response could not be generated." }, 500);
|