@@ -12,6 +12,8 @@ import (
1212 callbackspb "go.temporal.io/server/chasm/lib/callback/gen/callbackpb/v1"
1313 "go.temporal.io/server/chasm/lib/nexusoperation"
1414 chasmworkflowpb "go.temporal.io/server/chasm/lib/workflow/gen/workflowpb/v1"
15+ "go.temporal.io/server/common/log/tag"
16+ "go.temporal.io/server/common/softassert"
1517 "go.temporal.io/server/service/history/historybuilder"
1618 "google.golang.org/protobuf/types/known/emptypb"
1719 "google.golang.org/protobuf/types/known/timestamppb"
@@ -27,6 +29,9 @@ type Workflow struct {
2729 // MSPointer is a special in-memory field for accessing the underlying mutable state.
2830 chasm.MSPointer
2931
32+ // Visibility to store custom search attributes and memo.
33+ Visibility chasm.Field [* chasm.Visibility ]
34+
3035 // Callbacks map is used to store the callbacks for the workflow.
3136 Callbacks chasm.Map [string , * callback.Callback ]
3237
@@ -72,6 +77,73 @@ func (w *Workflow) Terminate(
7277 return chasm.TerminateComponentResponse {}, serviceerror .NewInternal ("workflow root Terminate should not be called" )
7378}
7479
80+ // SearchAttributes returns the predefined search attributes set in the underlying mutable state.
81+ func (w * Workflow ) SearchAttributes (ctx chasm.Context ) []chasm.SearchAttributeKeyValue {
82+ searchAttributes , err := w .GetPredefinedSearchAttributes ()
83+ softassert .That (
84+ ctx .Logger (),
85+ err == nil ,
86+ "failed to retrieve search attributes from mutable state execution info" ,
87+ tag .Error (err ),
88+ )
89+
90+ var res []chasm.SearchAttributeKeyValue
91+ for saName , value := range searchAttributes {
92+ res = append (res , chasm.SearchAttributeKeyValue {
93+ Alias : saName ,
94+ Field : saName ,
95+ Value : value ,
96+ })
97+ }
98+ return res
99+ }
100+
101+ // CustomSearchAttributes returns the custom search attributes.
102+ func (w * Workflow ) CustomSearchAttributes (ctx chasm.Context ) map [string ]* commonpb.Payload {
103+ if vis , ok := w .Visibility .TryGet (ctx ); ok {
104+ return vis .CustomSearchAttributes (ctx )
105+ }
106+ return nil
107+ }
108+
109+ // CustomMemo returns the custom memo.
110+ func (w * Workflow ) CustomMemo (ctx chasm.Context ) map [string ]* commonpb.Payload {
111+ if vis , ok := w .Visibility .TryGet (ctx ); ok {
112+ return vis .CustomMemo (ctx )
113+ }
114+ return nil
115+ }
116+
117+ // UpsertCustomSearchAttributes merges the provided custom search attributes into the existing one.
118+ // For details of the merge, see [chasm.Visibility.MergeCustomSearchAttributes].
119+ func (w * Workflow ) UpsertCustomSearchAttributes (
120+ ctx chasm.MutableContext ,
121+ customSearchAttributes map [string ]* commonpb.Payload ,
122+ ) error {
123+ if vis , ok := w .Visibility .TryGet (ctx ); ok {
124+ vis .MergeCustomSearchAttributes (ctx , customSearchAttributes )
125+ } else {
126+ vis := chasm .NewVisibilityWithData (ctx , customSearchAttributes , nil )
127+ w .Visibility = chasm .NewComponentField (ctx , vis )
128+ }
129+ return nil
130+ }
131+
132+ // UpsertCustomMemo merges the provided custom memo into the existing one.
133+ // For details of the merge, see [chasm.Visibility.MergeCustomMemo].
134+ func (w * Workflow ) UpsertCustomMemo (
135+ ctx chasm.MutableContext ,
136+ customMemo map [string ]* commonpb.Payload ,
137+ ) error {
138+ if vis , ok := w .Visibility .TryGet (ctx ); ok {
139+ vis .MergeCustomMemo (ctx , customMemo )
140+ } else {
141+ vis := chasm .NewVisibilityWithData (ctx , nil , customMemo )
142+ w .Visibility = chasm .NewComponentField (ctx , vis )
143+ }
144+ return nil
145+ }
146+
75147// ProcessCloseCallbacks triggers "WorkflowClosed" callbacks using the CHASM implementation.
76148// It schedules all workflow-level and update-level callbacks that are in STANDBY state.
77149func (w * Workflow ) ProcessCloseCallbacks (ctx chasm.MutableContext ) error {
0 commit comments