Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
7 changes: 4 additions & 3 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ var agentDeleteCmd = &cobra.Command{
func getAgentAuthType(logger logger.Logger, authType string) string {
if authType != "" {
switch authType {
case "bearer", "none":
case "project", "bearer", "none":
return authType
default:
}
}
auth := tui.Select(logger, "Select your Agent's webhook authentication method", "Do you want to secure the webhook or make it publicly available?", []tui.Option{
{Text: tui.PadRight("API Key", 10, " ") + tui.Muted("Bearer Token (will be generated for you)"), ID: "bearer"},
{Text: tui.PadRight("None", 10, " ") + tui.Muted("No Authentication Required"), ID: "none"},
{Text: tui.PadRight("API Key", 20, " ") + tui.Muted("Bearer Token (will be generated for you)"), ID: "bearer"},
{Text: tui.PadRight("Project API Key", 20, " ") + tui.Muted("The Project Key attched to your project"), ID: "project"},
{Text: tui.PadRight("None", 20, " ") + tui.Muted("No Authentication Required"), ID: "none"},
})
return auth
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func ShowNewProjectImport(ctx context.Context, logger logger.Logger, cmd *cobra.
errsystem.New(errsystem.ErrSaveProject, err,
errsystem.WithContextMessage("Error saving project after import")).ShowErrorAndExit()
}
saveEnv(dir, result.APIKey)
saveEnv(dir, result.APIKey, result.ProjectKey)
})
tui.ShowSuccess("Project imported successfully")
}
Expand Down
49 changes: 40 additions & 9 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,50 @@ Use the subcommands to manage your projects.`,
},
}

func saveEnv(dir string, apikey string) {
func saveEnv(dir string, apikey string, projectKey string) {
filename := filepath.Join(dir, ".env")
envLines, err := env.ParseEnvFile(filename)
if err != nil {
errsystem.New(errsystem.ErrReadConfigurationFile, err, errsystem.WithContextMessage("Failed to parse .env file")).ShowErrorAndExit()
}
var found bool
found := map[string]bool{
"AGENTUITY_SDK_KEY": false,
"AGENTUITY_API_KEY": false,
"AGENTUITY_PROJECT_KEY": false,
}

for i, envLine := range envLines {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

if envLine.Key == "AGENTUITY_API_KEY" {
envLines[i].Val = apikey
found = true
found["AGENTUITY_API_KEY"] = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've made this comment several times but it doesn't seem to stick...

AGENTUITY_AGENTS_KEY seems confusing to me. Is this the project-level key for the agent or the key to use for the SDK?

i think we should maybe be more intentional in the naming.

AGENTUITY_SDK_KEY - this would be current AGENTUITY_API_KEY but make it clear that it's needed for the SDK to run.

AGENTUITY_PROJECT_KEY - this would be what I think is your AGENTUITY_AGENTS_KEY but be the project-level key for accessing agents within the same project.

We would need to make AGENTUITY_API_KEY backwards compatible so i realize that this is a little more work but i think would make it more clear what is what.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Yep! I was in the process of making that change Thursday and and pick it back up now. 👍

}
if envLine.Key == "AGENTUITY_SDK_KEY" {
envLines[i].Val = apikey
found[envLine.Key] = true
}
if envLine.Key == "AGENTUITY_PROJECT_KEY" {
envLines[i].Val = projectKey
found[envLine.Key] = true
}
}

if found["AGENTUITY_API_KEY"] {
// Remove AGENTUITY_API_KEY since it's deprecated in newer SDK versions
for i := len(envLines) - 1; i >= 0; i-- {
if envLines[i].Key == "AGENTUITY_API_KEY" {
envLines = append(envLines[:i], envLines[i+1:]...)
}
}
found["AGENTUITY_API_KEY"] = false
}
if !found {
envLines = append(envLines, env.EnvLine{Key: "AGENTUITY_API_KEY", Val: apikey})

if !found["AGENTUITY_SDK_KEY"] {
envLines = append(envLines, env.EnvLine{Key: "AGENTUITY_SDK_KEY", Val: apikey})
}
if !found["AGENTUITY_PROJECT_KEY"] {
envLines = append(envLines, env.EnvLine{Key: "AGENTUITY_PROJECT_KEY", Val: projectKey})
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if we need all of this. since this version of the CLI that's executing and our network will support the new variable, why not just detect if we have the old one and remove it and replace it with the new one and not worry about the SDK version at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I think that would work for deployed projects but we'd something like this for devmode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can think of a simpler way to solve that problem tho.


if err := env.WriteEnvFile(filename, envLines); err != nil {
errsystem.New(errsystem.ErrWriteConfigurationFile, err, errsystem.WithContextMessage("Failed to write .env file")).ShowErrorAndExit()
}
Expand All @@ -65,6 +93,7 @@ type InitProjectArgs struct {
Name string
Description string
EnableWebhookAuth bool
AuthType string
Provider *templates.TemplateRules
Agents []project.AgentConfig
}
Expand All @@ -78,6 +107,7 @@ func initProject(ctx context.Context, logger logger.Logger, args InitProjectArgs
Name: args.Name,
Description: args.Description,
EnableWebhookAuth: args.EnableWebhookAuth,
AuthType: args.AuthType,
Dir: args.Dir,
Provider: args.Provider.Identifier,
Agents: args.Agents,
Expand Down Expand Up @@ -126,7 +156,7 @@ func initProject(ctx context.Context, logger logger.Logger, args InitProjectArgs
errsystem.New(errsystem.ErrSaveProject, err, errsystem.WithContextMessage("Failed to save project to disk")).ShowErrorAndExit()
}

saveEnv(args.Dir, result.APIKey)
saveEnv(args.Dir, result.APIKey, result.ProjectKey)

return result
}
Expand Down Expand Up @@ -540,7 +570,8 @@ Examples:
Description: description,
Provider: rules,
Agents: agents,
EnableWebhookAuth: authType != "none",
EnableWebhookAuth: authType == "project" || authType == "webhook",
AuthType: authType,
})

// remember our choices
Expand All @@ -562,7 +593,7 @@ Examples:
para = append(para, tui.Secondary("1. Switch into the project directory at ")+tui.Directory(projectDir))
para = append(para, tui.Secondary("2. Run ")+tui.Command("dev")+tui.Secondary(" to run the project locally in development mode"))
para = append(para, tui.Secondary("3. Run ")+tui.Command("deploy")+tui.Secondary(" to deploy the project to the Agentuity Agent Cloud"))
if authType != "none" {
if authType == "project" || authType == "webhook" {
para = append(para, tui.Secondary("4. Run ")+tui.Command("agent apikey")+tui.Secondary(" to fetch the Webhook API key for the agent"))
}
para = append(para, tui.Secondary("🏠 Access your project at ")+tui.Link("%s/projects/%s", appUrl, projectData.ProjectId))
Expand Down Expand Up @@ -811,6 +842,6 @@ func init() {
projectNewCmd.Flags().StringP("template", "t", "", "The template to use for the project")
projectNewCmd.Flags().Bool("force", false, "Force the project to be created even if the directory already exists")
projectNewCmd.Flags().String("templates-dir", "", "The directory to load the templates. Defaults to loading them from the github.com/agentuity/templates repository")
projectNewCmd.Flags().String("auth", "bearer", "The authentication type for the agent (bearer or none)")
projectNewCmd.Flags().String("auth", "project", "The authentication type for the agent (project, webhook, or none)")
projectNewCmd.Flags().String("action", "github-app", "The action to take for the project (github-action, github-app, none)")
}
2 changes: 1 addition & 1 deletion internal/bundler/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func init() {
Module: "@anthropic-ai",
Filename: "sdk\\/index.*",
Body: &patchAction{
Before: generateEnvGuard("ANTHROPIC_API_KEY", generateGatewayEnvGuard("ANTHROPIC_API_KEY", "process.env.AGENTUITY_API_KEY", "ANTHROPIC_BASE_URL", "anthropic")),
Before: generateEnvGuard("ANTHROPIC_API_KEY", generateGatewayEnvGuard("ANTHROPIC_API_KEY", "process.env.AGENTUITY_SDK_KEY", "ANTHROPIC_BASE_URL", "anthropic")),
},
}
}
2 changes: 1 addition & 1 deletion internal/bundler/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func init() {
Module: "openai",
Filename: "index",
Body: &patchAction{
Before: generateEnvGuard("OPENAI_API_KEY", generateGatewayEnvGuard("OPENAI_API_KEY", "process.env.AGENTUITY_API_KEY", "OPENAI_BASE_URL", "openai")),
Before: generateEnvGuard("OPENAI_API_KEY", generateGatewayEnvGuard("OPENAI_API_KEY", "process.env.AGENTUITY_SDK_KEY", "OPENAI_BASE_URL", "openai")),
},
}
}
4 changes: 2 additions & 2 deletions internal/bundler/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ _args = _newargs;`, index, inject)
}

func generateEnvGuard(name string, inject string) string {
return fmt.Sprintf(`if (!process.env.%[1]s || process.env.%[1]s === process.env.AGENTUITY_API_KEY) {
return fmt.Sprintf(`if (!process.env.%[1]s || process.env.%[1]s === process.env.AGENTUITY_SDK_KEY) {
%[2]s
}`, name, inject)
}

func generateGatewayEnvGuard(apikey string, apikeyval string, apibase string, provider string) string {
return fmt.Sprintf(`{
const apikey = process.env.AGENTUITY_API_KEY;
const apikey = process.env.AGENTUITY_SDK_KEY;
const url = process.env.AGENTUITY_TRANSPORT_URL;
if (url && apikey) {
process.env.%[1]s = %[2]s;
Expand Down
Loading
Loading