@letta-ai/letta-agent-sdk 0.8.2 → 0.8.3
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/client-entry.js +77 -6
- package/dist/client-entry.js.map +5 -5
- package/dist/cloud-sandbox.d.ts +2 -0
- package/dist/cloud-sandbox.d.ts.map +1 -1
- package/dist/index.js +77 -6
- package/dist/index.js.map +5 -5
- package/dist/remote-session-protocol.d.ts +3 -0
- package/dist/remote-session-protocol.d.ts.map +1 -1
- package/dist/remote-turn-coordinator.d.ts +1 -0
- package/dist/remote-turn-coordinator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cloud-sandbox.ts +12 -0
- package/src/remote-session-protocol.ts +3 -0
- package/src/remote-turn-coordinator.ts +89 -5
package/dist/cloud-sandbox.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-sandbox.d.ts","sourceRoot":"","sources":["../src/cloud-sandbox.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"cloud-sandbox.d.ts","sourceRoot":"","sources":["../src/cloud-sandbox.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sEAAsE;IACtE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC3C;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAeD,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GAAG,SAAS,EACjD,IAAI,EAAE,MAAM,GACX,IAAI,CA6EN"}
|
package/dist/index.js
CHANGED
|
@@ -6688,6 +6688,7 @@ function turnSendOptions(turn) {
|
|
|
6688
6688
|
|
|
6689
6689
|
// src/remote-turn-coordinator.ts
|
|
6690
6690
|
var MAX_RECENTLY_SETTLED_RUN_IDS = 256;
|
|
6691
|
+
var TRAILING_USAGE_GRACE_MS = 100;
|
|
6691
6692
|
|
|
6692
6693
|
class RemoteTurnCoordinator {
|
|
6693
6694
|
label;
|
|
@@ -6730,6 +6731,9 @@ class RemoteTurnCoordinator {
|
|
|
6730
6731
|
observedTurnEvidence: false,
|
|
6731
6732
|
observedRequiresApprovalStop: false,
|
|
6732
6733
|
pendingTerminal: null,
|
|
6734
|
+
pendingTerminalTimeout: null,
|
|
6735
|
+
deferredMessages: [],
|
|
6736
|
+
deferredTurnEvidence: false,
|
|
6733
6737
|
abortRequested: false,
|
|
6734
6738
|
timeout: null
|
|
6735
6739
|
};
|
|
@@ -6743,6 +6747,8 @@ class RemoteTurnCoordinator {
|
|
|
6743
6747
|
removeTrackedTurn(turn) {
|
|
6744
6748
|
if (turn.timeout)
|
|
6745
6749
|
clearTimeout(turn.timeout);
|
|
6750
|
+
if (turn.pendingTerminalTimeout)
|
|
6751
|
+
clearTimeout(turn.pendingTerminalTimeout);
|
|
6746
6752
|
if (this.activeTurn === turn) {
|
|
6747
6753
|
this.activeTurn = null;
|
|
6748
6754
|
return;
|
|
@@ -6773,6 +6779,29 @@ class RemoteTurnCoordinator {
|
|
|
6773
6779
|
this.enqueue(sdkMessage2);
|
|
6774
6780
|
return;
|
|
6775
6781
|
}
|
|
6782
|
+
const deferredDelta = streamDeltaRecord(message);
|
|
6783
|
+
const deferredMessageType = deferredDelta ? streamDeltaMessageType(deferredDelta) : undefined;
|
|
6784
|
+
const trailingUsageTurn = this.activeTurn?.pendingTerminalTimeout ? this.activeTurn : null;
|
|
6785
|
+
if (trailingUsageTurn) {
|
|
6786
|
+
const statusRunIds = message.type === "update_loop_status" ? loopStatusRunIds(message) : [];
|
|
6787
|
+
const belongsToTerminalTurn = message.type === "update_loop_status" && statusRunIds.length > 0 && statusRunIds.every((runId) => trailingUsageTurn.runIds.has(runId));
|
|
6788
|
+
if (belongsToTerminalTurn) {
|
|
6789
|
+
this.handleLoopStatusMessage(message);
|
|
6790
|
+
return;
|
|
6791
|
+
}
|
|
6792
|
+
if (message.type === "update_loop_status" && statusRunIds.length === 0) {
|
|
6793
|
+
trailingUsageTurn.deferredMessages.push(message);
|
|
6794
|
+
return;
|
|
6795
|
+
}
|
|
6796
|
+
const isTurnScoped = deferredDelta !== null && deferredMessageType !== "ping" || message.type === "update_loop_status" || turnFinishedRecord(message) !== null;
|
|
6797
|
+
if (isTurnScoped && deferredMessageType !== "usage_statistics" || deferredMessageType === "usage_statistics" && trailingUsageTurn.deferredTurnEvidence) {
|
|
6798
|
+
trailingUsageTurn.deferredMessages.push(message);
|
|
6799
|
+
if (isTurnScoped && deferredMessageType !== "usage_statistics") {
|
|
6800
|
+
trailingUsageTurn.deferredTurnEvidence = true;
|
|
6801
|
+
}
|
|
6802
|
+
return;
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6776
6805
|
if (message.type === "update_loop_status") {
|
|
6777
6806
|
this.handleLoopStatusMessage(message);
|
|
6778
6807
|
return;
|
|
@@ -6785,7 +6814,8 @@ class RemoteTurnCoordinator {
|
|
|
6785
6814
|
const delta = streamDeltaRecord(message);
|
|
6786
6815
|
if (!delta)
|
|
6787
6816
|
return;
|
|
6788
|
-
const
|
|
6817
|
+
const messageType = streamDeltaMessageType(delta);
|
|
6818
|
+
const active = messageType === "usage_statistics" || messageType === "stop_reason" ? this.activeTurn : this.activateNextTurnFromProtocol();
|
|
6789
6819
|
if (active) {
|
|
6790
6820
|
active.observedTurnEvidence = true;
|
|
6791
6821
|
const runId = streamDeltaRunId(delta);
|
|
@@ -6810,13 +6840,18 @@ class RemoteTurnCoordinator {
|
|
|
6810
6840
|
closeWithError(detail) {
|
|
6811
6841
|
if (this.closed)
|
|
6812
6842
|
return;
|
|
6843
|
+
let completedCanonicalTurn = false;
|
|
6844
|
+
while (this.activeTurn?.pendingTerminal && this.activeTurn.pendingTerminalTimeout) {
|
|
6845
|
+
this.completeActiveTurn(this.activeTurn.pendingTerminal);
|
|
6846
|
+
completedCanonicalTurn = true;
|
|
6847
|
+
}
|
|
6813
6848
|
const active = this.activeTurn;
|
|
6814
6849
|
if (active) {
|
|
6815
6850
|
this.failTurn(active, detail, {
|
|
6816
6851
|
errorCode: "stream_closed",
|
|
6817
6852
|
recoverable: true
|
|
6818
6853
|
});
|
|
6819
|
-
} else {
|
|
6854
|
+
} else if (!completedCanonicalTurn) {
|
|
6820
6855
|
this.enqueue({
|
|
6821
6856
|
type: "error",
|
|
6822
6857
|
message: detail,
|
|
@@ -6834,9 +6869,14 @@ class RemoteTurnCoordinator {
|
|
|
6834
6869
|
this.closed = true;
|
|
6835
6870
|
if (this.activeTurn?.timeout)
|
|
6836
6871
|
clearTimeout(this.activeTurn.timeout);
|
|
6872
|
+
if (this.activeTurn?.pendingTerminalTimeout) {
|
|
6873
|
+
clearTimeout(this.activeTurn.pendingTerminalTimeout);
|
|
6874
|
+
}
|
|
6837
6875
|
for (const turn of this.pendingTurns) {
|
|
6838
6876
|
if (turn.timeout)
|
|
6839
6877
|
clearTimeout(turn.timeout);
|
|
6878
|
+
if (turn.pendingTerminalTimeout)
|
|
6879
|
+
clearTimeout(turn.pendingTerminalTimeout);
|
|
6840
6880
|
}
|
|
6841
6881
|
this.activeTurn = null;
|
|
6842
6882
|
this.pendingTurns.length = 0;
|
|
@@ -6892,9 +6932,17 @@ class RemoteTurnCoordinator {
|
|
|
6892
6932
|
clearTimeout(active.timeout);
|
|
6893
6933
|
active.timeout = null;
|
|
6894
6934
|
}
|
|
6935
|
+
if (active.pendingTerminalTimeout) {
|
|
6936
|
+
clearTimeout(active.pendingTerminalTimeout);
|
|
6937
|
+
active.pendingTerminalTimeout = null;
|
|
6938
|
+
}
|
|
6939
|
+
const deferredMessages = active.deferredMessages.splice(0);
|
|
6895
6940
|
this.rememberSettledRunIds(active.runIds);
|
|
6896
6941
|
this.enqueue(this.resultFromTurn(turn, active));
|
|
6897
6942
|
this.activeTurn = null;
|
|
6943
|
+
for (const message of deferredMessages) {
|
|
6944
|
+
this.handleProtocolMessage(message, active.runtime);
|
|
6945
|
+
}
|
|
6898
6946
|
}
|
|
6899
6947
|
rememberSettledRunIds(runIds) {
|
|
6900
6948
|
for (const runId of runIds) {
|
|
@@ -6959,11 +7007,13 @@ class RemoteTurnCoordinator {
|
|
|
6959
7007
|
}
|
|
6960
7008
|
}
|
|
6961
7009
|
handleTurnFinished(finished) {
|
|
6962
|
-
|
|
6963
|
-
if (!active || !finished.runId)
|
|
7010
|
+
if (!finished.runId)
|
|
6964
7011
|
return;
|
|
6965
7012
|
if (this.settledRunIds.has(finished.runId))
|
|
6966
7013
|
return;
|
|
7014
|
+
const active = this.activeTurn ?? this.activateNextTurnFromProtocol();
|
|
7015
|
+
if (!active)
|
|
7016
|
+
return;
|
|
6967
7017
|
if (active.runIds.size > 0 && !active.runIds.has(finished.runId)) {
|
|
6968
7018
|
return;
|
|
6969
7019
|
}
|
|
@@ -6991,6 +7041,11 @@ class RemoteTurnCoordinator {
|
|
|
6991
7041
|
};
|
|
6992
7042
|
if (active.pendingTerminal) {
|
|
6993
7043
|
active.pendingTerminal = terminal;
|
|
7044
|
+
if (active.timeout) {
|
|
7045
|
+
clearTimeout(active.timeout);
|
|
7046
|
+
active.timeout = null;
|
|
7047
|
+
}
|
|
7048
|
+
this.schedulePendingTerminal(active);
|
|
6994
7049
|
return;
|
|
6995
7050
|
}
|
|
6996
7051
|
this.completeActiveTurn(terminal);
|
|
@@ -7014,7 +7069,9 @@ class RemoteTurnCoordinator {
|
|
|
7014
7069
|
return;
|
|
7015
7070
|
}
|
|
7016
7071
|
if (messageType === "usage_statistics" && active.pendingTerminal) {
|
|
7017
|
-
|
|
7072
|
+
if (active.pendingTerminalTimeout) {
|
|
7073
|
+
this.completeActiveTurn(active.pendingTerminal);
|
|
7074
|
+
}
|
|
7018
7075
|
return;
|
|
7019
7076
|
}
|
|
7020
7077
|
if (sdkMessage?.type === "error") {
|
|
@@ -7028,6 +7085,16 @@ class RemoteTurnCoordinator {
|
|
|
7028
7085
|
});
|
|
7029
7086
|
}
|
|
7030
7087
|
}
|
|
7088
|
+
schedulePendingTerminal(active) {
|
|
7089
|
+
if (active.pendingTerminalTimeout)
|
|
7090
|
+
return;
|
|
7091
|
+
active.pendingTerminalTimeout = setTimeout(() => {
|
|
7092
|
+
if (this.activeTurn !== active || !active.pendingTerminal)
|
|
7093
|
+
return;
|
|
7094
|
+
this.completeActiveTurn(active.pendingTerminal);
|
|
7095
|
+
}, TRAILING_USAGE_GRACE_MS);
|
|
7096
|
+
active.pendingTerminalTimeout.unref?.();
|
|
7097
|
+
}
|
|
7031
7098
|
transformStreamDelta(delta) {
|
|
7032
7099
|
const messageType = typeof delta.message_type === "string" ? delta.message_type : undefined;
|
|
7033
7100
|
const runId = typeof delta.run_id === "string" ? delta.run_id : undefined;
|
|
@@ -8880,6 +8947,7 @@ var MAX_TTL_MINUTES = 60;
|
|
|
8880
8947
|
var MAX_GITHUB_REPOSITORIES = 10;
|
|
8881
8948
|
var GITHUB_OWNER_PATTERN = /^[A-Za-z0-9-]+$/;
|
|
8882
8949
|
var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
8950
|
+
var GITHUB_COMMIT_PATTERN = /^[0-9a-fA-F]{40}$/;
|
|
8883
8951
|
function validatePositiveInteger2(value, name) {
|
|
8884
8952
|
if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
|
|
8885
8953
|
throw new Error(`Invalid ${name}. Expected a positive integer.`);
|
|
@@ -8914,6 +8982,9 @@ function validateCloudSandboxOptions(options, name) {
|
|
|
8914
8982
|
if (typeof repository.repo !== "string" || !GITHUB_REPOSITORY_PATTERN.test(repository.repo)) {
|
|
8915
8983
|
throw new Error(`Invalid ${name}.githubRepositories[${index}].repo.`);
|
|
8916
8984
|
}
|
|
8985
|
+
if (repository.commit !== undefined && (typeof repository.commit !== "string" || !GITHUB_COMMIT_PATTERN.test(repository.commit))) {
|
|
8986
|
+
throw new Error(`Invalid ${name}.githubRepositories[${index}].commit. Expected a full Git commit SHA.`);
|
|
8987
|
+
}
|
|
8917
8988
|
}
|
|
8918
8989
|
}
|
|
8919
8990
|
if (options.terminateOnClose !== undefined && typeof options.terminateOnClose !== "boolean") {
|
|
@@ -28756,4 +28827,4 @@ export {
|
|
|
28756
28827
|
CloudManagedSandboxExpiredError
|
|
28757
28828
|
};
|
|
28758
28829
|
|
|
28759
|
-
//# debugId=
|
|
28830
|
+
//# debugId=4E39B80847C7A8D464756E2164756E21
|