-
Notifications
You must be signed in to change notification settings - Fork 734
feat(smsus): deeplink support for SMUS #8286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/core/src/sagemakerunifiedstudio/uriHandlers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import * as vscode from 'vscode' | ||
| import { SearchParams } from '../shared/vscode/uriHandler' | ||
| import { ExtContext } from '../shared/extensions' | ||
| import { deeplinkConnect } from '../awsService/sagemaker/commands' | ||
| import { telemetry } from '../shared/telemetry/telemetry' | ||
| /** | ||
| * Registers the SMUS deeplink URI handler at path `/connect/smus`. | ||
| * | ||
| * This handler processes deeplink URLs from the SageMaker Unified Studio console | ||
| * to establish remote connections to SMUS spaces. | ||
| * | ||
| * @param ctx Extension context containing the URI handler | ||
| * @returns Disposable for cleanup | ||
| */ | ||
| export function register(ctx: ExtContext) { | ||
| async function connectHandler(params: ReturnType<typeof parseConnectParams>) { | ||
| await telemetry.smus_deeplinkConnect.run(async (span) => { | ||
| span.record(extractTelemetryMetadata(params)) | ||
|
|
||
| // WORKAROUND: The ws_url from the startSession API call contains a query parameter | ||
vpbhargav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 'cell-number' within itself. When the entire deeplink URL is processed by the URI | ||
| // handler, 'cell-number' is parsed as a standalone query parameter at the top level | ||
| // instead of remaining part of the ws_url. This causes the ws_url to lose the | ||
| // cell-number context it needs. To fix this, we manually re-append the cell-number | ||
| // query parameter back to the ws_url to restore the original intended URL structure. | ||
| await deeplinkConnect( | ||
| ctx, | ||
| params.connection_identifier, | ||
| params.session, | ||
| `${params.ws_url}&cell-number=${params['cell-number']}`, // Re-append cell-number to ws_url | ||
| params.token, | ||
| params.domain, | ||
| params.app_type, | ||
| true // isSMUS=true for SMUS connections | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| return vscode.Disposable.from(ctx.uriHandler.onPath('/connect/smus', connectHandler, parseConnectParams)) | ||
| } | ||
|
|
||
| /** | ||
| * Parses and validates SMUS deeplink URI parameters. | ||
| * | ||
| * Required parameters: | ||
| * - connection_identifier: Space ARN identifying the SMUS space | ||
| * - domain: Domain ID for the SMUS space (SM AI side) | ||
| * - user_profile: User profile name | ||
| * - session: SSM session ID | ||
| * - ws_url: WebSocket URL for SSM connection (originally contains cell-number as a query param) | ||
| * - cell-number: extracted from ws_url during URI parsing | ||
| * - token: Authentication token | ||
| * | ||
| * Optional parameters: | ||
| * - app_type: Application type (e.g., JupyterLab, CodeEditor) | ||
vpbhargav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * - smus_domain_id: SMUS domain identifier | ||
| * - smus_domain_account_id: SMUS domain account ID | ||
| * - smus_project_id: SMUS project identifier | ||
| * - smus_domain_region: SMUS domain region | ||
| * | ||
| * Note: The ws_url from startSession API originally includes cell-number as a query parameter. | ||
| * However, when the deeplink URL is processed, the URI handler extracts cell-number as a | ||
| * separate top-level parameter. This is why we need to re-append it in the connectHandler. | ||
| * | ||
| * @param query URI query parameters | ||
| * @returns Parsed parameters object | ||
| * @throws Error if required parameters are missing | ||
| */ | ||
| export function parseConnectParams(query: SearchParams) { | ||
| const requiredParams = query.getFromKeysOrThrow( | ||
| 'connection_identifier', | ||
| 'domain', | ||
| 'user_profile', | ||
| 'session', | ||
| 'ws_url', | ||
| 'cell-number', | ||
| 'token' | ||
| ) | ||
| const optionalParams = query.getFromKeys( | ||
| 'app_type', | ||
| 'smus_domain_id', | ||
| 'smus_domain_account_id', | ||
| 'smus_project_id', | ||
| 'smus_domain_region' | ||
| ) | ||
|
|
||
| return { ...requiredParams, ...optionalParams } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts telemetry metadata from URI parameters and space ARN. | ||
| * | ||
| * @param params Parsed URI parameters | ||
| * @returns Telemetry metadata object | ||
| */ | ||
| function extractTelemetryMetadata(params: ReturnType<typeof parseConnectParams>) { | ||
| // Extract metadata from space ARN | ||
| // ARN format: arn:aws:sagemaker:region:account-id:space/domain-id/space-name | ||
| const arnParts = params.connection_identifier.split(':') | ||
| const resourceParts = arnParts[5]?.split('/') // Gets "space/domain-id/space-name" | ||
|
|
||
| const projectRegion = arnParts[3] // region from ARN | ||
| const projectAccountId = arnParts[4] // account-id from ARN | ||
| const domainIdFromArn = resourceParts?.[1] // domain-id from ARN | ||
| const spaceName = resourceParts?.[2] // space-name from ARN | ||
|
|
||
| return { | ||
| smusDomainId: params.smus_domain_id, | ||
| smusDomainAccountId: params.smus_domain_account_id, | ||
| smusProjectId: params.smus_project_id, | ||
| smusDomainRegion: params.smus_domain_region, | ||
| smusProjectRegion: projectRegion, | ||
| smusProjectAccountId: projectAccountId, | ||
| smusSpaceKey: domainIdFromArn && spaceName ? `${domainIdFromArn}/${spaceName}` : undefined, | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.