ai

package
v1.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2024 License: MPL-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathDocPrefix = "Path Parameters"
	ErrDocPrefix  = "Errors"
)

Variables

View Source
var ErrorCodeMap = map[string]int64{
	"ai_task_limit_reached": 100,
}

Functions

func ParseSQLSchema

func ParseSQLSchema(app *apps.Instance, schema string) (*daemon.SQLCPlugin_Catalog, error)

ParseSQLSchema uses SQLC to parse the migration files for an encore database and returns the parsed catalog

Types

type AIError added in v1.37.0

type AIError struct {
	Message string `json:"message"`
	Code    string `json:"code"`
}

type AINotification

type AINotification struct {
	SubscriptionID string   `json:"subscriptionId,omitempty"`
	Value          any      `json:"value,omitempty"`
	Error          *AIError `json:"error,omitempty"`
	Finished       bool     `json:"finished,omitempty"`
}

AINotification is a wrapper around messages and errors from the encore platform ai service

type AINotifier

type AINotifier func(context.Context, *AINotification) error

type AISessionID

type AISessionID string

type AIStreamMessage

type AIStreamMessage struct {
	Value    TaskMessage
	Error    string
	Finished bool
}

type AIStreamUpdate

type AIStreamUpdate = Result[AIUpdateType]

type AIUpdateType

type AIUpdateType interface {
	IsAIUpdateType()
}

type BaseAIUpdateType

type BaseAIUpdateType struct {
	Type string `graphql:"__typename" json:"type"`
}

func (BaseAIUpdateType) IsAIUpdateType

func (b BaseAIUpdateType) IsAIUpdateType()

type CodeType

type CodeType string
const (
	CodeTypeEndpoint CodeType = "endpoint"
	CodeTypeTypes    CodeType = "types"
)

type Endpoint

type Endpoint struct {
	ID             string         `json:"id,omitempty"`
	Name           string         `json:"name"`
	Doc            string         `json:"doc"`
	Method         string         `json:"method"`
	Visibility     VisibilityType `json:"visibility"`
	Path           PathSegments   `json:"path"`
	RequestType    string         `json:"requestType,omitempty"`
	ResponseType   string         `json:"responseType,omitempty"`
	Errors         []*Error       `json:"errors,omitempty"`
	Types          []*Type        `json:"types,omitempty"`
	Language       string         `json:"language,omitempty"`
	TypeSource     string         `json:"typeSource,omitempty"`
	EndpointSource string         `json:"endpointSource,omitempty"`
}

func (*Endpoint) Auth

func (s *Endpoint) Auth() bool

func (*Endpoint) GraphQL

func (s *Endpoint) GraphQL() *Endpoint

GraphQL scrubs data that is not needed for the graphql client

func (*Endpoint) Render

func (e *Endpoint) Render() string

type EndpointUpdate

type EndpointUpdate struct {
	BaseAIUpdateType
	Service      string         `json:"service,omitempty"`
	Name         string         `json:"name,omitempty"`
	Doc          string         `json:"doc,omitempty"`
	Method       string         `json:"method,omitempty"`
	Visibility   VisibilityType `json:"visibility,omitempty"`
	Path         []PathSegment  `json:"path,omitempty"`
	RequestType  string         `json:"requestType,omitempty"`
	ResponseType string         `json:"responseType,omitempty"`
	Errors       []string       `json:"errors,omitempty"`
}

type Error

type Error struct {
	Code string `json:"code,omitempty"`
	Doc  string `json:"doc,omitempty"`
}

func (Error) DocItem

func (e Error) DocItem() (string, string)

func (Error) String

func (e Error) String() string

type ErrorUpdate

type ErrorUpdate struct {
	BaseAIUpdateType
	Code     string `json:"code,omitempty"`
	Doc      string `json:"doc,omitempty"`
	Service  string `json:"service,omitempty"`
	Endpoint string `json:"endpoint,omitempty"`
}

type LazySubClient

