asyar-sdk 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +165 -0
- package/dist/ExtensionBridge.d.ts +34 -0
- package/dist/ExtensionBridge.d.ts.map +1 -0
- package/dist/ExtensionBridge.js +192 -0
- package/dist/ExtensionBridge.js.map +1 -0
- package/dist/ExtensionContext.d.ts +25 -0
- package/dist/ExtensionContext.d.ts.map +1 -0
- package/dist/ExtensionContext.js +128 -0
- package/dist/ExtensionContext.js.map +1 -0
- package/dist/cli/commands/build.d.ts +5 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +122 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +3 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +85 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/link.d.ts +6 -0
- package/dist/cli/commands/link.d.ts.map +1 -0
- package/dist/cli/commands/link.js +153 -0
- package/dist/cli/commands/link.js.map +1 -0
- package/dist/cli/commands/publish.d.ts +3 -0
- package/dist/cli/commands/publish.d.ts.map +1 -0
- package/dist/cli/commands/publish.js +344 -0
- package/dist/cli/commands/publish.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +3 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +58 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +20 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/lib/auth.d.ts +16 -0
- package/dist/cli/lib/auth.d.ts.map +1 -0
- package/dist/cli/lib/auth.js +225 -0
- package/dist/cli/lib/auth.js.map +1 -0
- package/dist/cli/lib/config.d.ts +11 -0
- package/dist/cli/lib/config.d.ts.map +1 -0
- package/dist/cli/lib/config.js +77 -0
- package/dist/cli/lib/config.js.map +1 -0
- package/dist/cli/lib/github.d.ts +44 -0
- package/dist/cli/lib/github.d.ts.map +1 -0
- package/dist/cli/lib/github.js +106 -0
- package/dist/cli/lib/github.js.map +1 -0
- package/dist/cli/lib/manifest.d.ts +29 -0
- package/dist/cli/lib/manifest.d.ts.map +1 -0
- package/dist/cli/lib/manifest.js +138 -0
- package/dist/cli/lib/manifest.js.map +1 -0
- package/dist/cli/lib/platform.d.ts +2 -0
- package/dist/cli/lib/platform.d.ts.map +1 -0
- package/dist/cli/lib/platform.js +40 -0
- package/dist/cli/lib/platform.js.map +1 -0
- package/dist/cli/lib/store.d.ts +21 -0
- package/dist/cli/lib/store.d.ts.map +1 -0
- package/dist/cli/lib/store.js +81 -0
- package/dist/cli/lib/store.js.map +1 -0
- package/dist/cli/lib/zip.d.ts +7 -0
- package/dist/cli/lib/zip.d.ts.map +1 -0
- package/dist/cli/lib/zip.js +67 -0
- package/dist/cli/lib/zip.js.map +1 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +25 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/MessageBroker.d.ts +30 -0
- package/dist/ipc/MessageBroker.d.ts.map +1 -0
- package/dist/ipc/MessageBroker.js +118 -0
- package/dist/ipc/MessageBroker.js.map +1 -0
- package/dist/services/ActionServiceProxy.d.ts +17 -0
- package/dist/services/ActionServiceProxy.d.ts.map +1 -0
- package/dist/services/ActionServiceProxy.js +60 -0
- package/dist/services/ActionServiceProxy.js.map +1 -0
- package/dist/services/ClipboardHistoryServiceProxy.d.ts +26 -0
- package/dist/services/ClipboardHistoryServiceProxy.d.ts.map +1 -0
- package/dist/services/ClipboardHistoryServiceProxy.js +74 -0
- package/dist/services/ClipboardHistoryServiceProxy.js.map +1 -0
- package/dist/services/CommandServiceProxy.d.ts +15 -0
- package/dist/services/CommandServiceProxy.d.ts.map +1 -0
- package/dist/services/CommandServiceProxy.js +44 -0
- package/dist/services/CommandServiceProxy.js.map +1 -0
- package/dist/services/ExtensionManagerProxy.d.ts +25 -0
- package/dist/services/ExtensionManagerProxy.d.ts.map +1 -0
- package/dist/services/ExtensionManagerProxy.js +78 -0
- package/dist/services/ExtensionManagerProxy.js.map +1 -0
- package/dist/services/IClipboardHistoryService.d.ts +24 -0
- package/dist/services/IClipboardHistoryService.d.ts.map +1 -0
- package/dist/services/IClipboardHistoryService.js +3 -0
- package/dist/services/IClipboardHistoryService.js.map +1 -0
- package/dist/services/ICommandService.d.ts +10 -0
- package/dist/services/ICommandService.d.ts.map +1 -0
- package/dist/services/ICommandService.js +3 -0
- package/dist/services/ICommandService.js.map +1 -0
- package/dist/services/IExtensionManager.d.ts +26 -0
- package/dist/services/IExtensionManager.d.ts.map +1 -0
- package/dist/services/IExtensionManager.js +3 -0
- package/dist/services/IExtensionManager.js.map +1 -0
- package/dist/services/INotificationService.d.ts +15 -0
- package/dist/services/INotificationService.d.ts.map +1 -0
- package/dist/services/INotificationService.js +3 -0
- package/dist/services/INotificationService.js.map +1 -0
- package/dist/services/IStatusBarService.d.ts +11 -0
- package/dist/services/IStatusBarService.d.ts.map +1 -0
- package/dist/services/IStatusBarService.js +3 -0
- package/dist/services/IStatusBarService.js.map +1 -0
- package/dist/services/LogService.d.ts +8 -0
- package/dist/services/LogService.d.ts.map +1 -0
- package/dist/services/LogService.js +3 -0
- package/dist/services/LogService.js.map +1 -0
- package/dist/services/LogServiceProxy.d.ts +13 -0
- package/dist/services/LogServiceProxy.d.ts.map +1 -0
- package/dist/services/LogServiceProxy.js +33 -0
- package/dist/services/LogServiceProxy.js.map +1 -0
- package/dist/services/NetworkServiceProxy.d.ts +9 -0
- package/dist/services/NetworkServiceProxy.d.ts.map +1 -0
- package/dist/services/NetworkServiceProxy.js +37 -0
- package/dist/services/NetworkServiceProxy.js.map +1 -0
- package/dist/services/NotificationServiceProxy.d.ts +17 -0
- package/dist/services/NotificationServiceProxy.d.ts.map +1 -0
- package/dist/services/NotificationServiceProxy.js +42 -0
- package/dist/services/NotificationServiceProxy.js.map +1 -0
- package/dist/services/StatusBarServiceProxy.d.ts +11 -0
- package/dist/services/StatusBarServiceProxy.d.ts.map +1 -0
- package/dist/services/StatusBarServiceProxy.js +28 -0
- package/dist/services/StatusBarServiceProxy.js.map +1 -0
- package/dist/services/index.d.ts +15 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +35 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/ActionType.d.ts +64 -0
- package/dist/types/ActionType.d.ts.map +1 -0
- package/dist/types/ActionType.js +47 -0
- package/dist/types/ActionType.js.map +1 -0
- package/dist/types/ClipboardType.d.ts +20 -0
- package/dist/types/ClipboardType.d.ts.map +1 -0
- package/dist/types/ClipboardType.js +13 -0
- package/dist/types/ClipboardType.js.map +1 -0
- package/dist/types/CommandType.d.ts +36 -0
- package/dist/types/CommandType.d.ts.map +1 -0
- package/dist/types/CommandType.js +3 -0
- package/dist/types/CommandType.js.map +1 -0
- package/dist/types/ExtensionType.d.ts +50 -0
- package/dist/types/ExtensionType.d.ts.map +1 -0
- package/dist/types/ExtensionType.js +3 -0
- package/dist/types/ExtensionType.js.map +1 -0
- package/dist/types/NetworkType.d.ts +17 -0
- package/dist/types/NetworkType.d.ts.map +1 -0
- package/dist/types/NetworkType.js +3 -0
- package/dist/types/NetworkType.js.map +1 -0
- package/dist/types/NotificationType.d.ts +48 -0
- package/dist/types/NotificationType.d.ts.map +1 -0
- package/dist/types/NotificationType.js +3 -0
- package/dist/types/NotificationType.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Asyar API SDK
|
|
2
|
+
|
|
3
|
+
This package (`asyar-sdk`) provides the Software Development Kit (SDK) for building extensions for the [Asyar application](https://github.com/Xoshbin/asyar). It defines the core interfaces, types, and services that extensions interact with.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
The Asyar API enables developers to create extensions that integrate seamlessly with the Asyar core application. It provides access to essential services like logging, extension management, action handling, clipboard history, and notifications.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
To install the necessary dependencies for development or usage within the main Asyar project, use pnpm:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Building
|
|
18
|
+
|
|
19
|
+
To compile the TypeScript source code into JavaScript, run the build script:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm run build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This will generate the output files in the `dist/` directory as specified in `tsconfig.json`.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
This SDK is the bridge allowing Asyar extensions to interact with the Host Application. It dynamically adapts its behavior based on the execution context of the extension utilizing it.
|
|
30
|
+
|
|
31
|
+
Refer to the main [Asyar Architecture Guide](../../docs/extension-architecture.md) for detailed instructions on building extensions.
|
|
32
|
+
|
|
33
|
+
### Dual-Tier Architecture Support
|
|
34
|
+
|
|
35
|
+
The SDK supports two distinct environments seamlessly:
|
|
36
|
+
|
|
37
|
+
1. **Tier 1 (Built-in Extensions):**
|
|
38
|
+
* These extensions run directly inside the main Asyar Window context.
|
|
39
|
+
* The SDK bypasses strict `<iframe>` security verifications.
|
|
40
|
+
* `MessageBroker` requests automatically resolve against Host services synchronously.
|
|
41
|
+
2. **Tier 2 (Installed Extensions):**
|
|
42
|
+
* These extensions are executed within strictly isolated, secure `<iframe>` sandboxes.
|
|
43
|
+
* The SDK transparently serializes all Native SDK queries (such as navigating to a view, throwing a notification, checking the clipboard) into remote `postMessage` IPC payloads.
|
|
44
|
+
* The Host Application intercepts these simulated payloads, validates the iframe's `extensionId`, unpacks the variables via positional mapping, and returns a Promise.
|
|
45
|
+
|
|
46
|
+
> [!WARNING]
|
|
47
|
+
> **IPC Payload Requirements for SDK Contributors:**
|
|
48
|
+
> When adding new proxy boundaries to `ExtensionManagerProxy`, you MUST send payloads as named-key property objects where keys correspond to the Host's parameter names in order (e.g., `broker.invoke('method', { query, limit })`).
|
|
49
|
+
> Sending raw primitives will cause the generic deserializer inside the Asyar Host to convert the argument into `"[object Object]"`, silently breaking the pipeline.
|
|
50
|
+
|
|
51
|
+
Key exports include:
|
|
52
|
+
|
|
53
|
+
* **Interfaces:** `Extension`, `ExtensionContext`, `ILogService`, `IExtensionManager`, `IActionService`, `IClipboardHistoryService`, `INotificationService`, `IStatusBarService`, etc.
|
|
54
|
+
* **Types:** `ExtensionResult`, `ExtensionAction`, `ClipboardItem`, `IStatusBarItem`, etc.
|
|
55
|
+
* **Proxies:** `StatusBarServiceProxy` and others providing safe cross-context RPC.
|
|
56
|
+
|
|
57
|
+
Example import in an extension's `index.ts`:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type {
|
|
61
|
+
Extension,
|
|
62
|
+
ExtensionContext,
|
|
63
|
+
ExtensionResult,
|
|
64
|
+
ILogService,
|
|
65
|
+
IExtensionManager,
|
|
66
|
+
} from "asyar-sdk";
|
|
67
|
+
import type { ExtensionAction, IActionService } from "asyar-sdk";
|
|
68
|
+
|
|
69
|
+
class MyExtension implements Extension {
|
|
70
|
+
private logService?: ILogService;
|
|
71
|
+
|
|
72
|
+
async initialize(context: ExtensionContext): Promise<void> {
|
|
73
|
+
this.logService = context.getService<ILogService>("LogService");
|
|
74
|
+
this.logService?.info("Extension initialized using asyar-sdk");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ... other methods
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default new MyExtension();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Extension Icons
|
|
84
|
+
|
|
85
|
+
Add an `icon` field to your manifest to show a branded icon next to your commands in the launcher search results. Supports emoji or a base64 data URI for pixel-perfect images.
|
|
86
|
+
|
|
87
|
+
**Extension-level icon** (applies to all commands as default):
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"id": "com.example.my-extension",
|
|
91
|
+
"icon": "🚀",
|
|
92
|
+
"commands": [...]
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Command-level icon** (overrides the extension icon for a specific command):
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"commands": [
|
|
100
|
+
{ "id": "open", "name": "Open My Extension", "icon": "🚀" },
|
|
101
|
+
{ "id": "quick-run", "name": "Quick Run", "icon": "⚡" }
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Available Scripts
|
|
107
|
+
|
|
108
|
+
The following scripts are available via `pnpm run <script_name>`:
|
|
109
|
+
|
|
110
|
+
* `build`: Compiles the TypeScript code.
|
|
111
|
+
* `prepare`: Automatically runs `build` before publishing.
|
|
112
|
+
* `test`: Runs tests (requires test runner setup like Jest).
|
|
113
|
+
* `lint`: Lints the source code (requires linter setup like ESLint).
|
|
114
|
+
* `watch`: Compiles the code in watch mode.
|
|
115
|
+
|
|
116
|
+
## Clean Installation
|
|
117
|
+
|
|
118
|
+
A utility script `clean-install.sh` is provided to completely remove build artifacts, caches, and `node_modules`, then perform a fresh installation and build.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
./clean-install.sh
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Contributing
|
|
125
|
+
|
|
126
|
+
(Add contribution guidelines if applicable)
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
Distributed under the AGPLv3 License. See LICENSE.md for more information.
|
|
131
|
+
|
|
132
|
+
## Registering Actions
|
|
133
|
+
|
|
134
|
+
Extensions can register actions that appear in the ⌘K panel. Actions support optional grouping via the `category` field and icons via `icon`.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { ActionContext, ActionCategory } from 'asyar-sdk';
|
|
138
|
+
|
|
139
|
+
actionService.registerAction({
|
|
140
|
+
id: 'my-extension:do-thing',
|
|
141
|
+
title: 'Do Something',
|
|
142
|
+
description: 'A helpful description shown in the panel',
|
|
143
|
+
icon: '✨',
|
|
144
|
+
category: ActionCategory.PRIMARY, // Optional — groups related actions
|
|
145
|
+
extensionId: context.extensionId,
|
|
146
|
+
context: ActionContext.GLOBAL,
|
|
147
|
+
execute: async () => {
|
|
148
|
+
// your action logic
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Standard categories (`ActionCategory`)
|
|
154
|
+
|
|
155
|
+
| Constant | Display name | Use for |
|
|
156
|
+
|----------|-------------|---------|
|
|
157
|
+
| `ActionCategory.PRIMARY` | Primary | Main actions for the extension |
|
|
158
|
+
| `ActionCategory.NAVIGATION` | Navigation | Opening views, going back |
|
|
159
|
+
| `ActionCategory.EDIT` | Edit | Create, update, delete operations |
|
|
160
|
+
| `ActionCategory.SHARE` | Share | Export, copy, send |
|
|
161
|
+
| `ActionCategory.DESTRUCTIVE` | Destructive | Irreversible actions (delete, reset) |
|
|
162
|
+
| `ActionCategory.SYSTEM` | System | Reserved for built-in host actions |
|
|
163
|
+
|
|
164
|
+
Custom strings are always allowed. `ActionCategory` provides recommended names for consistency across extensions. If no `category` is set, the ⌘K panel automatically groups the action under the extension's display name.
|
|
165
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Extension, ExtensionManifest } from "./types/ExtensionType";
|
|
2
|
+
import { ExtensionAction } from "./types/ActionType";
|
|
3
|
+
import { CommandHandler } from "./types/CommandType";
|
|
4
|
+
export declare class ExtensionBridge {
|
|
5
|
+
private static instance;
|
|
6
|
+
private extensionManifests;
|
|
7
|
+
private extensionImplementations;
|
|
8
|
+
private componentRegistry;
|
|
9
|
+
private actionRegistry;
|
|
10
|
+
private commandRegistry;
|
|
11
|
+
private broker;
|
|
12
|
+
private constructor();
|
|
13
|
+
private handleActionExecute;
|
|
14
|
+
static getInstance(): ExtensionBridge;
|
|
15
|
+
private setupIPCListeners;
|
|
16
|
+
registerService(serviceType: string, implementation: any): void;
|
|
17
|
+
registerAction(extensionId: string, action: ExtensionAction): void;
|
|
18
|
+
unregisterAction(actionId: string): void;
|
|
19
|
+
getActions(): ExtensionAction[];
|
|
20
|
+
registerManifest(manifest: ExtensionManifest): void;
|
|
21
|
+
registerExtensionImplementation(id: string, extension: Extension): void;
|
|
22
|
+
initializeExtensions(): Promise<void>;
|
|
23
|
+
activateExtensions(): Promise<void>;
|
|
24
|
+
deactivateExtensions(): Promise<void>;
|
|
25
|
+
getManifests(): ExtensionManifest[];
|
|
26
|
+
getManifest(id: string): ExtensionManifest | undefined;
|
|
27
|
+
getExtensionImplementation(id: string): Extension | undefined;
|
|
28
|
+
registerCommand(commandId: string, handler: CommandHandler, extensionId: string): void;
|
|
29
|
+
unregisterCommand(commandId: string): void;
|
|
30
|
+
executeCommand(commandId: string, args?: Record<string, any>): Promise<any>;
|
|
31
|
+
getCommands(): string[];
|
|
32
|
+
getCommandsForExtension(extensionId: string): string[];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=ExtensionBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionBridge.d.ts","sourceRoot":"","sources":["../src/ExtensionBridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,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MAAM,EAAE;IAKvB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE;CAKvD"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ExtensionBridge = void 0;
|
|
13
|
+
const ExtensionContext_1 = require("./ExtensionContext");
|
|
14
|
+
const MessageBroker_1 = require("./ipc/MessageBroker");
|
|
15
|
+
// Define the bridge that will be used to communicate between extensions and the base app
|
|
16
|
+
class ExtensionBridge {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.extensionManifests = new Map();
|
|
19
|
+
this.extensionImplementations = new Map();
|
|
20
|
+
this.componentRegistry = {};
|
|
21
|
+
this.actionRegistry = new Map();
|
|
22
|
+
this.commandRegistry = new Map();
|
|
23
|
+
this.broker = MessageBroker_1.MessageBroker.getInstance();
|
|
24
|
+
this.setupIPCListeners();
|
|
25
|
+
if (typeof window !== 'undefined' && window.parent && window.parent !== window) {
|
|
26
|
+
window.addEventListener('message', this.handleActionExecute.bind(this));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
handleActionExecute(event) {
|
|
30
|
+
var _a;
|
|
31
|
+
const data = event.data;
|
|
32
|
+
if (!data || typeof data !== 'object')
|
|
33
|
+
return;
|
|
34
|
+
if (event.source !== window.parent)
|
|
35
|
+
return;
|
|
36
|
+
if (data.type !== 'asyar:action:execute')
|
|
37
|
+
return;
|
|
38
|
+
const actionId = (_a = data.payload) === null || _a === void 0 ? void 0 : _a.actionId;
|
|
39
|
+
if (!actionId)
|
|
40
|
+
return;
|
|
41
|
+
const action = this.actionRegistry.get(actionId);
|
|
42
|
+
if (action === null || action === void 0 ? void 0 : action.execute) {
|
|
43
|
+
Promise.resolve(action.execute()).catch(console.error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Singleton pattern
|
|
47
|
+
static getInstance() {
|
|
48
|
+
if (!ExtensionBridge.instance) {
|
|
49
|
+
ExtensionBridge.instance = new ExtensionBridge();
|
|
50
|
+
console.log("ExtensionBridge created:", ExtensionBridge.instance);
|
|
51
|
+
}
|
|
52
|
+
return ExtensionBridge.instance;
|
|
53
|
+
}
|
|
54
|
+
setupIPCListeners() {
|
|
55
|
+
// Listen for events from main app
|
|
56
|
+
this.broker.on('asyar:invoke:command', (data) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const result = yield this.executeCommand(data.payload.commandId, data.payload.args);
|
|
59
|
+
this.broker.send({
|
|
60
|
+
type: 'asyar:response',
|
|
61
|
+
messageId: data.messageId,
|
|
62
|
+
result
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
this.broker.send({
|
|
67
|
+
type: 'asyar:response',
|
|
68
|
+
messageId: data.messageId,
|
|
69
|
+
error: err.message || String(err)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
// Register a service implementation from the base app
|
|
75
|
+
registerService(serviceType, implementation) {
|
|
76
|
+
// Deprecated in new architecture, services are proxied
|
|
77
|
+
console.warn(`registerService is deprecated. Service ${serviceType} is now proxied.`);
|
|
78
|
+
}
|
|
79
|
+
// Component proxying has been removed in the new architecture.
|
|
80
|
+
// Extensions should bundle their own components.
|
|
81
|
+
// Register an action from an extension
|
|
82
|
+
registerAction(extensionId, action) {
|
|
83
|
+
const actionId = action.id;
|
|
84
|
+
this.actionRegistry.set(actionId, Object.assign(Object.assign({}, action), { id: actionId, extensionId }));
|
|
85
|
+
console.log(`Registered action: ${actionId}`);
|
|
86
|
+
}
|
|
87
|
+
// Unregister an action
|
|
88
|
+
unregisterAction(actionId) {
|
|
89
|
+
this.actionRegistry.delete(actionId);
|
|
90
|
+
}
|
|
91
|
+
// Get all registered actions
|
|
92
|
+
getActions() {
|
|
93
|
+
return Array.from(this.actionRegistry.values());
|
|
94
|
+
}
|
|
95
|
+
// Register an extension manifest
|
|
96
|
+
registerManifest(manifest) {
|
|
97
|
+
this.extensionManifests.set(manifest.id, manifest);
|
|
98
|
+
console.log(`Registered extension manifest: ${manifest.id} (${manifest.name} v${manifest.version})`);
|
|
99
|
+
}
|
|
100
|
+
// Register extension implementation
|
|
101
|
+
registerExtensionImplementation(id, extension) {
|
|
102
|
+
if (!this.extensionManifests.has(id)) {
|
|
103
|
+
console.error(`Cannot register extension implementation: Manifest for ${id} not found`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.extensionImplementations.set(id, extension);
|
|
107
|
+
console.log(`Registered extension implementation for: ${id}`);
|
|
108
|
+
}
|
|
109
|
+
// Initialize all registered extensions
|
|
110
|
+
initializeExtensions() {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
for (const [id, extension] of this.extensionImplementations.entries()) {
|
|
113
|
+
const manifest = this.extensionManifests.get(id);
|
|
114
|
+
if (!manifest) {
|
|
115
|
+
console.error(`Cannot initialize extension: Manifest for ${id} not found`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
console.log(`Initializing extension: ${manifest.id} (${manifest.name})`);
|
|
119
|
+
const context = new ExtensionContext_1.ExtensionContext();
|
|
120
|
+
context.setExtensionId(manifest.id);
|
|
121
|
+
yield extension.initialize(context);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// Activate all registered extensions
|
|
126
|
+
activateExtensions() {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
for (const [id, extension] of this.extensionImplementations.entries()) {
|
|
129
|
+
const manifest = this.extensionManifests.get(id);
|
|
130
|
+
if (!manifest)
|
|
131
|
+
continue;
|
|
132
|
+
console.log(`Activating extension: ${manifest.id}`);
|
|
133
|
+
yield extension.activate();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Deactivate all registered extensions
|
|
138
|
+
deactivateExtensions() {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
for (const [id, extension] of this.extensionImplementations.entries()) {
|
|
141
|
+
const manifest = this.extensionManifests.get(id);
|
|
142
|
+
if (!manifest)
|
|
143
|
+
continue;
|
|
144
|
+
console.log(`Deactivating extension: ${manifest.id}`);
|
|
145
|
+
yield extension.deactivate();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// Get all registered extension manifests
|
|
150
|
+
getManifests() {
|
|
151
|
+
return Array.from(this.extensionManifests.values());
|
|
152
|
+
}
|
|
153
|
+
// Get manifest by extension ID
|
|
154
|
+
getManifest(id) {
|
|
155
|
+
return this.extensionManifests.get(id);
|
|
156
|
+
}
|
|
157
|
+
// Get extension implementation by ID
|
|
158
|
+
getExtensionImplementation(id) {
|
|
159
|
+
return this.extensionImplementations.get(id);
|
|
160
|
+
}
|
|
161
|
+
// Register a command from an extension
|
|
162
|
+
registerCommand(commandId, handler, extensionId) {
|
|
163
|
+
this.commandRegistry.set(commandId, { handler, extensionId });
|
|
164
|
+
console.log(`Registered command: ${commandId}`);
|
|
165
|
+
}
|
|
166
|
+
// Unregister a command
|
|
167
|
+
unregisterCommand(commandId) {
|
|
168
|
+
this.commandRegistry.delete(commandId);
|
|
169
|
+
}
|
|
170
|
+
// Execute a command
|
|
171
|
+
executeCommand(commandId, args) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const command = this.commandRegistry.get(commandId);
|
|
174
|
+
if (!command) {
|
|
175
|
+
throw new Error(`Command not found: ${commandId}`);
|
|
176
|
+
}
|
|
177
|
+
return command.handler.execute(args);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// Get all registered commands
|
|
181
|
+
getCommands() {
|
|
182
|
+
return Array.from(this.commandRegistry.keys());
|
|
183
|
+
}
|
|
184
|
+
// Get commands for a specific extension
|
|
185
|
+
getCommandsForExtension(extensionId) {
|
|
186
|
+
return Array.from(this.commandRegistry.entries())
|
|
187
|
+
.filter(([_, value]) => value.extensionId === extensionId)
|
|
188
|
+
.map(([key, _]) => key);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.ExtensionBridge = ExtensionBridge;
|
|
192
|
+
//# sourceMappingURL=ExtensionBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionBridge.js","sourceRoot":"","sources":["../src/ExtensionBridge.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAsD;AAItD,uDAA6E;AAE7E,yFAAyF;AACzF,MAAa,eAAe;IAY1B;QAVQ,uBAAkB,GAAmC,IAAI,GAAG,EAAE,CAAC;QAC/D,6BAAwB,GAA2B,IAAI,GAAG,EAAE,CAAC;QAC7D,sBAAiB,GAAwB,EAAE,CAAC;QAC5C,mBAAc,GAAiC,IAAI,GAAG,EAAE,CAAC;QACzD,oBAAe,GAGnB,IAAI,GAAG,EAAE,CAAC;QAIZ,IAAI,CAAC,MAAM,GAAG,6BAAa,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC/E,MAAM,CAAC,gBAAgB,CAAC,S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vB,WAAmB;QAEnB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,uBAAuB,SAAS,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,uBAAuB;IACvB,iBAAiB,CAAC,SAAiB;QACjC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,oBAAoB;IACd,cAAc,CAClB,SAAiB,EACjB,IAA0B;;YAE1B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACpD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;KAAA;IAED,8BAA8B;IAC9B,WAAW;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,wCAAwC;IACxC,uBAAuB,CAAC,WAAmB;QACzC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;aAC9C,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,KAAK,WAAW,CAAC;aACzD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF;AA9MD,0CA8MC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ExtensionAction } from "./types/ActionType";
|
|
2
|
+
import { CommandHandler } from "./types/CommandType";
|
|
3
|
+
import { LogServiceProxy, NotificationServiceProxy, ClipboardHistoryServiceProxy, ExtensionManagerProxy, CommandServiceProxy, ActionServiceProxy, NetworkServiceProxy, StatusBarServiceProxy } from "./services";
|
|
4
|
+
export declare class ExtensionContext {
|
|
5
|
+
private extensionId;
|
|
6
|
+
readonly proxies: {
|
|
7
|
+
LogService: LogServiceProxy;
|
|
8
|
+
NotificationService: NotificationServiceProxy;
|
|
9
|
+
ClipboardHistoryService: ClipboardHistoryServiceProxy;
|
|
10
|
+
ExtensionManager: ExtensionManagerProxy;
|
|
11
|
+
CommandService: CommandServiceProxy;
|
|
12
|
+
ActionService: ActionServiceProxy;
|
|
13
|
+
NetworkService: NetworkServiceProxy;
|
|
14
|
+
StatusBarService: StatusBarServiceProxy;
|
|
15
|
+
};
|
|
16
|
+
constructor();
|
|
17
|
+
private setupFocusTracking;
|
|
18
|
+
getService<T>(serviceType: string): T;
|
|
19
|
+
setExtensionId(id: string): void;
|
|
20
|
+
registerAction(action: ExtensionAction): void;
|
|
21
|
+
unregisterAction(actionId: string): void;
|
|
22
|
+
registerCommand(commandId: string, handler: CommandHandler): void;
|
|
23
|
+
unregisterCommand(commandId: string): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ExtensionContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionContext.d.ts","sourceRoot":"","sources":["../src/ExtensionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAGpB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAc;IAGjC,SAAgB,OAAO;;;;;;;;;MASrB;;IAMF,OAAO,CAAC,kBAAkB;IA8C1B,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;IASrC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAWhC,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAa7C,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IASxC,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAiBjE,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAQ3C"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtensionContext = void 0;
|
|
4
|
+
const services_1 = require("./services");
|
|
5
|
+
// Define the context that will be passed to extensions
|
|
6
|
+
class ExtensionContext {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.extensionId = "";
|
|
9
|
+
// The local registry is now strictly for proxies
|
|
10
|
+
this.proxies = {
|
|
11
|
+
LogService: new services_1.LogServiceProxy(),
|
|
12
|
+
NotificationService: new services_1.NotificationServiceProxy(),
|
|
13
|
+
ClipboardHistoryService: new services_1.ClipboardHistoryServiceProxy(),
|
|
14
|
+
ExtensionManager: new services_1.ExtensionManagerProxy(),
|
|
15
|
+
CommandService: new services_1.CommandServiceProxy(),
|
|
16
|
+
ActionService: new services_1.ActionServiceProxy(),
|
|
17
|
+
NetworkService: new services_1.NetworkServiceProxy(),
|
|
18
|
+
StatusBarService: new services_1.StatusBarServiceProxy(),
|
|
19
|
+
};
|
|
20
|
+
this.setupFocusTracking();
|
|
21
|
+
}
|
|
22
|
+
setupFocusTracking() {
|
|
23
|
+
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
24
|
+
return;
|
|
25
|
+
const isInput = (el) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (!el)
|
|
28
|
+
return false;
|
|
29
|
+
const tag = el.tagName.toLowerCase();
|
|
30
|
+
if (tag === 'textarea' || tag === 'select')
|
|
31
|
+
return true;
|
|
32
|
+
if (tag === 'input') {
|
|
33
|
+
const type = ((_a = el.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'text';
|
|
34
|
+
const textTypes = ['text', 'search', 'email', 'password', 'number', 'tel', 'url', 'date', 'time', 'datetime-local', 'month', 'week'];
|
|
35
|
+
return textTypes.includes(type);
|
|
36
|
+
}
|
|
37
|
+
if (el.isContentEditable)
|
|
38
|
+
return true;
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
let currentlyFocused = false;
|
|
42
|
+
const emitFocus = (focused) => {
|
|
43
|
+
// Only emit if we are in an iframe (sandboxed extension)
|
|
44
|
+
if (window.parent && window.parent !== window) {
|
|
45
|
+
window.parent.postMessage({ type: 'asyar:extension:input-focus', focused }, '*');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// Use focusin and focusout because they bubble and capture generic focus changes
|
|
49
|
+
document.addEventListener('focusin', (e) => {
|
|
50
|
+
const active = isInput(e.target);
|
|
51
|
+
if (active !== currentlyFocused) {
|
|
52
|
+
currentlyFocused = active;
|
|
53
|
+
emitFocus(currentlyFocused);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
document.addEventListener('focusout', () => {
|
|
57
|
+
// Small timeout to allow the next element to receive focus
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
const active = isInput(document.activeElement);
|
|
60
|
+
if (active !== currentlyFocused) {
|
|
61
|
+
currentlyFocused = active;
|
|
62
|
+
emitFocus(currentlyFocused);
|
|
63
|
+
}
|
|
64
|
+
}, 0);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Method to get a service by its interface name
|
|
68
|
+
getService(serviceType) {
|
|
69
|
+
console.log("Getting service:", serviceType); // Add this line
|
|
70
|
+
const service = this.proxies[serviceType];
|
|
71
|
+
if (!service) {
|
|
72
|
+
throw new Error(`Service "${serviceType}" not registered`);
|
|
73
|
+
}
|
|
74
|
+
return service;
|
|
75
|
+
}
|
|
76
|
+
setExtensionId(id) {
|
|
77
|
+
this.extensionId = id;
|
|
78
|
+
// Inject into proxies if they support it
|
|
79
|
+
for (const key of Object.keys(this.proxies)) {
|
|
80
|
+
const svc = this.proxies[key];
|
|
81
|
+
if (svc && typeof svc.setExtensionId === 'function') {
|
|
82
|
+
svc.setExtensionId(id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
registerAction(action) {
|
|
87
|
+
const bridge = ExtensionBridge_1.ExtensionBridge.getInstance();
|
|
88
|
+
if (this.extensionId) {
|
|
89
|
+
bridge.registerAction(this.extensionId, action);
|
|
90
|
+
// We also need to notify the ActionServiceProxy to send the IPC message
|
|
91
|
+
const actionService = this.getService('ActionService');
|
|
92
|
+
actionService.registerAction(action);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.error("Cannot register action: Extension ID not set");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
unregisterAction(actionId) {
|
|
99
|
+
// Use bare actionId — matches the format used in registerAction (no extension prefix)
|
|
100
|
+
const bridge = ExtensionBridge_1.ExtensionBridge.getInstance();
|
|
101
|
+
bridge.unregisterAction(actionId);
|
|
102
|
+
const actionService = this.getService('ActionService');
|
|
103
|
+
actionService.unregisterAction(actionId);
|
|
104
|
+
}
|
|
105
|
+
registerCommand(commandId, handler) {
|
|
106
|
+
const bridge = ExtensionBridge_1.ExtensionBridge.getInstance();
|
|
107
|
+
if (this.extensionId) {
|
|
108
|
+
const fullCommandId = `${this.extensionId}.${commandId}`;
|
|
109
|
+
bridge.registerCommand(fullCommandId, handler, this.extensionId);
|
|
110
|
+
const commandService = this.getService('CommandService');
|
|
111
|
+
commandService.registerCommand(fullCommandId, handler, this.extensionId);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.error("Cannot register command: Extension ID not set");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
unregisterCommand(commandId) {
|
|
118
|
+
const fullCommandId = `${this.extensionId}.${commandId}`;
|
|
119
|
+
const bridge = ExtensionBridge_1.ExtensionBridge.getInstance();
|
|
120
|
+
bridge.unregisterCommand(fullCommandId);
|
|
121
|
+
const commandService = this.getService('CommandService');
|
|
122
|
+
commandService.unregisterCommand(fullCommandId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.ExtensionContext = ExtensionContext;
|
|
126
|
+
// Import at the end to avoid circular dependencies
|
|
127
|
+
const ExtensionBridge_1 = require("./ExtensionBridge");
|
|
128
|
+
//# sourceMappingURL=ExtensionContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionContext.js","sourceRoot":"","sources":["../src/ExtensionContext.ts"],"names":[],"mappings":";;;AAEA,yCASoB;AAEpB,uDAAuD;AACvD,MAAa,gBAAgB;IAe3B;QAdQ,gBAAW,GAAW,EAAE,CAAC;QAEjC,iDAAiD;QACjC,YAAO,GAAG;YACxB,UAAU,EAAE,IAAI,0BAAe,EAAE;YACjC,mBAAmB,EAAE,IAAI,mCAAwB,EAAE;YACnD,uBAAuB,EAAE,IAAI,uCAA4B,EAAE;YAC3D,gBAAgB,EAAE,IAAI,gCAAqB,EAAE;YAC7C,cAAc,EAAE,IAAI,8BAAmB,EAAE;YACzC,aAAa,EAAE,IAAI,6BAAkB,EAAE;YACvC,cAAc,EAAE,IAAI,8BAAmB,EAAE;YACzC,gBAAgB,EAAE,IAAI,gCAAqB,EAAE;SAC9C,CAAC;QAGA,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAEO,kBAAkB;QACxB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAO;QAE7E,MAAM,OAAO,GAAG,CAAC,EAAkB,EAAW,EAAE;;YAC9C,IAAI,CAAC,EAAE;gBAAE,OAAO,KAAK,CAAC;YACtB,MAAM,GAAG,GAAG,EAAE,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