MCPcopy Index your code
hub / github.com/coder/coder / ListAuthorizedAIBridgeSessions

Method ListAuthorizedAIBridgeSessions

coderd/database/modelqueries.go:1083–1147  ·  view source on GitHub ↗
(ctx context.Context, arg ListAIBridgeSessionsParams, prepared rbac.PreparedAuthorized)

Source from the content-addressed store, hash-verified

1081}
1082
1083func (q *sqlQuerier) ListAuthorizedAIBridgeSessions(ctx context.Context, arg ListAIBridgeSessionsParams, prepared rbac.PreparedAuthorized) ([]ListAIBridgeSessionsRow, error) {
1084 authorizedFilter, err := prepared.CompileToSQL(ctx, regosql.ConvertConfig{
1085 VariableConverter: regosql.AIBridgeInterceptionConverter(),
1086 })
1087 if err != nil {
1088 return nil, xerrors.Errorf("compile authorized filter: %w", err)
1089 }
1090 filtered, err := insertAuthorizedFilter(listAIBridgeSessions, fmt.Sprintf(" AND %s", authorizedFilter))
1091 if err != nil {
1092 return nil, xerrors.Errorf("insert authorized filter: %w", err)
1093 }
1094
1095 query := fmt.Sprintf("-- name: ListAuthorizedAIBridgeSessions :many\n%s", filtered)
1096 rows, err := q.db.QueryContext(ctx, query,
1097 arg.AfterSessionID,
1098 arg.StartedAfter,
1099 arg.StartedBefore,
1100 arg.InitiatorID,
1101 arg.Provider,
1102 arg.ProviderName,
1103 arg.Model,
1104 arg.Client,
1105 arg.SessionID,
1106 arg.Offset,
1107 arg.Limit,
1108 )
1109 if err != nil {
1110 return nil, err
1111 }
1112 defer rows.Close()
1113 var items []ListAIBridgeSessionsRow
1114 for rows.Next() {
1115 var i ListAIBridgeSessionsRow
1116 if err := rows.Scan(
1117 &i.SessionID,
1118 &i.UserID,
1119 &i.UserUsername,
1120 &i.UserName,
1121 &i.UserAvatarUrl,
1122 pq.Array(&i.Providers),
1123 pq.Array(&i.Models),
1124 &i.Client,
1125 &i.Metadata,
1126 &i.StartedAt,
1127 &i.EndedAt,
1128 &i.Threads,
1129 &i.InputTokens,
1130 &i.OutputTokens,
1131 &i.CacheReadInputTokens,
1132 &i.CacheWriteInputTokens,
1133 &i.LastPrompt,
1134 &i.LastActiveAt,
1135 ); err != nil {
1136 return nil, err
1137 }
1138 items = append(items, i)
1139 }
1140 if err := rows.Close(); err != nil {

Callers

nothing calls this directly

Calls 9

insertAuthorizedFilterFunction · 0.85
QueryContextMethod · 0.80
ErrMethod · 0.80
CompileToSQLMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
ErrorfMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected