v1

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 81 Imported by: 0

Documentation

Overview

Package v1 - duplicate detection handlers for P2-C002.

Package v1 - knowledge graph handlers for P3-C001.

Package v1 - review system handlers for P3-C002.

Package v1 provides the ChatAppService handlers for chat app integrations.

Package v1 provides chat channel factory and initialization.

Index

Constants

View Source
const (
	// The upload memory buffer is 32 MiB.
	// It should be kept low, so RAM usage doesn't get out of control.
	// This is unrelated to maximum upload size limit, which is now set through system setting.
	MaxUploadBufferSizeBytes = 32 << 20
	MebiByte                 = 1024 * 1024
	// ThumbnailCacheFolder is the folder name where the thumbnail images are stored.
	ThumbnailCacheFolder = ".thumbnail_cache"
)
View Source
const (
	// DefaultPageSize is the default page size for requests.
	DefaultPageSize = 10
	// MaxPageSize is the maximum page size for requests.
	MaxPageSize = 1000
)
View Source
const (
	InstanceSettingNamePrefix  = "instance/settings/"
	UserNamePrefix             = "users/"
	MemoNamePrefix             = "memos/"
	AttachmentNamePrefix       = "attachments/"
	ReactionNamePrefix         = "reactions/"
	InboxNamePrefix            = "inboxes/"
	IdentityProviderNamePrefix = "identity-providers/"
	ActivityNamePrefix         = "activities/"
	WebhookNamePrefix          = "webhooks/"
)
View Source
const (
	ShortcutNamePrefix            = "shortcuts/"
	PersonalAccessTokenNamePrefix = "personalAccessTokens/"
	SettingNamePrefix             = "settings/"
)
View Source
const DefaultHistoryRetention = 10

Default history retention count for router memory service.

View Source
const MaxBlockLimit = 100

MaxBlockLimit is the maximum number of blocks to return in a single request.

Variables

View Source
var PublicMethods = map[string]struct{}{

	"/memos.api.v1.AuthService/SignIn":       {},
	"/memos.api.v1.AuthService/RefreshToken": {},

	"/memos.api.v1.InstanceService/GetInstanceProfile": {},
	"/memos.api.v1.InstanceService/GetInstanceSetting": {},

	"/memos.api.v1.UserService/CreateUser":       {},
	"/memos.api.v1.UserService/GetUser":          {},
	"/memos.api.v1.UserService/GetUserAvatar":    {},
	"/memos.api.v1.UserService/GetUserStats":     {},
	"/memos.api.v1.UserService/ListAllUserStats": {},
	"/memos.api.v1.UserService/SearchUsers":      {},

	"/memos.api.v1.IdentityProviderService/ListIdentityProviders": {},

	"/memos.api.v1.MemoService/GetMemo":          {},
	"/memos.api.v1.MemoService/ListMemos":        {},
	"/memos.api.v1.MemoService/ListMemoComments": {},
}

PublicMethods defines API endpoints that don't require authentication. All other endpoints require a valid session or access token.

This is the SINGLE SOURCE OF TRUTH for public endpoints. Both Connect interceptor and gRPC-Gateway interceptor use this map.

Format: Full gRPC procedure path as returned by req.Spec().Procedure (Connect) or info.FullMethod (gRPC interceptor).

View Source
var SupportedThumbnailMimeTypes = []string{
	"image/png",
	"image/jpeg",
}

Functions

func ExtractActivityIDFromName

func ExtractActivityIDFromName(name string) (int32, error)

func ExtractAttachmentUIDFromName

func ExtractAttachmentUIDFromName(name string) (string, error)

ExtractAttachmentUIDFromName returns the attachment UID from a resource name.

func ExtractIdentityProviderIDFromName

func ExtractIdentityProviderIDFromName(name string) (int32, error)

func ExtractInboxIDFromName

func ExtractInboxIDFromName(name string) (int32, error)

ExtractInboxIDFromName returns the inbox ID from a resource name.

func ExtractInstanceSettingKeyFromName

func ExtractInstanceSettingKeyFromName(name string) (string, error)

func ExtractMemoReactionIDFromName

func ExtractMemoReactionIDFromName(name string) (string, int32, error)

ExtractMemoReactionIDFromName returns the memo UID and reaction ID from a resource name. e.g., "memos/abc/reactions/123" -> ("abc", 123).

func ExtractMemoUIDFromName

func ExtractMemoUIDFromName(name string) (string, error)

ExtractMemoUIDFromName returns the memo UID from a resource name. e.g., "memos/uuid" -> "uuid".

func ExtractNotificationIDFromName

func ExtractNotificationIDFromName(name string) (int32, error)

ExtractNotificationIDFromName extracts the notification ID from a resource name. Expected format: users/{user_id}/notifications/{notification_id}.

func ExtractUserAndPATIDFromName added in v0.101.0

func ExtractUserAndPATIDFromName(name string) (int32, string, error)

ExtractUserAndPATIDFromName extracts user ID and token ID from "users/{user}/personalAccessTokens/{tokenID}".

func ExtractUserAndSettingKeyFromName added in v0.101.0

func ExtractUserAndSettingKeyFromName(name string) (int32, string, error)

ExtractUserAndSettingKeyFromName extracts user ID and setting key from "users/{user}/settings/{key}".

func ExtractUserAndShortcutIDFromName added in v0.101.0

func ExtractUserAndShortcutIDFromName(name string) (int32, string, error)

ExtractUserAndShortcutIDFromName extracts user ID and shortcut ID from "users/{user}/shortcuts/{shortcut}".

func ExtractUserAndWebhookIDFromName added in v0.101.0

func ExtractUserAndWebhookIDFromName(name string) (int32, string, error)

