@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.cjs
CHANGED
|
@@ -1916,6 +1916,7 @@ var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
|
1916
1916
|
var import_rxjs2 = require("rxjs");
|
|
1917
1917
|
|
|
1918
1918
|
// src/environment/buildOptions.ts
|
|
1919
|
+
var logger7 = createLogger("environment/buildOptions");
|
|
1919
1920
|
function buildOptions(context, abortController) {
|
|
1920
1921
|
const options = {
|
|
1921
1922
|
abortController,
|
|
@@ -1924,9 +1925,15 @@ function buildOptions(context, abortController) {
|
|
|
1924
1925
|
if (context.cwd) {
|
|
1925
1926
|
options.cwd = context.cwd;
|
|
1926
1927
|
}
|
|
1927
|
-
const env = {
|
|
1928
|
-
|
|
1929
|
-
|
|
1928
|
+
const env = {};
|
|
1929
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
1930
|
+
if (value !== void 0) {
|
|
1931
|
+
env[key] = value;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
if (!env.PATH && process.env.PATH) {
|
|
1935
|
+
env.PATH = process.env.PATH;
|
|
1936
|
+
}
|
|
1930
1937
|
if (context.baseUrl) {
|
|
1931
1938
|
env.ANTHROPIC_BASE_URL = context.baseUrl;
|
|
1932
1939
|
}
|
|
@@ -1934,6 +1941,19 @@ function buildOptions(context, abortController) {
|
|
|
1934
1941
|
env.ANTHROPIC_API_KEY = context.apiKey;
|
|
1935
1942
|
}
|
|
1936
1943
|
options.env = env;
|
|
1944
|
+
logger7.info("buildOptions called", {
|
|
1945
|
+
hasPath: !!env.PATH,
|
|
1946
|
+
pathLength: env.PATH?.length,
|
|
1947
|
+
hasApiKey: !!env.ANTHROPIC_API_KEY,
|
|
1948
|
+
hasBaseUrl: !!env.ANTHROPIC_BASE_URL,
|
|
1949
|
+
baseUrl: env.ANTHROPIC_BASE_URL,
|
|
1950
|
+
model: context.model,
|
|
1951
|
+
permissionMode: context.permissionMode || "bypassPermissions",
|
|
1952
|
+
cwd: context.cwd
|
|
1953
|
+
});
|
|
1954
|
+
options.stderr = (data) => {
|
|
1955
|
+
logger7.info("SDK stderr", { data: data.trim() });
|
|
1956
|
+
};
|
|
1937
1957
|
if (context.model) options.model = context.model;
|
|
1938
1958
|
if (context.systemPrompt) options.systemPrompt = context.systemPrompt;
|
|
1939
1959
|
if (context.maxTurns) options.maxTurns = context.maxTurns;
|
|
@@ -2035,7 +2055,7 @@ async function* observableToAsyncIterable(observable) {
|
|
|
2035
2055
|
}
|
|
2036
2056
|
|
|
2037
2057
|
// src/environment/ClaudeEffector.ts
|
|
2038
|
-
var
|
|
2058
|
+
var logger8 = createLogger("ecosystem/ClaudeEffector");
|
|
2039
2059
|
var DEFAULT_TIMEOUT = 3e4;
|
|
2040
2060
|
var ClaudeEffector = class {
|
|
2041
2061
|
config;
|
|
@@ -2054,12 +2074,12 @@ var ClaudeEffector = class {
|
|
|
2054
2074
|
* Connect to SystemBus consumer to subscribe to events
|
|
2055
2075
|
*/
|
|
2056
2076
|
connect(consumer) {
|
|
2057
|
-
|
|
2077
|
+
logger8.debug("ClaudeEffector connected to SystemBusConsumer", {
|
|
2058
2078
|
agentId: this.config.agentId
|
|
2059
2079
|
});
|
|
2060
2080
|
consumer.on("user_message", async (event) => {
|
|
2061
2081
|
const typedEvent = event;
|
|
2062
|
-
|
|
2082
|
+
logger8.debug("user_message event received", {
|
|
2063
2083
|
eventAgentId: typedEvent.context?.agentId,
|
|
2064
2084
|
myAgentId: this.config.agentId,
|
|
2065
2085
|
matches: typedEvent.context?.agentId === this.config.agentId
|
|
@@ -2095,14 +2115,14 @@ var ClaudeEffector = class {
|
|
|
2095
2115
|
this.currentMeta = meta;
|
|
2096
2116
|
const timeout = this.config.timeout ?? DEFAULT_TIMEOUT;
|
|
2097
2117
|
const timeoutId = setTimeout(() => {
|
|
2098
|
-
|
|
2118
|
+
logger8.warn("Request timeout", { timeout });
|
|
2099
2119
|
this.currentAbortController?.abort(new Error(`Request timeout after ${timeout}ms`));
|
|
2100
2120
|
}, timeout);
|
|
2101
2121
|
try {
|
|
2102
2122
|
await this.initialize(this.currentAbortController);
|
|
2103
2123
|
const sessionId = this.config.sessionId || "default";
|
|
2104
2124
|
const sdkUserMessage = buildSDKUserMessage(message, sessionId);
|
|
2105
|
-
|
|
2125
|
+
logger8.debug("Sending message to Claude", {
|
|
2106
2126
|
content: typeof message.content === "string" ? message.content.substring(0, 80) : "[structured]",
|
|
2107
2127
|
timeout,
|
|
2108
2128
|
requestId: meta.requestId
|
|
@@ -2119,13 +2139,13 @@ var ClaudeEffector = class {
|
|
|
2119
2139
|
*/
|
|
2120
2140
|
interrupt(meta) {
|
|
2121
2141
|
if (this.claudeQuery) {
|
|
2122
|
-
|
|
2142
|
+
logger8.debug("Interrupting Claude query", { requestId: meta?.requestId });
|
|
2123
2143
|
this.wasInterrupted = true;
|
|
2124
2144
|
if (meta) {
|
|
2125
2145
|
this.currentMeta = meta;
|
|
2126
2146
|
}
|
|
2127
2147
|
this.claudeQuery.interrupt().catch((err) => {
|
|
2128
|
-
|
|
2148
|
+
logger8.debug("SDK interrupt() error (may be expected)", { error: err });
|
|
2129
2149
|
});
|
|
2130
2150
|
}
|
|
2131
2151
|
}
|
|
@@ -2134,7 +2154,7 @@ var ClaudeEffector = class {
|
|
|
2134
2154
|
*/
|
|
2135
2155
|
async initialize(abortController) {
|
|
2136
2156
|
if (this.isInitialized) return;
|
|
2137
|
-
|
|
2157
|
+
logger8.info("Initializing ClaudeEffector");
|
|
2138
2158
|
const context = {
|
|
2139
2159
|
apiKey: this.config.apiKey,
|
|
2140
2160
|
baseUrl: this.config.baseUrl,
|
|
@@ -2151,7 +2171,7 @@ var ClaudeEffector = class {
|
|
|
2151
2171
|
});
|
|
2152
2172
|
this.isInitialized = true;
|
|
2153
2173
|
this.startBackgroundListener();
|
|
2154
|
-
|
|
2174
|
+
logger8.info("ClaudeEffector initialized");
|
|
2155
2175
|
}
|
|
2156
2176
|
/**
|
|
2157
2177
|
* Start background listener for SDK responses
|
|
@@ -2160,7 +2180,7 @@ var ClaudeEffector = class {
|
|
|
2160
2180
|
(async () => {
|
|
2161
2181
|
try {
|
|
2162
2182
|
for await (const sdkMsg of this.claudeQuery) {
|
|
2163
|
-
|
|
2183
|
+
logger8.debug("SDK message received", {
|
|
2164
2184
|
type: sdkMsg.type,
|
|
2165
2185
|
subtype: sdkMsg.subtype,
|
|
2166
2186
|
sessionId: sdkMsg.session_id,
|
|
@@ -2177,10 +2197,10 @@ var ClaudeEffector = class {
|
|
|
2177
2197
|
}
|
|
2178
2198
|
if (sdkMsg.type === "result") {
|
|
2179
2199
|
const resultMsg = sdkMsg;
|
|
2180
|
-
|
|
2200
|
+
logger8.info("SDK result received (full)", {
|
|
2181
2201
|
fullResult: JSON.stringify(sdkMsg, null, 2)
|
|
2182
2202
|
});
|
|
2183
|
-
|
|
2203
|
+
logger8.info("SDK result received", {
|
|
2184
2204
|
subtype: resultMsg.subtype,
|
|
2185
2205
|
isError: resultMsg.is_error,
|
|
2186
2206
|
errors: resultMsg.errors,
|
|
@@ -2198,10 +2218,10 @@ var ClaudeEffector = class {
|
|
|
2198
2218
|
}
|
|
2199
2219
|
} catch (error) {
|
|
2200
2220
|
if (this.isAbortError(error)) {
|
|
2201
|
-
|
|
2221
|
+
logger8.debug("Background listener aborted (expected during interrupt)");
|
|
2202
2222
|
this.resetState();
|
|
2203
2223
|
} else {
|
|
2204
|
-
|
|
2224
|
+
logger8.error("Background listener error", { error });
|
|
2205
2225
|
if (this.currentMeta) {
|
|
2206
2226
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
2207
2227
|
this.receptor.emitError(errorMessage, "runtime_error", this.currentMeta);
|
|
@@ -2233,7 +2253,7 @@ var ClaudeEffector = class {
|
|
|
2233
2253
|
* Dispose and cleanup resources
|
|
2234
2254
|
*/
|
|
2235
2255
|
dispose() {
|
|
2236
|
-
|
|
2256
|
+
logger8.debug("Disposing ClaudeEffector");
|
|
2237
2257
|
if (this.currentAbortController) {
|
|
2238
2258
|
this.currentAbortController.abort();
|
|
2239
2259
|
}
|
|
@@ -2264,7 +2284,7 @@ var ClaudeEnvironment = class {
|
|
|
2264
2284
|
};
|
|
2265
2285
|
|
|
2266
2286
|
// src/internal/RuntimeAgent.ts
|
|
2267
|
-
var
|
|
2287
|
+
var logger9 = createLogger("runtime/RuntimeAgent");
|
|
2268
2288
|
var BusPresenter = class {
|
|
2269
2289
|
constructor(producer, session, agentId, imageId, containerId) {
|
|
2270
2290
|
this.producer = producer;
|
|
@@ -2301,7 +2321,7 @@ var BusPresenter = class {
|
|
|
2301
2321
|
this.producer.emit(systemEvent);
|
|
2302
2322
|
if (category === "message") {
|
|
2303
2323
|
this.session.addMessage(data).catch((err) => {
|
|
2304
|
-
|
|
2324
|
+
logger9.error("Failed to persist message", { error: err, messageType: output.type });
|
|
2305
2325
|
});
|
|
2306
2326
|
}
|
|
2307
2327
|
}
|
|
@@ -2359,7 +2379,7 @@ var BusPresenter = class {
|
|
|
2359
2379
|
};
|
|
2360
2380
|
}
|
|
2361
2381
|
default:
|
|
2362
|
-
|
|
2382
|
+
logger9.warn("Unknown message type, passing through", { type: output.type });
|
|
2363
2383
|
return eventData;
|
|
2364
2384
|
}
|
|
2365
2385
|
}
|
|
@@ -2412,6 +2432,7 @@ var RuntimeAgent = class {
|
|
|
2412
2432
|
baseUrl: config.llmConfig.baseUrl,
|
|
2413
2433
|
model: config.llmConfig.model,
|
|
2414
2434
|
systemPrompt: config.config.systemPrompt,
|
|
2435
|
+
cwd: config.sandbox.workdir.path,
|
|
2415
2436
|
resumeSessionId,
|
|
2416
2437
|
onSessionIdCaptured: (sdkSessionId) => {
|
|
2417
2438
|
this.saveSessionId(sdkSessionId);
|
|
@@ -2419,9 +2440,10 @@ var RuntimeAgent = class {
|
|
|
2419
2440
|
});
|
|
2420
2441
|
this.environment.receptor.connect(config.bus.asProducer());
|
|
2421
2442
|
this.environment.effector.connect(config.bus.asConsumer());
|
|
2422
|
-
|
|
2443
|
+
logger9.info("ClaudeEnvironment created for agent", {
|
|
2423
2444
|
agentId: this.agentId,
|
|
2424
2445
|
imageId: this.imageId,
|
|
2446
|
+
cwd: config.sandbox.workdir.path,
|
|
2425
2447
|
resumeSessionId: resumeSessionId ?? "none",
|
|
2426
2448
|
isResume: !!resumeSessionId,
|
|
2427
2449
|
imageMetadata: config.image.metadata
|
|
@@ -2453,14 +2475,14 @@ var RuntimeAgent = class {
|
|
|
2453
2475
|
this.driver = new BusDriver(config.bus.asConsumer(), {
|
|
2454
2476
|
agentId: this.agentId,
|
|
2455
2477
|
onStreamEvent: (event) => {
|
|
2456
|
-
|
|
2478
|
+
logger9.debug("BusDriver \u2192 Engine.handleStreamEvent", { type: event.type });
|
|
2457
2479
|
this.engine.handleStreamEvent(event);
|
|
2458
2480
|
},
|
|
2459
2481
|
onStreamComplete: (reason) => {
|
|
2460
|
-
|
|
2482
|
+
logger9.debug("Stream completed", { reason, agentId: this.agentId });
|
|
2461
2483
|
}
|
|
2462
2484
|
});
|
|
2463
|
-
|
|
2485
|
+
logger9.debug("RuntimeAgent created", {
|
|
2464
2486
|
agentId: this.agentId,
|
|
2465
2487
|
imageId: this.imageId
|
|
2466
2488
|
});
|
|
@@ -2469,13 +2491,13 @@ var RuntimeAgent = class {
|
|
|
2469
2491
|
* Save SDK session ID to image metadata for future resume
|
|
2470
2492
|
*/
|
|
2471
2493
|
saveSessionId(sdkSessionId) {
|
|
2472
|
-
|
|
2494
|
+
logger9.info("Saving SDK session ID to image metadata", {
|
|
2473
2495
|
agentId: this.agentId,
|
|
2474
2496
|
imageId: this.imageId,
|
|
2475
2497
|
sdkSessionId
|
|
2476
2498
|
});
|
|
2477
2499
|
this.imageRepository.updateMetadata(this.imageId, { claudeSdkSessionId: sdkSessionId }).catch((err) => {
|
|
2478
|
-
|
|
2500
|
+
logger9.error("Failed to save SDK session ID", { error: err, imageId: this.imageId });
|
|
2479
2501
|
});
|
|
2480
2502
|
}
|
|
2481
2503
|
get lifecycle() {
|
|
@@ -2488,7 +2510,7 @@ var RuntimeAgent = class {
|
|
|
2488
2510
|
* @param requestId - Request ID for correlation
|
|
2489
2511
|
*/
|
|
2490
2512
|
async receive(content, requestId) {
|
|
2491
|
-
|
|
2513
|
+
logger9.debug("RuntimeAgent.receive called", {
|
|
2492
2514
|
agentId: this.agentId,
|
|
2493
2515
|
contentPreview: content.substring(0, 50),
|
|
2494
2516
|
requestId
|
|
@@ -2497,13 +2519,13 @@ var RuntimeAgent = class {
|
|
|
2497
2519
|
throw new Error(`Cannot send message to ${this._lifecycle} agent`);
|
|
2498
2520
|
}
|
|
2499
2521
|
await this.interactor.receive(content, requestId || `req_${Date.now()}`);
|
|
2500
|
-
|
|
2522
|
+
logger9.debug("RuntimeAgent.receive completed", { agentId: this.agentId });
|
|
2501
2523
|
}
|
|
2502
2524
|
/**
|
|
2503
2525
|
* Interrupt current operation
|
|
2504
2526
|
*/
|
|
2505
2527
|
interrupt(requestId) {
|
|
2506
|
-
|
|
2528
|
+
logger9.debug("RuntimeAgent.interrupt called", { agentId: this.agentId, requestId });
|
|
2507
2529
|
this.interactor.interrupt(requestId);
|
|
2508
2530
|
this.producer.emit({
|
|
2509
2531
|
type: "interrupted",
|
|
@@ -2698,7 +2720,7 @@ var RuntimeSandbox = class {
|
|
|
2698
2720
|
};
|
|
2699
2721
|
|
|
2700
2722
|
// src/internal/RuntimeImage.ts
|
|
2701
|
-
var
|
|
2723
|
+
var logger10 = createLogger("runtime/RuntimeImage");
|
|
2702
2724
|
var RuntimeImage = class _RuntimeImage {
|
|
2703
2725
|
constructor(record, context) {
|
|
2704
2726
|
this.record = record;
|
|
@@ -2755,7 +2777,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2755
2777
|
createdAt: now,
|
|
2756
2778
|
updatedAt: now
|
|
2757
2779
|
});
|
|
2758
|
-
|
|
2780
|
+
logger10.info("Image created", {
|
|
2759
2781
|
imageId,
|
|
2760
2782
|
sessionId,
|
|
2761
2783
|
containerId: config.containerId,
|
|
@@ -2769,10 +2791,10 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2769
2791
|
static async load(imageId, context) {
|
|
2770
2792
|
const record = await context.imageRepository.findImageById(imageId);
|
|
2771
2793
|
if (!record) {
|
|
2772
|
-
|
|
2794
|
+
logger10.debug("Image not found", { imageId });
|
|
2773
2795
|
return null;
|
|
2774
2796
|
}
|
|
2775
|
-
|
|
2797
|
+
logger10.debug("Image loaded", { imageId, name: record.name });
|
|
2776
2798
|
return new _RuntimeImage(record, context);
|
|
2777
2799
|
}
|
|
2778
2800
|
/**
|
|
@@ -2806,7 +2828,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2806
2828
|
updatedAt: now
|
|
2807
2829
|
};
|
|
2808
2830
|
await this.context.imageRepository.saveImage(updatedRecord);
|
|
2809
|
-
|
|
2831
|
+
logger10.info("Image updated", { imageId: this.imageId, updates });
|
|
2810
2832
|
return new _RuntimeImage(updatedRecord, this.context);
|
|
2811
2833
|
}
|
|
2812
2834
|
/**
|
|
@@ -2815,7 +2837,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2815
2837
|
async delete() {
|
|
2816
2838
|
await this.context.sessionRepository.deleteSession(this.sessionId);
|
|
2817
2839
|
await this.context.imageRepository.deleteImage(this.imageId);
|
|
2818
|
-
|
|
2840
|
+
logger10.info("Image deleted", { imageId: this.imageId, sessionId: this.sessionId });
|
|
2819
2841
|
}
|
|
2820
2842
|
/**
|
|
2821
2843
|
* Get the underlying record
|
|
@@ -2837,7 +2859,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2837
2859
|
};
|
|
2838
2860
|
|
|
2839
2861
|
// src/internal/RuntimeContainer.ts
|
|
2840
|
-
var
|
|
2862
|
+
var logger11 = createLogger("runtime/RuntimeContainer");
|
|
2841
2863
|
var RuntimeContainer = class _RuntimeContainer {
|
|
2842
2864
|
containerId;
|
|
2843
2865
|
createdAt;
|
|
@@ -2877,7 +2899,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2877
2899
|
containerId
|
|
2878
2900
|
}
|
|
2879
2901
|
});
|
|
2880
|
-
|
|
2902
|
+
logger11.info("Container created", { containerId });
|
|
2881
2903
|
return container;
|
|
2882
2904
|
}
|
|
2883
2905
|
/**
|
|
@@ -2886,7 +2908,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2886
2908
|
static async load(containerId, context) {
|
|
2887
2909
|
const record = await context.persistence.containers.findContainerById(containerId);
|
|
2888
2910
|
if (!record) return null;
|
|
2889
|
-
|
|
2911
|
+
logger11.info("Container loaded", { containerId });
|
|
2890
2912
|
return new _RuntimeContainer(containerId, record.createdAt, context);
|
|
2891
2913
|
}
|
|
2892
2914
|
// ==================== Image → Agent Lifecycle ====================
|
|
@@ -2899,7 +2921,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2899
2921
|
if (existingAgentId) {
|
|
2900
2922
|
const existingAgent = this.agents.get(existingAgentId);
|
|
2901
2923
|
if (existingAgent) {
|
|
2902
|
-
|
|
2924
|
+
logger11.info("Reusing existing agent for image", {
|
|
2903
2925
|
containerId: this.containerId,
|
|
2904
2926
|
imageId: image.imageId,
|
|
2905
2927
|
agentId: existingAgentId
|
|
@@ -2958,7 +2980,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2958
2980
|
agentId
|
|
2959
2981
|
}
|
|
2960
2982
|
});
|
|
2961
|
-
|
|
2983
|
+
logger11.info("Agent created for image", {
|
|
2962
2984
|
containerId: this.containerId,
|
|
2963
2985
|
imageId: image.imageId,
|
|
2964
2986
|
agentId
|
|
@@ -2971,17 +2993,17 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2971
2993
|
async stopImage(imageId) {
|
|
2972
2994
|
const agentId = this.imageToAgent.get(imageId);
|
|
2973
2995
|
if (!agentId) {
|
|
2974
|
-
|
|
2996
|
+
logger11.debug("Image not running, nothing to stop", {
|
|
2975
2997
|
imageId,
|
|
2976
2998
|
containerId: this.containerId
|
|
2977
2999
|
});
|
|
2978
3000
|
return false;
|
|
2979
3001
|
}
|
|
2980
|
-
|
|
3002
|
+
logger11.info("Stopping image", { imageId, agentId, containerId: this.containerId });
|
|
2981
3003
|
const success = await this.destroyAgent(agentId);
|
|
2982
3004
|
if (success) {
|
|
2983
3005
|
this.imageToAgent.delete(imageId);
|
|
2984
|
-
|
|
3006
|
+
logger11.info("Image stopped", { imageId, agentId, containerId: this.containerId });
|
|
2985
3007
|
}
|
|
2986
3008
|
return success;
|
|
2987
3009
|
}
|
|
@@ -3038,7 +3060,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3038
3060
|
agentId
|
|
3039
3061
|
}
|
|
3040
3062
|
});
|
|
3041
|
-
|
|
3063
|
+
logger11.info("Agent destroyed", { containerId: this.containerId, agentId });
|
|
3042
3064
|
return true;
|
|
3043
3065
|
}
|
|
3044
3066
|
async destroyAllAgents() {
|
|
@@ -3066,7 +3088,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3066
3088
|
}
|
|
3067
3089
|
});
|
|
3068
3090
|
this.context.onDisposed?.(this.containerId);
|
|
3069
|
-
|
|
3091
|
+
logger11.info("Container disposed", { containerId: this.containerId, agentCount });
|
|
3070
3092
|
}
|
|
3071
3093
|
// ==================== Private Helpers ====================
|
|
3072
3094
|
generateAgentId() {
|
|
@@ -3077,7 +3099,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3077
3099
|
};
|
|
3078
3100
|
|
|
3079
3101
|
// src/internal/BaseEventHandler.ts
|
|
3080
|
-
var
|
|
3102
|
+
var logger12 = createLogger("runtime/BaseEventHandler");
|
|
3081
3103
|
var BaseEventHandler = class {
|
|
3082
3104
|
bus;
|
|
3083
3105
|
unsubscribes = [];
|
|
@@ -3116,7 +3138,7 @@ var BaseEventHandler = class {
|
|
|
3116
3138
|
handleError(err, context) {
|
|
3117
3139
|
const message = err instanceof Error ? err.message : String(err);
|
|
3118
3140
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3119
|
-
|
|
3141
|
+
logger12.error(`Error in ${context.operation || "handler"}`, {
|
|
3120
3142
|
message,
|
|
3121
3143
|
requestId: context.requestId,
|
|
3122
3144
|
details: context.details
|
|
@@ -3143,7 +3165,7 @@ var BaseEventHandler = class {
|
|
|
3143
3165
|
try {
|
|
3144
3166
|
context.onError(err);
|
|
3145
3167
|
} catch (callbackErr) {
|
|
3146
|
-
|
|
3168
|
+
logger12.error("Error in onError callback", { error: callbackErr });
|
|
3147
3169
|
}
|
|
3148
3170
|
}
|
|
3149
3171
|
}
|
|
@@ -3161,12 +3183,12 @@ var BaseEventHandler = class {
|
|
|
3161
3183
|
unsubscribe();
|
|
3162
3184
|
}
|
|
3163
3185
|
this.unsubscribes = [];
|
|
3164
|
-
|
|
3186
|
+
logger12.debug(`${this.constructor.name} disposed`);
|
|
3165
3187
|
}
|
|
3166
3188
|
};
|
|
3167
3189
|
|
|
3168
3190
|
// src/internal/CommandHandler.ts
|
|
3169
|
-
var
|
|
3191
|
+
var logger13 = createLogger("runtime/CommandHandler");
|
|
3170
3192
|
function createResponse(type, data) {
|
|
3171
3193
|
return {
|
|
3172
3194
|
type,
|
|
@@ -3199,7 +3221,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3199
3221
|
super(bus);
|
|
3200
3222
|
this.ops = operations;
|
|
3201
3223
|
this.bindHandlers();
|
|
3202
|
-
|
|
3224
|
+
logger13.debug("CommandHandler created");
|
|
3203
3225
|
}
|
|
3204
3226
|
/**
|
|
3205
3227
|
* Log error and emit system_error event
|
|
@@ -3207,7 +3229,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3207
3229
|
emitError(operation, err, requestId, context) {
|
|
3208
3230
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
3209
3231
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3210
|
-
|
|
3232
|
+
logger13.error(operation, {
|
|
3211
3233
|
requestId,
|
|
3212
3234
|
...context,
|
|
3213
3235
|
error: errorMessage,
|
|
@@ -3264,12 +3286,12 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3264
3286
|
this.subscribe(
|
|
3265
3287
|
this.bus.onCommand("image_messages_request", (event) => this.handleImageMessages(event))
|
|
3266
3288
|
);
|
|
3267
|
-
|
|
3289
|
+
logger13.debug("Command handlers bound");
|
|
3268
3290
|
}
|
|
3269
3291
|
// ==================== Container Handlers ====================
|
|
3270
3292
|
async handleContainerCreate(event) {
|
|
3271
3293
|
const { requestId, containerId } = event.data;
|
|
3272
|
-
|
|
3294
|
+
logger13.debug("Handling container_create_request", { requestId, containerId });
|
|
3273
3295
|
try {
|
|
3274
3296
|
await this.ops.createContainer(containerId);
|
|
3275
3297
|
this.bus.emit(
|
|
@@ -3291,7 +3313,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3291
3313
|
}
|
|
3292
3314
|
handleContainerGet(event) {
|
|
3293
3315
|
const { requestId, containerId } = event.data;
|
|
3294
|
-
|
|
3316
|
+
logger13.debug("Handling container_get_request", { requestId, containerId });
|
|
3295
3317
|
const container = this.ops.getContainer(containerId);
|
|
3296
3318
|
this.bus.emit(
|
|
3297
3319
|
createResponse("container_get_response", {
|
|
@@ -3303,7 +3325,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3303
3325
|
}
|
|
3304
3326
|
handleContainerList(event) {
|
|
3305
3327
|
const { requestId } = event.data;
|
|
3306
|
-
|
|
3328
|
+
logger13.debug("Handling container_list_request", { requestId });
|
|
3307
3329
|
const containers = this.ops.listContainers();
|
|
3308
3330
|
this.bus.emit(
|
|
3309
3331
|
createResponse("container_list_response", {
|
|
@@ -3315,7 +3337,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3315
3337
|
// ==================== Agent Handlers ====================
|
|
3316
3338
|
handleAgentGet(event) {
|
|
3317
3339
|
const { requestId, agentId } = event.data;
|
|
3318
|
-
|
|
3340
|
+
logger13.debug("Handling agent_get_request", { requestId, agentId });
|
|
3319
3341
|
const agent = this.ops.getAgent(agentId);
|
|
3320
3342
|
this.bus.emit(
|
|
3321
3343
|
createResponse("agent_get_response", {
|
|
@@ -3328,7 +3350,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3328
3350
|
}
|
|
3329
3351
|
handleAgentList(event) {
|
|
3330
3352
|
const { requestId, containerId } = event.data;
|
|
3331
|
-
|
|
3353
|
+
logger13.debug("Handling agent_list_request", { requestId, containerId });
|
|
3332
3354
|
const agents = this.ops.listAgents(containerId);
|
|
3333
3355
|
this.bus.emit(
|
|
3334
3356
|
createResponse("agent_list_response", {
|
|
@@ -3343,7 +3365,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3343
3365
|
}
|
|
3344
3366
|
async handleAgentDestroy(event) {
|
|
3345
3367
|
const { requestId, agentId } = event.data;
|
|
3346
|
-
|
|
3368
|
+
logger13.debug("Handling agent_destroy_request", { requestId, agentId });
|
|
3347
3369
|
try {
|
|
3348
3370
|
const success = await this.ops.destroyAgent(agentId);
|
|
3349
3371
|
this.bus.emit(
|
|
@@ -3367,7 +3389,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3367
3389
|
}
|
|
3368
3390
|
async handleAgentDestroyAll(event) {
|
|
3369
3391
|
const { requestId, containerId } = event.data;
|
|
3370
|
-
|
|
3392
|
+
logger13.debug("Handling agent_destroy_all_request", { requestId, containerId });
|
|
3371
3393
|
try {
|
|
3372
3394
|
await this.ops.destroyAllAgents(containerId);
|
|
3373
3395
|
this.bus.emit(
|
|
@@ -3389,7 +3411,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3389
3411
|
}
|
|
3390
3412
|
async handleMessageSend(event) {
|
|
3391
3413
|
const { requestId, imageId, agentId, content } = event.data;
|
|
3392
|
-
|
|
3414
|
+
logger13.debug("Handling message_send_request", { requestId, imageId, agentId });
|
|
3393
3415
|
try {
|
|
3394
3416
|
const result = await this.ops.receiveMessage(imageId, agentId, content, requestId);
|
|
3395
3417
|
this.bus.emit(
|
|
@@ -3413,7 +3435,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3413
3435
|
}
|
|
3414
3436
|
handleAgentInterrupt(event) {
|
|
3415
3437
|
const { requestId, imageId, agentId } = event.data;
|
|
3416
|
-
|
|
3438
|
+
logger13.debug("Handling agent_interrupt_request", { requestId, imageId, agentId });
|
|
3417
3439
|
try {
|
|
3418
3440
|
const result = this.ops.interruptAgent(imageId, agentId, requestId);
|
|
3419
3441
|
this.bus.emit(
|
|
@@ -3438,7 +3460,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3438
3460
|
// ==================== Image Handlers ====================
|
|
3439
3461
|
async handleImageCreate(event) {
|
|
3440
3462
|
const { requestId, containerId, config } = event.data;
|
|
3441
|
-
|
|
3463
|
+
logger13.debug("Handling image_create_request", { requestId, containerId });
|
|
3442
3464
|
try {
|
|
3443
3465
|
const record = await this.ops.createImage(containerId, config);
|
|
3444
3466
|
this.bus.emit(
|
|
@@ -3460,7 +3482,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3460
3482
|
}
|
|
3461
3483
|
async handleImageRun(event) {
|
|
3462
3484
|
const { requestId, imageId } = event.data;
|
|
3463
|
-
|
|
3485
|
+
logger13.debug("Handling image_run_request", { requestId, imageId });
|
|
3464
3486
|
try {
|
|
3465
3487
|
const result = await this.ops.runImage(imageId);
|
|
3466
3488
|
this.bus.emit(
|
|
@@ -3486,7 +3508,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3486
3508
|
}
|
|
3487
3509
|
async handleImageStop(event) {
|
|
3488
3510
|
const { requestId, imageId } = event.data;
|
|
3489
|
-
|
|
3511
|
+
logger13.debug("Handling image_stop_request", { requestId, imageId });
|
|
3490
3512
|
try {
|
|
3491
3513
|
await this.ops.stopImage(imageId);
|
|
3492
3514
|
this.bus.emit(
|
|
@@ -3508,7 +3530,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3508
3530
|
}
|
|
3509
3531
|
async handleImageUpdate(event) {
|
|
3510
3532
|
const { requestId, imageId, updates } = event.data;
|
|
3511
|
-
|
|
3533
|
+
logger13.debug("Handling image_update_request", { requestId, imageId });
|
|
3512
3534
|
try {
|
|
3513
3535
|
const record = await this.ops.updateImage(imageId, updates);
|
|
3514
3536
|
this.bus.emit(
|
|
@@ -3530,7 +3552,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3530
3552
|
}
|
|
3531
3553
|
async handleImageList(event) {
|
|
3532
3554
|
const { requestId, containerId } = event.data;
|
|
3533
|
-
|
|
3555
|
+
logger13.debug("Handling image_list_request", { requestId, containerId });
|
|
3534
3556
|
try {
|
|
3535
3557
|
const images = await this.ops.listImages(containerId);
|
|
3536
3558
|
this.bus.emit(
|
|
@@ -3552,7 +3574,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3552
3574
|
}
|
|
3553
3575
|
async handleImageGet(event) {
|
|
3554
3576
|
const { requestId, imageId } = event.data;
|
|
3555
|
-
|
|
3577
|
+
logger13.debug("Handling image_get_request", { requestId, imageId });
|
|
3556
3578
|
try {
|
|
3557
3579
|
const image = await this.ops.getImage(imageId);
|
|
3558
3580
|
this.bus.emit(
|
|
@@ -3573,7 +3595,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3573
3595
|
}
|
|
3574
3596
|
async handleImageDelete(event) {
|
|
3575
3597
|
const { requestId, imageId } = event.data;
|
|
3576
|
-
|
|
3598
|
+
logger13.debug("Handling image_delete_request", { requestId, imageId });
|
|
3577
3599
|
try {
|
|
3578
3600
|
await this.ops.deleteImage(imageId);
|
|
3579
3601
|
this.bus.emit(
|
|
@@ -3595,10 +3617,10 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3595
3617
|
}
|
|
3596
3618
|
async handleImageMessages(event) {
|
|
3597
3619
|
const { requestId, imageId } = event.data;
|
|
3598
|
-
|
|
3620
|
+
logger13.info("Handling image_messages_request", { requestId, imageId });
|
|
3599
3621
|
try {
|
|
3600
3622
|
const messages = await this.ops.getImageMessages(imageId);
|
|
3601
|
-
|
|
3623
|
+
logger13.info("Got messages for image", { imageId, count: messages.length });
|
|
3602
3624
|
this.bus.emit(
|
|
3603
3625
|
createResponse("image_messages_response", {
|
|
3604
3626
|
requestId,
|
|
@@ -3606,7 +3628,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3606
3628
|
messages
|
|
3607
3629
|
})
|
|
3608
3630
|
);
|
|
3609
|
-
|
|
3631
|
+
logger13.info("Emitted image_messages_response", { requestId, imageId });
|
|
3610
3632
|
} catch (err) {
|
|
3611
3633
|
this.emitError("Failed to get image messages", err, requestId, { imageId });
|
|
3612
3634
|
this.bus.emit(
|
|
@@ -3625,7 +3647,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3625
3647
|
// src/RuntimeImpl.ts
|
|
3626
3648
|
var import_node_os = require("os");
|
|
3627
3649
|
var import_node_path2 = require("path");
|
|
3628
|
-
var
|
|
3650
|
+
var logger14 = createLogger("runtime/RuntimeImpl");
|
|
3629
3651
|
var RuntimeImpl = class {
|
|
3630
3652
|
persistence;
|
|
3631
3653
|
llmProvider;
|
|
@@ -3636,20 +3658,20 @@ var RuntimeImpl = class {
|
|
|
3636
3658
|
/** Container registry: containerId -> RuntimeContainer */
|
|
3637
3659
|
containerRegistry = /* @__PURE__ */ new Map();
|
|
3638
3660
|
constructor(config) {
|
|
3639
|
-
|
|
3661
|
+
logger14.info("RuntimeImpl constructor start");
|
|
3640
3662
|
this.persistence = config.persistence;
|
|
3641
3663
|
this.llmProvider = config.llmProvider;
|
|
3642
3664
|
this.basePath = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".agentx");
|
|
3643
|
-
|
|
3665
|
+
logger14.info("Creating SystemBus");
|
|
3644
3666
|
this.bus = new SystemBusImpl();
|
|
3645
3667
|
this.llmConfig = this.llmProvider.provide();
|
|
3646
|
-
|
|
3668
|
+
logger14.info("LLM config loaded", {
|
|
3647
3669
|
hasApiKey: !!this.llmConfig.apiKey,
|
|
3648
3670
|
model: this.llmConfig.model
|
|
3649
3671
|
});
|
|
3650
|
-
|
|
3672
|
+
logger14.info("Creating CommandHandler");
|
|
3651
3673
|
this.commandHandler = new CommandHandler(this.bus, this.createRuntimeOperations());
|
|
3652
|
-
|
|
3674
|
+
logger14.info("RuntimeImpl constructor done");
|
|
3653
3675
|
}
|
|
3654
3676
|
// ==================== SystemBus delegation ====================
|
|
3655
3677
|
emit(event) {
|
|
@@ -3732,7 +3754,7 @@ var RuntimeImpl = class {
|
|
|
3732
3754
|
// Agent operations (by imageId - with auto-activation)
|
|
3733
3755
|
receiveMessage: async (imageId, agentId, content, requestId) => {
|
|
3734
3756
|
if (imageId) {
|
|
3735
|
-
|
|
3757
|
+
logger14.debug("Receiving message by imageId", {
|
|
3736
3758
|
imageId,
|
|
3737
3759
|
contentLength: content.length,
|
|
3738
3760
|
requestId
|
|
@@ -3741,7 +3763,7 @@ var RuntimeImpl = class {
|
|
|
3741
3763
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3742
3764
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3743
3765
|
const { agent, reused } = await container.runImage(record);
|
|
3744
|
-
|
|
3766
|
+
logger14.info("Message routed to agent", {
|
|
3745
3767
|
imageId,
|
|
3746
3768
|
agentId: agent.agentId,
|
|
3747
3769
|
reused,
|
|
@@ -3751,7 +3773,7 @@ var RuntimeImpl = class {
|
|
|
3751
3773
|
return { agentId: agent.agentId, imageId };
|
|
3752
3774
|
}
|
|
3753
3775
|
if (agentId) {
|
|
3754
|
-
|
|
3776
|
+
logger14.debug("Receiving message by agentId (legacy)", {
|
|
3755
3777
|
agentId,
|
|
3756
3778
|
contentLength: content.length,
|
|
3757
3779
|
requestId
|
|
@@ -3768,12 +3790,12 @@ var RuntimeImpl = class {
|
|
|
3768
3790
|
if (imageId) {
|
|
3769
3791
|
const foundAgentId = this.findAgentIdForImage(imageId);
|
|
3770
3792
|
if (!foundAgentId) {
|
|
3771
|
-
|
|
3793
|
+
logger14.debug("Image is offline, nothing to interrupt", { imageId });
|
|
3772
3794
|
return { imageId, agentId: void 0 };
|
|
3773
3795
|
}
|
|
3774
3796
|
const agent = this.findAgent(foundAgentId);
|
|
3775
3797
|
if (agent) {
|
|
3776
|
-
|
|
3798
|
+
logger14.info("Interrupting agent by imageId", {
|
|
3777
3799
|
imageId,
|
|
3778
3800
|
agentId: foundAgentId,
|
|
3779
3801
|
requestId
|
|
@@ -3785,7 +3807,7 @@ var RuntimeImpl = class {
|
|
|
3785
3807
|
if (agentId) {
|
|
3786
3808
|
const agent = this.findAgent(agentId);
|
|
3787
3809
|
if (!agent) throw new Error(`Agent not found: ${agentId}`);
|
|
3788
|
-
|
|
3810
|
+
logger14.info("Interrupting agent by agentId (legacy)", { agentId, requestId });
|
|
3789
3811
|
agent.interrupt(requestId);
|
|
3790
3812
|
const foundImageId = this.findImageIdForAgent(agentId);
|
|
3791
3813
|
return { agentId, imageId: foundImageId };
|
|
@@ -3794,32 +3816,32 @@ var RuntimeImpl = class {
|
|
|
3794
3816
|
},
|
|
3795
3817
|
// Image operations (new model)
|
|
3796
3818
|
createImage: async (containerId, config) => {
|
|
3797
|
-
|
|
3819
|
+
logger14.debug("Creating image", { containerId, name: config.name });
|
|
3798
3820
|
await this.getOrCreateContainer(containerId);
|
|
3799
3821
|
const image = await RuntimeImage.create(
|
|
3800
3822
|
{ containerId, ...config },
|
|
3801
3823
|
this.createImageContext()
|
|
3802
3824
|
);
|
|
3803
|
-
|
|
3825
|
+
logger14.info("Image created via RuntimeOps", { imageId: image.imageId, containerId });
|
|
3804
3826
|
return this.toImageListItemResult(image.toRecord(), false);
|
|
3805
3827
|
},
|
|
3806
3828
|
runImage: async (imageId) => {
|
|
3807
|
-
|
|
3829
|
+
logger14.debug("Running image", { imageId });
|
|
3808
3830
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3809
3831
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3810
3832
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3811
3833
|
const { agent, reused } = await container.runImage(record);
|
|
3812
|
-
|
|
3834
|
+
logger14.info("Image running", { imageId, agentId: agent.agentId, reused });
|
|
3813
3835
|
return { imageId, agentId: agent.agentId, reused };
|
|
3814
3836
|
},
|
|
3815
3837
|
stopImage: async (imageId) => {
|
|
3816
|
-
|
|
3838
|
+
logger14.debug("Stopping image", { imageId });
|
|
3817
3839
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3818
3840
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3819
3841
|
const container = this.containerRegistry.get(record.containerId);
|
|
3820
3842
|
if (container) {
|
|
3821
3843
|
await container.stopImage(imageId);
|
|
3822
|
-
|
|
3844
|
+
logger14.info("Image stopped via RuntimeOps", { imageId });
|
|
3823
3845
|
}
|
|
3824
3846
|
},
|
|
3825
3847
|
updateImage: async (imageId, updates) => {
|
|
@@ -3843,10 +3865,10 @@ var RuntimeImpl = class {
|
|
|
3843
3865
|
return this.toImageListItemResult(record, online);
|
|
3844
3866
|
},
|
|
3845
3867
|
deleteImage: async (imageId) => {
|
|
3846
|
-
|
|
3868
|
+
logger14.debug("Deleting image", { imageId });
|
|
3847
3869
|
const agentId = this.findAgentIdForImage(imageId);
|
|
3848
3870
|
if (agentId) {
|
|
3849
|
-
|
|
3871
|
+
logger14.debug("Stopping running agent before delete", { imageId, agentId });
|
|
3850
3872
|
for (const container of this.containerRegistry.values()) {
|
|
3851
3873
|
if (container.getAgent(agentId)) {
|
|
3852
3874
|
await container.destroyAgent(agentId);
|
|
@@ -3857,17 +3879,17 @@ var RuntimeImpl = class {
|
|
|
3857
3879
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3858
3880
|
if (image) {
|
|
3859
3881
|
await image.delete();
|
|
3860
|
-
|
|
3882
|
+
logger14.info("Image deleted via RuntimeOps", { imageId });
|
|
3861
3883
|
}
|
|
3862
3884
|
},
|
|
3863
3885
|
getImageMessages: async (imageId) => {
|
|
3864
|
-
|
|
3886
|
+
logger14.debug("Getting messages for image", { imageId });
|
|
3865
3887
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3866
3888
|
if (!image) {
|
|
3867
3889
|
throw new Error(`Image not found: ${imageId}`);
|
|
3868
3890
|
}
|
|
3869
3891
|
const messages = await image.getMessages();
|
|
3870
|
-
|
|
3892
|
+
logger14.debug("Got messages from storage", { imageId, count: messages.length });
|
|
3871
3893
|
return messages.map((m) => {
|
|
3872
3894
|
let content;
|
|
3873
3895
|
let role = m.role;
|
|
@@ -3984,14 +4006,14 @@ var RuntimeImpl = class {
|
|
|
3984
4006
|
}
|
|
3985
4007
|
// ==================== Lifecycle ====================
|
|
3986
4008
|
async dispose() {
|
|
3987
|
-
|
|
4009
|
+
logger14.info("Disposing RuntimeImpl");
|
|
3988
4010
|
this.commandHandler.dispose();
|
|
3989
4011
|
for (const container of this.containerRegistry.values()) {
|
|
3990
4012
|
await container.dispose();
|
|
3991
4013
|
}
|
|
3992
4014
|
this.bus.destroy();
|
|
3993
4015
|
this.containerRegistry.clear();
|
|
3994
|
-
|
|
4016
|
+
logger14.info("RuntimeImpl disposed");
|
|
3995
4017
|
}
|
|
3996
4018
|
};
|
|
3997
4019
|
|
|
@@ -4004,7 +4026,7 @@ function createRuntime(config) {
|
|
|
4004
4026
|
var import_unstorage = require("unstorage");
|
|
4005
4027
|
|
|
4006
4028
|
// src/internal/persistence/repository/StorageImageRepository.ts
|
|
4007
|
-
var
|
|
4029
|
+
var logger15 = createLogger("persistence/ImageRepository");
|
|
4008
4030
|
var PREFIX = "images";
|
|
4009
4031
|
var INDEX_BY_NAME = "idx:images:name";
|
|
4010
4032
|
var INDEX_BY_CONTAINER = "idx:images:container";
|
|
@@ -4028,7 +4050,7 @@ var StorageImageRepository = class {
|
|
|
4028
4050
|
this.containerIndexKey(record.containerId, record.imageId),
|
|
4029
4051
|
record.imageId
|
|
4030
4052
|
);
|
|
4031
|
-
|
|
4053
|
+
logger15.debug("Image saved", { imageId: record.imageId });
|
|
4032
4054
|
}
|
|
4033
4055
|
async findImageById(imageId) {
|
|
4034
4056
|
const record = await this.storage.getItem(this.key(imageId));
|
|
@@ -4083,7 +4105,7 @@ var StorageImageRepository = class {
|
|
|
4083
4105
|
await this.storage.removeItem(this.nameIndexKey(record.name, imageId));
|
|
4084
4106
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, imageId));
|
|
4085
4107
|
}
|
|
4086
|
-
|
|
4108
|
+
logger15.debug("Image deleted", { imageId });
|
|
4087
4109
|
}
|
|
4088
4110
|
async imageExists(imageId) {
|
|
4089
4111
|
return await this.storage.hasItem(this.key(imageId));
|
|
@@ -4102,12 +4124,12 @@ var StorageImageRepository = class {
|
|
|
4102
4124
|
updatedAt: Date.now()
|
|
4103
4125
|
};
|
|
4104
4126
|
await this.storage.setItem(this.key(imageId), updatedRecord);
|
|
4105
|
-
|
|
4127
|
+
logger15.debug("Image metadata updated", { imageId, metadata });
|
|
4106
4128
|
}
|
|
4107
4129
|
};
|
|
4108
4130
|
|
|
4109
4131
|
// src/internal/persistence/repository/StorageContainerRepository.ts
|
|
4110
|
-
var
|
|
4132
|
+
var logger16 = createLogger("persistence/ContainerRepository");
|
|
4111
4133
|
var PREFIX2 = "containers";
|
|
4112
4134
|
var StorageContainerRepository = class {
|
|
4113
4135
|
constructor(storage) {
|
|
@@ -4118,7 +4140,7 @@ var StorageContainerRepository = class {
|
|
|
4118
4140
|
}
|
|
4119
4141
|
async saveContainer(record) {
|
|
4120
4142
|
await this.storage.setItem(this.key(record.containerId), record);
|
|
4121
|
-
|
|
4143
|
+
logger16.debug("Container saved", { containerId: record.containerId });
|
|
4122
4144
|
}
|
|
4123
4145
|
async findContainerById(containerId) {
|
|
4124
4146
|
const record = await this.storage.getItem(this.key(containerId));
|
|
@@ -4137,7 +4159,7 @@ var StorageContainerRepository = class {
|
|
|
4137
4159
|
}
|
|
4138
4160
|
async deleteContainer(containerId) {
|
|
4139
4161
|
await this.storage.removeItem(this.key(containerId));
|
|
4140
|
-
|
|
4162
|
+
logger16.debug("Container deleted", { containerId });
|
|
4141
4163
|
}
|
|
4142
4164
|
async containerExists(containerId) {
|
|
4143
4165
|
return await this.storage.hasItem(this.key(containerId));
|
|
@@ -4145,7 +4167,7 @@ var StorageContainerRepository = class {
|
|
|
4145
4167
|
};
|
|
4146
4168
|
|
|
4147
4169
|
// src/internal/persistence/repository/StorageSessionRepository.ts
|
|
4148
|
-
var
|
|
4170
|
+
var logger17 = createLogger("persistence/SessionRepository");
|
|
4149
4171
|
var PREFIX3 = "sessions";
|
|
4150
4172
|
var MESSAGES_PREFIX = "messages";
|
|
4151
4173
|
var INDEX_BY_IMAGE = "idx:sessions:image";
|
|
@@ -4176,7 +4198,7 @@ var StorageSessionRepository = class {
|
|
|
4176
4198
|
this.containerIndexKey(record.containerId, record.sessionId),
|
|
4177
4199
|
record.sessionId
|
|
4178
4200
|
);
|
|
4179
|
-
|
|
4201
|
+
logger17.debug("Session saved", { sessionId: record.sessionId });
|
|
4180
4202
|
}
|
|
4181
4203
|
async findSessionById(sessionId) {
|
|
4182
4204
|
const record = await this.storage.getItem(this.key(sessionId));
|
|
@@ -4225,7 +4247,7 @@ var StorageSessionRepository = class {
|
|
|
4225
4247
|
await this.storage.removeItem(this.imageIndexKey(record.imageId, sessionId));
|
|
4226
4248
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, sessionId));
|
|
4227
4249
|
}
|
|
4228
|
-
|
|
4250
|
+
logger17.debug("Session deleted", { sessionId });
|
|
4229
4251
|
}
|
|
4230
4252
|
async sessionExists(sessionId) {
|
|
4231
4253
|
return await this.storage.hasItem(this.key(sessionId));
|
|
@@ -4235,13 +4257,13 @@ var StorageSessionRepository = class {
|
|
|
4235
4257
|
const messages = await this.getMessages(sessionId);
|
|
4236
4258
|
messages.push(message);
|
|
4237
4259
|
await this.storage.setItem(this.messagesKey(sessionId), messages);
|
|
4238
|
-
|
|
4260
|
+
logger17.debug("Message added to session", { sessionId, subtype: message.subtype });
|
|
4239
4261
|
}
|
|
4240
4262
|
async getMessages(sessionId) {
|
|
4241
4263
|
const messages = await this.storage.getItem(this.messagesKey(sessionId));
|
|
4242
4264
|
if (!messages || !Array.isArray(messages)) {
|
|
4243
4265
|
if (messages) {
|
|
4244
|
-
|
|
4266
|
+
logger17.warn("Messages data is not an array, resetting", {
|
|
4245
4267
|
sessionId,
|
|
4246
4268
|
type: typeof messages
|
|
4247
4269
|
});
|
|
@@ -4252,12 +4274,12 @@ var StorageSessionRepository = class {
|
|
|
4252
4274
|
}
|
|
4253
4275
|
async clearMessages(sessionId) {
|
|
4254
4276
|
await this.storage.removeItem(this.messagesKey(sessionId));
|
|
4255
|
-
|
|
4277
|
+
logger17.debug("Messages cleared for session", { sessionId });
|
|
4256
4278
|
}
|
|
4257
4279
|
};
|
|
4258
4280
|
|
|
4259
4281
|
// src/internal/persistence/PersistenceImpl.ts
|
|
4260
|
-
var
|
|
4282
|
+
var logger18 = createLogger("persistence/Persistence");
|
|
4261
4283
|
var PersistenceImpl = class _PersistenceImpl {
|
|
4262
4284
|
images;
|
|
4263
4285
|
containers;
|
|
@@ -4271,7 +4293,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4271
4293
|
this.images = new StorageImageRepository(this.storage);
|
|
4272
4294
|
this.containers = new StorageContainerRepository(this.storage);
|
|
4273
4295
|
this.sessions = new StorageSessionRepository(this.storage);
|
|
4274
|
-
|
|
4296
|
+
logger18.info("Persistence created", { driver: driverName });
|
|
4275
4297
|
}
|
|
4276
4298
|
/**
|
|
4277
4299
|
* Create a PersistenceImpl instance (async factory)
|
|
@@ -4292,7 +4314,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4292
4314
|
*/
|
|
4293
4315
|
async dispose() {
|
|
4294
4316
|
await this.storage.dispose();
|
|
4295
|
-
|
|
4317
|
+
logger18.info("Persistence disposed");
|
|
4296
4318
|
}
|
|
4297
4319
|
};
|
|
4298
4320
|
async function createStorageFromConfig(config) {
|