Files
Memoh/internal/db/sqlc/channels.sql.go
T
AlexMa233 609ca49cf5 feat: matrix support (part 1) (#242)
* feat(channel): add Matrix adapter support

* fix(channel): prevent reasoning leaks in Matrix replies

* fix(channel): persist Matrix sync cursors

* fix(channel): improve Matrix markdown rendering

* fix(channel): support Matrix attachments and multimodal history

* fix(channel): expand Matrix reply media context

* fix(handlers): allow media downloads for chat-access bots

* fix(channel): classify Matrix DMs as direct chats

* fix(channel): auto-join Matrix room invites

* fix(channel): resolve Matrix room aliases for outbound send

* fix(web): use Matrix brand icon in channel badges

Replace the generic Matrix hashtag badge with the official brand asset so channel badges feel recognizable and fit the circular mask cleanly.

* fix(channel): add Matrix room whitelist controls

Let Matrix bots decide whether to auto-join invites and restrict inbound activity to allowed rooms or aliases. Expose the new controls in the web settings UI with line-based whitelist input so access rules stay explicit.

* fix(channel): stabilize Matrix multimodal follow-ups and settings

* fix(flow): avoid gosec panic on byte decoding

* fix: fix golangci-lint

* fix(channel): remove Matrix built-in ACL

* fix(channel): preserve Matrix image captions

* fix(channel): validate Matrix homeserver and sync access

Fail Matrix connections early when the homeserver, access token, or /sync capability is misconfigured so bot health checks surface actionable errors.

* fix(channel): preserve optional toggles and relax Matrix startup validation

* fix(channel): tighten Matrix mention fallback parsing

* fix(flow): skip structured assistant tool-call outputs

* fix(flow): resolve merged resolver duplication

Keep the internal agent resolver implementation after merging main so split helper files do not redeclare flow symbols. Restore user message normalization in sanitize and persistence paths to keep flow tests and command packages building.

* fix(flow): remove unused merged resolver helper

Drop the leftover truncate helper and import from the resolver merge fix so golangci-lint passes again without affecting flow behavior.

---------

Co-authored-by: Acbox Liu <acbox0328@gmail.com>
2026-03-22 21:55:34 +08:00

339 lines
9.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: channels.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteBotChannelConfig = `-- name: DeleteBotChannelConfig :exec
DELETE FROM bot_channel_configs
WHERE bot_id = $1 AND channel_type = $2
`
type DeleteBotChannelConfigParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
}
func (q *Queries) DeleteBotChannelConfig(ctx context.Context, arg DeleteBotChannelConfigParams) error {
_, err := q.db.Exec(ctx, deleteBotChannelConfig, arg.BotID, arg.ChannelType)
return err
}
const getBotChannelConfig = `-- name: GetBotChannelConfig :one
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE bot_id = $1 AND channel_type = $2
LIMIT 1
`
type GetBotChannelConfigParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
}
func (q *Queries) GetBotChannelConfig(ctx context.Context, arg GetBotChannelConfigParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, getBotChannelConfig, arg.BotID, arg.ChannelType)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Disabled,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getBotChannelConfigByExternalIdentity = `-- name: GetBotChannelConfigByExternalIdentity :one
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE channel_type = $1 AND external_identity = $2
LIMIT 1
`
type GetBotChannelConfigByExternalIdentityParams struct {
ChannelType string `json:"channel_type"`
ExternalIdentity pgtype.Text `json:"external_identity"`
}
func (q *Queries) GetBotChannelConfigByExternalIdentity(ctx context.Context, arg GetBotChannelConfigByExternalIdentityParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, getBotChannelConfigByExternalIdentity, arg.ChannelType, arg.ExternalIdentity)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Disabled,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getUserChannelBinding = `-- name: GetUserChannelBinding :one
SELECT id, user_id, channel_type, config, created_at, updated_at
FROM user_channel_bindings
WHERE user_id = $1 AND channel_type = $2
LIMIT 1
`
type GetUserChannelBindingParams struct {
UserID pgtype.UUID `json:"user_id"`
ChannelType string `json:"channel_type"`
}
func (q *Queries) GetUserChannelBinding(ctx context.Context, arg GetUserChannelBindingParams) (UserChannelBinding, error) {
row := q.db.QueryRow(ctx, getUserChannelBinding, arg.UserID, arg.ChannelType)
var i UserChannelBinding
err := row.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listBotChannelConfigsByType = `-- name: ListBotChannelConfigsByType :many
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE channel_type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListBotChannelConfigsByType(ctx context.Context, channelType string) ([]BotChannelConfig, error) {
rows, err := q.db.Query(ctx, listBotChannelConfigsByType, channelType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BotChannelConfig
for rows.Next() {
var i BotChannelConfig
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Disabled,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUserChannelBindingsByPlatform = `-- name: ListUserChannelBindingsByPlatform :many
SELECT id, user_id, channel_type, config, created_at, updated_at
FROM user_channel_bindings
WHERE channel_type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListUserChannelBindingsByPlatform(ctx context.Context, channelType string) ([]UserChannelBinding, error) {
rows, err := q.db.Query(ctx, listUserChannelBindingsByPlatform, channelType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []UserChannelBinding
for rows.Next() {
var i UserChannelBinding
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const saveMatrixSyncSinceToken = `-- name: SaveMatrixSyncSinceToken :execrows
UPDATE bot_channel_configs
SET routing = COALESCE(routing, '{}'::jsonb) || jsonb_build_object(
'_matrix',
COALESCE(routing->'_matrix', '{}'::jsonb) || jsonb_build_object('since_token', $2::text)
)
WHERE id = $1
`
type SaveMatrixSyncSinceTokenParams struct {
ID pgtype.UUID `json:"id"`
SinceToken string `json:"since_token"`
}
func (q *Queries) SaveMatrixSyncSinceToken(ctx context.Context, arg SaveMatrixSyncSinceTokenParams) (int64, error) {
result, err := q.db.Exec(ctx, saveMatrixSyncSinceToken, arg.ID, arg.SinceToken)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateBotChannelConfigDisabled = `-- name: UpdateBotChannelConfigDisabled :one
UPDATE bot_channel_configs
SET
disabled = $3,
updated_at = now()
WHERE bot_id = $1 AND channel_type = $2
RETURNING id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at, created_at, updated_at
`
type UpdateBotChannelConfigDisabledParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
Disabled bool `json:"disabled"`
}
func (q *Queries) UpdateBotChannelConfigDisabled(ctx context.Context, arg UpdateBotChannelConfigDisabledParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, updateBotChannelConfigDisabled, arg.BotID, arg.ChannelType, arg.Disabled)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Disabled,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertBotChannelConfig = `-- name: UpsertBotChannelConfig :one
INSERT INTO bot_channel_configs (
bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (bot_id, channel_type)
DO UPDATE SET
credentials = EXCLUDED.credentials,
external_identity = EXCLUDED.external_identity,
self_identity = EXCLUDED.self_identity,
routing = EXCLUDED.routing,
capabilities = EXCLUDED.capabilities,
disabled = EXCLUDED.disabled,
verified_at = EXCLUDED.verified_at,
updated_at = now()
RETURNING id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, disabled, verified_at, created_at, updated_at
`
type UpsertBotChannelConfigParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
Credentials []byte `json:"credentials"`
ExternalIdentity pgtype.Text `json:"external_identity"`
SelfIdentity []byte `json:"self_identity"`
Routing []byte `json:"routing"`
Capabilities []byte `json:"capabilities"`
Disabled bool `json:"disabled"`
VerifiedAt pgtype.Timestamptz `json:"verified_at"`
}
func (q *Queries) UpsertBotChannelConfig(ctx context.Context, arg UpsertBotChannelConfigParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, upsertBotChannelConfig,
arg.BotID,
arg.ChannelType,
arg.Credentials,
arg.ExternalIdentity,
arg.SelfIdentity,
arg.Routing,
arg.Capabilities,
arg.Disabled,
arg.VerifiedAt,
)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Disabled,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertUserChannelBinding = `-- name: UpsertUserChannelBinding :one
INSERT INTO user_channel_bindings (user_id, channel_type, config)
VALUES ($1, $2, $3)
ON CONFLICT (user_id, channel_type)
DO UPDATE SET
config = EXCLUDED.config,
updated_at = now()
RETURNING id, user_id, channel_type, config, created_at, updated_at
`
type UpsertUserChannelBindingParams struct {
UserID pgtype.UUID `json:"user_id"`
ChannelType string `json:"channel_type"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertUserChannelBinding(ctx context.Context, arg UpsertUserChannelBindingParams) (UserChannelBinding, error) {
row := q.db.QueryRow(ctx, upsertUserChannelBinding, arg.UserID, arg.ChannelType, arg.Config)
var i UserChannelBinding
err := row.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}