@@ -12,8 +12,8 @@ export interface PortInfo {
1212/**
1313 * Parse port name to extract structured information
1414 *
15- * Port name formats:
16- * - sidepanel:<tabId>:< executionId>
15+ * Port name formats (executionId is always tab_<tabId>) :
16+ * - sidepanel:<executionId>
1717 * - newtab:<executionId>
1818 * - options:<executionId>
1919 *
@@ -26,33 +26,38 @@ export function parsePortName(portName: string): PortInfo {
2626 raw : portName
2727 }
2828
29- // Check for sidepanel with dynamic format
29+ // Check for sidepanel
3030 if ( portName . startsWith ( 'sidepanel:' ) ) {
3131 const parts = portName . split ( ':' )
3232 result . type = 'sidepanel'
3333
34- // Format: sidepanel:tabId:executionId
35- if ( parts . length >= 3 ) {
36- const tabId = parseInt ( parts [ 1 ] )
37- if ( ! isNaN ( tabId ) ) {
38- result . tabId = tabId
39- }
40- result . executionId = parts [ 2 ]
41- }
42- // Format without tabId: sidepanel:executionId (shouldn't happen but handle gracefully)
43- else if ( parts . length === 2 ) {
34+ if ( parts . length >= 2 ) {
4435 result . executionId = parts [ 1 ]
36+ // Extract tabId from executionId if it's in tab_<id> format
37+ if ( parts [ 1 ] . startsWith ( 'tab_' ) ) {
38+ const tabId = parseInt ( parts [ 1 ] . slice ( 4 ) )
39+ if ( ! isNaN ( tabId ) ) {
40+ result . tabId = tabId
41+ }
42+ }
4543 }
4644 }
47- // Check for newtab with dynamic format
45+ // Check for newtab with executionId (tab_<tabId>)
4846 else if ( portName . startsWith ( 'newtab:' ) ) {
4947 const parts = portName . split ( ':' )
5048 result . type = 'newtab'
5149 if ( parts . length >= 2 ) {
5250 result . executionId = parts [ 1 ]
51+ // Extract tabId from executionId if it's in tab_<id> format
52+ if ( parts [ 1 ] . startsWith ( 'tab_' ) ) {
53+ const tabId = parseInt ( parts [ 1 ] . slice ( 4 ) )
54+ if ( ! isNaN ( tabId ) ) {
55+ result . tabId = tabId
56+ }
57+ }
5358 }
5459 }
55- // Check for options with dynamic format
60+ // Check for options
5661 else if ( portName . startsWith ( 'options:' ) ) {
5762 const parts = portName . split ( ':' )
5863 result . type = 'options'
@@ -66,26 +71,17 @@ export function parsePortName(portName: string): PortInfo {
6671
6772/**
6873 * Create a port name with the given parameters
74+ * Note: executionId should be in format tab_<tabId> for tab-scoped executions
6975 *
7076 * @param type - The type of port
71- * @param executionId - Execution ID (required)
72- * @param tabId - Optional tab ID (for sidepanel only)
77+ * @param executionId - Execution ID (should be tab_<tabId> for tab contexts)
7378 * @returns Formatted port name
7479 */
7580export function createPortName (
7681 type : 'sidepanel' | 'newtab' | 'options' ,
77- executionId : string ,
78- tabId ?: number
82+ executionId : string
7983) : string {
80- if ( type === 'sidepanel' && tabId ) {
81- return `sidepanel:${ tabId } :${ executionId } `
82- }
83- if ( type === 'sidepanel' ) {
84- // This shouldn't happen - sidepanel should always have tabId
85- console . warn ( 'Creating sidepanel port without tab ID' )
86- return `sidepanel:${ executionId } `
87- }
88-
89- // For newtab and options
84+ // Simple format: type:executionId
85+ // Since executionId already contains tab info (tab_123), no need for redundancy
9086 return `${ type } :${ executionId } `
9187}
0 commit comments