@axiom-lattice/gateway 2.1.12 → 2.1.13
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +10 -0
- package/README.md +53 -0
- package/dist/index.js +379 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +377 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/config.ts +124 -0
- package/src/controllers/config.ts +126 -0
- package/src/controllers/models.ts +152 -0
- package/src/routes/index.ts +26 -0
- package/src/schemas/index.ts +74 -0
- package/src/services/supabase.ts +44 -10
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/gateway@2.1.
|
|
2
|
+
> @axiom-lattice/gateway@2.1.13 build /home/runner/work/agentic/agentic/packages/gateway
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --clean --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m58.53 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m121.16 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 156ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m56.17 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m121.06 KB[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 156ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 6271ms
|
|
20
20
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.32 KB[39m
|
|
21
21
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.32 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @axiom-lattice/gateway
|
|
2
2
|
|
|
3
|
+
## 2.1.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d9beb3a: update setting
|
|
8
|
+
- Updated dependencies [d9beb3a]
|
|
9
|
+
- @axiom-lattice/core@2.1.9
|
|
10
|
+
- @axiom-lattice/protocols@2.1.4
|
|
11
|
+
- @axiom-lattice/queue-redis@1.0.3
|
|
12
|
+
|
|
3
13
|
## 2.1.12
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -29,6 +29,59 @@ pnpm start
|
|
|
29
29
|
|
|
30
30
|
## API 接口
|
|
31
31
|
|
|
32
|
+
### Configuration API
|
|
33
|
+
|
|
34
|
+
The gateway supports dynamic configuration updates via JSON. You can update environment variables at runtime without restarting the server.
|
|
35
|
+
|
|
36
|
+
#### Get Configuration
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
GET /api/config
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Returns the current configuration (sensitive values are masked).
|
|
43
|
+
|
|
44
|
+
#### Update Configuration
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
PUT /api/config
|
|
48
|
+
Content-Type: application/json
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
"config": {
|
|
52
|
+
"port": 4001,
|
|
53
|
+
"queueServiceType": "redis",
|
|
54
|
+
"redisUrl": "redis://localhost:6379",
|
|
55
|
+
"redisPassword": "your-password",
|
|
56
|
+
"queueName": "tasks"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Note**: When updating `queueServiceType`, the queue service will be automatically reconfigured.
|
|
62
|
+
|
|
63
|
+
**Example**:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Update configuration from frontend
|
|
67
|
+
const response = await fetch("http://localhost:4001/api/config", {
|
|
68
|
+
method: "PUT",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
config: {
|
|
74
|
+
queueServiceType: "redis",
|
|
75
|
+
redisUrl: "redis://localhost:6379",
|
|
76
|
+
redisPassword: "your-password",
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const result = await response.json();
|
|
82
|
+
console.log(result); // { success: true, message: "Configuration updated successfully", data: {...} }
|
|
83
|
+
```
|
|
84
|
+
|
|
32
85
|
### 代理调用
|
|
33
86
|
|
|
34
87
|
- `POST /api/v1/run`: 运行代理
|
package/dist/index.js
CHANGED
|
@@ -952,6 +952,296 @@ async function deleteThread(request, reply) {
|
|
|
952
952
|
};
|
|
953
953
|
}
|
|
954
954
|
|
|
955
|
+
// src/config.ts
|
|
956
|
+
var ConfigService = class {
|
|
957
|
+
constructor() {
|
|
958
|
+
this.config = this.loadFromEnv();
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Load configuration from environment variables
|
|
962
|
+
*/
|
|
963
|
+
loadFromEnv() {
|
|
964
|
+
return {
|
|
965
|
+
port: process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
966
|
+
queueServiceType: process.env.QUEUE_SERVICE_TYPE,
|
|
967
|
+
redisUrl: process.env.REDIS_URL,
|
|
968
|
+
redisPassword: process.env.REDIS_PASSWORD,
|
|
969
|
+
queueName: process.env.QUEUE_NAME
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Update configuration from JSON object
|
|
974
|
+
* This will update both the internal config and process.env
|
|
975
|
+
*/
|
|
976
|
+
updateConfig(jsonConfig) {
|
|
977
|
+
for (const [key, value] of Object.entries(jsonConfig)) {
|
|
978
|
+
if (value !== null && value !== void 0) {
|
|
979
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
980
|
+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
|
981
|
+
const envKey = `${key.toUpperCase()}_${nestedKey.toUpperCase()}`;
|
|
982
|
+
process.env[envKey] = String(nestedValue);
|
|
983
|
+
}
|
|
984
|
+
} else {
|
|
985
|
+
process.env[key.toUpperCase()] = String(value);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
this.config = this.loadFromEnv();
|
|
990
|
+
this.config = this.deepMerge(this.config, jsonConfig);
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Deep merge two objects
|
|
994
|
+
*/
|
|
995
|
+
deepMerge(target, source) {
|
|
996
|
+
const output = { ...target };
|
|
997
|
+
if (this.isObject(target) && this.isObject(source)) {
|
|
998
|
+
Object.keys(source).forEach((key) => {
|
|
999
|
+
if (this.isObject(source[key])) {
|
|
1000
|
+
if (!(key in target)) {
|
|
1001
|
+
Object.assign(output, { [key]: source[key] });
|
|
1002
|
+
} else {
|
|
1003
|
+
output[key] = this.deepMerge(target[key], source[key]);
|
|
1004
|
+
}
|
|
1005
|
+
} else {
|
|
1006
|
+
Object.assign(output, { [key]: source[key] });
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return output;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Check if value is a plain object
|
|
1014
|
+
*/
|
|
1015
|
+
isObject(item) {
|
|
1016
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Get current configuration
|
|
1020
|
+
*/
|
|
1021
|
+
getConfig() {
|
|
1022
|
+
return { ...this.config };
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
var configService = new ConfigService();
|
|
1026
|
+
|
|
1027
|
+
// src/services/queue_service.ts
|
|
1028
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
1029
|
+
var import_protocols = require("@axiom-lattice/protocols");
|
|
1030
|
+
var import_queue_redis = require("@axiom-lattice/queue-redis");
|
|
1031
|
+
var DEFAULT_QUEUE_KEY = "default";
|
|
1032
|
+
var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
|
|
1033
|
+
var setQueueServiceType = (type) => {
|
|
1034
|
+
queueServiceType = type;
|
|
1035
|
+
console.log(`Queue service type set to: ${type}`);
|
|
1036
|
+
const queueName = process.env.QUEUE_NAME || "tasks";
|
|
1037
|
+
const config = {
|
|
1038
|
+
name: "Default Queue Service",
|
|
1039
|
+
description: `Default ${type} queue service`,
|
|
1040
|
+
type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
|
|
1041
|
+
queueName,
|
|
1042
|
+
options: type === "redis" ? {
|
|
1043
|
+
redisUrl: process.env.REDIS_URL,
|
|
1044
|
+
redisPassword: process.env.REDIS_PASSWORD
|
|
1045
|
+
} : void 0
|
|
1046
|
+
};
|
|
1047
|
+
if (import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1048
|
+
import_core4.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
|
|
1049
|
+
}
|
|
1050
|
+
let client;
|
|
1051
|
+
if (type === "redis") {
|
|
1052
|
+
client = new import_queue_redis.RedisQueueClient(queueName, {
|
|
1053
|
+
redisUrl: process.env.REDIS_URL,
|
|
1054
|
+
redisPassword: process.env.REDIS_PASSWORD
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
(0, import_core4.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
|
|
1058
|
+
};
|
|
1059
|
+
var getQueueService = () => {
|
|
1060
|
+
if (!import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1061
|
+
setQueueServiceType(queueServiceType);
|
|
1062
|
+
}
|
|
1063
|
+
return (0, import_core4.getQueueLattice)(DEFAULT_QUEUE_KEY);
|
|
1064
|
+
};
|
|
1065
|
+
var popAgentTaskFromQueue = async () => {
|
|
1066
|
+
const queue = getQueueService();
|
|
1067
|
+
const result = await queue.pop();
|
|
1068
|
+
return result;
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1071
|
+
// src/controllers/config.ts
|
|
1072
|
+
async function updateConfig(request, reply) {
|
|
1073
|
+
try {
|
|
1074
|
+
const { config: jsonConfig } = request.body;
|
|
1075
|
+
if (!jsonConfig || typeof jsonConfig !== "object") {
|
|
1076
|
+
return reply.status(400).send({
|
|
1077
|
+
success: false,
|
|
1078
|
+
error: "Invalid configuration: config must be an object"
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
configService.updateConfig(jsonConfig);
|
|
1082
|
+
const warnings = [];
|
|
1083
|
+
const requiresRestart = [];
|
|
1084
|
+
if (jsonConfig.port !== void 0) {
|
|
1085
|
+
requiresRestart.push("PORT");
|
|
1086
|
+
warnings.push("Port change requires server restart to take effect");
|
|
1087
|
+
}
|
|
1088
|
+
if (jsonConfig.queueServiceType) {
|
|
1089
|
+
setQueueServiceType(jsonConfig.queueServiceType);
|
|
1090
|
+
}
|
|
1091
|
+
if ((jsonConfig.redisUrl || jsonConfig.redisPassword) && (process.env.QUEUE_SERVICE_TYPE === "redis" || jsonConfig.queueServiceType === "redis")) {
|
|
1092
|
+
const currentType = jsonConfig.queueServiceType || process.env.QUEUE_SERVICE_TYPE || "memory";
|
|
1093
|
+
if (currentType === "redis") {
|
|
1094
|
+
setQueueServiceType("redis");
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const updatedConfig = configService.getConfig();
|
|
1098
|
+
const safeConfig = {
|
|
1099
|
+
...updatedConfig,
|
|
1100
|
+
redisPassword: updatedConfig.redisPassword ? "***" : updatedConfig.redisPassword
|
|
1101
|
+
};
|
|
1102
|
+
return reply.send({
|
|
1103
|
+
success: true,
|
|
1104
|
+
message: "Configuration updated successfully",
|
|
1105
|
+
data: safeConfig,
|
|
1106
|
+
warnings: warnings.length > 0 ? warnings : void 0,
|
|
1107
|
+
requiresRestart: requiresRestart.length > 0 ? requiresRestart : void 0
|
|
1108
|
+
});
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
console.error("Failed to update configuration", {
|
|
1111
|
+
error: error.message,
|
|
1112
|
+
stack: error.stack
|
|
1113
|
+
});
|
|
1114
|
+
return reply.status(500).send({
|
|
1115
|
+
success: false,
|
|
1116
|
+
error: error.message || "Failed to update configuration"
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
async function getConfig(request, reply) {
|
|
1121
|
+
try {
|
|
1122
|
+
const currentConfig = configService.getConfig();
|
|
1123
|
+
const safeConfig = {
|
|
1124
|
+
...currentConfig,
|
|
1125
|
+
redisPassword: currentConfig.redisPassword ? "***" : currentConfig.redisPassword
|
|
1126
|
+
};
|
|
1127
|
+
return reply.send({
|
|
1128
|
+
success: true,
|
|
1129
|
+
data: safeConfig
|
|
1130
|
+
});
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
console.error("Failed to get configuration", {
|
|
1133
|
+
error: error.message,
|
|
1134
|
+
stack: error.stack
|
|
1135
|
+
});
|
|
1136
|
+
return reply.status(500).send({
|
|
1137
|
+
success: false,
|
|
1138
|
+
error: error.message || "Failed to get configuration"
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// src/controllers/models.ts
|
|
1144
|
+
var import_core5 = require("@axiom-lattice/core");
|
|
1145
|
+
async function getModels(request, reply) {
|
|
1146
|
+
try {
|
|
1147
|
+
const allLattices = import_core5.modelLatticeManager.getAllLattices();
|
|
1148
|
+
const models = allLattices.map((lattice) => {
|
|
1149
|
+
const config = lattice.client.config || {};
|
|
1150
|
+
return {
|
|
1151
|
+
key: lattice.key,
|
|
1152
|
+
model: config.model || "",
|
|
1153
|
+
provider: config.provider || "openai",
|
|
1154
|
+
streaming: config.streaming || false,
|
|
1155
|
+
apiKey: config.apiKey || "",
|
|
1156
|
+
baseURL: config.baseURL || "",
|
|
1157
|
+
maxTokens: config.maxTokens,
|
|
1158
|
+
temperature: config.temperature,
|
|
1159
|
+
timeout: config.timeout,
|
|
1160
|
+
maxRetries: config.maxRetries
|
|
1161
|
+
};
|
|
1162
|
+
});
|
|
1163
|
+
return reply.send({
|
|
1164
|
+
success: true,
|
|
1165
|
+
data: models
|
|
1166
|
+
});
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
console.error("Failed to get models", {
|
|
1169
|
+
error: error.message,
|
|
1170
|
+
stack: error.stack
|
|
1171
|
+
});
|
|
1172
|
+
return reply.status(500).send({
|
|
1173
|
+
success: false,
|
|
1174
|
+
error: error.message || "Failed to get models"
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
async function updateModels(request, reply) {
|
|
1179
|
+
try {
|
|
1180
|
+
const { models } = request.body;
|
|
1181
|
+
if (!models || !Array.isArray(models)) {
|
|
1182
|
+
return reply.status(400).send({
|
|
1183
|
+
success: false,
|
|
1184
|
+
error: "Invalid request: models must be an array"
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
const registeredModels = [];
|
|
1188
|
+
const errors = [];
|
|
1189
|
+
for (const modelConfig of models) {
|
|
1190
|
+
if (!modelConfig.key || !modelConfig.model || !modelConfig.provider) {
|
|
1191
|
+
errors.push(
|
|
1192
|
+
`Model configuration is incomplete: key, model, and provider are required`
|
|
1193
|
+
);
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
try {
|
|
1197
|
+
if (import_core5.modelLatticeManager.hasLattice(modelConfig.key)) {
|
|
1198
|
+
import_core5.modelLatticeManager.removeLattice(modelConfig.key);
|
|
1199
|
+
}
|
|
1200
|
+
const llmConfig = {
|
|
1201
|
+
provider: modelConfig.provider,
|
|
1202
|
+
model: modelConfig.model,
|
|
1203
|
+
streaming: modelConfig.streaming ?? false,
|
|
1204
|
+
apiKey: modelConfig.apiKey,
|
|
1205
|
+
baseURL: modelConfig.baseURL,
|
|
1206
|
+
maxTokens: modelConfig.maxTokens,
|
|
1207
|
+
temperature: modelConfig.temperature,
|
|
1208
|
+
timeout: modelConfig.timeout,
|
|
1209
|
+
maxRetries: modelConfig.maxRetries
|
|
1210
|
+
};
|
|
1211
|
+
(0, import_core5.registerModelLattice)(modelConfig.key, llmConfig);
|
|
1212
|
+
registeredModels.push(modelConfig.key);
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
errors.push(
|
|
1215
|
+
`Failed to register model ${modelConfig.key}: ${error.message}`
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (errors.length > 0 && registeredModels.length === 0) {
|
|
1220
|
+
return reply.status(400).send({
|
|
1221
|
+
success: false,
|
|
1222
|
+
error: errors.join("; ")
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
return reply.send({
|
|
1226
|
+
success: true,
|
|
1227
|
+
message: `Successfully registered ${registeredModels.length} model(s)`,
|
|
1228
|
+
data: {
|
|
1229
|
+
registered: registeredModels,
|
|
1230
|
+
errors: errors.length > 0 ? errors : void 0
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
console.error("Failed to update models", {
|
|
1235
|
+
error: error.message,
|
|
1236
|
+
stack: error.stack
|
|
1237
|
+
});
|
|
1238
|
+
return reply.status(500).send({
|
|
1239
|
+
success: false,
|
|
1240
|
+
error: error.message || "Failed to update models"
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
|
|
955
1245
|
// src/schemas/index.ts
|
|
956
1246
|
var getAllMemoryItemsSchema = {
|
|
957
1247
|
description: "Get all memory items for an assistant thread",
|
|
@@ -1120,6 +1410,77 @@ var triggerAgentTaskSchema = {
|
|
|
1120
1410
|
}
|
|
1121
1411
|
}
|
|
1122
1412
|
};
|
|
1413
|
+
var updateConfigSchema = {
|
|
1414
|
+
description: "Update gateway configuration",
|
|
1415
|
+
tags: ["Configuration"],
|
|
1416
|
+
summary: "Update Configuration",
|
|
1417
|
+
body: {
|
|
1418
|
+
type: "object",
|
|
1419
|
+
properties: {
|
|
1420
|
+
config: {
|
|
1421
|
+
type: "object",
|
|
1422
|
+
description: "Configuration object to update",
|
|
1423
|
+
properties: {
|
|
1424
|
+
port: { type: "number", description: "Server port" },
|
|
1425
|
+
queueServiceType: {
|
|
1426
|
+
type: "string",
|
|
1427
|
+
enum: ["memory", "redis"],
|
|
1428
|
+
description: "Queue service type"
|
|
1429
|
+
},
|
|
1430
|
+
redisUrl: { type: "string", description: "Redis URL" },
|
|
1431
|
+
redisPassword: { type: "string", description: "Redis password" },
|
|
1432
|
+
queueName: { type: "string", description: "Queue name" }
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
required: ["config"]
|
|
1437
|
+
},
|
|
1438
|
+
response: {
|
|
1439
|
+
200: {
|
|
1440
|
+
type: "object",
|
|
1441
|
+
properties: {
|
|
1442
|
+
success: { type: "boolean" },
|
|
1443
|
+
message: { type: "string" },
|
|
1444
|
+
data: { type: "object" }
|
|
1445
|
+
}
|
|
1446
|
+
},
|
|
1447
|
+
400: {
|
|
1448
|
+
type: "object",
|
|
1449
|
+
properties: {
|
|
1450
|
+
success: { type: "boolean" },
|
|
1451
|
+
error: { type: "string" }
|
|
1452
|
+
}
|
|
1453
|
+
},
|
|
1454
|
+
500: {
|
|
1455
|
+
type: "object",
|
|
1456
|
+
properties: {
|
|
1457
|
+
success: { type: "boolean" },
|
|
1458
|
+
error: { type: "string" }
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
var getConfigSchema = {
|
|
1464
|
+
description: "Get current gateway configuration",
|
|
1465
|
+
tags: ["Configuration"],
|
|
1466
|
+
summary: "Get Configuration",
|
|
1467
|
+
response: {
|
|
1468
|
+
200: {
|
|
1469
|
+
type: "object",
|
|
1470
|
+
properties: {
|
|
1471
|
+
success: { type: "boolean" },
|
|
1472
|
+
data: { type: "object" }
|
|
1473
|
+
}
|
|
1474
|
+
},
|
|
1475
|
+
500: {
|
|
1476
|
+
type: "object",
|
|
1477
|
+
properties: {
|
|
1478
|
+
success: { type: "boolean" },
|
|
1479
|
+
error: { type: "string" }
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1123
1484
|
|
|
1124
1485
|
// src/routes/index.ts
|
|
1125
1486
|
var registerLatticeRoutes = (app2) => {
|
|
@@ -1184,6 +1545,18 @@ var registerLatticeRoutes = (app2) => {
|
|
|
1184
1545
|
"/api/assistants/:assistantId/threads/:threadId",
|
|
1185
1546
|
deleteThread
|
|
1186
1547
|
);
|
|
1548
|
+
app2.get(
|
|
1549
|
+
"/api/config",
|
|
1550
|
+
{ schema: getConfigSchema },
|
|
1551
|
+
getConfig
|
|
1552
|
+
);
|
|
1553
|
+
app2.put(
|
|
1554
|
+
"/api/config",
|
|
1555
|
+
{ schema: updateConfigSchema },
|
|
1556
|
+
updateConfig
|
|
1557
|
+
);
|
|
1558
|
+
app2.get("/api/models", getModels);
|
|
1559
|
+
app2.put("/api/models", updateModels);
|
|
1187
1560
|
};
|
|
1188
1561
|
|
|
1189
1562
|
// src/logger/Logger.ts
|
|
@@ -1386,52 +1759,8 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
1386
1759
|
await app2.register(import_swagger_ui.default, swaggerUiConfig);
|
|
1387
1760
|
};
|
|
1388
1761
|
|
|
1389
|
-
// src/services/queue_service.ts
|
|
1390
|
-
var import_core4 = require("@axiom-lattice/core");
|
|
1391
|
-
var import_protocols = require("@axiom-lattice/protocols");
|
|
1392
|
-
var import_queue_redis = require("@axiom-lattice/queue-redis");
|
|
1393
|
-
var DEFAULT_QUEUE_KEY = "default";
|
|
1394
|
-
var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
|
|
1395
|
-
var setQueueServiceType = (type) => {
|
|
1396
|
-
queueServiceType = type;
|
|
1397
|
-
console.log(`Queue service type set to: ${type}`);
|
|
1398
|
-
const queueName = process.env.QUEUE_NAME || "tasks";
|
|
1399
|
-
const config = {
|
|
1400
|
-
name: "Default Queue Service",
|
|
1401
|
-
description: `Default ${type} queue service`,
|
|
1402
|
-
type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
|
|
1403
|
-
queueName,
|
|
1404
|
-
options: type === "redis" ? {
|
|
1405
|
-
redisUrl: process.env.REDIS_URL,
|
|
1406
|
-
redisPassword: process.env.REDIS_PASSWORD
|
|
1407
|
-
} : void 0
|
|
1408
|
-
};
|
|
1409
|
-
if (import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1410
|
-
import_core4.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
|
|
1411
|
-
}
|
|
1412
|
-
let client;
|
|
1413
|
-
if (type === "redis") {
|
|
1414
|
-
client = new import_queue_redis.RedisQueueClient(queueName, {
|
|
1415
|
-
redisUrl: process.env.REDIS_URL,
|
|
1416
|
-
redisPassword: process.env.REDIS_PASSWORD
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
(0, import_core4.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
|
|
1420
|
-
};
|
|
1421
|
-
var getQueueService = () => {
|
|
1422
|
-
if (!import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1423
|
-
setQueueServiceType(queueServiceType);
|
|
1424
|
-
}
|
|
1425
|
-
return (0, import_core4.getQueueLattice)(DEFAULT_QUEUE_KEY);
|
|
1426
|
-
};
|
|
1427
|
-
var popAgentTaskFromQueue = async () => {
|
|
1428
|
-
const queue = getQueueService();
|
|
1429
|
-
const result = await queue.pop();
|
|
1430
|
-
return result;
|
|
1431
|
-
};
|
|
1432
|
-
|
|
1433
1762
|
// src/services/agent_task_consumer.ts
|
|
1434
|
-
var
|
|
1763
|
+
var import_core6 = require("@axiom-lattice/core");
|
|
1435
1764
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
1436
1765
|
const {
|
|
1437
1766
|
assistant_id,
|
|
@@ -1495,7 +1824,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1495
1824
|
}
|
|
1496
1825
|
if (callback_event) {
|
|
1497
1826
|
const state = await agent_state({ assistant_id, thread_id });
|
|
1498
|
-
|
|
1827
|
+
import_core6.eventBus.publish(callback_event, {
|
|
1499
1828
|
success: true,
|
|
1500
1829
|
state,
|
|
1501
1830
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1509,7 +1838,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1509
1838
|
await response.text();
|
|
1510
1839
|
if (callback_event) {
|
|
1511
1840
|
const state = await agent_state({ assistant_id, thread_id });
|
|
1512
|
-
|
|
1841
|
+
import_core6.eventBus.publish(callback_event, {
|
|
1513
1842
|
success: true,
|
|
1514
1843
|
state,
|
|
1515
1844
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1536,7 +1865,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1536
1865
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
1537
1866
|
}
|
|
1538
1867
|
if (callback_event) {
|
|
1539
|
-
|
|
1868
|
+
import_core6.eventBus.publish(callback_event, {
|
|
1540
1869
|
success: false,
|
|
1541
1870
|
error: error instanceof Error ? error.message : String(error),
|
|
1542
1871
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1574,7 +1903,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1574
1903
|
* 初始化事件监听和队列轮询
|
|
1575
1904
|
*/
|
|
1576
1905
|
initialize() {
|
|
1577
|
-
|
|
1906
|
+
import_core6.eventBus.subscribe(import_core6.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
1578
1907
|
this.startPollingQueue();
|
|
1579
1908
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
1580
1909
|
}
|
|
@@ -1693,7 +2022,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1693
2022
|
handleAgentTask(taskRequest).catch((error) => {
|
|
1694
2023
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
1695
2024
|
if (taskRequest.callback_event) {
|
|
1696
|
-
|
|
2025
|
+
import_core6.eventBus.publish(taskRequest.callback_event, {
|
|
1697
2026
|
success: false,
|
|
1698
2027
|
error: error instanceof Error ? error.message : String(error),
|
|
1699
2028
|
config: {
|