resolveAgentUrl function
Resolves an agent:// URL against store (port of omp's
AgentProtocolHandler.resolve, reduced to the dot-path query subset).
Throws AgentUrlException on malformed URLs, unknown ids, conflicting extraction syntax, or non-JSON content named for extraction.
Implementation
AgentUrlResolution resolveAgentUrl(String url, AgentOutputStore store) {
final parsed = _splitAgentUrl(url);
final hasPathExtraction = parsed.urlPath.isNotEmpty && parsed.urlPath != '/';
if (hasPathExtraction && parsed.query != null) {
throw AgentUrlException(
'$agentUrlScheme:// URL cannot combine path extraction with ?q=',
);
}
final hop = _resolveUrlPath(parsed.outputId, parsed.urlPath);
final resolved = _resolveRawContent(store, parsed.outputId, hop.nestedId);
final resolvedNested = hop.nestedId != null && resolved.id == hop.nestedId;
final extract =
parsed.query != null || (hasPathExtraction && !resolvedNested);
if (!extract) {
return AgentUrlResolution(
id: resolved.id,
content: resolved.content,
contentType: 'text/markdown',
);
}
return _extractJsonContent(resolved, parsed.query, hop.segments.join('.'));
}