54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package node
|
|
|
|
import (
|
|
runtime "iop/packages/go/agentruntime"
|
|
iop "iop/proto/gen/iop"
|
|
)
|
|
|
|
// runRequestFromProto is the Edge-Node wire boundary. Common runtime packages
|
|
// remain independent of protobuf and Node transport details.
|
|
func runRequestFromProto(req *iop.RunRequest) runtime.RunRequest {
|
|
return runtime.RunRequest{
|
|
RunID: req.GetRunId(),
|
|
Adapter: req.GetAdapter(),
|
|
Target: req.GetTarget(),
|
|
SessionID: req.GetSessionId(),
|
|
SessionMode: sessionModeFromProto(req.GetSessionMode()),
|
|
Background: req.GetBackground(),
|
|
Workspace: req.GetWorkspace(),
|
|
Policy: structAsMap(req.GetPolicy()),
|
|
Input: structAsMap(req.GetInput()),
|
|
TimeoutSec: int(req.GetTimeoutSec()),
|
|
Metadata: req.GetMetadata(),
|
|
}
|
|
}
|
|
|
|
// runEventToProto preserves the existing Edge-Node event values while
|
|
// translating the host-neutral common event into the Node wire response.
|
|
func runEventToProto(event runtime.RuntimeEvent, nodeID, sessionID string, background bool) *iop.RunEvent {
|
|
errorMessage := event.Error
|
|
if errorMessage == "" && event.Failure != nil {
|
|
errorMessage = event.Failure.Error()
|
|
}
|
|
wireEvent := &iop.RunEvent{
|
|
RunId: event.RunID,
|
|
Type: string(event.Type),
|
|
Delta: event.Delta,
|
|
Message: event.Message,
|
|
Error: errorMessage,
|
|
Metadata: event.Metadata,
|
|
Timestamp: event.Timestamp.UnixNano(),
|
|
SessionId: sessionID,
|
|
Background: background,
|
|
NodeId: nodeID,
|
|
}
|
|
if event.Usage != nil {
|
|
wireEvent.Usage = &iop.Usage{
|
|
InputTokens: int32(event.Usage.InputTokens),
|
|
OutputTokens: int32(event.Usage.OutputTokens),
|
|
ReasoningTokens: int32(event.Usage.ReasoningTokens),
|
|
CachedInputTokens: int32(event.Usage.CachedInputTokens),
|
|
}
|
|
}
|
|
return wireEvent
|
|
}
|