Files
WeHub Mirror 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
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

176 lines
5.7 KiB
TypeScript

import type { ComponentType } from 'react'
import { Loader } from '@sim/emcn'
import { FileText } from '@sim/emcn/icons'
import { Read as ReadTool } from '@/lib/copilot/generated/tool-catalog-v1'
import { VFS_DIR_TO_RESOURCE } from '@/lib/copilot/resources/types'
import { isToolHiddenInUi } from '@/lib/copilot/tools/client/hidden-tools'
import { getReadTargetBlock } from '@/lib/copilot/tools/client/read-block'
import { ClientToolCallState } from '@/lib/copilot/tools/client/tool-call-state'
import { humanizeDisplayIdentifier, humanizeToolName } from '@/lib/copilot/tools/tool-display'
import { decodeVfsSegmentSafe } from '@/lib/copilot/vfs/path-utils'
/** Respond tools are internal handoff tools shown with a friendly generic label. */
const HIDDEN_TOOL_SUFFIX = '_respond'
const INTERNAL_RESPOND_TOOL = 'respond'
interface ClientToolDisplay {
text: string
icon: ComponentType<{ className?: string }>
}
export function resolveToolDisplay(
toolName: string | undefined,
state: ClientToolCallState,
params?: Record<string, unknown>
): ClientToolDisplay | undefined {
if (!toolName) return undefined
if (isToolHiddenInUi(toolName)) return undefined
const specialDisplay = specialToolDisplay(toolName, state, params)
if (specialDisplay) return specialDisplay
return humanizedFallback(toolName, state)
}
function specialToolDisplay(
toolName: string,
state: ClientToolCallState,
params?: Record<string, unknown>
): ClientToolDisplay | undefined {
if (toolName === INTERNAL_RESPOND_TOOL || toolName.endsWith(HIDDEN_TOOL_SUFFIX)) {
return {
text: formatRespondLabel(state),
icon: Loader,
}
}
if (toolName === ReadTool.id) {
const target = describeReadTarget(readStringParam(params, 'path'))
return {
text: formatReadingLabel(target, state),
icon: FileText,
}
}
return undefined
}
function formatRespondLabel(state: ClientToolCallState): string {
void state
return 'Gathering thoughts'
}
function readStringParam(
params: Record<string, unknown> | undefined,
key: string
): string | undefined {
const value = params?.[key]
return typeof value === 'string' && value.trim() ? value.trim() : undefined
}
function formatReadingLabel(target: string | undefined, state: ClientToolCallState): string {
const suffix = ` ${target || 'file'}`
switch (state) {
case ClientToolCallState.success:
return `Read${suffix}`
case ClientToolCallState.error:
return `Attempted to read${suffix}`
case ClientToolCallState.rejected:
case ClientToolCallState.aborted:
return `Skipped reading${suffix}`
default:
return `Reading${suffix}`
}
}
function describeReadTarget(path: string | undefined): string | undefined {
if (!path) return undefined
const block = getReadTargetBlock(path)
if (block) return block.name
const segments = path
.split('/')
.map((segment) => segment.trim())
.filter(Boolean)
.map(decodeVfsSegmentSafe)
if (segments.length === 0) return undefined
const resourceType = VFS_DIR_TO_RESOURCE[segments[0]]
if (!resourceType) {
return humanizeDisplayIdentifier(stripExtension(segments[segments.length - 1]), 'sentence')
}
if (resourceType === 'file') {
return describeFileReadTarget(segments)
}
if (resourceType === 'workflow') {
return stripExtension(getLeafResourceSegment(segments))
}
const resourceName = segments[1] || segments[segments.length - 1]
return stripExtension(resourceName)
}
// A workspace file is addressed as a directory of facets in the VFS
// (files/{...path}/{name}/{facet}). `content` is the default facet — reading a
// file means reading its content — so it carries no qualifier, matching a bare
// `files/{...path}/{name}` read. The remaining facets are genuinely distinct, so
// they keep a descriptive label.
const FILE_FACET_LABELS: Record<string, string> = {
content: '',
'meta.json': 'metadata for',
style: 'style details for',
'compiled-check': 'the final file check for',
}
function describeFileReadTarget(segments: string[]): string {
const lastSegment = segments[segments.length - 1] || ''
const facetLabel = FILE_FACET_LABELS[lastSegment]
// Treat the suffix as a facet only when a real file name precedes it; otherwise
// the leaf is the file itself (e.g. a file literally named "content").
if (facetLabel !== undefined && segments.length > 2) {
const fileName = segments[segments.length - 2]
return facetLabel ? `${facetLabel} ${fileName}` : fileName
}
// Show just the file name, not the folder path — these are glanceable status
// lines, and the other resource types already render the leaf only.
return lastSegment
}
function getLeafResourceSegment(segments: string[]): string {
const lastSegment = segments[segments.length - 1] || ''
if (hasFileExtension(lastSegment) && segments.length > 1) {
return segments[segments.length - 2] || lastSegment
}
return lastSegment
}
function hasFileExtension(value: string): boolean {
return /\.[^/.]+$/.test(value)
}
function stripExtension(value: string): string {
return value.replace(/\.[^/.]+$/, '')
}
function humanizedFallback(
toolName: string,
state: ClientToolCallState
): ClientToolDisplay | undefined {
const titleCaseName = humanizeToolName(toolName)
if (state === ClientToolCallState.error) {
const lowerCaseName = humanizeDisplayIdentifier(toolName, 'sentence')
return { text: `Attempted to ${lowerCaseName}`, icon: Loader }
}
const stateVerb =
state === ClientToolCallState.success
? 'Executed'
: state === ClientToolCallState.rejected || state === ClientToolCallState.aborted
? 'Skipped'
: 'Executing'
return { text: `${stateVerb} ${titleCaseName}`, icon: Loader }
}