deploy: current vibn theia state
Some checks failed
Playwright Tests / Playwright Tests (ubuntu-22.04, Node.js 22.x) (push) Has been cancelled
3PP License Check / 3PP License Check (11, 22.x, ubuntu-22.04) (push) Has been cancelled
Publish packages to NPM / Perform Publishing (push) Has been cancelled

Made-with: Cursor
This commit is contained in:
2026-02-27 12:01:08 -08:00
commit 8bb5110148
3782 changed files with 640947 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
'../../configs/build.eslintrc.json'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json'
}
};

View File

@@ -0,0 +1,34 @@
<div align='center'>
<br />
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
<h2>ECLIPSE THEIA - SCAN OSS EXTENSION</h2>
<hr />
</div>
## Description
Offers a `ScanOSSService` on the backend and frontend for scanning code snippets.
If needed, an API key can be handed over via preference or environment variable (`SCANOSS_API_KEY`).
## Additional Information
- [API documentation for `@theia/scanoss`](https://eclipse-theia.github.io/theia/docs/next/modules/_theia_scanoss.html)
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
- [Theia - Website](https://theia-ide.org/)
- [SCAN OSS Website](https://www.scanoss.com/)
## License
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
## Trademark
"Theia" is a trademark of the Eclipse Foundation
<https://www.eclipse.org/theia>

View File

@@ -0,0 +1,50 @@
{
"name": "@theia/scanoss",
"version": "1.68.0",
"description": "Theia - SCANOSS Integration",
"dependencies": {
"@theia/core": "1.68.0",
"scanoss": "^0.15.2"
},
"publishConfig": {
"access": "public"
},
"theiaExtensions": [
{
"frontend": "lib/browser/scanoss-frontend-module",
"backend": "lib/node/scanoss-backend-module"
}
],
"keywords": [
"theia-extension"
],
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
"repository": {
"type": "git",
"url": "https://github.com/eclipse-theia/theia.git"
},
"bugs": {
"url": "https://github.com/eclipse-theia/theia/issues"
},
"homepage": "https://github.com/eclipse-theia/theia",
"files": [
"lib",
"src"
],
"main": "lib/common",
"scripts": {
"build": "theiaext build",
"clean": "theiaext clean",
"compile": "theiaext compile",
"lint": "theiaext lint",
"test": "theiaext test",
"watch": "theiaext watch"
},
"devDependencies": {
"@theia/ext-scripts": "1.68.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
},
"gitHead": "21358137e41342742707f660b8e222f940a27652"
}

View File

@@ -0,0 +1,29 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { ContainerModule } from '@theia/core/shared/inversify';
import { ScanOSSPreferencesSchema } from '../common/scanoss-preferences';
import { RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser';
import { SCANOSS_SERVICE_PATH, ScanOSSService } from '../common';
import { PreferenceContribution } from '@theia/core/lib/common/preferences/preference-schema';
export default new ContainerModule(bind => {
bind(PreferenceContribution).toConstantValue({ schema: ScanOSSPreferencesSchema });
bind(ScanOSSService).toDynamicValue(ctx => {
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
return provider.createProxy<ScanOSSService>(SCANOSS_SERVICE_PATH);
}).inSingletonScope();
});

View File

@@ -0,0 +1,16 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
export * from './scanoss-service';

View File

@@ -0,0 +1,30 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema';
export const SCAN_OSS_API_KEY_PREF = 'ai-features.SCANOSS.apiKey';
export const ScanOSSPreferencesSchema: PreferenceSchema = {
properties: {
[SCAN_OSS_API_KEY_PREF]: {
type: 'string',
markdownDescription: 'Enter an API Key of your SCANOSS Account. **Please note:** By using this preference the key will be stored in clear text\
on the machine running Theia. Use the environment variable `SCANOSS_API_KEY` to set the key securely.',
title: 'SCANOSS API Key'
}
}
};

View File

@@ -0,0 +1,38 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { ScannerComponent } from 'scanoss';
export const SCANOSS_SERVICE_PATH = '/services/scanoss/service';
export const ScanOSSService = Symbol('ScanOSSService');
export interface ScanOSSResultClean {
type: 'clean';
}
export interface ScanOSSResultMatch {
type: 'match';
matched: string; // e.g. "75%"
url: string;
raw: ScannerComponent;
file?: string;
}
export interface ScanOSSResultError {
type: 'error';
message: string;
}
export type ScanOSSResult = ScanOSSResultClean | ScanOSSResultMatch | ScanOSSResultError;
export interface ScanOSSService {
scanContent(content: string, apiKey?: string): Promise<ScanOSSResult>;
}

View File

@@ -0,0 +1,30 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { ContainerModule } from '@theia/core/shared/inversify';
import { ConnectionHandler, PreferenceContribution, RpcConnectionHandler } from '@theia/core';
import { ScanOSSService, SCANOSS_SERVICE_PATH } from '../common';
import { ScanOSSServiceImpl } from './scanoss-service-impl';
import { ScanOSSPreferencesSchema } from '../common/scanoss-preferences';
export default new ContainerModule(bind => {
bind(PreferenceContribution).toConstantValue({ schema: ScanOSSPreferencesSchema });
bind(ScanOSSServiceImpl).toSelf().inSingletonScope();
bind(ScanOSSService).toService(ScanOSSServiceImpl);
bind(ConnectionHandler).toDynamicValue(ctx =>
new RpcConnectionHandler(SCANOSS_SERVICE_PATH, () => ctx.container.get(ScanOSSService))
).inSingletonScope();
});

View File

@@ -0,0 +1,121 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { injectable } from '@theia/core/shared/inversify';
import { ScanOSSResult, ScanOSSService } from '../common';
import { Scanner, ScannerCfg, ScannerComponent } from 'scanoss';
// Define our own type of what is actually returned by the scanner
interface ScanOSSScanner {
scanContents: <T extends string>(options: { content: string; key: T }) => Promise<{ [K in `/${T}`]: ScannerComponent[] } | null>;
}
// Helper class to perform scans sequentially
class SequentialProcessor<T> {
private queue: Promise<T> = Promise.resolve() as Promise<T>;
public async processTask(task: () => Promise<T>): Promise<T> {
this.queue = this.queue.then(() => task());
return this.queue;
}
}
@injectable()
export class ScanOSSServiceImpl implements ScanOSSService {
private readonly processor = new SequentialProcessor<ScanOSSResult>();
async scanContent(content: string, apiKey?: string): Promise<ScanOSSResult> {
return this.processor.processTask(async () => this.doScanContent(content, apiKey));
}
async doScanContent(content: string, apiKey?: string): Promise<ScanOSSResult> {
const config = new ScannerCfg();
const apiKeyToUse = apiKey || process.env.SCANOSS_API_KEY || undefined;
if (apiKeyToUse) {
config.API_KEY = apiKeyToUse;
}
const scanner = new Scanner(config);
let results = undefined;
try {
results = await (scanner as unknown as ScanOSSScanner).scanContents({
content,
key: 'content_scanning',
});
} catch (e) {
console.debug('SCANOSS error', e);
// map known errors to a more user-friendly message
// Invalid API key message
if (e.message?.includes('Forbidden')) {
return {
type: 'error',
message: 'Forbidden: Please check your API key'
};
}
// Rate limit message
// HTTP:
// HTTP Status code: 503
// Server Response:
// 503 Unavailable. Check https://osskb.org/limit
if (e.message?.includes('https://osskb.org/limit')) {
return {
type: 'error',
message: 'You have reached the limit of the free data subscription, for a commercial subscription please contact support@scanoss.com'
};
}
return {
type: 'error',
message: e.message
};
}
if (!results) {
return {
type: 'error',
message: 'Scan request unsuccessful'
};
}
console.debug('SCANOSS results', JSON.stringify(results, undefined, 2));
let contentScanning: ScannerComponent[] | undefined = results['/content_scanning'];
if (!contentScanning) {
// #14648: The scanoss library prefixes the property with the path of a temporary file on Windows, so we need to search for it
contentScanning = Object.entries(results).find(([key]) => key.endsWith('content_scanning'))?.[1];
}
if (!contentScanning || contentScanning.length === 0) {
return {
type: 'error',
message: 'Scan request unsuccessful'
};
}
// first result is the best result
const firstEntry = contentScanning[0];
if (firstEntry.id === 'none') {
return {
type: 'clean'
};
}
return {
type: 'match',
matched: firstEntry.matched,
url: firstEntry.url,
raw: firstEntry
};
}
}

View File

@@ -0,0 +1,28 @@
// *****************************************************************************
// Copyright (C) 2024 EclipseSource GmbH and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
/* note: this bogus test file is required so that
we are able to run mocha unit tests on this
package, without having any actual unit tests in it.
This way a coverage report will be generated,
showing 0% coverage, instead of no report.
This file can be removed once we have real unit
tests in place. */
describe('ai-scanoss package', () => {
it('support code coverage statistics', () => true);
});

View File

@@ -0,0 +1,16 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
],
"references": [
{
"path": "../core"
}
]
}