Add name retrieval to bindings

This commit is contained in:
Jazz Turner-Baggs 2026-02-18 20:39:16 -08:00
parent 459ce2802c
commit a97ddfdbd0
No known key found for this signature in database
3 changed files with 17 additions and 0 deletions

View File

@ -53,6 +53,12 @@ pub fn create_context(name: String) -> repr_c::Box<ContextHandle> {
Box::new(ContextHandle(Context::new_with_name(name))).into()
}
/// Returns the friendly name of the context's identity
#[ffi_export]
pub fn get_friendly_name(ctx: &ContextHandle) -> repr_c::String {
ctx.0.get_friendly_name().to_string().into()
}
/// Destroys a conversation store and frees its memory
///
/// # Safety

View File

@ -99,6 +99,10 @@ type
## Returns: Opaque handle to the context. Must be freed with destroy_context()
proc create_context*(name: ReprCString): ContextHandle {.importc, dynlib: CONVERSATIONS_LIB.}
## Returns the friendly name of the context's identity
## The result must be freed by the caller (repr_c::String ownership transfers)
proc get_friendly_name*(ctx: ContextHandle): ReprCString {.importc, dynlib: CONVERSATIONS_LIB.}
## Destroys a context and frees its memory
## - handle must be a valid pointer from create_context()
## - handle must not be used after this call

View File

@ -20,6 +20,13 @@ proc newConversationsContext*(name: string): LibChat =
if result.handle.isNil:
raise newException(IOError, "Failed to create context")
## Get the friendly name of this context's installation
proc getInstallationName*(ctx: LibChat): string =
if ctx.handle == nil:
return ""
let name = get_friendly_name(ctx.handle)
result = $name
## Destroy the context and free resources
proc destroy*(ctx: var LibChat) =