Skip to content
Open
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
31 changes: 31 additions & 0 deletions plugins/opencode/api_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package opencode

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/importer"
"github.com/1Password/shell-plugins/sdk/provision"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func APIKey() schema.CredentialType {
return schema.CredentialType{
Name: credname.APIKey,
DocsURL: sdk.URL("https://opencode.ai/docs/providers/"),
ManagementURL: sdk.URL("https://opencode.ai/auth"),
Fields: []schema.CredentialField{
{
Name: fieldname.APIKey,
MarkdownDescription: "OpenCode Zen API key from https://opencode.ai/auth used to authenticate to OpenCode. `OPENCODE_API_KEY` covers only the OpenCode Zen gateway, not BYOK keys such as `ANTHROPIC_API_KEY`.",
Secret: true,
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"OPENCODE_API_KEY": fieldname.APIKey,
}
43 changes: 43 additions & 0 deletions plugins/opencode/api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package opencode

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

const exampleAPIKey = "sk-0123456789abcdefghijEXAMPLE"

func TestAPIKeyProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.APIKey: exampleAPIKey,
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"OPENCODE_API_KEY": exampleAPIKey,
},
},
},
})
}

func TestAPIKeyImporter(t *testing.T) {
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"OPENCODE_API_KEY": exampleAPIKey,
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.APIKey: exampleAPIKey,
},
},
},
},
})
}
26 changes: 26 additions & 0 deletions plugins/opencode/opencode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package opencode

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/needsauth"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
)

func OpencodeCLI() schema.Executable {
return schema.Executable{
Name: "OpenCode CLI",
Runs: []string{"opencode"},
DocsURL: sdk.URL("https://opencode.ai/docs/"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.NotWhenContainsArgs("auth"),
),
Uses: []schema.CredentialUsage{
{
Name: credname.APIKey,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/opencode/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package opencode

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "opencode",
Platform: schema.PlatformInfo{
Name: "OpenCode",
Homepage: sdk.URL("https://opencode.ai"),
},
Credentials: []schema.CredentialType{
APIKey(),
},
Executables: []schema.Executable{
OpencodeCLI(),
},
}
}