mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-15 00:17:27 +00:00
refactor(store): introduce typed RunContext for consolidated context injection
Add store.RunContext struct that consolidates 27 loop-injected context values into a single typed struct. RunContext is built once in loop_context.go and injected via store.WithRunContext(ctx, rc). 24 accessor functions (10 in store/context.go, 14 in tools/context_keys.go) updated with RunContext fallback — check individual key first, then RunContext. Consumers (170+ files) require zero changes. This enables adding new scope fields (e.g. ProjectID) by adding a single struct field instead of a new context key + With/From function pair.
This commit is contained in:
1 parent
d3a4398e78
commit
3bb524cb39
4 files changed
+251
-42
No files matched your search
@@ -241,6 +241,42 @@ func (l *Loop) injectContext(ctx context.Context, req *RunRequest) (contextSetup
|
||||
)
|
||||
}
|
||||
|
||||
// Build RunContext from all resolved values and inject as single context key.
|
||||
// This provides a typed, inspectable snapshot of all loop-injected context.
|
||||
// Individual With* keys above remain for backward compat during transition.
|
||||
providerName := ""
|
||||
if l.provider != nil {
|
||||
providerName = l.provider.Name()
|
||||
}
|
||||
rc := &store.RunContext{
|
||||
AgentID: l.agentUUID,
|
||||
AgentKey: l.id,
|
||||
TenantID: l.tenantID,
|
||||
UserID: req.UserID,
|
||||
AgentType: l.agentType,
|
||||
SenderID: req.SenderID,
|
||||
SelfEvolve: l.selfEvolve,
|
||||
SharedMemory: store.IsSharedMemory(ctx),
|
||||
SharedKG: store.IsSharedKG(ctx),
|
||||
RestrictToWorkspace: l.restrictToWs != nil && *l.restrictToWs,
|
||||
BuiltinToolSettings: l.builtinToolSettings,
|
||||
ChannelType: req.ChannelType,
|
||||
SubagentsCfg: l.subagentsCfg,
|
||||
ParentModel: l.model,
|
||||
ParentProvider: providerName,
|
||||
MemoryCfg: l.memoryCfg,
|
||||
SandboxCfg: l.sandboxCfg,
|
||||
ShellDenyGroups: l.shellDenyGroups,
|
||||
Workspace: tools.ToolWorkspaceFromCtx(ctx),
|
||||
TeamWorkspace: tools.ToolTeamWorkspaceFromCtx(ctx),
|
||||
TeamID: tools.ToolTeamIDFromCtx(ctx),
|
||||
WorkspaceChannel: req.WorkspaceChannel,
|
||||
WorkspaceChatID: req.WorkspaceChatID,
|
||||
TeamTaskID: req.TeamTaskID,
|
||||
AgentToolKey: l.id,
|
||||
}
|
||||
ctx = store.WithRunContext(ctx, rc)
|
||||
|
||||
return contextSetupResult{
|
||||
ctx: ctx,
|
||||
resolvedTeamSettings: resolvedTeamSettings,
|
||||
|
||||
Reference in new issue
Block a user