Skip to content
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

fix(codegen): Adds special cases for AuthStatus to re-enable codegen #5854

Merged
merged 10 commits into from
Oct 10, 2024
38 changes: 38 additions & 0 deletions .github/workflows/agent-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Please post in #team-cody-clients if you need help getting this CI check to pass.
# Worst-case: feel free to disable this workflow here https://github.com/sourcegraph/cody/actions/workflows/agent-bindings.yml
name: agent-bindings
on:

pull_request:
paths:
- '**.ts'
- '**.tsx'
- '**.js'

jobs:
kotlin:
if: github.repository == 'sourcegraph/cody'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # SECURITY: pin third-party action hashes
id: pnpm-install
with:
version: 8.6.7
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install --frozen-lockfile
- run: pnpm generate-agent-kotlin-bindings
- run: ./agent/scripts/error-if-diff.sh
- run: ./agent/scripts/compile-bindings-if-diff.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

import com.google.gson.annotations.SerializedName;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
Expand All @@ -12,11 +11,10 @@ sealed class AuthStatus {
companion object {
val deserializer: JsonDeserializer<AuthStatus> =
JsonDeserializer { element: JsonElement, _: Type, context: JsonDeserializationContext ->
if (element.getAsJsonObject().get("username") == null) {
context.deserialize<UnauthenticatedAuthStatus>(element, UnauthenticatedAuthStatus::class.java)
} else {
context.deserialize<AuthenticatedAuthStatus>(element, AuthenticatedAuthStatus::class.java)
}
when (element.getAsJsonObject().get("authenticated").getAsBoolean()) {
false -> context.deserialize<UnauthenticatedAuthStatus>(element, UnauthenticatedAuthStatus::class.java)
true -> context.deserialize<AuthenticatedAuthStatus>(element, AuthenticatedAuthStatus::class.java)
}
}
}
}
Expand All @@ -27,8 +25,7 @@ data class UnauthenticatedAuthStatus(
val showNetworkError: Boolean? = null,
val showInvalidAccessTokenError: Boolean? = null,
val pendingValidation: Boolean,
) : AuthStatus() {
}
) : AuthStatus()

data class AuthenticatedAuthStatus(
val endpoint: String,
Expand All @@ -41,6 +38,6 @@ data class AuthenticatedAuthStatus(
val displayName: String? = null,
val avatarURL: String? = null,
val pendingValidation: Boolean,
) : AuthStatus() {
}
val organizations: List<OrganizationsParams>? = null,
) : AuthStatus()

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ interface CodyAgentServer {
fun testing_autocomplete_awaitPendingVisibilityTimeout(params: Null?): CompletableFuture<CompletionItemID?>
@JsonRequest("testing/autocomplete/setCompletionVisibilityDelay")
fun testing_autocomplete_setCompletionVisibilityDelay(params: Testing_Autocomplete_SetCompletionVisibilityDelayParams): CompletableFuture<Null?>
@JsonRequest("testing/autocomplete/providerConfig")
fun testing_autocomplete_providerConfig(params: Null?): CompletableFuture<Testing_Autocomplete_ProviderConfigResult>
@JsonRequest("extensionConfiguration/change")
fun extensionConfiguration_change(params: ExtensionConfiguration): CompletableFuture<AuthStatus?>
@JsonRequest("extensionConfiguration/status")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ object Constants {
const val function = "function"
const val gateway = "gateway"
const val history = "history"
const val `https-example-com` = "https://example.com"
const val human = "human"
const val ignore = "ignore"
const val indentation = "indentation"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

data class Chat_RestoreParams(
val modelID: String? = null,
val messages: List<SerializedChatMessage>,
val chatID: String,
data class OrganizationsParams(
val name: String,
val id: String,
)

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ data class SerializedChatMessage(
val speaker: SpeakerEnum, // Oneof: human, assistant, system
val text: String? = null,
val model: String? = null,
val intent: IntentEnum? = null, // Oneof: search, chat
) {

enum class SpeakerEnum {
@SerializedName("human") Human,
@SerializedName("assistant") Assistant,
@SerializedName("system") System,
}

enum class IntentEnum {
@SerializedName("search") Search,
@SerializedName("chat") Chat,
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

data class Testing_Autocomplete_ProviderConfigResult(
val id: String,
val legacyModel: String,
val configSource: String,
)

2 changes: 1 addition & 1 deletion agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ export class Agent extends MessageHandler implements ExtensionClient {

this.registerAuthenticatedRequest('testing/autocomplete/providerConfig', async () => {
const provider = await vscode_shim.completionProvider()
return provider.config
return provider.config.provider
})

this.registerAuthenticatedRequest('graphql/getRepoIds', async ({ names, first }) => {
Expand Down
12 changes: 11 additions & 1 deletion agent/src/cli/scip-codegen/BaseCodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ export interface ProtocolSymbol {
kind: ProtocolMethodKind
}

export type ConstantType = string | boolean | number
export type ConstantTypeType = 'string' | 'boolean' | 'number'

export function typeOfUnion(union: DiscriminatedUnion): ConstantTypeType {
if (union.members.length === 0) {
throw new TypeError(`Union ${JSON.stringify(union, null, 2)} has no members`)
}
return typeof union.members[0].value as ConstantTypeType
}

export interface DiscriminatedUnionMember {
value: string
value: ConstantType
type: scip.Type
}
export interface DiscriminatedUnion {
Expand Down
Loading
Loading