mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-15 19:42:35 +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.
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package pluginapi
|
|
|
|
import "encoding/json"
|
|
|
|
// EventType is the kind of one NDJSON line in a streaming answer.
|
|
type EventType string
|
|
|
|
const (
|
|
// EventItem carries one result (a FetchedItem for connectors).
|
|
EventItem EventType = "item"
|
|
// EventCheckpoint carries a resumable cursor; WeKnora persists it.
|
|
EventCheckpoint EventType = "checkpoint"
|
|
// EventProgress reports progress for display.
|
|
EventProgress EventType = "progress"
|
|
// EventLog forwards a log line to WeKnora's logs.
|
|
EventLog EventType = "log"
|
|
// EventError ends the stream with an error.
|
|
EventError EventType = "error"
|
|
// EventEnd ends the stream successfully, with the final Data.
|
|
EventEnd EventType = "end"
|
|
)
|
|
|
|
// Event is one line of a streaming answer. A stream that stops without an
|
|
// "end" or "error" event was interrupted and is treated as failed.
|
|
type Event struct {
|
|
Type EventType `json:"type"`
|
|
Data json.RawMessage `json:"data,omitempty"`
|
|
// Error is set on EventError.
|
|
Error *Error `json:"error,omitempty"`
|
|
// Message is set on EventLog and EventProgress.
|
|
Message string `json:"message,omitempty"`
|
|
// Level is set on EventLog: debug, info, warn, error.
|
|
Level string `json:"level,omitempty"`
|
|
}
|