mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
docs: document mobile session hooks, plugin test helpers, and viewport detection
This commit is contained in:
1 parent
b974618dee
commit
f80aa1c0e5
5 files changed
+14
No files matched your search
@@ -147,6 +147,7 @@ function buildManagerToolDescription(): string {
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
/** Builds the standalone manager plugin with API actions and mobile session hooks. */
|
||||
export function buildManagerToolPluginSource(id: string): string {
|
||||
return `var REQUEST_TIMEOUT_MS = ${MANAGER_TOOL_REQUEST_TIMEOUT_MS}
|
||||
|
||||
@@ -174,6 +175,7 @@ var MOBILE_OUTPUT_INSTRUCTIONS = ${JSON.stringify(MANAGER_MOBILE_OUTPUT_INSTRUCT
|
||||
|
||||
var MOBILE_SESSIONS = new Set()
|
||||
|
||||
/** Updates mobile mode from explicit client metadata, preserving it when metadata is absent. */
|
||||
function trackMobileSession(event) {
|
||||
var client = event.metadata && event.metadata[CLIENT_METADATA_KEY]
|
||||
if (client === MOBILE_CLIENT) {
|
||||
@@ -183,6 +185,7 @@ function trackMobileSession(event) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Appends mobile reply guidance to the context of a tracked mobile session. */
|
||||
function addMobileOutputInstructions(event) {
|
||||
if (MOBILE_SESSIONS.has(event.sessionID)) {
|
||||
event.system.push({ type: 'text', text: MOBILE_OUTPUT_INSTRUCTIONS })
|
||||
@@ -329,6 +332,7 @@ async function runAction(input, context) {
|
||||
|
||||
export default {
|
||||
id: '${id}',
|
||||
/** Registers session hooks and exposes the manager tool through the plugin context. */
|
||||
async setup(ctx) {
|
||||
await ctx.session.hook('prompt', trackMobileSession)
|
||||
await ctx.session.hook('context', addMobileOutputInstructions)
|
||||
|
||||
@@ -106,6 +106,7 @@ function createRegistry<Event>(name: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a test plugin context with hook registries, event triggers, and tool transforms. */
|
||||
function createPluginContext() {
|
||||
const shellCreateBefore = createRegistry<ShellCreateBeforeEvent>('create.before')
|
||||
const toolExecuteAfter = createRegistry<ToolExecuteAfterEvent>('execute.after')
|
||||
@@ -138,6 +139,7 @@ function createPluginContext() {
|
||||
},
|
||||
},
|
||||
session: {
|
||||
/** Registers prompt or context callbacks, rejecting unsupported session hook names. */
|
||||
hook: async (name, callback) => {
|
||||
if (name === 'prompt') return sessionPrompt.register(callback as SessionPromptHookCallback)
|
||||
if (name === 'context') return sessionContext.register(callback as SessionContextHookCallback)
|
||||
@@ -151,7 +153,9 @@ function createPluginContext() {
|
||||
triggerShellCreateBefore: (event: ShellCreateBeforeEvent) => shellCreateBefore.trigger(event),
|
||||
triggerToolExecuteAfter: (event: ToolExecuteAfterEvent) => toolExecuteAfter.trigger(event),
|
||||
triggerPermissionEvaluate: (event: PermissionEvaluateEvent) => permissionEvaluate.trigger(event),
|
||||
/** Dispatches a prompt event to the registered session callbacks. */
|
||||
triggerSessionPrompt: (event: SessionPromptEvent) => sessionPrompt.trigger(event),
|
||||
/** Dispatches a context event so registered callbacks can update it. */
|
||||
triggerSessionContext: (event: SessionContextEvent) => sessionContext.trigger(event),
|
||||
registeredTools: () => {
|
||||
const tools: GeneratedTool[] = []
|
||||
@@ -164,6 +168,7 @@ function createPluginContext() {
|
||||
|
||||
let importCount = 0
|
||||
|
||||
/** Imports a fresh plugin instance, validates its definition, and runs setup in the test context. */
|
||||
export async function loadGeneratedPlugin(file: string): Promise<GeneratedPlugin> {
|
||||
importCount += 1
|
||||
const imported = (await import(`${pathToFileURL(file).href}?ocm-test=${importCount}`)) as { default?: unknown }
|
||||
|
||||
@@ -33,6 +33,7 @@ type JsonSchema = {
|
||||
minLength?: number
|
||||
}
|
||||
|
||||
/** Loads the installed manager plugin from the supplied configuration home for hook tests. */
|
||||
async function loadManagerPlugin(configHome: string): Promise<GeneratedPlugin> {
|
||||
return loadGeneratedPlugin(path.join(getOpenCodePluginDir(configHome), 'ocm-manager.js'))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user