ExtractUserAndWebhookIDFromName extracts user ID and webhook ID from "users/{user}/webhooks/{webhook}".

func ExtractUserIDAndSettingKeyFromName

func ExtractUserIDAndSettingKeyFromName(name string) (int32, string, error)

ExtractUserIDAndSettingKeyFromName extracts user ID and setting key from resource name. e.g., "users/123/settings/general" -> 123, "general". Delegates to the standardized resource name extractor.

func ExtractUserIDFromName

func ExtractUserIDFromName(name string) (int32, error)

ExtractUserIDFromName returns the uid from a resource name.

func ExtractWebhookIDFromResourceName added in v0.101.0

func ExtractWebhookIDFromResourceName(name string) string

ExtractWebhookIDFromResourceName extracts webhook ID from "users/{user}/webhooks/{webhook_id}". Lightweight variant that only returns the webhook ID.

func GetNameParentTokens

func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error)

GetNameParentTokens returns the tokens from a resource name.

func IsPublicMethod

func IsPublicMethod(procedure string) bool

IsPublicMethod checks if a procedure path is public (no authentication required). Returns true for public methods, false for protected methods.

func SaveAttachmentBlob

func SaveAttachmentBlob(ctx context.Context, profile *profile.Profile, stores *store.Store, create *store.Attachment) error

SaveAttachmentBlob save the blob of attachment based on the storage config. For personal assistant, always uses local storage.

func SetResponseHeader

func SetResponseHeader(ctx context.Context, key, value string) error

SetResponseHeader sets a header in the response.

This function works for both gRPC and Connect protocols:

  • For gRPC: Uses grpc.SetHeader to set headers in gRPC metadata
  • For Connect: Stores in HeaderCarrier for Connect wrapper to apply later

The protocol is automatically detected based on whether a HeaderCarrier exists in the context (injected by Connect wrappers).

func WithHeaderCarrier

func WithHeaderCarrier(ctx context.Context) context.Context

WithHeaderCarrier adds a header carrier to the context.

Types

type AIService

type AIService struct {
	v1pb.UnimplementedAIServiceServer
	RerankerService  pluginai.RerankerService
	EmbeddingService pluginai.EmbeddingService
	LLMService       pluginai.LLMService
	IntentLLMService pluginai.LLMService // Simple tasks: title, summary, tags

	AdaptiveRetriever      *retrieval.AdaptiveRetriever
	IntentClassifierConfig *pluginai.IntentClassifierConfig
	UniversalParrotConfig  *pluginai.UniversalParrotConfig // Phase 2: Config-driven parrots

	Store *store.Store

	TitleGenerator *pluginai.TitleGenerator // Conversation title generator
	EmbeddingModel string
	// contains filtered or unexported fields
}

AIService provides AI-powered features for memo management.

func (*AIService) AddContextSeparator

func (s *AIService) AddContextSeparator(ctx context.Context, req *v1pb.AddContextSeparatorRequest) (*emptypb.Empty, error)

func (*AIService) AppendEvent added in v0.94.0

func (s *AIService) AppendEvent(ctx context.Context, req *v1pb.AppendEventRequest) (*emptypb.Empty, error)

AppendEvent appends an event to the block's event stream.

func (*AIService) AppendUserInput added in v0.94.0

func (s *AIService) AppendUserInput(ctx context.Context, req *v1pb.AppendUserInputRequest) (*emptypb.Empty, error)

AppendUserInput appends a user input to an existing block.

func (*AIService) Chat

func (s *AIService) Chat(req *v1pb.ChatRequest, stream v1pb.AIService_ChatServer) error

Chat streams a chat response with AI agents. Emits events for conversation persistence (handled by ConversationService).

func (*AIService) ClearConversationMessages

func (s *AIService) ClearConversationMessages(ctx context.Context, req *v1pb.ClearConversationMessagesRequest) (*emptypb.Empty, error)

ClearConversationMessages deletes all blocks in a conversation.

func (*AIService) Close added in v0.93.0

func (s *AIService) Close(timeout time.Duration) error

Close gracefully shuts down the AI service, including the persister and router service.

func (*AIService) CreateAIConversation

func (s *AIService) CreateAIConversation(ctx context.Context, req *v1pb.CreateAIConversationRequest) (*v1pb.AIConversation, error)

func (*AIService) CreateBlock added in v0.94.0

func (s *AIService) CreateBlock(ctx context.Context, req *v1pb.CreateBlockRequest) (*v1pb.Block, error)

CreateBlock creates a new conversation block.

func (*AIService) DeleteAIConversation

func (s *AIService) DeleteAIConversation(ctx context.Context, req *v1pb.DeleteAIConversationRequest) (*emptypb.Empty, error)

func (*AIService) DeleteBlock added in v0.94.0

func (s *AIService) DeleteBlock(ctx context.Context, req *v1pb.DeleteBlockRequest) (*emptypb.Empty, error)

DeleteBlock deletes a block.

func (*AIService) DeleteBranch added in v0.94.0

func (s *AIService) DeleteBranch(ctx context.Context, req *v1pb.DeleteBranchRequest) (*emptypb.Empty, error)

DeleteBranch deletes a block and all its descendants.

func (*AIService) DetectDuplicates

DetectDuplicates checks for duplicate or related memos.

func (*AIService) ForkBlock added in v0.94.0

func (s *AIService) ForkBlock(ctx context.Context, req *v1pb.ForkBlockRequest) (*v1pb.Block, error)

ForkBlock creates a new block as a branch from an existing block.

func (*AIService) Format added in v0.100.0

Format formats user content into structured Markdown.

func (*AIService) GenerateConversationTitle added in v0.94.0

func (*AIService) GetAIConversation

