@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.cjs
CHANGED
|
@@ -227,8 +227,10 @@ var init_types = __esm({
|
|
|
227
227
|
// error events
|
|
228
228
|
FILE: "file",
|
|
229
229
|
// file_push, file_pull, file_sync (file sync operations)
|
|
230
|
-
INPUT: "input"
|
|
230
|
+
INPUT: "input",
|
|
231
231
|
// user_input (user prompts/messages)
|
|
232
|
+
WEBHOOK: "webhook"
|
|
233
|
+
// webhook_delivery, webhook_failure (outbound webhook events)
|
|
232
234
|
};
|
|
233
235
|
}
|
|
234
236
|
});
|
|
@@ -6428,24 +6430,72 @@ var init_sandbox_file_sync = __esm({
|
|
|
6428
6430
|
removeWebhook() {
|
|
6429
6431
|
this.webhookConfig = void 0;
|
|
6430
6432
|
}
|
|
6433
|
+
/**
|
|
6434
|
+
* Extract hostname from URL for display (security - don't expose full URL)
|
|
6435
|
+
*/
|
|
6436
|
+
extractHostname(url) {
|
|
6437
|
+
try {
|
|
6438
|
+
const urlObj = new URL(url);
|
|
6439
|
+
return urlObj.hostname;
|
|
6440
|
+
} catch {
|
|
6441
|
+
return "unknown";
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
/**
|
|
6445
|
+
* Persist webhook delivery event to the session timeline
|
|
6446
|
+
*/
|
|
6447
|
+
async persistWebhookDelivery(sessionId, webhookType, result, filePath, operation) {
|
|
6448
|
+
if (!this.eventStorage || !this.webhookConfig) return;
|
|
6449
|
+
try {
|
|
6450
|
+
const now = /* @__PURE__ */ new Date();
|
|
6451
|
+
const sequenceNumber = await this.getNextSequenceNumber(sessionId);
|
|
6452
|
+
const eventData = {
|
|
6453
|
+
webhookType,
|
|
6454
|
+
targetUrl: this.extractHostname(this.webhookConfig.url),
|
|
6455
|
+
success: result.success,
|
|
6456
|
+
statusCode: result.statusCode,
|
|
6457
|
+
error: result.error,
|
|
6458
|
+
durationMs: result.durationMs,
|
|
6459
|
+
retryCount: result.retryCount > 0 ? result.retryCount : void 0,
|
|
6460
|
+
filePath,
|
|
6461
|
+
operation
|
|
6462
|
+
};
|
|
6463
|
+
const eventType = result.success ? "webhook_delivery" : "webhook_failure";
|
|
6464
|
+
const sessionEvent = {
|
|
6465
|
+
eventType,
|
|
6466
|
+
category: exports.EventCategory.WEBHOOK,
|
|
6467
|
+
startedAt: new Date(now.getTime() - result.durationMs),
|
|
6468
|
+
endedAt: now,
|
|
6469
|
+
durationMs: result.durationMs,
|
|
6470
|
+
eventData,
|
|
6471
|
+
sequenceNumber
|
|
6472
|
+
};
|
|
6473
|
+
await this.eventStorage.saveEvents(sessionId, [sessionEvent]);
|
|
6474
|
+
} catch (error) {
|
|
6475
|
+
console.error("[FILE_SYNC] Error saving webhook delivery event to storage:", error);
|
|
6476
|
+
}
|
|
6477
|
+
}
|
|
6431
6478
|
/**
|
|
6432
6479
|
* Send a webhook notification
|
|
6433
6480
|
* @param payload - The webhook payload to send
|
|
6481
|
+
* @param sessionId - Session ID for persisting delivery events
|
|
6482
|
+
* @returns WebhookDeliveryResult with success/failure info
|
|
6434
6483
|
*/
|
|
6435
|
-
async sendWebhook(payload) {
|
|
6436
|
-
if (!this.webhookConfig) return;
|
|
6484
|
+
async sendWebhook(payload, sessionId) {
|
|
6485
|
+
if (!this.webhookConfig) return null;
|
|
6437
6486
|
const config = this.webhookConfig;
|
|
6438
6487
|
const eventType = payload.fileSyncEvent?.operation ?? "file_change";
|
|
6439
6488
|
if (config.events && config.events.length > 0) {
|
|
6440
6489
|
const shouldSend = config.events.some(
|
|
6441
6490
|
(e) => e === eventType || e === "file_change" && payload.event === "file_change"
|
|
6442
6491
|
);
|
|
6443
|
-
if (!shouldSend) return;
|
|
6492
|
+
if (!shouldSend) return null;
|
|
6444
6493
|
}
|
|
6445
6494
|
const body = JSON.stringify(payload);
|
|
6446
6495
|
const timeoutMs = config.timeoutMs ?? 1e4;
|
|
6447
6496
|
const retries = config.retries ?? 3;
|
|
6448
6497
|
const isAsync = config.async !== false;
|
|
6498
|
+
const startTime = Date.now();
|
|
6449
6499
|
const headers = {
|
|
6450
6500
|
"Content-Type": "application/json",
|
|
6451
6501
|
"User-Agent": "Ash-FileSync/1.0",
|
|
@@ -6467,12 +6517,23 @@ var init_sandbox_file_sync = __esm({
|
|
|
6467
6517
|
signal: controller.signal
|
|
6468
6518
|
});
|
|
6469
6519
|
clearTimeout(timeoutId);
|
|
6520
|
+
const durationMs = Date.now() - startTime;
|
|
6470
6521
|
if (!response.ok) {
|
|
6471
|
-
|
|
6522
|
+
const error = `Webhook returned ${response.status}: ${response.statusText}`;
|
|
6523
|
+
if (attempt < retries) {
|
|
6524
|
+
const delay = Math.pow(2, attempt) * 1e3;
|
|
6525
|
+
console.warn(`[FILE_SYNC] Webhook failed (attempt ${attempt + 1}/${retries}), retrying in ${delay}ms: ${error}`);
|
|
6526
|
+
await new Promise((resolve3) => setTimeout(resolve3, delay));
|
|
6527
|
+
return sendWithRetry(attempt + 1);
|
|
6528
|
+
}
|
|
6529
|
+
console.error(`[FILE_SYNC] Webhook failed after ${retries} attempts: ${error}`);
|
|
6530
|
+
return { success: false, statusCode: response.status, error, durationMs, retryCount: attempt };
|
|
6472
6531
|
}
|
|
6473
6532
|
console.log(`[FILE_SYNC] Webhook sent successfully to ${config.url}`);
|
|
6533
|
+
return { success: true, statusCode: response.status, durationMs, retryCount: attempt };
|
|
6474
6534
|
} catch (error) {
|
|
6475
6535
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6536
|
+
const durationMs = Date.now() - startTime;
|
|
6476
6537
|
if (attempt < retries) {
|
|
6477
6538
|
const delay = Math.pow(2, attempt) * 1e3;
|
|
6478
6539
|
console.warn(`[FILE_SYNC] Webhook failed (attempt ${attempt + 1}/${retries}), retrying in ${delay}ms: ${errorMsg}`);
|
|
@@ -6480,15 +6541,27 @@ var init_sandbox_file_sync = __esm({
|
|
|
6480
6541
|
return sendWithRetry(attempt + 1);
|
|
6481
6542
|
}
|
|
6482
6543
|
console.error(`[FILE_SYNC] Webhook failed after ${retries} attempts: ${errorMsg}`);
|
|
6483
|
-
|
|
6544
|
+
return { success: false, error: errorMsg, durationMs, retryCount: attempt };
|
|
6484
6545
|
}
|
|
6485
6546
|
};
|
|
6547
|
+
const webhookType = payload.event === "file_sync" ? "file_sync" : "file_change";
|
|
6548
|
+
const filePath = payload.fileSyncEvent?.filePath ?? payload.fileChangeEvent?.relativePath;
|
|
6549
|
+
const operation = payload.fileSyncEvent?.operation ?? payload.fileChangeEvent?.type;
|
|
6486
6550
|
if (isAsync) {
|
|
6487
|
-
sendWithRetry(0).
|
|
6551
|
+
sendWithRetry(0).then(async (result) => {
|
|
6552
|
+
if (sessionId) {
|
|
6553
|
+
await this.persistWebhookDelivery(sessionId, webhookType, result, filePath, operation);
|
|
6554
|
+
}
|
|
6555
|
+
}).catch((error) => {
|
|
6488
6556
|
console.error("[FILE_SYNC] Async webhook failed:", error);
|
|
6489
6557
|
});
|
|
6558
|
+
return null;
|
|
6490
6559
|
} else {
|
|
6491
|
-
await sendWithRetry(0);
|
|
6560
|
+
const result = await sendWithRetry(0);
|
|
6561
|
+
if (sessionId) {
|
|
6562
|
+
await this.persistWebhookDelivery(sessionId, webhookType, result, filePath, operation);
|
|
6563
|
+
}
|
|
6564
|
+
return result;
|
|
6492
6565
|
}
|
|
6493
6566
|
}
|
|
6494
6567
|
/**
|
|
@@ -6502,7 +6575,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6502
6575
|
metadata: this.webhookConfig?.metadata,
|
|
6503
6576
|
fileSyncEvent: event
|
|
6504
6577
|
};
|
|
6505
|
-
await this.sendWebhook(payload);
|
|
6578
|
+
await this.sendWebhook(payload, sessionId);
|
|
6506
6579
|
}
|
|
6507
6580
|
/**
|
|
6508
6581
|
* Send a file change event webhook (from watcher)
|
|
@@ -6515,7 +6588,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6515
6588
|
metadata: this.webhookConfig?.metadata,
|
|
6516
6589
|
fileChangeEvent: event
|
|
6517
6590
|
};
|
|
6518
|
-
await this.sendWebhook(payload);
|
|
6591
|
+
await this.sendWebhook(payload, event.sessionId);
|
|
6519
6592
|
}
|
|
6520
6593
|
/**
|
|
6521
6594
|
* Get the next sequence number for a session
|
|
@@ -6601,9 +6674,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6601
6674
|
const isTextFile = diff !== void 0 || event.newContent && !event.newContent.slice(0, 8192).includes(0);
|
|
6602
6675
|
const eventData = {
|
|
6603
6676
|
operation: event.operation,
|
|
6604
|
-
|
|
6605
|
-
source: "internal",
|
|
6606
|
-
// File sync operations are internal
|
|
6677
|
+
source: event.source,
|
|
6607
6678
|
filePath: event.filePath,
|
|
6608
6679
|
fileSize: event.fileSize,
|
|
6609
6680
|
success: event.success,
|
|
@@ -6612,7 +6683,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6612
6683
|
isTextFile,
|
|
6613
6684
|
previousSize: event.previousContent?.length
|
|
6614
6685
|
};
|
|
6615
|
-
const eventType =
|
|
6686
|
+
const eventType = event.operation;
|
|
6616
6687
|
const sessionEvent = {
|
|
6617
6688
|
eventType,
|
|
6618
6689
|
category: exports.EventCategory.FILE,
|
|
@@ -6653,7 +6724,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
6653
6724
|
* @param sessionId - Session ID
|
|
6654
6725
|
* @param path - File path (stored in S3 and used as relative path in sandbox)
|
|
6655
6726
|
* @param content - File content
|
|
6656
|
-
* @param options - Push options (e.g., targetPath
|
|
6727
|
+
* @param options - Push options (e.g., targetPath, source)
|
|
6657
6728
|
* @param previousContent - Optional previous content for diff computation
|
|
6658
6729
|
*/
|
|
6659
6730
|
async pushFile(sessionId, path15, content, options, previousContent) {
|
|
@@ -6662,12 +6733,14 @@ var init_sandbox_file_sync = __esm({
|
|
|
6662
6733
|
s3Written: false,
|
|
6663
6734
|
sandboxWritten: false
|
|
6664
6735
|
};
|
|
6736
|
+
const source = options?.source ?? "client_api";
|
|
6737
|
+
const uploadToStorageOp = source === "client_api" ? "client_uploaded_to_ash_storage" : "agent_sandbox_saved_to_ash_storage";
|
|
6665
6738
|
try {
|
|
6666
6739
|
await this.fileStore.writeFile(sessionId, path15, content);
|
|
6667
6740
|
result.s3Written = true;
|
|
6668
6741
|
await this.emitFileEvent(sessionId, {
|
|
6669
|
-
operation:
|
|
6670
|
-
|
|
6742
|
+
operation: uploadToStorageOp,
|
|
6743
|
+
source,
|
|
6671
6744
|
filePath: path15,
|
|
6672
6745
|
fileSize: content.length,
|
|
6673
6746
|
success: true,
|
|
@@ -6679,8 +6752,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6679
6752
|
result.error = `S3 write failed: ${errorMessage}`;
|
|
6680
6753
|
console.error(`[FILE_SYNC] S3 write failed for session ${sessionId}, path ${path15}:`, error);
|
|
6681
6754
|
await this.emitFileEvent(sessionId, {
|
|
6682
|
-
operation:
|
|
6683
|
-
|
|
6755
|
+
operation: uploadToStorageOp,
|
|
6756
|
+
source,
|
|
6684
6757
|
filePath: path15,
|
|
6685
6758
|
fileSize: content.length,
|
|
6686
6759
|
success: false,
|
|
@@ -6694,8 +6767,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6694
6767
|
const writeResult = await this.sandboxOps.writeFile(sessionId, sandboxPath, content);
|
|
6695
6768
|
result.sandboxWritten = writeResult.success;
|
|
6696
6769
|
await this.emitFileEvent(sessionId, {
|
|
6697
|
-
operation: "
|
|
6698
|
-
|
|
6770
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6771
|
+
source,
|
|
6699
6772
|
filePath: path15,
|
|
6700
6773
|
fileSize: content.length,
|
|
6701
6774
|
success: writeResult.success,
|
|
@@ -6708,8 +6781,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6708
6781
|
const errorMessage = extractErrorMessage(error);
|
|
6709
6782
|
console.warn(`[FILE_SYNC] Sandbox write error for ${path15}: ${errorMessage}`);
|
|
6710
6783
|
await this.emitFileEvent(sessionId, {
|
|
6711
|
-
operation: "
|
|
6712
|
-
|
|
6784
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6785
|
+
source,
|
|
6713
6786
|
filePath: path15,
|
|
6714
6787
|
fileSize: content.length,
|
|
6715
6788
|
success: false,
|
|
@@ -6738,8 +6811,12 @@ var init_sandbox_file_sync = __esm({
|
|
|
6738
6811
|
/**
|
|
6739
6812
|
* Pull a file from sandbox to S3
|
|
6740
6813
|
* Reads from sandbox and writes to S3
|
|
6814
|
+
*
|
|
6815
|
+
* @param sessionId - Session ID
|
|
6816
|
+
* @param path - File path (relative to sandbox)
|
|
6817
|
+
* @param options - Pull options (e.g., targetPath to override sandbox location)
|
|
6741
6818
|
*/
|
|
6742
|
-
async pullFile(sessionId, path15) {
|
|
6819
|
+
async pullFile(sessionId, path15, options) {
|
|
6743
6820
|
const result = {
|
|
6744
6821
|
path: path15,
|
|
6745
6822
|
content: null,
|
|
@@ -6750,13 +6827,13 @@ var init_sandbox_file_sync = __esm({
|
|
|
6750
6827
|
return result;
|
|
6751
6828
|
}
|
|
6752
6829
|
try {
|
|
6753
|
-
const sandboxPath = this.getSandboxPath(path15);
|
|
6830
|
+
const sandboxPath = this.getSandboxPath(path15, options?.targetPath);
|
|
6754
6831
|
const readResult = await this.sandboxOps.readFile(sessionId, sandboxPath);
|
|
6755
6832
|
if (!readResult.success || !readResult.content) {
|
|
6756
6833
|
result.error = readResult.error ?? "File not found in sandbox";
|
|
6757
6834
|
await this.emitFileEvent(sessionId, {
|
|
6758
|
-
operation: "
|
|
6759
|
-
|
|
6835
|
+
operation: "read_from_agent_sandbox",
|
|
6836
|
+
source: "ash_file_sync",
|
|
6760
6837
|
filePath: path15,
|
|
6761
6838
|
success: false,
|
|
6762
6839
|
error: result.error
|
|
@@ -6765,8 +6842,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6765
6842
|
}
|
|
6766
6843
|
result.content = readResult.content;
|
|
6767
6844
|
await this.emitFileEvent(sessionId, {
|
|
6768
|
-
operation: "
|
|
6769
|
-
|
|
6845
|
+
operation: "read_from_agent_sandbox",
|
|
6846
|
+
source: "ash_file_sync",
|
|
6770
6847
|
filePath: path15,
|
|
6771
6848
|
fileSize: readResult.content.length,
|
|
6772
6849
|
success: true,
|
|
@@ -6776,8 +6853,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6776
6853
|
const errorMessage = extractErrorMessage(error);
|
|
6777
6854
|
result.error = `Sandbox read failed: ${errorMessage}`;
|
|
6778
6855
|
await this.emitFileEvent(sessionId, {
|
|
6779
|
-
operation: "
|
|
6780
|
-
|
|
6856
|
+
operation: "read_from_agent_sandbox",
|
|
6857
|
+
source: "ash_file_sync",
|
|
6781
6858
|
filePath: path15,
|
|
6782
6859
|
success: false,
|
|
6783
6860
|
error: errorMessage
|
|
@@ -6788,8 +6865,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6788
6865
|
await this.fileStore.writeFile(sessionId, path15, result.content);
|
|
6789
6866
|
result.s3Written = true;
|
|
6790
6867
|
await this.emitFileEvent(sessionId, {
|
|
6791
|
-
operation: "
|
|
6792
|
-
|
|
6868
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
6869
|
+
source: "ash_file_sync",
|
|
6793
6870
|
filePath: path15,
|
|
6794
6871
|
fileSize: result.content.length,
|
|
6795
6872
|
success: true,
|
|
@@ -6800,8 +6877,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6800
6877
|
result.error = `S3 write failed: ${errorMessage}`;
|
|
6801
6878
|
console.error(`[FILE_SYNC] S3 write failed in pullFile for session ${sessionId}, path ${path15}:`, error);
|
|
6802
6879
|
await this.emitFileEvent(sessionId, {
|
|
6803
|
-
operation: "
|
|
6804
|
-
|
|
6880
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
6881
|
+
source: "ash_file_sync",
|
|
6805
6882
|
filePath: path15,
|
|
6806
6883
|
fileSize: result.content?.length,
|
|
6807
6884
|
success: false,
|
|
@@ -6848,8 +6925,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6848
6925
|
await this.fileStore.deleteFile(sessionId, path15);
|
|
6849
6926
|
result.s3Deleted = true;
|
|
6850
6927
|
await this.emitFileEvent(sessionId, {
|
|
6851
|
-
operation: "
|
|
6852
|
-
|
|
6928
|
+
operation: "deleted_from_ash_storage",
|
|
6929
|
+
source: "ash_file_sync",
|
|
6853
6930
|
filePath: path15,
|
|
6854
6931
|
success: true
|
|
6855
6932
|
});
|
|
@@ -6857,8 +6934,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6857
6934
|
const errorMessage = extractErrorMessage(error);
|
|
6858
6935
|
console.warn(`[FILE_SYNC] S3 delete failed for ${path15}: ${errorMessage}`);
|
|
6859
6936
|
await this.emitFileEvent(sessionId, {
|
|
6860
|
-
operation: "
|
|
6861
|
-
|
|
6937
|
+
operation: "deleted_from_ash_storage",
|
|
6938
|
+
source: "ash_file_sync",
|
|
6862
6939
|
filePath: path15,
|
|
6863
6940
|
success: false,
|
|
6864
6941
|
error: errorMessage
|
|
@@ -6870,16 +6947,16 @@ var init_sandbox_file_sync = __esm({
|
|
|
6870
6947
|
console.log(`[FILE_SYNC] Would delete ${sandboxPath} from sandbox`);
|
|
6871
6948
|
result.sandboxDeleted = true;
|
|
6872
6949
|
await this.emitFileEvent(sessionId, {
|
|
6873
|
-
operation: "
|
|
6874
|
-
|
|
6950
|
+
operation: "deleted_from_agent_sandbox",
|
|
6951
|
+
source: "ash_file_sync",
|
|
6875
6952
|
filePath: path15,
|
|
6876
6953
|
success: true
|
|
6877
6954
|
});
|
|
6878
6955
|
} catch (error) {
|
|
6879
6956
|
const errorMessage = extractErrorMessage(error);
|
|
6880
6957
|
await this.emitFileEvent(sessionId, {
|
|
6881
|
-
operation: "
|
|
6882
|
-
|
|
6958
|
+
operation: "deleted_from_agent_sandbox",
|
|
6959
|
+
source: "ash_file_sync",
|
|
6883
6960
|
filePath: path15,
|
|
6884
6961
|
success: false,
|
|
6885
6962
|
error: errorMessage
|
|
@@ -6905,11 +6982,11 @@ var init_sandbox_file_sync = __esm({
|
|
|
6905
6982
|
if (!content) {
|
|
6906
6983
|
result.errors.push({ path: file.path, error: "File not found in S3" });
|
|
6907
6984
|
await this.emitFileEvent(sessionId, {
|
|
6908
|
-
operation: "
|
|
6909
|
-
|
|
6985
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6986
|
+
source: "ash_file_sync",
|
|
6910
6987
|
filePath: file.path,
|
|
6911
6988
|
success: false,
|
|
6912
|
-
error: "File not found in
|
|
6989
|
+
error: "File not found in Ash storage"
|
|
6913
6990
|
});
|
|
6914
6991
|
continue;
|
|
6915
6992
|
}
|
|
@@ -6918,8 +6995,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6918
6995
|
if (writeResult.success) {
|
|
6919
6996
|
result.fileCount++;
|
|
6920
6997
|
await this.emitFileEvent(sessionId, {
|
|
6921
|
-
operation: "
|
|
6922
|
-
|
|
6998
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
6999
|
+
source: "ash_file_sync",
|
|
6923
7000
|
filePath: file.path,
|
|
6924
7001
|
fileSize: content.length,
|
|
6925
7002
|
success: true
|
|
@@ -6927,8 +7004,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6927
7004
|
} else {
|
|
6928
7005
|
result.errors.push({ path: file.path, error: writeResult.error ?? "Unknown error" });
|
|
6929
7006
|
await this.emitFileEvent(sessionId, {
|
|
6930
|
-
operation: "
|
|
6931
|
-
|
|
7007
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
7008
|
+
source: "ash_file_sync",
|
|
6932
7009
|
filePath: file.path,
|
|
6933
7010
|
fileSize: content.length,
|
|
6934
7011
|
success: false,
|
|
@@ -6942,8 +7019,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6942
7019
|
error: errorMessage
|
|
6943
7020
|
});
|
|
6944
7021
|
await this.emitFileEvent(sessionId, {
|
|
6945
|
-
operation: "
|
|
6946
|
-
|
|
7022
|
+
operation: "ash_storage_synced_to_agent_sandbox",
|
|
7023
|
+
source: "ash_file_sync",
|
|
6947
7024
|
filePath: file.path,
|
|
6948
7025
|
success: false,
|
|
6949
7026
|
error: errorMessage
|
|
@@ -6980,23 +7057,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
6980
7057
|
const pullResult = await this.pullFile(sessionId, filePath);
|
|
6981
7058
|
if (pullResult.s3Written) {
|
|
6982
7059
|
result.fileCount++;
|
|
6983
|
-
await this.emitFileEvent(sessionId, {
|
|
6984
|
-
operation: "sync_from_sandbox",
|
|
6985
|
-
direction: "to_s3",
|
|
6986
|
-
filePath,
|
|
6987
|
-
fileSize: pullResult.content?.length,
|
|
6988
|
-
success: true,
|
|
6989
|
-
newContent: pullResult.content ?? void 0
|
|
6990
|
-
});
|
|
6991
7060
|
} else if (pullResult.error) {
|
|
6992
7061
|
result.errors.push({ path: filePath, error: pullResult.error });
|
|
6993
|
-
await this.emitFileEvent(sessionId, {
|
|
6994
|
-
operation: "sync_from_sandbox",
|
|
6995
|
-
direction: "to_s3",
|
|
6996
|
-
filePath,
|
|
6997
|
-
success: false,
|
|
6998
|
-
error: pullResult.error
|
|
6999
|
-
});
|
|
7000
7062
|
}
|
|
7001
7063
|
} catch (error) {
|
|
7002
7064
|
const errorMessage = extractErrorMessage(error);
|
|
@@ -7005,8 +7067,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
7005
7067
|
error: errorMessage
|
|
7006
7068
|
});
|
|
7007
7069
|
await this.emitFileEvent(sessionId, {
|
|
7008
|
-
operation: "
|
|
7009
|
-
|
|
7070
|
+
operation: "agent_sandbox_saved_to_ash_storage",
|
|
7071
|
+
source: "ash_file_sync",
|
|
7010
7072
|
filePath,
|
|
7011
7073
|
success: false,
|
|
7012
7074
|
error: errorMessage
|
|
@@ -7042,9 +7104,10 @@ var init_sandbox_file_sync = __esm({
|
|
|
7042
7104
|
*/
|
|
7043
7105
|
async startWatching(sessionId, options) {
|
|
7044
7106
|
const opts = { ...this.defaultWatchOptions, ...options };
|
|
7107
|
+
const watchPath = opts.watchPaths?.[0] ?? ".";
|
|
7045
7108
|
await this.stopWatching(sessionId);
|
|
7046
7109
|
const handleFileChange = async (event) => {
|
|
7047
|
-
console.log(`[FILE_SYNC] File change detected: ${event.type} ${event.relativePath}`);
|
|
7110
|
+
console.log(`[FILE_SYNC] File change detected: ${event.type} ${event.relativePath} (watching from: ${watchPath})`);
|
|
7048
7111
|
if (this.webhookConfig) {
|
|
7049
7112
|
this.sendFileChangeWebhook(event);
|
|
7050
7113
|
}
|
|
@@ -7057,7 +7120,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7057
7120
|
}
|
|
7058
7121
|
if (event.type === "add" || event.type === "change") {
|
|
7059
7122
|
try {
|
|
7060
|
-
const pullResult = await this.pullFile(sessionId, event.relativePath);
|
|
7123
|
+
const pullResult = await this.pullFile(sessionId, event.relativePath, { targetPath: watchPath });
|
|
7061
7124
|
if (pullResult.s3Written) {
|
|
7062
7125
|
console.log(`[FILE_SYNC] Auto-synced ${event.relativePath} to S3`);
|
|
7063
7126
|
} else if (pullResult.error) {
|
|
@@ -7088,7 +7151,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7088
7151
|
});
|
|
7089
7152
|
await watcher.start();
|
|
7090
7153
|
this.localWatchers.set(sessionId, watcher);
|
|
7091
|
-
console.log(`[FILE_SYNC] Started local file watching for session ${sessionId}`);
|
|
7154
|
+
console.log(`[FILE_SYNC] Started local file watching for session ${sessionId} at ${opts.localPath}`);
|
|
7092
7155
|
} else {
|
|
7093
7156
|
if (!this.sandboxOps) {
|
|
7094
7157
|
throw new Error("Sandbox operations not configured. Call setSandboxOperations first.");
|
|
@@ -7096,7 +7159,8 @@ var init_sandbox_file_sync = __esm({
|
|
|
7096
7159
|
const watcher = new exports.RemoteSandboxFileWatcher({
|
|
7097
7160
|
sessionId,
|
|
7098
7161
|
sandboxOps: this.sandboxOps,
|
|
7099
|
-
basePath:
|
|
7162
|
+
basePath: watchPath,
|
|
7163
|
+
// Use watchPath instead of sandboxBasePath
|
|
7100
7164
|
pollIntervalMs: opts.pollIntervalMs ?? 2e3,
|
|
7101
7165
|
ignored: opts.ignored ?? ["**/node_modules/**", "**/.git/**"],
|
|
7102
7166
|
onFileChange: handleFileChange,
|
|
@@ -7106,7 +7170,7 @@ var init_sandbox_file_sync = __esm({
|
|
|
7106
7170
|
});
|
|
7107
7171
|
await watcher.start();
|
|
7108
7172
|
this.remoteWatchers.set(sessionId, watcher);
|
|
7109
|
-
console.log(`[FILE_SYNC] Started remote file watching for session ${sessionId}`);
|
|
7173
|
+
console.log(`[FILE_SYNC] Started remote file watching for session ${sessionId} at path: ${watchPath}`);
|
|
7110
7174
|
}
|
|
7111
7175
|
}
|
|
7112
7176
|
/**
|
|
@@ -16241,8 +16305,10 @@ var init_schema = __esm({
|
|
|
16241
16305
|
// error events
|
|
16242
16306
|
"file",
|
|
16243
16307
|
// file_push, file_pull, file_sync (file sync operations)
|
|
16244
|
-
"input"
|
|
16308
|
+
"input",
|
|
16245
16309
|
// user_input (user prompts/messages)
|
|
16310
|
+
"webhook"
|
|
16311
|
+
// webhook_delivery, webhook_failure (outbound webhook events)
|
|
16246
16312
|
]);
|
|
16247
16313
|
sessions = pgCore.pgTable(
|
|
16248
16314
|
"sessions",
|