Files
simstudioai--sim/apps/sim/lib/mothership/skills.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

68 lines
2.8 KiB
TypeScript

import { db, skill } from '@sim/db'
import { createLogger } from '@sim/logger'
import { eq } from 'drizzle-orm'
import type { ToolSchema } from '@/lib/copilot/chat/payload'
const logger = createLogger('MothershipUserSkills')
export const LOAD_USER_SKILL_TOOL_NAME = 'load_user_skill'
/**
* Build the single load_user_skill tool that exposes all workspace
* user-created skills to the mothership and its subagents.
*
* User skills live in the `skill` table (builtins are code-only and are treated
* as defaults, so they are excluded here). The tool is a non-deferred,
* sim-executed request-local tool: when the model calls it, Go forwards the
* call and sim resolves the content via resolveSkillContent (see tools/index.ts).
* It is available to all users — there is no super-admin gate, unlike the curated
* mothership_settings tools.
*
* Embedded copilot/internal skills are not handled here: those are autoloaded
* into each agent's system prompt on the Go side and never sent as loadable.
*/
export async function buildUserSkillTool(workspaceId: string): Promise<ToolSchema | null> {
if (!workspaceId) return null
let rows: { name: string; description: string }[]
try {
rows = await db
.select({ name: skill.name, description: skill.description })
.from(skill)
.where(eq(skill.workspaceId, workspaceId))
} catch (error) {
logger.error('Failed to load workspace skills for load_user_skill tool', { error, workspaceId })
return null
}
if (rows.length === 0) return null
const skillNames = rows.map((r) => r.name)
const catalog = rows.map((r) => `- ${r.name}: ${r.description}`).join('\n')
return {
name: LOAD_USER_SKILL_TOOL_NAME,
description: `Load a user-created skill's full instructions. You MUST call this before following a skill: the list below only tells you which skills exist and when each applies — it is NOT the instructions. To use a skill, call load_user_skill with its exact name and follow the content it returns; never act on a skill's name or description alone. Available skills:\n${catalog}`,
input_schema: {
type: 'object',
properties: {
skill_name: {
type: 'string',
description: 'Exact name of the user skill to load.',
enum: skillNames,
},
},
required: ['skill_name'],
additionalProperties: false,
},
// Do NOT set executeLocally: skill content is resolved on the sim backend
// (DB), so Go must dispatch this with executor "sim". executeLocally maps to
// ClientExecutable, which routes the call to the browser client (no handler)
// and the load hangs. mothershipToolKind 'skill' is enough for sim routing.
params: {
mothershipToolKind: 'skill',
mothershipToolName: LOAD_USER_SKILL_TOOL_NAME,
},
}
}