func (s *AIService) GetAIConversation(ctx context.Context, req *v1pb.GetAIConversationRequest) (*v1pb.AIConversation, error)

func (*AIService) GetBlock added in v0.94.0

func (s *AIService) GetBlock(ctx context.Context, req *v1pb.GetBlockRequest) (*v1pb.Block, error)

GetBlock retrieves a specific block.

func (*AIService) GetCostStats added in v0.93.0

func (s *AIService) GetCostStats(ctx context.Context, req *v1pb.GetCostStatsRequest) (*v1pb.CostStats, error)

GetCostStats retrieves aggregated cost statistics for the user.

func (*AIService) GetDueReviews

GetDueReviews returns memos that are due for review.

func (*AIService) GetKnowledgeGraph

GetKnowledgeGraph returns the knowledge graph for the current user.

func (*AIService) GetRelatedMemos

GetRelatedMemos finds memos related to a specific memo.

func (*AIService) GetReviewStats

GetReviewStats returns review statistics for the current user.

func (*AIService) GetSessionStats added in v0.93.0

func (s *AIService) GetSessionStats(ctx context.Context, req *v1pb.GetSessionStatsRequest) (*v1pb.SessionStats, error)

GetSessionStats retrieves statistics for a specific session.

func (*AIService) GetUserCostSettings added in v0.93.0

func (s *AIService) GetUserCostSettings(ctx context.Context, _ *emptypb.Empty) (*v1pb.UserCostSettings, error)

GetUserCostSettings retrieves user-specific cost control settings.

func (*AIService) IsEnabled

func (s *AIService) IsEnabled() bool

IsEnabled returns whether AI features are enabled. For basic features (embedding, search), only EmbeddingService is required. For Agent features (Memo, Schedule, etc.), both EmbeddingService and LLMService are required.

func (*AIService) IsLLMEnabled

func (s *AIService) IsLLMEnabled() bool

IsLLMEnabled returns whether LLM features are enabled (required for Agents).

func (*AIService) LinkMemos

LinkMemos creates a bidirectional relation between two memos.

func (*AIService) ListBlockBranches added in v0.94.0

ListBlockBranches lists all child blocks of a given block.

func (*AIService) ListBlocks added in v0.94.0

ListBlocks retrieves blocks for a conversation with pagination support.

func (*AIService) ListSessionStats added in v0.93.0

ListSessionStats retrieves session statistics with pagination.

func (*AIService) MergeMemos

MergeMemos merges source memo into target memo.

func (*AIService) RecordReview

func (s *AIService) RecordReview(ctx context.Context, req *v1pb.RecordReviewRequest) (*emptypb.Empty, error)

RecordReview records a review result and updates spaced repetition state.

func (*AIService) RecordRouterFeedback added in v0.100.0

func (s *AIService) RecordRouterFeedback(ctx context.Context, req *v1pb.RecordRouterFeedbackRequest) (*emptypb.Empty, error)

RecordRouterFeedback records user feedback for routing decisions. This enables HILT (Human-In-The-Loop) learning - the system learns from user corrections.

func (*AIService) SemanticSearch

SemanticSearch performs semantic search on memos.

func (*AIService) SetUserCostSettings added in v0.93.0

func (s *AIService) SetUserCostSettings(ctx context.Context, req *v1pb.SetUserCostSettingsRequest) (*v1pb.UserCostSettings, error)

SetUserCostSettings updates user-specific cost control settings.

func (*AIService) StopChat added in v0.80.0

func (s *AIService) StopChat(ctx context.Context, req *v1pb.StopChatRequest) (*emptypb.Empty, error)

StopChat cancels an ongoing chat stream and terminates the associated session. This is the implementation for session.stop from the async architecture spec. StopChat 取消正在进行的聊天流并终止相关会话。 这是异步架构规范中 session.stop 的实现。

Architecture Note: Session termination is primarily client-driven.

  • The client should cancel the streaming request (gRPC/HTTP) to immediately stop processing.
  • This method emits monitoring events for observability and metrics collection.
  • Active sessions are cleaned up after a 30-minute idle timeout (CCSessionManager).
  • For server-initiated termination in future, consider adding a session registry that maps conversationID to active context.CancelFunc for immediate cancellation.

func (*AIService) SuggestTags

SuggestTags suggests tags for memo content. P2-C001: Uses three-layer progressive strategy (statistics -> rules -> LLM).

func (*AIService) Summary added in v0.100.0

Summary generates a summary for memo content.

func (*AIService) SwitchBranch added in v0.94.0

func (s *AIService) SwitchBranch(ctx context.Context, req *v1pb.SwitchBranchRequest) (*emptypb.Empty, error)

SwitchBranch switches the active branch for a conversation.

func (*AIService) TriggerEnrichment added in v0.100.0

func (s *AIService) TriggerEnrichment(memoID string, content string, title string, userID int32)

TriggerEnrichment triggers async enrichment for a memo. This is called after memo creation/update to generate summary, tags, title.

func (*AIService) UpdateAIConversation

func (s *AIService) UpdateAIConversation(ctx context.Context, req *v1pb.UpdateAIConversationRequest) (*v1pb.AIConversation, error)

func (*AIService) UpdateBlock added in v0.94.0

func (s *AIService) UpdateBlock(ctx context.Context, req *v1pb.UpdateBlockRequest) (*v1pb.Block, error)

UpdateBlock updates a block.

type APIV1Service

type APIV1Service struct {
	// Domain Services
	UserService             *UserService
	MemoService             *MemoService
	AuthService             *AuthService
	AttachmentService       *AttachmentService
	ShortcutService         *ShortcutService
	InstanceService         *InstanceService
	IdentityProviderService *IdentityProviderService
	ActivityService         *ActivityService
	ChatAppService          *ChatAppService
	AIService               *AIService
	ScheduleService         *ScheduleService

	// Shared Infra
	MarkdownService markdown.Service
	Profile         *profile.Profile
	Store           *store.Store

	Secret string
	// contains filtered or unexported fields
}

