Skip to content

Commit d327802

Browse files
committed
feat(sdk): Support ttl spec in thread creation
1 parent 46a7049 commit d327802

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

.changeset/add-threads-ttl.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@langchain/langgraph-sdk": minor
3+
---
4+
5+
Add TTL support to ThreadsClient in TypeScript to match Python SDK:
6+
7+
- `threads.create({ ttl })` now accepts either a number (minutes) or an object `{ ttl: number, strategy?: "delete" }`.
8+
- `threads.update(threadId, { ttl })` accepts the same forms.
9+
10+
Numeric TTL values are normalized to `{ ttl, strategy: "delete" }` in the request payload.
11+

libs/sdk/src/client.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,19 @@ export class ThreadsClient<
740740
supersteps?: Array<{
741741
updates: Array<{ values: unknown; command?: Command; asNode: string }>;
742742
}>;
743+
/**
744+
* Optional time-to-live in minutes for the thread.
745+
* If a number is provided, it is treated as minutes and defaults to strategy "delete".
746+
* You may also provide an object { ttl: number, strategy?: "delete" }.
747+
*/
748+
ttl?: number | { ttl: number; strategy?: "delete" };
743749
}): Promise<Thread<TStateType>> {
750+
// Normalize ttl to an object if a number is provided
751+
const ttlPayload =
752+
typeof payload?.ttl === "number"
753+
? { ttl: payload.ttl, strategy: "delete" as const }
754+
: payload?.ttl;
755+
744756
return this.fetch<Thread<TStateType>>(`/threads`, {
745757
method: "POST",
746758
json: {
@@ -757,6 +769,7 @@ export class ThreadsClient<
757769
as_node: u.asNode,
758770
})),
759771
})),
772+
ttl: ttlPayload,
760773
},
761774
});
762775
}
@@ -786,11 +799,22 @@ export class ThreadsClient<
786799
* Metadata for the thread.
787800
*/
788801
metadata?: Metadata;
802+
/**
803+
* Optional time-to-live in minutes for the thread.
804+
* If a number is provided, it is treated as minutes and defaults to strategy "delete".
805+
* You may also provide an object { ttl: number, strategy?: "delete" }.
806+
*/
807+
ttl?: number | { ttl: number; strategy?: "delete" };
789808
}
790809
): Promise<Thread> {
810+
const ttlPayload =
811+
typeof payload?.ttl === "number"
812+
? { ttl: payload.ttl, strategy: "delete" as const }
813+
: payload?.ttl;
814+
791815
return this.fetch<Thread>(`/threads/${threadId}`, {
792816
method: "PATCH",
793-
json: { metadata: payload?.metadata },
817+
json: { metadata: payload?.metadata, ttl: ttlPayload },
794818
});
795819
}
796820

0 commit comments

Comments
 (0)