🐛 Bug fixes

This commit is contained in:
2025-10-26 12:37:52 +08:00
parent 4347281fcd
commit c3b6358f33
3 changed files with 73 additions and 67 deletions

View File

@@ -86,56 +86,76 @@ public class ThoughtProvider
return JsonSerializer.Serialize(response.Posts, GrpcTypeHelper.SerializerOptions); return JsonSerializer.Serialize(response.Posts, GrpcTypeHelper.SerializerOptions);
}, "search_posts", "Search posts by query from the Solar Network."), }, "search_posts", "Search posts by query from the Solar Network."),
KernelFunctionFactory.CreateFromMethod(async ( KernelFunctionFactory.CreateFromMethod(async (
string? publisherId = null, string? publisherId = null,
string? realmId = null, string? realmId = null,
int pageSize = 10, int pageSize = 10,
string? pageToken = null, string? pageToken = null,
string? orderBy = null, string? orderBy = null,
List<string>? categories = null, List<string>? categories = null,
List<string>? tags = null, List<string>? tags = null,
string? query = null, string? query = null,
List<int>? types = null, List<int>? types = null,
string? afterIso = null, string? afterIso = null,
string? beforeIso = null, string? beforeIso = null,
bool includeReplies = false, bool includeReplies = false,
string? pinned = null, string? pinned = null,
bool onlyMedia = false, bool onlyMedia = false,
bool shuffle = false bool shuffle = false
) => ) =>
{
var request = new ListPostsRequest
{ {
PublisherId = publisherId, var request = new ListPostsRequest
RealmId = realmId, {
PageSize = pageSize, PublisherId = publisherId,
PageToken = pageToken, RealmId = realmId,
OrderBy = orderBy, PageSize = pageSize,
Query = query, PageToken = pageToken,
IncludeReplies = includeReplies, OrderBy = orderBy,
Pinned = !string.IsNullOrEmpty(pinned) && int.TryParse(pinned, out int p) ? (PostPinMode)p : default, Query = query,
OnlyMedia = onlyMedia, IncludeReplies = includeReplies,
Shuffle = shuffle Pinned =
}; !string.IsNullOrEmpty(pinned) && int.TryParse(pinned, out int p) ? (PostPinMode)p : default,
if (!string.IsNullOrEmpty(afterIso)) OnlyMedia = onlyMedia,
{ Shuffle = shuffle
request.After = };
Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(DateTimeOffset.Parse(afterIso) if (!string.IsNullOrEmpty(afterIso))
.ToUniversalTime()); {
} request.After =
Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(DateTimeOffset.Parse(afterIso)
.ToUniversalTime());
}
if (!string.IsNullOrEmpty(beforeIso)) if (!string.IsNullOrEmpty(beforeIso))
{ {
request.Before = request.Before =
Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(DateTimeOffset.Parse(beforeIso) Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(DateTimeOffset.Parse(beforeIso)
.ToUniversalTime()); .ToUniversalTime());
} }
if (categories != null) request.Categories.AddRange(categories); if (categories != null) request.Categories.AddRange(categories);
if (tags != null) request.Tags.AddRange(tags); if (tags != null) request.Tags.AddRange(tags);
if (types != null) request.Types_.AddRange(types.Select(t => (PostType)t)); if (types != null) request.Types_.AddRange(types.Select(t => (PostType)t));
var response = await _postClient.ListPostsAsync(request); var response = await _postClient.ListPostsAsync(request);
return JsonSerializer.Serialize(response.Posts.Select(SnPost.FromProtoValue), GrpcTypeHelper.SerializerOptions); return JsonSerializer.Serialize(response.Posts.Select(SnPost.FromProtoValue),
}, "list_posts", "Get posts from the Solar Network with customizable filters.") GrpcTypeHelper.SerializerOptions);
}, "list_posts",
"Get posts from the Solar Network with customizable filters.\n" +
"Parameters:\n" +
"publisherId (optional, string: publisher ID to filter by)\n" +
"realmId (optional, string: realm ID to filter by)\n" +
"pageSize (optional, integer: posts per page, default 20)\n" +
"pageToken (optional, string: pagination token)\n" +
"orderBy (optional, string: field to order by)\n" +
"categories (optional, array of strings: category slugs)\n" +
"tags (optional, array of strings: tag slugs)\n" +
"query (optional, string: search query, will search in title, description and body)\n" +
"types (optional, array of integers: post types, use 0 for Moment, 1 for Article)\n" +
"afterIso (optional, string: ISO date for posts after this date)\n" +
"beforeIso (optional, string: ISO date for posts before this date)\n" +
"includeReplies (optional, boolean: include replies, default false)\n" +
"pinned (optional, string: pin mode as integer string, '0' for PublisherPage, '1' for RealmPage, '2' for ReplyPage)\n" +
"onlyMedia (optional, boolean: only posts with media, default false)\n" +
"shuffle (optional, boolean: shuffle results, default false)"
)
]); ]);
} }
@@ -149,7 +169,7 @@ public class ThoughtProvider
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto( FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
options: new FunctionChoiceBehaviorOptions options: new FunctionChoiceBehaviorOptions
{ {
AllowParallelCalls = true, AllowParallelCalls = true,
AllowConcurrentInvocation = true AllowConcurrentInvocation = true
}) })
}; };
@@ -167,4 +187,4 @@ public class ThoughtProvider
throw new InvalidOperationException("Unknown provider: " + ModelProviderType); throw new InvalidOperationException("Unknown provider: " + ModelProviderType);
} }
} }
} }

