Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6260d4f168 | ||
|
|
4206da92a6 | ||
|
|
4d6fbf1caa | ||
|
|
97ef7acec0 | ||
|
|
77189b6114 | ||
|
|
c32d315910 | ||
|
|
606ffd8275 | ||
|
|
601dba3fc4 | ||
|
|
00ab476a77 | ||
|
|
906079cbbb | ||
|
|
808d9c981c | ||
|
|
2b79c99dd7 | ||
|
|
77905ed3cd |
43
README.md
43
README.md
@@ -49,10 +49,10 @@ cd LocalAGI
|
|||||||
docker compose up
|
docker compose up
|
||||||
|
|
||||||
# NVIDIA GPU setup
|
# NVIDIA GPU setup
|
||||||
docker compose --profile nvidia up
|
docker compose -f docker-compose.nvidia.yaml up
|
||||||
|
|
||||||
# Intel GPU setup (for Intel Arc and integrated GPUs)
|
# Intel GPU setup (for Intel Arc and integrated GPUs)
|
||||||
docker compose --profile intel up
|
docker compose -f docker-compose.intel.yaml up
|
||||||
|
|
||||||
# Start with a specific model (see available models in models.localai.io, or localai.io to use any model in huggingface)
|
# Start with a specific model (see available models in models.localai.io, or localai.io to use any model in huggingface)
|
||||||
MODEL_NAME=gemma-3-12b-it docker compose up
|
MODEL_NAME=gemma-3-12b-it docker compose up
|
||||||
@@ -61,11 +61,40 @@ MODEL_NAME=gemma-3-12b-it docker compose up
|
|||||||
MODEL_NAME=gemma-3-12b-it \
|
MODEL_NAME=gemma-3-12b-it \
|
||||||
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
||||||
IMAGE_MODEL=flux.1-dev \
|
IMAGE_MODEL=flux.1-dev \
|
||||||
docker compose --profile nvidia up
|
docker compose -f docker-compose.nvidia.yaml up
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can access and manage your agents at [http://localhost:8080](http://localhost:8080)
|
Now you can access and manage your agents at [http://localhost:8080](http://localhost:8080)
|
||||||
|
|
||||||
|
## 📚🆕 Local Stack Family
|
||||||
|
|
||||||
|
🆕 LocalAI is now part of a comprehensive suite of AI tools designed to work together:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<a href="https://github.com/mudler/LocalAI">
|
||||||
|
<img src="https://raw.githubusercontent.com/mudler/LocalAI/refs/heads/master/core/http/static/logo_horizontal.png" width="300" alt="LocalAI Logo">
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<h3><a href="https://github.com/mudler/LocalAI">LocalAI</a></h3>
|
||||||
|
<p>LocalAI is the free, Open Source OpenAI alternative. LocalAI act as a drop-in replacement REST API that's compatible with OpenAI API specifications for local AI inferencing. Does not require GPU.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<a href="https://github.com/mudler/LocalRecall">
|
||||||
|
<img src="https://raw.githubusercontent.com/mudler/LocalRecall/refs/heads/main/static/localrecall_horizontal.png" width="300" alt="LocalRecall Logo">
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td width="50%" valign="top">
|
||||||
|
<h3><a href="https://github.com/mudler/LocalRecall">LocalRecall</a></h3>
|
||||||
|
<p>A REST-ful API and knowledge base management system that provides persistent memory and storage capabilities for AI agents.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
## 🖥️ Hardware Configurations
|
## 🖥️ Hardware Configurations
|
||||||
|
|
||||||
LocalAGI supports multiple hardware configurations through Docker Compose profiles:
|
LocalAGI supports multiple hardware configurations through Docker Compose profiles:
|
||||||
@@ -81,7 +110,7 @@ LocalAGI supports multiple hardware configurations through Docker Compose profil
|
|||||||
- Uses CUDA for acceleration
|
- Uses CUDA for acceleration
|
||||||
- Best for high-performance inference
|
- Best for high-performance inference
|
||||||
- Supports text, multimodal, and image generation models
|
- Supports text, multimodal, and image generation models
|
||||||
- Run with: `docker compose --profile nvidia up`
|
- Run with: `docker compose -f docker-compose.nvidia.yaml up`
|
||||||
- Default models:
|
- Default models:
|
||||||
- Text: `arcee-agent`
|
- Text: `arcee-agent`
|
||||||
- Multimodal: `minicpm-v-2_6`
|
- Multimodal: `minicpm-v-2_6`
|
||||||
@@ -97,7 +126,7 @@ LocalAGI supports multiple hardware configurations through Docker Compose profil
|
|||||||
- Uses SYCL for acceleration
|
- Uses SYCL for acceleration
|
||||||
- Best for Intel-based systems
|
- Best for Intel-based systems
|
||||||
- Supports text, multimodal, and image generation models
|
- Supports text, multimodal, and image generation models
|
||||||
- Run with: `docker compose --profile intel up`
|
- Run with: `docker compose -f docker-compose.intel.yaml up`
|
||||||
- Default models:
|
- Default models:
|
||||||
- Text: `arcee-agent`
|
- Text: `arcee-agent`
|
||||||
- Multimodal: `minicpm-v-2_6`
|
- Multimodal: `minicpm-v-2_6`
|
||||||
@@ -120,13 +149,13 @@ MODEL_NAME=gemma-3-12b-it docker compose up
|
|||||||
MODEL_NAME=gemma-3-12b-it \
|
MODEL_NAME=gemma-3-12b-it \
|
||||||
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
||||||
IMAGE_MODEL=flux.1-dev \
|
IMAGE_MODEL=flux.1-dev \
|
||||||
docker compose --profile nvidia up
|
docker compose -f docker-compose.nvidia.yaml up
|
||||||
|
|
||||||
# Intel GPU with custom models
|
# Intel GPU with custom models
|
||||||
MODEL_NAME=gemma-3-12b-it \
|
MODEL_NAME=gemma-3-12b-it \
|
||||||
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
MULTIMODAL_MODEL=minicpm-v-2_6 \
|
||||||
IMAGE_MODEL=sd-1.5-ggml \
|
IMAGE_MODEL=sd-1.5-ggml \
|
||||||
docker compose --profile intel up
|
docker compose -f docker-compose.intel.yaml up
|
||||||
```
|
```
|
||||||
|
|
||||||
If no models are specified, it will use the defaults:
|
If no models are specified, it will use the defaults:
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ var _ = Describe("Agent test", func() {
|
|||||||
defer agent.Stop()
|
defer agent.Stop()
|
||||||
|
|
||||||
result := agent.Ask(
|
result := agent.Ask(
|
||||||
types.WithText("plan a trip to San Francisco from Venice, Italy"),
|
types.WithText("Thoroughly plan a trip to San Francisco from Venice, Italy; check flight times, visa requirements and whether electrical items are allowed in cabin luggage."),
|
||||||
)
|
)
|
||||||
Expect(len(result.State)).To(BeNumerically(">", 1))
|
Expect(len(result.State)).To(BeNumerically(">", 1))
|
||||||
|
|
||||||
@@ -260,6 +260,7 @@ var _ = Describe("Agent test", func() {
|
|||||||
WithLLMAPIURL(apiURL),
|
WithLLMAPIURL(apiURL),
|
||||||
WithModel(testModel),
|
WithModel(testModel),
|
||||||
WithLLMAPIKey(apiKeyURL),
|
WithLLMAPIKey(apiKeyURL),
|
||||||
|
WithTimeout("10m"),
|
||||||
WithNewConversationSubscriber(func(m openai.ChatCompletionMessage) {
|
WithNewConversationSubscriber(func(m openai.ChatCompletionMessage) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
message = m
|
message = m
|
||||||
@@ -274,7 +275,7 @@ var _ = Describe("Agent test", func() {
|
|||||||
EnableStandaloneJob,
|
EnableStandaloneJob,
|
||||||
EnableHUD,
|
EnableHUD,
|
||||||
WithPeriodicRuns("1s"),
|
WithPeriodicRuns("1s"),
|
||||||
WithPermanentGoal("use the new_conversation tool"),
|
WithPermanentGoal("use the new_conversation tool to initiate a conversation with the user"),
|
||||||
// EnableStandaloneJob,
|
// EnableStandaloneJob,
|
||||||
// WithRandomIdentity(),
|
// WithRandomIdentity(),
|
||||||
)
|
)
|
||||||
|
|||||||
33
docker-compose.intel.yaml
Normal file
33
docker-compose.intel.yaml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
services:
|
||||||
|
localai:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localai
|
||||||
|
environment:
|
||||||
|
- LOCALAI_SINGLE_ACTIVE_BACKEND=true
|
||||||
|
- DEBUG=true
|
||||||
|
image: localai/localai:master-sycl-f32-ffmpeg-core
|
||||||
|
devices:
|
||||||
|
# On a system with integrated GPU and an Arc 770, this is the Arc 770
|
||||||
|
- /dev/dri/card1
|
||||||
|
- /dev/dri/renderD129
|
||||||
|
command:
|
||||||
|
- ${MODEL_NAME:-arcee-agent}
|
||||||
|
- ${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
||||||
|
- ${IMAGE_MODEL:-sd-1.5-ggml}
|
||||||
|
- granite-embedding-107m-multilingual
|
||||||
|
|
||||||
|
localrecall:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localrecall
|
||||||
|
|
||||||
|
localrecall-healthcheck:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localrecall-healthcheck
|
||||||
|
|
||||||
|
localagi:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localagi
|
||||||
31
docker-compose.nvidia.yaml
Normal file
31
docker-compose.nvidia.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
services:
|
||||||
|
localai:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localai
|
||||||
|
environment:
|
||||||
|
- LOCALAI_SINGLE_ACTIVE_BACKEND=true
|
||||||
|
- DEBUG=true
|
||||||
|
image: localai/localai:master-sycl-f32-ffmpeg-core
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
reservations:
|
||||||
|
devices:
|
||||||
|
- driver: nvidia
|
||||||
|
count: 1
|
||||||
|
capabilities: [gpu]
|
||||||
|
|
||||||
|
localrecall:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localrecall
|
||||||
|
|
||||||
|
localrecall-healthcheck:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localrecall-healthcheck
|
||||||
|
|
||||||
|
localagi:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: localagi
|
||||||
@@ -7,8 +7,9 @@ services:
|
|||||||
# Image list (dockerhub): https://hub.docker.com/r/localai/localai
|
# Image list (dockerhub): https://hub.docker.com/r/localai/localai
|
||||||
image: localai/localai:master-ffmpeg-core
|
image: localai/localai:master-ffmpeg-core
|
||||||
command:
|
command:
|
||||||
# - gemma-3-12b-it
|
|
||||||
- ${MODEL_NAME:-arcee-agent}
|
- ${MODEL_NAME:-arcee-agent}
|
||||||
|
- ${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
||||||
|
- ${IMAGE_MODEL:-flux.1-dev}
|
||||||
- granite-embedding-107m-multilingual
|
- granite-embedding-107m-multilingual
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8080/readyz"]
|
test: ["CMD", "curl", "-f", "http://localhost:8080/readyz"]
|
||||||
@@ -24,44 +25,6 @@ services:
|
|||||||
- ./volumes/models:/build/models:cached
|
- ./volumes/models:/build/models:cached
|
||||||
- ./volumes/images:/tmp/generated/images
|
- ./volumes/images:/tmp/generated/images
|
||||||
|
|
||||||
localai-nvidia:
|
|
||||||
profiles: ["nvidia"]
|
|
||||||
extends:
|
|
||||||
service: localai
|
|
||||||
environment:
|
|
||||||
- LOCALAI_SINGLE_ACTIVE_BACKEND=true
|
|
||||||
- DEBUG=true
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
reservations:
|
|
||||||
devices:
|
|
||||||
- driver: nvidia
|
|
||||||
count: 1
|
|
||||||
capabilities: [gpu]
|
|
||||||
command:
|
|
||||||
- ${MODEL_NAME:-arcee-agent}
|
|
||||||
- ${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
|
||||||
- ${IMAGE_MODEL:-flux.1-dev}
|
|
||||||
- granite-embedding-107m-multilingual
|
|
||||||
|
|
||||||
localai-intel:
|
|
||||||
profiles: ["intel"]
|
|
||||||
environment:
|
|
||||||
- LOCALAI_SINGLE_ACTIVE_BACKEND=true
|
|
||||||
- DEBUG=true
|
|
||||||
extends:
|
|
||||||
service: localai
|
|
||||||
image: localai/localai:master-sycl-f32-ffmpeg-core
|
|
||||||
devices:
|
|
||||||
# On a system with integrated GPU and an Arc 770, this is the Arc 770
|
|
||||||
- /dev/dri/card1
|
|
||||||
- /dev/dri/renderD129
|
|
||||||
command:
|
|
||||||
- ${MODEL_NAME:-arcee-agent}
|
|
||||||
- ${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
|
||||||
- ${IMAGE_MODEL:-sd-1.5-ggml}
|
|
||||||
- granite-embedding-107m-multilingual
|
|
||||||
|
|
||||||
localrecall:
|
localrecall:
|
||||||
image: quay.io/mudler/localrecall:main
|
image: quay.io/mudler/localrecall:main
|
||||||
ports:
|
ports:
|
||||||
@@ -97,6 +60,8 @@ services:
|
|||||||
#image: quay.io/mudler/localagi:master
|
#image: quay.io/mudler/localagi:master
|
||||||
environment:
|
environment:
|
||||||
- LOCALAGI_MODEL=${MODEL_NAME:-arcee-agent}
|
- LOCALAGI_MODEL=${MODEL_NAME:-arcee-agent}
|
||||||
|
- LOCALAGI_MULTIMODAL_MODEL=${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
||||||
|
- LOCALAGI_IMAGE_MODEL=${IMAGE_MODEL:-sd-1.5-ggml}
|
||||||
- LOCALAGI_LLM_API_URL=http://localai:8080
|
- LOCALAGI_LLM_API_URL=http://localai:8080
|
||||||
#- LOCALAGI_LLM_API_KEY=sk-1234567890
|
#- LOCALAGI_LLM_API_KEY=sk-1234567890
|
||||||
- LOCALAGI_LOCALRAG_URL=http://localrecall:8080
|
- LOCALAGI_LOCALRAG_URL=http://localrecall:8080
|
||||||
@@ -107,31 +72,3 @@ services:
|
|||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
volumes:
|
volumes:
|
||||||
- ./volumes/localagi/:/pool
|
- ./volumes/localagi/:/pool
|
||||||
|
|
||||||
localagi-nvidia:
|
|
||||||
profiles: ["nvidia"]
|
|
||||||
extends:
|
|
||||||
service: localagi
|
|
||||||
environment:
|
|
||||||
- LOCALAGI_MODEL=${MODEL_NAME:-arcee-agent}
|
|
||||||
- LOCALAGI_MULTIMODAL_MODEL=${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
|
||||||
- LOCALAGI_IMAGE_MODEL=${IMAGE_MODEL:-flux.1-dev}
|
|
||||||
- LOCALAGI_LLM_API_URL=http://localai:8080
|
|
||||||
- LOCALAGI_LOCALRAG_URL=http://localrecall:8080
|
|
||||||
- LOCALAGI_STATE_DIR=/pool
|
|
||||||
- LOCALAGI_TIMEOUT=5m
|
|
||||||
- LOCALAGI_ENABLE_CONVERSATIONS_LOGGING=false
|
|
||||||
|
|
||||||
localagi-intel:
|
|
||||||
profiles: ["intel"]
|
|
||||||
extends:
|
|
||||||
service: localagi
|
|
||||||
environment:
|
|
||||||
- LOCALAGI_MODEL=${MODEL_NAME:-arcee-agent}
|
|
||||||
- LOCALAGI_MULTIMODAL_MODEL=${MULTIMODAL_MODEL:-minicpm-v-2_6}
|
|
||||||
- LOCALAGI_IMAGE_MODEL=${IMAGE_MODEL:-sd-1.5-ggml}
|
|
||||||
- LOCALAGI_LLM_API_URL=http://localai:8080
|
|
||||||
- LOCALAGI_LOCALRAG_URL=http://localrecall:8080
|
|
||||||
- LOCALAGI_STATE_DIR=/pool
|
|
||||||
- LOCALAGI_TIMEOUT=5m
|
|
||||||
- LOCALAGI_ENABLE_CONVERSATIONS_LOGGING=false
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ const (
|
|||||||
ActionGithubPRReader = "github-pr-reader"
|
ActionGithubPRReader = "github-pr-reader"
|
||||||
ActionGithubPRCommenter = "github-pr-commenter"
|
ActionGithubPRCommenter = "github-pr-commenter"
|
||||||
ActionGithubPRReviewer = "github-pr-reviewer"
|
ActionGithubPRReviewer = "github-pr-reviewer"
|
||||||
|
ActionGithubPRCreator = "github-pr-creator"
|
||||||
|
ActionGithubGetAllContent = "github-get-all-repository-content"
|
||||||
ActionGithubREADME = "github-readme"
|
ActionGithubREADME = "github-readme"
|
||||||
ActionScraper = "scraper"
|
ActionScraper = "scraper"
|
||||||
ActionWikipedia = "wikipedia"
|
ActionWikipedia = "wikipedia"
|
||||||
@@ -49,12 +51,14 @@ var AvailableActions = []string{
|
|||||||
ActionGithubIssueCloser,
|
ActionGithubIssueCloser,
|
||||||
ActionGithubIssueSearcher,
|
ActionGithubIssueSearcher,
|
||||||
ActionGithubRepositoryGet,
|
ActionGithubRepositoryGet,
|
||||||
|
ActionGithubGetAllContent,
|
||||||
ActionGithubRepositoryCreateOrUpdate,
|
ActionGithubRepositoryCreateOrUpdate,
|
||||||
ActionGithubIssueReader,
|
ActionGithubIssueReader,
|
||||||
ActionGithubIssueCommenter,
|
ActionGithubIssueCommenter,
|
||||||
ActionGithubPRReader,
|
ActionGithubPRReader,
|
||||||
ActionGithubPRCommenter,
|
ActionGithubPRCommenter,
|
||||||
ActionGithubPRReviewer,
|
ActionGithubPRReviewer,
|
||||||
|
ActionGithubPRCreator,
|
||||||
ActionGithubREADME,
|
ActionGithubREADME,
|
||||||
ActionScraper,
|
ActionScraper,
|
||||||
ActionBrowse,
|
ActionBrowse,
|
||||||
@@ -118,6 +122,10 @@ func Action(name, agentName string, config map[string]string, pool *state.AgentP
|
|||||||
a = actions.NewGithubPRCommenter(config)
|
a = actions.NewGithubPRCommenter(config)
|
||||||
case ActionGithubPRReviewer:
|
case ActionGithubPRReviewer:
|
||||||
a = actions.NewGithubPRReviewer(config)
|
a = actions.NewGithubPRReviewer(config)
|
||||||
|
case ActionGithubPRCreator:
|
||||||
|
a = actions.NewGithubPRCreator(config)
|
||||||
|
case ActionGithubGetAllContent:
|
||||||
|
a = actions.NewGithubRepositoryGetAllContent(config)
|
||||||
case ActionGithubIssueCommenter:
|
case ActionGithubIssueCommenter:
|
||||||
a = actions.NewGithubIssueCommenter(config)
|
a = actions.NewGithubIssueCommenter(config)
|
||||||
case ActionGithubRepositoryGet:
|
case ActionGithubRepositoryGet:
|
||||||
@@ -201,6 +209,11 @@ func ActionsConfigMeta() []config.FieldGroup {
|
|||||||
Label: "GitHub Repository Get Content",
|
Label: "GitHub Repository Get Content",
|
||||||
Fields: actions.GithubRepositoryGetContentConfigMeta(),
|
Fields: actions.GithubRepositoryGetContentConfigMeta(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "github-get-all-repository-content",
|
||||||
|
Label: "GitHub Get All Repository Content",
|
||||||
|
Fields: actions.GithubRepositoryGetAllContentConfigMeta(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "github-repository-create-or-update-content",
|
Name: "github-repository-create-or-update-content",
|
||||||
Label: "GitHub Repository Create/Update Content",
|
Label: "GitHub Repository Create/Update Content",
|
||||||
@@ -226,6 +239,11 @@ func ActionsConfigMeta() []config.FieldGroup {
|
|||||||
Label: "GitHub PR Reviewer",
|
Label: "GitHub PR Reviewer",
|
||||||
Fields: actions.GithubPRReviewerConfigMeta(),
|
Fields: actions.GithubPRReviewerConfigMeta(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "github-pr-creator",
|
||||||
|
Label: "GitHub PR Creator",
|
||||||
|
Fields: actions.GithubPRCreatorConfigMeta(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "twitter-post",
|
Name: "twitter-post",
|
||||||
Label: "Twitter Post",
|
Label: "Twitter Post",
|
||||||
|
|||||||
315
services/actions/githubprcreator.go
Normal file
315
services/actions/githubprcreator.go
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
package actions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/go-github/v69/github"
|
||||||
|
"github.com/mudler/LocalAGI/core/types"
|
||||||
|
"github.com/mudler/LocalAGI/pkg/config"
|
||||||
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GithubPRCreator struct {
|
||||||
|
token, repository, owner, customActionName, defaultBranch string
|
||||||
|
client *github.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGithubPRCreator(config map[string]string) *GithubPRCreator {
|
||||||
|
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||||
|
|
||||||
|
return &GithubPRCreator{
|
||||||
|
client: client,
|
||||||
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
|
customActionName: config["customActionName"],
|
||||||
|
defaultBranch: config["defaultBranch"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubPRCreator) createOrUpdateBranch(ctx context.Context, branchName string) error {
|
||||||
|
// Get the latest commit SHA from the default branch
|
||||||
|
ref, _, err := g.client.Git.GetRef(ctx, g.owner, g.repository, "refs/heads/"+g.defaultBranch)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get reference: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to get the branch if it exists
|
||||||
|
_, resp, err := g.client.Git.GetRef(ctx, g.owner, g.repository, "refs/heads/"+branchName)
|
||||||
|
if err != nil {
|
||||||
|
// If branch doesn't exist, create it
|
||||||
|
if resp != nil && resp.StatusCode == 404 {
|
||||||
|
newRef := &github.Reference{
|
||||||
|
Ref: github.String("refs/heads/" + branchName),
|
||||||
|
Object: &github.GitObject{SHA: ref.Object.SHA},
|
||||||
|
}
|
||||||
|
_, _, err = g.client.Git.CreateRef(ctx, g.owner, g.repository, newRef)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create branch: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("failed to check branch existence: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Branch exists, update it to the latest commit
|
||||||
|
updateRef := &github.Reference{
|
||||||
|
Ref: github.String("refs/heads/" + branchName),
|
||||||
|
Object: &github.GitObject{SHA: ref.Object.SHA},
|
||||||
|
}
|
||||||
|
_, _, err = g.client.Git.UpdateRef(ctx, g.owner, g.repository, updateRef, true)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to update branch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubPRCreator) createOrUpdateFile(ctx context.Context, branch string, filePath string, content string, message string) error {
|
||||||
|
// Get the current file content if it exists
|
||||||
|
var sha *string
|
||||||
|
fileContent, _, _, err := g.client.Repositories.GetContents(ctx, g.owner, g.repository, filePath, &github.RepositoryContentGetOptions{
|
||||||
|
Ref: branch,
|
||||||
|
})
|
||||||
|
if err == nil && fileContent != nil {
|
||||||
|
sha = fileContent.SHA
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create or update the file
|
||||||
|
_, _, err = g.client.Repositories.CreateFile(ctx, g.owner, g.repository, filePath, &github.RepositoryContentFileOptions{
|
||||||
|
Message: &message,
|
||||||
|
Content: []byte(content),
|
||||||
|
Branch: &branch,
|
||||||
|
SHA: sha,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create/update file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubPRCreator) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||||
|
result := struct {
|
||||||
|
Repository string `json:"repository"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
Branch string `json:"branch"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
BaseBranch string `json:"base_branch"`
|
||||||
|
Files []struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
} `json:"files"`
|
||||||
|
}{}
|
||||||
|
err := params.Unmarshal(&result)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to unmarshal params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
result.Repository = g.repository
|
||||||
|
result.Owner = g.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.BaseBranch == "" {
|
||||||
|
result.BaseBranch = g.defaultBranch
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create or update branch
|
||||||
|
err = g.createOrUpdateBranch(ctx, result.Branch)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to create/update branch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create or update files
|
||||||
|
for _, file := range result.Files {
|
||||||
|
err = g.createOrUpdateFile(ctx, result.Branch, file.Path, file.Content, fmt.Sprintf("Update %s", file.Path))
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to update file %s: %w", file.Path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if PR already exists for this branch
|
||||||
|
prs, _, err := g.client.PullRequests.List(ctx, result.Owner, result.Repository, &github.PullRequestListOptions{
|
||||||
|
State: "open",
|
||||||
|
Head: fmt.Sprintf("%s:%s", result.Owner, result.Branch),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to list pull requests: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(prs) > 0 {
|
||||||
|
// Update existing PR
|
||||||
|
pr := prs[0]
|
||||||
|
update := &github.PullRequest{
|
||||||
|
Title: &result.Title,
|
||||||
|
Body: &result.Body,
|
||||||
|
}
|
||||||
|
updatedPR, _, err := g.client.PullRequests.Edit(ctx, result.Owner, result.Repository, pr.GetNumber(), update)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to update pull request: %w", err)
|
||||||
|
}
|
||||||
|
return types.ActionResult{
|
||||||
|
Result: fmt.Sprintf("Updated pull request #%d: %s", updatedPR.GetNumber(), updatedPR.GetHTMLURL()),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new pull request
|
||||||
|
newPR := &github.NewPullRequest{
|
||||||
|
Title: &result.Title,
|
||||||
|
Body: &result.Body,
|
||||||
|
Head: &result.Branch,
|
||||||
|
Base: &result.BaseBranch,
|
||||||
|
}
|
||||||
|
|
||||||
|
createdPR, _, err := g.client.PullRequests.Create(ctx, result.Owner, result.Repository, newPR)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to create pull request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.ActionResult{
|
||||||
|
Result: fmt.Sprintf("Created pull request #%d: %s", createdPR.GetNumber(), createdPR.GetHTMLURL()),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubPRCreator) Definition() types.ActionDefinition {
|
||||||
|
actionName := "create_github_pr"
|
||||||
|
if g.customActionName != "" {
|
||||||
|
actionName = g.customActionName
|
||||||
|
}
|
||||||
|
description := "Create a GitHub pull request with file changes"
|
||||||
|
if g.repository != "" && g.owner != "" && g.defaultBranch != "" {
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"branch": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The name of the new branch to create",
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The title of the pull request",
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The body/description of the pull request",
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
Type: jsonschema.Array,
|
||||||
|
Items: &jsonschema.Definition{
|
||||||
|
Type: jsonschema.Object,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"path": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The path of the file to create/update",
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The content of the file",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"path", "content"},
|
||||||
|
},
|
||||||
|
Description: "Array of files to create or update",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"branch", "title", "files"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"branch": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The name of the new branch to create",
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The title of the pull request",
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The body/description of the pull request",
|
||||||
|
},
|
||||||
|
"base_branch": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The base branch to merge into (defaults to configured default branch)",
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
Type: jsonschema.Array,
|
||||||
|
Items: &jsonschema.Definition{
|
||||||
|
Type: jsonschema.Object,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"path": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The path of the file to create/update",
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The content of the file",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"path", "content"},
|
||||||
|
},
|
||||||
|
Description: "Array of files to create or update",
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The repository to create the pull request in",
|
||||||
|
},
|
||||||
|
"owner": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The owner of the repository",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"branch", "title", "files", "repository", "owner"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *GithubPRCreator) Plannable() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GithubPRCreatorConfigMeta returns the metadata for GitHub PR Creator action configuration fields
|
||||||
|
func GithubPRCreatorConfigMeta() []config.Field {
|
||||||
|
return []config.Field{
|
||||||
|
{
|
||||||
|
Name: "token",
|
||||||
|
Label: "GitHub Token",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: true,
|
||||||
|
HelpText: "GitHub API token with repository access",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "repository",
|
||||||
|
Label: "Repository",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "owner",
|
||||||
|
Label: "Owner",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository owner",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "customActionName",
|
||||||
|
Label: "Custom Action Name",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
HelpText: "Custom name for this action",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "defaultBranch",
|
||||||
|
Label: "Default Branch",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "Default branch to create PRs against (defaults to main)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
118
services/actions/githubprcreator_test.go
Normal file
118
services/actions/githubprcreator_test.go
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package actions_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/mudler/LocalAGI/services/actions"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("GithubPRCreator", func() {
|
||||||
|
var (
|
||||||
|
action *actions.GithubPRCreator
|
||||||
|
ctx context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
ctx = context.Background()
|
||||||
|
|
||||||
|
// Check for required environment variables
|
||||||
|
token := os.Getenv("GITHUB_TOKEN")
|
||||||
|
repo := os.Getenv("TEST_REPOSITORY")
|
||||||
|
owner := os.Getenv("TEST_OWNER")
|
||||||
|
|
||||||
|
// Skip tests if any required environment variable is missing
|
||||||
|
if token == "" || repo == "" || owner == "" {
|
||||||
|
Skip("Skipping GitHub PR creator tests: required environment variables not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := map[string]string{
|
||||||
|
"token": token,
|
||||||
|
"repository": repo,
|
||||||
|
"owner": owner,
|
||||||
|
"customActionName": "test_create_pr",
|
||||||
|
"defaultBranch": "main",
|
||||||
|
}
|
||||||
|
|
||||||
|
action = actions.NewGithubPRCreator(config)
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Creating pull requests", func() {
|
||||||
|
It("should successfully create a pull request with file changes", func() {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"branch": "test-branch",
|
||||||
|
"title": "Test PR",
|
||||||
|
"body": "This is a test pull request",
|
||||||
|
"base_branch": "main",
|
||||||
|
"files": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"path": "test.txt",
|
||||||
|
"content": "This is a test file",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := action.Run(ctx, params)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(result.Result).To(ContainSubstring("pull request #"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle missing required fields", func() {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"title": "Test PR",
|
||||||
|
"body": "This is a test pull request",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := action.Run(ctx, params)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Action Definition", func() {
|
||||||
|
It("should return correct action definition", func() {
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Name.String()).To(Equal("test_create_pr"))
|
||||||
|
Expect(def.Description).To(ContainSubstring("Create a GitHub pull request with file changes"))
|
||||||
|
Expect(def.Properties).To(HaveKey("branch"))
|
||||||
|
Expect(def.Properties).To(HaveKey("title"))
|
||||||
|
Expect(def.Properties).To(HaveKey("files"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle custom action name", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
"customActionName": "custom_action_name",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubPRCreator(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Name.String()).To(Equal("custom_action_name"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Configuration", func() {
|
||||||
|
It("should handle missing repository and owner in config", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubPRCreator(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Properties).To(HaveKey("repository"))
|
||||||
|
Expect(def.Properties).To(HaveKey("owner"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle provided repository and owner in config", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
"repository": "test-repo",
|
||||||
|
"defaultBranch": "main",
|
||||||
|
"owner": "test-owner",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubPRCreator(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Properties).NotTo(HaveKey("repository"))
|
||||||
|
Expect(def.Properties).NotTo(HaveKey("owner"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -128,11 +128,13 @@ func (g *GithubPRReviewer) Run(ctx context.Context, params types.ActionParams) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionResult := fmt.Sprintf(
|
actionResult := fmt.Sprintf(
|
||||||
"Pull request https://github.com/%s/%s/pull/%d reviewed successfully with status: %s",
|
"Pull request https://github.com/%s/%s/pull/%d reviewed successfully with status: %s, comments: %v, message: %s",
|
||||||
result.Owner,
|
result.Owner,
|
||||||
result.Repository,
|
result.Repository,
|
||||||
result.PRNumber,
|
result.PRNumber,
|
||||||
strings.ToLower(result.ReviewAction),
|
strings.ToLower(result.ReviewAction),
|
||||||
|
result.Comments,
|
||||||
|
result.ReviewComment,
|
||||||
)
|
)
|
||||||
|
|
||||||
return types.ActionResult{Result: actionResult}, nil
|
return types.ActionResult{Result: actionResult}, nil
|
||||||
|
|||||||
103
services/actions/githubprreviewer_test.go
Normal file
103
services/actions/githubprreviewer_test.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package actions_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/mudler/LocalAGI/core/types"
|
||||||
|
"github.com/mudler/LocalAGI/services/actions"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("GithubPRReviewer", func() {
|
||||||
|
var (
|
||||||
|
reviewer *actions.GithubPRReviewer
|
||||||
|
ctx context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
ctx = context.Background()
|
||||||
|
|
||||||
|
// Check for required environment variables
|
||||||
|
token := os.Getenv("GITHUB_TOKEN")
|
||||||
|
repo := os.Getenv("TEST_REPOSITORY")
|
||||||
|
owner := os.Getenv("TEST_OWNER")
|
||||||
|
prNumber := os.Getenv("TEST_PR_NUMBER")
|
||||||
|
|
||||||
|
// Skip tests if any required environment variable is missing
|
||||||
|
if token == "" || repo == "" || owner == "" || prNumber == "" {
|
||||||
|
Skip("Skipping GitHub PR reviewer tests: required environment variables not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := map[string]string{
|
||||||
|
"token": token,
|
||||||
|
"repository": repo,
|
||||||
|
"owner": owner,
|
||||||
|
"customActionName": "test_review_github_pr",
|
||||||
|
}
|
||||||
|
|
||||||
|
reviewer = actions.NewGithubPRReviewer(config)
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Reviewing a PR", func() {
|
||||||
|
It("should successfully submit a review with comments", func() {
|
||||||
|
prNumber := os.Getenv("TEST_PR_NUMBER")
|
||||||
|
Expect(prNumber).NotTo(BeEmpty())
|
||||||
|
|
||||||
|
params := types.ActionParams{
|
||||||
|
"pr_number": prNumber,
|
||||||
|
"review_comment": "Test review comment from integration test",
|
||||||
|
"review_action": "COMMENT",
|
||||||
|
"comments": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"file": "README.md",
|
||||||
|
"line": 1,
|
||||||
|
"comment": "Test line comment from integration test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := reviewer.Run(ctx, params)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(result.Result).To(ContainSubstring("reviewed successfully"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle invalid PR number", func() {
|
||||||
|
params := types.ActionParams{
|
||||||
|
"pr_number": 999999,
|
||||||
|
"review_comment": "Test review comment",
|
||||||
|
"review_action": "COMMENT",
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := reviewer.Run(ctx, params)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(result.Result).To(ContainSubstring("not found"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle invalid review action", func() {
|
||||||
|
prNumber := os.Getenv("TEST_PR_NUMBER")
|
||||||
|
Expect(prNumber).NotTo(BeEmpty())
|
||||||
|
|
||||||
|
params := types.ActionParams{
|
||||||
|
"pr_number": prNumber,
|
||||||
|
"review_comment": "Test review comment",
|
||||||
|
"review_action": "INVALID_ACTION",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := reviewer.Run(ctx, params)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Action Definition", func() {
|
||||||
|
It("should return correct action definition", func() {
|
||||||
|
def := reviewer.Definition()
|
||||||
|
Expect(def.Name).To(Equal(types.ActionDefinitionName("test_review_github_pr")))
|
||||||
|
Expect(def.Description).To(ContainSubstring("Review a GitHub pull request"))
|
||||||
|
Expect(def.Properties).To(HaveKey("pr_number"))
|
||||||
|
Expect(def.Properties).To(HaveKey("review_action"))
|
||||||
|
Expect(def.Properties).To(HaveKey("comments"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
174
services/actions/githubrepositorygetallcontent.go
Normal file
174
services/actions/githubrepositorygetallcontent.go
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
package actions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/go-github/v69/github"
|
||||||
|
"github.com/mudler/LocalAGI/core/types"
|
||||||
|
"github.com/mudler/LocalAGI/pkg/config"
|
||||||
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GithubRepositoryGetAllContent struct {
|
||||||
|
token, repository, owner, customActionName string
|
||||||
|
client *github.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGithubRepositoryGetAllContent(config map[string]string) *GithubRepositoryGetAllContent {
|
||||||
|
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||||
|
|
||||||
|
return &GithubRepositoryGetAllContent{
|
||||||
|
client: client,
|
||||||
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
|
customActionName: config["customActionName"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubRepositoryGetAllContent) getContentRecursively(ctx context.Context, path string) (string, error) {
|
||||||
|
var result strings.Builder
|
||||||
|
|
||||||
|
// Get content at the current path
|
||||||
|
_, directoryContent, _, err := g.client.Repositories.GetContents(ctx, g.owner, g.repository, path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error getting content at path %s: %w", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process each item in the directory
|
||||||
|
for _, item := range directoryContent {
|
||||||
|
if item.GetType() == "dir" {
|
||||||
|
// Recursively get content for subdirectories
|
||||||
|
subContent, err := g.getContentRecursively(ctx, item.GetPath())
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
result.WriteString(subContent)
|
||||||
|
} else if item.GetType() == "file" {
|
||||||
|
// Get file content
|
||||||
|
fileContent, _, _, err := g.client.Repositories.GetContents(ctx, g.owner, g.repository, item.GetPath(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error getting file content for %s: %w", item.GetPath(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := fileContent.GetContent()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error decoding content for %s: %w", item.GetPath(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add file content to result with clear markers
|
||||||
|
result.WriteString(fmt.Sprintf("\n--- START FILE: %s ---\n", item.GetPath()))
|
||||||
|
result.WriteString(content)
|
||||||
|
result.WriteString(fmt.Sprintf("\n--- END FILE: %s ---\n", item.GetPath()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubRepositoryGetAllContent) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||||
|
result := struct {
|
||||||
|
Repository string `json:"repository"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
Path string `json:"path,omitempty"`
|
||||||
|
}{}
|
||||||
|
err := params.Unmarshal(&result)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, fmt.Errorf("failed to unmarshal params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
result.Repository = g.repository
|
||||||
|
result.Owner = g.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start from root if no path specified
|
||||||
|
if result.Path == "" {
|
||||||
|
result.Path = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := g.getContentRecursively(ctx, result.Path)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.ActionResult{Result: content}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubRepositoryGetAllContent) Definition() types.ActionDefinition {
|
||||||
|
actionName := "get_all_github_repository_content"
|
||||||
|
if g.customActionName != "" {
|
||||||
|
actionName = g.customActionName
|
||||||
|
}
|
||||||
|
description := "Get all content of a GitHub repository recursively"
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"path": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "Optional path to start from (defaults to repository root)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"path": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "Optional path to start from (defaults to repository root)",
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The repository to get content from",
|
||||||
|
},
|
||||||
|
"owner": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The owner of the repository",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"repository", "owner"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *GithubRepositoryGetAllContent) Plannable() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GithubRepositoryGetAllContentConfigMeta returns the metadata for GitHub Repository Get All Content action configuration fields
|
||||||
|
func GithubRepositoryGetAllContentConfigMeta() []config.Field {
|
||||||
|
return []config.Field{
|
||||||
|
{
|
||||||
|
Name: "token",
|
||||||
|
Label: "GitHub Token",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: true,
|
||||||
|
HelpText: "GitHub API token with repository access",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "repository",
|
||||||
|
Label: "Repository",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "owner",
|
||||||
|
Label: "Owner",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository owner",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "customActionName",
|
||||||
|
Label: "Custom Action Name",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
HelpText: "Custom name for this action",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
114
services/actions/githubrepositorygetallcontent_test.go
Normal file
114
services/actions/githubrepositorygetallcontent_test.go
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
package actions_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mudler/LocalAGI/services/actions"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("GithubRepositoryGetAllContent", func() {
|
||||||
|
var (
|
||||||
|
action *actions.GithubRepositoryGetAllContent
|
||||||
|
ctx context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
ctx = context.Background()
|
||||||
|
|
||||||
|
// Check for required environment variables
|
||||||
|
token := os.Getenv("GITHUB_TOKEN")
|
||||||
|
repo := os.Getenv("TEST_REPOSITORY")
|
||||||
|
owner := os.Getenv("TEST_OWNER")
|
||||||
|
|
||||||
|
// Skip tests if any required environment variable is missing
|
||||||
|
if token == "" || repo == "" || owner == "" {
|
||||||
|
Skip("Skipping GitHub repository get all content tests: required environment variables not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := map[string]string{
|
||||||
|
"token": token,
|
||||||
|
"repository": repo,
|
||||||
|
"owner": owner,
|
||||||
|
"customActionName": "test_get_all_content",
|
||||||
|
}
|
||||||
|
|
||||||
|
action = actions.NewGithubRepositoryGetAllContent(config)
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Getting repository content", func() {
|
||||||
|
It("should successfully get content from root directory with proper file markers", func() {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"path": ".",
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := action.Run(ctx, params)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(result.Result).NotTo(BeEmpty())
|
||||||
|
|
||||||
|
// Verify file markers
|
||||||
|
Expect(result.Result).To(ContainSubstring("--- START FILE:"))
|
||||||
|
Expect(result.Result).To(ContainSubstring("--- END FILE:"))
|
||||||
|
|
||||||
|
// Verify markers are properly paired
|
||||||
|
startCount := strings.Count(result.Result, "--- START FILE:")
|
||||||
|
endCount := strings.Count(result.Result, "--- END FILE:")
|
||||||
|
Expect(startCount).To(Equal(endCount), "Number of start and end markers should match")
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle non-existent path", func() {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"path": "non-existent-path",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := action.Run(ctx, params)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Action Definition", func() {
|
||||||
|
It("should return correct action definition", func() {
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Name.String()).To(Equal("test_get_all_content"))
|
||||||
|
Expect(def.Description).To(ContainSubstring("Get all content of a GitHub repository recursively"))
|
||||||
|
Expect(def.Properties).To(HaveKey("path"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle custom action name", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
"customActionName": "custom_action_name",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubRepositoryGetAllContent(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Name.String()).To(Equal("custom_action_name"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Configuration", func() {
|
||||||
|
It("should handle missing repository and owner in config", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubRepositoryGetAllContent(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Properties).To(HaveKey("repository"))
|
||||||
|
Expect(def.Properties).To(HaveKey("owner"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should handle provided repository and owner in config", func() {
|
||||||
|
config := map[string]string{
|
||||||
|
"token": "test-token",
|
||||||
|
"repository": "test-repo",
|
||||||
|
"owner": "test-owner",
|
||||||
|
}
|
||||||
|
action := actions.NewGithubRepositoryGetAllContent(config)
|
||||||
|
def := action.Definition()
|
||||||
|
Expect(def.Properties).NotTo(HaveKey("repository"))
|
||||||
|
Expect(def.Properties).NotTo(HaveKey("owner"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useParams, Link, useNavigate } from 'react-router-dom';
|
import { useParams, Link } from 'react-router-dom';
|
||||||
|
|
||||||
function AgentStatus() {
|
function AgentStatus() {
|
||||||
const { name } = useParams();
|
const { name } = useParams();
|
||||||
const navigate = useNavigate();
|
|
||||||
const [statusData, setStatusData] = useState(null);
|
const [statusData, setStatusData] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [eventSource, setEventSource] = useState(null);
|
const [_eventSource, setEventSource] = useState(null);
|
||||||
const [liveUpdates, setLiveUpdates] = useState([]);
|
const [liveUpdates, setLiveUpdates] = useState([]);
|
||||||
|
|
||||||
// Update document title
|
// Update document title
|
||||||
@@ -49,7 +48,7 @@ function AgentStatus() {
|
|||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
setLiveUpdates(prev => [data, ...prev.slice(0, 19)]); // Keep last 20 updates
|
setLiveUpdates(prev => [data, ...prev.slice(0, 19)]); // Keep last 20 updates
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error parsing SSE data:', err);
|
setLiveUpdates(prev => [event.data, ...prev.slice(0, 19)]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,23 +128,9 @@ function AgentStatus() {
|
|||||||
<h2 className="text-sm font-semibold mb-2">Agent Action:</h2>
|
<h2 className="text-sm font-semibold mb-2">Agent Action:</h2>
|
||||||
<div className="status-details">
|
<div className="status-details">
|
||||||
<div className="status-row">
|
<div className="status-row">
|
||||||
<span className="status-label">Result:</span>
|
<span className="status-label">{index}</span>
|
||||||
<span className="status-value">{formatValue(item.Result)}</span>
|
<span className="status-value">{formatValue(item)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="status-row">
|
|
||||||
<span className="status-label">Action:</span>
|
|
||||||
<span className="status-value">{formatValue(item.Action)}</span>
|
|
||||||
</div>
|
|
||||||
<div className="status-row">
|
|
||||||
<span className="status-label">Parameters:</span>
|
|
||||||
<span className="status-value pre-wrap">{formatValue(item.Params)}</span>
|
|
||||||
</div>
|
|
||||||
{item.Reasoning && (
|
|
||||||
<div className="status-row">
|
|
||||||
<span className="status-label">Reasoning:</span>
|
|
||||||
<span className="status-value reasoning">{formatValue(item.Reasoning)}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
'/status': backendUrl,
|
'/status': backendUrl,
|
||||||
'/action': backendUrl,
|
'/action': backendUrl,
|
||||||
'/actions': backendUrl,
|
'/actions': backendUrl,
|
||||||
|
'/avatars': backendUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -238,9 +239,20 @@ func (app *App) registerRoutes(pool *state.AgentPool, webapp *fiber.App) {
|
|||||||
history = &state.Status{ActionResults: []types.ActionState{}}
|
history = &state.Status{ActionResults: []types.ActionState{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entries := []string{}
|
||||||
|
for _, h := range Reverse(history.Results()) {
|
||||||
|
entries = append(entries, fmt.Sprintf(
|
||||||
|
"Result: %v Action: %v Params: %v Reasoning: %v",
|
||||||
|
h.Result,
|
||||||
|
h.Action.Definition().Name,
|
||||||
|
h.Params,
|
||||||
|
h.Reasoning,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
"Name": c.Params("name"),
|
"Name": c.Params("name"),
|
||||||
"History": Reverse(history.Results()),
|
"History": entries,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user