feat(messaging): serve MessagingService.Deliver and deliver chat schedules through it

This commit is contained in:
sam committed 2026-10-05 18:01:33 +11:00
1 parent 4245c4320d
commit 463f4cd92a
22 files changed
+689 -46

No files matched your search

+2
View File
@@ -26,6 +26,8 @@ func run() int {
flag.StringVar(&options.Gateway.Token, "gateway-token", "", "bearer token presented to archie-gateway")
flag.StringVar(&options.StateStore.Target, "state-store-target", "", "archie-state-store gRPC address (defaults to [services.state].target)")
flag.StringVar(&options.StateStore.Token, "state-store-token", "", "bearer token presented to archie-state-store")
flag.StringVar(&options.Listen, "listen", "", "MessagingService gRPC listen address (defaults to [services.messaging].listen)")
flag.StringVar(&options.Token, "token", "", "bearer token required from MessagingService callers on a non-loopback listener")
flag.DurationVar(&options.DependencyTimeout, "dependency-timeout", 0, "readiness probe timeout (default 5s)")
flag.DurationVar(&options.ShutdownTimeout, "shutdown-timeout", 0, "shutdown timeout (default 5s)")
flag.Parse()
+9 -2
View File
@@ -48,6 +48,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
"github.com/samcharles93/archie-core/internal/infrastructure/extension"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
@@ -167,14 +168,14 @@ type boot struct {
chatTasks gateway.TaskCreator
defaultChatIdentity string
// messaging delivers outbound chat messages through the Messaging Service.
messaging *messagingrpc.Client
startGateways []func()
trees *worktree.Manager
identityRunners []*daemon.IdentityRunner
d *daemon.Daemon
// schedulingEngine is the cron/scheduling ticker engine (setupScheduling).
// Nil when no chat task creator is configured, in which case startServices
// leaves it unstarted rather than running with no reachable job kind.
schedulingEngine *scheduling.Engine
// kindWorkflows/labelWorkflows are the resolved kind/label -> workflow
@@ -469,6 +470,12 @@ func (b *boot) setupGatewayClient() error {
}
b.addCleanup(cleanup)
b.chat = &webui.ChatService{Contract: contract}
messaging, closeMessaging, err := composeMessaging(b.cfg.Services, b.secrets)
if err != nil {
return err
}
b.addCleanup(closeMessaging)
b.messaging = messaging
b.setupReadinessProbes()
return nil
}
+11
View File
@@ -6,6 +6,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/secret"
)
@@ -28,3 +29,13 @@ func composeChatContract(services config.Services, secrets *secret.Registry, opt
}
return client, cleanup, nil
}
// composeMessaging builds the Messaging Service client. The connection is
// lazy, so an absent Messaging Service fails each delivery, not the daemon.
func composeMessaging(services config.Services, secrets *secret.Registry) (*messagingrpc.Client, func(), error) {
target, err := services.RequireTarget(config.ServiceNameMessaging)
if err != nil {
return nil, nil, err
}
return messagingrpc.Dial(target, services.ResolvedToken(config.ServiceNameMessaging, secrets.Getenv))
}
+16 -14
View File
@@ -51,30 +51,32 @@ func schedulingConfig(input configuration.SchedulingInput, bus *events.Bus) (sch
// subsystem, and the corresponding Stop is registered here via addCleanup so
// shutdown ordering matches every other daemon-lifecycle subsystem.
//
// Only the "workflow" kind is wired: it rides gateway.TaskCreator, the same
// non-forge-backed task creation path chat's /spawn uses, which is the one
// production capability here that does not require inventing a channel
// courier or a synthetic forge owner/repo. A deployment with no chat task
// creator configured (no [chat] identity profiles) leaves the engine
// unstarted rather than running with no reachable job kind.
// The "chat" kind delivers through the Messaging Service. The "workflow" kind
// rides gateway.TaskCreator, the path chat's /spawn uses, so it is wired only
// when [chat] identity profiles configure one.
func (b *boot) setupScheduling() error {
cfg, err := schedulingConfig(b.doc.Scheduling, b.bus)
if err != nil {
return fmt.Errorf("scheduling: %w", err)
}
if b.chatTasks == nil {
b.log.Warn("scheduling: no chat task creator configured; ticker engine not started")
return nil
}
store := scheduleResourceStore{client: b.controlPlane}
workflowRunner, err := crondelivery.NewWorkflowTask(store, spawnTaskSubmitter{creator: b.chatTasks, identity: b.defaultChatIdentity})
chatRunner, err := crondelivery.NewChatCourier(store, func(ctx context.Context, target scheduling.Target, text string) error {
return b.messaging.Deliver(ctx, target.Channel, target.ChatID, text)
})
if err != nil {
return fmt.Errorf("scheduling: build workflow runner: %w", err)
return fmt.Errorf("scheduling: build chat runner: %w", err)
}
router, err := crondelivery.NewRouter(store, map[string]scheduling.Runner{scheduling.KindWorkflow: workflowRunner}, cfg.Events)
runners := map[string]scheduling.Runner{scheduling.KindChat: chatRunner}
if b.chatTasks != nil {
workflowRunner, err := crondelivery.NewWorkflowTask(store, spawnTaskSubmitter{creator: b.chatTasks, identity: b.defaultChatIdentity})
if err != nil {
return fmt.Errorf("scheduling: build workflow runner: %w", err)
}
runners[scheduling.KindWorkflow] = workflowRunner
}
router, err := crondelivery.NewRouter(store, runners, cfg.Events)
if err != nil {
return fmt.Errorf("scheduling: build router: %w", err)
}
+21
View File
@@ -2,6 +2,7 @@ package archiemessaging
import (
"context"
"errors"
"fmt"
"log/slog"
"slices"
@@ -17,6 +18,7 @@ import (
"github.com/samcharles93/archie-core/internal/domain/health"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/sdnotify"
"github.com/samcharles93/archie-core/internal/secret"
)
@@ -263,3 +265,22 @@ func (s *Service) Stop() {
}
s.log.Info("messaging service stopped")
}
// Deliver sends text to chatID through the named running channel.
func (s *Service) Deliver(ctx context.Context, channel, chatID, text string) error {
for _, instance := range s.channels {
if instance.name != channel {
continue
}
sender, ok := instance.current().(channels.Sender)
if !ok {
return fmt.Errorf("%w: channel %q cannot send", messagingrpc.ErrUnavailable, channel)
}
err := sender.Send(ctx, chatID, text)
if errors.Is(err, channels.ErrNotRunning) {
return fmt.Errorf("%w: channel %q is not running", messagingrpc.ErrUnavailable, channel)
}
return err
}
return fmt.Errorf("%w: no channel %q", messagingrpc.ErrUnavailable, channel)
}
+11
View File
@@ -30,6 +30,7 @@ type ResolvedConfig struct {
type projection struct {
gateway ServiceTarget
stateStore ServiceTarget
messaging config.ServiceConnection
telegram config.TelegramConfig
workDir string
botUser string
@@ -87,6 +88,7 @@ func project(cfg config.Config) projection {
Token: cfg.Services.Get(config.ServiceNameGateway).TargetToken,
},
stateStore: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target, Token: cfg.Services.Get(config.ServiceNameState).TargetToken},
messaging: cfg.Services.Get(config.ServiceNameMessaging),
telegram: cfg.Chat.Telegram,
workDir: cfg.WorkDir,
botUser: cfg.BotUser,
@@ -102,6 +104,9 @@ func withEnvTokens(o Options) Options {
if o.StateStore.Token == "" {
o.StateStore.Token = os.Getenv("STATE_STORE_TOKEN")
}
if o.Token == "" {
o.Token = os.Getenv("MESSAGING_TOKEN")
}
return o
}
@@ -118,6 +123,12 @@ func merge(o Options, p projection) Options {
if o.StateStore.Token == "" {
o.StateStore.Token = p.stateStore.Token
}
if o.Listen == "" {
o.Listen = p.messaging.Listen
}
if o.Token == "" {
o.Token = p.messaging.TargetToken
}
return o
}
+11 -3
View File
@@ -13,6 +13,7 @@ import (
// Process defaults.
const (
defaultGatewayTarget = "127.0.0.1:8585"
defaultListen = "127.0.0.1:8586"
defaultDependencyTimeout = 5 * time.Second
defaultShutdownTimeout = 5 * time.Second
)
@@ -29,8 +30,12 @@ type Options struct {
Config string
Overlay string
Gateway ServiceTarget
StateStore ServiceTarget
Gateway ServiceTarget
StateStore ServiceTarget
// Listen is where MessagingService is served; Token is the bearer token
// its callers present on a non-loopback address.
Listen string
Token string
DependencyTimeout time.Duration
ShutdownTimeout time.Duration
}
@@ -39,6 +44,9 @@ func withDefaults(o Options) Options {
if o.Gateway.Target == "" {
o.Gateway.Target = defaultGatewayTarget
}
if o.Listen == "" {
o.Listen = defaultListen
}
if o.DependencyTimeout <= 0 {
o.DependencyTimeout = defaultDependencyTimeout
}
@@ -60,7 +68,7 @@ func (o Options) validate() error {
return err
}
}
return nil
return validateServiceTarget("messaging listen", ServiceTarget{Target: o.Listen, Token: o.Token})
}
func validateServiceTarget(serviceName string, target ServiceTarget) error {
+25
View File
@@ -4,6 +4,9 @@ import (
"context"
"fmt"
"log/slog"
"net"
"google.golang.org/grpc"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/config"
@@ -14,6 +17,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/extension"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/secretengine"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/secret"
@@ -101,7 +105,28 @@ func Run(ctx context.Context, o Options) error {
if err != nil {
return err
}
return serve(ctx, cfg.Options, srv, log)
}
// serve runs srv and serves MessagingService over it until ctx is cancelled.
func serve(ctx context.Context, o Options, srv *Service, log *slog.Logger) error {
opts, err := messagingrpc.ServerOptions(o.Listen, o.Token)
if err != nil {
return err
}
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", o.Listen)
if err != nil {
return fmt.Errorf("listen messaging (%s): %w", o.Listen, err)
}
server := grpc.NewServer(opts...)
messagingrpc.RegisterServer(server, srv)
go func() {
if err := server.Serve(listener); err != nil {
log.Error("messaging gRPC server stopped", "err", err)
}
}()
defer server.GracefulStop()
log.Info("messaging service listening", "listen", o.Listen)
return srv.Start(ctx)
}
+7 -1
View File
@@ -36,7 +36,13 @@ func validateSchedules(jobs []scheduling.JobSpec) error {
return fmt.Errorf("duplicate schedule %q", job.ID)
}
seen[job.ID] = struct{}{}
if job.Kind != scheduling.KindWorkflow {
switch job.Kind {
case scheduling.KindWorkflow:
case scheduling.KindChat:
if job.Target.Channel == "" || job.Target.ChatID == "" || strings.TrimSpace(job.Payload.Text) == "" {
return fmt.Errorf("chat schedule %q needs a channel, chat ID and message", job.ID)
}
default:
return fmt.Errorf("schedule %q has unsupported kind %q", job.ID, job.Kind)
}
if err := job.Schedule.Validate(); err != nil {
+10
View File
@@ -6,6 +6,7 @@ package channels
import (
"context"
"encoding/json"
"errors"
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
@@ -25,3 +26,12 @@ type Channel interface {
// ValidateConfig checks that the provided configuration is valid for this channel.
ValidateConfig(cfg map[string]any) error
}
// Sender is a channel that can post a message unprompted. Channels that only
// reply to inbound messages do not implement it.
type Sender interface {
Send(ctx context.Context, chatID, text string) error
}
// ErrNotRunning is returned by Send while the channel is stopped.
var ErrNotRunning = errors.New("channel is not running")
+25
View File
@@ -12,6 +12,7 @@ import (
"net/http"
"runtime/debug"
"slices"
"strconv"
"strings"
"sync"
"sync/atomic"
@@ -121,6 +122,9 @@ type Gateway struct {
log *slog.Logger
bot *bot.Bot
running bool
// outbound is the running bot as Send sees it: Send is called from the
// Messaging Service's RPC goroutines, not the update loop that owns bot.
outbound atomic.Pointer[bot.Bot]
// serverURL redirects the Bot API at a test server. Empty in production,
// where the library's default endpoint is used. It exists so launch's
@@ -313,6 +317,7 @@ func (g *Gateway) launch(ctx context.Context, client messaging.ChatContract, lif
return nil, fmt.Errorf("create bot: %w", err)
}
g.bot = b
g.outbound.Store(b)
g.registerCommandHandlers(b, client)
@@ -384,6 +389,7 @@ func (g *Gateway) Stop(ctx context.Context) error {
}
g.log.Info("stopping telegram gateway")
g.running = false
g.outbound.Store(nil)
g.abandonAllLive(ctx)
@@ -824,6 +830,25 @@ func (g *Gateway) sendMessage(ctx context.Context, b *bot.Bot, chatID int64, mes
}
}
// Send delivers text to chatID, split like a reply. It fails if the bot is not
// running or any part is rejected.
func (g *Gateway) Send(ctx context.Context, chatID, text string) error {
b := g.outbound.Load()
if b == nil {
return channels.ErrNotRunning
}
id, err := strconv.ParseInt(chatID, 10, 64)
if err != nil {
return fmt.Errorf("telegram chat id %q: %w", chatID, err)
}
for _, part := range splitBlocks(markdownToBlocks(text), messageMaxLen) {
if g.sendBlocks(ctx, b, id, 0, part, "deliver message failed") == 0 {
return fmt.Errorf("telegram rejected a message to chat %d", id)
}
}
return nil
}
// sendBlocks sends one rich message and returns its ID, or 0. A rejected rich
// message is resent as plain text.
func (g *Gateway) sendBlocks(ctx context.Context, b *bot.Bot, chatID int64, messageThreadID int, blocks []models.InputRichBlock, errMsg string) int {
+5 -3
View File
@@ -44,8 +44,9 @@ type ServiceSpec struct {
// spelling a consumer looks up and the spelling that was registered are the
// same token, not two string literals that a typo can separate.
const (
ServiceNameGateway = "gateway"
ServiceNameState = "state"
ServiceNameGateway = "gateway"
ServiceNameState = "state"
ServiceNameMessaging = "messaging"
)
var (
@@ -107,10 +108,11 @@ func RegisteredServices() []ServiceSpec {
}
func init() {
// The two services this repository ships. Everything that differs
// The services this repository ships. Everything that differs
// between them is an argument here, not a branch somewhere else: the
// gateway's target is defaulted while the State Store's is supplied by
// the operator, and each falls back to its own token variable.
RegisterService(ServiceBoth, ServiceNameGateway, "127.0.0.1:8585", "127.0.0.1:8585", "GATEWAY_TOKEN")
RegisterService(ServiceClient, ServiceNameState, "", "127.0.0.1:9090", "STATE_STORE_TOKEN")
RegisterService(ServiceBoth, ServiceNameMessaging, "127.0.0.1:8586", "127.0.0.1:8586", "MESSAGING_TOKEN")
}
@@ -0,0 +1,185 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc (unknown)
// source: messaging/v1/messaging.proto
package messagingv1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type DeliverRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
// channel names the channel, such as "telegram".
Channel string `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"`
// chat_id is the channel-native chat identifier.
ChatId string `protobuf:"bytes,2,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
Text string `protobuf:"bytes,3,opt,name=text,proto3" json:"text,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *DeliverRequest) Reset() {
*x = DeliverRequest{}
mi := &file_messaging_v1_messaging_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DeliverRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeliverRequest) ProtoMessage() {}
func (x *DeliverRequest) ProtoReflect() protoreflect.Message {
mi := &file_messaging_v1_messaging_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeliverRequest.ProtoReflect.Descriptor instead.
func (*DeliverRequest) Descriptor() ([]byte, []int) {
return file_messaging_v1_messaging_proto_rawDescGZIP(), []int{0}
}
func (x *DeliverRequest) GetChannel() string {
if x != nil {
return x.Channel
}
return ""
}
func (x *DeliverRequest) GetChatId() string {
if x != nil {
return x.ChatId
}
return ""
}
func (x *DeliverRequest) GetText() string {
if x != nil {
return x.Text
}
return ""
}
type DeliverResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *DeliverResponse) Reset() {
*x = DeliverResponse{}
mi := &file_messaging_v1_messaging_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DeliverResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeliverResponse) ProtoMessage() {}
func (x *DeliverResponse) ProtoReflect() protoreflect.Message {
mi := &file_messaging_v1_messaging_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeliverResponse.ProtoReflect.Descriptor instead.
func (*DeliverResponse) Descriptor() ([]byte, []int) {
return file_messaging_v1_messaging_proto_rawDescGZIP(), []int{1}
}
var File_messaging_v1_messaging_proto protoreflect.FileDescriptor
const file_messaging_v1_messaging_proto_rawDesc = "" +
"\n" +
"\x1cmessaging/v1/messaging.proto\x12\fmessaging.v1\"W\n" +
"\x0eDeliverRequest\x12\x18\n" +
"\achannel\x18\x01 \x01(\tR\achannel\x12\x17\n" +
"\achat_id\x18\x02 \x01(\tR\x06chatId\x12\x12\n" +
"\x04text\x18\x03 \x01(\tR\x04text\"\x11\n" +
"\x0fDeliverResponse2Z\n" +
"\x10MessagingService\x12F\n" +
"\aDeliver\x12\x1c.messaging.v1.DeliverRequest\x1a\x1d.messaging.v1.DeliverResponseB\xc4\x01\n" +
"\x10com.messaging.v1B\x0eMessagingProtoP\x01ZOgithub.com/samcharles93/archie-core/internal/contracts/messaging/v1;messagingv1\xa2\x02\x03MXX\xaa\x02\fMessaging.V1\xca\x02\fMessaging\\V1\xe2\x02\x18Messaging\\V1\\GPBMetadata\xea\x02\rMessaging::V1b\x06proto3"
var (
file_messaging_v1_messaging_proto_rawDescOnce sync.Once
file_messaging_v1_messaging_proto_rawDescData []byte
)
func file_messaging_v1_messaging_proto_rawDescGZIP() []byte {
file_messaging_v1_messaging_proto_rawDescOnce.Do(func() {
file_messaging_v1_messaging_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_messaging_v1_messaging_proto_rawDesc), len(file_messaging_v1_messaging_proto_rawDesc)))
})
return file_messaging_v1_messaging_proto_rawDescData
}
var file_messaging_v1_messaging_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_messaging_v1_messaging_proto_goTypes = []any{
(*DeliverRequest)(nil), // 0: messaging.v1.DeliverRequest
(*DeliverResponse)(nil), // 1: messaging.v1.DeliverResponse
}
var file_messaging_v1_messaging_proto_depIdxs = []int32{
0, // 0: messaging.v1.MessagingService.Deliver:input_type -> messaging.v1.DeliverRequest
1, // 1: messaging.v1.MessagingService.Deliver:output_type -> messaging.v1.DeliverResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_messaging_v1_messaging_proto_init() }
func file_messaging_v1_messaging_proto_init() {
if File_messaging_v1_messaging_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_messaging_v1_messaging_proto_rawDesc), len(file_messaging_v1_messaging_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_messaging_v1_messaging_proto_goTypes,
DependencyIndexes: file_messaging_v1_messaging_proto_depIdxs,
MessageInfos: file_messaging_v1_messaging_proto_msgTypes,
}.Build()
File_messaging_v1_messaging_proto = out.File
file_messaging_v1_messaging_proto_goTypes = nil
file_messaging_v1_messaging_proto_depIdxs = nil
}
@@ -0,0 +1,133 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc (unknown)
// source: messaging/v1/messaging.proto
package messagingv1
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
MessagingService_Deliver_FullMethodName = "/messaging.v1.MessagingService/Deliver"
)
// MessagingServiceClient is the client API for MessagingService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// MessagingService is the Messaging Service's contract: the process that holds
// the chat channel transports. Other services send outbound messages through
// it rather than holding channel credentials themselves.
type MessagingServiceClient interface {
// Deliver sends text to one chat on one channel. FAILED_PRECONDITION means
// the channel is not running or cannot send; the caller may retry later.
Deliver(ctx context.Context, in *DeliverRequest, opts ...grpc.CallOption) (*DeliverResponse, error)
}
type messagingServiceClient struct {
cc grpc.ClientConnInterface
}
func NewMessagingServiceClient(cc grpc.ClientConnInterface) MessagingServiceClient {
return &messagingServiceClient{cc}
}
func (c *messagingServiceClient) Deliver(ctx context.Context, in *DeliverRequest, opts ...grpc.CallOption) (*DeliverResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DeliverResponse)
err := c.cc.Invoke(ctx, MessagingService_Deliver_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// MessagingServiceServer is the server API for MessagingService service.
// All implementations must embed UnimplementedMessagingServiceServer
// for forward compatibility.
//
// MessagingService is the Messaging Service's contract: the process that holds
// the chat channel transports. Other services send outbound messages through
// it rather than holding channel credentials themselves.
type MessagingServiceServer interface {
// Deliver sends text to one chat on one channel. FAILED_PRECONDITION means
// the channel is not running or cannot send; the caller may retry later.
Deliver(context.Context, *DeliverRequest) (*DeliverResponse, error)
mustEmbedUnimplementedMessagingServiceServer()
}
// UnimplementedMessagingServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedMessagingServiceServer struct{}
func (UnimplementedMessagingServiceServer) Deliver(context.Context, *DeliverRequest) (*DeliverResponse, error) {
return nil, status.Error(codes.Unimplemented, "method Deliver not implemented")
}
func (UnimplementedMessagingServiceServer) mustEmbedUnimplementedMessagingServiceServer() {}
func (UnimplementedMessagingServiceServer) testEmbeddedByValue() {}
// UnsafeMessagingServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to MessagingServiceServer will
// result in compilation errors.
type UnsafeMessagingServiceServer interface {
mustEmbedUnimplementedMessagingServiceServer()
}
func RegisterMessagingServiceServer(s grpc.ServiceRegistrar, srv MessagingServiceServer) {
// If the following call panics, it indicates UnimplementedMessagingServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&MessagingService_ServiceDesc, srv)
}
func _MessagingService_Deliver_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeliverRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MessagingServiceServer).Deliver(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MessagingService_Deliver_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MessagingServiceServer).Deliver(ctx, req.(*DeliverRequest))
}
return interceptor(ctx, in, info, handler)
}
// MessagingService_ServiceDesc is the grpc.ServiceDesc for MessagingService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var MessagingService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "messaging.v1.MessagingService",
HandlerType: (*MessagingServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Deliver",
Handler: _MessagingService_Deliver_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "messaging/v1/messaging.proto",
}
+3 -3
View File
@@ -67,9 +67,9 @@ type JobSpec struct {
// Target identifies where the job's output goes. Empty Target is valid —
// the delivery runner chooses a default.
type Target struct {
// ChatID is the chat channel id (Telegram chat id, email address,
// webhook URL — depends on the channel). Empty defers to a default
// chosen by the delivery runner.
// Channel names the Messaging Service channel, such as "telegram".
Channel string `json:"channel,omitempty"`
// ChatID is the channel-native chat id.
ChatID string `json:"chat_id,omitempty"`
}
@@ -34,8 +34,8 @@ type RouterStore interface {
RunRecorder
}
// Courier sends one chat message. It must honour ctx.
type Courier func(ctx context.Context, chatID, text string) error
// Courier sends one chat message to target. It must honour ctx.
type Courier func(ctx context.Context, target scheduling.Target, text string) error
// TaskSubmitter submits one unit of work.
type TaskSubmitter interface {
@@ -38,8 +38,8 @@ func (c *ChatCourier) Run(ctx context.Context, job scheduling.Job) error {
if err != nil {
return err
}
if err := c.courier(ctx, spec.Target.ChatID, spec.Payload.Text); err != nil {
return fmt.Errorf("crondelivery: deliver job %q to %q: %w", job.ID, spec.Target.ChatID, err)
if err := c.courier(ctx, spec.Target, spec.Payload.Text); err != nil {
return fmt.Errorf("crondelivery: deliver job %q to %s:%s: %w", job.ID, spec.Target.Channel, spec.Target.ChatID, err)
}
return nil
}
@@ -0,0 +1,115 @@
// Package messagingrpc is the transport for messaging.v1.MessagingService:
// the server the Messaging Service registers and the client other services
// dial to deliver outbound chat messages.
package messagingrpc
import (
"context"
"crypto/subtle"
"errors"
"fmt"
"strings"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
pb "github.com/samcharles93/archie-core/internal/contracts/messaging/v1"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
)
const tokenMetadataKey = "messaging-token"
// ErrUnavailable marks a delivery the channel could not make now: the channel
// is unknown, stopped or cannot send. The caller may retry later.
var ErrUnavailable = errors.New("messaging: channel unavailable")
// Deliverer sends text to one chat on a named channel.
type Deliverer interface {
Deliver(ctx context.Context, channel, chatID, text string) error
}
type server struct {
pb.UnimplementedMessagingServiceServer
deliverer Deliverer
}
// RegisterServer registers MessagingService over d.
func RegisterServer(registrar grpc.ServiceRegistrar, d Deliverer) {
pb.RegisterMessagingServiceServer(registrar, &server{deliverer: d})
}
func (s *server) Deliver(ctx context.Context, req *pb.DeliverRequest) (*pb.DeliverResponse, error) {
if req.GetChannel() == "" || req.GetChatId() == "" || req.GetText() == "" {
return nil, status.Error(codes.InvalidArgument, "channel, chat_id and text are required")
}
err := s.deliverer.Deliver(ctx, req.GetChannel(), req.GetChatId(), req.GetText())
switch {
case err == nil:
return &pb.DeliverResponse{}, nil
case errors.Is(err, ErrUnavailable):
return nil, status.Error(codes.FailedPrecondition, err.Error())
default:
return nil, status.Error(codes.Unavailable, err.Error())
}
}
// ServerOptions serves a loopback listen address without credentials and
// requires token on any other, failing closed when it is empty.
func ServerOptions(listen, token string) ([]grpc.ServerOption, error) {
loopback, err := gatewayrpc.TargetIsLoopback(listen)
if err != nil {
return nil, err
}
if loopback {
return nil, nil
}
if token == "" {
return nil, fmt.Errorf("messaging listen address %q is non-loopback and requires a bearer token", listen)
}
return []grpc.ServerOption{grpc.ChainUnaryInterceptor(requireToken(token))}, nil
}
func requireToken(token string) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
values := metadata.ValueFromIncomingContext(ctx, tokenMetadataKey)
if len(values) == 0 || subtle.ConstantTimeCompare([]byte(token), []byte(values[0])) != 1 {
return nil, status.Error(codes.Unauthenticated, "missing or invalid messaging token")
}
return handler(ctx, req)
}
}
// Client delivers through a dialled MessagingService.
type Client struct{ rpc pb.MessagingServiceClient }
// Dial returns a client for target. A non-loopback target requires token.
func Dial(target, token string) (*Client, func(), error) {
target = strings.TrimSpace(target)
loopback, err := gatewayrpc.TargetIsLoopback(target)
if err != nil {
return nil, nil, fmt.Errorf("messaging target must be host:port: %w", err)
}
if !loopback && token == "" {
return nil, nil, fmt.Errorf("messaging target %q is non-loopback and requires a bearer token ([services.messaging].target_token / MESSAGING_TOKEN)", target)
}
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
if token != "" {
opts = append(opts, grpc.WithUnaryInterceptor(func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(metadata.AppendToOutgoingContext(ctx, tokenMetadataKey, token), method, req, reply, cc, opts...)
}))
}
conn, err := grpc.NewClient(target, opts...)
if err != nil {
return nil, nil, fmt.Errorf("create messaging client: %w", err)
}
return &Client{rpc: pb.NewMessagingServiceClient(conn)}, func() { _ = conn.Close() }, nil
}
// Deliver sends text to chatID on channel.
func (c *Client) Deliver(ctx context.Context, channel, chatID, text string) error {
_, err := c.rpc.Deliver(ctx, &pb.DeliverRequest{Channel: channel, ChatId: chatID, Text: text})
return err
}
@@ -0,0 +1,36 @@
package messagingrpc
import (
"context"
"testing"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
func TestRequireToken(t *testing.T) {
ok := func(context.Context, any) (any, error) { return "served", nil }
for _, tc := range []struct {
name string
md metadata.MD
want codes.Code
}{
{"valid", metadata.Pairs(tokenMetadataKey, "secret"), codes.OK},
{"wrong", metadata.Pairs(tokenMetadataKey, "secrex"), codes.Unauthenticated},
{"missing", metadata.MD{}, codes.Unauthenticated},
{"other service's key", metadata.Pairs("gateway-token", "secret"), codes.Unauthenticated},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := metadata.NewIncomingContext(context.Background(), tc.md)
_, err := requireToken("secret")(ctx, nil, &grpc.UnaryServerInfo{}, ok)
if got := status.Code(err); got != tc.want {
t.Fatalf("code = %v, want %v", got, tc.want)
}
})
}
if _, err := ServerOptions("0.0.0.0:8586", ""); err == nil {
t.Fatal("non-loopback listen with no token was accepted")
}
}
+22
View File
@@ -0,0 +1,22 @@
syntax = "proto3";
package messaging.v1;
// MessagingService is the Messaging Service's contract: the process that holds
// the chat channel transports. Other services send outbound messages through
// it rather than holding channel credentials themselves.
service MessagingService {
// Deliver sends text to one chat on one channel. FAILED_PRECONDITION means
// the channel is not running or cannot send; the caller may retry later.
rpc Deliver(DeliverRequest) returns (DeliverResponse);
}
message DeliverRequest {
// channel names the channel, such as "telegram".
string channel = 1;
// chat_id is the channel-native chat identifier.
string chat_id = 2;
string text = 3;
}
message DeliverResponse {}
+12 -12
View File
@@ -16,9 +16,9 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en
Defaulting to \`null\`.`),null)}function TS(e){return CS(e)&&!Number.isNaN(e)&&e>0?e:(console.error(`Invalid prop \`max\` of value \`${e}\` supplied to \`ProgressRoot\`. Only numbers greater than 0 are valid max values. Defaulting to \`${bS}\`.`),bS)}var ES=L({__name:`ProgressRoot`,props:{modelValue:{type:[Number,null],required:!1},max:{type:Number,required:!1,default:bS},getValueLabel:{type:Function,required:!1,default:(e,t)=>CS(e)?`${Math.round(e/t*bS)}%`:void 0},getValueText:{type:Function,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:[`update:modelValue`,`update:max`],setup(e,{emit:t}){let n=e,r=t;Q();let i=wh(n,`modelValue`,r,{passive:n.modelValue===void 0}),a=wh(n,`max`,r,{passive:n.max===void 0});I(()=>i.value,async e=>{let t=wS(e,n.max);t!==e&&(await Kn(),i.value=t)},{immediate:!0}),I(()=>n.max,e=>{let t=TS(n.max);t!==e&&(a.value=t)},{immediate:!0});let o=Y(()=>Vm(i.value)?`indeterminate`:i.value===a.value?`complete`:`loading`);return SS({modelValue:i,max:a,progressState:o}),(e,t)=>(V(),U(P(kg),{"as-child":e.asChild,as:e.as,"aria-valuemax":P(a),"aria-valuemin":0,"aria-valuenow":CS(P(i))?P(i):void 0,"aria-valuetext":e.getValueText?.(P(i),P(a)),"aria-label":e.getValueLabel(P(i),P(a)),role:`progressbar`,"data-state":o.value,"data-value":P(i)??void 0,"data-max":P(a)},{default:F(()=>[z(e.$slots,`default`,{modelValue:P(i)})]),_:3},8,[`as-child`,`as`,`aria-valuemax`,`aria-valuenow`,`aria-valuetext`,`aria-label`,`data-state`,`data-value`,`data-max`]))}}),DS=L({__name:`ProgressIndicator`,props:{asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},setup(e){let t=e,n=xS();return Q(),(e,r)=>(V(),U(P(kg),J(t,{"data-state":P(n).progressState.value,"data-value":P(n).modelValue?.value??void 0,"data-max":P(n).max.value}),{default:F(()=>[z(e.$slots,`default`)]),_:3},16,[`data-state`,`data-value`,`data-max`]))}}),OS=`radio.select`;function kS(e,t,n){Bm(OS,n,{originalEvent:e,value:t})}var AS=L({inheritAttrs:!1,__name:`Radio`,props:{id:{type:String,required:!1},value:{type:null,required:!1},disabled:{type:Boolean,required:!1,default:!1},checked:{type:Boolean,required:!1,default:void 0},asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`button`},name:{type:String,required:!1},required:{type:Boolean,required:!1}},emits:[`update:checked`,`select`],setup(e,{emit:t}){let n=e,r=t,i=wh(n,`checked`,r,{passive:n.checked===void 0}),{value:a}=_n(n),{forwardRef:o,currentElement:s}=Q(),c=Jh(s),l=Zh(),u=Y(()=>n.id&&s.value?document.querySelector(`[for="${n.id}"]`)?.innerText:void 0);function d(e){n.disabled||kS(e,n.value,e=>{r(`select`,e),!e?.defaultPrevented&&(i.value=!0,c.value&&e.stopPropagation())})}return(e,t)=>(V(),H(B,null,[G(P(kg),J({id:e.id,ref:P(o),role:`radio`,type:e.as===`button`?`button`:void 0,as:e.as,"aria-checked":P(i)??!1,"aria-label":u.value,"as-child":e.asChild,disabled:e.disabled?``:void 0,"data-state":P(i)?`checked`:`unchecked`,"data-disabled":e.disabled?``:void 0,value:P(a),required:e.required,name:e.name},{...P(l),...e.$attrs},{onClick:Bl(d,[`stop`])}),{default:F(()=>[z(e.$slots,`default`,{checked:P(i)})]),_:3},16,[`id`,`type`,`as`,`aria-checked`,`aria-label`,`as-child`,`disabled`,`data-state`,`data-disabled`,`value`,`required`,`name`]),P(c)&&e.name?(V(),U(P(iv),J({key:0,type:`radio`,tabindex:`-1`,value:P(a),checked:!!P(i),name:e.name,disabled:e.disabled,required:e.required},P(l)),null,16,[`value`,`checked`,`name`,`disabled`,`required`])):q(`v-if`,!0)],64))}}),[jS,MS]=Rm(`RadioGroupRoot`),NS=L({__name:`RadioGroupRoot`,props:{modelValue:{type:null,required:!1},defaultValue:{type:null,required:!1},disabled:{type:Boolean,required:!1,default:!1},orientation:{type:String,required:!1,default:void 0},dir:{type:String,required:!1},loop:{type:Boolean,required:!1,default:!0},asChild:{type:Boolean,required:!1},as:{type:null,required:!1},name:{type:String,required:!1},required:{type:Boolean,required:!1,default:!1}},emits:[`update:modelValue`],setup(e,{emit:t}){let n=e,r=t,{forwardRef:i,currentElement:a}=Q(),o=wh(n,`modelValue`,r,{defaultValue:n.defaultValue,passive:n.modelValue===void 0}),{disabled:s,loop:c,orientation:l,name:u,required:d,dir:f}=_n(n),p=Uh(f),m=Jh(a);return MS({modelValue:o,changeModelValue:e=>{o.value=e},disabled:s,loop:c,orientation:l,name:u?.value,required:d}),(e,t)=>(V(),U(P(Bb),{"as-child":``,orientation:P(l),dir:P(p),loop:P(c)},{default:F(()=>[G(P(kg),{ref:P(i),role:`radiogroup`,"data-disabled":P(s)?``:void 0,"as-child":e.asChild,as:e.as,"aria-orientation":P(l),"aria-required":P(d),dir:P(p)},{default:F(()=>[z(e.$slots,`default`,{modelValue:P(o)}),P(m)&&P(u)?(V(),U(P(iv),{key:0,required:P(d),disabled:P(s),value:P(o),name:P(u)},null,8,[`required`,`disabled`,`value`,`name`])):q(`v-if`,!0)]),_:3},8,[`data-disabled`,`as-child`,`as`,`aria-orientation`,`aria-required`,`dir`])]),_:3},8,[`orientation`,`dir`,`loop`]))}}),[Iee,PS]=Rm(`RadioGroupItem`),FS=L({inheritAttrs:!1,__name:`RadioGroupItem`,props:{id:{type:String,required:!1},value:{type:nuLine truncated
`),r=[],i=null,a=null,o=()=>{r.length&&(t.push({kind:`p`,inline:kE(r.join(` `))}),r=[])},s=()=>{i&&=(t.push({kind:i.tag,items:i.items.map(e=>kE(e))}),null)};for(let e=0;e<n.length;e++){let c=n[e];if(c.startsWith("```")){o(),s(),a?(t.push({kind:`pre`,code:a.join(`
`)}),a=null):a=[];continue}if(a){a.push(c);continue}let l=jE(c),u=e+1<n.length?jE(n[e+1]):null;if(l&&u&&ME(u)&&l.length===u.length){o(),s();let r=[];for(e+=2;e<n.length;e++){let t=jE(n[e]);if(!t||t.length!==l.length){e--;break}r.push(t)}t.push({kind:`table`,head:l.map(e=>kE(e)),rows:r.map(e=>e.map(e=>kE(e)))});continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.push({kind:`h${d[1].length}`,inline:kE(d[2])});continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tag!==e)&&(s(),i={tag:e,items:[]}),i.items.push((f||p)[1]);continue}if(c.startsWith(`>`)){o(),s(),t.push({kind:`blockquote`,inline:kE(c.replace(/^>\s?/,``))});continue}r.push(c)}return o(),s(),a&&t.push({kind:`pre`,code:a.join(`
`)}),t}function jE(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function ME(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var NE={class:`[overflow-wrap:anywhere]`},PE={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},FE={class:`font-mono text-[0.85em]`},IE={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},LE={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},RE={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},zE={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},BE={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},VE={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},HE={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},UE={key:8,class:`mb-2.5 last:mb-0`},Ree=L({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=Y(()=>AE(t.text));return(e,t)=>(V(),H(`div`,NE,[(V(!0),H(B,null,R(n.value,(e,t)=>(V(),H(B,{key:t},[e.kind===`pre`?(V(),H(`pre`,PE,[W(`code`,FE,M(e.code),1)])):e.kind===`table`?(V(),H(`table`,IE,[W(`thead`,null,[W(`tr`,null,[(V(!0),H(B,null,R(e.head,(e,t)=>(V(),H(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[G(DE,{inline:e},null,8,[`inline`])]))),128))])]),W(`tbody`,null,[(V(!0),H(B,null,R(e.rows,(e,t)=>(V(),H(`tr`,{key:t},[(V(!0),H(B,null,R(e,(e,t)=>(V(),H(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[G(DE,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(V(),H(`blockquote`,LE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(V(),H(`h1`,RE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(V(),H(`h2`,zE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(V(),H(`h3`,BE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(V(),H(`ul`,VE,[(V(!0),H(B,null,R(e.items,(e,t)=>(V(),H(`li`,{key:t},[G(DE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(V(),H(`ol`,HE,[(V(!0),H(B,null,R(e.items,(e,t)=>(V(),H(`li`,{key:t},[G(DE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(V(),H(`p`,UE,[G(DE,{inline:e.inline},null,8,[`inline`])])):q(``,!0)],64))),128))]))}}),zee={class:`truncate`},Bee=L({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=Qi(`RouterLink`);return V(),U(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:F(()=>[G(P(Xu),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),W(`span`,zee,M(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),Vee={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},Hee={class:`font-semibold text-foreground`},Uee={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},Wee=L({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=Y(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=Y(()=>t.tool.parameters||t.tool.Parameters||``),i=Y(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=Y(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(V(),U(Bee,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(V(),H(`div`,Vee,[G(P(Zd),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),W(`span`,Hee,M(n.value),1),r.value?(V(),H(`code`,Uee,M(r.value),1)):q(``,!0),W(`span`,{class:j(P(X)(`text-fg-muted`,i.value&&`text-danger`))},M(a.value),3)]))}}),Gee={key:0,class:`mb-2 grid gap-0.5 text-xs`},Kee={key:1,class:`mb-2 flex flex-wrap gap-1.5`},qee={key:3,class:`whitespace-pre-wrap`},WE=L({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},media:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(V(),H(`div`,{class:j([`flex`,e.assistant?`justify-start`:`justify-end`])},[W(`div`,{class:j(P(X)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(V(),H(`div`,Gee,[(V(!0),H(B,null,R(e.tools,(t,n)=>(V(),U(Wee,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):q(``,!0),e.media.length?(V(),H(`div`,Kee,[(V(!0),H(B,null,R(e.media,(e,t)=>(V(),U(bE,{key:t,attachment:e},null,8,[`attachment`]))),128))])):q(``,!0),e.assistant?(V(),U(Ree,{key:2,text:e.text},null,8,[`text`])):(V(),H(`div`,qee,M(e.text),1)),z(t.$slots,`default`)],2)],2))}}),Jee={class:`w-full self-center justify-self-center py-6 text-center`},Yee={class:`grid gap-2`},Xee=[`onClick`],Zee=L({__name:`ChaLine truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>Bj?`${n.slice(0,Bj).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var Hj=[`title`],Uj=L({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>fj(n.event)),a=Y(()=>Vj(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=Y(()=>n.event.at?bA(n.event.at):`—`);return(e,t)=>(V(),U(P(Lj),{class:j(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[Hl(Bl(o,[`prevent`]),[`enter`]),Hl(Bl(o,[`prevent`]),[`space`])]},{default:F(()=>[G(P(Ij),{class:`font-medium`},{default:F(()=>[K(M(n.event.kind||n.event.type||`event`),1)]),_:1}),G(P(Ij),{class:`font-mono`},{default:F(()=>[K(M(i.value>0?`#${i.value}`:`—`),1)]),_:1}),G(P(Ij),{class:`w-[55%] max-w-0`},{default:F(()=>[W(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},M(a.value.text),9,Hj)]),_:1}),G(P(Ij),null,{default:F(()=>[K(M(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}}),Wj=[{value:`all`,label:`All`},{value:`tasks`,label:`Tasks`},{value:`system`,label:`System`}];function Gj(e){return(Number(e?.task_id)||0)>0}function Kj(e,t){return t===`tasks`?Gj(e):t!==`system`||!Gj(e)}function qj(e,t){return e.filter(e=>Kj(e,t))}function Jj(e,t){return e>0?``:t===`all`?`Waiting for activity`:t===`tasks`?`No task events yet`:`No system events yet`}function Yj(e,t){return`${e}:${t??0}`}function Xj(e){let t=[];for(let n of e){let e=n.kind||n.type||`event`,r=Number(n.task_id)||0,i=Yj(Vj(n).text,r),a=t[t.length-1];if(a&&a.key===i){a.count+=1,a.events.push(n);continue}t.push({key:i,label:e,taskID:r,count:1,representative:n,events:[n]})}return t}var Zj={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},Qj={class:`max-h-[28rem] overflow-y-auto`},$j=[`aria-expanded`,`aria-label`,`onClick`],eM=[`title`],tM=L({__name:`LiveActivityCard`,setup(e){let t=aD(),{activity:n,streamKind:r,streamState:i}=Fu(Ck()),a=N(`all`),o=Y(()=>qj(n.value,a.value)),s=Y(()=>Jj(o.value.length,a.value)),c=qt(new Set),l=Y(()=>Xj(o.value));function u(e){c.has(e)?c.delete(e):c.add(e)}function d(e){return c.has(e.key)}function f(e){return Vj(e.representative)}function p(e){return e.representative.at?bA(e.representative.at):`—`}function m(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(V(),U(P(pA),null,{default:F(()=>[G(P(vA),null,{default:F(()=>[G(P(yA),null,{default:F(()=>[...t[1]||=[K(`Live activity`,-1)]]),_:1}),G(P(mA),{class:`flex items-center gap-2`},{default:F(()=>[G(P(Mj),{modelValue:a.value,"onUpdate:modelValue":t[0]||=e=>a.value=e,label:`Filter activity`,options:P(Wj)},null,8,[`modelValue`,`options`]),G(P(uA),{variant:P(r)},{default:F(()=>[K(M(P(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),G(P(hA),null,{default:F(()=>[W(`div`,Zj,[W(`div`,Qj,[G(P(Pj),null,{default:F(()=>[G(P(zj),{class:`sticky top-0 z-10 bg-card`},{default:F(()=>[G(P(Lj),null,{default:F(()=>[G(P(Rj),null,{default:F(()=>[...t[2]||=[K(`Event`,-1)]]),_:1}),G(P(Rj),null,{default:F(()=>[...t[3]||=[K(`Task`,-1)]]),_:1}),G(P(Rj),null,{default:F(()=>[...t[4]||=[K(`Detail`,-1)]]),_:1}),G(P(Rj),null,{default:F(()=>[...t[5]||=[K(`When`,-1)]]),_:1})]),_:1})]),_:1}),G(P(Fj),null,{default:F(()=>[o.value.length?q(``,!0):(V(),U(P(Lj),{key:0},{default:F(()=>[G(P(Ij),{colspan:`4`},{default:F(()=>[G(P(nA),null,{default:F(()=>[G(P(aA),null,{default:F(()=>[G(P(cA),null,{default:F(()=>[K(M(s.value),1)]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})),o.value.length?(V(!0),H(B,{key:1},R(l.value,e=>(V(),H(B,{key:e.key},[e.count===1?(V(),U(Uj,{key:0,event:e.representative,onOpen:m},null,8,[`event`])):(V(),H(B,{key:1},[G(P(Lj),{class:j(e.taskID>0?`cursor-pointer`:``),role:e.taskID>0?`link`:void 0,tabindex:e.taskID>0?0:void 0,title:e.taskID>0?`Open task details`:void 0,onClick:t=>e.taskID>0&&m(e.taskID),onKeydown:[Hl(Bl(t=>e.taskID>0&&m(e.taskID),[`prevent`]),[`enter`]),Hl(Bl(t=>e.taskID>0&&m(e.taskID),[`prevent`]),[`space`])]},{default:F(()=>[G(P(Ij),{class:`font-medium`},{default:F(()=>[W(`button`,{type:`button`,class:`inline-flex items-center gap-1 rounded hover:opacity-80`,"aria-expanded":d(e),"aria-label":`${d(e)?`Hide`:`Show`} ${e.count} ${e.label} events`,onClick:Bl(t=>u(e.key),[`stop`])},[d(e)?(V(),U(P(rd),{key:0,class:`size-3.5 shrink-0 text-fg-subtle`})):(V(),U(P(id),{key:1,class:`size-3.5 shrink-0 text-fg-subtle`})),K(` `+M(e.label)+` `,1),G(P(uA),{variant:`idle`},{default:F(()=>[K(`×`+M(e.count),1)]),_:2},1024)],8,$j)]),_:2},1024),G(P(Ij),{class:`font-mono`},{default:F(()=>[K(M(e.taskID>0?`#${e.taskID}`:`—`),1)]),_:2},1024),G(P(Ij),{class:`w-[55%] max-w-0`},{default:F(()=>[W(`span`,{class:`block truncate`,title:f(e).truncated?f(e).full:void 0},M(f(e).text),9,eM)]),_:2},1024),G(P(Ij),null,{default:F(()=>[K(M(p(e)),1)]),_:2},1024)]),_:2},1032,[`class`,`role`,`tabindex`,`title`,`onClick`,`onKeydown`]),d(e)?(V(!0),H(B,{key:0},R(e.events,(t,n)=>(V(),U(Uj,{key:`${e.key}:${n}`,ev Line truncated
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function SN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function CN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function wN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function TN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var EN=N([]),DN=N([]),ON=N(!0),kN=N(null),AN=N(null),jN=N(!1),MN=N(null);async function NN(){try{let e=await Z.eventTypes();ON.value=e.enabled!==!1,EN.value=e.event_types||[],DN.value=e.proposals||[],kN.value=null}catch(e){kN.value=e.message||String(e)}}function PN(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function FN(e){MN.value=null,AN.value=e}function IN(e){let t=WN.value.find(t=>String(t.id)===e.sample_id);FN({mode:`proposal`,id:null,source:e.source,name:``,rule:PN(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function LN(e=``){FN({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function RN(e){FN({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:PN(e.rule),headersText:``,body:``,exampleHeaders:{}})}function zN(){AN.value=null}async function BN(){let e=AN.value;if(e){jN.value=!0;try{if(e.mode===`edit`&&e.id)await Z.eventTypeUpdate(e.id,{name:e.name,rule:TN(e.rule)});else{let t=e.mode===`paste`?xN(e.headersText):e.exampleHeaders;await Z.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:TN(e.rule),example:{headers:t,body:e.body}})}AN.value=null,await NN()}catch(e){MN.value=e.message||String(e)}finally{jN.value=!1}}}var VN=N(null);async function HN(){let e=VN.value;if(VN.value=null,e)try{await Z.eventTypeDelete(e.id),await NN()}catch(e){kN.value=e.message||String(e)}}var UN=100,WN=N([]),GN=N(!0),KN=N(null),qN=N(!0),JN=N(null);async function YN(){try{let e=await Z.captures(UN);GN.value=e.enabled!==!1,WN.value=e.captures||[],KN.value=null}catch(e){KN.value=e.message||String(e)}finally{qN.value=!1}}function XN(e){let t=WN.value.find(t=>t.id===e);return t&&(JN.value=t),!!t}function ZN(){WN.value.length&&(JN.value=WN.value[0])}function QN(){wk(`captures`,()=>{YN(),NN()})}var $N=`archie.theme`,eP=`archie.density`,tP=`archie.motion`,nP=`archie.tooltips`;function rP(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function iP(e,t){try{localStorage.setItem(e,t)}catch{}}function aP(e){if(e!==`system`)return e;try{return matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}catch{return`dark`}}var oP=Pu(`appearance`,()=>{let e=N(rP($N,[`system`,`dark`,`light`],`dark`)),t=N(rP(eP,[`comfortable`,`compact`],`comfortable`)),n=N(rP(tP,[`system`,`reduced`],`system`)),r=N(rP(nP,[`on`,`off`],`on`)===`on`),i=!1;function a(){document.documentElement.dataset.theme=aP(e.value)}function o(t){e.value=t,a(),iP($N,t)}function s(e){t.value=e,document.documentElement.dataset.density=e,iP(eP,e)}function c(e){n.value=e,document.documentElement.dataset.motion=e,iP(tP,e)}function l(e){r.value=e,iP(nP,e?`on`:`off`)}function u(){if(!i){i=!0,a(),document.documentElement.dataset.density=t.value,document.documentElement.dataset.motion=n.value;try{matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>{e.value===`system`&&a()})}catch{}}}return{theme:e,density:t,motion:n,tooltipsEnabled:r,initialize:u,setTheme:o,setDensity:s,setMotion:c,setTooltips:l}}),sP=L({__name:`Tooltip`,props:{defaultOpen:{type:Boolean},open:{type:Boolean},delayDuration:{},disableHoverableContent:{type:Boolean},disableClosingTrigger:{type:Boolean},disabled:{type:Boolean},ignoreNonKeyboardFocus:{type:Boolean}},emits:[`update:open`],setup(e,{emit:t}){let n=e,r=Xh(n,t),{tooltipsEnabled:i}=Fu(oP());return(e,t)=>(V(),U(P(ZC),J({"data-slot":`tooltip`},P(r),{disabled:n.disabled||!P(i)}),{default:F(t=>[z(e.$slots,`default`,ve(cs(t)))]),_:3},16,[`disabled`]))}}),cP=L({inheritAttrs:!1,__name:`TooltipContent`,props:{forceMount:{type:Boolean},ariaLabel:{},asChild:{type:Boolean},as:{},side:{},sideOffset:{default:0},align:{},alignOffset:{},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`escapeKeyDown`,`pointerDownOutside`],setup(e,{emit:t}){let n=e,r=t,i=Xh(_w(n,`class`),r);return(e,t)=>(V(),U(P(tw),null,{default:F( Line truncated
`)}),t}function jE(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function ME(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var NE={class:`[overflow-wrap:anywhere]`},PE={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},FE={class:`font-mono text-[0.85em]`},IE={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},LE={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},RE={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},zE={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},BE={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},VE={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},Ree={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},zee={key:8,class:`mb-2.5 last:mb-0`},Bee=L({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=Y(()=>AE(t.text));return(e,t)=>(V(),H(`div`,NE,[(V(!0),H(B,null,R(n.value,(e,t)=>(V(),H(B,{key:t},[e.kind===`pre`?(V(),H(`pre`,PE,[W(`code`,FE,M(e.code),1)])):e.kind===`table`?(V(),H(`table`,IE,[W(`thead`,null,[W(`tr`,null,[(V(!0),H(B,null,R(e.head,(e,t)=>(V(),H(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[G(DE,{inline:e},null,8,[`inline`])]))),128))])]),W(`tbody`,null,[(V(!0),H(B,null,R(e.rows,(e,t)=>(V(),H(`tr`,{key:t},[(V(!0),H(B,null,R(e,(e,t)=>(V(),H(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[G(DE,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(V(),H(`blockquote`,LE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(V(),H(`h1`,RE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(V(),H(`h2`,zE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(V(),H(`h3`,BE,[G(DE,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(V(),H(`ul`,VE,[(V(!0),H(B,null,R(e.items,(e,t)=>(V(),H(`li`,{key:t},[G(DE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(V(),H(`ol`,Ree,[(V(!0),H(B,null,R(e.items,(e,t)=>(V(),H(`li`,{key:t},[G(DE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(V(),H(`p`,zee,[G(DE,{inline:e.inline},null,8,[`inline`])])):q(``,!0)],64))),128))]))}}),Vee={class:`truncate`},Hee=L({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=Qi(`RouterLink`);return V(),U(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:F(()=>[G(P(Xu),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),W(`span`,Vee,M(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),Uee={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},Wee={class:`font-semibold text-foreground`},Gee={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},Kee=L({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=Y(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=Y(()=>t.tool.parameters||t.tool.Parameters||``),i=Y(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=Y(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(V(),U(Hee,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(V(),H(`div`,Uee,[G(P(Zd),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),W(`span`,Wee,M(n.value),1),r.value?(V(),H(`code`,Gee,M(r.value),1)):q(``,!0),W(`span`,{class:j(P(X)(`text-fg-muted`,i.value&&`text-danger`))},M(a.value),3)]))}}),qee={key:0,class:`mb-2 grid gap-0.5 text-xs`},Jee={key:1,class:`mb-2 flex flex-wrap gap-1.5`},Yee={key:3,class:`whitespace-pre-wrap`},HE=L({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},media:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(V(),H(`div`,{class:j([`flex`,e.assistant?`justify-start`:`justify-end`])},[W(`div`,{class:j(P(X)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(V(),H(`div`,qee,[(V(!0),H(B,null,R(e.tools,(t,n)=>(V(),U(Kee,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):q(``,!0),e.media.length?(V(),H(`div`,Jee,[(V(!0),H(B,null,R(e.media,(e,t)=>(V(),U(bE,{key:t,attachment:e},null,8,[`attachment`]))),128))])):q(``,!0),e.assistant?(V(),U(Bee,{key:2,text:e.text},null,8,[`text`])):(V(),H(`div`,Yee,M(e.text),1)),z(t.$slots,`default`)],2)],2))}}),Xee={class:`w-full self-center justify-self-center py-6 text-center`},Zee={class:`grid gap-2`},Qee=[`onClick`],$ee=L({__name: Line truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>Rj?`${n.slice(0,Rj).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var Bj=[`title`],Vj=L({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>uj(n.event)),a=Y(()=>zj(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=Y(()=>n.event.at?vA(n.event.at):`—`);return(e,t)=>(V(),U(P(Fj),{class:j(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[Hl(Bl(o,[`prevent`]),[`enter`]),Hl(Bl(o,[`prevent`]),[`space`])]},{default:F(()=>[G(P(Pj),{class:`font-medium`},{default:F(()=>[K(M(n.event.kind||n.event.type||`event`),1)]),_:1}),G(P(Pj),{class:`font-mono`},{default:F(()=>[K(M(i.value>0?`#${i.value}`:`—`),1)]),_:1}),G(P(Pj),{class:`w-[55%] max-w-0`},{default:F(()=>[W(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},M(a.value.text),9,Bj)]),_:1}),G(P(Pj),null,{default:F(()=>[K(M(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}}),Hj=[{value:`all`,label:`All`},{value:`tasks`,label:`Tasks`},{value:`system`,label:`System`}];function Uj(e){return(Number(e?.task_id)||0)>0}function Wj(e,t){return t===`tasks`?Uj(e):t!==`system`||!Uj(e)}function Gj(e,t){return e.filter(e=>Wj(e,t))}function Kj(e,t){return e>0?``:t===`all`?`Waiting for activity`:t===`tasks`?`No task events yet`:`No system events yet`}function qj(e,t){return`${e}:${t??0}`}function Jj(e){let t=[];for(let n of e){let e=n.kind||n.type||`event`,r=Number(n.task_id)||0,i=qj(zj(n).text,r),a=t[t.length-1];if(a&&a.key===i){a.count+=1,a.events.push(n);continue}t.push({key:i,label:e,taskID:r,count:1,representative:n,events:[n]})}return t}var Yj={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},Xj={class:`max-h-[28rem] overflow-y-auto`},Zj=[`aria-expanded`,`aria-label`,`onClick`],Qj=[`title`],$j=L({__name:`LiveActivityCard`,setup(e){let t=rD(),{activity:n,streamKind:r,streamState:i}=Fu(xk()),a=N(`all`),o=Y(()=>Gj(n.value,a.value)),s=Y(()=>Kj(o.value.length,a.value)),c=qt(new Set),l=Y(()=>Jj(o.value));function u(e){c.has(e)?c.delete(e):c.add(e)}function d(e){return c.has(e.key)}function f(e){return zj(e.representative)}function p(e){return e.representative.at?vA(e.representative.at):`—`}function m(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(V(),U(P(dA),null,{default:F(()=>[G(P(gA),null,{default:F(()=>[G(P(_A),null,{default:F(()=>[...t[1]||=[K(`Live activity`,-1)]]),_:1}),G(P(fA),{class:`flex items-center gap-2`},{default:F(()=>[G(P(Aj),{modelValue:a.value,"onUpdate:modelValue":t[0]||=e=>a.value=e,label:`Filter activity`,options:P(Hj)},null,8,[`modelValue`,`options`]),G(P(cA),{variant:P(r)},{default:F(()=>[K(M(P(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),G(P(pA),null,{default:F(()=>[W(`div`,Yj,[W(`div`,Xj,[G(P(Mj),null,{default:F(()=>[G(P(Lj),{class:`sticky top-0 z-10 bg-card`},{default:F(()=>[G(P(Fj),null,{default:F(()=>[G(P(Ij),null,{default:F(()=>[...t[2]||=[K(`Event`,-1)]]),_:1}),G(P(Ij),null,{default:F(()=>[...t[3]||=[K(`Task`,-1)]]),_:1}),G(P(Ij),null,{default:F(()=>[...t[4]||=[K(`Detail`,-1)]]),_:1}),G(P(Ij),null,{default:F(()=>[...t[5]||=[K(`When`,-1)]]),_:1})]),_:1})]),_:1}),G(P(Nj),null,{default:F(()=>[o.value.length?q(``,!0):(V(),U(P(Fj),{key:0},{default:F(()=>[G(P(Pj),{colspan:`4`},{default:F(()=>[G(P(eA),null,{default:F(()=>[G(P(rA),null,{default:F(()=>[G(P(oA),null,{default:F(()=>[K(M(s.value),1)]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})),o.value.length?(V(!0),H(B,{key:1},R(l.value,e=>(V(),H(B,{key:e.key},[e.count===1?(V(),U(Vj,{key:0,event:e.representative,onOpen:m},null,8,[`event`])):(V(),H(B,{key:1},[G(P(Fj),{class:j(e.taskID>0?`cursor-pointer`:``),role:e.taskID>0?`link`:void 0,tabindex:e.taskID>0?0:void 0,title:e.taskID>0?`Open task details`:void 0,onClick:t=>e.taskID>0&&m(e.taskID),onKeydown:[Hl(Bl(t=>e.taskID>0&&m(e.taskID),[`prevent`]),[`enter`]),Hl(Bl(t=>e.taskID>0&&m(e.taskID),[`prevent`]),[`space`])]},{default:F(()=>[G(P(Pj),{class:`font-medium`},{default:F(()=>[W(`button`,{type:`button`,class:`inline-flex items-center gap-1 rounded hover:opacity-80`,"aria-expanded":d(e),"aria-label":`${d(e)?`Hide`:`Show`} ${e.count} ${e.label} events`,onClick:Bl(t=>u(e.key),[`stop`])},[d(e)?(V(),U(P(rd),{key:0,class:`size-3.5 shrink-0 text-fg-subtle`})):(V(),U(P(id),{key:1,class:`size-3.5 shrink-0 text-fg-subtle`})),K(` `+M(e.label)+` `,1),G(P(cA),{variant:`idle`},{default:F(()=>[K(`×`+M(e.count),1)]),_:2},1024)],8,Zj)]),_:2},1024),G(P(Pj),{class:`font-mono`},{default:F(()=>[K(M(e.taskID>0?`#${e.taskID}`:`—`),1)]),_:2},1024),G(P(Pj),{class:`w-[55%] max-w-0`},{default:F(()=>[W(`span`,{class:`block truncate`,title:f(e).truncated?f(e).full:void 0},M(f(e).text),9,Qj)]),_:2},1024),G(P(Pj),null,{default:F(()=>[K(M(p(e)),1)]),_:2},1024)]),_:2},1032,[`class`,`role`,`tabindex`,`title`,`onClick`,`onKeydown`]),d(e)?(V(!0),H(B,{key:0},R(e.events,(t,n)=>(V(),U(Vj,{key:`${e.key}:${n}`,ev Line truncated
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function bN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function xN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function SN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function CN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var wN=N([]),TN=N([]),EN=N(!0),DN=N(null),ON=N(null),kN=N(!1),AN=N(null);async function jN(){try{let e=await Z.eventTypes();EN.value=e.enabled!==!1,wN.value=e.event_types||[],TN.value=e.proposals||[],DN.value=null}catch(e){DN.value=e.message||String(e)}}function MN(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function NN(e){AN.value=null,ON.value=e}function PN(e){let t=HN.value.find(t=>String(t.id)===e.sample_id);NN({mode:`proposal`,id:null,source:e.source,name:``,rule:MN(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function FN(e=``){NN({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function IN(e){NN({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:MN(e.rule),headersText:``,body:``,exampleHeaders:{}})}function LN(){ON.value=null}async function RN(){let e=ON.value;if(e){kN.value=!0;try{if(e.mode===`edit`&&e.id)await Z.eventTypeUpdate(e.id,{name:e.name,rule:CN(e.rule)});else{let t=e.mode===`paste`?yN(e.headersText):e.exampleHeaders;await Z.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:CN(e.rule),example:{headers:t,body:e.body}})}ON.value=null,await jN()}catch(e){AN.value=e.message||String(e)}finally{kN.value=!1}}}var zN=N(null);async function BN(){let e=zN.value;if(zN.value=null,e)try{await Z.eventTypeDelete(e.id),await jN()}catch(e){DN.value=e.message||String(e)}}var VN=100,HN=N([]),UN=N(!0),WN=N(null),GN=N(!0),KN=N(null);async function qN(){try{let e=await Z.captures(VN);UN.value=e.enabled!==!1,HN.value=e.captures||[],WN.value=null}catch(e){WN.value=e.message||String(e)}finally{GN.value=!1}}function JN(e){let t=HN.value.find(t=>t.id===e);return t&&(KN.value=t),!!t}function YN(){HN.value.length&&(KN.value=HN.value[0])}function XN(){Sk(`captures`,()=>{qN(),jN()})}var ZN=`archie.theme`,QN=`archie.density`,$N=`archie.motion`,eP=`archie.tooltips`;function tP(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function nP(e,t){try{localStorage.setItem(e,t)}catch{}}function rP(e){if(e!==`system`)return e;try{return matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}catch{return`dark`}}var iP=Pu(`appearance`,()=>{let e=N(tP(ZN,[`system`,`dark`,`light`],`dark`)),t=N(tP(QN,[`comfortable`,`compact`],`comfortable`)),n=N(tP($N,[`system`,`reduced`],`system`)),r=N(tP(eP,[`on`,`off`],`on`)===`on`),i=!1;function a(){document.documentElement.dataset.theme=rP(e.value)}function o(t){e.value=t,a(),nP(ZN,t)}function s(e){t.value=e,document.documentElement.dataset.density=e,nP(QN,e)}function c(e){n.value=e,document.documentElement.dataset.motion=e,nP($N,e)}function l(e){r.value=e,nP(eP,e?`on`:`off`)}function u(){if(!i){i=!0,a(),document.documentElement.dataset.density=t.value,document.documentElement.dataset.motion=n.value;try{matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>{e.value===`system`&&a()})}catch{}}}return{theme:e,density:t,motion:n,tooltipsEnabled:r,initialize:u,setTheme:o,setDensity:s,setMotion:c,setTooltips:l}}),aP=L({__name:`Tooltip`,props:{defaultOpen:{type:Boolean},open:{type:Boolean},delayDuration:{},disableHoverableContent:{type:Boolean},disableClosingTrigger:{type:Boolean},disabled:{type:Boolean},ignoreNonKeyboardFocus:{type:Boolean}},emits:[`update:open`],setup(e,{emit:t}){let n=e,r=Xh(n,t),{tooltipsEnabled:i}=Fu(iP());return(e,t)=>(V(),U(P(ZC),J({"data-slot":`tooltip`},P(r),{disabled:n.disabled||!P(i)}),{default:F(t=>[z(e.$slots,`default`,ve(cs(t)))]),_:3},16,[`disabled`]))}}),oP=L({inheritAttrs:!1,__name:`TooltipContent`,props:{forceMount:{type:Boolean},ariaLabel:{},asChild:{type:Boolean},as:{},side:{},sideOffset:{default:0},align:{},alignOffset:{},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`escapeKeyDown`,`pointerDownOutside`],setup(e,{emit:t}){let n=e,r=t,i=Xh(_w(n,`class`),r);return(e,t)=>(V(),U(P(tw),null,{default:F( Line truncated
`)}};iJ.defaultYaml={explicit:!1,version:`1.2`},iJ.defaultTags={"!!":`tag:yaml.org,2002:`};function aJ(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function oJ(e){let t=new Set;return Zq(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function sJ(e,t){for(let n=1;;++n){let r=`${e}${n}`;if(!t.has(r))return r}}function cJ(e,t){let n=[],r=new Map,i=null;return{onAnchor:r=>{n.push(r),i??=oJ(e);let a=sJ(t,i);return i.add(a),a},setAnchors:()=>{for(let e of n){let t=r.get(e);if(typeof t==`object`&&t.anchor&&(Uq(t.node)||Gq(t.node)))t.node.anchor=t.anchor;else{let t=Error(`Failed to resolve repeated object (this should not happen)`);throw t.source=e,t}}},sourceObjects:r}}function lJ(e,t,n,r){if(r&&typeof r==`object`){if(Array.isArray(r))for(let t=0,n=r.length;t<n;++t){let n=r[t],i=lJ(e,r,String(t),n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}else if(r instanceof Map)for(let t of Array.from(r.keys())){let n=r.get(t),i=lJ(e,r,t,n);i===void 0?r.delete(t):i!==n&&r.set(t,i)}else if(r instanceof Set)for(let t of Array.from(r)){let n=lJ(e,r,t,t);n===void 0?r.delete(t):n!==t&&(r.delete(t),r.add(n))}else for(let[t,n]of Object.entries(r)){let i=lJ(e,r,t,n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}}return e.call(t,n,r)}function uJ(e,t,n){if(Array.isArray(e))return e.map((e,t)=>uJ(e,String(t),n));if(e&&typeof e.toJSON==`function`){if(!n||!qq(e))return e.toJSON(t,n);let r={aliasCount:0,count:1,res:void 0};n.anchors.set(e,r),n.onCreate=e=>{r.res=e,delete n.onCreate};let i=e.toJSON(t,n);return n.onCreate&&n.onCreate(i),i}return typeof e==`bigint`&&!n?.keep?Number(e):e}var dJ=class{constructor(e){Object.defineProperty(this,Rq,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:r,reviver:i}={}){if(!Bq(e))throw TypeError(`A document argument is required`);let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n==`number`?n:100},o=uJ(this,``,a);if(typeof r==`function`)for(let{count:e,res:t}of a.anchors.values())r(t,e);return typeof i==`function`?lJ(i,{"":o},``,o):o}},fJ=class extends dJ{constructor(e){super(Mq),this.source=e,Object.defineProperty(this,"tag",{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],Zq(e,{Node:(e,t)=>{(zq(t)||qq(t))&&n.push(t)}}),t&&(t.aliasResolveCache=n));let r;for(let e of n){if(e===this)break;e.anchor===this.source&&(r=e)}if(r&&t){let{anchors:e,doc:n,maxAliasCount:i}=t,a=e.get(r);if(a||=(uJ(r,null,t),e.get(r)),a?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(i>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=pJ(n,r,e)),a.count*a.aliasCount>i))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return r}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,t,n){let r=`*${this.source}`;if(e){if(aJ(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${r} `}return r}};function pJ(e,t,n){if(zq(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(Gq(t)){let r=0;for(let i of t.items){let t=pJ(e,i,n);t>r&&(r=t)}return r}if(Hq(t)){let r=pJ(e,t.key,n),i=pJ(e,t.value,n);return Math.max(r,i)}return 1}var mJ=e=>!e||typeof e!=`function`&&typeof e!=`object`,hJ=class extends dJ{constructor(e){super(Iq),this.value=e}toJSON(e,t){return t?.keep?this.value:uJ(this.value,e,t)}toString(){return String(this.value)}};hJ.BLOCK_FOLDED=`BLOCK_FOLDED`,hJ.BLOCK_LITERAL=`BLOCK_LITERAL`,hJ.PLAIN=`PLAIN`,hJ.QUOTE_DOUBLE=`QUOTE_DOUBLE`,hJ.QUOTE_SINGLE=`QUOTE_SINGLE`;var gJ=`tag:yaml.org,2002:`;function _J(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function vJ(e,t,n){if(Bq(e)&&(e=e.contents),Kq(e))return e;if(Hq(e)){let t=n.schema[Pq].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:r,onAnchor:i,onTagObj:a,schema:o,sourceObjects:s}=n,c;if(r&&e&&typeof e==`object`){if(c=s.get(e),c)return c.anchor??(c.anchor=i(e)),new fJ(c.anchor);c={anchor:null,node:null},s.set(e,c)}t?.startsWith(`!!`)&&(t=gJ+t.slice(2));let l=_J(e,t,o.tags);if(!l){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new hJ(e);return c&&(c.node=t),t Line truncated
`)?CJ(n,t):n.includes(`
`)?`
@@ -100,8 +100,8 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
`)+(a.substring(1)||` `),n=!0,r=!1;break;case`%`:e[i+1]?.[0]!==`#`&&(i+=1),n=!1;break;default:n||(r=!0),n=!1}}return{comment:t,afterEmptyLine:r}}var ZX=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,r)=>{let i=YX(e);r?this.warnings.push(new mX(i,t,n)):this.errors.push(new pX(i,t,n))},this.directives=new iJ({version:e.version||`1.2`}),this.options=e}decorate(e,t){let{comment:n,afterEmptyLine:r}=XX(this.prelude);if(n){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(r||e.directives.docStart||!i)e.commentBefore=n;else if(Gq(i)&&!i.flow&&i.items.length>0){let e=i.items[0];Hq(e)&&(e=e.key);let t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{let e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}if(t){for(let t=0;t<this.errors.length;++t)e.errors.push(this.errors[t]);for(let t=0;t<this.warnings.length;++t)e.warnings.push(this.warnings[t])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:XX(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(let t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(e.type){case`directive`:this.directives.add(e.source,(t,n,r)=>{let i=YX(e);i[0]+=t,this.onError(i,`BAD_DIRECTIVE`,n,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case`document`:{let t=JX(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,`MISSING_CHAR`,`Missing directives-end/doc-start indicator line`),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case`byte-order-mark`:case`space`:break;case`comment`:case`newline`:this.prelude.push(e.source);break;case`error`:{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new pX(YX(e),`UNEXPECTED_TOKEN`,t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case`doc-end`:{if(!this.doc){this.errors.push(new pX(YX(e),`UNEXPECTED_TOKEN`,`Unexpected doc-end without preceding document`));break}this.doc.directives.docEnd=!0;let t=CX(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new pX(YX(e),`UNEXPECTED_TOKEN`,`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let e=new uX(void 0,Object.assign({_directives:this.directives},this.options));this.atDirectives&&this.onError(t,`MISSING_CHAR`,`Missing directives-end indicator line`),e.range=[0,t,t],this.decorate(e,!1),yield e}}},QX=Symbol(`break visit`),$X=Symbol(`skip children`),eZ=Symbol(`remove item`);function tZ(e,t){`type`in e&&e.type===`document`&&(e={start:e.start,value:e.value}),nZ(Object.freeze([]),e,t)}tZ.BREAK=QX,tZ.SKIP=$X,tZ.REMOVE=eZ,tZ.itemAtPath=(e,t)=>{let n=e;for(let[e,r]of t){let t=n?.[e];if(t&&`items`in t)n=t.items[r];else return}return n},tZ.parentCollection=(e,t)=>{let n=tZ.itemAtPath(e,t.slice(0,-1)),r=t[t.length-1][0],i=n?.[r];if(i&&`items`in i)return i;throw Error(`Parent collection not found`)};function nZ(e,t,n){let r=n(t,e);if(typeof r==`symbol`)return r;for(let i of[`key`,`value`]){let a=t[i];if(a&&`items`in a){for(let t=0;t<a.items.length;++t){let r=nZ(Object.freeze(e.concat([[i,t]])),a.items[t],n);if(typeof r==`number`)t=r-1;else if(r===QX)return QX;else r===eZ&&(a.items.splice(t,1),--t)}typeof r==`function`&&i===`key`&&(r=r(t,e))}}return typeof r==`function`?r(t,e):r}function rZ(e){switch(e){case``:return`byte-order-mark`;case``:return`doc-mode`;case``:return`flow-error-end`;case``:return`scalar`;case`---`:return`doc-start`;case`...`:return`doc-end`;case``:case`
`:case`\r
`:return`newline`;case`-`:return`seq-item-ind`;case`?`:return`explicit-key-ind`;case`:`:return`map-value-ind`;case`{`:return`flow-map-start`;case`}`:return`flow-map-end`;case`[`:return`flow-seq-start`;case`]`:return`flow-seq-end`;case`,`:return`comma`}switch(e[0]){case` `:case` `:return`space`;case`#`:return`comment`;case`%`:return`directive-line`;case`*`:return`alias`;case`&`:return`anchor`;case`!`:return`tag`;case`'`:return`single-quoted-scalar`;case`"`:return`double-quoted-scalar`;case`|`:case`>`:return`block-scalar-header`}return null}function iZ(e){switch(e){case void 0:case` `:case`
`:case`\r`:case` `:return!0;default:return!1}}var aZ=new Set(`0123456789ABCDEFabcdef`),Dte=new Set(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()`),oZ=new Set(`,[]{}`),sZ=new Set(` ,[]{}
\r `),cZ=e=>!e||sZ.has(e),lZ=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer=``,this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if(typeof e!=`string`)throw TypeError(`source is not a string`);this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let n=this.next??`stream`;for(;n&&(t||this.hasChars(1));)n=yield*this.parseNext(n)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;t===` `||t===` `;)t=this.buffer[++e];return!t||t===`#`||t===`
`:case`\r`:case` `:return!0;default:return!1}}var aZ=new Set(`0123456789ABCDEFabcdef`),oZ=new Set(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()`),sZ=new Set(`,[]{}`),kte=new Set(` ,[]{}
\r `),cZ=e=>!e||kte.has(e),lZ=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer=``,this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if(typeof e!=`string`)throw TypeError(`source is not a string`);this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let n=this.next??`stream`;for(;n&&(t||this.hasChars(1));)n=yield*this.parseNext(n)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;t===` `||t===` `;)t=this.buffer[++e];return!t||t===`#`||t===`
`||t===`\r`&&this.buffer[e+1]===`
`}charAt(e){return this.buffer[this.pos+e]}continueScalar(e){let t=this.buffer[e];if(this.indentNext>0){let n=0;for(;t===` `;)t=this.buffer[++n+e];if(t===`\r`){let t=this.buffer[n+e+1];if(t===`
`||!t&&!this.atEnd)return e+n+1}return t===`
@@ -113,10 +113,10 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
`)break}default:break loop}if(!n&&!this.atEnd)return this.setNext(`block-scalar`);if(t>=this.indentNext){this.indentNext=this.blockScalarIndent===-1?t:this.blockScalarIndent+(this.indentNext===0?1:this.indentNext);do{let t=this.continueScalar(e+1);if(t===-1)break;e=this.buffer.indexOf(`
`,t)}while(e!==-1);if(e===-1){if(!this.atEnd)return this.setNext(`block-scalar`);e=this.buffer.length}}let r=e+1;for(n=this.buffer[r];n===` `;)n=this.buffer[++r];if(n===` `){for(;n===` `||n===` `||n===`\r`||n===`
`;)n=this.buffer[++r];e=r-1}else if(!this.blockScalarKeep)do{let n=e-1,r=this.buffer[n];r===`\r`&&(r=this.buffer[--n]);let i=n;for(;r===` `;)r=this.buffer[--n];if(r===`
`&&n>=this.pos&&n+1+t>i)e=n;else break}while(1);return yield``,yield*this.pushToIndex(e+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){let e=this.flowLevel>0,t=this.pos-1,n=this.pos-1,r;for(;r=this.buffer[++n];)if(r===`:`){let r=this.buffer[n+1];if(iZ(r)||e&&oZ.has(r))break;t=n}else if(iZ(r)){let i=this.buffer[n+1];if(r===`\r`&&(i===`
`&&n>=this.pos&&n+1+t>i)e=n;else break}while(1);return yield``,yield*this.pushToIndex(e+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){let e=this.flowLevel>0,t=this.pos-1,n=this.pos-1,r;for(;r=this.buffer[++n];)if(r===`:`){let r=this.buffer[n+1];if(iZ(r)||e&&sZ.has(r))break;t=n}else if(iZ(r)){let i=this.buffer[n+1];if(r===`\r`&&(i===`
`?(n+=1,r=`
`,i=this.buffer[n+1]):t=n),i===`#`||e&&oZ.has(i))break;if(r===`
`){let e=this.continueScalar(n+1);if(e===-1)break;n=Math.max(n,e-2)}}else{if(e&&oZ.has(r))break;t=n}return!r&&!this.atEnd?this.setNext(`plain-scalar`):(yield``,yield*this.pushToIndex(t+1,!0),e?`flow`:`doc`)}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){let n=this.buffer.slice(this.pos,e);return n?(yield n,this.pos+=n.length,n.length):(t&&(yield``),0)}*pushIndicators(){let e=0;loop:for(;;){switch(this.charAt(0)){case`!`:e+=yield*this.pushTag(),e+=yield*this.pushSpaces(!0);continue loop;case`&`:e+=yield*this.pushUntil(cZ),e+=yield*this.pushSpaces(!0);continue loop;case`-`:case`?`:case`:`:{let t=this.flowLevel>0,n=this.charAt(1);if(iZ(n)||t&&oZ.has(n)){t?this.flowKey&&=!1:this.indentNext=this.indentValue+1,e+=yield*this.pushCount(1),e+=yield*this.pushSpaces(!0);continue loop}}}break loop}return e}*pushTag(){if(this.charAt(1)===`<`){let e=this.pos+2,t=this.buffer[e];for(;!iZ(t)&&t!==`>`;)t=this.buffer[++e];return yield*this.pushToIndex(t===`>`?e+1:e,!1)}{let e=this.pos+1,t=this.buffer[e];for(;t;)if(Dte.has(t))t=this.buffer[++e];else if(t===`%`&&aZ.has(this.buffer[e+1])&&aZ.has(this.buffer[e+2]))t=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
`,i=this.buffer[n+1]):t=n),i===`#`||e&&sZ.has(i))break;if(r===`
`){let e=this.continueScalar(n+1);if(e===-1)break;n=Math.max(n,e-2)}}else{if(e&&sZ.has(r))break;t=n}return!r&&!this.atEnd?this.setNext(`plain-scalar`):(yield``,yield*this.pushToIndex(t+1,!0),e?`flow`:`doc`)}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){let n=this.buffer.slice(this.pos,e);return n?(yield n,this.pos+=n.length,n.length):(t&&(yield``),0)}*pushIndicators(){let e=0;loop:for(;;){switch(this.charAt(0)){case`!`:e+=yield*this.pushTag(),e+=yield*this.pushSpaces(!0);continue loop;case`&`:e+=yield*this.pushUntil(cZ),e+=yield*this.pushSpaces(!0);continue loop;case`-`:case`?`:case`:`:{let t=this.flowLevel>0,n=this.charAt(1);if(iZ(n)||t&&sZ.has(n)){t?this.flowKey&&=!1:this.indentNext=this.indentValue+1,e+=yield*this.pushCount(1),e+=yield*this.pushSpaces(!0);continue loop}}}break loop}return e}*pushTag(){if(this.charAt(1)===`<`){let e=this.pos+2,t=this.buffer[e];for(;!iZ(t)&&t!==`>`;)t=this.buffer[++e];return yield*this.pushToIndex(t===`>`?e+1:e,!1)}{let e=this.pos+1,t=this.buffer[e];for(;t;)if(oZ.has(t))t=this.buffer[++e];else if(t===`%`&&aZ.has(this.buffer[e+1])&&aZ.has(this.buffer[e+2]))t=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
`?yield*this.pushCount(1):e===`\r`&&this.charAt(1)===`
`?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,n;do n=this.buffer[++t];while(n===` `||e&&n===` `);let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}},uZ=class{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let t=0,n=this.lineStarts.length;for(;t<n;){let r=t+n>>1;this.lineStarts[r]<e?t=r+1:n=r}if(this.lineStarts[t]===e)return{line:t+1,col:1};if(t===0)return{line:0,col:e};let r=this.lineStarts[t-1];return{line:t,col:e-r+1}}}};function dZ(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function fZ(e){for(let t=0;t<e.length;++t)switch(e[t].type){case`space`:case`comment`:case`newline`:break;default:return t}return-1}function pZ(e){switch(e?.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:case`flow-collection`:return!0;default:return!1}}function mZ(e){switch(e.type){case`document`:return e.start;case`block-map`:{let t=e.items[e.items.length-1];return t.sep??t.start}case`block-seq`:return e.items[e.items.length-1].start;default:return[]}}function hZ(e){if(e.length===0)return[];let t=e.length;loop:for(;--t>=0;)switch(e[t].type){case`doc-start`:case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:case`newline`:break loop}for(;e[++t]?.type===`space`;);return e.splice(t,e.length)}function gZ(e,t){if(t.length<1e5)Array.prototype.push.apply(e,t);else for(let n=0;n<t.length;++n)e.push(t[n])}function _Z(e){if(e.start.type===`flow-seq-start`)for(let t of e.items)t.sep&&!t.value&&!dZ(t.start,`explicit-key-ind`)&&!dZ(t.sep,`map-value-ind`)&&(t.key&&(t.value=t.key),delete t.key,pZ(t.value)?t.value.end?gZ(t.value.end,t.sep):t.value.end=t.sep:gZ(t.start,t.sep),delete t.sep)}var vZ=class{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source=``,this.type=``,this.lexer=new lZ,this.onNewLine=e}*parse(e,t=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(let n of this.lexer.lex(e,t))yield*this.next(n);t||(yield*this.end())}*next(e){if(this.source=e,this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=e.length;return}let t=rZ(e);if(!t){let t=`Not a YAML token: ${e}`;yield*this.pop({type:`error`,offset:this.offset,message:t,source:e}),this.offset+=e.length}else if(t===`scalar`)this.atNewLine=!1,this.atScalar=!0,this.type=`scalar`;else{switch(this.type=t,yield*this.step(),t){case`newline`:this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case`space`:this.atNewLine&&e[0]===` `&&(this.indent+=e.length);break;case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:this.atNewLine&&(this.indent+=e.length);break;case`doc-mode`:case`flow-error-end`:return;default:this.atNewLine=!1}this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){let e=this.peek(1);if(this.type===`doc-end`&&e?.type!==`doc-end`){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:`doc-end`,offset:this.offset,source:this.source});return}if(!e)return yield*this.stream();switch(e.type){case`document`:return yield*this.document(e);case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return yield*this.scalar(e);case`block-scalar`:return yield*this.blockScalar(e);case`block-map`:return yield*this.blockMap(e);case`block-seq`:return yield*this.blockSequence(e);case`flow-collection`:return yield*this.flowCollection(e);case`doc-end`:return yield*this.documentEnd(e)}yield*this.pop()}peek(e){return this.stack[this.stack.length-e]}*pop(e){let t=e??this.stack.pop();if(!t)yield{type:`error`,offset:this.offset,source:``,message:`Tried to pop an empty stack`};else if(this.stack.length===0)yield t;else{let e=this.peek(1);switch(t.type===`block-scalar`?t.indent=`indent`in e?e.indent:0:t.type===`flow-collection`&&e.type===`document`&&(t.indent=0),t.type===`flow-collection`&&_Z(t),e.type){case`document`:e.value=t;break;case`block-scalar`:e.props.push(t);break;case`block-map`:{let n=e.items[e.items.length-1];if(n.value){e.items.push({start:[],key:t,sep:[]}),this.onKeyLine=!0;return}if(n.sep)n.value=t;else{Object.assign(n,{key:t,sep:[]}),this.onKeyLine=!n.explicitKey;return}break}case`block-seq`:{let n=e.items[e.items.length-1];n.value?e.items.push({start:[],value:t}):n.value=t;break}case`flow-collection`:{let n=e.items[e.items.length-1];!n||n.value?e.items.push({start:[],key:t,sep:[]}):n.sep?n.value=t:Object.assign(n,{key:t,sep:[]});return}default:yield*this.pop(),yield*this.pop(t)}if((e.type===`document`||e.type===`block-map`||e.type===`block-seq`)&&(t.type===`block-map`||t.type===`block-seq`)){let n=t.items[t.items.length-1];n&&!n.sep&&!n.value&&n.start.length>0&&fZ(n.start)===-1&&(t.indent===0||n.start.every(e=>e.type!==`comment`||e.i Line truncated
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
@@ -126,14 +126,14 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
`).find(e=>e.trim())?.trim()}}function NZ(e,t){let n=JSON.stringify(e??{})+` `+(typeof t==`string`?`{{ ${t.replace(/^!/,``)} }}`:``);return[...new Set([...n.matchAll(kZ)].map(e=>e[1]))]}function PZ(e){let t=bZ(e).toJS(),n=AZ(t)&&Array.isArray(t.steps)?t.steps:[],r=[],i=[],a=new Map,o=[],s=`start`;r.push({id:s,type:`step`,position:{x:0,y:0},data:{kind:`start`,key:`start`,title:`Starts when`,type:``,detail:``}});let c=[s],l=1,u=new Map,d=e=>{let t=u.get(e)??0;return u.set(e,t+1),t},f=(e,t,n,i,s,c,l)=>{let u=AZ(e)?e:{},f=typeof u.type==`string`?u.type:``,p=AZ(u.settings)?u.settings:{},m=typeof u.id==`string`?u.id:``,h=`step-${t}`;r.push({id:h,type:`step`,position:{x:n,y:i},data:{kind:`step`,key:m||t,title:m||OZ(f),type:f,detail:jZ(f,p),summary:MZ(p),when:typeof u.when==`string`?u.when:void 0,retry:AZ(u.retry)&&typeof u.retry.attempts==`number`?u.retry.attempts:void 0,continues:u.on_failure===`continue`,branch:s,path:l,...c??{stage:m||f,occurrence:d(m||f)}}}),m&&a.set(m,h);for(let e of NZ(u.settings,u.when))o.push({from:e,to:h});return h},p=(e,t,n)=>{e.forEach((r,a)=>i.push({id:`flow-${r}-${t}`,source:r,target:t,kind:`flow`,insertAfter:a===e.length-1?n:void 0}))};for(let[e,t]of n.entries()){if(AZ(t)&&AZ(t.parallel)){let n=Object.entries(t.parallel),r=typeof t.id==`string`?t.id:`parallel`,i={stage:r,occurrence:d(r)},a=[],o=0;n.forEach(([t,r],s)=>{let u=(s-(n.length-1)/2)*EZ,d=c,m=c;(Array.isArray(r)?r:[]).forEach((r,a)=>{let c=f(r,`${e+1}-${t}-${a+1}`,u,(l+a)*TZ,t,i,[`steps`,e,`parallel`,t,a]);p(d,c,d===m&&s===n.length-1?e-1:void 0),d=[c],o=Math.max(o,a+1)}),a.push(...d)}),c=a,l+=Math.max(o,1);continue}let n=f(t,String(e+1),0,l*TZ,void 0,void 0,[`steps`,e]);p(c,n,e-1),c=[n],l++}r.push({id:`add-end`,type:`add`,position:{x:104,y:l*TZ-24},data:{kind:`step`,key:`add`,title:``,type:``,detail:``}}),p(c,`add-end`);for(let{from:e,to:t}of o){let n=a.get(e);n&&(i.some(e=>e.kind===`flow`&&e.source===n&&e.target===t)||i.push({id:`data-${n}-${t}`,source:n,target:t,kind:`data`,label:e,offset:24+14*i.filter(e=>e.kind===`data`).length,sourceHandle:`data-out`,targetHandle:`data-in`}))}return{nodes:r,edges:i}}var FZ={agent:$u,command:Bd,repo:hd,gate:Ld,forge:Cd,human:qd,review:pd,workflow:Xd},IZ={agent:`Agents`,command:`Commands`,repo:`Repository`,gate:`Checks`,forge:`Issues and PRs`,human:`People`,review:`Review`,workflow:`Flow`};function LZ(e){return FZ[e.split(`.`)[0]]??Xd}function RZ(e){return Object.keys(IZ).map(t=>({title:IZ[t],icon:FZ[t],types:e.filter(e=>e.split(`.`)[0]===t)})).filter(e=>e.types.length)}function zZ(e,t){let n=bZ(e).getIn(t,!0);if(Vq(n))return n.toJSON()}function BZ(e,t,n){let r=bZ(e);return r.setIn(t,r.createNode(KZ(n))),r.toString()}function VZ(e,t,n){let r=bZ(e),i=r.get(`steps`,!0);if(Wq(i)||(r.set(`steps`,r.createNode([])),i=r.get(`steps`,!0)),!Wq(i))return{source:e,path:[]};let a=Math.min(Math.max(t+1,0),i.items.length);return i.items.splice(a,0,r.createNode({type:n})),{source:r.toString(),path:[`steps`,a]}}function HZ(e,t){let n=bZ(e),r=n.getIn(t.slice(0,-1),!0),i=t.at(-1);if(!Wq(r)||typeof i!=`number`)return{source:e,path:t};let a=n.createNode(n.getIn(t));return Vq(a)&&a.delete(`id`),r.items.splice(i+1,0,a),{source:n.toString(),path:[...t.slice(0,-1),i+1]}}function UZ(e,t){let n=bZ(e);n.deleteIn(t);let r=t.slice(0,-1);if(r.length>2){let e=n.getIn(r,!0);Wq(e)&&e.items.length===0&&n.deleteIn(r)}return n.toString()}function WZ(e,t,n){let r=bZ(e),i=r.getIn(t.slice(0,-1),!0),a=t.at(-1);if(!Wq(i)||typeof a!=`number`)return{source:e,path:t};let o=a+n;if(o<0||o>=i.items.length)return{source:e,path:t};let[s]=i.items.splice(a,1);return i.items.splice(o,0,s),{source:r.toString(),path:[...t.slice(0,-1),o]}}function GZ(e,t){let n=bZ(e).toJS(),r=Array.isArray(n?.steps)?n.steps:[],i=typeof t[1]==`number`?t[1]:r.length,a=[],o=e=>{if(typeof e!=`object`||!e)return;let t=e;if(typeof t.id==`string`&&a.push(t.id),typeof t.parallel==`object`&&t.parallel!==null)for(let e of Object.values(t.parallel))Array.isArray(e)&&e.forEach(o)};if(r.slice(0,i).forEach(o),t.length===5){let e=r[i]?.parallel?.[t[3]];Array.isArray(e)&&e.slice(0,t[4]).forEach(o)}return a}function KZ(e){if(Array.isArray(e))return e.map(KZ);if(typeof e!=`object`||!e)return e;let t={};for(let[n,r]of Object.entries(e)){if(r===void 0||r===``||r===null)continue;let e=KZ(r);(typeof e!=`object`||!e||Array.isArray(e)||Object.keys(e).length!==0)&&(t[n]=e)}return t}function qZ(e,t){let n=bZ(e).get(t,!0);return n&&typeof n==`object`&&`toJSON`in n?n.toJSON():bZ(e).get(t)}function JZ(e,t,n){let r=bZ(e),i=KZ({[t]:n})[t];return i===void 0?r.delete(t):r.set(t,r.createNode(i)),r.toString()}function YZ(e){return e.ok?`Valid`:e.line?`Line ${e.line}: ${e.message}`:e.message}function XZ(e,t=[]){let n=bZ(e),r=n.errors[0];if(r)return{ok:!1,message:uQ(r.message),line:r.linePos?.[0]?.line};let i=n.toJS();if(!dQ(i))return{ok:!1,message:`A workflow is a mapping with an id and steps.`};let a=typeof i.id==`string`?i.id.trim():``;if(!a)return{ok:!1,message:`workflow id is required`};let Line truncated
`).map((e,t)=>({number:t+1,text:e,tokens:oQ(e)}))}var iQ=/^(\s*)(-\s+)?/,aQ=/^([^:#\s][^:#]*?)(:)(\s*)(.*)$/;function oQ(e){let{code:t,comment:n}=sQ(e),r=cQ(t);return n&&r.push({text:n,kind:`comment`}),r}function sQ(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(t){r===t&&(t=``);continue}if(r===`"`||r===`'`){t=r;continue}if(r===`#`&&(n===0||/\s/.test(e[n-1]??``)))return{code:e.slice(0,n),comment:e.slice(n)}}return{code:e,comment:``}}function cQ(e){if(!e)return[];let t=[],n=iQ.exec(e);n?.[1]&&t.push({text:n[1],kind:`plain`}),n?.[2]&&t.push({text:n[2],kind:`punct`});let r=e.slice(n?.[0].length??0);if(!r)return t;let i=aQ.exec(r);return i?(t.push({text:i[1]??``,kind:`key`}),t.push({text:i[2]??`:`,kind:`punct`}),i[3]&&t.push({text:i[3],kind:`plain`}),[...t,...lQ(i[4]??``)]):[...t,...lQ(r)]}function lQ(e){if(!e)return[];let t=/^("[^"]*"?|'[^']*'?)([\s\S]*)$/.exec(e);if(!t)return[{text:e,kind:`plain`}];let n=[{text:t[1]??``,kind:`string`}];return t[2]&&n.push({text:t[2],kind:`plain`}),n}function uQ(e){return e.split(`
`)[0]?.trim()||`invalid YAML`}function dQ(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function fQ(e){return typeof e==`string`&&e.trim()!==``}var pQ={class:`flex h-full w-[24rem] flex-col border-l border-border bg-card shadow-xl`},mQ={class:`flex items-center gap-2.5 border-b border-border px-4 py-3`},hQ={class:`flex size-8 shrink-0 items-center justify-center rounded-md bg-secondary text-primary`},gQ={class:`min-w-0 flex-1`},_Q=[`value`,`placeholder`],vQ={class:`truncate font-mono text-[11px] text-fg-subtle`},yQ={class:`flex-1 space-y-5 overflow-y-auto px-4 py-4`},bQ={key:0,class:`rounded-md bg-danger/10 px-2.5 py-1.5 text-xs text-danger`,role:`alert`},xQ={key:1,class:`space-y-1.5`},SQ=[`title`],CQ=[`value`],wQ=[`value`],TQ={key:3,class:`flex flex-wrap items-center gap-1 pt-0.5`},EQ=[`onClick`],DQ=[`onClick`],OQ={key:2,class:`divide-y divide-border rounded-md border border-border`},kQ=[`title`],AQ=[`value`,`onChange`],jQ=[`value`],MQ=[`value`,`onInput`],NQ=[`value`,`onFocus`,`onInput`],PQ=[`title`],FQ={key:0,class:`text-xs text-danger`},IQ={class:`space-y-2`},LQ={class:`divide-y divide-border rounded-md border border-border`},RQ={class:`flex min-h-10 items-center gap-3 px-3 py-1.5`},zQ=[`value`],BQ={class:`flex min-h-10 items-center gap-3 px-3 py-1.5`},VQ=[`value`],HQ={class:`flex min-h-10 items-center gap-3 px-3 py-1.5`},UQ=[`value`],WQ={class:`flex items-center border-t border-border px-4 py-2.5`},GQ=L({__name:`StepEditor`,props:{yaml:{},path:{},vocabulary:{}},emits:[`update:yaml`,`close`,`remove`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>zZ(n.yaml,n.path)??{}),a=Y(()=>typeof i.value.type==`string`?i.value.type:``),o=Y(()=>n.vocabulary.find(e=>e.name===a.value)),s=Y(()=>typeof i.value.settings==`object`&&i.value.settings!==null?i.value.settings:{}),c=Y(()=>GZ(n.yaml,n.path)),l=Y(()=>o.value?.settings&&i.value.settings?tQ(i.value.settings,o.value.settings,`settings`):``),u=[`mission`,`workflow`,`message`,`body`,`plan`,`then`,`status`,`detail`,`run`,`rules`],d=/mission|body|detail|plan|rules/;function f(e,t){return t.type===`string`?t.enum?`select`:d.test(e)?`text`:`line`:t.type===`boolean`?`boolean`:t.type===`integer`||t.type===`number`?`number`:t.type===`array`&&t.items?.type===`string`?`lines`:`yaml`}let p=Y(()=>{let e=Object.entries(o.value?.settings?.properties??{}).map(([e,t])=>({key:e,schema:t,kind:f(e,t)})),t=e.filter(e=>u.includes(e.key)&&e.kind!==`boolean`).sort((e,t)=>u.indexOf(e.key)-u.indexOf(t.key))[0],n=e.filter(e=>e!==t);return{lead:t,compact:n.filter(e=>[`select`,`line`,`number`,`boolean`].includes(e.kind)),long:n.filter(e=>[`text`,`lines`,`yaml`].includes(e.kind))}});function m(e){let{id:t,type:i,...a}=e;r(`update:yaml`,BZ(n.yaml,n.path,{id:t,type:i,...a}))}function h(e,t){m({...i.value,[e]:t})}function g(e,t){m({...i.value,settings:{...s.value,[e]:t}})}let _=N(null);function v(e,t){let n=_.value??p.value.lead?.key;if(!n)return;let r=typeof s.value[n]==`string`?s.value[n]:``,i=`{{ steps.${e}.${t} }}`;g(n,r?`${r.trimEnd()} ${i}`:i)}let y=N({});function b(e,t){try{g(e,t.trim()?xZ(t):void 0),y.value={...y.value,[e]:``}}catch(t){y.value={...y.value,[e]:String(t.message).split(`
`)[0]}}}let x=e=>e===void 0?``:SZ(e).trimEnd(),S=(e,t)=>t.title??e.replaceAll(`_`,` `).replace(/^./,e=>e.toUpperCase()),C=e=>typeof s.value[e]==`string`?s.value[e]:``;return(e,t)=>(V(),H(`aside`,pQ,[W(`header`,mQ,[W(`span`,hQ,[(V(),U(ea(P(LZ)(a.value)),{class:`size-4`}))]),W(`div`,gQ,[W(`input`,{value:i.value.id??``,class:`w-full truncate bg-transparent text-sm font-medium outline-none placeholder:text-fg-subtle focus:underline`,placeholder:P(OZ)(a.value),"aria-label":`Step id`,onInput:t[0]||=e=>h(`id`,e.target.value)},null,40,_Q),W(`div`,vQ,M(a.value),1)]),G(P($),{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,onClick:t[1]||=e=>r(`close`)},{default:F(()=>[G(P(Qd))]),_:1})]),W(`div`,yQ,[l.value?(V(),H(`p`,bQ,M(l.value),1)):q(``,!0),p.value.lead?(V(),H(`section`,xQ,[W(`div`,{class:`flex items-center gap-1 text-xs font-medium text-muted-foreground`,title:p.value.lead.schema.description},[K(M(S(p.value.lead.key,p.value.lead.schema))+` `,1),p.value.lead.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,SQ),p.value.lead.kind===`select`?(V(),H(`select`,{key:0,class:`h-9 w-full rounded-md border border-input bg-background px-2`,value:C(p.value.lead.key),onChange:t[2]||=e=>g(p.value.lead.key,e.target.value||void 0)},[t[12]||=W(`option`,{value:``},`Default`,-1),(V(!0),H(B,null,R(p.value.lead.schema.enum,e=>(V(),H(`option`,{key:e,value:e},M(e),9,wQ))),128))],40,CQ)):p.value.lead.kind===`text`?(V(),U(P(uT),{key:1,"model-value":C(p.value.lead.key),class:`min-h-40 text-[13px] leading-relaxed`,onFocus:t[3]||=e=>_.value=p.value.lead.key,"onUpdate:modelValue":t[4]||=e=>g(p.value.lead.key,String(e))},null,8,[`model-value`])):(V(),U(P(jO),{key:2,"model-value":C(p.value.lead.key),onFocus:t[5]||=e=>_.value=p.value.lead.key,"onUpdate:modelValue":t[6]||=e=>g(p.value.lead.key,String(e))},null,8,[`model-value`])),c.value.length&&p.value.lead.kind!==`select`?(V(),H(`div`,TQ,[t[13]||=W(`span`,{class:`text-[11px] text-fg-subtle`},`Insert`,-1),(V(!0),H(B,null,R(c.value,e=>(V(),H(B,{key:e},[W(`button`,{type:`button`,class:`rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary`,onClick:t=>v(e,`summary`)},M(e),9,EQ),W(`button`,{type:`button`,class:`rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary`,onClick:t=>v(e,`result`)},M(e)+`.result`,9,DQ)],64))),128))])):q(``,!0)])):q(``,!0),p.value.compact.length?(V(),H(`section`,OQ,[(V(!0),H(B,null,R(p.value.compact,e=>(V(),H(`div`,{key:e.key,class:`flex min-h-10 items-center gap-3 px-3 py-1.5`},[W(`span`,{class:`flex flex-1 items-center gap-1 text-[13px]`,title:e.schema.description},[K(M(S(e.key,e.schema))+` `,1),e.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,kQ),e.kind===`boolean`?(V(),U(P(nk),{key:0,"model-value":s.value[e.key]===!0,"onUpdate:modelValue":t=>g(e.key,t||void 0)},null,8,[`model-value`,`onUpdate:modelValue`])):e.kind===`select`?(V(),H(`select`,{key:1,class:`h-7 max-w-40 rounded-md border border-input bg-background px-1.5 text-[13px]`,value:C(e.key),onChange:t=>g(e.key,t.target.value||void 0)},[t[14]||=W(`option`,{value:``},`Default`,-1),(V(!0),H(B,null,R(e.schema.enum,e=>(V(),H(`option`,{key:e,value:e},M(e),9,jQ))),128))],40,AQ)):e.kind===`number`?(V(),H(`input`,{key:2,type:`number`,class:`h-7 w-24 rounded-md border border-input bg-background px-2 text-right text-[13px]`,value:s.value[e.key]??``,onInput:t=>g(e.key,t.target.value===``?void 0:Number(t.target.value))},null,40,MQ)):(V(),H(`input`,{key:3,class:`h-7 w-40 rounded-md border border-input bg-background px-2 text-[13px]`,value:C(e.key),onFocus:t=>_.value=e.key,onInput:t=>g(e.key,t.target.value)},null,40,NQ))]))),128))])):q(``,!0),(V(!0),H(B,null,R(p.value.long,e=>(V(),H(`section`,{key:e.key,class:`space-y-1.5`},[W(`div`,{class:`flex items-center gap-1 text-xs font-medium text-muted-foreground`,title:e.schema.description},[K(M(S(e.key,e.schema))+` `,1),e.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,PQ),e.kind===`text`?(V(),U(P(uT),{key:0,"model-value":C(e.key),class:`min-h-20 text-[13px]`,onFocus:t=>_.value=e.key,"onUpdate:modelValue":t=>g(e.key,String(t))},null,8,[`model-value`,`onFocus`,`onUpdate:modelValue`])):e.kind===`lines`?(V(),U(P(uT),{key:1,"model-value":Array.isArray(s.value[e.key])?s.value[e.key].join(`
`)[0]}}}let x=e=>e===void 0?``:SZ(e).trimEnd(),S=(e,t)=>t.title??e.replaceAll(`_`,` `).replace(/^./,e=>e.toUpperCase()),C=e=>typeof s.value[e]==`string`?s.value[e]:``;return(e,t)=>(V(),H(`aside`,pQ,[W(`header`,mQ,[W(`span`,hQ,[(V(),U(ea(P(LZ)(a.value)),{class:`size-4`}))]),W(`div`,gQ,[W(`input`,{value:i.value.id??``,class:`w-full truncate bg-transparent text-sm font-medium outline-none placeholder:text-fg-subtle focus:underline`,placeholder:P(OZ)(a.value),"aria-label":`Step id`,onInput:t[0]||=e=>h(`id`,e.target.value)},null,40,_Q),W(`div`,vQ,M(a.value),1)]),G(P($),{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,onClick:t[1]||=e=>r(`close`)},{default:F(()=>[G(P(Qd))]),_:1})]),W(`div`,yQ,[l.value?(V(),H(`p`,bQ,M(l.value),1)):q(``,!0),p.value.lead?(V(),H(`section`,xQ,[W(`div`,{class:`flex items-center gap-1 text-xs font-medium text-muted-foreground`,title:p.value.lead.schema.description},[K(M(S(p.value.lead.key,p.value.lead.schema))+` `,1),p.value.lead.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,SQ),p.value.lead.kind===`select`?(V(),H(`select`,{key:0,class:`h-9 w-full rounded-md border border-input bg-background px-2`,value:C(p.value.lead.key),onChange:t[2]||=e=>g(p.value.lead.key,e.target.value||void 0)},[t[12]||=W(`option`,{value:``},`Default`,-1),(V(!0),H(B,null,R(p.value.lead.schema.enum,e=>(V(),H(`option`,{key:e,value:e},M(e),9,wQ))),128))],40,CQ)):p.value.lead.kind===`text`?(V(),U(P(uT),{key:1,"model-value":C(p.value.lead.key),class:`min-h-40 text-[13px] leading-relaxed`,onFocus:t[3]||=e=>_.value=p.value.lead.key,"onUpdate:modelValue":t[4]||=e=>g(p.value.lead.key,String(e))},null,8,[`model-value`])):(V(),U(P(kO),{key:2,"model-value":C(p.value.lead.key),onFocus:t[5]||=e=>_.value=p.value.lead.key,"onUpdate:modelValue":t[6]||=e=>g(p.value.lead.key,String(e))},null,8,[`model-value`])),c.value.length&&p.value.lead.kind!==`select`?(V(),H(`div`,TQ,[t[13]||=W(`span`,{class:`text-[11px] text-fg-subtle`},`Insert`,-1),(V(!0),H(B,null,R(c.value,e=>(V(),H(B,{key:e},[W(`button`,{type:`button`,class:`rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary`,onClick:t=>v(e,`summary`)},M(e),9,EQ),W(`button`,{type:`button`,class:`rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary`,onClick:t=>v(e,`result`)},M(e)+`.result`,9,DQ)],64))),128))])):q(``,!0)])):q(``,!0),p.value.compact.length?(V(),H(`section`,OQ,[(V(!0),H(B,null,R(p.value.compact,e=>(V(),H(`div`,{key:e.key,class:`flex min-h-10 items-center gap-3 px-3 py-1.5`},[W(`span`,{class:`flex flex-1 items-center gap-1 text-[13px]`,title:e.schema.description},[K(M(S(e.key,e.schema))+` `,1),e.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,kQ),e.kind===`boolean`?(V(),U(P(ek),{key:0,"model-value":s.value[e.key]===!0,"onUpdate:modelValue":t=>g(e.key,t||void 0)},null,8,[`model-value`,`onUpdate:modelValue`])):e.kind===`select`?(V(),H(`select`,{key:1,class:`h-7 max-w-40 rounded-md border border-input bg-background px-1.5 text-[13px]`,value:C(e.key),onChange:t=>g(e.key,t.target.value||void 0)},[t[14]||=W(`option`,{value:``},`Default`,-1),(V(!0),H(B,null,R(e.schema.enum,e=>(V(),H(`option`,{key:e,value:e},M(e),9,jQ))),128))],40,AQ)):e.kind===`number`?(V(),H(`input`,{key:2,type:`number`,class:`h-7 w-24 rounded-md border border-input bg-background px-2 text-right text-[13px]`,value:s.value[e.key]??``,onInput:t=>g(e.key,t.target.value===``?void 0:Number(t.target.value))},null,40,MQ)):(V(),H(`input`,{key:3,class:`h-7 w-40 rounded-md border border-input bg-background px-2 text-[13px]`,value:C(e.key),onFocus:t=>_.value=e.key,onInput:t=>g(e.key,t.target.value)},null,40,NQ))]))),128))])):q(``,!0),(V(!0),H(B,null,R(p.value.long,e=>(V(),H(`section`,{key:e.key,class:`space-y-1.5`},[W(`div`,{class:`flex items-center gap-1 text-xs font-medium text-muted-foreground`,title:e.schema.description},[K(M(S(e.key,e.schema))+` `,1),e.schema.description?(V(),U(P(ld),{key:0,class:`size-3 text-fg-subtle`})):q(``,!0)],8,PQ),e.kind===`text`?(V(),U(P(uT),{key:0,"model-value":C(e.key),class:`min-h-20 text-[13px]`,onFocus:t=>_.value=e.key,"onUpdate:modelValue":t=>g(e.key,String(t))},null,8,[`model-value`,`onFocus`,`onUpdate:modelValue`])):e.kind===`lines`?(V(),U(P(uT),{key:1,"model-value":Array.isArray(s.value[e.key])?s.value[e.key].join(`
`):``,class:`min-h-16 font-mono text-xs`,placeholder:`One per line`,"onUpdate:modelValue":t=>g(e.key,String(t).split(`
`).filter(Boolean))},null,8,[`model-value`,`onUpdate:modelValue`])):(V(),H(B,{key:2},[G(P(uT),{"model-value":x(s.value[e.key]),class:`min-h-24 font-mono text-xs`,placeholder:`YAML`,onChange:t=>b(e.key,t.target.value)},null,8,[`model-value`,`onChange`]),y.value[e.key]?(V(),H(`span`,FQ,M(y.value[e.key]),1)):q(``,!0)],64))]))),128)),W(`section`,IQ,[t[19]||=W(`div`,{class:`text-xs font-medium text-muted-foreground`},`Flow`,-1),W(`div`,LQ,[W(`label`,RQ,[t[15]||=W(`span`,{class:`flex-1 text-[13px]`},`Run only when`,-1),W(`input`,{class:`h-7 w-48 rounded-md border border-input bg-background px-2 font-mono text-xs`,placeholder:`always`,value:i.value.when??``,onInput:t[7]||=e=>h(`when`,e.target.value)},null,40,zQ)]),W(`label`,BQ,[t[17]||=W(`span`,{class:`flex-1 text-[13px]`},`If it fails`,-1),W(`select`,{class:`h-7 rounded-md border border-input bg-background px-1.5 text-[13px]`,value:i.value.on_failure??``,onChange:t[8]||=e=>h(`on_failure`,e.target.value||void 0)},[...t[16]||=[W(`option`,{value:``},`Park the task`,-1),W(`option`,{value:`continue`},`Continue`,-1)]],40,VQ)]),W(`label`,HQ,[t[18]||=W(`span`,{class:`flex-1 text-[13px]`},`Attempts`,-1),W(`input`,{type:`number`,min:`1`,max:`10`,placeholder:`1`,class:`h-7 w-20 rounded-md border border-input bg-background px-2 text-right text-[13px]`,value:i.value.retry?.attempts??``,onInput:t[9]||=e=>h(`retry`,e.target.value===``?void 0:{...i.value.retry,attempts:Number(e.target.value)})},null,40,UQ)])])])]),W(`footer`,WQ,[G(P($),{type:`button`,variant:`ghost`,size:`sm`,class:`text-danger`,onClick:t[10]||=e=>r(`remove`)},{default:F(()=>[G(P(Hd)),t[20]||=K(` Delete step`,-1)]),_:1}),G(P($),{type:`button`,size:`sm`,class:`ml-auto`,onClick:t[11]||=e=>r(`close`)},{default:F(()=>[...t[21]||=[K(`Done`,-1)]]),_:1})])]))}}),KQ=`repository_path`;function qQ(e,t,n){let r=[];for(let[n,i]of e){let e=t[n];e?.from===`path`&&e.path.trim()&&r.push({name:n,path:e.path.trim(),type:i.type??`string`,required:i.required===!0})}return n.trim()&&r.push({name:KQ,path:n.trim(),type:`string`,required:!0}),r}function JQ(e){return Array.isArray(e)?`array`:e===null?`null`:typeof e==`boolean`?`bool`:typeof e==`object`?`object`:typeof e}function YQ(e,t,n){let r=[];for(let[i,a]of e){let e=t[i],o=a.type??`string`;if(!(e&&(e.from===`path`?e.path.trim():e.value!==``))){a.required&&r.push(`${i} is required`);continue}if(e.from===`path`){let e=n?.failures?.find(e=>e.field_name===i);e&&r.push(`${i}: ${e.reason}`);continue}let s=JQ(kP(e.value,o));o!==`any`&&s!==o&&r.push(`${i} is ${o}, but ${JSON.stringify(e.value)} is not`)}return n?.failures?.some(e=>e.field_name===`repository_path`)&&r.push(`the repository path does not resolve`),r}function XQ(e,t){let n={};for(let[r,i]of e){let e=t[r];e?.from===`path`&&e.path.trim()?n[r]={param:r}:e?.from===`value`&&e.value!==``&&(n[r]={value:kP(e.value,i.type??`string`)})}return n}function ZQ(e,t){let n=e=>t.find(t=>t.name===e)?.path??``,r={};for(let[t,i]of Object.entries(e.inputs??{}))r[t]=i.param?{from:`path`,path:n(i.param),value:``}:{from:`value`,path:``,value:typeof i.value==`string`?i.value:JSON.stringify(i.value)};return{rows:r,repositoryPath:n(e.repo_param)}}function QQ(e,t=``){return Array.isArray(e)?e.slice(0,3).flatMap((e,n)=>{let r=`${t}[${n}]`;return[r,...QQ(e,r)]}):e&&typeof e==`object`?Object.entries(e).flatMap(([e,n])=>{let r=t?`${t}.${e}`:e;return[r,...QQ(n,r)]}):[]}function $Q(e){try{return e?.body?JSON.parse(e.body):null}catch{return null}}function e$(e){try{let t=JSON.parse(e.headers??`{}`);return Object.fromEntries(Object.entries(t).map(([e,t])=>[e,Array.isArray(t)?t.join(`, `):String(t)]))}catch{return{}}}function t$(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>80?`${t.slice(0,80)}…`:t}var n$={class:`flex h-full flex-col`},r$={class:`flex items-center gap-2 border-b border-border px-4 py-3`},i$={class:`min-w-0 flex-1 truncate text-sm font-medium`},a$={key:0,class:`flex flex-1 items-center justify-center`},o$={class:`space-y-1.5`},s$=[`disabled`],c$=[`value`],l$={key:1,class:`space-y-1.5`},u$=[`value`],d$=[`title`],f$={class:`space-y-1.5`},p$={id:`bind-paths`},m$=[`value`],h$={class:`divide-y divide-border rounded-md border border-border`},g$={class:`flex items-center gap-1.5 text-xs`},_$={class:`font-mono`},v$={class:`text-fg-subtle`},y$={key:0,class:`text-danger`,title:`Required`},b$=[`title`,`aria-label`,`onClick`],x$=[`onUpdate:modelValue`,`aria-label`],S$=[`onUpdate:modelValue`,`aria-label`],C$={key:2,class:`text-xs text-danger`},w$=[`title`],T$={key:0,class:`space-y-1 px-3 py-2`},E$={key:0,class:`text-xs text-danger`},D$={key:1,class:`truncate font-mono text-xs text-success`},O$={key:1,class:`px-3 py-2 text-xs text-fg-subtle`},k$={class:`space-y-2`},A$={key:0,role:`alert`,class:`text-xs text-danger`},j$={key:1,class:`text-xs text-fg-subtle`},M$={class:`flex gap-2`},N$=`__new__`,P$=L({__name:`BindEvent`,props:{yaml:{},binding:{}},emits:[`back`,`saved`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>String(qZ(n.yaml,`id`)??``)),a=Y(()= Line truncated
`).filter(Boolean))},null,8,[`model-value`,`onUpdate:modelValue`])):(V(),H(B,{key:2},[G(P(uT),{"model-value":x(s.value[e.key]),class:`min-h-24 font-mono text-xs`,placeholder:`YAML`,onChange:t=>b(e.key,t.target.value)},null,8,[`model-value`,`onChange`]),y.value[e.key]?(V(),H(`span`,FQ,M(y.value[e.key]),1)):q(``,!0)],64))]))),128)),W(`section`,IQ,[t[19]||=W(`div`,{class:`text-xs font-medium text-muted-foreground`},`Flow`,-1),W(`div`,LQ,[W(`label`,RQ,[t[15]||=W(`span`,{class:`flex-1 text-[13px]`},`Run only when`,-1),W(`input`,{class:`h-7 w-48 rounded-md border border-input bg-background px-2 font-mono text-xs`,placeholder:`always`,value:i.value.when??``,onInput:t[7]||=e=>h(`when`,e.target.value)},null,40,zQ)]),W(`label`,BQ,[t[17]||=W(`span`,{class:`flex-1 text-[13px]`},`If it fails`,-1),W(`select`,{class:`h-7 rounded-md border border-input bg-background px-1.5 text-[13px]`,value:i.value.on_failure??``,onChange:t[8]||=e=>h(`on_failure`,e.target.value||void 0)},[...t[16]||=[W(`option`,{value:``},`Park the task`,-1),W(`option`,{value:`continue`},`Continue`,-1)]],40,VQ)]),W(`label`,HQ,[t[18]||=W(`span`,{class:`flex-1 text-[13px]`},`Attempts`,-1),W(`input`,{type:`number`,min:`1`,max:`10`,placeholder:`1`,class:`h-7 w-20 rounded-md border border-input bg-background px-2 text-right text-[13px]`,value:i.value.retry?.attempts??``,onInput:t[9]||=e=>h(`retry`,e.target.value===``?void 0:{...i.value.retry,attempts:Number(e.target.value)})},null,40,UQ)])])])]),W(`footer`,WQ,[G(P($),{type:`button`,variant:`ghost`,size:`sm`,class:`text-danger`,onClick:t[10]||=e=>r(`remove`)},{default:F(()=>[G(P(Hd)),t[20]||=K(` Delete step`,-1)]),_:1}),G(P($),{type:`button`,size:`sm`,class:`ml-auto`,onClick:t[11]||=e=>r(`close`)},{default:F(()=>[...t[21]||=[K(`Done`,-1)]]),_:1})])]))}}),KQ=`repository_path`;function qQ(e,t,n){let r=[];for(let[n,i]of e){let e=t[n];e?.from===`path`&&e.path.trim()&&r.push({name:n,path:e.path.trim(),type:i.type??`string`,required:i.required===!0})}return n.trim()&&r.push({name:KQ,path:n.trim(),type:`string`,required:!0}),r}function JQ(e){return Array.isArray(e)?`array`:e===null?`null`:typeof e==`boolean`?`bool`:typeof e==`object`?`object`:typeof e}function YQ(e,t,n){let r=[];for(let[i,a]of e){let e=t[i],o=a.type??`string`;if(!(e&&(e.from===`path`?e.path.trim():e.value!==``))){a.required&&r.push(`${i} is required`);continue}if(e.from===`path`){let e=n?.failures?.find(e=>e.field_name===i);e&&r.push(`${i}: ${e.reason}`);continue}let s=JQ(DP(e.value,o));o!==`any`&&s!==o&&r.push(`${i} is ${o}, but ${JSON.stringify(e.value)} is not`)}return n?.failures?.some(e=>e.field_name===`repository_path`)&&r.push(`the repository path does not resolve`),r}function XQ(e,t){let n={};for(let[r,i]of e){let e=t[r];e?.from===`path`&&e.path.trim()?n[r]={param:r}:e?.from===`value`&&e.value!==``&&(n[r]={value:DP(e.value,i.type??`string`)})}return n}function ZQ(e,t){let n=e=>t.find(t=>t.name===e)?.path??``,r={};for(let[t,i]of Object.entries(e.inputs??{}))r[t]=i.param?{from:`path`,path:n(i.param),value:``}:{from:`value`,path:``,value:typeof i.value==`string`?i.value:JSON.stringify(i.value)};return{rows:r,repositoryPath:n(e.repo_param)}}function QQ(e,t=``){return Array.isArray(e)?e.slice(0,3).flatMap((e,n)=>{let r=`${t}[${n}]`;return[r,...QQ(e,r)]}):e&&typeof e==`object`?Object.entries(e).flatMap(([e,n])=>{let r=t?`${t}.${e}`:e;return[r,...QQ(n,r)]}):[]}function $Q(e){try{return e?.body?JSON.parse(e.body):null}catch{return null}}function e$(e){try{let t=JSON.parse(e.headers??`{}`);return Object.fromEntries(Object.entries(t).map(([e,t])=>[e,Array.isArray(t)?t.join(`, `):String(t)]))}catch{return{}}}function t$(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>80?`${t.slice(0,80)}…`:t}var n$={class:`flex h-full flex-col`},r$={class:`flex items-center gap-2 border-b border-border px-4 py-3`},i$={class:`min-w-0 flex-1 truncate text-sm font-medium`},a$={key:0,class:`flex flex-1 items-center justify-center`},o$={class:`space-y-1.5`},s$=[`disabled`],c$=[`value`],l$={key:1,class:`space-y-1.5`},u$=[`value`],d$=[`title`],f$={class:`space-y-1.5`},p$={id:`bind-paths`},m$=[`value`],h$={class:`divide-y divide-border rounded-md border border-border`},g$={class:`flex items-center gap-1.5 text-xs`},_$={class:`font-mono`},v$={class:`text-fg-subtle`},y$={key:0,class:`text-danger`,title:`Required`},b$=[`title`,`aria-label`,`onClick`],x$=[`onUpdate:modelValue`,`aria-label`],S$=[`onUpdate:modelValue`,`aria-label`],C$={key:2,class:`text-xs text-danger`},w$=[`title`],T$={key:0,class:`space-y-1 px-3 py-2`},E$={key:0,class:`text-xs text-danger`},D$={key:1,class:`truncate font-mono text-xs text-success`},O$={key:1,class:`px-3 py-2 text-xs text-fg-subtle`},k$={class:`space-y-2`},A$={key:0,role:`alert`,class:`text-xs text-danger`},j$={key:1,class:`text-xs text-fg-subtle`},M$={class:`flex gap-2`},N$=`__new__`,P$=L({__name:`BindEvent`,props:{yaml:{},binding:{}},emits:[`back`,`saved`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>String(qZ(n.yaml,`id`)??``)),a=Y(()= Line truncated
`).replace(`
`,`
+`).split(`
`).map(e=>e.trim().toLowerCase());if(i.length===1)return e.toLowerCase()===t.toLowerCase();r||n.add(e.toLowerCase());let a=i.every((e,t)=>n.has(e)&&Array.from(n.values())[t]===i[t]);return r&&n.delete(e.toLowerCase()),a}function v5(e,t){return n=>{if(!n.code&&!n.key)return!1;let r=y5(n.code,e);return Array.isArray(e)?e.some(e=>_5(n[r],e,t,n.type===`keyup`)):_5(n[r],e,t,n.type===`keyup`)}}function y5(e,t){return t.includes(e)?`code`:`key`}function b5(e,t){let n=Y(()=>fn(t?.target)??m5),r=cn(fn(e)===!0),i=!1,a=new Set,o=c(fn(e));I(()=>fn(e),(e,t)=>{typeof t==`boolean`&&typeof e!=`boolean`&&s(),o=c(e)},{immediate:!0}),f0([`blur`,`contextmenu`],s),m0((...e)=>o(...e),e=>{let n=fn(t?.actInsideInputWithModifier)??!0,a=fn(t?.preventDefault)??!1;if(i=g5(e),(!i||i&&!n)&&h5(e))return;let o=e.composedPath?.call(e)?.[0]||e.target,s=o?.nodeName===`BUTTON`||o?.nodeName===`A`;!a&&(i||!s)&&e.preventDefault(),r.value=!0},{eventName:`keydown`,target:n}),m0((...e)=>o(...e),e=>{let n=fn(t?.actInsideInputWithModifier)??!0;if(r.value){if((!i||i&&!n)&&h5(e))return;i=!1,r.value=!1}},{eventName:`keyup`,target:n});function s(){i=!1,a.clear(),r.value=fn(e)===!0}function c(e){return e===null?(s(),()=>!1):typeof e==`boolean`?(s(),r.value=e,()=>!1):Array.isArray(e)||typeof e==`string`?v5(e,a):e}return r}var x5=`vue-flow__node-desc`,S5=`vue-flow__edge-desc`,C5=`vue-flow__aria-live`,w5=[`Enter`,` `,`Escape`],T5={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};function E5(e){return{...e.computedPosition||{x:0,y:0},width:e.dimensions.width||0,height:e.dimensions.height||0}}function D5(e,t){let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)}function O5(e){return{width:e.offsetWidth,height:e.offsetHeight}}function k5(e,t=0,n=1){return Math.min(Math.max(e,t),n)}function A5(e,t){return{x:k5(e.x,t[0][0],t[1][0]),y:k5(e.y,t[0][1],t[1][1])}}function j5(e){let t=e.getRootNode();return`elementFromPoint`in t?t:window.document}function M5(e){return e&&typeof e==`object`&&`id`in e&&`source`in e&&`target`in e}function N5(e){return e&&typeof e==`object`&&`id`in e&&`position`in e&&!M5(e)}function P5(e){return N5(e)&&`computedPosition`in e}function F5(e){return!Number.isNaN(e)&&Number.isFinite(e)}function I5(e){return F5(e.width)&&F5(e.height)&&F5(e.x)&&F5(e.y)}function L5(e,t,n){let r={id:e.id.toString(),type:e.type??`default`,dimensions:rn({width:0,height:0}),computedPosition:rn({z:0,...e.position}),handleBounds:{source:[],target:[]},draggable:void 0,selectable:void 0,connectable:void 0,focusable:void 0,selected:!1,dragging:!1,resizing:!1,initialized:!1,isParent:!1,position:{x:0,y:0},data:G7(e.data)?e.data:{},events:rn(G7(e.events)?e.events:{})};return Object.assign(t??r,e,{id:e.id.toString(),parentNode:n})}function R5(e,t,n){let r={id:e.id.toString(),type:e.type??t?.type??`default`,source:e.source.toString(),target:e.target.toString(),sourceHandle:e.sourceHandle?.toString(),targetHandle:e.targetHandle?.toString(),updatable:e.updatable??n?.updatable,selectable:e.selectable??n?.selectable,focusable:e.focusable??n?.focusable,data:G7(e.data)?e.data:{},events:rn(G7(e.events)?e.events:{}),label:e.label??``,interactionWidth:e.interactionWidth??n?.interactionWidth,...n??{}};return Object.assign(t??r,e,{id:e.id.toString()})}function z5(e,t,n,r){let i=typeof e==`string`?e:e.id,a=new Set,o=r===`source`?`target`:`source`;for(let e of n)e[o]===i&&a.add(e[r]);return t.filter(e=>a.has(e.id))}function B5(...e){if(e.length===3){let[t,n,r]=e;return z5(t,n,r,`target`)}let[t,n]=e,r=typeof t==`string`?t:t.id;return n.filter(e=>M5(e)&&e.source===r).map(e=>n.find(t=>N5(t)&&t.id===e.target))}function V5(...e){if(e.length===3){let[t,n,r]=e;return z5(t,n,r,`source`)}let[t,n]=e,r=typeof t==`string`?t:t.id;return n.filter(e=>M5(e)&&e.target===r).map(e=>n.find(t=>N5(t)&&t.id===e.source))}function H5({source:e,sourceHandle:t,target:n,targetHandle:r}){return`vueflow__edge-${e}${t??``}-${n}${r??``}`}function U5(e,t){return t.some(t=>M5(t)&&t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle))}function W5({x:e,y:t},{x:n,y:r,zoom:i}){return{x:e*i+n,y:t*i+r}}function G5({x:e,y:t},{x:n,y:r,zoom:i},a=!1,o=[1,1]){let s={x:(e-n)/i,y:(t-r)/i};return a?F7(s,o):s}function K5(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function q5({x:e,y:t,width:n,height:r}){return{x:e,y:t,x2:e+n,y2:t+r}}function J5({x:e,y:t,x2:n,y2:r}){return{x:e,y:t,width:n-e,height:r-t}}function Y5(e){let t={x:1/0,y:1/0,x2:-1/0,y2:-1/0};for(let n=0;n<e.length;n++){let r=e[n];t=K5(t,q5({...r.computedPosition,...r.dimensions}))}return J5(t)}function X5(e,t,n={x:0,y:0,zoom:1},r=!1,i=!1){let a={...G5(t,n),width:t.width/n.zoom,height:t.height/n.zoom},o=[];for(let t of e){let{dimensions:e,selectable:n=!0,hidden:s= Line truncated
`).map(e=>e.trim().toLowerCase());if(i.length===1)return e.toLowerCase()===t.toLowerCase();r||n.add(e.toLowerCase());let a=i.every((e,t)=>n.has(e)&&Array.from(n.values())[t]===i[t]);return r&&n.delete(e.toLowerCase()),a}function v5(e,t){return n=>{if(!n.code&&!n.key)return!1;let r=y5(n.code,e);return Array.isArray(e)?e.some(e=>_5(n[r],e,t,n.type===`keyup`)):_5(n[r],e,t,n.type===`keyup`)}}function y5(e,t){return t.includes(e)?`code`:`key`}function b5(e,t){let n=Y(()=>fn(t?.target)??m5),r=cn(fn(e)===!0),i=!1,a=new Set,o=c(fn(e));I(()=>fn(e),(e,t)=>{typeof t==`boolean`&&typeof e!=`boolean`&&s(),o=c(e)},{immediate:!0}),f0([`blur`,`contextmenu`],s),m0((...e)=>o(...e),e=>{let n=fn(t?.actInsideInputWithModifier)??!0,a=fn(t?.preventDefault)??!1;if(i=g5(e),(!i||i&&!n)&&h5(e))return;let o=e.composedPath?.call(e)?.[0]||e.target,s=o?.nodeName===`BUTTON`||o?.nodeName===`A`;!a&&(i||!s)&&e.preventDefault(),r.value=!0},{eventName:`keydown`,target:n}),m0((...e)=>o(...e),e=>{let n=fn(t?.actInsideInputWithModifier)??!0;if(r.value){if((!i||i&&!n)&&h5(e))return;i=!1,r.value=!1}},{eventName:`keyup`,target:n});function s(){i=!1,a.clear(),r.value=fn(e)===!0}function c(e){return e===null?(s(),()=>!1):typeof e==`boolean`?(s(),r.value=e,()=>!1):Array.isArray(e)||typeof e==`string`?v5(e,a):e}return r}var x5=`vue-flow__node-desc`,S5=`vue-flow__edge-desc`,C5=`vue-flow__aria-live`,w5=[`Enter`,` `,`Escape`],T5={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};function E5(e){return{...e.computedPosition||{x:0,y:0},width:e.dimensions.width||0,height:e.dimensions.height||0}}function D5(e,t){let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)}function O5(e){return{width:e.offsetWidth,height:e.offsetHeight}}function k5(e,t=0,n=1){return Math.min(Math.max(e,t),n)}function A5(e,t){return{x:k5(e.x,t[0][0],t[1][0]),y:k5(e.y,t[0][1],t[1][1])}}function j5(e){let t=e.getRootNode();return`elementFromPoint`in t?t:window.document}function M5(e){return e&&typeof e==`object`&&`id`in e&&`source`in e&&`target`in e}function N5(e){return e&&typeof e==`object`&&`id`in e&&`position`in e&&!M5(e)}function P5(e){return N5(e)&&`computedPosition`in e}function F5(e){return!Number.isNaN(e)&&Number.isFinite(e)}function I5(e){return F5(e.width)&&F5(e.height)&&F5(e.x)&&F5(e.y)}function L5(e,t,n){let r={id:e.id.toString(),type:e.type??`default`,dimensions:rn({width:0,height:0}),computedPosition:rn({z:0,...e.position}),handleBounds:{source:[],target:[]},draggable:void 0,selectable:void 0,connectable:void 0,focusable:void 0,selected:!1,dragging:!1,resizing:!1,initialized:!1,isParent:!1,position:{x:0,y:0},data:G7(e.data)?e.data:{},events:rn(G7(e.events)?e.events:{})};return Object.assign(t??r,e,{id:e.id.toString(),parentNode:n})}function R5(e,t,n){let r={id:e.id.toString(),type:e.type??t?.type??`default`,source:e.source.toString(),target:e.target.toString(),sourceHandle:e.sourceHandle?.toString(),targetHandle:e.targetHandle?.toString(),updatable:e.updatable??n?.updatable,selectable:e.selectable??n?.selectable,focusable:e.focusable??n?.focusable,data:G7(e.data)?e.data:{},events:rn(G7(e.events)?e.events:{}),label:e.label??``,interactionWidth:e.interactionWidth??n?.interactionWidth,...n??{}};return Object.assign(t??r,e,{id:e.id.toString()})}function z5(e,t,n,r){let i=typeof e==`string`?e:e.id,a=new Set,o=r===`source`?`target`:`source`;for(let e of n)e[o]===i&&a.add(e[r]);return t.filter(e=>a.has(e.id))}function B5(...e){if(e.length===3){let[t,n,r]=e;return z5(t,n,r,`target`)}let[t,n]=e,r=typeof t==`string`?t:t.id;return n.filter(e=>M5(e)&&e.source===r).map(e=>n.find(t=>N5(t)&&t.id===e.target))}function V5(...e){if(e.length===3){let[t,n,r]=e;return z5(t,n,r,`source`)}let[t,n]=e,r=typeof t==`string`?t:t.id;return n.filter(e=>M5(e)&&e.target===r).map(e=>n.find(t=>N5(t)&&t.id===e.source))}function H5({source:e,sourceHandle:t,target:n,targetHandle:r}){return`vueflow__edge-${e}${t??``}-${n}${r??``}`}function U5(e,t){return t.some(t=>M5(t)&&t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle))}function W5({x:e,y:t},{x:n,y:r,zoom:i}){return{x:e*i+n,y:t*i+r}}function G5({x:e,y:t},{x:n,y:r,zoom:i},a=!1,o=[1,1]){let s={x:(e-n)/i,y:(t-r)/i};return a?F7(s,o):s}function K5(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function q5({x:e,y:t,width:n,height:r}){return{x:e,y:t,x2:e+n,y2:t+r}}function J5({x:e,y:t,x2:n,y2:r}){return{x:e,y:t,width:n-e,height:r-t}}function Y5(e){let t={x:1/0,y:1/0,x2:-1/0,y2:-1/0};for(let n=0;n<e.length;n++){let r=e[n];t=K5(t,q5({...r.computedPosition,...r.dimensions}))}return J5(t)}function X5(e,t,n={x:0,y:0,zoom:1},r=!1,i=!1){let a={...G5(t,n),width:t.width/n.zoom,height:t.height/n.zoom},o=[];for(let t of e){let{dimensions:e,selectable:n=!0,hidden:s= Line truncated
Node: ${e}`,NODE_NOT_FOUND:e=>`Node not found
Node: ${e}`,NODE_MISSING_PARENT:(e,t)=>`Node is missing a parent
Node: ${e}
@@ -153,4 +153,4 @@ Edge: ${e}
Source: ${t}
Target: ${n}`,EDGE_ORPHANED:e=>`Edge was orphaned (suddenly missing source or target) and has been removed
Edge: ${e}`,EDGE_NOT_FOUND:e=>`Edge not found
Edge: ${e}`,USEVUEFLOW_OPTIONS:()=>`The options parameter is deprecated and will be removed in the next major version. Please use the id parameter instead`},j7=class extends Error{constructor(e,...t){super(A7[e]?.call(A7,...t)),this.name=`VueFlowError`,this.code=e,this.args=t}};function M7(e){return`clientX`in e}function Ote(e){return`sourceEvent`in e}function N7(e,t){let n=M7(e),r,i;return n?(r=e.clientX,i=e.clientY):`touches`in e&&e.touches.length>0?(r=e.touches[0].clientX,i=e.touches[0].clientY):`changedTouches`in e&&e.changedTouches.length>0?(r=e.changedTouches[0].clientX,i=e.changedTouches[0].clientY):(r=0,i=0),{x:r-(t?.left??0),y:i-(t?.top??0)}}var P7=()=>typeof navigator<`u`&&(navigator==null?void 0:navigator.userAgent)?.indexOf(`Mac`)>=0;function kte(e){return{width:e.dimensions?.width??e.width??0,height:e.dimensions?.height??e.height??0}}function F7(e,t=[1,1]){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}var Ate=()=>!0;function I7(e){e?.classList.remove(`valid`,`connecting`,`vue-flow__handle-valid`,`vue-flow__handle-connecting`)}function jte(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())D5(i,E5(e))>0&&r.push(e);return r}var Mte=250;function Nte(e,t,n,r){let i=[],a=1/0,o=jte(e,n,t+Mte);for(let n of o){let o=[...n.handleBounds?.source??[],...n.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=T7(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function L7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Ate},u,d,f,p){let m=a===`target`,h=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y:_}=N7(e),v=o.elementFromPoint(g,_),y=v?.classList.contains(`${s}-flow__handle`)?v:h,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){let e=R7(void 0,y),t=y.getAttribute(`data-nodeid`),a=y.getAttribute(`data-handleid`),o=y.classList.contains(`connectable`),s=y.classList.contains(`connectableend`);if(!t||!e)return b;let c={source:m?t:r,sourceHandle:m?a:i,target:m?r:t,targetHandle:m?i:a};b.connection=c,b.isValid=o&&s&&(n===l5.Strict?m&&e===`source`||!m&&e===`target`:t!==r||a!==i)&&l(c,{nodes:d,edges:u,sourceNode:f(c.source),targetNode:f(c.target)}),b.toHandle=z7(t,e,a,p,n,!0)}return b}function R7(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Pte(e,t){let n=null;return t?n=`valid`:e&&!t&&(n=`invalid`),n}function Fte(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}function z7(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===l5.Strict?o.handleBounds?.[t]:[...o.handleBounds?.source??[],...o.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...T7(o,c,c.position,!0)}:c}var B7={[o5.Left]:o5.Right,[o5.Right]:o5.Left,[o5.Top]:o5.Bottom,[o5.Bottom]:o5.Top},Ite=[`production`,`prod`];function V7(e,...t){H7()&&console.warn(`[Vue Flow]: ${e}`,...t)}function H7(){return!Ite.includes(`production`)}function U7(e,t,n,r,i){let a=t.querySelectorAll(`.vue-flow__handle.${e}`);return a?.length?Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...O5(t)}}):null}function W7(e,t,n,r,i,a=!1,o){i.value=!1,e.selected?(a||e.selected&&t)&&(r([e]),Kn(()=>{o.blur()})):n([e])}function G7(e){return P(e)!==void 0}function Lte(e,t,n,r){if(!e||!e.source||!e.target)return n(new j7(k7.EDGE_INVALID,e?.id??`[ID UNKNOWN]`)),!1;let i;return i=M5(e)?e:{...e,id:H5(e)},i=R5(i,void 0,r),!U5(i,t)&&i}function Rte(e,t,n,r,i){if(!t.source||!t.target)return i(new j7(k7.EDGE_INVALID,e.id)),!1;if(!n)return i(new j7(k7.EDGE_NOT_FOUND,e.id)),!1;let{id:a,...o}=e;return{...o,id:r?H5(t):a,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle}}function K7(e,t,n){let r={},i=[];for(let a=0;a<e.length;++a){let o=e[a];if(!N5(o)){n(new j7(k7.NODE_INVALID,o?.id));continue}let s=L5(o,t(o.id),o.parentNode);o.parentNode&&(r[o.parentNode]=!0),i[a]=s}for(let e of i){let a=t(e.parentNode)||i.find(t=>t.id===e.parentNode);e.parentNode&&!a&&n(new j7(k7.NODE_MISSING_PARENT,e.id,e.parentNode)),(e.parentNode||r[e.id])&&(r[e.id]&&(e.isParent=!0),a&&(a.isParent=!0))}return i}function q7(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function J7(e,t,n){e.clear();for(let t of n){let{source:n,target:r,sourceHandle:i=null,targetHandle:a=null}=t,o={edgeId:t.id,source:n,target:r,sourceHandle:i,targetHandle:a},s=`${n}-${i}--${r}-${a}`;q7(`source`Line truncated
Edge: ${e}`,USEVUEFLOW_OPTIONS:()=>`The options parameter is deprecated and will be removed in the next major version. Please use the id parameter instead`},j7=class extends Error{constructor(e,...t){super(A7[e]?.call(A7,...t)),this.name=`VueFlowError`,this.code=e,this.args=t}};function M7(e){return`clientX`in e}function Ate(e){return`sourceEvent`in e}function N7(e,t){let n=M7(e),r,i;return n?(r=e.clientX,i=e.clientY):`touches`in e&&e.touches.length>0?(r=e.touches[0].clientX,i=e.touches[0].clientY):`changedTouches`in e&&e.changedTouches.length>0?(r=e.changedTouches[0].clientX,i=e.changedTouches[0].clientY):(r=0,i=0),{x:r-(t?.left??0),y:i-(t?.top??0)}}var P7=()=>typeof navigator<`u`&&(navigator==null?void 0:navigator.userAgent)?.indexOf(`Mac`)>=0;function jte(e){return{width:e.dimensions?.width??e.width??0,height:e.dimensions?.height??e.height??0}}function F7(e,t=[1,1]){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}var Mte=()=>!0;function I7(e){e?.classList.remove(`valid`,`connecting`,`vue-flow__handle-valid`,`vue-flow__handle-connecting`)}function Nte(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())D5(i,E5(e))>0&&r.push(e);return r}var Pte=250;function Fte(e,t,n,r){let i=[],a=1/0,o=Nte(e,n,t+Pte);for(let n of o){let o=[...n.handleBounds?.source??[],...n.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=T7(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function L7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Mte},u,d,f,p){let m=a===`target`,h=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y:_}=N7(e),v=o.elementFromPoint(g,_),y=v?.classList.contains(`${s}-flow__handle`)?v:h,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){let e=R7(void 0,y),t=y.getAttribute(`data-nodeid`),a=y.getAttribute(`data-handleid`),o=y.classList.contains(`connectable`),s=y.classList.contains(`connectableend`);if(!t||!e)return b;let c={source:m?t:r,sourceHandle:m?a:i,target:m?r:t,targetHandle:m?i:a};b.connection=c,b.isValid=o&&s&&(n===l5.Strict?m&&e===`source`||!m&&e===`target`:t!==r||a!==i)&&l(c,{nodes:d,edges:u,sourceNode:f(c.source),targetNode:f(c.target)}),b.toHandle=z7(t,e,a,p,n,!0)}return b}function R7(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Ite(e,t){let n=null;return t?n=`valid`:e&&!t&&(n=`invalid`),n}function Lte(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}function z7(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===l5.Strict?o.handleBounds?.[t]:[...o.handleBounds?.source??[],...o.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...T7(o,c,c.position,!0)}:c}var B7={[o5.Left]:o5.Right,[o5.Right]:o5.Left,[o5.Top]:o5.Bottom,[o5.Bottom]:o5.Top},Rte=[`production`,`prod`];function V7(e,...t){H7()&&console.warn(`[Vue Flow]: ${e}`,...t)}function H7(){return!Rte.includes(`production`)}function U7(e,t,n,r,i){let a=t.querySelectorAll(`.vue-flow__handle.${e}`);return a?.length?Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...O5(t)}}):null}function W7(e,t,n,r,i,a=!1,o){i.value=!1,e.selected?(a||e.selected&&t)&&(r([e]),Kn(()=>{o.blur()})):n([e])}function G7(e){return P(e)!==void 0}function zte(e,t,n,r){if(!e||!e.source||!e.target)return n(new j7(k7.EDGE_INVALID,e?.id??`[ID UNKNOWN]`)),!1;let i;return i=M5(e)?e:{...e,id:H5(e)},i=R5(i,void 0,r),!U5(i,t)&&i}function Bte(e,t,n,r,i){if(!t.source||!t.target)return i(new j7(k7.EDGE_INVALID,e.id)),!1;if(!n)return i(new j7(k7.EDGE_NOT_FOUND,e.id)),!1;let{id:a,...o}=e;return{...o,id:r?H5(t):a,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle}}function K7(e,t,n){let r={},i=[];for(let a=0;a<e.length;++a){let o=e[a];if(!N5(o)){n(new j7(k7.NODE_INVALID,o?.id));continue}let s=L5(o,t(o.id),o.parentNode);o.parentNode&&(r[o.parentNode]=!0),i[a]=s}for(let e of i){let a=t(e.parentNode)||i.find(t=>t.id===e.parentNode);e.parentNode&&!a&&n(new j7(k7.NODE_MISSING_PARENT,e.id,e.parentNode)),(e.parentNode||r[e.id])&&(r[e.id]&&(e.isParent=!0),a&&(a.isParent=!0))}return i}function q7(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function J7(e,t,n){e.clear();for(let t of n){let{source:n,target:r,sourceHandle:i=null,targetHandle:a=null}=t,o={edgeId:t.id,source:n,target:r,sourceHandle:i,targetHandle:a},s=`${n}-${i}--${r}-${a}`;q7(`source`Line truncated
+26 -4
View File
@@ -23,14 +23,14 @@ import HistoryLink from "./HistoryLink.vue";
const KIND = "schedules";
/** A scheduled job; only the "workflow" kind is wired, so every job is one. */
/** A scheduled job: "workflow" starts a task, "chat" sends a message. */
interface Job {
id: string;
kind: string;
detail?: string;
pool?: string;
schedule: { kind?: string; interval?: string; cron?: string; at?: string };
target: Record<string, unknown>;
target: { channel?: string; chat_id?: string };
payload: { text?: string };
next_run?: string;
}
@@ -50,6 +50,10 @@ const whenKinds = [
{ value: "cron", label: "Cron" },
{ value: "once", label: "Once" },
];
const jobKinds = [
{ value: "workflow", label: "Run a task" },
{ value: "chat", label: "Send a message" },
];
const pools = [
{ value: "", label: "Sequential" },
{ value: "parallel", label: "Parallel" },
@@ -123,13 +127,31 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
</div>
<p v-if="jobIssue(i)" class="mt-1.5 text-xs text-danger">{{ jobIssue(i)?.message }}</p>
</SettingRow>
<SettingRow label="Task title" :for="`job-${i}-title`" hint="Empty: the ID.">
<SettingRow label="Does">
<div class="flex flex-wrap items-center gap-3">
<SegmentedControl
:model-value="job.kind"
label="Does"
:options="jobKinds"
@update:model-value="(k: string) => { job.kind = k; job.target = k === 'chat' ? { channel: 'telegram', chat_id: '' } : {}; }"
/>
<DraftHint :kind="KIND" :path="`${i}.kind`" />
</div>
</SettingRow>
<SettingRow v-if="job.kind === 'chat'" label="To" :for="`job-${i}-chat`">
<div class="flex flex-wrap items-center gap-3">
<Input v-model="job.target.channel" class="w-32 font-mono" aria-label="Channel" placeholder="telegram" />
<Input :id="`job-${i}-chat`" v-model="job.target.chat_id" class="w-48 font-mono" aria-label="Chat ID" placeholder="Chat ID" />
<DraftHint :kind="KIND" :path="`${i}.target.chat_id`" />
</div>
</SettingRow>
<SettingRow v-else label="Task title" :for="`job-${i}-title`" hint="Empty: the ID.">
<div class="flex flex-wrap items-center gap-3">
<Input :id="`job-${i}-title`" v-model="job.detail" class="max-w-md" />
<DraftHint :kind="KIND" :path="`${i}.detail`" />
</div>
</SettingRow>
<SettingRow label="Instructions" :for="`job-${i}-text`">
<SettingRow :label="job.kind === 'chat' ? 'Message' : 'Instructions'" :for="`job-${i}-text`">
<Textarea :id="`job-${i}-text`" v-model="job.payload.text" :rows="3" />
<DraftHint :kind="KIND" :path="`${i}.payload.text`" />
</SettingRow>