@agentxjs/runtime 0.1.5 → 0.1.6
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 +134 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +134 -114
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
}
|
|
@@ -2419,7 +2439,7 @@ var RuntimeAgent = class {
|
|
|
2419
2439
|
});
|
|
2420
2440
|
this.environment.receptor.connect(config.bus.asProducer());
|
|
2421
2441
|
this.environment.effector.connect(config.bus.asConsumer());
|
|
2422
|
-
|
|
2442
|
+
logger9.info("ClaudeEnvironment created for agent", {
|
|
2423
2443
|
agentId: this.agentId,
|
|
2424
2444
|
imageId: this.imageId,
|
|
2425
2445
|
resumeSessionId: resumeSessionId ?? "none",
|
|
@@ -2453,14 +2473,14 @@ var RuntimeAgent = class {
|
|
|
2453
2473
|
this.driver = new BusDriver(config.bus.asConsumer(), {
|
|
2454
2474
|
agentId: this.agentId,
|
|
2455
2475
|
onStreamEvent: (event) => {
|
|
2456
|
-
|
|
2476
|
+
logger9.debug("BusDriver \u2192 Engine.handleStreamEvent", { type: event.type });
|
|
2457
2477
|
this.engine.handleStreamEvent(event);
|
|
2458
2478
|
},
|
|
2459
2479
|
onStreamComplete: (reason) => {
|
|
2460
|
-
|
|
2480
|
+
logger9.debug("Stream completed", { reason, agentId: this.agentId });
|
|
2461
2481
|
}
|
|
2462
2482
|
});
|
|
2463
|
-
|
|
2483
|
+
logger9.debug("RuntimeAgent created", {
|
|
2464
2484
|
agentId: this.agentId,
|
|
2465
2485
|
imageId: this.imageId
|
|
2466
2486
|
});
|
|
@@ -2469,13 +2489,13 @@ var RuntimeAgent = class {
|
|
|
2469
2489
|
* Save SDK session ID to image metadata for future resume
|
|
2470
2490
|
*/
|
|
2471
2491
|
saveSessionId(sdkSessionId) {
|
|
2472
|
-
|
|
2492
|
+
logger9.info("Saving SDK session ID to image metadata", {
|
|
2473
2493
|
agentId: this.agentId,
|
|
2474
2494
|
imageId: this.imageId,
|
|
2475
2495
|
sdkSessionId
|
|
2476
2496
|
});
|
|
2477
2497
|
this.imageRepository.updateMetadata(this.imageId, { claudeSdkSessionId: sdkSessionId }).catch((err) => {
|
|
2478
|
-
|
|
2498
|
+
logger9.error("Failed to save SDK session ID", { error: err, imageId: this.imageId });
|
|
2479
2499
|
});
|
|
2480
2500
|
}
|
|
2481
2501
|
get lifecycle() {
|
|
@@ -2488,7 +2508,7 @@ var RuntimeAgent = class {
|
|
|
2488
2508
|
* @param requestId - Request ID for correlation
|
|
2489
2509
|
*/
|
|
2490
2510
|
async receive(content, requestId) {
|
|
2491
|
-
|
|
2511
|
+
logger9.debug("RuntimeAgent.receive called", {
|
|
2492
2512
|
agentId: this.agentId,
|
|
2493
2513
|
contentPreview: content.substring(0, 50),
|
|
2494
2514
|
requestId
|
|
@@ -2497,13 +2517,13 @@ var RuntimeAgent = class {
|
|
|
2497
2517
|
throw new Error(`Cannot send message to ${this._lifecycle} agent`);
|
|
2498
2518
|
}
|
|
2499
2519
|
await this.interactor.receive(content, requestId || `req_${Date.now()}`);
|
|
2500
|
-
|
|
2520
|
+
logger9.debug("RuntimeAgent.receive completed", { agentId: this.agentId });
|
|
2501
2521
|
}
|
|
2502
2522
|
/**
|
|
2503
2523
|
* Interrupt current operation
|
|
2504
2524
|
*/
|
|
2505
2525
|
interrupt(requestId) {
|
|
2506
|
-
|
|
2526
|
+
logger9.debug("RuntimeAgent.interrupt called", { agentId: this.agentId, requestId });
|
|
2507
2527
|
this.interactor.interrupt(requestId);
|
|
2508
2528
|
this.producer.emit({
|
|
2509
2529
|
type: "interrupted",
|
|
@@ -2698,7 +2718,7 @@ var RuntimeSandbox = class {
|
|
|
2698
2718
|
};
|
|
2699
2719
|
|
|
2700
2720
|
// src/internal/RuntimeImage.ts
|
|
2701
|
-
var
|
|
2721
|
+
var logger10 = createLogger("runtime/RuntimeImage");
|
|
2702
2722
|
var RuntimeImage = class _RuntimeImage {
|
|
2703
2723
|
constructor(record, context) {
|
|
2704
2724
|
this.record = record;
|
|
@@ -2755,7 +2775,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2755
2775
|
createdAt: now,
|
|
2756
2776
|
updatedAt: now
|
|
2757
2777
|
});
|
|
2758
|
-
|
|
2778
|
+
logger10.info("Image created", {
|
|
2759
2779
|
imageId,
|
|
2760
2780
|
sessionId,
|
|
2761
2781
|
containerId: config.containerId,
|
|
@@ -2769,10 +2789,10 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2769
2789
|
static async load(imageId, context) {
|
|
2770
2790
|
const record = await context.imageRepository.findImageById(imageId);
|
|
2771
2791
|
if (!record) {
|
|
2772
|
-
|
|
2792
|
+
logger10.debug("Image not found", { imageId });
|
|
2773
2793
|
return null;
|
|
2774
2794
|
}
|
|
2775
|
-
|
|
2795
|
+
logger10.debug("Image loaded", { imageId, name: record.name });
|
|
2776
2796
|
return new _RuntimeImage(record, context);
|
|
2777
2797
|
}
|
|
2778
2798
|
/**
|
|
@@ -2806,7 +2826,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2806
2826
|
updatedAt: now
|
|
2807
2827
|
};
|
|
2808
2828
|
await this.context.imageRepository.saveImage(updatedRecord);
|
|
2809
|
-
|
|
2829
|
+
logger10.info("Image updated", { imageId: this.imageId, updates });
|
|
2810
2830
|
return new _RuntimeImage(updatedRecord, this.context);
|
|
2811
2831
|
}
|
|
2812
2832
|
/**
|
|
@@ -2815,7 +2835,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2815
2835
|
async delete() {
|
|
2816
2836
|
await this.context.sessionRepository.deleteSession(this.sessionId);
|
|
2817
2837
|
await this.context.imageRepository.deleteImage(this.imageId);
|
|
2818
|
-
|
|
2838
|
+
logger10.info("Image deleted", { imageId: this.imageId, sessionId: this.sessionId });
|
|
2819
2839
|
}
|
|
2820
2840
|
/**
|
|
2821
2841
|
* Get the underlying record
|
|
@@ -2837,7 +2857,7 @@ var RuntimeImage = class _RuntimeImage {
|
|
|
2837
2857
|
};
|
|
2838
2858
|
|
|
2839
2859
|
// src/internal/RuntimeContainer.ts
|
|
2840
|
-
var
|
|
2860
|
+
var logger11 = createLogger("runtime/RuntimeContainer");
|
|
2841
2861
|
var RuntimeContainer = class _RuntimeContainer {
|
|
2842
2862
|
containerId;
|
|
2843
2863
|
createdAt;
|
|
@@ -2877,7 +2897,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2877
2897
|
containerId
|
|
2878
2898
|
}
|
|
2879
2899
|
});
|
|
2880
|
-
|
|
2900
|
+
logger11.info("Container created", { containerId });
|
|
2881
2901
|
return container;
|
|
2882
2902
|
}
|
|
2883
2903
|
/**
|
|
@@ -2886,7 +2906,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2886
2906
|
static async load(containerId, context) {
|
|
2887
2907
|
const record = await context.persistence.containers.findContainerById(containerId);
|
|
2888
2908
|
if (!record) return null;
|
|
2889
|
-
|
|
2909
|
+
logger11.info("Container loaded", { containerId });
|
|
2890
2910
|
return new _RuntimeContainer(containerId, record.createdAt, context);
|
|
2891
2911
|
}
|
|
2892
2912
|
// ==================== Image → Agent Lifecycle ====================
|
|
@@ -2899,7 +2919,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2899
2919
|
if (existingAgentId) {
|
|
2900
2920
|
const existingAgent = this.agents.get(existingAgentId);
|
|
2901
2921
|
if (existingAgent) {
|
|
2902
|
-
|
|
2922
|
+
logger11.info("Reusing existing agent for image", {
|
|
2903
2923
|
containerId: this.containerId,
|
|
2904
2924
|
imageId: image.imageId,
|
|
2905
2925
|
agentId: existingAgentId
|
|
@@ -2958,7 +2978,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2958
2978
|
agentId
|
|
2959
2979
|
}
|
|
2960
2980
|
});
|
|
2961
|
-
|
|
2981
|
+
logger11.info("Agent created for image", {
|
|
2962
2982
|
containerId: this.containerId,
|
|
2963
2983
|
imageId: image.imageId,
|
|
2964
2984
|
agentId
|
|
@@ -2971,17 +2991,17 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
2971
2991
|
async stopImage(imageId) {
|
|
2972
2992
|
const agentId = this.imageToAgent.get(imageId);
|
|
2973
2993
|
if (!agentId) {
|
|
2974
|
-
|
|
2994
|
+
logger11.debug("Image not running, nothing to stop", {
|
|
2975
2995
|
imageId,
|
|
2976
2996
|
containerId: this.containerId
|
|
2977
2997
|
});
|
|
2978
2998
|
return false;
|
|
2979
2999
|
}
|
|
2980
|
-
|
|
3000
|
+
logger11.info("Stopping image", { imageId, agentId, containerId: this.containerId });
|
|
2981
3001
|
const success = await this.destroyAgent(agentId);
|
|
2982
3002
|
if (success) {
|
|
2983
3003
|
this.imageToAgent.delete(imageId);
|
|
2984
|
-
|
|
3004
|
+
logger11.info("Image stopped", { imageId, agentId, containerId: this.containerId });
|
|
2985
3005
|
}
|
|
2986
3006
|
return success;
|
|
2987
3007
|
}
|
|
@@ -3038,7 +3058,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3038
3058
|
agentId
|
|
3039
3059
|
}
|
|
3040
3060
|
});
|
|
3041
|
-
|
|
3061
|
+
logger11.info("Agent destroyed", { containerId: this.containerId, agentId });
|
|
3042
3062
|
return true;
|
|
3043
3063
|
}
|
|
3044
3064
|
async destroyAllAgents() {
|
|
@@ -3066,7 +3086,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3066
3086
|
}
|
|
3067
3087
|
});
|
|
3068
3088
|
this.context.onDisposed?.(this.containerId);
|
|
3069
|
-
|
|
3089
|
+
logger11.info("Container disposed", { containerId: this.containerId, agentCount });
|
|
3070
3090
|
}
|
|
3071
3091
|
// ==================== Private Helpers ====================
|
|
3072
3092
|
generateAgentId() {
|
|
@@ -3077,7 +3097,7 @@ var RuntimeContainer = class _RuntimeContainer {
|
|
|
3077
3097
|
};
|
|
3078
3098
|
|
|
3079
3099
|
// src/internal/BaseEventHandler.ts
|
|
3080
|
-
var
|
|
3100
|
+
var logger12 = createLogger("runtime/BaseEventHandler");
|
|
3081
3101
|
var BaseEventHandler = class {
|
|
3082
3102
|
bus;
|
|
3083
3103
|
unsubscribes = [];
|
|
@@ -3116,7 +3136,7 @@ var BaseEventHandler = class {
|
|
|
3116
3136
|
handleError(err, context) {
|
|
3117
3137
|
const message = err instanceof Error ? err.message : String(err);
|
|
3118
3138
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3119
|
-
|
|
3139
|
+
logger12.error(`Error in ${context.operation || "handler"}`, {
|
|
3120
3140
|
message,
|
|
3121
3141
|
requestId: context.requestId,
|
|
3122
3142
|
details: context.details
|
|
@@ -3143,7 +3163,7 @@ var BaseEventHandler = class {
|
|
|
3143
3163
|
try {
|
|
3144
3164
|
context.onError(err);
|
|
3145
3165
|
} catch (callbackErr) {
|
|
3146
|
-
|
|
3166
|
+
logger12.error("Error in onError callback", { error: callbackErr });
|
|
3147
3167
|
}
|
|
3148
3168
|
}
|
|
3149
3169
|
}
|
|
@@ -3161,12 +3181,12 @@ var BaseEventHandler = class {
|
|
|
3161
3181
|
unsubscribe();
|
|
3162
3182
|
}
|
|
3163
3183
|
this.unsubscribes = [];
|
|
3164
|
-
|
|
3184
|
+
logger12.debug(`${this.constructor.name} disposed`);
|
|
3165
3185
|
}
|
|
3166
3186
|
};
|
|
3167
3187
|
|
|
3168
3188
|
// src/internal/CommandHandler.ts
|
|
3169
|
-
var
|
|
3189
|
+
var logger13 = createLogger("runtime/CommandHandler");
|
|
3170
3190
|
function createResponse(type, data) {
|
|
3171
3191
|
return {
|
|
3172
3192
|
type,
|
|
@@ -3199,7 +3219,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3199
3219
|
super(bus);
|
|
3200
3220
|
this.ops = operations;
|
|
3201
3221
|
this.bindHandlers();
|
|
3202
|
-
|
|
3222
|
+
logger13.debug("CommandHandler created");
|
|
3203
3223
|
}
|
|
3204
3224
|
/**
|
|
3205
3225
|
* Log error and emit system_error event
|
|
@@ -3207,7 +3227,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3207
3227
|
emitError(operation, err, requestId, context) {
|
|
3208
3228
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
3209
3229
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
3210
|
-
|
|
3230
|
+
logger13.error(operation, {
|
|
3211
3231
|
requestId,
|
|
3212
3232
|
...context,
|
|
3213
3233
|
error: errorMessage,
|
|
@@ -3264,12 +3284,12 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3264
3284
|
this.subscribe(
|
|
3265
3285
|
this.bus.onCommand("image_messages_request", (event) => this.handleImageMessages(event))
|
|
3266
3286
|
);
|
|
3267
|
-
|
|
3287
|
+
logger13.debug("Command handlers bound");
|
|
3268
3288
|
}
|
|
3269
3289
|
// ==================== Container Handlers ====================
|
|
3270
3290
|
async handleContainerCreate(event) {
|
|
3271
3291
|
const { requestId, containerId } = event.data;
|
|
3272
|
-
|
|
3292
|
+
logger13.debug("Handling container_create_request", { requestId, containerId });
|
|
3273
3293
|
try {
|
|
3274
3294
|
await this.ops.createContainer(containerId);
|
|
3275
3295
|
this.bus.emit(
|
|
@@ -3291,7 +3311,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3291
3311
|
}
|
|
3292
3312
|
handleContainerGet(event) {
|
|
3293
3313
|
const { requestId, containerId } = event.data;
|
|
3294
|
-
|
|
3314
|
+
logger13.debug("Handling container_get_request", { requestId, containerId });
|
|
3295
3315
|
const container = this.ops.getContainer(containerId);
|
|
3296
3316
|
this.bus.emit(
|
|
3297
3317
|
createResponse("container_get_response", {
|
|
@@ -3303,7 +3323,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3303
3323
|
}
|
|
3304
3324
|
handleContainerList(event) {
|
|
3305
3325
|
const { requestId } = event.data;
|
|
3306
|
-
|
|
3326
|
+
logger13.debug("Handling container_list_request", { requestId });
|
|
3307
3327
|
const containers = this.ops.listContainers();
|
|
3308
3328
|
this.bus.emit(
|
|
3309
3329
|
createResponse("container_list_response", {
|
|
@@ -3315,7 +3335,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3315
3335
|
// ==================== Agent Handlers ====================
|
|
3316
3336
|
handleAgentGet(event) {
|
|
3317
3337
|
const { requestId, agentId } = event.data;
|
|
3318
|
-
|
|
3338
|
+
logger13.debug("Handling agent_get_request", { requestId, agentId });
|
|
3319
3339
|
const agent = this.ops.getAgent(agentId);
|
|
3320
3340
|
this.bus.emit(
|
|
3321
3341
|
createResponse("agent_get_response", {
|
|
@@ -3328,7 +3348,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3328
3348
|
}
|
|
3329
3349
|
handleAgentList(event) {
|
|
3330
3350
|
const { requestId, containerId } = event.data;
|
|
3331
|
-
|
|
3351
|
+
logger13.debug("Handling agent_list_request", { requestId, containerId });
|
|
3332
3352
|
const agents = this.ops.listAgents(containerId);
|
|
3333
3353
|
this.bus.emit(
|
|
3334
3354
|
createResponse("agent_list_response", {
|
|
@@ -3343,7 +3363,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3343
3363
|
}
|
|
3344
3364
|
async handleAgentDestroy(event) {
|
|
3345
3365
|
const { requestId, agentId } = event.data;
|
|
3346
|
-
|
|
3366
|
+
logger13.debug("Handling agent_destroy_request", { requestId, agentId });
|
|
3347
3367
|
try {
|
|
3348
3368
|
const success = await this.ops.destroyAgent(agentId);
|
|
3349
3369
|
this.bus.emit(
|
|
@@ -3367,7 +3387,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3367
3387
|
}
|
|
3368
3388
|
async handleAgentDestroyAll(event) {
|
|
3369
3389
|
const { requestId, containerId } = event.data;
|
|
3370
|
-
|
|
3390
|
+
logger13.debug("Handling agent_destroy_all_request", { requestId, containerId });
|
|
3371
3391
|
try {
|
|
3372
3392
|
await this.ops.destroyAllAgents(containerId);
|
|
3373
3393
|
this.bus.emit(
|
|
@@ -3389,7 +3409,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3389
3409
|
}
|
|
3390
3410
|
async handleMessageSend(event) {
|
|
3391
3411
|
const { requestId, imageId, agentId, content } = event.data;
|
|
3392
|
-
|
|
3412
|
+
logger13.debug("Handling message_send_request", { requestId, imageId, agentId });
|
|
3393
3413
|
try {
|
|
3394
3414
|
const result = await this.ops.receiveMessage(imageId, agentId, content, requestId);
|
|
3395
3415
|
this.bus.emit(
|
|
@@ -3413,7 +3433,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3413
3433
|
}
|
|
3414
3434
|
handleAgentInterrupt(event) {
|
|
3415
3435
|
const { requestId, imageId, agentId } = event.data;
|
|
3416
|
-
|
|
3436
|
+
logger13.debug("Handling agent_interrupt_request", { requestId, imageId, agentId });
|
|
3417
3437
|
try {
|
|
3418
3438
|
const result = this.ops.interruptAgent(imageId, agentId, requestId);
|
|
3419
3439
|
this.bus.emit(
|
|
@@ -3438,7 +3458,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3438
3458
|
// ==================== Image Handlers ====================
|
|
3439
3459
|
async handleImageCreate(event) {
|
|
3440
3460
|
const { requestId, containerId, config } = event.data;
|
|
3441
|
-
|
|
3461
|
+
logger13.debug("Handling image_create_request", { requestId, containerId });
|
|
3442
3462
|
try {
|
|
3443
3463
|
const record = await this.ops.createImage(containerId, config);
|
|
3444
3464
|
this.bus.emit(
|
|
@@ -3460,7 +3480,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3460
3480
|
}
|
|
3461
3481
|
async handleImageRun(event) {
|
|
3462
3482
|
const { requestId, imageId } = event.data;
|
|
3463
|
-
|
|
3483
|
+
logger13.debug("Handling image_run_request", { requestId, imageId });
|
|
3464
3484
|
try {
|
|
3465
3485
|
const result = await this.ops.runImage(imageId);
|
|
3466
3486
|
this.bus.emit(
|
|
@@ -3486,7 +3506,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3486
3506
|
}
|
|
3487
3507
|
async handleImageStop(event) {
|
|
3488
3508
|
const { requestId, imageId } = event.data;
|
|
3489
|
-
|
|
3509
|
+
logger13.debug("Handling image_stop_request", { requestId, imageId });
|
|
3490
3510
|
try {
|
|
3491
3511
|
await this.ops.stopImage(imageId);
|
|
3492
3512
|
this.bus.emit(
|
|
@@ -3508,7 +3528,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3508
3528
|
}
|
|
3509
3529
|
async handleImageUpdate(event) {
|
|
3510
3530
|
const { requestId, imageId, updates } = event.data;
|
|
3511
|
-
|
|
3531
|
+
logger13.debug("Handling image_update_request", { requestId, imageId });
|
|
3512
3532
|
try {
|
|
3513
3533
|
const record = await this.ops.updateImage(imageId, updates);
|
|
3514
3534
|
this.bus.emit(
|
|
@@ -3530,7 +3550,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3530
3550
|
}
|
|
3531
3551
|
async handleImageList(event) {
|
|
3532
3552
|
const { requestId, containerId } = event.data;
|
|
3533
|
-
|
|
3553
|
+
logger13.debug("Handling image_list_request", { requestId, containerId });
|
|
3534
3554
|
try {
|
|
3535
3555
|
const images = await this.ops.listImages(containerId);
|
|
3536
3556
|
this.bus.emit(
|
|
@@ -3552,7 +3572,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3552
3572
|
}
|
|
3553
3573
|
async handleImageGet(event) {
|
|
3554
3574
|
const { requestId, imageId } = event.data;
|
|
3555
|
-
|
|
3575
|
+
logger13.debug("Handling image_get_request", { requestId, imageId });
|
|
3556
3576
|
try {
|
|
3557
3577
|
const image = await this.ops.getImage(imageId);
|
|
3558
3578
|
this.bus.emit(
|
|
@@ -3573,7 +3593,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3573
3593
|
}
|
|
3574
3594
|
async handleImageDelete(event) {
|
|
3575
3595
|
const { requestId, imageId } = event.data;
|
|
3576
|
-
|
|
3596
|
+
logger13.debug("Handling image_delete_request", { requestId, imageId });
|
|
3577
3597
|
try {
|
|
3578
3598
|
await this.ops.deleteImage(imageId);
|
|
3579
3599
|
this.bus.emit(
|
|
@@ -3595,10 +3615,10 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3595
3615
|
}
|
|
3596
3616
|
async handleImageMessages(event) {
|
|
3597
3617
|
const { requestId, imageId } = event.data;
|
|
3598
|
-
|
|
3618
|
+
logger13.info("Handling image_messages_request", { requestId, imageId });
|
|
3599
3619
|
try {
|
|
3600
3620
|
const messages = await this.ops.getImageMessages(imageId);
|
|
3601
|
-
|
|
3621
|
+
logger13.info("Got messages for image", { imageId, count: messages.length });
|
|
3602
3622
|
this.bus.emit(
|
|
3603
3623
|
createResponse("image_messages_response", {
|
|
3604
3624
|
requestId,
|
|
@@ -3606,7 +3626,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3606
3626
|
messages
|
|
3607
3627
|
})
|
|
3608
3628
|
);
|
|
3609
|
-
|
|
3629
|
+
logger13.info("Emitted image_messages_response", { requestId, imageId });
|
|
3610
3630
|
} catch (err) {
|
|
3611
3631
|
this.emitError("Failed to get image messages", err, requestId, { imageId });
|
|
3612
3632
|
this.bus.emit(
|
|
@@ -3625,7 +3645,7 @@ var CommandHandler = class extends BaseEventHandler {
|
|
|
3625
3645
|
// src/RuntimeImpl.ts
|
|
3626
3646
|
var import_node_os = require("os");
|
|
3627
3647
|
var import_node_path2 = require("path");
|
|
3628
|
-
var
|
|
3648
|
+
var logger14 = createLogger("runtime/RuntimeImpl");
|
|
3629
3649
|
var RuntimeImpl = class {
|
|
3630
3650
|
persistence;
|
|
3631
3651
|
llmProvider;
|
|
@@ -3636,20 +3656,20 @@ var RuntimeImpl = class {
|
|
|
3636
3656
|
/** Container registry: containerId -> RuntimeContainer */
|
|
3637
3657
|
containerRegistry = /* @__PURE__ */ new Map();
|
|
3638
3658
|
constructor(config) {
|
|
3639
|
-
|
|
3659
|
+
logger14.info("RuntimeImpl constructor start");
|
|
3640
3660
|
this.persistence = config.persistence;
|
|
3641
3661
|
this.llmProvider = config.llmProvider;
|
|
3642
3662
|
this.basePath = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".agentx");
|
|
3643
|
-
|
|
3663
|
+
logger14.info("Creating SystemBus");
|
|
3644
3664
|
this.bus = new SystemBusImpl();
|
|
3645
3665
|
this.llmConfig = this.llmProvider.provide();
|
|
3646
|
-
|
|
3666
|
+
logger14.info("LLM config loaded", {
|
|
3647
3667
|
hasApiKey: !!this.llmConfig.apiKey,
|
|
3648
3668
|
model: this.llmConfig.model
|
|
3649
3669
|
});
|
|
3650
|
-
|
|
3670
|
+
logger14.info("Creating CommandHandler");
|
|
3651
3671
|
this.commandHandler = new CommandHandler(this.bus, this.createRuntimeOperations());
|
|
3652
|
-
|
|
3672
|
+
logger14.info("RuntimeImpl constructor done");
|
|
3653
3673
|
}
|
|
3654
3674
|
// ==================== SystemBus delegation ====================
|
|
3655
3675
|
emit(event) {
|
|
@@ -3732,7 +3752,7 @@ var RuntimeImpl = class {
|
|
|
3732
3752
|
// Agent operations (by imageId - with auto-activation)
|
|
3733
3753
|
receiveMessage: async (imageId, agentId, content, requestId) => {
|
|
3734
3754
|
if (imageId) {
|
|
3735
|
-
|
|
3755
|
+
logger14.debug("Receiving message by imageId", {
|
|
3736
3756
|
imageId,
|
|
3737
3757
|
contentLength: content.length,
|
|
3738
3758
|
requestId
|
|
@@ -3741,7 +3761,7 @@ var RuntimeImpl = class {
|
|
|
3741
3761
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3742
3762
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3743
3763
|
const { agent, reused } = await container.runImage(record);
|
|
3744
|
-
|
|
3764
|
+
logger14.info("Message routed to agent", {
|
|
3745
3765
|
imageId,
|
|
3746
3766
|
agentId: agent.agentId,
|
|
3747
3767
|
reused,
|
|
@@ -3751,7 +3771,7 @@ var RuntimeImpl = class {
|
|
|
3751
3771
|
return { agentId: agent.agentId, imageId };
|
|
3752
3772
|
}
|
|
3753
3773
|
if (agentId) {
|
|
3754
|
-
|
|
3774
|
+
logger14.debug("Receiving message by agentId (legacy)", {
|
|
3755
3775
|
agentId,
|
|
3756
3776
|
contentLength: content.length,
|
|
3757
3777
|
requestId
|
|
@@ -3768,12 +3788,12 @@ var RuntimeImpl = class {
|
|
|
3768
3788
|
if (imageId) {
|
|
3769
3789
|
const foundAgentId = this.findAgentIdForImage(imageId);
|
|
3770
3790
|
if (!foundAgentId) {
|
|
3771
|
-
|
|
3791
|
+
logger14.debug("Image is offline, nothing to interrupt", { imageId });
|
|
3772
3792
|
return { imageId, agentId: void 0 };
|
|
3773
3793
|
}
|
|
3774
3794
|
const agent = this.findAgent(foundAgentId);
|
|
3775
3795
|
if (agent) {
|
|
3776
|
-
|
|
3796
|
+
logger14.info("Interrupting agent by imageId", {
|
|
3777
3797
|
imageId,
|
|
3778
3798
|
agentId: foundAgentId,
|
|
3779
3799
|
requestId
|
|
@@ -3785,7 +3805,7 @@ var RuntimeImpl = class {
|
|
|
3785
3805
|
if (agentId) {
|
|
3786
3806
|
const agent = this.findAgent(agentId);
|
|
3787
3807
|
if (!agent) throw new Error(`Agent not found: ${agentId}`);
|
|
3788
|
-
|
|
3808
|
+
logger14.info("Interrupting agent by agentId (legacy)", { agentId, requestId });
|
|
3789
3809
|
agent.interrupt(requestId);
|
|
3790
3810
|
const foundImageId = this.findImageIdForAgent(agentId);
|
|
3791
3811
|
return { agentId, imageId: foundImageId };
|
|
@@ -3794,32 +3814,32 @@ var RuntimeImpl = class {
|
|
|
3794
3814
|
},
|
|
3795
3815
|
// Image operations (new model)
|
|
3796
3816
|
createImage: async (containerId, config) => {
|
|
3797
|
-
|
|
3817
|
+
logger14.debug("Creating image", { containerId, name: config.name });
|
|
3798
3818
|
await this.getOrCreateContainer(containerId);
|
|
3799
3819
|
const image = await RuntimeImage.create(
|
|
3800
3820
|
{ containerId, ...config },
|
|
3801
3821
|
this.createImageContext()
|
|
3802
3822
|
);
|
|
3803
|
-
|
|
3823
|
+
logger14.info("Image created via RuntimeOps", { imageId: image.imageId, containerId });
|
|
3804
3824
|
return this.toImageListItemResult(image.toRecord(), false);
|
|
3805
3825
|
},
|
|
3806
3826
|
runImage: async (imageId) => {
|
|
3807
|
-
|
|
3827
|
+
logger14.debug("Running image", { imageId });
|
|
3808
3828
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3809
3829
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3810
3830
|
const container = await this.getOrCreateContainer(record.containerId);
|
|
3811
3831
|
const { agent, reused } = await container.runImage(record);
|
|
3812
|
-
|
|
3832
|
+
logger14.info("Image running", { imageId, agentId: agent.agentId, reused });
|
|
3813
3833
|
return { imageId, agentId: agent.agentId, reused };
|
|
3814
3834
|
},
|
|
3815
3835
|
stopImage: async (imageId) => {
|
|
3816
|
-
|
|
3836
|
+
logger14.debug("Stopping image", { imageId });
|
|
3817
3837
|
const record = await this.persistence.images.findImageById(imageId);
|
|
3818
3838
|
if (!record) throw new Error(`Image not found: ${imageId}`);
|
|
3819
3839
|
const container = this.containerRegistry.get(record.containerId);
|
|
3820
3840
|
if (container) {
|
|
3821
3841
|
await container.stopImage(imageId);
|
|
3822
|
-
|
|
3842
|
+
logger14.info("Image stopped via RuntimeOps", { imageId });
|
|
3823
3843
|
}
|
|
3824
3844
|
},
|
|
3825
3845
|
updateImage: async (imageId, updates) => {
|
|
@@ -3843,10 +3863,10 @@ var RuntimeImpl = class {
|
|
|
3843
3863
|
return this.toImageListItemResult(record, online);
|
|
3844
3864
|
},
|
|
3845
3865
|
deleteImage: async (imageId) => {
|
|
3846
|
-
|
|
3866
|
+
logger14.debug("Deleting image", { imageId });
|
|
3847
3867
|
const agentId = this.findAgentIdForImage(imageId);
|
|
3848
3868
|
if (agentId) {
|
|
3849
|
-
|
|
3869
|
+
logger14.debug("Stopping running agent before delete", { imageId, agentId });
|
|
3850
3870
|
for (const container of this.containerRegistry.values()) {
|
|
3851
3871
|
if (container.getAgent(agentId)) {
|
|
3852
3872
|
await container.destroyAgent(agentId);
|
|
@@ -3857,17 +3877,17 @@ var RuntimeImpl = class {
|
|
|
3857
3877
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3858
3878
|
if (image) {
|
|
3859
3879
|
await image.delete();
|
|
3860
|
-
|
|
3880
|
+
logger14.info("Image deleted via RuntimeOps", { imageId });
|
|
3861
3881
|
}
|
|
3862
3882
|
},
|
|
3863
3883
|
getImageMessages: async (imageId) => {
|
|
3864
|
-
|
|
3884
|
+
logger14.debug("Getting messages for image", { imageId });
|
|
3865
3885
|
const image = await RuntimeImage.load(imageId, this.createImageContext());
|
|
3866
3886
|
if (!image) {
|
|
3867
3887
|
throw new Error(`Image not found: ${imageId}`);
|
|
3868
3888
|
}
|
|
3869
3889
|
const messages = await image.getMessages();
|
|
3870
|
-
|
|
3890
|
+
logger14.debug("Got messages from storage", { imageId, count: messages.length });
|
|
3871
3891
|
return messages.map((m) => {
|
|
3872
3892
|
let content;
|
|
3873
3893
|
let role = m.role;
|
|
@@ -3984,14 +4004,14 @@ var RuntimeImpl = class {
|
|
|
3984
4004
|
}
|
|
3985
4005
|
// ==================== Lifecycle ====================
|
|
3986
4006
|
async dispose() {
|
|
3987
|
-
|
|
4007
|
+
logger14.info("Disposing RuntimeImpl");
|
|
3988
4008
|
this.commandHandler.dispose();
|
|
3989
4009
|
for (const container of this.containerRegistry.values()) {
|
|
3990
4010
|
await container.dispose();
|
|
3991
4011
|
}
|
|
3992
4012
|
this.bus.destroy();
|
|
3993
4013
|
this.containerRegistry.clear();
|
|
3994
|
-
|
|
4014
|
+
logger14.info("RuntimeImpl disposed");
|
|
3995
4015
|
}
|
|
3996
4016
|
};
|
|
3997
4017
|
|
|
@@ -4004,7 +4024,7 @@ function createRuntime(config) {
|
|
|
4004
4024
|
var import_unstorage = require("unstorage");
|
|
4005
4025
|
|
|
4006
4026
|
// src/internal/persistence/repository/StorageImageRepository.ts
|
|
4007
|
-
var
|
|
4027
|
+
var logger15 = createLogger("persistence/ImageRepository");
|
|
4008
4028
|
var PREFIX = "images";
|
|
4009
4029
|
var INDEX_BY_NAME = "idx:images:name";
|
|
4010
4030
|
var INDEX_BY_CONTAINER = "idx:images:container";
|
|
@@ -4028,7 +4048,7 @@ var StorageImageRepository = class {
|
|
|
4028
4048
|
this.containerIndexKey(record.containerId, record.imageId),
|
|
4029
4049
|
record.imageId
|
|
4030
4050
|
);
|
|
4031
|
-
|
|
4051
|
+
logger15.debug("Image saved", { imageId: record.imageId });
|
|
4032
4052
|
}
|
|
4033
4053
|
async findImageById(imageId) {
|
|
4034
4054
|
const record = await this.storage.getItem(this.key(imageId));
|
|
@@ -4083,7 +4103,7 @@ var StorageImageRepository = class {
|
|
|
4083
4103
|
await this.storage.removeItem(this.nameIndexKey(record.name, imageId));
|
|
4084
4104
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, imageId));
|
|
4085
4105
|
}
|
|
4086
|
-
|
|
4106
|
+
logger15.debug("Image deleted", { imageId });
|
|
4087
4107
|
}
|
|
4088
4108
|
async imageExists(imageId) {
|
|
4089
4109
|
return await this.storage.hasItem(this.key(imageId));
|
|
@@ -4102,12 +4122,12 @@ var StorageImageRepository = class {
|
|
|
4102
4122
|
updatedAt: Date.now()
|
|
4103
4123
|
};
|
|
4104
4124
|
await this.storage.setItem(this.key(imageId), updatedRecord);
|
|
4105
|
-
|
|
4125
|
+
logger15.debug("Image metadata updated", { imageId, metadata });
|
|
4106
4126
|
}
|
|
4107
4127
|
};
|
|
4108
4128
|
|
|
4109
4129
|
// src/internal/persistence/repository/StorageContainerRepository.ts
|
|
4110
|
-
var
|
|
4130
|
+
var logger16 = createLogger("persistence/ContainerRepository");
|
|
4111
4131
|
var PREFIX2 = "containers";
|
|
4112
4132
|
var StorageContainerRepository = class {
|
|
4113
4133
|
constructor(storage) {
|
|
@@ -4118,7 +4138,7 @@ var StorageContainerRepository = class {
|
|
|
4118
4138
|
}
|
|
4119
4139
|
async saveContainer(record) {
|
|
4120
4140
|
await this.storage.setItem(this.key(record.containerId), record);
|
|
4121
|
-
|
|
4141
|
+
logger16.debug("Container saved", { containerId: record.containerId });
|
|
4122
4142
|
}
|
|
4123
4143
|
async findContainerById(containerId) {
|
|
4124
4144
|
const record = await this.storage.getItem(this.key(containerId));
|
|
@@ -4137,7 +4157,7 @@ var StorageContainerRepository = class {
|
|
|
4137
4157
|
}
|
|
4138
4158
|
async deleteContainer(containerId) {
|
|
4139
4159
|
await this.storage.removeItem(this.key(containerId));
|
|
4140
|
-
|
|
4160
|
+
logger16.debug("Container deleted", { containerId });
|
|
4141
4161
|
}
|
|
4142
4162
|
async containerExists(containerId) {
|
|
4143
4163
|
return await this.storage.hasItem(this.key(containerId));
|
|
@@ -4145,7 +4165,7 @@ var StorageContainerRepository = class {
|
|
|
4145
4165
|
};
|
|
4146
4166
|
|
|
4147
4167
|
// src/internal/persistence/repository/StorageSessionRepository.ts
|
|
4148
|
-
var
|
|
4168
|
+
var logger17 = createLogger("persistence/SessionRepository");
|
|
4149
4169
|
var PREFIX3 = "sessions";
|
|
4150
4170
|
var MESSAGES_PREFIX = "messages";
|
|
4151
4171
|
var INDEX_BY_IMAGE = "idx:sessions:image";
|
|
@@ -4176,7 +4196,7 @@ var StorageSessionRepository = class {
|
|
|
4176
4196
|
this.containerIndexKey(record.containerId, record.sessionId),
|
|
4177
4197
|
record.sessionId
|
|
4178
4198
|
);
|
|
4179
|
-
|
|
4199
|
+
logger17.debug("Session saved", { sessionId: record.sessionId });
|
|
4180
4200
|
}
|
|
4181
4201
|
async findSessionById(sessionId) {
|
|
4182
4202
|
const record = await this.storage.getItem(this.key(sessionId));
|
|
@@ -4225,7 +4245,7 @@ var StorageSessionRepository = class {
|
|
|
4225
4245
|
await this.storage.removeItem(this.imageIndexKey(record.imageId, sessionId));
|
|
4226
4246
|
await this.storage.removeItem(this.containerIndexKey(record.containerId, sessionId));
|
|
4227
4247
|
}
|
|
4228
|
-
|
|
4248
|
+
logger17.debug("Session deleted", { sessionId });
|
|
4229
4249
|
}
|
|
4230
4250
|
async sessionExists(sessionId) {
|
|
4231
4251
|
return await this.storage.hasItem(this.key(sessionId));
|
|
@@ -4235,13 +4255,13 @@ var StorageSessionRepository = class {
|
|
|
4235
4255
|
const messages = await this.getMessages(sessionId);
|
|
4236
4256
|
messages.push(message);
|
|
4237
4257
|
await this.storage.setItem(this.messagesKey(sessionId), messages);
|
|
4238
|
-
|
|
4258
|
+
logger17.debug("Message added to session", { sessionId, subtype: message.subtype });
|
|
4239
4259
|
}
|
|
4240
4260
|
async getMessages(sessionId) {
|
|
4241
4261
|
const messages = await this.storage.getItem(this.messagesKey(sessionId));
|
|
4242
4262
|
if (!messages || !Array.isArray(messages)) {
|
|
4243
4263
|
if (messages) {
|
|
4244
|
-
|
|
4264
|
+
logger17.warn("Messages data is not an array, resetting", {
|
|
4245
4265
|
sessionId,
|
|
4246
4266
|
type: typeof messages
|
|
4247
4267
|
});
|
|
@@ -4252,12 +4272,12 @@ var StorageSessionRepository = class {
|
|
|
4252
4272
|
}
|
|
4253
4273
|
async clearMessages(sessionId) {
|
|
4254
4274
|
await this.storage.removeItem(this.messagesKey(sessionId));
|
|
4255
|
-
|
|
4275
|
+
logger17.debug("Messages cleared for session", { sessionId });
|
|
4256
4276
|
}
|
|
4257
4277
|
};
|
|
4258
4278
|
|
|
4259
4279
|
// src/internal/persistence/PersistenceImpl.ts
|
|
4260
|
-
var
|
|
4280
|
+
var logger18 = createLogger("persistence/Persistence");
|
|
4261
4281
|
var PersistenceImpl = class _PersistenceImpl {
|
|
4262
4282
|
images;
|
|
4263
4283
|
containers;
|
|
@@ -4271,7 +4291,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4271
4291
|
this.images = new StorageImageRepository(this.storage);
|
|
4272
4292
|
this.containers = new StorageContainerRepository(this.storage);
|
|
4273
4293
|
this.sessions = new StorageSessionRepository(this.storage);
|
|
4274
|
-
|
|
4294
|
+
logger18.info("Persistence created", { driver: driverName });
|
|
4275
4295
|
}
|
|
4276
4296
|
/**
|
|
4277
4297
|
* Create a PersistenceImpl instance (async factory)
|
|
@@ -4292,7 +4312,7 @@ var PersistenceImpl = class _PersistenceImpl {
|
|
|
4292
4312
|
*/
|
|
4293
4313
|
async dispose() {
|
|
4294
4314
|
await this.storage.dispose();
|
|
4295
|
-
|
|
4315
|
+
logger18.info("Persistence disposed");
|
|
4296
4316
|
}
|
|
4297
4317
|
};
|
|
4298
4318
|
async function createStorageFromConfig(config) {
|