func NewAPIV1Service

func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store) *APIV1Service

func (*APIV1Service) GetMetricsOverview

func (s *APIV1Service) GetMetricsOverview(c echo.Context) error

GET /api/v1/system/metrics/overview.

func (*APIV1Service) RegisterGateway

func (s *APIV1Service) RegisterGateway(ctx context.Context, echoServer *echo.Echo) error

RegisterGateway registers the gRPC-Gateway and Connect handlers with the given Echo instance.

type ActivityService added in v0.101.0

type ActivityService struct {
	v1pb.UnimplementedActivityServiceServer
	Store *store.Store
}

func (*ActivityService) GetActivity added in v0.101.0

func (s *ActivityService) GetActivity(ctx context.Context, request *v1pb.GetActivityRequest) (*v1pb.Activity, error)

func (*ActivityService) ListActivities added in v0.101.0

type AttachmentService added in v0.101.0

type AttachmentService struct {
	v1pb.UnimplementedAttachmentServiceServer
	Store   *store.Store
	Profile *profile.Profile
	// contains filtered or unexported fields
}

func (*AttachmentService) CreateAttachment added in v0.101.0

func (s *AttachmentService) CreateAttachment(ctx context.Context, request *v1pb.CreateAttachmentRequest) (*v1pb.Attachment, error)

func (*AttachmentService) DeleteAttachment added in v0.101.0

func (s *AttachmentService) DeleteAttachment(ctx context.Context, request *v1pb.DeleteAttachmentRequest) (*emptypb.Empty, error)

func (*AttachmentService) GetAttachment added in v0.101.0

func (s *AttachmentService) GetAttachment(ctx context.Context, request *v1pb.GetAttachmentRequest) (*v1pb.Attachment, error)

func (*AttachmentService) GetAttachmentBlob added in v0.101.0

func (s *AttachmentService) GetAttachmentBlob(attachment *store.Attachment) ([]byte, error)

func (*AttachmentService) ListAttachments added in v0.101.0

func (*AttachmentService) UpdateAttachment added in v0.101.0

func (s *AttachmentService) UpdateAttachment(ctx context.Context, request *v1pb.UpdateAttachmentRequest) (*v1pb.Attachment, error)

type AuthInterceptor

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

AuthInterceptor handles authentication for Connect handlers.

It enforces authentication for all endpoints except those listed in PublicMethods. Role-based authorization (admin checks) remains in the service layer.

func NewAuthInterceptor

func NewAuthInterceptor(store *store.Store, secret string) *AuthInterceptor

NewAuthInterceptor creates a new auth interceptor.

func (*AuthInterceptor) WrapStreamingClient

func (*AuthInterceptor) WrapStreamingHandler

func (*AuthInterceptor) WrapUnary

