6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
128 lines
4.9 KiB
TypeScript
128 lines
4.9 KiB
TypeScript
import type { BlockVisibilityState } from '@/lib/core/config/block-visibility'
|
|
import { BLOCK_REGISTRY } from '@/blocks/registry-maps'
|
|
import { isHiddenUnder } from '@/blocks/visibility/context'
|
|
import { tools as toolRegistry } from '@/tools/registry'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
import { getLatestVersionTools, stripVersionSuffix } from '@/tools/utils'
|
|
|
|
export interface ExposedIntegrationToolOwner {
|
|
service: string
|
|
blockType: string
|
|
preview?: boolean
|
|
}
|
|
|
|
export interface ExposedIntegrationTool extends ExposedIntegrationToolOwner {
|
|
/**
|
|
* Full registry tool id — also the agent-callable id and the schema `id`
|
|
* field (e.g. gmail_read_v2). No stripping: discovery, the schema id, and the
|
|
* callable id are all this exact value, matching the block's tools.access.
|
|
*/
|
|
toolId: string
|
|
config: ToolConfig
|
|
/** Service directory name, e.g. "gmail". */
|
|
service: string
|
|
/** Operation stem within the service (used for the VFS path filename), e.g. "read". */
|
|
operation: string
|
|
/** Owning block's registry type — the key block-visibility rules gate on. */
|
|
blockType: string
|
|
/** Owning block's static `preview` marker, for the per-viewer filter. */
|
|
preview?: boolean
|
|
/** Every visible block that declares this tool, including preview successors. */
|
|
owners: readonly ExposedIntegrationToolOwner[]
|
|
}
|
|
|
|
let cached: ExposedIntegrationTool[] | null = null
|
|
|
|
/**
|
|
* Returns the UNGATED universe of integration tools exposable to the copilot
|
|
* agent: the latest version of each operation owned by a non-`hideFromToolbar`
|
|
* block — INCLUDING unreleased `preview` blocks.
|
|
*
|
|
* Deliberately sourced from the raw `BLOCK_REGISTRY` (never the visibility-
|
|
* projected `getAllBlocks`) so this process-global memo is deterministic and
|
|
* can never be poisoned by whichever viewer's gated projection ran first.
|
|
* Every per-viewer consumer MUST apply {@link filterExposedIntegrationTools}
|
|
* before exposing the set.
|
|
*
|
|
* This is the single source of truth shared by VFS discovery
|
|
* (components/integrations/**) and the deferred callable-tool payload, so the
|
|
* agent can call exactly what it can discover — no orphan callable tools, and no
|
|
* version drift between what the VFS shows and what is loadable.
|
|
*/
|
|
export function getExposedIntegrationTools(): ExposedIntegrationTool[] {
|
|
if (cached) return cached
|
|
|
|
// Map the tool ids each visible block exposes (both the raw id and its
|
|
// version-stripped base name) to that block's service directory + type.
|
|
const toolToBlocks = new Map<string, ExposedIntegrationToolOwner[]>()
|
|
for (const block of Object.values(BLOCK_REGISTRY)) {
|
|
if (block.hideFromToolbar) continue
|
|
if (!block.tools?.access) continue
|
|
const service = stripVersionSuffix(block.type)
|
|
const owner = { service, blockType: block.type, preview: block.preview }
|
|
for (const toolId of block.tools.access) {
|
|
for (const key of [toolId, stripVersionSuffix(toolId)]) {
|
|
const owners = toolToBlocks.get(key)
|
|
if (owners) {
|
|
if (!owners.some((existing) => existing.blockType === owner.blockType)) {
|
|
owners.push(owner)
|
|
}
|
|
} else {
|
|
toolToBlocks.set(key, [owner])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const exposed: ExposedIntegrationTool[] = []
|
|
const seen = new Set<string>()
|
|
for (const [toolId, config] of Object.entries(getLatestVersionTools(toolRegistry))) {
|
|
const baseName = stripVersionSuffix(toolId)
|
|
const owners = toolToBlocks.get(toolId) ?? toolToBlocks.get(baseName)
|
|
if (!owners || owners.length === 0) continue
|
|
const owner = owners.find((candidate) => !candidate.preview) ?? owners[0]
|
|
if (seen.has(baseName)) continue
|
|
seen.add(baseName)
|
|
const prefix = `${owner.service}_`
|
|
const operation = baseName.startsWith(prefix) ? baseName.slice(prefix.length) : baseName
|
|
exposed.push({
|
|
toolId,
|
|
config,
|
|
service: owner.service,
|
|
operation,
|
|
blockType: owner.blockType,
|
|
preview: owner.preview,
|
|
owners,
|
|
})
|
|
}
|
|
|
|
cached = exposed
|
|
return exposed
|
|
}
|
|
|
|
/**
|
|
* Per-viewer projection of the exposed set: drops tools whose owning block is
|
|
* hidden under `vis` (unrevealed preview blocks — including with a null state —
|
|
* and kill-switched types). Apply at every surface that hands the set to a
|
|
* viewer: VFS stamping, the deferred tool payload, `list_integration_tools`.
|
|
*/
|
|
export function filterExposedIntegrationTools(
|
|
tools: ExposedIntegrationTool[],
|
|
vis: BlockVisibilityState | null,
|
|
isOwnerAllowed: (owner: ExposedIntegrationToolOwner) => boolean = () => true
|
|
): ExposedIntegrationTool[] {
|
|
return tools.flatMap((tool) => {
|
|
const owner = tool.owners.find(
|
|
(candidate) =>
|
|
!isHiddenUnder(vis, { type: candidate.blockType, preview: candidate.preview }) &&
|
|
isOwnerAllowed(candidate)
|
|
)
|
|
return owner ? [{ ...tool, ...owner }] : []
|
|
})
|
|
}
|
|
|
|
/** Test-only: clears the memoized set so registry changes are picked up. */
|
|
export function resetExposedIntegrationToolsCache(): void {
|
|
cached = null
|
|
}
|