@ash-cloud/ash-ai 0.1.11 → 0.1.12
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 +141 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -14
- package/dist/index.d.ts +89 -14
- package/dist/index.js +141 -75
- package/dist/index.js.map +1 -1
- package/dist/{schema-B7RbjHWi.d.cts → schema-DSLyNeoS.d.cts} +3 -3
- package/dist/{schema-B7RbjHWi.d.ts → schema-DSLyNeoS.d.ts} +3 -3
- package/dist/schema.cjs +3 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +3 -1
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -199,8 +199,10 @@ var init_types = __esm({
|
|
|
199
199
|
// error events
|
|
200
200
|
FILE: "file",
|
|
201
201
|
// file_push, file_pull, file_sync (file sync operations)
|
|
202
|
-
INPUT: "input"
|
|
202
|
+
INPUT: "input",
|
|
203
203
|
// user_input (user prompts/messages)
|
|
204
|
+
WEBHOOK: "webhook"
|
|
205
|
+
// webhook_delivery, webhook_failure (outbound webhook events)
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
208
|
});
|
|
@@ -6400,24 +6402,72 @@ var init_sandbox_file_sync = __esm({
|
|
|
6400
6402
|
removeWebhook() {
|
|
6401
6403
|
this.webhookConfig = void 0;
|
|
6402
6404
|
}
|
|
6405
|
+
/**
|
|
6406
|
+
* Extract hostname from URL for display (security - don't expose full URL)
|
|
6407
|
+
*/
|
|
6408
|
+
extractHostname(url) {
|
|
6409
|
+
try {
|
|
6410
|
+
const urlObj = new URL(url);
|
|
6411
|
+
return urlObj.hostname;
|
|
6412
|
+
} catch {
|
|
6413
|
+
return "unknown";
|
|
6414
|
+
}
|
|
6415
|
+
}
|
|
6416
|
+
/**
|
|
6417
|
+
* Persist webhook delivery event to the session timeline
|
|
6418
|
+
*/
|
|
6419
|
+
async persistWebhookDelivery(sessionId, webhookType, result, filePath, operation) {
|
|
6420
|
+
if (!this.eventStorage || !this.webhookConfig) return;
|
|
6421
|
+
try {
|
|
6422
|
+
const now = /* @__PURE__ */ new Date();
|
|
6423
|
+
const sequenceNumber = await this.getNextSequenceNumber(sessionId);
|
|
6424
|
+
const eventData = {
|
|
6425
|
+
webhookType,
|
|
6426
|
+
targetUrl: this.extractHostname(this.webhookConfig.url),
|
|
6427
|
+
success: result.success,
|
|
6428
|
+
statusCode: result.statusCode,
|
|
6429
|
+
error: result.error,
|
|
6430
|
+
durationMs: result.durationMs,
|
|
6431
|
+
retryCount: result.retryCount > 0 ? result.retryCount : void 0,
|
|
6432
|
+
filePath,
|
|
6433
|
+
operation
|
|
6434
|
+
};
|
|
6435
|
+
const eventType = result.success ? "webhook_delivery" : "webhook_failure";
|
|
6436
|
+
const sessionEvent = {
|
|
6437
|
+
eventType,
|
|
6438
|
+
category: EventCategory.WEBHOOK,
|
|
6439
|
+
startedAt: new Date(now.getTime() - result.durationMs),
|
|
6440
|
+
endedAt: now,
|
|
6441
|
+
durationMs: result.durationMs,
|
|
6442
|
+
eventData,
|
|
6443
|
+
sequenceNumber
|
|
6444
|
+
};
|
|
6445
|
+
await this.eventStorage.saveEvents(sessionId, [sessionEvent]);
|
|
6446
|
+
} catch (error) {
|
|
6447
|
+
console.error("[FILE_SYNC] Error saving webhook delivery event to storage:", error);
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6403
6450
|
/**
|
|
6404
6451
|
* Send a webhook notification
|
|
6405
6452
|
* @param payload - The webhook payload to send
|
|
6453
|
+
* @param sessionId - Session ID for persisting delivery events
|
|
6454
|
+
* @returns WebhookDeliveryResult with success/failure info
|
|
6406
6455
|
*/
|
|
6407
|
-
async sendWebhook(payload) {
|
|
6408
|
-
if (!this.webhookConfig) return;
|
|
6456
|
+
async sendWebhook(payload, sessionId) {
|
|
6457
|
+
if (!this.webhookConfig) return null;
|
|
6409
6458
|
const config = this.webhookConfig;
|
|
6410
6459
|
const eventType = payload.fileSyncEvent?.operation ?? "file_change";
|
|
6411
6460
|
if (config.events && config.events.length > 0) {
|
|
6412
6461
|
const shouldSend = config.events.some(
|
|
6413
6462
|
(e) => e === eventType || e === "file_change" && payload.event === "file_change"
|
|
6414
6463
|
);
|
|
6415
|
-
if (!shouldSend) return;
|
|
6464
|
+
if (!shouldSend) return null;
|
|
6416
6465
|
}
|
|
6417
6466
|
const body = JSON.stringify(payload);
|
|
6418
6467
|
const timeoutMs = config.timeoutMs ?? 1e4;
|
|
6419
6468
|
const retries = config.retries ?? 3;
|
|
6420
6469
|
const isAsync = config.async !== false;
|
|
6470
|
+
const startTime = Date.now();
|
|
6421
6471
|
const headers = {
|
|
6422
6472
|
"Content-Type": "application/json",
|
|
6423
6473
|
"User-Agent": "Ash-FileSync/1.0",
|
|
@@ -6439,12 +6489,23 @@ var init_sandbox_file_sync = __esm({
|
|
|
6439
6489
|
signal: controller.signal
|
|
6440
6490
|
});
|
|
6441
6491
|
clearTimeout(timeoutId);
|
|
6492
|
+
const durationMs = Date.now() - startTime;
|
|
6442
6493
|
if (!response.ok) {
|
|
6443
|
-
|
|
6494
|
+
const error = `Webhook returned ${response.status}: ${response.statusText}`;
|
|
6495
|
+
if (attempt < retries) {
|
|
6496
|
+
const delay = Math.pow(2, attempt) * 1e3;
|
|
6497
|
+
console.warn(`[FILE_SYNC] Webhook failed (attempt ${attempt + 1}/${retries}), retrying in ${delay}ms: ${error}`);
|
|
6498
|
+
await new Promise((resolve3) => setTimeout(resolve3, delay));
|
|
6499
|
+
return sendWithRetry(attempt + 1);
|
|
6500
|
+
}
|
|
6501
|
+
console.error(`[FILE_SYNC] Webhook failed after ${retries} attempts: ${error}`);
|
|
6502
|
+
return { success: false, statusCode: response.status, error, durationMs, retryCount: attempt };
|
|
6444
6503
|
}
|
|
6445
6504
|
console.log(`[FILE_SYNC] Webhook sent successfully to ${config.url}`);
|
|
6505
|
+
return { success: true, statusCode: response.status, durationMs, retryCount: attempt };
|
|
6446
6506
|
} catch (error) {
|
|
6447
6507
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6508
|
+
const durationMs = Date.now() - startTime;
|
|
6448
6509
|
if (attempt < retries) {
|
|
6449
6510
|
const delay = Math.pow(2, attempt) * 1e3;
|
|
6450
6511
|
console.warn(`[FILE_SYNC] Webhook failed (attempt ${attempt + 1}/${retries}), retrying in ${delay}ms: ${errorMsg}`);
|
|
@@ -6452,15 +6513,27 @@ var init_sandbox_file_sync = __esm({
|
|
|
6452
6513
|
return sendWithRetry(attempt + 1);
|
|
6453
6514
|
}
|
|
6454
6515
|
console.error(`[FILE_SYNC] Webhook failed after ${retries} attempts: ${errorMsg}`);
|
|
6455
|
-
|
|
6516
|
+
return { success: false, error: errorMsg, durationMs, retryCount: attempt };
|
|
6456
6517
|
}
|
|
6457
6518
|
};
|
|
6519
|
+
const webhookType = payload.event === "file_sync" ? "file_sync" : "file_change";
|
|
6520
|
+
const filePath = payload.fileSyncEvent?.filePath ?? payload.fileChangeEvent?.relativePath;
|
|
6521
|
+
const operation = payload.fileSyncEvent?.operation ?? payload.fileChangeEvent?.type;
|
|
6458
6522
|
if (isAsync) {
|
|
6459
|
-
sendWithRetry(0).
|
|
6523
|
+
sendWithRetry(0).then(async (result) => {
|
|
6524
|
+
if (sessionId) {
|
|
6525
|
+
await this.persistWebhookDelivery(sessionId, webhookType, result, filePath, operation);
|
|
6526
|
+
}
|
|
6527
|
+
}).catch((error) => {
|
|
6460
6528
|
console.error("[FILE_SYNC] Async webhook failed:", error);
|
|
6461
6529
|
});
|
|
6530
|
+
return null;
|
|
6462
6531
|
} else {
|
|
6463
|
-
await sendWithRetry(0);
|
|
6532
|
+
const result = await sendWithRetry(0);
|
|
6533
|
+
if (sessionId) {
|
|
6534
|
+
await this.persistWebhookDelivery(sessionId, webhookType, result, filePath, operation);
|
|
6535
|
+
}
|
|
6536
|
+
return result;
|
|
6464
6537
|
}
|
|
6465
6538
|
}
|
|
6466
6539
|
/**
|
|
@@ -6474,7 +6547,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6474
6547
|
metadata: this.webhookConfig?.metadata,
|
|
6475
6548
|
fileSyncEvent: event
|
|
6476
6549
|
};
|
|
6477
|
-
await this.sendWebhook(payload);
|
|
6550
|
+
await this.sendWebhook(payload, sessionId);
|
|
6478
6551
|
}
|
|
6479
6552
|
/**
|
|
6480
6553
|
* Send a file change event webhook (from watcher)
|
|
@@ -6487,7 +6560,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6487
6560
|
metadata: this.webhookConfig?.metadata,
|
|
6488
6561
|
fileChangeEvent: event
|
|
6489
6562
|
};
|
|
6490
|
-
await this.sendWebhook(payload);
|
|
6563
|
+
await this.sendWebhook(payload, event.sessionId);
|
|
6491
6564
|
}
|
|
6492
6565
|
/**
|
|
6493
6566
|
* Get the next sequence number for a session
|
|
@@ -6573,9 +6646,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6573
6646
|
const isTextFile = diff !== void 0 || event.newContent && !event.newContent.slice(0, 8192).includes(0);
|
|
6574
6647
|
const eventData = {
|
|
6575
6648
|
operation: event.operation,
|
|
6576
|
-
|
|
6577
|
-
source: "internal",
|
|
6578
|
-
// File sync operations are internal
|
|
6649
|
+
source: event.source,
|
|
6579
6650
|
filePath: event.filePath,
|
|
6580
6651
|
fileSize: event.fileSize,
|
|
6581
6652
|
success: event.success,
|
|
@@ -6584,7 +6655,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6584
6655
|
isTextFile,
|
|
6585
6656
|
previousSize: event.previousContent?.length
|
|
6586
6657
|
};
|
|
6587
|
-
const eventType =
|
|
6658
|
+
const eventType = event.operation;
|
|
6588
6659
|
const sessionEvent = {
|
|
6589
6660
|
eventType,
|
|
6590
6661
|
category: EventCategory.FILE,
|
|
@@ -6625,7 +6696,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6625
6696
|
* @param sessionId - Session ID
|
|
6626
6697
|
* @param path - File path (stored in S3 and used as relative path in sandbox)
|
|
6627
6698
|
* @param content - File content
|
|
6628
|
-
* @param options - Push options (e.g., targetPath
|
|
6699
|
+
* @param options - Push options (e.g., targetPath, source)
|
|
6629
6700
|
* @param previousContent - Optional previous content for diff computation
|
|
6630
6701
|
*/
|
|
6631
6702
|
async pushFile(sessionId, path15, content, options, previousContent) {
|
|
@@ -6634,12 +6705,14 @@ var init_sandbox_file_sync = __esm({
|
|
|
6634
6705
|
s3Written: false,
|
|
6635
6706
|
sandboxWritten: false
|
|
6636
6707
|
};
|
|
6708
|
+
const source = options?.source ?? "client_api";
|
|
6709
|
+
const uploadToStorageOp = source === "client_api" ? "client_uploaded_to_ash_storage" : "agent_sandbox_saved_to_ash_storage";
|
|
6637
6710
|
try {
|
|
6638
6711
|
await this.fileStore.writeFile(sessionId, path15, content);
|
|
6639
6712
|
result.s3Written = true;
|
|
6640
6713
|
await this.emitFileEvent(sessionId, {
|
|
6641
|
-
operation:
|
|
6642
|
-
|
|
6714
|
+
operation: uploadToStorageOp,
|
|
6715
|
+
source,
|
|
6643
6716
|
filePath: path15,
|
|
6644
6717
|
fileSize: content.length,
|
|
6645
6718
|
success: true,
|
|
@@ -6651,8 +6724,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6651
6724
|
result.error = `S3 write failed: ${errorMessage}`;
|
|
6652
6725
|
console.error(`[FILE_SYNC] S3 write failed for session ${sessionId}, path ${path15}:`, error);
|
|
6653
6726
|
await this.emitFileEvent(sessionId, {
|
|
6654
|
-
operation:
|
|
6655
|
-
|
|
6727
|
+
operation: uploadToStorageOp,
|
|
6728
|
+
source,
|
|
6656
6729
|
filePath: path15,
|
|
6657
6730
|
fileSize: content.length,
|
|
6658
6731
|
success: false,
|
|
@@ -6666,8 +6739,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6666
6739
|
const writeResult = await this.sandboxOps.writeFile(sessionId, sandboxPath, content);
|
|
6667
6740
|
result.sandboxWritten = writeResult.success;
|
|
6668
6741
|
await this.emitFileEvent(sessionId, {
|
|
6669
|
-
operation: "
|
|
6670
|
-
|
|
6742
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6743
|
+
source,
|
|
6671
6744
|
filePath: path15,
|
|
6672
6745
|
fileSize: content.length,
|
|
6673
6746
|
success: writeResult.success,
|
|
@@ -6680,8 +6753,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6680
6753
|
const errorMessage = extractErrorMessage(error);
|
|
6681
6754
|
console.warn(`[FILE_SYNC] Sandbox write error for ${path15}: ${errorMessage}`);
|
|
6682
6755
|
await this.emitFileEvent(sessionId, {
|
|
6683
|
-
operation: "
|
|
6684
|
-
|
|
6756
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6757
|
+
source,
|
|
6685
6758
|
filePath: path15,
|
|
6686
6759
|
fileSize: content.length,
|
|
6687
6760
|
success: false,
|
|
@@ -6710,8 +6783,12 @@ var init_sandbox_file_sync = __esm({
|
|
|
6710
6783
|
/**
|
|
6711
6784
|
* Pull a file from sandbox to S3
|
|
6712
6785
|
* Reads from sandbox and writes to S3
|
|
6786
|
+
*
|
|
6787
|
+
* @param sessionId - Session ID
|
|
6788
|
+
* @param path - File path (relative to sandbox)
|
|
6789
|
+
* @param options - Pull options (e.g., targetPath to override sandbox location)
|
|
6713
6790
|
*/
|
|
6714
|
-
async pullFile(sessionId, path15) {
|
|
6791
|
+
async pullFile(sessionId, path15, options) {
|
|
6715
6792
|
const result = {
|
|
6716
6793
|
path: path15,
|
|
6717
6794
|
content: null,
|
|
@@ -6722,13 +6799,13 @@ var init_sandbox_file_sync = __esm({
|
|
|
6722
6799
|
return result;
|
|
6723
6800
|
}
|
|
6724
6801
|
try {
|
|
6725
|
-
const sandboxPath = this.getSandboxPath(path15);
|
|
6802
|
+
const sandboxPath = this.getSandboxPath(path15, options?.targetPath);
|
|
6726
6803
|
const readResult = await this.sandboxOps.readFile(sessionId, sandboxPath);
|
|
6727
6804
|
if (!readResult.success || !readResult.content) {
|
|
6728
6805
|
result.error = readResult.error ?? "File not found in sandbox";
|
|
6729
6806
|
await this.emitFileEvent(sessionId, {
|
|
6730
|
-
operation: "
|
|
6731
|
-
|
|
6807
|
+
operation: "read_from_agent_sandbox",
|
|
6808
|
+
source: "ash_file_sync",
|
|
6732
6809
|
filePath: path15,
|
|
6733
6810
|
success: false,
|
|
6734
6811
|
error: result.error
|
|
@@ -6737,8 +6814,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6737
6814
|
}
|
|
6738
6815
|
result.content = readResult.content;
|
|
6739
6816
|
await this.emitFileEvent(sessionId, {
|
|
6740
|
-
operation: "
|
|
6741
|
-
|
|
6817
|
+
operation: "read_from_agent_sandbox",
|
|
6818
|
+
source: "ash_file_sync",
|
|
6742
6819
|
filePath: path15,
|
|
6743
6820
|
fileSize: readResult.content.length,
|
|
6744
6821
|
success: true,
|
|
@@ -6748,8 +6825,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6748
6825
|
const errorMessage = extractErrorMessage(error);
|
|
6749
6826
|
result.error = `Sandbox read failed: ${errorMessage}`;
|
|
6750
6827
|
await this.emitFileEvent(sessionId, {
|
|
6751
|
-
operation: "
|
|
6752
|
-
|
|
6828
|
+
operation: "read_from_agent_sandbox",
|
|
6829
|
+
source: "ash_file_sync",
|
|
6753
6830
|
filePath: path15,
|
|
6754
6831
|
success: false,
|
|
6755
6832
|
error: errorMessage
|
|
@@ -6760,8 +6837,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6760
6837
|
await this.fileStore.writeFile(sessionId, path15, result.content);
|
|
6761
6838
|
result.s3Written = true;
|
|
6762
6839
|
await this.emitFileEvent(sessionId, {
|
|
6763
|
-
operation: "
|
|
6764
|
-
|
|
6840
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
6841
|
+
source: "ash_file_sync",
|
|
6765
6842
|
filePath: path15,
|
|
6766
6843
|
fileSize: result.content.length,
|
|
6767
6844
|
success: true,
|
|
@@ -6772,8 +6849,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6772
6849
|
result.error = `S3 write failed: ${errorMessage}`;
|
|
6773
6850
|
console.error(`[FILE_SYNC] S3 write failed in pullFile for session ${sessionId}, path ${path15}:`, error);
|
|
6774
6851
|
await this.emitFileEvent(sessionId, {
|
|
6775
|
-
operation: "
|
|
6776
|
-
|
|
6852
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
6853
|
+
source: "ash_file_sync",
|
|
6777
6854
|
filePath: path15,
|
|
6778
6855
|
fileSize: result.content?.length,
|
|
6779
6856
|
success: false,
|
|
@@ -6820,8 +6897,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6820
6897
|
await this.fileStore.deleteFile(sessionId, path15);
|
|
6821
6898
|
result.s3Deleted = true;
|
|
6822
6899
|
await this.emitFileEvent(sessionId, {
|
|
6823
|
-
operation: "
|
|
6824
|
-
|
|
6900
|
+
operation: "deleted_from_ash_storage",
|
|
6901
|
+
source: "ash_file_sync",
|
|
6825
6902
|
filePath: path15,
|
|
6826
6903
|
success: true
|
|
6827
6904
|
});
|
|
@@ -6829,8 +6906,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6829
6906
|
const errorMessage = extractErrorMessage(error);
|
|
6830
6907
|
console.warn(`[FILE_SYNC] S3 delete failed for ${path15}: ${errorMessage}`);
|
|
6831
6908
|
await this.emitFileEvent(sessionId, {
|
|
6832
|
-
operation: "
|
|
6833
|
-
|
|
6909
|
+
operation: "deleted_from_ash_storage",
|
|
6910
|
+
source: "ash_file_sync",
|
|
6834
6911
|
filePath: path15,
|
|
6835
6912
|
success: false,
|
|
6836
6913
|
error: errorMessage
|
|
@@ -6842,16 +6919,16 @@ var init_sandbox_file_sync = __esm({
|
|
|
6842
6919
|
console.log(`[FILE_SYNC] Would delete ${sandboxPath} from sandbox`);
|
|
6843
6920
|
result.sandboxDeleted = true;
|
|
6844
6921
|
await this.emitFileEvent(sessionId, {
|
|
6845
|
-
operation: "
|
|
6846
|
-
|
|
6922
|
+
operation: "deleted_from_agent_sandbox",
|
|
6923
|
+
source: "ash_file_sync",
|
|
6847
6924
|
filePath: path15,
|
|
6848
6925
|
success: true
|
|
6849
6926
|
});
|
|
6850
6927
|
} catch (error) {
|
|
6851
6928
|
const errorMessage = extractErrorMessage(error);
|
|
6852
6929
|
await this.emitFileEvent(sessionId, {
|
|
6853
|
-
operation: "
|
|
6854
|
-
|
|
6930
|
+
operation: "deleted_from_agent_sandbox",
|
|
6931
|
+
source: "ash_file_sync",
|
|
6855
6932
|
filePath: path15,
|
|
6856
6933
|
success: false,
|
|
6857
6934
|
error: errorMessage
|
|
@@ -6877,11 +6954,11 @@ var init_sandbox_file_sync = __esm({
|
|
|
6877
6954
|
if (!content) {
|
|
6878
6955
|
result.errors.push({ path: file.path, error: "File not found in S3" });
|
|
6879
6956
|
await this.emitFileEvent(sessionId, {
|
|
6880
|
-
operation: "
|
|
6881
|
-
|
|
6957
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6958
|
+
source: "ash_file_sync",
|
|
6882
6959
|
filePath: file.path,
|
|
6883
6960
|
success: false,
|
|
6884
|
-
error: "File not found in
|
|
6961
|
+
error: "File not found in Ash storage"
|
|
6885
6962
|
});
|
|
6886
6963
|
continue;
|
|
6887
6964
|
}
|
|
@@ -6890,8 +6967,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6890
6967
|
if (writeResult.success) {
|
|
6891
6968
|
result.fileCount++;
|
|
6892
6969
|
await this.emitFileEvent(sessionId, {
|
|
6893
|
-
operation: "
|
|
6894
|
-
|
|
6970
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6971
|
+
source: "ash_file_sync",
|
|
6895
6972
|
filePath: file.path,
|
|
6896
6973
|
fileSize: content.length,
|
|
6897
6974
|
success: true
|
|
@@ -6899,8 +6976,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6899
6976
|
} else {
|
|
6900
6977
|
result.errors.push({ path: file.path, error: writeResult.error ?? "Unknown error" });
|
|
6901
6978
|
await this.emitFileEvent(sessionId, {
|
|
6902
|
-
operation: "
|
|
6903
|
-
|
|
6979
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6980
|
+
source: "ash_file_sync",
|
|
6904
6981
|
filePath: file.path,
|
|
6905
6982
|
fileSize: content.length,
|
|
6906
6983
|
success: false,
|
|
@@ -6914,8 +6991,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6914
6991
|
error: errorMessage
|
|
6915
6992
|
});
|
|
6916
6993
|
await this.emitFileEvent(sessionId, {
|
|
6917
|
-
operation: "
|
|
6918
|
-
|
|
6994
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6995
|
+
source: "ash_file_sync",
|
|
6919
6996
|
filePath: file.path,
|
|
6920
6997
|
success: false,
|
|
6921
6998
|
error: errorMessage
|
|
@@ -6952,23 +7029,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6952
7029
|
const pullResult = await this.pullFile(sessionId, filePath);
|
|
6953
7030
|
if (pullResult.s3Written) {
|
|
6954
7031
|
result.fileCount++;
|
|
6955
|
-
await this.emitFileEvent(sessionId, {
|
|
6956
|
-
operation: "sync_from_sandbox",
|
|
6957
|
-
direction: "to_s3",
|
|
6958
|
-
filePath,
|
|
6959
|
-
fileSize: pullResult.content?.length,
|
|
6960
|
-
success: true,
|
|
6961
|
-
newContent: pullResult.content ?? void 0
|
|
6962
|
-
});
|
|
6963
7032
|
} else if (pullResult.error) {
|
|
6964
7033
|
result.errors.push({ path: filePath, error: pullResult.error });
|
|
6965
|
-
await this.emitFileEvent(sessionId, {
|
|
6966
|
-
operation: "sync_from_sandbox",
|
|
6967
|
-
direction: "to_s3",
|
|
6968
|
-
filePath,
|
|
6969
|
-
success: false,
|
|
6970
|
-
error: pullResult.error
|
|
6971
|
-
});
|
|
6972
7034
|
}
|
|
6973
7035
|
} catch (error) {
|
|
6974
7036
|
const errorMessage = extractErrorMessage(error);
|
|
@@ -6977,8 +7039,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6977
7039
|
error: errorMessage
|
|
6978
7040
|
});
|
|
6979
7041
|
await this.emitFileEvent(sessionId, {
|
|
6980
|
-
operation: "
|
|
6981
|
-
|
|
7042
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
7043
|
+
source: "ash_file_sync",
|
|
6982
7044
|
filePath,
|
|
6983
7045
|
success: false,
|
|
6984
7046
|
error: errorMessage
|
|
@@ -7014,9 +7076,10 @@ var init_sandbox_file_sync = __esm({
|
|
|
7014
7076
|
*/
|
|
7015
7077
|
async startWatching(sessionId, options) {
|
|
7016
7078
|
const opts = { ...this.defaultWatchOptions, ...options };
|
|
7079
|
+
const watchPath = opts.watchPaths?.[0] ?? ".";
|
|
7017
7080
|
await this.stopWatching(sessionId);
|
|
7018
7081
|
const handleFileChange = async (event) => {
|
|
7019
|
-
console.log(`[FILE_SYNC] File change detected: ${event.type} ${event.relativePath}`);
|
|
7082
|
+
console.log(`[FILE_SYNC] File change detected: ${event.type} ${event.relativePath} (watching from: ${watchPath})`);
|
|
7020
7083
|
if (this.webhookConfig) {
|
|
7021
7084
|
this.sendFileChangeWebhook(event);
|
|
7022
7085
|
}
|
|
@@ -7029,7 +7092,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7029
7092
|
}
|
|
7030
7093
|
if (event.type === "add" || event.type === "change") {
|
|
7031
7094
|
try {
|
|
7032
|
-
const pullResult = await this.pullFile(sessionId, event.relativePath);
|
|
7095
|
+
const pullResult = await this.pullFile(sessionId, event.relativePath, { targetPath: watchPath });
|
|
7033
7096
|
if (pullResult.s3Written) {
|
|
7034
7097
|
console.log(`[FILE_SYNC] Auto-synced ${event.relativePath} to S3`);
|
|
7035
7098
|
} else if (pullResult.error) {
|
|
@@ -7060,7 +7123,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7060
7123
|
});
|
|
7061
7124
|
await watcher.start();
|
|
7062
7125
|
this.localWatchers.set(sessionId, watcher);
|
|
7063
|
-
console.log(`[FILE_SYNC] Started local file watching for session ${sessionId}`);
|
|
7126
|
+
console.log(`[FILE_SYNC] Started local file watching for session ${sessionId} at ${opts.localPath}`);
|
|
7064
7127
|
} else {
|
|
7065
7128
|
if (!this.sandboxOps) {
|
|
7066
7129
|
throw new Error("Sandbox operations not configured. Call setSandboxOperations first.");
|
|
@@ -7068,7 +7131,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
7068
7131
|
const watcher = new RemoteSandboxFileWatcher({
|
|
7069
7132
|
sessionId,
|
|
7070
7133
|
sandboxOps: this.sandboxOps,
|
|
7071
|
-
basePath:
|
|
7134
|
+
basePath: watchPath,
|
|
7135
|
+
// Use watchPath instead of sandboxBasePath
|
|
7072
7136
|
pollIntervalMs: opts.pollIntervalMs ?? 2e3,
|
|
7073
7137
|
ignored: opts.ignored ?? ["**/node_modules/**", "**/.git/**"],
|
|
7074
7138
|
onFileChange: handleFileChange,
|
|
@@ -7078,7 +7142,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7078
7142
|
});
|
|
7079
7143
|
await watcher.start();
|
|
7080
7144
|
this.remoteWatchers.set(sessionId, watcher);
|
|
7081
|
-
console.log(`[FILE_SYNC] Started remote file watching for session ${sessionId}`);
|
|
7145
|
+
console.log(`[FILE_SYNC] Started remote file watching for session ${sessionId} at path: ${watchPath}`);
|
|
7082
7146
|
}
|
|
7083
7147
|
}
|
|
7084
7148
|
/**
|
|
@@ -16213,8 +16277,10 @@ var init_schema = __esm({
|
|
|
16213
16277
|
// error events
|
|
16214
16278
|
"file",
|
|
16215
16279
|
// file_push, file_pull, file_sync (file sync operations)
|
|
16216
|
-
"input"
|
|
16280
|
+
"input",
|
|
16217
16281
|
// user_input (user prompts/messages)
|
|
16282
|
+
"webhook"
|
|
16283
|
+
// webhook_delivery, webhook_failure (outbound webhook events)
|
|
16218
16284
|
]);
|
|
16219
16285
|
sessions = pgTable(
|
|
16220
16286
|
"sessions",
|