func (in *AuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc

type AuthService added in v0.101.0

type AuthService struct {
	v1pb.UnimplementedAuthServiceServer
	Store   *store.Store
	Secret  string
	Profile *profile.Profile
}

func (*AuthService) GetCurrentUser added in v0.101.0

GetCurrentUser returns the authenticated user's information. Validates the access token and returns user details.

Authentication: Required (access token). Returns: User information.

func (*AuthService) RefreshToken added in v0.101.0

RefreshToken exchanges a valid refresh token for a new access token.

This endpoint implements refresh token rotation with sliding window sessions: 1. Extracts the refresh token from the HttpOnly cookie (memos_refresh) 2. Validates the refresh token against the database (checking expiry and revocation) 3. Rotates the refresh token: generates a new one with fresh 30-day expiry 4. Generates a new short-lived access token (15 minutes) 5. Sets the new refresh token as HttpOnly cookie 6. Returns the new access token and its expiry time

Token rotation provides: - Sliding window sessions: active users stay logged in indefinitely - Better security: stolen refresh tokens become invalid after legitimate refresh

Authentication: Requires valid refresh token in cookie (public endpoint) Returns: New access token and expiry timestamp.

func (*AuthService) SignIn added in v0.101.0

func (s *AuthService) SignIn(ctx context.Context, request *v1pb.SignInRequest) (*v1pb.SignInResponse, error)

SignIn authenticates a user with credentials and returns tokens. On success, returns an access token and sets a refresh token cookie.

Supports two authentication methods: 1. Password-based authentication (username + password). 2. SSO authentication (OAuth2 authorization code).

Authentication: Not required (public endpoint). Returns: User info, access token, and token expiry.

func (*AuthService) SignOut added in v0.101.0

func (s *AuthService) SignOut(ctx context.Context, _ *v1pb.SignOutRequest) (*emptypb.Empty, error)

SignOut terminates the user's authentication. Revokes the refresh token and clears the authentication cookie.

Authentication: Required (access token). Returns: Empty response on success.

type ChatAppService added in v0.101.0

type ChatAppService struct {
	v1pb.UnimplementedChatAppServiceServer
	Store     *store.Store
	Secret    string
	Profile   *profile.Profile
	AIService *AIService
	// contains filtered or unexported fields
}

func (*ChatAppService) DeleteCredential added in v0.101.0

func (s *ChatAppService) DeleteCredential(ctx context.Context, request *v1pb.DeleteCredentialRequest) (*emptypb.Empty, error)

DeleteCredential removes a chat app binding for the current user.

func (*ChatAppService) GetWebhookInfo added in v0.101.0

func (s *ChatAppService) GetWebhookInfo(ctx context.Context, request *v1pb.GetWebhookInfoRequest) (*v1pb.WebhookInfo, error)

GetWebhookInfo returns webhook configuration for a platform.

func (*ChatAppService) HandleWebhook added in v0.101.0

func (s *ChatAppService) HandleWebhook(ctx context.Context, request *v1pb.WebhookRequest) (*v1pb.WebhookResponse, error)

HandleWebhook processes incoming webhook events from chat platforms.

func (*ChatAppService) ListCredentials added in v0.101.0

ListCredentials returns all registered chat app credentials for the current user.

func (*ChatAppService) RegisterCredential added in v0.101.0

func (s *ChatAppService) RegisterCredential(ctx context.Context, request *v1pb.RegisterCredentialRequest) (*v1pb.Credential, error)

RegisterCredential binds a chat app account to the current user.

func (*ChatAppService) SendMessage added in v0.101.0

func (s *ChatAppService) SendMessage(ctx context.Context, request *v1pb.SendMessageRequest) (*emptypb.Empty, error)

SendMessage sends a message to a chat app channel. This is used internally to deliver AI responses to users.

func (*ChatAppService) UpdateCredential added in v0.101.0

func (s *ChatAppService) UpdateCredential(ctx context.Context, request *v1pb.UpdateCredentialRequest) (*v1pb.Credential, error)

UpdateCredential modifies an existing credential.

type ConnectServiceHandler

type ConnectServiceHandler struct {
	*APIV1Service
}

ConnectServiceHandler wraps APIV1Service to implement Connect handler interfaces. It adapts the existing gRPC service implementations to work with Connect's request/response wrapper types.

This wrapper pattern allows us to: - Reuse existing gRPC service implementations - Support both native gRPC and Connect protocols - Maintain a single source of truth for business logic.

func NewConnectServiceHandler

func NewConnectServiceHandler(svc *APIV1Service) *ConnectServiceHandler

NewConnectServiceHandler creates a new Connect service handler.

func (*ConnectServiceHandler) AddContextSeparator

func (*ConnectServiceHandler) AppendEvent added in v0.94.0

func (*ConnectServiceHandler) AppendUserInput added in v0.94.0

func (*ConnectServiceHandler) Chat

func (*ConnectServiceHandler) ClearConversationMessages

func (*ConnectServiceHandler) CreateAttachment

func (*ConnectServiceHandler) CreateBlock added in v0.94.0

func (*ConnectServiceHandler) CreateMemo

func (*ConnectServiceHandler) CreateMemoComment

func (*ConnectServiceHandler) CreateSchedule

func (*ConnectServiceHandler) CreateShortcut

func (*ConnectServiceHandler) CreateUser

func (*ConnectServiceHandler) CreateUserWebhook

func (*ConnectServiceHandler) DeleteAIConversation

func (*ConnectServiceHandler) DeleteAttachment

func (*ConnectServiceHandler) DeleteBlock added in v0.94.0

func (*ConnectServiceHandler) DeleteBranch added in v0.94.0

func (*ConnectServiceHandler) DeleteIdentityProvider

func (*ConnectServiceHandler) DeleteMemo

func (*ConnectServiceHandler) DeleteMemoReaction

func (*ConnectServiceHandler) DeletePersonalAccessToken

func (*ConnectServiceHandler) DeleteSchedule

func (*ConnectServiceHandler) DeleteShortcut

func (*ConnectServiceHandler) DeleteUser

func (*ConnectServiceHandler) DeleteUserNotification

func (*ConnectServiceHandler) DeleteUserWebhook

func (*ConnectServiceHandler) ForkBlock added in v0.94.0

func (*ConnectServiceHandler) Format added in v0.100.0

func (*ConnectServiceHandler) GenerateConversationTitle added in v0.94.0

func (*ConnectServiceHandler) GetAIConversation

func (*ConnectServiceHandler) GetActivity

func (*ConnectServiceHandler) GetAttachment

func (*ConnectServiceHandler) GetBlock added in v0.94.0

func (*ConnectServiceHandler) GetCostStats added in v0.93.0

func (*ConnectServiceHandler) GetMemo

func (*ConnectServiceHandler) GetParrotSelfCognition

GetParrotSelfCognition returns the metacognitive information of a parrot agent.

func (*ConnectServiceHandler) GetSchedule

func (*ConnectServiceHandler) GetSessionStats added in v0.93.0

func (*ConnectServiceHandler) GetShortcut

func (*ConnectServiceHandler) GetUser

func (*ConnectServiceHandler) GetUserCostSettings added in v0.93.0

func (*ConnectServiceHandler) GetUserSetting

func (*ConnectServiceHandler) GetUserStats

func (*ConnectServiceHandler) LinkMemos

func (*ConnectServiceHandler) ListBlockBranches added in v0.94.0

func (*ConnectServiceHandler) ListBlocks added in v0.94.0

func (*ConnectServiceHandler) ListMemos

func (*ConnectServiceHandler) ListParrots

ListParrots returns all available parrot agents with their metacognitive information.

func (*ConnectServiceHandler) ListSessionStats added in v0.93.0

func (*ConnectServiceHandler) ListUsers

func (*ConnectServiceHandler) MergeMemos

func (*ConnectServiceHandler) RecordReview

func (*ConnectServiceHandler) RecordRouterFeedback added in v0.100.0

func (*ConnectServiceHandler) RegisterConnectHandlers

func (s *ConnectServiceHandler) RegisterConnectHandlers(mux *http.ServeMux, opts ...connect.HandlerOption)

RegisterConnectHandlers registers all Connect service handlers on the given mux.

func (*ConnectServiceHandler) SetMemoAttachments

func (*ConnectServiceHandler) SetMemoRelations

func (*ConnectServiceHandler) SetUserCostSettings added in v0.93.0

func (*ConnectServiceHandler) SignIn

func (*ConnectServiceHandler) SignOut

func (*ConnectServiceHandler) StopChat added in v0.80.0

StopChat cancels an ongoing chat stream and terminates the associated session. StopChat 取消正在进行的聊天流并终止相关会话。

func (*ConnectServiceHandler) Summary added in v0.100.0

func (*ConnectServiceHandler) SwitchBranch added in v0.94.0

func (*ConnectServiceHandler) UpdateAttachment

func (*ConnectServiceHandler) UpdateBlock added in v0.94.0

func (*ConnectServiceHandler) UpdateMemo

func (*ConnectServiceHandler) UpdateSchedule

func (*ConnectServiceHandler) UpdateShortcut

func (*ConnectServiceHandler) UpdateUser

func (*ConnectServiceHandler) UpdateUserSetting

func (*ConnectServiceHandler) UpdateUserWebhook

func (*ConnectServiceHandler) UpsertMemoReaction

type HeaderCarrier

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

HeaderCarrier stores headers that need to be set in the response.

Problem: The codebase supports two protocols simultaneously:

  • Native gRPC: Uses grpc.SetHeader() to set response headers
  • Connect-RPC: Uses connect.Response.Header().Set() to set response headers

Solution: HeaderCarrier provides a protocol-agnostic way to set headers.

  • Service methods call SetResponseHeader() regardless of protocol
  • For gRPC requests: SetResponseHeader uses grpc.SetHeader directly
  • For Connect requests: SetResponseHeader stores headers in HeaderCarrier
  • Connect wrappers extract headers from HeaderCarrier and apply to response

This allows service methods to work with both protocols without knowing which one is being used.

func GetHeaderCarrier

func GetHeaderCarrier(ctx context.Context) *HeaderCarrier

GetHeaderCarrier retrieves the header carrier from the context. Returns nil if no carrier is present.

func (*HeaderCarrier) All

func (h *HeaderCarrier) All() map[string]string

All returns all headers.

func (*HeaderCarrier) Get

func (h *HeaderCarrier) Get(key string) string

Get retrieves a header from the carrier.

func (*HeaderCarrier) Set

func (h *HeaderCarrier) Set(key, value string)

Set adds a header to the carrier.

type IdentityProviderService added in v0.101.0

type IdentityProviderService struct {
	v1pb.UnimplementedIdentityProviderServiceServer
	Store *store.Store
}

func (*IdentityProviderService) CreateIdentityProvider added in v0.101.0

func (*IdentityProviderService) DeleteIdentityProvider added in v0.101.0

func (s *IdentityProviderService) DeleteIdentityProvider(ctx context.Context, request *v1pb.DeleteIdentityProviderRequest) (*emptypb.Empty, error)

func (*IdentityProviderService) GetIdentityProvider added in v0.101.0

func (*IdentityProviderService) ListIdentityProviders added in v0.101.0

func (*IdentityProviderService) UpdateIdentityProvider added in v0.101.0

type InstanceService added in v0.101.0

type InstanceService struct {
	v1pb.UnimplementedInstanceServiceServer
	Store     *store.Store
	Profile   *profile.Profile
	AIService *AIService
}

func (*InstanceService) GetInstanceOwner added in v0.101.0

func (s *InstanceService) GetInstanceOwner(ctx context.Context) (*v1pb.User, error)

func (*InstanceService) GetInstanceProfile added in v0.101.0

GetInstanceProfile returns the instance profile.

func (*InstanceService) GetInstanceSetting added in v0.101.0

func (s *InstanceService) GetInstanceSetting(ctx context.Context, request *v1pb.GetInstanceSettingRequest) (*v1pb.InstanceSetting, error)

func (*InstanceService) UpdateInstanceSetting added in v0.101.0

func (s *InstanceService) UpdateInstanceSetting(ctx context.Context, request *v1pb.UpdateInstanceSettingRequest) (*v1pb.InstanceSetting, error)

type LoggingInterceptor

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

LoggingInterceptor logs Connect RPC requests with appropriate log levels.

Log levels: - INFO: Successful requests and expected client errors (not found, permission denied, etc.) - ERROR: Server errors (internal, unavailable, etc.)

func NewLoggingInterceptor

func NewLoggingInterceptor(logStacktrace bool) *LoggingInterceptor

NewLoggingInterceptor creates a new logging interceptor.

func (*LoggingInterceptor) WrapStreamingClient

func (*LoggingInterceptor) WrapStreamingHandler

func (*LoggingInterceptor) WrapUnary

type MemoService added in v0.101.0

type MemoService struct {
	v1pb.UnimplementedMemoServiceServer
	Store           *store.Store
	AIService       *AIService
	MarkdownService markdown.Service
	Profile         *profile.Profile
}

func (*MemoService) CreateMemo added in v0.101.0

func (s *MemoService) CreateMemo(ctx context.Context, request *v1pb.CreateMemoRequest) (*v1pb.Memo, error)

func (*MemoService) CreateMemoComment added in v0.101.0

func (s *MemoService) CreateMemoComment(ctx context.Context, request *v1pb.CreateMemoCommentRequest) (*v1pb.Memo, error)

func (*MemoService) DeleteMemo added in v0.101.0

func (s *MemoService) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoRequest) (*emptypb.Empty, error)

