-
Notifications
You must be signed in to change notification settings - Fork 36
Migrate Copilot Libraries API & Add Keyword Search #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+60,743
−2,588
Merged
Changes from 8 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 7beba82
Merge pull request #636 from VellummyilumVinoth/migration
xlight05 23e49de
Migrate to New libraries API
VellummyilumVinoth ed970e1
Merge pull request #672 from VellummyilumVinoth/refactor-libraries-mi…
xlight05 4617487
Add initial copilot extension model
xlight05 f508412
Merge pull request #679 from xlight05/copilot-extensions
xlight05 5567136
Fix some issues and retrieve all libraries
VellummyilumVinoth 72b8b9f
Merge pull request #681 from VellummyilumVinoth/external-libraries-se…
xlight05 91c502c
Fix Ballerina home
VellummyilumVinoth c6489fd
Merge pull request #699 from VellummyilumVinoth/fix-home-path
xlight05 9643641
Merge branch 'main' into copilot-library-unify
xlight05 4106d6f
Fix test failures
VellummyilumVinoth 2c604b7
Merge branch 'main' into copilot-library-unify
xlight05 c3b9fce
Merge pull request #702 from VellummyilumVinoth/fix-test-failures
xlight05 b59ab52
Fix failing tests
xlight05 4b37ee9
Merge pull request #704 from xlight05/lib-unfify-test1
xlight05 c6b26a8
Fix test failures
xlight05 f373612
Merge remote-tracking branch 'upstream/main' into lib-unify-fix2
xlight05 0d1bcc4
Merge pull request #705 from xlight05/lib-unify-fix2
xlight05 4854729
Fix test resources
xlight05 13dbd3c
Merge pull request #706 from xlight05/lib-unify-fix4
xlight05 e1bb037
Address minor comments
xlight05 e9297ff
Merge remote-tracking branch 'upstream/main' into copilot-library-unify
xlight05 36dc6a8
Update search index
xlight05 d1e6b6a
Address review comments
xlight05 b0ccf86
Update search tests
xlight05 661ce9c
Remove old library db and fix tests
xlight05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/InstructionLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
xlight05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return loadLibraryInstruction(packageName).isPresent() || | ||
| loadServiceInstruction(packageName).isPresent() || | ||
| loadTestInstruction(packageName).isPresent(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.