Optionalchunk chunk ?: ( chunk : { artifact ?: { metadata ?: Record < string , any > ; name ?: string ; parts : ( | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text : string ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media : { contentType ?: string ; url : string } ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest : { input ?: unknown ; name : string ; partial ?: boolean ; ref ?: string ; } ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse : { name : string ; output ?: unknown ; ref ?: (...) | (...) } & { content ?: (...) | (...); } ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom : Record < string , any > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning : string ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource : { uri : string } ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } )[] ; } ; customPatch ?: { from ?: string ; op : "replace" | "add" | "remove" | "copy" | "move" | "test" ; path : string ; value ?: any ; } [] ; modelChunk ?: { aggregated ?: boolean ; content : ( | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text : string ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media : { contentType ?: string ; url : string } ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest : { input ?: unknown ; name : string ; partial ?: boolean ; ref ?: string ; } ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse : { name : string ; output ?: unknown ; ref ?: (...) | (...) } & { content ?: (...) | (...); } ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom : Record < string , any > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning : string ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < string , unknown > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < string , unknown > ; reasoning ?: undefined ; resource : { uri : string } ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } )[] ; custom ?: unknown ; index ?: number ; role ?: "user" | "model" | "tool" | "system" ; } ; turnEnd ?: { finishReason ?: | "length" | "stop" | "failed" | "other" | "unknown" | "interrupted" | "blocked" | "aborted" | "detached" ; snapshotId ?: string ; } ; } , ) => | { artifact ?: { metadata ?: Record < string , any > ; name ?: string ; parts : ( | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text : string ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media : { contentType ?: (...) | (...); url : string } ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest : { input ?: unknown ; name : string ; partial ?: (...) | (...) | (...); ref ?: (...) | (...); } ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse : { name : ...; output ?: ...; ref ?: ... } & { content ?: ... } ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom : Record < string , any > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning : string ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource : { uri : string } ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } )[] ; } ; customPatch ?: { from ?: string ; op : "replace" | "add" | "remove" | "copy" | "move" | "test" ; path : string ; value ?: any ; } [] ; modelChunk ?: { aggregated ?: boolean ; content : ( | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text : string ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media : { contentType ?: (...) | (...); url : string } ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest : { input ?: unknown ; name : string ; partial ?: (...) | (...) | (...); ref ?: (...) | (...); } ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse : { name : ...; output ?: ...; ref ?: ... } & { content ?: ... } ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom : Record < string , any > ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning : string ; resource ?: undefined ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } | { custom ?: Record < (...), (...)> ; data ?: unknown ; media ?: undefined ; metadata ?: Record < (...), (...)> ; reasoning ?: undefined ; resource : { uri : string } ; text ?: undefined ; toolRequest ?: undefined ; toolResponse ?: undefined ; } )[] ; custom ?: unknown ; index ?: number ; role ?: "user" | "model" | "tool" | "system" ; } ; turnEnd ?: { finishReason ?: | "length" | "stop" | "failed" | "other" | "unknown" | "interrupted" | "blocked" | "aborted" | "detached" ; snapshotId ?: string ; } ; } | null | undefined
Defined in ai/lib/agent.d.ts:227
Projects an agent's server-side data onto the view a client should see.
Every member is optional; an omitted member passes the corresponding data through unchanged. Use this to redact sensitive fields or reshape data before it leaves the server - covering both data at rest and data in flight:
statereshapes/redacts session state at rest. Applied toAgentOutput.state(client-managed agents), to snapshots returned bygetSnapshotData, and as the baseline for streamedcustomPatchdiffs (so streamed custom-state deltas stay consistent with the transformed full state). Note:state.artifactsis part of session state, so artifact redaction at rest happens here too.chunkreshapes/redacts each stream chunk in flight (modelChunk,artifact,customPatch,turnEnd) - e.g. filtering "internal" tool request/response parts out of model chunks, or redacting streamed artifacts. Returnnull/undefinedto drop the chunk entirely.When both
stateandchunktouch the same data (e.g. artifacts), keeping the two projections consistent is the author's responsibility.