func (*MemoService) DeleteMemoReaction added in v0.101.0

func (s *MemoService) DeleteMemoReaction(ctx context.Context, request *v1pb.DeleteMemoReactionRequest) (*emptypb.Empty, error)

func (*MemoService) DispatchMemoCreatedWebhook added in v0.101.0

func (s *MemoService) DispatchMemoCreatedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoCreatedWebhook dispatches webhook when memo is created.

func (*MemoService) DispatchMemoDeletedWebhook added in v0.101.0

func (s *MemoService) DispatchMemoDeletedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoDeletedWebhook dispatches webhook when memo is deleted.

func (*MemoService) DispatchMemoUpdatedWebhook added in v0.101.0

func (s *MemoService) DispatchMemoUpdatedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoUpdatedWebhook dispatches webhook when memo is updated.

func (*MemoService) GetMemo added in v0.101.0

func (s *MemoService) GetMemo(ctx context.Context, request *v1pb.GetMemoRequest) (*v1pb.Memo, error)

func (*MemoService) GetRelatedMemos added in v0.101.0

GetRelatedMemos returns related memos for a given memo. P1-C003: Related memo recommendations based on semantic similarity and tag co-occurrence.

func (*MemoService) ListMemoAttachments added in v0.101.0

func (*MemoService) ListMemoComments added in v0.101.0

