archie-core-8cda.5.4 requires /api/tasks/{id}/action to go through
ChatContract rather than a task-action service the UI process composes
itself. The contract could not carry the request: ApplyTaskAction's identity
is a scope, and the daemon's action service distinguishes a named identity
from a nil one, which is the authenticated operator acting across
identities. Sending "" would not have expressed it either -- that is a real
identity in a single-identity deployment (chatTaskProfiles).
ApplyOperatorTaskAction is that case, additively: a separate RPC, so buf
sees no cardinality change on a shipped field, and no request that can carry
both an identity and operator authority. ChatTaskActor's identity becomes a
pointer end to end, from the Gateway's local adapter through the NATS hop to
taskactions.Service.Apply, which has always taken one.
The conformance test now covers both scopes through the local adapter and
the gRPC hop; the chat tool test pins that a chat action is never unscoped.
No caller passes nil yet -- the dashboard handler switches over with the
rest of the cutover.
71 lines
2.6 KiB
Go
71 lines
2.6 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
|
)
|
|
|
|
// ChatContract is the conversational boundary consumed by channel frontends.
|
|
// Results are snapshots: callers must not rely on shared object identity.
|
|
type ChatContract interface { //nolint:interfacebloat // wire contract intentionally covers the complete Gateway facade
|
|
Snapshot(context.Context) (ChatSnapshot, error)
|
|
GetSession(context.Context, string) (SessionContext, bool, error)
|
|
RecentMessages(context.Context, string, int) ([]messaging.Message, error)
|
|
RecentTurns(context.Context, string, int) ([]TurnRecord, error)
|
|
Route(context.Context, Inbound) (ChatReply, error)
|
|
// Stream emits started, delta/tool/media, then done or error, in order.
|
|
// Callers must drain the stream or cancel the context. Cancellation closes it.
|
|
Stream(context.Context, Inbound) (<-chan ChatEvent, error)
|
|
Cancel(context.Context, string) (ChatCancellation, error)
|
|
SetPersona(context.Context, string, string) (bool, error)
|
|
ChatTaskActionContract
|
|
}
|
|
|
|
// ChatTaskActionContract is the operator task mutation capability exposed by
|
|
// the Gateway. It is separate so read/turn consumers do not need to model it.
|
|
type ChatTaskActionContract interface {
|
|
// ApplyTaskAction applies an action on behalf of a chat identity, which
|
|
// may only act on its own tasks.
|
|
ApplyTaskAction(context.Context, string, int64, taskstate.Action) (TaskActionResult, error)
|
|
// ApplyOperatorTaskAction applies an action on behalf of an authenticated
|
|
// dashboard operator, who acts across identities. It is a separate method
|
|
// rather than an empty identity because "" is a real identity in a
|
|
// single-identity deployment (see chatTaskProfiles in the daemon).
|
|
ApplyOperatorTaskAction(context.Context, int64, taskstate.Action) (TaskActionResult, error)
|
|
}
|
|
|
|
type ChatSnapshot struct {
|
|
Sessions []SessionContext
|
|
Models []string
|
|
ModelsByProvider map[string][]string
|
|
Providers []string
|
|
ActiveModel string
|
|
ActiveProvider string
|
|
Personas []string
|
|
ActivePersonas map[string]string
|
|
RestartAvailable bool
|
|
CancellationAvailable bool
|
|
PersonasAvailable bool
|
|
}
|
|
|
|
type ChatReply struct {
|
|
Text string
|
|
SessionID string
|
|
}
|
|
|
|
type ChatCancellation struct {
|
|
Cancelled bool
|
|
Dropped int
|
|
}
|
|
|
|
// ChatEvent contains values only; Text holds the error message for error events.
|
|
type ChatEvent struct {
|
|
Kind string
|
|
Text string
|
|
SessionID string
|
|
Tool ToolCallEvent
|
|
Media MediaEvent
|
|
}
|