feat: used acp agent capabilities for local Inference support check (#9996)
This commit is contained in:
@@ -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