feat: used acp agent capabilities for local Inference support check (#9996)
This commit is contained in:
@@ -13,7 +13,6 @@ pub async fn check_token(
|
||||
next: Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
if request.uri().path() == "/status"
|
||||
|| request.uri().path() == "/features"
|
||||
|| request.uri().path() == "/mcp-ui-proxy"
|
||||
|| request.uri().path() == "/mcp-app-proxy"
|
||||
|| request.uri().path() == "/mcp-app-guest"
|
||||
|
||||
@@ -473,7 +473,6 @@ derive_utoipa!(IconTheme as IconThemeSchema);
|
||||
super::routes::telemetry::send_telemetry_event,
|
||||
super::routes::dictation::transcribe_dictation,
|
||||
super::routes::dictation::get_dictation_config,
|
||||
super::routes::features::get_features,
|
||||
),
|
||||
components(schemas(
|
||||
super::routes::config_management::UpsertConfigQuery,
|
||||
@@ -654,7 +653,6 @@ derive_utoipa!(IconTheme as IconThemeSchema);
|
||||
super::routes::dictation::TranscribeResponse,
|
||||
goose::dictation::providers::DictationProvider,
|
||||
super::routes::dictation::DictationProviderStatus,
|
||||
super::routes::features::FeaturesResponse,
|
||||
DownloadProgress,
|
||||
DownloadStatus,
|
||||
))
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
use axum::{routing::get, Json, Router};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct FeaturesResponse {
|
||||
/// Map of feature name to enabled status
|
||||
pub features: HashMap<String, bool>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/features",
|
||||
responses(
|
||||
(status = 200, description = "Compile-time feature flags", body = FeaturesResponse),
|
||||
)
|
||||
)]
|
||||
pub async fn get_features() -> Json<FeaturesResponse> {
|
||||
let mut features = HashMap::new();
|
||||
|
||||
features.insert(
|
||||
"local-inference".to_string(),
|
||||
cfg!(feature = "local-inference"),
|
||||
);
|
||||
features.insert("code-mode".to_string(), cfg!(feature = "code-mode"));
|
||||
|
||||
Json(FeaturesResponse { features })
|
||||
}
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new().route("/features", get(get_features))
|
||||
}
|
||||
@@ -3,7 +3,6 @@ pub mod agent;
|
||||
pub mod config_management;
|
||||
pub mod dictation;
|
||||
pub mod errors;
|
||||
pub mod features;
|
||||
#[cfg(feature = "local-inference")]
|
||||
pub mod local_inference;
|
||||
pub mod mcp_app_proxy;
|
||||
@@ -45,8 +44,7 @@ pub fn configure(state: Arc<crate::state::AppState>, secret_key: String) -> Rout
|
||||
.merge(mcp_app_proxy::routes(secret_key))
|
||||
.merge(session_events::routes(state.clone()))
|
||||
.merge(sampling::routes(state.clone()))
|
||||
.merge(dictation::routes(state.clone()))
|
||||
.merge(features::routes());
|
||||
.merge(dictation::routes(state.clone()));
|
||||
|
||||
#[cfg(feature = "local-inference")]
|
||||
let router = router.merge(local_inference::routes(state));
|
||||
|
||||
@@ -257,6 +257,21 @@ fn meta_string(
|
||||
Ok(Some(value.to_string()))
|
||||
}
|
||||
|
||||
fn agent_capabilities_meta() -> Option<Meta> {
|
||||
let mut goose = serde_json::Map::new();
|
||||
if cfg!(feature = "local-inference") {
|
||||
goose.insert("localInference".to_string(), serde_json::json!({}));
|
||||
}
|
||||
|
||||
if goose.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut meta = serde_json::Map::new();
|
||||
meta.insert("goose".to_string(), serde_json::Value::Object(goose));
|
||||
Some(meta)
|
||||
}
|
||||
|
||||
fn spawn_session_name_update_notifier(
|
||||
cx: ConnectionTo<Client>,
|
||||
) -> tokio::sync::mpsc::UnboundedSender<crate::session::SessionNameUpdate> {
|
||||
@@ -2206,7 +2221,8 @@ impl GooseAcpAgent {
|
||||
.audio(false)
|
||||
.embedded_context(true),
|
||||
)
|
||||
.mcp_capabilities(McpCapabilities::new().http(true));
|
||||
.mcp_capabilities(McpCapabilities::new().http(true))
|
||||
.meta(agent_capabilities_meta());
|
||||
Ok(InitializeResponse::new(args.protocol_version)
|
||||
.agent_info(Implementation::new("goose", env!("CARGO_PKG_VERSION")))
|
||||
.agent_capabilities(capabilities)
|
||||
|
||||
@@ -1703,26 +1703,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/features": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"super::routes::features"
|
||||
],
|
||||
"operationId": "get_features",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Compile-time feature flags",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/FeaturesResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/handle_nanogpt": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@@ -4986,21 +4966,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"FeaturesResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"features"
|
||||
],
|
||||
"properties": {
|
||||
"features": {
|
||||
"type": "object",
|
||||
"description": "Map of feature name to enabled status",
|
||||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ForkRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { InitializeResponse } from '@agentclientprotocol/sdk';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { hasLocalInferenceCapability } from '../capabilities';
|
||||
|
||||
function initializeResponseWithMeta(meta?: unknown): Pick<InitializeResponse, 'agentCapabilities'> {
|
||||
return {
|
||||
agentCapabilities: {
|
||||
_meta: meta,
|
||||
},
|
||||
} as Pick<InitializeResponse, 'agentCapabilities'>;
|
||||
}
|
||||
|
||||
describe('ACP capabilities', () => {
|
||||
it('detects local inference support from Goose metadata', () => {
|
||||
expect(
|
||||
hasLocalInferenceCapability(
|
||||
initializeResponseWithMeta({
|
||||
goose: {
|
||||
localInference: {},
|
||||
},
|
||||
})
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('treats missing local inference metadata as unsupported', () => {
|
||||
expect(hasLocalInferenceCapability(initializeResponseWithMeta())).toBe(false);
|
||||
expect(hasLocalInferenceCapability(initializeResponseWithMeta({}))).toBe(false);
|
||||
expect(hasLocalInferenceCapability(initializeResponseWithMeta({ goose: {} }))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores malformed Goose metadata', () => {
|
||||
expect(hasLocalInferenceCapability(initializeResponseWithMeta({ goose: true }))).toBe(false);
|
||||
expect(hasLocalInferenceCapability(initializeResponseWithMeta({ goose: null }))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
GooseClient,
|
||||
type GooseClientCallbacks,
|
||||
} from '@aaif/goose-sdk';
|
||||
import { PROTOCOL_VERSION } from '@agentclientprotocol/sdk';
|
||||
import { PROTOCOL_VERSION, type InitializeResponse } from '@agentclientprotocol/sdk';
|
||||
import packageJson from '../../package.json';
|
||||
import {
|
||||
handleAcpGooseSessionNotification,
|
||||
@@ -14,8 +14,13 @@ import { requestAcpElicitation } from './elicitationRequests';
|
||||
import { requestAcpPermission } from './permissionRequests';
|
||||
import { requestAcpRecipeParams } from './recipeParamRequests';
|
||||
|
||||
let clientPromise: Promise<GooseClient> | null = null;
|
||||
let resolvedClient: GooseClient | null = null;
|
||||
type InitializedAcpClient = {
|
||||
client: GooseClient;
|
||||
initializeResponse: InitializeResponse;
|
||||
};
|
||||
|
||||
let clientPromise: Promise<InitializedAcpClient> | null = null;
|
||||
let resolvedClient: InitializedAcpClient | null = null;
|
||||
|
||||
function createClientCallbacks(): () => GooseClientCallbacks {
|
||||
return () => ({
|
||||
@@ -39,7 +44,7 @@ function monitorConnection(client: GooseClient): void {
|
||||
});
|
||||
}
|
||||
|
||||
async function initializeConnection(): Promise<GooseClient> {
|
||||
async function initializeConnection(): Promise<InitializedAcpClient> {
|
||||
const wsUrl = await window.electron.getAcpUrl();
|
||||
if (!wsUrl) {
|
||||
throw new Error('ACP URL is not available');
|
||||
@@ -48,7 +53,7 @@ async function initializeConnection(): Promise<GooseClient> {
|
||||
const stream = createWebSocketStream(wsUrl);
|
||||
const client = new GooseClient(createClientCallbacks(), stream);
|
||||
|
||||
await client.initialize({
|
||||
const initializeResponse = await client.initialize({
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
clientCapabilities: {
|
||||
elicitation: { form: {} },
|
||||
@@ -67,19 +72,35 @@ async function initializeConnection(): Promise<GooseClient> {
|
||||
});
|
||||
|
||||
monitorConnection(client);
|
||||
return client;
|
||||
return { client, initializeResponse };
|
||||
}
|
||||
|
||||
export async function getAcpClient(): Promise<GooseClient> {
|
||||
return (await getInitializedAcpClient()).client;
|
||||
}
|
||||
|
||||
export function getAcpClientSync(): GooseClient | null {
|
||||
return resolvedClient?.client ?? null;
|
||||
}
|
||||
|
||||
export async function getAcpInitializeResponse(): Promise<InitializeResponse> {
|
||||
return (await getInitializedAcpClient()).initializeResponse;
|
||||
}
|
||||
|
||||
export function isAcpClientReady(): boolean {
|
||||
return resolvedClient !== null;
|
||||
}
|
||||
|
||||
async function getInitializedAcpClient(): Promise<InitializedAcpClient> {
|
||||
if (resolvedClient) {
|
||||
return resolvedClient;
|
||||
}
|
||||
|
||||
if (!clientPromise) {
|
||||
clientPromise = initializeConnection()
|
||||
.then((client) => {
|
||||
resolvedClient = client;
|
||||
return client;
|
||||
.then((clientState) => {
|
||||
resolvedClient = clientState;
|
||||
return clientState;
|
||||
})
|
||||
.catch((error) => {
|
||||
clientPromise = null;
|
||||
@@ -89,11 +110,3 @@ export async function getAcpClient(): Promise<GooseClient> {
|
||||
|
||||
return clientPromise;
|
||||
}
|
||||
|
||||
export function getAcpClientSync(): GooseClient | null {
|
||||
return resolvedClient;
|
||||
}
|
||||
|
||||
export function isAcpClientReady(): boolean {
|
||||
return resolvedClient !== null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { InitializeResponse } from '@agentclientprotocol/sdk';
|
||||
import { getAcpInitializeResponse } from './acpConnection';
|
||||
|
||||
export interface AcpFeatureCapabilities {
|
||||
localInference: boolean;
|
||||
}
|
||||
|
||||
export async function getAcpFeatureCapabilities(): Promise<AcpFeatureCapabilities> {
|
||||
const initializeResponse = await getAcpInitializeResponse();
|
||||
|
||||
return {
|
||||
localInference: hasLocalInferenceCapability(initializeResponse),
|
||||
};
|
||||
}
|
||||
|
||||
export function hasLocalInferenceCapability(
|
||||
initializeResponse: Pick<InitializeResponse, 'agentCapabilities'>
|
||||
): boolean {
|
||||
const agentCapabilities = initializeResponse.agentCapabilities;
|
||||
if (!agentCapabilities) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const meta = agentCapabilities._meta;
|
||||
if (!isRecord(meta)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const goose = meta.goose;
|
||||
if (!isRecord(goose)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'localInference' in goose;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -539,15 +539,6 @@ export type ExtensionResponse = {
|
||||
warnings?: Array<string>;
|
||||
};
|
||||
|
||||
export type FeaturesResponse = {
|
||||
/**
|
||||
* Map of feature name to enabled status
|
||||
*/
|
||||
features: {
|
||||
[key: string]: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export type ForkRequest = {
|
||||
copy: boolean;
|
||||
timestamp?: number | null;
|
||||
@@ -3135,22 +3126,6 @@ export type TranscribeDictationResponses = {
|
||||
|
||||
export type TranscribeDictationResponse = TranscribeDictationResponses[keyof TranscribeDictationResponses];
|
||||
|
||||
export type GetFeaturesData = {
|
||||
body?: never;
|
||||
path?: never;
|
||||
query?: never;
|
||||
url: '/features';
|
||||
};
|
||||
|
||||
export type GetFeaturesResponses = {
|
||||
/**
|
||||
* Compile-time feature flags
|
||||
*/
|
||||
200: FeaturesResponse;
|
||||
};
|
||||
|
||||
export type GetFeaturesResponse = GetFeaturesResponses[keyof GetFeaturesResponses];
|
||||
|
||||
export type StartNanogptSetupData = {
|
||||
body?: never;
|
||||
path?: never;
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
import { createContext, useContext, useEffect, useState, useMemo } from 'react';
|
||||
import { getFeatures } from '../api';
|
||||
import { getAcpFeatureCapabilities } from '../acp/capabilities';
|
||||
|
||||
interface FeaturesContextValue {
|
||||
localInference: boolean;
|
||||
codeMode: boolean;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
const FeaturesContext = createContext<FeaturesContextValue | null>(null);
|
||||
|
||||
export function FeaturesProvider({ children }: { children: React.ReactNode }) {
|
||||
const [features, setFeatures] = useState<Record<string, boolean>>({});
|
||||
const [localInference, setLocalInference] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const response = await getFeatures({ throwOnError: false });
|
||||
if (response.data) {
|
||||
setFeatures(response.data.features);
|
||||
}
|
||||
const capabilities = await getAcpFeatureCapabilities();
|
||||
setLocalInference(capabilities.localInference);
|
||||
} catch (error) {
|
||||
console.warn('[FeaturesContext] Failed to fetch features:', error);
|
||||
} finally {
|
||||
@@ -30,11 +27,10 @@ export function FeaturesProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const value = useMemo<FeaturesContextValue>(
|
||||
() => ({
|
||||
localInference: features['local-inference'] ?? false,
|
||||
codeMode: features['code-mode'] ?? true,
|
||||
localInference,
|
||||
isLoading,
|
||||
}),
|
||||
[features, isLoading]
|
||||
[localInference, isLoading]
|
||||
);
|
||||
|
||||
return <FeaturesContext.Provider value={value}>{children}</FeaturesContext.Provider>;
|
||||
|
||||
Reference in New Issue
Block a user