Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions c/csrc/include/longbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -1915,10 +1915,22 @@ typedef struct lb_chat_started_payload_t {
* Conversation identifier
*/
const char *chat_uid;
/**
* Numeric conversation identifier
*/
int64_t chat_id;
/**
* Message ID of this round
*/
const char *message_id;
/**
* Error code; empty when absent
*/
const char *error;
/**
* Error message; empty when absent
*/
const char *error_message;
} lb_chat_started_payload_t;

/**
Expand Down Expand Up @@ -2096,6 +2108,18 @@ typedef struct lb_reference_t {
* Reference index
*/
int32_t index;
/**
* Original reference index as provided by the source
*/
int32_t original_index;
/**
* Reference type (wire field `type`)
*/
const char *ref_type;
/**
* Reference identifier
*/
const char *id;
/**
* Reference title
*/
Expand All @@ -2104,6 +2128,10 @@ typedef struct lb_reference_t {
* Reference URL
*/
const char *url;
/**
* Full nested reference payload, as a JSON string; empty when absent
*/
const char *content_json;
} lb_reference_t;

/**
Expand Down
61 changes: 59 additions & 2 deletions c/src/agent_context/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,53 @@ pub struct CGetAgentsOptions {
pub struct CReference {
/// Reference index
pub index: i32,
/// Original reference index as provided by the source
pub original_index: i32,
/// Reference type (wire field `type`)
pub ref_type: *const c_char,
/// Reference identifier
pub id: *const c_char,
/// Reference title
pub title: *const c_char,
/// Reference URL
pub url: *const c_char,
/// Full nested reference payload, as a JSON string; empty when absent
pub content_json: *const c_char,
}

#[derive(Debug)]
pub(crate) struct CReferenceOwned {
index: i32,
original_index: i32,
ref_type: CString,
id: CString,
title: CString,
url: CString,
content_json: CString,
}

impl From<Reference> for CReferenceOwned {
fn from(v: Reference) -> Self {
let Reference { index, title, url } = v;
let Reference {
index,
original_index,
ref_type,
id,
title,
url,
content,
} = v;
Self {
index,
original_index,
ref_type: ref_type.into(),
id: id.into(),
title: title.into(),
url: url.into(),
content_json: content
.map(|v| serde_json::to_string(&v).unwrap_or_default())
.unwrap_or_default()
.into(),
}
}
}
Expand All @@ -281,11 +308,23 @@ impl ToFFI for CReferenceOwned {
type FFIType = CReference;

fn to_ffi_type(&self) -> Self::FFIType {
let CReferenceOwned { index, title, url } = self;
let CReferenceOwned {
index,
original_index,
ref_type,
id,
title,
url,
content_json,
} = self;
CReference {
index: *index,
original_index: *original_index,
ref_type: ref_type.to_ffi_type(),
id: id.to_ffi_type(),
title: title.to_ffi_type(),
url: url.to_ffi_type(),
content_json: content_json.to_ffi_type(),
}
}
}
Expand Down Expand Up @@ -593,25 +632,40 @@ impl ToFFI for CConversationResponseOwned {
pub struct CChatStartedPayload {
/// Conversation identifier
pub chat_uid: *const c_char,
/// Numeric conversation identifier
pub chat_id: i64,
/// Message ID of this round
pub message_id: *const c_char,
/// Error code; empty when absent
pub error: *const c_char,
/// Error message; empty when absent
pub error_message: *const c_char,
}

#[derive(Debug)]
pub(crate) struct CChatStartedPayloadOwned {
chat_uid: CString,
chat_id: i64,
message_id: CString,
error: CString,
error_message: CString,
}

impl From<ChatStartedPayload> for CChatStartedPayloadOwned {
fn from(v: ChatStartedPayload) -> Self {
let ChatStartedPayload {
chat_uid,
chat_id,
message_id,
error,
error_message,
} = v;
Self {
chat_uid: chat_uid.into(),
chat_id,
message_id: message_id.into(),
error: error.into(),
error_message: error_message.into(),
}
}
}
Expand All @@ -622,7 +676,10 @@ impl ToFFI for CChatStartedPayloadOwned {
fn to_ffi_type(&self) -> Self::FFIType {
CChatStartedPayload {
chat_uid: self.chat_uid.to_ffi_type(),
chat_id: self.chat_id,
message_id: self.message_id.to_ffi_type(),
error: self.error.to_ffi_type(),
error_message: self.error_message.to_ffi_type(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
public final class ChatStartedEvent extends ConversationStreamEvent {
private String chatUid;
private String messageId;
private long chatId;
private String error;
private String errorMessage;

/**
* Returns the conversation identifier.
Expand All @@ -25,8 +28,36 @@ public String getMessageId() {
return messageId;
}

/**
* Returns the ID of the owning conversation.
*
* @return owning conversation ID
*/
public long getChatId() {
return chatId;
}

