forked from admin/VolcanicAgenticCore
ChatSettingsStore keeps each chat's IANA zone in <AgentDir>/telegram/chat-settings.json; ChatTimeZoneService is the one path for a change (store, live session, scheduler re-evaluation, reply text). ChatRegistry.TimeZoneFor now reads the store and new sessions start in the chat's zone. /timezone, the set_timezone tool (ChatSettingsExtension), /status zone line, DEFAULT_TIMEZONE. The store updates its cache under the write gate so the last file written is the newest state.
35 lines
1.7 KiB
C#
35 lines
1.7 KiB
C#
using System.ComponentModel;
|
|
using Volcanic.AgenticCore.Abstractions.Extensions;
|
|
using Volcanic.AgenticCore.Abstractions.Tools;
|
|
|
|
namespace Volcanic.AgenticCore.Telegram.Chats;
|
|
|
|
/// <summary>Arguments of <c>set_timezone</c>.</summary>
|
|
public sealed record SetTimeZoneArgs([property: Description("IANA time zone, e.g. Europe/Berlin or America/New_York")] string Zone);
|
|
|
|
/// <summary>Host extension per chat: the <c>set_timezone</c> tool, whether or not the scheduler is enabled.</summary>
|
|
public sealed class ChatSettingsExtension(long chatId, ChatTimeZoneService zones) : IExtension
|
|
{
|
|
public const string ExtensionName = "telegram-chat-settings";
|
|
public const string ToolName = "set_timezone";
|
|
|
|
public string Name => ExtensionName;
|
|
|
|
public ValueTask ActivateAsync(IExtensionApi api, CancellationToken cancellationToken)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(api);
|
|
api.RegisterTool(new DelegateTool<SetTimeZoneArgs>(
|
|
ToolName,
|
|
"Set this chat's time zone (an IANA name). It applies to the date in your instructions, bash, scheduled jobs and message timestamps.",
|
|
async (args, _, ct) =>
|
|
{
|
|
if (!ChatTimeZones.TryParse(args.Zone, out var zone, out var error)) throw new ToolExecutionException(ToolResult.Text(error));
|
|
return ToolResult.Text(await zones.SetAsync(chatId, zone, ct).ConfigureAwait(false));
|
|
},
|
|
promptSnippet: "set_timezone: change this chat's time zone",
|
|
promptGuidelines: ["Use set_timezone only when the user tells you their location or time zone changed; confirm the new zone in your reply."],
|
|
executionMode: ToolExecutionMode.Sequential));
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|