mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-15 10:58:21 +08:00
A new module, github.com/Tencent/WeKnora/pluginsdk, so plugin authors import the protocol without WeKnora's dependency tree: - pluginapi: the protocol (envelope with context and the system / tenant / instance config scopes, error codes, NDJSON stream events, web search and connector messages, the host handshake line, HMAC request signing) plus openapi.yaml describing it for other languages. - pluginsdk: build a plugin in Go. Register web search providers and connectors, then Serve: started by the plugin host it listens on the socket it is given, prints the handshake and accepts only the host token; run on its own it verifies signed requests. Envelope deadlines reach the handler's context, panics become internal errors, and fetches stream items and checkpoints. - client: calls a plugin over a handshake socket or HTTPS, with typed transport errors; WeKnora's adapters and the conformance suite share it. - conformance + cmd/weknora-plugin-conformance: checks a running plugin answers discovery, rejects unauthenticated and malformed calls, and answers every endpoint it claims with an output or a protocol error. A test keeps openapi.yaml and the SDK routes in step. A new workflow builds and tests the module on Linux, macOS and Windows; go-lint lints it.
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package pluginapi
|
|
|
|
import "time"
|
|
|
|
// SearchPath is the web search endpoint for provider id.
|
|
func SearchPath(id string) string { return "/v1/websearch/" + id + "/search" }
|
|
|
|
// SearchInput is the input of a web search.
|
|
type SearchInput struct {
|
|
Query string `json:"query"`
|
|
MaxResults int `json:"maxResults"`
|
|
IncludeDate bool `json:"includeDate,omitempty"`
|
|
// Region and Freshness are optional filters; a provider that cannot
|
|
// honour a requested filter must fail rather than ignore it.
|
|
Region string `json:"region,omitempty"`
|
|
Freshness string `json:"freshness,omitempty"`
|
|
}
|
|
|
|
// SearchOutput is the output of a web search.
|
|
type SearchOutput struct {
|
|
Results []SearchResult `json:"results"`
|
|
}
|
|
|
|
// SearchResult is one hit.
|
|
type SearchResult struct {
|
|
Title string `json:"title"`
|
|
URL string `json:"url"`
|
|
Snippet string `json:"snippet,omitempty"`
|
|
Content string `json:"content,omitempty"`
|
|
Age string `json:"age,omitempty"`
|
|
PublishedAt *time.Time `json:"publishedAt,omitempty"`
|
|
}
|