/**
* Returns the error detail; empty at start.
*
* @return error detail
*/
public String getError() {
return error;
}

/**
* Returns the user-facing error message; empty at start.
*
* @return user-facing error message
*/
public String getErrorMessage() {
return errorMessage;
}

@Override
public String toString() {
return "ChatStartedEvent [chatUid=" + chatUid + ", messageId=" + messageId + "]";
return "ChatStartedEvent [chatUid=" + chatUid + ", messageId=" + messageId + ", chatId=" + chatId
+ ", error=" + error + ", errorMessage=" + errorMessage + "]";
}
}
52 changes: 49 additions & 3 deletions java/javasrc/src/main/java/com/longbridge/agent/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/
public class Reference {
private int index;
private int originalIndex;
private String refType;
private String id;
private String title;
private String url;
private String content;

/**
* Returns the reference index.
Expand All @@ -18,7 +22,35 @@ public int getIndex() {
}

/**
* Returns the reference title.
* Returns the original index in the source list, before any reranking.
*
* @return original reference index
*/
public int getOriginalIndex() {
return originalIndex;
}

/**
* Returns the reference kind, e.g. {@code "NewsArticle"}.
*
* @return reference kind
*/
public String getRefType() {
return refType;
}

/**
* Returns the reference id.
*
* @return reference id
*/
public String getId() {
return id;
}

/**
* Returns the reference title. Often empty at the top level — the
* human-readable title usually lives in {@link #getContent}.
*
* @return reference title
*/
Expand All @@ -27,16 +59,30 @@ public String getTitle() {
}

/**
* Returns the reference URL.
* Returns the reference URL. Often empty at the top level — see
* {@link #getContent}.
*
* @return reference URL
*/
public String getUrl() {
return url;
}

/**
* Returns the full reference payload as sent by the server ({@code
* source}, {@code description}, {@code published_at}, {@code
* source_url}, {@code source_logo}, {@code kind}, …), as JSON text. Kept
* as raw JSON because the field set varies by {@link #getRefType}.
*
* @return full reference payload (JSON text), or {@code null}
*/
public String getContent() {
return content;
}

@Override
public String toString() {
return "Reference [index=" + index + ", title=" + title + ", url=" + url + "]";
return "Reference [index=" + index + ", originalIndex=" + originalIndex + ", refType=" + refType + ", id="
+ id + ", title=" + title + ", url=" + url + ", content=" + content + "]";
}
}
4 changes: 2 additions & 2 deletions java/src/types/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,7 @@ impl_java_class!(
impl_java_class!(
"com/longbridge/agent/Reference",
longbridge::agent::Reference,
[index, title, url]
[index, original_index, ref_type, id, title, url, content]
);

impl_java_class!(
Expand Down Expand Up @@ -3000,7 +3000,7 @@ impl_java_class!(
impl_java_class!(
"com/longbridge/agent/ChatStartedEvent",
longbridge::agent::ChatStartedPayload,
[chat_uid, message_id]
[chat_uid, message_id, chat_id, error, error_message]
);

// JNI-side view of `longbridge::agent::WorkflowStartedInputs`, the `inputs`
Expand Down
14 changes: 14 additions & 0 deletions nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,12 @@ export interface ChatStartedPayload {
chatUid: string
/** Message ID of this round */
messageId: string
/** ID of the owning conversation */
chatId: number
/** Error detail; empty at start */
error: string
/** User-facing error message; empty at start */
errorMessage: string
}

/**
Expand Down Expand Up @@ -5998,10 +6004,18 @@ export interface RecentBuybacks {
export interface Reference {
/** Reference index */
index: number
/** Original index in the source list, before any reranking */
originalIndex: number
/** Reference kind, e.g. `"NewsArticle"` */
refType: string
/** Reference id */
id: string
/** Reference title */
title: string
/** Reference URL */
url: string
/** Full reference payload as sent by the server; kept as raw JSON because the field set varies by reference `refType` */
content?: any
}

/** Parameters for replacing an attached order */
Expand Down
Loading
Loading