@mondaydotcomorg/atp-runtime 0.18.2 → 0.18.4-rc.1
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/approval/index.js +2 -1
- package/dist/approval/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/replay.d.ts +75 -0
- package/dist/llm/replay.d.ts.map +1 -1
- package/dist/llm/replay.js +187 -5
- package/dist/llm/replay.js.map +1 -1
- package/package.json +1 -1
- package/src/approval/index.ts +2 -2
- package/src/index.ts +13 -0
- package/src/llm/index.ts +13 -0
- package/src/llm/replay.ts +239 -11
package/dist/approval/index.js
CHANGED
|
@@ -36,7 +36,8 @@ let ApprovalAPI = class ApprovalAPI {
|
|
|
36
36
|
if (cachedResult !== undefined) {
|
|
37
37
|
return cachedResult;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
const shouldPause = shouldPauseForClient();
|
|
40
|
+
if (shouldPause) {
|
|
40
41
|
pauseForCallback(CallbackType.APPROVAL, ApprovalOperation.REQUEST, {
|
|
41
42
|
message,
|
|
42
43
|
context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/approval/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MA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,OAAO,EAAE;YACR,WAAW,EAAE,wDAAwD;YACrE,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,yBAAyB;SAC/B;KACD,CAAC;;;;0CAsDD;AAnEI,WAAW;IADhB,UAAU,CAAC,UAAU,EAAE,yEAAyE,CAAC;GAC5F,WAAW,CAoEhB;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from './metadata/index.js';
|
|
|
9
9
|
export { log, initializeLogger, shutdownLogger } from './log/index.js';
|
|
10
10
|
export type { LogLevel, LoggerConfig, Logger } from './log/index.js';
|
|
11
11
|
export { GENERATED_METADATA } from './metadata/generated.js';
|
|
12
|
-
export { setClientLLMCallback, setPauseForClient, setReplayMode, getCallSequenceNumber, } from './llm/index.js';
|
|
12
|
+
export { initializeExecutionState, setClientLLMCallback, setPauseForClient, shouldPauseForClient, setReplayMode, getCallSequenceNumber, isReplayMode, storeAPICallResult, getAPICallResults, clearAPICallResults, setAPIResultCache, getAPIResultFromCache, storeAPIResultInCache, cleanupExecutionState, cleanupOldExecutionStates, resetAllExecutionState, getExecutionStateStats, } from './llm/index.js';
|
|
13
13
|
export { initializeCache } from './cache/index.js';
|
|
14
14
|
export { initializeApproval } from './approval/index.js';
|
|
15
15
|
export { setProgressCallback } from './progress/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE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C;AAE/F,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export * from './registry.js';
|
|
|
8
8
|
export * from './metadata/index.js';
|
|
9
9
|
export { log, initializeLogger, shutdownLogger } from './log/index.js';
|
|
10
10
|
export { GENERATED_METADATA } from './metadata/generated.js';
|
|
11
|
-
export { setClientLLMCallback, setPauseForClient, setReplayMode, getCallSequenceNumber, } from './llm/index.js';
|
|
11
|
+
export { initializeExecutionState, setClientLLMCallback, setPauseForClient, shouldPauseForClient, setReplayMode, getCallSequenceNumber, isReplayMode, storeAPICallResult, getAPICallResults, clearAPICallResults, setAPIResultCache, getAPIResultFromCache, storeAPIResultInCache, cleanupExecutionState, cleanupOldExecutionStates, resetAllExecutionState, getExecutionStateStats, } from './llm/index.js';
|
|
12
12
|
export { initializeCache } from './cache/index.js';
|
|
13
13
|
export { initializeApproval } from './approval/index.js';
|
|
14
14
|
export { setProgressCallback } from './progress/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACN,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,kBAAkB,CAAC"}
|
package/dist/llm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LLMCallOptions, LLMExtractOptions, LLMClassifyOptions } from './types';
|
|
2
2
|
export type { LLMCallOptions, LLMExtractOptions, LLMClassifyOptions, ClientLLMCallback, } from './types';
|
|
3
3
|
export { setClientLLMCallback, getClientLLMCallback } from './callback.js';
|
|
4
|
-
export { setPauseForClient, setReplayMode, getCallSequenceNumber, nextSequenceNumber, getCachedResult, runInExecutionContext, setCurrentExecutionId, clearCurrentExecutionId, } from './replay.js';
|
|
4
|
+
export { initializeExecutionState, setPauseForClient, shouldPauseForClient, setReplayMode, getCallSequenceNumber, nextSequenceNumber, getCachedResult, isReplayMode, runInExecutionContext, setCurrentExecutionId, clearCurrentExecutionId, storeAPICallResult, getAPICallResults, clearAPICallResults, setAPIResultCache, getAPIResultFromCache, storeAPIResultInCache, cleanupExecutionState, cleanupOldExecutionStates, resetAllExecutionState, getExecutionStateStats, } from './replay.js';
|
|
5
5
|
/**
|
|
6
6
|
* LLM Runtime API
|
|
7
7
|
*
|
package/dist/llm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAErF,YAAY,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAErF,YAAY,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EACN,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,cAIM,MAAM;IACX;;;OAGG;IAOG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAepD;;;OAGG;IAOG,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC;IAgBxD;;;OAGG;IAOG,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;CAe5D;AAED,eAAO,MAAM,GAAG,QAAe,CAAC"}
|
package/dist/llm/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import { pauseForCallback, CallbackType, LLMOperation } from '../pause/index.js'
|
|
|
19
19
|
import { RuntimeAPI, RuntimeMethod } from '../metadata/decorators.js';
|
|
20
20
|
import { nextSequenceNumber, getCachedResult } from './replay.js';
|
|
21
21
|
export { setClientLLMCallback, getClientLLMCallback } from './callback.js';
|
|
22
|
-
export { setPauseForClient, setReplayMode, getCallSequenceNumber, nextSequenceNumber, getCachedResult, runInExecutionContext, setCurrentExecutionId, clearCurrentExecutionId, } from './replay.js';
|
|
22
|
+
export { initializeExecutionState, setPauseForClient, shouldPauseForClient, setReplayMode, getCallSequenceNumber, nextSequenceNumber, getCachedResult, isReplayMode, runInExecutionContext, setCurrentExecutionId, clearCurrentExecutionId, storeAPICallResult, getAPICallResults, clearAPICallResults, setAPIResultCache, getAPIResultFromCache, storeAPIResultInCache, cleanupExecutionState, cleanupOldExecutionStates, resetAllExecutionState, getExecutionStateStats, } from './replay.js';
|
|
23
23
|
/**
|
|
24
24
|
* LLM Runtime API
|
|
25
25
|
*
|
package/dist/llm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAgB,MAAM,aAAa,CAAC;AAShF,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAgB,MAAM,aAAa,CAAC;AAShF,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EACN,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,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AC,eAAe,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,YAAsB,CAAC;QAC/B,CAAC;QAED,gBAAgB,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE;YACzD,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,OAAO;YACP,cAAc,EAAE,eAAe;SAC/B,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAlEM;IANL,aAAa,CAAC,gCAAgC,EAAE;QAChD,OAAO,EAAE;YACR,WAAW,EAAE,mCAAmC;YAChD,IAAI,EAAE,gBAAgB;SACtB;KACD,CAAC;;;;kCAcD;AAYK;IANL,aAAa,CAAC,gDAAgD,EAAE;QAChE,OAAO,EAAE;YACR,WAAW,EAAE,qCAAqC;YAClD,IAAI,EAAE,mBAAmB;SACzB;KACD,CAAC;;;;qCAeD;AAYK;IANL,aAAa,CAAC,mDAAmD,EAAE;QACnE,OAAO,EAAE;YACR,WAAW,EAAE,wCAAwC;YACrD,IAAI,EAAE,oBAAoB;SAC1B;KACD,CAAC;;;;sCAeD;AA5EI,MAAM;IAJX,UAAU,CACV,KAAK,EACL,+FAA+F,CAC/F;GACK,MAAM,CA6EX;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/llm/replay.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution-scoped state
|
|
3
|
+
*/
|
|
4
|
+
interface APICallRecord {
|
|
5
|
+
type: string;
|
|
6
|
+
operation: string;
|
|
7
|
+
payload: unknown;
|
|
8
|
+
result: unknown;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
sequenceNumber: number;
|
|
11
|
+
}
|
|
1
12
|
/**
|
|
2
13
|
* Sets the current execution ID for this call
|
|
3
14
|
* Called by executor before each runtime API invocation
|
|
@@ -8,6 +19,11 @@ export declare function setCurrentExecutionId(executionId: string): void;
|
|
|
8
19
|
* Called by executor after each runtime API invocation
|
|
9
20
|
*/
|
|
10
21
|
export declare function clearCurrentExecutionId(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Initialize execution state with correct values at execution start
|
|
24
|
+
* This must be called before any state access to ensure correct pause mode
|
|
25
|
+
*/
|
|
26
|
+
export declare function initializeExecutionState(shouldPause: boolean): void;
|
|
11
27
|
/**
|
|
12
28
|
* Runs a function within an execution context
|
|
13
29
|
* @param executionId - Unique ID for this execution
|
|
@@ -44,4 +60,63 @@ export declare function getCachedResult(sequenceNumber: number): unknown | undef
|
|
|
44
60
|
* Check if we're in replay mode
|
|
45
61
|
*/
|
|
46
62
|
export declare function isReplayMode(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Store an API call result during execution
|
|
65
|
+
* This is used to track server-side API calls so they can be cached on resume
|
|
66
|
+
*/
|
|
67
|
+
export declare function storeAPICallResult(record: {
|
|
68
|
+
type: string;
|
|
69
|
+
operation: string;
|
|
70
|
+
payload: unknown;
|
|
71
|
+
result: unknown;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
sequenceNumber: number;
|
|
74
|
+
}): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get all API call results tracked during this execution
|
|
77
|
+
* Used when building callback history on pause
|
|
78
|
+
*/
|
|
79
|
+
export declare function getAPICallResults(): APICallRecord[];
|
|
80
|
+
/**
|
|
81
|
+
* Clear API call results (used when execution completes or fails)
|
|
82
|
+
*/
|
|
83
|
+
export declare function clearAPICallResults(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Set up API result cache for resume (operation-based, not sequence-based)
|
|
86
|
+
* This allows API calls to find their cached results even if execution order changes
|
|
87
|
+
*/
|
|
88
|
+
export declare function setAPIResultCache(cache: Map<string, unknown> | undefined): void;
|
|
89
|
+
/**
|
|
90
|
+
* Get API result from cache by operation name
|
|
91
|
+
*/
|
|
92
|
+
export declare function getAPIResultFromCache(operation: string): unknown | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Store API result in cache by operation name (for initial execution)
|
|
95
|
+
*/
|
|
96
|
+
export declare function storeAPIResultInCache(operation: string, result: unknown): void;
|
|
97
|
+
/**
|
|
98
|
+
* Cleanup a specific execution's state
|
|
99
|
+
* This should be called when an execution completes, fails, or is no longer needed
|
|
100
|
+
*/
|
|
101
|
+
export declare function cleanupExecutionState(executionId: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Cleanup old execution states to prevent memory leaks
|
|
104
|
+
* Removes states older than the specified max age (default: 1 hour)
|
|
105
|
+
*/
|
|
106
|
+
export declare function cleanupOldExecutionStates(maxAgeMs?: number): number;
|
|
107
|
+
/**
|
|
108
|
+
* Reset ALL execution state - for testing purposes only
|
|
109
|
+
* WARNING: This will clear all execution states, breaking any in-flight executions
|
|
110
|
+
*/
|
|
111
|
+
export declare function resetAllExecutionState(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Get execution state statistics - for monitoring/debugging
|
|
114
|
+
*/
|
|
115
|
+
export declare function getExecutionStateStats(): {
|
|
116
|
+
totalStates: number;
|
|
117
|
+
oldestStateAge: number | null;
|
|
118
|
+
newestStateAge: number | null;
|
|
119
|
+
executionIds: string[];
|
|
120
|
+
};
|
|
121
|
+
export {};
|
|
47
122
|
//# sourceMappingURL=replay.d.ts.map
|
package/dist/llm/replay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/llm/replay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/llm/replay.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,UAAU,aAAa;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,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;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CAG/E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAG5E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAM9E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAK/D;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,GAAE,MAAgB,GAAG,MAAM,CAa5E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,EAAE,CAAC;CACvB,CAsBA"}
|
package/dist/llm/replay.js
CHANGED
|
@@ -30,7 +30,8 @@ export function clearCurrentExecutionId() {
|
|
|
30
30
|
currentExecutionId = null;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Gets the current execution state
|
|
33
|
+
* Gets the current execution state
|
|
34
|
+
* Note: State must be initialized before calling this. Use initializeExecutionState() first.
|
|
34
35
|
*/
|
|
35
36
|
function getCurrentState() {
|
|
36
37
|
let executionId = currentExecutionId;
|
|
@@ -40,17 +41,60 @@ function getCurrentState() {
|
|
|
40
41
|
if (!executionId) {
|
|
41
42
|
throw new Error('No execution context set. Executor must call setCurrentExecutionId() before runtime API calls.');
|
|
42
43
|
}
|
|
44
|
+
console.log(`[STATE] getCurrentState: executionId=${executionId}, hasState=${executionStates.has(executionId)}, totalStates=${executionStates.size}, stateKeys=${Array.from(executionStates.keys())}`);
|
|
43
45
|
let state = executionStates.get(executionId);
|
|
44
46
|
if (!state) {
|
|
47
|
+
// State should have been initialized explicitly at execution start
|
|
48
|
+
// Create it now with a safe default to prevent crashes
|
|
49
|
+
console.warn('[STATE] State not initialized, creating with default. This should not happen.', { executionId });
|
|
45
50
|
state = {
|
|
46
51
|
shouldPauseForClient: false,
|
|
47
52
|
replayResults: undefined,
|
|
48
53
|
callSequenceNumber: 0,
|
|
54
|
+
apiCallResults: [],
|
|
55
|
+
apiResultCache: undefined,
|
|
56
|
+
createdAt: Date.now(),
|
|
49
57
|
};
|
|
50
58
|
executionStates.set(executionId, state);
|
|
51
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
console.log(`[STATE] Found existing state: shouldPause=${state.shouldPauseForClient}, hasReplay=${!!state.replayResults}, seqNum=${state.callSequenceNumber}`);
|
|
62
|
+
}
|
|
52
63
|
return state;
|
|
53
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Initialize execution state with correct values at execution start
|
|
67
|
+
* This must be called before any state access to ensure correct pause mode
|
|
68
|
+
*/
|
|
69
|
+
export function initializeExecutionState(shouldPause) {
|
|
70
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
71
|
+
if (!executionId) {
|
|
72
|
+
throw new Error('No execution context set. Executor must call setCurrentExecutionId() before initializeExecutionState().');
|
|
73
|
+
}
|
|
74
|
+
console.log(`[INIT] initializeExecutionState called: executionId=${executionId}, shouldPause=${shouldPause}, existingState=${executionStates.has(executionId)}`);
|
|
75
|
+
const existingState = executionStates.get(executionId);
|
|
76
|
+
if (existingState) {
|
|
77
|
+
existingState.shouldPauseForClient = shouldPause;
|
|
78
|
+
if (!existingState.apiCallResults) {
|
|
79
|
+
existingState.apiCallResults = [];
|
|
80
|
+
}
|
|
81
|
+
if (!existingState.apiResultCache) {
|
|
82
|
+
existingState.apiResultCache = undefined;
|
|
83
|
+
}
|
|
84
|
+
console.log(`[INIT] Preserving existing state: replaySize=${existingState.replayResults?.size || 0}, counter=${existingState.callSequenceNumber}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const state = {
|
|
88
|
+
shouldPauseForClient: shouldPause,
|
|
89
|
+
replayResults: undefined,
|
|
90
|
+
callSequenceNumber: 0,
|
|
91
|
+
apiCallResults: [],
|
|
92
|
+
apiResultCache: undefined,
|
|
93
|
+
createdAt: Date.now(),
|
|
94
|
+
};
|
|
95
|
+
console.log(`[INIT] Creating new state: shouldPause=${shouldPause}`);
|
|
96
|
+
executionStates.set(executionId, state);
|
|
97
|
+
}
|
|
54
98
|
/**
|
|
55
99
|
* Runs a function within an execution context
|
|
56
100
|
* @param executionId - Unique ID for this execution
|
|
@@ -64,45 +108,77 @@ export function runInExecutionContext(executionId, fn) {
|
|
|
64
108
|
* @param pause - If true, throws PauseExecutionError instead of calling callback
|
|
65
109
|
*/
|
|
66
110
|
export function setPauseForClient(pause) {
|
|
67
|
-
|
|
111
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
112
|
+
if (!executionId) {
|
|
113
|
+
throw new Error('No execution context set. Executor must call setCurrentExecutionId() before setPauseForClient().');
|
|
114
|
+
}
|
|
115
|
+
const state = executionStates.get(executionId);
|
|
116
|
+
if (!state) {
|
|
117
|
+
throw new Error('Execution state not initialized. Call initializeExecutionState() first.');
|
|
118
|
+
}
|
|
119
|
+
state.shouldPauseForClient = pause;
|
|
68
120
|
}
|
|
69
121
|
/**
|
|
70
122
|
* Checks if should pause for client
|
|
71
123
|
*/
|
|
72
124
|
export function shouldPauseForClient() {
|
|
73
|
-
|
|
125
|
+
const state = getCurrentState();
|
|
126
|
+
return state.shouldPauseForClient;
|
|
74
127
|
}
|
|
75
128
|
/**
|
|
76
129
|
* Sets up replay mode for resumption
|
|
77
130
|
* @param results - Map of sequence number to result for replaying callbacks
|
|
78
131
|
*/
|
|
79
132
|
export function setReplayMode(results) {
|
|
133
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
134
|
+
console.log(`[REPLAY] setReplayMode called: executionId=${executionId}, replaySize=${results?.size || 0}, replayKeys=${results ? Array.from(results.keys()) : []}`);
|
|
80
135
|
const state = getCurrentState();
|
|
136
|
+
// Store replay results
|
|
137
|
+
const oldSize = state.replayResults?.size || 0;
|
|
81
138
|
state.replayResults = results;
|
|
139
|
+
// Always reset counter when setting replay mode
|
|
140
|
+
// - When entering replay mode with cached results: start from 0 to match first call
|
|
141
|
+
// - When clearing replay mode (results=undefined): reset to 0 for clean state
|
|
142
|
+
const oldCounter = state.callSequenceNumber;
|
|
82
143
|
state.callSequenceNumber = 0;
|
|
144
|
+
if (results && results.size > 0) {
|
|
145
|
+
console.log(`[REPLAY] Entering replay mode: ${oldCounter} -> 0 (have ${results.size} cached results)`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
console.log(`[REPLAY] Clearing replay mode: ${oldCounter} -> 0`);
|
|
149
|
+
}
|
|
150
|
+
console.log(`[REPLAY] setReplayMode completed: oldSize=${oldSize}, newSize=${state.replayResults?.size || 0}, callSequenceNumber=${state.callSequenceNumber}`);
|
|
83
151
|
}
|
|
84
152
|
/**
|
|
85
153
|
* Gets current call sequence number
|
|
86
154
|
*/
|
|
87
155
|
export function getCallSequenceNumber() {
|
|
88
|
-
|
|
156
|
+
const state = getCurrentState();
|
|
157
|
+
console.log(`[GET_SEQ] getCallSequenceNumber called: returning ${state.callSequenceNumber}, hasReplay=${!!state.replayResults}, replaySize=${state.replayResults?.size || 0}`);
|
|
158
|
+
return state.callSequenceNumber;
|
|
89
159
|
}
|
|
90
160
|
/**
|
|
91
161
|
* Increments and returns the next sequence number
|
|
92
162
|
*/
|
|
93
163
|
export function nextSequenceNumber() {
|
|
94
164
|
const state = getCurrentState();
|
|
95
|
-
|
|
165
|
+
const current = state.callSequenceNumber;
|
|
166
|
+
state.callSequenceNumber++;
|
|
167
|
+
console.log(`[SEQUENCE] nextSequenceNumber: returning ${current}, next will be ${state.callSequenceNumber}, isReplay=${state.replayResults !== undefined}, replaySize=${state.replayResults?.size || 0}`);
|
|
168
|
+
return current;
|
|
96
169
|
}
|
|
97
170
|
/**
|
|
98
171
|
* Check if we have a cached result for the current sequence
|
|
99
172
|
*/
|
|
100
173
|
export function getCachedResult(sequenceNumber) {
|
|
101
174
|
const state = getCurrentState();
|
|
175
|
+
console.log(`[CACHE] getCachedResult(${sequenceNumber}): hasReplayResults=${!!state.replayResults}, replayKeys=${state.replayResults ? Array.from(state.replayResults.keys()) : []}`);
|
|
102
176
|
if (state.replayResults && state.replayResults.has(sequenceNumber)) {
|
|
103
177
|
const result = state.replayResults.get(sequenceNumber);
|
|
178
|
+
console.log(`[CACHE] Found cached result for sequence ${sequenceNumber}:`, JSON.stringify(result));
|
|
104
179
|
return result;
|
|
105
180
|
}
|
|
181
|
+
console.log(`[CACHE] No cached result for sequence ${sequenceNumber}`);
|
|
106
182
|
return undefined;
|
|
107
183
|
}
|
|
108
184
|
/**
|
|
@@ -111,4 +187,110 @@ export function getCachedResult(sequenceNumber) {
|
|
|
111
187
|
export function isReplayMode() {
|
|
112
188
|
return getCurrentState().replayResults !== undefined;
|
|
113
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Store an API call result during execution
|
|
192
|
+
* This is used to track server-side API calls so they can be cached on resume
|
|
193
|
+
*/
|
|
194
|
+
export function storeAPICallResult(record) {
|
|
195
|
+
const state = getCurrentState();
|
|
196
|
+
state.apiCallResults.push(record);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get all API call results tracked during this execution
|
|
200
|
+
* Used when building callback history on pause
|
|
201
|
+
*/
|
|
202
|
+
export function getAPICallResults() {
|
|
203
|
+
const state = getCurrentState();
|
|
204
|
+
return state.apiCallResults;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Clear API call results (used when execution completes or fails)
|
|
208
|
+
*/
|
|
209
|
+
export function clearAPICallResults() {
|
|
210
|
+
const state = getCurrentState();
|
|
211
|
+
state.apiCallResults = [];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Set up API result cache for resume (operation-based, not sequence-based)
|
|
215
|
+
* This allows API calls to find their cached results even if execution order changes
|
|
216
|
+
*/
|
|
217
|
+
export function setAPIResultCache(cache) {
|
|
218
|
+
const state = getCurrentState();
|
|
219
|
+
state.apiResultCache = cache;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get API result from cache by operation name
|
|
223
|
+
*/
|
|
224
|
+
export function getAPIResultFromCache(operation) {
|
|
225
|
+
const state = getCurrentState();
|
|
226
|
+
return state.apiResultCache?.get(operation);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Store API result in cache by operation name (for initial execution)
|
|
230
|
+
*/
|
|
231
|
+
export function storeAPIResultInCache(operation, result) {
|
|
232
|
+
const state = getCurrentState();
|
|
233
|
+
if (!state.apiResultCache) {
|
|
234
|
+
state.apiResultCache = new Map();
|
|
235
|
+
}
|
|
236
|
+
state.apiResultCache.set(operation, result);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Cleanup a specific execution's state
|
|
240
|
+
* This should be called when an execution completes, fails, or is no longer needed
|
|
241
|
+
*/
|
|
242
|
+
export function cleanupExecutionState(executionId) {
|
|
243
|
+
executionStates.delete(executionId);
|
|
244
|
+
if (currentExecutionId === executionId) {
|
|
245
|
+
currentExecutionId = null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Cleanup old execution states to prevent memory leaks
|
|
250
|
+
* Removes states older than the specified max age (default: 1 hour)
|
|
251
|
+
*/
|
|
252
|
+
export function cleanupOldExecutionStates(maxAgeMs = 3600000) {
|
|
253
|
+
const now = Date.now();
|
|
254
|
+
let cleaned = 0;
|
|
255
|
+
for (const [executionId, state] of executionStates.entries()) {
|
|
256
|
+
const age = now - state.createdAt;
|
|
257
|
+
if (age > maxAgeMs) {
|
|
258
|
+
executionStates.delete(executionId);
|
|
259
|
+
cleaned++;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return cleaned;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Reset ALL execution state - for testing purposes only
|
|
266
|
+
* WARNING: This will clear all execution states, breaking any in-flight executions
|
|
267
|
+
*/
|
|
268
|
+
export function resetAllExecutionState() {
|
|
269
|
+
executionStates.clear();
|
|
270
|
+
currentExecutionId = null;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get execution state statistics - for monitoring/debugging
|
|
274
|
+
*/
|
|
275
|
+
export function getExecutionStateStats() {
|
|
276
|
+
const now = Date.now();
|
|
277
|
+
const executionIds = Array.from(executionStates.keys());
|
|
278
|
+
let oldestAge = null;
|
|
279
|
+
let newestAge = null;
|
|
280
|
+
for (const state of executionStates.values()) {
|
|
281
|
+
const age = now - state.createdAt;
|
|
282
|
+
if (oldestAge === null || age > oldestAge) {
|
|
283
|
+
oldestAge = age;
|
|
284
|
+
}
|
|
285
|
+
if (newestAge === null || age < newestAge) {
|
|
286
|
+
newestAge = age;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
totalStates: executionStates.size,
|
|
291
|
+
oldestStateAge: oldestAge,
|
|
292
|
+
newestStateAge: newestAge,
|
|
293
|
+
executionIds,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
114
296
|
//# sourceMappingURL=replay.js.map
|
package/dist/llm/replay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/llm/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/llm/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAuBhD;;;GAGG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;AAE1D;;;GAGG;AACH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AC9D,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC;QAClC,IAAI,GAAG,GAAG,QAAQ,EAAE,CAAC;YACpB,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACpC,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACrC,eAAe,CAAC,KAAK,EAAE,CAAC;IACxB,kBAAkB,GAAG,IAAI,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAMrC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,IAAI,SAAS,GAAkB,IAAI,CAAC;IACpC,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,KAAK,MAAM,KAAK,IAAI,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9C,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC;QAClC,IAAI,SAAS,KAAK,IAAI,IAAI,GAAG,GAAG,SAAS,EAAE,CAAC;YAC3C,SAAS,GAAG,GAAG,CAAC;QACjB,CAAC;QACD,IAAI,SAAS,KAAK,IAAI,IAAI,GAAG,GAAG,SAAS,EAAE,CAAC;YAC3C,SAAS,GAAG,GAAG,CAAC;QACjB,CAAC;IACF,CAAC;IAED,OAAO;QACN,WAAW,EAAE,eAAe,CAAC,IAAI;QACjC,cAAc,EAAE,SAAS;QACzB,cAAc,EAAE,SAAS;QACzB,YAAY;KACZ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/approval/index.ts
CHANGED
|
@@ -44,7 +44,8 @@ class ApprovalAPI {
|
|
|
44
44
|
return cachedResult as ApprovalResponse;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const shouldPause = shouldPauseForClient();
|
|
48
|
+
if (shouldPause) {
|
|
48
49
|
pauseForCallback(CallbackType.APPROVAL, ApprovalOperation.REQUEST, {
|
|
49
50
|
message,
|
|
50
51
|
context,
|
|
@@ -53,7 +54,6 @@ class ApprovalAPI {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const handler = getApprovalHandler();
|
|
56
|
-
|
|
57
57
|
if (!handler) {
|
|
58
58
|
throw new Error(
|
|
59
59
|
'Approval handler not configured. Human approval is required but no handler is set.'
|
package/src/index.ts
CHANGED
|
@@ -13,10 +13,23 @@ export type { LogLevel, LoggerConfig, Logger } from './log/index.js';
|
|
|
13
13
|
export { GENERATED_METADATA } from './metadata/generated.js';
|
|
14
14
|
|
|
15
15
|
export {
|
|
16
|
+
initializeExecutionState,
|
|
16
17
|
setClientLLMCallback,
|
|
17
18
|
setPauseForClient,
|
|
19
|
+
shouldPauseForClient,
|
|
18
20
|
setReplayMode,
|
|
19
21
|
getCallSequenceNumber,
|
|
22
|
+
isReplayMode,
|
|
23
|
+
storeAPICallResult,
|
|
24
|
+
getAPICallResults,
|
|
25
|
+
clearAPICallResults,
|
|
26
|
+
setAPIResultCache,
|
|
27
|
+
getAPIResultFromCache,
|
|
28
|
+
storeAPIResultInCache,
|
|
29
|
+
cleanupExecutionState,
|
|
30
|
+
cleanupOldExecutionStates,
|
|
31
|
+
resetAllExecutionState,
|
|
32
|
+
getExecutionStateStats,
|
|
20
33
|
} from './llm/index.js';
|
|
21
34
|
export { initializeCache } from './cache/index.js';
|
|
22
35
|
export { initializeApproval } from './approval/index.js';
|
package/src/llm/index.ts
CHANGED
|
@@ -19,14 +19,27 @@ export type {
|
|
|
19
19
|
} from './types';
|
|
20
20
|
export { setClientLLMCallback, getClientLLMCallback } from './callback.js';
|
|
21
21
|
export {
|
|
22
|
+
initializeExecutionState,
|
|
22
23
|
setPauseForClient,
|
|
24
|
+
shouldPauseForClient,
|
|
23
25
|
setReplayMode,
|
|
24
26
|
getCallSequenceNumber,
|
|
25
27
|
nextSequenceNumber,
|
|
26
28
|
getCachedResult,
|
|
29
|
+
isReplayMode,
|
|
27
30
|
runInExecutionContext,
|
|
28
31
|
setCurrentExecutionId,
|
|
29
32
|
clearCurrentExecutionId,
|
|
33
|
+
storeAPICallResult,
|
|
34
|
+
getAPICallResults,
|
|
35
|
+
clearAPICallResults,
|
|
36
|
+
setAPIResultCache,
|
|
37
|
+
getAPIResultFromCache,
|
|
38
|
+
storeAPIResultInCache,
|
|
39
|
+
cleanupExecutionState,
|
|
40
|
+
cleanupOldExecutionStates,
|
|
41
|
+
resetAllExecutionState,
|
|
42
|
+
getExecutionStateStats,
|
|
30
43
|
} from './replay.js';
|
|
31
44
|
|
|
32
45
|
/**
|
package/src/llm/replay.ts
CHANGED
|
@@ -3,10 +3,22 @@ import { AsyncLocalStorage } from 'async_hooks';
|
|
|
3
3
|
/**
|
|
4
4
|
* Execution-scoped state
|
|
5
5
|
*/
|
|
6
|
+
interface APICallRecord {
|
|
7
|
+
type: string;
|
|
8
|
+
operation: string;
|
|
9
|
+
payload: unknown;
|
|
10
|
+
result: unknown;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
sequenceNumber: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
interface ExecutionState {
|
|
7
16
|
shouldPauseForClient: boolean;
|
|
8
17
|
replayResults: Map<number, unknown> | undefined;
|
|
9
18
|
callSequenceNumber: number;
|
|
19
|
+
apiCallResults: APICallRecord[];
|
|
20
|
+
apiResultCache: Map<string, unknown> | undefined;
|
|
21
|
+
createdAt: number;
|
|
10
22
|
}
|
|
11
23
|
|
|
12
24
|
/**
|
|
@@ -45,7 +57,8 @@ export function clearCurrentExecutionId(): void {
|
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
/**
|
|
48
|
-
* Gets the current execution state
|
|
60
|
+
* Gets the current execution state
|
|
61
|
+
* Note: State must be initialized before calling this. Use initializeExecutionState() first.
|
|
49
62
|
*/
|
|
50
63
|
function getCurrentState(): ExecutionState {
|
|
51
64
|
let executionId = currentExecutionId;
|
|
@@ -60,18 +73,65 @@ function getCurrentState(): ExecutionState {
|
|
|
60
73
|
);
|
|
61
74
|
}
|
|
62
75
|
|
|
76
|
+
console.log(`[STATE] getCurrentState: executionId=${executionId}, hasState=${executionStates.has(executionId)}, totalStates=${executionStates.size}, stateKeys=${Array.from(executionStates.keys())}`);
|
|
77
|
+
|
|
63
78
|
let state = executionStates.get(executionId);
|
|
64
79
|
if (!state) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
// State should have been initialized explicitly at execution start
|
|
81
|
+
// Create it now with a safe default to prevent crashes
|
|
82
|
+
console.warn('[STATE] State not initialized, creating with default. This should not happen.', { executionId });
|
|
83
|
+
state = {
|
|
84
|
+
shouldPauseForClient: false,
|
|
85
|
+
replayResults: undefined,
|
|
86
|
+
callSequenceNumber: 0,
|
|
87
|
+
apiCallResults: [],
|
|
88
|
+
apiResultCache: undefined,
|
|
89
|
+
createdAt: Date.now(),
|
|
90
|
+
};
|
|
91
|
+
executionStates.set(executionId, state);
|
|
92
|
+
} else {
|
|
93
|
+
console.log(`[STATE] Found existing state: shouldPause=${state.shouldPauseForClient}, hasReplay=${!!state.replayResults}, seqNum=${state.callSequenceNumber}`);
|
|
71
94
|
}
|
|
72
95
|
return state;
|
|
73
96
|
}
|
|
74
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Initialize execution state with correct values at execution start
|
|
100
|
+
* This must be called before any state access to ensure correct pause mode
|
|
101
|
+
*/
|
|
102
|
+
export function initializeExecutionState(shouldPause: boolean): void {
|
|
103
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
104
|
+
if (!executionId) {
|
|
105
|
+
throw new Error('No execution context set. Executor must call setCurrentExecutionId() before initializeExecutionState().');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(`[INIT] initializeExecutionState called: executionId=${executionId}, shouldPause=${shouldPause}, existingState=${executionStates.has(executionId)}`);
|
|
109
|
+
|
|
110
|
+
const existingState = executionStates.get(executionId);
|
|
111
|
+
if (existingState) {
|
|
112
|
+
existingState.shouldPauseForClient = shouldPause;
|
|
113
|
+
if (!existingState.apiCallResults) {
|
|
114
|
+
existingState.apiCallResults = [];
|
|
115
|
+
}
|
|
116
|
+
if (!existingState.apiResultCache) {
|
|
117
|
+
existingState.apiResultCache = undefined;
|
|
118
|
+
}
|
|
119
|
+
console.log(`[INIT] Preserving existing state: replaySize=${existingState.replayResults?.size || 0}, counter=${existingState.callSequenceNumber}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const state: ExecutionState = {
|
|
124
|
+
shouldPauseForClient: shouldPause,
|
|
125
|
+
replayResults: undefined,
|
|
126
|
+
callSequenceNumber: 0,
|
|
127
|
+
apiCallResults: [],
|
|
128
|
+
apiResultCache: undefined,
|
|
129
|
+
createdAt: Date.now(),
|
|
130
|
+
};
|
|
131
|
+
console.log(`[INIT] Creating new state: shouldPause=${shouldPause}`);
|
|
132
|
+
executionStates.set(executionId, state);
|
|
133
|
+
}
|
|
134
|
+
|
|
75
135
|
/**
|
|
76
136
|
* Runs a function within an execution context
|
|
77
137
|
* @param executionId - Unique ID for this execution
|
|
@@ -86,14 +146,24 @@ export function runInExecutionContext<T>(executionId: string, fn: () => T): T {
|
|
|
86
146
|
* @param pause - If true, throws PauseExecutionError instead of calling callback
|
|
87
147
|
*/
|
|
88
148
|
export function setPauseForClient(pause: boolean): void {
|
|
89
|
-
|
|
149
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
150
|
+
if (!executionId) {
|
|
151
|
+
throw new Error('No execution context set. Executor must call setCurrentExecutionId() before setPauseForClient().');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const state = executionStates.get(executionId);
|
|
155
|
+
if (!state) {
|
|
156
|
+
throw new Error('Execution state not initialized. Call initializeExecutionState() first.');
|
|
157
|
+
}
|
|
158
|
+
state.shouldPauseForClient = pause;
|
|
90
159
|
}
|
|
91
160
|
|
|
92
161
|
/**
|
|
93
162
|
* Checks if should pause for client
|
|
94
163
|
*/
|
|
95
164
|
export function shouldPauseForClient(): boolean {
|
|
96
|
-
|
|
165
|
+
const state = getCurrentState();
|
|
166
|
+
return state.shouldPauseForClient;
|
|
97
167
|
}
|
|
98
168
|
|
|
99
169
|
/**
|
|
@@ -101,16 +171,36 @@ export function shouldPauseForClient(): boolean {
|
|
|
101
171
|
* @param results - Map of sequence number to result for replaying callbacks
|
|
102
172
|
*/
|
|
103
173
|
export function setReplayMode(results: Map<number, unknown> | undefined): void {
|
|
174
|
+
const executionId = currentExecutionId || executionContext.getStore();
|
|
175
|
+
console.log(`[REPLAY] setReplayMode called: executionId=${executionId}, replaySize=${results?.size || 0}, replayKeys=${results ? Array.from(results.keys()) : []}`);
|
|
104
176
|
const state = getCurrentState();
|
|
177
|
+
|
|
178
|
+
// Store replay results
|
|
179
|
+
const oldSize = state.replayResults?.size || 0;
|
|
105
180
|
state.replayResults = results;
|
|
181
|
+
|
|
182
|
+
// Always reset counter when setting replay mode
|
|
183
|
+
// - When entering replay mode with cached results: start from 0 to match first call
|
|
184
|
+
// - When clearing replay mode (results=undefined): reset to 0 for clean state
|
|
185
|
+
const oldCounter = state.callSequenceNumber;
|
|
106
186
|
state.callSequenceNumber = 0;
|
|
187
|
+
|
|
188
|
+
if (results && results.size > 0) {
|
|
189
|
+
console.log(`[REPLAY] Entering replay mode: ${oldCounter} -> 0 (have ${results.size} cached results)`);
|
|
190
|
+
} else {
|
|
191
|
+
console.log(`[REPLAY] Clearing replay mode: ${oldCounter} -> 0`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
console.log(`[REPLAY] setReplayMode completed: oldSize=${oldSize}, newSize=${state.replayResults?.size || 0}, callSequenceNumber=${state.callSequenceNumber}`);
|
|
107
195
|
}
|
|
108
196
|
|
|
109
197
|
/**
|
|
110
198
|
* Gets current call sequence number
|
|
111
199
|
*/
|
|
112
200
|
export function getCallSequenceNumber(): number {
|
|
113
|
-
|
|
201
|
+
const state = getCurrentState();
|
|
202
|
+
console.log(`[GET_SEQ] getCallSequenceNumber called: returning ${state.callSequenceNumber}, hasReplay=${!!state.replayResults}, replaySize=${state.replayResults?.size || 0}`);
|
|
203
|
+
return state.callSequenceNumber;
|
|
114
204
|
}
|
|
115
205
|
|
|
116
206
|
/**
|
|
@@ -118,7 +208,10 @@ export function getCallSequenceNumber(): number {
|
|
|
118
208
|
*/
|
|
119
209
|
export function nextSequenceNumber(): number {
|
|
120
210
|
const state = getCurrentState();
|
|
121
|
-
|
|
211
|
+
const current = state.callSequenceNumber;
|
|
212
|
+
state.callSequenceNumber++;
|
|
213
|
+
console.log(`[SEQUENCE] nextSequenceNumber: returning ${current}, next will be ${state.callSequenceNumber}, isReplay=${state.replayResults !== undefined}, replaySize=${state.replayResults?.size || 0}`);
|
|
214
|
+
return current;
|
|
122
215
|
}
|
|
123
216
|
|
|
124
217
|
/**
|
|
@@ -126,10 +219,13 @@ export function nextSequenceNumber(): number {
|
|
|
126
219
|
*/
|
|
127
220
|
export function getCachedResult(sequenceNumber: number): unknown | undefined {
|
|
128
221
|
const state = getCurrentState();
|
|
222
|
+
console.log(`[CACHE] getCachedResult(${sequenceNumber}): hasReplayResults=${!!state.replayResults}, replayKeys=${state.replayResults ? Array.from(state.replayResults.keys()) : []}`);
|
|
129
223
|
if (state.replayResults && state.replayResults.has(sequenceNumber)) {
|
|
130
224
|
const result = state.replayResults.get(sequenceNumber);
|
|
225
|
+
console.log(`[CACHE] Found cached result for sequence ${sequenceNumber}:`, JSON.stringify(result));
|
|
131
226
|
return result;
|
|
132
227
|
}
|
|
228
|
+
console.log(`[CACHE] No cached result for sequence ${sequenceNumber}`);
|
|
133
229
|
return undefined;
|
|
134
230
|
}
|
|
135
231
|
|
|
@@ -139,3 +235,135 @@ export function getCachedResult(sequenceNumber: number): unknown | undefined {
|
|
|
139
235
|
export function isReplayMode(): boolean {
|
|
140
236
|
return getCurrentState().replayResults !== undefined;
|
|
141
237
|
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Store an API call result during execution
|
|
241
|
+
* This is used to track server-side API calls so they can be cached on resume
|
|
242
|
+
*/
|
|
243
|
+
export function storeAPICallResult(record: {
|
|
244
|
+
type: string;
|
|
245
|
+
operation: string;
|
|
246
|
+
payload: unknown;
|
|
247
|
+
result: unknown;
|
|
248
|
+
timestamp: number;
|
|
249
|
+
sequenceNumber: number;
|
|
250
|
+
}): void {
|
|
251
|
+
const state = getCurrentState();
|
|
252
|
+
state.apiCallResults.push(record);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Get all API call results tracked during this execution
|
|
257
|
+
* Used when building callback history on pause
|
|
258
|
+
*/
|
|
259
|
+
export function getAPICallResults(): APICallRecord[] {
|
|
260
|
+
const state = getCurrentState();
|
|
261
|
+
return state.apiCallResults;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Clear API call results (used when execution completes or fails)
|
|
266
|
+
*/
|
|
267
|
+
export function clearAPICallResults(): void {
|
|
268
|
+
const state = getCurrentState();
|
|
269
|
+
state.apiCallResults = [];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Set up API result cache for resume (operation-based, not sequence-based)
|
|
274
|
+
* This allows API calls to find their cached results even if execution order changes
|
|
275
|
+
*/
|
|
276
|
+
export function setAPIResultCache(cache: Map<string, unknown> | undefined): void {
|
|
277
|
+
const state = getCurrentState();
|
|
278
|
+
state.apiResultCache = cache;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get API result from cache by operation name
|
|
283
|
+
*/
|
|
284
|
+
export function getAPIResultFromCache(operation: string): unknown | undefined {
|
|
285
|
+
const state = getCurrentState();
|
|
286
|
+
return state.apiResultCache?.get(operation);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Store API result in cache by operation name (for initial execution)
|
|
291
|
+
*/
|
|
292
|
+
export function storeAPIResultInCache(operation: string, result: unknown): void {
|
|
293
|
+
const state = getCurrentState();
|
|
294
|
+
if (!state.apiResultCache) {
|
|
295
|
+
state.apiResultCache = new Map();
|
|
296
|
+
}
|
|
297
|
+
state.apiResultCache.set(operation, result);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Cleanup a specific execution's state
|
|
302
|
+
* This should be called when an execution completes, fails, or is no longer needed
|
|
303
|
+
*/
|
|
304
|
+
export function cleanupExecutionState(executionId: string): void {
|
|
305
|
+
executionStates.delete(executionId);
|
|
306
|
+
if (currentExecutionId === executionId) {
|
|
307
|
+
currentExecutionId = null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Cleanup old execution states to prevent memory leaks
|
|
313
|
+
* Removes states older than the specified max age (default: 1 hour)
|
|
314
|
+
*/
|
|
315
|
+
export function cleanupOldExecutionStates(maxAgeMs: number = 3600000): number {
|
|
316
|
+
const now = Date.now();
|
|
317
|
+
let cleaned = 0;
|
|
318
|
+
|
|
319
|
+
for (const [executionId, state] of executionStates.entries()) {
|
|
320
|
+
const age = now - state.createdAt;
|
|
321
|
+
if (age > maxAgeMs) {
|
|
322
|
+
executionStates.delete(executionId);
|
|
323
|
+
cleaned++;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return cleaned;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Reset ALL execution state - for testing purposes only
|
|
332
|
+
* WARNING: This will clear all execution states, breaking any in-flight executions
|
|
333
|
+
*/
|
|
334
|
+
export function resetAllExecutionState(): void {
|
|
335
|
+
executionStates.clear();
|
|
336
|
+
currentExecutionId = null;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Get execution state statistics - for monitoring/debugging
|
|
341
|
+
*/
|
|
342
|
+
export function getExecutionStateStats(): {
|
|
343
|
+
totalStates: number;
|
|
344
|
+
oldestStateAge: number | null;
|
|
345
|
+
newestStateAge: number | null;
|
|
346
|
+
executionIds: string[];
|
|
347
|
+
} {
|
|
348
|
+
const now = Date.now();
|
|
349
|
+
const executionIds = Array.from(executionStates.keys());
|
|
350
|
+
let oldestAge: number | null = null;
|
|
351
|
+
let newestAge: number | null = null;
|
|
352
|
+
|
|
353
|
+
for (const state of executionStates.values()) {
|
|
354
|
+
const age = now - state.createdAt;
|
|
355
|
+
if (oldestAge === null || age > oldestAge) {
|
|
356
|
+
oldestAge = age;
|
|
357
|
+
}
|
|
358
|
+
if (newestAge === null || age < newestAge) {
|
|
359
|
+
newestAge = age;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
totalStates: executionStates.size,
|
|
365
|
+
oldestStateAge: oldestAge,
|
|
366
|
+
newestStateAge: newestAge,
|
|
367
|
+
executionIds,
|
|
368
|
+
};
|
|
369
|
+
}
|