@axiom-lattice/gateway 2.1.24 → 2.1.26

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/index.mjs CHANGED
@@ -247,7 +247,7 @@ async function resume_stream({
247
247
  // src/controllers/assistant.ts
248
248
  import { getStoreLattice } from "@axiom-lattice/core";
249
249
  import { randomUUID } from "crypto";
250
- import { getAllAgentConfigs } from "@axiom-lattice/core";
250
+ import { getAllAgentConfigs, eventBus } from "@axiom-lattice/core";
251
251
  function convertAgentConfigToAssistant(config) {
252
252
  return {
253
253
  id: config.key,
@@ -310,75 +310,80 @@ async function getAssistant(request, reply) {
310
310
  data: assistant
311
311
  };
312
312
  }
313
+ async function upsertAssistant(id, data, reply, requireFields = false) {
314
+ const storeLattice = getStoreLattice("default", "assistant");
315
+ const assistantStore = storeLattice.store;
316
+ const exists = await assistantStore.hasAssistant(id);
317
+ let assistant;
318
+ if (exists) {
319
+ assistant = await assistantStore.updateAssistant(id, data);
320
+ if (!assistant) {
321
+ return reply.status(500).send({
322
+ success: false,
323
+ message: "Failed to update assistant"
324
+ });
325
+ }
326
+ eventBus.publish("assistant:updated", { id: assistant.id, name: assistant.name });
327
+ return {
328
+ success: true,
329
+ message: "Updated assistant",
330
+ data: assistant
331
+ };
332
+ }
333
+ if (requireFields) {
334
+ const createData = data;
335
+ if (!createData.name || !createData.graphDefinition) {
336
+ return reply.status(400).send({
337
+ success: false,
338
+ message: "name and graphDefinition are required"
339
+ });
340
+ }
341
+ }
342
+ assistant = await assistantStore.createAssistant(id, data);
343
+ eventBus.publish("assistant:created", { id: assistant.id, name: assistant.name });
344
+ return reply.status(201).send({
345
+ success: true,
346
+ message: "Created assistant",
347
+ data: assistant
348
+ });
349
+ }
313
350
  async function createAssistant(request, reply) {
314
351
  const data = request.body;
315
- if (!data.name) {
352
+ if (!data.name || !data.graphDefinition) {
316
353
  return reply.status(400).send({
317
354
  success: false,
318
- message: "name is required"
355
+ message: "name and graphDefinition are required"
319
356
  });
320
357
  }
321
- if (!data.graphDefinition) {
322
- return reply.status(400).send({
323
- success: false,
324
- message: "graphDefinition is required"
325
- });
326
- }
327
- const id = randomUUID();
328
- const storeLattice = getStoreLattice("default", "assistant");
329
- const assistantStore = storeLattice.store;
330
- const newAssistant = await assistantStore.createAssistant(id, data);
331
- return reply.status(201).send({
332
- success: true,
333
- message: "Successfully created assistant",
334
- data: newAssistant
335
- });
358
+ const id = data.id ?? randomUUID();
359
+ return upsertAssistant(id, data, reply, true);
336
360
  }
337
361
  async function updateAssistant(request, reply) {
338
362
  const { id } = request.params;
339
363
  const updates = request.body;
340
- const agentConfigs = await getAllAgentConfigs();
341
- const isCodeConfigured = agentConfigs.some((config) => config.key === id);
342
- if (isCodeConfigured) {
343
- return reply.status(403).send({
344
- success: false,
345
- message: "Cannot update code-configured assistant. Only stored assistants can be updated."
346
- });
347
- }
348
- const storeLattice = getStoreLattice("default", "assistant");
349
- const assistantStore = storeLattice.store;
350
- const exists = await assistantStore.hasAssistant(id);
351
- if (!exists) {
352
- return reply.status(404).send({
353
- success: false,
354
- message: "Assistant not found"
355
- });
356
- }
357
- const updatedAssistant = await assistantStore.updateAssistant(id, updates);
358
- if (!updatedAssistant) {
359
- return reply.status(500).send({
360
- success: false,
361
- message: "Failed to update assistant"
362
- });
363
- }
364
- return {
365
- success: true,
366
- message: "Successfully updated assistant",
367
- data: updatedAssistant
368
- };
364
+ return upsertAssistant(id, updates, reply, false);
369
365
  }
370
366
  async function deleteAssistant(request, reply) {
371
367
  const { id } = request.params;
368
+ const storeLattice = getStoreLattice("default", "assistant");
369
+ const assistantStore = storeLattice.store;
372
370
  const agentConfigs = await getAllAgentConfigs();
373
371
  const isCodeConfigured = agentConfigs.some((config) => config.key === id);
374
372
  if (isCodeConfigured) {
375
- return reply.status(403).send({
376
- success: false,
377
- message: "Cannot delete code-configured assistant. Only stored assistants can be deleted."
378
- });
373
+ const exists2 = await assistantStore.hasAssistant(id);
374
+ if (!exists2) {
375
+ return reply.status(404).send({
376
+ success: false,
377
+ message: "Assistant not found (code-configured assistants cannot be deleted from code, only from store)"
378
+ });
379
+ }
380
+ await assistantStore.deleteAssistant(id);
381
+ eventBus.publish("assistant:deleted", { id });
382
+ return {
383
+ success: true,
384
+ message: "Deleted assistant from store (code-configured registration remains)"
385
+ };
379
386
  }
380
- const storeLattice = getStoreLattice("default", "assistant");
381
- const assistantStore = storeLattice.store;
382
387
  const exists = await assistantStore.hasAssistant(id);
383
388
  if (!exists) {
384
389
  return reply.status(404).send({
@@ -393,6 +398,7 @@ async function deleteAssistant(request, reply) {
393
398
  message: "Failed to delete assistant"
394
399
  });
395
400
  }
401
+ eventBus.publish("assistant:deleted", { id });
396
402
  return {
397
403
  success: true,
398
404
  message: "Successfully deleted assistant"
@@ -2104,13 +2110,17 @@ var ERROR_HTML = `<!DOCTYPE html>
2104
2110
  </body>
2105
2111
  </html>`;
2106
2112
  var SandboxService = class {
2107
- getSandboxConfig(assistantId) {
2113
+ getFilesystemIsolatedLevel(assistantId) {
2108
2114
  const agentConfig = getAgentConfig(assistantId);
2109
2115
  if (!agentConfig) {
2110
2116
  return null;
2111
2117
  }
2112
2118
  const agentLattice = getAgentLattice2(assistantId);
2113
- return agentLattice?.config?.connectedSandbox || null;
2119
+ const filesystemConfig = agentLattice?.config?.middleware?.find((m) => m.type === "filesystem");
2120
+ if (!filesystemConfig) {
2121
+ return null;
2122
+ }
2123
+ return filesystemConfig.config?.isolatedLevel || null;
2114
2124
  }
2115
2125
  computeSandboxName(assistantId, threadId, isolatedLevel) {
2116
2126
  let sandboxName;
@@ -2206,11 +2216,10 @@ function registerSandboxProxyRoutes(app2) {
2206
2216
  async (request, reply) => {
2207
2217
  console.log("[Sandbox Upload] Route matched:", request.url);
2208
2218
  const { assistantId, threadId } = request.params;
2209
- const sandboxConfig = sandboxService.getSandboxConfig(assistantId);
2210
- if (!sandboxConfig) {
2219
+ const isolatedLevel = sandboxService.getFilesystemIsolatedLevel(assistantId);
2220
+ if (!isolatedLevel) {
2211
2221
  return reply.status(500).send({ error: "Assistant sandbox config not found" });
2212
2222
  }
2213
- const { isolatedLevel } = sandboxConfig;
2214
2223
  const sandboxName = sandboxService.computeSandboxName(
2215
2224
  assistantId,
2216
2225
  threadId,
@@ -2253,11 +2262,10 @@ function registerSandboxProxyRoutes(app2) {
2253
2262
  if (!filePath || typeof filePath !== "string") {
2254
2263
  return reply.status(400).send({ error: "Query parameter 'path' is required" });
2255
2264
  }
2256
- const sandboxConfig = sandboxService.getSandboxConfig(assistantId);
2257
- if (!sandboxConfig) {
2258
- return reply.status(404).send({ error: "Assistant sandbox config not found" });
2265
+ const isolatedLevel = sandboxService.getFilesystemIsolatedLevel(assistantId);
2266
+ if (!isolatedLevel) {
2267
+ return reply.status(500).send({ error: "Assistant filesystem isolated level not found" });
2259
2268
  }
2260
- const { isolatedLevel } = sandboxConfig;
2261
2269
  const sandboxName = sandboxService.computeSandboxName(
2262
2270
  assistantId,
2263
2271
  threadId,
@@ -2499,7 +2507,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
2499
2507
  };
2500
2508
 
2501
2509
  // src/services/agent_task_consumer.ts
2502
- import { eventBus, AGENT_TASK_EVENT } from "@axiom-lattice/core";
2510
+ import { eventBus as eventBus2, AGENT_TASK_EVENT } from "@axiom-lattice/core";
2503
2511
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
2504
2512
  const {
2505
2513
  assistant_id,
@@ -2563,7 +2571,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
2563
2571
  }
2564
2572
  if (callback_event) {
2565
2573
  const state = await agent_state({ assistant_id, thread_id });
2566
- eventBus.publish(callback_event, {
2574
+ eventBus2.publish(callback_event, {
2567
2575
  success: true,
2568
2576
  state,
2569
2577
  config: { assistant_id, thread_id, tenant_id }
@@ -2577,7 +2585,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
2577
2585
  await response.text();
2578
2586
  if (callback_event) {
2579
2587
  const state = await agent_state({ assistant_id, thread_id });
2580
- eventBus.publish(callback_event, {
2588
+ eventBus2.publish(callback_event, {
2581
2589
  success: true,
2582
2590
  state,
2583
2591
  config: { assistant_id, thread_id, tenant_id }
@@ -2604,7 +2612,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
2604
2612
  return handleAgentTask(taskRequest, nextRetryCount);
2605
2613
  }
2606
2614
  if (callback_event) {
2607
- eventBus.publish(callback_event, {
2615
+ eventBus2.publish(callback_event, {
2608
2616
  success: false,
2609
2617
  error: error instanceof Error ? error.message : String(error),
2610
2618
  config: { assistant_id, thread_id, tenant_id }
@@ -2642,7 +2650,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
2642
2650
  * 初始化事件监听和队列轮询
2643
2651
  */
2644
2652
  initialize() {
2645
- eventBus.subscribe(AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
2653
+ eventBus2.subscribe(AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
2646
2654
  this.startPollingQueue();
2647
2655
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
2648
2656
  }
@@ -2761,7 +2769,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
2761
2769
  handleAgentTask(taskRequest).catch((error) => {
2762
2770
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
2763
2771
  if (taskRequest.callback_event) {
2764
- eventBus.publish(taskRequest.callback_event, {
2772
+ eventBus2.publish(taskRequest.callback_event, {
2765
2773
  success: false,
2766
2774
  error: error instanceof Error ? error.message : String(error),
2767
2775
  config: {