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
2 changes: 1 addition & 1 deletion apps/customer-portal/backend/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ERR_LIMIT_OFFSET_INVALID = "Limit must be between 1 and 50. Offset must be
const ERR_MSG_UNAUTHORIZED_ACCESS = "You're not authorized to access this service. Please sign in again. " +
"If the issue continues, contact support.";
const ERR_MSG_CASES_STATISTICS = "Failed to retrieve project case statistics.";
const ERR_MSG_CHATS_STATISTICS = "Failed to retrieve project chat statistics.";
const ERR_MSG_CONVERSATION_STATISTICS = "Failed to retrieve project conversation statistics.";

// Default Pagination Values
public const int DEFAULT_OFFSET = 0;
Expand Down
19 changes: 11 additions & 8 deletions apps/customer-portal/backend/modules/ai_chat_agent/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type ClientCredentialsOauth2Config record {|
string[] scopes = [];
|};

public enum Role {
USER = "user",
ASSISTANT = "assistant"
};

# Case classification payload.
public type CaseClassificationPayload record {|
# Chat history
Expand Down Expand Up @@ -92,6 +97,8 @@ public type ConversationPayload record {|
string region = "";
# Support tier (optional context for recommendations)
string tier = "";
# True if this is the first message that starts the conversation thread
boolean isFirstMessage;
json...;
|};

Expand Down Expand Up @@ -152,7 +159,7 @@ public type Action record {|
|};

# Recommendation item.
public type RecommendationItem record {|
public type RecommendationItem record {|
# Article title
string title;
# Article ID
Expand All @@ -163,7 +170,7 @@ public type RecommendationItem record {|
|};

# Recommendation response.
public type RecommendationResponse record {|
public type RecommendationResponse record {|
# Original query (shortDescription from classification)
string query;
# Top matching articles
Expand Down Expand Up @@ -219,9 +226,6 @@ public type ConversationListResponse record {|
json...;
|};

# Supported chat message roles.
public type Role "user"|"assistant";

# Single chat message for UI rendering.
public type Message record {|
# Message role: 'user' or 'assistant'
Expand Down Expand Up @@ -258,7 +262,7 @@ public type ChatHistoryResponse record {|
|};

# Conversation data for recommendations.
public type ConversationData record {|
public type ConversationData record {|
# Chat history as a string
string chatHistory;
# Environment products
Expand All @@ -271,10 +275,9 @@ public type ConversationData record {|
|};

# Recommendation request.
public type RecommendationRequest record {|
public type RecommendationRequest record {|
# Chat history
Message[] chatHistory;
# Customer question or issue description
ConversationData conversationData;
json...;
|};
29 changes: 6 additions & 23 deletions apps/customer-portal/backend/modules/ai_chat_agent/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,27 @@
// specific language governing permissions and limitations
// under the License.

# Build a recommendation request from a single user/assistant exchange and fetch recommendations.
# Build a recommendation request from a single user/assistant and fetch recommendations.
#
# + userMessage - User's message
# + assistantMessage - Assistant's response
# + envProducts - Environment products context
# + region - Customer region
# + tier - Support tier
# + return - Recommendation response or error
public isolated function getRecommendationsForExchange(
string userMessage,
string assistantMessage,
map<string[]> envProducts,
string region,
string tier
) returns RecommendationResponse|error {
Message user = {
role: "user",
content: userMessage,
timestamp: ""
};
Message assistant = {
role: "assistant",
content: assistantMessage,
timestamp: ""
};
public isolated function getRecommendations(string userMessage, string assistantMessage,
map<string[]> envProducts, string region, string tier) returns RecommendationResponse|error {

Message user = {role: USER, content: userMessage, timestamp: ""};
Message assistant = {role: ASSISTANT, content: assistantMessage, timestamp: ""};
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
ConversationData conversationData = {
chatHistory: string `${user.role}: ${user.content}\n${assistant.role}: ${assistant.content}`,
envProducts,
region,
tier
};

RecommendationRequest recommendationRequest = {
chatHistory: [user, assistant],
conversationData
};

RecommendationRequest recommendationRequest = {chatHistory: [user, assistant], conversationData};
return getRecommendation(recommendationRequest);
}

4 changes: 4 additions & 0 deletions apps/customer-portal/backend/modules/entity/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ public const CANCELED = 6;
const WAITING_ON_WSO2 = 1003;
const CLOSED = 3;
const REOPENED = 1006;

# Valid conversation state values
const ACTIVE = 2;
const RESOLVED = 3;
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
44 changes: 40 additions & 4 deletions apps/customer-portal/backend/modules/entity/entity.bal
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ public isolated function getCaseStatsForProject(string idToken, string id, strin
return csEntityClient->/projects/[id]/cases/stats.get(generateHeaders(idToken));
}

# Get chats statistics of a project by ID.
# Get conversation statistics of a project by ID.
#
# + idToken - ID token for authorization
# + id - Unique ID of the project
# + return - Project chats statistics or error
public isolated function getChatStatsForProject(string idToken, string id) returns ProjectChatStatsResponse|error {
return csEntityClient->/projects/[id]/chats/stats.get(generateHeaders(idToken));
# + return - Project conversations statistics or error
public isolated function getConversationStatsForProject(string idToken, string id)
returns ProjectConversationStatsResponse|error {

return csEntityClient->/projects/[id]/conversations/stats.get(generateHeaders(idToken));
}

# Get deployments statistics of a project by ID.
Expand Down Expand Up @@ -336,3 +338,37 @@ public isolated function searchTimeCards(string idToken, TimeCardSearchPayload p

return csEntityClient->/time\-cards/search.post(payload, generateHeaders(idToken));
}

# Search conversations of a project.
#
# + idToken - ID token for authorization
# + payload - Conversation search payload containing search criteria
# + return - Conversations response containing matching conversations or error
public isolated function searchConversations(string idToken, ConversationSearchPayload payload)
returns ConversationResponse|error {

return csEntityClient->/conversations/search.post(payload, generateHeaders(idToken));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Create a conversation.
#
# + idToken - ID token for authorization
# + payload - Conversation creation payload containing details of the conversation to be created
# + return - Conversation creation response containing details of the created conversation or error
public isolated function createConversation(string idToken, ConversationCreatePayload payload)
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
returns ConversationCreateResponse|error {

return csEntityClient->/conversations.post(payload, generateHeaders(idToken));
}

# Update a conversation.
#
# + idToken - ID token for authorization
# + conversationId - Unique ID of the conversation to be updated
# + payload - Conversation update payload containing details to be updated in the conversation
# + return - Conversation update response containing details of the updated conversation or error
public isolated function updateConversation(string idToken, string conversationId, ConversationUpdatePayload payload)
Comment thread
shayanmalinda marked this conversation as resolved.
Resolved
returns ConversationUpdateResponse|error {

return csEntityClient->/conversations/[conversationId].patch(payload, generateHeaders(idToken));
}
49 changes: 49 additions & 0 deletions apps/customer-portal/backend/modules/entity/enums.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

# Valid sort order values.
public enum SortOrder {
ASC = "asc",
DESC = "desc"
}

# Valid case sort field values.
public enum CaseSortField {
CREATED_ON = "createdOn",
UPDATED_ON = "updatedOn",
SEVERITY = "severity",
STATE = "state"
}

# Valid reference type values.
public enum ReferenceType {
CASE = "case",
CHANGE_REQUEST = "change_request",
CONVERSATION = "conversation",
DEPLOYMENT = "deployment"
}

# Valid comment type values.
public enum CommentType {
COMMENTS = "comments",
WORK_NOTE = "work_note"
}

# Valid conversation sort field values.
public enum ConversationSortField {
CHAT_CREATED_ON = "createdOn",
CHAT_UPDATED_ON = "updatedOn"
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
Loading