Skip to content

Commit a9ee865

Browse files
committed
feat(metadata): add metadata field to A2ARequest and propagate through pipeline service
1 parent b781913 commit a9ee865

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

pkg/ai/model/a2a.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package model
33
// A2ARequest carries the data needed to call AI Processor via JSON-RPC 2.0.
44
// Fields are NOT serialised directly — the adapter builds the wire format.
55
type A2ARequest struct {
6-
OutgoingURL string // full A2A endpoint URL from agent_bot.outgoing_url
7-
ContactID int64 // used for userId in JSON-RPC params
8-
ConversationID int64 // used for contextId in JSON-RPC params
9-
ApiKey string // used for X-API-Key header (per-event auth)
10-
Message string // aggregated buffer content (FR-15)
6+
OutgoingURL string // full A2A endpoint URL from agent_bot.outgoing_url
7+
ContactID int64 // used for userId in JSON-RPC params
8+
ConversationID int64 // used for contextId in JSON-RPC params
9+
ApiKey string // used for X-API-Key header (per-event auth)
10+
Message string // aggregated buffer content (FR-15)
11+
Metadata map[string]any // CRM metadata passed through to processor (tools context)
1112
}
1213

1314
// jsonRPCRequest is the JSON-RPC 2.0 envelope sent to AI Processor.

pkg/ai/service/ai_adapter.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (a *aiAdapter) Call(ctx context.Context, req *model.A2ARequest) (*model.Nor
6262
{Type: "text", Text: req.Message},
6363
},
6464
},
65-
Metadata: map[string]any{},
65+
Metadata: nonNilMetadata(req.Metadata),
6666
},
6767
}
6868

@@ -141,3 +141,11 @@ func extractResponseText(resp *model.A2AResponse) string {
141141
}
142142
return ""
143143
}
144+
145+
// nonNilMetadata ensures metadata is never nil (avoids "null" in JSON).
146+
func nonNilMetadata(m map[string]any) map[string]any {
147+
if m == nil {
148+
return map[string]any{}
149+
}
150+
return m
151+
}

pkg/pipeline/service/pipeline_service.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (s *pipelineService) startDebounce(ctx context.Context, event *model.Messag
166166
postbackURL: event.PostbackURL,
167167
outgoingURL: event.OutgoingURL,
168168
apiKey: event.ApiKey,
169+
metadata: event.Metadata,
169170
})
170171

171172
if err := s.debounce.Start(ctx, event.ContactID, event.ConversationID, event.MessageContent, event.BotConfig); err != nil {
@@ -183,6 +184,7 @@ func (s *pipelineService) startDebounce(ctx context.Context, event *model.Messag
183184
PostbackURL: event.PostbackURL,
184185
OutgoingURL: event.OutgoingURL,
185186
ApiKey: event.ApiKey,
187+
Metadata: event.Metadata,
186188
}
187189
if err := s.repo.SetState(ctx, event.ContactID, event.ConversationID, newState); err != nil {
188190
cancel()
@@ -209,6 +211,7 @@ func (s *pipelineService) skipDebounce(ctx context.Context, event *model.Message
209211
postbackURL: event.PostbackURL,
210212
outgoingURL: event.OutgoingURL,
211213
apiKey: event.ApiKey,
214+
metadata: event.Metadata,
212215
})
213216

214217
// debounce.Start appends to buffer; DebounceTime=0 means no timer (Story 2.1).
@@ -340,13 +343,15 @@ func (s *pipelineService) runAIStage(ctx context.Context, contactID, conversatio
340343
)
341344
start := time.Now()
342345

343-
// Retrieve outgoing_url and api_key from the pipeline entry.
346+
// Retrieve outgoing_url, api_key and metadata from the pipeline entry.
344347
key := pairKey(contactID, conversationID)
345348
var outgoingURL, apiKey string
349+
var metadata map[string]any
346350
if v, ok := s.entries.Load(key); ok {
347351
if entry, ok := v.(pipelineEntry); ok {
348352
outgoingURL = entry.outgoingURL
349353
apiKey = entry.apiKey
354+
metadata = entry.metadata
350355
}
351356
}
352357

@@ -356,6 +361,7 @@ func (s *pipelineService) runAIStage(ctx context.Context, contactID, conversatio
356361
ConversationID: conversationID,
357362
ApiKey: apiKey,
358363
Message: buffer,
364+
Metadata: metadata,
359365
})
360366
if err != nil {
361367
switch {

server

-16.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)