diff --git a/internal/app/agentworker/mcp_sampling.go b/internal/app/agentworker/mcp_sampling.go index d46ed5b8c..071987f2e 100644 --- a/internal/app/agentworker/mcp_sampling.go +++ b/internal/app/agentworker/mcp_sampling.go @@ -4,18 +4,24 @@ import ( "context" "errors" "fmt" + "log/slog" + "time" + "github.com/samcharles93/ai-sdk/chat" "github.com/samcharles93/ai-sdk/core" "github.com/samcharles93/ai-sdk/runtime" "github.com/samcharles93/archie-core/internal/agentexec/modelloop" "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/usage" + "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/tools/mcp" ) // taskSamplingHandler answers MCP sampling requests with the task's model. -// Without a runtime or model the request is refused. -func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig) mcp.SamplingHandler { +// Without a runtime or model the request is refused. record receives each +// call's model ref and token usage. +func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig, record func(context.Context, string, chat.Usage)) mcp.SamplingHandler { return func(ctx context.Context, req mcp.SamplingRequest) (mcp.SamplingResult, error) { if llm == nil { return mcp.SamplingResult{}, errors.New("mcp sampling: no model runtime is configured") @@ -39,6 +45,7 @@ func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig) mcp.Sampli options.Temperature = float32(*req.Temperature) } result, err := llm.Chat(ctx, model, options) + record(ctx, model, result.TotalUsage) if err != nil { return mcp.SamplingResult{}, fmt.Errorf("mcp sampling: %w", err) } @@ -50,3 +57,21 @@ func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig) mcp.Sampli }, nil } } + +// samplingUsageRecorder records a task's MCP sampling calls against the task. +// A failed write is logged, never fails the call. +func samplingUsageRecorder(store workflow.Store, t *workflow.Task, log *slog.Logger) func(context.Context, string, chat.Usage) { + return func(ctx context.Context, model string, used chat.Usage) { + if store == nil || t == nil { + return + } + record := usage.Record{ + Source: usage.SourceTask, TaskID: t.ID, Attempt: t.Attempt, Workflow: t.Workflow, Step: "mcp-sampling", + InputTokens: int64(used.PromptTokens), OutputTokens: int64(used.CompletionTokens), + CachedTokens: int64(used.CachedTokens), At: time.Now().UTC(), + }.WithRef(model) + if err := store.RecordUsage(ctx, record); err != nil && log != nil { + log.Warn("record model usage failed", "model", model, "err", err) + } + } +} diff --git a/internal/app/agentworker/task_execution.go b/internal/app/agentworker/task_execution.go index b2b782b49..304376d84 100644 --- a/internal/app/agentworker/task_execution.go +++ b/internal/app/agentworker/task_execution.go @@ -233,7 +233,7 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen if len(req.MCPServers) > 0 { llm = modelloop.NewRuntime(req.Providers, req.Cfg.ModelLimits) } - mcpSet, mcpErr := startMCPProviders(ctx, req.MCPServers, taskSamplingHandler(llm, req.Cfg), log) + mcpSet, mcpErr := startMCPProviders(ctx, req.MCPServers, taskSamplingHandler(llm, req.Cfg, samplingUsageRecorder(dependencies.store, req.Task, log)), log) if mcpSet != nil { defer mcpSet.cleanup(ctx, log) } diff --git a/internal/app/archiegateway/chat_setup.go b/internal/app/archiegateway/chat_setup.go index ba52ff7f2..909fd123f 100644 --- a/internal/app/archiegateway/chat_setup.go +++ b/internal/app/archiegateway/chat_setup.go @@ -15,6 +15,7 @@ import ( "github.com/samcharles93/archie-core/internal/agentexec/modelloop" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/messaging" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/gateway" "github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc" @@ -39,8 +40,10 @@ type chatSetup struct { // or model-aliases update swaps the runtime wholesale (ai-sdk's // Runtime caches the provider instances it built), so the pointer cannot // be captured at construction. nil means no model runtime is configured. - LLM func() *runtime.Runtime - ChatModels gateway.ModelManager + LLM func() *runtime.Runtime + ChatModels gateway.ModelManager + // Usage records each model call; nil records nothing. + Usage *usageSink ToolReg *tools.Registry Soul gateway.SoulSource ChatTasks gateway.TaskCreator @@ -129,7 +132,7 @@ func newChatTurnRunner( Sessions: sessionStore, Models: s.ChatModels, Soul: s.Soul, - Model: newChatTurnModel(s.LLM, s.ToolReg, cfg.Chat.MaxSteps, s.ToolLimits, s.ProviderOutcomes), + Model: newChatTurnModel(s.LLM, s.ToolReg, cfg.Chat.MaxSteps, s.ToolLimits, s.ProviderOutcomes, s.Usage), TaskLister: s.ChatTaskLister, Tasks: s.ChatTasks, TaskLogs: s.ChatTaskLogs, @@ -191,31 +194,38 @@ func chatRepoEnv(cfg config.Config, identity string) []gateway.RepoEnv { // and records at its own adapter (curatorLLMRunner). Anything that reaches the // runtime without recording leaves /status reporting a stale last-known // outcome, which is a /status that lies about the provider. -func sendChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream, outcomes *providerOutcomeRecorder, icons map[string]string) (string, error) { - text, err := runChatTurn(ctx, llm, chatModel, options, turn, icons) +func sendChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream, outcomes *providerOutcomeRecorder, usageRecords *usageSink, icons map[string]string) (string, error) { + text, used, err := runChatTurn(ctx, llm, chatModel, options, turn, icons) + usageRecords.record(ctx, usage.SourceChat, chatModel, used) // record tolerates a nil recorder: a setup built without one (tests, a // deployment whose health surface is unwired) still makes its calls. outcomes.record(chatModel, err) return text, err } -func runChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream, icons map[string]string) (string, error) { +// runChatTurn returns the reply and the tokens the call used, which a +// failed call may still report. +func runChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream, icons map[string]string) (string, chat.Usage, error) { if turn == nil { result, err := llm.Chat(ctx, chatModel, options) if err != nil { - return "", fmt.Errorf("llm chat: %w", err) + return "", result.TotalUsage, fmt.Errorf("llm chat: %w", err) } - return result.Text, nil + return result.Text, result.TotalUsage, nil } stream, err := llm.ChatStream(ctx, chatModel, options) if err != nil { - return "", fmt.Errorf("llm chat stream: %w", err) + return "", chat.Usage{}, fmt.Errorf("llm chat stream: %w", err) } text := drainChatStream(stream.FullStream, turn, icons) - if _, err := stream.FinishReason(); err != nil { - return "", fmt.Errorf("llm chat stream: %w", err) + var used chat.Usage + if stream.Usage != nil { + used, _ = stream.Usage() } - return text, nil + if _, err := stream.FinishReason(); err != nil { + return "", used, fmt.Errorf("llm chat stream: %w", err) + } + return text, used, nil } // drainChatStream consumes a model stream to close, reporting assistant text @@ -324,6 +334,7 @@ type chatTitleGenerator struct { log *slog.Logger llm func() *runtime.Runtime chatModels gateway.ModelManager + usage *usageSink } // newChatTitleGenerator wires an LLM-backed title generator for a chat @@ -333,7 +344,7 @@ func newChatTitleGenerator(s chatSetup) gateway.TitleGenerator { if s.LLM == nil || s.ChatModels == nil { return nil } - return &chatTitleGenerator{log: s.Log, llm: s.LLM, chatModels: s.ChatModels} + return &chatTitleGenerator{log: s.Log, llm: s.LLM, chatModels: s.ChatModels, usage: s.Usage} } func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, firstMessage string) (string, error) { @@ -357,7 +368,7 @@ func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, first return "", fmt.Errorf("no model runtime is configured") } text, err := sendChatTurn(ctx, llm, g.chatModels.ActiveModel(), - core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, nil, nil) + core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, nil, g.usage, nil) if err != nil { if g.log != nil { g.log.Error("session title generation failed", "session", sessionID, "err", err) diff --git a/internal/app/archiegateway/chat_turn_model.go b/internal/app/archiegateway/chat_turn_model.go index cc27526d7..3b424aec3 100644 --- a/internal/app/archiegateway/chat_turn_model.go +++ b/internal/app/archiegateway/chat_turn_model.go @@ -29,6 +29,7 @@ type chatTurnModel struct { limits func() modelloop.ToolLimits // outcomes records each call's result for /status (see sendChatTurn). outcomes *providerOutcomeRecorder + usage *usageSink } func newChatTurnModel( @@ -37,6 +38,7 @@ func newChatTurnModel( maxSteps int, limits func() modelloop.ToolLimits, outcomes *providerOutcomeRecorder, + usageRecords *usageSink, ) gateway.TurnModel { return &chatTurnModel{ llm: llm, @@ -44,6 +46,7 @@ func newChatTurnModel( maxSteps: maxSteps, limits: limits, outcomes: outcomes, + usage: usageRecords, } } @@ -70,6 +73,7 @@ func (m *chatTurnModel) Prepare( toolInfo: toolSummaries(options.Tools), toolTokens: gateway.EstimateTokens(string(toolSchema)), outcomes: m.outcomes, + usage: m.usage, icons: toolIcons(m.registry), }, nil } @@ -81,6 +85,7 @@ type preparedChatTurnModel struct { toolInfo []gateway.ToolSummary toolTokens int outcomes *providerOutcomeRecorder + usage *usageSink // icons maps tool name to the icon that tool registered, for chat // surfaces to render. A nil map yields "" for every lookup, which is // the no-icon rendering. @@ -202,5 +207,5 @@ func (m *preparedChatTurnModel) Generate( if m.llm == nil { return "", fmt.Errorf("llm chat: no model runtime is configured") } - return sendChatTurn(ctx, m.llm, m.model, options, stream, m.outcomes, m.icons) + return sendChatTurn(ctx, m.llm, m.model, options, stream, m.outcomes, m.usage, m.icons) } diff --git a/internal/app/archiegateway/curators.go b/internal/app/archiegateway/curators.go index 9c22ebe61..1f38b2e6b 100644 --- a/internal/app/archiegateway/curators.go +++ b/internal/app/archiegateway/curators.go @@ -14,6 +14,7 @@ import ( "github.com/samcharles93/archie-core/internal/app/controlplane" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/curator" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/events" infraMemory "github.com/samcharles93/archie-core/internal/infrastructure/memory" "github.com/samcharles93/archie-core/internal/infrastructure/sessioncurator" @@ -34,7 +35,7 @@ func (b *server) setupCurators(ctx context.Context) { MemoryEngines: b.memEngines, Skills: skillcurator.NewStore(skillsRoot), Conversations: sessioncurator.NewAdapter(b.chatSessionStore, b.cfg.BotUser), - LLM: curatorLLMRunner{llm: b.chatLLM, outcomes: b.providerOutcomes}, + LLM: curatorLLMRunner{llm: b.chatLLM, outcomes: b.providerOutcomes, usage: b.usage}, Model: b.chatModels.ActiveModel(), }) @@ -107,6 +108,7 @@ type curatorLLMRunner struct { // provider is demonstrably reachable -- or worse, keeps showing a much // older chat outcome as current. outcomes *providerOutcomeRecorder + usage *usageSink } func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (curator.ChatResult, error) { @@ -136,6 +138,7 @@ func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (cu MaxSteps: max(req.MaxSteps, 1), }) r.outcomes.record(req.Model, err) + r.usage.record(ctx, usage.SourceCurator, req.Model, res.TotalUsage) if err != nil { return curator.ChatResult{}, err } diff --git a/internal/app/archiegateway/gateway_runtime.go b/internal/app/archiegateway/gateway_runtime.go index 4acdc8d21..33f3d1d1a 100644 --- a/internal/app/archiegateway/gateway_runtime.go +++ b/internal/app/archiegateway/gateway_runtime.go @@ -74,6 +74,10 @@ func (b *server) setupChatRuntime(ctx context.Context, cfg config.Config, actor // later carries both: the recorder is written by sendChatTurn, the source // is read by /status. b.providerOutcomes = newProviderOutcomeRecorder() + b.usage = &usageSink{models: b.chatModels, log: b.log} + if b.stateStore != nil { + b.usage.store = b.stateStore + } b.statusHealth = newStatusHealth(b) b.setupChatTasks(cfg) @@ -253,6 +257,7 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct // The Gateway executes the web chat's turns, so it is the process // that must record their outcomes for /status. ProviderOutcomes: b.providerOutcomes, + Usage: b.usage, } router.LLM, router.LLMStream = makeChatLLMResponder(ctx, "web", setup, b.chatSessionStore, router) router.Titles = newChatTitleGenerator(setup) diff --git a/internal/app/archiegateway/mcp_sampling.go b/internal/app/archiegateway/mcp_sampling.go index aad4a708c..2761b8f8d 100644 --- a/internal/app/archiegateway/mcp_sampling.go +++ b/internal/app/archiegateway/mcp_sampling.go @@ -8,6 +8,7 @@ import ( "github.com/samcharles93/ai-sdk/core" "github.com/samcharles93/archie-core/internal/agentexec/modelloop" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/tools/mcp" ) @@ -48,6 +49,7 @@ func (b *server) mcpSamplingHandler() mcp.SamplingHandler { // recorded for /status like every other one; a nil recorder records // nothing. b.providerOutcomes.record(model, err) + b.usage.record(ctx, usage.SourceChat, model, result.TotalUsage) if err != nil { return mcp.SamplingResult{}, fmt.Errorf("mcp sampling: %w", err) } diff --git a/internal/app/archiegateway/server.go b/internal/app/archiegateway/server.go index 9928d0f9b..a24aeecd4 100644 --- a/internal/app/archiegateway/server.go +++ b/internal/app/archiegateway/server.go @@ -92,6 +92,7 @@ type server struct { curatorRegistry *curator.Registry curatorRuntime *curator.Runtime providerOutcomes *providerOutcomeRecorder + usage *usageSink statusHealth gateway.HealthSource updateService *releaseupdate.Service diff --git a/internal/app/archiegateway/usage.go b/internal/app/archiegateway/usage.go new file mode 100644 index 000000000..c5e11d0e4 --- /dev/null +++ b/internal/app/archiegateway/usage.go @@ -0,0 +1,45 @@ +package archiegateway + +import ( + "context" + "log/slog" + "time" + + "github.com/samcharles93/ai-sdk/chat" + + "github.com/samcharles93/archie-core/internal/domain/storecontract" + "github.com/samcharles93/archie-core/internal/domain/usage" + "github.com/samcharles93/archie-core/internal/gateway" +) + +const usageWriteTimeout = 5 * time.Second + +// usageSink records the gateway's model calls. Chat has no org of its own +// yet, so its records belong to the system org. A nil sink records nothing. +type usageSink struct { + store usage.Recorder + models gateway.ModelManager + log *slog.Logger +} + +// record appends one call's usage. It never fails the call: the write is +// detached from the caller's cancellation and a failure is only logged. +func (u *usageSink) record(ctx context.Context, source usage.Source, ref string, used chat.Usage) { + if u == nil || u.store == nil || ref == "" { + return + } + alias := "" + if u.models != nil && u.models.ActiveModel() == ref { + alias = u.models.ActiveAlias() + } + record := usage.Record{ + Org: storecontract.DefaultOrgID, Source: source, Alias: alias, + InputTokens: int64(used.PromptTokens), OutputTokens: int64(used.CompletionTokens), + CachedTokens: int64(used.CachedTokens), At: time.Now().UTC(), + }.WithRef(ref) + ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), usageWriteTimeout) + defer cancel() + if err := u.store.RecordUsage(ctx, record); err != nil && u.log != nil { + u.log.Warn("record model usage failed", "source", source, "model", ref, "err", err) + } +} diff --git a/internal/app/statestore/server.go b/internal/app/statestore/server.go index 1d8f69e9c..18a83c489 100644 --- a/internal/app/statestore/server.go +++ b/internal/app/statestore/server.go @@ -26,6 +26,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/presence" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/storepkg" + "github.com/samcharles93/archie-core/internal/domain/usage" infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access" "github.com/samcharles93/archie-core/internal/infrastructure/postgres" "github.com/samcharles93/archie-core/internal/infrastructure/readiness" @@ -375,6 +376,9 @@ func (b *server) executionDeps(deps *staterpc.Deps) { if ec, ok := b.st.(storecontract.ExecutionCanceller); ok { deps.Canceller = ec } + if ur, ok := b.st.(usage.Recorder); ok { + deps.Usage = ur + } if sr, ok := b.st.(storecontract.StepReader); ok { deps.StepReader = sr } diff --git a/internal/contracts/state/v1/state.pb.go b/internal/contracts/state/v1/state.pb.go index ef9a3a8a0..22ad05ac9 100644 --- a/internal/contracts/state/v1/state.pb.go +++ b/internal/contracts/state/v1/state.pb.go @@ -15368,6 +15368,229 @@ func (x *RecentLogsResponse) GetSnapshot() *v1.LogSnapshot { return nil } +// UsageRecord mirrors usage.Record. A task's record belongs to the task's +// org, whatever org_id says. +type UsageRecord struct { + state protoimpl.MessageState `protogen:"open.v1"` + OrgId string `protobuf:"bytes,1,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + // source is task, chat or curator. + Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` + TaskId int64 `protobuf:"varint,3,opt,name=task_id,json=taskId,proto3" json:"task_id,omitempty"` + Attempt int64 `protobuf:"varint,4,opt,name=attempt,proto3" json:"attempt,omitempty"` + Workflow string `protobuf:"bytes,5,opt,name=workflow,proto3" json:"workflow,omitempty"` + Step string `protobuf:"bytes,6,opt,name=step,proto3" json:"step,omitempty"` + Alias string `protobuf:"bytes,7,opt,name=alias,proto3" json:"alias,omitempty"` + Provider string `protobuf:"bytes,8,opt,name=provider,proto3" json:"provider,omitempty"` + Model string `protobuf:"bytes,9,opt,name=model,proto3" json:"model,omitempty"` + InputTokens int64 `protobuf:"varint,10,opt,name=input_tokens,json=inputTokens,proto3" json:"input_tokens,omitempty"` + OutputTokens int64 `protobuf:"varint,11,opt,name=output_tokens,json=outputTokens,proto3" json:"output_tokens,omitempty"` + CachedTokens int64 `protobuf:"varint,12,opt,name=cached_tokens,json=cachedTokens,proto3" json:"cached_tokens,omitempty"` + At *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=at,proto3" json:"at,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UsageRecord) Reset() { + *x = UsageRecord{} + mi := &file_state_v1_state_proto_msgTypes[285] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UsageRecord) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UsageRecord) ProtoMessage() {} + +func (x *UsageRecord) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[285] + 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 UsageRecord.ProtoReflect.Descriptor instead. +func (*UsageRecord) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{285} +} + +func (x *UsageRecord) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *UsageRecord) GetSource() string { + if x != nil { + return x.Source + } + return "" +} + +func (x *UsageRecord) GetTaskId() int64 { + if x != nil { + return x.TaskId + } + return 0 +} + +func (x *UsageRecord) GetAttempt() int64 { + if x != nil { + return x.Attempt + } + return 0 +} + +func (x *UsageRecord) GetWorkflow() string { + if x != nil { + return x.Workflow + } + return "" +} + +func (x *UsageRecord) GetStep() string { + if x != nil { + return x.Step + } + return "" +} + +func (x *UsageRecord) GetAlias() string { + if x != nil { + return x.Alias + } + return "" +} + +func (x *UsageRecord) GetProvider() string { + if x != nil { + return x.Provider + } + return "" +} + +func (x *UsageRecord) GetModel() string { + if x != nil { + return x.Model + } + return "" +} + +func (x *UsageRecord) GetInputTokens() int64 { + if x != nil { + return x.InputTokens + } + return 0 +} + +func (x *UsageRecord) GetOutputTokens() int64 { + if x != nil { + return x.OutputTokens + } + return 0 +} + +func (x *UsageRecord) GetCachedTokens() int64 { + if x != nil { + return x.CachedTokens + } + return 0 +} + +func (x *UsageRecord) GetAt() *timestamppb.Timestamp { + if x != nil { + return x.At + } + return nil +} + +type RecordUsageRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Record *UsageRecord `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordUsageRequest) Reset() { + *x = RecordUsageRequest{} + mi := &file_state_v1_state_proto_msgTypes[286] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordUsageRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordUsageRequest) ProtoMessage() {} + +func (x *RecordUsageRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[286] + 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 RecordUsageRequest.ProtoReflect.Descriptor instead. +func (*RecordUsageRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{286} +} + +func (x *RecordUsageRequest) GetRecord() *UsageRecord { + if x != nil { + return x.Record + } + return nil +} + +type RecordUsageResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordUsageResponse) Reset() { + *x = RecordUsageResponse{} + mi := &file_state_v1_state_proto_msgTypes[287] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordUsageResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordUsageResponse) ProtoMessage() {} + +func (x *RecordUsageResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[287] + 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 RecordUsageResponse.ProtoReflect.Descriptor instead. +func (*RecordUsageResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{287} +} + var File_state_v1_state_proto protoreflect.FileDescriptor const file_state_v1_state_proto_rawDesc = "" + @@ -16369,7 +16592,25 @@ const file_state_v1_state_proto_rawDesc = "" + "\x11RecentLogsRequest\x12*\n" + "\x05query\x18\x01 \x01(\v2\x14.logging.v1.LogQueryR\x05query\"I\n" + "\x12RecentLogsResponse\x123\n" + - "\bsnapshot\x18\x01 \x01(\v2\x17.logging.v1.LogSnapshotR\bsnapshot2\xdaR\n" + + "\bsnapshot\x18\x01 \x01(\v2\x17.logging.v1.LogSnapshotR\bsnapshot\"\x80\x03\n" + + "\vUsageRecord\x12\x15\n" + + "\x06org_id\x18\x01 \x01(\tR\x05orgId\x12\x16\n" + + "\x06source\x18\x02 \x01(\tR\x06source\x12\x17\n" + + "\atask_id\x18\x03 \x01(\x03R\x06taskId\x12\x18\n" + + "\aattempt\x18\x04 \x01(\x03R\aattempt\x12\x1a\n" + + "\bworkflow\x18\x05 \x01(\tR\bworkflow\x12\x12\n" + + "\x04step\x18\x06 \x01(\tR\x04step\x12\x14\n" + + "\x05alias\x18\a \x01(\tR\x05alias\x12\x1a\n" + + "\bprovider\x18\b \x01(\tR\bprovider\x12\x14\n" + + "\x05model\x18\t \x01(\tR\x05model\x12!\n" + + "\finput_tokens\x18\n" + + " \x01(\x03R\vinputTokens\x12#\n" + + "\routput_tokens\x18\v \x01(\x03R\foutputTokens\x12#\n" + + "\rcached_tokens\x18\f \x01(\x03R\fcachedTokens\x12*\n" + + "\x02at\x18\r \x01(\v2\x1a.google.protobuf.TimestampR\x02at\"C\n" + + "\x12RecordUsageRequest\x12-\n" + + "\x06record\x18\x01 \x01(\v2\x15.state.v1.UsageRecordR\x06record\"\x15\n" + + "\x13RecordUsageResponse2\xa6S\n" + "\x11StateStoreService\x12G\n" + "\n" + "RecentLogs\x12\x1b.state.v1.RecentLogsRequest\x1a\x1c.state.v1.RecentLogsResponse\x12S\n" + @@ -16403,7 +16644,8 @@ const file_state_v1_state_proto_rawDesc = "" + "\n" + "Transition\x12\x1b.state.v1.TransitionRequest\x1a\x1c.state.v1.TransitionResponse\x12;\n" + "\x06Update\x12\x17.state.v1.UpdateRequest\x1a\x18.state.v1.UpdateResponse\x12D\n" + - "\tStartStep\x12\x1a.state.v1.StartStepRequest\x1a\x1b.state.v1.StartStepResponse\x12G\n" + + "\tStartStep\x12\x1a.state.v1.StartStepRequest\x1a\x1b.state.v1.StartStepResponse\x12J\n" + + "\vRecordUsage\x12\x1c.state.v1.RecordUsageRequest\x1a\x1d.state.v1.RecordUsageResponse\x12G\n" + "\n" + "FinishStep\x12\x1b.state.v1.FinishStepRequest\x1a\x1c.state.v1.FinishStepResponse\x12V\n" + "\x0fCancelExecution\x12 .state.v1.CancelExecutionRequest\x1a!.state.v1.CancelExecutionResponse\x12D\n" + @@ -16517,7 +16759,7 @@ func file_state_v1_state_proto_rawDescGZIP() []byte { return file_state_v1_state_proto_rawDescData } -var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 287) +var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 290) var file_state_v1_state_proto_goTypes = []any{ (*RegisterTaskGrantRequest)(nil), // 0: state.v1.RegisterTaskGrantRequest (*RegisterTaskGrantResponse)(nil), // 1: state.v1.RegisterTaskGrantResponse @@ -16804,15 +17046,18 @@ var file_state_v1_state_proto_goTypes = []any{ (*AssignAgentResponse)(nil), // 282: state.v1.AssignAgentResponse (*RecentLogsRequest)(nil), // 283: state.v1.RecentLogsRequest (*RecentLogsResponse)(nil), // 284: state.v1.RecentLogsResponse - nil, // 285: state.v1.EventType.SchemaEntry - nil, // 286: state.v1.StatusCountsResponse.CountsEntry - (*timestamppb.Timestamp)(nil), // 287: google.protobuf.Timestamp - (*v1.LogQuery)(nil), // 288: logging.v1.LogQuery - (*v1.LogSnapshot)(nil), // 289: logging.v1.LogSnapshot + (*UsageRecord)(nil), // 285: state.v1.UsageRecord + (*RecordUsageRequest)(nil), // 286: state.v1.RecordUsageRequest + (*RecordUsageResponse)(nil), // 287: state.v1.RecordUsageResponse + nil, // 288: state.v1.EventType.SchemaEntry + nil, // 289: state.v1.StatusCountsResponse.CountsEntry + (*timestamppb.Timestamp)(nil), // 290: google.protobuf.Timestamp + (*v1.LogQuery)(nil), // 291: logging.v1.LogQuery + (*v1.LogSnapshot)(nil), // 292: logging.v1.LogSnapshot } var file_state_v1_state_proto_depIdxs = []int32{ - 287, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp - 287, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp + 290, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp + 290, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp 6, // 2: state.v1.ListIdentitiesResponse.identities:type_name -> state.v1.Identity 6, // 3: state.v1.GetIdentityResponse.identity:type_name -> state.v1.Identity 7, // 4: state.v1.CreateIdentityRequest.audit:type_name -> state.v1.IdentityAudit @@ -16828,37 +17073,37 @@ var file_state_v1_state_proto_depIdxs = []int32{ 6, // 14: state.v1.ResolveIdentitySubjectResponse.identity:type_name -> state.v1.Identity 7, // 15: state.v1.BindIdentitySubjectRequest.audit:type_name -> state.v1.IdentityAudit 6, // 16: state.v1.BindIdentitySubjectResponse.identity:type_name -> state.v1.Identity - 287, // 17: state.v1.PersonalToken.created_at:type_name -> google.protobuf.Timestamp + 290, // 17: state.v1.PersonalToken.created_at:type_name -> google.protobuf.Timestamp 26, // 18: state.v1.ListPersonalTokensResponse.tokens:type_name -> state.v1.PersonalToken - 287, // 19: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp - 287, // 20: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp - 287, // 21: state.v1.Event.at:type_name -> google.protobuf.Timestamp - 287, // 22: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp + 290, // 19: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp + 290, // 20: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp + 290, // 21: state.v1.Event.at:type_name -> google.protobuf.Timestamp + 290, // 22: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp 36, // 23: state.v1.EventType.header_conditions:type_name -> state.v1.EventTypeHeaderCondition 37, // 24: state.v1.EventType.payload_conditions:type_name -> state.v1.EventTypePayloadCondition - 285, // 25: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry - 287, // 26: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp - 287, // 27: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp + 288, // 25: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry + 290, // 26: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp + 290, // 27: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp 39, // 28: state.v1.Mapping.fields:type_name -> state.v1.MappingField - 287, // 29: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp - 287, // 30: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp - 287, // 31: state.v1.Mapping.last_matched_at:type_name -> google.protobuf.Timestamp + 290, // 29: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp + 290, // 30: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp + 290, // 31: state.v1.Mapping.last_matched_at:type_name -> google.protobuf.Timestamp 41, // 32: state.v1.Binding.matcher:type_name -> state.v1.BindingMatcher - 287, // 33: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp - 287, // 34: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp - 287, // 35: state.v1.Source.created_at:type_name -> google.protobuf.Timestamp - 287, // 36: state.v1.Source.updated_at:type_name -> google.protobuf.Timestamp + 290, // 33: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp + 290, // 34: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp + 290, // 35: state.v1.Source.created_at:type_name -> google.protobuf.Timestamp + 290, // 36: state.v1.Source.updated_at:type_name -> google.protobuf.Timestamp 33, // 37: state.v1.ActiveTasksByOriginResponse.tasks:type_name -> state.v1.Task 33, // 38: state.v1.EnqueueChatTaskResponse.task:type_name -> state.v1.Task 33, // 39: state.v1.ClaimNextResponse.task:type_name -> state.v1.Task 33, // 40: state.v1.ClaimByIssueResponse.task:type_name -> state.v1.Task 34, // 41: state.v1.StartStepResponse.event:type_name -> state.v1.Event 34, // 42: state.v1.FinishStepResponse.event:type_name -> state.v1.Event - 287, // 43: state.v1.StepExecution.started_at:type_name -> google.protobuf.Timestamp - 287, // 44: state.v1.StepExecution.finished_at:type_name -> google.protobuf.Timestamp + 290, // 43: state.v1.StepExecution.started_at:type_name -> google.protobuf.Timestamp + 290, // 44: state.v1.StepExecution.finished_at:type_name -> google.protobuf.Timestamp 65, // 45: state.v1.ListStepsResponse.steps:type_name -> state.v1.StepExecution - 287, // 46: state.v1.HarnessSecret.expires_at:type_name -> google.protobuf.Timestamp - 287, // 47: state.v1.HarnessSecret.updated_at:type_name -> google.protobuf.Timestamp + 290, // 46: state.v1.HarnessSecret.expires_at:type_name -> google.protobuf.Timestamp + 290, // 47: state.v1.HarnessSecret.updated_at:type_name -> google.protobuf.Timestamp 68, // 48: state.v1.GetHarnessSecretResponse.secret:type_name -> state.v1.HarnessSecret 68, // 49: state.v1.PutHarnessSecretRequest.secret:type_name -> state.v1.HarnessSecret 33, // 50: state.v1.UpdateRequest.task:type_name -> state.v1.Task @@ -16867,35 +17112,35 @@ var file_state_v1_state_proto_depIdxs = []int32{ 33, // 53: state.v1.OpenTaskByPRResponse.task:type_name -> state.v1.Task 33, // 54: state.v1.TaskByIDResponse.task:type_name -> state.v1.Task 33, // 55: state.v1.OpenPRsResponse.tasks:type_name -> state.v1.Task - 287, // 56: state.v1.TasksRequest.after_updated_at:type_name -> google.protobuf.Timestamp + 290, // 56: state.v1.TasksRequest.after_updated_at:type_name -> google.protobuf.Timestamp 33, // 57: state.v1.TasksResponse.tasks:type_name -> state.v1.Task - 286, // 58: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry + 289, // 58: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry 34, // 59: state.v1.InsertEventRequest.event:type_name -> state.v1.Event 34, // 60: state.v1.EventsSinceResponse.events:type_name -> state.v1.Event 34, // 61: state.v1.TaskEventsResponse.events:type_name -> state.v1.Event 44, // 62: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat 45, // 63: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat 46, // 64: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens - 287, // 65: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp + 290, // 65: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp 119, // 66: state.v1.PutConfigSnapshotRequest.snapshot:type_name -> state.v1.ConfigSnapshot 119, // 67: state.v1.GetConfigSnapshotResponse.snapshot:type_name -> state.v1.ConfigSnapshot - 287, // 68: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp + 290, // 68: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp 124, // 69: state.v1.PutChannelStatusRequest.channels:type_name -> state.v1.ChannelStatus 124, // 70: state.v1.ListChannelStatusResponse.channels:type_name -> state.v1.ChannelStatus - 287, // 71: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp + 290, // 71: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp 129, // 72: state.v1.PutApplyStatusRequest.status:type_name -> state.v1.ApplyStatus 129, // 73: state.v1.ListApplyStatusResponse.statuses:type_name -> state.v1.ApplyStatus - 287, // 74: state.v1.Presence.started_at:type_name -> google.protobuf.Timestamp - 287, // 75: state.v1.Presence.reported_at:type_name -> google.protobuf.Timestamp + 290, // 74: state.v1.Presence.started_at:type_name -> google.protobuf.Timestamp + 290, // 75: state.v1.Presence.reported_at:type_name -> google.protobuf.Timestamp 134, // 76: state.v1.Presence.checks:type_name -> state.v1.DependencyCheck - 287, // 77: state.v1.RecordCaptureRefusalRequest.refused_at:type_name -> google.protobuf.Timestamp - 287, // 78: state.v1.ListCaptureRefusalsRequest.since:type_name -> google.protobuf.Timestamp + 290, // 77: state.v1.RecordCaptureRefusalRequest.refused_at:type_name -> google.protobuf.Timestamp + 290, // 78: state.v1.ListCaptureRefusalsRequest.since:type_name -> google.protobuf.Timestamp 139, // 79: state.v1.ListCaptureRefusalsResponse.sources:type_name -> state.v1.CaptureRefusals 135, // 80: state.v1.PutPresenceRequest.presence:type_name -> state.v1.Presence 135, // 81: state.v1.ListPresenceResponse.presences:type_name -> state.v1.Presence - 287, // 82: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp - 287, // 83: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp - 287, // 84: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp + 290, // 82: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp + 290, // 83: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp + 290, // 84: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp 145, // 85: state.v1.ReadTaskLogResponse.entries:type_name -> state.v1.TaskLogEntry 35, // 86: state.v1.InsertCaptureRequest.capture:type_name -> state.v1.CapturedEvent 35, // 87: state.v1.StreamCapturesResponse.capture:type_name -> state.v1.CapturedEvent @@ -16914,7 +17159,7 @@ var file_state_v1_state_proto_depIdxs = []int32{ 43, // 100: state.v1.GetSourceResponse.source:type_name -> state.v1.Source 43, // 101: state.v1.ListSourcesResponse.sources:type_name -> state.v1.Source 42, // 102: state.v1.ArmedBindingsForSourceResponse.bindings:type_name -> state.v1.Binding - 287, // 103: state.v1.Dispatch.dispatched_at:type_name -> google.protobuf.Timestamp + 290, // 103: state.v1.Dispatch.dispatched_at:type_name -> google.protobuf.Timestamp 213, // 104: state.v1.ListDispatchesResponse.dispatches:type_name -> state.v1.Dispatch 35, // 105: state.v1.StreamUndispatchedCapturesResponse.capture:type_name -> state.v1.CapturedEvent 33, // 106: state.v1.EnqueueBindingTaskResponse.task:type_name -> state.v1.Task @@ -16932,7 +17177,7 @@ var file_state_v1_state_proto_depIdxs = []int32{ 248, // 118: state.v1.ListPoliciesResponse.policies:type_name -> state.v1.AccessPolicy 248, // 119: state.v1.PutPolicyRequest.policy:type_name -> state.v1.AccessPolicy 248, // 120: state.v1.DeletePolicyRequest.policy:type_name -> state.v1.AccessPolicy - 287, // 121: state.v1.AccessDenial.at:type_name -> google.protobuf.Timestamp + 290, // 121: state.v1.AccessDenial.at:type_name -> google.protobuf.Timestamp 257, // 122: state.v1.RecordDenialRequest.denial:type_name -> state.v1.AccessDenial 257, // 123: state.v1.ListDenialsResponse.denials:type_name -> state.v1.AccessDenial 262, // 124: state.v1.ListOrgsResponse.orgs:type_name -> state.v1.Org @@ -16941,261 +17186,265 @@ var file_state_v1_state_proto_depIdxs = []int32{ 263, // 127: state.v1.ListWorkspacesResponse.workspaces:type_name -> state.v1.Workspace 263, // 128: state.v1.CreateWorkspaceResponse.workspace:type_name -> state.v1.Workspace 264, // 129: state.v1.ListMembersResponse.members:type_name -> state.v1.Member - 288, // 130: state.v1.RecentLogsRequest.query:type_name -> logging.v1.LogQuery - 289, // 131: state.v1.RecentLogsResponse.snapshot:type_name -> logging.v1.LogSnapshot - 283, // 132: state.v1.StateStoreService.RecentLogs:input_type -> state.v1.RecentLogsRequest - 229, // 133: state.v1.StateStoreService.InstallPackage:input_type -> state.v1.InstallPackageRequest - 232, // 134: state.v1.StateStoreService.ListCatalogue:input_type -> state.v1.ListCatalogueRequest - 234, // 135: state.v1.StateStoreService.InstallFromCatalogue:input_type -> state.v1.InstallFromCatalogueRequest - 236, // 136: state.v1.StateStoreService.GetInstalledPackage:input_type -> state.v1.GetInstalledPackageRequest - 238, // 137: state.v1.StateStoreService.ListInstalledPackages:input_type -> state.v1.ListInstalledPackagesRequest - 240, // 138: state.v1.StateStoreService.AcceptPackageAuthority:input_type -> state.v1.AcceptPackageAuthorityRequest - 242, // 139: state.v1.StateStoreService.RemoveInstalledPackage:input_type -> state.v1.RemoveInstalledPackageRequest - 0, // 140: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest - 2, // 141: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest - 4, // 142: state.v1.StateStoreService.ResolveTaskGrant:input_type -> state.v1.ResolveTaskGrantRequest - 8, // 143: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest - 10, // 144: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest - 12, // 145: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest - 13, // 146: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest - 14, // 147: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest - 15, // 148: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest - 16, // 149: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest - 22, // 150: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest - 24, // 151: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest - 27, // 152: state.v1.StateStoreService.AddPersonalToken:input_type -> state.v1.AddPersonalTokenRequest - 29, // 153: state.v1.StateStoreService.ListPersonalTokens:input_type -> state.v1.ListPersonalTokensRequest - 31, // 154: state.v1.StateStoreService.RevokePersonalToken:input_type -> state.v1.RevokePersonalTokenRequest - 47, // 155: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest - 51, // 156: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest - 49, // 157: state.v1.StateStoreService.ActiveTasksByOrigin:input_type -> state.v1.ActiveTasksByOriginRequest - 53, // 158: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest - 55, // 159: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest - 57, // 160: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest - 73, // 161: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest - 59, // 162: state.v1.StateStoreService.StartStep:input_type -> state.v1.StartStepRequest - 61, // 163: state.v1.StateStoreService.FinishStep:input_type -> state.v1.FinishStepRequest - 63, // 164: state.v1.StateStoreService.CancelExecution:input_type -> state.v1.CancelExecutionRequest - 66, // 165: state.v1.StateStoreService.ListSteps:input_type -> state.v1.ListStepsRequest - 69, // 166: state.v1.StateStoreService.GetHarnessSecret:input_type -> state.v1.GetHarnessSecretRequest - 71, // 167: state.v1.StateStoreService.PutHarnessSecret:input_type -> state.v1.PutHarnessSecretRequest - 75, // 168: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest - 77, // 169: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest - 79, // 170: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest - 81, // 171: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest - 83, // 172: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest - 85, // 173: state.v1.StateStoreService.RespondReviewGate:input_type -> state.v1.RespondReviewGateRequest - 87, // 174: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest - 89, // 175: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest - 91, // 176: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest - 93, // 177: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest - 95, // 178: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest - 97, // 179: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest - 99, // 180: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest - 101, // 181: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest - 103, // 182: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest - 105, // 183: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest - 107, // 184: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest - 109, // 185: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest - 111, // 186: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest - 113, // 187: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest - 115, // 188: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest - 117, // 189: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest - 120, // 190: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest - 122, // 191: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest - 125, // 192: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest - 127, // 193: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest - 130, // 194: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest - 132, // 195: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest - 141, // 196: state.v1.StateStoreService.PutPresence:input_type -> state.v1.PutPresenceRequest - 136, // 197: state.v1.StateStoreService.RecordCaptureRefusal:input_type -> state.v1.RecordCaptureRefusalRequest - 138, // 198: state.v1.StateStoreService.ListCaptureRefusals:input_type -> state.v1.ListCaptureRefusalsRequest - 143, // 199: state.v1.StateStoreService.ListPresence:input_type -> state.v1.ListPresenceRequest - 146, // 200: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest - 148, // 201: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest - 150, // 202: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest - 152, // 203: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest - 154, // 204: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest - 156, // 205: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest - 158, // 206: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest - 160, // 207: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest - 162, // 208: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest - 164, // 209: state.v1.StateStoreService.RecordMappingMatch:input_type -> state.v1.RecordMappingMatchRequest - 166, // 210: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest - 168, // 211: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest - 170, // 212: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest - 172, // 213: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest - 174, // 214: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest - 176, // 215: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest - 178, // 216: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest - 212, // 217: state.v1.StateStoreService.ListDispatches:input_type -> state.v1.ListDispatchesRequest - 180, // 218: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest - 182, // 219: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest - 184, // 220: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest - 192, // 221: state.v1.StateStoreService.PauseBinding:input_type -> state.v1.PauseBindingRequest - 194, // 222: state.v1.StateStoreService.ResumeBinding:input_type -> state.v1.ResumeBindingRequest - 196, // 223: state.v1.StateStoreService.InsertSource:input_type -> state.v1.InsertSourceRequest - 198, // 224: state.v1.StateStoreService.GetSource:input_type -> state.v1.GetSourceRequest - 200, // 225: state.v1.StateStoreService.ListSources:input_type -> state.v1.ListSourcesRequest - 202, // 226: state.v1.StateStoreService.SetSourceSigning:input_type -> state.v1.SetSourceSigningRequest - 204, // 227: state.v1.StateStoreService.SetSourceSecret:input_type -> state.v1.SetSourceSecretRequest - 186, // 228: state.v1.StateStoreService.SetSourceName:input_type -> state.v1.SetSourceNameRequest - 188, // 229: state.v1.StateStoreService.SetSourceDeliveryHeader:input_type -> state.v1.SetSourceDeliveryHeaderRequest - 190, // 230: state.v1.StateStoreService.DeleteSource:input_type -> state.v1.DeleteSourceRequest - 206, // 231: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest - 208, // 232: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest - 210, // 233: state.v1.StateStoreService.SetDispatchTask:input_type -> state.v1.SetDispatchTaskRequest - 215, // 234: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest - 217, // 235: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest - 219, // 236: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest - 221, // 237: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest - 223, // 238: state.v1.StateStoreService.EnqueueCallTask:input_type -> state.v1.EnqueueCallTaskRequest - 225, // 239: state.v1.StateStoreService.WorkflowCallStatus:input_type -> state.v1.WorkflowCallStatusRequest - 244, // 240: state.v1.StateStoreService.GetPrincipal:input_type -> state.v1.GetPrincipalRequest - 249, // 241: state.v1.StateStoreService.ListPolicies:input_type -> state.v1.ListPoliciesRequest - 251, // 242: state.v1.StateStoreService.PutPolicy:input_type -> state.v1.PutPolicyRequest - 253, // 243: state.v1.StateStoreService.DeletePolicy:input_type -> state.v1.DeletePolicyRequest - 255, // 244: state.v1.StateStoreService.EnsureShippedOrgPolicies:input_type -> state.v1.EnsureShippedOrgPoliciesRequest - 258, // 245: state.v1.StateStoreService.RecordDenial:input_type -> state.v1.RecordDenialRequest - 260, // 246: state.v1.StateStoreService.ListDenials:input_type -> state.v1.ListDenialsRequest - 265, // 247: state.v1.StateStoreService.ListOrgs:input_type -> state.v1.ListOrgsRequest - 267, // 248: state.v1.StateStoreService.GetOrg:input_type -> state.v1.GetOrgRequest - 269, // 249: state.v1.StateStoreService.CreateOrg:input_type -> state.v1.CreateOrgRequest - 271, // 250: state.v1.StateStoreService.ListWorkspaces:input_type -> state.v1.ListWorkspacesRequest - 273, // 251: state.v1.StateStoreService.CreateWorkspace:input_type -> state.v1.CreateWorkspaceRequest - 275, // 252: state.v1.StateStoreService.ListMembers:input_type -> state.v1.ListMembersRequest - 277, // 253: state.v1.StateStoreService.SetMembership:input_type -> state.v1.SetMembershipRequest - 279, // 254: state.v1.StateStoreService.RemoveMembership:input_type -> state.v1.RemoveMembershipRequest - 281, // 255: state.v1.StateStoreService.AssignAgent:input_type -> state.v1.AssignAgentRequest - 284, // 256: state.v1.StateStoreService.RecentLogs:output_type -> state.v1.RecentLogsResponse - 230, // 257: state.v1.StateStoreService.InstallPackage:output_type -> state.v1.InstallPackageResponse - 233, // 258: state.v1.StateStoreService.ListCatalogue:output_type -> state.v1.ListCatalogueResponse - 235, // 259: state.v1.StateStoreService.InstallFromCatalogue:output_type -> state.v1.InstallFromCatalogueResponse - 237, // 260: state.v1.StateStoreService.GetInstalledPackage:output_type -> state.v1.GetInstalledPackageResponse - 239, // 261: state.v1.StateStoreService.ListInstalledPackages:output_type -> state.v1.ListInstalledPackagesResponse - 241, // 262: state.v1.StateStoreService.AcceptPackageAuthority:output_type -> state.v1.AcceptPackageAuthorityResponse - 243, // 263: state.v1.StateStoreService.RemoveInstalledPackage:output_type -> state.v1.RemoveInstalledPackageResponse - 1, // 264: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse - 3, // 265: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse - 5, // 266: state.v1.StateStoreService.ResolveTaskGrant:output_type -> state.v1.ResolveTaskGrantResponse - 9, // 267: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse - 11, // 268: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse - 17, // 269: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse - 18, // 270: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse - 19, // 271: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse - 20, // 272: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse - 21, // 273: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse - 23, // 274: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse - 25, // 275: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse - 28, // 276: state.v1.StateStoreService.AddPersonalToken:output_type -> state.v1.AddPersonalTokenResponse - 30, // 277: state.v1.StateStoreService.ListPersonalTokens:output_type -> state.v1.ListPersonalTokensResponse - 32, // 278: state.v1.StateStoreService.RevokePersonalToken:output_type -> state.v1.RevokePersonalTokenResponse - 48, // 279: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse - 52, // 280: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse - 50, // 281: state.v1.StateStoreService.ActiveTasksByOrigin:output_type -> state.v1.ActiveTasksByOriginResponse - 54, // 282: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse - 56, // 283: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse - 58, // 284: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse - 74, // 285: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse - 60, // 286: state.v1.StateStoreService.StartStep:output_type -> state.v1.StartStepResponse - 62, // 287: state.v1.StateStoreService.FinishStep:output_type -> state.v1.FinishStepResponse - 64, // 288: state.v1.StateStoreService.CancelExecution:output_type -> state.v1.CancelExecutionResponse - 67, // 289: state.v1.StateStoreService.ListSteps:output_type -> state.v1.ListStepsResponse - 70, // 290: state.v1.StateStoreService.GetHarnessSecret:output_type -> state.v1.GetHarnessSecretResponse - 72, // 291: state.v1.StateStoreService.PutHarnessSecret:output_type -> state.v1.PutHarnessSecretResponse - 76, // 292: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse - 78, // 293: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse - 80, // 294: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse - 82, // 295: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse - 84, // 296: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse - 86, // 297: state.v1.StateStoreService.RespondReviewGate:output_type -> state.v1.RespondReviewGateResponse - 88, // 298: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse - 90, // 299: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse - 92, // 300: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse - 94, // 301: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse - 96, // 302: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse - 98, // 303: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse - 100, // 304: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse - 102, // 305: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse - 104, // 306: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse - 106, // 307: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse - 108, // 308: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse - 110, // 309: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse - 112, // 310: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse - 114, // 311: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse - 116, // 312: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse - 118, // 313: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse - 121, // 314: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse - 123, // 315: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse - 126, // 316: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse - 128, // 317: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse - 131, // 318: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse - 133, // 319: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse - 142, // 320: state.v1.StateStoreService.PutPresence:output_type -> state.v1.PutPresenceResponse - 137, // 321: state.v1.StateStoreService.RecordCaptureRefusal:output_type -> state.v1.RecordCaptureRefusalResponse - 140, // 322: state.v1.StateStoreService.ListCaptureRefusals:output_type -> state.v1.ListCaptureRefusalsResponse - 144, // 323: state.v1.StateStoreService.ListPresence:output_type -> state.v1.ListPresenceResponse - 147, // 324: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse - 149, // 325: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse - 151, // 326: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse - 153, // 327: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse - 155, // 328: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse - 157, // 329: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse - 159, // 330: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse - 161, // 331: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse - 163, // 332: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse - 165, // 333: state.v1.StateStoreService.RecordMappingMatch:output_type -> state.v1.RecordMappingMatchResponse - 167, // 334: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse - 169, // 335: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse - 171, // 336: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse - 173, // 337: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse - 175, // 338: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse - 177, // 339: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse - 179, // 340: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse - 214, // 341: state.v1.StateStoreService.ListDispatches:output_type -> state.v1.ListDispatchesResponse - 181, // 342: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse - 183, // 343: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse - 185, // 344: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse - 193, // 345: state.v1.StateStoreService.PauseBinding:output_type -> state.v1.PauseBindingResponse - 195, // 346: state.v1.StateStoreService.ResumeBinding:output_type -> state.v1.ResumeBindingResponse - 197, // 347: state.v1.StateStoreService.InsertSource:output_type -> state.v1.InsertSourceResponse - 199, // 348: state.v1.StateStoreService.GetSource:output_type -> state.v1.GetSourceResponse - 201, // 349: state.v1.StateStoreService.ListSources:output_type -> state.v1.ListSourcesResponse - 203, // 350: state.v1.StateStoreService.SetSourceSigning:output_type -> state.v1.SetSourceSigningResponse - 205, // 351: state.v1.StateStoreService.SetSourceSecret:output_type -> state.v1.SetSourceSecretResponse - 187, // 352: state.v1.StateStoreService.SetSourceName:output_type -> state.v1.SetSourceNameResponse - 189, // 353: state.v1.StateStoreService.SetSourceDeliveryHeader:output_type -> state.v1.SetSourceDeliveryHeaderResponse - 191, // 354: state.v1.StateStoreService.DeleteSource:output_type -> state.v1.DeleteSourceResponse - 207, // 355: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse - 209, // 356: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse - 211, // 357: state.v1.StateStoreService.SetDispatchTask:output_type -> state.v1.SetDispatchTaskResponse - 216, // 358: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse - 218, // 359: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse - 220, // 360: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse - 222, // 361: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse - 224, // 362: state.v1.StateStoreService.EnqueueCallTask:output_type -> state.v1.EnqueueCallTaskResponse - 226, // 363: state.v1.StateStoreService.WorkflowCallStatus:output_type -> state.v1.WorkflowCallStatusResponse - 247, // 364: state.v1.StateStoreService.GetPrincipal:output_type -> state.v1.GetPrincipalResponse - 250, // 365: state.v1.StateStoreService.ListPolicies:output_type -> state.v1.ListPoliciesResponse - 252, // 366: state.v1.StateStoreService.PutPolicy:output_type -> state.v1.PutPolicyResponse - 254, // 367: state.v1.StateStoreService.DeletePolicy:output_type -> state.v1.DeletePolicyResponse - 256, // 368: state.v1.StateStoreService.EnsureShippedOrgPolicies:output_type -> state.v1.EnsureShippedOrgPoliciesResponse - 259, // 369: state.v1.StateStoreService.RecordDenial:output_type -> state.v1.RecordDenialResponse - 261, // 370: state.v1.StateStoreService.ListDenials:output_type -> state.v1.ListDenialsResponse - 266, // 371: state.v1.StateStoreService.ListOrgs:output_type -> state.v1.ListOrgsResponse - 268, // 372: state.v1.StateStoreService.GetOrg:output_type -> state.v1.GetOrgResponse - 270, // 373: state.v1.StateStoreService.CreateOrg:output_type -> state.v1.CreateOrgResponse - 272, // 374: state.v1.StateStoreService.ListWorkspaces:output_type -> state.v1.ListWorkspacesResponse - 274, // 375: state.v1.StateStoreService.CreateWorkspace:output_type -> state.v1.CreateWorkspaceResponse - 276, // 376: state.v1.StateStoreService.ListMembers:output_type -> state.v1.ListMembersResponse - 278, // 377: state.v1.StateStoreService.SetMembership:output_type -> state.v1.SetMembershipResponse - 280, // 378: state.v1.StateStoreService.RemoveMembership:output_type -> state.v1.RemoveMembershipResponse - 282, // 379: state.v1.StateStoreService.AssignAgent:output_type -> state.v1.AssignAgentResponse - 256, // [256:380] is the sub-list for method output_type - 132, // [132:256] is the sub-list for method input_type - 132, // [132:132] is the sub-list for extension type_name - 132, // [132:132] is the sub-list for extension extendee - 0, // [0:132] is the sub-list for field type_name + 291, // 130: state.v1.RecentLogsRequest.query:type_name -> logging.v1.LogQuery + 292, // 131: state.v1.RecentLogsResponse.snapshot:type_name -> logging.v1.LogSnapshot + 290, // 132: state.v1.UsageRecord.at:type_name -> google.protobuf.Timestamp + 285, // 133: state.v1.RecordUsageRequest.record:type_name -> state.v1.UsageRecord + 283, // 134: state.v1.StateStoreService.RecentLogs:input_type -> state.v1.RecentLogsRequest + 229, // 135: state.v1.StateStoreService.InstallPackage:input_type -> state.v1.InstallPackageRequest + 232, // 136: state.v1.StateStoreService.ListCatalogue:input_type -> state.v1.ListCatalogueRequest + 234, // 137: state.v1.StateStoreService.InstallFromCatalogue:input_type -> state.v1.InstallFromCatalogueRequest + 236, // 138: state.v1.StateStoreService.GetInstalledPackage:input_type -> state.v1.GetInstalledPackageRequest + 238, // 139: state.v1.StateStoreService.ListInstalledPackages:input_type -> state.v1.ListInstalledPackagesRequest + 240, // 140: state.v1.StateStoreService.AcceptPackageAuthority:input_type -> state.v1.AcceptPackageAuthorityRequest + 242, // 141: state.v1.StateStoreService.RemoveInstalledPackage:input_type -> state.v1.RemoveInstalledPackageRequest + 0, // 142: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest + 2, // 143: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest + 4, // 144: state.v1.StateStoreService.ResolveTaskGrant:input_type -> state.v1.ResolveTaskGrantRequest + 8, // 145: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest + 10, // 146: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest + 12, // 147: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest + 13, // 148: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest + 14, // 149: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest + 15, // 150: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest + 16, // 151: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest + 22, // 152: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest + 24, // 153: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest + 27, // 154: state.v1.StateStoreService.AddPersonalToken:input_type -> state.v1.AddPersonalTokenRequest + 29, // 155: state.v1.StateStoreService.ListPersonalTokens:input_type -> state.v1.ListPersonalTokensRequest + 31, // 156: state.v1.StateStoreService.RevokePersonalToken:input_type -> state.v1.RevokePersonalTokenRequest + 47, // 157: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest + 51, // 158: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest + 49, // 159: state.v1.StateStoreService.ActiveTasksByOrigin:input_type -> state.v1.ActiveTasksByOriginRequest + 53, // 160: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest + 55, // 161: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest + 57, // 162: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest + 73, // 163: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest + 59, // 164: state.v1.StateStoreService.StartStep:input_type -> state.v1.StartStepRequest + 286, // 165: state.v1.StateStoreService.RecordUsage:input_type -> state.v1.RecordUsageRequest + 61, // 166: state.v1.StateStoreService.FinishStep:input_type -> state.v1.FinishStepRequest + 63, // 167: state.v1.StateStoreService.CancelExecution:input_type -> state.v1.CancelExecutionRequest + 66, // 168: state.v1.StateStoreService.ListSteps:input_type -> state.v1.ListStepsRequest + 69, // 169: state.v1.StateStoreService.GetHarnessSecret:input_type -> state.v1.GetHarnessSecretRequest + 71, // 170: state.v1.StateStoreService.PutHarnessSecret:input_type -> state.v1.PutHarnessSecretRequest + 75, // 171: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest + 77, // 172: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest + 79, // 173: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest + 81, // 174: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest + 83, // 175: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest + 85, // 176: state.v1.StateStoreService.RespondReviewGate:input_type -> state.v1.RespondReviewGateRequest + 87, // 177: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest + 89, // 178: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest + 91, // 179: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest + 93, // 180: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest + 95, // 181: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest + 97, // 182: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest + 99, // 183: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest + 101, // 184: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest + 103, // 185: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest + 105, // 186: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest + 107, // 187: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest + 109, // 188: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest + 111, // 189: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest + 113, // 190: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest + 115, // 191: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest + 117, // 192: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest + 120, // 193: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest + 122, // 194: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest + 125, // 195: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest + 127, // 196: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest + 130, // 197: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest + 132, // 198: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest + 141, // 199: state.v1.StateStoreService.PutPresence:input_type -> state.v1.PutPresenceRequest + 136, // 200: state.v1.StateStoreService.RecordCaptureRefusal:input_type -> state.v1.RecordCaptureRefusalRequest + 138, // 201: state.v1.StateStoreService.ListCaptureRefusals:input_type -> state.v1.ListCaptureRefusalsRequest + 143, // 202: state.v1.StateStoreService.ListPresence:input_type -> state.v1.ListPresenceRequest + 146, // 203: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest + 148, // 204: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest + 150, // 205: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest + 152, // 206: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest + 154, // 207: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest + 156, // 208: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest + 158, // 209: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest + 160, // 210: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest + 162, // 211: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest + 164, // 212: state.v1.StateStoreService.RecordMappingMatch:input_type -> state.v1.RecordMappingMatchRequest + 166, // 213: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest + 168, // 214: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest + 170, // 215: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest + 172, // 216: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest + 174, // 217: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest + 176, // 218: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest + 178, // 219: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest + 212, // 220: state.v1.StateStoreService.ListDispatches:input_type -> state.v1.ListDispatchesRequest + 180, // 221: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest + 182, // 222: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest + 184, // 223: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest + 192, // 224: state.v1.StateStoreService.PauseBinding:input_type -> state.v1.PauseBindingRequest + 194, // 225: state.v1.StateStoreService.ResumeBinding:input_type -> state.v1.ResumeBindingRequest + 196, // 226: state.v1.StateStoreService.InsertSource:input_type -> state.v1.InsertSourceRequest + 198, // 227: state.v1.StateStoreService.GetSource:input_type -> state.v1.GetSourceRequest + 200, // 228: state.v1.StateStoreService.ListSources:input_type -> state.v1.ListSourcesRequest + 202, // 229: state.v1.StateStoreService.SetSourceSigning:input_type -> state.v1.SetSourceSigningRequest + 204, // 230: state.v1.StateStoreService.SetSourceSecret:input_type -> state.v1.SetSourceSecretRequest + 186, // 231: state.v1.StateStoreService.SetSourceName:input_type -> state.v1.SetSourceNameRequest + 188, // 232: state.v1.StateStoreService.SetSourceDeliveryHeader:input_type -> state.v1.SetSourceDeliveryHeaderRequest + 190, // 233: state.v1.StateStoreService.DeleteSource:input_type -> state.v1.DeleteSourceRequest + 206, // 234: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest + 208, // 235: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest + 210, // 236: state.v1.StateStoreService.SetDispatchTask:input_type -> state.v1.SetDispatchTaskRequest + 215, // 237: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest + 217, // 238: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest + 219, // 239: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest + 221, // 240: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest + 223, // 241: state.v1.StateStoreService.EnqueueCallTask:input_type -> state.v1.EnqueueCallTaskRequest + 225, // 242: state.v1.StateStoreService.WorkflowCallStatus:input_type -> state.v1.WorkflowCallStatusRequest + 244, // 243: state.v1.StateStoreService.GetPrincipal:input_type -> state.v1.GetPrincipalRequest + 249, // 244: state.v1.StateStoreService.ListPolicies:input_type -> state.v1.ListPoliciesRequest + 251, // 245: state.v1.StateStoreService.PutPolicy:input_type -> state.v1.PutPolicyRequest + 253, // 246: state.v1.StateStoreService.DeletePolicy:input_type -> state.v1.DeletePolicyRequest + 255, // 247: state.v1.StateStoreService.EnsureShippedOrgPolicies:input_type -> state.v1.EnsureShippedOrgPoliciesRequest + 258, // 248: state.v1.StateStoreService.RecordDenial:input_type -> state.v1.RecordDenialRequest + 260, // 249: state.v1.StateStoreService.ListDenials:input_type -> state.v1.ListDenialsRequest + 265, // 250: state.v1.StateStoreService.ListOrgs:input_type -> state.v1.ListOrgsRequest + 267, // 251: state.v1.StateStoreService.GetOrg:input_type -> state.v1.GetOrgRequest + 269, // 252: state.v1.StateStoreService.CreateOrg:input_type -> state.v1.CreateOrgRequest + 271, // 253: state.v1.StateStoreService.ListWorkspaces:input_type -> state.v1.ListWorkspacesRequest + 273, // 254: state.v1.StateStoreService.CreateWorkspace:input_type -> state.v1.CreateWorkspaceRequest + 275, // 255: state.v1.StateStoreService.ListMembers:input_type -> state.v1.ListMembersRequest + 277, // 256: state.v1.StateStoreService.SetMembership:input_type -> state.v1.SetMembershipRequest + 279, // 257: state.v1.StateStoreService.RemoveMembership:input_type -> state.v1.RemoveMembershipRequest + 281, // 258: state.v1.StateStoreService.AssignAgent:input_type -> state.v1.AssignAgentRequest + 284, // 259: state.v1.StateStoreService.RecentLogs:output_type -> state.v1.RecentLogsResponse + 230, // 260: state.v1.StateStoreService.InstallPackage:output_type -> state.v1.InstallPackageResponse + 233, // 261: state.v1.StateStoreService.ListCatalogue:output_type -> state.v1.ListCatalogueResponse + 235, // 262: state.v1.StateStoreService.InstallFromCatalogue:output_type -> state.v1.InstallFromCatalogueResponse + 237, // 263: state.v1.StateStoreService.GetInstalledPackage:output_type -> state.v1.GetInstalledPackageResponse + 239, // 264: state.v1.StateStoreService.ListInstalledPackages:output_type -> state.v1.ListInstalledPackagesResponse + 241, // 265: state.v1.StateStoreService.AcceptPackageAuthority:output_type -> state.v1.AcceptPackageAuthorityResponse + 243, // 266: state.v1.StateStoreService.RemoveInstalledPackage:output_type -> state.v1.RemoveInstalledPackageResponse + 1, // 267: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse + 3, // 268: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse + 5, // 269: state.v1.StateStoreService.ResolveTaskGrant:output_type -> state.v1.ResolveTaskGrantResponse + 9, // 270: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse + 11, // 271: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse + 17, // 272: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse + 18, // 273: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse + 19, // 274: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse + 20, // 275: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse + 21, // 276: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse + 23, // 277: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse + 25, // 278: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse + 28, // 279: state.v1.StateStoreService.AddPersonalToken:output_type -> state.v1.AddPersonalTokenResponse + 30, // 280: state.v1.StateStoreService.ListPersonalTokens:output_type -> state.v1.ListPersonalTokensResponse + 32, // 281: state.v1.StateStoreService.RevokePersonalToken:output_type -> state.v1.RevokePersonalTokenResponse + 48, // 282: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse + 52, // 283: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse + 50, // 284: state.v1.StateStoreService.ActiveTasksByOrigin:output_type -> state.v1.ActiveTasksByOriginResponse + 54, // 285: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse + 56, // 286: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse + 58, // 287: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse + 74, // 288: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse + 60, // 289: state.v1.StateStoreService.StartStep:output_type -> state.v1.StartStepResponse + 287, // 290: state.v1.StateStoreService.RecordUsage:output_type -> state.v1.RecordUsageResponse + 62, // 291: state.v1.StateStoreService.FinishStep:output_type -> state.v1.FinishStepResponse + 64, // 292: state.v1.StateStoreService.CancelExecution:output_type -> state.v1.CancelExecutionResponse + 67, // 293: state.v1.StateStoreService.ListSteps:output_type -> state.v1.ListStepsResponse + 70, // 294: state.v1.StateStoreService.GetHarnessSecret:output_type -> state.v1.GetHarnessSecretResponse + 72, // 295: state.v1.StateStoreService.PutHarnessSecret:output_type -> state.v1.PutHarnessSecretResponse + 76, // 296: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse + 78, // 297: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse + 80, // 298: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse + 82, // 299: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse + 84, // 300: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse + 86, // 301: state.v1.StateStoreService.RespondReviewGate:output_type -> state.v1.RespondReviewGateResponse + 88, // 302: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse + 90, // 303: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse + 92, // 304: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse + 94, // 305: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse + 96, // 306: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse + 98, // 307: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse + 100, // 308: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse + 102, // 309: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse + 104, // 310: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse + 106, // 311: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse + 108, // 312: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse + 110, // 313: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse + 112, // 314: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse + 114, // 315: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse + 116, // 316: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse + 118, // 317: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse + 121, // 318: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse + 123, // 319: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse + 126, // 320: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse + 128, // 321: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse + 131, // 322: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse + 133, // 323: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse + 142, // 324: state.v1.StateStoreService.PutPresence:output_type -> state.v1.PutPresenceResponse + 137, // 325: state.v1.StateStoreService.RecordCaptureRefusal:output_type -> state.v1.RecordCaptureRefusalResponse + 140, // 326: state.v1.StateStoreService.ListCaptureRefusals:output_type -> state.v1.ListCaptureRefusalsResponse + 144, // 327: state.v1.StateStoreService.ListPresence:output_type -> state.v1.ListPresenceResponse + 147, // 328: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse + 149, // 329: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse + 151, // 330: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse + 153, // 331: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse + 155, // 332: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse + 157, // 333: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse + 159, // 334: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse + 161, // 335: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse + 163, // 336: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse + 165, // 337: state.v1.StateStoreService.RecordMappingMatch:output_type -> state.v1.RecordMappingMatchResponse + 167, // 338: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse + 169, // 339: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse + 171, // 340: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse + 173, // 341: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse + 175, // 342: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse + 177, // 343: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse + 179, // 344: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse + 214, // 345: state.v1.StateStoreService.ListDispatches:output_type -> state.v1.ListDispatchesResponse + 181, // 346: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse + 183, // 347: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse + 185, // 348: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse + 193, // 349: state.v1.StateStoreService.PauseBinding:output_type -> state.v1.PauseBindingResponse + 195, // 350: state.v1.StateStoreService.ResumeBinding:output_type -> state.v1.ResumeBindingResponse + 197, // 351: state.v1.StateStoreService.InsertSource:output_type -> state.v1.InsertSourceResponse + 199, // 352: state.v1.StateStoreService.GetSource:output_type -> state.v1.GetSourceResponse + 201, // 353: state.v1.StateStoreService.ListSources:output_type -> state.v1.ListSourcesResponse + 203, // 354: state.v1.StateStoreService.SetSourceSigning:output_type -> state.v1.SetSourceSigningResponse + 205, // 355: state.v1.StateStoreService.SetSourceSecret:output_type -> state.v1.SetSourceSecretResponse + 187, // 356: state.v1.StateStoreService.SetSourceName:output_type -> state.v1.SetSourceNameResponse + 189, // 357: state.v1.StateStoreService.SetSourceDeliveryHeader:output_type -> state.v1.SetSourceDeliveryHeaderResponse + 191, // 358: state.v1.StateStoreService.DeleteSource:output_type -> state.v1.DeleteSourceResponse + 207, // 359: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse + 209, // 360: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse + 211, // 361: state.v1.StateStoreService.SetDispatchTask:output_type -> state.v1.SetDispatchTaskResponse + 216, // 362: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse + 218, // 363: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse + 220, // 364: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse + 222, // 365: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse + 224, // 366: state.v1.StateStoreService.EnqueueCallTask:output_type -> state.v1.EnqueueCallTaskResponse + 226, // 367: state.v1.StateStoreService.WorkflowCallStatus:output_type -> state.v1.WorkflowCallStatusResponse + 247, // 368: state.v1.StateStoreService.GetPrincipal:output_type -> state.v1.GetPrincipalResponse + 250, // 369: state.v1.StateStoreService.ListPolicies:output_type -> state.v1.ListPoliciesResponse + 252, // 370: state.v1.StateStoreService.PutPolicy:output_type -> state.v1.PutPolicyResponse + 254, // 371: state.v1.StateStoreService.DeletePolicy:output_type -> state.v1.DeletePolicyResponse + 256, // 372: state.v1.StateStoreService.EnsureShippedOrgPolicies:output_type -> state.v1.EnsureShippedOrgPoliciesResponse + 259, // 373: state.v1.StateStoreService.RecordDenial:output_type -> state.v1.RecordDenialResponse + 261, // 374: state.v1.StateStoreService.ListDenials:output_type -> state.v1.ListDenialsResponse + 266, // 375: state.v1.StateStoreService.ListOrgs:output_type -> state.v1.ListOrgsResponse + 268, // 376: state.v1.StateStoreService.GetOrg:output_type -> state.v1.GetOrgResponse + 270, // 377: state.v1.StateStoreService.CreateOrg:output_type -> state.v1.CreateOrgResponse + 272, // 378: state.v1.StateStoreService.ListWorkspaces:output_type -> state.v1.ListWorkspacesResponse + 274, // 379: state.v1.StateStoreService.CreateWorkspace:output_type -> state.v1.CreateWorkspaceResponse + 276, // 380: state.v1.StateStoreService.ListMembers:output_type -> state.v1.ListMembersResponse + 278, // 381: state.v1.StateStoreService.SetMembership:output_type -> state.v1.SetMembershipResponse + 280, // 382: state.v1.StateStoreService.RemoveMembership:output_type -> state.v1.RemoveMembershipResponse + 282, // 383: state.v1.StateStoreService.AssignAgent:output_type -> state.v1.AssignAgentResponse + 259, // [259:384] is the sub-list for method output_type + 134, // [134:259] is the sub-list for method input_type + 134, // [134:134] is the sub-list for extension type_name + 134, // [134:134] is the sub-list for extension extendee + 0, // [0:134] is the sub-list for field type_name } func init() { file_state_v1_state_proto_init() } @@ -17209,7 +17458,7 @@ func file_state_v1_state_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_state_v1_state_proto_rawDesc), len(file_state_v1_state_proto_rawDesc)), NumEnums: 0, - NumMessages: 287, + NumMessages: 290, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/contracts/state/v1/state_grpc.pb.go b/internal/contracts/state/v1/state_grpc.pb.go index d4d631593..f7958bc5f 100644 --- a/internal/contracts/state/v1/state_grpc.pb.go +++ b/internal/contracts/state/v1/state_grpc.pb.go @@ -50,6 +50,7 @@ const ( StateStoreService_Transition_FullMethodName = "/state.v1.StateStoreService/Transition" StateStoreService_Update_FullMethodName = "/state.v1.StateStoreService/Update" StateStoreService_StartStep_FullMethodName = "/state.v1.StateStoreService/StartStep" + StateStoreService_RecordUsage_FullMethodName = "/state.v1.StateStoreService/RecordUsage" StateStoreService_FinishStep_FullMethodName = "/state.v1.StateStoreService/FinishStep" StateStoreService_CancelExecution_FullMethodName = "/state.v1.StateStoreService/CancelExecution" StateStoreService_ListSteps_FullMethodName = "/state.v1.StateStoreService/ListSteps" @@ -204,6 +205,9 @@ type StateStoreServiceClient interface { // Step executions (docs/prds/execution-tree-state-machine.md). The run // credential authorises both on its own execution only. StartStep(ctx context.Context, in *StartStepRequest, opts ...grpc.CallOption) (*StartStepResponse, error) + // RecordUsage appends one model call's usage record. A run credential may + // record usage only for its own task. + RecordUsage(ctx context.Context, in *RecordUsageRequest, opts ...grpc.CallOption) (*RecordUsageResponse, error) FinishStep(ctx context.Context, in *FinishStepRequest, opts ...grpc.CallOption) (*FinishStepResponse, error) // Cancellation. Deliberately administrative (deny-by-default for a // task-scoped grant): a cancel is a dashboard, API and dispatch action @@ -698,6 +702,16 @@ func (c *stateStoreServiceClient) StartStep(ctx context.Context, in *StartStepRe return out, nil } +func (c *stateStoreServiceClient) RecordUsage(ctx context.Context, in *RecordUsageRequest, opts ...grpc.CallOption) (*RecordUsageResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RecordUsageResponse) + err := c.cc.Invoke(ctx, StateStoreService_RecordUsage_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *stateStoreServiceClient) FinishStep(ctx context.Context, in *FinishStepRequest, opts ...grpc.CallOption) (*FinishStepResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(FinishStepResponse) @@ -1714,6 +1728,9 @@ type StateStoreServiceServer interface { // Step executions (docs/prds/execution-tree-state-machine.md). The run // credential authorises both on its own execution only. StartStep(context.Context, *StartStepRequest) (*StartStepResponse, error) + // RecordUsage appends one model call's usage record. A run credential may + // record usage only for its own task. + RecordUsage(context.Context, *RecordUsageRequest) (*RecordUsageResponse, error) FinishStep(context.Context, *FinishStepRequest) (*FinishStepResponse, error) // Cancellation. Deliberately administrative (deny-by-default for a // task-scoped grant): a cancel is a dashboard, API and dispatch action @@ -1991,6 +2008,9 @@ func (UnimplementedStateStoreServiceServer) Update(context.Context, *UpdateReque func (UnimplementedStateStoreServiceServer) StartStep(context.Context, *StartStepRequest) (*StartStepResponse, error) { return nil, status.Error(codes.Unimplemented, "method StartStep not implemented") } +func (UnimplementedStateStoreServiceServer) RecordUsage(context.Context, *RecordUsageRequest) (*RecordUsageResponse, error) { + return nil, status.Error(codes.Unimplemented, "method RecordUsage not implemented") +} func (UnimplementedStateStoreServiceServer) FinishStep(context.Context, *FinishStepRequest) (*FinishStepResponse, error) { return nil, status.Error(codes.Unimplemented, "method FinishStep not implemented") } @@ -2849,6 +2869,24 @@ func _StateStoreService_StartStep_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _StateStoreService_RecordUsage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RecordUsageRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).RecordUsage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_RecordUsage_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).RecordUsage(ctx, req.(*RecordUsageRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _StateStoreService_FinishStep_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(FinishStepRequest) if err := dec(in); err != nil { @@ -4633,6 +4671,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{ MethodName: "StartStep", Handler: _StateStoreService_StartStep_Handler, }, + { + MethodName: "RecordUsage", + Handler: _StateStoreService_RecordUsage_Handler, + }, { MethodName: "FinishStep", Handler: _StateStoreService_FinishStep_Handler, diff --git a/internal/domain/usage/usage.go b/internal/domain/usage/usage.go new file mode 100644 index 000000000..34e35e12c --- /dev/null +++ b/internal/domain/usage/usage.go @@ -0,0 +1,46 @@ +// Package usage records model calls for attribution and chargeback. +package usage + +import ( + "context" + "strings" + "time" +) + +// Source is what made a model call. +type Source string + +const ( + SourceTask Source = "task" + SourceChat Source = "chat" + SourceCurator Source = "curator" +) + +// Record is one model call. A task's record belongs to the task's org, +// whatever Org says. +type Record struct { + Org string + Source Source + TaskID int64 + Attempt int + Workflow string + Step string + Alias string + Provider string + Model string + InputTokens int64 + OutputTokens int64 + CachedTokens int64 + At time.Time +} + +// Recorder appends usage records. +type Recorder interface { + RecordUsage(ctx context.Context, r Record) error +} + +// WithRef fills Provider and Model from a "provider/model" ref. +func (r Record) WithRef(ref string) Record { + r.Provider, r.Model, _ = strings.Cut(ref, "/") + return r +} diff --git a/internal/domain/workflow/agent.go b/internal/domain/workflow/agent.go index 8203c198b..c4c881137 100644 --- a/internal/domain/workflow/agent.go +++ b/internal/domain/workflow/agent.go @@ -68,7 +68,7 @@ func (a AgentStage) Stage() Stage { } // The agent call is a child of the stage's recorded step: the store // says what the stage's runtime did, not just what the stage did. - res, runErr := tc.RunAgentChild(ctx, a.Name, func() (agentrun.Result, error) { + res, runErr := tc.RunAgentChild(ctx, a.Name, a.Model, modelRef, func() (agentrun.Result, error) { return tc.Agent.Run(ctx, tc.Dir, req, tc.toolCallReporter(a.Name)) }) return a.handleResult(ctx, tc, req, res, runErr, modelRef) diff --git a/internal/domain/workflow/implement.go b/internal/domain/workflow/implement.go index 65fe81507..380772fc8 100644 --- a/internal/domain/workflow/implement.go +++ b/internal/domain/workflow/implement.go @@ -95,7 +95,7 @@ func runBaselineFix(ctx context.Context, tc *TaskContext, argv []string, out []b Protection: agentrun.Protection{Suffixes: append([]string(nil), tc.Repo.Protect...)}, } - res, agentErr := tc.RunAgentChild(ctx, "baseline-fix", func() (agentrun.Result, error) { + res, agentErr := tc.RunAgentChild(ctx, "baseline-fix", "", modelRef, func() (agentrun.Result, error) { return tc.Agent.Run(ctx, tc.Dir, req, tc.toolCallReporter("baseline-fix")) }) if agentErr != nil && res.Version == 0 { diff --git a/internal/domain/workflow/prreview_stages.go b/internal/domain/workflow/prreview_stages.go index 636f8f28c..84ea770d6 100644 --- a/internal/domain/workflow/prreview_stages.go +++ b/internal/domain/workflow/prreview_stages.go @@ -757,7 +757,7 @@ func runPRReviewAgentRecorded( Budget: agentrun.Budget{MaxSteps: maxSteps, WallClock: tc.Cfg.Budgets.WallClock.Std()}, CaptureTools: captureTools, } - res, err := tc.RunAgentChild(ctx, name, func() (agentrun.Result, error) { + res, err := tc.RunAgentChild(ctx, name, "", modelRef, func() (agentrun.Result, error) { return tc.Agent.Run(ctx, workspace, req, tc.toolCallReporter(name)) }) tc.prReview.tokensSpent.Add(int64(res.TokensUsed)) diff --git a/internal/domain/workflow/step_flow_test.go b/internal/domain/workflow/step_flow_test.go index bc3714d41..41c554d62 100644 --- a/internal/domain/workflow/step_flow_test.go +++ b/internal/domain/workflow/step_flow_test.go @@ -9,6 +9,7 @@ import ( "gopkg.in/yaml.v3" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/taskstate" @@ -44,6 +45,8 @@ func (f *fakeStepStore) FinishStep(_ context.Context, s task.StepFinish) (events return events.Event{ID: s.StepID}, nil } +func (f *fakeStepStore) RecordUsage(context.Context, usage.Record) error { return nil } + // TestRunBranchRecordsChildSteps pins the step contract a branch owes the // canvas: every branch step is a stage row parented to the parallel step and // named for its branch, and its outcome is recorded. diff --git a/internal/domain/workflow/task/task.go b/internal/domain/workflow/task/task.go index a59f625cd..98ebe0eef 100644 --- a/internal/domain/workflow/task/task.go +++ b/internal/domain/workflow/task/task.go @@ -8,6 +8,7 @@ import ( "time" "github.com/samcharles93/archie-core/internal/domain/org" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/taskstate" ) @@ -185,6 +186,8 @@ type Store interface { // the stage_finish event in the same transaction, and returns that event // for the caller's post-commit publish. FinishStep(ctx context.Context, s StepFinish) (events.Event, error) + // RecordUsage appends one model call's usage record. + RecordUsage(ctx context.Context, r usage.Record) error } // Definition is a workflow's id and stage order. diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go index e01b471d5..5bf40a436 100644 --- a/internal/domain/workflow/workflow.go +++ b/internal/domain/workflow/workflow.go @@ -15,6 +15,7 @@ import ( "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/agentrun" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/taskstate" @@ -568,7 +569,7 @@ var goTestOKLine = regexp.MustCompile(`^ok\s+\S+`) // RunAgentChild records one agent call as a child step of the current stage. // A failed write parks the execution. Outside a recorded run it just runs. -func (tc *TaskContext) RunAgentChild(ctx context.Context, name string, run func() (agentrun.Result, error)) (agentrun.Result, error) { +func (tc *TaskContext) RunAgentChild(ctx context.Context, name, alias, modelRef string, run func() (agentrun.Result, error)) (agentrun.Result, error) { if tc.workflowBranch != "" { name = tc.workflowBranch + "/" + name } @@ -577,6 +578,7 @@ func (tc *TaskContext) RunAgentChild(ctx context.Context, name string, run func( return agentrun.Result{}, err } res, runErr := run() + tc.recordUsage(ctx, name, alias, modelRef, res.Usage) to, detail := taskstate.StepSucceeded, res.Summary if runErr != nil { to, detail = taskstate.StepFailed, runErr.Error() @@ -621,3 +623,19 @@ func (tc *TaskContext) finishChildStep(ctx context.Context, stepID int64, to tas publishEvent(tc, event) return nil } + +// recordUsage appends the usage record for one agent run. A failed write is +// logged, never fails the run: the work already happened. +func (tc *TaskContext) recordUsage(ctx context.Context, step, alias, modelRef string, u agentrun.Usage) { + if tc.Store == nil { + return + } + record := usage.Record{ + Source: usage.SourceTask, TaskID: tc.Task.ID, Attempt: tc.Task.Attempt, Workflow: tc.Task.Workflow, + Step: step, Alias: alias, InputTokens: int64(u.PromptTokens), OutputTokens: int64(u.CompletionTokens), + CachedTokens: int64(u.CachedTokens), At: time.Now().UTC(), + }.WithRef(modelRef) + if err := tc.Store.RecordUsage(ctx, record); err != nil && tc.Log != nil { + tc.Log.Warn("record model usage failed", "step", step, "model", modelRef, "err", err) + } +} diff --git a/internal/infrastructure/postgres/migrations/0040_model_usage.sql b/internal/infrastructure/postgres/migrations/0040_model_usage.sql new file mode 100644 index 000000000..0e9da45f0 --- /dev/null +++ b/internal/infrastructure/postgres/migrations/0040_model_usage.sql @@ -0,0 +1,26 @@ +-- One row per model call: who made it, for what, on which model, and the +-- tokens it used. Chargeback and usage reports aggregate these rows. + +-- +goose Up + +CREATE TABLE model_usage ( + id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + org_id text NOT NULL, + source text NOT NULL CHECK (source IN ('task', 'chat', 'curator')), + task_id bigint NOT NULL DEFAULT 0, + attempt bigint NOT NULL DEFAULT 0, + workflow text NOT NULL DEFAULT '', + step text NOT NULL DEFAULT '', + alias text NOT NULL DEFAULT '', + provider text NOT NULL, + model text NOT NULL, + input_tokens bigint NOT NULL DEFAULT 0, + output_tokens bigint NOT NULL DEFAULT 0, + cached_tokens bigint NOT NULL DEFAULT 0, + at timestamptz NOT NULL +); +CREATE INDEX idx_model_usage_org_at ON model_usage (org_id, at); + +-- +goose Down + +DROP TABLE model_usage; diff --git a/internal/infrastructure/postgres/postgresdb/models.go b/internal/infrastructure/postgres/postgresdb/models.go index fdc14597a..127db021c 100644 --- a/internal/infrastructure/postgres/postgresdb/models.go +++ b/internal/infrastructure/postgres/postgresdb/models.go @@ -260,6 +260,23 @@ type Message struct { Media []byte } +type ModelUsage struct { + ID int64 + OrgID string + Source string + TaskID int64 + Attempt int64 + Workflow string + Step string + Alias string + Provider string + Model string + InputTokens int64 + OutputTokens int64 + CachedTokens int64 + At time.Time +} + type Org struct { ID string Name string diff --git a/internal/infrastructure/postgres/postgresdb/usage.sql.go b/internal/infrastructure/postgres/postgresdb/usage.sql.go new file mode 100644 index 000000000..080a62e89 --- /dev/null +++ b/internal/infrastructure/postgres/postgresdb/usage.sql.go @@ -0,0 +1,58 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: usage.sql + +package postgresdb + +import ( + "context" + "time" +) + +const insertModelUsage = `-- name: InsertModelUsage :exec +INSERT INTO model_usage ( + org_id, source, task_id, attempt, workflow, step, alias, provider, model, + input_tokens, output_tokens, cached_tokens, at +) VALUES ( + COALESCE((SELECT t.org_id FROM tasks t WHERE t.id = $1 AND $1 <> 0), $2::text), + $3, $1, $4, $5, $6, $7, + $8, $9, $10, $11, $12, $13 +) +` + +type InsertModelUsageParams struct { + TaskID int64 + OrgID string + Source string + Attempt int64 + Workflow string + Step string + Alias string + Provider string + Model string + InputTokens int64 + OutputTokens int64 + CachedTokens int64 + At time.Time +} + +// A task's usage belongs to the task's org, whatever the caller says. +func (q *Queries) InsertModelUsage(ctx context.Context, arg InsertModelUsageParams) error { + _, err := q.db.Exec(ctx, insertModelUsage, + arg.TaskID, + arg.OrgID, + arg.Source, + arg.Attempt, + arg.Workflow, + arg.Step, + arg.Alias, + arg.Provider, + arg.Model, + arg.InputTokens, + arg.OutputTokens, + arg.CachedTokens, + arg.At, + ) + return err +} diff --git a/internal/infrastructure/postgres/queries/usage.sql b/internal/infrastructure/postgres/queries/usage.sql new file mode 100644 index 000000000..53f4136d6 --- /dev/null +++ b/internal/infrastructure/postgres/queries/usage.sql @@ -0,0 +1,10 @@ +-- name: InsertModelUsage :exec +-- A task's usage belongs to the task's org, whatever the caller says. +INSERT INTO model_usage ( + org_id, source, task_id, attempt, workflow, step, alias, provider, model, + input_tokens, output_tokens, cached_tokens, at +) VALUES ( + COALESCE((SELECT t.org_id FROM tasks t WHERE t.id = sqlc.arg(task_id) AND sqlc.arg(task_id) <> 0), sqlc.arg(org_id)::text), + sqlc.arg(source), sqlc.arg(task_id), sqlc.arg(attempt), sqlc.arg(workflow), sqlc.arg(step), sqlc.arg(alias), + sqlc.arg(provider), sqlc.arg(model), sqlc.arg(input_tokens), sqlc.arg(output_tokens), sqlc.arg(cached_tokens), sqlc.arg(at) +); diff --git a/internal/infrastructure/postgres/usage.go b/internal/infrastructure/postgres/usage.go new file mode 100644 index 000000000..c7659cbd9 --- /dev/null +++ b/internal/infrastructure/postgres/usage.go @@ -0,0 +1,17 @@ +package postgres + +import ( + "context" + + "github.com/samcharles93/archie-core/internal/domain/usage" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb" +) + +// RecordUsage appends one model call's usage record. +func (s *Store) RecordUsage(ctx context.Context, r usage.Record) error { + return postgresdb.New(s.pool).InsertModelUsage(ctx, postgresdb.InsertModelUsageParams{ + TaskID: r.TaskID, OrgID: r.Org, Source: string(r.Source), Attempt: int64(r.Attempt), + Workflow: r.Workflow, Step: r.Step, Alias: r.Alias, Provider: r.Provider, Model: r.Model, + InputTokens: r.InputTokens, OutputTokens: r.OutputTokens, CachedTokens: r.CachedTokens, At: r.At, + }) +} diff --git a/internal/infrastructure/postgres/usage_org_test.go b/internal/infrastructure/postgres/usage_org_test.go new file mode 100644 index 000000000..3264ee0b7 --- /dev/null +++ b/internal/infrastructure/postgres/usage_org_test.go @@ -0,0 +1,45 @@ +package postgres_test + +import ( + "testing" + "time" + + "github.com/samcharles93/archie-core/internal/domain/usage" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" +) + +// A task's usage is billed to the task's org whatever org the caller names; +// usage with no task keeps the caller's org. +func TestRecordUsageBillsTheTaskOrg(t *testing.T) { + ctx := t.Context() + db := pgstore.Open(t) + var taskID int64 + if err := db.Pool.QueryRow(ctx, + `INSERT INTO tasks (owner, repo, issue_number, identity, org_id, workspace_id) VALUES ('o', 'r', 1, 'sam', 'acme', 'default') RETURNING id`, + ).Scan(&taskID); err != nil { + t.Fatal(err) + } + for _, tt := range []struct { + name string + record usage.Record + want string + }{ + {"a task bills its own org", usage.Record{Org: "other", Source: usage.SourceTask, TaskID: taskID}, "acme"}, + {"chat keeps the caller's org", usage.Record{Org: "org-sys", Source: usage.SourceChat}, "org-sys"}, + } { + t.Run(tt.name, func(t *testing.T) { + tt.record.Step, tt.record.At = tt.name, time.Now() + tt.record = tt.record.WithRef("openai/gpt-6-luna") + if err := db.RecordUsage(ctx, tt.record); err != nil { + t.Fatal(err) + } + var got string + if err := db.Pool.QueryRow(ctx, "SELECT org_id FROM model_usage WHERE step = $1", tt.name).Scan(&got); err != nil { + t.Fatal(err) + } + if got != tt.want { + t.Fatalf("org = %q, want %q", got, tt.want) + } + }) + } +} diff --git a/internal/infrastructure/staterpc/client.go b/internal/infrastructure/staterpc/client.go index 95176b968..a302d9589 100644 --- a/internal/infrastructure/staterpc/client.go +++ b/internal/infrastructure/staterpc/client.go @@ -17,6 +17,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/source" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/storepkg" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/logging" @@ -125,6 +126,12 @@ func (c *Client) Transition(ctx context.Context, taskID int64, from, to, detail return unmapError(err) } +// RecordUsage appends one model call's usage record. +func (c *Client) RecordUsage(ctx context.Context, r usage.Record) error { + _, err := c.client.RecordUsage(ctx, &pb.RecordUsageRequest{Record: usageProto(r)}) + return unmapError(err) +} + // StartStep and FinishStep record step executions and return the persisted // event. func (c *Client) StartStep(ctx context.Context, s task.StepStart) (int64, events.Event, error) { diff --git a/internal/infrastructure/staterpc/server.go b/internal/infrastructure/staterpc/server.go index c31f820a2..e7be1b9fb 100644 --- a/internal/infrastructure/staterpc/server.go +++ b/internal/infrastructure/staterpc/server.go @@ -25,6 +25,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/source" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/storepkg" + "github.com/samcharles93/archie-core/internal/domain/usage" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/logging" "github.com/samcharles93/archie-core/internal/taskstate" @@ -104,6 +105,9 @@ type Deps struct { // workflow engine's run credential calls. Optional: nil answers both RPCs // with codes.Unavailable. Steps storecontract.StepRecorder + // Usage appends model usage records. Optional: nil answers RecordUsage + // with codes.Unavailable. + Usage usage.Recorder // Canceller is the one cancel path: // an operator action's guarded write over the execution and its steps. // Optional: nil answers the RPC with codes.Unavailable. @@ -249,6 +253,20 @@ func (s *server) StartStep(ctx context.Context, r *pb.StartStepRequest) (*pb.Sta return &pb.StartStepResponse{StepId: stepID, Event: eventProto(event)}, nil } +// RecordUsage appends one model call's usage record. +func (s *server) RecordUsage(ctx context.Context, r *pb.RecordUsageRequest) (*pb.RecordUsageResponse, error) { + if s.deps.Usage == nil { + return nil, status.Error(codes.Unavailable, "usage recorder unavailable") + } + if r.Record == nil { + return nil, status.Error(codes.InvalidArgument, "record is required") + } + if err := s.deps.Usage.RecordUsage(ctx, usageValue(r.Record)); err != nil { + return nil, s.logErr("RecordUsage", err) + } + return &pb.RecordUsageResponse{}, nil +} + // CancelExecution is the one cancel path: // the store records the cancellation and returns the steps it cancelled; the // caller delivers it by cancelling the run's in-memory context afterwards. diff --git a/internal/infrastructure/staterpc/task_grants.go b/internal/infrastructure/staterpc/task_grants.go index 476096863..36906e682 100644 --- a/internal/infrastructure/staterpc/task_grants.go +++ b/internal/infrastructure/staterpc/task_grants.go @@ -128,6 +128,13 @@ var taskScopedTargets = map[string]func(any) int64{ } return r.ExecutionId }, + pb.StateStoreService_RecordUsage_FullMethodName: func(req any) int64 { + r, ok := req.(*pb.RecordUsageRequest) + if !ok || r.Record == nil { + return 0 + } + return r.Record.TaskId + }, pb.StateStoreService_FinishStep_FullMethodName: func(req any) int64 { r, ok := req.(*pb.FinishStepRequest) if !ok { diff --git a/internal/infrastructure/staterpc/usage_grant_test.go b/internal/infrastructure/staterpc/usage_grant_test.go new file mode 100644 index 000000000..9cb885329 --- /dev/null +++ b/internal/infrastructure/staterpc/usage_grant_test.go @@ -0,0 +1,29 @@ +package staterpc + +import ( + "testing" + + pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" +) + +// A run credential records usage only against its own task, so one tenant's +// task cannot bill another's. +func TestRecordUsageAuthority(t *testing.T) { + for _, tt := range []struct { + name string + record *pb.UsageRecord + allowed bool + }{ + {"own task", &pb.UsageRecord{TaskId: 7}, true}, + {"another task", &pb.UsageRecord{TaskId: 8}, false}, + {"no task", &pb.UsageRecord{OrgId: "org-sys"}, false}, + {"no record", nil, false}, + } { + t.Run(tt.name, func(t *testing.T) { + req := &pb.RecordUsageRequest{Record: tt.record} + if got := authorizesTaskScopedCall(pb.StateStoreService_RecordUsage_FullMethodName, req, 7); got != tt.allowed { + t.Fatalf("authorized = %v, want %v", got, tt.allowed) + } + }) + } +} diff --git a/internal/infrastructure/staterpc/usage_values.go b/internal/infrastructure/staterpc/usage_values.go new file mode 100644 index 000000000..20a223a7b --- /dev/null +++ b/internal/infrastructure/staterpc/usage_values.go @@ -0,0 +1,26 @@ +package staterpc + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + + pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" + "github.com/samcharles93/archie-core/internal/domain/usage" +) + +func usageProto(r usage.Record) *pb.UsageRecord { + return &pb.UsageRecord{ + OrgId: r.Org, Source: string(r.Source), TaskId: r.TaskID, Attempt: int64(r.Attempt), + Workflow: r.Workflow, Step: r.Step, Alias: r.Alias, Provider: r.Provider, Model: r.Model, + InputTokens: r.InputTokens, OutputTokens: r.OutputTokens, CachedTokens: r.CachedTokens, + At: timestamppb.New(r.At), + } +} + +func usageValue(r *pb.UsageRecord) usage.Record { + return usage.Record{ + Org: r.GetOrgId(), Source: usage.Source(r.GetSource()), TaskID: r.GetTaskId(), Attempt: int(r.GetAttempt()), + Workflow: r.GetWorkflow(), Step: r.GetStep(), Alias: r.GetAlias(), Provider: r.GetProvider(), Model: r.GetModel(), + InputTokens: r.GetInputTokens(), OutputTokens: r.GetOutputTokens(), CachedTokens: r.GetCachedTokens(), + At: r.GetAt().AsTime(), + } +} diff --git a/proto/state/v1/state.proto b/proto/state/v1/state.proto index cd4f39cc5..9a2edf251 100644 --- a/proto/state/v1/state.proto +++ b/proto/state/v1/state.proto @@ -61,6 +61,9 @@ service StateStoreService { // Step executions (docs/prds/execution-tree-state-machine.md). The run // credential authorises both on its own execution only. rpc StartStep(StartStepRequest) returns (StartStepResponse); + // RecordUsage appends one model call's usage record. A run credential may + // record usage only for its own task. + rpc RecordUsage(RecordUsageRequest) returns (RecordUsageResponse); rpc FinishStep(FinishStepRequest) returns (FinishStepResponse); // Cancellation. Deliberately administrative (deny-by-default for a // task-scoped grant): a cancel is a dashboard, API and dispatch action @@ -1492,3 +1495,24 @@ message AssignAgentResponse {} message RecentLogsRequest { logging.v1.LogQuery query = 1; } message RecentLogsResponse { logging.v1.LogSnapshot snapshot = 1; } + +// UsageRecord mirrors usage.Record. A task's record belongs to the task's +// org, whatever org_id says. +message UsageRecord { + string org_id = 1; + // source is task, chat or curator. + string source = 2; + int64 task_id = 3; + int64 attempt = 4; + string workflow = 5; + string step = 6; + string alias = 7; + string provider = 8; + string model = 9; + int64 input_tokens = 10; + int64 output_tokens = 11; + int64 cached_tokens = 12; + google.protobuf.Timestamp at = 13; +} +message RecordUsageRequest { UsageRecord record = 1; } +message RecordUsageResponse {}