type LazySubClient struct {
	*graphql.SubscriptionClient
	// contains filtered or unexported fields
}

LazySubClient is a wrapper around graphql.SubscriptionClient that starts the client when the first subscription is made. It also stops the client when the last subscription is removed and reconnects when a subscription is added.

func (*LazySubClient) Subscribe

func (l *LazySubClient) Subscribe(query interface{}, variables map[string]interface{}, notify func([]byte, error) error) (string, error)

Subscribe subscribes to a query and calls notify with the result.

type LocalEndpointUpdate

type LocalEndpointUpdate struct {
	Type     string    `json:"type,omitempty"`
	Service  string    `json:"service,omitempty"`
	Endpoint *Endpoint `json:"endpoint,omitempty"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager exposes the ai functionality to the local dashboard

func NewAIManager

func NewAIManager(client *graphql.SubscriptionClient) *Manager

func (*Manager) DefineEndpoints

func (m *Manager) DefineEndpoints(ctx context.Context, appSlug string, sessionID AISessionID, prompt string, md *meta.Data, proposed []Service, notifier AINotifier) (string, error)

func (*Manager) ModifySystemDesign

func (m *Manager) ModifySystemDesign(ctx context.Context, appSlug string, sessionID AISessionID, originalPrompt string, proposed []Service, newPrompt string, md *meta.Data, notifier AINotifier) (string, error)

func (*Manager) ParseCode

func (m *Manager) ParseCode(ctx context.Context, services []Service, app *apps.Instance) (*SyncResult, error)

func (*Manager) PreviewFiles

func (m *Manager) PreviewFiles(ctx context.Context, services []Service, app *apps.Instance) (*PreviewFilesResponse, error)

func (*Manager) ProposeSystemDesign

func (m *Manager) ProposeSystemDesign(ctx context.Context, appSlug, prompt string, md *meta.Data, notifier AINotifier) (string, error)

func (*Manager) Unsubscribe

func (m *Manager) Unsubscribe(id string) error

func (*Manager) UpdateCode

func (m *Manager) UpdateCode(ctx context.Context, services []Service, app *apps.Instance, overwrite bool) (*SyncResult, error)

func (*Manager) WriteFiles

func (m *Manager) WriteFiles(ctx context.Context, services []Service, app *apps.Instance) (*WriteFilesResponse, error)

type PathParamUpdate

type PathParamUpdate struct {
	BaseAIUpdateType
	Service  string `json:"service,omitempty"`
	Endpoint string `json:"endpoint,omitempty"`
	Param    string `json:"param,omitempty"`
	Doc      string `json:"doc,omitempty"`
}

type PathSegment

type PathSegment struct {
	Type      SegmentType       `json:"type,omitempty"`
	Value     *string           `json:"value,omitempty"`
	ValueType *SegmentValueType `json:"valueType,omitempty"`
	Doc       string            `graphql:"-" json:"doc,omitempty"`
}

func (PathSegment) DocItem

func (p PathSegment) DocItem() (string, string)

type PathSegments

type PathSegments []PathSegment

func (PathSegments) Render

func (p PathSegments) Render() (docPath string, goParams []string)

type Pos

type Pos struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

type PreviewFile

type PreviewFile struct {
	Path    paths.RelSlash `json:"path"`
	Content string         `json:"content"`
}

type PreviewFilesResponse

type PreviewFilesResponse struct {
	Files []PreviewFile `json:"files"`
}

type Result

type Result[T any] struct {
	Value    T
	Finished *bool
	Error    *string
}

type SegmentType

type SegmentType string
const (
	SegmentTypeLiteral  SegmentType = "literal"
	SegmentTypeParam    SegmentType = "param"
	SegmentTypeWildcard SegmentType = "wildcard"
	SegmentTypeFallback SegmentType = "fallback"
)

type SegmentValueType

type SegmentValueType string
const SegmentValueTypeString SegmentValueType = "string"

type Service

type Service struct {
	ID        string      `json:"id,omitempty"`
	Name      string      `json:"name,omitempty"`
	Doc       string      `json:"doc,omitempty"`
	Endpoints []*Endpoint `json:"endpoints,omitempty"`
}

func (Service) GetEndpoints

func (s Service) GetEndpoints() []*Endpoint

func (Service) GetName

func (s Service) GetName() string

func (Service) GraphQL

func (s Service) GraphQL() ServiceInput

GraphQL scrubs data that is not needed for the graphql client

type ServiceInput

type ServiceInput Service

ServiceInput is the graphql input type for our queries the graphQL client we use requires the type name to match the graphql type

type ServiceUpdate

type ServiceUpdate struct {
	BaseAIUpdateType
	Name string `json:"name,omitempty"`
	Doc  string `json:"doc,omitempty"`
}

type SessionUpdate

type SessionUpdate struct {
	BaseAIUpdateType
	Id AISessionID
}

type SyncResult

type SyncResult struct {
	Services []Service         `json:"services"`
	Errors   []ValidationError `json:"errors"`
}

type TaskMessage

type TaskMessage struct {
	Type string `graphql:"__typename"`

	ServiceUpdate   `graphql:"... on ServiceUpdate"`
	TypeUpdate      `graphql:"... on TypeUpdate"`
	TypeFieldUpdate `graphql:"... on TypeFieldUpdate"`
	ErrorUpdate     `graphql:"... on ErrorUpdate"`
	EndpointUpdate  `graphql:"... on EndpointUpdate"`
	SessionUpdate   `graphql:"... on SessionUpdate"`
	TitleUpdate     `graphql:"... on TitleUpdate"`
	PathParamUpdate `graphql:"... on PathParamUpdate"`
}

func (*TaskMessage) GetValue

func (u *TaskMessage) GetValue() AIUpdateType

type TitleUpdate

type TitleUpdate struct {
	BaseAIUpdateType
	Title string
}

type Type

type Type struct {
	Name   string       `json:"name,omitempty"`
	Doc    string       `json:"doc,omitempty"`
	Fields []*TypeField `json:"fields,omitempty"`
}

func (*Type) Render

func (s *Type) Render() string

type TypeField

type TypeField struct {
	Name     string         `json:"name,omitempty"`
	WireName string         `json:"wireName,omitempty"`
	Type     string         `json:"type,omitempty"`
	Location apienc.WireLoc `json:"location,omitempty"`
	Doc      string         `json:"doc,omitempty"`
}

type TypeFieldUpdate

type TypeFieldUpdate struct {
	BaseAIUpdateType
	Service  string `json:"service,omitempty"`
	Endpoint string `json:"endpoint,omitempty"`
	Struct   string `json:"struct,omitempty"`
	Name     string `json:"name,omitempty"`
	Type     string `json:"type,omitempty"`
	Doc      string `graphql:"mdoc: doc" json:"doc,omitempty"`
}

type TypeUpdate

type TypeUpdate struct {
	BaseAIUpdateType
	Service  string `json:"service,omitempty"`
	Endpoint string `json:"endpoint,omitempty"`
	Name     string `json:"name,omitempty"`
	Doc      string `graphql:"mdoc: doc" json:"doc,omitempty"`
}

type ValidationError

type ValidationError struct {
	Service  string   `json:"service"`
	Endpoint string   `json:"endpoint"`
	CodeType CodeType `json:"codeType"`
	Message  string   `json:"message"`
	Start    *Pos     `json:"start,omitempty"`
	End      *Pos     `json:"end,omitempty"`
}

ValidationError is a simplified ErrInSrc to return to the dashboard

type VisibilityType

type VisibilityType string
const (
	VisibilityTypePublic  VisibilityType = "public"
	VisibilityTypePrivate VisibilityType = "private"
	VisibilityTypeAuth    VisibilityType = "auth"
)

type WriteFilesResponse

type WriteFilesResponse struct {
	FilesPaths []paths.RelSlash `json:"paths"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL