@agentxjs/runtime 0.1.5 → 0.1.7
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.cjs +136 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +136 -114
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1879,6 +1879,7 @@ import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
|
1879
1879
|
import { Subject as Subject2 } from "rxjs";
|
|
1880
1880
|
|
|
1881
1881
|
// src/environment/buildOptions.ts
|
|
1882
|
+
var logger7 = createLogger("environment/buildOptions");
|
|
1882
1883
|
function buildOptions(context, abortController) {
|
|
1883
1884
|
const options = {
|
|
1884
1885
|
abortController,
|
|
@@ -1887,9 +1888,15 @@ function buildOptions(context, abortController) {
|
|
|
1887
1888
|
if (context.cwd) {
|
|
1888
1889
|
options.cwd = context.cwd;
|
|
1889
1890
|
}
|
|
1890
|
-
const env = {
|
|
1891
|
-
|
|
1892
|
-
|
|
1891
|
+
const env = {};
|
|
1892
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
1893
|
+
if (value !== void 0) {
|
|
1894
|
+
env[key] = value;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
if (!env.PATH && process.env.PATH) {
|
|
1898
|
+
env.PATH = process.env.PATH;
|
|
1899
|
+
}
|
|
1893
1900
|
if (context.baseUrl) {
|
|
1894
1901
|
env.ANTHROPIC_BASE_URL = context.baseUrl;
|
|
1895
1902
|
}
|
|
@@ -1897,6 +1904,19 @@ function buildOptions(context, abortController) {
|
|
|
1897
1904
|
env.ANTHROPIC_API_KEY = context.apiKey;
|
|
1898
1905
|
}
|
|
1899
1906
|
options.env = env;
|
|
1907
|
+
logger7.info("buildOptions called", {
|
|
1908
|
+
hasPath: !!env.PATH,
|
|
1909
|
+
pathLength: env.PATH?.length,
|
|
1910
|
+
hasApiKey: !!env.ANTHROPIC_API_KEY,
|
|
1911
|
+
hasBaseUrl: !!env.ANTHROPIC_BASE_URL,
|
|
1912
|
+
baseUrl: env.ANTHROPIC_BASE_URL,
|
|
1913
|
+
model: context.model,
|
|
1914
|
+
permissionMode: context.permissionMode || "bypassPermissions",
|
|
1915
|
+
cwd: context.cwd
|
|
1916
|
+
});
|
|
1917
|
+
options.stderr = (data) => {
|
|
1918
|
+
logger7.info("SDK stderr", { data: data.trim() });
|
|
1919
|
+
};
|
|
1900
1920
|
if (context.model) options.model = context.model;
|
|
1901
1921
|
if (context.systemPrompt) options.systemPrompt = context.systemPrompt;
|
|
1902
1922
|
if (context.maxTurns) options.maxTurns = context.maxTurns;
|
|
@@ -1998,7 +2018,7 @@ async function* observableToAsyncIterable(observable) {
|
|
|
1998
2018
|
}
|
|
1999
2019
|
|
|
2000
2020
|
// src/environment/ClaudeEffector.ts
|
|
2001
|
-
var
|
|
2021
|
+
var logger8 = createLogger("ecosystem/ClaudeEffector");
|
|
2002
2022
|
var DEFAULT_TIMEOUT = 3e4;
|
|
2003
2023
|
var ClaudeEffector = class {
|
|
2004
2024
|
config;
|
|
@@ -2017,12 +2037,12 @@ var ClaudeEffector = class {
|
|
|
2017
2037
|
* Connect to SystemBus consumer to subscribe to events
|
|
2018
2038
|
*/
|
|
2019
2039
|
connect(consumer) {
|
|
2020
|
-
|
|
2040
|
+
logger8.debug("ClaudeEffector connected to SystemBusConsumer", {
|
|
2021
2041
|
agentId: this.config.agentId
|
|
2022
2042
|
});
|
|
2023
2043
|
consumer.on("user_message", async (event) => {
|
|
2024
2044
|
const typedEvent = event;
|
|
2025
|
-
|
|
2045
|
+
logger8.debug("user_message event received", {
|
|
2026
2046
|
eventAgentId: typedEvent.context?.agentId,
|
|
2027
2047
|
myAgentId: this.config.agentId,
|
|
2028
2048
|
matches: typedEvent.context?.agentId === this.config.agentId
|
|
@@ -2058,14 +2078,14 @@ var ClaudeEffector = class {
|
|
|
2058
2078
|
this.currentMeta = meta;
|
|
2059
2079
|
const timeout = this.config.timeout ?? DEFAULT_TIMEOUT;
|
|
2060
2080
|
const timeoutId = setTimeout(() => {
|
|
2061
|
-
|
|
2081
|
+
logger8.warn("Request timeout", { timeout });
|
|
2062
2082
|
this.currentAbortController?.abort(new Error(`Request timeout after ${timeout}ms`));
|
|
2063
2083
|
}, timeout);
|
|
2064
2084
|
try {
|
|
2065
2085
|
await this.initialize(this.currentAbortController);
|
|
2066
2086
|
const sessionId = this.config.sessionId || "default";
|
|
2067
2087
|
const sdkUserMessage = buildSDKUserMessage(message, sessionId);
|
|
2068
|
-
|
|
2088
|
+
logger8.debug("Sending message to Claude", {
|
|
2069
2089
|
content: typeof message.content === "string" ? message.content.substring(0, 80) : "[structured]",
|
|
2070
2090
|
timeout,
|
|
2071
2091
|
requestId: meta.requestId
|
|
@@ -2082,13 +2102,13 @@ var ClaudeEffector = class {
|
|
|
2082
2102
|
*/
|
|
2083
2103
|
interrupt(meta) {
|
|
2084
2104
|
if (this.claudeQuery) {
|
|
2085
|
-
|
|
2105
|
+
logger8.debug("Interrupting Claude query", { requestId: meta?.requestId });
|
|
2086
2106
|
this.wasInterrupted = true;
|
|
2087
2107
|
if (meta) {
|
|
2088
2108
|
this.currentMeta = meta;
|
|
2089
2109
|
}
|
|
2090
2110
|
this.claudeQuery.interrupt().catch((err) => {
|
|
2091
|
-
|
|
2111
|
+
logger8.debug("SDK interrupt() error (may be expected)", { error: err });
|
|
2092
2112
|
});
|
|
2093
2113
|
}
|
|
2094
2114
|
}
|
|
@@ -2097,7 +2117,7 @@ var ClaudeEffector = class {
|
|
|
2097
2117
|
*/
|
|
2098
2118
|
async initialize(abortController) {
|
|
2099
2119
|
if (this.isInitialized) return;
|
|
2100
|
-
|
|
2120
|
+
logger8.info("Initializing ClaudeEffector");
|
|
2101
2121
|
const context = {
|
|
2102
2122
|
apiKey: this.config.apiKey,
|
|
2103
2123
|
baseUrl: this.config.baseUrl,
|
|
@@ -2114,7 +2134,7 @@ var ClaudeEffector = class {
|
|
|
2114
2134
|
});
|
|
2115
2135
|
this.isInitialized = true;
|
|
2116
2136
|
this.startBackgroundListener();
|
|
2117
|
-
|
|
2137
|
+
logger8.info("ClaudeEffector initialized");
|
|
2118
2138
|
}
|
|
2119
2139
|
/**
|
|
2120
2140
|
* Start background listener for SDK responses
|
|
@@ -2123,7 +2143,7 @@ var ClaudeEffector = class {
|
|
|
2123
2143
|
(async () => {
|
|
2124
2144
|
try {
|
|
2125
2145
|
for await (const sdkMsg of this.claudeQuery) {
|
|
2126
|
-
|
|
2146
|
+
logger8.debug("SDK message received", {
|
|
2127
2147
|
type: sdkMsg.type,
|
|
2128
2148
|
subtype: sdkMsg.subtype,
|
|
2129
2149
|
sessionId: sdkMsg.session_id,
|
|
@@ -2140,10 +2160,10 @@ var ClaudeEffector = class {
|
|
|
2140
2160
|
}
|
|
2141
2161
|
if (sdkMsg.type === "result") {
|
|
2142
2162
|
const resultMsg = sdkMsg;
|
|
2143
|
-
|
|
2163
|
+
logger8.info("SDK result received (full)", {
|
|
2144
2164
|
fullResult: JSON.stringify(sdkMsg, null, 2)
|
|
2145
2165
|
});
|
|
2146
|
-
|
|
2166
|
+
logger8.info("SDK result received", {
|
|
2147
2167
|
subtype: resultMsg.subtype,
|
|
2148
2168
|
isError: resultMsg.is_error,
|
|
2149
2169
|
errors: resultMsg.errors,
|
|
@@ -2161,10 +2181,10 @@ var ClaudeEffector = class {
|
|
|
2161
2181
|
}
|
|
2162
2182
|
} catch (error) {
|
|
2163
2183
|
if (this.isAbortError(error)) {
|
|
2164
|
-
|
|
2184
|
+
logger8.debug("Background listener aborted (expected during interrupt)");
|
|
2165
2185
|
this.resetState();
|
|
2166
2186
|
} else {
|
|
2167
|
-
|
|
2187
|
+
logger8.error("Background listener error", { error });
|
|
2168
2188
|
if (this.currentMeta) {
|
|
2169
2189
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
2170
2190
|
this.receptor.emitError(errorMessage, "runtime_error", this.currentMeta);
|
|
@@ -2196,7 +2216,7 @@ var ClaudeEffector = class {
|
|
|
2196
2216
|
* Dispose and cleanup resources
|
|
2197
2217
|
*/
|
|
2198
2218
|
dispose() {
|
|
2199
|
-
|
|
2219
|
+
logger8.debug("Disposing ClaudeEffector");
|
|
2200
2220
|
if (this.currentAbortController) {
|
|
2201
2221
|
this.currentAbortController.abort();
|
|
2202
2222
|
}
|
|
@@ -2227,7 +2247,7 @@ var ClaudeEnvironment = class {
|
|
|
2227
2247
|
};
|
|
2228
2248
|
|
|
2229
2249
|
// src/internal/RuntimeAgent.ts
|
|
2230
|
-
var
|
|
2250
|
+
var logger9 = createLogger("runtime/RuntimeAgent");
|
|
2231
2251
|
var BusPresenter = class {
|
|
2232
2252
|
constructor(producer, session, agentId, imageId, containerId) {
|
|
2233
2253
|
this.producer = producer;
|
|
@@ -2264,7 +2284,7 @@ var BusPresenter = class {
|
|
|
2264
2284
|
this.producer.emit(systemEvent);
|
|
2265
2285
|
if (category === "message") {
|
|
2266
2286
|
this.session.addMessage(data).catch((err) => {
|
|
2267
|
-
|
|
2287
|
+
logger9.error("Failed to persist message", { error: err, messageType: output.type });
|
|
2268
2288
|
});
|
|
2269
2289
|
}
|
|
2270
2290
|
}
|
|
@@ -2322,7 +2342,7 @@ var BusPresenter = class {
|
|
|
2322
2342
|
};
|
|
2323
2343
|
}
|
|
2324
2344
|
default:
|
|
2325
|
-
|
|
2345
|
+
logger9.warn("Unknown message type, passing through", { type: output.type });
|
|
2326
2346
|
return eventData;
|
|
2327
2347
|
}
|
|
2328
2348
|
}
|
|
@@ -2375,6 +2395,7 @@ var RuntimeAgent = class {
|
|
|
2375
2395
|
baseUrl: config.llmConfig.baseUrl,
|
|
2376
2396
|
model: config.llmConfig.model,
|
|
2377
2397
|
systemPrompt: config.config.systemPrompt,
|
|
2398
|
+
cwd: config.sandbox.workdir.path,
|
|
2378
2399
|
resumeSessionId,
|
|
2379
2400
|
onSessionIdCaptured: (sdkSessionId) => {
|
|
2380
2401
|
this.saveSessionId(sdkSessionId);
|
|
@@ -2382,9 +2403,10 @@ var RuntimeAgent = class {
|
|
|
2382
2403
|
});
|
|
2383
2404
|
this.environment.receptor.connect(config.bus.asProducer());
|
|
2384
2405
|
this.environment.effector.connect(config.bus.asConsumer());
|
|
2385
|
-
|
|
2406
|
+
logger9.info("ClaudeEnvironment created for agent", {
|
|
2386
2407
|
agentId: this.agentId,
|
|
2387
2408
|
imageId: this.imageId,
|
|
2409
|
+
cwd: config.sandbox.workdir.path,
|
|
2388
2410
|
resumeSessionId: resumeSessionId ?? "none",
|
|
2389
2411
|
isResume: !!resumeSessionId,
|
|
2390
2412
|
imageMetadata: config.image.metadata
|
|
@@ -2416,14 +2438,14 @@ var RuntimeAgent = class {
|
|
|
2416
2438
|
this.driver = new BusDriver(config.bus.asConsumer(), {
|
|
2417
2439
|
agentId: this.agentId,
|
|
2418
2440
|
onStreamEvent: (event) => {
|
|
2419
|
-
|
|
2441
|
+
logger9.debug("BusDriver \u2192 Engine.handleStreamEvent", { type: event.type });
|
|
2420
2442
|
this.engine.handleStreamEvent(event);
|
|
2421
2443
|
},
|
|
2422
2444
|
onStreamComplete: (reason) => {
|
|
2423
|
-
|
|
2445
|
+
logger9.debug("Stream completed", { reason, agentId: this.agentId });
|
|
2424
2446
|
}
|
|
2425
2447
|
});
|
|
2426
|
-
|
|
2448
|
+
logger9.debug("RuntimeAgent created", {
|
|
2427
2449
|
agentId: this.agentId,
|
|
2428
2450
|
imageId: this.imageId
|
|
2429
2451
|
});
|
|
@@ -2432,13 +2454,13 @@ var RuntimeAgent = class {
|
|
|
2432
2454
|
* Save SDK session ID to image metadata for future resume
|
|
2433
2455
|
*/
|
|
2434
2456
|
saveSessionId(sdkSessionId) {
|
|
2435
|
-
|
|
2457
|
+
logger9.info("Saving SDK session ID to image metadata", {
|
|
2436
2458
|
agentId: this.agentId,
|
|
2437
2459
|
imageId: this.imageId,
|
|
2438
2460
|
sdkSessionId
|
|
2439
2461
|
});
|
|
2440
2462
|
this.imageRepository.updateMetadata(this.imageId, { claudeSdkSessionId: sdkSessionId }).catch((err) => {
|
|
2441
|
-
|
|
2463
|
+
logger9.error("Failed to save SDK session ID", { error: err, imageId: this.imageId });
|
|
2442
2464
|
});
|
|
2443
2465
|
}
|
|
2444
2466
|
get lifecycle() {
|
|
@@ -2451,7 +2473,7 @@ var RuntimeAgent = class {
|
|
|
2451
2473
|
* @param requestId - Request ID for correlation
|
|
2452
2474
|
*/
|
|
2453
2475
|
async receive(content, requestId) {
|
|
2454
|
-
|
|
2476
|
+
logger9.debug("RuntimeAgent.receive called", {
|
|
2455
2477
|
agentId: this.agentId,
|
|
2456
2478
|
contentPreview: content.substring(0, 50),
|
|
2457
2479
|
requestId
|
|
@@ -2460,13 +2482,13 @@ var RuntimeAgent = class {
|
|
|
2460
2482
|
throw new Error(`Cannot send message to ${this._lifecycle} agent`);
|
|
2461
2483
|
}
|
|
2462
2484
|
await this.interactor.receive(content, requestId || `req_${Date.now()}`);
|
|
2463
|
-
|
|
2485
|
+
logger9.debug("RuntimeAgent.receive completed", { agentId: this.agentId });
|
|
2464
2486
|
}
|
|
2465
2487
|
/**
|
|
2466
2488
|
* Interrupt current operation
|
|
2467
2489
|
*/
|
|
2468
2490
|
interrupt(requestId) {
|
|
2469
|
-
|
|
2491
|
+
logger9.debug("RuntimeAgent.interrupt called", { agentId: this.agentId, requestId });
|
|
2470
2492
|
this.interactor.interrupt(requestId);
|
|
2471
2493
|
this.producer.emit({
|
|
2472
2494
|
type: "interrupted",
|
|
@@ -2661,7 +2683,7 @@ var RuntimeSandbox = class {
|
|
|
2661
2683
|
};
|
|
2662
2684
|
|
|
2663
2685
|
// src/internal/RuntimeImage.ts
|
|
2664
|
-
var
|
|
2686
|
+
var logger10 = createLogger("runtime/RuntimeImage");
|
|
2665
2687
|
var RuntimeImage = class _RuntimeImage {
|
|
2666
2688
|
constructor(record, context) {
|
|
2667
2689
|
this.record = record;
|
|
@@ -2718,7 +2740,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2718
2740
|
createdAt: now,
|
|
2719
2741
|
updatedAt: now
|
|
2720
2742
|
});
|
|
2721
|
-
|
|
2743
|
+
logger10.info("Image created", {
|
|
2722
2744
|
imageId,
|
|
2723
2745
|
sessionId,
|
|
2724
2746
|
containerId: config.containerId,
|
|
@@ -2732,10 +2754,10 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2732
2754
|
static async load(imageId, context) {
|
|
2733
2755
|
const record = await context.imageRepository.findImageById(imageId);
|
|
2734
2756
|
if (!record) {
|
|
2735
|
-
|
|
2757
|
+
logger10.debug("Image not found", { imageId });
|
|
2736
2758
|
return null;
|
|
2737
2759
|
}
|
|
2738
|
-
|
|
2760
|
+
logger10.debug("Image loaded", { imageId, name: record.name });
|
|
2739
2761
|
return new _RuntimeImage(record, context);
|
|
2740
2762
|
}
|
|
2741
2763
|
/**
|
|
@@ -2769,7 +2791,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2769
2791
|
updatedAt: now
|
|
2770
2792
|
};
|
|
2771
2793
|
await this.context.imageRepository.saveImage(updatedRecord);
|
|
2772
|
-
|
|
2794
|
+
logger10.info("Image updated", { imageId: this.imageId, updates });
|
|
2773
2795
|
return new _RuntimeImage(updatedRecord, this.context);
|
|
2774
2796
|
}
|
|
2775
2797
|
/**
|
|
@@ -2778,7 +2800,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2778
2800
|
async delete() {
|
|
2779
2801
|
await this.context.sessionRepository.deleteSession(this.sessionId);
|
|
2780
2802
|
await this.context.imageRepository.deleteImage(this.imageId);
|
|
2781
|
-
|
|
2803
|
+
logger10.info("Image deleted", { imageId: this.imageId, sessionId: this.sessionId });
|
|
2782
2804
|
}
|
|
2783
2805
|
/**
|
|
2784
2806
|
* Get the underlying record
|
|
@@ -2800,7 +2822,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2800
2822
|
};
|
|
2801
2823
|
|
|
2802
2824
|
// src/internal/RuntimeContainer.ts
|
|
2803
|
-
var
|
|
2825
|
+
var logger11 = createLogger("runtime/RuntimeContainer");
|
|
2804
2826
|
var RuntimeContainer = class _RuntimeContainer {
|
|
2805
2827
|
containerId;
|
|
2806
2828
|
createdAt;
|
|
@@ -2840,7 +2862,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2840
2862
|
containerId
|
|
2841
2863
|
}
|
|
2842
2864
|
});
|
|
2843
|
-
|
|
2865
|
+
logger11.info("Container created", { containerId });
|
|
2844
2866
|
return container;
|
|
2845
2867
|
}
|
|
2846
2868
|
/**
|
|
@@ -2849,7 +2871,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2849
2871
|
static async load(containerId, context) {
|
|
2850
2872
|
const record = await context.persistence.containers.findContainerById(containerId);
|
|
2851
2873
|
if (!record) return null;
|
|
2852
|
-
|
|
2874
|
+
logger11.info("Container loaded", { containerId });
|
|
2853
2875
|
return new _RuntimeContainer(containerId, record.createdAt, context);
|
|
2854
2876
|
}
|
|
2855
2877
|
// ==================== Image → Agent Lifecycle ====================
|
|
@@ -2862,7 +2884,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2862
2884
|
if (existingAgentId) {
|
|
2863
2885
|
const existingAgent = this.agents.get(existingAgentId);
|
|
2864
2886
|
if (existingAgent) {
|
|
2865
|
-
|
|
2887
|
+
logger11.info("Reusing existing agent for image", {
|
|
2866
2888
|
containerId: this.containerId,
|
|
2867
2889
|
imageId: image.imageId,
|
|
2868
2890
|
agentId: existingAgentId
|
|
@@ -2921,7 +2943,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2921
2943
|
agentId
|
|
2922
2944
|
}
|
|
2923
2945
|
});
|
|
2924
|
-
|
|
2946
|
+
logger11.info("Agent created for image", {
|
|
2925
2947
|
containerId: this.containerId,
|
|
2926
2948
|
imageId: image.imageId,
|
|
2927
2949
|
agentId
|
|
@@ -2934,17 +2956,17 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2934
2956
|
async stopImage(imageId) {
|
|
2935
2957
|
const agentId = this.imageToAgent.get(imageId);
|
|
2936
2958
|
if (!agentId) {
|
|
2937
|
-
|
|
2959
|
+
logger11.debug("Image not running, nothing to stop", {
|
|
2938
2960
|
imageId,
|
|
2939
2961
|
containerId: this.containerId
|
|
2940
2962
|
});
|
|
2941
2963
|
return false;
|
|
2942
2964
|
}
|
|
2943
|
-
|
|
2965
|
+
logger11.info("Stopping image", { imageId, agentId, containerId: this.containerId });
|
|
2944
2966
|
const success = await this.destroyAgent(agentId);
|
|
2945
2967
|
if (success) {
|
|
2946
2968
|
this.imageToAgent.delete(imageId);
|
|
2947
|
-
|
|
2969
|
+
logger11.info("Image stopped", { imageId, agentId, containerId: this.containerId });
|
|
2948
2970
|
}
|
|
2949
2971
|
return success;
|
|
2950
2972
|
}
|
|
@@ -3001,7 +3023,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3001
3023
|
agentId
|
|
3002
3024
|
}
|
|
3003
3025
|
});
|
|
3004
|
-
|
|
3026
|
+
logger11.info("Agent destroyed", { containerId: this.containerId, agentId });
|
|
3005
3027
|
return true;
|
|
3006
3028
|
}
|
|
3007
3029
|
async destroyAllAgents() {
|
|
@@ -3029,7 +3051,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3029
3051
|
}
|
|
3030
3052
|
});
|
|
3031
3053
|
this.context.onDisposed?.(this.containerId);
|
|
3032
|
-
|
|
3054
|
+
logger11.info("Container disposed", { containerId: this.containerId, agentCount });
|
|
3033
3055
|
}
|
|
3034
3056
|
// ==================== Private Helpers ====================
|
|
3035
3057
|
generateAgentId() {
|
|
@@ -3040,7 +3062,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3040
3062
|
};
|
|
3041
3063
|
|
|
3042
3064
|
// src/internal/BaseEventHandler.ts
|
|
3043
|
-
var
|
|
3065
|
+
var logger12 = createLogger("runtime/BaseEventHandler");
|
|
3044
3066
|
var BaseEventHandler = class {
|
|
3045
3067
|
bus;
|
|
3046
3068
|
unsubscribes = [];
|
|
@@ -3079,7 +3101,7 @@ var BaseEventHandler = class {
|
|
|
3079
3101
|
handleError(err, context) {
|
|
3080
3102
|
const message = err instanceof Error ? err.message : String(err);
|
|
3081
3103
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3082
|
-
|
|
3104
|
+
logger12.error(`Error in ${context.operation || "handler"}`, {
|
|
3083
3105
|
message,
|
|
3084
3106
|
requestId: context.requestId,
|
|
3085
3107
|
details: context.details
|
|
@@ -3106,7 +3128,7 @@ var BaseEventHandler = class {
|
|
|
3106
3128
|
try {
|
|
3107
3129
|
context.onError(err);
|
|
3108
3130
|
} catch (callbackErr) {
|
|
3109
|
-
|
|
3131
|
+
logger12.error("Error in onError callback", { error: callbackErr });
|
|
3110
3132
|
}
|
|
3111
3133
|
}
|
|
3112
3134
|
}
|
|
@@ -3124,12 +3146,12 @@ var BaseEventHandler = class {
|
|
|
3124
3146
|
unsubscribe();
|
|
3125
3147
|
}
|
|
3126
3148
|
this.unsubscribes = [];
|
|
3127
|
-
|
|
3149
|
+
logger12.debug(`${this.constructor.name} disposed`);
|
|
3128
3150
|
}
|
|
3129
3151
|
};
|
|
3130
3152
|
|
|
3131
3153
|
// src/internal/CommandHandler.ts
|
|
3132
|
-
var
|
|
3154
|
+
var logger13 = createLogger("runtime/CommandHandler");
|
|
3133
3155
|
function createResponse(type, data) {
|
|
3134
3156
|
return {
|
|
3135
3157
|
type,
|
|
@@ -3162,7 +3184,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3162
3184
|
super(bus);
|
|
3163
3185
|
this.ops = operations;
|
|
3164
3186
|
this.bindHandlers();
|
|
3165
|
-
|
|
3187
|
+
logger13.debug("CommandHandler created");
|
|
3166
3188
|
}
|
|
3167
3189
|
/**
|
|
3168
3190
|
* Log error and emit system_error event
|
|
@@ -3170,7 +3192,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3170
3192
|
emitError(operation, err, requestId, context) {
|
|
3171
3193
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
3172
3194
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3173
|
-
|
|
3195
|
+
logger13.error(operation, {
|
|
3174
3196
|
requestId,
|
|
3175
3197
|
...context,
|
|
3176
3198
|
error: errorMessage,
|
|
@@ -3227,12 +3249,12 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3227
3249
|
this.subscribe(
|
|
3228
3250
|
this.bus.onCommand("image_messages_request", (event) => this.handleImageMessages(event))
|
|
3229
3251
|
);
|
|
3230
|
-
|
|
3252
|
+
logger13.debug("Command handlers bound");
|
|
3231
3253
|
}
|
|
3232
3254
|
// ==================== Container Handlers ====================
|
|
3233
3255
|
async handleContainerCreate(event) {
|
|
3234
3256
|
const { requestId, containerId } = event.data;
|
|
3235
|
-
|
|
3257
|
+
logger13.debug("Handling container_create_request", { requestId, containerId });
|
|
3236
3258
|
try {
|
|
3237
3259
|
await this.ops.createContainer(containerId);
|
|
3238
3260
|
this.bus.emit(
|
|
@@ -3254,7 +3276,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3254
3276
|
}
|
|
3255
3277
|
handleContainerGet(event) {
|
|
3256
3278
|
const { requestId, containerId } = event.data;
|
|
3257
|
-
|
|
3279
|
+
logger13.debug("Handling container_get_request", { requestId, containerId });
|
|
3258
3280
|
const container = this.ops.getContainer(containerId);
|
|
3259
3281
|
this.bus.emit(
|
|
3260
3282
|
createResponse("container_get_response", {
|
|
@@ -3266,7 +3288,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3266
3288
|
}
|
|
3267
3289
|
handleContainerList(event) {
|
|
3268
3290
|
const { requestId } = event.data;
|
|
3269
|
-
|
|
3291
|
+
logger13.debug("Handling container_list_request", { requestId });
|
|
3270
3292
|
const containers = this.ops.listContainers();
|
|
3271
3293
|
this.bus.emit(
|
|
3272
3294
|
createResponse("container_list_response", {
|
|
@@ -3278,7 +3300,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3278
3300
|
// ==================== Agent Handlers ====================
|
|
3279
3301
|
handleAgentGet(event) {
|
|
3280
3302
|
const { requestId, agentId } = event.data;
|
|
3281
|
-
|
|
3303
|
+
logger13.debug("Handling agent_get_request", { requestId, agentId });
|
|
3282
3304
|
const agent = this.ops.getAgent(agentId);
|
|
3283
3305
|
this.bus.emit(
|
|
3284
3306
|
createResponse("agent_get_response", {
|
|
@@ -3291,7 +3313,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3291
3313
|
}
|
|
3292
3314
|
handleAgentList(event) {
|
|
3293
3315
|
const { requestId, containerId } = event.data;
|
|
3294
|
-
|
|
3316
|
+
logger13.debug("Handling agent_list_request", { requestId, containerId });
|
|
3295
3317
|
const agents = this.ops.listAgents(containerId);
|
|
3296
3318
|
this.bus.emit(
|
|
3297
3319
|
createResponse("agent_list_response", {
|
|
@@ -3306,7 +3328,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3306
3328
|
}
|
|
3307
3329
|
async handleAgentDestroy(event) {
|
|
3308
3330
|
const { requestId, agentId } = event.data;
|
|
3309
|
-
|
|
3331
|
+
logger13.debug("Handling agent_destroy_request", { requestId, agentId });
|
|
3310
3332
|
try {
|
|
3311
3333
|
const success = await this.ops.destroyAgent(agentId);
|
|
3312
3334
|
this.bus.emit(
|
|
@@ -3330,7 +3352,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3330
3352
|
}
|
|
3331
3353
|
async handleAgentDestroyAll(event) {
|
|
3332
3354
|
const { requestId, containerId } = event.data;
|
|
3333
|
-
|
|
3355
|
+
logger13.debug("Handling agent_destroy_all_request", { requestId, containerId });
|
|
3334
3356
|
try {
|
|
3335
3357
|
await this.ops.destroyAllAgents(containerId);
|
|
3336
3358
|
this.bus.emit(
|
|
@@ -3352,7 +3374,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3352
3374
|
}
|
|
3353
3375
|
async handleMessageSend(event) {
|
|
3354
3376
|
const { requestId, imageId, agentId, content } = event.data;
|
|
3355
|
-
|
|
3377
|
+
logger13.debug("Handling message_send_request", { requestId, imageId, agentId });
|
|
3356
3378
|
try {
|
|
3357
3379
|
const result = await this.ops.receiveMessage(imageId, agentId, content, requestId);
|
|
3358
3380
|
this.bus.emit(
|
|
@@ -3376,7 +3398,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3376
3398
|
}
|
|
3377
3399
|
handleAgentInterrupt(event) {
|
|
3378
3400
|
const { requestId, imageId, agentId } = event.data;
|
|
3379
|
-
|
|
3401
|
+
logger13.debug("Handling agent_interrupt_request", { requestId, imageId, agentId });
|
|
3380
3402
|
try {
|
|
3381
3403
|
const result = this.ops.interruptAgent(imageId, agentId, requestId);
|
|
3382
3404
|
this.bus.emit(
|
|
@@ -3401,7 +3423,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3401
3423
|
// ==================== Image Handlers ====================
|
|
3402
3424
|
async handleImageCreate(event) {
|
|
3403
3425
|
const { requestId, containerId, config } = event.data;
|
|
3404
|
-
|
|
3426
|
+
logger13.debug("Handling image_create_request", { requestId, containerId });
|
|
3405
3427
|
try {
|
|
3406
3428
|
const record = await this.ops.createImage(containerId, config);
|
|
3407
3429
|
this.bus.emit(
|
|
@@ -3423,7 +3445,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3423
3445
|
}
|
|
3424
3446
|
async handleImageRun(event) {
|
|
3425
3447
|
const { requestId, imageId } = event.data;
|
|
3426
|
-
|
|
3448
|
+
logger13.debug("Handling image_run_request", { requestId, imageId });
|
|
3427
3449
|
try {
|
|
3428
3450
|
const result = await this.ops.runImage(imageId);
|
|
3429
3451
|
this.bus.emit(
|
|
@@ -3449,7 +3471,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3449
3471
|
}
|
|
3450
3472
|
async handleImageStop(event) {
|
|
3451
3473
|
const { requestId, imageId } = event.data;
|
|
3452
|
-
|
|
3474
|
+
logger13.debug("Handling image_stop_request", { requestId, imageId });
|
|
3453
3475
|
try {
|
|
3454
3476
|
await this.ops.stopImage(imageId);
|
|
3455
3477
|
this.bus.emit(
|
|
@@ -3471,7 +3493,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3471
3493
|
}
|
|
3472
3494
|
async handleImageUpdate(event) {
|
|
3473
3495
|
const { requestId, imageId, updates } = event.data;
|
|
3474
|
-
|
|
3496
|
+
logger13.debug("Handling image_update_request", { requestId, imageId });
|
|
3475
3497
|
try {
|
|
3476
3498
|
const record = await this.ops.updateImage(imageId, updates);
|
|
3477
3499
|
this.bus.emit(
|
|
@@ -3493,7 +3515,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3493
3515
|
}
|
|
3494
3516
|
async handleImageList(event) {
|
|
3495
3517
|
const { requestId, containerId } = event.data;
|
|
3496
|
-
|
|
3518
|
+
logger13.debug("Handling image_list_request", { requestId, containerId });
|
|
3497
3519
|
try {
|
|
3498
3520
|
const images = await this.ops.listImages(containerId);
|
|
3499
3521
|
this.bus.emit(
|
|
@@ -3515,7 +3537,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3515
3537
|
}
|
|
3516
3538
|
async handleImageGet(event) {
|
|
3517
3539
|
const { requestId, imageId } = event.data;
|
|
3518
|
-
|
|
3540
|
+
logger13.debug("Handling image_get_request", { requestId, imageId });
|
|
3519
3541
|
try {
|
|
3520
3542
|
const image = await this.ops.getImage(imageId);
|
|
3521
3543
|
this.bus.emit(
|
|
@@ -3536,7 +3558,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3536
3558
|
}
|
|
3537
3559
|
async handleImageDelete(event) {
|
|
3538
3560
|
const { requestId, imageId } = event.data;
|
|
3539
|
-
|
|
3561
|
+
logger13.debug("Handling image_delete_request", { requestId, imageId });
|
|
3540
3562
|
try {
|
|
3541
3563
|
await this.ops.deleteImage(imageId);
|
|
3542
3564
|
this.bus.emit(
|
|
@@ -3558,10 +3580,10 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3558
3580
|
}
|
|
3559
3581
|
async handleImageMessages(event) {
|
|
3560
3582
|
const { requestId, imageId } = event.data;
|
|
3561
|
-
|
|
3583
|
+
logger13.info("Handling image_messages_request", { requestId, imageId });
|
|
3562
3584
|
try {
|
|
3563
3585
|
const messages = await this.ops.getImageMessages(imageId);
|
|
3564
|
-
|
|
3586
|
+
logger13.info("Got messages for image", { imageId, count: messages.length });
|
|
3565
3587
|
this.bus.emit(
|
|
3566
3588
|
createResponse("image_messages_response", {
|
|
3567
3589
|
requestId,
|
|
@@ -3569,7 +3591,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3569
3591
|
messages
|
|
3570
3592
|
})
|
|
3571
3593
|
);
|
|
3572
|
-
|
|
3594
|
+
logger13.info("Emitted image_messages_response", { requestId, imageId });
|
|
3573
3595
|
} catch (err) {
|
|
3574
3596
|
this.emitError("Failed to get image messages", err, requestId, { imageId });
|
|
3575
3597
|
this.bus.emit(
|
|
@@ -3588,7 +3610,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3588
3610
|
// src/RuntimeImpl.ts
|
|
3589
3611
|
import { homedir } from "os";
|
|
3590
3612
|
import { join as join2 } from "path";
|
|
3591
|
-
var
|
|
3613
|
+
var logger14 = createLogger("runtime/RuntimeImpl");
|
|
3592
3614
|
var RuntimeImpl = class {
|
|
3593
3615
|
persistence;
|
|
3594
3616
|
llmProvider;
|
|
@@ -3599,20 +3621,20 @@ var RuntimeImpl = class {
|
|
|
3599
3621
|
/** Container registry: containerId -> RuntimeContainer */
|
|
3600
3622
|
containerRegistry = /* @__PURE__ */ new Map();
|
|
3601
3623
|
constructor(config) {
|
|
3602
|
-
|
|
3624
|
+
logger14.info("RuntimeImpl constructor start");
|
|
3603
3625
|
this.persistence = config.persistence;
|
|
3604
3626
|
this.llmProvider = config.llmProvider;
|
|
3605
3627
|
this.basePath = join2(homedir(), ".agentx");
|
|
3606
|
-
|
|
3628
|
+
logger14.info("Creating SystemBus");
|
|
3607
3629
|
this.bus = new SystemBusImpl();
|
|
3608
3630
|
this.llmConfig = this.llmProvider.provide();
|
|
3609
|
-
|
|
3631
|
+
logger14.info("LLM config loaded", {
|
|
3610
3632
|
hasApiKey: !!this.llmConfig.apiKey,
|
|
3611
3633
|
model: this.llmConfig.model
|
|
3612
3634
|
});
|
|
3613
|
-
|
|
3635
|
+
logger14.info("Creating CommandHandler");
|
|
3614
3636
|
this.commandHandler = new CommandHandler(this.bus, this.createRuntimeOperations());
|
|
3615
|
-
|
|
3637
|
+
logger14.info("RuntimeImpl constructor done");
|
|
3616
3638
|
}
|
|
3617
3639
|
// ==================== SystemBus delegation ====================
|
|
3618
3640
|
emit(event) {
|
|
@@ -3695,7 +3717,7 @@ var RuntimeImpl = class {
|
|
|
3695
3717
|
// Agent operations (by imageId - with auto-activation)
|
|
3696
3718
|
receiveMessage: async (imageId, agentId, content, requestId) => {
|
|
3697
3719
|
if (imageId) {
|
|
3698
|
-
|
|
3720
|
+
logger14.debug("Receiving message by imageId", {
|
|
3699
3721
|
imageId,
|
|
3700
3722
|
contentLength: content.length,
|
|
3701
3723
|
requestId
|
|
@@ -3704,7 +3726,7 @@ var RuntimeImpl = class {
|
|
|
3704
3726
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3705
3727
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3706
3728
|
const { agent, reused } = await container.runImage(record);
|
|
3707
|
-
|
|
3729
|
+
logger14.info("Message routed to agent", {
|
|
3708
3730
|
imageId,
|
|
3709
3731
|
agentId: agent.agentId,
|
|
3710
3732
|
reused,
|
|
@@ -3714,7 +3736,7 @@ var RuntimeImpl = class {
|
|
|
3714
3736
|
return { agentId: agent.agentId, imageId };
|
|
3715
3737
|
}
|
|
3716
3738
|
if (agentId) {
|
|
3717
|
-
|
|
3739
|
+
logger14.debug("Receiving message by agentId (legacy)", {
|
|
3718
3740
|
agentId,
|
|
3719
3741
|
contentLength: content.length,
|
|
3720
3742
|
requestId
|
|
@@ -3731,12 +3753,12 @@ var RuntimeImpl = class {
|
|
|
3731
3753
|
if (imageId) {
|
|
3732
3754
|
const foundAgentId = this.findAgentIdForImage(imageId);
|
|
3733
3755
|
if (!foundAgentId) {
|
|
3734
|
-
|
|
3756
|
+
logger14.debug("Image is offline, nothing to interrupt", { imageId });
|
|
3735
3757
|
return { imageId, agentId: void 0 };
|
|
3736
3758
|
}
|
|
3737
3759
|
const agent = this.findAgent(foundAgentId);
|
|
3738
3760
|
if (agent) {
|
|
3739
|
-
|
|
3761
|
+
logger14.info("Interrupting agent by imageId", {
|
|
3740
3762
|
imageId,
|
|
3741
3763
|
agentId: foundAgentId,
|
|
3742
3764
|
requestId
|
|
@@ -3748,7 +3770,7 @@ var RuntimeImpl = class {
|
|
|
3748
3770
|
if (agentId) {
|
|
3749
3771
|
const agent = this.findAgent(agentId);
|
|
3750
3772
|
if (!agent) throw new Error(`Agent not found: ${agentId}`);
|
|
3751
|
-
|
|
3773
|
+
logger14.info("Interrupting agent by agentId (legacy)", { agentId, requestId });
|
|
3752
3774
|
agent.interrupt(requestId);
|
|
3753
3775
|
const foundImageId = this.findImageIdForAgent(agentId);
|
|
3754
3776
|
return { agentId, imageId: foundImageId };
|
|
@@ -3757,32 +3779,32 @@ var RuntimeImpl = class {
|
|
|
3757
3779
|
},
|
|
3758
3780
|
// Image operations (new model)
|
|
3759
3781
|
createImage: async (containerId, config) => {
|
|
3760
|
-
|
|
3782
|
+
logger14.debug("Creating image", { containerId, name: config.name });
|
|
3761
3783
|
await this.getOrCreateContainer(containerId);
|
|
3762
3784
|
const image = await RuntimeImage.create(
|
|
3763
3785
|
{ containerId, ...config },
|
|
3764
3786
|
this.createImageContext()
|
|
3765
3787
|
);
|
|
3766
|
-
|
|
3788
|
+
logger14.info("Image created via RuntimeOps", { imageId: image.imageId, containerId });
|
|
3767
3789
|
return this.toImageListItemResult(image.toRecord(), false);
|
|
3768
3790
|
},
|
|
3769
3791
|
runImage: async (imageId) => {
|
|
3770
|
-
|
|
3792
|
+
logger14.debug("Running image", { imageId });
|
|
3771
3793
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3772
3794
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3773
3795
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3774
3796
|
const { agent, reused } = await container.runImage(record);
|
|
3775
|
-
|
|
3797
|
+
logger14.info("Image running", { imageId, agentId: agent.agentId, reused });
|
|
3776
3798
|
return { imageId, agentId: agent.agentId, reused };
|
|
3777
3799
|
},
|
|
3778
3800
|
stopImage: async (imageId) => {
|
|
3779
|
-
|
|
3801
|
+
logger14.debug("Stopping image", { imageId });
|
|
3780
3802
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3781
3803
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3782
3804
|
const container = this.containerRegistry.get(record.containerId);
|
|
3783
3805
|
if (container) {
|
|
3784
3806
|
await container.stopImage(imageId);
|
|
3785
|
-
|
|
3807
|
+
logger14.info("Image stopped via RuntimeOps", { imageId });
|
|
3786
3808
|
}
|
|
3787
3809
|
},
|
|
3788
3810
|
updateImage: async (imageId, updates) => {
|
|
@@ -3806,10 +3828,10 @@ var RuntimeImpl = class {
|
|
|
3806
3828
|
return this.toImageListItemResult(record, online);
|
|
3807
3829
|
},
|
|
3808
3830
|
deleteImage: async (imageId) => {
|
|
3809
|
-
|
|
3831
|
+
logger14.debug("Deleting image", { imageId });
|
|
3810
3832
|
const agentId = this.findAgentIdForImage(imageId);
|
|
3811
3833
|
if (agentId) {
|
|
3812
|
-
|
|
3834
|
+
logger14.debug("Stopping running agent before delete", { imageId, agentId });
|
|
3813
3835
|
for (const container of this.containerRegistry.values()) {
|
|
3814
3836
|
if (container.getAgent(agentId)) {
|
|
3815
3837
|
await container.destroyAgent(agentId);
|
|
@@ -3820,17 +3842,17 @@ var RuntimeImpl = class {
|
|
|
3820
3842
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3821
3843
|
if (image) {
|
|
3822
3844
|
await image.delete();
|
|
3823
|
-
|
|
3845
|
+
logger14.info("Image deleted via RuntimeOps", { imageId });
|
|
3824
3846
|
}
|
|
3825
3847
|
},
|
|
3826
3848
|
getImageMessages: async (imageId) => {
|
|
3827
|
-
|
|
3849
|
+
logger14.debug("Getting messages for image", { imageId });
|
|
3828
3850
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3829
3851
|
if (!image) {
|
|
3830
3852
|
throw new Error(`Image not found: ${imageId}`);
|
|
3831
3853
|
}
|
|
3832
3854
|
const messages = await image.getMessages();
|
|
3833
|
-
|
|
3855
|
+
logger14.debug("Got messages from storage", { imageId, count: messages.length });
|
|
3834
3856
|
return messages.map((m) => {
|
|
3835
3857
|
let content;
|
|
3836
3858
|
let role = m.role;
|
|
@@ -3947,14 +3969,14 @@ var RuntimeImpl = class {
|
|
|
3947
3969
|
}
|
|
3948
3970
|
// ==================== Lifecycle ====================
|
|
3949
3971
|
async dispose() {
|
|
3950
|
-
|
|
3972
|
+
logger14.info("Disposing RuntimeImpl");
|
|
3951
3973
|
this.commandHandler.dispose();
|
|
3952
3974
|
for (const container of this.containerRegistry.values()) {
|
|
3953
3975
|
await container.dispose();
|
|
3954
3976
|
}
|
|
3955
3977
|
this.bus.destroy();
|
|
3956
3978
|
this.containerRegistry.clear();
|
|
3957
|
-
|
|
3979
|
+
logger14.info("RuntimeImpl disposed");
|
|
3958
3980
|
}
|
|
3959
3981
|
};
|
|
3960
3982
|
|
|
@@ -3967,7 +3989,7 @@ function createRuntime(config) {
|
|
|
3967
3989
|
import { createStorage } from "unstorage";
|
|
3968
3990
|
|
|
3969
3991
|
// src/internal/persistence/repository/StorageImageRepository.ts
|
|
3970
|
-
var
|
|
3992
|
+
var logger15 = createLogger("persistence/ImageRepository");
|
|
3971
3993
|
var PREFIX = "images";
|
|
3972
3994
|
var INDEX_BY_NAME = "idx:images:name";
|
|
3973
3995
|
var INDEX_BY_CONTAINER = "idx:images:container";
|
|
@@ -3991,7 +4013,7 @@ var StorageImageRepository = class {
|
|
|
3991
4013
|
this.containerIndexKey(record.containerId, record.imageId),
|
|
3992
4014
|
record.imageId
|
|
3993
4015
|
);
|
|
3994
|
-
|
|
4016
|
+
logger15.debug("Image saved", { imageId: record.imageId });
|
|
3995
4017
|
}
|
|
3996
4018
|
async findImageById(imageId) {
|
|
3997
4019
|
const record = await this.storage.getItem(this.key(imageId));
|
|
@@ -4046,7 +4068,7 @@ var StorageImageRepository = class {
|
|
|
4046
4068
|
await this.storage.removeItem(this.nameIndexKey(record.name, imageId));
|
|
4047
4069
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, imageId));
|
|
4048
4070
|
}
|
|
4049
|
-
|
|
4071
|
+
logger15.debug("Image deleted", { imageId });
|
|
4050
4072
|
}
|
|
4051
4073
|
async imageExists(imageId) {
|
|
4052
4074
|
return await this.storage.hasItem(this.key(imageId));
|
|
@@ -4065,12 +4087,12 @@ var StorageImageRepository = class {
|
|
|
4065
4087
|
updatedAt: Date.now()
|
|
4066
4088
|
};
|
|
4067
4089
|
await this.storage.setItem(this.key(imageId), updatedRecord);
|
|
4068
|
-
|
|
4090
|
+
logger15.debug("Image metadata updated", { imageId, metadata });
|
|
4069
4091
|
}
|
|
4070
4092
|
};
|
|
4071
4093
|
|
|
4072
4094
|
// src/internal/persistence/repository/StorageContainerRepository.ts
|
|
4073
|
-
var
|
|
4095
|
+
var logger16 = createLogger("persistence/ContainerRepository");
|
|
4074
4096
|
var PREFIX2 = "containers";
|
|
4075
4097
|
var StorageContainerRepository = class {
|
|
4076
4098
|
constructor(storage) {
|
|
@@ -4081,7 +4103,7 @@ var StorageContainerRepository = class {
|
|
|
4081
4103
|
}
|
|
4082
4104
|
async saveContainer(record) {
|
|
4083
4105
|
await this.storage.setItem(this.key(record.containerId), record);
|
|
4084
|
-
|
|
4106
|
+
logger16.debug("Container saved", { containerId: record.containerId });
|
|
4085
4107
|
}
|
|
4086
4108
|
async findContainerById(containerId) {
|
|
4087
4109
|
const record = await this.storage.getItem(this.key(containerId));
|
|
@@ -4100,7 +4122,7 @@ var StorageContainerRepository = class {
|
|
|
4100
4122
|
}
|
|
4101
4123
|
async deleteContainer(containerId) {
|
|
4102
4124
|
await this.storage.removeItem(this.key(containerId));
|
|
4103
|
-
|
|
4125
|
+
logger16.debug("Container deleted", { containerId });
|
|
4104
4126
|
}
|
|
4105
4127
|
async containerExists(containerId) {
|
|
4106
4128
|
return await this.storage.hasItem(this.key(containerId));
|
|
@@ -4108,7 +4130,7 @@ var StorageContainerRepository = class {
|
|
|
4108
4130
|
};
|
|
4109
4131
|
|
|
4110
4132
|
// src/internal/persistence/repository/StorageSessionRepository.ts
|
|
4111
|
-
var
|
|
4133
|
+
var logger17 = createLogger("persistence/SessionRepository");
|
|
4112
4134
|
var PREFIX3 = "sessions";
|
|
4113
4135
|
var MESSAGES_PREFIX = "messages";
|
|
4114
4136
|
var INDEX_BY_IMAGE = "idx:sessions:image";
|
|
@@ -4139,7 +4161,7 @@ var StorageSessionRepository = class {
|
|
|
4139
4161
|
this.containerIndexKey(record.containerId, record.sessionId),
|
|
4140
4162
|
record.sessionId
|
|
4141
4163
|
);
|
|
4142
|
-
|
|
4164
|
+
logger17.debug("Session saved", { sessionId: record.sessionId });
|
|
4143
4165
|
}
|
|
4144
4166
|
async findSessionById(sessionId) {
|
|
4145
4167
|
const record = await this.storage.getItem(this.key(sessionId));
|
|
@@ -4188,7 +4210,7 @@ var StorageSessionRepository = class {
|
|
|
4188
4210
|
await this.storage.removeItem(this.imageIndexKey(record.imageId, sessionId));
|
|
4189
4211
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, sessionId));
|
|
4190
4212
|
}
|
|
4191
|
-
|
|
4213
|
+
logger17.debug("Session deleted", { sessionId });
|
|
4192
4214
|
}
|
|
4193
4215
|
async sessionExists(sessionId) {
|
|
4194
4216
|
return await this.storage.hasItem(this.key(sessionId));
|
|
@@ -4198,13 +4220,13 @@ var StorageSessionRepository = class {
|
|
|
4198
4220
|
const messages = await this.getMessages(sessionId);
|
|
4199
4221
|
messages.push(message);
|
|
4200
4222
|
await this.storage.setItem(this.messagesKey(sessionId), messages);
|
|
4201
|
-
|
|
4223
|
+
logger17.debug("Message added to session", { sessionId, subtype: message.subtype });
|
|
4202
4224
|
}
|
|
4203
4225
|
async getMessages(sessionId) {
|
|
4204
4226
|
const messages = await this.storage.getItem(this.messagesKey(sessionId));
|
|
4205
4227
|
if (!messages || !Array.isArray(messages)) {
|
|
4206
4228
|
if (messages) {
|
|
4207
|
-
|
|
4229
|
+
logger17.warn("Messages data is not an array, resetting", {
|
|
4208
4230
|
sessionId,
|
|
4209
4231
|
type: typeof messages
|
|
4210
4232
|
});
|
|
@@ -4215,12 +4237,12 @@ var StorageSessionRepository = class {
|
|
|
4215
4237
|
}
|
|
4216
4238
|
async clearMessages(sessionId) {
|
|
4217
4239
|
await this.storage.removeItem(this.messagesKey(sessionId));
|
|
4218
|
-
|
|
4240
|
+
logger17.debug("Messages cleared for session", { sessionId });
|
|
4219
4241
|
}
|
|
4220
4242
|
};
|
|
4221
4243
|
|
|
4222
4244
|
// src/internal/persistence/PersistenceImpl.ts
|
|
4223
|
-
var
|
|
4245
|
+
var logger18 = createLogger("persistence/Persistence");
|
|
4224
4246
|
var PersistenceImpl = class _PersistenceImpl {
|
|
4225
4247
|
images;
|
|
4226
4248
|
containers;
|
|
@@ -4234,7 +4256,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4234
4256
|
this.images = new StorageImageRepository(this.storage);
|
|
4235
4257
|
this.containers = new StorageContainerRepository(this.storage);
|
|
4236
4258
|
this.sessions = new StorageSessionRepository(this.storage);
|
|
4237
|
-
|
|
4259
|
+
logger18.info("Persistence created", { driver: driverName });
|
|
4238
4260
|
}
|
|
4239
4261
|
/**
|
|
4240
4262
|
* Create a PersistenceImpl instance (async factory)
|
|
@@ -4255,7 +4277,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4255
4277
|
*/
|
|
4256
4278
|
async dispose() {
|
|
4257
4279
|
await this.storage.dispose();
|
|
4258
|
-
|
|
4280
|
+
logger18.info("Persistence disposed");
|
|
4259
4281
|
}
|
|
4260
4282
|
};
|
|
4261
4283
|
async function createStorageFromConfig(config) {
|