Restructure ultrawork message generation to support agent-specific instructions. - Extract ultrawork message components into modular constants - Add getUltraworkMessage(agentName) function that adapts instructions based on agent type - Support planner-specific vs default agent execution patterns - Pass agentName parameter through detector.ts for message resolution 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import {
|
|
KEYWORD_DETECTORS,
|
|
CODE_BLOCK_PATTERN,
|
|
INLINE_CODE_PATTERN,
|
|
} from "./constants"
|
|
|
|
export interface DetectedKeyword {
|
|
type: "ultrawork" | "search" | "analyze"
|
|
message: string
|
|
}
|
|
|
|
export function removeCodeBlocks(text: string): string {
|
|
return text.replace(CODE_BLOCK_PATTERN, "").replace(INLINE_CODE_PATTERN, "")
|
|
}
|
|
|
|
/**
|
|
* Resolves message to string, handling both static strings and dynamic functions.
|
|
*/
|
|
function resolveMessage(
|
|
message: string | ((agentName?: string) => string),
|
|
agentName?: string
|
|
): string {
|
|
return typeof message === "function" ? message(agentName) : message
|
|
}
|
|
|
|
export function detectKeywords(text: string, agentName?: string): string[] {
|
|
const textWithoutCode = removeCodeBlocks(text)
|
|
return KEYWORD_DETECTORS.filter(({ pattern }) =>
|
|
pattern.test(textWithoutCode)
|
|
).map(({ message }) => resolveMessage(message, agentName))
|
|
}
|
|
|
|
export function detectKeywordsWithType(text: string, agentName?: string): DetectedKeyword[] {
|
|
const textWithoutCode = removeCodeBlocks(text)
|
|
const types: Array<"ultrawork" | "search" | "analyze"> = ["ultrawork", "search", "analyze"]
|
|
return KEYWORD_DETECTORS.map(({ pattern, message }, index) => ({
|
|
matches: pattern.test(textWithoutCode),
|
|
type: types[index],
|
|
message: resolveMessage(message, agentName),
|
|
}))
|
|
.filter((result) => result.matches)
|
|
.map(({ type, message }) => ({ type, message }))
|
|
}
|
|
|
|
export function extractPromptText(
|
|
parts: Array<{ type: string; text?: string }>
|
|
): string {
|
|
return parts
|
|
.filter((p) => p.type === "text")
|
|
.map((p) => p.text || "")
|
|
.join(" ")
|
|
}
|