Files
WeKnora/pluginsdk/pluginapi/envelope.go
T
lyingbug 4328ab26a9 feat(plugin): code plugins — extension protocol, Go SDK, plugin host, web search and data source adapters (#3720)
* feat(pluginsdk): extension protocol v1, Go SDK and conformance suite
* feat(plugin): run code plugins in an embedded plugin host
* feat(plugin): remote adapters for web search and data sources
* fix(plugin): show plugin errors by their message
* feat(frontend): plugin connectors and web search providers in the UI
* docs(pluginsdk): how to write, package, test and install a plugin
* fix(plugin): gofmt two files and read openapi.yaml line-ending agnostic
* fix(plugin): mark a host plugin ready before Activate returns
2026-09-26 14:45:15 +08:00

72 lines
2.4 KiB
Go

package pluginapi
import (
"encoding/json"
"time"
)
// Envelope is the body of every call. Plugins must be stateless: everything
// about the tenant comes in the envelope, and credentials must not be cached
// across calls.
type Envelope struct {
Context Context `json:"context"`
Config Config `json:"config"`
// Input is the endpoint-specific request, such as a SearchInput.
Input json.RawMessage `json:"input,omitempty"`
}
// Context describes who is calling and until when.
type Context struct {
TenantID uint64 `json:"tenantId"`
UserID string `json:"userId,omitempty"`
Locale string `json:"locale,omitempty"`
RequestID string `json:"requestId,omitempty"`
// Deadline is when WeKnora stops waiting; plugins should give up by then.
Deadline *time.Time `json:"deadline,omitempty"`
// Host lets the plugin call back into WeKnora (Host API); absent when
// the plugin was granted no scopes.
Host *HostAccess `json:"host,omitempty"`
}
// HostAccess is where and how a plugin calls the WeKnora Host API.
type HostAccess struct {
URL string `json:"url"`
// Token is a short-lived bearer token bound to this tenant and the
// plugin's granted scopes.
Token string `json:"token"`
}
// Config carries the three configuration scopes separately, secrets already
// decrypted. They are never merged, so a key means the same thing wherever
// it appears.
type Config struct {
// System is the platform-wide configuration (config.system).
System map[string]any `json:"system,omitempty"`
// Tenant is the workspace configuration (config.tenant).
Tenant map[string]any `json:"tenant,omitempty"`
// Instance is the configuration of the integration instance being used:
// a data source, a web search provider.
Instance map[string]any `json:"instance,omitempty"`
}
// Output wraps a successful answer.
type Output struct {
Output json.RawMessage `json:"output"`
}
// Manifest is what GET /v1/manifest answers: enough for WeKnora to check that
// the process it started is the package it installed.
type Manifest struct {
ID string `json:"id"`
Version string `json:"version"`
APIVersion string `json:"apiVersion"`
// Contributes lists the contribution IDs the process serves per
// extension point, e.g. {"connectors": ["rss"]}.
Contributes map[string][]string `json:"contributes"`
}
// Health is what GET /v1/health answers.
type Health struct {
Status string `json:"status"` // "ok"
}