@acontext/acontext 0.1.7 → 0.1.8
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.
|
@@ -65,7 +65,8 @@ export interface ClaudeAgentStorageOptions {
|
|
|
65
65
|
* In the TS Claude Agent SDK, `session_id` is a flat field on system,
|
|
66
66
|
* result, stream_event, and other non-storable message types.
|
|
67
67
|
*
|
|
68
|
-
* Returns `null` when the message does not carry a session id
|
|
68
|
+
* Returns `null` when the message does not carry a session id or
|
|
69
|
+
* when the extracted value is not a valid UUID format.
|
|
69
70
|
*/
|
|
70
71
|
export declare function getSessionIdFromMessage(msg: Record<string, unknown>): string | null;
|
|
71
72
|
/**
|
|
@@ -54,13 +54,25 @@ function isReplayMessage(msg) {
|
|
|
54
54
|
// ---------------------------------------------------------------------------
|
|
55
55
|
// Helpers – session id extraction
|
|
56
56
|
// ---------------------------------------------------------------------------
|
|
57
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
58
|
+
/**
|
|
59
|
+
* Return `sid` if it is a valid UUID, otherwise warn and return `null`.
|
|
60
|
+
*/
|
|
61
|
+
function validateSessionId(sid) {
|
|
62
|
+
if (!UUID_RE.test(sid)) {
|
|
63
|
+
console.warn(`Ignoring non-UUID session_id from Claude stream: "${sid}"`);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return sid;
|
|
67
|
+
}
|
|
57
68
|
/**
|
|
58
69
|
* Try to extract a Claude session id from a non-storable message.
|
|
59
70
|
*
|
|
60
71
|
* In the TS Claude Agent SDK, `session_id` is a flat field on system,
|
|
61
72
|
* result, stream_event, and other non-storable message types.
|
|
62
73
|
*
|
|
63
|
-
* Returns `null` when the message does not carry a session id
|
|
74
|
+
* Returns `null` when the message does not carry a session id or
|
|
75
|
+
* when the extracted value is not a valid UUID format.
|
|
64
76
|
*/
|
|
65
77
|
function getSessionIdFromMessage(msg) {
|
|
66
78
|
// Only extract from non-storable messages
|
|
@@ -68,7 +80,10 @@ function getSessionIdFromMessage(msg) {
|
|
|
68
80
|
return null;
|
|
69
81
|
}
|
|
70
82
|
const sid = msg.session_id;
|
|
71
|
-
|
|
83
|
+
if (typeof sid !== 'string') {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return validateSessionId(sid);
|
|
72
87
|
}
|
|
73
88
|
// ---------------------------------------------------------------------------
|
|
74
89
|
// Helpers – block conversion (Claude SDK → Anthropic blob)
|
package/package.json
CHANGED