summaryrefslogtreecommitdiff
path: root/src/jet/action-handlers/compound-action.ts
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /src/jet/action-handlers/compound-action.ts
init commit
Diffstat (limited to 'src/jet/action-handlers/compound-action.ts')
-rw-r--r--src/jet/action-handlers/compound-action.ts33
1 files changed, 33 insertions, 0 deletions
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';
+ });
+}