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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
use std::collections::HashMap;
use serde_json::Value;
use url::Url;
use crate::client::{DEFAULT_SEARCH_LIMIT, HonchoParams};
use crate::error::Result;
use crate::session::PeerSpec;
use crate::types::dream::QueueStatus;
use crate::types::pagination::validate_pagination;
use crate::types::peer::Peer as PeerResponse;
use crate::types::session::SessionResponse;
use crate::types::workspace::WorkspaceConfiguration;
use super::Peer as BlockingPeer;
use super::Session as BlockingSession;
use super::iter::collect_pages;
use super::runtime::block_on;
/// Synchronous wrapper around [`crate::Honcho`].
#[derive(Clone)]
pub struct Honcho {
inner: crate::Honcho,
}
impl std::fmt::Debug for Honcho {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Honcho")
.field("workspace_id", &self.inner.workspace_id())
.field("base_url", &self.inner.base_url().as_str())
.finish()
}
}
#[bon::bon]
impl Honcho {
/// Create a blocking client pointed at `base_url` for `workspace_id`.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "my-workspace")?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn new(base_url: &str, workspace_id: &str) -> Result<Self> {
let inner = crate::Honcho::new(base_url, workspace_id)?;
Ok(Self { inner })
}
/// Returns a builder for [`HonchoParams`].
///
/// # Examples
///
/// ```no_run
/// let params = honcho_ai::blocking::Honcho::builder()
/// .base_url("http://localhost:8000".to_owned())
/// .workspace_id("my-workspace".to_owned())
/// .build();
/// let client = honcho_ai::blocking::Honcho::from_params(params)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn builder() -> crate::client::HonchoParamsBuilder {
crate::Honcho::builder()
}
/// Build from explicit params.
///
/// # Examples
///
/// ```no_run
/// let params = honcho_ai::blocking::Honcho::builder()
/// .base_url("http://localhost:8000".to_owned())
/// .build();
/// let client = honcho_ai::blocking::Honcho::from_params(params)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn from_params(params: HonchoParams) -> Result<Self> {
let inner = crate::Honcho::from_params(params)?;
Ok(Self { inner })
}
/// Eagerly ensure the workspace exists on the server.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// client.force_ensure()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn force_ensure(&self) -> Result<()> {
block_on(self.inner.force_ensure())?
}
/// Workspace ID this client is scoped to.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// assert_eq!(client.workspace_id(), "ws-1");
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
#[must_use]
pub fn workspace_id(&self) -> &str {
self.inner.workspace_id()
}
/// Resolved base URL.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// assert_eq!(client.base_url().as_str(), "http://localhost:8000/");
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
#[must_use]
pub fn base_url(&self) -> &Url {
self.inner.base_url()
}
/// Get or create a peer by ID.
///
/// Returns a builder; finish with `.build()`.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let peer = client.peer("alice").build()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
#[builder(finish_fn = build, on(String, into))]
pub fn peer(
&self,
#[builder(start_fn)] id: String,
metadata: Option<HashMap<String, Value>>,
#[builder(name = config)] configuration: Option<HashMap<String, Value>>,
) -> Result<BlockingPeer> {
block_on(
self.inner
.peer(id)
.maybe_metadata(metadata)
.maybe_config(configuration)
.build(),
)?
.map(BlockingPeer::new)
}
/// Get or create a session by ID.
///
/// Returns a builder; finish with `.build()`.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let session = client.session("s-42").build()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
#[builder(finish_fn = build, on(String, into))]
pub fn session(
&self,
#[builder(start_fn)] id: String,
metadata: Option<HashMap<String, Value>>,
peers: Option<Vec<PeerSpec>>,
configuration: Option<crate::SessionConfiguration>,
) -> Result<BlockingSession> {
block_on(
self.inner
.session(id)
.maybe_metadata(metadata)
.maybe_peers(peers)
.maybe_configuration(configuration)
.build(),
)?
.map(BlockingSession::new)
}
/// Search messages across the workspace.
///
/// Returns a builder; finish with `.build()`. `limit` defaults to 10.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let results = client.search("important topic").build()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
#[builder(finish_fn = build, on(String, into))]
pub fn search(
&self,
#[builder(start_fn)] query: String,
#[builder(default = DEFAULT_SEARCH_LIMIT)] limit: u32,
filters: Option<HashMap<String, Value>>,
) -> Result<Vec<crate::Message>> {
block_on(
self.inner
.search(query)
.limit(limit)
.maybe_filters(filters)
.build(),
)?
}
/// Refresh workspace state.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// client.refresh()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn refresh(&self) -> Result<()> {
block_on(self.inner.refresh())?
}
/// Get queue processing status.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let status = client.queue_status(None, None, None)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn queue_status(
&self,
observer_id: Option<&str>,
sender_id: Option<&str>,
session_id: Option<&str>,
) -> Result<QueueStatus> {
block_on(self.inner.queue_status(observer_id, sender_id, session_id))?
}
/// Schedule a dream task for memory consolidation.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// client.schedule_dream("alice", None, None)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn schedule_dream(
&self,
observer: &str,
session_id: Option<&str>,
observed_peer: Option<&str>,
) -> Result<()> {
block_on(
self.inner
.schedule_dream(observer, session_id, observed_peer),
)?
}
/// Delete a workspace by ID.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// client.delete_workspace("old-ws")?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
///
/// # Warning
///
/// Deleting the client's own workspace leaves this client pointing at a
/// workspace ID that no longer exists on the server. The next lazy
/// [`ensure_workspace`](Self::force_ensure) — triggered automatically by
/// most other methods — will silently recreate an **empty** workspace with
/// the same ID, so the deleted data is gone but the workspace reappears.
/// Prefer a dedicated, short-lived client for destructive deletion.
pub fn delete_workspace(&self, id: &str) -> Result<()> {
block_on(self.inner.delete_workspace(id))?
}
/// Fetch workspace metadata.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let metadata = client.get_metadata()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn get_metadata(&self) -> Result<HashMap<String, Value>> {
block_on(self.inner.get_metadata())?
}
/// Set workspace metadata.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let mut metadata = std::collections::HashMap::new();
/// metadata.insert("team".into(), "platform".into());
/// client.set_metadata(metadata)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn set_metadata(&self, metadata: HashMap<String, Value>) -> Result<()> {
block_on(self.inner.set_metadata(metadata))?
}
/// Fetch workspace configuration as a typed [`WorkspaceConfiguration`].
///
/// # Examples
///
/// ```ignore
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let config = client.get_configuration()?;
/// if let Some(reasoning) = &config.reasoning {
/// println!("reasoning enabled: {:?}", reasoning.enabled);
/// }
/// ```
pub fn get_configuration(&self) -> Result<WorkspaceConfiguration> {
block_on(self.inner.get_configuration())?
}
/// Set workspace configuration from a typed [`WorkspaceConfiguration`].
///
/// # Examples
///
/// ```no_run
/// use honcho_ai::types::common::ReasoningConfiguration;
/// use honcho_ai::types::workspace::WorkspaceConfiguration;
///
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
///
/// // Both types are `#[non_exhaustive]`, so build from `Default` and set
/// // fields instead of using a struct literal / functional-update syntax.
/// let mut reasoning = ReasoningConfiguration::default();
/// reasoning.enabled = Some(true);
///
/// let mut config = WorkspaceConfiguration::default();
/// config.reasoning = Some(reasoning);
///
/// client.set_configuration(&config)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn set_configuration(&self, config: &WorkspaceConfiguration) -> Result<()> {
block_on(self.inner.set_configuration(config))?
}
/// Fetch workspace configuration as a raw JSON map.
///
/// Prefer [`get_configuration`](Self::get_configuration) for typed access.
/// Use this when the server returns fields not yet represented in
/// [`WorkspaceConfiguration`].
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let raw = client.get_configuration_raw()?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn get_configuration_raw(&self) -> Result<HashMap<String, Value>> {
block_on(self.inner.get_configuration_raw())?
}
/// Set workspace configuration from a raw JSON map.
///
/// Prefer [`set_configuration`](Self::set_configuration) for typed access.
/// Use this when you need to send fields not yet represented in
/// [`WorkspaceConfiguration`].
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let mut raw = std::collections::HashMap::new();
/// raw.insert("custom".into(), "value".into());
/// client.set_configuration_raw(raw)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn set_configuration_raw(&self, configuration: HashMap<String, Value>) -> Result<()> {
block_on(self.inner.set_configuration_raw(configuration))?
}
/// List all peers in the workspace, collecting across pages.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let peers = client.peers()?;
/// for peer in &peers {
/// println!("{}", peer.id);
/// }
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn peers(&self) -> Result<Vec<PeerResponse>> {
collect_pages(self.inner.peers())
}
/// List peers with filters. Returns a single paginated result.
///
/// `page` is 1-based and `size` must be in `1..=100`; both are validated
/// client-side before any network request and a violation returns
/// [`HonchoError::Validation`](crate::error::HonchoError::Validation).
///
/// Mirrors the async
/// [`Honcho::peers_with_filters`](crate::Honcho::peers_with_filters): it
/// returns the same single [`Page`](crate::types::pagination::Page) for the
/// requested `page`/`size`, not a collected `Vec`.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let mut filters = std::collections::HashMap::new();
/// filters.insert("role".into(), "admin".into());
/// let page = client.peers_with_filters(filters, 1, 10, false)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn peers_with_filters(
&self,
filters: HashMap<String, Value>,
page: u64,
size: u64,
reverse: bool,
) -> Result<crate::types::pagination::Page<PeerResponse>> {
// Validate before entering the runtime so an out-of-range `page`/`size`
// fails fast with a `Validation` error instead of first triggering a
// lazy `ensure_workspace` network round-trip inside the async client.
validate_pagination(page, size)?;
block_on(self.inner.peers_with_filters(filters, page, size, reverse))?
}
/// List all sessions in the workspace, collecting across pages.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let sessions = client.sessions()?;
/// for session in &sessions {
/// println!("{}", session.id);
/// }
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn sessions(&self) -> Result<Vec<SessionResponse>> {
collect_pages(self.inner.sessions())
}
/// List sessions with filters. Returns a single paginated result.
///
/// `page` is 1-based and `size` must be in `1..=100`; both are validated
/// client-side before any network request and a violation returns
/// [`HonchoError::Validation`](crate::error::HonchoError::Validation).
///
/// Mirrors the async
/// [`Honcho::sessions_with_filters`](crate::Honcho::sessions_with_filters):
/// it returns the same single [`Page`](crate::types::pagination::Page) for
/// the requested `page`/`size`, not a collected `Vec`.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let mut filters = std::collections::HashMap::new();
/// filters.insert("is_active".into(), true.into());
/// let page = client.sessions_with_filters(filters, 1, 10, false)?;
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn sessions_with_filters(
&self,
filters: HashMap<String, Value>,
page: u64,
size: u64,
reverse: bool,
) -> Result<crate::types::pagination::Page<SessionResponse>> {
// Validate before entering the runtime so an out-of-range `page`/`size`
// fails fast with a `Validation` error instead of first triggering a
// lazy `ensure_workspace` network round-trip inside the async client.
validate_pagination(page, size)?;
block_on(
self.inner
.sessions_with_filters(filters, page, size, reverse),
)?
}
/// List all workspace IDs, collecting across pages.
///
/// # Examples
///
/// ```no_run
/// let client = honcho_ai::blocking::Honcho::new("http://localhost:8000", "ws-1")?;
/// let workspaces = client.workspaces()?;
/// for id in &workspaces {
/// println!("{id}");
/// }
/// # Ok::<(), honcho_ai::error::HonchoError>(())
/// ```
pub fn workspaces(&self) -> Result<Vec<String>> {
collect_pages(self.inner.workspaces())
}
}