-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.h
More file actions
97 lines (78 loc) · 3.5 KB
/
Copy pathsession.h
File metadata and controls
97 lines (78 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2026 Decart. SPDX-License-Identifier: MIT
#pragma once
#include <chrono>
#include <memory>
#include <optional>
#include <string>
#include "decart/realtime/types.h"
namespace decart {
namespace detail {
struct SessionInternals; // grants the realtime orchestrator access to Impl
} // namespace detail
/// Combined update for `RealtimeSession::set` — change the prompt, the reference
/// image, or both in a single call. At least one of `prompt`/`image` must be set.
struct SetInput {
std::optional<std::string> prompt;
bool enhance = true;
std::optional<ImageInput> image;
};
/// Per-call options for image/prompt updates.
struct UpdateOptions {
/// Optional prompt to apply alongside an image update.
std::optional<std::string> prompt;
bool enhance = true;
/// How long to wait for the server acknowledgement before timing out.
std::chrono::milliseconds timeout{30000};
};
/// A live realtime session. Created by `RealtimeClient::connect`.
///
/// Methods that talk to the server (`setPrompt`, `set`, `setImage`) block until
/// the server acknowledges and throw `decart::Exception` on failure or timeout.
/// The object is move-only; destroying it disconnects.
///
/// Thread-safety: control methods may be called from any thread. They must not
/// be called from inside a `ConnectOptions` callback.
class RealtimeSession {
public:
RealtimeSession();
~RealtimeSession();
RealtimeSession(const RealtimeSession&) = delete;
RealtimeSession& operator=(const RealtimeSession&) = delete;
RealtimeSession(RealtimeSession&&) noexcept;
RealtimeSession& operator=(RealtimeSession&&) noexcept;
/// Set the active text prompt. Blocks until acknowledged.
void setPrompt(const std::string& prompt, bool enhance = true);
/// Apply a prompt and/or reference image in one call. Blocks until acknowledged.
void set(const SetInput& input);
/// Set (or clear) the reference image. Pass `std::nullopt` to clear.
/// Blocks until acknowledged.
void setImage(const std::optional<ImageInput>& image, const UpdateOptions& options = {});
/// Stop transmitting video to the model without tearing down the connection.
/// The published track stays live and resumes with `unmute()` — no
/// renegotiation. Use this for connection pre-warming: connect (optionally with
/// `ConnectOptions::startMuted`), hold the authenticated session idle at no
/// generation cost, then `unmute()` and start capturing frames when the user is
/// ready. Local operation; `@throws decart::Exception` if the session has
/// disconnected.
void mute();
/// Resume transmitting to the model after `mute()` (or after connecting with
/// `ConnectOptions::startMuted`). Once unmuted the track sends again —
/// including WebRTC keepalive frames — so generation, and billing, can begin
/// even before your first `captureFrame`. Unmute only when you are ready to go
/// live. `@throws decart::Exception` if the session has disconnected.
void unmute();
/// True while the session is connected (state `Connected` or `Generating`).
bool isConnected() const noexcept;
/// Current connection state.
ConnectionState connectionState() const noexcept;
/// Server session id, available once the session has started.
std::optional<std::string> sessionId() const;
/// Tear down the session. Idempotent. Safe to call from any thread except
/// from inside a session callback.
void disconnect();
private:
friend struct detail::SessionInternals;
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace decart