Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576package daemon
import ( "albedo/cli/internal/daemon/protocol" "context" "errors" "io" "net/http" "strings")
// HoldQueuedInput holds one of your waiting messages while you edit it and// returns the lease in milliseconds. Renew the hold before it lapses.func (c *ChatClient) HoldQueuedInput(ctx context.Context, id string) (int64, error) { var result struct { LeaseMs int64 `json:"lease_ms"` } err := executeMutation(ctx, c.conn, operation{Name: "hold queued message", Body: struct{}{}, Policy: noRecovery, BuildRequest: func(base string, body io.Reader) (*http.Request, error) { return protocol.NewHoldInputRequestWithBody(base, c.agentID, id, "application/json", body) }}, []int{200}, func(data []byte, _ int) error { if err := decodeRequired(data, &result); err != nil { return err } if result.LeaseMs <= 0 { return fieldError("lease_ms") } return nil }) return result.LeaseMs, err}
// ReleaseQueuedInput lets a held message be read as it was.func (c *ChatClient) ReleaseQueuedInput(ctx context.Context, id string) error { return executeMutation(ctx, c.conn, operation{Name: "release queued message", Policy: noRecovery, BuildRequest: func(base string, _ io.Reader) (*http.Request, error) { return protocol.NewReleaseInputRequest(base, c.agentID, id) }}, []int{204}, func(_ []byte, _ int) error { return nil })}
// EditQueuedInput replaces a waiting message in place with the message sent.func (c *ChatClient) EditQueuedInput(ctx context.Context, id, text string, images []ImageAttachment, pastes []string) error { uploaded := make([]protocol.ImageUpload, len(images)) for i, image := range images { uploaded[i] = protocol.ImageUpload{MimeType: string(image.MimeType), Data: image.Data} } body := protocol.MessageInputRequest{Kind: "message", Text: text, Images: uploaded, Pastes: pastes} var result struct { Input protocol.Input `json:"input"` } return executeMutation(ctx, c.conn, operation{Name: "edit queued message", Body: body, Policy: noRecovery, BuildRequest: func(base string, reader io.Reader) (*http.Request, error) { return protocol.NewEditInputRequestWithBody(base, c.agentID, id, "application/json", reader) }}, []int{200}, func(data []byte, _ int) error { if err := decodeRequired(data, &result); err != nil { return err } if result.Input.ID != id { return fieldError("input identity") } return validInput(result.Input) })}
// CancelQueuedInput takes a waiting message out of the queue without touching// the running turn. A message the turn already read fails with// queue_item_not_found.func (c *ChatClient) CancelQueuedInput(ctx context.Context, id string) error { return executeMutation(ctx, c.conn, operation{Name: "cancel queued message", Policy: noRecovery, BuildRequest: func(base string, _ io.Reader) (*http.Request, error) { return protocol.NewDropQueuedRequestWithBody(base, c.agentID, id, "application/json", strings.NewReader("{}")) }}, []int{200}, func(_ []byte, _ int) error { return nil })}
// IsAPICode reports whether err is a daemon refusal with the given code.func IsAPICode(err error, code string) bool { api, ok := errors.AsType[*APIError](err) return ok && api.Code == code}