func (*MemoService) ListMemoReactions added in v0.101.0

func (*MemoService) ListMemoRelations added in v0.101.0

func (*MemoService) ListMemos added in v0.101.0

func (s *MemoService) ListMemos(ctx context.Context, request *v1pb.ListMemosRequest) (*v1pb.ListMemosResponse, error)

func (*MemoService) SearchWithHighlight added in v0.101.0

SearchWithHighlight searches memos and returns results with keyword highlighting. This is an AI-powered feature that requires PostgreSQL.

func (*MemoService) SetMemoAttachments added in v0.101.0

func (s *MemoService) SetMemoAttachments(ctx context.Context, request *v1pb.SetMemoAttachmentsRequest) (*emptypb.Empty, error)

func (*MemoService) SetMemoRelations added in v0.101.0

func (s *MemoService) SetMemoRelations(ctx context.Context, request *v1pb.SetMemoRelationsRequest) (*emptypb.Empty, error)

func (*MemoService) UpdateMemo added in v0.101.0

func (s *MemoService) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoRequest) (*v1pb.Memo, error)

func (*MemoService) UpsertMemoReaction added in v0.101.0

func (s *MemoService) UpsertMemoReaction(ctx context.Context, request *v1pb.UpsertMemoReactionRequest) (*v1pb.Reaction, error)

type MetadataInterceptor

type MetadataInterceptor struct{}

MetadataInterceptor converts Connect HTTP headers to gRPC metadata.

This ensures service methods can use metadata.FromIncomingContext() to access headers like User-Agent, X-Forwarded-For, etc., regardless of whether the request came via Connect RPC or gRPC-Gateway.

func NewMetadataInterceptor

func NewMetadataInterceptor() *MetadataInterceptor

NewMetadataInterceptor creates a new metadata interceptor.

func (*MetadataInterceptor) WrapStreamingClient

func (*MetadataInterceptor) WrapStreamingHandler

func (*MetadataInterceptor) WrapUnary

type MetricsOverviewResponse

type MetricsOverviewResponse struct {
	TimeRange     string  `json:"time_range"`
	TotalRequests int64   `json:"total_requests"`
	SuccessRate   float64 `json:"success_rate"`
	AvgLatencyMs  int64   `json:"avg_latency_ms"`
	P50LatencyMs  int64   `json:"p50_latency_ms"`
	P95LatencyMs  int64   `json:"p95_latency_ms"`
	ErrorCount    int64   `json:"error_count"`
	IsMock        bool    `json:"is_mock"`
}

MetricsOverviewResponse represents the overview response of system metrics.

type RecoveryInterceptor

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

RecoveryInterceptor recovers from panics in Connect handlers and returns an internal error.

func NewRecoveryInterceptor

func NewRecoveryInterceptor(logStacktrace bool) *RecoveryInterceptor

NewRecoveryInterceptor creates a new recovery interceptor.

func (*RecoveryInterceptor) WrapStreamingClient

func (*RecoveryInterceptor) WrapStreamingHandler

func (*RecoveryInterceptor) WrapUnary

type ScheduleService

type ScheduleService struct {
	v1pb.UnimplementedScheduleServiceServer

	Store      *store.Store
	LLMService ai.LLMService
}

ScheduleService provides schedule management APIs.

func (*ScheduleService) CheckConflict

CheckConflict checks for schedule conflicts.

func (*ScheduleService) CreateSchedule

func (s *ScheduleService) CreateSchedule(ctx context.Context, req *v1pb.CreateScheduleRequest) (*v1pb.Schedule, error)

CreateSchedule creates a new schedule.

func (*ScheduleService) DeleteSchedule

func (s *ScheduleService) DeleteSchedule(ctx context.Context, req *v1pb.DeleteScheduleRequest) (*emptypb.Empty, error)

DeleteSchedule deletes a schedule.

func (*ScheduleService) GetSchedule

func (s *ScheduleService) GetSchedule(ctx context.Context, req *v1pb.GetScheduleRequest) (*v1pb.Schedule, error)

GetSchedule gets a schedule by name.

func (*ScheduleService) ListSchedules

ListSchedules lists schedules with filters.

func (*ScheduleService) UpdateSchedule

func (s *ScheduleService) UpdateSchedule(ctx context.Context, req *v1pb.UpdateScheduleRequest) (*v1pb.Schedule, error)

UpdateSchedule updates a schedule.

type ShortcutService added in v0.101.0

type ShortcutService struct {
	v1pb.UnimplementedShortcutServiceServer
	Store   *store.Store
	Profile *profile.Profile
}

func (*ShortcutService) CreateShortcut added in v0.101.0

func (s *ShortcutService) CreateShortcut(ctx context.Context, request *v1pb.CreateShortcutRequest) (*v1pb.Shortcut, error)