View File

@@ -112,39 +112,25 @@ public class SnPost : ModelBase, IIdentifiedResource, IActivity
}; };
if (EditedAt.HasValue) if (EditedAt.HasValue)
{
proto.EditedAt = Timestamp.FromDateTimeOffset(EditedAt.Value.ToDateTimeOffset()); proto.EditedAt = Timestamp.FromDateTimeOffset(EditedAt.Value.ToDateTimeOffset());
}
if (PublishedAt.HasValue) if (PublishedAt.HasValue)
{
proto.PublishedAt = Timestamp.FromDateTimeOffset(PublishedAt.Value.ToDateTimeOffset()); proto.PublishedAt = Timestamp.FromDateTimeOffset(PublishedAt.Value.ToDateTimeOffset());
}
if (Content != null) if (Content != null)
{
proto.Content = Content; proto.Content = Content;
}
if (PinMode.HasValue) if (PinMode.HasValue)
{
proto.PinMode = (Proto.PostPinMode)((int)PinMode.Value + 1); proto.PinMode = (Proto.PostPinMode)((int)PinMode.Value + 1);
}
if (Meta != null) if (Meta != null)
{
proto.Meta = GrpcTypeHelper.ConvertObjectToByteString(Meta); proto.Meta = GrpcTypeHelper.ConvertObjectToByteString(Meta);
}
if (SensitiveMarks != null) if (SensitiveMarks != null)
{
proto.SensitiveMarks = GrpcTypeHelper.ConvertObjectToByteString(SensitiveMarks); proto.SensitiveMarks = GrpcTypeHelper.ConvertObjectToByteString(SensitiveMarks);
}
if (EmbedView != null) if (EmbedView != null)
{
proto.EmbedView = EmbedView.ToProtoValue(); proto.EmbedView = EmbedView.ToProtoValue();
}
if (RepliedPostId.HasValue) if (RepliedPostId.HasValue)
{ {

View File

@@ -239,14 +239,14 @@ message SearchPostsResponse {
} }
message ListPostsRequest { message ListPostsRequest {
string publisher_id = 1; google.protobuf.StringValue publisher_id = 1;
string realm_id = 2; google.protobuf.StringValue realm_id = 2;
int32 page_size = 3; int32 page_size = 3;
string page_token = 4; string page_token = 4;
string order_by = 5; google.protobuf.StringValue order_by = 5;
repeated string categories = 6; repeated string categories = 6;
repeated string tags = 7; repeated string tags = 7;
string query = 8; google.protobuf.StringValue query = 8;
repeated PostType types = 9; repeated PostType types = 9;
optional google.protobuf.Timestamp after = 10; // Filter posts created after this timestamp optional google.protobuf.Timestamp after = 10; // Filter posts created after this timestamp
optional google.protobuf.Timestamp before = 11; // Filter posts created before this timestamp optional google.protobuf.Timestamp before = 11; // Filter posts created before this timestamp