Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
24bc716
migrate to search index and enhance package metadata handling
VellummyilumVinoth Jan 30, 2026
7beba82
Merge pull request #636 from VellummyilumVinoth/migration
xlight05 Feb 2, 2026
23e49de
Migrate to New libraries API
VellummyilumVinoth Feb 5, 2026
ed970e1
Merge pull request #672 from VellummyilumVinoth/refactor-libraries-mi…
xlight05 Feb 6, 2026
4617487
Add initial copilot extension model
xlight05 Jan 29, 2026
f508412
Merge pull request #679 from xlight05/copilot-extensions
xlight05 Feb 6, 2026
5567136
Fix some issues and retrieve all libraries
VellummyilumVinoth Feb 11, 2026
72b8b9f
Merge pull request #681 from VellummyilumVinoth/external-libraries-se…
xlight05 Feb 11, 2026
91c502c
Fix Ballerina home
VellummyilumVinoth Feb 16, 2026
c6489fd
Merge pull request #699 from VellummyilumVinoth/fix-home-path
xlight05 Feb 16, 2026
9643641
Merge branch 'main' into copilot-library-unify
xlight05 Feb 16, 2026
4106d6f
Fix test failures
VellummyilumVinoth Feb 16, 2026
2c604b7
Merge branch 'main' into copilot-library-unify
xlight05 Feb 17, 2026
c3b9fce
Merge pull request #702 from VellummyilumVinoth/fix-test-failures
xlight05 Feb 17, 2026
b59ab52
Fix failing tests
xlight05 Feb 17, 2026
4b37ee9
Merge pull request #704 from xlight05/lib-unfify-test1
xlight05 Feb 17, 2026
c6b26a8
Fix test failures
xlight05 Feb 17, 2026
f373612
Merge remote-tracking branch 'upstream/main' into lib-unify-fix2
xlight05 Feb 17, 2026
0d1bcc4
Merge pull request #705 from xlight05/lib-unify-fix2
xlight05 Feb 17, 2026
4854729
Fix test resources
xlight05 Feb 17, 2026
13dbd3c
Merge pull request #706 from xlight05/lib-unify-fix4
xlight05 Feb 17, 2026
e1bb037
Address minor comments
xlight05 Feb 17, 2026
e9297ff
Merge remote-tracking branch 'upstream/main' into copilot-library-unify
xlight05 Feb 18, 2026
36dc6a8
Update search index
xlight05 Feb 18, 2026
d1e6b6a
Address review comments
xlight05 Feb 18, 2026
b0ccf86
Update search tests
xlight05 Feb 18, 2026
661ce9c
Remove old library db and fix tests
xlight05 Feb 18, 2026
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ build/

# macOS metadata files
.DS_Store
.claude
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"type": "CONNECTION",
"name": "tcpConnection",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.2.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.3.png",
"module": "tcp",
"children": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"type": "LISTENER",
"name": "rabbitmqListener",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.0.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.1.png",
"module": "rabbitmq",
"children": {}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "LISTENER",
"name": "rabbitmqListener",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.0.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.1.png",
"module": "rabbitmq",
"children": {}
}
Expand All @@ -42,7 +42,7 @@
"type": "SERVICE",
"name": "RabbitMQ Event Integration - \"queueName\"",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.0.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerinax_rabbitmq_3.3.1.png",
"module": "rabbitmq",
"children": {
"onMessage": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"type": "LISTENER",
"name": "tcpListener",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.2.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.3.png",
"module": "tcp",
"children": {}
}
Expand All @@ -117,7 +117,7 @@
"type": "SERVICE",
"name": "TCP Service",
"scope": "Global",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.2.png",
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_tcp_1.13.3.png",
"module": "tcp",
"children": {
"onConnect": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://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.
*/

package io.ballerina.flowmodelgenerator.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Utility class for loading custom instructions from resource files.
* Instructions are organized by package in the resources/copilot/instructions directory.
*
* <p>Directory structure:
* <pre>
* resources/copilot/instructions/
* └── {org}/
* └── {module}/
* ├── library.md → Library.instructions
* ├── service.md → GenericService.instructions
* └── test.md → Service.testGenerationInstruction
* </pre>
*
* @since 1.0.1
*/
public final class InstructionLoader {

private static final String INSTRUCTIONS_BASE_PATH = "/copilot/instructions";
private static final String LIBRARY_INSTRUCTION_FILE = "library.md";
private static final String SERVICE_INSTRUCTION_FILE = "service.md";
private static final String TEST_INSTRUCTION_FILE = "test.md";

private InstructionLoader() {
// Utility class, prevent instantiation
}

/**
* Loads the library instruction for a given package.
*
* @param packageName the full package name (e.g., "ballerina/http")
* @return Optional containing the instruction content, or empty if not found
*/
public static Optional<String> loadLibraryInstruction(String packageName) {
return loadInstruction(packageName, LIBRARY_INSTRUCTION_FILE);
}

/**
* Loads the service instruction for a given package.
*
* @param packageName the full package name (e.g., "ballerina/http")
* @return Optional containing the instruction content, or empty if not found
*/
public static Optional<String> loadServiceInstruction(String packageName) {
return loadInstruction(packageName, SERVICE_INSTRUCTION_FILE);
}

/**
* Loads the test generation instruction for a given package.
*
* @param packageName the full package name (e.g., "ballerina/http")
* @return Optional containing the instruction content, or empty if not found
*/
public static Optional<String> loadTestInstruction(String packageName) {
return loadInstruction(packageName, TEST_INSTRUCTION_FILE);
}

/**
* Loads an instruction file from the resources.
*
* @param packageName the full package name (e.g., "ballerina/http")
* @param fileName the instruction file name (e.g., "library.md")
* @return Optional containing the instruction content, or empty if not found
*/
private static Optional<String> loadInstruction(String packageName, String fileName) {
String resourcePath = buildResourcePath(packageName, fileName);
try (InputStream inputStream = InstructionLoader.class.getResourceAsStream(resourcePath)) {
if (inputStream == null) {
return Optional.empty();
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
String content = reader.lines().collect(Collectors.joining("\n"));
return content.isEmpty() ? Optional.empty() : Optional.of(content);
}
} catch (IOException e) {
return Optional.empty();
}
}

/**
* Builds the resource path for an instruction file.
*
* @param packageName the full package name (e.g., "ballerina/http")
* @param fileName the instruction file name
* @return the full resource path
*/
private static String buildResourcePath(String packageName, String fileName) {
// Package name format: "org/module" (e.g., "ballerina/http")
// Resource path: /copilot/instructions/org/module/filename.md
return INSTRUCTIONS_BASE_PATH + "/" + packageName + "/" + fileName;
}

/**
* Checks if any instruction exists for a given package.
*
* @param packageName the full package name
* @return true if at least one instruction file exists
*/
public static boolean hasAnyInstruction(String packageName) {
return loadLibraryInstruction(packageName).isPresent() ||
loadServiceInstruction(packageName).isPresent() ||
loadTestInstruction(packageName).isPresent();
}
}
Loading
Loading