Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.9 KB
Raw Blame
import { throwOnErr } from '@core/util/result';
import { agentHarnessServiceClient } from '@service-agent-harness/client';
import type { DiscoverAgentCapabilitiesRequest } from '@service-agent-harness/generated/schemas';
import { queryOptions, useQuery } from '@tanstack/solid-query';

function agentCapabilitiesQueryOptions(
  request: DiscoverAgentCapabilitiesRequest | undefined
) {
  return queryOptions({
    queryKey: ['agent-capabilities', request ?? null] as const,
    queryFn: async ({ signal }: { signal: AbortSignal }) => {
      if (!request) throw new Error('No capability target');
      const response = await throwOnErr(() =>
        agentHarnessServiceClient.discoverAgentCapabilities(request, signal)
      );
      return {
        configOptions: response.configOptions.map((option) => {
          const common = {
            id: option.id,
            name: option.name,
            description: option.description ?? null,
            category: option.category ?? null,
          };
          if (option.type === 'select')
            return {
              ...common,
              type: option.type,
              currentValue: option.currentValue,
              options: option.options.map((value) => ({
                ...value,
                description: value.description ?? null,
                group: value.group ?? null,
              })),
            };
          return {
            ...common,
            type: option.type,
            currentValue: option.currentValue,
          };
        }),
      };
    },
    enabled: request !== undefined,
    staleTime: 0,
    gcTime: 0,
    retry: false,
  });
}

/** Capabilities belong to a harness and selected model, never a provider alone. */
export function useAgentCapabilitiesQuery(
  target: () => DiscoverAgentCapabilitiesRequest | undefined
) {
  return useQuery(() => agentCapabilitiesQueryOptions(target()));
}