Skip to content

Commit ea41eae

Browse files
committed
refactor: rename warmTimeout to idleTimeout across chat APIs
1 parent 80dd700 commit ea41eae

File tree

7 files changed

+74
-74
lines changed

7 files changed

+74
-74
lines changed

packages/core/src/v3/realtimeStreams/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ export type RealtimeDefinedInputStream<TData> = {
194194
*/
195195
wait: (options?: InputStreamWaitOptions) => ManualWaitpointPromise<TData>;
196196
/**
197-
* Wait for data with a warm phase before suspending.
197+
* Wait for data with an idle phase before suspending.
198198
*
199-
* Keeps the task warm (active, using compute) for `warmTimeoutInSeconds`,
199+
* Keeps the task active (using compute) for `idleTimeoutInSeconds`,
200200
* then suspends via `.wait()` if no data arrives. If data arrives during
201-
* the warm phase the task responds instantly without suspending.
201+
* the idle phase the task responds instantly without suspending.
202202
*/
203-
waitWithWarmup: (options: InputStreamWaitWithWarmupOptions) => Promise<{ ok: true; output: TData } | { ok: false; error?: any }>;
203+
waitWithIdleTimeout: (options: InputStreamWaitWithIdleTimeoutOptions) => Promise<{ ok: true; output: TData } | { ok: false; error?: any }>;
204204
/**
205205
* Send data to this input stream on a specific run.
206206
* This is used from outside the task (e.g., from your backend or another task).
@@ -257,9 +257,9 @@ export type InputStreamWaitOptions = {
257257
spanName?: string;
258258
};
259259

260-
export type InputStreamWaitWithWarmupOptions = {
261-
/** Seconds to keep the task warm before suspending. */
262-
warmTimeoutInSeconds: number;
260+
export type InputStreamWaitWithIdleTimeoutOptions = {
261+
/** Seconds to keep the task idle (active, using compute) before suspending. */
262+
idleTimeoutInSeconds: number;
263263
/** Maximum time to wait after suspending (duration string, e.g. "1h"). */
264264
timeout?: string;
265265
/** Override the default span name for the outer operation. */

packages/trigger-sdk/src/v3/ai.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ export type ChatTaskWirePayload<TMessage extends UIMessage = UIMessage, TMetadat
321321
continuation?: boolean;
322322
/** The run ID of the previous run (only set when `continuation` is true). */
323323
previousRunId?: string;
324-
/** Override warm timeout for this run (seconds). Set by transport.preload(). */
325-
warmTimeoutInSeconds?: number;
324+
/** Override idle timeout for this run (seconds). Set by transport.preload(). */
325+
idleTimeoutInSeconds?: number;
326326
};
327327

328328
/**
@@ -896,16 +896,16 @@ export type ChatTaskOptions<
896896
turnTimeout?: string;
897897

898898
/**
899-
* How long (in seconds) to keep the run warm after each turn before suspending.
900-
* During this window the run stays active and can respond instantly to the
901-
* next message. After this timeout, the run suspends (frees compute) and waits
902-
* via `inputStream.wait()`.
899+
* How long (in seconds) the run stays idle (active, using compute) after each
900+
* turn, waiting for the next message. During this window responses are instant.
901+
* After this timeout the run suspends (frees compute) and waits via
902+
* `inputStream.wait()`.
903903
*
904904
* Set to `0` to suspend immediately after each turn.
905905
*
906906
* @default 30
907907
*/
908-
warmTimeoutInSeconds?: number;
908+
idleTimeoutInSeconds?: number;
909909

910910
/**
911911
* How long the `chatAccessToken` (scoped to this run) remains valid.
@@ -919,14 +919,14 @@ export type ChatTaskOptions<
919919
chatAccessTokenTTL?: string;
920920

921921
/**
922-
* How long (in seconds) to keep the run warm after `onPreload` fires,
922+
* How long (in seconds) the run stays idle after `onPreload` fires,
923923
* waiting for the first message before suspending.
924924
*
925925
* Only applies to preloaded runs (triggered via `transport.preload()`).
926926
*
927-
* @default Same as `warmTimeoutInSeconds`
927+
* @default Same as `idleTimeoutInSeconds`
928928
*/
929-
preloadWarmTimeoutInSeconds?: number;
929+
preloadIdleTimeoutInSeconds?: number;
930930

931931
/**
932932
* How long to wait (suspended) for the first message after a preloaded run starts.
@@ -1010,9 +1010,9 @@ function chatTask<
10101010
onTurnComplete,
10111011
maxTurns = 100,
10121012
turnTimeout = "1h",
1013-
warmTimeoutInSeconds = 30,
1013+
idleTimeoutInSeconds = 30,
10141014
chatAccessTokenTTL = "1h",
1015-
preloadWarmTimeoutInSeconds,
1015+
preloadIdleTimeoutInSeconds,
10161016
preloadTimeout,
10171017
uiMessageStreamOptions,
10181018
...restOptions
@@ -1111,18 +1111,18 @@ function chatTask<
11111111
}
11121112

11131113
// Wait for the first real message — use preload-specific timeouts if configured
1114-
const effectivePreloadWarmTimeout =
1115-
payload.warmTimeoutInSeconds
1116-
?? preloadWarmTimeoutInSeconds
1117-
?? warmTimeoutInSeconds;
1114+
const effectivePreloadIdleTimeout =
1115+
payload.idleTimeoutInSeconds
1116+
?? preloadIdleTimeoutInSeconds
1117+
?? idleTimeoutInSeconds;
11181118

11191119
const effectivePreloadTimeout =
11201120
(metadata.get(TURN_TIMEOUT_METADATA_KEY) as string | undefined)
11211121
?? preloadTimeout
11221122
?? turnTimeout;
11231123

1124-
const preloadResult = await messagesInput.waitWithWarmup({
1125-
warmTimeoutInSeconds: effectivePreloadWarmTimeout,
1124+
const preloadResult = await messagesInput.waitWithIdleTimeout({
1125+
idleTimeoutInSeconds: effectivePreloadIdleTimeout,
11261126
timeout: effectivePreloadTimeout,
11271127
spanName: "waiting for first message",
11281128
});
@@ -1493,14 +1493,14 @@ function chatTask<
14931493
return "continue";
14941494
}
14951495

1496-
// Wait for the next message — stay warm briefly, then suspend
1497-
const effectiveWarmTimeout =
1498-
(metadata.get(WARM_TIMEOUT_METADATA_KEY) as number | undefined) ?? warmTimeoutInSeconds;
1496+
// Wait for the next message — stay idle briefly, then suspend
1497+
const effectiveIdleTimeout =
1498+
(metadata.get(IDLE_TIMEOUT_METADATA_KEY) as number | undefined) ?? idleTimeoutInSeconds;
14991499
const effectiveTurnTimeout =
15001500
(metadata.get(TURN_TIMEOUT_METADATA_KEY) as string | undefined) ?? turnTimeout;
15011501

1502-
const next = await messagesInput.waitWithWarmup({
1503-
warmTimeoutInSeconds: effectiveWarmTimeout,
1502+
const next = await messagesInput.waitWithIdleTimeout({
1503+
idleTimeoutInSeconds: effectiveIdleTimeout,
15041504
timeout: effectiveTurnTimeout,
15051505
spanName: "waiting for next message",
15061506
});
@@ -1554,7 +1554,7 @@ function chatTask<
15541554
// ---------------------------------------------------------------------------
15551555

15561556
const TURN_TIMEOUT_METADATA_KEY = "chat.turnTimeout";
1557-
const WARM_TIMEOUT_METADATA_KEY = "chat.warmTimeout";
1557+
const IDLE_TIMEOUT_METADATA_KEY = "chat.idleTimeout";
15581558

15591559
/**
15601560
* Override the turn timeout for subsequent turns in the current run.
@@ -1597,24 +1597,24 @@ function setTurnTimeoutInSeconds(seconds: number): void {
15971597
}
15981598

15991599
/**
1600-
* Override the warm timeout for subsequent turns in the current run.
1600+
* Override the idle timeout for subsequent turns in the current run.
16011601
*
1602-
* The warm timeout controls how long the run stays active (using compute)
1602+
* The idle timeout controls how long the run stays active (using compute)
16031603
* after each turn, waiting for the next message. During this window,
16041604
* responses are instant. After it expires, the run suspends.
16051605
*
1606-
* @param seconds - Number of seconds to stay warm (0 to suspend immediately)
1606+
* @param seconds - Number of seconds to stay idle (0 to suspend immediately)
16071607
*
16081608
* @example
16091609
* ```ts
16101610
* run: async ({ messages, signal }) => {
1611-
* chat.setWarmTimeoutInSeconds(60);
1611+
* chat.setIdleTimeoutInSeconds(60);
16121612
* return streamText({ model, messages, abortSignal: signal });
16131613
* }
16141614
* ```
16151615
*/
1616-
function setWarmTimeoutInSeconds(seconds: number): void {
1617-
metadata.set(WARM_TIMEOUT_METADATA_KEY, seconds);
1616+
function setIdleTimeoutInSeconds(seconds: number): void {
1617+
metadata.set(IDLE_TIMEOUT_METADATA_KEY, seconds);
16181618
}
16191619

16201620
/**
@@ -1937,8 +1937,8 @@ class ChatMessageAccumulator {
19371937
export type ChatSessionOptions = {
19381938
/** Run-level cancel signal (from task context). */
19391939
signal: AbortSignal;
1940-
/** Seconds to stay warm between turns before suspending. @default 30 */
1941-
warmTimeoutInSeconds?: number;
1940+
/** Seconds to stay idle between turns before suspending. @default 30 */
1941+
idleTimeoutInSeconds?: number;
19421942
/** Duration string for suspend timeout. @default "1h" */
19431943
timeout?: string;
19441944
/** Max turns before ending. @default 100 */
@@ -1988,7 +1988,7 @@ export type ChatTurn = {
19881988
* Create a chat session that yields turns as an async iterator.
19891989
*
19901990
* Handles: preload wait, stop signals, message accumulation, turn-complete
1991-
* signaling, and warm/suspend between turns. You control: initialization,
1991+
* signaling, and idle/suspend between turns. You control: initialization,
19921992
* model/tool selection, persistence, and any custom per-turn logic.
19931993
*
19941994
* @example
@@ -2021,7 +2021,7 @@ function createChatSession(
20212021
): AsyncIterable<ChatTurn> {
20222022
const {
20232023
signal: runSignal,
2024-
warmTimeoutInSeconds = 30,
2024+
idleTimeoutInSeconds = 30,
20252025
timeout = "1h",
20262026
maxTurns = 100,
20272027
} = options;
@@ -2039,8 +2039,8 @@ function createChatSession(
20392039

20402040
// First turn: handle preload — wait for the first real message
20412041
if (turn === 0 && currentPayload.trigger === "preload") {
2042-
const result = await messagesInput.waitWithWarmup({
2043-
warmTimeoutInSeconds: currentPayload.warmTimeoutInSeconds ?? warmTimeoutInSeconds,
2042+
const result = await messagesInput.waitWithIdleTimeout({
2043+
idleTimeoutInSeconds: currentPayload.idleTimeoutInSeconds ?? idleTimeoutInSeconds,
20442044
timeout,
20452045
spanName: "waiting for first message",
20462046
});
@@ -2053,8 +2053,8 @@ function createChatSession(
20532053

20542054
// Subsequent turns: wait for the next message
20552055
if (turn > 0) {
2056-
const next = await messagesInput.waitWithWarmup({
2057-
warmTimeoutInSeconds,
2056+
const next = await messagesInput.waitWithIdleTimeout({
2057+
idleTimeoutInSeconds,
20582058
timeout,
20592059
spanName: "waiting for next message",
20602060
});
@@ -2391,8 +2391,8 @@ export const chat = {
23912391
setTurnTimeout,
23922392
/** Override the turn timeout at runtime (seconds). See {@link setTurnTimeoutInSeconds}. */
23932393
setTurnTimeoutInSeconds,
2394-
/** Override the warm timeout at runtime. See {@link setWarmTimeoutInSeconds}. */
2395-
setWarmTimeoutInSeconds,
2394+
/** Override the idle timeout at runtime. See {@link setIdleTimeoutInSeconds}. */
2395+
setIdleTimeoutInSeconds,
23962396
/** Override toUIMessageStream() options for the current turn. See {@link setUIMessageStreamOptions}. */
23972397
setUIMessageStreamOptions,
23982398
/** Check if the current turn was stopped by the user. See {@link isStopped}. */

packages/trigger-sdk/src/v3/chat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ export class TriggerChatTransport implements ChatTransport<UIMessage> {
464464
*
465465
* No-op if a session already exists for this chatId.
466466
*/
467-
async preload(chatId: string, options?: { warmTimeoutInSeconds?: number }): Promise<void> {
467+
async preload(chatId: string, options?: { idleTimeoutInSeconds?: number }): Promise<void> {
468468
// Don't preload if session already exists
469469
if (this.sessions.get(chatId)?.runId) return;
470470

@@ -473,8 +473,8 @@ export class TriggerChatTransport implements ChatTransport<UIMessage> {
473473
chatId,
474474
trigger: "preload" as const,
475475
metadata: this.defaultMetadata,
476-
...(options?.warmTimeoutInSeconds !== undefined
477-
? { warmTimeoutInSeconds: options.warmTimeoutInSeconds }
476+
...(options?.idleTimeoutInSeconds !== undefined
477+
? { idleTimeoutInSeconds: options.idleTimeoutInSeconds }
478478
: {}),
479479
};
480480

packages/trigger-sdk/src/v3/streams.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
InputStreamOncePromise,
2626
type InputStreamOnceResult,
2727
type InputStreamWaitOptions,
28-
type InputStreamWaitWithWarmupOptions,
28+
type InputStreamWaitWithIdleTimeoutOptions,
2929
type SendInputStreamOptions,
3030
type InferInputStreamType,
3131
type StreamWriteResult,
@@ -842,20 +842,20 @@ function input<TData>(opts: { id: string }): RealtimeDefinedInputStream<TData> {
842842
}
843843
});
844844
},
845-
async waitWithWarmup(options) {
845+
async waitWithIdleTimeout(options) {
846846
const self = this;
847-
const spanName = options.spanName ?? `inputStream.waitWithWarmup()`;
847+
const spanName = options.spanName ?? `inputStream.waitWithIdleTimeout()`;
848848

849849
return tracer.startActiveSpan(
850850
spanName,
851851
async (span) => {
852-
// Warm phase: keep compute alive
853-
if (options.warmTimeoutInSeconds > 0) {
852+
// Idle phase: keep compute alive
853+
if (options.idleTimeoutInSeconds > 0) {
854854
const warm = await inputStreams.once(opts.id, {
855-
timeoutMs: options.warmTimeoutInSeconds * 1000,
855+
timeoutMs: options.idleTimeoutInSeconds * 1000,
856856
});
857857
if (warm.ok) {
858-
span.setAttribute("wait.resolved", "warm");
858+
span.setAttribute("wait.resolved", "idle");
859859
return { ok: true as const, output: warm.output as TData };
860860
}
861861
}

references/ai-chat/src/components/chat-app.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function ChatApp({
5656
// Model for new chats (before first message is sent)
5757
const [newChatModel, setNewChatModel] = useState(DEFAULT_MODEL);
5858
const [preloadEnabled, setPreloadEnabled] = useState(true);
59-
const [warmTimeoutInSeconds, setWarmTimeoutInSeconds] = useState(60);
59+
const [idleTimeoutInSeconds, setIdleTimeoutInSeconds] = useState(60);
6060

6161
const handleSessionChange = useCallback(
6262
(chatId: string, session: SessionInfo | null) => {
@@ -106,7 +106,7 @@ export function ChatApp({
106106
setNewChatModel(DEFAULT_MODEL);
107107
if (preloadEnabled) {
108108
// Eagerly start the run — onPreload fires immediately for initialization
109-
transport.preload(id, { warmTimeoutInSeconds });
109+
transport.preload(id, { idleTimeoutInSeconds });
110110
}
111111
}
112112

@@ -159,8 +159,8 @@ export function ChatApp({
159159
onDeleteChat={handleDeleteChat}
160160
preloadEnabled={preloadEnabled}
161161
onPreloadChange={setPreloadEnabled}
162-
warmTimeoutInSeconds={warmTimeoutInSeconds}
163-
onWarmTimeoutChange={setWarmTimeoutInSeconds}
162+
idleTimeoutInSeconds={idleTimeoutInSeconds}
163+
onIdleTimeoutChange={setIdleTimeoutInSeconds}
164164
taskMode={taskMode}
165165
onTaskModeChange={onTaskModeChange}
166166
/>

references/ai-chat/src/components/chat-sidebar.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ type ChatSidebarProps = {
2626
onDeleteChat: (id: string) => void;
2727
preloadEnabled: boolean;
2828
onPreloadChange: (enabled: boolean) => void;
29-
warmTimeoutInSeconds: number;
30-
onWarmTimeoutChange: (seconds: number) => void;
29+
idleTimeoutInSeconds: number;
30+
onIdleTimeoutChange: (seconds: number) => void;
3131
taskMode: string;
3232
onTaskModeChange: (mode: string) => void;
3333
};
@@ -40,8 +40,8 @@ export function ChatSidebar({
4040
onDeleteChat,
4141
preloadEnabled,
4242
onPreloadChange,
43-
warmTimeoutInSeconds,
44-
onWarmTimeoutChange,
43+
idleTimeoutInSeconds,
44+
onIdleTimeoutChange,
4545
taskMode,
4646
onTaskModeChange,
4747
}: ChatSidebarProps) {
@@ -101,13 +101,13 @@ export function ChatSidebar({
101101
Preload new chats
102102
</label>
103103
<div className="flex items-center gap-2 text-xs text-gray-500">
104-
<span className="shrink-0">Warm timeout</span>
104+
<span className="shrink-0">Idle timeout</span>
105105
<input
106106
type="number"
107107
min={0}
108108
step={5}
109-
value={warmTimeoutInSeconds}
110-
onChange={(e) => onWarmTimeoutChange(Number(e.target.value))}
109+
value={idleTimeoutInSeconds}
110+
onChange={(e) => onIdleTimeoutChange(Number(e.target.value))}
111111
className="w-16 rounded border border-gray-300 px-1.5 py-0.5 text-xs text-gray-600 outline-none focus:border-blue-500"
112112
/>
113113
<span>s</span>

0 commit comments

Comments
 (0)