Download packages/agent-core-v2/src/session/agentLifecycle/subagentMetadata.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/session/agentLifecycle/subagentMetadata.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/agent-core-v2/src/session/agentLifecycle/subagentMetadata.ts
-
curl -L -o subagentMetadata.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/session/agentLifecycle/subagentMetadata.ts
2.16 kB
| import type { AgentMeta } from '#/session/sessionMetadata/sessionMetadata'; | |
| export function subagentLabels( | |
| parentAgentId: string, | |
| options: { readonly swarmItem?: string } = {}, | |
| ): Readonly<Record<string, string>> { | |
| const labels: Record<string, string> = { parentAgentId }; | |
| if (options.swarmItem !== undefined) { | |
| labels['swarmItem'] = options.swarmItem; | |
| } | |
| return labels; | |
| } | |
| export function withSubagentProfile( | |
| labels: Readonly<Record<string, string>> | undefined, | |
| profileName: string | undefined, | |
| ): Readonly<Record<string, string>> | undefined { | |
| if (profileName === undefined || profileName.length === 0) return labels; | |
| return { ...labels, profileName }; | |
| } | |
| export function labelsFromAgentMeta( | |
| meta: AgentMeta, | |
| ): Readonly<Record<string, string>> | undefined { | |
| const labels: Record<string, string> = { ...meta.labels }; | |
| const parentAgentId = subagentParentAgentId(meta); | |
| if (parentAgentId !== undefined) { | |
| labels['parentAgentId'] = parentAgentId; | |
| } | |
| const swarmItem = subagentSwarmItem(meta); | |
| if (swarmItem !== undefined) { | |
| labels['swarmItem'] = swarmItem; | |
| } | |
| return Object.keys(labels).length > 0 ? labels : undefined; | |
| } | |
| export function isSubagentMeta(meta: AgentMeta | undefined): boolean { | |
| if (meta === undefined) return false; | |
| if (subagentParentAgentId(meta) !== undefined) return true; | |
| return meta.type === 'sub'; | |
| } | |
| export function subagentParentAgentId(meta: AgentMeta | undefined): string | undefined { | |
| if (meta === undefined) return undefined; | |
| return firstNonEmpty(meta.labels?.['parentAgentId'], meta.parentAgentId ?? undefined); | |
| } | |
| export function subagentSwarmItem(meta: AgentMeta | undefined): string | undefined { | |
| if (meta === undefined) return undefined; | |
| return firstNonEmpty(meta.labels?.['swarmItem'], meta.swarmItem); | |
| } | |
| export function subagentProfileName(meta: AgentMeta | undefined): string | undefined { | |
| if (meta === undefined) return undefined; | |
| return firstNonEmpty(meta.labels?.['profileName']); | |
| } | |
| function firstNonEmpty(...values: readonly (string | undefined)[]): string | undefined { | |
| return values.find((value) => value !== undefined && value.length > 0); | |
| } | |