From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- src/jet/action-handlers/compound-action.ts | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/jet/action-handlers/compound-action.ts (limited to 'src/jet/action-handlers/compound-action.ts') diff --git a/src/jet/action-handlers/compound-action.ts b/src/jet/action-handlers/compound-action.ts new file mode 100644 index 0000000..9cf1be0 --- /dev/null +++ b/src/jet/action-handlers/compound-action.ts @@ -0,0 +1,33 @@ +import type { LoggerFactory } from '@amp/web-apps-logger'; +import type { Jet } from '~/jet'; +import type { CompoundAction } from '~/jet/models'; + +export type Dependencies = { + jet: Jet; + logger: LoggerFactory; +}; + +export async function registerHandler(dependencies: Dependencies) { + const { jet, logger } = dependencies; + + const log = logger.loggerFor('jet/action-handlers/compound-action'); + + jet.onAction('compoundAction', async (action: CompoundAction) => { + log.info('received CompoundAction:', action); + + const { subactions = [] } = action; + + // Perform actions in sequence + for (const action of subactions) { + await jet.perform(action).catch((e) => { + // Throwing error stops for...of execution + // TODO: rdar://73165545 (Error Handling Across App) + throw new Error( + `an error occurred while handling CompoundAction: ${e}`, + ); + }); + } + + return 'performed'; + }); +} -- cgit v1.2.3