@acontext/acontext 0.1.7 → 0.1.9

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.
@@ -50,7 +50,7 @@ export interface ClaudeAgentStorageOptions {
50
50
  sessionId?: string;
51
51
  /** Optional user identifier passed to `sessions.create()`. */
52
52
  user?: string;
53
- /** Whether to store ThinkingBlock content as text blocks. Default: false. */
53
+ /** Whether to store ThinkingBlock content as native thinking blocks. Default: false. */
54
54
  includeThinking?: boolean;
55
55
  /**
56
56
  * Optional error callback invoked when `storeMessage` raises.
@@ -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
- return typeof sid === 'string' ? sid : null;
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)
@@ -112,7 +127,11 @@ function convertBlock(block, role, includeThinking) {
112
127
  if (!thinkingText) {
113
128
  return null; // empty thinking text
114
129
  }
115
- return { type: 'text', text: thinkingText };
130
+ return {
131
+ type: 'thinking',
132
+ thinking: thinkingText,
133
+ signature: block.signature ?? '',
134
+ };
116
135
  }
117
136
  case 'tool_use': {
118
137
  if (role !== 'assistant') {
@@ -11,6 +11,10 @@ export declare const AssetSchema: z.ZodObject<{
11
11
  size_b: z.ZodNumber;
12
12
  }, z.core.$strip>;
13
13
  export type Asset = z.infer<typeof AssetSchema>;
14
+ /**
15
+ * Message part schema.
16
+ * Part type is one of: 'text', 'image', 'audio', 'video', 'file', 'tool-call', 'tool-result', 'data', 'thinking'.
17
+ */
14
18
  export declare const PartSchema: z.ZodObject<{
15
19
  type: z.ZodString;
16
20
  text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -13,6 +13,10 @@ exports.AssetSchema = zod_1.z.object({
13
13
  mime: zod_1.z.string(),
14
14
  size_b: zod_1.z.number(),
15
15
  });
16
+ /**
17
+ * Message part schema.
18
+ * Part type is one of: 'text', 'image', 'audio', 'video', 'file', 'tool-call', 'tool-result', 'data', 'thinking'.
19
+ */
16
20
  exports.PartSchema = zod_1.z.object({
17
21
  type: zod_1.z.string(),
18
22
  text: zod_1.z.string().nullable().optional(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -55,4 +55,4 @@
55
55
  "dist",
56
56
  "README.md"
57
57
  ]
58
- }
58
+ }