func (*ShortcutService) DeleteShortcut added in v0.101.0

func (s *ShortcutService) DeleteShortcut(ctx context.Context, request *v1pb.DeleteShortcutRequest) (*emptypb.Empty, error)

func (*ShortcutService) GetShortcut added in v0.101.0

func (s *ShortcutService) GetShortcut(ctx context.Context, request *v1pb.GetShortcutRequest) (*v1pb.Shortcut, error)

func (*ShortcutService) ListShortcuts added in v0.101.0

func (*ShortcutService) UpdateShortcut added in v0.101.0

func (s *ShortcutService) UpdateShortcut(ctx context.Context, request *v1pb.UpdateShortcutRequest) (*v1pb.Shortcut, error)

type UserService added in v0.101.0

type UserService struct {
	v1pb.UnimplementedUserServiceServer
	Store *store.Store
}

func (*UserService) CreatePersonalAccessToken added in v0.101.0

CreatePersonalAccessToken creates a new Personal Access Token (PAT) for a user.

Use cases: - User manually creates token in settings for mobile app - User creates token for CLI tool - User creates token for third-party integration

Token properties: - Random string with memos_pat_ prefix - SHA-256 hash stored in database - Optional expiration time (can be never-expiring) - User-provided description for identification

Security considerations: - Full token is only shown ONCE (in this response) - User should copy and store it securely - Token can be revoked by deleting it from settings

Authentication: Required (session cookie or access token) Authorization: User can only create tokens for themselves.

func (*UserService) CreateUser added in v0.101.0

func (s *UserService) CreateUser(ctx context.Context, request *v1pb.CreateUserRequest) (*v1pb.User, error)

func (*UserService) CreateUserWebhook added in v0.101.0

func (s *UserService) CreateUserWebhook(ctx context.Context, request *v1pb.CreateUserWebhookRequest) (*v1pb.UserWebhook, error)

func (*UserService) DeletePersonalAccessToken added in v0.101.0

func (s *UserService) DeletePersonalAccessToken(ctx context.Context, request *v1pb.DeletePersonalAccessTokenRequest) (*emptypb.Empty, error)

DeletePersonalAccessToken revokes a Personal Access Token.

This endpoint: 1. Removes the token from the user's access tokens list 2. Immediately invalidates the token (subsequent API calls with it will fail)

Use cases: - User revokes a compromised token - User removes token for unused app/device - User cleans up old tokens

Authentication: Required (session cookie or access token) Authorization: User can only delete their own tokens.

func (*UserService) DeleteUser added in v0.101.0

func (s *UserService) DeleteUser(ctx context.Context, request *v1pb.DeleteUserRequest) (*emptypb.Empty, error)

func (*UserService) DeleteUserNotification added in v0.101.0

func (s *UserService) DeleteUserNotification(ctx context.Context, request *v1pb.DeleteUserNotificationRequest) (*emptypb.Empty, error)

DeleteUserNotification permanently deletes a notification. Only the notification owner can delete their notifications.

func (*UserService) DeleteUserWebhook added in v0.101.0

func (s *UserService) DeleteUserWebhook(ctx context.Context, request *v1pb.DeleteUserWebhookRequest) (*emptypb.Empty, error)

func (*UserService) GetUser added in v0.101.0

func (s *UserService) GetUser(ctx context.Context, request *v1pb.GetUserRequest) (*v1pb.User, error)

func (*UserService) GetUserSetting added in v0.101.0

func (s *UserService) GetUserSetting(ctx context.Context, request *v1pb.GetUserSettingRequest) (*v1pb.UserSetting, error)

func (*UserService) GetUserStats added in v0.101.0

func (s *UserService) GetUserStats(ctx context.Context, req *v1pb.GetUserStatsRequest) (*v1pb.UserStats, error)

func (*UserService) ListAllUserStats added in v0.101.0

func (*UserService) ListPersonalAccessTokens added in v0.101.0

ListPersonalAccessTokens retrieves all Personal Access Tokens (PATs) for a user.

Personal Access Tokens are used for: - Mobile app authentication - CLI tool authentication - API client authentication - Any programmatic access requiring Bearer token auth

Security: - Only the token owner can list their tokens - Returns token metadata only (not the actual token value) - Invalid or expired tokens are filtered out

Authentication: Required (session cookie or access token) Authorization: User can only list their own tokens.

func (*UserService) ListUserNotifications added in v0.101.0

ListUserNotifications lists all notifications for a user. Notifications are backed by the inbox storage layer and represent activities that require user attention (e.g., memo comments).

func (*UserService) ListUserSettings added in v0.101.0

func (*UserService) ListUserWebhooks added in v0.101.0

func (*UserService) ListUsers added in v0.101.0

func (s *UserService) ListUsers(ctx context.Context, request *v1pb.ListUsersRequest) (*v1pb.ListUsersResponse, error)

func (*UserService) UpdateUser added in v0.101.0

func (s *UserService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRequest) (*v1pb.User, error)

func (*UserService) UpdateUserNotification added in v0.101.0

func (s *UserService) UpdateUserNotification(ctx context.Context, request *v1pb.UpdateUserNotificationRequest) (*v1pb.UserNotification, error)

UpdateUserNotification updates a notification's status (e.g., marking as read/archived). Only the notification owner can update their notifications.

func (*UserService) UpdateUserSetting added in v0.101.0

func (s *UserService) UpdateUserSetting(ctx context.Context, request *v1pb.UpdateUserSettingRequest) (*v1pb.UserSetting, error)

func (*UserService) UpdateUserWebhook added in v0.101.0

func (s *UserService) UpdateUserWebhook(ctx context.Context, request *v1pb.UpdateUserWebhookRequest) (*v1pb.UserWebhook, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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