@aiden-ade/sandbox-agent 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/cli-executable.test.d.ts +2 -0
- package/dist/__tests__/cli-executable.test.d.ts.map +1 -0
- package/dist/__tests__/cli-executable.test.js +83 -0
- package/dist/__tests__/cli-executable.test.js.map +1 -0
- package/dist/__tests__/cli-help.test.d.ts +2 -0
- package/dist/__tests__/cli-help.test.d.ts.map +1 -0
- package/dist/__tests__/cli-help.test.js +33 -0
- package/dist/__tests__/cli-help.test.js.map +1 -0
- package/dist/__tests__/core-agent-workflow-context.test.d.ts +2 -0
- package/dist/__tests__/core-agent-workflow-context.test.d.ts.map +1 -0
- package/dist/__tests__/core-agent-workflow-context.test.js +50 -0
- package/dist/__tests__/core-agent-workflow-context.test.js.map +1 -0
- package/dist/__tests__/daemon-socket.integration.test.d.ts +2 -0
- package/dist/__tests__/daemon-socket.integration.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-socket.integration.test.js +156 -0
- package/dist/__tests__/daemon-socket.integration.test.js.map +1 -0
- package/dist/__tests__/daemon.test.d.ts +2 -0
- package/dist/__tests__/daemon.test.d.ts.map +1 -0
- package/dist/__tests__/daemon.test.js +1014 -0
- package/dist/__tests__/daemon.test.js.map +1 -0
- package/dist/__tests__/generated-images.test.d.ts +2 -0
- package/dist/__tests__/generated-images.test.d.ts.map +1 -0
- package/dist/__tests__/generated-images.test.js +50 -0
- package/dist/__tests__/generated-images.test.js.map +1 -0
- package/dist/__tests__/sandbox-workflow-context.test.d.ts +2 -0
- package/dist/__tests__/sandbox-workflow-context.test.d.ts.map +1 -0
- package/dist/__tests__/sandbox-workflow-context.test.js +66 -0
- package/dist/__tests__/sandbox-workflow-context.test.js.map +1 -0
- package/dist/aiden-system-prompt.d.ts +6 -0
- package/dist/aiden-system-prompt.d.ts.map +1 -0
- package/dist/aiden-system-prompt.js +6 -0
- package/dist/aiden-system-prompt.js.map +1 -0
- package/dist/cli-executable.d.ts +58 -0
- package/dist/cli-executable.d.ts.map +1 -0
- package/dist/cli-executable.js +301 -0
- package/dist/cli-executable.js.map +1 -0
- package/dist/cli-help.d.ts +7 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +45 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/core-agent.d.ts +6 -2
- package/dist/core-agent.d.ts.map +1 -1
- package/dist/core-agent.js +140 -21
- package/dist/core-agent.js.map +1 -1
- package/dist/daemon.d.ts +46 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +876 -0
- package/dist/daemon.js.map +1 -0
- package/dist/generated-images.d.ts +4 -0
- package/dist/generated-images.d.ts.map +1 -0
- package/dist/generated-images.js +142 -0
- package/dist/generated-images.js.map +1 -0
- package/dist/index.cjs +276 -32
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +107 -42
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +6 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +40 -10
- package/dist/sandbox.js.map +1 -1
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +0 -4
- package/dist/updater.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/web-presenter.d.ts +7 -4
- package/dist/web-presenter.d.ts.map +1 -1
- package/dist/web-presenter.js +29 -4
- package/dist/web-presenter.js.map +1 -1
- package/dist/ws-client.d.ts +35 -0
- package/dist/ws-client.d.ts.map +1 -1
- package/dist/ws-client.js +32 -9
- package/dist/ws-client.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -10225,10 +10225,7 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
|
10225
10225
|
stdin.write(`${message}
|
|
10226
10226
|
`);
|
|
10227
10227
|
},
|
|
10228
|
-
keepStdinOpen: true
|
|
10229
|
-
allowContinuation: true,
|
|
10230
|
-
continuationIdleMs: 10 * 60 * 1e3
|
|
10231
|
-
// 10 minutes
|
|
10228
|
+
keepStdinOpen: true
|
|
10232
10229
|
}).run(context);
|
|
10233
10230
|
}
|
|
10234
10231
|
};
|
|
@@ -12673,7 +12670,7 @@ function extractGeneratedImagesFromToolResult(toolId, content, cwd, toolName) {
|
|
|
12673
12670
|
}
|
|
12674
12671
|
|
|
12675
12672
|
// src/version.ts
|
|
12676
|
-
var AGENT_VERSION = "0.1.
|
|
12673
|
+
var AGENT_VERSION = "0.1.26";
|
|
12677
12674
|
|
|
12678
12675
|
// src/daemon.ts
|
|
12679
12676
|
var OPENCODE_FREE_MODEL_IDS = [
|
|
@@ -12687,6 +12684,23 @@ var PRODUCTION_API_URL = "https://api.aiden-platform.com";
|
|
|
12687
12684
|
var PRODUCTION_WS_URL = "wss://ws.aiden-platform.com";
|
|
12688
12685
|
var LOCAL_API_URL = "http://localhost:8400";
|
|
12689
12686
|
var LOCAL_WS_URL = "ws://localhost:8401";
|
|
12687
|
+
function correlationLogFields(input) {
|
|
12688
|
+
return Object.fromEntries(
|
|
12689
|
+
Object.entries({
|
|
12690
|
+
taskId: input.taskId,
|
|
12691
|
+
conversationId: input.conversationId,
|
|
12692
|
+
runId: input.runId,
|
|
12693
|
+
messageId: input.messageId,
|
|
12694
|
+
cloudEnvironmentId: input.cloudEnvironmentId,
|
|
12695
|
+
provider: input.backendKind,
|
|
12696
|
+
backendKind: input.backendKind,
|
|
12697
|
+
agentVersion: input.agentVersion
|
|
12698
|
+
}).filter((entry) => {
|
|
12699
|
+
const value2 = entry[1];
|
|
12700
|
+
return typeof value2 === "string" && value2.trim().length > 0;
|
|
12701
|
+
}).map(([key, value2]) => [key, value2.trim()])
|
|
12702
|
+
);
|
|
12703
|
+
}
|
|
12690
12704
|
async function probeLocalDaemonEndpoint(port, token, timeoutMs = 750) {
|
|
12691
12705
|
try {
|
|
12692
12706
|
const headers = {};
|
|
@@ -12923,12 +12937,13 @@ async function collectRuntimeMetadataWithProviderLimits() {
|
|
|
12923
12937
|
return metadata;
|
|
12924
12938
|
}
|
|
12925
12939
|
var RuntimePresenter = class {
|
|
12926
|
-
constructor(socket, conversationId, runId, cwd, touchRunnerActivity) {
|
|
12940
|
+
constructor(socket, conversationId, runId, cwd, touchRunnerActivity, onRunComplete) {
|
|
12927
12941
|
this.socket = socket;
|
|
12928
12942
|
this.conversationId = conversationId;
|
|
12929
12943
|
this.runId = runId;
|
|
12930
12944
|
this.cwd = cwd;
|
|
12931
12945
|
this.touchRunnerActivity = touchRunnerActivity;
|
|
12946
|
+
this.onRunComplete = onRunComplete;
|
|
12932
12947
|
}
|
|
12933
12948
|
emittedGeneratedImageKeys = /* @__PURE__ */ new Set();
|
|
12934
12949
|
toolNamesById = /* @__PURE__ */ new Map();
|
|
@@ -13015,6 +13030,7 @@ var RuntimePresenter = class {
|
|
|
13015
13030
|
}
|
|
13016
13031
|
onComplete(result) {
|
|
13017
13032
|
this.emitEvent({ type: "query_complete", result, ts: Date.now() });
|
|
13033
|
+
this.onRunComplete?.();
|
|
13018
13034
|
}
|
|
13019
13035
|
};
|
|
13020
13036
|
async function setupDaemon(args) {
|
|
@@ -13213,19 +13229,34 @@ async function startDaemon(args) {
|
|
|
13213
13229
|
return;
|
|
13214
13230
|
}
|
|
13215
13231
|
socket.emit("agent.accepted", { runId: payload.runId });
|
|
13232
|
+
const correlation = correlationLogFields({
|
|
13233
|
+
taskId: payload.taskId ?? payload.taskMeta?.id,
|
|
13234
|
+
conversationId: payload.conversationId,
|
|
13235
|
+
runId: payload.runId,
|
|
13236
|
+
messageId: payload.messageId,
|
|
13237
|
+
cloudEnvironmentId: payload.cloudEnvironmentId,
|
|
13238
|
+
backendKind,
|
|
13239
|
+
agentVersion: AGENT_VERSION
|
|
13240
|
+
});
|
|
13216
13241
|
pushLog(`accepted run=${payload.runId}`);
|
|
13242
|
+
console.info("[aiden-agent] Agent run accepted", correlation);
|
|
13217
13243
|
const cwd = payload.projectPath ?? process.cwd();
|
|
13218
13244
|
const nowMs = Date.now();
|
|
13219
13245
|
const touchActivity = () => {
|
|
13220
13246
|
const entry = activeAgents.get(payload.runId);
|
|
13221
13247
|
if (entry) entry.lastActivityAtMs = Date.now();
|
|
13222
13248
|
};
|
|
13249
|
+
const releaseActiveRun = () => {
|
|
13250
|
+
if (!activeAgents.delete(payload.runId)) return;
|
|
13251
|
+
console.info("[aiden-agent] Agent run finished", correlation);
|
|
13252
|
+
};
|
|
13223
13253
|
const presenter = new RuntimePresenter(
|
|
13224
13254
|
socket,
|
|
13225
13255
|
payload.conversationId,
|
|
13226
13256
|
payload.runId,
|
|
13227
13257
|
cwd,
|
|
13228
|
-
touchActivity
|
|
13258
|
+
touchActivity,
|
|
13259
|
+
releaseActiveRun
|
|
13229
13260
|
);
|
|
13230
13261
|
const agent = new CoreAgent(presenter, {
|
|
13231
13262
|
backendKind,
|
|
@@ -13254,7 +13285,7 @@ async function startDaemon(args) {
|
|
|
13254
13285
|
taskMeta: payload.taskMeta,
|
|
13255
13286
|
prMeta: payload.prMeta,
|
|
13256
13287
|
conversationId: payload.conversationId,
|
|
13257
|
-
taskId: payload.taskMeta?.id,
|
|
13288
|
+
taskId: payload.taskId ?? payload.taskMeta?.id,
|
|
13258
13289
|
teamId: payload.teamId,
|
|
13259
13290
|
currentUser: payload.currentUser,
|
|
13260
13291
|
workflowTools: payload.workflowTools,
|
|
@@ -13263,13 +13294,17 @@ async function startDaemon(args) {
|
|
|
13263
13294
|
}).catch((error) => {
|
|
13264
13295
|
const message = error instanceof Error ? error.message : String(error);
|
|
13265
13296
|
pushLog(`failed run=${payload.runId} ${message}`);
|
|
13297
|
+
console.error("[aiden-agent] Agent run failed", {
|
|
13298
|
+
...correlation,
|
|
13299
|
+
error: message
|
|
13300
|
+
});
|
|
13266
13301
|
socket.emit("agent.event", {
|
|
13267
13302
|
conversationId: payload.conversationId,
|
|
13268
13303
|
runId: payload.runId,
|
|
13269
13304
|
event: { type: "session_error", error: message }
|
|
13270
13305
|
});
|
|
13271
13306
|
}).finally(() => {
|
|
13272
|
-
|
|
13307
|
+
releaseActiveRun();
|
|
13273
13308
|
});
|
|
13274
13309
|
});
|
|
13275
13310
|
socket.on("agent.abort", (payload) => {
|
|
@@ -13279,6 +13314,10 @@ async function startDaemon(args) {
|
|
|
13279
13314
|
abortActiveAgent(entry);
|
|
13280
13315
|
activeAgents.delete(payload.runId);
|
|
13281
13316
|
pushLog(`aborted run=${payload.runId}`);
|
|
13317
|
+
console.info("[aiden-agent] Agent run aborted", {
|
|
13318
|
+
runId: payload.runId,
|
|
13319
|
+
agentVersion: AGENT_VERSION
|
|
13320
|
+
});
|
|
13282
13321
|
});
|
|
13283
13322
|
socket.on(
|
|
13284
13323
|
"agent.tool_response",
|
|
@@ -13607,6 +13646,78 @@ async function printDoctor(args = []) {
|
|
|
13607
13646
|
);
|
|
13608
13647
|
}
|
|
13609
13648
|
|
|
13649
|
+
// src/lifecycle-logger.ts
|
|
13650
|
+
var AgentLifecycleLogger = class _AgentLifecycleLogger {
|
|
13651
|
+
context;
|
|
13652
|
+
constructor(context = {}) {
|
|
13653
|
+
this.context = normalizeContext(context);
|
|
13654
|
+
}
|
|
13655
|
+
setContext(context) {
|
|
13656
|
+
this.context = normalizeContext({ ...this.context, ...context });
|
|
13657
|
+
}
|
|
13658
|
+
child(context) {
|
|
13659
|
+
return new _AgentLifecycleLogger({ ...this.context, ...context });
|
|
13660
|
+
}
|
|
13661
|
+
debug(event, fields = {}) {
|
|
13662
|
+
this.log("debug", event, fields);
|
|
13663
|
+
}
|
|
13664
|
+
info(event, fields = {}) {
|
|
13665
|
+
this.log("info", event, fields);
|
|
13666
|
+
}
|
|
13667
|
+
warn(event, fields = {}) {
|
|
13668
|
+
this.log("warn", event, fields);
|
|
13669
|
+
}
|
|
13670
|
+
error(event, fields = {}) {
|
|
13671
|
+
this.log("error", event, fields);
|
|
13672
|
+
}
|
|
13673
|
+
log(level, event, fields) {
|
|
13674
|
+
const record = omitUndefined({
|
|
13675
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
13676
|
+
level,
|
|
13677
|
+
component: "sandbox-agent",
|
|
13678
|
+
event,
|
|
13679
|
+
...this.context,
|
|
13680
|
+
...normalizeFields(fields)
|
|
13681
|
+
});
|
|
13682
|
+
console[level](JSON.stringify(record));
|
|
13683
|
+
}
|
|
13684
|
+
};
|
|
13685
|
+
function lifecycleContextFromEnv(env) {
|
|
13686
|
+
return normalizeContext({
|
|
13687
|
+
taskId: env.AIDEN_TASK_ID,
|
|
13688
|
+
conversationId: env.AIDEN_SESSION_ID,
|
|
13689
|
+
runId: env.AIDEN_RUN_ID,
|
|
13690
|
+
sandboxId: env.AIDEN_SANDBOX_ID,
|
|
13691
|
+
provider: env.AIDEN_SANDBOX_PROVIDER,
|
|
13692
|
+
backendKind: env.AIDEN_BACKEND_KIND,
|
|
13693
|
+
agentVersion: AGENT_VERSION
|
|
13694
|
+
});
|
|
13695
|
+
}
|
|
13696
|
+
function normalizeContext(context) {
|
|
13697
|
+
return omitUndefined({
|
|
13698
|
+
...context,
|
|
13699
|
+
agentVersion: context.agentVersion ?? AGENT_VERSION
|
|
13700
|
+
});
|
|
13701
|
+
}
|
|
13702
|
+
function normalizeFields(fields) {
|
|
13703
|
+
const normalized = {};
|
|
13704
|
+
for (const [key, value2] of Object.entries(fields)) {
|
|
13705
|
+
if (value2 instanceof Error) {
|
|
13706
|
+
normalized[key] = {
|
|
13707
|
+
name: value2.name,
|
|
13708
|
+
message: value2.message,
|
|
13709
|
+
stack: value2.stack
|
|
13710
|
+
};
|
|
13711
|
+
} else {
|
|
13712
|
+
normalized[key] = value2;
|
|
13713
|
+
}
|
|
13714
|
+
}
|
|
13715
|
+
return normalized;
|
|
13716
|
+
}
|
|
13717
|
+
function omitUndefined(record) {
|
|
13718
|
+
return Object.fromEntries(Object.entries(record).filter(([, value2]) => value2 !== void 0));
|
|
13719
|
+
}
|
|
13720
|
+
|
|
13610
13721
|
// src/web-presenter.ts
|
|
13611
13722
|
var WebPresenter = class {
|
|
13612
13723
|
constructor(wsClient, _conversationId, cwd) {
|
|
@@ -13725,8 +13836,9 @@ var WebPresenter = class {
|
|
|
13725
13836
|
|
|
13726
13837
|
// src/ws-client.ts
|
|
13727
13838
|
var WSClient = class {
|
|
13728
|
-
|
|
13729
|
-
|
|
13839
|
+
constructor(wsUrl, sessionId, taskId, token, callbacks, agentVersion, lifecycle) {
|
|
13840
|
+
this.lifecycle = lifecycle;
|
|
13841
|
+
this.lifecycle?.info("sandbox_agent_ws_socket_create", { wsUrl });
|
|
13730
13842
|
this.socket = lookup(wsUrl, {
|
|
13731
13843
|
query: { type: "agent", sessionId, taskId, agentVersion: agentVersion ?? "" },
|
|
13732
13844
|
auth: { token },
|
|
@@ -13741,6 +13853,7 @@ var WSClient = class {
|
|
|
13741
13853
|
});
|
|
13742
13854
|
this.setupListeners(callbacks);
|
|
13743
13855
|
}
|
|
13856
|
+
socket;
|
|
13744
13857
|
emitEvent(event) {
|
|
13745
13858
|
this.socket.emit("agent_event", event);
|
|
13746
13859
|
}
|
|
@@ -13767,20 +13880,26 @@ var WSClient = class {
|
|
|
13767
13880
|
get connected() {
|
|
13768
13881
|
return this.socket.connected;
|
|
13769
13882
|
}
|
|
13883
|
+
setLifecycleContext(context) {
|
|
13884
|
+
this.lifecycle?.setContext(context);
|
|
13885
|
+
}
|
|
13770
13886
|
close() {
|
|
13887
|
+
this.lifecycle?.info("sandbox_agent_ws_close_requested");
|
|
13771
13888
|
this.socket.disconnect();
|
|
13772
13889
|
}
|
|
13773
13890
|
setupListeners(callbacks) {
|
|
13774
13891
|
this.socket.on("connect", () => {
|
|
13775
|
-
|
|
13892
|
+
this.lifecycle?.info("sandbox_agent_ws_socket_connected", { socketId: this.socket.id });
|
|
13776
13893
|
callbacks.onConnect?.();
|
|
13777
13894
|
});
|
|
13778
13895
|
this.socket.on("disconnect", (reason) => {
|
|
13779
|
-
|
|
13896
|
+
this.lifecycle?.info("sandbox_agent_ws_socket_disconnected", { reason });
|
|
13780
13897
|
callbacks.onDisconnect?.(reason);
|
|
13781
13898
|
});
|
|
13782
13899
|
this.socket.on("connect_error", (error) => {
|
|
13783
|
-
|
|
13900
|
+
this.lifecycle?.warn("sandbox_agent_ws_socket_connect_error", {
|
|
13901
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
13902
|
+
});
|
|
13784
13903
|
});
|
|
13785
13904
|
this.socket.on(
|
|
13786
13905
|
"user_message",
|
|
@@ -13805,6 +13924,7 @@ var WSClient = class {
|
|
|
13805
13924
|
messageId: data.messageId,
|
|
13806
13925
|
maxIterations: data.maxIterations,
|
|
13807
13926
|
taskId: data.taskId,
|
|
13927
|
+
cloudEnvironmentId: data.cloudEnvironmentId,
|
|
13808
13928
|
conversationId: data.conversationId,
|
|
13809
13929
|
teamId: data.teamId,
|
|
13810
13930
|
currentUser: data.currentUser
|
|
@@ -13820,12 +13940,32 @@ var WSClient = class {
|
|
|
13820
13940
|
}
|
|
13821
13941
|
});
|
|
13822
13942
|
this.socket.on("error", (data) => {
|
|
13823
|
-
|
|
13943
|
+
this.lifecycle?.error("sandbox_agent_ws_server_error", {
|
|
13944
|
+
message: data.message,
|
|
13945
|
+
code: data.code
|
|
13946
|
+
});
|
|
13824
13947
|
});
|
|
13825
13948
|
}
|
|
13826
13949
|
};
|
|
13827
13950
|
|
|
13828
13951
|
// src/sandbox.ts
|
|
13952
|
+
function correlationLogFields2(input) {
|
|
13953
|
+
return Object.fromEntries(
|
|
13954
|
+
Object.entries({
|
|
13955
|
+
taskId: input.taskId,
|
|
13956
|
+
conversationId: input.conversationId,
|
|
13957
|
+
runId: input.runId,
|
|
13958
|
+
messageId: input.messageId,
|
|
13959
|
+
cloudEnvironmentId: input.cloudEnvironmentId,
|
|
13960
|
+
provider: input.backendKind,
|
|
13961
|
+
backendKind: input.backendKind,
|
|
13962
|
+
agentVersion: input.agentVersion
|
|
13963
|
+
}).filter((entry) => {
|
|
13964
|
+
const value2 = entry[1];
|
|
13965
|
+
return typeof value2 === "string" && value2.trim().length > 0;
|
|
13966
|
+
}).map(([key, value2]) => [key, value2.trim()])
|
|
13967
|
+
);
|
|
13968
|
+
}
|
|
13829
13969
|
async function runSandbox(config) {
|
|
13830
13970
|
let currentTask = config.task;
|
|
13831
13971
|
let currentImages = [];
|
|
@@ -13840,15 +13980,26 @@ async function runSandbox(config) {
|
|
|
13840
13980
|
let currentMaxIterations = config.maxIterations ?? 50;
|
|
13841
13981
|
let currentTaskId = config.taskId;
|
|
13842
13982
|
let currentConversationId = config.sessionId;
|
|
13983
|
+
let currentRunId;
|
|
13984
|
+
let currentMessageId;
|
|
13985
|
+
let currentCloudEnvironmentId;
|
|
13843
13986
|
let currentTeamId = config.teamId;
|
|
13844
13987
|
const workflowId = config.workflowId;
|
|
13845
13988
|
const workflowExecutionId = config.workflowExecutionId;
|
|
13846
13989
|
let currentUser = config.currentUser;
|
|
13847
13990
|
let currentTerminalContextRefs;
|
|
13848
13991
|
let currentTerminalSnapshots;
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13992
|
+
const lifecycle = config.lifecycle ?? new AgentLifecycleLogger({
|
|
13993
|
+
taskId: config.taskId,
|
|
13994
|
+
conversationId: config.sessionId,
|
|
13995
|
+
runId: config.runId,
|
|
13996
|
+
sandboxId: config.sandboxId,
|
|
13997
|
+
provider: config.provider,
|
|
13998
|
+
backendKind: config.backendKind,
|
|
13999
|
+
agentVersion: AGENT_VERSION
|
|
14000
|
+
});
|
|
14001
|
+
lifecycle.info("sandbox_agent_ws_connect_attempt", {
|
|
14002
|
+
wsUrl: config.wsUrl
|
|
13852
14003
|
});
|
|
13853
14004
|
const wsClient = new WSClient(
|
|
13854
14005
|
config.wsUrl,
|
|
@@ -13857,6 +14008,31 @@ async function runSandbox(config) {
|
|
|
13857
14008
|
config.sessionToken,
|
|
13858
14009
|
{
|
|
13859
14010
|
onUserMessage: (payload) => {
|
|
14011
|
+
if (payload === null) {
|
|
14012
|
+
if (pendingMessageResolve) {
|
|
14013
|
+
const resolve2 = pendingMessageResolve;
|
|
14014
|
+
pendingMessageResolve = null;
|
|
14015
|
+
resolve2(null);
|
|
14016
|
+
}
|
|
14017
|
+
return;
|
|
14018
|
+
}
|
|
14019
|
+
lifecycle.setContext({
|
|
14020
|
+
runId: payload.runId,
|
|
14021
|
+
taskId: payload.taskId,
|
|
14022
|
+
conversationId: payload.conversationId,
|
|
14023
|
+
backendKind: payload.backendKind
|
|
14024
|
+
});
|
|
14025
|
+
wsClient.setLifecycleContext({
|
|
14026
|
+
runId: payload.runId,
|
|
14027
|
+
taskId: payload.taskId,
|
|
14028
|
+
conversationId: payload.conversationId,
|
|
14029
|
+
backendKind: payload.backendKind
|
|
14030
|
+
});
|
|
14031
|
+
lifecycle.info("sandbox_agent_user_message_received", {
|
|
14032
|
+
messageId: payload.messageId,
|
|
14033
|
+
hasImages: Boolean(payload.images?.length),
|
|
14034
|
+
fileCount: payload.files?.length ?? 0
|
|
14035
|
+
});
|
|
13860
14036
|
if (pendingMessageResolve) {
|
|
13861
14037
|
const resolve2 = pendingMessageResolve;
|
|
13862
14038
|
pendingMessageResolve = null;
|
|
@@ -13866,7 +14042,7 @@ async function runSandbox(config) {
|
|
|
13866
14042
|
}
|
|
13867
14043
|
},
|
|
13868
14044
|
onStop: () => {
|
|
13869
|
-
|
|
14045
|
+
lifecycle.info("sandbox_agent_stop_received");
|
|
13870
14046
|
if (currentAgent) {
|
|
13871
14047
|
const killed = currentAgent.kill();
|
|
13872
14048
|
if (!killed) currentAgent.abort();
|
|
@@ -13876,21 +14052,24 @@ async function runSandbox(config) {
|
|
|
13876
14052
|
if (currentAgent) {
|
|
13877
14053
|
const sent = currentAgent.sendToolResponse(toolId, response);
|
|
13878
14054
|
if (!sent) {
|
|
13879
|
-
|
|
14055
|
+
lifecycle.warn("sandbox_agent_tool_response_delivery_failed", { toolId });
|
|
13880
14056
|
}
|
|
13881
14057
|
} else {
|
|
13882
|
-
|
|
14058
|
+
lifecycle.warn("sandbox_agent_tool_response_without_active_agent", { toolId });
|
|
13883
14059
|
}
|
|
13884
14060
|
},
|
|
13885
|
-
onConnect: () =>
|
|
13886
|
-
onDisconnect: (reason) =>
|
|
14061
|
+
onConnect: () => lifecycle.info("sandbox_agent_ws_connected"),
|
|
14062
|
+
onDisconnect: (reason) => lifecycle.info("sandbox_agent_ws_disconnected", { reason })
|
|
13887
14063
|
},
|
|
13888
|
-
AGENT_VERSION
|
|
14064
|
+
AGENT_VERSION,
|
|
14065
|
+
lifecycle
|
|
13889
14066
|
);
|
|
13890
14067
|
try {
|
|
13891
14068
|
await wsClient.waitForConnection();
|
|
13892
14069
|
} catch (error) {
|
|
13893
|
-
|
|
14070
|
+
lifecycle.error("sandbox_agent_ws_connect_failed", {
|
|
14071
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
14072
|
+
});
|
|
13894
14073
|
process.exit(1);
|
|
13895
14074
|
}
|
|
13896
14075
|
const presenter = new WebPresenter(wsClient, config.sessionId, config.projectPath);
|
|
@@ -13909,8 +14088,33 @@ async function runSandbox(config) {
|
|
|
13909
14088
|
backendKind: activeBackendKind
|
|
13910
14089
|
});
|
|
13911
14090
|
currentAgent = agent;
|
|
14091
|
+
const correlation = correlationLogFields2({
|
|
14092
|
+
taskId: currentTaskId,
|
|
14093
|
+
conversationId: currentConversationId,
|
|
14094
|
+
runId: currentRunId,
|
|
14095
|
+
messageId: currentMessageId,
|
|
14096
|
+
cloudEnvironmentId: currentCloudEnvironmentId,
|
|
14097
|
+
backendKind: activeBackendKind,
|
|
14098
|
+
agentVersion: AGENT_VERSION
|
|
14099
|
+
});
|
|
14100
|
+
console.info("[sandbox] Agent run started", correlation);
|
|
13912
14101
|
let result;
|
|
13913
14102
|
try {
|
|
14103
|
+
lifecycle.setContext({
|
|
14104
|
+
taskId: currentTaskId,
|
|
14105
|
+
conversationId: currentConversationId,
|
|
14106
|
+
backendKind: activeBackendKind
|
|
14107
|
+
});
|
|
14108
|
+
wsClient.setLifecycleContext({
|
|
14109
|
+
taskId: currentTaskId,
|
|
14110
|
+
conversationId: currentConversationId,
|
|
14111
|
+
backendKind: activeBackendKind
|
|
14112
|
+
});
|
|
14113
|
+
lifecycle.info("sandbox_agent_run_start", {
|
|
14114
|
+
mode: activeMode,
|
|
14115
|
+
model: activeModel,
|
|
14116
|
+
maxIterations: currentMaxIterations
|
|
14117
|
+
});
|
|
13914
14118
|
result = await agent.run({
|
|
13915
14119
|
task: currentTask,
|
|
13916
14120
|
maxIterations: currentMaxIterations,
|
|
@@ -13954,7 +14158,13 @@ async function runSandbox(config) {
|
|
|
13954
14158
|
});
|
|
13955
14159
|
} catch (error) {
|
|
13956
14160
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
13957
|
-
console.error("[sandbox] Agent run failed
|
|
14161
|
+
console.error("[sandbox] Agent run failed", {
|
|
14162
|
+
...correlation,
|
|
14163
|
+
error: errorMessage
|
|
14164
|
+
});
|
|
14165
|
+
lifecycle.error("sandbox_agent_run_failed", {
|
|
14166
|
+
error: error instanceof Error ? error : new Error(errorMessage)
|
|
14167
|
+
});
|
|
13958
14168
|
result = {
|
|
13959
14169
|
success: false,
|
|
13960
14170
|
summary: "Agent run failed",
|
|
@@ -13965,9 +14175,19 @@ async function runSandbox(config) {
|
|
|
13965
14175
|
};
|
|
13966
14176
|
}
|
|
13967
14177
|
currentAgent = null;
|
|
14178
|
+
lifecycle.info("sandbox_agent_run_complete", {
|
|
14179
|
+
success: result.success,
|
|
14180
|
+
iterations: result.iterations,
|
|
14181
|
+
error: result.error
|
|
14182
|
+
});
|
|
13968
14183
|
if (result?.providerSessionId) {
|
|
13969
14184
|
lastProviderSessionId = result.providerSessionId;
|
|
13970
14185
|
}
|
|
14186
|
+
console.info("[sandbox] Agent run finished", {
|
|
14187
|
+
...correlation,
|
|
14188
|
+
success: String(result.success),
|
|
14189
|
+
iterations: String(result.iterations)
|
|
14190
|
+
});
|
|
13971
14191
|
if (stopped) break;
|
|
13972
14192
|
}
|
|
13973
14193
|
const nextPayload = queuedMessages.shift() ?? await new Promise((resolve2) => {
|
|
@@ -14018,6 +14238,15 @@ async function runSandbox(config) {
|
|
|
14018
14238
|
if (nextPayload.taskId !== void 0) {
|
|
14019
14239
|
currentTaskId = nextPayload.taskId;
|
|
14020
14240
|
}
|
|
14241
|
+
if (nextPayload.runId !== void 0) {
|
|
14242
|
+
currentRunId = nextPayload.runId;
|
|
14243
|
+
}
|
|
14244
|
+
if (nextPayload.messageId !== void 0) {
|
|
14245
|
+
currentMessageId = nextPayload.messageId;
|
|
14246
|
+
}
|
|
14247
|
+
if (nextPayload.cloudEnvironmentId !== void 0) {
|
|
14248
|
+
currentCloudEnvironmentId = nextPayload.cloudEnvironmentId;
|
|
14249
|
+
}
|
|
14021
14250
|
if (nextPayload.conversationId !== void 0) {
|
|
14022
14251
|
currentConversationId = nextPayload.conversationId;
|
|
14023
14252
|
}
|
|
@@ -14035,6 +14264,7 @@ async function runSandbox(config) {
|
|
|
14035
14264
|
}
|
|
14036
14265
|
}
|
|
14037
14266
|
presenter.setSuppressSessionLifecycle(false);
|
|
14267
|
+
lifecycle.info("sandbox_agent_process_exit");
|
|
14038
14268
|
wsClient.close();
|
|
14039
14269
|
}
|
|
14040
14270
|
|
|
@@ -14057,20 +14287,28 @@ async function runSessionFromEnv() {
|
|
|
14057
14287
|
const providerSessionId = process.env.AIDEN_PROVIDER_SESSION_ID || void 0;
|
|
14058
14288
|
const workflowId = process.env.AIDEN_WORKFLOW_ID || void 0;
|
|
14059
14289
|
const workflowExecutionId = process.env.AIDEN_WORKFLOW_EXECUTION_ID || void 0;
|
|
14290
|
+
const sandboxId = process.env.AIDEN_SANDBOX_ID || void 0;
|
|
14291
|
+
const provider = process.env.AIDEN_SANDBOX_PROVIDER || void 0;
|
|
14292
|
+
const runId = process.env.AIDEN_RUN_ID || void 0;
|
|
14293
|
+
const lifecycle = new AgentLifecycleLogger(lifecycleContextFromEnv(process.env));
|
|
14060
14294
|
if (!wsUrl || !sessionId || !taskId || !sessionToken || task == null) {
|
|
14295
|
+
lifecycle.error("sandbox_agent_bootstrap_missing_env", {
|
|
14296
|
+
hasWsUrl: Boolean(wsUrl),
|
|
14297
|
+
hasConversationId: Boolean(sessionId),
|
|
14298
|
+
hasTaskId: Boolean(taskId),
|
|
14299
|
+
hasSessionToken: Boolean(sessionToken),
|
|
14300
|
+
hasTask: task != null
|
|
14301
|
+
});
|
|
14061
14302
|
throw new Error(
|
|
14062
14303
|
"run-session is an internal Aiden sandbox/session command and must be launched by Aiden with session env vars. Missing required env vars: AIDEN_WS_URL, AIDEN_SESSION_ID, AIDEN_TASK_ID, AIDEN_SESSION_TOKEN, AIDEN_TASK"
|
|
14063
14304
|
);
|
|
14064
14305
|
}
|
|
14065
|
-
|
|
14306
|
+
lifecycle.info("sandbox_agent_process_start", {
|
|
14066
14307
|
sessionId,
|
|
14067
|
-
taskId,
|
|
14068
14308
|
projectPath,
|
|
14069
|
-
backendKind,
|
|
14070
14309
|
agentId,
|
|
14071
14310
|
mode,
|
|
14072
|
-
model
|
|
14073
|
-
version: AGENT_VERSION
|
|
14311
|
+
model
|
|
14074
14312
|
});
|
|
14075
14313
|
await runSandbox({
|
|
14076
14314
|
wsUrl,
|
|
@@ -14090,6 +14328,10 @@ async function runSessionFromEnv() {
|
|
|
14090
14328
|
providerSessionId,
|
|
14091
14329
|
workflowId,
|
|
14092
14330
|
workflowExecutionId,
|
|
14331
|
+
sandboxId,
|
|
14332
|
+
provider,
|
|
14333
|
+
runId,
|
|
14334
|
+
lifecycle,
|
|
14093
14335
|
maxIterations: 50
|
|
14094
14336
|
});
|
|
14095
14337
|
}
|
|
@@ -14149,7 +14391,9 @@ async function main() {
|
|
|
14149
14391
|
${HELP_TEXT}`);
|
|
14150
14392
|
}
|
|
14151
14393
|
main().catch((error) => {
|
|
14152
|
-
|
|
14394
|
+
new AgentLifecycleLogger(lifecycleContextFromEnv(process.env)).error("sandbox_agent_fatal", {
|
|
14395
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
14396
|
+
});
|
|
14153
14397
|
process.exit(1);
|
|
14154
14398
|
});
|
|
14155
14399
|
/*! Bundled license information:
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|