Documentation
¶
Overview ¶
Package datasource implements Fetch over a declarative protocol/datasource DataSource. It composes four pluggable concerns:
- Backend — how rows are obtained (MCP, resource, feed, or inline adapters).
- Projection — forge selectors project the backend result into rows.
- Cache — per-user/conversation/global memoisation with TTL.
- Identity — carried in ctx; never a method arg.
All public entry points (HTTP handler, internal MCP tool, scheduler) go through Fetch. There are no per-datasource or per-MCP-server code paths.
Index ¶
- Constants
- func WithIdentity(ctx context.Context, user, conversation string) context.Context
- func WithUnboundWindowProviderGuard(ctx context.Context, providers []string) context.Context
- type DefinitionAuthorizer
- type FeedRefResolver
- type FetchOptions
- type Identity
- type IdentityFunc
- type MCPResourceReader
- type MemoryStore
- type NativeComponentTransport
- type NativeMCPComponentDispatcher
- func (d *NativeMCPComponentDispatcher) ExecuteComponent(context.Context, string, string, windowprotocol.ComponentBinding, ...) (json.RawMessage, error)
- func (d *NativeMCPComponentDispatcher) IsComponentProducer(string) bool
- func (d *NativeMCPComponentDispatcher) ObserveComponent(context.Context, string, string, windowprotocol.ComponentBinding) (windowprotocol.ComponentBinding, error)
- type NewDeliveryPreparer
- type Options
- type OriginalDelivery
- type PreparedDelivery
- type ProviderExecutor
- type ResourceDefinitionResolver
- type ResourceRevalidator
- type Service
- func (s *Service) Fetch(ctx context.Context, id string, inputs map[string]interface{}, ...) (result *dsproto.FetchResult, resultErr error)
- func (s *Service) FetchPublished(ctx context.Context, ds *dsproto.DataSource, inputs map[string]interface{}, ...) (result *dsproto.FetchResult, fetchErr error)
- func (s *Service) InvalidateCache(ctx context.Context, id, inputsHash string) error
- func (s *Service) InvalidateDefinitionCache(ctx context.Context, ds *dsproto.DataSource, inputsHash string) error
- type Store
- type ToolExecutor
Constants ¶
const ( CtxUserKey identityKey = "agently.identity.user" CtxConversationKey identityKey = "agently.identity.conversation" )
Variables ¶
This section is empty.
Functions ¶
func WithIdentity ¶
WithIdentity returns ctx with explicit user + conversation identifiers. Useful from HTTP handlers and tests that don't use the full runtime auth stack.
func WithUnboundWindowProviderGuard ¶ added in v0.1.57
WithUnboundWindowProviderGuard marks an unbound UI window fetch with the host-configured cohort providers. Browser parameters cannot set this value. The guard is checked only against a freshly revalidated resource pin.
Types ¶
type DefinitionAuthorizer ¶ added in v0.1.57
type FeedRefResolver ¶
type FeedRefResolver interface {
ResolveFeed(ctx context.Context, feedID string) (interface{}, error)
}
FeedRefResolver resolves a feed_ref backend to its already-emitted payload. Implementation lives in sdk layer (feeds); service/datasource keeps the interface here so the core has no import cycle.
type FetchOptions ¶
type FetchOptions struct {
SelectionBinding *identity.SelectionBinding
WindowParameters map[string]any
// ResourceProof is opaque provider provenance for a standalone datasource.
// The provider still verifies the signature and fresh resource authorization.
ResourceProof *primitive.ExecutionProof
Target *types.WindowTarget
Resource *identity.ResolvedResource
// BypassCache forces a fresh backend call and writes the result back
// into cache.
BypassCache bool
// WriteThrough (with BypassCache=false) means: on hit, still kick off
// a background refresh if stale-while-revalidate is set. When used as
// a prewarm, set BypassCache=true.
WriteThrough bool
}
FetchOptions are per-call overrides carried on the wire.
type Identity ¶
Identity is the cache-key identity extracted from ctx. It is never used for auth decisions — auth is already attached to ctx by the time Fetch runs.
type IdentityFunc ¶
IdentityFunc extracts a cache-key identity (user, conversation) from ctx. Tests and non-HTTP callers can supply their own; the default reads well-known keys from ctx.
type MCPResourceReader ¶ added in v0.1.57
type MCPResourceReader interface {
ReadResource(context.Context, string, string) (json.RawMessage, error)
}
MCPResourceReader reads authored resource URIs through an admitted MCP connection. The host owns credentials, provider identity, authorization and original leases; implementations must return JSON and never derive a network endpoint from uri.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is a minimal thread-safe Store implementation suitable for tests and for callers that manage datasources in-process. Production wiring loads from extension/forge/datasources/*.yaml via the workspace repository; that repository's List() output feeds MemoryStore.Replace.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(id string) (*dsproto.DataSource, bool)
Get fetches a datasource by id.
func (*MemoryStore) List ¶
func (s *MemoryStore) List() []string
List returns a snapshot of known datasource ids.
func (*MemoryStore) Put ¶
func (s *MemoryStore) Put(ds *dsproto.DataSource)
Put registers a datasource.
func (*MemoryStore) Replace ¶
func (s *MemoryStore) Replace(items []*dsproto.DataSource)
Replace swaps the full set of datasources atomically.
type NativeComponentTransport ¶ added in v0.1.57
type NativeComponentTransport interface {
ObserveNativeComponent(context.Context, string, string) (windowprotocol.ComponentBinding, error)
ExecuteNativeComponent(context.Context, string, string, windowprotocol.ComponentBinding, map[string]interface{}) (json.RawMessage, error)
}
NativeComponentTransport is the deprecated client-bound component API. It is retained only so legacy callers receive an explicit migration error.
type NativeMCPComponentDispatcher ¶ added in v0.1.57
type NativeMCPComponentDispatcher struct{}
func NewNativeMCPComponentDispatcher
deprecated
added in
v0.1.57
func NewNativeMCPComponentDispatcher(NativeComponentTransport, []string) (*NativeMCPComponentDispatcher, error)
Deprecated: MCP wire component pins are unsupported. A pinned workflow must use provider-owned resource/datasource resolution and its declared fetch API.
func (*NativeMCPComponentDispatcher) ExecuteComponent ¶ added in v0.1.57
func (d *NativeMCPComponentDispatcher) ExecuteComponent(context.Context, string, string, windowprotocol.ComponentBinding, map[string]interface{}) (json.RawMessage, error)
func (*NativeMCPComponentDispatcher) IsComponentProducer ¶ added in v0.1.57
func (d *NativeMCPComponentDispatcher) IsComponentProducer(string) bool
func (*NativeMCPComponentDispatcher) ObserveComponent ¶ added in v0.1.57
func (d *NativeMCPComponentDispatcher) ObserveComponent(context.Context, string, string, windowprotocol.ComponentBinding) (windowprotocol.ComponentBinding, error)
type NewDeliveryPreparer ¶ added in v0.1.57
type NewDeliveryPreparer func(context.Context, OriginalDelivery) (context.Context, *PreparedDelivery, error)
NewDeliveryPreparer must verify the full original signed selection, fresh canonical actor, current namespace exposure and exact candidate, then mint fresh target/provider proofs. It must never retry a business operation. The returned context must derive from the supplied context to preserve managed MCP credentials, cache identity, conversation, and operation values. It may refresh trusted values but must not substitute an ambient/background context.
type Options ¶
type Options struct {
// NewDeliveryPreparer is optional trusted server wiring; never a wire callback.
NewDeliveryPreparer NewDeliveryPreparer
// ReadSequence owns pure PRE/POST metadata facts; dispatch barriers end PRE.
ReadSequence func(context.Context) (context.Context, func() error, error)
ReadContext func(context.Context) (context.Context, error)
ResourceReader MCPResourceReader
ProviderExecute ProviderExecutor
ExecutionContext func(context.Context) context.Context
ResolveDefinition ResourceDefinitionResolver
PermissionResolver permittedview.Resolver
ComponentDispatcher windowprotocol.ComponentDispatcher
ResolveResource ResourceRevalidator
AuthorizeDefinition DefinitionAuthorizer
Store Store
Executor ToolExecutor
Identity IdentityFunc // if nil, uses defaultIdentity (reads generic ctx keys)
FeedRef FeedRefResolver
Now func() time.Time // for tests; defaults to time.Now
// Authorize is checked on every fetch, including cache hits. The host
// resolves datasource identity and exact inputs from trusted mappings.
Authorize func(context.Context, string, map[string]interface{}) error
// DisableCache prevents a prior account's result from being reused while
// account-bound authorization is active and no account-aware cache key exists.
DisableCache bool
}
type OriginalDelivery ¶ added in v0.1.57
type OriginalDelivery struct {
Resource *identity.ResolvedResource
Target *types.WindowTarget
ResourceProof *primitive.ExecutionProof
SelectionBinding *identity.SelectionBinding
WindowParameters map[string]any
}
OriginalDelivery holds immutable selection provenance for a new interaction. Inputs and historical facts remain outside this preparation contract.
type PreparedDelivery ¶ added in v0.1.57
type PreparedDelivery struct {
Resource *identity.ResolvedResource
Target *types.WindowTarget
ResourceProof *primitive.ExecutionProof
}
PreparedDelivery is a detached, freshly verified artifact delivery context. Preparation grants no read/write business permission; managing MCP execution remains authoritative for each operation.
type ProviderExecutor ¶ added in v0.1.57
type ProviderExecutor func(context.Context, *dsproto.DataSource, map[string]interface{}) (json.RawMessage, error)
type ResourceDefinitionResolver ¶ added in v0.1.57
type ResourceDefinitionResolver func(context.Context, identity.ResolvedResource, *types.WindowTarget, string) (*dsproto.DataSource, error)
type ResourceRevalidator ¶ added in v0.1.57
type ResourceRevalidator func(context.Context, identity.ResolvedResource) (*identity.ResolvedResource, error)
Options are the construction options for New. DefinitionAuthorizer binds execution to a resolved resource's exact backend descriptor. It runs before dispatch/cache access and before returning rows.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the public entry point. Construct with New, then call Fetch.
func (*Service) Fetch ¶
func (s *Service) Fetch(ctx context.Context, id string, inputs map[string]interface{}, opts FetchOptions) (result *dsproto.FetchResult, resultErr error)
Fetch resolves the datasource by id and returns a projected result. The caller's identity is read from ctx by the configured IdentityFunc; auth to the upstream MCP server is already attached to ctx by the tool registry.
func (*Service) FetchPublished ¶ added in v0.1.57
func (s *Service) FetchPublished(ctx context.Context, ds *dsproto.DataSource, inputs map[string]interface{}, windowParameters map[string]any) (result *dsproto.FetchResult, fetchErr error)
FetchPublished executes an exact datasource descriptor from an admitted, immutable top-level window artifact. The caller must first select it from a trusted server-side window binding and recheck that admission before release. This path does no resource discovery, definition lookup, or row cache read. Managing MCP execution remains the business authorization boundary.
func (*Service) InvalidateCache ¶
InvalidateCache drops all entries for a datasource in the caller's scope. When inputsHash is non-empty, only the entry matching that hash is dropped.
func (*Service) InvalidateDefinitionCache ¶ added in v0.1.57
func (s *Service) InvalidateDefinitionCache(ctx context.Context, ds *dsproto.DataSource, inputsHash string) error
InvalidateDefinitionCache uses a caller's freshly resolved definition without publishing it into a shared datasource registry.
type Store ¶
type Store interface {
Get(id string) (*dsproto.DataSource, bool)
}
Store is the workspace-scoped registry of loaded datasources.
type ToolExecutor ¶
type ToolExecutor interface {
// Execute calls an MCP tool by fully qualified name "service:method"
// with args and returns the raw JSON string result (the registry's
// documented return type). ctx carries identity (auth token is
// attached by the registry via WithAuthTokenContext).
Execute(ctx context.Context, name string, args map[string]interface{}) (string, error)
}
ToolExecutor is the seam to invoke an MCP tool. In production this is wired to internal/tool/registry.Registry.Execute which dispatches under the caller's ctx identity. Tests can supply an in-memory stub.