( ctx context.Context, callerScope toolspkg.Scope, id toolspkg.ToolID, filename string, selector memoryToolSelector, )
| 5151 | } |
| 5152 | |
| 5153 | func (n *daemonNativeTools) resolveMemoryLocation( |
| 5154 | ctx context.Context, |
| 5155 | callerScope toolspkg.Scope, |
| 5156 | id toolspkg.ToolID, |
| 5157 | filename string, |
| 5158 | selector memoryToolSelector, |
| 5159 | ) (memoryToolLocation, error) { |
| 5160 | trimmedFilename, err := requiredNativeString(id, "filename", filename) |
| 5161 | if err != nil { |
| 5162 | return memoryToolLocation{}, err |
| 5163 | } |
| 5164 | scope, err := core.ParseOptionalMemoryScope(selector.Scope) |
| 5165 | if err != nil { |
| 5166 | return memoryToolLocation{}, err |
| 5167 | } |
| 5168 | if scope != "" { |
| 5169 | location, err := n.memoryStoreFor(ctx, callerScope, id, selector, scope) |
| 5170 | if err != nil { |
| 5171 | return memoryToolLocation{}, err |
| 5172 | } |
| 5173 | exists, err := location.Store.Exists(location.Scope, trimmedFilename) |
| 5174 | if err != nil { |
| 5175 | return memoryToolLocation{}, err |
| 5176 | } |
| 5177 | if !exists { |
| 5178 | return memoryToolLocation{}, fmt.Errorf("%w: memory %q not found", os.ErrNotExist, trimmedFilename) |
| 5179 | } |
| 5180 | location.Filename = trimmedFilename |
| 5181 | return location, nil |
| 5182 | } |
| 5183 | candidates := []memoryToolLocation{ |
| 5184 | {Store: n.deps.MemoryStore, Scope: memcontract.ScopeGlobal, Filename: trimmedFilename}, |
| 5185 | } |
| 5186 | if strings.TrimSpace(firstNonEmpty(selector.Workspace, callerScope.WorkspaceID)) != "" { |
| 5187 | workspaceSelector := selector |
| 5188 | workspaceSelector.Scope = string(memcontract.ScopeWorkspace) |
| 5189 | location, err := n.memoryStoreFor(ctx, callerScope, id, workspaceSelector, memcontract.ScopeWorkspace) |
| 5190 | if err != nil { |
| 5191 | return memoryToolLocation{}, err |
| 5192 | } |
| 5193 | location.Filename = trimmedFilename |
| 5194 | candidates = append(candidates, location) |
| 5195 | } |
| 5196 | if strings.TrimSpace(firstNonEmpty(selector.AgentName, callerScope.AgentName)) != "" { |
| 5197 | agentSelector := selector |
| 5198 | agentSelector.Scope = string(memcontract.ScopeAgent) |
| 5199 | location, err := n.memoryStoreFor(ctx, callerScope, id, agentSelector, memcontract.ScopeAgent) |
| 5200 | if err != nil { |
| 5201 | return memoryToolLocation{}, err |
| 5202 | } |
| 5203 | location.Filename = trimmedFilename |
| 5204 | candidates = append(candidates, location) |
| 5205 | } |
| 5206 | matches := make([]memoryToolLocation, 0, len(candidates)) |
| 5207 | for _, candidate := range candidates { |
| 5208 | exists, err := candidate.Store.Exists(candidate.Scope, trimmedFilename) |
| 5209 | if err != nil { |
| 5210 | return memoryToolLocation{}, err |
no test coverage detected